fix: 消息已读上报

This commit is contained in:
kaizheng(郑凯) 2025-02-13 22:05:57 +08:00
parent 4c93f9a3c2
commit 1e6102b49a
6 changed files with 109 additions and 17 deletions

View File

@ -4,7 +4,7 @@
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"build": "vue-cli-service build && sh ./build/deploy.sh",
"lint": "vue-cli-service lint"
},
"dependencies": {

View File

@ -35,3 +35,12 @@ export function sendMessage(data) {
data,
});
}
// APP保存消息已读
export function readMessage(data) {
return request({
url: "/app/group/message/readMessage",
method: "post",
data,
});
}

View File

@ -0,0 +1,62 @@
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);
}
}

View File

@ -4,6 +4,8 @@ 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 store from "@/store/index";
BScroll.use(PullDown);
BScroll.use(MouseWheel);
@ -27,7 +29,7 @@ export default function useChatData({ id, className, type }) {
groupId: id,
lastId: msgList.value[0]?.id,
size: 10,
type,
type, // 查询类型:1全部;2投顾;3用户;4精选;5私聊
});
if (ret.code === 0) {
let list = ret.data.list.reverse() || [];
@ -40,6 +42,12 @@ export default function useChatData({ id, className, type }) {
if (!hasNext.value) {
bs.value && bs.value.closePullDown();
}
setStorageTeacherMsg({
productId: id,
userId: store.state.userInfo.account,
msgArr: list,
type: type === 5 ? 2 : 1,
});
}
isPullingDown.value = false;
finishPullDown(preHisHeight);
@ -67,6 +75,12 @@ export default function useChatData({ id, className, type }) {
bs.value && bs.value.scrollTo(0, bs.value.maxScrollY, 0);
}
});
setStorageTeacherMsg({
productId: id,
userId: store.state.userInfo.account,
msg,
type: type === 5 ? 2 : 1,
});
};
// 刷新消息

View File

@ -70,10 +70,16 @@ export default function ({ id, privateMessage, chatMessage }) {
emitter.emit("cancelGetNewMsg");
// 接收群聊接收消息路径
chatMessage &&
(await stompClient.value.subscribe(`/app/group/topic/${id}`, chatMessage));
(await stompClient.value.subscribe(
`/app/group/topic/${id}`,
chatMessage
));
// APP端私聊消息
privateMessage &&
(await stompClient.value.subscribe(`/app/private/topic/${id}/${store.state.userInfo.account}`, privateMessage));
(await stompClient.value.subscribe(
`/app/private/topic/${id}/${store.state.userInfo.account}`,
privateMessage
));
};
stompClient.value.onStompError = (error) => {
console.log(error.body);
@ -115,7 +121,7 @@ export default function ({ id, privateMessage, chatMessage }) {
stompClient.value.activate();
};
connect()
connect();
window.addEventListener("unload", function (event) {
stompClient.value && stompClient.value.deactivate();

View File

@ -141,7 +141,8 @@ import { useRoute } from "vue-router";
import { showToast } from "vant";
import Share from "@/components/Share";
import { likeVideo, queryLiveCoupon } from "@/api/video";
// import { likeVideo, queryLiveCoupon } from "@/api/video";
import { likeVideo } from "@/api/video";
import emitter from "@/utils/emitter";
import useGetLiveStatusObj from "@/hooks/useGetLiveStatusObj";
import QuestionnairePopup from "../components/QuestionnairePopup.vue";
@ -392,19 +393,19 @@ const showDiscountCoupon = () => {
emitter.emit("showDiscountCoupon", couponDetail.value);
};
const getLiveCoupon = async () => {
let ret = await queryLiveCoupon({
liveId: props.detail.id,
});
if (ret.code === 0 && ret.data && ret.data.length) {
couponDetail.value = ret.data[0];
couponDetail.value.couponType = Number(couponDetail.value.couponType);
couponDetail.value.sendCouponId = couponDetail.value.id;
}
};
// const getLiveCoupon = async () => {
// let ret = await queryLiveCoupon({
// liveId: props.detail.id,
// });
// if (ret.code === 0 && ret.data && ret.data.length) {
// couponDetail.value = ret.data[0];
// couponDetail.value.couponType = Number(couponDetail.value.couponType);
// couponDetail.value.sendCouponId = couponDetail.value.id;
// }
// };
//
getLiveCoupon();
// getLiveCoupon();
let tipLook = false;
const userInTip = (name) => {