@amityco/ts-sdk 7.2.1-56aa34e.0 → 7.2.1-e149502.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.
- package/dist/@types/core/events.d.ts +4 -0
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/model.d.ts +4 -0
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +24 -0
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/notification.d.ts +78 -0
- package/dist/@types/domains/notification.d.ts.map +1 -0
- package/dist/@types/index.d.ts +1 -0
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.d.ts.map +1 -1
- package/dist/core/model/idResolvers.d.ts.map +1 -1
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/index.cjs.js +431 -44
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +414 -28
- package/dist/index.umd.js +4 -4
- package/dist/notificationTray/api/index.d.ts +3 -0
- package/dist/notificationTray/api/index.d.ts.map +1 -0
- package/dist/notificationTray/api/markItemsSeen.d.ts +16 -0
- package/dist/notificationTray/api/markItemsSeen.d.ts.map +1 -0
- package/dist/notificationTray/api/markTraySeen.d.ts +19 -0
- package/dist/notificationTray/api/markTraySeen.d.ts.map +1 -0
- package/dist/notificationTray/events/index.d.ts +2 -0
- package/dist/notificationTray/events/index.d.ts.map +1 -0
- package/dist/notificationTray/events/onNotificationTraySeenUpdated.d.ts +17 -0
- package/dist/notificationTray/events/onNotificationTraySeenUpdated.d.ts.map +1 -0
- package/dist/notificationTray/index.d.ts +4 -0
- package/dist/notificationTray/index.d.ts.map +1 -0
- package/dist/notificationTray/internalApi/getNotificationTraySeen.d.ts +30 -0
- package/dist/notificationTray/internalApi/getNotificationTraySeen.d.ts.map +1 -0
- package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.d.ts +13 -0
- package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.d.ts.map +1 -0
- package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.d.ts +9 -0
- package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.d.ts.map +1 -0
- package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.d.ts +9 -0
- package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.d.ts.map +1 -0
- package/dist/notificationTray/observers/getNotificationTrayItems.d.ts +12 -0
- package/dist/notificationTray/observers/getNotificationTrayItems.d.ts.map +1 -0
- package/dist/notificationTray/observers/getNotificationTraySeen.d.ts +20 -0
- package/dist/notificationTray/observers/getNotificationTraySeen.d.ts.map +1 -0
- package/dist/notificationTray/observers/index.d.ts +3 -0
- package/dist/notificationTray/observers/index.d.ts.map +1 -0
- package/dist/notificationTray/utils/prepareNotificationTrayItemsPayload.d.ts +2 -0
- package/dist/notificationTray/utils/prepareNotificationTrayItemsPayload.d.ts.map +1 -0
- package/dist/utils/linkedObject/index.d.ts +1 -0
- package/dist/utils/linkedObject/index.d.ts.map +1 -1
- package/dist/utils/linkedObject/notificationTrayLinkedObject.d.ts +2 -0
- package/dist/utils/linkedObject/notificationTrayLinkedObject.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/@types/core/events.ts +5 -0
- package/src/@types/core/model.ts +6 -0
- package/src/@types/core/payload.ts +29 -0
- package/src/@types/domains/notification.ts +94 -0
- package/src/@types/index.ts +1 -0
- package/src/core/model/idResolvers.ts +3 -0
- package/src/core/model/index.ts +2 -0
- package/src/index.ts +2 -0
- package/src/notificationTray/api/index.ts +2 -0
- package/src/notificationTray/api/markItemsSeen.ts +62 -0
- package/src/notificationTray/api/markTraySeen.ts +65 -0
- package/src/notificationTray/events/index.ts +1 -0
- package/src/notificationTray/events/onNotificationTraySeenUpdated.ts +36 -0
- package/src/notificationTray/index.ts +3 -0
- package/src/notificationTray/internalApi/getNotificationTraySeen.ts +80 -0
- package/src/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.ts +96 -0
- package/src/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.ts +31 -0
- package/src/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.ts +68 -0
- package/src/notificationTray/observers/getNotificationTrayItems.ts +44 -0
- package/src/notificationTray/observers/getNotificationTraySeen.ts +60 -0
- package/src/notificationTray/observers/index.ts +2 -0
- package/src/notificationTray/utils/prepareNotificationTrayItemsPayload.ts +12 -0
- package/src/utils/linkedObject/index.ts +2 -0
- package/src/utils/linkedObject/notificationTrayLinkedObject.ts +19 -0
package/dist/index.esm.js
CHANGED
|
@@ -106,6 +106,7 @@ const SECOND$1 = 1000;
|
|
|
106
106
|
const MINUTE = 60 * SECOND$1;
|
|
107
107
|
const HOUR = 60 * MINUTE;
|
|
108
108
|
const DAY = 24 * HOUR;
|
|
109
|
+
const WEEK = 7 * DAY;
|
|
109
110
|
const YEAR = 365 * DAY;
|
|
110
111
|
const ACCESS_TOKEN_WATCHER_INTERVAL = 10 * MINUTE;
|
|
111
112
|
|
|
@@ -528,6 +529,8 @@ const idResolvers = {
|
|
|
528
529
|
advertiser: ({ advertiserId }) => advertiserId,
|
|
529
530
|
pin: ({ placement, referenceId }) => `${placement}#${referenceId}`,
|
|
530
531
|
pinTarget: ({ targetId }) => targetId,
|
|
532
|
+
notificationTrayItem: ({ _id }) => _id,
|
|
533
|
+
notificationTraySeen: ({ userId }) => userId,
|
|
531
534
|
};
|
|
532
535
|
/**
|
|
533
536
|
* Retrieve the id resolver matching a domain name
|
|
@@ -579,6 +582,7 @@ const PAYLOAD2MODEL = {
|
|
|
579
582
|
advertisers: 'advertiser',
|
|
580
583
|
pinTargets: 'pinTarget',
|
|
581
584
|
pins: 'pin',
|
|
585
|
+
notificationTrayItems: 'notificationTrayItem',
|
|
582
586
|
};
|
|
583
587
|
/** hidden */
|
|
584
588
|
const isOutdated = (prevData, nextData) => {
|
|
@@ -22313,6 +22317,14 @@ const pinnedPostLinkedObject = (pinnedPost) => {
|
|
|
22313
22317
|
} });
|
|
22314
22318
|
};
|
|
22315
22319
|
|
|
22320
|
+
const notificationTrayLinkedObject = (noti) => {
|
|
22321
|
+
return Object.assign(Object.assign({}, noti), { isSeen: noti.lastSeenAt > noti.lastOccurredAt, isRecent: new Date(noti.lastOccurredAt).getTime() >= Date.now() - WEEK, users: noti.actors
|
|
22322
|
+
.map(({ _id }) => pullFromCache(['user', 'get', _id]))
|
|
22323
|
+
.filter(isNonNullable)
|
|
22324
|
+
.map(({ data }) => data)
|
|
22325
|
+
.map(user => userLinkedObject(user)) });
|
|
22326
|
+
};
|
|
22327
|
+
|
|
22316
22328
|
const LinkedObject = {
|
|
22317
22329
|
ad: adLinkedObject,
|
|
22318
22330
|
comment: commentLinkedObject,
|
|
@@ -22326,6 +22338,7 @@ const LinkedObject = {
|
|
|
22326
22338
|
reactor: reactorLinkedObject,
|
|
22327
22339
|
channel: channelLinkedObject,
|
|
22328
22340
|
pinnedPost: pinnedPostLinkedObject,
|
|
22341
|
+
notificationTray: notificationTrayLinkedObject,
|
|
22329
22342
|
};
|
|
22330
22343
|
|
|
22331
22344
|
const getChannelMessagePreviewWithUser = (channel) => {
|
|
@@ -26227,7 +26240,7 @@ const getUserUnread = (callback) => {
|
|
|
26227
26240
|
};
|
|
26228
26241
|
};
|
|
26229
26242
|
|
|
26230
|
-
var index$
|
|
26243
|
+
var index$m = /*#__PURE__*/Object.freeze({
|
|
26231
26244
|
__proto__: null,
|
|
26232
26245
|
getActiveClient: getActiveClient,
|
|
26233
26246
|
getActiveUser: getActiveUser,
|
|
@@ -27434,7 +27447,7 @@ const getMyFollowInfo = (callback) => {
|
|
|
27434
27447
|
};
|
|
27435
27448
|
/* end_public_function */
|
|
27436
27449
|
|
|
27437
|
-
var index$
|
|
27450
|
+
var index$l = /*#__PURE__*/Object.freeze({
|
|
27438
27451
|
__proto__: null,
|
|
27439
27452
|
blockUser: blockUser,
|
|
27440
27453
|
unBlockUser: unBlockUser,
|
|
@@ -28449,9 +28462,9 @@ var AmityUserSearchMatchType;
|
|
|
28449
28462
|
AmityUserSearchMatchType["PARTIAL"] = "partial";
|
|
28450
28463
|
})(AmityUserSearchMatchType || (AmityUserSearchMatchType = {}));
|
|
28451
28464
|
|
|
28452
|
-
var index$
|
|
28465
|
+
var index$k = /*#__PURE__*/Object.freeze({
|
|
28453
28466
|
__proto__: null,
|
|
28454
|
-
Relationship: index$
|
|
28467
|
+
Relationship: index$l,
|
|
28455
28468
|
getUserByIds: getUserByIds,
|
|
28456
28469
|
updateUser: updateUser,
|
|
28457
28470
|
flagUser: flagUser,
|
|
@@ -28715,7 +28728,7 @@ const uploadImage = async (formData, onProgress) => {
|
|
|
28715
28728
|
};
|
|
28716
28729
|
/* end_public_function */
|
|
28717
28730
|
|
|
28718
|
-
var index$
|
|
28731
|
+
var index$j = /*#__PURE__*/Object.freeze({
|
|
28719
28732
|
__proto__: null,
|
|
28720
28733
|
getFile: getFile,
|
|
28721
28734
|
uploadFile: uploadFile,
|
|
@@ -30582,7 +30595,7 @@ const getReactions = (params, callback, config) => {
|
|
|
30582
30595
|
};
|
|
30583
30596
|
/* end_public_function */
|
|
30584
30597
|
|
|
30585
|
-
var index$
|
|
30598
|
+
var index$i = /*#__PURE__*/Object.freeze({
|
|
30586
30599
|
__proto__: null,
|
|
30587
30600
|
addReaction: addReaction,
|
|
30588
30601
|
removeReaction: removeReaction,
|
|
@@ -32398,7 +32411,7 @@ const getMessages = (params, callback, config) => {
|
|
|
32398
32411
|
};
|
|
32399
32412
|
/* end_public_function */
|
|
32400
32413
|
|
|
32401
|
-
var index$
|
|
32414
|
+
var index$h = /*#__PURE__*/Object.freeze({
|
|
32402
32415
|
__proto__: null,
|
|
32403
32416
|
createMessage: createMessage,
|
|
32404
32417
|
updateMessage: updateMessage,
|
|
@@ -32924,7 +32937,7 @@ const stopMessageReceiptSync = (subChannelId) => {
|
|
|
32924
32937
|
};
|
|
32925
32938
|
/* end_public_function */
|
|
32926
32939
|
|
|
32927
|
-
var index$
|
|
32940
|
+
var index$g = /*#__PURE__*/Object.freeze({
|
|
32928
32941
|
__proto__: null,
|
|
32929
32942
|
getSubChannelByIds: getSubChannels$1,
|
|
32930
32943
|
createSubChannel: createSubChannel,
|
|
@@ -34238,7 +34251,7 @@ const searchMembers$1 = (params, callback, config) => {
|
|
|
34238
34251
|
};
|
|
34239
34252
|
/* end_public_function */
|
|
34240
34253
|
|
|
34241
|
-
var index$
|
|
34254
|
+
var index$f = /*#__PURE__*/Object.freeze({
|
|
34242
34255
|
__proto__: null,
|
|
34243
34256
|
addMembers: addMembers$1,
|
|
34244
34257
|
removeMembers: removeMembers$1,
|
|
@@ -34441,7 +34454,7 @@ const unmuteMembers = async (channelId, userIds) => {
|
|
|
34441
34454
|
};
|
|
34442
34455
|
/* end_public_function */
|
|
34443
34456
|
|
|
34444
|
-
var index$
|
|
34457
|
+
var index$e = /*#__PURE__*/Object.freeze({
|
|
34445
34458
|
__proto__: null,
|
|
34446
34459
|
addRole: addRole,
|
|
34447
34460
|
removeRole: removeRole,
|
|
@@ -34451,10 +34464,10 @@ var index$d = /*#__PURE__*/Object.freeze({
|
|
|
34451
34464
|
unmuteMembers: unmuteMembers
|
|
34452
34465
|
});
|
|
34453
34466
|
|
|
34454
|
-
var index$
|
|
34467
|
+
var index$d = /*#__PURE__*/Object.freeze({
|
|
34455
34468
|
__proto__: null,
|
|
34456
|
-
Membership: index$
|
|
34457
|
-
Moderation: index$
|
|
34469
|
+
Membership: index$f,
|
|
34470
|
+
Moderation: index$e,
|
|
34458
34471
|
getChannelByIds: getChannelByIds$1,
|
|
34459
34472
|
createChannel: createChannel,
|
|
34460
34473
|
updateChannel: updateChannel,
|
|
@@ -35834,7 +35847,7 @@ const searchMembers = (params, callback, config) => {
|
|
|
35834
35847
|
};
|
|
35835
35848
|
/* end_public_function */
|
|
35836
35849
|
|
|
35837
|
-
var index$
|
|
35850
|
+
var index$c = /*#__PURE__*/Object.freeze({
|
|
35838
35851
|
__proto__: null,
|
|
35839
35852
|
addMembers: addMembers,
|
|
35840
35853
|
removeMembers: removeMembers,
|
|
@@ -36859,7 +36872,7 @@ const unbanMembers = async (communityId, userIds) => {
|
|
|
36859
36872
|
};
|
|
36860
36873
|
/* end_public_function */
|
|
36861
36874
|
|
|
36862
|
-
var index$
|
|
36875
|
+
var index$b = /*#__PURE__*/Object.freeze({
|
|
36863
36876
|
__proto__: null,
|
|
36864
36877
|
addRoles: addRoles,
|
|
36865
36878
|
removeRoles: removeRoles,
|
|
@@ -36867,10 +36880,10 @@ var index$a = /*#__PURE__*/Object.freeze({
|
|
|
36867
36880
|
unbanMembers: unbanMembers
|
|
36868
36881
|
});
|
|
36869
36882
|
|
|
36870
|
-
var index$
|
|
36883
|
+
var index$a = /*#__PURE__*/Object.freeze({
|
|
36871
36884
|
__proto__: null,
|
|
36872
|
-
Moderation: index$
|
|
36873
|
-
Membership: index$
|
|
36885
|
+
Moderation: index$b,
|
|
36886
|
+
Membership: index$c,
|
|
36874
36887
|
getCommunityByIds: getCommunities$1,
|
|
36875
36888
|
createCommunity: createCommunity,
|
|
36876
36889
|
updateCommunity: updateCommunity,
|
|
@@ -37103,7 +37116,7 @@ const getCategories = (params, callback, config) => {
|
|
|
37103
37116
|
};
|
|
37104
37117
|
/* end_public_function */
|
|
37105
37118
|
|
|
37106
|
-
var index$
|
|
37119
|
+
var index$9 = /*#__PURE__*/Object.freeze({
|
|
37107
37120
|
__proto__: null,
|
|
37108
37121
|
getCategory: getCategory,
|
|
37109
37122
|
getCategories: getCategories
|
|
@@ -37271,7 +37284,7 @@ getCustomRankingGlobalFeed.locally = (query) => {
|
|
|
37271
37284
|
: undefined;
|
|
37272
37285
|
};
|
|
37273
37286
|
|
|
37274
|
-
var index$
|
|
37287
|
+
var index$8 = /*#__PURE__*/Object.freeze({
|
|
37275
37288
|
__proto__: null,
|
|
37276
37289
|
queryGlobalFeed: queryGlobalFeed,
|
|
37277
37290
|
getCustomRankingGlobalFeed: getCustomRankingGlobalFeed
|
|
@@ -38586,7 +38599,7 @@ const getComments = (params, callback, config) => {
|
|
|
38586
38599
|
};
|
|
38587
38600
|
/* end_public_function */
|
|
38588
38601
|
|
|
38589
|
-
var index$
|
|
38602
|
+
var index$7 = /*#__PURE__*/Object.freeze({
|
|
38590
38603
|
__proto__: null,
|
|
38591
38604
|
getCommentByIds: getCommentByIds,
|
|
38592
38605
|
createComment: createComment,
|
|
@@ -39593,7 +39606,7 @@ const semanticSearchPosts = (params, callback, config) => {
|
|
|
39593
39606
|
};
|
|
39594
39607
|
};
|
|
39595
39608
|
|
|
39596
|
-
var index$
|
|
39609
|
+
var index$6 = /*#__PURE__*/Object.freeze({
|
|
39597
39610
|
__proto__: null,
|
|
39598
39611
|
getPostByIds: getPostByIds,
|
|
39599
39612
|
createPost: createPost,
|
|
@@ -40127,7 +40140,7 @@ const getStreams = (params, callback, config) => {
|
|
|
40127
40140
|
};
|
|
40128
40141
|
};
|
|
40129
40142
|
|
|
40130
|
-
var index$
|
|
40143
|
+
var index$5 = /*#__PURE__*/Object.freeze({
|
|
40131
40144
|
__proto__: null,
|
|
40132
40145
|
createStream: createStream,
|
|
40133
40146
|
updateStream: updateStream,
|
|
@@ -40414,7 +40427,7 @@ const getPoll = (pollId, callback) => {
|
|
|
40414
40427
|
};
|
|
40415
40428
|
/* end_public_function */
|
|
40416
40429
|
|
|
40417
|
-
var index$
|
|
40430
|
+
var index$4 = /*#__PURE__*/Object.freeze({
|
|
40418
40431
|
__proto__: null,
|
|
40419
40432
|
createPoll: createPoll,
|
|
40420
40433
|
closePoll: closePoll,
|
|
@@ -40785,7 +40798,7 @@ const getPlayer = async (parameters) => {
|
|
|
40785
40798
|
return video;
|
|
40786
40799
|
};
|
|
40787
40800
|
|
|
40788
|
-
var index$
|
|
40801
|
+
var index$3 = /*#__PURE__*/Object.freeze({
|
|
40789
40802
|
__proto__: null,
|
|
40790
40803
|
getPlayer: getPlayer
|
|
40791
40804
|
});
|
|
@@ -41958,7 +41971,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
|
|
|
41958
41971
|
};
|
|
41959
41972
|
};
|
|
41960
41973
|
|
|
41961
|
-
var index$
|
|
41974
|
+
var index$2 = /*#__PURE__*/Object.freeze({
|
|
41962
41975
|
__proto__: null,
|
|
41963
41976
|
createImageStory: createImageStory,
|
|
41964
41977
|
createVideoStory: createVideoStory,
|
|
@@ -41995,7 +42008,7 @@ const getNetworkAds = async () => {
|
|
|
41995
42008
|
};
|
|
41996
42009
|
};
|
|
41997
42010
|
|
|
41998
|
-
var index = /*#__PURE__*/Object.freeze({
|
|
42011
|
+
var index$1 = /*#__PURE__*/Object.freeze({
|
|
41999
42012
|
__proto__: null,
|
|
42000
42013
|
getNetworkAds: getNetworkAds
|
|
42001
42014
|
});
|
|
@@ -42022,4 +42035,377 @@ const createUserToken = async (apiKey, apiRegion, params) => {
|
|
|
42022
42035
|
return { accessToken: data.accessToken };
|
|
42023
42036
|
};
|
|
42024
42037
|
|
|
42025
|
-
|
|
42038
|
+
/* begin_public_function
|
|
42039
|
+
id: notificationTray.getNotificationTraySeen
|
|
42040
|
+
*/
|
|
42041
|
+
/**
|
|
42042
|
+
* ```js
|
|
42043
|
+
* import { notificationTray } from '@amityco/ts-sdk'
|
|
42044
|
+
* const notificationTraySeen = await notificationTray.getNotificationTraySeen()
|
|
42045
|
+
* ```
|
|
42046
|
+
*
|
|
42047
|
+
*
|
|
42048
|
+
* @returns A page of {@link Amity.NotificationTraySeen} objects
|
|
42049
|
+
*
|
|
42050
|
+
* @category NotificationTray API
|
|
42051
|
+
* @async
|
|
42052
|
+
* */
|
|
42053
|
+
const getNotificationTraySeen$1 = async () => {
|
|
42054
|
+
const client = getActiveClient();
|
|
42055
|
+
client.log('notificationTray/getNotificationTraySeen', {});
|
|
42056
|
+
const { data: payload } = await client.http.get(`api/v1/notification-tray/tray/seen`);
|
|
42057
|
+
const cachedAt = client.cache && Date.now();
|
|
42058
|
+
if (client.cache) {
|
|
42059
|
+
const cacheKey = ['notificationTraySeen', 'get', client.userId];
|
|
42060
|
+
pushToCache(cacheKey, {
|
|
42061
|
+
userId: client.userId,
|
|
42062
|
+
lastTraySeenAt: payload.lastTraySeenAt,
|
|
42063
|
+
lastTrayOccuredAt: payload.lastTrayOccurredAt,
|
|
42064
|
+
});
|
|
42065
|
+
}
|
|
42066
|
+
return {
|
|
42067
|
+
data: {
|
|
42068
|
+
userId: client.userId,
|
|
42069
|
+
lastTraySeenAt: payload.lastTraySeenAt,
|
|
42070
|
+
lastTrayOccurredAt: payload.lastTrayOccurredAt,
|
|
42071
|
+
isSeen: payload.lastTraySeenAt > payload.lastTrayOccurredAt,
|
|
42072
|
+
},
|
|
42073
|
+
cachedAt,
|
|
42074
|
+
};
|
|
42075
|
+
};
|
|
42076
|
+
/* end_public_function */
|
|
42077
|
+
/**
|
|
42078
|
+
* ```js
|
|
42079
|
+
* import { notificationTray } from '@amityco/ts-sdk'
|
|
42080
|
+
* const notificationTraySeen = await notificationTray.getNotificationTraySeen.locally()
|
|
42081
|
+
* ```
|
|
42082
|
+
*
|
|
42083
|
+
* Queries a paginable list of {@link Amity.NotificationTraySeen} objects from cache
|
|
42084
|
+
*
|
|
42085
|
+
* @returns A page of {@link Amity.NotificationTraySeen} objects
|
|
42086
|
+
*
|
|
42087
|
+
* @category NotificationTray API
|
|
42088
|
+
* @async
|
|
42089
|
+
* */
|
|
42090
|
+
getNotificationTraySeen$1.locally = () => {
|
|
42091
|
+
var _a;
|
|
42092
|
+
const client = getActiveClient();
|
|
42093
|
+
client.log('notificationTray/getNotificationTraySeen.locally', {});
|
|
42094
|
+
if (!client.cache)
|
|
42095
|
+
return;
|
|
42096
|
+
const queryKey = ['notificationTraySeen', 'get'];
|
|
42097
|
+
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
42098
|
+
if (!data)
|
|
42099
|
+
return;
|
|
42100
|
+
return { data, cachedAt };
|
|
42101
|
+
};
|
|
42102
|
+
|
|
42103
|
+
/**
|
|
42104
|
+
* ```js
|
|
42105
|
+
* import { onNotificationTraySeenUpdated } from '@amityco/ts-sdk'
|
|
42106
|
+
* const dispose = onNotificationTraySeenUpdated(data => {
|
|
42107
|
+
* // ...
|
|
42108
|
+
* })
|
|
42109
|
+
* ```
|
|
42110
|
+
*
|
|
42111
|
+
* Fired when an {@link Amity.NotificationTraySeen} has been updated
|
|
42112
|
+
*
|
|
42113
|
+
* @param callback The function to call when the event was fired
|
|
42114
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
42115
|
+
*
|
|
42116
|
+
* @category NotificationTraySeen Events
|
|
42117
|
+
*/
|
|
42118
|
+
const onNotificationTraySeenUpdated = (callback) => {
|
|
42119
|
+
const client = getActiveClient();
|
|
42120
|
+
const disposers = [
|
|
42121
|
+
createEventSubscriber(client, 'onNotificationTraySeenUpdated', 'local.notificationTraySeen.updated', payload => callback(payload)),
|
|
42122
|
+
];
|
|
42123
|
+
return () => {
|
|
42124
|
+
disposers.forEach(fn => fn());
|
|
42125
|
+
};
|
|
42126
|
+
};
|
|
42127
|
+
|
|
42128
|
+
/* begin_public_function
|
|
42129
|
+
id: notificationTray.getNotificationTraySeen
|
|
42130
|
+
*/
|
|
42131
|
+
/**
|
|
42132
|
+
* ```js
|
|
42133
|
+
* import { notificationTray } from '@amityco/ts-sdk';
|
|
42134
|
+
*
|
|
42135
|
+
* let notificationTraySeen;
|
|
42136
|
+
*
|
|
42137
|
+
* const unsubscribe = getNotificationTraySeen(response => {
|
|
42138
|
+
* notificationTraySeen = response.data;
|
|
42139
|
+
* });
|
|
42140
|
+
* ```
|
|
42141
|
+
*
|
|
42142
|
+
* Observe all mutation on a given {@link Amity.NotificationTraySeen}
|
|
42143
|
+
*
|
|
42144
|
+
* @param callback the function to call when new data are available
|
|
42145
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the message
|
|
42146
|
+
*
|
|
42147
|
+
* @category NotificationTraySeen Live Object
|
|
42148
|
+
*/
|
|
42149
|
+
const getNotificationTraySeen = (callback) => {
|
|
42150
|
+
const { userId } = getActiveUser();
|
|
42151
|
+
return liveObject(userId, callback, 'userId', getNotificationTraySeen$1, [onNotificationTraySeenUpdated], {
|
|
42152
|
+
callbackDataSelector: (data) => {
|
|
42153
|
+
let isSeen = true;
|
|
42154
|
+
if (data === null || data === void 0 ? void 0 : data.lastTrayOccurredAt) {
|
|
42155
|
+
if (!data.lastTraySeenAt) {
|
|
42156
|
+
isSeen = false;
|
|
42157
|
+
}
|
|
42158
|
+
else {
|
|
42159
|
+
isSeen =
|
|
42160
|
+
convertDateStringToTimestamp(data.lastTraySeenAt) >
|
|
42161
|
+
convertDateStringToTimestamp(data.lastTrayOccurredAt);
|
|
42162
|
+
}
|
|
42163
|
+
}
|
|
42164
|
+
return {
|
|
42165
|
+
lastTrayOccurredAt: data === null || data === void 0 ? void 0 : data.lastTrayOccurredAt,
|
|
42166
|
+
lastTraySeenAt: data === null || data === void 0 ? void 0 : data.lastTraySeenAt,
|
|
42167
|
+
isSeen,
|
|
42168
|
+
};
|
|
42169
|
+
},
|
|
42170
|
+
});
|
|
42171
|
+
};
|
|
42172
|
+
/* end_public_function */
|
|
42173
|
+
|
|
42174
|
+
/**
|
|
42175
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
42176
|
+
* TODO: check if querybyIds is supported
|
|
42177
|
+
*/
|
|
42178
|
+
class NotificationTrayItemsPaginationController extends PaginationController {
|
|
42179
|
+
async getRequest(queryParams, token) {
|
|
42180
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
42181
|
+
const options = token ? { token } : { limit };
|
|
42182
|
+
const { data: queryResponse } = await this.http.get(`/api/v1/notification-tray`, {
|
|
42183
|
+
params: Object.assign(Object.assign({}, params), { options }),
|
|
42184
|
+
});
|
|
42185
|
+
return queryResponse;
|
|
42186
|
+
}
|
|
42187
|
+
}
|
|
42188
|
+
|
|
42189
|
+
class NotificationTrayItemsQuerystreamController extends QueryStreamController {
|
|
42190
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
42191
|
+
super(query, cacheKey);
|
|
42192
|
+
this.notifyChange = notifyChange;
|
|
42193
|
+
this.preparePayload = preparePayload;
|
|
42194
|
+
}
|
|
42195
|
+
async saveToMainDB(response) {
|
|
42196
|
+
const processedPayload = await this.preparePayload(response);
|
|
42197
|
+
const client = getActiveClient();
|
|
42198
|
+
const cachedAt = client.cache && Date.now();
|
|
42199
|
+
if (client.cache) {
|
|
42200
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
42201
|
+
}
|
|
42202
|
+
}
|
|
42203
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
42204
|
+
var _a, _b;
|
|
42205
|
+
if (refresh) {
|
|
42206
|
+
pushToCache(this.cacheKey, {
|
|
42207
|
+
data: response.notificationTrayItems.map(getResolver('notificationTrayItem')),
|
|
42208
|
+
});
|
|
42209
|
+
}
|
|
42210
|
+
else {
|
|
42211
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
42212
|
+
const notifications = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
42213
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
42214
|
+
...new Set([
|
|
42215
|
+
...notifications,
|
|
42216
|
+
...response.notificationTrayItems.map(getResolver('notificationTrayItem')),
|
|
42217
|
+
]),
|
|
42218
|
+
] }));
|
|
42219
|
+
}
|
|
42220
|
+
}
|
|
42221
|
+
}
|
|
42222
|
+
|
|
42223
|
+
const prepareNotificationTrayItemsPayload = (rawPayload) => {
|
|
42224
|
+
const users = rawPayload.users.map(convertRawUserToInternalUser);
|
|
42225
|
+
return Object.assign(Object.assign({}, rawPayload), { users });
|
|
42226
|
+
};
|
|
42227
|
+
|
|
42228
|
+
class NotificationTrayItemsLiveCollectionController extends LiveCollectionController {
|
|
42229
|
+
constructor(query, callback) {
|
|
42230
|
+
const queryStreamId = hash(query);
|
|
42231
|
+
const cacheKey = ['notificationTrayItem', 'collection', queryStreamId];
|
|
42232
|
+
const paginationController = new NotificationTrayItemsPaginationController(query);
|
|
42233
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
42234
|
+
this.query = query;
|
|
42235
|
+
this.queryStreamController = new NotificationTrayItemsQuerystreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareNotificationTrayItemsPayload);
|
|
42236
|
+
this.callback = callback.bind(this);
|
|
42237
|
+
this.loadPage({ initial: true });
|
|
42238
|
+
}
|
|
42239
|
+
setup() {
|
|
42240
|
+
var _a;
|
|
42241
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
42242
|
+
if (!collection) {
|
|
42243
|
+
pushToCache(this.cacheKey, {
|
|
42244
|
+
data: [],
|
|
42245
|
+
params: {},
|
|
42246
|
+
});
|
|
42247
|
+
}
|
|
42248
|
+
}
|
|
42249
|
+
async persistModel(queryPayload) {
|
|
42250
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
42251
|
+
}
|
|
42252
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
42253
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
42254
|
+
}
|
|
42255
|
+
// eslint-disable-next-line class-methods-use-this
|
|
42256
|
+
startSubscription() {
|
|
42257
|
+
return [];
|
|
42258
|
+
}
|
|
42259
|
+
notifyChange({ origin, loading, error }) {
|
|
42260
|
+
var _a, _b;
|
|
42261
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
42262
|
+
if (!collection)
|
|
42263
|
+
return;
|
|
42264
|
+
const data = ((_b = collection.data
|
|
42265
|
+
.map(id => pullFromCache(['notificationTrayItem', 'get', id]))
|
|
42266
|
+
.filter(isNonNullable)
|
|
42267
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.notificationTray);
|
|
42268
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
42269
|
+
return;
|
|
42270
|
+
this.callback({
|
|
42271
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
42272
|
+
data,
|
|
42273
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
42274
|
+
loading,
|
|
42275
|
+
error,
|
|
42276
|
+
});
|
|
42277
|
+
}
|
|
42278
|
+
}
|
|
42279
|
+
|
|
42280
|
+
/**
|
|
42281
|
+
* Get notification tray items for a notification tray page
|
|
42282
|
+
*
|
|
42283
|
+
* @param params the limit query parameters
|
|
42284
|
+
* @param callback the callback to be called when the notification tray items are updated
|
|
42285
|
+
* @returns items in the notification tray
|
|
42286
|
+
*
|
|
42287
|
+
* @category Notification tray items Live Collection
|
|
42288
|
+
*
|
|
42289
|
+
*/
|
|
42290
|
+
const getNotificationTrayItems = (params, callback, config) => {
|
|
42291
|
+
const { log, cache } = getActiveClient();
|
|
42292
|
+
if (!cache) {
|
|
42293
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
42294
|
+
}
|
|
42295
|
+
const timestamp = Date.now();
|
|
42296
|
+
log(`getNotificationTrayItems(tmpid: ${timestamp}) > listen`);
|
|
42297
|
+
const notiTrayItemsLiveCollection = new NotificationTrayItemsLiveCollectionController(params, callback);
|
|
42298
|
+
const disposers = notiTrayItemsLiveCollection.startSubscription();
|
|
42299
|
+
const cacheKey = notiTrayItemsLiveCollection.getCacheKey();
|
|
42300
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
42301
|
+
return () => {
|
|
42302
|
+
log(`getNotificationTrayItems(tmpid: ${timestamp}) > dispose`);
|
|
42303
|
+
disposers.forEach(fn => fn());
|
|
42304
|
+
};
|
|
42305
|
+
};
|
|
42306
|
+
|
|
42307
|
+
/* begin_public_function
|
|
42308
|
+
id: notificationTrayItem.markSeen
|
|
42309
|
+
*/
|
|
42310
|
+
/**
|
|
42311
|
+
* ```js
|
|
42312
|
+
* import { notificationTray } from '@amityco/ts-sdk'
|
|
42313
|
+
* const updated = await notificationTray.markItemsSeen()
|
|
42314
|
+
* ```
|
|
42315
|
+
*
|
|
42316
|
+
* Updates an {@link Amity.NotificationItemSeen}
|
|
42317
|
+
*
|
|
42318
|
+
* @param trayItems[] that include id and lastTraySeenAt, The ID of the {@link Amity.NotificationItemSeen} to edit
|
|
42319
|
+
* @returns the updated {@link Amity.NotificationItemSeen} object
|
|
42320
|
+
*
|
|
42321
|
+
* @category NotificationItemSeen API
|
|
42322
|
+
* @async
|
|
42323
|
+
*/
|
|
42324
|
+
const markItemsSeen = async (trayItems) => {
|
|
42325
|
+
const client = getActiveClient();
|
|
42326
|
+
client.log('notificationTray/markItemsSeen', {});
|
|
42327
|
+
const { data: payload } = await client.http.post(`api/v1/notification-tray/items/seen`, {
|
|
42328
|
+
trayItems: trayItems.map(item => ({
|
|
42329
|
+
id: item.id,
|
|
42330
|
+
lastSeenAt: item.lastSeenAt,
|
|
42331
|
+
})),
|
|
42332
|
+
});
|
|
42333
|
+
const updatedData = trayItems
|
|
42334
|
+
.map(patchItem => {
|
|
42335
|
+
var _a;
|
|
42336
|
+
const cacheData = (_a = pullFromCache([
|
|
42337
|
+
'notificationTrayItem',
|
|
42338
|
+
'get',
|
|
42339
|
+
patchItem.id,
|
|
42340
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
42341
|
+
if (!cacheData)
|
|
42342
|
+
return;
|
|
42343
|
+
const data = Object.assign(Object.assign({}, cacheData), payload);
|
|
42344
|
+
if (client.cache) {
|
|
42345
|
+
const cachedAt = Date.now();
|
|
42346
|
+
pushToCache(['notificationTrayItem', 'get'], data, { cachedAt });
|
|
42347
|
+
}
|
|
42348
|
+
return data;
|
|
42349
|
+
})
|
|
42350
|
+
.filter(Boolean);
|
|
42351
|
+
fireEvent('local.notificationTrayItem.updated', { notificationTrayItems: updatedData });
|
|
42352
|
+
};
|
|
42353
|
+
/* end_public_function */
|
|
42354
|
+
|
|
42355
|
+
/* begin_public_function
|
|
42356
|
+
id: notificationTray.markSeen
|
|
42357
|
+
*/
|
|
42358
|
+
/**
|
|
42359
|
+
* ```js
|
|
42360
|
+
* import { notificationTray } from '@amityco/ts-sdk'
|
|
42361
|
+
* const updated = await notificationTray.markTraySeen({
|
|
42362
|
+
* lastSeenAt: Amity.timestamp,
|
|
42363
|
+
* })
|
|
42364
|
+
* ```
|
|
42365
|
+
*
|
|
42366
|
+
* Updates an {@link Amity.NotificationTraySeen}
|
|
42367
|
+
*
|
|
42368
|
+
* @param userId The ID of the {@link Amity.NotificationTraySeen} to edit
|
|
42369
|
+
* @param lastSeenAt The patch data to apply
|
|
42370
|
+
* @returns the updated {@link Amity.NotificationTraySeen} object
|
|
42371
|
+
*
|
|
42372
|
+
* @category Post API
|
|
42373
|
+
* @async
|
|
42374
|
+
*/
|
|
42375
|
+
const markTraySeen = async (lastSeenAt) => {
|
|
42376
|
+
var _a;
|
|
42377
|
+
const client = getActiveClient();
|
|
42378
|
+
client.log('notificationTray/markTraySeen', {});
|
|
42379
|
+
const { data: payload } = await client.http.post(`api/v1/notification-tray/tray/seen`, {
|
|
42380
|
+
lastSeenAt,
|
|
42381
|
+
});
|
|
42382
|
+
const cacheData = (_a = pullFromCache([
|
|
42383
|
+
'notificationTraySeen',
|
|
42384
|
+
'get',
|
|
42385
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
42386
|
+
const data = {
|
|
42387
|
+
userId: client.userId,
|
|
42388
|
+
lastTraySeenAt: payload.lastSeenAt,
|
|
42389
|
+
};
|
|
42390
|
+
const updateCacheData = Object.assign(Object.assign({}, cacheData), data);
|
|
42391
|
+
const cachedAt = client.cache && Date.now();
|
|
42392
|
+
if (client.cache)
|
|
42393
|
+
pushToCache(['notificationTraySeen', 'get', client.userId], updateCacheData, { cachedAt });
|
|
42394
|
+
fireEvent('local.notificationTraySeen.updated', data);
|
|
42395
|
+
return {
|
|
42396
|
+
data: payload,
|
|
42397
|
+
cachedAt,
|
|
42398
|
+
};
|
|
42399
|
+
};
|
|
42400
|
+
/* end_public_function */
|
|
42401
|
+
|
|
42402
|
+
var index = /*#__PURE__*/Object.freeze({
|
|
42403
|
+
__proto__: null,
|
|
42404
|
+
getNotificationTraySeen: getNotificationTraySeen,
|
|
42405
|
+
getNotificationTrayItems: getNotificationTrayItems,
|
|
42406
|
+
markItemsSeen: markItemsSeen,
|
|
42407
|
+
markTraySeen: markTraySeen,
|
|
42408
|
+
onNotificationTraySeenUpdated: onNotificationTraySeenUpdated
|
|
42409
|
+
});
|
|
42410
|
+
|
|
42411
|
+
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, 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 };
|