Giter Site home page Giter Site logo

ssb-suggest-fork's Introduction

ssb-suggest

Background

When a user is writing a post in Scuttlebutt, sometimes they may want to mention another user. In most ssb-clients which use markdown, @-mentions work via a hyperlink that wraps a user's ssb key in a markdown link like so:

Hey [@corlock](@sHFNLAao6phQ5AN17ecYNUbszDa4Qf6DhyQsjtQfdmY=.ed25519)! How are you?

Most likely, a user only know another person's alias (what you call them, or what they call themselves), and does not know their feedId.

Originally abstracted from Patchwork, this plugin provides a way to return a list of SSB users (with avatar, alias, feedId, etc) based on a query text for an user's alias. The primary use of this plugin is for auto-suggest in scuttlebutt clients, so when a user starts typing "@cor" in a message, they will be prompted with a visual list of suggestions that can be auto-completed to a functioning @-mention in ssb markdown.

Usage

ssb-suggest is a plugin for ssb-server. For documentation on how plugins work in Scuttlebutt, see here.

Requires other plugins :

  • ssb-backlinks,
  • ssb-about
  • EITHER ssb-friends OR patchwork!

This module was extracted from patchwork, originally written by Matt Mckegg

Example usage

var Server = require('ssb-server')
  .use(require('ssb-server/plugins/master'))
  .use(require('ssb-suggest'))

var Config = require('ssb-config')

var server = Server(Config()) // just use default config

server.suggest.profile({ text: 'mi' }, (err, matches) => {
  if (err) console.log('OH no!', err)

  // do something with matches
})

API

SSB Plugin API

Adhering to the secret-stack plugin format, this module exposes the following standard plugin exports as an object with properties:

  • name (string)
  • version (string)
  • init (function)
  • manifest (object)

server.suggest API

When used as illustrated above, the plugin's init function is executed under the hood, and the returned object (as specified in the manifest object) is set as the value for server.suggest.

server.suggest.profile(opts, cb)

opts is an Object with properties:

  • text (optional), the text you're searching profiles names by. If not provided, then, falls back to offering defaultIds (if provided) or a sample of the most recent message authors.

  • defaultIds (optional, default=[]), an array of feedIds that are important in the current context. They could be people present in the current thread for example. These will be fallback matches, but also be prioritised in any matches to text.

  • limit (optional), how many results you want back Default: 20

  • cb is a callback with signature (err, matches) where matches is an Array of objects of form:

{
  id: FeedId,
  matchedName: String, // the name your search matched (within name / names)
  name: String, // the name you know this person by
  names: Array, // the names people you follow have given this person
  image: Blob,
  following: Boolean // whether you currently follow them
}

ssb-suggest-fork's People

Contributors

christianbundy avatar clevinson avatar dependabot[bot] avatar dominictarr avatar mixmix avatar staltz avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.