modifyMessage static method
Future<V2TimValueCallback<V2TimMessageChangeInfo> >
modifyMessage({
- required V2TimMessage message,
localCustomData localCustomInt cloudCustomData V2TIMTextElem V2TIMCustomElem
Implementation
static Future<V2TimValueCallback<V2TimMessageChangeInfo>> modifyMessage({
required V2TimMessage message,
}) async {
Map<String, dynamic> originMessage = 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(List<String>.from([message.msgID])));
int res = desktopSDK.D_TIMMsgFindMessages(json_message_id_array, user_data_find);
if (res != TIMResult.TIM_SUCC) {
return V2TimValueCallback<V2TimMessageChangeInfo>.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.first;
}
}
if (originMessage.isEmpty) {
return V2TimValueCallback<V2TimMessageChangeInfo>.fromJson({
"code": -2,
"desc": "find message error",
});
}
originMessage["message_custom_str"] = message.localCustomData;
originMessage["message_custom_int"] = message.localCustomInt;
originMessage["message_cloud_custom_str"] = message.cloudCustomData;
if (message.elemType == MessageElemType.V2TIM_ELEM_TYPE_TEXT) {
originMessage["message_elem_array"] = List.from([
Map<String, dynamic>.from({"elem_type": 0, "text_elem_content": message.textElem!.text})
]);
}
if (message.elemType == MessageElemType.V2TIM_ELEM_TYPE_CUSTOM) {
originMessage["message_elem_array"] = List.from([
Map<String, dynamic>.from({
"elem_type": 3,
"custom_elem_data": message.customElem!.data,
"custom_elem_desc": message.customElem!.desc,
"custom_elem_ext": message.customElem!.extension,
})
]);
}
Pointer<Uint8> json_msg_param = Tools.string2PointerInt8(json.encode(originMessage));
int res2 = desktopSDK.D_TIMMsgModifyMessage(json_msg_param, user_data);
if (res2 != TIMResult.TIM_SUCC) {
return V2TimValueCallback<V2TimMessageChangeInfo>.fromJson({
"code": res2,
"desc": "",
});
} else {
Map<String, dynamic> data = await getAsyncData(apiKey: userData);
Map<String, dynamic> nativeData = Map<String, dynamic>.from(json.decode(data["json_param"].isEmpty ? json.encode({}) : data["json_param"]));
Map<String, dynamic> dartData = Map<String, dynamic>.from({
"code": 0,
"desc": "",
"message": (await Tools.convertMessage2Dart(nativeData)).toJson(),
});
return V2TimValueCallback<V2TimMessageChangeInfo>.fromJson({
"code": data["code"],
"desc": data["desc"],
"data": dartData,
});
}
}