@linktr.ee/messaging-react 3.6.2-rc-1783311731 → 3.6.2-rc-1783317817
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.
- package/dist/{Card-4UyBK3XO.cjs → Card-BYdqLBN3.cjs} +2 -2
- package/dist/{Card-4UyBK3XO.cjs.map → Card-BYdqLBN3.cjs.map} +1 -1
- package/dist/{Card-RZ6C_IkE.js → Card-CZDLISxS.js} +3 -3
- package/dist/{Card-RZ6C_IkE.js.map → Card-CZDLISxS.js.map} +1 -1
- package/dist/{Card-0wf8lj5n.js → Card-Ca5OtJh6.js} +2 -2
- package/dist/{Card-0wf8lj5n.js.map → Card-Ca5OtJh6.js.map} +1 -1
- package/dist/{Card-DsQhJjj0.cjs → Card-DuSTf-S8.cjs} +2 -2
- package/dist/{Card-DsQhJjj0.cjs.map → Card-DuSTf-S8.cjs.map} +1 -1
- package/dist/{Card-iGNcxybY.js → Card-gjy-ib_1.js} +2 -2
- package/dist/{Card-iGNcxybY.js.map → Card-gjy-ib_1.js.map} +1 -1
- package/dist/{Card-6b4Ws9rn.cjs → Card-iHrzL32q.cjs} +2 -2
- package/dist/{Card-6b4Ws9rn.cjs.map → Card-iHrzL32q.cjs.map} +1 -1
- package/dist/{LockedThumbnail-Do9udNMm.js → LockedThumbnail-COK5XPQ9.js} +2 -2
- package/dist/{LockedThumbnail-Do9udNMm.js.map → LockedThumbnail-COK5XPQ9.js.map} +1 -1
- package/dist/{LockedThumbnail-N0pNOO3D.cjs → LockedThumbnail-DrWiitE6.cjs} +2 -2
- package/dist/{LockedThumbnail-N0pNOO3D.cjs.map → LockedThumbnail-DrWiitE6.cjs.map} +1 -1
- package/dist/assets/index.css +1 -1
- package/dist/{index-wFe1UO9t.js → index-CnR5N9Co.js} +1097 -1104
- package/dist/index-CnR5N9Co.js.map +1 -0
- package/dist/index-pODWIZCi.cjs +2 -0
- package/dist/index-pODWIZCi.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -2
- package/src/components/CustomMessage/CustomMessage.stories.tsx +18 -11
- package/src/components/CustomMessage/MessageDeliveryStatus.test.tsx +66 -0
- package/src/components/CustomMessage/MessageDeliveryStatus.tsx +53 -0
- package/src/components/CustomMessage/index.tsx +3 -2
- package/src/styles.css +16 -25
- package/dist/index-B3ZJaqJY.cjs +0 -2
- package/dist/index-B3ZJaqJY.cjs.map +0 -1
- package/dist/index-wFe1UO9t.js.map +0 -1
- package/src/components/CustomMessage/SentMessageDeliveryStatus.test.tsx +0 -107
- package/src/components/CustomMessage/SentMessageDeliveryStatus.tsx +0 -86
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import {
|
|
3
|
-
useChannelStateContext,
|
|
4
|
-
useChatContext,
|
|
5
|
-
useMessageContext,
|
|
6
|
-
} from 'stream-chat-react'
|
|
7
|
-
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
8
|
-
|
|
9
|
-
import { renderWithProviders, screen, within } from '../../test/utils'
|
|
10
|
-
|
|
11
|
-
import { SentMessageDeliveryStatus } from './SentMessageDeliveryStatus'
|
|
12
|
-
|
|
13
|
-
// stream-chat-react's `MessageStatus` owns the outer gating (own message, not
|
|
14
|
-
// error, not in a thread) and only exposes a terminal state once a message is
|
|
15
|
-
// stored — Stream's tested code. What this component owns is the "Delivered"
|
|
16
|
-
// label wired into the terminal slots (sent/delivered/read), its "last own
|
|
17
|
-
// message" gate derived from live channel state, and suppressing the sending
|
|
18
|
-
// spinner. Mock `MessageStatus` to render the slots it was handed, and the
|
|
19
|
-
// context hooks the label reads.
|
|
20
|
-
vi.mock('stream-chat-react', () => ({
|
|
21
|
-
useMessageContext: vi.fn(),
|
|
22
|
-
useChannelStateContext: vi.fn(),
|
|
23
|
-
useChatContext: vi.fn(),
|
|
24
|
-
MessageStatus: ({
|
|
25
|
-
MessageSentStatus,
|
|
26
|
-
MessageDeliveredStatus,
|
|
27
|
-
MessageReadStatus,
|
|
28
|
-
MessageSendingStatus,
|
|
29
|
-
}: Record<string, React.ComponentType>) => (
|
|
30
|
-
<div>
|
|
31
|
-
<div data-testid="sent-slot">
|
|
32
|
-
<MessageSentStatus />
|
|
33
|
-
</div>
|
|
34
|
-
<div data-testid="delivered-slot">
|
|
35
|
-
<MessageDeliveredStatus />
|
|
36
|
-
</div>
|
|
37
|
-
<div data-testid="read-slot">
|
|
38
|
-
<MessageReadStatus />
|
|
39
|
-
</div>
|
|
40
|
-
<div data-testid="sending-slot">
|
|
41
|
-
<MessageSendingStatus />
|
|
42
|
-
</div>
|
|
43
|
-
</div>
|
|
44
|
-
),
|
|
45
|
-
}))
|
|
46
|
-
|
|
47
|
-
const mockedUseMessageContext = vi.mocked(useMessageContext)
|
|
48
|
-
const mockedUseChannelStateContext = vi.mocked(useChannelStateContext)
|
|
49
|
-
const mockedUseChatContext = vi.mocked(useChatContext)
|
|
50
|
-
|
|
51
|
-
// A run where the viewer ('me') sent the first and last messages, with an
|
|
52
|
-
// incoming message in between — the case that broke the memo-based approach.
|
|
53
|
-
const CHANNEL_MESSAGES = [
|
|
54
|
-
{ id: 'own-1', user: { id: 'me' } },
|
|
55
|
-
{ id: 'their-1', user: { id: 'them' } },
|
|
56
|
-
{ id: 'own-2', user: { id: 'me' } },
|
|
57
|
-
]
|
|
58
|
-
|
|
59
|
-
const TERMINAL_SLOTS = ['sent-slot', 'delivered-slot', 'read-slot'] as const
|
|
60
|
-
|
|
61
|
-
describe('SentMessageDeliveryStatus', () => {
|
|
62
|
-
beforeEach(() => {
|
|
63
|
-
mockedUseChatContext.mockReturnValue({ client: { user: { id: 'me' } } } as never)
|
|
64
|
-
mockedUseChannelStateContext.mockReturnValue({
|
|
65
|
-
messages: CHANNEL_MESSAGES,
|
|
66
|
-
} as never)
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
it('renders "Delivered" in every terminal slot for the last own message', () => {
|
|
70
|
-
// delivered/read fire ahead of sent in receipt channels, so all three
|
|
71
|
-
// must show the label — never Stream's default delivered icon / read
|
|
72
|
-
// avatars.
|
|
73
|
-
mockedUseMessageContext.mockReturnValue({
|
|
74
|
-
message: { id: 'own-2' },
|
|
75
|
-
} as never)
|
|
76
|
-
|
|
77
|
-
renderWithProviders(<SentMessageDeliveryStatus />)
|
|
78
|
-
|
|
79
|
-
for (const slot of TERMINAL_SLOTS) {
|
|
80
|
-
expect(
|
|
81
|
-
within(screen.getByTestId(slot)).getByText('Delivered')
|
|
82
|
-
).toBeInTheDocument()
|
|
83
|
-
}
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
it('renders nothing for an earlier own message even though one is the last own message', () => {
|
|
87
|
-
mockedUseMessageContext.mockReturnValue({
|
|
88
|
-
message: { id: 'own-1' },
|
|
89
|
-
} as never)
|
|
90
|
-
|
|
91
|
-
renderWithProviders(<SentMessageDeliveryStatus />)
|
|
92
|
-
|
|
93
|
-
for (const slot of TERMINAL_SLOTS) {
|
|
94
|
-
expect(screen.getByTestId(slot)).toBeEmptyDOMElement()
|
|
95
|
-
}
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
it('always suppresses the sending spinner', () => {
|
|
99
|
-
mockedUseMessageContext.mockReturnValue({
|
|
100
|
-
message: { id: 'own-2' },
|
|
101
|
-
} as never)
|
|
102
|
-
|
|
103
|
-
renderWithProviders(<SentMessageDeliveryStatus />)
|
|
104
|
-
|
|
105
|
-
expect(screen.getByTestId('sending-slot')).toBeEmptyDOMElement()
|
|
106
|
-
})
|
|
107
|
-
})
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { ChecksIcon } from '@phosphor-icons/react'
|
|
2
|
-
import { useMemo } from 'react'
|
|
3
|
-
import {
|
|
4
|
-
MessageStatus,
|
|
5
|
-
useChannelStateContext,
|
|
6
|
-
useChatContext,
|
|
7
|
-
useMessageContext,
|
|
8
|
-
} from 'stream-chat-react'
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* "✓✓ Delivered" label, wired into *every* terminal `MessageStatus` state
|
|
12
|
-
* (sent / delivered / read).
|
|
13
|
-
*
|
|
14
|
-
* Two reasons this is more than a static label:
|
|
15
|
-
*
|
|
16
|
-
* 1. `MessageStatus` picks its `delivered`/`read` branches ahead of `sent`
|
|
17
|
-
* whenever Stream has `deliveredTo`/`readBy`, and — unlike `sent` — those
|
|
18
|
-
* branches aren't gated to the last own message. So we override all three
|
|
19
|
-
* terminal slots with this same label (never Stream's default delivered
|
|
20
|
-
* icon / read avatars — Read is out of scope) and re-apply the "last own
|
|
21
|
-
* message" gate ourselves.
|
|
22
|
-
*
|
|
23
|
-
* 2. We derive "last own message" from **live channel state**, not the
|
|
24
|
-
* message context's `lastOwnMessage`. Stream's `Message` is memoised by
|
|
25
|
-
* `areMessagePropsEqual`, which does not compare `lastOwnMessage`; a
|
|
26
|
-
* previous own row whose message/grouping props are unchanged (e.g. after
|
|
27
|
-
* an intervening incoming message) never re-renders, so its context
|
|
28
|
-
* `lastOwnMessage` goes stale and the old bubble would keep showing
|
|
29
|
-
* "Delivered" beside the new one. `useChannelStateContext` gets a fresh
|
|
30
|
-
* `messages` array on every new message and, being a context, re-renders
|
|
31
|
-
* this leaf straight through the stale `Message`/`MessageStatus` memos —
|
|
32
|
-
* so the label reliably hops to the newest own message.
|
|
33
|
-
*
|
|
34
|
-
* Rendered inside stream's `.str-chat__message-status` span, which supplies
|
|
35
|
-
* the flex layout; icon and copy are styled via that span in `styles.css`.
|
|
36
|
-
*/
|
|
37
|
-
const DeliveredStatus = () => {
|
|
38
|
-
const { message } = useMessageContext('SentMessageDeliveryStatus')
|
|
39
|
-
const { messages } = useChannelStateContext('SentMessageDeliveryStatus')
|
|
40
|
-
const { client } = useChatContext('SentMessageDeliveryStatus')
|
|
41
|
-
|
|
42
|
-
const ownUserId = client.user?.id
|
|
43
|
-
const lastOwnMessageId = useMemo(() => {
|
|
44
|
-
if (!ownUserId || !messages) return undefined
|
|
45
|
-
for (let i = messages.length - 1; i >= 0; i -= 1) {
|
|
46
|
-
if (messages[i].user?.id === ownUserId) return messages[i].id
|
|
47
|
-
}
|
|
48
|
-
return undefined
|
|
49
|
-
}, [messages, ownUserId])
|
|
50
|
-
|
|
51
|
-
if (message.id !== lastOwnMessageId) {
|
|
52
|
-
return null
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return (
|
|
56
|
-
<>
|
|
57
|
-
<ChecksIcon weight="bold" aria-hidden="true" />
|
|
58
|
-
<span data-testid="sent-message-delivery-status">Delivered</span>
|
|
59
|
-
</>
|
|
60
|
-
)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/** Suppresses a MessageStatus slot we don't want to render. */
|
|
64
|
-
const NoStatus = () => null
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Delivery status beneath the viewer's most recent sent message (MES-1036):
|
|
68
|
-
* a right-aligned "✓✓ Delivered" that appears once Stream confirms the
|
|
69
|
-
* message is stored and updates live.
|
|
70
|
-
*
|
|
71
|
-
* Built on stream-chat-react's `MessageStatus`, which owns the gating we keep
|
|
72
|
-
* — own message, not an error, not inside a thread — and only surfaces a
|
|
73
|
-
* terminal (sending/sent/delivered/read) state once the message is stored.
|
|
74
|
-
* Scope is "Delivered" only: the sending spinner is suppressed and all
|
|
75
|
-
* terminal states render {@link DeliveredStatus}, which supplies the label
|
|
76
|
-
* and the last-own-message gate (see there for why the gate is computed from
|
|
77
|
-
* live channel state rather than the context's `lastOwnMessage`).
|
|
78
|
-
*/
|
|
79
|
-
export const SentMessageDeliveryStatus = () => (
|
|
80
|
-
<MessageStatus
|
|
81
|
-
MessageSentStatus={DeliveredStatus}
|
|
82
|
-
MessageDeliveredStatus={DeliveredStatus}
|
|
83
|
-
MessageReadStatus={DeliveredStatus}
|
|
84
|
-
MessageSendingStatus={NoStatus}
|
|
85
|
-
/>
|
|
86
|
-
)
|