diff --git a/app/Http/Controllers/Api/DialogController.php b/app/Http/Controllers/Api/DialogController.php
index ffdc7ed7a..0bf26f070 100755
--- a/app/Http/Controllers/Api/DialogController.php
+++ b/app/Http/Controllers/Api/DialogController.php
@@ -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)
diff --git a/app/Models/WebSocketDialog.php b/app/Models/WebSocketDialog.php
index 108e49c7f..164d9cfdb 100644
--- a/app/Models/WebSocketDialog.php
+++ b/app/Models/WebSocketDialog.php
@@ -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');
diff --git a/resources/assets/js/pages/manage/components/DialogWrapper.vue b/resources/assets/js/pages/manage/components/DialogWrapper.vue
index d22f37e76..963614f73 100644
--- a/resources/assets/js/pages/manage/components/DialogWrapper.vue
+++ b/resources/assets/js/pages/manage/components/DialogWrapper.vue
@@ -98,10 +98,10 @@
-
+
- {{$L(`未读消息${beforeUnread.unread}条`)}}
+ {{$L(`未读消息${beforeUnread}条`)}}
@@ -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(_ => {
diff --git a/resources/assets/js/store/actions.js b/resources/assets/js/store/actions.js
index 501b60b62..1e3f8bb00 100644
--- a/resources/assets/js/store/actions.js
+++ b/resources/assets/js/store/actions.js
@@ -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 => {
diff --git a/resources/assets/js/store/state.js b/resources/assets/js/store/state.js
index c2793565f..61b800500 100644
--- a/resources/assets/js/store/state.js
+++ b/resources/assets/js/store/state.js
@@ -82,7 +82,6 @@ export default {
dialogHistory: [],
dialogInputCache: [],
dialogMsgTransfer: {time: 0},
- dialogBeforeUnreads: [],
// 文件
fileLists: [],