@amityco/ts-sdk 7.1.1-61f30ce0.0 → 7.1.1-67cf0d9.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 +2 -5
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/model.d.ts +2 -4
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +0 -18
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/core/readReceipt.d.ts +12 -1
- package/dist/@types/core/readReceipt.d.ts.map +1 -1
- package/dist/@types/domains/channel.d.ts +10 -0
- package/dist/@types/domains/channel.d.ts.map +1 -1
- package/dist/@types/domains/client.d.ts +2 -0
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/channelRepository/api/markChannelsAsReadBySegment.d.ts +16 -0
- package/dist/channelRepository/api/markChannelsAsReadBySegment.d.ts.map +1 -0
- package/dist/channelRepository/events/onChannelDeleted.d.ts.map +1 -1
- package/dist/channelRepository/events/onChannelLeft.d.ts.map +1 -1
- package/dist/{marker → channelRepository}/events/onChannelUnreadUpdatedLocal.d.ts +2 -2
- package/dist/channelRepository/events/onChannelUnreadUpdatedLocal.d.ts.map +1 -0
- package/dist/channelRepository/internalApi/getTotalChannelsUnread.d.ts +11 -0
- package/dist/channelRepository/internalApi/getTotalChannelsUnread.d.ts.map +1 -0
- package/dist/channelRepository/observers/getChannel.d.ts.map +1 -1
- package/dist/channelRepository/observers/getChannels/ChannelLiveCollectionController.d.ts.map +1 -1
- 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/constructChannelDynamicValue.d.ts.map +1 -1
- package/dist/channelRepository/utils/getLegacyChannelUnread.d.ts +2 -0
- package/dist/channelRepository/utils/getLegacyChannelUnread.d.ts.map +1 -0
- 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/api/enableUnreadCount.d.ts.map +1 -1
- package/dist/client/api/login.d.ts.map +1 -1
- package/dist/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngine.d.ts +33 -0
- package/dist/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngine.d.ts.map +1 -0
- package/dist/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngineOnLoginHandler.d.ts +3 -0
- package/dist/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngineOnLoginHandler.d.ts.map +1 -0
- package/dist/client/utils/ReadReceiptSync/readReceiptSyncEngine.d.ts +2 -4
- 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/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 +599 -477
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +580 -457
- package/dist/index.umd.js +4 -4
- package/dist/marker/events/onChannelUnreadInfoUpdatedLocal.d.ts +12 -0
- package/dist/marker/events/onChannelUnreadInfoUpdatedLocal.d.ts.map +1 -0
- package/dist/messageRepository/events/onMessageCreated.d.ts.map +1 -1
- package/dist/messageRepository/observers/getMessage.d.ts.map +1 -1
- package/dist/messageRepository/utils/markReadMessage.d.ts.map +1 -1
- package/dist/utils/linkedObject/index.d.ts +0 -1
- package/dist/utils/linkedObject/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/core/events.ts +2 -6
- package/src/@types/core/model.ts +4 -6
- package/src/@types/core/payload.ts +0 -25
- package/src/@types/core/readReceipt.ts +14 -1
- package/src/@types/domains/channel.ts +13 -0
- package/src/@types/domains/client.ts +3 -0
- package/src/channelRepository/api/markChannelsAsReadBySegment.ts +29 -0
- package/src/channelRepository/events/onChannelDeleted.ts +17 -4
- package/src/channelRepository/events/onChannelLeft.ts +11 -3
- package/src/{marker → channelRepository}/events/onChannelUnreadUpdatedLocal.ts +3 -3
- package/src/channelRepository/internalApi/getTotalChannelsUnread.ts +38 -0
- package/src/channelRepository/observers/getChannel.ts +3 -1
- package/src/channelRepository/observers/getChannels/ChannelLiveCollectionController.ts +6 -1
- package/src/channelRepository/observers/getTotalChannelsUnread.ts +129 -0
- package/src/channelRepository/observers/index.ts +1 -0
- package/src/channelRepository/utils/constructChannelDynamicValue.ts +12 -2
- package/src/channelRepository/utils/getLegacyChannelUnread.ts +5 -0
- package/src/channelRepository/utils/prepareChannelPayload.ts +68 -17
- package/src/client/api/createClient.ts +7 -1
- package/src/client/api/enableUnreadCount.ts +1 -0
- package/src/client/api/login.ts +5 -1
- package/src/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngine.ts +267 -0
- package/src/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngineOnLoginHandler.ts +21 -0
- package/src/client/utils/ReadReceiptSync/readReceiptSyncEngine.ts +74 -99
- package/src/client/utils/endpoints.ts +1 -0
- package/src/client/utils/setClientToken.ts +8 -0
- package/src/core/model/idResolvers.ts +2 -3
- package/src/core/model/index.ts +0 -2
- package/src/fileRepository/api/uploadFile.ts +1 -1
- package/src/fileRepository/api/uploadImage.ts +1 -1
- package/src/fileRepository/api/uploadVideo.ts +1 -1
- package/src/index.ts +0 -2
- package/src/marker/events/onChannelUnreadInfoUpdatedLocal.ts +29 -0
- package/src/messageRepository/events/onMessageCreated.ts +45 -1
- package/src/messageRepository/observers/getMessage.ts +0 -1
- package/src/messageRepository/utils/markReadMessage.ts +10 -3
- package/src/utils/linkedObject/index.ts +0 -2
- package/dist/@types/domains/notification.d.ts +0 -81
- package/dist/@types/domains/notification.d.ts.map +0 -1
- package/dist/marker/events/onChannelUnreadUpdatedLocal.d.ts.map +0 -1
- package/dist/notificationTrayRepository/api/index.d.ts +0 -3
- package/dist/notificationTrayRepository/api/index.d.ts.map +0 -1
- package/dist/notificationTrayRepository/api/markNotificationItemsSeen.d.ts +0 -16
- package/dist/notificationTrayRepository/api/markNotificationItemsSeen.d.ts.map +0 -1
- package/dist/notificationTrayRepository/api/markNotificationTraySeen.d.ts +0 -19
- package/dist/notificationTrayRepository/api/markNotificationTraySeen.d.ts.map +0 -1
- package/dist/notificationTrayRepository/events/index.d.ts +0 -2
- package/dist/notificationTrayRepository/events/index.d.ts.map +0 -1
- package/dist/notificationTrayRepository/events/onNotificationTraySeenUpdated.d.ts +0 -17
- package/dist/notificationTrayRepository/events/onNotificationTraySeenUpdated.d.ts.map +0 -1
- package/dist/notificationTrayRepository/index.d.ts +0 -4
- package/dist/notificationTrayRepository/index.d.ts.map +0 -1
- package/dist/notificationTrayRepository/internalApi/getNotificationTraySeen.d.ts +0 -30
- package/dist/notificationTrayRepository/internalApi/getNotificationTraySeen.d.ts.map +0 -1
- package/dist/notificationTrayRepository/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.d.ts +0 -13
- package/dist/notificationTrayRepository/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.d.ts.map +0 -1
- package/dist/notificationTrayRepository/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.d.ts +0 -9
- package/dist/notificationTrayRepository/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.d.ts.map +0 -1
- package/dist/notificationTrayRepository/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.d.ts +0 -9
- package/dist/notificationTrayRepository/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.d.ts.map +0 -1
- package/dist/notificationTrayRepository/observers/getNotificationTrayItems.d.ts +0 -12
- package/dist/notificationTrayRepository/observers/getNotificationTrayItems.d.ts.map +0 -1
- package/dist/notificationTrayRepository/observers/getNotificationTraySeen.d.ts +0 -21
- package/dist/notificationTrayRepository/observers/getNotificationTraySeen.d.ts.map +0 -1
- package/dist/notificationTrayRepository/observers/index.d.ts +0 -3
- package/dist/notificationTrayRepository/observers/index.d.ts.map +0 -1
- package/dist/notificationTrayRepository/utils/prepareNotificationTrayItemsPayload.d.ts +0 -2
- package/dist/notificationTrayRepository/utils/prepareNotificationTrayItemsPayload.d.ts.map +0 -1
- package/dist/utils/linkedObject/notificationTrayLinkedObject.d.ts +0 -2
- package/dist/utils/linkedObject/notificationTrayLinkedObject.d.ts.map +0 -1
- package/src/@types/domains/notification.ts +0 -90
- package/src/notificationTrayRepository/api/index.ts +0 -2
- package/src/notificationTrayRepository/api/markNotificationItemsSeen.ts +0 -59
- package/src/notificationTrayRepository/api/markNotificationTraySeen.ts +0 -65
- package/src/notificationTrayRepository/events/index.ts +0 -1
- package/src/notificationTrayRepository/events/onNotificationTraySeenUpdated.ts +0 -36
- package/src/notificationTrayRepository/index.ts +0 -3
- package/src/notificationTrayRepository/internalApi/getNotificationTraySeen.ts +0 -81
- package/src/notificationTrayRepository/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.ts +0 -96
- package/src/notificationTrayRepository/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.ts +0 -31
- package/src/notificationTrayRepository/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.ts +0 -68
- package/src/notificationTrayRepository/observers/getNotificationTrayItems.ts +0 -44
- package/src/notificationTrayRepository/observers/getNotificationTraySeen.ts +0 -43
- package/src/notificationTrayRepository/observers/index.ts +0 -2
- package/src/notificationTrayRepository/utils/prepareNotificationTrayItemsPayload.ts +0 -12
- package/src/utils/linkedObject/notificationTrayLinkedObject.ts +0 -28
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal used only
|
|
3
|
+
*
|
|
4
|
+
* Fired when an {@link Amity.channelUnreadInfo} has been updated.
|
|
5
|
+
*
|
|
6
|
+
* @param callback The function to call when the event was fired
|
|
7
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
8
|
+
*
|
|
9
|
+
* @category ChannelMarker Events
|
|
10
|
+
*/
|
|
11
|
+
export declare const onChannelUnreadInfoUpdatedLocal: (callback: Amity.Listener<Amity.Events['local.channelUnreadInfo.updated']>) => Amity.Unsubscriber;
|
|
12
|
+
//# sourceMappingURL=onChannelUnreadInfoUpdatedLocal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onChannelUnreadInfoUpdatedLocal.d.ts","sourceRoot":"","sources":["../../../src/marker/events/onChannelUnreadInfoUpdatedLocal.ts"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AACH,eAAO,MAAM,+BAA+B,aAChC,MAAM,QAAQ,CAAC,MAAM,MAAM,CAAC,iCAAiC,CAAC,CAAC,KACxE,MAAM,YAaR,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"onMessageCreated.d.ts","sourceRoot":"","sources":["../../../src/messageRepository/events/onMessageCreated.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"onMessageCreated.d.ts","sourceRoot":"","sources":["../../../src/messageRepository/events/onMessageCreated.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,oBAAoB,aACrB,MAAM,QAAQ,CAAC,MAAM,eAAe,CAAC,KAC9C,MAAM,YA0ER,CAAC;AAEF,eAAO,MAAM,qBAAqB,aACtB,MAAM,QAAQ,CAAC,MAAM,eAAe,CAAC,KAC9C,MAAM,YAoBR,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getMessage.d.ts","sourceRoot":"","sources":["../../../src/messageRepository/observers/getMessage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getMessage.d.ts","sourceRoot":"","sources":["../../../src/messageRepository/observers/getMessage.ts"],"names":[],"mappings":"AAmBA;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,UAAU,cACV,MAAM,OAAO,CAAC,WAAW,CAAC,YAC3B,MAAM,kBAAkB,CAAC,MAAM,OAAO,CAAC,KAChD,MAAM,YAmBR,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markReadMessage.d.ts","sourceRoot":"","sources":["../../../src/messageRepository/utils/markReadMessage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"markReadMessage.d.ts","sourceRoot":"","sources":["../../../src/messageRepository/utils/markReadMessage.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,eAAe,YAAa,MAAM,eAAe,SAU7D,CAAC"}
|
|
@@ -11,6 +11,5 @@ export declare const LinkedObject: {
|
|
|
11
11
|
reactor: (reactor: Amity.InternalReactor) => Amity.Reactor;
|
|
12
12
|
channel: (channel: Amity.InternalChannel<any>) => Amity.Channel<any>;
|
|
13
13
|
pinnedPost: (pinnedPost: Amity.RawPin) => Amity.PinnedPost;
|
|
14
|
-
notificationTray: (noti: Amity.RawNotificationTrayItem) => Amity.NotificationTrayItem;
|
|
15
14
|
};
|
|
16
15
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/linkedObject/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/linkedObject/index.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,YAAY;;;;;;;;;;;;;CAaxB,CAAC"}
|
package/package.json
CHANGED
|
@@ -237,7 +237,8 @@ declare global {
|
|
|
237
237
|
};
|
|
238
238
|
|
|
239
239
|
'local.subChannelUnread.updated': Amity.SubChannelUnreadInfo;
|
|
240
|
-
'local.
|
|
240
|
+
'local.channelUnreadInfo.updated': Amity.ChannelUnreadInfo;
|
|
241
|
+
'local.channelUnread.updated': Amity.ChannelUnread;
|
|
241
242
|
|
|
242
243
|
'local.story.created': Amity.StoryPayload;
|
|
243
244
|
'local.story.updated': Amity.StoryPayload;
|
|
@@ -255,11 +256,6 @@ declare global {
|
|
|
255
256
|
'local.story.error': Amity.StoryPayload;
|
|
256
257
|
'local.story.reload': { referenceIds: Amity.Story['referenceId'][] };
|
|
257
258
|
|
|
258
|
-
'local.notificationTraySeen.updated': Amity.InternalNotificationTraySeen;
|
|
259
|
-
'local.notificationTrayItem.updated': {
|
|
260
|
-
notificationTrayItems: Amity.InternalNotificationTrayItem[];
|
|
261
|
-
};
|
|
262
|
-
|
|
263
259
|
sessionStateChange: Amity.SessionStates;
|
|
264
260
|
// used by accessTokenExpiryWatcher
|
|
265
261
|
tokenExpired: Amity.SessionStates.TOKEN_EXPIRED;
|
package/src/@types/core/model.ts
CHANGED
|
@@ -25,6 +25,8 @@ declare global {
|
|
|
25
25
|
channelUnreadInfo: Amity.ChannelUnreadInfo;
|
|
26
26
|
subChannelUnreadInfo: Amity.SubChannelUnreadInfo;
|
|
27
27
|
|
|
28
|
+
channelUnread: Amity.ChannelUnread;
|
|
29
|
+
|
|
28
30
|
channelMarker: Amity.ChannelMarker;
|
|
29
31
|
subChannelMarker: Amity.SubChannelMarker;
|
|
30
32
|
messageMarker: Amity.MessageMarker;
|
|
@@ -55,9 +57,6 @@ declare global {
|
|
|
55
57
|
|
|
56
58
|
pinTarget: Amity.InternalPinTarget;
|
|
57
59
|
pin: Amity.InternalPin;
|
|
58
|
-
|
|
59
|
-
notificationTrayItem: Amity.InternalNotificationTrayItem;
|
|
60
|
-
notificationTraySeen: Amity.InternalNotificationTraySeen;
|
|
61
60
|
};
|
|
62
61
|
|
|
63
62
|
type Model = ValueOf<Models>;
|
|
@@ -87,6 +86,8 @@ declare global {
|
|
|
87
86
|
channelUnreadInfo: Pick<Amity.ChannelUnreadInfo, 'channelId'>;
|
|
88
87
|
subChannelUnreadInfo: Pick<Amity.SubChannelUnreadInfo, 'subChannelId'>;
|
|
89
88
|
|
|
89
|
+
channelUnread: Pick<Amity.ChannelUnread, 'channelId'>;
|
|
90
|
+
|
|
90
91
|
channelMarker: Pick<Amity.ChannelMarker, 'entityId' | 'userId'>;
|
|
91
92
|
subChannelMarker: Pick<Amity.SubChannelMarker, 'feedId' | 'entityId' | 'userId'>;
|
|
92
93
|
messageMarker: Pick<Amity.MessageMarker, 'feedId' | 'contentId' | 'creatorId'>;
|
|
@@ -117,9 +118,6 @@ declare global {
|
|
|
117
118
|
|
|
118
119
|
pinTarget: Pick<Amity.InternalPinTarget, 'targetId'>;
|
|
119
120
|
pin: Pick<Amity.InternalPin, 'placement' | 'referenceId'>;
|
|
120
|
-
|
|
121
|
-
notificationTrayItem: Amity.InternalNotificationTrayItem;
|
|
122
|
-
notificationTraySeen: Amity.InternalNotificationTraySeen;
|
|
123
121
|
};
|
|
124
122
|
}
|
|
125
123
|
}
|
|
@@ -26,7 +26,6 @@ declare global {
|
|
|
26
26
|
blockUser: Amity.BlockedUserPayload;
|
|
27
27
|
semanticSearchPost: Amity.SemanticSearchPostPayload;
|
|
28
28
|
semanticSearchCommunity: Amity.SemanticSearchCommunityPayload;
|
|
29
|
-
notificationTrayItem: Amity.NotificationTrayPayload;
|
|
30
29
|
};
|
|
31
30
|
|
|
32
31
|
type UserPayload = {
|
|
@@ -379,30 +378,6 @@ declare global {
|
|
|
379
378
|
reactions: Amity.InternalReactor[];
|
|
380
379
|
} & Amity.StoryPayload;
|
|
381
380
|
|
|
382
|
-
type NotificationTrayPayload = {
|
|
383
|
-
notificationTrayItems: Amity.RawNotificationTrayItem[];
|
|
384
|
-
users: Amity.RawUser[];
|
|
385
|
-
files?: Amity.File[];
|
|
386
|
-
};
|
|
387
|
-
|
|
388
|
-
type ProcessedNotificationTrayPayload = Omit<
|
|
389
|
-
NotificationTrayPayload,
|
|
390
|
-
'notificationTrayItems' | 'users'
|
|
391
|
-
> & {
|
|
392
|
-
notificationTrayItems: Amity.InternalNotificationTrayItem[];
|
|
393
|
-
users: Amity.InternalUser[];
|
|
394
|
-
files?: Amity.File[];
|
|
395
|
-
};
|
|
396
|
-
|
|
397
|
-
type NotificationTraySeenPayload = {
|
|
398
|
-
lastTraySeenAt: Amity.timestamp;
|
|
399
|
-
lastTrayOccuredAt: Amity.timestamp;
|
|
400
|
-
};
|
|
401
|
-
|
|
402
|
-
type NotificationTraySeenUpdatedPayload = {
|
|
403
|
-
lastTraySeenAt: Amity.timestamp;
|
|
404
|
-
};
|
|
405
|
-
|
|
406
381
|
/**
|
|
407
382
|
* Items that extend from `Amity.PostPayload`
|
|
408
383
|
* - communities: `Amity.RawCommunity` -> `Amity.Community` (Added Marker Service related props)
|
|
@@ -8,12 +8,25 @@ declare global {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
type ReadReceipt = {
|
|
11
|
-
|
|
11
|
+
channelId: Amity.Channel['channelId'];
|
|
12
12
|
latestSegment: number;
|
|
13
13
|
latestSyncSegment: number;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
type ReadReceiptSyncJob = {
|
|
17
|
+
channelId: Amity.Channel['channelId'];
|
|
18
|
+
segment: number;
|
|
19
|
+
syncState: ReadReceiptSyncState;
|
|
20
|
+
retryCount: number;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
type LegacyReadReceipt = {
|
|
24
|
+
subChannelId: Amity.SubChannel['subChannelId'];
|
|
25
|
+
latestSegment: number;
|
|
26
|
+
latestSyncSegment: number;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
type LegacyReadReceiptSyncJob = {
|
|
17
30
|
subChannelId: Amity.SubChannel['subChannelId'];
|
|
18
31
|
segment: number;
|
|
19
32
|
syncState: ReadReceiptSyncState;
|
|
@@ -84,6 +84,8 @@ declare global {
|
|
|
84
84
|
> & {
|
|
85
85
|
isMentioned: boolean;
|
|
86
86
|
subChannelsUnreadCount: number;
|
|
87
|
+
// legacy unread count does not use the maker service
|
|
88
|
+
unreadCount: number;
|
|
87
89
|
};
|
|
88
90
|
|
|
89
91
|
/* public type */
|
|
@@ -137,5 +139,16 @@ declare global {
|
|
|
137
139
|
Amity.Membership<'channel'>['userId'],
|
|
138
140
|
Pick<QueryChannelMembers, 'page'>
|
|
139
141
|
>;
|
|
142
|
+
|
|
143
|
+
// Use for channel's unread count value stored in the local cache
|
|
144
|
+
type ChannelUnread = {
|
|
145
|
+
channelId: Amity.Channel['channelId'];
|
|
146
|
+
unreadCount: number;
|
|
147
|
+
isMentioned: boolean;
|
|
148
|
+
readToSegment: number | null;
|
|
149
|
+
lastSegment: number;
|
|
150
|
+
lastMentionedSegment: number | null;
|
|
151
|
+
isDeleted: boolean;
|
|
152
|
+
};
|
|
140
153
|
}
|
|
141
154
|
}
|
|
@@ -36,6 +36,7 @@ declare global {
|
|
|
36
36
|
|
|
37
37
|
log: Logger;
|
|
38
38
|
http: AxiosInstance;
|
|
39
|
+
upload: AxiosInstance;
|
|
39
40
|
mqtt?: Amity.MqttClient;
|
|
40
41
|
ws?: SocketIOClient.Socket;
|
|
41
42
|
emitter: Emitter<Amity.Events>;
|
|
@@ -56,6 +57,8 @@ declare global {
|
|
|
56
57
|
|
|
57
58
|
isUnreadCountEnabled: boolean;
|
|
58
59
|
|
|
60
|
+
useLegacyUnreadCount: boolean;
|
|
61
|
+
|
|
59
62
|
use: () => void;
|
|
60
63
|
|
|
61
64
|
accessTokenExpiryWatcher: (sessionHandler: Amity.SessionHandler) => Amity.Unsubscriber;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api/activeClient';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* Mark subChannel as read by readToSegment
|
|
6
|
+
*
|
|
7
|
+
* @param subChannelIds the IDs of the {@link Amity.SubChannel} to update
|
|
8
|
+
* @param readToSegment the segment to mark as read
|
|
9
|
+
* @returns a success boolean if the {@link Amity.SubChannel} was updated
|
|
10
|
+
*
|
|
11
|
+
* @category Channel API
|
|
12
|
+
* @async
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export const markChannelsAsReadBySegment = async (
|
|
16
|
+
readings: {
|
|
17
|
+
channelId: Amity.Channel['channelId'];
|
|
18
|
+
readToSegment: number;
|
|
19
|
+
}[],
|
|
20
|
+
): Promise<boolean> => {
|
|
21
|
+
const client = getActiveClient();
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
await client.http.post<Amity.MarkAsReadPayload>('api/v3/channels/seen', { channels: readings });
|
|
25
|
+
return true;
|
|
26
|
+
} catch (e) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
@@ -6,6 +6,7 @@ import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
|
6
6
|
import { prepareChannelPayload } from '../utils/prepareChannelPayload';
|
|
7
7
|
import { addFlagIsDeletedSubChannelUnreadByChannelId } from '~/marker/utils/addFlagIsDeletedSubChannelUnreadByChannelId';
|
|
8
8
|
import { deleteChannelUnreadByChannelId } from '../../marker/utils/deleteChannelUnreadByChannelId';
|
|
9
|
+
import { dropFromCache, pullFromCache, pushToCache } from '~/cache/api';
|
|
9
10
|
|
|
10
11
|
type CallbackFn = (channel: Amity.StaticInternalChannel) => void;
|
|
11
12
|
const callbacks: CallbackFn[] = [];
|
|
@@ -28,12 +29,24 @@ export const onChannelDeleted = (callback: Amity.Listener<Amity.StaticInternalCh
|
|
|
28
29
|
const filter = async (payload: Amity.ChannelPayload) => {
|
|
29
30
|
const data = await prepareChannelPayload(payload);
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
const isConsistentMode = client.getMarkerSyncConsistentMode() && client.isUnreadCountEnabled;
|
|
33
|
+
const isLegacyUnreadCount = client.useLegacyUnreadCount;
|
|
34
|
+
|
|
35
|
+
data.channels.forEach(channel => {
|
|
36
|
+
if (isConsistentMode) {
|
|
33
37
|
addFlagIsDeletedSubChannelUnreadByChannelId(channel.channelId);
|
|
34
38
|
deleteChannelUnreadByChannelId(channel.channelId);
|
|
35
|
-
})
|
|
36
|
-
|
|
39
|
+
} else if (isLegacyUnreadCount) {
|
|
40
|
+
const cacheKey = ['channelUnread', 'get', channel.channelId];
|
|
41
|
+
const cache = pullFromCache<Amity.ChannelUnread>(cacheKey);
|
|
42
|
+
if (cache) {
|
|
43
|
+
pushToCache(cacheKey, {
|
|
44
|
+
...cache,
|
|
45
|
+
isDeleted: true,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
});
|
|
37
50
|
|
|
38
51
|
ingestInCache(data);
|
|
39
52
|
callbacks.forEach(cb => cb(data.channels[0]));
|
|
@@ -6,6 +6,7 @@ import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
|
6
6
|
import { prepareChannelPayload } from '../utils';
|
|
7
7
|
import { deleteChannelUnreadByChannelId } from '../../marker/utils/deleteChannelUnreadByChannelId';
|
|
8
8
|
import { addFlagIsDeletedSubChannelUnreadByChannelId } from '~/marker/utils/addFlagIsDeletedSubChannelUnreadByChannelId';
|
|
9
|
+
import { dropFromCache } from '~/cache/api';
|
|
9
10
|
|
|
10
11
|
type CallbackFn = (
|
|
11
12
|
channel: Amity.StaticInternalChannel,
|
|
@@ -40,10 +41,17 @@ export const onChannelLeft = (
|
|
|
40
41
|
isMessagePreviewUpdated: isLeftByMe,
|
|
41
42
|
});
|
|
42
43
|
|
|
43
|
-
|
|
44
|
+
const isConsistentMode = client.getMarkerSyncConsistentMode() && client.isUnreadCountEnabled;
|
|
45
|
+
const isLegacyUnreadCount = client.useLegacyUnreadCount;
|
|
46
|
+
|
|
47
|
+
if (isLeftByMe) {
|
|
44
48
|
preparedPayload.channels.forEach(channel => {
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
if (isConsistentMode) {
|
|
50
|
+
addFlagIsDeletedSubChannelUnreadByChannelId(channel.channelId);
|
|
51
|
+
deleteChannelUnreadByChannelId(channel.channelId);
|
|
52
|
+
} else if (isLegacyUnreadCount) {
|
|
53
|
+
dropFromCache(['channelUnread', 'get', channel.channelId]);
|
|
54
|
+
}
|
|
47
55
|
});
|
|
48
56
|
}
|
|
49
57
|
|
|
@@ -4,12 +4,12 @@ import { createEventSubscriber } from '~/core/events';
|
|
|
4
4
|
/**
|
|
5
5
|
* Internal used only
|
|
6
6
|
*
|
|
7
|
-
* Fired when an {@link Amity.
|
|
7
|
+
* Fired when an {@link Amity.ChannelUnread} has been updated.
|
|
8
8
|
*
|
|
9
9
|
* @param callback The function to call when the event was fired
|
|
10
10
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
11
11
|
*
|
|
12
|
-
* @category
|
|
12
|
+
* @category Channel Events
|
|
13
13
|
*/
|
|
14
14
|
export const onChannelUnreadUpdatedLocal = (
|
|
15
15
|
callback: Amity.Listener<Amity.Events['local.channelUnread.updated']>,
|
|
@@ -22,7 +22,7 @@ export const onChannelUnreadUpdatedLocal = (
|
|
|
22
22
|
|
|
23
23
|
return createEventSubscriber(
|
|
24
24
|
client,
|
|
25
|
-
'
|
|
25
|
+
'channel/onChannelUnreadUpdatedLocal',
|
|
26
26
|
'local.channelUnread.updated',
|
|
27
27
|
filter,
|
|
28
28
|
);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { queryCache } from '~/cache/api';
|
|
2
|
+
import { getActiveClient } from '~/client/api/activeClient';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* Calculate user unread from {@link Amity.ChannelUnread} objects
|
|
7
|
+
*
|
|
8
|
+
* @returns the {@link Amity.UserUnread} objects
|
|
9
|
+
*
|
|
10
|
+
* @category Channel API
|
|
11
|
+
* @async
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export const getTotalChannelsUnread = (): Amity.Cached<Amity.UserUnread> => {
|
|
15
|
+
const client = getActiveClient();
|
|
16
|
+
client.log('channel/getTotalChannelsUnread.locally');
|
|
17
|
+
|
|
18
|
+
const cachedChannelsUnread =
|
|
19
|
+
queryCache<Amity.ChannelUnread>(['channelUnread', 'get'])?.filter(({ data }) => {
|
|
20
|
+
return !data.isDeleted;
|
|
21
|
+
}) || [];
|
|
22
|
+
|
|
23
|
+
const totalChannelsUnread: Amity.UserUnread = cachedChannelsUnread?.reduce(
|
|
24
|
+
(acc, { data }) => {
|
|
25
|
+
acc.unreadCount += data.unreadCount;
|
|
26
|
+
acc.isMentioned = acc.isMentioned || data.isMentioned;
|
|
27
|
+
return acc;
|
|
28
|
+
},
|
|
29
|
+
{ unreadCount: 0, isMentioned: false as boolean },
|
|
30
|
+
) || { unreadCount: 0, isMentioned: false };
|
|
31
|
+
|
|
32
|
+
const cachedAt = client.cache && Date.now();
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
data: totalChannelsUnread,
|
|
36
|
+
cachedAt,
|
|
37
|
+
};
|
|
38
|
+
};
|
|
@@ -32,8 +32,9 @@ import { isEqual } from '~/utils/isEqual';
|
|
|
32
32
|
import { updateChannelCache } from '../utils/updateChannelCache';
|
|
33
33
|
import { onChannelMarkerUpdated } from '~/marker/events/onChannelMarkerUpdated';
|
|
34
34
|
import { onSubChannelCreated } from '~/subChannelRepository';
|
|
35
|
-
import {
|
|
35
|
+
import { onChannelUnreadInfoUpdatedLocal } from '~/marker/events/onChannelUnreadInfoUpdatedLocal';
|
|
36
36
|
import { constructChannelObject } from '../utils/constructChannelObject';
|
|
37
|
+
import { onChannelUnreadUpdatedLocal } from '../events/onChannelUnreadUpdatedLocal';
|
|
37
38
|
|
|
38
39
|
/* begin_public_function
|
|
39
40
|
id: channel.get
|
|
@@ -295,6 +296,7 @@ export const getChannel = (
|
|
|
295
296
|
'channel',
|
|
296
297
|
),
|
|
297
298
|
convertEventPayload(onSubChannelCreated, 'channelId', 'channel'),
|
|
299
|
+
convertEventPayload(onChannelUnreadInfoUpdatedLocal, 'channelId', 'channel'),
|
|
298
300
|
convertEventPayload(onChannelUnreadUpdatedLocal, 'channelId', 'channel'),
|
|
299
301
|
],
|
|
300
302
|
{
|
|
@@ -55,8 +55,9 @@ import { prepareUnreadCountInfo } from '~/channelRepository/utils/prepareUnreadC
|
|
|
55
55
|
import { resolveUnreadInfoOnChannelEvent } from '~/channelRepository/utils/resolveUnreadInfoOnChannelEvent';
|
|
56
56
|
import { onChannelResolved } from '~/channelRepository/events/onChannelResolved';
|
|
57
57
|
import { onUserMessageFeedMarkerResolved } from '~/marker/events/onUserMessageFeedMarkerResolved';
|
|
58
|
-
import {
|
|
58
|
+
import { onChannelUnreadInfoUpdatedLocal } from '~/marker/events/onChannelUnreadInfoUpdatedLocal';
|
|
59
59
|
import { constructChannelObject } from '~/channelRepository/utils/constructChannelObject';
|
|
60
|
+
import { onChannelUnreadUpdatedLocal } from '~/channelRepository/events/onChannelUnreadUpdatedLocal';
|
|
60
61
|
|
|
61
62
|
export class ChannelLiveCollectionController extends LiveCollectionController<
|
|
62
63
|
'channel',
|
|
@@ -566,6 +567,10 @@ export class ChannelLiveCollectionController extends LiveCollectionController<
|
|
|
566
567
|
},
|
|
567
568
|
action: Amity.ChannelActionType.OnResolveUnread,
|
|
568
569
|
},
|
|
570
|
+
{
|
|
571
|
+
fn: convertEventPayload(onChannelUnreadInfoUpdatedLocal, 'channelId', 'channel'),
|
|
572
|
+
action: Amity.ChannelActionType.OnUpdate,
|
|
573
|
+
},
|
|
569
574
|
{
|
|
570
575
|
fn: convertEventPayload(onChannelUnreadUpdatedLocal, 'channelId', 'channel'),
|
|
571
576
|
action: Amity.ChannelActionType.OnUpdate,
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { getActiveUser } from '~/client/api/activeUser';
|
|
2
|
+
import { getTotalChannelsUnread as _getTotalChannelsUnread } from '../internalApi/getTotalChannelsUnread';
|
|
3
|
+
import { onChannelUnreadUpdatedLocal } from '../events/onChannelUnreadUpdatedLocal';
|
|
4
|
+
import { ASCApiError, ASCError } from '~/core/errors';
|
|
5
|
+
import { getActiveClient } from '~/client';
|
|
6
|
+
import { convertGetterPropsToStatic } from '~/utils/object';
|
|
7
|
+
import { createQuery, runQuery } from '~/core/query';
|
|
8
|
+
import {
|
|
9
|
+
UNSYNCED_OBJECT_CACHED_AT_MESSAGE,
|
|
10
|
+
UNSYNCED_OBJECT_CACHED_AT_VALUE,
|
|
11
|
+
} from '~/utils/constants';
|
|
12
|
+
import { isEqual } from '~/utils/isEqual';
|
|
13
|
+
|
|
14
|
+
/* begin_public_function
|
|
15
|
+
id: totalChannelsUnread.get
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* ```js
|
|
19
|
+
* import { ChannelRepository } from '@amityco/ts-sdk';
|
|
20
|
+
*
|
|
21
|
+
* let totalChannelsUnread;
|
|
22
|
+
*
|
|
23
|
+
* const unsubscribe = ChannelRepository.getTotalChannelsUnread(response => {
|
|
24
|
+
* unread = response.data;
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* Observe all mutation on a given {@link Amity.UserUnread}
|
|
29
|
+
*
|
|
30
|
+
* @returns An {@link Amity.UserUnread} function to run when willing to stop observing the message
|
|
31
|
+
*
|
|
32
|
+
* @category User Unread Live Object
|
|
33
|
+
*
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
export const getTotalChannelsUnread = (
|
|
37
|
+
callback: Amity.LiveObjectCallback<Amity.UserUnread | undefined>,
|
|
38
|
+
): Amity.Unsubscriber => {
|
|
39
|
+
const { _id: userId } = getActiveUser();
|
|
40
|
+
|
|
41
|
+
if (!userId)
|
|
42
|
+
throw new ASCError(
|
|
43
|
+
'The _id has not been defined in ActiveUser',
|
|
44
|
+
Amity.ClientError.UNKNOWN_ERROR,
|
|
45
|
+
Amity.ErrorLevel.ERROR,
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
const { log, cache } = getActiveClient();
|
|
49
|
+
|
|
50
|
+
if (!cache) {
|
|
51
|
+
console.log('For using Live Object feature you need to enable Cache!');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const timestamp = Date.now();
|
|
55
|
+
log(`liveTotalChannelsUnread(tmpid: ${timestamp}) > listen`);
|
|
56
|
+
|
|
57
|
+
const disposers: Amity.Unsubscriber[] = [];
|
|
58
|
+
|
|
59
|
+
let isUnsyncedModel = false; // for messages
|
|
60
|
+
|
|
61
|
+
let model: Amity.UserUnread | undefined;
|
|
62
|
+
|
|
63
|
+
const dispatcher = (data: Amity.LiveObject<Amity.UserUnread | undefined>) => {
|
|
64
|
+
const { data: userUnread } = data;
|
|
65
|
+
|
|
66
|
+
const callbackModel = userUnread
|
|
67
|
+
? {
|
|
68
|
+
unreadCount: userUnread.unreadCount,
|
|
69
|
+
isMentioned: userUnread.isMentioned,
|
|
70
|
+
}
|
|
71
|
+
: undefined;
|
|
72
|
+
|
|
73
|
+
model = callbackModel ? convertGetterPropsToStatic(callbackModel) : callbackModel;
|
|
74
|
+
|
|
75
|
+
callback({
|
|
76
|
+
data: callbackModel
|
|
77
|
+
? { ...callbackModel, isMentioned: callbackModel.isMentioned }
|
|
78
|
+
: callbackModel,
|
|
79
|
+
|
|
80
|
+
loading: data.loading,
|
|
81
|
+
error: data.error,
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const realtimeRouter = (userUnread: Amity.UserUnread) => {
|
|
86
|
+
if (isEqual(model, userUnread)) return;
|
|
87
|
+
|
|
88
|
+
dispatcher({
|
|
89
|
+
loading: false,
|
|
90
|
+
data: userUnread,
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const onFetch = () => {
|
|
95
|
+
const query = createQuery(async () => _getTotalChannelsUnread());
|
|
96
|
+
|
|
97
|
+
runQuery(query, ({ error, data, loading, origin, cachedAt }) => {
|
|
98
|
+
if (cachedAt === UNSYNCED_OBJECT_CACHED_AT_VALUE) {
|
|
99
|
+
dispatcher({
|
|
100
|
+
data,
|
|
101
|
+
origin,
|
|
102
|
+
loading: false,
|
|
103
|
+
error: new ASCApiError(
|
|
104
|
+
UNSYNCED_OBJECT_CACHED_AT_MESSAGE,
|
|
105
|
+
Amity.ClientError.DISALOOW_UNSYNCED_OBJECT,
|
|
106
|
+
Amity.ErrorLevel.ERROR,
|
|
107
|
+
),
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
isUnsyncedModel = true;
|
|
111
|
+
disposers.forEach(fn => fn());
|
|
112
|
+
} else if (!isUnsyncedModel) {
|
|
113
|
+
dispatcher({ loading, data, origin, error });
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (error) {
|
|
117
|
+
disposers.forEach(fn => fn());
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
disposers.push(onChannelUnreadUpdatedLocal(realtimeRouter));
|
|
123
|
+
|
|
124
|
+
onFetch();
|
|
125
|
+
|
|
126
|
+
return () => {
|
|
127
|
+
disposers.forEach(fn => fn());
|
|
128
|
+
};
|
|
129
|
+
};
|
|
@@ -1,17 +1,27 @@
|
|
|
1
|
+
import { get } from 'http';
|
|
1
2
|
import { shallowClone } from '~/utils/shallowClone';
|
|
2
3
|
import { getChannelIsMentioned } from './getChannelIsMentioned';
|
|
3
4
|
import { getSubChannelsUnreadCount } from './getSubChannelsUnreadCount';
|
|
5
|
+
import { getActiveClient } from '~/client/api/activeClient';
|
|
6
|
+
import { getLegacyChannelUnread } from './getLegacyChannelUnread';
|
|
4
7
|
|
|
5
8
|
export const constructChannelDynamicValue = (
|
|
6
9
|
channel: Amity.StaticInternalChannel,
|
|
7
10
|
): Amity.InternalChannel => {
|
|
11
|
+
const client = getActiveClient();
|
|
8
12
|
const { messageCount, ...rest } = channel;
|
|
13
|
+
|
|
9
14
|
return shallowClone(rest, {
|
|
10
|
-
get
|
|
11
|
-
return
|
|
15
|
+
get unreadCount() {
|
|
16
|
+
return getLegacyChannelUnread(rest.channelId)?.unreadCount ?? 0;
|
|
12
17
|
},
|
|
13
18
|
get subChannelsUnreadCount() {
|
|
14
19
|
return getSubChannelsUnreadCount(rest);
|
|
15
20
|
},
|
|
21
|
+
get isMentioned() {
|
|
22
|
+
if (client.useLegacyUnreadCount)
|
|
23
|
+
return getLegacyChannelUnread(rest.channelId)?.isMentioned ?? false;
|
|
24
|
+
return getChannelIsMentioned(rest);
|
|
25
|
+
},
|
|
16
26
|
});
|
|
17
27
|
};
|