mirror of
https://github.com/kuaifan/dootask.git
synced 2026-03-27 07:40:51 +00:00
fix: 消息已读
This commit is contained in:
parent
473eaa040f
commit
8c1cea6e6e
71
resources/assets/js/store/actions.js
vendored
71
resources/assets/js/store/actions.js
vendored
@ -2371,13 +2371,24 @@ export default {
|
|||||||
state.wsReadWaitList.push(data.id);
|
state.wsReadWaitList.push(data.id);
|
||||||
clearTimeout(state.wsReadTimeout);
|
clearTimeout(state.wsReadTimeout);
|
||||||
state.wsReadTimeout = setTimeout(() => {
|
state.wsReadTimeout = setTimeout(() => {
|
||||||
|
const id = $A.cloneJSON(state.wsReadWaitList);
|
||||||
|
state.wsReadWaitList = [];
|
||||||
|
//
|
||||||
dispatch("websocketSend", {
|
dispatch("websocketSend", {
|
||||||
type: 'readMsg',
|
type: 'readMsg',
|
||||||
data: {
|
data: {id}
|
||||||
id: $A.cloneJSON(state.wsReadWaitList)
|
}).catch(_ => {
|
||||||
}
|
// try again later
|
||||||
|
setTimeout(_ => {
|
||||||
|
dispatch("websocketSend", {
|
||||||
|
type: 'readMsg',
|
||||||
|
data: {id}
|
||||||
|
}).catch(_ => {
|
||||||
|
// or fail
|
||||||
|
state.wsReadWaitList.push(...id)
|
||||||
|
});
|
||||||
|
}, 1000)
|
||||||
});
|
});
|
||||||
state.wsReadWaitList = [];
|
|
||||||
}, 50);
|
}, 50);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -2735,31 +2746,37 @@ export default {
|
|||||||
* 发送 websocket 消息
|
* 发送 websocket 消息
|
||||||
* @param state
|
* @param state
|
||||||
* @param params {type, data, callback}
|
* @param params {type, data, callback}
|
||||||
|
* @returns {Promise<unknown>}
|
||||||
*/
|
*/
|
||||||
websocketSend({state}, params) {
|
websocketSend({state}, params) {
|
||||||
if (!$A.isJson(params)) {
|
return new Promise((resolve, reject) => {
|
||||||
typeof callback === "function" && callback(null, false)
|
if (!$A.isJson(params)) {
|
||||||
return;
|
reject()
|
||||||
}
|
return
|
||||||
const {type, data, callback} = params;
|
}
|
||||||
let msgId = undefined;
|
const {type, data, callback} = params
|
||||||
if (!state.ws) {
|
let msgId = undefined
|
||||||
typeof callback === "function" && callback(null, false)
|
if (!state.ws) {
|
||||||
return;
|
typeof callback === "function" && callback(null, false)
|
||||||
}
|
reject()
|
||||||
if (typeof callback === "function") {
|
return
|
||||||
msgId = $A.randomString(16)
|
}
|
||||||
state.wsCall[msgId] = callback;
|
if (typeof callback === "function") {
|
||||||
}
|
msgId = $A.randomString(16)
|
||||||
try {
|
state.wsCall[msgId] = callback
|
||||||
state.ws.send(JSON.stringify({
|
}
|
||||||
type,
|
try {
|
||||||
msgId,
|
state.ws.send(JSON.stringify({
|
||||||
data
|
type,
|
||||||
}));
|
msgId,
|
||||||
} catch (e) {
|
data
|
||||||
typeof callback === "function" && callback(null, false)
|
}))
|
||||||
}
|
resolve()
|
||||||
|
} catch (e) {
|
||||||
|
typeof callback === "function" && callback(null, false)
|
||||||
|
reject(e)
|
||||||
|
}
|
||||||
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user