@amityco/ts-sdk 7.1.1-279cf96.0 → 7.1.1-295c780.0
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/@types/domains/channel.d.ts +1 -1
- package/dist/@types/domains/channel.d.ts.map +1 -1
- package/dist/channelRepository/utils/prepareChannelPayload.d.ts.map +1 -1
- package/dist/commentRepository/events/utils.d.ts.map +1 -1
- package/dist/index.cjs.js +64 -8
- package/dist/index.esm.js +64 -8
- package/dist/index.umd.js +1 -1
- package/package.json +1 -1
- package/src/@types/domains/channel.ts +1 -1
- package/src/channelRepository/utils/prepareChannelPayload.ts +5 -3
- package/src/commentRepository/events/utils.ts +73 -0
- package/src/messageRepository/events/onMessageCreated.ts +6 -6
package/package.json
CHANGED
|
@@ -75,15 +75,17 @@ const updateChannelUnread = ({
|
|
|
75
75
|
isMentioned = lastMentionedSegment > readToSegment;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
const cacheChannelUnread: Amity.ChannelUnread = {
|
|
79
79
|
channelId: channels[i].channelId,
|
|
80
80
|
lastSegment: channels[i].messageCount,
|
|
81
81
|
readToSegment,
|
|
82
82
|
lastMentionedSegment,
|
|
83
83
|
unreadCount,
|
|
84
84
|
isMentioned,
|
|
85
|
-
isDeleted: channels[i].isDeleted,
|
|
86
|
-
}
|
|
85
|
+
isDeleted: channels[i].isDeleted || false,
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
pushToCache(cacheKey, cacheChannelUnread);
|
|
87
89
|
}
|
|
88
90
|
};
|
|
89
91
|
|
|
@@ -53,6 +53,36 @@ export const createCommentEventSubscriber = (
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (['comment.deleted'].includes(event)) {
|
|
59
|
+
// NOTE: skip deleting comment to parent comment children if it's the same user since we use the local event to update instead.
|
|
60
|
+
if (event === 'comment.deleted' && comment.data.userId === client.userId) return;
|
|
61
|
+
|
|
62
|
+
if (comments[0].parentId) {
|
|
63
|
+
const parentComment = pullFromCache<Amity.InternalComment>([
|
|
64
|
+
'comment',
|
|
65
|
+
'get',
|
|
66
|
+
comments[0].parentId,
|
|
67
|
+
]);
|
|
68
|
+
|
|
69
|
+
if (parentComment?.data) {
|
|
70
|
+
// Remove deleted comment in parent childComment if still exists
|
|
71
|
+
if (parentComment.data.children.includes(comments[0].commentId)) {
|
|
72
|
+
const newParentComment = {
|
|
73
|
+
...parentComment.data,
|
|
74
|
+
childrenNumber: parentComment.data.childrenNumber - 1,
|
|
75
|
+
children: [
|
|
76
|
+
...new Set([
|
|
77
|
+
...parentComment.data.children.filter(id => id !== comments[0].commentId),
|
|
78
|
+
]),
|
|
79
|
+
],
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
pushToCache(['comment', 'get', comments[0].parentId], newParentComment);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
56
86
|
|
|
57
87
|
const queries = queryCache<Amity.InternalComment[]>(['comment', 'query'])?.filter(
|
|
58
88
|
({ key }) => (key[2] as Amity.QueryComments)?.referenceId === comment.data.referenceId,
|
|
@@ -135,6 +165,49 @@ export const createLocalCommentEventSubscriber = (
|
|
|
135
165
|
queries?.map(({ key, data }) => upsertInCache(key, data as any, { cachedAt: -1 }));
|
|
136
166
|
}
|
|
137
167
|
|
|
168
|
+
if (['local.comment.deleted'].includes(event)) {
|
|
169
|
+
if (comments[0].parentId) {
|
|
170
|
+
const parentComment = pullFromCache<Amity.InternalComment>([
|
|
171
|
+
'comment',
|
|
172
|
+
'get',
|
|
173
|
+
comments[0].parentId,
|
|
174
|
+
]);
|
|
175
|
+
|
|
176
|
+
if (parentComment?.data) {
|
|
177
|
+
// Remove deleted comment in parent childComment if still exists
|
|
178
|
+
if (parentComment.data.children.includes(comments[0].commentId)) {
|
|
179
|
+
const newParentComment = {
|
|
180
|
+
...parentComment.data,
|
|
181
|
+
childrenNumber: parentComment.data.childrenNumber - 1,
|
|
182
|
+
children: [
|
|
183
|
+
...new Set([
|
|
184
|
+
...parentComment.data.children.filter(id => id !== comments[0].commentId),
|
|
185
|
+
]),
|
|
186
|
+
],
|
|
187
|
+
};
|
|
188
|
+
pushToCache(['comment', 'get', comments[0].parentId], newParentComment);
|
|
189
|
+
|
|
190
|
+
setTimeout(() => {
|
|
191
|
+
// NOTE: This is workaround solution for emitting event not work properly.
|
|
192
|
+
fireEvent('comment.updated', {
|
|
193
|
+
comments: [newParentComment],
|
|
194
|
+
commentChildren: [],
|
|
195
|
+
files: [],
|
|
196
|
+
users: [],
|
|
197
|
+
communityUsers: [],
|
|
198
|
+
});
|
|
199
|
+
}, 200);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const queries = queryCache<Amity.InternalComment[]>(['comment', 'query'])?.filter(
|
|
205
|
+
({ key }) => (key[2] as Amity.QueryComments)?.referenceId === comment.data.referenceId,
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
queries?.map(({ key, data }) => upsertInCache(key, data as any, { cachedAt: -1 }));
|
|
209
|
+
}
|
|
210
|
+
|
|
138
211
|
callback(LinkedObject.comment(comment.data));
|
|
139
212
|
}
|
|
140
213
|
}
|
|
@@ -53,7 +53,7 @@ export const onMessageCreatedMqtt = (
|
|
|
53
53
|
!channelUnread ||
|
|
54
54
|
channelUnread.lastSegment >= message.segment ||
|
|
55
55
|
typeof channelUnread.readToSegment !== 'number' ||
|
|
56
|
-
typeof channelUnread.
|
|
56
|
+
typeof channelUnread.lastMentionedSegment !== 'number'
|
|
57
57
|
)
|
|
58
58
|
return;
|
|
59
59
|
|
|
@@ -67,16 +67,16 @@ export const onMessageCreatedMqtt = (
|
|
|
67
67
|
);
|
|
68
68
|
});
|
|
69
69
|
|
|
70
|
-
const
|
|
70
|
+
const lastMentionedSegment = isMentionedInMessage
|
|
71
71
|
? message.segment
|
|
72
|
-
: channelUnread.
|
|
72
|
+
: channelUnread.lastMentionedSegment;
|
|
73
73
|
|
|
74
|
-
const updatedChannelUnread = {
|
|
74
|
+
const updatedChannelUnread: Amity.ChannelUnread = {
|
|
75
75
|
...channelUnread,
|
|
76
76
|
lastSegment,
|
|
77
77
|
unreadCount: Math.max(lastSegment - channelUnread.readToSegment, 0),
|
|
78
|
-
|
|
79
|
-
isMentioned: !(channelUnread.readToSegment >=
|
|
78
|
+
lastMentionedSegment,
|
|
79
|
+
isMentioned: !(channelUnread.readToSegment >= lastMentionedSegment),
|
|
80
80
|
};
|
|
81
81
|
|
|
82
82
|
pushToCache(['channelUnread', 'get', message.channelId], updatedChannelUnread);
|