Skip to content

修复单聊渲染消息的bug - #2

Open
smileexpression wants to merge 1 commit into
GuoZhaoran:masterfrom
smileexpression:fix-view-home-bug
Open

修复单聊渲染消息的bug#2
smileexpression wants to merge 1 commit into
GuoZhaoran:masterfrom
smileexpression:fix-view-home-bug

Conversation

@smileexpression

Copy link
Copy Markdown

问题描述

现有用户A,B和C,每个用户互相添加了另外两个用户。当A发送消息给B时,B会渲染出A和C发送同一条消息给B。发现是 app/view/chat/main.html 文件中,对单聊消息渲染的判断条件出了问题。

原判断条件

item.ismine? item.msg.dstid==msgcontext.dstid : item.msg.dstid==msgcontext.userid

如果消息是我发的 (ismine 为真),那么消息的目标 dstid 必须等于当前聊天上下文 msgcontext.dstid;如果消息不是我发的,那么消息的目标 dstid 必须等于我的用户 ID userid

这个逻辑的问题在于,对于我收到的消息,只检查了消息是否发送给我,但没有检查消息的发送者是否是当前的聊天对象。因此会出现B看到A发送的消息同时渲染在了A和C里面的问题。

修改后判断条件

item.ismine? item.msg.dstid==msgcontext.dstid : item.msg.userid==msgcontext.dstid

如果消息不是我发的,那么消息的发送者 userid 必须等于当前聊天上下文 dstid

那为什么原判断条件不需要了呢?

item.msg.dstid==msgcontext.userid

服务端分配消息时,已经根据消息的dstid,分配到该用户的管道中,因此,用户收到的消息一定是满足该条件的(前提是:消息不是我发的 (ismine 为假))。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant