ssb-threads
TypeScript icon, indicating that this package has built-in type declarations

10.8.0 • Public • Published

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.

  • opts.reverse: boolean, default true. false means threads will be delivered from oldest to most recent, true means they will be delivered from most recent to oldest.
  • opts.threadMaxSize: optional number (default: Infinity). Dictates the maximum amount of messages in each returned thread object. Serves for previewing threads, particularly long ones.
  • opts.allowlist: optional array of strings. Dictates which messages types to allow as root messages, while forbidding other types.
  • opts.blocklist: optional array of strings. Dictates which messages types to forbid as root messages, while allowing other types.
  • opts.following: optional boolean (default: false). true means only threads created by those directly followed (and yourself) will be emitted. Requires ssb-friends.

ssb.threads.publicSummary(opts)

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

  • opts.reverse: boolean, default true. false means threads will be delivered from oldest to most recent, true means they will be delivered from most recent to oldest.
  • opts.allowlist: optional array of strings. Dictates which messages types to allow as root messages, while forbidding other types.
  • opts.blocklist: optional array of strings. Dictates which messages types to forbid as root messages, while allowing other types.
  • opts.following: optional boolean (default: false). true means only summaries for threads created by those directly followed (and yourself) will be emitted. Requires ssb-friends.

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.

  • opts.includeSelf: optional boolean that indicates if updates from yourself (the current ssb.id) should be included in this stream or not.
  • opts.allowlist: optional array of strings. Dictates which messages types to allow as root messages, while forbidding other types.
  • opts.blocklist: optional array of strings. Dictates which messages types to forbid as root messages, while allowing other types.
  • opts.following: optional boolean (default: false). true means only message keys for threads created by those directly followed will be emitted. Requires ssb-friends.

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 #).

  • opts.hashtag: string, required. This is a short hashtag string such as #animals that identifies which content categary we are interested in.
  • opts.allowlist: optional array of strings. Dictates which messages types to allow as root messages, while forbidding other types.
  • opts.blocklist: optional array of strings. Dictates which messages types to forbid as root messages, while allowing other types.

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 #).

  • opts.hashtag: string, required unless you have opts.hashtags. This is a short hashtag string such as #animals that identifies which content category we are interested in.
  • opts.hashtags: array of strings, optional. Like opts.hashtag but allows you to specify multiple hashtags such that summaries returned will match any of the hashtags.
  • opts.reverse: boolean, default true. false means threads will be delivered from oldest to most recent, true means they will be delivered from most recent to oldest.
  • opts.allowlist: optional array of strings. Dictates which messages types to allow as root messages, while forbidding other types.
  • opts.blocklist: optional array of strings. Dictates which messages types to forbid as root messages, while allowing other types.

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.

  • opts.hashtag: string, required unless you have opts.hashtags. This is a short hashtag string such as #animals that identifies which content category we are interested in.
  • opts.hashtags: array of strings, optional. Like opts.hashtag but allows you to specify multiple hashtags such that summaries returned will match any of the hashtags.
  • opts.allowlist: optional array of strings. Dictates which messages types to allow as root messages, while forbidding other types.
  • opts.blocklist: optional array of strings. Dictates which messages types to forbid as root messages, while allowing other types.

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.

  • opts.query: string, required. Prefix string used to identify the hashtags we are interested in.
  • opts.limit: number, default 10. Limits the number of results that are returned.

ssb.threads.private(opts)

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

  • opts.reverse: boolean, default true. false means threads will be delivered from oldest to most recent, true means they will be delivered from most recent to oldest.
  • opts.threadMaxSize: optional number (default: Infinity). Dictates the maximum amount of messages in each returned thread object. Serves for previewing threads, particularly long ones.
  • opts.allowlist: optional array of strings. Dictates which messages types to allow as root messages, while forbidding other types.
  • opts.blocklist: optional array of strings. Dictates which messages types to forbid as root messages, while allowing other types.

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.

  • opts.limit: number, required. Limits the number of results that are returned.
  • opts.preserveCase: optional boolean, default false. Return the hashtag labels with their original casing. By default, all hashtag labels are converted to lowercase but there are times when it's preferable to preserve the casing as seen in 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.

  • opts.includeSelf: optional boolean that indicates if updates from yourself (the current ssb.id) should be included in this stream or not.
  • opts.allowlist: optional array of strings. Dictates which messages types to allow as root messages, while forbidding other types.
  • opts.blocklist: optional array of strings. Dictates which messages types to forbid as root messages, while allowing other types.

ssb.threads.profile(opts)

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

  • opts.id: FeedId of some SSB user.
  • opts.reverse: boolean., default true. false means threads will be delivered from oldest to most recent, true means they will be delivered from most recent to oldest.
  • opts.threadMaxSize: optional number (default: Infinity). Dictates the maximum amount of messages in each returned thread object. Serves for previewing threads, particularly long ones.
  • opts.allowlist: optional array of strings. Dictates which messages types to allow as root messages, while forbidding other types.
  • opts.blocklist: optional array of strings. Dictates which messages types to forbid as root messages, while allowing other types.

ssb.threads.profileSummary(opts)

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

  • opts.id: FeedId of some SSB user.
  • opts.reverse: boolean, default true. false means threads will be delivered from oldest to most recent, true means they will be delivered from most recent to oldest.
  • opts.allowlist: optional array of strings. Dictates which messages types to allow as root messages, while forbidding other types.
  • opts.blocklist: optional array of strings. Dictates which messages types to forbid as root messages, while allowing other types.

ssb.threads.thread(opts)

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

  • opts.root: a MsgId that identifies the root of the thread.
  • opts.private: optional boolean indicating that (when true) you want to get only private messages, or (when false) only public messages; ⚠️ Warning: you should only use this locally, do not allow remote peers to call ssb.threads.thread, you don't want them to see your encrypted messages.
  • opts.threadMaxSize: optional number (default: Infinity). Dictates the maximum amount of messages in each returned thread object. Serves for previewing threads, particularly long ones.
  • opts.allowlist: optional array of strings. Dictates which messages types to allow as root messages, while forbidding other types.
  • opts.blocklist: optional array of strings. Dictates which messages types to forbid as root messages, while allowing other types.

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.

  • opts.root: a MesgId that identifies the root of the thread.
  • opts.private: optional boolean indicating that (when true) you want to get only private messages, or (when false) only public messages; ⚠️ Warning: you should only use this locally, do not allow remote peers to call ssb.threads.thread, you don't want them to see your encrypted messages.
  • opts.allowlist: optional array of strings. Dictates which messages types to allow as root messages, while forbidding other types.
  • opts.blocklist: optional array of strings. Dictates which messages types to forbid as root messages, while allowing other types.

Install

npm install --save ssb-threads

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i ssb-threads

Weekly Downloads

59

Version

10.8.0

License

MIT

Unpacked Size

83.4 kB

Total Files

12

Last publish

Collaborators

  • staltz
  • arj03