perf: 优化消息对话排序

This commit is contained in:
kuaifan 2022-01-23 15:01:58 +08:00
parent 004bf36dc1
commit 493cf7d46a
4 changed files with 13 additions and 25 deletions

View File

@ -345,7 +345,7 @@ export default {
msgAllUnread() {
let num = 0;
this.cacheDialogs.map(({unread}) => {
this.cacheDialogs.some(({unread}) => {
if (unread) {
num += unread;
}

View File

@ -329,7 +329,6 @@ export default {
sendSuccess(data) {
this.$store.dispatch("saveDialogMsg", data);
this.$store.dispatch("increaseTaskMsgNum", this.dialogId);
this.$store.dispatch("moveDialogTop", this.dialogId);
this.$store.dispatch("updateDialogLastMsg", data);
this.onActive();
},

View File

@ -124,7 +124,14 @@ export default {
dialogList() {
const {dialogActive, dialogKey} = this;
if (dialogActive == '' && dialogKey == '') {
return this.cacheDialogs.filter(({name}) => name !== undefined);
return this.cacheDialogs.filter(({name, last_at}) => {
if (name === undefined) {
return false;
}
return last_at;
}).sort((a, b) => {
return $A.Date(b.last_at) - $A.Date(a.last_at);
});
}
return this.cacheDialogs.filter(({name, type, group_type, last_msg, last_at}) => {
if (name === undefined) {
@ -159,14 +166,14 @@ export default {
}
return true;
}).sort((a, b) => {
return $A.Date(a.last_at) - $A.Date(b.last_at);
return $A.Date(b.last_at) - $A.Date(a.last_at);
})
},
msgUnread() {
return function (type) {
let num = 0;
this.cacheDialogs.map((dialog) => {
this.cacheDialogs.some((dialog) => {
if (dialog.unread) {
switch (type) {
case 'project':
@ -231,10 +238,10 @@ export default {
const dialog = this.dialogList.find(({unread}) => unread > 0)
if (dialog) {
try {
this.$refs[`dialog_${dialog.id}`][0].scrollIntoView({behavior: "smooth"});
this.$refs[`dialog_${dialog.id}`][0].scrollIntoView();
} catch (e) {
scrollIntoView(this.$refs[`dialog_${dialog.id}`][0], {
behavior: 'smooth',
behavior: 'instant',
inline: 'end',
})
}

View File

@ -1749,22 +1749,6 @@ export default {
});
},
/**
* 将会话移动到首位
* @param state
* @param dialog_id
*/
moveDialogTop({state}, dialog_id) {
$A.execMainDispatch("moveDialogTop", dialog_id)
//
const index = state.cacheDialogs.findIndex(({id}) => id == dialog_id);
if (index > -1) {
const tmp = $A.cloneJSON(state.cacheDialogs[index]);
state.cacheDialogs.splice(index, 1);
state.cacheDialogs.unshift(tmp);
}
},
/**
* 忘记对话数据
* @param state
@ -2026,8 +2010,6 @@ export default {
if (dialog) {
// 新增未读数
dialog.unread++;
// 移动到首位
dispatch("moveDialogTop", dialog_id);
}
Store.set('dialogMsgPush', data);
}