Commit c81c9fb5 by Sixong.Zhu

update sort

parent 153f4070
Showing with 20 additions and 9 deletions
...@@ -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);
}); });
} }
...@@ -334,7 +334,7 @@ export default { ...@@ -334,7 +334,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,
...@@ -393,6 +393,8 @@ export default { ...@@ -393,6 +393,8 @@ export default {
async [ChatStore.ACTION_GET_MY_CHAT_LIST]({ commit, state }) { async [ChatStore.ACTION_GET_MY_CHAT_LIST]({ commit, state }) {
let cache = await dbController.getChatList(); let cache = await dbController.getChatList();
cache.sort((x, y) => (x.last_msg_ts < y.last_msg_ts ? 1 : -1));
for (const item of cache) { for (const item of cache) {
if (item.business_data && !item.detail_name) { if (item.business_data && !item.detail_name) {
const d = JSON.parse( const d = JSON.parse(
...@@ -836,7 +838,7 @@ export default { ...@@ -836,7 +838,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);
}) })
); );
...@@ -1054,16 +1056,25 @@ export default { ...@@ -1054,16 +1056,25 @@ export default {
if (cache[id]) { if (cache[id]) {
return Promise.resolve({ id, name: cache[id] }); return Promise.resolve({ id, name: cache[id] });
} }
return new Promise<{ id: string; name: string }>((resolve, reject) => { return new Promise<{ id: string; name: string }>(
Chat.getSdk().model("user") (resolve, reject) => {
Chat.getSdk()
.model("user")
.detail(id) .detail(id)
.query() .query()
.then((userInfo: any) => { .then((userInfo: any) => {
const name = userInfo.row.first_name.display as string; const name = userInfo.row.first_name
Vue.set(state[ChatStore.STATE_CHAT_USERNAME], id, name); .display as string;
Vue.set(
state[ChatStore.STATE_CHAT_USERNAME],
id,
name
);
resolve({ id, name }); resolve({ id, name });
}).catch(reject); })
}); .catch(reject);
}
);
}, },
}, },
getters: { getters: {
......
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