openimsdk / open-im-sdk-reactnative

IM ReactNative
MIT License
38 stars 53 forks source link

[BUG] call getAdvancedHistoryMessageList method, output getHistoryMessageFailed #41

Open OrrinHatch opened 1 week ago

OrrinHatch commented 1 week ago

OpenIM Server Version

3.8.0

Operating System and CPU Architecture

Linux (AMD)

Deployment Method

Docker Deployment

Bug Description and Steps to Reproduce

 const prevList = [...get().historyMessageList];
    await OpenIMSDKRN.getAdvancedHistoryMessageList(
      {
        count: GET_HISTORY_MESSAGE_COUNT,
        lastMinSeq: loadMore ? get().lastMinSeq : 0,
        startClientMsgID: loadMore ? prevList[prevList.length - 1]?.clientMsgID : '',
        conversationID,
      },
      uuidv4(),
    )
      .then((data) => {
        // Call success
        console.log('getAdvancedHistoryMessageList: ', data);

        if (conversationID !== useConversationStore.getState().currentConversation?.conversationID) return;

        (data.messageList as ExMessageItem[]).map((message, idx) => {
          if (!idx) {
            message.gapTime = true;
            return null;
          }
          const prevTime = data.messageList[idx - 1]?.sendTime;
          if (message.sessionType === SessionType.Notification) {
            (data.messageList[idx - 1] as ExMessageItem).gapTime = message.sendTime - prevTime > 300000;
          } else {
            message.gapTime = message.sendTime - prevTime > 300000;
          }
          return null;
        });
        const nextList = [...(loadMore ? prevList : []), ...data.messageList.reverse()];

        set(() => ({
          lastMinSeq: data.lastMinSeq,
          hasMore: data.messageList.length !== 0,
          historyMessageList: nextList,
        }));
      })
      .catch((error) => {
        console.log('error:', error)
        console.error('获取历史消息失败!:', error.errCode, error.errMsg);
        Toast.fail(getLocale('toast.getHistoryMessageFailed'));
        set(() => ({
          lastMinSeq: 0,
          hasMore: false,
          historyMessageList: [],
        }));
      });

log output:

error: [Error: error *errors.withStack not implement CodeError: GetMessage failed: record not found]
Unable to find module for RedBox

'获取历史消息失败!:', undefined, undefined
Unable to find module for RedBox

'getAdvancedHistoryMessageList: ', { lastMinSeq: 1,
  errMsg: '',
  isEnd: false,
  messageList: 
   [ { recvID: '685e737d298f41cf82053a445c48755f',
       attachedInfoElem: 
        { hasReadTime: 0,
          isEncryption: false,
          burnDuration: 0,
          inEncryptStatus: false,
          isPrivateChat: false,
          groupHasReadInfo: { groupMemberCount: 0, hasReadCount: 0 } },
       isRead: false,
       senderNickname: '露露',
       notificationElem: { detail: '{"fromToUserID":{"fromUserID":"685e737d298f41cf82053a445c48755f","toUserID":"ac2800c35cd94bbe94cf16f7959760d9"},"handleMsg":"","friendVersion":0,"friendVersionID":""}' },
       seq: 1,
       contentType: 1201,
       serverMsgID: '679d36765d7280c2f20ba84591a33fdd',
       senderPlatformID: 0,
       sendTime: 1726040987906,
       sendID: 'ac2800c35cd94bbe94cf16f7959760d9',
       clientMsgID: '9b701db8772155bef78e882778aea2ec',
       senderFaceUrl: 'https://xxxx.oss-cn-hongkong.aliyuncs.com/imgs/f29e6fce9add4afeb6168deda0842bc1.jpg',
       createTime: 1726040987906,
       status: 2,
       msgFrom: 200,
       sessionType: 1 },
     { recvID: 'ac2800c35cd94bbe94cf16f7959760d9',
       attachedInfoElem: 
        { hasReadTime: 1728109021085,
          isEncryption: false,
          burnDuration: 0,
          inEncryptStatus: false,
          isPrivateChat: false,
          groupHasReadInfo: { groupMemberCount: 0, hasReadCount: 0 } },
       isRead: true,
       senderNickname: 'chatTest12',
       notificationElem: { detail: '{"fromToUserID":{"fromUserID":"ac2800c35cd94bbe94cf16f7959760d9","toUserID":"685e737d298f41cf82053a445c48755f"},"handleMsg":"","friendVersion":0,"friendVersionID":""}' },
       seq: 2,
       contentType: 1201,
       serverMsgID: '68760dd51ee51bb63502b977256f573d',
       senderPlatformID: 0,
       sendTime: 1726040987987,
       sendID: '685e737d298f41cf82053a445c48755f',
       clientMsgID: 'dd029a7e9a82192e1be7274973c793dd',
       senderFaceUrl: 'https://xxxx.oss-cn-hongkong.aliyuncs.com/imgs/f29e6fce9add4afeb6168deda0842bc1.jpg',
       createTime: 1726040987987,
       status: 2,
       msgFrom: 200,
       sessionType: 1 } ],
  errCode: 0 }

Screenshots Link

No response

OrrinHatch commented 1 week ago

Why does the call first fail and then succeed in returning data? Hi bro, why ?

OrrinHatch commented 1 week ago

First, it attempts to retrieve the local messages. When no local messages are found, an error is thrown. After that, it fetches the messages from the server ?

lgz5689 commented 6 days ago

If there is no local data, the server is requested and the data is returned