Commit 8620aa88 by Sixong.Zhu

update unread method

parent 8082d7a8
...@@ -27,8 +27,11 @@ ...@@ -27,8 +27,11 @@
:class="{ all: isAllRead }" :class="{ all: isAllRead }"
> >
<template v-if="isAllRead">全部已读</template> <template v-if="isAllRead">全部已读</template>
<template v-else-if="data.read_count > 0" <template
>{{ data.read_count }}人已读</template v-else-if="manualReaded || data.read_count"
>{{
manualReaded || data.read_count
}}人已读</template
> >
<template v-else>未读</template> <template v-else>未读</template>
</span> </span>
...@@ -151,7 +154,6 @@ ...@@ -151,7 +154,6 @@
import PurchasePlanMessage from "./message-item/purchase-plan-message.vue"; import PurchasePlanMessage from "./message-item/purchase-plan-message.vue";
import MyWelfareMessage from "./message-item/my-welfare-message.vue"; import MyWelfareMessage from "./message-item/my-welfare-message.vue";
import QuestionAnswerMessage from "./message-item/question-answer-message.vue"; import QuestionAnswerMessage from "./message-item/question-answer-message.vue";
import xim from "./../xim";
import { ChatRole } from "@/customer-service/model"; import { ChatRole } from "@/customer-service/model";
import { getUserMapping } from "../utils/user-info"; import { getUserMapping } from "../utils/user-info";
import Xim from "@/customer-service/xim"; import Xim from "@/customer-service/xim";
...@@ -210,6 +212,9 @@ ...@@ -210,6 +212,9 @@
@chatStore.State(ChatStore.STATE_CHAT_CURRENT_IS_CHAT_MEMBER) @chatStore.State(ChatStore.STATE_CHAT_CURRENT_IS_CHAT_MEMBER)
private readonly isChatMember!: ChatStore.STATE_CHAT_CURRENT_IS_CHAT_MEMBER; private readonly isChatMember!: ChatStore.STATE_CHAT_CURRENT_IS_CHAT_MEMBER;
@chatStore.Action(ChatStore.ACTION_UPDATE_MESSAGE_READ_STATUS)
private readonly updateMessage!: ChatStore.ACTION_UPDATE_MESSAGE_READ_STATUS;
@Prop({ type: Object, default: () => Object.create(null) }) @Prop({ type: Object, default: () => Object.create(null) })
private readonly data!: dto.Message; private readonly data!: dto.Message;
...@@ -231,6 +236,8 @@ ...@@ -231,6 +236,8 @@
private readListVisibility = false; private readListVisibility = false;
private org = ""; private org = "";
private manualAllRead = false;
private manualReaded = 0;
private readerListOffset = false; private readerListOffset = false;
private defaultMessageHandledStatus = dto.MessageHandled.Default; private defaultMessageHandledStatus = dto.MessageHandled.Default;
...@@ -253,7 +260,10 @@ ...@@ -253,7 +260,10 @@
} }
private get isAllRead() { private get isAllRead() {
return this.data.read_count >= this.data.total_read_count; return (
this.manualAllRead ||
this.data.read_count >= this.data.total_read_count
);
} }
private get messageBody(): { eid?: string; oid?: string; msg: any } { private get messageBody(): { eid?: string; oid?: string; msg: any } {
...@@ -326,7 +336,7 @@ ...@@ -326,7 +336,7 @@
} }
private get defaultAvatar() { private get defaultAvatar() {
return xim.getAvatar(); return Xim.getAvatar();
} }
private get chatRole() { private get chatRole() {
...@@ -381,7 +391,7 @@ ...@@ -381,7 +391,7 @@
if (this.isTextMessage && !this.isMyMessage) { if (this.isTextMessage && !this.isMyMessage) {
const m = this.messageBody.msg as { text: string }; const m = this.messageBody.msg as { text: string };
if (m && m.text) { if (m && m.text) {
const keywords = xim.getMatchedTextKeywords(); const keywords = Xim.getMatchedTextKeywords();
return keywords.find((i) => m.text.includes(i)); return keywords.find((i) => m.text.includes(i));
} }
} }
...@@ -390,6 +400,27 @@ ...@@ -390,6 +400,27 @@
created() { created() {
this.messageComponent = messageMapping.get(this.messageType) as string; this.messageComponent = messageMapping.get(this.messageType) as string;
if (Xim.isBackend()) {
this.data &&
!this.isAllRead &&
ximInstance
.queryNextPageMsg("group", this.chatId, this.data.id - 1, 1)
.then((m) => {
if (m && m.length) {
const t = m[0];
t.read_count &&
t.read_count !== this.data.read_count &&
this.updateMessage({
chat: this.chatId,
start: this.data.id,
all: (this.manualAllRead =
t.read_count === t.total_read_count),
readed: (this.manualReaded = t.read_count),
});
}
});
}
} }
private isCustomer() { private isCustomer() {
......
...@@ -205,11 +205,14 @@ export default { ...@@ -205,11 +205,14 @@ export default {
); );
}, },
[ChatStore.MUTATION_SAVE_MYSELF_ID](state) { [ChatStore.MUTATION_SAVE_MYSELF_ID](state) {
Chat.getToken().then((token) => { if (!state[ChatStore.STATE_CHAT_MY_ID]) {
const eid = decodeJwt<{ user_id: string; sub: string }>(token); Chat.getToken().then((token) => {
state[ChatStore.STATE_CHAT_MY_ID] = String(eid.user_id); const eid =
state[ChatStore.STATE_CHAT_MY_UID] = eid.sub; decodeJwt<{ user_id: string; sub: string }>(token);
}); state[ChatStore.STATE_CHAT_MY_ID] = String(eid.user_id);
state[ChatStore.STATE_CHAT_MY_UID] = eid.sub;
});
}
}, },
[ChatStore.MUTATION_CLEAR_MYSELF_ID](state) { [ChatStore.MUTATION_CLEAR_MYSELF_ID](state) {
state[ChatStore.STATE_CHAT_MY_ID] = null; state[ChatStore.STATE_CHAT_MY_ID] = null;
...@@ -390,6 +393,8 @@ export default { ...@@ -390,6 +393,8 @@ export default {
}, },
actions: { actions: {
async [ChatStore.ACTION_GET_MY_CHAT_LIST]({ commit, state }) { async [ChatStore.ACTION_GET_MY_CHAT_LIST]({ commit, state }) {
commit(ChatStore.MUTATION_SAVE_MYSELF_ID);
let cache = await dbController.getChatList(); let cache = await dbController.getChatList();
cache.sort((x, y) => (x.last_msg_ts < y.last_msg_ts ? 1 : -1)); cache.sort((x, y) => (x.last_msg_ts < y.last_msg_ts ? 1 : -1));
...@@ -1072,6 +1077,7 @@ export default { ...@@ -1072,6 +1077,7 @@ export default {
start: number; start: number;
end?: number; end?: number;
all?: boolean; all?: boolean;
readed?: number;
} }
) => { ) => {
const items = state[ChatStore.STATE_CHAT_MSG_HISTORY] as Message[]; const items = state[ChatStore.STATE_CHAT_MSG_HISTORY] as Message[];
...@@ -1082,6 +1088,8 @@ export default { ...@@ -1082,6 +1088,8 @@ export default {
if (p) { if (p) {
p.read_count = option.all p.read_count = option.all
? p.total_read_count ? p.total_read_count
: option.readed
? option.readed
: p.read_count + 1; : p.read_count + 1;
} }
} }
...@@ -1090,16 +1098,20 @@ export default { ...@@ -1090,16 +1098,20 @@ export default {
if (p) { if (p) {
p.read_count = option.all p.read_count = option.all
? p.total_read_count ? p.total_read_count
: option.readed
? option.readed
: p.read_count + 1; : p.read_count + 1;
} }
} }
} }
return dbController.setMessageReaded(option.chat, { return dbController
start: option.start, .setMessageReaded(option.chat, {
end: option.end, start: option.start,
allRead: option.all, end: option.end,
}); allRead: option.all,
})
.then(() => (state[ChatStore.STATE_CHAT_MSG_HISTORY] = items));
}, },
}, },
getters: { getters: {
......
...@@ -364,6 +364,7 @@ export namespace ChatStore { ...@@ -364,6 +364,7 @@ export namespace ChatStore {
start: number; start: number;
end?: number; end?: number;
all?: boolean; all?: boolean;
readed?: number;
}) => Promise<void>; }) => Promise<void>;
export interface ChatUpdateParameter { export interface ChatUpdateParameter {
......
...@@ -166,13 +166,13 @@ export class Xim { ...@@ -166,13 +166,13 @@ export class Xim {
rid = 0, rid = 0,
limit = DefaultMsgPageSize, limit = DefaultMsgPageSize,
desc: boolean, desc: boolean,
p: { isMember: boolean; model: string; obj: string } p?: { isMember: boolean; model: string; obj: string }
): Promise<Message[]> { ): Promise<Message[]> {
this.checkConnected(); this.checkConnected();
if (this.client == null) { if (this.client == null) {
throw new Error("client shouldn't undefined"); throw new Error("client shouldn't undefined");
} }
if (!p.isMember && p.model && p.obj) { if (p && !p.isMember && p.model && p.obj) {
return this.queryMessageWhenIsNotMember(p, limit, lid, rid, desc); return this.queryMessageWhenIsNotMember(p, limit, lid, rid, desc);
} }
const res = await this.client.fetchChatMsgs(chatType, chatId, { const res = await this.client.fetchChatMsgs(chatType, chatId, {
...@@ -259,7 +259,7 @@ export class Xim { ...@@ -259,7 +259,7 @@ export class Xim {
chatId: number, chatId: number,
msgId: number, msgId: number,
limit: number, limit: number,
p: { isMember: boolean; model: string; obj: string } p?: { isMember: boolean; model: string; obj: string }
) { ) {
const data = await this.queryMsgs( const data = await this.queryMsgs(
chatType, chatType,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment