perf: 优化未读消息提示

This commit is contained in:
kuaifan
2023-02-07 09:07:00 +08:00
parent 2ebb963342
commit 0f0da2ad27
5 changed files with 16 additions and 36 deletions

View File

@@ -79,9 +79,11 @@ class WebSocketDialog extends AbstractModel
$unreadBuilder = WebSocketDialogMsgRead::whereDialogId($this->id)->whereUserid($userid)->whereReadAt(null);
$this->unread = $unreadBuilder->count();
$this->mention = 0;
$this->first_umid = 0; // 第一条未读消息
$this->last_umid = 0;
if ($this->unread > 0) {
$this->mention = $unreadBuilder->clone()->whereMention(1)->count();
$this->first_umid = intval($unreadBuilder->clone()->orderBy('msg_id')->value('msg_id'));
$this->last_umid = intval($unreadBuilder->clone()->orderByDesc('msg_id')->value('msg_id'));
}
$this->mark_unread = $this->mark_unread ?? $dialogUserFun('mark_unread');