diff --git a/gui/src/js/chatHandler.ts b/gui/src/js/chatHandler.ts index 79191f3b..3138b07f 100644 --- a/gui/src/js/chatHandler.ts +++ b/gui/src/js/chatHandler.ts @@ -20,7 +20,7 @@ import { sendMessage, sendBroadcastChannel } from "./sock.js"; import { displayToast } from "./popupHandler.js"; //const FD = require("./src/js/freedata.js"); -import { btoa_FD } from "./freedata.js"; +import { btoa_FD,sortByProperty } from "./freedata.js"; // define default message object interface Attachment { @@ -279,16 +279,6 @@ function sortChatList() { 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) { return new Promise(async (resolve, reject) => { try { diff --git a/gui/src/js/freedata.ts b/gui/src/js/freedata.ts index 6f532bee..18fdd623 100644 --- a/gui/src/js/freedata.ts +++ b/gui/src/js/freedata.ts @@ -25,3 +25,22 @@ export function atob(data) { //exports.atob = function (data) { return window.btoa(Buffer.from(data, "base64").toString("utf8")); } +//https://medium.com/@asadise/sorting-a-json-array-according-one-property-in-javascript-18b1d22cd9e9 +export function sortByProperty(property) { + return function (a, b) { + if (a[property] > b[property]) return 1; + else if (a[property] < b[property]) return -1; + + return 0; + }; +} + +//https://medium.com/@asadise/sorting-a-json-array-according-one-property-in-javascript-18b1d22cd9e9 +export function sortByPropertyDesc(property) { + return function (a, b) { + if (a[property] < b[property]) return 1; + else if (a[property] > b[property]) return -1; + + return 0; + }; +} \ No newline at end of file