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'])) {
|
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_at'] = $time->toDateTimeString('millisecond');
|
||||||
$data['user_ms'] = $time->valueOf();
|
$data['user_ms'] = $time->valueOf();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -47,6 +47,8 @@ use Carbon\Carbon;
|
|||||||
*/
|
*/
|
||||||
class WebSocketDialogUser extends AbstractModel
|
class WebSocketDialogUser extends AbstractModel
|
||||||
{
|
{
|
||||||
|
protected $dateFormat = 'Y-m-d H:i:s.u';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
* @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 {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
cloneJSON(myObj) {
|
cloneJSON(myObj) {
|
||||||
if (typeof (myObj) !== 'object') return myObj;
|
try {
|
||||||
if (myObj === null) return myObj;
|
return structuredClone(myObj);
|
||||||
//
|
} catch (e) {
|
||||||
return $A.jsonParse($A.jsonStringify(myObj))
|
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('') + suffix;
|
||||||
}
|
}
|
||||||
return sliced.join('');
|
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, // 滚动到底部重新获取消息
|
scrollToBottomRefresh: false, // 滚动到底部重新获取消息
|
||||||
androidKeyboardVisible: false, // Android键盘是否可见
|
androidKeyboardVisible: false, // Android键盘是否可见
|
||||||
replyMsgAutoMention: false, // 允许回复消息后自动@
|
replyMsgAutoMention: false, // 允许回复消息后自动@
|
||||||
|
waitUnreadData: {}, // 等待未读数据
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -1215,7 +1216,7 @@ export default {
|
|||||||
|
|
||||||
dialogId: {
|
dialogId: {
|
||||||
handler(dialog_id, old_id) {
|
handler(dialog_id, old_id) {
|
||||||
this.getDialogBase(dialog_id)
|
this.getDialogBase(dialog_id, old_id)
|
||||||
//
|
//
|
||||||
this.$store.dispatch('closeDialog', old_id)
|
this.$store.dispatch('closeDialog', old_id)
|
||||||
//
|
//
|
||||||
@ -1449,8 +1450,22 @@ export default {
|
|||||||
/**
|
/**
|
||||||
* 获取会话基本信息
|
* 获取会话基本信息
|
||||||
* @param dialog_id
|
* @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) {
|
if (!dialog_id) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -1473,10 +1488,20 @@ export default {
|
|||||||
dialog_id,
|
dialog_id,
|
||||||
msg_id: this.msgId,
|
msg_id: this.msgId,
|
||||||
msg_type: this.msgType,
|
msg_type: this.msgType,
|
||||||
}).then(_ => {
|
}).then(({data}) => {
|
||||||
this.openId = dialog_id
|
this.openId = dialog_id
|
||||||
this.msgPrepared = true
|
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(_ => {
|
setTimeout(_ => {
|
||||||
this.onSearchMsgId()
|
this.onSearchMsgId()
|
||||||
this.positionShow = this.readTimeout === null
|
this.positionShow = this.readTimeout === null
|
||||||
|
|||||||
@ -675,7 +675,7 @@ export default {
|
|||||||
|
|
||||||
columnList() {
|
columnList() {
|
||||||
const {projectId, cacheColumns, allTask} = this;
|
const {projectId, cacheColumns, allTask} = this;
|
||||||
const list = cacheColumns.filter(({project_id}) => {
|
const list = $A.cloneJSON(cacheColumns).filter(({project_id}) => {
|
||||||
return project_id == projectId
|
return project_id == projectId
|
||||||
}).sort((a, b) => {
|
}).sort((a, b) => {
|
||||||
if (a.sort != b.sort) {
|
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: "",
|
clientId: "",
|
||||||
|
|
||||||
// 缓存版本号(如果想升级后清除客户端缓存则修改此参数值)
|
// 缓存版本号(如果想升级后清除客户端缓存则修改此参数值)
|
||||||
cacheVersion: "v8",
|
cacheVersion: "v9",
|
||||||
|
|
||||||
// 窗口是否激活
|
// 窗口是否激活
|
||||||
windowActive: true,
|
windowActive: true,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user