flutter 发送文件后,从getHistoryMessages历史消息获取,文件获取不到。

jmessage
ios
标签: #<Tag:0x00007f83e7b4d170> #<Tag:0x00007f83e743bfa8>

(Gxzlolo) #1

获取文件不存在
调用方法 await jmessage.downloadFile(target: target, messageId: messageId);
{PlatformException(Error 1, cann’t find this message!, The operation couldn’t be completed. (cann’t find this message! error 1.))}
msgId_1559637962538308


#2

提供一下你的操作步骤,插件的版本号


(Gxzlolo) #3

jmessage_flutter: 0.0.16

 void messageSendData(
      String fromusername,
      String path,
      JMMessageType type,
      JMConversationType conversationType,
      Map<dynamic, dynamic> customObject) async {
    var msg = returnJMConversationType(fromusername, conversationType);
    var message;
   if (type == JMMessageType.file) {
      //type = file 时 path 为必填。
      message = await jmessage.createMessage(
          type: type, targetType: msg, path: path, extras: customObject);
      message.fileName = path;
    } 

    try {
      await jmessage.sendMessage(
          message: message,
          sendOption: JMMessageSendOptions.fromJson({
            'isShowNotification': true,
            'isRetainOffline': true,
          }));
    } catch (Expection) {}
  }

获取历史消息

Future loadData() async {
    status = CommonPageStatus.RUNNING;
    if (messageStateModel == null) {
      messageStateModel = ScopedModel.of<MainStateModel>(context);
    }
    messageStateModel
        .getFromHistorMessages(
            this.widget.username.toString(), this.widget.conversationType, 10)
        .then((msgList) {
      for (int i = 0; i < msgList.length; i++) {
        ChatItem chatItem = new ChatItem();
        var msg = msgList[i];
        JMUserInfo info = msg.target;
        chatItem.username = info.username;
        if (info.username.contains(this.widget.username.toString())) {
          chatItem.type = 0;
          chatItem.defaultAvatar =
              (info.avatarThumbPath == null || info.avatarThumbPath.isEmpty
                  ? 'images/icon_head.png'
                  : info.avatarThumbPath);
        } else {
          chatItem.type = 1;
          chatItem.defaultAvatar =
              (info.avatarThumbPath == null || info.avatarThumbPath.isEmpty
                  ? 'images/pic_touxiang.png'
                  : info.avatarThumbPath);
        }

      if (msg is JMFileMessage) {
          chatItem.jmType = 'file';
          chatItem.customerObject = msg.extras;
          chatItem.path = msg.fileName;
          // print('fileName:${msg.fileName}');
          if (msg.fileName == "") {
            messageStateModel
                .downloadFiles(msg.from.targetType, msg.id)
                .then((value) {
              if (value != null) {
                Map res = value;
                if (res['filePath'] != null) {
                  msg.fileName = res['filePath'];
                  chatItem.path = msg.fileName;
                }
              }
            });
          }
        } 
        int createTime = 0;
        if (msg != null) {
          createTime = msg.createTime;
        }
        chatItem.date = covertTimestamp(createTime, true);
        this.items.add(chatItem);
      }
      setState(() {});
      if (this.items.length > 0) {
        if (_scrollController != null) {
          Timer(
              Duration(milliseconds: 100),
              () => _scrollController
                  .jumpTo(_scrollController.position.maxScrollExtent));
        }
      }
    });
  }

#4

你这个消息的 Message ID 确定是正确的吗?根据这个 ID 并不能查到你这条消息

请提供下你详细的操作步骤和所传的值


(Gxzlolo) #5

这个是历史消息获取到的数据


#6

image
3787081673
用这个 ID 取一下试试


(Gxzlolo) #7



messageId:3787081673


(Gxzlolo) #8

(Gxzlolo) #9

能不能帮忙解决一下,我所有功能都实现了,就等获取文件


#10

研发这边找到了原因,会修改下插件代码,由于排期紧张,修改完会直接给你来测试看是否 OK


(Gxzlolo) #11

可以让我跟研发加QQ284056367吗?我们可以讨论,到时候我把我做的开源.


(Gxzlolo) #12

发语音,也获取不到数据。


#13

提供下你的代码

发语音和接收语音,下载语音文件的


(Gxzlolo) #14

下载语音

Future downloadVoiceFiles(dynamic target, String messageId) async {
    try {
      await jmessage.downloadVoiceFile(target: target, messageId: messageId);
    } catch (Exception) {
      print("downloadVoiceFile:{$Exception}");
    }
  }

getHistoryMessages 消息历史数据列表

 if (msg is JMVoiceMessage) {
          chatItem.jmType = 'voice';
          chatItem.path = msg.path;
          chatItem.customerObject = msg.extras;
          if (msg.path == "") {
            messageStateModel
                .downloadVoiceFiles(msg.from.targetType, msg.id)
                .then((value) {
              if (value != null) {
                Map res = value;
                if (res['filePath'] != null) {
                  msg.path = res['filePath'];
                  chatItem.path = msg.path;
                }
              }
            });
          }
        }

发语音

void messageSendData(
      String fromusername,
      String path,
      JMMessageType type,
      JMConversationType conversationType,
      Map<dynamic, dynamic> customObject)
   async {
    var msg = returnJMConversationType(fromusername, conversationType);
    var message;
     if (type == JMMessageType.voice) {
      //type = voice 时 path 为必填。
      message =
          await jmessage.createMessage(type: type, targetType: msg, path: path);
    }

    try {
      await jmessage.sendMessage(
          message: message,
          sendOption: JMMessageSendOptions.fromJson({
            'isShowNotification': true,
            'isRetainOffline': true,
          }));
    } catch (Expection) {}

  }

#15

文件的问题,升级到 0.0.17 后测试一下


(Gxzlolo) #16


(Gxzlolo) #17

Because uservice depends on jmessage_flutter 0.0.17 which doesn’t match any versions, version solving failed.

pub get failed (1)

exit code 1
更新不到最新版本


#18

远程的由于研发这边网络的原因没更新上去,目前只能采取在 GItHub手动下载的方式


(Gxzlolo) #19

用手机流量很快的,还是传一下吧!


(Gxzlolo) #20

上传了嘛???