@amityco/ts-sdk-react-native 7.20.1-7e58953.0 → 7.21.1-3f070be.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.
@@ -18,7 +18,9 @@ declare global {
18
18
  targetType: 'community' | 'user' | 'content';
19
19
  links?: Amity.Link[];
20
20
  } & Amity.Relationship<CommentReferenceType> & Amity.Content<T> & Amity.Metadata & Amity.Flaggable & Amity.Reactable & Amity.Timestamps & Amity.SoftDelete & Amity.Subscribable & Amity.Mentionable<'user'>;
21
- type InternalComment<T extends CommentContentType = any> = RawComment<T>;
21
+ type InternalComment<T extends CommentContentType = any> = RawComment<T> & {
22
+ syncState?: Amity.SyncState;
23
+ };
22
24
  type CommentTarget = {
23
25
  type: InternalComment['targetType'] | 'unknown';
24
26
  communityId?: Amity.Community['communityId'];
@@ -1 +1 @@
1
- {"version":3,"file":"comment.d.ts","sourceRoot":"","sources":["../../../src/@types/domains/comment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC;AAEV,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,KAAK,CAAC;QACd,KAAK,kBAAkB,GAAG,MAAM,CAAC;QACjC,KAAK,oBAAoB,GAAG,SAAS,GAAG,MAAM,GAAG,OAAO,CAAC;QAEzD,KAAK,iBAAiB,GAClB,SAAS,GACT,UAAU,GACV,UAAU,GACV,UAAU,GACV,WAAW,GACX,aAAa,GACb,iBAAiB,GACjB,mBAAmB,CAAC;QAExB,KAAK,UAAU,CAAC,CAAC,SAAS,kBAAkB,GAAG,GAAG,IAAI;YACpD,SAAS,EAAE,MAAM,CAAC;YAClB,MAAM,EAAE,MAAM,CAAC;YACf,QAAQ,CAAC,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;YACnC,MAAM,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;YAChC,cAAc,EAAE,MAAM,CAAC;YACvB,QAAQ,EAAE,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;YAC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aAAa,EAAE,QAAQ,GAAG,MAAM,CAAC,GAAG;YACvC,MAAM,CAAC,EAAE,aAAa,GAAG,cAAc,CAAC;SACzC,CACF,CAAC;QAEF,KAAK,0BAA0B,GAAG,KAAK,CAAC,mBAAmB,CACzD,KAAK,CAAC,eAAe,CAAC,WAAW,CAAC,EAClC;YAAE,IAAI,CAAC,EAAE,KAAK,CAAC,KAAK,GAAG,SAAS,CAAC;YAAC,KAAK,CAAC,EAAE,MAAM,CAAA;SAAE,CACnD,CAAC;KACH;CACF"}
@@ -1,3 +1,4 @@
1
+ declare type CreateCommentBundle = Pick<Amity.Comment<Amity.CommentContentType>, 'data' | 'referenceType' | 'referenceId' | 'parentId' | 'metadata' | 'mentionees' | 'attachments' | 'links'>;
1
2
  /**
2
3
  * ```js
3
4
  * import { CommentRepository } from '@amityco/ts-sdk-react-native'
@@ -12,5 +13,6 @@
12
13
  * @category Comment API
13
14
  * @async
14
15
  */
15
- export declare const createComment: (bundle: Pick<Amity.Comment<Amity.CommentContentType>, 'data' | 'referenceType' | 'referenceId' | 'parentId' | 'metadata' | 'mentionees' | 'attachments' | 'links'>) => Promise<Amity.Cached<Amity.Comment>>;
16
+ export declare const createComment: (bundle: CreateCommentBundle) => Promise<Amity.Cached<Amity.Comment>>;
17
+ export {};
16
18
  //# sourceMappingURL=createComment.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createComment.d.ts","sourceRoot":"","sources":["../../../src/commentRepository/api/createComment.ts"],"names":[],"mappings":"AAeA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,aAAa,WAChB,KACN,aAAa,CAAC,MAAM,kBAAkB,CAAC,EACrC,MAAM,GACN,eAAe,GACf,aAAa,GACb,UAAU,GACV,UAAU,GACV,YAAY,GACZ,aAAa,GACb,OAAO,CACV,KACA,QAAQ,MAAM,MAAM,CAAC,aAAa,CAAC,CAyDrC,CAAC"}
1
+ {"version":3,"file":"createComment.d.ts","sourceRoot":"","sources":["../../../src/commentRepository/api/createComment.ts"],"names":[],"mappings":"AAkBA,aAAK,mBAAmB,GAAG,IAAI,CAC7B,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,kBAAkB,CAAC,EACrC,MAAM,GACN,eAAe,GACf,aAAa,GACb,UAAU,GACV,UAAU,GACV,YAAY,GACZ,aAAa,GACb,OAAO,CACV,CAAC;AA+DF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,aAAa,WAChB,mBAAmB,KAC1B,QAAQ,MAAM,MAAM,CAAC,aAAa,CAAC,CAmFrC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"deleteComment.d.ts","sourceRoot":"","sources":["../../../src/commentRepository/api/deleteComment.ts"],"names":[],"mappings":"AAiBA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,aAAa,cACb,aAAa,CAAC,WAAW,CAAC,0BAEpC,QAAQ,aAAa,CA+DvB,CAAC"}
1
+ {"version":3,"file":"deleteComment.d.ts","sourceRoot":"","sources":["../../../src/commentRepository/api/deleteComment.ts"],"names":[],"mappings":"AAiBA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,aAAa,cACb,aAAa,CAAC,WAAW,CAAC,0BAEpC,QAAQ,aAAa,CAoFvB,CAAC"}
package/dist/index.cjs.js CHANGED
@@ -278,8 +278,8 @@ exports.AnalyticsSourceTypeEnum = void 0;
278
278
 
279
279
  function getVersion() {
280
280
  try {
281
- // the string ''v7.20.0-cjs'' should be replaced by actual value by @rollup/plugin-replace
282
- return 'v7.20.0-cjs';
281
+ // the string ''v7.21.0-cjs'' should be replaced by actual value by @rollup/plugin-replace
282
+ return 'v7.21.0-cjs';
283
283
  }
284
284
  catch (error) {
285
285
  return '__dev__';
@@ -26142,9 +26142,55 @@ getCommentByIds.locally = (commentIds) => {
26142
26142
  };
26143
26143
  };
26144
26144
 
26145
- /* begin_public_function
26146
- id: comment.create
26147
- */
26145
+ const getLocalCommentId = () => uuid();
26146
+ const createCommentOptimistic = (bundle) => {
26147
+ const client = getActiveClient();
26148
+ if (!client.cache)
26149
+ return;
26150
+ const commentId = getLocalCommentId();
26151
+ client.log('comment/createComment.optimistically', Object.assign({ commentId }, bundle));
26152
+ const createdTime = new Date().toISOString();
26153
+ const comment = {
26154
+ commentId,
26155
+ userId: client.userId,
26156
+ parentId: bundle.parentId,
26157
+ rootId: bundle.parentId || commentId,
26158
+ childrenNumber: 0,
26159
+ children: [],
26160
+ segmentNumber: 0,
26161
+ editedAt: createdTime,
26162
+ referenceId: bundle.referenceId,
26163
+ referenceType: bundle.referenceType,
26164
+ data: bundle.data,
26165
+ metadata: bundle.metadata,
26166
+ mentionees: bundle.mentionees,
26167
+ attachments: bundle.attachments,
26168
+ links: bundle.links,
26169
+ createdAt: createdTime,
26170
+ updatedAt: createdTime,
26171
+ isDeleted: false,
26172
+ flagCount: 0,
26173
+ hashFlag: null,
26174
+ reactions: {},
26175
+ reactionsCount: 0,
26176
+ myReactions: [],
26177
+ path: '',
26178
+ targetId: '',
26179
+ targetType: 'community',
26180
+ dataType: 'text',
26181
+ syncState: "syncing" /* Amity.SyncState.Syncing */,
26182
+ };
26183
+ const cachedAt = UNSYNCED_OBJECT_CACHED_AT_VALUE;
26184
+ pushToCache(['comment', 'get', comment.commentId], comment, { cachedAt });
26185
+ fireEvent('local.comment.created', {
26186
+ comments: [comment],
26187
+ commentChildren: [],
26188
+ users: [],
26189
+ files: [],
26190
+ communityUsers: [],
26191
+ });
26192
+ return comment;
26193
+ };
26148
26194
  /**
26149
26195
  * ```js
26150
26196
  * import { CommentRepository } from '@amityco/ts-sdk-react-native'
@@ -26162,48 +26208,70 @@ getCommentByIds.locally = (commentIds) => {
26162
26208
  const createComment = async (bundle) => {
26163
26209
  const client = getActiveClient();
26164
26210
  client.log('comment/createComment', bundle);
26165
- const { data } = await client.http.post('/api/v3/comments', bundle);
26166
- const { comments } = data;
26167
- // BE always returns an array of comments If it got record 0 from BE it might have a problem on creation logic
26168
- if (comments.length === 0)
26169
- throw new Error('Comment not created');
26170
- const cachedAt = client.cache && Date.now();
26171
- if (client.cache)
26172
- ingestInCache(data, { cachedAt });
26173
- if (['post', 'content'].includes(bundle.referenceType)) {
26174
- PostCommentCountEngine$1.getInstance().queueCommentChangeTask(new CreateTask(bundle.referenceId, comments[0].commentId, data.comments[0].createdAt));
26175
- }
26176
- else if (bundle.referenceType === 'story') {
26177
- const storyIndex = pullFromCache([
26178
- "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
26179
- bundle.referenceId,
26180
- ]);
26181
- if (storyIndex === null || storyIndex === void 0 ? void 0 : storyIndex.data) {
26182
- const cacheStory = pullFromCache([
26183
- "story" /* STORY_KEY_CACHE.STORY */,
26184
- 'get',
26185
- storyIndex.data,
26211
+ const optimisticData = createCommentOptimistic(bundle);
26212
+ const commentId = optimisticData === null || optimisticData === void 0 ? void 0 : optimisticData.commentId;
26213
+ try {
26214
+ const { data } = await client.http.post('/api/v3/comments', Object.assign(Object.assign({}, bundle), { commentId }));
26215
+ const { comments } = data;
26216
+ // BE always returns an array of comments If it got record 0 from BE it might have a problem on creation logic
26217
+ if (comments.length === 0)
26218
+ throw new Error('Comment not created');
26219
+ const cachedAt = client.cache && Date.now();
26220
+ if (client.cache)
26221
+ ingestInCache(data, { cachedAt });
26222
+ if (['post', 'content'].includes(bundle.referenceType)) {
26223
+ PostCommentCountEngine$1.getInstance().queueCommentChangeTask(new CreateTask(bundle.referenceId, comments[0].commentId, data.comments[0].createdAt));
26224
+ }
26225
+ else if (bundle.referenceType === 'story') {
26226
+ const storyIndex = pullFromCache([
26227
+ "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
26228
+ bundle.referenceId,
26186
26229
  ]);
26187
- if (cacheStory === null || cacheStory === void 0 ? void 0 : cacheStory.data) {
26188
- fireEvent('story.updated', {
26189
- stories: [
26190
- Object.assign(Object.assign({}, cacheStory.data), { commentsCount: cacheStory.data.commentsCount + 1, comments: [...new Set([...cacheStory.data.comments, comments[0].commentId])] }),
26191
- ],
26192
- categories: [],
26193
- comments,
26194
- communities: [],
26195
- communityUsers: data.communityUsers,
26196
- files: data.files,
26197
- users: data.users,
26198
- });
26230
+ if (storyIndex === null || storyIndex === void 0 ? void 0 : storyIndex.data) {
26231
+ const cacheStory = pullFromCache([
26232
+ "story" /* STORY_KEY_CACHE.STORY */,
26233
+ 'get',
26234
+ storyIndex.data,
26235
+ ]);
26236
+ if (cacheStory === null || cacheStory === void 0 ? void 0 : cacheStory.data) {
26237
+ fireEvent('story.updated', {
26238
+ stories: [
26239
+ Object.assign(Object.assign({}, cacheStory.data), { commentsCount: cacheStory.data.commentsCount + 1, comments: [...new Set([...cacheStory.data.comments, comments[0].commentId])] }),
26240
+ ],
26241
+ categories: [],
26242
+ comments,
26243
+ communities: [],
26244
+ communityUsers: data.communityUsers,
26245
+ files: data.files,
26246
+ users: data.users,
26247
+ });
26248
+ }
26199
26249
  }
26200
26250
  }
26251
+ fireEvent('local.comment.created', {
26252
+ comments: [Object.assign(Object.assign({}, comments[0]), { syncState: "synced" /* Amity.SyncState.Synced */ })],
26253
+ commentChildren: data.commentChildren,
26254
+ users: data.users,
26255
+ files: data.files,
26256
+ communityUsers: data.communityUsers,
26257
+ });
26258
+ return {
26259
+ data: LinkedObject.comment(comments[0]),
26260
+ cachedAt,
26261
+ };
26262
+ }
26263
+ catch (e) {
26264
+ if (optimisticData) {
26265
+ fireEvent('local.comment.created', {
26266
+ comments: [Object.assign(Object.assign({}, optimisticData), { syncState: "error" /* Amity.SyncState.Error */ })],
26267
+ commentChildren: [],
26268
+ users: [],
26269
+ files: [],
26270
+ communityUsers: [],
26271
+ });
26272
+ }
26273
+ throw e;
26201
26274
  }
26202
- fireEvent('local.comment.created', data);
26203
- return {
26204
- data: LinkedObject.comment(comments[0]),
26205
- cachedAt,
26206
- };
26207
26275
  };
26208
26276
  /* end_public_function */
26209
26277
 
@@ -26330,8 +26398,21 @@ getStoryByStoryId$1.locally = (storyId) => {
26330
26398
  * @async
26331
26399
  */
26332
26400
  const deleteComment = async (commentId, permanent = false) => {
26333
- var _a, _b;
26401
+ var _a, _b, _c;
26334
26402
  const client = getActiveClient();
26403
+ const cached = (_a = pullFromCache(['comment', 'get', commentId])) === null || _a === void 0 ? void 0 : _a.data;
26404
+ if ((cached === null || cached === void 0 ? void 0 : cached.syncState) === "error" /* Amity.SyncState.Error */) {
26405
+ const deletedComment = Object.assign(Object.assign({}, cached), { isDeleted: true });
26406
+ dropFromCache(['comment', 'get', commentId]);
26407
+ fireEvent('local.comment.deleted', {
26408
+ comments: [deletedComment],
26409
+ commentChildren: [],
26410
+ files: [],
26411
+ users: [],
26412
+ communityUsers: [],
26413
+ });
26414
+ return deletedComment;
26415
+ }
26335
26416
  const comment = await getComment$2(commentId);
26336
26417
  // API-FIX: This endpoint has not been implemented yet.
26337
26418
  await client.http.delete(`/api/v4/comments/${encodeURIComponent(commentId)}`, {
@@ -26361,11 +26442,11 @@ const deleteComment = async (commentId, permanent = false) => {
26361
26442
  });
26362
26443
  }
26363
26444
  else {
26364
- const post = (_a = pullFromCache(['post', 'get', comment.data.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
26445
+ const post = (_b = pullFromCache(['post', 'get', comment.data.referenceId])) === null || _b === void 0 ? void 0 : _b.data;
26365
26446
  if (post) {
26366
26447
  const engine = PostCommentCountEngine$1.getInstance();
26367
26448
  engine.queueCommentChangeTask(new DeleteTask(post.postId, commentId));
26368
- if (!deleted.parentId && ((_b = deleted.children /* c8 ignore next */) === null || _b === void 0 ? void 0 : _b.length) > 0) {
26449
+ if (!deleted.parentId && ((_c = deleted.children /* c8 ignore next */) === null || _c === void 0 ? void 0 : _c.length) > 0) {
26369
26450
  // NOTE: delete the parent comment will also remove all children comments
26370
26451
  deleted.children.forEach((childCommentId) => {
26371
26452
  engine.queueCommentChangeTask(new DeleteTask(post.postId, childCommentId));
package/dist/index.esm.js CHANGED
@@ -244,8 +244,8 @@ var AnalyticsSourceTypeEnum;
244
244
 
245
245
  function getVersion() {
246
246
  try {
247
- // the string ''v7.20.0-esm'' should be replaced by actual value by @rollup/plugin-replace
248
- return 'v7.20.0-esm';
247
+ // the string ''v7.21.0-esm'' should be replaced by actual value by @rollup/plugin-replace
248
+ return 'v7.21.0-esm';
249
249
  }
250
250
  catch (error) {
251
251
  return '__dev__';
@@ -42215,9 +42215,55 @@ getCommentByIds.locally = (commentIds) => {
42215
42215
  };
42216
42216
  };
42217
42217
 
42218
- /* begin_public_function
42219
- id: comment.create
42220
- */
42218
+ const getLocalCommentId = () => uuid();
42219
+ const createCommentOptimistic = (bundle) => {
42220
+ const client = getActiveClient();
42221
+ if (!client.cache)
42222
+ return;
42223
+ const commentId = getLocalCommentId();
42224
+ client.log('comment/createComment.optimistically', Object.assign({ commentId }, bundle));
42225
+ const createdTime = new Date().toISOString();
42226
+ const comment = {
42227
+ commentId,
42228
+ userId: client.userId,
42229
+ parentId: bundle.parentId,
42230
+ rootId: bundle.parentId || commentId,
42231
+ childrenNumber: 0,
42232
+ children: [],
42233
+ segmentNumber: 0,
42234
+ editedAt: createdTime,
42235
+ referenceId: bundle.referenceId,
42236
+ referenceType: bundle.referenceType,
42237
+ data: bundle.data,
42238
+ metadata: bundle.metadata,
42239
+ mentionees: bundle.mentionees,
42240
+ attachments: bundle.attachments,
42241
+ links: bundle.links,
42242
+ createdAt: createdTime,
42243
+ updatedAt: createdTime,
42244
+ isDeleted: false,
42245
+ flagCount: 0,
42246
+ hashFlag: null,
42247
+ reactions: {},
42248
+ reactionsCount: 0,
42249
+ myReactions: [],
42250
+ path: '',
42251
+ targetId: '',
42252
+ targetType: 'community',
42253
+ dataType: 'text',
42254
+ syncState: "syncing" /* Amity.SyncState.Syncing */,
42255
+ };
42256
+ const cachedAt = UNSYNCED_OBJECT_CACHED_AT_VALUE;
42257
+ pushToCache(['comment', 'get', comment.commentId], comment, { cachedAt });
42258
+ fireEvent('local.comment.created', {
42259
+ comments: [comment],
42260
+ commentChildren: [],
42261
+ users: [],
42262
+ files: [],
42263
+ communityUsers: [],
42264
+ });
42265
+ return comment;
42266
+ };
42221
42267
  /**
42222
42268
  * ```js
42223
42269
  * import { CommentRepository } from '@amityco/ts-sdk-react-native'
@@ -42235,48 +42281,70 @@ getCommentByIds.locally = (commentIds) => {
42235
42281
  const createComment = async (bundle) => {
42236
42282
  const client = getActiveClient();
42237
42283
  client.log('comment/createComment', bundle);
42238
- const { data } = await client.http.post('/api/v3/comments', bundle);
42239
- const { comments } = data;
42240
- // BE always returns an array of comments If it got record 0 from BE it might have a problem on creation logic
42241
- if (comments.length === 0)
42242
- throw new Error('Comment not created');
42243
- const cachedAt = client.cache && Date.now();
42244
- if (client.cache)
42245
- ingestInCache(data, { cachedAt });
42246
- if (['post', 'content'].includes(bundle.referenceType)) {
42247
- PostCommentCountEngine$1.getInstance().queueCommentChangeTask(new CreateTask(bundle.referenceId, comments[0].commentId, data.comments[0].createdAt));
42248
- }
42249
- else if (bundle.referenceType === 'story') {
42250
- const storyIndex = pullFromCache([
42251
- "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
42252
- bundle.referenceId,
42253
- ]);
42254
- if (storyIndex === null || storyIndex === void 0 ? void 0 : storyIndex.data) {
42255
- const cacheStory = pullFromCache([
42256
- "story" /* STORY_KEY_CACHE.STORY */,
42257
- 'get',
42258
- storyIndex.data,
42284
+ const optimisticData = createCommentOptimistic(bundle);
42285
+ const commentId = optimisticData === null || optimisticData === void 0 ? void 0 : optimisticData.commentId;
42286
+ try {
42287
+ const { data } = await client.http.post('/api/v3/comments', Object.assign(Object.assign({}, bundle), { commentId }));
42288
+ const { comments } = data;
42289
+ // BE always returns an array of comments If it got record 0 from BE it might have a problem on creation logic
42290
+ if (comments.length === 0)
42291
+ throw new Error('Comment not created');
42292
+ const cachedAt = client.cache && Date.now();
42293
+ if (client.cache)
42294
+ ingestInCache(data, { cachedAt });
42295
+ if (['post', 'content'].includes(bundle.referenceType)) {
42296
+ PostCommentCountEngine$1.getInstance().queueCommentChangeTask(new CreateTask(bundle.referenceId, comments[0].commentId, data.comments[0].createdAt));
42297
+ }
42298
+ else if (bundle.referenceType === 'story') {
42299
+ const storyIndex = pullFromCache([
42300
+ "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
42301
+ bundle.referenceId,
42259
42302
  ]);
42260
- if (cacheStory === null || cacheStory === void 0 ? void 0 : cacheStory.data) {
42261
- fireEvent('story.updated', {
42262
- stories: [
42263
- Object.assign(Object.assign({}, cacheStory.data), { commentsCount: cacheStory.data.commentsCount + 1, comments: [...new Set([...cacheStory.data.comments, comments[0].commentId])] }),
42264
- ],
42265
- categories: [],
42266
- comments,
42267
- communities: [],
42268
- communityUsers: data.communityUsers,
42269
- files: data.files,
42270
- users: data.users,
42271
- });
42303
+ if (storyIndex === null || storyIndex === void 0 ? void 0 : storyIndex.data) {
42304
+ const cacheStory = pullFromCache([
42305
+ "story" /* STORY_KEY_CACHE.STORY */,
42306
+ 'get',
42307
+ storyIndex.data,
42308
+ ]);
42309
+ if (cacheStory === null || cacheStory === void 0 ? void 0 : cacheStory.data) {
42310
+ fireEvent('story.updated', {
42311
+ stories: [
42312
+ Object.assign(Object.assign({}, cacheStory.data), { commentsCount: cacheStory.data.commentsCount + 1, comments: [...new Set([...cacheStory.data.comments, comments[0].commentId])] }),
42313
+ ],
42314
+ categories: [],
42315
+ comments,
42316
+ communities: [],
42317
+ communityUsers: data.communityUsers,
42318
+ files: data.files,
42319
+ users: data.users,
42320
+ });
42321
+ }
42272
42322
  }
42273
42323
  }
42324
+ fireEvent('local.comment.created', {
42325
+ comments: [Object.assign(Object.assign({}, comments[0]), { syncState: "synced" /* Amity.SyncState.Synced */ })],
42326
+ commentChildren: data.commentChildren,
42327
+ users: data.users,
42328
+ files: data.files,
42329
+ communityUsers: data.communityUsers,
42330
+ });
42331
+ return {
42332
+ data: LinkedObject.comment(comments[0]),
42333
+ cachedAt,
42334
+ };
42335
+ }
42336
+ catch (e) {
42337
+ if (optimisticData) {
42338
+ fireEvent('local.comment.created', {
42339
+ comments: [Object.assign(Object.assign({}, optimisticData), { syncState: "error" /* Amity.SyncState.Error */ })],
42340
+ commentChildren: [],
42341
+ users: [],
42342
+ files: [],
42343
+ communityUsers: [],
42344
+ });
42345
+ }
42346
+ throw e;
42274
42347
  }
42275
- fireEvent('local.comment.created', data);
42276
- return {
42277
- data: LinkedObject.comment(comments[0]),
42278
- cachedAt,
42279
- };
42280
42348
  };
42281
42349
  /* end_public_function */
42282
42350
 
@@ -42403,8 +42471,21 @@ getStoryByStoryId$1.locally = (storyId) => {
42403
42471
  * @async
42404
42472
  */
42405
42473
  const deleteComment = async (commentId, permanent = false) => {
42406
- var _a, _b;
42474
+ var _a, _b, _c;
42407
42475
  const client = getActiveClient();
42476
+ const cached = (_a = pullFromCache(['comment', 'get', commentId])) === null || _a === void 0 ? void 0 : _a.data;
42477
+ if ((cached === null || cached === void 0 ? void 0 : cached.syncState) === "error" /* Amity.SyncState.Error */) {
42478
+ const deletedComment = Object.assign(Object.assign({}, cached), { isDeleted: true });
42479
+ dropFromCache(['comment', 'get', commentId]);
42480
+ fireEvent('local.comment.deleted', {
42481
+ comments: [deletedComment],
42482
+ commentChildren: [],
42483
+ files: [],
42484
+ users: [],
42485
+ communityUsers: [],
42486
+ });
42487
+ return deletedComment;
42488
+ }
42408
42489
  const comment = await getComment$2(commentId);
42409
42490
  // API-FIX: This endpoint has not been implemented yet.
42410
42491
  await client.http.delete(`/api/v4/comments/${encodeURIComponent(commentId)}`, {
@@ -42434,11 +42515,11 @@ const deleteComment = async (commentId, permanent = false) => {
42434
42515
  });
42435
42516
  }
42436
42517
  else {
42437
- const post = (_a = pullFromCache(['post', 'get', comment.data.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
42518
+ const post = (_b = pullFromCache(['post', 'get', comment.data.referenceId])) === null || _b === void 0 ? void 0 : _b.data;
42438
42519
  if (post) {
42439
42520
  const engine = PostCommentCountEngine$1.getInstance();
42440
42521
  engine.queueCommentChangeTask(new DeleteTask(post.postId, commentId));
42441
- if (!deleted.parentId && ((_b = deleted.children /* c8 ignore next */) === null || _b === void 0 ? void 0 : _b.length) > 0) {
42522
+ if (!deleted.parentId && ((_c = deleted.children /* c8 ignore next */) === null || _c === void 0 ? void 0 : _c.length) > 0) {
42442
42523
  // NOTE: delete the parent comment will also remove all children comments
42443
42524
  deleted.children.forEach((childCommentId) => {
42444
42525
  engine.queueCommentChangeTask(new DeleteTask(post.postId, childCommentId));