@amityco/ts-sdk 7.19.0 → 7.19.1-0d42b83a.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 (84) hide show
  1. package/dist/@types/core/events.d.ts +2 -0
  2. package/dist/@types/core/events.d.ts.map +1 -1
  3. package/dist/@types/core/model.d.ts +2 -0
  4. package/dist/@types/core/model.d.ts.map +1 -1
  5. package/dist/@types/core/payload.d.ts +7 -0
  6. package/dist/@types/core/payload.d.ts.map +1 -1
  7. package/dist/@types/domains/channel.d.ts +20 -0
  8. package/dist/@types/domains/channel.d.ts.map +1 -1
  9. package/dist/@types/domains/client.d.ts +1 -0
  10. package/dist/@types/domains/client.d.ts.map +1 -1
  11. package/dist/@types/domains/message.d.ts +16 -0
  12. package/dist/@types/domains/message.d.ts.map +1 -1
  13. package/dist/@types/domains/notificationSettings.d.ts +101 -0
  14. package/dist/@types/domains/notificationSettings.d.ts.map +1 -0
  15. package/dist/@types/index.d.ts +2 -1
  16. package/dist/@types/index.d.ts.map +1 -1
  17. package/dist/channelRepository/api/archiveChannel.d.ts +16 -0
  18. package/dist/channelRepository/api/archiveChannel.d.ts.map +1 -0
  19. package/dist/channelRepository/api/getArchivedChannelIds.d.ts +13 -0
  20. package/dist/channelRepository/api/getArchivedChannelIds.d.ts.map +1 -0
  21. package/dist/channelRepository/api/index.d.ts +3 -0
  22. package/dist/channelRepository/api/index.d.ts.map +1 -1
  23. package/dist/channelRepository/api/unarchiveChannel.d.ts +16 -0
  24. package/dist/channelRepository/api/unarchiveChannel.d.ts.map +1 -0
  25. package/dist/channelRepository/api/updateChannel.d.ts +1 -1
  26. package/dist/channelRepository/api/updateChannel.d.ts.map +1 -1
  27. package/dist/channelRepository/channelMembership/observers/getMembers/ChannelMemberQueryStreamController.d.ts.map +1 -1
  28. package/dist/channelRepository/channelModeration/api/banMembers.d.ts.map +1 -1
  29. package/dist/channelRepository/channelModeration/api/muteMembers.d.ts.map +1 -1
  30. package/dist/channelRepository/channelModeration/api/unbanMembers.d.ts.map +1 -1
  31. package/dist/channelRepository/channelModeration/api/unmuteMembers.d.ts.map +1 -1
  32. package/dist/channelRepository/events/index.d.ts +2 -0
  33. package/dist/channelRepository/events/index.d.ts.map +1 -1
  34. package/dist/channelRepository/events/onChannelArchived.d.ts +10 -0
  35. package/dist/channelRepository/events/onChannelArchived.d.ts.map +1 -0
  36. package/dist/channelRepository/events/onChannelMemberRoleRemoved.d.ts.map +1 -1
  37. package/dist/channelRepository/events/onChannelUnarchived.d.ts +11 -0
  38. package/dist/channelRepository/events/onChannelUnarchived.d.ts.map +1 -0
  39. package/dist/channelRepository/observers/getArchivedChannels/ArchivedChannelLiveCollectionController.d.ts +12 -0
  40. package/dist/channelRepository/observers/getArchivedChannels/ArchivedChannelLiveCollectionController.d.ts.map +1 -0
  41. package/dist/channelRepository/observers/getArchivedChannels/ArchivedChannelPaginationController.d.ts +11 -0
  42. package/dist/channelRepository/observers/getArchivedChannels/ArchivedChannelPaginationController.d.ts.map +1 -0
  43. package/dist/channelRepository/observers/getArchivedChannels/ArchivedChannelQueryStreamController.d.ts +13 -0
  44. package/dist/channelRepository/observers/getArchivedChannels/ArchivedChannelQueryStreamController.d.ts.map +1 -0
  45. package/dist/channelRepository/observers/getArchivedChannels/getArchivedChannels.d.ts +20 -0
  46. package/dist/channelRepository/observers/getArchivedChannels/getArchivedChannels.d.ts.map +1 -0
  47. package/dist/channelRepository/observers/getArchivedChannels/index.d.ts +2 -0
  48. package/dist/channelRepository/observers/getArchivedChannels/index.d.ts.map +1 -0
  49. package/dist/channelRepository/observers/getChannels/ChannelLiveCollectionController.d.ts.map +1 -1
  50. package/dist/channelRepository/observers/getChannels/ChannelQueryStreamController.d.ts.map +1 -1
  51. package/dist/channelRepository/observers/index.d.ts +1 -0
  52. package/dist/channelRepository/observers/index.d.ts.map +1 -1
  53. package/dist/client/api/index.d.ts +2 -0
  54. package/dist/client/api/index.d.ts.map +1 -1
  55. package/dist/client/api/notifications.d.ts +27 -0
  56. package/dist/client/api/notifications.d.ts.map +1 -0
  57. package/dist/client/api/tests/notifications.integration.test.d.ts +2 -0
  58. package/dist/client/api/tests/notifications.integration.test.d.ts.map +1 -0
  59. package/dist/client/services/ReadReceiptSync/readReceiptSyncEngine.d.ts.map +1 -1
  60. package/dist/core/events.d.ts +3 -3
  61. package/dist/core/events.d.ts.map +1 -1
  62. package/dist/core/model/idResolvers.d.ts.map +1 -1
  63. package/dist/core/model/index.d.ts.map +1 -1
  64. package/dist/index.cjs.js +738 -8
  65. package/dist/index.esm.js +739 -9
  66. package/dist/index.umd.js +3 -3
  67. package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts +1 -0
  68. package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts.map +1 -1
  69. package/dist/messageRepository/observers/index.d.ts +1 -0
  70. package/dist/messageRepository/observers/index.d.ts.map +1 -1
  71. package/dist/messageRepository/observers/searchMessage/SearchMessageLiveCollectionController.d.ts +12 -0
  72. package/dist/messageRepository/observers/searchMessage/SearchMessageLiveCollectionController.d.ts.map +1 -0
  73. package/dist/messageRepository/observers/searchMessage/SearchMessagePaginationController.d.ts +10 -0
  74. package/dist/messageRepository/observers/searchMessage/SearchMessagePaginationController.d.ts.map +1 -0
  75. package/dist/messageRepository/observers/searchMessage/SearchMessageQueryStreamController.d.ts +8 -0
  76. package/dist/messageRepository/observers/searchMessage/SearchMessageQueryStreamController.d.ts.map +1 -0
  77. package/dist/messageRepository/observers/searchMessage/index.d.ts +2 -0
  78. package/dist/messageRepository/observers/searchMessage/index.d.ts.map +1 -0
  79. package/dist/messageRepository/observers/searchMessage/searchMessage.d.ts +24 -0
  80. package/dist/messageRepository/observers/searchMessage/searchMessage.d.ts.map +1 -0
  81. package/dist/reactionRepository/internalApi/addReaction.d.ts.map +1 -1
  82. package/dist/reactionRepository/internalApi/removeReaction.d.ts.map +1 -1
  83. package/dist/utils/linkedObject/channelLinkedObject.d.ts.map +1 -1
  84. package/package.json +1 -1
package/dist/index.esm.js CHANGED
@@ -59,6 +59,13 @@ var FileAccessTypeEnum;
59
59
  FileAccessTypeEnum["NETWORK"] = "network";
60
60
  })(FileAccessTypeEnum || (FileAccessTypeEnum = {}));
61
61
 
62
+ var AmityChannelNotificationModeEnum;
63
+ (function (AmityChannelNotificationModeEnum) {
64
+ AmityChannelNotificationModeEnum["Default"] = "default";
65
+ AmityChannelNotificationModeEnum["Silent"] = "silent";
66
+ AmityChannelNotificationModeEnum["Subscribe"] = "subscribe";
67
+ })(AmityChannelNotificationModeEnum || (AmityChannelNotificationModeEnum = {}));
68
+
62
69
  const CommunityPostSettings = Object.freeze({
63
70
  ONLY_ADMIN_CAN_POST: 'ONLY_ADMIN_CAN_POST',
64
71
  ADMIN_REVIEW_POST_REQUIRED: 'ADMIN_REVIEW_POST_REQUIRED',
@@ -240,6 +247,39 @@ var AnalyticsSourceTypeEnum;
240
247
  AnalyticsSourceTypeEnum["ROOM"] = "room";
241
248
  })(AnalyticsSourceTypeEnum || (AnalyticsSourceTypeEnum = {}));
242
249
 
250
+ var UserNotificationModuleNameEnum;
251
+ (function (UserNotificationModuleNameEnum) {
252
+ UserNotificationModuleNameEnum["CHAT"] = "chat";
253
+ UserNotificationModuleNameEnum["SOCIAL"] = "social";
254
+ UserNotificationModuleNameEnum["VIDEO_STREAMING"] = "video-streaming";
255
+ })(UserNotificationModuleNameEnum || (UserNotificationModuleNameEnum = {}));
256
+ var CommunityNotificationEventNameEnum;
257
+ (function (CommunityNotificationEventNameEnum) {
258
+ CommunityNotificationEventNameEnum["POST_CREATED"] = "post.created";
259
+ CommunityNotificationEventNameEnum["POST_REACTED"] = "post.reacted";
260
+ CommunityNotificationEventNameEnum["COMMENT_CREATED"] = "comment.created";
261
+ CommunityNotificationEventNameEnum["COMMENT_REPLIED"] = "comment.replied";
262
+ CommunityNotificationEventNameEnum["COMMENT_REACTED"] = "comment.reacted";
263
+ CommunityNotificationEventNameEnum["STORY_CREATED"] = "story.created";
264
+ CommunityNotificationEventNameEnum["STORY_REACTED"] = "story.reacted";
265
+ CommunityNotificationEventNameEnum["STORY_COMMENT_CREATED"] = "story-comment.created";
266
+ CommunityNotificationEventNameEnum["LIVESTREAM_START"] = "video-streaming.didStart";
267
+ })(CommunityNotificationEventNameEnum || (CommunityNotificationEventNameEnum = {}));
268
+ var NotificationSettingsLevelEnum;
269
+ (function (NotificationSettingsLevelEnum) {
270
+ NotificationSettingsLevelEnum["USER"] = "user";
271
+ NotificationSettingsLevelEnum["COMMUNITY"] = "community";
272
+ NotificationSettingsLevelEnum["CHANNEL"] = "channel";
273
+ })(NotificationSettingsLevelEnum || (NotificationSettingsLevelEnum = {}));
274
+ /**
275
+ * `NOT` variant is intentionally excluded from public API (internal server-side use only).
276
+ */
277
+ var NotificationRolesFilterTypeEnum;
278
+ (function (NotificationRolesFilterTypeEnum) {
279
+ NotificationRolesFilterTypeEnum["ALL"] = "all";
280
+ NotificationRolesFilterTypeEnum["ONLY"] = "only";
281
+ })(NotificationRolesFilterTypeEnum || (NotificationRolesFilterTypeEnum = {}));
282
+
243
283
  function getVersion() {
244
284
  try {
245
285
  // the string ''v7.19.0-esm'' should be replaced by actual value by @rollup/plugin-replace
@@ -652,6 +692,7 @@ const idResolvers = {
652
692
  channel: ({ channelInternalId }) => channelInternalId,
653
693
  subChannel: ({ subChannelId }) => subChannelId,
654
694
  channelUsers: ({ channelId, userId }) => `${channelId}#${userId}`,
695
+ archivedChannel: ({ channelId }) => channelId,
655
696
  message: ({ messageId, referenceId }) => referenceId !== null && referenceId !== void 0 ? referenceId : messageId,
656
697
  messagePreviewChannel: ({ channelId }) => `${channelId}`,
657
698
  messagePreviewSubChannel: ({ subChannelId }) => `${subChannelId}`,
@@ -715,6 +756,7 @@ const PAYLOAD2MODEL = {
715
756
  channels: 'channel',
716
757
  messageFeeds: 'subChannel',
717
758
  channelUsers: 'channelUsers',
759
+ archives: 'archivedChannel',
718
760
  messages: 'message',
719
761
  messagePreviewChannel: 'messagePreviewChannel',
720
762
  messagePreviewSubChannel: 'messagePreviewSubChannel',
@@ -22770,7 +22812,7 @@ const onChannelMemberRoleRemoved = (callback) => {
22770
22812
  const client = getActiveClient();
22771
22813
  const filter = async (payload) => {
22772
22814
  const { channels, channelUsers } = payload;
22773
- callback(channels[0], channelUsers.find(channelUser => channelUser.membership === 'member'));
22815
+ callbacks$1.forEach(cb => cb(channels[0], channelUsers.find(channelUser => channelUser.membership === 'member')));
22774
22816
  };
22775
22817
  mainDisposer$1 = createEventSubscriber(client, 'onChannelMemberRoleRemoved', 'local.channel-moderator.role-removed', filter);
22776
22818
  }
@@ -22778,6 +22820,39 @@ const onChannelMemberRoleRemoved = (callback) => {
22778
22820
  return () => dispose$1(callback);
22779
22821
  };
22780
22822
 
22823
+ /**
22824
+ * Fired when a {@link Amity.Channel} has been archived by the active user.
22825
+ *
22826
+ * @param callback The function to call when the event was fired
22827
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
22828
+ *
22829
+ * @category Channel Events
22830
+ */
22831
+ const onChannelArchived = (callback) => {
22832
+ const client = getActiveClient();
22833
+ const filter = async (payload) => {
22834
+ callback(payload);
22835
+ };
22836
+ return createEventSubscriber(client, 'onChannelArchived', 'local.channel.archived', filter);
22837
+ };
22838
+
22839
+ /**
22840
+ * Fired when a previously archived {@link Amity.Channel} has been unarchived
22841
+ * by the active user.
22842
+ *
22843
+ * @param callback The function to call when the event was fired
22844
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
22845
+ *
22846
+ * @category Channel Events
22847
+ */
22848
+ const onChannelUnarchived = (callback) => {
22849
+ const client = getActiveClient();
22850
+ const filter = async (payload) => {
22851
+ callback(payload);
22852
+ };
22853
+ return createEventSubscriber(client, 'onChannelUnarchived', 'local.channel.unarchived', filter);
22854
+ };
22855
+
22781
22856
  const callbacks = [];
22782
22857
  let mainDisposer = null;
22783
22858
  const dispose = (cb) => {
@@ -22891,6 +22966,17 @@ const channelLinkedObject = (channel) => {
22891
22966
  markAsRead: () => markAsRead(channel.channelInternalId),
22892
22967
  previewMembers,
22893
22968
  myMembership: (callback) => getMyMembership(channel.channelId, callback),
22969
+ get avatar() {
22970
+ var _a;
22971
+ if (!channel.avatarFileId)
22972
+ return undefined;
22973
+ const avatar = (_a = pullFromCache([
22974
+ 'file',
22975
+ 'get',
22976
+ `${channel.avatarFileId}`,
22977
+ ])) === null || _a === void 0 ? void 0 : _a.data;
22978
+ return avatar;
22979
+ },
22894
22980
  });
22895
22981
  };
22896
22982
 
@@ -24253,9 +24339,8 @@ class MessageReadReceiptSyncEngine {
24253
24339
  // Step 1: Optimistic update of channelUnread.readToSegment to message.segment and update unreadCount value
24254
24340
  const cacheKey = ['channelUnread', 'get', channelId];
24255
24341
  const channelUnread = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24256
- if (typeof (channelUnread === null || channelUnread === void 0 ? void 0 : channelUnread.readToSegment) === 'number' &&
24257
- channelUnread &&
24258
- segment > channelUnread.readToSegment) {
24342
+ if (channelUnread &&
24343
+ (typeof channelUnread.readToSegment !== 'number' || segment > channelUnread.readToSegment)) {
24259
24344
  channelUnread.readToSegment = segment;
24260
24345
  channelUnread.unreadCount = Math.max(channelUnread.lastSegment - segment, 0);
24261
24346
  pushToCache(cacheKey, channelUnread);
@@ -26880,6 +26965,140 @@ const setAccessTokenHandler = (accessTokenHandler) => {
26880
26965
  client.accessTokenHandler = accessTokenHandler;
26881
26966
  };
26882
26967
 
26968
+ function parseRolesFilter(listenFromRoleIds, ignoreFromRoleIds) {
26969
+ if (ignoreFromRoleIds && ignoreFromRoleIds.length > 0) {
26970
+ return { type: 'not', roleIds: ignoreFromRoleIds };
26971
+ }
26972
+ if (listenFromRoleIds && listenFromRoleIds.length > 0) {
26973
+ return { type: NotificationRolesFilterTypeEnum.ONLY, roleIds: listenFromRoleIds };
26974
+ }
26975
+ return { type: NotificationRolesFilterTypeEnum.ALL };
26976
+ }
26977
+ function serializeRolesFilter(rolesFilter) {
26978
+ if ((rolesFilter === null || rolesFilter === void 0 ? void 0 : rolesFilter.type) === NotificationRolesFilterTypeEnum.ONLY) {
26979
+ return { listenFromRoleIds: rolesFilter.roleIds };
26980
+ }
26981
+ return { listenFromRoleIds: [] };
26982
+ }
26983
+ class ChannelNotifications {
26984
+ constructor(channelId) {
26985
+ this.channelId = channelId;
26986
+ }
26987
+ async enable() {
26988
+ const client = getActiveClient();
26989
+ const body = {
26990
+ level: NotificationSettingsLevelEnum.CHANNEL,
26991
+ channelId: this.channelId,
26992
+ isPushNotifiable: true,
26993
+ };
26994
+ await client.http.post('/api/v3/notification/setting', body);
26995
+ }
26996
+ async disable() {
26997
+ const client = getActiveClient();
26998
+ const body = {
26999
+ level: NotificationSettingsLevelEnum.CHANNEL,
27000
+ channelId: this.channelId,
27001
+ isPushNotifiable: false,
27002
+ };
27003
+ await client.http.post('/api/v3/notification/setting', body);
27004
+ }
27005
+ async getSettings() {
27006
+ const client = getActiveClient();
27007
+ const { data } = await client.http.get(`/api/v3/notification/setting?level=${NotificationSettingsLevelEnum.CHANNEL}&channelId=${encodeURIComponent(this.channelId)}`);
27008
+ return { isEnabled: data.isPushNotifiable };
27009
+ }
27010
+ }
27011
+ class UserNotifications {
27012
+ async enable(modules) {
27013
+ var _a;
27014
+ const client = getActiveClient();
27015
+ const notifiableEvents = (_a = modules === null || modules === void 0 ? void 0 : modules.map(module => (Object.assign({ moduleName: module.moduleName, isPushNotifiable: module.isEnabled }, serializeRolesFilter(module.rolesFilter))))) !== null && _a !== void 0 ? _a : [];
27016
+ const body = {
27017
+ level: NotificationSettingsLevelEnum.USER,
27018
+ isPushNotifiable: true,
27019
+ notifiableEvents,
27020
+ };
27021
+ await client.http.post('/api/v3/notification/setting', body);
27022
+ }
27023
+ async disableAllNotifications() {
27024
+ const client = getActiveClient();
27025
+ const body = {
27026
+ level: NotificationSettingsLevelEnum.USER,
27027
+ isPushNotifiable: false,
27028
+ notifiableEvents: [],
27029
+ };
27030
+ await client.http.post('/api/v3/notification/setting', body);
27031
+ }
27032
+ async getSettings() {
27033
+ var _a;
27034
+ const client = getActiveClient();
27035
+ const { data } = await client.http.get(`/api/v3/notification/setting?level=${NotificationSettingsLevelEnum.USER}`);
27036
+ const validModuleNames = Object.values(UserNotificationModuleNameEnum);
27037
+ const modules = ((_a = data.notifiableEvents) !== null && _a !== void 0 ? _a : [])
27038
+ .filter(e => e.moduleName != null && validModuleNames.includes(e.moduleName))
27039
+ .map(e => ({
27040
+ moduleName: e.moduleName,
27041
+ isEnabled: e.isPushNotifiable,
27042
+ rolesFilter: parseRolesFilter(e.listenFromRoleIds, e.ignoreFromRoleIds),
27043
+ }));
27044
+ return { isEnabled: data.isPushNotifiable, modules };
27045
+ }
27046
+ }
27047
+ class CommunityNotifications {
27048
+ constructor(communityId) {
27049
+ this.communityId = communityId;
27050
+ }
27051
+ async enable(events) {
27052
+ var _a;
27053
+ const client = getActiveClient();
27054
+ const notifiableEvents = (_a = events === null || events === void 0 ? void 0 : events.map(event => (Object.assign({ moduleName: UserNotificationModuleNameEnum.SOCIAL, name: event.eventName, isPushNotifiable: event.isEnabled }, serializeRolesFilter(event.rolesFilter))))) !== null && _a !== void 0 ? _a : [];
27055
+ const body = {
27056
+ level: NotificationSettingsLevelEnum.COMMUNITY,
27057
+ communityId: this.communityId,
27058
+ isPushNotifiable: true,
27059
+ notifiableEvents,
27060
+ };
27061
+ await client.http.post('/api/v3/notification/setting', body);
27062
+ }
27063
+ async disable() {
27064
+ const client = getActiveClient();
27065
+ const body = {
27066
+ level: NotificationSettingsLevelEnum.COMMUNITY,
27067
+ communityId: this.communityId,
27068
+ isPushNotifiable: false,
27069
+ notifiableEvents: [],
27070
+ };
27071
+ await client.http.post('/api/v3/notification/setting', body);
27072
+ }
27073
+ async getSettings() {
27074
+ var _a;
27075
+ const client = getActiveClient();
27076
+ const { data } = await client.http.get(`/api/v3/notification/setting?level=${NotificationSettingsLevelEnum.COMMUNITY}&communityId=${encodeURIComponent(this.communityId)}`);
27077
+ const validEventNames = Object.values(CommunityNotificationEventNameEnum);
27078
+ const events = ((_a = data.notifiableEvents) !== null && _a !== void 0 ? _a : [])
27079
+ .filter(e => e.name != null && validEventNames.includes(e.name))
27080
+ .map(e => ({
27081
+ eventName: e.name,
27082
+ isEnabled: e.isPushNotifiable,
27083
+ isNetworkEnabled: e.isNetworkEnabled,
27084
+ rolesFilter: parseRolesFilter(e.listenFromRoleIds, e.ignoreFromRoleIds),
27085
+ }));
27086
+ return { isEnabled: data.isPushNotifiable, events };
27087
+ }
27088
+ }
27089
+ class Notifications {
27090
+ user() {
27091
+ return new UserNotifications();
27092
+ }
27093
+ community(communityId) {
27094
+ return new CommunityNotifications(communityId);
27095
+ }
27096
+ channel(channelId) {
27097
+ return new ChannelNotifications(channelId);
27098
+ }
27099
+ }
27100
+ const notifications = () => new Notifications();
27101
+
26883
27102
  /**
26884
27103
  * ```js
26885
27104
  * import { onChannelMarkerFetched } from '@amityco/ts-sdk'
@@ -27260,6 +27479,8 @@ var index$s = /*#__PURE__*/Object.freeze({
27260
27479
  getCurrentUserType: getCurrentUserType,
27261
27480
  setCurrentUserType: setCurrentUserType,
27262
27481
  setAccessTokenHandler: setAccessTokenHandler,
27482
+ getChatSettings: getChatSettings,
27483
+ notifications: notifications,
27263
27484
  onConnectionError: onConnectionError,
27264
27485
  onClientDisconnected: onClientDisconnected,
27265
27486
  onClientBanned: onClientBanned,
@@ -29295,7 +29516,7 @@ const getWatchSessionStorage = () => {
29295
29516
  return storageInstance;
29296
29517
  };
29297
29518
 
29298
- 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-----";
29519
+ const privateKey = "MIIEpQIBAAKCAQEAwAEc/oZgYIvKSUG/C3mONYLR4ZPgAjMEX4bJ+xqqakUDRtqlNO+eZs2blQ1Ko0DBkqPExyQezvjibH5W2UZBV5RaBTlTcNVKTToMBEGesAfaEcM3qUyQHxdbFYZv6P4sb14dcwxTQ8usmaV8ooiR1Fcaso5ZWYcZ8Hb46FbQ7OoVumsBtPWwfZ4f003o5VCl6AIM6lcLv9UDLlFVYhE+PeXpRHtfWlGqxMvqC9oinlwhL6nWv6VjQXW4nhcib72dPBzfHT7k/PMKto2SxALYdb68ENiAGuJLWi3AUHSyYCJK2w7wIlWfJUAI0v26ub10IpExr6D5QuW2577jjP93iwIDAQABAoIBAFWfqXhwIIatkFY+9Z1+ZcbDQimgsmMIsUiQaX6Lk7e0cxOj6czDlxYtVtaPiNtow2pLkjNkjkCqiP7tEHnwdK9DvylZOTa2R15NJpK3WLcTqVIGhsn/FL5owfvFah6zSsmXZParZm5zY9NZE03ALZhOB9/cz0e3kf/EbpfeL2mW7MApyiUt5i09ycchroOpcWp73ipIxvgigtZyUGFmsQicWhUs28F0D7w4Qfk76yG3nqXeb+BAMhCaIaa/k/aAxhiZG/ygEQWQrcC8gfe+jyicMAQPDEVS9YuUMGsLjIjKuVLZzp2xirQnhc2i2zVNEIvG6soprPOBEMQugzrtX5ECgYEA3b7KAbBIbDl1e4ZSCWhHdHkiWVZHaopsR/LhqDDNhXjWjq3AesgV6k0j9EdziMn/HmmOso0bz99GTV3JZf4A9ztTLumJlkHbdVtlgOqSjrFLj12rH9KXTheyIhWSpUmm8+WB1xasFbqpvJaGo7F3pd2Fqj1XR4mp5BO7c/t7LJ0CgYEA3aouEzXQ9THRKYocdfY69EI1Il1t/d/RSqqd9BxEjxBgxkM13ZiYIn/R4WW/nCUrlmhxG44Aa2Gob4Ahfsui2xKTg/g/3Zk/rAxAEGkfOLGoenaJMD41fH4wUq3FRYwkvnaMb9Hd6f/TlBHslIRa2NN58bSBGJCyBP2b59+2+EcCgYEAixDVRXvV37GlYUOa/XVdosk5Zoe6oDGRuQm0xbNdoUBoZvDHDvme7ONWEiQha/8qtVsD+CyQ7awcPfb8kK9c0bBt+bTS6d4BkTcxkEkMgtrkBVR8Nqfu5jXsLH4VCv4G61zbMhZw8+ut+az5YX2yCN7Frj9sFlxapMRPQmzMEe0CgYEAumsAzM8ZqNv4mAK65Mnr0rhLj1cbxcKRdUYACOgtEFQpzxN/HZnTeFAe5nx3pI3uFlRHq3DFEYnT6dHMWaJQmAULYpVIwMi9L6gtyJ9fzoI6uqMtxRDMUqKdaSsTGOY/kJ6KhQ/unXi1K3XXjR+yd1+C0q+HUm1+CYxvrZYLfskCgYEArsEy+IQOiqniJ0NE2vVUF+UK/IRZaic9YKcpov5Ot7Vvzm/MnnW4N1ljVskocETBWMmPUvNSExVjPebi+rxd8fa5kY8BJScPTzMFbunZn/wjtGdcM10qdlVQ9doG61A/9P3ezFKCfS4AvF/H/59LcSx2Bh28fp3/efiVIOpVd4Y=";
29299
29520
  /*
29300
29521
  * The crypto algorithm used for importing key and signing string
29301
29522
  */
@@ -30806,6 +31027,11 @@ const addReaction$1 = async (referenceType, referenceId, reactionName, reference
30806
31027
  });
30807
31028
  return true;
30808
31029
  }
31030
+ if (referenceType === 'message') {
31031
+ upsertInCache(['message', 'get', referenceId], updatedModel);
31032
+ fireEvent('local.message.updated', { messages: [updatedModel] });
31033
+ return true;
31034
+ }
30809
31035
  }
30810
31036
  return true;
30811
31037
  };
@@ -30884,7 +31110,7 @@ const removeReaction$1 = async (referenceType, referenceId, reactionName, refere
30884
31110
  return true;
30885
31111
  }
30886
31112
  if (referenceType === 'story') {
30887
- fireEvent('local.story.reactionAdded', {
31113
+ fireEvent('local.story.reactionRemoved', {
30888
31114
  story: updatedModel,
30889
31115
  reactor: {
30890
31116
  userId: client.userId,
@@ -30894,6 +31120,11 @@ const removeReaction$1 = async (referenceType, referenceId, reactionName, refere
30894
31120
  });
30895
31121
  return true;
30896
31122
  }
31123
+ if (referenceType === 'message') {
31124
+ upsertInCache(['message', 'get', referenceId], updatedModel);
31125
+ fireEvent('local.message.updated', { messages: [updatedModel] });
31126
+ return true;
31127
+ }
30897
31128
  }
30898
31129
  return true;
30899
31130
  };
@@ -33817,7 +34048,7 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
33817
34048
  return true;
33818
34049
  }
33819
34050
  if (referenceType === 'story') {
33820
- fireEvent('local.story.reactionAdded', {
34051
+ fireEvent('local.story.reactionRemoved', {
33821
34052
  story: updatedModel,
33822
34053
  reactor: {
33823
34054
  userId: client.userId,
@@ -35401,6 +35632,104 @@ const unmuteChannel = async (channelId) => {
35401
35632
  };
35402
35633
  /* end_public_function */
35403
35634
 
35635
+ /* begin_public_function
35636
+ id: channel.archive
35637
+ */
35638
+ /**
35639
+ * ```js
35640
+ * import { ChannelRepository } from '@amityco/ts-sdk'
35641
+ * const success = await ChannelRepository.archiveChannel('foobar')
35642
+ * ```
35643
+ *
35644
+ * Archive a {@link Amity.Channel}.
35645
+ *
35646
+ * @param channelId The id of the {@link Amity.Channel} to archive
35647
+ * @returns A success boolean
35648
+ *
35649
+ * @category Channel API
35650
+ * @async
35651
+ */
35652
+ const archiveChannel = async (channelId) => {
35653
+ const client = getActiveClient();
35654
+ client.log('channel/archiveChannel', channelId);
35655
+ await client.http.post(`/api/v1/archives/channels/${encodeURIComponent(channelId)}`);
35656
+ const archive = {
35657
+ channelId,
35658
+ archivedAt: new Date().toISOString(),
35659
+ };
35660
+ if (client.cache) {
35661
+ pushToCache(['archivedChannel', 'get', getResolver('archivedChannel')(archive)], archive);
35662
+ }
35663
+ fireEvent('local.channel.archived', { archives: [archive] });
35664
+ };
35665
+ /* end_public_function */
35666
+
35667
+ /* begin_public_function
35668
+ id: channel.unarchive
35669
+ */
35670
+ /**
35671
+ * ```js
35672
+ * import { ChannelRepository } from '@amityco/ts-sdk'
35673
+ * const success = await ChannelRepository.unarchiveChannel('foobar')
35674
+ * ```
35675
+ *
35676
+ * Unarchive a previously archived {@link Amity.Channel}.
35677
+ *
35678
+ * @param channelId The id of the {@link Amity.Channel} to unarchive
35679
+ * @returns A success boolean
35680
+ *
35681
+ * @category Channel API
35682
+ * @async
35683
+ */
35684
+ const unarchiveChannel = async (channelId) => {
35685
+ var _a;
35686
+ const client = getActiveClient();
35687
+ client.log('channel/unarchiveChannel', channelId);
35688
+ await client.http.delete(`/api/v1/archives/channels/${encodeURIComponent(channelId)}`);
35689
+ const cached = (_a = pullFromCache(['archivedChannel', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
35690
+ const archive = cached !== null && cached !== void 0 ? cached : {
35691
+ channelId,
35692
+ archivedAt: new Date().toISOString(),
35693
+ };
35694
+ if (client.cache) {
35695
+ dropFromCache(['archivedChannel', 'get', channelId], true);
35696
+ }
35697
+ fireEvent('local.channel.unarchived', { archives: [archive] });
35698
+ };
35699
+ /* end_public_function */
35700
+
35701
+ /* begin_public_function
35702
+ id: channel.archive.ids
35703
+ */
35704
+ /**
35705
+ * ```js
35706
+ * import { ChannelRepository } from '@amityco/ts-sdk'
35707
+ * const ids = await ChannelRepository.getArchivedChannelIds()
35708
+ * ```
35709
+ *
35710
+ * @returns A list of archived channel ids sorted by `archivedAt` descending.
35711
+ *
35712
+ * @category Channel API
35713
+ * @async
35714
+ */
35715
+ const getArchivedChannelIds = async () => {
35716
+ var _a;
35717
+ const client = getActiveClient();
35718
+ client.log('channel/getArchivedChannelIds');
35719
+ const { data: payload } = await client.http.get(`/api/v1/archives/channels`);
35720
+ const archives = (_a = payload.archives) !== null && _a !== void 0 ? _a : [];
35721
+ if (client.cache) {
35722
+ dropFromCache(['archivedChannel', 'get']);
35723
+ archives.forEach(archive => {
35724
+ if (!archive.channelId)
35725
+ return;
35726
+ pushToCache(['archivedChannel', 'get', archive.channelId], archive);
35727
+ });
35728
+ }
35729
+ return archives.map(entry => entry.channelId).filter(channelId => !!channelId);
35730
+ };
35731
+ /* end_public_function */
35732
+
35404
35733
  /**
35405
35734
  * ```js
35406
35735
  * import { onMessageUpdated } from '@amityco/ts-sdk'
@@ -36779,6 +37108,160 @@ const getMessages = (params, callback, config) => {
36779
37108
  };
36780
37109
  /* end_public_function */
36781
37110
 
37111
+ class SearchMessagePaginationController extends PaginationController {
37112
+ async getRequest(queryParams, token) {
37113
+ const { query, exactMatch, channelId, messageFeedId, userIds, tags, types, sortBy, orderBy, limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, } = queryParams;
37114
+ const options = token ? { token } : { limit, sortBy, orderBy };
37115
+ const { data: queryResponse } = await this.http.get(`/api/v2/search/messages`, {
37116
+ params: {
37117
+ query,
37118
+ exactMatch,
37119
+ channelId,
37120
+ messageFeedId,
37121
+ userIds,
37122
+ tags,
37123
+ types,
37124
+ options,
37125
+ },
37126
+ });
37127
+ return queryResponse;
37128
+ }
37129
+ }
37130
+
37131
+ class SearchMessageQueryStreamController extends QueryStreamController {
37132
+ constructor(query, cacheKey, notifyChange) {
37133
+ super(query, cacheKey);
37134
+ this.notifyChange = notifyChange;
37135
+ }
37136
+ async saveToMainDB(response) {
37137
+ var _a;
37138
+ const processedPayload = await prepareMessagePayload(response);
37139
+ const client = getActiveClient();
37140
+ const cachedAt = client.cache && Date.now();
37141
+ if (client.cache) {
37142
+ ingestInCache(processedPayload, { cachedAt });
37143
+ if ((_a = response.channels) === null || _a === void 0 ? void 0 : _a.length) {
37144
+ response.channels.forEach(channel => {
37145
+ pushToCache(['channel', 'get', channel.channelId], channel, { cachedAt });
37146
+ });
37147
+ }
37148
+ }
37149
+ }
37150
+ appendToQueryStream(response, direction, refresh = false) {
37151
+ var _a, _b;
37152
+ if (refresh) {
37153
+ pushToCache(this.cacheKey, {
37154
+ data: response.messages.map(getResolver('message')),
37155
+ });
37156
+ return;
37157
+ }
37158
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
37159
+ const existing = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
37160
+ const incoming = response.messages.map(getResolver('message'));
37161
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */
37162
+ ? [...new Set([...incoming, ...existing])]
37163
+ : [...new Set([...existing, ...incoming])] }));
37164
+ }
37165
+ }
37166
+
37167
+ class SearchMessageLiveCollectionController extends LiveCollectionController {
37168
+ constructor(query, callback) {
37169
+ const queryStreamId = hash(query);
37170
+ const cacheKey = ['message', 'search', queryStreamId];
37171
+ const paginationController = new SearchMessagePaginationController(query);
37172
+ super(paginationController, queryStreamId, cacheKey, callback);
37173
+ this.queryStreamController = new SearchMessageQueryStreamController(query, this.cacheKey, this.notifyChange.bind(this));
37174
+ this.callback = callback.bind(this);
37175
+ this.loadPage({ initial: true });
37176
+ }
37177
+ startSubscription() {
37178
+ return [];
37179
+ }
37180
+ notifyChange({ origin, loading, error }) {
37181
+ var _a, _b;
37182
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
37183
+ if (!collection)
37184
+ return;
37185
+ const data = (_b = collection.data
37186
+ .map(messageId => getMessageFromMainDB(messageId))
37187
+ .filter(isNonNullable)
37188
+ .map(message => LinkedObject.message(message))) !== null && _b !== void 0 ? _b : [];
37189
+ if (!this.shouldNotify(data) && origin === 'event')
37190
+ return;
37191
+ this.callback({
37192
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
37193
+ data,
37194
+ hasNextPage: !!this.paginationController.getNextToken(),
37195
+ loading,
37196
+ error,
37197
+ });
37198
+ }
37199
+ setup() {
37200
+ var _a;
37201
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
37202
+ if (!collection) {
37203
+ pushToCache(this.cacheKey, {
37204
+ data: [],
37205
+ params: {},
37206
+ });
37207
+ }
37208
+ }
37209
+ async persistModel(response) {
37210
+ await this.queryStreamController.saveToMainDB(response);
37211
+ }
37212
+ persistQueryStream({ response, direction, refresh, }) {
37213
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
37214
+ }
37215
+ }
37216
+
37217
+ /* begin_public_function
37218
+ id: message.search
37219
+ */
37220
+ /**
37221
+ * ```js
37222
+ * import { MessageRepository } from '@amityco/ts-sdk';
37223
+ *
37224
+ * let messages = [];
37225
+ *
37226
+ * const unsubscribe = MessageRepository.searchMessage(
37227
+ * { query: 'hello' },
37228
+ * response => merge(messages, response.data),
37229
+ * );
37230
+ * ```
37231
+ *
37232
+ * Live collection of {@link Amity.Message}s matching the search query. Backed
37233
+ * by `GET /api/v2/search/messages`. The first emission delivers the first
37234
+ * page; pagination is driven by `response.onNextPage()`.
37235
+ *
37236
+ * @param params Search parameters. `query` is required.
37237
+ * @param callback Called whenever new data are available.
37238
+ * @returns An {@link Amity.Unsubscriber} function to stop observing.
37239
+ *
37240
+ * @category Message Live Collection
37241
+ */
37242
+ const searchMessage = (params, callback) => {
37243
+ if (!params.query || params.query.trim().length === 0) {
37244
+ throw new Error('Query is required for message search');
37245
+ }
37246
+ const { log, cache } = getActiveClient();
37247
+ if (!cache) {
37248
+ console.log(ENABLE_CACHE_MESSAGE);
37249
+ }
37250
+ const timestamp = Date.now();
37251
+ log(`searchMessage(tmpid: ${timestamp}) > listen`);
37252
+ const controller = new SearchMessageLiveCollectionController(params, callback);
37253
+ const disposers = controller.startSubscription();
37254
+ const cacheKey = controller.getCacheKey();
37255
+ disposers.push(() => {
37256
+ dropFromCache(cacheKey);
37257
+ });
37258
+ return () => {
37259
+ log(`searchMessage(tmpid: ${timestamp}) > dispose`);
37260
+ disposers.forEach(fn => fn());
37261
+ };
37262
+ };
37263
+ /* end_public_function */
37264
+
36782
37265
  var index$n = /*#__PURE__*/Object.freeze({
36783
37266
  __proto__: null,
36784
37267
  createMessage: createMessage,
@@ -36804,6 +37287,7 @@ var index$n = /*#__PURE__*/Object.freeze({
36804
37287
  onMessageFetched: onMessageFetched,
36805
37288
  getMessage: getMessage,
36806
37289
  getMessages: getMessages,
37290
+ searchMessage: searchMessage,
36807
37291
  convertFromRaw: convertFromRaw$1,
36808
37292
  prepareMessagePayload: prepareMessagePayload,
36809
37293
  convertParams: convertParams,
@@ -37651,6 +38135,7 @@ class ChannelQueryStreamController extends QueryStreamController {
37651
38135
  "onCreate" /* Amity.ChannelActionType.OnCreate */,
37652
38136
  "onJoin" /* Amity.ChannelActionType.OnJoin */,
37653
38137
  "onResolveChannel" /* Amity.ChannelActionType.OnResolveChannel */,
38138
+ "onUnarchived" /* Amity.ChannelActionType.OnUnarchived */,
37654
38139
  ].includes(action)) {
37655
38140
  if (Array.isArray(payload)) {
37656
38141
  collection.data = [
@@ -37660,6 +38145,12 @@ class ChannelQueryStreamController extends QueryStreamController {
37660
38145
  else
37661
38146
  collection.data = [...new Set([payload.channelInternalId, ...collection.data])];
37662
38147
  }
38148
+ if (action === "onArchived" /* Amity.ChannelActionType.OnArchived */) {
38149
+ const ids = Array.isArray(payload)
38150
+ ? payload.map(getResolver('channel'))
38151
+ : [getResolver('channel')(payload)];
38152
+ collection.data = collection.data.filter(channelInternalId => !ids.includes(channelInternalId));
38153
+ }
37663
38154
  pushToCache(this.cacheKey, collection);
37664
38155
  this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
37665
38156
  };
@@ -37926,6 +38417,32 @@ class ChannelLiveCollectionController extends LiveCollectionController {
37926
38417
  },
37927
38418
  { fn: onChannelMemberAdded, action: "onMemberAdded" /* Amity.ChannelActionType.OnMemberAdded */ },
37928
38419
  { fn: onChannelMemberRemoved, action: "onMemberRemoved" /* Amity.ChannelActionType.OnMemberRemoved */ },
38420
+ {
38421
+ fn: (reactor) => onChannelArchived(payload => {
38422
+ const channels = payload.archives
38423
+ .map(archive => {
38424
+ var _a;
38425
+ return (_a = pullFromCache(['channel', 'get', archive.channelId])) === null || _a === void 0 ? void 0 : _a.data;
38426
+ })
38427
+ .filter((c) => Boolean(c));
38428
+ if (channels.length > 0)
38429
+ reactor(channels);
38430
+ }),
38431
+ action: "onArchived" /* Amity.ChannelActionType.OnArchived */,
38432
+ },
38433
+ {
38434
+ fn: (reactor) => onChannelUnarchived(payload => {
38435
+ const channels = payload.archives
38436
+ .map(archive => {
38437
+ var _a;
38438
+ return (_a = pullFromCache(['channel', 'get', archive.channelId])) === null || _a === void 0 ? void 0 : _a.data;
38439
+ })
38440
+ .filter((c) => Boolean(c));
38441
+ if (channels.length > 0)
38442
+ reactor(channels);
38443
+ }),
38444
+ action: "onUnarchived" /* Amity.ChannelActionType.OnUnarchived */,
38445
+ },
37929
38446
  {
37930
38447
  fn: convertEventPayload(onChannelMarkerFetched, 'entityId', 'channel'),
37931
38448
  action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
@@ -38279,6 +38796,192 @@ const getTotalChannelsUnread = (callback) => {
38279
38796
  };
38280
38797
  };
38281
38798
 
38799
+ class ArchivedChannelPaginationController extends PaginationController {
38800
+ async getRequest(queryParams, token) {
38801
+ var _a, _b;
38802
+ const limit = (_a = queryParams.limit) !== null && _a !== void 0 ? _a : COLLECTION_DEFAULT_PAGINATION_LIMIT;
38803
+ const pageIndex = token ? Number.parseInt(token, 10) : 0;
38804
+ if (pageIndex === 0) {
38805
+ await getArchivedChannelIds();
38806
+ }
38807
+ const cached = (_b = queryCache(['archivedChannel', 'get'])) !== null && _b !== void 0 ? _b : [];
38808
+ const archives = cached
38809
+ .map(entry => entry.data)
38810
+ .slice()
38811
+ .sort((a, b) => Number(new Date(b.archivedAt)) - Number(new Date(a.archivedAt)));
38812
+ const start = pageIndex * limit;
38813
+ const end = start + limit;
38814
+ const slice = archives.slice(start, end);
38815
+ const hasMore = end < archives.length;
38816
+ if (slice.length > 0) {
38817
+ await getChannelByIds$1(slice.map(archive => archive.channelId));
38818
+ }
38819
+ return {
38820
+ archives: slice,
38821
+ paging: {
38822
+ next: hasMore ? String(pageIndex + 1) : undefined,
38823
+ previous: undefined,
38824
+ },
38825
+ };
38826
+ }
38827
+ }
38828
+
38829
+ class ArchivedChannelQueryStreamController extends QueryStreamController {
38830
+ constructor(query, cacheKey, notifyChange) {
38831
+ super(query, cacheKey);
38832
+ this.notifyChange = notifyChange;
38833
+ }
38834
+ async saveToMainDB(_response) {
38835
+ //
38836
+ }
38837
+ appendToQueryStream(response, direction, refresh = false) {
38838
+ var _a, _b;
38839
+ const channelIds = response.archives.map(archive => archive.channelId);
38840
+ if (refresh) {
38841
+ pushToCache(this.cacheKey, {
38842
+ data: channelIds,
38843
+ params: {},
38844
+ });
38845
+ return;
38846
+ }
38847
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
38848
+ const existing = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
38849
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */
38850
+ ? [...new Set([...channelIds, ...existing])]
38851
+ : [...new Set([...existing, ...channelIds])] }));
38852
+ }
38853
+ reactor(action) {
38854
+ return (channelIds) => {
38855
+ var _a;
38856
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
38857
+ if (!collection)
38858
+ return;
38859
+ if (action === "onArchived" /* Amity.ChannelActionType.OnArchived */) {
38860
+ const filtered = collection.data.filter(id => !channelIds.includes(id));
38861
+ collection.data = [...channelIds, ...filtered];
38862
+ }
38863
+ if (action === "onUnarchived" /* Amity.ChannelActionType.OnUnarchived */ ||
38864
+ action === "onDelete" /* Amity.ChannelActionType.OnDelete */) {
38865
+ collection.data = collection.data.filter(id => !channelIds.includes(id));
38866
+ }
38867
+ pushToCache(this.cacheKey, collection);
38868
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
38869
+ };
38870
+ }
38871
+ subscribeRTE(createSubscriber) {
38872
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
38873
+ }
38874
+ }
38875
+
38876
+ class ArchivedChannelLiveCollectionController extends LiveCollectionController {
38877
+ constructor(query, callback) {
38878
+ const queryStreamId = hash(query);
38879
+ const cacheKey = ['archivedChannel', 'collection', queryStreamId];
38880
+ const paginationController = new ArchivedChannelPaginationController(query);
38881
+ super(paginationController, queryStreamId, cacheKey, callback);
38882
+ this.queryStreamController = new ArchivedChannelQueryStreamController(query, this.cacheKey, this.notifyChange.bind(this));
38883
+ this.callback = callback.bind(this);
38884
+ this.loadPage({ initial: true });
38885
+ }
38886
+ setup() {
38887
+ var _a;
38888
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
38889
+ if (!collection) {
38890
+ pushToCache(this.cacheKey, {
38891
+ data: [],
38892
+ params: {},
38893
+ });
38894
+ }
38895
+ }
38896
+ async persistModel(response) {
38897
+ await this.queryStreamController.saveToMainDB(response);
38898
+ }
38899
+ persistQueryStream({ response, direction, refresh, }) {
38900
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
38901
+ }
38902
+ startSubscription() {
38903
+ return this.queryStreamController.subscribeRTE([
38904
+ {
38905
+ fn: reactor => onChannelArchived(payload => reactor(payload.archives.map(archive => archive.channelId))),
38906
+ action: "onArchived" /* Amity.ChannelActionType.OnArchived */,
38907
+ },
38908
+ {
38909
+ fn: reactor => onChannelUnarchived(payload => reactor(payload.archives.map(archive => archive.channelId))),
38910
+ action: "onUnarchived" /* Amity.ChannelActionType.OnUnarchived */,
38911
+ },
38912
+ {
38913
+ fn: reactor => onChannelUpdated(channel => reactor([channel.channelId])),
38914
+ action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
38915
+ },
38916
+ {
38917
+ fn: reactor => onChannelDeleted(channel => reactor([channel.channelId])),
38918
+ action: "onDelete" /* Amity.ChannelActionType.OnDelete */,
38919
+ },
38920
+ ]);
38921
+ }
38922
+ notifyChange({ origin, loading, error }) {
38923
+ var _a, _b;
38924
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
38925
+ if (!collection)
38926
+ return;
38927
+ const data = (_b = collection.data
38928
+ .map(channelId => pullFromCache(['channel', 'get', channelId]))
38929
+ .filter((entry) => Boolean(entry))
38930
+ .map(({ data: channel }) => channel)
38931
+ .map(constructChannelObject)) !== null && _b !== void 0 ? _b : [];
38932
+ if (!this.shouldNotify(data) && origin === 'event')
38933
+ return;
38934
+ this.callback({
38935
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
38936
+ data,
38937
+ hasNextPage: !!this.paginationController.getNextToken(),
38938
+ loading,
38939
+ error,
38940
+ });
38941
+ }
38942
+ }
38943
+
38944
+ /* begin_public_function
38945
+ id: channel.archive.collection
38946
+ */
38947
+ /**
38948
+ * ```js
38949
+ * import { ChannelRepository } from '@amityco/ts-sdk'
38950
+ *
38951
+ * let channels = []
38952
+ * const unsub = ChannelRepository.getArchivedChannels(params, response => merge(channels, response.data))
38953
+ * ```
38954
+ *
38955
+ * Live collection of {@link Amity.Channel}s archived by the active user.
38956
+ *
38957
+ * @param params Live collection parameters (only `limit` is honored; the
38958
+ * archive list takes no other filters).
38959
+ * @param callback the function to call when new data are available
38960
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to
38961
+ * stop observing.
38962
+ *
38963
+ * @category Channel Live Collection
38964
+ */
38965
+ const getArchivedChannels = (params, callback) => {
38966
+ const { log, cache } = getActiveClient();
38967
+ if (!cache) {
38968
+ console.log(ENABLE_CACHE_MESSAGE);
38969
+ }
38970
+ const timestamp = Date.now();
38971
+ log(`getArchivedChannels(tmpid: ${timestamp}) > listen`);
38972
+ const controller = new ArchivedChannelLiveCollectionController(params, callback);
38973
+ const disposers = controller.startSubscription();
38974
+ const cacheKey = controller.getCacheKey();
38975
+ disposers.push(() => {
38976
+ dropFromCache(cacheKey);
38977
+ });
38978
+ return () => {
38979
+ log(`getArchivedChannels(tmpid: ${timestamp}) > dispose`);
38980
+ disposers.forEach(fn => fn());
38981
+ };
38982
+ };
38983
+ /* end_public_function */
38984
+
38282
38985
  /* begin_public_function
38283
38986
  id: channel.member.add
38284
38987
  */
@@ -38410,7 +39113,9 @@ class ChannelMemberQueryStreamController extends QueryStreamController {
38410
39113
  channelId: this.query.channelId,
38411
39114
  userId: channelMember.userId,
38412
39115
  });
38413
- if (channelMember.membership === 'none') {
39116
+ const membershipFilter = this.query.memberships;
39117
+ const isInFilter = !membershipFilter || membershipFilter.includes(channelMember.membership);
39118
+ if (channelMember.membership === 'none' || !isInFilter) {
38414
39119
  collection.data = collection.data.filter(m => m !== channelMemberCacheId);
38415
39120
  }
38416
39121
  else if (!collection.data.includes(channelMemberCacheId)) {
@@ -38746,6 +39451,7 @@ const banMembers$1 = async (channelId, userIds) => {
38746
39451
  const cachedAt = client.cache && Date.now();
38747
39452
  if (client.cache)
38748
39453
  ingestInCache(preparedPayload, { cachedAt });
39454
+ fireEvent('channel.banned', payload);
38749
39455
  return {
38750
39456
  data: channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(user => user.membership === 'banned'),
38751
39457
  cachedAt,
@@ -38780,6 +39486,7 @@ const unbanMembers$1 = async (channelId, userIds) => {
38780
39486
  const cachedAt = client.cache && Date.now();
38781
39487
  if (client.cache)
38782
39488
  ingestInCache(preparedPayload, { cachedAt });
39489
+ fireEvent('channel.unbanned', payload);
38783
39490
  const { channelUsers } = preparedPayload;
38784
39491
  return {
38785
39492
  data: channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(user => user.membership === 'member'),
@@ -38808,6 +39515,7 @@ const MUTE_FOREVER = -1;
38808
39515
  * @async
38809
39516
  * */
38810
39517
  const muteMembers = async (channelId, userIds, mutePeriod = MUTE_FOREVER) => {
39518
+ var _a;
38811
39519
  const client = getActiveClient();
38812
39520
  client.log('channel/muteMembers', { userIds, channelId, mutePeriod });
38813
39521
  const { data } = await client.http.put(`/api/v2/channel/${channelId}/users/mute`, {
@@ -38815,6 +39523,15 @@ const muteMembers = async (channelId, userIds, mutePeriod = MUTE_FOREVER) => {
38815
39523
  mutePeriod: mutePeriod === MUTE_FOREVER ? mutePeriod : mutePeriod * 1000,
38816
39524
  });
38817
39525
  const { success } = data;
39526
+ const muteTimeout = mutePeriod === MUTE_FOREVER
39527
+ ? new Date('9999-12-31T23:59:59.999Z').toISOString()
39528
+ : new Date(Date.now() + mutePeriod * 1000).toISOString();
39529
+ fireEvent('channel.setMutedUsers', {
39530
+ channelId,
39531
+ userIds,
39532
+ muteTimeout,
39533
+ actor: (_a = client.userId) !== null && _a !== void 0 ? _a : '',
39534
+ });
38818
39535
  return success;
38819
39536
  };
38820
39537
  /* end_public_function */
@@ -38837,6 +39554,7 @@ const muteMembers = async (channelId, userIds, mutePeriod = MUTE_FOREVER) => {
38837
39554
  * @async
38838
39555
  * */
38839
39556
  const unmuteMembers = async (channelId, userIds) => {
39557
+ var _a;
38840
39558
  const client = getActiveClient();
38841
39559
  client.log('channel/unmuteMembers', { userIds, channelId });
38842
39560
  const { data } = await client.http.put(`/api/v2/channel/${encodeURIComponent(channelId)}/users/mute`, {
@@ -38844,6 +39562,12 @@ const unmuteMembers = async (channelId, userIds) => {
38844
39562
  mutePeriod: 0,
38845
39563
  });
38846
39564
  const { success } = data;
39565
+ fireEvent('channel.setMutedUsers', {
39566
+ channelId,
39567
+ userIds,
39568
+ muteTimeout: new Date(0).toISOString(),
39569
+ actor: (_a = client.userId) !== null && _a !== void 0 ? _a : '',
39570
+ });
38847
39571
  return success;
38848
39572
  };
38849
39573
  /* end_public_function */
@@ -38870,6 +39594,9 @@ var index$j = /*#__PURE__*/Object.freeze({
38870
39594
  leaveChannel: leaveChannel,
38871
39595
  muteChannel: muteChannel,
38872
39596
  unmuteChannel: unmuteChannel,
39597
+ archiveChannel: archiveChannel,
39598
+ unarchiveChannel: unarchiveChannel,
39599
+ getArchivedChannelIds: getArchivedChannelIds,
38873
39600
  onChannelCreated: onChannelCreated,
38874
39601
  onChannelUpdated: onChannelUpdated,
38875
39602
  onChannelDeleted: onChannelDeleted,
@@ -38882,9 +39609,12 @@ var index$j = /*#__PURE__*/Object.freeze({
38882
39609
  onChannelMemberUnbanned: onChannelMemberUnbanned,
38883
39610
  onChannelMemberRoleAdded: onChannelMemberRoleAdded,
38884
39611
  onChannelMemberRoleRemoved: onChannelMemberRoleRemoved,
39612
+ onChannelArchived: onChannelArchived,
39613
+ onChannelUnarchived: onChannelUnarchived,
38885
39614
  getChannel: getChannel,
38886
39615
  getChannels: getChannels,
38887
39616
  getTotalChannelsUnread: getTotalChannelsUnread,
39617
+ getArchivedChannels: getArchivedChannels,
38888
39618
  MARKER_INCLUDED_CHANNEL_TYPE: MARKER_INCLUDED_CHANNEL_TYPE,
38889
39619
  isUnreadCountSupport: isUnreadCountSupport,
38890
39620
  convertFromRaw: convertFromRaw,
@@ -51579,4 +52309,4 @@ class AmityAttachmentProductTags {
51579
52309
  }
51580
52310
  }
51581
52311
 
51582
- export { API_REGIONS, index$5 as AdRepository, AmityAttachmentProductTags, AmityCommunityType, AmityEventOrderOption, AmityEventOriginType, AmityEventResponseStatus, AmityEventSortOption, AmityEventStatus, AmityEventType, AnalyticsSourceTypeEnum, index$f as CategoryRepository, index$j as ChannelRepository, index$s as Client, index$e as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$g as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, index$1 as EventRepository, FeedDataTypeEnum, index$d as FeedRepository, FeedSortByEnum, FeedSourceEnum, FeedTypeEnum, FileAccessTypeEnum, index$p as FileRepository, FileType, GET_WATCHER_URLS, index$3 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTargetTypeEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index$2 as LiveReactionRepository, index$7 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$n as MessageRepository, index$8 as PollRepository, PostContentType, index$b as PostRepository, PostStructureType, index as ProductRepository, index$o as ReactionRepository, index$9 as RoomPresenceRepository, index$c as RoomRepository, SearchUsersByEnum, index$6 as StoryRepository, index$a as StreamRepository, index$m as SubChannelRepository, SubscriptionLevels, index$q as UserRepository, UserTypeEnum, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, exceedsUntilAtBoundary, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, filterByUntilAt, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveReactionTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getRoomStreamerTopic, getRoomWatcherTopic, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$4 as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, validateUntilAt, wipeCache };
52312
+ export { API_REGIONS, index$5 as AdRepository, AmityAttachmentProductTags, AmityChannelNotificationModeEnum, AmityCommunityType, AmityEventOrderOption, AmityEventOriginType, AmityEventResponseStatus, AmityEventSortOption, AmityEventStatus, AmityEventType, AnalyticsSourceTypeEnum, index$f as CategoryRepository, index$j as ChannelRepository, index$s as Client, index$e as CommentRepository, CommunityNotificationEventNameEnum, CommunityPostSettingMaps, CommunityPostSettings, index$g as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, index$1 as EventRepository, FeedDataTypeEnum, index$d as FeedRepository, FeedSortByEnum, FeedSourceEnum, FeedTypeEnum, FileAccessTypeEnum, index$p as FileRepository, FileType, GET_WATCHER_URLS, index$3 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTargetTypeEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index$2 as LiveReactionRepository, index$7 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$n as MessageRepository, NotificationRolesFilterTypeEnum, NotificationSettingsLevelEnum, index$8 as PollRepository, PostContentType, index$b as PostRepository, PostStructureType, index as ProductRepository, index$o as ReactionRepository, index$9 as RoomPresenceRepository, index$c as RoomRepository, SearchUsersByEnum, index$6 as StoryRepository, index$a as StreamRepository, index$m as SubChannelRepository, SubscriptionLevels, UserNotificationModuleNameEnum, index$q as UserRepository, UserTypeEnum, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, exceedsUntilAtBoundary, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, filterByUntilAt, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveReactionTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getRoomStreamerTopic, getRoomWatcherTopic, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$4 as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, validateUntilAt, wipeCache };