Add a comment
You can add comments by appending them to the appendable data associated with the current page.
Contents

Permanent comments
If the current page is using the Permanent Comments Plugin, the plugin will store your new comment using the Immutable Data API. This means that once a comment is posted, it can't be edited (immutable data doesn't have any owner).
Get an immutable data writer handle
The plugin fetches an immutable data writer handle.
GET /immutable-data/writer
controller.js
window.safeImmutableData.getWriterHandle(this._authToken)
Write immutable data
The plugin stores the comment as immutable data using the immutable data writer handle.
POST /immutable-data/:handleId
controller.js
window.safeImmutableData.write(this._authToken, writerHandle, payload)
The payload parameter contains the public name you selected, your comment and the current timestamp in JSON format.
controller.js
const payload = new Buffer(JSON.stringify({
name: publicName,
comment: comment,
time: timeStamp
}));
Example
{
"name": "example",
"comment": "Hello, world!",
"time": 1476741155526
}
Close the immutable data writer
The plugin saves the data map of the comment as immutable data on the SAFE Network.
PUT /immutable-data/:handleId/:cipherOptsHandle
controller.js
window.safeImmutableData.closeWriter(this._authToken, writerHandle)
Editable comments
If the current page is using the Editable Comments Plugin, the plugin will store your new comment using the Structured Data API. This means that users will be able to edit their own comments.
Create a structured data
The plugin fetches a structured data handle for the comment you want to add.
POST /structured-data
controller.js
window.safeStructuredData.create(this._authToken, name, 501, payload)
Parameters
The name parameter will be the public name you selected combined with the current timestamp and a random string. The actual ID of the structured data will be the hash of the name parameter.
The type tag will be 501 (versioned) because the editable comments plugin lets you see the previous versions of each comment.
The payload parameter will contain the public name you selected, your comment and the current timestamp in JSON format (stored as a base64 string).
controller.js
const timeStamp = (new Date()).getTime()
const name = publicName + timeStamp + generateRandomString()
const payload = new Buffer(JSON.stringify({
name: publicName,
comment: comment,
time: timeStamp
})).toString('base64')
Example
{
"name": "example",
"comment": "test 123",
"time": 1475234797311
}
Save the structured data
The plugin saves the structured data representing your comment to the SAFE Network.
PUT /structured-data/:handleId
controller.js
window.safeStructuredData.put(this._authToken, currentSDHandleId)
Get a data identifier handle
The plugin fetches a data identifier handle using the structured data handle representing your comment.
GET /structured-data/data-id/:handleId
controller.js
window.safeStructuredData.getDataIdHandle(this._authToken, currentSDHandleId)
Append the comment to the appendable data
The plugin appends the data identifier handle representing your comment to the appendable data of the current page.
PUT /appendable-data/:handleId/:dataIdHandle
controller.js
window.safeAppendableData.append(this._authToken, this._currentPostHandleId, dataIdHandle)
Drop the data identifier handle
The plugin drops the data identifier handle representing your comment.
DELETE /data-id/:handleId
controller.js
window.safeDataId.dropHandle(this._authToken, dataIdHandle)
Drop the immutable data writer handle
If the current page is using the Permanent Comments Plugin, the plugin drops the immutable data writer handle.
DELETE /immutable-data/writer/:handleId
controller.js
window.safeImmutableData.dropWriter(this._authToken, writerHandle)
Drop the structured data handle
If the current page is using the Editable Comments Plugin, the plugin drops the structured data handle.
DELETE /structured-data/handle/:handleId
controller.js
window.safeStructuredData.dropHandle(this._authToken, currentSDHandleId)
After successfully adding your comment to the appendable data of the current page, the plugin reloads the comments.
Last updated
Was this helpful?