@amityco/ts-sdk 7.8.1-5d16a58a.0 → 7.8.1-fffd2ec.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/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/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/feedRepository/index.d.ts +0 -1
- package/dist/feedRepository/index.d.ts.map +1 -1
- package/dist/index.cjs.js +1092 -1329
- package/dist/index.esm.js +1091 -1328
- package/dist/index.umd.js +1 -1
- package/package.json +1 -1
- package/src/@types/domains/feed.ts +0 -43
- package/src/feedRepository/index.ts +0 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/LiveCollectionController.d.ts +0 -14
- 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 +0 -129
- 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 +0 -15
- 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 +0 -78
- 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 +0 -14
- 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 +0 -15
- 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/LiveCollectionController.ts +0 -192
- package/src/feedRepository/observers/getUserFeed/PaginationController.ts +0 -37
- package/src/feedRepository/observers/getUserFeed/QueryStreamController.ts +0 -119
- package/src/feedRepository/observers/getUserFeed.ts +0 -56
- package/src/feedRepository/observers/index.ts +0 -1
package/dist/index.esm.js
CHANGED
|
@@ -39267,1035 +39267,1010 @@ getCustomRankingGlobalFeed.locally = (query) => {
|
|
|
39267
39267
|
: undefined;
|
|
39268
39268
|
};
|
|
39269
39269
|
|
|
39270
|
-
|
|
39271
|
-
|
|
39272
|
-
|
|
39273
|
-
|
|
39274
|
-
|
|
39275
|
-
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) }),
|
|
39276
|
-
});
|
|
39277
|
-
return queryResponse;
|
|
39278
|
-
}
|
|
39279
|
-
}
|
|
39280
|
-
|
|
39281
|
-
var EnumPostActions;
|
|
39282
|
-
(function (EnumPostActions) {
|
|
39283
|
-
EnumPostActions["OnPostCreated"] = "onPostCreated";
|
|
39284
|
-
EnumPostActions["OnPostUpdated"] = "onPostUpdated";
|
|
39285
|
-
EnumPostActions["OnPostDeleted"] = "onPostDeleted";
|
|
39286
|
-
EnumPostActions["OnPostFlagged"] = "onPostFlagged";
|
|
39287
|
-
EnumPostActions["OnPostUnflagged"] = "onPostUnflagged";
|
|
39288
|
-
EnumPostActions["OnPostReactionAdded"] = "onPostReactionAdded";
|
|
39289
|
-
EnumPostActions["OnPostReactionRemoved"] = "onPostReactionRemoved";
|
|
39290
|
-
EnumPostActions["OnPostApproved"] = "onPostApproved";
|
|
39291
|
-
EnumPostActions["OnPostDeclined"] = "onPostDeclined";
|
|
39292
|
-
})(EnumPostActions || (EnumPostActions = {}));
|
|
39293
|
-
|
|
39294
|
-
class UserFeedQueryStreamController extends QueryStreamController {
|
|
39295
|
-
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
39296
|
-
super(query, cacheKey);
|
|
39297
|
-
this.notifyChange = notifyChange;
|
|
39298
|
-
this.preparePayload = preparePayload;
|
|
39299
|
-
}
|
|
39300
|
-
async saveToMainDB(response) {
|
|
39301
|
-
const processedPayload = await this.preparePayload(response);
|
|
39302
|
-
const client = getActiveClient();
|
|
39303
|
-
const cachedAt = client.cache && Date.now();
|
|
39304
|
-
if (client.cache) {
|
|
39305
|
-
ingestInCache(processedPayload, { cachedAt });
|
|
39306
|
-
}
|
|
39307
|
-
}
|
|
39308
|
-
appendToQueryStream(response, direction, refresh = false) {
|
|
39309
|
-
var _a, _b;
|
|
39310
|
-
if (refresh) {
|
|
39311
|
-
pushToCache(this.cacheKey, {
|
|
39312
|
-
data: response.posts.map(getResolver('post')),
|
|
39313
|
-
});
|
|
39314
|
-
}
|
|
39315
|
-
else {
|
|
39316
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
39317
|
-
const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
39318
|
-
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
|
|
39319
|
-
}
|
|
39320
|
-
}
|
|
39321
|
-
reactor(action) {
|
|
39322
|
-
return (post) => {
|
|
39323
|
-
var _a, _b;
|
|
39324
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
39325
|
-
if (!collection)
|
|
39326
|
-
return;
|
|
39327
|
-
// if the collection is parent post collection and
|
|
39328
|
-
// post is not included in the collection or post is child post
|
|
39329
|
-
if ((!this.query.dataTypes || this.query.dataTypes.length === 0) &&
|
|
39330
|
-
!collection.data.includes(post.parentPostId ? post.parentPostId : post.postId))
|
|
39331
|
-
return;
|
|
39332
|
-
if (action === EnumPostActions.OnPostDeleted) {
|
|
39333
|
-
collection.data = collection.data.filter(postId => postId !== post.postId);
|
|
39334
|
-
}
|
|
39335
|
-
if (post.parentPostId && post.isDeleted) {
|
|
39336
|
-
const parentPost = (_b = pullFromCache([
|
|
39337
|
-
'post',
|
|
39338
|
-
'get',
|
|
39339
|
-
post.parentPostId,
|
|
39340
|
-
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
39341
|
-
if (!parentPost)
|
|
39342
|
-
return;
|
|
39343
|
-
parentPost.children = parentPost.children.filter(childId => childId !== post.postId);
|
|
39344
|
-
pushToCache(['post', 'get', parentPost.postId], parentPost);
|
|
39345
|
-
}
|
|
39346
|
-
if (action === EnumPostActions.OnPostDeclined) {
|
|
39347
|
-
collection.data = collection.data.filter(postId => postId !== post.postId);
|
|
39348
|
-
}
|
|
39349
|
-
if (action === EnumPostActions.OnPostCreated || action === EnumPostActions.OnPostApproved) {
|
|
39350
|
-
if (this.query.dataTypes &&
|
|
39351
|
-
this.query.dataTypes.length > 0 &&
|
|
39352
|
-
!this.query.dataTypes.includes(post.dataType)) {
|
|
39353
|
-
return;
|
|
39354
|
-
}
|
|
39355
|
-
collection.data = [...new Set([post.postId, ...collection.data])];
|
|
39356
|
-
}
|
|
39357
|
-
pushToCache(this.cacheKey, collection);
|
|
39358
|
-
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
39359
|
-
};
|
|
39360
|
-
}
|
|
39361
|
-
subscribeRTE(createSubscriber) {
|
|
39362
|
-
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
39363
|
-
}
|
|
39364
|
-
}
|
|
39270
|
+
var index$a = /*#__PURE__*/Object.freeze({
|
|
39271
|
+
__proto__: null,
|
|
39272
|
+
queryGlobalFeed: queryGlobalFeed,
|
|
39273
|
+
getCustomRankingGlobalFeed: getCustomRankingGlobalFeed
|
|
39274
|
+
});
|
|
39365
39275
|
|
|
39366
39276
|
/* begin_public_function
|
|
39367
|
-
id:
|
|
39277
|
+
id: post.get_by_ids
|
|
39368
39278
|
*/
|
|
39369
39279
|
/**
|
|
39370
39280
|
* ```js
|
|
39371
|
-
* import {
|
|
39372
|
-
* const
|
|
39281
|
+
* import { getPostByIds } from '@amityco/ts-sdk'
|
|
39282
|
+
* const { data: posts } = await getPostByIds(['foo', 'bar'])
|
|
39373
39283
|
* ```
|
|
39374
39284
|
*
|
|
39375
|
-
* Fetches a collection of {@link Amity.
|
|
39285
|
+
* Fetches a collection of {@link Amity.Post} objects
|
|
39376
39286
|
*
|
|
39377
|
-
* @param
|
|
39378
|
-
* @returns the associated collection of {@link Amity.
|
|
39287
|
+
* @param postIds the IDs of the {@link Amity.Post} to fetch
|
|
39288
|
+
* @returns the associated collection of {@link Amity.Post} objects
|
|
39379
39289
|
*
|
|
39380
|
-
* @category
|
|
39290
|
+
* @category Post API
|
|
39381
39291
|
* @async
|
|
39382
39292
|
*/
|
|
39383
|
-
const
|
|
39293
|
+
const getPostByIds = async (postIds) => {
|
|
39384
39294
|
const client = getActiveClient();
|
|
39385
|
-
client.log('
|
|
39386
|
-
const
|
|
39387
|
-
let
|
|
39295
|
+
client.log('post/getPostByIds', postIds);
|
|
39296
|
+
const encodedPostIds = postIds.map(postId => encodeURIComponent(postId));
|
|
39297
|
+
let payload;
|
|
39388
39298
|
try {
|
|
39389
39299
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
39390
|
-
const response = await client.http.get(`/api/v3/
|
|
39391
|
-
params: {
|
|
39300
|
+
const response = await client.http.get(`/api/v3/posts/list`, {
|
|
39301
|
+
params: { postIds: encodedPostIds },
|
|
39392
39302
|
});
|
|
39393
|
-
|
|
39303
|
+
payload = response.data;
|
|
39394
39304
|
}
|
|
39395
39305
|
catch (error) {
|
|
39396
|
-
|
|
39306
|
+
postIds.forEach(postId => {
|
|
39397
39307
|
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
39398
|
-
pushToTombstone('
|
|
39308
|
+
pushToTombstone('post', postId);
|
|
39399
39309
|
}
|
|
39400
39310
|
});
|
|
39401
39311
|
throw error;
|
|
39402
39312
|
}
|
|
39313
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
39403
39314
|
const cachedAt = client.cache && Date.now();
|
|
39404
39315
|
if (client.cache)
|
|
39405
39316
|
ingestInCache(data, { cachedAt });
|
|
39406
39317
|
return {
|
|
39407
|
-
data: data.
|
|
39318
|
+
data: data.posts.map(LinkedObject.post),
|
|
39408
39319
|
cachedAt,
|
|
39409
39320
|
};
|
|
39410
39321
|
};
|
|
39411
39322
|
/* end_public_function */
|
|
39412
39323
|
/**
|
|
39413
39324
|
* ```js
|
|
39414
|
-
* import {
|
|
39415
|
-
* const
|
|
39325
|
+
* import { getPostByIds } from '@amityco/ts-sdk'
|
|
39326
|
+
* const { data: posts } = getPostByIds.locally(['foo', 'bar'])
|
|
39416
39327
|
* ```
|
|
39417
39328
|
*
|
|
39418
|
-
* Fetches a collection of {@link Amity.
|
|
39329
|
+
* Fetches a collection of {@link Amity.Post} objects from cache
|
|
39419
39330
|
*
|
|
39420
|
-
* @param
|
|
39421
|
-
* @returns the associated collection of {@link Amity.
|
|
39331
|
+
* @param postIds the IDs of the {@link Amity.Post} to fetch
|
|
39332
|
+
* @returns the associated collection of {@link Amity.Post} objects
|
|
39422
39333
|
*
|
|
39423
|
-
* @category
|
|
39334
|
+
* @category Post API
|
|
39424
39335
|
*/
|
|
39425
|
-
|
|
39336
|
+
getPostByIds.locally = (postIds) => {
|
|
39426
39337
|
var _a;
|
|
39427
39338
|
const client = getActiveClient();
|
|
39428
|
-
client.log('
|
|
39339
|
+
client.log('post/getPostByIds.locally', postIds);
|
|
39429
39340
|
if (!client.cache)
|
|
39430
39341
|
return;
|
|
39431
|
-
const cached =
|
|
39432
|
-
.map(
|
|
39342
|
+
const cached = postIds
|
|
39343
|
+
.map(postId => pullFromCache(['post', 'get', postId]))
|
|
39433
39344
|
.filter(Boolean);
|
|
39434
|
-
const
|
|
39345
|
+
const posts = cached.map(({ data }) => data);
|
|
39435
39346
|
const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
|
|
39436
|
-
if ((cached === null || cached === void 0 ? void 0 : cached.length) <
|
|
39347
|
+
if ((cached === null || cached === void 0 ? void 0 : cached.length) < postIds.length)
|
|
39437
39348
|
return;
|
|
39438
39349
|
return {
|
|
39439
|
-
data:
|
|
39350
|
+
data: posts.map(LinkedObject.post),
|
|
39440
39351
|
cachedAt: oldest.cachedAt,
|
|
39441
39352
|
};
|
|
39442
39353
|
};
|
|
39443
39354
|
|
|
39444
39355
|
/* begin_public_function
|
|
39445
|
-
id:
|
|
39356
|
+
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
|
|
39446
39357
|
*/
|
|
39447
39358
|
/**
|
|
39448
39359
|
* ```js
|
|
39449
|
-
* import {
|
|
39450
|
-
* const
|
|
39360
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
39361
|
+
* const created = await PostRepository.createPost({
|
|
39362
|
+
* targetType: 'user',
|
|
39363
|
+
* targetId: 'foobar',
|
|
39364
|
+
* data: { text: 'hello world' }
|
|
39365
|
+
* }))
|
|
39451
39366
|
* ```
|
|
39452
39367
|
*
|
|
39453
|
-
* Creates an {@link Amity.
|
|
39368
|
+
* Creates an {@link Amity.Post}
|
|
39454
39369
|
*
|
|
39455
|
-
* @param bundle The data necessary to create a new {@link Amity.
|
|
39456
|
-
* @returns The newly created {@link Amity.
|
|
39370
|
+
* @param bundle The data necessary to create a new {@link Amity.Post}
|
|
39371
|
+
* @returns The newly created {@link Amity.Post}
|
|
39457
39372
|
*
|
|
39458
|
-
* @category
|
|
39373
|
+
* @category Post API
|
|
39459
39374
|
* @async
|
|
39460
39375
|
*/
|
|
39461
|
-
const
|
|
39462
|
-
var _a;
|
|
39376
|
+
const createPost = async (bundle) => {
|
|
39463
39377
|
const client = getActiveClient();
|
|
39464
|
-
client.log('
|
|
39465
|
-
|
|
39466
|
-
|
|
39467
|
-
|
|
39468
|
-
|
|
39469
|
-
|
|
39378
|
+
client.log('post/createPost', bundle);
|
|
39379
|
+
if (!bundle.dataType || ['text', 'image', 'file', 'video'].includes(bundle.dataType)) {
|
|
39380
|
+
// eslint-disable-next-line no-param-reassign
|
|
39381
|
+
delete bundle.dataType;
|
|
39382
|
+
}
|
|
39383
|
+
const { data: payload } = await client.http.post('/api/v4/posts', bundle);
|
|
39384
|
+
fireEvent('post.created', payload);
|
|
39385
|
+
const data = preparePostPayload(payload);
|
|
39470
39386
|
const cachedAt = client.cache && Date.now();
|
|
39471
39387
|
if (client.cache)
|
|
39472
39388
|
ingestInCache(data, { cachedAt });
|
|
39473
|
-
|
|
39474
|
-
const post = (_a = pullFromCache(['post', 'get', bundle.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
39475
|
-
if (post) {
|
|
39476
|
-
post.commentsCount += 1;
|
|
39477
|
-
fireEvent('local.post.updated', {
|
|
39478
|
-
posts: [post],
|
|
39479
|
-
categories: [],
|
|
39480
|
-
comments: [],
|
|
39481
|
-
communities: [],
|
|
39482
|
-
communityUsers: data.communityUsers,
|
|
39483
|
-
feeds: [],
|
|
39484
|
-
files: data.files,
|
|
39485
|
-
postChildren: [],
|
|
39486
|
-
users: data.users,
|
|
39487
|
-
videoStreamings: [],
|
|
39488
|
-
});
|
|
39489
|
-
}
|
|
39490
|
-
}
|
|
39491
|
-
else if (bundle.referenceType === 'story') {
|
|
39492
|
-
const storyIndex = pullFromCache([
|
|
39493
|
-
"story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
|
|
39494
|
-
bundle.referenceId,
|
|
39495
|
-
]);
|
|
39496
|
-
if (storyIndex === null || storyIndex === void 0 ? void 0 : storyIndex.data) {
|
|
39497
|
-
const cacheStory = pullFromCache([
|
|
39498
|
-
"story" /* STORY_KEY_CACHE.STORY */,
|
|
39499
|
-
'get',
|
|
39500
|
-
storyIndex.data,
|
|
39501
|
-
]);
|
|
39502
|
-
if (cacheStory === null || cacheStory === void 0 ? void 0 : cacheStory.data) {
|
|
39503
|
-
fireEvent('story.updated', {
|
|
39504
|
-
stories: [
|
|
39505
|
-
Object.assign(Object.assign({}, cacheStory.data), { commentsCount: cacheStory.data.commentsCount + 1, comments: [...new Set([...cacheStory.data.comments, comments[0].commentId])] }),
|
|
39506
|
-
],
|
|
39507
|
-
categories: [],
|
|
39508
|
-
comments,
|
|
39509
|
-
communities: [],
|
|
39510
|
-
communityUsers: data.communityUsers,
|
|
39511
|
-
files: data.files,
|
|
39512
|
-
users: data.users,
|
|
39513
|
-
});
|
|
39514
|
-
}
|
|
39515
|
-
}
|
|
39516
|
-
}
|
|
39517
|
-
fireEvent('local.comment.created', data);
|
|
39389
|
+
const { posts } = data;
|
|
39518
39390
|
return {
|
|
39519
|
-
data: LinkedObject.
|
|
39391
|
+
data: LinkedObject.post(posts[0]),
|
|
39520
39392
|
cachedAt,
|
|
39521
39393
|
};
|
|
39522
39394
|
};
|
|
39523
39395
|
/* end_public_function */
|
|
39524
39396
|
|
|
39525
39397
|
/* begin_public_function
|
|
39526
|
-
id:
|
|
39398
|
+
id: post.edit, post.edit.custom_post
|
|
39527
39399
|
*/
|
|
39528
39400
|
/**
|
|
39529
39401
|
* ```js
|
|
39530
|
-
* import {
|
|
39531
|
-
* const updated = await
|
|
39402
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
39403
|
+
* const updated = await PostRepository.editPost(postId, {
|
|
39532
39404
|
* data: { text: 'hello world' }
|
|
39533
39405
|
* })
|
|
39534
39406
|
* ```
|
|
39535
39407
|
*
|
|
39536
|
-
* Updates an {@link Amity.
|
|
39408
|
+
* Updates an {@link Amity.Post}
|
|
39537
39409
|
*
|
|
39538
|
-
* @param
|
|
39410
|
+
* @param postId The ID of the {@link Amity.Post} to edit
|
|
39539
39411
|
* @param patch The patch data to apply
|
|
39540
|
-
* @returns the updated {@link Amity.
|
|
39412
|
+
* @returns the updated {@link Amity.Post} object
|
|
39541
39413
|
*
|
|
39542
|
-
* @category
|
|
39414
|
+
* @category Post API
|
|
39543
39415
|
* @async
|
|
39544
39416
|
*/
|
|
39545
|
-
const
|
|
39417
|
+
const editPost = async (postId, patch) => {
|
|
39546
39418
|
const client = getActiveClient();
|
|
39547
|
-
client.log('user/
|
|
39548
|
-
const { data } = await client.http.put(`/api/
|
|
39419
|
+
client.log('user/editPost', patch);
|
|
39420
|
+
const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, patch);
|
|
39421
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
39549
39422
|
const cachedAt = client.cache && Date.now();
|
|
39550
39423
|
if (client.cache)
|
|
39551
39424
|
ingestInCache(data, { cachedAt });
|
|
39552
|
-
fireEvent('
|
|
39553
|
-
const {
|
|
39425
|
+
fireEvent('local.post.updated', data);
|
|
39426
|
+
const { posts } = data;
|
|
39554
39427
|
return {
|
|
39555
|
-
data: LinkedObject.
|
|
39428
|
+
data: LinkedObject.post(posts.find(post => post.postId === postId)),
|
|
39556
39429
|
cachedAt,
|
|
39557
39430
|
};
|
|
39558
39431
|
};
|
|
39559
39432
|
/* end_public_function */
|
|
39560
39433
|
|
|
39561
|
-
// Due to we have optimistic logic, we will use referenceId as a id in SDK instead of storyId
|
|
39562
|
-
const applyMissingField = (rawData, isCreated = false) => {
|
|
39563
|
-
const { storyId, referenceId } = rawData;
|
|
39564
|
-
if (!isCreated) {
|
|
39565
|
-
if (referenceId)
|
|
39566
|
-
return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */ });
|
|
39567
|
-
}
|
|
39568
|
-
return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */, referenceId: storyId });
|
|
39569
|
-
};
|
|
39570
|
-
const convertRawStoryToInternal = (data, isCreated = false) => {
|
|
39571
|
-
const { stories } = data;
|
|
39572
|
-
const storiesData = stories.map(story => applyMissingField(story, isCreated));
|
|
39573
|
-
return Object.assign(Object.assign({}, data), { stories: storiesData });
|
|
39574
|
-
};
|
|
39575
|
-
|
|
39576
|
-
const getStoryByStoryId$1 = async (storyId) => {
|
|
39577
|
-
const client = getActiveClient();
|
|
39578
|
-
client.log('story/getStoryByStoryId', storyId);
|
|
39579
|
-
// Get story referenceId from cache
|
|
39580
|
-
const cacheReferenceId = pullFromCache([
|
|
39581
|
-
"story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
|
|
39582
|
-
storyId,
|
|
39583
|
-
]);
|
|
39584
|
-
if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
|
|
39585
|
-
const { data: referenceId } = cacheReferenceId;
|
|
39586
|
-
isInTombstone('story', referenceId);
|
|
39587
|
-
}
|
|
39588
|
-
let data;
|
|
39589
|
-
try {
|
|
39590
|
-
const response = await client.http.get(`/api/v4/stories/${storyId}`);
|
|
39591
|
-
data = convertRawStoryToInternal(response.data);
|
|
39592
|
-
}
|
|
39593
|
-
catch (error) {
|
|
39594
|
-
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
39595
|
-
pushToTombstone('story', storyId);
|
|
39596
|
-
}
|
|
39597
|
-
throw error;
|
|
39598
|
-
}
|
|
39599
|
-
const cachedAt = client.cache && Date.now();
|
|
39600
|
-
if (client.cache) {
|
|
39601
|
-
ingestInCache(data, { cachedAt });
|
|
39602
|
-
}
|
|
39603
|
-
return {
|
|
39604
|
-
data: data.stories[0],
|
|
39605
|
-
cachedAt,
|
|
39606
|
-
};
|
|
39607
|
-
};
|
|
39608
|
-
getStoryByStoryId$1.locally = (storyId) => {
|
|
39609
|
-
const client = getActiveClient();
|
|
39610
|
-
client.log('story/getStorybyStoryId', storyId);
|
|
39611
|
-
// Get story referenceId from cache
|
|
39612
|
-
const cacheReferenceId = pullFromCache([
|
|
39613
|
-
"story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
|
|
39614
|
-
storyId,
|
|
39615
|
-
]);
|
|
39616
|
-
if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
|
|
39617
|
-
const { data: referenceId } = cacheReferenceId;
|
|
39618
|
-
isInTombstone('story', referenceId);
|
|
39619
|
-
}
|
|
39620
|
-
const cachedAt = client.cache && Date.now();
|
|
39621
|
-
const storyCache = pullFromCache(['story', 'get', storyId]);
|
|
39622
|
-
if (!storyCache)
|
|
39623
|
-
return;
|
|
39624
|
-
return {
|
|
39625
|
-
data: storyCache.data,
|
|
39626
|
-
cachedAt,
|
|
39627
|
-
};
|
|
39628
|
-
};
|
|
39629
|
-
|
|
39630
|
-
/* begin_public_function
|
|
39631
|
-
id: comment.soft_delete, comment.hard_delete
|
|
39632
|
-
*/
|
|
39633
39434
|
/**
|
|
39634
39435
|
* ```js
|
|
39635
|
-
* import {
|
|
39636
|
-
* const success = await
|
|
39436
|
+
* import { deletePost } from '@amityco/ts-sdk'
|
|
39437
|
+
* const success = await deletePost('foobar')
|
|
39637
39438
|
* ```
|
|
39638
39439
|
*
|
|
39639
|
-
* Deletes a {@link Amity.
|
|
39440
|
+
* Deletes a {@link Amity.Post}
|
|
39640
39441
|
*
|
|
39641
|
-
* @param
|
|
39642
|
-
* @return A success boolean if the {@link Amity.
|
|
39442
|
+
* @param postId The {@link Amity.Post} ID to delete
|
|
39443
|
+
* @return A success boolean if the {@link Amity.Post} was deleted
|
|
39643
39444
|
*
|
|
39644
|
-
* @
|
|
39445
|
+
* @private
|
|
39645
39446
|
* @async
|
|
39646
39447
|
*/
|
|
39647
|
-
const
|
|
39448
|
+
const deletePost = async (postId, permanent = false) => {
|
|
39648
39449
|
var _a;
|
|
39649
39450
|
const client = getActiveClient();
|
|
39650
|
-
const
|
|
39651
|
-
|
|
39652
|
-
await client.http.delete(`/api/v4/comments/${encodeURIComponent(commentId)}`, {
|
|
39451
|
+
const post = await getPost$2(postId);
|
|
39452
|
+
await client.http.delete(`/api/v4/posts/${encodeURIComponent(postId)}`, {
|
|
39653
39453
|
params: {
|
|
39654
|
-
|
|
39454
|
+
postId,
|
|
39655
39455
|
permanent,
|
|
39656
39456
|
},
|
|
39657
39457
|
});
|
|
39658
|
-
// to
|
|
39659
|
-
|
|
39660
|
-
|
|
39661
|
-
|
|
39662
|
-
|
|
39663
|
-
|
|
39458
|
+
// there is currently a limitation which doesn't allow us to fire event to tell that community
|
|
39459
|
+
// has been updated. reason is that, when the object is deleted, we don't have its `communityId`
|
|
39460
|
+
// and so we cannot refetch the community or advertise on events. hopefully this should be solved
|
|
39461
|
+
// later when realtime events covers that for us.
|
|
39462
|
+
if (post.data.targetType === 'community') {
|
|
39463
|
+
const community = await getCommunity$1(post.data.targetId);
|
|
39464
|
+
const communityUsersCache = (_a = queryCache(['communityUsers', 'get'])) !== null && _a !== void 0 ? _a : [];
|
|
39465
|
+
const communityUsers = communityUsersCache
|
|
39466
|
+
.filter(({ key }) => {
|
|
39467
|
+
// cache key is ['communityUsers', 'get', `${communityId}#`${userId}`}]
|
|
39468
|
+
if (key[0] !== 'communityUsers')
|
|
39469
|
+
return false;
|
|
39470
|
+
if (key[1] !== 'get')
|
|
39471
|
+
return false;
|
|
39472
|
+
if (typeof key[2] === 'string')
|
|
39473
|
+
return key[2].includes(community.data.communityId);
|
|
39474
|
+
return false;
|
|
39475
|
+
})
|
|
39476
|
+
.map(({ data }) => data);
|
|
39477
|
+
fireEvent('community.updated', {
|
|
39478
|
+
communities: [community.data],
|
|
39664
39479
|
categories: [],
|
|
39665
|
-
|
|
39666
|
-
|
|
39667
|
-
communityUsers: [],
|
|
39480
|
+
communityUsers,
|
|
39481
|
+
feeds: [],
|
|
39668
39482
|
files: [],
|
|
39669
39483
|
users: [],
|
|
39670
39484
|
});
|
|
39671
39485
|
}
|
|
39486
|
+
// to support hard deletion
|
|
39487
|
+
const deleted = Object.assign(Object.assign({}, post.data), { isDeleted: true });
|
|
39488
|
+
if (permanent) {
|
|
39489
|
+
setTimeout(() => {
|
|
39490
|
+
pushToTombstone('post', postId);
|
|
39491
|
+
}, 0);
|
|
39492
|
+
}
|
|
39672
39493
|
else {
|
|
39673
|
-
|
|
39674
|
-
if (post) {
|
|
39675
|
-
let removeCount;
|
|
39676
|
-
if (!deleted.parentId) {
|
|
39677
|
-
// NOTE: delete the parent comment will remove all children comments
|
|
39678
|
-
removeCount = deleted.childrenNumber + 1;
|
|
39679
|
-
}
|
|
39680
|
-
else
|
|
39681
|
-
removeCount = 1;
|
|
39682
|
-
post.commentsCount -= removeCount;
|
|
39683
|
-
fireEvent('local.post.updated', {
|
|
39684
|
-
posts: [post],
|
|
39685
|
-
categories: [],
|
|
39686
|
-
comments: [],
|
|
39687
|
-
communities: [],
|
|
39688
|
-
communityUsers: [],
|
|
39689
|
-
feeds: [],
|
|
39690
|
-
files: [],
|
|
39691
|
-
postChildren: [],
|
|
39692
|
-
users: [],
|
|
39693
|
-
videoStreamings: [],
|
|
39694
|
-
});
|
|
39695
|
-
}
|
|
39494
|
+
upsertInCache(['post', 'get', postId], { isDeleted: true });
|
|
39696
39495
|
}
|
|
39697
|
-
fireEvent('local.
|
|
39698
|
-
|
|
39699
|
-
|
|
39496
|
+
fireEvent('local.post.deleted', {
|
|
39497
|
+
posts: [deleted],
|
|
39498
|
+
categories: [],
|
|
39499
|
+
comments: [],
|
|
39500
|
+
communities: [],
|
|
39501
|
+
communityUsers: [],
|
|
39502
|
+
feeds: [],
|
|
39700
39503
|
files: [],
|
|
39504
|
+
postChildren: [],
|
|
39701
39505
|
users: [],
|
|
39702
|
-
|
|
39506
|
+
videoStreamings: [],
|
|
39703
39507
|
});
|
|
39704
|
-
|
|
39705
|
-
scheduleTask(() => pushToTombstone('comment', commentId));
|
|
39706
|
-
}
|
|
39707
|
-
else {
|
|
39708
|
-
upsertInCache(['comment', 'get', commentId], { isDeleted: true });
|
|
39709
|
-
}
|
|
39710
|
-
return deleted;
|
|
39508
|
+
return LinkedObject.post(deleted);
|
|
39711
39509
|
};
|
|
39712
|
-
/* end_public_function */
|
|
39713
39510
|
|
|
39714
39511
|
/* begin_public_function
|
|
39715
|
-
id:
|
|
39512
|
+
id: post.soft_delete
|
|
39716
39513
|
*/
|
|
39717
39514
|
/**
|
|
39718
39515
|
* ```js
|
|
39719
|
-
* import {
|
|
39720
|
-
* const success = await
|
|
39516
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
39517
|
+
* const success = await PostRepository.softDeletePost('foobar')
|
|
39721
39518
|
* ```
|
|
39722
39519
|
*
|
|
39723
|
-
*
|
|
39520
|
+
* Soft deletes a {@link Amity.Post}
|
|
39724
39521
|
*
|
|
39725
|
-
* @param
|
|
39726
|
-
* @return A success boolean if the {@link Amity.
|
|
39522
|
+
* @param postId The {@link Amity.Post} ID to soft delete
|
|
39523
|
+
* @return A success boolean if the {@link Amity.Post} was deleted
|
|
39727
39524
|
*
|
|
39728
|
-
* @category
|
|
39525
|
+
* @category Post API
|
|
39729
39526
|
* @async
|
|
39730
39527
|
*/
|
|
39731
|
-
const
|
|
39528
|
+
const softDeletePost = async (postId) => {
|
|
39732
39529
|
const client = getActiveClient();
|
|
39733
|
-
client.log('
|
|
39734
|
-
const softDeleted =
|
|
39735
|
-
return softDeleted;
|
|
39530
|
+
client.log('post/softDeletePost', postId);
|
|
39531
|
+
const softDeleted = await deletePost(postId, false);
|
|
39532
|
+
return LinkedObject.post(softDeleted);
|
|
39736
39533
|
};
|
|
39737
39534
|
/* end_public_function */
|
|
39738
39535
|
|
|
39739
39536
|
/* begin_public_function
|
|
39740
|
-
id:
|
|
39537
|
+
id: post.hard_delete
|
|
39741
39538
|
*/
|
|
39742
39539
|
/**
|
|
39743
39540
|
* ```js
|
|
39744
|
-
* import {
|
|
39745
|
-
* const success = await
|
|
39541
|
+
* import { hardDeletePost } from '@amityco/ts-sdk'
|
|
39542
|
+
* const success = await hardDeletePost('foobar')
|
|
39746
39543
|
* ```
|
|
39747
39544
|
*
|
|
39748
|
-
*
|
|
39545
|
+
* Hard deletes a {@link Amity.Post}
|
|
39749
39546
|
*
|
|
39750
|
-
* @param
|
|
39751
|
-
* @return A success boolean if the {@link Amity.
|
|
39547
|
+
* @param postId The {@link Amity.Post} ID to be hard delete
|
|
39548
|
+
* @return A success boolean if the {@link Amity.Post} was deleted
|
|
39752
39549
|
*
|
|
39753
|
-
* @category
|
|
39550
|
+
* @category Post API
|
|
39754
39551
|
* @async
|
|
39755
39552
|
*/
|
|
39756
|
-
const
|
|
39553
|
+
const hardDeletePost = async (postId) => {
|
|
39757
39554
|
const client = getActiveClient();
|
|
39758
|
-
client.log('
|
|
39759
|
-
const hardDeleted =
|
|
39760
|
-
return hardDeleted;
|
|
39555
|
+
client.log('post/hardDeletePost', postId);
|
|
39556
|
+
const hardDeleted = await deletePost(postId, true);
|
|
39557
|
+
return LinkedObject.post(hardDeleted);
|
|
39761
39558
|
};
|
|
39762
39559
|
/* end_public_function */
|
|
39763
39560
|
|
|
39764
39561
|
/* begin_public_function
|
|
39765
|
-
id:
|
|
39562
|
+
id: post.approve
|
|
39766
39563
|
*/
|
|
39767
39564
|
/**
|
|
39768
39565
|
* ```js
|
|
39769
|
-
* import {
|
|
39770
|
-
*
|
|
39566
|
+
* import { approvePost } from '@amityco/ts-sdk'
|
|
39567
|
+
*
|
|
39568
|
+
* const { data: post } = await approvePost('postId')
|
|
39771
39569
|
* ```
|
|
39772
39570
|
*
|
|
39773
|
-
*
|
|
39774
|
-
* @param reason the reason to flag the comment
|
|
39775
|
-
* @returns the created report result
|
|
39571
|
+
* Approves a {@link Amity.Post}
|
|
39776
39572
|
*
|
|
39777
|
-
* @
|
|
39573
|
+
* @param postId The {@link Amity.Post} ID to be approved
|
|
39574
|
+
* @return A {@link Amity.Post} that was approved
|
|
39575
|
+
*
|
|
39576
|
+
* @category Post API
|
|
39778
39577
|
* @async
|
|
39779
|
-
|
|
39780
|
-
const
|
|
39578
|
+
*/
|
|
39579
|
+
const approvePost = async (postId) => {
|
|
39781
39580
|
const client = getActiveClient();
|
|
39782
|
-
client.log('
|
|
39783
|
-
const
|
|
39784
|
-
|
|
39785
|
-
|
|
39786
|
-
|
|
39787
|
-
|
|
39788
|
-
}
|
|
39789
|
-
const
|
|
39790
|
-
|
|
39791
|
-
|
|
39792
|
-
|
|
39793
|
-
|
|
39794
|
-
|
|
39581
|
+
client.log('post/approvePost', postId);
|
|
39582
|
+
const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/approve`);
|
|
39583
|
+
fireEvent('post.approved', payload);
|
|
39584
|
+
// fire virtual event for community update
|
|
39585
|
+
if (payload.posts[0].targetType === 'community') {
|
|
39586
|
+
fireEvent('community.updated', payload);
|
|
39587
|
+
}
|
|
39588
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
39589
|
+
const cachedAt = client.cache && Date.now();
|
|
39590
|
+
if (client.cache)
|
|
39591
|
+
ingestInCache(data, { cachedAt });
|
|
39592
|
+
return {
|
|
39593
|
+
data: LinkedObject.post(data.posts.find(post => post.postId === postId)),
|
|
39594
|
+
cachedAt,
|
|
39595
|
+
};
|
|
39795
39596
|
};
|
|
39796
39597
|
/* end_public_function */
|
|
39797
39598
|
|
|
39798
39599
|
/* begin_public_function
|
|
39799
|
-
id:
|
|
39600
|
+
id: post.decline
|
|
39800
39601
|
*/
|
|
39801
39602
|
/**
|
|
39802
39603
|
* ```js
|
|
39803
|
-
* import {
|
|
39804
|
-
*
|
|
39604
|
+
* import { declinePost } from '@amityco/ts-sdk'
|
|
39605
|
+
*
|
|
39606
|
+
* const {data: post} = await declinePost('postId')
|
|
39805
39607
|
* ```
|
|
39806
39608
|
*
|
|
39807
|
-
*
|
|
39808
|
-
* @returns the unflagged result
|
|
39609
|
+
* Declines a {@link Amity.Post}
|
|
39809
39610
|
*
|
|
39810
|
-
* @
|
|
39611
|
+
* @param postId The {@link Amity.Post} ID to be declined
|
|
39612
|
+
* @return A {@link Amity.Post} that was declined
|
|
39613
|
+
*
|
|
39614
|
+
* @category Post API
|
|
39615
|
+
* @async
|
|
39616
|
+
*/
|
|
39617
|
+
const declinePost = async (postId) => {
|
|
39618
|
+
const client = getActiveClient();
|
|
39619
|
+
client.log('post/declinePost', postId);
|
|
39620
|
+
const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/decline`);
|
|
39621
|
+
// fire virtual event
|
|
39622
|
+
if (payload.posts[0].targetType === 'community') {
|
|
39623
|
+
fireEvent('community.updated', payload);
|
|
39624
|
+
}
|
|
39625
|
+
fireEvent('post.declined', payload);
|
|
39626
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
39627
|
+
const cachedAt = client.cache && Date.now();
|
|
39628
|
+
if (client.cache)
|
|
39629
|
+
ingestInCache(data, { cachedAt });
|
|
39630
|
+
return {
|
|
39631
|
+
data: LinkedObject.post(payload.posts.find(post => post.postId === postId)),
|
|
39632
|
+
cachedAt,
|
|
39633
|
+
};
|
|
39634
|
+
};
|
|
39635
|
+
/* end_public_function */
|
|
39636
|
+
|
|
39637
|
+
/* begin_public_function
|
|
39638
|
+
id: post.flag
|
|
39639
|
+
*/
|
|
39640
|
+
/**
|
|
39641
|
+
* ```js
|
|
39642
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
39643
|
+
* const flagged = await PostRepository.flagPost(postId, reason)
|
|
39644
|
+
* ```
|
|
39645
|
+
*
|
|
39646
|
+
* @param postId of the post to flag
|
|
39647
|
+
* @param reason the reason to flag the post
|
|
39648
|
+
* @returns a boolean
|
|
39649
|
+
*
|
|
39650
|
+
* @category Post API
|
|
39811
39651
|
* @async
|
|
39812
39652
|
* */
|
|
39813
|
-
const
|
|
39653
|
+
const flagPost = async (postId, reason) => {
|
|
39814
39654
|
const client = getActiveClient();
|
|
39815
|
-
client.log('
|
|
39816
|
-
const
|
|
39655
|
+
client.log('post/flagPost', postId);
|
|
39656
|
+
const isPredefinedReason = reason &&
|
|
39657
|
+
Object.entries(ContentFlagReasonEnum).some(([key, value]) => key !== ContentFlagReasonEnum.Others && value === reason);
|
|
39658
|
+
const body = {
|
|
39659
|
+
reason: reason && isPredefinedReason ? reason : ContentFlagReasonEnum.Others,
|
|
39660
|
+
detail: reason && !isPredefinedReason ? reason : '',
|
|
39661
|
+
};
|
|
39662
|
+
const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/flag`, body);
|
|
39817
39663
|
if (client.cache) {
|
|
39818
|
-
ingestInCache(payload);
|
|
39664
|
+
ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
|
|
39819
39665
|
}
|
|
39820
|
-
fireEvent('
|
|
39666
|
+
fireEvent('post.flagged', payload);
|
|
39821
39667
|
return !!payload;
|
|
39822
39668
|
};
|
|
39823
39669
|
/* end_public_function */
|
|
39824
39670
|
|
|
39825
39671
|
/* begin_public_function
|
|
39826
|
-
id:
|
|
39672
|
+
id: post.unflag
|
|
39827
39673
|
*/
|
|
39828
39674
|
/**
|
|
39829
39675
|
* ```js
|
|
39830
|
-
* import {
|
|
39831
|
-
* const
|
|
39676
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
39677
|
+
* const unflagged = await PostRepository.unflagPost(postId)
|
|
39832
39678
|
* ```
|
|
39833
39679
|
*
|
|
39834
|
-
* @param
|
|
39835
|
-
* @returns
|
|
39680
|
+
* @param postId of the post to unflag
|
|
39681
|
+
* @returns the unflag post result
|
|
39836
39682
|
*
|
|
39837
|
-
* @category
|
|
39683
|
+
* @category Post API
|
|
39838
39684
|
* @async
|
|
39839
39685
|
* */
|
|
39840
|
-
const
|
|
39686
|
+
const unflagPost = async (postId) => {
|
|
39841
39687
|
const client = getActiveClient();
|
|
39842
|
-
client.log('
|
|
39843
|
-
const { data:
|
|
39688
|
+
client.log('post/unflagPost', postId);
|
|
39689
|
+
const { data: payload } = await client.http.delete(`/api/v3/posts/${encodeURIComponent(postId)}/unflag`);
|
|
39690
|
+
if (client.cache) {
|
|
39691
|
+
ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
|
|
39692
|
+
}
|
|
39693
|
+
fireEvent('post.unflagged', payload);
|
|
39694
|
+
return !!payload;
|
|
39695
|
+
};
|
|
39696
|
+
/* end_public_function */
|
|
39697
|
+
|
|
39698
|
+
/* begin_public_function
|
|
39699
|
+
id: post.check_flag_by_me
|
|
39700
|
+
*/
|
|
39701
|
+
/**
|
|
39702
|
+
* ```js
|
|
39703
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
39704
|
+
* const isReported = await PostRepository.isPostFlaggedByMe('post', postId)
|
|
39705
|
+
* ```
|
|
39706
|
+
*
|
|
39707
|
+
* @param postId of the post to check if flagged by current user
|
|
39708
|
+
* @returns `true` if the post is flagged by me, `false` if doesn't.
|
|
39709
|
+
*
|
|
39710
|
+
* @category Post API
|
|
39711
|
+
* @async
|
|
39712
|
+
* */
|
|
39713
|
+
const isPostFlaggedByMe = async (postId) => {
|
|
39714
|
+
const client = getActiveClient();
|
|
39715
|
+
client.log('post/isPostFlaggedByMe', postId);
|
|
39716
|
+
const { data: { result }, } = await client.http.get(`/api/v3/posts/${postId}/isflagbyme`);
|
|
39844
39717
|
return result;
|
|
39845
39718
|
};
|
|
39846
39719
|
/* end_public_function */
|
|
39847
39720
|
|
|
39848
|
-
|
|
39721
|
+
/* begin_public_function
|
|
39722
|
+
id: post.create.clip_post
|
|
39723
|
+
*/
|
|
39724
|
+
/**
|
|
39725
|
+
* ```js
|
|
39726
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
39727
|
+
* const created = await PostRepository.createClipPost({
|
|
39728
|
+
* targetType: 'user',
|
|
39729
|
+
* targetId: 'foobar',
|
|
39730
|
+
* dataType: 'clip',
|
|
39731
|
+
* data: { text: 'hello world' },
|
|
39732
|
+
* attachments: [{ type: 'clip', fileId: 'fileId123', displayMode: 'fill', isMuted: false }]
|
|
39733
|
+
* }))
|
|
39734
|
+
* ```
|
|
39735
|
+
*
|
|
39736
|
+
* Creates an {@link Amity.Post}
|
|
39737
|
+
*
|
|
39738
|
+
* @param bundle The data necessary to create a new {@link Amity.Post}
|
|
39739
|
+
* @returns The newly created {@link Amity.Post}
|
|
39740
|
+
*
|
|
39741
|
+
* @category Post API
|
|
39742
|
+
* @async
|
|
39743
|
+
*/
|
|
39744
|
+
const createClipPost = async (bundle) => {
|
|
39849
39745
|
const client = getActiveClient();
|
|
39850
|
-
client.log('
|
|
39851
|
-
|
|
39746
|
+
client.log('post/createPost', bundle);
|
|
39747
|
+
const { data: payload } = await client.http.post('/api/v4/posts', bundle);
|
|
39748
|
+
fireEvent('post.created', payload);
|
|
39749
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
39750
|
+
const cachedAt = client.cache && Date.now();
|
|
39751
|
+
if (client.cache)
|
|
39752
|
+
ingestInCache(data, { cachedAt });
|
|
39753
|
+
const { posts } = data;
|
|
39754
|
+
return {
|
|
39755
|
+
data: LinkedObject.post(posts[0]),
|
|
39756
|
+
cachedAt,
|
|
39757
|
+
};
|
|
39758
|
+
};
|
|
39759
|
+
/* end_public_function */
|
|
39760
|
+
|
|
39761
|
+
/* begin_public_function
|
|
39762
|
+
id: comment.get_by_ids
|
|
39763
|
+
*/
|
|
39764
|
+
/**
|
|
39765
|
+
* ```js
|
|
39766
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
39767
|
+
* const comments = await CommentRepository.getCommentByIds(['foo', 'bar'])
|
|
39768
|
+
* ```
|
|
39769
|
+
*
|
|
39770
|
+
* Fetches a collection of {@link Amity.Comment} objects
|
|
39771
|
+
*
|
|
39772
|
+
* @param commentIds the IDs of the {@link Amity.Comment} to fetch
|
|
39773
|
+
* @returns the associated collection of {@link Amity.Comment} objects
|
|
39774
|
+
*
|
|
39775
|
+
* @category Comment API
|
|
39776
|
+
* @async
|
|
39777
|
+
*/
|
|
39778
|
+
const getCommentByIds = async (commentIds) => {
|
|
39779
|
+
const client = getActiveClient();
|
|
39780
|
+
client.log('comment/getCommentByIds', commentIds);
|
|
39781
|
+
const encodedCommentIds = commentIds.map(commentId => encodeURIComponent(commentId));
|
|
39852
39782
|
let data;
|
|
39853
39783
|
try {
|
|
39854
39784
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
39855
|
-
const response = await client.http.get(`/api/v3/comments
|
|
39785
|
+
const response = await client.http.get(`/api/v3/comments/list`, {
|
|
39786
|
+
params: { commentIds: encodedCommentIds },
|
|
39787
|
+
});
|
|
39856
39788
|
data = response.data;
|
|
39857
39789
|
}
|
|
39858
39790
|
catch (error) {
|
|
39859
|
-
|
|
39860
|
-
|
|
39861
|
-
|
|
39791
|
+
commentIds.forEach(commentId => {
|
|
39792
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
39793
|
+
pushToTombstone('comment', commentId);
|
|
39794
|
+
}
|
|
39795
|
+
});
|
|
39862
39796
|
throw error;
|
|
39863
39797
|
}
|
|
39864
39798
|
const cachedAt = client.cache && Date.now();
|
|
39865
39799
|
if (client.cache)
|
|
39866
39800
|
ingestInCache(data, { cachedAt });
|
|
39867
|
-
const { comments } = data;
|
|
39868
39801
|
return {
|
|
39869
|
-
data: comments.
|
|
39802
|
+
data: data.comments.map(comment => LinkedObject.comment(comment)),
|
|
39870
39803
|
cachedAt,
|
|
39871
39804
|
};
|
|
39872
39805
|
};
|
|
39873
|
-
|
|
39806
|
+
/* end_public_function */
|
|
39807
|
+
/**
|
|
39808
|
+
* ```js
|
|
39809
|
+
* import { getCommentByIds } from '@amityco/ts-sdk'
|
|
39810
|
+
* const comments = getCommentByIds.locally(['foo', 'bar'])
|
|
39811
|
+
* ```
|
|
39812
|
+
*
|
|
39813
|
+
* Fetches a collection of {@link Amity.Comment} objects from cache
|
|
39814
|
+
*
|
|
39815
|
+
* @param commentIds the IDs of the {@link Amity.Comment} to fetch
|
|
39816
|
+
* @returns the associated collection of {@link Amity.Comment} objects
|
|
39817
|
+
*
|
|
39818
|
+
* @category Comment API
|
|
39819
|
+
*/
|
|
39820
|
+
getCommentByIds.locally = (commentIds) => {
|
|
39821
|
+
var _a;
|
|
39874
39822
|
const client = getActiveClient();
|
|
39875
|
-
client.log('comment/
|
|
39823
|
+
client.log('comment/getCommentByIds.locally', commentIds);
|
|
39876
39824
|
if (!client.cache)
|
|
39877
39825
|
return;
|
|
39878
|
-
const cached =
|
|
39879
|
-
|
|
39826
|
+
const cached = commentIds
|
|
39827
|
+
.map(commentId => pullFromCache(['comment', 'get', commentId]))
|
|
39828
|
+
.filter(Boolean);
|
|
39829
|
+
const comments = cached.map(({ data }) => data);
|
|
39830
|
+
const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
|
|
39831
|
+
if ((cached === null || cached === void 0 ? void 0 : cached.length) < commentIds.length)
|
|
39880
39832
|
return;
|
|
39881
39833
|
return {
|
|
39882
|
-
data:
|
|
39883
|
-
cachedAt:
|
|
39834
|
+
data: comments.map(comment => LinkedObject.comment(comment)),
|
|
39835
|
+
cachedAt: oldest.cachedAt,
|
|
39884
39836
|
};
|
|
39885
39837
|
};
|
|
39886
39838
|
|
|
39839
|
+
/* begin_public_function
|
|
39840
|
+
id: comment.create
|
|
39841
|
+
*/
|
|
39887
39842
|
/**
|
|
39888
39843
|
* ```js
|
|
39889
|
-
* import {
|
|
39890
|
-
* const
|
|
39891
|
-
* // ...
|
|
39892
|
-
* })
|
|
39844
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
39845
|
+
* const newComment = await CommentRepository.createComment(bundle)
|
|
39893
39846
|
* ```
|
|
39894
39847
|
*
|
|
39895
|
-
*
|
|
39848
|
+
* Creates an {@link Amity.Comment}
|
|
39896
39849
|
*
|
|
39897
|
-
* @param
|
|
39898
|
-
* @returns
|
|
39850
|
+
* @param bundle The data necessary to create a new {@link Amity.Comment}
|
|
39851
|
+
* @returns The newly created {@link Amity.Comment}
|
|
39899
39852
|
*
|
|
39900
|
-
* @category Comment
|
|
39853
|
+
* @category Comment API
|
|
39854
|
+
* @async
|
|
39901
39855
|
*/
|
|
39902
|
-
const
|
|
39903
|
-
|
|
39904
|
-
/**
|
|
39905
|
-
* ```js
|
|
39906
|
-
* import { onLocalCommentReactionAdded } from '@amityco/ts-sdk'
|
|
39907
|
-
* const dispose = onLocalCommentReactionAdded(comment => {
|
|
39908
|
-
* // ...
|
|
39909
|
-
* })
|
|
39910
|
-
* ```
|
|
39911
|
-
*
|
|
39912
|
-
* Fired when a {@link Amity.InternalComment} has been reacted
|
|
39913
|
-
*
|
|
39914
|
-
* @param callback The function to call when the event was fired
|
|
39915
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
39916
|
-
*
|
|
39917
|
-
* @category Comment Events
|
|
39918
|
-
*/
|
|
39919
|
-
const onLocalCommentReactionAdded = (callback) => {
|
|
39856
|
+
const createComment = async (bundle) => {
|
|
39857
|
+
var _a;
|
|
39920
39858
|
const client = getActiveClient();
|
|
39921
|
-
|
|
39922
|
-
|
|
39923
|
-
|
|
39859
|
+
client.log('comment/createComment', bundle);
|
|
39860
|
+
const { data } = await client.http.post('/api/v3/comments', bundle);
|
|
39861
|
+
const { comments } = data;
|
|
39862
|
+
// BE always returns an array of comments If it got record 0 from BE it might have a problem on creation logic
|
|
39863
|
+
if (comments.length === 0)
|
|
39864
|
+
throw new Error('Comment not created');
|
|
39865
|
+
const cachedAt = client.cache && Date.now();
|
|
39866
|
+
if (client.cache)
|
|
39867
|
+
ingestInCache(data, { cachedAt });
|
|
39868
|
+
if (['post', 'content'].includes(bundle.referenceType)) {
|
|
39869
|
+
const post = (_a = pullFromCache(['post', 'get', bundle.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
39870
|
+
if (post) {
|
|
39871
|
+
post.commentsCount += 1;
|
|
39872
|
+
fireEvent('local.post.updated', {
|
|
39873
|
+
posts: [post],
|
|
39874
|
+
categories: [],
|
|
39875
|
+
comments: [],
|
|
39876
|
+
communities: [],
|
|
39877
|
+
communityUsers: data.communityUsers,
|
|
39878
|
+
feeds: [],
|
|
39879
|
+
files: data.files,
|
|
39880
|
+
postChildren: [],
|
|
39881
|
+
users: data.users,
|
|
39882
|
+
videoStreamings: [],
|
|
39883
|
+
});
|
|
39924
39884
|
}
|
|
39925
|
-
|
|
39926
|
-
|
|
39927
|
-
|
|
39885
|
+
}
|
|
39886
|
+
else if (bundle.referenceType === 'story') {
|
|
39887
|
+
const storyIndex = pullFromCache([
|
|
39888
|
+
"story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
|
|
39889
|
+
bundle.referenceId,
|
|
39890
|
+
]);
|
|
39891
|
+
if (storyIndex === null || storyIndex === void 0 ? void 0 : storyIndex.data) {
|
|
39892
|
+
const cacheStory = pullFromCache([
|
|
39893
|
+
"story" /* STORY_KEY_CACHE.STORY */,
|
|
39894
|
+
'get',
|
|
39895
|
+
storyIndex.data,
|
|
39896
|
+
]);
|
|
39897
|
+
if (cacheStory === null || cacheStory === void 0 ? void 0 : cacheStory.data) {
|
|
39898
|
+
fireEvent('story.updated', {
|
|
39899
|
+
stories: [
|
|
39900
|
+
Object.assign(Object.assign({}, cacheStory.data), { commentsCount: cacheStory.data.commentsCount + 1, comments: [...new Set([...cacheStory.data.comments, comments[0].commentId])] }),
|
|
39901
|
+
],
|
|
39902
|
+
categories: [],
|
|
39903
|
+
comments,
|
|
39904
|
+
communities: [],
|
|
39905
|
+
communityUsers: data.communityUsers,
|
|
39906
|
+
files: data.files,
|
|
39907
|
+
users: data.users,
|
|
39908
|
+
});
|
|
39909
|
+
}
|
|
39928
39910
|
}
|
|
39911
|
+
}
|
|
39912
|
+
fireEvent('local.comment.created', data);
|
|
39913
|
+
return {
|
|
39914
|
+
data: LinkedObject.comment(comments[0]),
|
|
39915
|
+
cachedAt,
|
|
39929
39916
|
};
|
|
39930
|
-
return createEventSubscriber(client, 'local.comment.addReaction', 'local.comment.addReaction', filter);
|
|
39931
39917
|
};
|
|
39918
|
+
/* end_public_function */
|
|
39932
39919
|
|
|
39920
|
+
/* begin_public_function
|
|
39921
|
+
id: comment.update_comment
|
|
39922
|
+
*/
|
|
39933
39923
|
/**
|
|
39934
39924
|
* ```js
|
|
39935
|
-
* import {
|
|
39936
|
-
* const
|
|
39937
|
-
*
|
|
39925
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
39926
|
+
* const updated = await CommentRepository.updateComment(commentId, {
|
|
39927
|
+
* data: { text: 'hello world' }
|
|
39938
39928
|
* })
|
|
39939
39929
|
* ```
|
|
39940
39930
|
*
|
|
39941
|
-
*
|
|
39931
|
+
* Updates an {@link Amity.Comment}
|
|
39942
39932
|
*
|
|
39943
|
-
* @param
|
|
39944
|
-
* @
|
|
39933
|
+
* @param commentId The ID of the {@link Amity.Comment} to edit
|
|
39934
|
+
* @param patch The patch data to apply
|
|
39935
|
+
* @returns the updated {@link Amity.Comment} object
|
|
39945
39936
|
*
|
|
39946
|
-
* @category Comment
|
|
39937
|
+
* @category Comment API
|
|
39938
|
+
* @async
|
|
39947
39939
|
*/
|
|
39948
|
-
const
|
|
39940
|
+
const updateComment = async (commentId, patch) => {
|
|
39949
39941
|
const client = getActiveClient();
|
|
39950
|
-
|
|
39951
|
-
|
|
39952
|
-
|
|
39953
|
-
|
|
39954
|
-
|
|
39955
|
-
|
|
39956
|
-
|
|
39942
|
+
client.log('user/updateComment', patch);
|
|
39943
|
+
const { data } = await client.http.put(`/api/v3/comments/${encodeURIComponent(commentId)}`, patch);
|
|
39944
|
+
const cachedAt = client.cache && Date.now();
|
|
39945
|
+
if (client.cache)
|
|
39946
|
+
ingestInCache(data, { cachedAt });
|
|
39947
|
+
fireEvent('comment.updated', data);
|
|
39948
|
+
const { comments } = data;
|
|
39949
|
+
return {
|
|
39950
|
+
data: LinkedObject.comment(comments.find(comment => comment.commentId === commentId)),
|
|
39951
|
+
cachedAt,
|
|
39952
|
+
};
|
|
39953
|
+
};
|
|
39954
|
+
/* end_public_function */
|
|
39955
|
+
|
|
39956
|
+
// Due to we have optimistic logic, we will use referenceId as a id in SDK instead of storyId
|
|
39957
|
+
const applyMissingField = (rawData, isCreated = false) => {
|
|
39958
|
+
const { storyId, referenceId } = rawData;
|
|
39959
|
+
if (!isCreated) {
|
|
39960
|
+
if (referenceId)
|
|
39961
|
+
return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */ });
|
|
39962
|
+
}
|
|
39963
|
+
return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */, referenceId: storyId });
|
|
39964
|
+
};
|
|
39965
|
+
const convertRawStoryToInternal = (data, isCreated = false) => {
|
|
39966
|
+
const { stories } = data;
|
|
39967
|
+
const storiesData = stories.map(story => applyMissingField(story, isCreated));
|
|
39968
|
+
return Object.assign(Object.assign({}, data), { stories: storiesData });
|
|
39969
|
+
};
|
|
39970
|
+
|
|
39971
|
+
const getStoryByStoryId$1 = async (storyId) => {
|
|
39972
|
+
const client = getActiveClient();
|
|
39973
|
+
client.log('story/getStoryByStoryId', storyId);
|
|
39974
|
+
// Get story referenceId from cache
|
|
39975
|
+
const cacheReferenceId = pullFromCache([
|
|
39976
|
+
"story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
|
|
39977
|
+
storyId,
|
|
39978
|
+
]);
|
|
39979
|
+
if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
|
|
39980
|
+
const { data: referenceId } = cacheReferenceId;
|
|
39981
|
+
isInTombstone('story', referenceId);
|
|
39982
|
+
}
|
|
39983
|
+
let data;
|
|
39984
|
+
try {
|
|
39985
|
+
const response = await client.http.get(`/api/v4/stories/${storyId}`);
|
|
39986
|
+
data = convertRawStoryToInternal(response.data);
|
|
39987
|
+
}
|
|
39988
|
+
catch (error) {
|
|
39989
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
39990
|
+
pushToTombstone('story', storyId);
|
|
39957
39991
|
}
|
|
39992
|
+
throw error;
|
|
39993
|
+
}
|
|
39994
|
+
const cachedAt = client.cache && Date.now();
|
|
39995
|
+
if (client.cache) {
|
|
39996
|
+
ingestInCache(data, { cachedAt });
|
|
39997
|
+
}
|
|
39998
|
+
return {
|
|
39999
|
+
data: data.stories[0],
|
|
40000
|
+
cachedAt,
|
|
40001
|
+
};
|
|
40002
|
+
};
|
|
40003
|
+
getStoryByStoryId$1.locally = (storyId) => {
|
|
40004
|
+
const client = getActiveClient();
|
|
40005
|
+
client.log('story/getStorybyStoryId', storyId);
|
|
40006
|
+
// Get story referenceId from cache
|
|
40007
|
+
const cacheReferenceId = pullFromCache([
|
|
40008
|
+
"story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
|
|
40009
|
+
storyId,
|
|
40010
|
+
]);
|
|
40011
|
+
if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
|
|
40012
|
+
const { data: referenceId } = cacheReferenceId;
|
|
40013
|
+
isInTombstone('story', referenceId);
|
|
40014
|
+
}
|
|
40015
|
+
const cachedAt = client.cache && Date.now();
|
|
40016
|
+
const storyCache = pullFromCache(['story', 'get', storyId]);
|
|
40017
|
+
if (!storyCache)
|
|
40018
|
+
return;
|
|
40019
|
+
return {
|
|
40020
|
+
data: storyCache.data,
|
|
40021
|
+
cachedAt,
|
|
39958
40022
|
};
|
|
39959
|
-
return createEventSubscriber(client, 'local.comment.removeReaction', 'local.comment.removeReaction', filter);
|
|
39960
40023
|
};
|
|
39961
40024
|
|
|
39962
40025
|
/* begin_public_function
|
|
39963
|
-
id: comment.
|
|
40026
|
+
id: comment.soft_delete, comment.hard_delete
|
|
39964
40027
|
*/
|
|
39965
40028
|
/**
|
|
39966
40029
|
* ```js
|
|
39967
|
-
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
39968
|
-
*
|
|
39969
|
-
* let comment;
|
|
39970
|
-
*
|
|
39971
|
-
* const unsub = CommentRepository.getComment(commentId, response => {
|
|
39972
|
-
* comment = response.data;
|
|
39973
|
-
* });
|
|
40030
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
40031
|
+
* const success = await CommentRepository.deleteComment('foobar')
|
|
39974
40032
|
* ```
|
|
39975
40033
|
*
|
|
39976
|
-
*
|
|
40034
|
+
* Deletes a {@link Amity.Comment}
|
|
39977
40035
|
*
|
|
39978
|
-
* @param commentId
|
|
39979
|
-
* @
|
|
39980
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the comment
|
|
40036
|
+
* @param commentId The {@link Amity.Comment} ID to delete
|
|
40037
|
+
* @return A success boolean if the {@link Amity.Comment} was deleted
|
|
39981
40038
|
*
|
|
39982
|
-
* @category Comment
|
|
40039
|
+
* @category Comment API
|
|
40040
|
+
* @async
|
|
39983
40041
|
*/
|
|
39984
|
-
const
|
|
39985
|
-
|
|
39986
|
-
|
|
39987
|
-
|
|
39988
|
-
|
|
39989
|
-
|
|
39990
|
-
|
|
39991
|
-
|
|
39992
|
-
|
|
39993
|
-
|
|
39994
|
-
|
|
39995
|
-
|
|
39996
|
-
};
|
|
39997
|
-
|
|
39998
|
-
|
|
39999
|
-
|
|
40000
|
-
|
|
40001
|
-
|
|
40002
|
-
|
|
40003
|
-
|
|
40004
|
-
|
|
40005
|
-
|
|
40006
|
-
|
|
40007
|
-
|
|
40008
|
-
});
|
|
40009
|
-
return queryResponse;
|
|
40010
|
-
}
|
|
40011
|
-
}
|
|
40012
|
-
|
|
40013
|
-
var EnumCommentActions;
|
|
40014
|
-
(function (EnumCommentActions) {
|
|
40015
|
-
EnumCommentActions["OnCommentCreated"] = "onCommentCreated";
|
|
40016
|
-
EnumCommentActions["OnCommentUpdated"] = "onCommentUpdated";
|
|
40017
|
-
EnumCommentActions["OnCommentDeleted"] = "onCommentDeleted";
|
|
40018
|
-
EnumCommentActions["OnCommentFlagged"] = "onCommentFlagged";
|
|
40019
|
-
EnumCommentActions["OnCommentUnflagged"] = "onCommentUnflagged";
|
|
40020
|
-
EnumCommentActions["OnCommentReactionAdded"] = "onCommentReactionAdded";
|
|
40021
|
-
EnumCommentActions["OnCommentReactionRemoved"] = "onCommentReactionRemoved";
|
|
40022
|
-
})(EnumCommentActions || (EnumCommentActions = {}));
|
|
40023
|
-
|
|
40024
|
-
class CommentQueryStreamController extends QueryStreamController {
|
|
40025
|
-
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
40026
|
-
super(query, cacheKey);
|
|
40027
|
-
this.notifyChange = notifyChange;
|
|
40028
|
-
this.preparePayload = preparePayload;
|
|
40029
|
-
}
|
|
40030
|
-
async saveToMainDB(response) {
|
|
40031
|
-
const processedPayload = await this.preparePayload(response);
|
|
40032
|
-
const client = getActiveClient();
|
|
40033
|
-
const cachedAt = client.cache && Date.now();
|
|
40034
|
-
if (client.cache) {
|
|
40035
|
-
ingestInCache(processedPayload, { cachedAt });
|
|
40036
|
-
}
|
|
40042
|
+
const deleteComment = async (commentId, permanent = false) => {
|
|
40043
|
+
var _a;
|
|
40044
|
+
const client = getActiveClient();
|
|
40045
|
+
const comment = await getComment$2(commentId);
|
|
40046
|
+
// API-FIX: This endpoint has not been implemented yet.
|
|
40047
|
+
await client.http.delete(`/api/v4/comments/${encodeURIComponent(commentId)}`, {
|
|
40048
|
+
params: {
|
|
40049
|
+
commentId,
|
|
40050
|
+
permanent,
|
|
40051
|
+
},
|
|
40052
|
+
});
|
|
40053
|
+
// to support hard deletion
|
|
40054
|
+
const deleted = Object.assign(Object.assign({}, comment.data), { isDeleted: true });
|
|
40055
|
+
if (comment.data.referenceType === 'story') {
|
|
40056
|
+
const story = await getStoryByStoryId$1(comment.data.referenceId);
|
|
40057
|
+
fireEvent('local.story.updated', {
|
|
40058
|
+
stories: [story.data],
|
|
40059
|
+
categories: [],
|
|
40060
|
+
comments: [],
|
|
40061
|
+
communities: [],
|
|
40062
|
+
communityUsers: [],
|
|
40063
|
+
files: [],
|
|
40064
|
+
users: [],
|
|
40065
|
+
});
|
|
40037
40066
|
}
|
|
40038
|
-
|
|
40039
|
-
|
|
40040
|
-
if (
|
|
40041
|
-
|
|
40042
|
-
|
|
40067
|
+
else {
|
|
40068
|
+
const post = (_a = pullFromCache(['post', 'get', comment.data.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
40069
|
+
if (post) {
|
|
40070
|
+
let removeCount;
|
|
40071
|
+
if (!deleted.parentId) {
|
|
40072
|
+
// NOTE: delete the parent comment will remove all children comments
|
|
40073
|
+
removeCount = deleted.childrenNumber + 1;
|
|
40074
|
+
}
|
|
40075
|
+
else
|
|
40076
|
+
removeCount = 1;
|
|
40077
|
+
post.commentsCount -= removeCount;
|
|
40078
|
+
fireEvent('local.post.updated', {
|
|
40079
|
+
posts: [post],
|
|
40080
|
+
categories: [],
|
|
40081
|
+
comments: [],
|
|
40082
|
+
communities: [],
|
|
40083
|
+
communityUsers: [],
|
|
40084
|
+
feeds: [],
|
|
40085
|
+
files: [],
|
|
40086
|
+
postChildren: [],
|
|
40087
|
+
users: [],
|
|
40088
|
+
videoStreamings: [],
|
|
40043
40089
|
});
|
|
40044
40090
|
}
|
|
40045
|
-
else {
|
|
40046
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
40047
|
-
const comments = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
40048
|
-
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...comments, ...response.comments.map(getResolver('comment'))])] }));
|
|
40049
|
-
}
|
|
40050
40091
|
}
|
|
40051
|
-
|
|
40052
|
-
|
|
40053
|
-
|
|
40054
|
-
|
|
40055
|
-
|
|
40056
|
-
|
|
40057
|
-
|
|
40058
|
-
|
|
40059
|
-
|
|
40060
|
-
if (this.query.parentId && this.query.parentId !== comment.parentId) {
|
|
40061
|
-
return;
|
|
40062
|
-
}
|
|
40063
|
-
if (!this.query.parentId && comment.parentId) {
|
|
40064
|
-
return;
|
|
40065
|
-
}
|
|
40066
|
-
if (action === EnumCommentActions.OnCommentCreated) {
|
|
40067
|
-
collection.data = [...new Set([comment.commentId, ...collection.data])];
|
|
40068
|
-
}
|
|
40069
|
-
pushToCache(this.cacheKey, collection);
|
|
40070
|
-
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
40071
|
-
};
|
|
40092
|
+
fireEvent('local.comment.deleted', {
|
|
40093
|
+
comments: [deleted],
|
|
40094
|
+
commentChildren: [],
|
|
40095
|
+
files: [],
|
|
40096
|
+
users: [],
|
|
40097
|
+
communityUsers: [],
|
|
40098
|
+
});
|
|
40099
|
+
if (permanent) {
|
|
40100
|
+
scheduleTask(() => pushToTombstone('comment', commentId));
|
|
40072
40101
|
}
|
|
40073
|
-
|
|
40074
|
-
|
|
40102
|
+
else {
|
|
40103
|
+
upsertInCache(['comment', 'get', commentId], { isDeleted: true });
|
|
40075
40104
|
}
|
|
40076
|
-
|
|
40105
|
+
return deleted;
|
|
40106
|
+
};
|
|
40107
|
+
/* end_public_function */
|
|
40077
40108
|
|
|
40109
|
+
/* begin_public_function
|
|
40110
|
+
id: comment.soft_delete
|
|
40111
|
+
*/
|
|
40078
40112
|
/**
|
|
40079
40113
|
* ```js
|
|
40080
|
-
* import {
|
|
40081
|
-
* const
|
|
40082
|
-
* // ...
|
|
40083
|
-
* })
|
|
40114
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
40115
|
+
* const success = await CommentRepository.softDeleteComment('foobar')
|
|
40084
40116
|
* ```
|
|
40085
40117
|
*
|
|
40086
|
-
*
|
|
40118
|
+
* Deletes a {@link Amity.Comment}
|
|
40087
40119
|
*
|
|
40088
|
-
* @param
|
|
40089
|
-
* @
|
|
40120
|
+
* @param commentId The {@link Amity.Comment} ID to delete
|
|
40121
|
+
* @return A success boolean if the {@link Amity.Comment} was deleted
|
|
40090
40122
|
*
|
|
40091
|
-
* @category Comment
|
|
40123
|
+
* @category Comment API
|
|
40124
|
+
* @async
|
|
40092
40125
|
*/
|
|
40093
|
-
const
|
|
40094
|
-
|
|
40126
|
+
const softDeleteComment = async (commentId) => {
|
|
40127
|
+
const client = getActiveClient();
|
|
40128
|
+
client.log('comment/softDeleteComment', commentId);
|
|
40129
|
+
const softDeleted = deleteComment(commentId);
|
|
40130
|
+
return softDeleted;
|
|
40095
40131
|
};
|
|
40096
|
-
|
|
40097
|
-
class CommentLiveCollectionController extends LiveCollectionController {
|
|
40098
|
-
constructor(query, callback) {
|
|
40099
|
-
const queryStreamId = hash(query);
|
|
40100
|
-
const cacheKey = ['comments', 'collection', queryStreamId];
|
|
40101
|
-
const paginationController = new CommentPaginationController(query);
|
|
40102
|
-
super(paginationController, queryStreamId, cacheKey, callback);
|
|
40103
|
-
this.query = query;
|
|
40104
|
-
this.queryStreamController = new CommentQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommentPayload);
|
|
40105
|
-
this.callback = callback.bind(this);
|
|
40106
|
-
this.loadPage({ initial: true });
|
|
40107
|
-
}
|
|
40108
|
-
setup() {
|
|
40109
|
-
var _a;
|
|
40110
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
40111
|
-
if (!collection) {
|
|
40112
|
-
pushToCache(this.cacheKey, {
|
|
40113
|
-
data: [],
|
|
40114
|
-
params: {},
|
|
40115
|
-
});
|
|
40116
|
-
}
|
|
40117
|
-
}
|
|
40118
|
-
async persistModel(queryPayload) {
|
|
40119
|
-
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
40120
|
-
}
|
|
40121
|
-
persistQueryStream({ response, direction, refresh, }) {
|
|
40122
|
-
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
40123
|
-
}
|
|
40124
|
-
startSubscription() {
|
|
40125
|
-
return this.queryStreamController.subscribeRTE([
|
|
40126
|
-
{ fn: onCommentCreatedLocal, action: EnumCommentActions.OnCommentCreated },
|
|
40127
|
-
{ fn: onCommentDeleteLocal, action: EnumCommentActions.OnCommentDeleted },
|
|
40128
|
-
{ fn: onCommentCreated, action: EnumCommentActions.OnCommentCreated },
|
|
40129
|
-
{ fn: onCommentUpdated, action: EnumCommentActions.OnCommentUpdated },
|
|
40130
|
-
{ fn: onCommentDeleted, action: EnumCommentActions.OnCommentDeleted },
|
|
40131
|
-
{ fn: onCommentFlagged, action: EnumCommentActions.OnCommentFlagged },
|
|
40132
|
-
{ fn: onCommentUnflagged, action: EnumCommentActions.OnCommentUnflagged },
|
|
40133
|
-
{ fn: onCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
|
|
40134
|
-
{ fn: onCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
|
|
40135
|
-
{ fn: onLocalCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
|
|
40136
|
-
{ fn: onLocalCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
|
|
40137
|
-
]);
|
|
40138
|
-
}
|
|
40139
|
-
notifyChange({ origin, loading, error }) {
|
|
40140
|
-
var _a, _b;
|
|
40141
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
40142
|
-
if (!collection)
|
|
40143
|
-
return;
|
|
40144
|
-
const data = this.applyFilter((_b = collection.data
|
|
40145
|
-
.map(id => pullFromCache(['comment', 'get', id]))
|
|
40146
|
-
.filter(isNonNullable)
|
|
40147
|
-
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.comment);
|
|
40148
|
-
if (!this.shouldNotify(data) && origin === 'event')
|
|
40149
|
-
return;
|
|
40150
|
-
this.callback({
|
|
40151
|
-
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
40152
|
-
data,
|
|
40153
|
-
hasNextPage: !!this.paginationController.getNextToken(),
|
|
40154
|
-
loading,
|
|
40155
|
-
error,
|
|
40156
|
-
});
|
|
40157
|
-
}
|
|
40158
|
-
applyFilter(data) {
|
|
40159
|
-
let comments = data;
|
|
40160
|
-
if (!this.query.includeDeleted) {
|
|
40161
|
-
comments = filterByPropEquality(comments, 'isDeleted', false);
|
|
40162
|
-
}
|
|
40163
|
-
if (this.query.parentId) {
|
|
40164
|
-
comments = comments.filter(comment => comment.parentId === this.query.parentId);
|
|
40165
|
-
}
|
|
40166
|
-
if (typeof this.query.hasFlag === 'boolean') {
|
|
40167
|
-
if (this.query.hasFlag) {
|
|
40168
|
-
comments = comments.filter(comment => comment.hashFlag != null);
|
|
40169
|
-
}
|
|
40170
|
-
else {
|
|
40171
|
-
comments = comments.filter(comment => comment.hashFlag == null);
|
|
40172
|
-
}
|
|
40173
|
-
}
|
|
40174
|
-
if (this.query.dataTypes) {
|
|
40175
|
-
if (this.query.dataTypes.matchType === 'exact') {
|
|
40176
|
-
comments = comments.filter(comment => {
|
|
40177
|
-
var _a, _b;
|
|
40178
|
-
const sortedDataTypesQueryValue = ((_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.values.sort()) || [];
|
|
40179
|
-
const sortedDataTypesCommentValue = ((_b = comment.dataTypes) === null || _b === void 0 ? void 0 : _b.sort()) || [];
|
|
40180
|
-
if (sortedDataTypesCommentValue.length !== sortedDataTypesQueryValue.length) {
|
|
40181
|
-
return false;
|
|
40182
|
-
}
|
|
40183
|
-
return sortedDataTypesQueryValue.every((value, index) => value === sortedDataTypesCommentValue[index]);
|
|
40184
|
-
});
|
|
40185
|
-
}
|
|
40186
|
-
if (this.query.dataTypes.matchType === 'any') {
|
|
40187
|
-
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); }); });
|
|
40188
|
-
}
|
|
40189
|
-
}
|
|
40190
|
-
switch (this.query.sortBy) {
|
|
40191
|
-
case 'firstCreated':
|
|
40192
|
-
comments = comments.sort(sortByFirstCreated);
|
|
40193
|
-
break;
|
|
40194
|
-
case 'lastCreated':
|
|
40195
|
-
default:
|
|
40196
|
-
comments = comments.sort(sortByLastCreated);
|
|
40197
|
-
break;
|
|
40198
|
-
}
|
|
40199
|
-
return comments;
|
|
40200
|
-
}
|
|
40201
|
-
}
|
|
40132
|
+
/* end_public_function */
|
|
40202
40133
|
|
|
40203
40134
|
/* begin_public_function
|
|
40204
|
-
id: comment.
|
|
40135
|
+
id: comment.hard_delete
|
|
40205
40136
|
*/
|
|
40206
40137
|
/**
|
|
40207
40138
|
* ```js
|
|
40208
|
-
* import {
|
|
40209
|
-
*
|
|
40210
|
-
* let comments = []
|
|
40211
|
-
* const unsub = getComments({
|
|
40212
|
-
* referenceType: Amity.InternalComment['referenceType'];
|
|
40213
|
-
* referenceId: Amity.InternalComment['referenceId'];
|
|
40214
|
-
* }, response => merge(comments, response.data))
|
|
40139
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
40140
|
+
* const success = await CommentRepository.hardDeleteComment('foobar')
|
|
40215
40141
|
* ```
|
|
40216
40142
|
*
|
|
40217
|
-
*
|
|
40143
|
+
* Deletes a {@link Amity.Comment}
|
|
40218
40144
|
*
|
|
40219
|
-
* @param
|
|
40220
|
-
* @
|
|
40221
|
-
* @param callback the function to call when new data are available
|
|
40222
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
40145
|
+
* @param commentId The {@link Amity.Comment} ID to delete
|
|
40146
|
+
* @return A success boolean if the {@link Amity.Comment} was deleted
|
|
40223
40147
|
*
|
|
40224
|
-
* @category
|
|
40148
|
+
* @category Comment API
|
|
40149
|
+
* @async
|
|
40225
40150
|
*/
|
|
40226
|
-
const
|
|
40227
|
-
const
|
|
40228
|
-
|
|
40229
|
-
|
|
40230
|
-
|
|
40231
|
-
|
|
40232
|
-
|
|
40233
|
-
|
|
40234
|
-
|
|
40235
|
-
|
|
40236
|
-
|
|
40237
|
-
|
|
40238
|
-
|
|
40239
|
-
|
|
40151
|
+
const hardDeleteComment = async (commentId) => {
|
|
40152
|
+
const client = getActiveClient();
|
|
40153
|
+
client.log('comment/hardDeleteComment', commentId);
|
|
40154
|
+
const hardDeleted = deleteComment(commentId, true);
|
|
40155
|
+
return hardDeleted;
|
|
40156
|
+
};
|
|
40157
|
+
/* end_public_function */
|
|
40158
|
+
|
|
40159
|
+
/* begin_public_function
|
|
40160
|
+
id: comment.flag
|
|
40161
|
+
*/
|
|
40162
|
+
/**
|
|
40163
|
+
* ```js
|
|
40164
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
40165
|
+
* const flagged = await CommentRepository.flagComment(commentId, reason)
|
|
40166
|
+
* ```
|
|
40167
|
+
*
|
|
40168
|
+
* @param commentId The ID of the comment to flag
|
|
40169
|
+
* @param reason the reason to flag the comment
|
|
40170
|
+
* @returns the created report result
|
|
40171
|
+
*
|
|
40172
|
+
* @category Comment API
|
|
40173
|
+
* @async
|
|
40174
|
+
* */
|
|
40175
|
+
const flagComment = async (commentId, reason) => {
|
|
40176
|
+
const client = getActiveClient();
|
|
40177
|
+
client.log('comment/flagComment', commentId);
|
|
40178
|
+
const isPredefinedReason = reason &&
|
|
40179
|
+
Object.entries(ContentFlagReasonEnum).some(([key, value]) => key !== ContentFlagReasonEnum.Others && value === reason);
|
|
40180
|
+
const body = {
|
|
40181
|
+
reason: reason && isPredefinedReason ? reason : ContentFlagReasonEnum.Others,
|
|
40182
|
+
detail: reason && !isPredefinedReason ? reason : '',
|
|
40240
40183
|
};
|
|
40184
|
+
const { data: payload } = await client.http.post(`/api/v3/comments/${encodeURIComponent(commentId)}/flag`, body);
|
|
40185
|
+
if (client.cache) {
|
|
40186
|
+
ingestInCache(payload);
|
|
40187
|
+
}
|
|
40188
|
+
fireEvent('comment.flagged', payload);
|
|
40189
|
+
return !!payload;
|
|
40241
40190
|
};
|
|
40242
40191
|
/* end_public_function */
|
|
40243
40192
|
|
|
40244
|
-
|
|
40245
|
-
|
|
40246
|
-
|
|
40247
|
-
|
|
40248
|
-
|
|
40249
|
-
|
|
40250
|
-
|
|
40251
|
-
|
|
40252
|
-
|
|
40253
|
-
|
|
40254
|
-
|
|
40255
|
-
|
|
40256
|
-
|
|
40257
|
-
|
|
40258
|
-
|
|
40259
|
-
|
|
40260
|
-
|
|
40261
|
-
|
|
40262
|
-
|
|
40263
|
-
|
|
40264
|
-
|
|
40193
|
+
/* begin_public_function
|
|
40194
|
+
id: comment.unflag
|
|
40195
|
+
*/
|
|
40196
|
+
/**
|
|
40197
|
+
* ```js
|
|
40198
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
40199
|
+
* const unflagged = await CommentRepository.unflagComment('commentId')
|
|
40200
|
+
* ```
|
|
40201
|
+
*
|
|
40202
|
+
* @param commentId The ID of comment to unflag
|
|
40203
|
+
* @returns the unflagged result
|
|
40204
|
+
*
|
|
40205
|
+
* @category Comment API
|
|
40206
|
+
* @async
|
|
40207
|
+
* */
|
|
40208
|
+
const unflagComment = async (commentId) => {
|
|
40209
|
+
const client = getActiveClient();
|
|
40210
|
+
client.log('comment/unflagComment', commentId);
|
|
40211
|
+
const { data: payload } = await client.http.delete(`/api/v3/comments/${encodeURIComponent(commentId)}/unflag`);
|
|
40212
|
+
if (client.cache) {
|
|
40213
|
+
ingestInCache(payload);
|
|
40214
|
+
}
|
|
40215
|
+
fireEvent('comment.unflagged', payload);
|
|
40216
|
+
return !!payload;
|
|
40217
|
+
};
|
|
40218
|
+
/* end_public_function */
|
|
40219
|
+
|
|
40220
|
+
/* begin_public_function
|
|
40221
|
+
id: comment.check_flag_by_me
|
|
40222
|
+
*/
|
|
40223
|
+
/**
|
|
40224
|
+
* ```js
|
|
40225
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
40226
|
+
* const isReported = await CommentRepository.isCommentFlaggedByMe('commentId')
|
|
40227
|
+
* ```
|
|
40228
|
+
*
|
|
40229
|
+
* @param commentId The ID of the comment to check if flagged by current user
|
|
40230
|
+
* @returns `true` if the comment is flagged by me, `false` if doesn't.
|
|
40231
|
+
*
|
|
40232
|
+
* @category Comment API
|
|
40233
|
+
* @async
|
|
40234
|
+
* */
|
|
40235
|
+
const isCommentFlaggedByMe = async (commentId) => {
|
|
40236
|
+
const client = getActiveClient();
|
|
40237
|
+
client.log('comment/isCommentFlaggedByMe', commentId);
|
|
40238
|
+
const { data: { result }, } = await client.http.get(`/api/v3/comments/${commentId}/isflagbyme`);
|
|
40239
|
+
return result;
|
|
40240
|
+
};
|
|
40241
|
+
/* end_public_function */
|
|
40265
40242
|
|
|
40266
|
-
const
|
|
40243
|
+
const getComment$1 = async (commentId) => {
|
|
40267
40244
|
const client = getActiveClient();
|
|
40268
|
-
client.log('
|
|
40269
|
-
isInTombstone('
|
|
40270
|
-
let
|
|
40245
|
+
client.log('comment/getComment', commentId);
|
|
40246
|
+
isInTombstone('comment', commentId);
|
|
40247
|
+
let data;
|
|
40271
40248
|
try {
|
|
40272
40249
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
40273
|
-
const response = await client.http.get(`/api/v3/
|
|
40274
|
-
|
|
40250
|
+
const response = await client.http.get(`/api/v3/comments/${encodeURIComponent(commentId)}`);
|
|
40251
|
+
data = response.data;
|
|
40275
40252
|
}
|
|
40276
40253
|
catch (error) {
|
|
40277
40254
|
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
40278
|
-
pushToTombstone('
|
|
40255
|
+
pushToTombstone('comment', commentId);
|
|
40279
40256
|
}
|
|
40280
40257
|
throw error;
|
|
40281
40258
|
}
|
|
40282
|
-
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
40283
40259
|
const cachedAt = client.cache && Date.now();
|
|
40284
40260
|
if (client.cache)
|
|
40285
40261
|
ingestInCache(data, { cachedAt });
|
|
40286
|
-
const {
|
|
40287
|
-
const result = posts.find(post => post.postId === postId);
|
|
40262
|
+
const { comments } = data;
|
|
40288
40263
|
return {
|
|
40289
|
-
data:
|
|
40264
|
+
data: comments.find(comment => comment.commentId === commentId),
|
|
40290
40265
|
cachedAt,
|
|
40291
40266
|
};
|
|
40292
40267
|
};
|
|
40293
|
-
|
|
40268
|
+
getComment$1.locally = (commentId) => {
|
|
40294
40269
|
const client = getActiveClient();
|
|
40295
|
-
client.log('
|
|
40270
|
+
client.log('comment/getComment.locally', commentId);
|
|
40296
40271
|
if (!client.cache)
|
|
40297
40272
|
return;
|
|
40298
|
-
const cached = pullFromCache(['
|
|
40273
|
+
const cached = pullFromCache(['comment', 'get', commentId]);
|
|
40299
40274
|
if (!cached)
|
|
40300
40275
|
return;
|
|
40301
40276
|
return {
|
|
@@ -40306,113 +40281,231 @@ getPost$1.locally = (postId) => {
|
|
|
40306
40281
|
|
|
40307
40282
|
/**
|
|
40308
40283
|
* ```js
|
|
40309
|
-
* import {
|
|
40310
|
-
* const dispose =
|
|
40284
|
+
* import { onCommentDeleteLocal } from '@amityco/ts-sdk'
|
|
40285
|
+
* const dispose = onCommentDeleteLocal(comment => {
|
|
40311
40286
|
* // ...
|
|
40312
40287
|
* })
|
|
40313
40288
|
* ```
|
|
40314
40289
|
*
|
|
40315
|
-
* Fired when a {@link Amity.
|
|
40290
|
+
* Fired when a {@link Amity.InternalComment} has been deleted
|
|
40316
40291
|
*
|
|
40317
40292
|
* @param callback The function to call when the event was fired
|
|
40318
40293
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
40319
40294
|
*
|
|
40320
|
-
* @category
|
|
40295
|
+
* @category Comment Events
|
|
40321
40296
|
*/
|
|
40322
|
-
const
|
|
40297
|
+
const onCommentDeleteLocal = (callback) => createLocalCommentEventSubscriber('local.comment.deleted', callback);
|
|
40323
40298
|
|
|
40324
40299
|
/**
|
|
40325
40300
|
* ```js
|
|
40326
|
-
* import {
|
|
40327
|
-
* const dispose =
|
|
40301
|
+
* import { onLocalCommentReactionAdded } from '@amityco/ts-sdk'
|
|
40302
|
+
* const dispose = onLocalCommentReactionAdded(comment => {
|
|
40328
40303
|
* // ...
|
|
40329
40304
|
* })
|
|
40330
40305
|
* ```
|
|
40331
40306
|
*
|
|
40332
|
-
* Fired when a {@link Amity.
|
|
40307
|
+
* Fired when a {@link Amity.InternalComment} has been reacted
|
|
40333
40308
|
*
|
|
40334
40309
|
* @param callback The function to call when the event was fired
|
|
40335
40310
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
40336
40311
|
*
|
|
40337
|
-
* @category
|
|
40312
|
+
* @category Comment Events
|
|
40338
40313
|
*/
|
|
40339
|
-
const
|
|
40314
|
+
const onLocalCommentReactionAdded = (callback) => {
|
|
40340
40315
|
const client = getActiveClient();
|
|
40341
|
-
const filter = ({
|
|
40316
|
+
const filter = ({ comment }) => {
|
|
40342
40317
|
if (!client.cache) {
|
|
40343
|
-
callback(
|
|
40318
|
+
callback(comment);
|
|
40344
40319
|
}
|
|
40345
40320
|
else {
|
|
40346
|
-
upsertInCache(['
|
|
40347
|
-
callback(
|
|
40321
|
+
upsertInCache(['comment', 'get', comment.commentId], comment);
|
|
40322
|
+
callback(commentLinkedObject(comment));
|
|
40348
40323
|
}
|
|
40349
40324
|
};
|
|
40350
|
-
return createEventSubscriber(client, 'local.
|
|
40325
|
+
return createEventSubscriber(client, 'local.comment.addReaction', 'local.comment.addReaction', filter);
|
|
40351
40326
|
};
|
|
40352
40327
|
|
|
40353
40328
|
/**
|
|
40354
40329
|
* ```js
|
|
40355
|
-
* import {
|
|
40356
|
-
* const dispose =
|
|
40330
|
+
* import { onLocalCommentReactionRemoved } from '@amityco/ts-sdk'
|
|
40331
|
+
* const dispose = onLocalCommentReactionRemoved(comment => {
|
|
40357
40332
|
* // ...
|
|
40358
40333
|
* })
|
|
40359
40334
|
* ```
|
|
40360
40335
|
*
|
|
40361
|
-
* Fired when a {@link Amity.
|
|
40336
|
+
* Fired when a {@link Amity.InternalComment} has been reacted
|
|
40362
40337
|
*
|
|
40363
40338
|
* @param callback The function to call when the event was fired
|
|
40364
40339
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
40365
40340
|
*
|
|
40366
|
-
* @category
|
|
40341
|
+
* @category Comment Events
|
|
40367
40342
|
*/
|
|
40368
|
-
const
|
|
40343
|
+
const onLocalCommentReactionRemoved = (callback) => {
|
|
40369
40344
|
const client = getActiveClient();
|
|
40370
|
-
const filter = ({
|
|
40345
|
+
const filter = ({ comment }) => {
|
|
40371
40346
|
if (!client.cache) {
|
|
40372
|
-
callback(
|
|
40347
|
+
callback(comment);
|
|
40373
40348
|
}
|
|
40374
40349
|
else {
|
|
40375
|
-
upsertInCache(['
|
|
40376
|
-
callback(
|
|
40350
|
+
upsertInCache(['comment', 'get', comment.commentId], comment);
|
|
40351
|
+
callback(commentLinkedObject(comment));
|
|
40377
40352
|
}
|
|
40378
40353
|
};
|
|
40379
|
-
return createEventSubscriber(client, 'local.
|
|
40354
|
+
return createEventSubscriber(client, 'local.comment.removeReaction', 'local.comment.removeReaction', filter);
|
|
40380
40355
|
};
|
|
40381
40356
|
|
|
40357
|
+
/* begin_public_function
|
|
40358
|
+
id: comment.get
|
|
40359
|
+
*/
|
|
40382
40360
|
/**
|
|
40383
40361
|
* ```js
|
|
40384
|
-
* import {
|
|
40385
|
-
*
|
|
40386
|
-
*
|
|
40387
|
-
*
|
|
40362
|
+
* import { CommentRepository } from '@amityco/ts-sdk';
|
|
40363
|
+
*
|
|
40364
|
+
* let comment;
|
|
40365
|
+
*
|
|
40366
|
+
* const unsub = CommentRepository.getComment(commentId, response => {
|
|
40367
|
+
* comment = response.data;
|
|
40368
|
+
* });
|
|
40388
40369
|
* ```
|
|
40389
40370
|
*
|
|
40390
|
-
*
|
|
40371
|
+
* Observe all mutation on a given {@link Amity.Comment}
|
|
40391
40372
|
*
|
|
40392
|
-
* @param
|
|
40393
|
-
* @
|
|
40373
|
+
* @param commentId the ID of the comment to observe
|
|
40374
|
+
* @param callback the function to call when new data are available
|
|
40375
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the comment
|
|
40394
40376
|
*
|
|
40395
|
-
* @category
|
|
40377
|
+
* @category Comment Live Object
|
|
40396
40378
|
*/
|
|
40397
|
-
const
|
|
40379
|
+
const getComment = (commentId, callback) => {
|
|
40380
|
+
return liveObject(commentId, callback, 'commentId', getComment$1, [
|
|
40381
|
+
onCommentDeleteLocal,
|
|
40382
|
+
onCommentDeleted,
|
|
40383
|
+
onCommentFlagged,
|
|
40384
|
+
onCommentReactionAdded,
|
|
40385
|
+
onCommentReactionRemoved,
|
|
40386
|
+
onCommentUnflagged,
|
|
40387
|
+
onCommentUpdated,
|
|
40388
|
+
onLocalCommentReactionAdded,
|
|
40389
|
+
onLocalCommentReactionRemoved,
|
|
40390
|
+
]);
|
|
40391
|
+
};
|
|
40392
|
+
/* end_public_function */
|
|
40398
40393
|
|
|
40399
|
-
class
|
|
40400
|
-
|
|
40401
|
-
const
|
|
40402
|
-
const
|
|
40403
|
-
|
|
40404
|
-
|
|
40405
|
-
|
|
40406
|
-
|
|
40407
|
-
|
|
40408
|
-
|
|
40394
|
+
class CommentPaginationController extends PaginationController {
|
|
40395
|
+
async getRequest(queryParams, token) {
|
|
40396
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
|
|
40397
|
+
const baseOptions = {
|
|
40398
|
+
type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
|
|
40399
|
+
};
|
|
40400
|
+
const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
|
|
40401
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/comments`, {
|
|
40402
|
+
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options }),
|
|
40403
|
+
});
|
|
40404
|
+
return queryResponse;
|
|
40409
40405
|
}
|
|
40410
|
-
|
|
40411
|
-
|
|
40412
|
-
|
|
40413
|
-
|
|
40414
|
-
|
|
40415
|
-
|
|
40406
|
+
}
|
|
40407
|
+
|
|
40408
|
+
var EnumCommentActions;
|
|
40409
|
+
(function (EnumCommentActions) {
|
|
40410
|
+
EnumCommentActions["OnCommentCreated"] = "onCommentCreated";
|
|
40411
|
+
EnumCommentActions["OnCommentUpdated"] = "onCommentUpdated";
|
|
40412
|
+
EnumCommentActions["OnCommentDeleted"] = "onCommentDeleted";
|
|
40413
|
+
EnumCommentActions["OnCommentFlagged"] = "onCommentFlagged";
|
|
40414
|
+
EnumCommentActions["OnCommentUnflagged"] = "onCommentUnflagged";
|
|
40415
|
+
EnumCommentActions["OnCommentReactionAdded"] = "onCommentReactionAdded";
|
|
40416
|
+
EnumCommentActions["OnCommentReactionRemoved"] = "onCommentReactionRemoved";
|
|
40417
|
+
})(EnumCommentActions || (EnumCommentActions = {}));
|
|
40418
|
+
|
|
40419
|
+
class CommentQueryStreamController extends QueryStreamController {
|
|
40420
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
40421
|
+
super(query, cacheKey);
|
|
40422
|
+
this.notifyChange = notifyChange;
|
|
40423
|
+
this.preparePayload = preparePayload;
|
|
40424
|
+
}
|
|
40425
|
+
async saveToMainDB(response) {
|
|
40426
|
+
const processedPayload = await this.preparePayload(response);
|
|
40427
|
+
const client = getActiveClient();
|
|
40428
|
+
const cachedAt = client.cache && Date.now();
|
|
40429
|
+
if (client.cache) {
|
|
40430
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
40431
|
+
}
|
|
40432
|
+
}
|
|
40433
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
40434
|
+
var _a, _b;
|
|
40435
|
+
if (refresh) {
|
|
40436
|
+
pushToCache(this.cacheKey, {
|
|
40437
|
+
data: response.comments.map(getResolver('comment')),
|
|
40438
|
+
});
|
|
40439
|
+
}
|
|
40440
|
+
else {
|
|
40441
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
40442
|
+
const comments = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
40443
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...comments, ...response.comments.map(getResolver('comment'))])] }));
|
|
40444
|
+
}
|
|
40445
|
+
}
|
|
40446
|
+
reactor(action) {
|
|
40447
|
+
return (comment) => {
|
|
40448
|
+
var _a;
|
|
40449
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
40450
|
+
if (this.query.referenceId !== comment.referenceId ||
|
|
40451
|
+
this.query.referenceType !== comment.referenceType ||
|
|
40452
|
+
!collection) {
|
|
40453
|
+
return;
|
|
40454
|
+
}
|
|
40455
|
+
if (this.query.parentId && this.query.parentId !== comment.parentId) {
|
|
40456
|
+
return;
|
|
40457
|
+
}
|
|
40458
|
+
if (!this.query.parentId && comment.parentId) {
|
|
40459
|
+
return;
|
|
40460
|
+
}
|
|
40461
|
+
if (action === EnumCommentActions.OnCommentCreated) {
|
|
40462
|
+
collection.data = [...new Set([comment.commentId, ...collection.data])];
|
|
40463
|
+
}
|
|
40464
|
+
pushToCache(this.cacheKey, collection);
|
|
40465
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
40466
|
+
};
|
|
40467
|
+
}
|
|
40468
|
+
subscribeRTE(createSubscriber) {
|
|
40469
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
40470
|
+
}
|
|
40471
|
+
}
|
|
40472
|
+
|
|
40473
|
+
/**
|
|
40474
|
+
* ```js
|
|
40475
|
+
* import { onCommentCreated } from '@amityco/ts-sdk'
|
|
40476
|
+
* const dispose = onCommentCreated(comment => {
|
|
40477
|
+
* // ...
|
|
40478
|
+
* })
|
|
40479
|
+
* ```
|
|
40480
|
+
*
|
|
40481
|
+
* Fired when a {@link Amity.InternalComment} has been created
|
|
40482
|
+
*
|
|
40483
|
+
* @param callback The function to call when the event was fired
|
|
40484
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
40485
|
+
*
|
|
40486
|
+
* @category Comment Events
|
|
40487
|
+
*/
|
|
40488
|
+
const onCommentCreatedLocal = (callback) => {
|
|
40489
|
+
return createLocalCommentEventSubscriber('local.comment.created', callback);
|
|
40490
|
+
};
|
|
40491
|
+
|
|
40492
|
+
class CommentLiveCollectionController extends LiveCollectionController {
|
|
40493
|
+
constructor(query, callback) {
|
|
40494
|
+
const queryStreamId = hash(query);
|
|
40495
|
+
const cacheKey = ['comments', 'collection', queryStreamId];
|
|
40496
|
+
const paginationController = new CommentPaginationController(query);
|
|
40497
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
40498
|
+
this.query = query;
|
|
40499
|
+
this.queryStreamController = new CommentQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommentPayload);
|
|
40500
|
+
this.callback = callback.bind(this);
|
|
40501
|
+
this.loadPage({ initial: true });
|
|
40502
|
+
}
|
|
40503
|
+
setup() {
|
|
40504
|
+
var _a;
|
|
40505
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
40506
|
+
if (!collection) {
|
|
40507
|
+
pushToCache(this.cacheKey, {
|
|
40508
|
+
data: [],
|
|
40416
40509
|
params: {},
|
|
40417
40510
|
});
|
|
40418
40511
|
}
|
|
@@ -40425,45 +40518,17 @@ class UserFeedLiveCollectionController extends LiveCollectionController {
|
|
|
40425
40518
|
}
|
|
40426
40519
|
startSubscription() {
|
|
40427
40520
|
return this.queryStreamController.subscribeRTE([
|
|
40428
|
-
{ fn:
|
|
40429
|
-
{ fn:
|
|
40430
|
-
{ fn:
|
|
40431
|
-
{ fn:
|
|
40432
|
-
{ fn:
|
|
40433
|
-
{ fn:
|
|
40434
|
-
{ fn:
|
|
40435
|
-
{ fn:
|
|
40436
|
-
{ fn:
|
|
40437
|
-
{ fn:
|
|
40438
|
-
{ fn:
|
|
40439
|
-
{ fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
|
|
40440
|
-
{ fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
|
|
40441
|
-
{
|
|
40442
|
-
fn: convertEventPayload((callback) => {
|
|
40443
|
-
return onCommentCreated(async (comment) => {
|
|
40444
|
-
var _a;
|
|
40445
|
-
const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
40446
|
-
if (!currentCollection || currentCollection.data.includes(comment.referenceId))
|
|
40447
|
-
return;
|
|
40448
|
-
await getPost$1(comment.referenceId);
|
|
40449
|
-
callback(comment);
|
|
40450
|
-
});
|
|
40451
|
-
}, 'referenceId', 'post'),
|
|
40452
|
-
action: EnumPostActions.OnPostUpdated,
|
|
40453
|
-
},
|
|
40454
|
-
{
|
|
40455
|
-
fn: convertEventPayload((callback) => {
|
|
40456
|
-
return onCommentDeleted(async (comment) => {
|
|
40457
|
-
var _a;
|
|
40458
|
-
const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
40459
|
-
if (!currentCollection || currentCollection.data.includes(comment.referenceId))
|
|
40460
|
-
return;
|
|
40461
|
-
await getPost$1(comment.referenceId);
|
|
40462
|
-
callback(comment);
|
|
40463
|
-
});
|
|
40464
|
-
}, 'referenceId', 'post'),
|
|
40465
|
-
action: EnumPostActions.OnPostUpdated,
|
|
40466
|
-
},
|
|
40521
|
+
{ fn: onCommentCreatedLocal, action: EnumCommentActions.OnCommentCreated },
|
|
40522
|
+
{ fn: onCommentDeleteLocal, action: EnumCommentActions.OnCommentDeleted },
|
|
40523
|
+
{ fn: onCommentCreated, action: EnumCommentActions.OnCommentCreated },
|
|
40524
|
+
{ fn: onCommentUpdated, action: EnumCommentActions.OnCommentUpdated },
|
|
40525
|
+
{ fn: onCommentDeleted, action: EnumCommentActions.OnCommentDeleted },
|
|
40526
|
+
{ fn: onCommentFlagged, action: EnumCommentActions.OnCommentFlagged },
|
|
40527
|
+
{ fn: onCommentUnflagged, action: EnumCommentActions.OnCommentUnflagged },
|
|
40528
|
+
{ fn: onCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
|
|
40529
|
+
{ fn: onCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
|
|
40530
|
+
{ fn: onLocalCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
|
|
40531
|
+
{ fn: onLocalCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
|
|
40467
40532
|
]);
|
|
40468
40533
|
}
|
|
40469
40534
|
notifyChange({ origin, loading, error }) {
|
|
@@ -40472,9 +40537,9 @@ class UserFeedLiveCollectionController extends LiveCollectionController {
|
|
|
40472
40537
|
if (!collection)
|
|
40473
40538
|
return;
|
|
40474
40539
|
const data = this.applyFilter((_b = collection.data
|
|
40475
|
-
.map(id => pullFromCache(['
|
|
40540
|
+
.map(id => pullFromCache(['comment', 'get', id]))
|
|
40476
40541
|
.filter(isNonNullable)
|
|
40477
|
-
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.
|
|
40542
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.comment);
|
|
40478
40543
|
if (!this.shouldNotify(data) && origin === 'event')
|
|
40479
40544
|
return;
|
|
40480
40545
|
this.callback({
|
|
@@ -40486,560 +40551,204 @@ class UserFeedLiveCollectionController extends LiveCollectionController {
|
|
|
40486
40551
|
});
|
|
40487
40552
|
}
|
|
40488
40553
|
applyFilter(data) {
|
|
40489
|
-
|
|
40490
|
-
let posts = data;
|
|
40554
|
+
let comments = data;
|
|
40491
40555
|
if (!this.query.includeDeleted) {
|
|
40492
|
-
|
|
40556
|
+
comments = filterByPropEquality(comments, 'isDeleted', false);
|
|
40493
40557
|
}
|
|
40494
|
-
if (
|
|
40495
|
-
|
|
40558
|
+
if (this.query.parentId) {
|
|
40559
|
+
comments = comments.filter(comment => comment.parentId === this.query.parentId);
|
|
40560
|
+
}
|
|
40561
|
+
if (typeof this.query.hasFlag === 'boolean') {
|
|
40562
|
+
if (this.query.hasFlag) {
|
|
40563
|
+
comments = comments.filter(comment => comment.hashFlag != null);
|
|
40564
|
+
}
|
|
40565
|
+
else {
|
|
40566
|
+
comments = comments.filter(comment => comment.hashFlag == null);
|
|
40567
|
+
}
|
|
40568
|
+
}
|
|
40569
|
+
if (this.query.dataTypes) {
|
|
40570
|
+
if (this.query.dataTypes.matchType === 'exact') {
|
|
40571
|
+
comments = comments.filter(comment => {
|
|
40572
|
+
var _a, _b;
|
|
40573
|
+
const sortedDataTypesQueryValue = ((_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.values.sort()) || [];
|
|
40574
|
+
const sortedDataTypesCommentValue = ((_b = comment.dataTypes) === null || _b === void 0 ? void 0 : _b.sort()) || [];
|
|
40575
|
+
if (sortedDataTypesCommentValue.length !== sortedDataTypesQueryValue.length) {
|
|
40576
|
+
return false;
|
|
40577
|
+
}
|
|
40578
|
+
return sortedDataTypesQueryValue.every((value, index) => value === sortedDataTypesCommentValue[index]);
|
|
40579
|
+
});
|
|
40580
|
+
}
|
|
40581
|
+
if (this.query.dataTypes.matchType === 'any') {
|
|
40582
|
+
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); }); });
|
|
40583
|
+
}
|
|
40496
40584
|
}
|
|
40497
40585
|
switch (this.query.sortBy) {
|
|
40498
40586
|
case 'firstCreated':
|
|
40499
|
-
|
|
40587
|
+
comments = comments.sort(sortByFirstCreated);
|
|
40500
40588
|
break;
|
|
40501
40589
|
case 'lastCreated':
|
|
40502
40590
|
default:
|
|
40503
|
-
|
|
40591
|
+
comments = comments.sort(sortByLastCreated);
|
|
40504
40592
|
break;
|
|
40505
40593
|
}
|
|
40506
|
-
return
|
|
40594
|
+
return comments;
|
|
40507
40595
|
}
|
|
40508
40596
|
}
|
|
40509
40597
|
|
|
40510
40598
|
/* begin_public_function
|
|
40511
|
-
id:
|
|
40599
|
+
id: comment.query
|
|
40512
40600
|
*/
|
|
40513
40601
|
/**
|
|
40514
40602
|
* ```js
|
|
40515
|
-
* import {
|
|
40516
|
-
*
|
|
40517
|
-
* let posts = []
|
|
40518
|
-
* const unsubscribe = FeedRepository.getUserFeed({
|
|
40519
|
-
* userId: string,
|
|
40520
|
-
* feedSources: ['user', 'community'],
|
|
40521
|
-
* }, response => response => processResponse(response))
|
|
40522
|
-
* ```
|
|
40523
|
-
*
|
|
40524
|
-
* Observe all mutations on a list of {@link Amity.Post} for a given user and feedSources
|
|
40525
|
-
*
|
|
40526
|
-
* @param params.userId the ID of the user
|
|
40527
|
-
* @param params.feedSources the sources of the feed
|
|
40528
|
-
* @param callback the function to call when new data are available
|
|
40529
|
-
* @param config
|
|
40530
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
40603
|
+
* import { getComments } from '@amityco/ts-sdk'
|
|
40531
40604
|
*
|
|
40532
|
-
*
|
|
40533
|
-
|
|
40534
|
-
|
|
40535
|
-
|
|
40536
|
-
|
|
40537
|
-
console.log(ENABLE_CACHE_MESSAGE);
|
|
40538
|
-
}
|
|
40539
|
-
const timestamp = Date.now();
|
|
40540
|
-
log(`getUserFeed(tmpid: ${timestamp}) > listen`);
|
|
40541
|
-
const userFeedLiveCollection = new UserFeedLiveCollectionController(params, callback);
|
|
40542
|
-
const disposers = userFeedLiveCollection.startSubscription();
|
|
40543
|
-
const cacheKey = userFeedLiveCollection.getCacheKey();
|
|
40544
|
-
disposers.push(() => dropFromCache(cacheKey));
|
|
40545
|
-
return () => {
|
|
40546
|
-
log(`getUserFeed(tmpid: ${timestamp}) > dispose`);
|
|
40547
|
-
disposers.forEach(fn => fn());
|
|
40548
|
-
};
|
|
40549
|
-
};
|
|
40550
|
-
/* end_public_function */
|
|
40551
|
-
|
|
40552
|
-
var index$9 = /*#__PURE__*/Object.freeze({
|
|
40553
|
-
__proto__: null,
|
|
40554
|
-
queryGlobalFeed: queryGlobalFeed,
|
|
40555
|
-
getCustomRankingGlobalFeed: getCustomRankingGlobalFeed,
|
|
40556
|
-
getUserFeed: getUserFeed
|
|
40557
|
-
});
|
|
40558
|
-
|
|
40559
|
-
/* begin_public_function
|
|
40560
|
-
id: post.get_by_ids
|
|
40561
|
-
*/
|
|
40562
|
-
/**
|
|
40563
|
-
* ```js
|
|
40564
|
-
* import { getPostByIds } from '@amityco/ts-sdk'
|
|
40565
|
-
* const { data: posts } = await getPostByIds(['foo', 'bar'])
|
|
40605
|
+
* let comments = []
|
|
40606
|
+
* const unsub = getComments({
|
|
40607
|
+
* referenceType: Amity.InternalComment['referenceType'];
|
|
40608
|
+
* referenceId: Amity.InternalComment['referenceId'];
|
|
40609
|
+
* }, response => merge(comments, response.data))
|
|
40566
40610
|
* ```
|
|
40567
40611
|
*
|
|
40568
|
-
*
|
|
40569
|
-
*
|
|
40570
|
-
* @param postIds the IDs of the {@link Amity.Post} to fetch
|
|
40571
|
-
* @returns the associated collection of {@link Amity.Post} objects
|
|
40612
|
+
* Observe all mutations on a list of {@link Amity.InternalComment} for a given target object
|
|
40572
40613
|
*
|
|
40573
|
-
* @
|
|
40574
|
-
* @
|
|
40575
|
-
|
|
40576
|
-
|
|
40577
|
-
|
|
40578
|
-
|
|
40579
|
-
|
|
40580
|
-
|
|
40581
|
-
|
|
40582
|
-
|
|
40583
|
-
|
|
40584
|
-
params: { postIds: encodedPostIds },
|
|
40585
|
-
});
|
|
40586
|
-
payload = response.data;
|
|
40587
|
-
}
|
|
40588
|
-
catch (error) {
|
|
40589
|
-
postIds.forEach(postId => {
|
|
40590
|
-
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
40591
|
-
pushToTombstone('post', postId);
|
|
40592
|
-
}
|
|
40593
|
-
});
|
|
40594
|
-
throw error;
|
|
40595
|
-
}
|
|
40596
|
-
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
40597
|
-
const cachedAt = client.cache && Date.now();
|
|
40598
|
-
if (client.cache)
|
|
40599
|
-
ingestInCache(data, { cachedAt });
|
|
40600
|
-
return {
|
|
40601
|
-
data: data.posts.map(LinkedObject.post),
|
|
40602
|
-
cachedAt,
|
|
40603
|
-
};
|
|
40604
|
-
};
|
|
40605
|
-
/* end_public_function */
|
|
40606
|
-
/**
|
|
40607
|
-
* ```js
|
|
40608
|
-
* import { getPostByIds } from '@amityco/ts-sdk'
|
|
40609
|
-
* const { data: posts } = getPostByIds.locally(['foo', 'bar'])
|
|
40610
|
-
* ```
|
|
40611
|
-
*
|
|
40612
|
-
* Fetches a collection of {@link Amity.Post} objects from cache
|
|
40613
|
-
*
|
|
40614
|
-
* @param postIds the IDs of the {@link Amity.Post} to fetch
|
|
40615
|
-
* @returns the associated collection of {@link Amity.Post} objects
|
|
40616
|
-
*
|
|
40617
|
-
* @category Post API
|
|
40618
|
-
*/
|
|
40619
|
-
getPostByIds.locally = (postIds) => {
|
|
40620
|
-
var _a;
|
|
40621
|
-
const client = getActiveClient();
|
|
40622
|
-
client.log('post/getPostByIds.locally', postIds);
|
|
40623
|
-
if (!client.cache)
|
|
40624
|
-
return;
|
|
40625
|
-
const cached = postIds
|
|
40626
|
-
.map(postId => pullFromCache(['post', 'get', postId]))
|
|
40627
|
-
.filter(Boolean);
|
|
40628
|
-
const posts = cached.map(({ data }) => data);
|
|
40629
|
-
const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
|
|
40630
|
-
if ((cached === null || cached === void 0 ? void 0 : cached.length) < postIds.length)
|
|
40631
|
-
return;
|
|
40632
|
-
return {
|
|
40633
|
-
data: posts.map(LinkedObject.post),
|
|
40634
|
-
cachedAt: oldest.cachedAt,
|
|
40635
|
-
};
|
|
40636
|
-
};
|
|
40637
|
-
|
|
40638
|
-
/* begin_public_function
|
|
40639
|
-
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
|
|
40640
|
-
*/
|
|
40641
|
-
/**
|
|
40642
|
-
* ```js
|
|
40643
|
-
* import { PostRepository } from '@amityco/ts-sdk'
|
|
40644
|
-
* const created = await PostRepository.createPost({
|
|
40645
|
-
* targetType: 'user',
|
|
40646
|
-
* targetId: 'foobar',
|
|
40647
|
-
* data: { text: 'hello world' }
|
|
40648
|
-
* }))
|
|
40649
|
-
* ```
|
|
40650
|
-
*
|
|
40651
|
-
* Creates an {@link Amity.Post}
|
|
40652
|
-
*
|
|
40653
|
-
* @param bundle The data necessary to create a new {@link Amity.Post}
|
|
40654
|
-
* @returns The newly created {@link Amity.Post}
|
|
40655
|
-
*
|
|
40656
|
-
* @category Post API
|
|
40657
|
-
* @async
|
|
40658
|
-
*/
|
|
40659
|
-
const createPost = async (bundle) => {
|
|
40660
|
-
const client = getActiveClient();
|
|
40661
|
-
client.log('post/createPost', bundle);
|
|
40662
|
-
if (!bundle.dataType || ['text', 'image', 'file', 'video'].includes(bundle.dataType)) {
|
|
40663
|
-
// eslint-disable-next-line no-param-reassign
|
|
40664
|
-
delete bundle.dataType;
|
|
40665
|
-
}
|
|
40666
|
-
const { data: payload } = await client.http.post('/api/v4/posts', bundle);
|
|
40667
|
-
fireEvent('post.created', payload);
|
|
40668
|
-
const data = preparePostPayload(payload);
|
|
40669
|
-
const cachedAt = client.cache && Date.now();
|
|
40670
|
-
if (client.cache)
|
|
40671
|
-
ingestInCache(data, { cachedAt });
|
|
40672
|
-
const { posts } = data;
|
|
40673
|
-
return {
|
|
40674
|
-
data: LinkedObject.post(posts[0]),
|
|
40675
|
-
cachedAt,
|
|
40676
|
-
};
|
|
40677
|
-
};
|
|
40678
|
-
/* end_public_function */
|
|
40679
|
-
|
|
40680
|
-
/* begin_public_function
|
|
40681
|
-
id: post.edit, post.edit.custom_post
|
|
40682
|
-
*/
|
|
40683
|
-
/**
|
|
40684
|
-
* ```js
|
|
40685
|
-
* import { PostRepository } from '@amityco/ts-sdk'
|
|
40686
|
-
* const updated = await PostRepository.editPost(postId, {
|
|
40687
|
-
* data: { text: 'hello world' }
|
|
40688
|
-
* })
|
|
40689
|
-
* ```
|
|
40690
|
-
*
|
|
40691
|
-
* Updates an {@link Amity.Post}
|
|
40692
|
-
*
|
|
40693
|
-
* @param postId The ID of the {@link Amity.Post} to edit
|
|
40694
|
-
* @param patch The patch data to apply
|
|
40695
|
-
* @returns the updated {@link Amity.Post} object
|
|
40696
|
-
*
|
|
40697
|
-
* @category Post API
|
|
40698
|
-
* @async
|
|
40699
|
-
*/
|
|
40700
|
-
const editPost = async (postId, patch) => {
|
|
40701
|
-
const client = getActiveClient();
|
|
40702
|
-
client.log('user/editPost', patch);
|
|
40703
|
-
const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, patch);
|
|
40704
|
-
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
40705
|
-
const cachedAt = client.cache && Date.now();
|
|
40706
|
-
if (client.cache)
|
|
40707
|
-
ingestInCache(data, { cachedAt });
|
|
40708
|
-
fireEvent('local.post.updated', data);
|
|
40709
|
-
const { posts } = data;
|
|
40710
|
-
return {
|
|
40711
|
-
data: LinkedObject.post(posts.find(post => post.postId === postId)),
|
|
40712
|
-
cachedAt,
|
|
40713
|
-
};
|
|
40714
|
-
};
|
|
40715
|
-
/* end_public_function */
|
|
40716
|
-
|
|
40717
|
-
/**
|
|
40718
|
-
* ```js
|
|
40719
|
-
* import { deletePost } from '@amityco/ts-sdk'
|
|
40720
|
-
* const success = await deletePost('foobar')
|
|
40721
|
-
* ```
|
|
40722
|
-
*
|
|
40723
|
-
* Deletes a {@link Amity.Post}
|
|
40724
|
-
*
|
|
40725
|
-
* @param postId The {@link Amity.Post} ID to delete
|
|
40726
|
-
* @return A success boolean if the {@link Amity.Post} was deleted
|
|
40727
|
-
*
|
|
40728
|
-
* @private
|
|
40729
|
-
* @async
|
|
40730
|
-
*/
|
|
40731
|
-
const deletePost = async (postId, permanent = false) => {
|
|
40732
|
-
var _a;
|
|
40733
|
-
const client = getActiveClient();
|
|
40734
|
-
const post = await getPost$2(postId);
|
|
40735
|
-
await client.http.delete(`/api/v4/posts/${encodeURIComponent(postId)}`, {
|
|
40736
|
-
params: {
|
|
40737
|
-
postId,
|
|
40738
|
-
permanent,
|
|
40739
|
-
},
|
|
40740
|
-
});
|
|
40741
|
-
// there is currently a limitation which doesn't allow us to fire event to tell that community
|
|
40742
|
-
// has been updated. reason is that, when the object is deleted, we don't have its `communityId`
|
|
40743
|
-
// and so we cannot refetch the community or advertise on events. hopefully this should be solved
|
|
40744
|
-
// later when realtime events covers that for us.
|
|
40745
|
-
if (post.data.targetType === 'community') {
|
|
40746
|
-
const community = await getCommunity$1(post.data.targetId);
|
|
40747
|
-
const communityUsersCache = (_a = queryCache(['communityUsers', 'get'])) !== null && _a !== void 0 ? _a : [];
|
|
40748
|
-
const communityUsers = communityUsersCache
|
|
40749
|
-
.filter(({ key }) => {
|
|
40750
|
-
// cache key is ['communityUsers', 'get', `${communityId}#`${userId}`}]
|
|
40751
|
-
if (key[0] !== 'communityUsers')
|
|
40752
|
-
return false;
|
|
40753
|
-
if (key[1] !== 'get')
|
|
40754
|
-
return false;
|
|
40755
|
-
if (typeof key[2] === 'string')
|
|
40756
|
-
return key[2].includes(community.data.communityId);
|
|
40757
|
-
return false;
|
|
40758
|
-
})
|
|
40759
|
-
.map(({ data }) => data);
|
|
40760
|
-
fireEvent('community.updated', {
|
|
40761
|
-
communities: [community.data],
|
|
40762
|
-
categories: [],
|
|
40763
|
-
communityUsers,
|
|
40764
|
-
feeds: [],
|
|
40765
|
-
files: [],
|
|
40766
|
-
users: [],
|
|
40767
|
-
});
|
|
40768
|
-
}
|
|
40769
|
-
// to support hard deletion
|
|
40770
|
-
const deleted = Object.assign(Object.assign({}, post.data), { isDeleted: true });
|
|
40771
|
-
if (permanent) {
|
|
40772
|
-
setTimeout(() => {
|
|
40773
|
-
pushToTombstone('post', postId);
|
|
40774
|
-
}, 0);
|
|
40775
|
-
}
|
|
40776
|
-
else {
|
|
40777
|
-
upsertInCache(['post', 'get', postId], { isDeleted: true });
|
|
40778
|
-
}
|
|
40779
|
-
fireEvent('local.post.deleted', {
|
|
40780
|
-
posts: [deleted],
|
|
40781
|
-
categories: [],
|
|
40782
|
-
comments: [],
|
|
40783
|
-
communities: [],
|
|
40784
|
-
communityUsers: [],
|
|
40785
|
-
feeds: [],
|
|
40786
|
-
files: [],
|
|
40787
|
-
postChildren: [],
|
|
40788
|
-
users: [],
|
|
40789
|
-
videoStreamings: [],
|
|
40790
|
-
});
|
|
40791
|
-
return LinkedObject.post(deleted);
|
|
40792
|
-
};
|
|
40793
|
-
|
|
40794
|
-
/* begin_public_function
|
|
40795
|
-
id: post.soft_delete
|
|
40796
|
-
*/
|
|
40797
|
-
/**
|
|
40798
|
-
* ```js
|
|
40799
|
-
* import { PostRepository } from '@amityco/ts-sdk'
|
|
40800
|
-
* const success = await PostRepository.softDeletePost('foobar')
|
|
40801
|
-
* ```
|
|
40802
|
-
*
|
|
40803
|
-
* Soft deletes a {@link Amity.Post}
|
|
40804
|
-
*
|
|
40805
|
-
* @param postId The {@link Amity.Post} ID to soft delete
|
|
40806
|
-
* @return A success boolean if the {@link Amity.Post} was deleted
|
|
40807
|
-
*
|
|
40808
|
-
* @category Post API
|
|
40809
|
-
* @async
|
|
40810
|
-
*/
|
|
40811
|
-
const softDeletePost = async (postId) => {
|
|
40812
|
-
const client = getActiveClient();
|
|
40813
|
-
client.log('post/softDeletePost', postId);
|
|
40814
|
-
const softDeleted = await deletePost(postId, false);
|
|
40815
|
-
return LinkedObject.post(softDeleted);
|
|
40816
|
-
};
|
|
40817
|
-
/* end_public_function */
|
|
40818
|
-
|
|
40819
|
-
/* begin_public_function
|
|
40820
|
-
id: post.hard_delete
|
|
40821
|
-
*/
|
|
40822
|
-
/**
|
|
40823
|
-
* ```js
|
|
40824
|
-
* import { hardDeletePost } from '@amityco/ts-sdk'
|
|
40825
|
-
* const success = await hardDeletePost('foobar')
|
|
40826
|
-
* ```
|
|
40827
|
-
*
|
|
40828
|
-
* Hard deletes a {@link Amity.Post}
|
|
40829
|
-
*
|
|
40830
|
-
* @param postId The {@link Amity.Post} ID to be hard delete
|
|
40831
|
-
* @return A success boolean if the {@link Amity.Post} was deleted
|
|
40832
|
-
*
|
|
40833
|
-
* @category Post API
|
|
40834
|
-
* @async
|
|
40835
|
-
*/
|
|
40836
|
-
const hardDeletePost = async (postId) => {
|
|
40837
|
-
const client = getActiveClient();
|
|
40838
|
-
client.log('post/hardDeletePost', postId);
|
|
40839
|
-
const hardDeleted = await deletePost(postId, true);
|
|
40840
|
-
return LinkedObject.post(hardDeleted);
|
|
40841
|
-
};
|
|
40842
|
-
/* end_public_function */
|
|
40843
|
-
|
|
40844
|
-
/* begin_public_function
|
|
40845
|
-
id: post.approve
|
|
40846
|
-
*/
|
|
40847
|
-
/**
|
|
40848
|
-
* ```js
|
|
40849
|
-
* import { approvePost } from '@amityco/ts-sdk'
|
|
40850
|
-
*
|
|
40851
|
-
* const { data: post } = await approvePost('postId')
|
|
40852
|
-
* ```
|
|
40853
|
-
*
|
|
40854
|
-
* Approves a {@link Amity.Post}
|
|
40855
|
-
*
|
|
40856
|
-
* @param postId The {@link Amity.Post} ID to be approved
|
|
40857
|
-
* @return A {@link Amity.Post} that was approved
|
|
40858
|
-
*
|
|
40859
|
-
* @category Post API
|
|
40860
|
-
* @async
|
|
40861
|
-
*/
|
|
40862
|
-
const approvePost = async (postId) => {
|
|
40863
|
-
const client = getActiveClient();
|
|
40864
|
-
client.log('post/approvePost', postId);
|
|
40865
|
-
const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/approve`);
|
|
40866
|
-
fireEvent('post.approved', payload);
|
|
40867
|
-
// fire virtual event for community update
|
|
40868
|
-
if (payload.posts[0].targetType === 'community') {
|
|
40869
|
-
fireEvent('community.updated', payload);
|
|
40870
|
-
}
|
|
40871
|
-
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
40872
|
-
const cachedAt = client.cache && Date.now();
|
|
40873
|
-
if (client.cache)
|
|
40874
|
-
ingestInCache(data, { cachedAt });
|
|
40875
|
-
return {
|
|
40876
|
-
data: LinkedObject.post(data.posts.find(post => post.postId === postId)),
|
|
40877
|
-
cachedAt,
|
|
40878
|
-
};
|
|
40879
|
-
};
|
|
40880
|
-
/* end_public_function */
|
|
40881
|
-
|
|
40882
|
-
/* begin_public_function
|
|
40883
|
-
id: post.decline
|
|
40884
|
-
*/
|
|
40885
|
-
/**
|
|
40886
|
-
* ```js
|
|
40887
|
-
* import { declinePost } from '@amityco/ts-sdk'
|
|
40888
|
-
*
|
|
40889
|
-
* const {data: post} = await declinePost('postId')
|
|
40890
|
-
* ```
|
|
40891
|
-
*
|
|
40892
|
-
* Declines a {@link Amity.Post}
|
|
40893
|
-
*
|
|
40894
|
-
* @param postId The {@link Amity.Post} ID to be declined
|
|
40895
|
-
* @return A {@link Amity.Post} that was declined
|
|
40896
|
-
*
|
|
40897
|
-
* @category Post API
|
|
40898
|
-
* @async
|
|
40899
|
-
*/
|
|
40900
|
-
const declinePost = async (postId) => {
|
|
40901
|
-
const client = getActiveClient();
|
|
40902
|
-
client.log('post/declinePost', postId);
|
|
40903
|
-
const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/decline`);
|
|
40904
|
-
// fire virtual event
|
|
40905
|
-
if (payload.posts[0].targetType === 'community') {
|
|
40906
|
-
fireEvent('community.updated', payload);
|
|
40614
|
+
* @param referenceType the type of the target
|
|
40615
|
+
* @param referenceId the ID of the target
|
|
40616
|
+
* @param callback the function to call when new data are available
|
|
40617
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
40618
|
+
*
|
|
40619
|
+
* @category Comments Live Collection
|
|
40620
|
+
*/
|
|
40621
|
+
const getComments = (params, callback, config) => {
|
|
40622
|
+
const { log, cache } = getActiveClient();
|
|
40623
|
+
if (!cache) {
|
|
40624
|
+
console.log('For using Live Collection feature you need to enable Cache!');
|
|
40907
40625
|
}
|
|
40908
|
-
|
|
40909
|
-
|
|
40910
|
-
const
|
|
40911
|
-
|
|
40912
|
-
|
|
40913
|
-
|
|
40914
|
-
|
|
40915
|
-
|
|
40626
|
+
const timestamp = Date.now();
|
|
40627
|
+
log(`getComments(tmpid: ${timestamp}) > listen`);
|
|
40628
|
+
const commentsLiveCollection = new CommentLiveCollectionController(params, callback);
|
|
40629
|
+
const disposers = commentsLiveCollection.startSubscription();
|
|
40630
|
+
const cacheKey = commentsLiveCollection.getCacheKey();
|
|
40631
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
40632
|
+
return () => {
|
|
40633
|
+
log(`getComments(tmpid: ${timestamp}) > dispose`);
|
|
40634
|
+
disposers.forEach(fn => fn());
|
|
40916
40635
|
};
|
|
40917
40636
|
};
|
|
40918
40637
|
/* end_public_function */
|
|
40919
40638
|
|
|
40920
|
-
|
|
40921
|
-
|
|
40922
|
-
|
|
40639
|
+
var index$9 = /*#__PURE__*/Object.freeze({
|
|
40640
|
+
__proto__: null,
|
|
40641
|
+
getCommentByIds: getCommentByIds,
|
|
40642
|
+
createComment: createComment,
|
|
40643
|
+
updateComment: updateComment,
|
|
40644
|
+
deleteComment: deleteComment,
|
|
40645
|
+
softDeleteComment: softDeleteComment,
|
|
40646
|
+
hardDeleteComment: hardDeleteComment,
|
|
40647
|
+
flagComment: flagComment,
|
|
40648
|
+
unflagComment: unflagComment,
|
|
40649
|
+
isCommentFlaggedByMe: isCommentFlaggedByMe,
|
|
40650
|
+
onCommentCreated: onCommentCreated,
|
|
40651
|
+
onCommentUpdated: onCommentUpdated,
|
|
40652
|
+
onCommentDeleted: onCommentDeleted,
|
|
40653
|
+
onCommentFlagged: onCommentFlagged,
|
|
40654
|
+
onCommentUnflagged: onCommentUnflagged,
|
|
40655
|
+
onCommentReactionAdded: onCommentReactionAdded,
|
|
40656
|
+
onCommentReactionRemoved: onCommentReactionRemoved,
|
|
40657
|
+
getComment: getComment,
|
|
40658
|
+
getComments: getComments
|
|
40659
|
+
});
|
|
40660
|
+
|
|
40923
40661
|
/**
|
|
40924
40662
|
* ```js
|
|
40925
|
-
* import {
|
|
40926
|
-
* const
|
|
40663
|
+
* import { onPostUpdatedLocal } from '@amityco/ts-sdk'
|
|
40664
|
+
* const dispose = onPostUpdatedLocal(post => {
|
|
40665
|
+
* // ...
|
|
40666
|
+
* })
|
|
40927
40667
|
* ```
|
|
40928
40668
|
*
|
|
40929
|
-
*
|
|
40930
|
-
* @param reason the reason to flag the post
|
|
40931
|
-
* @returns a boolean
|
|
40669
|
+
* Fired when a {@link Amity.InternalPost} has been updated
|
|
40932
40670
|
*
|
|
40933
|
-
* @
|
|
40934
|
-
* @
|
|
40935
|
-
*
|
|
40936
|
-
|
|
40937
|
-
|
|
40938
|
-
|
|
40939
|
-
const isPredefinedReason = reason &&
|
|
40940
|
-
Object.entries(ContentFlagReasonEnum).some(([key, value]) => key !== ContentFlagReasonEnum.Others && value === reason);
|
|
40941
|
-
const body = {
|
|
40942
|
-
reason: reason && isPredefinedReason ? reason : ContentFlagReasonEnum.Others,
|
|
40943
|
-
detail: reason && !isPredefinedReason ? reason : '',
|
|
40944
|
-
};
|
|
40945
|
-
const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/flag`, body);
|
|
40946
|
-
if (client.cache) {
|
|
40947
|
-
ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
|
|
40948
|
-
}
|
|
40949
|
-
fireEvent('post.flagged', payload);
|
|
40950
|
-
return !!payload;
|
|
40951
|
-
};
|
|
40952
|
-
/* end_public_function */
|
|
40671
|
+
* @param callback The function to call when the event was fired
|
|
40672
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
40673
|
+
*
|
|
40674
|
+
* @category Post Events
|
|
40675
|
+
*/
|
|
40676
|
+
const onPostUpdatedLocal = (callback) => createLocalPostEventSubscriber('local.post.updated', callback);
|
|
40953
40677
|
|
|
40954
|
-
/* begin_public_function
|
|
40955
|
-
id: post.unflag
|
|
40956
|
-
*/
|
|
40957
40678
|
/**
|
|
40958
40679
|
* ```js
|
|
40959
|
-
* import {
|
|
40960
|
-
* const
|
|
40680
|
+
* import { onLocalPostReactionAdded } from '@amityco/ts-sdk'
|
|
40681
|
+
* const dispose = onPostReactionAdded(post => {
|
|
40682
|
+
* // ...
|
|
40683
|
+
* })
|
|
40961
40684
|
* ```
|
|
40962
40685
|
*
|
|
40963
|
-
*
|
|
40964
|
-
* @returns the unflag post result
|
|
40686
|
+
* Fired when a {@link Amity.InternalPost} has been reacted
|
|
40965
40687
|
*
|
|
40966
|
-
* @
|
|
40967
|
-
* @
|
|
40968
|
-
*
|
|
40969
|
-
|
|
40688
|
+
* @param callback The function to call when the event was fired
|
|
40689
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
40690
|
+
*
|
|
40691
|
+
* @category Post Events
|
|
40692
|
+
*/
|
|
40693
|
+
const onLocalPostReactionAdded = (callback) => {
|
|
40970
40694
|
const client = getActiveClient();
|
|
40971
|
-
|
|
40972
|
-
|
|
40973
|
-
|
|
40974
|
-
|
|
40975
|
-
|
|
40976
|
-
|
|
40977
|
-
|
|
40695
|
+
const filter = ({ post }) => {
|
|
40696
|
+
if (!client.cache) {
|
|
40697
|
+
callback(post);
|
|
40698
|
+
}
|
|
40699
|
+
else {
|
|
40700
|
+
upsertInCache(['post', 'get', post.postId], post);
|
|
40701
|
+
callback(post);
|
|
40702
|
+
}
|
|
40703
|
+
};
|
|
40704
|
+
return createEventSubscriber(client, 'local.post.addReaction', 'local.post.addReaction', filter);
|
|
40978
40705
|
};
|
|
40979
|
-
/* end_public_function */
|
|
40980
40706
|
|
|
40981
|
-
/* begin_public_function
|
|
40982
|
-
id: post.check_flag_by_me
|
|
40983
|
-
*/
|
|
40984
40707
|
/**
|
|
40985
40708
|
* ```js
|
|
40986
|
-
* import {
|
|
40987
|
-
* const
|
|
40709
|
+
* import { onLocalPostReactionRemoved } from '@amityco/ts-sdk'
|
|
40710
|
+
* const dispose = onPostReactionRemoved(post => {
|
|
40711
|
+
* // ...
|
|
40712
|
+
* })
|
|
40988
40713
|
* ```
|
|
40989
40714
|
*
|
|
40990
|
-
*
|
|
40991
|
-
* @returns `true` if the post is flagged by me, `false` if doesn't.
|
|
40715
|
+
* Fired when a {@link Amity.InternalPost} has been reacted
|
|
40992
40716
|
*
|
|
40993
|
-
* @
|
|
40994
|
-
* @
|
|
40995
|
-
*
|
|
40996
|
-
|
|
40717
|
+
* @param callback The function to call when the event was fired
|
|
40718
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
40719
|
+
*
|
|
40720
|
+
* @category Post Events
|
|
40721
|
+
*/
|
|
40722
|
+
const onLocalPostReactionRemoved = (callback) => {
|
|
40997
40723
|
const client = getActiveClient();
|
|
40998
|
-
|
|
40999
|
-
|
|
41000
|
-
|
|
40724
|
+
const filter = ({ post }) => {
|
|
40725
|
+
if (!client.cache) {
|
|
40726
|
+
callback(post);
|
|
40727
|
+
}
|
|
40728
|
+
else {
|
|
40729
|
+
upsertInCache(['post', 'get', post.postId], post);
|
|
40730
|
+
callback(post);
|
|
40731
|
+
}
|
|
40732
|
+
};
|
|
40733
|
+
return createEventSubscriber(client, 'local.post.removeReaction', 'local.post.removeReaction', filter);
|
|
41001
40734
|
};
|
|
41002
|
-
/* end_public_function */
|
|
41003
40735
|
|
|
41004
|
-
/* begin_public_function
|
|
41005
|
-
id: post.create.clip_post
|
|
41006
|
-
*/
|
|
41007
40736
|
/**
|
|
41008
40737
|
* ```js
|
|
41009
|
-
* import {
|
|
41010
|
-
* const
|
|
41011
|
-
*
|
|
41012
|
-
*
|
|
41013
|
-
* dataType: 'clip',
|
|
41014
|
-
* data: { text: 'hello world' },
|
|
41015
|
-
* attachments: [{ type: 'clip', fileId: 'fileId123', displayMode: 'fill', isMuted: false }]
|
|
41016
|
-
* }))
|
|
40738
|
+
* import { onLocalPostDeleted } from '@amityco/ts-sdk'
|
|
40739
|
+
* const dispose = onLocalPostDeleted(post => {
|
|
40740
|
+
* // ...
|
|
40741
|
+
* })
|
|
41017
40742
|
* ```
|
|
41018
40743
|
*
|
|
41019
|
-
*
|
|
40744
|
+
* Fired when a {@link Amity.InternalPost} has been deleted
|
|
41020
40745
|
*
|
|
41021
|
-
* @param
|
|
41022
|
-
* @returns
|
|
40746
|
+
* @param callback The function to call when the event was fired
|
|
40747
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
41023
40748
|
*
|
|
41024
|
-
* @category Post
|
|
41025
|
-
* @async
|
|
40749
|
+
* @category Post Events
|
|
41026
40750
|
*/
|
|
41027
|
-
const
|
|
41028
|
-
const client = getActiveClient();
|
|
41029
|
-
client.log('post/createPost', bundle);
|
|
41030
|
-
const { data: payload } = await client.http.post('/api/v4/posts', bundle);
|
|
41031
|
-
fireEvent('post.created', payload);
|
|
41032
|
-
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
41033
|
-
const cachedAt = client.cache && Date.now();
|
|
41034
|
-
if (client.cache)
|
|
41035
|
-
ingestInCache(data, { cachedAt });
|
|
41036
|
-
const { posts } = data;
|
|
41037
|
-
return {
|
|
41038
|
-
data: LinkedObject.post(posts[0]),
|
|
41039
|
-
cachedAt,
|
|
41040
|
-
};
|
|
41041
|
-
};
|
|
41042
|
-
/* end_public_function */
|
|
40751
|
+
const onLocalPostDeleted = (callback) => createLocalPostEventSubscriber('local.post.deleted', callback);
|
|
41043
40752
|
|
|
41044
40753
|
/* begin_public_function
|
|
41045
40754
|
id: post.get
|
|
@@ -41063,7 +40772,7 @@ const createClipPost = async (bundle) => {
|
|
|
41063
40772
|
*
|
|
41064
40773
|
* @category Post Live Object
|
|
41065
40774
|
*/
|
|
41066
|
-
const getPost = (postId, callback) => {
|
|
40775
|
+
const getPost$1 = (postId, callback) => {
|
|
41067
40776
|
const responder = (snapshot) => {
|
|
41068
40777
|
const { data } = snapshot;
|
|
41069
40778
|
callback(Object.assign(Object.assign({}, snapshot), { data: data ? LinkedObject.post(snapshot.data) : data }));
|
|
@@ -41152,6 +40861,19 @@ class PostPaginationController extends PaginationController {
|
|
|
41152
40861
|
}
|
|
41153
40862
|
}
|
|
41154
40863
|
|
|
40864
|
+
var EnumPostActions;
|
|
40865
|
+
(function (EnumPostActions) {
|
|
40866
|
+
EnumPostActions["OnPostCreated"] = "onPostCreated";
|
|
40867
|
+
EnumPostActions["OnPostUpdated"] = "onPostUpdated";
|
|
40868
|
+
EnumPostActions["OnPostDeleted"] = "onPostDeleted";
|
|
40869
|
+
EnumPostActions["OnPostFlagged"] = "onPostFlagged";
|
|
40870
|
+
EnumPostActions["OnPostUnflagged"] = "onPostUnflagged";
|
|
40871
|
+
EnumPostActions["OnPostReactionAdded"] = "onPostReactionAdded";
|
|
40872
|
+
EnumPostActions["OnPostReactionRemoved"] = "onPostReactionRemoved";
|
|
40873
|
+
EnumPostActions["OnPostApproved"] = "onPostApproved";
|
|
40874
|
+
EnumPostActions["OnPostDeclined"] = "onPostDeclined";
|
|
40875
|
+
})(EnumPostActions || (EnumPostActions = {}));
|
|
40876
|
+
|
|
41155
40877
|
class PostQueryStreamController extends QueryStreamController {
|
|
41156
40878
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
41157
40879
|
super(query, cacheKey);
|
|
@@ -41217,6 +40939,47 @@ class PostQueryStreamController extends QueryStreamController {
|
|
|
41217
40939
|
}
|
|
41218
40940
|
}
|
|
41219
40941
|
|
|
40942
|
+
const getPost = async (postId) => {
|
|
40943
|
+
const client = getActiveClient();
|
|
40944
|
+
client.log('post/getPost', postId);
|
|
40945
|
+
isInTombstone('post', postId);
|
|
40946
|
+
let payload;
|
|
40947
|
+
try {
|
|
40948
|
+
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
40949
|
+
const response = await client.http.get(`/api/v3/posts/${encodeURIComponent(postId)}`);
|
|
40950
|
+
payload = response.data;
|
|
40951
|
+
}
|
|
40952
|
+
catch (error) {
|
|
40953
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
40954
|
+
pushToTombstone('post', postId);
|
|
40955
|
+
}
|
|
40956
|
+
throw error;
|
|
40957
|
+
}
|
|
40958
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
40959
|
+
const cachedAt = client.cache && Date.now();
|
|
40960
|
+
if (client.cache)
|
|
40961
|
+
ingestInCache(data, { cachedAt });
|
|
40962
|
+
const { posts } = data;
|
|
40963
|
+
const result = posts.find(post => post.postId === postId);
|
|
40964
|
+
return {
|
|
40965
|
+
data: result,
|
|
40966
|
+
cachedAt,
|
|
40967
|
+
};
|
|
40968
|
+
};
|
|
40969
|
+
getPost.locally = (postId) => {
|
|
40970
|
+
const client = getActiveClient();
|
|
40971
|
+
client.log('post/getPost.locally', postId);
|
|
40972
|
+
if (!client.cache)
|
|
40973
|
+
return;
|
|
40974
|
+
const cached = pullFromCache(['post', 'get', postId]);
|
|
40975
|
+
if (!cached)
|
|
40976
|
+
return;
|
|
40977
|
+
return {
|
|
40978
|
+
data: cached.data,
|
|
40979
|
+
cachedAt: cached.cachedAt,
|
|
40980
|
+
};
|
|
40981
|
+
};
|
|
40982
|
+
|
|
41220
40983
|
class PostLiveCollectionController extends LiveCollectionController {
|
|
41221
40984
|
constructor(query, callback) {
|
|
41222
40985
|
const queryStreamId = hash(query);
|
|
@@ -41266,7 +41029,7 @@ class PostLiveCollectionController extends LiveCollectionController {
|
|
|
41266
41029
|
const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
41267
41030
|
if (!currentCollection || currentCollection.data.includes(comment.referenceId))
|
|
41268
41031
|
return;
|
|
41269
|
-
await getPost
|
|
41032
|
+
await getPost(comment.referenceId);
|
|
41270
41033
|
callback(comment);
|
|
41271
41034
|
});
|
|
41272
41035
|
}, 'referenceId', 'post'),
|
|
@@ -41279,7 +41042,7 @@ class PostLiveCollectionController extends LiveCollectionController {
|
|
|
41279
41042
|
const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
41280
41043
|
if (!currentCollection || currentCollection.data.includes(comment.referenceId))
|
|
41281
41044
|
return;
|
|
41282
|
-
await getPost
|
|
41045
|
+
await getPost(comment.referenceId);
|
|
41283
41046
|
callback(comment);
|
|
41284
41047
|
});
|
|
41285
41048
|
}, 'referenceId', 'post'),
|
|
@@ -41905,7 +41668,7 @@ var index$8 = /*#__PURE__*/Object.freeze({
|
|
|
41905
41668
|
onPostUnflagged: onPostUnflagged,
|
|
41906
41669
|
onPostReactionAdded: onPostReactionAdded,
|
|
41907
41670
|
onPostReactionRemoved: onPostReactionRemoved,
|
|
41908
|
-
getPost: getPost,
|
|
41671
|
+
getPost: getPost$1,
|
|
41909
41672
|
getPosts: getPosts,
|
|
41910
41673
|
getPinnedPosts: getPinnedPosts,
|
|
41911
41674
|
getGlobalPinnedPosts: getGlobalPinnedPosts,
|
|
@@ -45103,4 +44866,4 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
45103
44866
|
getReactions: getReactions
|
|
45104
44867
|
});
|
|
45105
44868
|
|
|
45106
|
-
export { API_REGIONS, index$3 as AdRepository, index$b as CategoryRepository, index$f as ChannelRepository, index$o as Client, index$
|
|
44869
|
+
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 };
|