about summary refs log tree commit diff
path: root/src/state/models/muted-threads.ts
blob: e6f2027452ad71b6d2c20c4cd733d1458fb12e5c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**
 * This is a temporary client-side system for storing muted threads
 * When the system lands on prod we should switch to that
 */

import {makeAutoObservable} from 'mobx'
import {isObj, hasProp, isStrArray} from 'lib/type-guards'

export class MutedThreads {
  uris: Set<string> = new Set()

  constructor() {
    makeAutoObservable(
      this,
      {serialize: false, hydrate: false},
      {autoBind: true},
    )
  }

  serialize() {
    return {uris: Array.from(this.uris)}
  }

  hydrate(v: unknown) {
    if (isObj(v) && hasProp(v, 'uris') && isStrArray(v.uris)) {
      this.uris = new Set(v.uris)
    }
  }
}