@linktr.ee/messaging-react 3.38.2 → 4.0.0-rc-1786383199

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 (32) hide show
  1. package/dist/{Card-2Ms7lBDO.js → Card-B3XsV8Td.js} +2 -2
  2. package/dist/{Card-2Ms7lBDO.js.map → Card-B3XsV8Td.js.map} +1 -1
  3. package/dist/{Card-KwVE3M5j.cjs → Card-DkQdjw4V.cjs} +2 -2
  4. package/dist/{Card-KwVE3M5j.cjs.map → Card-DkQdjw4V.cjs.map} +1 -1
  5. package/dist/index-B1u9TBSD.cjs +3 -0
  6. package/dist/index-B1u9TBSD.cjs.map +1 -0
  7. package/dist/{index-i03XGFsr.js → index-NfAAanC-.js} +372 -371
  8. package/dist/index-NfAAanC-.js.map +1 -0
  9. package/dist/index.cjs +1 -1
  10. package/dist/index.d.ts +18 -13
  11. package/dist/index.js +1 -1
  12. package/dist/testing.d.ts +5 -2
  13. package/package.json +2 -2
  14. package/src/components/{ChannelHeaderRedesign.tsx → ChannelHeader.tsx} +4 -2
  15. package/src/components/{ChannelView.broadcast-name.integration.test.tsx → ChannelView.broadcast-resolution.integration.test.tsx} +11 -9
  16. package/src/components/ChannelView.tsx +15 -15
  17. package/src/components/CustomMessage/BroadcastContext.test.ts +52 -0
  18. package/src/components/CustomMessage/BroadcastContext.ts +101 -0
  19. package/src/components/CustomMessage/CustomMessage.stories.tsx +29 -21
  20. package/src/components/CustomMessage/CustomMessage.test.tsx +49 -20
  21. package/src/components/CustomMessage/SentMessageDeliveryStatus.test.tsx +37 -17
  22. package/src/components/CustomMessage/SentMessageDeliveryStatus.tsx +17 -24
  23. package/src/components/CustomMessage/index.tsx +18 -13
  24. package/src/components/MessagingShell/index.tsx +2 -2
  25. package/src/index.ts +2 -1
  26. package/src/stream-custom-data.ts +5 -2
  27. package/src/types.ts +13 -9
  28. package/dist/index-DzOGH7lG.cjs +0 -3
  29. package/dist/index-DzOGH7lG.cjs.map +0 -1
  30. package/dist/index-i03XGFsr.js.map +0 -1
  31. package/src/components/CustomMessage/BroadcastNameContext.test.ts +0 -43
  32. package/src/components/CustomMessage/BroadcastNameContext.ts +0 -95
@@ -1,43 +0,0 @@
1
- import { describe, expect, it, vi } from 'vitest'
2
-
3
- import { buildBroadcastNamesById } from './BroadcastNameContext'
4
-
5
- describe('buildBroadcastNamesById', () => {
6
- it('returns undefined when no resolver is provided', () => {
7
- expect(
8
- buildBroadcastNamesById(
9
- [{ metadata: { broadcast_id: 'broadcast-1' } }],
10
- undefined
11
- )
12
- ).toBeUndefined()
13
- })
14
-
15
- it('resolves each unique broadcast id once', () => {
16
- const resolveBroadcastName = vi.fn((id: string) => `name-for-${id}`)
17
-
18
- expect(
19
- buildBroadcastNamesById(
20
- [
21
- { metadata: { broadcast_id: 'broadcast-1' } },
22
- { metadata: { broadcast_id: 'broadcast-1' } },
23
- { metadata: { broadcast_id: 'broadcast-2' } },
24
- { metadata: {} },
25
- ],
26
- resolveBroadcastName
27
- )
28
- ).toEqual({
29
- 'broadcast-1': 'name-for-broadcast-1',
30
- 'broadcast-2': 'name-for-broadcast-2',
31
- })
32
- expect(resolveBroadcastName).toHaveBeenCalledTimes(2)
33
- })
34
-
35
- it('omits ids the resolver cannot resolve yet', () => {
36
- expect(
37
- buildBroadcastNamesById(
38
- [{ metadata: { broadcast_id: 'broadcast-1' } }],
39
- () => undefined
40
- )
41
- ).toBeUndefined()
42
- })
43
- })
@@ -1,95 +0,0 @@
1
- import { createContext, useState } from 'react'
2
-
3
- import type { BroadcastNameResolver } from '../../types'
4
-
5
- /** Live campaign names keyed by broadcast id — not the resolver function. */
6
- export type BroadcastNamesById = Readonly<Record<string, string>>
7
-
8
- export const BroadcastNameContext = createContext<
9
- BroadcastNamesById | undefined
10
- >(undefined)
11
-
12
- const broadcastIdFromMessage = (message: {
13
- metadata?: { broadcast_id?: unknown }
14
- }): string | undefined => {
15
- const broadcastId = message.metadata?.broadcast_id
16
- return typeof broadcastId === 'string' ? broadcastId : undefined
17
- }
18
-
19
- /**
20
- * Resolve campaign names for the messages currently in view.
21
- *
22
- * Built outside memoized Stream rows so a new resolver reference can publish
23
- * new campaign names without remounting the Stream message rows.
24
- */
25
- export const buildBroadcastNamesById = (
26
- messages: readonly { metadata?: { broadcast_id?: unknown } }[] | undefined,
27
- resolveBroadcastName: BroadcastNameResolver | undefined
28
- ): BroadcastNamesById | undefined => {
29
- if (!resolveBroadcastName || !messages?.length) {
30
- return undefined
31
- }
32
-
33
- const seen = new Set<string>()
34
- let names: Record<string, string> | undefined
35
-
36
- for (const message of messages) {
37
- const broadcastId = broadcastIdFromMessage(message)
38
- if (!broadcastId || seen.has(broadcastId)) {
39
- continue
40
- }
41
- seen.add(broadcastId)
42
-
43
- const resolved = resolveBroadcastName(broadcastId)
44
- if (!resolved) {
45
- continue
46
- }
47
-
48
- names ??= {}
49
- names[broadcastId] = resolved
50
- }
51
-
52
- return names
53
- }
54
-
55
- const areBroadcastNamesEqual = (
56
- previous: BroadcastNamesById | undefined,
57
- next: BroadcastNamesById | undefined
58
- ): boolean => {
59
- if (previous === next) {
60
- return true
61
- }
62
- if (!previous || !next) {
63
- return false
64
- }
65
-
66
- const previousIds = Object.keys(previous)
67
- const nextIds = Object.keys(next)
68
- if (previousIds.length !== nextIds.length) {
69
- return false
70
- }
71
-
72
- return previousIds.every((id) => previous[id] === next[id])
73
- }
74
-
75
- /**
76
- * Re-invokes the resolver on every render, but only returns a new object when
77
- * the resolved strings actually change — so context consumers update for
78
- * late-arriving campaign names without thrashing on unrelated renders.
79
- */
80
- export const useBroadcastNamesById = (
81
- messages: readonly { metadata?: { broadcast_id?: unknown } }[] | undefined,
82
- resolveBroadcastName: BroadcastNameResolver | undefined
83
- ): BroadcastNamesById | undefined => {
84
- const names = buildBroadcastNamesById(messages, resolveBroadcastName)
85
- const [publishedNames, setPublishedNames] = useState<
86
- BroadcastNamesById | undefined
87
- >(names)
88
-
89
- if (!areBroadcastNamesEqual(publishedNames, names)) {
90
- setPublishedNames(names)
91
- return names
92
- }
93
-
94
- return publishedNames
95
- }