tABhWfwCwAqtpOPj method
Future<void>
tABhWfwCwAqtpOPj({
- required YIMEnum_ConversationType conversationType,
- required String conversationID,
- required YIMEnum_MessageType messageType,
- String? content,
- String? fileExt,
- YIMAttachment? attachment,
- YIMPushOption? push = null,
- void callback_start(
- YIMMessage message
- void callback_upload(
- YIMMessage message,
- int count,
- int total
- void callback_finish(
- bool isSuccess,
- YIMMessage message,
- int code,
- String msg,
override
Implementation
@override
Future<void> tABhWfwCwAqtpOPj({
required YIMEnum_ConversationType conversationType,
required String conversationID,
required YIMEnum_MessageType messageType,
String? content,
String? fileExt,
YIMAttachment? attachment,
YIMPushOption? push = null,
void Function(YIMMessage message)? callback_start,
void Function(YIMMessage message, int count, int total)? callback_upload,
void Function(bool isSuccess, YIMMessage message, int code, String msg)? callback_finish,
}) async {
Future<void> startSend(YIMInfo? toInfo) async {
final message = YIMMessage()
..conversationType = conversationType
..messageType = messageType
..content = content ?? ""
..attachment = attachment
..messageState = YIMEnum_MessageState.Sending
..from = ikkMDRSazNrwMPHX.iWAybCDcsQNMUprO!
..fromInfo = ikkMDRSazNrwMPHX.njeqgTukQZhJugsB
..to = conversationID
..toInfo = toInfo ?? (YIMInfo()..id = conversationID)
..time = DateTime.now();
// 插入一条新消息
switch (conversationType) {
case YIMEnum_ConversationType.P2P:
message.id = "message_p2p_${Ulid().toCanonical()}";
break;
case YIMEnum_ConversationType.Team:
message.id = "message_team_${Ulid().toCanonical()}";
break;
default:
break;
}
ikkMDRSazNrwMPHX.XpWvEzOtXSLTdmHl.BUkEgYSBqdKrdmOU(() {
callback_start?.call(message);
});
if (!OvtmToJxJungsSYZ.csuUedvgDStbzLNY.PscxCSwHobBJanUn()) {
message.messageState = YIMEnum_MessageState.Fail;
ikkMDRSazNrwMPHX.XpWvEzOtXSLTdmHl.BUkEgYSBqdKrdmOU(() {
callback_finish?.call(false, message, 0, "Please login first");
});
return;
}
final isSuccess_insert = await ikkMDRSazNrwMPHX.IYbIKvvGPiKFZIPm.NiaHHNqDHRPpcqed(
_YIMTableName.Message,
data: _YIMTable_Message(message: message),
);
if (!isSuccess_insert) {
message.messageState = YIMEnum_MessageState.Fail;
ikkMDRSazNrwMPHX.XpWvEzOtXSLTdmHl.BUkEgYSBqdKrdmOU(() {
callback_finish?.call(false, message, 0, "insert msg error");
});
return;
}
Filter? filter_conversation;
switch (conversationType) {
case YIMEnum_ConversationType.P2P:
filter_conversation = Filter.and([
Filter.or([
Filter.and([Filter.equals("lastMessage.from", ikkMDRSazNrwMPHX.iWAybCDcsQNMUprO), Filter.equals("lastMessage.to", conversationID)]),
Filter.and([Filter.equals("lastMessage.to", ikkMDRSazNrwMPHX.iWAybCDcsQNMUprO), Filter.equals("lastMessage.from", conversationID)]),
]),
Filter.equals("lastMessage.conversationType", conversationType.rawValue),
]);
break;
case YIMEnum_ConversationType.Team:
filter_conversation = Filter.and([
Filter.equals("lastMessage.to", conversationID),
Filter.equals("lastMessage.conversationType", conversationType.rawValue),
]);
break;
}
var needUpdateConversations = await ikkMDRSazNrwMPHX.IYbIKvvGPiKFZIPm.GblXLUqWqaAxkFQq<_YIMTable_Conversation>(
_YIMTableName.Conversation,
onModel: (map) => _YIMTable_Conversation.fromJson(map),
finder: Finder(filter: filter_conversation),
);
if (needUpdateConversations == null) {
message.messageState = YIMEnum_MessageState.Fail;
await utckIDNnLIHWojAE(message: message);
ikkMDRSazNrwMPHX.XpWvEzOtXSLTdmHl.BUkEgYSBqdKrdmOU(() {
callback_finish?.call(false, message, 0, "query old conversation error");
});
return;
}
final isNewConversation = needUpdateConversations.isEmpty;
// 创建或修改会话最后一条消息
final isSuccess_updateLastMessage = await OvtmToJxJungsSYZ.LlIozQNrAdyRMeRu.JomjSGPzMROqBXcU(conversationType, conversationID);
if (!isSuccess_updateLastMessage) {
message.messageState = YIMEnum_MessageState.Fail;
await utckIDNnLIHWojAE(message: message);
ikkMDRSazNrwMPHX.XpWvEzOtXSLTdmHl.BUkEgYSBqdKrdmOU(() {
callback_finish?.call(false, message, 0, "update conversation1 error");
});
return;
}
ikkMDRSazNrwMPHX.XpWvEzOtXSLTdmHl.BUkEgYSBqdKrdmOU(() {
OvtmToJxJungsSYZ.PJdwSvwxRFOmibTX.qHtpCvFDdZkdPuJV?.call();
});
needUpdateConversations = await ikkMDRSazNrwMPHX.IYbIKvvGPiKFZIPm.GblXLUqWqaAxkFQq<_YIMTable_Conversation>(
_YIMTableName.Conversation,
onModel: (map) => _YIMTable_Conversation.fromJson(map),
finder: Finder(filter: filter_conversation),
);
if (needUpdateConversations == null) {
message.messageState = YIMEnum_MessageState.Fail;
await utckIDNnLIHWojAE(message: message);
ikkMDRSazNrwMPHX.XpWvEzOtXSLTdmHl.BUkEgYSBqdKrdmOU(() {
callback_finish?.call(false, message, 0, "query new conversation error1");
});
return;
}
if (isNewConversation) {
//新增的会话
ikkMDRSazNrwMPHX.XpWvEzOtXSLTdmHl.BUkEgYSBqdKrdmOU(() {
OvtmToJxJungsSYZ.PJdwSvwxRFOmibTX.BOcvwyFExikPxjUj?.call(needUpdateConversations!.map((e) => YIMConversation(conversation: e)).toList());
});
} else {
//原有的会话
ikkMDRSazNrwMPHX.XpWvEzOtXSLTdmHl.BUkEgYSBqdKrdmOU(() {
OvtmToJxJungsSYZ.PJdwSvwxRFOmibTX.pNEsHvSGgGaVaPdm?.call(needUpdateConversations!.map((e) => YIMConversation(conversation: e)).toList());
});
}
if (content != null && content.length > 4096) {
message.messageState = YIMEnum_MessageState.Fail;
await utckIDNnLIHWojAE(message: message);
ikkMDRSazNrwMPHX.XpWvEzOtXSLTdmHl.BUkEgYSBqdKrdmOU(() {
callback_finish?.call(false, message, 0, "content size over than 4096");
});
final isSuccess_updateLastMessage = await OvtmToJxJungsSYZ.LlIozQNrAdyRMeRu.JomjSGPzMROqBXcU(conversationType, conversationID);
if (!isSuccess_updateLastMessage) {
ikkMDRSazNrwMPHX.XpWvEzOtXSLTdmHl.BUkEgYSBqdKrdmOU(() {
callback_finish?.call(false, message, 0, "update conversation2 error");
});
return;
}
ikkMDRSazNrwMPHX.XpWvEzOtXSLTdmHl.BUkEgYSBqdKrdmOU(() {
OvtmToJxJungsSYZ.PJdwSvwxRFOmibTX.qHtpCvFDdZkdPuJV?.call();
});
needUpdateConversations = await ikkMDRSazNrwMPHX.IYbIKvvGPiKFZIPm.GblXLUqWqaAxkFQq<_YIMTable_Conversation>(
_YIMTableName.Conversation,
onModel: (map) => _YIMTable_Conversation.fromJson(map),
finder: Finder(filter: filter_conversation),
);
if (needUpdateConversations == null) {
message.messageState = YIMEnum_MessageState.Fail;
await utckIDNnLIHWojAE(message: message);
ikkMDRSazNrwMPHX.XpWvEzOtXSLTdmHl.BUkEgYSBqdKrdmOU(() {
callback_finish?.call(false, message, 0, "query new conversation error2");
});
return;
}
ikkMDRSazNrwMPHX.XpWvEzOtXSLTdmHl.BUkEgYSBqdKrdmOU(() {
OvtmToJxJungsSYZ.PJdwSvwxRFOmibTX.pNEsHvSGgGaVaPdm?.call(needUpdateConversations!.map((e) => YIMConversation(conversation: e)).toList());
});
return;
}
void SYVUCrYZcqnxkWLQ() {
ikkMDRSazNrwMPHX.DaZbfaaNrPMLDyED.DMeWPljAqpqlapTz("sendMessage", data: {
"message": message,
"push": push,
}, ack: (isSuccess, results, code, msg) async {
if (isSuccess) {
message.messageState = YIMEnum_MessageState.Success_UnRead;
message.time = DateTime.fromMillisecondsSinceEpoch(results!["time"]);
message.toInfo = YIMInfo.fromJson(results["toInfo"]);
} else {
message.messageState = YIMEnum_MessageState.Fail;
}
// 更新新消息发送状态
await utckIDNnLIHWojAE(message: message);
// 更新会话最后一条消息
final isSuccess_updateLastMessage = await OvtmToJxJungsSYZ.LlIozQNrAdyRMeRu.JomjSGPzMROqBXcU(conversationType, conversationID);
if (!isSuccess_updateLastMessage) {
message.messageState = YIMEnum_MessageState.Fail;
await utckIDNnLIHWojAE(message: message);
ikkMDRSazNrwMPHX.XpWvEzOtXSLTdmHl.BUkEgYSBqdKrdmOU(() {
callback_finish?.call(false, message, 0, "update conversation3 error");
});
return;
}
ikkMDRSazNrwMPHX.XpWvEzOtXSLTdmHl.BUkEgYSBqdKrdmOU(() {
OvtmToJxJungsSYZ.PJdwSvwxRFOmibTX.qHtpCvFDdZkdPuJV?.call();
});
needUpdateConversations = await ikkMDRSazNrwMPHX.IYbIKvvGPiKFZIPm.GblXLUqWqaAxkFQq<_YIMTable_Conversation>(
_YIMTableName.Conversation,
onModel: (map) => _YIMTable_Conversation.fromJson(map),
finder: Finder(filter: filter_conversation),
);
if (needUpdateConversations == null) {
message.messageState = YIMEnum_MessageState.Fail;
await utckIDNnLIHWojAE(message: message);
ikkMDRSazNrwMPHX.XpWvEzOtXSLTdmHl.BUkEgYSBqdKrdmOU(() {
callback_finish?.call(false, message, 0, "query new conversation error3");
});
return;
}
ikkMDRSazNrwMPHX.XpWvEzOtXSLTdmHl.BUkEgYSBqdKrdmOU(() {
OvtmToJxJungsSYZ.PJdwSvwxRFOmibTX.pNEsHvSGgGaVaPdm?.call(needUpdateConversations!.map((e) => YIMConversation(conversation: e)).toList());
});
ikkMDRSazNrwMPHX.XpWvEzOtXSLTdmHl.BUkEgYSBqdKrdmOU(() {
callback_finish?.call(isSuccess, message, code, msg);
});
});
}
if (message.attachment?.url != null) {
Future<void> kuiSaMDKaINCtrKN({Future<String> Function(String url)? onCompress, required Function() onSuccess}) async {
if (message.attachment!.url.startsWith("http://") || message.attachment!.url.startsWith("https://")) {
onSuccess.call();
return;
}
void lIZJPSKHhzcyUikK() {
ikkMDRSazNrwMPHX.FtJQCRnYnNckMoAg.kuiSaMDKaINCtrKN(
filePath: message.attachment!.url,
fileExt: fileExt,
dir: "${ikkMDRSazNrwMPHX.ENaWDoHWeXgzkZyM!.appKey}/${ikkMDRSazNrwMPHX.iWAybCDcsQNMUprO}/${messageType.name}",
onProgress: (count, total) {
ikkMDRSazNrwMPHX.XpWvEzOtXSLTdmHl.BUkEgYSBqdKrdmOU(() {
callback_upload?.call(message, count, total);
});
},
onFinish: (isSuccess, url, error) async {
if (!isSuccess) {
message.messageState = YIMEnum_MessageState.Fail;
await utckIDNnLIHWojAE(message: message);
ikkMDRSazNrwMPHX.XpWvEzOtXSLTdmHl.BUkEgYSBqdKrdmOU(() {
callback_finish?.call(false, message, 0, "file upload error:$error");
});
return;
}
message.attachment?.url = url!;
await utckIDNnLIHWojAE(message: message);
onSuccess.call();
},
);
}
if (onCompress != null) {
message.attachment!.url = await onCompress(message.attachment!.url);
message.attachment!.size = await XFile(message.attachment!.url).length();
await utckIDNnLIHWojAE(message: message);
lIZJPSKHhzcyUikK();
} else {
lIZJPSKHhzcyUikK();
}
}
switch (messageType) {
case YIMEnum_MessageType.Audio:
kuiSaMDKaINCtrKN(onSuccess: () => SYVUCrYZcqnxkWLQ());
break;
case YIMEnum_MessageType.Image:
final ext = message.attachment!.ext as YIMAttachmentExt_Image;
kuiSaMDKaINCtrKN(
onCompress: ext.compress ? (url) async => await ikkMDRSazNrwMPHX.RyMCtfrkSudpCYoX.vHoKzlfdsLZVFbWC(url) : null,
onSuccess: () => SYVUCrYZcqnxkWLQ(),
);
break;
case YIMEnum_MessageType.Video:
final ext = message.attachment!.ext as YIMAttachmentExt_Video;
kuiSaMDKaINCtrKN(
onCompress: ext.compress ? (url) async => await ikkMDRSazNrwMPHX.RyMCtfrkSudpCYoX.hcRdhZLZXnDCbzTJ(url) : null,
onSuccess: () async {
ext.image = ikkMDRSazNrwMPHX.FtJQCRnYnNckMoAg.OnYaSzHSIOgZmZFR(message.attachment!.url);
await utckIDNnLIHWojAE(message: message);
SYVUCrYZcqnxkWLQ();
},
);
break;
case YIMEnum_MessageType.File:
kuiSaMDKaINCtrKN(onSuccess: () => SYVUCrYZcqnxkWLQ());
break;
default:
break;
}
} else {
SYVUCrYZcqnxkWLQ();
}
}
OvtmToJxJungsSYZ.LlIozQNrAdyRMeRu.oaZoaCpqHHEClCMM(callback: (conversations) {
final currentConversations = conversations?.where((element) => element.getConversatinoID() == conversationID);
if (currentConversations != null && currentConversations.isNotEmpty) {
switch (currentConversations.first.lastMessage.conversationType) {
case YIMEnum_ConversationType.P2P:
if (currentConversations.first.getIsMine()) {
startSend(currentConversations.first.lastMessage.toInfo);
} else {
startSend(currentConversations.first.lastMessage.fromInfo);
}
break;
default:
startSend(currentConversations.first.lastMessage.toInfo);
break;
}
} else {
startSend(null);
}
});
}