chat-pc/src/event/read.js

55 lines
1.3 KiB
JavaScript

import Base from './base'
import { useTalkStore, useDialogueStore } from '@/store'
import ws from '@/connect'
import { bus } from '@/utils/event-bus'
/**
* 已读回执事件
*/
class Read extends Base {
/**
* @var resource 资源
*/
resource
/**
* 场景类型
*/
type
/**
* 初始化构造方法
*
* @param {Object} resource Socket消息
*/
constructor(resource, type) {
super()
this.resource = resource
this.type = type
this.handle()
}
handle() {
if (this.type == 'total') {
console.error('====接收到了新版已读回执全量=====', this.resource)
const readList = this.resource.result
if (readList.length > 0) {
readList.forEach((item) => {
useDialogueStore().updateDialogueRecord({
msg_id: item.msg_id,
read_total_num: item.read_total_num
})
})
}
} else if (this.type == 'incr') {
console.error('====接收到了新版已读回执增量=====', this.resource)
// 由于直接使用增量的数值,会导致消息列表的已读回执数量不准确,可能多可能少
// 所以收到增量消息后,直接手动触发一次查询全量
bus.emit('check-visible-out-elements', 'incr')
}
}
}
export default Read