事件监听回调感觉不对

若安 1天前 50

两个问题:

1.我在第一次主动给别人发消息的时候,conversationInfoUpdate事件不会触发,只有在对方给我发消息的时候才会触发。不应该是我在第一次发送完消息后就产生一个新的会话吗,这个事件应该立即触发才对呀。

2.我在监听receiveMsg事件的时候,我前面发送了3个消息,但是对方给我回了一个消息之后这个事件就立马触发了4次,前三次返回的消息是我发送的,第4次返回才是对方发送的。 正常来说,要么我在发送完消息之后立马触发receiveMsg事件,要么就在对方发送过来消息后,只有发送过来的这条消息才会触发这个事件,也就是只触发这一次。

最新回复 (7)
  • HeavyRain 1天前
    引用 2
    demo上有这些问题吗
  • 若安 1天前
    引用 3
    我说的第二个问题demo里是有的,第一个问题我没办法在demo里测试,因为我都是在不加好友的状态下进行聊天的
  • 若安 1天前
    引用 4
    HeavyRain demo上有这些问题吗
    我说的第二个问题demo里是有的,第一个问题我没办法在demo里测试,因为我都是在不加好友的状态下进行聊天的
  • x86 1天前
    引用 5

    第二个问题,因为 web 端本地是不持久化存储消息的,所以收到消息时,会把上次收到消息,到这次收到消息之间的消息都拉取,这可能会包含自己发送的消息。

    demo 在上层收到消息的监听里面,会判断本地是否已存在,如果已存在的话,对消息进行更新;否则插入。

            wfc.eventEmitter.on(EventType.ReceiveMessage, (msg, hasMore) => {
    //...
    
     // 会把下来加载更多加载的历史消息给清理了
                    let lastTimestamp = 0;
                    let msgListLength = conversationState.currentConversationMessageList.length;
                    if (msgListLength > 0) {
                        lastTimestamp = conversationState.currentConversationMessageList[msgListLength - 1].timestamp;
                    }
                    this._patchMessage(msg, lastTimestamp);
                    let msgIndex = conversationState.currentConversationMessageList.findIndex(m => {
                        return m.messageId === msg.messageId
                            || (gt(m.messageUid, 0) && eq(m.messageUid, msg.messageUid))
                            || (m.messageContent.type === MessageContentType.Streaming_Text_Generating
                                && (msg.messageContent.type === MessageContentType.Streaming_Text_Generating || msg.messageContent.type === MessageContentType.Streaming_Text_Generated)
                                && m.messageContent.streamId === msg.messageContent.streamId
                            )
                    });
                    if (msgIndex > -1) {
                        // FYI: https://v2.vuejs.org/v2/guide/reactivity#Change-Detection-Caveats
                        conversationState.currentConversationMessageList.splice(msgIndex, 1, msg);
                        console.log('msg duplicate, update message')
                        return;
                    } else {
                        let firstMsg = conversationState.currentConversationMessageList[0];
                        if(firstMsg && lt(msg.timestamp, firstMsg.timestamp)) {
                            console.log('msg timestamp is less than first msg, maybe update old message content, ignore')
                            return;
                        }
                    }
    
    //...
    
  • x86 1天前
    引用 6
    第一个问题,我们可以加一下,让发消息时,也触发 `conversationInfoUpdate`事件
  • 若安 1天前
    引用 7
    x86 第一个问题,我们可以加一下,让发消息时,也触发 `conversationInfoUpdate`事件
    主要我们是做房地产项目的,想让客户直接可以对经纪人聊天,加好友的话太麻烦了
  • x86 23小时前
    引用 8
    若安 主要我们是做房地产项目的,想让客户直接可以对经纪人聊天,加好友的话太麻烦了
    和是否是好友没关系,已经添加了,给我们发邮件要下新版本
返回