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