@amityco/ts-sdk 7.7.1-00acca4a.0 → 7.7.1-11a1171d.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/feed.d.ts +0 -31
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/feed.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/feed.js +1 -21
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/feed.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/hashtag.d.ts +11 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/hashtag.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/hashtag.js +2 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/hashtag.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/post.d.ts +14 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/post.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/post.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/index.d.ts +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/index.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/index.js +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/index.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/index.d.ts +0 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/index.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/index.js +0 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/index.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/createPost.d.ts +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/createPost.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/editPost.d.ts +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/editPost.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/queryPosts.js +2 -2
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/queryPosts.js.map +1 -1
- 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
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/{feedRepository/observers/getUserFeed/LiveCollectionController.js → postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.js} +9 -12
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.d.ts +5 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.js +27 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.js.map +1 -0
- 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
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/{feedRepository/observers/getUserFeed/QueryStreamController.js → postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.js} +6 -19
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/index.d.ts +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/index.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/index.js +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/index.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/searchPostsByHashtag.d.ts +22 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/searchPostsByHashtag.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/searchPostsByHashtag.js +45 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/searchPostsByHashtag.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/tsconfig.tsbuildinfo +1 -1
- package/dist/@types/domains/feed.d.ts +0 -31
- package/dist/@types/domains/feed.d.ts.map +1 -1
- package/dist/@types/domains/hashtag.d.ts +11 -0
- package/dist/@types/domains/hashtag.d.ts.map +1 -0
- package/dist/@types/domains/post.d.ts +14 -1
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/@types/index.d.ts +1 -0
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/feedRepository/index.d.ts +0 -1
- package/dist/feedRepository/index.d.ts.map +1 -1
- package/dist/index.cjs.js +1332 -1336
- package/dist/index.esm.js +1331 -1335
- package/dist/index.umd.js +4 -4
- package/dist/postRepository/api/createPost.d.ts +1 -1
- package/dist/postRepository/api/editPost.d.ts +1 -1
- package/dist/{feedRepository/observers/getUserFeed/LiveCollectionController.d.ts → postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.d.ts} +4 -4
- package/dist/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.d.ts.map +1 -0
- package/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.d.ts +5 -0
- package/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.d.ts.map +1 -0
- 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
- package/dist/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.d.ts.map +1 -0
- package/dist/postRepository/observers/index.d.ts +1 -0
- package/dist/postRepository/observers/index.d.ts.map +1 -1
- package/dist/postRepository/observers/searchPostsByHashtag.d.ts +22 -0
- package/dist/postRepository/observers/searchPostsByHashtag.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/@types/domains/feed.ts +0 -43
- package/src/@types/domains/hashtag.ts +11 -0
- package/src/@types/domains/post.ts +18 -1
- package/src/@types/index.ts +1 -0
- package/src/feedRepository/index.ts +0 -1
- package/src/postRepository/api/createPost.ts +1 -1
- package/src/postRepository/api/editPost.ts +1 -1
- package/src/postRepository/api/queryPosts.ts +2 -2
- package/src/{feedRepository/observers/getUserFeed/LiveCollectionController.ts → postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.ts} +17 -27
- package/src/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.ts +49 -0
- package/src/{feedRepository/observers/getUserFeed/QueryStreamController.ts → postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.ts} +9 -29
- package/src/postRepository/observers/index.ts +1 -0
- package/src/postRepository/observers/searchPostsByHashtag.ts +56 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/LiveCollectionController.d.ts.map +0 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/LiveCollectionController.js.map +0 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/PaginationController.d.ts +0 -5
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/PaginationController.d.ts.map +0 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/PaginationController.js +0 -15
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/PaginationController.js.map +0 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/QueryStreamController.d.ts.map +0 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/QueryStreamController.js.map +0 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed.d.ts +0 -23
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed.d.ts.map +0 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed.js +0 -46
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed.js.map +0 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/index.d.ts +0 -2
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/index.d.ts.map +0 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/index.js +0 -2
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/index.js.map +0 -1
- package/dist/feedRepository/observers/getUserFeed/LiveCollectionController.d.ts.map +0 -1
- package/dist/feedRepository/observers/getUserFeed/PaginationController.d.ts +0 -5
- package/dist/feedRepository/observers/getUserFeed/PaginationController.d.ts.map +0 -1
- package/dist/feedRepository/observers/getUserFeed/QueryStreamController.d.ts.map +0 -1
- package/dist/feedRepository/observers/getUserFeed.d.ts +0 -23
- package/dist/feedRepository/observers/getUserFeed.d.ts.map +0 -1
- package/dist/feedRepository/observers/index.d.ts +0 -2
- package/dist/feedRepository/observers/index.d.ts.map +0 -1
- package/src/feedRepository/observers/getUserFeed/PaginationController.ts +0 -37
- package/src/feedRepository/observers/getUserFeed.ts +0 -56
- package/src/feedRepository/observers/index.ts +0 -1
package/dist/index.esm.js
CHANGED
|
@@ -39272,1035 +39272,1010 @@ getCustomRankingGlobalFeed.locally = (query) => {
|
|
|
39272
39272
|
: undefined;
|
|
39273
39273
|
};
|
|
39274
39274
|
|
|
39275
|
-
|
|
39276
|
-
|
|
39277
|
-
|
|
39278
|
-
|
|
39279
|
-
|
|
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:
|
|
39282
|
+
id: post.get_by_ids
|
|
39373
39283
|
*/
|
|
39374
39284
|
/**
|
|
39375
39285
|
* ```js
|
|
39376
|
-
* import {
|
|
39377
|
-
* const
|
|
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.
|
|
39290
|
+
* Fetches a collection of {@link Amity.Post} objects
|
|
39381
39291
|
*
|
|
39382
|
-
* @param
|
|
39383
|
-
* @returns the associated collection of {@link Amity.
|
|
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
|
|
39295
|
+
* @category Post API
|
|
39386
39296
|
* @async
|
|
39387
39297
|
*/
|
|
39388
|
-
const
|
|
39298
|
+
const getPostByIds = async (postIds) => {
|
|
39389
39299
|
const client = getActiveClient();
|
|
39390
|
-
client.log('
|
|
39391
|
-
const
|
|
39392
|
-
let
|
|
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/
|
|
39396
|
-
params: {
|
|
39305
|
+
const response = await client.http.get(`/api/v3/posts/list`, {
|
|
39306
|
+
params: { postIds: encodedPostIds },
|
|
39397
39307
|
});
|
|
39398
|
-
|
|
39308
|
+
payload = response.data;
|
|
39399
39309
|
}
|
|
39400
39310
|
catch (error) {
|
|
39401
|
-
|
|
39311
|
+
postIds.forEach(postId => {
|
|
39402
39312
|
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
39403
|
-
pushToTombstone('
|
|
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.
|
|
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 {
|
|
39420
|
-
* const
|
|
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.
|
|
39334
|
+
* Fetches a collection of {@link Amity.Post} objects from cache
|
|
39424
39335
|
*
|
|
39425
|
-
* @param
|
|
39426
|
-
* @returns the associated collection of {@link Amity.
|
|
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
|
|
39339
|
+
* @category Post API
|
|
39429
39340
|
*/
|
|
39430
|
-
|
|
39341
|
+
getPostByIds.locally = (postIds) => {
|
|
39431
39342
|
var _a;
|
|
39432
39343
|
const client = getActiveClient();
|
|
39433
|
-
client.log('
|
|
39344
|
+
client.log('post/getPostByIds.locally', postIds);
|
|
39434
39345
|
if (!client.cache)
|
|
39435
39346
|
return;
|
|
39436
|
-
const cached =
|
|
39437
|
-
.map(
|
|
39347
|
+
const cached = postIds
|
|
39348
|
+
.map(postId => pullFromCache(['post', 'get', postId]))
|
|
39438
39349
|
.filter(Boolean);
|
|
39439
|
-
const
|
|
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) <
|
|
39352
|
+
if ((cached === null || cached === void 0 ? void 0 : cached.length) < postIds.length)
|
|
39442
39353
|
return;
|
|
39443
39354
|
return {
|
|
39444
|
-
data:
|
|
39355
|
+
data: posts.map(LinkedObject.post),
|
|
39445
39356
|
cachedAt: oldest.cachedAt,
|
|
39446
39357
|
};
|
|
39447
39358
|
};
|
|
39448
39359
|
|
|
39449
39360
|
/* begin_public_function
|
|
39450
|
-
id:
|
|
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 {
|
|
39455
|
-
* const
|
|
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.
|
|
39373
|
+
* Creates an {@link Amity.Post}
|
|
39459
39374
|
*
|
|
39460
|
-
* @param bundle The data necessary to create a new {@link Amity.
|
|
39461
|
-
* @returns The newly created {@link Amity.
|
|
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
|
|
39378
|
+
* @category Post API
|
|
39464
39379
|
* @async
|
|
39465
39380
|
*/
|
|
39466
|
-
const
|
|
39467
|
-
var _a;
|
|
39381
|
+
const createPost = async (bundle) => {
|
|
39468
39382
|
const client = getActiveClient();
|
|
39469
|
-
client.log('
|
|
39470
|
-
|
|
39471
|
-
|
|
39472
|
-
|
|
39473
|
-
|
|
39474
|
-
|
|
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
|
-
|
|
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.
|
|
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:
|
|
39403
|
+
id: post.edit, post.edit.custom_post
|
|
39532
39404
|
*/
|
|
39533
39405
|
/**
|
|
39534
39406
|
* ```js
|
|
39535
|
-
* import {
|
|
39536
|
-
* const updated = await
|
|
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.
|
|
39413
|
+
* Updates an {@link Amity.Post}
|
|
39542
39414
|
*
|
|
39543
|
-
* @param
|
|
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.
|
|
39417
|
+
* @returns the updated {@link Amity.Post} object
|
|
39546
39418
|
*
|
|
39547
|
-
* @category
|
|
39419
|
+
* @category Post API
|
|
39548
39420
|
* @async
|
|
39549
39421
|
*/
|
|
39550
|
-
const
|
|
39422
|
+
const editPost = async (postId, patch) => {
|
|
39551
39423
|
const client = getActiveClient();
|
|
39552
|
-
client.log('user/
|
|
39553
|
-
const { data } = await client.http.put(`/api/
|
|
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('
|
|
39558
|
-
const {
|
|
39430
|
+
fireEvent('local.post.updated', data);
|
|
39431
|
+
const { posts } = data;
|
|
39559
39432
|
return {
|
|
39560
|
-
data: LinkedObject.
|
|
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 {
|
|
39641
|
-
* const success = await
|
|
39441
|
+
* import { deletePost } from '@amityco/ts-sdk'
|
|
39442
|
+
* const success = await deletePost('foobar')
|
|
39642
39443
|
* ```
|
|
39643
39444
|
*
|
|
39644
|
-
* Deletes a {@link Amity.
|
|
39445
|
+
* Deletes a {@link Amity.Post}
|
|
39645
39446
|
*
|
|
39646
|
-
* @param
|
|
39647
|
-
* @return A success boolean if the {@link Amity.
|
|
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
|
-
* @
|
|
39450
|
+
* @private
|
|
39650
39451
|
* @async
|
|
39651
39452
|
*/
|
|
39652
|
-
const
|
|
39453
|
+
const deletePost = async (postId, permanent = false) => {
|
|
39653
39454
|
var _a;
|
|
39654
39455
|
const client = getActiveClient();
|
|
39655
|
-
const
|
|
39656
|
-
|
|
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
|
-
|
|
39459
|
+
postId,
|
|
39660
39460
|
permanent,
|
|
39661
39461
|
},
|
|
39662
39462
|
});
|
|
39663
|
-
// to
|
|
39664
|
-
|
|
39665
|
-
|
|
39666
|
-
|
|
39667
|
-
|
|
39668
|
-
|
|
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
|
-
|
|
39671
|
-
|
|
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
|
-
|
|
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.
|
|
39703
|
-
|
|
39704
|
-
|
|
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
|
-
|
|
39511
|
+
videoStreamings: [],
|
|
39708
39512
|
});
|
|
39709
|
-
|
|
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:
|
|
39517
|
+
id: post.soft_delete
|
|
39721
39518
|
*/
|
|
39722
39519
|
/**
|
|
39723
39520
|
* ```js
|
|
39724
|
-
* import {
|
|
39725
|
-
* const success = await
|
|
39521
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
39522
|
+
* const success = await PostRepository.softDeletePost('foobar')
|
|
39726
39523
|
* ```
|
|
39727
39524
|
*
|
|
39728
|
-
*
|
|
39525
|
+
* Soft deletes a {@link Amity.Post}
|
|
39729
39526
|
*
|
|
39730
|
-
* @param
|
|
39731
|
-
* @return A success boolean if the {@link Amity.
|
|
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
|
|
39530
|
+
* @category Post API
|
|
39734
39531
|
* @async
|
|
39735
39532
|
*/
|
|
39736
|
-
const
|
|
39533
|
+
const softDeletePost = async (postId) => {
|
|
39737
39534
|
const client = getActiveClient();
|
|
39738
|
-
client.log('
|
|
39739
|
-
const softDeleted =
|
|
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:
|
|
39542
|
+
id: post.hard_delete
|
|
39746
39543
|
*/
|
|
39747
39544
|
/**
|
|
39748
39545
|
* ```js
|
|
39749
|
-
* import {
|
|
39750
|
-
* const success = await
|
|
39546
|
+
* import { hardDeletePost } from '@amityco/ts-sdk'
|
|
39547
|
+
* const success = await hardDeletePost('foobar')
|
|
39751
39548
|
* ```
|
|
39752
39549
|
*
|
|
39753
|
-
*
|
|
39550
|
+
* Hard deletes a {@link Amity.Post}
|
|
39754
39551
|
*
|
|
39755
|
-
* @param
|
|
39756
|
-
* @return A success boolean if the {@link Amity.
|
|
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
|
|
39555
|
+
* @category Post API
|
|
39759
39556
|
* @async
|
|
39760
39557
|
*/
|
|
39761
|
-
const
|
|
39558
|
+
const hardDeletePost = async (postId) => {
|
|
39762
39559
|
const client = getActiveClient();
|
|
39763
|
-
client.log('
|
|
39764
|
-
const hardDeleted =
|
|
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:
|
|
39567
|
+
id: post.approve
|
|
39771
39568
|
*/
|
|
39772
39569
|
/**
|
|
39773
39570
|
* ```js
|
|
39774
|
-
* import {
|
|
39775
|
-
*
|
|
39571
|
+
* import { approvePost } from '@amityco/ts-sdk'
|
|
39572
|
+
*
|
|
39573
|
+
* const { data: post } = await approvePost('postId')
|
|
39776
39574
|
* ```
|
|
39777
39575
|
*
|
|
39778
|
-
*
|
|
39779
|
-
* @param reason the reason to flag the comment
|
|
39780
|
-
* @returns the created report result
|
|
39576
|
+
* Approves a {@link Amity.Post}
|
|
39781
39577
|
*
|
|
39782
|
-
* @
|
|
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
|
|
39583
|
+
*/
|
|
39584
|
+
const approvePost = async (postId) => {
|
|
39786
39585
|
const client = getActiveClient();
|
|
39787
|
-
client.log('
|
|
39788
|
-
const
|
|
39789
|
-
|
|
39790
|
-
|
|
39791
|
-
|
|
39792
|
-
|
|
39793
|
-
}
|
|
39794
|
-
const
|
|
39795
|
-
|
|
39796
|
-
|
|
39797
|
-
|
|
39798
|
-
|
|
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
|
+
};
|
|
39601
|
+
};
|
|
39602
|
+
/* end_public_function */
|
|
39603
|
+
|
|
39604
|
+
/* begin_public_function
|
|
39605
|
+
id: post.decline
|
|
39606
|
+
*/
|
|
39607
|
+
/**
|
|
39608
|
+
* ```js
|
|
39609
|
+
* import { declinePost } from '@amityco/ts-sdk'
|
|
39610
|
+
*
|
|
39611
|
+
* const {data: post} = await declinePost('postId')
|
|
39612
|
+
* ```
|
|
39613
|
+
*
|
|
39614
|
+
* Declines a {@link Amity.Post}
|
|
39615
|
+
*
|
|
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
|
|
39620
|
+
* @async
|
|
39621
|
+
*/
|
|
39622
|
+
const declinePost = async (postId) => {
|
|
39623
|
+
const client = getActiveClient();
|
|
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);
|
|
39629
|
+
}
|
|
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
|
+
};
|
|
39639
|
+
};
|
|
39640
|
+
/* end_public_function */
|
|
39641
|
+
|
|
39642
|
+
/* begin_public_function
|
|
39643
|
+
id: post.flag
|
|
39644
|
+
*/
|
|
39645
|
+
/**
|
|
39646
|
+
* ```js
|
|
39647
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
39648
|
+
* const flagged = await PostRepository.flagPost(postId, reason)
|
|
39649
|
+
* ```
|
|
39650
|
+
*
|
|
39651
|
+
* @param postId of the post to flag
|
|
39652
|
+
* @param reason the reason to flag the post
|
|
39653
|
+
* @returns a boolean
|
|
39654
|
+
*
|
|
39655
|
+
* @category Post API
|
|
39656
|
+
* @async
|
|
39657
|
+
* */
|
|
39658
|
+
const flagPost = async (postId, reason) => {
|
|
39659
|
+
const client = getActiveClient();
|
|
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 : '',
|
|
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);
|
|
39799
39672
|
return !!payload;
|
|
39800
39673
|
};
|
|
39801
39674
|
/* end_public_function */
|
|
39802
39675
|
|
|
39803
39676
|
/* begin_public_function
|
|
39804
|
-
id:
|
|
39677
|
+
id: post.unflag
|
|
39805
39678
|
*/
|
|
39806
39679
|
/**
|
|
39807
39680
|
* ```js
|
|
39808
|
-
* import {
|
|
39809
|
-
* const unflagged = await
|
|
39681
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
39682
|
+
* const unflagged = await PostRepository.unflagPost(postId)
|
|
39810
39683
|
* ```
|
|
39811
39684
|
*
|
|
39812
|
-
* @param
|
|
39813
|
-
* @returns the
|
|
39685
|
+
* @param postId of the post to unflag
|
|
39686
|
+
* @returns the unflag post result
|
|
39814
39687
|
*
|
|
39815
|
-
* @category
|
|
39688
|
+
* @category Post API
|
|
39816
39689
|
* @async
|
|
39817
39690
|
* */
|
|
39818
|
-
const
|
|
39691
|
+
const unflagPost = async (postId) => {
|
|
39819
39692
|
const client = getActiveClient();
|
|
39820
|
-
client.log('
|
|
39821
|
-
const { data: payload } = await client.http.delete(`/api/v3/
|
|
39693
|
+
client.log('post/unflagPost', postId);
|
|
39694
|
+
const { data: payload } = await client.http.delete(`/api/v3/posts/${encodeURIComponent(postId)}/unflag`);
|
|
39822
39695
|
if (client.cache) {
|
|
39823
|
-
ingestInCache(payload);
|
|
39696
|
+
ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
|
|
39824
39697
|
}
|
|
39825
|
-
fireEvent('
|
|
39698
|
+
fireEvent('post.unflagged', payload);
|
|
39826
39699
|
return !!payload;
|
|
39827
39700
|
};
|
|
39828
39701
|
/* end_public_function */
|
|
39829
39702
|
|
|
39830
39703
|
/* begin_public_function
|
|
39831
|
-
id:
|
|
39704
|
+
id: post.check_flag_by_me
|
|
39832
39705
|
*/
|
|
39833
39706
|
/**
|
|
39834
39707
|
* ```js
|
|
39835
|
-
* import {
|
|
39836
|
-
* const isReported = await
|
|
39708
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
39709
|
+
* const isReported = await PostRepository.isPostFlaggedByMe('post', postId)
|
|
39837
39710
|
* ```
|
|
39838
39711
|
*
|
|
39839
|
-
* @param
|
|
39840
|
-
* @returns `true` if the
|
|
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.
|
|
39841
39714
|
*
|
|
39842
|
-
* @category
|
|
39715
|
+
* @category Post API
|
|
39843
39716
|
* @async
|
|
39844
39717
|
* */
|
|
39845
|
-
const
|
|
39718
|
+
const isPostFlaggedByMe = async (postId) => {
|
|
39846
39719
|
const client = getActiveClient();
|
|
39847
|
-
client.log('
|
|
39848
|
-
const { data: { result }, } = await client.http.get(`/api/v3/
|
|
39720
|
+
client.log('post/isPostFlaggedByMe', postId);
|
|
39721
|
+
const { data: { result }, } = await client.http.get(`/api/v3/posts/${postId}/isflagbyme`);
|
|
39849
39722
|
return result;
|
|
39850
39723
|
};
|
|
39851
39724
|
/* end_public_function */
|
|
39852
39725
|
|
|
39853
|
-
|
|
39726
|
+
/* begin_public_function
|
|
39727
|
+
id: post.create.clip_post
|
|
39728
|
+
*/
|
|
39729
|
+
/**
|
|
39730
|
+
* ```js
|
|
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
|
+
* }))
|
|
39739
|
+
* ```
|
|
39740
|
+
*
|
|
39741
|
+
* Creates an {@link Amity.Post}
|
|
39742
|
+
*
|
|
39743
|
+
* @param bundle The data necessary to create a new {@link Amity.Post}
|
|
39744
|
+
* @returns The newly created {@link Amity.Post}
|
|
39745
|
+
*
|
|
39746
|
+
* @category Post API
|
|
39747
|
+
* @async
|
|
39748
|
+
*/
|
|
39749
|
+
const createClipPost = async (bundle) => {
|
|
39854
39750
|
const client = getActiveClient();
|
|
39855
|
-
client.log('
|
|
39856
|
-
|
|
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,
|
|
39762
|
+
};
|
|
39763
|
+
};
|
|
39764
|
+
/* end_public_function */
|
|
39765
|
+
|
|
39766
|
+
/* begin_public_function
|
|
39767
|
+
id: comment.get_by_ids
|
|
39768
|
+
*/
|
|
39769
|
+
/**
|
|
39770
|
+
* ```js
|
|
39771
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
39772
|
+
* const comments = await CommentRepository.getCommentByIds(['foo', 'bar'])
|
|
39773
|
+
* ```
|
|
39774
|
+
*
|
|
39775
|
+
* Fetches a collection of {@link Amity.Comment} objects
|
|
39776
|
+
*
|
|
39777
|
+
* @param commentIds the IDs of the {@link Amity.Comment} to fetch
|
|
39778
|
+
* @returns the associated collection of {@link Amity.Comment} objects
|
|
39779
|
+
*
|
|
39780
|
+
* @category Comment API
|
|
39781
|
+
* @async
|
|
39782
|
+
*/
|
|
39783
|
+
const getCommentByIds = async (commentIds) => {
|
|
39784
|
+
const client = getActiveClient();
|
|
39785
|
+
client.log('comment/getCommentByIds', commentIds);
|
|
39786
|
+
const encodedCommentIds = commentIds.map(commentId => encodeURIComponent(commentId));
|
|
39857
39787
|
let data;
|
|
39858
39788
|
try {
|
|
39859
39789
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
39860
|
-
const response = await client.http.get(`/api/v3/comments
|
|
39790
|
+
const response = await client.http.get(`/api/v3/comments/list`, {
|
|
39791
|
+
params: { commentIds: encodedCommentIds },
|
|
39792
|
+
});
|
|
39861
39793
|
data = response.data;
|
|
39862
39794
|
}
|
|
39863
39795
|
catch (error) {
|
|
39864
|
-
|
|
39865
|
-
|
|
39866
|
-
|
|
39796
|
+
commentIds.forEach(commentId => {
|
|
39797
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
39798
|
+
pushToTombstone('comment', commentId);
|
|
39799
|
+
}
|
|
39800
|
+
});
|
|
39867
39801
|
throw error;
|
|
39868
39802
|
}
|
|
39869
39803
|
const cachedAt = client.cache && Date.now();
|
|
39870
39804
|
if (client.cache)
|
|
39871
39805
|
ingestInCache(data, { cachedAt });
|
|
39872
|
-
const { comments } = data;
|
|
39873
39806
|
return {
|
|
39874
|
-
data: comments.
|
|
39807
|
+
data: data.comments.map(comment => LinkedObject.comment(comment)),
|
|
39875
39808
|
cachedAt,
|
|
39876
39809
|
};
|
|
39877
39810
|
};
|
|
39878
|
-
|
|
39811
|
+
/* end_public_function */
|
|
39812
|
+
/**
|
|
39813
|
+
* ```js
|
|
39814
|
+
* import { getCommentByIds } from '@amityco/ts-sdk'
|
|
39815
|
+
* const comments = getCommentByIds.locally(['foo', 'bar'])
|
|
39816
|
+
* ```
|
|
39817
|
+
*
|
|
39818
|
+
* Fetches a collection of {@link Amity.Comment} objects from cache
|
|
39819
|
+
*
|
|
39820
|
+
* @param commentIds the IDs of the {@link Amity.Comment} to fetch
|
|
39821
|
+
* @returns the associated collection of {@link Amity.Comment} objects
|
|
39822
|
+
*
|
|
39823
|
+
* @category Comment API
|
|
39824
|
+
*/
|
|
39825
|
+
getCommentByIds.locally = (commentIds) => {
|
|
39826
|
+
var _a;
|
|
39879
39827
|
const client = getActiveClient();
|
|
39880
|
-
client.log('comment/
|
|
39828
|
+
client.log('comment/getCommentByIds.locally', commentIds);
|
|
39881
39829
|
if (!client.cache)
|
|
39882
39830
|
return;
|
|
39883
|
-
const cached =
|
|
39884
|
-
|
|
39831
|
+
const cached = commentIds
|
|
39832
|
+
.map(commentId => pullFromCache(['comment', 'get', commentId]))
|
|
39833
|
+
.filter(Boolean);
|
|
39834
|
+
const comments = cached.map(({ data }) => data);
|
|
39835
|
+
const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
|
|
39836
|
+
if ((cached === null || cached === void 0 ? void 0 : cached.length) < commentIds.length)
|
|
39885
39837
|
return;
|
|
39886
39838
|
return {
|
|
39887
|
-
data:
|
|
39888
|
-
cachedAt:
|
|
39839
|
+
data: comments.map(comment => LinkedObject.comment(comment)),
|
|
39840
|
+
cachedAt: oldest.cachedAt,
|
|
39889
39841
|
};
|
|
39890
39842
|
};
|
|
39891
39843
|
|
|
39844
|
+
/* begin_public_function
|
|
39845
|
+
id: comment.create
|
|
39846
|
+
*/
|
|
39892
39847
|
/**
|
|
39893
39848
|
* ```js
|
|
39894
|
-
* import {
|
|
39895
|
-
* const
|
|
39896
|
-
* // ...
|
|
39897
|
-
* })
|
|
39849
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
39850
|
+
* const newComment = await CommentRepository.createComment(bundle)
|
|
39898
39851
|
* ```
|
|
39899
39852
|
*
|
|
39900
|
-
*
|
|
39853
|
+
* Creates an {@link Amity.Comment}
|
|
39901
39854
|
*
|
|
39902
|
-
* @param
|
|
39903
|
-
* @returns
|
|
39855
|
+
* @param bundle The data necessary to create a new {@link Amity.Comment}
|
|
39856
|
+
* @returns The newly created {@link Amity.Comment}
|
|
39904
39857
|
*
|
|
39905
|
-
* @category Comment
|
|
39858
|
+
* @category Comment API
|
|
39859
|
+
* @async
|
|
39906
39860
|
*/
|
|
39907
|
-
const
|
|
39908
|
-
|
|
39909
|
-
/**
|
|
39910
|
-
* ```js
|
|
39911
|
-
* import { onLocalCommentReactionAdded } from '@amityco/ts-sdk'
|
|
39912
|
-
* const dispose = onLocalCommentReactionAdded(comment => {
|
|
39913
|
-
* // ...
|
|
39914
|
-
* })
|
|
39915
|
-
* ```
|
|
39916
|
-
*
|
|
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
|
|
39921
|
-
*
|
|
39922
|
-
* @category Comment Events
|
|
39923
|
-
*/
|
|
39924
|
-
const onLocalCommentReactionAdded = (callback) => {
|
|
39861
|
+
const createComment = async (bundle) => {
|
|
39862
|
+
var _a;
|
|
39925
39863
|
const client = getActiveClient();
|
|
39926
|
-
|
|
39927
|
-
|
|
39928
|
-
|
|
39864
|
+
client.log('comment/createComment', bundle);
|
|
39865
|
+
const { data } = await client.http.post('/api/v3/comments', bundle);
|
|
39866
|
+
const { comments } = data;
|
|
39867
|
+
// BE always returns an array of comments If it got record 0 from BE it might have a problem on creation logic
|
|
39868
|
+
if (comments.length === 0)
|
|
39869
|
+
throw new Error('Comment not created');
|
|
39870
|
+
const cachedAt = client.cache && Date.now();
|
|
39871
|
+
if (client.cache)
|
|
39872
|
+
ingestInCache(data, { cachedAt });
|
|
39873
|
+
if (['post', 'content'].includes(bundle.referenceType)) {
|
|
39874
|
+
const post = (_a = pullFromCache(['post', 'get', bundle.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
39875
|
+
if (post) {
|
|
39876
|
+
post.commentsCount += 1;
|
|
39877
|
+
fireEvent('local.post.updated', {
|
|
39878
|
+
posts: [post],
|
|
39879
|
+
categories: [],
|
|
39880
|
+
comments: [],
|
|
39881
|
+
communities: [],
|
|
39882
|
+
communityUsers: data.communityUsers,
|
|
39883
|
+
feeds: [],
|
|
39884
|
+
files: data.files,
|
|
39885
|
+
postChildren: [],
|
|
39886
|
+
users: data.users,
|
|
39887
|
+
videoStreamings: [],
|
|
39888
|
+
});
|
|
39929
39889
|
}
|
|
39930
|
-
|
|
39931
|
-
|
|
39932
|
-
|
|
39890
|
+
}
|
|
39891
|
+
else if (bundle.referenceType === 'story') {
|
|
39892
|
+
const storyIndex = pullFromCache([
|
|
39893
|
+
"story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
|
|
39894
|
+
bundle.referenceId,
|
|
39895
|
+
]);
|
|
39896
|
+
if (storyIndex === null || storyIndex === void 0 ? void 0 : storyIndex.data) {
|
|
39897
|
+
const cacheStory = pullFromCache([
|
|
39898
|
+
"story" /* STORY_KEY_CACHE.STORY */,
|
|
39899
|
+
'get',
|
|
39900
|
+
storyIndex.data,
|
|
39901
|
+
]);
|
|
39902
|
+
if (cacheStory === null || cacheStory === void 0 ? void 0 : cacheStory.data) {
|
|
39903
|
+
fireEvent('story.updated', {
|
|
39904
|
+
stories: [
|
|
39905
|
+
Object.assign(Object.assign({}, cacheStory.data), { commentsCount: cacheStory.data.commentsCount + 1, comments: [...new Set([...cacheStory.data.comments, comments[0].commentId])] }),
|
|
39906
|
+
],
|
|
39907
|
+
categories: [],
|
|
39908
|
+
comments,
|
|
39909
|
+
communities: [],
|
|
39910
|
+
communityUsers: data.communityUsers,
|
|
39911
|
+
files: data.files,
|
|
39912
|
+
users: data.users,
|
|
39913
|
+
});
|
|
39914
|
+
}
|
|
39933
39915
|
}
|
|
39916
|
+
}
|
|
39917
|
+
fireEvent('local.comment.created', data);
|
|
39918
|
+
return {
|
|
39919
|
+
data: LinkedObject.comment(comments[0]),
|
|
39920
|
+
cachedAt,
|
|
39934
39921
|
};
|
|
39935
|
-
return createEventSubscriber(client, 'local.comment.addReaction', 'local.comment.addReaction', filter);
|
|
39936
39922
|
};
|
|
39923
|
+
/* end_public_function */
|
|
39937
39924
|
|
|
39925
|
+
/* begin_public_function
|
|
39926
|
+
id: comment.update_comment
|
|
39927
|
+
*/
|
|
39938
39928
|
/**
|
|
39939
39929
|
* ```js
|
|
39940
|
-
* import {
|
|
39941
|
-
* const
|
|
39942
|
-
*
|
|
39930
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
39931
|
+
* const updated = await CommentRepository.updateComment(commentId, {
|
|
39932
|
+
* data: { text: 'hello world' }
|
|
39943
39933
|
* })
|
|
39944
39934
|
* ```
|
|
39945
39935
|
*
|
|
39946
|
-
*
|
|
39936
|
+
* Updates an {@link Amity.Comment}
|
|
39947
39937
|
*
|
|
39948
|
-
* @param
|
|
39949
|
-
* @
|
|
39938
|
+
* @param commentId The ID of the {@link Amity.Comment} to edit
|
|
39939
|
+
* @param patch The patch data to apply
|
|
39940
|
+
* @returns the updated {@link Amity.Comment} object
|
|
39950
39941
|
*
|
|
39951
|
-
* @category Comment
|
|
39942
|
+
* @category Comment API
|
|
39943
|
+
* @async
|
|
39952
39944
|
*/
|
|
39953
|
-
const
|
|
39945
|
+
const updateComment = async (commentId, patch) => {
|
|
39954
39946
|
const client = getActiveClient();
|
|
39955
|
-
|
|
39956
|
-
|
|
39957
|
-
|
|
39958
|
-
|
|
39959
|
-
|
|
39960
|
-
|
|
39961
|
-
|
|
39947
|
+
client.log('user/updateComment', patch);
|
|
39948
|
+
const { data } = await client.http.put(`/api/v3/comments/${encodeURIComponent(commentId)}`, patch);
|
|
39949
|
+
const cachedAt = client.cache && Date.now();
|
|
39950
|
+
if (client.cache)
|
|
39951
|
+
ingestInCache(data, { cachedAt });
|
|
39952
|
+
fireEvent('comment.updated', data);
|
|
39953
|
+
const { comments } = data;
|
|
39954
|
+
return {
|
|
39955
|
+
data: LinkedObject.comment(comments.find(comment => comment.commentId === commentId)),
|
|
39956
|
+
cachedAt,
|
|
39957
|
+
};
|
|
39958
|
+
};
|
|
39959
|
+
/* end_public_function */
|
|
39960
|
+
|
|
39961
|
+
// Due to we have optimistic logic, we will use referenceId as a id in SDK instead of storyId
|
|
39962
|
+
const applyMissingField = (rawData, isCreated = false) => {
|
|
39963
|
+
const { storyId, referenceId } = rawData;
|
|
39964
|
+
if (!isCreated) {
|
|
39965
|
+
if (referenceId)
|
|
39966
|
+
return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */ });
|
|
39967
|
+
}
|
|
39968
|
+
return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */, referenceId: storyId });
|
|
39969
|
+
};
|
|
39970
|
+
const convertRawStoryToInternal = (data, isCreated = false) => {
|
|
39971
|
+
const { stories } = data;
|
|
39972
|
+
const storiesData = stories.map(story => applyMissingField(story, isCreated));
|
|
39973
|
+
return Object.assign(Object.assign({}, data), { stories: storiesData });
|
|
39974
|
+
};
|
|
39975
|
+
|
|
39976
|
+
const getStoryByStoryId$1 = async (storyId) => {
|
|
39977
|
+
const client = getActiveClient();
|
|
39978
|
+
client.log('story/getStoryByStoryId', storyId);
|
|
39979
|
+
// Get story referenceId from cache
|
|
39980
|
+
const cacheReferenceId = pullFromCache([
|
|
39981
|
+
"story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
|
|
39982
|
+
storyId,
|
|
39983
|
+
]);
|
|
39984
|
+
if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
|
|
39985
|
+
const { data: referenceId } = cacheReferenceId;
|
|
39986
|
+
isInTombstone('story', referenceId);
|
|
39987
|
+
}
|
|
39988
|
+
let data;
|
|
39989
|
+
try {
|
|
39990
|
+
const response = await client.http.get(`/api/v4/stories/${storyId}`);
|
|
39991
|
+
data = convertRawStoryToInternal(response.data);
|
|
39992
|
+
}
|
|
39993
|
+
catch (error) {
|
|
39994
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
39995
|
+
pushToTombstone('story', storyId);
|
|
39962
39996
|
}
|
|
39997
|
+
throw error;
|
|
39998
|
+
}
|
|
39999
|
+
const cachedAt = client.cache && Date.now();
|
|
40000
|
+
if (client.cache) {
|
|
40001
|
+
ingestInCache(data, { cachedAt });
|
|
40002
|
+
}
|
|
40003
|
+
return {
|
|
40004
|
+
data: data.stories[0],
|
|
40005
|
+
cachedAt,
|
|
40006
|
+
};
|
|
40007
|
+
};
|
|
40008
|
+
getStoryByStoryId$1.locally = (storyId) => {
|
|
40009
|
+
const client = getActiveClient();
|
|
40010
|
+
client.log('story/getStorybyStoryId', storyId);
|
|
40011
|
+
// Get story referenceId from cache
|
|
40012
|
+
const cacheReferenceId = pullFromCache([
|
|
40013
|
+
"story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
|
|
40014
|
+
storyId,
|
|
40015
|
+
]);
|
|
40016
|
+
if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
|
|
40017
|
+
const { data: referenceId } = cacheReferenceId;
|
|
40018
|
+
isInTombstone('story', referenceId);
|
|
40019
|
+
}
|
|
40020
|
+
const cachedAt = client.cache && Date.now();
|
|
40021
|
+
const storyCache = pullFromCache(['story', 'get', storyId]);
|
|
40022
|
+
if (!storyCache)
|
|
40023
|
+
return;
|
|
40024
|
+
return {
|
|
40025
|
+
data: storyCache.data,
|
|
40026
|
+
cachedAt,
|
|
39963
40027
|
};
|
|
39964
|
-
return createEventSubscriber(client, 'local.comment.removeReaction', 'local.comment.removeReaction', filter);
|
|
39965
40028
|
};
|
|
39966
40029
|
|
|
39967
40030
|
/* begin_public_function
|
|
39968
|
-
id: comment.
|
|
40031
|
+
id: comment.soft_delete, comment.hard_delete
|
|
39969
40032
|
*/
|
|
39970
40033
|
/**
|
|
39971
40034
|
* ```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
|
-
* });
|
|
40035
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
40036
|
+
* const success = await CommentRepository.deleteComment('foobar')
|
|
39979
40037
|
* ```
|
|
39980
40038
|
*
|
|
39981
|
-
*
|
|
40039
|
+
* Deletes a {@link Amity.Comment}
|
|
39982
40040
|
*
|
|
39983
|
-
* @param commentId
|
|
39984
|
-
* @
|
|
39985
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the comment
|
|
40041
|
+
* @param commentId The {@link Amity.Comment} ID to delete
|
|
40042
|
+
* @return A success boolean if the {@link Amity.Comment} was deleted
|
|
39986
40043
|
*
|
|
39987
|
-
* @category Comment
|
|
40044
|
+
* @category Comment API
|
|
40045
|
+
* @async
|
|
39988
40046
|
*/
|
|
39989
|
-
const
|
|
39990
|
-
|
|
39991
|
-
|
|
39992
|
-
|
|
39993
|
-
|
|
39994
|
-
|
|
39995
|
-
|
|
39996
|
-
|
|
39997
|
-
|
|
39998
|
-
|
|
39999
|
-
|
|
40000
|
-
|
|
40001
|
-
};
|
|
40002
|
-
|
|
40003
|
-
|
|
40004
|
-
|
|
40005
|
-
|
|
40006
|
-
|
|
40007
|
-
|
|
40008
|
-
|
|
40009
|
-
|
|
40010
|
-
|
|
40011
|
-
|
|
40012
|
-
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options }),
|
|
40047
|
+
const deleteComment = async (commentId, permanent = false) => {
|
|
40048
|
+
var _a;
|
|
40049
|
+
const client = getActiveClient();
|
|
40050
|
+
const comment = await getComment$2(commentId);
|
|
40051
|
+
// API-FIX: This endpoint has not been implemented yet.
|
|
40052
|
+
await client.http.delete(`/api/v4/comments/${encodeURIComponent(commentId)}`, {
|
|
40053
|
+
params: {
|
|
40054
|
+
commentId,
|
|
40055
|
+
permanent,
|
|
40056
|
+
},
|
|
40057
|
+
});
|
|
40058
|
+
// to support hard deletion
|
|
40059
|
+
const deleted = Object.assign(Object.assign({}, comment.data), { isDeleted: true });
|
|
40060
|
+
if (comment.data.referenceType === 'story') {
|
|
40061
|
+
const story = await getStoryByStoryId$1(comment.data.referenceId);
|
|
40062
|
+
fireEvent('local.story.updated', {
|
|
40063
|
+
stories: [story.data],
|
|
40064
|
+
categories: [],
|
|
40065
|
+
comments: [],
|
|
40066
|
+
communities: [],
|
|
40067
|
+
communityUsers: [],
|
|
40068
|
+
files: [],
|
|
40069
|
+
users: [],
|
|
40013
40070
|
});
|
|
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
40071
|
}
|
|
40043
|
-
|
|
40044
|
-
|
|
40045
|
-
if (
|
|
40046
|
-
|
|
40047
|
-
|
|
40072
|
+
else {
|
|
40073
|
+
const post = (_a = pullFromCache(['post', 'get', comment.data.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
40074
|
+
if (post) {
|
|
40075
|
+
let removeCount;
|
|
40076
|
+
if (!deleted.parentId) {
|
|
40077
|
+
// NOTE: delete the parent comment will remove all children comments
|
|
40078
|
+
removeCount = deleted.childrenNumber + 1;
|
|
40079
|
+
}
|
|
40080
|
+
else
|
|
40081
|
+
removeCount = 1;
|
|
40082
|
+
post.commentsCount -= removeCount;
|
|
40083
|
+
fireEvent('local.post.updated', {
|
|
40084
|
+
posts: [post],
|
|
40085
|
+
categories: [],
|
|
40086
|
+
comments: [],
|
|
40087
|
+
communities: [],
|
|
40088
|
+
communityUsers: [],
|
|
40089
|
+
feeds: [],
|
|
40090
|
+
files: [],
|
|
40091
|
+
postChildren: [],
|
|
40092
|
+
users: [],
|
|
40093
|
+
videoStreamings: [],
|
|
40048
40094
|
});
|
|
40049
40095
|
}
|
|
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
|
-
}
|
|
40055
40096
|
}
|
|
40056
|
-
|
|
40057
|
-
|
|
40058
|
-
|
|
40059
|
-
|
|
40060
|
-
|
|
40061
|
-
|
|
40062
|
-
|
|
40063
|
-
|
|
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])];
|
|
40073
|
-
}
|
|
40074
|
-
pushToCache(this.cacheKey, collection);
|
|
40075
|
-
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
40076
|
-
};
|
|
40097
|
+
fireEvent('local.comment.deleted', {
|
|
40098
|
+
comments: [deleted],
|
|
40099
|
+
commentChildren: [],
|
|
40100
|
+
files: [],
|
|
40101
|
+
users: [],
|
|
40102
|
+
communityUsers: [],
|
|
40103
|
+
});
|
|
40104
|
+
if (permanent) {
|
|
40105
|
+
scheduleTask(() => pushToTombstone('comment', commentId));
|
|
40077
40106
|
}
|
|
40078
|
-
|
|
40079
|
-
|
|
40107
|
+
else {
|
|
40108
|
+
upsertInCache(['comment', 'get', commentId], { isDeleted: true });
|
|
40080
40109
|
}
|
|
40081
|
-
|
|
40110
|
+
return deleted;
|
|
40111
|
+
};
|
|
40112
|
+
/* end_public_function */
|
|
40082
40113
|
|
|
40114
|
+
/* begin_public_function
|
|
40115
|
+
id: comment.soft_delete
|
|
40116
|
+
*/
|
|
40083
40117
|
/**
|
|
40084
40118
|
* ```js
|
|
40085
|
-
* import {
|
|
40086
|
-
* const
|
|
40087
|
-
* // ...
|
|
40088
|
-
* })
|
|
40119
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
40120
|
+
* const success = await CommentRepository.softDeleteComment('foobar')
|
|
40089
40121
|
* ```
|
|
40090
40122
|
*
|
|
40091
|
-
*
|
|
40123
|
+
* Deletes a {@link Amity.Comment}
|
|
40092
40124
|
*
|
|
40093
|
-
* @param
|
|
40094
|
-
* @
|
|
40125
|
+
* @param commentId The {@link Amity.Comment} ID to delete
|
|
40126
|
+
* @return A success boolean if the {@link Amity.Comment} was deleted
|
|
40095
40127
|
*
|
|
40096
|
-
* @category Comment
|
|
40128
|
+
* @category Comment API
|
|
40129
|
+
* @async
|
|
40097
40130
|
*/
|
|
40098
|
-
const
|
|
40099
|
-
|
|
40131
|
+
const softDeleteComment = async (commentId) => {
|
|
40132
|
+
const client = getActiveClient();
|
|
40133
|
+
client.log('comment/softDeleteComment', commentId);
|
|
40134
|
+
const softDeleted = deleteComment(commentId);
|
|
40135
|
+
return softDeleted;
|
|
40100
40136
|
};
|
|
40101
|
-
|
|
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: {},
|
|
40120
|
-
});
|
|
40121
|
-
}
|
|
40122
|
-
}
|
|
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 },
|
|
40142
|
-
]);
|
|
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]);
|
|
40189
|
-
});
|
|
40190
|
-
}
|
|
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
|
-
}
|
|
40204
|
-
return comments;
|
|
40205
|
-
}
|
|
40206
|
-
}
|
|
40137
|
+
/* end_public_function */
|
|
40207
40138
|
|
|
40208
40139
|
/* begin_public_function
|
|
40209
|
-
id: comment.
|
|
40140
|
+
id: comment.hard_delete
|
|
40210
40141
|
*/
|
|
40211
40142
|
/**
|
|
40212
40143
|
* ```js
|
|
40213
|
-
* import {
|
|
40214
|
-
*
|
|
40215
|
-
* let comments = []
|
|
40216
|
-
* const unsub = getComments({
|
|
40217
|
-
* referenceType: Amity.InternalComment['referenceType'];
|
|
40218
|
-
* referenceId: Amity.InternalComment['referenceId'];
|
|
40219
|
-
* }, response => merge(comments, response.data))
|
|
40144
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
40145
|
+
* const success = await CommentRepository.hardDeleteComment('foobar')
|
|
40220
40146
|
* ```
|
|
40221
40147
|
*
|
|
40222
|
-
*
|
|
40148
|
+
* Deletes a {@link Amity.Comment}
|
|
40223
40149
|
*
|
|
40224
|
-
* @param
|
|
40225
|
-
* @
|
|
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
|
|
40150
|
+
* @param commentId The {@link Amity.Comment} ID to delete
|
|
40151
|
+
* @return A success boolean if the {@link Amity.Comment} was deleted
|
|
40228
40152
|
*
|
|
40229
|
-
* @category
|
|
40153
|
+
* @category Comment API
|
|
40154
|
+
* @async
|
|
40230
40155
|
*/
|
|
40231
|
-
const
|
|
40232
|
-
const
|
|
40233
|
-
|
|
40234
|
-
|
|
40235
|
-
|
|
40236
|
-
|
|
40237
|
-
|
|
40238
|
-
|
|
40239
|
-
|
|
40240
|
-
|
|
40241
|
-
|
|
40242
|
-
|
|
40243
|
-
|
|
40244
|
-
|
|
40156
|
+
const hardDeleteComment = async (commentId) => {
|
|
40157
|
+
const client = getActiveClient();
|
|
40158
|
+
client.log('comment/hardDeleteComment', commentId);
|
|
40159
|
+
const hardDeleted = deleteComment(commentId, true);
|
|
40160
|
+
return hardDeleted;
|
|
40161
|
+
};
|
|
40162
|
+
/* end_public_function */
|
|
40163
|
+
|
|
40164
|
+
/* begin_public_function
|
|
40165
|
+
id: comment.flag
|
|
40166
|
+
*/
|
|
40167
|
+
/**
|
|
40168
|
+
* ```js
|
|
40169
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
40170
|
+
* const flagged = await CommentRepository.flagComment(commentId, reason)
|
|
40171
|
+
* ```
|
|
40172
|
+
*
|
|
40173
|
+
* @param commentId The ID of the comment to flag
|
|
40174
|
+
* @param reason the reason to flag the comment
|
|
40175
|
+
* @returns the created report result
|
|
40176
|
+
*
|
|
40177
|
+
* @category Comment API
|
|
40178
|
+
* @async
|
|
40179
|
+
* */
|
|
40180
|
+
const flagComment = async (commentId, reason) => {
|
|
40181
|
+
const client = getActiveClient();
|
|
40182
|
+
client.log('comment/flagComment', commentId);
|
|
40183
|
+
const isPredefinedReason = reason &&
|
|
40184
|
+
Object.entries(ContentFlagReasonEnum).some(([key, value]) => key !== ContentFlagReasonEnum.Others && value === reason);
|
|
40185
|
+
const body = {
|
|
40186
|
+
reason: reason && isPredefinedReason ? reason : ContentFlagReasonEnum.Others,
|
|
40187
|
+
detail: reason && !isPredefinedReason ? reason : '',
|
|
40245
40188
|
};
|
|
40189
|
+
const { data: payload } = await client.http.post(`/api/v3/comments/${encodeURIComponent(commentId)}/flag`, body);
|
|
40190
|
+
if (client.cache) {
|
|
40191
|
+
ingestInCache(payload);
|
|
40192
|
+
}
|
|
40193
|
+
fireEvent('comment.flagged', payload);
|
|
40194
|
+
return !!payload;
|
|
40246
40195
|
};
|
|
40247
40196
|
/* end_public_function */
|
|
40248
40197
|
|
|
40249
|
-
|
|
40250
|
-
|
|
40251
|
-
|
|
40252
|
-
|
|
40253
|
-
|
|
40254
|
-
|
|
40255
|
-
|
|
40256
|
-
|
|
40257
|
-
|
|
40258
|
-
|
|
40259
|
-
|
|
40260
|
-
|
|
40261
|
-
|
|
40262
|
-
|
|
40263
|
-
|
|
40264
|
-
|
|
40265
|
-
|
|
40266
|
-
|
|
40267
|
-
|
|
40268
|
-
|
|
40269
|
-
|
|
40198
|
+
/* begin_public_function
|
|
40199
|
+
id: comment.unflag
|
|
40200
|
+
*/
|
|
40201
|
+
/**
|
|
40202
|
+
* ```js
|
|
40203
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
40204
|
+
* const unflagged = await CommentRepository.unflagComment('commentId')
|
|
40205
|
+
* ```
|
|
40206
|
+
*
|
|
40207
|
+
* @param commentId The ID of comment to unflag
|
|
40208
|
+
* @returns the unflagged result
|
|
40209
|
+
*
|
|
40210
|
+
* @category Comment API
|
|
40211
|
+
* @async
|
|
40212
|
+
* */
|
|
40213
|
+
const unflagComment = async (commentId) => {
|
|
40214
|
+
const client = getActiveClient();
|
|
40215
|
+
client.log('comment/unflagComment', commentId);
|
|
40216
|
+
const { data: payload } = await client.http.delete(`/api/v3/comments/${encodeURIComponent(commentId)}/unflag`);
|
|
40217
|
+
if (client.cache) {
|
|
40218
|
+
ingestInCache(payload);
|
|
40219
|
+
}
|
|
40220
|
+
fireEvent('comment.unflagged', payload);
|
|
40221
|
+
return !!payload;
|
|
40222
|
+
};
|
|
40223
|
+
/* end_public_function */
|
|
40224
|
+
|
|
40225
|
+
/* begin_public_function
|
|
40226
|
+
id: comment.check_flag_by_me
|
|
40227
|
+
*/
|
|
40228
|
+
/**
|
|
40229
|
+
* ```js
|
|
40230
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
40231
|
+
* const isReported = await CommentRepository.isCommentFlaggedByMe('commentId')
|
|
40232
|
+
* ```
|
|
40233
|
+
*
|
|
40234
|
+
* @param commentId The ID of the comment to check if flagged by current user
|
|
40235
|
+
* @returns `true` if the comment is flagged by me, `false` if doesn't.
|
|
40236
|
+
*
|
|
40237
|
+
* @category Comment API
|
|
40238
|
+
* @async
|
|
40239
|
+
* */
|
|
40240
|
+
const isCommentFlaggedByMe = async (commentId) => {
|
|
40241
|
+
const client = getActiveClient();
|
|
40242
|
+
client.log('comment/isCommentFlaggedByMe', commentId);
|
|
40243
|
+
const { data: { result }, } = await client.http.get(`/api/v3/comments/${commentId}/isflagbyme`);
|
|
40244
|
+
return result;
|
|
40245
|
+
};
|
|
40246
|
+
/* end_public_function */
|
|
40270
40247
|
|
|
40271
|
-
const
|
|
40248
|
+
const getComment$1 = async (commentId) => {
|
|
40272
40249
|
const client = getActiveClient();
|
|
40273
|
-
client.log('
|
|
40274
|
-
isInTombstone('
|
|
40275
|
-
let
|
|
40250
|
+
client.log('comment/getComment', commentId);
|
|
40251
|
+
isInTombstone('comment', commentId);
|
|
40252
|
+
let data;
|
|
40276
40253
|
try {
|
|
40277
40254
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
40278
|
-
const response = await client.http.get(`/api/v3/
|
|
40279
|
-
|
|
40255
|
+
const response = await client.http.get(`/api/v3/comments/${encodeURIComponent(commentId)}`);
|
|
40256
|
+
data = response.data;
|
|
40280
40257
|
}
|
|
40281
40258
|
catch (error) {
|
|
40282
40259
|
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
40283
|
-
pushToTombstone('
|
|
40260
|
+
pushToTombstone('comment', commentId);
|
|
40284
40261
|
}
|
|
40285
40262
|
throw error;
|
|
40286
40263
|
}
|
|
40287
|
-
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
40288
40264
|
const cachedAt = client.cache && Date.now();
|
|
40289
40265
|
if (client.cache)
|
|
40290
40266
|
ingestInCache(data, { cachedAt });
|
|
40291
|
-
const {
|
|
40292
|
-
const result = posts.find(post => post.postId === postId);
|
|
40267
|
+
const { comments } = data;
|
|
40293
40268
|
return {
|
|
40294
|
-
data:
|
|
40269
|
+
data: comments.find(comment => comment.commentId === commentId),
|
|
40295
40270
|
cachedAt,
|
|
40296
40271
|
};
|
|
40297
40272
|
};
|
|
40298
|
-
|
|
40273
|
+
getComment$1.locally = (commentId) => {
|
|
40299
40274
|
const client = getActiveClient();
|
|
40300
|
-
client.log('
|
|
40275
|
+
client.log('comment/getComment.locally', commentId);
|
|
40301
40276
|
if (!client.cache)
|
|
40302
40277
|
return;
|
|
40303
|
-
const cached = pullFromCache(['
|
|
40278
|
+
const cached = pullFromCache(['comment', 'get', commentId]);
|
|
40304
40279
|
if (!cached)
|
|
40305
40280
|
return;
|
|
40306
40281
|
return {
|
|
@@ -40311,116 +40286,234 @@ getPost$1.locally = (postId) => {
|
|
|
40311
40286
|
|
|
40312
40287
|
/**
|
|
40313
40288
|
* ```js
|
|
40314
|
-
* import {
|
|
40315
|
-
* const dispose =
|
|
40289
|
+
* import { onCommentDeleteLocal } from '@amityco/ts-sdk'
|
|
40290
|
+
* const dispose = onCommentDeleteLocal(comment => {
|
|
40316
40291
|
* // ...
|
|
40317
40292
|
* })
|
|
40318
40293
|
* ```
|
|
40319
40294
|
*
|
|
40320
|
-
* Fired when a {@link Amity.
|
|
40295
|
+
* Fired when a {@link Amity.InternalComment} has been deleted
|
|
40321
40296
|
*
|
|
40322
40297
|
* @param callback The function to call when the event was fired
|
|
40323
40298
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
40324
40299
|
*
|
|
40325
|
-
* @category
|
|
40300
|
+
* @category Comment Events
|
|
40326
40301
|
*/
|
|
40327
|
-
const
|
|
40302
|
+
const onCommentDeleteLocal = (callback) => createLocalCommentEventSubscriber('local.comment.deleted', callback);
|
|
40328
40303
|
|
|
40329
40304
|
/**
|
|
40330
40305
|
* ```js
|
|
40331
|
-
* import {
|
|
40332
|
-
* const dispose =
|
|
40306
|
+
* import { onLocalCommentReactionAdded } from '@amityco/ts-sdk'
|
|
40307
|
+
* const dispose = onLocalCommentReactionAdded(comment => {
|
|
40333
40308
|
* // ...
|
|
40334
40309
|
* })
|
|
40335
40310
|
* ```
|
|
40336
40311
|
*
|
|
40337
|
-
* Fired when a {@link Amity.
|
|
40312
|
+
* Fired when a {@link Amity.InternalComment} has been reacted
|
|
40338
40313
|
*
|
|
40339
40314
|
* @param callback The function to call when the event was fired
|
|
40340
40315
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
40341
40316
|
*
|
|
40342
|
-
* @category
|
|
40317
|
+
* @category Comment Events
|
|
40343
40318
|
*/
|
|
40344
|
-
const
|
|
40319
|
+
const onLocalCommentReactionAdded = (callback) => {
|
|
40345
40320
|
const client = getActiveClient();
|
|
40346
|
-
const filter = ({
|
|
40321
|
+
const filter = ({ comment }) => {
|
|
40347
40322
|
if (!client.cache) {
|
|
40348
|
-
callback(
|
|
40323
|
+
callback(comment);
|
|
40349
40324
|
}
|
|
40350
40325
|
else {
|
|
40351
|
-
upsertInCache(['
|
|
40352
|
-
callback(
|
|
40326
|
+
upsertInCache(['comment', 'get', comment.commentId], comment);
|
|
40327
|
+
callback(commentLinkedObject(comment));
|
|
40353
40328
|
}
|
|
40354
40329
|
};
|
|
40355
|
-
return createEventSubscriber(client, 'local.
|
|
40330
|
+
return createEventSubscriber(client, 'local.comment.addReaction', 'local.comment.addReaction', filter);
|
|
40356
40331
|
};
|
|
40357
40332
|
|
|
40358
40333
|
/**
|
|
40359
40334
|
* ```js
|
|
40360
|
-
* import {
|
|
40361
|
-
* const dispose =
|
|
40335
|
+
* import { onLocalCommentReactionRemoved } from '@amityco/ts-sdk'
|
|
40336
|
+
* const dispose = onLocalCommentReactionRemoved(comment => {
|
|
40362
40337
|
* // ...
|
|
40363
40338
|
* })
|
|
40364
40339
|
* ```
|
|
40365
40340
|
*
|
|
40366
|
-
* Fired when a {@link Amity.
|
|
40341
|
+
* Fired when a {@link Amity.InternalComment} has been reacted
|
|
40367
40342
|
*
|
|
40368
40343
|
* @param callback The function to call when the event was fired
|
|
40369
40344
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
40370
40345
|
*
|
|
40371
|
-
* @category
|
|
40346
|
+
* @category Comment Events
|
|
40372
40347
|
*/
|
|
40373
|
-
const
|
|
40348
|
+
const onLocalCommentReactionRemoved = (callback) => {
|
|
40374
40349
|
const client = getActiveClient();
|
|
40375
|
-
const filter = ({
|
|
40350
|
+
const filter = ({ comment }) => {
|
|
40376
40351
|
if (!client.cache) {
|
|
40377
|
-
callback(
|
|
40352
|
+
callback(comment);
|
|
40378
40353
|
}
|
|
40379
40354
|
else {
|
|
40380
|
-
upsertInCache(['
|
|
40381
|
-
callback(
|
|
40355
|
+
upsertInCache(['comment', 'get', comment.commentId], comment);
|
|
40356
|
+
callback(commentLinkedObject(comment));
|
|
40382
40357
|
}
|
|
40383
40358
|
};
|
|
40384
|
-
return createEventSubscriber(client, 'local.
|
|
40359
|
+
return createEventSubscriber(client, 'local.comment.removeReaction', 'local.comment.removeReaction', filter);
|
|
40385
40360
|
};
|
|
40386
40361
|
|
|
40362
|
+
/* begin_public_function
|
|
40363
|
+
id: comment.get
|
|
40364
|
+
*/
|
|
40387
40365
|
/**
|
|
40388
40366
|
* ```js
|
|
40389
|
-
* import {
|
|
40390
|
-
*
|
|
40391
|
-
*
|
|
40392
|
-
*
|
|
40367
|
+
* import { CommentRepository } from '@amityco/ts-sdk';
|
|
40368
|
+
*
|
|
40369
|
+
* let comment;
|
|
40370
|
+
*
|
|
40371
|
+
* const unsub = CommentRepository.getComment(commentId, response => {
|
|
40372
|
+
* comment = response.data;
|
|
40373
|
+
* });
|
|
40393
40374
|
* ```
|
|
40394
40375
|
*
|
|
40395
|
-
*
|
|
40376
|
+
* Observe all mutation on a given {@link Amity.Comment}
|
|
40396
40377
|
*
|
|
40397
|
-
* @param
|
|
40398
|
-
* @
|
|
40378
|
+
* @param commentId the ID of the comment to observe
|
|
40379
|
+
* @param callback the function to call when new data are available
|
|
40380
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the comment
|
|
40399
40381
|
*
|
|
40400
|
-
* @category
|
|
40382
|
+
* @category Comment Live Object
|
|
40401
40383
|
*/
|
|
40402
|
-
const
|
|
40384
|
+
const getComment = (commentId, callback) => {
|
|
40385
|
+
return liveObject(commentId, callback, 'commentId', getComment$1, [
|
|
40386
|
+
onCommentDeleteLocal,
|
|
40387
|
+
onCommentDeleted,
|
|
40388
|
+
onCommentFlagged,
|
|
40389
|
+
onCommentReactionAdded,
|
|
40390
|
+
onCommentReactionRemoved,
|
|
40391
|
+
onCommentUnflagged,
|
|
40392
|
+
onCommentUpdated,
|
|
40393
|
+
onLocalCommentReactionAdded,
|
|
40394
|
+
onLocalCommentReactionRemoved,
|
|
40395
|
+
]);
|
|
40396
|
+
};
|
|
40397
|
+
/* end_public_function */
|
|
40403
40398
|
|
|
40404
|
-
class
|
|
40405
|
-
|
|
40406
|
-
const
|
|
40407
|
-
const
|
|
40408
|
-
|
|
40409
|
-
|
|
40410
|
-
|
|
40411
|
-
|
|
40412
|
-
|
|
40413
|
-
|
|
40399
|
+
class CommentPaginationController extends PaginationController {
|
|
40400
|
+
async getRequest(queryParams, token) {
|
|
40401
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
|
|
40402
|
+
const baseOptions = {
|
|
40403
|
+
type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
|
|
40404
|
+
};
|
|
40405
|
+
const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
|
|
40406
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/comments`, {
|
|
40407
|
+
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options }),
|
|
40408
|
+
});
|
|
40409
|
+
return queryResponse;
|
|
40414
40410
|
}
|
|
40415
|
-
|
|
40416
|
-
|
|
40417
|
-
|
|
40418
|
-
|
|
40419
|
-
|
|
40420
|
-
|
|
40421
|
-
|
|
40422
|
-
|
|
40423
|
-
|
|
40411
|
+
}
|
|
40412
|
+
|
|
40413
|
+
var EnumCommentActions;
|
|
40414
|
+
(function (EnumCommentActions) {
|
|
40415
|
+
EnumCommentActions["OnCommentCreated"] = "onCommentCreated";
|
|
40416
|
+
EnumCommentActions["OnCommentUpdated"] = "onCommentUpdated";
|
|
40417
|
+
EnumCommentActions["OnCommentDeleted"] = "onCommentDeleted";
|
|
40418
|
+
EnumCommentActions["OnCommentFlagged"] = "onCommentFlagged";
|
|
40419
|
+
EnumCommentActions["OnCommentUnflagged"] = "onCommentUnflagged";
|
|
40420
|
+
EnumCommentActions["OnCommentReactionAdded"] = "onCommentReactionAdded";
|
|
40421
|
+
EnumCommentActions["OnCommentReactionRemoved"] = "onCommentReactionRemoved";
|
|
40422
|
+
})(EnumCommentActions || (EnumCommentActions = {}));
|
|
40423
|
+
|
|
40424
|
+
class CommentQueryStreamController extends QueryStreamController {
|
|
40425
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
40426
|
+
super(query, cacheKey);
|
|
40427
|
+
this.notifyChange = notifyChange;
|
|
40428
|
+
this.preparePayload = preparePayload;
|
|
40429
|
+
}
|
|
40430
|
+
async saveToMainDB(response) {
|
|
40431
|
+
const processedPayload = await this.preparePayload(response);
|
|
40432
|
+
const client = getActiveClient();
|
|
40433
|
+
const cachedAt = client.cache && Date.now();
|
|
40434
|
+
if (client.cache) {
|
|
40435
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
40436
|
+
}
|
|
40437
|
+
}
|
|
40438
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
40439
|
+
var _a, _b;
|
|
40440
|
+
if (refresh) {
|
|
40441
|
+
pushToCache(this.cacheKey, {
|
|
40442
|
+
data: response.comments.map(getResolver('comment')),
|
|
40443
|
+
});
|
|
40444
|
+
}
|
|
40445
|
+
else {
|
|
40446
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
40447
|
+
const comments = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
40448
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...comments, ...response.comments.map(getResolver('comment'))])] }));
|
|
40449
|
+
}
|
|
40450
|
+
}
|
|
40451
|
+
reactor(action) {
|
|
40452
|
+
return (comment) => {
|
|
40453
|
+
var _a;
|
|
40454
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
40455
|
+
if (this.query.referenceId !== comment.referenceId ||
|
|
40456
|
+
this.query.referenceType !== comment.referenceType ||
|
|
40457
|
+
!collection) {
|
|
40458
|
+
return;
|
|
40459
|
+
}
|
|
40460
|
+
if (this.query.parentId && this.query.parentId !== comment.parentId) {
|
|
40461
|
+
return;
|
|
40462
|
+
}
|
|
40463
|
+
if (!this.query.parentId && comment.parentId) {
|
|
40464
|
+
return;
|
|
40465
|
+
}
|
|
40466
|
+
if (action === EnumCommentActions.OnCommentCreated) {
|
|
40467
|
+
collection.data = [...new Set([comment.commentId, ...collection.data])];
|
|
40468
|
+
}
|
|
40469
|
+
pushToCache(this.cacheKey, collection);
|
|
40470
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
40471
|
+
};
|
|
40472
|
+
}
|
|
40473
|
+
subscribeRTE(createSubscriber) {
|
|
40474
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
40475
|
+
}
|
|
40476
|
+
}
|
|
40477
|
+
|
|
40478
|
+
/**
|
|
40479
|
+
* ```js
|
|
40480
|
+
* import { onCommentCreated } from '@amityco/ts-sdk'
|
|
40481
|
+
* const dispose = onCommentCreated(comment => {
|
|
40482
|
+
* // ...
|
|
40483
|
+
* })
|
|
40484
|
+
* ```
|
|
40485
|
+
*
|
|
40486
|
+
* Fired when a {@link Amity.InternalComment} has been created
|
|
40487
|
+
*
|
|
40488
|
+
* @param callback The function to call when the event was fired
|
|
40489
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
40490
|
+
*
|
|
40491
|
+
* @category Comment Events
|
|
40492
|
+
*/
|
|
40493
|
+
const onCommentCreatedLocal = (callback) => {
|
|
40494
|
+
return createLocalCommentEventSubscriber('local.comment.created', callback);
|
|
40495
|
+
};
|
|
40496
|
+
|
|
40497
|
+
class CommentLiveCollectionController extends LiveCollectionController {
|
|
40498
|
+
constructor(query, callback) {
|
|
40499
|
+
const queryStreamId = hash(query);
|
|
40500
|
+
const cacheKey = ['comments', 'collection', queryStreamId];
|
|
40501
|
+
const paginationController = new CommentPaginationController(query);
|
|
40502
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
40503
|
+
this.query = query;
|
|
40504
|
+
this.queryStreamController = new CommentQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommentPayload);
|
|
40505
|
+
this.callback = callback.bind(this);
|
|
40506
|
+
this.loadPage({ initial: true });
|
|
40507
|
+
}
|
|
40508
|
+
setup() {
|
|
40509
|
+
var _a;
|
|
40510
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
40511
|
+
if (!collection) {
|
|
40512
|
+
pushToCache(this.cacheKey, {
|
|
40513
|
+
data: [],
|
|
40514
|
+
params: {},
|
|
40515
|
+
});
|
|
40516
|
+
}
|
|
40424
40517
|
}
|
|
40425
40518
|
async persistModel(queryPayload) {
|
|
40426
40519
|
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
@@ -40430,45 +40523,17 @@ class UserFeedLiveCollectionController extends LiveCollectionController {
|
|
|
40430
40523
|
}
|
|
40431
40524
|
startSubscription() {
|
|
40432
40525
|
return this.queryStreamController.subscribeRTE([
|
|
40433
|
-
{ fn:
|
|
40434
|
-
{ fn:
|
|
40435
|
-
{ fn:
|
|
40436
|
-
{ fn:
|
|
40437
|
-
{ fn:
|
|
40438
|
-
{ fn:
|
|
40439
|
-
{ fn:
|
|
40440
|
-
{ fn:
|
|
40441
|
-
{ fn:
|
|
40442
|
-
{ fn:
|
|
40443
|
-
{ fn:
|
|
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
|
-
},
|
|
40526
|
+
{ fn: onCommentCreatedLocal, action: EnumCommentActions.OnCommentCreated },
|
|
40527
|
+
{ fn: onCommentDeleteLocal, action: EnumCommentActions.OnCommentDeleted },
|
|
40528
|
+
{ fn: onCommentCreated, action: EnumCommentActions.OnCommentCreated },
|
|
40529
|
+
{ fn: onCommentUpdated, action: EnumCommentActions.OnCommentUpdated },
|
|
40530
|
+
{ fn: onCommentDeleted, action: EnumCommentActions.OnCommentDeleted },
|
|
40531
|
+
{ fn: onCommentFlagged, action: EnumCommentActions.OnCommentFlagged },
|
|
40532
|
+
{ fn: onCommentUnflagged, action: EnumCommentActions.OnCommentUnflagged },
|
|
40533
|
+
{ fn: onCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
|
|
40534
|
+
{ fn: onCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
|
|
40535
|
+
{ fn: onLocalCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
|
|
40536
|
+
{ fn: onLocalCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
|
|
40472
40537
|
]);
|
|
40473
40538
|
}
|
|
40474
40539
|
notifyChange({ origin, loading, error }) {
|
|
@@ -40477,9 +40542,9 @@ class UserFeedLiveCollectionController extends LiveCollectionController {
|
|
|
40477
40542
|
if (!collection)
|
|
40478
40543
|
return;
|
|
40479
40544
|
const data = this.applyFilter((_b = collection.data
|
|
40480
|
-
.map(id => pullFromCache(['
|
|
40545
|
+
.map(id => pullFromCache(['comment', 'get', id]))
|
|
40481
40546
|
.filter(isNonNullable)
|
|
40482
|
-
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.
|
|
40547
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.comment);
|
|
40483
40548
|
if (!this.shouldNotify(data) && origin === 'event')
|
|
40484
40549
|
return;
|
|
40485
40550
|
this.callback({
|
|
@@ -40491,560 +40556,204 @@ class UserFeedLiveCollectionController extends LiveCollectionController {
|
|
|
40491
40556
|
});
|
|
40492
40557
|
}
|
|
40493
40558
|
applyFilter(data) {
|
|
40494
|
-
|
|
40495
|
-
let posts = data;
|
|
40559
|
+
let comments = data;
|
|
40496
40560
|
if (!this.query.includeDeleted) {
|
|
40497
|
-
|
|
40498
|
-
}
|
|
40499
|
-
if ((_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.length) {
|
|
40500
|
-
posts = filterByPostDataTypes(posts, this.query.dataTypes);
|
|
40561
|
+
comments = filterByPropEquality(comments, 'isDeleted', false);
|
|
40501
40562
|
}
|
|
40502
|
-
|
|
40503
|
-
|
|
40504
|
-
posts = posts.sort(sortByFirstCreated);
|
|
40505
|
-
break;
|
|
40506
|
-
case 'lastCreated':
|
|
40507
|
-
default:
|
|
40508
|
-
posts = posts.sort(sortByLastCreated);
|
|
40509
|
-
break;
|
|
40563
|
+
if (this.query.parentId) {
|
|
40564
|
+
comments = comments.filter(comment => comment.parentId === this.query.parentId);
|
|
40510
40565
|
}
|
|
40511
|
-
|
|
40512
|
-
|
|
40513
|
-
|
|
40514
|
-
|
|
40515
|
-
/* begin_public_function
|
|
40516
|
-
id: feed.query.user_feed
|
|
40517
|
-
*/
|
|
40518
|
-
/**
|
|
40519
|
-
* ```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))
|
|
40527
|
-
* ```
|
|
40528
|
-
*
|
|
40529
|
-
* Observe all mutations on a list of {@link Amity.Post} for a given user and feedSources
|
|
40530
|
-
*
|
|
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
|
|
40536
|
-
*
|
|
40537
|
-
* @category Posts Live Collection
|
|
40538
|
-
*/
|
|
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
|
-
};
|
|
40554
|
-
};
|
|
40555
|
-
/* end_public_function */
|
|
40556
|
-
|
|
40557
|
-
var index$9 = /*#__PURE__*/Object.freeze({
|
|
40558
|
-
__proto__: null,
|
|
40559
|
-
queryGlobalFeed: queryGlobalFeed,
|
|
40560
|
-
getCustomRankingGlobalFeed: getCustomRankingGlobalFeed,
|
|
40561
|
-
getUserFeed: getUserFeed
|
|
40562
|
-
});
|
|
40563
|
-
|
|
40564
|
-
/* begin_public_function
|
|
40565
|
-
id: post.get_by_ids
|
|
40566
|
-
*/
|
|
40567
|
-
/**
|
|
40568
|
-
* ```js
|
|
40569
|
-
* import { getPostByIds } from '@amityco/ts-sdk'
|
|
40570
|
-
* const { data: posts } = await getPostByIds(['foo', 'bar'])
|
|
40571
|
-
* ```
|
|
40572
|
-
*
|
|
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
|
|
40577
|
-
*
|
|
40578
|
-
* @category Post API
|
|
40579
|
-
* @async
|
|
40580
|
-
*/
|
|
40581
|
-
const getPostByIds = async (postIds) => {
|
|
40582
|
-
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);
|
|
40566
|
+
if (typeof this.query.hasFlag === 'boolean') {
|
|
40567
|
+
if (this.query.hasFlag) {
|
|
40568
|
+
comments = comments.filter(comment => comment.hashFlag != null);
|
|
40597
40569
|
}
|
|
40598
|
-
|
|
40599
|
-
|
|
40600
|
-
|
|
40601
|
-
|
|
40602
|
-
|
|
40603
|
-
|
|
40604
|
-
|
|
40605
|
-
|
|
40606
|
-
|
|
40607
|
-
|
|
40608
|
-
|
|
40609
|
-
|
|
40610
|
-
|
|
40611
|
-
|
|
40612
|
-
|
|
40613
|
-
|
|
40614
|
-
|
|
40615
|
-
|
|
40616
|
-
|
|
40617
|
-
|
|
40618
|
-
|
|
40619
|
-
|
|
40620
|
-
|
|
40621
|
-
|
|
40622
|
-
|
|
40623
|
-
|
|
40624
|
-
|
|
40625
|
-
|
|
40626
|
-
|
|
40627
|
-
|
|
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
|
-
};
|
|
40641
|
-
};
|
|
40642
|
-
|
|
40643
|
-
/* 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
|
|
40645
|
-
*/
|
|
40646
|
-
/**
|
|
40647
|
-
* ```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
|
-
* }))
|
|
40654
|
-
* ```
|
|
40655
|
-
*
|
|
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}
|
|
40660
|
-
*
|
|
40661
|
-
* @category Post API
|
|
40662
|
-
* @async
|
|
40663
|
-
*/
|
|
40664
|
-
const createPost = async (bundle) => {
|
|
40665
|
-
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;
|
|
40670
|
-
}
|
|
40671
|
-
const { data: payload } = await client.http.post('/api/v4/posts', bundle);
|
|
40672
|
-
fireEvent('post.created', payload);
|
|
40673
|
-
const data = preparePostPayload(payload);
|
|
40674
|
-
const cachedAt = client.cache && Date.now();
|
|
40675
|
-
if (client.cache)
|
|
40676
|
-
ingestInCache(data, { cachedAt });
|
|
40677
|
-
const { posts } = data;
|
|
40678
|
-
return {
|
|
40679
|
-
data: LinkedObject.post(posts[0]),
|
|
40680
|
-
cachedAt,
|
|
40681
|
-
};
|
|
40682
|
-
};
|
|
40683
|
-
/* end_public_function */
|
|
40684
|
-
|
|
40685
|
-
/* begin_public_function
|
|
40686
|
-
id: post.edit, post.edit.custom_post
|
|
40687
|
-
*/
|
|
40688
|
-
/**
|
|
40689
|
-
* ```js
|
|
40690
|
-
* import { PostRepository } from '@amityco/ts-sdk'
|
|
40691
|
-
* const updated = await PostRepository.editPost(postId, {
|
|
40692
|
-
* data: { text: 'hello world' }
|
|
40693
|
-
* })
|
|
40694
|
-
* ```
|
|
40695
|
-
*
|
|
40696
|
-
* Updates an {@link Amity.Post}
|
|
40697
|
-
*
|
|
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
|
|
40701
|
-
*
|
|
40702
|
-
* @category Post API
|
|
40703
|
-
* @async
|
|
40704
|
-
*/
|
|
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 */
|
|
40721
|
-
|
|
40722
|
-
/**
|
|
40723
|
-
* ```js
|
|
40724
|
-
* import { deletePost } from '@amityco/ts-sdk'
|
|
40725
|
-
* const success = await deletePost('foobar')
|
|
40726
|
-
* ```
|
|
40727
|
-
*
|
|
40728
|
-
* Deletes a {@link Amity.Post}
|
|
40729
|
-
*
|
|
40730
|
-
* @param postId The {@link Amity.Post} ID to delete
|
|
40731
|
-
* @return A success boolean if the {@link Amity.Post} was deleted
|
|
40732
|
-
*
|
|
40733
|
-
* @private
|
|
40734
|
-
* @async
|
|
40735
|
-
*/
|
|
40736
|
-
const deletePost = async (postId, permanent = false) => {
|
|
40737
|
-
var _a;
|
|
40738
|
-
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);
|
|
40797
|
-
};
|
|
40798
|
-
|
|
40799
|
-
/* begin_public_function
|
|
40800
|
-
id: post.soft_delete
|
|
40801
|
-
*/
|
|
40802
|
-
/**
|
|
40803
|
-
* ```js
|
|
40804
|
-
* import { PostRepository } from '@amityco/ts-sdk'
|
|
40805
|
-
* const success = await PostRepository.softDeletePost('foobar')
|
|
40806
|
-
* ```
|
|
40807
|
-
*
|
|
40808
|
-
* Soft deletes a {@link Amity.Post}
|
|
40809
|
-
*
|
|
40810
|
-
* @param postId The {@link Amity.Post} ID to soft delete
|
|
40811
|
-
* @return A success boolean if the {@link Amity.Post} was deleted
|
|
40812
|
-
*
|
|
40813
|
-
* @category Post API
|
|
40814
|
-
* @async
|
|
40815
|
-
*/
|
|
40816
|
-
const softDeletePost = async (postId) => {
|
|
40817
|
-
const client = getActiveClient();
|
|
40818
|
-
client.log('post/softDeletePost', postId);
|
|
40819
|
-
const softDeleted = await deletePost(postId, false);
|
|
40820
|
-
return LinkedObject.post(softDeleted);
|
|
40821
|
-
};
|
|
40822
|
-
/* end_public_function */
|
|
40823
|
-
|
|
40824
|
-
/* begin_public_function
|
|
40825
|
-
id: post.hard_delete
|
|
40826
|
-
*/
|
|
40827
|
-
/**
|
|
40828
|
-
* ```js
|
|
40829
|
-
* import { hardDeletePost } from '@amityco/ts-sdk'
|
|
40830
|
-
* const success = await hardDeletePost('foobar')
|
|
40831
|
-
* ```
|
|
40832
|
-
*
|
|
40833
|
-
* Hard deletes a {@link Amity.Post}
|
|
40834
|
-
*
|
|
40835
|
-
* @param postId The {@link Amity.Post} ID to be hard delete
|
|
40836
|
-
* @return A success boolean if the {@link Amity.Post} was deleted
|
|
40837
|
-
*
|
|
40838
|
-
* @category Post API
|
|
40839
|
-
* @async
|
|
40840
|
-
*/
|
|
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);
|
|
40846
|
-
};
|
|
40847
|
-
/* end_public_function */
|
|
40848
|
-
|
|
40849
|
-
/* begin_public_function
|
|
40850
|
-
id: post.approve
|
|
40851
|
-
*/
|
|
40852
|
-
/**
|
|
40853
|
-
* ```js
|
|
40854
|
-
* import { approvePost } from '@amityco/ts-sdk'
|
|
40855
|
-
*
|
|
40856
|
-
* const { data: post } = await approvePost('postId')
|
|
40857
|
-
* ```
|
|
40858
|
-
*
|
|
40859
|
-
* Approves a {@link Amity.Post}
|
|
40860
|
-
*
|
|
40861
|
-
* @param postId The {@link Amity.Post} ID to be approved
|
|
40862
|
-
* @return A {@link Amity.Post} that was approved
|
|
40863
|
-
*
|
|
40864
|
-
* @category Post API
|
|
40865
|
-
* @async
|
|
40866
|
-
*/
|
|
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);
|
|
40570
|
+
else {
|
|
40571
|
+
comments = comments.filter(comment => comment.hashFlag == null);
|
|
40572
|
+
}
|
|
40573
|
+
}
|
|
40574
|
+
if (this.query.dataTypes) {
|
|
40575
|
+
if (this.query.dataTypes.matchType === 'exact') {
|
|
40576
|
+
comments = comments.filter(comment => {
|
|
40577
|
+
var _a, _b;
|
|
40578
|
+
const sortedDataTypesQueryValue = ((_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.values.sort()) || [];
|
|
40579
|
+
const sortedDataTypesCommentValue = ((_b = comment.dataTypes) === null || _b === void 0 ? void 0 : _b.sort()) || [];
|
|
40580
|
+
if (sortedDataTypesCommentValue.length !== sortedDataTypesQueryValue.length) {
|
|
40581
|
+
return false;
|
|
40582
|
+
}
|
|
40583
|
+
return sortedDataTypesQueryValue.every((value, index) => value === sortedDataTypesCommentValue[index]);
|
|
40584
|
+
});
|
|
40585
|
+
}
|
|
40586
|
+
if (this.query.dataTypes.matchType === 'any') {
|
|
40587
|
+
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); }); });
|
|
40588
|
+
}
|
|
40589
|
+
}
|
|
40590
|
+
switch (this.query.sortBy) {
|
|
40591
|
+
case 'firstCreated':
|
|
40592
|
+
comments = comments.sort(sortByFirstCreated);
|
|
40593
|
+
break;
|
|
40594
|
+
case 'lastCreated':
|
|
40595
|
+
default:
|
|
40596
|
+
comments = comments.sort(sortByLastCreated);
|
|
40597
|
+
break;
|
|
40598
|
+
}
|
|
40599
|
+
return comments;
|
|
40875
40600
|
}
|
|
40876
|
-
|
|
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 */
|
|
40601
|
+
}
|
|
40886
40602
|
|
|
40887
40603
|
/* begin_public_function
|
|
40888
|
-
id:
|
|
40604
|
+
id: comment.query
|
|
40889
40605
|
*/
|
|
40890
40606
|
/**
|
|
40891
40607
|
* ```js
|
|
40892
|
-
* import {
|
|
40608
|
+
* import { getComments } from '@amityco/ts-sdk'
|
|
40893
40609
|
*
|
|
40894
|
-
*
|
|
40610
|
+
* let comments = []
|
|
40611
|
+
* const unsub = getComments({
|
|
40612
|
+
* referenceType: Amity.InternalComment['referenceType'];
|
|
40613
|
+
* referenceId: Amity.InternalComment['referenceId'];
|
|
40614
|
+
* }, response => merge(comments, response.data))
|
|
40895
40615
|
* ```
|
|
40896
40616
|
*
|
|
40897
|
-
*
|
|
40617
|
+
* Observe all mutations on a list of {@link Amity.InternalComment} for a given target object
|
|
40898
40618
|
*
|
|
40899
|
-
* @param
|
|
40900
|
-
* @
|
|
40619
|
+
* @param referenceType the type of the target
|
|
40620
|
+
* @param referenceId the ID of the target
|
|
40621
|
+
* @param callback the function to call when new data are available
|
|
40622
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
40901
40623
|
*
|
|
40902
|
-
* @category
|
|
40903
|
-
* @async
|
|
40624
|
+
* @category Comments Live Collection
|
|
40904
40625
|
*/
|
|
40905
|
-
const
|
|
40906
|
-
const
|
|
40907
|
-
|
|
40908
|
-
|
|
40909
|
-
// fire virtual event
|
|
40910
|
-
if (payload.posts[0].targetType === 'community') {
|
|
40911
|
-
fireEvent('community.updated', payload);
|
|
40626
|
+
const getComments = (params, callback, config) => {
|
|
40627
|
+
const { log, cache } = getActiveClient();
|
|
40628
|
+
if (!cache) {
|
|
40629
|
+
console.log('For using Live Collection feature you need to enable Cache!');
|
|
40912
40630
|
}
|
|
40913
|
-
|
|
40914
|
-
|
|
40915
|
-
const
|
|
40916
|
-
|
|
40917
|
-
|
|
40918
|
-
|
|
40919
|
-
|
|
40920
|
-
|
|
40631
|
+
const timestamp = Date.now();
|
|
40632
|
+
log(`getComments(tmpid: ${timestamp}) > listen`);
|
|
40633
|
+
const commentsLiveCollection = new CommentLiveCollectionController(params, callback);
|
|
40634
|
+
const disposers = commentsLiveCollection.startSubscription();
|
|
40635
|
+
const cacheKey = commentsLiveCollection.getCacheKey();
|
|
40636
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
40637
|
+
return () => {
|
|
40638
|
+
log(`getComments(tmpid: ${timestamp}) > dispose`);
|
|
40639
|
+
disposers.forEach(fn => fn());
|
|
40921
40640
|
};
|
|
40922
40641
|
};
|
|
40923
40642
|
/* end_public_function */
|
|
40924
40643
|
|
|
40925
|
-
|
|
40926
|
-
|
|
40927
|
-
|
|
40644
|
+
var index$9 = /*#__PURE__*/Object.freeze({
|
|
40645
|
+
__proto__: null,
|
|
40646
|
+
getCommentByIds: getCommentByIds,
|
|
40647
|
+
createComment: createComment,
|
|
40648
|
+
updateComment: updateComment,
|
|
40649
|
+
deleteComment: deleteComment,
|
|
40650
|
+
softDeleteComment: softDeleteComment,
|
|
40651
|
+
hardDeleteComment: hardDeleteComment,
|
|
40652
|
+
flagComment: flagComment,
|
|
40653
|
+
unflagComment: unflagComment,
|
|
40654
|
+
isCommentFlaggedByMe: isCommentFlaggedByMe,
|
|
40655
|
+
onCommentCreated: onCommentCreated,
|
|
40656
|
+
onCommentUpdated: onCommentUpdated,
|
|
40657
|
+
onCommentDeleted: onCommentDeleted,
|
|
40658
|
+
onCommentFlagged: onCommentFlagged,
|
|
40659
|
+
onCommentUnflagged: onCommentUnflagged,
|
|
40660
|
+
onCommentReactionAdded: onCommentReactionAdded,
|
|
40661
|
+
onCommentReactionRemoved: onCommentReactionRemoved,
|
|
40662
|
+
getComment: getComment,
|
|
40663
|
+
getComments: getComments
|
|
40664
|
+
});
|
|
40665
|
+
|
|
40928
40666
|
/**
|
|
40929
40667
|
* ```js
|
|
40930
|
-
* import {
|
|
40931
|
-
* const
|
|
40668
|
+
* import { onPostUpdatedLocal } from '@amityco/ts-sdk'
|
|
40669
|
+
* const dispose = onPostUpdatedLocal(post => {
|
|
40670
|
+
* // ...
|
|
40671
|
+
* })
|
|
40932
40672
|
* ```
|
|
40933
40673
|
*
|
|
40934
|
-
*
|
|
40935
|
-
* @param reason the reason to flag the post
|
|
40936
|
-
* @returns a boolean
|
|
40674
|
+
* Fired when a {@link Amity.InternalPost} has been updated
|
|
40937
40675
|
*
|
|
40938
|
-
* @
|
|
40939
|
-
* @
|
|
40940
|
-
*
|
|
40941
|
-
|
|
40942
|
-
|
|
40943
|
-
|
|
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 */
|
|
40676
|
+
* @param callback The function to call when the event was fired
|
|
40677
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
40678
|
+
*
|
|
40679
|
+
* @category Post Events
|
|
40680
|
+
*/
|
|
40681
|
+
const onPostUpdatedLocal = (callback) => createLocalPostEventSubscriber('local.post.updated', callback);
|
|
40958
40682
|
|
|
40959
|
-
/* begin_public_function
|
|
40960
|
-
id: post.unflag
|
|
40961
|
-
*/
|
|
40962
40683
|
/**
|
|
40963
40684
|
* ```js
|
|
40964
|
-
* import {
|
|
40965
|
-
* const
|
|
40685
|
+
* import { onLocalPostReactionAdded } from '@amityco/ts-sdk'
|
|
40686
|
+
* const dispose = onPostReactionAdded(post => {
|
|
40687
|
+
* // ...
|
|
40688
|
+
* })
|
|
40966
40689
|
* ```
|
|
40967
40690
|
*
|
|
40968
|
-
*
|
|
40969
|
-
* @returns the unflag post result
|
|
40691
|
+
* Fired when a {@link Amity.InternalPost} has been reacted
|
|
40970
40692
|
*
|
|
40971
|
-
* @
|
|
40972
|
-
* @
|
|
40973
|
-
*
|
|
40974
|
-
|
|
40693
|
+
* @param callback The function to call when the event was fired
|
|
40694
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
40695
|
+
*
|
|
40696
|
+
* @category Post Events
|
|
40697
|
+
*/
|
|
40698
|
+
const onLocalPostReactionAdded = (callback) => {
|
|
40975
40699
|
const client = getActiveClient();
|
|
40976
|
-
|
|
40977
|
-
|
|
40978
|
-
|
|
40979
|
-
|
|
40980
|
-
|
|
40981
|
-
|
|
40982
|
-
|
|
40700
|
+
const filter = ({ post }) => {
|
|
40701
|
+
if (!client.cache) {
|
|
40702
|
+
callback(post);
|
|
40703
|
+
}
|
|
40704
|
+
else {
|
|
40705
|
+
upsertInCache(['post', 'get', post.postId], post);
|
|
40706
|
+
callback(post);
|
|
40707
|
+
}
|
|
40708
|
+
};
|
|
40709
|
+
return createEventSubscriber(client, 'local.post.addReaction', 'local.post.addReaction', filter);
|
|
40983
40710
|
};
|
|
40984
|
-
/* end_public_function */
|
|
40985
40711
|
|
|
40986
|
-
/* begin_public_function
|
|
40987
|
-
id: post.check_flag_by_me
|
|
40988
|
-
*/
|
|
40989
40712
|
/**
|
|
40990
40713
|
* ```js
|
|
40991
|
-
* import {
|
|
40992
|
-
* const
|
|
40714
|
+
* import { onLocalPostReactionRemoved } from '@amityco/ts-sdk'
|
|
40715
|
+
* const dispose = onPostReactionRemoved(post => {
|
|
40716
|
+
* // ...
|
|
40717
|
+
* })
|
|
40993
40718
|
* ```
|
|
40994
40719
|
*
|
|
40995
|
-
*
|
|
40996
|
-
* @returns `true` if the post is flagged by me, `false` if doesn't.
|
|
40720
|
+
* Fired when a {@link Amity.InternalPost} has been reacted
|
|
40997
40721
|
*
|
|
40998
|
-
* @
|
|
40999
|
-
* @
|
|
41000
|
-
*
|
|
41001
|
-
|
|
40722
|
+
* @param callback The function to call when the event was fired
|
|
40723
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
40724
|
+
*
|
|
40725
|
+
* @category Post Events
|
|
40726
|
+
*/
|
|
40727
|
+
const onLocalPostReactionRemoved = (callback) => {
|
|
41002
40728
|
const client = getActiveClient();
|
|
41003
|
-
|
|
41004
|
-
|
|
41005
|
-
|
|
40729
|
+
const filter = ({ post }) => {
|
|
40730
|
+
if (!client.cache) {
|
|
40731
|
+
callback(post);
|
|
40732
|
+
}
|
|
40733
|
+
else {
|
|
40734
|
+
upsertInCache(['post', 'get', post.postId], post);
|
|
40735
|
+
callback(post);
|
|
40736
|
+
}
|
|
40737
|
+
};
|
|
40738
|
+
return createEventSubscriber(client, 'local.post.removeReaction', 'local.post.removeReaction', filter);
|
|
41006
40739
|
};
|
|
41007
|
-
/* end_public_function */
|
|
41008
40740
|
|
|
41009
|
-
/* begin_public_function
|
|
41010
|
-
id: post.create.clip_post
|
|
41011
|
-
*/
|
|
41012
40741
|
/**
|
|
41013
40742
|
* ```js
|
|
41014
|
-
* import {
|
|
41015
|
-
* const
|
|
41016
|
-
*
|
|
41017
|
-
*
|
|
41018
|
-
* dataType: 'clip',
|
|
41019
|
-
* data: { text: 'hello world' },
|
|
41020
|
-
* attachments: [{ type: 'clip', fileId: 'fileId123', displayMode: 'fill', isMuted: false }]
|
|
41021
|
-
* }))
|
|
40743
|
+
* import { onLocalPostDeleted } from '@amityco/ts-sdk'
|
|
40744
|
+
* const dispose = onLocalPostDeleted(post => {
|
|
40745
|
+
* // ...
|
|
40746
|
+
* })
|
|
41022
40747
|
* ```
|
|
41023
40748
|
*
|
|
41024
|
-
*
|
|
40749
|
+
* Fired when a {@link Amity.InternalPost} has been deleted
|
|
41025
40750
|
*
|
|
41026
|
-
* @param
|
|
41027
|
-
* @returns
|
|
40751
|
+
* @param callback The function to call when the event was fired
|
|
40752
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
41028
40753
|
*
|
|
41029
|
-
* @category Post
|
|
41030
|
-
* @async
|
|
40754
|
+
* @category Post Events
|
|
41031
40755
|
*/
|
|
41032
|
-
const
|
|
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 */
|
|
40756
|
+
const onLocalPostDeleted = (callback) => createLocalPostEventSubscriber('local.post.deleted', callback);
|
|
41048
40757
|
|
|
41049
40758
|
/* begin_public_function
|
|
41050
40759
|
id: post.get
|
|
@@ -41068,7 +40777,7 @@ const createClipPost = async (bundle) => {
|
|
|
41068
40777
|
*
|
|
41069
40778
|
* @category Post Live Object
|
|
41070
40779
|
*/
|
|
41071
|
-
const getPost = (postId, callback) => {
|
|
40780
|
+
const getPost$1 = (postId, callback) => {
|
|
41072
40781
|
const responder = (snapshot) => {
|
|
41073
40782
|
const { data } = snapshot;
|
|
41074
40783
|
callback(Object.assign(Object.assign({}, snapshot), { data: data ? LinkedObject.post(snapshot.data) : data }));
|
|
@@ -41157,6 +40866,19 @@ class PostPaginationController extends PaginationController {
|
|
|
41157
40866
|
}
|
|
41158
40867
|
}
|
|
41159
40868
|
|
|
40869
|
+
var EnumPostActions;
|
|
40870
|
+
(function (EnumPostActions) {
|
|
40871
|
+
EnumPostActions["OnPostCreated"] = "onPostCreated";
|
|
40872
|
+
EnumPostActions["OnPostUpdated"] = "onPostUpdated";
|
|
40873
|
+
EnumPostActions["OnPostDeleted"] = "onPostDeleted";
|
|
40874
|
+
EnumPostActions["OnPostFlagged"] = "onPostFlagged";
|
|
40875
|
+
EnumPostActions["OnPostUnflagged"] = "onPostUnflagged";
|
|
40876
|
+
EnumPostActions["OnPostReactionAdded"] = "onPostReactionAdded";
|
|
40877
|
+
EnumPostActions["OnPostReactionRemoved"] = "onPostReactionRemoved";
|
|
40878
|
+
EnumPostActions["OnPostApproved"] = "onPostApproved";
|
|
40879
|
+
EnumPostActions["OnPostDeclined"] = "onPostDeclined";
|
|
40880
|
+
})(EnumPostActions || (EnumPostActions = {}));
|
|
40881
|
+
|
|
41160
40882
|
class PostQueryStreamController extends QueryStreamController {
|
|
41161
40883
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
41162
40884
|
super(query, cacheKey);
|
|
@@ -41222,6 +40944,47 @@ class PostQueryStreamController extends QueryStreamController {
|
|
|
41222
40944
|
}
|
|
41223
40945
|
}
|
|
41224
40946
|
|
|
40947
|
+
const getPost = async (postId) => {
|
|
40948
|
+
const client = getActiveClient();
|
|
40949
|
+
client.log('post/getPost', postId);
|
|
40950
|
+
isInTombstone('post', postId);
|
|
40951
|
+
let payload;
|
|
40952
|
+
try {
|
|
40953
|
+
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
40954
|
+
const response = await client.http.get(`/api/v3/posts/${encodeURIComponent(postId)}`);
|
|
40955
|
+
payload = response.data;
|
|
40956
|
+
}
|
|
40957
|
+
catch (error) {
|
|
40958
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
40959
|
+
pushToTombstone('post', postId);
|
|
40960
|
+
}
|
|
40961
|
+
throw error;
|
|
40962
|
+
}
|
|
40963
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
40964
|
+
const cachedAt = client.cache && Date.now();
|
|
40965
|
+
if (client.cache)
|
|
40966
|
+
ingestInCache(data, { cachedAt });
|
|
40967
|
+
const { posts } = data;
|
|
40968
|
+
const result = posts.find(post => post.postId === postId);
|
|
40969
|
+
return {
|
|
40970
|
+
data: result,
|
|
40971
|
+
cachedAt,
|
|
40972
|
+
};
|
|
40973
|
+
};
|
|
40974
|
+
getPost.locally = (postId) => {
|
|
40975
|
+
const client = getActiveClient();
|
|
40976
|
+
client.log('post/getPost.locally', postId);
|
|
40977
|
+
if (!client.cache)
|
|
40978
|
+
return;
|
|
40979
|
+
const cached = pullFromCache(['post', 'get', postId]);
|
|
40980
|
+
if (!cached)
|
|
40981
|
+
return;
|
|
40982
|
+
return {
|
|
40983
|
+
data: cached.data,
|
|
40984
|
+
cachedAt: cached.cachedAt,
|
|
40985
|
+
};
|
|
40986
|
+
};
|
|
40987
|
+
|
|
41225
40988
|
class PostLiveCollectionController extends LiveCollectionController {
|
|
41226
40989
|
constructor(query, callback) {
|
|
41227
40990
|
const queryStreamId = hash(query);
|
|
@@ -41271,7 +41034,7 @@ class PostLiveCollectionController extends LiveCollectionController {
|
|
|
41271
41034
|
const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
41272
41035
|
if (!currentCollection || currentCollection.data.includes(comment.referenceId))
|
|
41273
41036
|
return;
|
|
41274
|
-
await getPost
|
|
41037
|
+
await getPost(comment.referenceId);
|
|
41275
41038
|
callback(comment);
|
|
41276
41039
|
});
|
|
41277
41040
|
}, 'referenceId', 'post'),
|
|
@@ -41284,7 +41047,7 @@ class PostLiveCollectionController extends LiveCollectionController {
|
|
|
41284
41047
|
const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
41285
41048
|
if (!currentCollection || currentCollection.data.includes(comment.referenceId))
|
|
41286
41049
|
return;
|
|
41287
|
-
await getPost
|
|
41050
|
+
await getPost(comment.referenceId);
|
|
41288
41051
|
callback(comment);
|
|
41289
41052
|
});
|
|
41290
41053
|
}, 'referenceId', 'post'),
|
|
@@ -41887,6 +41650,238 @@ const semanticSearchPosts = (params, callback, config) => {
|
|
|
41887
41650
|
};
|
|
41888
41651
|
};
|
|
41889
41652
|
|
|
41653
|
+
class SearchPostPaginationController extends PaginationController {
|
|
41654
|
+
async getRequest(queryParams, token) {
|
|
41655
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, matchingOnlyParentPost, hashtags, dataTypes, targetType = 'all' } = queryParams, params = __rest(queryParams, ["limit", "matchingOnlyParentPost", "hashtags", "dataTypes", "targetType"]);
|
|
41656
|
+
const baseOptions = {
|
|
41657
|
+
type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
|
|
41658
|
+
};
|
|
41659
|
+
const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
|
|
41660
|
+
const { data: queryResponse } = await this.http.get(`/api/v1/search/posts`, {
|
|
41661
|
+
params: Object.assign(Object.assign({}, params), { hashtags,
|
|
41662
|
+
dataTypes,
|
|
41663
|
+
targetType,
|
|
41664
|
+
/*
|
|
41665
|
+
* when creating post like image, file, video BE will create 2 posts
|
|
41666
|
+
* 1. parent post to store text with dataType=text
|
|
41667
|
+
* 2. child post to store dataTypes post data
|
|
41668
|
+
*
|
|
41669
|
+
* By default, BE queries only parent post
|
|
41670
|
+
*/
|
|
41671
|
+
matchingOnlyParentPost: matchingOnlyParentPost !== null && matchingOnlyParentPost !== void 0 ? matchingOnlyParentPost : !(dataTypes === null || dataTypes === void 0 ? void 0 : dataTypes.length), options }),
|
|
41672
|
+
});
|
|
41673
|
+
return queryResponse;
|
|
41674
|
+
}
|
|
41675
|
+
}
|
|
41676
|
+
|
|
41677
|
+
class SearchPostQueryStreamController extends QueryStreamController {
|
|
41678
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
41679
|
+
super(query, cacheKey);
|
|
41680
|
+
this.notifyChange = notifyChange;
|
|
41681
|
+
this.preparePayload = preparePayload;
|
|
41682
|
+
}
|
|
41683
|
+
async saveToMainDB(response) {
|
|
41684
|
+
const processedPayload = await this.preparePayload(response);
|
|
41685
|
+
const client = getActiveClient();
|
|
41686
|
+
const cachedAt = client.cache && Date.now();
|
|
41687
|
+
if (client.cache) {
|
|
41688
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
41689
|
+
}
|
|
41690
|
+
}
|
|
41691
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
41692
|
+
var _a, _b;
|
|
41693
|
+
if (refresh) {
|
|
41694
|
+
pushToCache(this.cacheKey, {
|
|
41695
|
+
data: response.posts.map(getResolver('post')),
|
|
41696
|
+
});
|
|
41697
|
+
}
|
|
41698
|
+
else {
|
|
41699
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
41700
|
+
const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
41701
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
|
|
41702
|
+
}
|
|
41703
|
+
}
|
|
41704
|
+
reactor(action) {
|
|
41705
|
+
return (post) => {
|
|
41706
|
+
var _a, _b;
|
|
41707
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
41708
|
+
if (!collection)
|
|
41709
|
+
return;
|
|
41710
|
+
if (post.parentPostId && post.isDeleted) {
|
|
41711
|
+
const parentPost = (_b = pullFromCache([
|
|
41712
|
+
'post',
|
|
41713
|
+
'get',
|
|
41714
|
+
post.parentPostId,
|
|
41715
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
41716
|
+
if (!parentPost)
|
|
41717
|
+
return;
|
|
41718
|
+
parentPost.children = parentPost.children.filter(childId => childId !== post.postId);
|
|
41719
|
+
pushToCache(['post', 'get', parentPost.postId], parentPost);
|
|
41720
|
+
}
|
|
41721
|
+
if (action === EnumPostActions.OnPostDeclined) {
|
|
41722
|
+
collection.data = collection.data.filter(postId => postId !== post.postId);
|
|
41723
|
+
}
|
|
41724
|
+
if (action === EnumPostActions.OnPostCreated || action === EnumPostActions.OnPostApproved) {
|
|
41725
|
+
collection.data = [...new Set([post.postId, ...collection.data])];
|
|
41726
|
+
}
|
|
41727
|
+
pushToCache(this.cacheKey, collection);
|
|
41728
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
41729
|
+
};
|
|
41730
|
+
}
|
|
41731
|
+
subscribeRTE(createSubscriber) {
|
|
41732
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
41733
|
+
}
|
|
41734
|
+
}
|
|
41735
|
+
|
|
41736
|
+
class SearchPostLiveCollectionController extends LiveCollectionController {
|
|
41737
|
+
constructor(query, callback) {
|
|
41738
|
+
const queryStreamId = hash(query);
|
|
41739
|
+
const cacheKey = ['posts', 'collection', queryStreamId];
|
|
41740
|
+
const paginationController = new SearchPostPaginationController(query);
|
|
41741
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
41742
|
+
this.query = query;
|
|
41743
|
+
this.queryStreamController = new SearchPostQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
|
|
41744
|
+
this.callback = callback.bind(this);
|
|
41745
|
+
this.loadPage({ initial: true });
|
|
41746
|
+
}
|
|
41747
|
+
setup() {
|
|
41748
|
+
var _a;
|
|
41749
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
41750
|
+
if (!collection) {
|
|
41751
|
+
pushToCache(this.cacheKey, {
|
|
41752
|
+
data: [],
|
|
41753
|
+
params: {},
|
|
41754
|
+
});
|
|
41755
|
+
}
|
|
41756
|
+
}
|
|
41757
|
+
async persistModel(queryPayload) {
|
|
41758
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
41759
|
+
}
|
|
41760
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
41761
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
41762
|
+
}
|
|
41763
|
+
startSubscription() {
|
|
41764
|
+
return this.queryStreamController.subscribeRTE([
|
|
41765
|
+
{ fn: onPostCreated, action: EnumPostActions.OnPostCreated },
|
|
41766
|
+
{ fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
|
|
41767
|
+
{ fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
|
|
41768
|
+
{ fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
|
|
41769
|
+
{ fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
|
|
41770
|
+
{ fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
|
|
41771
|
+
{ fn: onPostApproved, action: EnumPostActions.OnPostApproved },
|
|
41772
|
+
{ fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
|
|
41773
|
+
{ fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
|
|
41774
|
+
{ fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
|
|
41775
|
+
{ fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
|
|
41776
|
+
{ fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
|
|
41777
|
+
{ fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
|
|
41778
|
+
{
|
|
41779
|
+
fn: convertEventPayload((callback) => {
|
|
41780
|
+
return onCommentCreated(async (comment) => {
|
|
41781
|
+
var _a;
|
|
41782
|
+
const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
41783
|
+
if (!currentCollection || currentCollection.data.includes(comment.referenceId))
|
|
41784
|
+
return;
|
|
41785
|
+
await getPost(comment.referenceId);
|
|
41786
|
+
callback(comment);
|
|
41787
|
+
});
|
|
41788
|
+
}, 'referenceId', 'post'),
|
|
41789
|
+
action: EnumPostActions.OnPostUpdated,
|
|
41790
|
+
},
|
|
41791
|
+
{
|
|
41792
|
+
fn: convertEventPayload((callback) => {
|
|
41793
|
+
return onCommentDeleted(async (comment) => {
|
|
41794
|
+
var _a;
|
|
41795
|
+
const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
41796
|
+
if (!currentCollection || currentCollection.data.includes(comment.referenceId))
|
|
41797
|
+
return;
|
|
41798
|
+
await getPost(comment.referenceId);
|
|
41799
|
+
callback(comment);
|
|
41800
|
+
});
|
|
41801
|
+
}, 'referenceId', 'post'),
|
|
41802
|
+
action: EnumPostActions.OnPostUpdated,
|
|
41803
|
+
},
|
|
41804
|
+
]);
|
|
41805
|
+
}
|
|
41806
|
+
notifyChange({ origin, loading, error }) {
|
|
41807
|
+
var _a, _b;
|
|
41808
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
41809
|
+
if (!collection)
|
|
41810
|
+
return;
|
|
41811
|
+
const data = this.applyFilter((_b = collection.data
|
|
41812
|
+
.map(id => pullFromCache(['post', 'get', id]))
|
|
41813
|
+
.filter(isNonNullable)
|
|
41814
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
|
|
41815
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
41816
|
+
return;
|
|
41817
|
+
this.callback({
|
|
41818
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
41819
|
+
data,
|
|
41820
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
41821
|
+
loading,
|
|
41822
|
+
error,
|
|
41823
|
+
});
|
|
41824
|
+
}
|
|
41825
|
+
applyFilter(data) {
|
|
41826
|
+
var _a;
|
|
41827
|
+
let posts = data;
|
|
41828
|
+
if ((_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.length) {
|
|
41829
|
+
posts = filterByPostDataTypes(posts, this.query.dataTypes);
|
|
41830
|
+
}
|
|
41831
|
+
switch (this.query.sortBy) {
|
|
41832
|
+
case 'firstCreated':
|
|
41833
|
+
posts = posts.sort(sortByFirstCreated);
|
|
41834
|
+
break;
|
|
41835
|
+
case 'lastCreated':
|
|
41836
|
+
default:
|
|
41837
|
+
posts = posts.sort(sortByLastCreated);
|
|
41838
|
+
break;
|
|
41839
|
+
}
|
|
41840
|
+
return posts;
|
|
41841
|
+
}
|
|
41842
|
+
}
|
|
41843
|
+
|
|
41844
|
+
/* begin_public_function
|
|
41845
|
+
id: post.query
|
|
41846
|
+
*/
|
|
41847
|
+
/**
|
|
41848
|
+
* ```js
|
|
41849
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
41850
|
+
*
|
|
41851
|
+
* let posts = []
|
|
41852
|
+
* const unsub = PostRepository.searchPostsByHashtag({
|
|
41853
|
+
* hashtags: ['amity'],
|
|
41854
|
+
* limit: 10,
|
|
41855
|
+
* }, response => merge(posts, response.data))
|
|
41856
|
+
* ```
|
|
41857
|
+
*
|
|
41858
|
+
* Observe all mutations on a list of {@link Amity.Post} for a given target object
|
|
41859
|
+
*
|
|
41860
|
+
* @param params.hashtags the hashtags to search for
|
|
41861
|
+
* @param callback the function to call when new data are available
|
|
41862
|
+
* @param config
|
|
41863
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
41864
|
+
*
|
|
41865
|
+
* @category Posts Live Collection
|
|
41866
|
+
*/
|
|
41867
|
+
const searchPostsByHashtag = (params, callback, config) => {
|
|
41868
|
+
const { log, cache } = getActiveClient();
|
|
41869
|
+
if (!cache) {
|
|
41870
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
41871
|
+
}
|
|
41872
|
+
const timestamp = Date.now();
|
|
41873
|
+
log(`searchPostsByHashtag(tmpid: ${timestamp}) > listen`);
|
|
41874
|
+
const postsLiveCollection = new SearchPostLiveCollectionController(params, callback);
|
|
41875
|
+
const disposers = postsLiveCollection.startSubscription();
|
|
41876
|
+
const cacheKey = postsLiveCollection.getCacheKey();
|
|
41877
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
41878
|
+
return () => {
|
|
41879
|
+
log(`searchPostsByHashtag(tmpid: ${timestamp}) > dispose`);
|
|
41880
|
+
disposers.forEach(fn => fn());
|
|
41881
|
+
};
|
|
41882
|
+
};
|
|
41883
|
+
/* end_public_function */
|
|
41884
|
+
|
|
41890
41885
|
var index$8 = /*#__PURE__*/Object.freeze({
|
|
41891
41886
|
__proto__: null,
|
|
41892
41887
|
getPostByIds: getPostByIds,
|
|
@@ -41910,11 +41905,12 @@ var index$8 = /*#__PURE__*/Object.freeze({
|
|
|
41910
41905
|
onPostUnflagged: onPostUnflagged,
|
|
41911
41906
|
onPostReactionAdded: onPostReactionAdded,
|
|
41912
41907
|
onPostReactionRemoved: onPostReactionRemoved,
|
|
41913
|
-
getPost: getPost,
|
|
41908
|
+
getPost: getPost$1,
|
|
41914
41909
|
getPosts: getPosts,
|
|
41915
41910
|
getPinnedPosts: getPinnedPosts,
|
|
41916
41911
|
getGlobalPinnedPosts: getGlobalPinnedPosts,
|
|
41917
|
-
semanticSearchPosts: semanticSearchPosts
|
|
41912
|
+
semanticSearchPosts: semanticSearchPosts,
|
|
41913
|
+
searchPostsByHashtag: searchPostsByHashtag
|
|
41918
41914
|
});
|
|
41919
41915
|
|
|
41920
41916
|
/* begin_public_function
|
|
@@ -45111,4 +45107,4 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
45111
45107
|
getReactions: getReactions
|
|
45112
45108
|
});
|
|
45113
45109
|
|
|
45114
|
-
export { API_REGIONS, index$3 as AdRepository, index$b as CategoryRepository, index$f as ChannelRepository, index$o as Client, index$
|
|
45110
|
+
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 };
|