Create new inbox

Hello! I’m a student of the University Of Oviedo, and we are creating an app using Solid.
The main idea is to share routes, so we decide to create a folder in root with the name viade, where we have one folder for the routes (viade/routes) and now i want to create a new inbox in viade, so the notifications of the app will be here, pulled apart from the other notifications in the inbox in root.

One idea i had, is that @inrupt/solid-react-components has a hook, useNotification, that has a lot of methods thats helps to do this. One, is the method “createInbox”, that has three params: inboxPath, appPath, settingFileName, but dont know how to use it because i think i put the params wrong or something like that…

I hope someone could help me

1 Like

Hey there! I’m actually working on documentation now for how the React SDK sample application demonstrates things like this. I still think that is likely the best example for now, but a few things to note:

First, Solid pods get inboxes created when you register a new pod, so there will always be a global inbox. You can see what an inbox is in Solid by looking there - and essentially, it’s just a regular container. The only difference is an inbox is linked from somewhere via ldp:inbox predicate, as you can see on your profile card. All new Solid users should have this.

In the SDK we decided that global inbox isn’t enough, we want more granular control over inboxes, so we created our own. Our path, as described in the generated application, is /public/games/ticttactoe, and there we initialize a bunch of stuff: data.ttl file, which links out to external games, settings.ttl which stores game settings, and /inbox container. We link to the full /public/games/tictactoe/inbox path in settings.ttl using ldp:inbox (in theory you can move this inbox anywhere as long as it is linked from settings.ttl).

Some of the sample code creating an inbox in the Tic Tac Toe game can be seen here.

You’re right that there are three params (the last is optional):

inboxPath is the full path to where you want the inbox to be, so for example https://mypod.provider.com/public/inbox.
appPath is the root path where your app data is stored, for example https://mypod.provider.com/public/myAppData
settingFileName is the optional param, and this is the file where your ldp:inbox link goes. By default it will be settings.ttl stored in the appPath container. You can change the name here if you want.

Once all these are in place, the createInbox function will create the new inbox (if it doesn’t exist), create settings,ttl (if it doesn’t exist) and then link the inbox in settings.ttl via ldp:inbox for you.

2 Likes

@james.martin
For the inbox folder, do you grant ‘Authenticated Pod’ to Submitter Authorization? If not how can someone post to the inbox?

From your-pod.solid.community/inbox/.acl

# ACL resource for the profile Inbox

@prefix acl: <http://www.w3.org/ns/auth/acl#>.
@prefix foaf: <http://xmlns.com/foaf/0.1/>.

<#owner>
    a acl:Authorization;

    acl:agent
        <https://otman.solid.community/profile/card#me>;

    acl:accessTo <./>;
    acl:defaultForNew <./>;

    acl:mode
        acl:Read, acl:Write, acl:Control.

# Public-appendable but NOT public-readable
<#public>
    a acl:Authorization;

    acl:agentClass foaf:Agent;  # everyone

    acl:accessTo <./>;

    acl:mode acl:Append.

So it’s append access for everyone

2 Likes

Yes. @A_A is correct about what we add. “You” are owner of your inbox, of course, but we grant “all” users Append permissions. This was done in the SDK to mirror what the default settings of the root /inbox is.

We also handle all of that in the createInbox call as well. We use the SDK’s ACL library to set up permissions once the new inbox was created, with the following lines:

const permissions = [{ agents: null, modes: [AccessControlList.MODES.APPEND] }];
const aclContainer = await ACLFactory.createNewAcl(this.owner, newInboxPath);
await aclContainer.createACL(permissions);

Side note - in the ACL library, it usually takes an array of agents you wish to change/create permissions for. If you instead send “null” that is setting the permission for all agents, aka the “Everyone” option.

But in summary, if you’re using createInbox in the React SDK, this is automatically handled by the createInbox function call.

1 Like

Thanks!! i have tried what you said, and it works!!. First it looks if there is a folder name inbox, if it exists, i look to the permissions (if a have to change something), and if it’s linked in settings.ttl(if it doesn’t exist, i create it).
But now i have another doubt. This is in a folder in root that i have created that is private, so how can I get the user’s inbox to create a notification? To send the notification i use de hook useNotification again and a method createNotification, and i have to get the user’s inbox path if i want to send the notification.
Sorry if i don’t explain very well hahaha

1 Like

Excellent! Glad it worked.

So, to send a notification you’re correct that there’s a hook function called createNotification. This takes 4 params (two are optional). The call is createNotification(content, to, type, license);

content is a JSON representation of the fields in the notification shape. A very simple example (from App.js in the solid-react-components library) is:

{
      title: 'Notification Example',
      summary: 'This is a basic solid notification example.',
      actor: 'https://solidsdk.inrupt.net/profile/card#me'
}

This will load up the title, summary, and “actor” fields for you in the notification.

to is the inbox you are sending the notification to. However we don’t want to hardcode inbox IRIs, so instead we have a helper function called discoverInbox which will take any resource and look for a ldp:inbox link and return it. Usage example:

const inboxUrl = await discoverInbox(userWebID);

So that’s probably what you will want to send.

The last two, type and license, are optional. type is an IRI to a notification type based on ActivityStream types, and we provide a lookup file as a JS const for these types. The default is NotificationTypes.ANNOUNCE but we also use INVITE. license similarly is an IRI to a license, and we provide a default license if you don’t provide one. This is a license for distribution of each notification.

I hope this helps!

4 Likes

I’m sorry if I’m being a pain, but this is costing me a little hahaha.
I have a problem now, and that is that the settings.ttl I generate, nobody has access to it nor to read it, write it, etc… only the owner. So to get my friend’s inbox, he won’t let me because, if he has a settings.ttl in the path I’m looking for, I can’t look at it.
Also, I don’t know how to look if there is the settings.ttl file that I need (because if it doesn’t exist, my friend doesn’t have the file structure that my application generates, so I can’t nor i don’t want to send him the notification).

Looking at the sample generated application from the SDK, the settings.ttl should have Everyone View access. It sounds like your ACLs are set differently - are you inheriting it from somewhere else, or is it just not setting it initially properly?

There is an access control list class in the solid-react-components you could use to update the permissions once the file is created as well. (However, make sure you use the provided Factory to create new instances).

1 Like

Hi @james.martin,
When try to import @inrupt/solid-react-components using yarn add @inrupt/solid-react-components I get the following error
./node_modules/@inrupt/solid-react-components/build/index.js
Module not found: Can’t resolve ‘styled-components’ in
Do you know how to solve it?
Thanks

Hello! This is my personal account but it’s me, James. It looks like you’re missing a dev dependency, styled-components. It should already be packaged but try yarn installing that package and see if it clears things up?

I’m no longer active on this project unfortunately, so I’ve not been very involved in the last few months.

3 Likes