OverviewFilesCommitsIssuesDocsReleasesPeers

keet-cli / keet-core-4.14.4-pretty / lib / core / migrations / 3 / messages.js

134 lines · javascript ref:
const e = require("@holepunchto/hyperindex"),
  d = require("compact-encoding")
;((module.exports.IndexFilePointer = [e.BUFFER, e.STRING, e.UINT]),
  (module.exports.RecentsKeyEncoding = {
    preencode(e, o) {
      d.lexint.preencode(e, o)
    },
    encode(e, o) {
      d.lexint.encode(e, o)
    },
    decode(e) {
      const o = e.start
      try {
        return d.lexint.decode(e)
      } catch {
        return ((e.start = o), d.uint.decode(e))
      }
    },
  }))
const o = {
  preencode(e, o) {
    ;(e.end++,
      o.displayName && d.string.preencode(e, o.displayName),
      o.avatar && d.buffer.preencode(e, o.avatar))
  },
  encode(e, o) {
    const n = e.start++
    let c = 0
    ;(o.displayName && ((c |= 1), d.string.encode(e, o.displayName)),
      o.avatar && ((c |= 2), d.buffer.encode(e, o.avatar)),
      (e.buffer[n] = c))
  },
  decode(e) {
    const o = d.uint.decode(e)
    return {
      displayName: 1 & o ? d.string.decode(e) : null,
      avatar: 2 & o ? d.buffer.decode(e) : null,
    }
  },
}
;((module.exports.FileRecord = {
  preencode(e, o) {
    ;(d.uint.preencode(e, 0), d.fixed32.preencode(e, o.roomKey))
  },
  encode(e, o) {
    const n = e.start++
    d.fixed32.encode(e, o.roomKey)
    let c = 0
    ;(o.cleared && (c |= 1), (e.buffer[n] = c))
  },
  decode(e) {
    const o = d.uint.decode(e)
    return { roomKey: d.fixed32.decode(e), cleared: !!(1 & o) }
  },
}),
  (module.exports.RoomRecord = {
    preencode(e, o) {
      ;(e.end++,
        d.uint.preencode(e, o.unread),
        d.uint.preencode(e, o.priority),
        d.bool.preencode(e, o.bookmarked),
        o.indexing && d.bool.preencode(e, o.indexing))
    },
    encode(e, n) {
      const c = e.start++
      ;(d.uint.encode(e, n.unread), d.uint.encode(e, n.priority), d.bool.encode(e, n.bookmarked))
      let i = 0
      ;(n.indexing && ((i |= 1), d.bool.encode(e, n.indexing)),
        n.incognito && ((i |= 2), o.encode(e, n.incognito)),
        n.hidden && (i |= 4),
        (e.buffer[c] = i))
    },
    decode(e) {
      const n = d.uint.decode(e)
      return {
        unread: d.uint.decode(e),
        priority: d.uint.decode(e),
        bookmarked: d.bool.decode(e),
        indexing: !!(1 & n) && d.bool.decode(e),
        incognito: 2 & n ? o.decode(e) : null,
        hidden: !!(4 & n),
      }
    },
  }))
const n = {
  preencode(e, o) {
    ;(e.end++,
      d.fixed32.preencode(e, o.identityPublicKey),
      d.buffer.preencode(e, o.deviceProof),
      d.buffer.preencode(e, o.sharedInviteSeed))
  },
  encode(e, o) {
    const n = e.start++
    d.fixed32.encode(e, o.identityPublicKey)
    let c = 0
    ;(o.deviceProof && ((c |= 1), d.buffer.encode(e, o.deviceProof)),
      o.sharedInviteSeed && ((c |= 2), d.buffer.encode(e, o.sharedInviteSeed)),
      (e.buffer[n] = c))
  },
  decode(e) {
    const o = d.uint.decode(e)
    return {
      identityPublicKey: d.fixed32.decode(e),
      deviceProof: 1 & o ? d.buffer.decode(e) : null,
      sharedInviteSeed: 2 & o ? d.buffer.decode(e) : null,
    }
  },
}
module.exports.LocalIdentityRecord = {
  preencode(e, o) {
    ;(d.uint.preencode(e, 2),
      d.fixed32.preencode(e, o.privateProfileKey),
      o.deviceName && d.string.preencode(e, o.deviceName),
      o.identity && n.preencode(e, o.identity))
  },
  encode(e, o) {
    let c = 0
    ;(o.deviceName && (c |= 1),
      o.identity && (c |= 2),
      d.uint.encode(e, c),
      d.fixed32.encode(e, o.privateProfileKey),
      o.deviceName && d.string.encode(e, o.deviceName),
      o.identity && n.encode(e, o.identity))
  },
  decode(e) {
    const o = d.uint.decode(e)
    return {
      privateProfileKey: d.fixed32.decode(e),
      deviceName: 1 & o ? d.string.decode(e) : null,
      identity: 2 & o ? n.decode(e) : null,
    }
  },
}