@amityco/ts-sdk 7.11.1-9f733521.0 → 7.11.1-b50cd2fe.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 (160) hide show
  1. package/dist/@types/core/events.d.ts +13 -32
  2. package/dist/@types/core/events.d.ts.map +1 -1
  3. package/dist/@types/core/model.d.ts +3 -2
  4. package/dist/@types/core/model.d.ts.map +1 -1
  5. package/dist/@types/core/payload.d.ts +4 -15
  6. package/dist/@types/core/payload.d.ts.map +1 -1
  7. package/dist/@types/core/transport.d.ts +0 -3
  8. package/dist/@types/core/transport.d.ts.map +1 -1
  9. package/dist/@types/domains/community.d.ts +1 -8
  10. package/dist/@types/domains/community.d.ts.map +1 -1
  11. package/dist/@types/domains/content.d.ts +4 -1
  12. package/dist/@types/domains/content.d.ts.map +1 -1
  13. package/dist/@types/domains/feed.d.ts +2 -1
  14. package/dist/@types/domains/feed.d.ts.map +1 -1
  15. package/dist/@types/domains/partials.d.ts +2 -2
  16. package/dist/@types/domains/partials.d.ts.map +1 -1
  17. package/dist/@types/domains/post.d.ts +2 -0
  18. package/dist/@types/domains/post.d.ts.map +1 -1
  19. package/dist/@types/domains/room.d.ts +77 -0
  20. package/dist/@types/domains/room.d.ts.map +1 -0
  21. package/dist/@types/index.d.ts +2 -1
  22. package/dist/@types/index.d.ts.map +1 -1
  23. package/dist/channelRepository/api/createChannel.d.ts +1 -0
  24. package/dist/channelRepository/api/createChannel.d.ts.map +1 -1
  25. package/dist/core/events.d.ts +3 -3
  26. package/dist/core/events.d.ts.map +1 -1
  27. package/dist/core/model/index.d.ts.map +1 -1
  28. package/dist/core/subscription.d.ts +2 -0
  29. package/dist/core/subscription.d.ts.map +1 -1
  30. package/dist/index.cjs.js +2796 -2568
  31. package/dist/index.d.ts +1 -1
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.esm.js +872 -646
  34. package/dist/index.umd.js +3 -3
  35. package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts +1 -1
  36. package/dist/messagePreview/utils/getSubChannelMessagePreviewWithUser.d.ts +1 -1
  37. package/dist/roomRepository/api/createRoom.d.ts +24 -0
  38. package/dist/roomRepository/api/createRoom.d.ts.map +1 -0
  39. package/dist/roomRepository/api/deleteRoom.d.ts +16 -0
  40. package/dist/roomRepository/api/deleteRoom.d.ts.map +1 -0
  41. package/dist/roomRepository/api/getBroadcasterData.d.ts +16 -0
  42. package/dist/roomRepository/api/getBroadcasterData.d.ts.map +1 -0
  43. package/dist/roomRepository/api/getRecordedUrl.d.ts +19 -0
  44. package/dist/roomRepository/api/getRecordedUrl.d.ts.map +1 -0
  45. package/dist/roomRepository/api/index.d.ts +7 -0
  46. package/dist/roomRepository/api/index.d.ts.map +1 -0
  47. package/dist/roomRepository/api/stopRoom.d.ts +16 -0
  48. package/dist/roomRepository/api/stopRoom.d.ts.map +1 -0
  49. package/dist/roomRepository/api/updateRoom.d.ts +24 -0
  50. package/dist/roomRepository/api/updateRoom.d.ts.map +1 -0
  51. package/dist/roomRepository/events/index.d.ts +12 -0
  52. package/dist/roomRepository/events/index.d.ts.map +1 -0
  53. package/dist/roomRepository/events/onRoomCreated.d.ts +17 -0
  54. package/dist/roomRepository/events/onRoomCreated.d.ts.map +1 -0
  55. package/dist/roomRepository/events/onRoomDeleted.d.ts +17 -0
  56. package/dist/roomRepository/events/onRoomDeleted.d.ts.map +1 -0
  57. package/dist/roomRepository/events/onRoomEndBroadcasting.d.ts +17 -0
  58. package/dist/roomRepository/events/onRoomEndBroadcasting.d.ts.map +1 -0
  59. package/dist/roomRepository/events/onRoomParticipantInviting.d.ts +17 -0
  60. package/dist/roomRepository/events/onRoomParticipantInviting.d.ts.map +1 -0
  61. package/dist/roomRepository/events/onRoomParticipantJoined.d.ts +17 -0
  62. package/dist/roomRepository/events/onRoomParticipantJoined.d.ts.map +1 -0
  63. package/dist/roomRepository/events/onRoomParticipantLeft.d.ts +17 -0
  64. package/dist/roomRepository/events/onRoomParticipantLeft.d.ts.map +1 -0
  65. package/dist/roomRepository/events/onRoomRecordedAvailable.d.ts +17 -0
  66. package/dist/roomRepository/events/onRoomRecordedAvailable.d.ts.map +1 -0
  67. package/dist/roomRepository/events/onRoomStartBroadcasting.d.ts +17 -0
  68. package/dist/roomRepository/events/onRoomStartBroadcasting.d.ts.map +1 -0
  69. package/dist/roomRepository/events/onRoomStopped.d.ts +17 -0
  70. package/dist/roomRepository/events/onRoomStopped.d.ts.map +1 -0
  71. package/dist/roomRepository/events/onRoomUpdated.d.ts +17 -0
  72. package/dist/roomRepository/events/onRoomUpdated.d.ts.map +1 -0
  73. package/dist/roomRepository/events/onRoomWaitingReconnect.d.ts +17 -0
  74. package/dist/roomRepository/events/onRoomWaitingReconnect.d.ts.map +1 -0
  75. package/dist/roomRepository/index.d.ts.map +1 -0
  76. package/dist/roomRepository/internalApi/getLiveChat.d.ts +16 -0
  77. package/dist/roomRepository/internalApi/getLiveChat.d.ts.map +1 -0
  78. package/dist/roomRepository/internalApi/getRoomById.d.ts +5 -0
  79. package/dist/roomRepository/internalApi/getRoomById.d.ts.map +1 -0
  80. package/dist/roomRepository/internalApi/index.d.ts +3 -0
  81. package/dist/roomRepository/internalApi/index.d.ts.map +1 -0
  82. package/dist/roomRepository/observers/enums.d.ts +10 -0
  83. package/dist/roomRepository/observers/enums.d.ts.map +1 -0
  84. package/dist/roomRepository/observers/getRoom.d.ts +2 -0
  85. package/dist/roomRepository/observers/getRoom.d.ts.map +1 -0
  86. package/dist/roomRepository/observers/getRooms/RoomLiveCollectionController.d.ts +14 -0
  87. package/dist/roomRepository/observers/getRooms/RoomLiveCollectionController.d.ts.map +1 -0
  88. package/dist/roomRepository/observers/getRooms/RoomPaginationController.d.ts +5 -0
  89. package/dist/roomRepository/observers/getRooms/RoomPaginationController.d.ts.map +1 -0
  90. package/dist/roomRepository/observers/getRooms/RoomQueryStreamController.d.ts +15 -0
  91. package/dist/roomRepository/observers/getRooms/RoomQueryStreamController.d.ts.map +1 -0
  92. package/dist/roomRepository/observers/getRooms.d.ts +29 -0
  93. package/dist/roomRepository/observers/getRooms.d.ts.map +1 -0
  94. package/dist/roomRepository/observers/index.d.ts +3 -0
  95. package/dist/roomRepository/observers/index.d.ts.map +1 -0
  96. package/dist/roomRepository/observers/utils.d.ts +6 -0
  97. package/dist/roomRepository/observers/utils.d.ts.map +1 -0
  98. package/dist/utils/linkedObject/index.d.ts +0 -1
  99. package/dist/utils/linkedObject/index.d.ts.map +1 -1
  100. package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
  101. package/dist/utils/linkedObject/roomLinkedObject.d.ts +2 -0
  102. package/dist/utils/linkedObject/roomLinkedObject.d.ts.map +1 -0
  103. package/dist/utils/postTypePredicate.d.ts +1 -0
  104. package/dist/utils/postTypePredicate.d.ts.map +1 -1
  105. package/dist/utils/tests/dummy/comment.d.ts +1 -1
  106. package/package.json +1 -1
  107. package/dist/@types/domains/event.d.ts +0 -77
  108. package/dist/@types/domains/event.d.ts.map +0 -1
  109. package/dist/eventRepository/api/createEvent.d.ts +0 -16
  110. package/dist/eventRepository/api/createEvent.d.ts.map +0 -1
  111. package/dist/eventRepository/api/deleteEvent.d.ts +0 -15
  112. package/dist/eventRepository/api/deleteEvent.d.ts.map +0 -1
  113. package/dist/eventRepository/api/index.d.ts +0 -4
  114. package/dist/eventRepository/api/index.d.ts.map +0 -1
  115. package/dist/eventRepository/api/updateEvent.d.ts +0 -17
  116. package/dist/eventRepository/api/updateEvent.d.ts.map +0 -1
  117. package/dist/eventRepository/events/enums.d.ts +0 -6
  118. package/dist/eventRepository/events/enums.d.ts.map +0 -1
  119. package/dist/eventRepository/events/index.d.ts +0 -4
  120. package/dist/eventRepository/events/index.d.ts.map +0 -1
  121. package/dist/eventRepository/events/onEventCreated.d.ts +0 -17
  122. package/dist/eventRepository/events/onEventCreated.d.ts.map +0 -1
  123. package/dist/eventRepository/events/onEventDeleted.d.ts +0 -17
  124. package/dist/eventRepository/events/onEventDeleted.d.ts.map +0 -1
  125. package/dist/eventRepository/events/onEventUpdated.d.ts +0 -17
  126. package/dist/eventRepository/events/onEventUpdated.d.ts.map +0 -1
  127. package/dist/eventRepository/index.d.ts.map +0 -1
  128. package/dist/eventRepository/internalApi/getEvent.d.ts +0 -32
  129. package/dist/eventRepository/internalApi/getEvent.d.ts.map +0 -1
  130. package/dist/eventRepository/internalApi/index.d.ts +0 -2
  131. package/dist/eventRepository/internalApi/index.d.ts.map +0 -1
  132. package/dist/eventRepository/observers/getEvent.d.ts +0 -21
  133. package/dist/eventRepository/observers/getEvent.d.ts.map +0 -1
  134. package/dist/eventRepository/observers/getEvents/LiveCollectionController.d.ts +0 -13
  135. package/dist/eventRepository/observers/getEvents/LiveCollectionController.d.ts.map +0 -1
  136. package/dist/eventRepository/observers/getEvents/PaginationController.d.ts +0 -5
  137. package/dist/eventRepository/observers/getEvents/PaginationController.d.ts.map +0 -1
  138. package/dist/eventRepository/observers/getEvents/QueryStreamController.d.ts +0 -15
  139. package/dist/eventRepository/observers/getEvents/QueryStreamController.d.ts.map +0 -1
  140. package/dist/eventRepository/observers/getEvents.d.ts +0 -12
  141. package/dist/eventRepository/observers/getEvents.d.ts.map +0 -1
  142. package/dist/eventRepository/observers/getMyEvents/LiveCollectionController.d.ts +0 -13
  143. package/dist/eventRepository/observers/getMyEvents/LiveCollectionController.d.ts.map +0 -1
  144. package/dist/eventRepository/observers/getMyEvents/PaginationController.d.ts +0 -5
  145. package/dist/eventRepository/observers/getMyEvents/PaginationController.d.ts.map +0 -1
  146. package/dist/eventRepository/observers/getMyEvents/QueryStreamController.d.ts +0 -15
  147. package/dist/eventRepository/observers/getMyEvents/QueryStreamController.d.ts.map +0 -1
  148. package/dist/eventRepository/observers/getMyEvents.d.ts +0 -12
  149. package/dist/eventRepository/observers/getMyEvents.d.ts.map +0 -1
  150. package/dist/eventRepository/observers/index.d.ts +0 -4
  151. package/dist/eventRepository/observers/index.d.ts.map +0 -1
  152. package/dist/eventRepository/utils/createEventEventSubscriber.d.ts +0 -2
  153. package/dist/eventRepository/utils/createEventEventSubscriber.d.ts.map +0 -1
  154. package/dist/eventRepository/utils/index.d.ts +0 -3
  155. package/dist/eventRepository/utils/index.d.ts.map +0 -1
  156. package/dist/eventRepository/utils/prepareEventPayload.d.ts +0 -2
  157. package/dist/eventRepository/utils/prepareEventPayload.d.ts.map +0 -1
  158. package/dist/utils/linkedObject/eventLinkObject.d.ts +0 -2
  159. package/dist/utils/linkedObject/eventLinkObject.d.ts.map +0 -1
  160. /package/dist/{eventRepository → roomRepository}/index.d.ts +0 -0
package/dist/index.esm.js CHANGED
@@ -112,6 +112,7 @@ const PostContentType = Object.freeze({
112
112
  POLL: 'poll',
113
113
  CLIP: 'clip',
114
114
  AUDIO: 'audio',
115
+ ROOM: 'room',
115
116
  });
116
117
  const PostStructureType = Object.freeze({
117
118
  TEXT: 'text',
@@ -163,6 +164,7 @@ var FeedDataTypeEnum;
163
164
  FeedDataTypeEnum["LiveStream"] = "liveStream";
164
165
  FeedDataTypeEnum["Clip"] = "clip";
165
166
  FeedDataTypeEnum["Poll"] = "poll";
167
+ FeedDataTypeEnum["Room"] = "room";
166
168
  })(FeedDataTypeEnum || (FeedDataTypeEnum = {}));
167
169
  var FeedSortByEnum;
168
170
  (function (FeedSortByEnum) {
@@ -177,30 +179,6 @@ var FeedSourceEnum;
177
179
  FeedSourceEnum["User"] = "user";
178
180
  })(FeedSourceEnum || (FeedSourceEnum = {}));
179
181
 
180
- var AmityEventType;
181
- (function (AmityEventType) {
182
- AmityEventType["Virtual"] = "virtual";
183
- AmityEventType["InPerson"] = "in_person";
184
- })(AmityEventType || (AmityEventType = {}));
185
- var AmityEventOriginType;
186
- (function (AmityEventOriginType) {
187
- AmityEventOriginType["Community"] = "community";
188
- AmityEventOriginType["User"] = "user";
189
- })(AmityEventOriginType || (AmityEventOriginType = {}));
190
- var AmityEventStatus;
191
- (function (AmityEventStatus) {
192
- AmityEventStatus["Scheduled"] = "scheduled";
193
- AmityEventStatus["Live"] = "live";
194
- AmityEventStatus["Ended"] = "ended";
195
- AmityEventStatus["Cancelled"] = "cancelled";
196
- })(AmityEventStatus || (AmityEventStatus = {}));
197
- var AmityEventResponseStatus;
198
- (function (AmityEventResponseStatus) {
199
- AmityEventResponseStatus["Going"] = "going";
200
- AmityEventResponseStatus["Interested"] = "interested";
201
- AmityEventResponseStatus["NotGoing"] = "not_going";
202
- })(AmityEventResponseStatus || (AmityEventResponseStatus = {}));
203
-
204
182
  function getVersion() {
205
183
  try {
206
184
  // the string ''v7.11.0-esm'' should be replaced by actual value by @rollup/plugin-replace
@@ -649,7 +627,7 @@ const idResolvers = {
649
627
  notificationTraySeen: ({ userId }) => userId,
650
628
  invitation: ({ _id }) => _id,
651
629
  joinRequest: ({ joinRequestId }) => joinRequestId,
652
- event: ({ eventId }) => eventId,
630
+ room: ({ roomId }) => roomId,
653
631
  };
654
632
  /**
655
633
  * Retrieve the id resolver matching a domain name
@@ -705,8 +683,7 @@ const PAYLOAD2MODEL = {
705
683
  notificationTrayItems: 'notificationTrayItem',
706
684
  invitations: 'invitation',
707
685
  joinRequests: 'joinRequest',
708
- events: 'event',
709
- discussionCommunities: 'community',
686
+ rooms: 'room',
710
687
  };
711
688
  /** hidden */
712
689
  const isOutdated = (prevData, nextData) => {
@@ -1506,6 +1483,37 @@ async function modifyMqttConnection() {
1506
1483
  }
1507
1484
  }
1508
1485
 
1486
+ const userLinkedObject = (user) => {
1487
+ return Object.assign(Object.assign({}, user), { get avatar() {
1488
+ var _a;
1489
+ if (!user.avatarFileId)
1490
+ return undefined;
1491
+ const avatar = (_a = pullFromCache([
1492
+ 'file',
1493
+ 'get',
1494
+ `${user.avatarFileId}`,
1495
+ ])) === null || _a === void 0 ? void 0 : _a.data;
1496
+ return avatar;
1497
+ } });
1498
+ };
1499
+
1500
+ /* begin_public_function
1501
+ id: client.get_current_user
1502
+ */
1503
+ const getCurrentUser = () => {
1504
+ var _a;
1505
+ const client = getActiveClient();
1506
+ if (!client) {
1507
+ throw new ASCError('Connect client first', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "fatal" /* Amity.ErrorLevel.FATAL */);
1508
+ }
1509
+ const cache = (_a = pullFromCache(['user', 'get', client.userId])) === null || _a === void 0 ? void 0 : _a.data;
1510
+ if (!cache) {
1511
+ throw new ASCError('Connect client first', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "fatal" /* Amity.ErrorLevel.FATAL */);
1512
+ }
1513
+ return userLinkedObject(cache);
1514
+ };
1515
+ /* end_public_function */
1516
+
1509
1517
  var SubscriptionLevels;
1510
1518
  (function (SubscriptionLevels) {
1511
1519
  SubscriptionLevels["COMMUNITY"] = "community";
@@ -1611,6 +1619,14 @@ const getLiveStreamTopic = () => {
1611
1619
  const getLiveReactionTopic = (post) => {
1612
1620
  return `${post.path}/liveReaction`;
1613
1621
  };
1622
+ const getRoomWatcherTopic = (room) => {
1623
+ const user = getCurrentUser();
1624
+ return `${getNetworkId(user)}/room/${room._id}`;
1625
+ };
1626
+ const getRoomStreamerTopic = (room) => {
1627
+ const user = getCurrentUser();
1628
+ return `${getNetworkId(user)}/room/${room.roomId}/streamer`;
1629
+ };
1614
1630
  function subscribeTopic(topic, callback) {
1615
1631
  const { mqtt } = getActiveClient();
1616
1632
  if (!mqtt)
@@ -21037,20 +21053,6 @@ const getChannelMessagePreview = (channelId) => {
21037
21053
  return ((_b = (_a = pullFromCache(['messagePreviewChannel', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : null);
21038
21054
  };
21039
21055
 
21040
- const userLinkedObject = (user) => {
21041
- return Object.assign(Object.assign({}, user), { get avatar() {
21042
- var _a;
21043
- if (!user.avatarFileId)
21044
- return undefined;
21045
- const avatar = (_a = pullFromCache([
21046
- 'file',
21047
- 'get',
21048
- `${user.avatarFileId}`,
21049
- ])) === null || _a === void 0 ? void 0 : _a.data;
21050
- return avatar;
21051
- } });
21052
- };
21053
-
21054
21056
  const getChannelMessagePreviewWithUser = (channel) => {
21055
21057
  var _a;
21056
21058
  const messagePreview = channel.messagePreviewId
@@ -25133,23 +25135,6 @@ const loginAsVisitor = async (params) => {
25133
25135
  };
25134
25136
  /* end_public_function */
25135
25137
 
25136
- /* begin_public_function
25137
- id: client.get_current_user
25138
- */
25139
- const getCurrentUser = () => {
25140
- var _a;
25141
- const client = getActiveClient();
25142
- if (!client) {
25143
- throw new ASCError('Connect client first', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "fatal" /* Amity.ErrorLevel.FATAL */);
25144
- }
25145
- const cache = (_a = pullFromCache(['user', 'get', client.userId])) === null || _a === void 0 ? void 0 : _a.data;
25146
- if (!cache) {
25147
- throw new ASCError('Connect client first', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "fatal" /* Amity.ErrorLevel.FATAL */);
25148
- }
25149
- return userLinkedObject(cache);
25150
- };
25151
- /* end_public_function */
25152
-
25153
25138
  /* begin_public_function
25154
25139
  id: client.renew_access_token
25155
25140
  */
@@ -28151,7 +28136,7 @@ getChannel$1.locally = (channelId) => {
28151
28136
  * @category Stream API
28152
28137
  * @async
28153
28138
  */
28154
- const getLiveChat = async (stream) => {
28139
+ const getLiveChat$1 = async (stream) => {
28155
28140
  var _a;
28156
28141
  const client = getActiveClient();
28157
28142
  client.log('stream/getLiveChat', stream.streamId);
@@ -28218,7 +28203,7 @@ const streamLinkedObject = (stream) => {
28218
28203
  return streamLinkedObject(streamCache);
28219
28204
  })
28220
28205
  .filter(isNonNullable);
28221
- }, getLiveChat: () => getLiveChat(stream), isBanned: !stream.watcherUrl, watcherUrl: null, get [GET_WATCHER_URLS]() {
28206
+ }, getLiveChat: () => getLiveChat$1(stream), isBanned: !stream.watcherUrl, watcherUrl: null, get [GET_WATCHER_URLS]() {
28222
28207
  return stream.watcherUrl;
28223
28208
  } });
28224
28209
  };
@@ -28326,6 +28311,95 @@ function isAmityAudioPost(post) {
28326
28311
  'fileId' in post.data &&
28327
28312
  post.dataType === 'audio');
28328
28313
  }
28314
+ function isAmityRoomPost(post) {
28315
+ return !!(post.data &&
28316
+ typeof post.data !== 'string' &&
28317
+ 'roomId' in post.data &&
28318
+ post.dataType === 'room');
28319
+ }
28320
+
28321
+ /**
28322
+ * ```js
28323
+ * import { RoomRepository } from '@amityco/ts-sdk'
28324
+ * const stream = await getStream('foobar')
28325
+ * ```
28326
+ *
28327
+ * Fetches a {@link Amity.Channel} object linked with a current stream
28328
+ *
28329
+ * @param stream {@link Amity.Stream} that has linked live channel
28330
+ * @returns the associated {@link Amity.Channel<'live'>} object
28331
+ *
28332
+ * @category Stream API
28333
+ * @async
28334
+ */
28335
+ const getLiveChat = async (room) => {
28336
+ var _a;
28337
+ const client = getActiveClient();
28338
+ client.log('room/getLiveChat', room.roomId);
28339
+ if (room.liveChannelId) {
28340
+ const channel = (_a = pullFromCache([
28341
+ 'channel',
28342
+ 'get',
28343
+ room.liveChannelId,
28344
+ ])) === null || _a === void 0 ? void 0 : _a.data;
28345
+ if (channel)
28346
+ return channelLinkedObject(constructChannelObject(channel));
28347
+ const { data } = await getChannel$1(room.liveChannelId);
28348
+ return channelLinkedObject(constructChannelObject(data));
28349
+ }
28350
+ // No Channel ID
28351
+ // streamer: create a new live channel
28352
+ if (room.createdBy === client.userId) {
28353
+ const { data: channel } = await createChannel({
28354
+ type: 'live',
28355
+ postId: room.referenceId,
28356
+ roomId: room.roomId,
28357
+ });
28358
+ // Update channelId to stream object in cache
28359
+ mergeInCache(['room', 'get', room.roomId], {
28360
+ liveChannelId: channel.channelId,
28361
+ });
28362
+ return channel;
28363
+ }
28364
+ // watcher: return undefined
28365
+ return undefined;
28366
+ };
28367
+
28368
+ const roomLinkedObject = (room) => {
28369
+ return Object.assign(Object.assign({}, room), { get moderation() {
28370
+ var _a;
28371
+ return (_a = pullFromCache(['roomModeration', 'get', room.roomId])) === null || _a === void 0 ? void 0 : _a.data;
28372
+ },
28373
+ get post() {
28374
+ var _a;
28375
+ if (room.referenceType !== 'post')
28376
+ return;
28377
+ return (_a = pullFromCache(['post', 'get', room.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
28378
+ },
28379
+ get community() {
28380
+ var _a;
28381
+ if (room.targetType !== 'community')
28382
+ return;
28383
+ return (_a = pullFromCache(['community', 'get', room.targetId])) === null || _a === void 0 ? void 0 : _a.data;
28384
+ },
28385
+ get user() {
28386
+ var _a;
28387
+ return (_a = pullFromCache(['user', 'get', room.createdBy])) === null || _a === void 0 ? void 0 : _a.data;
28388
+ },
28389
+ get childRooms() {
28390
+ if (!room.childRoomIds || room.childRoomIds.length === 0)
28391
+ return [];
28392
+ return room.childRoomIds
28393
+ .map(id => {
28394
+ var _a;
28395
+ const roomCache = (_a = pullFromCache(['room', 'get', id])) === null || _a === void 0 ? void 0 : _a.data;
28396
+ if (!roomCache)
28397
+ return undefined;
28398
+ return roomLinkedObject(roomCache);
28399
+ })
28400
+ .filter(isNonNullable);
28401
+ }, getLiveChat: () => getLiveChat(room) });
28402
+ };
28329
28403
 
28330
28404
  const postLinkedObject = (post) => {
28331
28405
  return shallowClone(post, {
@@ -28420,6 +28494,13 @@ const postLinkedObject = (post) => {
28420
28494
  ? (_b = pullFromCache(['file', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.fileId])) === null || _b === void 0 ? void 0 : _b.data
28421
28495
  : undefined;
28422
28496
  },
28497
+ getRoomInfo() {
28498
+ var _a, _b;
28499
+ if (!isAmityRoomPost(post))
28500
+ return;
28501
+ const room = (_b = pullFromCache(['room', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.roomId])) === null || _b === void 0 ? void 0 : _b.data;
28502
+ return room ? roomLinkedObject(room) : undefined;
28503
+ },
28423
28504
  });
28424
28505
  };
28425
28506
 
@@ -29777,35 +29858,6 @@ const communityLinkedObject = (community) => {
29777
29858
  } });
29778
29859
  };
29779
29860
 
29780
- const eventLinkedObject = (event) => {
29781
- return Object.assign(Object.assign({}, event), { get creator() {
29782
- const cacheData = pullFromCache(['user', 'get', event.userId]);
29783
- if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
29784
- return;
29785
- return userLinkedObject(cacheData.data);
29786
- },
29787
- get discussionCommunity() {
29788
- if (!event.discussionCommunityId)
29789
- return;
29790
- const cacheData = pullFromCache([
29791
- 'community',
29792
- 'get',
29793
- event.discussionCommunityId,
29794
- ]);
29795
- if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
29796
- return;
29797
- return communityLinkedObject(cacheData.data);
29798
- },
29799
- get liveStream() {
29800
- if (!event.livestreamId)
29801
- return;
29802
- const cacheData = pullFromCache(['stream', 'get', event.livestreamId]);
29803
- if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
29804
- return;
29805
- return cacheData.data;
29806
- } });
29807
- };
29808
-
29809
29861
  const LinkedObject = {
29810
29862
  ad: adLinkedObject,
29811
29863
  comment: commentLinkedObject,
@@ -29824,7 +29876,6 @@ const LinkedObject = {
29824
29876
  invitation: invitationLinkedObject,
29825
29877
  joinRequest: joinRequestLinkedObject,
29826
29878
  channelMember: channelMemberLinkedObject,
29827
- event: eventLinkedObject,
29828
29879
  };
29829
29880
 
29830
29881
  /* begin_public_function
@@ -43809,6 +43860,729 @@ var index$8 = /*#__PURE__*/Object.freeze({
43809
43860
  getStreams: getStreams
43810
43861
  });
43811
43862
 
43863
+ /* begin_public_function
43864
+ id: room.create
43865
+ */
43866
+ /**
43867
+ * ```js
43868
+ * import { createRoom } from '@amityco/ts-sdk'
43869
+ * const created = await createRoom({ title: 'my room', 'thumbnailFileId': fileId })
43870
+ * ```
43871
+ *
43872
+ * Creates an {@link Amity.Room}
43873
+ *
43874
+ * @param bundle The data necessary to create a new {@link Amity.Room}
43875
+ * @returns The newly created {@link Amity.Room}
43876
+ *
43877
+ * @category Room API
43878
+ * @async
43879
+ */
43880
+ const createRoom = async (bundle) => {
43881
+ const client = getActiveClient();
43882
+ client.log('room/createRoom', bundle);
43883
+ const { data } = await client.http.post('/api/v1/rooms', bundle);
43884
+ fireEvent('local.room.created', data);
43885
+ const cachedAt = client.cache && Date.now();
43886
+ // TODO: check if should pick `users` filed which contains participants - if no need to ingest in the cache
43887
+ if (client.cache)
43888
+ ingestInCache(data, { cachedAt });
43889
+ const { rooms } = data;
43890
+ return {
43891
+ data: roomLinkedObject(rooms[0]),
43892
+ cachedAt,
43893
+ };
43894
+ };
43895
+ /* end_public_function */
43896
+
43897
+ /* begin_public_function
43898
+ id: room.update
43899
+ */
43900
+ /**
43901
+ * ```js
43902
+ * import { updateRoom } from '@amityco/ts-sdk'
43903
+ * const updated = await updateRoom('roomId', { title: 'updated title' })
43904
+ * ```
43905
+ *
43906
+ * Updates an {@link Amity.InternalRoom}
43907
+ *
43908
+ * @param roomId The ID of the room to update
43909
+ * @param bundle The data to update the room with
43910
+ * @returns The updated {@link Amity.InternalRoom}
43911
+ *
43912
+ * @category Room API
43913
+ * @async
43914
+ */
43915
+ const updateRoom = async (roomId, bundle) => {
43916
+ const client = getActiveClient();
43917
+ client.log('room/updateRoom', { roomId, bundle });
43918
+ const { data } = await client.http.put(`/api/v1/rooms/${roomId}`, bundle);
43919
+ fireEvent('local.room.updated', data);
43920
+ const cachedAt = client.cache && Date.now();
43921
+ if (client.cache)
43922
+ ingestInCache(data, { cachedAt });
43923
+ const { rooms } = data;
43924
+ return {
43925
+ data: rooms[0],
43926
+ cachedAt,
43927
+ };
43928
+ };
43929
+ /* end_public_function */
43930
+
43931
+ /* begin_public_function
43932
+ id: room.delete
43933
+ */
43934
+ /**
43935
+ * ```js
43936
+ * import { deleteRoom } from '@amityco/ts-sdk'
43937
+ * const result = await deleteRoom('roomId')
43938
+ * ```
43939
+ *
43940
+ * Deletes an {@link Amity.Room}
43941
+ *
43942
+ * @param roomId The ID of the room to delete
43943
+ * @returns Promise that resolves when the room is deleted
43944
+ *
43945
+ * @category Room API
43946
+ * @async
43947
+ */
43948
+ const deleteRoom = async (roomId) => {
43949
+ const client = getActiveClient();
43950
+ client.log('room/deleteRoom', { roomId });
43951
+ await client.http.delete(`/api/v1/rooms/${roomId}`);
43952
+ fireEvent('local.room.deleted', { rooms: [{ _id: roomId }] });
43953
+ };
43954
+ /* end_public_function */
43955
+
43956
+ /* begin_public_function
43957
+ id: room.stop
43958
+ */
43959
+ /**
43960
+ * ```js
43961
+ * import { stopRoom } from '@amityco/ts-sdk'
43962
+ * const result = await stopRoom('roomId')
43963
+ * ```
43964
+ *
43965
+ * Stops a room's broadcasting
43966
+ *
43967
+ * @param roomId The ID of the room to stop
43968
+ * @returns The updated room data
43969
+ *
43970
+ * @category Room API
43971
+ * @async
43972
+ */
43973
+ const stopRoom = async (roomId) => {
43974
+ const client = getActiveClient();
43975
+ client.log('room/stopRoom', { roomId });
43976
+ const { data } = await client.http.post(`/api/v1/rooms/${roomId}/stop`);
43977
+ fireEvent('local.room.stopped', data);
43978
+ const cachedAt = client.cache && Date.now();
43979
+ if (client.cache)
43980
+ ingestInCache(data, { cachedAt });
43981
+ const { rooms } = data;
43982
+ return {
43983
+ data: rooms[0],
43984
+ cachedAt,
43985
+ };
43986
+ };
43987
+ /* end_public_function */
43988
+
43989
+ /* begin_public_function
43990
+ id: room.getBroadcasterData
43991
+ */
43992
+ /**
43993
+ * ```js
43994
+ * import { getBroadcasterData } from '@amityco/ts-sdk'
43995
+ * const token = await getBroadcasterData('roomId')
43996
+ * ```
43997
+ *
43998
+ * Gets broadcaster data for a room
43999
+ *
44000
+ * @param roomId The ID of the room to get token for
44001
+ * @returns The broadcaster data of the room including coHostToken, coHostUrl and direactStreamUrl
44002
+ *
44003
+ * @category Room API
44004
+ * @async
44005
+ */
44006
+ const getBroadcasterData = async (roomId) => {
44007
+ const client = getActiveClient();
44008
+ client.log('room/getBroadcasterData', { roomId });
44009
+ const { data } = await client.http.get(`/api/v1/rooms/${roomId}/token`);
44010
+ return data;
44011
+ };
44012
+ /* end_public_function */
44013
+
44014
+ /* begin_public_function
44015
+ id: room.getRecordedUrl
44016
+ */
44017
+ /**
44018
+ * ```js
44019
+ * import { getRecordedUrl } from '@amityco/ts-sdk'
44020
+ * const recordedUrl = await getRecordedUrl('roomId')
44021
+ * ```
44022
+ *
44023
+ * Gets the recorded URL for a room
44024
+ *
44025
+ * @param roomId The ID of the room to get recorded URL for
44026
+ * @returns The recorded URL information
44027
+ *
44028
+ * @category Room API
44029
+ * @async
44030
+ */
44031
+ const getRecordedUrl = async (roomId) => {
44032
+ const client = getActiveClient();
44033
+ client.log('room/getRecordedUrl', { roomId });
44034
+ const { data } = await client.http.get(`/api/v1/rooms/${roomId}/recorded`);
44035
+ return data;
44036
+ };
44037
+ /* end_public_function */
44038
+
44039
+ /**
44040
+ * ```js
44041
+ * import { onRoomStartBroadcasting } from '@amityco/ts-sdk'
44042
+ * const dispose = onRoomStartBroadcasting(room => {
44043
+ * // ...
44044
+ * })
44045
+ * ```
44046
+ *
44047
+ * Fired when a {@link Amity.Room} has started broadcasting
44048
+ *
44049
+ * @param callback The function to call when the event was fired
44050
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44051
+ *
44052
+ * @category Room Events
44053
+ */
44054
+ const onRoomStartBroadcasting = (callback) => {
44055
+ const client = getActiveClient();
44056
+ const filter = (payload) => {
44057
+ ingestInCache(payload);
44058
+ callback(payload.rooms[0]);
44059
+ };
44060
+ return createEventSubscriber(client, 'room/onRoomStartBroadcasting', 'room.startBroadcasting', filter);
44061
+ };
44062
+
44063
+ /**
44064
+ * ```js
44065
+ * import { onRoomWaitingReconnect } from '@amityco/ts-sdk'
44066
+ * const dispose = onRoomWaitingReconnect(room => {
44067
+ * // ...
44068
+ * })
44069
+ * ```
44070
+ *
44071
+ * Fired when a {@link Amity.Room} is waiting for reconnection
44072
+ *
44073
+ * @param callback The function to call when the event was fired
44074
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44075
+ *
44076
+ * @category Room Events
44077
+ */
44078
+ const onRoomWaitingReconnect = (callback) => {
44079
+ const client = getActiveClient();
44080
+ const filter = (payload) => {
44081
+ ingestInCache(payload);
44082
+ callback(payload.rooms[0]);
44083
+ };
44084
+ return createEventSubscriber(client, 'room/onRoomWaitingReconnect', 'room.waitingReconnect', filter);
44085
+ };
44086
+
44087
+ /**
44088
+ * ```js
44089
+ * import { onRoomEndBroadcasting } from '@amityco/ts-sdk'
44090
+ * const dispose = onRoomEndBroadcasting(room => {
44091
+ * // ...
44092
+ * })
44093
+ * ```
44094
+ *
44095
+ * Fired when a {@link Amity.Room} has ended broadcasting
44096
+ *
44097
+ * @param callback The function to call when the event was fired
44098
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44099
+ *
44100
+ * @category Room Events
44101
+ */
44102
+ const onRoomEndBroadcasting = (callback) => {
44103
+ const client = getActiveClient();
44104
+ const filter = (payload) => {
44105
+ ingestInCache(payload);
44106
+ callback(payload.rooms[0]);
44107
+ };
44108
+ return createEventSubscriber(client, 'room/onRoomEndBroadcasting', 'room.endBroadcasting', filter);
44109
+ };
44110
+
44111
+ /**
44112
+ * ```js
44113
+ * import { onRoomRecordedAvailable } from '@amityco/ts-sdk'
44114
+ * const dispose = onRoomRecordedAvailable(room => {
44115
+ * // ...
44116
+ * })
44117
+ * ```
44118
+ *
44119
+ * Fired when a {@link Amity.Room} recorded content becomes available
44120
+ *
44121
+ * @param callback The function to call when the event was fired
44122
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44123
+ *
44124
+ * @category Room Events
44125
+ */
44126
+ const onRoomRecordedAvailable = (callback) => {
44127
+ const client = getActiveClient();
44128
+ const filter = (payload) => {
44129
+ ingestInCache(payload);
44130
+ callback(payload.rooms[0]);
44131
+ };
44132
+ return createEventSubscriber(client, 'room/onRoomRecordedAvailable', 'room.recordedAvailable', filter);
44133
+ };
44134
+
44135
+ /**
44136
+ * ```js
44137
+ * import { onRoomParticipantInviting } from '@amityco/ts-sdk'
44138
+ * const dispose = onRoomParticipantInviting(room => {
44139
+ * // ...
44140
+ * })
44141
+ * ```
44142
+ *
44143
+ * Fired when a participant is being invited to a {@link Amity.Room}
44144
+ *
44145
+ * @param callback The function to call when the event was fired
44146
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44147
+ *
44148
+ * @category Room Events
44149
+ */
44150
+ const onRoomParticipantInviting = (callback) => {
44151
+ const client = getActiveClient();
44152
+ const filter = (payload) => {
44153
+ ingestInCache(payload);
44154
+ callback(payload.rooms[0]);
44155
+ };
44156
+ return createEventSubscriber(client, 'room/onRoomParticipantInviting', 'room.participantInviting', filter);
44157
+ };
44158
+
44159
+ /**
44160
+ * ```js
44161
+ * import { onRoomParticipantJoined } from '@amityco/ts-sdk'
44162
+ * const dispose = onRoomParticipantJoined(room => {
44163
+ * // ...
44164
+ * })
44165
+ * ```
44166
+ *
44167
+ * Fired when a participant has joined a {@link Amity.Room}
44168
+ *
44169
+ * @param callback The function to call when the event was fired
44170
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44171
+ *
44172
+ * @category Room Events
44173
+ */
44174
+ const onRoomParticipantJoined = (callback) => {
44175
+ const client = getActiveClient();
44176
+ const filter = (payload) => {
44177
+ ingestInCache(payload);
44178
+ callback(payload.rooms[0]);
44179
+ };
44180
+ return createEventSubscriber(client, 'room/onRoomParticipantJoined', 'room.participantJoined', filter);
44181
+ };
44182
+
44183
+ /**
44184
+ * ```js
44185
+ * import { onRoomParticipantLeft } from '@amityco/ts-sdk'
44186
+ * const dispose = onRoomParticipantLeft(room => {
44187
+ * // ...
44188
+ * })
44189
+ * ```
44190
+ *
44191
+ * Fired when a participant has left a {@link Amity.Room}
44192
+ *
44193
+ * @param callback The function to call when the event was fired
44194
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44195
+ *
44196
+ * @category Room Events
44197
+ */
44198
+ const onRoomParticipantLeft = (callback) => {
44199
+ const client = getActiveClient();
44200
+ const filter = (payload) => {
44201
+ ingestInCache(payload);
44202
+ callback(payload.rooms[0]);
44203
+ };
44204
+ return createEventSubscriber(client, 'room/onRoomParticipantLeft', 'room.participantLeft', filter);
44205
+ };
44206
+
44207
+ /**
44208
+ * ```js
44209
+ * import { onRoomCreated } from '@amityco/ts-sdk'
44210
+ * const dispose = onRoomCreated(room => {
44211
+ * // ...
44212
+ * })
44213
+ * ```
44214
+ *
44215
+ * Fired when a {@link Amity.Room} has been created locally
44216
+ *
44217
+ * @param callback The function to call when the event was fired
44218
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44219
+ *
44220
+ * @category Room Events
44221
+ */
44222
+ const onRoomCreated = (callback) => {
44223
+ const client = getActiveClient();
44224
+ const filter = (payload) => {
44225
+ ingestInCache(payload);
44226
+ callback(payload.rooms[0]);
44227
+ };
44228
+ return createEventSubscriber(client, 'room/onRoomCreated', 'local.room.created', filter);
44229
+ };
44230
+
44231
+ /**
44232
+ * ```js
44233
+ * import { onRoomUpdated } from '@amityco/ts-sdk'
44234
+ * const dispose = onRoomUpdated(room => {
44235
+ * // ...
44236
+ * })
44237
+ * ```
44238
+ *
44239
+ * Fired when a {@link Amity.Room} has been updated locally
44240
+ *
44241
+ * @param callback The function to call when the event was fired
44242
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44243
+ *
44244
+ * @category Room Events
44245
+ */
44246
+ const onRoomUpdated = (callback) => {
44247
+ const client = getActiveClient();
44248
+ const filter = (payload) => {
44249
+ ingestInCache(payload);
44250
+ callback(payload.rooms[0]);
44251
+ };
44252
+ return createEventSubscriber(client, 'room/onRoomUpdated', 'local.room.updated', filter);
44253
+ };
44254
+
44255
+ /**
44256
+ * ```js
44257
+ * import { onRoomDeleted } from '@amityco/ts-sdk'
44258
+ * const dispose = onRoomDeleted(room => {
44259
+ * // ...
44260
+ * })
44261
+ * ```
44262
+ *
44263
+ * Fired when a {@link Amity.Room} has been deleted locally
44264
+ *
44265
+ * @param callback The function to call when the event was fired
44266
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44267
+ *
44268
+ * @category Room Events
44269
+ */
44270
+ const onRoomDeleted = (callback) => {
44271
+ const client = getActiveClient();
44272
+ const filter = (payload) => {
44273
+ ingestInCache(payload);
44274
+ callback(payload.rooms[0]);
44275
+ };
44276
+ return createEventSubscriber(client, 'room/onRoomDeleted', 'local.room.deleted', filter);
44277
+ };
44278
+
44279
+ /**
44280
+ * ```js
44281
+ * import { onRoomStopped } from '@amityco/ts-sdk'
44282
+ * const dispose = onRoomStopped(room => {
44283
+ * // ...
44284
+ * })
44285
+ * ```
44286
+ *
44287
+ * Fired when a {@link Amity.Room} has been stopped locally
44288
+ *
44289
+ * @param callback The function to call when the event was fired
44290
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44291
+ *
44292
+ * @category Room Events
44293
+ */
44294
+ const onRoomStopped = (callback) => {
44295
+ const client = getActiveClient();
44296
+ const filter = (payload) => {
44297
+ ingestInCache(payload);
44298
+ callback(payload.rooms[0]);
44299
+ };
44300
+ return createEventSubscriber(client, 'room/onRoomStopped', 'local.room.stopped', filter);
44301
+ };
44302
+
44303
+ const getRoomById = async (roomId) => {
44304
+ const client = getActiveClient();
44305
+ client.log('room/getRoomById', roomId);
44306
+ // Check if room is in tombstone
44307
+ isInTombstone('room', roomId);
44308
+ let data;
44309
+ try {
44310
+ const response = await client.http.get(`/api/v1/rooms/${roomId}`);
44311
+ data = response.data;
44312
+ }
44313
+ catch (error) {
44314
+ if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
44315
+ pushToTombstone('room', roomId);
44316
+ }
44317
+ throw error;
44318
+ }
44319
+ const cachedAt = client.cache && Date.now();
44320
+ if (client.cache) {
44321
+ ingestInCache(data, { cachedAt });
44322
+ }
44323
+ return {
44324
+ data: data.rooms[0],
44325
+ cachedAt,
44326
+ };
44327
+ };
44328
+ getRoomById.locally = (roomId) => {
44329
+ const client = getActiveClient();
44330
+ client.log('room/getRoomById.locally', roomId);
44331
+ // Check if room is in tombstone
44332
+ isInTombstone('room', roomId);
44333
+ const cachedAt = client.cache && Date.now();
44334
+ const roomCache = pullFromCache(['room', 'get', roomId]);
44335
+ if (!roomCache)
44336
+ return;
44337
+ return {
44338
+ data: roomCache.data,
44339
+ cachedAt,
44340
+ };
44341
+ };
44342
+
44343
+ const getRoom = (roomId, callback) => {
44344
+ // TODO: add callbackDataSelector if there are linked object fields
44345
+ return liveObject(roomId, callback, '_id', getRoomById, [
44346
+ onRoomEndBroadcasting,
44347
+ onRoomStartBroadcasting,
44348
+ onRoomWaitingReconnect,
44349
+ onRoomRecordedAvailable,
44350
+ ]);
44351
+ };
44352
+
44353
+ class RoomPaginationController extends PaginationController {
44354
+ async getRequest(queryParams, token) {
44355
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
44356
+ const baseOptions = {
44357
+ type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
44358
+ };
44359
+ const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
44360
+ const { data: queryResponse } = await this.http.get(`/api/v1/rooms`, {
44361
+ params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options }),
44362
+ });
44363
+ return queryResponse;
44364
+ }
44365
+ }
44366
+
44367
+ var EnumRoomActions;
44368
+ (function (EnumRoomActions) {
44369
+ EnumRoomActions["OnRoomCreated"] = "OnRoomCreated";
44370
+ EnumRoomActions["OnRoomUpdated"] = "OnRoomUpdated";
44371
+ EnumRoomActions["OnRoomDeleted"] = "OnRoomDeleted";
44372
+ EnumRoomActions["OnRoomStartBroadcasting"] = "OnRoomStartBroadcasting";
44373
+ EnumRoomActions["OnRoomEndBroadcasting"] = "OnRoomEndBroadcasting";
44374
+ EnumRoomActions["OnRoomParticipantJoined"] = "OnRoomParticipantJoined";
44375
+ EnumRoomActions["OnRoomParticipantLeft"] = "OnRoomParticipantLeft";
44376
+ })(EnumRoomActions || (EnumRoomActions = {}));
44377
+
44378
+ class RoomQueryStreamController extends QueryStreamController {
44379
+ constructor(query, cacheKey, notifyChange, preparePayload) {
44380
+ super(query, cacheKey);
44381
+ this.notifyChange = notifyChange;
44382
+ this.preparePayload = preparePayload;
44383
+ }
44384
+ async saveToMainDB(response) {
44385
+ const processedPayload = await this.preparePayload(response);
44386
+ const client = getActiveClient();
44387
+ const cachedAt = client.cache && Date.now();
44388
+ if (client.cache) {
44389
+ ingestInCache(processedPayload, { cachedAt });
44390
+ }
44391
+ }
44392
+ appendToQueryStream(response, direction, refresh = false) {
44393
+ var _a, _b;
44394
+ if (refresh) {
44395
+ pushToCache(this.cacheKey, {
44396
+ data: response.rooms.map(getResolver('room')),
44397
+ });
44398
+ }
44399
+ else {
44400
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
44401
+ const rooms = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
44402
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...rooms, ...response.rooms.map(getResolver('room'))])] }));
44403
+ }
44404
+ }
44405
+ reactor(action) {
44406
+ return (room) => {
44407
+ var _a;
44408
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
44409
+ if (!collection)
44410
+ return;
44411
+ if (action === EnumRoomActions.OnRoomDeleted) {
44412
+ collection.data = collection.data.filter(roomId => roomId !== room._id);
44413
+ }
44414
+ if (action === EnumRoomActions.OnRoomCreated) {
44415
+ collection.data = [...new Set([room._id, ...collection.data])];
44416
+ }
44417
+ pushToCache(this.cacheKey, collection);
44418
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
44419
+ };
44420
+ }
44421
+ subscribeRTE(createSubscriber) {
44422
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
44423
+ }
44424
+ }
44425
+
44426
+ // TODO: confirm related events
44427
+ const getRoomSubscription = () => [
44428
+ {
44429
+ fn: onRoomStartBroadcasting,
44430
+ action: EnumRoomActions.OnRoomStartBroadcasting,
44431
+ },
44432
+ {
44433
+ fn: onRoomEndBroadcasting,
44434
+ action: EnumRoomActions.OnRoomEndBroadcasting,
44435
+ },
44436
+ {
44437
+ fn: onRoomRecordedAvailable,
44438
+ action: EnumRoomActions.OnRoomUpdated,
44439
+ },
44440
+ ];
44441
+
44442
+ class RoomLiveCollectionController extends LiveCollectionController {
44443
+ constructor(query, callback) {
44444
+ const queryStreamId = hash(query);
44445
+ const cacheKey = ['rooms', 'collection', queryStreamId];
44446
+ const paginationController = new RoomPaginationController(query);
44447
+ super(paginationController, queryStreamId, cacheKey, callback);
44448
+ this.query = query;
44449
+ this.queryStreamController = new RoomQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), response => response);
44450
+ this.callback = callback.bind(this);
44451
+ this.loadPage({ initial: true });
44452
+ }
44453
+ setup() {
44454
+ var _a;
44455
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
44456
+ if (!collection) {
44457
+ pushToCache(this.cacheKey, {
44458
+ data: [],
44459
+ params: {},
44460
+ });
44461
+ }
44462
+ }
44463
+ async persistModel(queryPayload) {
44464
+ await this.queryStreamController.saveToMainDB(queryPayload);
44465
+ }
44466
+ persistQueryStream({ response, direction, refresh, }) {
44467
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
44468
+ }
44469
+ startSubscription() {
44470
+ return this.queryStreamController.subscribeRTE(getRoomSubscription());
44471
+ }
44472
+ notifyChange({ origin, loading, error }) {
44473
+ var _a, _b;
44474
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
44475
+ if (!collection)
44476
+ return;
44477
+ const data = this.applyFilter((_b = collection.data
44478
+ .map(id => pullFromCache(['room', 'get', id]))
44479
+ .filter(isNonNullable)
44480
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(room => room); // Since Room is same as InternalRoom, no transformation needed
44481
+ if (!this.shouldNotify(data) && origin === 'event')
44482
+ return;
44483
+ this.callback({
44484
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
44485
+ data,
44486
+ hasNextPage: !!this.paginationController.getNextToken(),
44487
+ loading,
44488
+ error,
44489
+ });
44490
+ }
44491
+ applyFilter(data) {
44492
+ let rooms = data;
44493
+ if (!this.query.includeDeleted) {
44494
+ rooms = filterByPropEquality(rooms, 'isDeleted', false);
44495
+ }
44496
+ if (this.query.statuses && this.query.statuses.length > 0) {
44497
+ rooms = rooms.filter(room => { var _a; return (_a = this.query.statuses) === null || _a === void 0 ? void 0 : _a.includes(room.status); });
44498
+ }
44499
+ if (this.query.type) {
44500
+ rooms = filterByPropEquality(rooms, 'type', this.query.type);
44501
+ }
44502
+ switch (this.query.sortBy) {
44503
+ case 'firstCreated':
44504
+ rooms = rooms.sort(sortByFirstCreated);
44505
+ break;
44506
+ case 'lastCreated':
44507
+ default:
44508
+ rooms = rooms.sort(sortByLastCreated);
44509
+ break;
44510
+ }
44511
+ return rooms;
44512
+ }
44513
+ }
44514
+
44515
+ /* begin_public_function
44516
+ id: room.get_rooms
44517
+ */
44518
+ /**
44519
+ * ```js
44520
+ * import { RoomRepository } from '@amityco/ts-sdk'
44521
+ *
44522
+ * let rooms = []
44523
+ * const unsub = RoomRepository.getRooms({
44524
+ * type: 'direct_streaming',
44525
+ * statuses: ['live', 'idle'],
44526
+ * sortBy: 'lastCreated',
44527
+ * limit: 20,
44528
+ * includeDeleted: false
44529
+ * }, response => merge(rooms, response.data))
44530
+ * ```
44531
+ *
44532
+ * Observe all mutations on a list of {@link Amity.Room} for a given query
44533
+ *
44534
+ * @param params.type the type of rooms to filter by ('direct_streaming' | 'co_hosts')
44535
+ * @param params.statuses array of room statuses to filter by (['idle', 'live', 'waiting_reconnect', 'ended', 'recorded'])
44536
+ * @param params.sortBy sort rooms by creation time ('firstCreated' | 'lastCreated')
44537
+ * @param params.limit maximum number of rooms to retrieve per page
44538
+ * @param params.includeDeleted whether to include deleted rooms in the results
44539
+ * @param callback the function to call when new data are available
44540
+ * @param config optional configuration for the live collection
44541
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the rooms
44542
+ *
44543
+ * @category Rooms Live Collection
44544
+ */
44545
+ const getRooms = (params, callback, config) => {
44546
+ const { log, cache } = getActiveClient();
44547
+ if (!cache) {
44548
+ console.log(ENABLE_CACHE_MESSAGE);
44549
+ }
44550
+ const timestamp = Date.now();
44551
+ log(`getRooms(tmpid: ${timestamp}) > listen`);
44552
+ const roomsLiveCollection = new RoomLiveCollectionController(params, callback);
44553
+ const disposers = roomsLiveCollection.startSubscription();
44554
+ const cacheKey = roomsLiveCollection.getCacheKey();
44555
+ disposers.push(() => dropFromCache(cacheKey));
44556
+ return () => {
44557
+ log(`getRooms(tmpid: ${timestamp}) > dispose`);
44558
+ disposers.forEach(fn => fn());
44559
+ };
44560
+ };
44561
+ /* end_public_function */
44562
+
44563
+ var index$7 = /*#__PURE__*/Object.freeze({
44564
+ __proto__: null,
44565
+ createRoom: createRoom,
44566
+ updateRoom: updateRoom,
44567
+ deleteRoom: deleteRoom,
44568
+ stopRoom: stopRoom,
44569
+ getBroadcasterData: getBroadcasterData,
44570
+ getRecordedUrl: getRecordedUrl,
44571
+ onRoomStartBroadcasting: onRoomStartBroadcasting,
44572
+ onRoomWaitingReconnect: onRoomWaitingReconnect,
44573
+ onRoomEndBroadcasting: onRoomEndBroadcasting,
44574
+ onRoomRecordedAvailable: onRoomRecordedAvailable,
44575
+ onRoomParticipantInviting: onRoomParticipantInviting,
44576
+ onRoomParticipantJoined: onRoomParticipantJoined,
44577
+ onRoomParticipantLeft: onRoomParticipantLeft,
44578
+ onRoomCreated: onRoomCreated,
44579
+ onRoomUpdated: onRoomUpdated,
44580
+ onRoomDeleted: onRoomDeleted,
44581
+ onRoomStopped: onRoomStopped,
44582
+ getRoom: getRoom,
44583
+ getRooms: getRooms
44584
+ });
44585
+
43812
44586
  /* begin_public_function
43813
44587
  id: poll.create
43814
44588
  */
@@ -44109,7 +44883,7 @@ const getPoll = (pollId, callback) => {
44109
44883
  };
44110
44884
  /* end_public_function */
44111
44885
 
44112
- var index$7 = /*#__PURE__*/Object.freeze({
44886
+ var index$6 = /*#__PURE__*/Object.freeze({
44113
44887
  __proto__: null,
44114
44888
  createPoll: createPoll,
44115
44889
  closePoll: closePoll,
@@ -44492,7 +45266,7 @@ const getPlayer = async (parameters) => {
44492
45266
  return video;
44493
45267
  };
44494
45268
 
44495
- var index$6 = /*#__PURE__*/Object.freeze({
45269
+ var index$5 = /*#__PURE__*/Object.freeze({
44496
45270
  __proto__: null,
44497
45271
  getPlayer: getPlayer
44498
45272
  });
@@ -45665,7 +46439,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
45665
46439
  };
45666
46440
  };
45667
46441
 
45668
- var index$5 = /*#__PURE__*/Object.freeze({
46442
+ var index$4 = /*#__PURE__*/Object.freeze({
45669
46443
  __proto__: null,
45670
46444
  createImageStory: createImageStory,
45671
46445
  createVideoStory: createVideoStory,
@@ -45702,7 +46476,7 @@ const getNetworkAds = async () => {
45702
46476
  };
45703
46477
  };
45704
46478
 
45705
- var index$4 = /*#__PURE__*/Object.freeze({
46479
+ var index$3 = /*#__PURE__*/Object.freeze({
45706
46480
  __proto__: null,
45707
46481
  getNetworkAds: getNetworkAds
45708
46482
  });
@@ -46093,7 +46867,7 @@ const markTraySeen = async (lastSeenAt) => {
46093
46867
  };
46094
46868
  /* end_public_function */
46095
46869
 
46096
- var index$3 = /*#__PURE__*/Object.freeze({
46870
+ var index$2 = /*#__PURE__*/Object.freeze({
46097
46871
  __proto__: null,
46098
46872
  getNotificationTraySeen: getNotificationTraySeen,
46099
46873
  getNotificationTrayItems: getNotificationTrayItems,
@@ -46294,7 +47068,7 @@ const getMyCommunityInvitations = (params, callback, config) => {
46294
47068
  };
46295
47069
  };
46296
47070
 
46297
- var index$2 = /*#__PURE__*/Object.freeze({
47071
+ var index$1 = /*#__PURE__*/Object.freeze({
46298
47072
  __proto__: null,
46299
47073
  onLocalInvitationCreated: onLocalInvitationCreated,
46300
47074
  onLocalInvitationUpdated: onLocalInvitationUpdated,
@@ -46435,559 +47209,11 @@ const getReactions = (postId, callback) => {
46435
47209
  };
46436
47210
  };
46437
47211
 
46438
- var index$1 = /*#__PURE__*/Object.freeze({
47212
+ var index = /*#__PURE__*/Object.freeze({
46439
47213
  __proto__: null,
46440
47214
  createReaction: createReaction,
46441
47215
  onLiveReactionCreated: onLiveReactionCreated,
46442
47216
  getReactions: getReactions
46443
47217
  });
46444
47218
 
46445
- const prepareEventPayload = (rawPayload) => {
46446
- return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser) });
46447
- };
46448
-
46449
- const createEventEventSubscriber = (event, callback) => {
46450
- const client = getActiveClient();
46451
- const filter = (payload) => {
46452
- const unpackedPayload = prepareEventPayload(payload);
46453
- if (!client.cache) {
46454
- callback(unpackedPayload.events[0]);
46455
- }
46456
- else {
46457
- ingestInCache(unpackedPayload);
46458
- const event = pullFromCache([
46459
- 'event',
46460
- 'get',
46461
- unpackedPayload.events[0].eventId,
46462
- ]);
46463
- callback(event.data);
46464
- }
46465
- };
46466
- return createEventSubscriber(client, event, event, filter);
46467
- };
46468
-
46469
- /* begin_public_function
46470
- id: event.create
46471
- */
46472
- /**
46473
- * ```js
46474
- * import { EventRepository } from '@amityco/ts-sdk'
46475
- * const response = await EventRepository.createEvent(bundle)
46476
- * ```
46477
- *
46478
- * Creates an {@link Amity.Event}
46479
- *
46480
- * @param bundle The data necessary to create a new {@link Amity.Event}
46481
- * @returns The newly created {@link Amity.Event}
46482
- *
46483
- * @category Event API
46484
- * @async
46485
- */
46486
- const createEvent = async (bundle) => {
46487
- const client = getActiveClient();
46488
- client.log('event/createEvent', bundle);
46489
- const { data: payload } = await client.http.post('/api/v1/events', bundle);
46490
- fireEvent('event.created', payload);
46491
- const preparedPayload = prepareEventPayload(payload);
46492
- const cachedAt = client.cache && Date.now();
46493
- if (client.cache)
46494
- ingestInCache(preparedPayload, { cachedAt });
46495
- return {
46496
- data: eventLinkedObject(preparedPayload.events[0]),
46497
- cachedAt,
46498
- };
46499
- };
46500
- /* end_public_function */
46501
-
46502
- /* begin_public_function
46503
- id: event.update
46504
- */
46505
- /**
46506
- * ```js
46507
- * import { EventRepository } from '@amityco/ts-sdk'
46508
- * const response = await EventRepository.updateEvent(eventId, bundle)
46509
- * ```
46510
- *
46511
- * Updates an {@link Amity.Event}
46512
- *
46513
- * @param eventId The ID of the {@link Amity.Event} to edit
46514
- * @param bundle The data necessary to update an existing {@link Amity.Event}
46515
- * @returns the updated {@link Amity.Event}
46516
- *
46517
- * @category Event API
46518
- * @async
46519
- */
46520
- const updateEvent = async (eventId, bundle) => {
46521
- const client = getActiveClient();
46522
- client.log('event/updateEvent', eventId, bundle);
46523
- const { data: payload } = await client.http.put(`/api/v1/events/${eventId}`, bundle);
46524
- fireEvent('event.updated', payload);
46525
- const preparedPayload = prepareEventPayload(payload);
46526
- const cachedAt = client.cache && Date.now();
46527
- if (client.cache)
46528
- ingestInCache(preparedPayload, { cachedAt });
46529
- return {
46530
- data: eventLinkedObject(preparedPayload.events.find(event => event.eventId === eventId)),
46531
- cachedAt,
46532
- };
46533
- };
46534
- /* end_public_function */
46535
-
46536
- /* begin_public_function
46537
- id: event.get
46538
- */
46539
- /**
46540
- * ```js
46541
- * import { EventRepository } from '@amityco/ts-sdk'
46542
- * const event = await EventRepository.getEvent(eventId)
46543
- * ```
46544
- *
46545
- * Fetches a {@link Amity.Event} object
46546
- *
46547
- * @param eventId the ID of the {@link Amity.Event} to fetch
46548
- * @returns the associated {@link Amity.Event} object
46549
- *
46550
- * @category Event API
46551
- * @async
46552
- */
46553
- const getEvent$1 = async (eventId) => {
46554
- const client = getActiveClient();
46555
- client.log('event/getEvent', eventId);
46556
- const { data: payload } = await client.http.get(`/api/v3/events/${eventId}`);
46557
- const data = prepareEventPayload(payload);
46558
- const cachedAt = client.cache && Date.now();
46559
- if (client.cache)
46560
- ingestInCache(data, { cachedAt });
46561
- return {
46562
- data: data.events.find(event => event.eventId === eventId),
46563
- cachedAt,
46564
- };
46565
- };
46566
- /* end_public_function */
46567
- /**
46568
- * ```js
46569
- * import { EventRepository } from '@amityco/ts-sdk'
46570
- * const event = EventRepository.getEvent.locally(eventId)
46571
- * ```
46572
- *
46573
- * Fetches a {@link Amity.Event} object in cache
46574
- *
46575
- * @param eventId the ID of the {@link Amity.Event} to fetch
46576
- * @returns the associated {@link Amity.Event} object
46577
- *
46578
- * @category Event API
46579
- */
46580
- getEvent$1.locally = (eventId) => {
46581
- const client = getActiveClient();
46582
- client.log('event/getEvent.locally', eventId);
46583
- if (!client.cache)
46584
- return;
46585
- const cache = pullFromCache(['event', 'get', eventId]);
46586
- if (!cache)
46587
- return;
46588
- return {
46589
- data: cache.data,
46590
- cachedAt: cache.cachedAt,
46591
- };
46592
- };
46593
-
46594
- /* begin_public_function
46595
- id: event.delete
46596
- */
46597
- /**
46598
- * ```js
46599
- * import { EventRepository } from '@amityco/ts-sdk'
46600
- * const { success } = await EventRepository.deleteEvent(eventId)
46601
- * ```
46602
- *
46603
- * Deletes a {@link Amity.Event}
46604
- *
46605
- * @param eventId The {@link Amity.Event} ID to delete
46606
- *
46607
- * @category Event API
46608
- * @async
46609
- */
46610
- const deleteEvent = async (eventId) => {
46611
- const client = getActiveClient();
46612
- client.log('event/deleteEvent', eventId);
46613
- const event = await getEvent$1(eventId);
46614
- await client.http.delete(`/api/v3/events/${eventId}`);
46615
- const deletedEvent = Object.assign(Object.assign({}, event.data), { isDeleted: true });
46616
- upsertInCache(['event', 'get', eventId], deletedEvent);
46617
- fireEvent('event.deleted', {
46618
- users: [],
46619
- files: [],
46620
- communities: [],
46621
- videoStreamings: [],
46622
- events: [deletedEvent],
46623
- discussionCommunities: [],
46624
- });
46625
- };
46626
- /* end_public_function */
46627
-
46628
- /**
46629
- * ```js
46630
- * import { EventRepository } from '@amityco/ts-sdk'
46631
- * const dispose = EventRepository.onEventCreated(event => {
46632
- * // ...
46633
- * })
46634
- * ```
46635
- *
46636
- * Fired when a {@link Amity.Event} has been created
46637
- *
46638
- * @param callback The function to call when the event was fired
46639
- * @returns an {@link Amity.Unsubscriber} function to stop listening
46640
- *
46641
- * @category Event Events
46642
- */
46643
- const onEventCreated = (callback) => createEventEventSubscriber('event.created', callback);
46644
-
46645
- /**
46646
- * ```js
46647
- * import { EventRepository } from '@amityco/ts-sdk'
46648
- * const dispose = EventRepository.onEventUpdated(event => {
46649
- * // ...
46650
- * })
46651
- * ```
46652
- *
46653
- * Fired when a {@link Amity.Event} has been updated
46654
- *
46655
- * @param callback The function to call when the event was fired
46656
- * @returns an {@link Amity.Unsubscriber} function to stop listening
46657
- *
46658
- * @category Event Events
46659
- */
46660
- const onEventUpdated = (callback) => createEventEventSubscriber('event.updated', callback);
46661
-
46662
- /**
46663
- * ```js
46664
- * import { EventRepository } from '@amityco/ts-sdk'
46665
- * const dispose = EventRepository.onEventDeleted(event => {
46666
- * // ...
46667
- * })
46668
- * ```
46669
- *
46670
- * Fired when a {@link Amity.Event} has been deleted
46671
- *
46672
- * @param callback The function to call when the event was fired
46673
- * @returns an {@link Amity.Unsubscriber} function to stop listening
46674
- *
46675
- * @category Event Events
46676
- */
46677
- const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted', callback);
46678
-
46679
- /* begin_public_function
46680
- id: event.get
46681
- */
46682
- /**
46683
- * ```js
46684
- * import { EventRepository } from '@amityco/ts-sdk';
46685
- *
46686
- * let event;
46687
- *
46688
- * const unsubscribe = EventRepository.getEvent(eventId, response => {
46689
- * event = response.data;
46690
- * });
46691
- * ```
46692
- *
46693
- * Observe all mutation on a given {@link Amity.Event}
46694
- *
46695
- * @param eventId the ID of the event to observe
46696
- * @param callback the function to call when new snapshot of event are available
46697
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the event
46698
- *
46699
- * @category Event Live Object
46700
- */
46701
- const getEvent = (eventId, callback) => {
46702
- return liveObject(eventId, callback, 'eventId', getEvent$1, [onEventCreated, onEventUpdated, onEventDeleted], {
46703
- callbackDataSelector: (data) => (data ? eventLinkedObject(data) : data),
46704
- });
46705
- };
46706
- /* end_public_function */
46707
-
46708
- var EventActionsEnum;
46709
- (function (EventActionsEnum) {
46710
- EventActionsEnum["OnEventCreated"] = "onEventCreated";
46711
- EventActionsEnum["OnEventUpdated"] = "onEventUpdated";
46712
- EventActionsEnum["OnEventDeleted"] = "onEventDeleted";
46713
- })(EventActionsEnum || (EventActionsEnum = {}));
46714
-
46715
- class EventPaginationController extends PaginationController {
46716
- async getRequest(queryParams, token) {
46717
- const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
46718
- const options = token ? { token } : { limit };
46719
- const { data: response } = await this.http.get(`/api/v1/events`, { params: Object.assign(Object.assign({}, params), { options }) });
46720
- return response;
46721
- }
46722
- }
46723
-
46724
- class EventQueryStreamController extends QueryStreamController {
46725
- constructor(query, cacheKey, notifyChange, preparePayload) {
46726
- super(query, cacheKey);
46727
- this.notifyChange = notifyChange;
46728
- this.preparePayload = preparePayload;
46729
- }
46730
- async saveToMainDB(response) {
46731
- const processedPayload = this.preparePayload(response);
46732
- const client = getActiveClient();
46733
- const cachedAt = client.cache && Date.now();
46734
- if (client.cache)
46735
- ingestInCache(processedPayload, { cachedAt });
46736
- }
46737
- appendToQueryStream(response, direction, refresh = false) {
46738
- var _a, _b;
46739
- if (refresh) {
46740
- pushToCache(this.cacheKey, { data: response.events.map(getResolver('event')) });
46741
- }
46742
- else {
46743
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
46744
- const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
46745
- pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...events, ...response.events.map(getResolver('event'))])] }));
46746
- }
46747
- }
46748
- reactor(action) {
46749
- return (event) => {
46750
- var _a;
46751
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
46752
- if (!collection)
46753
- return;
46754
- if (action === EventActionsEnum.OnEventCreated) {
46755
- collection.data = [...new Set([event.eventId, ...collection.data])];
46756
- }
46757
- if (action === EventActionsEnum.OnEventDeleted) {
46758
- collection.data = collection.data.filter(eventId => eventId !== event.eventId);
46759
- }
46760
- pushToCache(this.cacheKey, collection);
46761
- this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
46762
- };
46763
- }
46764
- subscribeRTE(createSubscriber) {
46765
- return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
46766
- }
46767
- }
46768
-
46769
- class EventLiveCollectionController extends LiveCollectionController {
46770
- constructor(query, callback) {
46771
- const queryStreamId = hash(query);
46772
- const cacheKey = ['event', 'collection', queryStreamId];
46773
- const paginationController = new EventPaginationController(query);
46774
- super(paginationController, queryStreamId, cacheKey, callback);
46775
- this.query = query;
46776
- this.queryStreamController = new EventQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventPayload);
46777
- this.callback = callback.bind(this);
46778
- this.loadPage({ initial: true });
46779
- }
46780
- setup() {
46781
- var _a;
46782
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
46783
- if (!collection)
46784
- pushToCache(this.cacheKey, { data: [], params: {} });
46785
- }
46786
- async persistModel(queryPayload) {
46787
- await this.queryStreamController.saveToMainDB(queryPayload);
46788
- }
46789
- persistQueryStream({ response, direction, refresh, }) {
46790
- this.queryStreamController.appendToQueryStream(response, direction, refresh);
46791
- }
46792
- startSubscription() {
46793
- return this.queryStreamController.subscribeRTE([
46794
- { fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
46795
- { fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
46796
- { fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
46797
- ]);
46798
- }
46799
- notifyChange({ origin, loading, error }) {
46800
- var _a, _b;
46801
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
46802
- if (!collection)
46803
- return;
46804
- const data = ((_b = collection.data
46805
- .map(eventId => pullFromCache(['event', 'get', eventId]))
46806
- .filter(isNonNullable)
46807
- .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
46808
- if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
46809
- return;
46810
- this.callback({
46811
- data,
46812
- error,
46813
- loading,
46814
- hasNextPage: !!this.paginationController.getNextToken(),
46815
- onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
46816
- });
46817
- }
46818
- }
46819
-
46820
- /**
46821
- * Get events
46822
- *
46823
- * @param params the query parameters
46824
- * @param callback the callback to be called when the events are updated
46825
- * @returns events
46826
- *
46827
- * @category Event Live Collection
46828
- *
46829
- */
46830
- const getEvents = (params, callback, config) => {
46831
- const { log, cache } = getActiveClient();
46832
- if (!cache)
46833
- console.log(ENABLE_CACHE_MESSAGE);
46834
- const timestamp = Date.now();
46835
- log(`getEvents: (tmpid: ${timestamp}) > listen`);
46836
- const eventLiveCollection = new EventLiveCollectionController(params, callback);
46837
- const disposers = eventLiveCollection.startSubscription();
46838
- const cacheKey = eventLiveCollection.getCacheKey();
46839
- disposers.push(() => dropFromCache(cacheKey));
46840
- return () => {
46841
- log(`getEvents (tmpid: ${timestamp}) > dispose`);
46842
- disposers.forEach(fn => fn());
46843
- };
46844
- };
46845
-
46846
- class MyEventPaginationController extends PaginationController {
46847
- async getRequest(queryParams, token) {
46848
- const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
46849
- const options = token ? { token } : { limit };
46850
- const { data: response } = await this.http.get(`/api/v1/events/me/rsvps`, { params: Object.assign(Object.assign({}, params), { options }) });
46851
- return response;
46852
- }
46853
- }
46854
-
46855
- class MyEventQueryStreamController extends QueryStreamController {
46856
- constructor(query, cacheKey, notifyChange, preparePayload) {
46857
- super(query, cacheKey);
46858
- this.notifyChange = notifyChange;
46859
- this.preparePayload = preparePayload;
46860
- }
46861
- async saveToMainDB(response) {
46862
- const processedPayload = this.preparePayload(response);
46863
- const client = getActiveClient();
46864
- const cachedAt = client.cache && Date.now();
46865
- if (client.cache)
46866
- ingestInCache(processedPayload, { cachedAt });
46867
- }
46868
- appendToQueryStream(response, direction, refresh = false) {
46869
- var _a, _b;
46870
- if (refresh) {
46871
- pushToCache(this.cacheKey, { data: response.events.map(getResolver('event')) });
46872
- }
46873
- else {
46874
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
46875
- const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
46876
- pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...events, ...response.events.map(getResolver('event'))])] }));
46877
- }
46878
- }
46879
- reactor(action) {
46880
- return (event) => {
46881
- var _a;
46882
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
46883
- if (!collection)
46884
- return;
46885
- if (action === EventActionsEnum.OnEventCreated) {
46886
- const client = getActiveClient();
46887
- if (client.userId !== event.userId)
46888
- return;
46889
- collection.data = [...new Set([event.eventId, ...collection.data])];
46890
- }
46891
- if (action === EventActionsEnum.OnEventDeleted) {
46892
- collection.data = collection.data.filter(eventId => eventId !== event.eventId);
46893
- }
46894
- pushToCache(this.cacheKey, collection);
46895
- this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
46896
- };
46897
- }
46898
- subscribeRTE(createSubscriber) {
46899
- return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
46900
- }
46901
- }
46902
-
46903
- class MyEventLiveCollectionController extends LiveCollectionController {
46904
- constructor(query, callback) {
46905
- const queryStreamId = hash(query);
46906
- const cacheKey = ['event', 'collection', queryStreamId];
46907
- const paginationController = new MyEventPaginationController(query);
46908
- super(paginationController, queryStreamId, cacheKey, callback);
46909
- this.query = query;
46910
- this.queryStreamController = new MyEventQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventPayload);
46911
- this.callback = callback.bind(this);
46912
- this.loadPage({ initial: true });
46913
- }
46914
- setup() {
46915
- var _a;
46916
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
46917
- if (!collection)
46918
- pushToCache(this.cacheKey, { data: [], params: {} });
46919
- }
46920
- async persistModel(queryPayload) {
46921
- await this.queryStreamController.saveToMainDB(queryPayload);
46922
- }
46923
- persistQueryStream({ response, direction, refresh, }) {
46924
- this.queryStreamController.appendToQueryStream(response, direction, refresh);
46925
- }
46926
- startSubscription() {
46927
- return this.queryStreamController.subscribeRTE([
46928
- { fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
46929
- { fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
46930
- { fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
46931
- ]);
46932
- }
46933
- notifyChange({ origin, loading, error }) {
46934
- var _a, _b;
46935
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
46936
- if (!collection)
46937
- return;
46938
- const data = ((_b = collection.data
46939
- .map(eventId => pullFromCache(['event', 'get', eventId]))
46940
- .filter(isNonNullable)
46941
- .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
46942
- if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
46943
- return;
46944
- this.callback({
46945
- data,
46946
- error,
46947
- loading,
46948
- hasNextPage: !!this.paginationController.getNextToken(),
46949
- onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
46950
- });
46951
- }
46952
- }
46953
-
46954
- /**
46955
- * Get my events
46956
- *
46957
- * @param params the query parameters
46958
- * @param callback the callback to be called when the events are updated
46959
- * @returns events
46960
- *
46961
- * @category Event Live Collection
46962
- *
46963
- */
46964
- const getMyEvents = (params, callback, config) => {
46965
- const { log, cache } = getActiveClient();
46966
- if (!cache)
46967
- console.log(ENABLE_CACHE_MESSAGE);
46968
- const timestamp = Date.now();
46969
- log(`getMyEvents: (tmpid: ${timestamp}) > listen`);
46970
- const myEventLiveCollection = new MyEventLiveCollectionController(params, callback);
46971
- const disposers = myEventLiveCollection.startSubscription();
46972
- const cacheKey = myEventLiveCollection.getCacheKey();
46973
- disposers.push(() => dropFromCache(cacheKey));
46974
- return () => {
46975
- log(`getMyEvents (tmpid: ${timestamp}) > dispose`);
46976
- disposers.forEach(fn => fn());
46977
- };
46978
- };
46979
-
46980
- var index = /*#__PURE__*/Object.freeze({
46981
- __proto__: null,
46982
- createEvent: createEvent,
46983
- updateEvent: updateEvent,
46984
- deleteEvent: deleteEvent,
46985
- onEventCreated: onEventCreated,
46986
- onEventUpdated: onEventUpdated,
46987
- onEventDeleted: onEventDeleted,
46988
- getEvent: getEvent,
46989
- getEvents: getEvents,
46990
- getMyEvents: getMyEvents
46991
- });
46992
-
46993
- export { API_REGIONS, index$4 as AdRepository, AmityEventOriginType, AmityEventResponseStatus, AmityEventStatus, AmityEventType, index$c as CategoryRepository, index$g as ChannelRepository, index$p as Client, index$b as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$d as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, index as EventRepository, FeedDataTypeEnum, index$a as FeedRepository, FeedSortByEnum, FeedSourceEnum, FileAccessTypeEnum, index$m as FileRepository, FileType, GET_WATCHER_URLS, index$2 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index$1 as LiveReactionRepository, index$6 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$k as MessageRepository, index$7 as PollRepository, PostContentType, index$9 as PostRepository, PostStructureType, index$l as ReactionRepository, index$5 as StoryRepository, index$8 as StreamRepository, index$j as SubChannelRepository, SubscriptionLevels, index$n as UserRepository, UserTypeEnum, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveReactionTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$3 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, wipeCache };
47219
+ export { API_REGIONS, index$3 as AdRepository, index$c as CategoryRepository, index$g as ChannelRepository, index$p as Client, index$b as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$d as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, FeedDataTypeEnum, index$a as FeedRepository, FeedSortByEnum, FeedSourceEnum, FileAccessTypeEnum, index$m as FileRepository, FileType, GET_WATCHER_URLS, index$1 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index as LiveReactionRepository, index$5 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$k as MessageRepository, index$6 as PollRepository, PostContentType, index$9 as PostRepository, PostStructureType, index$l as ReactionRepository, index$7 as RoomRepository, index$4 as StoryRepository, index$8 as StreamRepository, index$j as SubChannelRepository, SubscriptionLevels, index$n as UserRepository, UserTypeEnum, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, 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$2 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, wipeCache };