@amityco/ts-sdk 6.18.1-c018952.0 → 6.19.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/.env +26 -26
- package/dist/@types/core/events.d.ts +4 -0
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/objectResolver.d.ts +13 -0
- package/dist/@types/core/objectResolver.d.ts.map +1 -0
- package/dist/@types/domains/channel.d.ts +12 -1
- package/dist/@types/domains/channel.d.ts.map +1 -1
- package/dist/analytic/api/syncEvent.d.ts.map +1 -1
- package/dist/analytic/service/analytic/AnalyticsEngine.d.ts +1 -0
- package/dist/analytic/service/analytic/AnalyticsEngine.d.ts.map +1 -1
- package/dist/analytic/service/analytic/AnalyticsEventCapturer.d.ts +1 -0
- package/dist/analytic/service/analytic/AnalyticsEventCapturer.d.ts.map +1 -1
- package/dist/analytic/service/analytic/AnalyticsEventSyncer.d.ts.map +1 -1
- package/dist/channelRepository/api/getChannel.d.ts.map +1 -1
- package/dist/channelRepository/api/getChannelByIds.d.ts.map +1 -1
- package/dist/channelRepository/events/onChannelFetched.d.ts +17 -0
- package/dist/channelRepository/events/onChannelFetched.d.ts.map +1 -0
- package/dist/channelRepository/observers/getChannels/ChannelLiveCollectionController.d.ts.map +1 -1
- package/dist/channelRepository/observers/getChannels/ChannelQueryStreamController.d.ts +3 -3
- package/dist/channelRepository/observers/getChannels/ChannelQueryStreamController.d.ts.map +1 -1
- package/dist/channelRepository/observers/observeChannel.d.ts +1 -1
- package/dist/channelRepository/observers/observeChannel.d.ts.map +1 -1
- package/dist/channelRepository/utils/prepareChannelPayload.d.ts.map +1 -1
- package/dist/channelRepository/utils/prepateUnreadCountInfo.d.ts +2 -0
- package/dist/channelRepository/utils/prepateUnreadCountInfo.d.ts.map +1 -0
- package/dist/channelRepository/utils/resolveUnreadInfoOnChannelEvent.d.ts +2 -0
- package/dist/channelRepository/utils/resolveUnreadInfoOnChannelEvent.d.ts.map +1 -0
- package/dist/client/api/login.d.ts.map +1 -1
- package/dist/client/utils/ObjectResolver/objectResolverEngine.d.ts +26 -0
- package/dist/client/utils/ObjectResolver/objectResolverEngine.d.ts.map +1 -0
- package/dist/client/utils/ObjectResolver/objectResolverEngineOnLoginHandler.d.ts +3 -0
- package/dist/client/utils/ObjectResolver/objectResolverEngineOnLoginHandler.d.ts.map +1 -0
- package/dist/client/utils/onOffline.d.ts +2 -0
- package/dist/client/utils/onOffline.d.ts.map +1 -0
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.d.ts.map +1 -1
- package/dist/index.cjs.js +446 -158
- package/dist/index.esm.js +446 -158
- package/dist/index.umd.js +4 -4
- package/dist/marker/api/getUserMessageFeedMarkers.d.ts.map +1 -1
- package/dist/marker/events/onUserFeedMarkerFetched.d.ts +17 -0
- package/dist/marker/events/onUserFeedMarkerFetched.d.ts.map +1 -0
- package/dist/marker/utils/addFlagSubChannelUnreadByChannelId.d.ts +2 -0
- package/dist/marker/utils/addFlagSubChannelUnreadByChannelId.d.ts.map +1 -0
- package/dist/marker/utils/addFlagSubChannelUnreadBySubChannelId.d.ts +2 -0
- package/dist/marker/utils/addFlagSubChannelUnreadBySubChannelId.d.ts.map +1 -0
- package/dist/messageRepository/observers/tests/markReadMessage.test.d.ts +2 -0
- package/dist/messageRepository/observers/tests/markReadMessage.test.d.ts.map +1 -0
- package/dist/reactionRepository/events/onReactionAdded.d.ts.map +1 -1
- package/dist/subChannelRepository/events/onSubChannelCreated.d.ts.map +1 -1
- package/dist/subChannelRepository/utils/persistOptimisticUnreadInfo.d.ts +1 -1
- package/dist/subChannelRepository/utils/persistOptimisticUnreadInfo.d.ts.map +1 -1
- package/dist/utils/liveObject.d.ts.map +1 -1
- package/dist/utils/tests/dummy/message.d.ts +5 -4
- package/dist/utils/tests/dummy/message.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/core/events.ts +5 -0
- package/src/@types/core/objectResolver.ts +14 -0
- package/src/@types/domains/channel.ts +12 -10
- package/src/analytic/api/syncEvent.ts +1 -3
- package/src/analytic/service/analytic/AnalyticsEngine.ts +6 -6
- package/src/analytic/service/analytic/AnalyticsEventCapturer.ts +9 -1
- package/src/analytic/service/analytic/AnalyticsEventSyncer.ts +9 -3
- package/src/channelRepository/api/getChannel.ts +5 -0
- package/src/channelRepository/api/getChannelByIds.ts +3 -0
- package/src/channelRepository/events/onChannelFetched.ts +28 -0
- package/src/channelRepository/observers/getChannels/ChannelLiveCollectionController.ts +86 -26
- package/src/channelRepository/observers/getChannels/ChannelQueryStreamController.ts +21 -8
- package/src/channelRepository/observers/observeChannel.ts +22 -9
- package/src/channelRepository/observers/observeChannels.ts +9 -9
- package/src/channelRepository/utils/prepareChannelPayload.ts +0 -13
- package/src/channelRepository/utils/prepateUnreadCountInfo.ts +20 -0
- package/src/channelRepository/utils/resolveUnreadInfoOnChannelEvent.ts +15 -0
- package/src/channelRepository/utils/tests/prepareChannelPayload.test.ts +2 -2
- package/src/client/api/login.ts +3 -1
- package/src/client/utils/ObjectResolver/objectResolverEngine.ts +143 -0
- package/src/client/utils/ObjectResolver/objectResolverEngineOnLoginHandler.ts +21 -0
- package/src/client/utils/onOffline.ts +15 -0
- package/src/marker/api/getUserMessageFeedMarkers.ts +3 -0
- package/src/marker/events/onUserFeedMarkerFetched.ts +37 -0
- package/src/marker/utils/addFlagSubChannelUnreadByChannelId.ts +19 -0
- package/src/marker/utils/addFlagSubChannelUnreadBySubChannelId.ts +13 -0
- package/src/messageRepository/observers/tests/markReadMessage.test.ts +225 -0
- package/src/reactionRepository/events/onReactionAdded.ts +1 -0
- package/src/subChannelRepository/events/onSubChannelCreated.ts +8 -1
- package/src/subChannelRepository/utils/persistOptimisticUnreadInfo.ts +24 -19
- package/src/utils/liveObject.ts +1 -0
- package/src/utils/tests/client.ts +1 -1
- package/src/utils/tests/dummy/channel.ts +4 -4
- package/src/utils/tests/dummy/message.ts +11 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getUserMessageFeedMarkers.d.ts","sourceRoot":"","sources":["../../../src/marker/api/getUserMessageFeedMarkers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getUserMessageFeedMarkers.d.ts","sourceRoot":"","sources":["../../../src/marker/api/getUserMessageFeedMarkers.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,wBAAwB,eACvB,MAAM,UAAU,CAAC,WAAW,CAAC,EAAE,KAC1C,QAAQ,MAAM,4BAA4B,CAgB5C,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ```js
|
|
3
|
+
* import { onFeedMarkerUpdated } from '@amityco/ts-sdk'
|
|
4
|
+
* const dispose = onFeedMarkerUpdated(feedMarker => {
|
|
5
|
+
* // ...
|
|
6
|
+
* })
|
|
7
|
+
* ```
|
|
8
|
+
*
|
|
9
|
+
* Fired when an {@link Amity.UserMessageFeedMarkerPayload} has been updated
|
|
10
|
+
*
|
|
11
|
+
* @param callback The function to call when the event was fired
|
|
12
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
13
|
+
*
|
|
14
|
+
* @category FeedMarker Events
|
|
15
|
+
*/
|
|
16
|
+
export declare const onUserFeedMarkerFetched: (callback: Amity.Listener<Amity.UserMessageFeedMarkerPayload>) => Amity.Unsubscriber;
|
|
17
|
+
//# sourceMappingURL=onUserFeedMarkerFetched.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onUserFeedMarkerFetched.d.ts","sourceRoot":"","sources":["../../../src/marker/events/onUserFeedMarkerFetched.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,uBAAuB,aACxB,MAAM,QAAQ,CAAC,MAAM,4BAA4B,CAAC,KAC3D,MAAM,YAeR,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addFlagSubChannelUnreadByChannelId.d.ts","sourceRoot":"","sources":["../../../src/marker/utils/addFlagSubChannelUnreadByChannelId.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kCAAkC,cAAe,MAAM,SAgBnE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addFlagSubChannelUnreadBySubChannelId.d.ts","sourceRoot":"","sources":["../../../src/marker/utils/addFlagSubChannelUnreadBySubChannelId.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,qCAAqC,iBAAkB,MAAM,SAUzE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markReadMessage.test.d.ts","sourceRoot":"","sources":["../../../../src/messageRepository/observers/tests/markReadMessage.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"onReactionAdded.d.ts","sourceRoot":"","sources":["../../../src/reactionRepository/events/onReactionAdded.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;;;;KAgBK;AACL,eAAO,MAAM,eAAe,kBACX,MAAM,aAAa,eACrB,MAAM,QAAQ,CAAC,aAAa,CAAC,wIAEzC,MAAM,
|
|
1
|
+
{"version":3,"file":"onReactionAdded.d.ts","sourceRoot":"","sources":["../../../src/reactionRepository/events/onReactionAdded.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;;;;KAgBK;AACL,eAAO,MAAM,eAAe,kBACX,MAAM,aAAa,eACrB,MAAM,QAAQ,CAAC,aAAa,CAAC,wIAEzC,MAAM,YAuCR,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"onSubChannelCreated.d.ts","sourceRoot":"","sources":["../../../src/subChannelRepository/events/onSubChannelCreated.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,mBAAmB,aAAc,MAAM,QAAQ,CAAC,MAAM,UAAU,CAAC,
|
|
1
|
+
{"version":3,"file":"onSubChannelCreated.d.ts","sourceRoot":"","sources":["../../../src/subChannelRepository/events/onSubChannelCreated.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,mBAAmB,aAAc,MAAM,QAAQ,CAAC,MAAM,UAAU,CAAC,uBAuB7E,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const persistOptimisticUnreadInfo: (
|
|
1
|
+
export declare const persistOptimisticUnreadInfo: (subChannelOptimisticInfo: Pick<Amity.SubChannel, 'channelId' | 'subChannelId' | 'createdAt' | 'updatedAt'>) => void;
|
|
2
2
|
//# sourceMappingURL=persistOptimisticUnreadInfo.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"persistOptimisticUnreadInfo.d.ts","sourceRoot":"","sources":["../../../src/subChannelRepository/utils/persistOptimisticUnreadInfo.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,2BAA2B,
|
|
1
|
+
{"version":3,"file":"persistOptimisticUnreadInfo.d.ts","sourceRoot":"","sources":["../../../src/subChannelRepository/utils/persistOptimisticUnreadInfo.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,2BAA2B,6BACZ,KACxB,MAAM,UAAU,EAChB,WAAW,GAAG,cAAc,GAAG,WAAW,GAAG,WAAW,CACzD,SAqBF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"liveObject.d.ts","sourceRoot":"","sources":["../../src/utils/liveObject.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,UAAU,uPASiC,MAAM,YAAY,wEAEvE,MAAM,
|
|
1
|
+
{"version":3,"file":"liveObject.d.ts","sourceRoot":"","sources":["../../src/utils/liveObject.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,UAAU,uPASiC,MAAM,YAAY,wEAEvE,MAAM,YAmFR,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export declare function generateRawMessage(params?: Partial<Amity.RawMessage>): Amity.RawMessage;
|
|
2
|
-
export declare const convertRawMessage: ({ channelPublicId, childCount, creatorPublicId, mentionedUsers, messageFeedId, reactionCount, reactions, referenceId, segment, messageId, myReactions, ...rest }: Amity.RawMessage) => Amity.
|
|
2
|
+
export declare const convertRawMessage: ({ channelPublicId, childCount, creatorPublicId, mentionedUsers, messageFeedId, reactionCount, reactions, referenceId, segment, messageId, myReactions, creatorId, ...rest }: Amity.RawMessage) => Amity.InternalMessage;
|
|
3
|
+
export declare const withLinkedObject: (message: Amity.InternalMessage) => Amity.Message;
|
|
3
4
|
export declare const convertRawMessagePayload: (rawPayload: Amity.MessagePayload) => Amity.ProcessedMessagePayload;
|
|
4
|
-
export declare const message11: Amity.
|
|
5
|
+
export declare const message11: Amity.InternalMessage;
|
|
5
6
|
export declare const messages: {
|
|
6
7
|
subChannelId: string;
|
|
7
8
|
page1: string[];
|
|
@@ -17,7 +18,7 @@ export declare const messagesDesc: {
|
|
|
17
18
|
};
|
|
18
19
|
export declare const messageQueryResponse: {
|
|
19
20
|
data: {
|
|
20
|
-
messages: Amity.
|
|
21
|
+
messages: Amity.InternalMessage<any>[];
|
|
21
22
|
files: never[];
|
|
22
23
|
users: never[];
|
|
23
24
|
paging: {
|
|
@@ -27,7 +28,7 @@ export declare const messageQueryResponse: {
|
|
|
27
28
|
};
|
|
28
29
|
};
|
|
29
30
|
export declare const messagePayload: {
|
|
30
|
-
messages: Amity.
|
|
31
|
+
messages: Amity.InternalMessage<any>[];
|
|
31
32
|
files: Amity.File<"image">[];
|
|
32
33
|
users: Amity.User[];
|
|
33
34
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../../../src/utils/tests/dummy/message.ts"],"names":[],"mappings":"AAGA,wBAAgB,kBAAkB,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,KAAK,CAAC,UAAU,CAyBvF;AAED,eAAO,MAAM,iBAAiB,
|
|
1
|
+
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../../../src/utils/tests/dummy/message.ts"],"names":[],"mappings":"AAGA,wBAAgB,kBAAkB,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,KAAK,CAAC,UAAU,CAyBvF;AAED,eAAO,MAAM,iBAAiB,gLAc3B,MAAM,UAAU,KAAG,MAAM,eAkB1B,CAAC;AAEH,eAAO,MAAM,gBAAgB,YAAa,MAAM,eAAe,KAAG,MAAM,OAOtE,CAAC;AAEH,eAAO,MAAM,wBAAwB,eACvB,MAAM,cAAc,KAC/B,MAAM,uBAGP,CAAC;AAEH,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,eAM7B,CAAC;AAEF,eAAO,MAAM,QAAQ;;;;;;CAMpB,CAAC;AAEF,eAAO,MAAM,YAAY;;;;;CAKxB,CAAC;AAEF,eAAO,MAAM,oBAAoB;;;;;;;;;;CAUhC,CAAC;AAGF,eAAO,MAAM,cAAc;;;;CAI1B,CAAC"}
|
package/package.json
CHANGED
|
@@ -164,6 +164,7 @@ declare global {
|
|
|
164
164
|
|
|
165
165
|
type LocalEvents = {
|
|
166
166
|
'local.channel.updated': MakeRequired<Amity.ProcessedChannelPayload, 'channels'>;
|
|
167
|
+
'local.channel.fetched': Amity.InternalChannel[];
|
|
167
168
|
'local.channel-moderator.role-added': Amity.ProcessedChannelPayload;
|
|
168
169
|
'local.channel-moderator.role-removed': Amity.ProcessedChannelPayload;
|
|
169
170
|
'local.message.created': MakeRequired<Amity.ProcessedMessagePayload, 'messages'>;
|
|
@@ -183,6 +184,10 @@ declare global {
|
|
|
183
184
|
'local.messageMarker.fetched': MakeRequired<Amity.MessageMarkerPayload, 'contentMarkers'>;
|
|
184
185
|
'local.userMarker.fetched': { userMarkers: Amity.UserMarker[] };
|
|
185
186
|
|
|
187
|
+
'local.userMessageFeedMarker.fetched': {
|
|
188
|
+
userMessageFeedMarker: Amity.UserMessageFeedMarkerPayload;
|
|
189
|
+
};
|
|
190
|
+
|
|
186
191
|
'local.story.created': Amity.StoryPayload;
|
|
187
192
|
'local.story.updated': Amity.StoryPayload;
|
|
188
193
|
'local.story.deleted': Amity.StoryPayload;
|
|
@@ -15,16 +15,18 @@ declare global {
|
|
|
15
15
|
| 'onChannelMemberRoleAdded'
|
|
16
16
|
| 'onChannelMemberRoleRemoved';
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
const enum ChannelActionType {
|
|
19
|
+
OnFetch = 'onFetch',
|
|
20
|
+
OnCreate = 'onCreate',
|
|
21
|
+
OnUpdate = 'onUpdate',
|
|
22
|
+
OnDelete = 'onDelete',
|
|
23
|
+
OnJoin = 'onJoin',
|
|
24
|
+
OnLeft = 'onLeft',
|
|
25
|
+
OnMute = 'onMute',
|
|
26
|
+
OnMemberAdded = 'onMemberAdded',
|
|
27
|
+
OnMemberRemoved = 'onMemberRemoved',
|
|
28
|
+
OnUserMessageFeedMarkerFetch = 'onUserMessageFeedMarkerFetch',
|
|
29
|
+
}
|
|
28
30
|
|
|
29
31
|
type RawChannel<T extends ChannelType = any> = {
|
|
30
32
|
_id: string;
|
|
@@ -6,7 +6,5 @@ export const syncEvent = async (events: Amity.AnalyticEventModel[]) => {
|
|
|
6
6
|
activities: events,
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
-
await client.http.post<Amity.ChannelPayload>('/api/v1/analytics/activities',
|
|
10
|
-
activities: events,
|
|
11
|
-
});
|
|
9
|
+
await client.http.post<Amity.ChannelPayload>('/api/v1/analytics/activities', params);
|
|
12
10
|
};
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { getActiveClient } from '~/client/api/activeClient';
|
|
2
|
-
import { dropFromCache } from '~/cache/api';
|
|
3
2
|
import { AnalyticsEventSyncer } from './AnalyticsEventSyncer';
|
|
4
3
|
import { AnalyticsEventCapturer } from './AnalyticsEventCapturer';
|
|
5
|
-
import { ANALYTIC_CACHE_KEY } from '../../constant';
|
|
6
4
|
|
|
7
5
|
class AnalyticsEngine {
|
|
8
6
|
private _client: Amity.Client;
|
|
@@ -49,14 +47,16 @@ class AnalyticsEngine {
|
|
|
49
47
|
}
|
|
50
48
|
|
|
51
49
|
handleTokenExpired() {
|
|
52
|
-
this.
|
|
50
|
+
this._stopAndDestroy();
|
|
53
51
|
}
|
|
54
52
|
|
|
55
53
|
destroy() {
|
|
56
|
-
this.
|
|
54
|
+
this._stopAndDestroy();
|
|
55
|
+
}
|
|
57
56
|
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
_stopAndDestroy() {
|
|
58
|
+
this._eventSyncer.stop();
|
|
59
|
+
this._eventCapturer.resetAllBuckets();
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { upsertInCache } from '~/cache/api/upsertInCache';
|
|
2
2
|
import { pullFromCache } from '~/cache/api/pullFromCache';
|
|
3
3
|
import { DAY, MINUTE } from '~/utils/constants';
|
|
4
|
-
import { pushToCache } from '~/cache/api';
|
|
4
|
+
import { dropFromCache, pushToCache } from '~/cache/api';
|
|
5
5
|
import { fireEvent } from '~/core/events';
|
|
6
6
|
import { STORY_KEY_CACHE } from '~/storyRepository/constants';
|
|
7
7
|
import { ANALYTIC_CACHE_KEY, HIGH_PRIORITY_ANALYTIC_CACHE_KEY } from '../../constant';
|
|
@@ -148,6 +148,14 @@ export class AnalyticsEventCapturer {
|
|
|
148
148
|
}, 300);
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
+
resetAllBuckets() {
|
|
152
|
+
this._recentViewed = {};
|
|
153
|
+
this._recentHighPriorityViewed = {};
|
|
154
|
+
|
|
155
|
+
dropFromCache(ANALYTIC_CACHE_KEY);
|
|
156
|
+
dropFromCache(HIGH_PRIORITY_ANALYTIC_CACHE_KEY);
|
|
157
|
+
}
|
|
158
|
+
|
|
151
159
|
markStoryAsViewed(story: Amity.InternalStory) {
|
|
152
160
|
this.markStory(story, Amity.AnalyticEventActivityType.View);
|
|
153
161
|
}
|
|
@@ -22,9 +22,15 @@ export class AnalyticsEventSyncer {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
stop() {
|
|
25
|
-
if (
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
if (this._timer) {
|
|
26
|
+
clearInterval(this._timer);
|
|
27
|
+
this._timer = undefined;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (this._high_priority_timer) {
|
|
31
|
+
clearInterval(this._high_priority_timer);
|
|
32
|
+
this._high_priority_timer = undefined;
|
|
33
|
+
}
|
|
28
34
|
}
|
|
29
35
|
|
|
30
36
|
async syncCapturedEvent() {
|
|
@@ -8,6 +8,7 @@ import { checkIfShouldGoesToTombstone } from '~/cache/utils';
|
|
|
8
8
|
import { pushToTombstone } from '~/cache/api/pushToTombstone';
|
|
9
9
|
|
|
10
10
|
import { prepareChannelPayload } from '../utils';
|
|
11
|
+
import { prepareUnreadCountInfo } from '../utils/prepateUnreadCountInfo';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* ```js
|
|
@@ -39,6 +40,10 @@ export const getChannel = async (
|
|
|
39
40
|
);
|
|
40
41
|
|
|
41
42
|
data = await prepareChannelPayload(payload);
|
|
43
|
+
|
|
44
|
+
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
45
|
+
prepareUnreadCountInfo(payload);
|
|
46
|
+
}
|
|
42
47
|
} catch (error) {
|
|
43
48
|
if (checkIfShouldGoesToTombstone((error as Amity.ErrorResponse)?.code)) {
|
|
44
49
|
pushToTombstone('channel', channelId);
|
|
@@ -6,6 +6,7 @@ import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
|
6
6
|
import { checkIfShouldGoesToTombstone } from '~/cache/utils';
|
|
7
7
|
import { pushToTombstone } from '~/cache/api/pushToTombstone';
|
|
8
8
|
import { prepareChannelPayload } from '../utils';
|
|
9
|
+
import { fireEvent } from '~/core/events';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* ```js
|
|
@@ -53,6 +54,8 @@ export const getChannelByIds = async (
|
|
|
53
54
|
const cachedAt = client.cache && Date.now();
|
|
54
55
|
if (client.cache) ingestInCache(data, { cachedAt });
|
|
55
56
|
|
|
57
|
+
fireEvent('local.channel.fetched', data.channels);
|
|
58
|
+
|
|
56
59
|
return {
|
|
57
60
|
data: data.channels,
|
|
58
61
|
cachedAt,
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createEventSubscriber } from '~/core/events';
|
|
2
|
+
|
|
3
|
+
import { getActiveClient } from '~/client/api/activeClient';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* ```js
|
|
7
|
+
* import { onChannelFetched } from '@amityco/ts-sdk'
|
|
8
|
+
* const dispose = onChannelFetched(channel => {
|
|
9
|
+
* // ...
|
|
10
|
+
* })
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* Fired when any {@link Amity.Channel} list have been fetched
|
|
14
|
+
*
|
|
15
|
+
* @param callback The function to call when the event was fired
|
|
16
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
17
|
+
*
|
|
18
|
+
* @category Channel Events
|
|
19
|
+
*/
|
|
20
|
+
export const onChannelFetched = (callback: Amity.Listener<Amity.InternalChannel[]>) => {
|
|
21
|
+
const client = getActiveClient();
|
|
22
|
+
|
|
23
|
+
const filter = async (payload: Amity.InternalChannel[]) => {
|
|
24
|
+
callback(payload);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return createEventSubscriber(client, 'onChannelFetched', 'local.channel.fetched', filter);
|
|
28
|
+
};
|
|
@@ -22,6 +22,7 @@ import { onMessageUpdated } from '~/messageRepository/events/onMessageUpdated';
|
|
|
22
22
|
import { onMessageDeleted } from '~/messageRepository/events/onMessageDeleted';
|
|
23
23
|
import { onSubChannelUpdated } from '~/subChannelRepository/events/onSubChannelUpdated';
|
|
24
24
|
import { onSubChannelDeleted } from '~/subChannelRepository/events/onSubChannelDeleted';
|
|
25
|
+
import { onChannelFetched } from '~/channelRepository/events/onChannelFetched';
|
|
25
26
|
import { convertEventPayload } from '~/utils/event';
|
|
26
27
|
import { onChannelMarkerFetched } from '~/marker/events';
|
|
27
28
|
import {
|
|
@@ -49,6 +50,11 @@ import { PaginationController } from '~/core/liveCollection/PaginationController
|
|
|
49
50
|
import { onUserFeedMarkerUpdated } from '~/marker/events/onUserFeedMarkerUpdated';
|
|
50
51
|
import { onSubChannelCreated } from '~/subChannelRepository';
|
|
51
52
|
|
|
53
|
+
import ObjectResolverEngine from '~/client/utils/ObjectResolver/objectResolverEngine';
|
|
54
|
+
import { prepareUnreadCountInfo } from '~/channelRepository/utils/prepateUnreadCountInfo';
|
|
55
|
+
import { onUserFeedMarkerFetched } from '~/marker/events/onUserFeedMarkerFetched';
|
|
56
|
+
import { resolveUnreadInfoOnChannelEvent } from '~/channelRepository/utils/resolveUnreadInfoOnChannelEvent';
|
|
57
|
+
|
|
52
58
|
export class ChannelLiveCollectionController extends LiveCollectionController<
|
|
53
59
|
'channel',
|
|
54
60
|
Amity.ChannelLiveCollection,
|
|
@@ -74,7 +80,17 @@ export class ChannelLiveCollectionController extends LiveCollectionController<
|
|
|
74
80
|
this.query,
|
|
75
81
|
this.cacheKey,
|
|
76
82
|
this.notifyChange.bind(this),
|
|
77
|
-
|
|
83
|
+
async (channel: Amity.ChannelPayload) => {
|
|
84
|
+
try {
|
|
85
|
+
const client = getActiveClient();
|
|
86
|
+
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
87
|
+
await prepareUnreadCountInfo(channel);
|
|
88
|
+
}
|
|
89
|
+
} catch (e) {
|
|
90
|
+
console.error('Error while preparing unread count info', e);
|
|
91
|
+
}
|
|
92
|
+
return prepareChannelPayload(channel);
|
|
93
|
+
},
|
|
78
94
|
paginationController,
|
|
79
95
|
);
|
|
80
96
|
|
|
@@ -235,19 +251,23 @@ export class ChannelLiveCollectionController extends LiveCollectionController<
|
|
|
235
251
|
message.channelId,
|
|
236
252
|
])?.data;
|
|
237
253
|
|
|
238
|
-
if (!cacheData)
|
|
254
|
+
if (!cacheData) {
|
|
255
|
+
const objectResolverEngine = ObjectResolverEngine.getInstance();
|
|
239
256
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
257
|
+
objectResolverEngine.resolve(message.channelId, Amity.ReferenceType.CHANNEL);
|
|
258
|
+
} else {
|
|
259
|
+
updateChannelCache(cacheData, {
|
|
260
|
+
lastActivity: message.createdAt,
|
|
261
|
+
});
|
|
243
262
|
|
|
244
|
-
|
|
263
|
+
callback(message);
|
|
264
|
+
}
|
|
245
265
|
});
|
|
246
266
|
},
|
|
247
267
|
'messageId',
|
|
248
268
|
'channel',
|
|
249
269
|
),
|
|
250
|
-
action:
|
|
270
|
+
action: Amity.ChannelActionType.OnUpdate,
|
|
251
271
|
},
|
|
252
272
|
{
|
|
253
273
|
// TODO: merge this code to another onMessageCreated in this file
|
|
@@ -272,12 +292,19 @@ export class ChannelLiveCollectionController extends LiveCollectionController<
|
|
|
272
292
|
'messageId',
|
|
273
293
|
'channel',
|
|
274
294
|
),
|
|
275
|
-
action:
|
|
295
|
+
action: Amity.ChannelActionType.OnUpdate,
|
|
296
|
+
},
|
|
297
|
+
{ fn: onChannelDeleted, action: Amity.ChannelActionType.OnDelete },
|
|
298
|
+
{ fn: onChannelUpdated, action: Amity.ChannelActionType.OnUpdate },
|
|
299
|
+
{ fn: onChannelMuted, action: Amity.ChannelActionType.OnMute },
|
|
300
|
+
{
|
|
301
|
+
fn: (callback: Amity.Listener<Amity.InternalChannel>) => {
|
|
302
|
+
return onChannelJoined(channel => {
|
|
303
|
+
resolveUnreadInfoOnChannelEvent(channel, callback);
|
|
304
|
+
});
|
|
305
|
+
},
|
|
306
|
+
action: Amity.ChannelActionType.OnJoin,
|
|
276
307
|
},
|
|
277
|
-
{ fn: onChannelDeleted, action: 'onDelete' },
|
|
278
|
-
{ fn: onChannelUpdated, action: 'onUpdate' },
|
|
279
|
-
{ fn: onChannelMuted, action: 'onMute' },
|
|
280
|
-
{ fn: onChannelJoined, action: 'onJoin' },
|
|
281
308
|
{
|
|
282
309
|
fn: (reactor: Amity.Listener<Amity.InternalChannel>) => {
|
|
283
310
|
const callback = (
|
|
@@ -300,17 +327,17 @@ export class ChannelLiveCollectionController extends LiveCollectionController<
|
|
|
300
327
|
};
|
|
301
328
|
return onChannelLeft(callback);
|
|
302
329
|
},
|
|
303
|
-
action:
|
|
330
|
+
action: Amity.ChannelActionType.OnLeft,
|
|
304
331
|
},
|
|
305
|
-
{ fn: onChannelMemberAdded, action:
|
|
306
|
-
{ fn: onChannelMemberRemoved, action:
|
|
332
|
+
{ fn: onChannelMemberAdded, action: Amity.ChannelActionType.OnMemberAdded },
|
|
333
|
+
{ fn: onChannelMemberRemoved, action: Amity.ChannelActionType.OnMemberRemoved },
|
|
307
334
|
{
|
|
308
335
|
fn: convertEventPayload(onChannelMarkerFetched, 'entityId', 'channel'),
|
|
309
|
-
action:
|
|
336
|
+
action: Amity.ChannelActionType.OnUpdate,
|
|
310
337
|
},
|
|
311
338
|
{
|
|
312
339
|
fn: convertEventPayload(onChannelMarkerUpdated, 'entityId', 'channel'),
|
|
313
|
-
action:
|
|
340
|
+
action: Amity.ChannelActionType.OnUpdate,
|
|
314
341
|
},
|
|
315
342
|
{
|
|
316
343
|
fn: convertEventPayload(
|
|
@@ -344,7 +371,7 @@ export class ChannelLiveCollectionController extends LiveCollectionController<
|
|
|
344
371
|
'channelId',
|
|
345
372
|
'channel',
|
|
346
373
|
),
|
|
347
|
-
action:
|
|
374
|
+
action: Amity.ChannelActionType.OnUpdate,
|
|
348
375
|
},
|
|
349
376
|
{
|
|
350
377
|
fn: convertEventPayload(
|
|
@@ -378,7 +405,7 @@ export class ChannelLiveCollectionController extends LiveCollectionController<
|
|
|
378
405
|
'channelId',
|
|
379
406
|
'channel',
|
|
380
407
|
),
|
|
381
|
-
action:
|
|
408
|
+
action: Amity.ChannelActionType.OnUpdate,
|
|
382
409
|
},
|
|
383
410
|
{
|
|
384
411
|
fn: convertEventPayload(
|
|
@@ -400,7 +427,7 @@ export class ChannelLiveCollectionController extends LiveCollectionController<
|
|
|
400
427
|
'channelId',
|
|
401
428
|
'channel',
|
|
402
429
|
),
|
|
403
|
-
action:
|
|
430
|
+
action: Amity.ChannelActionType.OnUpdate,
|
|
404
431
|
},
|
|
405
432
|
{
|
|
406
433
|
fn: convertEventPayload(
|
|
@@ -434,7 +461,7 @@ export class ChannelLiveCollectionController extends LiveCollectionController<
|
|
|
434
461
|
'channelId',
|
|
435
462
|
'channel',
|
|
436
463
|
),
|
|
437
|
-
action:
|
|
464
|
+
action: Amity.ChannelActionType.OnUpdate,
|
|
438
465
|
},
|
|
439
466
|
{
|
|
440
467
|
fn: convertEventPayload(
|
|
@@ -461,7 +488,7 @@ export class ChannelLiveCollectionController extends LiveCollectionController<
|
|
|
461
488
|
'channelId',
|
|
462
489
|
'channel',
|
|
463
490
|
),
|
|
464
|
-
action:
|
|
491
|
+
action: Amity.ChannelActionType.OnUpdate,
|
|
465
492
|
},
|
|
466
493
|
{
|
|
467
494
|
fn: convertEventPayload(
|
|
@@ -487,20 +514,53 @@ export class ChannelLiveCollectionController extends LiveCollectionController<
|
|
|
487
514
|
'channelId',
|
|
488
515
|
'channel',
|
|
489
516
|
),
|
|
490
|
-
action:
|
|
517
|
+
action: Amity.ChannelActionType.OnUpdate,
|
|
491
518
|
},
|
|
492
519
|
{
|
|
493
520
|
fn: convertEventPayload(onUserFeedMarkerUpdated, 'entityId', 'channel'),
|
|
494
|
-
action:
|
|
521
|
+
action: Amity.ChannelActionType.OnUpdate,
|
|
495
522
|
},
|
|
496
523
|
{
|
|
497
524
|
fn: convertEventPayload(onSubChannelCreated, 'channelId', 'channel'),
|
|
498
|
-
action:
|
|
525
|
+
action: Amity.ChannelActionType.OnUpdate,
|
|
526
|
+
},
|
|
527
|
+
{
|
|
528
|
+
fn: onChannelFetched,
|
|
529
|
+
action: Amity.ChannelActionType.OnFetch,
|
|
530
|
+
},
|
|
531
|
+
{
|
|
532
|
+
fn: (callback: Amity.Listener<Amity.InternalChannel[]>) => {
|
|
533
|
+
const handleUserFeedMarkerFetch = async (marker: Amity.UserMessageFeedMarkerPayload) => {
|
|
534
|
+
if (marker.feedMarkers) {
|
|
535
|
+
const channelIds = marker.feedMarkers.map(feedMarker => feedMarker.entityId);
|
|
536
|
+
const channels = channelIds
|
|
537
|
+
.map(
|
|
538
|
+
channelId =>
|
|
539
|
+
pullFromCache<Amity.InternalChannel>(['channel', 'get', channelId])?.data,
|
|
540
|
+
)
|
|
541
|
+
.filter(Boolean) as Amity.InternalChannel[];
|
|
542
|
+
|
|
543
|
+
callback(channels);
|
|
544
|
+
}
|
|
545
|
+
};
|
|
546
|
+
return onUserFeedMarkerFetched(handleUserFeedMarkerFetch);
|
|
547
|
+
},
|
|
548
|
+
action: Amity.ChannelActionType.OnUserMessageFeedMarkerFetch,
|
|
499
549
|
},
|
|
500
550
|
];
|
|
501
551
|
|
|
502
552
|
if (this.paginationController instanceof PaginationController) {
|
|
503
|
-
return [
|
|
553
|
+
return [
|
|
554
|
+
...subscriptions,
|
|
555
|
+
{
|
|
556
|
+
fn: (callback: Amity.Listener<Amity.InternalChannel>) => {
|
|
557
|
+
return onChannelCreated(channel => {
|
|
558
|
+
resolveUnreadInfoOnChannelEvent(channel, callback);
|
|
559
|
+
});
|
|
560
|
+
},
|
|
561
|
+
action: Amity.ChannelActionType.OnCreate,
|
|
562
|
+
},
|
|
563
|
+
];
|
|
504
564
|
}
|
|
505
565
|
|
|
506
566
|
return subscriptions;
|
|
@@ -64,27 +64,40 @@ export class ChannelQueryStreamController extends QueryStreamController<
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
reactor(action:
|
|
68
|
-
return (payload: Amity.
|
|
67
|
+
reactor(action: Amity.ChannelActionType) {
|
|
68
|
+
return (payload: Amity.InternalChannel | Amity.InternalChannel[]) => {
|
|
69
69
|
const collection = pullFromCache<Amity.ChannelLiveCollectionCache>(this.cacheKey)?.data;
|
|
70
70
|
if (!collection) return;
|
|
71
71
|
|
|
72
|
+
if (this.paginationController instanceof ChannelPaginationNoPageController)
|
|
73
|
+
return this.notifyChange({ origin: Amity.LiveDataOrigin.EVENT, loading: false });
|
|
74
|
+
|
|
72
75
|
if (
|
|
73
|
-
|
|
74
|
-
|
|
76
|
+
[
|
|
77
|
+
Amity.ChannelActionType.OnCreate,
|
|
78
|
+
Amity.ChannelActionType.OnJoin,
|
|
79
|
+
Amity.ChannelActionType.OnFetch,
|
|
80
|
+
Amity.ChannelActionType.OnUserMessageFeedMarkerFetch,
|
|
81
|
+
].includes(action)
|
|
75
82
|
) {
|
|
76
|
-
|
|
77
|
-
|
|
83
|
+
if (Array.isArray(payload))
|
|
84
|
+
collection.data = [
|
|
85
|
+
...new Set([...payload.map(({ channelId }) => channelId), ...collection.data]),
|
|
86
|
+
];
|
|
87
|
+
else collection.data = [...new Set([payload.channelId, ...collection.data])];
|
|
78
88
|
}
|
|
79
89
|
|
|
90
|
+
pushToCache(this.cacheKey, collection);
|
|
80
91
|
this.notifyChange({ origin: Amity.LiveDataOrigin.EVENT, loading: false });
|
|
81
92
|
};
|
|
82
93
|
}
|
|
83
94
|
|
|
84
95
|
subscribeRTE(
|
|
85
96
|
createSubscriber: {
|
|
86
|
-
fn: (
|
|
87
|
-
|
|
97
|
+
fn: (
|
|
98
|
+
reactor: Amity.Listener<Amity.InternalChannel | Amity.InternalChannel[]>,
|
|
99
|
+
) => Amity.Unsubscriber;
|
|
100
|
+
action: Amity.ChannelActionType;
|
|
88
101
|
}[],
|
|
89
102
|
) {
|
|
90
103
|
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|