@amityco/ts-sdk 7.18.1-d0641289.0 → 7.18.1-eaf39c6c.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/channelRepository/utils/prepareChannelPayload.d.ts.map +1 -1
- package/dist/commentRepository/events/utils.d.ts.map +1 -1
- package/dist/index.cjs.js +216 -220
- package/dist/index.esm.js +216 -220
- package/dist/index.umd.js +1 -1
- package/dist/postRepository/api/getPost.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepareChannelPayload.d.ts","sourceRoot":"","sources":["../../../src/channelRepository/utils/prepareChannelPayload.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,4BAA4B,UAA6C,CAAC;AACvF,eAAO,MAAM,oBAAoB,aAAc,KAAK,MAAM,UAAU,EAAE,MAAM,CAAC,YAChC,CAAC;AAE9C,wBAAgB,cAAc,CAC5B,OAAO,EAAE,KAAK,CAAC,UAAU,EACzB,OAAO,GAAE;IAAE,uBAAuB,CAAC,EAAE,OAAO,CAAA;CAAsC,GACjF,KAAK,CAAC,qBAAqB,CAmB7B;AAED,eAAO,MAAM,qBAAqB,eACpB,MAAM,cAAc,YACvB;IAAE,uBAAuB,CAAC,EAAE,OAAO,CAAA;CAAE,SAO/C,CAAC;
|
|
1
|
+
{"version":3,"file":"prepareChannelPayload.d.ts","sourceRoot":"","sources":["../../../src/channelRepository/utils/prepareChannelPayload.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,4BAA4B,UAA6C,CAAC;AACvF,eAAO,MAAM,oBAAoB,aAAc,KAAK,MAAM,UAAU,EAAE,MAAM,CAAC,YAChC,CAAC;AAE9C,wBAAgB,cAAc,CAC5B,OAAO,EAAE,KAAK,CAAC,UAAU,EACzB,OAAO,GAAE;IAAE,uBAAuB,CAAC,EAAE,OAAO,CAAA;CAAsC,GACjF,KAAK,CAAC,qBAAqB,CAmB7B;AAED,eAAO,MAAM,qBAAqB,eACpB,MAAM,cAAc,YACvB;IAAE,uBAAuB,CAAC,EAAE,OAAO,CAAA;CAAE,SAO/C,CAAC;AAkDF,eAAO,MAAM,qBAAqB,eACpB,MAAM,cAAc,YACvB;IAAE,uBAAuB,CAAC,EAAE,OAAO,CAAA;CAAE,KAC7C,QAAQ,MAAM,uBAAuB,CA2DvC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/commentRepository/events/utils.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,4BAA4B,UAChC,MAAM,MAAM,iBAAiB,YAC1B,MAAM,QAAQ,CAAC,MAAM,eAAe,CAAC,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/commentRepository/events/utils.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,4BAA4B,UAChC,MAAM,MAAM,iBAAiB,YAC1B,MAAM,QAAQ,CAAC,MAAM,eAAe,CAAC,uBAoFhD,CAAC;AAEF,eAAO,MAAM,iCAAiC,UACrC,MAAM,KACX,MAAM,kBAAkB,EACxB,2BAA2B,GAAG,8BAA8B,CAC7D,YACS,MAAM,QAAQ,CAAC,MAAM,eAAe,CAAC,uBAqIhD,CAAC"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -5954,31 +5954,33 @@ const preUpdateChannelCache = (rawPayload, options = { isMessagePreviewUpdated:
|
|
|
5954
5954
|
const updateChannelUnread = ({ currentUserId, channels, channelUsers, }) => {
|
|
5955
5955
|
const channelsUnread = [];
|
|
5956
5956
|
for (let i = 0; i < channels.length; i += 1) {
|
|
5957
|
-
|
|
5958
|
-
|
|
5959
|
-
|
|
5960
|
-
|
|
5961
|
-
|
|
5962
|
-
|
|
5963
|
-
|
|
5964
|
-
|
|
5965
|
-
|
|
5966
|
-
|
|
5967
|
-
|
|
5968
|
-
|
|
5969
|
-
|
|
5970
|
-
|
|
5971
|
-
|
|
5972
|
-
|
|
5973
|
-
|
|
5974
|
-
|
|
5975
|
-
|
|
5976
|
-
|
|
5977
|
-
|
|
5978
|
-
|
|
5979
|
-
|
|
5957
|
+
if (isUnreadCountSupport(channels[i])) {
|
|
5958
|
+
const cacheKey = ['channelUnread', 'get', channels[i].channelId];
|
|
5959
|
+
const channelUser = channelUsers.find(channelUser => channelUser.channelId === channels[i].channelId && channelUser.userId === currentUserId);
|
|
5960
|
+
let unreadCount = 0;
|
|
5961
|
+
let readToSegment = null;
|
|
5962
|
+
let lastMentionedSegment = null;
|
|
5963
|
+
let isMentioned = false;
|
|
5964
|
+
if (channelUser) {
|
|
5965
|
+
readToSegment = channelUser.readToSegment;
|
|
5966
|
+
lastMentionedSegment = channelUser.lastMentionedSegment;
|
|
5967
|
+
unreadCount = Math.max(channels[i].messageCount - readToSegment, 0);
|
|
5968
|
+
isMentioned = lastMentionedSegment > readToSegment;
|
|
5969
|
+
}
|
|
5970
|
+
const cacheChannelUnread = {
|
|
5971
|
+
channelId: channels[i].channelId,
|
|
5972
|
+
lastSegment: channels[i].messageCount,
|
|
5973
|
+
readToSegment,
|
|
5974
|
+
lastMentionedSegment,
|
|
5975
|
+
unreadCount,
|
|
5976
|
+
isMentioned,
|
|
5977
|
+
isDeleted: channels[i].isDeleted || false,
|
|
5978
|
+
};
|
|
5979
|
+
pushToCache(cacheKey, cacheChannelUnread);
|
|
5980
|
+
channelsUnread.push(cacheChannelUnread);
|
|
5981
|
+
}
|
|
5982
|
+
fireEvent('local.channelUnread.updated', channelsUnread);
|
|
5980
5983
|
}
|
|
5981
|
-
fireEvent('local.channelUnread.updated', channelsUnread);
|
|
5982
5984
|
};
|
|
5983
5985
|
const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpdated: true }) => {
|
|
5984
5986
|
const client = getActiveClient();
|
|
@@ -17140,6 +17142,195 @@ getMessage$1.locally = (messageId) => {
|
|
|
17140
17142
|
};
|
|
17141
17143
|
};
|
|
17142
17144
|
|
|
17145
|
+
class ResetTask {
|
|
17146
|
+
constructor(postId, latestCreatedAt, serverCommentCount) {
|
|
17147
|
+
this.postId = postId;
|
|
17148
|
+
this.latestCreatedAt = latestCreatedAt;
|
|
17149
|
+
this.serverCommentCount = serverCommentCount;
|
|
17150
|
+
}
|
|
17151
|
+
}
|
|
17152
|
+
|
|
17153
|
+
// Task to track comment creation
|
|
17154
|
+
class CreateTask {
|
|
17155
|
+
constructor(postId, commentId, createdAt) {
|
|
17156
|
+
this.postId = postId;
|
|
17157
|
+
this.commentId = commentId;
|
|
17158
|
+
this.createdAt = createdAt;
|
|
17159
|
+
}
|
|
17160
|
+
}
|
|
17161
|
+
|
|
17162
|
+
// Task to track comment deletion
|
|
17163
|
+
class DeleteTask {
|
|
17164
|
+
constructor(postId, commentId) {
|
|
17165
|
+
this.postId = postId;
|
|
17166
|
+
this.commentId = commentId;
|
|
17167
|
+
}
|
|
17168
|
+
}
|
|
17169
|
+
|
|
17170
|
+
class CommentChange {
|
|
17171
|
+
constructor(latestCreatedAt, serverCommentCount) {
|
|
17172
|
+
this.latestCommentCreatedAt = latestCreatedAt;
|
|
17173
|
+
this.serverCommentCount = serverCommentCount;
|
|
17174
|
+
this.createdCommentIds = new Set();
|
|
17175
|
+
this.deletedCommentIds = new Set();
|
|
17176
|
+
}
|
|
17177
|
+
}
|
|
17178
|
+
|
|
17179
|
+
class PostCommentCountEngine {
|
|
17180
|
+
constructor() {
|
|
17181
|
+
this.isProcessing = false;
|
|
17182
|
+
this.tasks = [];
|
|
17183
|
+
this.commentChangeTracker = new Map();
|
|
17184
|
+
}
|
|
17185
|
+
queueCommentChangeTask(task) {
|
|
17186
|
+
this.tasks.push(task);
|
|
17187
|
+
if (!this.isProcessing) {
|
|
17188
|
+
this.processCommentChangeTask();
|
|
17189
|
+
}
|
|
17190
|
+
}
|
|
17191
|
+
processCommentChangeTask() {
|
|
17192
|
+
if (this.isProcessing) {
|
|
17193
|
+
return;
|
|
17194
|
+
}
|
|
17195
|
+
this.isProcessing = true;
|
|
17196
|
+
if (this.tasks.length === 0) {
|
|
17197
|
+
this.isProcessing = false;
|
|
17198
|
+
return;
|
|
17199
|
+
}
|
|
17200
|
+
// Process in capped batches, coalescing updates
|
|
17201
|
+
const batch = this.tasks.splice(0, PostCommentCountEngine.BATCH_SIZE);
|
|
17202
|
+
const modifiedPostIds = new Set();
|
|
17203
|
+
batch.forEach(task => {
|
|
17204
|
+
let modified = false;
|
|
17205
|
+
if (task instanceof ResetTask) {
|
|
17206
|
+
modified = this.processResetTaskInternal(task);
|
|
17207
|
+
}
|
|
17208
|
+
else if (task instanceof CreateTask) {
|
|
17209
|
+
modified = this.processCreateTaskInternal(task);
|
|
17210
|
+
}
|
|
17211
|
+
else if (task instanceof DeleteTask) {
|
|
17212
|
+
modified = this.processDeleteTaskInternal(task);
|
|
17213
|
+
}
|
|
17214
|
+
if (modified) {
|
|
17215
|
+
modifiedPostIds.add(task.postId);
|
|
17216
|
+
}
|
|
17217
|
+
});
|
|
17218
|
+
// Publish one update per modified post
|
|
17219
|
+
modifiedPostIds.forEach(postId => {
|
|
17220
|
+
const count = this.computeCommentCount(postId);
|
|
17221
|
+
PostCommentCountEngine.publishUpdate(postId, count);
|
|
17222
|
+
});
|
|
17223
|
+
this.isProcessing = false;
|
|
17224
|
+
// Recurse if more tasks remain
|
|
17225
|
+
if (this.tasks.length > 0) {
|
|
17226
|
+
this.processCommentChangeTask();
|
|
17227
|
+
}
|
|
17228
|
+
}
|
|
17229
|
+
processResetTaskInternal(task) {
|
|
17230
|
+
// Always creates/overwrites tracker
|
|
17231
|
+
this.commentChangeTracker.set(task.postId, new CommentChange(task.latestCreatedAt, task.serverCommentCount));
|
|
17232
|
+
return true;
|
|
17233
|
+
}
|
|
17234
|
+
processCreateTaskInternal(task) {
|
|
17235
|
+
const tracker = this.commentChangeTracker.get(task.postId);
|
|
17236
|
+
if (!tracker)
|
|
17237
|
+
return false; // No tracker, skip
|
|
17238
|
+
if (tracker.createdCommentIds.has(task.commentId))
|
|
17239
|
+
return false; // Deduplication
|
|
17240
|
+
if (task.createdAt <= tracker.latestCommentCreatedAt)
|
|
17241
|
+
return false; // Timestamp filtering
|
|
17242
|
+
tracker.createdCommentIds.add(task.commentId);
|
|
17243
|
+
return true;
|
|
17244
|
+
}
|
|
17245
|
+
processDeleteTaskInternal(task) {
|
|
17246
|
+
const tracker = this.commentChangeTracker.get(task.postId);
|
|
17247
|
+
if (!tracker)
|
|
17248
|
+
return false; // No tracker, skip
|
|
17249
|
+
if (tracker.deletedCommentIds.has(task.commentId))
|
|
17250
|
+
return false; // Deduplication
|
|
17251
|
+
tracker.deletedCommentIds.add(task.commentId);
|
|
17252
|
+
return true;
|
|
17253
|
+
}
|
|
17254
|
+
computeCommentCount(postId) {
|
|
17255
|
+
const tracker = this.commentChangeTracker.get(postId);
|
|
17256
|
+
if (!tracker)
|
|
17257
|
+
return 0;
|
|
17258
|
+
const count = tracker.serverCommentCount + tracker.createdCommentIds.size - tracker.deletedCommentIds.size;
|
|
17259
|
+
return Math.max(0, count);
|
|
17260
|
+
}
|
|
17261
|
+
static publishUpdate(postId, newCount) {
|
|
17262
|
+
var _a;
|
|
17263
|
+
const queryKey = ['post', 'get', postId];
|
|
17264
|
+
mergeInCache(queryKey, {
|
|
17265
|
+
localCommentCount: newCount,
|
|
17266
|
+
});
|
|
17267
|
+
const postPayload = (_a = pullFromCache(queryKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
17268
|
+
if (!postPayload)
|
|
17269
|
+
return;
|
|
17270
|
+
fireEvent('local.post.updated', {
|
|
17271
|
+
posts: [postPayload],
|
|
17272
|
+
});
|
|
17273
|
+
}
|
|
17274
|
+
}
|
|
17275
|
+
PostCommentCountEngine.BATCH_SIZE = 50;
|
|
17276
|
+
let instance;
|
|
17277
|
+
var PostCommentCountEngine$1 = {
|
|
17278
|
+
getInstance: () => {
|
|
17279
|
+
if (!instance) {
|
|
17280
|
+
instance = new PostCommentCountEngine();
|
|
17281
|
+
}
|
|
17282
|
+
return instance;
|
|
17283
|
+
},
|
|
17284
|
+
};
|
|
17285
|
+
|
|
17286
|
+
const updateStreamReferences = (streams, streamId, postId) => {
|
|
17287
|
+
if (!streamId)
|
|
17288
|
+
return streams;
|
|
17289
|
+
return streams.map(stream => stream.streamId === streamId
|
|
17290
|
+
? Object.assign(Object.assign({}, stream), { referenceType: 'post', referenceId: postId, postId }) : stream);
|
|
17291
|
+
};
|
|
17292
|
+
const preparePostPayload = (payload) => {
|
|
17293
|
+
const { posts: postsData, postChildren, videoStreamings } = payload, postPayload = __rest(payload, ["posts", "postChildren", "videoStreamings"]);
|
|
17294
|
+
// Unpack community payload by mapping payload field to postSetting value.
|
|
17295
|
+
const communitiesWithPostSetting = addPostSetting({ communities: postPayload.communities });
|
|
17296
|
+
// map users with community
|
|
17297
|
+
const mappedCommunityUsers = postPayload.communityUsers.map(communityUser => {
|
|
17298
|
+
const user = postPayload.users.find(user => user.userId === communityUser.userId);
|
|
17299
|
+
return Object.assign(Object.assign({}, communityUser), { user });
|
|
17300
|
+
});
|
|
17301
|
+
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
17302
|
+
let mappedNewStream = [];
|
|
17303
|
+
// feed type
|
|
17304
|
+
const posts = postsData.map(post => {
|
|
17305
|
+
var _a, _b, _c, _d;
|
|
17306
|
+
const feedType = (_a = postPayload.feeds.find(feed => feed.feedId === post.feedId)) === null || _a === void 0 ? void 0 : _a.feedType;
|
|
17307
|
+
const childPosts = payload.postChildren.filter(children => children.parentPostId === post.postId);
|
|
17308
|
+
if (childPosts.length > 0 && isAmityLivestreamPost(childPosts[0])) {
|
|
17309
|
+
mappedNewStream = updateStreamReferences(videoStreamings, (_b = childPosts[0].data) === null || _b === void 0 ? void 0 : _b.streamId, post.postId);
|
|
17310
|
+
}
|
|
17311
|
+
// --- Computed Comment Count: ResetTask integration ---
|
|
17312
|
+
// Find all comments for this post (referenceType === 'post' && referenceId === postId)
|
|
17313
|
+
const allComments = (payload.comments || []).filter((c) => c.referenceType === 'post' && c.referenceId === post.postId);
|
|
17314
|
+
// Compute latestCreatedAt
|
|
17315
|
+
const latestCreatedAt = allComments.length === 0
|
|
17316
|
+
? new Date().toISOString()
|
|
17317
|
+
: allComments
|
|
17318
|
+
.map(c => c.createdAt)
|
|
17319
|
+
.sort()
|
|
17320
|
+
.at(-1);
|
|
17321
|
+
// Queue ResetTask for this post
|
|
17322
|
+
PostCommentCountEngine$1.getInstance().queueCommentChangeTask(new ResetTask(post.postId, latestCreatedAt, (_c = post.commentsCount) !== null && _c !== void 0 ? _c : 0));
|
|
17323
|
+
return Object.assign(Object.assign({}, post), { childPosts,
|
|
17324
|
+
feedType, localCommentCount: (_d = post.localCommentCount) !== null && _d !== void 0 ? _d : post.commentsCount, pinnedProductId: post === null || post === void 0 ? void 0 : post.pinnedProductId });
|
|
17325
|
+
});
|
|
17326
|
+
return Object.assign(Object.assign({}, postPayload), { postChildren, videoStreamings: mappedNewStream, posts, communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
17327
|
+
};
|
|
17328
|
+
const prepareSemanticSearchPostPayload = (_a) => {
|
|
17329
|
+
var { searchResult, polls } = _a, postPayload = __rest(_a, ["searchResult", "polls"]);
|
|
17330
|
+
const processedPostPayload = preparePostPayload(postPayload);
|
|
17331
|
+
return Object.assign(Object.assign({}, processedPostPayload), { polls });
|
|
17332
|
+
};
|
|
17333
|
+
|
|
17143
17334
|
/**
|
|
17144
17335
|
* ```js
|
|
17145
17336
|
* import { getPost } from '@amityco/ts-sdk'
|
|
@@ -17170,7 +17361,7 @@ const getPost$2 = async (postId) => {
|
|
|
17170
17361
|
}
|
|
17171
17362
|
throw error;
|
|
17172
17363
|
}
|
|
17173
|
-
const data =
|
|
17364
|
+
const data = preparePostPayload(payload);
|
|
17174
17365
|
const cachedAt = client.cache && Date.now();
|
|
17175
17366
|
if (client.cache)
|
|
17176
17367
|
ingestInCache(data, { cachedAt });
|
|
@@ -17588,195 +17779,6 @@ removeReaction.optimistically = (referenceType, referenceId, reactionName) => {
|
|
|
17588
17779
|
return !((_d = reaction === null || reaction === void 0 ? void 0 : reaction.myReactions) === null || _d === void 0 ? void 0 : _d.includes(reactionName));
|
|
17589
17780
|
};
|
|
17590
17781
|
|
|
17591
|
-
class ResetTask {
|
|
17592
|
-
constructor(postId, latestCreatedAt, serverCommentCount) {
|
|
17593
|
-
this.postId = postId;
|
|
17594
|
-
this.latestCreatedAt = latestCreatedAt;
|
|
17595
|
-
this.serverCommentCount = serverCommentCount;
|
|
17596
|
-
}
|
|
17597
|
-
}
|
|
17598
|
-
|
|
17599
|
-
// Task to track comment creation
|
|
17600
|
-
class CreateTask {
|
|
17601
|
-
constructor(postId, commentId, createdAt) {
|
|
17602
|
-
this.postId = postId;
|
|
17603
|
-
this.commentId = commentId;
|
|
17604
|
-
this.createdAt = createdAt;
|
|
17605
|
-
}
|
|
17606
|
-
}
|
|
17607
|
-
|
|
17608
|
-
// Task to track comment deletion
|
|
17609
|
-
class DeleteTask {
|
|
17610
|
-
constructor(postId, commentId) {
|
|
17611
|
-
this.postId = postId;
|
|
17612
|
-
this.commentId = commentId;
|
|
17613
|
-
}
|
|
17614
|
-
}
|
|
17615
|
-
|
|
17616
|
-
class CommentChange {
|
|
17617
|
-
constructor(latestCreatedAt, serverCommentCount) {
|
|
17618
|
-
this.latestCommentCreatedAt = latestCreatedAt;
|
|
17619
|
-
this.serverCommentCount = serverCommentCount;
|
|
17620
|
-
this.createdCommentIds = new Set();
|
|
17621
|
-
this.deletedCommentIds = new Set();
|
|
17622
|
-
}
|
|
17623
|
-
}
|
|
17624
|
-
|
|
17625
|
-
class PostCommentCountEngine {
|
|
17626
|
-
constructor() {
|
|
17627
|
-
this.isProcessing = false;
|
|
17628
|
-
this.tasks = [];
|
|
17629
|
-
this.commentChangeTracker = new Map();
|
|
17630
|
-
}
|
|
17631
|
-
queueCommentChangeTask(task) {
|
|
17632
|
-
this.tasks.push(task);
|
|
17633
|
-
if (!this.isProcessing) {
|
|
17634
|
-
this.processCommentChangeTask();
|
|
17635
|
-
}
|
|
17636
|
-
}
|
|
17637
|
-
processCommentChangeTask() {
|
|
17638
|
-
if (this.isProcessing) {
|
|
17639
|
-
return;
|
|
17640
|
-
}
|
|
17641
|
-
this.isProcessing = true;
|
|
17642
|
-
if (this.tasks.length === 0) {
|
|
17643
|
-
this.isProcessing = false;
|
|
17644
|
-
return;
|
|
17645
|
-
}
|
|
17646
|
-
// Process in capped batches, coalescing updates
|
|
17647
|
-
const batch = this.tasks.splice(0, PostCommentCountEngine.BATCH_SIZE);
|
|
17648
|
-
const modifiedPostIds = new Set();
|
|
17649
|
-
batch.forEach(task => {
|
|
17650
|
-
let modified = false;
|
|
17651
|
-
if (task instanceof ResetTask) {
|
|
17652
|
-
modified = this.processResetTaskInternal(task);
|
|
17653
|
-
}
|
|
17654
|
-
else if (task instanceof CreateTask) {
|
|
17655
|
-
modified = this.processCreateTaskInternal(task);
|
|
17656
|
-
}
|
|
17657
|
-
else if (task instanceof DeleteTask) {
|
|
17658
|
-
modified = this.processDeleteTaskInternal(task);
|
|
17659
|
-
}
|
|
17660
|
-
if (modified) {
|
|
17661
|
-
modifiedPostIds.add(task.postId);
|
|
17662
|
-
}
|
|
17663
|
-
});
|
|
17664
|
-
// Publish one update per modified post
|
|
17665
|
-
modifiedPostIds.forEach(postId => {
|
|
17666
|
-
const count = this.computeCommentCount(postId);
|
|
17667
|
-
PostCommentCountEngine.publishUpdate(postId, count);
|
|
17668
|
-
});
|
|
17669
|
-
this.isProcessing = false;
|
|
17670
|
-
// Recurse if more tasks remain
|
|
17671
|
-
if (this.tasks.length > 0) {
|
|
17672
|
-
this.processCommentChangeTask();
|
|
17673
|
-
}
|
|
17674
|
-
}
|
|
17675
|
-
processResetTaskInternal(task) {
|
|
17676
|
-
// Always creates/overwrites tracker
|
|
17677
|
-
this.commentChangeTracker.set(task.postId, new CommentChange(task.latestCreatedAt, task.serverCommentCount));
|
|
17678
|
-
return true;
|
|
17679
|
-
}
|
|
17680
|
-
processCreateTaskInternal(task) {
|
|
17681
|
-
const tracker = this.commentChangeTracker.get(task.postId);
|
|
17682
|
-
if (!tracker)
|
|
17683
|
-
return false; // No tracker, skip
|
|
17684
|
-
if (tracker.createdCommentIds.has(task.commentId))
|
|
17685
|
-
return false; // Deduplication
|
|
17686
|
-
if (task.createdAt <= tracker.latestCommentCreatedAt)
|
|
17687
|
-
return false; // Timestamp filtering
|
|
17688
|
-
tracker.createdCommentIds.add(task.commentId);
|
|
17689
|
-
return true;
|
|
17690
|
-
}
|
|
17691
|
-
processDeleteTaskInternal(task) {
|
|
17692
|
-
const tracker = this.commentChangeTracker.get(task.postId);
|
|
17693
|
-
if (!tracker)
|
|
17694
|
-
return false; // No tracker, skip
|
|
17695
|
-
if (tracker.deletedCommentIds.has(task.commentId))
|
|
17696
|
-
return false; // Deduplication
|
|
17697
|
-
tracker.deletedCommentIds.add(task.commentId);
|
|
17698
|
-
return true;
|
|
17699
|
-
}
|
|
17700
|
-
computeCommentCount(postId) {
|
|
17701
|
-
const tracker = this.commentChangeTracker.get(postId);
|
|
17702
|
-
if (!tracker)
|
|
17703
|
-
return 0;
|
|
17704
|
-
const count = tracker.serverCommentCount + tracker.createdCommentIds.size - tracker.deletedCommentIds.size;
|
|
17705
|
-
return Math.max(0, count);
|
|
17706
|
-
}
|
|
17707
|
-
static publishUpdate(postId, newCount) {
|
|
17708
|
-
var _a;
|
|
17709
|
-
const queryKey = ['post', 'get', postId];
|
|
17710
|
-
mergeInCache(queryKey, {
|
|
17711
|
-
localCommentCount: newCount,
|
|
17712
|
-
});
|
|
17713
|
-
const postPayload = (_a = pullFromCache(queryKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
17714
|
-
if (!postPayload)
|
|
17715
|
-
return;
|
|
17716
|
-
fireEvent('local.post.updated', {
|
|
17717
|
-
posts: [postPayload],
|
|
17718
|
-
});
|
|
17719
|
-
}
|
|
17720
|
-
}
|
|
17721
|
-
PostCommentCountEngine.BATCH_SIZE = 50;
|
|
17722
|
-
let instance;
|
|
17723
|
-
var PostCommentCountEngine$1 = {
|
|
17724
|
-
getInstance: () => {
|
|
17725
|
-
if (!instance) {
|
|
17726
|
-
instance = new PostCommentCountEngine();
|
|
17727
|
-
}
|
|
17728
|
-
return instance;
|
|
17729
|
-
},
|
|
17730
|
-
};
|
|
17731
|
-
|
|
17732
|
-
const updateStreamReferences = (streams, streamId, postId) => {
|
|
17733
|
-
if (!streamId)
|
|
17734
|
-
return streams;
|
|
17735
|
-
return streams.map(stream => stream.streamId === streamId
|
|
17736
|
-
? Object.assign(Object.assign({}, stream), { referenceType: 'post', referenceId: postId, postId }) : stream);
|
|
17737
|
-
};
|
|
17738
|
-
const preparePostPayload = (payload) => {
|
|
17739
|
-
const { posts: postsData, postChildren, videoStreamings } = payload, postPayload = __rest(payload, ["posts", "postChildren", "videoStreamings"]);
|
|
17740
|
-
// Unpack community payload by mapping payload field to postSetting value.
|
|
17741
|
-
const communitiesWithPostSetting = addPostSetting({ communities: postPayload.communities });
|
|
17742
|
-
// map users with community
|
|
17743
|
-
const mappedCommunityUsers = postPayload.communityUsers.map(communityUser => {
|
|
17744
|
-
const user = postPayload.users.find(user => user.userId === communityUser.userId);
|
|
17745
|
-
return Object.assign(Object.assign({}, communityUser), { user });
|
|
17746
|
-
});
|
|
17747
|
-
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
17748
|
-
let mappedNewStream = [];
|
|
17749
|
-
// feed type
|
|
17750
|
-
const posts = postsData.map(post => {
|
|
17751
|
-
var _a, _b, _c, _d;
|
|
17752
|
-
const feedType = (_a = postPayload.feeds.find(feed => feed.feedId === post.feedId)) === null || _a === void 0 ? void 0 : _a.feedType;
|
|
17753
|
-
const childPosts = payload.postChildren.filter(children => children.parentPostId === post.postId);
|
|
17754
|
-
if (childPosts.length > 0 && isAmityLivestreamPost(childPosts[0])) {
|
|
17755
|
-
mappedNewStream = updateStreamReferences(videoStreamings, (_b = childPosts[0].data) === null || _b === void 0 ? void 0 : _b.streamId, post.postId);
|
|
17756
|
-
}
|
|
17757
|
-
// --- Computed Comment Count: ResetTask integration ---
|
|
17758
|
-
// Find all comments for this post (referenceType === 'post' && referenceId === postId)
|
|
17759
|
-
const allComments = (payload.comments || []).filter((c) => c.referenceType === 'post' && c.referenceId === post.postId);
|
|
17760
|
-
// Compute latestCreatedAt
|
|
17761
|
-
const latestCreatedAt = allComments.length === 0
|
|
17762
|
-
? new Date().toISOString()
|
|
17763
|
-
: allComments
|
|
17764
|
-
.map(c => c.createdAt)
|
|
17765
|
-
.sort()
|
|
17766
|
-
.at(-1);
|
|
17767
|
-
// Queue ResetTask for this post
|
|
17768
|
-
PostCommentCountEngine$1.getInstance().queueCommentChangeTask(new ResetTask(post.postId, latestCreatedAt, (_c = post.commentsCount) !== null && _c !== void 0 ? _c : 0));
|
|
17769
|
-
return Object.assign(Object.assign({}, post), { childPosts,
|
|
17770
|
-
feedType, localCommentCount: (_d = post.localCommentCount) !== null && _d !== void 0 ? _d : post.commentsCount, pinnedProductId: post === null || post === void 0 ? void 0 : post.pinnedProductId });
|
|
17771
|
-
});
|
|
17772
|
-
return Object.assign(Object.assign({}, postPayload), { postChildren, videoStreamings: mappedNewStream, posts, communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
17773
|
-
};
|
|
17774
|
-
const prepareSemanticSearchPostPayload = (_a) => {
|
|
17775
|
-
var { searchResult, polls } = _a, postPayload = __rest(_a, ["searchResult", "polls"]);
|
|
17776
|
-
const processedPostPayload = preparePostPayload(postPayload);
|
|
17777
|
-
return Object.assign(Object.assign({}, processedPostPayload), { polls });
|
|
17778
|
-
};
|
|
17779
|
-
|
|
17780
17782
|
const processDeleteChildPost = (payload) => {
|
|
17781
17783
|
var _a;
|
|
17782
17784
|
const post = payload.posts[0];
|
|
@@ -18094,9 +18096,6 @@ const createCommentEventSubscriber = (event, callback) => {
|
|
|
18094
18096
|
comments[0].commentId,
|
|
18095
18097
|
]);
|
|
18096
18098
|
if (['comment.created'].includes(event)) {
|
|
18097
|
-
// NOTE: skip adding comment to parent comment children if it's the same user since we use the local event to update instead.
|
|
18098
|
-
if (event === 'comment.created' && comment.data.userId === client.userId)
|
|
18099
|
-
return;
|
|
18100
18099
|
if (comments[0].parentId) {
|
|
18101
18100
|
const parentComment = pullFromCache([
|
|
18102
18101
|
'comment',
|
|
@@ -18112,9 +18111,6 @@ const createCommentEventSubscriber = (event, callback) => {
|
|
|
18112
18111
|
}
|
|
18113
18112
|
}
|
|
18114
18113
|
if (['comment.deleted'].includes(event)) {
|
|
18115
|
-
// NOTE: skip deleting comment to parent comment children if it's the same user since we use the local event to update instead.
|
|
18116
|
-
if (event === 'comment.deleted' && comment.data.userId === client.userId)
|
|
18117
|
-
return;
|
|
18118
18114
|
if (comments[0].parentId) {
|
|
18119
18115
|
const parentComment = pullFromCache([
|
|
18120
18116
|
'comment',
|