Commit d70348a8 by Sixong.Zhu

时间戳排序

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