deleteMessageFromLocalStorage static method

Future<V2TimCallback> deleteMessageFromLocalStorage({
  1. required String msgID,
})

Implementation

static Future<V2TimCallback> deleteMessageFromLocalStorage({
  required String msgID,
}) async {
  Map<String, dynamic> message = Map.from({});
  String userData = Tools.generateUserData();
  Pointer<Uint8> user_data = Tools.string2PointerInt8(userData);
  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;
      }
    }
  }
  if (message.isNotEmpty) {
    Pointer<Uint8> conv_id = Tools.string2PointerInt8(message["message_conv_id"]);
    int conv_type = message["message_conv_type"];

    Pointer<Uint8> json_msgdel_param = Tools.string2PointerInt8(json.encode({
      "msg_delete_param_msg": message,
      "msg_delete_param_is_ramble": false,
    }));
    int res1 = desktopSDK.D_TIMMsgDelete(conv_id, conv_type, json_msgdel_param, user_data);
    if (res1 != TIMResult.TIM_SUCC) {
      return V2TimCallback.fromJson({
        "code": res1,
        "desc": "",
      });
    } else {
      Map<String, dynamic> revoke = await getAsyncData(apiKey: userData);
      return V2TimCallback.fromJson({
        "code": revoke["code"],
        "desc": revoke["desc"],
      });
    }
  } else {
    return V2TimCallback.fromJson({"code": -1, "desc": "message not found"});
  }
}