@amityco/ts-sdk 7.1.1-611ceb49.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
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { QueryStreamController } from '~/core/liveCollection/QueryStreamController';
|
|
2
|
-
import { pullFromCache, pushToCache } from '~/cache/api';
|
|
3
|
-
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
|
-
import { getResolver } from '~/core/model';
|
|
5
|
-
import { getActiveClient } from '~/client';
|
|
6
|
-
|
|
7
|
-
export class NotificationTrayItemsQuerystreamController extends QueryStreamController<
|
|
8
|
-
Amity.NotificationTrayPayload,
|
|
9
|
-
Amity.NotificationTrayItemLiveCollection
|
|
10
|
-
> {
|
|
11
|
-
private notifyChange: (params: Amity.LiveCollectionNotifyParams) => void;
|
|
12
|
-
|
|
13
|
-
private preparePayload: (
|
|
14
|
-
response: Amity.NotificationTrayPayload,
|
|
15
|
-
) => Amity.ProcessedNotificationTrayPayload;
|
|
16
|
-
|
|
17
|
-
constructor(
|
|
18
|
-
query: Amity.NotificationTrayItemLiveCollection,
|
|
19
|
-
cacheKey: string[],
|
|
20
|
-
notifyChange: (params: Amity.LiveCollectionNotifyParams) => void,
|
|
21
|
-
preparePayload: (
|
|
22
|
-
response: Amity.NotificationTrayPayload,
|
|
23
|
-
) => Amity.ProcessedNotificationTrayPayload,
|
|
24
|
-
) {
|
|
25
|
-
super(query, cacheKey);
|
|
26
|
-
this.notifyChange = notifyChange;
|
|
27
|
-
this.preparePayload = preparePayload;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
async saveToMainDB(response: Amity.NotificationTrayPayload) {
|
|
31
|
-
const processedPayload = await this.preparePayload(response);
|
|
32
|
-
|
|
33
|
-
const client = getActiveClient();
|
|
34
|
-
const cachedAt = client.cache && Date.now();
|
|
35
|
-
|
|
36
|
-
if (client.cache) {
|
|
37
|
-
ingestInCache(processedPayload, { cachedAt });
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
appendToQueryStream(
|
|
42
|
-
response: Amity.NotificationTrayPayload & Partial<Amity.Pagination>,
|
|
43
|
-
direction: Amity.LiveCollectionPageDirection,
|
|
44
|
-
refresh = false,
|
|
45
|
-
) {
|
|
46
|
-
if (refresh) {
|
|
47
|
-
pushToCache(this.cacheKey, {
|
|
48
|
-
data: response.notificationTrayItems.map(getResolver('notificationTrayItem')),
|
|
49
|
-
});
|
|
50
|
-
} else {
|
|
51
|
-
const collection = pullFromCache<Amity.NotificationTrayItemLiveCollectionCache>(
|
|
52
|
-
this.cacheKey,
|
|
53
|
-
)?.data;
|
|
54
|
-
|
|
55
|
-
const notifications = collection?.data ?? [];
|
|
56
|
-
|
|
57
|
-
pushToCache(this.cacheKey, {
|
|
58
|
-
...collection,
|
|
59
|
-
data: [
|
|
60
|
-
...new Set([
|
|
61
|
-
...notifications,
|
|
62
|
-
...response.notificationTrayItems.map(getResolver('notificationTrayItem')),
|
|
63
|
-
]),
|
|
64
|
-
],
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { getActiveClient } from '~/client/api';
|
|
2
|
-
import { dropFromCache } from '~/cache/api';
|
|
3
|
-
import { ENABLE_CACHE_MESSAGE } from '~/utils/constants';
|
|
4
|
-
import { NotificationTrayItemsLiveCollectionController } from './getNotificationTrayItems/NotificationTrayItemsLiveCollectionController';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Get notification tray items for a notification tray page
|
|
8
|
-
*
|
|
9
|
-
* @param params the limit query parameters
|
|
10
|
-
* @param callback the callback to be called when the notification tray items are updated
|
|
11
|
-
* @returns items in the notification tray
|
|
12
|
-
*
|
|
13
|
-
* @category Notification tray items Live Collection
|
|
14
|
-
*
|
|
15
|
-
*/
|
|
16
|
-
export const getNotificationTrayItems = (
|
|
17
|
-
params: Amity.LiveCollectionParams<Amity.NotificationTrayItemLiveCollection>,
|
|
18
|
-
callback: Amity.LiveCollectionCallback<Amity.RawNotificationTrayItem>,
|
|
19
|
-
config?: Amity.LiveCollectionConfig,
|
|
20
|
-
) => {
|
|
21
|
-
const { log, cache } = getActiveClient();
|
|
22
|
-
|
|
23
|
-
if (!cache) {
|
|
24
|
-
console.log(ENABLE_CACHE_MESSAGE);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const timestamp = Date.now();
|
|
28
|
-
log(`getNotificationTrayItems(tmpid: ${timestamp}) > listen`);
|
|
29
|
-
|
|
30
|
-
const notiTrayItemsLiveCollection = new NotificationTrayItemsLiveCollectionController(
|
|
31
|
-
params,
|
|
32
|
-
callback,
|
|
33
|
-
);
|
|
34
|
-
const disposers = notiTrayItemsLiveCollection.startSubscription();
|
|
35
|
-
|
|
36
|
-
const cacheKey = notiTrayItemsLiveCollection.getCacheKey();
|
|
37
|
-
|
|
38
|
-
disposers.push(() => dropFromCache(cacheKey));
|
|
39
|
-
|
|
40
|
-
return () => {
|
|
41
|
-
log(`getNotificationTrayItems(tmpid: ${timestamp}) > dispose`);
|
|
42
|
-
disposers.forEach(fn => fn());
|
|
43
|
-
};
|
|
44
|
-
};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { liveObject } from '~/utils/liveObject';
|
|
2
|
-
import { getNotificationTraySeen as _getNotificationTraySeen } from '../internalApi/getNotificationTraySeen';
|
|
3
|
-
import { onNotificationTraySeenUpdated } from '../events/onNotificationTraySeenUpdated';
|
|
4
|
-
import { getActiveUser } from '~/client';
|
|
5
|
-
|
|
6
|
-
/* begin_public_function
|
|
7
|
-
id: notificationTraySeen.get
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* ```js
|
|
11
|
-
* import { getNotificationTraySeen } from '@amityco/ts-sdk';
|
|
12
|
-
*
|
|
13
|
-
* let notificationTraySeen;
|
|
14
|
-
*
|
|
15
|
-
* const unsubscribe = getNotificationTraySeen(userId, response => {
|
|
16
|
-
* notificationTraySeen = response.data;
|
|
17
|
-
* });
|
|
18
|
-
* ```
|
|
19
|
-
*
|
|
20
|
-
* Observe all mutation on a given {@link Amity.NotificationTraySeen}
|
|
21
|
-
*
|
|
22
|
-
* @param userId the ID of the user to observe
|
|
23
|
-
* @param callback the function to call when new data are available
|
|
24
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the message
|
|
25
|
-
*
|
|
26
|
-
* @category NotificationTraySeen Live Object
|
|
27
|
-
*/
|
|
28
|
-
export const getNotificationTraySeen = (
|
|
29
|
-
callback: Amity.LiveObjectCallback<Amity.NotificationTraySeenPayload>,
|
|
30
|
-
): Amity.Unsubscriber => {
|
|
31
|
-
const responder: Amity.LiveObjectCallback<Amity.InternalNotificationTraySeen> = (
|
|
32
|
-
snapshot: Amity.LiveObject<Amity.InternalNotificationTraySeen>,
|
|
33
|
-
) => {
|
|
34
|
-
const { data } = snapshot;
|
|
35
|
-
callback({ ...snapshot, data });
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const { userId } = getActiveUser();
|
|
39
|
-
return liveObject(userId, responder, 'userId', _getNotificationTraySeen, [
|
|
40
|
-
onNotificationTraySeenUpdated,
|
|
41
|
-
]);
|
|
42
|
-
};
|
|
43
|
-
/* end_public_function */
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { convertRawUserToInternalUser } from '~/userRepository/utils/convertRawUserToInternalUser';
|
|
2
|
-
|
|
3
|
-
export const prepareNotificationTrayItemsPayload = (
|
|
4
|
-
rawPayload: Amity.NotificationTrayPayload,
|
|
5
|
-
): Amity.ProcessedNotificationTrayPayload => {
|
|
6
|
-
const users = rawPayload.users.map(convertRawUserToInternalUser);
|
|
7
|
-
|
|
8
|
-
return {
|
|
9
|
-
...rawPayload,
|
|
10
|
-
users,
|
|
11
|
-
};
|
|
12
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { markNotificationItemsSeen } from '~/notificationTrayRepository/api/markNotificationItemsSeen';
|
|
2
|
-
import { pullFromCache } from '~/cache/api';
|
|
3
|
-
import { userLinkedObject } from './userLinkedObject';
|
|
4
|
-
import { isNonNullable } from '..';
|
|
5
|
-
import { WEEK } from '../constants';
|
|
6
|
-
|
|
7
|
-
export const notificationTrayLinkedObject = (
|
|
8
|
-
noti: Amity.InternalNotificationTrayItem,
|
|
9
|
-
): Amity.NotificationTrayItem => {
|
|
10
|
-
return {
|
|
11
|
-
...noti,
|
|
12
|
-
isSeen: noti.lastSeenAt > noti.lastOccuredAt,
|
|
13
|
-
isRecent: new Date(noti.lastOccuredAt).getTime() >= Date.now() - WEEK,
|
|
14
|
-
users: noti.actors
|
|
15
|
-
.map(userId => pullFromCache<Amity.InternalUser>(['user', 'get', userId])?.data)
|
|
16
|
-
.filter(isNonNullable)
|
|
17
|
-
.map(user => userLinkedObject(user)),
|
|
18
|
-
markRead: () =>
|
|
19
|
-
markNotificationItemsSeen({
|
|
20
|
-
trayItems: [
|
|
21
|
-
{
|
|
22
|
-
id: noti._id,
|
|
23
|
-
lastSeenAt: noti.lastSeenAt,
|
|
24
|
-
},
|
|
25
|
-
],
|
|
26
|
-
}),
|
|
27
|
-
};
|
|
28
|
-
};
|