about summary refs log tree commit diff
path: root/src/state/messages/convo/util.ts
blob: 92046cf1f59df6aa86339f51bdacf5853cfa8c5f (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
30
31
32
import {
  ConvoState,
  ConvoStateBackgrounded,
  ConvoStateDisabled,
  ConvoStateReady,
  ConvoStateSuspended,
  ConvoStatus,
} from './types'

/**
 * States where the convo is ready to be used - either ready, or backgrounded/suspended
 * and ready to be resumed
 */
export type ActiveConvoStates =
  | ConvoStateReady
  | ConvoStateBackgrounded
  | ConvoStateSuspended
  | ConvoStateDisabled

/**
 * Checks if a `Convo` has a `status` that is "active", meaning the chat is
 * loaded and ready to be used, or its in a suspended or background state, and
 * ready for resumption.
 */
export function isConvoActive(convo: ConvoState): convo is ActiveConvoStates {
  return (
    convo.status === ConvoStatus.Ready ||
    convo.status === ConvoStatus.Backgrounded ||
    convo.status === ConvoStatus.Suspended ||
    convo.status === ConvoStatus.Disabled
  )
}