@amityco/ts-sdk-react-native 6.16.0 → 6.17.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 (70) hide show
  1. package/dist/@types/core/events.d.ts +1 -0
  2. package/dist/@types/core/events.d.ts.map +1 -1
  3. package/dist/@types/domains/client.d.ts +1 -1
  4. package/dist/@types/domains/client.d.ts.map +1 -1
  5. package/dist/@types/domains/reaction.d.ts +1 -1
  6. package/dist/@types/domains/reaction.d.ts.map +1 -1
  7. package/dist/@types/domains/story.d.ts +4 -0
  8. package/dist/@types/domains/story.d.ts.map +1 -1
  9. package/dist/cache/api/backupCache.d.ts.map +1 -1
  10. package/dist/cache/api/restoreCache.d.ts.map +1 -1
  11. package/dist/cache/api/wipeCache.d.ts.map +1 -1
  12. package/dist/channelRepository/events/onChannelLeft.d.ts.map +1 -1
  13. package/dist/channelRepository/utils/prepareChannelPayload.d.ts +9 -3
  14. package/dist/channelRepository/utils/prepareChannelPayload.d.ts.map +1 -1
  15. package/dist/commentRepository/api/createComment.d.ts.map +1 -1
  16. package/dist/commentRepository/events/utils.d.ts.map +1 -1
  17. package/dist/commentRepository/observers/getComment.d.ts.map +1 -1
  18. package/dist/core/events.d.ts +3 -3
  19. package/dist/core/events.d.ts.map +1 -1
  20. package/dist/index.cjs.js +237 -50
  21. package/dist/index.esm.js +236 -49
  22. package/dist/index.umd.js +4 -4
  23. package/dist/messageRepository/utils/prepareMessagePayload.d.ts.map +1 -1
  24. package/dist/postRepository/observers/getPost.d.ts.map +1 -1
  25. package/dist/postRepository/observers/getPosts.d.ts.map +1 -1
  26. package/dist/reactionRepository/events/onReactionAdded.d.ts +1 -1
  27. package/dist/reactionRepository/events/onReactionAdded.d.ts.map +1 -1
  28. package/dist/reactionRepository/events/onReactionRemoved.d.ts +1 -1
  29. package/dist/reactionRepository/events/onReactionRemoved.d.ts.map +1 -1
  30. package/dist/reactionRepository/utils/dispatchReactable.d.ts.map +1 -1
  31. package/dist/reactionRepository/utils/fetchReference.d.ts +1 -1
  32. package/dist/reactionRepository/utils/fetchReference.d.ts.map +1 -1
  33. package/dist/storyRepository/constants.d.ts +1 -0
  34. package/dist/storyRepository/constants.d.ts.map +1 -1
  35. package/dist/storyRepository/events/onStoryUpdated.d.ts +2 -0
  36. package/dist/storyRepository/events/onStoryUpdated.d.ts.map +1 -0
  37. package/dist/storyRepository/observers/getActiveStoriesByTarget.d.ts.map +1 -1
  38. package/dist/storyRepository/observers/getTargetsByTargetIds.d.ts +2 -0
  39. package/dist/storyRepository/observers/getTargetsByTargetIds.d.ts.map +1 -0
  40. package/dist/storyRepository/observers/index.d.ts +1 -0
  41. package/dist/storyRepository/observers/index.d.ts.map +1 -1
  42. package/dist/storyRepository/utils/convertStoryPayloadToRaw.d.ts.map +1 -1
  43. package/dist/utils/tests/dummy/post.d.ts.map +1 -1
  44. package/package.json +1 -1
  45. package/src/@types/core/events.ts +1 -0
  46. package/src/@types/domains/client.ts +1 -1
  47. package/src/@types/domains/reaction.ts +1 -1
  48. package/src/@types/domains/story.ts +6 -0
  49. package/src/analytic/api/queryReachUser.ts +1 -1
  50. package/src/cache/api/backupCache.ts +3 -3
  51. package/src/cache/api/restoreCache.ts +3 -3
  52. package/src/cache/api/wipeCache.ts +3 -3
  53. package/src/channelRepository/events/onChannelLeft.ts +9 -1
  54. package/src/channelRepository/utils/prepareChannelPayload.ts +31 -5
  55. package/src/commentRepository/api/createComment.ts +53 -13
  56. package/src/commentRepository/api/updateComment.ts +1 -1
  57. package/src/commentRepository/events/utils.ts +34 -13
  58. package/src/commentRepository/observers/getComment.ts +21 -0
  59. package/src/communityRepository/communityMembership/events/tests/utils.test.ts +2 -1
  60. package/src/messageRepository/utils/prepareMessagePayload.ts +1 -2
  61. package/src/postRepository/observers/getPost.ts +25 -1
  62. package/src/postRepository/observers/getPosts.ts +11 -5
  63. package/src/reactionRepository/utils/dispatchReactable.ts +11 -0
  64. package/src/storyRepository/constants.ts +1 -0
  65. package/src/storyRepository/events/onStoryUpdated.ts +14 -0
  66. package/src/storyRepository/observers/getActiveStoriesByTarget.ts +2 -0
  67. package/src/storyRepository/observers/getTargetsByTargetIds.ts +88 -0
  68. package/src/storyRepository/observers/index.ts +1 -0
  69. package/src/storyRepository/utils/convertStoryPayloadToRaw.ts +1 -0
  70. package/src/utils/tests/dummy/post.ts +1 -0
package/dist/index.esm.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { encode, decode, btoa, atob } from 'js-base64';
2
- import AsyncStorage from '@react-native-async-storage/async-storage';
3
2
  import mitt from 'mitt';
4
3
  import debug from 'debug';
5
4
  import axios from 'axios';
6
5
  import HttpAgent, { HttpsAgent } from 'agentkeepalive';
7
6
  import io from 'socket.io-client';
7
+ import AsyncStorage from '@react-native-async-storage/async-storage';
8
8
  import uuid$1 from 'react-native-uuid';
9
9
  import hash from 'object-hash';
10
10
  import Hls from 'hls.js';
@@ -84,8 +84,8 @@ const PostContentType = Object.freeze({
84
84
 
85
85
  function getVersion() {
86
86
  try {
87
- // the string ''v6.16.0-esm'' should be replaced by actual value by @rollup/plugin-replace
88
- return 'v6.16.0-esm';
87
+ // the string ''v6.17.0-esm'' should be replaced by actual value by @rollup/plugin-replace
88
+ return 'v6.17.0-esm';
89
89
  }
90
90
  catch (error) {
91
91
  return '__dev__';
@@ -736,7 +736,9 @@ const restoreCache = async (storageKey = 'amitySdk') => {
736
736
  if (!client.cache)
737
737
  return false;
738
738
  client.log('cache/api/restoreCache', { storageKey });
739
- const serializedData = (_a = (await AsyncStorage.getItem(`${storageKey}#${client.userId}`))) !== null && _a !== void 0 ? _a : '{}';
739
+ const serializedData = localStorage
740
+ ? (_a = (await localStorage.getItem(`${storageKey}#${client.userId}`))) !== null && _a !== void 0 ? _a : '{}'
741
+ : '{}';
740
742
  let cache = {};
741
743
  try {
742
744
  cache = JSON.parse(serializedData);
@@ -782,7 +784,9 @@ const backupCache = async (storageKey = 'amitySdk', persistIf = (entry) => entry
782
784
  // nothing to backup, abort
783
785
  if (!Object.keys(offlineEntries).length)
784
786
  return false;
785
- await AsyncStorage.setItem(`${storageKey}#${userId}`, JSON.stringify(offlineEntries));
787
+ if (localStorage) {
788
+ await localStorage.setItem(`${storageKey}#${userId}`, JSON.stringify(offlineEntries));
789
+ }
786
790
  return true;
787
791
  };
788
792
 
@@ -811,7 +815,9 @@ const wipeCache = async (storageKey = 'amitySdk') => {
811
815
  return false;
812
816
  log('cache/api/wipeCache', { storageKey });
813
817
  cache.data = {};
814
- await AsyncStorage.setItem(`${storageKey}#${userId}`, '{}');
818
+ if (localStorage) {
819
+ await localStorage.setItem(`${storageKey}#${userId}`, '{}');
820
+ }
815
821
  return true;
816
822
  };
817
823
 
@@ -21699,23 +21705,34 @@ const handleSubChannelUpdated = async (subChannel) => {
21699
21705
 
21700
21706
  const MARKER_INCLUDED_CHANNEL_TYPE = ['broadcast', 'conversation', 'community'];
21701
21707
  const isUnreadCountSupport$2 = ({ type }) => MARKER_INCLUDED_CHANNEL_TYPE.includes(type);
21702
- function convertFromRaw$2(channel) {
21708
+ function convertFromRaw$2(channel, options = { isMessagePreviewUpdated: true }) {
21709
+ var _a;
21710
+ let { messagePreviewId } = channel;
21711
+ const messagePreviewChannelCache = (_a = pullFromCache([
21712
+ 'messagePreviewChannel',
21713
+ 'get',
21714
+ channel.channelId,
21715
+ ])) === null || _a === void 0 ? void 0 : _a.data;
21716
+ if ((messagePreviewChannelCache === null || messagePreviewChannelCache === void 0 ? void 0 : messagePreviewChannelCache.messagePreviewId) && !options.isMessagePreviewUpdated) {
21717
+ messagePreviewId = messagePreviewChannelCache.messagePreviewId;
21718
+ }
21703
21719
  return Object.assign(Object.assign({ get unreadCount() {
21704
21720
  return getChannelUnreadCount(channel);
21705
21721
  },
21706
21722
  get hasMentioned() {
21707
21723
  return getChannelHasMentioned(channel);
21708
- } }, channel), { defaultSubChannelId: channel._id, isUnreadCountSupport: isUnreadCountSupport$2(channel) });
21724
+ } }, channel), { defaultSubChannelId: channel._id, isUnreadCountSupport: isUnreadCountSupport$2(channel), messagePreviewId });
21709
21725
  }
21710
- const preUpdateChannelCache = (rawPayload) => {
21726
+ const preUpdateChannelCache = (rawPayload, options = { isMessagePreviewUpdated: true }) => {
21711
21727
  ingestInCache({
21712
- channels: rawPayload.channels.map(channel => convertFromRaw$2(channel)),
21728
+ channels: rawPayload.channels.map(channel => convertFromRaw$2(channel, { isMessagePreviewUpdated: options.isMessagePreviewUpdated })),
21713
21729
  });
21714
21730
  };
21715
- const prepareChannelPayload = async (rawPayload) => {
21731
+ const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpdated: true }) => {
21716
21732
  const client = getActiveClient();
21717
21733
  const networkPreviewSetting = await client.getMessagePreviewSetting(false);
21718
- if (networkPreviewSetting !== "no-message-preview" /* Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW */ &&
21734
+ if (options.isMessagePreviewUpdated &&
21735
+ networkPreviewSetting !== "no-message-preview" /* Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW */ &&
21719
21736
  rawPayload.messagePreviews &&
21720
21737
  rawPayload.messagePreviews.length > 0) {
21721
21738
  updateChannelMessagePreviewCache(rawPayload);
@@ -21726,7 +21743,7 @@ const prepareChannelPayload = async (rawPayload) => {
21726
21743
  .map(({ channelId }) => channelId);
21727
21744
  if (markerIds.length > 0) {
21728
21745
  // since the get markers method requires a channel cache to function with the reducer.
21729
- preUpdateChannelCache(rawPayload);
21746
+ preUpdateChannelCache(rawPayload, { isMessagePreviewUpdated: options.isMessagePreviewUpdated });
21730
21747
  try {
21731
21748
  await getChannelMarkers(markerIds);
21732
21749
  }
@@ -21735,7 +21752,7 @@ const prepareChannelPayload = async (rawPayload) => {
21735
21752
  }
21736
21753
  }
21737
21754
  // attach marker to channel
21738
- const channels = rawPayload.channels.map(convertFromRaw$2);
21755
+ const channels = rawPayload.channels.map(payload => convertFromRaw$2(payload, { isMessagePreviewUpdated: options.isMessagePreviewUpdated }));
21739
21756
  // user marker to channel users
21740
21757
  const channelUsers = withUsers(rawPayload.channelUsers);
21741
21758
  const restRawPayload = __rest(rawPayload, ["messageFeedsInfo", "messagePreviews"]);
@@ -22041,6 +22058,7 @@ function convertFromRaw$1(_a) {
22041
22058
  }
22042
22059
 
22043
22060
  function convertFromRaw(message, reactors, event) {
22061
+ var _a;
22044
22062
  const { channelPublicId, childCount, creatorPublicId, mentionedUsers, messageFeedId, myReactions, reactionCount, reactions, referenceId, segment, messageId } = message, rest = __rest(message, ["channelPublicId", "childCount", "creatorPublicId", "mentionedUsers", "messageFeedId", "myReactions", "reactionCount", "reactions", "referenceId", "segment", "messageId"]);
22045
22063
  let cache;
22046
22064
  if (referenceId) {
@@ -22062,7 +22080,7 @@ function convertFromRaw(message, reactors, event) {
22062
22080
  *
22063
22081
  * Check git blame for previous iteration
22064
22082
  */
22065
- myReactions: myReactions !== null && myReactions !== void 0 ? myReactions : [], reactionsCount: reactionCount, subChannelId: messageFeedId, uniqueId: cache ? cache.data.uniqueId : messageId, referenceId });
22083
+ myReactions: myReactions || ((_a = cache === null || cache === void 0 ? void 0 : cache.data.myReactions) !== null && _a !== void 0 ? _a : []), reactionsCount: reactionCount, subChannelId: messageFeedId, uniqueId: cache ? cache.data.uniqueId : messageId, referenceId });
22066
22084
  if (mentionedUsers) {
22067
22085
  out.mentionees = mentionedUsers.map(mention => {
22068
22086
  if (mention.type === 'channel') {
@@ -24055,7 +24073,12 @@ const onChannelJoined = (callback) => {
24055
24073
  const onChannelLeft = (callback) => {
24056
24074
  const client = getActiveClient();
24057
24075
  const filter = async (payload) => {
24058
- const preparedPayload = await prepareChannelPayload(payload);
24076
+ const { userId } = getActiveClient();
24077
+ const { channelUsers: leftUsers } = payload;
24078
+ const isLeftByMe = leftUsers.some(user => user.userId === userId);
24079
+ const preparedPayload = await prepareChannelPayload(payload, {
24080
+ isMessagePreviewUpdated: isLeftByMe,
24081
+ });
24059
24082
  const { channels, channelUsers } = preparedPayload;
24060
24083
  ingestInCache(preparedPayload);
24061
24084
  callback(channels[0], channelUsers[0]);
@@ -27329,6 +27352,17 @@ const dispatchReactable = (referenceType, model) => {
27329
27352
  else if (referenceType === 'comment')
27330
27353
  // @ts-ignore: refactor later
27331
27354
  fireEvent('comment.updated', { comments: [model] });
27355
+ else if (referenceType === 'story')
27356
+ // Need to provide all data same StoryPayload from BE
27357
+ fireEvent('story.updated', {
27358
+ categories: [],
27359
+ comments: [],
27360
+ communities: [],
27361
+ communityUsers: [],
27362
+ files: [],
27363
+ users: [],
27364
+ stories: [model],
27365
+ });
27332
27366
  };
27333
27367
 
27334
27368
  /**
@@ -27995,16 +28029,29 @@ const createCommentEventSubscriber = (event, callback) => {
27995
28029
  }
27996
28030
  else {
27997
28031
  ingestInCache(payload);
27998
- const comment = pullFromCache([
27999
- 'comment',
28000
- 'get',
28001
- payload.comments[0].commentId,
28002
- ]);
28003
- if (['comment.created'].includes(event)) {
28004
- const queries = (_a = queryCache(['comment', 'query'])) === null || _a === void 0 ? void 0 : _a.filter(({ key }) => { var _a; return ((_a = key[2]) === null || _a === void 0 ? void 0 : _a.referenceId) === comment.data.referenceId; });
28005
- queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
28032
+ const { comments } = payload;
28033
+ if (comments.length > 0) {
28034
+ const comment = pullFromCache([
28035
+ 'comment',
28036
+ 'get',
28037
+ comments[0].commentId,
28038
+ ]);
28039
+ if (['comment.created'].includes(event)) {
28040
+ if (comments[0].parentId) {
28041
+ const parentComment = pullFromCache([
28042
+ 'comment',
28043
+ 'get',
28044
+ comments[0].parentId,
28045
+ ]);
28046
+ if (parentComment === null || parentComment === void 0 ? void 0 : parentComment.data) {
28047
+ pushToCache(['comment', 'get', comments[0].parentId], Object.assign(Object.assign({}, parentComment.data), { childrenNumber: parentComment.data.childrenNumber + 1, children: [...new Set([...parentComment.data.children, comments[0].commentId])] }));
28048
+ }
28049
+ }
28050
+ const queries = (_a = queryCache(['comment', 'query'])) === null || _a === void 0 ? void 0 : _a.filter(({ key }) => { var _a; return ((_a = key[2]) === null || _a === void 0 ? void 0 : _a.referenceId) === comment.data.referenceId; });
28051
+ queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
28052
+ }
28053
+ callback(LinkedObject.comment(comment.data));
28006
28054
  }
28007
- callback(LinkedObject.comment(comment.data));
28008
28055
  }
28009
28056
  };
28010
28057
  return createEventSubscriber(client, event, event, filter);
@@ -34699,7 +34746,27 @@ const getPost = (postId, callback) => {
34699
34746
  return liveObject(postId, callback, 'postId', getPost$1, [
34700
34747
  onPostApproved,
34701
34748
  onPostDeclined,
34702
- onPostDeleted,
34749
+ (callback) => {
34750
+ return onPostDeleted((post) => {
34751
+ var _a;
34752
+ let targetPost = post;
34753
+ // check if the deleted post is a child of the target post
34754
+ if (post.parentPostId === postId && post.isDeleted) {
34755
+ const parentPost = (_a = pullFromCache([
34756
+ 'post',
34757
+ 'get',
34758
+ post.parentPostId,
34759
+ ])) === null || _a === void 0 ? void 0 : _a.data;
34760
+ if (parentPost) {
34761
+ parentPost.children = parentPost.children.filter(childId => childId !== post.postId);
34762
+ pushToCache(['post', 'get', parentPost.postId], parentPost);
34763
+ // if the deleted post is a child of the target post, then the target post is the parent post
34764
+ targetPost = parentPost;
34765
+ }
34766
+ }
34767
+ callback(targetPost);
34768
+ });
34769
+ },
34703
34770
  onPostFlagged,
34704
34771
  onPostReactionAdded,
34705
34772
  onPostReactionRemoved,
@@ -34837,11 +34904,16 @@ const getPosts = (params, callback, config) => {
34837
34904
  const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
34838
34905
  if (!collection)
34839
34906
  return;
34840
- if (post === null || post === void 0 ? void 0 : post.parentPostId) {
34841
- const parentPost = pullFromCache(['post', 'get', post.parentPostId]);
34842
- if (((_b = parentPost === null || parentPost === void 0 ? void 0 : parentPost.data) === null || _b === void 0 ? void 0 : _b.targetId) !== params.targetId) {
34907
+ if (post.parentPostId && post.isDeleted) {
34908
+ const parentPost = (_b = pullFromCache([
34909
+ 'post',
34910
+ 'get',
34911
+ post.parentPostId,
34912
+ ])) === null || _b === void 0 ? void 0 : _b.data;
34913
+ if (!parentPost || (parentPost === null || parentPost === void 0 ? void 0 : parentPost.targetId) !== params.targetId)
34843
34914
  return;
34844
- }
34915
+ parentPost.children = parentPost.children.filter(childId => childId !== post.postId);
34916
+ pushToCache(['post', 'get', parentPost.postId], parentPost);
34845
34917
  }
34846
34918
  else {
34847
34919
  if (params.targetId !== post.targetId)
@@ -35023,23 +35095,54 @@ const createComment = async (bundle) => {
35023
35095
  const client = getActiveClient();
35024
35096
  client.log('comment/createComment', bundle);
35025
35097
  const { data } = await client.http.post('/api/v3/comments', bundle);
35098
+ const { comments } = data;
35099
+ // BE always returns an array of comments If it got record 0 from BE it might have a problem on creation logic
35100
+ if (comments.length === 0)
35101
+ throw new Error('Comment not created');
35026
35102
  const cachedAt = client.cache && Date.now();
35027
35103
  if (client.cache)
35028
35104
  ingestInCache(data, { cachedAt });
35029
- const post = await getPost$1(bundle.referenceId);
35030
- fireEvent('post.updated', {
35031
- posts: [post.data],
35032
- categories: [],
35033
- comments: [],
35034
- communities: [],
35035
- communityUsers: [],
35036
- feeds: [],
35037
- files: [],
35038
- postChildren: [],
35039
- users: [],
35040
- });
35105
+ if (['post', 'content'].includes(bundle.referenceType)) {
35106
+ const post = await getPost$1(bundle.referenceId);
35107
+ fireEvent('post.updated', {
35108
+ posts: [post.data],
35109
+ categories: [],
35110
+ comments: [],
35111
+ communities: [],
35112
+ communityUsers: [],
35113
+ feeds: [],
35114
+ files: [],
35115
+ postChildren: [],
35116
+ users: [],
35117
+ });
35118
+ }
35119
+ else if (bundle.referenceType === 'story') {
35120
+ const storyIndex = pullFromCache([
35121
+ "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
35122
+ bundle.referenceId,
35123
+ ]);
35124
+ if (storyIndex === null || storyIndex === void 0 ? void 0 : storyIndex.data) {
35125
+ const cacheStory = pullFromCache([
35126
+ "story" /* STORY_KEY_CACHE.STORY */,
35127
+ 'get',
35128
+ storyIndex.data,
35129
+ ]);
35130
+ if (cacheStory === null || cacheStory === void 0 ? void 0 : cacheStory.data) {
35131
+ fireEvent('story.updated', {
35132
+ stories: [
35133
+ Object.assign(Object.assign({}, cacheStory.data), { commentsCount: cacheStory.data.commentsCount + 1, comments: [...new Set([...cacheStory.data.comments, comments[0].commentId])] }),
35134
+ ],
35135
+ categories: [],
35136
+ comments,
35137
+ communities: [],
35138
+ communityUsers: data.communityUsers,
35139
+ files: data.files,
35140
+ users: data.users,
35141
+ });
35142
+ }
35143
+ }
35144
+ }
35041
35145
  fireEvent('comment.created', data);
35042
- const { comments } = data;
35043
35146
  return {
35044
35147
  data: LinkedObject.comment(comments[0]),
35045
35148
  cachedAt,
@@ -35077,7 +35180,7 @@ const updateComment = async (commentId, patch) => {
35077
35180
  fireEvent('comment.updated', data);
35078
35181
  const { comments } = data;
35079
35182
  return {
35080
- data: LinkedObject.comment(comments.find(comment => comment.userId === commentId)),
35183
+ data: LinkedObject.comment(comments.find(comment => comment.commentId === commentId)),
35081
35184
  cachedAt,
35082
35185
  };
35083
35186
  };
@@ -35418,6 +35521,20 @@ const getComment = (commentId, callback) => {
35418
35521
  onCommentReactionRemoved,
35419
35522
  onCommentUnflagged,
35420
35523
  onCommentUpdated,
35524
+ (callback) => {
35525
+ return onCommentCreated((comment) => {
35526
+ if (comment.parentId !== commentId)
35527
+ return;
35528
+ const cacheParent = pullFromCache([
35529
+ 'comment',
35530
+ 'get',
35531
+ comment.parentId,
35532
+ ]);
35533
+ if (!(cacheParent === null || cacheParent === void 0 ? void 0 : cacheParent.data))
35534
+ return;
35535
+ callback(Object.assign(Object.assign({}, cacheParent.data), { childrenNumber: cacheParent.data.childrenNumber + 1, children: [...new Set([...cacheParent.data.children, comment.commentId])] }));
35536
+ });
35537
+ },
35421
35538
  ]);
35422
35539
  };
35423
35540
  /* end_public_function */
@@ -36792,7 +36909,7 @@ const convertStoryPayloadToRaw = (payload) => {
36792
36909
  const expiresAt = now.getTime() + YEAR;
36793
36910
  return {
36794
36911
  stories: [
36795
- Object.assign({ createdAt: now.toISOString(), updatedAt: now.toISOString(), flagCount: 0, hashFlag: null, reactions: {}, reactionsCount: 0, storyId: payload.referenceId, path: '', creatorId: client.userId || '', creatorPublicId: client.userId || '', targetPublicId: payload.targetId, commentsCount: 0, isDeleted: false, hasFlaggedComment: false, mentionedUsers: [], impression: 0, reach: 0, expiresAt: new Date(expiresAt).toISOString() }, payload),
36912
+ Object.assign({ createdAt: now.toISOString(), updatedAt: now.toISOString(), flagCount: 0, hashFlag: null, reactions: {}, reactionsCount: 0, storyId: payload.referenceId, path: '', creatorId: client.userId || '', creatorPublicId: client.userId || '', targetPublicId: payload.targetId, comments: [], commentsCount: 0, isDeleted: false, hasFlaggedComment: false, mentionedUsers: [], impression: 0, reach: 0, expiresAt: new Date(expiresAt).toISOString() }, payload),
36796
36913
  ],
36797
36914
  categories: [],
36798
36915
  communityUsers: [],
@@ -37018,6 +37135,15 @@ const softDeleteStory = async (storyId) => {
37018
37135
  return result;
37019
37136
  };
37020
37137
 
37138
+ const onStoryUpdated = (callback) => {
37139
+ const client = getActiveClient();
37140
+ const filter = async (payload) => {
37141
+ ingestInCache(payload);
37142
+ callback(payload.stories);
37143
+ };
37144
+ return createEventSubscriber(client, 'onStoryUpdated', 'story.updated', filter);
37145
+ };
37146
+
37021
37147
  const updateLocalLastStoryExpires = (stories) => {
37022
37148
  stories.forEach(story => {
37023
37149
  const currentCache = pullFromCache(["story-expire" /* STORY_KEY_CACHE.EXPIRE */, story.targetId]);
@@ -37214,7 +37340,7 @@ const getActiveStoriesByTarget = (params, callback) => {
37214
37340
  });
37215
37341
  };
37216
37342
  onFetch(true);
37217
- disposers.push(onStoryCreated(realtimeRouter()), onStoryDeleted(realtimeRouter()), onStoryError(realtimeRouter()), onStoryLocalDataUpdated(reloadData()), () => dropFromCache(cacheKey));
37343
+ disposers.push(onStoryCreated(realtimeRouter()), onStoryUpdated(realtimeRouter()), onStoryDeleted(realtimeRouter()), onStoryError(realtimeRouter()), onStoryLocalDataUpdated(reloadData()), () => dropFromCache(cacheKey));
37218
37344
  return () => {
37219
37345
  log(`getActiveStoriesByTarget(tmpid: ${timestamp}) > dispose`);
37220
37346
  disposers.forEach(fn => fn());
@@ -37286,7 +37412,7 @@ const getStoryByStoryId = (storyId, callback) => {
37286
37412
  }, 'storyId', getStoryByStoryId$1, [getSingleItemFromArray(onStoryDeleted), getSingleItemFromArray(onStoryError)]);
37287
37413
  };
37288
37414
 
37289
- const getTargetsByTargetIds = async (targets) => {
37415
+ const getTargetsByTargetIds$1 = async (targets) => {
37290
37416
  const client = getActiveClient();
37291
37417
  client.log('story/getTargetsByTargetIds', targets);
37292
37418
  const response = await client.http.get('/api/v4/stories/seen', {
@@ -37312,10 +37438,70 @@ const getTargetById = (params, callback) => {
37312
37438
  }
37313
37439
  callback(Object.assign(Object.assign({}, result), { data: LinkedObject.storyTarget(result.data[0]) }));
37314
37440
  }, 'query', param => {
37315
- return getTargetsByTargetIds([param]);
37441
+ return getTargetsByTargetIds$1([param]);
37316
37442
  }, []);
37317
37443
  };
37318
37444
 
37445
+ const getTargetsByTargetIds = (params, callback) => {
37446
+ const { log, cache } = getActiveClient();
37447
+ const disposers = [];
37448
+ const cacheKey = ['storyTargets', 'collection', params];
37449
+ const timestamp = Date.now();
37450
+ log(`getTargetsByTargetIds(tmpid: ${timestamp}) > listen`);
37451
+ if (!cache) {
37452
+ console.log(ENABLE_CACHE_MESSAGE);
37453
+ }
37454
+ const responder = (snapshot) => {
37455
+ var _a;
37456
+ const storyTargets = snapshot.data
37457
+ .map(targetId => {
37458
+ const storyTargetCache = pullFromCache([
37459
+ 'storyTarget',
37460
+ 'get',
37461
+ targetId,
37462
+ ]);
37463
+ if (!(storyTargetCache === null || storyTargetCache === void 0 ? void 0 : storyTargetCache.data))
37464
+ return undefined;
37465
+ return LinkedObject.storyTarget(storyTargetCache.data);
37466
+ })
37467
+ .filter(Boolean);
37468
+ callback({
37469
+ onNextPage: undefined,
37470
+ data: storyTargets,
37471
+ hasNextPage: !!((_a = snapshot.params) === null || _a === void 0 ? void 0 : _a.page),
37472
+ loading: snapshot.loading || false,
37473
+ });
37474
+ };
37475
+ const processNewData = (result, initial = false, loading = false, error = false) => {
37476
+ const cached = pullFromCache(cacheKey);
37477
+ const data = {
37478
+ loading,
37479
+ error,
37480
+ params: { page: undefined },
37481
+ data: [],
37482
+ };
37483
+ if (result) {
37484
+ data.data = initial
37485
+ ? result.map(getResolver('storyTarget'))
37486
+ : [...new Set([...((cached === null || cached === void 0 ? void 0 : cached.data) || []), ...result.map(getResolver('storyTarget'))])];
37487
+ }
37488
+ pushToCache(cacheKey, data.data);
37489
+ responder(data);
37490
+ };
37491
+ const onFetch = (initial) => {
37492
+ const query = createQuery(getTargetsByTargetIds$1, params);
37493
+ runQuery(query, ({ data: result, error, loading }) => {
37494
+ processNewData(result, initial, loading, error);
37495
+ });
37496
+ };
37497
+ onFetch(true);
37498
+ disposers.push(() => dropFromCache(cacheKey));
37499
+ return () => {
37500
+ log(`getTargetsByTargetIds(tmpid: ${timestamp}) > dispose`);
37501
+ disposers.forEach(fn => fn());
37502
+ };
37503
+ };
37504
+
37319
37505
  var index = /*#__PURE__*/Object.freeze({
37320
37506
  __proto__: null,
37321
37507
  createImageStory: createImageStory,
@@ -37324,7 +37510,8 @@ var index = /*#__PURE__*/Object.freeze({
37324
37510
  softDeleteStory: softDeleteStory,
37325
37511
  getActiveStoriesByTarget: getActiveStoriesByTarget,
37326
37512
  getStoryByStoryId: getStoryByStoryId,
37327
- getTargetById: getTargetById
37513
+ getTargetById: getTargetById,
37514
+ getTargetsByTargetIds: getTargetsByTargetIds
37328
37515
  });
37329
37516
 
37330
37517
  /**