fix: 消息已读

This commit is contained in:
kuaifan 2022-09-06 16:04:01 +08:00
parent 473eaa040f
commit 8c1cea6e6e

View File

@ -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) {
return new Promise((resolve, reject) => {
if (!$A.isJson(params)) { if (!$A.isJson(params)) {
typeof callback === "function" && callback(null, false) reject()
return; return
} }
const {type, data, callback} = params; const {type, data, callback} = params
let msgId = undefined; let msgId = undefined
if (!state.ws) { if (!state.ws) {
typeof callback === "function" && callback(null, false) typeof callback === "function" && callback(null, false)
return; reject()
return
} }
if (typeof callback === "function") { if (typeof callback === "function") {
msgId = $A.randomString(16) msgId = $A.randomString(16)
state.wsCall[msgId] = callback; state.wsCall[msgId] = callback
} }
try { try {
state.ws.send(JSON.stringify({ state.ws.send(JSON.stringify({
type, type,
msgId, msgId,
data data
})); }))
resolve()
} catch (e) { } catch (e) {
typeof callback === "function" && callback(null, false) typeof callback === "function" && callback(null, false)
reject(e)
} }
})
}, },
/** /**