Manage Friends using Solid

Hi! I’m currently in a work team and we are developing an application using Solid. We want to add a friendship system that allows the user to introduce the webID of one of his friends and the friend will be added in Solid. We are using the libraries @inrupt/solid-client and “@inrupt/vocab-common-rdf”

Until now I´m trying to store the webIDs as foaf:knows in the profile/card section of the user. The code with which i’m working is the following:

export async function addFriend(webID:string, friend:Friend): Promise<{ error: boolean, errorMessage: string }> {
    let profile = webID.split("#")[0]; //just in case there is extra information in the url
    // get the dataset from the url
    let dataSet = await getSolidDataset(profile, {fetch: fetch});  
  
    let dataSetThing = getThing(dataSet, webID) as Thing;

    try {
      let existsFriend = getUrlAll(dataSetThing, FOAF.knows)
      if (existsFriend.some((url) => url === friend.webID)){
        return{error:true,errorMessage:"You are already friends with this user!"}
      }
      else{
        // We create the friend
      let newFriend = buildThing(dataSetThing)
      .addUrl(FOAF.knows, friend.webID as string)
      .build();

      // insert friend in dataset
      dataSet = setThing(dataSet, dataSetThing);
      dataSet = await saveSolidDatasetAt(webID, dataSet, {fetch: fetch})
      return{error:false,errorMessage:""}
      }
    } catch (error){
      return{error:true,errorMessage:"Not a valid webId!"}
    }
}

This code does not break but no webIDs are added when looking at the source code of the profile/card.

Does anybody know where do I have the problem or another way in which this can be solved?
If you want to take a look, here is our GitHub repository: GitHub - Arquisoft/lomap_en2a: LoMap Software architecture group en2a course 2022_23
This piece of code is in the filter-patri branch.

Thank you very much in advance!

On the first look it seems fine. Have you checked what it actually stores? e.g. console.log(dataSet) before you save it and then also take a look at the network requests in the browser dev tools to see what is actually stored at the saveSolidDatasetAt call.

Oh, and you never use the newFriend variable?

We made it work! We used the browser to debug the flow of the eecution and apparently we were not grabbing the :me section of the profile card. But now is working.

Thank you very much! :grinning:

2 Likes