no message

This commit is contained in:
kuaifan
2024-01-09 19:13:47 +08:00
parent 10a77ee2a9
commit f7df6408ed
4 changed files with 81 additions and 36 deletions

View File

@@ -156,7 +156,11 @@ class WebSocketDialog extends AbstractModel
$this->last_at = $this->last_msg?->created_at;
} else {
// 未读信息
$this->generateUnread($userid);
if (Base::judgeClientVersion("0.34.0")) {
$this->generateUnread($userid);
} else {
$this->generateUnread_03398($userid, $hasData);
}
// 未读标记
$this->mark_unread = $this->mark_unread ?? $dialogUserFun('mark_unread');
// 是否免打扰
@@ -266,6 +270,43 @@ class WebSocketDialog extends AbstractModel
return $this;
}
/**
* 生成未读数据 // todo: 旧版兼容,后续删除
* @param $userid
* @param $positionData
* @return $this
*/
public function generateUnread_03398($userid, $positionData = false)
{
$builder = WebSocketDialogMsgRead::whereDialogId($this->id)->whereUserid($userid)->whereReadAt(null);
$this->unread = $builder->count();
$this->mention = $this->unread > 0 ? $builder->clone()->whereMention(1)->count() : 0;
if ($positionData) {
$array = [];
// @我的消息
if ($this->mention > 0) {
$list = $builder->clone()->whereMention(1)->orderByDesc('msg_id')->take(20)->get();
foreach ($list as $item) {
$array[] = [
'msg_id' => $item->msg_id,
'label' => Doo::translate('@我的消息'),
];
}
}
// 最早一条未读消息
if ($this->unread > 0
&& $first_id = intval($builder->clone()->orderBy('msg_id')->value('msg_id'))) {
$array[] = [
'msg_id' => $first_id,
'label' => '{UNREAD}'
];
}
//
$this->position_msgs = $array;
}
return $this;
}
/**
* 加入聊天室
* @param int|array $userid 加入的会员ID或会员ID组