Commit d70348a8 by Sixong.Zhu

时间戳排序

parent cf20b3e5
......@@ -121,7 +121,11 @@ import { parserMessage } from "./controller";
import { EVENTS } from "@/EventConsts";
import { chatStore, ChatStore } from "@/customer-service/store/model";
import { formatTime, TimeFormatRule } from "@/customer-service/utils/time";
import {
formatTime,
parseString2TimeValue,
TimeFormatRule,
} from "@/customer-service/utils/time";
import { Chat as ChatType } from "@/customer-service/xim/models/chat";
interface SelectChatType extends ChatType {
......@@ -171,7 +175,11 @@ export default class ModelChatList extends Vue {
private refreshing = false;
private get chatRooms() {
return this.chatList || [];
return this.chatList.sort(
(x, y) =>
parseString2TimeValue((y.last_msg_ts || "") + "", 100) -
parseString2TimeValue((x.last_msg_ts || "") + "", 99)
);
}
public clearActiveId() {
......@@ -224,7 +232,7 @@ export default class ModelChatList extends Vue {
async created() {
await this.getList();
this.setSource(ChatStore.StateChatSourceDirection.Server);
this.scrollbar.update();
this.scrollbar && this.scrollbar.update();
await this.sdk
.model("UniplatChat")
.registerOnChange(this.onTransportMessage);
......
......@@ -75,10 +75,10 @@ export default class ChatList extends Controller {
private unReadMsgCount = 0;
private get chatRooms() {
const list =
this.chatList?.list.filter(
(chat) => chat.title.indexOf(this.searchKeyword) > -1
) || [];
if (this.chatList) {
const list = this.chatList.list
.filter((chat) => chat.title.indexOf(this.searchKeyword) > -1)
.sort((x, y) => y.last_msg_ts - x.last_msg_ts);
let unReadMsgCount = 0;
list.filter((chat) => chat.unread_msg_count > 0).forEach((chat) => {
unReadMsgCount += chat.unread_msg_count;
......@@ -88,6 +88,8 @@ export default class ChatList extends Controller {
this.$eventHub.$emit(EVENTS.NewMsg, this.unReadMsgCount);
return list;
}
return [];
}
private isSelected(item: ChatType) {
if (this.chatId) {
......
......@@ -468,13 +468,14 @@ export default class Message extends Mixins(Filters) {
}
private withdraw() {
ximInstance
.withdraw(this.chatId, this.data.id)
.then(() => {
ximInstance.withdraw(this.chatId, this.data.id).finally(() => {
dbController
.removeMessage(this.chatId, this.data.id)
.finally(() => {
this.executeWithDraw(this.data.id);
dbController.removeMessage(this.chatId, this.data.id);
})
.finally(() => this.$emit("withdraw", this.data.id));
this.$emit("withdraw", this.data.id);
});
});
}
}
</script>
......
......@@ -60,7 +60,7 @@ class ChatCacheDatabaseController {
const setupDb = () => {
const db = that.messageDatabases.get(k);
try {
that.buildTables(db, this.chatMessageKey);
that.buildTables(db, this.chatMessageKey, "id");
} catch (e) {
console.error(e);
}
......@@ -176,8 +176,12 @@ class ChatCacheDatabaseController {
}
public removeMessage(chat: number, msg: number) {
return new Promise<void>((resolve, reject) => {
const store = this.buildChatMessageStore(chat);
store.delete(msg);
const d = store.delete(msg);
d.onsuccess = () => resolve();
d.onerror = () => reject();
});
}
public mergeChatList(source1: Chat[], source2: Chat[]) {
......
......@@ -162,7 +162,7 @@ export function formatTime(
if (String(time).indexOf("-")) {
time = String(time).replace(/-/g, "/");
}
if (/^\d+$/.test(time + '') && +time < STANDARD) {
if (/^\d+$/.test(time + "") && +time < STANDARD) {
time = +time * 1000;
}
const t = new Date(time);
......@@ -222,3 +222,13 @@ export function formatTime(
format2DetailTime(hour, t, option.rule)
);
}
export function parseString2TimeValue(time: string, defaultValue = 0) {
if (!time) {
return defaultValue;
}
if (String(time).indexOf("-")) {
time = String(time).replace(/-/g, "/");
}
return new Date(time).valueOf();
}
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