@amityco/ts-sdk-react-native 6.13.0 → 6.13.2

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.
Files changed (37) hide show
  1. package/dist/@types/core/paging.d.ts +3 -0
  2. package/dist/@types/core/paging.d.ts.map +1 -1
  3. package/dist/@types/domains/channel.d.ts +2 -1
  4. package/dist/@types/domains/channel.d.ts.map +1 -1
  5. package/dist/@types/domains/comment.d.ts +6 -2
  6. package/dist/@types/domains/comment.d.ts.map +1 -1
  7. package/dist/@types/domains/user.d.ts +2 -1
  8. package/dist/@types/domains/user.d.ts.map +1 -1
  9. package/dist/channelRepsitory/api/queryChannels.d.ts +1 -1
  10. package/dist/channelRepsitory/api/queryChannels.d.ts.map +1 -1
  11. package/dist/channelRepsitory/observers/getChannels.d.ts.map +1 -1
  12. package/dist/commentRepository/api/queryComments.d.ts +1 -1
  13. package/dist/commentRepository/api/queryComments.d.ts.map +1 -1
  14. package/dist/commentRepository/observers/getComments.d.ts.map +1 -1
  15. package/dist/index.cjs.js +65 -58
  16. package/dist/index.esm.js +65 -58
  17. package/dist/index.umd.js +2 -2
  18. package/dist/streamRepository/observers/getStreams.d.ts +1 -0
  19. package/dist/streamRepository/observers/getStreams.d.ts.map +1 -1
  20. package/dist/userRepository/api/queryUsers.d.ts +2 -2
  21. package/dist/userRepository/api/queryUsers.d.ts.map +1 -1
  22. package/dist/userRepository/observers/getUsers.d.ts.map +1 -1
  23. package/package.json +1 -1
  24. package/src/@types/core/paging.ts +2 -0
  25. package/src/@types/domains/channel.ts +2 -1
  26. package/src/@types/domains/comment.ts +3 -2
  27. package/src/@types/domains/user.ts +2 -1
  28. package/src/channelRepsitory/api/queryChannels.ts +6 -15
  29. package/src/channelRepsitory/observers/getChannels.ts +24 -21
  30. package/src/commentRepository/api/queryComments.ts +7 -15
  31. package/src/commentRepository/observers/getComments.ts +9 -5
  32. package/src/communityRepository/api/queryCommunities.ts +2 -2
  33. package/src/communityRepository/communityMembership/observers/tests/getMembers.test.ts +11 -11
  34. package/src/communityRepository/observers/getCommunities.ts +1 -1
  35. package/src/streamRepository/observers/getStreams.ts +6 -5
  36. package/src/userRepository/api/queryUsers.ts +27 -18
  37. package/src/userRepository/observers/getUsers.ts +9 -6
@@ -8,6 +8,7 @@
8
8
  *
9
9
  * @param params for querying streams
10
10
  * @param callback the function to call when new data are available
11
+ * @param config
11
12
  * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the streams
12
13
  *
13
14
  * @category Stream Live Collection
@@ -1 +1 @@
1
- {"version":3,"file":"getStreams.d.ts","sourceRoot":"","sources":["../../../src/streamRepository/observers/getStreams.ts"],"names":[],"mappings":"AA0BA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,UAAU,WACb,MAAM,oBAAoB,YACxB,MAAM,sBAAsB,CAAC,MAAM,MAAM,CAAC,WAC3C,MAAM,oBAAoB,eAyGpC,CAAC"}
1
+ {"version":3,"file":"getStreams.d.ts","sourceRoot":"","sources":["../../../src/streamRepository/observers/getStreams.ts"],"names":[],"mappings":"AA0BA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,UAAU,WACb,MAAM,oBAAoB,YACxB,MAAM,sBAAsB,CAAC,MAAM,MAAM,CAAC,WAC3C,MAAM,oBAAoB,eAyGpC,CAAC"}
@@ -14,7 +14,7 @@
14
14
  * @async
15
15
  */
16
16
  export declare const queryUsers: {
17
- (query?: Amity.QueryUsers): Promise<Amity.Cached<Amity.Paged<Amity.InternalUser>>>;
17
+ (query?: Amity.QueryUsers): Promise<Amity.Cached<Amity.PageToken<Amity.InternalUser>>>;
18
18
  /**
19
19
  * ```js
20
20
  * import { queryUsers } from '@amityco/ts-sdk-react-native'
@@ -29,6 +29,6 @@ export declare const queryUsers: {
29
29
  *
30
30
  * @category User API
31
31
  */
32
- locally(query?: Parameters<typeof queryUsers>[0]): Amity.Cached<Amity.Paged<Amity.InternalUser>> | undefined;
32
+ locally(query?: Parameters<typeof queryUsers>[0]): Amity.Cached<Amity.PageToken<Amity.InternalUser>> | undefined;
33
33
  };
34
34
  //# sourceMappingURL=queryUsers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"queryUsers.d.ts","sourceRoot":"","sources":["../../../src/userRepository/api/queryUsers.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,UAAU;aACd,MAAM,UAAU,GACtB,QAAQ,MAAM,MAAM,CAAC,MAAM,KAAK,CAAC,MAAM,YAAY,CAAC,CAAC,CAAC;IAiDzD;;;;;;;;;;;;;OAaG;oBAEM,WAAW,iBAAiB,CAAC,CAAC,CAAC,CAAC,GACtC,MAAM,MAAM,CAAC,MAAM,KAAK,CAAC,MAAM,YAAY,CAAC,CAAC,GAAG,SAAS;CAlB3D,CAAC"}
1
+ {"version":3,"file":"queryUsers.d.ts","sourceRoot":"","sources":["../../../src/userRepository/api/queryUsers.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,UAAU;aACd,MAAM,UAAU,GACtB,QAAQ,MAAM,MAAM,CAAC,MAAM,SAAS,CAAC,MAAM,YAAY,CAAC,CAAC,CAAC;IAwD7D;;;;;;;;;;;;;OAaG;oBAEM,WAAW,iBAAiB,CAAC,CAAC,CAAC,CAAC,GACtC,MAAM,MAAM,CAAC,MAAM,SAAS,CAAC,MAAM,YAAY,CAAC,CAAC,GAAG,SAAS;CAlB/D,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"getUsers.d.ts","sourceRoot":"","sources":["../../../src/userRepository/observers/getUsers.ts"],"names":[],"mappings":"AAoCA,eAAO,MAAM,WAAW,4CAEd,MAAM,kBAAkB,QAsBjC,CAAC;AAKF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,QAAQ,WACX,MAAM,kBAAkB,YACtB,MAAM,sBAAsB,CAAC,MAAM,IAAI,CAAC,WACzC,MAAM,oBAAoB,eAgGpC,CAAC"}
1
+ {"version":3,"file":"getUsers.d.ts","sourceRoot":"","sources":["../../../src/userRepository/observers/getUsers.ts"],"names":[],"mappings":"AAoCA,eAAO,MAAM,WAAW,4CAEd,MAAM,kBAAkB,QAsBjC,CAAC;AAKF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,QAAQ,WACX,MAAM,kBAAkB,YACtB,MAAM,sBAAsB,CAAC,MAAM,IAAI,CAAC,WACzC,MAAM,oBAAoB,eAmGpC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amityco/ts-sdk-react-native",
3
- "version": "6.13.0",
3
+ "version": "6.13.2",
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",
@@ -56,5 +56,7 @@ declare global {
56
56
  };
57
57
 
58
58
  type Paged<T, K extends Page | PageRaw = Page> = { data: T[] } & Pages<K>;
59
+
60
+ type PageToken<T> = { data: T[] } & Amity.Pagination;
59
61
  }
60
62
  }
@@ -92,7 +92,8 @@ declare global {
92
92
  isDeleted?: Amity.Channel['isDeleted'];
93
93
  tags?: Amity.Taggable['tags'];
94
94
  excludeTags?: Amity.Taggable['tags'];
95
- page?: Amity.Page;
95
+ limit?: number;
96
+ page?: string;
96
97
  };
97
98
 
98
99
  type ChannelLiveCollection = Amity.LiveCollectionParams<Omit<QueryChannels, 'page'>>;
@@ -57,7 +57,8 @@ declare global {
57
57
  parentId?: Amity.InternalComment['commentId'] | null;
58
58
  hasFlag?: boolean;
59
59
  includeDeleted?: boolean;
60
- page?: Amity.Page;
60
+ limit?: number;
61
+ page?: Amity.Token;
61
62
  dataTypes?: {
62
63
  values: ('image' | 'text')[];
63
64
  // matchType is a query format that you can set to any to query any type of comment
@@ -74,7 +75,7 @@ declare global {
74
75
 
75
76
  type CommentLiveCollectionCache = Amity.LiveCollectionCache<
76
77
  Amity.InternalComment['commentId'],
77
- Pick<QueryComments, 'page'>
78
+ { page?: Amity.Token | undefined; limit?: number }
78
79
  >;
79
80
  }
80
81
  }
@@ -34,7 +34,8 @@ declare global {
34
34
  displayName?: Amity.InternalUser['displayName'];
35
35
  filter?: 'all' | 'flagged';
36
36
  sortBy?: 'displayName' | 'firstCreated' | 'lastCreated';
37
- page?: Amity.Page;
37
+ limit?: number;
38
+ page?: string;
38
39
  };
39
40
 
40
41
  type UserLiveCollection = Amity.LiveCollectionParams<Omit<QueryUsers, 'page'>>;
@@ -1,9 +1,7 @@
1
1
  import { getActiveClient } from '~/client/api';
2
-
3
- import { toPage, toToken } from '~/core/query';
4
2
  import { getResolver } from '~/core/model';
5
3
 
6
- import { pullFromCache, pushToCache } from '~/cache/api';
4
+ import { pushToCache } from '~/cache/api';
7
5
  import { ingestInCache } from '~/cache/api/ingestInCache';
8
6
 
9
7
  import { prepareChannelPayload } from '../utils';
@@ -25,12 +23,12 @@ import { prepareChannelPayload } from '../utils';
25
23
  */
26
24
  export const queryChannels = async (
27
25
  query?: Amity.QueryChannels,
28
- ): Promise<Amity.Cached<Amity.Paged<Amity.InternalChannel>>> => {
26
+ ): Promise<Amity.Cached<Amity.PageToken<Amity.InternalChannel>>> => {
29
27
  const client = getActiveClient();
30
28
  client.log('channel/queryChannels', query);
31
29
 
32
30
  // safe decapsulation
33
- const { page = { limit: 10 }, displayName, membership, ...params } = query ?? {};
31
+ const { page = undefined, limit = 10, displayName, membership, ...params } = query ?? {};
34
32
 
35
33
  // API-FIX: parameters should be querystring.
36
34
  // API-FIX: backend doesn't answer Amity.Response
@@ -43,7 +41,7 @@ export const queryChannels = async (
43
41
  keyword: displayName,
44
42
  filter: membership,
45
43
  options: {
46
- token: toToken(page, 'skiplimit'),
44
+ token: page,
47
45
  },
48
46
  },
49
47
  },
@@ -60,16 +58,9 @@ export const queryChannels = async (
60
58
  if (client.cache) {
61
59
  ingestInCache(data, { cachedAt });
62
60
 
63
- const cacheKey = [
64
- 'channel',
65
- 'query',
66
- { ...params, options: { ...page } } as Amity.Serializable,
67
- ];
61
+ const cacheKey = ['channel', 'query', { ...params, options: { limit } } as Amity.Serializable];
68
62
  pushToCache(cacheKey, { channels: channels.map(getResolver('channel')), paging });
69
63
  }
70
64
 
71
- const nextPage = toPage(paging.next);
72
- const prevPage = toPage(paging.previous);
73
-
74
- return { data: channels, cachedAt, prevPage, nextPage };
65
+ return { data: channels, cachedAt, paging };
75
66
  };
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable no-use-before-define */
2
2
  import { getResolver } from '~/core/model';
3
- import { dropFromCache, pullFromCache, pushToCache, upsertInCache } from '~/cache/api';
3
+ import { dropFromCache, pullFromCache, pushToCache } from '~/cache/api';
4
4
  import { getActiveClient } from '~/client/api';
5
5
  import {
6
6
  createQuery,
@@ -22,32 +22,32 @@ import {
22
22
  import { CACHE_SHORTEN_LIFESPAN } from '~/cache/utils';
23
23
  import { convertEventPayload } from '~/utils/event';
24
24
  import { uuid } from '~/core/uuid';
25
- import {
26
- onChannelCreated,
27
- onChannelDeleted,
28
- onChannelJoined,
29
- onChannelLeft,
30
- onChannelMemberAdded,
31
- onChannelMemberRemoved,
32
- onChannelMuted,
33
- onChannelUpdated,
34
- } from '../events';
35
- import { queryChannels } from '../api/queryChannels';
36
- import { getChannelMessagePreview } from '../../messagePreview/utils/getChannelMessagePreview';
37
25
  import { onMessageCreated } from '~/messageRepository/events/onMessageCreated';
38
26
  import { onMessageUpdated } from '~/messageRepository/events/onMessageUpdated';
39
27
  import { onMessageDeleted } from '~/messageRepository/events/onMessageDeleted';
40
28
  import { onSubChannelUpdated } from '~/subChannelRepository/events/onSubChannelUpdated';
41
29
  import { onSubChannelDeleted } from '~/subChannelRepository/events/onSubChannelDeleted';
42
- import { getChannel } from '../api/getChannel';
43
- import { getChannelMessagePreviewWithUser } from '../../messagePreview/utils/getChannelMessagePreviewWithUser';
44
30
  import {
45
31
  handleMessageCreated,
46
32
  handleMessageUpdated,
47
33
  handleSubChannelUpdated,
48
34
  } from '~/messagePreview/utils/updateMessagePreviewFromMessage';
49
- import { updateChannelCache } from '../utils/updateChannelCache';
50
35
  import { onChannelMarkerUpdated } from '~/marker/events/onChannelMarkerUpdated';
36
+ import { getChannel } from '../api/getChannel';
37
+ import { getChannelMessagePreviewWithUser } from '../../messagePreview/utils/getChannelMessagePreviewWithUser';
38
+ import { updateChannelCache } from '../utils/updateChannelCache';
39
+ import { getChannelMessagePreview } from '../../messagePreview/utils/getChannelMessagePreview';
40
+ import {
41
+ onChannelCreated,
42
+ onChannelDeleted,
43
+ onChannelJoined,
44
+ onChannelLeft,
45
+ onChannelMemberAdded,
46
+ onChannelMemberRemoved,
47
+ onChannelMuted,
48
+ onChannelUpdated,
49
+ } from '../events';
50
+ import { queryChannels } from '../api/queryChannels';
51
51
 
52
52
  /* begin_public_function
53
53
  id: channel.query
@@ -132,7 +132,7 @@ export const getChannels = (
132
132
  case 'displayName':
133
133
  /*
134
134
  * The server returns channels with empty | null displayName's first before
135
- * returning sorted list of channels with displayNames
135
+ * returning a sorted list of channels with displayNames
136
136
  *
137
137
  * This section needs to be updated as displayNames can be null as well
138
138
  */
@@ -176,21 +176,24 @@ export const getChannels = (
176
176
 
177
177
  const query = createQuery(queryChannels, {
178
178
  ...queryParams,
179
- page: (!initial ? collection?.params.page : undefined) ?? { limit },
179
+ page: !initial ? collection?.params.page : undefined,
180
+ limit,
180
181
  });
181
182
 
182
183
  runQuery(
183
184
  query,
184
- ({ data: result, error, loading, nextPage: page }) => {
185
+ ({ data: result, error, loading, paging }) => {
185
186
  const data = {
186
187
  loading,
187
188
  error,
188
- params: { page },
189
+ params: { page: paging?.next },
189
190
  data: channels,
190
191
  };
191
192
 
192
193
  if (result) {
193
- data.data = [...new Set([...channels, ...result.map(getResolver('channel'))])];
194
+ data.data = initial
195
+ ? result.map(getResolver('channel')) // Replace all collection from BE when initial fetch
196
+ : [...new Set([...channels, ...result.map(getResolver('channel'))])];
194
197
  }
195
198
 
196
199
  pushToCache(cacheKey, data);
@@ -1,6 +1,4 @@
1
1
  import { getActiveClient } from '~/client/api';
2
-
3
- import { toPage, toToken } from '~/core/query';
4
2
  import { pushToCache } from '~/cache/api';
5
3
  import { ingestInCache } from '~/cache/api/ingestInCache';
6
4
  import { getResolver } from '~/core/model';
@@ -23,15 +21,16 @@ import { inferIsDeleted } from '~/utils/inferIsDeleted';
23
21
  */
24
22
  export const queryComments = async (
25
23
  query: Amity.QueryComments,
26
- ): Promise<Amity.Cached<Amity.Paged<Amity.InternalComment>>> => {
24
+ ): Promise<Amity.Cached<Amity.PageToken<Amity.InternalComment>>> => {
27
25
  const client = getActiveClient();
28
26
  client.log('comment/queryComments', query);
29
27
 
30
- const { page = { limit: 10 }, includeDeleted, ...params } = query;
28
+ const { limit = 10, includeDeleted, ...params } = query;
31
29
 
32
30
  const options = {
33
- type: params.sortBy || query.page?.limit ? 'pagination' : undefined,
34
- token: toToken(page, params.sortBy ? 'skiplimit' : 'afterbefore'),
31
+ type: params.sortBy || query.limit ? 'pagination' : undefined,
32
+ limit: query.limit,
33
+ token: query.page,
35
34
  };
36
35
  // const filterByParentId = query.parentId !== undefined
37
36
 
@@ -60,16 +59,9 @@ export const queryComments = async (
60
59
  if (client.cache) {
61
60
  ingestInCache(payload as Amity.CommentPayload, { cachedAt });
62
61
 
63
- const cacheKey = [
64
- 'comment',
65
- 'query',
66
- { ...params, options: { ...page } } as Amity.Serializable,
67
- ];
62
+ const cacheKey = ['comment', 'query', { ...params, options: { limit } } as Amity.Serializable];
68
63
  pushToCache(cacheKey, { comments: comments.map(getResolver('comment')), paging });
69
64
  }
70
65
 
71
- const nextPage = toPage(paging.next);
72
- const prevPage = toPage(paging.previous);
73
-
74
- return { data: comments, cachedAt, prevPage, nextPage };
66
+ return { data: comments, cachedAt, paging };
75
67
  };
@@ -139,14 +139,16 @@ export const getComments = (
139
139
 
140
140
  const query = createQuery(queryComments, {
141
141
  ...queryParams,
142
- page: (!initial ? collection?.params.page : undefined) ?? { limit },
142
+ limit: queryLimit,
143
+ page: !initial ? collection?.params.page : undefined,
143
144
  });
144
145
 
145
146
  runQuery(
146
147
  query,
147
- ({ data: result, error, loading, prevPage, nextPage }) => {
148
- // depend on sortBy value we have two different pagination type
149
- const page = queryParams.sortBy || params?.limit ? nextPage : prevPage;
148
+ ({ data: result, error, loading, paging }) => {
149
+ // depend on sortBy value we have two different pagination types
150
+ const sorting = queryParams.sortBy || 'lastCreated';
151
+ const page = sorting === 'lastCreated' ? paging?.next : paging?.previous;
150
152
 
151
153
  const data = {
152
154
  loading,
@@ -156,7 +158,9 @@ export const getComments = (
156
158
  };
157
159
 
158
160
  if (result) {
159
- data.data = [...new Set([...comments, ...result.map(getResolver('comment'))])];
161
+ data.data = initial
162
+ ? result.map(getResolver('comment')) // Replace a collection list with new data from BE
163
+ : [...new Set([...comments, ...result.map(getResolver('comment'))])];
160
164
  }
161
165
 
162
166
  pushToCache(cacheKey, data);
@@ -30,11 +30,11 @@ export const queryCommunities = async (
30
30
  client.log('channel/queryCommunities', query);
31
31
 
32
32
  // safe decapsulation
33
- const { page, ...params } = query ?? {};
33
+ const { page = { limit: 10 }, ...params } = query ?? {};
34
34
  const { displayName, membership, includeDeleted, ...restParams } = params ?? {};
35
35
 
36
36
  // API-FIX: parameters should be querystring.
37
- // API-FIX: backend doesnt answer Amity.Response
37
+ // API-FIX: backend doesn't answer Amity.Response
38
38
  // const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<CommunityPayload>>>(
39
39
  const { data } = await client.http.get<Amity.CommunityPayload & Amity.Pagination>(
40
40
  `/api/v3/communities`,
@@ -1,22 +1,22 @@
1
1
  import { getPastDate } from '~/core/model';
2
2
  import { disableCache, enableCache } from '~/cache/api';
3
3
  import {
4
+ bannedCommunityUser,
4
5
  client,
5
- connectClient,
6
- disconnectClient,
7
- pause,
8
- user11,
9
- user13,
10
6
  community11,
11
7
  communityUser11,
12
8
  communityUser13,
13
- withRoleCommunityUser,
14
- bannedCommunityUser,
15
9
  communityUserQueryResponse,
16
10
  communityUserQueryResponsePage2,
11
+ connectClient,
17
12
  convertedCommunityUser1,
18
13
  convertedCommunityUser2,
19
14
  convertedCommunityUser3,
15
+ disconnectClient,
16
+ pause,
17
+ user11,
18
+ user13,
19
+ withRoleCommunityUser,
20
20
  } from '~/utils/tests';
21
21
 
22
22
  // makes it easier to spy on applyFilter
@@ -220,14 +220,14 @@ describe('getMembers > applyFilter', () => {
220
220
  ][] = [
221
221
  ['it should filter by roles', { communityId, roles: ['test-role'] }, [m1, m2], [m1]],
222
222
  [
223
- 'it should filter by membership:member',
224
- { communityId, membership: ['member'] },
223
+ 'it should filter by memberships: member',
224
+ { communityId, memberships: ['member'] },
225
225
  [m1, m2],
226
226
  [m1],
227
227
  ],
228
228
  [
229
- 'it should filter by membership:banned',
230
- { communityId, membership: ['banned'] },
229
+ 'it should filter by memberships: banned',
230
+ { communityId, memberships: ['banned'] },
231
231
  [m1, m2],
232
232
  [m2],
233
233
  ],
@@ -148,7 +148,7 @@ export const getCommunities = (
148
148
 
149
149
  const query = createQuery(queryCommunities, {
150
150
  ...queryParams,
151
- page: (!initial ? collection?.params.page : undefined) ?? { limit },
151
+ page: !initial ? collection?.params.page : { limit },
152
152
  });
153
153
 
154
154
  runQuery(
@@ -5,11 +5,11 @@ import { getActiveClient } from '~/client/api';
5
5
 
6
6
  import {
7
7
  createQuery,
8
- runQuery,
9
- queryOptions,
10
8
  filterByPropEquality,
11
- sortByLastCreated,
9
+ queryOptions,
10
+ runQuery,
12
11
  sortByFirstCreated,
12
+ sortByLastCreated,
13
13
  } from '~/core/query';
14
14
 
15
15
  import {
@@ -34,6 +34,7 @@ import { onStreamRecorded, onStreamStarted, onStreamStopped } from '../events';
34
34
  *
35
35
  * @param params for querying streams
36
36
  * @param callback the function to call when new data are available
37
+ * @param config
37
38
  * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the streams
38
39
  *
39
40
  * @category Stream Live Collection
@@ -70,7 +71,7 @@ export const getStreams = (
70
71
  return streams;
71
72
  };
72
73
 
73
- const responder = (data: Amity.UserLiveCollectionCache, isEventModel = false) => {
74
+ const responder = (data: Amity.StreamLiveCollectionCache, isEventModel = false) => {
74
75
  const streams: Amity.Stream[] =
75
76
  data.data
76
77
  .map(streamId => {
@@ -102,7 +103,7 @@ export const getStreams = (
102
103
  };
103
104
 
104
105
  const onFetch = (initial = false) => {
105
- const collection = pullFromCache<Amity.UserLiveCollectionCache>(cacheKey)?.data;
106
+ const collection = pullFromCache<Amity.StreamLiveCollectionCache>(cacheKey)?.data;
106
107
 
107
108
  const streams = collection?.data ?? [];
108
109
 
@@ -1,7 +1,5 @@
1
1
  import { getActiveClient } from '~/client/api';
2
2
 
3
- import { toPage, toToken } from '~/core/query';
4
-
5
3
  import { pullFromCache, pushToCache } from '~/cache/api';
6
4
  import { ingestInCache } from '~/cache/api/ingestInCache';
7
5
  import { getResolver } from '~/core/model';
@@ -25,12 +23,13 @@ import { LinkedObject } from '~/utils/linkedObject';
25
23
  */
26
24
  export const queryUsers = async (
27
25
  query: Amity.QueryUsers = {},
28
- ): Promise<Amity.Cached<Amity.Paged<Amity.InternalUser>>> => {
26
+ ): Promise<Amity.Cached<Amity.PageToken<Amity.InternalUser>>> => {
29
27
  const client = getActiveClient();
30
28
  client.log('user/queryUsers', query);
31
29
 
32
30
  const {
33
- page = { limit: 10 },
31
+ page,
32
+ limit = 10,
34
33
  displayName,
35
34
  filter = 'all',
36
35
  sortBy = 'displayName',
@@ -44,7 +43,8 @@ export const queryUsers = async (
44
43
  filter,
45
44
  sortBy,
46
45
  options: {
47
- token: toToken(page, 'skiplimit'),
46
+ token: page,
47
+ limit,
48
48
  },
49
49
  },
50
50
  });
@@ -59,19 +59,24 @@ export const queryUsers = async (
59
59
  ingestInCache(payload as Amity.UserPayload, { cachedAt });
60
60
 
61
61
  /*
62
- * using query as cache key over params because if the keyword, filter, sort
62
+ * using a query as a cache key over params because if the keyword, filter, sort
63
63
  * change the API will NOT cache results, when it should
64
64
  */
65
- const cacheKey = ['user', 'query', { ...query, options: { ...page } } as Amity.Serializable];
65
+ const cacheKey = [
66
+ 'user',
67
+ 'query',
68
+ { ...query, options: { limit, token: page } } as Amity.Serializable,
69
+ ];
66
70
  pushToCache(cacheKey, { users: users.map(getResolver('user')), paging });
67
71
  }
68
72
 
69
73
  fireEvent('user.fetched', data);
70
74
 
71
- const prevPage = toPage(paging.previous);
72
- const nextPage = toPage(paging.next);
73
-
74
- return { data: users.map(user => LinkedObject.user(user)), cachedAt, prevPage, nextPage };
75
+ return {
76
+ data: users.map(user => LinkedObject.user(user)),
77
+ cachedAt,
78
+ paging,
79
+ };
75
80
  };
76
81
 
77
82
  /**
@@ -90,20 +95,23 @@ export const queryUsers = async (
90
95
  */
91
96
  queryUsers.locally = (
92
97
  query: Parameters<typeof queryUsers>[0] = {},
93
- ): Amity.Cached<Amity.Paged<Amity.InternalUser>> | undefined => {
98
+ ): Amity.Cached<Amity.PageToken<Amity.InternalUser>> | undefined => {
94
99
  const client = getActiveClient();
95
100
  client.log('user/queryUsers.locally', query);
96
101
 
97
102
  if (!client.cache) return;
98
103
 
99
- const { page = { limit: 10 } } = query ?? {};
104
+ const { limit = 10, page } = query ?? {};
100
105
 
101
106
  const cacheKey = [
102
107
  'user',
103
108
  'query',
104
109
  {
105
110
  ...query,
106
- options: { ...page },
111
+ options: {
112
+ limit,
113
+ token: page,
114
+ },
107
115
  } as Amity.Serializable,
108
116
  ];
109
117
 
@@ -117,10 +125,11 @@ queryUsers.locally = (
117
125
  .filter(Boolean)
118
126
  .map(({ data }) => data) ?? [];
119
127
 
120
- const prevPage = toPage(data?.paging.previous);
121
- const nextPage = toPage(data?.paging.next);
122
-
123
128
  return users.length > 0 && users.length === data?.users?.length
124
- ? { data: users, cachedAt, prevPage, nextPage }
129
+ ? {
130
+ data: users.map(LinkedObject.user),
131
+ cachedAt,
132
+ paging: data?.paging,
133
+ }
125
134
  : undefined;
126
135
  };
@@ -20,6 +20,7 @@ import {
20
20
  ENABLE_CACHE_MESSAGE,
21
21
  } from '~/utils/constants';
22
22
 
23
+ import { LinkedObject } from '~/utils/linkedObject';
23
24
  import { queryUsers } from '../api/queryUsers';
24
25
  import {
25
26
  onUserDeleted,
@@ -28,7 +29,6 @@ import {
28
29
  onUserUnflagged,
29
30
  onUserUpdated,
30
31
  } from '../events';
31
- import { LinkedObject } from '~/utils/linkedObject';
32
32
 
33
33
  /*
34
34
  * Exported for testing
@@ -122,7 +122,7 @@ export const getUsers = (
122
122
  };
123
123
 
124
124
  const realtimeRouter = (_: Amity.UserActionType) => (user: Amity.User) => {
125
- const collection = pullFromCache<Amity.CommunityLiveCollectionCache>(cacheKey)?.data;
125
+ const collection = pullFromCache<Amity.UserLiveCollectionCache>(cacheKey)?.data;
126
126
  if (!collection) return;
127
127
 
128
128
  collection.data = [...new Set([user.userId, ...collection.data])];
@@ -139,21 +139,24 @@ export const getUsers = (
139
139
 
140
140
  const query = createQuery(queryUsers, {
141
141
  ...queryParams,
142
- page: (!initial ? collection?.params.page : undefined) ?? { limit },
142
+ limit,
143
+ page: !initial ? collection?.params.page : undefined,
143
144
  });
144
145
 
145
146
  runQuery(
146
147
  query,
147
- ({ data: result, error, loading, nextPage: page }) => {
148
+ ({ data: result, error, loading, paging }) => {
148
149
  const data = {
149
150
  loading,
150
151
  error,
151
- params: { page },
152
+ params: { page: paging?.next },
152
153
  data: users,
153
154
  };
154
155
 
155
156
  if (result) {
156
- data.data = [...new Set([...users, ...result.map(getResolver('user'))])];
157
+ data.data = initial
158
+ ? result.map(getResolver('user'))
159
+ : [...new Set([...users, ...result.map(getResolver('user'))])];
157
160
  }
158
161
 
159
162
  pushToCache(cacheKey, data);