ssbc / ssb-threads

Scuttlebot plugin for fetching messages as threads
MIT License
21 stars 5 forks source link

ssb-threads

A Scuttlebot plugin for fetching messages as threads

Usage

This plugin requires ssb-db2 v3.4.0 or higher and does not support ssb-db. If the ssb-friends plugin is available it will filter the messages of blocked users and provide the option of only retrieving information about threads created by users you follow directly.

 SecretStack({appKey: require('ssb-caps').shs})
   .use(require('ssb-master'))
   .use(require('ssb-db2'))
   .use(require('ssb-conn'))
   .use(require('ssb-friends'))
+  .use(require('ssb-threads'))
   .use(require('ssb-blobs'))
   .call(null, config)
pull(
  ssb.threads.public({
    reverse: true, // threads sorted from most recent to least recent
    threadMaxSize: 3, // at most 3 messages in each thread
  }),
  pull.drain(thread => {
    console.log(thread);
  }),
);

API

"Thread objects"

Whenever an API returns a so-called "thread object", it refers to an object of shape { messages, full } where messages is an array of SSB messages, and full is a boolean indicating whether messages array contains all of the possible messages in the thread. Any message that has its root field or branch field or fork field pointing to the root of the thread can be included in this array, but sometimes we may omit a message if the threadMaxSize has been reached, in which case the messages.length will be equal to the threadMaxSize option.

In TypeScript:

type Thread = {
  messages: Array<Msg>;
  full: boolean;
}

"Summary objects"

Whenever an API returns a so-called "thread summary object", it refers to an object of shape { root, replyCount } where root is an SSB message for the top-most post in the thread, and replyCount is a number indicating how many other messages (besides the root) are in the thread. In TypeScript:

type ThreadSummary = {
  root: Msg;
  replyCount: number;
}

ssb.threads.public(opts)

Returns a pull stream that emits thread objects of public messages.

ssb.threads.publicSummary(opts)

Returns a pull stream that emits summary objects of public threads.

ssb.threads.publicUpdates(opts)

Returns a ("live") pull stream that emits a message key (strings) for every new message that passes the (optional) allowlist or blocklist.

ssb.threads.hashtagCount(opts, cb)

Gets the number of public threads that match a specific hashtag opts.hashtag. "Hashtag" here means msg.value.content.channel and msg.value.content.mentions[].link (beginning with #).

ssb.threads.hashtagSummary(opts)

Similar to publicSummary but limits the results to public threads that match a specific hashtag opts.hashtag. "Hashtag" here means msg.value.content.channel and msg.value.content.mentions[].link (beginning with #).

ssb.threads.hashtagUpdates(opts)

Returns a ("live") pull stream that emits the message key (string) for thread roots every time there is a new reply or root tagged with the given opts.hashtag, and that passes the (optional) allowlist or blocklist.

ssb.threads.hashtagsMatching(opts, cb)

Call the callback with an array of [hashtagLabel, count] tuples where hashtagLabel begins with opts.query. "hashtagLabel" here means msg.value.content.channel and msg.value.content.mentions[].link (omitting the #). Results are ordered based on the number of occurrences for the hashtag (count) from highest to lowest.

ssb.threads.private(opts)

Returns a pull stream that emits thread objects of private conversations.

ssb.threads.recentHashtags(opts, cb)

Call the callback with an array of hashtags labels of length opts.limit (defaults to 10 if unspecified). "hashtagLabel" here means msg.value.content.channel and msg.value.content.mentions[].link (omitting the #). Results are ordered with the most recent first, as determined by the log.

ssb.threads.privateUpdates(opts)

Returns a ("live") pull stream that emits the message key (string) for thread roots every time there is a new reply or root, and that passes the (optional) allowlist or blocklist.

ssb.threads.profile(opts)

Returns a pull stream that emits thread objects of public messages initiated by a certain profile id.

ssb.threads.profileSummary(opts)

Returns a pull stream that emits summary objects of public messages where the profile id participated in.

ssb.threads.thread(opts)

Returns a pull stream that emits one thread object of messages under the root identified by opts.root (MsgId).

If opts.allowlist and opts.blocklist are not defined, only messages of type post will be returned.

ssb.threads.threadUpdates(opts)

Returns a ("live") pull stream that emits every new message which is a reply to this thread, and which passes the (optional) allowlist or blocklist.

Install

npm install --save ssb-threads

License

MIT