Commit 23cf5fea by Sixong.Zhu

未读消息计数

parent b707d4d5
...@@ -44,6 +44,9 @@ export default class ChatList extends Vue { ...@@ -44,6 +44,9 @@ export default class ChatList extends Vue {
@chatStore.Action(ChatStore.ACTION_UPDATE_CHAT) @chatStore.Action(ChatStore.ACTION_UPDATE_CHAT)
protected readonly updateChat!: ChatStore.ACTION_UPDATE_CHAT; protected readonly updateChat!: ChatStore.ACTION_UPDATE_CHAT;
@chatStore.Action(ChatStore.ACTION_REBUILD_UNREAD_MESSAGE_COUNT)
protected readonly updateUnreadMessageCount!: ChatStore.ACTION_REBUILD_UNREAD_MESSAGE_COUNT;
protected parseMesage(data: ChatItem) { protected parseMesage(data: ChatItem) {
if (data.last_msg_sender && data.last_msg_sender !== "0") { if (data.last_msg_sender && data.last_msg_sender !== "0") {
if (!this.userNames[data.last_msg_sender]) { if (!this.userNames[data.last_msg_sender]) {
......
...@@ -198,6 +198,7 @@ export default class MessageList extends Vue { ...@@ -198,6 +198,7 @@ export default class MessageList extends Vue {
this.saveScrollToBottomFunc(this.scrollToNewMsg); this.saveScrollToBottomFunc(this.scrollToNewMsg);
this.scrollToNewMsg(); this.scrollToNewMsg();
setTimeout(() => this.scroll2End(200)); setTimeout(() => this.scroll2End(200));
setTimeout(() => this.scroll2End(1000));
} }
public beforeDestroy() { public beforeDestroy() {
......
...@@ -124,7 +124,7 @@ export interface Message { ...@@ -124,7 +124,7 @@ export interface Message {
export type MessageRequestResult = readonly Message[]; export type MessageRequestResult = readonly Message[];
export interface CreateChatByServicemanRequestResult { export interface BaseChatItem {
id: number; id: number;
org_id: string; org_id: string;
uid: string; uid: string;
...@@ -135,7 +135,6 @@ export interface CreateChatByServicemanRequestResult { ...@@ -135,7 +135,6 @@ export interface CreateChatByServicemanRequestResult {
app_id: string; app_id: string;
tag: string; tag: string;
msg_id: number; msg_id: number;
ext: string;
exit_msg_id: number; exit_msg_id: number;
is_exited: boolean; is_exited: boolean;
dnd: number; dnd: number;
...@@ -144,7 +143,6 @@ export interface CreateChatByServicemanRequestResult { ...@@ -144,7 +143,6 @@ export interface CreateChatByServicemanRequestResult {
join_msg_id: number; join_msg_id: number;
last_read_msg_id: number; last_read_msg_id: number;
biz_id: string; biz_id: string;
business_data: string;
is_finish: boolean; is_finish: boolean;
is_deleted: boolean; is_deleted: boolean;
is_remove: boolean; is_remove: boolean;
...@@ -164,6 +162,23 @@ export interface CreateChatByServicemanRequestResult { ...@@ -164,6 +162,23 @@ export interface CreateChatByServicemanRequestResult {
user_updated: number; user_updated: number;
} }
export interface RawChatItem extends BaseChatItem {
ext: string;
business_data: string;
last_msg_content: string;
}
export interface TransferedChatItem extends BaseChatItem {
chat_id: number;
ext: string;
business_data: {
detail_name: string;
model_name: string;
obj_id: string;
};
last_msg_content: { text?: string };
}
export type ChatMemberExtraInfo = { export type ChatMemberExtraInfo = {
name?: string; name?: string;
phone?: string; phone?: string;
......
...@@ -2,7 +2,7 @@ import Vue from "vue"; ...@@ -2,7 +2,7 @@ import Vue from "vue";
import { Module } from "vuex"; import { Module } from "vuex";
import { dbController } from "../database"; import { dbController } from "../database";
import { ChatMember, ServiceType, MessageHandled } from "../model"; import { ChatMember, ServiceType, MessageHandled, RawChatItem } from "../model";
import { isAccessibleUrl } from "../service/tools"; import { isAccessibleUrl } from "../service/tools";
import { unique } from "../utils"; import { unique } from "../utils";
import { getChatModelInfo } from "../utils/chat-info"; import { getChatModelInfo } from "../utils/chat-info";
...@@ -74,7 +74,7 @@ async function preCacheImgs(msgs: any[]) { ...@@ -74,7 +74,7 @@ async function preCacheImgs(msgs: any[]) {
); );
} }
function buildChatItem(chat: any) { function buildChatItem(chat: RawChatItem) {
let business_data; let business_data;
if (chat.business_data) { if (chat.business_data) {
business_data = JSON.parse(chat.business_data); business_data = JSON.parse(chat.business_data);
...@@ -115,6 +115,7 @@ export default { ...@@ -115,6 +115,7 @@ export default {
[ChatStore.STATE_CHAT_CURRENT_USER_TYPE]: null, [ChatStore.STATE_CHAT_CURRENT_USER_TYPE]: null,
[ChatStore.STATE_CHAT_SEND_FAIL_MESSAGE]: null, [ChatStore.STATE_CHAT_SEND_FAIL_MESSAGE]: null,
[ChatStore.STATE_CHAT_USERNAME]: {}, [ChatStore.STATE_CHAT_USERNAME]: {},
[ChatStore.STATE_CURRENT_UNREAD_MESSAGE_COUNT]: 0,
}), }),
mutations: { mutations: {
[ChatStore.MUTATION_SHOW_CHAT](state, isSingle?: boolean) { [ChatStore.MUTATION_SHOW_CHAT](state, isSingle?: boolean) {
...@@ -357,9 +358,16 @@ export default { ...@@ -357,9 +358,16 @@ export default {
}, },
}, },
actions: { actions: {
async [ChatStore.ACTION_GET_MY_CHAT_LIST]({ commit }) { async [ChatStore.ACTION_GET_MY_CHAT_LIST]({ commit, state }) {
let cache = await dbController.getChatList(); let cache = await dbController.getChatList();
const buildUnreadMessage = (items: ChatType[]) => {
let sum = 0;
items.forEach((i) => (sum += i.unread_msg_count));
state[ChatStore.STATE_CURRENT_UNREAD_MESSAGE_COUNT] = sum;
return items;
};
if (cache && cache.length) { if (cache && cache.length) {
commit(ChatStore.MUTATION_SAVE_CHAT_LIST, { commit(ChatStore.MUTATION_SAVE_CHAT_LIST, {
list: cache, list: cache,
...@@ -377,19 +385,25 @@ export default { ...@@ -377,19 +385,25 @@ export default {
} }
}); });
return cache; return buildUnreadMessage(cache);
} }
const data = await xim.fetchChatList(); const data = await xim.fetchChatList();
if (data == null) return; if (data == null) return;
const chatList = data.args[0]; const chatList = data.args[0] as RawChatItem[];
const items = chatList.map((chat: any) => buildChatItem(chat)); const items = chatList.map((chat) => buildChatItem(chat));
dbController.saveChatList(items); dbController.saveChatList(items);
commit(ChatStore.MUTATION_SAVE_CHAT_LIST, { commit(ChatStore.MUTATION_SAVE_CHAT_LIST, {
list: items, list: items,
total: 9999, total: 9999,
}); });
return items; return buildUnreadMessage(items);
},
async [ChatStore.ACTION_REBUILD_UNREAD_MESSAGE_COUNT]({ state }) {
let items = await dbController.getChatList();
let sum = 0;
items.forEach((i) => (sum += i.unread_msg_count));
state[ChatStore.STATE_CURRENT_UNREAD_MESSAGE_COUNT] = sum;
}, },
// async [ChatStore.ACTION_JOIN_CHAT]( // async [ChatStore.ACTION_JOIN_CHAT](
// { commit }, // { commit },
......
...@@ -81,6 +81,9 @@ export namespace ChatStore { ...@@ -81,6 +81,9 @@ export namespace ChatStore {
export const STATE_FUNC_ON_NEW_MSG = "收到消息回调方法"; export const STATE_FUNC_ON_NEW_MSG = "收到消息回调方法";
export type STATE_FUNC_ON_NEW_MSG = (e: chatDto.Message) => void; export type STATE_FUNC_ON_NEW_MSG = (e: chatDto.Message) => void;
export const STATE_CURRENT_UNREAD_MESSAGE_COUNT = "当前未读消息数";
export type STATE_CURRENT_UNREAD_MESSAGE_COUNT = number;
/* getter */ /* getter */
export const GETTER_CURRENT_CHAT_PRESENT_MEMBERS = "当前会话未退出的参与者"; export const GETTER_CURRENT_CHAT_PRESENT_MEMBERS = "当前会话未退出的参与者";
export type GETTER_CURRENT_CHAT_PRESENT_MEMBERS = dto.ChatMembers | null; export type GETTER_CURRENT_CHAT_PRESENT_MEMBERS = dto.ChatMembers | null;
...@@ -243,6 +246,9 @@ export namespace ChatStore { ...@@ -243,6 +246,9 @@ export namespace ChatStore {
keyword?: string keyword?: string
) => Promise<ChatType[]>; ) => Promise<ChatType[]>;
export const ACTION_REBUILD_UNREAD_MESSAGE_COUNT = "重新计算未读消息数";
export type ACTION_REBUILD_UNREAD_MESSAGE_COUNT = () => void;
export const ACTION_JOIN_CHAT = "加入某个会话"; export const ACTION_JOIN_CHAT = "加入某个会话";
export type ACTION_JOIN_CHAT = (chatId: number) => void; export type ACTION_JOIN_CHAT = (chatId: number) => void;
......
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