@amityco/ts-sdk 6.29.1 → 6.29.2-5977448.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 (82) hide show
  1. package/.env +26 -26
  2. package/dist/@types/core/payload.d.ts +15 -5
  3. package/dist/@types/core/payload.d.ts.map +1 -1
  4. package/dist/@types/domains/community.d.ts +30 -8
  5. package/dist/@types/domains/community.d.ts.map +1 -1
  6. package/dist/@types/domains/user.d.ts +34 -6
  7. package/dist/@types/domains/user.d.ts.map +1 -1
  8. package/dist/channelRepository/channelMembership/observers/getMembers/ChannelMemberPaginationController.d.ts +2 -1
  9. package/dist/channelRepository/channelMembership/observers/getMembers/ChannelMemberPaginationController.d.ts.map +1 -1
  10. package/dist/channelRepository/observers/getChannels/ChannelPaginationController.d.ts +3 -2
  11. package/dist/channelRepository/observers/getChannels/ChannelPaginationController.d.ts.map +1 -1
  12. package/dist/group/utils/withUser.d.ts +13 -0
  13. package/dist/group/utils/withUser.d.ts.map +1 -1
  14. package/dist/index.cjs.js +722 -563
  15. package/dist/index.esm.js +722 -563
  16. package/dist/index.umd.js +1 -1
  17. package/dist/report/api/createReport.d.ts +1 -2
  18. package/dist/report/api/createReport.d.ts.map +1 -1
  19. package/dist/report/api/deleteReport.d.ts +1 -2
  20. package/dist/report/api/deleteReport.d.ts.map +1 -1
  21. package/dist/report/api/isReportedByMe.d.ts +1 -2
  22. package/dist/report/api/isReportedByMe.d.ts.map +1 -1
  23. package/dist/userRepository/api/flagUser.d.ts.map +1 -1
  24. package/dist/userRepository/api/getUser.d.ts.map +1 -1
  25. package/dist/userRepository/api/getUserByIds.d.ts.map +1 -1
  26. package/dist/userRepository/api/queryBlockedUsers.d.ts.map +1 -1
  27. package/dist/userRepository/api/queryUsers.d.ts.map +1 -1
  28. package/dist/userRepository/api/unflagUser.d.ts.map +1 -1
  29. package/dist/userRepository/api/updateUser.d.ts.map +1 -1
  30. package/dist/userRepository/events/utils.d.ts.map +1 -1
  31. package/dist/userRepository/internalApi/getUser.d.ts.map +1 -1
  32. package/dist/userRepository/internalApi/queryUsers.d.ts.map +1 -1
  33. package/dist/userRepository/observers/enums.d.ts +8 -0
  34. package/dist/userRepository/observers/enums.d.ts.map +1 -0
  35. package/dist/userRepository/observers/getUsers/UserLiveCollectionController.d.ts +14 -0
  36. package/dist/userRepository/observers/getUsers/UserLiveCollectionController.d.ts.map +1 -0
  37. package/dist/userRepository/observers/getUsers/UserPaginationController.d.ts +5 -0
  38. package/dist/userRepository/observers/getUsers/UserPaginationController.d.ts.map +1 -0
  39. package/dist/userRepository/observers/getUsers/UserQueryStreamController.d.ts +15 -0
  40. package/dist/userRepository/observers/getUsers/UserQueryStreamController.d.ts.map +1 -0
  41. package/dist/userRepository/observers/getUsers.d.ts +0 -1
  42. package/dist/userRepository/observers/getUsers.d.ts.map +1 -1
  43. package/dist/userRepository/observers/searchUserByDisplayName/SearchUserLiveCollectionController.d.ts +14 -0
  44. package/dist/userRepository/observers/searchUserByDisplayName/SearchUserLiveCollectionController.d.ts.map +1 -0
  45. package/dist/userRepository/observers/searchUserByDisplayName/SearchUserPaginationController.d.ts +5 -0
  46. package/dist/userRepository/observers/searchUserByDisplayName/SearchUserPaginationController.d.ts.map +1 -0
  47. package/dist/userRepository/observers/searchUserByDisplayName/SearchUserQueryStreamController.d.ts +15 -0
  48. package/dist/userRepository/observers/searchUserByDisplayName/SearchUserQueryStreamController.d.ts.map +1 -0
  49. package/dist/userRepository/observers/searchUserByDisplayName.d.ts.map +1 -1
  50. package/dist/userRepository/utils/index.d.ts +3 -0
  51. package/dist/userRepository/utils/index.d.ts.map +1 -0
  52. package/dist/utils/tests/dummy/user.d.ts +10 -2
  53. package/dist/utils/tests/dummy/user.d.ts.map +1 -1
  54. package/package.json +1 -1
  55. package/src/@types/core/payload.ts +17 -6
  56. package/src/@types/domains/community.ts +38 -12
  57. package/src/@types/domains/user.ts +49 -6
  58. package/src/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.ts +3 -3
  59. package/src/group/utils/withUser.ts +35 -0
  60. package/src/report/api/createReport.ts +100 -31
  61. package/src/report/api/deleteReport.ts +100 -31
  62. package/src/report/api/isReportedByMe.ts +72 -11
  63. package/src/userRepository/api/flagUser.ts +5 -2
  64. package/src/userRepository/api/getUser.ts +4 -43
  65. package/src/userRepository/api/getUserByIds.ts +5 -2
  66. package/src/userRepository/api/queryBlockedUsers.ts +6 -6
  67. package/src/userRepository/api/queryUsers.ts +11 -87
  68. package/src/userRepository/api/unflagUser.ts +5 -2
  69. package/src/userRepository/api/updateUser.ts +5 -11
  70. package/src/userRepository/events/utils.ts +4 -1
  71. package/src/userRepository/internalApi/getUser.ts +12 -16
  72. package/src/userRepository/internalApi/queryUsers.ts +7 -4
  73. package/src/userRepository/observers/enums.ts +7 -0
  74. package/src/userRepository/observers/getUsers/UserLiveCollectionController.ts +131 -0
  75. package/src/userRepository/observers/getUsers/UserPaginationController.ts +25 -0
  76. package/src/userRepository/observers/getUsers/UserQueryStreamController.ts +82 -0
  77. package/src/userRepository/observers/getUsers.ts +7 -137
  78. package/src/userRepository/observers/searchUserByDisplayName/SearchUserLiveCollectionController.ts +116 -0
  79. package/src/userRepository/observers/searchUserByDisplayName/SearchUserPaginationController.ts +25 -0
  80. package/src/userRepository/observers/searchUserByDisplayName/SearchUserQueryStreamController.ts +82 -0
  81. package/src/userRepository/observers/searchUserByDisplayName.ts +25 -1
  82. package/src/userRepository/utils/index.ts +13 -0
package/dist/index.cjs.js CHANGED
@@ -7677,9 +7677,20 @@ const onChannelMemberBanned = (callback) => {
7677
7677
  return createEventSubscriber(client, 'onChannelMemberBanned', 'channel.banned', filter);
7678
7678
  };
7679
7679
 
7680
+ function convertRawUserToInternalUser(rawUser) {
7681
+ return Object.assign(Object.assign({}, rawUser), { isGlobalBanned: rawUser.isGlobalBan });
7682
+ }
7683
+ function prepareUserPayload(response) {
7684
+ return {
7685
+ users: response.users.map(convertRawUserToInternalUser),
7686
+ files: response.files,
7687
+ };
7688
+ }
7689
+
7680
7690
  const createUserEventSubscriber = (event, callback) => {
7681
7691
  const client = getActiveClient();
7682
- const filter = (payload) => {
7692
+ const filter = (data) => {
7693
+ const payload = prepareUserPayload(data);
7683
7694
  if (client.cache) {
7684
7695
  ingestInCache(payload);
7685
7696
  }
@@ -9915,18 +9926,17 @@ const queryBlockedUsers = async (query) => {
9915
9926
  const { data } = await client.http.get('/api/v4/me/user-blocks', {
9916
9927
  params,
9917
9928
  });
9918
- const { paging } = data, blockedUsers = __rest(data, ["paging"]);
9919
- const { users } = blockedUsers;
9929
+ const payload = prepareUserPayload(data);
9920
9930
  const cachedAt = client.cache && Date.now();
9921
9931
  if (client.cache) {
9922
- ingestInCache(blockedUsers, { cachedAt });
9932
+ ingestInCache(payload, { cachedAt });
9923
9933
  const cacheKey = ['blockedUsers', 'query', params];
9924
- pushToCache(cacheKey, { users: users.map(getResolver('user')), paging });
9934
+ pushToCache(cacheKey, { users: payload.users.map(getResolver('user')), paging: data.paging });
9925
9935
  }
9926
- const { next, previous, total } = paging;
9936
+ const { next, previous, total } = data.paging;
9927
9937
  const nextPage = toPageRaw(next);
9928
9938
  const prevPage = toPageRaw(previous);
9929
- return { data: users, prevPage, nextPage, total, cachedAt };
9939
+ return { data: payload.users, prevPage, nextPage, total, cachedAt };
9930
9940
  };
9931
9941
  /**
9932
9942
  * ```js
@@ -11006,12 +11016,13 @@ const getUserByIds = async (userIds) => {
11006
11016
  const { data } = await client.http.get(`/api/v3/users/list`, {
11007
11017
  params: { userIds: encodedUserIds },
11008
11018
  });
11019
+ const payload = prepareUserPayload(data);
11009
11020
  const cachedAt = client.cache && Date.now();
11010
11021
  if (client.cache)
11011
- ingestInCache(data, { cachedAt });
11022
+ ingestInCache(payload, { cachedAt });
11012
11023
  fireEvent('user.fetched', data);
11013
11024
  return {
11014
- data: data.users.map(user => LinkedObject.user(user)),
11025
+ data: payload.users.map(user => LinkedObject.user(user)),
11015
11026
  cachedAt,
11016
11027
  };
11017
11028
  };
@@ -11069,20 +11080,14 @@ getUserByIds.locally = (userIds) => {
11069
11080
  const updateUser = async (userId, patch) => {
11070
11081
  const client = getActiveClient();
11071
11082
  client.log('user/updateUser', userId, patch);
11072
- // API-FIX: Endpoint is malformed, userId should be a url param.
11073
- /*
11074
- const { data } = await client.http.put<Amity.Response<UserPayload>>(
11075
- `/api/v3/users/${userId}`, patch,
11076
- )
11077
- */
11078
11083
  const { data } = await client.http.put(`/api/v3/users/`, Object.assign(Object.assign({ userId }, patch), { createNewUserWhenNotFound: false }));
11084
+ const payload = prepareUserPayload(data);
11079
11085
  const cachedAt = client.cache && Date.now();
11080
11086
  if (client.cache)
11081
- ingestInCache(data, { cachedAt });
11082
- const { users } = data;
11087
+ ingestInCache(payload, { cachedAt });
11083
11088
  fireEvent('user.updated', data);
11084
11089
  return {
11085
- data: users.find(user => user.userId === userId),
11090
+ data: payload.users.find(user => user.userId === userId),
11086
11091
  cachedAt,
11087
11092
  };
11088
11093
  };
@@ -11106,11 +11111,12 @@ const updateUser = async (userId, patch) => {
11106
11111
  const flagUser = async (userId) => {
11107
11112
  const client = getActiveClient();
11108
11113
  client.log('user/flagUser', userId);
11109
- const { data: payload } = await client.http.post(`api/v4/me/flags/${encodeURIComponent(userId)}`);
11114
+ const { data } = await client.http.post(`api/v4/me/flags/${encodeURIComponent(userId)}`);
11115
+ const payload = prepareUserPayload(data);
11110
11116
  if (client.cache) {
11111
11117
  ingestInCache(payload);
11112
11118
  }
11113
- fireEvent('user.flagged', payload);
11119
+ fireEvent('user.flagged', data);
11114
11120
  return !!payload;
11115
11121
  };
11116
11122
  /* end_public_function */
@@ -11133,11 +11139,12 @@ const flagUser = async (userId) => {
11133
11139
  const unflagUser = async (userId) => {
11134
11140
  const client = getActiveClient();
11135
11141
  client.log('user/unflag', userId);
11136
- const { data: payload } = await client.http.delete(`/api/v4/me/flags/${encodeURIComponent(userId)}`);
11142
+ const { data } = await client.http.delete(`/api/v4/me/flags/${encodeURIComponent(userId)}`);
11143
+ const payload = prepareUserPayload(data);
11137
11144
  if (client.cache) {
11138
11145
  ingestInCache(payload);
11139
11146
  }
11140
- fireEvent('user.unflagged', payload);
11147
+ fireEvent('user.unflagged', data);
11141
11148
  return !!payload;
11142
11149
  };
11143
11150
  /* end_public_function */
@@ -11268,10 +11275,17 @@ const getUser$2 = async (userId) => {
11268
11275
  const client = getActiveClient();
11269
11276
  client.log('user/getUser', userId);
11270
11277
  isInTombstone('user', userId);
11271
- let data;
11272
11278
  try {
11273
- const response = await client.http.get(`/api/v3/users/${encodeURIComponent(userId)}`);
11274
- data = response.data;
11279
+ const { data } = await client.http.get(`/api/v3/users/${encodeURIComponent(userId)}`);
11280
+ const cachedAt = client.cache && Date.now();
11281
+ const payload = prepareUserPayload(data);
11282
+ if (client.cache)
11283
+ ingestInCache(payload, { cachedAt });
11284
+ fireEvent('user.fetched', data);
11285
+ return {
11286
+ data: payload.users.find(user => user.userId === userId),
11287
+ cachedAt,
11288
+ };
11275
11289
  }
11276
11290
  catch (error) {
11277
11291
  if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
@@ -11279,15 +11293,6 @@ const getUser$2 = async (userId) => {
11279
11293
  }
11280
11294
  throw error;
11281
11295
  }
11282
- const cachedAt = client.cache && Date.now();
11283
- if (client.cache)
11284
- ingestInCache(data, { cachedAt });
11285
- const { users } = data;
11286
- fireEvent('user.fetched', data);
11287
- return {
11288
- data: users.find(user => user.userId === userId),
11289
- cachedAt,
11290
- };
11291
11296
  };
11292
11297
  /**
11293
11298
  * ```js
@@ -11353,204 +11358,349 @@ const getUser$1 = (userId, callback) => {
11353
11358
  };
11354
11359
  /* end_public_function */
11355
11360
 
11356
- /**
11357
- * ```js
11358
- * import { queryUsers } from '@amityco/ts-sdk'
11359
- * const { data: users, prevPage, nextPage } = await queryUsers({ displayName: 'foo' })
11360
- * ```
11361
- *
11362
- * Queries a paginable list of {@link Amity.InternalUser} objects
11363
- * Search is performed by displayName such as `.startsWith(search)`
11364
- *
11365
- * @param query The query parameters
11366
- * @returns A page of {@link Amity.InternalUser} objects
11367
- *
11368
- * @category User API
11369
- * @async
11370
- */
11371
- const queryUsers = async (query = {}) => {
11372
- const client = getActiveClient();
11373
- client.log('user/queryUsers', query);
11374
- const { page, limit = 10, displayName, filter = 'all', sortBy = 'displayName' } = query, params = __rest(query, ["page", "limit", "displayName", "filter", "sortBy"]);
11375
- const { data } = await client.http.get(`/api/v3/users`, {
11376
- params: Object.assign(Object.assign({}, params), { keyword: displayName, filter,
11377
- sortBy, options: page ? { token: page } : { limit } }),
11378
- });
11379
- // unpacking
11380
- const { paging } = data, payload = __rest(data, ["paging"]);
11381
- const { users } = payload;
11382
- const cachedAt = client.cache && Date.now();
11383
- if (client.cache) {
11384
- ingestInCache(payload, { cachedAt });
11385
- /*
11386
- * using a query as a cache key over params because if the keyword, filter, sort
11387
- * change the API will NOT cache results, when it should
11388
- */
11389
- const cacheKey = [
11390
- 'user',
11391
- 'query',
11392
- Object.assign(Object.assign({}, query), { options: { limit, token: page } }),
11393
- ];
11394
- pushToCache(cacheKey, { users: users.map(getResolver('user')), paging });
11361
+ class PaginationController {
11362
+ constructor(queryParams) {
11363
+ const { http } = getActiveClient();
11364
+ this.queryParams = queryParams;
11365
+ this.http = http;
11395
11366
  }
11396
- fireEvent('user.fetched', data);
11397
- return {
11398
- data: users,
11399
- cachedAt,
11400
- paging,
11401
- };
11402
- };
11403
- /**
11404
- * ```js
11405
- * import { queryUsers } from '@amityco/ts-sdk'
11406
- * const { data: users } = queryUsers.locally({ keyword: 'foo' })
11407
- * ```
11408
- *
11409
- * Queries a paginable list of {@link Amity.InternalUser} objects from cache
11410
- * Search is performed by displayName such as `.startsWith(search)`
11411
- *
11412
- * @param query The query parameters
11413
- * @returns A page of {@link Amity.InternalUser} objects
11414
- *
11415
- * @category User API
11416
- */
11417
- queryUsers.locally = (query = {}) => {
11418
- var _a, _b, _c;
11419
- const client = getActiveClient();
11420
- client.log('user/queryUsers.locally', query);
11421
- if (!client.cache)
11422
- return;
11423
- const { limit = 10, page } = query !== null && query !== void 0 ? query : {};
11424
- const cacheKey = [
11425
- 'user',
11426
- 'query',
11427
- Object.assign(Object.assign({}, query), { options: {
11428
- limit,
11429
- token: page,
11430
- } }),
11431
- ];
11432
- const { data, cachedAt } = (_a = pullFromCache(cacheKey)) !== null && _a !== void 0 ? _a : {};
11433
- const users = (_b = data === null || data === void 0 ? void 0 : data.users.map(userId => pullFromCache(['user', 'get', userId])).filter(Boolean).map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
11434
- return users.length > 0 && users.length === ((_c = data === null || data === void 0 ? void 0 : data.users) === null || _c === void 0 ? void 0 : _c.length)
11435
- ? {
11436
- data: users,
11437
- cachedAt,
11438
- paging: data === null || data === void 0 ? void 0 : data.paging,
11367
+ loadFirstPage() {
11368
+ return this.onFetch("first" /* Amity.LiveCollectionPageDirection.FIRST */);
11369
+ }
11370
+ loadNextPage() {
11371
+ return this.onFetch("next" /* Amity.LiveCollectionPageDirection.NEXT */);
11372
+ }
11373
+ loadPreviousPage() {
11374
+ return this.onFetch("prev" /* Amity.LiveCollectionPageDirection.PREV */);
11375
+ }
11376
+ async onFetch(direction = "first" /* Amity.LiveCollectionPageDirection.FIRST */) {
11377
+ var _a, _b, _c, _d;
11378
+ if (direction === 'prev' && !this.previousToken)
11379
+ return;
11380
+ if (direction === 'next' && !this.nextToken)
11381
+ return;
11382
+ let token;
11383
+ if (direction === 'prev')
11384
+ token = this.previousToken;
11385
+ if (direction === 'next')
11386
+ token = this.nextToken;
11387
+ const queryResponse = await this.getRequest(this.queryParams, token);
11388
+ if (direction === 'first') {
11389
+ this.nextToken = (_a = queryResponse.paging) === null || _a === void 0 ? void 0 : _a.next;
11390
+ this.previousToken = (_b = queryResponse.paging) === null || _b === void 0 ? void 0 : _b.previous;
11439
11391
  }
11440
- : undefined;
11441
- };
11392
+ if (direction === 'prev')
11393
+ this.previousToken = (_c = queryResponse.paging) === null || _c === void 0 ? void 0 : _c.previous;
11394
+ if (direction === 'next')
11395
+ this.nextToken = (_d = queryResponse.paging) === null || _d === void 0 ? void 0 : _d.next;
11396
+ return queryResponse;
11397
+ }
11398
+ getNextToken() {
11399
+ return this.nextToken;
11400
+ }
11401
+ getPrevToken() {
11402
+ return this.previousToken;
11403
+ }
11404
+ }
11442
11405
 
11443
- /*
11444
- * Exported for testing
11445
- * @hidden
11446
- */
11447
- const applyFilter$2 = (data, params) => {
11448
- let users = filterByStringComparePartially(data, 'displayName', params.displayName);
11449
- switch (params.sortBy) {
11450
- case 'firstCreated':
11451
- users = users.sort(sortByFirstCreated);
11452
- break;
11453
- case 'lastCreated':
11454
- users = users.sort(sortByLastCreated);
11455
- break;
11456
- default:
11457
- users = users
11458
- // this needs to be aligned with the backend data type
11459
- .map(u => (u.displayName ? u : Object.assign(Object.assign({}, u), { displayName: '' })))
11460
- .sort(sortByDisplayName);
11406
+ class UserPaginationController extends PaginationController {
11407
+ async getRequest(queryParams, token) {
11408
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, displayName } = queryParams, params = __rest(queryParams, ["limit", "displayName"]);
11409
+ const options = token ? { token } : { limit };
11410
+ const { data: queryResponse } = await this.http.get(`/api/v3/users`, {
11411
+ params: Object.assign(Object.assign({}, params), { keyword: displayName, options, isDeleted: false }),
11412
+ });
11413
+ return queryResponse;
11461
11414
  }
11462
- return users;
11463
- };
11464
- /* begin_public_function
11465
- id: user.query
11466
- */
11467
- /**
11468
- * ```js
11469
- * import { liveUsers } from '@amityco/ts-sdk'
11470
- *
11471
- * let users = []
11472
- * const unsub = liveUsers({}, response => merge(users, response.data))
11473
- * ```
11474
- *
11475
- * Observe all mutations on a list of {@link Amity.User}s
11476
- *
11477
- * @param params for querying users
11478
- * @param callback the function to call when new data are available
11479
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the users
11480
- *
11481
- * @category Category Live Collection
11482
- */
11483
- const getUsers = (params, callback, config) => {
11484
- const { log, cache } = getActiveClient();
11485
- if (!cache) {
11486
- // eslint-disable-next-line no-console
11487
- console.log(ENABLE_CACHE_MESSAGE);
11415
+ }
11416
+
11417
+ class QueryStreamController {
11418
+ constructor(query, cacheKey) {
11419
+ this.query = query;
11420
+ this.cacheKey = cacheKey;
11488
11421
  }
11489
- const timestamp = Date.now();
11490
- log(`liveUsers(tmpid: ${timestamp}) > listen`);
11491
- const { limit: queryLimit } = params, queryParams = __rest(params, ["limit"]);
11492
- const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
11493
- const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
11494
- const disposers = [];
11495
- const cacheKey = ['user', 'collection', uuid()];
11496
- const responder = (data, isEventModel = false) => {
11422
+ }
11423
+
11424
+ class UserQueryStreamController extends QueryStreamController {
11425
+ constructor(query, cacheKey, notifyChange, preparePayload) {
11426
+ super(query, cacheKey);
11427
+ this.notifyChange = notifyChange;
11428
+ this.preparePayload = preparePayload;
11429
+ }
11430
+ async saveToMainDB(response) {
11431
+ const processedPayload = await this.preparePayload(response);
11432
+ const client = getActiveClient();
11433
+ const cachedAt = client.cache && Date.now();
11434
+ if (client.cache) {
11435
+ ingestInCache(processedPayload, { cachedAt });
11436
+ }
11437
+ }
11438
+ appendToQueryStream(response, direction, refresh = false) {
11497
11439
  var _a, _b;
11498
- const users = (_a = data.data
11499
- .map(userId => pullFromCache(['user', 'get', userId]))
11500
- .filter(Boolean)
11501
- .map(({ data }) => LinkedObject.user(data))) !== null && _a !== void 0 ? _a : [];
11502
- callback({
11503
- onNextPage: onFetch,
11440
+ if (refresh) {
11441
+ pushToCache(this.cacheKey, {
11442
+ data: response.users.map(getResolver('user')),
11443
+ });
11444
+ }
11445
+ else {
11446
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
11447
+ const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
11448
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...users, ...response.users.map(getResolver('user'))])] }));
11449
+ }
11450
+ }
11451
+ reactor(action) {
11452
+ return (user) => {
11453
+ var _a;
11454
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
11455
+ if (!collection)
11456
+ return;
11504
11457
  /*
11505
- * Only apply filter to RTE Model
11458
+ * Simply update a collection and let responder decide what to do with data
11506
11459
  */
11507
- data: isEventModel ? applyFilter$2(users, params) : users,
11508
- hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
11509
- loading: data.loading,
11510
- error: data.error,
11511
- });
11512
- };
11513
- const realtimeRouter = (_) => (user) => {
11514
- var _a;
11515
- const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
11516
- if (!collection)
11517
- return;
11518
- collection.data = [...new Set([user.userId, ...collection.data])];
11519
- pushToCache(cacheKey, collection);
11520
- responder(collection, true);
11521
- };
11522
- const onFetch = (initial = false) => {
11523
- var _a, _b;
11524
- const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
11525
- const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
11526
- if (!initial && users.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
11527
- return;
11528
- const pagingCondition = initial ? { limit } : { page: collection === null || collection === void 0 ? void 0 : collection.params.page };
11529
- const query = createQuery(queryUsers, Object.assign(Object.assign({}, queryParams), pagingCondition));
11530
- runQuery(query, ({ data: result, error, loading, paging }) => {
11531
- const data = {
11532
- loading,
11533
- error,
11534
- params: { page: paging === null || paging === void 0 ? void 0 : paging.next },
11535
- data: users,
11536
- };
11537
- if (result) {
11538
- data.data = initial
11539
- ? result.map(getResolver('user'))
11540
- : [...new Set([...users, ...result.map(getResolver('user'))])];
11541
- }
11542
- pushToCache(cacheKey, data);
11543
- responder(data);
11544
- }, queryOptions(policy));
11545
- };
11546
- disposers.push(onUserUpdated(realtimeRouter()), onUserDeleted(realtimeRouter()), onUserFlagged(realtimeRouter()), onUserUnflagged(realtimeRouter()), onUserFlagCleared(realtimeRouter()));
11547
- onFetch(true);
11548
- return () => {
11549
- log(`liveUsers(tmpid: ${timestamp}) > dispose`);
11550
- disposers.forEach(fn => fn());
11551
- };
11552
- };
11553
- /* end_public_function */
11460
+ collection.data = [...new Set([user.userId, ...collection.data])];
11461
+ pushToCache(this.cacheKey, collection);
11462
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
11463
+ };
11464
+ }
11465
+ subscribeRTE(createSubscriber) {
11466
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
11467
+ }
11468
+ }
11469
+
11470
+ class PaginationNoPageController {
11471
+ constructor(queryParams) {
11472
+ const { http } = getActiveClient();
11473
+ this.queryParams = queryParams;
11474
+ this.http = http;
11475
+ }
11476
+ async onFetch() {
11477
+ const queryResponse = await this.getRequest(this.queryParams);
11478
+ return queryResponse;
11479
+ }
11480
+ }
11481
+
11482
+ class LiveCollectionController {
11483
+ constructor(paginationController, queryStreamId, cacheKey, callback) {
11484
+ this.paginationController = paginationController;
11485
+ this.queryStreamId = queryStreamId;
11486
+ this.cacheKey = cacheKey;
11487
+ this.callback = callback;
11488
+ }
11489
+ async refresh() {
11490
+ try {
11491
+ let result;
11492
+ if (this.paginationController instanceof PaginationNoPageController) {
11493
+ result = await this.paginationController.onFetch();
11494
+ }
11495
+ else {
11496
+ result = await this.paginationController.loadFirstPage();
11497
+ }
11498
+ if (!result)
11499
+ return;
11500
+ await this.persistModel(result);
11501
+ this.persistQueryStream({
11502
+ response: result,
11503
+ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
11504
+ refresh: true,
11505
+ });
11506
+ this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
11507
+ }
11508
+ catch (e) {
11509
+ this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
11510
+ }
11511
+ }
11512
+ loadPage({ initial = false, direction = "next" /* Amity.LiveCollectionPageDirection.NEXT */, }) {
11513
+ this.setup();
11514
+ this.notifyChange({ origin: "local" /* Amity.LiveDataOrigin.LOCAL */, loading: true });
11515
+ if (initial) {
11516
+ this.refresh();
11517
+ }
11518
+ else if (direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */) {
11519
+ this.loadPrevPage();
11520
+ }
11521
+ else if (direction === "next" /* Amity.LiveCollectionPageDirection.NEXT */) {
11522
+ this.loadNextPage();
11523
+ }
11524
+ }
11525
+ async loadNextPage() {
11526
+ try {
11527
+ if (this.paginationController instanceof PaginationNoPageController)
11528
+ return;
11529
+ const result = await this.paginationController.loadNextPage();
11530
+ if (!result)
11531
+ return;
11532
+ await this.persistModel(result);
11533
+ this.persistQueryStream({
11534
+ response: result,
11535
+ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
11536
+ });
11537
+ this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
11538
+ }
11539
+ catch (e) {
11540
+ this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
11541
+ }
11542
+ }
11543
+ async loadPrevPage() {
11544
+ try {
11545
+ if (this.paginationController instanceof PaginationNoPageController)
11546
+ return;
11547
+ const result = await this.paginationController.loadPreviousPage();
11548
+ if (!result)
11549
+ return;
11550
+ await this.persistModel(result);
11551
+ this.persistQueryStream({
11552
+ response: result,
11553
+ direction: "prev" /* Amity.LiveCollectionPageDirection.PREV */,
11554
+ });
11555
+ this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
11556
+ }
11557
+ catch (e) {
11558
+ this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
11559
+ }
11560
+ }
11561
+ shouldNotify(data) {
11562
+ const newData = data.map(convertGetterPropsToStatic).map(removeFunctionProperties);
11563
+ if (isEqual(this.snapshot, newData))
11564
+ return false;
11565
+ this.snapshot = newData;
11566
+ return true;
11567
+ }
11568
+ getCacheKey() {
11569
+ return this.cacheKey;
11570
+ }
11571
+ }
11572
+
11573
+ var EnumUserActions;
11574
+ (function (EnumUserActions) {
11575
+ EnumUserActions["OnUserDeleted"] = "onUserDeleted";
11576
+ EnumUserActions["OnUserUpdated"] = "onUserUpdated";
11577
+ EnumUserActions["OnUserFlagged"] = "onUserFlagged";
11578
+ EnumUserActions["OnUserUnflagged"] = "onUserUnflagged";
11579
+ EnumUserActions["OnUserFlagCleared"] = "onUserFlagCleared";
11580
+ })(EnumUserActions || (EnumUserActions = {}));
11581
+
11582
+ function isNonNullable(value) {
11583
+ return value != null;
11584
+ }
11585
+
11586
+ class UserLiveCollectionController extends LiveCollectionController {
11587
+ constructor(query, callback) {
11588
+ const queryStreamId = hash__default["default"](query);
11589
+ const cacheKey = ['user', 'collection', queryStreamId];
11590
+ const paginationController = new UserPaginationController(query);
11591
+ super(paginationController, queryStreamId, cacheKey, callback);
11592
+ this.query = query;
11593
+ this.queryStreamController = new UserQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareUserPayload);
11594
+ this.callback = callback.bind(this);
11595
+ this.loadPage({ initial: true });
11596
+ }
11597
+ setup() {
11598
+ var _a;
11599
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
11600
+ if (!collection) {
11601
+ pushToCache(this.cacheKey, {
11602
+ data: [],
11603
+ params: {},
11604
+ });
11605
+ }
11606
+ }
11607
+ async persistModel(queryPayload) {
11608
+ await this.queryStreamController.saveToMainDB(queryPayload);
11609
+ }
11610
+ persistQueryStream({ response, direction, refresh, }) {
11611
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
11612
+ }
11613
+ startSubscription() {
11614
+ return this.queryStreamController.subscribeRTE([
11615
+ { fn: onUserDeleted, action: EnumUserActions.OnUserDeleted },
11616
+ { fn: onUserUpdated, action: EnumUserActions.OnUserUpdated },
11617
+ { fn: onUserFlagged, action: EnumUserActions.OnUserFlagged },
11618
+ { fn: onUserUnflagged, action: EnumUserActions.OnUserUnflagged },
11619
+ { fn: onUserFlagCleared, action: EnumUserActions.OnUserFlagCleared },
11620
+ ]);
11621
+ }
11622
+ notifyChange({ origin, loading, error }) {
11623
+ var _a, _b;
11624
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
11625
+ if (!collection)
11626
+ return;
11627
+ const data = this.applyFilter((_b = collection.data
11628
+ .map(id => pullFromCache(['user', 'get', id]))
11629
+ .filter(isNonNullable)
11630
+ .map(({ data }) => data)
11631
+ .map(LinkedObject.user)) !== null && _b !== void 0 ? _b : []);
11632
+ if (!this.shouldNotify(data) && origin === 'event')
11633
+ return;
11634
+ this.callback({
11635
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
11636
+ data,
11637
+ hasNextPage: !!this.paginationController.getNextToken(),
11638
+ loading,
11639
+ error,
11640
+ });
11641
+ }
11642
+ applyFilter(data) {
11643
+ let users = data;
11644
+ if (!this.query.displayName) {
11645
+ const sortFn = (() => {
11646
+ switch (this.query.sortBy) {
11647
+ case Amity.UserSortByEnum.FirstCreated:
11648
+ return sortByFirstCreated;
11649
+ case Amity.UserSortByEnum.LastCreated:
11650
+ return sortByLastCreated;
11651
+ case Amity.UserSortByEnum.DisplayName:
11652
+ return sortByDisplayName;
11653
+ default:
11654
+ return sortByLastCreated;
11655
+ }
11656
+ })();
11657
+ users = users.sort(sortFn);
11658
+ }
11659
+ if (this.query.filter === 'flagged') {
11660
+ users = users.filter(user => !!user.hashFlag);
11661
+ }
11662
+ users = users.filter(user => user.isDeleted == null || user.isDeleted === false);
11663
+ return users;
11664
+ }
11665
+ }
11666
+
11667
+ /* begin_public_function
11668
+ id: user.query
11669
+ */
11670
+ /**
11671
+ * ```js
11672
+ * import { liveUsers } from '@amityco/ts-sdk'
11673
+ *
11674
+ * let users = []
11675
+ * const unsub = liveUsers({}, response => merge(users, response.data))
11676
+ * ```
11677
+ *
11678
+ * Observe all mutations on a list of {@link Amity.User}s
11679
+ *
11680
+ * @param params for querying users
11681
+ * @param callback the function to call when new data are available
11682
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the users
11683
+ *
11684
+ * @category Category Live Collection
11685
+ */
11686
+ const getUsers = (params, callback, config) => {
11687
+ const { log, cache } = getActiveClient();
11688
+ if (!cache) {
11689
+ // eslint-disable-next-line no-console
11690
+ console.log(ENABLE_CACHE_MESSAGE);
11691
+ }
11692
+ const timestamp = Date.now();
11693
+ log(`liveUsers(tmpid: ${timestamp}) > listen`);
11694
+ const usersLiveCollection = new UserLiveCollectionController(params, callback);
11695
+ const disposers = usersLiveCollection.startSubscription();
11696
+ const cacheKey = usersLiveCollection.getCacheKey();
11697
+ disposers.push(() => dropFromCache(cacheKey));
11698
+ return () => {
11699
+ log(`liveUsers(tmpid: ${timestamp}) > dispose`);
11700
+ disposers.forEach(fn => fn());
11701
+ };
11702
+ };
11703
+ /* end_public_function */
11554
11704
 
11555
11705
  /**
11556
11706
  * ```js
@@ -11567,27 +11717,9 @@ const getUsers = (params, callback, config) => {
11567
11717
  * @async
11568
11718
  */
11569
11719
  const getUser = async (userId) => {
11570
- const client = getActiveClient();
11571
- client.log('user/getUser', userId);
11572
- isInTombstone('user', userId);
11573
- let data;
11574
- try {
11575
- const response = await client.http.get(`/api/v3/users/${encodeURIComponent(userId)}`);
11576
- data = response.data;
11577
- }
11578
- catch (error) {
11579
- if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
11580
- pushToTombstone('user', userId);
11581
- }
11582
- throw error;
11583
- }
11584
- const cachedAt = client.cache && Date.now();
11585
- if (client.cache)
11586
- ingestInCache(data, { cachedAt });
11587
- const { users } = data;
11588
- fireEvent('user.fetched', data);
11720
+ const { data, cachedAt } = await getUser$2(userId);
11589
11721
  return {
11590
- data: LinkedObject.user(users.find(user => user.userId === userId)),
11722
+ data: LinkedObject.user(data),
11591
11723
  cachedAt,
11592
11724
  };
11593
11725
  };
@@ -11605,11 +11737,7 @@ const getUser = async (userId) => {
11605
11737
  * @category User API
11606
11738
  */
11607
11739
  getUser.locally = (userId) => {
11608
- const client = getActiveClient();
11609
- client.log('user/getUser.locally', userId);
11610
- if (!client.cache)
11611
- return;
11612
- const cached = pullFromCache(['user', 'get', userId]);
11740
+ const cached = getUser$2.locally(userId);
11613
11741
  if (!cached)
11614
11742
  return;
11615
11743
  return {
@@ -11659,6 +11787,130 @@ const observeUser = (userId, callback) => {
11659
11787
  };
11660
11788
  };
11661
11789
 
11790
+ class SearchUserPaginationController extends PaginationController {
11791
+ async getRequest(queryParams, token) {
11792
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, displayName } = queryParams, params = __rest(queryParams, ["limit", "displayName"]);
11793
+ const options = token ? { token } : { limit };
11794
+ const { data: queryResponse } = await this.http.get(`/api/v3/users`, {
11795
+ params: Object.assign(Object.assign({}, params), { keyword: displayName, options, isDeleted: false }),
11796
+ });
11797
+ return queryResponse;
11798
+ }
11799
+ }
11800
+
11801
+ class SearchUserQueryStreamController extends QueryStreamController {
11802
+ constructor(query, cacheKey, notifyChange, preparePayload) {
11803
+ super(query, cacheKey);
11804
+ this.notifyChange = notifyChange;
11805
+ this.preparePayload = preparePayload;
11806
+ }
11807
+ async saveToMainDB(response) {
11808
+ const processedPayload = await this.preparePayload(response);
11809
+ const client = getActiveClient();
11810
+ const cachedAt = client.cache && Date.now();
11811
+ if (client.cache) {
11812
+ ingestInCache(processedPayload, { cachedAt });
11813
+ }
11814
+ }
11815
+ appendToQueryStream(response, direction, refresh = false) {
11816
+ var _a, _b;
11817
+ if (refresh) {
11818
+ pushToCache(this.cacheKey, {
11819
+ data: response.users.map(getResolver('user')),
11820
+ });
11821
+ }
11822
+ else {
11823
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
11824
+ const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
11825
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...users, ...response.users.map(getResolver('user'))])] }));
11826
+ }
11827
+ }
11828
+ reactor(action) {
11829
+ return (user) => {
11830
+ var _a;
11831
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
11832
+ if (!collection)
11833
+ return;
11834
+ /*
11835
+ * Simply update a collection and let responder decide what to do with data
11836
+ */
11837
+ collection.data = [...new Set([user.userId, ...collection.data])];
11838
+ pushToCache(this.cacheKey, collection);
11839
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
11840
+ };
11841
+ }
11842
+ subscribeRTE(createSubscriber) {
11843
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
11844
+ }
11845
+ }
11846
+
11847
+ class SearchUserLiveCollectionController extends LiveCollectionController {
11848
+ constructor(query, callback) {
11849
+ var _a;
11850
+ const queryStreamId = hash__default["default"](query);
11851
+ const cacheKey = ['user', 'collection', queryStreamId];
11852
+ const paginationController = new SearchUserPaginationController(query);
11853
+ super(paginationController, queryStreamId, cacheKey, callback);
11854
+ this.query = Object.assign(Object.assign({}, query), { filter: (_a = query.filter) !== null && _a !== void 0 ? _a : 'all' });
11855
+ this.queryStreamController = new SearchUserQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareUserPayload);
11856
+ this.callback = callback.bind(this);
11857
+ this.loadPage({ initial: true });
11858
+ }
11859
+ setup() {
11860
+ var _a;
11861
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
11862
+ if (!collection) {
11863
+ pushToCache(this.cacheKey, {
11864
+ data: [],
11865
+ params: {},
11866
+ });
11867
+ }
11868
+ }
11869
+ async persistModel(queryPayload) {
11870
+ await this.queryStreamController.saveToMainDB(queryPayload);
11871
+ }
11872
+ persistQueryStream({ response, direction, refresh, }) {
11873
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
11874
+ }
11875
+ startSubscription() {
11876
+ return this.queryStreamController.subscribeRTE([
11877
+ { fn: onUserDeleted, action: EnumUserActions.OnUserDeleted },
11878
+ { fn: onUserUpdated, action: EnumUserActions.OnUserUpdated },
11879
+ { fn: onUserFlagged, action: EnumUserActions.OnUserFlagged },
11880
+ { fn: onUserUnflagged, action: EnumUserActions.OnUserUnflagged },
11881
+ { fn: onUserFlagCleared, action: EnumUserActions.OnUserFlagCleared },
11882
+ ]);
11883
+ }
11884
+ notifyChange({ origin, loading, error }) {
11885
+ var _a, _b;
11886
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
11887
+ if (!collection)
11888
+ return;
11889
+ const data = this.applyFilter((_b = collection.data
11890
+ .map(id => pullFromCache(['user', 'get', id]))
11891
+ .filter(isNonNullable)
11892
+ .map(({ data }) => data)
11893
+ .map(LinkedObject.user)) !== null && _b !== void 0 ? _b : []);
11894
+ if (!this.shouldNotify(data) && origin === 'event')
11895
+ return;
11896
+ this.callback({
11897
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
11898
+ data,
11899
+ hasNextPage: !!this.paginationController.getNextToken(),
11900
+ loading,
11901
+ error,
11902
+ });
11903
+ }
11904
+ applyFilter(data) {
11905
+ let users = data;
11906
+ if (this.query.filter === 'flagged') {
11907
+ users = users.filter(user => !!user.hashFlag);
11908
+ }
11909
+ users = users.filter(user => user.isDeleted == null || user.isDeleted === false);
11910
+ return users;
11911
+ }
11912
+ }
11913
+
11662
11914
  /* begin_public_function
11663
11915
  id: user.search
11664
11916
  */
@@ -11680,7 +11932,21 @@ const observeUser = (userId, callback) => {
11680
11932
  * @category Category Live Collection
11681
11933
  */
11682
11934
  const searchUserByDisplayName = (params, callback, config) => {
11683
- return getUsers(Object.assign(Object.assign({}, params), { filter: 'all' }), callback, config);
11935
+ const { log, cache } = getActiveClient();
11936
+ if (!cache) {
11937
+ // eslint-disable-next-line no-console
11938
+ console.log(ENABLE_CACHE_MESSAGE);
11939
+ }
11940
+ const timestamp = Date.now();
11941
+ log(`liveSearchUsers(tmpid: ${timestamp}) > listen`);
11942
+ const searchUsersLiveCollection = new SearchUserLiveCollectionController(params, callback);
11943
+ const disposers = searchUsersLiveCollection.startSubscription();
11944
+ const cacheKey = searchUsersLiveCollection.getCacheKey();
11945
+ disposers.push(() => dropFromCache(cacheKey));
11946
+ return () => {
11947
+ log(`liveSearchUsers(tmpid: ${timestamp}) > dispose`);
11948
+ disposers.forEach(fn => fn());
11949
+ };
11684
11950
  };
11685
11951
  /* end_public_function */
11686
11952
 
@@ -13745,29 +14011,115 @@ var index$h = /*#__PURE__*/Object.freeze({
13745
14011
  getReactions: getReactions
13746
14012
  });
13747
14013
 
13748
- var REFERENCE_TYPES = {
13749
- post: {
13750
- domainName: 'posts',
13751
- eventName: 'v3/post.isflagbyme',
13752
- primaryKey: 'postId',
13753
- },
13754
- comment: {
13755
- domainName: 'comments',
13756
- eventName: 'v3/comment.isflagbyme',
13757
- primaryKey: 'commentId',
13758
- },
13759
- message: {
13760
- domainName: 'messages',
13761
- eventName: 'v3/message.isFlaggedByMe',
13762
- primaryKey: 'messageId',
13763
- },
13764
- user: {
13765
- domainName: 'users',
13766
- eventName: 'user.isFlagByMe',
13767
- primaryKey: 'userId',
13768
- },
14014
+ const getMatchPostSetting = (value) => {
14015
+ var _a;
14016
+ return (_a = Object.keys(CommunityPostSettingMaps).find(key => value.needApprovalOnPostCreation ===
14017
+ CommunityPostSettingMaps[key].needApprovalOnPostCreation &&
14018
+ value.onlyAdminCanPost === CommunityPostSettingMaps[key].onlyAdminCanPost)) !== null && _a !== void 0 ? _a : DefaultCommunityPostSetting;
14019
+ };
14020
+ const convertCommunityUsersToUniqueObject = (communityUsers) => {
14021
+ if (!communityUsers)
14022
+ return communityUsers;
14023
+ const result = {};
14024
+ communityUsers.forEach(user => {
14025
+ result[`${user.userId}#${user.communityId}`] = user;
14026
+ });
14027
+ return result;
14028
+ };
14029
+ const convertCommunityPayload = (rawPayload) => {
14030
+ // Unpack community payload by mapping payload field to postSetting value.
14031
+ const communities = rawPayload.communities.map((_a) => {
14032
+ var { needApprovalOnPostCreation, onlyAdminCanPost } = _a, restCommunityPayload = __rest(_a, ["needApprovalOnPostCreation", "onlyAdminCanPost"]);
14033
+ return (Object.assign({ postSetting: getMatchPostSetting({
14034
+ needApprovalOnPostCreation,
14035
+ onlyAdminCanPost,
14036
+ }) }, restCommunityPayload));
14037
+ });
14038
+ const mergeCommunityUsers = communities.reduce((acc, { communityId }) => {
14039
+ var _a;
14040
+ const users = (_a = pullFromCache([
14041
+ 'communityUsers',
14042
+ 'collection',
14043
+ communityId,
14044
+ ])) === null || _a === void 0 ? void 0 : _a.data;
14045
+ if (!users)
14046
+ return acc;
14047
+ return Object.assign(Object.assign({}, convertCommunityUsersToUniqueObject(users)), acc);
14048
+ }, convertCommunityUsersToUniqueObject(rawPayload.communityUsers));
14049
+ const communityUsers = withUsers(Object.values(mergeCommunityUsers));
14050
+ const communityWithMembershipStatus = updateMembershipStatus(communities, communityUsers);
14051
+ return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers });
14052
+ };
14053
+ const prepareCommunityPayload = (rawPayload) => {
14054
+ const { communities, communityUsers } = convertCommunityPayload(rawPayload);
14055
+ return Object.assign(Object.assign({}, rawPayload), { communities,
14056
+ communityUsers });
14057
+ };
14058
+ const prepareCommunityRequest = (params) => {
14059
+ const { postSetting = undefined, storySetting } = params, restParam = __rest(params, ["postSetting", "storySetting"]);
14060
+ return Object.assign(Object.assign(Object.assign({}, restParam), (postSetting ? CommunityPostSettingMaps[postSetting] : undefined)), {
14061
+ // Convert story setting to the actual value. (Allow by default)
14062
+ allowCommentInStory: typeof (storySetting === null || storySetting === void 0 ? void 0 : storySetting.enableComment) === 'boolean' ? storySetting.enableComment : true });
14063
+ };
14064
+
14065
+ const preparePostPayload = (postPayload) => {
14066
+ const { posts } = postPayload;
14067
+ const { communities, communityUsers } = convertCommunityPayload({
14068
+ communities: postPayload.communities,
14069
+ communityUsers: postPayload.communityUsers,
14070
+ });
14071
+ return Object.assign(Object.assign({}, postPayload), { posts,
14072
+ communities,
14073
+ communityUsers });
13769
14074
  };
13770
14075
 
14076
+ function prepareCommentPayload(commentPayload) {
14077
+ const { comments } = commentPayload;
14078
+ return Object.assign(Object.assign({}, commentPayload), { comments: comments.map(comment => {
14079
+ if (comment.hasOwnProperty('myReactions'))
14080
+ return comment;
14081
+ // Sometimes `myReactions` field will not come with BE response because that field is empty
14082
+ // We need to put it with an empty array manually to make it show up in client side
14083
+ return Object.assign({ myReactions: [] }, comment);
14084
+ }) });
14085
+ }
14086
+
14087
+ const createMessageReport = async ({ client, referenceId, }) => {
14088
+ const { data: payload } = await client.http.post(`/api/v5/messages/${encodeURIComponent(referenceId)}/flags`);
14089
+ if (client.cache) {
14090
+ const messagePayload = await prepareMessagePayload(payload);
14091
+ ingestInCache(messagePayload);
14092
+ }
14093
+ fireEvent(`message.flagged`, payload);
14094
+ return !!payload;
14095
+ };
14096
+ const createPostReport = async ({ client, referenceId, }) => {
14097
+ const { data: payload } = await client.http.post(`/api/v3/post/${encodeURIComponent(referenceId)}/flag`);
14098
+ if (client.cache) {
14099
+ const postPayload = await preparePostPayload(payload);
14100
+ ingestInCache(postPayload);
14101
+ }
14102
+ fireEvent(`post.flagged`, payload);
14103
+ return !!payload;
14104
+ };
14105
+ const createUserReport = async ({ client, referenceId, }) => {
14106
+ const { data: payload } = await client.http.post(`/api/v4/me/flags/${encodeURIComponent(referenceId)}`);
14107
+ if (client.cache) {
14108
+ const userPayload = await prepareUserPayload(payload);
14109
+ ingestInCache(userPayload);
14110
+ }
14111
+ fireEvent(`user.flagged`, payload);
14112
+ return !!payload;
14113
+ };
14114
+ const createCommentReport = async ({ client, referenceId, }) => {
14115
+ const { data: payload } = await client.http.post(`/api/v3/comment/${encodeURIComponent(referenceId)}/flag`);
14116
+ if (client.cache) {
14117
+ const commentPayload = await prepareCommentPayload(payload);
14118
+ ingestInCache(commentPayload);
14119
+ }
14120
+ fireEvent(`comment.flagged`, payload);
14121
+ return !!payload;
14122
+ };
13771
14123
  /**
13772
14124
  * ```js
13773
14125
  * import { createReport } from '@amityco/ts-sdk'
@@ -13784,33 +14136,57 @@ var REFERENCE_TYPES = {
13784
14136
  const createReport = async (referenceType, referenceId) => {
13785
14137
  const client = getActiveClient();
13786
14138
  client.log('report/createReport', { referenceType, referenceId });
13787
- const getAPIUrl = () => {
13788
- if (referenceType === 'user') {
13789
- return `/api/v4/me/flags/${encodeURIComponent(referenceId)}`;
13790
- }
13791
- if (referenceType === 'message') {
13792
- return `/api/v5/messages/${encodeURIComponent(referenceId)}/flags`;
13793
- }
13794
- const { domainName } = REFERENCE_TYPES[referenceType];
13795
- return `/api/v3/${domainName}/${encodeURIComponent(referenceId)}/flag`;
13796
- };
13797
- const { data: payload } = await client.http.post(getAPIUrl());
13798
- if (client.cache) {
13799
- if (referenceType === 'message') {
13800
- const messagePayload = await prepareMessagePayload(payload);
13801
- ingestInCache(messagePayload);
13802
- }
13803
- else if (referenceType === 'post') {
13804
- ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
13805
- }
13806
- else {
13807
- ingestInCache(payload);
13808
- }
14139
+ if (referenceType === 'user') {
14140
+ return createUserReport({ client, referenceId });
13809
14141
  }
13810
- fireEvent(`${referenceType}.flagged`, payload);
13811
- return !!payload;
14142
+ if (referenceType === 'message') {
14143
+ return createMessageReport({ client, referenceId });
14144
+ }
14145
+ if (referenceType === 'post') {
14146
+ return createPostReport({ client, referenceId });
14147
+ }
14148
+ if (referenceType === 'comment') {
14149
+ return createCommentReport({ client, referenceId });
14150
+ }
14151
+ return false;
13812
14152
  };
13813
14153
 
14154
+ const deleteMessageReport = async ({ client, referenceId, }) => {
14155
+ const { data: payload } = await client.http.delete(`/api/v5/messages/${encodeURIComponent(referenceId)}/flags`);
14156
+ if (client.cache) {
14157
+ const messagePayload = await prepareMessagePayload(payload);
14158
+ ingestInCache(messagePayload);
14159
+ }
14160
+ fireEvent(`message.unflagged`, payload);
14161
+ return !!payload;
14162
+ };
14163
+ const deletePostReport = async ({ client, referenceId, }) => {
14164
+ const { data: payload } = await client.http.delete(`/api/v3/post/${encodeURIComponent(referenceId)}/flag`);
14165
+ if (client.cache) {
14166
+ const postPayload = await preparePostPayload(payload);
14167
+ ingestInCache(postPayload);
14168
+ }
14169
+ fireEvent(`post.unflagged`, payload);
14170
+ return !!payload;
14171
+ };
14172
+ const deleteUserReport = async ({ client, referenceId, }) => {
14173
+ const { data: payload } = await client.http.delete(`/api/v4/me/flags/${encodeURIComponent(referenceId)}`);
14174
+ if (client.cache) {
14175
+ const userPayload = await prepareUserPayload(payload);
14176
+ ingestInCache(userPayload);
14177
+ }
14178
+ fireEvent(`user.unflagged`, payload);
14179
+ return !!payload;
14180
+ };
14181
+ const deleteCommentReport = async ({ client, referenceId, }) => {
14182
+ const { data: payload } = await client.http.delete(`/api/v3/comment/${encodeURIComponent(referenceId)}/flag`);
14183
+ if (client.cache) {
14184
+ const commentPayload = await prepareCommentPayload(payload);
14185
+ ingestInCache(commentPayload);
14186
+ }
14187
+ fireEvent(`comment.unflagged`, payload);
14188
+ return !!payload;
14189
+ };
13814
14190
  /**
13815
14191
  * ```js
13816
14192
  * import { deleteReport } from '@amityco/ts-sdk'
@@ -13827,34 +14203,45 @@ const createReport = async (referenceType, referenceId) => {
13827
14203
  const deleteReport = async (referenceType, referenceId) => {
13828
14204
  const client = getActiveClient();
13829
14205
  client.log('report/deleteReport', { referenceType, referenceId });
13830
- const getAPIUrl = () => {
13831
- if (referenceType === 'user') {
13832
- return `/api/v4/me/flags/${encodeURIComponent(referenceId)}`;
13833
- }
13834
- if (referenceType === 'message') {
13835
- return `/api/v5/messages/${encodeURIComponent(referenceId)}/flags`;
13836
- }
13837
- const { domainName } = REFERENCE_TYPES[referenceType];
13838
- return `/api/v3/${domainName}/${encodeURIComponent(referenceId)}/unflag`;
13839
- };
13840
- const { data: payload } = await client.http.delete(getAPIUrl());
13841
- if (client.cache) {
13842
- if (referenceType === 'message') {
13843
- const messagePayload = await prepareMessagePayload(payload);
13844
- ingestInCache(messagePayload);
13845
- }
13846
- else if (referenceType === 'post') {
13847
- ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
13848
- }
13849
- else {
13850
- ingestInCache(payload);
13851
- }
14206
+ if (referenceType === 'user') {
14207
+ return deleteUserReport({ client, referenceId });
13852
14208
  }
13853
- // @ts-ignore
13854
- fireEvent(`${referenceType}.unflagged`, payload);
13855
- return !!payload;
14209
+ if (referenceType === 'message') {
14210
+ return deleteMessageReport({ client, referenceId });
14211
+ }
14212
+ if (referenceType === 'post') {
14213
+ return deletePostReport({ client, referenceId });
14214
+ }
14215
+ if (referenceType === 'comment') {
14216
+ return deleteCommentReport({ client, referenceId });
14217
+ }
14218
+ return false;
13856
14219
  };
13857
14220
 
14221
+ const getMessageReport = async ({ client, referenceId, }) => {
14222
+ var _a;
14223
+ const { data } = await client.http.get(`/api/v5/messages/${encodeURIComponent(referenceId)}/flags`);
14224
+ const { result, isFlagByMe } = data !== null && data !== void 0 ? data : {};
14225
+ return (_a = result !== null && result !== void 0 ? result : isFlagByMe) !== null && _a !== void 0 ? _a : false;
14226
+ };
14227
+ const getPostReport = async ({ client, referenceId, }) => {
14228
+ var _a;
14229
+ const { data } = await client.http.get(`/api/v3/user/${referenceId}/isflagbyme`);
14230
+ const { result, isFlagByMe } = data !== null && data !== void 0 ? data : {};
14231
+ return (_a = result !== null && result !== void 0 ? result : isFlagByMe) !== null && _a !== void 0 ? _a : false;
14232
+ };
14233
+ const getUserReport = async ({ client, referenceId, }) => {
14234
+ var _a;
14235
+ const { data } = await client.http.get(`/api/v3/user/${referenceId}/isflagbyme`);
14236
+ const { result, isFlagByMe } = data !== null && data !== void 0 ? data : {};
14237
+ return (_a = result !== null && result !== void 0 ? result : isFlagByMe) !== null && _a !== void 0 ? _a : false;
14238
+ };
14239
+ const getCommentReport = async ({ client, referenceId, }) => {
14240
+ var _a;
14241
+ const { data } = await client.http.get(`/api/v3/comment/${referenceId}/isflagbyme`);
14242
+ const { result, isFlagByMe } = data !== null && data !== void 0 ? data : {};
14243
+ return (_a = result !== null && result !== void 0 ? result : isFlagByMe) !== null && _a !== void 0 ? _a : false;
14244
+ };
13858
14245
  /**
13859
14246
  * ```js
13860
14247
  * import { isReportedByMe } from '@amityco/ts-sdk'
@@ -13869,17 +14256,21 @@ const deleteReport = async (referenceType, referenceId) => {
13869
14256
  * @async
13870
14257
  * */
13871
14258
  const isReportedByMe = async (referenceType, referenceId) => {
13872
- var _a;
13873
14259
  const client = getActiveClient();
13874
14260
  client.log('report/isReportedByMe', { referenceType, referenceId });
13875
- const { domainName } = REFERENCE_TYPES[referenceType];
14261
+ if (referenceType === 'user') {
14262
+ return getUserReport({ client, referenceId });
14263
+ }
13876
14264
  if (referenceType === 'message') {
13877
- const { data } = await client.http.get(`/api/v5/messages/${encodeURIComponent(referenceId)}/flags`);
13878
- return data.result;
14265
+ return getMessageReport({ client, referenceId });
13879
14266
  }
13880
- const { data } = await client.http.get(`/api/v3/${domainName}/${referenceId}/isflagbyme`);
13881
- const { result, isFlagByMe } = data !== null && data !== void 0 ? data : {};
13882
- return (_a = result !== null && result !== void 0 ? result : isFlagByMe) !== null && _a !== void 0 ? _a : false;
14267
+ if (referenceType === 'post') {
14268
+ return getPostReport({ client, referenceId });
14269
+ }
14270
+ if (referenceType === 'comment') {
14271
+ return getCommentReport({ client, referenceId });
14272
+ }
14273
+ return false;
13883
14274
  };
13884
14275
 
13885
14276
  /* begin_public_function
@@ -15398,116 +15789,6 @@ const getMessage$1 = (messageId, callback) => {
15398
15789
  };
15399
15790
  /* end_public_function */
15400
15791
 
15401
- class PaginationNoPageController {
15402
- constructor(queryParams) {
15403
- const { http } = getActiveClient();
15404
- this.queryParams = queryParams;
15405
- this.http = http;
15406
- }
15407
- async onFetch() {
15408
- const queryResponse = await this.getRequest(this.queryParams);
15409
- return queryResponse;
15410
- }
15411
- }
15412
-
15413
- class LiveCollectionController {
15414
- constructor(paginationController, queryStreamId, cacheKey, callback) {
15415
- this.paginationController = paginationController;
15416
- this.queryStreamId = queryStreamId;
15417
- this.cacheKey = cacheKey;
15418
- this.callback = callback;
15419
- }
15420
- async refresh() {
15421
- try {
15422
- let result;
15423
- if (this.paginationController instanceof PaginationNoPageController) {
15424
- result = await this.paginationController.onFetch();
15425
- }
15426
- else {
15427
- result = await this.paginationController.loadFirstPage();
15428
- }
15429
- if (!result)
15430
- return;
15431
- await this.persistModel(result);
15432
- this.persistQueryStream({
15433
- response: result,
15434
- direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
15435
- refresh: true,
15436
- });
15437
- this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
15438
- }
15439
- catch (e) {
15440
- this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
15441
- }
15442
- }
15443
- loadPage({ initial = false, direction = "next" /* Amity.LiveCollectionPageDirection.NEXT */, }) {
15444
- this.setup();
15445
- this.notifyChange({ origin: "local" /* Amity.LiveDataOrigin.LOCAL */, loading: true });
15446
- if (initial) {
15447
- this.refresh();
15448
- }
15449
- else if (direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */) {
15450
- this.loadPrevPage();
15451
- }
15452
- else if (direction === "next" /* Amity.LiveCollectionPageDirection.NEXT */) {
15453
- this.loadNextPage();
15454
- }
15455
- }
15456
- async loadNextPage() {
15457
- try {
15458
- if (this.paginationController instanceof PaginationNoPageController)
15459
- return;
15460
- const result = await this.paginationController.loadNextPage();
15461
- if (!result)
15462
- return;
15463
- await this.persistModel(result);
15464
- this.persistQueryStream({
15465
- response: result,
15466
- direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
15467
- });
15468
- this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
15469
- }
15470
- catch (e) {
15471
- this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
15472
- }
15473
- }
15474
- async loadPrevPage() {
15475
- try {
15476
- if (this.paginationController instanceof PaginationNoPageController)
15477
- return;
15478
- const result = await this.paginationController.loadPreviousPage();
15479
- if (!result)
15480
- return;
15481
- await this.persistModel(result);
15482
- this.persistQueryStream({
15483
- response: result,
15484
- direction: "prev" /* Amity.LiveCollectionPageDirection.PREV */,
15485
- });
15486
- this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
15487
- }
15488
- catch (e) {
15489
- this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
15490
- }
15491
- }
15492
- shouldNotify(data) {
15493
- const newData = data.map(convertGetterPropsToStatic).map(removeFunctionProperties);
15494
- if (isEqual(this.snapshot, newData))
15495
- return false;
15496
- this.snapshot = newData;
15497
- return true;
15498
- }
15499
- getCacheKey() {
15500
- return this.cacheKey;
15501
- }
15502
- }
15503
-
15504
- class QueryStreamController {
15505
- constructor(query, cacheKey) {
15506
- this.query = query;
15507
- this.cacheKey = cacheKey;
15508
- }
15509
- }
15510
-
15511
15792
  /* eslint-disable no-use-before-define */
15512
15793
  class MessageQueryStreamController extends QueryStreamController {
15513
15794
  constructor(query, cacheKey, notifyChange, preparePayload, paginationController) {
@@ -15590,51 +15871,6 @@ class MessageQueryStreamController extends QueryStreamController {
15590
15871
  }
15591
15872
  }
15592
15873
 
15593
- class PaginationController {
15594
- constructor(queryParams) {
15595
- const { http } = getActiveClient();
15596
- this.queryParams = queryParams;
15597
- this.http = http;
15598
- }
15599
- loadFirstPage() {
15600
- return this.onFetch("first" /* Amity.LiveCollectionPageDirection.FIRST */);
15601
- }
15602
- loadNextPage() {
15603
- return this.onFetch("next" /* Amity.LiveCollectionPageDirection.NEXT */);
15604
- }
15605
- loadPreviousPage() {
15606
- return this.onFetch("prev" /* Amity.LiveCollectionPageDirection.PREV */);
15607
- }
15608
- async onFetch(direction = "first" /* Amity.LiveCollectionPageDirection.FIRST */) {
15609
- var _a, _b, _c, _d;
15610
- if (direction === 'prev' && !this.previousToken)
15611
- return;
15612
- if (direction === 'next' && !this.nextToken)
15613
- return;
15614
- let token;
15615
- if (direction === 'prev')
15616
- token = this.previousToken;
15617
- if (direction === 'next')
15618
- token = this.nextToken;
15619
- const queryResponse = await this.getRequest(this.queryParams, token);
15620
- if (direction === 'first') {
15621
- this.nextToken = (_a = queryResponse.paging) === null || _a === void 0 ? void 0 : _a.next;
15622
- this.previousToken = (_b = queryResponse.paging) === null || _b === void 0 ? void 0 : _b.previous;
15623
- }
15624
- if (direction === 'prev')
15625
- this.previousToken = (_c = queryResponse.paging) === null || _c === void 0 ? void 0 : _c.previous;
15626
- if (direction === 'next')
15627
- this.nextToken = (_d = queryResponse.paging) === null || _d === void 0 ? void 0 : _d.next;
15628
- return queryResponse;
15629
- }
15630
- getNextToken() {
15631
- return this.nextToken;
15632
- }
15633
- getPrevToken() {
15634
- return this.previousToken;
15635
- }
15636
- }
15637
-
15638
15874
  /* eslint-disable no-use-before-define */
15639
15875
  /**
15640
15876
  * TODO: handle cache receive cache option, and cache policy
@@ -17946,57 +18182,6 @@ const saveCommunityUsers = (communities, communityUsers) => {
17946
18182
  });
17947
18183
  };
17948
18184
 
17949
- const getMatchPostSetting = (value) => {
17950
- var _a;
17951
- return (_a = Object.keys(CommunityPostSettingMaps).find(key => value.needApprovalOnPostCreation ===
17952
- CommunityPostSettingMaps[key].needApprovalOnPostCreation &&
17953
- value.onlyAdminCanPost === CommunityPostSettingMaps[key].onlyAdminCanPost)) !== null && _a !== void 0 ? _a : DefaultCommunityPostSetting;
17954
- };
17955
- const convertCommunityUsersToUniqueObject = (communityUsers) => {
17956
- if (!communityUsers)
17957
- return communityUsers;
17958
- const result = {};
17959
- communityUsers.forEach(user => {
17960
- result[`${user.userId}#${user.communityId}`] = user;
17961
- });
17962
- return result;
17963
- };
17964
- const convertCommunityPayload = (rawPayload) => {
17965
- // Unpack community payload by mapping payload field to postSetting value.
17966
- const communities = rawPayload.communities.map((_a) => {
17967
- var { needApprovalOnPostCreation, onlyAdminCanPost } = _a, restCommunityPayload = __rest(_a, ["needApprovalOnPostCreation", "onlyAdminCanPost"]);
17968
- return (Object.assign({ postSetting: getMatchPostSetting({
17969
- needApprovalOnPostCreation,
17970
- onlyAdminCanPost,
17971
- }) }, restCommunityPayload));
17972
- });
17973
- const mergeCommunityUsers = communities.reduce((acc, { communityId }) => {
17974
- var _a;
17975
- const users = (_a = pullFromCache([
17976
- 'communityUsers',
17977
- 'collection',
17978
- communityId,
17979
- ])) === null || _a === void 0 ? void 0 : _a.data;
17980
- if (!users)
17981
- return acc;
17982
- return Object.assign(Object.assign({}, convertCommunityUsersToUniqueObject(users)), acc);
17983
- }, convertCommunityUsersToUniqueObject(rawPayload.communityUsers));
17984
- const communityUsers = withUsers(Object.values(mergeCommunityUsers));
17985
- const communityWithMembershipStatus = updateMembershipStatus(communities, communityUsers);
17986
- return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers });
17987
- };
17988
- const prepareCommunityPayload = (rawPayload) => {
17989
- const { communities, communityUsers } = convertCommunityPayload(rawPayload);
17990
- return Object.assign(Object.assign({}, rawPayload), { communities,
17991
- communityUsers });
17992
- };
17993
- const prepareCommunityRequest = (params) => {
17994
- const { postSetting = undefined, storySetting } = params, restParam = __rest(params, ["postSetting", "storySetting"]);
17995
- return Object.assign(Object.assign(Object.assign({}, restParam), (postSetting ? CommunityPostSettingMaps[postSetting] : undefined)), {
17996
- // Convert story setting to the actual value. (Allow by default)
17997
- allowCommentInStory: typeof (storySetting === null || storySetting === void 0 ? void 0 : storySetting.enableComment) === 'boolean' ? storySetting.enableComment : true });
17998
- };
17999
-
18000
18185
  /**
18001
18186
  * ```js
18002
18187
  * import { getCommunities } from '@amityco/ts-sdk'
@@ -18432,10 +18617,6 @@ const onCommunityUpdated = (callback) => createCommunityEventSubscriber('communi
18432
18617
  */
18433
18618
  const onCommunityDeleted = (callback) => createCommunityEventSubscriber('community.deleted', callback);
18434
18619
 
18435
- function isNonNullable(value) {
18436
- return value != null;
18437
- }
18438
-
18439
18620
  function hasPermission(member, payload, permission) {
18440
18621
  if (member.permissions.some(x => x === permission)) {
18441
18622
  return true;
@@ -19545,11 +19726,11 @@ class CommunityLiveCollectionController extends LiveCollectionController {
19545
19726
  if (!this.query.displayName) {
19546
19727
  const sortFn = (() => {
19547
19728
  switch (this.query.sortBy) {
19548
- case 'firstCreated':
19729
+ case Amity.CommunitySortByEnum.FirstCreated:
19549
19730
  return sortByFirstCreated;
19550
- case 'lastCreated':
19731
+ case Amity.CommunitySortByEnum.LastCreated:
19551
19732
  return sortByLastCreated;
19552
- case 'displayName':
19733
+ case Amity.CommunitySortByEnum.DisplayName:
19553
19734
  return sortByDisplayName;
19554
19735
  default:
19555
19736
  return sortByLastCreated;
@@ -21774,17 +21955,6 @@ class CommentQueryStreamController extends QueryStreamController {
21774
21955
  }
21775
21956
  }
21776
21957
 
21777
- function prepareCommentPayload(commentPayload) {
21778
- const { comments } = commentPayload;
21779
- return Object.assign(Object.assign({}, commentPayload), { comments: comments.map(comment => {
21780
- if (comment.hasOwnProperty('myReactions'))
21781
- return comment;
21782
- // Sometimes `myReactions` field will not come with BE response because that field is empty
21783
- // We need to put it with an empty array manually to make it show up in client side
21784
- return Object.assign({ myReactions: [] }, comment);
21785
- }) });
21786
- }
21787
-
21788
21958
  class CommentLiveCollectionController extends LiveCollectionController {
21789
21959
  constructor(query, callback) {
21790
21960
  const queryStreamId = hash__default["default"](query);
@@ -22137,17 +22307,6 @@ class PostQueryStreamController extends QueryStreamController {
22137
22307
  }
22138
22308
  }
22139
22309
 
22140
- const preparePostPayload = (postPayload) => {
22141
- const { posts } = postPayload;
22142
- const { communities, communityUsers } = convertCommunityPayload({
22143
- communities: postPayload.communities,
22144
- communityUsers: postPayload.communityUsers,
22145
- });
22146
- return Object.assign(Object.assign({}, postPayload), { posts,
22147
- communities,
22148
- communityUsers });
22149
- };
22150
-
22151
22310
  const getPost = async (postId) => {
22152
22311
  const client = getActiveClient();
22153
22312
  client.log('post/getPost', postId);
@@ -23264,7 +23423,7 @@ var index$3 = /*#__PURE__*/Object.freeze({
23264
23423
  getPoll: getPoll
23265
23424
  });
23266
23425
 
23267
- const privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDHo80SecH7FuF2\nhFYnb+l26/VN8UMLXAQFLnxciNTEwkGVFMpdezlH8rU2HtUJL4RETogbAOLVY0XM\njs6sPn8G1nALmh9qeDpUtVqFOVtBHxEZ910TLOtQiunjqJKO5nWdqZ71EC3OFluR\niGQkO84BiIFbv37ub7xl3S8XarbtKoLcyVpkDHi+1wx1pgCAn6gtBUgckPL5NR8j\nLseabl3HAXQfhTCKo4tmOFM2Dxwl1IUMmIJrJg/aIU/U0tj/1Eoo7mG0JcNWX19l\nW3EecCbi0ncCJOrkUdwlBrcjaMayaX/ubEwyUeTGiLdyc4L3GRLHjyK8xgVNXRMH\nbZWJ2a5NAgMBAAECggEASxuE+35zTFO/XydKgmvIGcWL9FbgMlXb7Vcf0nBoG945\nbiz0NVc2paraIhJXc608xbYF3qLmtAE1MVBI0ORyRdBHNxY024l/6H6SH60Ed+uI\nM4ysp5ourY6Vj+DLwpdRiI9YDjqYAQDIUmhNxJP7XPhOMoZI6st+xZQBM34ic/bv\nAMSJm9OZphSp3+qXVkFZztr2mxD2EZSJJLYxi8BCdgM2qhazalbcJ6zDKHCZWVWm\n8RRxDGldyMb/237JxETzP40tAlzOZDmBAbUgEnurDJ93RVDIE3rbZUshwgeQd18a\nem096mWgvB1AIKYgsTAR3pw+V19YWAjq/glP6fz8wQKBgQD/oQq+ukKF0PRgBeM5\ngeTjSwsdGppQLmf5ndujvoiz/TpdjDEPu6R8kigQr1rG2t4K/yfdZoI8RdmJD1al\n3Q7N9hofooSy4rj6E3txzWZCHJjHad2cnCp/O26HiReGAl7wTcfTmNdiFHhZQzm5\nJBkvWAiwuvQMNfEbnXxw6/vIDwKBgQDH7fX8gsc77JLvAWgp1MaQN/sbqVb6JeT1\nFQfR8E/WFCSmzQBtNzd5KgYuCeelwr/8DyYytvN2BzCYZXp73gI1jF3YlW5jVn74\nOY6TwQ095digwo6Z0yuxopdIOApKgAkL9PRKgNrqAf3NAyMua6lOGifzjDojC3KU\nfylQmxMn4wKBgHp2B9O/H0dEBw5JQ8W0+JX6yWQz7mEjGiR2/1W+XXb8hQ1zr709\nw1r6Gb+EghRpnZ3fBpYGGbYOMFx8wKHM+N6qW3F0ReX8v2juFGE8aRSa5oYBrWzt\nU16Idjbv8hj84cZ1PJmdyvDtpYn9rpWHOZl4rxEbPvbqkIsOMyNVqdT5AoGAOSge\nmwIIU2le2FVeohbibXiToWTYKMuMmURZ5/r72AgKMmWJKbAPe+Q3wBG01/7FRBpQ\noU8Ma0HC8s6QJbliiEyIx9JwrJWd1vkdecBHONrtA4ibm/5zD2WcOllLF+FitLhi\n3qnX6+6F0IaFGFBPJrTzlv0P4dTz/OAdv52V7GECgYEA2TttOKBAqWllgOaZOkql\nLVMJVmgR7s6tLi1+cEP8ZcapV9aRbRzTAKXm4f8AEhtlG9F9kCOvHYCYGi6JaiWJ\nZkHjeex3T+eE6Di6y5Bm/Ift5jtVhJ4jCVwHOKTMej79NPUFTJfv8hCo29haBDv6\nRXFrv+T21KCcw8k3sJeJWWQ=\n-----END PRIVATE KEY-----";
23426
+ const privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDAARz+hmBgi8pJ\nQb8LeY41gtHhk+ACMwRfhsn7GqpqRQNG2qU0755mzZuVDUqjQMGSo8THJB7O+OJs\nflbZRkFXlFoFOVNw1UpNOgwEQZ6wB9oRwzepTJAfF1sVhm/o/ixvXh1zDFNDy6yZ\npXyiiJHUVxqyjllZhxnwdvjoVtDs6hW6awG09bB9nh/TTejlUKXoAgzqVwu/1QMu\nUVViET495elEe19aUarEy+oL2iKeXCEvqda/pWNBdbieFyJvvZ08HN8dPuT88wq2\njZLEAth1vrwQ2IAa4ktaLcBQdLJgIkrbDvAiVZ8lQAjS/bq5vXQikTGvoPlC5bbn\nvuOM/3eLAgMBAAECggEAVZ+peHAghq2QVj71nX5lxsNCKaCyYwixSJBpfouTt7Rz\nE6PpzMOXFi1W1o+I22jDakuSM2SOQKqI/u0QefB0r0O/KVk5NrZHXk0mkrdYtxOp\nUgaGyf8UvmjB+8VqHrNKyZdk9qtmbnNj01kTTcAtmE4H39zPR7eR/8Rul94vaZbs\nwCnKJS3mLT3JxyGug6lxanveKkjG+CKC1nJQYWaxCJxaFSzbwXQPvDhB+TvrIbee\npd5v4EAyEJohpr+T9oDGGJkb/KARBZCtwLyB976PKJwwBA8MRVL1i5QwawuMiMq5\nUtnOnbGKtCeFzaLbNU0Qi8bqyims84EQxC6DOu1fkQKBgQDdvsoBsEhsOXV7hlIJ\naEd0eSJZVkdqimxH8uGoMM2FeNaOrcB6yBXqTSP0R3OIyf8eaY6yjRvP30ZNXcll\n/gD3O1Mu6YmWQdt1W2WA6pKOsUuPXasf0pdOF7IiFZKlSabz5YHXFqwVuqm8loaj\nsXel3YWqPVdHiankE7tz+3ssnQKBgQDdqi4TNdD1MdEpihx19jr0QjUiXW3939FK\nqp30HESPEGDGQzXdmJgif9HhZb+cJSuWaHEbjgBrYahvgCF+y6LbEpOD+D/dmT+s\nDEAQaR84sah6dokwPjV8fjBSrcVFjCS+doxv0d3p/9OUEeyUhFrY03nxtIEYkLIE\n/Zvn37b4RwKBgQCLENVFe9XfsaVhQ5r9dV2iyTlmh7qgMZG5CbTFs12hQGhm8McO\n+Z7s41YSJCFr/yq1WwP4LJDtrBw99vyQr1zRsG35tNLp3gGRNzGQSQyC2uQFVHw2\np+7mNewsfhUK/gbrXNsyFnDz6635rPlhfbII3sWuP2wWXFqkxE9CbMwR7QKBgQC6\nawDMzxmo2/iYArrkyevSuEuPVxvFwpF1RgAI6C0QVCnPE38dmdN4UB7mfHekje4W\nVEercMURidPp0cxZolCYBQtilUjAyL0vqC3In1/Ogjq6oy3FEMxSop1pKxMY5j+Q\nnoqFD+6deLUrddeNH7J3X4LSr4dSbX4JjG+tlgt+yQKBgQCuwTL4hA6KqeInQ0Ta\n9VQX5Qr8hFlqJz1gpymi/k63tW/Ob8yedbg3WWNWyShwRMFYyY9S81ITFWM95uL6\nvF3x9rmRjwElJw9PMwVu6dmf/CO0Z1wzXSp2VVD12gbrUD/0/d7MUoJ9LgC8X8f/\nn0txLHYGHbx+nf95+JUg6lV3hg==\n-----END PRIVATE KEY-----";
23268
23427
  /*
23269
23428
  * The crypto algorithm used for importing key and signing string
23270
23429
  */