Fetch comments
The plugin fetches the comments associated with the current page and adds them to the UI.
Contents

Get a data identifier handle
The plugin fetches a data identifier handle for the appendable data associated with the current page.
POST /data-id/appendable-datacontroller.js
window.safeDataId.getAppendableDataHandle(this._authToken, this._getLocation())The name of the appendable data is based on the URL of the current page.
controller.js
_getLocation () {
if (this._isDevMode() && this._data.user.dns) {
return `comments-dev-${this._data.user.dns}/${window.location.pathname}`
}
return `${this._hostName}/${window.location.pathname}`
}Example
blog.example//post.htmlThe actual name of the appendable data is the hash of _getLocation().
Get an appendable data handle
The plugin fetches an appendable data handle using the data identifier handle previously obtained.
GET /appendable-data/handle/:dataIdHandlecontroller.js
window.safeAppendableData.getHandle(
this._authToken, dataHandleId)Get the metadata of the appendable data
The plugin fetches the metadata of the appendable data using the appendable data handle. The length of the appendable data represents the number of comments for the current page.
GET /appendable-data/metadata/:handleIdcontroller.js
window.safeAppendableData.getMetadata(
this._authToken, this._currentPostHandleId)If the data length is 0, it means that the current page doesn't have any comments.
Iterate through the appendable data
If the data length is greater than 0, the plugin fetches all the comments contained inside the appendable data.
Get a data identifier handle from the appendable data
The plugin fetches a data identifier handle from the appendable data based on the current index.
GET /appendable-data/:handleId/:indexcontroller.js
window.safeAppendableData.getDataIdAt(
this._authToken, this._currentPostHandleId, index)Permanent comments
If the current page is using the Permanent Comments Plugin, the plugin will expect the comments inside the appendable data to be stored as immutable data.
Get an immutable data reader handle
The plugin fetches the data map of the comment using the data identifier handle of the current comment.
GET /immutable-data/reader/:handleIdcontroller.js
window.safeImmutableData.getReaderHandle(this._authToken, address)The API returns an immutable data reader handle.
Read the immutable data
The plugin reads the immutable data representing the comment using the immutable data reader handle.
GET /immutable-data/:handleIdcontroller.js
window.safeImmutableData.read(this._authToken, handleId)Drop the immutable data reader handle
The plugin drops the immutable data reader handle.
DELETE /immutable-data/reader/:handleIdcontroller.js
window.safeImmutableData.dropReader(this._authToken, hId)Editable comments
If the current page is using the Editable Comments Plugin, the plugin will expect the comments inside the appendable data to be stored as structured data.
Get a structured data handle
The plugin fetches a structured data handle using the data identifier handle of the current comment.
GET /structured-data/handle/:dataIdHandlecontroller.js
window.safeStructuredData.getHandle(this._authToken, address)Fetch the structured data
The plugin fetches the content of the structured data using the structured data handle.
GET /structured-data/:handleId/:version?controller.js
window.safeStructuredData.readData(this._authToken, payload.handleId)Drop the structured data handle
The plugin drops the structured data handle of the current comment.
DELETE /structured-data/handle/:handleIdcontroller.js
window.safeStructuredData.dropHandle(this._authToken, hId)Drop the data identifier handle
The plugin drops the data identifier handle of the current comment.
DELETE /data-id/:handleIdcontroller.js
window.safeDataId.dropHandle(this._authToken, dataIdHandle)The plugin continues iterating through the appendable data until all the comments it contains have been fetched. The plugin then sorts them by time and adds them to the UI.
Drop the data identifier handle for appendable data
The plugin drops the data identifier handle of the appendable data associated with the current page.
DELETE /data-id/:handleIdcontroller.js
window.safeDataId.dropHandle(this._authToken, dataIdHandle)Last updated
Was this helpful?