addMessageReaction static method

Future<V2TimCallback> addMessageReaction({
  1. required String msgID,
  2. required String reactionID,
})

Implementation

static Future<V2TimCallback> addMessageReaction({
  required String msgID,
  required String reactionID,
}) async {
  String userData = Tools.generateUserData();
  Pointer<Uint8> user_data = Tools.string2PointerInt8(userData);
  Pointer<Uint8> reactionIDPtr = Tools.string2PointerInt8(reactionID);

  String userDataFindMsg = Tools.generateUserData(methodName: "findMessage");
  Pointer<Uint8> user_data_find_msg = Tools.string2PointerInt8(userDataFindMsg);

  var msgIDListPtr = Tools.string2PointerInt8(json.encode([msgID]));
  Map<String, dynamic>? message_c;
  int res1 = desktopSDK.D_TIMMsgFindMessages(msgIDListPtr, user_data_find_msg);
  if (res1 != TIMResult.TIM_SUCC) {
    return V2TimCallback.fromJson({
      "code": res1,
      "desc": "find message error",
    });
  } else {
    Map<String, dynamic> msgListData = await getAsyncData(apiKey: userDataFindMsg);
    List<Map<String, dynamic>> dataList = List<Map<String, dynamic>>.from(json.decode(msgListData["json_param"].isEmpty ? json.encode([]) : msgListData["json_param"]));

    for (var element in dataList) {
      if (element["message_msg_id"] == msgID) {
        message_c = element;
      }
      // V2TimMessage converInfo = await Tools.convertMessage2Dart(jso);
      // list.add(converInfo.toJson());
    }
  }
  if (message_c == null) {
    return V2TimCallback.fromJson({
      "code": -2,
      "desc": "find message error",
    });
  }

  Pointer<Uint8> msgJsonPtr = Tools.string2PointerInt8(json.encode(message_c));

  int res = desktopSDK.D_TIMMsgAddMessageReaction(msgJsonPtr, reactionIDPtr, user_data);
  if (res != TIMResult.TIM_SUCC) {
    return V2TimCallback.fromJson({
      "code": res,
      "desc": "",
    });
  } else {
    Map<String, dynamic> data = await getAsyncData(apiKey: userData);

    return V2TimCallback.fromJson({
      "code": data["code"],
      "desc": data["desc"],
      "data": "",
    });
  }
}