@amityco/ts-sdk 0.0.1-beta.43.1 → 0.0.1-beta.45.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.
Files changed (53) hide show
  1. package/dist/category/api/queryCategories.d.ts.map +1 -1
  2. package/dist/comment/api/queryComments.d.ts.map +1 -1
  3. package/dist/community/api/queryCommunities.d.ts.map +1 -1
  4. package/dist/core/query/filtering.d.ts +10 -0
  5. package/dist/core/query/filtering.d.ts.map +1 -1
  6. package/dist/index.cjs.js +136 -114
  7. package/dist/index.esm.js +136 -115
  8. package/dist/index.umd.js +4 -4
  9. package/dist/message/api/queryMessages.d.ts +1 -17
  10. package/dist/message/api/queryMessages.d.ts.map +1 -1
  11. package/dist/message/utils/prepareMessagePayload.d.ts.map +1 -1
  12. package/dist/post/api/queryPosts.d.ts.map +1 -1
  13. package/dist/post/observers/livePosts.d.ts.map +1 -1
  14. package/dist/subChannel/api/querySubChannels.d.ts.map +1 -1
  15. package/dist/utils/inferIsDeleted.d.ts +2 -0
  16. package/dist/utils/inferIsDeleted.d.ts.map +1 -0
  17. package/dist/utils/tests/inferIsDeleted.test.d.ts +2 -0
  18. package/dist/utils/tests/inferIsDeleted.test.d.ts.map +1 -0
  19. package/package.json +1 -1
  20. package/src/category/api/queryCategories.ts +3 -1
  21. package/src/category/observers/liveCategories.ts +5 -5
  22. package/src/category/observers/tests/liveCategories.test.ts +7 -5
  23. package/src/channel/api/tests/removeChannelMembers.test.ts +3 -4
  24. package/src/channel/observers/liveChannelMembers.ts +4 -4
  25. package/src/channel/observers/liveChannels.ts +4 -4
  26. package/src/channel/observers/tests/liveChannels.test.ts +9 -15
  27. package/src/client/api/connectClient.ts +1 -1
  28. package/src/comment/api/queryComments.ts +3 -1
  29. package/src/comment/observers/liveComments.ts +5 -5
  30. package/src/community/api/queryCommunities.ts +2 -1
  31. package/src/community/api/test/queryCommunity.test.ts +2 -2
  32. package/src/community/observers/liveCommunities.ts +5 -5
  33. package/src/community/observers/liveCommunityMembers.ts +4 -4
  34. package/src/community/observers/tests/liveCommunities.test.ts +7 -7
  35. package/src/core/query/filtering.ts +38 -0
  36. package/src/follow/observers/liveFollowers.ts +4 -4
  37. package/src/follow/observers/liveFollowings.ts +4 -4
  38. package/src/message/api/queryMessages.ts +15 -50
  39. package/src/message/api/tests/queryMessages.test.ts +2 -37
  40. package/src/message/observers/liveMessages.ts +7 -7
  41. package/src/message/tests/observers/liveMessage.test.ts +1 -1
  42. package/src/message/tests/observers/liveMessages.test.ts +1 -1
  43. package/src/message/utils/prepareMessagePayload.ts +3 -1
  44. package/src/post/api/queryPosts.ts +3 -1
  45. package/src/post/observers/livePosts.ts +11 -6
  46. package/src/post/observers/tests/livePosts.test.ts +10 -4
  47. package/src/reaction/observers/liveReactions.ts +4 -4
  48. package/src/subChannel/api/querySubChannels.ts +3 -1
  49. package/src/subChannel/observers/liveSubChannels.ts +1 -1
  50. package/src/user/observers/liveUsers.ts +4 -4
  51. package/src/user/observers/tests/liveUsers.test.ts +3 -9
  52. package/src/utils/inferIsDeleted.ts +16 -0
  53. package/src/utils/tests/inferIsDeleted.test.ts +15 -0
@@ -12,21 +12,5 @@
12
12
  * @category Message API
13
13
  * @async
14
14
  */
15
- export declare const queryMessages: {
16
- (query: Amity.QueryMessages): Promise<Amity.Cached<Amity.Paged<Amity.Message, Amity.Page<string>>>>;
17
- /**
18
- * ```js
19
- * import { queryMessages } from '@amityco/ts-sdk'
20
- * const messages = queryMessages.locally!({ channelId })
21
- * ```
22
- *
23
- * Queries a paginable list of {@link Amity.Message} objects from cache
24
- *
25
- * @param query The query parameters
26
- * @returns A page of {@link Amity.Message} objects
27
- *
28
- * @category Message API
29
- */
30
- locally(query: Parameters<typeof queryMessages>[0]): Amity.Cached<Amity.Paged<Amity.Message, Amity.Page<string>>> | undefined;
31
- };
15
+ export declare const queryMessages: (query: Amity.QueryMessages) => Promise<Amity.Cached<Amity.Paged<Amity.Message, Amity.Page<string>>>>;
32
16
  //# sourceMappingURL=queryMessages.d.ts.map
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"queryMessages.d.ts","sourceRoot":"","sources":["../../../src/message/api/queryMessages.ts"],"names":[],"mappings":"AAYA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,aAAa,UACjB,MAAM,aAAa,KACzB,QAAQ,MAAM,MAAM,CAAC,MAAM,KAAK,CAAC,MAAM,OAAO,EAAE,MAAM,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CA0CtE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"prepareMessagePayload.d.ts","sourceRoot":"","sources":["../../../src/message/utils/prepareMessagePayload.ts"],"names":[],"mappings":"AA0BA,wBAAgB,cAAc,CAC5B,OAAO,EAAE,KAAK,CAAC,UAAU,EACzB,MAAM,CAAC,EAAE,KAAK,CAAC,aAAa,GAC3B,KAAK,CAAC,OAAO,CA8Df;AAED,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,KAAK,CAAC,OAAO,EACtB,MAAM,CAAC,EAAE,KAAK,CAAC,aAAa,GAC3B,KAAK,CAAC,OAAO,CASf;AAED,eAAO,MAAM,qBAAqB,YACvB,MAAM,cAAc,KAC5B,QAAQ,MAAM,uBAAuB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E,CAAC"}
1
+ {"version":3,"file":"queryPosts.d.ts","sourceRoot":"","sources":["../../../src/post/api/queryPosts.ts"],"names":[],"mappings":"AAcA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,UAAU;YACd,MAAM,UAAU,GACtB,QAAQ,MAAM,MAAM,CAAC,MAAM,KAAK,CAAC,MAAM,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC;IAmDhE;;;;;;;;;;;;OAYG;mBAEM,WAAW,iBAAiB,CAAC,CAAC,CAAC,CAAC,GACtC,MAAM,MAAM,CAAC,MAAM,KAAK,CAAC,MAAM,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,GAAG,SAAS;CAlBlE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"livePosts.d.ts","sourceRoot":"","sources":["../../../src/post/observers/livePosts.ts"],"names":[],"mappings":"AAmCA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,SAAS,WACZ,MAAM,kBAAkB,YACtB,MAAM,sBAAsB,CAAC,MAAM,IAAI,CAAC,WACzC,MAAM,oBAAoB,KAClC,MAAM,YAgIR,CAAC"}
1
+ {"version":3,"file":"livePosts.d.ts","sourceRoot":"","sources":["../../../src/post/observers/livePosts.ts"],"names":[],"mappings":"AAoCA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,SAAS,WACZ,MAAM,kBAAkB,YACtB,MAAM,sBAAsB,CAAC,MAAM,IAAI,CAAC,WACzC,MAAM,oBAAoB,KAClC,MAAM,YAoIR,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"querySubChannels.d.ts","sourceRoot":"","sources":["../../../src/subChannel/api/querySubChannels.ts"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gBAAgB;YACpB,MAAM,gBAAgB,GAC5B,QAAQ,MAAM,MAAM,CAAC,MAAM,KAAK,CAAC,MAAM,UAAU,CAAC,CAAC,CAAC;IA4CvD;;;;;;;;;;;;OAYG;mBAEM,WAAW,uBAAuB,CAAC,CAAC,CAAC,CAAC,GAC5C,MAAM,MAAM,CAAC,MAAM,KAAK,CAAC,MAAM,UAAU,CAAC,CAAC,GAAG,SAAS;CAlBzD,CAAC"}
1
+ {"version":3,"file":"querySubChannels.d.ts","sourceRoot":"","sources":["../../../src/subChannel/api/querySubChannels.ts"],"names":[],"mappings":"AAaA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gBAAgB;YACpB,MAAM,gBAAgB,GAC5B,QAAQ,MAAM,MAAM,CAAC,MAAM,KAAK,CAAC,MAAM,UAAU,CAAC,CAAC,CAAC;IA4CvD;;;;;;;;;;;;OAYG;mBAEM,WAAW,uBAAuB,CAAC,CAAC,CAAC,CAAC,GAC5C,MAAM,MAAM,CAAC,MAAM,KAAK,CAAC,MAAM,UAAU,CAAC,CAAC,GAAG,SAAS;CAlBzD,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const inferIsDeleted: (includeDeleted?: boolean) => boolean | undefined;
2
+ //# sourceMappingURL=inferIsDeleted.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inferIsDeleted.d.ts","sourceRoot":"","sources":["../../src/utils/inferIsDeleted.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,cAAc,oBAAqB,OAAO,KAAG,OAAO,GAAG,SACvB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=inferIsDeleted.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inferIsDeleted.test.d.ts","sourceRoot":"","sources":["../../../src/utils/tests/inferIsDeleted.test.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amityco/ts-sdk",
3
- "version": "0.0.1-beta.43.1",
3
+ "version": "0.0.1-beta.45.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",
@@ -6,6 +6,8 @@ import { pullFromCache, pushToCache } from '~/cache/api';
6
6
  import { ingestInCache } from '~/cache/api/ingestInCache';
7
7
  import { getResolver } from '~/core/model';
8
8
 
9
+ import { inferIsDeleted } from '~/utils/inferIsDeleted';
10
+
9
11
  /* begin_public_function
10
12
  id: community.category.query
11
13
  */
@@ -36,7 +38,7 @@ export const queryCategories = async (
36
38
  {
37
39
  params: {
38
40
  ...params,
39
- isDeleted: includeDeleted === false ? false : undefined,
41
+ isDeleted: inferIsDeleted(includeDeleted),
40
42
  options: {
41
43
  token: toToken(page, 'skiplimit'),
42
44
  },
@@ -63,7 +63,7 @@ export const liveCategories = (
63
63
  .filter(Boolean)
64
64
  .map(({ data }) => data) ?? [];
65
65
 
66
- if (params.includeDeleted === false) {
66
+ if (!params.includeDeleted) {
67
67
  categories = filterByPropEquality(categories, 'isDeleted', false);
68
68
  }
69
69
 
@@ -96,16 +96,16 @@ export const liveCategories = (
96
96
  *};
97
97
  */
98
98
 
99
- const onFetch = () => {
99
+ const onFetch = (initial = false) => {
100
100
  const collection = pullFromCache<Amity.CategoryLiveCollectionCache>(cacheKey)?.data;
101
101
 
102
102
  const categories = collection?.data ?? [];
103
103
 
104
- if (categories.length > 0 && !collection?.params.page) return;
104
+ if (!initial && categories.length > 0 && !collection?.params.page) return;
105
105
 
106
106
  const query = createQuery(queryCategories, {
107
107
  ...queryParams,
108
- page: collection?.params.page ?? { limit },
108
+ page: (!initial ? collection?.params.page : undefined) ?? { limit },
109
109
  });
110
110
 
111
111
  runQuery(
@@ -134,7 +134,7 @@ export const liveCategories = (
134
134
  // @TODO -> update once observers added
135
135
  });
136
136
 
137
- onFetch();
137
+ onFetch(true);
138
138
 
139
139
  return () => {
140
140
  log(`liveCategories(tmpid: ${timestamp}) > dispose`);
@@ -22,7 +22,9 @@ const getSnapshot = (params?: Record<string, any>) => {
22
22
  };
23
23
  };
24
24
 
25
- describe('live Caategories', () => {
25
+ const params = { includeDeleted: true };
26
+
27
+ describe('live Categories', () => {
26
28
  beforeAll(connectClient);
27
29
  afterAll(disconnectClient);
28
30
 
@@ -37,7 +39,7 @@ describe('live Caategories', () => {
37
39
  const callback = jest.fn();
38
40
  client.http.get = jest.fn().mockResolvedValue(categoryQueryResponse);
39
41
 
40
- liveCategories({}, callback);
42
+ liveCategories(params, callback);
41
43
  await pause();
42
44
 
43
45
  expect(callback).toHaveBeenCalledTimes(2);
@@ -57,9 +59,9 @@ describe('live Caategories', () => {
57
59
  const callback = jest.fn();
58
60
  client.http.get = jest.fn().mockResolvedValue(categoryQueryResponse);
59
61
 
60
- liveCategories({}, () => undefined);
62
+ liveCategories(params, () => undefined);
61
63
  await pause();
62
- liveCategories({}, callback);
64
+ liveCategories(params, callback);
63
65
  await pause();
64
66
 
65
67
  expect(callback).toHaveBeenCalledTimes(2);
@@ -116,7 +118,7 @@ describe('live Caategories', () => {
116
118
  .mockResolvedValue(categoryQueryResponse)
117
119
  .mockResolvedValueOnce(categoryQueryResponsePage2);
118
120
 
119
- liveCategories({}, callback);
121
+ liveCategories(params, callback);
120
122
  await pause();
121
123
 
122
124
  expect(callback).toHaveBeenCalled();
@@ -91,11 +91,10 @@ describe('removeChannelMembers', () => {
91
91
  await pause();
92
92
 
93
93
  /*
94
- * Assertion below is required to check if the event handler is called with the right
95
- * params. It's not enough to check if the handler does not throw
94
+ * Removed assertion for checking what the callback was called with as it's
95
+ * impossible to guarantee the order in which the events will be fired
96
96
  */
97
- expect(callback).toHaveBeenNthCalledWith(1, channel1, channelUser);
98
- expect(callback).toHaveBeenNthCalledWith(2, channel1, channelUser3);
97
+ expect(callback).toHaveBeenCalledTimes(2);
99
98
 
100
99
  unsub();
101
100
  });
@@ -137,16 +137,16 @@ export const liveChannelMembers = (
137
137
  responder(collection);
138
138
  };
139
139
 
140
- const onFetch = () => {
140
+ const onFetch = (initial = false) => {
141
141
  const collection = pullFromCache<Amity.ChannelMembersLiveCollectionCache>(cacheKey)?.data;
142
142
 
143
143
  const channelMembers = collection?.data ?? [];
144
144
 
145
- if (channelMembers.length > 0 && !collection?.params.page) return;
145
+ if (!initial && channelMembers.length > 0 && !collection?.params.page) return;
146
146
 
147
147
  const query = createQuery(queryChannelMembers, {
148
148
  ...queryParams,
149
- page: collection?.params.page ?? { limit },
149
+ page: (!initial ? collection?.params.page : undefined) ?? { limit },
150
150
  });
151
151
 
152
152
  runQuery(
@@ -180,7 +180,7 @@ export const liveChannelMembers = (
180
180
  onChannelMemberUnbanned(realtimeRouter('onChannelMemberUnbanned')),
181
181
  );
182
182
 
183
- onFetch();
183
+ onFetch(true);
184
184
 
185
185
  return () => {
186
186
  log(`liveChannelMembers(tmpid: ${timestamp}) > dispose`);
@@ -146,16 +146,16 @@ export const liveChannels = (
146
146
  responder(collection);
147
147
  };
148
148
 
149
- const onFetch = () => {
149
+ const onFetch = (initial = false) => {
150
150
  const collection = pullFromCache<Amity.ChannelLiveCollectionCache>(cacheKey)?.data;
151
151
 
152
152
  const channels = collection?.data ?? [];
153
153
 
154
- if (channels.length > 0 && !collection?.params.page) return;
154
+ if (!initial && channels.length > 0 && !collection?.params.page) return;
155
155
 
156
156
  const query = createQuery(queryChannels, {
157
157
  ...queryParams,
158
- page: collection?.params.page ?? { limit },
158
+ page: (!initial ? collection?.params.page : undefined) ?? { limit },
159
159
  });
160
160
 
161
161
  runQuery(
@@ -192,7 +192,7 @@ export const liveChannels = (
192
192
  onMessageCreated(() => null), // watch unread count
193
193
  );
194
194
 
195
- onFetch();
195
+ onFetch(true);
196
196
 
197
197
  return () => {
198
198
  log(`liveChannels(tmpid: ${timestamp}) > dispose`);
@@ -9,6 +9,7 @@ import {
9
9
  client,
10
10
  connectClient,
11
11
  convertRawChannelPayload,
12
+ convertChannelFromRaw,
12
13
  disconnectClient,
13
14
  generateRawChannel,
14
15
  generateRawMessage,
@@ -20,7 +21,6 @@ import {
20
21
  } from '~/utils/tests';
21
22
 
22
23
  import { liveChannels } from '../liveChannels';
23
- import { convertFromRaw } from '../../utils';
24
24
  import * as getChannelMarkers from '../../../marker/api/getChannelMarkers';
25
25
 
26
26
  const getSnapshot = (params?: Record<string, any>) => {
@@ -75,17 +75,11 @@ describe('liveChannels', () => {
75
75
  liveChannels({}, callback);
76
76
  await pause();
77
77
 
78
- expect(callback).toHaveBeenCalledTimes(2);
78
+ // The second `getChannels` call fetches data from the cache,
79
+ // so there is no loading state and the callback only fires once.
80
+ expect(callback).toHaveBeenCalledTimes(1);
79
81
  expect(callback).toHaveBeenNthCalledWith(
80
82
  1,
81
- expect.objectContaining(
82
- getSnapshot({
83
- data: convertRawChannelPayload(channelQueryResponse.data).channels,
84
- }),
85
- ),
86
- );
87
- expect(callback).toHaveBeenNthCalledWith(
88
- 2,
89
83
  expect.objectContaining(
90
84
  getSnapshot({
91
85
  data: convertRawChannelPayload(channelQueryResponse.data).channels,
@@ -99,17 +93,17 @@ describe('liveChannels', () => {
99
93
  channelId: 'deleted-channel-id',
100
94
  isDeleted: true,
101
95
  });
102
- const deletedChannel = convertFromRaw(rawDeletedChannel);
96
+ const deletedChannel = convertChannelFromRaw(rawDeletedChannel);
103
97
  const rawTaggedChannel = generateRawChannel({
104
98
  channelId: 'tagged-channel-id',
105
99
  tags: ['tag1', 'tag2'],
106
100
  });
107
- const taggedChannel = convertFromRaw(rawTaggedChannel);
101
+ const taggedChannel = convertChannelFromRaw(rawTaggedChannel);
108
102
  const rawTaggedChannel2 = generateRawChannel({
109
103
  channelId: 'tagged-channel-id-2',
110
104
  tags: ['tag2'],
111
105
  });
112
- const taggedChannel2 = convertFromRaw(rawTaggedChannel2);
106
+ const taggedChannel2 = convertChannelFromRaw(rawTaggedChannel2);
113
107
 
114
108
  const filters: [string, Amity.ChannelLiveCollection, Amity.Channel[]][] = [
115
109
  ['deleted', { isDeleted: false }, [channel1, taggedChannel, taggedChannel2]],
@@ -200,13 +194,13 @@ describe('liveChannels', () => {
200
194
  'it should add new channel to collection onCreate',
201
195
  'channel.created',
202
196
  rawNewChannel,
203
- [convertFromRaw(rawNewChannel), channel1, channel2],
197
+ [convertChannelFromRaw(rawNewChannel), channel1, channel2],
204
198
  ],
205
199
  [
206
200
  'it should add new channel to collection onJoin',
207
201
  'channel.joined',
208
202
  rawNewChannel,
209
- [convertFromRaw(rawNewChannel), channel1, channel2],
203
+ [convertChannelFromRaw(rawNewChannel), channel1, channel2],
210
204
  ],
211
205
  [
212
206
  'it should update channel in collection onUpdate',
@@ -107,8 +107,8 @@ export const connectClient = async (
107
107
  * token expires
108
108
  */
109
109
  unsubWatcher = client.accessTokenExpiryWatcher(
110
- client.token?.issuedAt!,
111
110
  client.token?.expiresAt!,
111
+ client.token?.issuedAt!,
112
112
  sessionHandler!,
113
113
  );
114
114
 
@@ -5,6 +5,8 @@ import { pullFromCache, pushToCache } from '~/cache/api';
5
5
  import { ingestInCache } from '~/cache/api/ingestInCache';
6
6
  import { getResolver } from '~/core/model';
7
7
 
8
+ import { inferIsDeleted } from '~/utils/inferIsDeleted';
9
+
8
10
  /* begin_public_function
9
11
  id: comment.query
10
12
  */
@@ -44,7 +46,7 @@ export const queryComments = async (
44
46
  {
45
47
  params: {
46
48
  ...params,
47
- isDeleted: includeDeleted === false ? false : undefined,
49
+ isDeleted: inferIsDeleted(includeDeleted),
48
50
  // filterByParentId, API-FIX: backend does not support this boolean LOL. what the hell seriously.
49
51
  options,
50
52
  },
@@ -82,7 +82,7 @@ export const liveComments = (
82
82
  .filter(Boolean)
83
83
  .map(({ data }) => data) ?? [];
84
84
 
85
- if (params.includeDeleted === false) {
85
+ if (!params.includeDeleted) {
86
86
  comments = filterByPropEquality(comments, 'isDeleted', false);
87
87
  }
88
88
 
@@ -120,16 +120,16 @@ export const liveComments = (
120
120
  responder(collection);
121
121
  };
122
122
 
123
- const onFetch = () => {
123
+ const onFetch = (initial = false) => {
124
124
  const collection = pullFromCache<Amity.CommentLiveCollectionCache>(cacheKey)?.data;
125
125
 
126
126
  const comments = collection?.data ?? [];
127
127
 
128
- if (comments.length > 0 && !collection?.params?.page) return;
128
+ if (!initial && comments.length > 0 && !collection?.params?.page) return;
129
129
 
130
130
  const query = createQuery(queryComments, {
131
131
  ...queryParams,
132
- page: collection?.params?.page ?? { limit },
132
+ page: (!initial ? collection?.params.page : undefined) ?? { limit },
133
133
  });
134
134
 
135
135
  runQuery(
@@ -167,7 +167,7 @@ export const liveComments = (
167
167
  onCommentReactionRemoved(realtimeRouter('onReactionRemoved')),
168
168
  );
169
169
 
170
- onFetch();
170
+ onFetch(true);
171
171
 
172
172
  return () => {
173
173
  log(`liveComments(tmpid: ${timestamp}) > dispose`);
@@ -5,6 +5,7 @@ import { pushToCache } from '~/cache/api';
5
5
  import { ingestInCache } from '~/cache/api/ingestInCache';
6
6
  import { getResolver } from '~/core/model';
7
7
 
8
+ import { inferIsDeleted } from '~/utils/inferIsDeleted';
8
9
  import { prepareCommunityPayload } from '../utils';
9
10
 
10
11
  /* begin_public_function
@@ -43,7 +44,7 @@ export const queryCommunities = async (
43
44
  {
44
45
  params: {
45
46
  ...restParams,
46
- isDeleted: includeDeleted === false ? false : undefined,
47
+ isDeleted: inferIsDeleted(includeDeleted),
47
48
  keyword: displayName,
48
49
  filter: membership,
49
50
  options: {
@@ -89,14 +89,14 @@ describe('queryCommunities', () => {
89
89
  expect(mockFn.mock.lastCall[1].params.isDeleted).toBe(false);
90
90
  });
91
91
 
92
- test('it should set isDeleted to undefined if includeDeleted is undefined', async () => {
92
+ test('it should set isDeleted to false if includeDeleted is undefined', async () => {
93
93
  const mockFn = jest.fn();
94
94
  client.http.get = mockFn.mockResolvedValue(resolvedGetValue);
95
95
 
96
96
  await queryCommunities(queryCriteriaWithoutPage);
97
97
 
98
98
  expect(mockFn.mock.lastCall).toHaveLength(2);
99
- expect(mockFn.mock.lastCall[1].params.isDeleted).toBeUndefined();
99
+ expect(mockFn.mock.lastCall[1].params.isDeleted).toBe(false);
100
100
  });
101
101
  });
102
102
 
@@ -78,7 +78,7 @@ export const liveCommunities = (
78
78
 
79
79
  communities = filterByPropEquality(communities, 'displayName', params.displayName);
80
80
 
81
- if (params.includeDeleted === false) {
81
+ if (!params.includeDeleted) {
82
82
  communities = filterByPropEquality(communities, 'isDeleted', false);
83
83
  }
84
84
 
@@ -138,16 +138,16 @@ export const liveCommunities = (
138
138
  responder(collection);
139
139
  };
140
140
 
141
- const onFetch = () => {
141
+ const onFetch = (initial = false) => {
142
142
  const collection = pullFromCache<Amity.CommunityLiveCollectionCache>(cacheKey)?.data;
143
143
 
144
144
  const communities = collection?.data ?? [];
145
145
 
146
- if (communities.length > 0 && !collection?.params.page) return;
146
+ if (!initial && communities.length > 0 && !collection?.params.page) return;
147
147
 
148
148
  const query = createQuery(queryCommunities, {
149
149
  ...queryParams,
150
- page: collection?.params.page ?? { limit },
150
+ page: (!initial ? collection?.params.page : undefined) ?? { limit },
151
151
  });
152
152
 
153
153
  runQuery(
@@ -181,7 +181,7 @@ export const liveCommunities = (
181
181
  onCommunityUserChanged(realtimeRouter('onMemberCountChanged')),
182
182
  );
183
183
 
184
- onFetch();
184
+ onFetch(true);
185
185
 
186
186
  return () => {
187
187
  log(`liveCommunities(tmpid: ${timestamp}) > dispose`);
@@ -132,16 +132,16 @@ export const liveCommunityMembers = (
132
132
  responder(collection);
133
133
  };
134
134
 
135
- const onFetch = () => {
135
+ const onFetch = (initial = false) => {
136
136
  const collection = pullFromCache<Amity.CommunityMemberLiveCollectionCache>(cacheKey)?.data;
137
137
 
138
138
  const communityMembers = collection?.data ?? [];
139
139
 
140
- if (communityMembers.length > 0 && !collection?.params.page) return;
140
+ if (!initial && communityMembers.length > 0 && !collection?.params.page) return;
141
141
 
142
142
  const query = createQuery(queryCommunityMembers, {
143
143
  ...queryParams,
144
- page: collection?.params.page ?? { limit },
144
+ page: (!initial ? collection?.params.page : undefined) ?? { limit },
145
145
  });
146
146
 
147
147
  runQuery(
@@ -178,7 +178,7 @@ export const liveCommunityMembers = (
178
178
  onCommunityUserRoleRemoved(realtimeRouter('onMemberCountChanged')),
179
179
  );
180
180
 
181
- onFetch();
181
+ onFetch(true);
182
182
 
183
183
  return () => {
184
184
  log(`liveCommunityMembers(tmpid: ${timestamp}) > dispose`);
@@ -39,7 +39,7 @@ describe('liveCommunities', () => {
39
39
  const callback = jest.fn();
40
40
  client.http.get = jest.fn().mockResolvedValue(communityQueryResponse);
41
41
 
42
- liveCommunities({}, callback);
42
+ liveCommunities({ includeDeleted: true }, callback);
43
43
  await pause();
44
44
 
45
45
  expect(callback).toHaveBeenCalledTimes(2);
@@ -59,9 +59,9 @@ describe('liveCommunities', () => {
59
59
  const callback = jest.fn();
60
60
  client.http.get = jest.fn().mockResolvedValue(communityQueryResponse);
61
61
 
62
- liveCommunities({}, () => undefined);
62
+ liveCommunities({ includeDeleted: true }, () => undefined);
63
63
  await pause();
64
- liveCommunities({}, callback);
64
+ liveCommunities({ includeDeleted: true }, callback);
65
65
  await pause();
66
66
 
67
67
  expect(callback).toHaveBeenCalledTimes(2);
@@ -86,9 +86,9 @@ describe('liveCommunities', () => {
86
86
 
87
87
  const filters: [string, Amity.CommunityLiveCollection, Amity.Community[]][] = [
88
88
  ['not deleted', { includeDeleted: false }, [community2]],
89
- ['categoryId', { categoryId: 'test-category-id' }, [community1]],
90
- ['displayName', { displayName: 'community 1' }, [community1]],
91
- ['tagged', { tags: ['test-community-tag'] }, [community1]],
89
+ ['categoryId', { categoryId: 'test-category-id', includeDeleted: true }, [community1]],
90
+ ['displayName', { displayName: 'community 1', includeDeleted: true }, [community1]],
91
+ ['tagged', { tags: ['test-community-tag'], includeDeleted: true }, [community1]],
92
92
  ];
93
93
 
94
94
  test.each(filters)('it should filter by %s communities', async (filter, params, expected) => {
@@ -121,7 +121,7 @@ describe('liveCommunities', () => {
121
121
  .mockResolvedValue(communityQueryResponse)
122
122
  .mockResolvedValueOnce(communityQueryResponsePage2);
123
123
 
124
- liveCommunities({}, callback);
124
+ liveCommunities({ includeDeleted: true }, callback);
125
125
  await pause();
126
126
 
127
127
  expect(callback).toHaveBeenCalled();
@@ -136,3 +136,41 @@ export const filterByCommunityMembership = <T extends Amity.Community>(
136
136
  return !communityUser || communityUser.communityMembership !== 'none';
137
137
  });
138
138
  };
139
+
140
+ /**
141
+ * Filter a post collection by dataType
142
+ *
143
+ * @param collection the post to filter
144
+ * @param dataTypes of the post to be filtered by
145
+ * @returns a filtered collection with items only matching the criteria
146
+ *
147
+ * @hidden
148
+ */
149
+ export const filterByPostDataTypes = <T extends Amity.Post>(
150
+ collection: T[],
151
+ dataTypes: Amity.PostLiveCollection['dataTypes'],
152
+ ): T[] => {
153
+ const filteredPosts: T[] = [];
154
+
155
+ collection.forEach(c => {
156
+ /*
157
+ * A text post with no children is just a text post
158
+ */
159
+ if (c.dataType === 'text' && !c.children.length) return;
160
+
161
+ if (c.children.length) {
162
+ const childPost = pullFromCache<Amity.Post>(['post', 'get', c.children[0]])?.data;
163
+
164
+ if (childPost && dataTypes?.includes(childPost?.dataType)) {
165
+ // @ts-ignore
166
+ filteredPosts.push(childPost);
167
+ }
168
+
169
+ return;
170
+ }
171
+
172
+ if (dataTypes?.includes(c.dataType)) filteredPosts.push(c);
173
+ });
174
+
175
+ return filteredPosts;
176
+ };
@@ -96,16 +96,16 @@ export const liveFollowers = (
96
96
  responder(collection);
97
97
  };
98
98
 
99
- const onFetch = () => {
99
+ const onFetch = (initial = false) => {
100
100
  const collection = pullFromCache<Amity.FollowerLiveCollectionCache>(cacheKey)?.data;
101
101
 
102
102
  const followers = collection?.data ?? [];
103
103
 
104
- if (followers.length > 0 && !collection?.params?.page) return;
104
+ if (!initial && followers.length > 0 && !collection?.params?.page) return;
105
105
 
106
106
  const query = createQuery(queryFollowers, {
107
107
  ...queryParams,
108
- page: collection?.params?.page ?? { limit },
108
+ page: (!initial ? collection?.params.page : undefined) ?? { limit },
109
109
  });
110
110
 
111
111
  runQuery(
@@ -140,7 +140,7 @@ export const liveFollowers = (
140
140
  onFollowerDeleted(realtimeRouter('onDeleted')),
141
141
  );
142
142
 
143
- onFetch();
143
+ onFetch(true);
144
144
 
145
145
  return () => {
146
146
  log(`liveFollowers(tmpid: ${timestamp}) > dispose`);
@@ -96,16 +96,16 @@ export const liveFollowings = (
96
96
  responder(collection);
97
97
  };
98
98
 
99
- const onFetch = () => {
99
+ const onFetch = (initial = false) => {
100
100
  const collection = pullFromCache<Amity.FollowingLiveCollectionCache>(cacheKey)?.data;
101
101
 
102
102
  const followings = collection?.data ?? [];
103
103
 
104
- if (followings.length > 0 && !collection?.params?.page) return;
104
+ if (!initial && followings.length > 0 && !collection?.params?.page) return;
105
105
 
106
106
  const query = createQuery(queryFollowings, {
107
107
  ...queryParams,
108
- page: collection?.params?.page ?? { limit },
108
+ page: (!initial ? collection?.params.page : undefined) ?? { limit },
109
109
  });
110
110
 
111
111
  runQuery(
@@ -140,7 +140,7 @@ export const liveFollowings = (
140
140
  onFollowerDeleted(realtimeRouter('onDeleted')),
141
141
  );
142
142
 
143
- onFetch();
143
+ onFetch(true);
144
144
 
145
145
  return () => {
146
146
  log(`liveFollowings(tmpid: ${timestamp}) > dispose`);