const e = require("safety-catch"),
{ PrivateRoomSchema: t } = require("@holepunchto/keet-core-schemas"),
{ AddPrivateRoomOperation: o, RemovePrivateRoomOperation: a } = t.Operations
module.exports = class {
static Operations = new Set([o.TYPE, a.TYPE])
constructor(e) {
;((this.profile = e), (this.rooms = null))
}
initialize() {
this.rooms = this.profile.view.collections.privateRooms
}
async _applyAddPrivateRoomOperation(e) {
const { key: t } = e.value
await this.rooms.update(t, { key: t }, { upsert: !0 })
}
async _applyRemovePrivateRoomOperation(t) {
const { key: o } = t.value
try {
await this.rooms.delete(o)
} catch (t) {
e(t)
}
}
async autobaseApply(e, t) {
switch (e.type) {
case o.TYPE:
return this._applyAddPrivateRoomOperation(e, t)
case a.TYPE:
return this._applyRemovePrivateRoomOperation(e, t)
}
}
}