@amityco/ts-sdk-react-native 6.28.1 → 6.28.2
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/dist/@types/core/payload.d.ts +1 -1
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/commentRepository/observers/getComments.d.ts +1 -1
- package/dist/commentRepository/observers/getComments.d.ts.map +1 -1
- package/dist/communityRepository/utils/payload.d.ts +7 -0
- package/dist/communityRepository/utils/payload.d.ts.map +1 -1
- package/dist/index.cjs.js +284 -180
- package/dist/index.esm.js +284 -180
- package/dist/index.umd.js +2 -2
- package/dist/postRepository/internalApi/getPost.d.ts +5 -0
- package/dist/postRepository/internalApi/getPost.d.ts.map +1 -0
- package/dist/postRepository/internalApi/index.d.ts +13 -0
- package/dist/postRepository/internalApi/index.d.ts.map +1 -0
- package/dist/postRepository/observers/getPosts/PostLiveCollectionController.d.ts +14 -0
- package/dist/postRepository/observers/getPosts/PostLiveCollectionController.d.ts.map +1 -0
- package/dist/postRepository/observers/getPosts/PostPaginationController.d.ts +5 -0
- package/dist/postRepository/observers/getPosts/PostPaginationController.d.ts.map +1 -0
- package/dist/postRepository/observers/getPosts/PostQueryStreamController.d.ts +15 -0
- package/dist/postRepository/observers/getPosts/PostQueryStreamController.d.ts.map +1 -0
- package/dist/postRepository/observers/getPosts/enums.d.ts +12 -0
- package/dist/postRepository/observers/getPosts/enums.d.ts.map +1 -0
- package/dist/postRepository/observers/getPosts.d.ts.map +1 -1
- package/dist/postRepository/utils/payload.d.ts +2 -0
- package/dist/postRepository/utils/payload.d.ts.map +1 -0
- package/dist/utils/tests/dummy/post.d.ts +3 -3
- package/package.json +1 -1
- package/src/@types/core/payload.ts +1 -1
- package/src/commentRepository/observers/getComments.ts +1 -1
- package/src/communityRepository/utils/payload.ts +19 -3
- package/src/postRepository/internalApi/getPost.ts +65 -0
- package/src/postRepository/internalApi/index.ts +16 -0
- package/src/postRepository/observers/getPosts/PostLiveCollectionController.ts +190 -0
- package/src/postRepository/observers/getPosts/PostPaginationController.ts +45 -0
- package/src/postRepository/observers/getPosts/PostQueryStreamController.ts +102 -0
- package/src/postRepository/observers/getPosts/enums.ts +11 -0
- package/src/postRepository/observers/getPosts.ts +6 -197
- package/src/postRepository/utils/payload.ts +17 -0
package/dist/index.esm.js
CHANGED
|
@@ -90,8 +90,8 @@ const PostContentType = Object.freeze({
|
|
|
90
90
|
|
|
91
91
|
function getVersion() {
|
|
92
92
|
try {
|
|
93
|
-
// the string ''v6.28.
|
|
94
|
-
return 'v6.28.
|
|
93
|
+
// the string ''v6.28.2-esm'' should be replaced by actual value by @rollup/plugin-replace
|
|
94
|
+
return 'v6.28.2-esm';
|
|
95
95
|
}
|
|
96
96
|
catch (error) {
|
|
97
97
|
return '__dev__';
|
|
@@ -28661,7 +28661,7 @@ getMessage$2.locally = (messageId) => {
|
|
|
28661
28661
|
* @category Post API
|
|
28662
28662
|
* @async
|
|
28663
28663
|
*/
|
|
28664
|
-
const getPost$
|
|
28664
|
+
const getPost$2 = async (postId) => {
|
|
28665
28665
|
const client = getActiveClient();
|
|
28666
28666
|
client.log('post/getPost', postId);
|
|
28667
28667
|
isInTombstone('post', postId);
|
|
@@ -28701,7 +28701,7 @@ const getPost$1 = async (postId) => {
|
|
|
28701
28701
|
*
|
|
28702
28702
|
* @category Post API
|
|
28703
28703
|
*/
|
|
28704
|
-
getPost$
|
|
28704
|
+
getPost$2.locally = (postId) => {
|
|
28705
28705
|
const client = getActiveClient();
|
|
28706
28706
|
client.log('post/getPost.locally', postId);
|
|
28707
28707
|
if (!client.cache)
|
|
@@ -34101,7 +34101,7 @@ const convertCommunityUsersToUniqueObject = (communityUsers) => {
|
|
|
34101
34101
|
});
|
|
34102
34102
|
return result;
|
|
34103
34103
|
};
|
|
34104
|
-
const
|
|
34104
|
+
const convertCommunityPayload = (rawPayload) => {
|
|
34105
34105
|
// Unpack community payload by mapping payload field to postSetting value.
|
|
34106
34106
|
const communities = rawPayload.communities.map((_a) => {
|
|
34107
34107
|
var { needApprovalOnPostCreation, onlyAdminCanPost } = _a, restCommunityPayload = __rest(_a, ["needApprovalOnPostCreation", "onlyAdminCanPost"]);
|
|
@@ -34125,6 +34125,11 @@ const prepareCommunityPayload = (rawPayload) => {
|
|
|
34125
34125
|
const communityWithMembershipStatus = updateMembershipStatus(communities, communityUsers);
|
|
34126
34126
|
return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers });
|
|
34127
34127
|
};
|
|
34128
|
+
const prepareCommunityPayload = (rawPayload) => {
|
|
34129
|
+
const { communities, communityUsers } = convertCommunityPayload(rawPayload);
|
|
34130
|
+
return Object.assign(Object.assign({}, rawPayload), { communities,
|
|
34131
|
+
communityUsers });
|
|
34132
|
+
};
|
|
34128
34133
|
const prepareCommunityRequest = (params) => {
|
|
34129
34134
|
const { postSetting = undefined, storySetting } = params, restParam = __rest(params, ["postSetting", "storySetting"]);
|
|
34130
34135
|
return Object.assign(Object.assign(Object.assign({}, restParam), (postSetting ? CommunityPostSettingMaps[postSetting] : undefined)), {
|
|
@@ -36857,7 +36862,7 @@ const editPost = async (postId, patch) => {
|
|
|
36857
36862
|
const deletePost = async (postId, permanent = false) => {
|
|
36858
36863
|
var _a;
|
|
36859
36864
|
const client = getActiveClient();
|
|
36860
|
-
const post = await getPost$
|
|
36865
|
+
const post = await getPost$2(postId);
|
|
36861
36866
|
await client.http.delete(`/api/v4/posts/${encodeURIComponent(postId)}`, {
|
|
36862
36867
|
params: {
|
|
36863
36868
|
postId,
|
|
@@ -37196,7 +37201,7 @@ const observePost = (postId, callback, policy = 'cache_then_server') => {
|
|
|
37196
37201
|
};
|
|
37197
37202
|
const disposers = [];
|
|
37198
37203
|
disposers.push(onPostUpdated(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUpdate')), onPostDeleted(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onDelete')), onPostApproved(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onApproved')), onPostDeclined(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onDeclined')), onPostFlagged(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onFlagged')), onPostUnflagged(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUnflagged')), onPostReactionAdded(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onReactionAdded')), onPostReactionRemoved(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onReactionRemoved')));
|
|
37199
|
-
runQuery(createQuery(getPost$
|
|
37204
|
+
runQuery(createQuery(getPost$2, postId), result => (result.data || result.error) &&
|
|
37200
37205
|
router(Object.assign(Object.assign({}, result), { data: result.data && LinkedObject.post(result.data) }), 'onFetch'), queryOptions(policy));
|
|
37201
37206
|
return () => {
|
|
37202
37207
|
log(`observePosts(tmpid: ${timestamp}) > dispose`);
|
|
@@ -37311,7 +37316,7 @@ const createComment = async (bundle) => {
|
|
|
37311
37316
|
if (client.cache)
|
|
37312
37317
|
ingestInCache(data, { cachedAt });
|
|
37313
37318
|
if (['post', 'content'].includes(bundle.referenceType)) {
|
|
37314
|
-
const post = await getPost$
|
|
37319
|
+
const post = await getPost$2(bundle.referenceId);
|
|
37315
37320
|
fireEvent('local.post.updated', {
|
|
37316
37321
|
posts: [post.data],
|
|
37317
37322
|
categories: [],
|
|
@@ -37505,7 +37510,7 @@ const deleteComment = async (commentId, permanent = false) => {
|
|
|
37505
37510
|
});
|
|
37506
37511
|
}
|
|
37507
37512
|
else {
|
|
37508
|
-
const post = await getPost$
|
|
37513
|
+
const post = await getPost$2(comment.data.referenceId);
|
|
37509
37514
|
fireEvent('local.post.updated', {
|
|
37510
37515
|
posts: [post.data],
|
|
37511
37516
|
categories: [],
|
|
@@ -38109,12 +38114,12 @@ var index$6 = /*#__PURE__*/Object.freeze({
|
|
|
38109
38114
|
*
|
|
38110
38115
|
* @category Post Live Object
|
|
38111
38116
|
*/
|
|
38112
|
-
const getPost = (postId, callback) => {
|
|
38117
|
+
const getPost$1 = (postId, callback) => {
|
|
38113
38118
|
const responder = (snapshot) => {
|
|
38114
38119
|
const { data } = snapshot;
|
|
38115
38120
|
callback(Object.assign(Object.assign({}, snapshot), { data: data ? LinkedObject.post(snapshot.data) : data }));
|
|
38116
38121
|
};
|
|
38117
|
-
return liveObject(postId, responder, 'postId', getPost$
|
|
38122
|
+
return liveObject(postId, responder, 'postId', getPost$2, [
|
|
38118
38123
|
onPostApproved,
|
|
38119
38124
|
onPostDeclined,
|
|
38120
38125
|
(callback) => {
|
|
@@ -38154,7 +38159,7 @@ const getPost = (postId, callback) => {
|
|
|
38154
38159
|
convertEventPayload((callback) => {
|
|
38155
38160
|
return onCommentCreated(async (comment) => {
|
|
38156
38161
|
if (comment.referenceId === postId) {
|
|
38157
|
-
await getPost$
|
|
38162
|
+
await getPost$2(postId);
|
|
38158
38163
|
callback(comment);
|
|
38159
38164
|
}
|
|
38160
38165
|
});
|
|
@@ -38162,7 +38167,7 @@ const getPost = (postId, callback) => {
|
|
|
38162
38167
|
convertEventPayload((callback) => {
|
|
38163
38168
|
return onCommentDeleted(async (comment) => {
|
|
38164
38169
|
if (comment.referenceId === postId) {
|
|
38165
|
-
await getPost$
|
|
38170
|
+
await getPost$2(postId);
|
|
38166
38171
|
callback(comment);
|
|
38167
38172
|
}
|
|
38168
38173
|
});
|
|
@@ -38171,61 +38176,272 @@ const getPost = (postId, callback) => {
|
|
|
38171
38176
|
};
|
|
38172
38177
|
/* end_public_function */
|
|
38173
38178
|
|
|
38174
|
-
|
|
38175
|
-
|
|
38176
|
-
|
|
38177
|
-
|
|
38178
|
-
|
|
38179
|
-
|
|
38180
|
-
|
|
38181
|
-
|
|
38182
|
-
|
|
38183
|
-
|
|
38184
|
-
|
|
38185
|
-
|
|
38186
|
-
|
|
38187
|
-
|
|
38188
|
-
|
|
38189
|
-
|
|
38190
|
-
|
|
38191
|
-
|
|
38192
|
-
|
|
38193
|
-
|
|
38194
|
-
|
|
38195
|
-
|
|
38196
|
-
|
|
38197
|
-
|
|
38198
|
-
|
|
38199
|
-
|
|
38200
|
-
|
|
38201
|
-
|
|
38202
|
-
|
|
38203
|
-
|
|
38204
|
-
|
|
38205
|
-
|
|
38206
|
-
|
|
38207
|
-
|
|
38208
|
-
|
|
38209
|
-
|
|
38210
|
-
|
|
38211
|
-
|
|
38212
|
-
|
|
38179
|
+
class PostPaginationController extends PaginationController {
|
|
38180
|
+
async getRequest(queryParams, token) {
|
|
38181
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted, matchingOnlyParentPost } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted", "matchingOnlyParentPost"]);
|
|
38182
|
+
const { dataTypes } = params;
|
|
38183
|
+
const baseOptions = {
|
|
38184
|
+
type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
|
|
38185
|
+
};
|
|
38186
|
+
const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
|
|
38187
|
+
const { data: queryResponse } = await this.http.get(`/api/v4/posts`, {
|
|
38188
|
+
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted),
|
|
38189
|
+
/*
|
|
38190
|
+
* when creating post like image, file, video BE will create 2 posts
|
|
38191
|
+
* 1. parent post to store text with dataType=text
|
|
38192
|
+
* 2. child post to store dataTypes post data
|
|
38193
|
+
*
|
|
38194
|
+
* By default, BE queries only parent post
|
|
38195
|
+
*/
|
|
38196
|
+
matchingOnlyParentPost: matchingOnlyParentPost !== null && matchingOnlyParentPost !== void 0 ? matchingOnlyParentPost : !(dataTypes === null || dataTypes === void 0 ? void 0 : dataTypes.length), options }),
|
|
38197
|
+
});
|
|
38198
|
+
return queryResponse;
|
|
38199
|
+
}
|
|
38200
|
+
}
|
|
38201
|
+
|
|
38202
|
+
var EnumPostActions;
|
|
38203
|
+
(function (EnumPostActions) {
|
|
38204
|
+
EnumPostActions["OnPostCreated"] = "onPostCreated";
|
|
38205
|
+
EnumPostActions["OnPostUpdated"] = "onPostUpdated";
|
|
38206
|
+
EnumPostActions["OnPostDeleted"] = "onPostDeleted";
|
|
38207
|
+
EnumPostActions["OnPostFlagged"] = "onPostFlagged";
|
|
38208
|
+
EnumPostActions["OnPostUnflagged"] = "onPostUnflagged";
|
|
38209
|
+
EnumPostActions["OnPostReactionAdded"] = "onPostReactionAdded";
|
|
38210
|
+
EnumPostActions["OnPostReactionRemoved"] = "onPostReactionRemoved";
|
|
38211
|
+
EnumPostActions["OnPostApproved"] = "onPostApproved";
|
|
38212
|
+
EnumPostActions["OnPostDeclined"] = "onPostDeclined";
|
|
38213
|
+
})(EnumPostActions || (EnumPostActions = {}));
|
|
38214
|
+
|
|
38215
|
+
class PostQueryStreamController extends QueryStreamController {
|
|
38216
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
38217
|
+
super(query, cacheKey);
|
|
38218
|
+
this.notifyChange = notifyChange;
|
|
38219
|
+
this.preparePayload = preparePayload;
|
|
38220
|
+
}
|
|
38221
|
+
async saveToMainDB(response) {
|
|
38222
|
+
const processedPayload = await this.preparePayload(response);
|
|
38223
|
+
const client = getActiveClient();
|
|
38224
|
+
const cachedAt = client.cache && Date.now();
|
|
38225
|
+
if (client.cache) {
|
|
38226
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
38227
|
+
}
|
|
38228
|
+
}
|
|
38229
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
38230
|
+
var _a, _b;
|
|
38231
|
+
if (refresh) {
|
|
38232
|
+
pushToCache(this.cacheKey, {
|
|
38233
|
+
data: response.posts.map(getResolver('post')),
|
|
38234
|
+
});
|
|
38235
|
+
}
|
|
38236
|
+
else {
|
|
38237
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
38238
|
+
const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
38239
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
|
|
38240
|
+
}
|
|
38241
|
+
}
|
|
38242
|
+
reactor(action) {
|
|
38243
|
+
return (post) => {
|
|
38244
|
+
var _a, _b;
|
|
38245
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
38246
|
+
if (!collection)
|
|
38247
|
+
return;
|
|
38248
|
+
if (post.parentPostId && post.isDeleted) {
|
|
38249
|
+
const parentPost = (_b = pullFromCache([
|
|
38250
|
+
'post',
|
|
38251
|
+
'get',
|
|
38252
|
+
post.parentPostId,
|
|
38253
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
38254
|
+
if (!parentPost || (parentPost === null || parentPost === void 0 ? void 0 : parentPost.targetId) !== this.query.targetId)
|
|
38255
|
+
return;
|
|
38256
|
+
parentPost.children = parentPost.children.filter(childId => childId !== post.postId);
|
|
38257
|
+
pushToCache(['post', 'get', parentPost.postId], parentPost);
|
|
38258
|
+
}
|
|
38259
|
+
else {
|
|
38260
|
+
if (this.query.targetId !== post.targetId)
|
|
38261
|
+
return;
|
|
38262
|
+
if (this.query.targetType !== post.targetType)
|
|
38263
|
+
return;
|
|
38264
|
+
}
|
|
38265
|
+
if (action === EnumPostActions.OnPostDeclined) {
|
|
38266
|
+
collection.data = collection.data.filter(postId => postId !== post.postId);
|
|
38267
|
+
}
|
|
38268
|
+
if (action === EnumPostActions.OnPostCreated || action === EnumPostActions.OnPostApproved) {
|
|
38269
|
+
collection.data = [...new Set([post.postId, ...collection.data])];
|
|
38270
|
+
}
|
|
38271
|
+
pushToCache(this.cacheKey, collection);
|
|
38272
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
38273
|
+
};
|
|
38274
|
+
}
|
|
38275
|
+
subscribeRTE(createSubscriber) {
|
|
38276
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
38277
|
+
}
|
|
38278
|
+
}
|
|
38279
|
+
|
|
38280
|
+
const preparePostPayload = (postPayload) => {
|
|
38281
|
+
const { posts } = postPayload;
|
|
38282
|
+
const { communities, communityUsers } = convertCommunityPayload({
|
|
38283
|
+
communities: postPayload.communities,
|
|
38284
|
+
communityUsers: postPayload.communityUsers,
|
|
38213
38285
|
});
|
|
38214
|
-
|
|
38215
|
-
|
|
38216
|
-
|
|
38217
|
-
|
|
38218
|
-
|
|
38219
|
-
|
|
38220
|
-
const
|
|
38221
|
-
|
|
38222
|
-
|
|
38223
|
-
|
|
38224
|
-
|
|
38286
|
+
return Object.assign(Object.assign({}, postPayload), { posts,
|
|
38287
|
+
communities,
|
|
38288
|
+
communityUsers });
|
|
38289
|
+
};
|
|
38290
|
+
|
|
38291
|
+
const getPost = async (postId) => {
|
|
38292
|
+
const client = getActiveClient();
|
|
38293
|
+
client.log('post/getPost', postId);
|
|
38294
|
+
isInTombstone('post', postId);
|
|
38295
|
+
let payload;
|
|
38296
|
+
try {
|
|
38297
|
+
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
38298
|
+
const response = await client.http.get(`/api/v3/posts/${encodeURIComponent(postId)}`);
|
|
38299
|
+
payload = response.data;
|
|
38225
38300
|
}
|
|
38226
|
-
|
|
38301
|
+
catch (error) {
|
|
38302
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
38303
|
+
pushToTombstone('post', postId);
|
|
38304
|
+
}
|
|
38305
|
+
throw error;
|
|
38306
|
+
}
|
|
38307
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
38308
|
+
const cachedAt = client.cache && Date.now();
|
|
38309
|
+
if (client.cache)
|
|
38310
|
+
ingestInCache(data, { cachedAt });
|
|
38311
|
+
const { posts } = data;
|
|
38312
|
+
const result = posts.find(post => post.postId === postId);
|
|
38313
|
+
return {
|
|
38314
|
+
data: result,
|
|
38315
|
+
cachedAt,
|
|
38316
|
+
};
|
|
38317
|
+
};
|
|
38318
|
+
getPost.locally = (postId) => {
|
|
38319
|
+
const client = getActiveClient();
|
|
38320
|
+
client.log('post/getPost.locally', postId);
|
|
38321
|
+
if (!client.cache)
|
|
38322
|
+
return;
|
|
38323
|
+
const cached = pullFromCache(['post', 'get', postId]);
|
|
38324
|
+
if (!cached)
|
|
38325
|
+
return;
|
|
38326
|
+
return {
|
|
38327
|
+
data: cached.data,
|
|
38328
|
+
cachedAt: cached.cachedAt,
|
|
38329
|
+
};
|
|
38227
38330
|
};
|
|
38228
38331
|
|
|
38332
|
+
class PostLiveCollectionController extends LiveCollectionController {
|
|
38333
|
+
constructor(query, callback) {
|
|
38334
|
+
const queryStreamId = hash(query);
|
|
38335
|
+
const cacheKey = ['posts', 'collection', queryStreamId];
|
|
38336
|
+
const paginationController = new PostPaginationController(query);
|
|
38337
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
38338
|
+
this.query = query;
|
|
38339
|
+
this.queryStreamController = new PostQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
|
|
38340
|
+
this.callback = callback.bind(this);
|
|
38341
|
+
this.loadPage({ initial: true });
|
|
38342
|
+
}
|
|
38343
|
+
setup() {
|
|
38344
|
+
var _a;
|
|
38345
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
38346
|
+
if (!collection) {
|
|
38347
|
+
pushToCache(this.cacheKey, {
|
|
38348
|
+
data: [],
|
|
38349
|
+
params: {},
|
|
38350
|
+
});
|
|
38351
|
+
}
|
|
38352
|
+
}
|
|
38353
|
+
async persistModel(queryPayload) {
|
|
38354
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
38355
|
+
}
|
|
38356
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
38357
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
38358
|
+
}
|
|
38359
|
+
startSubscription() {
|
|
38360
|
+
return this.queryStreamController.subscribeRTE([
|
|
38361
|
+
{ fn: onPostCreated, action: EnumPostActions.OnPostCreated },
|
|
38362
|
+
{ fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
|
|
38363
|
+
{ fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
|
|
38364
|
+
{ fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
|
|
38365
|
+
{ fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
|
|
38366
|
+
{ fn: onPostApproved, action: EnumPostActions.OnPostApproved },
|
|
38367
|
+
{ fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
|
|
38368
|
+
{ fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
|
|
38369
|
+
{ fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
|
|
38370
|
+
{
|
|
38371
|
+
fn: convertEventPayload((callback) => {
|
|
38372
|
+
return onCommentCreated(async (comment) => {
|
|
38373
|
+
var _a;
|
|
38374
|
+
const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
38375
|
+
if (!currentCollection || currentCollection.data.includes(comment.referenceId))
|
|
38376
|
+
return;
|
|
38377
|
+
await getPost(comment.referenceId);
|
|
38378
|
+
callback(comment);
|
|
38379
|
+
});
|
|
38380
|
+
}, 'referenceId', 'post'),
|
|
38381
|
+
action: EnumPostActions.OnPostUpdated,
|
|
38382
|
+
},
|
|
38383
|
+
{
|
|
38384
|
+
fn: convertEventPayload((callback) => {
|
|
38385
|
+
return onCommentDeleted(async (comment) => {
|
|
38386
|
+
var _a;
|
|
38387
|
+
const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
38388
|
+
if (!currentCollection || currentCollection.data.includes(comment.referenceId))
|
|
38389
|
+
return;
|
|
38390
|
+
await getPost(comment.referenceId);
|
|
38391
|
+
callback(comment);
|
|
38392
|
+
});
|
|
38393
|
+
}, 'referenceId', 'post'),
|
|
38394
|
+
action: EnumPostActions.OnPostUpdated,
|
|
38395
|
+
},
|
|
38396
|
+
]);
|
|
38397
|
+
}
|
|
38398
|
+
notifyChange({ origin, loading, error }) {
|
|
38399
|
+
var _a, _b;
|
|
38400
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
38401
|
+
if (!collection)
|
|
38402
|
+
return;
|
|
38403
|
+
const data = this.applyFilter((_b = collection.data
|
|
38404
|
+
.map(id => pullFromCache(['post', 'get', id]))
|
|
38405
|
+
.filter(isNonNullable)
|
|
38406
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
|
|
38407
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
38408
|
+
return;
|
|
38409
|
+
this.callback({
|
|
38410
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
38411
|
+
data,
|
|
38412
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
38413
|
+
loading,
|
|
38414
|
+
error,
|
|
38415
|
+
});
|
|
38416
|
+
}
|
|
38417
|
+
applyFilter(data) {
|
|
38418
|
+
var _a;
|
|
38419
|
+
let posts = data;
|
|
38420
|
+
if (!this.query.includeDeleted) {
|
|
38421
|
+
posts = filterByPropEquality(posts, 'isDeleted', false);
|
|
38422
|
+
}
|
|
38423
|
+
if (this.query.tags) {
|
|
38424
|
+
posts = posts.filter(p => { var _a; return (_a = p.tags) === null || _a === void 0 ? void 0 : _a.some(t => { var _a; return (_a = this.query.tags) === null || _a === void 0 ? void 0 : _a.includes(t); }); });
|
|
38425
|
+
}
|
|
38426
|
+
if (this.query.targetType === 'community' && this.query.feedType) {
|
|
38427
|
+
posts = filterByFeedType(posts, this.query.feedType);
|
|
38428
|
+
}
|
|
38429
|
+
if ((_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.length) {
|
|
38430
|
+
posts = filterByPostDataTypes(posts, this.query.dataTypes);
|
|
38431
|
+
}
|
|
38432
|
+
switch (this.query.sortBy) {
|
|
38433
|
+
case 'firstCreated':
|
|
38434
|
+
posts = posts.sort(sortByFirstCreated);
|
|
38435
|
+
break;
|
|
38436
|
+
case 'lastCreated':
|
|
38437
|
+
default:
|
|
38438
|
+
posts = posts.sort(sortByLastCreated);
|
|
38439
|
+
break;
|
|
38440
|
+
}
|
|
38441
|
+
return posts;
|
|
38442
|
+
}
|
|
38443
|
+
}
|
|
38444
|
+
|
|
38229
38445
|
/* begin_public_function
|
|
38230
38446
|
id: post.query
|
|
38231
38447
|
*/
|
|
@@ -38257,121 +38473,9 @@ const getPosts = (params, callback, config) => {
|
|
|
38257
38473
|
}
|
|
38258
38474
|
const timestamp = Date.now();
|
|
38259
38475
|
log(`getPosts(tmpid: ${timestamp}) > listen`);
|
|
38260
|
-
const
|
|
38261
|
-
const
|
|
38262
|
-
const
|
|
38263
|
-
const disposers = [];
|
|
38264
|
-
const cacheKey = [
|
|
38265
|
-
'post',
|
|
38266
|
-
'collection',
|
|
38267
|
-
{ targetId: params.targetId, targetType: params.targetType },
|
|
38268
|
-
];
|
|
38269
|
-
const responder = (data) => {
|
|
38270
|
-
var _a, _b, _c;
|
|
38271
|
-
let posts = (_a = data.data
|
|
38272
|
-
.map(postId => pullFromCache(['post', 'get', postId]))
|
|
38273
|
-
.filter(Boolean)
|
|
38274
|
-
.map(({ data }) => LinkedObject.post(data))) !== null && _a !== void 0 ? _a : [];
|
|
38275
|
-
const sortBy = params.sortBy ? params.sortBy : 'lastCreated';
|
|
38276
|
-
posts = posts.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
38277
|
-
if (!params.includeDeleted) {
|
|
38278
|
-
posts = filterByPropEquality(posts, 'isDeleted', false);
|
|
38279
|
-
}
|
|
38280
|
-
if (params.tags) {
|
|
38281
|
-
posts = posts.filter(p => { var _a; return (_a = p.tags) === null || _a === void 0 ? void 0 : _a.some(t => { var _a; return (_a = params.tags) === null || _a === void 0 ? void 0 : _a.includes(t); }); });
|
|
38282
|
-
}
|
|
38283
|
-
if (params.targetType === 'community' && params.feedType) {
|
|
38284
|
-
posts = filterByFeedType(posts, params.feedType);
|
|
38285
|
-
}
|
|
38286
|
-
if ((_b = params.dataTypes) === null || _b === void 0 ? void 0 : _b.length) {
|
|
38287
|
-
posts = filterByPostDataTypes(posts, params.dataTypes);
|
|
38288
|
-
}
|
|
38289
|
-
callback({
|
|
38290
|
-
onNextPage: onFetch,
|
|
38291
|
-
data: posts,
|
|
38292
|
-
hasNextPage: !!((_c = data.params) === null || _c === void 0 ? void 0 : _c.page),
|
|
38293
|
-
loading: data.loading,
|
|
38294
|
-
error: data.error,
|
|
38295
|
-
});
|
|
38296
|
-
};
|
|
38297
|
-
const realtimeRouter = (action) => (post) => {
|
|
38298
|
-
var _a, _b;
|
|
38299
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
38300
|
-
if (!collection)
|
|
38301
|
-
return;
|
|
38302
|
-
if (post.parentPostId && post.isDeleted) {
|
|
38303
|
-
const parentPost = (_b = pullFromCache([
|
|
38304
|
-
'post',
|
|
38305
|
-
'get',
|
|
38306
|
-
post.parentPostId,
|
|
38307
|
-
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
38308
|
-
if (!parentPost || (parentPost === null || parentPost === void 0 ? void 0 : parentPost.targetId) !== params.targetId)
|
|
38309
|
-
return;
|
|
38310
|
-
parentPost.children = parentPost.children.filter(childId => childId !== post.postId);
|
|
38311
|
-
pushToCache(['post', 'get', parentPost.postId], parentPost);
|
|
38312
|
-
}
|
|
38313
|
-
else {
|
|
38314
|
-
if (params.targetId !== post.targetId)
|
|
38315
|
-
return;
|
|
38316
|
-
if (params.targetType !== post.targetType)
|
|
38317
|
-
return;
|
|
38318
|
-
}
|
|
38319
|
-
/*
|
|
38320
|
-
* This is not ideal, but currently this is the only way to update the
|
|
38321
|
-
* collection on post declined
|
|
38322
|
-
*/
|
|
38323
|
-
if (action === 'onDeclined') {
|
|
38324
|
-
collection.data = collection.data.filter(postId => postId !== post.postId);
|
|
38325
|
-
}
|
|
38326
|
-
else {
|
|
38327
|
-
collection.data = [...new Set([post.postId, ...collection.data])];
|
|
38328
|
-
}
|
|
38329
|
-
pushToCache(cacheKey, collection);
|
|
38330
|
-
responder(collection);
|
|
38331
|
-
};
|
|
38332
|
-
const onFetch = (initial = false) => {
|
|
38333
|
-
var _a, _b, _c;
|
|
38334
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
38335
|
-
const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
38336
|
-
if (!initial && posts.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
|
|
38337
|
-
return;
|
|
38338
|
-
const query = createQuery(queryPosts, Object.assign(Object.assign({}, queryParams), { limit: initial ? limit : undefined, page: !initial ? collection === null || collection === void 0 ? void 0 : collection.params.page : undefined }));
|
|
38339
|
-
runQuery(query, ({ data: result, error, loading, paging }) => {
|
|
38340
|
-
const data = {
|
|
38341
|
-
loading,
|
|
38342
|
-
error,
|
|
38343
|
-
params: { page: paging === null || paging === void 0 ? void 0 : paging.next },
|
|
38344
|
-
data: posts,
|
|
38345
|
-
};
|
|
38346
|
-
if (result) {
|
|
38347
|
-
data.data = initial
|
|
38348
|
-
? result.map(getResolver('post'))
|
|
38349
|
-
: [...new Set([...posts, ...result.map(getResolver('post'))])];
|
|
38350
|
-
}
|
|
38351
|
-
pushToCache(cacheKey, data);
|
|
38352
|
-
responder(data);
|
|
38353
|
-
}, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
|
|
38354
|
-
};
|
|
38355
|
-
disposers.push(onPostCreated(realtimeRouter('onCreate')), onPostApproved(realtimeRouter('onApproved')), onPostDeclined(realtimeRouter('onDeclined')), onPostDeleted(realtimeRouter('onDelete')), onPostUpdated(realtimeRouter('onUpdate')), onPostFlagged(realtimeRouter('onFlagged')), onPostUnflagged(realtimeRouter('onUnflagged')), onPostReactionAdded(realtimeRouter('onReactionAdded')), onPostReactionRemoved(realtimeRouter('onReactionRemoved')), convertEventPayload((callback) => {
|
|
38356
|
-
return onCommentCreated(async (comment) => {
|
|
38357
|
-
var _a;
|
|
38358
|
-
const currentCollection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
38359
|
-
if (!currentCollection || currentCollection.data.includes(comment.referenceId))
|
|
38360
|
-
return;
|
|
38361
|
-
await getPost$1(comment.referenceId);
|
|
38362
|
-
callback(comment);
|
|
38363
|
-
});
|
|
38364
|
-
}, 'referenceId', 'post')(realtimeRouter('onUpdate')), convertEventPayload((callback) => {
|
|
38365
|
-
return onCommentDeleted(async (comment) => {
|
|
38366
|
-
var _a;
|
|
38367
|
-
const currentCollection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
38368
|
-
if (!currentCollection || currentCollection.data.includes(comment.referenceId))
|
|
38369
|
-
return;
|
|
38370
|
-
await getPost$1(comment.referenceId);
|
|
38371
|
-
callback(comment);
|
|
38372
|
-
});
|
|
38373
|
-
}, 'referenceId', 'post')(realtimeRouter('onUpdate')));
|
|
38374
|
-
onFetch(true);
|
|
38476
|
+
const postsLiveCollection = new PostLiveCollectionController(params, callback);
|
|
38477
|
+
const disposers = postsLiveCollection.startSubscription();
|
|
38478
|
+
const cacheKey = postsLiveCollection.getCacheKey();
|
|
38375
38479
|
disposers.push(() => dropFromCache(cacheKey));
|
|
38376
38480
|
return () => {
|
|
38377
38481
|
log(`getPosts(tmpid: ${timestamp}) > dispose`);
|
|
@@ -38405,7 +38509,7 @@ var index$5 = /*#__PURE__*/Object.freeze({
|
|
|
38405
38509
|
onPostReactionRemoved: onPostReactionRemoved,
|
|
38406
38510
|
observePosts: observePosts,
|
|
38407
38511
|
observePost: observePost,
|
|
38408
|
-
getPost: getPost,
|
|
38512
|
+
getPost: getPost$1,
|
|
38409
38513
|
getPosts: getPosts
|
|
38410
38514
|
});
|
|
38411
38515
|
|