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

@ -457,15 +457,6 @@ class DialogController extends AbstractController
->where('web_socket_dialog_msgs.id', '<', $last->id)
->orderByDesc('web_socket_dialog_msgs.id')
->value('id'));
//
if (empty($position_id)) {
$unreadBuilder = WebSocketDialogMsgRead::whereDialogId($dialog_id)->whereUserid($user->userid)->whereReadAt(null)->where('msg_id', '<', $last->id);
$unread = $unreadBuilder->count();
$data['before'] = [
'unread' => $unread,
'first_id' => $unread > 0 ? intval($unreadBuilder->orderBy('msg_id')->value('msg_id')) : 0,
];
}
}
$data['list'] = $list;
$data['time'] = Base::time();
@ -1050,6 +1041,7 @@ class DialogController extends AbstractController
switch ($type) {
case 'read':
$data['unread'] = 0;
$data['first_umid'] = 0;
WebSocketDialogMsgRead::whereUserid($user->userid)
->whereReadAt(null)
->whereDialogId($dialogId)

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');

View File

@ -98,10 +98,10 @@
</div>
<!--顶部提示-->
<div v-if="beforeUnread" class="dialog-top" :class="{'down': tagShow}">
<div v-if="beforeUnread > 0" class="dialog-top" :class="{'down': tagShow}">
<div class="top-unread" @click="goBeforeUnread">
<Icon v-if="beforeLoad" type="ios-loading" class="icon-loading"></Icon>
<span>{{$L(`未读消息${beforeUnread.unread}`)}}</span>
<span>{{$L(`未读消息${beforeUnread}`)}}</span>
</div>
</div>
@ -548,7 +548,6 @@ export default {
'dialogMsgs',
'dialogTodos',
'dialogMsgTransfer',
'dialogBeforeUnreads',
'cacheDialogs',
'wsOpenNum',
'touchBackInProgress',
@ -765,8 +764,14 @@ export default {
},
beforeUnread() {
const before = this.dialogBeforeUnreads.find(({id}) => id === this.dialogId)
return before || null
const {unread, first_umid} = this.dialogData
if (unread > 0
&& first_umid > 0
&& this.allMsgs.length > 0
&& this.allMsgs.findIndex(({id}) => id == first_umid) === -1) {
return unread
}
return 0
}
},
@ -2219,17 +2224,17 @@ export default {
},
goBeforeUnread() {
if (!this.beforeUnread || this.beforeLoad) {
if (this.beforeUnread === 0 || this.beforeLoad) {
return;
}
//
this.beforeLoad = true
const {first_id} = this.beforeUnread
const {first_umid} = this.dialogData
this.$store.dispatch("dialogMsgMark", {
dialog_id: this.dialogId,
type: 'read'
}).then(_ => {
this.onPositionId(first_id)
this.onPositionId(first_umid)
}).catch(({msg}) => {
$A.modalError(msg)
}).finally(_ => {

View File

@ -2507,18 +2507,6 @@ export default {
dispatch("saveDialogTodo", resData.todo)
}
//
const before = Object.assign({id: data.dialog_id}, resData.before || {});
const index = state.dialogBeforeUnreads.findIndex(({id}) => id == data.dialog_id);
if (before.unread) {
if (index > -1) {
state.dialogBeforeUnreads.splice(index, 1, before);
} else {
state.dialogBeforeUnreads.push(before);
}
} else if (index > -1) {
state.dialogBeforeUnreads.splice(index, 1);
}
//
dispatch("saveDialogMsg", resData.list)
resolve(result)
}).catch(e => {
@ -2596,12 +2584,6 @@ export default {
url: 'dialog/msg/mark',
data,
}).then(result => {
if (data.type === 'read') {
const index = state.dialogBeforeUnreads.findIndex(({id}) => id == data.dialog_id)
if (index > -1) {
state.dialogBeforeUnreads.splice(index, 1)
}
}
dispatch("saveDialog", result.data)
resolve(result)
}).catch(e => {

View File

@ -82,7 +82,6 @@ export default {
dialogHistory: [],
dialogInputCache: [],
dialogMsgTransfer: {time: 0},
dialogBeforeUnreads: [],
// 文件
fileLists: [],