Commit 2aff577f by Sixong.Zhu

update

parent 28d34715
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
import VideoPreview from "./video-preview.vue"; import VideoPreview from "./video-preview.vue";
import { ChatStore, chatStore } from "@/customer-service/store/model"; import { ChatStore, chatStore } from "@/customer-service/store/model";
import { dbController } from "../database"; import { dbController } from "../database";
import { getLastMessageId } from "../store";
@Component({ components: { message, ImagePreview, VideoPreview } }) @Component({ components: { message, ImagePreview, VideoPreview } })
export default class MessageList extends Vue { export default class MessageList extends Vue {
...@@ -323,7 +324,7 @@ ...@@ -323,7 +324,7 @@
if (msg == null) return; if (msg == null) return;
if (msg.length === 0) return; if (msg.length === 0) return;
this.startLoadingNew(); this.startLoadingNew();
const msgId = msg[msg.length - 1].id; const msgId = getLastMessageId(msg);
const data = await this.getNextPageMsg(msgId); const data = await this.getNextPageMsg(msgId);
if (data.length === 0) { if (data.length === 0) {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
......
...@@ -31,7 +31,7 @@ function uniqueMessages( ...@@ -31,7 +31,7 @@ function uniqueMessages(
messages: NonNullable<ChatStore.STATE_CHAT_MSG_HISTORY> messages: NonNullable<ChatStore.STATE_CHAT_MSG_HISTORY>
) { ) {
const arr = [...messages]; const arr = [...messages];
return unique(arr, function(item, all) { return unique(arr, function (item, all) {
return all.findIndex((k) => k.id === item.id); return all.findIndex((k) => k.id === item.id);
}); });
} }
...@@ -52,7 +52,9 @@ async function preCacheImgs(msgs?: any[]) { ...@@ -52,7 +52,9 @@ async function preCacheImgs(msgs?: any[]) {
return Promise.resolve(); return Promise.resolve();
} }
await Promise.all( await Promise.all(
msgs.filter(i => i.id > 0).map((k) => { msgs
.filter((i) => i.id > 0)
.map((k) => {
return new Promise((resolve: (p: void) => void) => { return new Promise((resolve: (p: void) => void) => {
if (k.type === "image") { if (k.type === "image") {
const msg = JSON.parse(k.msg); const msg = JSON.parse(k.msg);
...@@ -102,6 +104,15 @@ const filterActiveChats = (items: RawChatItem[]) => { ...@@ -102,6 +104,15 @@ const filterActiveChats = (items: RawChatItem[]) => {
); );
}; };
export function getLastMessageId(msgs: Message[] | any) {
const last = msgs[msgs.length - 1];
let id = last.id;
if (id < 0) {
id = Math.max(...msgs.map((i) => i.id));
}
return id;
}
export default { export default {
namespaced: true, namespaced: true,
state: () => ({ state: () => ({
...@@ -315,7 +326,7 @@ export default { ...@@ -315,7 +326,7 @@ export default {
state[ChatStore.STATE_CHAT_SENDING_MESSAGES] = [...current]; state[ChatStore.STATE_CHAT_SENDING_MESSAGES] = [...current];
} }
}, },
[ChatStore.MUTATION_SAVE_CURRENT_CHAT_INPUTING]: (function() { [ChatStore.MUTATION_SAVE_CURRENT_CHAT_INPUTING]: (function () {
const setTimeoutId: { [key: string]: number } = {}; const setTimeoutId: { [key: string]: number } = {};
return ( return (
state: ChatStoreState, state: ChatStoreState,
...@@ -513,11 +524,7 @@ export default { ...@@ -513,11 +524,7 @@ export default {
if (msgs == null || msgs.length === 0) { if (msgs == null || msgs.length === 0) {
newMsgsArr = await dispatch(ChatStore.ACTION_GET_CHAT_MESSAGES); newMsgsArr = await dispatch(ChatStore.ACTION_GET_CHAT_MESSAGES);
} else { } else {
const last = msgs[msgs.length - 1] const id = getLastMessageId(msgs);
let id = last.id
if (id < 0) {
id = Math.max(...msgs.map(i => i.id))
}
newMsgsArr = await dispatch( newMsgsArr = await dispatch(
ChatStore.ACTION_GET_CHAT_MESSAGES_AFTER_SPECIFIC_ID, ChatStore.ACTION_GET_CHAT_MESSAGES_AFTER_SPECIFIC_ID,
id id
...@@ -722,7 +729,7 @@ export default { ...@@ -722,7 +729,7 @@ export default {
} }
commit( commit(
ChatStore.MUTATION_SAVE_CURRENT_CHAT_MEMBERS, ChatStore.MUTATION_SAVE_CURRENT_CHAT_MEMBERS,
unique(newChatMembers, function(item, all) { unique(newChatMembers, function (item, all) {
return all.findIndex((k) => k.eid === item.eid); return all.findIndex((k) => k.eid === item.eid);
}) })
); );
......
...@@ -37,7 +37,8 @@ class Chat { ...@@ -37,7 +37,8 @@ class Chat {
} }
this._sdk = option.sdk; this._sdk = option.sdk;
this._orgId = option.orgId; this._orgId = option.orgId;
option.serviceType !== undefined && (this.serviceType = option.serviceType); option.serviceType !== undefined &&
(this.serviceType = option.serviceType);
option.product && (this.product = option.product); option.product && (this.product = option.product);
this.eventHub = option.eventHub || null; this.eventHub = option.eventHub || null;
if (option.user) { if (option.user) {
...@@ -47,7 +48,11 @@ class Chat { ...@@ -47,7 +48,11 @@ class Chat {
}; };
} }
dbController.setup(this._sdk().global.uid); dbController.setup(
this._sdk().global.uid +
"-" +
(this._sdk().global.initData.orgId || 0)
);
this.token = async () => option.sdk().global.jwtToken; this.token = async () => option.sdk().global.jwtToken;
tokenManager.save(this.token); tokenManager.save(this.token);
......
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