Skip to content
This repository has been archived by the owner on Aug 9, 2021. It is now read-only.

Commit

Permalink
openThread in docs (#690)
Browse files Browse the repository at this point in the history
* openThread in docs

* remove joinThreads
  • Loading branch information
RachBLondon authored and oed committed Jan 9, 2020
1 parent 796cc52 commit 41027bd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ console.log(profile)
3Box allows applications to create, read, update, and delete public and private data stored in a user's 3Box. To enable this functionality, applications must first authenticate the user's 3Box by calling the `auth` method. This method prompts the user to authenticate (sign-in) to your dapp and returns a promise with a threeBox instance. You can only update (set, get, remove) data for users that have authenticated to and are currently interacting with your dapp. Below `ethereumProvider` refers to the object that you would get from `web3.currentProvider`, or `window.ethereum`.

#### 1. Create a 3Box instance
To create a 3Box session you call the `create` method. This creates an instance of the Box class which can be used to joinThreads and authenticate the user in any order. In order to create a 3Box session a `provider` needs to be passed. This can be an `ethereum provider` (from `web3.currentProvider`, or `window.ethereum`) or a `3ID Provider` (from [IdentityWallet](https://github.com/3box/identity-wallet-js)).
To create a 3Box session you call the `create` method. This creates an instance of the Box class which can be used to openThreads and authenticate the user in any order. In order to create a 3Box session a `provider` needs to be passed. This can be an `ethereum provider` (from `web3.currentProvider`, or `window.ethereum`) or a `3ID Provider` (from [IdentityWallet](https://github.com/3box/identity-wallet-js)).
```js
const box = await Box.create(provider)
```
Expand All @@ -72,7 +72,7 @@ When you first authenticate the box in your dapp all data might not be synced fr
```js
await box.syncDone
```
This will allow you to know when all the user's data is available to you. We advise against *setting* any data before this sync has happened. However, reading data before the sync is complete is fine and encouraged - just remember to check for updates once the sync is finished!
This will allow you to know when all the user's data is available to you. We advise against *setting* any data before this sync has happened. However, reading data before the sync is complete is fine and encouraged - just remember to check for updates once the sync is finished! Please note, `box.syncDone` can only be called once the user has been authenticated, it is not possible if only the `Box.create` method has been called.

If you prefer to not use promises you can add a callback using the `onSyncDone` method.

Expand Down Expand Up @@ -113,11 +113,12 @@ await box.private.setMultiple(privateFields, privateValues)
```

##### Open a thread
Once you have created a 3Box session you can open a thread to view data in it. This can be done before you authenticate the user to be able to post in the thread.
Once you have created a 3Box session you can open a thread to view data in it. This can be done before you authenticate the user (required for them to post in the thread).
When opening a thread the moderation options need to be given. You can pass `firstModerator`, a 3ID (or ethereum address) of the first moderator, and a `members` boolean which indicates if it is a members thread or not.
```js
const thread = await box.openThread('myDapp', 'myThread', { firstModerator: 'did:3:bafy...', members: true })
```
Once a thread has been opened you can call the `getPosts()` method to retrive the posts.


<!-- commenting this out for now, not really needed when we're not using the iframe
Expand Down Expand Up @@ -184,6 +185,7 @@ You can get all posts made in a thread without opening a space. This is great fo
const posts = await Box.getThread(spaceName, threadName, firstModerator, membersThread)
console.log(posts)
```
Threads can also be viewed without opening space, or authenticating by calling the `getPosts()` method on the thread object returned from `openThread` (see Open a thread section above).

```js
const posts = await Box.getThreadByAddress(threadAddress)
Expand Down
8 changes: 5 additions & 3 deletions readme-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ console.log(profile)
3Box allows applications to create, read, update, and delete public and private data stored in a user's 3Box. To enable this functionality, applications must first authenticate the user's 3Box by calling the `auth` method. This method prompts the user to authenticate (sign-in) to your dapp and returns a promise with a threeBox instance. You can only update (set, get, remove) data for users that have authenticated to and are currently interacting with your dapp. Below `ethereumProvider` refers to the object that you would get from `web3.currentProvider`, or `window.ethereum`.

#### 1. Create a 3Box instance
To create a 3Box session you call the `create` method. This creates an instance of the Box class which can be used to joinThreads and authenticate the user in any order. In order to create a 3Box session a `provider` needs to be passed. This can be an `ethereum provider` (from `web3.currentProvider`, or `window.ethereum`) or a `3ID Provider` (from [IdentityWallet](https://github.com/3box/identity-wallet-js)).
To create a 3Box session you call the `create` method. This creates an instance of the Box class which can be used to openThreads and authenticate the user in any order. In order to create a 3Box session a `provider` needs to be passed. This can be an `ethereum provider` (from `web3.currentProvider`, or `window.ethereum`) or a `3ID Provider` (from [IdentityWallet](https://github.com/3box/identity-wallet-js)).
```js
const box = await Box.create(provider)
```
Expand All @@ -72,7 +72,7 @@ When you first authenticate the box in your dapp all data might not be synced fr
```js
await box.syncDone
```
This will allow you to know when all the user's data is available to you. We advise against *setting* any data before this sync has happened. However, reading data before the sync is complete is fine and encouraged - just remember to check for updates once the sync is finished!
This will allow you to know when all the user's data is available to you. We advise against *setting* any data before this sync has happened. However, reading data before the sync is complete is fine and encouraged - just remember to check for updates once the sync is finished! Please note, `box.syncDone` can only be called once the user has been authenticated, it is not possible if only the `Box.create` method has been called.

If you prefer to not use promises you can add a callback using the `onSyncDone` method.

Expand Down Expand Up @@ -113,11 +113,12 @@ await box.private.setMultiple(privateFields, privateValues)
```

##### Open a thread
Once you have created a 3Box session you can open a thread to view data in it. This can be done before you authenticate the user to be able to post in the thread.
Once you have created a 3Box session you can open a thread to view data in it. This can be done before you authenticate the user (required for them to post in the thread).
When opening a thread the moderation options need to be given. You can pass `firstModerator`, a 3ID (or ethereum address) of the first moderator, and a `members` boolean which indicates if it is a members thread or not.
```js
const thread = await box.openThread('myDapp', 'myThread', { firstModerator: 'did:3:bafy...', members: true })
```
Once a thread has been opened you can call the `getPosts()` method to retrive the posts.


<!-- commenting this out for now, not really needed when we're not using the iframe
Expand Down Expand Up @@ -184,6 +185,7 @@ You can get all posts made in a thread without opening a space. This is great fo
const posts = await Box.getThread(spaceName, threadName, firstModerator, membersThread)
console.log(posts)
```
Threads can also be viewed without opening space, or authenticating by calling the `getPosts()` method on the thread object returned from `openThread` (see Open a thread section above).

```js
const posts = await Box.getThreadByAddress(threadAddress)
Expand Down

0 comments on commit 41027bd

Please sign in to comment.