@amityco/ts-sdk 7.0.3-7f3fd9b.0 → 7.1.1-1325f22d.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 (79) hide show
  1. package/dist/@types/core/events.d.ts +4 -0
  2. package/dist/@types/core/events.d.ts.map +1 -1
  3. package/dist/@types/core/model.d.ts +4 -0
  4. package/dist/@types/core/model.d.ts.map +1 -1
  5. package/dist/@types/core/payload.d.ts +18 -0
  6. package/dist/@types/core/payload.d.ts.map +1 -1
  7. package/dist/@types/domains/notification.d.ts +81 -0
  8. package/dist/@types/domains/notification.d.ts.map +1 -0
  9. package/dist/core/events.d.ts +3 -3
  10. package/dist/core/events.d.ts.map +1 -1
  11. package/dist/core/model/idResolvers.d.ts.map +1 -1
  12. package/dist/core/model/index.d.ts.map +1 -1
  13. package/dist/index.cjs.js +427 -46
  14. package/dist/index.d.ts +1 -0
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.esm.js +410 -30
  17. package/dist/index.umd.js +4 -4
  18. package/dist/notificationTray/api/index.d.ts +3 -0
  19. package/dist/notificationTray/api/index.d.ts.map +1 -0
  20. package/dist/notificationTray/api/markItemsSeen.d.ts +16 -0
  21. package/dist/notificationTray/api/markItemsSeen.d.ts.map +1 -0
  22. package/dist/notificationTray/api/markTraySeen.d.ts +19 -0
  23. package/dist/notificationTray/api/markTraySeen.d.ts.map +1 -0
  24. package/dist/notificationTray/events/index.d.ts +2 -0
  25. package/dist/notificationTray/events/index.d.ts.map +1 -0
  26. package/dist/notificationTray/events/onNotificationTraySeenUpdated.d.ts +17 -0
  27. package/dist/notificationTray/events/onNotificationTraySeenUpdated.d.ts.map +1 -0
  28. package/dist/notificationTray/index.d.ts +4 -0
  29. package/dist/notificationTray/index.d.ts.map +1 -0
  30. package/dist/notificationTray/internalApi/getNotificationTraySeen.d.ts +30 -0
  31. package/dist/notificationTray/internalApi/getNotificationTraySeen.d.ts.map +1 -0
  32. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.d.ts +13 -0
  33. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.d.ts.map +1 -0
  34. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.d.ts +9 -0
  35. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.d.ts.map +1 -0
  36. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.d.ts +9 -0
  37. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.d.ts.map +1 -0
  38. package/dist/notificationTray/observers/getNotificationTrayItems.d.ts +12 -0
  39. package/dist/notificationTray/observers/getNotificationTrayItems.d.ts.map +1 -0
  40. package/dist/notificationTray/observers/getNotificationTraySeen.d.ts +21 -0
  41. package/dist/notificationTray/observers/getNotificationTraySeen.d.ts.map +1 -0
  42. package/dist/notificationTray/observers/index.d.ts +3 -0
  43. package/dist/notificationTray/observers/index.d.ts.map +1 -0
  44. package/dist/notificationTray/utils/prepareNotificationTrayItemsPayload.d.ts +2 -0
  45. package/dist/notificationTray/utils/prepareNotificationTrayItemsPayload.d.ts.map +1 -0
  46. package/dist/reactionRepository/api/addReaction.d.ts.map +1 -1
  47. package/dist/reactionRepository/api/removeReaction.d.ts.map +1 -1
  48. package/dist/reactionRepository/observers/getReactions/ReactionPaginationController.d.ts.map +1 -1
  49. package/dist/utils/linkedObject/index.d.ts +1 -0
  50. package/dist/utils/linkedObject/index.d.ts.map +1 -1
  51. package/dist/utils/linkedObject/notificationTrayLinkedObject.d.ts +2 -0
  52. package/dist/utils/linkedObject/notificationTrayLinkedObject.d.ts.map +1 -0
  53. package/package.json +1 -1
  54. package/src/@types/core/events.ts +5 -0
  55. package/src/@types/core/model.ts +6 -0
  56. package/src/@types/core/payload.ts +25 -0
  57. package/src/@types/domains/notification.ts +90 -0
  58. package/src/core/model/idResolvers.ts +3 -0
  59. package/src/core/model/index.ts +2 -0
  60. package/src/index.ts +2 -0
  61. package/src/notificationTray/api/index.ts +2 -0
  62. package/src/notificationTray/api/markItemsSeen.ts +59 -0
  63. package/src/notificationTray/api/markTraySeen.ts +65 -0
  64. package/src/notificationTray/events/index.ts +1 -0
  65. package/src/notificationTray/events/onNotificationTraySeenUpdated.ts +36 -0
  66. package/src/notificationTray/index.ts +3 -0
  67. package/src/notificationTray/internalApi/getNotificationTraySeen.ts +81 -0
  68. package/src/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.ts +96 -0
  69. package/src/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.ts +31 -0
  70. package/src/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.ts +68 -0
  71. package/src/notificationTray/observers/getNotificationTrayItems.ts +44 -0
  72. package/src/notificationTray/observers/getNotificationTraySeen.ts +43 -0
  73. package/src/notificationTray/observers/index.ts +2 -0
  74. package/src/notificationTray/utils/prepareNotificationTrayItemsPayload.ts +12 -0
  75. package/src/reactionRepository/api/addReaction.ts +8 -0
  76. package/src/reactionRepository/api/removeReaction.ts +8 -0
  77. package/src/reactionRepository/observers/getReactions/ReactionPaginationController.ts +8 -0
  78. package/src/utils/linkedObject/index.ts +2 -0
  79. package/src/utils/linkedObject/notificationTrayLinkedObject.ts +28 -0
package/dist/index.cjs.js CHANGED
@@ -102,8 +102,8 @@ const PostContentType = Object.freeze({
102
102
 
103
103
  function getVersion() {
104
104
  try {
105
- // the string ''v7.0.2-cjs'' should be replaced by actual value by @rollup/plugin-replace
106
- return 'v7.0.2-cjs';
105
+ // the string ''v7.1.0-cjs'' should be replaced by actual value by @rollup/plugin-replace
106
+ return 'v7.1.0-cjs';
107
107
  }
108
108
  catch (error) {
109
109
  return '__dev__';
@@ -121,6 +121,7 @@ const SECOND$1 = 1000;
121
121
  const MINUTE = 60 * SECOND$1;
122
122
  const HOUR = 60 * MINUTE;
123
123
  const DAY = 24 * HOUR;
124
+ const WEEK = 7 * DAY;
124
125
  const YEAR = 365 * DAY;
125
126
  const ACCESS_TOKEN_WATCHER_INTERVAL = 10 * MINUTE;
126
127
 
@@ -542,6 +543,8 @@ const idResolvers = {
542
543
  advertiser: ({ advertiserId }) => advertiserId,
543
544
  pin: ({ placement, referenceId }) => `${placement}#${referenceId}`,
544
545
  pinTarget: ({ targetId }) => targetId,
546
+ notificationTrayItem: ({ _id }) => _id,
547
+ notificationTraySeen: ({ userId }) => userId,
545
548
  };
546
549
  /**
547
550
  * Retrieve the id resolver matching a domain name
@@ -593,6 +596,7 @@ const PAYLOAD2MODEL = {
593
596
  advertisers: 'advertiser',
594
597
  pinTargets: 'pinTarget',
595
598
  pins: 'pin',
599
+ notificationTrayItems: 'notificationTrayItem',
596
600
  };
597
601
  /** hidden */
598
602
  const isOutdated = (prevData, nextData) => {
@@ -5993,6 +5997,65 @@ const pinnedPostLinkedObject = (pinnedPost) => {
5993
5997
  } });
5994
5998
  };
5995
5999
 
6000
+ /* begin_public_function
6001
+ id: notificationTrayItem.markSeen
6002
+ */
6003
+ /**
6004
+ * ```js
6005
+ * import { notificationTray } from '@amityco/ts-sdk'
6006
+ * const updated = await notificationTray.markItemsSeen()
6007
+ * ```
6008
+ *
6009
+ * Updates an {@link Amity.NotificationItemSeen}
6010
+ *
6011
+ * @param trayItems[] that include id and lastTraySeenAt, The ID of the {@link Amity.NotificationItemSeen} to edit
6012
+ * @returns the updated {@link Amity.NotificationItemSeen} object
6013
+ *
6014
+ * @category NotificationItemSeen API
6015
+ * @async
6016
+ */
6017
+ const markItemsSeen = async (patch) => {
6018
+ const client = getActiveClient();
6019
+ client.log('notificationTray/markItemsSeen', {});
6020
+ const { data: payload } = await client.http.put(`api/v1/notification-tray/items/seen`, {
6021
+ patch,
6022
+ });
6023
+ const updatedData = patch.trayItems
6024
+ .map(patchItem => {
6025
+ var _a;
6026
+ const cacheData = (_a = pullFromCache([
6027
+ 'notificationTraySeen',
6028
+ 'get',
6029
+ patchItem.id,
6030
+ ])) === null || _a === void 0 ? void 0 : _a.data;
6031
+ if (!cacheData)
6032
+ return;
6033
+ const data = Object.assign(Object.assign({}, cacheData), payload);
6034
+ if (client.cache) {
6035
+ const cachedAt = Date.now();
6036
+ pushToCache(['notificationTrayItem', 'get'], data, { cachedAt });
6037
+ }
6038
+ return data;
6039
+ })
6040
+ .filter(Boolean);
6041
+ fireEvent('local.notificationTrayItem.updated', { notificationTrayItems: updatedData });
6042
+ };
6043
+ /* end_public_function */
6044
+
6045
+ const notificationTrayLinkedObject = (noti) => {
6046
+ return Object.assign(Object.assign({}, noti), { isSeen: noti.lastSeenAt > noti.lastOccuredAt, isRecent: new Date(noti.lastOccuredAt).getTime() >= Date.now() - WEEK, users: noti.actors
6047
+ .map(userId => { var _a; return (_a = pullFromCache(['user', 'get', userId])) === null || _a === void 0 ? void 0 : _a.data; })
6048
+ .filter(isNonNullable)
6049
+ .map(user => userLinkedObject(user)), markRead: () => markItemsSeen({
6050
+ trayItems: [
6051
+ {
6052
+ id: noti._id,
6053
+ lastSeenAt: noti.lastSeenAt,
6054
+ },
6055
+ ],
6056
+ }) });
6057
+ };
6058
+
5996
6059
  const LinkedObject = {
5997
6060
  ad: adLinkedObject,
5998
6061
  comment: commentLinkedObject,
@@ -6006,6 +6069,7 @@ const LinkedObject = {
6006
6069
  reactor: reactorLinkedObject,
6007
6070
  channel: channelLinkedObject,
6008
6071
  pinnedPost: pinnedPostLinkedObject,
6072
+ notificationTray: notificationTrayLinkedObject,
6009
6073
  };
6010
6074
 
6011
6075
  const getChannelMessagePreviewWithUser = (channel) => {
@@ -9776,7 +9840,7 @@ const getUserUnread = (callback) => {
9776
9840
  };
9777
9841
  };
9778
9842
 
9779
- var index$l = /*#__PURE__*/Object.freeze({
9843
+ var index$m = /*#__PURE__*/Object.freeze({
9780
9844
  __proto__: null,
9781
9845
  getActiveClient: getActiveClient,
9782
9846
  getActiveUser: getActiveUser,
@@ -10983,7 +11047,7 @@ const getMyFollowInfo = (callback) => {
10983
11047
  };
10984
11048
  /* end_public_function */
10985
11049
 
10986
- var index$k = /*#__PURE__*/Object.freeze({
11050
+ var index$l = /*#__PURE__*/Object.freeze({
10987
11051
  __proto__: null,
10988
11052
  blockUser: blockUser,
10989
11053
  unBlockUser: unBlockUser,
@@ -11998,9 +12062,9 @@ var AmityUserSearchMatchType;
11998
12062
  AmityUserSearchMatchType["PARTIAL"] = "partial";
11999
12063
  })(AmityUserSearchMatchType || (AmityUserSearchMatchType = {}));
12000
12064
 
12001
- var index$j = /*#__PURE__*/Object.freeze({
12065
+ var index$k = /*#__PURE__*/Object.freeze({
12002
12066
  __proto__: null,
12003
- Relationship: index$k,
12067
+ Relationship: index$l,
12004
12068
  getUserByIds: getUserByIds,
12005
12069
  updateUser: updateUser,
12006
12070
  flagUser: flagUser,
@@ -12264,7 +12328,7 @@ const uploadImage = async (formData, onProgress) => {
12264
12328
  };
12265
12329
  /* end_public_function */
12266
12330
 
12267
- var index$i = /*#__PURE__*/Object.freeze({
12331
+ var index$j = /*#__PURE__*/Object.freeze({
12268
12332
  __proto__: null,
12269
12333
  getFile: getFile,
12270
12334
  uploadFile: uploadFile,
@@ -12740,6 +12804,8 @@ const addReaction = async (referenceType, referenceId, reactionName) => {
12740
12804
  referenceType,
12741
12805
  reactionName,
12742
12806
  });
12807
+ if (!['post', 'comment', 'story', 'message'].includes(referenceType))
12808
+ throw new ASCApiError('The reference type is not valid. It should be one of post, comment, story, or message', 400000 /* Amity.ServerError.BAD_REQUEST */, "error" /* Amity.ErrorLevel.ERROR */);
12743
12809
  const { data } = await client.http.post('/api/v2/reactions', {
12744
12810
  referenceId,
12745
12811
  referenceType,
@@ -12859,6 +12925,8 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
12859
12925
  referenceType,
12860
12926
  reactionName,
12861
12927
  });
12928
+ if (!['post', 'comment', 'story', 'message'].includes(referenceType))
12929
+ throw new ASCApiError('The reference type is not valid. It should be one of post, comment, story, or message', 400000 /* Amity.ServerError.BAD_REQUEST */, "error" /* Amity.ErrorLevel.ERROR */);
12862
12930
  const { data } = await client.http.delete(`/api/v2/reactions`, {
12863
12931
  data: {
12864
12932
  referenceId,
@@ -13784,6 +13852,8 @@ class ReactionPaginationController extends PaginationController {
13784
13852
  const client = getActiveClient();
13785
13853
  client.log('reaction/queryReactions', queryParams);
13786
13854
  const path = '/api/v3/reactions';
13855
+ if (!['post', 'comment', 'story', 'message'].includes(params.referenceType))
13856
+ throw new ASCApiError('The reference type is not valid. It should be one of post, comment, story, or message', 400000 /* Amity.ServerError.BAD_REQUEST */, "error" /* Amity.ErrorLevel.ERROR */);
13787
13857
  const { data: queryResponse } = await this.http.get(path, {
13788
13858
  params: Object.assign(Object.assign({}, params), { referenceVersion: REFERENCE_API_V5, // Need to put this param to make it can query reaction for message in sub-channel
13789
13859
  options }),
@@ -14070,7 +14140,7 @@ const getReactions = (params, callback, config) => {
14070
14140
  };
14071
14141
  /* end_public_function */
14072
14142
 
14073
- var index$h = /*#__PURE__*/Object.freeze({
14143
+ var index$i = /*#__PURE__*/Object.freeze({
14074
14144
  __proto__: null,
14075
14145
  addReaction: addReaction,
14076
14146
  removeReaction: removeReaction,
@@ -15886,7 +15956,7 @@ const getMessages = (params, callback, config) => {
15886
15956
  };
15887
15957
  /* end_public_function */
15888
15958
 
15889
- var index$g = /*#__PURE__*/Object.freeze({
15959
+ var index$h = /*#__PURE__*/Object.freeze({
15890
15960
  __proto__: null,
15891
15961
  createMessage: createMessage,
15892
15962
  updateMessage: updateMessage,
@@ -16412,7 +16482,7 @@ const stopMessageReceiptSync = (subChannelId) => {
16412
16482
  };
16413
16483
  /* end_public_function */
16414
16484
 
16415
- var index$f = /*#__PURE__*/Object.freeze({
16485
+ var index$g = /*#__PURE__*/Object.freeze({
16416
16486
  __proto__: null,
16417
16487
  getSubChannelByIds: getSubChannels$1,
16418
16488
  createSubChannel: createSubChannel,
@@ -17589,7 +17659,7 @@ const searchMembers$1 = (params, callback, config) => {
17589
17659
  };
17590
17660
  /* end_public_function */
17591
17661
 
17592
- var index$e = /*#__PURE__*/Object.freeze({
17662
+ var index$f = /*#__PURE__*/Object.freeze({
17593
17663
  __proto__: null,
17594
17664
  addMembers: addMembers$1,
17595
17665
  removeMembers: removeMembers$1,
@@ -17792,7 +17862,7 @@ const unmuteMembers = async (channelId, userIds) => {
17792
17862
  };
17793
17863
  /* end_public_function */
17794
17864
 
17795
- var index$d = /*#__PURE__*/Object.freeze({
17865
+ var index$e = /*#__PURE__*/Object.freeze({
17796
17866
  __proto__: null,
17797
17867
  addRole: addRole,
17798
17868
  removeRole: removeRole,
@@ -17802,10 +17872,10 @@ var index$d = /*#__PURE__*/Object.freeze({
17802
17872
  unmuteMembers: unmuteMembers
17803
17873
  });
17804
17874
 
17805
- var index$c = /*#__PURE__*/Object.freeze({
17875
+ var index$d = /*#__PURE__*/Object.freeze({
17806
17876
  __proto__: null,
17807
- Membership: index$e,
17808
- Moderation: index$d,
17877
+ Membership: index$f,
17878
+ Moderation: index$e,
17809
17879
  getChannelByIds: getChannelByIds$1,
17810
17880
  createChannel: createChannel,
17811
17881
  updateChannel: updateChannel,
@@ -19184,7 +19254,7 @@ const searchMembers = (params, callback, config) => {
19184
19254
  };
19185
19255
  /* end_public_function */
19186
19256
 
19187
- var index$b = /*#__PURE__*/Object.freeze({
19257
+ var index$c = /*#__PURE__*/Object.freeze({
19188
19258
  __proto__: null,
19189
19259
  addMembers: addMembers,
19190
19260
  removeMembers: removeMembers,
@@ -20209,7 +20279,7 @@ const unbanMembers = async (communityId, userIds) => {
20209
20279
  };
20210
20280
  /* end_public_function */
20211
20281
 
20212
- var index$a = /*#__PURE__*/Object.freeze({
20282
+ var index$b = /*#__PURE__*/Object.freeze({
20213
20283
  __proto__: null,
20214
20284
  addRoles: addRoles,
20215
20285
  removeRoles: removeRoles,
@@ -20217,10 +20287,10 @@ var index$a = /*#__PURE__*/Object.freeze({
20217
20287
  unbanMembers: unbanMembers
20218
20288
  });
20219
20289
 
20220
- var index$9 = /*#__PURE__*/Object.freeze({
20290
+ var index$a = /*#__PURE__*/Object.freeze({
20221
20291
  __proto__: null,
20222
- Moderation: index$a,
20223
- Membership: index$b,
20292
+ Moderation: index$b,
20293
+ Membership: index$c,
20224
20294
  getCommunityByIds: getCommunities$1,
20225
20295
  createCommunity: createCommunity,
20226
20296
  updateCommunity: updateCommunity,
@@ -20453,7 +20523,7 @@ const getCategories = (params, callback, config) => {
20453
20523
  };
20454
20524
  /* end_public_function */
20455
20525
 
20456
- var index$8 = /*#__PURE__*/Object.freeze({
20526
+ var index$9 = /*#__PURE__*/Object.freeze({
20457
20527
  __proto__: null,
20458
20528
  getCategory: getCategory,
20459
20529
  getCategories: getCategories
@@ -20621,7 +20691,7 @@ getCustomRankingGlobalFeed.locally = (query) => {
20621
20691
  : undefined;
20622
20692
  };
20623
20693
 
20624
- var index$7 = /*#__PURE__*/Object.freeze({
20694
+ var index$8 = /*#__PURE__*/Object.freeze({
20625
20695
  __proto__: null,
20626
20696
  queryGlobalFeed: queryGlobalFeed,
20627
20697
  getCustomRankingGlobalFeed: getCustomRankingGlobalFeed
@@ -21936,7 +22006,7 @@ const getComments = (params, callback, config) => {
21936
22006
  };
21937
22007
  /* end_public_function */
21938
22008
 
21939
- var index$6 = /*#__PURE__*/Object.freeze({
22009
+ var index$7 = /*#__PURE__*/Object.freeze({
21940
22010
  __proto__: null,
21941
22011
  getCommentByIds: getCommentByIds,
21942
22012
  createComment: createComment,
@@ -22943,7 +23013,7 @@ const semanticSearchPosts = (params, callback, config) => {
22943
23013
  };
22944
23014
  };
22945
23015
 
22946
- var index$5 = /*#__PURE__*/Object.freeze({
23016
+ var index$6 = /*#__PURE__*/Object.freeze({
22947
23017
  __proto__: null,
22948
23018
  getPostByIds: getPostByIds,
22949
23019
  createPost: createPost,
@@ -23477,7 +23547,7 @@ const getStreams = (params, callback, config) => {
23477
23547
  };
23478
23548
  };
23479
23549
 
23480
- var index$4 = /*#__PURE__*/Object.freeze({
23550
+ var index$5 = /*#__PURE__*/Object.freeze({
23481
23551
  __proto__: null,
23482
23552
  createStream: createStream,
23483
23553
  updateStream: updateStream,
@@ -23764,7 +23834,7 @@ const getPoll = (pollId, callback) => {
23764
23834
  };
23765
23835
  /* end_public_function */
23766
23836
 
23767
- var index$3 = /*#__PURE__*/Object.freeze({
23837
+ var index$4 = /*#__PURE__*/Object.freeze({
23768
23838
  __proto__: null,
23769
23839
  createPoll: createPoll,
23770
23840
  closePoll: closePoll,
@@ -24135,7 +24205,7 @@ const getPlayer = async (parameters) => {
24135
24205
  return video;
24136
24206
  };
24137
24207
 
24138
- var index$2 = /*#__PURE__*/Object.freeze({
24208
+ var index$3 = /*#__PURE__*/Object.freeze({
24139
24209
  __proto__: null,
24140
24210
  getPlayer: getPlayer
24141
24211
  });
@@ -25308,7 +25378,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
25308
25378
  };
25309
25379
  };
25310
25380
 
25311
- var index$1 = /*#__PURE__*/Object.freeze({
25381
+ var index$2 = /*#__PURE__*/Object.freeze({
25312
25382
  __proto__: null,
25313
25383
  createImageStory: createImageStory,
25314
25384
  createVideoStory: createVideoStory,
@@ -25345,7 +25415,7 @@ const getNetworkAds = async () => {
25345
25415
  };
25346
25416
  };
25347
25417
 
25348
- var index = /*#__PURE__*/Object.freeze({
25418
+ var index$1 = /*#__PURE__*/Object.freeze({
25349
25419
  __proto__: null,
25350
25420
  getNetworkAds: getNetworkAds
25351
25421
  });
@@ -25372,31 +25442,341 @@ const createUserToken = async (apiKey, apiRegion, params) => {
25372
25442
  return { accessToken: data.accessToken };
25373
25443
  };
25374
25444
 
25445
+ /* begin_public_function
25446
+ id: notificationTray.getNotificationTraySeen
25447
+ */
25448
+ /**
25449
+ * ```js
25450
+ * import { notificationTray } from '@amityco/ts-sdk'
25451
+ * const notificationTraySeen = await notificationTray.getNotificationTraySeen()
25452
+ * ```
25453
+ *
25454
+ *
25455
+ * @returns A page of {@link Amity.NotificationTraySeen} objects
25456
+ *
25457
+ * @category NotificationTray API
25458
+ * @async
25459
+ * */
25460
+ const getNotificationTraySeen$1 = async () => {
25461
+ const client = getActiveClient();
25462
+ client.log('notificationTray/getNotificationTraySeen', {});
25463
+ const { data: payload } = await client.http.get(`api/v1/notification-tray/tray/seen`);
25464
+ const cachedAt = client.cache && Date.now();
25465
+ if (client.cache) {
25466
+ const cacheKey = ['notificationTraySeen', 'get', client.userId];
25467
+ pushToCache(cacheKey, {
25468
+ userId: client.userId,
25469
+ lastTraySeenAt: payload.lastTraySeenAt,
25470
+ lastTrayOccuredAt: payload.lastTrayOccuredAt,
25471
+ });
25472
+ }
25473
+ return {
25474
+ data: {
25475
+ userId: client.userId,
25476
+ lastTraySeenAt: payload.lastTraySeenAt,
25477
+ lastTrayOccuredAt: payload.lastTrayOccuredAt,
25478
+ isSeen: payload.lastTraySeenAt > payload.lastTrayOccuredAt,
25479
+ },
25480
+ cachedAt,
25481
+ };
25482
+ };
25483
+ /* end_public_function */
25484
+ /**
25485
+ * ```js
25486
+ * import { notificationTray } from '@amityco/ts-sdk'
25487
+ * const notificationTraySeen = await notificationTray.getNotificationTraySeen.locally()
25488
+ * ```
25489
+ *
25490
+ * Queries a paginable list of {@link Amity.NotificationTraySeen} objects from cache
25491
+ *
25492
+ * @returns A page of {@link Amity.NotificationTraySeen} objects
25493
+ *
25494
+ * @category NotificationTray API
25495
+ * @async
25496
+ * */
25497
+ getNotificationTraySeen$1.locally = () => {
25498
+ var _a;
25499
+ const client = getActiveClient();
25500
+ client.log('notificationTray/getNotificationTraySeen.locally', {});
25501
+ if (!client.cache)
25502
+ return;
25503
+ const queryKey = ['notificationTraySeen', 'get'];
25504
+ const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
25505
+ if (!(data === null || data === void 0 ? void 0 : data.notificationTraySeen))
25506
+ return;
25507
+ return { data: data.notificationTraySeen, cachedAt };
25508
+ };
25509
+
25510
+ /**
25511
+ * ```js
25512
+ * import { onNotificationTraySeenUpdated } from '@amityco/ts-sdk'
25513
+ * const dispose = onNotificationTraySeenUpdated(data => {
25514
+ * // ...
25515
+ * })
25516
+ * ```
25517
+ *
25518
+ * Fired when an {@link Amity.NotificationTraySeen} has been updated
25519
+ *
25520
+ * @param callback The function to call when the event was fired
25521
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
25522
+ *
25523
+ * @category NotificationTraySeen Events
25524
+ */
25525
+ const onNotificationTraySeenUpdated = (callback) => {
25526
+ const client = getActiveClient();
25527
+ const disposers = [
25528
+ createEventSubscriber(client, 'onNotificationTraySeenUpdated', 'local.notificationTraySeen.updated', payload => callback(payload)),
25529
+ ];
25530
+ return () => {
25531
+ disposers.forEach(fn => fn());
25532
+ };
25533
+ };
25534
+
25535
+ /* begin_public_function
25536
+ id: notificationTraySeen.get
25537
+ */
25538
+ /**
25539
+ * ```js
25540
+ * import { getNotificationTraySeen } from '@amityco/ts-sdk';
25541
+ *
25542
+ * let notificationTraySeen;
25543
+ *
25544
+ * const unsubscribe = getNotificationTraySeen(userId, response => {
25545
+ * notificationTraySeen = response.data;
25546
+ * });
25547
+ * ```
25548
+ *
25549
+ * Observe all mutation on a given {@link Amity.NotificationTraySeen}
25550
+ *
25551
+ * @param userId the ID of the user to observe
25552
+ * @param callback the function to call when new data are available
25553
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the message
25554
+ *
25555
+ * @category NotificationTraySeen Live Object
25556
+ */
25557
+ const getNotificationTraySeen = (callback) => {
25558
+ const responder = (snapshot) => {
25559
+ const { data } = snapshot;
25560
+ callback(Object.assign(Object.assign({}, snapshot), { data }));
25561
+ };
25562
+ const { userId } = getActiveUser();
25563
+ return liveObject(userId, responder, 'userId', getNotificationTraySeen$1, [
25564
+ onNotificationTraySeenUpdated,
25565
+ ]);
25566
+ };
25567
+ /* end_public_function */
25568
+
25569
+ /**
25570
+ * TODO: handle cache receive cache option, and cache policy
25571
+ * TODO: check if querybyIds is supported
25572
+ */
25573
+ class NotificationTrayItemsPaginationController extends PaginationController {
25574
+ async getRequest(queryParams, token) {
25575
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
25576
+ const options = token ? { token } : { limit };
25577
+ const { data: queryResponse } = await this.http.get(`/api/v1/notification-tray`, {
25578
+ params: Object.assign(Object.assign({}, params), { options }),
25579
+ });
25580
+ return queryResponse;
25581
+ }
25582
+ }
25583
+
25584
+ class NotificationTrayItemsQuerystreamController extends QueryStreamController {
25585
+ constructor(query, cacheKey, notifyChange, preparePayload) {
25586
+ super(query, cacheKey);
25587
+ this.notifyChange = notifyChange;
25588
+ this.preparePayload = preparePayload;
25589
+ }
25590
+ async saveToMainDB(response) {
25591
+ const processedPayload = await this.preparePayload(response);
25592
+ const client = getActiveClient();
25593
+ const cachedAt = client.cache && Date.now();
25594
+ if (client.cache) {
25595
+ ingestInCache(processedPayload, { cachedAt });
25596
+ }
25597
+ }
25598
+ appendToQueryStream(response, direction, refresh = false) {
25599
+ var _a, _b;
25600
+ if (refresh) {
25601
+ pushToCache(this.cacheKey, {
25602
+ data: response.notificationTrayItems.map(getResolver('notificationTrayItem')),
25603
+ });
25604
+ }
25605
+ else {
25606
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
25607
+ const notifications = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
25608
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
25609
+ ...new Set([
25610
+ ...notifications,
25611
+ ...response.notificationTrayItems.map(getResolver('notificationTrayItem')),
25612
+ ]),
25613
+ ] }));
25614
+ }
25615
+ }
25616
+ }
25617
+
25618
+ const prepareNotificationTrayItemsPayload = (rawPayload) => {
25619
+ const users = rawPayload.users.map(convertRawUserToInternalUser);
25620
+ return Object.assign(Object.assign({}, rawPayload), { users });
25621
+ };
25622
+
25623
+ class NotificationTrayItemsLiveCollectionController extends LiveCollectionController {
25624
+ constructor(query, callback) {
25625
+ const queryStreamId = hash__default["default"](query);
25626
+ const cacheKey = ['notificationTrayItem', 'collection', queryStreamId];
25627
+ const paginationController = new NotificationTrayItemsPaginationController(query);
25628
+ super(paginationController, queryStreamId, cacheKey, callback);
25629
+ this.query = query;
25630
+ this.queryStreamController = new NotificationTrayItemsQuerystreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareNotificationTrayItemsPayload);
25631
+ this.callback = callback.bind(this);
25632
+ this.loadPage({ initial: true });
25633
+ }
25634
+ setup() {
25635
+ var _a;
25636
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
25637
+ if (!collection) {
25638
+ pushToCache(this.cacheKey, {
25639
+ data: [],
25640
+ params: {},
25641
+ });
25642
+ }
25643
+ }
25644
+ async persistModel(queryPayload) {
25645
+ await this.queryStreamController.saveToMainDB(queryPayload);
25646
+ }
25647
+ persistQueryStream({ response, direction, refresh, }) {
25648
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
25649
+ }
25650
+ // eslint-disable-next-line class-methods-use-this
25651
+ startSubscription() {
25652
+ return [];
25653
+ }
25654
+ notifyChange({ origin, loading, error }) {
25655
+ var _a, _b;
25656
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
25657
+ if (!collection)
25658
+ return;
25659
+ const data = ((_b = collection.data
25660
+ .map(id => pullFromCache(['notificationTrayItem', 'get', id]))
25661
+ .filter(isNonNullable)
25662
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.notificationTray);
25663
+ if (!this.shouldNotify(data) && origin === 'event')
25664
+ return;
25665
+ this.callback({
25666
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
25667
+ data,
25668
+ hasNextPage: !!this.paginationController.getNextToken(),
25669
+ loading,
25670
+ error,
25671
+ });
25672
+ }
25673
+ }
25674
+
25675
+ /**
25676
+ * Get notification tray items for a notification tray page
25677
+ *
25678
+ * @param params the limit query parameters
25679
+ * @param callback the callback to be called when the notification tray items are updated
25680
+ * @returns items in the notification tray
25681
+ *
25682
+ * @category Notification tray items Live Collection
25683
+ *
25684
+ */
25685
+ const getNotificationTrayItems = (params, callback, config) => {
25686
+ const { log, cache } = getActiveClient();
25687
+ if (!cache) {
25688
+ console.log(ENABLE_CACHE_MESSAGE);
25689
+ }
25690
+ const timestamp = Date.now();
25691
+ log(`getNotificationTrayItems(tmpid: ${timestamp}) > listen`);
25692
+ const notiTrayItemsLiveCollection = new NotificationTrayItemsLiveCollectionController(params, callback);
25693
+ const disposers = notiTrayItemsLiveCollection.startSubscription();
25694
+ const cacheKey = notiTrayItemsLiveCollection.getCacheKey();
25695
+ disposers.push(() => dropFromCache(cacheKey));
25696
+ return () => {
25697
+ log(`getNotificationTrayItems(tmpid: ${timestamp}) > dispose`);
25698
+ disposers.forEach(fn => fn());
25699
+ };
25700
+ };
25701
+
25702
+ /* begin_public_function
25703
+ id: notificationTray.markSeen
25704
+ */
25705
+ /**
25706
+ * ```js
25707
+ * import { notificationTray } from '@amityco/ts-sdk'
25708
+ * const updated = await notificationTray.markTraySeen({
25709
+ * lastSeenAt: Amity.timestamp,
25710
+ * })
25711
+ * ```
25712
+ *
25713
+ * Updates an {@link Amity.NotificationTraySeen}
25714
+ *
25715
+ * @param userId The ID of the {@link Amity.NotificationTraySeen} to edit
25716
+ * @param lastSeenAt The patch data to apply
25717
+ * @returns the updated {@link Amity.NotificationTraySeen} object
25718
+ *
25719
+ * @category Post API
25720
+ * @async
25721
+ */
25722
+ const markTraySeen = async (lastSeenAt) => {
25723
+ var _a;
25724
+ const client = getActiveClient();
25725
+ client.log('notificationTray/markTraySeen', {});
25726
+ const { data: payload } = await client.http.put(`api/v1/notification-tray/tray/seen`, {
25727
+ lastSeenAt,
25728
+ });
25729
+ const cacheData = (_a = pullFromCache([
25730
+ 'notificationTraySeen',
25731
+ 'get',
25732
+ ])) === null || _a === void 0 ? void 0 : _a.data;
25733
+ const data = Object.assign({ userId: client.userId }, payload);
25734
+ const updateCacheData = Object.assign(Object.assign({}, cacheData), data);
25735
+ const cachedAt = client.cache && Date.now();
25736
+ if (client.cache)
25737
+ pushToCache(['notificationTraySeen', 'get', client.userId], updateCacheData, { cachedAt });
25738
+ fireEvent('local.notificationTraySeen.updated', data);
25739
+ return {
25740
+ data: payload,
25741
+ cachedAt,
25742
+ };
25743
+ };
25744
+ /* end_public_function */
25745
+
25746
+ var index = /*#__PURE__*/Object.freeze({
25747
+ __proto__: null,
25748
+ getNotificationTraySeen: getNotificationTraySeen,
25749
+ getNotificationTrayItems: getNotificationTrayItems,
25750
+ markItemsSeen: markItemsSeen,
25751
+ markTraySeen: markTraySeen,
25752
+ onNotificationTraySeenUpdated: onNotificationTraySeenUpdated
25753
+ });
25754
+
25375
25755
  exports.API_REGIONS = API_REGIONS;
25376
- exports.AdRepository = index;
25377
- exports.CategoryRepository = index$8;
25378
- exports.ChannelRepository = index$c;
25379
- exports.Client = index$l;
25380
- exports.CommentRepository = index$6;
25756
+ exports.AdRepository = index$1;
25757
+ exports.CategoryRepository = index$9;
25758
+ exports.ChannelRepository = index$d;
25759
+ exports.Client = index$m;
25760
+ exports.CommentRepository = index$7;
25381
25761
  exports.CommunityPostSettingMaps = CommunityPostSettingMaps;
25382
25762
  exports.CommunityPostSettings = CommunityPostSettings;
25383
- exports.CommunityRepository = index$9;
25763
+ exports.CommunityRepository = index$a;
25384
25764
  exports.ContentFeedType = ContentFeedType;
25385
25765
  exports.DefaultCommunityPostSetting = DefaultCommunityPostSetting;
25386
- exports.FeedRepository = index$7;
25387
- exports.FileRepository = index$i;
25766
+ exports.FeedRepository = index$8;
25767
+ exports.FileRepository = index$j;
25388
25768
  exports.FileType = FileType;
25389
- exports.LiveStreamPlayer = index$2;
25769
+ exports.LiveStreamPlayer = index$3;
25390
25770
  exports.MessageContentType = MessageContentType;
25391
- exports.MessageRepository = index$g;
25392
- exports.PollRepository = index$3;
25771
+ exports.MessageRepository = index$h;
25772
+ exports.PollRepository = index$4;
25393
25773
  exports.PostContentType = PostContentType;
25394
- exports.PostRepository = index$5;
25395
- exports.ReactionRepository = index$h;
25396
- exports.StoryRepository = index$1;
25397
- exports.StreamRepository = index$4;
25398
- exports.SubChannelRepository = index$f;
25399
- exports.UserRepository = index$j;
25774
+ exports.PostRepository = index$6;
25775
+ exports.ReactionRepository = index$i;
25776
+ exports.StoryRepository = index$2;
25777
+ exports.StreamRepository = index$5;
25778
+ exports.SubChannelRepository = index$g;
25779
+ exports.UserRepository = index$k;
25400
25780
  exports.VERSION = VERSION;
25401
25781
  exports.VideoResolution = VideoResolution;
25402
25782
  exports.VideoSize = VideoSize;
@@ -25449,6 +25829,7 @@ exports.isPaged = isPaged;
25449
25829
  exports.isReportedByMe = isReportedByMe;
25450
25830
  exports.isSkip = isSkip;
25451
25831
  exports.mergeInCache = mergeInCache;
25832
+ exports.notificationTray = index;
25452
25833
  exports.onChannelMarkerFetched = onChannelMarkerFetched;
25453
25834
  exports.onFeedMarkerFetched = onFeedMarkerFetched;
25454
25835
  exports.onFeedMarkerUpdated = onFeedMarkerUpdated;