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.
- package/lib/commonjs/components/Attachment/Gallery.js +21 -16
- package/lib/commonjs/components/Attachment/Gallery.js.map +1 -1
- package/lib/commonjs/components/Attachment/GalleryImage.js +3 -3
- package/lib/commonjs/components/Attachment/GalleryImage.js.map +1 -1
- package/lib/commonjs/components/Channel/Channel.js +34 -30
- package/lib/commonjs/components/Channel/Channel.js.map +1 -1
- package/lib/commonjs/components/ChannelList/hooks/usePaginatedChannels.js +5 -1
- package/lib/commonjs/components/ChannelList/hooks/usePaginatedChannels.js.map +1 -1
- package/lib/commonjs/components/Message/hooks/useMessageActions.js +2 -2
- package/lib/commonjs/components/Message/hooks/useMessageActions.js.map +1 -1
- package/lib/commonjs/components/MessageInput/FileUploadPreview.js +18 -21
- package/lib/commonjs/components/MessageInput/FileUploadPreview.js.map +1 -1
- package/lib/commonjs/components/MessageInput/ImageUploadPreview.js +7 -32
- package/lib/commonjs/components/MessageInput/ImageUploadPreview.js.map +1 -1
- package/lib/commonjs/components/index.js +1 -1
- package/lib/commonjs/components/index.js.map +1 -1
- package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js +128 -89
- package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js.map +1 -1
- package/lib/commonjs/contexts/messageInputContext/hooks/useMessageDetailsForState.js +1 -0
- package/lib/commonjs/contexts/messageInputContext/hooks/useMessageDetailsForState.js.map +1 -1
- package/lib/commonjs/utils/DBSyncManager.js +16 -16
- package/lib/commonjs/utils/DBSyncManager.js.map +1 -1
- package/lib/commonjs/{components/Message/utils → utils}/removeReservedFields.js +1 -1
- package/lib/commonjs/utils/removeReservedFields.js.map +1 -0
- package/lib/commonjs/utils/utils.js +2 -2
- package/lib/commonjs/utils/utils.js.map +1 -1
- package/lib/commonjs/version.json +1 -1
- package/lib/module/components/Attachment/Gallery.js +21 -16
- package/lib/module/components/Attachment/Gallery.js.map +1 -1
- package/lib/module/components/Attachment/GalleryImage.js +3 -3
- package/lib/module/components/Attachment/GalleryImage.js.map +1 -1
- package/lib/module/components/Channel/Channel.js +34 -30
- package/lib/module/components/Channel/Channel.js.map +1 -1
- package/lib/module/components/ChannelList/hooks/usePaginatedChannels.js +5 -1
- package/lib/module/components/ChannelList/hooks/usePaginatedChannels.js.map +1 -1
- package/lib/module/components/Message/hooks/useMessageActions.js +2 -2
- package/lib/module/components/Message/hooks/useMessageActions.js.map +1 -1
- package/lib/module/components/MessageInput/FileUploadPreview.js +18 -21
- package/lib/module/components/MessageInput/FileUploadPreview.js.map +1 -1
- package/lib/module/components/MessageInput/ImageUploadPreview.js +7 -32
- package/lib/module/components/MessageInput/ImageUploadPreview.js.map +1 -1
- package/lib/module/components/index.js +1 -1
- package/lib/module/components/index.js.map +1 -1
- package/lib/module/contexts/messageInputContext/MessageInputContext.js +128 -89
- package/lib/module/contexts/messageInputContext/MessageInputContext.js.map +1 -1
- package/lib/module/contexts/messageInputContext/hooks/useMessageDetailsForState.js +1 -0
- package/lib/module/contexts/messageInputContext/hooks/useMessageDetailsForState.js.map +1 -1
- package/lib/module/utils/DBSyncManager.js +16 -16
- package/lib/module/utils/DBSyncManager.js.map +1 -1
- package/lib/module/{components/Message/utils → utils}/removeReservedFields.js +1 -1
- package/lib/module/utils/removeReservedFields.js.map +1 -0
- package/lib/module/utils/utils.js +2 -2
- package/lib/module/utils/utils.js.map +1 -1
- package/lib/module/version.json +1 -1
- package/lib/typescript/components/MessageInput/FileUploadPreview.d.ts +1 -1
- package/lib/typescript/components/MessageInput/ImageUploadPreview.d.ts +1 -1
- package/lib/typescript/components/index.d.ts +1 -1
- package/lib/typescript/store/mappers/mapTaskToStorable.d.ts +0 -8
- package/lib/typescript/store/types.d.ts +0 -4
- package/lib/typescript/utils/DBSyncManager.d.ts +1 -1
- package/lib/typescript/{components/Message/utils → utils}/removeReservedFields.d.ts +2 -2
- package/lib/typescript/utils/utils.d.ts +1 -1
- package/package.json +1 -1
- package/src/components/Attachment/Gallery.tsx +5 -1
- package/src/components/Attachment/GalleryImage.tsx +2 -0
- package/src/components/Channel/Channel.tsx +12 -11
- package/src/components/ChannelList/hooks/usePaginatedChannels.ts +6 -4
- package/src/components/Message/hooks/useMessageActions.tsx +1 -1
- package/src/components/MessageInput/FileUploadPreview.tsx +4 -5
- package/src/components/MessageInput/ImageUploadPreview.tsx +10 -35
- package/src/components/index.ts +1 -1
- package/src/contexts/messageInputContext/MessageInputContext.tsx +94 -75
- package/src/contexts/messageInputContext/__tests__/__snapshots__/sendMessage.test.tsx.snap +0 -3
- package/src/contexts/messageInputContext/hooks/useMessageDetailsForState.ts +1 -0
- package/src/store/types.ts +0 -5
- package/src/utils/DBSyncManager.ts +1 -1
- package/src/{components/Message/utils → utils}/removeReservedFields.ts +7 -3
- package/src/utils/utils.ts +7 -6
- package/src/version.json +1 -1
- package/lib/commonjs/components/Message/utils/removeReservedFields.js.map +0 -1
- package/lib/commonjs/utils/pendingTaskUtils.js +0 -302
- package/lib/commonjs/utils/pendingTaskUtils.js.map +0 -1
- package/lib/module/components/Message/utils/removeReservedFields.js.map +0 -1
- package/lib/module/utils/pendingTaskUtils.js +0 -302
- package/lib/module/utils/pendingTaskUtils.js.map +0 -1
- package/lib/typescript/utils/pendingTaskUtils.d.ts +0 -13
- 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
|
-
};
|