cautpartener / client / src / core / session.ts
 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
 * Per-tab session state the views share: the active identity (set by boot)
 * and the selfroom handle once its heavy stack finished loading in the
 * background. Views must tolerate selfroom === null (first seconds of boot,
 * or a mailbox-less offline session).
 */

import type { AudienceService } from "./audience";
import type { CallService } from "./calls";
import type { ContactsService } from "./contacts";
import type { ChatService } from "./conversations";
import type { HomeLang } from "./home-log";
import type { ActiveIdentity } from "./identity-store";
import type { SelfRoom } from "./selfroom";

export const Session: {
  identity: ActiveIdentity | null;
  selfroom: SelfRoom | null;
  /** Contact/group service over the selfroom; non-null once selfroom is up. */
  contacts: ContactsService | null;
  /** Conversation registry + chat rooms (M3); non-null once selfroom is up. */
  chat: ChatService | null;
  /** Audience-restriction keys/grants (M5b); non-null once selfroom is up. */
  audience: AudienceService | null;
  /** 1:1 audio/video calls (P4); non-null once selfroom is up. */
  calls: CallService | null;
  /**
   * Lang chosen before the selfroom was up, stamped with the CLICK-time ts —
   * LWW must order the intent at the moment the user acted, not at the later
   * flush time. Flushed (and awaited) by main.ts when the room starts.
   */
  pendingLang: { lang: HomeLang; ts: number } | null;
} = {
  identity: null,
  selfroom: null,
  contacts: null,
  chat: null,
  audience: null,
  calls: null,
  pendingLang: null,
};

/**
 * Record a user-made language change into the home log (settings op) so it
 * reaches the user's other devices. i18n's setLang() is the caller's job —
 * this only handles the replication side, and buffers when the room isn't
 * up yet.
 */
export function recordLangChange(lang: HomeLang): void {
  if (Session.selfroom) {
    Session.pendingLang = null;
    void Session.selfroom.setSettings({ lang }).catch(() => {});
  } else {
    Session.pendingLang = { lang, ts: Date.now() };
  }
}

static mirror of HEAD · about · clone: git clone https://cod-sursa.cautpartener.ro/cautpartener.git