createMergerMessage static method

Future<V2TimValueCallback<V2TimMsgCreateInfoResult>> createMergerMessage({
  1. required List<String> msgIDList,
  2. required String title,
  3. required List<String> abstractList,
  4. required String compatibleText,
  5. List<String>? webMessageInstanceList,
})

Implementation

static Future<V2TimValueCallback<V2TimMsgCreateInfoResult>> createMergerMessage({
  required List<String> msgIDList,
  required String title,
  required List<String> abstractList,
  required String compatibleText,
  List<String>? webMessageInstanceList,
}) async {
  String userData = Tools.generateUserData(methodName: "findMessage");
  Pointer<Uint8> user_data = Tools.string2PointerInt8(userData);
  Pointer<Uint8> json_message_id_array = Tools.string2PointerInt8(json.encode(msgIDList));
  int res = desktopSDK.D_TIMMsgFindMessages(json_message_id_array, user_data);
  if (res != TIMResult.TIM_SUCC) {
    return V2TimValueCallback<V2TimMsgCreateInfoResult>.fromJson({
      "code": -2,
      "desc": "find message error",
    });
  } else {
    Map<String, dynamic> data = await getAsyncData(apiKey: userData);

    if (data["code"] == 0) {
      Map<String, dynamic> message = Tools.createNativeMessage(
        elem: List<Map<String, dynamic>>.from([
          Map<String, dynamic>.from({
            "elem_type": Tools.dartElemTypeToNative(MessageElemType.V2TIM_ELEM_TYPE_MERGER),
            "merge_elem_title": title,
            "merge_elem_abstract_array": abstractList,
            "merge_elem_compatible_text": compatibleText,
            "merge_elem_message_array": List<Map<String, dynamic>>.from(json.decode(data["json_param"].isEmpty ? json.encode([]) : data["json_param"])),
          })
        ]),
      );
      String key = Tools.generateUniqueString();
      createdMessage[key] = message;

      return V2TimValueCallback<V2TimMsgCreateInfoResult>.fromJson({
        "code": 0,
        "desc": "success",
        "data": Map<String, dynamic>.from({"id": key, "messageInfo": (await Tools.convertMessage2Dart(message)).toJson()})
      });
    } else {
      return V2TimValueCallback<V2TimMsgCreateInfoResult>.fromJson({
        "code": -2,
        "desc": "find message error",
      });
    }
  }
}