Commit 23cf5fea by Sixong.Zhu

未读消息计数

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