@amityco/ts-sdk 7.7.1-47be9e51.0 → 7.7.1-4843378b.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.
Files changed (129) hide show
  1. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/feed.d.ts +0 -31
  2. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/feed.d.ts.map +1 -1
  3. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/feed.js +1 -21
  4. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/feed.js.map +1 -1
  5. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/hashtag.d.ts +11 -0
  6. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/hashtag.d.ts.map +1 -0
  7. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/hashtag.js +2 -0
  8. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/hashtag.js.map +1 -0
  9. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/post.d.ts +8 -3
  10. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/post.d.ts.map +1 -1
  11. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/post.js.map +1 -1
  12. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/index.d.ts +1 -0
  13. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/index.d.ts.map +1 -1
  14. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/index.js +1 -0
  15. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/index.js.map +1 -1
  16. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/index.d.ts +0 -1
  17. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/index.d.ts.map +1 -1
  18. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/index.js +0 -1
  19. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/index.js.map +1 -1
  20. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/createPost.d.ts +1 -1
  21. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/createPost.js.map +1 -1
  22. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/editPost.d.ts +1 -1
  23. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/editPost.js.map +1 -1
  24. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/getPostsByHashtag.d.ts +16 -0
  25. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/getPostsByHashtag.d.ts.map +1 -0
  26. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/getPostsByHashtag.js +62 -0
  27. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/getPostsByHashtag.js.map +1 -0
  28. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/index.d.ts +1 -0
  29. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/index.d.ts.map +1 -1
  30. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/index.js +1 -0
  31. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/index.js.map +1 -1
  32. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPosts/PostPaginationController.d.ts.map +1 -1
  33. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPosts/PostPaginationController.js +2 -3
  34. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPosts/PostPaginationController.js.map +1 -1
  35. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/{feedRepository/observers/getUserFeed/LiveCollectionController.d.ts → postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.d.ts} +4 -4
  36. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.d.ts.map +1 -0
  37. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/{feedRepository/observers/getUserFeed/LiveCollectionController.js → postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.js} +9 -12
  38. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.js.map +1 -0
  39. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.d.ts +5 -0
  40. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.d.ts.map +1 -0
  41. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.js +26 -0
  42. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.js.map +1 -0
  43. package/{dist/feedRepository/observers/getUserFeed/QueryStreamController.d.ts → .rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.d.ts} +4 -4
  44. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.d.ts.map +1 -0
  45. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/{feedRepository/observers/getUserFeed/QueryStreamController.js → postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.js} +6 -19
  46. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.js.map +1 -0
  47. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/index.d.ts +1 -0
  48. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/index.d.ts.map +1 -1
  49. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/index.js +1 -0
  50. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/index.js.map +1 -1
  51. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/searchPostsByHashtag.d.ts +22 -0
  52. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/searchPostsByHashtag.d.ts.map +1 -0
  53. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/searchPostsByHashtag.js +45 -0
  54. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/searchPostsByHashtag.js.map +1 -0
  55. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/tsconfig.tsbuildinfo +1 -1
  56. package/dist/@types/domains/feed.d.ts +0 -31
  57. package/dist/@types/domains/feed.d.ts.map +1 -1
  58. package/dist/@types/domains/hashtag.d.ts +11 -0
  59. package/dist/@types/domains/hashtag.d.ts.map +1 -0
  60. package/dist/@types/domains/post.d.ts +8 -3
  61. package/dist/@types/domains/post.d.ts.map +1 -1
  62. package/dist/@types/index.d.ts +1 -0
  63. package/dist/@types/index.d.ts.map +1 -1
  64. package/dist/feedRepository/index.d.ts +0 -1
  65. package/dist/feedRepository/index.d.ts.map +1 -1
  66. package/dist/index.cjs.js +1394 -1343
  67. package/dist/index.esm.js +1393 -1342
  68. package/dist/index.umd.js +4 -4
  69. package/dist/postRepository/api/createPost.d.ts +1 -1
  70. package/dist/postRepository/api/editPost.d.ts +1 -1
  71. package/dist/postRepository/api/getPostsByHashtag.d.ts +16 -0
  72. package/dist/postRepository/api/getPostsByHashtag.d.ts.map +1 -0
  73. package/dist/postRepository/api/index.d.ts +1 -0
  74. package/dist/postRepository/api/index.d.ts.map +1 -1
  75. package/dist/postRepository/observers/getPosts/PostPaginationController.d.ts.map +1 -1
  76. package/dist/{feedRepository/observers/getUserFeed/LiveCollectionController.d.ts → postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.d.ts} +4 -4
  77. package/dist/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.d.ts.map +1 -0
  78. package/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.d.ts +5 -0
  79. package/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.d.ts.map +1 -0
  80. package/{.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/QueryStreamController.d.ts → dist/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.d.ts} +4 -4
  81. package/dist/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.d.ts.map +1 -0
  82. package/dist/postRepository/observers/index.d.ts +1 -0
  83. package/dist/postRepository/observers/index.d.ts.map +1 -1
  84. package/dist/postRepository/observers/searchPostsByHashtag.d.ts +22 -0
  85. package/dist/postRepository/observers/searchPostsByHashtag.d.ts.map +1 -0
  86. package/package.json +1 -1
  87. package/src/@types/domains/feed.ts +0 -43
  88. package/src/@types/domains/hashtag.ts +11 -0
  89. package/src/@types/domains/post.ts +12 -3
  90. package/src/@types/index.ts +1 -0
  91. package/src/feedRepository/index.ts +0 -1
  92. package/src/postRepository/api/createPost.ts +1 -1
  93. package/src/postRepository/api/editPost.ts +1 -1
  94. package/src/postRepository/api/getPostsByHashtag.ts +77 -0
  95. package/src/postRepository/api/index.ts +2 -0
  96. package/src/postRepository/observers/getPosts/PostPaginationController.ts +0 -3
  97. package/src/{feedRepository/observers/getUserFeed/LiveCollectionController.ts → postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.ts} +17 -23
  98. package/src/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.ts +45 -0
  99. package/src/{feedRepository/observers/getUserFeed/QueryStreamController.ts → postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.ts} +9 -29
  100. package/src/postRepository/observers/index.ts +1 -0
  101. package/src/postRepository/observers/searchPostsByHashtag.ts +56 -0
  102. package/tsconfig.tsbuildinfo +1 -1
  103. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/LiveCollectionController.d.ts.map +0 -1
  104. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/LiveCollectionController.js.map +0 -1
  105. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/PaginationController.d.ts +0 -5
  106. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/PaginationController.d.ts.map +0 -1
  107. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/PaginationController.js +0 -15
  108. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/PaginationController.js.map +0 -1
  109. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/QueryStreamController.d.ts.map +0 -1
  110. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/QueryStreamController.js.map +0 -1
  111. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed.d.ts +0 -23
  112. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed.d.ts.map +0 -1
  113. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed.js +0 -46
  114. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed.js.map +0 -1
  115. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/index.d.ts +0 -2
  116. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/index.d.ts.map +0 -1
  117. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/index.js +0 -2
  118. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/index.js.map +0 -1
  119. package/dist/feedRepository/observers/getUserFeed/LiveCollectionController.d.ts.map +0 -1
  120. package/dist/feedRepository/observers/getUserFeed/PaginationController.d.ts +0 -5
  121. package/dist/feedRepository/observers/getUserFeed/PaginationController.d.ts.map +0 -1
  122. package/dist/feedRepository/observers/getUserFeed/QueryStreamController.d.ts.map +0 -1
  123. package/dist/feedRepository/observers/getUserFeed.d.ts +0 -23
  124. package/dist/feedRepository/observers/getUserFeed.d.ts.map +0 -1
  125. package/dist/feedRepository/observers/index.d.ts +0 -2
  126. package/dist/feedRepository/observers/index.d.ts.map +0 -1
  127. package/src/feedRepository/observers/getUserFeed/PaginationController.ts +0 -37
  128. package/src/feedRepository/observers/getUserFeed.ts +0 -56
  129. package/src/feedRepository/observers/index.ts +0 -1
package/dist/index.esm.js CHANGED
@@ -39272,1779 +39272,1543 @@ getCustomRankingGlobalFeed.locally = (query) => {
39272
39272
  : undefined;
39273
39273
  };
39274
39274
 
39275
- class UserFeedPaginationController extends PaginationController {
39276
- async getRequest(queryParams, token) {
39277
- const { userId, feedSources, dataTypes, includeDeleted, matchingOnlyParentPost, limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["userId", "feedSources", "dataTypes", "includeDeleted", "matchingOnlyParentPost", "limit"]);
39278
- const options = token ? { token } : { limit };
39279
- const { data: queryResponse } = await this.http.get(`/api/v4/user-feeds/${userId}`, {
39280
- params: Object.assign(Object.assign({}, params), { options, dataTypes: (dataTypes === null || dataTypes === void 0 ? void 0 : dataTypes.length) ? dataTypes : undefined, includePostedFeed: feedSources, isDeleted: inferIsDeleted(includeDeleted), matchingOnlyParentPost: matchingOnlyParentPost !== null && matchingOnlyParentPost !== void 0 ? matchingOnlyParentPost : !(dataTypes === null || dataTypes === void 0 ? void 0 : dataTypes.length) }),
39281
- });
39282
- return queryResponse;
39283
- }
39284
- }
39285
-
39286
- var EnumPostActions;
39287
- (function (EnumPostActions) {
39288
- EnumPostActions["OnPostCreated"] = "onPostCreated";
39289
- EnumPostActions["OnPostUpdated"] = "onPostUpdated";
39290
- EnumPostActions["OnPostDeleted"] = "onPostDeleted";
39291
- EnumPostActions["OnPostFlagged"] = "onPostFlagged";
39292
- EnumPostActions["OnPostUnflagged"] = "onPostUnflagged";
39293
- EnumPostActions["OnPostReactionAdded"] = "onPostReactionAdded";
39294
- EnumPostActions["OnPostReactionRemoved"] = "onPostReactionRemoved";
39295
- EnumPostActions["OnPostApproved"] = "onPostApproved";
39296
- EnumPostActions["OnPostDeclined"] = "onPostDeclined";
39297
- })(EnumPostActions || (EnumPostActions = {}));
39298
-
39299
- class UserFeedQueryStreamController extends QueryStreamController {
39300
- constructor(query, cacheKey, notifyChange, preparePayload) {
39301
- super(query, cacheKey);
39302
- this.notifyChange = notifyChange;
39303
- this.preparePayload = preparePayload;
39304
- }
39305
- async saveToMainDB(response) {
39306
- const processedPayload = await this.preparePayload(response);
39307
- const client = getActiveClient();
39308
- const cachedAt = client.cache && Date.now();
39309
- if (client.cache) {
39310
- ingestInCache(processedPayload, { cachedAt });
39311
- }
39312
- }
39313
- appendToQueryStream(response, direction, refresh = false) {
39314
- var _a, _b;
39315
- if (refresh) {
39316
- pushToCache(this.cacheKey, {
39317
- data: response.posts.map(getResolver('post')),
39318
- });
39319
- }
39320
- else {
39321
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
39322
- const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
39323
- pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
39324
- }
39325
- }
39326
- reactor(action) {
39327
- return (post) => {
39328
- var _a, _b;
39329
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
39330
- if (!collection)
39331
- return;
39332
- // if the collection is parent post collection and
39333
- // post is not included in the collection or post is child post
39334
- if ((!this.query.dataTypes || this.query.dataTypes.length === 0) &&
39335
- !collection.data.includes(post.parentPostId ? post.parentPostId : post.postId))
39336
- return;
39337
- if (action === EnumPostActions.OnPostDeleted) {
39338
- collection.data = collection.data.filter(postId => postId !== post.postId);
39339
- }
39340
- if (post.parentPostId && post.isDeleted) {
39341
- const parentPost = (_b = pullFromCache([
39342
- 'post',
39343
- 'get',
39344
- post.parentPostId,
39345
- ])) === null || _b === void 0 ? void 0 : _b.data;
39346
- if (!parentPost)
39347
- return;
39348
- parentPost.children = parentPost.children.filter(childId => childId !== post.postId);
39349
- pushToCache(['post', 'get', parentPost.postId], parentPost);
39350
- }
39351
- if (action === EnumPostActions.OnPostDeclined) {
39352
- collection.data = collection.data.filter(postId => postId !== post.postId);
39353
- }
39354
- if (action === EnumPostActions.OnPostCreated || action === EnumPostActions.OnPostApproved) {
39355
- if (this.query.dataTypes &&
39356
- this.query.dataTypes.length > 0 &&
39357
- !this.query.dataTypes.includes(post.dataType)) {
39358
- return;
39359
- }
39360
- collection.data = [...new Set([post.postId, ...collection.data])];
39361
- }
39362
- pushToCache(this.cacheKey, collection);
39363
- this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
39364
- };
39365
- }
39366
- subscribeRTE(createSubscriber) {
39367
- return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
39368
- }
39369
- }
39275
+ var index$a = /*#__PURE__*/Object.freeze({
39276
+ __proto__: null,
39277
+ queryGlobalFeed: queryGlobalFeed,
39278
+ getCustomRankingGlobalFeed: getCustomRankingGlobalFeed
39279
+ });
39370
39280
 
39371
39281
  /* begin_public_function
39372
- id: comment.get_by_ids
39282
+ id: post.get_by_ids
39373
39283
  */
39374
39284
  /**
39375
39285
  * ```js
39376
- * import { CommentRepository } from '@amityco/ts-sdk'
39377
- * const comments = await CommentRepository.getCommentByIds(['foo', 'bar'])
39286
+ * import { getPostByIds } from '@amityco/ts-sdk'
39287
+ * const { data: posts } = await getPostByIds(['foo', 'bar'])
39378
39288
  * ```
39379
39289
  *
39380
- * Fetches a collection of {@link Amity.Comment} objects
39290
+ * Fetches a collection of {@link Amity.Post} objects
39381
39291
  *
39382
- * @param commentIds the IDs of the {@link Amity.Comment} to fetch
39383
- * @returns the associated collection of {@link Amity.Comment} objects
39292
+ * @param postIds the IDs of the {@link Amity.Post} to fetch
39293
+ * @returns the associated collection of {@link Amity.Post} objects
39384
39294
  *
39385
- * @category Comment API
39295
+ * @category Post API
39386
39296
  * @async
39387
39297
  */
39388
- const getCommentByIds = async (commentIds) => {
39298
+ const getPostByIds = async (postIds) => {
39389
39299
  const client = getActiveClient();
39390
- client.log('comment/getCommentByIds', commentIds);
39391
- const encodedCommentIds = commentIds.map(commentId => encodeURIComponent(commentId));
39392
- let data;
39300
+ client.log('post/getPostByIds', postIds);
39301
+ const encodedPostIds = postIds.map(postId => encodeURIComponent(postId));
39302
+ let payload;
39393
39303
  try {
39394
39304
  // API-FIX: endpoint should not be /list, parameters should be querystring.
39395
- const response = await client.http.get(`/api/v3/comments/list`, {
39396
- params: { commentIds: encodedCommentIds },
39305
+ const response = await client.http.get(`/api/v3/posts/list`, {
39306
+ params: { postIds: encodedPostIds },
39397
39307
  });
39398
- data = response.data;
39308
+ payload = response.data;
39399
39309
  }
39400
39310
  catch (error) {
39401
- commentIds.forEach(commentId => {
39311
+ postIds.forEach(postId => {
39402
39312
  if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
39403
- pushToTombstone('comment', commentId);
39313
+ pushToTombstone('post', postId);
39404
39314
  }
39405
39315
  });
39406
39316
  throw error;
39407
39317
  }
39318
+ const data = prepareMembershipPayload(payload, 'communityUsers');
39408
39319
  const cachedAt = client.cache && Date.now();
39409
39320
  if (client.cache)
39410
39321
  ingestInCache(data, { cachedAt });
39411
39322
  return {
39412
- data: data.comments.map(comment => LinkedObject.comment(comment)),
39323
+ data: data.posts.map(LinkedObject.post),
39413
39324
  cachedAt,
39414
39325
  };
39415
39326
  };
39416
39327
  /* end_public_function */
39417
39328
  /**
39418
39329
  * ```js
39419
- * import { getCommentByIds } from '@amityco/ts-sdk'
39420
- * const comments = getCommentByIds.locally(['foo', 'bar'])
39330
+ * import { getPostByIds } from '@amityco/ts-sdk'
39331
+ * const { data: posts } = getPostByIds.locally(['foo', 'bar'])
39421
39332
  * ```
39422
39333
  *
39423
- * Fetches a collection of {@link Amity.Comment} objects from cache
39334
+ * Fetches a collection of {@link Amity.Post} objects from cache
39424
39335
  *
39425
- * @param commentIds the IDs of the {@link Amity.Comment} to fetch
39426
- * @returns the associated collection of {@link Amity.Comment} objects
39336
+ * @param postIds the IDs of the {@link Amity.Post} to fetch
39337
+ * @returns the associated collection of {@link Amity.Post} objects
39427
39338
  *
39428
- * @category Comment API
39339
+ * @category Post API
39429
39340
  */
39430
- getCommentByIds.locally = (commentIds) => {
39341
+ getPostByIds.locally = (postIds) => {
39431
39342
  var _a;
39432
39343
  const client = getActiveClient();
39433
- client.log('comment/getCommentByIds.locally', commentIds);
39344
+ client.log('post/getPostByIds.locally', postIds);
39434
39345
  if (!client.cache)
39435
39346
  return;
39436
- const cached = commentIds
39437
- .map(commentId => pullFromCache(['comment', 'get', commentId]))
39347
+ const cached = postIds
39348
+ .map(postId => pullFromCache(['post', 'get', postId]))
39438
39349
  .filter(Boolean);
39439
- const comments = cached.map(({ data }) => data);
39350
+ const posts = cached.map(({ data }) => data);
39440
39351
  const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
39441
- if ((cached === null || cached === void 0 ? void 0 : cached.length) < commentIds.length)
39352
+ if ((cached === null || cached === void 0 ? void 0 : cached.length) < postIds.length)
39442
39353
  return;
39443
39354
  return {
39444
- data: comments.map(comment => LinkedObject.comment(comment)),
39355
+ data: posts.map(LinkedObject.post),
39445
39356
  cachedAt: oldest.cachedAt,
39446
39357
  };
39447
39358
  };
39448
39359
 
39449
39360
  /* begin_public_function
39450
- id: comment.create
39361
+ id: post.create.text_post, post.create.image_post, post.create.file_post, post.create.video_post, post.create.poll_post, post.create.livestream_post, post.create.custom_post
39451
39362
  */
39452
39363
  /**
39453
39364
  * ```js
39454
- * import { CommentRepository } from '@amityco/ts-sdk'
39455
- * const newComment = await CommentRepository.createComment(bundle)
39365
+ * import { PostRepository } from '@amityco/ts-sdk'
39366
+ * const created = await PostRepository.createPost({
39367
+ * targetType: 'user',
39368
+ * targetId: 'foobar',
39369
+ * data: { text: 'hello world' }
39370
+ * }))
39456
39371
  * ```
39457
39372
  *
39458
- * Creates an {@link Amity.Comment}
39373
+ * Creates an {@link Amity.Post}
39459
39374
  *
39460
- * @param bundle The data necessary to create a new {@link Amity.Comment}
39461
- * @returns The newly created {@link Amity.Comment}
39375
+ * @param bundle The data necessary to create a new {@link Amity.Post}
39376
+ * @returns The newly created {@link Amity.Post}
39462
39377
  *
39463
- * @category Comment API
39378
+ * @category Post API
39464
39379
  * @async
39465
39380
  */
39466
- const createComment = async (bundle) => {
39467
- var _a;
39381
+ const createPost = async (bundle) => {
39468
39382
  const client = getActiveClient();
39469
- client.log('comment/createComment', bundle);
39470
- const { data } = await client.http.post('/api/v3/comments', bundle);
39471
- const { comments } = data;
39472
- // BE always returns an array of comments If it got record 0 from BE it might have a problem on creation logic
39473
- if (comments.length === 0)
39474
- throw new Error('Comment not created');
39383
+ client.log('post/createPost', bundle);
39384
+ if (!bundle.dataType || ['text', 'image', 'file', 'video'].includes(bundle.dataType)) {
39385
+ // eslint-disable-next-line no-param-reassign
39386
+ delete bundle.dataType;
39387
+ }
39388
+ const { data: payload } = await client.http.post('/api/v4/posts', bundle);
39389
+ fireEvent('post.created', payload);
39390
+ const data = preparePostPayload(payload);
39475
39391
  const cachedAt = client.cache && Date.now();
39476
39392
  if (client.cache)
39477
39393
  ingestInCache(data, { cachedAt });
39478
- if (['post', 'content'].includes(bundle.referenceType)) {
39479
- const post = (_a = pullFromCache(['post', 'get', bundle.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
39480
- if (post) {
39481
- post.commentsCount += 1;
39482
- fireEvent('local.post.updated', {
39483
- posts: [post],
39484
- categories: [],
39485
- comments: [],
39486
- communities: [],
39487
- communityUsers: data.communityUsers,
39488
- feeds: [],
39489
- files: data.files,
39490
- postChildren: [],
39491
- users: data.users,
39492
- videoStreamings: [],
39493
- });
39494
- }
39495
- }
39496
- else if (bundle.referenceType === 'story') {
39497
- const storyIndex = pullFromCache([
39498
- "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
39499
- bundle.referenceId,
39500
- ]);
39501
- if (storyIndex === null || storyIndex === void 0 ? void 0 : storyIndex.data) {
39502
- const cacheStory = pullFromCache([
39503
- "story" /* STORY_KEY_CACHE.STORY */,
39504
- 'get',
39505
- storyIndex.data,
39506
- ]);
39507
- if (cacheStory === null || cacheStory === void 0 ? void 0 : cacheStory.data) {
39508
- fireEvent('story.updated', {
39509
- stories: [
39510
- Object.assign(Object.assign({}, cacheStory.data), { commentsCount: cacheStory.data.commentsCount + 1, comments: [...new Set([...cacheStory.data.comments, comments[0].commentId])] }),
39511
- ],
39512
- categories: [],
39513
- comments,
39514
- communities: [],
39515
- communityUsers: data.communityUsers,
39516
- files: data.files,
39517
- users: data.users,
39518
- });
39519
- }
39520
- }
39521
- }
39522
- fireEvent('local.comment.created', data);
39394
+ const { posts } = data;
39523
39395
  return {
39524
- data: LinkedObject.comment(comments[0]),
39396
+ data: LinkedObject.post(posts[0]),
39525
39397
  cachedAt,
39526
39398
  };
39527
39399
  };
39528
39400
  /* end_public_function */
39529
39401
 
39530
39402
  /* begin_public_function
39531
- id: comment.update_comment
39403
+ id: post.edit, post.edit.custom_post
39532
39404
  */
39533
39405
  /**
39534
39406
  * ```js
39535
- * import { CommentRepository } from '@amityco/ts-sdk'
39536
- * const updated = await CommentRepository.updateComment(commentId, {
39407
+ * import { PostRepository } from '@amityco/ts-sdk'
39408
+ * const updated = await PostRepository.editPost(postId, {
39537
39409
  * data: { text: 'hello world' }
39538
39410
  * })
39539
39411
  * ```
39540
39412
  *
39541
- * Updates an {@link Amity.Comment}
39413
+ * Updates an {@link Amity.Post}
39542
39414
  *
39543
- * @param commentId The ID of the {@link Amity.Comment} to edit
39415
+ * @param postId The ID of the {@link Amity.Post} to edit
39544
39416
  * @param patch The patch data to apply
39545
- * @returns the updated {@link Amity.Comment} object
39417
+ * @returns the updated {@link Amity.Post} object
39546
39418
  *
39547
- * @category Comment API
39419
+ * @category Post API
39548
39420
  * @async
39549
39421
  */
39550
- const updateComment = async (commentId, patch) => {
39422
+ const editPost = async (postId, patch) => {
39551
39423
  const client = getActiveClient();
39552
- client.log('user/updateComment', patch);
39553
- const { data } = await client.http.put(`/api/v3/comments/${encodeURIComponent(commentId)}`, patch);
39424
+ client.log('user/editPost', patch);
39425
+ const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, patch);
39426
+ const data = prepareMembershipPayload(payload, 'communityUsers');
39554
39427
  const cachedAt = client.cache && Date.now();
39555
39428
  if (client.cache)
39556
39429
  ingestInCache(data, { cachedAt });
39557
- fireEvent('comment.updated', data);
39558
- const { comments } = data;
39430
+ fireEvent('local.post.updated', data);
39431
+ const { posts } = data;
39559
39432
  return {
39560
- data: LinkedObject.comment(comments.find(comment => comment.commentId === commentId)),
39433
+ data: LinkedObject.post(posts.find(post => post.postId === postId)),
39561
39434
  cachedAt,
39562
39435
  };
39563
39436
  };
39564
39437
  /* end_public_function */
39565
39438
 
39566
- // Due to we have optimistic logic, we will use referenceId as a id in SDK instead of storyId
39567
- const applyMissingField = (rawData, isCreated = false) => {
39568
- const { storyId, referenceId } = rawData;
39569
- if (!isCreated) {
39570
- if (referenceId)
39571
- return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */ });
39572
- }
39573
- return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */, referenceId: storyId });
39574
- };
39575
- const convertRawStoryToInternal = (data, isCreated = false) => {
39576
- const { stories } = data;
39577
- const storiesData = stories.map(story => applyMissingField(story, isCreated));
39578
- return Object.assign(Object.assign({}, data), { stories: storiesData });
39579
- };
39580
-
39581
- const getStoryByStoryId$1 = async (storyId) => {
39582
- const client = getActiveClient();
39583
- client.log('story/getStoryByStoryId', storyId);
39584
- // Get story referenceId from cache
39585
- const cacheReferenceId = pullFromCache([
39586
- "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
39587
- storyId,
39588
- ]);
39589
- if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
39590
- const { data: referenceId } = cacheReferenceId;
39591
- isInTombstone('story', referenceId);
39592
- }
39593
- let data;
39594
- try {
39595
- const response = await client.http.get(`/api/v4/stories/${storyId}`);
39596
- data = convertRawStoryToInternal(response.data);
39597
- }
39598
- catch (error) {
39599
- if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
39600
- pushToTombstone('story', storyId);
39601
- }
39602
- throw error;
39603
- }
39604
- const cachedAt = client.cache && Date.now();
39605
- if (client.cache) {
39606
- ingestInCache(data, { cachedAt });
39607
- }
39608
- return {
39609
- data: data.stories[0],
39610
- cachedAt,
39611
- };
39612
- };
39613
- getStoryByStoryId$1.locally = (storyId) => {
39614
- const client = getActiveClient();
39615
- client.log('story/getStorybyStoryId', storyId);
39616
- // Get story referenceId from cache
39617
- const cacheReferenceId = pullFromCache([
39618
- "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
39619
- storyId,
39620
- ]);
39621
- if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
39622
- const { data: referenceId } = cacheReferenceId;
39623
- isInTombstone('story', referenceId);
39624
- }
39625
- const cachedAt = client.cache && Date.now();
39626
- const storyCache = pullFromCache(['story', 'get', storyId]);
39627
- if (!storyCache)
39628
- return;
39629
- return {
39630
- data: storyCache.data,
39631
- cachedAt,
39632
- };
39633
- };
39634
-
39635
- /* begin_public_function
39636
- id: comment.soft_delete, comment.hard_delete
39637
- */
39638
39439
  /**
39639
39440
  * ```js
39640
- * import { CommentRepository } from '@amityco/ts-sdk'
39641
- * const success = await CommentRepository.deleteComment('foobar')
39441
+ * import { deletePost } from '@amityco/ts-sdk'
39442
+ * const success = await deletePost('foobar')
39642
39443
  * ```
39643
39444
  *
39644
- * Deletes a {@link Amity.Comment}
39445
+ * Deletes a {@link Amity.Post}
39645
39446
  *
39646
- * @param commentId The {@link Amity.Comment} ID to delete
39647
- * @return A success boolean if the {@link Amity.Comment} was deleted
39447
+ * @param postId The {@link Amity.Post} ID to delete
39448
+ * @return A success boolean if the {@link Amity.Post} was deleted
39648
39449
  *
39649
- * @category Comment API
39450
+ * @private
39650
39451
  * @async
39651
39452
  */
39652
- const deleteComment = async (commentId, permanent = false) => {
39453
+ const deletePost = async (postId, permanent = false) => {
39653
39454
  var _a;
39654
39455
  const client = getActiveClient();
39655
- const comment = await getComment$2(commentId);
39656
- // API-FIX: This endpoint has not been implemented yet.
39657
- await client.http.delete(`/api/v4/comments/${encodeURIComponent(commentId)}`, {
39456
+ const post = await getPost$2(postId);
39457
+ await client.http.delete(`/api/v4/posts/${encodeURIComponent(postId)}`, {
39658
39458
  params: {
39659
- commentId,
39459
+ postId,
39660
39460
  permanent,
39661
39461
  },
39662
39462
  });
39663
- // to support hard deletion
39664
- const deleted = Object.assign(Object.assign({}, comment.data), { isDeleted: true });
39665
- if (comment.data.referenceType === 'story') {
39666
- const story = await getStoryByStoryId$1(comment.data.referenceId);
39667
- fireEvent('local.story.updated', {
39668
- stories: [story.data],
39463
+ // there is currently a limitation which doesn't allow us to fire event to tell that community
39464
+ // has been updated. reason is that, when the object is deleted, we don't have its `communityId`
39465
+ // and so we cannot refetch the community or advertise on events. hopefully this should be solved
39466
+ // later when realtime events covers that for us.
39467
+ if (post.data.targetType === 'community') {
39468
+ const community = await getCommunity$1(post.data.targetId);
39469
+ const communityUsersCache = (_a = queryCache(['communityUsers', 'get'])) !== null && _a !== void 0 ? _a : [];
39470
+ const communityUsers = communityUsersCache
39471
+ .filter(({ key }) => {
39472
+ // cache key is ['communityUsers', 'get', `${communityId}#`${userId}`}]
39473
+ if (key[0] !== 'communityUsers')
39474
+ return false;
39475
+ if (key[1] !== 'get')
39476
+ return false;
39477
+ if (typeof key[2] === 'string')
39478
+ return key[2].includes(community.data.communityId);
39479
+ return false;
39480
+ })
39481
+ .map(({ data }) => data);
39482
+ fireEvent('community.updated', {
39483
+ communities: [community.data],
39669
39484
  categories: [],
39670
- comments: [],
39671
- communities: [],
39672
- communityUsers: [],
39485
+ communityUsers,
39486
+ feeds: [],
39673
39487
  files: [],
39674
39488
  users: [],
39675
39489
  });
39676
39490
  }
39491
+ // to support hard deletion
39492
+ const deleted = Object.assign(Object.assign({}, post.data), { isDeleted: true });
39493
+ if (permanent) {
39494
+ setTimeout(() => {
39495
+ pushToTombstone('post', postId);
39496
+ }, 0);
39497
+ }
39677
39498
  else {
39678
- const post = (_a = pullFromCache(['post', 'get', comment.data.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
39679
- if (post) {
39680
- let removeCount;
39681
- if (!deleted.parentId) {
39682
- // NOTE: delete the parent comment will remove all children comments
39683
- removeCount = deleted.childrenNumber + 1;
39684
- }
39685
- else
39686
- removeCount = 1;
39687
- post.commentsCount -= removeCount;
39688
- fireEvent('local.post.updated', {
39689
- posts: [post],
39690
- categories: [],
39691
- comments: [],
39692
- communities: [],
39693
- communityUsers: [],
39694
- feeds: [],
39695
- files: [],
39696
- postChildren: [],
39697
- users: [],
39698
- videoStreamings: [],
39699
- });
39700
- }
39499
+ upsertInCache(['post', 'get', postId], { isDeleted: true });
39701
39500
  }
39702
- fireEvent('local.comment.deleted', {
39703
- comments: [deleted],
39704
- commentChildren: [],
39501
+ fireEvent('local.post.deleted', {
39502
+ posts: [deleted],
39503
+ categories: [],
39504
+ comments: [],
39505
+ communities: [],
39506
+ communityUsers: [],
39507
+ feeds: [],
39705
39508
  files: [],
39509
+ postChildren: [],
39706
39510
  users: [],
39707
- communityUsers: [],
39511
+ videoStreamings: [],
39708
39512
  });
39709
- if (permanent) {
39710
- scheduleTask(() => pushToTombstone('comment', commentId));
39711
- }
39712
- else {
39713
- upsertInCache(['comment', 'get', commentId], { isDeleted: true });
39714
- }
39715
- return deleted;
39513
+ return LinkedObject.post(deleted);
39716
39514
  };
39717
- /* end_public_function */
39718
39515
 
39719
39516
  /* begin_public_function
39720
- id: comment.soft_delete
39517
+ id: post.soft_delete
39721
39518
  */
39722
39519
  /**
39723
39520
  * ```js
39724
- * import { CommentRepository } from '@amityco/ts-sdk'
39725
- * const success = await CommentRepository.softDeleteComment('foobar')
39521
+ * import { PostRepository } from '@amityco/ts-sdk'
39522
+ * const success = await PostRepository.softDeletePost('foobar')
39726
39523
  * ```
39727
39524
  *
39728
- * Deletes a {@link Amity.Comment}
39525
+ * Soft deletes a {@link Amity.Post}
39729
39526
  *
39730
- * @param commentId The {@link Amity.Comment} ID to delete
39731
- * @return A success boolean if the {@link Amity.Comment} was deleted
39527
+ * @param postId The {@link Amity.Post} ID to soft delete
39528
+ * @return A success boolean if the {@link Amity.Post} was deleted
39732
39529
  *
39733
- * @category Comment API
39530
+ * @category Post API
39734
39531
  * @async
39735
39532
  */
39736
- const softDeleteComment = async (commentId) => {
39533
+ const softDeletePost = async (postId) => {
39737
39534
  const client = getActiveClient();
39738
- client.log('comment/softDeleteComment', commentId);
39739
- const softDeleted = deleteComment(commentId);
39740
- return softDeleted;
39535
+ client.log('post/softDeletePost', postId);
39536
+ const softDeleted = await deletePost(postId, false);
39537
+ return LinkedObject.post(softDeleted);
39741
39538
  };
39742
39539
  /* end_public_function */
39743
39540
 
39744
39541
  /* begin_public_function
39745
- id: comment.hard_delete
39542
+ id: post.hard_delete
39746
39543
  */
39747
39544
  /**
39748
39545
  * ```js
39749
- * import { CommentRepository } from '@amityco/ts-sdk'
39750
- * const success = await CommentRepository.hardDeleteComment('foobar')
39546
+ * import { hardDeletePost } from '@amityco/ts-sdk'
39547
+ * const success = await hardDeletePost('foobar')
39751
39548
  * ```
39752
39549
  *
39753
- * Deletes a {@link Amity.Comment}
39550
+ * Hard deletes a {@link Amity.Post}
39754
39551
  *
39755
- * @param commentId The {@link Amity.Comment} ID to delete
39756
- * @return A success boolean if the {@link Amity.Comment} was deleted
39552
+ * @param postId The {@link Amity.Post} ID to be hard delete
39553
+ * @return A success boolean if the {@link Amity.Post} was deleted
39757
39554
  *
39758
- * @category Comment API
39555
+ * @category Post API
39759
39556
  * @async
39760
39557
  */
39761
- const hardDeleteComment = async (commentId) => {
39558
+ const hardDeletePost = async (postId) => {
39762
39559
  const client = getActiveClient();
39763
- client.log('comment/hardDeleteComment', commentId);
39764
- const hardDeleted = deleteComment(commentId, true);
39765
- return hardDeleted;
39560
+ client.log('post/hardDeletePost', postId);
39561
+ const hardDeleted = await deletePost(postId, true);
39562
+ return LinkedObject.post(hardDeleted);
39766
39563
  };
39767
39564
  /* end_public_function */
39768
39565
 
39769
39566
  /* begin_public_function
39770
- id: comment.flag
39567
+ id: post.approve
39771
39568
  */
39772
39569
  /**
39773
39570
  * ```js
39774
- * import { CommentRepository } from '@amityco/ts-sdk'
39775
- * const flagged = await CommentRepository.flagComment(commentId, reason)
39571
+ * import { approvePost } from '@amityco/ts-sdk'
39572
+ *
39573
+ * const { data: post } = await approvePost('postId')
39776
39574
  * ```
39777
39575
  *
39778
- * @param commentId The ID of the comment to flag
39779
- * @param reason the reason to flag the comment
39780
- * @returns the created report result
39576
+ * Approves a {@link Amity.Post}
39781
39577
  *
39782
- * @category Comment API
39578
+ * @param postId The {@link Amity.Post} ID to be approved
39579
+ * @return A {@link Amity.Post} that was approved
39580
+ *
39581
+ * @category Post API
39783
39582
  * @async
39784
- * */
39785
- const flagComment = async (commentId, reason) => {
39583
+ */
39584
+ const approvePost = async (postId) => {
39786
39585
  const client = getActiveClient();
39787
- client.log('comment/flagComment', commentId);
39788
- const isPredefinedReason = reason &&
39789
- Object.entries(ContentFlagReasonEnum).some(([key, value]) => key !== ContentFlagReasonEnum.Others && value === reason);
39790
- const body = {
39791
- reason: reason && isPredefinedReason ? reason : ContentFlagReasonEnum.Others,
39792
- detail: reason && !isPredefinedReason ? reason : '',
39793
- };
39794
- const { data: payload } = await client.http.post(`/api/v3/comments/${encodeURIComponent(commentId)}/flag`, body);
39795
- if (client.cache) {
39796
- ingestInCache(payload);
39797
- }
39798
- fireEvent('comment.flagged', payload);
39799
- return !!payload;
39586
+ client.log('post/approvePost', postId);
39587
+ const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/approve`);
39588
+ fireEvent('post.approved', payload);
39589
+ // fire virtual event for community update
39590
+ if (payload.posts[0].targetType === 'community') {
39591
+ fireEvent('community.updated', payload);
39592
+ }
39593
+ const data = prepareMembershipPayload(payload, 'communityUsers');
39594
+ const cachedAt = client.cache && Date.now();
39595
+ if (client.cache)
39596
+ ingestInCache(data, { cachedAt });
39597
+ return {
39598
+ data: LinkedObject.post(data.posts.find(post => post.postId === postId)),
39599
+ cachedAt,
39600
+ };
39800
39601
  };
39801
39602
  /* end_public_function */
39802
39603
 
39803
39604
  /* begin_public_function
39804
- id: comment.unflag
39605
+ id: post.decline
39805
39606
  */
39806
39607
  /**
39807
39608
  * ```js
39808
- * import { CommentRepository } from '@amityco/ts-sdk'
39809
- * const unflagged = await CommentRepository.unflagComment('commentId')
39609
+ * import { declinePost } from '@amityco/ts-sdk'
39610
+ *
39611
+ * const {data: post} = await declinePost('postId')
39810
39612
  * ```
39811
39613
  *
39812
- * @param commentId The ID of comment to unflag
39813
- * @returns the unflagged result
39614
+ * Declines a {@link Amity.Post}
39814
39615
  *
39815
- * @category Comment API
39616
+ * @param postId The {@link Amity.Post} ID to be declined
39617
+ * @return A {@link Amity.Post} that was declined
39618
+ *
39619
+ * @category Post API
39816
39620
  * @async
39817
- * */
39818
- const unflagComment = async (commentId) => {
39621
+ */
39622
+ const declinePost = async (postId) => {
39819
39623
  const client = getActiveClient();
39820
- client.log('comment/unflagComment', commentId);
39821
- const { data: payload } = await client.http.delete(`/api/v3/comments/${encodeURIComponent(commentId)}/unflag`);
39822
- if (client.cache) {
39823
- ingestInCache(payload);
39624
+ client.log('post/declinePost', postId);
39625
+ const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/decline`);
39626
+ // fire virtual event
39627
+ if (payload.posts[0].targetType === 'community') {
39628
+ fireEvent('community.updated', payload);
39824
39629
  }
39825
- fireEvent('comment.unflagged', payload);
39826
- return !!payload;
39630
+ fireEvent('post.declined', payload);
39631
+ const data = prepareMembershipPayload(payload, 'communityUsers');
39632
+ const cachedAt = client.cache && Date.now();
39633
+ if (client.cache)
39634
+ ingestInCache(data, { cachedAt });
39635
+ return {
39636
+ data: LinkedObject.post(payload.posts.find(post => post.postId === postId)),
39637
+ cachedAt,
39638
+ };
39827
39639
  };
39828
39640
  /* end_public_function */
39829
39641
 
39830
39642
  /* begin_public_function
39831
- id: comment.check_flag_by_me
39643
+ id: post.flag
39832
39644
  */
39833
39645
  /**
39834
39646
  * ```js
39835
- * import { CommentRepository } from '@amityco/ts-sdk'
39836
- * const isReported = await CommentRepository.isCommentFlaggedByMe('commentId')
39647
+ * import { PostRepository } from '@amityco/ts-sdk'
39648
+ * const flagged = await PostRepository.flagPost(postId, reason)
39837
39649
  * ```
39838
39650
  *
39839
- * @param commentId The ID of the comment to check if flagged by current user
39840
- * @returns `true` if the comment is flagged by me, `false` if doesn't.
39651
+ * @param postId of the post to flag
39652
+ * @param reason the reason to flag the post
39653
+ * @returns a boolean
39841
39654
  *
39842
- * @category Comment API
39655
+ * @category Post API
39843
39656
  * @async
39844
39657
  * */
39845
- const isCommentFlaggedByMe = async (commentId) => {
39846
- const client = getActiveClient();
39847
- client.log('comment/isCommentFlaggedByMe', commentId);
39848
- const { data: { result }, } = await client.http.get(`/api/v3/comments/${commentId}/isflagbyme`);
39849
- return result;
39850
- };
39851
- /* end_public_function */
39852
-
39853
- const getComment$1 = async (commentId) => {
39854
- const client = getActiveClient();
39855
- client.log('comment/getComment', commentId);
39856
- isInTombstone('comment', commentId);
39857
- let data;
39858
- try {
39859
- // API-FIX: endpoint should not be /list, parameters should be querystring.
39860
- const response = await client.http.get(`/api/v3/comments/${encodeURIComponent(commentId)}`);
39861
- data = response.data;
39862
- }
39863
- catch (error) {
39864
- if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
39865
- pushToTombstone('comment', commentId);
39866
- }
39867
- throw error;
39868
- }
39869
- const cachedAt = client.cache && Date.now();
39870
- if (client.cache)
39871
- ingestInCache(data, { cachedAt });
39872
- const { comments } = data;
39873
- return {
39874
- data: comments.find(comment => comment.commentId === commentId),
39875
- cachedAt,
39876
- };
39877
- };
39878
- getComment$1.locally = (commentId) => {
39658
+ const flagPost = async (postId, reason) => {
39879
39659
  const client = getActiveClient();
39880
- client.log('comment/getComment.locally', commentId);
39881
- if (!client.cache)
39882
- return;
39883
- const cached = pullFromCache(['comment', 'get', commentId]);
39884
- if (!cached)
39885
- return;
39886
- return {
39887
- data: cached.data,
39888
- cachedAt: cached.cachedAt,
39660
+ client.log('post/flagPost', postId);
39661
+ const isPredefinedReason = reason &&
39662
+ Object.entries(ContentFlagReasonEnum).some(([key, value]) => key !== ContentFlagReasonEnum.Others && value === reason);
39663
+ const body = {
39664
+ reason: reason && isPredefinedReason ? reason : ContentFlagReasonEnum.Others,
39665
+ detail: reason && !isPredefinedReason ? reason : '',
39889
39666
  };
39667
+ const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/flag`, body);
39668
+ if (client.cache) {
39669
+ ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
39670
+ }
39671
+ fireEvent('post.flagged', payload);
39672
+ return !!payload;
39890
39673
  };
39674
+ /* end_public_function */
39891
39675
 
39676
+ /* begin_public_function
39677
+ id: post.unflag
39678
+ */
39892
39679
  /**
39893
39680
  * ```js
39894
- * import { onCommentDeleteLocal } from '@amityco/ts-sdk'
39895
- * const dispose = onCommentDeleteLocal(comment => {
39896
- * // ...
39897
- * })
39681
+ * import { PostRepository } from '@amityco/ts-sdk'
39682
+ * const unflagged = await PostRepository.unflagPost(postId)
39898
39683
  * ```
39899
39684
  *
39900
- * Fired when a {@link Amity.InternalComment} has been deleted
39901
- *
39902
- * @param callback The function to call when the event was fired
39903
- * @returns an {@link Amity.Unsubscriber} function to stop listening
39685
+ * @param postId of the post to unflag
39686
+ * @returns the unflag post result
39904
39687
  *
39905
- * @category Comment Events
39906
- */
39907
- const onCommentDeleteLocal = (callback) => createLocalCommentEventSubscriber('local.comment.deleted', callback);
39688
+ * @category Post API
39689
+ * @async
39690
+ * */
39691
+ const unflagPost = async (postId) => {
39692
+ const client = getActiveClient();
39693
+ client.log('post/unflagPost', postId);
39694
+ const { data: payload } = await client.http.delete(`/api/v3/posts/${encodeURIComponent(postId)}/unflag`);
39695
+ if (client.cache) {
39696
+ ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
39697
+ }
39698
+ fireEvent('post.unflagged', payload);
39699
+ return !!payload;
39700
+ };
39701
+ /* end_public_function */
39908
39702
 
39703
+ /* begin_public_function
39704
+ id: post.check_flag_by_me
39705
+ */
39909
39706
  /**
39910
39707
  * ```js
39911
- * import { onLocalCommentReactionAdded } from '@amityco/ts-sdk'
39912
- * const dispose = onLocalCommentReactionAdded(comment => {
39913
- * // ...
39914
- * })
39708
+ * import { PostRepository } from '@amityco/ts-sdk'
39709
+ * const isReported = await PostRepository.isPostFlaggedByMe('post', postId)
39915
39710
  * ```
39916
39711
  *
39917
- * Fired when a {@link Amity.InternalComment} has been reacted
39918
- *
39919
- * @param callback The function to call when the event was fired
39920
- * @returns an {@link Amity.Unsubscriber} function to stop listening
39712
+ * @param postId of the post to check if flagged by current user
39713
+ * @returns `true` if the post is flagged by me, `false` if doesn't.
39921
39714
  *
39922
- * @category Comment Events
39923
- */
39924
- const onLocalCommentReactionAdded = (callback) => {
39715
+ * @category Post API
39716
+ * @async
39717
+ * */
39718
+ const isPostFlaggedByMe = async (postId) => {
39925
39719
  const client = getActiveClient();
39926
- const filter = ({ comment }) => {
39927
- if (!client.cache) {
39928
- callback(comment);
39929
- }
39930
- else {
39931
- upsertInCache(['comment', 'get', comment.commentId], comment);
39932
- callback(commentLinkedObject(comment));
39933
- }
39934
- };
39935
- return createEventSubscriber(client, 'local.comment.addReaction', 'local.comment.addReaction', filter);
39720
+ client.log('post/isPostFlaggedByMe', postId);
39721
+ const { data: { result }, } = await client.http.get(`/api/v3/posts/${postId}/isflagbyme`);
39722
+ return result;
39936
39723
  };
39724
+ /* end_public_function */
39937
39725
 
39726
+ /* begin_public_function
39727
+ id: post.create.clip_post
39728
+ */
39938
39729
  /**
39939
39730
  * ```js
39940
- * import { onLocalCommentReactionRemoved } from '@amityco/ts-sdk'
39941
- * const dispose = onLocalCommentReactionRemoved(comment => {
39942
- * // ...
39943
- * })
39731
+ * import { PostRepository } from '@amityco/ts-sdk'
39732
+ * const created = await PostRepository.createClipPost({
39733
+ * targetType: 'user',
39734
+ * targetId: 'foobar',
39735
+ * dataType: 'clip',
39736
+ * data: { text: 'hello world' },
39737
+ * attachments: [{ type: 'clip', fileId: 'fileId123', displayMode: 'fill', isMuted: false }]
39738
+ * }))
39944
39739
  * ```
39945
39740
  *
39946
- * Fired when a {@link Amity.InternalComment} has been reacted
39741
+ * Creates an {@link Amity.Post}
39947
39742
  *
39948
- * @param callback The function to call when the event was fired
39949
- * @returns an {@link Amity.Unsubscriber} function to stop listening
39743
+ * @param bundle The data necessary to create a new {@link Amity.Post}
39744
+ * @returns The newly created {@link Amity.Post}
39950
39745
  *
39951
- * @category Comment Events
39746
+ * @category Post API
39747
+ * @async
39952
39748
  */
39953
- const onLocalCommentReactionRemoved = (callback) => {
39749
+ const createClipPost = async (bundle) => {
39954
39750
  const client = getActiveClient();
39955
- const filter = ({ comment }) => {
39956
- if (!client.cache) {
39957
- callback(comment);
39958
- }
39959
- else {
39960
- upsertInCache(['comment', 'get', comment.commentId], comment);
39961
- callback(commentLinkedObject(comment));
39962
- }
39751
+ client.log('post/createPost', bundle);
39752
+ const { data: payload } = await client.http.post('/api/v4/posts', bundle);
39753
+ fireEvent('post.created', payload);
39754
+ const data = prepareMembershipPayload(payload, 'communityUsers');
39755
+ const cachedAt = client.cache && Date.now();
39756
+ if (client.cache)
39757
+ ingestInCache(data, { cachedAt });
39758
+ const { posts } = data;
39759
+ return {
39760
+ data: LinkedObject.post(posts[0]),
39761
+ cachedAt,
39963
39762
  };
39964
- return createEventSubscriber(client, 'local.comment.removeReaction', 'local.comment.removeReaction', filter);
39965
39763
  };
39764
+ /* end_public_function */
39966
39765
 
39967
- /* begin_public_function
39968
- id: comment.get
39969
- */
39970
39766
  /**
39971
39767
  * ```js
39972
- * import { CommentRepository } from '@amityco/ts-sdk';
39973
- *
39974
- * let comment;
39975
- *
39976
- * const unsub = CommentRepository.getComment(commentId, response => {
39977
- * comment = response.data;
39978
- * });
39768
+ * import { searchPostsByHashtag } from '@amityco/ts-sdk'
39769
+ * const { data: posts, prevPage, nextPage } = await searchPostsByHashtag({ hashtags: ['amity'], limit: 10 });
39979
39770
  * ```
39980
39771
  *
39981
- * Observe all mutation on a given {@link Amity.Comment}
39772
+ * Queries a paginable list of {@link Amity.Post} objects
39982
39773
  *
39983
- * @param commentId the ID of the comment to observe
39984
- * @param callback the function to call when new data are available
39985
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the comment
39774
+ * @param query The query parameters
39775
+ * @returns posts
39986
39776
  *
39987
- * @category Comment Live Object
39777
+ * @category Post API
39778
+ * @async
39988
39779
  */
39989
- const getComment = (commentId, callback) => {
39990
- return liveObject(commentId, callback, 'commentId', getComment$1, [
39991
- onCommentDeleteLocal,
39992
- onCommentDeleted,
39993
- onCommentFlagged,
39994
- onCommentReactionAdded,
39995
- onCommentReactionRemoved,
39996
- onCommentUnflagged,
39997
- onCommentUpdated,
39998
- onLocalCommentReactionAdded,
39999
- onLocalCommentReactionRemoved,
40000
- ]);
39780
+ const getPostsByHashtag = async (query) => {
39781
+ const client = getActiveClient();
39782
+ client.log('post/queryByHashtag', query);
39783
+ const { page, limit = 10 } = query, params = __rest(query, ["page", "limit"]);
39784
+ const { dataTypes, matchingOnlyParentPost, hashtags } = params;
39785
+ const options = (() => {
39786
+ if (page)
39787
+ return { token: page };
39788
+ if (limit)
39789
+ return { limit };
39790
+ return undefined;
39791
+ })();
39792
+ // API-FIX: parameters should be querystring. (1)
39793
+ // API-FIX: backend should answer Amity.Response (2)
39794
+ // const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<Amity.PostPayload>>>(
39795
+ const { data } = await client.http.get(`/api/v5/posts`, {
39796
+ params: Object.assign(Object.assign({}, params), { hashtags,
39797
+ /*
39798
+ * when creating post like image, file, video BE will create 2 posts
39799
+ * 1. parent post to store text with dataType=text
39800
+ * 2. child post to store dataTypes post data
39801
+ *
39802
+ * By default, BE queries only parent post
39803
+ */
39804
+ matchingOnlyParentPost: matchingOnlyParentPost !== null && matchingOnlyParentPost !== void 0 ? matchingOnlyParentPost : !(dataTypes === null || dataTypes === void 0 ? void 0 : dataTypes.length), options }),
39805
+ });
39806
+ // API-FIX: backend should answer Amity.Response (2)
39807
+ // const { paging, posts } = unwrapPayload(data)
39808
+ // unpacking
39809
+ const { paging } = data, payload = __rest(data, ["paging"]);
39810
+ const paperedPayload = prepareMembershipPayload(payload, 'communityUsers');
39811
+ const { posts } = payload;
39812
+ const cachedAt = client.cache && Date.now();
39813
+ if (client.cache) {
39814
+ ingestInCache(paperedPayload, { cachedAt });
39815
+ const cacheKey = ['post', 'query', Object.assign(Object.assign({}, params), { options })];
39816
+ pushToCache(cacheKey, { posts: posts.map(getResolver('post')), paging });
39817
+ }
39818
+ return { data: posts.map(LinkedObject.post), cachedAt, paging };
40001
39819
  };
40002
- /* end_public_function */
40003
39820
 
40004
- class CommentPaginationController extends PaginationController {
40005
- async getRequest(queryParams, token) {
40006
- const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
40007
- const baseOptions = {
40008
- type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
40009
- };
40010
- const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
40011
- const { data: queryResponse } = await this.http.get(`/api/v3/comments`, {
40012
- params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options }),
39821
+ /* begin_public_function
39822
+ id: comment.get_by_ids
39823
+ */
39824
+ /**
39825
+ * ```js
39826
+ * import { CommentRepository } from '@amityco/ts-sdk'
39827
+ * const comments = await CommentRepository.getCommentByIds(['foo', 'bar'])
39828
+ * ```
39829
+ *
39830
+ * Fetches a collection of {@link Amity.Comment} objects
39831
+ *
39832
+ * @param commentIds the IDs of the {@link Amity.Comment} to fetch
39833
+ * @returns the associated collection of {@link Amity.Comment} objects
39834
+ *
39835
+ * @category Comment API
39836
+ * @async
39837
+ */
39838
+ const getCommentByIds = async (commentIds) => {
39839
+ const client = getActiveClient();
39840
+ client.log('comment/getCommentByIds', commentIds);
39841
+ const encodedCommentIds = commentIds.map(commentId => encodeURIComponent(commentId));
39842
+ let data;
39843
+ try {
39844
+ // API-FIX: endpoint should not be /list, parameters should be querystring.
39845
+ const response = await client.http.get(`/api/v3/comments/list`, {
39846
+ params: { commentIds: encodedCommentIds },
40013
39847
  });
40014
- return queryResponse;
40015
- }
40016
- }
40017
-
40018
- var EnumCommentActions;
40019
- (function (EnumCommentActions) {
40020
- EnumCommentActions["OnCommentCreated"] = "onCommentCreated";
40021
- EnumCommentActions["OnCommentUpdated"] = "onCommentUpdated";
40022
- EnumCommentActions["OnCommentDeleted"] = "onCommentDeleted";
40023
- EnumCommentActions["OnCommentFlagged"] = "onCommentFlagged";
40024
- EnumCommentActions["OnCommentUnflagged"] = "onCommentUnflagged";
40025
- EnumCommentActions["OnCommentReactionAdded"] = "onCommentReactionAdded";
40026
- EnumCommentActions["OnCommentReactionRemoved"] = "onCommentReactionRemoved";
40027
- })(EnumCommentActions || (EnumCommentActions = {}));
40028
-
40029
- class CommentQueryStreamController extends QueryStreamController {
40030
- constructor(query, cacheKey, notifyChange, preparePayload) {
40031
- super(query, cacheKey);
40032
- this.notifyChange = notifyChange;
40033
- this.preparePayload = preparePayload;
40034
- }
40035
- async saveToMainDB(response) {
40036
- const processedPayload = await this.preparePayload(response);
40037
- const client = getActiveClient();
40038
- const cachedAt = client.cache && Date.now();
40039
- if (client.cache) {
40040
- ingestInCache(processedPayload, { cachedAt });
40041
- }
40042
- }
40043
- appendToQueryStream(response, direction, refresh = false) {
40044
- var _a, _b;
40045
- if (refresh) {
40046
- pushToCache(this.cacheKey, {
40047
- data: response.comments.map(getResolver('comment')),
40048
- });
40049
- }
40050
- else {
40051
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40052
- const comments = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
40053
- pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...comments, ...response.comments.map(getResolver('comment'))])] }));
40054
- }
39848
+ data = response.data;
40055
39849
  }
40056
- reactor(action) {
40057
- return (comment) => {
40058
- var _a;
40059
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40060
- if (this.query.referenceId !== comment.referenceId ||
40061
- this.query.referenceType !== comment.referenceType ||
40062
- !collection) {
40063
- return;
40064
- }
40065
- if (this.query.parentId && this.query.parentId !== comment.parentId) {
40066
- return;
40067
- }
40068
- if (!this.query.parentId && comment.parentId) {
40069
- return;
40070
- }
40071
- if (action === EnumCommentActions.OnCommentCreated) {
40072
- collection.data = [...new Set([comment.commentId, ...collection.data])];
39850
+ catch (error) {
39851
+ commentIds.forEach(commentId => {
39852
+ if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
39853
+ pushToTombstone('comment', commentId);
40073
39854
  }
40074
- pushToCache(this.cacheKey, collection);
40075
- this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
40076
- };
40077
- }
40078
- subscribeRTE(createSubscriber) {
40079
- return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
39855
+ });
39856
+ throw error;
40080
39857
  }
40081
- }
40082
-
39858
+ const cachedAt = client.cache && Date.now();
39859
+ if (client.cache)
39860
+ ingestInCache(data, { cachedAt });
39861
+ return {
39862
+ data: data.comments.map(comment => LinkedObject.comment(comment)),
39863
+ cachedAt,
39864
+ };
39865
+ };
39866
+ /* end_public_function */
40083
39867
  /**
40084
39868
  * ```js
40085
- * import { onCommentCreated } from '@amityco/ts-sdk'
40086
- * const dispose = onCommentCreated(comment => {
40087
- * // ...
40088
- * })
39869
+ * import { getCommentByIds } from '@amityco/ts-sdk'
39870
+ * const comments = getCommentByIds.locally(['foo', 'bar'])
40089
39871
  * ```
40090
39872
  *
40091
- * Fired when a {@link Amity.InternalComment} has been created
39873
+ * Fetches a collection of {@link Amity.Comment} objects from cache
40092
39874
  *
40093
- * @param callback The function to call when the event was fired
40094
- * @returns an {@link Amity.Unsubscriber} function to stop listening
39875
+ * @param commentIds the IDs of the {@link Amity.Comment} to fetch
39876
+ * @returns the associated collection of {@link Amity.Comment} objects
40095
39877
  *
40096
- * @category Comment Events
39878
+ * @category Comment API
40097
39879
  */
40098
- const onCommentCreatedLocal = (callback) => {
40099
- return createLocalCommentEventSubscriber('local.comment.created', callback);
39880
+ getCommentByIds.locally = (commentIds) => {
39881
+ var _a;
39882
+ const client = getActiveClient();
39883
+ client.log('comment/getCommentByIds.locally', commentIds);
39884
+ if (!client.cache)
39885
+ return;
39886
+ const cached = commentIds
39887
+ .map(commentId => pullFromCache(['comment', 'get', commentId]))
39888
+ .filter(Boolean);
39889
+ const comments = cached.map(({ data }) => data);
39890
+ const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
39891
+ if ((cached === null || cached === void 0 ? void 0 : cached.length) < commentIds.length)
39892
+ return;
39893
+ return {
39894
+ data: comments.map(comment => LinkedObject.comment(comment)),
39895
+ cachedAt: oldest.cachedAt,
39896
+ };
40100
39897
  };
40101
39898
 
40102
- class CommentLiveCollectionController extends LiveCollectionController {
40103
- constructor(query, callback) {
40104
- const queryStreamId = hash(query);
40105
- const cacheKey = ['comments', 'collection', queryStreamId];
40106
- const paginationController = new CommentPaginationController(query);
40107
- super(paginationController, queryStreamId, cacheKey, callback);
40108
- this.query = query;
40109
- this.queryStreamController = new CommentQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommentPayload);
40110
- this.callback = callback.bind(this);
40111
- this.loadPage({ initial: true });
40112
- }
40113
- setup() {
40114
- var _a;
40115
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40116
- if (!collection) {
40117
- pushToCache(this.cacheKey, {
40118
- data: [],
40119
- params: {},
39899
+ /* begin_public_function
39900
+ id: comment.create
39901
+ */
39902
+ /**
39903
+ * ```js
39904
+ * import { CommentRepository } from '@amityco/ts-sdk'
39905
+ * const newComment = await CommentRepository.createComment(bundle)
39906
+ * ```
39907
+ *
39908
+ * Creates an {@link Amity.Comment}
39909
+ *
39910
+ * @param bundle The data necessary to create a new {@link Amity.Comment}
39911
+ * @returns The newly created {@link Amity.Comment}
39912
+ *
39913
+ * @category Comment API
39914
+ * @async
39915
+ */
39916
+ const createComment = async (bundle) => {
39917
+ var _a;
39918
+ const client = getActiveClient();
39919
+ client.log('comment/createComment', bundle);
39920
+ const { data } = await client.http.post('/api/v3/comments', bundle);
39921
+ const { comments } = data;
39922
+ // BE always returns an array of comments If it got record 0 from BE it might have a problem on creation logic
39923
+ if (comments.length === 0)
39924
+ throw new Error('Comment not created');
39925
+ const cachedAt = client.cache && Date.now();
39926
+ if (client.cache)
39927
+ ingestInCache(data, { cachedAt });
39928
+ if (['post', 'content'].includes(bundle.referenceType)) {
39929
+ const post = (_a = pullFromCache(['post', 'get', bundle.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
39930
+ if (post) {
39931
+ post.commentsCount += 1;
39932
+ fireEvent('local.post.updated', {
39933
+ posts: [post],
39934
+ categories: [],
39935
+ comments: [],
39936
+ communities: [],
39937
+ communityUsers: data.communityUsers,
39938
+ feeds: [],
39939
+ files: data.files,
39940
+ postChildren: [],
39941
+ users: data.users,
39942
+ videoStreamings: [],
40120
39943
  });
40121
39944
  }
40122
39945
  }
40123
- async persistModel(queryPayload) {
40124
- await this.queryStreamController.saveToMainDB(queryPayload);
40125
- }
40126
- persistQueryStream({ response, direction, refresh, }) {
40127
- this.queryStreamController.appendToQueryStream(response, direction, refresh);
40128
- }
40129
- startSubscription() {
40130
- return this.queryStreamController.subscribeRTE([
40131
- { fn: onCommentCreatedLocal, action: EnumCommentActions.OnCommentCreated },
40132
- { fn: onCommentDeleteLocal, action: EnumCommentActions.OnCommentDeleted },
40133
- { fn: onCommentCreated, action: EnumCommentActions.OnCommentCreated },
40134
- { fn: onCommentUpdated, action: EnumCommentActions.OnCommentUpdated },
40135
- { fn: onCommentDeleted, action: EnumCommentActions.OnCommentDeleted },
40136
- { fn: onCommentFlagged, action: EnumCommentActions.OnCommentFlagged },
40137
- { fn: onCommentUnflagged, action: EnumCommentActions.OnCommentUnflagged },
40138
- { fn: onCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
40139
- { fn: onCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
40140
- { fn: onLocalCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
40141
- { fn: onLocalCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
39946
+ else if (bundle.referenceType === 'story') {
39947
+ const storyIndex = pullFromCache([
39948
+ "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
39949
+ bundle.referenceId,
40142
39950
  ]);
40143
- }
40144
- notifyChange({ origin, loading, error }) {
40145
- var _a, _b;
40146
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40147
- if (!collection)
40148
- return;
40149
- const data = this.applyFilter((_b = collection.data
40150
- .map(id => pullFromCache(['comment', 'get', id]))
40151
- .filter(isNonNullable)
40152
- .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.comment);
40153
- if (!this.shouldNotify(data) && origin === 'event')
40154
- return;
40155
- this.callback({
40156
- onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
40157
- data,
40158
- hasNextPage: !!this.paginationController.getNextToken(),
40159
- loading,
40160
- error,
40161
- });
40162
- }
40163
- applyFilter(data) {
40164
- let comments = data;
40165
- if (!this.query.includeDeleted) {
40166
- comments = filterByPropEquality(comments, 'isDeleted', false);
40167
- }
40168
- if (this.query.parentId) {
40169
- comments = comments.filter(comment => comment.parentId === this.query.parentId);
40170
- }
40171
- if (typeof this.query.hasFlag === 'boolean') {
40172
- if (this.query.hasFlag) {
40173
- comments = comments.filter(comment => comment.hashFlag != null);
40174
- }
40175
- else {
40176
- comments = comments.filter(comment => comment.hashFlag == null);
40177
- }
40178
- }
40179
- if (this.query.dataTypes) {
40180
- if (this.query.dataTypes.matchType === 'exact') {
40181
- comments = comments.filter(comment => {
40182
- var _a, _b;
40183
- const sortedDataTypesQueryValue = ((_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.values.sort()) || [];
40184
- const sortedDataTypesCommentValue = ((_b = comment.dataTypes) === null || _b === void 0 ? void 0 : _b.sort()) || [];
40185
- if (sortedDataTypesCommentValue.length !== sortedDataTypesQueryValue.length) {
40186
- return false;
40187
- }
40188
- return sortedDataTypesQueryValue.every((value, index) => value === sortedDataTypesCommentValue[index]);
39951
+ if (storyIndex === null || storyIndex === void 0 ? void 0 : storyIndex.data) {
39952
+ const cacheStory = pullFromCache([
39953
+ "story" /* STORY_KEY_CACHE.STORY */,
39954
+ 'get',
39955
+ storyIndex.data,
39956
+ ]);
39957
+ if (cacheStory === null || cacheStory === void 0 ? void 0 : cacheStory.data) {
39958
+ fireEvent('story.updated', {
39959
+ stories: [
39960
+ Object.assign(Object.assign({}, cacheStory.data), { commentsCount: cacheStory.data.commentsCount + 1, comments: [...new Set([...cacheStory.data.comments, comments[0].commentId])] }),
39961
+ ],
39962
+ categories: [],
39963
+ comments,
39964
+ communities: [],
39965
+ communityUsers: data.communityUsers,
39966
+ files: data.files,
39967
+ users: data.users,
40189
39968
  });
40190
39969
  }
40191
- if (this.query.dataTypes.matchType === 'any') {
40192
- comments = comments.filter(comment => { var _a; return (_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.values.some(value => { var _a; return (_a = comment.dataTypes) === null || _a === void 0 ? void 0 : _a.includes(value); }); });
40193
- }
40194
- }
40195
- switch (this.query.sortBy) {
40196
- case 'firstCreated':
40197
- comments = comments.sort(sortByFirstCreated);
40198
- break;
40199
- case 'lastCreated':
40200
- default:
40201
- comments = comments.sort(sortByLastCreated);
40202
- break;
40203
39970
  }
40204
- return comments;
40205
39971
  }
40206
- }
39972
+ fireEvent('local.comment.created', data);
39973
+ return {
39974
+ data: LinkedObject.comment(comments[0]),
39975
+ cachedAt,
39976
+ };
39977
+ };
39978
+ /* end_public_function */
40207
39979
 
40208
39980
  /* begin_public_function
40209
- id: comment.query
39981
+ id: comment.update_comment
40210
39982
  */
40211
39983
  /**
40212
39984
  * ```js
40213
- * import { getComments } from '@amityco/ts-sdk'
40214
- *
40215
- * let comments = []
40216
- * const unsub = getComments({
40217
- * referenceType: Amity.InternalComment['referenceType'];
40218
- * referenceId: Amity.InternalComment['referenceId'];
40219
- * }, response => merge(comments, response.data))
39985
+ * import { CommentRepository } from '@amityco/ts-sdk'
39986
+ * const updated = await CommentRepository.updateComment(commentId, {
39987
+ * data: { text: 'hello world' }
39988
+ * })
40220
39989
  * ```
40221
39990
  *
40222
- * Observe all mutations on a list of {@link Amity.InternalComment} for a given target object
39991
+ * Updates an {@link Amity.Comment}
40223
39992
  *
40224
- * @param referenceType the type of the target
40225
- * @param referenceId the ID of the target
40226
- * @param callback the function to call when new data are available
40227
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
39993
+ * @param commentId The ID of the {@link Amity.Comment} to edit
39994
+ * @param patch The patch data to apply
39995
+ * @returns the updated {@link Amity.Comment} object
40228
39996
  *
40229
- * @category Comments Live Collection
39997
+ * @category Comment API
39998
+ * @async
40230
39999
  */
40231
- const getComments = (params, callback, config) => {
40232
- const { log, cache } = getActiveClient();
40233
- if (!cache) {
40234
- console.log('For using Live Collection feature you need to enable Cache!');
40235
- }
40236
- const timestamp = Date.now();
40237
- log(`getComments(tmpid: ${timestamp}) > listen`);
40238
- const commentsLiveCollection = new CommentLiveCollectionController(params, callback);
40239
- const disposers = commentsLiveCollection.startSubscription();
40240
- const cacheKey = commentsLiveCollection.getCacheKey();
40241
- disposers.push(() => dropFromCache(cacheKey));
40242
- return () => {
40243
- log(`getComments(tmpid: ${timestamp}) > dispose`);
40244
- disposers.forEach(fn => fn());
40000
+ const updateComment = async (commentId, patch) => {
40001
+ const client = getActiveClient();
40002
+ client.log('user/updateComment', patch);
40003
+ const { data } = await client.http.put(`/api/v3/comments/${encodeURIComponent(commentId)}`, patch);
40004
+ const cachedAt = client.cache && Date.now();
40005
+ if (client.cache)
40006
+ ingestInCache(data, { cachedAt });
40007
+ fireEvent('comment.updated', data);
40008
+ const { comments } = data;
40009
+ return {
40010
+ data: LinkedObject.comment(comments.find(comment => comment.commentId === commentId)),
40011
+ cachedAt,
40245
40012
  };
40246
40013
  };
40247
40014
  /* end_public_function */
40248
40015
 
40249
- var index$a = /*#__PURE__*/Object.freeze({
40250
- __proto__: null,
40251
- getCommentByIds: getCommentByIds,
40252
- createComment: createComment,
40253
- updateComment: updateComment,
40254
- deleteComment: deleteComment,
40255
- softDeleteComment: softDeleteComment,
40256
- hardDeleteComment: hardDeleteComment,
40257
- flagComment: flagComment,
40258
- unflagComment: unflagComment,
40259
- isCommentFlaggedByMe: isCommentFlaggedByMe,
40260
- onCommentCreated: onCommentCreated,
40261
- onCommentUpdated: onCommentUpdated,
40262
- onCommentDeleted: onCommentDeleted,
40263
- onCommentFlagged: onCommentFlagged,
40264
- onCommentUnflagged: onCommentUnflagged,
40265
- onCommentReactionAdded: onCommentReactionAdded,
40266
- onCommentReactionRemoved: onCommentReactionRemoved,
40267
- getComment: getComment,
40268
- getComments: getComments
40269
- });
40016
+ // Due to we have optimistic logic, we will use referenceId as a id in SDK instead of storyId
40017
+ const applyMissingField = (rawData, isCreated = false) => {
40018
+ const { storyId, referenceId } = rawData;
40019
+ if (!isCreated) {
40020
+ if (referenceId)
40021
+ return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */ });
40022
+ }
40023
+ return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */, referenceId: storyId });
40024
+ };
40025
+ const convertRawStoryToInternal = (data, isCreated = false) => {
40026
+ const { stories } = data;
40027
+ const storiesData = stories.map(story => applyMissingField(story, isCreated));
40028
+ return Object.assign(Object.assign({}, data), { stories: storiesData });
40029
+ };
40270
40030
 
40271
- const getPost$1 = async (postId) => {
40031
+ const getStoryByStoryId$1 = async (storyId) => {
40272
40032
  const client = getActiveClient();
40273
- client.log('post/getPost', postId);
40274
- isInTombstone('post', postId);
40275
- let payload;
40033
+ client.log('story/getStoryByStoryId', storyId);
40034
+ // Get story referenceId from cache
40035
+ const cacheReferenceId = pullFromCache([
40036
+ "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
40037
+ storyId,
40038
+ ]);
40039
+ if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
40040
+ const { data: referenceId } = cacheReferenceId;
40041
+ isInTombstone('story', referenceId);
40042
+ }
40043
+ let data;
40276
40044
  try {
40277
- // API-FIX: endpoint should not be /list, parameters should be querystring.
40278
- const response = await client.http.get(`/api/v3/posts/${encodeURIComponent(postId)}`);
40279
- payload = response.data;
40045
+ const response = await client.http.get(`/api/v4/stories/${storyId}`);
40046
+ data = convertRawStoryToInternal(response.data);
40280
40047
  }
40281
40048
  catch (error) {
40282
40049
  if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
40283
- pushToTombstone('post', postId);
40050
+ pushToTombstone('story', storyId);
40284
40051
  }
40285
40052
  throw error;
40286
40053
  }
40287
- const data = prepareMembershipPayload(payload, 'communityUsers');
40288
40054
  const cachedAt = client.cache && Date.now();
40289
- if (client.cache)
40055
+ if (client.cache) {
40290
40056
  ingestInCache(data, { cachedAt });
40291
- const { posts } = data;
40292
- const result = posts.find(post => post.postId === postId);
40057
+ }
40293
40058
  return {
40294
- data: result,
40059
+ data: data.stories[0],
40295
40060
  cachedAt,
40296
40061
  };
40297
40062
  };
40298
- getPost$1.locally = (postId) => {
40063
+ getStoryByStoryId$1.locally = (storyId) => {
40299
40064
  const client = getActiveClient();
40300
- client.log('post/getPost.locally', postId);
40301
- if (!client.cache)
40302
- return;
40303
- const cached = pullFromCache(['post', 'get', postId]);
40304
- if (!cached)
40065
+ client.log('story/getStorybyStoryId', storyId);
40066
+ // Get story referenceId from cache
40067
+ const cacheReferenceId = pullFromCache([
40068
+ "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
40069
+ storyId,
40070
+ ]);
40071
+ if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
40072
+ const { data: referenceId } = cacheReferenceId;
40073
+ isInTombstone('story', referenceId);
40074
+ }
40075
+ const cachedAt = client.cache && Date.now();
40076
+ const storyCache = pullFromCache(['story', 'get', storyId]);
40077
+ if (!storyCache)
40305
40078
  return;
40306
40079
  return {
40307
- data: cached.data,
40308
- cachedAt: cached.cachedAt,
40080
+ data: storyCache.data,
40081
+ cachedAt,
40309
40082
  };
40310
40083
  };
40311
40084
 
40085
+ /* begin_public_function
40086
+ id: comment.soft_delete, comment.hard_delete
40087
+ */
40312
40088
  /**
40313
40089
  * ```js
40314
- * import { onPostUpdatedLocal } from '@amityco/ts-sdk'
40315
- * const dispose = onPostUpdatedLocal(post => {
40316
- * // ...
40317
- * })
40318
- * ```
40319
- *
40320
- * Fired when a {@link Amity.InternalPost} has been updated
40321
- *
40322
- * @param callback The function to call when the event was fired
40323
- * @returns an {@link Amity.Unsubscriber} function to stop listening
40324
- *
40325
- * @category Post Events
40326
- */
40327
- const onPostUpdatedLocal = (callback) => createLocalPostEventSubscriber('local.post.updated', callback);
40328
-
40329
- /**
40330
- * ```js
40331
- * import { onLocalPostReactionAdded } from '@amityco/ts-sdk'
40332
- * const dispose = onPostReactionAdded(post => {
40333
- * // ...
40334
- * })
40090
+ * import { CommentRepository } from '@amityco/ts-sdk'
40091
+ * const success = await CommentRepository.deleteComment('foobar')
40335
40092
  * ```
40336
40093
  *
40337
- * Fired when a {@link Amity.InternalPost} has been reacted
40094
+ * Deletes a {@link Amity.Comment}
40338
40095
  *
40339
- * @param callback The function to call when the event was fired
40340
- * @returns an {@link Amity.Unsubscriber} function to stop listening
40096
+ * @param commentId The {@link Amity.Comment} ID to delete
40097
+ * @return A success boolean if the {@link Amity.Comment} was deleted
40341
40098
  *
40342
- * @category Post Events
40099
+ * @category Comment API
40100
+ * @async
40343
40101
  */
40344
- const onLocalPostReactionAdded = (callback) => {
40102
+ const deleteComment = async (commentId, permanent = false) => {
40103
+ var _a;
40345
40104
  const client = getActiveClient();
40346
- const filter = ({ post }) => {
40347
- if (!client.cache) {
40348
- callback(post);
40349
- }
40350
- else {
40351
- upsertInCache(['post', 'get', post.postId], post);
40352
- callback(post);
40105
+ const comment = await getComment$2(commentId);
40106
+ // API-FIX: This endpoint has not been implemented yet.
40107
+ await client.http.delete(`/api/v4/comments/${encodeURIComponent(commentId)}`, {
40108
+ params: {
40109
+ commentId,
40110
+ permanent,
40111
+ },
40112
+ });
40113
+ // to support hard deletion
40114
+ const deleted = Object.assign(Object.assign({}, comment.data), { isDeleted: true });
40115
+ if (comment.data.referenceType === 'story') {
40116
+ const story = await getStoryByStoryId$1(comment.data.referenceId);
40117
+ fireEvent('local.story.updated', {
40118
+ stories: [story.data],
40119
+ categories: [],
40120
+ comments: [],
40121
+ communities: [],
40122
+ communityUsers: [],
40123
+ files: [],
40124
+ users: [],
40125
+ });
40126
+ }
40127
+ else {
40128
+ const post = (_a = pullFromCache(['post', 'get', comment.data.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
40129
+ if (post) {
40130
+ let removeCount;
40131
+ if (!deleted.parentId) {
40132
+ // NOTE: delete the parent comment will remove all children comments
40133
+ removeCount = deleted.childrenNumber + 1;
40134
+ }
40135
+ else
40136
+ removeCount = 1;
40137
+ post.commentsCount -= removeCount;
40138
+ fireEvent('local.post.updated', {
40139
+ posts: [post],
40140
+ categories: [],
40141
+ comments: [],
40142
+ communities: [],
40143
+ communityUsers: [],
40144
+ feeds: [],
40145
+ files: [],
40146
+ postChildren: [],
40147
+ users: [],
40148
+ videoStreamings: [],
40149
+ });
40353
40150
  }
40354
- };
40355
- return createEventSubscriber(client, 'local.post.addReaction', 'local.post.addReaction', filter);
40151
+ }
40152
+ fireEvent('local.comment.deleted', {
40153
+ comments: [deleted],
40154
+ commentChildren: [],
40155
+ files: [],
40156
+ users: [],
40157
+ communityUsers: [],
40158
+ });
40159
+ if (permanent) {
40160
+ scheduleTask(() => pushToTombstone('comment', commentId));
40161
+ }
40162
+ else {
40163
+ upsertInCache(['comment', 'get', commentId], { isDeleted: true });
40164
+ }
40165
+ return deleted;
40356
40166
  };
40167
+ /* end_public_function */
40357
40168
 
40169
+ /* begin_public_function
40170
+ id: comment.soft_delete
40171
+ */
40358
40172
  /**
40359
40173
  * ```js
40360
- * import { onLocalPostReactionRemoved } from '@amityco/ts-sdk'
40361
- * const dispose = onPostReactionRemoved(post => {
40362
- * // ...
40363
- * })
40174
+ * import { CommentRepository } from '@amityco/ts-sdk'
40175
+ * const success = await CommentRepository.softDeleteComment('foobar')
40364
40176
  * ```
40365
40177
  *
40366
- * Fired when a {@link Amity.InternalPost} has been reacted
40178
+ * Deletes a {@link Amity.Comment}
40367
40179
  *
40368
- * @param callback The function to call when the event was fired
40369
- * @returns an {@link Amity.Unsubscriber} function to stop listening
40180
+ * @param commentId The {@link Amity.Comment} ID to delete
40181
+ * @return A success boolean if the {@link Amity.Comment} was deleted
40370
40182
  *
40371
- * @category Post Events
40183
+ * @category Comment API
40184
+ * @async
40372
40185
  */
40373
- const onLocalPostReactionRemoved = (callback) => {
40186
+ const softDeleteComment = async (commentId) => {
40374
40187
  const client = getActiveClient();
40375
- const filter = ({ post }) => {
40376
- if (!client.cache) {
40377
- callback(post);
40378
- }
40379
- else {
40380
- upsertInCache(['post', 'get', post.postId], post);
40381
- callback(post);
40382
- }
40383
- };
40384
- return createEventSubscriber(client, 'local.post.removeReaction', 'local.post.removeReaction', filter);
40188
+ client.log('comment/softDeleteComment', commentId);
40189
+ const softDeleted = deleteComment(commentId);
40190
+ return softDeleted;
40385
40191
  };
40386
-
40387
- /**
40388
- * ```js
40389
- * import { onLocalPostDeleted } from '@amityco/ts-sdk'
40390
- * const dispose = onLocalPostDeleted(post => {
40391
- * // ...
40392
- * })
40393
- * ```
40394
- *
40395
- * Fired when a {@link Amity.InternalPost} has been deleted
40396
- *
40397
- * @param callback The function to call when the event was fired
40398
- * @returns an {@link Amity.Unsubscriber} function to stop listening
40399
- *
40400
- * @category Post Events
40401
- */
40402
- const onLocalPostDeleted = (callback) => createLocalPostEventSubscriber('local.post.deleted', callback);
40403
-
40404
- class UserFeedLiveCollectionController extends LiveCollectionController {
40405
- constructor(query, callback) {
40406
- const queryStreamId = hash(query);
40407
- const cacheKey = ['userFeed', 'collection', queryStreamId];
40408
- const paginationController = new UserFeedPaginationController(query);
40409
- super(paginationController, queryStreamId, cacheKey, callback);
40410
- this.query = query;
40411
- this.queryStreamController = new UserFeedQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
40412
- this.callback = callback.bind(this);
40413
- this.loadPage({ initial: true });
40414
- }
40415
- setup() {
40416
- var _a;
40417
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40418
- if (!collection) {
40419
- pushToCache(this.cacheKey, {
40420
- data: [],
40421
- params: {},
40422
- });
40423
- }
40424
- }
40425
- async persistModel(queryPayload) {
40426
- await this.queryStreamController.saveToMainDB(queryPayload);
40427
- }
40428
- persistQueryStream({ response, direction, refresh, }) {
40429
- this.queryStreamController.appendToQueryStream(response, direction, refresh);
40430
- }
40431
- startSubscription() {
40432
- return this.queryStreamController.subscribeRTE([
40433
- { fn: onPostCreated, action: EnumPostActions.OnPostCreated },
40434
- { fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
40435
- { fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
40436
- { fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
40437
- { fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
40438
- { fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
40439
- { fn: onPostApproved, action: EnumPostActions.OnPostApproved },
40440
- { fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
40441
- { fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
40442
- { fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
40443
- { fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
40444
- { fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
40445
- { fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
40446
- {
40447
- fn: convertEventPayload((callback) => {
40448
- return onCommentCreated(async (comment) => {
40449
- var _a;
40450
- const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40451
- if (!currentCollection || currentCollection.data.includes(comment.referenceId))
40452
- return;
40453
- await getPost$1(comment.referenceId);
40454
- callback(comment);
40455
- });
40456
- }, 'referenceId', 'post'),
40457
- action: EnumPostActions.OnPostUpdated,
40458
- },
40459
- {
40460
- fn: convertEventPayload((callback) => {
40461
- return onCommentDeleted(async (comment) => {
40462
- var _a;
40463
- const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40464
- if (!currentCollection || currentCollection.data.includes(comment.referenceId))
40465
- return;
40466
- await getPost$1(comment.referenceId);
40467
- callback(comment);
40468
- });
40469
- }, 'referenceId', 'post'),
40470
- action: EnumPostActions.OnPostUpdated,
40471
- },
40472
- ]);
40473
- }
40474
- notifyChange({ origin, loading, error }) {
40475
- var _a, _b;
40476
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40477
- if (!collection)
40478
- return;
40479
- const data = this.applyFilter((_b = collection.data
40480
- .map(id => pullFromCache(['post', 'get', id]))
40481
- .filter(isNonNullable)
40482
- .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
40483
- if (!this.shouldNotify(data) && origin === 'event')
40484
- return;
40485
- this.callback({
40486
- onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
40487
- data,
40488
- hasNextPage: !!this.paginationController.getNextToken(),
40489
- loading,
40490
- error,
40491
- });
40492
- }
40493
- applyFilter(data) {
40494
- var _a;
40495
- let posts = data;
40496
- if (!this.query.includeDeleted) {
40497
- posts = filterByPropEquality(posts, 'isDeleted', false);
40498
- }
40499
- if ((_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.length) {
40500
- posts = filterByPostDataTypes(posts, this.query.dataTypes);
40501
- }
40502
- switch (this.query.sortBy) {
40503
- case 'firstCreated':
40504
- posts = posts.sort(sortByFirstCreated);
40505
- break;
40506
- case 'lastCreated':
40507
- default:
40508
- posts = posts.sort(sortByLastCreated);
40509
- break;
40510
- }
40511
- return posts;
40512
- }
40513
- }
40192
+ /* end_public_function */
40514
40193
 
40515
40194
  /* begin_public_function
40516
- id: feed.query.user_feed
40195
+ id: comment.hard_delete
40517
40196
  */
40518
40197
  /**
40519
40198
  * ```js
40520
- * import { FeedRepository } from '@amityco/ts-sdk'
40521
- *
40522
- * let posts = []
40523
- * const unsubscribe = FeedRepository.getUserFeed({
40524
- * userId: string,
40525
- * feedSources: ['user', 'community'],
40526
- * }, response => response => processResponse(response))
40199
+ * import { CommentRepository } from '@amityco/ts-sdk'
40200
+ * const success = await CommentRepository.hardDeleteComment('foobar')
40527
40201
  * ```
40528
40202
  *
40529
- * Observe all mutations on a list of {@link Amity.Post} for a given user and feedSources
40203
+ * Deletes a {@link Amity.Comment}
40530
40204
  *
40531
- * @param params.userId the ID of the user
40532
- * @param params.feedSources the sources of the feed
40533
- * @param callback the function to call when new data are available
40534
- * @param config
40535
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
40205
+ * @param commentId The {@link Amity.Comment} ID to delete
40206
+ * @return A success boolean if the {@link Amity.Comment} was deleted
40536
40207
  *
40537
- * @category Posts Live Collection
40208
+ * @category Comment API
40209
+ * @async
40538
40210
  */
40539
- const getUserFeed = (params, callback, config) => {
40540
- const { log, cache } = getActiveClient();
40541
- if (!cache) {
40542
- console.log(ENABLE_CACHE_MESSAGE);
40543
- }
40544
- const timestamp = Date.now();
40545
- log(`getUserFeed(tmpid: ${timestamp}) > listen`);
40546
- const userFeedLiveCollection = new UserFeedLiveCollectionController(params, callback);
40547
- const disposers = userFeedLiveCollection.startSubscription();
40548
- const cacheKey = userFeedLiveCollection.getCacheKey();
40549
- disposers.push(() => dropFromCache(cacheKey));
40550
- return () => {
40551
- log(`getUserFeed(tmpid: ${timestamp}) > dispose`);
40552
- disposers.forEach(fn => fn());
40553
- };
40211
+ const hardDeleteComment = async (commentId) => {
40212
+ const client = getActiveClient();
40213
+ client.log('comment/hardDeleteComment', commentId);
40214
+ const hardDeleted = deleteComment(commentId, true);
40215
+ return hardDeleted;
40554
40216
  };
40555
40217
  /* end_public_function */
40556
40218
 
40557
- var index$9 = /*#__PURE__*/Object.freeze({
40558
- __proto__: null,
40559
- queryGlobalFeed: queryGlobalFeed,
40560
- getCustomRankingGlobalFeed: getCustomRankingGlobalFeed,
40561
- getUserFeed: getUserFeed
40562
- });
40563
-
40564
40219
  /* begin_public_function
40565
- id: post.get_by_ids
40220
+ id: comment.flag
40566
40221
  */
40567
40222
  /**
40568
40223
  * ```js
40569
- * import { getPostByIds } from '@amityco/ts-sdk'
40570
- * const { data: posts } = await getPostByIds(['foo', 'bar'])
40224
+ * import { CommentRepository } from '@amityco/ts-sdk'
40225
+ * const flagged = await CommentRepository.flagComment(commentId, reason)
40571
40226
  * ```
40572
40227
  *
40573
- * Fetches a collection of {@link Amity.Post} objects
40574
- *
40575
- * @param postIds the IDs of the {@link Amity.Post} to fetch
40576
- * @returns the associated collection of {@link Amity.Post} objects
40228
+ * @param commentId The ID of the comment to flag
40229
+ * @param reason the reason to flag the comment
40230
+ * @returns the created report result
40577
40231
  *
40578
- * @category Post API
40232
+ * @category Comment API
40579
40233
  * @async
40580
- */
40581
- const getPostByIds = async (postIds) => {
40234
+ * */
40235
+ const flagComment = async (commentId, reason) => {
40582
40236
  const client = getActiveClient();
40583
- client.log('post/getPostByIds', postIds);
40584
- const encodedPostIds = postIds.map(postId => encodeURIComponent(postId));
40585
- let payload;
40586
- try {
40587
- // API-FIX: endpoint should not be /list, parameters should be querystring.
40588
- const response = await client.http.get(`/api/v3/posts/list`, {
40589
- params: { postIds: encodedPostIds },
40590
- });
40591
- payload = response.data;
40592
- }
40593
- catch (error) {
40594
- postIds.forEach(postId => {
40595
- if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
40596
- pushToTombstone('post', postId);
40597
- }
40598
- });
40599
- throw error;
40600
- }
40601
- const data = prepareMembershipPayload(payload, 'communityUsers');
40602
- const cachedAt = client.cache && Date.now();
40603
- if (client.cache)
40604
- ingestInCache(data, { cachedAt });
40605
- return {
40606
- data: data.posts.map(LinkedObject.post),
40607
- cachedAt,
40237
+ client.log('comment/flagComment', commentId);
40238
+ const isPredefinedReason = reason &&
40239
+ Object.entries(ContentFlagReasonEnum).some(([key, value]) => key !== ContentFlagReasonEnum.Others && value === reason);
40240
+ const body = {
40241
+ reason: reason && isPredefinedReason ? reason : ContentFlagReasonEnum.Others,
40242
+ detail: reason && !isPredefinedReason ? reason : '',
40608
40243
  };
40244
+ const { data: payload } = await client.http.post(`/api/v3/comments/${encodeURIComponent(commentId)}/flag`, body);
40245
+ if (client.cache) {
40246
+ ingestInCache(payload);
40247
+ }
40248
+ fireEvent('comment.flagged', payload);
40249
+ return !!payload;
40609
40250
  };
40610
40251
  /* end_public_function */
40252
+
40253
+ /* begin_public_function
40254
+ id: comment.unflag
40255
+ */
40611
40256
  /**
40612
40257
  * ```js
40613
- * import { getPostByIds } from '@amityco/ts-sdk'
40614
- * const { data: posts } = getPostByIds.locally(['foo', 'bar'])
40258
+ * import { CommentRepository } from '@amityco/ts-sdk'
40259
+ * const unflagged = await CommentRepository.unflagComment('commentId')
40615
40260
  * ```
40616
40261
  *
40617
- * Fetches a collection of {@link Amity.Post} objects from cache
40618
- *
40619
- * @param postIds the IDs of the {@link Amity.Post} to fetch
40620
- * @returns the associated collection of {@link Amity.Post} objects
40262
+ * @param commentId The ID of comment to unflag
40263
+ * @returns the unflagged result
40621
40264
  *
40622
- * @category Post API
40623
- */
40624
- getPostByIds.locally = (postIds) => {
40625
- var _a;
40265
+ * @category Comment API
40266
+ * @async
40267
+ * */
40268
+ const unflagComment = async (commentId) => {
40626
40269
  const client = getActiveClient();
40627
- client.log('post/getPostByIds.locally', postIds);
40628
- if (!client.cache)
40629
- return;
40630
- const cached = postIds
40631
- .map(postId => pullFromCache(['post', 'get', postId]))
40632
- .filter(Boolean);
40633
- const posts = cached.map(({ data }) => data);
40634
- const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
40635
- if ((cached === null || cached === void 0 ? void 0 : cached.length) < postIds.length)
40636
- return;
40637
- return {
40638
- data: posts.map(LinkedObject.post),
40639
- cachedAt: oldest.cachedAt,
40640
- };
40270
+ client.log('comment/unflagComment', commentId);
40271
+ const { data: payload } = await client.http.delete(`/api/v3/comments/${encodeURIComponent(commentId)}/unflag`);
40272
+ if (client.cache) {
40273
+ ingestInCache(payload);
40274
+ }
40275
+ fireEvent('comment.unflagged', payload);
40276
+ return !!payload;
40641
40277
  };
40278
+ /* end_public_function */
40642
40279
 
40643
40280
  /* begin_public_function
40644
- id: post.create.text_post, post.create.image_post, post.create.file_post, post.create.video_post, post.create.poll_post, post.create.livestream_post, post.create.custom_post
40281
+ id: comment.check_flag_by_me
40645
40282
  */
40646
40283
  /**
40647
40284
  * ```js
40648
- * import { PostRepository } from '@amityco/ts-sdk'
40649
- * const created = await PostRepository.createPost({
40650
- * targetType: 'user',
40651
- * targetId: 'foobar',
40652
- * data: { text: 'hello world' }
40653
- * }))
40285
+ * import { CommentRepository } from '@amityco/ts-sdk'
40286
+ * const isReported = await CommentRepository.isCommentFlaggedByMe('commentId')
40654
40287
  * ```
40655
40288
  *
40656
- * Creates an {@link Amity.Post}
40657
- *
40658
- * @param bundle The data necessary to create a new {@link Amity.Post}
40659
- * @returns The newly created {@link Amity.Post}
40289
+ * @param commentId The ID of the comment to check if flagged by current user
40290
+ * @returns `true` if the comment is flagged by me, `false` if doesn't.
40660
40291
  *
40661
- * @category Post API
40292
+ * @category Comment API
40662
40293
  * @async
40663
- */
40664
- const createPost = async (bundle) => {
40294
+ * */
40295
+ const isCommentFlaggedByMe = async (commentId) => {
40665
40296
  const client = getActiveClient();
40666
- client.log('post/createPost', bundle);
40667
- if (!bundle.dataType || ['text', 'image', 'file', 'video'].includes(bundle.dataType)) {
40668
- // eslint-disable-next-line no-param-reassign
40669
- delete bundle.dataType;
40297
+ client.log('comment/isCommentFlaggedByMe', commentId);
40298
+ const { data: { result }, } = await client.http.get(`/api/v3/comments/${commentId}/isflagbyme`);
40299
+ return result;
40300
+ };
40301
+ /* end_public_function */
40302
+
40303
+ const getComment$1 = async (commentId) => {
40304
+ const client = getActiveClient();
40305
+ client.log('comment/getComment', commentId);
40306
+ isInTombstone('comment', commentId);
40307
+ let data;
40308
+ try {
40309
+ // API-FIX: endpoint should not be /list, parameters should be querystring.
40310
+ const response = await client.http.get(`/api/v3/comments/${encodeURIComponent(commentId)}`);
40311
+ data = response.data;
40312
+ }
40313
+ catch (error) {
40314
+ if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
40315
+ pushToTombstone('comment', commentId);
40316
+ }
40317
+ throw error;
40670
40318
  }
40671
- const { data: payload } = await client.http.post('/api/v4/posts', bundle);
40672
- fireEvent('post.created', payload);
40673
- const data = preparePostPayload(payload);
40674
40319
  const cachedAt = client.cache && Date.now();
40675
40320
  if (client.cache)
40676
40321
  ingestInCache(data, { cachedAt });
40677
- const { posts } = data;
40322
+ const { comments } = data;
40678
40323
  return {
40679
- data: LinkedObject.post(posts[0]),
40324
+ data: comments.find(comment => comment.commentId === commentId),
40680
40325
  cachedAt,
40681
40326
  };
40682
40327
  };
40683
- /* end_public_function */
40328
+ getComment$1.locally = (commentId) => {
40329
+ const client = getActiveClient();
40330
+ client.log('comment/getComment.locally', commentId);
40331
+ if (!client.cache)
40332
+ return;
40333
+ const cached = pullFromCache(['comment', 'get', commentId]);
40334
+ if (!cached)
40335
+ return;
40336
+ return {
40337
+ data: cached.data,
40338
+ cachedAt: cached.cachedAt,
40339
+ };
40340
+ };
40684
40341
 
40685
- /* begin_public_function
40686
- id: post.edit, post.edit.custom_post
40687
- */
40688
40342
  /**
40689
40343
  * ```js
40690
- * import { PostRepository } from '@amityco/ts-sdk'
40691
- * const updated = await PostRepository.editPost(postId, {
40692
- * data: { text: 'hello world' }
40344
+ * import { onCommentDeleteLocal } from '@amityco/ts-sdk'
40345
+ * const dispose = onCommentDeleteLocal(comment => {
40346
+ * // ...
40693
40347
  * })
40694
40348
  * ```
40695
40349
  *
40696
- * Updates an {@link Amity.Post}
40350
+ * Fired when a {@link Amity.InternalComment} has been deleted
40697
40351
  *
40698
- * @param postId The ID of the {@link Amity.Post} to edit
40699
- * @param patch The patch data to apply
40700
- * @returns the updated {@link Amity.Post} object
40352
+ * @param callback The function to call when the event was fired
40353
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
40701
40354
  *
40702
- * @category Post API
40703
- * @async
40355
+ * @category Comment Events
40704
40356
  */
40705
- const editPost = async (postId, patch) => {
40706
- const client = getActiveClient();
40707
- client.log('user/editPost', patch);
40708
- const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, patch);
40709
- const data = prepareMembershipPayload(payload, 'communityUsers');
40710
- const cachedAt = client.cache && Date.now();
40711
- if (client.cache)
40712
- ingestInCache(data, { cachedAt });
40713
- fireEvent('local.post.updated', data);
40714
- const { posts } = data;
40715
- return {
40716
- data: LinkedObject.post(posts.find(post => post.postId === postId)),
40717
- cachedAt,
40718
- };
40719
- };
40720
- /* end_public_function */
40357
+ const onCommentDeleteLocal = (callback) => createLocalCommentEventSubscriber('local.comment.deleted', callback);
40721
40358
 
40722
40359
  /**
40723
40360
  * ```js
40724
- * import { deletePost } from '@amityco/ts-sdk'
40725
- * const success = await deletePost('foobar')
40361
+ * import { onLocalCommentReactionAdded } from '@amityco/ts-sdk'
40362
+ * const dispose = onLocalCommentReactionAdded(comment => {
40363
+ * // ...
40364
+ * })
40726
40365
  * ```
40727
40366
  *
40728
- * Deletes a {@link Amity.Post}
40367
+ * Fired when a {@link Amity.InternalComment} has been reacted
40729
40368
  *
40730
- * @param postId The {@link Amity.Post} ID to delete
40731
- * @return A success boolean if the {@link Amity.Post} was deleted
40369
+ * @param callback The function to call when the event was fired
40370
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
40732
40371
  *
40733
- * @private
40734
- * @async
40372
+ * @category Comment Events
40735
40373
  */
40736
- const deletePost = async (postId, permanent = false) => {
40737
- var _a;
40374
+ const onLocalCommentReactionAdded = (callback) => {
40738
40375
  const client = getActiveClient();
40739
- const post = await getPost$2(postId);
40740
- await client.http.delete(`/api/v4/posts/${encodeURIComponent(postId)}`, {
40741
- params: {
40742
- postId,
40743
- permanent,
40744
- },
40745
- });
40746
- // there is currently a limitation which doesn't allow us to fire event to tell that community
40747
- // has been updated. reason is that, when the object is deleted, we don't have its `communityId`
40748
- // and so we cannot refetch the community or advertise on events. hopefully this should be solved
40749
- // later when realtime events covers that for us.
40750
- if (post.data.targetType === 'community') {
40751
- const community = await getCommunity$1(post.data.targetId);
40752
- const communityUsersCache = (_a = queryCache(['communityUsers', 'get'])) !== null && _a !== void 0 ? _a : [];
40753
- const communityUsers = communityUsersCache
40754
- .filter(({ key }) => {
40755
- // cache key is ['communityUsers', 'get', `${communityId}#`${userId}`}]
40756
- if (key[0] !== 'communityUsers')
40757
- return false;
40758
- if (key[1] !== 'get')
40759
- return false;
40760
- if (typeof key[2] === 'string')
40761
- return key[2].includes(community.data.communityId);
40762
- return false;
40763
- })
40764
- .map(({ data }) => data);
40765
- fireEvent('community.updated', {
40766
- communities: [community.data],
40767
- categories: [],
40768
- communityUsers,
40769
- feeds: [],
40770
- files: [],
40771
- users: [],
40772
- });
40773
- }
40774
- // to support hard deletion
40775
- const deleted = Object.assign(Object.assign({}, post.data), { isDeleted: true });
40776
- if (permanent) {
40777
- setTimeout(() => {
40778
- pushToTombstone('post', postId);
40779
- }, 0);
40780
- }
40781
- else {
40782
- upsertInCache(['post', 'get', postId], { isDeleted: true });
40783
- }
40784
- fireEvent('local.post.deleted', {
40785
- posts: [deleted],
40786
- categories: [],
40787
- comments: [],
40788
- communities: [],
40789
- communityUsers: [],
40790
- feeds: [],
40791
- files: [],
40792
- postChildren: [],
40793
- users: [],
40794
- videoStreamings: [],
40795
- });
40796
- return LinkedObject.post(deleted);
40376
+ const filter = ({ comment }) => {
40377
+ if (!client.cache) {
40378
+ callback(comment);
40379
+ }
40380
+ else {
40381
+ upsertInCache(['comment', 'get', comment.commentId], comment);
40382
+ callback(commentLinkedObject(comment));
40383
+ }
40384
+ };
40385
+ return createEventSubscriber(client, 'local.comment.addReaction', 'local.comment.addReaction', filter);
40797
40386
  };
40798
40387
 
40799
- /* begin_public_function
40800
- id: post.soft_delete
40801
- */
40802
40388
  /**
40803
40389
  * ```js
40804
- * import { PostRepository } from '@amityco/ts-sdk'
40805
- * const success = await PostRepository.softDeletePost('foobar')
40390
+ * import { onLocalCommentReactionRemoved } from '@amityco/ts-sdk'
40391
+ * const dispose = onLocalCommentReactionRemoved(comment => {
40392
+ * // ...
40393
+ * })
40806
40394
  * ```
40807
40395
  *
40808
- * Soft deletes a {@link Amity.Post}
40396
+ * Fired when a {@link Amity.InternalComment} has been reacted
40809
40397
  *
40810
- * @param postId The {@link Amity.Post} ID to soft delete
40811
- * @return A success boolean if the {@link Amity.Post} was deleted
40398
+ * @param callback The function to call when the event was fired
40399
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
40812
40400
  *
40813
- * @category Post API
40814
- * @async
40401
+ * @category Comment Events
40815
40402
  */
40816
- const softDeletePost = async (postId) => {
40403
+ const onLocalCommentReactionRemoved = (callback) => {
40817
40404
  const client = getActiveClient();
40818
- client.log('post/softDeletePost', postId);
40819
- const softDeleted = await deletePost(postId, false);
40820
- return LinkedObject.post(softDeleted);
40405
+ const filter = ({ comment }) => {
40406
+ if (!client.cache) {
40407
+ callback(comment);
40408
+ }
40409
+ else {
40410
+ upsertInCache(['comment', 'get', comment.commentId], comment);
40411
+ callback(commentLinkedObject(comment));
40412
+ }
40413
+ };
40414
+ return createEventSubscriber(client, 'local.comment.removeReaction', 'local.comment.removeReaction', filter);
40821
40415
  };
40822
- /* end_public_function */
40823
40416
 
40824
40417
  /* begin_public_function
40825
- id: post.hard_delete
40418
+ id: comment.get
40826
40419
  */
40827
40420
  /**
40828
40421
  * ```js
40829
- * import { hardDeletePost } from '@amityco/ts-sdk'
40830
- * const success = await hardDeletePost('foobar')
40422
+ * import { CommentRepository } from '@amityco/ts-sdk';
40423
+ *
40424
+ * let comment;
40425
+ *
40426
+ * const unsub = CommentRepository.getComment(commentId, response => {
40427
+ * comment = response.data;
40428
+ * });
40831
40429
  * ```
40832
40430
  *
40833
- * Hard deletes a {@link Amity.Post}
40431
+ * Observe all mutation on a given {@link Amity.Comment}
40834
40432
  *
40835
- * @param postId The {@link Amity.Post} ID to be hard delete
40836
- * @return A success boolean if the {@link Amity.Post} was deleted
40433
+ * @param commentId the ID of the comment to observe
40434
+ * @param callback the function to call when new data are available
40435
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the comment
40837
40436
  *
40838
- * @category Post API
40839
- * @async
40437
+ * @category Comment Live Object
40840
40438
  */
40841
- const hardDeletePost = async (postId) => {
40842
- const client = getActiveClient();
40843
- client.log('post/hardDeletePost', postId);
40844
- const hardDeleted = await deletePost(postId, true);
40845
- return LinkedObject.post(hardDeleted);
40439
+ const getComment = (commentId, callback) => {
40440
+ return liveObject(commentId, callback, 'commentId', getComment$1, [
40441
+ onCommentDeleteLocal,
40442
+ onCommentDeleted,
40443
+ onCommentFlagged,
40444
+ onCommentReactionAdded,
40445
+ onCommentReactionRemoved,
40446
+ onCommentUnflagged,
40447
+ onCommentUpdated,
40448
+ onLocalCommentReactionAdded,
40449
+ onLocalCommentReactionRemoved,
40450
+ ]);
40846
40451
  };
40847
40452
  /* end_public_function */
40848
40453
 
40849
- /* begin_public_function
40850
- id: post.approve
40851
- */
40454
+ class CommentPaginationController extends PaginationController {
40455
+ async getRequest(queryParams, token) {
40456
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
40457
+ const baseOptions = {
40458
+ type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
40459
+ };
40460
+ const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
40461
+ const { data: queryResponse } = await this.http.get(`/api/v3/comments`, {
40462
+ params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options }),
40463
+ });
40464
+ return queryResponse;
40465
+ }
40466
+ }
40467
+
40468
+ var EnumCommentActions;
40469
+ (function (EnumCommentActions) {
40470
+ EnumCommentActions["OnCommentCreated"] = "onCommentCreated";
40471
+ EnumCommentActions["OnCommentUpdated"] = "onCommentUpdated";
40472
+ EnumCommentActions["OnCommentDeleted"] = "onCommentDeleted";
40473
+ EnumCommentActions["OnCommentFlagged"] = "onCommentFlagged";
40474
+ EnumCommentActions["OnCommentUnflagged"] = "onCommentUnflagged";
40475
+ EnumCommentActions["OnCommentReactionAdded"] = "onCommentReactionAdded";
40476
+ EnumCommentActions["OnCommentReactionRemoved"] = "onCommentReactionRemoved";
40477
+ })(EnumCommentActions || (EnumCommentActions = {}));
40478
+
40479
+ class CommentQueryStreamController extends QueryStreamController {
40480
+ constructor(query, cacheKey, notifyChange, preparePayload) {
40481
+ super(query, cacheKey);
40482
+ this.notifyChange = notifyChange;
40483
+ this.preparePayload = preparePayload;
40484
+ }
40485
+ async saveToMainDB(response) {
40486
+ const processedPayload = await this.preparePayload(response);
40487
+ const client = getActiveClient();
40488
+ const cachedAt = client.cache && Date.now();
40489
+ if (client.cache) {
40490
+ ingestInCache(processedPayload, { cachedAt });
40491
+ }
40492
+ }
40493
+ appendToQueryStream(response, direction, refresh = false) {
40494
+ var _a, _b;
40495
+ if (refresh) {
40496
+ pushToCache(this.cacheKey, {
40497
+ data: response.comments.map(getResolver('comment')),
40498
+ });
40499
+ }
40500
+ else {
40501
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40502
+ const comments = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
40503
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...comments, ...response.comments.map(getResolver('comment'))])] }));
40504
+ }
40505
+ }
40506
+ reactor(action) {
40507
+ return (comment) => {
40508
+ var _a;
40509
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40510
+ if (this.query.referenceId !== comment.referenceId ||
40511
+ this.query.referenceType !== comment.referenceType ||
40512
+ !collection) {
40513
+ return;
40514
+ }
40515
+ if (this.query.parentId && this.query.parentId !== comment.parentId) {
40516
+ return;
40517
+ }
40518
+ if (!this.query.parentId && comment.parentId) {
40519
+ return;
40520
+ }
40521
+ if (action === EnumCommentActions.OnCommentCreated) {
40522
+ collection.data = [...new Set([comment.commentId, ...collection.data])];
40523
+ }
40524
+ pushToCache(this.cacheKey, collection);
40525
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
40526
+ };
40527
+ }
40528
+ subscribeRTE(createSubscriber) {
40529
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
40530
+ }
40531
+ }
40532
+
40852
40533
  /**
40853
40534
  * ```js
40854
- * import { approvePost } from '@amityco/ts-sdk'
40855
- *
40856
- * const { data: post } = await approvePost('postId')
40535
+ * import { onCommentCreated } from '@amityco/ts-sdk'
40536
+ * const dispose = onCommentCreated(comment => {
40537
+ * // ...
40538
+ * })
40857
40539
  * ```
40858
40540
  *
40859
- * Approves a {@link Amity.Post}
40541
+ * Fired when a {@link Amity.InternalComment} has been created
40860
40542
  *
40861
- * @param postId The {@link Amity.Post} ID to be approved
40862
- * @return A {@link Amity.Post} that was approved
40543
+ * @param callback The function to call when the event was fired
40544
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
40863
40545
  *
40864
- * @category Post API
40865
- * @async
40546
+ * @category Comment Events
40866
40547
  */
40867
- const approvePost = async (postId) => {
40868
- const client = getActiveClient();
40869
- client.log('post/approvePost', postId);
40870
- const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/approve`);
40871
- fireEvent('post.approved', payload);
40872
- // fire virtual event for community update
40873
- if (payload.posts[0].targetType === 'community') {
40874
- fireEvent('community.updated', payload);
40548
+ const onCommentCreatedLocal = (callback) => {
40549
+ return createLocalCommentEventSubscriber('local.comment.created', callback);
40550
+ };
40551
+
40552
+ class CommentLiveCollectionController extends LiveCollectionController {
40553
+ constructor(query, callback) {
40554
+ const queryStreamId = hash(query);
40555
+ const cacheKey = ['comments', 'collection', queryStreamId];
40556
+ const paginationController = new CommentPaginationController(query);
40557
+ super(paginationController, queryStreamId, cacheKey, callback);
40558
+ this.query = query;
40559
+ this.queryStreamController = new CommentQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommentPayload);
40560
+ this.callback = callback.bind(this);
40561
+ this.loadPage({ initial: true });
40562
+ }
40563
+ setup() {
40564
+ var _a;
40565
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40566
+ if (!collection) {
40567
+ pushToCache(this.cacheKey, {
40568
+ data: [],
40569
+ params: {},
40570
+ });
40571
+ }
40572
+ }
40573
+ async persistModel(queryPayload) {
40574
+ await this.queryStreamController.saveToMainDB(queryPayload);
40575
+ }
40576
+ persistQueryStream({ response, direction, refresh, }) {
40577
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
40578
+ }
40579
+ startSubscription() {
40580
+ return this.queryStreamController.subscribeRTE([
40581
+ { fn: onCommentCreatedLocal, action: EnumCommentActions.OnCommentCreated },
40582
+ { fn: onCommentDeleteLocal, action: EnumCommentActions.OnCommentDeleted },
40583
+ { fn: onCommentCreated, action: EnumCommentActions.OnCommentCreated },
40584
+ { fn: onCommentUpdated, action: EnumCommentActions.OnCommentUpdated },
40585
+ { fn: onCommentDeleted, action: EnumCommentActions.OnCommentDeleted },
40586
+ { fn: onCommentFlagged, action: EnumCommentActions.OnCommentFlagged },
40587
+ { fn: onCommentUnflagged, action: EnumCommentActions.OnCommentUnflagged },
40588
+ { fn: onCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
40589
+ { fn: onCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
40590
+ { fn: onLocalCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
40591
+ { fn: onLocalCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
40592
+ ]);
40593
+ }
40594
+ notifyChange({ origin, loading, error }) {
40595
+ var _a, _b;
40596
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40597
+ if (!collection)
40598
+ return;
40599
+ const data = this.applyFilter((_b = collection.data
40600
+ .map(id => pullFromCache(['comment', 'get', id]))
40601
+ .filter(isNonNullable)
40602
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.comment);
40603
+ if (!this.shouldNotify(data) && origin === 'event')
40604
+ return;
40605
+ this.callback({
40606
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
40607
+ data,
40608
+ hasNextPage: !!this.paginationController.getNextToken(),
40609
+ loading,
40610
+ error,
40611
+ });
40612
+ }
40613
+ applyFilter(data) {
40614
+ let comments = data;
40615
+ if (!this.query.includeDeleted) {
40616
+ comments = filterByPropEquality(comments, 'isDeleted', false);
40617
+ }
40618
+ if (this.query.parentId) {
40619
+ comments = comments.filter(comment => comment.parentId === this.query.parentId);
40620
+ }
40621
+ if (typeof this.query.hasFlag === 'boolean') {
40622
+ if (this.query.hasFlag) {
40623
+ comments = comments.filter(comment => comment.hashFlag != null);
40624
+ }
40625
+ else {
40626
+ comments = comments.filter(comment => comment.hashFlag == null);
40627
+ }
40628
+ }
40629
+ if (this.query.dataTypes) {
40630
+ if (this.query.dataTypes.matchType === 'exact') {
40631
+ comments = comments.filter(comment => {
40632
+ var _a, _b;
40633
+ const sortedDataTypesQueryValue = ((_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.values.sort()) || [];
40634
+ const sortedDataTypesCommentValue = ((_b = comment.dataTypes) === null || _b === void 0 ? void 0 : _b.sort()) || [];
40635
+ if (sortedDataTypesCommentValue.length !== sortedDataTypesQueryValue.length) {
40636
+ return false;
40637
+ }
40638
+ return sortedDataTypesQueryValue.every((value, index) => value === sortedDataTypesCommentValue[index]);
40639
+ });
40640
+ }
40641
+ if (this.query.dataTypes.matchType === 'any') {
40642
+ comments = comments.filter(comment => { var _a; return (_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.values.some(value => { var _a; return (_a = comment.dataTypes) === null || _a === void 0 ? void 0 : _a.includes(value); }); });
40643
+ }
40644
+ }
40645
+ switch (this.query.sortBy) {
40646
+ case 'firstCreated':
40647
+ comments = comments.sort(sortByFirstCreated);
40648
+ break;
40649
+ case 'lastCreated':
40650
+ default:
40651
+ comments = comments.sort(sortByLastCreated);
40652
+ break;
40653
+ }
40654
+ return comments;
40875
40655
  }
40876
- const data = prepareMembershipPayload(payload, 'communityUsers');
40877
- const cachedAt = client.cache && Date.now();
40878
- if (client.cache)
40879
- ingestInCache(data, { cachedAt });
40880
- return {
40881
- data: LinkedObject.post(data.posts.find(post => post.postId === postId)),
40882
- cachedAt,
40883
- };
40884
- };
40885
- /* end_public_function */
40656
+ }
40886
40657
 
40887
40658
  /* begin_public_function
40888
- id: post.decline
40659
+ id: comment.query
40889
40660
  */
40890
40661
  /**
40891
40662
  * ```js
40892
- * import { declinePost } from '@amityco/ts-sdk'
40663
+ * import { getComments } from '@amityco/ts-sdk'
40893
40664
  *
40894
- * const {data: post} = await declinePost('postId')
40665
+ * let comments = []
40666
+ * const unsub = getComments({
40667
+ * referenceType: Amity.InternalComment['referenceType'];
40668
+ * referenceId: Amity.InternalComment['referenceId'];
40669
+ * }, response => merge(comments, response.data))
40895
40670
  * ```
40896
40671
  *
40897
- * Declines a {@link Amity.Post}
40672
+ * Observe all mutations on a list of {@link Amity.InternalComment} for a given target object
40898
40673
  *
40899
- * @param postId The {@link Amity.Post} ID to be declined
40900
- * @return A {@link Amity.Post} that was declined
40674
+ * @param referenceType the type of the target
40675
+ * @param referenceId the ID of the target
40676
+ * @param callback the function to call when new data are available
40677
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
40901
40678
  *
40902
- * @category Post API
40903
- * @async
40679
+ * @category Comments Live Collection
40904
40680
  */
40905
- const declinePost = async (postId) => {
40906
- const client = getActiveClient();
40907
- client.log('post/declinePost', postId);
40908
- const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/decline`);
40909
- // fire virtual event
40910
- if (payload.posts[0].targetType === 'community') {
40911
- fireEvent('community.updated', payload);
40681
+ const getComments = (params, callback, config) => {
40682
+ const { log, cache } = getActiveClient();
40683
+ if (!cache) {
40684
+ console.log('For using Live Collection feature you need to enable Cache!');
40912
40685
  }
40913
- fireEvent('post.declined', payload);
40914
- const data = prepareMembershipPayload(payload, 'communityUsers');
40915
- const cachedAt = client.cache && Date.now();
40916
- if (client.cache)
40917
- ingestInCache(data, { cachedAt });
40918
- return {
40919
- data: LinkedObject.post(payload.posts.find(post => post.postId === postId)),
40920
- cachedAt,
40686
+ const timestamp = Date.now();
40687
+ log(`getComments(tmpid: ${timestamp}) > listen`);
40688
+ const commentsLiveCollection = new CommentLiveCollectionController(params, callback);
40689
+ const disposers = commentsLiveCollection.startSubscription();
40690
+ const cacheKey = commentsLiveCollection.getCacheKey();
40691
+ disposers.push(() => dropFromCache(cacheKey));
40692
+ return () => {
40693
+ log(`getComments(tmpid: ${timestamp}) > dispose`);
40694
+ disposers.forEach(fn => fn());
40921
40695
  };
40922
40696
  };
40923
40697
  /* end_public_function */
40924
40698
 
40925
- /* begin_public_function
40926
- id: post.flag
40927
- */
40699
+ var index$9 = /*#__PURE__*/Object.freeze({
40700
+ __proto__: null,
40701
+ getCommentByIds: getCommentByIds,
40702
+ createComment: createComment,
40703
+ updateComment: updateComment,
40704
+ deleteComment: deleteComment,
40705
+ softDeleteComment: softDeleteComment,
40706
+ hardDeleteComment: hardDeleteComment,
40707
+ flagComment: flagComment,
40708
+ unflagComment: unflagComment,
40709
+ isCommentFlaggedByMe: isCommentFlaggedByMe,
40710
+ onCommentCreated: onCommentCreated,
40711
+ onCommentUpdated: onCommentUpdated,
40712
+ onCommentDeleted: onCommentDeleted,
40713
+ onCommentFlagged: onCommentFlagged,
40714
+ onCommentUnflagged: onCommentUnflagged,
40715
+ onCommentReactionAdded: onCommentReactionAdded,
40716
+ onCommentReactionRemoved: onCommentReactionRemoved,
40717
+ getComment: getComment,
40718
+ getComments: getComments
40719
+ });
40720
+
40928
40721
  /**
40929
40722
  * ```js
40930
- * import { PostRepository } from '@amityco/ts-sdk'
40931
- * const flagged = await PostRepository.flagPost(postId, reason)
40723
+ * import { onPostUpdatedLocal } from '@amityco/ts-sdk'
40724
+ * const dispose = onPostUpdatedLocal(post => {
40725
+ * // ...
40726
+ * })
40932
40727
  * ```
40933
40728
  *
40934
- * @param postId of the post to flag
40935
- * @param reason the reason to flag the post
40936
- * @returns a boolean
40729
+ * Fired when a {@link Amity.InternalPost} has been updated
40937
40730
  *
40938
- * @category Post API
40939
- * @async
40940
- * */
40941
- const flagPost = async (postId, reason) => {
40942
- const client = getActiveClient();
40943
- client.log('post/flagPost', postId);
40944
- const isPredefinedReason = reason &&
40945
- Object.entries(ContentFlagReasonEnum).some(([key, value]) => key !== ContentFlagReasonEnum.Others && value === reason);
40946
- const body = {
40947
- reason: reason && isPredefinedReason ? reason : ContentFlagReasonEnum.Others,
40948
- detail: reason && !isPredefinedReason ? reason : '',
40949
- };
40950
- const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/flag`, body);
40951
- if (client.cache) {
40952
- ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
40953
- }
40954
- fireEvent('post.flagged', payload);
40955
- return !!payload;
40956
- };
40957
- /* end_public_function */
40731
+ * @param callback The function to call when the event was fired
40732
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
40733
+ *
40734
+ * @category Post Events
40735
+ */
40736
+ const onPostUpdatedLocal = (callback) => createLocalPostEventSubscriber('local.post.updated', callback);
40958
40737
 
40959
- /* begin_public_function
40960
- id: post.unflag
40961
- */
40962
40738
  /**
40963
40739
  * ```js
40964
- * import { PostRepository } from '@amityco/ts-sdk'
40965
- * const unflagged = await PostRepository.unflagPost(postId)
40740
+ * import { onLocalPostReactionAdded } from '@amityco/ts-sdk'
40741
+ * const dispose = onPostReactionAdded(post => {
40742
+ * // ...
40743
+ * })
40966
40744
  * ```
40967
40745
  *
40968
- * @param postId of the post to unflag
40969
- * @returns the unflag post result
40746
+ * Fired when a {@link Amity.InternalPost} has been reacted
40970
40747
  *
40971
- * @category Post API
40972
- * @async
40973
- * */
40974
- const unflagPost = async (postId) => {
40748
+ * @param callback The function to call when the event was fired
40749
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
40750
+ *
40751
+ * @category Post Events
40752
+ */
40753
+ const onLocalPostReactionAdded = (callback) => {
40975
40754
  const client = getActiveClient();
40976
- client.log('post/unflagPost', postId);
40977
- const { data: payload } = await client.http.delete(`/api/v3/posts/${encodeURIComponent(postId)}/unflag`);
40978
- if (client.cache) {
40979
- ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
40980
- }
40981
- fireEvent('post.unflagged', payload);
40982
- return !!payload;
40755
+ const filter = ({ post }) => {
40756
+ if (!client.cache) {
40757
+ callback(post);
40758
+ }
40759
+ else {
40760
+ upsertInCache(['post', 'get', post.postId], post);
40761
+ callback(post);
40762
+ }
40763
+ };
40764
+ return createEventSubscriber(client, 'local.post.addReaction', 'local.post.addReaction', filter);
40983
40765
  };
40984
- /* end_public_function */
40985
40766
 
40986
- /* begin_public_function
40987
- id: post.check_flag_by_me
40988
- */
40989
40767
  /**
40990
40768
  * ```js
40991
- * import { PostRepository } from '@amityco/ts-sdk'
40992
- * const isReported = await PostRepository.isPostFlaggedByMe('post', postId)
40769
+ * import { onLocalPostReactionRemoved } from '@amityco/ts-sdk'
40770
+ * const dispose = onPostReactionRemoved(post => {
40771
+ * // ...
40772
+ * })
40993
40773
  * ```
40994
40774
  *
40995
- * @param postId of the post to check if flagged by current user
40996
- * @returns `true` if the post is flagged by me, `false` if doesn't.
40775
+ * Fired when a {@link Amity.InternalPost} has been reacted
40997
40776
  *
40998
- * @category Post API
40999
- * @async
41000
- * */
41001
- const isPostFlaggedByMe = async (postId) => {
40777
+ * @param callback The function to call when the event was fired
40778
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
40779
+ *
40780
+ * @category Post Events
40781
+ */
40782
+ const onLocalPostReactionRemoved = (callback) => {
41002
40783
  const client = getActiveClient();
41003
- client.log('post/isPostFlaggedByMe', postId);
41004
- const { data: { result }, } = await client.http.get(`/api/v3/posts/${postId}/isflagbyme`);
41005
- return result;
40784
+ const filter = ({ post }) => {
40785
+ if (!client.cache) {
40786
+ callback(post);
40787
+ }
40788
+ else {
40789
+ upsertInCache(['post', 'get', post.postId], post);
40790
+ callback(post);
40791
+ }
40792
+ };
40793
+ return createEventSubscriber(client, 'local.post.removeReaction', 'local.post.removeReaction', filter);
41006
40794
  };
41007
- /* end_public_function */
41008
40795
 
41009
- /* begin_public_function
41010
- id: post.create.clip_post
41011
- */
41012
40796
  /**
41013
40797
  * ```js
41014
- * import { PostRepository } from '@amityco/ts-sdk'
41015
- * const created = await PostRepository.createClipPost({
41016
- * targetType: 'user',
41017
- * targetId: 'foobar',
41018
- * dataType: 'clip',
41019
- * data: { text: 'hello world' },
41020
- * attachments: [{ type: 'clip', fileId: 'fileId123', displayMode: 'fill', isMuted: false }]
41021
- * }))
40798
+ * import { onLocalPostDeleted } from '@amityco/ts-sdk'
40799
+ * const dispose = onLocalPostDeleted(post => {
40800
+ * // ...
40801
+ * })
41022
40802
  * ```
41023
40803
  *
41024
- * Creates an {@link Amity.Post}
40804
+ * Fired when a {@link Amity.InternalPost} has been deleted
41025
40805
  *
41026
- * @param bundle The data necessary to create a new {@link Amity.Post}
41027
- * @returns The newly created {@link Amity.Post}
40806
+ * @param callback The function to call when the event was fired
40807
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
41028
40808
  *
41029
- * @category Post API
41030
- * @async
40809
+ * @category Post Events
41031
40810
  */
41032
- const createClipPost = async (bundle) => {
41033
- const client = getActiveClient();
41034
- client.log('post/createPost', bundle);
41035
- const { data: payload } = await client.http.post('/api/v4/posts', bundle);
41036
- fireEvent('post.created', payload);
41037
- const data = prepareMembershipPayload(payload, 'communityUsers');
41038
- const cachedAt = client.cache && Date.now();
41039
- if (client.cache)
41040
- ingestInCache(data, { cachedAt });
41041
- const { posts } = data;
41042
- return {
41043
- data: LinkedObject.post(posts[0]),
41044
- cachedAt,
41045
- };
41046
- };
41047
- /* end_public_function */
40811
+ const onLocalPostDeleted = (callback) => createLocalPostEventSubscriber('local.post.deleted', callback);
41048
40812
 
41049
40813
  /* begin_public_function
41050
40814
  id: post.get
@@ -41068,7 +40832,7 @@ const createClipPost = async (bundle) => {
41068
40832
  *
41069
40833
  * @category Post Live Object
41070
40834
  */
41071
- const getPost = (postId, callback) => {
40835
+ const getPost$1 = (postId, callback) => {
41072
40836
  const responder = (snapshot) => {
41073
40837
  const { data } = snapshot;
41074
40838
  callback(Object.assign(Object.assign({}, snapshot), { data: data ? LinkedObject.post(snapshot.data) : data }));
@@ -41136,14 +40900,14 @@ const getPost = (postId, callback) => {
41136
40900
 
41137
40901
  class PostPaginationController extends PaginationController {
41138
40902
  async getRequest(queryParams, token) {
41139
- const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted, matchingOnlyParentPost } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted", "matchingOnlyParentPost"]);
40903
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, matchingOnlyParentPost } = queryParams, params = __rest(queryParams, ["limit", "matchingOnlyParentPost"]);
41140
40904
  const { dataTypes } = params;
41141
40905
  const baseOptions = {
41142
40906
  type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
41143
40907
  };
41144
40908
  const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
41145
40909
  const { data: queryResponse } = await this.http.get(`/api/v5/posts`, {
41146
- params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted),
40910
+ params: Object.assign(Object.assign({}, params), {
41147
40911
  /*
41148
40912
  * when creating post like image, file, video BE will create 2 posts
41149
40913
  * 1. parent post to store text with dataType=text
@@ -41157,6 +40921,19 @@ class PostPaginationController extends PaginationController {
41157
40921
  }
41158
40922
  }
41159
40923
 
40924
+ var EnumPostActions;
40925
+ (function (EnumPostActions) {
40926
+ EnumPostActions["OnPostCreated"] = "onPostCreated";
40927
+ EnumPostActions["OnPostUpdated"] = "onPostUpdated";
40928
+ EnumPostActions["OnPostDeleted"] = "onPostDeleted";
40929
+ EnumPostActions["OnPostFlagged"] = "onPostFlagged";
40930
+ EnumPostActions["OnPostUnflagged"] = "onPostUnflagged";
40931
+ EnumPostActions["OnPostReactionAdded"] = "onPostReactionAdded";
40932
+ EnumPostActions["OnPostReactionRemoved"] = "onPostReactionRemoved";
40933
+ EnumPostActions["OnPostApproved"] = "onPostApproved";
40934
+ EnumPostActions["OnPostDeclined"] = "onPostDeclined";
40935
+ })(EnumPostActions || (EnumPostActions = {}));
40936
+
41160
40937
  class PostQueryStreamController extends QueryStreamController {
41161
40938
  constructor(query, cacheKey, notifyChange, preparePayload) {
41162
40939
  super(query, cacheKey);
@@ -41222,6 +40999,47 @@ class PostQueryStreamController extends QueryStreamController {
41222
40999
  }
41223
41000
  }
41224
41001
 
41002
+ const getPost = async (postId) => {
41003
+ const client = getActiveClient();
41004
+ client.log('post/getPost', postId);
41005
+ isInTombstone('post', postId);
41006
+ let payload;
41007
+ try {
41008
+ // API-FIX: endpoint should not be /list, parameters should be querystring.
41009
+ const response = await client.http.get(`/api/v3/posts/${encodeURIComponent(postId)}`);
41010
+ payload = response.data;
41011
+ }
41012
+ catch (error) {
41013
+ if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
41014
+ pushToTombstone('post', postId);
41015
+ }
41016
+ throw error;
41017
+ }
41018
+ const data = prepareMembershipPayload(payload, 'communityUsers');
41019
+ const cachedAt = client.cache && Date.now();
41020
+ if (client.cache)
41021
+ ingestInCache(data, { cachedAt });
41022
+ const { posts } = data;
41023
+ const result = posts.find(post => post.postId === postId);
41024
+ return {
41025
+ data: result,
41026
+ cachedAt,
41027
+ };
41028
+ };
41029
+ getPost.locally = (postId) => {
41030
+ const client = getActiveClient();
41031
+ client.log('post/getPost.locally', postId);
41032
+ if (!client.cache)
41033
+ return;
41034
+ const cached = pullFromCache(['post', 'get', postId]);
41035
+ if (!cached)
41036
+ return;
41037
+ return {
41038
+ data: cached.data,
41039
+ cachedAt: cached.cachedAt,
41040
+ };
41041
+ };
41042
+
41225
41043
  class PostLiveCollectionController extends LiveCollectionController {
41226
41044
  constructor(query, callback) {
41227
41045
  const queryStreamId = hash(query);
@@ -41271,7 +41089,7 @@ class PostLiveCollectionController extends LiveCollectionController {
41271
41089
  const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
41272
41090
  if (!currentCollection || currentCollection.data.includes(comment.referenceId))
41273
41091
  return;
41274
- await getPost$1(comment.referenceId);
41092
+ await getPost(comment.referenceId);
41275
41093
  callback(comment);
41276
41094
  });
41277
41095
  }, 'referenceId', 'post'),
@@ -41284,7 +41102,7 @@ class PostLiveCollectionController extends LiveCollectionController {
41284
41102
  const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
41285
41103
  if (!currentCollection || currentCollection.data.includes(comment.referenceId))
41286
41104
  return;
41287
- await getPost$1(comment.referenceId);
41105
+ await getPost(comment.referenceId);
41288
41106
  callback(comment);
41289
41107
  });
41290
41108
  }, 'referenceId', 'post'),
@@ -41887,6 +41705,237 @@ const semanticSearchPosts = (params, callback, config) => {
41887
41705
  };
41888
41706
  };
41889
41707
 
41708
+ class SearchPostPaginationController extends PaginationController {
41709
+ async getRequest(queryParams, token) {
41710
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, matchingOnlyParentPost, hashtags } = queryParams, params = __rest(queryParams, ["limit", "matchingOnlyParentPost", "hashtags"]);
41711
+ const { dataTypes } = params;
41712
+ const baseOptions = {
41713
+ type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
41714
+ };
41715
+ const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
41716
+ const { data: queryResponse } = await this.http.get(`/api/v1/search/posts`, {
41717
+ params: Object.assign(Object.assign({}, params), { hashtags,
41718
+ /*
41719
+ * when creating post like image, file, video BE will create 2 posts
41720
+ * 1. parent post to store text with dataType=text
41721
+ * 2. child post to store dataTypes post data
41722
+ *
41723
+ * By default, BE queries only parent post
41724
+ */
41725
+ matchingOnlyParentPost: matchingOnlyParentPost !== null && matchingOnlyParentPost !== void 0 ? matchingOnlyParentPost : !(dataTypes === null || dataTypes === void 0 ? void 0 : dataTypes.length), options }),
41726
+ });
41727
+ return queryResponse;
41728
+ }
41729
+ }
41730
+
41731
+ class SearchPostQueryStreamController extends QueryStreamController {
41732
+ constructor(query, cacheKey, notifyChange, preparePayload) {
41733
+ super(query, cacheKey);
41734
+ this.notifyChange = notifyChange;
41735
+ this.preparePayload = preparePayload;
41736
+ }
41737
+ async saveToMainDB(response) {
41738
+ const processedPayload = await this.preparePayload(response);
41739
+ const client = getActiveClient();
41740
+ const cachedAt = client.cache && Date.now();
41741
+ if (client.cache) {
41742
+ ingestInCache(processedPayload, { cachedAt });
41743
+ }
41744
+ }
41745
+ appendToQueryStream(response, direction, refresh = false) {
41746
+ var _a, _b;
41747
+ if (refresh) {
41748
+ pushToCache(this.cacheKey, {
41749
+ data: response.posts.map(getResolver('post')),
41750
+ });
41751
+ }
41752
+ else {
41753
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
41754
+ const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
41755
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
41756
+ }
41757
+ }
41758
+ reactor(action) {
41759
+ return (post) => {
41760
+ var _a, _b;
41761
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
41762
+ if (!collection)
41763
+ return;
41764
+ if (post.parentPostId && post.isDeleted) {
41765
+ const parentPost = (_b = pullFromCache([
41766
+ 'post',
41767
+ 'get',
41768
+ post.parentPostId,
41769
+ ])) === null || _b === void 0 ? void 0 : _b.data;
41770
+ if (!parentPost)
41771
+ return;
41772
+ parentPost.children = parentPost.children.filter(childId => childId !== post.postId);
41773
+ pushToCache(['post', 'get', parentPost.postId], parentPost);
41774
+ }
41775
+ if (action === EnumPostActions.OnPostDeclined) {
41776
+ collection.data = collection.data.filter(postId => postId !== post.postId);
41777
+ }
41778
+ if (action === EnumPostActions.OnPostCreated || action === EnumPostActions.OnPostApproved) {
41779
+ collection.data = [...new Set([post.postId, ...collection.data])];
41780
+ }
41781
+ pushToCache(this.cacheKey, collection);
41782
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
41783
+ };
41784
+ }
41785
+ subscribeRTE(createSubscriber) {
41786
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
41787
+ }
41788
+ }
41789
+
41790
+ class SearchPostLiveCollectionController extends LiveCollectionController {
41791
+ constructor(query, callback) {
41792
+ const queryStreamId = hash(query);
41793
+ const cacheKey = ['posts', 'collection', queryStreamId];
41794
+ const paginationController = new SearchPostPaginationController(query);
41795
+ super(paginationController, queryStreamId, cacheKey, callback);
41796
+ this.query = query;
41797
+ this.queryStreamController = new SearchPostQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
41798
+ this.callback = callback.bind(this);
41799
+ this.loadPage({ initial: true });
41800
+ }
41801
+ setup() {
41802
+ var _a;
41803
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
41804
+ if (!collection) {
41805
+ pushToCache(this.cacheKey, {
41806
+ data: [],
41807
+ params: {},
41808
+ });
41809
+ }
41810
+ }
41811
+ async persistModel(queryPayload) {
41812
+ await this.queryStreamController.saveToMainDB(queryPayload);
41813
+ }
41814
+ persistQueryStream({ response, direction, refresh, }) {
41815
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
41816
+ }
41817
+ startSubscription() {
41818
+ return this.queryStreamController.subscribeRTE([
41819
+ { fn: onPostCreated, action: EnumPostActions.OnPostCreated },
41820
+ { fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
41821
+ { fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
41822
+ { fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
41823
+ { fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
41824
+ { fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
41825
+ { fn: onPostApproved, action: EnumPostActions.OnPostApproved },
41826
+ { fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
41827
+ { fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
41828
+ { fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
41829
+ { fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
41830
+ { fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
41831
+ { fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
41832
+ {
41833
+ fn: convertEventPayload((callback) => {
41834
+ return onCommentCreated(async (comment) => {
41835
+ var _a;
41836
+ const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
41837
+ if (!currentCollection || currentCollection.data.includes(comment.referenceId))
41838
+ return;
41839
+ await getPost(comment.referenceId);
41840
+ callback(comment);
41841
+ });
41842
+ }, 'referenceId', 'post'),
41843
+ action: EnumPostActions.OnPostUpdated,
41844
+ },
41845
+ {
41846
+ fn: convertEventPayload((callback) => {
41847
+ return onCommentDeleted(async (comment) => {
41848
+ var _a;
41849
+ const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
41850
+ if (!currentCollection || currentCollection.data.includes(comment.referenceId))
41851
+ return;
41852
+ await getPost(comment.referenceId);
41853
+ callback(comment);
41854
+ });
41855
+ }, 'referenceId', 'post'),
41856
+ action: EnumPostActions.OnPostUpdated,
41857
+ },
41858
+ ]);
41859
+ }
41860
+ notifyChange({ origin, loading, error }) {
41861
+ var _a, _b;
41862
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
41863
+ if (!collection)
41864
+ return;
41865
+ const data = this.applyFilter((_b = collection.data
41866
+ .map(id => pullFromCache(['post', 'get', id]))
41867
+ .filter(isNonNullable)
41868
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
41869
+ if (!this.shouldNotify(data) && origin === 'event')
41870
+ return;
41871
+ this.callback({
41872
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
41873
+ data,
41874
+ hasNextPage: !!this.paginationController.getNextToken(),
41875
+ loading,
41876
+ error,
41877
+ });
41878
+ }
41879
+ applyFilter(data) {
41880
+ var _a;
41881
+ let posts = data;
41882
+ if ((_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.length) {
41883
+ posts = filterByPostDataTypes(posts, this.query.dataTypes);
41884
+ }
41885
+ switch (this.query.sortBy) {
41886
+ case 'firstCreated':
41887
+ posts = posts.sort(sortByFirstCreated);
41888
+ break;
41889
+ case 'lastCreated':
41890
+ default:
41891
+ posts = posts.sort(sortByLastCreated);
41892
+ break;
41893
+ }
41894
+ return posts;
41895
+ }
41896
+ }
41897
+
41898
+ /* begin_public_function
41899
+ id: post.query
41900
+ */
41901
+ /**
41902
+ * ```js
41903
+ * import { PostRepository } from '@amityco/ts-sdk'
41904
+ *
41905
+ * let posts = []
41906
+ * const unsub = PostRepository.searchPostsByHashtag({
41907
+ * hashtags: ['amity'],
41908
+ * limit: 10,
41909
+ * }, response => merge(posts, response.data))
41910
+ * ```
41911
+ *
41912
+ * Observe all mutations on a list of {@link Amity.Post} for a given target object
41913
+ *
41914
+ * @param params.hashtags the hashtags to search for
41915
+ * @param callback the function to call when new data are available
41916
+ * @param config
41917
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
41918
+ *
41919
+ * @category Posts Live Collection
41920
+ */
41921
+ const searchPostsByHashtag = (params, callback, config) => {
41922
+ const { log, cache } = getActiveClient();
41923
+ if (!cache) {
41924
+ console.log(ENABLE_CACHE_MESSAGE);
41925
+ }
41926
+ const timestamp = Date.now();
41927
+ log(`searchPostsByHashtag(tmpid: ${timestamp}) > listen`);
41928
+ const postsLiveCollection = new SearchPostLiveCollectionController(params, callback);
41929
+ const disposers = postsLiveCollection.startSubscription();
41930
+ const cacheKey = postsLiveCollection.getCacheKey();
41931
+ disposers.push(() => dropFromCache(cacheKey));
41932
+ return () => {
41933
+ log(`searchPostsByHashtag(tmpid: ${timestamp}) > dispose`);
41934
+ disposers.forEach(fn => fn());
41935
+ };
41936
+ };
41937
+ /* end_public_function */
41938
+
41890
41939
  var index$8 = /*#__PURE__*/Object.freeze({
41891
41940
  __proto__: null,
41892
41941
  getPostByIds: getPostByIds,
@@ -41901,6 +41950,7 @@ var index$8 = /*#__PURE__*/Object.freeze({
41901
41950
  unflagPost: unflagPost,
41902
41951
  isPostFlaggedByMe: isPostFlaggedByMe,
41903
41952
  createClipPost: createClipPost,
41953
+ getPostsByHashtag: getPostsByHashtag,
41904
41954
  onPostCreated: onPostCreated,
41905
41955
  onPostUpdated: onPostUpdated,
41906
41956
  onPostDeleted: onPostDeleted,
@@ -41910,11 +41960,12 @@ var index$8 = /*#__PURE__*/Object.freeze({
41910
41960
  onPostUnflagged: onPostUnflagged,
41911
41961
  onPostReactionAdded: onPostReactionAdded,
41912
41962
  onPostReactionRemoved: onPostReactionRemoved,
41913
- getPost: getPost,
41963
+ getPost: getPost$1,
41914
41964
  getPosts: getPosts,
41915
41965
  getPinnedPosts: getPinnedPosts,
41916
41966
  getGlobalPinnedPosts: getGlobalPinnedPosts,
41917
- semanticSearchPosts: semanticSearchPosts
41967
+ semanticSearchPosts: semanticSearchPosts,
41968
+ searchPostsByHashtag: searchPostsByHashtag
41918
41969
  });
41919
41970
 
41920
41971
  /* begin_public_function
@@ -45111,4 +45162,4 @@ var index = /*#__PURE__*/Object.freeze({
45111
45162
  getReactions: getReactions
45112
45163
  });
45113
45164
 
45114
- export { API_REGIONS, index$3 as AdRepository, index$b as CategoryRepository, index$f as ChannelRepository, index$o as Client, index$a as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$c as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, index$9 as FeedRepository, FileAccessTypeEnum, index$l as FileRepository, FileType, index$1 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index as LiveReactionRepository, index$5 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$j as MessageRepository, index$6 as PollRepository, PostContentType, index$8 as PostRepository, index$k as ReactionRepository, index$4 as StoryRepository, index$7 as StreamRepository, index$i as SubChannelRepository, SubscriptionLevels, index$m as UserRepository, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveReactionTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$2 as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };
45165
+ export { API_REGIONS, index$3 as AdRepository, index$b as CategoryRepository, index$f as ChannelRepository, index$o as Client, index$9 as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$c as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, index$a as FeedRepository, FileAccessTypeEnum, index$l as FileRepository, FileType, index$1 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index as LiveReactionRepository, index$5 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$j as MessageRepository, index$6 as PollRepository, PostContentType, index$8 as PostRepository, index$k as ReactionRepository, index$4 as StoryRepository, index$7 as StreamRepository, index$i as SubChannelRepository, SubscriptionLevels, index$m as UserRepository, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveReactionTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$2 as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };