@amityco/ts-sdk 7.2.1-56aa34e.0 → 7.2.1-88f63a0b.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 (86) hide show
  1. package/.eslintrc.json +2 -1
  2. package/dist/@types/core/events.d.ts +4 -0
  3. package/dist/@types/core/events.d.ts.map +1 -1
  4. package/dist/@types/core/model.d.ts +4 -0
  5. package/dist/@types/core/model.d.ts.map +1 -1
  6. package/dist/@types/core/payload.d.ts +24 -0
  7. package/dist/@types/core/payload.d.ts.map +1 -1
  8. package/dist/@types/domains/ad.d.ts +1 -1
  9. package/dist/@types/domains/ad.d.ts.map +1 -1
  10. package/dist/@types/domains/content.d.ts +12 -0
  11. package/dist/@types/domains/content.d.ts.map +1 -1
  12. package/dist/@types/domains/notification.d.ts +78 -0
  13. package/dist/@types/domains/notification.d.ts.map +1 -0
  14. package/dist/@types/index.d.ts +1 -0
  15. package/dist/@types/index.d.ts.map +1 -1
  16. package/dist/core/events.d.ts +3 -3
  17. package/dist/core/events.d.ts.map +1 -1
  18. package/dist/core/model/idResolvers.d.ts.map +1 -1
  19. package/dist/core/model/index.d.ts.map +1 -1
  20. package/dist/index.cjs.js +454 -47
  21. package/dist/index.d.ts +1 -0
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.esm.js +437 -31
  24. package/dist/index.umd.js +4 -4
  25. package/dist/messageRepository/api/flagMessage.d.ts +2 -1
  26. package/dist/messageRepository/api/flagMessage.d.ts.map +1 -1
  27. package/dist/notificationTray/api/index.d.ts +3 -0
  28. package/dist/notificationTray/api/index.d.ts.map +1 -0
  29. package/dist/notificationTray/api/markItemsSeen.d.ts +16 -0
  30. package/dist/notificationTray/api/markItemsSeen.d.ts.map +1 -0
  31. package/dist/notificationTray/api/markTraySeen.d.ts +19 -0
  32. package/dist/notificationTray/api/markTraySeen.d.ts.map +1 -0
  33. package/dist/notificationTray/events/index.d.ts +2 -0
  34. package/dist/notificationTray/events/index.d.ts.map +1 -0
  35. package/dist/notificationTray/events/onNotificationTraySeenUpdated.d.ts +17 -0
  36. package/dist/notificationTray/events/onNotificationTraySeenUpdated.d.ts.map +1 -0
  37. package/dist/notificationTray/index.d.ts +4 -0
  38. package/dist/notificationTray/index.d.ts.map +1 -0
  39. package/dist/notificationTray/internalApi/getNotificationTraySeen.d.ts +30 -0
  40. package/dist/notificationTray/internalApi/getNotificationTraySeen.d.ts.map +1 -0
  41. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.d.ts +13 -0
  42. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.d.ts.map +1 -0
  43. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.d.ts +9 -0
  44. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.d.ts.map +1 -0
  45. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.d.ts +9 -0
  46. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.d.ts.map +1 -0
  47. package/dist/notificationTray/observers/getNotificationTrayItems.d.ts +12 -0
  48. package/dist/notificationTray/observers/getNotificationTrayItems.d.ts.map +1 -0
  49. package/dist/notificationTray/observers/getNotificationTraySeen.d.ts +20 -0
  50. package/dist/notificationTray/observers/getNotificationTraySeen.d.ts.map +1 -0
  51. package/dist/notificationTray/observers/index.d.ts +3 -0
  52. package/dist/notificationTray/observers/index.d.ts.map +1 -0
  53. package/dist/notificationTray/utils/prepareNotificationTrayItemsPayload.d.ts +2 -0
  54. package/dist/notificationTray/utils/prepareNotificationTrayItemsPayload.d.ts.map +1 -0
  55. package/dist/utils/linkedObject/index.d.ts +1 -0
  56. package/dist/utils/linkedObject/index.d.ts.map +1 -1
  57. package/dist/utils/linkedObject/notificationTrayLinkedObject.d.ts +2 -0
  58. package/dist/utils/linkedObject/notificationTrayLinkedObject.d.ts.map +1 -0
  59. package/package.json +1 -1
  60. package/src/@types/core/events.ts +5 -0
  61. package/src/@types/core/model.ts +6 -0
  62. package/src/@types/core/payload.ts +29 -0
  63. package/src/@types/domains/ad.ts +1 -1
  64. package/src/@types/domains/content.ts +16 -0
  65. package/src/@types/domains/notification.ts +94 -0
  66. package/src/@types/index.ts +1 -0
  67. package/src/core/model/idResolvers.ts +3 -0
  68. package/src/core/model/index.ts +2 -0
  69. package/src/index.ts +2 -0
  70. package/src/messageRepository/api/flagMessage.ts +18 -5
  71. package/src/notificationTray/api/index.ts +2 -0
  72. package/src/notificationTray/api/markItemsSeen.ts +62 -0
  73. package/src/notificationTray/api/markTraySeen.ts +65 -0
  74. package/src/notificationTray/events/index.ts +1 -0
  75. package/src/notificationTray/events/onNotificationTraySeenUpdated.ts +36 -0
  76. package/src/notificationTray/index.ts +3 -0
  77. package/src/notificationTray/internalApi/getNotificationTraySeen.ts +80 -0
  78. package/src/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.ts +96 -0
  79. package/src/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.ts +31 -0
  80. package/src/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.ts +68 -0
  81. package/src/notificationTray/observers/getNotificationTrayItems.ts +44 -0
  82. package/src/notificationTray/observers/getNotificationTraySeen.ts +60 -0
  83. package/src/notificationTray/observers/index.ts +2 -0
  84. package/src/notificationTray/utils/prepareNotificationTrayItemsPayload.ts +12 -0
  85. package/src/utils/linkedObject/index.ts +2 -0
  86. package/src/utils/linkedObject/notificationTrayLinkedObject.ts +19 -0
package/dist/index.cjs.js CHANGED
@@ -80,7 +80,19 @@ const ContentFeedType = Object.freeze({
80
80
  CHAT: 'chat',
81
81
  POST: 'post',
82
82
  MESSAGE: 'message',
83
- });
83
+ });
84
+ exports.ContentFlagReasonEnum = void 0;
85
+ (function (ContentFlagReasonEnum) {
86
+ ContentFlagReasonEnum["CommunityGuidelines"] = "Against community guidelines";
87
+ ContentFlagReasonEnum["HarassmentOrBullying"] = "Harassment or bullying";
88
+ ContentFlagReasonEnum["SelfHarmOrSuicide"] = "Self-harm or suicide";
89
+ ContentFlagReasonEnum["ViolenceOrThreateningContent"] = "Violence or threatening content";
90
+ ContentFlagReasonEnum["SellingRestrictedItems"] = "Selling and promoting restricted items";
91
+ ContentFlagReasonEnum["SexualContentOrNudity"] = "Sexual message or nudity";
92
+ ContentFlagReasonEnum["SpamOrScams"] = "Spam or scams";
93
+ ContentFlagReasonEnum["FalseInformation"] = "False information or misinformation";
94
+ ContentFlagReasonEnum["Others"] = "Others";
95
+ })(exports.ContentFlagReasonEnum || (exports.ContentFlagReasonEnum = {}));
84
96
 
85
97
  const MessageContentType = Object.freeze({
86
98
  TEXT: 'text',
@@ -121,6 +133,7 @@ const SECOND$1 = 1000;
121
133
  const MINUTE = 60 * SECOND$1;
122
134
  const HOUR = 60 * MINUTE;
123
135
  const DAY = 24 * HOUR;
136
+ const WEEK = 7 * DAY;
124
137
  const YEAR = 365 * DAY;
125
138
  const ACCESS_TOKEN_WATCHER_INTERVAL = 10 * MINUTE;
126
139
 
@@ -543,6 +556,8 @@ const idResolvers = {
543
556
  advertiser: ({ advertiserId }) => advertiserId,
544
557
  pin: ({ placement, referenceId }) => `${placement}#${referenceId}`,
545
558
  pinTarget: ({ targetId }) => targetId,
559
+ notificationTrayItem: ({ _id }) => _id,
560
+ notificationTraySeen: ({ userId }) => userId,
546
561
  };
547
562
  /**
548
563
  * Retrieve the id resolver matching a domain name
@@ -594,6 +609,7 @@ const PAYLOAD2MODEL = {
594
609
  advertisers: 'advertiser',
595
610
  pinTargets: 'pinTarget',
596
611
  pins: 'pin',
612
+ notificationTrayItems: 'notificationTrayItem',
597
613
  };
598
614
  /** hidden */
599
615
  const isOutdated = (prevData, nextData) => {
@@ -6221,6 +6237,14 @@ const pinnedPostLinkedObject = (pinnedPost) => {
6221
6237
  } });
6222
6238
  };
6223
6239
 
6240
+ const notificationTrayLinkedObject = (noti) => {
6241
+ return Object.assign(Object.assign({}, noti), { isSeen: noti.lastSeenAt > noti.lastOccurredAt, isRecent: new Date(noti.lastOccurredAt).getTime() >= Date.now() - WEEK, users: noti.actors
6242
+ .map(({ _id }) => pullFromCache(['user', 'get', _id]))
6243
+ .filter(isNonNullable)
6244
+ .map(({ data }) => data)
6245
+ .map(user => userLinkedObject(user)) });
6246
+ };
6247
+
6224
6248
  const LinkedObject = {
6225
6249
  ad: adLinkedObject,
6226
6250
  comment: commentLinkedObject,
@@ -6234,6 +6258,7 @@ const LinkedObject = {
6234
6258
  reactor: reactorLinkedObject,
6235
6259
  channel: channelLinkedObject,
6236
6260
  pinnedPost: pinnedPostLinkedObject,
6261
+ notificationTray: notificationTrayLinkedObject,
6237
6262
  };
6238
6263
 
6239
6264
  const getChannelMessagePreviewWithUser = (channel) => {
@@ -10135,7 +10160,7 @@ const getUserUnread = (callback) => {
10135
10160
  };
10136
10161
  };
10137
10162
 
10138
- var index$l = /*#__PURE__*/Object.freeze({
10163
+ var index$m = /*#__PURE__*/Object.freeze({
10139
10164
  __proto__: null,
10140
10165
  getActiveClient: getActiveClient,
10141
10166
  getActiveUser: getActiveUser,
@@ -11342,7 +11367,7 @@ const getMyFollowInfo = (callback) => {
11342
11367
  };
11343
11368
  /* end_public_function */
11344
11369
 
11345
- var index$k = /*#__PURE__*/Object.freeze({
11370
+ var index$l = /*#__PURE__*/Object.freeze({
11346
11371
  __proto__: null,
11347
11372
  blockUser: blockUser,
11348
11373
  unBlockUser: unBlockUser,
@@ -12357,9 +12382,9 @@ var AmityUserSearchMatchType;
12357
12382
  AmityUserSearchMatchType["PARTIAL"] = "partial";
12358
12383
  })(AmityUserSearchMatchType || (AmityUserSearchMatchType = {}));
12359
12384
 
12360
- var index$j = /*#__PURE__*/Object.freeze({
12385
+ var index$k = /*#__PURE__*/Object.freeze({
12361
12386
  __proto__: null,
12362
- Relationship: index$k,
12387
+ Relationship: index$l,
12363
12388
  getUserByIds: getUserByIds,
12364
12389
  updateUser: updateUser,
12365
12390
  flagUser: flagUser,
@@ -12623,7 +12648,7 @@ const uploadImage = async (formData, onProgress) => {
12623
12648
  };
12624
12649
  /* end_public_function */
12625
12650
 
12626
- var index$i = /*#__PURE__*/Object.freeze({
12651
+ var index$j = /*#__PURE__*/Object.freeze({
12627
12652
  __proto__: null,
12628
12653
  getFile: getFile,
12629
12654
  uploadFile: uploadFile,
@@ -14490,7 +14515,7 @@ const getReactions = (params, callback, config) => {
14490
14515
  };
14491
14516
  /* end_public_function */
14492
14517
 
14493
- var index$h = /*#__PURE__*/Object.freeze({
14518
+ var index$i = /*#__PURE__*/Object.freeze({
14494
14519
  __proto__: null,
14495
14520
  addReaction: addReaction,
14496
14521
  removeReaction: removeReaction,
@@ -15811,15 +15836,23 @@ getDeliveredUsers.locally = (query) => {
15811
15836
  * ```
15812
15837
  *
15813
15838
  * @param messageId of the message to flag
15839
+ * @param reason the reason to flag the message
15814
15840
  * @returns the created report result
15815
15841
  *
15816
15842
  * @category Message API
15817
15843
  * @async
15818
15844
  * */
15819
- const flagMessage = async (messageId) => {
15845
+ const flagMessage = async (messageId, reason) => {
15820
15846
  const client = getActiveClient();
15821
15847
  client.log('message/flag', messageId);
15822
- const { data: payload } = await client.http.post(`/api/v5/messages/${encodeURIComponent(messageId)}/flags`);
15848
+ const isPredefinedReason = Object.values(exports.ContentFlagReasonEnum)
15849
+ .filter(value => value !== exports.ContentFlagReasonEnum.Others)
15850
+ .includes(reason);
15851
+ const body = {
15852
+ reason: isPredefinedReason ? reason : exports.ContentFlagReasonEnum.Others,
15853
+ detail: isPredefinedReason ? '' : reason,
15854
+ };
15855
+ const { data: payload } = await client.http.post(`/api/v5/messages/${encodeURIComponent(messageId)}/flags`, body);
15823
15856
  if (client.cache) {
15824
15857
  const messagePayload = await prepareMessagePayload(payload);
15825
15858
  ingestInCache(messagePayload);
@@ -16306,7 +16339,7 @@ const getMessages = (params, callback, config) => {
16306
16339
  };
16307
16340
  /* end_public_function */
16308
16341
 
16309
- var index$g = /*#__PURE__*/Object.freeze({
16342
+ var index$h = /*#__PURE__*/Object.freeze({
16310
16343
  __proto__: null,
16311
16344
  createMessage: createMessage,
16312
16345
  updateMessage: updateMessage,
@@ -16832,7 +16865,7 @@ const stopMessageReceiptSync = (subChannelId) => {
16832
16865
  };
16833
16866
  /* end_public_function */
16834
16867
 
16835
- var index$f = /*#__PURE__*/Object.freeze({
16868
+ var index$g = /*#__PURE__*/Object.freeze({
16836
16869
  __proto__: null,
16837
16870
  getSubChannelByIds: getSubChannels$1,
16838
16871
  createSubChannel: createSubChannel,
@@ -18146,7 +18179,7 @@ const searchMembers$1 = (params, callback, config) => {
18146
18179
  };
18147
18180
  /* end_public_function */
18148
18181
 
18149
- var index$e = /*#__PURE__*/Object.freeze({
18182
+ var index$f = /*#__PURE__*/Object.freeze({
18150
18183
  __proto__: null,
18151
18184
  addMembers: addMembers$1,
18152
18185
  removeMembers: removeMembers$1,
@@ -18349,7 +18382,7 @@ const unmuteMembers = async (channelId, userIds) => {
18349
18382
  };
18350
18383
  /* end_public_function */
18351
18384
 
18352
- var index$d = /*#__PURE__*/Object.freeze({
18385
+ var index$e = /*#__PURE__*/Object.freeze({
18353
18386
  __proto__: null,
18354
18387
  addRole: addRole,
18355
18388
  removeRole: removeRole,
@@ -18359,10 +18392,10 @@ var index$d = /*#__PURE__*/Object.freeze({
18359
18392
  unmuteMembers: unmuteMembers
18360
18393
  });
18361
18394
 
18362
- var index$c = /*#__PURE__*/Object.freeze({
18395
+ var index$d = /*#__PURE__*/Object.freeze({
18363
18396
  __proto__: null,
18364
- Membership: index$e,
18365
- Moderation: index$d,
18397
+ Membership: index$f,
18398
+ Moderation: index$e,
18366
18399
  getChannelByIds: getChannelByIds$1,
18367
18400
  createChannel: createChannel,
18368
18401
  updateChannel: updateChannel,
@@ -19742,7 +19775,7 @@ const searchMembers = (params, callback, config) => {
19742
19775
  };
19743
19776
  /* end_public_function */
19744
19777
 
19745
- var index$b = /*#__PURE__*/Object.freeze({
19778
+ var index$c = /*#__PURE__*/Object.freeze({
19746
19779
  __proto__: null,
19747
19780
  addMembers: addMembers,
19748
19781
  removeMembers: removeMembers,
@@ -20767,7 +20800,7 @@ const unbanMembers = async (communityId, userIds) => {
20767
20800
  };
20768
20801
  /* end_public_function */
20769
20802
 
20770
- var index$a = /*#__PURE__*/Object.freeze({
20803
+ var index$b = /*#__PURE__*/Object.freeze({
20771
20804
  __proto__: null,
20772
20805
  addRoles: addRoles,
20773
20806
  removeRoles: removeRoles,
@@ -20775,10 +20808,10 @@ var index$a = /*#__PURE__*/Object.freeze({
20775
20808
  unbanMembers: unbanMembers
20776
20809
  });
20777
20810
 
20778
- var index$9 = /*#__PURE__*/Object.freeze({
20811
+ var index$a = /*#__PURE__*/Object.freeze({
20779
20812
  __proto__: null,
20780
- Moderation: index$a,
20781
- Membership: index$b,
20813
+ Moderation: index$b,
20814
+ Membership: index$c,
20782
20815
  getCommunityByIds: getCommunities$1,
20783
20816
  createCommunity: createCommunity,
20784
20817
  updateCommunity: updateCommunity,
@@ -21011,7 +21044,7 @@ const getCategories = (params, callback, config) => {
21011
21044
  };
21012
21045
  /* end_public_function */
21013
21046
 
21014
- var index$8 = /*#__PURE__*/Object.freeze({
21047
+ var index$9 = /*#__PURE__*/Object.freeze({
21015
21048
  __proto__: null,
21016
21049
  getCategory: getCategory,
21017
21050
  getCategories: getCategories
@@ -21179,7 +21212,7 @@ getCustomRankingGlobalFeed.locally = (query) => {
21179
21212
  : undefined;
21180
21213
  };
21181
21214
 
21182
- var index$7 = /*#__PURE__*/Object.freeze({
21215
+ var index$8 = /*#__PURE__*/Object.freeze({
21183
21216
  __proto__: null,
21184
21217
  queryGlobalFeed: queryGlobalFeed,
21185
21218
  getCustomRankingGlobalFeed: getCustomRankingGlobalFeed
@@ -22494,7 +22527,7 @@ const getComments = (params, callback, config) => {
22494
22527
  };
22495
22528
  /* end_public_function */
22496
22529
 
22497
- var index$6 = /*#__PURE__*/Object.freeze({
22530
+ var index$7 = /*#__PURE__*/Object.freeze({
22498
22531
  __proto__: null,
22499
22532
  getCommentByIds: getCommentByIds,
22500
22533
  createComment: createComment,
@@ -23501,7 +23534,7 @@ const semanticSearchPosts = (params, callback, config) => {
23501
23534
  };
23502
23535
  };
23503
23536
 
23504
- var index$5 = /*#__PURE__*/Object.freeze({
23537
+ var index$6 = /*#__PURE__*/Object.freeze({
23505
23538
  __proto__: null,
23506
23539
  getPostByIds: getPostByIds,
23507
23540
  createPost: createPost,
@@ -24035,7 +24068,7 @@ const getStreams = (params, callback, config) => {
24035
24068
  };
24036
24069
  };
24037
24070
 
24038
- var index$4 = /*#__PURE__*/Object.freeze({
24071
+ var index$5 = /*#__PURE__*/Object.freeze({
24039
24072
  __proto__: null,
24040
24073
  createStream: createStream,
24041
24074
  updateStream: updateStream,
@@ -24322,7 +24355,7 @@ const getPoll = (pollId, callback) => {
24322
24355
  };
24323
24356
  /* end_public_function */
24324
24357
 
24325
- var index$3 = /*#__PURE__*/Object.freeze({
24358
+ var index$4 = /*#__PURE__*/Object.freeze({
24326
24359
  __proto__: null,
24327
24360
  createPoll: createPoll,
24328
24361
  closePoll: closePoll,
@@ -24693,7 +24726,7 @@ const getPlayer = async (parameters) => {
24693
24726
  return video;
24694
24727
  };
24695
24728
 
24696
- var index$2 = /*#__PURE__*/Object.freeze({
24729
+ var index$3 = /*#__PURE__*/Object.freeze({
24697
24730
  __proto__: null,
24698
24731
  getPlayer: getPlayer
24699
24732
  });
@@ -25866,7 +25899,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
25866
25899
  };
25867
25900
  };
25868
25901
 
25869
- var index$1 = /*#__PURE__*/Object.freeze({
25902
+ var index$2 = /*#__PURE__*/Object.freeze({
25870
25903
  __proto__: null,
25871
25904
  createImageStory: createImageStory,
25872
25905
  createVideoStory: createVideoStory,
@@ -25903,7 +25936,7 @@ const getNetworkAds = async () => {
25903
25936
  };
25904
25937
  };
25905
25938
 
25906
- var index = /*#__PURE__*/Object.freeze({
25939
+ var index$1 = /*#__PURE__*/Object.freeze({
25907
25940
  __proto__: null,
25908
25941
  getNetworkAds: getNetworkAds
25909
25942
  });
@@ -25930,31 +25963,404 @@ const createUserToken = async (apiKey, apiRegion, params) => {
25930
25963
  return { accessToken: data.accessToken };
25931
25964
  };
25932
25965
 
25966
+ /* begin_public_function
25967
+ id: notificationTray.getNotificationTraySeen
25968
+ */
25969
+ /**
25970
+ * ```js
25971
+ * import { notificationTray } from '@amityco/ts-sdk'
25972
+ * const notificationTraySeen = await notificationTray.getNotificationTraySeen()
25973
+ * ```
25974
+ *
25975
+ *
25976
+ * @returns A page of {@link Amity.NotificationTraySeen} objects
25977
+ *
25978
+ * @category NotificationTray API
25979
+ * @async
25980
+ * */
25981
+ const getNotificationTraySeen$1 = async () => {
25982
+ const client = getActiveClient();
25983
+ client.log('notificationTray/getNotificationTraySeen', {});
25984
+ const { data: payload } = await client.http.get(`api/v1/notification-tray/tray/seen`);
25985
+ const cachedAt = client.cache && Date.now();
25986
+ if (client.cache) {
25987
+ const cacheKey = ['notificationTraySeen', 'get', client.userId];
25988
+ pushToCache(cacheKey, {
25989
+ userId: client.userId,
25990
+ lastTraySeenAt: payload.lastTraySeenAt,
25991
+ lastTrayOccuredAt: payload.lastTrayOccurredAt,
25992
+ });
25993
+ }
25994
+ return {
25995
+ data: {
25996
+ userId: client.userId,
25997
+ lastTraySeenAt: payload.lastTraySeenAt,
25998
+ lastTrayOccurredAt: payload.lastTrayOccurredAt,
25999
+ isSeen: payload.lastTraySeenAt > payload.lastTrayOccurredAt,
26000
+ },
26001
+ cachedAt,
26002
+ };
26003
+ };
26004
+ /* end_public_function */
26005
+ /**
26006
+ * ```js
26007
+ * import { notificationTray } from '@amityco/ts-sdk'
26008
+ * const notificationTraySeen = await notificationTray.getNotificationTraySeen.locally()
26009
+ * ```
26010
+ *
26011
+ * Queries a paginable list of {@link Amity.NotificationTraySeen} objects from cache
26012
+ *
26013
+ * @returns A page of {@link Amity.NotificationTraySeen} objects
26014
+ *
26015
+ * @category NotificationTray API
26016
+ * @async
26017
+ * */
26018
+ getNotificationTraySeen$1.locally = () => {
26019
+ var _a;
26020
+ const client = getActiveClient();
26021
+ client.log('notificationTray/getNotificationTraySeen.locally', {});
26022
+ if (!client.cache)
26023
+ return;
26024
+ const queryKey = ['notificationTraySeen', 'get'];
26025
+ const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
26026
+ if (!data)
26027
+ return;
26028
+ return { data, cachedAt };
26029
+ };
26030
+
26031
+ /**
26032
+ * ```js
26033
+ * import { onNotificationTraySeenUpdated } from '@amityco/ts-sdk'
26034
+ * const dispose = onNotificationTraySeenUpdated(data => {
26035
+ * // ...
26036
+ * })
26037
+ * ```
26038
+ *
26039
+ * Fired when an {@link Amity.NotificationTraySeen} has been updated
26040
+ *
26041
+ * @param callback The function to call when the event was fired
26042
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
26043
+ *
26044
+ * @category NotificationTraySeen Events
26045
+ */
26046
+ const onNotificationTraySeenUpdated = (callback) => {
26047
+ const client = getActiveClient();
26048
+ const disposers = [
26049
+ createEventSubscriber(client, 'onNotificationTraySeenUpdated', 'local.notificationTraySeen.updated', payload => callback(payload)),
26050
+ ];
26051
+ return () => {
26052
+ disposers.forEach(fn => fn());
26053
+ };
26054
+ };
26055
+
26056
+ /* begin_public_function
26057
+ id: notificationTray.getNotificationTraySeen
26058
+ */
26059
+ /**
26060
+ * ```js
26061
+ * import { notificationTray } from '@amityco/ts-sdk';
26062
+ *
26063
+ * let notificationTraySeen;
26064
+ *
26065
+ * const unsubscribe = getNotificationTraySeen(response => {
26066
+ * notificationTraySeen = response.data;
26067
+ * });
26068
+ * ```
26069
+ *
26070
+ * Observe all mutation on a given {@link Amity.NotificationTraySeen}
26071
+ *
26072
+ * @param callback the function to call when new data are available
26073
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the message
26074
+ *
26075
+ * @category NotificationTraySeen Live Object
26076
+ */
26077
+ const getNotificationTraySeen = (callback) => {
26078
+ const { userId } = getActiveUser();
26079
+ return liveObject(userId, callback, 'userId', getNotificationTraySeen$1, [onNotificationTraySeenUpdated], {
26080
+ callbackDataSelector: (data) => {
26081
+ let isSeen = true;
26082
+ if (data === null || data === void 0 ? void 0 : data.lastTrayOccurredAt) {
26083
+ if (!data.lastTraySeenAt) {
26084
+ isSeen = false;
26085
+ }
26086
+ else {
26087
+ isSeen =
26088
+ convertDateStringToTimestamp(data.lastTraySeenAt) >
26089
+ convertDateStringToTimestamp(data.lastTrayOccurredAt);
26090
+ }
26091
+ }
26092
+ return {
26093
+ lastTrayOccurredAt: data === null || data === void 0 ? void 0 : data.lastTrayOccurredAt,
26094
+ lastTraySeenAt: data === null || data === void 0 ? void 0 : data.lastTraySeenAt,
26095
+ isSeen,
26096
+ };
26097
+ },
26098
+ });
26099
+ };
26100
+ /* end_public_function */
26101
+
26102
+ /**
26103
+ * TODO: handle cache receive cache option, and cache policy
26104
+ * TODO: check if querybyIds is supported
26105
+ */
26106
+ class NotificationTrayItemsPaginationController extends PaginationController {
26107
+ async getRequest(queryParams, token) {
26108
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
26109
+ const options = token ? { token } : { limit };
26110
+ const { data: queryResponse } = await this.http.get(`/api/v1/notification-tray`, {
26111
+ params: Object.assign(Object.assign({}, params), { options }),
26112
+ });
26113
+ return queryResponse;
26114
+ }
26115
+ }
26116
+
26117
+ class NotificationTrayItemsQuerystreamController extends QueryStreamController {
26118
+ constructor(query, cacheKey, notifyChange, preparePayload) {
26119
+ super(query, cacheKey);
26120
+ this.notifyChange = notifyChange;
26121
+ this.preparePayload = preparePayload;
26122
+ }
26123
+ async saveToMainDB(response) {
26124
+ const processedPayload = await this.preparePayload(response);
26125
+ const client = getActiveClient();
26126
+ const cachedAt = client.cache && Date.now();
26127
+ if (client.cache) {
26128
+ ingestInCache(processedPayload, { cachedAt });
26129
+ }
26130
+ }
26131
+ appendToQueryStream(response, direction, refresh = false) {
26132
+ var _a, _b;
26133
+ if (refresh) {
26134
+ pushToCache(this.cacheKey, {
26135
+ data: response.notificationTrayItems.map(getResolver('notificationTrayItem')),
26136
+ });
26137
+ }
26138
+ else {
26139
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
26140
+ const notifications = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
26141
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
26142
+ ...new Set([
26143
+ ...notifications,
26144
+ ...response.notificationTrayItems.map(getResolver('notificationTrayItem')),
26145
+ ]),
26146
+ ] }));
26147
+ }
26148
+ }
26149
+ }
26150
+
26151
+ const prepareNotificationTrayItemsPayload = (rawPayload) => {
26152
+ const users = rawPayload.users.map(convertRawUserToInternalUser);
26153
+ return Object.assign(Object.assign({}, rawPayload), { users });
26154
+ };
26155
+
26156
+ class NotificationTrayItemsLiveCollectionController extends LiveCollectionController {
26157
+ constructor(query, callback) {
26158
+ const queryStreamId = hash__default["default"](query);
26159
+ const cacheKey = ['notificationTrayItem', 'collection', queryStreamId];
26160
+ const paginationController = new NotificationTrayItemsPaginationController(query);
26161
+ super(paginationController, queryStreamId, cacheKey, callback);
26162
+ this.query = query;
26163
+ this.queryStreamController = new NotificationTrayItemsQuerystreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareNotificationTrayItemsPayload);
26164
+ this.callback = callback.bind(this);
26165
+ this.loadPage({ initial: true });
26166
+ }
26167
+ setup() {
26168
+ var _a;
26169
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
26170
+ if (!collection) {
26171
+ pushToCache(this.cacheKey, {
26172
+ data: [],
26173
+ params: {},
26174
+ });
26175
+ }
26176
+ }
26177
+ async persistModel(queryPayload) {
26178
+ await this.queryStreamController.saveToMainDB(queryPayload);
26179
+ }
26180
+ persistQueryStream({ response, direction, refresh, }) {
26181
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
26182
+ }
26183
+ // eslint-disable-next-line class-methods-use-this
26184
+ startSubscription() {
26185
+ return [];
26186
+ }
26187
+ notifyChange({ origin, loading, error }) {
26188
+ var _a, _b;
26189
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
26190
+ if (!collection)
26191
+ return;
26192
+ const data = ((_b = collection.data
26193
+ .map(id => pullFromCache(['notificationTrayItem', 'get', id]))
26194
+ .filter(isNonNullable)
26195
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.notificationTray);
26196
+ if (!this.shouldNotify(data) && origin === 'event')
26197
+ return;
26198
+ this.callback({
26199
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
26200
+ data,
26201
+ hasNextPage: !!this.paginationController.getNextToken(),
26202
+ loading,
26203
+ error,
26204
+ });
26205
+ }
26206
+ }
26207
+
26208
+ /**
26209
+ * Get notification tray items for a notification tray page
26210
+ *
26211
+ * @param params the limit query parameters
26212
+ * @param callback the callback to be called when the notification tray items are updated
26213
+ * @returns items in the notification tray
26214
+ *
26215
+ * @category Notification tray items Live Collection
26216
+ *
26217
+ */
26218
+ const getNotificationTrayItems = (params, callback, config) => {
26219
+ const { log, cache } = getActiveClient();
26220
+ if (!cache) {
26221
+ console.log(ENABLE_CACHE_MESSAGE);
26222
+ }
26223
+ const timestamp = Date.now();
26224
+ log(`getNotificationTrayItems(tmpid: ${timestamp}) > listen`);
26225
+ const notiTrayItemsLiveCollection = new NotificationTrayItemsLiveCollectionController(params, callback);
26226
+ const disposers = notiTrayItemsLiveCollection.startSubscription();
26227
+ const cacheKey = notiTrayItemsLiveCollection.getCacheKey();
26228
+ disposers.push(() => dropFromCache(cacheKey));
26229
+ return () => {
26230
+ log(`getNotificationTrayItems(tmpid: ${timestamp}) > dispose`);
26231
+ disposers.forEach(fn => fn());
26232
+ };
26233
+ };
26234
+
26235
+ /* begin_public_function
26236
+ id: notificationTrayItem.markSeen
26237
+ */
26238
+ /**
26239
+ * ```js
26240
+ * import { notificationTray } from '@amityco/ts-sdk'
26241
+ * const updated = await notificationTray.markItemsSeen()
26242
+ * ```
26243
+ *
26244
+ * Updates an {@link Amity.NotificationItemSeen}
26245
+ *
26246
+ * @param trayItems[] that include id and lastTraySeenAt, The ID of the {@link Amity.NotificationItemSeen} to edit
26247
+ * @returns the updated {@link Amity.NotificationItemSeen} object
26248
+ *
26249
+ * @category NotificationItemSeen API
26250
+ * @async
26251
+ */
26252
+ const markItemsSeen = async (trayItems) => {
26253
+ const client = getActiveClient();
26254
+ client.log('notificationTray/markItemsSeen', {});
26255
+ const { data: payload } = await client.http.post(`api/v1/notification-tray/items/seen`, {
26256
+ trayItems: trayItems.map(item => ({
26257
+ id: item.id,
26258
+ lastSeenAt: item.lastSeenAt,
26259
+ })),
26260
+ });
26261
+ const updatedData = trayItems
26262
+ .map(patchItem => {
26263
+ var _a;
26264
+ const cacheData = (_a = pullFromCache([
26265
+ 'notificationTrayItem',
26266
+ 'get',
26267
+ patchItem.id,
26268
+ ])) === null || _a === void 0 ? void 0 : _a.data;
26269
+ if (!cacheData)
26270
+ return;
26271
+ const data = Object.assign(Object.assign({}, cacheData), payload);
26272
+ if (client.cache) {
26273
+ const cachedAt = Date.now();
26274
+ pushToCache(['notificationTrayItem', 'get'], data, { cachedAt });
26275
+ }
26276
+ return data;
26277
+ })
26278
+ .filter(Boolean);
26279
+ fireEvent('local.notificationTrayItem.updated', { notificationTrayItems: updatedData });
26280
+ };
26281
+ /* end_public_function */
26282
+
26283
+ /* begin_public_function
26284
+ id: notificationTray.markSeen
26285
+ */
26286
+ /**
26287
+ * ```js
26288
+ * import { notificationTray } from '@amityco/ts-sdk'
26289
+ * const updated = await notificationTray.markTraySeen({
26290
+ * lastSeenAt: Amity.timestamp,
26291
+ * })
26292
+ * ```
26293
+ *
26294
+ * Updates an {@link Amity.NotificationTraySeen}
26295
+ *
26296
+ * @param userId The ID of the {@link Amity.NotificationTraySeen} to edit
26297
+ * @param lastSeenAt The patch data to apply
26298
+ * @returns the updated {@link Amity.NotificationTraySeen} object
26299
+ *
26300
+ * @category Post API
26301
+ * @async
26302
+ */
26303
+ const markTraySeen = async (lastSeenAt) => {
26304
+ var _a;
26305
+ const client = getActiveClient();
26306
+ client.log('notificationTray/markTraySeen', {});
26307
+ const { data: payload } = await client.http.post(`api/v1/notification-tray/tray/seen`, {
26308
+ lastSeenAt,
26309
+ });
26310
+ const cacheData = (_a = pullFromCache([
26311
+ 'notificationTraySeen',
26312
+ 'get',
26313
+ ])) === null || _a === void 0 ? void 0 : _a.data;
26314
+ const data = {
26315
+ userId: client.userId,
26316
+ lastTraySeenAt: payload.lastSeenAt,
26317
+ };
26318
+ const updateCacheData = Object.assign(Object.assign({}, cacheData), data);
26319
+ const cachedAt = client.cache && Date.now();
26320
+ if (client.cache)
26321
+ pushToCache(['notificationTraySeen', 'get', client.userId], updateCacheData, { cachedAt });
26322
+ fireEvent('local.notificationTraySeen.updated', data);
26323
+ return {
26324
+ data: payload,
26325
+ cachedAt,
26326
+ };
26327
+ };
26328
+ /* end_public_function */
26329
+
26330
+ var index = /*#__PURE__*/Object.freeze({
26331
+ __proto__: null,
26332
+ getNotificationTraySeen: getNotificationTraySeen,
26333
+ getNotificationTrayItems: getNotificationTrayItems,
26334
+ markItemsSeen: markItemsSeen,
26335
+ markTraySeen: markTraySeen,
26336
+ onNotificationTraySeenUpdated: onNotificationTraySeenUpdated
26337
+ });
26338
+
25933
26339
  exports.API_REGIONS = API_REGIONS;
25934
- exports.AdRepository = index;
25935
- exports.CategoryRepository = index$8;
25936
- exports.ChannelRepository = index$c;
25937
- exports.Client = index$l;
25938
- exports.CommentRepository = index$6;
26340
+ exports.AdRepository = index$1;
26341
+ exports.CategoryRepository = index$9;
26342
+ exports.ChannelRepository = index$d;
26343
+ exports.Client = index$m;
26344
+ exports.CommentRepository = index$7;
25939
26345
  exports.CommunityPostSettingMaps = CommunityPostSettingMaps;
25940
26346
  exports.CommunityPostSettings = CommunityPostSettings;
25941
- exports.CommunityRepository = index$9;
26347
+ exports.CommunityRepository = index$a;
25942
26348
  exports.ContentFeedType = ContentFeedType;
25943
26349
  exports.DefaultCommunityPostSetting = DefaultCommunityPostSetting;
25944
- exports.FeedRepository = index$7;
25945
- exports.FileRepository = index$i;
26350
+ exports.FeedRepository = index$8;
26351
+ exports.FileRepository = index$j;
25946
26352
  exports.FileType = FileType;
25947
- exports.LiveStreamPlayer = index$2;
26353
+ exports.LiveStreamPlayer = index$3;
25948
26354
  exports.MessageContentType = MessageContentType;
25949
- exports.MessageRepository = index$g;
25950
- exports.PollRepository = index$3;
26355
+ exports.MessageRepository = index$h;
26356
+ exports.PollRepository = index$4;
25951
26357
  exports.PostContentType = PostContentType;
25952
- exports.PostRepository = index$5;
25953
- exports.ReactionRepository = index$h;
25954
- exports.StoryRepository = index$1;
25955
- exports.StreamRepository = index$4;
25956
- exports.SubChannelRepository = index$f;
25957
- exports.UserRepository = index$j;
26358
+ exports.PostRepository = index$6;
26359
+ exports.ReactionRepository = index$i;
26360
+ exports.StoryRepository = index$2;
26361
+ exports.StreamRepository = index$5;
26362
+ exports.SubChannelRepository = index$g;
26363
+ exports.UserRepository = index$k;
25958
26364
  exports.VERSION = VERSION;
25959
26365
  exports.VideoResolution = VideoResolution;
25960
26366
  exports.VideoSize = VideoSize;
@@ -26007,6 +26413,7 @@ exports.isPaged = isPaged;
26007
26413
  exports.isReportedByMe = isReportedByMe;
26008
26414
  exports.isSkip = isSkip;
26009
26415
  exports.mergeInCache = mergeInCache;
26416
+ exports.notificationTray = index;
26010
26417
  exports.onChannelMarkerFetched = onChannelMarkerFetched;
26011
26418
  exports.onFeedMarkerFetched = onFeedMarkerFetched;
26012
26419
  exports.onFeedMarkerUpdated = onFeedMarkerUpdated;