@amityco/ts-sdk-react-native 6.30.2-bc5ef81.0 → 6.30.3-cae094b.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.
Files changed (50) hide show
  1. package/dist/@types/core/payload.d.ts +12 -0
  2. package/dist/@types/core/payload.d.ts.map +1 -1
  3. package/dist/@types/domains/post.d.ts +10 -0
  4. package/dist/@types/domains/post.d.ts.map +1 -1
  5. package/dist/commentRepository/api/createComment.d.ts.map +1 -1
  6. package/dist/commentRepository/api/deleteComment.d.ts.map +1 -1
  7. package/dist/commentRepository/internalApi/createComment.d.ts.map +1 -1
  8. package/dist/commentRepository/internalApi/deleteComment.d.ts.map +1 -1
  9. package/dist/core/query/filtering.d.ts.map +1 -1
  10. package/dist/index.cjs.js +254 -26
  11. package/dist/index.esm.js +254 -26
  12. package/dist/index.umd.js +3 -3
  13. package/dist/postRepository/api/deletePost.d.ts.map +1 -1
  14. package/dist/postRepository/observers/enums.d.ts +12 -0
  15. package/dist/postRepository/observers/enums.d.ts.map +1 -0
  16. package/dist/postRepository/observers/getPosts/PostQueryStreamController.d.ts +1 -1
  17. package/dist/postRepository/observers/getPosts/PostQueryStreamController.d.ts.map +1 -1
  18. package/dist/postRepository/observers/index.d.ts +1 -0
  19. package/dist/postRepository/observers/index.d.ts.map +1 -1
  20. package/dist/postRepository/observers/semanticSearch/SemanticSearchPostLiveCollectionController.d.ts +14 -0
  21. package/dist/postRepository/observers/semanticSearch/SemanticSearchPostLiveCollectionController.d.ts.map +1 -0
  22. package/dist/postRepository/observers/semanticSearch/SemanticSearchPostPaginationController.d.ts +11 -0
  23. package/dist/postRepository/observers/semanticSearch/SemanticSearchPostPaginationController.d.ts.map +1 -0
  24. package/dist/postRepository/observers/semanticSearch/SemanticSearchPostQueryStreamController.d.ts +15 -0
  25. package/dist/postRepository/observers/semanticSearch/SemanticSearchPostQueryStreamController.d.ts.map +1 -0
  26. package/dist/postRepository/observers/semanticSearch/utils.d.ts +3 -0
  27. package/dist/postRepository/observers/semanticSearch/utils.d.ts.map +1 -0
  28. package/dist/postRepository/observers/semanticSearchPosts.d.ts +10 -0
  29. package/dist/postRepository/observers/semanticSearchPosts.d.ts.map +1 -0
  30. package/dist/postRepository/utils/payload.d.ts +2 -1
  31. package/dist/postRepository/utils/payload.d.ts.map +1 -1
  32. package/package.json +1 -1
  33. package/src/@types/core/payload.ts +11 -0
  34. package/src/@types/domains/post.ts +17 -0
  35. package/src/commentRepository/api/createComment.ts +1 -0
  36. package/src/commentRepository/api/deleteComment.ts +1 -0
  37. package/src/commentRepository/internalApi/createComment.ts +1 -0
  38. package/src/commentRepository/internalApi/deleteComment.ts +1 -0
  39. package/src/core/query/filtering.ts +6 -22
  40. package/src/postRepository/api/deletePost.ts +1 -0
  41. package/src/postRepository/observers/enums.ts +11 -0
  42. package/src/postRepository/observers/getPosts/PostLiveCollectionController.ts +1 -1
  43. package/src/postRepository/observers/getPosts/PostQueryStreamController.ts +1 -1
  44. package/src/postRepository/observers/index.ts +1 -0
  45. package/src/postRepository/observers/semanticSearch/SemanticSearchPostLiveCollectionController.ts +199 -0
  46. package/src/postRepository/observers/semanticSearch/SemanticSearchPostPaginationController.ts +27 -0
  47. package/src/postRepository/observers/semanticSearch/SemanticSearchPostQueryStreamController.ts +111 -0
  48. package/src/postRepository/observers/semanticSearch/utils.ts +12 -0
  49. package/src/postRepository/observers/semanticSearchPosts.ts +42 -0
  50. package/src/postRepository/utils/payload.ts +17 -2
package/dist/index.esm.js CHANGED
@@ -88,8 +88,8 @@ const PostContentType = Object.freeze({
88
88
 
89
89
  function getVersion() {
90
90
  try {
91
- // the string ''v6.30.1-esm'' should be replaced by actual value by @rollup/plugin-replace
92
- return 'v6.30.1-esm';
91
+ // the string ''v6.30.2-esm'' should be replaced by actual value by @rollup/plugin-replace
92
+ return 'v6.30.2-esm';
93
93
  }
94
94
  catch (error) {
95
95
  return '__dev__';
@@ -1150,33 +1150,18 @@ const filterByCommunityMembership = (collection, membership, userId) => {
1150
1150
  * @hidden
1151
1151
  */
1152
1152
  const filterByPostDataTypes = (collection, dataTypes) => {
1153
- const postIds = [];
1154
1153
  return collection.reduce((acc, post) => {
1155
1154
  var _a;
1156
- // A text post with no children is just a text post
1157
- if (post.dataType === 'text' && !post.children.length)
1158
- return acc;
1159
- // Skip if post is already in the collection
1160
- if (postIds.includes(post.postId))
1161
- return acc;
1162
1155
  // Check dataType for current post
1163
1156
  if (dataTypes === null || dataTypes === void 0 ? void 0 : dataTypes.includes(post.dataType)) {
1164
- acc.push(post);
1157
+ return [...acc, post];
1165
1158
  }
1166
- // Check dataType for child post. this function will return all child posts in a same level of parent post (flatten)
1167
- if (!post.children.length)
1168
- return acc;
1169
- const childPost = (_a = pullFromCache(['post', 'get', post.children[0]])) === null || _a === void 0 ? void 0 : _a.data;
1170
- if (!childPost)
1159
+ if (((post === null || post === void 0 ? void 0 : post.children) || []).length > 0) {
1160
+ const childPost = (_a = pullFromCache(['post', 'get', post.children[0]])) === null || _a === void 0 ? void 0 : _a.data;
1161
+ if (!(dataTypes === null || dataTypes === void 0 ? void 0 : dataTypes.includes(childPost === null || childPost === void 0 ? void 0 : childPost.dataType)))
1162
+ return [...acc, post];
1171
1163
  return acc;
1172
- // Prevent to insert a duplicate record
1173
- if (postIds.includes(childPost.postId))
1174
- return acc;
1175
- if (!(dataTypes === null || dataTypes === void 0 ? void 0 : dataTypes.includes(childPost === null || childPost === void 0 ? void 0 : childPost.dataType)))
1176
- return acc;
1177
- postIds.push(childPost.postId);
1178
- // @ts-ignore
1179
- acc.push(childPost);
1164
+ }
1180
1165
  return acc;
1181
1166
  }, []);
1182
1167
  };
@@ -29614,7 +29599,8 @@ const prepareCommunityRequest = (params) => {
29614
29599
  allowCommentInStory: typeof (storySetting === null || storySetting === void 0 ? void 0 : storySetting.enableComment) === 'boolean' ? storySetting.enableComment : true });
29615
29600
  };
29616
29601
 
29617
- const preparePostPayload = (postPayload) => {
29602
+ const preparePostPayload = (payload) => {
29603
+ const { posts: postsData } = payload, postPayload = __rest(payload, ["posts"]);
29618
29604
  // Unpack community payload by mapping payload field to postSetting value.
29619
29605
  const communitiesWithPostSetting = addPostSetting({ communities: postPayload.communities });
29620
29606
  // map users with community
@@ -29624,12 +29610,17 @@ const preparePostPayload = (postPayload) => {
29624
29610
  });
29625
29611
  const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
29626
29612
  // feed type
29627
- const posts = postPayload.posts.map(post => {
29613
+ const posts = postsData.map(post => {
29628
29614
  var _a;
29629
29615
  const feedType = (_a = postPayload.feeds.find(feed => feed.feedId === post.feedId)) === null || _a === void 0 ? void 0 : _a.feedType;
29630
29616
  return Object.assign(Object.assign({}, post), { feedType });
29631
29617
  });
29632
29618
  return Object.assign(Object.assign({}, postPayload), { posts, communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
29619
+ };
29620
+ const prepareSemanticSearchPostPayload = (_a) => {
29621
+ var { searchResult, polls } = _a, postPayload = __rest(_a, ["searchResult", "polls"]);
29622
+ const processedPostPayload = preparePostPayload(postPayload);
29623
+ return Object.assign(Object.assign({}, processedPostPayload), { polls });
29633
29624
  };
29634
29625
 
29635
29626
  const createPostEventSubscriber = (event, callback) => {
@@ -37684,6 +37675,7 @@ const deletePost = async (postId, permanent = false) => {
37684
37675
  files: [],
37685
37676
  postChildren: [],
37686
37677
  users: [],
37678
+ videoStreamings: [],
37687
37679
  });
37688
37680
  return LinkedObject.post(deleted);
37689
37681
  };
@@ -38097,6 +38089,7 @@ const createComment = async (bundle) => {
38097
38089
  files: data.files,
38098
38090
  postChildren: [],
38099
38091
  users: data.users,
38092
+ videoStreamings: [],
38100
38093
  });
38101
38094
  }
38102
38095
  }
@@ -38302,6 +38295,7 @@ const deleteComment = async (commentId, permanent = false) => {
38302
38295
  files: [],
38303
38296
  postChildren: [],
38304
38297
  users: [],
38298
+ videoStreamings: [],
38305
38299
  });
38306
38300
  }
38307
38301
  }
@@ -39563,6 +39557,239 @@ const getPinnedPosts = (params, callback, config) => {
39563
39557
  };
39564
39558
  };
39565
39559
 
39560
+ class SemanticSearchPostPaginationController extends PaginationController {
39561
+ async getRequest(queryParams, token) {
39562
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
39563
+ const baseOptions = {
39564
+ type: queryParams.limit ? 'pagination' : undefined,
39565
+ };
39566
+ const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
39567
+ const { data: queryResponse } = await this.http.get(`/api/v1/semantic-search/posts`, {
39568
+ params: Object.assign(Object.assign({}, params), { options }),
39569
+ });
39570
+ return queryResponse;
39571
+ }
39572
+ }
39573
+
39574
+ function preparePostResponse(response) {
39575
+ return response.posts.map(post => {
39576
+ const postScore = response.searchResult.find(result => result.postId === post.postId);
39577
+ return `${post.postId}:${postScore.score}`;
39578
+ });
39579
+ }
39580
+ function getPostIdsFromCache(cacheData) {
39581
+ return (cacheData !== null && cacheData !== void 0 ? cacheData : []).map(postIdWithScore => {
39582
+ return postIdWithScore.split(':')[0];
39583
+ });
39584
+ }
39585
+
39586
+ class SemanticSearchPostQueryStreamController extends QueryStreamController {
39587
+ constructor(query, cacheKey, notifyChange, preparePayload) {
39588
+ super(query, cacheKey);
39589
+ this.notifyChange = notifyChange;
39590
+ this.preparePayload = preparePayload;
39591
+ }
39592
+ async saveToMainDB(response) {
39593
+ const processedPayload = this.preparePayload(response);
39594
+ const client = getActiveClient();
39595
+ const cachedAt = client.cache && Date.now();
39596
+ if (client.cache) {
39597
+ ingestInCache(processedPayload, { cachedAt });
39598
+ }
39599
+ }
39600
+ appendToQueryStream(response, direction, refresh = false) {
39601
+ var _a, _b;
39602
+ if (refresh) {
39603
+ pushToCache(this.cacheKey, {
39604
+ data: preparePostResponse(response),
39605
+ });
39606
+ }
39607
+ else {
39608
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
39609
+ const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
39610
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...preparePostResponse(response)])] }));
39611
+ }
39612
+ }
39613
+ reactor(action) {
39614
+ return (post) => {
39615
+ var _a, _b;
39616
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
39617
+ if (!collection)
39618
+ return;
39619
+ if (post.parentPostId && post.isDeleted) {
39620
+ const parentSemanticSearchPost = (_b = pullFromCache([
39621
+ 'post',
39622
+ 'get',
39623
+ post.parentPostId,
39624
+ ])) === null || _b === void 0 ? void 0 : _b.data;
39625
+ if (!parentSemanticSearchPost || (parentSemanticSearchPost === null || parentSemanticSearchPost === void 0 ? void 0 : parentSemanticSearchPost.targetId) !== this.query.targetId)
39626
+ return;
39627
+ parentSemanticSearchPost.children = parentSemanticSearchPost.children.filter(childId => childId !== post.postId);
39628
+ pushToCache(['post', 'get', parentSemanticSearchPost.postId], parentSemanticSearchPost);
39629
+ }
39630
+ else {
39631
+ if (this.query.targetId !== post.targetId)
39632
+ return;
39633
+ if (this.query.targetType !== post.targetType)
39634
+ return;
39635
+ }
39636
+ if (action === EnumPostActions.OnPostDeclined) {
39637
+ collection.data = collection.data.filter(postId => postId !== post.postId);
39638
+ }
39639
+ if (action === EnumPostActions.OnPostCreated || action === EnumPostActions.OnPostApproved) {
39640
+ collection.data = [...new Set([post.postId, ...collection.data])];
39641
+ }
39642
+ pushToCache(this.cacheKey, collection);
39643
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
39644
+ };
39645
+ }
39646
+ subscribeRTE(createSubscriber) {
39647
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
39648
+ }
39649
+ }
39650
+
39651
+ class SemanticSearchPostLiveCollectionController extends LiveCollectionController {
39652
+ constructor(inputQuery, callback) {
39653
+ const query = Object.assign(Object.assign({}, inputQuery), { matchingOnlyParentPost: inputQuery.matchingOnlyParentPost == null ? true : inputQuery.matchingOnlyParentPost, dataTypes: inputQuery.dataTypes == null ? ['text', 'image'] : inputQuery.dataTypes });
39654
+ const queryStreamId = hash(query);
39655
+ const cacheKey = ['posts', 'collection', queryStreamId];
39656
+ const paginationController = new SemanticSearchPostPaginationController(query);
39657
+ super(paginationController, queryStreamId, cacheKey, callback);
39658
+ this.query = query;
39659
+ this.queryStreamController = new SemanticSearchPostQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareSemanticSearchPostPayload);
39660
+ this.callback = callback.bind(this);
39661
+ this.loadPage({ initial: true });
39662
+ }
39663
+ setup() {
39664
+ var _a;
39665
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
39666
+ if (!collection) {
39667
+ pushToCache(this.cacheKey, {
39668
+ data: [],
39669
+ params: {},
39670
+ });
39671
+ }
39672
+ }
39673
+ async persistModel(queryPayload) {
39674
+ await this.queryStreamController.saveToMainDB(queryPayload);
39675
+ }
39676
+ persistQueryStream({ response, direction, refresh, }) {
39677
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
39678
+ }
39679
+ startSubscription() {
39680
+ return this.queryStreamController.subscribeRTE([
39681
+ { fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
39682
+ { fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
39683
+ { fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
39684
+ {
39685
+ fn: onPostUnflagged,
39686
+ action: EnumPostActions.OnPostUnflagged,
39687
+ },
39688
+ { fn: onPostApproved, action: EnumPostActions.OnPostApproved },
39689
+ { fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
39690
+ {
39691
+ fn: onPostReactionAdded,
39692
+ action: EnumPostActions.OnPostReactionAdded,
39693
+ },
39694
+ {
39695
+ fn: onPostReactionRemoved,
39696
+ action: EnumPostActions.OnPostReactionRemoved,
39697
+ },
39698
+ {
39699
+ fn: convertEventPayload((callback) => {
39700
+ return onCommentCreated(async (comment) => {
39701
+ const collectionCache = pullFromCache(this.cacheKey);
39702
+ const currentCollectionPostIds = getPostIdsFromCache(collectionCache === null || collectionCache === void 0 ? void 0 : collectionCache.data);
39703
+ if (currentCollectionPostIds.includes(comment.referenceId))
39704
+ return;
39705
+ await getPost$2(comment.referenceId);
39706
+ callback(comment);
39707
+ });
39708
+ }, 'referenceId', 'post'),
39709
+ action: EnumPostActions.OnPostUpdated,
39710
+ },
39711
+ {
39712
+ fn: convertEventPayload((callback) => {
39713
+ return onCommentDeleted(async (comment) => {
39714
+ const collectionCache = pullFromCache(this.cacheKey);
39715
+ const currentCollectionPostIds = getPostIdsFromCache(collectionCache === null || collectionCache === void 0 ? void 0 : collectionCache.data);
39716
+ if (currentCollectionPostIds.includes(comment.referenceId))
39717
+ return;
39718
+ await getPost$2(comment.referenceId);
39719
+ callback(comment);
39720
+ });
39721
+ }, 'referenceId', 'post'),
39722
+ action: EnumPostActions.OnPostUpdated,
39723
+ },
39724
+ ]);
39725
+ }
39726
+ notifyChange({ origin, loading, error }) {
39727
+ var _a, _b;
39728
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
39729
+ if (!collection)
39730
+ return;
39731
+ const data = this.applyFilter((_b = collection.data
39732
+ .map(postIdWithScore => {
39733
+ const [postId, score] = postIdWithScore.split(':');
39734
+ return {
39735
+ postId,
39736
+ score: parseFloat(score),
39737
+ };
39738
+ })
39739
+ .sort((a, b) => b.score - a.score)
39740
+ .map(({ postId }) => pullFromCache(['post', 'get', postId]))
39741
+ .filter(isNonNullable)
39742
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
39743
+ if (!this.shouldNotify(data) && origin === 'event')
39744
+ return;
39745
+ this.callback({
39746
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
39747
+ data,
39748
+ hasNextPage: !!this.paginationController.getNextToken(),
39749
+ loading,
39750
+ error,
39751
+ });
39752
+ }
39753
+ applyFilter(data) {
39754
+ let posts = data;
39755
+ if (this.query.targetType) {
39756
+ posts = posts.filter(post => post.targetType === this.query.targetType);
39757
+ }
39758
+ if (this.query.targetId) {
39759
+ posts = posts.filter(post => post.targetId === this.query.targetId);
39760
+ }
39761
+ if (this.query.dataTypes && this.query.dataTypes.length > 0) {
39762
+ posts = filterByPostDataTypes(posts, this.query.dataTypes);
39763
+ }
39764
+ return posts;
39765
+ }
39766
+ }
39767
+
39768
+ /**
39769
+ * search posts by semantic search
39770
+ *
39771
+ * @returns the associated pinned post(s)
39772
+ *
39773
+ * @category Posts Live Collection
39774
+ *
39775
+ */
39776
+ const semanticSearchPosts = (params, callback, config) => {
39777
+ const { log, cache } = getActiveClient();
39778
+ if (!cache) {
39779
+ console.log(ENABLE_CACHE_MESSAGE);
39780
+ }
39781
+ const timestamp = Date.now();
39782
+ log(`semanticSearchPosts(tmpid: ${timestamp}) > listen`);
39783
+ const semanticSearchPostLiveCollection = new SemanticSearchPostLiveCollectionController(params, callback);
39784
+ const disposers = semanticSearchPostLiveCollection.startSubscription();
39785
+ const cacheKey = semanticSearchPostLiveCollection.getCacheKey();
39786
+ disposers.push(() => dropFromCache(cacheKey));
39787
+ return () => {
39788
+ log(`semanticSearchPosts(tmpid: ${timestamp}) > dispose`);
39789
+ disposers.forEach(fn => fn());
39790
+ };
39791
+ };
39792
+
39566
39793
  var index$5 = /*#__PURE__*/Object.freeze({
39567
39794
  __proto__: null,
39568
39795
  getPostByIds: getPostByIds,
@@ -39590,7 +39817,8 @@ var index$5 = /*#__PURE__*/Object.freeze({
39590
39817
  observePost: observePost,
39591
39818
  getPost: getPost$1,
39592
39819
  getPosts: getPosts,
39593
- getPinnedPosts: getPinnedPosts
39820
+ getPinnedPosts: getPinnedPosts,
39821
+ semanticSearchPosts: semanticSearchPosts
39594
39822
  });
39595
39823
 
39596
39824
  /* begin_public_function