@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.cjs.js
CHANGED
|
@@ -125,8 +125,8 @@ const PostContentType = Object.freeze({
|
|
|
125
125
|
|
|
126
126
|
function getVersion() {
|
|
127
127
|
try {
|
|
128
|
-
// the string ''v6.28.
|
|
129
|
-
return 'v6.28.
|
|
128
|
+
// the string ''v6.28.2-cjs'' should be replaced by actual value by @rollup/plugin-replace
|
|
129
|
+
return 'v6.28.2-cjs';
|
|
130
130
|
}
|
|
131
131
|
catch (error) {
|
|
132
132
|
return '__dev__';
|
|
@@ -12589,7 +12589,7 @@ getMessage$2.locally = (messageId) => {
|
|
|
12589
12589
|
* @category Post API
|
|
12590
12590
|
* @async
|
|
12591
12591
|
*/
|
|
12592
|
-
const getPost$
|
|
12592
|
+
const getPost$2 = async (postId) => {
|
|
12593
12593
|
const client = getActiveClient();
|
|
12594
12594
|
client.log('post/getPost', postId);
|
|
12595
12595
|
isInTombstone('post', postId);
|
|
@@ -12629,7 +12629,7 @@ const getPost$1 = async (postId) => {
|
|
|
12629
12629
|
*
|
|
12630
12630
|
* @category Post API
|
|
12631
12631
|
*/
|
|
12632
|
-
getPost$
|
|
12632
|
+
getPost$2.locally = (postId) => {
|
|
12633
12633
|
const client = getActiveClient();
|
|
12634
12634
|
client.log('post/getPost.locally', postId);
|
|
12635
12635
|
if (!client.cache)
|
|
@@ -18029,7 +18029,7 @@ const convertCommunityUsersToUniqueObject = (communityUsers) => {
|
|
|
18029
18029
|
});
|
|
18030
18030
|
return result;
|
|
18031
18031
|
};
|
|
18032
|
-
const
|
|
18032
|
+
const convertCommunityPayload = (rawPayload) => {
|
|
18033
18033
|
// Unpack community payload by mapping payload field to postSetting value.
|
|
18034
18034
|
const communities = rawPayload.communities.map((_a) => {
|
|
18035
18035
|
var { needApprovalOnPostCreation, onlyAdminCanPost } = _a, restCommunityPayload = __rest(_a, ["needApprovalOnPostCreation", "onlyAdminCanPost"]);
|
|
@@ -18053,6 +18053,11 @@ const prepareCommunityPayload = (rawPayload) => {
|
|
|
18053
18053
|
const communityWithMembershipStatus = updateMembershipStatus(communities, communityUsers);
|
|
18054
18054
|
return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers });
|
|
18055
18055
|
};
|
|
18056
|
+
const prepareCommunityPayload = (rawPayload) => {
|
|
18057
|
+
const { communities, communityUsers } = convertCommunityPayload(rawPayload);
|
|
18058
|
+
return Object.assign(Object.assign({}, rawPayload), { communities,
|
|
18059
|
+
communityUsers });
|
|
18060
|
+
};
|
|
18056
18061
|
const prepareCommunityRequest = (params) => {
|
|
18057
18062
|
const { postSetting = undefined, storySetting } = params, restParam = __rest(params, ["postSetting", "storySetting"]);
|
|
18058
18063
|
return Object.assign(Object.assign(Object.assign({}, restParam), (postSetting ? CommunityPostSettingMaps[postSetting] : undefined)), {
|
|
@@ -20785,7 +20790,7 @@ const editPost = async (postId, patch) => {
|
|
|
20785
20790
|
const deletePost = async (postId, permanent = false) => {
|
|
20786
20791
|
var _a;
|
|
20787
20792
|
const client = getActiveClient();
|
|
20788
|
-
const post = await getPost$
|
|
20793
|
+
const post = await getPost$2(postId);
|
|
20789
20794
|
await client.http.delete(`/api/v4/posts/${encodeURIComponent(postId)}`, {
|
|
20790
20795
|
params: {
|
|
20791
20796
|
postId,
|
|
@@ -21124,7 +21129,7 @@ const observePost = (postId, callback, policy = 'cache_then_server') => {
|
|
|
21124
21129
|
};
|
|
21125
21130
|
const disposers = [];
|
|
21126
21131
|
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')));
|
|
21127
|
-
runQuery(createQuery(getPost$
|
|
21132
|
+
runQuery(createQuery(getPost$2, postId), result => (result.data || result.error) &&
|
|
21128
21133
|
router(Object.assign(Object.assign({}, result), { data: result.data && LinkedObject.post(result.data) }), 'onFetch'), queryOptions(policy));
|
|
21129
21134
|
return () => {
|
|
21130
21135
|
log(`observePosts(tmpid: ${timestamp}) > dispose`);
|
|
@@ -21239,7 +21244,7 @@ const createComment = async (bundle) => {
|
|
|
21239
21244
|
if (client.cache)
|
|
21240
21245
|
ingestInCache(data, { cachedAt });
|
|
21241
21246
|
if (['post', 'content'].includes(bundle.referenceType)) {
|
|
21242
|
-
const post = await getPost$
|
|
21247
|
+
const post = await getPost$2(bundle.referenceId);
|
|
21243
21248
|
fireEvent('local.post.updated', {
|
|
21244
21249
|
posts: [post.data],
|
|
21245
21250
|
categories: [],
|
|
@@ -21433,7 +21438,7 @@ const deleteComment = async (commentId, permanent = false) => {
|
|
|
21433
21438
|
});
|
|
21434
21439
|
}
|
|
21435
21440
|
else {
|
|
21436
|
-
const post = await getPost$
|
|
21441
|
+
const post = await getPost$2(comment.data.referenceId);
|
|
21437
21442
|
fireEvent('local.post.updated', {
|
|
21438
21443
|
posts: [post.data],
|
|
21439
21444
|
categories: [],
|
|
@@ -22037,12 +22042,12 @@ var index$6 = /*#__PURE__*/Object.freeze({
|
|
|
22037
22042
|
*
|
|
22038
22043
|
* @category Post Live Object
|
|
22039
22044
|
*/
|
|
22040
|
-
const getPost = (postId, callback) => {
|
|
22045
|
+
const getPost$1 = (postId, callback) => {
|
|
22041
22046
|
const responder = (snapshot) => {
|
|
22042
22047
|
const { data } = snapshot;
|
|
22043
22048
|
callback(Object.assign(Object.assign({}, snapshot), { data: data ? LinkedObject.post(snapshot.data) : data }));
|
|
22044
22049
|
};
|
|
22045
|
-
return liveObject(postId, responder, 'postId', getPost$
|
|
22050
|
+
return liveObject(postId, responder, 'postId', getPost$2, [
|
|
22046
22051
|
onPostApproved,
|
|
22047
22052
|
onPostDeclined,
|
|
22048
22053
|
(callback) => {
|
|
@@ -22082,7 +22087,7 @@ const getPost = (postId, callback) => {
|
|
|
22082
22087
|
convertEventPayload((callback) => {
|
|
22083
22088
|
return onCommentCreated(async (comment) => {
|
|
22084
22089
|
if (comment.referenceId === postId) {
|
|
22085
|
-
await getPost$
|
|
22090
|
+
await getPost$2(postId);
|
|
22086
22091
|
callback(comment);
|
|
22087
22092
|
}
|
|
22088
22093
|
});
|
|
@@ -22090,7 +22095,7 @@ const getPost = (postId, callback) => {
|
|
|
22090
22095
|
convertEventPayload((callback) => {
|
|
22091
22096
|
return onCommentDeleted(async (comment) => {
|
|
22092
22097
|
if (comment.referenceId === postId) {
|
|
22093
|
-
await getPost$
|
|
22098
|
+
await getPost$2(postId);
|
|
22094
22099
|
callback(comment);
|
|
22095
22100
|
}
|
|
22096
22101
|
});
|
|
@@ -22099,61 +22104,272 @@ const getPost = (postId, callback) => {
|
|
|
22099
22104
|
};
|
|
22100
22105
|
/* end_public_function */
|
|
22101
22106
|
|
|
22102
|
-
|
|
22103
|
-
|
|
22104
|
-
|
|
22105
|
-
|
|
22106
|
-
|
|
22107
|
-
|
|
22108
|
-
|
|
22109
|
-
|
|
22110
|
-
|
|
22111
|
-
|
|
22112
|
-
|
|
22113
|
-
|
|
22114
|
-
|
|
22115
|
-
|
|
22116
|
-
|
|
22117
|
-
|
|
22118
|
-
|
|
22119
|
-
|
|
22120
|
-
|
|
22121
|
-
|
|
22122
|
-
|
|
22123
|
-
|
|
22124
|
-
|
|
22125
|
-
|
|
22126
|
-
|
|
22127
|
-
|
|
22128
|
-
|
|
22129
|
-
|
|
22130
|
-
|
|
22131
|
-
|
|
22132
|
-
|
|
22133
|
-
|
|
22134
|
-
|
|
22135
|
-
|
|
22136
|
-
|
|
22137
|
-
|
|
22138
|
-
|
|
22139
|
-
|
|
22140
|
-
|
|
22107
|
+
class PostPaginationController extends PaginationController {
|
|
22108
|
+
async getRequest(queryParams, token) {
|
|
22109
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted, matchingOnlyParentPost } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted", "matchingOnlyParentPost"]);
|
|
22110
|
+
const { dataTypes } = params;
|
|
22111
|
+
const baseOptions = {
|
|
22112
|
+
type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
|
|
22113
|
+
};
|
|
22114
|
+
const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
|
|
22115
|
+
const { data: queryResponse } = await this.http.get(`/api/v4/posts`, {
|
|
22116
|
+
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted),
|
|
22117
|
+
/*
|
|
22118
|
+
* when creating post like image, file, video BE will create 2 posts
|
|
22119
|
+
* 1. parent post to store text with dataType=text
|
|
22120
|
+
* 2. child post to store dataTypes post data
|
|
22121
|
+
*
|
|
22122
|
+
* By default, BE queries only parent post
|
|
22123
|
+
*/
|
|
22124
|
+
matchingOnlyParentPost: matchingOnlyParentPost !== null && matchingOnlyParentPost !== void 0 ? matchingOnlyParentPost : !(dataTypes === null || dataTypes === void 0 ? void 0 : dataTypes.length), options }),
|
|
22125
|
+
});
|
|
22126
|
+
return queryResponse;
|
|
22127
|
+
}
|
|
22128
|
+
}
|
|
22129
|
+
|
|
22130
|
+
var EnumPostActions;
|
|
22131
|
+
(function (EnumPostActions) {
|
|
22132
|
+
EnumPostActions["OnPostCreated"] = "onPostCreated";
|
|
22133
|
+
EnumPostActions["OnPostUpdated"] = "onPostUpdated";
|
|
22134
|
+
EnumPostActions["OnPostDeleted"] = "onPostDeleted";
|
|
22135
|
+
EnumPostActions["OnPostFlagged"] = "onPostFlagged";
|
|
22136
|
+
EnumPostActions["OnPostUnflagged"] = "onPostUnflagged";
|
|
22137
|
+
EnumPostActions["OnPostReactionAdded"] = "onPostReactionAdded";
|
|
22138
|
+
EnumPostActions["OnPostReactionRemoved"] = "onPostReactionRemoved";
|
|
22139
|
+
EnumPostActions["OnPostApproved"] = "onPostApproved";
|
|
22140
|
+
EnumPostActions["OnPostDeclined"] = "onPostDeclined";
|
|
22141
|
+
})(EnumPostActions || (EnumPostActions = {}));
|
|
22142
|
+
|
|
22143
|
+
class PostQueryStreamController extends QueryStreamController {
|
|
22144
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
22145
|
+
super(query, cacheKey);
|
|
22146
|
+
this.notifyChange = notifyChange;
|
|
22147
|
+
this.preparePayload = preparePayload;
|
|
22148
|
+
}
|
|
22149
|
+
async saveToMainDB(response) {
|
|
22150
|
+
const processedPayload = await this.preparePayload(response);
|
|
22151
|
+
const client = getActiveClient();
|
|
22152
|
+
const cachedAt = client.cache && Date.now();
|
|
22153
|
+
if (client.cache) {
|
|
22154
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
22155
|
+
}
|
|
22156
|
+
}
|
|
22157
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
22158
|
+
var _a, _b;
|
|
22159
|
+
if (refresh) {
|
|
22160
|
+
pushToCache(this.cacheKey, {
|
|
22161
|
+
data: response.posts.map(getResolver('post')),
|
|
22162
|
+
});
|
|
22163
|
+
}
|
|
22164
|
+
else {
|
|
22165
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22166
|
+
const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
22167
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
|
|
22168
|
+
}
|
|
22169
|
+
}
|
|
22170
|
+
reactor(action) {
|
|
22171
|
+
return (post) => {
|
|
22172
|
+
var _a, _b;
|
|
22173
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22174
|
+
if (!collection)
|
|
22175
|
+
return;
|
|
22176
|
+
if (post.parentPostId && post.isDeleted) {
|
|
22177
|
+
const parentPost = (_b = pullFromCache([
|
|
22178
|
+
'post',
|
|
22179
|
+
'get',
|
|
22180
|
+
post.parentPostId,
|
|
22181
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
22182
|
+
if (!parentPost || (parentPost === null || parentPost === void 0 ? void 0 : parentPost.targetId) !== this.query.targetId)
|
|
22183
|
+
return;
|
|
22184
|
+
parentPost.children = parentPost.children.filter(childId => childId !== post.postId);
|
|
22185
|
+
pushToCache(['post', 'get', parentPost.postId], parentPost);
|
|
22186
|
+
}
|
|
22187
|
+
else {
|
|
22188
|
+
if (this.query.targetId !== post.targetId)
|
|
22189
|
+
return;
|
|
22190
|
+
if (this.query.targetType !== post.targetType)
|
|
22191
|
+
return;
|
|
22192
|
+
}
|
|
22193
|
+
if (action === EnumPostActions.OnPostDeclined) {
|
|
22194
|
+
collection.data = collection.data.filter(postId => postId !== post.postId);
|
|
22195
|
+
}
|
|
22196
|
+
if (action === EnumPostActions.OnPostCreated || action === EnumPostActions.OnPostApproved) {
|
|
22197
|
+
collection.data = [...new Set([post.postId, ...collection.data])];
|
|
22198
|
+
}
|
|
22199
|
+
pushToCache(this.cacheKey, collection);
|
|
22200
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
22201
|
+
};
|
|
22202
|
+
}
|
|
22203
|
+
subscribeRTE(createSubscriber) {
|
|
22204
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
22205
|
+
}
|
|
22206
|
+
}
|
|
22207
|
+
|
|
22208
|
+
const preparePostPayload = (postPayload) => {
|
|
22209
|
+
const { posts } = postPayload;
|
|
22210
|
+
const { communities, communityUsers } = convertCommunityPayload({
|
|
22211
|
+
communities: postPayload.communities,
|
|
22212
|
+
communityUsers: postPayload.communityUsers,
|
|
22141
22213
|
});
|
|
22142
|
-
|
|
22143
|
-
|
|
22144
|
-
|
|
22145
|
-
|
|
22146
|
-
|
|
22147
|
-
|
|
22148
|
-
const
|
|
22149
|
-
|
|
22150
|
-
|
|
22151
|
-
|
|
22152
|
-
|
|
22214
|
+
return Object.assign(Object.assign({}, postPayload), { posts,
|
|
22215
|
+
communities,
|
|
22216
|
+
communityUsers });
|
|
22217
|
+
};
|
|
22218
|
+
|
|
22219
|
+
const getPost = async (postId) => {
|
|
22220
|
+
const client = getActiveClient();
|
|
22221
|
+
client.log('post/getPost', postId);
|
|
22222
|
+
isInTombstone('post', postId);
|
|
22223
|
+
let payload;
|
|
22224
|
+
try {
|
|
22225
|
+
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
22226
|
+
const response = await client.http.get(`/api/v3/posts/${encodeURIComponent(postId)}`);
|
|
22227
|
+
payload = response.data;
|
|
22153
22228
|
}
|
|
22154
|
-
|
|
22229
|
+
catch (error) {
|
|
22230
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
22231
|
+
pushToTombstone('post', postId);
|
|
22232
|
+
}
|
|
22233
|
+
throw error;
|
|
22234
|
+
}
|
|
22235
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
22236
|
+
const cachedAt = client.cache && Date.now();
|
|
22237
|
+
if (client.cache)
|
|
22238
|
+
ingestInCache(data, { cachedAt });
|
|
22239
|
+
const { posts } = data;
|
|
22240
|
+
const result = posts.find(post => post.postId === postId);
|
|
22241
|
+
return {
|
|
22242
|
+
data: result,
|
|
22243
|
+
cachedAt,
|
|
22244
|
+
};
|
|
22245
|
+
};
|
|
22246
|
+
getPost.locally = (postId) => {
|
|
22247
|
+
const client = getActiveClient();
|
|
22248
|
+
client.log('post/getPost.locally', postId);
|
|
22249
|
+
if (!client.cache)
|
|
22250
|
+
return;
|
|
22251
|
+
const cached = pullFromCache(['post', 'get', postId]);
|
|
22252
|
+
if (!cached)
|
|
22253
|
+
return;
|
|
22254
|
+
return {
|
|
22255
|
+
data: cached.data,
|
|
22256
|
+
cachedAt: cached.cachedAt,
|
|
22257
|
+
};
|
|
22155
22258
|
};
|
|
22156
22259
|
|
|
22260
|
+
class PostLiveCollectionController extends LiveCollectionController {
|
|
22261
|
+
constructor(query, callback) {
|
|
22262
|
+
const queryStreamId = hash__default["default"](query);
|
|
22263
|
+
const cacheKey = ['posts', 'collection', queryStreamId];
|
|
22264
|
+
const paginationController = new PostPaginationController(query);
|
|
22265
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
22266
|
+
this.query = query;
|
|
22267
|
+
this.queryStreamController = new PostQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
|
|
22268
|
+
this.callback = callback.bind(this);
|
|
22269
|
+
this.loadPage({ initial: true });
|
|
22270
|
+
}
|
|
22271
|
+
setup() {
|
|
22272
|
+
var _a;
|
|
22273
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22274
|
+
if (!collection) {
|
|
22275
|
+
pushToCache(this.cacheKey, {
|
|
22276
|
+
data: [],
|
|
22277
|
+
params: {},
|
|
22278
|
+
});
|
|
22279
|
+
}
|
|
22280
|
+
}
|
|
22281
|
+
async persistModel(queryPayload) {
|
|
22282
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
22283
|
+
}
|
|
22284
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
22285
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
22286
|
+
}
|
|
22287
|
+
startSubscription() {
|
|
22288
|
+
return this.queryStreamController.subscribeRTE([
|
|
22289
|
+
{ fn: onPostCreated, action: EnumPostActions.OnPostCreated },
|
|
22290
|
+
{ fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
|
|
22291
|
+
{ fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
|
|
22292
|
+
{ fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
|
|
22293
|
+
{ fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
|
|
22294
|
+
{ fn: onPostApproved, action: EnumPostActions.OnPostApproved },
|
|
22295
|
+
{ fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
|
|
22296
|
+
{ fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
|
|
22297
|
+
{ fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
|
|
22298
|
+
{
|
|
22299
|
+
fn: convertEventPayload((callback) => {
|
|
22300
|
+
return onCommentCreated(async (comment) => {
|
|
22301
|
+
var _a;
|
|
22302
|
+
const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22303
|
+
if (!currentCollection || currentCollection.data.includes(comment.referenceId))
|
|
22304
|
+
return;
|
|
22305
|
+
await getPost(comment.referenceId);
|
|
22306
|
+
callback(comment);
|
|
22307
|
+
});
|
|
22308
|
+
}, 'referenceId', 'post'),
|
|
22309
|
+
action: EnumPostActions.OnPostUpdated,
|
|
22310
|
+
},
|
|
22311
|
+
{
|
|
22312
|
+
fn: convertEventPayload((callback) => {
|
|
22313
|
+
return onCommentDeleted(async (comment) => {
|
|
22314
|
+
var _a;
|
|
22315
|
+
const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22316
|
+
if (!currentCollection || currentCollection.data.includes(comment.referenceId))
|
|
22317
|
+
return;
|
|
22318
|
+
await getPost(comment.referenceId);
|
|
22319
|
+
callback(comment);
|
|
22320
|
+
});
|
|
22321
|
+
}, 'referenceId', 'post'),
|
|
22322
|
+
action: EnumPostActions.OnPostUpdated,
|
|
22323
|
+
},
|
|
22324
|
+
]);
|
|
22325
|
+
}
|
|
22326
|
+
notifyChange({ origin, loading, error }) {
|
|
22327
|
+
var _a, _b;
|
|
22328
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22329
|
+
if (!collection)
|
|
22330
|
+
return;
|
|
22331
|
+
const data = this.applyFilter((_b = collection.data
|
|
22332
|
+
.map(id => pullFromCache(['post', 'get', id]))
|
|
22333
|
+
.filter(isNonNullable)
|
|
22334
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
|
|
22335
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
22336
|
+
return;
|
|
22337
|
+
this.callback({
|
|
22338
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
22339
|
+
data,
|
|
22340
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
22341
|
+
loading,
|
|
22342
|
+
error,
|
|
22343
|
+
});
|
|
22344
|
+
}
|
|
22345
|
+
applyFilter(data) {
|
|
22346
|
+
var _a;
|
|
22347
|
+
let posts = data;
|
|
22348
|
+
if (!this.query.includeDeleted) {
|
|
22349
|
+
posts = filterByPropEquality(posts, 'isDeleted', false);
|
|
22350
|
+
}
|
|
22351
|
+
if (this.query.tags) {
|
|
22352
|
+
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); }); });
|
|
22353
|
+
}
|
|
22354
|
+
if (this.query.targetType === 'community' && this.query.feedType) {
|
|
22355
|
+
posts = filterByFeedType(posts, this.query.feedType);
|
|
22356
|
+
}
|
|
22357
|
+
if ((_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.length) {
|
|
22358
|
+
posts = filterByPostDataTypes(posts, this.query.dataTypes);
|
|
22359
|
+
}
|
|
22360
|
+
switch (this.query.sortBy) {
|
|
22361
|
+
case 'firstCreated':
|
|
22362
|
+
posts = posts.sort(sortByFirstCreated);
|
|
22363
|
+
break;
|
|
22364
|
+
case 'lastCreated':
|
|
22365
|
+
default:
|
|
22366
|
+
posts = posts.sort(sortByLastCreated);
|
|
22367
|
+
break;
|
|
22368
|
+
}
|
|
22369
|
+
return posts;
|
|
22370
|
+
}
|
|
22371
|
+
}
|
|
22372
|
+
|
|
22157
22373
|
/* begin_public_function
|
|
22158
22374
|
id: post.query
|
|
22159
22375
|
*/
|
|
@@ -22185,121 +22401,9 @@ const getPosts = (params, callback, config) => {
|
|
|
22185
22401
|
}
|
|
22186
22402
|
const timestamp = Date.now();
|
|
22187
22403
|
log(`getPosts(tmpid: ${timestamp}) > listen`);
|
|
22188
|
-
const
|
|
22189
|
-
const
|
|
22190
|
-
const
|
|
22191
|
-
const disposers = [];
|
|
22192
|
-
const cacheKey = [
|
|
22193
|
-
'post',
|
|
22194
|
-
'collection',
|
|
22195
|
-
{ targetId: params.targetId, targetType: params.targetType },
|
|
22196
|
-
];
|
|
22197
|
-
const responder = (data) => {
|
|
22198
|
-
var _a, _b, _c;
|
|
22199
|
-
let posts = (_a = data.data
|
|
22200
|
-
.map(postId => pullFromCache(['post', 'get', postId]))
|
|
22201
|
-
.filter(Boolean)
|
|
22202
|
-
.map(({ data }) => LinkedObject.post(data))) !== null && _a !== void 0 ? _a : [];
|
|
22203
|
-
const sortBy = params.sortBy ? params.sortBy : 'lastCreated';
|
|
22204
|
-
posts = posts.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
22205
|
-
if (!params.includeDeleted) {
|
|
22206
|
-
posts = filterByPropEquality(posts, 'isDeleted', false);
|
|
22207
|
-
}
|
|
22208
|
-
if (params.tags) {
|
|
22209
|
-
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); }); });
|
|
22210
|
-
}
|
|
22211
|
-
if (params.targetType === 'community' && params.feedType) {
|
|
22212
|
-
posts = filterByFeedType(posts, params.feedType);
|
|
22213
|
-
}
|
|
22214
|
-
if ((_b = params.dataTypes) === null || _b === void 0 ? void 0 : _b.length) {
|
|
22215
|
-
posts = filterByPostDataTypes(posts, params.dataTypes);
|
|
22216
|
-
}
|
|
22217
|
-
callback({
|
|
22218
|
-
onNextPage: onFetch,
|
|
22219
|
-
data: posts,
|
|
22220
|
-
hasNextPage: !!((_c = data.params) === null || _c === void 0 ? void 0 : _c.page),
|
|
22221
|
-
loading: data.loading,
|
|
22222
|
-
error: data.error,
|
|
22223
|
-
});
|
|
22224
|
-
};
|
|
22225
|
-
const realtimeRouter = (action) => (post) => {
|
|
22226
|
-
var _a, _b;
|
|
22227
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22228
|
-
if (!collection)
|
|
22229
|
-
return;
|
|
22230
|
-
if (post.parentPostId && post.isDeleted) {
|
|
22231
|
-
const parentPost = (_b = pullFromCache([
|
|
22232
|
-
'post',
|
|
22233
|
-
'get',
|
|
22234
|
-
post.parentPostId,
|
|
22235
|
-
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
22236
|
-
if (!parentPost || (parentPost === null || parentPost === void 0 ? void 0 : parentPost.targetId) !== params.targetId)
|
|
22237
|
-
return;
|
|
22238
|
-
parentPost.children = parentPost.children.filter(childId => childId !== post.postId);
|
|
22239
|
-
pushToCache(['post', 'get', parentPost.postId], parentPost);
|
|
22240
|
-
}
|
|
22241
|
-
else {
|
|
22242
|
-
if (params.targetId !== post.targetId)
|
|
22243
|
-
return;
|
|
22244
|
-
if (params.targetType !== post.targetType)
|
|
22245
|
-
return;
|
|
22246
|
-
}
|
|
22247
|
-
/*
|
|
22248
|
-
* This is not ideal, but currently this is the only way to update the
|
|
22249
|
-
* collection on post declined
|
|
22250
|
-
*/
|
|
22251
|
-
if (action === 'onDeclined') {
|
|
22252
|
-
collection.data = collection.data.filter(postId => postId !== post.postId);
|
|
22253
|
-
}
|
|
22254
|
-
else {
|
|
22255
|
-
collection.data = [...new Set([post.postId, ...collection.data])];
|
|
22256
|
-
}
|
|
22257
|
-
pushToCache(cacheKey, collection);
|
|
22258
|
-
responder(collection);
|
|
22259
|
-
};
|
|
22260
|
-
const onFetch = (initial = false) => {
|
|
22261
|
-
var _a, _b, _c;
|
|
22262
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22263
|
-
const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
22264
|
-
if (!initial && posts.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
|
|
22265
|
-
return;
|
|
22266
|
-
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 }));
|
|
22267
|
-
runQuery(query, ({ data: result, error, loading, paging }) => {
|
|
22268
|
-
const data = {
|
|
22269
|
-
loading,
|
|
22270
|
-
error,
|
|
22271
|
-
params: { page: paging === null || paging === void 0 ? void 0 : paging.next },
|
|
22272
|
-
data: posts,
|
|
22273
|
-
};
|
|
22274
|
-
if (result) {
|
|
22275
|
-
data.data = initial
|
|
22276
|
-
? result.map(getResolver('post'))
|
|
22277
|
-
: [...new Set([...posts, ...result.map(getResolver('post'))])];
|
|
22278
|
-
}
|
|
22279
|
-
pushToCache(cacheKey, data);
|
|
22280
|
-
responder(data);
|
|
22281
|
-
}, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
|
|
22282
|
-
};
|
|
22283
|
-
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) => {
|
|
22284
|
-
return onCommentCreated(async (comment) => {
|
|
22285
|
-
var _a;
|
|
22286
|
-
const currentCollection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22287
|
-
if (!currentCollection || currentCollection.data.includes(comment.referenceId))
|
|
22288
|
-
return;
|
|
22289
|
-
await getPost$1(comment.referenceId);
|
|
22290
|
-
callback(comment);
|
|
22291
|
-
});
|
|
22292
|
-
}, 'referenceId', 'post')(realtimeRouter('onUpdate')), convertEventPayload((callback) => {
|
|
22293
|
-
return onCommentDeleted(async (comment) => {
|
|
22294
|
-
var _a;
|
|
22295
|
-
const currentCollection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22296
|
-
if (!currentCollection || currentCollection.data.includes(comment.referenceId))
|
|
22297
|
-
return;
|
|
22298
|
-
await getPost$1(comment.referenceId);
|
|
22299
|
-
callback(comment);
|
|
22300
|
-
});
|
|
22301
|
-
}, 'referenceId', 'post')(realtimeRouter('onUpdate')));
|
|
22302
|
-
onFetch(true);
|
|
22404
|
+
const postsLiveCollection = new PostLiveCollectionController(params, callback);
|
|
22405
|
+
const disposers = postsLiveCollection.startSubscription();
|
|
22406
|
+
const cacheKey = postsLiveCollection.getCacheKey();
|
|
22303
22407
|
disposers.push(() => dropFromCache(cacheKey));
|
|
22304
22408
|
return () => {
|
|
22305
22409
|
log(`getPosts(tmpid: ${timestamp}) > dispose`);
|
|
@@ -22333,7 +22437,7 @@ var index$5 = /*#__PURE__*/Object.freeze({
|
|
|
22333
22437
|
onPostReactionRemoved: onPostReactionRemoved,
|
|
22334
22438
|
observePosts: observePosts,
|
|
22335
22439
|
observePost: observePost,
|
|
22336
|
-
getPost: getPost,
|
|
22440
|
+
getPost: getPost$1,
|
|
22337
22441
|
getPosts: getPosts
|
|
22338
22442
|
});
|
|
22339
22443
|
|