Fix message sorting

This commit is contained in:
Mashintime 2023-10-18 23:55:24 -04:00
parent c55595484b
commit aa8abf021e
2 changed files with 19 additions and 4 deletions

View file

@ -21,7 +21,7 @@ import chat_new_message from "./chat_new_message.vue";
import { updateAllChat, newMessage } from "../js/chatHandler"; import { updateAllChat, newMessage } from "../js/chatHandler";
updateAllChat(); //updateAllChat();
</script> </script>
<template> <template>

View file

@ -232,13 +232,25 @@ function sortChatList() {
reorderedData[dxcallsign] = []; reorderedData[dxcallsign] = [];
} }
reorderedData[dxcallsign].push(obj); reorderedData[dxcallsign].push(obj);
reorderedData[dxcallsign] = reorderedData[dxcallsign].sort(sortByProperty("timestamp"));
} }
}); });
//console.log(reorderedData["DJ2LS-0"]) //console.log(reorderedData["2LS-0"])
return reorderedData; return reorderedData;
} }
//https://medium.com/@asadise/sorting-a-json-array-according-one-property-in-javascript-18b1d22cd9e9
function sortByProperty(property){
return function(a,b){
if(a[property] > b[property])
return 1;
else if(a[property] < b[property])
return -1;
return 0;
}
}
export function getMessageAttachment(id) { export function getMessageAttachment(id) {
@ -516,10 +528,13 @@ export async function updateAllChat(cleanup) {
} else { } else {
chat.unsorted_chat_list.push(item); chat.unsorted_chat_list.push(item);
chat.sorted_chat_list = sortChatList();
} }
} }
chat.sorted_chat_list = sortChatList();
/* /*
if (typeof result !== "undefined") { if (typeof result !== "undefined") {