OverviewFilesCommitsIssuesDocsReleasesPeers

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

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