@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.d.ts CHANGED
@@ -25,4 +25,5 @@ export * as LiveStreamPlayer from './liveStreamPlayer';
25
25
  export * as StoryRepository from './storyRepository';
26
26
  export * as AdRepository from './adRepository';
27
27
  export * from './external/api';
28
+ export * as notificationTray from './notificationTray';
28
29
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,UAAU,CAAC;AAEzB,cAAc,WAAW,CAAC;AAG1B,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAE5B,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAGvD,OAAO,KAAK,cAAc,MAAM,kBAAkB,CAAC;AAEnD,OAAO,KAAK,cAAc,MAAM,kBAAkB,CAAC;AAEnD,cAAc,YAAY,CAAC;AAG3B,OAAO,KAAK,kBAAkB,MAAM,sBAAsB,CAAC;AAE3D,cAAc,cAAc,CAAC;AAG7B,OAAO,KAAK,iBAAiB,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,iBAAiB,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,oBAAoB,MAAM,wBAAwB,CAAC;AAE/D,cAAc,iBAAiB,CAAC;AAGhC,OAAO,KAAK,mBAAmB,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,kBAAkB,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,cAAc,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,cAAc,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,iBAAiB,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,gBAAgB,MAAM,oBAAoB,CAAC;AAEvD,OAAO,KAAK,cAAc,MAAM,kBAAkB,CAAC;AAEnD,OAAO,KAAK,gBAAgB,MAAM,oBAAoB,CAAC;AAEvD,OAAO,KAAK,eAAe,MAAM,mBAAmB,CAAC;AAGrD,OAAO,KAAK,YAAY,MAAM,gBAAgB,CAAC;AAG/C,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,UAAU,CAAC;AAEzB,cAAc,WAAW,CAAC;AAG1B,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAE5B,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAGvD,OAAO,KAAK,cAAc,MAAM,kBAAkB,CAAC;AAEnD,OAAO,KAAK,cAAc,MAAM,kBAAkB,CAAC;AAEnD,cAAc,YAAY,CAAC;AAG3B,OAAO,KAAK,kBAAkB,MAAM,sBAAsB,CAAC;AAE3D,cAAc,cAAc,CAAC;AAG7B,OAAO,KAAK,iBAAiB,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,iBAAiB,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,oBAAoB,MAAM,wBAAwB,CAAC;AAE/D,cAAc,iBAAiB,CAAC;AAGhC,OAAO,KAAK,mBAAmB,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,kBAAkB,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,cAAc,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,cAAc,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,iBAAiB,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,gBAAgB,MAAM,oBAAoB,CAAC;AAEvD,OAAO,KAAK,cAAc,MAAM,kBAAkB,CAAC;AAEnD,OAAO,KAAK,gBAAgB,MAAM,oBAAoB,CAAC;AAEvD,OAAO,KAAK,eAAe,MAAM,mBAAmB,CAAC;AAGrD,OAAO,KAAK,YAAY,MAAM,gBAAgB,CAAC;AAG/C,cAAc,gBAAgB,CAAC;AAE/B,OAAO,KAAK,gBAAgB,MAAM,oBAAoB,CAAC"}
package/dist/index.esm.js CHANGED
@@ -65,7 +65,19 @@ const ContentFeedType = Object.freeze({
65
65
  CHAT: 'chat',
66
66
  POST: 'post',
67
67
  MESSAGE: 'message',
68
- });
68
+ });
69
+ var ContentFlagReasonEnum;
70
+ (function (ContentFlagReasonEnum) {
71
+ ContentFlagReasonEnum["CommunityGuidelines"] = "Against community guidelines";
72
+ ContentFlagReasonEnum["HarassmentOrBullying"] = "Harassment or bullying";
73
+ ContentFlagReasonEnum["SelfHarmOrSuicide"] = "Self-harm or suicide";
74
+ ContentFlagReasonEnum["ViolenceOrThreateningContent"] = "Violence or threatening content";
75
+ ContentFlagReasonEnum["SellingRestrictedItems"] = "Selling and promoting restricted items";
76
+ ContentFlagReasonEnum["SexualContentOrNudity"] = "Sexual message or nudity";
77
+ ContentFlagReasonEnum["SpamOrScams"] = "Spam or scams";
78
+ ContentFlagReasonEnum["FalseInformation"] = "False information or misinformation";
79
+ ContentFlagReasonEnum["Others"] = "Others";
80
+ })(ContentFlagReasonEnum || (ContentFlagReasonEnum = {}));
69
81
 
70
82
  const MessageContentType = Object.freeze({
71
83
  TEXT: 'text',
@@ -106,6 +118,7 @@ const SECOND$1 = 1000;
106
118
  const MINUTE = 60 * SECOND$1;
107
119
  const HOUR = 60 * MINUTE;
108
120
  const DAY = 24 * HOUR;
121
+ const WEEK = 7 * DAY;
109
122
  const YEAR = 365 * DAY;
110
123
  const ACCESS_TOKEN_WATCHER_INTERVAL = 10 * MINUTE;
111
124
 
@@ -528,6 +541,8 @@ const idResolvers = {
528
541
  advertiser: ({ advertiserId }) => advertiserId,
529
542
  pin: ({ placement, referenceId }) => `${placement}#${referenceId}`,
530
543
  pinTarget: ({ targetId }) => targetId,
544
+ notificationTrayItem: ({ _id }) => _id,
545
+ notificationTraySeen: ({ userId }) => userId,
531
546
  };
532
547
  /**
533
548
  * Retrieve the id resolver matching a domain name
@@ -579,6 +594,7 @@ const PAYLOAD2MODEL = {
579
594
  advertisers: 'advertiser',
580
595
  pinTargets: 'pinTarget',
581
596
  pins: 'pin',
597
+ notificationTrayItems: 'notificationTrayItem',
582
598
  };
583
599
  /** hidden */
584
600
  const isOutdated = (prevData, nextData) => {
@@ -22313,6 +22329,14 @@ const pinnedPostLinkedObject = (pinnedPost) => {
22313
22329
  } });
22314
22330
  };
22315
22331
 
22332
+ const notificationTrayLinkedObject = (noti) => {
22333
+ return Object.assign(Object.assign({}, noti), { isSeen: noti.lastSeenAt > noti.lastOccurredAt, isRecent: new Date(noti.lastOccurredAt).getTime() >= Date.now() - WEEK, users: noti.actors
22334
+ .map(({ _id }) => pullFromCache(['user', 'get', _id]))
22335
+ .filter(isNonNullable)
22336
+ .map(({ data }) => data)
22337
+ .map(user => userLinkedObject(user)) });
22338
+ };
22339
+
22316
22340
  const LinkedObject = {
22317
22341
  ad: adLinkedObject,
22318
22342
  comment: commentLinkedObject,
@@ -22326,6 +22350,7 @@ const LinkedObject = {
22326
22350
  reactor: reactorLinkedObject,
22327
22351
  channel: channelLinkedObject,
22328
22352
  pinnedPost: pinnedPostLinkedObject,
22353
+ notificationTray: notificationTrayLinkedObject,
22329
22354
  };
22330
22355
 
22331
22356
  const getChannelMessagePreviewWithUser = (channel) => {
@@ -26227,7 +26252,7 @@ const getUserUnread = (callback) => {
26227
26252
  };
26228
26253
  };
26229
26254
 
26230
- var index$l = /*#__PURE__*/Object.freeze({
26255
+ var index$m = /*#__PURE__*/Object.freeze({
26231
26256
  __proto__: null,
26232
26257
  getActiveClient: getActiveClient,
26233
26258
  getActiveUser: getActiveUser,
@@ -27434,7 +27459,7 @@ const getMyFollowInfo = (callback) => {
27434
27459
  };
27435
27460
  /* end_public_function */
27436
27461
 
27437
- var index$k = /*#__PURE__*/Object.freeze({
27462
+ var index$l = /*#__PURE__*/Object.freeze({
27438
27463
  __proto__: null,
27439
27464
  blockUser: blockUser,
27440
27465
  unBlockUser: unBlockUser,
@@ -28449,9 +28474,9 @@ var AmityUserSearchMatchType;
28449
28474
  AmityUserSearchMatchType["PARTIAL"] = "partial";
28450
28475
  })(AmityUserSearchMatchType || (AmityUserSearchMatchType = {}));
28451
28476
 
28452
- var index$j = /*#__PURE__*/Object.freeze({
28477
+ var index$k = /*#__PURE__*/Object.freeze({
28453
28478
  __proto__: null,
28454
- Relationship: index$k,
28479
+ Relationship: index$l,
28455
28480
  getUserByIds: getUserByIds,
28456
28481
  updateUser: updateUser,
28457
28482
  flagUser: flagUser,
@@ -28715,7 +28740,7 @@ const uploadImage = async (formData, onProgress) => {
28715
28740
  };
28716
28741
  /* end_public_function */
28717
28742
 
28718
- var index$i = /*#__PURE__*/Object.freeze({
28743
+ var index$j = /*#__PURE__*/Object.freeze({
28719
28744
  __proto__: null,
28720
28745
  getFile: getFile,
28721
28746
  uploadFile: uploadFile,
@@ -30582,7 +30607,7 @@ const getReactions = (params, callback, config) => {
30582
30607
  };
30583
30608
  /* end_public_function */
30584
30609
 
30585
- var index$h = /*#__PURE__*/Object.freeze({
30610
+ var index$i = /*#__PURE__*/Object.freeze({
30586
30611
  __proto__: null,
30587
30612
  addReaction: addReaction,
30588
30613
  removeReaction: removeReaction,
@@ -31903,15 +31928,23 @@ getDeliveredUsers.locally = (query) => {
31903
31928
  * ```
31904
31929
  *
31905
31930
  * @param messageId of the message to flag
31931
+ * @param reason the reason to flag the message
31906
31932
  * @returns the created report result
31907
31933
  *
31908
31934
  * @category Message API
31909
31935
  * @async
31910
31936
  * */
31911
- const flagMessage = async (messageId) => {
31937
+ const flagMessage = async (messageId, reason) => {
31912
31938
  const client = getActiveClient();
31913
31939
  client.log('message/flag', messageId);
31914
- const { data: payload } = await client.http.post(`/api/v5/messages/${encodeURIComponent(messageId)}/flags`);
31940
+ const isPredefinedReason = Object.values(ContentFlagReasonEnum)
31941
+ .filter(value => value !== ContentFlagReasonEnum.Others)
31942
+ .includes(reason);
31943
+ const body = {
31944
+ reason: isPredefinedReason ? reason : ContentFlagReasonEnum.Others,
31945
+ detail: isPredefinedReason ? '' : reason,
31946
+ };
31947
+ const { data: payload } = await client.http.post(`/api/v5/messages/${encodeURIComponent(messageId)}/flags`, body);
31915
31948
  if (client.cache) {
31916
31949
  const messagePayload = await prepareMessagePayload(payload);
31917
31950
  ingestInCache(messagePayload);
@@ -32398,7 +32431,7 @@ const getMessages = (params, callback, config) => {
32398
32431
  };
32399
32432
  /* end_public_function */
32400
32433
 
32401
- var index$g = /*#__PURE__*/Object.freeze({
32434
+ var index$h = /*#__PURE__*/Object.freeze({
32402
32435
  __proto__: null,
32403
32436
  createMessage: createMessage,
32404
32437
  updateMessage: updateMessage,
@@ -32924,7 +32957,7 @@ const stopMessageReceiptSync = (subChannelId) => {
32924
32957
  };
32925
32958
  /* end_public_function */
32926
32959
 
32927
- var index$f = /*#__PURE__*/Object.freeze({
32960
+ var index$g = /*#__PURE__*/Object.freeze({
32928
32961
  __proto__: null,
32929
32962
  getSubChannelByIds: getSubChannels$1,
32930
32963
  createSubChannel: createSubChannel,
@@ -34238,7 +34271,7 @@ const searchMembers$1 = (params, callback, config) => {
34238
34271
  };
34239
34272
  /* end_public_function */
34240
34273
 
34241
- var index$e = /*#__PURE__*/Object.freeze({
34274
+ var index$f = /*#__PURE__*/Object.freeze({
34242
34275
  __proto__: null,
34243
34276
  addMembers: addMembers$1,
34244
34277
  removeMembers: removeMembers$1,
@@ -34441,7 +34474,7 @@ const unmuteMembers = async (channelId, userIds) => {
34441
34474
  };
34442
34475
  /* end_public_function */
34443
34476
 
34444
- var index$d = /*#__PURE__*/Object.freeze({
34477
+ var index$e = /*#__PURE__*/Object.freeze({
34445
34478
  __proto__: null,
34446
34479
  addRole: addRole,
34447
34480
  removeRole: removeRole,
@@ -34451,10 +34484,10 @@ var index$d = /*#__PURE__*/Object.freeze({
34451
34484
  unmuteMembers: unmuteMembers
34452
34485
  });
34453
34486
 
34454
- var index$c = /*#__PURE__*/Object.freeze({
34487
+ var index$d = /*#__PURE__*/Object.freeze({
34455
34488
  __proto__: null,
34456
- Membership: index$e,
34457
- Moderation: index$d,
34489
+ Membership: index$f,
34490
+ Moderation: index$e,
34458
34491
  getChannelByIds: getChannelByIds$1,
34459
34492
  createChannel: createChannel,
34460
34493
  updateChannel: updateChannel,
@@ -35834,7 +35867,7 @@ const searchMembers = (params, callback, config) => {
35834
35867
  };
35835
35868
  /* end_public_function */
35836
35869
 
35837
- var index$b = /*#__PURE__*/Object.freeze({
35870
+ var index$c = /*#__PURE__*/Object.freeze({
35838
35871
  __proto__: null,
35839
35872
  addMembers: addMembers,
35840
35873
  removeMembers: removeMembers,
@@ -36859,7 +36892,7 @@ const unbanMembers = async (communityId, userIds) => {
36859
36892
  };
36860
36893
  /* end_public_function */
36861
36894
 
36862
- var index$a = /*#__PURE__*/Object.freeze({
36895
+ var index$b = /*#__PURE__*/Object.freeze({
36863
36896
  __proto__: null,
36864
36897
  addRoles: addRoles,
36865
36898
  removeRoles: removeRoles,
@@ -36867,10 +36900,10 @@ var index$a = /*#__PURE__*/Object.freeze({
36867
36900
  unbanMembers: unbanMembers
36868
36901
  });
36869
36902
 
36870
- var index$9 = /*#__PURE__*/Object.freeze({
36903
+ var index$a = /*#__PURE__*/Object.freeze({
36871
36904
  __proto__: null,
36872
- Moderation: index$a,
36873
- Membership: index$b,
36905
+ Moderation: index$b,
36906
+ Membership: index$c,
36874
36907
  getCommunityByIds: getCommunities$1,
36875
36908
  createCommunity: createCommunity,
36876
36909
  updateCommunity: updateCommunity,
@@ -37103,7 +37136,7 @@ const getCategories = (params, callback, config) => {
37103
37136
  };
37104
37137
  /* end_public_function */
37105
37138
 
37106
- var index$8 = /*#__PURE__*/Object.freeze({
37139
+ var index$9 = /*#__PURE__*/Object.freeze({
37107
37140
  __proto__: null,
37108
37141
  getCategory: getCategory,
37109
37142
  getCategories: getCategories
@@ -37271,7 +37304,7 @@ getCustomRankingGlobalFeed.locally = (query) => {
37271
37304
  : undefined;
37272
37305
  };
37273
37306
 
37274
- var index$7 = /*#__PURE__*/Object.freeze({
37307
+ var index$8 = /*#__PURE__*/Object.freeze({
37275
37308
  __proto__: null,
37276
37309
  queryGlobalFeed: queryGlobalFeed,
37277
37310
  getCustomRankingGlobalFeed: getCustomRankingGlobalFeed
@@ -38586,7 +38619,7 @@ const getComments = (params, callback, config) => {
38586
38619
  };
38587
38620
  /* end_public_function */
38588
38621
 
38589
- var index$6 = /*#__PURE__*/Object.freeze({
38622
+ var index$7 = /*#__PURE__*/Object.freeze({
38590
38623
  __proto__: null,
38591
38624
  getCommentByIds: getCommentByIds,
38592
38625
  createComment: createComment,
@@ -39593,7 +39626,7 @@ const semanticSearchPosts = (params, callback, config) => {
39593
39626
  };
39594
39627
  };
39595
39628
 
39596
- var index$5 = /*#__PURE__*/Object.freeze({
39629
+ var index$6 = /*#__PURE__*/Object.freeze({
39597
39630
  __proto__: null,
39598
39631
  getPostByIds: getPostByIds,
39599
39632
  createPost: createPost,
@@ -40127,7 +40160,7 @@ const getStreams = (params, callback, config) => {
40127
40160
  };
40128
40161
  };
40129
40162
 
40130
- var index$4 = /*#__PURE__*/Object.freeze({
40163
+ var index$5 = /*#__PURE__*/Object.freeze({
40131
40164
  __proto__: null,
40132
40165
  createStream: createStream,
40133
40166
  updateStream: updateStream,
@@ -40414,7 +40447,7 @@ const getPoll = (pollId, callback) => {
40414
40447
  };
40415
40448
  /* end_public_function */
40416
40449
 
40417
- var index$3 = /*#__PURE__*/Object.freeze({
40450
+ var index$4 = /*#__PURE__*/Object.freeze({
40418
40451
  __proto__: null,
40419
40452
  createPoll: createPoll,
40420
40453
  closePoll: closePoll,
@@ -40785,7 +40818,7 @@ const getPlayer = async (parameters) => {
40785
40818
  return video;
40786
40819
  };
40787
40820
 
40788
- var index$2 = /*#__PURE__*/Object.freeze({
40821
+ var index$3 = /*#__PURE__*/Object.freeze({
40789
40822
  __proto__: null,
40790
40823
  getPlayer: getPlayer
40791
40824
  });
@@ -41958,7 +41991,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
41958
41991
  };
41959
41992
  };
41960
41993
 
41961
- var index$1 = /*#__PURE__*/Object.freeze({
41994
+ var index$2 = /*#__PURE__*/Object.freeze({
41962
41995
  __proto__: null,
41963
41996
  createImageStory: createImageStory,
41964
41997
  createVideoStory: createVideoStory,
@@ -41995,7 +42028,7 @@ const getNetworkAds = async () => {
41995
42028
  };
41996
42029
  };
41997
42030
 
41998
- var index = /*#__PURE__*/Object.freeze({
42031
+ var index$1 = /*#__PURE__*/Object.freeze({
41999
42032
  __proto__: null,
42000
42033
  getNetworkAds: getNetworkAds
42001
42034
  });
@@ -42022,4 +42055,377 @@ const createUserToken = async (apiKey, apiRegion, params) => {
42022
42055
  return { accessToken: data.accessToken };
42023
42056
  };
42024
42057
 
42025
- export { API_REGIONS, index as AdRepository, index$8 as CategoryRepository, index$c as ChannelRepository, index$l as Client, index$6 as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$9 as CommunityRepository, ContentFeedType, DefaultCommunityPostSetting, index$7 as FeedRepository, FileAccessTypeEnum, index$i as FileRepository, FileType, index$2 as LiveStreamPlayer, MessageContentType, index$g as MessageRepository, index$3 as PollRepository, PostContentType, index$5 as PostRepository, index$h as ReactionRepository, index$1 as StoryRepository, index$4 as StreamRepository, index$f as SubChannelRepository, SubscriptionLevels, index$j as UserRepository, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };
42058
+ /* begin_public_function
42059
+ id: notificationTray.getNotificationTraySeen
42060
+ */
42061
+ /**
42062
+ * ```js
42063
+ * import { notificationTray } from '@amityco/ts-sdk'
42064
+ * const notificationTraySeen = await notificationTray.getNotificationTraySeen()
42065
+ * ```
42066
+ *
42067
+ *
42068
+ * @returns A page of {@link Amity.NotificationTraySeen} objects
42069
+ *
42070
+ * @category NotificationTray API
42071
+ * @async
42072
+ * */
42073
+ const getNotificationTraySeen$1 = async () => {
42074
+ const client = getActiveClient();
42075
+ client.log('notificationTray/getNotificationTraySeen', {});
42076
+ const { data: payload } = await client.http.get(`api/v1/notification-tray/tray/seen`);
42077
+ const cachedAt = client.cache && Date.now();
42078
+ if (client.cache) {
42079
+ const cacheKey = ['notificationTraySeen', 'get', client.userId];
42080
+ pushToCache(cacheKey, {
42081
+ userId: client.userId,
42082
+ lastTraySeenAt: payload.lastTraySeenAt,
42083
+ lastTrayOccuredAt: payload.lastTrayOccurredAt,
42084
+ });
42085
+ }
42086
+ return {
42087
+ data: {
42088
+ userId: client.userId,
42089
+ lastTraySeenAt: payload.lastTraySeenAt,
42090
+ lastTrayOccurredAt: payload.lastTrayOccurredAt,
42091
+ isSeen: payload.lastTraySeenAt > payload.lastTrayOccurredAt,
42092
+ },
42093
+ cachedAt,
42094
+ };
42095
+ };
42096
+ /* end_public_function */
42097
+ /**
42098
+ * ```js
42099
+ * import { notificationTray } from '@amityco/ts-sdk'
42100
+ * const notificationTraySeen = await notificationTray.getNotificationTraySeen.locally()
42101
+ * ```
42102
+ *
42103
+ * Queries a paginable list of {@link Amity.NotificationTraySeen} objects from cache
42104
+ *
42105
+ * @returns A page of {@link Amity.NotificationTraySeen} objects
42106
+ *
42107
+ * @category NotificationTray API
42108
+ * @async
42109
+ * */
42110
+ getNotificationTraySeen$1.locally = () => {
42111
+ var _a;
42112
+ const client = getActiveClient();
42113
+ client.log('notificationTray/getNotificationTraySeen.locally', {});
42114
+ if (!client.cache)
42115
+ return;
42116
+ const queryKey = ['notificationTraySeen', 'get'];
42117
+ const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
42118
+ if (!data)
42119
+ return;
42120
+ return { data, cachedAt };
42121
+ };
42122
+
42123
+ /**
42124
+ * ```js
42125
+ * import { onNotificationTraySeenUpdated } from '@amityco/ts-sdk'
42126
+ * const dispose = onNotificationTraySeenUpdated(data => {
42127
+ * // ...
42128
+ * })
42129
+ * ```
42130
+ *
42131
+ * Fired when an {@link Amity.NotificationTraySeen} has been updated
42132
+ *
42133
+ * @param callback The function to call when the event was fired
42134
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
42135
+ *
42136
+ * @category NotificationTraySeen Events
42137
+ */
42138
+ const onNotificationTraySeenUpdated = (callback) => {
42139
+ const client = getActiveClient();
42140
+ const disposers = [
42141
+ createEventSubscriber(client, 'onNotificationTraySeenUpdated', 'local.notificationTraySeen.updated', payload => callback(payload)),
42142
+ ];
42143
+ return () => {
42144
+ disposers.forEach(fn => fn());
42145
+ };
42146
+ };
42147
+
42148
+ /* begin_public_function
42149
+ id: notificationTray.getNotificationTraySeen
42150
+ */
42151
+ /**
42152
+ * ```js
42153
+ * import { notificationTray } from '@amityco/ts-sdk';
42154
+ *
42155
+ * let notificationTraySeen;
42156
+ *
42157
+ * const unsubscribe = getNotificationTraySeen(response => {
42158
+ * notificationTraySeen = response.data;
42159
+ * });
42160
+ * ```
42161
+ *
42162
+ * Observe all mutation on a given {@link Amity.NotificationTraySeen}
42163
+ *
42164
+ * @param callback the function to call when new data are available
42165
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the message
42166
+ *
42167
+ * @category NotificationTraySeen Live Object
42168
+ */
42169
+ const getNotificationTraySeen = (callback) => {
42170
+ const { userId } = getActiveUser();
42171
+ return liveObject(userId, callback, 'userId', getNotificationTraySeen$1, [onNotificationTraySeenUpdated], {
42172
+ callbackDataSelector: (data) => {
42173
+ let isSeen = true;
42174
+ if (data === null || data === void 0 ? void 0 : data.lastTrayOccurredAt) {
42175
+ if (!data.lastTraySeenAt) {
42176
+ isSeen = false;
42177
+ }
42178
+ else {
42179
+ isSeen =
42180
+ convertDateStringToTimestamp(data.lastTraySeenAt) >
42181
+ convertDateStringToTimestamp(data.lastTrayOccurredAt);
42182
+ }
42183
+ }
42184
+ return {
42185
+ lastTrayOccurredAt: data === null || data === void 0 ? void 0 : data.lastTrayOccurredAt,
42186
+ lastTraySeenAt: data === null || data === void 0 ? void 0 : data.lastTraySeenAt,
42187
+ isSeen,
42188
+ };
42189
+ },
42190
+ });
42191
+ };
42192
+ /* end_public_function */
42193
+
42194
+ /**
42195
+ * TODO: handle cache receive cache option, and cache policy
42196
+ * TODO: check if querybyIds is supported
42197
+ */
42198
+ class NotificationTrayItemsPaginationController extends PaginationController {
42199
+ async getRequest(queryParams, token) {
42200
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
42201
+ const options = token ? { token } : { limit };
42202
+ const { data: queryResponse } = await this.http.get(`/api/v1/notification-tray`, {
42203
+ params: Object.assign(Object.assign({}, params), { options }),
42204
+ });
42205
+ return queryResponse;
42206
+ }
42207
+ }
42208
+
42209
+ class NotificationTrayItemsQuerystreamController extends QueryStreamController {
42210
+ constructor(query, cacheKey, notifyChange, preparePayload) {
42211
+ super(query, cacheKey);
42212
+ this.notifyChange = notifyChange;
42213
+ this.preparePayload = preparePayload;
42214
+ }
42215
+ async saveToMainDB(response) {
42216
+ const processedPayload = await this.preparePayload(response);
42217
+ const client = getActiveClient();
42218
+ const cachedAt = client.cache && Date.now();
42219
+ if (client.cache) {
42220
+ ingestInCache(processedPayload, { cachedAt });
42221
+ }
42222
+ }
42223
+ appendToQueryStream(response, direction, refresh = false) {
42224
+ var _a, _b;
42225
+ if (refresh) {
42226
+ pushToCache(this.cacheKey, {
42227
+ data: response.notificationTrayItems.map(getResolver('notificationTrayItem')),
42228
+ });
42229
+ }
42230
+ else {
42231
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
42232
+ const notifications = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
42233
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
42234
+ ...new Set([
42235
+ ...notifications,
42236
+ ...response.notificationTrayItems.map(getResolver('notificationTrayItem')),
42237
+ ]),
42238
+ ] }));
42239
+ }
42240
+ }
42241
+ }
42242
+
42243
+ const prepareNotificationTrayItemsPayload = (rawPayload) => {
42244
+ const users = rawPayload.users.map(convertRawUserToInternalUser);
42245
+ return Object.assign(Object.assign({}, rawPayload), { users });
42246
+ };
42247
+
42248
+ class NotificationTrayItemsLiveCollectionController extends LiveCollectionController {
42249
+ constructor(query, callback) {
42250
+ const queryStreamId = hash(query);
42251
+ const cacheKey = ['notificationTrayItem', 'collection', queryStreamId];
42252
+ const paginationController = new NotificationTrayItemsPaginationController(query);
42253
+ super(paginationController, queryStreamId, cacheKey, callback);
42254
+ this.query = query;
42255
+ this.queryStreamController = new NotificationTrayItemsQuerystreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareNotificationTrayItemsPayload);
42256
+ this.callback = callback.bind(this);
42257
+ this.loadPage({ initial: true });
42258
+ }
42259
+ setup() {
42260
+ var _a;
42261
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
42262
+ if (!collection) {
42263
+ pushToCache(this.cacheKey, {
42264
+ data: [],
42265
+ params: {},
42266
+ });
42267
+ }
42268
+ }
42269
+ async persistModel(queryPayload) {
42270
+ await this.queryStreamController.saveToMainDB(queryPayload);
42271
+ }
42272
+ persistQueryStream({ response, direction, refresh, }) {
42273
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
42274
+ }
42275
+ // eslint-disable-next-line class-methods-use-this
42276
+ startSubscription() {
42277
+ return [];
42278
+ }
42279
+ notifyChange({ origin, loading, error }) {
42280
+ var _a, _b;
42281
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
42282
+ if (!collection)
42283
+ return;
42284
+ const data = ((_b = collection.data
42285
+ .map(id => pullFromCache(['notificationTrayItem', 'get', id]))
42286
+ .filter(isNonNullable)
42287
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.notificationTray);
42288
+ if (!this.shouldNotify(data) && origin === 'event')
42289
+ return;
42290
+ this.callback({
42291
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
42292
+ data,
42293
+ hasNextPage: !!this.paginationController.getNextToken(),
42294
+ loading,
42295
+ error,
42296
+ });
42297
+ }
42298
+ }
42299
+
42300
+ /**
42301
+ * Get notification tray items for a notification tray page
42302
+ *
42303
+ * @param params the limit query parameters
42304
+ * @param callback the callback to be called when the notification tray items are updated
42305
+ * @returns items in the notification tray
42306
+ *
42307
+ * @category Notification tray items Live Collection
42308
+ *
42309
+ */
42310
+ const getNotificationTrayItems = (params, callback, config) => {
42311
+ const { log, cache } = getActiveClient();
42312
+ if (!cache) {
42313
+ console.log(ENABLE_CACHE_MESSAGE);
42314
+ }
42315
+ const timestamp = Date.now();
42316
+ log(`getNotificationTrayItems(tmpid: ${timestamp}) > listen`);
42317
+ const notiTrayItemsLiveCollection = new NotificationTrayItemsLiveCollectionController(params, callback);
42318
+ const disposers = notiTrayItemsLiveCollection.startSubscription();
42319
+ const cacheKey = notiTrayItemsLiveCollection.getCacheKey();
42320
+ disposers.push(() => dropFromCache(cacheKey));
42321
+ return () => {
42322
+ log(`getNotificationTrayItems(tmpid: ${timestamp}) > dispose`);
42323
+ disposers.forEach(fn => fn());
42324
+ };
42325
+ };
42326
+
42327
+ /* begin_public_function
42328
+ id: notificationTrayItem.markSeen
42329
+ */
42330
+ /**
42331
+ * ```js
42332
+ * import { notificationTray } from '@amityco/ts-sdk'
42333
+ * const updated = await notificationTray.markItemsSeen()
42334
+ * ```
42335
+ *
42336
+ * Updates an {@link Amity.NotificationItemSeen}
42337
+ *
42338
+ * @param trayItems[] that include id and lastTraySeenAt, The ID of the {@link Amity.NotificationItemSeen} to edit
42339
+ * @returns the updated {@link Amity.NotificationItemSeen} object
42340
+ *
42341
+ * @category NotificationItemSeen API
42342
+ * @async
42343
+ */
42344
+ const markItemsSeen = async (trayItems) => {
42345
+ const client = getActiveClient();
42346
+ client.log('notificationTray/markItemsSeen', {});
42347
+ const { data: payload } = await client.http.post(`api/v1/notification-tray/items/seen`, {
42348
+ trayItems: trayItems.map(item => ({
42349
+ id: item.id,
42350
+ lastSeenAt: item.lastSeenAt,
42351
+ })),
42352
+ });
42353
+ const updatedData = trayItems
42354
+ .map(patchItem => {
42355
+ var _a;
42356
+ const cacheData = (_a = pullFromCache([
42357
+ 'notificationTrayItem',
42358
+ 'get',
42359
+ patchItem.id,
42360
+ ])) === null || _a === void 0 ? void 0 : _a.data;
42361
+ if (!cacheData)
42362
+ return;
42363
+ const data = Object.assign(Object.assign({}, cacheData), payload);
42364
+ if (client.cache) {
42365
+ const cachedAt = Date.now();
42366
+ pushToCache(['notificationTrayItem', 'get'], data, { cachedAt });
42367
+ }
42368
+ return data;
42369
+ })
42370
+ .filter(Boolean);
42371
+ fireEvent('local.notificationTrayItem.updated', { notificationTrayItems: updatedData });
42372
+ };
42373
+ /* end_public_function */
42374
+
42375
+ /* begin_public_function
42376
+ id: notificationTray.markSeen
42377
+ */
42378
+ /**
42379
+ * ```js
42380
+ * import { notificationTray } from '@amityco/ts-sdk'
42381
+ * const updated = await notificationTray.markTraySeen({
42382
+ * lastSeenAt: Amity.timestamp,
42383
+ * })
42384
+ * ```
42385
+ *
42386
+ * Updates an {@link Amity.NotificationTraySeen}
42387
+ *
42388
+ * @param userId The ID of the {@link Amity.NotificationTraySeen} to edit
42389
+ * @param lastSeenAt The patch data to apply
42390
+ * @returns the updated {@link Amity.NotificationTraySeen} object
42391
+ *
42392
+ * @category Post API
42393
+ * @async
42394
+ */
42395
+ const markTraySeen = async (lastSeenAt) => {
42396
+ var _a;
42397
+ const client = getActiveClient();
42398
+ client.log('notificationTray/markTraySeen', {});
42399
+ const { data: payload } = await client.http.post(`api/v1/notification-tray/tray/seen`, {
42400
+ lastSeenAt,
42401
+ });
42402
+ const cacheData = (_a = pullFromCache([
42403
+ 'notificationTraySeen',
42404
+ 'get',
42405
+ ])) === null || _a === void 0 ? void 0 : _a.data;
42406
+ const data = {
42407
+ userId: client.userId,
42408
+ lastTraySeenAt: payload.lastSeenAt,
42409
+ };
42410
+ const updateCacheData = Object.assign(Object.assign({}, cacheData), data);
42411
+ const cachedAt = client.cache && Date.now();
42412
+ if (client.cache)
42413
+ pushToCache(['notificationTraySeen', 'get', client.userId], updateCacheData, { cachedAt });
42414
+ fireEvent('local.notificationTraySeen.updated', data);
42415
+ return {
42416
+ data: payload,
42417
+ cachedAt,
42418
+ };
42419
+ };
42420
+ /* end_public_function */
42421
+
42422
+ var index = /*#__PURE__*/Object.freeze({
42423
+ __proto__: null,
42424
+ getNotificationTraySeen: getNotificationTraySeen,
42425
+ getNotificationTrayItems: getNotificationTrayItems,
42426
+ markItemsSeen: markItemsSeen,
42427
+ markTraySeen: markTraySeen,
42428
+ onNotificationTraySeenUpdated: onNotificationTraySeenUpdated
42429
+ });
42430
+
42431
+ export { API_REGIONS, index$1 as AdRepository, index$9 as CategoryRepository, index$d as ChannelRepository, index$m as Client, index$7 as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$a as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, index$8 as FeedRepository, FileAccessTypeEnum, index$j as FileRepository, FileType, index$3 as LiveStreamPlayer, MessageContentType, index$h as MessageRepository, index$4 as PollRepository, PostContentType, index$6 as PostRepository, index$i as ReactionRepository, index$2 as StoryRepository, index$5 as StreamRepository, index$g as SubChannelRepository, SubscriptionLevels, index$k as UserRepository, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };