getMessageReactions static method

Future<V2TimValueCallback<V2TimMessageReactionResult>> getMessageReactions({
  1. required List<String> msgIDList,
  2. required int maxUserCountPerReaction,
})

Implementation

static Future<V2TimValueCallback<V2TimMessageReactionResult>> getMessageReactions({
  required List<String> msgIDList,
  required int maxUserCountPerReaction,
}) async {
  String userData = Tools.generateUserData();
  Pointer<Uint8> user_data = Tools.string2PointerInt8(userData);

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

  var msgIDListPtr = Tools.string2PointerInt8(json.encode(msgIDList));

  List<Map<String, dynamic>> message_c_list = [];
  int res1 = desktopSDK.D_TIMMsgFindMessages(msgIDListPtr, user_data_find_msg);
  if (res1 != TIMResult.TIM_SUCC) {
    return V2TimValueCallback<V2TimMessageReactionResult>.fromJson({
      "code": res1,
      "desc": "find message error",
      "data": Map<String, dynamic>.from({
        "messageID": "",
      }),
    });
  } 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) {
      message_c_list.add(element);
    }
  }
  if (message_c_list.isEmpty) {
    return V2TimValueCallback<V2TimMessageReactionResult>.fromJson({
      "code": -2,
      "desc": "find message error",
      "data": Map<String, dynamic>.from({
        "messageID": "",
      }),
    });
  }

  Pointer<Uint8> json_msg_arrayPtr = Tools.string2PointerInt8(json.encode(message_c_list));
  int res = desktopSDK.D_TIMMsgGetMessageReactions(json_msg_arrayPtr, maxUserCountPerReaction, user_data);

  if (res != TIMResult.TIM_SUCC) {
    return V2TimValueCallback<V2TimMessageReactionResult>.fromJson({
      "code": res,
      "desc": "",
      "data": Map<String, dynamic>.from({"messageID": ""})
    });
  } else {
    Map<String, dynamic> data = await getAsyncData(apiKey: userData);
    Map<String, dynamic> dataMap = Map<String, dynamic>.from(
      json.decode(data["json_param"].isEmpty ? json.encode({}) : data["json_param"]),
    );
    List<Map<String, dynamic>> listrecation = List.from(dataMap["message_reaction_result_reaction_list"] ?? []);
    List<Map<String, dynamic>> listReactionDart = [];
    for (var i = 0; i < listrecation.length; i++) {
      var item = listrecation[i];
      List<Map<String, dynamic>> userinfo = List.from(item["message_reaction_partial_user_info_array"] ?? []);
      List<Map<String, dynamic>> userinfoDart = [];
      for (var i = 0; i < userinfo.length; i++) {
        var info = userinfo[i];
        userinfoDart.add(V2TimUserInfo.fromJson(
          {
            "userID": info["user_profile_identifier"],
            "nickName": info["user_profile_nick_name"],
            "faceUrl": info["user_profile_face_url"],
          },
        ).toJson());
      }
      listReactionDart.add(
        Map<String, dynamic>.from(
          {
            "reactionID": item["message_reaction_id"],
            "totalUserCount": item["message_reaction_total_user_count"],
            "partialUserList": userinfoDart,
            "reactedByMyself": item["message_reaction_reacted_by_myself"],
          },
        ),
      );
    }
    return V2TimValueCallback<V2TimMessageReactionResult>.fromJson({
      "code": data["code"],
      "desc": data["desc"],
      "data": Map<String, dynamic>.from({
        "resultCode": dataMap["message_reaction_result_code"],
        "resultInfo": dataMap["message_reaction_result_info"],
        "messageID": dataMap["message_reaction_result_msg_id"],
        "reactionList": listReactionDart,
      }),
    });
  }
}