fix: 交易圈投顾要是发言已读上报
This commit is contained in:
parent
1e6102b49a
commit
512678dde3
@ -181,6 +181,10 @@ const props = defineProps({
|
||||
type: Object,
|
||||
default: () => {},
|
||||
},
|
||||
stompClient: {
|
||||
type: Object,
|
||||
default: null,
|
||||
},
|
||||
});
|
||||
|
||||
const defaultAvatar = {
|
||||
@ -237,6 +241,7 @@ const {
|
||||
className: `.interact-scroll${props.type}`,
|
||||
id: route.query.id,
|
||||
type: props.type,
|
||||
stompClient: props.stompClient,
|
||||
});
|
||||
|
||||
const maskUserName = (value) => {
|
||||
|
||||
@ -1,62 +0,0 @@
|
||||
import { readMessage } from "@/api/circle";
|
||||
|
||||
// type 1 公共互动 2私聊
|
||||
function getStorageTeacherMsg({
|
||||
productId,
|
||||
productType = 41,
|
||||
type = 1,
|
||||
userId,
|
||||
}) {
|
||||
const getMsgIds = localStorage.getItem(
|
||||
`read-msg-${productType}-${productId}-${userId}-${type}`
|
||||
);
|
||||
if (getMsgIds) {
|
||||
return JSON.parse(getMsgIds);
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
// 老师发的言,并且已经上报的缓存起来
|
||||
export function setStorageTeacherMsg({
|
||||
productId,
|
||||
productType = 41,
|
||||
userId,
|
||||
type = 1, // type 1 公共互动 2私聊
|
||||
msg, // 单条消息
|
||||
msgArr, // 多条消息
|
||||
}) {
|
||||
const storageMsgIds = getStorageTeacherMsg({
|
||||
productId,
|
||||
productType,
|
||||
type,
|
||||
userId,
|
||||
});
|
||||
|
||||
let messageIds = [];
|
||||
// userType用户类型:1投顾;2用户;3助教;4运营人员
|
||||
if (msg) {
|
||||
if (!storageMsgIds.includes(msg.id) && msg.userType !== 2) {
|
||||
messageIds = [msg.id];
|
||||
}
|
||||
} else if (msgArr && msgArr.length) {
|
||||
msgArr.forEach((msg) => {
|
||||
if (msg.userType !== 2 && !storageMsgIds.includes(msg.id)) {
|
||||
messageIds.push(msg.id);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
if (messageIds.length) {
|
||||
setTimeout(async () => {
|
||||
let ret = await readMessage({ messageIds }).catch(() => {});
|
||||
if (ret && ret.code === 0) {
|
||||
localStorage.setItem(
|
||||
`read-msg-${productType}-${productId}-${userId}-${type}`,
|
||||
JSON.stringify(messageIds.concat(storageMsgIds))
|
||||
);
|
||||
}
|
||||
}, Math.random() * 3);
|
||||
}
|
||||
}
|
||||
@ -4,13 +4,13 @@ import BScroll from "@better-scroll/core";
|
||||
import PullDown from "@better-scroll/pull-down";
|
||||
import MouseWheel from "@better-scroll/mouse-wheel";
|
||||
import useDisableScroll from "@/hooks/useDisableScroll";
|
||||
import { setStorageTeacherMsg } from "./storage";
|
||||
import useReadMessage from "./useReadMessage";
|
||||
import store from "@/store/index";
|
||||
|
||||
BScroll.use(PullDown);
|
||||
BScroll.use(MouseWheel);
|
||||
|
||||
export default function useChatData({ id, className, type }) {
|
||||
export default function useChatData({ id, className, type, stompClient }) {
|
||||
const { addScrollEvent } = useDisableScroll();
|
||||
const hasNext = ref(true);
|
||||
let bs = ref();
|
||||
@ -20,6 +20,8 @@ export default function useChatData({ id, className, type }) {
|
||||
const msgIdsObj = ref({});
|
||||
const loading = ref(false);
|
||||
|
||||
const { setStorageTeacherMsg } = useReadMessage();
|
||||
|
||||
const getLiveHisMsg = async () => {
|
||||
loading.value = true;
|
||||
if (isPullingDown.value) return;
|
||||
@ -47,6 +49,7 @@ export default function useChatData({ id, className, type }) {
|
||||
userId: store.state.userInfo.account,
|
||||
msgArr: list,
|
||||
type: type === 5 ? 2 : 1,
|
||||
stompClient,
|
||||
});
|
||||
}
|
||||
isPullingDown.value = false;
|
||||
|
||||
104
src/views/Circle/hooks/useReadMessage.js
Normal file
104
src/views/Circle/hooks/useReadMessage.js
Normal file
@ -0,0 +1,104 @@
|
||||
// import { readMessage } from "@/api/circle";
|
||||
|
||||
export default function useReadMessage() {
|
||||
// type 1 公共互动 2私聊
|
||||
const getStorageTeacherMsg = ({
|
||||
productId,
|
||||
productType = 41,
|
||||
type = 1,
|
||||
userId,
|
||||
}) => {
|
||||
const getMsgIds = localStorage.getItem(
|
||||
`read-msg-${productType}-${productId}-${userId}-${type}`
|
||||
);
|
||||
if (getMsgIds) {
|
||||
return JSON.parse(getMsgIds);
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
// 老师发的言,并且已经上报的缓存起来
|
||||
let uploadReadMsgIds = []; // 存储需要上传的ids
|
||||
let timeout = null;
|
||||
|
||||
const uploadReadMsg = ({
|
||||
productId,
|
||||
productType,
|
||||
userId,
|
||||
type, // type 1 公共互动 2私聊
|
||||
stompClient,
|
||||
messageIds,
|
||||
storageMsgIds,
|
||||
}) => {
|
||||
console.log("stompClient", stompClient);
|
||||
uploadReadMsgIds = Array.from(new Set(uploadReadMsgIds.concat(messageIds)));
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(async () => {
|
||||
stompClient &&
|
||||
stompClient.publish({
|
||||
destination: `/chat/group/readMessage`,
|
||||
headers: {
|
||||
userId: userId,
|
||||
messageIds: uploadReadMsgIds,
|
||||
},
|
||||
});
|
||||
localStorage.setItem(
|
||||
`read-msg-${productType}-${productId}-${userId}-${type}`,
|
||||
JSON.stringify(uploadReadMsgIds.concat(storageMsgIds).sort())
|
||||
);
|
||||
uploadReadMsgIds = [];
|
||||
}, 5000);
|
||||
};
|
||||
|
||||
const setStorageTeacherMsg = ({
|
||||
productId,
|
||||
productType = 41,
|
||||
userId,
|
||||
type = 1, // type 1 公共互动 2私聊
|
||||
msg, // 单条消息
|
||||
msgArr, // 多条消息
|
||||
stompClient,
|
||||
}) => {
|
||||
const storageMsgIds = getStorageTeacherMsg({
|
||||
productId,
|
||||
productType,
|
||||
type,
|
||||
userId,
|
||||
});
|
||||
|
||||
let messageIds = [];
|
||||
// userType用户类型:1投顾;2用户;3助教;4运营人员
|
||||
if (msg) {
|
||||
if (!storageMsgIds.includes(msg.id) && msg.userType !== 2) {
|
||||
messageIds = [msg.id];
|
||||
}
|
||||
} else if (msgArr && msgArr.length) {
|
||||
msgArr.forEach((msg) => {
|
||||
if (msg.userType !== 2 && !storageMsgIds.includes(msg.id)) {
|
||||
messageIds.push(msg.id);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
if (messageIds.length) {
|
||||
uploadReadMsg({
|
||||
productId,
|
||||
productType,
|
||||
userId,
|
||||
type, // type 1 公共互动 2私聊
|
||||
msg, // 单条消息
|
||||
msgArr, // 多条消息
|
||||
stompClient,
|
||||
messageIds,
|
||||
storageMsgIds,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
setStorageTeacherMsg,
|
||||
};
|
||||
}
|
||||
@ -138,4 +138,7 @@ export default function ({ id, privateMessage, chatMessage }) {
|
||||
}
|
||||
}
|
||||
});
|
||||
return {
|
||||
stompClient,
|
||||
};
|
||||
}
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
:bsRefresh="active === 0"
|
||||
:detail="detail"
|
||||
:newMsg="newMsg"
|
||||
:stompClient="stompClient"
|
||||
/>
|
||||
</van-tab>
|
||||
<van-tab title="老师" :name="1">
|
||||
@ -27,6 +28,7 @@
|
||||
:bsRefresh="active === 1"
|
||||
:detail="detail"
|
||||
:newMsg="newMsg"
|
||||
:stompClient="stompClient"
|
||||
/>
|
||||
</van-tab>
|
||||
<van-tab title="私聊" :name="2">
|
||||
@ -35,6 +37,7 @@
|
||||
:bsRefresh="active === 2"
|
||||
:detail="detail"
|
||||
:newMsg="privateNewMsg"
|
||||
:stompClient="stompClient"
|
||||
/>
|
||||
</van-tab>
|
||||
<van-tab title="精选" :name="3">
|
||||
@ -43,6 +46,7 @@
|
||||
:bsRefresh="active === 3"
|
||||
:detail="detail"
|
||||
:newMsg="newMsg"
|
||||
:stompClient="stompClient"
|
||||
/>
|
||||
</van-tab>
|
||||
</van-tabs>
|
||||
@ -138,7 +142,11 @@ const chatMessage = (msg) => {
|
||||
detail.value.showMemberCount = data;
|
||||
}
|
||||
};
|
||||
useWebSocket({ id: route.query.id, privateMessage, chatMessage });
|
||||
const { stompClient } = useWebSocket({
|
||||
id: route.query.id,
|
||||
privateMessage,
|
||||
chatMessage,
|
||||
});
|
||||
|
||||
const sendMsg = async () => {
|
||||
let ret = await sendMessage({
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user