mirror of
https://github.com/kuaifan/dootask.git
synced 2026-03-17 19:23:26 +00:00
perf: 优化未读消息提示
This commit is contained in:
parent
2ebb963342
commit
0f0da2ad27
@ -457,15 +457,6 @@ class DialogController extends AbstractController
|
|||||||
->where('web_socket_dialog_msgs.id', '<', $last->id)
|
->where('web_socket_dialog_msgs.id', '<', $last->id)
|
||||||
->orderByDesc('web_socket_dialog_msgs.id')
|
->orderByDesc('web_socket_dialog_msgs.id')
|
||||||
->value('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['list'] = $list;
|
||||||
$data['time'] = Base::time();
|
$data['time'] = Base::time();
|
||||||
@ -1050,6 +1041,7 @@ class DialogController extends AbstractController
|
|||||||
switch ($type) {
|
switch ($type) {
|
||||||
case 'read':
|
case 'read':
|
||||||
$data['unread'] = 0;
|
$data['unread'] = 0;
|
||||||
|
$data['first_umid'] = 0;
|
||||||
WebSocketDialogMsgRead::whereUserid($user->userid)
|
WebSocketDialogMsgRead::whereUserid($user->userid)
|
||||||
->whereReadAt(null)
|
->whereReadAt(null)
|
||||||
->whereDialogId($dialogId)
|
->whereDialogId($dialogId)
|
||||||
|
|||||||
@ -79,9 +79,11 @@ class WebSocketDialog extends AbstractModel
|
|||||||
$unreadBuilder = WebSocketDialogMsgRead::whereDialogId($this->id)->whereUserid($userid)->whereReadAt(null);
|
$unreadBuilder = WebSocketDialogMsgRead::whereDialogId($this->id)->whereUserid($userid)->whereReadAt(null);
|
||||||
$this->unread = $unreadBuilder->count();
|
$this->unread = $unreadBuilder->count();
|
||||||
$this->mention = 0;
|
$this->mention = 0;
|
||||||
|
$this->first_umid = 0; // 第一条未读消息
|
||||||
$this->last_umid = 0;
|
$this->last_umid = 0;
|
||||||
if ($this->unread > 0) {
|
if ($this->unread > 0) {
|
||||||
$this->mention = $unreadBuilder->clone()->whereMention(1)->count();
|
$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->last_umid = intval($unreadBuilder->clone()->orderByDesc('msg_id')->value('msg_id'));
|
||||||
}
|
}
|
||||||
$this->mark_unread = $this->mark_unread ?? $dialogUserFun('mark_unread');
|
$this->mark_unread = $this->mark_unread ?? $dialogUserFun('mark_unread');
|
||||||
|
|||||||
@ -98,10 +98,10 @@
|
|||||||
</div>
|
</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">
|
<div class="top-unread" @click="goBeforeUnread">
|
||||||
<Icon v-if="beforeLoad" type="ios-loading" class="icon-loading"></Icon>
|
<Icon v-if="beforeLoad" type="ios-loading" class="icon-loading"></Icon>
|
||||||
<span>{{$L(`未读消息${beforeUnread.unread}条`)}}</span>
|
<span>{{$L(`未读消息${beforeUnread}条`)}}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -548,7 +548,6 @@ export default {
|
|||||||
'dialogMsgs',
|
'dialogMsgs',
|
||||||
'dialogTodos',
|
'dialogTodos',
|
||||||
'dialogMsgTransfer',
|
'dialogMsgTransfer',
|
||||||
'dialogBeforeUnreads',
|
|
||||||
'cacheDialogs',
|
'cacheDialogs',
|
||||||
'wsOpenNum',
|
'wsOpenNum',
|
||||||
'touchBackInProgress',
|
'touchBackInProgress',
|
||||||
@ -765,8 +764,14 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
beforeUnread() {
|
beforeUnread() {
|
||||||
const before = this.dialogBeforeUnreads.find(({id}) => id === this.dialogId)
|
const {unread, first_umid} = this.dialogData
|
||||||
return before || null
|
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() {
|
goBeforeUnread() {
|
||||||
if (!this.beforeUnread || this.beforeLoad) {
|
if (this.beforeUnread === 0 || this.beforeLoad) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
this.beforeLoad = true
|
this.beforeLoad = true
|
||||||
const {first_id} = this.beforeUnread
|
const {first_umid} = this.dialogData
|
||||||
this.$store.dispatch("dialogMsgMark", {
|
this.$store.dispatch("dialogMsgMark", {
|
||||||
dialog_id: this.dialogId,
|
dialog_id: this.dialogId,
|
||||||
type: 'read'
|
type: 'read'
|
||||||
}).then(_ => {
|
}).then(_ => {
|
||||||
this.onPositionId(first_id)
|
this.onPositionId(first_umid)
|
||||||
}).catch(({msg}) => {
|
}).catch(({msg}) => {
|
||||||
$A.modalError(msg)
|
$A.modalError(msg)
|
||||||
}).finally(_ => {
|
}).finally(_ => {
|
||||||
|
|||||||
18
resources/assets/js/store/actions.js
vendored
18
resources/assets/js/store/actions.js
vendored
@ -2507,18 +2507,6 @@ export default {
|
|||||||
dispatch("saveDialogTodo", resData.todo)
|
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)
|
dispatch("saveDialogMsg", resData.list)
|
||||||
resolve(result)
|
resolve(result)
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
@ -2596,12 +2584,6 @@ export default {
|
|||||||
url: 'dialog/msg/mark',
|
url: 'dialog/msg/mark',
|
||||||
data,
|
data,
|
||||||
}).then(result => {
|
}).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)
|
dispatch("saveDialog", result.data)
|
||||||
resolve(result)
|
resolve(result)
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
|
|||||||
1
resources/assets/js/store/state.js
vendored
1
resources/assets/js/store/state.js
vendored
@ -82,7 +82,6 @@ export default {
|
|||||||
dialogHistory: [],
|
dialogHistory: [],
|
||||||
dialogInputCache: [],
|
dialogInputCache: [],
|
||||||
dialogMsgTransfer: {time: 0},
|
dialogMsgTransfer: {time: 0},
|
||||||
dialogBeforeUnreads: [],
|
|
||||||
|
|
||||||
// 文件
|
// 文件
|
||||||
fileLists: [],
|
fileLists: [],
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user