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

Commit

Permalink
Message display bugs fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
RisottoNacho committed Apr 4, 2019
1 parent 8744ff5 commit 6710642
Show file tree
Hide file tree
Showing 7 changed files with 842 additions and 1,199 deletions.
1,703 changes: 664 additions & 1,039 deletions src/index.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/scripts/LogInManager.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
var podUtils = require('./podUtilities.js');

async function login (credentials) {
async function login(credentials) {
podUtils.login(credentials);
$('#login').addClass('d-none');
$('#logout').removeClass('d-none');
$('#chatRef').removeClass('d-none');
}

async function logout () {
async function logout() {
podUtils.logout();
$('#login').removeClass('d-none');
$('#logout').addClass('d-none');
Expand Down
172 changes: 86 additions & 86 deletions src/scripts/NotificationManager.js
Original file line number Diff line number Diff line change
@@ -1,115 +1,115 @@
var podUtils = require('./podUtilities.js');
const notAppend="SolidChatNot";
const notAppend = "SolidChatNot";
//Method for Delete readed Notifications (Current user open)
async function deleteNotification(userURI, reciver){
var userInbox = userURI+"inbox/";
//List all user
var List=[];
List = await readAllNotification(userInbox);
var newList=[]
async function deleteNotification(userURI, reciver) {
var userInbox = userURI + "inbox/";
//List all user
var List = [];
List = await readAllNotification(userInbox);
var newList = []

//UpdateList
for(var i=0; i<List.length;i++){
if(List[i]!=reciver)
newList.push(List[i]);
}
//AddUsers
var text ="";
if(newList.length>0){
text= " noti:news";
for(var i=0; i<newList.length;i++){
text+= " \""+newList[i]+"\",";
}
text=text.slice(0,-1);
text+= " .";
//UpdateList
for (var i = 0; i < List.length; i++) {
if (List[i] != reciver)
newList.push(List[i]);
}
//AddUsers
var text = "";
if (newList.length > 0) {
text = " noti:news";
for (var i = 0; i < newList.length; i++) {
text += " \"" + newList[i] + "\",";
}
text = text.slice(0, -1);
text += " .";
}

//Write final Notification
var noti = "@prefix : <#> . \n"
noti+= "@prefix noti: <http://schema.org/> . \n"
noti+= "@prefix user: <"+userInbox+"/> . \n"
noti+= "\n"
noti+= ":notifications \n"
noti+= " a noti:Notification ; \n"
noti+= text;
await podUtils.deleteFile(userInbox+notAppend+".ttl", false);
await podUtils.writeTurtle(userInbox+notAppend, noti, false);
//Write final Notification
var noti = "@prefix : <#> . \n"
noti += "@prefix noti: <http://schema.org/> . \n"
noti += "@prefix user: <" + userInbox + "/> . \n"
noti += "\n"
noti += ":notifications \n"
noti += " a noti:Notification ; \n"
noti += text;

await podUtils.deleteFile(userInbox + notAppend + ".ttl", false);
await podUtils.writeTurtle(userInbox + notAppend, noti, false);
}

//Method for write new Notification on send Msg
async function writeNotification(receiverURI, user){

var receiverInbox = receiverURI+"inbox/";
//List all user
var List=[];
console.log("#####Leyendo");
List = await readAllNotification(receiverURI);

var existe=0;
//UpdateList
for(var i=0; i<List.length;i++){
if(List[i]==user)
existe=1;
}
async function writeNotification(receiverURI, user) {

if(existe==0)
List.push(user);
var receiverInbox = receiverURI + "inbox/";
//List all user
var List = [];
console.log("#####Leyendo");
List = await readAllNotification(receiverURI);

//AddUsers
var text= " noti:news";
for(var i=0; i<List.length;i++){
text+= " \""+List[i]+"\",";
}
text=text.slice(0,-1);
text+= " .";
var existe = 0;
//UpdateList
for (var i = 0; i < List.length; i++) {
if (List[i] == user)
existe = 1;
}

//Write final Notification
var noti = "@prefix : <#> . \n"
noti+= "@prefix noti: <http://schema.org/> . \n"
noti+= "@prefix user: <"+receiverURI+"/> . \n"
noti+= "\n"
noti+= ":notifications \n"
noti+= " a noti:Notification ; \n"
noti+= text;
console.log("#########Borrando");
await podUtils.deleteFile(receiverInbox+notAppend+".ttl", false);
console.log("########Escribiendo");
await podUtils.writeTurtle(receiverInbox+notAppend, noti, false);
if (existe == 0)
List.push(user);

//AddUsers
var text = " noti:news";
for (var i = 0; i < List.length; i++) {
text += " \"" + List[i] + "\",";
}
text = text.slice(0, -1);
text += " .";

//Write final Notification
var noti = "@prefix : <#> . \n"
noti += "@prefix noti: <http://schema.org/> . \n"
noti += "@prefix user: <" + receiverURI + "/> . \n"
noti += "\n"
noti += ":notifications \n"
noti += " a noti:Notification ; \n"
noti += text;
console.log("#########Borrando");
await podUtils.deleteFile(receiverInbox + notAppend + ".ttl", false);
console.log("########Escribiendo");
await podUtils.writeTurtle(receiverInbox + notAppend, noti, false);
}
//Methor for constantly reading new Notifications from others chat
async function readAllNotification(receiverURI){
async function readAllNotification(receiverURI) {
//Read Notification file
var receiverInbox = receiverURI+"inbox/";
var fileURL = receiverInbox+notAppend+".ttl";
var receiverInbox = receiverURI + "inbox/";
var fileURL = receiverInbox + notAppend + ".ttl";

//ERROR 403 forbidden
var file = await podUtils.readFile(fileURL,true);
var file = await podUtils.readFile(fileURL, true);

var userList=[];
if(file!=null){
var userList = [];
if (file != null) {
//Return all user with notifications
var usersText = file.split("\"");
for(var i=0; i<usersText.length ; i++){
if(i%2==1){
for (var i = 0; i < usersText.length; i++) {
if (i % 2 == 1) {
userList.push(usersText[i]);
}

}
}else{
} else {
var noti = "@prefix : <#> . \n"
noti+= "@prefix noti: <http://schema.org/> . \n"
noti+= "@prefix user: <"+receiverURI+"/> . \n"
noti+= "\n"
noti+= ":notifications \n"
noti+= " a noti:Notification ; \n"
await podUtils.writeTurtle(receiverInbox+notAppend, noti, false);
noti += "@prefix noti: <http://schema.org/> . \n"
noti += "@prefix user: <" + receiverURI + "/> . \n"
noti += "\n"
noti += ":notifications \n"
noti += " a noti:Notification ; \n"
await podUtils.writeTurtle(receiverInbox + notAppend, noti, false);
}
return userList;
}

module.exports = {
deleteNotification : deleteNotification,
writeNotification : writeNotification,
readAllNotification : readAllNotification
deleteNotification: deleteNotification,
writeNotification: writeNotification,
readAllNotification: readAllNotification
}
20 changes: 10 additions & 10 deletions src/scripts/chatManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var podUtils = require('./podUtilities.js');
var notiMan = require('./NotificationManager.js');

const ToLog = true;
const notify= false;
const notify = false;


class message {
Expand Down Expand Up @@ -57,8 +57,8 @@ async function sendMessage(text) {


ret = await podUtils.createFile(filename, jsonString, ToLog);
if(notify)
await notiMan.writeNotification(INFO.receiverURI, INFO.user);
if (notify)
await notiMan.writeNotification(INFO.receiverURI, INFO.user);
} catch (error) {

//IF folder doesnt exist: create new user folder
Expand Down Expand Up @@ -103,11 +103,11 @@ async function sendMessage(text) {
messages.push(new message(text, new Date().getTime()));
jsonString = JSON.stringify(messages);


ret = await podUtils.createFile(filename, jsonString, ToLog);
if(notify)
await notiMan.writeNotification(INFO.receiverURI, INFO.user);
if (notify)
await notiMan.writeNotification(INFO.receiverURI, INFO.user);

}
return ret;
}
Expand Down Expand Up @@ -158,7 +158,7 @@ async function receiveMessages() {
dict.push(new message("<div class=\"containerChat\"><p id=\"noMarginMessge\">" + element.text + "</p><p id=\"username\">" + INFO.receiverName + " " + strDate + "</p></div>", date));
});

dict.sort(function(a, b) {
dict.sort(function (a, b) {
return a.date > b.date ? 1 : a.date < b.date ? -1 : 0;
});

Expand All @@ -169,8 +169,8 @@ async function receiveMessages() {
MESSAGES.toShow = MESSAGES.toShow.slice(-10);

//Delete existing notifiations
if(notify)
notiMan.deleteNotification(INFO.userURI, INFO.receiver);
if (notify)
notiMan.deleteNotification(INFO.userURI, INFO.receiver);

return MESSAGES.toShow;
}
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function updateMessages(toShow) {
if (chatM.ToLog)
console.log("Update msgs");
var messages = "";
$('#messages').empty();
$('#messages').empty();
toShow.forEach((message) => {
messages = messages + message;
});
Expand Down
Loading

0 comments on commit 6710642

Please sign in to comment.