@amityco/ts-sdk-react-native 6.14.2-5d7d534.0 → 6.15.1-fee6c8f.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 +6 -1
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/live.d.ts +5 -3
- package/dist/@types/core/live.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 +14 -0
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/core/permissions.d.ts +2 -1
- package/dist/@types/core/permissions.d.ts.map +1 -1
- package/dist/@types/domains/analytics.d.ts +4 -1
- package/dist/@types/domains/analytics.d.ts.map +1 -1
- package/dist/@types/domains/category.d.ts +2 -1
- package/dist/@types/domains/category.d.ts.map +1 -1
- package/dist/@types/domains/channel.d.ts +3 -1
- package/dist/@types/domains/channel.d.ts.map +1 -1
- package/dist/@types/domains/comment.d.ts +1 -1
- package/dist/@types/domains/comment.d.ts.map +1 -1
- package/dist/@types/domains/community.d.ts +8 -3
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/@types/domains/feed.d.ts +15 -0
- package/dist/@types/domains/feed.d.ts.map +1 -1
- package/dist/@types/domains/messagePreview.d.ts +1 -1
- package/dist/@types/domains/messagePreview.d.ts.map +1 -1
- package/dist/@types/domains/partials.d.ts +9 -0
- package/dist/@types/domains/partials.d.ts.map +1 -1
- package/dist/@types/domains/post.d.ts +3 -2
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/@types/domains/story.d.ts +126 -0
- package/dist/@types/domains/story.d.ts.map +1 -0
- package/dist/@types/domains/stream.d.ts +2 -1
- package/dist/@types/domains/stream.d.ts.map +1 -1
- package/dist/@types/domains/subChannel.d.ts +1 -1
- package/dist/@types/domains/subChannel.d.ts.map +1 -1
- package/dist/@types/index.d.ts +1 -0
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/analytic/constant.d.ts +1 -0
- package/dist/analytic/constant.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 +5 -0
- package/dist/analytic/service/analytic/AnalyticsEventCapturer.d.ts.map +1 -1
- package/dist/analytic/service/analytic/AnalyticsEventSyncer.d.ts +2 -0
- package/dist/analytic/service/analytic/AnalyticsEventSyncer.d.ts.map +1 -1
- package/dist/categoryRepository/internalApi/queryCategories.d.ts +2 -2
- package/dist/categoryRepository/internalApi/queryCategories.d.ts.map +1 -1
- package/dist/categoryRepository/observers/getCategories.d.ts.map +1 -1
- package/dist/channelRepository/api/createChannel.d.ts +1 -1
- package/dist/channelRepository/api/createChannel.d.ts.map +1 -1
- package/dist/channelRepository/channelMembership/observers/getMembers.d.ts.map +1 -1
- package/dist/channelRepository/channelMembership/observers/liveCollection/ChannelMemberLiveCollectionController.d.ts +14 -0
- package/dist/channelRepository/channelMembership/observers/liveCollection/ChannelMemberLiveCollectionController.d.ts.map +1 -0
- package/dist/channelRepository/channelMembership/observers/liveCollection/ChannelMemberPaginationController.d.ts +13 -0
- package/dist/channelRepository/channelMembership/observers/liveCollection/ChannelMemberPaginationController.d.ts.map +1 -0
- package/dist/channelRepository/channelMembership/observers/liveCollection/ChannelMemberQueryStreamController.d.ts +14 -0
- package/dist/channelRepository/channelMembership/observers/liveCollection/ChannelMemberQueryStreamController.d.ts.map +1 -0
- package/dist/channelRepository/observers/getChannels.d.ts.map +1 -1
- package/dist/channelRepository/observers/liveCollection/ChannelLiveCollectionController.d.ts +19 -0
- package/dist/channelRepository/observers/liveCollection/ChannelLiveCollectionController.d.ts.map +1 -0
- package/dist/channelRepository/observers/liveCollection/ChannelPaginationController.d.ts +14 -0
- package/dist/channelRepository/observers/liveCollection/ChannelPaginationController.d.ts.map +1 -0
- package/dist/channelRepository/observers/liveCollection/ChannelPagnationNoPageController.d.ts +5 -0
- package/dist/channelRepository/observers/liveCollection/ChannelPagnationNoPageController.d.ts.map +1 -0
- package/dist/channelRepository/observers/liveCollection/ChannelQueryStreamController.d.ts +17 -0
- package/dist/channelRepository/observers/liveCollection/ChannelQueryStreamController.d.ts.map +1 -0
- package/dist/channelRepository/utils/prepareChannelPayload.d.ts +1 -0
- package/dist/channelRepository/utils/prepareChannelPayload.d.ts.map +1 -1
- package/dist/communityRepository/api/createCommunity.d.ts +1 -1
- package/dist/communityRepository/api/createCommunity.d.ts.map +1 -1
- package/dist/communityRepository/api/queryCommunities.d.ts +1 -1
- package/dist/communityRepository/api/queryCommunities.d.ts.map +1 -1
- package/dist/communityRepository/api/updateCommunity.d.ts +1 -1
- package/dist/communityRepository/api/updateCommunity.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/api/queryCommunityMembers.d.ts +2 -7
- package/dist/communityRepository/communityMembership/api/queryCommunityMembers.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/observers/getMembers.d.ts.map +1 -1
- package/dist/communityRepository/observers/getCommunities.d.ts.map +1 -1
- package/dist/communityRepository/utils/payload.d.ts +2 -1
- package/dist/communityRepository/utils/payload.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/liveCollection/LiveCollectionController.d.ts +3 -2
- package/dist/core/liveCollection/LiveCollectionController.d.ts.map +1 -1
- package/dist/core/liveCollection/PaginationNoPageController.d.ts +9 -0
- package/dist/core/liveCollection/PaginationNoPageController.d.ts.map +1 -0
- package/dist/core/model/idResolvers.d.ts.map +1 -1
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/core/query/sorting.d.ts +14 -0
- package/dist/core/query/sorting.d.ts.map +1 -1
- package/dist/feedRepository/api/getCustomRankingGlobalFeed.d.ts +36 -2
- package/dist/feedRepository/api/getCustomRankingGlobalFeed.d.ts.map +1 -1
- package/dist/feedRepository/api/queryGlobalFeed.d.ts +24 -6
- package/dist/feedRepository/api/queryGlobalFeed.d.ts.map +1 -1
- package/dist/index.cjs.js +7936 -7216
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +5842 -5121
- package/dist/index.umd.js +4 -4
- package/dist/marker/api/getChannelMarkers.d.ts +2 -5
- package/dist/marker/api/getChannelMarkers.d.ts.map +1 -1
- package/dist/marker/api/getMessageMarkers.d.ts +3 -4
- package/dist/marker/api/getMessageMarkers.d.ts.map +1 -1
- package/dist/marker/events/onMessageMarked.d.ts.map +1 -1
- package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts +1 -47
- package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts.map +1 -1
- package/dist/messageRepository/observers/liveCollection/MessageLiveCollectionController.d.ts.map +1 -1
- package/dist/messageRepository/observers/liveCollection/MessageQueryStreamController.d.ts +1 -1
- package/dist/messageRepository/observers/liveCollection/MessageQueryStreamController.d.ts.map +1 -1
- package/dist/postRepository/api/queryPosts.d.ts +1 -1
- package/dist/postRepository/api/queryPosts.d.ts.map +1 -1
- package/dist/postRepository/observers/getPosts.d.ts.map +1 -1
- package/dist/role/api/queryRoles.d.ts +9 -1
- package/dist/role/api/queryRoles.d.ts.map +1 -1
- package/dist/storyRepository/api/createImageStory.d.ts +17 -0
- package/dist/storyRepository/api/createImageStory.d.ts.map +1 -0
- package/dist/storyRepository/api/createVideoStory.d.ts +15 -0
- package/dist/storyRepository/api/createVideoStory.d.ts.map +1 -0
- package/dist/storyRepository/api/hardDeleteStory.d.ts +2 -0
- package/dist/storyRepository/api/hardDeleteStory.d.ts.map +1 -0
- package/dist/storyRepository/api/index.d.ts +5 -0
- package/dist/storyRepository/api/index.d.ts.map +1 -0
- package/dist/storyRepository/api/softDeleteStory.d.ts +2 -0
- package/dist/storyRepository/api/softDeleteStory.d.ts.map +1 -0
- package/dist/storyRepository/events/onStoryCreated.d.ts +2 -0
- package/dist/storyRepository/events/onStoryCreated.d.ts.map +1 -0
- package/dist/storyRepository/events/onStoryDeleted.d.ts +2 -0
- package/dist/storyRepository/events/onStoryDeleted.d.ts.map +1 -0
- package/dist/storyRepository/events/onStoryError.d.ts +2 -0
- package/dist/storyRepository/events/onStoryError.d.ts.map +1 -0
- package/dist/storyRepository/index.d.ts +3 -0
- package/dist/storyRepository/index.d.ts.map +1 -0
- package/dist/storyRepository/internalApi/createStory.d.ts +2 -0
- package/dist/storyRepository/internalApi/createStory.d.ts.map +1 -0
- package/dist/storyRepository/internalApi/deleteStory.d.ts +2 -0
- package/dist/storyRepository/internalApi/deleteStory.d.ts.map +1 -0
- package/dist/storyRepository/internalApi/getActiveStoriesByTarget.d.ts +2 -0
- package/dist/storyRepository/internalApi/getActiveStoriesByTarget.d.ts.map +1 -0
- package/dist/storyRepository/observers/getActiveStoriesByTarget.d.ts +2 -0
- package/dist/storyRepository/observers/getActiveStoriesByTarget.d.ts.map +1 -0
- package/dist/storyRepository/observers/index.d.ts +2 -0
- package/dist/storyRepository/observers/index.d.ts.map +1 -0
- package/dist/storyRepository/utils/convertRawToStory.d.ts +3 -0
- package/dist/storyRepository/utils/convertRawToStory.d.ts.map +1 -0
- package/dist/storyRepository/utils/convertStoryPayloadToRaw.d.ts +2 -0
- package/dist/storyRepository/utils/convertStoryPayloadToRaw.d.ts.map +1 -0
- package/dist/storyRepository/utils/createOptimisticEvent.d.ts +6 -0
- package/dist/storyRepository/utils/createOptimisticEvent.d.ts.map +1 -0
- package/dist/storyRepository/utils/getStoryCache.d.ts +5 -0
- package/dist/storyRepository/utils/getStoryCache.d.ts.map +1 -0
- package/dist/streamRepository/api/index.d.ts.map +1 -1
- package/dist/streamRepository/api/queryStreams.d.ts +2 -0
- package/dist/streamRepository/api/queryStreams.d.ts.map +1 -1
- package/dist/streamRepository/internalApi/queryStreams.d.ts +16 -0
- package/dist/streamRepository/internalApi/queryStreams.d.ts.map +1 -0
- package/dist/streamRepository/observers/getStreams.d.ts +1 -1
- package/dist/streamRepository/observers/getStreams.d.ts.map +1 -1
- package/dist/subChannelRepository/observers/getSubChannels.d.ts.map +1 -1
- package/dist/subChannelRepository/observers/liveCollection/SubChannelLiveCollectionController.d.ts +14 -0
- package/dist/subChannelRepository/observers/liveCollection/SubChannelLiveCollectionController.d.ts.map +1 -0
- package/dist/subChannelRepository/observers/liveCollection/SubChannelPaginationController.d.ts +9 -0
- package/dist/subChannelRepository/observers/liveCollection/SubChannelPaginationController.d.ts.map +1 -0
- package/dist/subChannelRepository/observers/liveCollection/SubChannelQueryStreamController.d.ts +14 -0
- package/dist/subChannelRepository/observers/liveCollection/SubChannelQueryStreamController.d.ts.map +1 -0
- package/dist/subChannelRepository/utils/prepareSubChannelPayload.d.ts +1 -0
- package/dist/subChannelRepository/utils/prepareSubChannelPayload.d.ts.map +1 -1
- package/dist/utils/constants.d.ts +5 -0
- package/dist/utils/constants.d.ts.map +1 -1
- package/dist/utils/linkedObject/commentLinkedObject.d.ts.map +1 -1
- package/dist/utils/linkedObject/index.d.ts +1 -0
- package/dist/utils/linkedObject/index.d.ts.map +1 -1
- package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
- package/dist/utils/linkedObject/storyLinkedObject.d.ts +2 -0
- package/dist/utils/linkedObject/storyLinkedObject.d.ts.map +1 -0
- package/dist/utils/tests/dummy/channel.d.ts +9 -0
- package/dist/utils/tests/dummy/channel.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/core/events.ts +8 -1
- package/src/@types/core/live.ts +7 -4
- package/src/@types/core/model.ts +6 -0
- package/src/@types/core/payload.ts +19 -0
- package/src/@types/core/permissions.ts +1 -0
- package/src/@types/domains/analytics.ts +4 -1
- package/src/@types/domains/category.ts +2 -1
- package/src/@types/domains/channel.ts +4 -1
- package/src/@types/domains/comment.ts +1 -1
- package/src/@types/domains/community.ts +11 -5
- package/src/@types/domains/feed.ts +16 -0
- package/src/@types/domains/messagePreview.ts +1 -1
- package/src/@types/domains/partials.ts +12 -0
- package/src/@types/domains/post.ts +3 -2
- package/src/@types/domains/story.ts +150 -0
- package/src/@types/domains/stream.ts +2 -1
- package/src/@types/domains/subChannel.ts +1 -1
- package/src/@types/index.ts +1 -3
- package/src/analytic/constant.ts +2 -1
- package/src/analytic/service/analytic/AnalyticsEngine.ts +9 -0
- package/src/analytic/service/analytic/AnalyticsEventCapturer.ts +63 -10
- package/src/analytic/service/analytic/AnalyticsEventSyncer.ts +34 -4
- package/src/categoryRepository/internalApi/queryCategories.ts +25 -18
- package/src/categoryRepository/observers/getCategories.ts +4 -3
- package/src/channelRepository/api/createChannel.ts +7 -3
- package/src/channelRepository/channelMembership/observers/getMembers.ts +9 -123
- package/src/channelRepository/channelMembership/observers/liveCollection/ChannelMemberLiveCollectionController.ts +154 -0
- package/src/channelRepository/channelMembership/observers/liveCollection/ChannelMemberPaginationController.ts +28 -0
- package/src/channelRepository/channelMembership/observers/liveCollection/ChannelMemberQueryStreamController.ts +109 -0
- package/src/channelRepository/channelMembership/observers/tests/getMembers.test.ts +3 -1
- package/src/channelRepository/observers/getChannels.ts +10 -316
- package/src/channelRepository/observers/liveCollection/ChannelLiveCollectionController.ts +413 -0
- package/src/channelRepository/observers/liveCollection/ChannelPaginationController.ts +36 -0
- package/src/channelRepository/observers/liveCollection/ChannelPagnationNoPageController.ts +20 -0
- package/src/channelRepository/observers/liveCollection/ChannelQueryStreamController.ts +89 -0
- package/src/channelRepository/observers/tests/getChannel.test.ts +4 -1
- package/src/channelRepository/observers/tests/getChannels.test.ts +153 -40
- package/src/channelRepository/utils/prepareChannelPayload.ts +1 -1
- package/src/client/utils/markerSyncEngine.ts +1 -1
- package/src/communityRepository/api/createCommunity.ts +7 -6
- package/src/communityRepository/api/queryCommunities.ts +12 -14
- package/src/communityRepository/api/test/queryCommunity.test.ts +18 -12
- package/src/communityRepository/api/updateCommunity.ts +4 -3
- package/src/communityRepository/communityMembership/api/queryCommunityMembers.ts +26 -25
- package/src/communityRepository/communityMembership/observers/getMembers.ts +4 -3
- package/src/communityRepository/observers/getCommunities.ts +8 -5
- package/src/communityRepository/utils/payload.ts +7 -2
- package/src/core/liveCollection/LiveCollectionController.ts +19 -5
- package/src/core/liveCollection/PaginationNoPageController.ts +26 -0
- package/src/core/model/idResolvers.ts +2 -0
- package/src/core/model/index.ts +2 -0
- package/src/core/query/sorting.ts +18 -0
- package/src/feedRepository/api/getCustomRankingGlobalFeed.ts +50 -8
- package/src/feedRepository/api/queryGlobalFeed.ts +56 -12
- package/src/index.ts +2 -1
- package/src/marker/api/getChannelMarkers.ts +6 -16
- package/src/marker/api/getMessageMarkers.ts +12 -20
- package/src/marker/api/tests/getChannelMarkers.test.ts +1 -11
- package/src/marker/api/tests/getMessageMarkers.test.ts +1 -11
- package/src/marker/events/onMessageMarked.ts +4 -5
- package/src/messagePreview/utils/getChannelMessagePreviewWithUser.ts +9 -2
- package/src/messageRepository/observers/liveCollection/MessageLiveCollectionController.ts +1 -0
- package/src/messageRepository/observers/liveCollection/MessageQueryStreamController.ts +2 -1
- package/src/postRepository/api/queryPosts.ts +12 -10
- package/src/postRepository/observers/getPosts.ts +7 -4
- package/src/role/api/queryRoles.ts +25 -6
- package/src/storyRepository/api/createImageStory.ts +94 -0
- package/src/storyRepository/api/createVideoStory.ts +92 -0
- package/src/storyRepository/api/hardDeleteStory.ts +6 -0
- package/src/storyRepository/api/index.ts +4 -0
- package/src/storyRepository/api/softDeleteStory.ts +6 -0
- package/src/storyRepository/events/onStoryCreated.ts +14 -0
- package/src/storyRepository/events/onStoryDeleted.ts +14 -0
- package/src/storyRepository/events/onStoryError.ts +14 -0
- package/src/storyRepository/index.ts +2 -0
- package/src/storyRepository/internalApi/createStory.ts +26 -0
- package/src/storyRepository/internalApi/deleteStory.ts +35 -0
- package/src/storyRepository/internalApi/getActiveStoriesByTarget.ts +36 -0
- package/src/storyRepository/observers/getActiveStoriesByTarget.ts +163 -0
- package/src/storyRepository/observers/index.ts +1 -0
- package/src/storyRepository/utils/convertRawToStory.ts +16 -0
- package/src/storyRepository/utils/convertStoryPayloadToRaw.ts +43 -0
- package/src/storyRepository/utils/createOptimisticEvent.ts +63 -0
- package/src/storyRepository/utils/getStoryCache.ts +6 -0
- package/src/streamRepository/api/index.ts +1 -1
- package/src/streamRepository/api/queryStreams.ts +2 -0
- package/src/streamRepository/internalApi/queryStreams.ts +57 -0
- package/src/streamRepository/observers/getStreams.ts +6 -5
- package/src/subChannelRepository/observers/getSubChannels.ts +8 -228
- package/src/subChannelRepository/observers/liveCollection/SubChannelLiveCollectionController.ts +274 -0
- package/src/subChannelRepository/observers/liveCollection/SubChannelPaginationController.ts +35 -0
- package/src/subChannelRepository/observers/liveCollection/SubChannelQueryStreamController.ts +94 -0
- package/src/subChannelRepository/observers/tests/getSubChannels.test.ts +73 -45
- package/src/subChannelRepository/observers/tests/getSubChannelsWithMessagePreview.test.ts +58 -21
- package/src/subChannelRepository/utils/prepareSubChannelPayload.ts +1 -1
- package/src/utils/constants.ts +5 -0
- package/src/utils/linkedObject/commentLinkedObject.ts +3 -1
- package/src/utils/linkedObject/index.ts +2 -0
- package/src/utils/linkedObject/postLinkedObject.ts +4 -2
- package/src/utils/linkedObject/storyLinkedObject.ts +83 -0
- package/src/utils/tests/dummy/channel.ts +14 -4
- package/dist/categoryRepository/api/queryCategories.d.ts +0 -32
- package/dist/categoryRepository/api/queryCategories.d.ts.map +0 -1
- package/src/categoryRepository/api/queryCategories.ts +0 -116
package/src/subChannelRepository/observers/liveCollection/SubChannelLiveCollectionController.ts
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
/* eslint-disable no-use-before-define */
|
|
2
|
+
import hash from 'object-hash';
|
|
3
|
+
import { LiveCollectionController } from '~/core/liveCollection/LiveCollectionController';
|
|
4
|
+
import { pullFromCache, pushToCache } from '~/cache/api';
|
|
5
|
+
import { SubChannelPaginationController } from './SubChannelPaginationController';
|
|
6
|
+
import { SubChannelQueryStreamController } from './SubChannelQueryStreamController';
|
|
7
|
+
import {
|
|
8
|
+
onSubChannelCreated,
|
|
9
|
+
onSubChannelDeleted,
|
|
10
|
+
onSubChannelUpdated,
|
|
11
|
+
} from '~/subChannelRepository/events';
|
|
12
|
+
import { onMessageCreated, onMessageUpdated, onMessageDeleted } from '~/messageRepository/events';
|
|
13
|
+
import { onSubChannelMarkerFetched, onSubChannelMarkerUpdated } from '~/marker/events';
|
|
14
|
+
import { convertEventPayload } from '~/utils/event';
|
|
15
|
+
import { filterByPropEquality, sortByLastActivity } from '~/core/query';
|
|
16
|
+
import { getActiveClient } from '~/client';
|
|
17
|
+
import {
|
|
18
|
+
getSubChannelMessagePreview,
|
|
19
|
+
getSubChannelMessagePreviewWithUser,
|
|
20
|
+
handleMessageCreated,
|
|
21
|
+
handleMessageUpdated,
|
|
22
|
+
} from '~/messagePreview/utils';
|
|
23
|
+
import { getSubChannel } from '~/subChannelRepository/api/getSubChannel';
|
|
24
|
+
import { updateSubChannelCache } from '~/subChannelRepository/utils/updateSubChannelCache';
|
|
25
|
+
import { prepareSubChannelPayload } from '~/subChannelRepository/utils';
|
|
26
|
+
import { onSubChannelFetched } from '~/subChannelRepository/events/onSubChannelFetched';
|
|
27
|
+
|
|
28
|
+
export class SubChannelLiveCollectionController extends LiveCollectionController<
|
|
29
|
+
'subChannel',
|
|
30
|
+
Amity.SubChannelLiveCollection,
|
|
31
|
+
Amity.SubChannel,
|
|
32
|
+
SubChannelPaginationController
|
|
33
|
+
> {
|
|
34
|
+
private queryStreamController: SubChannelQueryStreamController;
|
|
35
|
+
|
|
36
|
+
private query: Amity.SubChannelLiveCollection;
|
|
37
|
+
|
|
38
|
+
constructor(
|
|
39
|
+
query: Amity.SubChannelLiveCollection,
|
|
40
|
+
callback: Amity.LiveCollectionCallback<Amity.SubChannel>,
|
|
41
|
+
) {
|
|
42
|
+
const queryStreamId = hash(query);
|
|
43
|
+
const cacheKey = ['subChannel', 'collection', queryStreamId];
|
|
44
|
+
const paginationController = new SubChannelPaginationController(query);
|
|
45
|
+
|
|
46
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
47
|
+
|
|
48
|
+
this.query = query;
|
|
49
|
+
this.queryStreamController = new SubChannelQueryStreamController(
|
|
50
|
+
this.query,
|
|
51
|
+
this.cacheKey,
|
|
52
|
+
this.notifyChange.bind(this),
|
|
53
|
+
prepareSubChannelPayload,
|
|
54
|
+
);
|
|
55
|
+
this.callback = callback.bind(this);
|
|
56
|
+
this.loadPage(true);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
protected setup() {
|
|
60
|
+
const collection = pullFromCache<Amity.SubChannelLiveCollectionCache>(this.cacheKey)?.data;
|
|
61
|
+
if (!collection) {
|
|
62
|
+
pushToCache(this.cacheKey, {
|
|
63
|
+
data: [],
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
protected async persistModel(response: Amity.SubChannelPayload & Amity.Pagination) {
|
|
69
|
+
await this.queryStreamController.saveToMainDB(response);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
protected persistQueryStream({
|
|
73
|
+
response,
|
|
74
|
+
direction,
|
|
75
|
+
refresh,
|
|
76
|
+
}: Amity.LiveCollectionPersistQueryStreamParams<'subChannel'>) {
|
|
77
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
startSubscription() {
|
|
81
|
+
return this.queryStreamController.subscribeRTE([
|
|
82
|
+
{ fn: onSubChannelFetched, action: 'onCreate' },
|
|
83
|
+
{ fn: onSubChannelCreated, action: 'onCreate' },
|
|
84
|
+
{ fn: onSubChannelDeleted, action: 'onDelete' },
|
|
85
|
+
{
|
|
86
|
+
fn: callback => {
|
|
87
|
+
return onSubChannelUpdated(async (subChannel: Amity.SubChannel) => {
|
|
88
|
+
const collection = pullFromCache<Amity.SubChannelLiveCollectionCache>(
|
|
89
|
+
this.cacheKey,
|
|
90
|
+
)?.data;
|
|
91
|
+
|
|
92
|
+
if (!collection || !collection.data.includes(subChannel.subChannelId)) return;
|
|
93
|
+
|
|
94
|
+
const client = getActiveClient();
|
|
95
|
+
const messagePreviewSetting = await client.getMessagePreviewSetting(false);
|
|
96
|
+
|
|
97
|
+
if (messagePreviewSetting !== Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW) {
|
|
98
|
+
const messagePreview = getSubChannelMessagePreview(subChannel.subChannelId);
|
|
99
|
+
|
|
100
|
+
if (messagePreview?.subChannelId === subChannel.subChannelId) {
|
|
101
|
+
pushToCache(['messagePreviewSubChannel', 'get', subChannel.subChannelId], {
|
|
102
|
+
...messagePreview,
|
|
103
|
+
subChannelName: subChannel.displayName,
|
|
104
|
+
subChannelUpdatedAt: subChannel.updatedAt,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
callback(subChannel);
|
|
110
|
+
});
|
|
111
|
+
},
|
|
112
|
+
action: 'onUpdate',
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
fn: callback => {
|
|
116
|
+
return onMessageCreated(async message => {
|
|
117
|
+
const cacheData = pullFromCache<Amity.SubChannel>([
|
|
118
|
+
'subChannel',
|
|
119
|
+
'get',
|
|
120
|
+
message.subChannelId,
|
|
121
|
+
]);
|
|
122
|
+
|
|
123
|
+
if (!cacheData) return;
|
|
124
|
+
|
|
125
|
+
const collection = pullFromCache<Amity.SubChannelLiveCollectionCache>(
|
|
126
|
+
this.cacheKey,
|
|
127
|
+
)?.data;
|
|
128
|
+
|
|
129
|
+
if (!collection || !collection.data.includes(message.subChannelId)) return;
|
|
130
|
+
|
|
131
|
+
const client = getActiveClient();
|
|
132
|
+
const messagePreviewSetting = await client.getMessagePreviewSetting(false);
|
|
133
|
+
|
|
134
|
+
if (messagePreviewSetting === Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW) return;
|
|
135
|
+
|
|
136
|
+
handleMessageCreated(message);
|
|
137
|
+
|
|
138
|
+
const subChannelCache = pullFromCache<Amity.SubChannel>([
|
|
139
|
+
'subChannel',
|
|
140
|
+
'get',
|
|
141
|
+
message.subChannelId,
|
|
142
|
+
])?.data;
|
|
143
|
+
if (!subChannelCache) return;
|
|
144
|
+
|
|
145
|
+
updateSubChannelCache(message.subChannelId, subChannelCache, {
|
|
146
|
+
lastActivity: message.createdAt,
|
|
147
|
+
messagePreviewId: message.messageId,
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
callback({
|
|
151
|
+
...cacheData.data,
|
|
152
|
+
messagePreviewId: message.messageId,
|
|
153
|
+
subChannelId: message.subChannelId,
|
|
154
|
+
lastActivity: message.createdAt,
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
},
|
|
158
|
+
action: 'onUpdate',
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
fn: callback => {
|
|
162
|
+
return onSubChannelMarkerUpdated((subChannelMarkers: Amity.SubChannelMarker[]) => {
|
|
163
|
+
const subChannelWithMarkerUpdated =
|
|
164
|
+
subChannelMarkers
|
|
165
|
+
.map(
|
|
166
|
+
({ feedId }) => pullFromCache<Amity.SubChannel>(['subChannel', 'get', feedId])!,
|
|
167
|
+
)
|
|
168
|
+
.filter(Boolean)
|
|
169
|
+
.map(({ data }) => data) ?? [];
|
|
170
|
+
|
|
171
|
+
if (subChannelWithMarkerUpdated.length === 0) return;
|
|
172
|
+
callback(subChannelWithMarkerUpdated);
|
|
173
|
+
});
|
|
174
|
+
},
|
|
175
|
+
action: 'onUpdate',
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
fn: convertEventPayload(
|
|
179
|
+
(callback: Amity.Listener<Amity.Message>) => {
|
|
180
|
+
const updateMessagePreview = async (message: Amity.Message) => {
|
|
181
|
+
const client = getActiveClient();
|
|
182
|
+
const messagePreviewSetting = await client.getMessagePreviewSetting(false);
|
|
183
|
+
|
|
184
|
+
if (messagePreviewSetting === Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW) return;
|
|
185
|
+
|
|
186
|
+
const collection = pullFromCache<Amity.SubChannelLiveCollectionCache>(
|
|
187
|
+
this.cacheKey,
|
|
188
|
+
)?.data;
|
|
189
|
+
|
|
190
|
+
if (!collection || !collection.data.includes(message.subChannelId)) return;
|
|
191
|
+
|
|
192
|
+
handleMessageUpdated(message);
|
|
193
|
+
|
|
194
|
+
callback(message);
|
|
195
|
+
};
|
|
196
|
+
return onMessageUpdated(updateMessagePreview);
|
|
197
|
+
},
|
|
198
|
+
'subChannelId',
|
|
199
|
+
'subChannel',
|
|
200
|
+
),
|
|
201
|
+
action: 'onUpdate',
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
fn: convertEventPayload(
|
|
205
|
+
(callback: Amity.Listener<Amity.Message>) => {
|
|
206
|
+
const updateMessagePreview = async (message: Amity.Message) => {
|
|
207
|
+
const client = getActiveClient();
|
|
208
|
+
const messagePreviewSetting = await client.getMessagePreviewSetting(false);
|
|
209
|
+
|
|
210
|
+
if (messagePreviewSetting === Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW) return;
|
|
211
|
+
|
|
212
|
+
const collection = pullFromCache<Amity.SubChannelLiveCollectionCache>(
|
|
213
|
+
this.cacheKey,
|
|
214
|
+
)?.data;
|
|
215
|
+
|
|
216
|
+
if (!collection || !collection.data.includes(message.subChannelId)) return;
|
|
217
|
+
|
|
218
|
+
if (
|
|
219
|
+
messagePreviewSetting ===
|
|
220
|
+
Amity.MessagePreviewSetting.MESSAGE_PREVIEW_NOT_INCLUDE_DELETED
|
|
221
|
+
) {
|
|
222
|
+
await getSubChannel(message.subChannelId);
|
|
223
|
+
} else {
|
|
224
|
+
await handleMessageUpdated(message);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
callback(message);
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
return onMessageDeleted(updateMessagePreview);
|
|
231
|
+
},
|
|
232
|
+
'subChannelId',
|
|
233
|
+
'subChannel',
|
|
234
|
+
),
|
|
235
|
+
action: 'onUpdate',
|
|
236
|
+
},
|
|
237
|
+
]);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
notifyChange({ origin, loading, error }: Amity.LiveCollectionNotifyParams) {
|
|
241
|
+
const collection = pullFromCache<Amity.SubChannelLiveCollectionCache>(this.cacheKey)?.data;
|
|
242
|
+
if (!collection) return;
|
|
243
|
+
|
|
244
|
+
const data = this.applyFilter(
|
|
245
|
+
collection.data
|
|
246
|
+
.map(subChannelId => pullFromCache<Amity.SubChannel>(['subChannel', 'get', subChannelId])!)
|
|
247
|
+
.filter(Boolean)
|
|
248
|
+
.map(({ data }) => data)
|
|
249
|
+
.map(getSubChannelMessagePreviewWithUser) ?? [],
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
if (!this.shouldNotify(data) && origin === 'event') return;
|
|
253
|
+
|
|
254
|
+
this.callback({
|
|
255
|
+
onNextPage: () => this.loadPage(false, Amity.LiveCollectionPageDirection.NEXT),
|
|
256
|
+
data,
|
|
257
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
258
|
+
loading,
|
|
259
|
+
error,
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
applyFilter(data: Amity.SubChannel[]) {
|
|
264
|
+
let subChannels = data;
|
|
265
|
+
|
|
266
|
+
if (!this.query.includeDeleted) {
|
|
267
|
+
subChannels = filterByPropEquality(data, 'isDeleted', false);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
subChannels.sort(sortByLastActivity);
|
|
271
|
+
|
|
272
|
+
return subChannels;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/* eslint-disable no-use-before-define */
|
|
2
|
+
|
|
3
|
+
import { PaginationController } from '~/core/liveCollection/PaginationController';
|
|
4
|
+
import { COLLECTION_DEFAULT_PAGINATION_LIMIT } from '~/utils/constants';
|
|
5
|
+
import { convertQueryParams } from '~/subChannelRepository/utils';
|
|
6
|
+
import { inferIsDeleted } from '~/utils/inferIsDeleted';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
10
|
+
* TODO: check if querybyIds is supported
|
|
11
|
+
*/
|
|
12
|
+
export class SubChannelPaginationController extends PaginationController<
|
|
13
|
+
'subChannel',
|
|
14
|
+
Amity.SubChannelLiveCollection
|
|
15
|
+
> {
|
|
16
|
+
async getRequest(queryParams: Amity.SubChannelLiveCollection, token: string | undefined) {
|
|
17
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, ...params } = queryParams;
|
|
18
|
+
const { channelId, includeDeleted, ...restProcessedParams } = convertQueryParams(params) ?? {};
|
|
19
|
+
|
|
20
|
+
const options = token ? { token } : { limit };
|
|
21
|
+
|
|
22
|
+
const { data: queryResponse } = await this.http.get<Amity.SubChannelPayload & Amity.Pagination>(
|
|
23
|
+
`/api/v5/message-feeds/channel/${channelId}`,
|
|
24
|
+
{
|
|
25
|
+
params: {
|
|
26
|
+
...restProcessedParams,
|
|
27
|
+
isDeleted: inferIsDeleted(includeDeleted),
|
|
28
|
+
options,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
return queryResponse;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/* eslint-disable no-use-before-define */
|
|
2
|
+
import { QueryStreamController } from '~/core/liveCollection/QueryStreamController';
|
|
3
|
+
import { pullFromCache, pushToCache } from '~/cache/api';
|
|
4
|
+
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
5
|
+
import { getActiveClient } from '~/client';
|
|
6
|
+
|
|
7
|
+
export class SubChannelQueryStreamController extends QueryStreamController<
|
|
8
|
+
Amity.SubChannelPayload,
|
|
9
|
+
Amity.SubChannelLiveCollection
|
|
10
|
+
> {
|
|
11
|
+
private notifyChange: (params: Amity.LiveCollectionNotifyParams) => void;
|
|
12
|
+
|
|
13
|
+
private preparePayload: (
|
|
14
|
+
response: Amity.SubChannelPayload,
|
|
15
|
+
) => Promise<Amity.ProcessedSubChannelPayload>;
|
|
16
|
+
|
|
17
|
+
constructor(
|
|
18
|
+
query: Amity.SubChannelLiveCollection,
|
|
19
|
+
cacheKey: string[],
|
|
20
|
+
notifyChange: (params: Amity.LiveCollectionNotifyParams) => void,
|
|
21
|
+
preparePayload: (
|
|
22
|
+
response: Amity.SubChannelPayload,
|
|
23
|
+
) => Promise<Amity.ProcessedSubChannelPayload>,
|
|
24
|
+
) {
|
|
25
|
+
super(query, cacheKey);
|
|
26
|
+
this.notifyChange = notifyChange;
|
|
27
|
+
this.preparePayload = preparePayload;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async saveToMainDB(response: Amity.SubChannelPayload) {
|
|
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.SubChannelPayload & Partial<Amity.Pagination>,
|
|
43
|
+
direction: Amity.LiveCollectionPageDirection,
|
|
44
|
+
refresh = false,
|
|
45
|
+
) {
|
|
46
|
+
if (refresh) {
|
|
47
|
+
pushToCache(this.cacheKey, {
|
|
48
|
+
data: response.messageFeeds.map(({ messageFeedId }) => messageFeedId),
|
|
49
|
+
});
|
|
50
|
+
} else {
|
|
51
|
+
const collection = pullFromCache<Amity.SubChannelLiveCollectionCache>(this.cacheKey)?.data;
|
|
52
|
+
|
|
53
|
+
const subChannels = collection?.data ?? [];
|
|
54
|
+
|
|
55
|
+
pushToCache(this.cacheKey, {
|
|
56
|
+
...collection,
|
|
57
|
+
data: [
|
|
58
|
+
...new Set([
|
|
59
|
+
...subChannels,
|
|
60
|
+
...response.messageFeeds.map(({ messageFeedId }) => messageFeedId),
|
|
61
|
+
]),
|
|
62
|
+
],
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
reactor(action: string) {
|
|
68
|
+
return (payload: Amity.SubChannel | Amity.SubChannel[]) => {
|
|
69
|
+
const collection = pullFromCache<Amity.SubChannelLiveCollectionCache>(this.cacheKey)?.data;
|
|
70
|
+
if (!collection) return;
|
|
71
|
+
|
|
72
|
+
if (!Array.isArray(payload)) {
|
|
73
|
+
if (this.query.channelId !== payload.channelId) return;
|
|
74
|
+
|
|
75
|
+
if (action === 'onCreate') {
|
|
76
|
+
collection.data = [...new Set([payload.subChannelId, ...collection.data])];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
pushToCache(this.cacheKey, collection);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
this.notifyChange({ origin: Amity.LiveDataOrigin.EVENT, loading: false });
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
subscribeRTE(
|
|
87
|
+
createSubscriber: {
|
|
88
|
+
fn: (reactor: Amity.Listener<Amity.SubChannel | Amity.SubChannel[]>) => Amity.Unsubscriber;
|
|
89
|
+
action: string;
|
|
90
|
+
}[],
|
|
91
|
+
) {
|
|
92
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -160,24 +160,24 @@ describe('getSubChannels', () => {
|
|
|
160
160
|
|
|
161
161
|
test('when querying two subchannel collections with same channelId but different params, pagination remains functional', async () => {
|
|
162
162
|
const subChannelCase1Page1 = [
|
|
163
|
-
generateRawSubChannel({ channelPublicId: 'channel1', name: '1' }),
|
|
164
|
-
generateRawSubChannel({ channelPublicId: 'channel1', name: '2' }),
|
|
163
|
+
generateRawSubChannel({ channelPublicId: 'channel1', name: '1', messageFeedId: '1' }),
|
|
164
|
+
generateRawSubChannel({ channelPublicId: 'channel1', name: '2', messageFeedId: '2' }),
|
|
165
165
|
];
|
|
166
166
|
const subChannelCase1Page2 = [
|
|
167
|
-
generateRawSubChannel({ channelPublicId: 'channel1', name: '3' }),
|
|
168
|
-
generateRawSubChannel({ channelPublicId: 'channel1', name: '4' }),
|
|
167
|
+
generateRawSubChannel({ channelPublicId: 'channel1', name: '3', messageFeedId: '3' }),
|
|
168
|
+
generateRawSubChannel({ channelPublicId: 'channel1', name: '4', messageFeedId: '4' }),
|
|
169
169
|
];
|
|
170
170
|
const subChannelCase2Page1 = [
|
|
171
|
-
generateRawSubChannel({ channelPublicId: 'channel1', name: 'x6' }),
|
|
172
|
-
generateRawSubChannel({ channelPublicId: 'channel1', name: 'x5' }),
|
|
171
|
+
generateRawSubChannel({ channelPublicId: 'channel1', name: 'x6', messageFeedId: 'x6' }),
|
|
172
|
+
generateRawSubChannel({ channelPublicId: 'channel1', name: 'x5', messageFeedId: 'x5' }),
|
|
173
173
|
];
|
|
174
174
|
const subChannelCase2Page2 = [
|
|
175
|
-
generateRawSubChannel({ channelPublicId: 'channel1', name: 'x4' }),
|
|
176
|
-
generateRawSubChannel({ channelPublicId: 'channel1', name: 'x3' }),
|
|
175
|
+
generateRawSubChannel({ channelPublicId: 'channel1', name: 'x4', messageFeedId: 'x4' }),
|
|
176
|
+
generateRawSubChannel({ channelPublicId: 'channel1', name: 'x3', messageFeedId: 'x3' }),
|
|
177
177
|
];
|
|
178
178
|
const subChannelCase2Page3 = [
|
|
179
|
-
generateRawSubChannel({ channelPublicId: 'channel1', name: 'x2' }),
|
|
180
|
-
generateRawSubChannel({ channelPublicId: 'channel1', name: 'x1' }),
|
|
179
|
+
generateRawSubChannel({ channelPublicId: 'channel1', name: 'x2', messageFeedId: 'x2' }),
|
|
180
|
+
generateRawSubChannel({ channelPublicId: 'channel1', name: 'x1', messageFeedId: 'x1' }),
|
|
181
181
|
];
|
|
182
182
|
|
|
183
183
|
const callback = jest.fn();
|
|
@@ -185,7 +185,7 @@ describe('getSubChannels', () => {
|
|
|
185
185
|
|
|
186
186
|
client.http.get = jest.fn().mockImplementation((url, params) => {
|
|
187
187
|
if (params.params?.excludeDefaultMessageFeed === true) {
|
|
188
|
-
if (params?.params
|
|
188
|
+
if (params?.params?.options?.token === 'eyJiZWZvcmUiOjU1LCJsYXN0IjoxMH0=') {
|
|
189
189
|
return Promise.resolve({
|
|
190
190
|
data: {
|
|
191
191
|
messageFeeds: subChannelCase2Page2,
|
|
@@ -194,13 +194,13 @@ describe('getSubChannels', () => {
|
|
|
194
194
|
files: [],
|
|
195
195
|
paging: {
|
|
196
196
|
previous: 'eyJiZWZvcmUiOjQ1LCJsYXN0IjoxMH0=',
|
|
197
|
-
next: '
|
|
197
|
+
next: 'eyJiZWZvcmUiOjQ1LCJsaW1pdCI6NX0=',
|
|
198
198
|
},
|
|
199
199
|
},
|
|
200
200
|
});
|
|
201
201
|
}
|
|
202
202
|
|
|
203
|
-
if (params?.params
|
|
203
|
+
if (params?.params?.options?.token === 'eyJiZWZvcmUiOjQ1LCJsaW1pdCI6NX0=') {
|
|
204
204
|
return Promise.resolve({
|
|
205
205
|
data: {
|
|
206
206
|
messageFeeds: subChannelCase2Page3,
|
|
@@ -227,7 +227,7 @@ describe('getSubChannels', () => {
|
|
|
227
227
|
},
|
|
228
228
|
});
|
|
229
229
|
}
|
|
230
|
-
if (params?.params
|
|
230
|
+
if (params?.params?.options?.token === 'eyJiZWZvcmUiOjU1LCJsYXN0IjoxMH0=') {
|
|
231
231
|
return Promise.resolve({
|
|
232
232
|
data: {
|
|
233
233
|
messageFeeds: subChannelCase1Page2,
|
|
@@ -261,34 +261,37 @@ describe('getSubChannels', () => {
|
|
|
261
261
|
|
|
262
262
|
await pause();
|
|
263
263
|
|
|
264
|
-
expect(callback).toHaveBeenCalledTimes(
|
|
264
|
+
expect(callback).toHaveBeenCalledTimes(2);
|
|
265
265
|
expect(callback).lastCalledWith(
|
|
266
266
|
expect.objectContaining({
|
|
267
|
-
data:
|
|
268
|
-
|
|
269
|
-
|
|
267
|
+
data: subChannelCase1Page1
|
|
268
|
+
.map(convertSubChannelFromRaw)
|
|
269
|
+
.map(getSubChannelMessagePreviewWithUser),
|
|
270
270
|
loading: false,
|
|
271
271
|
hasNextPage: true,
|
|
272
272
|
error: undefined,
|
|
273
273
|
}),
|
|
274
274
|
);
|
|
275
275
|
|
|
276
|
-
expect(callback2).toHaveBeenCalledTimes(
|
|
276
|
+
expect(callback2).toHaveBeenCalledTimes(2);
|
|
277
277
|
|
|
278
|
+
/**
|
|
279
|
+
* not have been called with subChannelCase1Page1
|
|
280
|
+
*/
|
|
278
281
|
expect(callback2).not.toHaveBeenCalledWith(
|
|
279
282
|
expect.objectContaining({
|
|
280
|
-
data:
|
|
281
|
-
|
|
282
|
-
|
|
283
|
+
data: subChannelCase1Page1
|
|
284
|
+
.map(convertSubChannelFromRaw)
|
|
285
|
+
.map(getSubChannelMessagePreviewWithUser),
|
|
283
286
|
loading: false,
|
|
284
287
|
}),
|
|
285
288
|
);
|
|
286
289
|
|
|
287
290
|
expect(callback2).lastCalledWith(
|
|
288
291
|
expect.objectContaining({
|
|
289
|
-
data:
|
|
290
|
-
|
|
291
|
-
|
|
292
|
+
data: subChannelCase2Page1
|
|
293
|
+
.map(convertSubChannelFromRaw)
|
|
294
|
+
.map(getSubChannelMessagePreviewWithUser),
|
|
292
295
|
loading: false,
|
|
293
296
|
hasNextPage: true,
|
|
294
297
|
error: undefined,
|
|
@@ -303,10 +306,15 @@ describe('getSubChannels', () => {
|
|
|
303
306
|
|
|
304
307
|
await pause();
|
|
305
308
|
|
|
306
|
-
|
|
309
|
+
/**
|
|
310
|
+
* calling callback 2 times so, callback2 should have been called 6 times with 3 pages of data
|
|
311
|
+
*/
|
|
312
|
+
expect(callback2).toHaveBeenCalledTimes(6);
|
|
307
313
|
expect(callback2).lastCalledWith(
|
|
308
314
|
expect.objectContaining({
|
|
309
|
-
data: [
|
|
315
|
+
data: [...subChannelCase2Page1, ...subChannelCase2Page2, ...subChannelCase2Page3]
|
|
316
|
+
.map(convertSubChannelFromRaw)
|
|
317
|
+
.map(getSubChannelMessagePreviewWithUser),
|
|
310
318
|
loading: false,
|
|
311
319
|
}),
|
|
312
320
|
);
|
|
@@ -315,25 +323,40 @@ describe('getSubChannels', () => {
|
|
|
315
323
|
|
|
316
324
|
await pause();
|
|
317
325
|
|
|
318
|
-
|
|
326
|
+
// /**
|
|
327
|
+
// * calling nextPage 1 times so, callback2 should have been called 4 times;
|
|
328
|
+
// */
|
|
329
|
+
expect(callback).toHaveBeenCalledTimes(4);
|
|
319
330
|
expect(callback).lastCalledWith(
|
|
320
331
|
expect.objectContaining({
|
|
321
|
-
data: [
|
|
332
|
+
data: [...subChannelCase1Page1, ...subChannelCase1Page2]
|
|
333
|
+
.map(convertSubChannelFromRaw)
|
|
334
|
+
.map(getSubChannelMessagePreviewWithUser),
|
|
322
335
|
loading: false,
|
|
323
336
|
}),
|
|
324
337
|
);
|
|
325
338
|
|
|
326
339
|
expect(callback).not.toHaveBeenCalledWith(
|
|
327
340
|
expect.objectContaining({
|
|
328
|
-
data: [
|
|
341
|
+
data: [...subChannelCase2Page1, ...subChannelCase2Page2, ...subChannelCase2Page3]
|
|
342
|
+
.map(convertSubChannelFromRaw)
|
|
343
|
+
.map(getSubChannelMessagePreviewWithUser),
|
|
329
344
|
loading: false,
|
|
330
345
|
}),
|
|
331
346
|
);
|
|
332
347
|
});
|
|
333
348
|
|
|
349
|
+
/**
|
|
350
|
+
* TODO: change this test to use with event
|
|
351
|
+
* and add test to check if query params is converted correct for includeDeleted
|
|
352
|
+
*/
|
|
334
353
|
describe('when querying the subchannel collection with specific sort and filter options, results sort correctly', () => {
|
|
335
|
-
const subChannel1 = generateRawSubChannel({ channelId: 'aaaaa' });
|
|
336
|
-
const deletedRawSubChannel = generateRawSubChannel({
|
|
354
|
+
const subChannel1 = generateRawSubChannel({ channelId: 'aaaaa', messageFeedId: 'aaaa-1' });
|
|
355
|
+
const deletedRawSubChannel = generateRawSubChannel({
|
|
356
|
+
channelId: 'aaaaa',
|
|
357
|
+
messageFeedId: 'aaaa-2',
|
|
358
|
+
isDeleted: true,
|
|
359
|
+
});
|
|
337
360
|
|
|
338
361
|
const filterCases: [
|
|
339
362
|
string,
|
|
@@ -345,12 +368,12 @@ describe('getSubChannels', () => {
|
|
|
345
368
|
'includeDeleted = true',
|
|
346
369
|
{ channelId: 'aaaaa', includeDeleted: true },
|
|
347
370
|
[deletedRawSubChannel, subChannel1],
|
|
348
|
-
[subChannel1],
|
|
371
|
+
[deletedRawSubChannel, subChannel1],
|
|
349
372
|
],
|
|
350
373
|
[
|
|
351
374
|
'includeDeleted = false',
|
|
352
375
|
{ channelId: 'aaaaa', includeDeleted: false },
|
|
353
|
-
[
|
|
376
|
+
[subChannel1],
|
|
354
377
|
[subChannel1],
|
|
355
378
|
],
|
|
356
379
|
];
|
|
@@ -386,14 +409,19 @@ describe('getSubChannels', () => {
|
|
|
386
409
|
test('when querying two subchannel collections with the same channelId but different params, results are distinct', async () => {
|
|
387
410
|
const callback = jest.fn();
|
|
388
411
|
const callback2 = jest.fn();
|
|
389
|
-
const subChannel = generateRawSubChannel({
|
|
412
|
+
const subChannel = generateRawSubChannel({
|
|
413
|
+
channelPublicId: 'channel1',
|
|
414
|
+
messageFeedId: 'channel1-subChannel1',
|
|
415
|
+
});
|
|
390
416
|
const subChannel2 = generateRawSubChannel({
|
|
391
417
|
channelPublicId: 'channel1',
|
|
392
418
|
lastMessageId: 'thisissubchannelforanothercase',
|
|
419
|
+
messageFeedId: 'channel1-subChannel2',
|
|
393
420
|
});
|
|
394
421
|
const defaultSubChannel = generateRawSubChannel({
|
|
395
422
|
channelPublicId: 'channel1',
|
|
396
423
|
lastMessageId: 'thisisdefault',
|
|
424
|
+
messageFeedId: 'channel1',
|
|
397
425
|
});
|
|
398
426
|
|
|
399
427
|
client.http.get = jest.fn().mockImplementation((url, params) => {
|
|
@@ -433,18 +461,18 @@ describe('getSubChannels', () => {
|
|
|
433
461
|
|
|
434
462
|
await pause(100);
|
|
435
463
|
|
|
436
|
-
expect(callback.mock.calls.length).toBe(
|
|
464
|
+
expect(callback.mock.calls.length).toBe(2);
|
|
465
|
+
/**
|
|
466
|
+
* excludeDefaultSubChannel: false
|
|
467
|
+
* should return [defaultSubChannel, subChannel];
|
|
468
|
+
*/
|
|
437
469
|
expect(callback).toHaveBeenCalledWith(
|
|
438
470
|
expect.objectContaining({
|
|
439
|
-
data: [
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
}),
|
|
443
|
-
);
|
|
444
|
-
expect(callback).lastCalledWith(
|
|
445
|
-
expect.objectContaining({
|
|
446
|
-
data: [convertSubChannelFromRaw(defaultSubChannel)],
|
|
471
|
+
data: [defaultSubChannel, subChannel]
|
|
472
|
+
.map(convertSubChannelFromRaw)
|
|
473
|
+
.map(getSubChannelMessagePreviewWithUser),
|
|
447
474
|
error: undefined,
|
|
475
|
+
hasNextPage: false,
|
|
448
476
|
loading: false,
|
|
449
477
|
}),
|
|
450
478
|
);
|
|
@@ -452,7 +480,7 @@ describe('getSubChannels', () => {
|
|
|
452
480
|
expect(callback2.mock.calls.length).toBe(2);
|
|
453
481
|
expect(callback2).lastCalledWith(
|
|
454
482
|
expect.objectContaining({
|
|
455
|
-
data: [convertSubChannelFromRaw(subChannel2)],
|
|
483
|
+
data: [{ ...convertSubChannelFromRaw(subChannel2), messagePreview: null }],
|
|
456
484
|
error: undefined,
|
|
457
485
|
loading: false,
|
|
458
486
|
}),
|