How to use the ssb-ref.isFeedId function in ssb-ref

To help you get started, we’ve selected a few ssb-ref examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github blockades / patchbay-dark-crystal / views / component / recipients.js View on Github external
addSuggest(input, (inputText, cb) => {
    if (state.recps.getLength() >= state.maxRecps) return
    // TODO - tell the user they're only allowed 6 (or 7?!) people in a message

    if (isFeedId(inputText)) return
    // suggest mention not needed, handled by eventListener above

    const searchTerm = inputText.replace(/^@/, '')
    suggest.about(searchTerm, cb)
  }, {cls: 'PatchSuggest'})
github luandro / ssb-graphql-defaults / schema / ssb / message / helpers.js View on Github external
export const getHistoryStream = ({ id, sequence = 0 }, sbot, pubsub, channel) => {
  if (!ref.isFeedId(id)) { reject(console.log(`${id} is not a valid feed ID`)) }
  console.log('Starting', sbot.createHistoryStream)
  pull(
    sbot.createHistoryStream({ id, sequencex }),
    pull.drain(message => {
      console.log('Got msg', message)
      return pubsub.publish(channel, { message })
    }),
  )
}
github blockades / patchbay-dark-crystal / views / component / recipients.js View on Github external
input.addEventListener('keyup', (e) => {
    if (isFeedId(e.target.value)) {
      addRecp({ state, link: e.target.value }, (err) => {
        if (err) console.error(err)

        e.target.value = ''
        e.target.placeholder = ''
      })
      return
    }

    if (isBackspace(e) && state.isEmpty && state.recps.getLength() > state.minRecps) {
      recps.pop()
      onChange()
    }

    state.isEmpty = e.target.value.length === 0
  })
github soapdog / patchfox / src / router / sync / routes.js View on Github external
const Intercept = ({ encodedId }, _state, _url) => {
            let id = decodeURIComponent(encodedId).replace("ssb:", "");
            switch (id[0]) {
            case "#":
                window.location.hash = "channel/" + id.slice(1);
                break;
            case "%":
                if (!isMsgId(id)) {
                    console.error(`intercept url should been a msg but it is not: ${id}`);
                    return false;
                }
                window.location.hash = "thread/" + encodeURIComponent(id);
                break;
            case "@":
                if (!isFeedId(id)) {
                    console.error(`intercept url should been a feed but it is not: ${id}`);
                    return false;
                }
                window.location.hash = "feed/" + encodeURIComponent(id);
                break;
            case "&":
                if (!isBlobId(id)) {
                    console.error(`intercept url should been a blob but it is not: ${id}`);
                    return false;
                }
                window.location = "http://localhost:8989/blobs/get/" + id;
                break;
            }

            if (id.indexOf("javascript:") === 0) {
                return h("h1", "stop trying to inject JS here");
github staltz / manyverse / src / frontend / components / Markdown.ts View on Github external
link: (props: {children: any; href: string}) => {
    const isFeedCypherlink = Ref.isFeedId(props.href);
    const isMsgCypherlink = Ref.isMsgId(props.href);
    const isCypherlink = isFeedCypherlink || isMsgCypherlink;
    const isChildCypherlink =
      props.children.length === 1 &&
      (Ref.isFeedId(props.children[0]) || Ref.isMsgId(props.children[0]));
    return $(
      Text,
      {
        ...textProps,
        style: isCypherlink ? styles.cypherlink : styles.link,
        onPress: () => {
          if (isFeedCypherlink) {
            GlobalEventBus.dispatch({
              type: 'triggerFeedCypherlink',
              feedId: props.href,
            });
          } else if (isMsgCypherlink) {
            GlobalEventBus.dispatch({
              type: 'triggerMsgCypherlink',
              msgId: props.href,
            });
github blockades / patchbay-dark-crystal / views / component / recipient.js View on Github external
module.exports = function Recipient ({ recp, avatar, name = identity }) {
  if (isFeedId(recp)) {
    return h('DarkCrystalRecipient', [ avatar(recp) ])
  }

  if (!isFeedId(recp.link)) throw new Error('Recipient expects { link: feedId, name }')

  return h('DarkCrystalRecipient', [
    avatar(recp.link),
    h('div.name', [
      isName(recp.name) ? recp.name : name(recp.link)
    ])
  ])
}
github ssbc / ssb-validate / index.js View on Github external
exports.checkInvalidCheap = function (state, msg) {
  //the message is just invalid
  if(!ref.isFeedId(msg.author))
    return new Error('invalid message: must have author')
  if(!isSigMatchesCurve(msg))
    return new Error('invalid message: signature type must match author type')

  //state is id, sequence, timestamp
  if(state) {
    //most likely, we just tried to append two messages twice
    //or append another message after an error.
    if(msg.sequence != state.sequence + 1)
      return new Error('invalid message: expected sequence ' + (state.sequence + 1) + ' but got:'+ msg.sequence + 'in state:'+JSON.stringify(state)+', on feed:'+msg.author)
    //if the timestamp doesn't increase, they should have noticed at their end.
    if(isNaN(state.timestamp)) throw new Error('state must have timestamp property, on feed:'+msg.author)
    //if we have the correct sequence and wrong previous,
    //this must be a fork!
    if(msg.previous != state.id)
      return fatal(new Error('invalid message: expected different previous message, on feed:'+msg.author))
github blockades / patchbay-dark-crystal / views / component / recipient-input.js View on Github external
input.addEventListener('keyup', (e) => {
    let targetIsntEmpty = e.target.value.length !== 0
    let recpsLength = recps.getLength()
    let isBackspace = (e.code === 'Backspace' || e.key === 'Backspace' || e.keyCode === 8)
    let isEnter = (e.code === 'Enter' || e.key === 'Enter' || e.keyCode == 13)

    if (isEnter && isFeedId(e.target.value)) {
      recps.push(e.target.value)
      boxActive = false
      e.target.value = ''
      e.target.placeholder = ''
    }

    if (boxActive) {
      if (targetIsntEmpty) boxActive = false
      return
    }

    if (targetIsntEmpty) {
      targetEmpty = false
      return
    }
github staltz / manyverse / src / frontend / components / Markdown.ts View on Github external
link: (props: {children: any; href: string}) => {
    const isFeedCypherlink = Ref.isFeedId(props.href);
    const isMsgCypherlink = Ref.isMsgId(props.href);
    const isCypherlink = isFeedCypherlink || isMsgCypherlink;
    const isChildCypherlink =
      props.children.length === 1 &&
      (Ref.isFeedId(props.children[0]) || Ref.isMsgId(props.children[0]));
    return $(
      Text,
      {
        ...textProps,
        style: isCypherlink ? styles.cypherlink : styles.link,
        onPress: () => {
          if (isFeedCypherlink) {
            GlobalEventBus.dispatch({
              type: 'triggerFeedCypherlink',
              feedId: props.href,
            });