This repository has been archived by the owner on Mar 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8744ff5
commit 6710642
Showing
7 changed files
with
842 additions
and
1,199 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.