setLocalCustomData static method

Future<V2TimCallback> setLocalCustomData({
  1. required String msgID,
  2. required String localCustomData,
})

Implementation

static Future<V2TimCallback> setLocalCustomData({
  required String msgID,
  required String localCustomData,
}) async {
  Map<String, dynamic> message = Map.from({});
  String userDatafind = Tools.generateUserData(methodName: "findMessage");
  Pointer<Uint8> user_data_find = Tools.string2PointerInt8(userDatafind);
  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_find);
  if (res == TIMResult.TIM_SUCC) {
    Map<String, dynamic> data = await getAsyncData(apiKey: userDatafind);
    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"]));
      if (messageList.isNotEmpty) {
        message = messageList.first;
      }
    } else {
      return V2TimCallback.fromJson({
        "code": data["code"],
        "desc": data["desc"],
        "data": "",
      });
    }
  } else {
    return V2TimCallback.fromJson({
      "code": -1,
      "desc": "message not found",
      "data": "",
    });
  }
  if (message.isNotEmpty) {
    message["message_custom_str"] = localCustomData;
    String userData = Tools.generateUserData();
    Pointer<Uint8> user_data_ptr = Tools.string2PointerInt8(userData);
    int res1 = desktopSDK.D_TIMMsgSetLocalCustomData(
      Tools.string2PointerInt8(json.encode(message)),
      user_data_ptr,
    );
    if (res1 != TIMResult.TIM_SUCC) {
      return V2TimCallback.fromJson({
        "code": res1,
        "desc": "",
      });
    } else {
      Map<String, dynamic> data = await getAsyncData(apiKey: userData);
      return V2TimCallback.fromJson({
        "code": data["code"],
        "desc": data["desc"],
      });
    }
  } else {
    return V2TimCallback.fromJson({
      "code": -1,
      "desc": 'message not found',
    });
  }
}