Fetch comments

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

Contents

Fetch comments

Get a data identifier handle

The plugin fetches a data identifier handle for the appendable data associated with the current page.

Get data ID handle

POST /data-id/appendable-data
controller.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.html

The 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

GET /appendable-data/handle/:dataIdHandle
controller.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

GET /appendable-data/metadata/:handleId
controller.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 data ID handle at index

GET /appendable-data/:handleId/:index
controller.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 handle

GET /immutable-data/reader/:handleId
controller.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.

Read immutable data

GET /immutable-data/:handleId
controller.js
window.safeImmutableData.read(this._authToken, handleId)

Drop the immutable data reader handle

The plugin drops the immutable data reader handle.

Drop immutable data reader handle

DELETE /immutable-data/reader/:handleId
controller.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

GET /structured-data/handle/:dataIdHandle
controller.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.

Read structured data

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.

Drop structured data handle

DELETE /structured-data/handle/:handleId
controller.js
window.safeStructuredData.dropHandle(this._authToken, hId)

Drop the data identifier handle

The plugin drops the data identifier handle of the current comment.

Drop data ID handle

DELETE /data-id/:handleId
controller.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.

Drop data ID handle

DELETE /data-id/:handleId
controller.js
window.safeDataId.dropHandle(this._authToken, dataIdHandle)

results matching ""

    No results matching ""