1
0
mirror of https://github.com/chylex/Discord-History-Tracker.git synced 2025-04-10 17:15:43 +02:00

Refactor savefile and state in renderer

This commit is contained in:
chylex 2016-11-02 17:20:40 +01:00
parent c5b6e1d110
commit b54ab16a39
2 changed files with 13 additions and 20 deletions

View File

@ -13,10 +13,7 @@ SAVEFILE.isValid = function(parsedObj){
};
SAVEFILE.prototype.getServer = function(index){
return this.meta.servers[index] || {
name: "<unknown>",
type: "ERROR"
};
return this.meta.servers[index] || { name: "<unknown>", type: "ERROR" };
};
SAVEFILE.prototype.getChannels = function(){
@ -42,11 +39,9 @@ SAVEFILE.prototype.getMessageCount = function(channel){
SAVEFILE.prototype.getAllMessages = function(){
var messages = {};
for(var channelKey of Object.keys(this.data)){
for(var messageKey of Object.keys(this.data[channelKey])){
messages[messageKey] = this.data[channelKey][messageKey];
}
}
UTILS.forEachValue(this.data, messageObject => {
UTILS.combineObjects(messages, messageObject);
});
return messages;
};

View File

@ -6,8 +6,13 @@ var STATE = (function(){
var currentPage;
var messagesPerPage;
var getPageCount = function(){
return !MSGS ? 0 : (!messagesPerPage ? 1 : Math.ceil(MSGS.length/messagesPerPage));
var messageKeySorter = (key1, key2) => {
if (key1.length === key2.length){
return key1 > key2 ? 1 : key1 < key2 ? -1 : 0;
}
else{
return key1.length > key2.length ? 1 : -1;
}
};
return {
@ -40,14 +45,7 @@ var STATE = (function(){
selectedChannel = channel;
currentPage = 1;
MSGS = Object.keys(FILE.getMessages(channel)).sort((key1, key2) => {
if (key1.length === key2.length){
return key1 > key2 ? 1 : key1 < key2 ? -1 : 0;
}
else{
return key1.length > key2.length ? 1 : -1;
}
});
MSGS = Object.keys(FILE.getMessages(channel)).sort(messageKeySorter);
},
getSelectedChannel: function(){
@ -104,7 +102,7 @@ var STATE = (function(){
},
getPageCount: function(){
return getPageCount();
return !MSGS ? 0 : (!messagesPerPage ? 1 : Math.ceil(MSGS.length/messagesPerPage));
}
};
})();