@amityco/ts-sdk 7.8.0 → 7.8.1-5d16a58a.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/.env +26 -26
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/feed.d.ts +31 -0
- 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 +21 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/feed.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/index.d.ts +1 -0
- 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 +1 -0
- 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/feedRepository/observers/getUserFeed/LiveCollectionController.d.ts +14 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/LiveCollectionController.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/LiveCollectionController.js +129 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/LiveCollectionController.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/PaginationController.d.ts +5 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/PaginationController.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/PaginationController.js +15 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/PaginationController.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/QueryStreamController.d.ts +15 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/QueryStreamController.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/QueryStreamController.js +78 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/QueryStreamController.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed.d.ts +23 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed.js +46 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/index.d.ts +2 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/index.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/index.js +2 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/index.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/tsconfig.tsbuildinfo +1 -1
- package/dist/@types/domains/feed.d.ts +31 -0
- package/dist/@types/domains/feed.d.ts.map +1 -1
- package/dist/feedRepository/index.d.ts +1 -0
- package/dist/feedRepository/index.d.ts.map +1 -1
- package/dist/feedRepository/observers/getUserFeed/LiveCollectionController.d.ts +14 -0
- package/dist/feedRepository/observers/getUserFeed/LiveCollectionController.d.ts.map +1 -0
- package/dist/feedRepository/observers/getUserFeed/PaginationController.d.ts +5 -0
- package/dist/feedRepository/observers/getUserFeed/PaginationController.d.ts.map +1 -0
- package/dist/feedRepository/observers/getUserFeed/QueryStreamController.d.ts +15 -0
- package/dist/feedRepository/observers/getUserFeed/QueryStreamController.d.ts.map +1 -0
- package/dist/feedRepository/observers/getUserFeed.d.ts +23 -0
- package/dist/feedRepository/observers/getUserFeed.d.ts.map +1 -0
- package/dist/feedRepository/observers/index.d.ts +2 -0
- package/dist/feedRepository/observers/index.d.ts.map +1 -0
- package/dist/index.cjs.js +1297 -1060
- package/dist/index.esm.js +1296 -1059
- package/dist/index.umd.js +4 -4
- package/package.json +1 -1
- package/src/@types/domains/feed.ts +43 -0
- package/src/feedRepository/index.ts +1 -0
- package/src/feedRepository/observers/getUserFeed/LiveCollectionController.ts +192 -0
- package/src/feedRepository/observers/getUserFeed/PaginationController.ts +37 -0
- package/src/feedRepository/observers/getUserFeed/QueryStreamController.ts +119 -0
- package/src/feedRepository/observers/getUserFeed.ts +56 -0
- package/src/feedRepository/observers/index.ts +1 -0
- package/tsconfig.tsbuildinfo +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -23176,1010 +23176,1035 @@ getCustomRankingGlobalFeed.locally = (query) => {
|
|
|
23176
23176
|
: undefined;
|
|
23177
23177
|
};
|
|
23178
23178
|
|
|
23179
|
-
|
|
23180
|
-
|
|
23181
|
-
|
|
23182
|
-
|
|
23183
|
-
}
|
|
23179
|
+
class UserFeedPaginationController extends PaginationController {
|
|
23180
|
+
async getRequest(queryParams, token) {
|
|
23181
|
+
const { userId, feedSources, dataTypes, includeDeleted, matchingOnlyParentPost, limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["userId", "feedSources", "dataTypes", "includeDeleted", "matchingOnlyParentPost", "limit"]);
|
|
23182
|
+
const options = token ? { token } : { limit };
|
|
23183
|
+
const { data: queryResponse } = await this.http.get(`/api/v4/user-feeds/${userId}`, {
|
|
23184
|
+
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) }),
|
|
23185
|
+
});
|
|
23186
|
+
return queryResponse;
|
|
23187
|
+
}
|
|
23188
|
+
}
|
|
23189
|
+
|
|
23190
|
+
var EnumPostActions;
|
|
23191
|
+
(function (EnumPostActions) {
|
|
23192
|
+
EnumPostActions["OnPostCreated"] = "onPostCreated";
|
|
23193
|
+
EnumPostActions["OnPostUpdated"] = "onPostUpdated";
|
|
23194
|
+
EnumPostActions["OnPostDeleted"] = "onPostDeleted";
|
|
23195
|
+
EnumPostActions["OnPostFlagged"] = "onPostFlagged";
|
|
23196
|
+
EnumPostActions["OnPostUnflagged"] = "onPostUnflagged";
|
|
23197
|
+
EnumPostActions["OnPostReactionAdded"] = "onPostReactionAdded";
|
|
23198
|
+
EnumPostActions["OnPostReactionRemoved"] = "onPostReactionRemoved";
|
|
23199
|
+
EnumPostActions["OnPostApproved"] = "onPostApproved";
|
|
23200
|
+
EnumPostActions["OnPostDeclined"] = "onPostDeclined";
|
|
23201
|
+
})(EnumPostActions || (EnumPostActions = {}));
|
|
23202
|
+
|
|
23203
|
+
class UserFeedQueryStreamController extends QueryStreamController {
|
|
23204
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
23205
|
+
super(query, cacheKey);
|
|
23206
|
+
this.notifyChange = notifyChange;
|
|
23207
|
+
this.preparePayload = preparePayload;
|
|
23208
|
+
}
|
|
23209
|
+
async saveToMainDB(response) {
|
|
23210
|
+
const processedPayload = await this.preparePayload(response);
|
|
23211
|
+
const client = getActiveClient();
|
|
23212
|
+
const cachedAt = client.cache && Date.now();
|
|
23213
|
+
if (client.cache) {
|
|
23214
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
23215
|
+
}
|
|
23216
|
+
}
|
|
23217
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
23218
|
+
var _a, _b;
|
|
23219
|
+
if (refresh) {
|
|
23220
|
+
pushToCache(this.cacheKey, {
|
|
23221
|
+
data: response.posts.map(getResolver('post')),
|
|
23222
|
+
});
|
|
23223
|
+
}
|
|
23224
|
+
else {
|
|
23225
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23226
|
+
const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
23227
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
|
|
23228
|
+
}
|
|
23229
|
+
}
|
|
23230
|
+
reactor(action) {
|
|
23231
|
+
return (post) => {
|
|
23232
|
+
var _a, _b;
|
|
23233
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23234
|
+
if (!collection)
|
|
23235
|
+
return;
|
|
23236
|
+
// if the collection is parent post collection and
|
|
23237
|
+
// post is not included in the collection or post is child post
|
|
23238
|
+
if ((!this.query.dataTypes || this.query.dataTypes.length === 0) &&
|
|
23239
|
+
!collection.data.includes(post.parentPostId ? post.parentPostId : post.postId))
|
|
23240
|
+
return;
|
|
23241
|
+
if (action === EnumPostActions.OnPostDeleted) {
|
|
23242
|
+
collection.data = collection.data.filter(postId => postId !== post.postId);
|
|
23243
|
+
}
|
|
23244
|
+
if (post.parentPostId && post.isDeleted) {
|
|
23245
|
+
const parentPost = (_b = pullFromCache([
|
|
23246
|
+
'post',
|
|
23247
|
+
'get',
|
|
23248
|
+
post.parentPostId,
|
|
23249
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
23250
|
+
if (!parentPost)
|
|
23251
|
+
return;
|
|
23252
|
+
parentPost.children = parentPost.children.filter(childId => childId !== post.postId);
|
|
23253
|
+
pushToCache(['post', 'get', parentPost.postId], parentPost);
|
|
23254
|
+
}
|
|
23255
|
+
if (action === EnumPostActions.OnPostDeclined) {
|
|
23256
|
+
collection.data = collection.data.filter(postId => postId !== post.postId);
|
|
23257
|
+
}
|
|
23258
|
+
if (action === EnumPostActions.OnPostCreated || action === EnumPostActions.OnPostApproved) {
|
|
23259
|
+
if (this.query.dataTypes &&
|
|
23260
|
+
this.query.dataTypes.length > 0 &&
|
|
23261
|
+
!this.query.dataTypes.includes(post.dataType)) {
|
|
23262
|
+
return;
|
|
23263
|
+
}
|
|
23264
|
+
collection.data = [...new Set([post.postId, ...collection.data])];
|
|
23265
|
+
}
|
|
23266
|
+
pushToCache(this.cacheKey, collection);
|
|
23267
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
23268
|
+
};
|
|
23269
|
+
}
|
|
23270
|
+
subscribeRTE(createSubscriber) {
|
|
23271
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
23272
|
+
}
|
|
23273
|
+
}
|
|
23184
23274
|
|
|
23185
23275
|
/* begin_public_function
|
|
23186
|
-
id:
|
|
23276
|
+
id: comment.get_by_ids
|
|
23187
23277
|
*/
|
|
23188
23278
|
/**
|
|
23189
23279
|
* ```js
|
|
23190
|
-
* import {
|
|
23191
|
-
* const
|
|
23280
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
23281
|
+
* const comments = await CommentRepository.getCommentByIds(['foo', 'bar'])
|
|
23192
23282
|
* ```
|
|
23193
23283
|
*
|
|
23194
|
-
* Fetches a collection of {@link Amity.
|
|
23284
|
+
* Fetches a collection of {@link Amity.Comment} objects
|
|
23195
23285
|
*
|
|
23196
|
-
* @param
|
|
23197
|
-
* @returns the associated collection of {@link Amity.
|
|
23286
|
+
* @param commentIds the IDs of the {@link Amity.Comment} to fetch
|
|
23287
|
+
* @returns the associated collection of {@link Amity.Comment} objects
|
|
23198
23288
|
*
|
|
23199
|
-
* @category
|
|
23289
|
+
* @category Comment API
|
|
23200
23290
|
* @async
|
|
23201
23291
|
*/
|
|
23202
|
-
const
|
|
23292
|
+
const getCommentByIds = async (commentIds) => {
|
|
23203
23293
|
const client = getActiveClient();
|
|
23204
|
-
client.log('
|
|
23205
|
-
const
|
|
23206
|
-
let
|
|
23294
|
+
client.log('comment/getCommentByIds', commentIds);
|
|
23295
|
+
const encodedCommentIds = commentIds.map(commentId => encodeURIComponent(commentId));
|
|
23296
|
+
let data;
|
|
23207
23297
|
try {
|
|
23208
23298
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
23209
|
-
const response = await client.http.get(`/api/v3/
|
|
23210
|
-
params: {
|
|
23299
|
+
const response = await client.http.get(`/api/v3/comments/list`, {
|
|
23300
|
+
params: { commentIds: encodedCommentIds },
|
|
23211
23301
|
});
|
|
23212
|
-
|
|
23302
|
+
data = response.data;
|
|
23213
23303
|
}
|
|
23214
23304
|
catch (error) {
|
|
23215
|
-
|
|
23305
|
+
commentIds.forEach(commentId => {
|
|
23216
23306
|
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
23217
|
-
pushToTombstone('
|
|
23307
|
+
pushToTombstone('comment', commentId);
|
|
23218
23308
|
}
|
|
23219
23309
|
});
|
|
23220
23310
|
throw error;
|
|
23221
23311
|
}
|
|
23222
|
-
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
23223
23312
|
const cachedAt = client.cache && Date.now();
|
|
23224
23313
|
if (client.cache)
|
|
23225
23314
|
ingestInCache(data, { cachedAt });
|
|
23226
23315
|
return {
|
|
23227
|
-
data: data.
|
|
23316
|
+
data: data.comments.map(comment => LinkedObject.comment(comment)),
|
|
23228
23317
|
cachedAt,
|
|
23229
23318
|
};
|
|
23230
23319
|
};
|
|
23231
23320
|
/* end_public_function */
|
|
23232
23321
|
/**
|
|
23233
23322
|
* ```js
|
|
23234
|
-
* import {
|
|
23235
|
-
* const
|
|
23323
|
+
* import { getCommentByIds } from '@amityco/ts-sdk'
|
|
23324
|
+
* const comments = getCommentByIds.locally(['foo', 'bar'])
|
|
23236
23325
|
* ```
|
|
23237
23326
|
*
|
|
23238
|
-
* Fetches a collection of {@link Amity.
|
|
23327
|
+
* Fetches a collection of {@link Amity.Comment} objects from cache
|
|
23239
23328
|
*
|
|
23240
|
-
* @param
|
|
23241
|
-
* @returns the associated collection of {@link Amity.
|
|
23329
|
+
* @param commentIds the IDs of the {@link Amity.Comment} to fetch
|
|
23330
|
+
* @returns the associated collection of {@link Amity.Comment} objects
|
|
23242
23331
|
*
|
|
23243
|
-
* @category
|
|
23332
|
+
* @category Comment API
|
|
23244
23333
|
*/
|
|
23245
|
-
|
|
23334
|
+
getCommentByIds.locally = (commentIds) => {
|
|
23246
23335
|
var _a;
|
|
23247
23336
|
const client = getActiveClient();
|
|
23248
|
-
client.log('
|
|
23337
|
+
client.log('comment/getCommentByIds.locally', commentIds);
|
|
23249
23338
|
if (!client.cache)
|
|
23250
23339
|
return;
|
|
23251
|
-
const cached =
|
|
23252
|
-
.map(
|
|
23340
|
+
const cached = commentIds
|
|
23341
|
+
.map(commentId => pullFromCache(['comment', 'get', commentId]))
|
|
23253
23342
|
.filter(Boolean);
|
|
23254
|
-
const
|
|
23343
|
+
const comments = cached.map(({ data }) => data);
|
|
23255
23344
|
const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
|
|
23256
|
-
if ((cached === null || cached === void 0 ? void 0 : cached.length) <
|
|
23345
|
+
if ((cached === null || cached === void 0 ? void 0 : cached.length) < commentIds.length)
|
|
23257
23346
|
return;
|
|
23258
23347
|
return {
|
|
23259
|
-
data:
|
|
23348
|
+
data: comments.map(comment => LinkedObject.comment(comment)),
|
|
23260
23349
|
cachedAt: oldest.cachedAt,
|
|
23261
23350
|
};
|
|
23262
23351
|
};
|
|
23263
23352
|
|
|
23264
23353
|
/* begin_public_function
|
|
23265
|
-
id:
|
|
23354
|
+
id: comment.create
|
|
23266
23355
|
*/
|
|
23267
23356
|
/**
|
|
23268
23357
|
* ```js
|
|
23269
|
-
* import {
|
|
23270
|
-
* const
|
|
23271
|
-
* targetType: 'user',
|
|
23272
|
-
* targetId: 'foobar',
|
|
23273
|
-
* data: { text: 'hello world' }
|
|
23274
|
-
* }))
|
|
23358
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
23359
|
+
* const newComment = await CommentRepository.createComment(bundle)
|
|
23275
23360
|
* ```
|
|
23276
23361
|
*
|
|
23277
|
-
* Creates an {@link Amity.
|
|
23362
|
+
* Creates an {@link Amity.Comment}
|
|
23278
23363
|
*
|
|
23279
|
-
* @param bundle The data necessary to create a new {@link Amity.
|
|
23280
|
-
* @returns The newly created {@link Amity.
|
|
23364
|
+
* @param bundle The data necessary to create a new {@link Amity.Comment}
|
|
23365
|
+
* @returns The newly created {@link Amity.Comment}
|
|
23281
23366
|
*
|
|
23282
|
-
* @category
|
|
23367
|
+
* @category Comment API
|
|
23283
23368
|
* @async
|
|
23284
23369
|
*/
|
|
23285
|
-
const
|
|
23370
|
+
const createComment = async (bundle) => {
|
|
23371
|
+
var _a;
|
|
23286
23372
|
const client = getActiveClient();
|
|
23287
|
-
client.log('
|
|
23288
|
-
|
|
23289
|
-
|
|
23290
|
-
|
|
23291
|
-
|
|
23292
|
-
|
|
23293
|
-
fireEvent('post.created', payload);
|
|
23294
|
-
const data = preparePostPayload(payload);
|
|
23373
|
+
client.log('comment/createComment', bundle);
|
|
23374
|
+
const { data } = await client.http.post('/api/v3/comments', bundle);
|
|
23375
|
+
const { comments } = data;
|
|
23376
|
+
// BE always returns an array of comments If it got record 0 from BE it might have a problem on creation logic
|
|
23377
|
+
if (comments.length === 0)
|
|
23378
|
+
throw new Error('Comment not created');
|
|
23295
23379
|
const cachedAt = client.cache && Date.now();
|
|
23296
23380
|
if (client.cache)
|
|
23297
23381
|
ingestInCache(data, { cachedAt });
|
|
23298
|
-
|
|
23382
|
+
if (['post', 'content'].includes(bundle.referenceType)) {
|
|
23383
|
+
const post = (_a = pullFromCache(['post', 'get', bundle.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23384
|
+
if (post) {
|
|
23385
|
+
post.commentsCount += 1;
|
|
23386
|
+
fireEvent('local.post.updated', {
|
|
23387
|
+
posts: [post],
|
|
23388
|
+
categories: [],
|
|
23389
|
+
comments: [],
|
|
23390
|
+
communities: [],
|
|
23391
|
+
communityUsers: data.communityUsers,
|
|
23392
|
+
feeds: [],
|
|
23393
|
+
files: data.files,
|
|
23394
|
+
postChildren: [],
|
|
23395
|
+
users: data.users,
|
|
23396
|
+
videoStreamings: [],
|
|
23397
|
+
});
|
|
23398
|
+
}
|
|
23399
|
+
}
|
|
23400
|
+
else if (bundle.referenceType === 'story') {
|
|
23401
|
+
const storyIndex = pullFromCache([
|
|
23402
|
+
"story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
|
|
23403
|
+
bundle.referenceId,
|
|
23404
|
+
]);
|
|
23405
|
+
if (storyIndex === null || storyIndex === void 0 ? void 0 : storyIndex.data) {
|
|
23406
|
+
const cacheStory = pullFromCache([
|
|
23407
|
+
"story" /* STORY_KEY_CACHE.STORY */,
|
|
23408
|
+
'get',
|
|
23409
|
+
storyIndex.data,
|
|
23410
|
+
]);
|
|
23411
|
+
if (cacheStory === null || cacheStory === void 0 ? void 0 : cacheStory.data) {
|
|
23412
|
+
fireEvent('story.updated', {
|
|
23413
|
+
stories: [
|
|
23414
|
+
Object.assign(Object.assign({}, cacheStory.data), { commentsCount: cacheStory.data.commentsCount + 1, comments: [...new Set([...cacheStory.data.comments, comments[0].commentId])] }),
|
|
23415
|
+
],
|
|
23416
|
+
categories: [],
|
|
23417
|
+
comments,
|
|
23418
|
+
communities: [],
|
|
23419
|
+
communityUsers: data.communityUsers,
|
|
23420
|
+
files: data.files,
|
|
23421
|
+
users: data.users,
|
|
23422
|
+
});
|
|
23423
|
+
}
|
|
23424
|
+
}
|
|
23425
|
+
}
|
|
23426
|
+
fireEvent('local.comment.created', data);
|
|
23299
23427
|
return {
|
|
23300
|
-
data: LinkedObject.
|
|
23428
|
+
data: LinkedObject.comment(comments[0]),
|
|
23301
23429
|
cachedAt,
|
|
23302
23430
|
};
|
|
23303
23431
|
};
|
|
23304
23432
|
/* end_public_function */
|
|
23305
23433
|
|
|
23306
23434
|
/* begin_public_function
|
|
23307
|
-
id:
|
|
23435
|
+
id: comment.update_comment
|
|
23308
23436
|
*/
|
|
23309
23437
|
/**
|
|
23310
23438
|
* ```js
|
|
23311
|
-
* import {
|
|
23312
|
-
* const updated = await
|
|
23439
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
23440
|
+
* const updated = await CommentRepository.updateComment(commentId, {
|
|
23313
23441
|
* data: { text: 'hello world' }
|
|
23314
23442
|
* })
|
|
23315
23443
|
* ```
|
|
23316
23444
|
*
|
|
23317
|
-
* Updates an {@link Amity.
|
|
23445
|
+
* Updates an {@link Amity.Comment}
|
|
23318
23446
|
*
|
|
23319
|
-
* @param
|
|
23447
|
+
* @param commentId The ID of the {@link Amity.Comment} to edit
|
|
23320
23448
|
* @param patch The patch data to apply
|
|
23321
|
-
* @returns the updated {@link Amity.
|
|
23449
|
+
* @returns the updated {@link Amity.Comment} object
|
|
23322
23450
|
*
|
|
23323
|
-
* @category
|
|
23451
|
+
* @category Comment API
|
|
23324
23452
|
* @async
|
|
23325
23453
|
*/
|
|
23326
|
-
const
|
|
23454
|
+
const updateComment = async (commentId, patch) => {
|
|
23327
23455
|
const client = getActiveClient();
|
|
23328
|
-
client.log('user/
|
|
23329
|
-
const { data
|
|
23330
|
-
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
23456
|
+
client.log('user/updateComment', patch);
|
|
23457
|
+
const { data } = await client.http.put(`/api/v3/comments/${encodeURIComponent(commentId)}`, patch);
|
|
23331
23458
|
const cachedAt = client.cache && Date.now();
|
|
23332
23459
|
if (client.cache)
|
|
23333
23460
|
ingestInCache(data, { cachedAt });
|
|
23334
|
-
fireEvent('
|
|
23335
|
-
const {
|
|
23461
|
+
fireEvent('comment.updated', data);
|
|
23462
|
+
const { comments } = data;
|
|
23336
23463
|
return {
|
|
23337
|
-
data: LinkedObject.
|
|
23464
|
+
data: LinkedObject.comment(comments.find(comment => comment.commentId === commentId)),
|
|
23338
23465
|
cachedAt,
|
|
23339
23466
|
};
|
|
23340
23467
|
};
|
|
23341
23468
|
/* end_public_function */
|
|
23342
23469
|
|
|
23470
|
+
// Due to we have optimistic logic, we will use referenceId as a id in SDK instead of storyId
|
|
23471
|
+
const applyMissingField = (rawData, isCreated = false) => {
|
|
23472
|
+
const { storyId, referenceId } = rawData;
|
|
23473
|
+
if (!isCreated) {
|
|
23474
|
+
if (referenceId)
|
|
23475
|
+
return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */ });
|
|
23476
|
+
}
|
|
23477
|
+
return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */, referenceId: storyId });
|
|
23478
|
+
};
|
|
23479
|
+
const convertRawStoryToInternal = (data, isCreated = false) => {
|
|
23480
|
+
const { stories } = data;
|
|
23481
|
+
const storiesData = stories.map(story => applyMissingField(story, isCreated));
|
|
23482
|
+
return Object.assign(Object.assign({}, data), { stories: storiesData });
|
|
23483
|
+
};
|
|
23484
|
+
|
|
23485
|
+
const getStoryByStoryId$1 = async (storyId) => {
|
|
23486
|
+
const client = getActiveClient();
|
|
23487
|
+
client.log('story/getStoryByStoryId', storyId);
|
|
23488
|
+
// Get story referenceId from cache
|
|
23489
|
+
const cacheReferenceId = pullFromCache([
|
|
23490
|
+
"story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
|
|
23491
|
+
storyId,
|
|
23492
|
+
]);
|
|
23493
|
+
if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
|
|
23494
|
+
const { data: referenceId } = cacheReferenceId;
|
|
23495
|
+
isInTombstone('story', referenceId);
|
|
23496
|
+
}
|
|
23497
|
+
let data;
|
|
23498
|
+
try {
|
|
23499
|
+
const response = await client.http.get(`/api/v4/stories/${storyId}`);
|
|
23500
|
+
data = convertRawStoryToInternal(response.data);
|
|
23501
|
+
}
|
|
23502
|
+
catch (error) {
|
|
23503
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
23504
|
+
pushToTombstone('story', storyId);
|
|
23505
|
+
}
|
|
23506
|
+
throw error;
|
|
23507
|
+
}
|
|
23508
|
+
const cachedAt = client.cache && Date.now();
|
|
23509
|
+
if (client.cache) {
|
|
23510
|
+
ingestInCache(data, { cachedAt });
|
|
23511
|
+
}
|
|
23512
|
+
return {
|
|
23513
|
+
data: data.stories[0],
|
|
23514
|
+
cachedAt,
|
|
23515
|
+
};
|
|
23516
|
+
};
|
|
23517
|
+
getStoryByStoryId$1.locally = (storyId) => {
|
|
23518
|
+
const client = getActiveClient();
|
|
23519
|
+
client.log('story/getStorybyStoryId', storyId);
|
|
23520
|
+
// Get story referenceId from cache
|
|
23521
|
+
const cacheReferenceId = pullFromCache([
|
|
23522
|
+
"story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
|
|
23523
|
+
storyId,
|
|
23524
|
+
]);
|
|
23525
|
+
if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
|
|
23526
|
+
const { data: referenceId } = cacheReferenceId;
|
|
23527
|
+
isInTombstone('story', referenceId);
|
|
23528
|
+
}
|
|
23529
|
+
const cachedAt = client.cache && Date.now();
|
|
23530
|
+
const storyCache = pullFromCache(['story', 'get', storyId]);
|
|
23531
|
+
if (!storyCache)
|
|
23532
|
+
return;
|
|
23533
|
+
return {
|
|
23534
|
+
data: storyCache.data,
|
|
23535
|
+
cachedAt,
|
|
23536
|
+
};
|
|
23537
|
+
};
|
|
23538
|
+
|
|
23539
|
+
/* begin_public_function
|
|
23540
|
+
id: comment.soft_delete, comment.hard_delete
|
|
23541
|
+
*/
|
|
23343
23542
|
/**
|
|
23344
23543
|
* ```js
|
|
23345
|
-
* import {
|
|
23346
|
-
* const success = await
|
|
23544
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
23545
|
+
* const success = await CommentRepository.deleteComment('foobar')
|
|
23347
23546
|
* ```
|
|
23348
23547
|
*
|
|
23349
|
-
* Deletes a {@link Amity.
|
|
23548
|
+
* Deletes a {@link Amity.Comment}
|
|
23350
23549
|
*
|
|
23351
|
-
* @param
|
|
23352
|
-
* @return A success boolean if the {@link Amity.
|
|
23550
|
+
* @param commentId The {@link Amity.Comment} ID to delete
|
|
23551
|
+
* @return A success boolean if the {@link Amity.Comment} was deleted
|
|
23353
23552
|
*
|
|
23354
|
-
* @
|
|
23553
|
+
* @category Comment API
|
|
23355
23554
|
* @async
|
|
23356
23555
|
*/
|
|
23357
|
-
const
|
|
23556
|
+
const deleteComment = async (commentId, permanent = false) => {
|
|
23358
23557
|
var _a;
|
|
23359
23558
|
const client = getActiveClient();
|
|
23360
|
-
const
|
|
23361
|
-
|
|
23559
|
+
const comment = await getComment$2(commentId);
|
|
23560
|
+
// API-FIX: This endpoint has not been implemented yet.
|
|
23561
|
+
await client.http.delete(`/api/v4/comments/${encodeURIComponent(commentId)}`, {
|
|
23362
23562
|
params: {
|
|
23363
|
-
|
|
23563
|
+
commentId,
|
|
23364
23564
|
permanent,
|
|
23365
23565
|
},
|
|
23366
23566
|
});
|
|
23367
|
-
//
|
|
23368
|
-
|
|
23369
|
-
|
|
23370
|
-
|
|
23371
|
-
|
|
23372
|
-
|
|
23373
|
-
const communityUsersCache = (_a = queryCache(['communityUsers', 'get'])) !== null && _a !== void 0 ? _a : [];
|
|
23374
|
-
const communityUsers = communityUsersCache
|
|
23375
|
-
.filter(({ key }) => {
|
|
23376
|
-
// cache key is ['communityUsers', 'get', `${communityId}#`${userId}`}]
|
|
23377
|
-
if (key[0] !== 'communityUsers')
|
|
23378
|
-
return false;
|
|
23379
|
-
if (key[1] !== 'get')
|
|
23380
|
-
return false;
|
|
23381
|
-
if (typeof key[2] === 'string')
|
|
23382
|
-
return key[2].includes(community.data.communityId);
|
|
23383
|
-
return false;
|
|
23384
|
-
})
|
|
23385
|
-
.map(({ data }) => data);
|
|
23386
|
-
fireEvent('community.updated', {
|
|
23387
|
-
communities: [community.data],
|
|
23567
|
+
// to support hard deletion
|
|
23568
|
+
const deleted = Object.assign(Object.assign({}, comment.data), { isDeleted: true });
|
|
23569
|
+
if (comment.data.referenceType === 'story') {
|
|
23570
|
+
const story = await getStoryByStoryId$1(comment.data.referenceId);
|
|
23571
|
+
fireEvent('local.story.updated', {
|
|
23572
|
+
stories: [story.data],
|
|
23388
23573
|
categories: [],
|
|
23389
|
-
|
|
23390
|
-
|
|
23574
|
+
comments: [],
|
|
23575
|
+
communities: [],
|
|
23576
|
+
communityUsers: [],
|
|
23391
23577
|
files: [],
|
|
23392
23578
|
users: [],
|
|
23393
23579
|
});
|
|
23394
23580
|
}
|
|
23395
|
-
// to support hard deletion
|
|
23396
|
-
const deleted = Object.assign(Object.assign({}, post.data), { isDeleted: true });
|
|
23397
|
-
if (permanent) {
|
|
23398
|
-
setTimeout(() => {
|
|
23399
|
-
pushToTombstone('post', postId);
|
|
23400
|
-
}, 0);
|
|
23401
|
-
}
|
|
23402
23581
|
else {
|
|
23403
|
-
|
|
23582
|
+
const post = (_a = pullFromCache(['post', 'get', comment.data.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23583
|
+
if (post) {
|
|
23584
|
+
let removeCount;
|
|
23585
|
+
if (!deleted.parentId) {
|
|
23586
|
+
// NOTE: delete the parent comment will remove all children comments
|
|
23587
|
+
removeCount = deleted.childrenNumber + 1;
|
|
23588
|
+
}
|
|
23589
|
+
else
|
|
23590
|
+
removeCount = 1;
|
|
23591
|
+
post.commentsCount -= removeCount;
|
|
23592
|
+
fireEvent('local.post.updated', {
|
|
23593
|
+
posts: [post],
|
|
23594
|
+
categories: [],
|
|
23595
|
+
comments: [],
|
|
23596
|
+
communities: [],
|
|
23597
|
+
communityUsers: [],
|
|
23598
|
+
feeds: [],
|
|
23599
|
+
files: [],
|
|
23600
|
+
postChildren: [],
|
|
23601
|
+
users: [],
|
|
23602
|
+
videoStreamings: [],
|
|
23603
|
+
});
|
|
23604
|
+
}
|
|
23404
23605
|
}
|
|
23405
|
-
fireEvent('local.
|
|
23406
|
-
|
|
23407
|
-
|
|
23408
|
-
comments: [],
|
|
23409
|
-
communities: [],
|
|
23410
|
-
communityUsers: [],
|
|
23411
|
-
feeds: [],
|
|
23606
|
+
fireEvent('local.comment.deleted', {
|
|
23607
|
+
comments: [deleted],
|
|
23608
|
+
commentChildren: [],
|
|
23412
23609
|
files: [],
|
|
23413
|
-
postChildren: [],
|
|
23414
23610
|
users: [],
|
|
23415
|
-
|
|
23611
|
+
communityUsers: [],
|
|
23416
23612
|
});
|
|
23417
|
-
|
|
23613
|
+
if (permanent) {
|
|
23614
|
+
scheduleTask(() => pushToTombstone('comment', commentId));
|
|
23615
|
+
}
|
|
23616
|
+
else {
|
|
23617
|
+
upsertInCache(['comment', 'get', commentId], { isDeleted: true });
|
|
23618
|
+
}
|
|
23619
|
+
return deleted;
|
|
23418
23620
|
};
|
|
23621
|
+
/* end_public_function */
|
|
23419
23622
|
|
|
23420
23623
|
/* begin_public_function
|
|
23421
|
-
id:
|
|
23624
|
+
id: comment.soft_delete
|
|
23422
23625
|
*/
|
|
23423
23626
|
/**
|
|
23424
23627
|
* ```js
|
|
23425
|
-
* import {
|
|
23426
|
-
* const success = await
|
|
23628
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
23629
|
+
* const success = await CommentRepository.softDeleteComment('foobar')
|
|
23427
23630
|
* ```
|
|
23428
23631
|
*
|
|
23429
|
-
*
|
|
23632
|
+
* Deletes a {@link Amity.Comment}
|
|
23430
23633
|
*
|
|
23431
|
-
* @param
|
|
23432
|
-
* @return A success boolean if the {@link Amity.
|
|
23634
|
+
* @param commentId The {@link Amity.Comment} ID to delete
|
|
23635
|
+
* @return A success boolean if the {@link Amity.Comment} was deleted
|
|
23433
23636
|
*
|
|
23434
|
-
* @category
|
|
23637
|
+
* @category Comment API
|
|
23435
23638
|
* @async
|
|
23436
23639
|
*/
|
|
23437
|
-
const
|
|
23640
|
+
const softDeleteComment = async (commentId) => {
|
|
23438
23641
|
const client = getActiveClient();
|
|
23439
|
-
client.log('
|
|
23440
|
-
const softDeleted =
|
|
23441
|
-
return
|
|
23642
|
+
client.log('comment/softDeleteComment', commentId);
|
|
23643
|
+
const softDeleted = deleteComment(commentId);
|
|
23644
|
+
return softDeleted;
|
|
23442
23645
|
};
|
|
23443
23646
|
/* end_public_function */
|
|
23444
23647
|
|
|
23445
23648
|
/* begin_public_function
|
|
23446
|
-
id:
|
|
23649
|
+
id: comment.hard_delete
|
|
23447
23650
|
*/
|
|
23448
23651
|
/**
|
|
23449
23652
|
* ```js
|
|
23450
|
-
* import {
|
|
23451
|
-
* const success = await
|
|
23653
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
23654
|
+
* const success = await CommentRepository.hardDeleteComment('foobar')
|
|
23452
23655
|
* ```
|
|
23453
23656
|
*
|
|
23454
|
-
*
|
|
23657
|
+
* Deletes a {@link Amity.Comment}
|
|
23455
23658
|
*
|
|
23456
|
-
* @param
|
|
23457
|
-
* @return A success boolean if the {@link Amity.
|
|
23659
|
+
* @param commentId The {@link Amity.Comment} ID to delete
|
|
23660
|
+
* @return A success boolean if the {@link Amity.Comment} was deleted
|
|
23458
23661
|
*
|
|
23459
|
-
* @category
|
|
23662
|
+
* @category Comment API
|
|
23460
23663
|
* @async
|
|
23461
23664
|
*/
|
|
23462
|
-
const
|
|
23665
|
+
const hardDeleteComment = async (commentId) => {
|
|
23463
23666
|
const client = getActiveClient();
|
|
23464
|
-
client.log('
|
|
23465
|
-
const hardDeleted =
|
|
23466
|
-
return
|
|
23667
|
+
client.log('comment/hardDeleteComment', commentId);
|
|
23668
|
+
const hardDeleted = deleteComment(commentId, true);
|
|
23669
|
+
return hardDeleted;
|
|
23467
23670
|
};
|
|
23468
23671
|
/* end_public_function */
|
|
23469
23672
|
|
|
23470
23673
|
/* begin_public_function
|
|
23471
|
-
id:
|
|
23674
|
+
id: comment.flag
|
|
23472
23675
|
*/
|
|
23473
23676
|
/**
|
|
23474
23677
|
* ```js
|
|
23475
|
-
* import {
|
|
23476
|
-
*
|
|
23477
|
-
* const { data: post } = await approvePost('postId')
|
|
23678
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
23679
|
+
* const flagged = await CommentRepository.flagComment(commentId, reason)
|
|
23478
23680
|
* ```
|
|
23479
23681
|
*
|
|
23480
|
-
*
|
|
23481
|
-
*
|
|
23482
|
-
* @
|
|
23483
|
-
* @return A {@link Amity.Post} that was approved
|
|
23682
|
+
* @param commentId The ID of the comment to flag
|
|
23683
|
+
* @param reason the reason to flag the comment
|
|
23684
|
+
* @returns the created report result
|
|
23484
23685
|
*
|
|
23485
|
-
* @category
|
|
23686
|
+
* @category Comment API
|
|
23486
23687
|
* @async
|
|
23487
|
-
*/
|
|
23488
|
-
const
|
|
23688
|
+
* */
|
|
23689
|
+
const flagComment = async (commentId, reason) => {
|
|
23489
23690
|
const client = getActiveClient();
|
|
23490
|
-
client.log('
|
|
23491
|
-
const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/approve`);
|
|
23492
|
-
fireEvent('post.approved', payload);
|
|
23493
|
-
// fire virtual event for community update
|
|
23494
|
-
if (payload.posts[0].targetType === 'community') {
|
|
23495
|
-
fireEvent('community.updated', payload);
|
|
23496
|
-
}
|
|
23497
|
-
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
23498
|
-
const cachedAt = client.cache && Date.now();
|
|
23499
|
-
if (client.cache)
|
|
23500
|
-
ingestInCache(data, { cachedAt });
|
|
23501
|
-
return {
|
|
23502
|
-
data: LinkedObject.post(data.posts.find(post => post.postId === postId)),
|
|
23503
|
-
cachedAt,
|
|
23504
|
-
};
|
|
23505
|
-
};
|
|
23506
|
-
/* end_public_function */
|
|
23507
|
-
|
|
23508
|
-
/* begin_public_function
|
|
23509
|
-
id: post.decline
|
|
23510
|
-
*/
|
|
23511
|
-
/**
|
|
23512
|
-
* ```js
|
|
23513
|
-
* import { declinePost } from '@amityco/ts-sdk'
|
|
23514
|
-
*
|
|
23515
|
-
* const {data: post} = await declinePost('postId')
|
|
23516
|
-
* ```
|
|
23517
|
-
*
|
|
23518
|
-
* Declines a {@link Amity.Post}
|
|
23519
|
-
*
|
|
23520
|
-
* @param postId The {@link Amity.Post} ID to be declined
|
|
23521
|
-
* @return A {@link Amity.Post} that was declined
|
|
23522
|
-
*
|
|
23523
|
-
* @category Post API
|
|
23524
|
-
* @async
|
|
23525
|
-
*/
|
|
23526
|
-
const declinePost = async (postId) => {
|
|
23527
|
-
const client = getActiveClient();
|
|
23528
|
-
client.log('post/declinePost', postId);
|
|
23529
|
-
const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/decline`);
|
|
23530
|
-
// fire virtual event
|
|
23531
|
-
if (payload.posts[0].targetType === 'community') {
|
|
23532
|
-
fireEvent('community.updated', payload);
|
|
23533
|
-
}
|
|
23534
|
-
fireEvent('post.declined', payload);
|
|
23535
|
-
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
23536
|
-
const cachedAt = client.cache && Date.now();
|
|
23537
|
-
if (client.cache)
|
|
23538
|
-
ingestInCache(data, { cachedAt });
|
|
23539
|
-
return {
|
|
23540
|
-
data: LinkedObject.post(payload.posts.find(post => post.postId === postId)),
|
|
23541
|
-
cachedAt,
|
|
23542
|
-
};
|
|
23543
|
-
};
|
|
23544
|
-
/* end_public_function */
|
|
23545
|
-
|
|
23546
|
-
/* begin_public_function
|
|
23547
|
-
id: post.flag
|
|
23548
|
-
*/
|
|
23549
|
-
/**
|
|
23550
|
-
* ```js
|
|
23551
|
-
* import { PostRepository } from '@amityco/ts-sdk'
|
|
23552
|
-
* const flagged = await PostRepository.flagPost(postId, reason)
|
|
23553
|
-
* ```
|
|
23554
|
-
*
|
|
23555
|
-
* @param postId of the post to flag
|
|
23556
|
-
* @param reason the reason to flag the post
|
|
23557
|
-
* @returns a boolean
|
|
23558
|
-
*
|
|
23559
|
-
* @category Post API
|
|
23560
|
-
* @async
|
|
23561
|
-
* */
|
|
23562
|
-
const flagPost = async (postId, reason) => {
|
|
23563
|
-
const client = getActiveClient();
|
|
23564
|
-
client.log('post/flagPost', postId);
|
|
23691
|
+
client.log('comment/flagComment', commentId);
|
|
23565
23692
|
const isPredefinedReason = reason &&
|
|
23566
23693
|
Object.entries(exports.ContentFlagReasonEnum).some(([key, value]) => key !== exports.ContentFlagReasonEnum.Others && value === reason);
|
|
23567
23694
|
const body = {
|
|
23568
23695
|
reason: reason && isPredefinedReason ? reason : exports.ContentFlagReasonEnum.Others,
|
|
23569
23696
|
detail: reason && !isPredefinedReason ? reason : '',
|
|
23570
23697
|
};
|
|
23571
|
-
const { data: payload } = await client.http.post(`/api/v3/
|
|
23698
|
+
const { data: payload } = await client.http.post(`/api/v3/comments/${encodeURIComponent(commentId)}/flag`, body);
|
|
23572
23699
|
if (client.cache) {
|
|
23573
|
-
ingestInCache(
|
|
23700
|
+
ingestInCache(payload);
|
|
23574
23701
|
}
|
|
23575
|
-
fireEvent('
|
|
23702
|
+
fireEvent('comment.flagged', payload);
|
|
23576
23703
|
return !!payload;
|
|
23577
23704
|
};
|
|
23578
23705
|
/* end_public_function */
|
|
23579
23706
|
|
|
23580
23707
|
/* begin_public_function
|
|
23581
|
-
id:
|
|
23708
|
+
id: comment.unflag
|
|
23582
23709
|
*/
|
|
23583
23710
|
/**
|
|
23584
23711
|
* ```js
|
|
23585
|
-
* import {
|
|
23586
|
-
* const unflagged = await
|
|
23712
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
23713
|
+
* const unflagged = await CommentRepository.unflagComment('commentId')
|
|
23587
23714
|
* ```
|
|
23588
23715
|
*
|
|
23589
|
-
* @param
|
|
23590
|
-
* @returns the
|
|
23716
|
+
* @param commentId The ID of comment to unflag
|
|
23717
|
+
* @returns the unflagged result
|
|
23591
23718
|
*
|
|
23592
|
-
* @category
|
|
23719
|
+
* @category Comment API
|
|
23593
23720
|
* @async
|
|
23594
23721
|
* */
|
|
23595
|
-
const
|
|
23722
|
+
const unflagComment = async (commentId) => {
|
|
23596
23723
|
const client = getActiveClient();
|
|
23597
|
-
client.log('
|
|
23598
|
-
const { data: payload } = await client.http.delete(`/api/v3/
|
|
23724
|
+
client.log('comment/unflagComment', commentId);
|
|
23725
|
+
const { data: payload } = await client.http.delete(`/api/v3/comments/${encodeURIComponent(commentId)}/unflag`);
|
|
23599
23726
|
if (client.cache) {
|
|
23600
|
-
ingestInCache(
|
|
23727
|
+
ingestInCache(payload);
|
|
23601
23728
|
}
|
|
23602
|
-
fireEvent('
|
|
23729
|
+
fireEvent('comment.unflagged', payload);
|
|
23603
23730
|
return !!payload;
|
|
23604
23731
|
};
|
|
23605
23732
|
/* end_public_function */
|
|
23606
23733
|
|
|
23607
23734
|
/* begin_public_function
|
|
23608
|
-
id:
|
|
23735
|
+
id: comment.check_flag_by_me
|
|
23609
23736
|
*/
|
|
23610
23737
|
/**
|
|
23611
23738
|
* ```js
|
|
23612
|
-
* import {
|
|
23613
|
-
* const isReported = await
|
|
23739
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
23740
|
+
* const isReported = await CommentRepository.isCommentFlaggedByMe('commentId')
|
|
23614
23741
|
* ```
|
|
23615
23742
|
*
|
|
23616
|
-
* @param
|
|
23617
|
-
* @returns `true` if the
|
|
23743
|
+
* @param commentId The ID of the comment to check if flagged by current user
|
|
23744
|
+
* @returns `true` if the comment is flagged by me, `false` if doesn't.
|
|
23618
23745
|
*
|
|
23619
|
-
* @category
|
|
23746
|
+
* @category Comment API
|
|
23620
23747
|
* @async
|
|
23621
23748
|
* */
|
|
23622
|
-
const
|
|
23749
|
+
const isCommentFlaggedByMe = async (commentId) => {
|
|
23623
23750
|
const client = getActiveClient();
|
|
23624
|
-
client.log('
|
|
23625
|
-
const { data: { result }, } = await client.http.get(`/api/v3/
|
|
23751
|
+
client.log('comment/isCommentFlaggedByMe', commentId);
|
|
23752
|
+
const { data: { result }, } = await client.http.get(`/api/v3/comments/${commentId}/isflagbyme`);
|
|
23626
23753
|
return result;
|
|
23627
23754
|
};
|
|
23628
23755
|
/* end_public_function */
|
|
23629
23756
|
|
|
23630
|
-
|
|
23631
|
-
id: post.create.clip_post
|
|
23632
|
-
*/
|
|
23633
|
-
/**
|
|
23634
|
-
* ```js
|
|
23635
|
-
* import { PostRepository } from '@amityco/ts-sdk'
|
|
23636
|
-
* const created = await PostRepository.createClipPost({
|
|
23637
|
-
* targetType: 'user',
|
|
23638
|
-
* targetId: 'foobar',
|
|
23639
|
-
* dataType: 'clip',
|
|
23640
|
-
* data: { text: 'hello world' },
|
|
23641
|
-
* attachments: [{ type: 'clip', fileId: 'fileId123', displayMode: 'fill', isMuted: false }]
|
|
23642
|
-
* }))
|
|
23643
|
-
* ```
|
|
23644
|
-
*
|
|
23645
|
-
* Creates an {@link Amity.Post}
|
|
23646
|
-
*
|
|
23647
|
-
* @param bundle The data necessary to create a new {@link Amity.Post}
|
|
23648
|
-
* @returns The newly created {@link Amity.Post}
|
|
23649
|
-
*
|
|
23650
|
-
* @category Post API
|
|
23651
|
-
* @async
|
|
23652
|
-
*/
|
|
23653
|
-
const createClipPost = async (bundle) => {
|
|
23654
|
-
const client = getActiveClient();
|
|
23655
|
-
client.log('post/createPost', bundle);
|
|
23656
|
-
const { data: payload } = await client.http.post('/api/v4/posts', bundle);
|
|
23657
|
-
fireEvent('post.created', payload);
|
|
23658
|
-
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
23659
|
-
const cachedAt = client.cache && Date.now();
|
|
23660
|
-
if (client.cache)
|
|
23661
|
-
ingestInCache(data, { cachedAt });
|
|
23662
|
-
const { posts } = data;
|
|
23663
|
-
return {
|
|
23664
|
-
data: LinkedObject.post(posts[0]),
|
|
23665
|
-
cachedAt,
|
|
23666
|
-
};
|
|
23667
|
-
};
|
|
23668
|
-
/* end_public_function */
|
|
23669
|
-
|
|
23670
|
-
/* begin_public_function
|
|
23671
|
-
id: comment.get_by_ids
|
|
23672
|
-
*/
|
|
23673
|
-
/**
|
|
23674
|
-
* ```js
|
|
23675
|
-
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
23676
|
-
* const comments = await CommentRepository.getCommentByIds(['foo', 'bar'])
|
|
23677
|
-
* ```
|
|
23678
|
-
*
|
|
23679
|
-
* Fetches a collection of {@link Amity.Comment} objects
|
|
23680
|
-
*
|
|
23681
|
-
* @param commentIds the IDs of the {@link Amity.Comment} to fetch
|
|
23682
|
-
* @returns the associated collection of {@link Amity.Comment} objects
|
|
23683
|
-
*
|
|
23684
|
-
* @category Comment API
|
|
23685
|
-
* @async
|
|
23686
|
-
*/
|
|
23687
|
-
const getCommentByIds = async (commentIds) => {
|
|
23757
|
+
const getComment$1 = async (commentId) => {
|
|
23688
23758
|
const client = getActiveClient();
|
|
23689
|
-
client.log('comment/
|
|
23690
|
-
|
|
23759
|
+
client.log('comment/getComment', commentId);
|
|
23760
|
+
isInTombstone('comment', commentId);
|
|
23691
23761
|
let data;
|
|
23692
23762
|
try {
|
|
23693
23763
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
23694
|
-
const response = await client.http.get(`/api/v3/comments
|
|
23695
|
-
params: { commentIds: encodedCommentIds },
|
|
23696
|
-
});
|
|
23764
|
+
const response = await client.http.get(`/api/v3/comments/${encodeURIComponent(commentId)}`);
|
|
23697
23765
|
data = response.data;
|
|
23698
23766
|
}
|
|
23699
23767
|
catch (error) {
|
|
23700
|
-
|
|
23701
|
-
|
|
23702
|
-
|
|
23703
|
-
}
|
|
23704
|
-
});
|
|
23768
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
23769
|
+
pushToTombstone('comment', commentId);
|
|
23770
|
+
}
|
|
23705
23771
|
throw error;
|
|
23706
23772
|
}
|
|
23707
23773
|
const cachedAt = client.cache && Date.now();
|
|
23708
23774
|
if (client.cache)
|
|
23709
23775
|
ingestInCache(data, { cachedAt });
|
|
23776
|
+
const { comments } = data;
|
|
23710
23777
|
return {
|
|
23711
|
-
data:
|
|
23778
|
+
data: comments.find(comment => comment.commentId === commentId),
|
|
23712
23779
|
cachedAt,
|
|
23713
23780
|
};
|
|
23714
23781
|
};
|
|
23715
|
-
|
|
23716
|
-
/**
|
|
23717
|
-
* ```js
|
|
23718
|
-
* import { getCommentByIds } from '@amityco/ts-sdk'
|
|
23719
|
-
* const comments = getCommentByIds.locally(['foo', 'bar'])
|
|
23720
|
-
* ```
|
|
23721
|
-
*
|
|
23722
|
-
* Fetches a collection of {@link Amity.Comment} objects from cache
|
|
23723
|
-
*
|
|
23724
|
-
* @param commentIds the IDs of the {@link Amity.Comment} to fetch
|
|
23725
|
-
* @returns the associated collection of {@link Amity.Comment} objects
|
|
23726
|
-
*
|
|
23727
|
-
* @category Comment API
|
|
23728
|
-
*/
|
|
23729
|
-
getCommentByIds.locally = (commentIds) => {
|
|
23730
|
-
var _a;
|
|
23782
|
+
getComment$1.locally = (commentId) => {
|
|
23731
23783
|
const client = getActiveClient();
|
|
23732
|
-
client.log('comment/
|
|
23784
|
+
client.log('comment/getComment.locally', commentId);
|
|
23733
23785
|
if (!client.cache)
|
|
23734
23786
|
return;
|
|
23735
|
-
const cached =
|
|
23736
|
-
|
|
23737
|
-
.filter(Boolean);
|
|
23738
|
-
const comments = cached.map(({ data }) => data);
|
|
23739
|
-
const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
|
|
23740
|
-
if ((cached === null || cached === void 0 ? void 0 : cached.length) < commentIds.length)
|
|
23787
|
+
const cached = pullFromCache(['comment', 'get', commentId]);
|
|
23788
|
+
if (!cached)
|
|
23741
23789
|
return;
|
|
23742
23790
|
return {
|
|
23743
|
-
data:
|
|
23744
|
-
cachedAt:
|
|
23791
|
+
data: cached.data,
|
|
23792
|
+
cachedAt: cached.cachedAt,
|
|
23745
23793
|
};
|
|
23746
23794
|
};
|
|
23747
23795
|
|
|
23748
|
-
/* begin_public_function
|
|
23749
|
-
id: comment.create
|
|
23750
|
-
*/
|
|
23751
23796
|
/**
|
|
23752
23797
|
* ```js
|
|
23753
|
-
* import {
|
|
23754
|
-
* const
|
|
23798
|
+
* import { onCommentDeleteLocal } from '@amityco/ts-sdk'
|
|
23799
|
+
* const dispose = onCommentDeleteLocal(comment => {
|
|
23800
|
+
* // ...
|
|
23801
|
+
* })
|
|
23755
23802
|
* ```
|
|
23756
23803
|
*
|
|
23757
|
-
*
|
|
23804
|
+
* Fired when a {@link Amity.InternalComment} has been deleted
|
|
23758
23805
|
*
|
|
23759
|
-
* @param
|
|
23760
|
-
* @returns
|
|
23806
|
+
* @param callback The function to call when the event was fired
|
|
23807
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
23761
23808
|
*
|
|
23762
|
-
* @category Comment
|
|
23763
|
-
* @async
|
|
23809
|
+
* @category Comment Events
|
|
23764
23810
|
*/
|
|
23765
|
-
const
|
|
23766
|
-
|
|
23811
|
+
const onCommentDeleteLocal = (callback) => createLocalCommentEventSubscriber('local.comment.deleted', callback);
|
|
23812
|
+
|
|
23813
|
+
/**
|
|
23814
|
+
* ```js
|
|
23815
|
+
* import { onLocalCommentReactionAdded } from '@amityco/ts-sdk'
|
|
23816
|
+
* const dispose = onLocalCommentReactionAdded(comment => {
|
|
23817
|
+
* // ...
|
|
23818
|
+
* })
|
|
23819
|
+
* ```
|
|
23820
|
+
*
|
|
23821
|
+
* Fired when a {@link Amity.InternalComment} has been reacted
|
|
23822
|
+
*
|
|
23823
|
+
* @param callback The function to call when the event was fired
|
|
23824
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
23825
|
+
*
|
|
23826
|
+
* @category Comment Events
|
|
23827
|
+
*/
|
|
23828
|
+
const onLocalCommentReactionAdded = (callback) => {
|
|
23767
23829
|
const client = getActiveClient();
|
|
23768
|
-
|
|
23769
|
-
|
|
23770
|
-
|
|
23771
|
-
// BE always returns an array of comments If it got record 0 from BE it might have a problem on creation logic
|
|
23772
|
-
if (comments.length === 0)
|
|
23773
|
-
throw new Error('Comment not created');
|
|
23774
|
-
const cachedAt = client.cache && Date.now();
|
|
23775
|
-
if (client.cache)
|
|
23776
|
-
ingestInCache(data, { cachedAt });
|
|
23777
|
-
if (['post', 'content'].includes(bundle.referenceType)) {
|
|
23778
|
-
const post = (_a = pullFromCache(['post', 'get', bundle.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23779
|
-
if (post) {
|
|
23780
|
-
post.commentsCount += 1;
|
|
23781
|
-
fireEvent('local.post.updated', {
|
|
23782
|
-
posts: [post],
|
|
23783
|
-
categories: [],
|
|
23784
|
-
comments: [],
|
|
23785
|
-
communities: [],
|
|
23786
|
-
communityUsers: data.communityUsers,
|
|
23787
|
-
feeds: [],
|
|
23788
|
-
files: data.files,
|
|
23789
|
-
postChildren: [],
|
|
23790
|
-
users: data.users,
|
|
23791
|
-
videoStreamings: [],
|
|
23792
|
-
});
|
|
23830
|
+
const filter = ({ comment }) => {
|
|
23831
|
+
if (!client.cache) {
|
|
23832
|
+
callback(comment);
|
|
23793
23833
|
}
|
|
23794
|
-
|
|
23795
|
-
|
|
23796
|
-
|
|
23797
|
-
"story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
|
|
23798
|
-
bundle.referenceId,
|
|
23799
|
-
]);
|
|
23800
|
-
if (storyIndex === null || storyIndex === void 0 ? void 0 : storyIndex.data) {
|
|
23801
|
-
const cacheStory = pullFromCache([
|
|
23802
|
-
"story" /* STORY_KEY_CACHE.STORY */,
|
|
23803
|
-
'get',
|
|
23804
|
-
storyIndex.data,
|
|
23805
|
-
]);
|
|
23806
|
-
if (cacheStory === null || cacheStory === void 0 ? void 0 : cacheStory.data) {
|
|
23807
|
-
fireEvent('story.updated', {
|
|
23808
|
-
stories: [
|
|
23809
|
-
Object.assign(Object.assign({}, cacheStory.data), { commentsCount: cacheStory.data.commentsCount + 1, comments: [...new Set([...cacheStory.data.comments, comments[0].commentId])] }),
|
|
23810
|
-
],
|
|
23811
|
-
categories: [],
|
|
23812
|
-
comments,
|
|
23813
|
-
communities: [],
|
|
23814
|
-
communityUsers: data.communityUsers,
|
|
23815
|
-
files: data.files,
|
|
23816
|
-
users: data.users,
|
|
23817
|
-
});
|
|
23818
|
-
}
|
|
23834
|
+
else {
|
|
23835
|
+
upsertInCache(['comment', 'get', comment.commentId], comment);
|
|
23836
|
+
callback(commentLinkedObject(comment));
|
|
23819
23837
|
}
|
|
23820
|
-
}
|
|
23821
|
-
fireEvent('local.comment.created', data);
|
|
23822
|
-
return {
|
|
23823
|
-
data: LinkedObject.comment(comments[0]),
|
|
23824
|
-
cachedAt,
|
|
23825
23838
|
};
|
|
23839
|
+
return createEventSubscriber(client, 'local.comment.addReaction', 'local.comment.addReaction', filter);
|
|
23826
23840
|
};
|
|
23827
|
-
/* end_public_function */
|
|
23828
23841
|
|
|
23829
|
-
/* begin_public_function
|
|
23830
|
-
id: comment.update_comment
|
|
23831
|
-
*/
|
|
23832
23842
|
/**
|
|
23833
23843
|
* ```js
|
|
23834
|
-
* import {
|
|
23835
|
-
* const
|
|
23836
|
-
*
|
|
23844
|
+
* import { onLocalCommentReactionRemoved } from '@amityco/ts-sdk'
|
|
23845
|
+
* const dispose = onLocalCommentReactionRemoved(comment => {
|
|
23846
|
+
* // ...
|
|
23837
23847
|
* })
|
|
23838
23848
|
* ```
|
|
23839
23849
|
*
|
|
23840
|
-
*
|
|
23850
|
+
* Fired when a {@link Amity.InternalComment} has been reacted
|
|
23841
23851
|
*
|
|
23842
|
-
* @param
|
|
23843
|
-
* @
|
|
23844
|
-
* @returns the updated {@link Amity.Comment} object
|
|
23852
|
+
* @param callback The function to call when the event was fired
|
|
23853
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
23845
23854
|
*
|
|
23846
|
-
* @category Comment
|
|
23847
|
-
* @async
|
|
23855
|
+
* @category Comment Events
|
|
23848
23856
|
*/
|
|
23849
|
-
const
|
|
23850
|
-
const client = getActiveClient();
|
|
23851
|
-
client.log('user/updateComment', patch);
|
|
23852
|
-
const { data } = await client.http.put(`/api/v3/comments/${encodeURIComponent(commentId)}`, patch);
|
|
23853
|
-
const cachedAt = client.cache && Date.now();
|
|
23854
|
-
if (client.cache)
|
|
23855
|
-
ingestInCache(data, { cachedAt });
|
|
23856
|
-
fireEvent('comment.updated', data);
|
|
23857
|
-
const { comments } = data;
|
|
23858
|
-
return {
|
|
23859
|
-
data: LinkedObject.comment(comments.find(comment => comment.commentId === commentId)),
|
|
23860
|
-
cachedAt,
|
|
23861
|
-
};
|
|
23862
|
-
};
|
|
23863
|
-
/* end_public_function */
|
|
23864
|
-
|
|
23865
|
-
// Due to we have optimistic logic, we will use referenceId as a id in SDK instead of storyId
|
|
23866
|
-
const applyMissingField = (rawData, isCreated = false) => {
|
|
23867
|
-
const { storyId, referenceId } = rawData;
|
|
23868
|
-
if (!isCreated) {
|
|
23869
|
-
if (referenceId)
|
|
23870
|
-
return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */ });
|
|
23871
|
-
}
|
|
23872
|
-
return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */, referenceId: storyId });
|
|
23873
|
-
};
|
|
23874
|
-
const convertRawStoryToInternal = (data, isCreated = false) => {
|
|
23875
|
-
const { stories } = data;
|
|
23876
|
-
const storiesData = stories.map(story => applyMissingField(story, isCreated));
|
|
23877
|
-
return Object.assign(Object.assign({}, data), { stories: storiesData });
|
|
23878
|
-
};
|
|
23879
|
-
|
|
23880
|
-
const getStoryByStoryId$1 = async (storyId) => {
|
|
23857
|
+
const onLocalCommentReactionRemoved = (callback) => {
|
|
23881
23858
|
const client = getActiveClient();
|
|
23882
|
-
|
|
23883
|
-
|
|
23884
|
-
|
|
23885
|
-
|
|
23886
|
-
|
|
23887
|
-
|
|
23888
|
-
|
|
23889
|
-
const { data: referenceId } = cacheReferenceId;
|
|
23890
|
-
isInTombstone('story', referenceId);
|
|
23891
|
-
}
|
|
23892
|
-
let data;
|
|
23893
|
-
try {
|
|
23894
|
-
const response = await client.http.get(`/api/v4/stories/${storyId}`);
|
|
23895
|
-
data = convertRawStoryToInternal(response.data);
|
|
23896
|
-
}
|
|
23897
|
-
catch (error) {
|
|
23898
|
-
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
23899
|
-
pushToTombstone('story', storyId);
|
|
23859
|
+
const filter = ({ comment }) => {
|
|
23860
|
+
if (!client.cache) {
|
|
23861
|
+
callback(comment);
|
|
23862
|
+
}
|
|
23863
|
+
else {
|
|
23864
|
+
upsertInCache(['comment', 'get', comment.commentId], comment);
|
|
23865
|
+
callback(commentLinkedObject(comment));
|
|
23900
23866
|
}
|
|
23901
|
-
throw error;
|
|
23902
|
-
}
|
|
23903
|
-
const cachedAt = client.cache && Date.now();
|
|
23904
|
-
if (client.cache) {
|
|
23905
|
-
ingestInCache(data, { cachedAt });
|
|
23906
|
-
}
|
|
23907
|
-
return {
|
|
23908
|
-
data: data.stories[0],
|
|
23909
|
-
cachedAt,
|
|
23910
|
-
};
|
|
23911
|
-
};
|
|
23912
|
-
getStoryByStoryId$1.locally = (storyId) => {
|
|
23913
|
-
const client = getActiveClient();
|
|
23914
|
-
client.log('story/getStorybyStoryId', storyId);
|
|
23915
|
-
// Get story referenceId from cache
|
|
23916
|
-
const cacheReferenceId = pullFromCache([
|
|
23917
|
-
"story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
|
|
23918
|
-
storyId,
|
|
23919
|
-
]);
|
|
23920
|
-
if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
|
|
23921
|
-
const { data: referenceId } = cacheReferenceId;
|
|
23922
|
-
isInTombstone('story', referenceId);
|
|
23923
|
-
}
|
|
23924
|
-
const cachedAt = client.cache && Date.now();
|
|
23925
|
-
const storyCache = pullFromCache(['story', 'get', storyId]);
|
|
23926
|
-
if (!storyCache)
|
|
23927
|
-
return;
|
|
23928
|
-
return {
|
|
23929
|
-
data: storyCache.data,
|
|
23930
|
-
cachedAt,
|
|
23931
23867
|
};
|
|
23868
|
+
return createEventSubscriber(client, 'local.comment.removeReaction', 'local.comment.removeReaction', filter);
|
|
23932
23869
|
};
|
|
23933
23870
|
|
|
23934
23871
|
/* begin_public_function
|
|
23935
|
-
id: comment.
|
|
23872
|
+
id: comment.get
|
|
23936
23873
|
*/
|
|
23937
23874
|
/**
|
|
23938
23875
|
* ```js
|
|
23939
|
-
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
23940
|
-
*
|
|
23876
|
+
* import { CommentRepository } from '@amityco/ts-sdk';
|
|
23877
|
+
*
|
|
23878
|
+
* let comment;
|
|
23879
|
+
*
|
|
23880
|
+
* const unsub = CommentRepository.getComment(commentId, response => {
|
|
23881
|
+
* comment = response.data;
|
|
23882
|
+
* });
|
|
23941
23883
|
* ```
|
|
23942
23884
|
*
|
|
23943
|
-
*
|
|
23885
|
+
* Observe all mutation on a given {@link Amity.Comment}
|
|
23944
23886
|
*
|
|
23945
|
-
* @param commentId
|
|
23946
|
-
* @
|
|
23887
|
+
* @param commentId the ID of the comment to observe
|
|
23888
|
+
* @param callback the function to call when new data are available
|
|
23889
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the comment
|
|
23947
23890
|
*
|
|
23948
|
-
* @category Comment
|
|
23949
|
-
* @async
|
|
23891
|
+
* @category Comment Live Object
|
|
23950
23892
|
*/
|
|
23951
|
-
const
|
|
23952
|
-
|
|
23953
|
-
|
|
23954
|
-
|
|
23955
|
-
|
|
23956
|
-
|
|
23957
|
-
|
|
23958
|
-
|
|
23959
|
-
|
|
23960
|
-
|
|
23961
|
-
|
|
23962
|
-
|
|
23963
|
-
|
|
23964
|
-
|
|
23965
|
-
|
|
23966
|
-
|
|
23967
|
-
|
|
23968
|
-
|
|
23969
|
-
|
|
23970
|
-
|
|
23971
|
-
|
|
23972
|
-
|
|
23973
|
-
|
|
23893
|
+
const getComment = (commentId, callback) => {
|
|
23894
|
+
return liveObject(commentId, callback, 'commentId', getComment$1, [
|
|
23895
|
+
onCommentDeleteLocal,
|
|
23896
|
+
onCommentDeleted,
|
|
23897
|
+
onCommentFlagged,
|
|
23898
|
+
onCommentReactionAdded,
|
|
23899
|
+
onCommentReactionRemoved,
|
|
23900
|
+
onCommentUnflagged,
|
|
23901
|
+
onCommentUpdated,
|
|
23902
|
+
onLocalCommentReactionAdded,
|
|
23903
|
+
onLocalCommentReactionRemoved,
|
|
23904
|
+
]);
|
|
23905
|
+
};
|
|
23906
|
+
/* end_public_function */
|
|
23907
|
+
|
|
23908
|
+
class CommentPaginationController extends PaginationController {
|
|
23909
|
+
async getRequest(queryParams, token) {
|
|
23910
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
|
|
23911
|
+
const baseOptions = {
|
|
23912
|
+
type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
|
|
23913
|
+
};
|
|
23914
|
+
const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
|
|
23915
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/comments`, {
|
|
23916
|
+
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options }),
|
|
23974
23917
|
});
|
|
23918
|
+
return queryResponse;
|
|
23975
23919
|
}
|
|
23976
|
-
|
|
23977
|
-
|
|
23978
|
-
|
|
23979
|
-
|
|
23980
|
-
|
|
23981
|
-
|
|
23982
|
-
|
|
23983
|
-
|
|
23984
|
-
|
|
23985
|
-
|
|
23986
|
-
|
|
23987
|
-
|
|
23988
|
-
|
|
23989
|
-
|
|
23990
|
-
|
|
23991
|
-
|
|
23992
|
-
|
|
23993
|
-
|
|
23994
|
-
|
|
23995
|
-
|
|
23996
|
-
|
|
23997
|
-
|
|
23920
|
+
}
|
|
23921
|
+
|
|
23922
|
+
var EnumCommentActions;
|
|
23923
|
+
(function (EnumCommentActions) {
|
|
23924
|
+
EnumCommentActions["OnCommentCreated"] = "onCommentCreated";
|
|
23925
|
+
EnumCommentActions["OnCommentUpdated"] = "onCommentUpdated";
|
|
23926
|
+
EnumCommentActions["OnCommentDeleted"] = "onCommentDeleted";
|
|
23927
|
+
EnumCommentActions["OnCommentFlagged"] = "onCommentFlagged";
|
|
23928
|
+
EnumCommentActions["OnCommentUnflagged"] = "onCommentUnflagged";
|
|
23929
|
+
EnumCommentActions["OnCommentReactionAdded"] = "onCommentReactionAdded";
|
|
23930
|
+
EnumCommentActions["OnCommentReactionRemoved"] = "onCommentReactionRemoved";
|
|
23931
|
+
})(EnumCommentActions || (EnumCommentActions = {}));
|
|
23932
|
+
|
|
23933
|
+
class CommentQueryStreamController extends QueryStreamController {
|
|
23934
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
23935
|
+
super(query, cacheKey);
|
|
23936
|
+
this.notifyChange = notifyChange;
|
|
23937
|
+
this.preparePayload = preparePayload;
|
|
23938
|
+
}
|
|
23939
|
+
async saveToMainDB(response) {
|
|
23940
|
+
const processedPayload = await this.preparePayload(response);
|
|
23941
|
+
const client = getActiveClient();
|
|
23942
|
+
const cachedAt = client.cache && Date.now();
|
|
23943
|
+
if (client.cache) {
|
|
23944
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
23945
|
+
}
|
|
23946
|
+
}
|
|
23947
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
23948
|
+
var _a, _b;
|
|
23949
|
+
if (refresh) {
|
|
23950
|
+
pushToCache(this.cacheKey, {
|
|
23951
|
+
data: response.comments.map(getResolver('comment')),
|
|
23998
23952
|
});
|
|
23999
23953
|
}
|
|
23954
|
+
else {
|
|
23955
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23956
|
+
const comments = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
23957
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...comments, ...response.comments.map(getResolver('comment'))])] }));
|
|
23958
|
+
}
|
|
24000
23959
|
}
|
|
24001
|
-
|
|
24002
|
-
|
|
24003
|
-
|
|
24004
|
-
|
|
24005
|
-
|
|
24006
|
-
|
|
24007
|
-
|
|
24008
|
-
|
|
24009
|
-
|
|
23960
|
+
reactor(action) {
|
|
23961
|
+
return (comment) => {
|
|
23962
|
+
var _a;
|
|
23963
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23964
|
+
if (this.query.referenceId !== comment.referenceId ||
|
|
23965
|
+
this.query.referenceType !== comment.referenceType ||
|
|
23966
|
+
!collection) {
|
|
23967
|
+
return;
|
|
23968
|
+
}
|
|
23969
|
+
if (this.query.parentId && this.query.parentId !== comment.parentId) {
|
|
23970
|
+
return;
|
|
23971
|
+
}
|
|
23972
|
+
if (!this.query.parentId && comment.parentId) {
|
|
23973
|
+
return;
|
|
23974
|
+
}
|
|
23975
|
+
if (action === EnumCommentActions.OnCommentCreated) {
|
|
23976
|
+
collection.data = [...new Set([comment.commentId, ...collection.data])];
|
|
23977
|
+
}
|
|
23978
|
+
pushToCache(this.cacheKey, collection);
|
|
23979
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
23980
|
+
};
|
|
24010
23981
|
}
|
|
24011
|
-
|
|
24012
|
-
|
|
23982
|
+
subscribeRTE(createSubscriber) {
|
|
23983
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
24013
23984
|
}
|
|
24014
|
-
|
|
24015
|
-
};
|
|
24016
|
-
/* end_public_function */
|
|
23985
|
+
}
|
|
24017
23986
|
|
|
24018
|
-
/* begin_public_function
|
|
24019
|
-
id: comment.soft_delete
|
|
24020
|
-
*/
|
|
24021
23987
|
/**
|
|
24022
23988
|
* ```js
|
|
24023
|
-
* import {
|
|
24024
|
-
* const
|
|
23989
|
+
* import { onCommentCreated } from '@amityco/ts-sdk'
|
|
23990
|
+
* const dispose = onCommentCreated(comment => {
|
|
23991
|
+
* // ...
|
|
23992
|
+
* })
|
|
24025
23993
|
* ```
|
|
24026
23994
|
*
|
|
24027
|
-
*
|
|
23995
|
+
* Fired when a {@link Amity.InternalComment} has been created
|
|
24028
23996
|
*
|
|
24029
|
-
* @param
|
|
24030
|
-
* @
|
|
23997
|
+
* @param callback The function to call when the event was fired
|
|
23998
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
24031
23999
|
*
|
|
24032
|
-
* @category Comment
|
|
24033
|
-
* @async
|
|
24000
|
+
* @category Comment Events
|
|
24034
24001
|
*/
|
|
24035
|
-
const
|
|
24036
|
-
|
|
24037
|
-
client.log('comment/softDeleteComment', commentId);
|
|
24038
|
-
const softDeleted = deleteComment(commentId);
|
|
24039
|
-
return softDeleted;
|
|
24002
|
+
const onCommentCreatedLocal = (callback) => {
|
|
24003
|
+
return createLocalCommentEventSubscriber('local.comment.created', callback);
|
|
24040
24004
|
};
|
|
24041
|
-
|
|
24005
|
+
|
|
24006
|
+
class CommentLiveCollectionController extends LiveCollectionController {
|
|
24007
|
+
constructor(query, callback) {
|
|
24008
|
+
const queryStreamId = hash__default["default"](query);
|
|
24009
|
+
const cacheKey = ['comments', 'collection', queryStreamId];
|
|
24010
|
+
const paginationController = new CommentPaginationController(query);
|
|
24011
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
24012
|
+
this.query = query;
|
|
24013
|
+
this.queryStreamController = new CommentQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommentPayload);
|
|
24014
|
+
this.callback = callback.bind(this);
|
|
24015
|
+
this.loadPage({ initial: true });
|
|
24016
|
+
}
|
|
24017
|
+
setup() {
|
|
24018
|
+
var _a;
|
|
24019
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24020
|
+
if (!collection) {
|
|
24021
|
+
pushToCache(this.cacheKey, {
|
|
24022
|
+
data: [],
|
|
24023
|
+
params: {},
|
|
24024
|
+
});
|
|
24025
|
+
}
|
|
24026
|
+
}
|
|
24027
|
+
async persistModel(queryPayload) {
|
|
24028
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
24029
|
+
}
|
|
24030
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
24031
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
24032
|
+
}
|
|
24033
|
+
startSubscription() {
|
|
24034
|
+
return this.queryStreamController.subscribeRTE([
|
|
24035
|
+
{ fn: onCommentCreatedLocal, action: EnumCommentActions.OnCommentCreated },
|
|
24036
|
+
{ fn: onCommentDeleteLocal, action: EnumCommentActions.OnCommentDeleted },
|
|
24037
|
+
{ fn: onCommentCreated, action: EnumCommentActions.OnCommentCreated },
|
|
24038
|
+
{ fn: onCommentUpdated, action: EnumCommentActions.OnCommentUpdated },
|
|
24039
|
+
{ fn: onCommentDeleted, action: EnumCommentActions.OnCommentDeleted },
|
|
24040
|
+
{ fn: onCommentFlagged, action: EnumCommentActions.OnCommentFlagged },
|
|
24041
|
+
{ fn: onCommentUnflagged, action: EnumCommentActions.OnCommentUnflagged },
|
|
24042
|
+
{ fn: onCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
|
|
24043
|
+
{ fn: onCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
|
|
24044
|
+
{ fn: onLocalCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
|
|
24045
|
+
{ fn: onLocalCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
|
|
24046
|
+
]);
|
|
24047
|
+
}
|
|
24048
|
+
notifyChange({ origin, loading, error }) {
|
|
24049
|
+
var _a, _b;
|
|
24050
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24051
|
+
if (!collection)
|
|
24052
|
+
return;
|
|
24053
|
+
const data = this.applyFilter((_b = collection.data
|
|
24054
|
+
.map(id => pullFromCache(['comment', 'get', id]))
|
|
24055
|
+
.filter(isNonNullable)
|
|
24056
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.comment);
|
|
24057
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
24058
|
+
return;
|
|
24059
|
+
this.callback({
|
|
24060
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
24061
|
+
data,
|
|
24062
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
24063
|
+
loading,
|
|
24064
|
+
error,
|
|
24065
|
+
});
|
|
24066
|
+
}
|
|
24067
|
+
applyFilter(data) {
|
|
24068
|
+
let comments = data;
|
|
24069
|
+
if (!this.query.includeDeleted) {
|
|
24070
|
+
comments = filterByPropEquality(comments, 'isDeleted', false);
|
|
24071
|
+
}
|
|
24072
|
+
if (this.query.parentId) {
|
|
24073
|
+
comments = comments.filter(comment => comment.parentId === this.query.parentId);
|
|
24074
|
+
}
|
|
24075
|
+
if (typeof this.query.hasFlag === 'boolean') {
|
|
24076
|
+
if (this.query.hasFlag) {
|
|
24077
|
+
comments = comments.filter(comment => comment.hashFlag != null);
|
|
24078
|
+
}
|
|
24079
|
+
else {
|
|
24080
|
+
comments = comments.filter(comment => comment.hashFlag == null);
|
|
24081
|
+
}
|
|
24082
|
+
}
|
|
24083
|
+
if (this.query.dataTypes) {
|
|
24084
|
+
if (this.query.dataTypes.matchType === 'exact') {
|
|
24085
|
+
comments = comments.filter(comment => {
|
|
24086
|
+
var _a, _b;
|
|
24087
|
+
const sortedDataTypesQueryValue = ((_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.values.sort()) || [];
|
|
24088
|
+
const sortedDataTypesCommentValue = ((_b = comment.dataTypes) === null || _b === void 0 ? void 0 : _b.sort()) || [];
|
|
24089
|
+
if (sortedDataTypesCommentValue.length !== sortedDataTypesQueryValue.length) {
|
|
24090
|
+
return false;
|
|
24091
|
+
}
|
|
24092
|
+
return sortedDataTypesQueryValue.every((value, index) => value === sortedDataTypesCommentValue[index]);
|
|
24093
|
+
});
|
|
24094
|
+
}
|
|
24095
|
+
if (this.query.dataTypes.matchType === 'any') {
|
|
24096
|
+
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); }); });
|
|
24097
|
+
}
|
|
24098
|
+
}
|
|
24099
|
+
switch (this.query.sortBy) {
|
|
24100
|
+
case 'firstCreated':
|
|
24101
|
+
comments = comments.sort(sortByFirstCreated);
|
|
24102
|
+
break;
|
|
24103
|
+
case 'lastCreated':
|
|
24104
|
+
default:
|
|
24105
|
+
comments = comments.sort(sortByLastCreated);
|
|
24106
|
+
break;
|
|
24107
|
+
}
|
|
24108
|
+
return comments;
|
|
24109
|
+
}
|
|
24110
|
+
}
|
|
24042
24111
|
|
|
24043
24112
|
/* begin_public_function
|
|
24044
|
-
id: comment.
|
|
24113
|
+
id: comment.query
|
|
24045
24114
|
*/
|
|
24046
24115
|
/**
|
|
24047
24116
|
* ```js
|
|
24048
|
-
* import {
|
|
24049
|
-
*
|
|
24117
|
+
* import { getComments } from '@amityco/ts-sdk'
|
|
24118
|
+
*
|
|
24119
|
+
* let comments = []
|
|
24120
|
+
* const unsub = getComments({
|
|
24121
|
+
* referenceType: Amity.InternalComment['referenceType'];
|
|
24122
|
+
* referenceId: Amity.InternalComment['referenceId'];
|
|
24123
|
+
* }, response => merge(comments, response.data))
|
|
24050
24124
|
* ```
|
|
24051
24125
|
*
|
|
24052
|
-
*
|
|
24126
|
+
* Observe all mutations on a list of {@link Amity.InternalComment} for a given target object
|
|
24053
24127
|
*
|
|
24054
|
-
* @param
|
|
24055
|
-
* @
|
|
24128
|
+
* @param referenceType the type of the target
|
|
24129
|
+
* @param referenceId the ID of the target
|
|
24130
|
+
* @param callback the function to call when new data are available
|
|
24131
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
24056
24132
|
*
|
|
24057
|
-
* @category
|
|
24058
|
-
* @async
|
|
24133
|
+
* @category Comments Live Collection
|
|
24059
24134
|
*/
|
|
24060
|
-
const
|
|
24061
|
-
const
|
|
24062
|
-
|
|
24063
|
-
|
|
24064
|
-
|
|
24135
|
+
const getComments = (params, callback, config) => {
|
|
24136
|
+
const { log, cache } = getActiveClient();
|
|
24137
|
+
if (!cache) {
|
|
24138
|
+
console.log('For using Live Collection feature you need to enable Cache!');
|
|
24139
|
+
}
|
|
24140
|
+
const timestamp = Date.now();
|
|
24141
|
+
log(`getComments(tmpid: ${timestamp}) > listen`);
|
|
24142
|
+
const commentsLiveCollection = new CommentLiveCollectionController(params, callback);
|
|
24143
|
+
const disposers = commentsLiveCollection.startSubscription();
|
|
24144
|
+
const cacheKey = commentsLiveCollection.getCacheKey();
|
|
24145
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
24146
|
+
return () => {
|
|
24147
|
+
log(`getComments(tmpid: ${timestamp}) > dispose`);
|
|
24148
|
+
disposers.forEach(fn => fn());
|
|
24149
|
+
};
|
|
24065
24150
|
};
|
|
24066
24151
|
/* end_public_function */
|
|
24067
24152
|
|
|
24068
|
-
|
|
24069
|
-
|
|
24070
|
-
|
|
24071
|
-
|
|
24072
|
-
|
|
24073
|
-
|
|
24074
|
-
|
|
24075
|
-
|
|
24076
|
-
|
|
24077
|
-
|
|
24078
|
-
|
|
24079
|
-
|
|
24080
|
-
|
|
24081
|
-
|
|
24082
|
-
|
|
24083
|
-
|
|
24084
|
-
|
|
24085
|
-
|
|
24086
|
-
|
|
24087
|
-
|
|
24088
|
-
|
|
24089
|
-
const body = {
|
|
24090
|
-
reason: reason && isPredefinedReason ? reason : exports.ContentFlagReasonEnum.Others,
|
|
24091
|
-
detail: reason && !isPredefinedReason ? reason : '',
|
|
24092
|
-
};
|
|
24093
|
-
const { data: payload } = await client.http.post(`/api/v3/comments/${encodeURIComponent(commentId)}/flag`, body);
|
|
24094
|
-
if (client.cache) {
|
|
24095
|
-
ingestInCache(payload);
|
|
24096
|
-
}
|
|
24097
|
-
fireEvent('comment.flagged', payload);
|
|
24098
|
-
return !!payload;
|
|
24099
|
-
};
|
|
24100
|
-
/* end_public_function */
|
|
24101
|
-
|
|
24102
|
-
/* begin_public_function
|
|
24103
|
-
id: comment.unflag
|
|
24104
|
-
*/
|
|
24105
|
-
/**
|
|
24106
|
-
* ```js
|
|
24107
|
-
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
24108
|
-
* const unflagged = await CommentRepository.unflagComment('commentId')
|
|
24109
|
-
* ```
|
|
24110
|
-
*
|
|
24111
|
-
* @param commentId The ID of comment to unflag
|
|
24112
|
-
* @returns the unflagged result
|
|
24113
|
-
*
|
|
24114
|
-
* @category Comment API
|
|
24115
|
-
* @async
|
|
24116
|
-
* */
|
|
24117
|
-
const unflagComment = async (commentId) => {
|
|
24118
|
-
const client = getActiveClient();
|
|
24119
|
-
client.log('comment/unflagComment', commentId);
|
|
24120
|
-
const { data: payload } = await client.http.delete(`/api/v3/comments/${encodeURIComponent(commentId)}/unflag`);
|
|
24121
|
-
if (client.cache) {
|
|
24122
|
-
ingestInCache(payload);
|
|
24123
|
-
}
|
|
24124
|
-
fireEvent('comment.unflagged', payload);
|
|
24125
|
-
return !!payload;
|
|
24126
|
-
};
|
|
24127
|
-
/* end_public_function */
|
|
24128
|
-
|
|
24129
|
-
/* begin_public_function
|
|
24130
|
-
id: comment.check_flag_by_me
|
|
24131
|
-
*/
|
|
24132
|
-
/**
|
|
24133
|
-
* ```js
|
|
24134
|
-
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
24135
|
-
* const isReported = await CommentRepository.isCommentFlaggedByMe('commentId')
|
|
24136
|
-
* ```
|
|
24137
|
-
*
|
|
24138
|
-
* @param commentId The ID of the comment to check if flagged by current user
|
|
24139
|
-
* @returns `true` if the comment is flagged by me, `false` if doesn't.
|
|
24140
|
-
*
|
|
24141
|
-
* @category Comment API
|
|
24142
|
-
* @async
|
|
24143
|
-
* */
|
|
24144
|
-
const isCommentFlaggedByMe = async (commentId) => {
|
|
24145
|
-
const client = getActiveClient();
|
|
24146
|
-
client.log('comment/isCommentFlaggedByMe', commentId);
|
|
24147
|
-
const { data: { result }, } = await client.http.get(`/api/v3/comments/${commentId}/isflagbyme`);
|
|
24148
|
-
return result;
|
|
24149
|
-
};
|
|
24150
|
-
/* end_public_function */
|
|
24153
|
+
var index$a = /*#__PURE__*/Object.freeze({
|
|
24154
|
+
__proto__: null,
|
|
24155
|
+
getCommentByIds: getCommentByIds,
|
|
24156
|
+
createComment: createComment,
|
|
24157
|
+
updateComment: updateComment,
|
|
24158
|
+
deleteComment: deleteComment,
|
|
24159
|
+
softDeleteComment: softDeleteComment,
|
|
24160
|
+
hardDeleteComment: hardDeleteComment,
|
|
24161
|
+
flagComment: flagComment,
|
|
24162
|
+
unflagComment: unflagComment,
|
|
24163
|
+
isCommentFlaggedByMe: isCommentFlaggedByMe,
|
|
24164
|
+
onCommentCreated: onCommentCreated,
|
|
24165
|
+
onCommentUpdated: onCommentUpdated,
|
|
24166
|
+
onCommentDeleted: onCommentDeleted,
|
|
24167
|
+
onCommentFlagged: onCommentFlagged,
|
|
24168
|
+
onCommentUnflagged: onCommentUnflagged,
|
|
24169
|
+
onCommentReactionAdded: onCommentReactionAdded,
|
|
24170
|
+
onCommentReactionRemoved: onCommentReactionRemoved,
|
|
24171
|
+
getComment: getComment,
|
|
24172
|
+
getComments: getComments
|
|
24173
|
+
});
|
|
24151
24174
|
|
|
24152
|
-
const
|
|
24175
|
+
const getPost$1 = async (postId) => {
|
|
24153
24176
|
const client = getActiveClient();
|
|
24154
|
-
client.log('
|
|
24155
|
-
isInTombstone('
|
|
24156
|
-
let
|
|
24177
|
+
client.log('post/getPost', postId);
|
|
24178
|
+
isInTombstone('post', postId);
|
|
24179
|
+
let payload;
|
|
24157
24180
|
try {
|
|
24158
24181
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
24159
|
-
const response = await client.http.get(`/api/v3/
|
|
24160
|
-
|
|
24182
|
+
const response = await client.http.get(`/api/v3/posts/${encodeURIComponent(postId)}`);
|
|
24183
|
+
payload = response.data;
|
|
24161
24184
|
}
|
|
24162
24185
|
catch (error) {
|
|
24163
24186
|
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
24164
|
-
pushToTombstone('
|
|
24187
|
+
pushToTombstone('post', postId);
|
|
24165
24188
|
}
|
|
24166
24189
|
throw error;
|
|
24167
24190
|
}
|
|
24191
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
24168
24192
|
const cachedAt = client.cache && Date.now();
|
|
24169
24193
|
if (client.cache)
|
|
24170
24194
|
ingestInCache(data, { cachedAt });
|
|
24171
|
-
const {
|
|
24195
|
+
const { posts } = data;
|
|
24196
|
+
const result = posts.find(post => post.postId === postId);
|
|
24172
24197
|
return {
|
|
24173
|
-
data:
|
|
24198
|
+
data: result,
|
|
24174
24199
|
cachedAt,
|
|
24175
24200
|
};
|
|
24176
24201
|
};
|
|
24177
|
-
|
|
24202
|
+
getPost$1.locally = (postId) => {
|
|
24178
24203
|
const client = getActiveClient();
|
|
24179
|
-
client.log('
|
|
24204
|
+
client.log('post/getPost.locally', postId);
|
|
24180
24205
|
if (!client.cache)
|
|
24181
24206
|
return;
|
|
24182
|
-
const cached = pullFromCache(['
|
|
24207
|
+
const cached = pullFromCache(['post', 'get', postId]);
|
|
24183
24208
|
if (!cached)
|
|
24184
24209
|
return;
|
|
24185
24210
|
return {
|
|
@@ -24190,224 +24215,106 @@ getComment$1.locally = (commentId) => {
|
|
|
24190
24215
|
|
|
24191
24216
|
/**
|
|
24192
24217
|
* ```js
|
|
24193
|
-
* import {
|
|
24194
|
-
* const dispose =
|
|
24218
|
+
* import { onPostUpdatedLocal } from '@amityco/ts-sdk'
|
|
24219
|
+
* const dispose = onPostUpdatedLocal(post => {
|
|
24195
24220
|
* // ...
|
|
24196
24221
|
* })
|
|
24197
24222
|
* ```
|
|
24198
24223
|
*
|
|
24199
|
-
* Fired when a {@link Amity.
|
|
24224
|
+
* Fired when a {@link Amity.InternalPost} has been updated
|
|
24200
24225
|
*
|
|
24201
24226
|
* @param callback The function to call when the event was fired
|
|
24202
24227
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
24203
24228
|
*
|
|
24204
|
-
* @category
|
|
24229
|
+
* @category Post Events
|
|
24205
24230
|
*/
|
|
24206
|
-
const
|
|
24231
|
+
const onPostUpdatedLocal = (callback) => createLocalPostEventSubscriber('local.post.updated', callback);
|
|
24207
24232
|
|
|
24208
24233
|
/**
|
|
24209
24234
|
* ```js
|
|
24210
|
-
* import {
|
|
24211
|
-
* const dispose =
|
|
24235
|
+
* import { onLocalPostReactionAdded } from '@amityco/ts-sdk'
|
|
24236
|
+
* const dispose = onPostReactionAdded(post => {
|
|
24212
24237
|
* // ...
|
|
24213
24238
|
* })
|
|
24214
24239
|
* ```
|
|
24215
24240
|
*
|
|
24216
|
-
* Fired when a {@link Amity.
|
|
24241
|
+
* Fired when a {@link Amity.InternalPost} has been reacted
|
|
24217
24242
|
*
|
|
24218
24243
|
* @param callback The function to call when the event was fired
|
|
24219
24244
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
24220
24245
|
*
|
|
24221
|
-
* @category
|
|
24246
|
+
* @category Post Events
|
|
24222
24247
|
*/
|
|
24223
|
-
const
|
|
24248
|
+
const onLocalPostReactionAdded = (callback) => {
|
|
24224
24249
|
const client = getActiveClient();
|
|
24225
|
-
const filter = ({
|
|
24250
|
+
const filter = ({ post }) => {
|
|
24226
24251
|
if (!client.cache) {
|
|
24227
|
-
callback(
|
|
24252
|
+
callback(post);
|
|
24228
24253
|
}
|
|
24229
24254
|
else {
|
|
24230
|
-
upsertInCache(['
|
|
24231
|
-
callback(
|
|
24255
|
+
upsertInCache(['post', 'get', post.postId], post);
|
|
24256
|
+
callback(post);
|
|
24232
24257
|
}
|
|
24233
24258
|
};
|
|
24234
|
-
return createEventSubscriber(client, 'local.
|
|
24259
|
+
return createEventSubscriber(client, 'local.post.addReaction', 'local.post.addReaction', filter);
|
|
24235
24260
|
};
|
|
24236
24261
|
|
|
24237
24262
|
/**
|
|
24238
24263
|
* ```js
|
|
24239
|
-
* import {
|
|
24240
|
-
* const dispose =
|
|
24264
|
+
* import { onLocalPostReactionRemoved } from '@amityco/ts-sdk'
|
|
24265
|
+
* const dispose = onPostReactionRemoved(post => {
|
|
24241
24266
|
* // ...
|
|
24242
24267
|
* })
|
|
24243
24268
|
* ```
|
|
24244
24269
|
*
|
|
24245
|
-
* Fired when a {@link Amity.
|
|
24270
|
+
* Fired when a {@link Amity.InternalPost} has been reacted
|
|
24246
24271
|
*
|
|
24247
24272
|
* @param callback The function to call when the event was fired
|
|
24248
24273
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
24249
24274
|
*
|
|
24250
|
-
* @category
|
|
24275
|
+
* @category Post Events
|
|
24251
24276
|
*/
|
|
24252
|
-
const
|
|
24277
|
+
const onLocalPostReactionRemoved = (callback) => {
|
|
24253
24278
|
const client = getActiveClient();
|
|
24254
|
-
const filter = ({
|
|
24279
|
+
const filter = ({ post }) => {
|
|
24255
24280
|
if (!client.cache) {
|
|
24256
|
-
callback(
|
|
24281
|
+
callback(post);
|
|
24257
24282
|
}
|
|
24258
24283
|
else {
|
|
24259
|
-
upsertInCache(['
|
|
24260
|
-
callback(
|
|
24284
|
+
upsertInCache(['post', 'get', post.postId], post);
|
|
24285
|
+
callback(post);
|
|
24261
24286
|
}
|
|
24262
24287
|
};
|
|
24263
|
-
return createEventSubscriber(client, 'local.
|
|
24288
|
+
return createEventSubscriber(client, 'local.post.removeReaction', 'local.post.removeReaction', filter);
|
|
24264
24289
|
};
|
|
24265
24290
|
|
|
24266
|
-
/* begin_public_function
|
|
24267
|
-
id: comment.get
|
|
24268
|
-
*/
|
|
24269
24291
|
/**
|
|
24270
24292
|
* ```js
|
|
24271
|
-
* import {
|
|
24272
|
-
*
|
|
24273
|
-
*
|
|
24274
|
-
*
|
|
24275
|
-
* const unsub = CommentRepository.getComment(commentId, response => {
|
|
24276
|
-
* comment = response.data;
|
|
24277
|
-
* });
|
|
24293
|
+
* import { onLocalPostDeleted } from '@amityco/ts-sdk'
|
|
24294
|
+
* const dispose = onLocalPostDeleted(post => {
|
|
24295
|
+
* // ...
|
|
24296
|
+
* })
|
|
24278
24297
|
* ```
|
|
24279
24298
|
*
|
|
24280
|
-
*
|
|
24299
|
+
* Fired when a {@link Amity.InternalPost} has been deleted
|
|
24281
24300
|
*
|
|
24282
|
-
* @param
|
|
24283
|
-
* @
|
|
24284
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the comment
|
|
24301
|
+
* @param callback The function to call when the event was fired
|
|
24302
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
24285
24303
|
*
|
|
24286
|
-
* @category
|
|
24304
|
+
* @category Post Events
|
|
24287
24305
|
*/
|
|
24288
|
-
const
|
|
24289
|
-
return liveObject(commentId, callback, 'commentId', getComment$1, [
|
|
24290
|
-
onCommentDeleteLocal,
|
|
24291
|
-
onCommentDeleted,
|
|
24292
|
-
onCommentFlagged,
|
|
24293
|
-
onCommentReactionAdded,
|
|
24294
|
-
onCommentReactionRemoved,
|
|
24295
|
-
onCommentUnflagged,
|
|
24296
|
-
onCommentUpdated,
|
|
24297
|
-
onLocalCommentReactionAdded,
|
|
24298
|
-
onLocalCommentReactionRemoved,
|
|
24299
|
-
]);
|
|
24300
|
-
};
|
|
24301
|
-
/* end_public_function */
|
|
24302
|
-
|
|
24303
|
-
class CommentPaginationController extends PaginationController {
|
|
24304
|
-
async getRequest(queryParams, token) {
|
|
24305
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
|
|
24306
|
-
const baseOptions = {
|
|
24307
|
-
type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
|
|
24308
|
-
};
|
|
24309
|
-
const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
|
|
24310
|
-
const { data: queryResponse } = await this.http.get(`/api/v3/comments`, {
|
|
24311
|
-
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options }),
|
|
24312
|
-
});
|
|
24313
|
-
return queryResponse;
|
|
24314
|
-
}
|
|
24315
|
-
}
|
|
24316
|
-
|
|
24317
|
-
var EnumCommentActions;
|
|
24318
|
-
(function (EnumCommentActions) {
|
|
24319
|
-
EnumCommentActions["OnCommentCreated"] = "onCommentCreated";
|
|
24320
|
-
EnumCommentActions["OnCommentUpdated"] = "onCommentUpdated";
|
|
24321
|
-
EnumCommentActions["OnCommentDeleted"] = "onCommentDeleted";
|
|
24322
|
-
EnumCommentActions["OnCommentFlagged"] = "onCommentFlagged";
|
|
24323
|
-
EnumCommentActions["OnCommentUnflagged"] = "onCommentUnflagged";
|
|
24324
|
-
EnumCommentActions["OnCommentReactionAdded"] = "onCommentReactionAdded";
|
|
24325
|
-
EnumCommentActions["OnCommentReactionRemoved"] = "onCommentReactionRemoved";
|
|
24326
|
-
})(EnumCommentActions || (EnumCommentActions = {}));
|
|
24306
|
+
const onLocalPostDeleted = (callback) => createLocalPostEventSubscriber('local.post.deleted', callback);
|
|
24327
24307
|
|
|
24328
|
-
class
|
|
24329
|
-
constructor(query,
|
|
24330
|
-
|
|
24331
|
-
|
|
24332
|
-
|
|
24333
|
-
|
|
24334
|
-
|
|
24335
|
-
|
|
24336
|
-
|
|
24337
|
-
|
|
24338
|
-
if (client.cache) {
|
|
24339
|
-
ingestInCache(processedPayload, { cachedAt });
|
|
24340
|
-
}
|
|
24341
|
-
}
|
|
24342
|
-
appendToQueryStream(response, direction, refresh = false) {
|
|
24343
|
-
var _a, _b;
|
|
24344
|
-
if (refresh) {
|
|
24345
|
-
pushToCache(this.cacheKey, {
|
|
24346
|
-
data: response.comments.map(getResolver('comment')),
|
|
24347
|
-
});
|
|
24348
|
-
}
|
|
24349
|
-
else {
|
|
24350
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24351
|
-
const comments = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
24352
|
-
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...comments, ...response.comments.map(getResolver('comment'))])] }));
|
|
24353
|
-
}
|
|
24354
|
-
}
|
|
24355
|
-
reactor(action) {
|
|
24356
|
-
return (comment) => {
|
|
24357
|
-
var _a;
|
|
24358
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24359
|
-
if (this.query.referenceId !== comment.referenceId ||
|
|
24360
|
-
this.query.referenceType !== comment.referenceType ||
|
|
24361
|
-
!collection) {
|
|
24362
|
-
return;
|
|
24363
|
-
}
|
|
24364
|
-
if (this.query.parentId && this.query.parentId !== comment.parentId) {
|
|
24365
|
-
return;
|
|
24366
|
-
}
|
|
24367
|
-
if (!this.query.parentId && comment.parentId) {
|
|
24368
|
-
return;
|
|
24369
|
-
}
|
|
24370
|
-
if (action === EnumCommentActions.OnCommentCreated) {
|
|
24371
|
-
collection.data = [...new Set([comment.commentId, ...collection.data])];
|
|
24372
|
-
}
|
|
24373
|
-
pushToCache(this.cacheKey, collection);
|
|
24374
|
-
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
24375
|
-
};
|
|
24376
|
-
}
|
|
24377
|
-
subscribeRTE(createSubscriber) {
|
|
24378
|
-
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
24379
|
-
}
|
|
24380
|
-
}
|
|
24381
|
-
|
|
24382
|
-
/**
|
|
24383
|
-
* ```js
|
|
24384
|
-
* import { onCommentCreated } from '@amityco/ts-sdk'
|
|
24385
|
-
* const dispose = onCommentCreated(comment => {
|
|
24386
|
-
* // ...
|
|
24387
|
-
* })
|
|
24388
|
-
* ```
|
|
24389
|
-
*
|
|
24390
|
-
* Fired when a {@link Amity.InternalComment} has been created
|
|
24391
|
-
*
|
|
24392
|
-
* @param callback The function to call when the event was fired
|
|
24393
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
24394
|
-
*
|
|
24395
|
-
* @category Comment Events
|
|
24396
|
-
*/
|
|
24397
|
-
const onCommentCreatedLocal = (callback) => {
|
|
24398
|
-
return createLocalCommentEventSubscriber('local.comment.created', callback);
|
|
24399
|
-
};
|
|
24400
|
-
|
|
24401
|
-
class CommentLiveCollectionController extends LiveCollectionController {
|
|
24402
|
-
constructor(query, callback) {
|
|
24403
|
-
const queryStreamId = hash__default["default"](query);
|
|
24404
|
-
const cacheKey = ['comments', 'collection', queryStreamId];
|
|
24405
|
-
const paginationController = new CommentPaginationController(query);
|
|
24406
|
-
super(paginationController, queryStreamId, cacheKey, callback);
|
|
24407
|
-
this.query = query;
|
|
24408
|
-
this.queryStreamController = new CommentQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommentPayload);
|
|
24409
|
-
this.callback = callback.bind(this);
|
|
24410
|
-
this.loadPage({ initial: true });
|
|
24308
|
+
class UserFeedLiveCollectionController extends LiveCollectionController {
|
|
24309
|
+
constructor(query, callback) {
|
|
24310
|
+
const queryStreamId = hash__default["default"](query);
|
|
24311
|
+
const cacheKey = ['userFeed', 'collection', queryStreamId];
|
|
24312
|
+
const paginationController = new UserFeedPaginationController(query);
|
|
24313
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
24314
|
+
this.query = query;
|
|
24315
|
+
this.queryStreamController = new UserFeedQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
|
|
24316
|
+
this.callback = callback.bind(this);
|
|
24317
|
+
this.loadPage({ initial: true });
|
|
24411
24318
|
}
|
|
24412
24319
|
setup() {
|
|
24413
24320
|
var _a;
|
|
@@ -24427,17 +24334,45 @@ class CommentLiveCollectionController extends LiveCollectionController {
|
|
|
24427
24334
|
}
|
|
24428
24335
|
startSubscription() {
|
|
24429
24336
|
return this.queryStreamController.subscribeRTE([
|
|
24430
|
-
{ fn:
|
|
24431
|
-
{ fn:
|
|
24432
|
-
{ fn:
|
|
24433
|
-
{ fn:
|
|
24434
|
-
{ fn:
|
|
24435
|
-
{ fn:
|
|
24436
|
-
{ fn:
|
|
24437
|
-
{ fn:
|
|
24438
|
-
{ fn:
|
|
24439
|
-
{ fn:
|
|
24440
|
-
{ fn:
|
|
24337
|
+
{ fn: onPostCreated, action: EnumPostActions.OnPostCreated },
|
|
24338
|
+
{ fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
|
|
24339
|
+
{ fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
|
|
24340
|
+
{ fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
|
|
24341
|
+
{ fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
|
|
24342
|
+
{ fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
|
|
24343
|
+
{ fn: onPostApproved, action: EnumPostActions.OnPostApproved },
|
|
24344
|
+
{ fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
|
|
24345
|
+
{ fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
|
|
24346
|
+
{ fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
|
|
24347
|
+
{ fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
|
|
24348
|
+
{ fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
|
|
24349
|
+
{ fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
|
|
24350
|
+
{
|
|
24351
|
+
fn: convertEventPayload((callback) => {
|
|
24352
|
+
return onCommentCreated(async (comment) => {
|
|
24353
|
+
var _a;
|
|
24354
|
+
const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24355
|
+
if (!currentCollection || currentCollection.data.includes(comment.referenceId))
|
|
24356
|
+
return;
|
|
24357
|
+
await getPost$1(comment.referenceId);
|
|
24358
|
+
callback(comment);
|
|
24359
|
+
});
|
|
24360
|
+
}, 'referenceId', 'post'),
|
|
24361
|
+
action: EnumPostActions.OnPostUpdated,
|
|
24362
|
+
},
|
|
24363
|
+
{
|
|
24364
|
+
fn: convertEventPayload((callback) => {
|
|
24365
|
+
return onCommentDeleted(async (comment) => {
|
|
24366
|
+
var _a;
|
|
24367
|
+
const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24368
|
+
if (!currentCollection || currentCollection.data.includes(comment.referenceId))
|
|
24369
|
+
return;
|
|
24370
|
+
await getPost$1(comment.referenceId);
|
|
24371
|
+
callback(comment);
|
|
24372
|
+
});
|
|
24373
|
+
}, 'referenceId', 'post'),
|
|
24374
|
+
action: EnumPostActions.OnPostUpdated,
|
|
24375
|
+
},
|
|
24441
24376
|
]);
|
|
24442
24377
|
}
|
|
24443
24378
|
notifyChange({ origin, loading, error }) {
|
|
@@ -24446,9 +24381,9 @@ class CommentLiveCollectionController extends LiveCollectionController {
|
|
|
24446
24381
|
if (!collection)
|
|
24447
24382
|
return;
|
|
24448
24383
|
const data = this.applyFilter((_b = collection.data
|
|
24449
|
-
.map(id => pullFromCache(['
|
|
24384
|
+
.map(id => pullFromCache(['post', 'get', id]))
|
|
24450
24385
|
.filter(isNonNullable)
|
|
24451
|
-
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.
|
|
24386
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
|
|
24452
24387
|
if (!this.shouldNotify(data) && origin === 'event')
|
|
24453
24388
|
return;
|
|
24454
24389
|
this.callback({
|
|
@@ -24460,86 +24395,64 @@ class CommentLiveCollectionController extends LiveCollectionController {
|
|
|
24460
24395
|
});
|
|
24461
24396
|
}
|
|
24462
24397
|
applyFilter(data) {
|
|
24463
|
-
|
|
24398
|
+
var _a;
|
|
24399
|
+
let posts = data;
|
|
24464
24400
|
if (!this.query.includeDeleted) {
|
|
24465
|
-
|
|
24466
|
-
}
|
|
24467
|
-
if (this.query.parentId) {
|
|
24468
|
-
comments = comments.filter(comment => comment.parentId === this.query.parentId);
|
|
24469
|
-
}
|
|
24470
|
-
if (typeof this.query.hasFlag === 'boolean') {
|
|
24471
|
-
if (this.query.hasFlag) {
|
|
24472
|
-
comments = comments.filter(comment => comment.hashFlag != null);
|
|
24473
|
-
}
|
|
24474
|
-
else {
|
|
24475
|
-
comments = comments.filter(comment => comment.hashFlag == null);
|
|
24476
|
-
}
|
|
24401
|
+
posts = filterByPropEquality(posts, 'isDeleted', false);
|
|
24477
24402
|
}
|
|
24478
|
-
if (this.query.dataTypes) {
|
|
24479
|
-
|
|
24480
|
-
comments = comments.filter(comment => {
|
|
24481
|
-
var _a, _b;
|
|
24482
|
-
const sortedDataTypesQueryValue = ((_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.values.sort()) || [];
|
|
24483
|
-
const sortedDataTypesCommentValue = ((_b = comment.dataTypes) === null || _b === void 0 ? void 0 : _b.sort()) || [];
|
|
24484
|
-
if (sortedDataTypesCommentValue.length !== sortedDataTypesQueryValue.length) {
|
|
24485
|
-
return false;
|
|
24486
|
-
}
|
|
24487
|
-
return sortedDataTypesQueryValue.every((value, index) => value === sortedDataTypesCommentValue[index]);
|
|
24488
|
-
});
|
|
24489
|
-
}
|
|
24490
|
-
if (this.query.dataTypes.matchType === 'any') {
|
|
24491
|
-
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); }); });
|
|
24492
|
-
}
|
|
24403
|
+
if ((_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.length) {
|
|
24404
|
+
posts = filterByPostDataTypes(posts, this.query.dataTypes);
|
|
24493
24405
|
}
|
|
24494
24406
|
switch (this.query.sortBy) {
|
|
24495
24407
|
case 'firstCreated':
|
|
24496
|
-
|
|
24408
|
+
posts = posts.sort(sortByFirstCreated);
|
|
24497
24409
|
break;
|
|
24498
24410
|
case 'lastCreated':
|
|
24499
24411
|
default:
|
|
24500
|
-
|
|
24412
|
+
posts = posts.sort(sortByLastCreated);
|
|
24501
24413
|
break;
|
|
24502
24414
|
}
|
|
24503
|
-
return
|
|
24415
|
+
return posts;
|
|
24504
24416
|
}
|
|
24505
24417
|
}
|
|
24506
24418
|
|
|
24507
24419
|
/* begin_public_function
|
|
24508
|
-
id:
|
|
24420
|
+
id: feed.query.user_feed
|
|
24509
24421
|
*/
|
|
24510
24422
|
/**
|
|
24511
24423
|
* ```js
|
|
24512
|
-
* import {
|
|
24424
|
+
* import { FeedRepository } from '@amityco/ts-sdk'
|
|
24513
24425
|
*
|
|
24514
|
-
* let
|
|
24515
|
-
* const
|
|
24516
|
-
*
|
|
24517
|
-
*
|
|
24518
|
-
* }, response =>
|
|
24426
|
+
* let posts = []
|
|
24427
|
+
* const unsubscribe = FeedRepository.getUserFeed({
|
|
24428
|
+
* userId: string,
|
|
24429
|
+
* feedSources: ['user', 'community'],
|
|
24430
|
+
* }, response => response => processResponse(response))
|
|
24519
24431
|
* ```
|
|
24520
24432
|
*
|
|
24521
|
-
* Observe all mutations on a list of {@link Amity.
|
|
24433
|
+
* Observe all mutations on a list of {@link Amity.Post} for a given user and feedSources
|
|
24522
24434
|
*
|
|
24523
|
-
* @param
|
|
24524
|
-
* @param
|
|
24435
|
+
* @param params.userId the ID of the user
|
|
24436
|
+
* @param params.feedSources the sources of the feed
|
|
24525
24437
|
* @param callback the function to call when new data are available
|
|
24438
|
+
* @param config
|
|
24526
24439
|
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
24527
24440
|
*
|
|
24528
|
-
* @category
|
|
24441
|
+
* @category Posts Live Collection
|
|
24529
24442
|
*/
|
|
24530
|
-
const
|
|
24443
|
+
const getUserFeed = (params, callback, config) => {
|
|
24531
24444
|
const { log, cache } = getActiveClient();
|
|
24532
24445
|
if (!cache) {
|
|
24533
|
-
console.log(
|
|
24446
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
24534
24447
|
}
|
|
24535
24448
|
const timestamp = Date.now();
|
|
24536
|
-
log(`
|
|
24537
|
-
const
|
|
24538
|
-
const disposers =
|
|
24539
|
-
const cacheKey =
|
|
24449
|
+
log(`getUserFeed(tmpid: ${timestamp}) > listen`);
|
|
24450
|
+
const userFeedLiveCollection = new UserFeedLiveCollectionController(params, callback);
|
|
24451
|
+
const disposers = userFeedLiveCollection.startSubscription();
|
|
24452
|
+
const cacheKey = userFeedLiveCollection.getCacheKey();
|
|
24540
24453
|
disposers.push(() => dropFromCache(cacheKey));
|
|
24541
24454
|
return () => {
|
|
24542
|
-
log(`
|
|
24455
|
+
log(`getUserFeed(tmpid: ${timestamp}) > dispose`);
|
|
24543
24456
|
disposers.forEach(fn => fn());
|
|
24544
24457
|
};
|
|
24545
24458
|
};
|
|
@@ -24547,117 +24460,495 @@ const getComments = (params, callback, config) => {
|
|
|
24547
24460
|
|
|
24548
24461
|
var index$9 = /*#__PURE__*/Object.freeze({
|
|
24549
24462
|
__proto__: null,
|
|
24550
|
-
|
|
24551
|
-
|
|
24552
|
-
|
|
24553
|
-
deleteComment: deleteComment,
|
|
24554
|
-
softDeleteComment: softDeleteComment,
|
|
24555
|
-
hardDeleteComment: hardDeleteComment,
|
|
24556
|
-
flagComment: flagComment,
|
|
24557
|
-
unflagComment: unflagComment,
|
|
24558
|
-
isCommentFlaggedByMe: isCommentFlaggedByMe,
|
|
24559
|
-
onCommentCreated: onCommentCreated,
|
|
24560
|
-
onCommentUpdated: onCommentUpdated,
|
|
24561
|
-
onCommentDeleted: onCommentDeleted,
|
|
24562
|
-
onCommentFlagged: onCommentFlagged,
|
|
24563
|
-
onCommentUnflagged: onCommentUnflagged,
|
|
24564
|
-
onCommentReactionAdded: onCommentReactionAdded,
|
|
24565
|
-
onCommentReactionRemoved: onCommentReactionRemoved,
|
|
24566
|
-
getComment: getComment,
|
|
24567
|
-
getComments: getComments
|
|
24463
|
+
queryGlobalFeed: queryGlobalFeed,
|
|
24464
|
+
getCustomRankingGlobalFeed: getCustomRankingGlobalFeed,
|
|
24465
|
+
getUserFeed: getUserFeed
|
|
24568
24466
|
});
|
|
24569
24467
|
|
|
24468
|
+
/* begin_public_function
|
|
24469
|
+
id: post.get_by_ids
|
|
24470
|
+
*/
|
|
24471
|
+
/**
|
|
24472
|
+
* ```js
|
|
24473
|
+
* import { getPostByIds } from '@amityco/ts-sdk'
|
|
24474
|
+
* const { data: posts } = await getPostByIds(['foo', 'bar'])
|
|
24475
|
+
* ```
|
|
24476
|
+
*
|
|
24477
|
+
* Fetches a collection of {@link Amity.Post} objects
|
|
24478
|
+
*
|
|
24479
|
+
* @param postIds the IDs of the {@link Amity.Post} to fetch
|
|
24480
|
+
* @returns the associated collection of {@link Amity.Post} objects
|
|
24481
|
+
*
|
|
24482
|
+
* @category Post API
|
|
24483
|
+
* @async
|
|
24484
|
+
*/
|
|
24485
|
+
const getPostByIds = async (postIds) => {
|
|
24486
|
+
const client = getActiveClient();
|
|
24487
|
+
client.log('post/getPostByIds', postIds);
|
|
24488
|
+
const encodedPostIds = postIds.map(postId => encodeURIComponent(postId));
|
|
24489
|
+
let payload;
|
|
24490
|
+
try {
|
|
24491
|
+
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
24492
|
+
const response = await client.http.get(`/api/v3/posts/list`, {
|
|
24493
|
+
params: { postIds: encodedPostIds },
|
|
24494
|
+
});
|
|
24495
|
+
payload = response.data;
|
|
24496
|
+
}
|
|
24497
|
+
catch (error) {
|
|
24498
|
+
postIds.forEach(postId => {
|
|
24499
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
24500
|
+
pushToTombstone('post', postId);
|
|
24501
|
+
}
|
|
24502
|
+
});
|
|
24503
|
+
throw error;
|
|
24504
|
+
}
|
|
24505
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
24506
|
+
const cachedAt = client.cache && Date.now();
|
|
24507
|
+
if (client.cache)
|
|
24508
|
+
ingestInCache(data, { cachedAt });
|
|
24509
|
+
return {
|
|
24510
|
+
data: data.posts.map(LinkedObject.post),
|
|
24511
|
+
cachedAt,
|
|
24512
|
+
};
|
|
24513
|
+
};
|
|
24514
|
+
/* end_public_function */
|
|
24515
|
+
/**
|
|
24516
|
+
* ```js
|
|
24517
|
+
* import { getPostByIds } from '@amityco/ts-sdk'
|
|
24518
|
+
* const { data: posts } = getPostByIds.locally(['foo', 'bar'])
|
|
24519
|
+
* ```
|
|
24520
|
+
*
|
|
24521
|
+
* Fetches a collection of {@link Amity.Post} objects from cache
|
|
24522
|
+
*
|
|
24523
|
+
* @param postIds the IDs of the {@link Amity.Post} to fetch
|
|
24524
|
+
* @returns the associated collection of {@link Amity.Post} objects
|
|
24525
|
+
*
|
|
24526
|
+
* @category Post API
|
|
24527
|
+
*/
|
|
24528
|
+
getPostByIds.locally = (postIds) => {
|
|
24529
|
+
var _a;
|
|
24530
|
+
const client = getActiveClient();
|
|
24531
|
+
client.log('post/getPostByIds.locally', postIds);
|
|
24532
|
+
if (!client.cache)
|
|
24533
|
+
return;
|
|
24534
|
+
const cached = postIds
|
|
24535
|
+
.map(postId => pullFromCache(['post', 'get', postId]))
|
|
24536
|
+
.filter(Boolean);
|
|
24537
|
+
const posts = cached.map(({ data }) => data);
|
|
24538
|
+
const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
|
|
24539
|
+
if ((cached === null || cached === void 0 ? void 0 : cached.length) < postIds.length)
|
|
24540
|
+
return;
|
|
24541
|
+
return {
|
|
24542
|
+
data: posts.map(LinkedObject.post),
|
|
24543
|
+
cachedAt: oldest.cachedAt,
|
|
24544
|
+
};
|
|
24545
|
+
};
|
|
24546
|
+
|
|
24547
|
+
/* begin_public_function
|
|
24548
|
+
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
|
|
24549
|
+
*/
|
|
24550
|
+
/**
|
|
24551
|
+
* ```js
|
|
24552
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
24553
|
+
* const created = await PostRepository.createPost({
|
|
24554
|
+
* targetType: 'user',
|
|
24555
|
+
* targetId: 'foobar',
|
|
24556
|
+
* data: { text: 'hello world' }
|
|
24557
|
+
* }))
|
|
24558
|
+
* ```
|
|
24559
|
+
*
|
|
24560
|
+
* Creates an {@link Amity.Post}
|
|
24561
|
+
*
|
|
24562
|
+
* @param bundle The data necessary to create a new {@link Amity.Post}
|
|
24563
|
+
* @returns The newly created {@link Amity.Post}
|
|
24564
|
+
*
|
|
24565
|
+
* @category Post API
|
|
24566
|
+
* @async
|
|
24567
|
+
*/
|
|
24568
|
+
const createPost = async (bundle) => {
|
|
24569
|
+
const client = getActiveClient();
|
|
24570
|
+
client.log('post/createPost', bundle);
|
|
24571
|
+
if (!bundle.dataType || ['text', 'image', 'file', 'video'].includes(bundle.dataType)) {
|
|
24572
|
+
// eslint-disable-next-line no-param-reassign
|
|
24573
|
+
delete bundle.dataType;
|
|
24574
|
+
}
|
|
24575
|
+
const { data: payload } = await client.http.post('/api/v4/posts', bundle);
|
|
24576
|
+
fireEvent('post.created', payload);
|
|
24577
|
+
const data = preparePostPayload(payload);
|
|
24578
|
+
const cachedAt = client.cache && Date.now();
|
|
24579
|
+
if (client.cache)
|
|
24580
|
+
ingestInCache(data, { cachedAt });
|
|
24581
|
+
const { posts } = data;
|
|
24582
|
+
return {
|
|
24583
|
+
data: LinkedObject.post(posts[0]),
|
|
24584
|
+
cachedAt,
|
|
24585
|
+
};
|
|
24586
|
+
};
|
|
24587
|
+
/* end_public_function */
|
|
24588
|
+
|
|
24589
|
+
/* begin_public_function
|
|
24590
|
+
id: post.edit, post.edit.custom_post
|
|
24591
|
+
*/
|
|
24592
|
+
/**
|
|
24593
|
+
* ```js
|
|
24594
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
24595
|
+
* const updated = await PostRepository.editPost(postId, {
|
|
24596
|
+
* data: { text: 'hello world' }
|
|
24597
|
+
* })
|
|
24598
|
+
* ```
|
|
24599
|
+
*
|
|
24600
|
+
* Updates an {@link Amity.Post}
|
|
24601
|
+
*
|
|
24602
|
+
* @param postId The ID of the {@link Amity.Post} to edit
|
|
24603
|
+
* @param patch The patch data to apply
|
|
24604
|
+
* @returns the updated {@link Amity.Post} object
|
|
24605
|
+
*
|
|
24606
|
+
* @category Post API
|
|
24607
|
+
* @async
|
|
24608
|
+
*/
|
|
24609
|
+
const editPost = async (postId, patch) => {
|
|
24610
|
+
const client = getActiveClient();
|
|
24611
|
+
client.log('user/editPost', patch);
|
|
24612
|
+
const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, patch);
|
|
24613
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
24614
|
+
const cachedAt = client.cache && Date.now();
|
|
24615
|
+
if (client.cache)
|
|
24616
|
+
ingestInCache(data, { cachedAt });
|
|
24617
|
+
fireEvent('local.post.updated', data);
|
|
24618
|
+
const { posts } = data;
|
|
24619
|
+
return {
|
|
24620
|
+
data: LinkedObject.post(posts.find(post => post.postId === postId)),
|
|
24621
|
+
cachedAt,
|
|
24622
|
+
};
|
|
24623
|
+
};
|
|
24624
|
+
/* end_public_function */
|
|
24625
|
+
|
|
24626
|
+
/**
|
|
24627
|
+
* ```js
|
|
24628
|
+
* import { deletePost } from '@amityco/ts-sdk'
|
|
24629
|
+
* const success = await deletePost('foobar')
|
|
24630
|
+
* ```
|
|
24631
|
+
*
|
|
24632
|
+
* Deletes a {@link Amity.Post}
|
|
24633
|
+
*
|
|
24634
|
+
* @param postId The {@link Amity.Post} ID to delete
|
|
24635
|
+
* @return A success boolean if the {@link Amity.Post} was deleted
|
|
24636
|
+
*
|
|
24637
|
+
* @private
|
|
24638
|
+
* @async
|
|
24639
|
+
*/
|
|
24640
|
+
const deletePost = async (postId, permanent = false) => {
|
|
24641
|
+
var _a;
|
|
24642
|
+
const client = getActiveClient();
|
|
24643
|
+
const post = await getPost$2(postId);
|
|
24644
|
+
await client.http.delete(`/api/v4/posts/${encodeURIComponent(postId)}`, {
|
|
24645
|
+
params: {
|
|
24646
|
+
postId,
|
|
24647
|
+
permanent,
|
|
24648
|
+
},
|
|
24649
|
+
});
|
|
24650
|
+
// there is currently a limitation which doesn't allow us to fire event to tell that community
|
|
24651
|
+
// has been updated. reason is that, when the object is deleted, we don't have its `communityId`
|
|
24652
|
+
// and so we cannot refetch the community or advertise on events. hopefully this should be solved
|
|
24653
|
+
// later when realtime events covers that for us.
|
|
24654
|
+
if (post.data.targetType === 'community') {
|
|
24655
|
+
const community = await getCommunity$1(post.data.targetId);
|
|
24656
|
+
const communityUsersCache = (_a = queryCache(['communityUsers', 'get'])) !== null && _a !== void 0 ? _a : [];
|
|
24657
|
+
const communityUsers = communityUsersCache
|
|
24658
|
+
.filter(({ key }) => {
|
|
24659
|
+
// cache key is ['communityUsers', 'get', `${communityId}#`${userId}`}]
|
|
24660
|
+
if (key[0] !== 'communityUsers')
|
|
24661
|
+
return false;
|
|
24662
|
+
if (key[1] !== 'get')
|
|
24663
|
+
return false;
|
|
24664
|
+
if (typeof key[2] === 'string')
|
|
24665
|
+
return key[2].includes(community.data.communityId);
|
|
24666
|
+
return false;
|
|
24667
|
+
})
|
|
24668
|
+
.map(({ data }) => data);
|
|
24669
|
+
fireEvent('community.updated', {
|
|
24670
|
+
communities: [community.data],
|
|
24671
|
+
categories: [],
|
|
24672
|
+
communityUsers,
|
|
24673
|
+
feeds: [],
|
|
24674
|
+
files: [],
|
|
24675
|
+
users: [],
|
|
24676
|
+
});
|
|
24677
|
+
}
|
|
24678
|
+
// to support hard deletion
|
|
24679
|
+
const deleted = Object.assign(Object.assign({}, post.data), { isDeleted: true });
|
|
24680
|
+
if (permanent) {
|
|
24681
|
+
setTimeout(() => {
|
|
24682
|
+
pushToTombstone('post', postId);
|
|
24683
|
+
}, 0);
|
|
24684
|
+
}
|
|
24685
|
+
else {
|
|
24686
|
+
upsertInCache(['post', 'get', postId], { isDeleted: true });
|
|
24687
|
+
}
|
|
24688
|
+
fireEvent('local.post.deleted', {
|
|
24689
|
+
posts: [deleted],
|
|
24690
|
+
categories: [],
|
|
24691
|
+
comments: [],
|
|
24692
|
+
communities: [],
|
|
24693
|
+
communityUsers: [],
|
|
24694
|
+
feeds: [],
|
|
24695
|
+
files: [],
|
|
24696
|
+
postChildren: [],
|
|
24697
|
+
users: [],
|
|
24698
|
+
videoStreamings: [],
|
|
24699
|
+
});
|
|
24700
|
+
return LinkedObject.post(deleted);
|
|
24701
|
+
};
|
|
24702
|
+
|
|
24703
|
+
/* begin_public_function
|
|
24704
|
+
id: post.soft_delete
|
|
24705
|
+
*/
|
|
24706
|
+
/**
|
|
24707
|
+
* ```js
|
|
24708
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
24709
|
+
* const success = await PostRepository.softDeletePost('foobar')
|
|
24710
|
+
* ```
|
|
24711
|
+
*
|
|
24712
|
+
* Soft deletes a {@link Amity.Post}
|
|
24713
|
+
*
|
|
24714
|
+
* @param postId The {@link Amity.Post} ID to soft delete
|
|
24715
|
+
* @return A success boolean if the {@link Amity.Post} was deleted
|
|
24716
|
+
*
|
|
24717
|
+
* @category Post API
|
|
24718
|
+
* @async
|
|
24719
|
+
*/
|
|
24720
|
+
const softDeletePost = async (postId) => {
|
|
24721
|
+
const client = getActiveClient();
|
|
24722
|
+
client.log('post/softDeletePost', postId);
|
|
24723
|
+
const softDeleted = await deletePost(postId, false);
|
|
24724
|
+
return LinkedObject.post(softDeleted);
|
|
24725
|
+
};
|
|
24726
|
+
/* end_public_function */
|
|
24727
|
+
|
|
24728
|
+
/* begin_public_function
|
|
24729
|
+
id: post.hard_delete
|
|
24730
|
+
*/
|
|
24731
|
+
/**
|
|
24732
|
+
* ```js
|
|
24733
|
+
* import { hardDeletePost } from '@amityco/ts-sdk'
|
|
24734
|
+
* const success = await hardDeletePost('foobar')
|
|
24735
|
+
* ```
|
|
24736
|
+
*
|
|
24737
|
+
* Hard deletes a {@link Amity.Post}
|
|
24738
|
+
*
|
|
24739
|
+
* @param postId The {@link Amity.Post} ID to be hard delete
|
|
24740
|
+
* @return A success boolean if the {@link Amity.Post} was deleted
|
|
24741
|
+
*
|
|
24742
|
+
* @category Post API
|
|
24743
|
+
* @async
|
|
24744
|
+
*/
|
|
24745
|
+
const hardDeletePost = async (postId) => {
|
|
24746
|
+
const client = getActiveClient();
|
|
24747
|
+
client.log('post/hardDeletePost', postId);
|
|
24748
|
+
const hardDeleted = await deletePost(postId, true);
|
|
24749
|
+
return LinkedObject.post(hardDeleted);
|
|
24750
|
+
};
|
|
24751
|
+
/* end_public_function */
|
|
24752
|
+
|
|
24753
|
+
/* begin_public_function
|
|
24754
|
+
id: post.approve
|
|
24755
|
+
*/
|
|
24756
|
+
/**
|
|
24757
|
+
* ```js
|
|
24758
|
+
* import { approvePost } from '@amityco/ts-sdk'
|
|
24759
|
+
*
|
|
24760
|
+
* const { data: post } = await approvePost('postId')
|
|
24761
|
+
* ```
|
|
24762
|
+
*
|
|
24763
|
+
* Approves a {@link Amity.Post}
|
|
24764
|
+
*
|
|
24765
|
+
* @param postId The {@link Amity.Post} ID to be approved
|
|
24766
|
+
* @return A {@link Amity.Post} that was approved
|
|
24767
|
+
*
|
|
24768
|
+
* @category Post API
|
|
24769
|
+
* @async
|
|
24770
|
+
*/
|
|
24771
|
+
const approvePost = async (postId) => {
|
|
24772
|
+
const client = getActiveClient();
|
|
24773
|
+
client.log('post/approvePost', postId);
|
|
24774
|
+
const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/approve`);
|
|
24775
|
+
fireEvent('post.approved', payload);
|
|
24776
|
+
// fire virtual event for community update
|
|
24777
|
+
if (payload.posts[0].targetType === 'community') {
|
|
24778
|
+
fireEvent('community.updated', payload);
|
|
24779
|
+
}
|
|
24780
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
24781
|
+
const cachedAt = client.cache && Date.now();
|
|
24782
|
+
if (client.cache)
|
|
24783
|
+
ingestInCache(data, { cachedAt });
|
|
24784
|
+
return {
|
|
24785
|
+
data: LinkedObject.post(data.posts.find(post => post.postId === postId)),
|
|
24786
|
+
cachedAt,
|
|
24787
|
+
};
|
|
24788
|
+
};
|
|
24789
|
+
/* end_public_function */
|
|
24790
|
+
|
|
24791
|
+
/* begin_public_function
|
|
24792
|
+
id: post.decline
|
|
24793
|
+
*/
|
|
24570
24794
|
/**
|
|
24571
24795
|
* ```js
|
|
24572
|
-
* import {
|
|
24573
|
-
*
|
|
24574
|
-
*
|
|
24575
|
-
* })
|
|
24796
|
+
* import { declinePost } from '@amityco/ts-sdk'
|
|
24797
|
+
*
|
|
24798
|
+
* const {data: post} = await declinePost('postId')
|
|
24576
24799
|
* ```
|
|
24577
24800
|
*
|
|
24578
|
-
*
|
|
24801
|
+
* Declines a {@link Amity.Post}
|
|
24579
24802
|
*
|
|
24580
|
-
* @param
|
|
24581
|
-
* @
|
|
24803
|
+
* @param postId The {@link Amity.Post} ID to be declined
|
|
24804
|
+
* @return A {@link Amity.Post} that was declined
|
|
24582
24805
|
*
|
|
24583
|
-
* @category Post
|
|
24806
|
+
* @category Post API
|
|
24807
|
+
* @async
|
|
24584
24808
|
*/
|
|
24585
|
-
const
|
|
24809
|
+
const declinePost = async (postId) => {
|
|
24810
|
+
const client = getActiveClient();
|
|
24811
|
+
client.log('post/declinePost', postId);
|
|
24812
|
+
const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/decline`);
|
|
24813
|
+
// fire virtual event
|
|
24814
|
+
if (payload.posts[0].targetType === 'community') {
|
|
24815
|
+
fireEvent('community.updated', payload);
|
|
24816
|
+
}
|
|
24817
|
+
fireEvent('post.declined', payload);
|
|
24818
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
24819
|
+
const cachedAt = client.cache && Date.now();
|
|
24820
|
+
if (client.cache)
|
|
24821
|
+
ingestInCache(data, { cachedAt });
|
|
24822
|
+
return {
|
|
24823
|
+
data: LinkedObject.post(payload.posts.find(post => post.postId === postId)),
|
|
24824
|
+
cachedAt,
|
|
24825
|
+
};
|
|
24826
|
+
};
|
|
24827
|
+
/* end_public_function */
|
|
24586
24828
|
|
|
24829
|
+
/* begin_public_function
|
|
24830
|
+
id: post.flag
|
|
24831
|
+
*/
|
|
24587
24832
|
/**
|
|
24588
24833
|
* ```js
|
|
24589
|
-
* import {
|
|
24590
|
-
* const
|
|
24591
|
-
* // ...
|
|
24592
|
-
* })
|
|
24834
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
24835
|
+
* const flagged = await PostRepository.flagPost(postId, reason)
|
|
24593
24836
|
* ```
|
|
24594
24837
|
*
|
|
24595
|
-
*
|
|
24596
|
-
*
|
|
24597
|
-
* @
|
|
24598
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
24838
|
+
* @param postId of the post to flag
|
|
24839
|
+
* @param reason the reason to flag the post
|
|
24840
|
+
* @returns a boolean
|
|
24599
24841
|
*
|
|
24600
|
-
* @category Post
|
|
24601
|
-
|
|
24602
|
-
|
|
24842
|
+
* @category Post API
|
|
24843
|
+
* @async
|
|
24844
|
+
* */
|
|
24845
|
+
const flagPost = async (postId, reason) => {
|
|
24603
24846
|
const client = getActiveClient();
|
|
24604
|
-
|
|
24605
|
-
|
|
24606
|
-
|
|
24607
|
-
|
|
24608
|
-
|
|
24609
|
-
|
|
24610
|
-
callback(post);
|
|
24611
|
-
}
|
|
24847
|
+
client.log('post/flagPost', postId);
|
|
24848
|
+
const isPredefinedReason = reason &&
|
|
24849
|
+
Object.entries(exports.ContentFlagReasonEnum).some(([key, value]) => key !== exports.ContentFlagReasonEnum.Others && value === reason);
|
|
24850
|
+
const body = {
|
|
24851
|
+
reason: reason && isPredefinedReason ? reason : exports.ContentFlagReasonEnum.Others,
|
|
24852
|
+
detail: reason && !isPredefinedReason ? reason : '',
|
|
24612
24853
|
};
|
|
24613
|
-
|
|
24854
|
+
const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/flag`, body);
|
|
24855
|
+
if (client.cache) {
|
|
24856
|
+
ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
|
|
24857
|
+
}
|
|
24858
|
+
fireEvent('post.flagged', payload);
|
|
24859
|
+
return !!payload;
|
|
24614
24860
|
};
|
|
24861
|
+
/* end_public_function */
|
|
24615
24862
|
|
|
24863
|
+
/* begin_public_function
|
|
24864
|
+
id: post.unflag
|
|
24865
|
+
*/
|
|
24616
24866
|
/**
|
|
24617
24867
|
* ```js
|
|
24618
|
-
* import {
|
|
24619
|
-
* const
|
|
24620
|
-
* // ...
|
|
24621
|
-
* })
|
|
24868
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
24869
|
+
* const unflagged = await PostRepository.unflagPost(postId)
|
|
24622
24870
|
* ```
|
|
24623
24871
|
*
|
|
24624
|
-
*
|
|
24872
|
+
* @param postId of the post to unflag
|
|
24873
|
+
* @returns the unflag post result
|
|
24625
24874
|
*
|
|
24626
|
-
* @
|
|
24627
|
-
* @
|
|
24875
|
+
* @category Post API
|
|
24876
|
+
* @async
|
|
24877
|
+
* */
|
|
24878
|
+
const unflagPost = async (postId) => {
|
|
24879
|
+
const client = getActiveClient();
|
|
24880
|
+
client.log('post/unflagPost', postId);
|
|
24881
|
+
const { data: payload } = await client.http.delete(`/api/v3/posts/${encodeURIComponent(postId)}/unflag`);
|
|
24882
|
+
if (client.cache) {
|
|
24883
|
+
ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
|
|
24884
|
+
}
|
|
24885
|
+
fireEvent('post.unflagged', payload);
|
|
24886
|
+
return !!payload;
|
|
24887
|
+
};
|
|
24888
|
+
/* end_public_function */
|
|
24889
|
+
|
|
24890
|
+
/* begin_public_function
|
|
24891
|
+
id: post.check_flag_by_me
|
|
24892
|
+
*/
|
|
24893
|
+
/**
|
|
24894
|
+
* ```js
|
|
24895
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
24896
|
+
* const isReported = await PostRepository.isPostFlaggedByMe('post', postId)
|
|
24897
|
+
* ```
|
|
24628
24898
|
*
|
|
24629
|
-
* @
|
|
24630
|
-
|
|
24631
|
-
|
|
24899
|
+
* @param postId of the post to check if flagged by current user
|
|
24900
|
+
* @returns `true` if the post is flagged by me, `false` if doesn't.
|
|
24901
|
+
*
|
|
24902
|
+
* @category Post API
|
|
24903
|
+
* @async
|
|
24904
|
+
* */
|
|
24905
|
+
const isPostFlaggedByMe = async (postId) => {
|
|
24632
24906
|
const client = getActiveClient();
|
|
24633
|
-
|
|
24634
|
-
|
|
24635
|
-
|
|
24636
|
-
}
|
|
24637
|
-
else {
|
|
24638
|
-
upsertInCache(['post', 'get', post.postId], post);
|
|
24639
|
-
callback(post);
|
|
24640
|
-
}
|
|
24641
|
-
};
|
|
24642
|
-
return createEventSubscriber(client, 'local.post.removeReaction', 'local.post.removeReaction', filter);
|
|
24907
|
+
client.log('post/isPostFlaggedByMe', postId);
|
|
24908
|
+
const { data: { result }, } = await client.http.get(`/api/v3/posts/${postId}/isflagbyme`);
|
|
24909
|
+
return result;
|
|
24643
24910
|
};
|
|
24911
|
+
/* end_public_function */
|
|
24644
24912
|
|
|
24913
|
+
/* begin_public_function
|
|
24914
|
+
id: post.create.clip_post
|
|
24915
|
+
*/
|
|
24645
24916
|
/**
|
|
24646
24917
|
* ```js
|
|
24647
|
-
* import {
|
|
24648
|
-
* const
|
|
24649
|
-
*
|
|
24650
|
-
*
|
|
24918
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
24919
|
+
* const created = await PostRepository.createClipPost({
|
|
24920
|
+
* targetType: 'user',
|
|
24921
|
+
* targetId: 'foobar',
|
|
24922
|
+
* dataType: 'clip',
|
|
24923
|
+
* data: { text: 'hello world' },
|
|
24924
|
+
* attachments: [{ type: 'clip', fileId: 'fileId123', displayMode: 'fill', isMuted: false }]
|
|
24925
|
+
* }))
|
|
24651
24926
|
* ```
|
|
24652
24927
|
*
|
|
24653
|
-
*
|
|
24928
|
+
* Creates an {@link Amity.Post}
|
|
24654
24929
|
*
|
|
24655
|
-
* @param
|
|
24656
|
-
* @returns
|
|
24930
|
+
* @param bundle The data necessary to create a new {@link Amity.Post}
|
|
24931
|
+
* @returns The newly created {@link Amity.Post}
|
|
24657
24932
|
*
|
|
24658
|
-
* @category Post
|
|
24933
|
+
* @category Post API
|
|
24934
|
+
* @async
|
|
24659
24935
|
*/
|
|
24660
|
-
const
|
|
24936
|
+
const createClipPost = async (bundle) => {
|
|
24937
|
+
const client = getActiveClient();
|
|
24938
|
+
client.log('post/createPost', bundle);
|
|
24939
|
+
const { data: payload } = await client.http.post('/api/v4/posts', bundle);
|
|
24940
|
+
fireEvent('post.created', payload);
|
|
24941
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
24942
|
+
const cachedAt = client.cache && Date.now();
|
|
24943
|
+
if (client.cache)
|
|
24944
|
+
ingestInCache(data, { cachedAt });
|
|
24945
|
+
const { posts } = data;
|
|
24946
|
+
return {
|
|
24947
|
+
data: LinkedObject.post(posts[0]),
|
|
24948
|
+
cachedAt,
|
|
24949
|
+
};
|
|
24950
|
+
};
|
|
24951
|
+
/* end_public_function */
|
|
24661
24952
|
|
|
24662
24953
|
/* begin_public_function
|
|
24663
24954
|
id: post.get
|
|
@@ -24681,7 +24972,7 @@ const onLocalPostDeleted = (callback) => createLocalPostEventSubscriber('local.p
|
|
|
24681
24972
|
*
|
|
24682
24973
|
* @category Post Live Object
|
|
24683
24974
|
*/
|
|
24684
|
-
const getPost
|
|
24975
|
+
const getPost = (postId, callback) => {
|
|
24685
24976
|
const responder = (snapshot) => {
|
|
24686
24977
|
const { data } = snapshot;
|
|
24687
24978
|
callback(Object.assign(Object.assign({}, snapshot), { data: data ? LinkedObject.post(snapshot.data) : data }));
|
|
@@ -24770,19 +25061,6 @@ class PostPaginationController extends PaginationController {
|
|
|
24770
25061
|
}
|
|
24771
25062
|
}
|
|
24772
25063
|
|
|
24773
|
-
var EnumPostActions;
|
|
24774
|
-
(function (EnumPostActions) {
|
|
24775
|
-
EnumPostActions["OnPostCreated"] = "onPostCreated";
|
|
24776
|
-
EnumPostActions["OnPostUpdated"] = "onPostUpdated";
|
|
24777
|
-
EnumPostActions["OnPostDeleted"] = "onPostDeleted";
|
|
24778
|
-
EnumPostActions["OnPostFlagged"] = "onPostFlagged";
|
|
24779
|
-
EnumPostActions["OnPostUnflagged"] = "onPostUnflagged";
|
|
24780
|
-
EnumPostActions["OnPostReactionAdded"] = "onPostReactionAdded";
|
|
24781
|
-
EnumPostActions["OnPostReactionRemoved"] = "onPostReactionRemoved";
|
|
24782
|
-
EnumPostActions["OnPostApproved"] = "onPostApproved";
|
|
24783
|
-
EnumPostActions["OnPostDeclined"] = "onPostDeclined";
|
|
24784
|
-
})(EnumPostActions || (EnumPostActions = {}));
|
|
24785
|
-
|
|
24786
25064
|
class PostQueryStreamController extends QueryStreamController {
|
|
24787
25065
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
24788
25066
|
super(query, cacheKey);
|
|
@@ -24848,47 +25126,6 @@ class PostQueryStreamController extends QueryStreamController {
|
|
|
24848
25126
|
}
|
|
24849
25127
|
}
|
|
24850
25128
|
|
|
24851
|
-
const getPost = async (postId) => {
|
|
24852
|
-
const client = getActiveClient();
|
|
24853
|
-
client.log('post/getPost', postId);
|
|
24854
|
-
isInTombstone('post', postId);
|
|
24855
|
-
let payload;
|
|
24856
|
-
try {
|
|
24857
|
-
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
24858
|
-
const response = await client.http.get(`/api/v3/posts/${encodeURIComponent(postId)}`);
|
|
24859
|
-
payload = response.data;
|
|
24860
|
-
}
|
|
24861
|
-
catch (error) {
|
|
24862
|
-
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
24863
|
-
pushToTombstone('post', postId);
|
|
24864
|
-
}
|
|
24865
|
-
throw error;
|
|
24866
|
-
}
|
|
24867
|
-
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
24868
|
-
const cachedAt = client.cache && Date.now();
|
|
24869
|
-
if (client.cache)
|
|
24870
|
-
ingestInCache(data, { cachedAt });
|
|
24871
|
-
const { posts } = data;
|
|
24872
|
-
const result = posts.find(post => post.postId === postId);
|
|
24873
|
-
return {
|
|
24874
|
-
data: result,
|
|
24875
|
-
cachedAt,
|
|
24876
|
-
};
|
|
24877
|
-
};
|
|
24878
|
-
getPost.locally = (postId) => {
|
|
24879
|
-
const client = getActiveClient();
|
|
24880
|
-
client.log('post/getPost.locally', postId);
|
|
24881
|
-
if (!client.cache)
|
|
24882
|
-
return;
|
|
24883
|
-
const cached = pullFromCache(['post', 'get', postId]);
|
|
24884
|
-
if (!cached)
|
|
24885
|
-
return;
|
|
24886
|
-
return {
|
|
24887
|
-
data: cached.data,
|
|
24888
|
-
cachedAt: cached.cachedAt,
|
|
24889
|
-
};
|
|
24890
|
-
};
|
|
24891
|
-
|
|
24892
25129
|
class PostLiveCollectionController extends LiveCollectionController {
|
|
24893
25130
|
constructor(query, callback) {
|
|
24894
25131
|
const queryStreamId = hash__default["default"](query);
|
|
@@ -24938,7 +25175,7 @@ class PostLiveCollectionController extends LiveCollectionController {
|
|
|
24938
25175
|
const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24939
25176
|
if (!currentCollection || currentCollection.data.includes(comment.referenceId))
|
|
24940
25177
|
return;
|
|
24941
|
-
await getPost(comment.referenceId);
|
|
25178
|
+
await getPost$1(comment.referenceId);
|
|
24942
25179
|
callback(comment);
|
|
24943
25180
|
});
|
|
24944
25181
|
}, 'referenceId', 'post'),
|
|
@@ -24951,7 +25188,7 @@ class PostLiveCollectionController extends LiveCollectionController {
|
|
|
24951
25188
|
const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24952
25189
|
if (!currentCollection || currentCollection.data.includes(comment.referenceId))
|
|
24953
25190
|
return;
|
|
24954
|
-
await getPost(comment.referenceId);
|
|
25191
|
+
await getPost$1(comment.referenceId);
|
|
24955
25192
|
callback(comment);
|
|
24956
25193
|
});
|
|
24957
25194
|
}, 'referenceId', 'post'),
|
|
@@ -25577,7 +25814,7 @@ var index$8 = /*#__PURE__*/Object.freeze({
|
|
|
25577
25814
|
onPostUnflagged: onPostUnflagged,
|
|
25578
25815
|
onPostReactionAdded: onPostReactionAdded,
|
|
25579
25816
|
onPostReactionRemoved: onPostReactionRemoved,
|
|
25580
|
-
getPost: getPost
|
|
25817
|
+
getPost: getPost,
|
|
25581
25818
|
getPosts: getPosts,
|
|
25582
25819
|
getPinnedPosts: getPinnedPosts,
|
|
25583
25820
|
getGlobalPinnedPosts: getGlobalPinnedPosts,
|
|
@@ -26460,7 +26697,7 @@ var index$6 = /*#__PURE__*/Object.freeze({
|
|
|
26460
26697
|
getPoll: getPoll
|
|
26461
26698
|
});
|
|
26462
26699
|
|
|
26463
|
-
const privateKey = "-----BEGIN PRIVATE KEY-----\
|
|
26700
|
+
const privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDAARz+hmBgi8pJ\nQb8LeY41gtHhk+ACMwRfhsn7GqpqRQNG2qU0755mzZuVDUqjQMGSo8THJB7O+OJs\nflbZRkFXlFoFOVNw1UpNOgwEQZ6wB9oRwzepTJAfF1sVhm/o/ixvXh1zDFNDy6yZ\npXyiiJHUVxqyjllZhxnwdvjoVtDs6hW6awG09bB9nh/TTejlUKXoAgzqVwu/1QMu\nUVViET495elEe19aUarEy+oL2iKeXCEvqda/pWNBdbieFyJvvZ08HN8dPuT88wq2\njZLEAth1vrwQ2IAa4ktaLcBQdLJgIkrbDvAiVZ8lQAjS/bq5vXQikTGvoPlC5bbn\nvuOM/3eLAgMBAAECggEAVZ+peHAghq2QVj71nX5lxsNCKaCyYwixSJBpfouTt7Rz\nE6PpzMOXFi1W1o+I22jDakuSM2SOQKqI/u0QefB0r0O/KVk5NrZHXk0mkrdYtxOp\nUgaGyf8UvmjB+8VqHrNKyZdk9qtmbnNj01kTTcAtmE4H39zPR7eR/8Rul94vaZbs\nwCnKJS3mLT3JxyGug6lxanveKkjG+CKC1nJQYWaxCJxaFSzbwXQPvDhB+TvrIbee\npd5v4EAyEJohpr+T9oDGGJkb/KARBZCtwLyB976PKJwwBA8MRVL1i5QwawuMiMq5\nUtnOnbGKtCeFzaLbNU0Qi8bqyims84EQxC6DOu1fkQKBgQDdvsoBsEhsOXV7hlIJ\naEd0eSJZVkdqimxH8uGoMM2FeNaOrcB6yBXqTSP0R3OIyf8eaY6yjRvP30ZNXcll\n/gD3O1Mu6YmWQdt1W2WA6pKOsUuPXasf0pdOF7IiFZKlSabz5YHXFqwVuqm8loaj\nsXel3YWqPVdHiankE7tz+3ssnQKBgQDdqi4TNdD1MdEpihx19jr0QjUiXW3939FK\nqp30HESPEGDGQzXdmJgif9HhZb+cJSuWaHEbjgBrYahvgCF+y6LbEpOD+D/dmT+s\nDEAQaR84sah6dokwPjV8fjBSrcVFjCS+doxv0d3p/9OUEeyUhFrY03nxtIEYkLIE\n/Zvn37b4RwKBgQCLENVFe9XfsaVhQ5r9dV2iyTlmh7qgMZG5CbTFs12hQGhm8McO\n+Z7s41YSJCFr/yq1WwP4LJDtrBw99vyQr1zRsG35tNLp3gGRNzGQSQyC2uQFVHw2\np+7mNewsfhUK/gbrXNsyFnDz6635rPlhfbII3sWuP2wWXFqkxE9CbMwR7QKBgQC6\nawDMzxmo2/iYArrkyevSuEuPVxvFwpF1RgAI6C0QVCnPE38dmdN4UB7mfHekje4W\nVEercMURidPp0cxZolCYBQtilUjAyL0vqC3In1/Ogjq6oy3FEMxSop1pKxMY5j+Q\nnoqFD+6deLUrddeNH7J3X4LSr4dSbX4JjG+tlgt+yQKBgQCuwTL4hA6KqeInQ0Ta\n9VQX5Qr8hFlqJz1gpymi/k63tW/Ob8yedbg3WWNWyShwRMFYyY9S81ITFWM95uL6\nvF3x9rmRjwElJw9PMwVu6dmf/CO0Z1wzXSp2VVD12gbrUD/0/d7MUoJ9LgC8X8f/\nn0txLHYGHbx+nf95+JUg6lV3hg==\n-----END PRIVATE KEY-----";
|
|
26464
26701
|
/*
|
|
26465
26702
|
* The crypto algorithm used for importing key and signing string
|
|
26466
26703
|
*/
|
|
@@ -28780,13 +29017,13 @@ exports.AdRepository = index$3;
|
|
|
28780
29017
|
exports.CategoryRepository = index$b;
|
|
28781
29018
|
exports.ChannelRepository = index$f;
|
|
28782
29019
|
exports.Client = index$o;
|
|
28783
|
-
exports.CommentRepository = index$
|
|
29020
|
+
exports.CommentRepository = index$a;
|
|
28784
29021
|
exports.CommunityPostSettingMaps = CommunityPostSettingMaps;
|
|
28785
29022
|
exports.CommunityPostSettings = CommunityPostSettings;
|
|
28786
29023
|
exports.CommunityRepository = index$c;
|
|
28787
29024
|
exports.ContentFeedType = ContentFeedType;
|
|
28788
29025
|
exports.DefaultCommunityPostSetting = DefaultCommunityPostSetting;
|
|
28789
|
-
exports.FeedRepository = index$
|
|
29026
|
+
exports.FeedRepository = index$9;
|
|
28790
29027
|
exports.FileRepository = index$l;
|
|
28791
29028
|
exports.FileType = FileType;
|
|
28792
29029
|
exports.InvitationRepository = index$1;
|