@ethora/chat-component 26.6.7 → 26.7.2

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.
Files changed (46) hide show
  1. package/dist/VideoCallOverlay-BgYU8sTM.js +23647 -0
  2. package/dist/VideoCallOverlay-BgYU8sTM.js.map +1 -0
  3. package/dist/assets/icons.d.ts +4 -0
  4. package/dist/components/MainComponents/ChatHeader.d.ts +2 -1
  5. package/dist/components/MainComponents/LanguageSelectorModal.d.ts +3 -0
  6. package/dist/components/MainComponents/ProfileImagePlaceholder.d.ts +2 -0
  7. package/dist/components/MainComponents/Switch.d.ts +8 -0
  8. package/dist/components/MessageBubble/MessageTranslate.d.ts +25 -0
  9. package/dist/components/MessageBubble/TranslatedMessageBody.d.ts +21 -0
  10. package/dist/components/Notification/NotificationPermissionBanner.d.ts +16 -0
  11. package/dist/components/RoomComponents/ChatRoomItem.d.ts +2 -2
  12. package/dist/components/RoomComponents/OnlineUsersPopover.d.ts +11 -0
  13. package/dist/components/styled/StyledInputComponents/MediaComponents.d.ts +4 -0
  14. package/dist/firebase-messaging-sw.js +16 -4
  15. package/dist/helpers/callLogMessage.d.ts +22 -0
  16. package/dist/helpers/createUserNameFromSetUser.d.ts +36 -1
  17. package/dist/helpers/isLikelyMucJid.d.ts +18 -0
  18. package/dist/helpers/resolveIconColor.d.ts +5 -3
  19. package/dist/helpers/scheduleAckCatchup.d.ts +27 -0
  20. package/dist/helpers/toBaseLanguage.d.ts +8 -0
  21. package/dist/hooks/useChatSettingState.d.ts +2 -0
  22. package/dist/hooks/useChatWrapperInit.d.ts +3 -1
  23. package/dist/hooks/useIsMobileViewport.d.ts +1 -0
  24. package/dist/hooks/useMessageTranslation.d.ts +28 -0
  25. package/dist/hooks/useRoomPresence.d.ts +10 -0
  26. package/dist/hooks/useSendMessage.d.ts +1 -0
  27. package/dist/i18n/strings.d.ts +15 -0
  28. package/dist/i18n/useT.d.ts +33 -0
  29. package/dist/main-82wctwRX.js +74711 -0
  30. package/dist/main-82wctwRX.js.map +1 -0
  31. package/dist/main.d.ts +1 -0
  32. package/dist/main.js +23 -77070
  33. package/dist/main.js.map +1 -1
  34. package/dist/networking/authRefresh.d.ts +6 -0
  35. package/dist/networking/xmppClient.d.ts +2 -0
  36. package/dist/roomStore/Middleware/unreadMidlleware.d.ts +1 -0
  37. package/dist/roomStore/callSlice.d.ts +1 -0
  38. package/dist/roomStore/chatSettingsSlice.d.ts +25 -1
  39. package/dist/roomStore/roomsSlice.d.ts +8 -1
  40. package/dist/types/models/config.model.d.ts +122 -0
  41. package/dist/types/models/language.model.d.ts +1 -1
  42. package/dist/types/models/message.model.d.ts +1 -0
  43. package/dist/utils/translateModePolicy.d.ts +19 -0
  44. package/package.json +1 -1
  45. package/public/firebase-messaging-sw.js +16 -4
  46. package/dist/components/MessageBubble/MessageTranslations.d.ts +0 -10
@@ -1,3 +1,4 @@
1
+ import { User } from '../types/types';
1
2
  /**
2
3
  * THE single refresh-token rotation point for the SDK.
3
4
  *
@@ -98,5 +99,10 @@ export declare function refreshAuthTokens(options?: RefreshOptions): Promise<Ref
98
99
  */
99
100
  export declare function refreshAuthTokensQuietly(): Promise<RefreshResult | null>;
100
101
  export declare function startCrossTabTokenSync(): () => void;
102
+ type CredentialLike = Partial<Pick<User, 'xmppUsername' | 'refreshToken' | 'token'>> | null | undefined;
103
+ export declare function markCurrentSessionDead(): void;
104
+ export declare function isSessionDead(candidate: CredentialLike): boolean;
105
+ export declare function clearDeadSessionLatch(): void;
101
106
  /** Test seam: drops any shared in-flight promise between cases. */
102
107
  export declare function __resetAuthRefreshStateForTests(): void;
108
+ export {};
@@ -22,6 +22,7 @@ export declare class XmppClient implements XmppClientInterface {
22
22
  private reconnecting;
23
23
  private reconnectPromise;
24
24
  presencesReady: boolean;
25
+ private sendAllPresencesInFlight;
25
26
  private connectionSteps;
26
27
  private messageQueue;
27
28
  private highLaneBurstLimit;
@@ -141,6 +142,7 @@ export declare class XmppClient implements XmppClientInterface {
141
142
  private startAdaptivePing;
142
143
  private markActivity;
143
144
  sendAllPresencesAndMarkReady(): Promise<void>;
145
+ private runAllPresencesSweep;
144
146
  reconnect(): Promise<void>;
145
147
  allRoomPresencesStanza(): Promise<AllRoomPresenceSummary>;
146
148
  ensureConnected(timeout?: number): Promise<void>;
@@ -1,2 +1,3 @@
1
1
  import { Middleware } from '@reduxjs/toolkit';
2
+ export declare const resolveTouchedRooms: (action: any, prevState: any, nextState: any) => Set<string>;
2
3
  export declare const unreadMiddleware: Middleware;
@@ -13,6 +13,7 @@ export interface CallState {
13
13
  token: string | null;
14
14
  error: string | null;
15
15
  startedAt: number | null;
16
+ connectedAt: number | null;
16
17
  }
17
18
  export declare const startOutgoingCall: import('@reduxjs/toolkit').ActionCreatorWithOptionalPayload<{
18
19
  roomJid: string;
@@ -8,6 +8,30 @@ interface ChatState {
8
8
  selectedUser?: IUser;
9
9
  activeFile?: ModalFile;
10
10
  langSource?: Iso639_1Codes;
11
+ /**
12
+ * Whether THIS reader's own outgoing messages get tagged with
13
+ * `<translate source="xx"/>` (see sendTextMessageWithTranslateTag) so
14
+ * translations can be generated for them. Defaults to true so existing
15
+ * hosts that already set `config.translates.enabled` see no change
16
+ * until a reader explicitly opts out via the language-selector toggle.
17
+ *
18
+ * Turning this off does NOT untag anything already sent - a message
19
+ * ships with whatever tag was active at send time, permanently. Turning
20
+ * it back on only affects messages sent from that point forward. Same
21
+ * asymmetry the other direction: turning it on doesn't retroactively
22
+ * tag old messages either - see the disclaimer surfaced next to the
23
+ * toggle in LanguageSelectorModal.
24
+ */
25
+ translateSendEnabled?: boolean;
26
+ /**
27
+ * Reader's own auto/manual pick from the language-selector modal's
28
+ * switcher. Undefined means "never touched it" - falls back to
29
+ * `config.translates.mode` (see resolveTranslateMode). Ignored entirely
30
+ * when the host sets `config.translates.forceType: true`, which is also
31
+ * why the switcher itself doesn't render in that case - nothing should
32
+ * ever write here that a host has pinned.
33
+ */
34
+ translateMode?: 'auto' | 'manual';
11
35
  }
12
36
  export declare const setUser: import('@reduxjs/toolkit').ActionCreatorWithOptionalPayload<User, "chatSettingStore/setUser">, setConfig: import('@reduxjs/toolkit').ActionCreatorWithNonInferrablePayload<"chatSettingStore/setConfig">, refreshTokens: import('@reduxjs/toolkit').ActionCreatorWithOptionalPayload<{
13
37
  token: string;
@@ -16,6 +40,6 @@ export declare const setUser: import('@reduxjs/toolkit').ActionCreatorWithOption
16
40
  xmppPassword?: string;
17
41
  }, "chatSettingStore/refreshTokens">, logout: import('@reduxjs/toolkit').ActionCreatorWithoutPayload<"chatSettingStore/logout">, setActiveModal: import('@reduxjs/toolkit').ActionCreatorWithOptionalPayload<string, "chatSettingStore/setActiveModal">, setDeleteModal: import('@reduxjs/toolkit').ActionCreatorWithOptionalPayload<DeleteModal, "chatSettingStore/setDeleteModal">, setSelectedUser: import('@reduxjs/toolkit').ActionCreatorWithOptionalPayload<IUser, "chatSettingStore/setSelectedUser">, updateUser: import('@reduxjs/toolkit').ActionCreatorWithOptionalPayload<{
18
42
  updates: Partial<User>;
19
- }, "chatSettingStore/updateUser">, setActiveFile: import('@reduxjs/toolkit').ActionCreatorWithOptionalPayload<ModalFile, "chatSettingStore/setActiveFile">, setLangSource: import('@reduxjs/toolkit').ActionCreatorWithOptionalPayload<Iso639_1Codes, "chatSettingStore/setLangSource">;
43
+ }, "chatSettingStore/updateUser">, setActiveFile: import('@reduxjs/toolkit').ActionCreatorWithOptionalPayload<ModalFile, "chatSettingStore/setActiveFile">, setLangSource: import('@reduxjs/toolkit').ActionCreatorWithOptionalPayload<Iso639_1Codes, "chatSettingStore/setLangSource">, setTranslateSendEnabled: import('@reduxjs/toolkit').ActionCreatorWithOptionalPayload<boolean, "chatSettingStore/setTranslateSendEnabled">, setTranslateMode: import('@reduxjs/toolkit').ActionCreatorWithOptionalPayload<"auto" | "manual", "chatSettingStore/setTranslateMode">;
20
44
  declare const _default: import('redux').Reducer<ChatState>;
21
45
  export default _default;
@@ -9,6 +9,7 @@ interface RoomMessagesState {
9
9
  editAction?: EditAction;
10
10
  isLoading: boolean;
11
11
  usersSet: Record<string, RoomMember>;
12
+ presenceByRoom: Record<string, string[]>;
12
13
  reportRoom: {
13
14
  isOpen: boolean;
14
15
  };
@@ -67,7 +68,13 @@ export declare const addRoom: import('@reduxjs/toolkit').ActionCreatorWithOption
67
68
  chatJID?: string;
68
69
  }, "roomMessages/setRoomNoMessages">, setCurrentRoom: import('@reduxjs/toolkit').ActionCreatorWithOptionalPayload<{
69
70
  roomJID: string | null;
70
- }, "roomMessages/setCurrentRoom">, setChatUiVisible: import('@reduxjs/toolkit').ActionCreatorWithOptionalPayload<boolean, "roomMessages/setChatUiVisible">, setRoomRole: import('@reduxjs/toolkit').ActionCreatorWithOptionalPayload<{
71
+ }, "roomMessages/setCurrentRoom">, setMemberOnline: import('@reduxjs/toolkit').ActionCreatorWithOptionalPayload<{
72
+ roomJID: string;
73
+ xmppUsername: string;
74
+ }, "roomMessages/setMemberOnline">, setMemberOffline: import('@reduxjs/toolkit').ActionCreatorWithOptionalPayload<{
75
+ roomJID: string;
76
+ xmppUsername: string;
77
+ }, "roomMessages/setMemberOffline">, setChatUiVisible: import('@reduxjs/toolkit').ActionCreatorWithOptionalPayload<boolean, "roomMessages/setChatUiVisible">, setRoomRole: import('@reduxjs/toolkit').ActionCreatorWithOptionalPayload<{
71
78
  chatJID: string;
72
79
  role: string;
73
80
  }, "roomMessages/setRoomRole">, setReactions: import('@reduxjs/toolkit').ActionCreatorWithOptionalPayload<ReactionAction, "roomMessages/setReactions">, setLogoutState: import('@reduxjs/toolkit').ActionCreatorWithoutPayload<"roomMessages/setLogoutState">, setActiveMessage: import('@reduxjs/toolkit').ActionCreatorWithOptionalPayload<{
@@ -238,6 +238,88 @@ export interface IConfig {
238
238
  translates?: {
239
239
  enabled: boolean;
240
240
  translations?: Iso639_1Codes;
241
+ /**
242
+ * 'auto' shows the translation inline automatically. 'manual' shows a
243
+ * "Translate" link the reader clicks (LinkedIn-style), then renders the
244
+ * result inline with a "Show original" toggle. Default 'auto'.
245
+ *
246
+ * Neither mode calls any translation service - both only ever display
247
+ * `message.translations`, whatever arrived attached to the stanza (see
248
+ * `readerLocale` below for how a message gets translated in the first
249
+ * place). This is purely a display choice: show it immediately, or let
250
+ * the reader ask for it.
251
+ */
252
+ mode?: 'auto' | 'manual';
253
+ /**
254
+ * Pins `mode` as fixed host policy. When true, the language-selector
255
+ * modal's auto/manual switcher does not render at all, and the reader
256
+ * has no way to override `mode` - it's always whatever the host set.
257
+ * Defaults to false: the reader can flip between auto and manual
258
+ * themselves via the switcher, which then wins over `mode` (the host's
259
+ * declared default, used until the reader touches it).
260
+ */
261
+ forceType?: boolean;
262
+ /**
263
+ * Reader's full locale (BCP-47, e.g. "fr-CA"). Falls back to
264
+ * `config.i18n.locale`. The region is passed through to `onTranslate` so
265
+ * the service can distinguish fr-CA vs fr-FR; the Translate button
266
+ * visibility comparison ignores the region (en-US vs en-CA => no button).
267
+ *
268
+ * This is also how a host drives the reader's language from OUTSIDE the
269
+ * chat component: set it (e.g. from your own app's language switcher)
270
+ * and pass the updated config down as a normal prop. Whenever it
271
+ * changes, the component syncs it into the same internal state the
272
+ * in-chat language picker writes to - so it drives both what a reader
273
+ * sees translated INTO and the source language declared on their own
274
+ * outgoing messages. Leave unset to let the reader manage it themselves
275
+ * via the picker (see `showLanguageSelector`).
276
+ */
277
+ readerLocale?: string;
278
+ /**
279
+ * Shows/hides the globe-icon language picker in the chat header.
280
+ * Defaults to true whenever `enabled` is true. Set to false when the
281
+ * host manages the reader's language itself (via `readerLocale`) and
282
+ * an in-chat picker would just be a second, redundant control.
283
+ */
284
+ showLanguageSelector?: boolean;
285
+ /**
286
+ * Shows/hides the list of selectable languages INSIDE the picker
287
+ * (English/Español/...). Defaults to true. Set to false to keep only
288
+ * the enable/disable-translates toggle - for hosts that drive the
289
+ * reader's language externally via `readerLocale` and don't want a
290
+ * second, redundant language list, but still want the reader to control
291
+ * whether their own outgoing messages get tagged for translation.
292
+ */
293
+ showLanguageList?: boolean;
294
+ /**
295
+ * Host-provided translation function. When set, the manual Translate
296
+ * action calls this - wire it to your own service - instead of reading
297
+ * `message.translations`. Optional; omit to use only what already
298
+ * arrived over XMPP.
299
+ */
300
+ onTranslate?: (text: string, ctx: {
301
+ sourceLocale?: string;
302
+ targetLocale: string;
303
+ message: IMessage;
304
+ }) => Promise<string>;
305
+ /**
306
+ * Host predicate deciding whether to show the Translate action for a given
307
+ * message. When omitted, the component compares base languages (message
308
+ * source vs reader, region ignored) and shows the action when they differ.
309
+ */
310
+ showTranslateForMessage?: (message: IMessage) => boolean;
311
+ };
312
+ /**
313
+ * Static UI i18n (interface captions like "Search...", "Type message").
314
+ * `locale` is a BCP-47 tag the host passes from the device/user (e.g. "en",
315
+ * "fr-CA", "es-US"); captions resolve to its base language. `strings`
316
+ * overrides or extends any built-in caption by key (see src/i18n/strings.ts).
317
+ * Built-in languages: en, fr, es. Independent from `translates` (dynamic
318
+ * per-message translation).
319
+ */
320
+ i18n?: {
321
+ locale?: string;
322
+ strings?: Record<string, string>;
241
323
  };
242
324
  disableRoomConfig?: boolean;
243
325
  disableProfilesInteractions?: boolean;
@@ -377,6 +459,46 @@ export interface IConfig {
377
459
  iconPath?: string;
378
460
  badgePath?: string;
379
461
  softAsk?: boolean;
462
+ /**
463
+ * In-app banner that nudges the user to turn on browser notifications.
464
+ * Off by default. The banner renders one of two states automatically from
465
+ * the current `Notification.permission`:
466
+ * - "default" (never asked) → an "Enable notifications" card with a button
467
+ * that triggers the browser permission prompt;
468
+ * - "denied" (blocked) → a "Notifications are blocked" card explaining how
469
+ * to re-allow it from the browser's site settings.
470
+ * It hides itself entirely once permission is "granted", when the browser
471
+ * has no Notification API, or when `pushNotifications.enabled` is not true.
472
+ * Every label is overridable so it can be localised.
473
+ */
474
+ permissionBanner?: {
475
+ /** Master switch for the banner. Default false (opt-in). */
476
+ enabled?: boolean;
477
+ /** Show the prompt while permission is "default". Default true. */
478
+ showWhenDefault?: boolean;
479
+ /**
480
+ * Show the notice while permission is "denied". Default false: a blocked
481
+ * state can only be fixed by hand in the browser's site settings, so by
482
+ * default we don't nag. Set true to opt back into the reminder.
483
+ */
484
+ showWhenBlocked?: boolean;
485
+ /** Render a dismiss (×) control. Default true. Dismissal lasts the tab session. */
486
+ dismissible?: boolean;
487
+ /** Where the fixed banner is anchored. Default "bottom-right". */
488
+ position?: 'top-left' | 'top-right' | 'top-center' | 'bottom-left' | 'bottom-right' | 'bottom-center';
489
+ /** Title for the "enable" state. Default "Enable notifications". */
490
+ enableTitle?: string;
491
+ /** Description for the "enable" state. */
492
+ enableDescription?: string;
493
+ /** Button label for the "enable" state. Default "Enable notifications". */
494
+ enableButtonLabel?: string;
495
+ /** Title for the "blocked" state. Default "Notifications are blocked". */
496
+ blockedTitle?: string;
497
+ /** Description for the "blocked" state. */
498
+ blockedDescription?: string;
499
+ /** Inline style overrides merged onto the banner container. */
500
+ style?: React.CSSProperties;
501
+ };
380
502
  onClick?: (params: {
381
503
  roomJID?: string;
382
504
  messageId?: string;
@@ -1,4 +1,4 @@
1
- export type Iso639_1Codes = 'en' | 'es' | 'pt' | 'ht' | 'zh';
1
+ export type Iso639_1Codes = 'en' | 'en-CA' | 'es' | 'es-US' | 'pt' | 'ht' | 'fr' | 'fr-CA' | 'zh';
2
2
  export interface Language {
3
3
  iso639_1: Iso639_1Codes;
4
4
  name: string;
@@ -22,6 +22,7 @@ export interface IMessage {
22
22
  activeMessage?: boolean;
23
23
  isReply?: boolean | string;
24
24
  isDeleted?: boolean;
25
+ isEdited?: boolean;
25
26
  mainMessage?: string;
26
27
  reply?: IReply[];
27
28
  reaction?: Record<string, ReactionMessage>;
@@ -0,0 +1,19 @@
1
+ import { IConfig } from '../types/types';
2
+ export type TranslateMode = 'auto' | 'manual';
3
+ /**
4
+ * Whether the reader is allowed to pick auto vs manual themselves via the
5
+ * language-selector modal's switcher. `forceType: true` means the host has
6
+ * pinned `translates.mode` as policy - the switcher must not even render,
7
+ * let alone let a reader flip it.
8
+ */
9
+ export declare const canReaderChooseTranslateMode: (translates?: IConfig["translates"]) => boolean;
10
+ /**
11
+ * The mode actually in effect for this reader right now.
12
+ *
13
+ * `forceType` wins unconditionally - even a leftover `readerMode` from
14
+ * before the host turned forcing on must not leak through. Otherwise the
15
+ * reader's own pick (if they've touched the switcher) wins over the host's
16
+ * declared default, and the host's `mode` (defaulting to 'auto') is the
17
+ * fallback for a reader who never has.
18
+ */
19
+ export declare const resolveTranslateMode: (translates?: IConfig["translates"], readerMode?: TranslateMode) => TranslateMode;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ethora/chat-component",
3
- "version": "26.6.7",
3
+ "version": "26.7.2",
4
4
  "type": "module",
5
5
  "main": "dist/main.js",
6
6
  "types": "dist/main.d.ts",
@@ -384,9 +384,10 @@ async function handlePush(raw = {}, source = 'push') {
384
384
  });
385
385
 
386
386
  const visible = isVisibleClients(windowClients);
387
+ const hasAnyClient = windowClients.length > 0;
387
388
 
388
389
  if (DEBUG) log('clients:', dumpClients(windowClients));
389
- log('visibleClientExists:', visible);
390
+ log('visibleClientExists:', visible, 'anyClientExists:', hasAnyClient);
390
391
 
391
392
  await broadcastDebugMessage({
392
393
  source,
@@ -445,9 +446,20 @@ async function handlePush(raw = {}, source = 'push') {
445
446
  },
446
447
  };
447
448
 
448
- if (!visible) {
449
+ // Calls: a client that's merely backgrounded (open, just not the
450
+ // visible/focused tab) is NOT the "nobody will hear this ring" case -
451
+ // VideoCallOverlay already rings its own OS notification for exactly
452
+ // that state (see its comment: this SW push is meant to be the
453
+ // fully-offline fallback). `visible` collapses "backgrounded but open"
454
+ // and "fully closed" into the same false, which duplicated that
455
+ // client-side ring every time the tab was merely hidden. Suppress on
456
+ // ANY open client for calls; regular messages keep the visible-only
457
+ // check they already had.
458
+ const suppress = isCall ? hasAnyClient : visible;
459
+
460
+ if (!suppress) {
449
461
  log('SHOW NOTIFICATION', {
450
- reason: 'NO_VISIBLE_CLIENT',
462
+ reason: isCall ? 'NO_CLIENT_AT_ALL' : 'NO_VISIBLE_CLIENT',
451
463
  tag: options.tag,
452
464
  isCall,
453
465
  });
@@ -456,7 +468,7 @@ async function handlePush(raw = {}, source = 'push') {
456
468
  }
457
469
 
458
470
  log('SKIP NOTIFICATION', {
459
- reason: 'VISIBLE_CLIENT',
471
+ reason: isCall ? 'CLIENT_OPEN_WILL_RING_ITSELF' : 'VISIBLE_CLIENT',
460
472
  });
461
473
  }
462
474
 
@@ -1,10 +0,0 @@
1
- import { FC } from 'react';
2
- import { IConfig, IMessage } from '../../types/types';
3
- interface MessageTranslationsProps {
4
- message: IMessage;
5
- langSource?: string;
6
- isUser: boolean;
7
- config?: IConfig;
8
- }
9
- declare const MessageTranslations: FC<MessageTranslationsProps>;
10
- export default MessageTranslations;