mirror of
https://github.com/kuaifan/dootask.git
synced 2026-02-08 07:15:36 +00:00
perf: 优化消息已读逻辑
This commit is contained in:
parent
c46fd080df
commit
dace1dd1f3
@ -230,7 +230,7 @@ class WebSocketDialog extends AbstractModel
|
||||
}
|
||||
// 会员数据处理
|
||||
if (isset($data['user_at']) && !isset($data['user_ms'])) {
|
||||
$time = Carbon::parse($fields['user_at']);
|
||||
$time = Carbon::parse($data['user_at']);
|
||||
$data['user_at'] = $time->toDateTimeString('millisecond');
|
||||
$data['user_ms'] = $time->valueOf();
|
||||
}
|
||||
|
||||
@ -47,6 +47,8 @@ use Carbon\Carbon;
|
||||
*/
|
||||
class WebSocketDialogUser extends AbstractModel
|
||||
{
|
||||
protected $dateFormat = 'Y-m-d H:i:s.u';
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
*/
|
||||
|
||||
24
resources/assets/js/functions/common.js
vendored
24
resources/assets/js/functions/common.js
vendored
@ -347,10 +347,12 @@ const timezone = require("dayjs/plugin/timezone");
|
||||
* @returns {*}
|
||||
*/
|
||||
cloneJSON(myObj) {
|
||||
if (typeof (myObj) !== 'object') return myObj;
|
||||
if (myObj === null) return myObj;
|
||||
//
|
||||
return $A.jsonParse($A.jsonStringify(myObj))
|
||||
try {
|
||||
return structuredClone(myObj);
|
||||
} catch (e) {
|
||||
if (typeof myObj !== 'object' || myObj === null) return myObj;
|
||||
return $A.jsonParse($A.jsonStringify(myObj))
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
@ -1255,7 +1257,19 @@ const timezone = require("dayjs/plugin/timezone");
|
||||
return sliced.join('') + suffix;
|
||||
}
|
||||
return sliced.join('');
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取两个数组后面的交集
|
||||
* @param arr1
|
||||
* @param arr2
|
||||
* @returns {*}
|
||||
*/
|
||||
getLastSameElements(arr1, arr2) {
|
||||
return arr1.slice(-(arr1.filter((item, index) =>
|
||||
item === arr2[arr2.length - arr1.length + index]
|
||||
).length));
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
@ -832,6 +832,7 @@ export default {
|
||||
scrollToBottomRefresh: false, // 滚动到底部重新获取消息
|
||||
androidKeyboardVisible: false, // Android键盘是否可见
|
||||
replyMsgAutoMention: false, // 允许回复消息后自动@
|
||||
waitUnreadData: {}, // 等待未读数据
|
||||
}
|
||||
},
|
||||
|
||||
@ -1215,7 +1216,7 @@ export default {
|
||||
|
||||
dialogId: {
|
||||
handler(dialog_id, old_id) {
|
||||
this.getDialogBase(dialog_id)
|
||||
this.getDialogBase(dialog_id, old_id)
|
||||
//
|
||||
this.$store.dispatch('closeDialog', old_id)
|
||||
//
|
||||
@ -1449,8 +1450,22 @@ export default {
|
||||
/**
|
||||
* 获取会话基本信息
|
||||
* @param dialog_id
|
||||
* @param old_id
|
||||
*/
|
||||
getDialogBase(dialog_id) {
|
||||
getDialogBase(dialog_id, old_id = null) {
|
||||
if (old_id) {
|
||||
const ens = []
|
||||
const ids = this.allMsgs.filter(item => item.read_at === null && item.userid != this.userId).map(item => item.id)
|
||||
const enters = this.$refs.scroller?.$el.querySelectorAll('.item-enter') || []
|
||||
for (const enter of enters) {
|
||||
const id = $A.runNum(enter.querySelector(".dialog-view")?.getAttribute('data-id'));
|
||||
if (id && !ids.includes(id)) {
|
||||
ids.push(id)
|
||||
}
|
||||
}
|
||||
this.waitUnreadData[old_id] = $A.getLastSameElements(ids, ens)
|
||||
}
|
||||
|
||||
if (!dialog_id) {
|
||||
return
|
||||
}
|
||||
@ -1473,10 +1488,20 @@ export default {
|
||||
dialog_id,
|
||||
msg_id: this.msgId,
|
||||
msg_type: this.msgType,
|
||||
}).then(_ => {
|
||||
}).then(({data}) => {
|
||||
this.openId = dialog_id
|
||||
this.msgPrepared = true
|
||||
//
|
||||
if (this.dialogId !== dialog_id) {
|
||||
let unreadIds = this.waitUnreadData[dialog_id] || []
|
||||
if (unreadIds.length > 0) {
|
||||
const ids = [...data.list.map(item => item.id)].reverse();
|
||||
$A.getLastSameElements(unreadIds, ids).forEach(id => {
|
||||
this.$store.dispatch("dialogMsgRead", {id, dialog_id})
|
||||
})
|
||||
}
|
||||
}
|
||||
//
|
||||
setTimeout(_ => {
|
||||
this.onSearchMsgId()
|
||||
this.positionShow = this.readTimeout === null
|
||||
|
||||
@ -675,7 +675,7 @@ export default {
|
||||
|
||||
columnList() {
|
||||
const {projectId, cacheColumns, allTask} = this;
|
||||
const list = cacheColumns.filter(({project_id}) => {
|
||||
const list = $A.cloneJSON(cacheColumns).filter(({project_id}) => {
|
||||
return project_id == projectId
|
||||
}).sort((a, b) => {
|
||||
if (a.sort != b.sort) {
|
||||
|
||||
2
resources/assets/js/store/state.js
vendored
2
resources/assets/js/store/state.js
vendored
@ -7,7 +7,7 @@ export default {
|
||||
clientId: "",
|
||||
|
||||
// 缓存版本号(如果想升级后清除客户端缓存则修改此参数值)
|
||||
cacheVersion: "v8",
|
||||
cacheVersion: "v9",
|
||||
|
||||
// 窗口是否激活
|
||||
windowActive: true,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user