@amityco/ts-sdk-react-native 6.20.1 → 6.21.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 +12 -7
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/model.d.ts +3 -3
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +2 -2
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/channel.d.ts +3 -0
- package/dist/@types/domains/channel.d.ts.map +1 -1
- package/dist/@types/domains/reaction.d.ts +8 -4
- package/dist/@types/domains/reaction.d.ts.map +1 -1
- package/dist/channelRepository/api/getChannel.d.ts +2 -2
- package/dist/channelRepository/api/getChannel.d.ts.map +1 -1
- package/dist/channelRepository/api/getChannelByIds.d.ts +2 -2
- package/dist/channelRepository/api/getChannelByIds.d.ts.map +1 -1
- package/dist/channelRepository/events/onChannelResolved.d.ts +12 -0
- package/dist/channelRepository/events/onChannelResolved.d.ts.map +1 -0
- package/dist/channelRepository/observers/getChannel.d.ts.map +1 -1
- package/dist/channelRepository/observers/getChannels/ChannelLiveCollectionController.d.ts.map +1 -1
- package/dist/channelRepository/observers/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/getSubChannelsUnreadCount.d.ts.map +1 -1
- package/dist/channelRepository/utils/prepateUnreadCountInfo.d.ts.map +1 -1
- package/dist/channelRepository/utils/resolveChannels.d.ts +2 -0
- package/dist/channelRepository/utils/resolveChannels.d.ts.map +1 -0
- package/dist/client/api/login.d.ts.map +1 -1
- package/dist/client/utils/ObjectResolver/objectResolverEngine.d.ts.map +1 -1
- package/dist/client/utils/onOffline.d.ts.map +1 -1
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.d.ts.map +1 -1
- package/dist/index.cjs.js +199 -155
- package/dist/index.esm.js +199 -155
- package/dist/index.umd.js +2 -2
- package/dist/marker/events/onUserMessageFeedMarkerResolved.d.ts +12 -0
- package/dist/marker/events/onUserMessageFeedMarkerResolved.d.ts.map +1 -0
- package/dist/marker/utils/resolveUserMessageFeedMakers.d.ts +2 -0
- package/dist/marker/utils/resolveUserMessageFeedMakers.d.ts.map +1 -0
- package/dist/messageRepository/utils/prepareMessagePayload.d.ts +1 -1
- package/dist/messageRepository/utils/prepareMessagePayload.d.ts.map +1 -1
- package/dist/reactionRepository/api/addReaction.d.ts +2 -2
- package/dist/reactionRepository/api/addReaction.d.ts.map +1 -1
- package/dist/reactionRepository/api/queryReactor.d.ts +3 -3
- package/dist/reactionRepository/api/queryReactor.d.ts.map +1 -1
- package/dist/reactionRepository/api/removeReaction.d.ts +2 -2
- package/dist/reactionRepository/api/removeReaction.d.ts.map +1 -1
- package/dist/reactionRepository/events/onReactorAdded.d.ts +2 -2
- package/dist/reactionRepository/events/onReactorAdded.d.ts.map +1 -1
- package/dist/reactionRepository/events/onReactorRemoved.d.ts +2 -2
- package/dist/reactionRepository/events/onReactorRemoved.d.ts.map +1 -1
- package/dist/reactionRepository/observers/getReactions.d.ts +1 -1
- package/dist/reactionRepository/observers/getReactions.d.ts.map +1 -1
- package/dist/reactionRepository/utils/prepareMessagePayloadForCache.d.ts +1 -1
- package/dist/reactionRepository/utils/prepareMessagePayloadForCache.d.ts.map +1 -1
- package/dist/streamRepository/events/onStreamStopped.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/reactorLinkedObject.d.ts +2 -0
- package/dist/utils/linkedObject/reactorLinkedObject.d.ts.map +1 -0
- package/dist/utils/tests/dummy/reaction.d.ts +1 -1
- package/dist/utils/tests/dummy/reaction.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/core/events.ts +13 -7
- package/src/@types/core/model.ts +3 -3
- package/src/@types/core/payload.ts +2 -2
- package/src/@types/domains/channel.ts +3 -0
- package/src/@types/domains/reaction.ts +10 -4
- package/src/analytic/api/queryReachUser.ts +1 -1
- package/src/channelRepository/api/getChannel.ts +11 -7
- package/src/channelRepository/api/getChannelByIds.ts +13 -7
- package/src/channelRepository/events/onChannelResolved.ts +22 -0
- package/src/channelRepository/observers/getChannel.ts +2 -0
- package/src/channelRepository/observers/getChannels/ChannelLiveCollectionController.ts +14 -10
- package/src/channelRepository/observers/getChannels/ChannelQueryStreamController.ts +4 -5
- package/src/channelRepository/utils/getChannelIsMentioned.ts +2 -2
- package/src/channelRepository/utils/getSubChannelsUnreadCount.ts +3 -2
- package/src/channelRepository/utils/prepareChannelPayload.ts +2 -2
- package/src/channelRepository/utils/prepateUnreadCountInfo.ts +2 -1
- package/src/channelRepository/utils/resolveChannels.ts +8 -0
- package/src/client/api/login.ts +1 -3
- package/src/client/utils/ObjectResolver/objectResolverEngine.ts +5 -4
- package/src/client/utils/hasPermission/checkUserPermission.ts +1 -1
- package/src/client/utils/onOffline.ts +17 -0
- package/src/commentRepository/events/onCommentReactionAdded.ts +1 -1
- package/src/commentRepository/events/onCommentReactionRemoved.ts +1 -1
- package/src/commentRepository/observers/tests/getComment.test.ts +2 -2
- package/src/core/events.ts +4 -0
- package/src/core/model/idResolvers.ts +1 -1
- package/src/core/query/filtering.ts +1 -1
- package/src/marker/events/onUserMessageFeedMarkerResolved.ts +29 -0
- package/src/marker/utils/resolveUserMessageFeedMakers.ts +17 -0
- package/src/messageRepository/utils/prepareMessagePayload.ts +2 -2
- package/src/postRepository/observers/tests/getPost.test.ts +1 -1
- package/src/postRepository/observers/tests/getPosts.test.ts +1 -1
- package/src/reactionRepository/api/addReaction.ts +2 -2
- package/src/reactionRepository/api/queryReactor.ts +3 -3
- package/src/reactionRepository/api/removeReaction.ts +2 -2
- package/src/reactionRepository/events/onReactorAdded.ts +5 -5
- package/src/reactionRepository/events/onReactorRemoved.ts +5 -5
- package/src/reactionRepository/observers/getReactions.ts +18 -16
- package/src/reactionRepository/utils/prepareMessagePayloadForCache.ts +1 -1
- package/src/streamRepository/events/onStreamRecorded.ts +1 -1
- package/src/streamRepository/events/onStreamStarted.ts +1 -1
- package/src/streamRepository/events/onStreamStopped.ts +6 -1
- package/src/utils/linkedObject/index.ts +2 -0
- package/src/utils/linkedObject/reactorLinkedObject.ts +13 -0
- package/src/utils/tests/dummy/reaction.ts +1 -1
|
@@ -76,15 +76,14 @@ export class ChannelQueryStreamController extends QueryStreamController<
|
|
|
76
76
|
[
|
|
77
77
|
Amity.ChannelActionType.OnCreate,
|
|
78
78
|
Amity.ChannelActionType.OnJoin,
|
|
79
|
-
Amity.ChannelActionType.
|
|
80
|
-
Amity.ChannelActionType.OnUserMessageFeedMarkerFetch,
|
|
79
|
+
Amity.ChannelActionType.OnResolve,
|
|
81
80
|
].includes(action)
|
|
82
81
|
) {
|
|
83
|
-
if (Array.isArray(payload))
|
|
82
|
+
if (Array.isArray(payload)) {
|
|
84
83
|
collection.data = [
|
|
85
|
-
...new Set([...payload.map((
|
|
84
|
+
...new Set([...payload.map(getResolver('channel')), ...collection.data]),
|
|
86
85
|
];
|
|
87
|
-
else collection.data = [...new Set([payload.
|
|
86
|
+
} else collection.data = [...new Set([payload.channelInternalId, ...collection.data])];
|
|
88
87
|
}
|
|
89
88
|
|
|
90
89
|
pushToCache(this.cacheKey, collection);
|
|
@@ -33,10 +33,10 @@ export const getChannelIsMentioned = (channel: Amity.RawChannel, marker?: Amity.
|
|
|
33
33
|
const client = getActiveClient();
|
|
34
34
|
|
|
35
35
|
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
36
|
-
return getUnreadInfoCached(channel.
|
|
36
|
+
return getUnreadInfoCached(channel.channelPublicId)?.isMentioned ?? false;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
return marker?.hasMentioned !== undefined
|
|
40
40
|
? marker?.hasMentioned
|
|
41
|
-
: getCachedMarker(channel.
|
|
41
|
+
: getCachedMarker(channel.channelPublicId)?.hasMentioned ?? false;
|
|
42
42
|
};
|
|
@@ -36,7 +36,8 @@ export const getSubChannelsUnreadCount = (
|
|
|
36
36
|
const client = getActiveClient();
|
|
37
37
|
|
|
38
38
|
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
39
|
-
|
|
39
|
+
// Marker service API uses channelInternalId as channelId
|
|
40
|
+
return getUnreadInfoCached(channel.channelInternalId)?.unreadCount ?? 0;
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
if (marker?.isDeleted) {
|
|
@@ -46,5 +47,5 @@ export const getSubChannelsUnreadCount = (
|
|
|
46
47
|
return 0;
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
return marker?.unreadCount ?? getCachedMarker(channel.
|
|
50
|
+
return marker?.unreadCount ?? getCachedMarker(channel.channelInternalId)?.unreadCount ?? 0;
|
|
50
51
|
};
|
|
@@ -44,7 +44,7 @@ export function convertFromRaw(
|
|
|
44
44
|
return getSubChannelsUnreadCount(channel);
|
|
45
45
|
},
|
|
46
46
|
...channel,
|
|
47
|
-
defaultSubChannelId: channel.
|
|
47
|
+
defaultSubChannelId: channel.channelInternalId,
|
|
48
48
|
isUnreadCountSupport: isUnreadCountSupport(channel),
|
|
49
49
|
messagePreviewId,
|
|
50
50
|
};
|
|
@@ -80,7 +80,7 @@ export const prepareChannelPayload = async (
|
|
|
80
80
|
const markerIds = rawPayload.channels
|
|
81
81
|
// filter channel by type. Only conversation, community and broadcast type are included.
|
|
82
82
|
.filter(isUnreadCountSupport)
|
|
83
|
-
.map(({
|
|
83
|
+
.map(({ channelInternalId }) => channelInternalId);
|
|
84
84
|
|
|
85
85
|
if (markerIds.length > 0) {
|
|
86
86
|
// since the get markers method requires a channel cache to function with the reducer.
|
|
@@ -6,8 +6,9 @@ export const prepareUnreadCountInfo = async (rawPayload: Amity.ChannelPayload) =
|
|
|
6
6
|
const client = getActiveClient();
|
|
7
7
|
// if consistent mode is enabled, persist the unread count info to the cache
|
|
8
8
|
|
|
9
|
+
// Marker service API uses channelInternalId as channelId
|
|
9
10
|
const queryPayload = await getUserMessageFeedMakers(
|
|
10
|
-
rawPayload.channels.map(({
|
|
11
|
+
rawPayload.channels.map(({ channelInternalId }) => channelInternalId),
|
|
11
12
|
);
|
|
12
13
|
|
|
13
14
|
const { feedMarkers, userFeedMarkers } = queryPayload;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { getChannelByIds } from '../api/getChannelByIds';
|
|
2
|
+
import { fireEvent } from '~/core/events';
|
|
3
|
+
|
|
4
|
+
export const resolveChannels = async (channelIds: Amity.InternalChannel['channelPublicId'][]) => {
|
|
5
|
+
const { data: channels } = await getChannelByIds(channelIds);
|
|
6
|
+
|
|
7
|
+
fireEvent('local.channel.resolved', channels);
|
|
8
|
+
};
|
package/src/client/api/login.ts
CHANGED
|
@@ -121,9 +121,7 @@ export const login = async (
|
|
|
121
121
|
// wire websocket events to our event emitter
|
|
122
122
|
proxyWebsocketEvents(client.ws, client.emitter);
|
|
123
123
|
|
|
124
|
-
client.ws.
|
|
125
|
-
client.ws.open();
|
|
126
|
-
});
|
|
124
|
+
client.ws.open();
|
|
127
125
|
|
|
128
126
|
client.userId = user.userId;
|
|
129
127
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { onOnline } from '../onOnline';
|
|
2
|
-
import { getChannelByIds } from '~/channelRepository/api/getChannelByIds';
|
|
3
2
|
|
|
4
3
|
import { onOffline } from '../onOffline';
|
|
5
|
-
import { getUserMessageFeedMakers } from '~/marker/api/getUserMessageFeedMarkers';
|
|
6
4
|
import { SECOND } from '~/utils/constants';
|
|
5
|
+
import { resolveChannels } from '~/channelRepository/utils/resolveChannels';
|
|
6
|
+
import { resolveUserMessageFeedMarkers } from '~/marker/utils/resolveUserMessageFeedMakers';
|
|
7
7
|
|
|
8
8
|
class ObjectResolverEngine {
|
|
9
9
|
private readonly TIMER_INTERVAL_MS = SECOND;
|
|
@@ -90,8 +90,9 @@ class ObjectResolverEngine {
|
|
|
90
90
|
// Send Requests.
|
|
91
91
|
// Incase of failure: Ignore
|
|
92
92
|
// Incase of success: Persist in Domain DB & Notify Live collection
|
|
93
|
-
if (channelIds.length > 0)
|
|
94
|
-
if (userMessageFeedMarkerIds.length > 0)
|
|
93
|
+
if (channelIds.length > 0) resolveChannels(channelIds);
|
|
94
|
+
if (userMessageFeedMarkerIds.length > 0)
|
|
95
|
+
resolveUserMessageFeedMarkers(userMessageFeedMarkerIds);
|
|
95
96
|
|
|
96
97
|
// After sending request
|
|
97
98
|
this.isResolvingTask = false;
|
|
@@ -4,7 +4,7 @@ export const checkUserPermission = (
|
|
|
4
4
|
userId: Amity.User['userId'] | undefined,
|
|
5
5
|
permission: string,
|
|
6
6
|
) => {
|
|
7
|
-
const user = pullFromCache<Amity.User>(['
|
|
7
|
+
const user = pullFromCache<Amity.User>(['user', 'get', userId])?.data;
|
|
8
8
|
|
|
9
9
|
if (!user) return false;
|
|
10
10
|
|
|
@@ -9,6 +9,23 @@ export const onOffline = (callback: () => void) => {
|
|
|
9
9
|
return () => document.removeEventListener('offline', callback);
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
// @TODO: Please update code below to follow our coding conventions and our TS rules
|
|
13
|
+
if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
15
|
+
let unsubscribeFn = () => {};
|
|
16
|
+
|
|
17
|
+
import('@react-native-community/netinfo').then(NetInfo => {
|
|
18
|
+
unsubscribeFn = NetInfo.addEventListener(state => {
|
|
19
|
+
if (state.isConnected) return;
|
|
20
|
+
callback();
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
return () => {
|
|
25
|
+
unsubscribeFn();
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
12
29
|
// Handle unsupported environment
|
|
13
30
|
console.error('Unsupported environment');
|
|
14
31
|
return () => console.error('Unsupported environment');
|
|
@@ -25,7 +25,7 @@ export const onCommentReactionAdded = (
|
|
|
25
25
|
): Amity.Unsubscriber => {
|
|
26
26
|
const client = getActiveClient();
|
|
27
27
|
|
|
28
|
-
const filter = (payload: Amity.CommentPayload & { reactor: Amity.
|
|
28
|
+
const filter = (payload: Amity.CommentPayload & { reactor: Amity.InternalReactor }) => {
|
|
29
29
|
if (!client.cache) {
|
|
30
30
|
callback(LinkedObject.comment(payload.comments[0]));
|
|
31
31
|
} else {
|
|
@@ -25,7 +25,7 @@ export const onCommentReactionRemoved = (
|
|
|
25
25
|
): Amity.Unsubscriber => {
|
|
26
26
|
const client = getActiveClient();
|
|
27
27
|
|
|
28
|
-
const filter = (payload: Amity.CommentPayload & { reactor: Amity.
|
|
28
|
+
const filter = (payload: Amity.CommentPayload & { reactor: Amity.InternalReactor }) => {
|
|
29
29
|
if (!client.cache) {
|
|
30
30
|
callback(LinkedObject.comment(payload.comments[0]));
|
|
31
31
|
} else {
|
|
@@ -12,8 +12,8 @@ import {
|
|
|
12
12
|
} from '~/utils/tests';
|
|
13
13
|
import { getFutureDate } from '~/core/model';
|
|
14
14
|
|
|
15
|
-
import { getComment } from '../getComment';
|
|
16
15
|
import { LinkedObject } from '~/utils/linkedObject';
|
|
16
|
+
import { getComment } from '../getComment';
|
|
17
17
|
|
|
18
18
|
describe('getComment', () => {
|
|
19
19
|
const response = {
|
|
@@ -81,7 +81,7 @@ describe('getComment', () => {
|
|
|
81
81
|
data: { text: 'new-text' },
|
|
82
82
|
});
|
|
83
83
|
|
|
84
|
-
const reactor: Amity.
|
|
84
|
+
const reactor: Amity.InternalReactor = {
|
|
85
85
|
createdAt: getFutureDate(update.updatedAt),
|
|
86
86
|
reactionId: 'like',
|
|
87
87
|
reactionName: 'like',
|
package/src/core/events.ts
CHANGED
|
@@ -15,6 +15,10 @@ const WS_EVENTS = [
|
|
|
15
15
|
'sessionStateChange',
|
|
16
16
|
// for internal use by accessTokenExpiryWatcher
|
|
17
17
|
'tokenExpired',
|
|
18
|
+
|
|
19
|
+
'v3.video-streaming.didRecord',
|
|
20
|
+
'v3.video-streaming.didStart',
|
|
21
|
+
'v3.video-streaming.didStop',
|
|
18
22
|
] as const;
|
|
19
23
|
|
|
20
24
|
const MQTT_EVENTS = [
|
|
@@ -15,7 +15,7 @@ const idResolvers: Resolvers = {
|
|
|
15
15
|
file: ({ fileId }) => fileId,
|
|
16
16
|
role: ({ roleId }) => roleId,
|
|
17
17
|
|
|
18
|
-
channel: ({
|
|
18
|
+
channel: ({ channelInternalId }) => channelInternalId,
|
|
19
19
|
subChannel: ({ subChannelId }) => subChannelId,
|
|
20
20
|
channelUsers: ({ channelId, userId }) => `${channelId}#${userId}`,
|
|
21
21
|
message: ({ messageId }) => messageId,
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api/activeClient';
|
|
2
|
+
import { createEventSubscriber } from '~/core/events';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Internal used only
|
|
6
|
+
*
|
|
7
|
+
* Fired when an {@link Amity.userMessageFeedMarkers} has been resolved by Object Rsesolver
|
|
8
|
+
*
|
|
9
|
+
* @param callback The function to call when the event was fired
|
|
10
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
11
|
+
*
|
|
12
|
+
* @category MessageMarker Events
|
|
13
|
+
*/
|
|
14
|
+
export const onUserMessageFeedMarkerResolved = (
|
|
15
|
+
callback: Amity.Listener<Amity.Events['local.userMessageFeedMarkers.resolved']>,
|
|
16
|
+
): Amity.Unsubscriber => {
|
|
17
|
+
const client = getActiveClient();
|
|
18
|
+
|
|
19
|
+
const filter = (payload: Amity.Events['local.userMessageFeedMarkers.resolved']) => {
|
|
20
|
+
callback(payload);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
return createEventSubscriber(
|
|
24
|
+
client,
|
|
25
|
+
'userMessageFeedMarker/onUserMessageFeedMarkerResolved',
|
|
26
|
+
'local.userMessageFeedMarkers.resolved',
|
|
27
|
+
filter,
|
|
28
|
+
);
|
|
29
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { getUserMessageFeedMakers } from '../api/getUserMessageFeedMarkers';
|
|
2
|
+
import { fireEvent } from '~/core/events';
|
|
3
|
+
import { persistUnreadCountInfo } from './persistUnreadCountInfo';
|
|
4
|
+
|
|
5
|
+
export const resolveUserMessageFeedMarkers = async (
|
|
6
|
+
channelIds: Amity.InternalChannel['channelInternalId'][],
|
|
7
|
+
) => {
|
|
8
|
+
const queryPayload = await getUserMessageFeedMakers(channelIds);
|
|
9
|
+
|
|
10
|
+
const { feedMarkers, userFeedMarkers } = queryPayload;
|
|
11
|
+
persistUnreadCountInfo({
|
|
12
|
+
feedMarkers,
|
|
13
|
+
userFeedMarkers,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
fireEvent('local.userMessageFeedMarkers.resolved', { feedMarkers, userFeedMarkers });
|
|
17
|
+
};
|
|
@@ -4,15 +4,15 @@ import { getMessageMarkers } from '~/marker/api/getMessageMarkers';
|
|
|
4
4
|
import { prepareMessagePayloadForCache } from '~/reactionRepository/utils/prepareMessagePayloadForCache';
|
|
5
5
|
import { inferIsDeleted } from '~/utils/inferIsDeleted';
|
|
6
6
|
|
|
7
|
-
import { getMessageReadCount } from './getMessageReadCount';
|
|
8
7
|
import { MessageContentType } from '~/@types';
|
|
9
8
|
import { convertFromRaw as convertSubChannelFromRaw } from '~/subChannelRepository/utils/convertSubChannelFromRaw';
|
|
10
9
|
import { updateSubChannelCache } from '~/subChannelRepository/utils/updateSubChannelCache';
|
|
11
10
|
import { COLLECTION_DEFAULT_PAGINATION_LIMIT } from '~/utils/constants';
|
|
11
|
+
import { getMessageReadCount } from './getMessageReadCount';
|
|
12
12
|
|
|
13
13
|
export function convertFromRaw(
|
|
14
14
|
message: Amity.RawMessage,
|
|
15
|
-
reactors?: Amity.
|
|
15
|
+
reactors?: Amity.InternalReactor[],
|
|
16
16
|
event?: keyof Amity.MqttMessageEvents,
|
|
17
17
|
): Amity.InternalMessage {
|
|
18
18
|
const {
|
|
@@ -76,7 +76,7 @@ describe('getPost', () => {
|
|
|
76
76
|
data: { text: 'new-text' },
|
|
77
77
|
updatedAt: getFutureDate(post.updatedAt),
|
|
78
78
|
};
|
|
79
|
-
const reactor: Amity.
|
|
79
|
+
const reactor: Amity.InternalReactor = {
|
|
80
80
|
createdAt: getFutureDate(post.updatedAt),
|
|
81
81
|
reactionId: 'like',
|
|
82
82
|
reactionName: 'like',
|
|
@@ -214,7 +214,7 @@ describe('getPosts', () => {
|
|
|
214
214
|
const reactionEvents: [
|
|
215
215
|
string,
|
|
216
216
|
keyof Amity.Events,
|
|
217
|
-
Amity.PostPayload & { reactor: Amity.
|
|
217
|
+
Amity.PostPayload & { reactor: Amity.InternalReactor },
|
|
218
218
|
][] = [
|
|
219
219
|
[
|
|
220
220
|
'it should update post in collection onReactionAdded',
|
|
@@ -27,7 +27,7 @@ import { dispatchReactable } from '../utils';
|
|
|
27
27
|
export const addReaction = async (
|
|
28
28
|
referenceType: Amity.Reaction['referenceType'],
|
|
29
29
|
referenceId: Amity.Reaction['referenceId'],
|
|
30
|
-
reactionName: Amity.
|
|
30
|
+
reactionName: Amity.InternalReactor['reactionName'],
|
|
31
31
|
): Promise<boolean> => {
|
|
32
32
|
const client = getActiveClient();
|
|
33
33
|
client.log('reaction/createReaction', {
|
|
@@ -76,7 +76,7 @@ export const addReaction = async (
|
|
|
76
76
|
addReaction.optimistically = (
|
|
77
77
|
referenceType: Amity.ReactableType,
|
|
78
78
|
referenceId: Amity.Reaction['referenceId'],
|
|
79
|
-
reactionName: Amity.
|
|
79
|
+
reactionName: Amity.InternalReactor['reactionName'],
|
|
80
80
|
): boolean | undefined => {
|
|
81
81
|
const client = getActiveClient();
|
|
82
82
|
client.log('reaction/createReaction.optimistically', {
|
|
@@ -11,17 +11,17 @@ import { queryReactions } from './queryReactions';
|
|
|
11
11
|
* })
|
|
12
12
|
* ```
|
|
13
13
|
*
|
|
14
|
-
* Queries a paginable list of {@link Amity.
|
|
14
|
+
* Queries a paginable list of {@link Amity.InternalReactor} objects
|
|
15
15
|
*
|
|
16
16
|
* @param query The query parameters
|
|
17
|
-
* @returns A page of {@link Amity.
|
|
17
|
+
* @returns A page of {@link Amity.InternalReactor} objects
|
|
18
18
|
*
|
|
19
19
|
* @reaction Reaction API
|
|
20
20
|
* @async
|
|
21
21
|
* */
|
|
22
22
|
export const queryReactor = async (
|
|
23
23
|
query: Amity.QueryReactions,
|
|
24
|
-
): Promise<Amity.Paged<Amity.
|
|
24
|
+
): Promise<Amity.Paged<Amity.InternalReactor, Amity.Page<string>>> => {
|
|
25
25
|
const client = getActiveClient();
|
|
26
26
|
client.log('reaction/queryReactor', query);
|
|
27
27
|
|
|
@@ -28,7 +28,7 @@ import { dispatchReactable } from '../utils';
|
|
|
28
28
|
export const removeReaction = async (
|
|
29
29
|
referenceType: Amity.Reaction['referenceType'],
|
|
30
30
|
referenceId: Amity.Reaction['referenceId'],
|
|
31
|
-
reactionName: Amity.
|
|
31
|
+
reactionName: Amity.InternalReactor['reactionName'],
|
|
32
32
|
): Promise<boolean> => {
|
|
33
33
|
const client = getActiveClient();
|
|
34
34
|
client.log('reaction/removeReaction', {
|
|
@@ -79,7 +79,7 @@ export const removeReaction = async (
|
|
|
79
79
|
removeReaction.optimistically = (
|
|
80
80
|
referenceType: Amity.ReactableType,
|
|
81
81
|
referenceId: Amity.Reaction['referenceId'],
|
|
82
|
-
reactionName: Amity.
|
|
82
|
+
reactionName: Amity.InternalReactor['reactionName'],
|
|
83
83
|
): boolean | undefined => {
|
|
84
84
|
const client = getActiveClient();
|
|
85
85
|
client.log('reaction/removeReaction.optimistically', {
|
|
@@ -11,7 +11,7 @@ import { prepareMessagePayload } from '~/messageRepository/utils';
|
|
|
11
11
|
* })
|
|
12
12
|
* ```
|
|
13
13
|
*
|
|
14
|
-
* Fired when an {@link Amity.
|
|
14
|
+
* Fired when an {@link Amity.InternalReactor} has been added
|
|
15
15
|
*
|
|
16
16
|
* @param {@link Amity.ReactableType} referenceType
|
|
17
17
|
* @param {string} referenceId
|
|
@@ -23,14 +23,14 @@ import { prepareMessagePayload } from '~/messageRepository/utils';
|
|
|
23
23
|
export const onReactorAdded = (
|
|
24
24
|
referenceType: Amity.ReactableType,
|
|
25
25
|
referenceId: Amity.Reaction['referenceId'],
|
|
26
|
-
callback: Amity.Listener<Amity.
|
|
26
|
+
callback: Amity.Listener<Amity.InternalReactor>,
|
|
27
27
|
): Amity.Unsubscriber => {
|
|
28
28
|
const client = getActiveClient();
|
|
29
29
|
|
|
30
30
|
const callbackWrapper = (
|
|
31
31
|
referenceType_: Amity.ReactableType,
|
|
32
32
|
referenceId_: Amity.Reaction['referenceId'],
|
|
33
|
-
reaction: Amity.
|
|
33
|
+
reaction: Amity.InternalReactor,
|
|
34
34
|
) => {
|
|
35
35
|
if (referenceType_ === referenceType && referenceId_ === referenceId) {
|
|
36
36
|
callback(reaction);
|
|
@@ -51,7 +51,7 @@ export const onReactorAdded = (
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
if (referenceType === 'post') {
|
|
54
|
-
const filter = (payload: Amity.PostPayload & { reactor: Amity.
|
|
54
|
+
const filter = (payload: Amity.PostPayload & { reactor: Amity.InternalReactor }) => {
|
|
55
55
|
const { reactor, ...rest } = payload;
|
|
56
56
|
|
|
57
57
|
ingestInCache(rest as Amity.ProcessedPostPayload);
|
|
@@ -76,7 +76,7 @@ export const onReactorAdded = (
|
|
|
76
76
|
return createEventSubscriber(client, 'story.reactionAdded', 'story.reactionAdded', filter);
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
const filter = (payload: Amity.CommentPayload & { reactor: Amity.
|
|
79
|
+
const filter = (payload: Amity.CommentPayload & { reactor: Amity.InternalReactor }) => {
|
|
80
80
|
const { reactor, ...rest } = payload;
|
|
81
81
|
|
|
82
82
|
ingestInCache(rest as Amity.CommentPayload);
|
|
@@ -11,7 +11,7 @@ import { prepareMessagePayload } from '~/messageRepository/utils';
|
|
|
11
11
|
* })
|
|
12
12
|
* ```
|
|
13
13
|
*
|
|
14
|
-
* Fired when an {@link Amity.
|
|
14
|
+
* Fired when an {@link Amity.InternalReactor} has been removed
|
|
15
15
|
*
|
|
16
16
|
* @param {@link Amity.ReactableType} referenceType
|
|
17
17
|
* @param {string} referenceId
|
|
@@ -23,14 +23,14 @@ import { prepareMessagePayload } from '~/messageRepository/utils';
|
|
|
23
23
|
export const onReactorRemoved = (
|
|
24
24
|
referenceType: Amity.ReactableType,
|
|
25
25
|
referenceId: Amity.Reaction['referenceId'],
|
|
26
|
-
callback: Amity.Listener<Amity.
|
|
26
|
+
callback: Amity.Listener<Amity.InternalReactor>,
|
|
27
27
|
): Amity.Unsubscriber => {
|
|
28
28
|
const client = getActiveClient();
|
|
29
29
|
|
|
30
30
|
const callbackWrapper = (
|
|
31
31
|
referenceType_: Amity.ReactableType,
|
|
32
32
|
referenceId_: Amity.Reaction['referenceId'],
|
|
33
|
-
reaction: Amity.
|
|
33
|
+
reaction: Amity.InternalReactor,
|
|
34
34
|
) => {
|
|
35
35
|
if (referenceType_ === referenceType && referenceId_ === referenceId) {
|
|
36
36
|
callback(reaction);
|
|
@@ -51,7 +51,7 @@ export const onReactorRemoved = (
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
if (referenceType === 'post') {
|
|
54
|
-
const filter = (payload: Amity.PostPayload & { reactor: Amity.
|
|
54
|
+
const filter = (payload: Amity.PostPayload & { reactor: Amity.InternalReactor }) => {
|
|
55
55
|
const { reactor, ...rest } = payload;
|
|
56
56
|
|
|
57
57
|
ingestInCache(rest as Amity.ProcessedPostPayload);
|
|
@@ -78,7 +78,7 @@ export const onReactorRemoved = (
|
|
|
78
78
|
return createEventSubscriber(client, 'story.reactionRemoved', 'story.reactionRemoved', filter);
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
const filter = (payload: Amity.CommentPayload & { reactor: Amity.
|
|
81
|
+
const filter = (payload: Amity.CommentPayload & { reactor: Amity.InternalReactor }) => {
|
|
82
82
|
const { reactor, ...rest } = payload;
|
|
83
83
|
|
|
84
84
|
ingestInCache(rest as Amity.CommentPayload);
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
/* eslint-disable no-use-before-define */
|
|
2
2
|
import { getResolver } from '~/core/model';
|
|
3
3
|
import { getActiveClient } from '~/client/api';
|
|
4
|
-
import {
|
|
5
|
-
import { createQuery,
|
|
4
|
+
import { pullFromCache, pushToCache } from '~/cache/api';
|
|
5
|
+
import { createQuery, queryOptions, runQuery } from '~/core/query';
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
8
|
COLLECTION_DEFAULT_CACHING_POLICY,
|
|
9
9
|
COLLECTION_DEFAULT_PAGINATION_LIMIT,
|
|
10
10
|
} from '~/utils/constants';
|
|
11
11
|
|
|
12
|
+
import { LinkedObject } from '~/utils/linkedObject';
|
|
12
13
|
import { onReactorAdded, onReactorRemoved } from '../events';
|
|
13
14
|
import { queryReactor } from '../api/queryReactor';
|
|
14
15
|
|
|
@@ -26,7 +27,7 @@ import { queryReactor } from '../api/queryReactor';
|
|
|
26
27
|
* }, response => merge(reactions, response.data))
|
|
27
28
|
* ```
|
|
28
29
|
*
|
|
29
|
-
* Observe all mutations on a list of {@link Amity.
|
|
30
|
+
* Observe all mutations on a list of {@link Amity.InternalReactor} for a given target object
|
|
30
31
|
*
|
|
31
32
|
* @param params for querying reactions
|
|
32
33
|
* @param callback the function to call when new data are available
|
|
@@ -64,9 +65,9 @@ export const getReactions = (
|
|
|
64
65
|
const responder = (data: Amity.ReactionLiveCollectionCache) => {
|
|
65
66
|
const reactions: Amity.Reactor[] =
|
|
66
67
|
data.data
|
|
67
|
-
.map(reactorId => pullFromCache<Amity.
|
|
68
|
+
.map(reactorId => pullFromCache<Amity.InternalReactor>(['reactor', 'get', reactorId])!)
|
|
68
69
|
.filter(Boolean)
|
|
69
|
-
.map(({ data }) => data) ?? [];
|
|
70
|
+
.map(({ data }) => LinkedObject.reactor(data)) ?? [];
|
|
70
71
|
|
|
71
72
|
callback({
|
|
72
73
|
onNextPage: onFetch,
|
|
@@ -77,19 +78,20 @@ export const getReactions = (
|
|
|
77
78
|
});
|
|
78
79
|
};
|
|
79
80
|
|
|
80
|
-
const realtimeRouter =
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
const realtimeRouter =
|
|
82
|
+
(action: Amity.ReactionActionType) => (reaction: Amity.InternalReactor) => {
|
|
83
|
+
const collection = pullFromCache<Amity.ReactionLiveCollectionCache>(cacheKey)?.data;
|
|
84
|
+
if (!collection) return;
|
|
83
85
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
86
|
+
if (action === 'onAdded') {
|
|
87
|
+
collection.data = [...new Set([reaction.reactionId, ...collection.data])];
|
|
88
|
+
} else if (action === 'onRemoved') {
|
|
89
|
+
collection.data = collection.data.filter(p => p !== reaction.reactionId);
|
|
90
|
+
}
|
|
89
91
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
92
|
+
pushToCache(cacheKey, collection);
|
|
93
|
+
responder(collection);
|
|
94
|
+
};
|
|
93
95
|
|
|
94
96
|
const onFetch = (initial = false) => {
|
|
95
97
|
const collection = pullFromCache<Amity.ReactionLiveCollectionCache>(cacheKey)?.data;
|
|
@@ -8,7 +8,7 @@ import { getActiveClient } from '~/client/api/activeClient';
|
|
|
8
8
|
*/
|
|
9
9
|
export const prepareMessagePayloadForCache = (
|
|
10
10
|
payload: Amity.InternalMessage,
|
|
11
|
-
reactors: Amity.
|
|
11
|
+
reactors: Amity.InternalReactor[],
|
|
12
12
|
event: Pick<Amity.Events, 'message.reactionAdded' | 'message.reactionRemoved'> | string,
|
|
13
13
|
) => {
|
|
14
14
|
const client = getActiveClient();
|
|
@@ -26,5 +26,10 @@ export const onStreamStopped = (callback: Amity.Listener<Amity.Stream>): Amity.U
|
|
|
26
26
|
callback(payload.videoStreamings[0]);
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
-
return createEventSubscriber(
|
|
29
|
+
return createEventSubscriber(
|
|
30
|
+
client,
|
|
31
|
+
'stream/onStreamStropped',
|
|
32
|
+
'v3.video-streaming.didStop',
|
|
33
|
+
filter,
|
|
34
|
+
);
|
|
30
35
|
};
|
|
@@ -5,6 +5,7 @@ import { userLinkedObject } from './userLinkedObject';
|
|
|
5
5
|
import { postLinkedObject } from './postLinkedObject';
|
|
6
6
|
import { messageLinkedObject } from './messageLinkedObject';
|
|
7
7
|
import { storyTargetLinkedObject } from './storyTargetLinkedObject';
|
|
8
|
+
import { reactorLinkedObject } from './reactorLinkedObject';
|
|
8
9
|
|
|
9
10
|
export const LinkedObject = {
|
|
10
11
|
comment: commentLinkedObject,
|
|
@@ -14,4 +15,5 @@ export const LinkedObject = {
|
|
|
14
15
|
story: storyLinkedObject,
|
|
15
16
|
storyTarget: storyTargetLinkedObject,
|
|
16
17
|
message: messageLinkedObject,
|
|
18
|
+
reactor: reactorLinkedObject,
|
|
17
19
|
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { pullFromCache } from '~/cache/api/pullFromCache';
|
|
2
|
+
import { userLinkedObject } from './userLinkedObject';
|
|
3
|
+
|
|
4
|
+
export const reactorLinkedObject = (reactor: Amity.InternalReactor): Amity.Reactor => {
|
|
5
|
+
return {
|
|
6
|
+
...reactor,
|
|
7
|
+
get user(): Amity.User | undefined {
|
|
8
|
+
const user = pullFromCache<Amity.InternalUser>(['user', 'get', reactor.userId])?.data;
|
|
9
|
+
if (!user) return undefined;
|
|
10
|
+
return userLinkedObject(user);
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
};
|