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

Commit

Permalink
Testing some getters and setters
Browse files Browse the repository at this point in the history
  • Loading branch information
enriquead committed Apr 2, 2019
1 parent 6161ea7 commit b020887
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 140 deletions.
50 changes: 13 additions & 37 deletions lib/commgroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class GroupCommunication {
this.sendMessageToGroup(personal, myUrlFile, message);
} catch (e) {
core.logger.error(`Could not send message to the group.`);
core.logger.error(e);
core.logger.error(e);
}
await this.loadMessages(personal, myUrlFile);
}
Expand All @@ -118,19 +118,11 @@ class GroupCommunication {
var messageTx = message;

fc.readFile(urlCore).then( success => {
var newText = '\n\n\n:'+messageUrl+' a \t\tschem:Message;\n'+
'\tschem:dateSent\t\"'+time+'\";\n'+
'\tschem:givenName\t\"'+personal.username+'\";\n'+
'\tschem:text\t"'+messageTx+'"\t.';
var newText = '\n\n\n:'+messageUrl+' a \t\tschem:Message;\n'+'\tschem:dateSent\t\"'+time+'\";\n'+
'\tschem:givenName\t\"'+personal.username+'\";\n'+ '\tschem:text\t"'+messageTx+'"\t.';
var body = success + newText;

fc.updateFile(urlCore, body).then( success => {
console.log( `Message sent to group.`)
}, err => console.log(err) );
}, err => console.log(err) );
fc.updateFile(urlCore, body).then( success => { console.log( `Message sent to group.`) }, err => console.log(err) );}, err => console.log(err) );
}


/**
* This method sends an invitation to an user
* @param receiver is the user who recives the invitation
Expand All @@ -143,44 +135,31 @@ class GroupCommunication {
var header = "@prefix : <#>.\n@prefix stor: <http://example.org/storage/>.\n@prefix schem: <http://schema.org/>.\n@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .";
var body = ':CHAT\n\tstor:storeIn <'+urlCore+'>;\n\tschem:name "'+groupName+'";\n\tschem:dateRead "'+dateTimeZero+'"^^xsd:dateTime .';

fc.updateFile(urlFile, header + "\n\n\n" + body).then( success => {
console.log("Create group file in other POD");
}, err => console.log(err) );
fc.updateFile(urlFile, header + "\n\n\n" + body).then( success => {console.log("Create group file in other POD");}, err => console.log(err) );
}

createCoreFile(personal, rand, groupName, friendsGroup){
var urlCore = "https://"+personal.username+".solid.community/inbox/groupcore_"+rand+".ttl";

var header = "@prefix : <#>.\n@prefix stor: <http://example.org/storage/>.\n@prefix schem: <http://schema.org/>.\n@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .";
var body = ':GROUP\n\tschem:name "'+groupName+'" .';

fc.updateFile(urlCore, header + "\n\n\n" + body).then( success => {
console.log("Create group file in other POD");
}, err => console.log(err) );
fc.updateFile(urlCore, header + "\n\n\n" + body).then( success => {console.log("Create group file in other POD"); }, err => console.log(err) );

fc.updateFile(urlCore + ".acl", this.templatePermission(friendsGroup, "groupcore_" + rand+ ".ttl")).then( success => {
console.log("Gave permission correctly")
}, err => console.log(err) );
fc.updateFile(urlCore + ".acl", this.templatePermission(friendsGroup, "groupcore_" + rand+ ".ttl")).then( success => {console.log("Gave permission correctly")}, err => console.log(err) );
}

templatePermission(friends, file){
var header = "@prefix : <#>.\n"+
"@prefix n0: <http://www.w3.org/ns/auth/acl#>.\n"+
"@prefix n1: <http://xmlns.com/foaf/0.1/>.\n"+
"@prefix c: </profile/card#>.\n";
var header = "@prefix : <#>.\n"+"@prefix n0: <http://www.w3.org/ns/auth/acl#>.\n"+
"@prefix n1: <http://xmlns.com/foaf/0.1/>.\n"+ "@prefix c: </profile/card#>.\n";
var i = 0;
for(let friend of friends){
header += "@prefix c"+i+": <https://"+friend.username+".solid.community/profile/card#>.\n";
i++;
}
header += "\n:ControlReadWrite\n"+
"\ta n0:Authorization;\n"+
"\tn0:accessTo <"+file+">;\n"+
"\tn0:agent c:me;\n"+
"\tn0:mode n0:Control, n0:Read, n0:Write.\n"+
":ReadWrite\n"+
"\ta n0:Authorization;\n"+
"\tn0:accessTo <"+file+">;\n"+
header += "\n:ControlReadWrite\n"+ "\ta n0:Authorization;\n"+
"\tn0:accessTo <"+file+">;\n"+"\tn0:agent c:me;\n"+
"\tn0:mode n0:Control, n0:Read, n0:Write.\n"+":ReadWrite\n"+
"\ta n0:Authorization;\n"+"\tn0:accessTo <"+file+">;\n"+
"\tn0:agent ";
for(var j=0; j<i; j++){
header += "c" + j + ":me";
Expand All @@ -206,8 +185,6 @@ class GroupCommunication {
return exists;
}



async clearInbox(core, personal){
const resources = await core.getAllResourcesInInbox(await core.getInboxUrl(personal.userWebId));

Expand Down Expand Up @@ -235,5 +212,4 @@ class GroupCommunication {
return chatGroups;
}
}

module.exports = GroupCommunication;
59 changes: 19 additions & 40 deletions lib/commprivate.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,36 +154,29 @@ class PrivateCommunication {
async sendPhoto(personal,core,file){
console.log("Now in commprivate " + file.name);
var a = $("#possible-people option:selected").val();
var receiver = core.getFriendOfList(personal.friendList, a);
var extensionFile = file.name.split(".").pop();

var myUrlFile = "https://"+personal.username+".solid.community/inbox/"+receiver.username+"-"+this.randomString(10)+"."+extensionFile;
$("#data-name").val(myUrlFile);
console.log(myUrlFile);
fc.createFile(myUrlFile).then( fileCreated => {
console.log(`Created file ${fileCreated}.`);
}, err => console.log(err) );

var content = "";
var reader = new FileReader();
reader.onload = function (evento) {
//El evento "onload" se lleva a cabo cada vez que se completa con éxito una operación de lectura
//La propiedad "result" es donde se almacena el contenido del archivo
//Esta propiedad solamente es válida cuando se termina la operación de lectura
content = reader.result;
}
reader.readAsBinaryString(file);
console.log(content);
var receiver = core.getFriendOfList(personal.friendList, a);
var extensionFile = file.name.split(".").pop();

var myUrlFile = "https://"+personal.username+".solid.community/inbox/"+receiver.username+"-"+this.randomString(10)+"."+extensionFile;
$("#data-name").val(myUrlFile);
console.log(myUrlFile);
fc.createFile(myUrlFile).then( fileCreated => {console.log(`Created file ${fileCreated}.`);}, err => console.log(err) );
var content = "";
var reader = new FileReader();
reader.onload = function (evento) {
//El evento "onload" se lleva a cabo cada vez que se completa con éxito una operación de lectura
//La propiedad "result" es donde se almacena el contenido del archivo
//Esta propiedad solamente es válida cuando se termina la operación de lectura
content = reader.result;
}
reader.readAsBinaryString(file);
console.log(content);
/*
fc.updateFile(myUrlFile + ".acl", this.templatePermission(receiver.username, receiver.username + ".ttl")).then( success => {
console.log("Gave permission to my friend")
}, err => console.log(err) );
*/

fc.updateFile(myUrlFile,content).then( success => {
console.log("Store photo in private");
}, err => console.log(err) );

fc.updateFile(myUrlFile,content).then( success => {console.log("Store photo in private");}, err => console.log(err) );
//await this.sendMessage(personal,core);
}

Expand All @@ -192,18 +185,6 @@ class PrivateCommunication {
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
/**
* This method sends a message to a friend
* Returns an error message if I can not send the message to the user
Expand Down Expand Up @@ -311,9 +292,7 @@ class PrivateCommunication {
*/
givePermission(myInbox, receiver){
fc.updateFile(myInbox + receiver.username + ".ttl.acl",
this.templatePermission(receiver.username, receiver.username+".ttl")).then( success => {
console.log( `Permissions changed in your file.`)
}, err => console.log(err) );
this.templatePermission(receiver.username, receiver.username+".ttl")).then( success => {console.log( `Permissions changed in your file.`)}, err => console.log(err));
};

templatePermission(other, file){
Expand Down
63 changes: 27 additions & 36 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,6 @@ class ChatCore {
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
async storePhoto(personal,file){
console.log("Now here " + file.name);
var a = $("#possible-people option:selected").val();
Expand All @@ -79,16 +70,7 @@ class ChatCore {
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////

async sendMessage(personal, a, message) {
if(message.length == 0)
return;
Expand Down Expand Up @@ -203,8 +185,7 @@ class ChatCore {
isFriend(text, myUser){
try{
this.getUsername(text);
if(this.checkNotMe(text, myUser))
return true;
if(this.checkNotMe(text, myUser)) return true;
return false;
} catch (TypeError){
return false;
Expand All @@ -228,38 +209,48 @@ class ChatCore {
async getObjectFromPredicateForResource(url, predicate) {
const deferred = Q.defer();
const rdfjsSource = await rdfjsSourceFromUrl(url, this.fetch);

if (rdfjsSource) {
const engine = newEngine();

engine.query(`SELECT ?o {
<${url}> <${predicate}> ?o.
}`,
engine.query(`SELECT ?o {<${url}> <${predicate}> ?o.}`,
{sources: [{type: 'rdfjsSource', value: rdfjsSource}]})
.then(function (result) {
result.bindingsStream.on('data', function (data) {
data = data.toObject();

deferred.resolve(data['?o']);
});

result.bindingsStream.on('end', function () {
deferred.resolve(null);
result.bindingsStream.on('data', function (data) {data = data.toObject();
deferred.resolve(data['?o']);
});
result.bindingsStream.on('end', function () {deferred.resolve(null);});
});
} else {
deferred.resolve(null);
}

return deferred.promise;
};

randomString(length) {
var chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
var result = '';
for (var i = length; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)];
return result;
}
// Getters and setters
getInboxUrls(){
return this.inboxUrls;
}

getFetch(){
return this.fetch;
}

getAlreadyCheckedResources(){
return this.alreadyCheckedResources;
}

getGroupCommunication(){

return this.commGroup;

}
getPrivateCommunication(){
this.commPrivate;
}
}

module.exports = ChatCore;
26 changes: 15 additions & 11 deletions lib/personal.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,30 +59,22 @@ class Personal {
})
}
}

getGroupByName(name){
for(var group of this.groupsLoaded){
if(group.name == name){
return group;
}
if(group.name == name){ return group;}
}
return id;
}

getGroupByID(id){
for(var group of this.groupsLoaded){
if(group.file.url.includes(id)){
return group;
}
if(group.file.url.includes(id)){return group;}
}
return null;
}

getGroupByMyUrl(url){
for(var group of this.groupsLoaded){
if(group.file.url == url){
return group;
}
if(group.file.url == url){ return group;}
}
return null;
}
Expand Down Expand Up @@ -115,8 +107,20 @@ class Personal {
};


//Getters and setters

getWebIdUrl(){
return this.userWebId;
}
getCore(){
return this.core;
}
getFriendList(){
return this.friendList;
}

}



module.exports = Personal;

0 comments on commit b020887

Please sign in to comment.