OverviewFilesCommitsIssuesDocsReleasesPeers

keet-deobfuscated / @holepunchto / keet-core-schemas / lib / private-mailbox / messages.js

101 lines · javascript ref:
const e = require("compact-encoding"),
  { MemberId: o } = require("../members/messages"),
  { MessageId: d } = require("../chat/messages"),
  t = {
    preencode(d, t) {
      ;(e.uint.preencode(d, t.timestamp), o.preencode(d, t.roomKey), e.uint.preencode(d, t.seq))
    },
    encode(d, t) {
      ;(e.uint.encode(d, t.timestamp), o.encode(d, t.roomKey), e.uint.encode(d, t.seq))
    },
    decode: (d) => ({ timestamp: e.uint.decode(d), roomKey: o.decode(d), seq: e.uint.decode(d) }),
  },
  n = {
    preencode(o, t) {
      let n = 0
      ;(t.message && (n |= 1),
        t.invitation && (n |= 2),
        t.seen && (n |= 4),
        t.id && (n |= 8),
        t.mailId && (n |= 16),
        t.targetRoomKey && (n |= 32),
        t.receiverKey && (n |= 64),
        t.status && (n |= 128),
        e.uint.preencode(o, n),
        e.uint.preencode(o, t.type),
        e.buffer.preencode(o, t.senderKey),
        t.message && e.string.preencode(o, t.message),
        t.invitation && e.string.preencode(o, t.invitation),
        t.id && d.preencode(o, t.id),
        t.mailId && d.preencode(o, t.mailId),
        t.targetRoomKey && e.buffer.preencode(o, t.targetRoomKey),
        t.receiverKey && e.buffer.preencode(o, t.receiverKey),
        t.status && e.uint.preencode(o, t.status))
    },
    encode(o, t) {
      let n = 0
      ;(t.message && (n |= 1),
        t.invitation && (n |= 2),
        t.seen && (n |= 4),
        t.id && (n |= 8),
        t.mailId && (n |= 16),
        t.targetRoomKey && (n |= 32),
        t.receiverKey && (n |= 64),
        t.status && (n |= 128),
        e.uint.encode(o, n),
        e.uint.encode(o, t.type),
        e.buffer.encode(o, t.senderKey),
        t.message && e.string.encode(o, t.message),
        t.invitation && e.string.encode(o, t.invitation),
        t.id && d.encode(o, t.id),
        t.mailId && d.encode(o, t.mailId),
        t.targetRoomKey && e.buffer.encode(o, t.targetRoomKey),
        t.receiverKey && e.buffer.encode(o, t.receiverKey),
        t.status && e.uint.encode(o, t.status))
    },
    decode(o) {
      const t = e.uint.decode(o)
      return {
        seen: !!(4 & t),
        type: e.uint.decode(o),
        senderKey: e.buffer.decode(o),
        message: 1 & t ? e.string.decode(o) : null,
        invitation: 2 & t ? e.string.decode(o) : null,
        id: 8 & t ? d.decode(o) : null,
        mailId: 16 & t ? d.decode(o) : null,
        targetRoomKey: 32 & t ? e.buffer.decode(o) : null,
        receiverKey: 64 & t ? e.buffer.decode(o) : null,
        status: 128 & t ? e.uint.decode(o) : null,
      }
    },
  },
  r = {
    preencode(o, t) {
      let n = 0
      ;(t.roomKey && (n |= 1),
        t.status && (n |= 2),
        e.uint.preencode(o, n),
        d.preencode(o, t.id),
        t.roomKey && e.buffer.preencode(o, t.roomKey),
        t.status && e.uint.preencode(o, t.status))
    },
    encode(o, t) {
      let n = 0
      ;(t.roomKey && (n |= 1),
        t.status && (n |= 2),
        e.uint.encode(o, n),
        d.encode(o, t.id),
        t.roomKey && e.buffer.encode(o, t.roomKey),
        t.status && e.uint.encode(o, t.status))
    },
    decode(o) {
      const t = e.uint.decode(o)
      return {
        id: d.decode(o),
        roomKey: 1 & t ? e.buffer.decode(o) : null,
        status: 2 & t ? e.uint.decode(o) : null,
      }
    },
  }
module.exports = { DmIndexRecord: r, PrivateMailboxRecordId: t, PrivateMailboxRecordData: n }