stream-chat-react-native-core 5.6.0-beta.0 → 5.6.0-beta.1

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 (87) hide show
  1. package/lib/commonjs/components/Attachment/Gallery.js +21 -16
  2. package/lib/commonjs/components/Attachment/Gallery.js.map +1 -1
  3. package/lib/commonjs/components/Attachment/GalleryImage.js +3 -3
  4. package/lib/commonjs/components/Attachment/GalleryImage.js.map +1 -1
  5. package/lib/commonjs/components/Channel/Channel.js +34 -30
  6. package/lib/commonjs/components/Channel/Channel.js.map +1 -1
  7. package/lib/commonjs/components/ChannelList/hooks/usePaginatedChannels.js +5 -1
  8. package/lib/commonjs/components/ChannelList/hooks/usePaginatedChannels.js.map +1 -1
  9. package/lib/commonjs/components/Message/hooks/useMessageActions.js +2 -2
  10. package/lib/commonjs/components/Message/hooks/useMessageActions.js.map +1 -1
  11. package/lib/commonjs/components/MessageInput/FileUploadPreview.js +18 -21
  12. package/lib/commonjs/components/MessageInput/FileUploadPreview.js.map +1 -1
  13. package/lib/commonjs/components/MessageInput/ImageUploadPreview.js +7 -32
  14. package/lib/commonjs/components/MessageInput/ImageUploadPreview.js.map +1 -1
  15. package/lib/commonjs/components/index.js +1 -1
  16. package/lib/commonjs/components/index.js.map +1 -1
  17. package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js +128 -89
  18. package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js.map +1 -1
  19. package/lib/commonjs/contexts/messageInputContext/hooks/useMessageDetailsForState.js +1 -0
  20. package/lib/commonjs/contexts/messageInputContext/hooks/useMessageDetailsForState.js.map +1 -1
  21. package/lib/commonjs/utils/DBSyncManager.js +16 -16
  22. package/lib/commonjs/utils/DBSyncManager.js.map +1 -1
  23. package/lib/commonjs/{components/Message/utils → utils}/removeReservedFields.js +1 -1
  24. package/lib/commonjs/utils/removeReservedFields.js.map +1 -0
  25. package/lib/commonjs/utils/utils.js +2 -2
  26. package/lib/commonjs/utils/utils.js.map +1 -1
  27. package/lib/commonjs/version.json +1 -1
  28. package/lib/module/components/Attachment/Gallery.js +21 -16
  29. package/lib/module/components/Attachment/Gallery.js.map +1 -1
  30. package/lib/module/components/Attachment/GalleryImage.js +3 -3
  31. package/lib/module/components/Attachment/GalleryImage.js.map +1 -1
  32. package/lib/module/components/Channel/Channel.js +34 -30
  33. package/lib/module/components/Channel/Channel.js.map +1 -1
  34. package/lib/module/components/ChannelList/hooks/usePaginatedChannels.js +5 -1
  35. package/lib/module/components/ChannelList/hooks/usePaginatedChannels.js.map +1 -1
  36. package/lib/module/components/Message/hooks/useMessageActions.js +2 -2
  37. package/lib/module/components/Message/hooks/useMessageActions.js.map +1 -1
  38. package/lib/module/components/MessageInput/FileUploadPreview.js +18 -21
  39. package/lib/module/components/MessageInput/FileUploadPreview.js.map +1 -1
  40. package/lib/module/components/MessageInput/ImageUploadPreview.js +7 -32
  41. package/lib/module/components/MessageInput/ImageUploadPreview.js.map +1 -1
  42. package/lib/module/components/index.js +1 -1
  43. package/lib/module/components/index.js.map +1 -1
  44. package/lib/module/contexts/messageInputContext/MessageInputContext.js +128 -89
  45. package/lib/module/contexts/messageInputContext/MessageInputContext.js.map +1 -1
  46. package/lib/module/contexts/messageInputContext/hooks/useMessageDetailsForState.js +1 -0
  47. package/lib/module/contexts/messageInputContext/hooks/useMessageDetailsForState.js.map +1 -1
  48. package/lib/module/utils/DBSyncManager.js +16 -16
  49. package/lib/module/utils/DBSyncManager.js.map +1 -1
  50. package/lib/module/{components/Message/utils → utils}/removeReservedFields.js +1 -1
  51. package/lib/module/utils/removeReservedFields.js.map +1 -0
  52. package/lib/module/utils/utils.js +2 -2
  53. package/lib/module/utils/utils.js.map +1 -1
  54. package/lib/module/version.json +1 -1
  55. package/lib/typescript/components/MessageInput/FileUploadPreview.d.ts +1 -1
  56. package/lib/typescript/components/MessageInput/ImageUploadPreview.d.ts +1 -1
  57. package/lib/typescript/components/index.d.ts +1 -1
  58. package/lib/typescript/store/mappers/mapTaskToStorable.d.ts +0 -8
  59. package/lib/typescript/store/types.d.ts +0 -4
  60. package/lib/typescript/utils/DBSyncManager.d.ts +1 -1
  61. package/lib/typescript/{components/Message/utils → utils}/removeReservedFields.d.ts +2 -2
  62. package/lib/typescript/utils/utils.d.ts +1 -1
  63. package/package.json +1 -1
  64. package/src/components/Attachment/Gallery.tsx +5 -1
  65. package/src/components/Attachment/GalleryImage.tsx +2 -0
  66. package/src/components/Channel/Channel.tsx +12 -11
  67. package/src/components/ChannelList/hooks/usePaginatedChannels.ts +6 -4
  68. package/src/components/Message/hooks/useMessageActions.tsx +1 -1
  69. package/src/components/MessageInput/FileUploadPreview.tsx +4 -5
  70. package/src/components/MessageInput/ImageUploadPreview.tsx +10 -35
  71. package/src/components/index.ts +1 -1
  72. package/src/contexts/messageInputContext/MessageInputContext.tsx +94 -75
  73. package/src/contexts/messageInputContext/__tests__/__snapshots__/sendMessage.test.tsx.snap +0 -3
  74. package/src/contexts/messageInputContext/hooks/useMessageDetailsForState.ts +1 -0
  75. package/src/store/types.ts +0 -5
  76. package/src/utils/DBSyncManager.ts +1 -1
  77. package/src/{components/Message/utils → utils}/removeReservedFields.ts +7 -3
  78. package/src/utils/utils.ts +7 -6
  79. package/src/version.json +1 -1
  80. package/lib/commonjs/components/Message/utils/removeReservedFields.js.map +0 -1
  81. package/lib/commonjs/utils/pendingTaskUtils.js +0 -302
  82. package/lib/commonjs/utils/pendingTaskUtils.js.map +0 -1
  83. package/lib/module/components/Message/utils/removeReservedFields.js.map +0 -1
  84. package/lib/module/utils/pendingTaskUtils.js +0 -302
  85. package/lib/module/utils/pendingTaskUtils.js.map +0 -1
  86. package/lib/typescript/utils/pendingTaskUtils.d.ts +0 -13
  87. package/src/utils/pendingTaskUtils.ts +0 -131
@@ -1,131 +0,0 @@
1
- import type { AxiosError } from 'axios';
2
-
3
- import type { APIErrorResponse, StreamChat } from 'stream-chat';
4
-
5
- import { addPendingTask } from '../store/apis/addPendingTask';
6
- import { deletePendingTask } from '../store/apis/deletePendingTask';
7
- import { getPendingTasks } from '../store/apis/getPendingTasks';
8
- import type { PendingTask } from '../store/types';
9
- import type { DefaultStreamChatGenerics } from '../types/types';
10
-
11
- export const queueTask = async <
12
- StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
13
- >({
14
- client,
15
- task,
16
- }: {
17
- client: StreamChat<StreamChatGenerics>;
18
- task: PendingTask;
19
- }) => {
20
- const removeFromApi = addPendingTask(task);
21
-
22
- let response;
23
- try {
24
- response = await executeTask<StreamChatGenerics>({ client, task });
25
- } catch (e) {
26
- if ((e as AxiosError<APIErrorResponse>)?.response?.data?.code === 4) {
27
- // Error code 16 - message already exists
28
- // ignore
29
- } else {
30
- throw e;
31
- }
32
- }
33
-
34
- removeFromApi();
35
-
36
- return response;
37
- };
38
-
39
- const executeTask = async <
40
- StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
41
- >({
42
- client,
43
- task,
44
- }: {
45
- client: StreamChat<StreamChatGenerics>;
46
- task: PendingTask;
47
- }) => {
48
- const channel = client.channel(task.channelType, task.channelId);
49
-
50
- if (task.type === 'send-reaction') {
51
- return await channel.sendReaction(...task.payload);
52
- }
53
-
54
- if (task.type === 'delete-reaction') {
55
- return await channel.deleteReaction(...task.payload);
56
- }
57
-
58
- if (task.type === 'delete-message') {
59
- return await client.deleteMessage(...task.payload);
60
- }
61
-
62
- if (task.type === 'send-message') {
63
- const message = task.payload[0];
64
- if (message.attachments?.length) {
65
- for (let i = 0; i < message.attachments?.length; i++) {
66
- const attachment = message.attachments[i];
67
- if (attachment.type === 'image' && attachment.image_url) {
68
- const response = await channel.sendImage(attachment.image_url);
69
- attachment.image_url = response.file;
70
- }
71
-
72
- if (
73
- (attachment.type === 'file' ||
74
- attachment.type === 'audio' ||
75
- attachment.type === 'video') &&
76
- attachment.asset_url
77
- ) {
78
- const response = await channel.sendFile(attachment.asset_url);
79
- attachment.asset_url = response.file;
80
- }
81
- }
82
- }
83
-
84
- return await channel.sendMessage(...task.payload);
85
- }
86
-
87
- throw new Error('Invalid task type');
88
- };
89
-
90
- const restBeforeNextTask = () => new Promise((resolve) => setTimeout(resolve, 500));
91
- export const executePendingTasks = async <
92
- StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
93
- >(
94
- client: StreamChat<StreamChatGenerics>,
95
- ) => {
96
- const queue = getPendingTasks();
97
- for (const task of queue) {
98
- if (!task.id) continue;
99
-
100
- try {
101
- await executeTask<StreamChatGenerics>({
102
- client,
103
- task,
104
- });
105
- } catch (e) {
106
- if ((e as AxiosError<APIErrorResponse>)?.response?.data?.code === 4) {
107
- // Error code 16 - message already exists
108
- // ignore
109
- } else {
110
- throw e;
111
- }
112
- }
113
-
114
- deletePendingTask({
115
- id: task.id,
116
- });
117
- await restBeforeNextTask();
118
- }
119
- };
120
-
121
- export const dropPendingTasks = (conditions: { messageId: string }) => {
122
- const tasks = getPendingTasks(conditions);
123
-
124
- for (const task of tasks) {
125
- if (!task.id) continue;
126
-
127
- deletePendingTask({
128
- id: task.id,
129
- });
130
- }
131
- };