Commit 2aff577f by Sixong.Zhu

update

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