createForwardMessage static method

Future<V2TimValueCallback<V2TimMsgCreateInfoResult>> createForwardMessage({
  1. required String msgID,
  2. String? webMessageInstance,
})

Implementation

static Future<V2TimValueCallback<V2TimMsgCreateInfoResult>> createForwardMessage({
  required String msgID,
  String? webMessageInstance,
}) async {
  String userData = Tools.generateUserData(methodName: "findMessage");
  Pointer<Uint8> user_data = Tools.string2PointerInt8(userData);
  Pointer<Uint8> json_message_id_array = Tools.string2PointerInt8(json.encode(List<String>.from([msgID])));
  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) {
      List<Map<String, dynamic>> messageList = List<Map<String, dynamic>>.from(json.decode(data["json_param"].isEmpty ? json.encode([]) : data["json_param"]));
      Map<String, dynamic> message = messageList.first;
      message["message_is_forward_message"] = true;
      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",
      });
    }
  }
}