@amityco/ts-sdk 0.0.1-beta.43 → 0.0.1-beta.43.1
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/community/observers/liveCommunities.d.ts.map +1 -1
- package/dist/core/query/filtering.d.ts +11 -0
- package/dist/core/query/filtering.d.ts.map +1 -1
- package/dist/index.cjs.js +47 -15
- package/dist/index.esm.js +47 -16
- package/dist/index.umd.js +3 -3
- package/dist/message/api/queryMessages.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/community/observers/liveCommunities.ts +4 -7
- package/src/community/observers/tests/liveCommunities.test.ts +0 -87
- package/src/community/observers/tests/liveCommunity.test.ts +4 -4
- package/src/core/query/filtering.ts +41 -0
- package/src/core/query/query.ts +4 -4
- package/src/message/api/queryMessages.ts +7 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryMessages.d.ts","sourceRoot":"","sources":["../../../src/message/api/queryMessages.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"queryMessages.d.ts","sourceRoot":"","sources":["../../../src/message/api/queryMessages.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,aAAa;YACjB,MAAM,aAAa,GACzB,QAAQ,MAAM,MAAM,CAAC,MAAM,KAAK,CAAC,MAAM,OAAO,EAAE,MAAM,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAuCxE;;;;;;;;;;;;OAYG;mBAEM,WAAW,oBAAoB,CAAC,CAAC,CAAC,CAAC,GACzC,MAAM,MAAM,CAAC,MAAM,KAAK,CAAC,MAAM,OAAO,EAAE,MAAM,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,SAAS;CAlB1E,CAAC"}
|
package/package.json
CHANGED
|
@@ -5,6 +5,7 @@ import { getActiveClient } from '~/client/api';
|
|
|
5
5
|
import {
|
|
6
6
|
createQuery,
|
|
7
7
|
filterByPropEquality,
|
|
8
|
+
filterByCommunityMembership,
|
|
8
9
|
queryOptions,
|
|
9
10
|
runQuery,
|
|
10
11
|
sortByDisplayName,
|
|
@@ -51,7 +52,7 @@ export const liveCommunities = (
|
|
|
51
52
|
callback: Amity.LiveCollectionCallback<Amity.Community>,
|
|
52
53
|
config?: Amity.LiveCollectionConfig,
|
|
53
54
|
) => {
|
|
54
|
-
const { log, cache } = getActiveClient();
|
|
55
|
+
const { log, cache, userId } = getActiveClient();
|
|
55
56
|
|
|
56
57
|
if (!cache) {
|
|
57
58
|
console.log(ENABLE_CACHE_MESSAGE);
|
|
@@ -89,12 +90,8 @@ export const liveCommunities = (
|
|
|
89
90
|
communities = communities.filter(c => c.tags?.some(t => params.tags?.includes(t)));
|
|
90
91
|
}
|
|
91
92
|
|
|
92
|
-
if (params.membership
|
|
93
|
-
communities =
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (params.membership === 'notMember') {
|
|
97
|
-
communities = filterByPropEquality(communities, 'isJoined', false);
|
|
93
|
+
if (params.membership && userId) {
|
|
94
|
+
communities = filterByCommunityMembership(communities, params.membership, userId);
|
|
98
95
|
}
|
|
99
96
|
|
|
100
97
|
const sortBy = params.sortBy || 'lastCreated';
|
|
@@ -89,9 +89,6 @@ describe('liveCommunities', () => {
|
|
|
89
89
|
['categoryId', { categoryId: 'test-category-id' }, [community1]],
|
|
90
90
|
['displayName', { displayName: 'community 1' }, [community1]],
|
|
91
91
|
['tagged', { tags: ['test-community-tag'] }, [community1]],
|
|
92
|
-
['member', { membership: 'member' }, [community1]],
|
|
93
|
-
['not member', { membership: 'notMember' }, [community2]],
|
|
94
|
-
['all membership', { membership: 'all' }, [community1, community2]],
|
|
95
92
|
];
|
|
96
93
|
|
|
97
94
|
test.each(filters)('it should filter by %s communities', async (filter, params, expected) => {
|
|
@@ -216,89 +213,5 @@ describe('liveCommunities', () => {
|
|
|
216
213
|
),
|
|
217
214
|
);
|
|
218
215
|
});
|
|
219
|
-
|
|
220
|
-
const joinCommunityPayload = {
|
|
221
|
-
...communityQueryResponse.data.communities[0],
|
|
222
|
-
communityId: 'joining-community',
|
|
223
|
-
isDeleted: false,
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
const joinedCommunity = prepareCommunityPayload({
|
|
227
|
-
...emptyCommunityPayload,
|
|
228
|
-
communities: [joinCommunityPayload],
|
|
229
|
-
}).communities[0];
|
|
230
|
-
|
|
231
|
-
const joiningUser: Amity.RawMembership<'community'> = {
|
|
232
|
-
...communityUser11,
|
|
233
|
-
userId: 'test',
|
|
234
|
-
communityId: 'joining-community',
|
|
235
|
-
communityMembership: 'member',
|
|
236
|
-
};
|
|
237
|
-
|
|
238
|
-
const memberEvents: [
|
|
239
|
-
string,
|
|
240
|
-
Amity.CommunityLiveCollection,
|
|
241
|
-
keyof Amity.Events,
|
|
242
|
-
Amity.CommunityPayload,
|
|
243
|
-
Amity.Community[],
|
|
244
|
-
][] = [
|
|
245
|
-
[
|
|
246
|
-
'it should add new community to collection onJoin',
|
|
247
|
-
{ membership: 'member' },
|
|
248
|
-
'community.joined',
|
|
249
|
-
{
|
|
250
|
-
...emptyCommunityPayload,
|
|
251
|
-
communities: [joinCommunityPayload],
|
|
252
|
-
communityUsers: [joiningUser],
|
|
253
|
-
},
|
|
254
|
-
[joinedCommunity, community1],
|
|
255
|
-
],
|
|
256
|
-
[
|
|
257
|
-
'it should not add new member to community collection onJoin if membership:not member',
|
|
258
|
-
{ membership: 'notMember' },
|
|
259
|
-
'community.joined',
|
|
260
|
-
{
|
|
261
|
-
...emptyCommunityPayload,
|
|
262
|
-
communities: [joinCommunityPayload],
|
|
263
|
-
communityUsers: [joiningUser],
|
|
264
|
-
},
|
|
265
|
-
[],
|
|
266
|
-
],
|
|
267
|
-
[
|
|
268
|
-
'it should update community in collection onLeft',
|
|
269
|
-
{ membership: 'member' },
|
|
270
|
-
'community.left',
|
|
271
|
-
{ ...communityPayload, communities: [{ ...community1, isJoined: false }] },
|
|
272
|
-
[],
|
|
273
|
-
],
|
|
274
|
-
[
|
|
275
|
-
'it should add new community in collection onLeft and if membership:not member',
|
|
276
|
-
{ membership: 'notMember' },
|
|
277
|
-
'community.left',
|
|
278
|
-
{ ...communityPayload, communities: [{ ...community1, isJoined: false }] },
|
|
279
|
-
[{ ...community1, isJoined: false }],
|
|
280
|
-
],
|
|
281
|
-
];
|
|
282
|
-
|
|
283
|
-
test.each(memberEvents)('%s', async (test, params, event, communityPayload, expected) => {
|
|
284
|
-
const callback = jest.fn();
|
|
285
|
-
client.http.get = jest.fn().mockResolvedValue(communityQueryResponsePage2);
|
|
286
|
-
|
|
287
|
-
liveCommunities(params, callback);
|
|
288
|
-
await pause();
|
|
289
|
-
|
|
290
|
-
client.emitter.emit(event, communityPayload);
|
|
291
|
-
await pause();
|
|
292
|
-
|
|
293
|
-
expect(callback).toHaveBeenNthCalledWith(
|
|
294
|
-
3,
|
|
295
|
-
expect.objectContaining(
|
|
296
|
-
getSnapshot({
|
|
297
|
-
data: expected,
|
|
298
|
-
loading: false,
|
|
299
|
-
}),
|
|
300
|
-
),
|
|
301
|
-
);
|
|
302
|
-
});
|
|
303
216
|
});
|
|
304
217
|
});
|
|
@@ -81,10 +81,10 @@ describe('liveCommunity events', () => {
|
|
|
81
81
|
|
|
82
82
|
const communityUserEvents: [string, keyof Amity.MqttCommunityUserEvents][] = [
|
|
83
83
|
['it should add user on community.joined event', 'community.joined'],
|
|
84
|
-
['should get update on community.left event', 'community.left'],
|
|
85
|
-
['should get update on community.userChanged event', 'community.userChanged'],
|
|
86
|
-
['should get update on community.userBanned event', 'community.userBanned'],
|
|
87
|
-
['should get update on community.userUnbanned event', 'community.userUnbanned'],
|
|
84
|
+
['it should get update on community.left event', 'community.left'],
|
|
85
|
+
['it should get update on community.userChanged event', 'community.userChanged'],
|
|
86
|
+
['it should get update on community.userBanned event', 'community.userBanned'],
|
|
87
|
+
['it should get update on community.userUnbanned event', 'community.userUnbanned'],
|
|
88
88
|
];
|
|
89
89
|
|
|
90
90
|
test.each(communityUserEvents)('%s', async (test, event) => {
|
|
@@ -95,3 +95,44 @@ export const filterByFeedType = <T extends Amity.Post>(
|
|
|
95
95
|
return feed && feed.feedType === feedType;
|
|
96
96
|
});
|
|
97
97
|
};
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Filter a community collection by membership of the userId
|
|
101
|
+
*
|
|
102
|
+
* @param collection the community to filter
|
|
103
|
+
* @param membership the membership to be filtered by
|
|
104
|
+
* @param userId user id to be filtered by
|
|
105
|
+
* @returns a filtered collection with items only matching the criteria
|
|
106
|
+
*
|
|
107
|
+
* @hidden
|
|
108
|
+
*/
|
|
109
|
+
export const filterByCommunityMembership = <T extends Amity.Community>(
|
|
110
|
+
collection: T[],
|
|
111
|
+
membership: Amity.CommunityLiveCollection['membership'],
|
|
112
|
+
userId: Amity.Membership<'community'>['userId'],
|
|
113
|
+
): T[] => {
|
|
114
|
+
if (membership === 'all') {
|
|
115
|
+
return collection;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return collection.filter(c => {
|
|
119
|
+
// get resolver for the community by user
|
|
120
|
+
const communityUserCacheKey = getResolver('communityUsers')({
|
|
121
|
+
communityId: c.communityId,
|
|
122
|
+
userId,
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
const communityUser = pullFromCache<Amity.Membership<'community'>>([
|
|
126
|
+
'communityUsers',
|
|
127
|
+
'get',
|
|
128
|
+
communityUserCacheKey,
|
|
129
|
+
])?.data;
|
|
130
|
+
|
|
131
|
+
if (membership === 'member') {
|
|
132
|
+
return communityUser && communityUser.communityMembership === 'member';
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// only membership value remainging is 'notMember'
|
|
136
|
+
return !communityUser || communityUser.communityMembership !== 'none';
|
|
137
|
+
});
|
|
138
|
+
};
|
package/src/core/query/query.ts
CHANGED
|
@@ -165,11 +165,11 @@ export const runQuery = <Args extends any[], Returned extends any>(
|
|
|
165
165
|
callback?: (args: Amity.Snapshot<Returned>) => void,
|
|
166
166
|
options: Amity.QueryOptions = queryOptions('cache_then_server'),
|
|
167
167
|
) => {
|
|
168
|
-
console.
|
|
169
|
-
'Deprecation Notice:
|
|
168
|
+
console.info(
|
|
169
|
+
'Deprecation Notice: By Q3, CreateQuery/RunQuery will no longer be exported from the SDK. You will be able to use the API without either methods.',
|
|
170
170
|
);
|
|
171
|
-
console.
|
|
172
|
-
'Deprecation Notice:
|
|
171
|
+
console.info(
|
|
172
|
+
'Deprecation Notice: From v6.0.0, individual module imports will no longer be supported. All public APIs will need to be imported from their respective repositories. Ex: CommunityRepository, UserRepository, etc.',
|
|
173
173
|
);
|
|
174
174
|
|
|
175
175
|
let local: Returned | undefined;
|
|
@@ -2,9 +2,7 @@ import { getActiveClient } from '~/client/api';
|
|
|
2
2
|
|
|
3
3
|
import { fireEvent } from '~/core/events';
|
|
4
4
|
import { toPageRaw } from '~/core/query';
|
|
5
|
-
import { pullFromCache
|
|
6
|
-
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
7
|
-
import { getResolver } from '~/core/model';
|
|
5
|
+
import { pullFromCache } from '~/cache/api';
|
|
8
6
|
import { convertQueryParams, prepareMessagePayload } from '../utils';
|
|
9
7
|
|
|
10
8
|
/* begin_public_function
|
|
@@ -49,12 +47,12 @@ export const queryMessages = async (
|
|
|
49
47
|
|
|
50
48
|
const cachedAt = client.cache && Date.now();
|
|
51
49
|
|
|
52
|
-
if (client.cache) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
50
|
+
// if (client.cache) {
|
|
51
|
+
// ingestInCache(data, { cachedAt });
|
|
52
|
+
//
|
|
53
|
+
// const cacheKey = ['message', 'query', params as Amity.Serializable];
|
|
54
|
+
// pushToCache(cacheKey, { messages: messages.map(getResolver('message')), paging });
|
|
55
|
+
// }
|
|
58
56
|
|
|
59
57
|
fireEvent('local.message.fetched', { messages });
|
|
60
58
|
|