@amityco/ts-sdk 6.35.3-024c022.0 → 6.35.3-223c453.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 (34) hide show
  1. package/dist/channelRepository/internalApi/getChannelByIds.d.ts +2 -2
  2. package/dist/channelRepository/internalApi/getChannelByIds.d.ts.map +1 -1
  3. package/dist/channelRepository/observers/getChannel.d.ts.map +1 -1
  4. package/dist/channelRepository/observers/getChannels/ChannelLiveCollectionController.d.ts.map +1 -1
  5. package/dist/channelRepository/utils/constructChannelObject.d.ts.map +1 -1
  6. package/dist/channelRepository/utils/updateChannelCache.d.ts +1 -1
  7. package/dist/channelRepository/utils/updateChannelCache.d.ts.map +1 -1
  8. package/dist/communityRepository/observers/searchCommunities.d.ts +1 -1
  9. package/dist/communityRepository/observers/searchCommunities.d.ts.map +1 -1
  10. package/dist/communityRepository/utils/communityQueryFilter.d.ts.map +1 -1
  11. package/dist/index.cjs.js +135 -25
  12. package/dist/index.esm.js +135 -25
  13. package/dist/index.umd.js +2 -2
  14. package/dist/messageRepository/api/createMessage.d.ts.map +1 -1
  15. package/dist/messageRepository/observers/getMessages/getMessages.d.ts +0 -1
  16. package/dist/messageRepository/observers/getMessages/getMessages.d.ts.map +1 -1
  17. package/package.json +1 -1
  18. package/src/channelRepository/api/getChannelByIds.ts +5 -5
  19. package/src/channelRepository/internalApi/getChannelByIds.ts +5 -7
  20. package/src/channelRepository/observers/getChannel.ts +33 -13
  21. package/src/channelRepository/observers/getChannels/ChannelLiveCollectionController.ts +6 -12
  22. package/src/channelRepository/utils/constructChannelObject.ts +7 -0
  23. package/src/channelRepository/utils/resolveChannels.ts +1 -1
  24. package/src/channelRepository/utils/updateChannelCache.ts +4 -1
  25. package/src/communityRepository/communityMembership/observers/tests/getMembers.test.ts +0 -1
  26. package/src/communityRepository/observers/searchCommunities.ts +1 -1
  27. package/src/communityRepository/observers/tests/getCommunities.test.ts +0 -1
  28. package/src/communityRepository/utils/communityQueryFilter.ts +1 -8
  29. package/src/core/events.ts +1 -1
  30. package/src/messageRepository/api/createMessage.ts +6 -2
  31. package/src/messageRepository/api/tests/createMessage.test.ts +1 -0
  32. package/src/messageRepository/api/tests/deleteMessage.test.ts +5 -1
  33. package/src/messageRepository/observers/getMessages/getMessages.ts +0 -34
  34. package/src/userRepository/observers/tests/getUsers.test.ts +1 -43
@@ -1 +1 @@
1
- {"version":3,"file":"createMessage.d.ts","sourceRoot":"","sources":["../../../src/messageRepository/api/createMessage.ts"],"names":[],"mappings":"AAmBA,aAAK,kBAAkB,CAAC,CAAC,SAAS,KAAK,CAAC,kBAAkB,IAAI,IAAI,CAChE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAChB,cAAc,GAAG,UAAU,GAAG,UAAU,GAAG,MAAM,GAAG,UAAU,GAAG,YAAY,CAC9E,GAAG;IACF,IAAI,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IAChC,MAAM,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAoEF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,aAAa,yEAEvB,QAAQ,MAAM,MAAM,CAAC,MAAM,OAAO,CAAC,CA2CrC,CAAC"}
1
+ {"version":3,"file":"createMessage.d.ts","sourceRoot":"","sources":["../../../src/messageRepository/api/createMessage.ts"],"names":[],"mappings":"AAmBA,aAAK,kBAAkB,CAAC,CAAC,SAAS,KAAK,CAAC,kBAAkB,IAAI,IAAI,CAChE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAChB,cAAc,GAAG,UAAU,GAAG,UAAU,GAAG,MAAM,GAAG,UAAU,GAAG,YAAY,CAC9E,GAAG;IACF,IAAI,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IAChC,MAAM,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAwEF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,aAAa,yEAEvB,QAAQ,MAAM,MAAM,CAAC,MAAM,OAAO,CAAC,CA2CrC,CAAC"}
@@ -1,4 +1,3 @@
1
- export declare const applyFilter: <T extends Amity.Message<any>>(data: T[], params: Amity.MessagesLiveCollection) => T[];
2
1
  /**
3
2
  * ```js
4
3
  * import { getMessages } from '@amityco/ts-sdk';
@@ -1 +1 @@
1
- {"version":3,"file":"getMessages.d.ts","sourceRoot":"","sources":["../../../../src/messageRepository/observers/getMessages/getMessages.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,WAAW,oDAEd,MAAM,sBAAsB,QAuBrC,CAAC;AAKF;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,WAAW,WACd,MAAM,sBAAsB,YAC1B,MAAM,sBAAsB,CAAC,MAAM,OAAO,CAAC,WAC5C,MAAM,oBAAoB,KAClC,MAAM,YAuBR,CAAC"}
1
+ {"version":3,"file":"getMessages.d.ts","sourceRoot":"","sources":["../../../../src/messageRepository/observers/getMessages/getMessages.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,WAAW,WACd,MAAM,sBAAsB,YAC1B,MAAM,sBAAsB,CAAC,MAAM,OAAO,CAAC,WAC5C,MAAM,oBAAoB,KAClC,MAAM,YAuBR,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amityco/ts-sdk",
3
- "version": "6.35.3-024c022.0",
3
+ "version": "6.35.3-223c453.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",
@@ -8,8 +8,8 @@ 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/prepareUnreadCountInfo';
11
- import { LinkedObject } from '~/utils/linkedObject';
12
- import { constructChannelDynamicValue } from '../utils/constructChannelDynamicValue';
11
+
12
+ import { constructChannelObject } from '../utils/constructChannelObject';
13
13
 
14
14
  /**
15
15
  * ```js
@@ -65,7 +65,7 @@ export const getChannelByIds = async (
65
65
  fireEvent('local.channel.fetched', data.channels);
66
66
 
67
67
  return {
68
- data: data.channels.map(channel => LinkedObject.channel(constructChannelDynamicValue(channel))),
68
+ data: data.channels.map(channel => constructChannelObject(channel)),
69
69
  cachedAt,
70
70
  };
71
71
  };
@@ -91,7 +91,7 @@ getChannelByIds.locally = (
91
91
 
92
92
  if (!client.cache) return;
93
93
 
94
- const cached = queryCache<Amity.InternalChannel>(['channel', 'get'])?.filter(({ data }) => {
94
+ const cached = queryCache<Amity.StaticInternalChannel>(['channel', 'get'])?.filter(({ data }) => {
95
95
  return channelIds.includes(data.channelPublicId);
96
96
  });
97
97
 
@@ -101,7 +101,7 @@ getChannelByIds.locally = (
101
101
  const oldest = cached.sort((a, b) => (a.cachedAt! < b.cachedAt! ? -1 : 1))?.[0];
102
102
 
103
103
  return {
104
- data: channels.map(channel => LinkedObject.channel(channel)),
104
+ data: channels.map(channel => constructChannelObject(channel)),
105
105
  cachedAt: oldest.cachedAt,
106
106
  };
107
107
  };
@@ -8,8 +8,6 @@ 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/prepareUnreadCountInfo';
11
- import { LinkedObject } from '~/utils/linkedObject';
12
- import { constructChannelDynamicValue } from '../utils/constructChannelDynamicValue';
13
11
 
14
12
  /**
15
13
  * ```js
@@ -27,7 +25,7 @@ import { constructChannelDynamicValue } from '../utils/constructChannelDynamicVa
27
25
  */
28
26
  export const getChannelByIds = async (
29
27
  channelIds: Amity.Channel['channelPublicId'][],
30
- ): Promise<Amity.Cached<Amity.Channel[]>> => {
28
+ ): Promise<Amity.Cached<Amity.StaticInternalChannel[]>> => {
31
29
  const client = getActiveClient();
32
30
  client.log('channel/getChannelByIds', channelIds);
33
31
 
@@ -65,7 +63,7 @@ export const getChannelByIds = async (
65
63
  fireEvent('local.channel.fetched', data.channels);
66
64
 
67
65
  return {
68
- data: data.channels.map(channel => LinkedObject.channel(constructChannelDynamicValue(channel))),
66
+ data: data.channels,
69
67
  cachedAt,
70
68
  };
71
69
  };
@@ -85,13 +83,13 @@ export const getChannelByIds = async (
85
83
  */
86
84
  getChannelByIds.locally = (
87
85
  channelIds: Amity.Channel['channelPublicId'][],
88
- ): Amity.Cached<Amity.Channel[]> | undefined => {
86
+ ): Amity.Cached<Amity.StaticInternalChannel[]> | undefined => {
89
87
  const client = getActiveClient();
90
88
  client.log('channel/getChannelByIds.locally', channelIds);
91
89
 
92
90
  if (!client.cache) return;
93
91
 
94
- const cached = queryCache<Amity.InternalChannel>(['channel', 'get'])?.filter(({ data }) => {
92
+ const cached = queryCache<Amity.StaticInternalChannel>(['channel', 'get'])?.filter(({ data }) => {
95
93
  return channelIds.includes(data.channelPublicId);
96
94
  });
97
95
 
@@ -101,7 +99,7 @@ getChannelByIds.locally = (
101
99
  const oldest = cached.sort((a, b) => (a.cachedAt! < b.cachedAt! ? -1 : 1))?.[0];
102
100
 
103
101
  return {
104
- data: channels.map(channel => LinkedObject.channel(channel)),
102
+ data: channels,
105
103
  cachedAt: oldest.cachedAt,
106
104
  };
107
105
  };
@@ -28,14 +28,12 @@ import {
28
28
  handleSubChannelUpdated,
29
29
  } from '~/messagePreview/utils/updateMessagePreviewFromMessage';
30
30
  import { getActiveClient } from '~/client/api/activeClient';
31
- import { getChannelMessagePreviewWithUser } from '~/messagePreview/utils';
32
31
  import { isEqual } from '~/utils/isEqual';
33
32
  import { updateChannelCache } from '../utils/updateChannelCache';
34
33
  import { onChannelMarkerUpdated } from '~/marker/events/onChannelMarkerUpdated';
35
34
  import { onSubChannelCreated } from '~/subChannelRepository';
36
- import { LinkedObject } from '~/utils/linkedObject';
37
35
  import { onChannelUnreadUpdatedLocal } from '~/marker/events/onChannelUnreadUpdatedLocal';
38
- import { constructChannelDynamicValue } from '../utils/constructChannelDynamicValue';
36
+ import { constructChannelObject } from '../utils/constructChannelObject';
39
37
 
40
38
  /* begin_public_function
41
39
  id: channel.get
@@ -74,10 +72,8 @@ export const getChannel = (
74
72
 
75
73
  const data = {
76
74
  ...response,
77
- // TODO: refactor to be a function to construct public channel object
78
- data: LinkedObject.channel(
79
- constructChannelDynamicValue(getChannelMessagePreviewWithUser(response.data)),
80
- ),
75
+
76
+ data: constructChannelObject(response.data),
81
77
  };
82
78
 
83
79
  const { origin, ...newSnapshot } = data;
@@ -121,7 +117,11 @@ export const getChannel = (
121
117
  if (message.channelId !== channelId) return;
122
118
 
123
119
  // channelId from message is channelInternalId
124
- const channel = pullFromCache<Amity.Channel>(['channel', 'get', channelId])?.data;
120
+ const channel = pullFromCache<Amity.StaticInternalChannel>([
121
+ 'channel',
122
+ 'get',
123
+ channelId,
124
+ ])?.data;
125
125
  if (!channel) return;
126
126
 
127
127
  updateChannelCache(channel, {
@@ -150,7 +150,11 @@ export const getChannel = (
150
150
  if (message.channelId !== channelId) return;
151
151
 
152
152
  // channelId from message is channelInternalId
153
- const channel = pullFromCache<Amity.Channel>(['channel', 'get', channelId])?.data;
153
+ const channel = pullFromCache<Amity.StaticInternalChannel>([
154
+ 'channel',
155
+ 'get',
156
+ channelId,
157
+ ])?.data;
154
158
  if (!channel) return;
155
159
 
156
160
  updateChannelCache(channel, {
@@ -168,7 +172,11 @@ export const getChannel = (
168
172
  convertEventPayload(
169
173
  (callback: Amity.Listener<Amity.InternalMessage>) => {
170
174
  const updateMessagePreview = async (message: Amity.InternalMessage) => {
171
- const channel = pullFromCache<Amity.Channel>(['channel', 'get', channelId])?.data;
175
+ const channel = pullFromCache<Amity.StaticInternalChannel>([
176
+ 'channel',
177
+ 'get',
178
+ channelId,
179
+ ])?.data;
172
180
  if (!channel || channel.messagePreviewId !== message.messageId) return;
173
181
 
174
182
  const messagePreviewSetting = await client.getMessagePreviewSetting(false);
@@ -188,7 +196,11 @@ export const getChannel = (
188
196
  convertEventPayload(
189
197
  (callback: Amity.Listener<Amity.InternalMessage>) => {
190
198
  const updateMessagePreview = async (message: Amity.InternalMessage) => {
191
- const channel = pullFromCache<Amity.Channel>(['channel', 'get', channelId])?.data;
199
+ const channel = pullFromCache<Amity.StaticInternalChannel>([
200
+ 'channel',
201
+ 'get',
202
+ channelId,
203
+ ])?.data;
192
204
  if (!channel || channel.messagePreviewId !== message.messageId) return;
193
205
 
194
206
  const messagePreviewSetting = await client.getMessagePreviewSetting(false);
@@ -231,7 +243,11 @@ export const getChannel = (
231
243
 
232
244
  await _getChannel(channelId);
233
245
 
234
- const channel = pullFromCache<Amity.Channel>(['channel', 'get', channelId])?.data;
246
+ const channel = pullFromCache<Amity.StaticInternalChannel>([
247
+ 'channel',
248
+ 'get',
249
+ channelId,
250
+ ])?.data;
235
251
  if (!channel) return;
236
252
 
237
253
  callback(subChannel);
@@ -263,7 +279,11 @@ export const getChannel = (
263
279
  )
264
280
  return;
265
281
 
266
- const channel = pullFromCache<Amity.Channel>(['channel', 'get', channelId])?.data;
282
+ const channel = pullFromCache<Amity.StaticInternalChannel>([
283
+ 'channel',
284
+ 'get',
285
+ channelId,
286
+ ])?.data;
267
287
  if (!channel) return;
268
288
 
269
289
  callback(subChannel);
@@ -55,9 +55,8 @@ import { prepareUnreadCountInfo } from '~/channelRepository/utils/prepareUnreadC
55
55
  import { resolveUnreadInfoOnChannelEvent } from '~/channelRepository/utils/resolveUnreadInfoOnChannelEvent';
56
56
  import { onChannelResolved } from '~/channelRepository/events/onChannelResolved';
57
57
  import { onUserMessageFeedMarkerResolved } from '~/marker/events/onUserMessageFeedMarkerResolved';
58
- import { LinkedObject } from '~/utils/linkedObject';
59
58
  import { onChannelUnreadUpdatedLocal } from '~/marker/events/onChannelUnreadUpdatedLocal';
60
- import { constructChannelDynamicValue } from '~/channelRepository/utils/constructChannelDynamicValue';
59
+ import { constructChannelObject } from '~/channelRepository/utils/constructChannelObject';
61
60
 
62
61
  export class ChannelLiveCollectionController extends LiveCollectionController<
63
62
  'channel',
@@ -140,12 +139,7 @@ export class ChannelLiveCollectionController extends LiveCollectionController<
140
139
  )
141
140
  .filter(Boolean)
142
141
  .map(({ data }) => data)
143
- // add messagePreview >> Amity.InternalChannel -> Amity.InternalChannel
144
- .map(getChannelMessagePreviewWithUser)
145
- // construct getter value >> Amity.StaticInternalChannel -> Amity.Channel
146
- .map(constructChannelDynamicValue)
147
- // add markAsRead >> Amity.InternalChannel -> Amity.Channel
148
- .map(LinkedObject.channel) ?? [];
142
+ .map(constructChannelObject) ?? [];
149
143
 
150
144
  if (this.paginationController instanceof ChannelPaginationController) {
151
145
  data = this.applyFilter(data);
@@ -269,7 +263,7 @@ export class ChannelLiveCollectionController extends LiveCollectionController<
269
263
  Amity.ReferenceType.USER_MESSAGE_FEED_MARKER,
270
264
  );
271
265
 
272
- const channelCache = pullFromCache<Amity.Channel>([
266
+ const channelCache = pullFromCache<Amity.StaticInternalChannel>([
273
267
  'channel',
274
268
  'get',
275
269
  message.channelId,
@@ -296,7 +290,7 @@ export class ChannelLiveCollectionController extends LiveCollectionController<
296
290
  fn: convertEventPayload(
297
291
  (callback: Amity.Listener<Amity.InternalMessage>) => {
298
292
  return onMessageCreatedLocal(message => {
299
- const cacheData = pullFromCache<Amity.Channel>([
293
+ const cacheData = pullFromCache<Amity.StaticInternalChannel>([
300
294
  'channel',
301
295
  'get',
302
296
  message.channelId,
@@ -375,7 +369,7 @@ export class ChannelLiveCollectionController extends LiveCollectionController<
375
369
 
376
370
  if (this.shouldAbort(message.channelId)) return;
377
371
 
378
- const channel = pullFromCache<Amity.Channel>([
372
+ const channel = pullFromCache<Amity.StaticInternalChannel>([
379
373
  'channel',
380
374
  'get',
381
375
  message.channelId,
@@ -409,7 +403,7 @@ export class ChannelLiveCollectionController extends LiveCollectionController<
409
403
 
410
404
  if (this.shouldAbort(message.channelId)) return;
411
405
 
412
- const channel = pullFromCache<Amity.Channel>([
406
+ const channel = pullFromCache<Amity.StaticInternalChannel>([
413
407
  'channel',
414
408
  'get',
415
409
  message.channelId,
@@ -3,6 +3,13 @@ import { constructChannelDynamicValue } from './constructChannelDynamicValue';
3
3
  import { LinkedObject } from '~/utils/linkedObject';
4
4
 
5
5
  export const constructChannelObject = (channel: Amity.StaticInternalChannel): Amity.Channel => {
6
+ /**
7
+ * convert internal cache data to be public channel data
8
+ * 1. [getChannelMessagePreviewWithUser] add messagePreview >> Amity.InternalChannel -> Amity.InternalChannel
9
+ * 2. [constructChannelDynamicValue] construct getter value >> Amity.StaticInternalChannel -> Amity.Channel
10
+ * 3. [LinkedObject.channel] add markAsRead >> Amity.InternalChannel -> Amity.Channel
11
+ */
12
+
6
13
  return LinkedObject.channel(
7
14
  constructChannelDynamicValue(getChannelMessagePreviewWithUser(channel)),
8
15
  );
@@ -1,5 +1,5 @@
1
1
  import { queryCache } from '~/cache/api';
2
- import { getChannelByIds } from '../api/getChannelByIds';
2
+ import { getChannelByIds } from '../internalApi/getChannelByIds';
3
3
  import { fireEvent } from '~/core/events';
4
4
 
5
5
  export const resolveChannels = async (channelIds: Amity.InternalChannel['channelPublicId'][]) => {
@@ -1,7 +1,10 @@
1
1
  import { pushToCache } from '~/cache/api';
2
2
  import { shallowClone } from '~/utils/shallowClone';
3
3
 
4
- export function updateChannelCache(channel: Amity.Channel, params: Partial<Amity.Channel>) {
4
+ export function updateChannelCache(
5
+ channel: Amity.StaticInternalChannel,
6
+ params: Partial<Amity.StaticInternalChannel>,
7
+ ) {
5
8
  pushToCache(
6
9
  ['channel', 'get', channel.channelId],
7
10
  // eslint-disable-next-line prefer-object-spread
@@ -238,7 +238,6 @@ describe('getMembers > applyFilter', () => {
238
238
  [m1, m2],
239
239
  [m2, m1],
240
240
  ],
241
- ['it should filter by search term', { communityId, search: 'sea' }, [m1, m2], [m2]],
242
241
  ];
243
242
 
244
243
  test.each(filters)('%s', (test, param, input, expected) => {
@@ -25,7 +25,7 @@ import { SearchCommunityLiveCollectionController } from './searchCommunities/Sea
25
25
  * @category Community Live Collection
26
26
  */
27
27
  export const searchCommunities = (
28
- params: Amity.CommunityLiveCollection,
28
+ params: Amity.SearchCommunityLiveCollection,
29
29
  callback: Amity.LiveCollectionCallback<Amity.Community>,
30
30
  config?: Amity.LiveCollectionConfig,
31
31
  ) => {
@@ -87,7 +87,6 @@ describe('getCommunities', () => {
87
87
  const filters: [string, Amity.CommunityLiveCollection, Amity.Community[]][] = [
88
88
  ['not deleted', { includeDeleted: false }, [community2]],
89
89
  ['categoryId', { categoryId: 'test-category-id', includeDeleted: true }, [community1]],
90
- ['displayName', { displayName: 'community 1', includeDeleted: true }, [community1]],
91
90
  ['tagged', { tags: ['test-community-tag'], includeDeleted: true }, [community1]],
92
91
  ];
93
92
 
@@ -1,7 +1,6 @@
1
1
  import {
2
2
  filterByCommunityMembership,
3
3
  filterByPropEquality,
4
- sortByDisplayName,
5
4
  sortByFirstCreated,
6
5
  sortByLastCreated,
7
6
  } from '~/core/query';
@@ -12,7 +11,6 @@ export const communityQueryFilter = (
12
11
  userId: string,
13
12
  ): Amity.Community[] => {
14
13
  let communities = data;
15
- communities = filterByPropEquality(communities, 'displayName', params.displayName);
16
14
 
17
15
  if (!params.includeDeleted) {
18
16
  communities = filterByPropEquality(communities, 'isDeleted', false);
@@ -44,11 +42,6 @@ export const communityQueryFilter = (
44
42
  *
45
43
  * This section needs to be updated as displayNames can be null as well
46
44
  */
47
- if (sortBy === 'displayName') {
48
- communities = communities
49
- // this needs to be aligned with the backend data type
50
- .map(c => (c.displayName ? c : { ...c, displayName: '' }))
51
- .sort(sortByDisplayName);
52
- }
45
+
53
46
  return communities;
54
47
  };
@@ -32,7 +32,7 @@ const MQTT_EVENTS = [
32
32
  'video-streaming.didFlag',
33
33
  'video-streaming.didTerminate',
34
34
 
35
- 'user.didGlobalBan',
35
+ // 'user.didGlobalBan' remove due to message event,
36
36
  ] as const;
37
37
 
38
38
  /** @hidden */
@@ -56,12 +56,16 @@ const createMessageOptimistic = <T extends Amity.MessageContentType>(
56
56
  });
57
57
 
58
58
  if (subChannel.data.channelId === subChannel.data.subChannelId) {
59
- const channel = pullFromCache<Amity.Channel>(['channel', 'get', subChannel.data.channelId]);
59
+ const channel = pullFromCache<Amity.StaticInternalChannel>([
60
+ 'channel',
61
+ 'get',
62
+ subChannel.data.channelId,
63
+ ]);
60
64
 
61
65
  if (channel?.data) {
62
66
  upsertInCache(['channel', 'get', subChannel.data.channelId], {
63
67
  ...channel.data,
64
- messageCount: (subChannel.data.messageCount ?? 0) + 1,
68
+ messageCount: (channel.data.messageCount ?? 0) + 1,
65
69
  });
66
70
  }
67
71
  }
@@ -81,6 +81,7 @@ describe('createMessage', () => {
81
81
  });
82
82
  });
83
83
 
84
+ // TODO: fix this test, because createMessage.optimistically is not exist anymore
84
85
  describe('createMessage.optimistically', () => {
85
86
  beforeEach(enableCache);
86
87
 
@@ -92,7 +92,11 @@ describe('softDeleteMessage.optimistically', () => {
92
92
  pushToCache(['message', 'get', deleteId], { ...messageToDelete, channelId });
93
93
 
94
94
  softDeleteMessage.optimistically(deleteId);
95
- const recieved = pullFromCache<Amity.Channel>(['channel', 'get', channelId])?.data;
95
+ const recieved = pullFromCache<Amity.StaticInternalChannel>([
96
+ 'channel',
97
+ 'get',
98
+ channelId,
99
+ ])?.data;
96
100
 
97
101
  expect(recieved?.messageCount).toBe(1);
98
102
  });
@@ -1,42 +1,8 @@
1
- /* eslint-disable no-use-before-define */
2
1
  import { getActiveClient } from '~/client/api';
3
2
  import { dropFromCache } from '~/cache/api';
4
- import { filterByPropEquality } from '~/core/query';
5
-
6
3
  import { ENABLE_CACHE_MESSAGE } from '~/utils/constants';
7
4
  import { MessageLiveCollectionController } from './MessageLiveCollectionController';
8
5
 
9
- /*
10
- * Exported for testing
11
- * @hidden
12
- */
13
- export const applyFilter = <T extends Amity.Message>(
14
- data: T[],
15
- params: Amity.MessagesLiveCollection,
16
- ): T[] => {
17
- let messages = data;
18
-
19
- /*
20
- * for cases when message is deleted via RTE, this flag is used to get
21
- * items from cache that are !deleted
22
- */
23
- if (!params.includeDeleted) {
24
- messages = filterByPropEquality(messages, 'isDeleted', false);
25
- }
26
-
27
- messages = messages.sort((message1, message2) => {
28
- if (params.sortBy === 'segmentAsc') {
29
- return message1.channelSegment - message2.channelSegment;
30
- }
31
- if (params.sortBy === 'segmentDesc') {
32
- return message2.channelSegment - message1.channelSegment;
33
- }
34
- return 0;
35
- });
36
-
37
- return messages;
38
- };
39
-
40
6
  /* begin_public_function
41
7
  id: message.query
42
8
  */
@@ -14,7 +14,7 @@ import {
14
14
  // makes it easier to spy on applyFilter
15
15
  import * as getUsersModule from '../getUsers';
16
16
 
17
- const { getUsers, applyFilter } = getUsersModule;
17
+ const { getUsers } = getUsersModule;
18
18
 
19
19
  const getSnapshot = (params?: Record<string, any>) => {
20
20
  return {
@@ -174,47 +174,5 @@ describe('getUsers', () => {
174
174
  ),
175
175
  );
176
176
  });
177
-
178
- test('it should apply filters on RTE only', async () => {
179
- const callback = jest.fn();
180
- const applyFilterSpy = jest.spyOn(getUsersModule, 'applyFilter');
181
- client.http.get = jest.fn().mockResolvedValue(userQueryResponse);
182
-
183
- getUsers(params, callback);
184
- await pause();
185
-
186
- expect(applyFilterSpy).not.toHaveBeenCalled();
187
-
188
- client.emitter.emit('user.updated', { users: [updatedUser], files: [] });
189
- await pause();
190
-
191
- expect(applyFilterSpy).toHaveBeenCalled();
192
- });
193
- });
194
- });
195
-
196
- describe('getUsers > applyFilter', () => {
197
- const u1 = {
198
- userId: 'test',
199
- displayName: 'a',
200
- createdAt: new Date().toISOString(),
201
- } as Amity.InternalUser;
202
-
203
- const u2 = {
204
- userId: 'searchable',
205
- displayName: 'b',
206
- createdAt: getPastDate(),
207
- } as Amity.InternalUser;
208
-
209
- const filters: [string, Amity.UserLiveCollection, Amity.InternalUser[], Amity.InternalUser[]][] =
210
- [
211
- ['it should filter by display name', { displayName: 'a' }, [u1, u2], [u1]],
212
- ['it should sort by dispaly name', {}, [u1, u2], [u1, u2]],
213
- ['it should sort by last created', { sortBy: 'lastCreated' }, [u1, u2], [u1, u2]],
214
- ['it should sort by first created', { sortBy: 'firstCreated' }, [u1, u2], [u2, u1]],
215
- ];
216
-
217
- test.each(filters)('%s', (test, param, input, expected) => {
218
- expect(applyFilter(input, param)).toStrictEqual(expected);
219
177
  });
220
178
  });