@amityco/ts-sdk 7.1.1-e887d15f.0 → 7.2.1-3663404.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 +45 -1
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/channel.d.ts +2 -2
- package/dist/@types/domains/channel.d.ts.map +1 -1
- package/dist/@types/domains/client.d.ts +1 -0
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/@types/domains/file.d.ts +1 -20
- package/dist/@types/domains/file.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/domains/post.d.ts +4 -0
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/@types/index.d.ts +1 -0
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/channelRepository/events/onChannelDeleted.d.ts.map +1 -1
- package/dist/channelRepository/internalApi/getTotalChannelsUnread.d.ts +11 -0
- package/dist/channelRepository/internalApi/getTotalChannelsUnread.d.ts.map +1 -0
- package/dist/channelRepository/observers/getTotalChannelsUnread.d.ts +20 -0
- package/dist/channelRepository/observers/getTotalChannelsUnread.d.ts.map +1 -0
- package/dist/channelRepository/observers/index.d.ts +1 -0
- package/dist/channelRepository/observers/index.d.ts.map +1 -1
- package/dist/channelRepository/utils/prepareChannelPayload.d.ts.map +1 -1
- package/dist/client/api/createClient.d.ts +1 -0
- package/dist/client/api/createClient.d.ts.map +1 -1
- package/dist/client/utils/ReadReceiptSync/readReceiptSyncEngine.d.ts.map +1 -1
- package/dist/client/utils/endpoints.d.ts +1 -0
- package/dist/client/utils/endpoints.d.ts.map +1 -1
- package/dist/client/utils/setClientToken.d.ts.map +1 -1
- package/dist/commentRepository/events/utils.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/fileRepository/api/index.d.ts +1 -0
- package/dist/fileRepository/api/index.d.ts.map +1 -1
- package/dist/fileRepository/api/updateAltText.d.ts +17 -0
- package/dist/fileRepository/api/updateAltText.d.ts.map +1 -0
- package/dist/fileRepository/api/uploadImage.d.ts +2 -1
- package/dist/fileRepository/api/uploadImage.d.ts.map +1 -1
- package/dist/index.cjs.js +748 -73
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +731 -57
- package/dist/index.umd.js +4 -4
- package/dist/messageRepository/events/onMessageCreated.d.ts.map +1 -1
- package/dist/messageRepository/observers/getMessage.d.ts.map +1 -1
- 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/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
- package/dist/utils/postTypePredicate.d.ts +4 -0
- package/dist/utils/postTypePredicate.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 +52 -1
- package/src/@types/domains/channel.ts +2 -2
- package/src/@types/domains/client.ts +1 -0
- package/src/@types/domains/file.ts +1 -21
- package/src/@types/domains/notification.ts +94 -0
- package/src/@types/domains/post.ts +4 -0
- package/src/@types/index.ts +1 -0
- package/src/channelRepository/events/onChannelDeleted.ts +9 -2
- package/src/channelRepository/internalApi/getTotalChannelsUnread.ts +38 -0
- package/src/channelRepository/observers/getTotalChannelsUnread.ts +129 -0
- package/src/channelRepository/observers/index.ts +1 -0
- package/src/channelRepository/utils/prepareChannelPayload.ts +21 -10
- package/src/client/api/createClient.ts +4 -1
- package/src/client/utils/ReadReceiptSync/readReceiptSyncEngine.ts +5 -1
- package/src/client/utils/endpoints.ts +1 -0
- package/src/client/utils/setClientToken.ts +8 -0
- package/src/commentRepository/events/utils.ts +73 -0
- package/src/core/model/idResolvers.ts +3 -0
- package/src/core/model/index.ts +2 -0
- package/src/fileRepository/api/index.ts +1 -0
- package/src/fileRepository/api/updateAltText.ts +39 -0
- package/src/fileRepository/api/uploadFile.ts +1 -1
- package/src/fileRepository/api/uploadImage.ts +23 -4
- package/src/fileRepository/api/uploadVideo.ts +1 -1
- package/src/index.ts +2 -0
- package/src/messageRepository/events/onMessageCreated.ts +19 -9
- package/src/messageRepository/observers/getMessage.ts +0 -1
- 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/src/utils/linkedObject/postLinkedObject.ts +29 -0
- package/src/utils/postTypePredicate.ts +27 -0
package/dist/index.esm.js
CHANGED
|
@@ -87,8 +87,8 @@ const PostContentType = Object.freeze({
|
|
|
87
87
|
|
|
88
88
|
function getVersion() {
|
|
89
89
|
try {
|
|
90
|
-
// the string ''v7.
|
|
91
|
-
return 'v7.
|
|
90
|
+
// the string ''v7.2.0-esm'' should be replaced by actual value by @rollup/plugin-replace
|
|
91
|
+
return 'v7.2.0-esm';
|
|
92
92
|
}
|
|
93
93
|
catch (error) {
|
|
94
94
|
return '__dev__';
|
|
@@ -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) => {
|
|
@@ -1547,6 +1551,7 @@ const API_REGIONS = {
|
|
|
1547
1551
|
};
|
|
1548
1552
|
const URLS = {
|
|
1549
1553
|
http: 'https://apix.{region}.amity.co',
|
|
1554
|
+
upload: 'https://upload.{region}.amity.co',
|
|
1550
1555
|
mqtt: 'wss://sse.{region}.amity.co:443/mqtt',
|
|
1551
1556
|
};
|
|
1552
1557
|
function computeUrl(type, region) {
|
|
@@ -21621,6 +21626,26 @@ const commentLinkedObject = (comment) => {
|
|
|
21621
21626
|
} });
|
|
21622
21627
|
};
|
|
21623
21628
|
|
|
21629
|
+
function isAmityImagePost(post) {
|
|
21630
|
+
return !!(post.data &&
|
|
21631
|
+
typeof post.data !== 'string' &&
|
|
21632
|
+
'fileId' in post.data &&
|
|
21633
|
+
post.dataType === 'image');
|
|
21634
|
+
}
|
|
21635
|
+
function isAmityFilePost(post) {
|
|
21636
|
+
return !!(post.data &&
|
|
21637
|
+
typeof post.data !== 'string' &&
|
|
21638
|
+
'fileId' in post.data &&
|
|
21639
|
+
post.dataType === 'file');
|
|
21640
|
+
}
|
|
21641
|
+
function isAmityVideoPost(post) {
|
|
21642
|
+
return !!(post.data &&
|
|
21643
|
+
typeof post.data !== 'string' &&
|
|
21644
|
+
'videoFileId' in post.data &&
|
|
21645
|
+
'thumbnailFileId' in post.data &&
|
|
21646
|
+
post.dataType === 'video');
|
|
21647
|
+
}
|
|
21648
|
+
|
|
21624
21649
|
const postLinkedObject = (post) => {
|
|
21625
21650
|
return Object.assign(Object.assign({}, post), { analytics: {
|
|
21626
21651
|
markAsViewed: () => {
|
|
@@ -21649,6 +21674,30 @@ const postLinkedObject = (post) => {
|
|
|
21649
21674
|
if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
|
|
21650
21675
|
return;
|
|
21651
21676
|
return userLinkedObject(cacheData.data);
|
|
21677
|
+
},
|
|
21678
|
+
getImageInfo() {
|
|
21679
|
+
var _a, _b;
|
|
21680
|
+
return isAmityImagePost(post)
|
|
21681
|
+
? (_b = pullFromCache(['file', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.fileId])) === null || _b === void 0 ? void 0 : _b.data
|
|
21682
|
+
: undefined;
|
|
21683
|
+
},
|
|
21684
|
+
getVideoInfo() {
|
|
21685
|
+
var _a, _b, _c;
|
|
21686
|
+
return isAmityVideoPost(post)
|
|
21687
|
+
? (_c = pullFromCache(['file', 'get', (_b = (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.videoFileId) === null || _b === void 0 ? void 0 : _b.original])) === null || _c === void 0 ? void 0 : _c.data
|
|
21688
|
+
: undefined;
|
|
21689
|
+
},
|
|
21690
|
+
getVideoThumbnailInfo() {
|
|
21691
|
+
var _a, _b;
|
|
21692
|
+
return isAmityVideoPost(post)
|
|
21693
|
+
? (_b = pullFromCache(['file', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.thumbnailFileId])) === null || _b === void 0 ? void 0 : _b.data
|
|
21694
|
+
: undefined;
|
|
21695
|
+
},
|
|
21696
|
+
getFileInfo() {
|
|
21697
|
+
var _a, _b;
|
|
21698
|
+
return isAmityFilePost(post)
|
|
21699
|
+
? (_b = pullFromCache(['file', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.fileId])) === null || _b === void 0 ? void 0 : _b.data
|
|
21700
|
+
: undefined;
|
|
21652
21701
|
} });
|
|
21653
21702
|
};
|
|
21654
21703
|
|
|
@@ -21820,7 +21869,9 @@ class MessageReadReceiptSyncEngine {
|
|
|
21820
21869
|
// Step 1: Optimistic update of channelUnread.readToSegment to message.segment and update unreadCount value
|
|
21821
21870
|
const cacheKey = ['channelUnread', 'get', channelId];
|
|
21822
21871
|
const channelUnread = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
21823
|
-
if (channelUnread
|
|
21872
|
+
if (typeof (channelUnread === null || channelUnread === void 0 ? void 0 : channelUnread.readToSegment) === 'number' &&
|
|
21873
|
+
channelUnread &&
|
|
21874
|
+
segment > channelUnread.readToSegment) {
|
|
21824
21875
|
channelUnread.readToSegment = segment;
|
|
21825
21876
|
channelUnread.unreadCount = Math.max(channelUnread.lastSegment - segment, 0);
|
|
21826
21877
|
pushToCache(cacheKey, channelUnread);
|
|
@@ -22310,6 +22361,14 @@ const pinnedPostLinkedObject = (pinnedPost) => {
|
|
|
22310
22361
|
} });
|
|
22311
22362
|
};
|
|
22312
22363
|
|
|
22364
|
+
const notificationTrayLinkedObject = (noti) => {
|
|
22365
|
+
return Object.assign(Object.assign({}, noti), { isSeen: noti.lastSeenAt > noti.lastOccurredAt, isRecent: new Date(noti.lastOccurredAt).getTime() >= Date.now() - WEEK, users: noti.actors
|
|
22366
|
+
.map(({ _id }) => pullFromCache(['user', 'get', _id]))
|
|
22367
|
+
.filter(isNonNullable)
|
|
22368
|
+
.map(({ data }) => data)
|
|
22369
|
+
.map(user => userLinkedObject(user)) });
|
|
22370
|
+
};
|
|
22371
|
+
|
|
22313
22372
|
const LinkedObject = {
|
|
22314
22373
|
ad: adLinkedObject,
|
|
22315
22374
|
comment: commentLinkedObject,
|
|
@@ -22323,6 +22382,7 @@ const LinkedObject = {
|
|
|
22323
22382
|
reactor: reactorLinkedObject,
|
|
22324
22383
|
channel: channelLinkedObject,
|
|
22325
22384
|
pinnedPost: pinnedPostLinkedObject,
|
|
22385
|
+
notificationTray: notificationTrayLinkedObject,
|
|
22326
22386
|
};
|
|
22327
22387
|
|
|
22328
22388
|
const getChannelMessagePreviewWithUser = (channel) => {
|
|
@@ -23153,19 +23213,27 @@ const preUpdateChannelCache = (rawPayload, options = { isMessagePreviewUpdated:
|
|
|
23153
23213
|
const updateChannelUnread = ({ currentUserId, channels, channelUsers, }) => {
|
|
23154
23214
|
for (let i = 0; i < channels.length; i += 1) {
|
|
23155
23215
|
const cacheKey = ['channelUnread', 'get', channels[i].channelId];
|
|
23156
|
-
const
|
|
23157
|
-
|
|
23158
|
-
|
|
23159
|
-
|
|
23160
|
-
|
|
23216
|
+
const channelUser = channelUsers.find(channelUser => channelUser.channelId === channels[i].channelId && channelUser.userId === currentUserId);
|
|
23217
|
+
let unreadCount = 0;
|
|
23218
|
+
let readToSegment = null;
|
|
23219
|
+
let lastMentionedSegment = null;
|
|
23220
|
+
let isMentioned = false;
|
|
23221
|
+
if (channelUser) {
|
|
23222
|
+
readToSegment = channelUser.readToSegment;
|
|
23223
|
+
lastMentionedSegment = channelUser.lastMentionedSegment;
|
|
23224
|
+
unreadCount = Math.max(channels[i].messageCount - readToSegment, 0);
|
|
23225
|
+
isMentioned = lastMentionedSegment > readToSegment;
|
|
23226
|
+
}
|
|
23227
|
+
const cacheChannelUnread = {
|
|
23161
23228
|
channelId: channels[i].channelId,
|
|
23162
23229
|
lastSegment: channels[i].messageCount,
|
|
23163
23230
|
readToSegment,
|
|
23164
23231
|
lastMentionedSegment,
|
|
23165
|
-
unreadCount
|
|
23166
|
-
isMentioned
|
|
23167
|
-
isDeleted: channels[i].isDeleted,
|
|
23168
|
-
}
|
|
23232
|
+
unreadCount,
|
|
23233
|
+
isMentioned,
|
|
23234
|
+
isDeleted: channels[i].isDeleted || false,
|
|
23235
|
+
};
|
|
23236
|
+
pushToCache(cacheKey, cacheChannelUnread);
|
|
23169
23237
|
}
|
|
23170
23238
|
};
|
|
23171
23239
|
const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpdated: true }) => {
|
|
@@ -23965,6 +24033,12 @@ const setClientToken = async (params) => {
|
|
|
23965
24033
|
isGlobalBanned: false,
|
|
23966
24034
|
isUserDeleted: false,
|
|
23967
24035
|
};
|
|
24036
|
+
client.upload.defaults.headers.common.Authorization = `Bearer ${accessToken}`;
|
|
24037
|
+
client.upload.defaults.metadata = {
|
|
24038
|
+
tokenExpiry: expiresAt,
|
|
24039
|
+
isGlobalBanned: false,
|
|
24040
|
+
isUserDeleted: false,
|
|
24041
|
+
};
|
|
23968
24042
|
// manually setup the token for ws transport
|
|
23969
24043
|
if (client.ws)
|
|
23970
24044
|
client.ws.io.opts.query = { token: accessToken };
|
|
@@ -24017,7 +24091,11 @@ const onChannelDeleted = (callback) => {
|
|
|
24017
24091
|
deleteChannelUnreadByChannelId(channel.channelId);
|
|
24018
24092
|
}
|
|
24019
24093
|
else if (isLegacyUnreadCount) {
|
|
24020
|
-
|
|
24094
|
+
const cacheKey = ['channelUnread', 'get', channel.channelId];
|
|
24095
|
+
const cache = pullFromCache(cacheKey);
|
|
24096
|
+
if (cache) {
|
|
24097
|
+
pushToCache(cacheKey, Object.assign(Object.assign({}, cache), { isDeleted: true }));
|
|
24098
|
+
}
|
|
24021
24099
|
}
|
|
24022
24100
|
});
|
|
24023
24101
|
ingestInCache(data);
|
|
@@ -25004,7 +25082,10 @@ const onMessageCreatedMqtt = (callback) => {
|
|
|
25004
25082
|
'get',
|
|
25005
25083
|
message.channelId,
|
|
25006
25084
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
25007
|
-
if (!channelUnread ||
|
|
25085
|
+
if (!channelUnread ||
|
|
25086
|
+
channelUnread.lastSegment >= message.segment ||
|
|
25087
|
+
typeof channelUnread.readToSegment !== 'number' ||
|
|
25088
|
+
typeof channelUnread.lastMentionedSegment !== 'number')
|
|
25008
25089
|
return;
|
|
25009
25090
|
const lastSegment = message.segment;
|
|
25010
25091
|
const isMentionedInMessage = (_b = message.mentionedUsers) === null || _b === void 0 ? void 0 : _b.some(mention => {
|
|
@@ -25013,10 +25094,12 @@ const onMessageCreatedMqtt = (callback) => {
|
|
|
25013
25094
|
client.userId &&
|
|
25014
25095
|
mention.userPublicIds.includes(client.userId)));
|
|
25015
25096
|
});
|
|
25016
|
-
const
|
|
25097
|
+
const lastMentionedSegment = isMentionedInMessage
|
|
25017
25098
|
? message.segment
|
|
25018
|
-
: channelUnread.
|
|
25019
|
-
|
|
25099
|
+
: channelUnread.lastMentionedSegment;
|
|
25100
|
+
const updatedChannelUnread = Object.assign(Object.assign({}, channelUnread), { lastSegment, unreadCount: Math.max(lastSegment - channelUnread.readToSegment, 0), lastMentionedSegment, isMentioned: !(channelUnread.readToSegment >= lastMentionedSegment) });
|
|
25101
|
+
pushToCache(['channelUnread', 'get', message.channelId], updatedChannelUnread);
|
|
25102
|
+
fireEvent('local.channelUnread.updated', updatedChannelUnread);
|
|
25020
25103
|
});
|
|
25021
25104
|
}
|
|
25022
25105
|
// Update in cache
|
|
@@ -25673,15 +25756,17 @@ const DEFAULT_DEBUG_SESSION = 'amity';
|
|
|
25673
25756
|
* @category Client API
|
|
25674
25757
|
* */
|
|
25675
25758
|
const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAULT_DEBUG_SESSION, apiEndpoint, prefixDeviceIdKey, rteEnabled = true, } = {}) => {
|
|
25676
|
-
var _a, _b;
|
|
25759
|
+
var _a, _b, _c;
|
|
25677
25760
|
const log = createLogger(debugSession);
|
|
25678
25761
|
log('client/api/createClient', {
|
|
25679
25762
|
apiKey: apiKey.replace(/.{5}$/g, 'xxxxx'),
|
|
25680
25763
|
apiRegion,
|
|
25681
25764
|
});
|
|
25682
25765
|
const httpEndpoint = (_a = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.http) !== null && _a !== void 0 ? _a : computeUrl('http', apiRegion);
|
|
25683
|
-
const
|
|
25766
|
+
const uploadEndpoint = (_b = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.upload) !== null && _b !== void 0 ? _b : computeUrl('upload', apiRegion);
|
|
25767
|
+
const mqttEndpoint = (_c = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.mqtt) !== null && _c !== void 0 ? _c : computeUrl('mqtt', apiRegion);
|
|
25684
25768
|
const http = createHttpTransport(httpEndpoint);
|
|
25769
|
+
const upload = createHttpTransport(uploadEndpoint);
|
|
25685
25770
|
let ws;
|
|
25686
25771
|
let mqtt;
|
|
25687
25772
|
if (rteEnabled) {
|
|
@@ -25712,6 +25797,7 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
|
|
|
25712
25797
|
http,
|
|
25713
25798
|
ws,
|
|
25714
25799
|
mqtt,
|
|
25800
|
+
upload,
|
|
25715
25801
|
emitter,
|
|
25716
25802
|
/*
|
|
25717
25803
|
* Session Components
|
|
@@ -25741,7 +25827,7 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
|
|
|
25741
25827
|
return activeClient;
|
|
25742
25828
|
setActiveClient(client);
|
|
25743
25829
|
}
|
|
25744
|
-
catch (
|
|
25830
|
+
catch (_d) {
|
|
25745
25831
|
setActiveClient(client);
|
|
25746
25832
|
}
|
|
25747
25833
|
return client;
|
|
@@ -26198,7 +26284,7 @@ const getUserUnread = (callback) => {
|
|
|
26198
26284
|
};
|
|
26199
26285
|
};
|
|
26200
26286
|
|
|
26201
|
-
var index$
|
|
26287
|
+
var index$m = /*#__PURE__*/Object.freeze({
|
|
26202
26288
|
__proto__: null,
|
|
26203
26289
|
getActiveClient: getActiveClient,
|
|
26204
26290
|
getActiveUser: getActiveUser,
|
|
@@ -27405,7 +27491,7 @@ const getMyFollowInfo = (callback) => {
|
|
|
27405
27491
|
};
|
|
27406
27492
|
/* end_public_function */
|
|
27407
27493
|
|
|
27408
|
-
var index$
|
|
27494
|
+
var index$l = /*#__PURE__*/Object.freeze({
|
|
27409
27495
|
__proto__: null,
|
|
27410
27496
|
blockUser: blockUser,
|
|
27411
27497
|
unBlockUser: unBlockUser,
|
|
@@ -28420,9 +28506,9 @@ var AmityUserSearchMatchType;
|
|
|
28420
28506
|
AmityUserSearchMatchType["PARTIAL"] = "partial";
|
|
28421
28507
|
})(AmityUserSearchMatchType || (AmityUserSearchMatchType = {}));
|
|
28422
28508
|
|
|
28423
|
-
var index$
|
|
28509
|
+
var index$k = /*#__PURE__*/Object.freeze({
|
|
28424
28510
|
__proto__: null,
|
|
28425
|
-
Relationship: index$
|
|
28511
|
+
Relationship: index$l,
|
|
28426
28512
|
getUserByIds: getUserByIds,
|
|
28427
28513
|
updateUser: updateUser,
|
|
28428
28514
|
flagUser: flagUser,
|
|
@@ -28530,7 +28616,7 @@ const uploadFile = async (formData, onProgress) => {
|
|
|
28530
28616
|
const headers = 'getHeaders' in formData
|
|
28531
28617
|
? formData.getHeaders()
|
|
28532
28618
|
: { 'content-type': 'multipart/form-data' };
|
|
28533
|
-
const { data } = await client.
|
|
28619
|
+
const { data } = await client.upload.post('/api/v4/files', formData, {
|
|
28534
28620
|
headers,
|
|
28535
28621
|
onUploadProgress({ loaded, total = 100 }) {
|
|
28536
28622
|
onProgress && onProgress(Math.round((loaded * 100) / total));
|
|
@@ -28620,7 +28706,7 @@ const uploadVideo = async (formData, feedType, onProgress) => {
|
|
|
28620
28706
|
const headers = 'getHeaders' in formData
|
|
28621
28707
|
? formData.getHeaders()
|
|
28622
28708
|
: { 'content-type': 'multipart/form-data' };
|
|
28623
|
-
const { data } = await client.
|
|
28709
|
+
const { data } = await client.upload.post('/api/v4/videos', formData, {
|
|
28624
28710
|
headers,
|
|
28625
28711
|
onUploadProgress({ loaded, total = 100 }) {
|
|
28626
28712
|
onProgress && onProgress(Math.round((loaded * 100) / total));
|
|
@@ -28651,24 +28737,37 @@ const uploadVideo = async (formData, feedType, onProgress) => {
|
|
|
28651
28737
|
*
|
|
28652
28738
|
* @param formData The data necessary to create a new {@link Amity.File<'image'>}
|
|
28653
28739
|
* @param onProgress The callback to track the upload progress
|
|
28740
|
+
* @param altText The alt text for the image
|
|
28654
28741
|
* @returns The newly created {@link Amity.File<'image'>}
|
|
28655
28742
|
*
|
|
28656
28743
|
* @category File API
|
|
28657
28744
|
* @async
|
|
28658
28745
|
*/
|
|
28659
|
-
const uploadImage = async (formData, onProgress) => {
|
|
28746
|
+
const uploadImage = async (formData, onProgress, altText) => {
|
|
28660
28747
|
const client = getActiveClient();
|
|
28661
28748
|
client.log('file/uploadImage', formData);
|
|
28662
28749
|
const files = formData.getAll('files');
|
|
28663
|
-
if (
|
|
28664
|
-
|
|
28750
|
+
if (files === null || files === void 0 ? void 0 : files.length) {
|
|
28751
|
+
console.warn('Deprecation Warning: `files` is deprecated, please use `file` instead.');
|
|
28752
|
+
formData.append('preferredFilename', files[0].name);
|
|
28753
|
+
}
|
|
28754
|
+
else {
|
|
28755
|
+
const file = formData.get('file');
|
|
28756
|
+
if (!file) {
|
|
28757
|
+
throw new Error('The formData object must have a `file` or `files` key');
|
|
28758
|
+
}
|
|
28759
|
+
formData.append('preferredFilename', file.name);
|
|
28760
|
+
// alt is for single image
|
|
28761
|
+
if (altText) {
|
|
28762
|
+
formData.append('altText', altText);
|
|
28763
|
+
}
|
|
28764
|
+
}
|
|
28665
28765
|
const accessType = GlobalFileAccessType$1.getInstance().getFileAccessType();
|
|
28666
28766
|
formData.append('accessType', accessType);
|
|
28667
|
-
formData.append('preferredFilename', files[0].name);
|
|
28668
28767
|
const headers = 'getHeaders' in formData
|
|
28669
28768
|
? formData.getHeaders()
|
|
28670
28769
|
: { 'content-type': 'multipart/form-data' };
|
|
28671
|
-
const { data } = await client.
|
|
28770
|
+
const { data } = await client.upload.post('/api/v4/images', formData, {
|
|
28672
28771
|
headers,
|
|
28673
28772
|
onUploadProgress({ loaded, total = 100 }) {
|
|
28674
28773
|
onProgress && onProgress(Math.round((loaded * 100) / total));
|
|
@@ -28686,14 +28785,46 @@ const uploadImage = async (formData, onProgress) => {
|
|
|
28686
28785
|
};
|
|
28687
28786
|
/* end_public_function */
|
|
28688
28787
|
|
|
28689
|
-
|
|
28788
|
+
/* begin_public_function
|
|
28789
|
+
id: file.update.altText
|
|
28790
|
+
*/
|
|
28791
|
+
/**
|
|
28792
|
+
* ```js
|
|
28793
|
+
* import { FileRepository } from '@amityco/ts-sdk'
|
|
28794
|
+
* const updated = await FileRepository.updateAltText(fileId, altText)
|
|
28795
|
+
* ```
|
|
28796
|
+
*
|
|
28797
|
+
* Updates an {@link Amity.File<'image'>['altText']}.
|
|
28798
|
+
*
|
|
28799
|
+
* @param fileId The ID of the {@link Amity.File<'image'>} to edit
|
|
28800
|
+
* @param altText The new alt text for the {@link Amity.File<'image'>}
|
|
28801
|
+
* @returns the updated {@link Amity.File<'image'>} object
|
|
28802
|
+
*
|
|
28803
|
+
* @category File API
|
|
28804
|
+
* @async
|
|
28805
|
+
*/
|
|
28806
|
+
const updateAltText = async (fileId, altText) => {
|
|
28807
|
+
const client = getActiveClient();
|
|
28808
|
+
client.log('file/updateAltText', altText);
|
|
28809
|
+
const { data } = await client.http.put(`/api/v3/files/${fileId}`, {
|
|
28810
|
+
altText,
|
|
28811
|
+
});
|
|
28812
|
+
const cachedAt = client.cache && Date.now();
|
|
28813
|
+
if (client.cache)
|
|
28814
|
+
ingestInCache({ files: [data] }, { cachedAt });
|
|
28815
|
+
return true;
|
|
28816
|
+
};
|
|
28817
|
+
/* end_public_function */
|
|
28818
|
+
|
|
28819
|
+
var index$j = /*#__PURE__*/Object.freeze({
|
|
28690
28820
|
__proto__: null,
|
|
28691
28821
|
getFile: getFile,
|
|
28692
28822
|
uploadFile: uploadFile,
|
|
28693
28823
|
deleteFile: deleteFile,
|
|
28694
28824
|
fileUrlWithSize: fileUrlWithSize,
|
|
28695
28825
|
uploadVideo: uploadVideo,
|
|
28696
|
-
uploadImage: uploadImage
|
|
28826
|
+
uploadImage: uploadImage,
|
|
28827
|
+
updateAltText: updateAltText
|
|
28697
28828
|
});
|
|
28698
28829
|
|
|
28699
28830
|
/**
|
|
@@ -29753,6 +29884,29 @@ const createCommentEventSubscriber = (event, callback) => {
|
|
|
29753
29884
|
}
|
|
29754
29885
|
}
|
|
29755
29886
|
}
|
|
29887
|
+
}
|
|
29888
|
+
if (['comment.deleted'].includes(event)) {
|
|
29889
|
+
// NOTE: skip deleting comment to parent comment children if it's the same user since we use the local event to update instead.
|
|
29890
|
+
if (event === 'comment.deleted' && comment.data.userId === client.userId)
|
|
29891
|
+
return;
|
|
29892
|
+
if (comments[0].parentId) {
|
|
29893
|
+
const parentComment = pullFromCache([
|
|
29894
|
+
'comment',
|
|
29895
|
+
'get',
|
|
29896
|
+
comments[0].parentId,
|
|
29897
|
+
]);
|
|
29898
|
+
if (parentComment === null || parentComment === void 0 ? void 0 : parentComment.data) {
|
|
29899
|
+
// Remove deleted comment in parent childComment if still exists
|
|
29900
|
+
if (parentComment.data.children.includes(comments[0].commentId)) {
|
|
29901
|
+
const newParentComment = Object.assign(Object.assign({}, parentComment.data), { childrenNumber: parentComment.data.childrenNumber - 1, children: [
|
|
29902
|
+
...new Set([
|
|
29903
|
+
...parentComment.data.children.filter(id => id !== comments[0].commentId),
|
|
29904
|
+
]),
|
|
29905
|
+
] });
|
|
29906
|
+
pushToCache(['comment', 'get', comments[0].parentId], newParentComment);
|
|
29907
|
+
}
|
|
29908
|
+
}
|
|
29909
|
+
}
|
|
29756
29910
|
const queries = (_a = queryCache(['comment', 'query'])) === null || _a === void 0 ? void 0 : _a.filter(({ key }) => { var _a; return ((_a = key[2]) === null || _a === void 0 ? void 0 : _a.referenceId) === comment.data.referenceId; });
|
|
29757
29911
|
queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
|
|
29758
29912
|
}
|
|
@@ -29765,7 +29919,7 @@ const createCommentEventSubscriber = (event, callback) => {
|
|
|
29765
29919
|
const createLocalCommentEventSubscriber = (event, callback) => {
|
|
29766
29920
|
const client = getActiveClient();
|
|
29767
29921
|
const filter = (payload) => {
|
|
29768
|
-
var _a;
|
|
29922
|
+
var _a, _b;
|
|
29769
29923
|
if (!client.cache) {
|
|
29770
29924
|
// TODO: here we are missing specific properties here!
|
|
29771
29925
|
callback(LinkedObject.comment(payload.comments[0]));
|
|
@@ -29808,6 +29962,38 @@ const createLocalCommentEventSubscriber = (event, callback) => {
|
|
|
29808
29962
|
const queries = (_a = queryCache(['comment', 'query'])) === null || _a === void 0 ? void 0 : _a.filter(({ key }) => { var _a; return ((_a = key[2]) === null || _a === void 0 ? void 0 : _a.referenceId) === comment.data.referenceId; });
|
|
29809
29963
|
queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
|
|
29810
29964
|
}
|
|
29965
|
+
if (['local.comment.deleted'].includes(event)) {
|
|
29966
|
+
if (comments[0].parentId) {
|
|
29967
|
+
const parentComment = pullFromCache([
|
|
29968
|
+
'comment',
|
|
29969
|
+
'get',
|
|
29970
|
+
comments[0].parentId,
|
|
29971
|
+
]);
|
|
29972
|
+
if (parentComment === null || parentComment === void 0 ? void 0 : parentComment.data) {
|
|
29973
|
+
// Remove deleted comment in parent childComment if still exists
|
|
29974
|
+
if (parentComment.data.children.includes(comments[0].commentId)) {
|
|
29975
|
+
const newParentComment = Object.assign(Object.assign({}, parentComment.data), { childrenNumber: parentComment.data.childrenNumber - 1, children: [
|
|
29976
|
+
...new Set([
|
|
29977
|
+
...parentComment.data.children.filter(id => id !== comments[0].commentId),
|
|
29978
|
+
]),
|
|
29979
|
+
] });
|
|
29980
|
+
pushToCache(['comment', 'get', comments[0].parentId], newParentComment);
|
|
29981
|
+
setTimeout(() => {
|
|
29982
|
+
// NOTE: This is workaround solution for emitting event not work properly.
|
|
29983
|
+
fireEvent('comment.updated', {
|
|
29984
|
+
comments: [newParentComment],
|
|
29985
|
+
commentChildren: [],
|
|
29986
|
+
files: [],
|
|
29987
|
+
users: [],
|
|
29988
|
+
communityUsers: [],
|
|
29989
|
+
});
|
|
29990
|
+
}, 200);
|
|
29991
|
+
}
|
|
29992
|
+
}
|
|
29993
|
+
}
|
|
29994
|
+
const queries = (_b = queryCache(['comment', 'query'])) === null || _b === void 0 ? void 0 : _b.filter(({ key }) => { var _a; return ((_a = key[2]) === null || _a === void 0 ? void 0 : _a.referenceId) === comment.data.referenceId; });
|
|
29995
|
+
queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
|
|
29996
|
+
}
|
|
29811
29997
|
callback(LinkedObject.comment(comment.data));
|
|
29812
29998
|
}
|
|
29813
29999
|
}
|
|
@@ -30498,7 +30684,7 @@ const getReactions = (params, callback, config) => {
|
|
|
30498
30684
|
};
|
|
30499
30685
|
/* end_public_function */
|
|
30500
30686
|
|
|
30501
|
-
var index$
|
|
30687
|
+
var index$i = /*#__PURE__*/Object.freeze({
|
|
30502
30688
|
__proto__: null,
|
|
30503
30689
|
addReaction: addReaction,
|
|
30504
30690
|
removeReaction: removeReaction,
|
|
@@ -32314,7 +32500,7 @@ const getMessages = (params, callback, config) => {
|
|
|
32314
32500
|
};
|
|
32315
32501
|
/* end_public_function */
|
|
32316
32502
|
|
|
32317
|
-
var index$
|
|
32503
|
+
var index$h = /*#__PURE__*/Object.freeze({
|
|
32318
32504
|
__proto__: null,
|
|
32319
32505
|
createMessage: createMessage,
|
|
32320
32506
|
updateMessage: updateMessage,
|
|
@@ -32840,7 +33026,7 @@ const stopMessageReceiptSync = (subChannelId) => {
|
|
|
32840
33026
|
};
|
|
32841
33027
|
/* end_public_function */
|
|
32842
33028
|
|
|
32843
|
-
var index$
|
|
33029
|
+
var index$g = /*#__PURE__*/Object.freeze({
|
|
32844
33030
|
__proto__: null,
|
|
32845
33031
|
getSubChannelByIds: getSubChannels$1,
|
|
32846
33032
|
createSubChannel: createSubChannel,
|
|
@@ -33676,6 +33862,120 @@ const getChannels = (params, callback, config) => {
|
|
|
33676
33862
|
};
|
|
33677
33863
|
/* end_public_function */
|
|
33678
33864
|
|
|
33865
|
+
/**
|
|
33866
|
+
*
|
|
33867
|
+
* Calculate user unread from {@link Amity.ChannelUnread} objects
|
|
33868
|
+
*
|
|
33869
|
+
* @returns the {@link Amity.UserUnread} objects
|
|
33870
|
+
*
|
|
33871
|
+
* @category Channel API
|
|
33872
|
+
* @async
|
|
33873
|
+
*/
|
|
33874
|
+
const getTotalChannelsUnread$1 = () => {
|
|
33875
|
+
var _a;
|
|
33876
|
+
const client = getActiveClient();
|
|
33877
|
+
client.log('channel/getTotalChannelsUnread.locally');
|
|
33878
|
+
const cachedChannelsUnread = ((_a = queryCache(['channelUnread', 'get'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
|
|
33879
|
+
return !data.isDeleted;
|
|
33880
|
+
})) || [];
|
|
33881
|
+
const totalChannelsUnread = (cachedChannelsUnread === null || cachedChannelsUnread === void 0 ? void 0 : cachedChannelsUnread.reduce((acc, { data }) => {
|
|
33882
|
+
acc.unreadCount += data.unreadCount;
|
|
33883
|
+
acc.isMentioned = acc.isMentioned || data.isMentioned;
|
|
33884
|
+
return acc;
|
|
33885
|
+
}, { unreadCount: 0, isMentioned: false })) || { unreadCount: 0, isMentioned: false };
|
|
33886
|
+
const cachedAt = client.cache && Date.now();
|
|
33887
|
+
return {
|
|
33888
|
+
data: totalChannelsUnread,
|
|
33889
|
+
cachedAt,
|
|
33890
|
+
};
|
|
33891
|
+
};
|
|
33892
|
+
|
|
33893
|
+
/* begin_public_function
|
|
33894
|
+
id: totalChannelsUnread.get
|
|
33895
|
+
*/
|
|
33896
|
+
/**
|
|
33897
|
+
* ```js
|
|
33898
|
+
* import { ChannelRepository } from '@amityco/ts-sdk';
|
|
33899
|
+
*
|
|
33900
|
+
* let totalChannelsUnread;
|
|
33901
|
+
*
|
|
33902
|
+
* const unsubscribe = ChannelRepository.getTotalChannelsUnread(response => {
|
|
33903
|
+
* unread = response.data;
|
|
33904
|
+
* });
|
|
33905
|
+
* ```
|
|
33906
|
+
*
|
|
33907
|
+
* Observe all mutation on a given {@link Amity.UserUnread}
|
|
33908
|
+
*
|
|
33909
|
+
* @returns An {@link Amity.UserUnread} function to run when willing to stop observing the message
|
|
33910
|
+
*
|
|
33911
|
+
* @category User Unread Live Object
|
|
33912
|
+
*
|
|
33913
|
+
*/
|
|
33914
|
+
const getTotalChannelsUnread = (callback) => {
|
|
33915
|
+
const { _id: userId } = getActiveUser();
|
|
33916
|
+
if (!userId)
|
|
33917
|
+
throw new ASCError('The _id has not been defined in ActiveUser', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
33918
|
+
const { log, cache } = getActiveClient();
|
|
33919
|
+
if (!cache) {
|
|
33920
|
+
console.log('For using Live Object feature you need to enable Cache!');
|
|
33921
|
+
}
|
|
33922
|
+
const timestamp = Date.now();
|
|
33923
|
+
log(`liveTotalChannelsUnread(tmpid: ${timestamp}) > listen`);
|
|
33924
|
+
const disposers = [];
|
|
33925
|
+
let isUnsyncedModel = false; // for messages
|
|
33926
|
+
let model;
|
|
33927
|
+
const dispatcher = (data) => {
|
|
33928
|
+
const { data: userUnread } = data;
|
|
33929
|
+
const callbackModel = userUnread
|
|
33930
|
+
? {
|
|
33931
|
+
unreadCount: userUnread.unreadCount,
|
|
33932
|
+
isMentioned: userUnread.isMentioned,
|
|
33933
|
+
}
|
|
33934
|
+
: undefined;
|
|
33935
|
+
model = callbackModel ? convertGetterPropsToStatic(callbackModel) : callbackModel;
|
|
33936
|
+
callback({
|
|
33937
|
+
data: callbackModel
|
|
33938
|
+
? Object.assign(Object.assign({}, callbackModel), { isMentioned: callbackModel.isMentioned }) : callbackModel,
|
|
33939
|
+
loading: data.loading,
|
|
33940
|
+
error: data.error,
|
|
33941
|
+
});
|
|
33942
|
+
};
|
|
33943
|
+
const realtimeRouter = (userUnread) => {
|
|
33944
|
+
if (isEqual(model, userUnread))
|
|
33945
|
+
return;
|
|
33946
|
+
dispatcher({
|
|
33947
|
+
loading: false,
|
|
33948
|
+
data: userUnread,
|
|
33949
|
+
});
|
|
33950
|
+
};
|
|
33951
|
+
const onFetch = () => {
|
|
33952
|
+
const query = createQuery(async () => getTotalChannelsUnread$1());
|
|
33953
|
+
runQuery(query, ({ error, data, loading, origin, cachedAt }) => {
|
|
33954
|
+
if (cachedAt === UNSYNCED_OBJECT_CACHED_AT_VALUE) {
|
|
33955
|
+
dispatcher({
|
|
33956
|
+
data,
|
|
33957
|
+
origin,
|
|
33958
|
+
loading: false,
|
|
33959
|
+
error: new ASCApiError(UNSYNCED_OBJECT_CACHED_AT_MESSAGE, 800800 /* Amity.ClientError.DISALOOW_UNSYNCED_OBJECT */, "error" /* Amity.ErrorLevel.ERROR */),
|
|
33960
|
+
});
|
|
33961
|
+
isUnsyncedModel = true;
|
|
33962
|
+
disposers.forEach(fn => fn());
|
|
33963
|
+
}
|
|
33964
|
+
else if (!isUnsyncedModel) {
|
|
33965
|
+
dispatcher({ loading, data, origin, error });
|
|
33966
|
+
}
|
|
33967
|
+
if (error) {
|
|
33968
|
+
disposers.forEach(fn => fn());
|
|
33969
|
+
}
|
|
33970
|
+
});
|
|
33971
|
+
};
|
|
33972
|
+
disposers.push(onChannelUnreadUpdatedLocal(realtimeRouter));
|
|
33973
|
+
onFetch();
|
|
33974
|
+
return () => {
|
|
33975
|
+
disposers.forEach(fn => fn());
|
|
33976
|
+
};
|
|
33977
|
+
};
|
|
33978
|
+
|
|
33679
33979
|
/* begin_public_function
|
|
33680
33980
|
id: channel.member.add
|
|
33681
33981
|
*/
|
|
@@ -34040,7 +34340,7 @@ const searchMembers$1 = (params, callback, config) => {
|
|
|
34040
34340
|
};
|
|
34041
34341
|
/* end_public_function */
|
|
34042
34342
|
|
|
34043
|
-
var index$
|
|
34343
|
+
var index$f = /*#__PURE__*/Object.freeze({
|
|
34044
34344
|
__proto__: null,
|
|
34045
34345
|
addMembers: addMembers$1,
|
|
34046
34346
|
removeMembers: removeMembers$1,
|
|
@@ -34243,7 +34543,7 @@ const unmuteMembers = async (channelId, userIds) => {
|
|
|
34243
34543
|
};
|
|
34244
34544
|
/* end_public_function */
|
|
34245
34545
|
|
|
34246
|
-
var index$
|
|
34546
|
+
var index$e = /*#__PURE__*/Object.freeze({
|
|
34247
34547
|
__proto__: null,
|
|
34248
34548
|
addRole: addRole,
|
|
34249
34549
|
removeRole: removeRole,
|
|
@@ -34253,10 +34553,10 @@ var index$d = /*#__PURE__*/Object.freeze({
|
|
|
34253
34553
|
unmuteMembers: unmuteMembers
|
|
34254
34554
|
});
|
|
34255
34555
|
|
|
34256
|
-
var index$
|
|
34556
|
+
var index$d = /*#__PURE__*/Object.freeze({
|
|
34257
34557
|
__proto__: null,
|
|
34258
|
-
Membership: index$
|
|
34259
|
-
Moderation: index$
|
|
34558
|
+
Membership: index$f,
|
|
34559
|
+
Moderation: index$e,
|
|
34260
34560
|
getChannelByIds: getChannelByIds$1,
|
|
34261
34561
|
createChannel: createChannel,
|
|
34262
34562
|
updateChannel: updateChannel,
|
|
@@ -34279,6 +34579,7 @@ var index$c = /*#__PURE__*/Object.freeze({
|
|
|
34279
34579
|
onChannelMemberRoleRemoved: onChannelMemberRoleRemoved,
|
|
34280
34580
|
getChannel: getChannel,
|
|
34281
34581
|
getChannels: getChannels,
|
|
34582
|
+
getTotalChannelsUnread: getTotalChannelsUnread,
|
|
34282
34583
|
MARKER_INCLUDED_CHANNEL_TYPE: MARKER_INCLUDED_CHANNEL_TYPE,
|
|
34283
34584
|
isUnreadCountSupport: isUnreadCountSupport,
|
|
34284
34585
|
convertFromRaw: convertFromRaw,
|
|
@@ -35635,7 +35936,7 @@ const searchMembers = (params, callback, config) => {
|
|
|
35635
35936
|
};
|
|
35636
35937
|
/* end_public_function */
|
|
35637
35938
|
|
|
35638
|
-
var index$
|
|
35939
|
+
var index$c = /*#__PURE__*/Object.freeze({
|
|
35639
35940
|
__proto__: null,
|
|
35640
35941
|
addMembers: addMembers,
|
|
35641
35942
|
removeMembers: removeMembers,
|
|
@@ -36660,7 +36961,7 @@ const unbanMembers = async (communityId, userIds) => {
|
|
|
36660
36961
|
};
|
|
36661
36962
|
/* end_public_function */
|
|
36662
36963
|
|
|
36663
|
-
var index$
|
|
36964
|
+
var index$b = /*#__PURE__*/Object.freeze({
|
|
36664
36965
|
__proto__: null,
|
|
36665
36966
|
addRoles: addRoles,
|
|
36666
36967
|
removeRoles: removeRoles,
|
|
@@ -36668,10 +36969,10 @@ var index$a = /*#__PURE__*/Object.freeze({
|
|
|
36668
36969
|
unbanMembers: unbanMembers
|
|
36669
36970
|
});
|
|
36670
36971
|
|
|
36671
|
-
var index$
|
|
36972
|
+
var index$a = /*#__PURE__*/Object.freeze({
|
|
36672
36973
|
__proto__: null,
|
|
36673
|
-
Moderation: index$
|
|
36674
|
-
Membership: index$
|
|
36974
|
+
Moderation: index$b,
|
|
36975
|
+
Membership: index$c,
|
|
36675
36976
|
getCommunityByIds: getCommunities$1,
|
|
36676
36977
|
createCommunity: createCommunity,
|
|
36677
36978
|
updateCommunity: updateCommunity,
|
|
@@ -36904,7 +37205,7 @@ const getCategories = (params, callback, config) => {
|
|
|
36904
37205
|
};
|
|
36905
37206
|
/* end_public_function */
|
|
36906
37207
|
|
|
36907
|
-
var index$
|
|
37208
|
+
var index$9 = /*#__PURE__*/Object.freeze({
|
|
36908
37209
|
__proto__: null,
|
|
36909
37210
|
getCategory: getCategory,
|
|
36910
37211
|
getCategories: getCategories
|
|
@@ -37072,7 +37373,7 @@ getCustomRankingGlobalFeed.locally = (query) => {
|
|
|
37072
37373
|
: undefined;
|
|
37073
37374
|
};
|
|
37074
37375
|
|
|
37075
|
-
var index$
|
|
37376
|
+
var index$8 = /*#__PURE__*/Object.freeze({
|
|
37076
37377
|
__proto__: null,
|
|
37077
37378
|
queryGlobalFeed: queryGlobalFeed,
|
|
37078
37379
|
getCustomRankingGlobalFeed: getCustomRankingGlobalFeed
|
|
@@ -38387,7 +38688,7 @@ const getComments = (params, callback, config) => {
|
|
|
38387
38688
|
};
|
|
38388
38689
|
/* end_public_function */
|
|
38389
38690
|
|
|
38390
|
-
var index$
|
|
38691
|
+
var index$7 = /*#__PURE__*/Object.freeze({
|
|
38391
38692
|
__proto__: null,
|
|
38392
38693
|
getCommentByIds: getCommentByIds,
|
|
38393
38694
|
createComment: createComment,
|
|
@@ -39394,7 +39695,7 @@ const semanticSearchPosts = (params, callback, config) => {
|
|
|
39394
39695
|
};
|
|
39395
39696
|
};
|
|
39396
39697
|
|
|
39397
|
-
var index$
|
|
39698
|
+
var index$6 = /*#__PURE__*/Object.freeze({
|
|
39398
39699
|
__proto__: null,
|
|
39399
39700
|
getPostByIds: getPostByIds,
|
|
39400
39701
|
createPost: createPost,
|
|
@@ -39928,7 +40229,7 @@ const getStreams = (params, callback, config) => {
|
|
|
39928
40229
|
};
|
|
39929
40230
|
};
|
|
39930
40231
|
|
|
39931
|
-
var index$
|
|
40232
|
+
var index$5 = /*#__PURE__*/Object.freeze({
|
|
39932
40233
|
__proto__: null,
|
|
39933
40234
|
createStream: createStream,
|
|
39934
40235
|
updateStream: updateStream,
|
|
@@ -40215,7 +40516,7 @@ const getPoll = (pollId, callback) => {
|
|
|
40215
40516
|
};
|
|
40216
40517
|
/* end_public_function */
|
|
40217
40518
|
|
|
40218
|
-
var index$
|
|
40519
|
+
var index$4 = /*#__PURE__*/Object.freeze({
|
|
40219
40520
|
__proto__: null,
|
|
40220
40521
|
createPoll: createPoll,
|
|
40221
40522
|
closePoll: closePoll,
|
|
@@ -40586,7 +40887,7 @@ const getPlayer = async (parameters) => {
|
|
|
40586
40887
|
return video;
|
|
40587
40888
|
};
|
|
40588
40889
|
|
|
40589
|
-
var index$
|
|
40890
|
+
var index$3 = /*#__PURE__*/Object.freeze({
|
|
40590
40891
|
__proto__: null,
|
|
40591
40892
|
getPlayer: getPlayer
|
|
40592
40893
|
});
|
|
@@ -41759,7 +42060,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
|
|
|
41759
42060
|
};
|
|
41760
42061
|
};
|
|
41761
42062
|
|
|
41762
|
-
var index$
|
|
42063
|
+
var index$2 = /*#__PURE__*/Object.freeze({
|
|
41763
42064
|
__proto__: null,
|
|
41764
42065
|
createImageStory: createImageStory,
|
|
41765
42066
|
createVideoStory: createVideoStory,
|
|
@@ -41796,7 +42097,7 @@ const getNetworkAds = async () => {
|
|
|
41796
42097
|
};
|
|
41797
42098
|
};
|
|
41798
42099
|
|
|
41799
|
-
var index = /*#__PURE__*/Object.freeze({
|
|
42100
|
+
var index$1 = /*#__PURE__*/Object.freeze({
|
|
41800
42101
|
__proto__: null,
|
|
41801
42102
|
getNetworkAds: getNetworkAds
|
|
41802
42103
|
});
|
|
@@ -41823,4 +42124,377 @@ const createUserToken = async (apiKey, apiRegion, params) => {
|
|
|
41823
42124
|
return { accessToken: data.accessToken };
|
|
41824
42125
|
};
|
|
41825
42126
|
|
|
41826
|
-
|
|
42127
|
+
/* begin_public_function
|
|
42128
|
+
id: notificationTray.getNotificationTraySeen
|
|
42129
|
+
*/
|
|
42130
|
+
/**
|
|
42131
|
+
* ```js
|
|
42132
|
+
* import { notificationTray } from '@amityco/ts-sdk'
|
|
42133
|
+
* const notificationTraySeen = await notificationTray.getNotificationTraySeen()
|
|
42134
|
+
* ```
|
|
42135
|
+
*
|
|
42136
|
+
*
|
|
42137
|
+
* @returns A page of {@link Amity.NotificationTraySeen} objects
|
|
42138
|
+
*
|
|
42139
|
+
* @category NotificationTray API
|
|
42140
|
+
* @async
|
|
42141
|
+
* */
|
|
42142
|
+
const getNotificationTraySeen$1 = async () => {
|
|
42143
|
+
const client = getActiveClient();
|
|
42144
|
+
client.log('notificationTray/getNotificationTraySeen', {});
|
|
42145
|
+
const { data: payload } = await client.http.get(`api/v1/notification-tray/tray/seen`);
|
|
42146
|
+
const cachedAt = client.cache && Date.now();
|
|
42147
|
+
if (client.cache) {
|
|
42148
|
+
const cacheKey = ['notificationTraySeen', 'get', client.userId];
|
|
42149
|
+
pushToCache(cacheKey, {
|
|
42150
|
+
userId: client.userId,
|
|
42151
|
+
lastTraySeenAt: payload.lastTraySeenAt,
|
|
42152
|
+
lastTrayOccuredAt: payload.lastTrayOccurredAt,
|
|
42153
|
+
});
|
|
42154
|
+
}
|
|
42155
|
+
return {
|
|
42156
|
+
data: {
|
|
42157
|
+
userId: client.userId,
|
|
42158
|
+
lastTraySeenAt: payload.lastTraySeenAt,
|
|
42159
|
+
lastTrayOccurredAt: payload.lastTrayOccurredAt,
|
|
42160
|
+
isSeen: payload.lastTraySeenAt > payload.lastTrayOccurredAt,
|
|
42161
|
+
},
|
|
42162
|
+
cachedAt,
|
|
42163
|
+
};
|
|
42164
|
+
};
|
|
42165
|
+
/* end_public_function */
|
|
42166
|
+
/**
|
|
42167
|
+
* ```js
|
|
42168
|
+
* import { notificationTray } from '@amityco/ts-sdk'
|
|
42169
|
+
* const notificationTraySeen = await notificationTray.getNotificationTraySeen.locally()
|
|
42170
|
+
* ```
|
|
42171
|
+
*
|
|
42172
|
+
* Queries a paginable list of {@link Amity.NotificationTraySeen} objects from cache
|
|
42173
|
+
*
|
|
42174
|
+
* @returns A page of {@link Amity.NotificationTraySeen} objects
|
|
42175
|
+
*
|
|
42176
|
+
* @category NotificationTray API
|
|
42177
|
+
* @async
|
|
42178
|
+
* */
|
|
42179
|
+
getNotificationTraySeen$1.locally = () => {
|
|
42180
|
+
var _a;
|
|
42181
|
+
const client = getActiveClient();
|
|
42182
|
+
client.log('notificationTray/getNotificationTraySeen.locally', {});
|
|
42183
|
+
if (!client.cache)
|
|
42184
|
+
return;
|
|
42185
|
+
const queryKey = ['notificationTraySeen', 'get'];
|
|
42186
|
+
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
42187
|
+
if (!data)
|
|
42188
|
+
return;
|
|
42189
|
+
return { data, cachedAt };
|
|
42190
|
+
};
|
|
42191
|
+
|
|
42192
|
+
/**
|
|
42193
|
+
* ```js
|
|
42194
|
+
* import { onNotificationTraySeenUpdated } from '@amityco/ts-sdk'
|
|
42195
|
+
* const dispose = onNotificationTraySeenUpdated(data => {
|
|
42196
|
+
* // ...
|
|
42197
|
+
* })
|
|
42198
|
+
* ```
|
|
42199
|
+
*
|
|
42200
|
+
* Fired when an {@link Amity.NotificationTraySeen} has been updated
|
|
42201
|
+
*
|
|
42202
|
+
* @param callback The function to call when the event was fired
|
|
42203
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
42204
|
+
*
|
|
42205
|
+
* @category NotificationTraySeen Events
|
|
42206
|
+
*/
|
|
42207
|
+
const onNotificationTraySeenUpdated = (callback) => {
|
|
42208
|
+
const client = getActiveClient();
|
|
42209
|
+
const disposers = [
|
|
42210
|
+
createEventSubscriber(client, 'onNotificationTraySeenUpdated', 'local.notificationTraySeen.updated', payload => callback(payload)),
|
|
42211
|
+
];
|
|
42212
|
+
return () => {
|
|
42213
|
+
disposers.forEach(fn => fn());
|
|
42214
|
+
};
|
|
42215
|
+
};
|
|
42216
|
+
|
|
42217
|
+
/* begin_public_function
|
|
42218
|
+
id: notificationTray.getNotificationTraySeen
|
|
42219
|
+
*/
|
|
42220
|
+
/**
|
|
42221
|
+
* ```js
|
|
42222
|
+
* import { notificationTray } from '@amityco/ts-sdk';
|
|
42223
|
+
*
|
|
42224
|
+
* let notificationTraySeen;
|
|
42225
|
+
*
|
|
42226
|
+
* const unsubscribe = getNotificationTraySeen(response => {
|
|
42227
|
+
* notificationTraySeen = response.data;
|
|
42228
|
+
* });
|
|
42229
|
+
* ```
|
|
42230
|
+
*
|
|
42231
|
+
* Observe all mutation on a given {@link Amity.NotificationTraySeen}
|
|
42232
|
+
*
|
|
42233
|
+
* @param callback the function to call when new data are available
|
|
42234
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the message
|
|
42235
|
+
*
|
|
42236
|
+
* @category NotificationTraySeen Live Object
|
|
42237
|
+
*/
|
|
42238
|
+
const getNotificationTraySeen = (callback) => {
|
|
42239
|
+
const { userId } = getActiveUser();
|
|
42240
|
+
return liveObject(userId, callback, 'userId', getNotificationTraySeen$1, [onNotificationTraySeenUpdated], {
|
|
42241
|
+
callbackDataSelector: (data) => {
|
|
42242
|
+
let isSeen = true;
|
|
42243
|
+
if (data === null || data === void 0 ? void 0 : data.lastTrayOccurredAt) {
|
|
42244
|
+
if (!data.lastTraySeenAt) {
|
|
42245
|
+
isSeen = false;
|
|
42246
|
+
}
|
|
42247
|
+
else {
|
|
42248
|
+
isSeen =
|
|
42249
|
+
convertDateStringToTimestamp(data.lastTraySeenAt) >
|
|
42250
|
+
convertDateStringToTimestamp(data.lastTrayOccurredAt);
|
|
42251
|
+
}
|
|
42252
|
+
}
|
|
42253
|
+
return {
|
|
42254
|
+
lastTrayOccurredAt: data === null || data === void 0 ? void 0 : data.lastTrayOccurredAt,
|
|
42255
|
+
lastTraySeenAt: data === null || data === void 0 ? void 0 : data.lastTraySeenAt,
|
|
42256
|
+
isSeen,
|
|
42257
|
+
};
|
|
42258
|
+
},
|
|
42259
|
+
});
|
|
42260
|
+
};
|
|
42261
|
+
/* end_public_function */
|
|
42262
|
+
|
|
42263
|
+
/**
|
|
42264
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
42265
|
+
* TODO: check if querybyIds is supported
|
|
42266
|
+
*/
|
|
42267
|
+
class NotificationTrayItemsPaginationController extends PaginationController {
|
|
42268
|
+
async getRequest(queryParams, token) {
|
|
42269
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
42270
|
+
const options = token ? { token } : { limit };
|
|
42271
|
+
const { data: queryResponse } = await this.http.get(`/api/v1/notification-tray`, {
|
|
42272
|
+
params: Object.assign(Object.assign({}, params), { options }),
|
|
42273
|
+
});
|
|
42274
|
+
return queryResponse;
|
|
42275
|
+
}
|
|
42276
|
+
}
|
|
42277
|
+
|
|
42278
|
+
class NotificationTrayItemsQuerystreamController extends QueryStreamController {
|
|
42279
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
42280
|
+
super(query, cacheKey);
|
|
42281
|
+
this.notifyChange = notifyChange;
|
|
42282
|
+
this.preparePayload = preparePayload;
|
|
42283
|
+
}
|
|
42284
|
+
async saveToMainDB(response) {
|
|
42285
|
+
const processedPayload = await this.preparePayload(response);
|
|
42286
|
+
const client = getActiveClient();
|
|
42287
|
+
const cachedAt = client.cache && Date.now();
|
|
42288
|
+
if (client.cache) {
|
|
42289
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
42290
|
+
}
|
|
42291
|
+
}
|
|
42292
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
42293
|
+
var _a, _b;
|
|
42294
|
+
if (refresh) {
|
|
42295
|
+
pushToCache(this.cacheKey, {
|
|
42296
|
+
data: response.notificationTrayItems.map(getResolver('notificationTrayItem')),
|
|
42297
|
+
});
|
|
42298
|
+
}
|
|
42299
|
+
else {
|
|
42300
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
42301
|
+
const notifications = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
42302
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
42303
|
+
...new Set([
|
|
42304
|
+
...notifications,
|
|
42305
|
+
...response.notificationTrayItems.map(getResolver('notificationTrayItem')),
|
|
42306
|
+
]),
|
|
42307
|
+
] }));
|
|
42308
|
+
}
|
|
42309
|
+
}
|
|
42310
|
+
}
|
|
42311
|
+
|
|
42312
|
+
const prepareNotificationTrayItemsPayload = (rawPayload) => {
|
|
42313
|
+
const users = rawPayload.users.map(convertRawUserToInternalUser);
|
|
42314
|
+
return Object.assign(Object.assign({}, rawPayload), { users });
|
|
42315
|
+
};
|
|
42316
|
+
|
|
42317
|
+
class NotificationTrayItemsLiveCollectionController extends LiveCollectionController {
|
|
42318
|
+
constructor(query, callback) {
|
|
42319
|
+
const queryStreamId = hash(query);
|
|
42320
|
+
const cacheKey = ['notificationTrayItem', 'collection', queryStreamId];
|
|
42321
|
+
const paginationController = new NotificationTrayItemsPaginationController(query);
|
|
42322
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
42323
|
+
this.query = query;
|
|
42324
|
+
this.queryStreamController = new NotificationTrayItemsQuerystreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareNotificationTrayItemsPayload);
|
|
42325
|
+
this.callback = callback.bind(this);
|
|
42326
|
+
this.loadPage({ initial: true });
|
|
42327
|
+
}
|
|
42328
|
+
setup() {
|
|
42329
|
+
var _a;
|
|
42330
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
42331
|
+
if (!collection) {
|
|
42332
|
+
pushToCache(this.cacheKey, {
|
|
42333
|
+
data: [],
|
|
42334
|
+
params: {},
|
|
42335
|
+
});
|
|
42336
|
+
}
|
|
42337
|
+
}
|
|
42338
|
+
async persistModel(queryPayload) {
|
|
42339
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
42340
|
+
}
|
|
42341
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
42342
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
42343
|
+
}
|
|
42344
|
+
// eslint-disable-next-line class-methods-use-this
|
|
42345
|
+
startSubscription() {
|
|
42346
|
+
return [];
|
|
42347
|
+
}
|
|
42348
|
+
notifyChange({ origin, loading, error }) {
|
|
42349
|
+
var _a, _b;
|
|
42350
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
42351
|
+
if (!collection)
|
|
42352
|
+
return;
|
|
42353
|
+
const data = ((_b = collection.data
|
|
42354
|
+
.map(id => pullFromCache(['notificationTrayItem', 'get', id]))
|
|
42355
|
+
.filter(isNonNullable)
|
|
42356
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.notificationTray);
|
|
42357
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
42358
|
+
return;
|
|
42359
|
+
this.callback({
|
|
42360
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
42361
|
+
data,
|
|
42362
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
42363
|
+
loading,
|
|
42364
|
+
error,
|
|
42365
|
+
});
|
|
42366
|
+
}
|
|
42367
|
+
}
|
|
42368
|
+
|
|
42369
|
+
/**
|
|
42370
|
+
* Get notification tray items for a notification tray page
|
|
42371
|
+
*
|
|
42372
|
+
* @param params the limit query parameters
|
|
42373
|
+
* @param callback the callback to be called when the notification tray items are updated
|
|
42374
|
+
* @returns items in the notification tray
|
|
42375
|
+
*
|
|
42376
|
+
* @category Notification tray items Live Collection
|
|
42377
|
+
*
|
|
42378
|
+
*/
|
|
42379
|
+
const getNotificationTrayItems = (params, callback, config) => {
|
|
42380
|
+
const { log, cache } = getActiveClient();
|
|
42381
|
+
if (!cache) {
|
|
42382
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
42383
|
+
}
|
|
42384
|
+
const timestamp = Date.now();
|
|
42385
|
+
log(`getNotificationTrayItems(tmpid: ${timestamp}) > listen`);
|
|
42386
|
+
const notiTrayItemsLiveCollection = new NotificationTrayItemsLiveCollectionController(params, callback);
|
|
42387
|
+
const disposers = notiTrayItemsLiveCollection.startSubscription();
|
|
42388
|
+
const cacheKey = notiTrayItemsLiveCollection.getCacheKey();
|
|
42389
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
42390
|
+
return () => {
|
|
42391
|
+
log(`getNotificationTrayItems(tmpid: ${timestamp}) > dispose`);
|
|
42392
|
+
disposers.forEach(fn => fn());
|
|
42393
|
+
};
|
|
42394
|
+
};
|
|
42395
|
+
|
|
42396
|
+
/* begin_public_function
|
|
42397
|
+
id: notificationTrayItem.markSeen
|
|
42398
|
+
*/
|
|
42399
|
+
/**
|
|
42400
|
+
* ```js
|
|
42401
|
+
* import { notificationTray } from '@amityco/ts-sdk'
|
|
42402
|
+
* const updated = await notificationTray.markItemsSeen()
|
|
42403
|
+
* ```
|
|
42404
|
+
*
|
|
42405
|
+
* Updates an {@link Amity.NotificationItemSeen}
|
|
42406
|
+
*
|
|
42407
|
+
* @param trayItems[] that include id and lastTraySeenAt, The ID of the {@link Amity.NotificationItemSeen} to edit
|
|
42408
|
+
* @returns the updated {@link Amity.NotificationItemSeen} object
|
|
42409
|
+
*
|
|
42410
|
+
* @category NotificationItemSeen API
|
|
42411
|
+
* @async
|
|
42412
|
+
*/
|
|
42413
|
+
const markItemsSeen = async (trayItems) => {
|
|
42414
|
+
const client = getActiveClient();
|
|
42415
|
+
client.log('notificationTray/markItemsSeen', {});
|
|
42416
|
+
const { data: payload } = await client.http.post(`api/v1/notification-tray/items/seen`, {
|
|
42417
|
+
trayItems: trayItems.map(item => ({
|
|
42418
|
+
id: item.id,
|
|
42419
|
+
lastSeenAt: item.lastSeenAt,
|
|
42420
|
+
})),
|
|
42421
|
+
});
|
|
42422
|
+
const updatedData = trayItems
|
|
42423
|
+
.map(patchItem => {
|
|
42424
|
+
var _a;
|
|
42425
|
+
const cacheData = (_a = pullFromCache([
|
|
42426
|
+
'notificationTrayItem',
|
|
42427
|
+
'get',
|
|
42428
|
+
patchItem.id,
|
|
42429
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
42430
|
+
if (!cacheData)
|
|
42431
|
+
return;
|
|
42432
|
+
const data = Object.assign(Object.assign({}, cacheData), payload);
|
|
42433
|
+
if (client.cache) {
|
|
42434
|
+
const cachedAt = Date.now();
|
|
42435
|
+
pushToCache(['notificationTrayItem', 'get'], data, { cachedAt });
|
|
42436
|
+
}
|
|
42437
|
+
return data;
|
|
42438
|
+
})
|
|
42439
|
+
.filter(Boolean);
|
|
42440
|
+
fireEvent('local.notificationTrayItem.updated', { notificationTrayItems: updatedData });
|
|
42441
|
+
};
|
|
42442
|
+
/* end_public_function */
|
|
42443
|
+
|
|
42444
|
+
/* begin_public_function
|
|
42445
|
+
id: notificationTray.markSeen
|
|
42446
|
+
*/
|
|
42447
|
+
/**
|
|
42448
|
+
* ```js
|
|
42449
|
+
* import { notificationTray } from '@amityco/ts-sdk'
|
|
42450
|
+
* const updated = await notificationTray.markTraySeen({
|
|
42451
|
+
* lastSeenAt: Amity.timestamp,
|
|
42452
|
+
* })
|
|
42453
|
+
* ```
|
|
42454
|
+
*
|
|
42455
|
+
* Updates an {@link Amity.NotificationTraySeen}
|
|
42456
|
+
*
|
|
42457
|
+
* @param userId The ID of the {@link Amity.NotificationTraySeen} to edit
|
|
42458
|
+
* @param lastSeenAt The patch data to apply
|
|
42459
|
+
* @returns the updated {@link Amity.NotificationTraySeen} object
|
|
42460
|
+
*
|
|
42461
|
+
* @category Post API
|
|
42462
|
+
* @async
|
|
42463
|
+
*/
|
|
42464
|
+
const markTraySeen = async (lastSeenAt) => {
|
|
42465
|
+
var _a;
|
|
42466
|
+
const client = getActiveClient();
|
|
42467
|
+
client.log('notificationTray/markTraySeen', {});
|
|
42468
|
+
const { data: payload } = await client.http.post(`api/v1/notification-tray/tray/seen`, {
|
|
42469
|
+
lastSeenAt,
|
|
42470
|
+
});
|
|
42471
|
+
const cacheData = (_a = pullFromCache([
|
|
42472
|
+
'notificationTraySeen',
|
|
42473
|
+
'get',
|
|
42474
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
42475
|
+
const data = {
|
|
42476
|
+
userId: client.userId,
|
|
42477
|
+
lastTraySeenAt: payload.lastSeenAt,
|
|
42478
|
+
};
|
|
42479
|
+
const updateCacheData = Object.assign(Object.assign({}, cacheData), data);
|
|
42480
|
+
const cachedAt = client.cache && Date.now();
|
|
42481
|
+
if (client.cache)
|
|
42482
|
+
pushToCache(['notificationTraySeen', 'get', client.userId], updateCacheData, { cachedAt });
|
|
42483
|
+
fireEvent('local.notificationTraySeen.updated', data);
|
|
42484
|
+
return {
|
|
42485
|
+
data: payload,
|
|
42486
|
+
cachedAt,
|
|
42487
|
+
};
|
|
42488
|
+
};
|
|
42489
|
+
/* end_public_function */
|
|
42490
|
+
|
|
42491
|
+
var index = /*#__PURE__*/Object.freeze({
|
|
42492
|
+
__proto__: null,
|
|
42493
|
+
getNotificationTraySeen: getNotificationTraySeen,
|
|
42494
|
+
getNotificationTrayItems: getNotificationTrayItems,
|
|
42495
|
+
markItemsSeen: markItemsSeen,
|
|
42496
|
+
markTraySeen: markTraySeen,
|
|
42497
|
+
onNotificationTraySeenUpdated: onNotificationTraySeenUpdated
|
|
42498
|
+
});
|
|
42499
|
+
|
|
42500
|
+
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 };
|