toJson method
function for updating currently downloading message's local url in memory
progress
V2TimMessageDownloadProgress
function for updating current downloading message progress
after updating, function will notify listener TencentCloudChatMessageDataKeys.downloadMessag
progress
V2TimMessageDownloadProgress
Callback for message downloading progress
function(V2TimMessageDownloadProgress)
function for removing message from download queue
msgID
(required) string, messageID
function for adding message to downloading queue
data
(required) DownloadMessageQueueData
isClick
(optional) bool
function for start downling data in downloading queue
function for checking if message is downloading
msgID
(required) messageID
returns bool value whether message is downloading
function for checking if message is in downloading queue
msgID
(required) messageID
returns bool value whether message is in downloading queue
==== Common Functions ====
Implementation
// void updateMessageLocalUrlInMemory(V2TimMessageDownloadProgress progress) {
// String msgID = progress.msgID;
// if (_currentDownloadMessage != null) {
// String currentDownloadMsgID = _currentDownloadMessage!.msgID;
// if (currentDownloadMsgID == msgID) {
// var msgList = getMessageList(key: _currentDownloadMessage!.key);
// var idx = msgList.indexWhere((element) => element.msgID == msgID);
// if (idx > -1) {
// var msg = msgList[idx];
// // add local url
// if (msg.elemType == MessageElemType.V2TIM_ELEM_TYPE_FILE) {
// if (msg.fileElem != null) {
// msg.fileElem!.localUrl = progress.path;
// TencentCloudChat.instance.logInstance.console(
// componentName: _tag,
// logs: "update memery file message local snanp path $msgID",
// logLevel: TencentCloudChatLogLevel.debug,
// );
// }
// } else if (msg.elemType == MessageElemType.V2TIM_ELEM_TYPE_IMAGE) {
// if (msg.imageElem != null) {
// List<V2TimImage?> images = msg.imageElem!.imageList ?? [];
// for (var i = 0; i < images.length; i++) {
// V2TimImage? image = images[i];
// if (image != null) {
// if (image.type == _currentDownloadMessage?.imageType) {
// image.localUrl = progress.path;
// TencentCloudChat.instance.logInstance.console(
// componentName: _tag,
// logs: "update memery image message local path $msgID",
// logLevel: TencentCloudChatLogLevel.debug,
// );
// }
// }
// }
// }
// } else if (msg.elemType == MessageElemType.V2TIM_ELEM_TYPE_SOUND) {
// if (msg.soundElem != null) {
// msg.soundElem!.localUrl = progress.path;
// TencentCloudChat.instance.logInstance.console(
// componentName: _tag,
// logs: "update memery sound message local snanp path $msgID",
// logLevel: TencentCloudChatLogLevel.debug,
// );
// }
// } else if (msg.elemType == MessageElemType.V2TIM_ELEM_TYPE_VIDEO) {
// if (msg.videoElem != null) {
// if (_currentDownloadMessage?.isSnapshot == true) {
// msg.videoElem!.localSnapshotUrl = progress.path;
// TencentCloudChat.instance.logInstance.console(
// componentName: _tag,
// logs: "update memery video message local snanp path $msgID",
// logLevel: TencentCloudChatLogLevel.debug,
// );
// } else {
// msg.videoElem!.localVideoUrl = progress.path;
// TencentCloudChat.instance.logInstance.console(
// componentName: _tag,
// logs: "update memery video message local path $msgID",
// logLevel: TencentCloudChatLogLevel.debug,
// );
// }
// }
// }
// var replacements = [msg];
// msgList.replaceRange(idx, (idx + 1), replacements);
// updateMessageList(
// messageList: msgList,
// userID: _currentDownloadMessage?.conversationType == ConversationType.V2TIM_C2C ? _currentDownloadMessage?.key : null,
// groupID: _currentDownloadMessage?.conversationType == ConversationType.V2TIM_GROUP ? _currentDownloadMessage?.key : null,
// disableNotify: true, // disable this time notify. use widget state .
// );
// }
// }
// }
// }
/// function for updating current downloading message progress
/// after updating, function will notify listener [TencentCloudChatMessageDataKeys.downloadMessag]
/// [progress] V2TimMessageDownloadProgress
// void updateCurrentDownloadMessage(V2TimMessageDownloadProgress progress) {
// if (_currentDownloadMessage != null) {
// _currentDownloadMessage?.currentDownloadSize = progress.currentSize;
// _currentDownloadMessage?.totalSize = progress.totalSize;
// _currentDownloadMessage?.downloadFinish = progress.isFinish;
// if (progress.isFinish) {
// if (_currentDownloadMessage?.isSnapshot == true) {
// _currentDownloadMessage?.snapPath = progress.path;
// } else {
// _currentDownloadMessage?.path = progress.path;
// }
// }
// notifyListener(TencentCloudChatMessageDataKeys.downloadMessage as T);
// }
// }
// List<String> messageDownloadFinishedList = [];
/// Callback for message downloading progress
/// function(V2TimMessageDownloadProgress)
// void onMessageDownload(V2TimMessageDownloadProgress progress) async {
// updateCurrentDownloadMessage(progress);
// if (!messageDownloadFinishedList.contains(progress.msgID) && progress.isFinish == true) {
// messageDownloadFinishedList.add(progress.msgID);
// _isDownloading = false;
// TencentCloudChat.instance.logInstance.console(
// componentName: _tag,
// logs: "${progress.msgID} isError ${progress.isError} download finished",
// logLevel: TencentCloudChatLogLevel.debug,
// );
// if (_downloadQueue.any((ele) => ele.msgID == progress.msgID)) {
// _downloadQueue.removeWhere((ele) => ele.msgID == progress.msgID);
// }
// updateMessageLocalUrlInMemory(progress);
// await Future.delayed(const Duration(seconds: 1));
// startDownload();
// }
// }
/// function for removing message from download queue
/// [msgID] (required) string, messageID
// removeFromDownloadQueue({
// required String msgID,
// }) {
// int removeIndex = _removedDownloadQueue.indexWhere((element) => element.msgID == msgID);
// int currentIndex = _downloadQueue.indexWhere((element) => element.msgID == msgID);
// if (currentIndex > -1) {
// if (removeIndex == -1) {}
// }
// _removedDownloadQueue.add(_downloadQueue.firstWhere((element) => element.msgID == msgID));
// _downloadQueue.removeWhere((element) => element.msgID == msgID);
// TencentCloudChat.instance.logInstance.console(
// componentName: _tag,
// logs: "$msgID has been remove from download queue",
// logLevel: TencentCloudChatLogLevel.debug,
// );
// }
/// function for adding message to downloading queue
/// [data] (required) DownloadMessageQueueData
/// [isClick] (optional) bool
// addDownloadMessageToQueue({
// required DownloadMessageQueueData data,
// bool? isClick,
// }) {
// if (TencentCloudChat.instance.dataInstance.basic.userConfig.autoDownloadMultimediaMessage == true || isClick == true || data.isSnapshot == true) {
// int idx = _downloadQueue.indexWhere((element) => element.msgID == data.msgID);
// if (idx > -1) {
// TencentCloudChat.instance.logInstance.console(
// componentName: _tag,
// logs: "${data.msgID} is already add to the download queue",
// logLevel: TencentCloudChatLogLevel.debug,
// );
// return;
// }
// if (_currentDownloadMessage != null) {
// if (data.msgID == _currentDownloadMessage!.msgID && data.isSnapshot != true) {
// TencentCloudChat.instance.logInstance.console(
// componentName: _tag,
// logs: "${data.msgID} is downloading",
// logLevel: TencentCloudChatLogLevel.debug,
// );
// return;
// }
// }
// TencentCloudChat.instance.logInstance.console(
// componentName: _tag,
// logs: "${data.msgID} add message to the queue message type ${data.messageType}",
// logLevel: TencentCloudChatLogLevel.debug,
// );
// _downloadQueue.add(data);
// if (!_isDownloading) {
// startDownload();
// }
// } else {
// TencentCloudChat.instance.logInstance.console(
// componentName: _tag,
// logs: "download message end.",
// logLevel: TencentCloudChatLogLevel.debug,
// );
// }
// }
/// function for start downling data in downloading queue
// startDownload() {
// if (_downloadQueue.isNotEmpty) {
// DownloadMessageQueueData readyToDownload = _downloadQueue.removeAt(0);
// _currentDownloadMessage = readyToDownload;
// downloadMessage(
// msgID: readyToDownload.msgID.replaceAll("-snap", ""), // replace snap
// messageType: readyToDownload.messageType,
// imageType: readyToDownload.imageType,
// isSnapshot: readyToDownload.isSnapshot,
// );
// } else {
// _currentDownloadMessage = null;
// TencentCloudChat.instance.logInstance.console(
// componentName: _tag,
// logs: "download message end.",
// logLevel: TencentCloudChatLogLevel.debug,
// );
// _isDownloading = false;
// }
// }
/// function for checking if message is downloading
/// [msgID] (required) messageID
/// returns bool value whether message is downloading
// bool isDownloading({
// required msgID,
// }) {
// return _currentDownloadMessage?.msgID == msgID;
// }
/// function for checking if message is in downloading queue
/// [msgID] (required) messageID
/// returns bool value whether message is in downloading queue
// bool isInDownloadQueue({
// required msgID,
// }) {
// return _downloadQueue.indexWhere((element) => element.msgID == msgID) > -1;
// }
// downloadMessage({
// required String msgID,
// required int messageType,
// required int imageType,
// required bool isSnapshot,
// }) {
// _isDownloading = true;
// TencentCloudChat.instance.chatSDKInstance.manager.getMessageManager().downloadMessage(msgID: msgID, messageType: messageType, imageType: imageType, isSnapshot: isSnapshot).then((value) {
// if (value.code != 0) {
// _isDownloading = false;
// startDownload();
// }
// TencentCloudChat.instance.logInstance.console(
// componentName: _tag,
// logs: "start downlaod message ($msgID) ${value.toJson()}",
// logLevel: TencentCloudChatLogLevel.debug,
// );
// });
// }
/// ==== Common Functions ====
// Convert the message data to a JSON object.
@override
Map<String, dynamic> toJson() {
return Map<String, dynamic>.from({"messageHighlighted": _messageHighlighted});
}