Skip to content
This repository has been archived by the owner on Mar 26, 2022. It is now read-only.

Commit

Permalink
Fixed bug with empty chats
Browse files Browse the repository at this point in the history
  • Loading branch information
troken11 committed Apr 3, 2019
1 parent 12951c8 commit 9c2f723
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions lib/commprivate.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class PrivateCommunication {
messages.push(new Message(sender,dateTime,message));
}
myMsgRead = true;
}, err => {if(!testing){$("#addOurMessages").empty()}});
}, err => {if(!testing){}});

fc.readFile(fileWithMessagesSentByTheOtherUSer).then( body => {
var res = body.split("\n\n\n");
Expand Down Expand Up @@ -86,7 +86,9 @@ class PrivateCommunication {
}else {
this.orderAndShow(messages, me,testing);
}
}, err => {if(!testing){$("#addOurMessages").empty()}} );
}, err => {if(!testing){
var that = this;
setTimeout(function(){that.orderAndShow(messages, me,testing);}, 500);}} );
}

orderAndShow(messages, me,testing){
Expand All @@ -97,23 +99,27 @@ class PrivateCommunication {
return new Date(b.dateTime) - new Date(a.dateTime);
});
if(!testing){
console.log(messages);
$("#addMessages").empty();
console.log(messages);
}
this.showMessages(messages,me,testing);
}

showMessages(messages, me,testing){
$("#addMessages").empty();
$("#addOurMessages").empty();
$("#addOtherMessages").empty();
}
for ( var i=messages.length-1; i>=0; i--){
var mesg = messages[i].content;
var mesgToAdd = "";
var year = messages[i].dateTime.split("-")[0];
var month = messages[i].dateTime.split("-")[1];
var day = messages[i].dateTime.split("-")[2].split("T")[0];
var hourMinute = messages[i].dateTime.split("T")[1];
var hour = hourMinute.split(":")[0];
var minute = hourMinute.split(":")[1];
var dateToAdd = year + "-" + month + "-" + day + " - " + hour + ":" + minute;;
var year = messages[i].dateTime.split("-")[0];
var month = messages[i].dateTime.split("-")[1];
var day = messages[i].dateTime.split("-")[2].split("T")[0];
var hourMinute = messages[i].dateTime.split("T")[1];
var hour = hourMinute.split(":")[0];
var minute = hourMinute.split(":")[1];
var dateToAdd = year + "-" + month + "-" + day + " - " + hour + ":" + minute;;
var format = mesg.split(".");
console.log(dateToAdd);
console.log(dateToAdd);
if (format[format.length-1] == "jpg" || format[format.length-1] == "gif" || format[format.length-1] == "png"){
mesgToAdd = "<p><img src='" + mesg + "'></p>";
}else{
Expand Down

0 comments on commit 9c2f723

Please sign in to comment.