@amityco/ts-sdk-react-native 6.22.1-600ab29.0 → 6.22.1-b0a1854.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/package.json +3 -1
- package/rollup.config.js +6 -0
- package/src/@types/core/events.ts +8 -0
- package/src/@types/domains/channel.ts +1 -0
- package/src/@types/domains/community.ts +50 -1
- package/src/@types/domains/post.ts +3 -3
- package/src/channelRepository/api/getChannel.ts +1 -1
- package/src/channelRepository/api/getChannelByIds.ts +4 -3
- package/src/channelRepository/api/markAsRead.ts +6 -2
- package/src/channelRepository/channelMembership/observers/getMembers/ChannelMemberLiveCollectionController.ts +2 -2
- package/src/channelRepository/channelMembership/observers/getMembers/ChannelMemberQueryStreamController.ts +5 -2
- package/src/channelRepository/events/onChannelMemberRoleAdded.ts +1 -1
- package/src/channelRepository/events/onChannelMemberRoleRemoved.ts +1 -1
- package/src/channelRepository/observers/getChannel.ts +8 -4
- package/src/channelRepository/observers/getChannels/ChannelLiveCollectionController.ts +10 -8
- package/src/channelRepository/observers/observeChannel.ts +15 -3
- package/src/channelRepository/observers/observeChannels.ts +8 -4
- package/src/client/api/index.ts +3 -0
- package/src/client/api/logout.ts +1 -1
- package/src/client/api/registerPushNotification.ts +37 -0
- package/src/client/api/secureLogout.ts +1 -1
- package/src/client/api/unregisterPushNotification.ts +26 -0
- package/src/client/utils/ReadReceiptSync/readReceiptSyncEngine.ts +6 -3
- package/src/client/utils/markerSyncEngine.ts +4 -1
- package/src/commentRepository/api/createComment.ts +2 -2
- package/src/commentRepository/api/deleteComment.ts +2 -4
- package/src/commentRepository/events/utils.ts +9 -6
- package/src/commentRepository/internalApi/createComment.ts +3 -2
- package/src/commentRepository/internalApi/deleteComment.ts +2 -2
- package/src/communityRepository/api/createCommunity.ts +5 -2
- package/src/communityRepository/api/getCommunities.ts +5 -1
- package/src/communityRepository/api/getCommunity.ts +5 -1
- package/src/communityRepository/api/queryCommunities.ts +2 -2
- package/src/communityRepository/api/updateCommunity.ts +5 -1
- package/src/communityRepository/communityMembership/events/utils.ts +2 -2
- package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersLiveCollectionController.ts +151 -0
- package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersPaginationController.ts +26 -0
- package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.ts +114 -0
- package/src/communityRepository/communityMembership/observers/getMembers/enums.ts +10 -0
- package/src/communityRepository/communityMembership/observers/getMembers.ts +15 -128
- package/src/communityRepository/communityMembership/observers/index.ts +1 -0
- package/src/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersLiveCollectionController.ts +130 -0
- package/src/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersPaginationController.ts +29 -0
- package/src/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersQueryStreamController.ts +105 -0
- package/src/communityRepository/communityMembership/observers/searchMembers/enums.ts +9 -0
- package/src/communityRepository/communityMembership/observers/searchMembers.ts +60 -0
- package/src/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.ts +155 -0
- package/src/communityRepository/observers/getCommunities/CommunitiesPaginationController.ts +31 -0
- package/src/communityRepository/observers/getCommunities/CommunitiesQueryStreamController.ts +89 -0
- package/src/communityRepository/observers/getCommunities/enums.ts +5 -0
- package/src/communityRepository/observers/getCommunities.ts +7 -150
- package/src/communityRepository/observers/index.ts +1 -0
- package/src/communityRepository/observers/searchCommunities/SearchCommunitiesLiveCollectionController.ts +127 -0
- package/src/communityRepository/observers/searchCommunities/SearchCommunitiesPaginationController.ts +31 -0
- package/src/communityRepository/observers/searchCommunities/SearchCommunitiesQueryStreamController.ts +82 -0
- package/src/communityRepository/observers/searchCommunities/enums.ts +5 -0
- package/src/communityRepository/observers/searchCommunities.ts +56 -0
- package/src/communityRepository/utils/payload.ts +35 -1
- package/src/communityRepository/utils/saveCommunityUsers.ts +16 -0
- package/src/core/liveCollection/LiveCollectionController.ts +10 -6
- package/src/fileRepository/api/createFile.ts +5 -2
- package/src/fileRepository/api/createImage.ts +6 -2
- package/src/fileRepository/api/createVideo.ts +5 -2
- package/src/fileRepository/api/uploadFile.ts +5 -2
- package/src/fileRepository/api/uploadImage.ts +5 -2
- package/src/fileRepository/api/uploadVideo.ts +5 -2
- package/src/marker/events/onChannelUnreadUpdatedLocal.ts +29 -0
- package/src/marker/events/onSubChannelMarkerFetched.ts +1 -1
- package/src/marker/events/onSubChannelUnreadUpdatedLocal.ts +29 -0
- package/src/marker/events/onUserFeedMarkerUpdated.ts +3 -4
- package/src/marker/utils/reCalculateChannelUnreadInfo.ts +7 -3
- package/src/messagePreview/utils/getChannelMessagePreviewWithUser.ts +5 -1
- package/src/messageRepository/events/onMessageCreated.ts +4 -0
- package/src/messageRepository/observers/getMessages/MessageLiveCollectionController.ts +3 -3
- package/src/messageRepository/utils/markReadMessage.ts +8 -0
- package/src/postRepository/api/createPost.ts +1 -2
- package/src/postRepository/api/editPost.ts +1 -1
- package/src/postRepository/api/updatePost.ts +1 -1
- package/src/postRepository/observers/getPost.ts +26 -0
- package/src/postRepository/observers/getPosts.ts +31 -0
- package/src/storyRepository/observers/getGlobalStoryTargets/GlobalStoryLiveCollectionController.ts +2 -2
- package/src/storyRepository/observers/getStoriesByTargetIds/StoryLiveCollectionController.ts +1 -1
- package/src/subChannelRepository/observers/getSubChannel.ts +10 -6
- package/src/subChannelRepository/observers/getSubChannels/SubChannelLiveCollectionController.ts +13 -10
- package/src/utils/linkedObject/channelLinkedObject.ts +8 -0
- package/src/utils/linkedObject/index.ts +2 -0
- package/src/utils/linkedObject/messageLinkedObject.ts +2 -7
- package/src/utils/liveObject.ts +3 -0
- package/src/utils/object.ts +15 -0
|
@@ -30,8 +30,11 @@ export const uploadVideo = async (
|
|
|
30
30
|
const client = getActiveClient();
|
|
31
31
|
client.log('file/uploadVideo', formData);
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
const files = formData.getAll('files');
|
|
34
|
+
|
|
35
|
+
if (!files.length) throw new Error('The formData object must have a `files` key.');
|
|
36
|
+
|
|
37
|
+
formData.append('preferredFilename', (files[0] as File).name);
|
|
35
38
|
|
|
36
39
|
if (feedType) {
|
|
37
40
|
formData.append('feedType', feedType);
|
|
@@ -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 onChannelUnreadUpdatedLocal = (
|
|
15
|
+
callback: Amity.Listener<Amity.Events['local.channelUnread.updated']>,
|
|
16
|
+
): Amity.Unsubscriber => {
|
|
17
|
+
const client = getActiveClient();
|
|
18
|
+
|
|
19
|
+
const filter = (payload: Amity.Events['local.channelUnread.updated']) => {
|
|
20
|
+
callback(payload);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
return createEventSubscriber(
|
|
24
|
+
client,
|
|
25
|
+
'channelMarker/onChannelUnreadUpdatedLocal',
|
|
26
|
+
'local.channelUnread.updated',
|
|
27
|
+
filter,
|
|
28
|
+
);
|
|
29
|
+
};
|
|
@@ -22,7 +22,7 @@ export const onSubChannelMarkerFetched = (
|
|
|
22
22
|
const client = getActiveClient();
|
|
23
23
|
|
|
24
24
|
const filter = (payload: Amity.Events['local.subChannelMarker.fetched']) => {
|
|
25
|
-
|
|
25
|
+
payload.userFeedMarkers.forEach(callback);
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
return createEventSubscriber(
|
|
@@ -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 onSubChannelUnreadUpdatedLocal = (
|
|
15
|
+
callback: Amity.Listener<Amity.Events['local.subChannelUnread.updated']>,
|
|
16
|
+
): Amity.Unsubscriber => {
|
|
17
|
+
const client = getActiveClient();
|
|
18
|
+
|
|
19
|
+
const filter = (payload: Amity.Events['local.subChannelUnread.updated']) => {
|
|
20
|
+
callback(payload);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
return createEventSubscriber(
|
|
24
|
+
client,
|
|
25
|
+
'subChannelMarker/onSubChannelUnreadUpdatedLocal',
|
|
26
|
+
'local.subChannelUnread.updated',
|
|
27
|
+
filter,
|
|
28
|
+
);
|
|
29
|
+
};
|
|
@@ -23,10 +23,9 @@ export const onUserFeedMarkerUpdated = (
|
|
|
23
23
|
const client = getActiveClient();
|
|
24
24
|
|
|
25
25
|
const filter = (payload: Amity.Events['marker.userFeed-updated']) => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
callback(payload.feedMarkers[0]);
|
|
26
|
+
payload.feedMarkers.forEach(feedMarker => {
|
|
27
|
+
callback(feedMarker);
|
|
28
|
+
});
|
|
30
29
|
};
|
|
31
30
|
|
|
32
31
|
return createEventSubscriber(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { pushToCache, queryCache } from '~/cache/api';
|
|
2
2
|
import { pullFromCache } from '~/cache/api/pullFromCache';
|
|
3
3
|
|
|
4
|
-
export const reCalculateChannelUnreadInfo =
|
|
4
|
+
export const reCalculateChannelUnreadInfo = (channelId: string): Amity.ChannelUnreadInfo => {
|
|
5
5
|
const cacheKeyChannelUnread = ['channelUnreadInfo', 'get', channelId];
|
|
6
6
|
const cacheChannelUnreadInfo =
|
|
7
7
|
pullFromCache<Amity.ChannelUnreadInfo>(cacheKeyChannelUnread)?.data;
|
|
@@ -25,7 +25,7 @@ export const reCalculateChannelUnreadInfo = async (channelId: string) => {
|
|
|
25
25
|
isMentioned = subChannelUnreadsInfo.some(({ data }) => data.isMentioned);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
const channelUnreadInfo = {
|
|
29
29
|
...(cacheChannelUnreadInfo ?? {
|
|
30
30
|
channelId,
|
|
31
31
|
createdAt: new Date().toISOString(),
|
|
@@ -33,5 +33,9 @@ export const reCalculateChannelUnreadInfo = async (channelId: string) => {
|
|
|
33
33
|
updatedAt: new Date().toISOString(),
|
|
34
34
|
unreadCount: channelUnreads,
|
|
35
35
|
isMentioned,
|
|
36
|
-
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
pushToCache(cacheKeyChannelUnread, channelUnreadInfo);
|
|
39
|
+
|
|
40
|
+
return channelUnreadInfo;
|
|
37
41
|
};
|
|
@@ -2,7 +2,11 @@ import { pullFromCache } from '~/cache/api';
|
|
|
2
2
|
import { getChannelMessagePreview } from './getChannelMessagePreview';
|
|
3
3
|
import { LinkedObject } from '~/utils/linkedObject';
|
|
4
4
|
|
|
5
|
-
export const getChannelMessagePreviewWithUser = (
|
|
5
|
+
export const getChannelMessagePreviewWithUser = (
|
|
6
|
+
channel: Amity.InternalChannel,
|
|
7
|
+
): Amity.InternalChannel & {
|
|
8
|
+
messagePreview: Amity.MessagePreview | null;
|
|
9
|
+
} => {
|
|
6
10
|
const messagePreview = channel.messagePreviewId
|
|
7
11
|
? getChannelMessagePreview(channel.channelId)
|
|
8
12
|
: null;
|
|
@@ -4,6 +4,8 @@ import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
|
4
4
|
import { prepareMessagePayload } from '../utils';
|
|
5
5
|
import { updateSubChannelUnreadFromMessage } from '~/marker/utils/updateSubChannelUnreadFromMessage';
|
|
6
6
|
import { reCalculateChannelUnreadInfo } from '~/marker/utils/reCalculateChannelUnreadInfo';
|
|
7
|
+
import { markReadMessage } from '../utils/markReadMessage';
|
|
8
|
+
import { getActiveUser } from '~/client/api/activeUser';
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
11
|
* ```js
|
|
@@ -25,6 +27,7 @@ export const onMessageCreatedMqtt = (
|
|
|
25
27
|
callback: Amity.Listener<Amity.InternalMessage>,
|
|
26
28
|
): Amity.Unsubscriber => {
|
|
27
29
|
const client = getActiveClient();
|
|
30
|
+
const user = getActiveUser();
|
|
28
31
|
|
|
29
32
|
const filter = async (rawPayload: Amity.MessagePayload) => {
|
|
30
33
|
const payload = await prepareMessagePayload(rawPayload);
|
|
@@ -41,6 +44,7 @@ export const onMessageCreatedMqtt = (
|
|
|
41
44
|
ingestInCache(payload);
|
|
42
45
|
|
|
43
46
|
payload.messages.forEach(message => {
|
|
47
|
+
if (message.creatorPrivateId === user._id) markReadMessage(message);
|
|
44
48
|
callback(message);
|
|
45
49
|
});
|
|
46
50
|
};
|
|
@@ -49,7 +49,7 @@ export class MessageLiveCollectionController extends LiveCollectionController<
|
|
|
49
49
|
);
|
|
50
50
|
|
|
51
51
|
this.callback = callback.bind(this);
|
|
52
|
-
this.loadPage(true);
|
|
52
|
+
this.loadPage({ initial: true });
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
protected setup() {
|
|
@@ -107,8 +107,8 @@ export class MessageLiveCollectionController extends LiveCollectionController<
|
|
|
107
107
|
if (!this.shouldNotify(data) && origin === 'event') return;
|
|
108
108
|
|
|
109
109
|
this.callback({
|
|
110
|
-
onNextPage: () => this.loadPage(
|
|
111
|
-
onPrevPage: () => this.loadPage(
|
|
110
|
+
onNextPage: () => this.loadPage({ direction: Amity.LiveCollectionPageDirection.NEXT }),
|
|
111
|
+
onPrevPage: () => this.loadPage({ direction: Amity.LiveCollectionPageDirection.PREV }),
|
|
112
112
|
data,
|
|
113
113
|
hasNextPage: !!this.paginationController.getNextToken(),
|
|
114
114
|
hasPrevPage: !!this.paginationController.getPrevToken(),
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import ReadReceiptSyncEngine from '~/client/utils/ReadReceiptSync/readReceiptSyncEngine';
|
|
2
|
+
|
|
3
|
+
export const markReadMessage = (message: Amity.InternalMessage) => {
|
|
4
|
+
const { subChannelId, channelSegment } = message;
|
|
5
|
+
const markReadReceiptEngine = ReadReceiptSyncEngine.getInstance();
|
|
6
|
+
|
|
7
|
+
markReadReceiptEngine.markRead(subChannelId, channelSegment);
|
|
8
|
+
};
|
|
@@ -26,7 +26,7 @@ import { LinkedObject } from '~/utils/linkedObject';
|
|
|
26
26
|
* @category Post API
|
|
27
27
|
* @async
|
|
28
28
|
*/
|
|
29
|
-
export const createPost = async <T extends Amity.PostContentType>(
|
|
29
|
+
export const createPost = async <T extends Amity.PostContentType | string>(
|
|
30
30
|
bundle: Pick<Amity.Post<T>, 'targetType' | 'targetId'> &
|
|
31
31
|
Partial<Pick<Amity.Post<T>, 'metadata' | 'mentionees' | 'tags'>> & {
|
|
32
32
|
dataType?: T;
|
|
@@ -37,7 +37,6 @@ export const createPost = async <T extends Amity.PostContentType>(
|
|
|
37
37
|
const client = getActiveClient();
|
|
38
38
|
client.log('post/createPost', bundle);
|
|
39
39
|
|
|
40
|
-
// API-FIX: backend rejects that we pass the dataType manually T_T
|
|
41
40
|
if (!bundle.dataType || ['text', 'image', 'file', 'video'].includes(bundle.dataType)) {
|
|
42
41
|
// eslint-disable-next-line no-param-reassign
|
|
43
42
|
delete bundle.dataType;
|
|
@@ -47,7 +47,7 @@ export const editPost = async <T extends Amity.PostContentType>(
|
|
|
47
47
|
const cachedAt = client.cache && Date.now();
|
|
48
48
|
if (client.cache) ingestInCache(data, { cachedAt });
|
|
49
49
|
|
|
50
|
-
fireEvent('post.updated', data);
|
|
50
|
+
fireEvent('local.post.updated', data);
|
|
51
51
|
|
|
52
52
|
const { posts } = data;
|
|
53
53
|
|
|
@@ -51,7 +51,7 @@ export const updatePost = async <T extends Amity.PostContentType>(
|
|
|
51
51
|
const cachedAt = client.cache && Date.now();
|
|
52
52
|
if (client.cache) ingestInCache(data, { cachedAt });
|
|
53
53
|
|
|
54
|
-
fireEvent('post.updated', data);
|
|
54
|
+
fireEvent('local.post.updated', data);
|
|
55
55
|
|
|
56
56
|
const { posts } = data;
|
|
57
57
|
|
|
@@ -13,6 +13,8 @@ import {
|
|
|
13
13
|
} from '../events';
|
|
14
14
|
import { pullFromCache, pushToCache } from '~/cache/api';
|
|
15
15
|
import { LinkedObject } from '~/utils/linkedObject';
|
|
16
|
+
import { onCommentCreated, onCommentDeleted } from '~/commentRepository';
|
|
17
|
+
import { convertEventPayload } from '~/utils/event';
|
|
16
18
|
|
|
17
19
|
/* begin_public_function
|
|
18
20
|
id: post.get
|
|
@@ -80,6 +82,30 @@ export const getPost = (
|
|
|
80
82
|
},
|
|
81
83
|
onPostUnflagged,
|
|
82
84
|
onPostUpdated,
|
|
85
|
+
convertEventPayload(
|
|
86
|
+
(callback: Amity.Listener<Amity.InternalComment>) => {
|
|
87
|
+
return onCommentCreated(async (comment: Amity.InternalComment) => {
|
|
88
|
+
if (comment.referenceId === postId) {
|
|
89
|
+
await _getPost(postId);
|
|
90
|
+
callback(comment);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
},
|
|
94
|
+
'referenceId',
|
|
95
|
+
'post',
|
|
96
|
+
),
|
|
97
|
+
convertEventPayload(
|
|
98
|
+
(callback: Amity.Listener<Amity.InternalComment>) => {
|
|
99
|
+
return onCommentDeleted(async (comment: Amity.InternalComment) => {
|
|
100
|
+
if (comment.referenceId === postId) {
|
|
101
|
+
await _getPost(postId);
|
|
102
|
+
callback(comment);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
},
|
|
106
|
+
'referenceId',
|
|
107
|
+
'post',
|
|
108
|
+
),
|
|
83
109
|
]);
|
|
84
110
|
};
|
|
85
111
|
/* end_public_function */
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { getResolver } from '~/core/model';
|
|
3
3
|
import { getActiveClient } from '~/client/api';
|
|
4
4
|
import { dropFromCache, pullFromCache, pushToCache } from '~/cache/api';
|
|
5
|
+
import { getPost as _getPost } from '../api/getPost';
|
|
5
6
|
|
|
6
7
|
import {
|
|
7
8
|
createQuery,
|
|
@@ -34,6 +35,8 @@ import {
|
|
|
34
35
|
onPostUpdated,
|
|
35
36
|
} from '../events';
|
|
36
37
|
import { queryPosts } from '../api/queryPosts';
|
|
38
|
+
import { convertEventPayload } from '~/utils/event';
|
|
39
|
+
import { onCommentCreated, onCommentDeleted } from '~/commentRepository';
|
|
37
40
|
|
|
38
41
|
/* begin_public_function
|
|
39
42
|
id: post.query
|
|
@@ -204,6 +207,34 @@ export const getPosts = (
|
|
|
204
207
|
onPostUnflagged(realtimeRouter('onUnflagged')),
|
|
205
208
|
onPostReactionAdded(realtimeRouter('onReactionAdded')),
|
|
206
209
|
onPostReactionRemoved(realtimeRouter('onReactionRemoved')),
|
|
210
|
+
convertEventPayload(
|
|
211
|
+
(callback: Amity.Listener<Amity.InternalComment>) => {
|
|
212
|
+
return onCommentCreated(async (comment: Amity.InternalComment) => {
|
|
213
|
+
const currentCollection = pullFromCache<Amity.PostLiveCollectionCache>(cacheKey)?.data;
|
|
214
|
+
|
|
215
|
+
if (!currentCollection || currentCollection.data.includes(comment.referenceId)) return;
|
|
216
|
+
|
|
217
|
+
await _getPost(comment.referenceId);
|
|
218
|
+
callback(comment);
|
|
219
|
+
});
|
|
220
|
+
},
|
|
221
|
+
'referenceId',
|
|
222
|
+
'post',
|
|
223
|
+
)(realtimeRouter('onUpdate')),
|
|
224
|
+
convertEventPayload(
|
|
225
|
+
(callback: Amity.Listener<Amity.InternalComment>) => {
|
|
226
|
+
return onCommentDeleted(async (comment: Amity.InternalComment) => {
|
|
227
|
+
const currentCollection = pullFromCache<Amity.PostLiveCollectionCache>(cacheKey)?.data;
|
|
228
|
+
|
|
229
|
+
if (!currentCollection || currentCollection.data.includes(comment.referenceId)) return;
|
|
230
|
+
|
|
231
|
+
await _getPost(comment.referenceId);
|
|
232
|
+
callback(comment);
|
|
233
|
+
});
|
|
234
|
+
},
|
|
235
|
+
'referenceId',
|
|
236
|
+
'post',
|
|
237
|
+
)(realtimeRouter('onUpdate')),
|
|
207
238
|
);
|
|
208
239
|
|
|
209
240
|
onFetch(true);
|
package/src/storyRepository/observers/getGlobalStoryTargets/GlobalStoryLiveCollectionController.ts
CHANGED
|
@@ -48,7 +48,7 @@ export class GlobalStoryLiveCollectionController extends LiveCollectionControlle
|
|
|
48
48
|
|
|
49
49
|
this.paginationController = paginationController;
|
|
50
50
|
this.callback = callback.bind(this);
|
|
51
|
-
this.loadPage(true);
|
|
51
|
+
this.loadPage({ initial: true });
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
protected setup() {
|
|
@@ -94,7 +94,7 @@ export class GlobalStoryLiveCollectionController extends LiveCollectionControlle
|
|
|
94
94
|
) as Amity.StoryTarget[];
|
|
95
95
|
|
|
96
96
|
this.callback({
|
|
97
|
-
onNextPage: () => this.loadPage(
|
|
97
|
+
onNextPage: () => this.loadPage({ direction: Amity.LiveCollectionPageDirection.NEXT }),
|
|
98
98
|
data,
|
|
99
99
|
hasNextPage: !!this.paginationController.getNextToken(),
|
|
100
100
|
loading,
|
package/src/storyRepository/observers/getStoriesByTargetIds/StoryLiveCollectionController.ts
CHANGED
|
@@ -42,7 +42,7 @@ export class StoryLiveCollectionController extends LiveCollectionController<
|
|
|
42
42
|
|
|
43
43
|
this.paginationController = paginationController;
|
|
44
44
|
this.callback = callback.bind(this);
|
|
45
|
-
this.loadPage(true);
|
|
45
|
+
this.loadPage({ initial: true });
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
protected setup() {
|
|
@@ -20,7 +20,7 @@ import { getActiveClient } from '~/client';
|
|
|
20
20
|
import { getSubChannelMessagePreviewWithUser } from '~/messagePreview/utils';
|
|
21
21
|
import { isEqual } from '~/utils/isEqual';
|
|
22
22
|
import { updateSubChannelCache } from '../utils/updateSubChannelCache';
|
|
23
|
-
import {
|
|
23
|
+
import { onSubChannelUnreadUpdatedLocal } from '~/marker/events/onSubChannelUnreadUpdatedLocal';
|
|
24
24
|
|
|
25
25
|
/* begin_public_function
|
|
26
26
|
id: subchannel.get
|
|
@@ -135,10 +135,12 @@ export const getSubChannel = (
|
|
|
135
135
|
updateSubChannelCache(message.subChannelId, subChannel, {
|
|
136
136
|
messagePreviewId: message.messageId,
|
|
137
137
|
});
|
|
138
|
+
};
|
|
138
139
|
|
|
140
|
+
return onMessageCreatedMqtt(async (message: Amity.InternalMessage) => {
|
|
141
|
+
await updateMessagePreview(message);
|
|
139
142
|
callback(message);
|
|
140
|
-
};
|
|
141
|
-
return onMessageCreatedMqtt(updateMessagePreview);
|
|
143
|
+
});
|
|
142
144
|
},
|
|
143
145
|
'subChannelId',
|
|
144
146
|
'subChannel',
|
|
@@ -163,10 +165,12 @@ export const getSubChannel = (
|
|
|
163
165
|
updateSubChannelCache(message.subChannelId, subChannel, {
|
|
164
166
|
messagePreviewId: message.messageId,
|
|
165
167
|
});
|
|
168
|
+
};
|
|
166
169
|
|
|
170
|
+
return onMessageCreatedLocal(async (message: Amity.InternalMessage) => {
|
|
171
|
+
await updateMessagePreview(message);
|
|
167
172
|
callback(message);
|
|
168
|
-
};
|
|
169
|
-
return onMessageCreatedLocal(updateMessagePreview);
|
|
173
|
+
});
|
|
170
174
|
},
|
|
171
175
|
'subChannelId',
|
|
172
176
|
'subChannel',
|
|
@@ -217,7 +221,7 @@ export const getSubChannel = (
|
|
|
217
221
|
'subChannelId',
|
|
218
222
|
'subChannel',
|
|
219
223
|
),
|
|
220
|
-
convertEventPayload(
|
|
224
|
+
convertEventPayload(onSubChannelUnreadUpdatedLocal, 'subChannelId', 'subChannel'),
|
|
221
225
|
],
|
|
222
226
|
{
|
|
223
227
|
forceDispatch: true,
|
package/src/subChannelRepository/observers/getSubChannels/SubChannelLiveCollectionController.ts
CHANGED
|
@@ -29,7 +29,7 @@ import { getSubChannel } from '~/subChannelRepository/api/getSubChannel';
|
|
|
29
29
|
import { updateSubChannelCache } from '~/subChannelRepository/utils/updateSubChannelCache';
|
|
30
30
|
import { prepareSubChannelPayload } from '~/subChannelRepository/utils';
|
|
31
31
|
import { onSubChannelFetched } from '~/subChannelRepository/events/onSubChannelFetched';
|
|
32
|
-
import {
|
|
32
|
+
import { onSubChannelUnreadUpdatedLocal } from '~/marker/events/onSubChannelUnreadUpdatedLocal';
|
|
33
33
|
|
|
34
34
|
export class SubChannelLiveCollectionController extends LiveCollectionController<
|
|
35
35
|
'subChannel',
|
|
@@ -59,7 +59,7 @@ export class SubChannelLiveCollectionController extends LiveCollectionController
|
|
|
59
59
|
prepareSubChannelPayload,
|
|
60
60
|
);
|
|
61
61
|
this.callback = callback.bind(this);
|
|
62
|
-
this.loadPage(true);
|
|
62
|
+
this.loadPage({ initial: true });
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
protected setup() {
|
|
@@ -119,6 +119,14 @@ export class SubChannelLiveCollectionController extends LiveCollectionController
|
|
|
119
119
|
},
|
|
120
120
|
{
|
|
121
121
|
fn: callback => {
|
|
122
|
+
const updateMessagePreview = async (message: Amity.InternalMessage) => {
|
|
123
|
+
const client = getActiveClient();
|
|
124
|
+
const messagePreviewSetting = await client.getMessagePreviewSetting(false);
|
|
125
|
+
|
|
126
|
+
if (messagePreviewSetting === Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW) return;
|
|
127
|
+
|
|
128
|
+
handleMessageCreated(message);
|
|
129
|
+
};
|
|
122
130
|
return onMessageCreatedMqtt(async message => {
|
|
123
131
|
const cacheData = pullFromCache<Amity.SubChannel>([
|
|
124
132
|
'subChannel',
|
|
@@ -134,12 +142,7 @@ export class SubChannelLiveCollectionController extends LiveCollectionController
|
|
|
134
142
|
|
|
135
143
|
if (!collection || !collection.data.includes(message.subChannelId)) return;
|
|
136
144
|
|
|
137
|
-
|
|
138
|
-
const messagePreviewSetting = await client.getMessagePreviewSetting(false);
|
|
139
|
-
|
|
140
|
-
if (messagePreviewSetting === Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW) return;
|
|
141
|
-
|
|
142
|
-
handleMessageCreated(message);
|
|
145
|
+
await updateMessagePreview(message);
|
|
143
146
|
|
|
144
147
|
const subChannelCache = pullFromCache<Amity.SubChannel>([
|
|
145
148
|
'subChannel',
|
|
@@ -291,7 +294,7 @@ export class SubChannelLiveCollectionController extends LiveCollectionController
|
|
|
291
294
|
action: 'onUpdate',
|
|
292
295
|
},
|
|
293
296
|
{
|
|
294
|
-
fn: convertEventPayload(
|
|
297
|
+
fn: convertEventPayload(onSubChannelUnreadUpdatedLocal, 'subChannelId', 'subChannel'),
|
|
295
298
|
action: 'onUpdate',
|
|
296
299
|
},
|
|
297
300
|
]);
|
|
@@ -312,7 +315,7 @@ export class SubChannelLiveCollectionController extends LiveCollectionController
|
|
|
312
315
|
if (!this.shouldNotify(data) && origin === 'event') return;
|
|
313
316
|
|
|
314
317
|
this.callback({
|
|
315
|
-
onNextPage: () => this.loadPage(
|
|
318
|
+
onNextPage: () => this.loadPage({ direction: Amity.LiveCollectionPageDirection.NEXT }),
|
|
316
319
|
data,
|
|
317
320
|
hasNextPage: !!this.paginationController.getNextToken(),
|
|
318
321
|
loading,
|
|
@@ -6,6 +6,7 @@ import { postLinkedObject } from './postLinkedObject';
|
|
|
6
6
|
import { messageLinkedObject } from './messageLinkedObject';
|
|
7
7
|
import { storyTargetLinkedObject } from './storyTargetLinkedObject';
|
|
8
8
|
import { reactorLinkedObject } from './reactorLinkedObject';
|
|
9
|
+
import { channelLinkedObject } from './channelLinkedObject';
|
|
9
10
|
|
|
10
11
|
export const LinkedObject = {
|
|
11
12
|
comment: commentLinkedObject,
|
|
@@ -16,4 +17,5 @@ export const LinkedObject = {
|
|
|
16
17
|
storyTarget: storyTargetLinkedObject,
|
|
17
18
|
message: messageLinkedObject,
|
|
18
19
|
reactor: reactorLinkedObject,
|
|
20
|
+
channel: channelLinkedObject,
|
|
19
21
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import ReadReceiptSyncEngine from '~/client/utils/ReadReceiptSync/readReceiptSyncEngine';
|
|
2
1
|
import { getMessageReadCount } from '~/messageRepository/utils/getMessageReadCount';
|
|
2
|
+
import { markReadMessage } from '~/messageRepository/utils/markReadMessage';
|
|
3
3
|
|
|
4
4
|
export const messageLinkedObject = (message: Amity.InternalMessage): Amity.Message => {
|
|
5
5
|
const { creatorPrivateId, ...rest } = message;
|
|
@@ -11,11 +11,6 @@ export const messageLinkedObject = (message: Amity.InternalMessage): Amity.Messa
|
|
|
11
11
|
get deliveredCount() {
|
|
12
12
|
return getMessageReadCount(message).deliveredCount;
|
|
13
13
|
},
|
|
14
|
-
markRead: () =>
|
|
15
|
-
const { subChannelId, channelSegment } = message;
|
|
16
|
-
const markReadReceiptEngine = ReadReceiptSyncEngine.getInstance();
|
|
17
|
-
|
|
18
|
-
markReadReceiptEngine.markRead(subChannelId, channelSegment);
|
|
19
|
-
},
|
|
14
|
+
markRead: () => markReadMessage(message),
|
|
20
15
|
};
|
|
21
16
|
};
|
package/src/utils/liveObject.ts
CHANGED
package/src/utils/object.ts
CHANGED
|
@@ -20,3 +20,18 @@ export const convertGetterPropsToStatic = <T extends Record<string, unknown>>(ob
|
|
|
20
20
|
|
|
21
21
|
return Object.fromEntries(entries);
|
|
22
22
|
};
|
|
23
|
+
|
|
24
|
+
export const removeFunctionProperties = <T extends Record<string, unknown>>(obj: T): T => {
|
|
25
|
+
if (!isObject(obj)) {
|
|
26
|
+
return obj;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const entries = Object.entries(obj).map(([key, value]) => {
|
|
30
|
+
if (typeof value === 'function') {
|
|
31
|
+
return [key, undefined];
|
|
32
|
+
}
|
|
33
|
+
return [key, value];
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
return Object.fromEntries(entries);
|
|
37
|
+
};
|