@amityco/ts-sdk 7.5.4-3506dd3.0 → 7.5.4-54f750e3.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/domains/channel.d.ts +1 -0
- package/dist/@types/domains/channel.d.ts.map +1 -1
- package/dist/@types/domains/group.d.ts +2 -0
- package/dist/@types/domains/group.d.ts.map +1 -1
- package/dist/@types/domains/invitation.d.ts +4 -2
- package/dist/@types/domains/invitation.d.ts.map +1 -1
- package/dist/channelRepository/channelMembership/observers/getMembers/ChannelMemberLiveCollectionController.d.ts.map +1 -1
- package/dist/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberLiveCollectionController.d.ts.map +1 -1
- package/dist/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberQueryStreamController.d.ts +2 -2
- package/dist/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberQueryStreamController.d.ts.map +1 -1
- package/dist/client/api/index.d.ts +1 -0
- package/dist/client/api/index.d.ts.map +1 -1
- package/dist/client/api/resumeSession.d.ts +32 -0
- package/dist/client/api/resumeSession.d.ts.map +1 -0
- package/dist/client/api/tests/resumeSession.test.d.ts +2 -0
- package/dist/client/api/tests/resumeSession.test.d.ts.map +1 -0
- package/dist/communityRepository/api/deleteCommunity.d.ts.map +1 -1
- package/dist/communityRepository/api/getCommunity.d.ts +2 -2
- package/dist/communityRepository/api/getCommunity.d.ts.map +1 -1
- package/dist/communityRepository/observers/getCommunity.d.ts.map +1 -1
- package/dist/communityRepository/observers/getJoinRequests/JoinRequestsPaginationController.d.ts.map +1 -1
- package/dist/index.cjs.js +228 -22
- package/dist/index.esm.js +227 -22
- package/dist/index.umd.js +4 -4
- package/dist/utils/linkedObject/channelLinkedObject.d.ts.map +1 -1
- package/dist/utils/linkedObject/channelMemberLinkedObject.d.ts +2 -0
- package/dist/utils/linkedObject/channelMemberLinkedObject.d.ts.map +1 -0
- package/dist/utils/linkedObject/index.d.ts +1 -0
- package/dist/utils/linkedObject/index.d.ts.map +1 -1
- package/dist/utils/linkedObject/invitationLinkedObject.d.ts.map +1 -1
- package/dist/utils/tests/dummy/community.d.ts +2 -0
- package/dist/utils/tests/dummy/community.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/@types/domains/channel.ts +1 -0
- package/src/@types/domains/group.ts +2 -0
- package/src/@types/domains/invitation.ts +8 -3
- package/src/channelRepository/channelMembership/observers/getMembers/ChannelMemberLiveCollectionController.ts +3 -1
- package/src/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberLiveCollectionController.ts +2 -1
- package/src/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberQueryStreamController.ts +2 -2
- package/src/client/api/index.ts +1 -0
- package/src/client/api/resumeSession.ts +282 -0
- package/src/client/api/tests/resumeSession.test.ts +173 -0
- package/src/communityRepository/api/deleteCommunity.ts +2 -1
- package/src/communityRepository/api/getCommunity.ts +5 -7
- package/src/communityRepository/observers/getCommunity.ts +24 -12
- package/src/communityRepository/observers/getJoinRequests/JoinRequestsPaginationController.ts +1 -2
- package/src/utils/linkedObject/channelLinkedObject.ts +19 -0
- package/src/utils/linkedObject/channelMemberLinkedObject.ts +20 -0
- package/src/utils/linkedObject/index.ts +2 -0
- package/src/utils/linkedObject/invitationLinkedObject.ts +4 -2
|
@@ -25,7 +25,7 @@ export const getCommunity = async (
|
|
|
25
25
|
communityId: Amity.Community['communityId'],
|
|
26
26
|
type?: Amity.JoinRequestType,
|
|
27
27
|
includeDiscoverablePrivateCommunity?: boolean,
|
|
28
|
-
): Promise<Amity.Cached<Amity.
|
|
28
|
+
): Promise<Amity.Cached<Amity.InternalCommunity>> => {
|
|
29
29
|
const client = getActiveClient();
|
|
30
30
|
client.log('community/getCommunity', communityId);
|
|
31
31
|
|
|
@@ -51,9 +51,7 @@ export const getCommunity = async (
|
|
|
51
51
|
const { communities } = data;
|
|
52
52
|
|
|
53
53
|
return {
|
|
54
|
-
data:
|
|
55
|
-
communities.find(community => community.communityId === communityId)!,
|
|
56
|
-
),
|
|
54
|
+
data: communities.find(community => community.communityId === communityId)!,
|
|
57
55
|
cachedAt,
|
|
58
56
|
};
|
|
59
57
|
};
|
|
@@ -73,18 +71,18 @@ export const getCommunity = async (
|
|
|
73
71
|
*/
|
|
74
72
|
getCommunity.locally = (
|
|
75
73
|
communityId: Amity.Community['communityId'],
|
|
76
|
-
): Amity.Cached<Amity.
|
|
74
|
+
): Amity.Cached<Amity.InternalCommunity> | undefined => {
|
|
77
75
|
const client = getActiveClient();
|
|
78
76
|
client.log('community/getCommunity.locally', communityId);
|
|
79
77
|
|
|
80
78
|
if (!client.cache) return;
|
|
81
79
|
|
|
82
|
-
const cached = pullFromCache<Amity.
|
|
80
|
+
const cached = pullFromCache<Amity.InternalCommunity>(['community', 'get', communityId]);
|
|
83
81
|
|
|
84
82
|
if (!cached) return;
|
|
85
83
|
|
|
86
84
|
return {
|
|
87
|
-
data:
|
|
85
|
+
data: cached.data,
|
|
88
86
|
cachedAt: cached.cachedAt,
|
|
89
87
|
};
|
|
90
88
|
};
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
onLocalCommunityJoin,
|
|
13
13
|
} from '../communityMembership/events';
|
|
14
14
|
import { convertEventPayload } from '~/utils/event';
|
|
15
|
+
import { LinkedObject } from '~/utils/linkedObject';
|
|
15
16
|
|
|
16
17
|
/* begin_public_function
|
|
17
18
|
id: community.get
|
|
@@ -39,17 +40,28 @@ export const getCommunity = (
|
|
|
39
40
|
communityId: Amity.Community['communityId'],
|
|
40
41
|
callback: Amity.LiveObjectCallback<Amity.Community>,
|
|
41
42
|
): Amity.Unsubscriber => {
|
|
42
|
-
return liveObject(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
43
|
+
return liveObject(
|
|
44
|
+
communityId,
|
|
45
|
+
callback,
|
|
46
|
+
'communityId',
|
|
47
|
+
_getCommunity,
|
|
48
|
+
[
|
|
49
|
+
onCommunityUpdated,
|
|
50
|
+
onCommunityDeleted,
|
|
51
|
+
onCommunityJoined,
|
|
52
|
+
onCommunityLeft,
|
|
53
|
+
onLocalCommunityJoined,
|
|
54
|
+
onLocalCommunityLeft,
|
|
55
|
+
onCommunityUserBanned,
|
|
56
|
+
onCommunityUserUnbanned,
|
|
57
|
+
onCommunityUserChanged,
|
|
58
|
+
convertEventPayload(onLocalCommunityJoin, 'targetId', 'community'),
|
|
59
|
+
],
|
|
60
|
+
{
|
|
61
|
+
callbackDataSelector: (data: Amity.InternalCommunity) => {
|
|
62
|
+
return LinkedObject.community(data);
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
);
|
|
54
66
|
};
|
|
55
67
|
/* end_public_function */
|
package/src/communityRepository/observers/getJoinRequests/JoinRequestsPaginationController.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { PaginationController } from '~/core/liveCollection/PaginationController';
|
|
2
|
-
import { COLLECTION_DEFAULT_PAGINATION_LIMIT } from '~/utils/constants';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* TODO: handle cache receive cache option, and cache policy
|
|
@@ -10,7 +9,7 @@ export class JoinRequestsPaginationController extends PaginationController<
|
|
|
10
9
|
Amity.JoinRequestLiveCollection
|
|
11
10
|
> {
|
|
12
11
|
async getRequest(queryParams: Amity.JoinRequestLiveCollection, token: string | undefined) {
|
|
13
|
-
const { limit =
|
|
12
|
+
const { limit = 20, communityId, ...params } = queryParams;
|
|
14
13
|
const options = token ? { token } : { limit };
|
|
15
14
|
|
|
16
15
|
const { data: queryResponse } = await this.http.get<
|
|
@@ -1,8 +1,27 @@
|
|
|
1
1
|
import { markAsRead } from '~/channelRepository/internalApi/markAsRead';
|
|
2
2
|
import { shallowClone } from '../shallowClone';
|
|
3
|
+
import { queryCache } from '~/cache/api';
|
|
4
|
+
import { channelMemberLinkedObject } from './channelMemberLinkedObject';
|
|
3
5
|
|
|
4
6
|
export const channelLinkedObject = (channel: Amity.InternalChannel): Amity.Channel => {
|
|
7
|
+
let previewMembers: Amity.Membership<'channel'>[] = [];
|
|
8
|
+
|
|
9
|
+
if (channel.type === 'conversation') {
|
|
10
|
+
const channelUsers = queryCache<Amity.Membership<'channel'>>(['channelUsers', 'get']);
|
|
11
|
+
if (channelUsers && channelUsers?.length > 0) {
|
|
12
|
+
previewMembers = (
|
|
13
|
+
channelUsers?.filter(({ data }) => data.channelId === channel.channelId) ?? []
|
|
14
|
+
)
|
|
15
|
+
// sort in ascending order by userInternalId
|
|
16
|
+
.sort((a, b) => a.data.userInternalId.localeCompare(b.data.userInternalId))
|
|
17
|
+
// Select only first 4 members
|
|
18
|
+
.slice(0, 4)
|
|
19
|
+
.map(({ data }) => channelMemberLinkedObject(data));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
5
23
|
return shallowClone(channel, {
|
|
6
24
|
markAsRead: () => markAsRead(channel.channelInternalId),
|
|
25
|
+
previewMembers,
|
|
7
26
|
});
|
|
8
27
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { pullFromCache } from '~/cache/api/pullFromCache';
|
|
2
|
+
import { userLinkedObject } from './userLinkedObject';
|
|
3
|
+
|
|
4
|
+
export const channelMemberLinkedObject = (
|
|
5
|
+
channelMember: Amity.Membership<'channel'>,
|
|
6
|
+
): Amity.Membership<'channel'> => {
|
|
7
|
+
const getUser = (): Amity.User | undefined => {
|
|
8
|
+
const cacheKey = ['user', 'get', channelMember.userId];
|
|
9
|
+
const internalUser = pullFromCache<Amity.InternalUser>(cacheKey)?.data;
|
|
10
|
+
|
|
11
|
+
return internalUser ? userLinkedObject(internalUser) : undefined;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
...channelMember,
|
|
16
|
+
get user() {
|
|
17
|
+
return getUser();
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
};
|
|
@@ -14,6 +14,7 @@ import { notificationTrayLinkedObject } from './notificationTrayLinkedObject';
|
|
|
14
14
|
import { communityLinkedObject } from './communityLinkedObject';
|
|
15
15
|
import { invitationLinkedObject } from './invitationLinkedObject';
|
|
16
16
|
import { joinRequestLinkedObject } from './joinRequestLinkedObject';
|
|
17
|
+
import { channelMemberLinkedObject } from './channelMemberLinkedObject';
|
|
17
18
|
|
|
18
19
|
export const LinkedObject = {
|
|
19
20
|
ad: adLinkedObject,
|
|
@@ -32,4 +33,5 @@ export const LinkedObject = {
|
|
|
32
33
|
community: communityLinkedObject,
|
|
33
34
|
invitation: invitationLinkedObject,
|
|
34
35
|
joinRequest: joinRequestLinkedObject,
|
|
36
|
+
channelMember: channelMemberLinkedObject,
|
|
35
37
|
};
|
|
@@ -22,8 +22,10 @@ export const invitationLinkedObject = (invitation: Amity.InternalInvitation): Am
|
|
|
22
22
|
'get',
|
|
23
23
|
invitation.targetId,
|
|
24
24
|
]);
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
return {
|
|
26
|
+
community: cacheData?.data,
|
|
27
|
+
communityId: invitation.communityId,
|
|
28
|
+
};
|
|
27
29
|
}
|
|
28
30
|
return undefined;
|
|
29
31
|
},
|