@amityco/ts-sdk 0.0.1-beta.42.2 → 0.0.1-beta.43
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 +11 -1
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/marker.d.ts +37 -0
- package/dist/@types/core/marker.d.ts.map +1 -0
- package/dist/@types/core/model.d.ts +10 -0
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +44 -0
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/channel.d.ts +5 -8
- package/dist/@types/domains/channel.d.ts.map +1 -1
- package/dist/@types/domains/client.d.ts +1 -0
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/@types/domains/marker.d.ts +15 -0
- package/dist/@types/domains/marker.d.ts.map +1 -0
- package/dist/@types/domains/message.d.ts +3 -0
- package/dist/@types/domains/message.d.ts.map +1 -1
- package/dist/@types/domains/partials.d.ts +3 -0
- package/dist/@types/domains/partials.d.ts.map +1 -1
- package/dist/@types/domains/subChannel.d.ts +2 -0
- package/dist/@types/domains/subChannel.d.ts.map +1 -1
- package/dist/channel/api/getChannels.d.ts.map +1 -1
- package/dist/channel/api/index.d.ts +0 -2
- package/dist/channel/api/index.d.ts.map +1 -1
- package/dist/channel/events/onChannelUpdated.d.ts.map +1 -1
- package/dist/channel/utils/index.d.ts +1 -2
- package/dist/channel/utils/index.d.ts.map +1 -1
- package/dist/channel/utils/prepareChannelPayload.d.ts +6 -0
- package/dist/channel/utils/prepareChannelPayload.d.ts.map +1 -0
- package/dist/channel/utils/tests/prepareChannelPayload.test.d.ts +5 -1
- package/dist/channel/utils/tests/prepareChannelPayload.test.d.ts.map +1 -1
- package/dist/client/api/activeUser.d.ts +2 -2
- package/dist/client/api/activeUser.d.ts.map +1 -1
- package/dist/client/api/connectClient.d.ts.map +1 -1
- package/dist/client/api/index.d.ts +2 -0
- package/dist/client/api/index.d.ts.map +1 -1
- package/dist/client/api/markerSync.d.ts +21 -0
- package/dist/client/api/markerSync.d.ts.map +1 -0
- package/dist/client/observers/getTotalUnreadCount.d.ts +18 -0
- package/dist/client/observers/getTotalUnreadCount.d.ts.map +1 -0
- package/dist/client/observers/index.d.ts +2 -0
- package/dist/client/observers/index.d.ts.map +1 -0
- package/dist/client/observers/tests/getTotalUnreadCount.test.d.ts +2 -0
- package/dist/client/observers/tests/getTotalUnreadCount.test.d.ts.map +1 -0
- package/dist/client/utils/index.d.ts +2 -0
- package/dist/client/utils/index.d.ts.map +1 -0
- package/dist/client/utils/markerSyncEngine.d.ts +46 -0
- package/dist/client/utils/markerSyncEngine.d.ts.map +1 -0
- package/dist/comment/api/getComments.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 +1931 -1159
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +1901 -1160
- package/dist/index.umd.js +4 -4
- package/dist/marker/api/getChannelMarkers.d.ts +18 -0
- package/dist/marker/api/getChannelMarkers.d.ts.map +1 -0
- package/dist/marker/api/getMessageMarkers.d.ts +18 -0
- package/dist/marker/api/getMessageMarkers.d.ts.map +1 -0
- package/dist/marker/api/getSubChannelMarkers.d.ts +18 -0
- package/dist/marker/api/getSubChannelMarkers.d.ts.map +1 -0
- package/dist/marker/api/getUserMarker.d.ts +8 -0
- package/dist/marker/api/getUserMarker.d.ts.map +1 -0
- package/dist/marker/api/index.d.ts +5 -0
- package/dist/marker/api/index.d.ts.map +1 -0
- package/dist/marker/api/tests/getChannelMarkers.test.d.ts +2 -0
- package/dist/marker/api/tests/getChannelMarkers.test.d.ts.map +1 -0
- package/dist/marker/api/tests/getMessageMarkers.test.d.ts +2 -0
- package/dist/marker/api/tests/getMessageMarkers.test.d.ts.map +1 -0
- package/dist/marker/api/tests/getSubChannelMarkers.test.d.ts +2 -0
- package/dist/marker/api/tests/getSubChannelMarkers.test.d.ts.map +1 -0
- package/dist/marker/events/index.d.ts +7 -0
- package/dist/marker/events/index.d.ts.map +1 -0
- package/dist/marker/events/onChannelMarkerFetched.d.ts +17 -0
- package/dist/marker/events/onChannelMarkerFetched.d.ts.map +1 -0
- package/dist/marker/events/onFeedlMarkerFetched.d.ts +17 -0
- package/dist/marker/events/onFeedlMarkerFetched.d.ts.map +1 -0
- package/dist/marker/events/onMessageMarkerFetched.d.ts +17 -0
- package/dist/marker/events/onMessageMarkerFetched.d.ts.map +1 -0
- package/dist/marker/events/onSubChannelMarkerFetched.d.ts +17 -0
- package/dist/marker/events/onSubChannelMarkerFetched.d.ts.map +1 -0
- package/dist/marker/events/onSubChannelMarkerUpdated.d.ts +17 -0
- package/dist/marker/events/onSubChannelMarkerUpdated.d.ts.map +1 -0
- package/dist/marker/events/onUserMarkerFetched.d.ts +17 -0
- package/dist/marker/events/onUserMarkerFetched.d.ts.map +1 -0
- package/dist/message/api/getMessage.d.ts.map +1 -1
- package/dist/message/api/getMessages.d.ts.map +1 -1
- package/dist/message/api/index.d.ts +1 -0
- package/dist/message/api/index.d.ts.map +1 -1
- package/dist/message/api/markAsDelivered.d.ts +17 -0
- package/dist/message/api/markAsDelivered.d.ts.map +1 -0
- package/dist/message/api/queryMessages.d.ts.map +1 -1
- package/dist/message/api/tests/markAsDelivered.test.d.ts +2 -0
- package/dist/message/api/tests/markAsDelivered.test.d.ts.map +1 -0
- package/dist/message/api/updateMessage.d.ts.map +1 -1
- package/dist/message/events/index.d.ts +1 -0
- package/dist/message/events/index.d.ts.map +1 -1
- package/dist/message/events/onMessageCreated.d.ts +2 -1
- package/dist/message/events/onMessageCreated.d.ts.map +1 -1
- package/dist/message/events/onMessageUpdated.d.ts.map +1 -1
- package/dist/message/utils/index.d.ts +1 -18
- package/dist/message/utils/index.d.ts.map +1 -1
- package/dist/message/utils/prepareMessagePayload.d.ts +16 -0
- package/dist/message/utils/prepareMessagePayload.d.ts.map +1 -0
- package/dist/post/api/getPosts.d.ts.map +1 -1
- package/dist/post/api/tests/getPosts.test.d.ts +2 -0
- package/dist/post/api/tests/getPosts.test.d.ts.map +1 -0
- package/dist/report/api/createReport.d.ts.map +1 -1
- package/dist/report/api/deleteReport.d.ts.map +1 -1
- package/dist/subChannel/api/getSubChannels.d.ts.map +1 -1
- package/dist/subChannel/api/index.d.ts +2 -0
- package/dist/subChannel/api/index.d.ts.map +1 -1
- package/dist/subChannel/api/startReadingAPI.d.ts +17 -0
- package/dist/subChannel/api/startReadingAPI.d.ts.map +1 -0
- package/dist/subChannel/api/stopReadingAPI.d.ts +17 -0
- package/dist/subChannel/api/stopReadingAPI.d.ts.map +1 -0
- package/dist/subChannel/events/onSubChannelUpdated.d.ts +1 -1
- package/dist/subChannel/events/onSubChannelUpdated.d.ts.map +1 -1
- package/dist/subChannel/observers/liveSubChannel.d.ts.map +1 -1
- package/dist/subChannel/utils/index.d.ts +2 -7
- package/dist/subChannel/utils/index.d.ts.map +1 -1
- package/dist/subChannel/utils/markReadEngine.d.ts +33 -0
- package/dist/subChannel/utils/markReadEngine.d.ts.map +1 -0
- package/dist/subChannel/utils/prepareSubChannelPayload.d.ts +15 -0
- package/dist/subChannel/utils/prepareSubChannelPayload.d.ts.map +1 -0
- package/dist/utils/liveObject.d.ts +1 -1
- package/dist/utils/liveObject.d.ts.map +1 -1
- package/dist/utils/tests/client.d.ts +1 -0
- package/dist/utils/tests/client.d.ts.map +1 -1
- package/dist/utils/tests/dummy/channel.d.ts +4 -0
- package/dist/utils/tests/dummy/channel.d.ts.map +1 -1
- package/dist/utils/tests/dummy/comment.d.ts.map +1 -1
- package/dist/utils/tests/dummy/index.d.ts +1 -0
- package/dist/utils/tests/dummy/index.d.ts.map +1 -1
- package/dist/utils/tests/dummy/marker.d.ts +6 -0
- package/dist/utils/tests/dummy/marker.d.ts.map +1 -0
- package/dist/utils/tests/dummy/message.d.ts +2 -0
- package/dist/utils/tests/dummy/message.d.ts.map +1 -1
- package/dist/utils/tests/dummy/subChannel.d.ts +1 -0
- package/dist/utils/tests/dummy/subChannel.d.ts.map +1 -1
- package/dist/utils/tests/utils.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/core/events.ts +13 -1
- package/src/@types/core/marker.ts +42 -0
- package/src/@types/core/model.ts +12 -0
- package/src/@types/core/payload.ts +52 -0
- package/src/@types/domains/channel.ts +5 -16
- package/src/@types/domains/client.ts +2 -0
- package/src/@types/domains/marker.ts +15 -0
- package/src/@types/domains/message.ts +3 -0
- package/src/@types/domains/partials.ts +4 -0
- package/src/@types/domains/subChannel.ts +2 -0
- package/src/channel/api/addChannelMembers.ts +1 -1
- package/src/channel/api/addChannelMembersRole.ts +1 -1
- package/src/channel/api/banChannelMembers.ts +1 -1
- package/src/channel/api/createChannel.ts +1 -1
- package/src/channel/api/getChannel.ts +1 -1
- package/src/channel/api/getChannels.ts +21 -5
- package/src/channel/api/index.ts +0 -3
- package/src/channel/api/joinChannel.ts +1 -1
- package/src/channel/api/leaveChannel.ts +1 -1
- package/src/channel/api/queryChannelMembers.ts +1 -1
- package/src/channel/api/queryChannels.ts +3 -3
- package/src/channel/api/removeChannelMembers.ts +1 -1
- package/src/channel/api/removeChannelMembersRole.ts +1 -1
- package/src/channel/api/tests/addChannelMembers.test.ts +16 -0
- package/src/channel/api/tests/createChannel.test.ts +29 -8
- package/src/channel/api/tests/getChannel.test.ts +11 -4
- package/src/channel/api/tests/getChannels.test.ts +22 -14
- package/src/channel/api/tests/queryChannelMembers.test.ts +13 -4
- package/src/channel/api/tests/queryChannels.test.ts +19 -9
- package/src/channel/api/unbanChannelMembers.ts +1 -1
- package/src/channel/api/updateChannel.ts +1 -1
- package/src/channel/events/onChannelCreated.ts +2 -2
- package/src/channel/events/onChannelDeleted.ts +4 -4
- package/src/channel/events/onChannelJoined.ts +2 -2
- package/src/channel/events/onChannelLeft.ts +2 -2
- package/src/channel/events/onChannelMemberAdded.ts +2 -2
- package/src/channel/events/onChannelMemberBanned.ts +3 -3
- package/src/channel/events/onChannelMemberRemoved.ts +2 -2
- package/src/channel/events/onChannelMemberUnbanned.ts +2 -2
- package/src/channel/events/onChannelMuted.ts +2 -2
- package/src/channel/events/onChannelUpdated.ts +25 -4
- package/src/channel/events/tests/onChannelCreated.test.ts +4 -1
- package/src/channel/events/tests/onChannelJoined.test.ts +5 -1
- package/src/channel/events/tests/onChannelMemberAdded.test.ts +5 -1
- package/src/channel/events/tests/onChannelMemberBanned.test.ts +4 -1
- package/src/channel/events/tests/onChannelMemberRemoved.test.ts +5 -1
- package/src/channel/events/tests/onChannelMemberUnbanned.test.ts +10 -10
- package/src/channel/events/tests/onChannelUpdated.test.ts +5 -1
- package/src/channel/observers/tests/liveChannelMembers.test.ts +5 -11
- package/src/channel/observers/tests/liveChannels.test.ts +21 -24
- package/src/channel/utils/index.ts +1 -57
- package/src/channel/utils/prepareChannelPayload.ts +91 -0
- package/src/channel/utils/tests/prepareChannelPayload.test.ts +102 -104
- package/src/client/api/activeUser.ts +2 -2
- package/src/client/api/connectClient.ts +2 -1
- package/src/client/api/index.ts +3 -0
- package/src/client/api/markerSync.ts +42 -0
- package/src/client/observers/getTotalUnreadCount.ts +52 -0
- package/src/client/observers/index.ts +1 -0
- package/src/client/observers/tests/getTotalUnreadCount.test.ts +126 -0
- package/src/client/utils/index.ts +1 -0
- package/src/client/utils/markerSyncEngine.ts +179 -0
- package/src/comment/api/getComments.ts +20 -4
- package/src/comment/api/tests/getComments.test.ts +12 -1
- package/src/comment/api/tests/queryComments.test.ts +2 -2
- package/src/core/model/idResolvers.ts +7 -0
- package/src/core/model/identifyModel.ts +1 -1
- package/src/core/model/index.ts +6 -0
- package/src/core/tests/query/query/runQuery.test.ts +3 -1
- package/src/group/utils/withUser.ts +2 -2
- package/src/index.ts +6 -0
- package/src/marker/api/getChannelMarkers.ts +53 -0
- package/src/marker/api/getMessageMarkers.ts +54 -0
- package/src/marker/api/getSubChannelMarkers.ts +54 -0
- package/src/marker/api/getUserMarker.ts +47 -0
- package/src/marker/api/index.ts +4 -0
- package/src/marker/api/tests/getChannelMarkers.test.ts +109 -0
- package/src/marker/api/tests/getMessageMarkers.test.ts +114 -0
- package/src/marker/api/tests/getSubChannelMarkers.test.ts +116 -0
- package/src/marker/events/index.ts +10 -0
- package/src/marker/events/onChannelMarkerFetched.ts +34 -0
- package/src/marker/events/onFeedlMarkerFetched.ts +34 -0
- package/src/marker/events/onMessageMarkerFetched.ts +34 -0
- package/src/marker/events/onSubChannelMarkerFetched.ts +34 -0
- package/src/marker/events/onSubChannelMarkerUpdated.ts +34 -0
- package/src/marker/events/onUserMarkerFetched.ts +34 -0
- package/src/message/api/createMessage.ts +1 -1
- package/src/message/api/getMessage.ts +6 -5
- package/src/message/api/getMessages.ts +7 -6
- package/src/message/api/index.ts +1 -0
- package/src/message/api/markAsDelivered.ts +36 -0
- package/src/message/api/queryMessages.ts +8 -6
- package/src/message/api/tests/createMessage.test.ts +13 -4
- package/src/message/api/tests/getMessage.test.ts +12 -3
- package/src/message/api/tests/getMessages.test.ts +14 -5
- package/src/message/api/tests/markAsDelivered.test.ts +83 -0
- package/src/message/api/tests/queryMessages.test.ts +14 -3
- package/src/message/api/updateMessage.ts +8 -7
- package/src/message/events/index.ts +2 -0
- package/src/message/events/onMessageCreated.ts +14 -41
- package/src/message/events/onMessageDeleted.ts +2 -2
- package/src/message/events/onMessageFlagCleared.ts +2 -2
- package/src/message/events/onMessageFlagged.ts +2 -2
- package/src/message/events/onMessageReactionAdded.ts +2 -2
- package/src/message/events/onMessageReactionRemoved.ts +2 -2
- package/src/message/events/onMessageUnflagged.ts +2 -2
- package/src/message/events/onMessageUpdated.ts +27 -5
- package/src/message/tests/events.test.ts +4 -2
- package/src/message/tests/observers/liveMessage.test.ts +22 -10
- package/src/message/tests/observers/liveMessages.test.ts +25 -18
- package/src/message/utils/index.ts +1 -140
- package/src/message/utils/prepareMessagePayload.ts +182 -0
- package/src/post/api/getPosts.ts +20 -4
- package/src/post/api/tests/getPosts.test.ts +18 -0
- package/src/reaction/events/onReactionAdded.ts +2 -2
- package/src/reaction/events/onReactionRemoved.ts +2 -2
- package/src/reaction/events/onReactorAdded.ts +2 -2
- package/src/reaction/events/onReactorRemoved.ts +2 -2
- package/src/report/api/createReport.ts +2 -1
- package/src/report/api/deleteReport.ts +2 -1
- package/src/subChannel/api/createSubChannel.ts +1 -1
- package/src/subChannel/api/getSubChannel.ts +1 -1
- package/src/subChannel/api/getSubChannels.ts +2 -1
- package/src/subChannel/api/index.ts +3 -0
- package/src/subChannel/api/querySubChannels.ts +1 -1
- package/src/subChannel/api/startReadingAPI.ts +33 -0
- package/src/subChannel/api/stopReadingAPI.ts +33 -0
- package/src/subChannel/api/tests/createSubChannel.test.ts +6 -3
- package/src/subChannel/api/tests/deleteSubChannel.test.ts +7 -5
- package/src/subChannel/api/tests/getSubChannel.test.ts +6 -4
- package/src/subChannel/api/tests/getSubChannels.test.ts +6 -3
- package/src/subChannel/api/tests/updateSubChannel.test.ts +6 -3
- package/src/subChannel/api/updateSubChannel.ts +1 -1
- package/src/subChannel/events/onSubChannelCreated.ts +2 -2
- package/src/subChannel/events/onSubChannelDeleted.ts +2 -2
- package/src/subChannel/events/onSubChannelUpdated.ts +43 -4
- package/src/subChannel/observers/liveSubChannel.ts +2 -0
- package/src/subChannel/observers/tests/liveSubChannel.test.ts +15 -10
- package/src/subChannel/observers/tests/liveSubChannels.test.ts +21 -14
- package/src/subChannel/utils/index.ts +2 -50
- package/src/subChannel/utils/markReadEngine.ts +117 -0
- package/src/subChannel/utils/prepareSubChannelPayload.ts +132 -0
- package/src/utils/liveObject.ts +15 -4
- package/src/utils/tests/client.ts +3 -1
- package/src/utils/tests/dummy/channel.ts +38 -21
- package/src/utils/tests/dummy/comment.ts +2 -2
- package/src/utils/tests/dummy/index.ts +1 -0
- package/src/utils/tests/dummy/marker.ts +68 -0
- package/src/utils/tests/dummy/message.ts +42 -2
- package/src/utils/tests/dummy/post.ts +1 -1
- package/src/utils/tests/dummy/subChannel.ts +16 -5
- package/src/utils/tests/utils.ts +4 -1
- package/dist/channel/api/startReading.d.ts +0 -17
- package/dist/channel/api/startReading.d.ts.map +0 -1
- package/dist/channel/api/stopReading.d.ts +0 -16
- package/dist/channel/api/stopReading.d.ts.map +0 -1
- package/dist/channel/api/tests/startReading.test.d.ts +0 -2
- package/dist/channel/api/tests/startReading.test.d.ts.map +0 -1
- package/dist/channel/api/tests/stopReading.test.d.ts +0 -2
- package/dist/channel/api/tests/stopReading.test.d.ts.map +0 -1
- package/src/channel/api/startReading.ts +0 -57
- package/src/channel/api/stopReading.ts +0 -53
- package/src/channel/api/tests/startReading.test.ts +0 -25
- package/src/channel/api/tests/stopReading.test.ts +0 -25
|
@@ -6,9 +6,11 @@ import {
|
|
|
6
6
|
client,
|
|
7
7
|
connectClient,
|
|
8
8
|
disconnectClient,
|
|
9
|
+
pause,
|
|
9
10
|
rawChannelUser,
|
|
10
11
|
user11,
|
|
11
12
|
} from '~/utils/tests';
|
|
13
|
+
|
|
12
14
|
import { onChannelMemberRemoved } from '../onChannelMemberRemoved';
|
|
13
15
|
|
|
14
16
|
describe('onChannelMemberRemoved event', () => {
|
|
@@ -31,12 +33,14 @@ describe('onChannelMemberRemoved event', () => {
|
|
|
31
33
|
users: [user11],
|
|
32
34
|
};
|
|
33
35
|
|
|
34
|
-
test('it should call callback when have someone remove member from channel', () => {
|
|
36
|
+
test('it should call callback when have someone remove member from channel', async () => {
|
|
35
37
|
const callback = jest.fn();
|
|
36
38
|
|
|
37
39
|
const unsub = onChannelMemberRemoved(callback);
|
|
38
40
|
client.emitter.emit('channel.membersRemoved', channelPayload);
|
|
39
41
|
|
|
42
|
+
await pause();
|
|
43
|
+
|
|
40
44
|
unsub();
|
|
41
45
|
|
|
42
46
|
expect(callback).toHaveBeenCalled();
|
|
@@ -10,21 +10,16 @@ import {
|
|
|
10
10
|
user11,
|
|
11
11
|
user12,
|
|
12
12
|
channelRaw1,
|
|
13
|
+
pause,
|
|
13
14
|
} from '~/utils/tests';
|
|
14
15
|
|
|
15
16
|
import { onChannelMemberUnbanned } from '../onChannelMemberUnbanned';
|
|
16
17
|
|
|
17
18
|
describe('onChannelMemberBanned event', () => {
|
|
18
|
-
beforeAll(
|
|
19
|
-
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
afterAll(async () => {
|
|
23
|
-
await disconnectClient();
|
|
24
|
-
});
|
|
19
|
+
beforeAll(connectClient);
|
|
20
|
+
afterAll(disconnectClient);
|
|
25
21
|
|
|
26
22
|
beforeEach(enableCache);
|
|
27
|
-
|
|
28
23
|
afterEach(disableCache);
|
|
29
24
|
|
|
30
25
|
const channelPayload: Amity.ChannelMembershipPayload = {
|
|
@@ -34,22 +29,27 @@ describe('onChannelMemberBanned event', () => {
|
|
|
34
29
|
users: [user11, user12],
|
|
35
30
|
};
|
|
36
31
|
|
|
37
|
-
test('it should call callback with channel and unbanned member', () => {
|
|
32
|
+
test('it should call callback with channel and unbanned member', async () => {
|
|
38
33
|
const callback = jest.fn();
|
|
39
34
|
|
|
40
35
|
const unsub = onChannelMemberUnbanned(callback);
|
|
41
36
|
client.emitter.emit('channel.unbanned', channelPayload);
|
|
42
37
|
|
|
38
|
+
await pause();
|
|
39
|
+
|
|
43
40
|
unsub();
|
|
44
41
|
|
|
45
42
|
expect(callback).toHaveBeenCalled();
|
|
46
43
|
expect(callback).toHaveBeenCalledWith(channel1, { ...rawChannelUser3, user: user12 });
|
|
47
44
|
});
|
|
48
45
|
|
|
49
|
-
test('it should return an Unsubscriber', () => {
|
|
46
|
+
test('it should return an Unsubscriber', async () => {
|
|
50
47
|
const callback = jest.fn();
|
|
51
48
|
|
|
52
49
|
const unsub = onChannelMemberUnbanned(callback);
|
|
50
|
+
|
|
51
|
+
await pause();
|
|
52
|
+
|
|
53
53
|
unsub();
|
|
54
54
|
|
|
55
55
|
client.emitter.emit('channel.unbanned', channelPayload);
|
|
@@ -5,9 +5,11 @@ import {
|
|
|
5
5
|
client,
|
|
6
6
|
connectClient,
|
|
7
7
|
disconnectClient,
|
|
8
|
+
pause,
|
|
8
9
|
rawChannelUser,
|
|
9
10
|
user11,
|
|
10
11
|
} from '~/utils/tests';
|
|
12
|
+
|
|
11
13
|
import { onChannelUpdated } from '../onChannelUpdated';
|
|
12
14
|
|
|
13
15
|
describe('onChannelUpdated event', () => {
|
|
@@ -30,12 +32,14 @@ describe('onChannelUpdated event', () => {
|
|
|
30
32
|
users: [user11],
|
|
31
33
|
};
|
|
32
34
|
|
|
33
|
-
test('it should call callback when channel have updated', () => {
|
|
35
|
+
test('it should call callback when channel have updated', async () => {
|
|
34
36
|
const callback = jest.fn();
|
|
35
37
|
|
|
36
38
|
const unsub = onChannelUpdated(callback);
|
|
37
39
|
client.emitter.emit('channel.updated', channelPayload);
|
|
38
40
|
|
|
41
|
+
await pause();
|
|
42
|
+
|
|
39
43
|
unsub();
|
|
40
44
|
|
|
41
45
|
expect(callback).toHaveBeenCalled();
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
channelUserWithRole,
|
|
13
13
|
client,
|
|
14
14
|
connectClient,
|
|
15
|
+
convertRawChannelPayload,
|
|
15
16
|
disconnectClient,
|
|
16
17
|
emptyChannelUserQueryResponse,
|
|
17
18
|
mutedChannelUser,
|
|
@@ -25,7 +26,6 @@ import {
|
|
|
25
26
|
} from '~/utils/tests';
|
|
26
27
|
|
|
27
28
|
import { liveChannelMembers } from '../liveChannelMembers';
|
|
28
|
-
import { prepareChannelPayload } from '../../utils';
|
|
29
29
|
|
|
30
30
|
const getSnapshot = (params?: Record<string, any>) => {
|
|
31
31
|
return {
|
|
@@ -37,16 +37,10 @@ const getSnapshot = (params?: Record<string, any>) => {
|
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
describe('liveChannelMembers', () => {
|
|
40
|
-
beforeAll(
|
|
41
|
-
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
afterAll(async () => {
|
|
45
|
-
await disconnectClient();
|
|
46
|
-
});
|
|
40
|
+
beforeAll(connectClient);
|
|
41
|
+
afterAll(disconnectClient);
|
|
47
42
|
|
|
48
43
|
beforeEach(enableCache);
|
|
49
|
-
|
|
50
44
|
afterEach(disableCache);
|
|
51
45
|
|
|
52
46
|
const { channelId } = channel1;
|
|
@@ -117,8 +111,8 @@ describe('liveChannelMembers', () => {
|
|
|
117
111
|
onNextPage();
|
|
118
112
|
await pause();
|
|
119
113
|
|
|
120
|
-
const payload =
|
|
121
|
-
const payload2 =
|
|
114
|
+
const payload = convertRawChannelPayload(channelUserQueryResponse.data);
|
|
115
|
+
const payload2 = convertRawChannelPayload(channelUserQueryResponsePage2.data);
|
|
122
116
|
|
|
123
117
|
const snapshot = getSnapshot();
|
|
124
118
|
snapshot.loading = false;
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
channelRaw2,
|
|
9
9
|
client,
|
|
10
10
|
connectClient,
|
|
11
|
+
convertRawChannelPayload,
|
|
11
12
|
disconnectClient,
|
|
12
13
|
generateRawChannel,
|
|
13
14
|
generateRawMessage,
|
|
@@ -17,8 +18,10 @@ import {
|
|
|
17
18
|
rawChannelUser2,
|
|
18
19
|
user11,
|
|
19
20
|
} from '~/utils/tests';
|
|
21
|
+
|
|
20
22
|
import { liveChannels } from '../liveChannels';
|
|
21
|
-
import { convertFromRaw
|
|
23
|
+
import { convertFromRaw } from '../../utils';
|
|
24
|
+
import * as getChannelMarkers from '../../../marker/api/getChannelMarkers';
|
|
22
25
|
|
|
23
26
|
const getSnapshot = (params?: Record<string, any>) => {
|
|
24
27
|
return {
|
|
@@ -29,24 +32,18 @@ const getSnapshot = (params?: Record<string, any>) => {
|
|
|
29
32
|
};
|
|
30
33
|
};
|
|
31
34
|
|
|
32
|
-
const convertFromRawParams = {
|
|
33
|
-
defaultSubChannelHasUnreadMention: false,
|
|
34
|
-
defaultSubChannelUnreadCount: 0,
|
|
35
|
-
localLastMentionSegment: 0,
|
|
36
|
-
localReadToSegment: 0,
|
|
37
|
-
};
|
|
38
|
-
|
|
39
35
|
describe('liveChannels', () => {
|
|
40
36
|
beforeAll(async () => {
|
|
41
37
|
await connectClient();
|
|
42
|
-
});
|
|
43
38
|
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
jest.spyOn(getChannelMarkers, 'getChannelMarkers').mockResolvedValue({
|
|
40
|
+
data: [],
|
|
41
|
+
cachedAt: undefined,
|
|
42
|
+
});
|
|
46
43
|
});
|
|
47
44
|
|
|
45
|
+
afterAll(disconnectClient);
|
|
48
46
|
beforeEach(enableCache);
|
|
49
|
-
|
|
50
47
|
afterEach(disableCache);
|
|
51
48
|
|
|
52
49
|
test('it should return channel collection', async () => {
|
|
@@ -62,7 +59,7 @@ describe('liveChannels', () => {
|
|
|
62
59
|
2,
|
|
63
60
|
expect.objectContaining(
|
|
64
61
|
getSnapshot({
|
|
65
|
-
data:
|
|
62
|
+
data: convertRawChannelPayload(channelQueryResponse.data).channels,
|
|
66
63
|
loading: false,
|
|
67
64
|
}),
|
|
68
65
|
),
|
|
@@ -83,7 +80,7 @@ describe('liveChannels', () => {
|
|
|
83
80
|
1,
|
|
84
81
|
expect.objectContaining(
|
|
85
82
|
getSnapshot({
|
|
86
|
-
data:
|
|
83
|
+
data: convertRawChannelPayload(channelQueryResponse.data).channels,
|
|
87
84
|
}),
|
|
88
85
|
),
|
|
89
86
|
);
|
|
@@ -91,7 +88,7 @@ describe('liveChannels', () => {
|
|
|
91
88
|
2,
|
|
92
89
|
expect.objectContaining(
|
|
93
90
|
getSnapshot({
|
|
94
|
-
data:
|
|
91
|
+
data: convertRawChannelPayload(channelQueryResponse.data).channels,
|
|
95
92
|
loading: false,
|
|
96
93
|
}),
|
|
97
94
|
),
|
|
@@ -102,17 +99,17 @@ describe('liveChannels', () => {
|
|
|
102
99
|
channelId: 'deleted-channel-id',
|
|
103
100
|
isDeleted: true,
|
|
104
101
|
});
|
|
105
|
-
const deletedChannel = convertFromRaw(rawDeletedChannel
|
|
102
|
+
const deletedChannel = convertFromRaw(rawDeletedChannel);
|
|
106
103
|
const rawTaggedChannel = generateRawChannel({
|
|
107
104
|
channelId: 'tagged-channel-id',
|
|
108
105
|
tags: ['tag1', 'tag2'],
|
|
109
106
|
});
|
|
110
|
-
const taggedChannel = convertFromRaw(rawTaggedChannel
|
|
107
|
+
const taggedChannel = convertFromRaw(rawTaggedChannel);
|
|
111
108
|
const rawTaggedChannel2 = generateRawChannel({
|
|
112
109
|
channelId: 'tagged-channel-id-2',
|
|
113
110
|
tags: ['tag2'],
|
|
114
111
|
});
|
|
115
|
-
const taggedChannel2 = convertFromRaw(rawTaggedChannel2
|
|
112
|
+
const taggedChannel2 = convertFromRaw(rawTaggedChannel2);
|
|
116
113
|
|
|
117
114
|
const filters: [string, Amity.ChannelLiveCollection, Amity.Channel[]][] = [
|
|
118
115
|
['deleted', { isDeleted: false }, [channel1, taggedChannel, taggedChannel2]],
|
|
@@ -187,8 +184,8 @@ describe('liveChannels', () => {
|
|
|
187
184
|
getSnapshot({
|
|
188
185
|
loading: false,
|
|
189
186
|
data: [
|
|
190
|
-
...
|
|
191
|
-
...
|
|
187
|
+
...convertRawChannelPayload(channelQueryResponsePage2.data).channels,
|
|
188
|
+
...convertRawChannelPayload(channelQueryResponse.data).channels,
|
|
192
189
|
],
|
|
193
190
|
}),
|
|
194
191
|
),
|
|
@@ -203,13 +200,13 @@ describe('liveChannels', () => {
|
|
|
203
200
|
'it should add new channel to collection onCreate',
|
|
204
201
|
'channel.created',
|
|
205
202
|
rawNewChannel,
|
|
206
|
-
[convertFromRaw(rawNewChannel
|
|
203
|
+
[convertFromRaw(rawNewChannel), channel1, channel2],
|
|
207
204
|
],
|
|
208
205
|
[
|
|
209
206
|
'it should add new channel to collection onJoin',
|
|
210
207
|
'channel.joined',
|
|
211
208
|
rawNewChannel,
|
|
212
|
-
[convertFromRaw(rawNewChannel
|
|
209
|
+
[convertFromRaw(rawNewChannel), channel1, channel2],
|
|
213
210
|
],
|
|
214
211
|
[
|
|
215
212
|
'it should update channel in collection onUpdate',
|
|
@@ -423,7 +420,8 @@ describe('liveChannels', () => {
|
|
|
423
420
|
});
|
|
424
421
|
});
|
|
425
422
|
|
|
426
|
-
|
|
423
|
+
// TODO: re-enable this after implement marker-sync service
|
|
424
|
+
xit('should increase the unread count once message is created', async () => {
|
|
427
425
|
const callback = jest.fn();
|
|
428
426
|
client.http.get = jest.fn().mockResolvedValue({
|
|
429
427
|
data: {
|
|
@@ -457,7 +455,6 @@ describe('liveChannels', () => {
|
|
|
457
455
|
data: [
|
|
458
456
|
{
|
|
459
457
|
...channel1,
|
|
460
|
-
defaultSubChannelUnreadCount: 1,
|
|
461
458
|
lastActivity: expect.anything(),
|
|
462
459
|
messageCount: channel1.messageCount + 1,
|
|
463
460
|
updatedAt: expect.anything(),
|
|
@@ -1,57 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { withUsers } from '~/group/utils';
|
|
3
|
-
|
|
4
|
-
export function convertFromRaw(
|
|
5
|
-
{ _id, ...rest }: Amity.RawChannel,
|
|
6
|
-
params: Pick<
|
|
7
|
-
Amity.Channel,
|
|
8
|
-
| 'defaultSubChannelHasUnreadMention'
|
|
9
|
-
| 'defaultSubChannelUnreadCount'
|
|
10
|
-
| 'localLastMentionSegment'
|
|
11
|
-
| 'localReadToSegment'
|
|
12
|
-
>,
|
|
13
|
-
): Amity.Channel {
|
|
14
|
-
return {
|
|
15
|
-
...rest,
|
|
16
|
-
...params,
|
|
17
|
-
defaultSubChannelId: _id,
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function getSegmentParams(rawChannel: Amity.RawChannel) {
|
|
22
|
-
let cached;
|
|
23
|
-
|
|
24
|
-
try {
|
|
25
|
-
cached = pullFromCache<Amity.Channel>(['channel', 'get', rawChannel.channelId]);
|
|
26
|
-
// eslint-disable-next-line no-empty
|
|
27
|
-
} catch {}
|
|
28
|
-
|
|
29
|
-
if (cached) {
|
|
30
|
-
return {
|
|
31
|
-
defaultSubChannelHasUnreadMention: cached.data.defaultSubChannelHasUnreadMention,
|
|
32
|
-
defaultSubChannelUnreadCount: cached.data.defaultSubChannelUnreadCount,
|
|
33
|
-
localReadToSegment: cached.data.localReadToSegment,
|
|
34
|
-
localLastMentionSegment: cached.data.localLastMentionSegment,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return {
|
|
39
|
-
defaultSubChannelHasUnreadMention: false,
|
|
40
|
-
defaultSubChannelUnreadCount: 0,
|
|
41
|
-
// @ts-ignore
|
|
42
|
-
localReadToSegment: rawChannel.messageCount > 0 ? rawChannel.messageCount - 1 : 0,
|
|
43
|
-
localLastMentionSegment: 0,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export const prepareChannelPayload = (
|
|
48
|
-
rawPayload: Amity.ChannelPayload,
|
|
49
|
-
): Amity.ProcessedChannelPayload => {
|
|
50
|
-
const channels: Amity.Channel[] = rawPayload.channels.map(channel =>
|
|
51
|
-
convertFromRaw(channel, getSegmentParams(channel)),
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
const channelUsers: Amity.Membership<'channel'>[] = withUsers(rawPayload.channelUsers);
|
|
55
|
-
|
|
56
|
-
return { ...rawPayload, channels, channelUsers };
|
|
57
|
-
};
|
|
1
|
+
export * from './prepareChannelPayload';
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { pullFromCache } from '~/cache/api/pullFromCache';
|
|
2
|
+
import { getActiveUser } from '~/client/api/activeUser';
|
|
3
|
+
import { getResolver } from '~/core/model';
|
|
4
|
+
import { withUsers } from '~/group/utils/withUser';
|
|
5
|
+
import { getChannelMarkers } from '~/marker/api';
|
|
6
|
+
|
|
7
|
+
export const MARKER_INCLUDED_CHANNEL_TYPE = ['broadcast', 'conversation', 'community'];
|
|
8
|
+
export const isUnreadCountSupport = ({ type }: Pick<Amity.RawChannel, 'type'>) =>
|
|
9
|
+
MARKER_INCLUDED_CHANNEL_TYPE.includes(type);
|
|
10
|
+
|
|
11
|
+
const getCachedMarker = (entityId: string) => {
|
|
12
|
+
const key = {
|
|
13
|
+
entityId,
|
|
14
|
+
userId: getActiveUser()._id,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
return pullFromCache<Amity.ChannelMarker>([
|
|
18
|
+
'channelMarker',
|
|
19
|
+
'get',
|
|
20
|
+
getResolver('channelMarker')(key),
|
|
21
|
+
])?.data;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const getUnreadCount = (channel: Amity.RawChannel, marker?: Amity.ChannelMarker) => {
|
|
25
|
+
if (marker?.isDeleted) {
|
|
26
|
+
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to
|
|
27
|
+
// leave the channel because currently backend can't handle this, so every time a user is banned
|
|
28
|
+
// from a channel or the channel is deleted the channel's unread count will reset to zero
|
|
29
|
+
return 0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return marker?.unreadCount ?? getCachedMarker(channel.channelId)?.unreadCount ?? 0;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export function convertFromRaw(
|
|
36
|
+
channel: Amity.RawChannel,
|
|
37
|
+
marker?: Amity.ChannelMarker,
|
|
38
|
+
): Amity.Channel {
|
|
39
|
+
return {
|
|
40
|
+
...channel,
|
|
41
|
+
isUnreadCountSupport: isUnreadCountSupport(channel),
|
|
42
|
+
unreadCount: getUnreadCount(channel, marker),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function updateChannelMarker(
|
|
47
|
+
channel: Amity.Channel,
|
|
48
|
+
marker?: Amity.ChannelMarker,
|
|
49
|
+
): Amity.Channel {
|
|
50
|
+
return {
|
|
51
|
+
...channel,
|
|
52
|
+
unreadCount: getUnreadCount(channel, marker),
|
|
53
|
+
updatedAt: new Date().toISOString(),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export const prepareChannelPayload = async (
|
|
58
|
+
rawPayload: Amity.ChannelPayload,
|
|
59
|
+
): Promise<Amity.ProcessedChannelPayload> => {
|
|
60
|
+
// make a fetch marker to prepare it for merging with the raw channel payload.
|
|
61
|
+
let markers: Amity.ChannelMarker[] = [];
|
|
62
|
+
|
|
63
|
+
const markerIds = rawPayload.channels
|
|
64
|
+
// filter channel by type. Only conversation, community and broadcast type are included.
|
|
65
|
+
.filter(isUnreadCountSupport)
|
|
66
|
+
.map(({ channelId }) => channelId);
|
|
67
|
+
|
|
68
|
+
if (markerIds.length > 0)
|
|
69
|
+
// from the spec, allow marker fetch to fail
|
|
70
|
+
try {
|
|
71
|
+
({ data: markers } = await getChannelMarkers(markerIds));
|
|
72
|
+
} catch (e) {
|
|
73
|
+
// empty block
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// attach marker to channel
|
|
77
|
+
const channels = rawPayload.channels.map(channel => {
|
|
78
|
+
const marker = markers?.find(({ entityId }) => entityId === channel.channelId);
|
|
79
|
+
|
|
80
|
+
return convertFromRaw(channel, marker);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// user marker to channel users
|
|
84
|
+
const channelUsers: Amity.Membership<'channel'>[] = withUsers(rawPayload.channelUsers);
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
...rawPayload,
|
|
88
|
+
channels,
|
|
89
|
+
channelUsers,
|
|
90
|
+
};
|
|
91
|
+
};
|
|
@@ -1,120 +1,118 @@
|
|
|
1
|
+
import { disableCache, enableCache, pushToCache } from '~/cache/api';
|
|
2
|
+
import { ASCApiError } from '~/core/errors';
|
|
1
3
|
import {
|
|
4
|
+
generateChannelMarker,
|
|
2
5
|
connectClient,
|
|
3
6
|
disconnectClient,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
channelRaw2,
|
|
8
|
-
rawChannelUser,
|
|
9
|
-
rawChannelUser2,
|
|
7
|
+
generateRawChannel,
|
|
8
|
+
generateRawChannelUser,
|
|
9
|
+
convertChannelUserFromRaw,
|
|
10
10
|
} from '~/utils/tests';
|
|
11
11
|
|
|
12
|
-
import
|
|
12
|
+
import * as getChannelMarkers from '../../../marker/api/getChannelMarkers';
|
|
13
|
+
import { isUnreadCountSupport, MARKER_INCLUDED_CHANNEL_TYPE, prepareChannelPayload } from '..';
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
export const communityChannel: Amity.RawChannel = generateRawChannel({
|
|
16
|
+
channelId: 'ch1',
|
|
17
|
+
type: 'community',
|
|
16
18
|
});
|
|
19
|
+
export const liveChannel: Amity.RawChannel = generateRawChannel({
|
|
20
|
+
channelId: 'ch2',
|
|
21
|
+
type: 'live',
|
|
22
|
+
});
|
|
23
|
+
export const conversationChannel: Amity.RawChannel = generateRawChannel({
|
|
24
|
+
channelId: 'ch3',
|
|
25
|
+
type: 'conversation',
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export const rawChannelUser = generateRawChannelUser();
|
|
29
|
+
|
|
30
|
+
export const channelUser = convertChannelUserFromRaw(rawChannelUser, undefined);
|
|
17
31
|
|
|
18
|
-
|
|
19
|
-
|
|
32
|
+
const channelMarker1 = generateChannelMarker({
|
|
33
|
+
entityId: communityChannel.channelId,
|
|
34
|
+
userId: 'user1',
|
|
20
35
|
});
|
|
21
36
|
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
37
|
+
const channelMarker2 = generateChannelMarker({
|
|
38
|
+
entityId: conversationChannel.channelId,
|
|
39
|
+
userId: 'user1',
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const resolvedChannelMarkers: Amity.Cached<Amity.Paged<Amity.ChannelMarker>> = {
|
|
43
|
+
data: [channelMarker1, channelMarker2],
|
|
44
|
+
cachedAt: Date.now(),
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const channelPayload: Amity.ChannelPayload = {
|
|
48
|
+
channels: [communityChannel, liveChannel, conversationChannel],
|
|
49
|
+
channelUsers: [rawChannelUser],
|
|
50
|
+
users: [],
|
|
25
51
|
files: [],
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const convertedChannelPayload: Amity.ProcessedChannelPayload = {
|
|
55
|
+
channels: [
|
|
56
|
+
{ ...communityChannel, isUnreadCountSupport: true, unreadCount: channelMarker1.unreadCount },
|
|
57
|
+
{ ...liveChannel, isUnreadCountSupport: false, unreadCount: 0 },
|
|
58
|
+
{ ...conversationChannel, isUnreadCountSupport: true, unreadCount: channelMarker2.unreadCount },
|
|
59
|
+
],
|
|
60
|
+
channelUsers: [channelUser],
|
|
26
61
|
users: [],
|
|
62
|
+
files: [],
|
|
27
63
|
};
|
|
28
64
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
channelUsers: [rawChannelUser2],
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
id: 5,
|
|
86
|
-
desc: 'unreadCount: > 0, if channelUser.readToSegment < channel.messageCount',
|
|
87
|
-
before: {
|
|
88
|
-
...responseSchema,
|
|
89
|
-
channels: [channelRaw2],
|
|
90
|
-
channelUsers: [rawChannelUser2],
|
|
91
|
-
},
|
|
92
|
-
after: {
|
|
93
|
-
...responseSchema,
|
|
94
|
-
channels: [channel2],
|
|
95
|
-
channelUsers: [rawChannelUser2],
|
|
96
|
-
},
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
id: 4,
|
|
100
|
-
desc: 'hasMention: true, unreadCount: > 0, if 4 / 5 ',
|
|
101
|
-
before: {
|
|
102
|
-
...responseSchema,
|
|
103
|
-
channels: [channelRaw2],
|
|
104
|
-
channelUsers: [rawChannelUser2],
|
|
105
|
-
},
|
|
106
|
-
after: {
|
|
107
|
-
...responseSchema,
|
|
108
|
-
channels: [channel2],
|
|
109
|
-
channelUsers: [rawChannelUser2],
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
|
-
];
|
|
113
|
-
|
|
114
|
-
xdescribe('channel/utils/prepareChannelPayload', () => {
|
|
115
|
-
tests.forEach(({ id, desc, before, after }) => {
|
|
116
|
-
test(`${id} - ${desc}`, () => {
|
|
117
|
-
expect(prepareChannelPayload(before)).toEqual(after);
|
|
118
|
-
});
|
|
65
|
+
describe('prepareChannelPayload', () => {
|
|
66
|
+
beforeAll(connectClient);
|
|
67
|
+
afterAll(disconnectClient);
|
|
68
|
+
|
|
69
|
+
beforeEach(enableCache);
|
|
70
|
+
afterEach(disableCache);
|
|
71
|
+
|
|
72
|
+
it('should map channel payload with marker correctly', async () => {
|
|
73
|
+
jest
|
|
74
|
+
.spyOn(getChannelMarkers, 'getChannelMarkers')
|
|
75
|
+
.mockResolvedValueOnce(resolvedChannelMarkers);
|
|
76
|
+
|
|
77
|
+
const { channels: received } = await prepareChannelPayload(channelPayload);
|
|
78
|
+
|
|
79
|
+
expect(received).toEqual(convertedChannelPayload.channels);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('should map channel payload with marker cache correctly', async () => {
|
|
83
|
+
pushToCache(['channelMarker', 'get', channelMarker1.entityId], channelMarker1);
|
|
84
|
+
pushToCache(['channelMarker', 'get', channelMarker2.entityId], channelMarker2);
|
|
85
|
+
|
|
86
|
+
const { channels: received } = await prepareChannelPayload(channelPayload);
|
|
87
|
+
|
|
88
|
+
expect(received).toEqual(convertedChannelPayload.channels);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('should map channel payload with `unreadCount: 0` on unable to fetch marker', async () => {
|
|
92
|
+
const { channels: received } = await prepareChannelPayload(channelPayload);
|
|
93
|
+
|
|
94
|
+
const expected = convertedChannelPayload.channels.map(c => ({ ...c, unreadCount: 0 }));
|
|
95
|
+
|
|
96
|
+
expect(received).toEqual(expected);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it(`should filter channels by ${MARKER_INCLUDED_CHANNEL_TYPE.join(', ')} type(s)`, async () => {
|
|
100
|
+
const mock = jest
|
|
101
|
+
.spyOn(getChannelMarkers, 'getChannelMarkers')
|
|
102
|
+
.mockResolvedValueOnce(resolvedChannelMarkers);
|
|
103
|
+
|
|
104
|
+
await prepareChannelPayload(channelPayload);
|
|
105
|
+
|
|
106
|
+
const expected = channelPayload.channels.filter(isUnreadCountSupport).map(c => c.channelId);
|
|
107
|
+
|
|
108
|
+
expect(mock).toHaveBeenCalledWith(expected);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('should not throw an error on `getChannelMarkers` failed', async () => {
|
|
112
|
+
jest
|
|
113
|
+
.spyOn(getChannelMarkers, 'getChannelMarkers')
|
|
114
|
+
.mockRejectedValueOnce(new ASCApiError('error', 500, Amity.ErrorLevel.ERROR));
|
|
115
|
+
|
|
116
|
+
await expect(prepareChannelPayload(channelPayload)).resolves.not.toThrow();
|
|
119
117
|
});
|
|
120
118
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ASCError } from '~/core/errors';
|
|
2
2
|
|
|
3
|
-
let activeUser:
|
|
3
|
+
let activeUser: Amity.ActiveUser | null = null;
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* for internal use
|
|
@@ -17,7 +17,7 @@ export const getActiveUser = () => {
|
|
|
17
17
|
return activeUser!;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
export const setActiveUser = (user: Amity.
|
|
20
|
+
export const setActiveUser = (user: Amity.ActiveUser) => {
|
|
21
21
|
activeUser = {
|
|
22
22
|
_id: user._id,
|
|
23
23
|
userId: user.userId,
|