getMessageReadReceipts static method

Future<V2TimValueCallback<List<V2TimMessageReceipt>>> getMessageReadReceipts({
  1. required List<String> messageIDList,
})

Implementation

static Future<V2TimValueCallback<List<V2TimMessageReceipt>>> getMessageReadReceipts({
  required List<String> messageIDList,
}) async {
  List<Map<String, dynamic>> originMessage = List<Map<String, dynamic>>.from([]);
  String userData = Tools.generateUserData();
  String userDataFind = Tools.generateUserData(methodName: "findMessage");
  Pointer<Uint8> user_data = Tools.string2PointerInt8(userData);
  Pointer<Uint8> user_data_find = Tools.string2PointerInt8(userDataFind);
  Pointer<Uint8> json_message_id_array = Tools.string2PointerInt8(json.encode(messageIDList));
  int res = desktopSDK.D_TIMMsgFindMessages(json_message_id_array, user_data_find);
  if (res != TIMResult.TIM_SUCC) {
    return V2TimValueCallback<List<V2TimMessageReceipt>>.fromJson({
      "code": -2,
      "desc": "find message error",
    });
  } else {
    Map<String, dynamic> messageData = await getAsyncData(apiKey: userDataFind);
    List<Map<String, dynamic>> nativeMessage = List<Map<String, dynamic>>.from(json.decode(messageData["json_param"].isEmpty ? json.encode([]) : messageData["json_param"]));
    if (nativeMessage.isNotEmpty) {
      originMessage = nativeMessage;
    }
  }
  if (originMessage.isEmpty) {
    return V2TimValueCallback<List<V2TimMessageReceipt>>.fromJson({
      "code": -2,
      "desc": "find message error",
    });
  }

  Pointer<Uint8> json_msg_array = Tools.string2PointerInt8(json.encode(originMessage));

  int res2 = desktopSDK.D_TIMMsgGetMessageReadReceipts(json_msg_array, user_data);
  if (res2 != TIMResult.TIM_SUCC) {
    return V2TimValueCallback<List<V2TimMessageReceipt>>.fromJson({
      "code": res2,
      "desc": "",
    });
  } else {
    Map<String, dynamic> data = await getAsyncData(apiKey: userData);
    List<Map<String, dynamic>> dataList = List<Map<String, dynamic>>.from(json.decode(data["json_param"].isEmpty ? json.encode([]) : data["json_param"]));
    List<Map<String, dynamic>> list = List<Map<String, dynamic>>.empty(growable: true);
    for (var element in dataList) {
      Map<String, dynamic> jso = element;
      list.add(Map<String, dynamic>.from({
        "userID": jso["msg_receipt_conv_type"] == 1 ? jso["msg_receipt_conv_id"] : "",
        "timestamp": jso["msg_receipt_time_stamp"] ?? (DateTime.now().millisecondsSinceEpoch / 100).floor(),
        "groupID": jso["msg_receipt_conv_type"] == 2 ? jso["msg_receipt_conv_id"] : "", // TODO
        "msgID": jso["msg_receipt_msg_id"],
        "readCount": jso["msg_receipt_read_count"],
        "unreadCount": jso["msg_receipt_unread_count"]
      }));
    }
    return V2TimValueCallback<List<V2TimMessageReceipt>>.fromJson({
      "code": data["code"],
      "desc": data["desc"],
      "data": list,
    });
  }
}