@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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amityco/ts-sdk-react-native",
|
|
3
|
-
"version": "6.22.1-
|
|
3
|
+
"version": "6.22.1-b0a1854.0",
|
|
4
4
|
"license": "CC-BY-ND-4.0",
|
|
5
5
|
"author": "amity.co <developers@amity.co> (https://amity.co)",
|
|
6
6
|
"description": "Amity Social Cloud Typescript SDK",
|
|
@@ -46,12 +46,14 @@
|
|
|
46
46
|
"@types/jest": "^27.5.1",
|
|
47
47
|
"@types/node": "^18.6.4",
|
|
48
48
|
"@types/object-hash": "^3.0.6",
|
|
49
|
+
"@types/react-native": "0.63.4",
|
|
49
50
|
"@types/socket.io-client": "^1.4.34",
|
|
50
51
|
"chalk": "^4.1.2",
|
|
51
52
|
"concurrently": "^6.1.0",
|
|
52
53
|
"form-data": "^4.0.0",
|
|
53
54
|
"jest": "^28.1.0",
|
|
54
55
|
"nock": "^13.3.0",
|
|
56
|
+
"react-native": "0.63.4",
|
|
55
57
|
"react-native-web": "^0.19.8",
|
|
56
58
|
"rimraf": "^3.0.2",
|
|
57
59
|
"rollup": "^2.77.2",
|
package/rollup.config.js
CHANGED
|
@@ -194,6 +194,9 @@ declare global {
|
|
|
194
194
|
userFeedMarkers: Amity.UserFeedMarkerResponse[];
|
|
195
195
|
};
|
|
196
196
|
|
|
197
|
+
'local.subChannelUnread.updated': Amity.SubChannelUnreadInfo;
|
|
198
|
+
'local.channelUnread.updated': Amity.ChannelUnreadInfo;
|
|
199
|
+
|
|
197
200
|
'local.story.created': Amity.StoryPayload;
|
|
198
201
|
'local.story.updated': Amity.StoryPayload;
|
|
199
202
|
'local.story.deleted': Amity.StoryPayload;
|
|
@@ -206,6 +209,11 @@ declare global {
|
|
|
206
209
|
'local.story.error': Amity.StoryPayload;
|
|
207
210
|
'local.story.reload': { referenceIds: Amity.Story['referenceId'][] };
|
|
208
211
|
|
|
212
|
+
'local.post.updated': Amity.PostPayload;
|
|
213
|
+
|
|
214
|
+
'local.comment.created': Amity.CommentPayload;
|
|
215
|
+
'local.comment.deleted': Amity.CommentPayload;
|
|
216
|
+
|
|
209
217
|
sessionStateChange: Amity.SessionStates;
|
|
210
218
|
// used by accessTokenExpiryWatcher
|
|
211
219
|
tokenExpired: Amity.SessionStates.TOKEN_EXPIRED;
|
|
@@ -75,6 +75,22 @@ declare global {
|
|
|
75
75
|
};
|
|
76
76
|
|
|
77
77
|
type QueryCommunities = {
|
|
78
|
+
/** @deprecated use searchCommunities instead */
|
|
79
|
+
displayName?: string;
|
|
80
|
+
membership?: 'all' | 'member' | 'notMember';
|
|
81
|
+
categoryId?: Amity.InternalCategory['categoryId'];
|
|
82
|
+
includeDeleted?: boolean;
|
|
83
|
+
tags?: Amity.Taggable['tags'];
|
|
84
|
+
sortBy?:
|
|
85
|
+
| 'firstCreated'
|
|
86
|
+
| 'lastCreated'
|
|
87
|
+
/** @deprecated sortBy displayName is not available */
|
|
88
|
+
| 'displayName';
|
|
89
|
+
page?: string;
|
|
90
|
+
limit?: number;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
type SearchQueryCommunities = {
|
|
78
94
|
displayName?: string;
|
|
79
95
|
membership?: 'all' | 'member' | 'notMember';
|
|
80
96
|
categoryId?: Amity.InternalCategory['categoryId'];
|
|
@@ -87,16 +103,40 @@ declare global {
|
|
|
87
103
|
|
|
88
104
|
type CommunityLiveCollection = Amity.LiveCollectionParams<Omit<QueryCommunities, 'page'>>;
|
|
89
105
|
|
|
106
|
+
type SearchCommunityLiveCollection = Amity.LiveCollectionParams<
|
|
107
|
+
Omit<SearchQueryCommunities, 'page'>
|
|
108
|
+
>;
|
|
109
|
+
|
|
90
110
|
type CommunityLiveCollectionCache = Amity.LiveCollectionCache<
|
|
91
111
|
Amity.Community['communityId'],
|
|
92
112
|
Pick<QueryCommunities, 'page'>
|
|
93
113
|
>;
|
|
94
114
|
|
|
115
|
+
type SearchCommunityLiveCollectionCache = Amity.LiveCollectionCache<
|
|
116
|
+
Amity.Community['communityId'],
|
|
117
|
+
Pick<SearchQueryCommunities, 'page'>
|
|
118
|
+
>;
|
|
119
|
+
|
|
95
120
|
type QueryCommunityMembers = {
|
|
96
121
|
communityId: string;
|
|
97
122
|
memberships?: ('banned' | 'member')[];
|
|
98
123
|
roles?: string[];
|
|
99
|
-
sortBy?:
|
|
124
|
+
sortBy?:
|
|
125
|
+
| 'firstCreated'
|
|
126
|
+
| 'lastCreated'
|
|
127
|
+
/** @deprecated sortBy displayName is not available */
|
|
128
|
+
| 'displayName';
|
|
129
|
+
/** @deprecated use searchCommunityMembers instead */
|
|
130
|
+
search?: Amity.InternalUser['displayName'] | Amity.InternalUser['userId'];
|
|
131
|
+
page?: string;
|
|
132
|
+
limit?: number;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
type QuerySearchCommunityMembers = {
|
|
136
|
+
communityId: string;
|
|
137
|
+
memberships?: ('banned' | 'member')[];
|
|
138
|
+
roles?: string[];
|
|
139
|
+
sortBy?: 'firstCreated' | 'lastCreated' | 'displayName';
|
|
100
140
|
search?: Amity.InternalUser['displayName'] | Amity.InternalUser['userId'];
|
|
101
141
|
page?: string;
|
|
102
142
|
limit?: number;
|
|
@@ -106,9 +146,18 @@ declare global {
|
|
|
106
146
|
Omit<QueryCommunityMembers, 'page'>
|
|
107
147
|
>;
|
|
108
148
|
|
|
149
|
+
type SearchCommunityMemberLiveCollection = Amity.LiveCollectionParams<
|
|
150
|
+
Omit<QuerySearchCommunityMembers, 'page'>
|
|
151
|
+
>;
|
|
152
|
+
|
|
109
153
|
type CommunityMemberLiveCollectionCache = Amity.LiveCollectionCache<
|
|
110
154
|
Amity.Membership<'community'>['userId'],
|
|
111
155
|
Pick<QueryCommunityMembers, 'page'>
|
|
112
156
|
>;
|
|
157
|
+
|
|
158
|
+
type SearchCommunityMemberLiveCollectionCache = Amity.LiveCollectionCache<
|
|
159
|
+
Amity.Community['communityId'],
|
|
160
|
+
Pick<QuerySearchCommunityMembers, 'page'>
|
|
161
|
+
>;
|
|
113
162
|
}
|
|
114
163
|
}
|
|
@@ -5,7 +5,6 @@ export const PostContentType = Object.freeze({
|
|
|
5
5
|
VIDEO: 'video',
|
|
6
6
|
LIVESTREAM: 'liveStream',
|
|
7
7
|
POLL: 'poll',
|
|
8
|
-
CUSTOM: 'custom',
|
|
9
8
|
});
|
|
10
9
|
|
|
11
10
|
declare global {
|
|
@@ -27,7 +26,7 @@ declare global {
|
|
|
27
26
|
| 'onReactionAdded'
|
|
28
27
|
| 'onReactionRemoved';
|
|
29
28
|
|
|
30
|
-
type InternalPost<T extends PostContentType = any> = {
|
|
29
|
+
type InternalPost<T extends PostContentType | string = any> = {
|
|
31
30
|
postId: string;
|
|
32
31
|
postedUserId: Amity.InternalUser['userId']; // API-FIX: it should be "userId"
|
|
33
32
|
parentId: Amity.InternalPost['postId'];
|
|
@@ -60,7 +59,8 @@ declare global {
|
|
|
60
59
|
};
|
|
61
60
|
};
|
|
62
61
|
|
|
63
|
-
type Post<T extends PostContentType = any> = Amity.InternalPost<T> &
|
|
62
|
+
type Post<T extends PostContentType | string = any> = Amity.InternalPost<T> &
|
|
63
|
+
Amity.PostLinkObject;
|
|
64
64
|
|
|
65
65
|
type QueryPosts = {
|
|
66
66
|
targetId: string;
|
|
@@ -79,7 +79,7 @@ export const getChannel = async (
|
|
|
79
79
|
*/
|
|
80
80
|
getChannel.locally = (
|
|
81
81
|
channelId: Amity.Channel['channelPublicId'],
|
|
82
|
-
): Amity.Cached<Amity.
|
|
82
|
+
): Amity.Cached<Amity.InternalChannel> | undefined => {
|
|
83
83
|
const client = getActiveClient();
|
|
84
84
|
client.log('channel/getChannel.locally', channelId);
|
|
85
85
|
|
|
@@ -8,6 +8,7 @@ import { pushToTombstone } from '~/cache/api/pushToTombstone';
|
|
|
8
8
|
import { prepareChannelPayload } from '../utils';
|
|
9
9
|
import { fireEvent } from '~/core/events';
|
|
10
10
|
import { prepareUnreadCountInfo } from '../utils/prepateUnreadCountInfo';
|
|
11
|
+
import { LinkedObject } from '~/utils/linkedObject';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* ```js
|
|
@@ -25,7 +26,7 @@ import { prepareUnreadCountInfo } from '../utils/prepateUnreadCountInfo';
|
|
|
25
26
|
*/
|
|
26
27
|
export const getChannelByIds = async (
|
|
27
28
|
channelIds: Amity.Channel['channelPublicId'][],
|
|
28
|
-
): Promise<Amity.Cached<Amity.
|
|
29
|
+
): Promise<Amity.Cached<Amity.Channel[]>> => {
|
|
29
30
|
const client = getActiveClient();
|
|
30
31
|
client.log('channel/getChannelByIds', channelIds);
|
|
31
32
|
|
|
@@ -63,7 +64,7 @@ export const getChannelByIds = async (
|
|
|
63
64
|
fireEvent('local.channel.fetched', data.channels);
|
|
64
65
|
|
|
65
66
|
return {
|
|
66
|
-
data: data.channels,
|
|
67
|
+
data: data.channels.map(channel => LinkedObject.channel(channel)),
|
|
67
68
|
cachedAt,
|
|
68
69
|
};
|
|
69
70
|
};
|
|
@@ -99,7 +100,7 @@ getChannelByIds.locally = (
|
|
|
99
100
|
const oldest = cached.sort((a, b) => (a.cachedAt! < b.cachedAt! ? -1 : 1))?.[0];
|
|
100
101
|
|
|
101
102
|
return {
|
|
102
|
-
data: channels,
|
|
103
|
+
data: channels.map(channel => LinkedObject.channel(channel)),
|
|
103
104
|
cachedAt: oldest.cachedAt,
|
|
104
105
|
};
|
|
105
106
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getActiveClient } from '~/client/api';
|
|
1
|
+
import { getActiveClient } from '~/client/api/activeClient';
|
|
2
2
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
3
3
|
import { convertChannelMarkerResponse, convertSubChannelMarkerResponse } from '~/utils/marker';
|
|
4
4
|
import { fireEvent } from '~/core/events';
|
|
@@ -9,6 +9,8 @@ import { fireEvent } from '~/core/events';
|
|
|
9
9
|
* const success = await ChannelRepository.markAsRead('channelId')
|
|
10
10
|
* ```
|
|
11
11
|
*
|
|
12
|
+
* @deprecated Please use the {@link Amity.Channel.markAsRead} method instead
|
|
13
|
+
*
|
|
12
14
|
* Updating all {@link Amity.SubChannel} in specify {@link Amity.Channel} as read
|
|
13
15
|
*
|
|
14
16
|
* @param channelId the ID of to specify {@link Amity.Channel}
|
|
@@ -17,7 +19,9 @@ import { fireEvent } from '~/core/events';
|
|
|
17
19
|
* @category Channel API
|
|
18
20
|
* @async
|
|
19
21
|
*/
|
|
20
|
-
export const markAsRead = async (
|
|
22
|
+
export const markAsRead = async (
|
|
23
|
+
channelId: Amity.Channel['channelInternalId'],
|
|
24
|
+
): Promise<boolean> => {
|
|
21
25
|
const client = getActiveClient();
|
|
22
26
|
client.log('channel/markAsRead', channelId);
|
|
23
27
|
|
|
@@ -52,7 +52,7 @@ export class ChannelMemberLiveCollectionController extends LiveCollectionControl
|
|
|
52
52
|
);
|
|
53
53
|
|
|
54
54
|
this.callback = callback.bind(this);
|
|
55
|
-
this.loadPage(true);
|
|
55
|
+
this.loadPage({ initial: true });
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
protected setup() {
|
|
@@ -104,7 +104,7 @@ export class ChannelMemberLiveCollectionController extends LiveCollectionControl
|
|
|
104
104
|
if (!this.shouldNotify(data) && origin === 'event') return;
|
|
105
105
|
|
|
106
106
|
this.callback({
|
|
107
|
-
onNextPage: () => this.loadPage(
|
|
107
|
+
onNextPage: () => this.loadPage({ direction: Amity.LiveCollectionPageDirection.NEXT }),
|
|
108
108
|
data,
|
|
109
109
|
hasNextPage: !!this.paginationController.getNextToken(),
|
|
110
110
|
loading,
|
|
@@ -72,7 +72,7 @@ export class ChannelMemberQueryStreamController extends QueryStreamController<
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
reactor(action: string) {
|
|
75
|
-
return (channel: Amity.
|
|
75
|
+
return (channel: Amity.InternalChannel, channelMember: Amity.Membership<'channel'>) => {
|
|
76
76
|
if (this.query.channelId !== channelMember.channelId) return;
|
|
77
77
|
|
|
78
78
|
const collection = pullFromCache<Amity.ChannelMembersLiveCollectionCache>(
|
|
@@ -99,7 +99,10 @@ export class ChannelMemberQueryStreamController extends QueryStreamController<
|
|
|
99
99
|
subscribeRTE(
|
|
100
100
|
createSubscriber: {
|
|
101
101
|
fn: (
|
|
102
|
-
reactor: (
|
|
102
|
+
reactor: (
|
|
103
|
+
channel: Amity.InternalChannel,
|
|
104
|
+
channelMember: Amity.Membership<'channel'>,
|
|
105
|
+
) => void,
|
|
103
106
|
) => Amity.Unsubscriber;
|
|
104
107
|
action: string;
|
|
105
108
|
}[],
|
|
@@ -17,7 +17,7 @@ import { createEventSubscriber } from '~/core/events';
|
|
|
17
17
|
* @category Channel Events
|
|
18
18
|
*/
|
|
19
19
|
export const onChannelMemberRoleAdded = (
|
|
20
|
-
callback: (channel: Amity.
|
|
20
|
+
callback: (channel: Amity.InternalChannel, member: Amity.Membership<'channel'>) => void,
|
|
21
21
|
): Amity.Unsubscriber => {
|
|
22
22
|
const client = getActiveClient();
|
|
23
23
|
|
|
@@ -20,7 +20,7 @@ import { prepareChannelPayload } from '../utils';
|
|
|
20
20
|
* @category Channel Events
|
|
21
21
|
*/
|
|
22
22
|
export const onChannelMemberRoleRemoved = (
|
|
23
|
-
callback: (channel: Amity.
|
|
23
|
+
callback: (channel: Amity.InternalChannel, member: Amity.Membership<'channel'>) => void,
|
|
24
24
|
): Amity.Unsubscriber => {
|
|
25
25
|
const client = getActiveClient();
|
|
26
26
|
|
|
@@ -33,7 +33,8 @@ import { isEqual } from '~/utils/isEqual';
|
|
|
33
33
|
import { updateChannelCache } from '../utils/updateChannelCache';
|
|
34
34
|
import { onChannelMarkerUpdated } from '~/marker/events/onChannelMarkerUpdated';
|
|
35
35
|
import { onSubChannelCreated } from '~/subChannelRepository';
|
|
36
|
-
import {
|
|
36
|
+
import { LinkedObject } from '~/utils/linkedObject';
|
|
37
|
+
import { onChannelUnreadUpdatedLocal } from '~/marker/events/onChannelUnreadUpdatedLocal';
|
|
37
38
|
|
|
38
39
|
/* begin_public_function
|
|
39
40
|
id: channel.get
|
|
@@ -72,7 +73,7 @@ export const getChannel = (
|
|
|
72
73
|
|
|
73
74
|
const data = {
|
|
74
75
|
...response,
|
|
75
|
-
data: getChannelMessagePreviewWithUser(response.data),
|
|
76
|
+
data: LinkedObject.channel(getChannelMessagePreviewWithUser(response.data)),
|
|
76
77
|
};
|
|
77
78
|
|
|
78
79
|
const { origin, ...newSnapshot } = data;
|
|
@@ -126,7 +127,10 @@ export const getChannel = (
|
|
|
126
127
|
callback(message);
|
|
127
128
|
};
|
|
128
129
|
|
|
129
|
-
return onMessageCreatedMqtt(
|
|
130
|
+
return onMessageCreatedMqtt(async (message: Amity.InternalMessage) => {
|
|
131
|
+
await updateMessagePreview(message);
|
|
132
|
+
callback(message);
|
|
133
|
+
});
|
|
130
134
|
},
|
|
131
135
|
'channelId',
|
|
132
136
|
'channel',
|
|
@@ -267,7 +271,7 @@ export const getChannel = (
|
|
|
267
271
|
'channel',
|
|
268
272
|
),
|
|
269
273
|
convertEventPayload(onSubChannelCreated, 'channelId', 'channel'),
|
|
270
|
-
convertEventPayload(
|
|
274
|
+
convertEventPayload(onChannelUnreadUpdatedLocal, 'channelId', 'channel'),
|
|
271
275
|
],
|
|
272
276
|
{
|
|
273
277
|
forceDispatch: true,
|
|
@@ -47,7 +47,6 @@ import { getActiveClient } from '~/client';
|
|
|
47
47
|
import { prepareChannelPayload } from '~/channelRepository/utils';
|
|
48
48
|
import { ChannelPaginationNoPageController } from './ChannelPagnationNoPageController';
|
|
49
49
|
import { PaginationController } from '~/core/liveCollection/PaginationController';
|
|
50
|
-
import { onUserFeedMarkerUpdated } from '~/marker/events/onUserFeedMarkerUpdated';
|
|
51
50
|
import { onSubChannelCreated } from '~/subChannelRepository';
|
|
52
51
|
|
|
53
52
|
import ObjectResolverEngine from '~/client/utils/ObjectResolver/objectResolverEngine';
|
|
@@ -55,6 +54,8 @@ import { prepareUnreadCountInfo } from '~/channelRepository/utils/prepateUnreadC
|
|
|
55
54
|
import { resolveUnreadInfoOnChannelEvent } from '~/channelRepository/utils/resolveUnreadInfoOnChannelEvent';
|
|
56
55
|
import { onChannelResolved } from '~/channelRepository/events/onChannelResolved';
|
|
57
56
|
import { onUserMessageFeedMarkerResolved } from '~/marker/events/onUserMessageFeedMarkerResolved';
|
|
57
|
+
import { LinkedObject } from '~/utils/linkedObject';
|
|
58
|
+
import { onChannelUnreadUpdatedLocal } from '~/marker/events/onChannelUnreadUpdatedLocal';
|
|
58
59
|
|
|
59
60
|
export class ChannelLiveCollectionController extends LiveCollectionController<
|
|
60
61
|
'channel',
|
|
@@ -97,7 +98,7 @@ export class ChannelLiveCollectionController extends LiveCollectionController<
|
|
|
97
98
|
|
|
98
99
|
this.paginationController = paginationController;
|
|
99
100
|
this.callback = callback.bind(this);
|
|
100
|
-
this.loadPage(true);
|
|
101
|
+
this.loadPage({ initial: true });
|
|
101
102
|
}
|
|
102
103
|
|
|
103
104
|
protected setup() {
|
|
@@ -135,7 +136,8 @@ export class ChannelLiveCollectionController extends LiveCollectionController<
|
|
|
135
136
|
.map(channelId => pullFromCache<Amity.Channel>(['channel', 'get', channelId])!)
|
|
136
137
|
.filter(Boolean)
|
|
137
138
|
.map(({ data }) => data)
|
|
138
|
-
.map(getChannelMessagePreviewWithUser)
|
|
139
|
+
.map(getChannelMessagePreviewWithUser)
|
|
140
|
+
.map(LinkedObject.channel) ?? [];
|
|
139
141
|
|
|
140
142
|
if (this.paginationController instanceof ChannelPaginationController) {
|
|
141
143
|
data = this.applyFilter(data);
|
|
@@ -146,7 +148,7 @@ export class ChannelLiveCollectionController extends LiveCollectionController<
|
|
|
146
148
|
this.callback({
|
|
147
149
|
onNextPage:
|
|
148
150
|
this.paginationController instanceof ChannelPaginationController
|
|
149
|
-
? () => this.loadPage(
|
|
151
|
+
? () => this.loadPage({ direction: Amity.LiveCollectionPageDirection.NEXT })
|
|
150
152
|
: undefined,
|
|
151
153
|
data,
|
|
152
154
|
hasNextPage:
|
|
@@ -515,10 +517,6 @@ export class ChannelLiveCollectionController extends LiveCollectionController<
|
|
|
515
517
|
),
|
|
516
518
|
action: Amity.ChannelActionType.OnUpdate,
|
|
517
519
|
},
|
|
518
|
-
{
|
|
519
|
-
fn: convertEventPayload(onUserFeedMarkerUpdated, 'entityId', 'channel'),
|
|
520
|
-
action: Amity.ChannelActionType.OnUpdate,
|
|
521
|
-
},
|
|
522
520
|
{
|
|
523
521
|
fn: convertEventPayload(onSubChannelCreated, 'channelId', 'channel'),
|
|
524
522
|
action: Amity.ChannelActionType.OnUpdate,
|
|
@@ -551,6 +549,10 @@ export class ChannelLiveCollectionController extends LiveCollectionController<
|
|
|
551
549
|
},
|
|
552
550
|
action: Amity.ChannelActionType.OnResolve,
|
|
553
551
|
},
|
|
552
|
+
{
|
|
553
|
+
fn: convertEventPayload(onChannelUnreadUpdatedLocal, 'channelId', 'channel'),
|
|
554
|
+
action: Amity.ChannelActionType.OnUpdate,
|
|
555
|
+
},
|
|
554
556
|
];
|
|
555
557
|
|
|
556
558
|
if (this.paginationController instanceof PaginationController) {
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
onChannelMemberAdded,
|
|
16
16
|
onChannelMemberRemoved,
|
|
17
17
|
} from '../events';
|
|
18
|
+
import { LinkedObject } from '~/utils/linkedObject';
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* ```js
|
|
@@ -46,11 +47,22 @@ export const observeChannel = <Events extends [Exclude<Amity.ChannelActionType,
|
|
|
46
47
|
// filter function
|
|
47
48
|
if (result.data?.channelId !== channelId) return;
|
|
48
49
|
|
|
49
|
-
if (callback instanceof Function)
|
|
50
|
+
if (callback instanceof Function)
|
|
51
|
+
return callback({
|
|
52
|
+
...result,
|
|
53
|
+
data: LinkedObject.channel(result.data),
|
|
54
|
+
});
|
|
50
55
|
|
|
51
|
-
if (action !== 'onFetch')
|
|
56
|
+
if (action !== 'onFetch')
|
|
57
|
+
callback.onEvent?.(action, {
|
|
58
|
+
...result,
|
|
59
|
+
data: LinkedObject.channel(result.data),
|
|
60
|
+
});
|
|
52
61
|
|
|
53
|
-
callback[action]?.(
|
|
62
|
+
callback[action]?.({
|
|
63
|
+
...result,
|
|
64
|
+
data: LinkedObject.channel(result.data),
|
|
65
|
+
});
|
|
54
66
|
};
|
|
55
67
|
|
|
56
68
|
const disposers: Amity.Unsubscriber[] = [];
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
onChannelMemberAdded,
|
|
13
13
|
onChannelMemberRemoved,
|
|
14
14
|
} from '../events';
|
|
15
|
+
import { LinkedObject } from '~/utils/linkedObject';
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* ```js
|
|
@@ -38,11 +39,14 @@ export const observeChannels = (
|
|
|
38
39
|
|
|
39
40
|
const disposers: Amity.Unsubscriber[] = [];
|
|
40
41
|
|
|
41
|
-
const router = (
|
|
42
|
-
|
|
42
|
+
const router = (
|
|
43
|
+
channel: Amity.InternalChannel,
|
|
44
|
+
action: Exclude<Amity.ChannelActionType, 'onFetch'>,
|
|
45
|
+
) => {
|
|
46
|
+
if (callback instanceof Function) return callback(LinkedObject.channel(channel));
|
|
43
47
|
|
|
44
|
-
callback.onEvent?.(action, channel);
|
|
45
|
-
callback[action]?.(channel);
|
|
48
|
+
callback.onEvent?.(action, LinkedObject.channel(channel));
|
|
49
|
+
callback[action]?.(LinkedObject.channel(channel));
|
|
46
50
|
};
|
|
47
51
|
|
|
48
52
|
disposers.push(
|
package/src/client/api/index.ts
CHANGED
package/src/client/api/logout.ts
CHANGED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Platform } from 'react-native';
|
|
2
|
+
import { getActiveClient } from './activeClient';
|
|
3
|
+
import { getDeviceId } from '~/core/device';
|
|
4
|
+
import { ASCApiError, ASCInvalidParameterError } from '~/core/errors';
|
|
5
|
+
|
|
6
|
+
export const registerPushNotification = async (deviceToken: string): Promise<boolean> => {
|
|
7
|
+
const client = getActiveClient();
|
|
8
|
+
|
|
9
|
+
let platform: 'ios' | 'android';
|
|
10
|
+
|
|
11
|
+
if (Platform.OS === 'ios' || Platform.OS === 'android') {
|
|
12
|
+
platform = Platform.OS;
|
|
13
|
+
} else {
|
|
14
|
+
throw new ASCInvalidParameterError('Unsupported platform');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const deviceId = getDeviceId();
|
|
18
|
+
|
|
19
|
+
const {
|
|
20
|
+
data: { status, error },
|
|
21
|
+
} = await client.http.post<{ status: 'success' | 'error'; error?: string }>(
|
|
22
|
+
'/v1/notification',
|
|
23
|
+
{
|
|
24
|
+
userId: client.userId,
|
|
25
|
+
deviceId,
|
|
26
|
+
platform,
|
|
27
|
+
token: deviceToken,
|
|
28
|
+
},
|
|
29
|
+
{ headers: { 'X-API-Key': client.apiKey } },
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
if (error) {
|
|
33
|
+
throw new ASCApiError(error, Amity.ServerError.BUSINESS_ERROR, Amity.ErrorLevel.ERROR);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return status === 'success';
|
|
37
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { getDeviceId } from '~/core/device';
|
|
2
|
+
import { getActiveClient } from './activeClient';
|
|
3
|
+
import { ASCApiError } from '~/core/errors';
|
|
4
|
+
|
|
5
|
+
export const unregisterPushNotification = async (): Promise<boolean> => {
|
|
6
|
+
const client = getActiveClient();
|
|
7
|
+
const deviceId = getDeviceId();
|
|
8
|
+
|
|
9
|
+
const {
|
|
10
|
+
data: { status, error },
|
|
11
|
+
} = await client.http.delete<{ status: 'success' | 'error'; error?: string }>(
|
|
12
|
+
'/v1/notification',
|
|
13
|
+
{
|
|
14
|
+
data: {
|
|
15
|
+
deviceId,
|
|
16
|
+
},
|
|
17
|
+
headers: { 'X-API-Key': client.apiKey },
|
|
18
|
+
},
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
if (error) {
|
|
22
|
+
throw new ASCApiError(error, Amity.ServerError.BUSINESS_ERROR, Amity.ErrorLevel.ERROR);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return status === 'success';
|
|
26
|
+
};
|
|
@@ -2,6 +2,7 @@ import { pullFromCache, pushToCache, queryCache } from '~/cache/api';
|
|
|
2
2
|
import { getActiveClient } from '../../api/activeClient';
|
|
3
3
|
import { markAsReadBySegment } from '~/subChannelRepository/api/markAsReadBySegment';
|
|
4
4
|
import { reCalculateChannelUnreadInfo } from '~/marker/utils/reCalculateChannelUnreadInfo';
|
|
5
|
+
import { fireEvent } from '~/core/events';
|
|
5
6
|
|
|
6
7
|
export class MessageReadReceiptSyncEngine {
|
|
7
8
|
private client: Amity.Client;
|
|
@@ -178,10 +179,12 @@ export class MessageReadReceiptSyncEngine {
|
|
|
178
179
|
subChannelUnreadInfo.readToSegment = segment;
|
|
179
180
|
subChannelUnreadInfo.unreadCount = Math.max(subChannelUnreadInfo.lastSegment - segment, 0);
|
|
180
181
|
|
|
181
|
-
reCalculateChannelUnreadInfo(subChannelUnreadInfo.channelId);
|
|
182
|
-
|
|
182
|
+
const channelUnreadInfo = reCalculateChannelUnreadInfo(subChannelUnreadInfo.channelId);
|
|
183
|
+
fireEvent('local.channelUnread.updated', channelUnreadInfo);
|
|
183
184
|
|
|
184
|
-
|
|
185
|
+
pushToCache(cacheKey, subChannelUnreadInfo);
|
|
186
|
+
fireEvent('local.subChannelUnread.updated', subChannelUnreadInfo);
|
|
187
|
+
}
|
|
185
188
|
|
|
186
189
|
// Step 2: Enqueue the read receipt
|
|
187
190
|
this.enqueueReadReceipt(subChannelId, segment);
|
|
@@ -18,6 +18,7 @@ import { enableUnreadCount } from '../api/enableUnreadCount';
|
|
|
18
18
|
|
|
19
19
|
import { onOnline } from './onOnline';
|
|
20
20
|
import { onUserFeedMarkerUpdated } from '~/marker/events/onUserFeedMarkerUpdated';
|
|
21
|
+
import { getActiveClient } from '~/client/api/activeClient';
|
|
21
22
|
|
|
22
23
|
const SYNC_TRIGGER_INTERVAL_TIME = 2000;
|
|
23
24
|
const ON_SUB_CHANNEL_DELETE_SYNC_TRIGGER_DELAY = 2000;
|
|
@@ -145,7 +146,9 @@ const registerEventListeners = () => {
|
|
|
145
146
|
|
|
146
147
|
onMessageCreatedMqtt(message => {
|
|
147
148
|
// only conversation, community and broadcast types can sync
|
|
148
|
-
|
|
149
|
+
const client = getActiveClient();
|
|
150
|
+
if (isUnreadCountSupport(message) && message.creatorId !== client.userId)
|
|
151
|
+
events.push(Amity.MarkerSyncEvent.NEW_MESSAGE);
|
|
149
152
|
}),
|
|
150
153
|
|
|
151
154
|
onChannelCreated(() => events.push(Amity.MarkerSyncEvent.CHANNEL_CREATED)),
|
|
@@ -53,7 +53,7 @@ export const createComment = async (
|
|
|
53
53
|
if (['post', 'content'].includes(bundle.referenceType)) {
|
|
54
54
|
const post = await getPost(bundle.referenceId);
|
|
55
55
|
|
|
56
|
-
fireEvent('post.updated', {
|
|
56
|
+
fireEvent('local.post.updated', {
|
|
57
57
|
posts: [post.data],
|
|
58
58
|
categories: [],
|
|
59
59
|
comments: [],
|
|
@@ -97,7 +97,7 @@ export const createComment = async (
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
fireEvent('comment.created', data);
|
|
100
|
+
fireEvent('local.comment.created', data);
|
|
101
101
|
|
|
102
102
|
return {
|
|
103
103
|
data: LinkedObject.comment(comments[0]),
|
|
@@ -64,8 +64,7 @@ export const deleteComment = async (
|
|
|
64
64
|
} else {
|
|
65
65
|
const post = await getPost(comment.data.referenceId);
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
fireEvent('post.updated', {
|
|
67
|
+
fireEvent('local.post.updated', {
|
|
69
68
|
posts: [post.data],
|
|
70
69
|
categories: [],
|
|
71
70
|
comments: [],
|
|
@@ -78,8 +77,7 @@ export const deleteComment = async (
|
|
|
78
77
|
});
|
|
79
78
|
}
|
|
80
79
|
|
|
81
|
-
|
|
82
|
-
fireEvent('comment.deleted', {
|
|
80
|
+
fireEvent('local.comment.deleted', {
|
|
83
81
|
comments: [deleted],
|
|
84
82
|
commentChildren: [],
|
|
85
83
|
files: [],
|