@nivaro/react 0.3.94 → 0.3.96

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,39 +1,40 @@
1
- import { readItems as Z } from "@nivaro/sdk";
2
- import { useQueryClient as q, useMutation as y, useQuery as p, useInfiniteQuery as J } from "@tanstack/react-query";
3
- import { useContext as X, useState as O, useEffect as w, useMemo as k, useCallback as I, useRef as Q, createContext as ee } from "react";
4
- import { toast as te } from "sonner";
5
- import { useNivaroClient as f } from "../../context.js";
6
- import { get as g, patch as R, post as F, del as N } from "../../lib/commands.js";
7
- import { isDndActive as ne } from "../../lib/dnd.js";
8
- import { useLiveRefetchInterval as se } from "../../lib/live-queries.js";
9
- import { playNotificationSound as re } from "../../lib/notification-sound.js";
10
- import { announceLocalPrefs as oe } from "../../lib/user-sync.js";
11
- import { bindChatOutbox as ae, enqueueChatOutbox as ie } from "./chat-outbox.js";
12
- import { discardOutbox as Ft, editOutbox as Kt, holdOutbox as Ot, nudgeChatOutbox as It, retryOutbox as xt, useOutbox as kt } from "./chat-outbox.js";
13
- import { huddleHolds as ce, holdNotification as ue } from "./huddle/huddle-hold.js";
14
- const Pe = ["👍", "✅", "👀", "🎉", "❤️", "😂"], le = ee(null);
1
+ import { readItems as ee } from "@nivaro/sdk";
2
+ import { useQueryClient as b, useMutation as g, useQuery as v, useInfiniteQuery as te } from "@tanstack/react-query";
3
+ import { useContext as ne, useState as P, useEffect as T, useMemo as D, useCallback as U, useRef as A, createContext as se } from "react";
4
+ import { useNivaroClient as m } from "../../context.js";
5
+ import { get as p, patch as S, post as M, del as B } from "../../lib/commands.js";
6
+ import { isDndActive as re } from "../../lib/dnd.js";
7
+ import { useLiveRefetchInterval as oe } from "../../lib/live-queries.js";
8
+ import { playNotificationSound as ae } from "../../lib/notification-sound.js";
9
+ import { useTabAttention as ie } from "../../lib/tab-attention.js";
10
+ import { announceLocalPrefs as ce } from "../../lib/user-sync.js";
11
+ import { showChatMessageCard as ue, dismissChatCard as le } from "./ChatMessageToast.js";
12
+ import { bindChatOutbox as G, enqueueChatOutbox as V } from "./chat-outbox.js";
13
+ import { discardOutbox as Ot, editOutbox as kt, holdOutbox as xt, nudgeChatOutbox as Qt, retryOutbox as Lt, useOutbox as Pt } from "./chat-outbox.js";
14
+ import { huddleHolds as de, holdNotification as me } from "./huddle/huddle-hold.js";
15
+ const Ae = ["👍", "✅", "👀", "🎉", "❤️", "😂"], fe = se(null);
15
16
  function _() {
16
- const e = X(le);
17
+ const e = ne(fe);
17
18
  if (!e) throw new Error("Chat components must be wrapped in <ChatProvider>");
18
19
  return e;
19
20
  }
20
- const Qe = 0, Ne = {
21
+ const Ne = 0, De = {
21
22
  collections: { messages: "chat_messages", reads: "chat_last_read", presence: "user_presence" },
22
23
  globalRoom: "global",
23
24
  globalLabel: "General",
24
25
  entityPattern: String.raw`\b([A-Za-z]{2,4}\d{2}(?:INV)?-\d+)\b`
25
26
  };
26
- function Ue(e, t) {
27
+ function Ee(e, t) {
27
28
  return `dm:${[e.toUpperCase(), t.toUpperCase()].sort().join(":")}`;
28
29
  }
29
- function H(e, t) {
30
+ function W(e, t) {
30
31
  if (!e.startsWith("dm:")) return null;
31
32
  const n = e.slice(3);
32
33
  return [n.slice(0, 36), n.slice(37)].find((o) => o.toLowerCase() !== t.toLowerCase()) ?? null;
33
34
  }
34
- function K(e, t) {
35
- const n = _(), s = q(), o = (t ?? []).join("|");
36
- w(() => {
35
+ function k(e, t) {
36
+ const n = _(), s = b(), o = (t ?? []).join("|");
37
+ T(() => {
37
38
  const r = () => {
38
39
  for (const a of e) s.invalidateQueries({ queryKey: a });
39
40
  };
@@ -41,75 +42,75 @@ function K(e, t) {
41
42
  if (n.realtime) return n.realtime(n.collections.messages, r);
42
43
  }, [n.subscribeRooms, n.realtime, o, s]);
43
44
  }
44
- function de(e, t) {
45
- const n = _(), s = q();
46
- w(() => {
45
+ function he(e, t) {
46
+ const n = _(), s = b();
47
+ T(() => {
47
48
  if (n.realtime)
48
49
  return n.realtime(e, () => {
49
50
  for (const o of t) s.invalidateQueries({ queryKey: o });
50
51
  });
51
52
  }, [n.realtime, e, s]);
52
53
  }
53
- function Ae(e, t = null) {
54
- var U, A, D;
55
- const n = _(), s = f(), o = t ? "around" in t ? `around:${t.around}` : `date:${t.date}` : "latest", { data: r, isLoading: a } = p({
54
+ function je(e, t = null) {
55
+ var I, w, x;
56
+ const n = _(), s = m(), o = t ? "around" in t ? `around:${t.around}` : `date:${t.date}` : "latest", { data: r, isLoading: a } = v({
56
57
  queryKey: ["nvr-chat", e, o],
57
58
  queryFn: async () => {
58
- const C = { room: e, limit: 80 };
59
- return t && "around" in t && (C.around = t.around), t && "date" in t && (C.date = t.date), await s.request(
60
- g("/chat/messages", C)
59
+ const q = { room: e, limit: 80 };
60
+ return t && "around" in t && (q.around = t.around), t && "date" in t && (q.date = t.date), await s.request(
61
+ p("/chat/messages", q)
61
62
  );
62
63
  },
63
64
  enabled: !!e,
64
65
  staleTime: 5e3,
65
66
  refetchInterval: n.realtime || n.subscribeRooms ? void 0 : 1e4
66
67
  });
67
- K([["nvr-chat"], ["nvr-chat-rooms"], ["nvr-chat-thread"]], e ? [e] : []);
68
- const [i, c] = O([]), [m, l] = O(null), [d, u] = O(!1);
69
- w(() => {
70
- c([]), l(null);
68
+ k([["nvr-chat"], ["nvr-chat-rooms"], ["nvr-chat-thread"]], e ? [e] : []);
69
+ const [i, c] = P([]), [u, d] = P(null), [l, h] = P(!1);
70
+ T(() => {
71
+ c([]), d(null);
71
72
  }, [e, o]);
72
- const v = (r == null ? void 0 : r.data) ?? [], h = k(() => {
73
- if (i.length === 0) return v;
74
- const C = new Set(v.map((S) => S.id));
75
- return [...i.filter((S) => !C.has(S.id)), ...v];
76
- }, [i, v]), b = I(async () => {
77
- var S;
78
- if (!e || d) return;
79
- const C = h[0];
80
- if (C) {
81
- u(!0);
73
+ const y = (r == null ? void 0 : r.data) ?? [], f = D(() => {
74
+ if (i.length === 0) return y;
75
+ const q = new Set(y.map((C) => C.id));
76
+ return [...i.filter((C) => !q.has(C.id)), ...y];
77
+ }, [i, y]), R = U(async () => {
78
+ var C;
79
+ if (!e || l) return;
80
+ const q = f[0];
81
+ if (q) {
82
+ h(!0);
82
83
  try {
83
- const E = await s.request(
84
- g("/chat/messages", { room: e, limit: 60, before: C.id })
84
+ const O = await s.request(
85
+ p("/chat/messages", { room: e, limit: 60, before: q.id })
85
86
  );
86
- c((Y) => [...E.data ?? [], ...Y]), l(!!((S = E.meta) != null && S.has_older));
87
+ c((Q) => [...O.data ?? [], ...Q]), d(!!((C = O.meta) != null && C.has_older));
87
88
  } finally {
88
- u(!1);
89
+ h(!1);
89
90
  }
90
91
  }
91
- }, [e, h, s, d]);
92
+ }, [e, f, s, l]);
92
93
  return {
93
- messages: h,
94
+ messages: f,
94
95
  loading: a,
95
- hasOlder: m ?? !!((U = r == null ? void 0 : r.meta) != null && U.has_older),
96
- hasNewer: !!((A = r == null ? void 0 : r.meta) != null && A.has_newer),
97
- anchorId: ((D = r == null ? void 0 : r.meta) == null ? void 0 : D.anchor) ?? null,
98
- loadOlder: b,
99
- loadingOlder: d
96
+ hasOlder: u ?? !!((I = r == null ? void 0 : r.meta) != null && I.has_older),
97
+ hasNewer: !!((w = r == null ? void 0 : r.meta) != null && w.has_newer),
98
+ anchorId: ((x = r == null ? void 0 : r.meta) == null ? void 0 : x.anchor) ?? null,
99
+ loadOlder: R,
100
+ loadingOlder: l
100
101
  };
101
102
  }
102
- function De(e, t) {
103
- const n = _(), s = f(), { data: o, isLoading: r } = p({
103
+ function ze(e, t) {
104
+ const n = _(), s = m(), { data: o, isLoading: r } = v({
104
105
  queryKey: ["nvr-chat-thread", e, t],
105
106
  queryFn: async () => (await s.request(
106
- g("/chat/messages", { room: e, thread: t, limit: 300 })
107
+ p("/chat/messages", { room: e, thread: t, limit: 300 })
107
108
  )).data ?? [],
108
109
  enabled: !!e && !!t,
109
110
  staleTime: 5e3,
110
111
  refetchInterval: n.realtime || n.subscribeRooms ? void 0 : 1e4
111
112
  });
112
- K([["nvr-chat-thread"]], e ? [e] : []);
113
+ k([["nvr-chat-thread"]], e ? [e] : []);
113
114
  const a = o ?? [];
114
115
  return {
115
116
  root: a.find((i) => i.id === t) ?? null,
@@ -117,47 +118,47 @@ function De(e, t) {
117
118
  loading: r
118
119
  };
119
120
  }
120
- function Ee(e) {
121
+ function Be(e) {
121
122
  var r, a, i;
122
- const t = f(), n = q(), s = _();
123
- return ae(t, n, ((r = s.me) == null ? void 0 : r.id) ?? null), { mutate: I(
123
+ const t = m(), n = b(), s = _();
124
+ return G(t, n, ((r = s.me) == null ? void 0 : r.id) ?? null), { mutate: U(
124
125
  (c) => {
125
- var l, d;
126
- const m = typeof c == "string" ? { text: c } : c;
127
- ie({
128
- client_id: me(),
126
+ var d, l;
127
+ const u = typeof c == "string" ? { text: c } : c;
128
+ V({
129
+ client_id: Y(),
129
130
  room: e,
130
- text: m.text,
131
- mentions: m.mentions ?? [],
132
- attachments: m.attachments ?? [],
133
- parent_id: m.parentId ?? null,
134
- quote_id: m.quoteId ?? null,
135
- urgent: !!m.urgent,
131
+ text: u.text,
132
+ mentions: u.mentions ?? [],
133
+ attachments: u.attachments ?? [],
134
+ parent_id: u.parentId ?? null,
135
+ quote_id: u.quoteId ?? null,
136
+ urgent: !!u.urgent,
136
137
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
137
- sender: ((l = s.me) == null ? void 0 : l.id) ?? "",
138
- sender_name: ((d = s.me) == null ? void 0 : d.name) ?? null
138
+ sender: ((d = s.me) == null ? void 0 : d.id) ?? "",
139
+ sender_name: ((l = s.me) == null ? void 0 : l.name) ?? null
139
140
  });
140
141
  },
141
142
  [e, (a = s.me) == null ? void 0 : a.id, (i = s.me) == null ? void 0 : i.name]
142
143
  ), isPending: !1 };
143
144
  }
144
- function me() {
145
+ function Y() {
145
146
  var t;
146
147
  const e = globalThis.crypto;
147
148
  return ((t = e == null ? void 0 : e.randomUUID) == null ? void 0 : t.call(e)) ?? `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
148
149
  }
149
- function G(e, t, n) {
150
+ function Z(e, t, n) {
150
151
  const s = (t == null ? void 0 : t.toLowerCase()) ?? "";
151
152
  return e.map((r) => {
152
- var c, m, l, d, u;
153
+ var c, u, d, l, h;
153
154
  const a = r.kind === "unknown" ? "entity" : r.kind, i = a === "global" ? (
154
155
  // The server names General only when an admin renamed it.
155
156
  r.label ?? n.globalLabel
156
157
  ) : a === "dm" ? (
157
158
  // The server resolves the peer's name from the user table; the
158
159
  // message sender is only a fallback for hosts that don't send one.
159
- r.label ?? (((m = (c = r.last_message) == null ? void 0 : c.sender) == null ? void 0 : m.toLowerCase()) !== s ? ((l = r.last_message) == null ? void 0 : l.sender_name) ?? null : null) ?? `User ${((d = H(r.room, s)) == null ? void 0 : d.slice(0, 8)) ?? ""}`
160
- ) : r.label ?? ((u = n.roomLabel) == null ? void 0 : u.call(n, r.room)) ?? r.room.toUpperCase();
160
+ r.label ?? (((u = (c = r.last_message) == null ? void 0 : c.sender) == null ? void 0 : u.toLowerCase()) !== s ? ((d = r.last_message) == null ? void 0 : d.sender_name) ?? null : null) ?? `User ${((l = W(r.room, s)) == null ? void 0 : l.slice(0, 8)) ?? ""}`
161
+ ) : r.label ?? ((h = n.roomLabel) == null ? void 0 : h.call(n, r.room)) ?? r.room.toUpperCase();
161
162
  return {
162
163
  room: r.room,
163
164
  label: i,
@@ -180,101 +181,101 @@ function G(e, t, n) {
180
181
  return (a.lastMessage ? new Date(a.lastMessage.date_created).getTime() : 0) - i;
181
182
  });
182
183
  }
183
- function je() {
184
- const e = _(), t = f(), n = e.me, s = p({
184
+ function He() {
185
+ const e = _(), t = m(), n = e.me, s = v({
185
186
  queryKey: ["nvr-chat-rooms", n == null ? void 0 : n.id],
186
- queryFn: async () => (await t.request(g("/chat/rooms"))).data ?? [],
187
+ queryFn: async () => (await t.request(p("/chat/rooms"))).data ?? [],
187
188
  enabled: !!n,
188
189
  refetchInterval: 45e3,
189
190
  staleTime: 1e4
190
191
  });
191
- K([["nvr-chat-rooms"]]);
192
- const o = k(
193
- () => G(s.data ?? [], n == null ? void 0 : n.id, e),
192
+ k([["nvr-chat-rooms"]]);
193
+ const o = D(
194
+ () => Z(s.data ?? [], n == null ? void 0 : n.id, e),
194
195
  [s.data, n == null ? void 0 : n.id, e]
195
- ), r = L().chat_badge_mode, a = o.reduce((i, c) => {
196
- var m;
196
+ ), r = E().chat_badge_mode, a = o.reduce((i, c) => {
197
+ var u;
197
198
  if (c.muted) return i;
198
199
  if (r === "conversations") {
199
- const l = c.kind === "dm" || c.kind === "channel" && !!((m = c.channel) != null && m.is_direct);
200
- return i + (l ? c.unread : c.mentions ?? 0);
200
+ const d = c.kind === "dm" || c.kind === "channel" && !!((u = c.channel) != null && u.is_direct);
201
+ return i + (d ? c.unread : c.mentions ?? 0);
201
202
  }
202
203
  return i + c.unread;
203
204
  }, 0);
204
205
  return { rooms: o, totalUnread: a, loading: s.isLoading };
205
206
  }
206
- function ze(e) {
207
- const t = _(), n = f(), s = t.me, o = p({
207
+ function Ge(e) {
208
+ const t = _(), n = m(), s = t.me, o = v({
208
209
  queryKey: ["nvr-chat-rooms", s == null ? void 0 : s.id, "archived"],
209
210
  queryFn: async () => (await n.request(
210
- g("/chat/rooms", { archived: "1" })
211
+ p("/chat/rooms", { archived: "1" })
211
212
  )).data ?? [],
212
213
  enabled: !!s && e,
213
214
  staleTime: 1e4
214
215
  });
215
- return { rooms: k(() => G(o.data ?? [], s == null ? void 0 : s.id, t), [o.data, s == null ? void 0 : s.id, t]), loading: o.isLoading };
216
+ return { rooms: D(() => Z(o.data ?? [], s == null ? void 0 : s.id, t), [o.data, s == null ? void 0 : s.id, t]), loading: o.isLoading };
216
217
  }
217
- function Be(e) {
218
- const t = f(), { data: n, isLoading: s } = p({
218
+ function Ve(e) {
219
+ const t = m(), { data: n, isLoading: s } = v({
219
220
  queryKey: ["nvr-chat-directory", e],
220
221
  queryFn: async () => (await t.request(
221
- g("/chat/directory", e ? { search: e } : void 0)
222
+ p("/chat/directory", e ? { search: e } : void 0)
222
223
  )).data ?? [],
223
224
  staleTime: 15e3
224
225
  });
225
226
  return { channels: n ?? [], loading: s };
226
227
  }
227
- function He() {
228
- const e = f(), t = q(), n = () => {
228
+ function We() {
229
+ const e = m(), t = b(), n = () => {
229
230
  t.invalidateQueries({ queryKey: ["nvr-chat-rooms"] }), t.invalidateQueries({ queryKey: ["nvr-chat-directory"] });
230
- }, s = y({
231
- mutationFn: (l) => e.request(F(`/chat/rooms/${encodeURIComponent(l)}/join`)),
231
+ }, s = g({
232
+ mutationFn: (d) => e.request(M(`/chat/rooms/${encodeURIComponent(d)}/join`)),
232
233
  onSuccess: n
233
- }), o = y({
234
- mutationFn: (l) => e.request(N(`/chat/rooms/${encodeURIComponent(l)}/join`)),
234
+ }), o = g({
235
+ mutationFn: (d) => e.request(B(`/chat/rooms/${encodeURIComponent(d)}/join`)),
235
236
  onSuccess: n
236
- }), r = y({
237
- mutationFn: ({ room: l, muted: d }) => e.request(R(`/chat/rooms/${encodeURIComponent(l)}`, { muted: d })),
237
+ }), r = g({
238
+ mutationFn: ({ room: d, muted: l }) => e.request(S(`/chat/rooms/${encodeURIComponent(d)}`, { muted: l })),
238
239
  onSuccess: n
239
- }), a = y({
240
- mutationFn: ({ room: l, mode: d }) => e.request(
241
- R(`/chat/rooms/${encodeURIComponent(l)}`, {
242
- notify_mode: d === "mentions" ? "mentions" : null
240
+ }), a = g({
241
+ mutationFn: ({ room: d, mode: l }) => e.request(
242
+ S(`/chat/rooms/${encodeURIComponent(d)}`, {
243
+ notify_mode: l === "mentions" ? "mentions" : null
243
244
  })
244
245
  ),
245
246
  onSuccess: n
246
- }), i = y({
247
- mutationFn: ({ room: l, archived: d }) => e.request(R(`/chat/rooms/${encodeURIComponent(l)}`, { archived: d })),
247
+ }), i = g({
248
+ mutationFn: ({ room: d, archived: l }) => e.request(S(`/chat/rooms/${encodeURIComponent(d)}`, { archived: l })),
248
249
  onSuccess: n
249
- }), c = y({
250
- mutationFn: ({ room: l, starred: d }) => e.request(R(`/chat/rooms/${encodeURIComponent(l)}`, { starred: d })),
250
+ }), c = g({
251
+ mutationFn: ({ room: d, starred: l }) => e.request(S(`/chat/rooms/${encodeURIComponent(d)}`, { starred: l })),
251
252
  onSuccess: n
252
- }), m = y({
253
- mutationFn: (l) => e.request(R(`/chat/rooms/${encodeURIComponent(l)}`, { welcome_seen: !0 })),
253
+ }), u = g({
254
+ mutationFn: (d) => e.request(S(`/chat/rooms/${encodeURIComponent(d)}`, { welcome_seen: !0 })),
254
255
  onSuccess: n
255
256
  });
256
- return { join: s, leave: o, setMuted: r, setNotifyMode: a, setArchived: i, setStarred: c, dismissWelcome: m };
257
+ return { join: s, leave: o, setMuted: r, setNotifyMode: a, setArchived: i, setStarred: c, dismissWelcome: u };
257
258
  }
258
- function Ge(e) {
259
- const t = f(), { data: n, isLoading: s } = p({
259
+ function Ye(e) {
260
+ const t = m(), { data: n, isLoading: s } = v({
260
261
  queryKey: ["nvr-chat-members", e],
261
262
  queryFn: async () => (await t.request(
262
- g(`/chat/channels/${e}/members`)
263
+ p(`/chat/channels/${e}/members`)
263
264
  )).data ?? [],
264
265
  enabled: e != null,
265
266
  staleTime: 1e4
266
267
  });
267
268
  return { members: n ?? [], loading: s };
268
269
  }
269
- const fe = 50;
270
- function Ve(e, t) {
271
- const [n, s] = O(e);
272
- return w(() => {
270
+ const ye = 50;
271
+ function Ze(e, t) {
272
+ const [n, s] = P(e);
273
+ return T(() => {
273
274
  const o = setTimeout(() => s(e), t);
274
275
  return () => clearTimeout(o);
275
276
  }, [e, t]), n;
276
277
  }
277
- function he(e) {
278
+ function ge(e) {
278
279
  const t = String(e.id ?? e.user ?? ""), n = e.first_name ?? null, s = e.last_name ?? null, o = e.email ?? null;
279
280
  return {
280
281
  id: t,
@@ -286,24 +287,24 @@ function he(e) {
286
287
  email: o
287
288
  };
288
289
  }
289
- function We(e, t, n, s) {
290
- var c, m, l;
291
- const o = f(), r = J({
290
+ function Je(e, t, n, s) {
291
+ var c, u, d;
292
+ const o = m(), r = te({
292
293
  queryKey: ["nvr-chat-members-page", e, t, n],
293
294
  initialPageParam: 0,
294
- queryFn: async ({ pageParam: d }) => {
295
- const u = new URLSearchParams({ limit: String(fe), offset: String(d) });
296
- return n.trim() && u.set("q", n.trim()), await o.request(
297
- g(`${t}?${u.toString()}`)
295
+ queryFn: async ({ pageParam: l }) => {
296
+ const h = new URLSearchParams({ limit: String(ye), offset: String(l) });
297
+ return n.trim() && h.set("q", n.trim()), await o.request(
298
+ p(`${t}?${h.toString()}`)
298
299
  );
299
300
  },
300
- getNextPageParam: (d, u) => d.has_more ? u.reduce((v, h) => {
301
- var b;
302
- return v + (((b = h.data) == null ? void 0 : b.length) ?? 0);
301
+ getNextPageParam: (l, h) => l.has_more ? h.reduce((y, f) => {
302
+ var R;
303
+ return y + (((R = f.data) == null ? void 0 : R.length) ?? 0);
303
304
  }, 0) : void 0,
304
305
  enabled: s && !!t,
305
306
  staleTime: 1e4
306
- }), a = (((c = r.data) == null ? void 0 : c.pages) ?? []).flatMap((d) => (d.data ?? []).map(he)), i = ((l = (m = r.data) == null ? void 0 : m.pages[0]) == null ? void 0 : l.total) ?? a.length;
307
+ }), a = (((c = r.data) == null ? void 0 : c.pages) ?? []).flatMap((l) => (l.data ?? []).map(ge)), i = ((d = (u = r.data) == null ? void 0 : u.pages[0]) == null ? void 0 : d.total) ?? a.length;
307
308
  return {
308
309
  members: a,
309
310
  total: i,
@@ -315,81 +316,81 @@ function We(e, t, n, s) {
315
316
  }
316
317
  };
317
318
  }
318
- function Ye(e) {
319
- const t = f(), n = q(), s = () => {
319
+ function Xe(e) {
320
+ const t = m(), n = b(), s = () => {
320
321
  n.invalidateQueries({ queryKey: ["nvr-chat-members", e] }), n.invalidateQueries({ queryKey: ["nvr-chat-members-page"] }), n.invalidateQueries({ queryKey: ["nvr-chat-rooms"] }), n.invalidateQueries({ queryKey: ["nvr-chat-directory"] });
321
- }, o = y({
322
- mutationFn: (i) => t.request(R(`/chat/channels/${e}`, i)),
322
+ }, o = g({
323
+ mutationFn: (i) => t.request(S(`/chat/channels/${e}`, i)),
323
324
  onSuccess: s
324
- }), r = y({
325
- mutationFn: (i) => t.request(F(`/chat/channels/${e}/members`, { user_id: i })),
325
+ }), r = g({
326
+ mutationFn: (i) => t.request(M(`/chat/channels/${e}/members`, { user_id: i })),
326
327
  onSuccess: s
327
- }), a = y({
328
- mutationFn: (i) => t.request(N(`/chat/channels/${e}/members/${i}`)),
328
+ }), a = g({
329
+ mutationFn: (i) => t.request(B(`/chat/channels/${e}/members/${i}`)),
329
330
  onSuccess: s
330
331
  });
331
332
  return { update: o, addMember: r, removeMember: a };
332
333
  }
333
- function Ze() {
334
- const e = f(), { data: t } = p({
334
+ function et() {
335
+ const e = m(), { data: t } = v({
335
336
  queryKey: ["nvr-chat-roles"],
336
337
  queryFn: async () => (await e.request(
337
- g("/chat/roles")
338
+ p("/chat/roles")
338
339
  )).data ?? [],
339
340
  staleTime: 5 * 6e4
340
341
  });
341
342
  return t ?? [];
342
343
  }
343
- function Je(e, t) {
344
- const n = f(), { data: s, isLoading: o } = p({
344
+ function tt(e, t) {
345
+ const n = m(), { data: s, isLoading: o } = v({
345
346
  queryKey: ["nvr-chat-user-search", e],
346
347
  queryFn: async () => (await n.request(
347
- g("/users", { limit: 20, ...e.trim() ? { search: e.trim() } : {} })
348
+ p("/users", { limit: 20, ...e.trim() ? { search: e.trim() } : {} })
348
349
  )).data ?? [],
349
350
  enabled: t,
350
351
  staleTime: 3e4
351
352
  });
352
353
  return { users: s ?? [], loading: o };
353
354
  }
354
- function Xe() {
355
- const e = f(), t = q();
356
- return y({
357
- mutationFn: (n) => e.request(F("/chat/channels", n)),
355
+ function nt() {
356
+ const e = m(), t = b();
357
+ return g({
358
+ mutationFn: (n) => e.request(M("/chat/channels", n)),
358
359
  onSuccess: () => {
359
360
  t.invalidateQueries({ queryKey: ["nvr-chat-rooms"] }), t.invalidateQueries({ queryKey: ["nvr-chat-directory"] });
360
361
  }
361
362
  });
362
363
  }
363
- let j = 0;
364
- const P = /* @__PURE__ */ new Map();
364
+ let H = 0;
365
+ const j = /* @__PURE__ */ new Map();
365
366
  function z(e) {
366
367
  var t;
367
368
  return e.kind === "dm" || e.kind === "channel" && !!((t = e.channel) != null && t.is_direct);
368
369
  }
369
- const T = /* @__PURE__ */ new Map();
370
- function et(e) {
371
- w(() => {
370
+ const $ = /* @__PURE__ */ new Map();
371
+ function st(e) {
372
+ T(() => {
372
373
  if (e)
373
- return T.set(e, (T.get(e) ?? 0) + 1), () => {
374
- const t = (T.get(e) ?? 1) - 1;
375
- t <= 0 ? T.delete(e) : T.set(e, t);
374
+ return $.set(e, ($.get(e) ?? 0) + 1), () => {
375
+ const t = ($.get(e) ?? 1) - 1;
376
+ t <= 0 ? $.delete(e) : $.set(e, t);
376
377
  };
377
378
  }, [e]);
378
379
  }
379
- function ye() {
380
+ function pe() {
380
381
  return typeof document > "u" || document.visibilityState === "visible";
381
382
  }
382
- function B(e) {
383
- return T.has(e) && ye();
383
+ function L(e) {
384
+ return $.has(e) && pe();
384
385
  }
385
- function ge() {
386
- const e = L().notification_sound;
386
+ function ve() {
387
+ const e = E().notification_sound;
387
388
  return typeof e == "string" ? e : "off";
388
389
  }
389
- function L() {
390
- const e = f(), { data: t } = p({
390
+ function E() {
391
+ const e = m(), { data: t } = v({
391
392
  queryKey: ["nvr-profile-prefs"],
392
- queryFn: () => e.request(g("/users/me")).then((n) => {
393
+ queryFn: () => e.request(p("/users/me")).then((n) => {
393
394
  var s;
394
395
  return ((s = n.data) == null ? void 0 : s.preferences) ?? {};
395
396
  }),
@@ -397,10 +398,10 @@ function L() {
397
398
  });
398
399
  return t ?? {};
399
400
  }
400
- function pe() {
401
- const e = f(), t = q();
402
- return y({
403
- mutationFn: (n) => e.request(R("/users/me/preferences", n)),
401
+ function qe() {
402
+ const e = m(), t = b();
403
+ return g({
404
+ mutationFn: (n) => e.request(S("/users/me/preferences", n)),
404
405
  onMutate: (n) => {
405
406
  const s = t.getQueryData(["nvr-profile-prefs"]);
406
407
  return t.setQueryData(["nvr-profile-prefs"], { ...s ?? {}, ...n }), { prev: s };
@@ -408,15 +409,15 @@ function pe() {
408
409
  onError: (n, s, o) => {
409
410
  o != null && o.prev && t.setQueryData(["nvr-profile-prefs"], o.prev);
410
411
  },
411
- onSuccess: (n, s) => oe(Object.keys(s)),
412
+ onSuccess: (n, s) => ce(Object.keys(s)),
412
413
  onSettled: () => {
413
414
  t.invalidateQueries({ queryKey: ["nvr-profile-prefs"] }), t.invalidateQueries({ queryKey: ["presence-online"] });
414
415
  }
415
416
  });
416
417
  }
417
- function tt() {
418
- const e = L(), t = pe(), n = Object.keys(e).length > 0;
419
- w(() => {
418
+ function rt() {
419
+ const e = E(), t = qe(), n = Object.keys(e).length > 0;
420
+ T(() => {
420
421
  if (!n) return;
421
422
  let s = "";
422
423
  try {
@@ -434,82 +435,115 @@ function tt() {
434
435
  }
435
436
  }, [n, e.browser_timezone]);
436
437
  }
437
- function nt(e, t) {
438
- const n = _(), s = ge(), o = L(), r = Q(o);
439
- r.current = o, w(() => {
440
- const a = t ? t.filter((l) => z(l) && !B(l.room)).reduce((l, d) => l + d.unread, 0) : e, i = a > j, c = ce(r.current), m = ne(r.current) || c;
441
- if (n.sound && i && !m && re(s), n.sound && i && c && ue({ kind: "chat", title: "New message" }), t) {
442
- const l = P.size > 0, d = T.size > 0;
443
- for (const u of t) {
444
- const v = P.get(u.room) ?? 0;
445
- if (l && !m && !u.muted && z(u) && u.unread > v && !B(u.room)) {
446
- const h = u.lastMessage, b = h != null && h.sender_name ? String(h.sender_name).trim() : null;
447
- te(
448
- u.kind === "dm" ? `New message from ${b || u.label}` : `New message in ${u.label}${b ? ` — ${b}` : ""}`,
449
- {
450
- description: h != null && h.message ? String(h.message).replace(/<[^>]*>/g, "").slice(0, 90) : void 0,
451
- duration: 4e3,
452
- ...d ? { position: "top-center" } : {},
453
- // Reading the message is the whole reason the toast exists, so
454
- // it opens the conversation — only when a host has somewhere to
455
- // open it, otherwise the click would do nothing.
456
- ...Re() ? {
457
- className: "cursor-pointer",
458
- onDismiss: void 0,
459
- action: {
460
- label: "Open",
461
- onClick: () => W(u.room, u.label)
462
- }
463
- } : {}
464
- }
465
- );
438
+ function ot(e, t) {
439
+ const n = _(), s = ve(), o = E(), r = A(o);
440
+ r.current = o;
441
+ const a = m(), i = b(), c = A({
442
+ client: a,
443
+ qc: i,
444
+ me: n.me,
445
+ markRead: (u) => {
446
+ }
447
+ });
448
+ c.current = {
449
+ client: a,
450
+ qc: i,
451
+ me: n.me,
452
+ markRead: (u) => {
453
+ a.request(M(`/chat/rooms/${encodeURIComponent(u)}/read`)).then(() => i.invalidateQueries({ queryKey: ["nvr-chat-rooms"] })).catch(() => {
454
+ });
455
+ }
456
+ }, ie(
457
+ t ? t.filter((u) => z(u) && !u.muted && !L(u.room)).reduce((u, d) => u + d.unread, 0) : 0
458
+ ), T(() => {
459
+ const u = t ? t.filter((y) => z(y) && !L(y.room)).reduce((y, f) => y + f.unread, 0) : e, d = u > H, l = de(r.current), h = re(r.current) || l;
460
+ if (n.sound && d && !h && ae(s), n.sound && d && l && me({ kind: "chat", title: "New message" }), t) {
461
+ const y = j.size > 0;
462
+ for (const f of t) {
463
+ const R = j.get(f.room) ?? 0;
464
+ if (y && !h && !f.muted && z(f) && f.unread > R && !L(f.room)) {
465
+ const I = f.lastMessage;
466
+ if (I) {
467
+ const w = f.room;
468
+ ue(
469
+ {
470
+ room: w,
471
+ label: f.label,
472
+ kind: f.kind,
473
+ mentioned: (f.mentions ?? 0) > 0
474
+ },
475
+ I,
476
+ {
477
+ reply: (x) => {
478
+ var C, O, Q;
479
+ const q = c.current;
480
+ G(q.client, q.qc, ((C = q.me) == null ? void 0 : C.id) ?? null), V({
481
+ client_id: Y(),
482
+ room: w,
483
+ text: x,
484
+ mentions: [],
485
+ attachments: [],
486
+ parent_id: null,
487
+ quote_id: null,
488
+ urgent: !1,
489
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
490
+ sender: ((O = q.me) == null ? void 0 : O.id) ?? "",
491
+ sender_name: ((Q = q.me) == null ? void 0 : Q.name) ?? null
492
+ }), q.markRead(w);
493
+ },
494
+ markRead: () => c.current.markRead(w),
495
+ // Only when the host has somewhere to open it.
496
+ ...Se() ? { open: () => X(w, f.label) } : {}
497
+ }
498
+ );
499
+ }
466
500
  }
467
- P.set(u.room, u.unread);
501
+ (f.unread === 0 || L(f.room)) && le(f.room), j.set(f.room, f.unread);
468
502
  }
469
503
  }
470
- j = a;
504
+ H = u;
471
505
  }, [e, n.sound, t, s]);
472
506
  }
473
- function st() {
474
- const e = f(), t = q();
475
- return y({
476
- mutationFn: (n) => e.request(F(`/chat/rooms/${encodeURIComponent(n)}/read`)),
507
+ function at() {
508
+ const e = m(), t = b();
509
+ return g({
510
+ mutationFn: (n) => e.request(M(`/chat/rooms/${encodeURIComponent(n)}/read`)),
477
511
  onSuccess: () => void t.invalidateQueries({ queryKey: ["nvr-chat-rooms"] })
478
512
  });
479
513
  }
480
- const ve = ["nvr-chat-room-types"];
481
- function V(e) {
514
+ const be = ["nvr-chat-room-types"];
515
+ function J(e) {
482
516
  return {
483
- queryKey: ve,
517
+ queryKey: be,
484
518
  queryFn: async () => {
485
- const t = await e.request(g("/chat/room-types"));
519
+ const t = await e.request(p("/chat/room-types"));
486
520
  return ((t == null ? void 0 : t.data) ?? []).filter((n) => n.is_active);
487
521
  },
488
522
  staleTime: 5 * 6e4
489
523
  };
490
524
  }
491
- function rt(e) {
492
- const t = _(), n = f(), s = (e == null ? void 0 : e.indexOf(":")) ?? -1, o = e && s > 0 ? e.slice(0, s) : null, r = e && s > 0 ? e.slice(s + 1) : null, a = !!e && !!o && !!r && e !== t.globalRoom && o !== "dm" && o !== "ch", { data: i } = p({ ...V(n), enabled: a }), c = a ? i == null ? void 0 : i.find((d) => d.is_active && d.prefix === o) : void 0, { data: m } = p({
525
+ function it(e) {
526
+ const t = _(), n = m(), s = (e == null ? void 0 : e.indexOf(":")) ?? -1, o = e && s > 0 ? e.slice(0, s) : null, r = e && s > 0 ? e.slice(s + 1) : null, a = !!e && !!o && !!r && e !== t.globalRoom && o !== "dm" && o !== "ch", { data: i } = v({ ...J(n), enabled: a }), c = a ? i == null ? void 0 : i.find((l) => l.is_active && l.prefix === o) : void 0, { data: u } = v({
493
527
  queryKey: ["nvr-chat-entity-record", c == null ? void 0 : c.collection, c == null ? void 0 : c.match_field, r],
494
528
  queryFn: async () => {
495
- var u, v;
496
- return c.match_field === "id" ? r : ((v = (u = (await n.request(
497
- g(`/items/${c.collection}`, {
529
+ var h, y;
530
+ return c.match_field === "id" ? r : ((y = (h = (await n.request(
531
+ p(`/items/${c.collection}`, {
498
532
  limit: 1,
499
533
  fields: "id",
500
534
  filter: JSON.stringify({ [c.match_field]: { _eq: r } })
501
535
  })
502
- )).data) == null ? void 0 : u[0]) == null ? void 0 : v.id) ?? null;
536
+ )).data) == null ? void 0 : h[0]) == null ? void 0 : y.id) ?? null;
503
537
  },
504
538
  enabled: !!c && !!r,
505
539
  staleTime: 5 * 6e4
506
540
  });
507
- return !c || m == null ? null : (t.recordUrl ?? ((d, u) => `/collections/${d}/${u}`))(c.collection, m);
541
+ return !c || u == null ? null : (t.recordUrl ?? ((l, h) => `/collections/${l}/${h}`))(c.collection, u);
508
542
  }
509
- const qe = /@\[([^\]]+)\](?:\([^)]*\))?/g;
510
- function ot(e, t) {
543
+ const _e = /@\[([^\]]+)\](?:\([^)]*\))?/g;
544
+ function ct(e, t) {
511
545
  const n = new RegExp(t, "gi"), s = [];
512
- for (const a of e.matchAll(qe))
546
+ for (const a of e.matchAll(_e))
513
547
  s.push({
514
548
  start: a.index,
515
549
  end: a.index + a[0].length,
@@ -528,32 +562,32 @@ function ot(e, t) {
528
562
  a.start > r && o.push({ text: e.slice(r, a.start) }), o.push(a.token), r = a.end;
529
563
  return r < e.length && o.push({ text: e.slice(r) }), o;
530
564
  }
531
- function at(e, t) {
565
+ function ut(e, t) {
532
566
  const s = e.slice(0, t).match(/@([^@\n\r]*)$/);
533
567
  return s ? s[1] : null;
534
568
  }
535
- const be = 3e3;
536
- function it(e) {
537
- const t = _(), n = f();
538
- q();
539
- const s = Q(!1), o = Q(null), r = t.me, a = I(() => {
569
+ const Ce = 3e3;
570
+ function lt(e) {
571
+ const t = _(), n = m();
572
+ b();
573
+ const s = A(!1), o = A(null), r = t.me, a = U(() => {
540
574
  o.current && clearTimeout(o.current), o.current = null, s.current && r && t.setTypingRoom && (s.current = !1, t.setTypingRoom(r.id, null));
541
- }, [r, t]), i = I(() => {
542
- !r || !e || !t.setTypingRoom || (s.current || (s.current = !0, t.setTypingRoom(r.id, e)), o.current && clearTimeout(o.current), o.current = setTimeout(a, be));
575
+ }, [r, t]), i = U(() => {
576
+ !r || !e || !t.setTypingRoom || (s.current || (s.current = !0, t.setTypingRoom(r.id, e)), o.current && clearTimeout(o.current), o.current = setTimeout(a, Ce));
543
577
  }, [r, e, t, a]);
544
- w(() => a, [a]);
545
- const c = se(6e3, {
578
+ T(() => a, [a]);
579
+ const c = oe(6e3, {
546
580
  safetyMs: 3e4,
547
581
  enabled: !!t.realtime
548
- }), { data: m } = p({
582
+ }), { data: u } = v({
549
583
  queryKey: ["nvr-chat-typing", e],
550
584
  queryFn: async () => {
551
- const d = new Date(Date.now() - 6e4).toISOString();
585
+ const l = new Date(Date.now() - 6e4).toISOString();
552
586
  return (await n.request(
553
- Z(t.collections.presence, {
587
+ ee(t.collections.presence, {
554
588
  limit: 10,
555
589
  fields: ["user_id", "display_name", "typing_room", "last_seen"],
556
- filter: { typing_room: { _eq: e }, last_seen: { _gte: d } }
590
+ filter: { typing_room: { _eq: e }, last_seen: { _gte: l } }
557
591
  })
558
592
  )).data ?? [];
559
593
  },
@@ -561,24 +595,24 @@ function it(e) {
561
595
  refetchInterval: c,
562
596
  staleTime: 2e3
563
597
  });
564
- de(t.collections.presence, [["nvr-chat-typing"]]);
565
- const l = k(() => {
566
- var v;
567
- const d = (v = r == null ? void 0 : r.id) == null ? void 0 : v.toLowerCase(), u = (m ?? []).filter((h) => {
568
- var b;
569
- return ((b = h.user_id) == null ? void 0 : b.toLowerCase()) !== d;
570
- }).map((h) => h.display_name ?? "Someone");
571
- return u.length === 0 ? null : u.length === 1 ? `${u[0]} is typing…` : u.length === 2 ? `${u[0]} and ${u[1]} are typing…` : `${u.length} people are typing…`;
572
- }, [m, r == null ? void 0 : r.id]);
573
- return { onType: i, clearTyping: a, typingText: l };
574
- }
575
- function ct(e) {
576
- const t = _(), n = f(), s = t.me, o = e && s ? H(e, s.id) : null, { data: r } = p({
598
+ he(t.collections.presence, [["nvr-chat-typing"]]);
599
+ const d = D(() => {
600
+ var y;
601
+ const l = (y = r == null ? void 0 : r.id) == null ? void 0 : y.toLowerCase(), h = (u ?? []).filter((f) => {
602
+ var R;
603
+ return ((R = f.user_id) == null ? void 0 : R.toLowerCase()) !== l;
604
+ }).map((f) => f.display_name ?? "Someone");
605
+ return h.length === 0 ? null : h.length === 1 ? `${h[0]} is typing…` : h.length === 2 ? `${h[0]} and ${h[1]} are typing…` : `${h.length} people are typing…`;
606
+ }, [u, r == null ? void 0 : r.id]);
607
+ return { onType: i, clearTyping: a, typingText: d };
608
+ }
609
+ function dt(e) {
610
+ const t = _(), n = m(), s = t.me, o = e && s ? W(e, s.id) : null, { data: r } = v({
577
611
  queryKey: ["nvr-chat-peer-read", e],
578
612
  queryFn: async () => {
579
613
  var i;
580
614
  return ((i = (await n.request(
581
- g(
615
+ p(
582
616
  `/chat/rooms/${encodeURIComponent(e)}/peer-read`
583
617
  )
584
618
  )).data) == null ? void 0 : i.last_read_at) ?? null;
@@ -587,40 +621,40 @@ function ct(e) {
587
621
  refetchInterval: 3e4,
588
622
  staleTime: 5e3
589
623
  });
590
- return K([["nvr-chat-peer-read"]], e ? [e] : []), r ?? null;
624
+ return k([["nvr-chat-peer-read"]], e ? [e] : []), r ?? null;
591
625
  }
592
- function ut(e) {
593
- const t = f(), n = q();
594
- return y({
595
- mutationFn: ({ messageId: s, emoji: o }) => t.request(F(`/chat/messages/${s}/reactions`, { emoji: o })),
626
+ function mt(e) {
627
+ const t = m(), n = b();
628
+ return g({
629
+ mutationFn: ({ messageId: s, emoji: o }) => t.request(M(`/chat/messages/${s}/reactions`, { emoji: o })),
596
630
  onSuccess: () => void n.invalidateQueries({ queryKey: ["nvr-chat", e] })
597
631
  });
598
632
  }
599
- function lt(e) {
600
- const t = f(), n = q();
601
- return y({
602
- mutationFn: ({ messageId: s, text: o }) => t.request(R(`/chat/messages/${s}`, { message: o })),
633
+ function ft(e) {
634
+ const t = m(), n = b();
635
+ return g({
636
+ mutationFn: ({ messageId: s, text: o }) => t.request(S(`/chat/messages/${s}`, { message: o })),
603
637
  onSuccess: () => void n.invalidateQueries({ queryKey: ["nvr-chat", e] })
604
638
  });
605
639
  }
606
- function dt(e) {
607
- const t = f(), n = q();
608
- return y({
609
- mutationFn: (s) => t.request(N(`/chat/messages/${s}`)),
640
+ function ht(e) {
641
+ const t = m(), n = b();
642
+ return g({
643
+ mutationFn: (s) => t.request(B(`/chat/messages/${s}`)),
610
644
  onSuccess: () => {
611
645
  n.invalidateQueries({ queryKey: ["nvr-chat", e] }), n.invalidateQueries({ queryKey: ["nvr-chat-rooms"] });
612
646
  }
613
647
  });
614
648
  }
615
- function mt(e, t = {}) {
616
- const n = f(), s = { q: e };
649
+ function yt(e, t = {}) {
650
+ const n = m(), s = { q: e };
617
651
  t.sender && (s.sender = t.sender), t.room && (s.room = t.room), t.from && (s.from = t.from), t.to && (s.to = t.to), t.has_attachment && (s.has_attachment = "1"), t.mentions_me && (s.mentions_me = "1");
618
- const o = Object.keys(s).length > 1, { data: r, isLoading: a } = p({
652
+ const o = Object.keys(s).length > 1, { data: r, isLoading: a } = v({
619
653
  queryKey: ["nvr-chat-search", s],
620
654
  queryFn: async () => {
621
655
  var c;
622
656
  const i = await n.request(
623
- g("/chat/search", s)
657
+ p("/chat/search", s)
624
658
  );
625
659
  return { hits: i.data ?? [], meaning: ((c = i.meta) == null ? void 0 : c.meaning) ?? null };
626
660
  },
@@ -629,43 +663,43 @@ function mt(e, t = {}) {
629
663
  });
630
664
  return { hits: (r == null ? void 0 : r.hits) ?? [], meaning: (r == null ? void 0 : r.meaning) ?? null, loading: a };
631
665
  }
632
- function ft() {
633
- const e = f(), t = q();
634
- return y({
635
- mutationFn: async (n) => (await e.request(F("/chat/group-dm", n))).data,
666
+ function gt() {
667
+ const e = m(), t = b();
668
+ return g({
669
+ mutationFn: async (n) => (await e.request(M("/chat/group-dm", n))).data,
636
670
  onSuccess: () => void t.invalidateQueries({ queryKey: ["nvr-chat-rooms"] })
637
671
  });
638
672
  }
639
- function _e() {
640
- const e = f(), { data: t } = p({
673
+ function Re() {
674
+ const e = m(), { data: t } = v({
641
675
  queryKey: ["nvr-chat-config"],
642
- queryFn: async () => (await e.request(g("/chat/config"))).data ?? { bot_name: null, bot_user_id: null },
676
+ queryFn: async () => (await e.request(p("/chat/config"))).data ?? { bot_name: null, bot_user_id: null },
643
677
  staleTime: 5 * 6e4
644
678
  });
645
679
  return t ?? { bot_name: null, bot_user_id: null };
646
680
  }
647
- function ht() {
648
- return _e().bot_name;
681
+ function pt() {
682
+ return Re().bot_name;
649
683
  }
650
- function yt(e) {
651
- const t = f(), { data: n } = p({
684
+ function vt(e) {
685
+ const t = m(), { data: n } = v({
652
686
  queryKey: ["nvr-chat-pins", e],
653
687
  queryFn: async () => (await t.request(
654
- g(`/chat/rooms/${encodeURIComponent(e)}/pins`)
688
+ p(`/chat/rooms/${encodeURIComponent(e)}/pins`)
655
689
  )).data ?? [],
656
690
  enabled: !!e,
657
691
  staleTime: 15e3
658
692
  });
659
- return K([["nvr-chat-pins"]], e ? [e] : []), n ?? [];
693
+ return k([["nvr-chat-pins"]], e ? [e] : []), n ?? [];
660
694
  }
661
- function gt(e) {
662
- const t = f(), n = q();
663
- return y({
664
- mutationFn: (s) => t.request(F(`/chat/messages/${s}/pin`)),
695
+ function qt(e) {
696
+ const t = m(), n = b();
697
+ return g({
698
+ mutationFn: (s) => t.request(M(`/chat/messages/${s}/pin`)),
665
699
  onSuccess: () => void n.invalidateQueries({ queryKey: ["nvr-chat-pins", e] })
666
700
  });
667
701
  }
668
- const x = [
702
+ const N = [
669
703
  "#7dd3fc",
670
704
  "#86efac",
671
705
  "#fcd34d",
@@ -675,130 +709,130 @@ const x = [
675
709
  "#99f6e4",
676
710
  "#00ceff"
677
711
  ];
678
- function pt(e) {
679
- return x[Ce(e)];
712
+ function bt(e) {
713
+ return N[we(e)];
680
714
  }
681
- function Ce(e) {
715
+ function we(e) {
682
716
  let t = 0;
683
717
  for (const n of e) t = t * 31 + n.charCodeAt(0) | 0;
684
- return Math.abs(t) % x.length;
718
+ return Math.abs(t) % N.length;
685
719
  }
686
- function vt(e) {
687
- return Number.isInteger(e) && e >= 0 && e < x.length ? x[e] : null;
720
+ function _t(e) {
721
+ return Number.isInteger(e) && e >= 0 && e < N.length ? N[e] : null;
688
722
  }
689
- function qt(e) {
723
+ function Ct(e) {
690
724
  return [...e].sort((t, n) => {
691
725
  const s = (t.display_name ?? "").trim(), o = (n.display_name ?? "").trim();
692
726
  return !s != !o ? s ? -1 : 1 : s.localeCompare(o, void 0, { sensitivity: "base" }) || String(t.user_id).localeCompare(String(n.user_id));
693
727
  });
694
728
  }
695
- function bt(e) {
729
+ function Rt(e) {
696
730
  var n, s;
697
731
  if (!e) return "?";
698
732
  const t = e.trim().split(/\s+/);
699
733
  return ((((n = t[0]) == null ? void 0 : n[0]) ?? "") + (((s = t[1]) == null ? void 0 : s[0]) ?? "")).toUpperCase() || "?";
700
734
  }
701
- let M = null;
702
- function _t(e) {
703
- return M = e, () => {
704
- M === e && (M = null);
735
+ let K = null;
736
+ function wt(e) {
737
+ return K = e, () => {
738
+ K === e && (K = null);
705
739
  };
706
740
  }
707
- function Ct() {
708
- return M !== null;
741
+ function St() {
742
+ return K !== null;
709
743
  }
710
- function Rt(e, t) {
711
- M == null || M(e, t);
744
+ function Tt(e, t) {
745
+ K == null || K(e, t);
712
746
  }
713
- let $ = null;
714
- function wt(e) {
715
- return $ = e, () => {
716
- $ === e && ($ = null);
747
+ let F = null;
748
+ function Mt(e) {
749
+ return F = e, () => {
750
+ F === e && (F = null);
717
751
  };
718
752
  }
719
- function Re() {
720
- return $ !== null;
753
+ function Se() {
754
+ return F !== null;
721
755
  }
722
- function W(e, t) {
723
- $ == null || $(e, t);
756
+ function X(e, t) {
757
+ F == null || F(e, t);
724
758
  }
725
- function St(e = !0) {
726
- const t = f(), { data: n } = p({ ...V(t), enabled: e });
759
+ function Kt(e = !0) {
760
+ const t = m(), { data: n } = v({ ...J(t), enabled: e });
727
761
  return n;
728
762
  }
729
- async function Tt(e, t, n) {
763
+ async function Ft(e, t, n) {
730
764
  var r;
731
765
  const s = await e.request(
732
- g("/chat/record-room", { collection: t, item: n })
766
+ p("/chat/record-room", { collection: t, item: n })
733
767
  );
734
768
  if (!((r = s.data) != null && r.room)) return !1;
735
769
  const o = s.data.room.slice(s.data.room.indexOf(":") + 1);
736
- return W(s.data.room, o), !0;
770
+ return X(s.data.room, o), !0;
737
771
  }
738
772
  export {
739
- Ne as CHAT_DEFAULTS,
740
- ve as CHAT_ROOM_TYPES_KEY,
741
- le as ChatConfigContext,
742
- Qe as GENERAL_CHANNEL_ID,
743
- fe as MEMBER_PAGE_SIZE,
744
- Pe as REACTION_EMOJI,
745
- Re as canOpenChatRoom,
746
- Ct as canOpenDm,
747
- pt as chatAvatarColor,
748
- vt as chatAvatarColorAt,
749
- Ce as chatAvatarColorIndex,
750
- bt as chatInitials,
751
- V as chatRoomTypesQuery,
752
- Ft as discardOutbox,
753
- Tt as discussRecord,
754
- H as dmPeer,
755
- Ue as dmRoom,
756
- Kt as editOutbox,
757
- at as getMentionQuery,
758
- Ot as holdOutbox,
759
- It as nudgeChatOutbox,
760
- W as openChatRoom,
761
- Rt as openDmWith,
762
- _t as registerDmOpener,
763
- wt as registerRoomOpener,
764
- xt as retryOutbox,
765
- qt as sortOnlineUsers,
766
- ot as splitMessageTokens,
767
- he as toPagedMember,
768
- ze as useArchivedRooms,
769
- Ye as useChannelAdmin,
770
- Be as useChannelDirectory,
771
- Ge as useChannelMembers,
772
- _e as useChatBotInfo,
773
- ht as useChatBotName,
773
+ De as CHAT_DEFAULTS,
774
+ be as CHAT_ROOM_TYPES_KEY,
775
+ fe as ChatConfigContext,
776
+ Ne as GENERAL_CHANNEL_ID,
777
+ ye as MEMBER_PAGE_SIZE,
778
+ Ae as REACTION_EMOJI,
779
+ Se as canOpenChatRoom,
780
+ St as canOpenDm,
781
+ bt as chatAvatarColor,
782
+ _t as chatAvatarColorAt,
783
+ we as chatAvatarColorIndex,
784
+ Rt as chatInitials,
785
+ J as chatRoomTypesQuery,
786
+ Ot as discardOutbox,
787
+ Ft as discussRecord,
788
+ W as dmPeer,
789
+ Ee as dmRoom,
790
+ kt as editOutbox,
791
+ ut as getMentionQuery,
792
+ xt as holdOutbox,
793
+ Qt as nudgeChatOutbox,
794
+ X as openChatRoom,
795
+ Tt as openDmWith,
796
+ wt as registerDmOpener,
797
+ Mt as registerRoomOpener,
798
+ Lt as retryOutbox,
799
+ Ct as sortOnlineUsers,
800
+ ct as splitMessageTokens,
801
+ ge as toPagedMember,
802
+ Ge as useArchivedRooms,
803
+ Xe as useChannelAdmin,
804
+ Ve as useChannelDirectory,
805
+ Ye as useChannelMembers,
806
+ Re as useChatBotInfo,
807
+ pt as useChatBotName,
774
808
  _ as useChatConfig,
775
- Ae as useChatMessages,
776
- Ze as useChatRoles,
777
- je as useChatRooms,
778
- mt as useChatSearch,
779
- De as useChatThread,
780
- Xe as useCreateChannel,
781
- ft as useCreateGroupDm,
782
- Ve as useDebouncedMemberQuery,
783
- dt as useDeleteMessage,
784
- lt as useEditMessage,
785
- rt as useEntityRoomLink,
786
- st as useMarkRoomRead,
787
- L as useMyPreferences,
788
- ge as useNotificationSoundPreference,
789
- et as useOpenRoomRegistration,
790
- kt as useOutbox,
791
- We as usePagedMembers,
792
- ct as usePeerReadAt,
793
- tt as useRecordBrowserTimezone,
794
- St as useRecordRoomTypes,
795
- He as useRoomMembership,
796
- yt as useRoomPins,
797
- Ee as useSendChatMessage,
798
- pe as useSetMyPreferences,
799
- gt as useTogglePin,
800
- ut as useToggleReaction,
801
- it as useTypingIndicator,
802
- nt as useUnreadChirp,
803
- Je as useUserSearch
809
+ je as useChatMessages,
810
+ et as useChatRoles,
811
+ He as useChatRooms,
812
+ yt as useChatSearch,
813
+ ze as useChatThread,
814
+ nt as useCreateChannel,
815
+ gt as useCreateGroupDm,
816
+ Ze as useDebouncedMemberQuery,
817
+ ht as useDeleteMessage,
818
+ ft as useEditMessage,
819
+ it as useEntityRoomLink,
820
+ at as useMarkRoomRead,
821
+ E as useMyPreferences,
822
+ ve as useNotificationSoundPreference,
823
+ st as useOpenRoomRegistration,
824
+ Pt as useOutbox,
825
+ Je as usePagedMembers,
826
+ dt as usePeerReadAt,
827
+ rt as useRecordBrowserTimezone,
828
+ Kt as useRecordRoomTypes,
829
+ We as useRoomMembership,
830
+ vt as useRoomPins,
831
+ Be as useSendChatMessage,
832
+ qe as useSetMyPreferences,
833
+ qt as useTogglePin,
834
+ mt as useToggleReaction,
835
+ lt as useTypingIndicator,
836
+ ot as useUnreadChirp,
837
+ tt as useUserSearch
804
838
  };