stream-chat-react-native-core 9.5.1-beta.6 → 9.5.1-beta.8
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/lib/commonjs/components/ChannelDetails/components/navigation-section/PinnedMessageItem.js +4 -1
- package/lib/commonjs/components/ChannelDetails/components/navigation-section/PinnedMessageItem.js.map +1 -1
- package/lib/commonjs/components/MessageList/MessageFlashList.js +7 -2
- package/lib/commonjs/components/MessageList/MessageFlashList.js.map +1 -1
- package/lib/commonjs/components/MessageList/MessageList.js +7 -2
- package/lib/commonjs/components/MessageList/MessageList.js.map +1 -1
- package/lib/commonjs/components/Notifications/index.js +11 -0
- package/lib/commonjs/components/Notifications/index.js.map +1 -1
- package/lib/commonjs/components/Notifications/notificationFilters.js +9 -0
- package/lib/commonjs/components/Notifications/notificationFilters.js.map +1 -0
- package/lib/commonjs/version.json +1 -1
- package/lib/module/components/ChannelDetails/components/navigation-section/PinnedMessageItem.js +4 -1
- package/lib/module/components/ChannelDetails/components/navigation-section/PinnedMessageItem.js.map +1 -1
- package/lib/module/components/MessageList/MessageFlashList.js +7 -2
- package/lib/module/components/MessageList/MessageFlashList.js.map +1 -1
- package/lib/module/components/MessageList/MessageList.js +7 -2
- package/lib/module/components/MessageList/MessageList.js.map +1 -1
- package/lib/module/components/Notifications/index.js +11 -0
- package/lib/module/components/Notifications/index.js.map +1 -1
- package/lib/module/components/Notifications/notificationFilters.js +9 -0
- package/lib/module/components/Notifications/notificationFilters.js.map +1 -0
- package/lib/module/version.json +1 -1
- package/lib/typescript/components/ChannelDetails/components/navigation-section/PinnedMessageItem.d.ts.map +1 -1
- package/lib/typescript/components/MessageList/MessageFlashList.d.ts +1 -1
- package/lib/typescript/components/MessageList/MessageFlashList.d.ts.map +1 -1
- package/lib/typescript/components/MessageList/MessageList.d.ts +1 -1
- package/lib/typescript/components/MessageList/MessageList.d.ts.map +1 -1
- package/lib/typescript/components/Notifications/index.d.ts +1 -0
- package/lib/typescript/components/Notifications/index.d.ts.map +1 -1
- package/lib/typescript/components/Notifications/notificationFilters.d.ts +10 -0
- package/lib/typescript/components/Notifications/notificationFilters.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/components/ChannelDetails/components/__tests__/navigation-section/PinnedMessageItem.test.tsx +30 -2
- package/src/components/ChannelDetails/components/navigation-section/PinnedMessageItem.tsx +5 -1
- package/src/components/MessageList/MessageFlashList.tsx +13 -3
- package/src/components/MessageList/MessageList.tsx +13 -3
- package/src/components/Notifications/__tests__/notificationFilters.test.ts +50 -0
- package/src/components/Notifications/index.ts +1 -0
- package/src/components/Notifications/notificationFilters.ts +26 -0
- package/src/version.json +1 -1
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Notification } from 'stream-chat';
|
|
2
|
+
|
|
3
|
+
import { excludeCanceledUploadNotifications } from '../notificationFilters';
|
|
4
|
+
|
|
5
|
+
const buildNotification = (overrides: Partial<Notification> = {}): Notification =>
|
|
6
|
+
({
|
|
7
|
+
createdAt: 0,
|
|
8
|
+
id: 'n1',
|
|
9
|
+
message: 'Error uploading attachment',
|
|
10
|
+
origin: { emitter: 'AttachmentManager' },
|
|
11
|
+
type: 'api:attachment:upload:failed',
|
|
12
|
+
...overrides,
|
|
13
|
+
}) as Notification;
|
|
14
|
+
|
|
15
|
+
const canceledError = (name: 'AbortError' | 'CanceledError') => {
|
|
16
|
+
const error = new Error('canceled');
|
|
17
|
+
error.name = name;
|
|
18
|
+
return error;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// A filter returns `true` to KEEP a notification, `false` to hide it.
|
|
22
|
+
describe('excludeCanceledUploadNotifications', () => {
|
|
23
|
+
it.each(['AbortError', 'CanceledError'] as const)(
|
|
24
|
+
'hides an upload-failed notification aborted with %s',
|
|
25
|
+
(name) => {
|
|
26
|
+
const notification = buildNotification({ originalError: canceledError(name) });
|
|
27
|
+
|
|
28
|
+
expect(excludeCanceledUploadNotifications(notification)).toBe(false);
|
|
29
|
+
},
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
it('keeps a genuine upload failure', () => {
|
|
33
|
+
const notification = buildNotification({ originalError: new Error('Network Error') });
|
|
34
|
+
|
|
35
|
+
expect(excludeCanceledUploadNotifications(notification)).toBe(true);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('keeps an upload-failed notification with no original error', () => {
|
|
39
|
+
expect(excludeCanceledUploadNotifications(buildNotification())).toBe(true);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('keeps a cancellation error reported on a different notification type', () => {
|
|
43
|
+
const notification = buildNotification({
|
|
44
|
+
originalError: canceledError('CanceledError'),
|
|
45
|
+
type: 'api:message:send:failed',
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
expect(excludeCanceledUploadNotifications(notification)).toBe(true);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Notification } from 'stream-chat';
|
|
2
|
+
|
|
3
|
+
import type { NotificationListFilter } from './NotificationList';
|
|
4
|
+
|
|
5
|
+
const ATTACHMENT_UPLOAD_FAILED_TYPE = 'api:attachment:upload:failed';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A cancelled upload surfaces as an `api:attachment:upload:failed` notification
|
|
9
|
+
* whose original error is an `AbortError` (fetch) or `CanceledError` (axios).
|
|
10
|
+
* This is what happens when the user removes an attachment before its upload
|
|
11
|
+
* has finished - the inflight request is aborted, not genuinely failed.
|
|
12
|
+
*/
|
|
13
|
+
const isCanceledAttachmentUpload = (notification: Notification) =>
|
|
14
|
+
notification.type === ATTACHMENT_UPLOAD_FAILED_TYPE &&
|
|
15
|
+
(notification.originalError?.name === 'CanceledError' ||
|
|
16
|
+
notification.originalError?.name === 'AbortError');
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Notification list filter that keeps every notification except the spurious
|
|
20
|
+
* "upload failed" one produced when a user removes an attachment mid-upload
|
|
21
|
+
* (a filter returns `true` to keep a notification). Genuine upload failures
|
|
22
|
+
* (network, server) are kept because their error is neither aborted nor
|
|
23
|
+
* cancelled.
|
|
24
|
+
*/
|
|
25
|
+
export const excludeCanceledUploadNotifications: NotificationListFilter = (notification) =>
|
|
26
|
+
!isCanceledAttachmentUpload(notification);
|
package/src/version.json
CHANGED