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