@amityco/ts-sdk 7.11.1-8ef0bbb7.0 → 7.11.1-9eba2589.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 (241) hide show
  1. package/dist/@types/core/events.d.ts +51 -10
  2. package/dist/@types/core/events.d.ts.map +1 -1
  3. package/dist/@types/core/model.d.ts +6 -0
  4. package/dist/@types/core/model.d.ts.map +1 -1
  5. package/dist/@types/core/payload.d.ts +33 -0
  6. package/dist/@types/core/payload.d.ts.map +1 -1
  7. package/dist/@types/core/permissions.d.ts +5 -1
  8. package/dist/@types/core/permissions.d.ts.map +1 -1
  9. package/dist/@types/core/transport.d.ts +3 -0
  10. package/dist/@types/core/transport.d.ts.map +1 -1
  11. package/dist/@types/domains/channel.d.ts +1 -0
  12. package/dist/@types/domains/channel.d.ts.map +1 -1
  13. package/dist/@types/domains/community.d.ts +11 -1
  14. package/dist/@types/domains/community.d.ts.map +1 -1
  15. package/dist/@types/domains/event.d.ts +81 -0
  16. package/dist/@types/domains/event.d.ts.map +1 -0
  17. package/dist/@types/domains/feed.d.ts +2 -1
  18. package/dist/@types/domains/feed.d.ts.map +1 -1
  19. package/dist/@types/domains/invitation.d.ts +7 -2
  20. package/dist/@types/domains/invitation.d.ts.map +1 -1
  21. package/dist/@types/domains/partials.d.ts +2 -2
  22. package/dist/@types/domains/partials.d.ts.map +1 -1
  23. package/dist/@types/domains/room.d.ts +30 -6
  24. package/dist/@types/domains/room.d.ts.map +1 -1
  25. package/dist/@types/index.d.ts +1 -0
  26. package/dist/@types/index.d.ts.map +1 -1
  27. package/dist/channelRepository/api/createChannel.d.ts +1 -0
  28. package/dist/channelRepository/api/createChannel.d.ts.map +1 -1
  29. package/dist/client/api/getPresenceSetting.d.ts +2 -0
  30. package/dist/client/api/getPresenceSetting.d.ts.map +1 -0
  31. package/dist/client/api/resumeSession.d.ts.map +1 -1
  32. package/dist/client/services/ObjectResolver/objectResolverEngine.d.ts.map +1 -0
  33. package/dist/client/services/ObjectResolver/objectResolverEngineOnLoginHandler.d.ts.map +1 -0
  34. package/dist/client/services/ReadReceiptSync/legacyReadReceiptSyncEngine.d.ts.map +1 -0
  35. package/dist/client/services/ReadReceiptSync/legacyReadReceiptSyncEngineOnLoginHandler.d.ts.map +1 -0
  36. package/dist/client/services/ReadReceiptSync/readReceiptSyncEngine.d.ts.map +1 -0
  37. package/dist/client/services/ReadReceiptSync/readReceiptSyncEngineOnLoginHandler.d.ts.map +1 -0
  38. package/dist/core/events.d.ts +3 -3
  39. package/dist/core/events.d.ts.map +1 -1
  40. package/dist/core/model/idResolvers.d.ts.map +1 -1
  41. package/dist/core/model/index.d.ts.map +1 -1
  42. package/dist/core/subscription.d.ts +2 -0
  43. package/dist/core/subscription.d.ts.map +1 -1
  44. package/dist/eventRepository/api/createEvent.d.ts +16 -0
  45. package/dist/eventRepository/api/createEvent.d.ts.map +1 -0
  46. package/dist/eventRepository/api/deleteEvent.d.ts +15 -0
  47. package/dist/eventRepository/api/deleteEvent.d.ts.map +1 -0
  48. package/dist/eventRepository/api/index.d.ts +4 -0
  49. package/dist/eventRepository/api/index.d.ts.map +1 -0
  50. package/dist/eventRepository/api/updateEvent.d.ts +17 -0
  51. package/dist/eventRepository/api/updateEvent.d.ts.map +1 -0
  52. package/dist/eventRepository/events/enums.d.ts +6 -0
  53. package/dist/eventRepository/events/enums.d.ts.map +1 -0
  54. package/dist/eventRepository/events/index.d.ts +7 -0
  55. package/dist/eventRepository/events/index.d.ts.map +1 -0
  56. package/dist/eventRepository/events/onEventCreated.d.ts +17 -0
  57. package/dist/eventRepository/events/onEventCreated.d.ts.map +1 -0
  58. package/dist/eventRepository/events/onEventDeleted.d.ts +17 -0
  59. package/dist/eventRepository/events/onEventDeleted.d.ts.map +1 -0
  60. package/dist/eventRepository/events/onEventUpdated.d.ts +17 -0
  61. package/dist/eventRepository/events/onEventUpdated.d.ts.map +1 -0
  62. package/dist/eventRepository/events/onLocalEventCreated.d.ts +17 -0
  63. package/dist/eventRepository/events/onLocalEventCreated.d.ts.map +1 -0
  64. package/dist/eventRepository/events/onLocalEventDeleted.d.ts +17 -0
  65. package/dist/eventRepository/events/onLocalEventDeleted.d.ts.map +1 -0
  66. package/dist/eventRepository/events/onLocalEventUpdated.d.ts +17 -0
  67. package/dist/eventRepository/events/onLocalEventUpdated.d.ts.map +1 -0
  68. package/dist/eventRepository/index.d.ts +4 -0
  69. package/dist/eventRepository/index.d.ts.map +1 -0
  70. package/dist/eventRepository/internalApi/getEvent.d.ts +32 -0
  71. package/dist/eventRepository/internalApi/getEvent.d.ts.map +1 -0
  72. package/dist/eventRepository/internalApi/index.d.ts +2 -0
  73. package/dist/eventRepository/internalApi/index.d.ts.map +1 -0
  74. package/dist/eventRepository/observers/getEvent.d.ts +21 -0
  75. package/dist/eventRepository/observers/getEvent.d.ts.map +1 -0
  76. package/dist/eventRepository/observers/getEvents/LiveCollectionController.d.ts +13 -0
  77. package/dist/eventRepository/observers/getEvents/LiveCollectionController.d.ts.map +1 -0
  78. package/dist/eventRepository/observers/getEvents/PaginationController.d.ts +5 -0
  79. package/dist/eventRepository/observers/getEvents/PaginationController.d.ts.map +1 -0
  80. package/dist/eventRepository/observers/getEvents/QueryStreamController.d.ts +15 -0
  81. package/dist/eventRepository/observers/getEvents/QueryStreamController.d.ts.map +1 -0
  82. package/dist/eventRepository/observers/getEvents.d.ts +12 -0
  83. package/dist/eventRepository/observers/getEvents.d.ts.map +1 -0
  84. package/dist/eventRepository/observers/getMyEvents/LiveCollectionController.d.ts +13 -0
  85. package/dist/eventRepository/observers/getMyEvents/LiveCollectionController.d.ts.map +1 -0
  86. package/dist/eventRepository/observers/getMyEvents/PaginationController.d.ts +5 -0
  87. package/dist/eventRepository/observers/getMyEvents/PaginationController.d.ts.map +1 -0
  88. package/dist/eventRepository/observers/getMyEvents/QueryStreamController.d.ts +15 -0
  89. package/dist/eventRepository/observers/getMyEvents/QueryStreamController.d.ts.map +1 -0
  90. package/dist/eventRepository/observers/getMyEvents.d.ts +12 -0
  91. package/dist/eventRepository/observers/getMyEvents.d.ts.map +1 -0
  92. package/dist/eventRepository/observers/index.d.ts +4 -0
  93. package/dist/eventRepository/observers/index.d.ts.map +1 -0
  94. package/dist/eventRepository/utils/createEventEventSubscriber.d.ts +2 -0
  95. package/dist/eventRepository/utils/createEventEventSubscriber.d.ts.map +1 -0
  96. package/dist/eventRepository/utils/index.d.ts +3 -0
  97. package/dist/eventRepository/utils/index.d.ts.map +1 -0
  98. package/dist/eventRepository/utils/prepareEventPayload.d.ts +2 -0
  99. package/dist/eventRepository/utils/prepareEventPayload.d.ts.map +1 -0
  100. package/dist/index.cjs.js +4232 -2784
  101. package/dist/index.d.ts +2 -0
  102. package/dist/index.d.ts.map +1 -1
  103. package/dist/index.esm.js +2526 -1082
  104. package/dist/index.umd.js +3 -3
  105. package/dist/invitationRepository/api/acceptInvitation.d.ts +16 -0
  106. package/dist/invitationRepository/api/acceptInvitation.d.ts.map +1 -0
  107. package/dist/invitationRepository/api/cancelInvitation.d.ts +16 -0
  108. package/dist/invitationRepository/api/cancelInvitation.d.ts.map +1 -0
  109. package/dist/invitationRepository/api/getMyInvitation.d.ts +16 -0
  110. package/dist/invitationRepository/api/getMyInvitation.d.ts.map +1 -0
  111. package/dist/invitationRepository/api/index.d.ts +3 -0
  112. package/dist/invitationRepository/api/index.d.ts.map +1 -0
  113. package/dist/invitationRepository/events/index.d.ts +1 -1
  114. package/dist/invitationRepository/events/index.d.ts.map +1 -1
  115. package/dist/invitationRepository/events/onLocalInvitationCanceled.d.ts +17 -0
  116. package/dist/invitationRepository/events/onLocalInvitationCanceled.d.ts.map +1 -0
  117. package/dist/invitationRepository/index.d.ts +1 -0
  118. package/dist/invitationRepository/index.d.ts.map +1 -1
  119. package/dist/invitationRepository/internalApi/getInvitation.d.ts +1 -1
  120. package/dist/invitationRepository/internalApi/getInvitation.d.ts.map +1 -1
  121. package/dist/invitationRepository/internalObservers/getInvitations/InvitationsLiveCollectionController.d.ts.map +1 -0
  122. package/dist/invitationRepository/internalObservers/getInvitations/InvitationsPaginationController.d.ts.map +1 -0
  123. package/dist/invitationRepository/internalObservers/getInvitations/InvitationsQueryStreamController.d.ts.map +1 -0
  124. package/dist/invitationRepository/{observers → internalObservers}/getInvitations/enums.d.ts +1 -1
  125. package/dist/invitationRepository/internalObservers/getInvitations/enums.d.ts.map +1 -0
  126. package/dist/invitationRepository/internalObservers/getInvitations.d.ts +12 -0
  127. package/dist/invitationRepository/internalObservers/getInvitations.d.ts.map +1 -0
  128. package/dist/invitationRepository/observers/getInvitations.d.ts +28 -6
  129. package/dist/invitationRepository/observers/getInvitations.d.ts.map +1 -1
  130. package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsQueryStreamController.d.ts +1 -1
  131. package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsQueryStreamController.d.ts.map +1 -1
  132. package/dist/invitationRepository/observers/index.d.ts +1 -0
  133. package/dist/invitationRepository/observers/index.d.ts.map +1 -1
  134. package/dist/liveReactionRepository/api/createReaction.d.ts +2 -2
  135. package/dist/liveReactionRepository/api/createReaction.d.ts.map +1 -1
  136. package/dist/liveReactionRepository/service/ReactionSyncEngine.d.ts +1 -1
  137. package/dist/liveReactionRepository/service/ReactionSyncEngine.d.ts.map +1 -1
  138. package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts +2 -1
  139. package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts.map +1 -1
  140. package/dist/roomPresenceRepository/api/getRoomOnlineUsers.d.ts +18 -0
  141. package/dist/roomPresenceRepository/api/getRoomOnlineUsers.d.ts.map +1 -0
  142. package/dist/roomPresenceRepository/api/getRoomUserCount.d.ts +17 -0
  143. package/dist/roomPresenceRepository/api/getRoomUserCount.d.ts.map +1 -0
  144. package/dist/roomPresenceRepository/api/index.d.ts +5 -0
  145. package/dist/roomPresenceRepository/api/index.d.ts.map +1 -0
  146. package/dist/roomPresenceRepository/api/startHeartbeat.d.ts +15 -0
  147. package/dist/roomPresenceRepository/api/startHeartbeat.d.ts.map +1 -0
  148. package/dist/roomPresenceRepository/api/stopHeartbeat.d.ts +15 -0
  149. package/dist/roomPresenceRepository/api/stopHeartbeat.d.ts.map +1 -0
  150. package/dist/roomPresenceRepository/index.d.ts +2 -0
  151. package/dist/roomPresenceRepository/index.d.ts.map +1 -0
  152. package/dist/roomPresenceRepository/services/RoomPresenceSyncEngine/RoomPresenceSyncEngine.d.ts +38 -0
  153. package/dist/roomPresenceRepository/services/RoomPresenceSyncEngine/RoomPresenceSyncEngine.d.ts.map +1 -0
  154. package/dist/roomPresenceRepository/services/RoomPresenceSyncEngine/index.d.ts +2 -0
  155. package/dist/roomPresenceRepository/services/RoomPresenceSyncEngine/index.d.ts.map +1 -0
  156. package/dist/roomPresenceRepository/services/RoomPresenceSyncEngine/roomPresenceSyncEngineFactory.d.ts +32 -0
  157. package/dist/roomPresenceRepository/services/RoomPresenceSyncEngine/roomPresenceSyncEngineFactory.d.ts.map +1 -0
  158. package/dist/roomPresenceRepository/services/index.d.ts +2 -0
  159. package/dist/roomPresenceRepository/services/index.d.ts.map +1 -0
  160. package/dist/roomRepository/api/getBroadcasterData.d.ts +16 -0
  161. package/dist/roomRepository/api/getBroadcasterData.d.ts.map +1 -0
  162. package/dist/roomRepository/api/index.d.ts +3 -1
  163. package/dist/roomRepository/api/index.d.ts.map +1 -1
  164. package/dist/roomRepository/api/leaveRoom.d.ts +16 -0
  165. package/dist/roomRepository/api/leaveRoom.d.ts.map +1 -0
  166. package/dist/roomRepository/api/removeParticipant.d.ts +17 -0
  167. package/dist/roomRepository/api/removeParticipant.d.ts.map +1 -0
  168. package/dist/roomRepository/api/updateRoom.d.ts +1 -1
  169. package/dist/roomRepository/api/updateRoom.d.ts.map +1 -1
  170. package/dist/roomRepository/events/index.d.ts +6 -1
  171. package/dist/roomRepository/events/index.d.ts.map +1 -1
  172. package/dist/roomRepository/events/onRoomCoHostInviteAccepted.d.ts +17 -0
  173. package/dist/roomRepository/events/onRoomCoHostInviteAccepted.d.ts.map +1 -0
  174. package/dist/roomRepository/events/onRoomCoHostInviteCanceled.d.ts +17 -0
  175. package/dist/roomRepository/events/onRoomCoHostInviteCanceled.d.ts.map +1 -0
  176. package/dist/roomRepository/events/onRoomCoHostInviteRejected.d.ts +17 -0
  177. package/dist/roomRepository/events/onRoomCoHostInviteRejected.d.ts.map +1 -0
  178. package/dist/roomRepository/events/{onRoomParticipantInviting.d.ts → onRoomCoHostInvited.d.ts} +2 -2
  179. package/dist/roomRepository/events/onRoomCoHostInvited.d.ts.map +1 -0
  180. package/dist/roomRepository/events/onRoomEndBroadcasting.d.ts +1 -1
  181. package/dist/roomRepository/events/onRoomEndBroadcasting.d.ts.map +1 -1
  182. package/dist/roomRepository/events/onRoomLeft.d.ts +17 -0
  183. package/dist/roomRepository/events/onRoomLeft.d.ts.map +1 -0
  184. package/dist/roomRepository/events/onRoomParticipantJoined.d.ts +1 -1
  185. package/dist/roomRepository/events/onRoomParticipantJoined.d.ts.map +1 -1
  186. package/dist/roomRepository/events/onRoomParticipantLeft.d.ts +1 -1
  187. package/dist/roomRepository/events/onRoomParticipantLeft.d.ts.map +1 -1
  188. package/dist/roomRepository/events/onRoomParticipantRemoved.d.ts +17 -0
  189. package/dist/roomRepository/events/onRoomParticipantRemoved.d.ts.map +1 -0
  190. package/dist/roomRepository/events/onRoomParticipantRemovedLocal.d.ts +17 -0
  191. package/dist/roomRepository/events/onRoomParticipantRemovedLocal.d.ts.map +1 -0
  192. package/dist/roomRepository/events/onRoomRecordedAvailable.d.ts +1 -1
  193. package/dist/roomRepository/events/onRoomRecordedAvailable.d.ts.map +1 -1
  194. package/dist/roomRepository/events/onRoomStartBroadcasting.d.ts +1 -1
  195. package/dist/roomRepository/events/onRoomStartBroadcasting.d.ts.map +1 -1
  196. package/dist/roomRepository/events/onRoomWaitingReconnect.d.ts +1 -1
  197. package/dist/roomRepository/events/onRoomWaitingReconnect.d.ts.map +1 -1
  198. package/dist/roomRepository/events/onRoomWatchingCountUpdated.d.ts +17 -0
  199. package/dist/roomRepository/events/onRoomWatchingCountUpdated.d.ts.map +1 -0
  200. package/dist/roomRepository/events/onRoomWatchingUsersFetched.d.ts +17 -0
  201. package/dist/roomRepository/events/onRoomWatchingUsersFetched.d.ts.map +1 -0
  202. package/dist/roomRepository/internalApi/getLiveChat.d.ts +16 -0
  203. package/dist/roomRepository/internalApi/getLiveChat.d.ts.map +1 -0
  204. package/dist/roomRepository/internalApi/index.d.ts +1 -0
  205. package/dist/roomRepository/internalApi/index.d.ts.map +1 -1
  206. package/dist/roomRepository/observers/getRoom.d.ts.map +1 -1
  207. package/dist/utils/linkedObject/communityLinkedObject.d.ts.map +1 -1
  208. package/dist/utils/linkedObject/eventLinkObject.d.ts +2 -0
  209. package/dist/utils/linkedObject/eventLinkObject.d.ts.map +1 -0
  210. package/dist/utils/linkedObject/index.d.ts +2 -0
  211. package/dist/utils/linkedObject/index.d.ts.map +1 -1
  212. package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
  213. package/dist/utils/linkedObject/roomLinkedObject.d.ts +2 -0
  214. package/dist/utils/linkedObject/roomLinkedObject.d.ts.map +1 -0
  215. package/dist/utils/linkedObject/roomWatchingUserLinkedObject.d.ts +2 -0
  216. package/dist/utils/linkedObject/roomWatchingUserLinkedObject.d.ts.map +1 -0
  217. package/package.json +1 -1
  218. package/dist/client/utils/ObjectResolver/objectResolverEngine.d.ts.map +0 -1
  219. package/dist/client/utils/ObjectResolver/objectResolverEngineOnLoginHandler.d.ts.map +0 -1
  220. package/dist/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngine.d.ts.map +0 -1
  221. package/dist/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngineOnLoginHandler.d.ts.map +0 -1
  222. package/dist/client/utils/ReadReceiptSync/readReceiptSyncEngine.d.ts.map +0 -1
  223. package/dist/client/utils/ReadReceiptSync/readReceiptSyncEngineOnLoginHandler.d.ts.map +0 -1
  224. package/dist/invitationRepository/events/onLocalInvitationDeleted.d.ts +0 -17
  225. package/dist/invitationRepository/events/onLocalInvitationDeleted.d.ts.map +0 -1
  226. package/dist/invitationRepository/observers/getInvitations/InvitationsLiveCollectionController.d.ts.map +0 -1
  227. package/dist/invitationRepository/observers/getInvitations/InvitationsPaginationController.d.ts.map +0 -1
  228. package/dist/invitationRepository/observers/getInvitations/InvitationsQueryStreamController.d.ts.map +0 -1
  229. package/dist/invitationRepository/observers/getInvitations/enums.d.ts.map +0 -1
  230. package/dist/roomRepository/api/getRoomToken.d.ts +0 -16
  231. package/dist/roomRepository/api/getRoomToken.d.ts.map +0 -1
  232. package/dist/roomRepository/events/onRoomParticipantInviting.d.ts.map +0 -1
  233. /package/dist/client/{utils → services}/ObjectResolver/objectResolverEngine.d.ts +0 -0
  234. /package/dist/client/{utils → services}/ObjectResolver/objectResolverEngineOnLoginHandler.d.ts +0 -0
  235. /package/dist/client/{utils → services}/ReadReceiptSync/legacyReadReceiptSyncEngine.d.ts +0 -0
  236. /package/dist/client/{utils → services}/ReadReceiptSync/legacyReadReceiptSyncEngineOnLoginHandler.d.ts +0 -0
  237. /package/dist/client/{utils → services}/ReadReceiptSync/readReceiptSyncEngine.d.ts +0 -0
  238. /package/dist/client/{utils → services}/ReadReceiptSync/readReceiptSyncEngineOnLoginHandler.d.ts +0 -0
  239. /package/dist/invitationRepository/{observers → internalObservers}/getInvitations/InvitationsLiveCollectionController.d.ts +0 -0
  240. /package/dist/invitationRepository/{observers → internalObservers}/getInvitations/InvitationsPaginationController.d.ts +0 -0
  241. /package/dist/invitationRepository/{observers → internalObservers}/getInvitations/InvitationsQueryStreamController.d.ts +0 -0
package/dist/index.esm.js CHANGED
@@ -126,7 +126,7 @@ const PostStructureType = Object.freeze({
126
126
  var InvitationTypeEnum;
127
127
  (function (InvitationTypeEnum) {
128
128
  InvitationTypeEnum["CommunityMemberInvite"] = "communityMemberInvite";
129
- InvitationTypeEnum["LivestreamInvite"] = "livestreamInvite";
129
+ InvitationTypeEnum["LivestreamCohostInvite"] = "livestreamCohostInvite";
130
130
  })(InvitationTypeEnum || (InvitationTypeEnum = {}));
131
131
  var InvitationStatusEnum;
132
132
  (function (InvitationStatusEnum) {
@@ -140,6 +140,11 @@ var InvitationSortByEnum;
140
140
  InvitationSortByEnum["FirstCreated"] = "firstCreated";
141
141
  InvitationSortByEnum["LastCreated"] = "lastCreated";
142
142
  })(InvitationSortByEnum || (InvitationSortByEnum = {}));
143
+ var InvitationTargetTypeEnum;
144
+ (function (InvitationTargetTypeEnum) {
145
+ InvitationTargetTypeEnum["Community"] = "community";
146
+ InvitationTargetTypeEnum["Room"] = "room";
147
+ })(InvitationTargetTypeEnum || (InvitationTargetTypeEnum = {}));
143
148
 
144
149
  var JoinRequestStatusEnum;
145
150
  (function (JoinRequestStatusEnum) {
@@ -164,6 +169,7 @@ var FeedDataTypeEnum;
164
169
  FeedDataTypeEnum["LiveStream"] = "liveStream";
165
170
  FeedDataTypeEnum["Clip"] = "clip";
166
171
  FeedDataTypeEnum["Poll"] = "poll";
172
+ FeedDataTypeEnum["Room"] = "room";
167
173
  })(FeedDataTypeEnum || (FeedDataTypeEnum = {}));
168
174
  var FeedSortByEnum;
169
175
  (function (FeedSortByEnum) {
@@ -178,6 +184,30 @@ var FeedSourceEnum;
178
184
  FeedSourceEnum["User"] = "user";
179
185
  })(FeedSourceEnum || (FeedSourceEnum = {}));
180
186
 
187
+ var AmityEventType;
188
+ (function (AmityEventType) {
189
+ AmityEventType["Virtual"] = "virtual";
190
+ AmityEventType["InPerson"] = "in_person";
191
+ })(AmityEventType || (AmityEventType = {}));
192
+ var AmityEventOriginType;
193
+ (function (AmityEventOriginType) {
194
+ AmityEventOriginType["Community"] = "community";
195
+ AmityEventOriginType["User"] = "user";
196
+ })(AmityEventOriginType || (AmityEventOriginType = {}));
197
+ var AmityEventStatus;
198
+ (function (AmityEventStatus) {
199
+ AmityEventStatus["Scheduled"] = "scheduled";
200
+ AmityEventStatus["Live"] = "live";
201
+ AmityEventStatus["Ended"] = "ended";
202
+ AmityEventStatus["Cancelled"] = "cancelled";
203
+ })(AmityEventStatus || (AmityEventStatus = {}));
204
+ var AmityEventResponseStatus;
205
+ (function (AmityEventResponseStatus) {
206
+ AmityEventResponseStatus["Going"] = "going";
207
+ AmityEventResponseStatus["Interested"] = "interested";
208
+ AmityEventResponseStatus["NotGoing"] = "not_going";
209
+ })(AmityEventResponseStatus || (AmityEventResponseStatus = {}));
210
+
181
211
  function getVersion() {
182
212
  try {
183
213
  // the string ''v7.11.0-esm'' should be replaced by actual value by @rollup/plugin-replace
@@ -627,6 +657,8 @@ const idResolvers = {
627
657
  invitation: ({ _id }) => _id,
628
658
  joinRequest: ({ joinRequestId }) => joinRequestId,
629
659
  room: ({ roomId }) => roomId,
660
+ event: ({ eventId }) => eventId,
661
+ discussionCommunity: ({ communityId }) => communityId,
630
662
  };
631
663
  /**
632
664
  * Retrieve the id resolver matching a domain name
@@ -683,6 +715,9 @@ const PAYLOAD2MODEL = {
683
715
  invitations: 'invitation',
684
716
  joinRequests: 'joinRequest',
685
717
  rooms: 'room',
718
+ events: 'event',
719
+ discussionCommunities: 'discussionCommunity',
720
+ viewers: 'viewer',
686
721
  };
687
722
  /** hidden */
688
723
  const isOutdated = (prevData, nextData) => {
@@ -1413,12 +1448,14 @@ const createEventEmitter = () => {
1413
1448
  const proxyMqttEvents = (mqttClient, emitter) => {
1414
1449
  MQTT_EVENTS.forEach(event => {
1415
1450
  mqttClient === null || mqttClient === void 0 ? void 0 : mqttClient.on(event, (...params) => {
1451
+ console.log('global event received => ', event);
1416
1452
  emitter.emit(event, params.length === 1 ? params[0] : params);
1417
1453
  });
1418
1454
  });
1419
1455
  // @ts-ignore
1420
1456
  mqttClient.on('message', (topic, payload) => {
1421
1457
  const message = JSON.parse(payload.toString());
1458
+ console.log('message event received => ', message.eventType, message.data);
1422
1459
  emitter.emit(message.eventType, message.data);
1423
1460
  });
1424
1461
  };
@@ -1482,6 +1519,37 @@ async function modifyMqttConnection() {
1482
1519
  }
1483
1520
  }
1484
1521
 
1522
+ const userLinkedObject = (user) => {
1523
+ return Object.assign(Object.assign({}, user), { get avatar() {
1524
+ var _a;
1525
+ if (!user.avatarFileId)
1526
+ return undefined;
1527
+ const avatar = (_a = pullFromCache([
1528
+ 'file',
1529
+ 'get',
1530
+ `${user.avatarFileId}`,
1531
+ ])) === null || _a === void 0 ? void 0 : _a.data;
1532
+ return avatar;
1533
+ } });
1534
+ };
1535
+
1536
+ /* begin_public_function
1537
+ id: client.get_current_user
1538
+ */
1539
+ const getCurrentUser = () => {
1540
+ var _a;
1541
+ const client = getActiveClient();
1542
+ if (!client) {
1543
+ throw new ASCError('Connect client first', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "fatal" /* Amity.ErrorLevel.FATAL */);
1544
+ }
1545
+ const cache = (_a = pullFromCache(['user', 'get', client.userId])) === null || _a === void 0 ? void 0 : _a.data;
1546
+ if (!cache) {
1547
+ throw new ASCError('Connect client first', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "fatal" /* Amity.ErrorLevel.FATAL */);
1548
+ }
1549
+ return userLinkedObject(cache);
1550
+ };
1551
+ /* end_public_function */
1552
+
1485
1553
  var SubscriptionLevels;
1486
1554
  (function (SubscriptionLevels) {
1487
1555
  SubscriptionLevels["COMMUNITY"] = "community";
@@ -1587,6 +1655,14 @@ const getLiveStreamTopic = () => {
1587
1655
  const getLiveReactionTopic = (post) => {
1588
1656
  return `${post.path}/liveReaction`;
1589
1657
  };
1658
+ const getRoomWatcherTopic = (room) => {
1659
+ const user = getCurrentUser();
1660
+ return `${getNetworkId(user)}/room/${room._id}`;
1661
+ };
1662
+ const getRoomStreamerTopic = (room) => {
1663
+ const user = getCurrentUser();
1664
+ return `${getNetworkId(user)}/room/${room.roomId}/streamer`;
1665
+ };
1590
1666
  function subscribeTopic(topic, callback) {
1591
1667
  const { mqtt } = getActiveClient();
1592
1668
  if (!mqtt)
@@ -21013,20 +21089,6 @@ const getChannelMessagePreview = (channelId) => {
21013
21089
  return ((_b = (_a = pullFromCache(['messagePreviewChannel', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : null);
21014
21090
  };
21015
21091
 
21016
- const userLinkedObject = (user) => {
21017
- return Object.assign(Object.assign({}, user), { get avatar() {
21018
- var _a;
21019
- if (!user.avatarFileId)
21020
- return undefined;
21021
- const avatar = (_a = pullFromCache([
21022
- 'file',
21023
- 'get',
21024
- `${user.avatarFileId}`,
21025
- ])) === null || _a === void 0 ? void 0 : _a.data;
21026
- return avatar;
21027
- } });
21028
- };
21029
-
21030
21092
  const getChannelMessagePreviewWithUser = (channel) => {
21031
21093
  var _a;
21032
21094
  const messagePreview = channel.messagePreviewId
@@ -24604,19 +24666,19 @@ class LiveReactionSyncEngine {
24604
24666
  // Clear buffer
24605
24667
  this.clearBuffer();
24606
24668
  const payloads = reactions.reduce((prev, curr) => {
24607
- const { streamId } = curr, rest = __rest(curr, ["streamId"]);
24608
- if (!prev[streamId]) {
24669
+ const { roomId } = curr, rest = __rest(curr, ["roomId"]);
24670
+ if (!prev[roomId]) {
24609
24671
  // eslint-disable-next-line no-param-reassign
24610
- prev[streamId] = [rest];
24672
+ prev[roomId] = [rest];
24611
24673
  }
24612
24674
  else
24613
- prev[streamId].push(rest);
24675
+ prev[roomId].push(rest);
24614
24676
  return prev;
24615
24677
  }, {});
24616
24678
  // Call server api `POST /api/v1/reactions/live` to sync live reactions
24617
- Object.entries(payloads).forEach(([streamId, reactions]) => {
24679
+ Object.entries(payloads).forEach(([roomId, reactions]) => {
24618
24680
  createLiveReaction({
24619
- liveStreamId: streamId,
24681
+ liveStreamId: roomId,
24620
24682
  reactions,
24621
24683
  });
24622
24684
  });
@@ -25109,23 +25171,6 @@ const loginAsVisitor = async (params) => {
25109
25171
  };
25110
25172
  /* end_public_function */
25111
25173
 
25112
- /* begin_public_function
25113
- id: client.get_current_user
25114
- */
25115
- const getCurrentUser = () => {
25116
- var _a;
25117
- const client = getActiveClient();
25118
- if (!client) {
25119
- throw new ASCError('Connect client first', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "fatal" /* Amity.ErrorLevel.FATAL */);
25120
- }
25121
- const cache = (_a = pullFromCache(['user', 'get', client.userId])) === null || _a === void 0 ? void 0 : _a.data;
25122
- if (!cache) {
25123
- throw new ASCError('Connect client first', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "fatal" /* Amity.ErrorLevel.FATAL */);
25124
- }
25125
- return userLinkedObject(cache);
25126
- };
25127
- /* end_public_function */
25128
-
25129
25174
  /* begin_public_function
25130
25175
  id: client.renew_access_token
25131
25176
  */
@@ -26555,7 +26600,7 @@ const getUserUnread = (callback) => {
26555
26600
  };
26556
26601
  };
26557
26602
 
26558
- var index$p = /*#__PURE__*/Object.freeze({
26603
+ var index$r = /*#__PURE__*/Object.freeze({
26559
26604
  __proto__: null,
26560
26605
  getActiveClient: getActiveClient,
26561
26606
  getActiveUser: getActiveUser,
@@ -27774,7 +27819,7 @@ const getMyFollowInfo = (callback) => {
27774
27819
  };
27775
27820
  /* end_public_function */
27776
27821
 
27777
- var index$o = /*#__PURE__*/Object.freeze({
27822
+ var index$q = /*#__PURE__*/Object.freeze({
27778
27823
  __proto__: null,
27779
27824
  blockUser: blockUser,
27780
27825
  unBlockUser: unBlockUser,
@@ -28127,7 +28172,7 @@ getChannel$1.locally = (channelId) => {
28127
28172
  * @category Stream API
28128
28173
  * @async
28129
28174
  */
28130
- const getLiveChat = async (stream) => {
28175
+ const getLiveChat$1 = async (stream) => {
28131
28176
  var _a;
28132
28177
  const client = getActiveClient();
28133
28178
  client.log('stream/getLiveChat', stream.streamId);
@@ -28194,7 +28239,7 @@ const streamLinkedObject = (stream) => {
28194
28239
  return streamLinkedObject(streamCache);
28195
28240
  })
28196
28241
  .filter(isNonNullable);
28197
- }, getLiveChat: () => getLiveChat(stream), isBanned: !stream.watcherUrl, watcherUrl: null, get [GET_WATCHER_URLS]() {
28242
+ }, getLiveChat: () => getLiveChat$1(stream), isBanned: !stream.watcherUrl, watcherUrl: null, get [GET_WATCHER_URLS]() {
28198
28243
  return stream.watcherUrl;
28199
28244
  } });
28200
28245
  };
@@ -28309,734 +28354,218 @@ function isAmityRoomPost(post) {
28309
28354
  post.dataType === 'room');
28310
28355
  }
28311
28356
 
28312
- const postLinkedObject = (post) => {
28313
- return shallowClone(post, {
28314
- childrenPosts: post.children
28315
- .map(childPost => { var _a; return (_a = pullFromCache(['post', 'get', childPost])) === null || _a === void 0 ? void 0 : _a.data; })
28316
- .filter(isNonNullable)
28317
- .map(postLinkedObject),
28318
- analytics: {
28319
- markAsViewed: () => {
28320
- const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
28321
- analyticsEngineInstance.markPostAsViewed(post.postId);
28322
- },
28323
- },
28324
- get latestComments() {
28325
- if (!post.comments)
28326
- return [];
28327
- return (post.comments
28328
- .map(commentId => {
28329
- var _a;
28330
- const commentCached = (_a = pullFromCache([
28331
- 'comment',
28332
- 'get',
28333
- commentId,
28334
- ])) === null || _a === void 0 ? void 0 : _a.data;
28335
- if (!commentCached)
28336
- return null;
28337
- return commentLinkedObject(commentCached);
28338
- })
28339
- .filter(Boolean) || []);
28340
- },
28341
- get creator() {
28342
- const cacheData = pullFromCache(['user', 'get', post.postedUserId]);
28343
- if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
28344
- return;
28345
- return userLinkedObject(cacheData.data);
28346
- },
28347
- getImageInfo() {
28348
- var _a, _b;
28349
- return isAmityImagePost(post)
28350
- ? (_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
28351
- : undefined;
28352
- },
28353
- getVideoInfo() {
28354
- var _a, _b, _c;
28355
- return isAmityVideoPost(post)
28356
- ? (_c = pullFromCache(['file', 'get', (_b = (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.videoFileId) === null || _b === void 0 ? void 0 : _b.original])) === null || _c === void 0 ? void 0 : _c.data
28357
- : undefined;
28358
- },
28359
- getVideoThumbnailInfo() {
28360
- var _a, _b;
28361
- return isAmityVideoPost(post)
28362
- ? (_b = pullFromCache(['file', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.thumbnailFileId])) === null || _b === void 0 ? void 0 : _b.data
28363
- : undefined;
28364
- },
28365
- getFileInfo() {
28366
- var _a, _b;
28367
- return isAmityFilePost(post)
28368
- ? (_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
28369
- : undefined;
28370
- },
28371
- getLivestreamInfo() {
28372
- var _a, _b;
28373
- if (!isAmityLivestreamPost(post))
28374
- return;
28375
- const cache = (_b = pullFromCache([
28376
- 'stream',
28377
- 'get',
28378
- (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.streamId,
28379
- ])) === null || _b === void 0 ? void 0 : _b.data;
28380
- if (!cache)
28381
- return;
28382
- return streamLinkedObject(cache);
28383
- },
28384
- getPollInfo() {
28385
- var _a, _b;
28386
- if (!isAmityPollPost(post))
28387
- return;
28388
- const cache = (_b = pullFromCache(['poll', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.pollId])) === null || _b === void 0 ? void 0 : _b.data;
28389
- if (!cache)
28390
- return;
28391
- return cache;
28392
- },
28393
- getClipInfo() {
28394
- var _a, _b;
28395
- return isAmityClipPost(post)
28396
- ? (_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
28397
- : undefined;
28398
- },
28399
- getAudioInfo() {
28400
- var _a, _b;
28401
- return isAmityAudioPost(post)
28402
- ? (_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
28403
- : undefined;
28404
- },
28405
- getRoomInfo() {
28406
- var _a, _b;
28407
- if (!isAmityRoomPost(post))
28408
- return;
28409
- return (_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;
28410
- },
28411
- });
28357
+ /**
28358
+ * ```js
28359
+ * import { RoomRepository } from '@amityco/ts-sdk'
28360
+ * const stream = await getStream('foobar')
28361
+ * ```
28362
+ *
28363
+ * Fetches a {@link Amity.Channel} object linked with a current stream
28364
+ *
28365
+ * @param stream {@link Amity.Stream} that has linked live channel
28366
+ * @returns the associated {@link Amity.Channel<'live'>} object
28367
+ *
28368
+ * @category Stream API
28369
+ * @async
28370
+ */
28371
+ const getLiveChat = async (room) => {
28372
+ var _a;
28373
+ const client = getActiveClient();
28374
+ client.log('room/getLiveChat', room.roomId);
28375
+ if (room.liveChannelId) {
28376
+ const channel = (_a = pullFromCache([
28377
+ 'channel',
28378
+ 'get',
28379
+ room.liveChannelId,
28380
+ ])) === null || _a === void 0 ? void 0 : _a.data;
28381
+ if (channel)
28382
+ return channelLinkedObject(constructChannelObject(channel));
28383
+ const { data } = await getChannel$1(room.liveChannelId);
28384
+ return channelLinkedObject(constructChannelObject(data));
28385
+ }
28386
+ // No Channel ID
28387
+ // streamer: create a new live channel
28388
+ if (room.createdBy === client.userId) {
28389
+ const { data: channel } = await createChannel({
28390
+ type: 'live',
28391
+ postId: room.referenceId,
28392
+ roomId: room.roomId,
28393
+ });
28394
+ // Update channelId to stream object in cache
28395
+ mergeInCache(['room', 'get', room.roomId], {
28396
+ liveChannelId: channel.channelId,
28397
+ });
28398
+ return channel;
28399
+ }
28400
+ // watcher: return undefined
28401
+ return undefined;
28412
28402
  };
28413
28403
 
28414
- /** @hidden */
28415
- const dispatchReactable = (referenceType, model) => {
28416
- if (referenceType === 'message')
28417
- // @ts-ignore: refactor later
28418
- fireEvent('local.message.updated', { messages: [model] });
28419
- else if (referenceType === 'post')
28420
- // @ts-ignore: refactor later
28421
- fireEvent('post.updated', { posts: [model] });
28422
- else if (referenceType === 'comment')
28423
- // @ts-ignore: refactor later
28424
- fireEvent('comment.updated', { comments: [model] });
28425
- else if (referenceType === 'story')
28426
- // Need to provide all data same StoryPayload from BE
28427
- fireEvent('story.updated', {
28428
- categories: [],
28429
- comments: [],
28430
- communities: [],
28431
- communityUsers: [],
28432
- files: [],
28433
- users: [],
28434
- stories: [model],
28435
- });
28404
+ const convertRawInvitationToInternalInvitation = (rawInvitation) => {
28405
+ return Object.assign(Object.assign({}, rawInvitation), { createdById: rawInvitation.createdBy });
28436
28406
  };
28437
28407
 
28438
- const addReaction$1 = async (referenceType, referenceId, reactionName, referenceVersion) => {
28439
- var _a, _b, _c;
28440
- const client = getActiveClient();
28441
- client.log('reaction/createReaction', {
28442
- referenceId,
28443
- referenceType,
28444
- reactionName,
28445
- });
28446
- if (!['post', 'comment', 'story', 'message'].includes(referenceType))
28447
- throw new ASCApiError('The reference type is not valid. It should be one of post, comment, story, or message', 400000 /* Amity.ServerError.BAD_REQUEST */, "error" /* Amity.ErrorLevel.ERROR */);
28448
- const { data } = await client.http.post('/api/v2/reactions', {
28449
- referenceId,
28450
- referenceType,
28451
- reactionName,
28452
- referenceVersion,
28453
- });
28454
- if (client.cache) {
28455
- const model = pullFromCache([
28456
- referenceType,
28457
- 'get',
28458
- referenceId,
28459
- ]);
28460
- if (!model || ((_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName)))
28461
- return true;
28462
- const updatedModel = Object.assign(Object.assign({}, model.data), { reactionsCount: model.data.reactionsCount + 1, myReactions: [...((_b = model.data.myReactions) !== null && _b !== void 0 ? _b : []), reactionName], reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: ((_c = model.data.reactions[reactionName]) !== null && _c !== void 0 ? _c : 0) + 1 }), updatedAt: new Date().toISOString() });
28463
- if (referenceType === 'comment') {
28464
- fireEvent('local.comment.addReaction', {
28465
- comment: updatedModel,
28466
- reactor: {
28467
- userId: client.userId,
28468
- reactionName,
28469
- reactionId: data.addedId,
28470
- },
28471
- });
28472
- return true;
28473
- }
28474
- if (referenceType === 'post') {
28475
- fireEvent('local.post.addReaction', {
28476
- post: updatedModel,
28477
- reactor: {
28478
- userId: client.userId,
28479
- reactionName,
28480
- reactionId: data.addedId,
28481
- },
28482
- });
28483
- return true;
28484
- }
28485
- if (referenceType === 'story') {
28486
- fireEvent('local.story.reactionAdded', {
28487
- story: updatedModel,
28488
- reactor: {
28489
- userId: client.userId,
28490
- reactionName,
28491
- reactionId: data.addedId,
28492
- },
28493
- });
28494
- return true;
28495
- }
28496
- }
28497
- return true;
28408
+ const prepareInvitationPayload = (rawPayload) => {
28409
+ return Object.assign(Object.assign({}, rawPayload), { invitations: rawPayload.invitations.map(convertRawInvitationToInternalInvitation), users: rawPayload.users.map(convertRawUserToInternalUser) });
28498
28410
  };
28499
- addReaction$1.optimistically = (referenceType, referenceId, reactionName) => {
28500
- var _a, _b, _c, _d, _e;
28411
+
28412
+ /* begin_public_function
28413
+ id: invitation.createInvitations
28414
+ */
28415
+ /**
28416
+ * ```js
28417
+ * import { createInvitations } from '@amityco/ts-sdk'
28418
+ * const created = await createInvitations({
28419
+ * type: string,
28420
+ * targetType: string,
28421
+ * targetId: string,
28422
+ * userIds: string[]
28423
+ * }))
28424
+ * ```
28425
+ *
28426
+ * Creates an {@link Amity.Invitation}
28427
+ *
28428
+ * @param bundle The data necessary to create a new {@link Amity.Invitation}
28429
+ * @returns The newly created {@link Amity.Invitation}
28430
+ *
28431
+ * @category Invitation API
28432
+ * @async
28433
+ */
28434
+ const createInvitations = async (bundle) => {
28501
28435
  const client = getActiveClient();
28502
- client.log('reaction/createReaction.optimistically', {
28503
- referenceId,
28504
- referenceType,
28505
- reactionName,
28506
- });
28507
- if (!client.cache)
28508
- return;
28509
- const model = pullFromCache([
28510
- referenceType,
28511
- 'get',
28512
- referenceId,
28513
- ]);
28514
- if (!(model === null || model === void 0 ? void 0 : model.data) || ((_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName)))
28515
- return;
28516
- const reaction = Object.assign(Object.assign({}, model.data), { reactionsCount: model.data.reactionsCount + 1, myReactions: [...((_b = model.data.myReactions) !== null && _b !== void 0 ? _b : []), reactionName], reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: ((_c = model.data.reactions[reactionName]) !== null && _c !== void 0 ? _c : 0) + 1 }) });
28517
- upsertInCache([referenceType, 'get', referenceId], reaction, {
28518
- cachedAt: UNSYNCED_OBJECT_CACHED_AT_VALUE,
28519
- });
28520
- dispatchReactable(referenceType, reaction);
28521
- return (_e = (_d = reaction === null || reaction === void 0 ? void 0 : reaction.myReactions) === null || _d === void 0 ? void 0 : _d.includes(reactionName)) !== null && _e !== void 0 ? _e : false;
28436
+ client.log('invitation/createInvitations', bundle);
28437
+ const { data: payload } = await client.http.post('/api/v1/invitations', bundle);
28438
+ const data = prepareInvitationPayload(payload);
28439
+ const cachedAt = client.cache && Date.now();
28440
+ if (client.cache)
28441
+ ingestInCache(data, { cachedAt });
28442
+ fireEvent('local.invitation.created', data.invitations);
28443
+ return {
28444
+ data: data.invitations,
28445
+ cachedAt,
28446
+ };
28522
28447
  };
28448
+ /* end_public_function */
28523
28449
 
28524
- const removeReaction$1 = async (referenceType, referenceId, reactionName, referenceVersion) => {
28525
- var _a, _b;
28450
+ /* begin_public_function
28451
+ id: invitation.accept
28452
+ */
28453
+ /**
28454
+ * ```js
28455
+ * import { acceptInvitation } from '@amityco/ts-sdk'
28456
+ * const isAccepted = await acceptInvitation(invitationId)
28457
+ * ```
28458
+ *
28459
+ * Accepts a {@link Amity.Invitation} object
28460
+ *
28461
+ * @param invitationId the {@link Amity.Invitation} to accept
28462
+ * @returns A success boolean if the {@link Amity.Invitation} was accepted
28463
+ *
28464
+ * @category Invitation API
28465
+ * @async
28466
+ */
28467
+ const acceptInvitation$1 = async (invitationId) => {
28468
+ var _a;
28526
28469
  const client = getActiveClient();
28527
- client.log('reaction/removeReaction', {
28528
- referenceId,
28529
- referenceType,
28530
- reactionName,
28531
- });
28532
- if (!['post', 'comment', 'story', 'message'].includes(referenceType))
28533
- throw new ASCApiError('The reference type is not valid. It should be one of post, comment, story, or message', 400000 /* Amity.ServerError.BAD_REQUEST */, "error" /* Amity.ErrorLevel.ERROR */);
28534
- const { data } = await client.http.delete(`/api/v2/reactions`, {
28535
- data: {
28536
- referenceId,
28537
- referenceType,
28538
- reactionName,
28539
- referenceVersion,
28540
- },
28541
- });
28542
- if (client.cache) {
28543
- const model = pullFromCache([
28544
- referenceType,
28545
- 'get',
28546
- referenceId,
28547
- ]);
28548
- if (!model)
28549
- return true;
28550
- const updatedModel = Object.assign(Object.assign({}, model.data), { reactionsCount: Math.max(0, model.data.reactionsCount - 1), myReactions: ((_a = model.data.myReactions) !== null && _a !== void 0 ? _a : []).filter(item => item !== reactionName), reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: Math.max(0, ((_b = model.data.reactions[reactionName]) !== null && _b !== void 0 ? _b : 0) - 1) }), updatedAt: new Date().toISOString() });
28551
- if (referenceType === 'comment') {
28552
- fireEvent('local.comment.removeReaction', {
28553
- comment: updatedModel,
28554
- reactor: {
28555
- reactionId: data.removedId,
28556
- reactionName,
28557
- userId: client.userId,
28558
- },
28559
- });
28560
- return true;
28561
- }
28562
- if (referenceType === 'post') {
28563
- fireEvent('local.post.removeReaction', {
28564
- post: updatedModel,
28565
- reactor: {
28566
- reactionId: data.removedId,
28567
- reactionName,
28568
- userId: client.userId,
28569
- },
28570
- });
28571
- return true;
28572
- }
28573
- if (referenceType === 'story') {
28574
- fireEvent('local.story.reactionAdded', {
28575
- story: updatedModel,
28576
- reactor: {
28577
- userId: client.userId,
28578
- reactionName,
28579
- reactionId: data.removedId,
28580
- },
28581
- });
28582
- return true;
28583
- }
28470
+ client.log('invitation/acceptInvitation', invitationId);
28471
+ const { data } = await client.http.post(`/api/v1/invitations/${invitationId}/accept`);
28472
+ const invitation = (_a = pullFromCache([
28473
+ 'invitation',
28474
+ 'get',
28475
+ invitationId,
28476
+ ])) === null || _a === void 0 ? void 0 : _a.data;
28477
+ if (invitation) {
28478
+ upsertInCache(['invitation', 'get', invitationId], { status: "approved" /* InvitationStatusEnum.Approved */ });
28479
+ fireEvent('local.invitation.updated', [invitation]);
28584
28480
  }
28585
- return true;
28586
- };
28587
-
28588
- const addReactionToMessage = (reactionName, message) => {
28589
- const isMessageV3 = message.publicId !== message.messageId;
28590
- return addReaction$1('message', isMessageV3 ? message.publicId : message.messageId, reactionName, isMessageV3 ? 3 : 5);
28481
+ return data.success;
28591
28482
  };
28483
+ /* end_public_function */
28592
28484
 
28593
- const getCachedMarker = (message) => {
28594
- var _a, _b;
28595
- const key = {
28596
- creatorId: 'creatorPrivateId' in message ? message.creatorPrivateId : message.creatorId,
28597
- feedId: (_a = message.messageFeedId) !== null && _a !== void 0 ? _a : message.subChannelId,
28598
- contentId: message.messageId,
28599
- };
28600
- return (_b = pullFromCache([
28601
- 'messageMarker',
28485
+ /* begin_public_function
28486
+ id: invitation.reject
28487
+ */
28488
+ /**
28489
+ * ```js
28490
+ * import { rejectInvitation } from '@amityco/ts-sdk'
28491
+ * const isRejected = await rejectInvitation(invitationId)
28492
+ * ```
28493
+ *
28494
+ * Rejects a {@link Amity.Invitation} object
28495
+ *
28496
+ * @param invitationId the {@link Amity.Invitation} to reject
28497
+ * @returns A success boolean if the {@link Amity.Invitation} was rejected
28498
+ *
28499
+ * @category Invitation API
28500
+ * @async
28501
+ */
28502
+ const rejectInvitation = async (invitationId) => {
28503
+ var _a;
28504
+ const client = getActiveClient();
28505
+ client.log('invitation/rejectInvitation', invitationId);
28506
+ const { data } = await client.http.post(`/api/v1/invitations/${invitationId}/reject`);
28507
+ const invitation = (_a = pullFromCache([
28508
+ 'invitation',
28602
28509
  'get',
28603
- getResolver('messageMarker')(key),
28604
- ])) === null || _b === void 0 ? void 0 : _b.data;
28510
+ invitationId,
28511
+ ])) === null || _a === void 0 ? void 0 : _a.data;
28512
+ if (invitation) {
28513
+ upsertInCache(['invitation', 'get', invitationId], { status: "rejected" /* InvitationStatusEnum.Rejected */ });
28514
+ fireEvent('local.invitation.updated', [invitation]);
28515
+ }
28516
+ return data.success;
28605
28517
  };
28606
- const getMessageReadCount = (message, marker) => {
28607
- var _a;
28608
- // Look in the marker param first
28609
- return (_a = marker !== null && marker !== void 0 ? marker :
28610
- // If the marker param is not set, look in the cache
28611
- getCachedMarker(message)) !== null && _a !== void 0 ? _a : { readCount: 0, deliveredCount: 0 };
28612
- }; // and if not found in cache use default value `0`
28518
+ /* end_public_function */
28613
28519
 
28614
- const removeReactionToMessage = (reactionName, message) => {
28615
- const isMessageV3 = message.publicId !== message.messageId;
28616
- return removeReaction$1('message', isMessageV3 ? message.publicId : message.messageId, reactionName, isMessageV3 ? 3 : 5);
28617
- };
28520
+ var InvitationActionsEnum;
28521
+ (function (InvitationActionsEnum) {
28522
+ InvitationActionsEnum["OnLocalInvitationCreated"] = "onLocalInvitationCreated";
28523
+ InvitationActionsEnum["OnLocalInvitationUpdated"] = "onLocalInvitationUpdated";
28524
+ InvitationActionsEnum["OnLocalInvitationCanceled"] = "onLocalInvitationCanceled";
28525
+ })(InvitationActionsEnum || (InvitationActionsEnum = {}));
28618
28526
 
28619
- const messageLinkedObject = (message) => {
28620
- const rest = __rest(message, ["creatorPrivateId"]);
28621
- return Object.assign(Object.assign({}, rest), { get readCount() {
28622
- return getMessageReadCount(message).readCount;
28623
- },
28624
- get deliveredCount() {
28625
- return getMessageReadCount(message).deliveredCount;
28527
+ const invitationLinkedObject = (invitation) => {
28528
+ return Object.assign(Object.assign({}, invitation), { get user() {
28529
+ const cacheData = pullFromCache(['user', 'get', invitation.invitedUserPublicId]);
28530
+ if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
28531
+ return userLinkedObject(cacheData.data);
28532
+ return undefined;
28626
28533
  },
28627
- get creator() {
28628
- var _a;
28629
- return (_a = pullFromCache(['user', 'get', message.creatorId])) === null || _a === void 0 ? void 0 : _a.data;
28630
- }, markRead: () => markReadMessage(message), addReaction: (reactionName) => addReactionToMessage(reactionName, message), removeReaction: (reactionName) => removeReactionToMessage(reactionName, message) });
28631
- };
28632
-
28633
- const reactorLinkedObject = (reactor) => {
28634
- return Object.assign(Object.assign({}, reactor), { get user() {
28635
- var _a;
28636
- const user = (_a = pullFromCache(['user', 'get', reactor.userId])) === null || _a === void 0 ? void 0 : _a.data;
28637
- if (!user)
28638
- return undefined;
28639
- return userLinkedObject(user);
28640
- } });
28641
- };
28642
-
28643
- const adLinkedObject = (ad) => {
28644
- const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
28645
- const { image9_16: image916, image1_1: image11 } = ad, restAds = __rest(ad, ["image9_16", "image1_1"]);
28646
- return Object.assign(Object.assign({}, restAds), { analytics: {
28647
- markAsSeen: (placement) => {
28648
- analyticsEngineInstance.markAdAsViewed(ad, placement);
28649
- },
28650
- markLinkAsClicked: (placement) => {
28651
- analyticsEngineInstance.markAdAsClicked(ad, placement);
28652
- },
28653
- }, get advertiser() {
28654
- var _a, _b;
28655
- const advertiserData = (_a = pullFromCache([
28656
- 'advertiser',
28657
- 'get',
28658
- ad.advertiserId,
28659
- ])) === null || _a === void 0 ? void 0 : _a.data;
28660
- if (!advertiserData)
28661
- return;
28662
- const avatarFile = (_b = pullFromCache([
28663
- 'file',
28664
- 'get',
28665
- advertiserData.avatarFileId,
28666
- ])) === null || _b === void 0 ? void 0 : _b.data;
28667
- return Object.assign(Object.assign({}, advertiserData), { avatar: avatarFile });
28668
- },
28669
- get image1_1() {
28670
- const cacheData = pullFromCache(['file', 'get', image11]);
28671
- if (!cacheData)
28672
- return undefined;
28673
- return cacheData.data || undefined;
28674
- },
28675
- get image9_16() {
28676
- const cacheData = pullFromCache(['file', 'get', image916]);
28677
- if (!cacheData)
28678
- return undefined;
28679
- return cacheData.data || undefined;
28680
- } });
28681
- };
28682
-
28683
- const pinnedPostLinkedObject = (pinnedPost) => {
28684
- var _a;
28685
- const postCached = pullFromCache(['post', 'get', pinnedPost.referenceId]);
28686
- const pinnedBy = (_a = queryCache(['user', 'get']).find(cache => {
28687
- var _a;
28688
- return ((_a = cache.data) === null || _a === void 0 ? void 0 : _a.userInternalId) === pinnedPost.pinnedBy;
28689
- })) === null || _a === void 0 ? void 0 : _a.data;
28690
- return Object.assign(Object.assign({}, pinnedPost), { pinnedBy,
28691
- get post() {
28692
- if (!(postCached === null || postCached === void 0 ? void 0 : postCached.data))
28693
- return;
28694
- return postLinkedObject(postCached.data);
28534
+ get createdBy() {
28535
+ const cacheData = pullFromCache(['user', 'get', invitation.inviterUserPublicId]);
28536
+ if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
28537
+ return userLinkedObject(cacheData.data);
28538
+ return undefined;
28695
28539
  },
28696
28540
  get target() {
28697
- const pinTarget = pullFromCache([
28698
- 'pinTarget',
28699
- 'get',
28700
- postCached === null || postCached === void 0 ? void 0 : postCached.data.targetId,
28701
- ]);
28702
- if (!(pinTarget === null || pinTarget === void 0 ? void 0 : pinTarget.data))
28703
- return;
28704
- return pinTarget === null || pinTarget === void 0 ? void 0 : pinTarget.data;
28705
- } });
28706
- };
28707
-
28708
- const notificationTrayLinkedObject = (noti) => {
28709
- return Object.assign(Object.assign({}, noti), { isSeen: noti.lastSeenAt > noti.lastOccurredAt, isRecent: new Date(noti.lastOccurredAt).getTime() >= Date.now() - WEEK, users: noti.actors
28710
- .map(({ publicId }) => pullFromCache(['user', 'get', publicId]))
28711
- .filter(isNonNullable)
28712
- .map(({ data }) => data)
28713
- .map(user => userLinkedObject(user)) });
28714
- };
28715
-
28716
- /*
28717
- * verifies membership status
28718
- */
28719
- function isMember(membership) {
28720
- return membership !== 'none';
28721
- }
28722
- /*
28723
- * checks if currently logged in user is part of the community
28724
- */
28725
- function isCurrentUserPartOfCommunity(c, m) {
28726
- const { userId } = getActiveUser();
28727
- return c.communityId === m.communityId && m.userId === userId;
28728
- }
28729
- /*
28730
- * For mqtt events server will not send user specific data as it's broadcasted
28731
- * to multiple users and it also does not include communityUser
28732
- *
28733
- * Client SDK needs to check for the existing isJoined field in cache data before calculating.
28734
- * Althought this can be calculated, it's not scalable.
28735
- */
28736
- function updateMembershipStatus(communities, communityUsers) {
28737
- return communities.map(c => {
28738
- const cachedCommunity = pullFromCache([
28739
- 'community',
28740
- 'get',
28741
- c.communityId,
28742
- ]);
28743
- if ((cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data) && (cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data.hasOwnProperty('isJoined'))) {
28744
- return Object.assign(Object.assign({}, cachedCommunity.data), c);
28745
- }
28746
- const isJoined = communityUsers.some(m => isCurrentUserPartOfCommunity(c, m) && isMember(m.communityMembership));
28747
- return Object.assign(Object.assign({}, c), { isJoined });
28748
- });
28749
- }
28750
-
28751
- const getMatchPostSetting = (value) => {
28752
- var _a;
28753
- return (_a = Object.keys(CommunityPostSettingMaps).find(key => value.needApprovalOnPostCreation ===
28754
- CommunityPostSettingMaps[key].needApprovalOnPostCreation &&
28755
- value.onlyAdminCanPost === CommunityPostSettingMaps[key].onlyAdminCanPost)) !== null && _a !== void 0 ? _a : DefaultCommunityPostSetting;
28756
- };
28757
- function addPostSetting({ communities }) {
28758
- return communities.map((_a) => {
28759
- var { needApprovalOnPostCreation, onlyAdminCanPost } = _a, restCommunityPayload = __rest(_a, ["needApprovalOnPostCreation", "onlyAdminCanPost"]);
28760
- return (Object.assign({ postSetting: getMatchPostSetting({
28761
- needApprovalOnPostCreation,
28762
- onlyAdminCanPost,
28763
- }) }, restCommunityPayload));
28764
- });
28765
- }
28766
- const prepareCommunityPayload = (rawPayload) => {
28767
- const communitiesWithPostSetting = addPostSetting({ communities: rawPayload.communities });
28768
- // Convert users to internal format
28769
- const internalUsers = rawPayload.users.map(convertRawUserToInternalUser);
28770
- // map users with community
28771
- const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
28772
- const user = internalUsers.find(user => user.userId === communityUser.userId);
28773
- return Object.assign(Object.assign({}, communityUser), { user });
28774
- });
28775
- const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
28776
- return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser), communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
28777
- };
28778
- const prepareCommunityJoinRequestPayload = (rawPayload) => {
28779
- const mappedJoinRequests = rawPayload.joinRequests.map(joinRequest => {
28780
- return Object.assign(Object.assign({}, joinRequest), { joinRequestId: joinRequest._id });
28781
- });
28782
- const users = rawPayload.users.map(convertRawUserToInternalUser);
28783
- return Object.assign(Object.assign({}, rawPayload), { joinRequests: mappedJoinRequests, users });
28784
- };
28785
- const prepareCommunityMembershipPayload = (rawPayload) => {
28786
- const communitiesWithPostSetting = addPostSetting({ communities: rawPayload.communities });
28787
- // map users with community
28788
- const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
28789
- const user = rawPayload.users.find(user => user.userId === communityUser.userId);
28790
- return Object.assign(Object.assign({}, communityUser), { user });
28791
- });
28792
- const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
28793
- return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
28794
- };
28795
- const prepareCommunityRequest = (params) => {
28796
- const { postSetting = undefined, storySetting } = params, restParam = __rest(params, ["postSetting", "storySetting"]);
28797
- return Object.assign(Object.assign(Object.assign({}, restParam), (postSetting ? CommunityPostSettingMaps[postSetting] : undefined)), {
28798
- // Convert story setting to the actual value. (Allow by default)
28799
- allowCommentInStory: typeof (storySetting === null || storySetting === void 0 ? void 0 : storySetting.enableComment) === 'boolean' ? storySetting.enableComment : true });
28800
- };
28801
- const prepareSemanticSearchCommunityPayload = (_a) => {
28802
- var communityPayload = __rest(_a, ["searchResult"]);
28803
- const processedCommunityPayload = prepareCommunityPayload(communityPayload);
28804
- return Object.assign({}, processedCommunityPayload);
28805
- };
28806
-
28807
- /* begin_public_function
28808
- id: joinRequest.approve
28809
- */
28810
- /**
28811
- * ```js
28812
- * import { joinRequest } from '@amityco/ts-sdk'
28813
- * const isAccepted = await joinRequest.approve()
28814
- * ```
28815
- *
28816
- * Accepts a {@link Amity.JoinRequest} object
28817
- *
28818
- * @param joinRequest the {@link Amity.JoinRequest} to accept
28819
- * @returns A success boolean if the {@link Amity.JoinRequest} was accepted
28820
- *
28821
- * @category Join Request API
28822
- * @async
28823
- */
28824
- const approveJoinRequest = async (joinRequest) => {
28825
- var _a;
28826
- const client = getActiveClient();
28827
- client.log('joinRequest/approveJoinRequest', joinRequest.joinRequestId);
28828
- const { data } = await client.http.post(`/api/v4/communities/${joinRequest.targetId}/join/approve`, {
28829
- userId: joinRequest.requestorInternalId,
28830
- });
28831
- const joinRequestCache = (_a = pullFromCache([
28832
- 'joinRequest',
28833
- 'get',
28834
- joinRequest.joinRequestId,
28835
- ])) === null || _a === void 0 ? void 0 : _a.data;
28836
- if (joinRequestCache) {
28837
- upsertInCache(['joinRequest', 'get', joinRequest.joinRequestId], {
28838
- status: "approved" /* JoinRequestStatusEnum.Approved */,
28839
- });
28840
- fireEvent('local.joinRequest.updated', [joinRequestCache]);
28841
- }
28842
- return data.success;
28843
- };
28844
- /* end_public_function */
28845
-
28846
- /* begin_public_function
28847
- id: joinRequest.cancel
28848
- */
28849
- /**
28850
- * ```js
28851
- * import { joinRequest } from '@amityco/ts-sdk'
28852
- * const isCanceled = await joinRequest.cancel()
28853
- * ```
28854
- *
28855
- * Cancels a {@link Amity.JoinRequest} object
28856
- *
28857
- * @param joinRequest the {@link Amity.JoinRequest} to cancel
28858
- * @returns A success boolean if the {@link Amity.JoinRequest} was canceled
28859
- *
28860
- * @category Join Request API
28861
- * @async
28862
- */
28863
- const cancelJoinRequest = async (joinRequest) => {
28864
- var _a;
28865
- const client = getActiveClient();
28866
- client.log('joinRequest/cancelJoinRequest', joinRequest.joinRequestId);
28867
- const { data } = await client.http.delete(`/api/v4/communities/${joinRequest.targetId}/join`);
28868
- const joinRequestCache = (_a = pullFromCache([
28869
- 'joinRequest',
28870
- 'get',
28871
- joinRequest.joinRequestId,
28872
- ])) === null || _a === void 0 ? void 0 : _a.data;
28873
- if (joinRequestCache) {
28874
- upsertInCache(['joinRequest', 'get', joinRequest.joinRequestId], {
28875
- status: "cancelled" /* JoinRequestStatusEnum.Cancelled */,
28876
- });
28877
- fireEvent('local.joinRequest.deleted', [joinRequestCache]);
28878
- }
28879
- return data.success;
28880
- };
28881
- /* end_public_function */
28882
-
28883
- /* begin_public_function
28884
- id: joinRequest.reject
28885
- */
28886
- /**
28887
- * ```js
28888
- * import { joinRequest } from '@amityco/ts-sdk'
28889
- * const isRejected = await joinRequest.reject()
28890
- * ```
28891
- *
28892
- * Rejects a {@link Amity.JoinRequest} object
28893
- *
28894
- * @param joinRequest the {@link Amity.JoinRequest} to reject
28895
- * @returns A success boolean if the {@link Amity.JoinRequest} was rejected
28896
- *
28897
- * @category Join Request API
28898
- * @async
28899
- */
28900
- const rejectJoinRequest = async (joinRequest) => {
28901
- var _a;
28902
- const client = getActiveClient();
28903
- client.log('joinRequest/rejectJoinRequest', joinRequest.joinRequestId);
28904
- const { data } = await client.http.post(`/api/v4/communities/${joinRequest.targetId}/join/reject`, {
28905
- userId: joinRequest.requestorInternalId,
28906
- });
28907
- const joinRequestCache = (_a = pullFromCache([
28908
- 'joinRequest',
28909
- 'get',
28910
- joinRequest.joinRequestId,
28911
- ])) === null || _a === void 0 ? void 0 : _a.data;
28912
- if (joinRequestCache) {
28913
- upsertInCache(['joinRequest', 'get', joinRequest.joinRequestId], {
28914
- status: "rejected" /* JoinRequestStatusEnum.Rejected */,
28915
- });
28916
- fireEvent('local.joinRequest.updated', [joinRequestCache]);
28917
- }
28918
- return data.success;
28919
- };
28920
- /* end_public_function */
28921
-
28922
- const joinRequestLinkedObject = (joinRequest) => {
28923
- return Object.assign(Object.assign({}, joinRequest), { get user() {
28924
- var _a;
28925
- const user = (_a = pullFromCache([
28926
- 'user',
28927
- 'get',
28928
- joinRequest.requestorPublicId,
28929
- ])) === null || _a === void 0 ? void 0 : _a.data;
28930
- if (!user)
28541
+ if (invitation.targetType === 'community') {
28542
+ const cacheData = pullFromCache([
28543
+ 'community',
28544
+ 'get',
28545
+ invitation.targetId,
28546
+ ]);
28547
+ if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
28548
+ return cacheData.data;
28931
28549
  return undefined;
28932
- return userLinkedObject(user);
28933
- }, cancel: async () => {
28934
- await cancelJoinRequest(joinRequest);
28935
- }, approve: async () => {
28936
- await approveJoinRequest(joinRequest);
28550
+ }
28551
+ return undefined;
28552
+ }, accept: async () => {
28553
+ await acceptInvitation$1(invitation._id);
28937
28554
  }, reject: async () => {
28938
- await rejectJoinRequest(joinRequest);
28555
+ await rejectInvitation(invitation._id);
28939
28556
  } });
28940
28557
  };
28941
28558
 
28942
- /* begin_public_function
28943
- id: community.getMyJoinRequest
28944
- */
28945
- /**
28946
- * ```js
28947
- * import { community } from '@amityco/ts-sdk'
28948
- * const isJoined = await community.getMyJoinRequest('foobar')
28949
- * ```
28950
- *
28951
- * Joins a {@link Amity.Community} object
28952
- *
28953
- * @param communityId the {@link Amity.Community} to join
28954
- * @returns A success boolean if the {@link Amity.Community} was joined
28955
- *
28956
- * @category Community API
28957
- * @async
28958
- */
28959
- const getMyJoinRequest = async (communityId) => {
28960
- const client = getActiveClient();
28961
- client.log('community/myJoinRequest', communityId);
28962
- const { data: payload } = await client.http.get(`/api/v4/communities/${communityId}/join/me`);
28963
- const data = prepareCommunityJoinRequestPayload(payload);
28964
- const cachedAt = client.cache && Date.now();
28965
- if (client.cache)
28966
- ingestInCache(data, { cachedAt });
28967
- return {
28968
- data: data.joinRequests[0] ? joinRequestLinkedObject(data.joinRequests[0]) : undefined,
28969
- cachedAt,
28970
- };
28971
- };
28972
- /* end_public_function */
28973
-
28974
- /* begin_public_function
28975
- id: community.join
28976
- */
28977
- /**
28978
- * ```js
28979
- * import { community } from '@amityco/ts-sdk'
28980
- * const isJoined = await community.join('foobar')
28981
- * ```
28982
- *
28983
- * Joins a {@link Amity.Community} object
28984
- *
28985
- * @param communityId the {@link Amity.Community} to join
28986
- * @returns A status join result
28987
- *
28988
- * @category Community API
28989
- * @async
28990
- */
28991
- const joinRequest = async (communityId) => {
28992
- var _a;
28993
- const client = getActiveClient();
28994
- client.log('community/joinRequest', communityId);
28995
- const { data: payload } = await client.http.post(`/api/v4/communities/${communityId}/join`);
28996
- const data = prepareCommunityJoinRequestPayload(payload);
28997
- const cachedAt = client.cache && Date.now();
28998
- if (client.cache)
28999
- ingestInCache(data, { cachedAt });
29000
- const status = data.joinRequests[0].status === "approved" /* JoinRequestStatusEnum.Approved */
29001
- ? "success" /* JoinResultStatusEnum.Success */
29002
- : "pending" /* JoinResultStatusEnum.Pending */;
29003
- if (status === "success" /* JoinResultStatusEnum.Success */ && client.cache) {
29004
- const community = (_a = pullFromCache(['community', 'get', communityId])) === null || _a === void 0 ? void 0 : _a.data;
29005
- if (community) {
29006
- const updatedCommunity = Object.assign(Object.assign({}, community), { isJoined: true });
29007
- upsertInCache(['community', 'get', communityId], updatedCommunity);
29008
- }
29009
- }
29010
- fireEvent('v4.local.community.joined', data.joinRequests);
29011
- return status === "success" /* JoinResultStatusEnum.Success */
29012
- ? { status }
29013
- : { status, request: joinRequestLinkedObject(data.joinRequests[0]) };
29014
- };
29015
- /* end_public_function */
29016
-
29017
- /**
29018
- * TODO: handle cache receive cache option, and cache policy
29019
- * TODO: check if querybyIds is supported
29020
- */
29021
- class JoinRequestsPaginationController extends PaginationController {
28559
+ class InvitationsPaginationController extends PaginationController {
29022
28560
  async getRequest(queryParams, token) {
29023
- const { limit = 20, communityId } = queryParams, params = __rest(queryParams, ["limit", "communityId"]);
28561
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
29024
28562
  const options = token ? { token } : { limit };
29025
- const { data: queryResponse } = await this.http.get(`/api/v4/communities/${communityId}/join`, {
29026
- params: Object.assign(Object.assign({}, params), { options }),
29027
- });
29028
- return queryResponse;
28563
+ const { data } = await this.http.get('/api/v1/invitations', { params: Object.assign(Object.assign({}, params), { options }) });
28564
+ return data;
29029
28565
  }
29030
28566
  }
29031
28567
 
29032
- var EnumJoinRequestAction$1;
29033
- (function (EnumJoinRequestAction) {
29034
- EnumJoinRequestAction["OnLocalJoinRequestCreated"] = "OnLocalJoinRequestCreated";
29035
- EnumJoinRequestAction["OnLocalJoinRequestUpdated"] = "OnLocalJoinRequestUpdated";
29036
- EnumJoinRequestAction["OnLocalJoinRequestDeleted"] = "OnLocalJoinRequestDeleted";
29037
- })(EnumJoinRequestAction$1 || (EnumJoinRequestAction$1 = {}));
29038
-
29039
- class JoinRequestsQueryStreamController extends QueryStreamController {
28568
+ class InvitationsQueryStreamController extends QueryStreamController {
29040
28569
  constructor(query, cacheKey, notifyChange, preparePayload) {
29041
28570
  super(query, cacheKey);
29042
28571
  this.notifyChange = notifyChange;
@@ -29054,41 +28583,38 @@ class JoinRequestsQueryStreamController extends QueryStreamController {
29054
28583
  var _a, _b;
29055
28584
  if (refresh) {
29056
28585
  pushToCache(this.cacheKey, {
29057
- data: response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
28586
+ data: response.invitations.map(getResolver('invitation')),
29058
28587
  });
29059
28588
  }
29060
28589
  else {
29061
28590
  const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
29062
- const joinRequests = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
28591
+ const invitations = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
29063
28592
  pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
29064
- ...new Set([
29065
- ...joinRequests,
29066
- ...response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
29067
- ]),
28593
+ ...new Set([...invitations, ...response.invitations.map(getResolver('invitation'))]),
29068
28594
  ] }));
29069
28595
  }
29070
28596
  }
29071
28597
  reactor(action) {
29072
- return (joinRequest) => {
28598
+ return (invitations) => {
29073
28599
  var _a;
29074
28600
  const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
29075
28601
  if (!collection)
29076
28602
  return;
29077
- if (action === EnumJoinRequestAction$1.OnLocalJoinRequestUpdated) {
29078
- const isExist = collection.data.find(id => id === joinRequest[0].joinRequestId);
28603
+ if (action === InvitationActionsEnum.OnLocalInvitationUpdated) {
28604
+ const isExist = collection.data.find(id => id === invitations[0].invitationId);
29079
28605
  if (!isExist)
29080
28606
  return;
29081
28607
  }
29082
- if (action === EnumJoinRequestAction$1.OnLocalJoinRequestCreated) {
28608
+ if (action === InvitationActionsEnum.OnLocalInvitationCreated) {
29083
28609
  collection.data = [
29084
28610
  ...new Set([
29085
- ...joinRequest.map(joinRequest => joinRequest.joinRequestId),
28611
+ ...invitations.map(invitation => invitation.invitationId),
29086
28612
  ...collection.data,
29087
28613
  ]),
29088
28614
  ];
29089
28615
  }
29090
- if (action === EnumJoinRequestAction$1.OnLocalJoinRequestDeleted) {
29091
- collection.data = collection.data.filter(id => id !== joinRequest[0].joinRequestId);
28616
+ if (action === InvitationActionsEnum.OnLocalInvitationDeleted) {
28617
+ collection.data = collection.data.filter(id => id !== invitations[0].invitationId);
29092
28618
  }
29093
28619
  pushToCache(this.cacheKey, collection);
29094
28620
  this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
@@ -29101,23 +28627,23 @@ class JoinRequestsQueryStreamController extends QueryStreamController {
29101
28627
 
29102
28628
  /**
29103
28629
  * ```js
29104
- * import { onJoinRequestCreated } from '@amityco/ts-sdk'
29105
- * const dispose = onJoinRequestCreated(data => {
28630
+ * import { onLocalInvitationCreated } from '@amityco/ts-sdk'
28631
+ * const dispose = onLocalInvitationCreated(data => {
29106
28632
  * // ...
29107
28633
  * })
29108
28634
  * ```
29109
28635
  *
29110
- * Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
28636
+ * Fired when an {@link Amity.InvitationPayload} has been created
29111
28637
  *
29112
28638
  * @param callback The function to call when the event was fired
29113
28639
  * @returns an {@link Amity.Unsubscriber} function to stop listening
29114
28640
  *
29115
- * @category JoinRequest Events
28641
+ * @category Invitation Events
29116
28642
  */
29117
- const onJoinRequestCreated = (callback) => {
28643
+ const onLocalInvitationCreated = (callback) => {
29118
28644
  const client = getActiveClient();
29119
28645
  const disposers = [
29120
- createEventSubscriber(client, 'onJoinRequestCreated', 'local.joinRequest.created', payload => callback(payload)),
28646
+ createEventSubscriber(client, 'onLocalInvitationCreated', 'local.invitation.created', payload => callback(payload)),
29121
28647
  ];
29122
28648
  return () => {
29123
28649
  disposers.forEach(fn => fn());
@@ -29126,23 +28652,23 @@ const onJoinRequestCreated = (callback) => {
29126
28652
 
29127
28653
  /**
29128
28654
  * ```js
29129
- * import { onJoinRequestUpdated } from '@amityco/ts-sdk'
29130
- * const dispose = onJoinRequestUpdated(data => {
28655
+ * import { onLocalInvitationUpdated } from '@amityco/ts-sdk'
28656
+ * const dispose = onLocalInvitationUpdated(data => {
29131
28657
  * // ...
29132
28658
  * })
29133
28659
  * ```
29134
28660
  *
29135
- * Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
28661
+ * Fired when an {@link Amity.InvitationPayload} has been updated
29136
28662
  *
29137
28663
  * @param callback The function to call when the event was fired
29138
28664
  * @returns an {@link Amity.Unsubscriber} function to stop listening
29139
28665
  *
29140
- * @category JoinRequest Events
28666
+ * @category Invitation Events
29141
28667
  */
29142
- const onJoinRequestUpdated = (callback) => {
28668
+ const onLocalInvitationUpdated = (callback) => {
29143
28669
  const client = getActiveClient();
29144
28670
  const disposers = [
29145
- createEventSubscriber(client, 'onJoinRequestUpdated', 'local.joinRequest.updated', payload => callback(payload)),
28671
+ createEventSubscriber(client, 'onLocalInvitationUpdated', 'local.invitation.updated', payload => callback(payload)),
29146
28672
  ];
29147
28673
  return () => {
29148
28674
  disposers.forEach(fn => fn());
@@ -29151,37 +28677,37 @@ const onJoinRequestUpdated = (callback) => {
29151
28677
 
29152
28678
  /**
29153
28679
  * ```js
29154
- * import { onJoinRequestDeleted } from '@amityco/ts-sdk'
29155
- * const dispose = onJoinRequestDeleted(data => {
28680
+ * import { onLocalInvitationCanceled } from '@amityco/ts-sdk'
28681
+ * const dispose = onLocalInvitationCanceled(data => {
29156
28682
  * // ...
29157
28683
  * })
29158
28684
  * ```
29159
28685
  *
29160
- * Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
28686
+ * Fired when an {@link Amity.InvitationPayload} has been deleted
29161
28687
  *
29162
28688
  * @param callback The function to call when the event was fired
29163
28689
  * @returns an {@link Amity.Unsubscriber} function to stop listening
29164
28690
  *
29165
- * @category JoinRequest Events
28691
+ * @category Invitation Events
29166
28692
  */
29167
- const onJoinRequestDeleted = (callback) => {
28693
+ const onLocalInvitationCanceled = (callback) => {
29168
28694
  const client = getActiveClient();
29169
28695
  const disposers = [
29170
- createEventSubscriber(client, 'onJoinRequestDeleted', 'local.joinRequest.deleted', payload => callback(payload)),
28696
+ createEventSubscriber(client, 'onLocalInvitationCanceled', 'local.invitation.canceled', payload => callback(payload)),
29171
28697
  ];
29172
28698
  return () => {
29173
28699
  disposers.forEach(fn => fn());
29174
28700
  };
29175
28701
  };
29176
28702
 
29177
- class JoinRequestsLiveCollectionController extends LiveCollectionController {
28703
+ class InvitationsLiveCollectionController extends LiveCollectionController {
29178
28704
  constructor(query, callback) {
29179
28705
  const queryStreamId = hash(query);
29180
- const cacheKey = ['joinRequest', 'collection', queryStreamId];
29181
- const paginationController = new JoinRequestsPaginationController(query);
28706
+ const cacheKey = ['invitation', 'collection', queryStreamId];
28707
+ const paginationController = new InvitationsPaginationController(query);
29182
28708
  super(paginationController, queryStreamId, cacheKey, callback);
29183
28709
  this.query = query;
29184
- this.queryStreamController = new JoinRequestsQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityJoinRequestPayload);
28710
+ this.queryStreamController = new InvitationsQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareInvitationPayload);
29185
28711
  this.callback = callback.bind(this);
29186
28712
  this.loadPage({ initial: true });
29187
28713
  }
@@ -29199,26 +28725,33 @@ class JoinRequestsLiveCollectionController extends LiveCollectionController {
29199
28725
  await this.queryStreamController.saveToMainDB(queryPayload);
29200
28726
  }
29201
28727
  persistQueryStream({ response, direction, refresh, }) {
29202
- const joinRequestResponse = response;
29203
- this.queryStreamController.appendToQueryStream(joinRequestResponse, direction, refresh);
28728
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
29204
28729
  }
29205
28730
  startSubscription() {
29206
28731
  return this.queryStreamController.subscribeRTE([
29207
- { fn: onJoinRequestCreated, action: EnumJoinRequestAction$1.OnLocalJoinRequestCreated },
29208
- { fn: onJoinRequestUpdated, action: EnumJoinRequestAction$1.OnLocalJoinRequestUpdated },
29209
- { fn: onJoinRequestDeleted, action: EnumJoinRequestAction$1.OnLocalJoinRequestDeleted },
28732
+ {
28733
+ fn: onLocalInvitationCreated,
28734
+ action: InvitationActionsEnum.OnLocalInvitationCreated,
28735
+ },
28736
+ {
28737
+ fn: onLocalInvitationUpdated,
28738
+ action: InvitationActionsEnum.OnLocalInvitationUpdated,
28739
+ },
28740
+ {
28741
+ fn: onLocalInvitationCanceled,
28742
+ action: InvitationActionsEnum.OnLocalInvitationCanceled,
28743
+ },
29210
28744
  ]);
29211
28745
  }
29212
28746
  notifyChange({ origin, loading, error }) {
29213
- var _a;
28747
+ var _a, _b;
29214
28748
  const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
29215
28749
  if (!collection)
29216
28750
  return;
29217
- const data = this.applyFilter(collection.data
29218
- .map(id => pullFromCache(['joinRequest', 'get', id]))
28751
+ const data = this.applyFilter((_b = collection.data
28752
+ .map(id => pullFromCache(['invitation', 'get', id]))
29219
28753
  .filter(isNonNullable)
29220
- .map(({ data }) => data)
29221
- .map(joinRequestLinkedObject));
28754
+ .map(({ data }) => invitationLinkedObject(data))) !== null && _b !== void 0 ? _b : []);
29222
28755
  if (!this.shouldNotify(data) && origin === 'event')
29223
28756
  return;
29224
28757
  this.callback({
@@ -29230,9 +28763,18 @@ class JoinRequestsLiveCollectionController extends LiveCollectionController {
29230
28763
  });
29231
28764
  }
29232
28765
  applyFilter(data) {
29233
- let joinRequest = data;
29234
- if (this.query.status) {
29235
- joinRequest = joinRequest.filter(joinRequest => joinRequest.status === this.query.status);
28766
+ let invitations = data;
28767
+ if (this.query.targetId) {
28768
+ invitations = invitations.filter(invitation => invitation.targetId === this.query.targetId);
28769
+ }
28770
+ if (this.query.statuses) {
28771
+ invitations = invitations.filter(invitation => { var _a; return (_a = this.query.statuses) === null || _a === void 0 ? void 0 : _a.includes(invitation.status); });
28772
+ }
28773
+ if (this.query.targetType) {
28774
+ invitations = invitations.filter(invitation => invitation.targetType === this.query.targetType);
28775
+ }
28776
+ if (this.query.type) {
28777
+ invitations = invitations.filter(invitation => invitation.type === this.query.type);
29236
28778
  }
29237
28779
  const sortFn = (() => {
29238
28780
  switch (this.query.sortBy) {
@@ -29244,242 +28786,859 @@ class JoinRequestsLiveCollectionController extends LiveCollectionController {
29244
28786
  return sortByLastCreated;
29245
28787
  }
29246
28788
  })();
29247
- joinRequest = joinRequest.sort(sortFn);
29248
- return joinRequest;
28789
+ invitations = invitations.sort(sortFn);
28790
+ return invitations;
29249
28791
  }
29250
28792
  }
29251
28793
 
29252
28794
  /**
29253
- * Get Join Requests
28795
+ * Get invitations
29254
28796
  *
29255
28797
  * @param params the query parameters
29256
- * @param callback the callback to be called when the join request are updated
29257
- * @returns joinRequests
28798
+ * @param callback the callback to be called when the invitations are updated
28799
+ * @returns invitations
29258
28800
  *
29259
- * @category joinRequest Live Collection
28801
+ * @category Invitation Live Collection
29260
28802
  *
29261
28803
  */
29262
- const getJoinRequests = (params, callback, config) => {
28804
+ const getInvitations$1 = (params, callback, config) => {
29263
28805
  const { log, cache } = getActiveClient();
29264
28806
  if (!cache) {
29265
28807
  console.log(ENABLE_CACHE_MESSAGE);
29266
28808
  }
29267
28809
  const timestamp = Date.now();
29268
- log(`getJoinRequests: (tmpid: ${timestamp}) > listen`);
29269
- const joinRequestLiveCollection = new JoinRequestsLiveCollectionController(params, callback);
29270
- const disposers = joinRequestLiveCollection.startSubscription();
29271
- const cacheKey = joinRequestLiveCollection.getCacheKey();
28810
+ log(`getInvitations: (tmpid: ${timestamp}) > listen`);
28811
+ const invitationsLiveCollection = new InvitationsLiveCollectionController(params, callback);
28812
+ const disposers = invitationsLiveCollection.startSubscription();
28813
+ const cacheKey = invitationsLiveCollection.getCacheKey();
29272
28814
  disposers.push(() => {
29273
28815
  dropFromCache(cacheKey);
29274
28816
  });
29275
- return () => {
29276
- log(`getJoinRequests (tmpid: ${timestamp}) > dispose`);
29277
- disposers.forEach(fn => fn());
29278
- };
28817
+ return () => {
28818
+ log(`getInvitations (tmpid: ${timestamp}) > dispose`);
28819
+ disposers.forEach(fn => fn());
28820
+ };
28821
+ };
28822
+
28823
+ const prepareMyInvitationsPayload = (rawPayload) => {
28824
+ return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser), invitations: rawPayload.invitations.map(convertRawInvitationToInternalInvitation) });
28825
+ };
28826
+
28827
+ /* begin_public_function
28828
+ id: invitation.get
28829
+ */
28830
+ /**
28831
+ * ```js
28832
+ * import { getInvitation } from '@amityco/ts-sdk'
28833
+ * const { invitation } = await getInvitation(targetType, targetId)
28834
+ * ```
28835
+ *
28836
+ * Get a {@link Amity.Invitation} object
28837
+ *
28838
+ * @param targetType The type of the target of the {@link Amity.Invitation}
28839
+ * @param targetId The ID of the target of the {@link Amity.Invitation}
28840
+ * @returns A {@link Amity.Invitation} object
28841
+ *
28842
+ * @category Invitation API
28843
+ * @async
28844
+ */
28845
+ const getInvitation = async (params) => {
28846
+ const client = getActiveClient();
28847
+ client.log('invitation/getInvitation', params.targetType, params.targetId, params.type);
28848
+ const { data: payload } = await client.http.get(`/api/v1/invitations/me`, { params });
28849
+ const data = prepareMyInvitationsPayload(payload);
28850
+ const cachedAt = client.cache && Date.now();
28851
+ if (client.cache)
28852
+ ingestInCache(data, { cachedAt });
28853
+ return {
28854
+ data: data.invitations[0] ? invitationLinkedObject(data.invitations[0]) : undefined,
28855
+ cachedAt,
28856
+ };
28857
+ };
28858
+ /* end_public_function */
28859
+
28860
+ const roomLinkedObject = (room) => {
28861
+ return Object.assign(Object.assign({}, room), { get moderation() {
28862
+ var _a;
28863
+ return (_a = pullFromCache(['roomModeration', 'get', room.roomId])) === null || _a === void 0 ? void 0 : _a.data;
28864
+ },
28865
+ get post() {
28866
+ var _a;
28867
+ if (room.referenceType !== 'post')
28868
+ return;
28869
+ return (_a = pullFromCache(['post', 'get', room.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
28870
+ },
28871
+ get community() {
28872
+ var _a;
28873
+ if (room.targetType !== 'community')
28874
+ return;
28875
+ return (_a = pullFromCache(['community', 'get', room.targetId])) === null || _a === void 0 ? void 0 : _a.data;
28876
+ },
28877
+ get user() {
28878
+ var _a;
28879
+ const user = (_a = pullFromCache(['user', 'get', room.createdBy])) === null || _a === void 0 ? void 0 : _a.data;
28880
+ return user ? userLinkedObject(user) : user;
28881
+ },
28882
+ get childRooms() {
28883
+ if (!room.childRoomIds || room.childRoomIds.length === 0)
28884
+ return [];
28885
+ return room.childRoomIds
28886
+ .map(id => {
28887
+ var _a;
28888
+ const roomCache = (_a = pullFromCache(['room', 'get', id])) === null || _a === void 0 ? void 0 : _a.data;
28889
+ if (!roomCache)
28890
+ return undefined;
28891
+ return roomLinkedObject(roomCache);
28892
+ })
28893
+ .filter(isNonNullable);
28894
+ }, participants: room.participants.map(participant => (Object.assign(Object.assign({}, participant), { get user() {
28895
+ var _a;
28896
+ const user = (_a = pullFromCache(['user', 'get', participant.userId])) === null || _a === void 0 ? void 0 : _a.data;
28897
+ return user ? userLinkedObject(user) : user;
28898
+ } }))), getLiveChat: () => getLiveChat(room), createInvitation: (userId) => createInvitations({
28899
+ type: "livestreamCohostInvite" /* InvitationTypeEnum.LivestreamCohostInvite */,
28900
+ targetType: 'room',
28901
+ targetId: room.roomId,
28902
+ userIds: [userId],
28903
+ }), getInvitations: (params, callback) => getInvitations$1(Object.assign(Object.assign({}, params), { targetId: room.roomId, targetType: 'room', type: "livestreamCohostInvite" /* InvitationTypeEnum.LivestreamCohostInvite */ }), callback), getMyInvitation: async () => {
28904
+ const { data } = await getInvitation({
28905
+ targetId: room.roomId,
28906
+ targetType: 'room',
28907
+ type: "livestreamCohostInvite" /* InvitationTypeEnum.LivestreamCohostInvite */,
28908
+ });
28909
+ return data;
28910
+ } });
28911
+ };
28912
+
28913
+ const postLinkedObject = (post) => {
28914
+ return shallowClone(post, {
28915
+ childrenPosts: post.children
28916
+ .map(childPost => { var _a; return (_a = pullFromCache(['post', 'get', childPost])) === null || _a === void 0 ? void 0 : _a.data; })
28917
+ .filter(isNonNullable)
28918
+ .map(postLinkedObject),
28919
+ analytics: {
28920
+ markAsViewed: () => {
28921
+ const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
28922
+ analyticsEngineInstance.markPostAsViewed(post.postId);
28923
+ },
28924
+ },
28925
+ get latestComments() {
28926
+ if (!post.comments)
28927
+ return [];
28928
+ return (post.comments
28929
+ .map(commentId => {
28930
+ var _a;
28931
+ const commentCached = (_a = pullFromCache([
28932
+ 'comment',
28933
+ 'get',
28934
+ commentId,
28935
+ ])) === null || _a === void 0 ? void 0 : _a.data;
28936
+ if (!commentCached)
28937
+ return null;
28938
+ return commentLinkedObject(commentCached);
28939
+ })
28940
+ .filter(Boolean) || []);
28941
+ },
28942
+ get creator() {
28943
+ const cacheData = pullFromCache(['user', 'get', post.postedUserId]);
28944
+ if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
28945
+ return;
28946
+ return userLinkedObject(cacheData.data);
28947
+ },
28948
+ getImageInfo() {
28949
+ var _a, _b;
28950
+ return isAmityImagePost(post)
28951
+ ? (_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
28952
+ : undefined;
28953
+ },
28954
+ getVideoInfo() {
28955
+ var _a, _b, _c;
28956
+ return isAmityVideoPost(post)
28957
+ ? (_c = pullFromCache(['file', 'get', (_b = (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.videoFileId) === null || _b === void 0 ? void 0 : _b.original])) === null || _c === void 0 ? void 0 : _c.data
28958
+ : undefined;
28959
+ },
28960
+ getVideoThumbnailInfo() {
28961
+ var _a, _b;
28962
+ return isAmityVideoPost(post)
28963
+ ? (_b = pullFromCache(['file', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.thumbnailFileId])) === null || _b === void 0 ? void 0 : _b.data
28964
+ : undefined;
28965
+ },
28966
+ getFileInfo() {
28967
+ var _a, _b;
28968
+ return isAmityFilePost(post)
28969
+ ? (_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
28970
+ : undefined;
28971
+ },
28972
+ getLivestreamInfo() {
28973
+ var _a, _b;
28974
+ if (!isAmityLivestreamPost(post))
28975
+ return;
28976
+ const cache = (_b = pullFromCache([
28977
+ 'stream',
28978
+ 'get',
28979
+ (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.streamId,
28980
+ ])) === null || _b === void 0 ? void 0 : _b.data;
28981
+ if (!cache)
28982
+ return;
28983
+ return streamLinkedObject(cache);
28984
+ },
28985
+ getPollInfo() {
28986
+ var _a, _b;
28987
+ if (!isAmityPollPost(post))
28988
+ return;
28989
+ const cache = (_b = pullFromCache(['poll', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.pollId])) === null || _b === void 0 ? void 0 : _b.data;
28990
+ if (!cache)
28991
+ return;
28992
+ return cache;
28993
+ },
28994
+ getClipInfo() {
28995
+ var _a, _b;
28996
+ return isAmityClipPost(post)
28997
+ ? (_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
28998
+ : undefined;
28999
+ },
29000
+ getAudioInfo() {
29001
+ var _a, _b;
29002
+ return isAmityAudioPost(post)
29003
+ ? (_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
29004
+ : undefined;
29005
+ },
29006
+ getRoomInfo() {
29007
+ var _a, _b;
29008
+ if (!isAmityRoomPost(post))
29009
+ return;
29010
+ 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;
29011
+ return room ? roomLinkedObject(room) : undefined;
29012
+ },
29013
+ });
29014
+ };
29015
+
29016
+ /** @hidden */
29017
+ const dispatchReactable = (referenceType, model) => {
29018
+ if (referenceType === 'message')
29019
+ // @ts-ignore: refactor later
29020
+ fireEvent('local.message.updated', { messages: [model] });
29021
+ else if (referenceType === 'post')
29022
+ // @ts-ignore: refactor later
29023
+ fireEvent('post.updated', { posts: [model] });
29024
+ else if (referenceType === 'comment')
29025
+ // @ts-ignore: refactor later
29026
+ fireEvent('comment.updated', { comments: [model] });
29027
+ else if (referenceType === 'story')
29028
+ // Need to provide all data same StoryPayload from BE
29029
+ fireEvent('story.updated', {
29030
+ categories: [],
29031
+ comments: [],
29032
+ communities: [],
29033
+ communityUsers: [],
29034
+ files: [],
29035
+ users: [],
29036
+ stories: [model],
29037
+ });
29038
+ };
29039
+
29040
+ const addReaction$1 = async (referenceType, referenceId, reactionName, referenceVersion) => {
29041
+ var _a, _b, _c;
29042
+ const client = getActiveClient();
29043
+ client.log('reaction/createReaction', {
29044
+ referenceId,
29045
+ referenceType,
29046
+ reactionName,
29047
+ });
29048
+ if (!['post', 'comment', 'story', 'message'].includes(referenceType))
29049
+ throw new ASCApiError('The reference type is not valid. It should be one of post, comment, story, or message', 400000 /* Amity.ServerError.BAD_REQUEST */, "error" /* Amity.ErrorLevel.ERROR */);
29050
+ const { data } = await client.http.post('/api/v2/reactions', {
29051
+ referenceId,
29052
+ referenceType,
29053
+ reactionName,
29054
+ referenceVersion,
29055
+ });
29056
+ if (client.cache) {
29057
+ const model = pullFromCache([
29058
+ referenceType,
29059
+ 'get',
29060
+ referenceId,
29061
+ ]);
29062
+ if (!model || ((_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName)))
29063
+ return true;
29064
+ const updatedModel = Object.assign(Object.assign({}, model.data), { reactionsCount: model.data.reactionsCount + 1, myReactions: [...((_b = model.data.myReactions) !== null && _b !== void 0 ? _b : []), reactionName], reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: ((_c = model.data.reactions[reactionName]) !== null && _c !== void 0 ? _c : 0) + 1 }), updatedAt: new Date().toISOString() });
29065
+ if (referenceType === 'comment') {
29066
+ fireEvent('local.comment.addReaction', {
29067
+ comment: updatedModel,
29068
+ reactor: {
29069
+ userId: client.userId,
29070
+ reactionName,
29071
+ reactionId: data.addedId,
29072
+ },
29073
+ });
29074
+ return true;
29075
+ }
29076
+ if (referenceType === 'post') {
29077
+ fireEvent('local.post.addReaction', {
29078
+ post: updatedModel,
29079
+ reactor: {
29080
+ userId: client.userId,
29081
+ reactionName,
29082
+ reactionId: data.addedId,
29083
+ },
29084
+ });
29085
+ return true;
29086
+ }
29087
+ if (referenceType === 'story') {
29088
+ fireEvent('local.story.reactionAdded', {
29089
+ story: updatedModel,
29090
+ reactor: {
29091
+ userId: client.userId,
29092
+ reactionName,
29093
+ reactionId: data.addedId,
29094
+ },
29095
+ });
29096
+ return true;
29097
+ }
29098
+ }
29099
+ return true;
29100
+ };
29101
+ addReaction$1.optimistically = (referenceType, referenceId, reactionName) => {
29102
+ var _a, _b, _c, _d, _e;
29103
+ const client = getActiveClient();
29104
+ client.log('reaction/createReaction.optimistically', {
29105
+ referenceId,
29106
+ referenceType,
29107
+ reactionName,
29108
+ });
29109
+ if (!client.cache)
29110
+ return;
29111
+ const model = pullFromCache([
29112
+ referenceType,
29113
+ 'get',
29114
+ referenceId,
29115
+ ]);
29116
+ if (!(model === null || model === void 0 ? void 0 : model.data) || ((_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName)))
29117
+ return;
29118
+ const reaction = Object.assign(Object.assign({}, model.data), { reactionsCount: model.data.reactionsCount + 1, myReactions: [...((_b = model.data.myReactions) !== null && _b !== void 0 ? _b : []), reactionName], reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: ((_c = model.data.reactions[reactionName]) !== null && _c !== void 0 ? _c : 0) + 1 }) });
29119
+ upsertInCache([referenceType, 'get', referenceId], reaction, {
29120
+ cachedAt: UNSYNCED_OBJECT_CACHED_AT_VALUE,
29121
+ });
29122
+ dispatchReactable(referenceType, reaction);
29123
+ return (_e = (_d = reaction === null || reaction === void 0 ? void 0 : reaction.myReactions) === null || _d === void 0 ? void 0 : _d.includes(reactionName)) !== null && _e !== void 0 ? _e : false;
29124
+ };
29125
+
29126
+ const removeReaction$1 = async (referenceType, referenceId, reactionName, referenceVersion) => {
29127
+ var _a, _b;
29128
+ const client = getActiveClient();
29129
+ client.log('reaction/removeReaction', {
29130
+ referenceId,
29131
+ referenceType,
29132
+ reactionName,
29133
+ });
29134
+ if (!['post', 'comment', 'story', 'message'].includes(referenceType))
29135
+ throw new ASCApiError('The reference type is not valid. It should be one of post, comment, story, or message', 400000 /* Amity.ServerError.BAD_REQUEST */, "error" /* Amity.ErrorLevel.ERROR */);
29136
+ const { data } = await client.http.delete(`/api/v2/reactions`, {
29137
+ data: {
29138
+ referenceId,
29139
+ referenceType,
29140
+ reactionName,
29141
+ referenceVersion,
29142
+ },
29143
+ });
29144
+ if (client.cache) {
29145
+ const model = pullFromCache([
29146
+ referenceType,
29147
+ 'get',
29148
+ referenceId,
29149
+ ]);
29150
+ if (!model)
29151
+ return true;
29152
+ const updatedModel = Object.assign(Object.assign({}, model.data), { reactionsCount: Math.max(0, model.data.reactionsCount - 1), myReactions: ((_a = model.data.myReactions) !== null && _a !== void 0 ? _a : []).filter(item => item !== reactionName), reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: Math.max(0, ((_b = model.data.reactions[reactionName]) !== null && _b !== void 0 ? _b : 0) - 1) }), updatedAt: new Date().toISOString() });
29153
+ if (referenceType === 'comment') {
29154
+ fireEvent('local.comment.removeReaction', {
29155
+ comment: updatedModel,
29156
+ reactor: {
29157
+ reactionId: data.removedId,
29158
+ reactionName,
29159
+ userId: client.userId,
29160
+ },
29161
+ });
29162
+ return true;
29163
+ }
29164
+ if (referenceType === 'post') {
29165
+ fireEvent('local.post.removeReaction', {
29166
+ post: updatedModel,
29167
+ reactor: {
29168
+ reactionId: data.removedId,
29169
+ reactionName,
29170
+ userId: client.userId,
29171
+ },
29172
+ });
29173
+ return true;
29174
+ }
29175
+ if (referenceType === 'story') {
29176
+ fireEvent('local.story.reactionAdded', {
29177
+ story: updatedModel,
29178
+ reactor: {
29179
+ userId: client.userId,
29180
+ reactionName,
29181
+ reactionId: data.removedId,
29182
+ },
29183
+ });
29184
+ return true;
29185
+ }
29186
+ }
29187
+ return true;
29188
+ };
29189
+
29190
+ const addReactionToMessage = (reactionName, message) => {
29191
+ const isMessageV3 = message.publicId !== message.messageId;
29192
+ return addReaction$1('message', isMessageV3 ? message.publicId : message.messageId, reactionName, isMessageV3 ? 3 : 5);
29193
+ };
29194
+
29195
+ const getCachedMarker = (message) => {
29196
+ var _a, _b;
29197
+ const key = {
29198
+ creatorId: 'creatorPrivateId' in message ? message.creatorPrivateId : message.creatorId,
29199
+ feedId: (_a = message.messageFeedId) !== null && _a !== void 0 ? _a : message.subChannelId,
29200
+ contentId: message.messageId,
29201
+ };
29202
+ return (_b = pullFromCache([
29203
+ 'messageMarker',
29204
+ 'get',
29205
+ getResolver('messageMarker')(key),
29206
+ ])) === null || _b === void 0 ? void 0 : _b.data;
29207
+ };
29208
+ const getMessageReadCount = (message, marker) => {
29209
+ var _a;
29210
+ // Look in the marker param first
29211
+ return (_a = marker !== null && marker !== void 0 ? marker :
29212
+ // If the marker param is not set, look in the cache
29213
+ getCachedMarker(message)) !== null && _a !== void 0 ? _a : { readCount: 0, deliveredCount: 0 };
29214
+ }; // and if not found in cache use default value `0`
29215
+
29216
+ const removeReactionToMessage = (reactionName, message) => {
29217
+ const isMessageV3 = message.publicId !== message.messageId;
29218
+ return removeReaction$1('message', isMessageV3 ? message.publicId : message.messageId, reactionName, isMessageV3 ? 3 : 5);
29219
+ };
29220
+
29221
+ const messageLinkedObject = (message) => {
29222
+ const rest = __rest(message, ["creatorPrivateId"]);
29223
+ return Object.assign(Object.assign({}, rest), { get readCount() {
29224
+ return getMessageReadCount(message).readCount;
29225
+ },
29226
+ get deliveredCount() {
29227
+ return getMessageReadCount(message).deliveredCount;
29228
+ },
29229
+ get creator() {
29230
+ var _a;
29231
+ return (_a = pullFromCache(['user', 'get', message.creatorId])) === null || _a === void 0 ? void 0 : _a.data;
29232
+ }, markRead: () => markReadMessage(message), addReaction: (reactionName) => addReactionToMessage(reactionName, message), removeReaction: (reactionName) => removeReactionToMessage(reactionName, message) });
29233
+ };
29234
+
29235
+ const reactorLinkedObject = (reactor) => {
29236
+ return Object.assign(Object.assign({}, reactor), { get user() {
29237
+ var _a;
29238
+ const user = (_a = pullFromCache(['user', 'get', reactor.userId])) === null || _a === void 0 ? void 0 : _a.data;
29239
+ if (!user)
29240
+ return undefined;
29241
+ return userLinkedObject(user);
29242
+ } });
29243
+ };
29244
+
29245
+ const adLinkedObject = (ad) => {
29246
+ const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
29247
+ const { image9_16: image916, image1_1: image11 } = ad, restAds = __rest(ad, ["image9_16", "image1_1"]);
29248
+ return Object.assign(Object.assign({}, restAds), { analytics: {
29249
+ markAsSeen: (placement) => {
29250
+ analyticsEngineInstance.markAdAsViewed(ad, placement);
29251
+ },
29252
+ markLinkAsClicked: (placement) => {
29253
+ analyticsEngineInstance.markAdAsClicked(ad, placement);
29254
+ },
29255
+ }, get advertiser() {
29256
+ var _a, _b;
29257
+ const advertiserData = (_a = pullFromCache([
29258
+ 'advertiser',
29259
+ 'get',
29260
+ ad.advertiserId,
29261
+ ])) === null || _a === void 0 ? void 0 : _a.data;
29262
+ if (!advertiserData)
29263
+ return;
29264
+ const avatarFile = (_b = pullFromCache([
29265
+ 'file',
29266
+ 'get',
29267
+ advertiserData.avatarFileId,
29268
+ ])) === null || _b === void 0 ? void 0 : _b.data;
29269
+ return Object.assign(Object.assign({}, advertiserData), { avatar: avatarFile });
29270
+ },
29271
+ get image1_1() {
29272
+ const cacheData = pullFromCache(['file', 'get', image11]);
29273
+ if (!cacheData)
29274
+ return undefined;
29275
+ return cacheData.data || undefined;
29276
+ },
29277
+ get image9_16() {
29278
+ const cacheData = pullFromCache(['file', 'get', image916]);
29279
+ if (!cacheData)
29280
+ return undefined;
29281
+ return cacheData.data || undefined;
29282
+ } });
29283
+ };
29284
+
29285
+ const pinnedPostLinkedObject = (pinnedPost) => {
29286
+ var _a;
29287
+ const postCached = pullFromCache(['post', 'get', pinnedPost.referenceId]);
29288
+ const pinnedBy = (_a = queryCache(['user', 'get']).find(cache => {
29289
+ var _a;
29290
+ return ((_a = cache.data) === null || _a === void 0 ? void 0 : _a.userInternalId) === pinnedPost.pinnedBy;
29291
+ })) === null || _a === void 0 ? void 0 : _a.data;
29292
+ return Object.assign(Object.assign({}, pinnedPost), { pinnedBy,
29293
+ get post() {
29294
+ if (!(postCached === null || postCached === void 0 ? void 0 : postCached.data))
29295
+ return;
29296
+ return postLinkedObject(postCached.data);
29297
+ },
29298
+ get target() {
29299
+ const pinTarget = pullFromCache([
29300
+ 'pinTarget',
29301
+ 'get',
29302
+ postCached === null || postCached === void 0 ? void 0 : postCached.data.targetId,
29303
+ ]);
29304
+ if (!(pinTarget === null || pinTarget === void 0 ? void 0 : pinTarget.data))
29305
+ return;
29306
+ return pinTarget === null || pinTarget === void 0 ? void 0 : pinTarget.data;
29307
+ } });
29308
+ };
29309
+
29310
+ const notificationTrayLinkedObject = (noti) => {
29311
+ return Object.assign(Object.assign({}, noti), { isSeen: noti.lastSeenAt > noti.lastOccurredAt, isRecent: new Date(noti.lastOccurredAt).getTime() >= Date.now() - WEEK, users: noti.actors
29312
+ .map(({ publicId }) => pullFromCache(['user', 'get', publicId]))
29313
+ .filter(isNonNullable)
29314
+ .map(({ data }) => data)
29315
+ .map(user => userLinkedObject(user)) });
29316
+ };
29317
+
29318
+ /*
29319
+ * verifies membership status
29320
+ */
29321
+ function isMember(membership) {
29322
+ return membership !== 'none';
29323
+ }
29324
+ /*
29325
+ * checks if currently logged in user is part of the community
29326
+ */
29327
+ function isCurrentUserPartOfCommunity(c, m) {
29328
+ const { userId } = getActiveUser();
29329
+ return c.communityId === m.communityId && m.userId === userId;
29330
+ }
29331
+ /*
29332
+ * For mqtt events server will not send user specific data as it's broadcasted
29333
+ * to multiple users and it also does not include communityUser
29334
+ *
29335
+ * Client SDK needs to check for the existing isJoined field in cache data before calculating.
29336
+ * Althought this can be calculated, it's not scalable.
29337
+ */
29338
+ function updateMembershipStatus(communities, communityUsers) {
29339
+ return communities.map(c => {
29340
+ const cachedCommunity = pullFromCache([
29341
+ 'community',
29342
+ 'get',
29343
+ c.communityId,
29344
+ ]);
29345
+ if ((cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data) && (cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data.hasOwnProperty('isJoined'))) {
29346
+ return Object.assign(Object.assign({}, cachedCommunity.data), c);
29347
+ }
29348
+ const isJoined = communityUsers.some(m => isCurrentUserPartOfCommunity(c, m) && isMember(m.communityMembership));
29349
+ return Object.assign(Object.assign({}, c), { isJoined });
29350
+ });
29351
+ }
29352
+
29353
+ const getMatchPostSetting = (value) => {
29354
+ var _a;
29355
+ return (_a = Object.keys(CommunityPostSettingMaps).find(key => value.needApprovalOnPostCreation ===
29356
+ CommunityPostSettingMaps[key].needApprovalOnPostCreation &&
29357
+ value.onlyAdminCanPost === CommunityPostSettingMaps[key].onlyAdminCanPost)) !== null && _a !== void 0 ? _a : DefaultCommunityPostSetting;
29358
+ };
29359
+ function addPostSetting({ communities }) {
29360
+ return communities.map((_a) => {
29361
+ var { needApprovalOnPostCreation, onlyAdminCanPost } = _a, restCommunityPayload = __rest(_a, ["needApprovalOnPostCreation", "onlyAdminCanPost"]);
29362
+ return (Object.assign({ postSetting: getMatchPostSetting({
29363
+ needApprovalOnPostCreation,
29364
+ onlyAdminCanPost,
29365
+ }) }, restCommunityPayload));
29366
+ });
29367
+ }
29368
+ const prepareCommunityPayload = (rawPayload) => {
29369
+ const communitiesWithPostSetting = addPostSetting({ communities: rawPayload.communities });
29370
+ // Convert users to internal format
29371
+ const internalUsers = rawPayload.users.map(convertRawUserToInternalUser);
29372
+ // map users with community
29373
+ const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
29374
+ const user = internalUsers.find(user => user.userId === communityUser.userId);
29375
+ return Object.assign(Object.assign({}, communityUser), { user });
29376
+ });
29377
+ const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
29378
+ return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser), communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
29379
+ };
29380
+ const prepareCommunityJoinRequestPayload = (rawPayload) => {
29381
+ const mappedJoinRequests = rawPayload.joinRequests.map(joinRequest => {
29382
+ return Object.assign(Object.assign({}, joinRequest), { joinRequestId: joinRequest._id });
29383
+ });
29384
+ const users = rawPayload.users.map(convertRawUserToInternalUser);
29385
+ return Object.assign(Object.assign({}, rawPayload), { joinRequests: mappedJoinRequests, users });
29279
29386
  };
29280
-
29281
- const convertRawInvitationToInternalInvitation = (rawInvitation) => {
29282
- return Object.assign(Object.assign({}, rawInvitation), { createdById: rawInvitation.createdBy });
29387
+ const prepareCommunityMembershipPayload = (rawPayload) => {
29388
+ const communitiesWithPostSetting = addPostSetting({ communities: rawPayload.communities });
29389
+ // map users with community
29390
+ const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
29391
+ const user = rawPayload.users.find(user => user.userId === communityUser.userId);
29392
+ return Object.assign(Object.assign({}, communityUser), { user });
29393
+ });
29394
+ const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
29395
+ return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
29283
29396
  };
29284
-
29285
- const prepareInvitationPayload = (rawPayload) => {
29286
- return Object.assign(Object.assign({}, rawPayload), { invitations: rawPayload.invitations.map(convertRawInvitationToInternalInvitation), users: rawPayload.users.map(convertRawUserToInternalUser) });
29397
+ const prepareCommunityRequest = (params) => {
29398
+ const { postSetting = undefined, storySetting } = params, restParam = __rest(params, ["postSetting", "storySetting"]);
29399
+ return Object.assign(Object.assign(Object.assign({}, restParam), (postSetting ? CommunityPostSettingMaps[postSetting] : undefined)), {
29400
+ // Convert story setting to the actual value. (Allow by default)
29401
+ allowCommentInStory: typeof (storySetting === null || storySetting === void 0 ? void 0 : storySetting.enableComment) === 'boolean' ? storySetting.enableComment : true });
29402
+ };
29403
+ const prepareSemanticSearchCommunityPayload = (_a) => {
29404
+ var communityPayload = __rest(_a, ["searchResult"]);
29405
+ const processedCommunityPayload = prepareCommunityPayload(communityPayload);
29406
+ return Object.assign({}, processedCommunityPayload);
29287
29407
  };
29288
29408
 
29289
29409
  /* begin_public_function
29290
- id: invitation.createInvitations
29410
+ id: joinRequest.approve
29291
29411
  */
29292
29412
  /**
29293
29413
  * ```js
29294
- * import { createInvitations } from '@amityco/ts-sdk'
29295
- * const created = await createInvitations({
29296
- * type: string,
29297
- * targetType: string,
29298
- * targetId: string,
29299
- * userIds: string[]
29300
- * }))
29414
+ * import { joinRequest } from '@amityco/ts-sdk'
29415
+ * const isAccepted = await joinRequest.approve()
29301
29416
  * ```
29302
29417
  *
29303
- * Creates an {@link Amity.Invitation}
29418
+ * Accepts a {@link Amity.JoinRequest} object
29304
29419
  *
29305
- * @param bundle The data necessary to create a new {@link Amity.Invitation}
29306
- * @returns The newly created {@link Amity.Invitation}
29420
+ * @param joinRequest the {@link Amity.JoinRequest} to accept
29421
+ * @returns A success boolean if the {@link Amity.JoinRequest} was accepted
29307
29422
  *
29308
- * @category Invitation API
29423
+ * @category Join Request API
29309
29424
  * @async
29310
29425
  */
29311
- const createInvitations = async (bundle) => {
29426
+ const approveJoinRequest = async (joinRequest) => {
29427
+ var _a;
29312
29428
  const client = getActiveClient();
29313
- client.log('invitation/createInvitations', bundle);
29314
- const { data: payload } = await client.http.post('/api/v1/invitations', bundle);
29315
- const data = prepareInvitationPayload(payload);
29316
- const cachedAt = client.cache && Date.now();
29317
- if (client.cache)
29318
- ingestInCache(data, { cachedAt });
29319
- fireEvent('local.invitation.created', data.invitations);
29320
- return {
29321
- data: data.invitations,
29322
- cachedAt,
29323
- };
29429
+ client.log('joinRequest/approveJoinRequest', joinRequest.joinRequestId);
29430
+ const { data } = await client.http.post(`/api/v4/communities/${joinRequest.targetId}/join/approve`, {
29431
+ userId: joinRequest.requestorInternalId,
29432
+ });
29433
+ const joinRequestCache = (_a = pullFromCache([
29434
+ 'joinRequest',
29435
+ 'get',
29436
+ joinRequest.joinRequestId,
29437
+ ])) === null || _a === void 0 ? void 0 : _a.data;
29438
+ if (joinRequestCache) {
29439
+ upsertInCache(['joinRequest', 'get', joinRequest.joinRequestId], {
29440
+ status: "approved" /* JoinRequestStatusEnum.Approved */,
29441
+ });
29442
+ fireEvent('local.joinRequest.updated', [joinRequestCache]);
29443
+ }
29444
+ return data.success;
29324
29445
  };
29325
29446
  /* end_public_function */
29326
29447
 
29327
29448
  /* begin_public_function
29328
- id: invitation.accept
29449
+ id: joinRequest.cancel
29329
29450
  */
29330
29451
  /**
29331
29452
  * ```js
29332
- * import { acceptInvitation } from '@amityco/ts-sdk'
29333
- * const isAccepted = await acceptInvitation(invitationId)
29453
+ * import { joinRequest } from '@amityco/ts-sdk'
29454
+ * const isCanceled = await joinRequest.cancel()
29334
29455
  * ```
29335
29456
  *
29336
- * Accepts a {@link Amity.Invitation} object
29457
+ * Cancels a {@link Amity.JoinRequest} object
29337
29458
  *
29338
- * @param invitationId the {@link Amity.Invitation} to accept
29339
- * @returns A success boolean if the {@link Amity.Invitation} was accepted
29459
+ * @param joinRequest the {@link Amity.JoinRequest} to cancel
29460
+ * @returns A success boolean if the {@link Amity.JoinRequest} was canceled
29340
29461
  *
29341
- * @category Invitation API
29462
+ * @category Join Request API
29342
29463
  * @async
29343
29464
  */
29344
- const acceptInvitation = async (invitationId) => {
29465
+ const cancelJoinRequest = async (joinRequest) => {
29345
29466
  var _a;
29346
29467
  const client = getActiveClient();
29347
- client.log('invitation/acceptInvitation', invitationId);
29348
- const { data } = await client.http.post(`/api/v1/invitations/${invitationId}/accept`);
29349
- const invitation = (_a = pullFromCache([
29350
- 'invitation',
29468
+ client.log('joinRequest/cancelJoinRequest', joinRequest.joinRequestId);
29469
+ const { data } = await client.http.delete(`/api/v4/communities/${joinRequest.targetId}/join`);
29470
+ const joinRequestCache = (_a = pullFromCache([
29471
+ 'joinRequest',
29351
29472
  'get',
29352
- invitationId,
29473
+ joinRequest.joinRequestId,
29353
29474
  ])) === null || _a === void 0 ? void 0 : _a.data;
29354
- if (invitation) {
29355
- upsertInCache(['invitation', 'get', invitationId], { status: "approved" /* InvitationStatusEnum.Approved */ });
29356
- fireEvent('local.invitation.updated', [invitation]);
29475
+ if (joinRequestCache) {
29476
+ upsertInCache(['joinRequest', 'get', joinRequest.joinRequestId], {
29477
+ status: "cancelled" /* JoinRequestStatusEnum.Cancelled */,
29478
+ });
29479
+ fireEvent('local.joinRequest.deleted', [joinRequestCache]);
29357
29480
  }
29358
29481
  return data.success;
29359
29482
  };
29360
29483
  /* end_public_function */
29361
29484
 
29362
29485
  /* begin_public_function
29363
- id: invitation.reject
29486
+ id: joinRequest.reject
29364
29487
  */
29365
29488
  /**
29366
29489
  * ```js
29367
- * import { rejectInvitation } from '@amityco/ts-sdk'
29368
- * const isRejected = await rejectInvitation(invitationId)
29490
+ * import { joinRequest } from '@amityco/ts-sdk'
29491
+ * const isRejected = await joinRequest.reject()
29369
29492
  * ```
29370
29493
  *
29371
- * Rejects a {@link Amity.Invitation} object
29494
+ * Rejects a {@link Amity.JoinRequest} object
29372
29495
  *
29373
- * @param invitationId the {@link Amity.Invitation} to reject
29374
- * @returns A success boolean if the {@link Amity.Invitation} was rejected
29496
+ * @param joinRequest the {@link Amity.JoinRequest} to reject
29497
+ * @returns A success boolean if the {@link Amity.JoinRequest} was rejected
29375
29498
  *
29376
- * @category Invitation API
29499
+ * @category Join Request API
29377
29500
  * @async
29378
29501
  */
29379
- const rejectInvitation = async (invitationId) => {
29502
+ const rejectJoinRequest = async (joinRequest) => {
29380
29503
  var _a;
29381
29504
  const client = getActiveClient();
29382
- client.log('invitation/rejectInvitation', invitationId);
29383
- const { data } = await client.http.post(`/api/v1/invitations/${invitationId}/reject`);
29384
- const invitation = (_a = pullFromCache([
29385
- 'invitation',
29505
+ client.log('joinRequest/rejectJoinRequest', joinRequest.joinRequestId);
29506
+ const { data } = await client.http.post(`/api/v4/communities/${joinRequest.targetId}/join/reject`, {
29507
+ userId: joinRequest.requestorInternalId,
29508
+ });
29509
+ const joinRequestCache = (_a = pullFromCache([
29510
+ 'joinRequest',
29386
29511
  'get',
29387
- invitationId,
29512
+ joinRequest.joinRequestId,
29388
29513
  ])) === null || _a === void 0 ? void 0 : _a.data;
29389
- if (invitation) {
29390
- upsertInCache(['invitation', 'get', invitationId], { status: "rejected" /* InvitationStatusEnum.Rejected */ });
29391
- fireEvent('local.invitation.updated', [invitation]);
29514
+ if (joinRequestCache) {
29515
+ upsertInCache(['joinRequest', 'get', joinRequest.joinRequestId], {
29516
+ status: "rejected" /* JoinRequestStatusEnum.Rejected */,
29517
+ });
29518
+ fireEvent('local.joinRequest.updated', [joinRequestCache]);
29392
29519
  }
29393
29520
  return data.success;
29394
29521
  };
29395
29522
  /* end_public_function */
29396
29523
 
29397
- const prepareMyInvitationsPayload = (rawPayload) => {
29398
- return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser), invitations: rawPayload.invitations.map(convertRawInvitationToInternalInvitation) });
29399
- };
29400
-
29401
- const invitationLinkedObject = (invitation) => {
29402
- return Object.assign(Object.assign({}, invitation), { get user() {
29403
- const cacheData = pullFromCache(['user', 'get', invitation.invitedUserPublicId]);
29404
- if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
29405
- return userLinkedObject(cacheData.data);
29406
- return undefined;
29407
- },
29408
- get createdBy() {
29409
- const cacheData = pullFromCache(['user', 'get', invitation.inviterUserPublicId]);
29410
- if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
29411
- return userLinkedObject(cacheData.data);
29412
- return undefined;
29413
- },
29414
- get target() {
29415
- if (invitation.targetType === 'community') {
29416
- const cacheData = pullFromCache([
29417
- 'community',
29418
- 'get',
29419
- invitation.targetId,
29420
- ]);
29421
- if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
29422
- return cacheData.data;
29524
+ const joinRequestLinkedObject = (joinRequest) => {
29525
+ return Object.assign(Object.assign({}, joinRequest), { get user() {
29526
+ var _a;
29527
+ const user = (_a = pullFromCache([
29528
+ 'user',
29529
+ 'get',
29530
+ joinRequest.requestorPublicId,
29531
+ ])) === null || _a === void 0 ? void 0 : _a.data;
29532
+ if (!user)
29423
29533
  return undefined;
29424
- }
29425
- return undefined;
29426
- }, accept: async () => {
29427
- await acceptInvitation(invitation._id);
29534
+ return userLinkedObject(user);
29535
+ }, cancel: async () => {
29536
+ await cancelJoinRequest(joinRequest);
29537
+ }, approve: async () => {
29538
+ await approveJoinRequest(joinRequest);
29428
29539
  }, reject: async () => {
29429
- await rejectInvitation(invitation._id);
29540
+ await rejectJoinRequest(joinRequest);
29430
29541
  } });
29431
29542
  };
29432
29543
 
29433
29544
  /* begin_public_function
29434
- id: invitation.get
29545
+ id: community.getMyJoinRequest
29435
29546
  */
29436
29547
  /**
29437
29548
  * ```js
29438
- * import { getInvitation } from '@amityco/ts-sdk'
29439
- * const { invitation } = await getInvitation(targetType, targetId)
29549
+ * import { community } from '@amityco/ts-sdk'
29550
+ * const isJoined = await community.getMyJoinRequest('foobar')
29440
29551
  * ```
29441
29552
  *
29442
- * Get a {@link Amity.Invitation} object
29553
+ * Joins a {@link Amity.Community} object
29443
29554
  *
29444
- * @param targetType The type of the target of the {@link Amity.Invitation}
29445
- * @param targetId The ID of the target of the {@link Amity.Invitation}
29446
- * @returns A {@link Amity.Invitation} object
29555
+ * @param communityId the {@link Amity.Community} to join
29556
+ * @returns A success boolean if the {@link Amity.Community} was joined
29447
29557
  *
29448
- * @category Invitation API
29558
+ * @category Community API
29449
29559
  * @async
29450
29560
  */
29451
- const getInvitation = async (targetType, targetId) => {
29561
+ const getMyJoinRequest = async (communityId) => {
29452
29562
  const client = getActiveClient();
29453
- client.log('invitation/getInvitation', targetType, targetId);
29454
- const { data: payload } = await client.http.get(`/api/v1/invitations/me`, { params: { targetType, targetId } });
29455
- const data = prepareMyInvitationsPayload(payload);
29563
+ client.log('community/myJoinRequest', communityId);
29564
+ const { data: payload } = await client.http.get(`/api/v4/communities/${communityId}/join/me`);
29565
+ const data = prepareCommunityJoinRequestPayload(payload);
29456
29566
  const cachedAt = client.cache && Date.now();
29457
29567
  if (client.cache)
29458
29568
  ingestInCache(data, { cachedAt });
29459
29569
  return {
29460
- data: data.invitations[0] ? invitationLinkedObject(data.invitations[0]) : undefined,
29570
+ data: data.joinRequests[0] ? joinRequestLinkedObject(data.joinRequests[0]) : undefined,
29461
29571
  cachedAt,
29462
29572
  };
29463
29573
  };
29464
29574
  /* end_public_function */
29465
29575
 
29466
- var InvitationActionsEnum;
29467
- (function (InvitationActionsEnum) {
29468
- InvitationActionsEnum["OnLocalInvitationCreated"] = "onLocalInvitationCreated";
29469
- InvitationActionsEnum["OnLocalInvitationUpdated"] = "onLocalInvitationUpdated";
29470
- InvitationActionsEnum["OnLocalInvitationDeleted"] = "onLocalInvitationDeleted";
29471
- })(InvitationActionsEnum || (InvitationActionsEnum = {}));
29576
+ /* begin_public_function
29577
+ id: community.join
29578
+ */
29579
+ /**
29580
+ * ```js
29581
+ * import { community } from '@amityco/ts-sdk'
29582
+ * const isJoined = await community.join('foobar')
29583
+ * ```
29584
+ *
29585
+ * Joins a {@link Amity.Community} object
29586
+ *
29587
+ * @param communityId the {@link Amity.Community} to join
29588
+ * @returns A status join result
29589
+ *
29590
+ * @category Community API
29591
+ * @async
29592
+ */
29593
+ const joinRequest = async (communityId) => {
29594
+ var _a;
29595
+ const client = getActiveClient();
29596
+ client.log('community/joinRequest', communityId);
29597
+ const { data: payload } = await client.http.post(`/api/v4/communities/${communityId}/join`);
29598
+ const data = prepareCommunityJoinRequestPayload(payload);
29599
+ const cachedAt = client.cache && Date.now();
29600
+ if (client.cache)
29601
+ ingestInCache(data, { cachedAt });
29602
+ const status = data.joinRequests[0].status === "approved" /* JoinRequestStatusEnum.Approved */
29603
+ ? "success" /* JoinResultStatusEnum.Success */
29604
+ : "pending" /* JoinResultStatusEnum.Pending */;
29605
+ if (status === "success" /* JoinResultStatusEnum.Success */ && client.cache) {
29606
+ const community = (_a = pullFromCache(['community', 'get', communityId])) === null || _a === void 0 ? void 0 : _a.data;
29607
+ if (community) {
29608
+ const updatedCommunity = Object.assign(Object.assign({}, community), { isJoined: true });
29609
+ upsertInCache(['community', 'get', communityId], updatedCommunity);
29610
+ }
29611
+ }
29612
+ fireEvent('v4.local.community.joined', data.joinRequests);
29613
+ return status === "success" /* JoinResultStatusEnum.Success */
29614
+ ? { status }
29615
+ : { status, request: joinRequestLinkedObject(data.joinRequests[0]) };
29616
+ };
29617
+ /* end_public_function */
29472
29618
 
29473
- class InvitationsPaginationController extends PaginationController {
29619
+ /**
29620
+ * TODO: handle cache receive cache option, and cache policy
29621
+ * TODO: check if querybyIds is supported
29622
+ */
29623
+ class JoinRequestsPaginationController extends PaginationController {
29474
29624
  async getRequest(queryParams, token) {
29475
- const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
29625
+ const { limit = 20, communityId } = queryParams, params = __rest(queryParams, ["limit", "communityId"]);
29476
29626
  const options = token ? { token } : { limit };
29477
- const { data } = await this.http.get('/api/v1/invitations', { params: Object.assign(Object.assign({}, params), { options }) });
29478
- return data;
29627
+ const { data: queryResponse } = await this.http.get(`/api/v4/communities/${communityId}/join`, {
29628
+ params: Object.assign(Object.assign({}, params), { options }),
29629
+ });
29630
+ return queryResponse;
29479
29631
  }
29480
29632
  }
29481
29633
 
29482
- class InvitationsQueryStreamController extends QueryStreamController {
29634
+ var EnumJoinRequestAction$1;
29635
+ (function (EnumJoinRequestAction) {
29636
+ EnumJoinRequestAction["OnLocalJoinRequestCreated"] = "OnLocalJoinRequestCreated";
29637
+ EnumJoinRequestAction["OnLocalJoinRequestUpdated"] = "OnLocalJoinRequestUpdated";
29638
+ EnumJoinRequestAction["OnLocalJoinRequestDeleted"] = "OnLocalJoinRequestDeleted";
29639
+ })(EnumJoinRequestAction$1 || (EnumJoinRequestAction$1 = {}));
29640
+
29641
+ class JoinRequestsQueryStreamController extends QueryStreamController {
29483
29642
  constructor(query, cacheKey, notifyChange, preparePayload) {
29484
29643
  super(query, cacheKey);
29485
29644
  this.notifyChange = notifyChange;
@@ -29497,38 +29656,41 @@ class InvitationsQueryStreamController extends QueryStreamController {
29497
29656
  var _a, _b;
29498
29657
  if (refresh) {
29499
29658
  pushToCache(this.cacheKey, {
29500
- data: response.invitations.map(getResolver('invitation')),
29659
+ data: response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
29501
29660
  });
29502
29661
  }
29503
29662
  else {
29504
29663
  const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
29505
- const invitations = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
29664
+ const joinRequests = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
29506
29665
  pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
29507
- ...new Set([...invitations, ...response.invitations.map(getResolver('invitation'))]),
29666
+ ...new Set([
29667
+ ...joinRequests,
29668
+ ...response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
29669
+ ]),
29508
29670
  ] }));
29509
29671
  }
29510
29672
  }
29511
29673
  reactor(action) {
29512
- return (invitations) => {
29674
+ return (joinRequest) => {
29513
29675
  var _a;
29514
29676
  const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
29515
29677
  if (!collection)
29516
29678
  return;
29517
- if (action === InvitationActionsEnum.OnLocalInvitationUpdated) {
29518
- const isExist = collection.data.find(id => id === invitations[0].invitationId);
29679
+ if (action === EnumJoinRequestAction$1.OnLocalJoinRequestUpdated) {
29680
+ const isExist = collection.data.find(id => id === joinRequest[0].joinRequestId);
29519
29681
  if (!isExist)
29520
29682
  return;
29521
29683
  }
29522
- if (action === InvitationActionsEnum.OnLocalInvitationCreated) {
29684
+ if (action === EnumJoinRequestAction$1.OnLocalJoinRequestCreated) {
29523
29685
  collection.data = [
29524
29686
  ...new Set([
29525
- ...invitations.map(invitation => invitation.invitationId),
29687
+ ...joinRequest.map(joinRequest => joinRequest.joinRequestId),
29526
29688
  ...collection.data,
29527
29689
  ]),
29528
29690
  ];
29529
29691
  }
29530
- if (action === InvitationActionsEnum.OnLocalInvitationDeleted) {
29531
- collection.data = collection.data.filter(id => id !== invitations[0].invitationId);
29692
+ if (action === EnumJoinRequestAction$1.OnLocalJoinRequestDeleted) {
29693
+ collection.data = collection.data.filter(id => id !== joinRequest[0].joinRequestId);
29532
29694
  }
29533
29695
  pushToCache(this.cacheKey, collection);
29534
29696
  this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
@@ -29541,23 +29703,23 @@ class InvitationsQueryStreamController extends QueryStreamController {
29541
29703
 
29542
29704
  /**
29543
29705
  * ```js
29544
- * import { onLocalInvitationCreated } from '@amityco/ts-sdk'
29545
- * const dispose = onLocalInvitationCreated(data => {
29706
+ * import { onJoinRequestCreated } from '@amityco/ts-sdk'
29707
+ * const dispose = onJoinRequestCreated(data => {
29546
29708
  * // ...
29547
29709
  * })
29548
29710
  * ```
29549
29711
  *
29550
- * Fired when an {@link Amity.InvitationPayload} has been created
29712
+ * Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
29551
29713
  *
29552
29714
  * @param callback The function to call when the event was fired
29553
29715
  * @returns an {@link Amity.Unsubscriber} function to stop listening
29554
29716
  *
29555
- * @category Invitation Events
29717
+ * @category JoinRequest Events
29556
29718
  */
29557
- const onLocalInvitationCreated = (callback) => {
29719
+ const onJoinRequestCreated = (callback) => {
29558
29720
  const client = getActiveClient();
29559
29721
  const disposers = [
29560
- createEventSubscriber(client, 'onLocalInvitationCreated', 'local.invitation.created', payload => callback(payload)),
29722
+ createEventSubscriber(client, 'onJoinRequestCreated', 'local.joinRequest.created', payload => callback(payload)),
29561
29723
  ];
29562
29724
  return () => {
29563
29725
  disposers.forEach(fn => fn());
@@ -29566,23 +29728,23 @@ const onLocalInvitationCreated = (callback) => {
29566
29728
 
29567
29729
  /**
29568
29730
  * ```js
29569
- * import { onLocalInvitationUpdated } from '@amityco/ts-sdk'
29570
- * const dispose = onLocalInvitationUpdated(data => {
29731
+ * import { onJoinRequestUpdated } from '@amityco/ts-sdk'
29732
+ * const dispose = onJoinRequestUpdated(data => {
29571
29733
  * // ...
29572
29734
  * })
29573
29735
  * ```
29574
29736
  *
29575
- * Fired when an {@link Amity.InvitationPayload} has been updated
29737
+ * Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
29576
29738
  *
29577
29739
  * @param callback The function to call when the event was fired
29578
29740
  * @returns an {@link Amity.Unsubscriber} function to stop listening
29579
29741
  *
29580
- * @category Invitation Events
29742
+ * @category JoinRequest Events
29581
29743
  */
29582
- const onLocalInvitationUpdated = (callback) => {
29744
+ const onJoinRequestUpdated = (callback) => {
29583
29745
  const client = getActiveClient();
29584
29746
  const disposers = [
29585
- createEventSubscriber(client, 'onLocalInvitationUpdated', 'local.invitation.updated', payload => callback(payload)),
29747
+ createEventSubscriber(client, 'onJoinRequestUpdated', 'local.joinRequest.updated', payload => callback(payload)),
29586
29748
  ];
29587
29749
  return () => {
29588
29750
  disposers.forEach(fn => fn());
@@ -29591,37 +29753,37 @@ const onLocalInvitationUpdated = (callback) => {
29591
29753
 
29592
29754
  /**
29593
29755
  * ```js
29594
- * import { onLocalInvitationDeleted } from '@amityco/ts-sdk'
29595
- * const dispose = onLocalInvitationDeleted(data => {
29756
+ * import { onJoinRequestDeleted } from '@amityco/ts-sdk'
29757
+ * const dispose = onJoinRequestDeleted(data => {
29596
29758
  * // ...
29597
29759
  * })
29598
29760
  * ```
29599
29761
  *
29600
- * Fired when an {@link Amity.InvitationPayload} has been deleted
29762
+ * Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
29601
29763
  *
29602
29764
  * @param callback The function to call when the event was fired
29603
29765
  * @returns an {@link Amity.Unsubscriber} function to stop listening
29604
29766
  *
29605
- * @category Invitation Events
29767
+ * @category JoinRequest Events
29606
29768
  */
29607
- const onLocalInvitationDeleted = (callback) => {
29769
+ const onJoinRequestDeleted = (callback) => {
29608
29770
  const client = getActiveClient();
29609
29771
  const disposers = [
29610
- createEventSubscriber(client, 'onLocalInvitationDeleted', 'local.invitation.deleted', payload => callback(payload)),
29772
+ createEventSubscriber(client, 'onJoinRequestDeleted', 'local.joinRequest.deleted', payload => callback(payload)),
29611
29773
  ];
29612
29774
  return () => {
29613
29775
  disposers.forEach(fn => fn());
29614
29776
  };
29615
29777
  };
29616
29778
 
29617
- class InvitationsLiveCollectionController extends LiveCollectionController {
29779
+ class JoinRequestsLiveCollectionController extends LiveCollectionController {
29618
29780
  constructor(query, callback) {
29619
29781
  const queryStreamId = hash(query);
29620
- const cacheKey = ['invitation', 'collection', queryStreamId];
29621
- const paginationController = new InvitationsPaginationController(query);
29782
+ const cacheKey = ['joinRequest', 'collection', queryStreamId];
29783
+ const paginationController = new JoinRequestsPaginationController(query);
29622
29784
  super(paginationController, queryStreamId, cacheKey, callback);
29623
29785
  this.query = query;
29624
- this.queryStreamController = new InvitationsQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareInvitationPayload);
29786
+ this.queryStreamController = new JoinRequestsQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityJoinRequestPayload);
29625
29787
  this.callback = callback.bind(this);
29626
29788
  this.loadPage({ initial: true });
29627
29789
  }
@@ -29639,33 +29801,26 @@ class InvitationsLiveCollectionController extends LiveCollectionController {
29639
29801
  await this.queryStreamController.saveToMainDB(queryPayload);
29640
29802
  }
29641
29803
  persistQueryStream({ response, direction, refresh, }) {
29642
- this.queryStreamController.appendToQueryStream(response, direction, refresh);
29804
+ const joinRequestResponse = response;
29805
+ this.queryStreamController.appendToQueryStream(joinRequestResponse, direction, refresh);
29643
29806
  }
29644
29807
  startSubscription() {
29645
29808
  return this.queryStreamController.subscribeRTE([
29646
- {
29647
- fn: onLocalInvitationCreated,
29648
- action: InvitationActionsEnum.OnLocalInvitationCreated,
29649
- },
29650
- {
29651
- fn: onLocalInvitationUpdated,
29652
- action: InvitationActionsEnum.OnLocalInvitationUpdated,
29653
- },
29654
- {
29655
- fn: onLocalInvitationDeleted,
29656
- action: InvitationActionsEnum.OnLocalInvitationDeleted,
29657
- },
29809
+ { fn: onJoinRequestCreated, action: EnumJoinRequestAction$1.OnLocalJoinRequestCreated },
29810
+ { fn: onJoinRequestUpdated, action: EnumJoinRequestAction$1.OnLocalJoinRequestUpdated },
29811
+ { fn: onJoinRequestDeleted, action: EnumJoinRequestAction$1.OnLocalJoinRequestDeleted },
29658
29812
  ]);
29659
29813
  }
29660
29814
  notifyChange({ origin, loading, error }) {
29661
- var _a, _b;
29815
+ var _a;
29662
29816
  const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
29663
29817
  if (!collection)
29664
29818
  return;
29665
- const data = this.applyFilter((_b = collection.data
29666
- .map(id => pullFromCache(['invitation', 'get', id]))
29819
+ const data = this.applyFilter(collection.data
29820
+ .map(id => pullFromCache(['joinRequest', 'get', id]))
29667
29821
  .filter(isNonNullable)
29668
- .map(({ data }) => invitationLinkedObject(data))) !== null && _b !== void 0 ? _b : []);
29822
+ .map(({ data }) => data)
29823
+ .map(joinRequestLinkedObject));
29669
29824
  if (!this.shouldNotify(data) && origin === 'event')
29670
29825
  return;
29671
29826
  this.callback({
@@ -29677,18 +29832,9 @@ class InvitationsLiveCollectionController extends LiveCollectionController {
29677
29832
  });
29678
29833
  }
29679
29834
  applyFilter(data) {
29680
- let invitations = data;
29681
- if (this.query.targetId) {
29682
- invitations = invitations.filter(invitation => invitation.targetId === this.query.targetId);
29683
- }
29684
- if (this.query.statuses) {
29685
- invitations = invitations.filter(invitation => { var _a; return (_a = this.query.statuses) === null || _a === void 0 ? void 0 : _a.includes(invitation.status); });
29686
- }
29687
- if (this.query.targetType) {
29688
- invitations = invitations.filter(invitation => invitation.targetType === this.query.targetType);
29689
- }
29690
- if (this.query.type) {
29691
- invitations = invitations.filter(invitation => invitation.type === this.query.type);
29835
+ let joinRequest = data;
29836
+ if (this.query.status) {
29837
+ joinRequest = joinRequest.filter(joinRequest => joinRequest.status === this.query.status);
29692
29838
  }
29693
29839
  const sortFn = (() => {
29694
29840
  switch (this.query.sortBy) {
@@ -29700,36 +29846,36 @@ class InvitationsLiveCollectionController extends LiveCollectionController {
29700
29846
  return sortByLastCreated;
29701
29847
  }
29702
29848
  })();
29703
- invitations = invitations.sort(sortFn);
29704
- return invitations;
29849
+ joinRequest = joinRequest.sort(sortFn);
29850
+ return joinRequest;
29705
29851
  }
29706
29852
  }
29707
29853
 
29708
29854
  /**
29709
- * Get invitations
29855
+ * Get Join Requests
29710
29856
  *
29711
29857
  * @param params the query parameters
29712
- * @param callback the callback to be called when the invitations are updated
29713
- * @returns invitations
29858
+ * @param callback the callback to be called when the join request are updated
29859
+ * @returns joinRequests
29714
29860
  *
29715
- * @category Invitation Live Collection
29861
+ * @category joinRequest Live Collection
29716
29862
  *
29717
29863
  */
29718
- const getInvitations = (params, callback, config) => {
29864
+ const getJoinRequests = (params, callback, config) => {
29719
29865
  const { log, cache } = getActiveClient();
29720
29866
  if (!cache) {
29721
29867
  console.log(ENABLE_CACHE_MESSAGE);
29722
29868
  }
29723
29869
  const timestamp = Date.now();
29724
- log(`getInvitations: (tmpid: ${timestamp}) > listen`);
29725
- const invitationsLiveCollection = new InvitationsLiveCollectionController(params, callback);
29726
- const disposers = invitationsLiveCollection.startSubscription();
29727
- const cacheKey = invitationsLiveCollection.getCacheKey();
29870
+ log(`getJoinRequests: (tmpid: ${timestamp}) > listen`);
29871
+ const joinRequestLiveCollection = new JoinRequestsLiveCollectionController(params, callback);
29872
+ const disposers = joinRequestLiveCollection.startSubscription();
29873
+ const cacheKey = joinRequestLiveCollection.getCacheKey();
29728
29874
  disposers.push(() => {
29729
29875
  dropFromCache(cacheKey);
29730
29876
  });
29731
29877
  return () => {
29732
- log(`getInvitations (tmpid: ${timestamp}) > dispose`);
29878
+ log(`getJoinRequests (tmpid: ${timestamp}) > dispose`);
29733
29879
  disposers.forEach(fn => fn());
29734
29880
  };
29735
29881
  };
@@ -29753,9 +29899,12 @@ const communityLinkedObject = (community) => {
29753
29899
  userIds,
29754
29900
  });
29755
29901
  }, getMemberInvitations: (params, callback) => {
29756
- return getInvitations(Object.assign(Object.assign({}, params), { targetId: community.communityId, targetType: 'community', type: "communityMemberInvite" /* InvitationTypeEnum.CommunityMemberInvite */ }), callback);
29902
+ return getInvitations$1(Object.assign(Object.assign({}, params), { targetId: community.communityId, targetType: 'community', type: "communityMemberInvite" /* InvitationTypeEnum.CommunityMemberInvite */ }), callback);
29757
29903
  }, getInvitation: async () => {
29758
- const { data } = await getInvitation('community', community.communityId);
29904
+ const { data } = await getInvitation({
29905
+ targetType: 'community',
29906
+ targetId: community.communityId,
29907
+ });
29759
29908
  return data;
29760
29909
  }, join: async () => joinRequest(community.communityId), getJoinRequests: (params, callback) => {
29761
29910
  return getJoinRequests(Object.assign(Object.assign({}, params), { communityId: community.communityId }), callback);
@@ -29765,6 +29914,51 @@ const communityLinkedObject = (community) => {
29765
29914
  } });
29766
29915
  };
29767
29916
 
29917
+ const eventLinkedObject = (event) => {
29918
+ return Object.assign(Object.assign({}, event), { get creator() {
29919
+ const cacheData = pullFromCache(['user', 'get', event.userId]);
29920
+ if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
29921
+ return;
29922
+ return userLinkedObject(cacheData.data);
29923
+ },
29924
+ get discussionCommunity() {
29925
+ if (!event.discussionCommunityId)
29926
+ return;
29927
+ const cacheData = pullFromCache([
29928
+ 'discussionCommunity',
29929
+ 'get',
29930
+ event.discussionCommunityId,
29931
+ ]);
29932
+ if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
29933
+ return;
29934
+ return communityLinkedObject(cacheData.data);
29935
+ },
29936
+ get targetCommunity() {
29937
+ if (!event.originId)
29938
+ return;
29939
+ const cacheData = pullFromCache(['community', 'get', event.originId]);
29940
+ if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
29941
+ return;
29942
+ return communityLinkedObject(cacheData.data);
29943
+ },
29944
+ get coverImage() {
29945
+ if (!event.coverImageFileId)
29946
+ return;
29947
+ const cacheData = pullFromCache(['file', 'get', event.coverImageFileId]);
29948
+ if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
29949
+ return;
29950
+ return cacheData.data;
29951
+ },
29952
+ get liveStream() {
29953
+ if (!event.livestreamId)
29954
+ return;
29955
+ const cacheData = pullFromCache(['stream', 'get', event.livestreamId]);
29956
+ if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
29957
+ return;
29958
+ return cacheData.data;
29959
+ } });
29960
+ };
29961
+
29768
29962
  const LinkedObject = {
29769
29963
  ad: adLinkedObject,
29770
29964
  comment: commentLinkedObject,
@@ -29783,6 +29977,8 @@ const LinkedObject = {
29783
29977
  invitation: invitationLinkedObject,
29784
29978
  joinRequest: joinRequestLinkedObject,
29785
29979
  channelMember: channelMemberLinkedObject,
29980
+ room: roomLinkedObject,
29981
+ event: eventLinkedObject,
29786
29982
  };
29787
29983
 
29788
29984
  /* begin_public_function
@@ -30773,9 +30969,9 @@ var AmityUserSearchMatchType;
30773
30969
  AmityUserSearchMatchType["PARTIAL"] = "partial";
30774
30970
  })(AmityUserSearchMatchType || (AmityUserSearchMatchType = {}));
30775
30971
 
30776
- var index$n = /*#__PURE__*/Object.freeze({
30972
+ var index$p = /*#__PURE__*/Object.freeze({
30777
30973
  __proto__: null,
30778
- Relationship: index$o,
30974
+ Relationship: index$q,
30779
30975
  getUserByIds: getUserByIds,
30780
30976
  updateUser: updateUser,
30781
30977
  flagUser: flagUser,
@@ -31178,7 +31374,7 @@ const uploadAudio = async (formData, onProgress) => {
31178
31374
  };
31179
31375
  /* end_public_function */
31180
31376
 
31181
- var index$m = /*#__PURE__*/Object.freeze({
31377
+ var index$o = /*#__PURE__*/Object.freeze({
31182
31378
  __proto__: null,
31183
31379
  getFile: getFile,
31184
31380
  uploadFile: uploadFile,
@@ -32990,7 +33186,7 @@ const getReactions$1 = (params, callback, config) => {
32990
33186
  };
32991
33187
  /* end_public_function */
32992
33188
 
32993
- var index$l = /*#__PURE__*/Object.freeze({
33189
+ var index$n = /*#__PURE__*/Object.freeze({
32994
33190
  __proto__: null,
32995
33191
  addReaction: addReaction,
32996
33192
  removeReaction: removeReaction,
@@ -34762,7 +34958,7 @@ const getMessages = (params, callback, config) => {
34762
34958
  };
34763
34959
  /* end_public_function */
34764
34960
 
34765
- var index$k = /*#__PURE__*/Object.freeze({
34961
+ var index$m = /*#__PURE__*/Object.freeze({
34766
34962
  __proto__: null,
34767
34963
  createMessage: createMessage,
34768
34964
  updateMessage: updateMessage,
@@ -35288,7 +35484,7 @@ const stopMessageReceiptSync = (subChannelId) => {
35288
35484
  };
35289
35485
  /* end_public_function */
35290
35486
 
35291
- var index$j = /*#__PURE__*/Object.freeze({
35487
+ var index$l = /*#__PURE__*/Object.freeze({
35292
35488
  __proto__: null,
35293
35489
  getSubChannelByIds: getSubChannels$1,
35294
35490
  createSubChannel: createSubChannel,
@@ -36615,7 +36811,7 @@ const searchMembers$1 = (params, callback, config) => {
36615
36811
  };
36616
36812
  /* end_public_function */
36617
36813
 
36618
- var index$i = /*#__PURE__*/Object.freeze({
36814
+ var index$k = /*#__PURE__*/Object.freeze({
36619
36815
  __proto__: null,
36620
36816
  addMembers: addMembers$1,
36621
36817
  removeMembers: removeMembers$1,
@@ -36818,7 +37014,7 @@ const unmuteMembers = async (channelId, userIds) => {
36818
37014
  };
36819
37015
  /* end_public_function */
36820
37016
 
36821
- var index$h = /*#__PURE__*/Object.freeze({
37017
+ var index$j = /*#__PURE__*/Object.freeze({
36822
37018
  __proto__: null,
36823
37019
  addRole: addRole,
36824
37020
  removeRole: removeRole,
@@ -36828,10 +37024,10 @@ var index$h = /*#__PURE__*/Object.freeze({
36828
37024
  unmuteMembers: unmuteMembers
36829
37025
  });
36830
37026
 
36831
- var index$g = /*#__PURE__*/Object.freeze({
37027
+ var index$i = /*#__PURE__*/Object.freeze({
36832
37028
  __proto__: null,
36833
- Membership: index$i,
36834
- Moderation: index$h,
37029
+ Membership: index$k,
37030
+ Moderation: index$j,
36835
37031
  getChannelByIds: getChannelByIds$1,
36836
37032
  createChannel: createChannel,
36837
37033
  updateChannel: updateChannel,
@@ -38234,7 +38430,7 @@ const searchMembers = (params, callback, config) => {
38234
38430
  };
38235
38431
  /* end_public_function */
38236
38432
 
38237
- var index$f = /*#__PURE__*/Object.freeze({
38433
+ var index$h = /*#__PURE__*/Object.freeze({
38238
38434
  __proto__: null,
38239
38435
  addMembers: addMembers,
38240
38436
  removeMembers: removeMembers,
@@ -39485,7 +39681,7 @@ const unbanMembers = async (communityId, userIds) => {
39485
39681
  };
39486
39682
  /* end_public_function */
39487
39683
 
39488
- var index$e = /*#__PURE__*/Object.freeze({
39684
+ var index$g = /*#__PURE__*/Object.freeze({
39489
39685
  __proto__: null,
39490
39686
  addRoles: addRoles,
39491
39687
  removeRoles: removeRoles,
@@ -39493,10 +39689,10 @@ var index$e = /*#__PURE__*/Object.freeze({
39493
39689
  unbanMembers: unbanMembers
39494
39690
  });
39495
39691
 
39496
- var index$d = /*#__PURE__*/Object.freeze({
39692
+ var index$f = /*#__PURE__*/Object.freeze({
39497
39693
  __proto__: null,
39498
- Moderation: index$e,
39499
- Membership: index$f,
39694
+ Moderation: index$g,
39695
+ Membership: index$h,
39500
39696
  getCommunityByIds: getCommunities$1,
39501
39697
  createCommunity: createCommunity,
39502
39698
  updateCommunity: updateCommunity,
@@ -39730,7 +39926,7 @@ const getCategories = (params, callback, config) => {
39730
39926
  };
39731
39927
  /* end_public_function */
39732
39928
 
39733
- var index$c = /*#__PURE__*/Object.freeze({
39929
+ var index$e = /*#__PURE__*/Object.freeze({
39734
39930
  __proto__: null,
39735
39931
  getCategory: getCategory,
39736
39932
  getCategories: getCategories
@@ -40789,7 +40985,7 @@ const getComments = (params, callback, config) => {
40789
40985
  };
40790
40986
  /* end_public_function */
40791
40987
 
40792
- var index$b = /*#__PURE__*/Object.freeze({
40988
+ var index$d = /*#__PURE__*/Object.freeze({
40793
40989
  __proto__: null,
40794
40990
  getCommentByIds: getCommentByIds,
40795
40991
  createComment: createComment,
@@ -41460,7 +41656,7 @@ const getUserFeed = (params, callback, config) => {
41460
41656
  };
41461
41657
  /* end_public_function */
41462
41658
 
41463
- var index$a = /*#__PURE__*/Object.freeze({
41659
+ var index$c = /*#__PURE__*/Object.freeze({
41464
41660
  __proto__: null,
41465
41661
  queryGlobalFeed: queryGlobalFeed,
41466
41662
  getCustomRankingGlobalFeed: getCustomRankingGlobalFeed,
@@ -43141,7 +43337,7 @@ const searchPostsByHashtag = (params, callback, config) => {
43141
43337
  };
43142
43338
  /* end_public_function */
43143
43339
 
43144
- var index$9 = /*#__PURE__*/Object.freeze({
43340
+ var index$b = /*#__PURE__*/Object.freeze({
43145
43341
  __proto__: null,
43146
43342
  getPostByIds: getPostByIds,
43147
43343
  createPost: createPost,
@@ -43749,7 +43945,7 @@ const getStreams = (params, callback, config) => {
43749
43945
  };
43750
43946
  };
43751
43947
 
43752
- var index$8 = /*#__PURE__*/Object.freeze({
43948
+ var index$a = /*#__PURE__*/Object.freeze({
43753
43949
  __proto__: null,
43754
43950
  createStream: createStream,
43755
43951
  updateStream: updateStream,
@@ -43795,7 +43991,7 @@ const createRoom = async (bundle) => {
43795
43991
  ingestInCache(data, { cachedAt });
43796
43992
  const { rooms } = data;
43797
43993
  return {
43798
- data: rooms[0],
43994
+ data: roomLinkedObject(rooms[0]),
43799
43995
  cachedAt,
43800
43996
  };
43801
43997
  };
@@ -43829,7 +44025,7 @@ const updateRoom = async (roomId, bundle) => {
43829
44025
  ingestInCache(data, { cachedAt });
43830
44026
  const { rooms } = data;
43831
44027
  return {
43832
- data: rooms[0],
44028
+ data: roomLinkedObject(rooms[0]),
43833
44029
  cachedAt,
43834
44030
  };
43835
44031
  };
@@ -43894,25 +44090,25 @@ const stopRoom = async (roomId) => {
43894
44090
  /* end_public_function */
43895
44091
 
43896
44092
  /* begin_public_function
43897
- id: room.getToken
44093
+ id: room.getBroadcasterData
43898
44094
  */
43899
44095
  /**
43900
44096
  * ```js
43901
- * import { getRoomToken } from '@amityco/ts-sdk'
43902
- * const token = await getRoomToken('roomId')
44097
+ * import { getBroadcasterData } from '@amityco/ts-sdk'
44098
+ * const token = await getBroadcasterData('roomId')
43903
44099
  * ```
43904
44100
  *
43905
- * Gets an access token for a room
44101
+ * Gets broadcaster data for a room
43906
44102
  *
43907
44103
  * @param roomId The ID of the room to get token for
43908
- * @returns The room access token
44104
+ * @returns The broadcaster data of the room including coHostToken, coHostUrl and direactStreamUrl
43909
44105
  *
43910
44106
  * @category Room API
43911
44107
  * @async
43912
44108
  */
43913
- const getRoomToken = async (roomId) => {
44109
+ const getBroadcasterData = async (roomId) => {
43914
44110
  const client = getActiveClient();
43915
- client.log('room/getRoomToken', { roomId });
44111
+ client.log('room/getBroadcasterData', { roomId });
43916
44112
  const { data } = await client.http.get(`/api/v1/rooms/${roomId}/token`);
43917
44113
  return data;
43918
44114
  };
@@ -43943,6 +44139,62 @@ const getRecordedUrl = async (roomId) => {
43943
44139
  };
43944
44140
  /* end_public_function */
43945
44141
 
44142
+ /* begin_public_function
44143
+ id: room.removeParticipant
44144
+ */
44145
+ /**
44146
+ * ```js
44147
+ * import { removeParticipant } from '@amityco/ts-sdk'
44148
+ * const result = await removeParticipant('roomId', 'participantUserId')
44149
+ * ```
44150
+ *
44151
+ * Removes a participant from an {@link Amity.Room}
44152
+ *
44153
+ * @param roomId The ID of the room to remove participant from
44154
+ * @param participantUserId The ID of the user to remove as participant
44155
+ * @returns Promise that resolves when the participant is removed
44156
+ *
44157
+ * @category Room API
44158
+ * @async
44159
+ */
44160
+ const removeParticipant = async (roomId, participantUserId) => {
44161
+ const client = getActiveClient();
44162
+ client.log('room/removeParticipant', { roomId, participantUserId });
44163
+ await client.http.delete(`/api/v1/rooms/${roomId}/participants/${participantUserId}`);
44164
+ fireEvent('local.room.participantRemoved', {
44165
+ rooms: [{ _id: roomId }],
44166
+ users: [{ _id: participantUserId }],
44167
+ });
44168
+ };
44169
+ /* end_public_function */
44170
+
44171
+ /* begin_public_function
44172
+ id: room.leave
44173
+ */
44174
+ /**
44175
+ * ```js
44176
+ * import { leaveRoom } from '@amityco/ts-sdk'
44177
+ * const result = await leaveRoom('roomId')
44178
+ * ```
44179
+ *
44180
+ * Leaves an {@link Amity.Room}
44181
+ *
44182
+ * @param roomId The ID of the room to leave
44183
+ * @returns Promise that resolves when the user has left the room
44184
+ *
44185
+ * @category Room API
44186
+ * @async
44187
+ */
44188
+ const leaveRoom = async (roomId) => {
44189
+ const client = getActiveClient();
44190
+ client.log('room/leaveRoom', { roomId });
44191
+ await client.http.post(`/api/v1/rooms/${roomId}/leave`);
44192
+ fireEvent('local.room.left', {
44193
+ rooms: [{ _id: roomId }],
44194
+ });
44195
+ };
44196
+ /* end_public_function */
44197
+
43946
44198
  /**
43947
44199
  * ```js
43948
44200
  * import { onRoomStartBroadcasting } from '@amityco/ts-sdk'
@@ -44054,13 +44306,131 @@ const onRoomRecordedAvailable = (callback) => {
44054
44306
  *
44055
44307
  * @category Room Events
44056
44308
  */
44057
- const onRoomParticipantInviting = (callback) => {
44309
+ const onRoomCoHostInvited = (callback) => {
44058
44310
  const client = getActiveClient();
44059
44311
  const filter = (payload) => {
44060
- ingestInCache(payload);
44061
- callback(payload.rooms[0]);
44312
+ const data = prepareMyInvitationsPayload(payload);
44313
+ ingestInCache(data);
44314
+ callback(data.invitations);
44315
+ };
44316
+ return createEventSubscriber(client, 'room/onRoomCoHostInvited', 'room.didCohostInvite', filter);
44317
+ };
44318
+
44319
+ const getRoomById = async (roomId) => {
44320
+ const client = getActiveClient();
44321
+ client.log('room/getRoomById', roomId);
44322
+ // Check if room is in tombstone
44323
+ isInTombstone('room', roomId);
44324
+ let data;
44325
+ try {
44326
+ const response = await client.http.get(`/api/v1/rooms/${roomId}`);
44327
+ data = response.data;
44328
+ }
44329
+ catch (error) {
44330
+ if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
44331
+ pushToTombstone('room', roomId);
44332
+ }
44333
+ throw error;
44334
+ }
44335
+ const cachedAt = client.cache && Date.now();
44336
+ if (client.cache) {
44337
+ ingestInCache(data, { cachedAt });
44338
+ }
44339
+ return {
44340
+ data: data.rooms[0],
44341
+ cachedAt,
44342
+ };
44343
+ };
44344
+ getRoomById.locally = (roomId) => {
44345
+ const client = getActiveClient();
44346
+ client.log('room/getRoomById.locally', roomId);
44347
+ // Check if room is in tombstone
44348
+ isInTombstone('room', roomId);
44349
+ const cachedAt = client.cache && Date.now();
44350
+ const roomCache = pullFromCache(['room', 'get', roomId]);
44351
+ if (!roomCache)
44352
+ return;
44353
+ return {
44354
+ data: roomCache.data,
44355
+ cachedAt,
44356
+ };
44357
+ };
44358
+
44359
+ /**
44360
+ * ```js
44361
+ * import { onRoomCoHostInviteAccepted } from '@amityco/ts-sdk'
44362
+ * const dispose = onRoomCoHostInviteAccepted(room => {
44363
+ * // ...
44364
+ * })
44365
+ * ```
44366
+ *
44367
+ * Fired when a co-host invitation is accepted for a {@link Amity.Room}
44368
+ *
44369
+ * @param callback The function to call when the event was fired
44370
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44371
+ *
44372
+ * @category Room Events
44373
+ */
44374
+ const onRoomCoHostInviteAccepted = (callback) => {
44375
+ const client = getActiveClient();
44376
+ const filter = async (payload) => {
44377
+ var _a;
44378
+ const data = prepareMyInvitationsPayload(payload);
44379
+ await getRoomById((_a = data.invitations) === null || _a === void 0 ? void 0 : _a[0].targetId);
44380
+ ingestInCache(data);
44381
+ callback(data.invitations[0]);
44062
44382
  };
44063
- return createEventSubscriber(client, 'room/onRoomParticipantInviting', 'room.participantInviting', filter);
44383
+ return createEventSubscriber(client, 'room/onRoomCoHostInviteAccepted', 'room.didCohostInviteAccept', filter);
44384
+ };
44385
+
44386
+ /**
44387
+ * ```js
44388
+ * import { onRoomCoHostInviteRejected } from '@amityco/ts-sdk'
44389
+ * const dispose = onRoomCoHostInviteRejected(room => {
44390
+ * // ...
44391
+ * })
44392
+ * ```
44393
+ *
44394
+ * Fired when a co-host invitation is rejected for a {@link Amity.Room}
44395
+ *
44396
+ * @param callback The function to call when the event was fired
44397
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44398
+ *
44399
+ * @category Room Events
44400
+ */
44401
+ const onRoomCoHostInviteRejected = (callback) => {
44402
+ const client = getActiveClient();
44403
+ const filter = (payload) => {
44404
+ const data = prepareMyInvitationsPayload(payload);
44405
+ ingestInCache(data);
44406
+ callback(data.invitations);
44407
+ };
44408
+ return createEventSubscriber(client, 'room/onRoomCoHostInviteRejected', 'room.didCohostInviteReject', filter);
44409
+ };
44410
+
44411
+ /**
44412
+ * ```js
44413
+ * import { onRoomCoHostInviteCanceled } from '@amityco/ts-sdk'
44414
+ * const dispose = onRoomCoHostInviteCanceled(room => {
44415
+ * // ...
44416
+ * })
44417
+ * ```
44418
+ *
44419
+ * Fired when a co-host invitation is canceled for a {@link Amity.Room}
44420
+ *
44421
+ * @param callback The function to call when the event was fired
44422
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44423
+ *
44424
+ * @category Room Events
44425
+ */
44426
+ const onRoomCoHostInviteCanceled = (callback) => {
44427
+ const client = getActiveClient();
44428
+ const filter = (payload) => {
44429
+ const data = prepareMyInvitationsPayload(payload);
44430
+ ingestInCache(data);
44431
+ callback(data.invitations);
44432
+ };
44433
+ return createEventSubscriber(client, 'room/onRoomCoHostInviteCanceled', 'room.didCohostInviteCancel', filter);
44064
44434
  };
44065
44435
 
44066
44436
  /**
@@ -44207,44 +44577,76 @@ const onRoomStopped = (callback) => {
44207
44577
  return createEventSubscriber(client, 'room/onRoomStopped', 'local.room.stopped', filter);
44208
44578
  };
44209
44579
 
44210
- const getRoomById = async (roomId) => {
44580
+ /**
44581
+ * ```js
44582
+ * import { onRoomParticipantRemoved } from '@amityco/ts-sdk'
44583
+ * const dispose = onRoomParticipantRemoved(room => {
44584
+ * // ...
44585
+ * })
44586
+ * ```
44587
+ *
44588
+ * Fired when a participant has been removed from a {@link Amity.Room} locally
44589
+ *
44590
+ * @param callback The function to call when the event was fired
44591
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44592
+ *
44593
+ * @category Room Events
44594
+ */
44595
+ const onRoomParticipantRemoved = (callback) => {
44211
44596
  const client = getActiveClient();
44212
- client.log('room/getRoomById', roomId);
44213
- // Check if room is in tombstone
44214
- isInTombstone('room', roomId);
44215
- let data;
44216
- try {
44217
- const response = await client.http.get(`/api/v1/rooms/${roomId}`);
44218
- data = response.data;
44219
- }
44220
- catch (error) {
44221
- if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
44222
- pushToTombstone('room', roomId);
44223
- }
44224
- throw error;
44225
- }
44226
- const cachedAt = client.cache && Date.now();
44227
- if (client.cache) {
44228
- ingestInCache(data, { cachedAt });
44229
- }
44230
- return {
44231
- data: data.rooms[0],
44232
- cachedAt,
44597
+ const filter = (payload) => {
44598
+ ingestInCache(payload);
44599
+ callback(payload.rooms[0]);
44233
44600
  };
44601
+ return createEventSubscriber(client, 'room/onRoomParticipantRemoved', 'room.participantRemoved', filter);
44234
44602
  };
44235
- getRoomById.locally = (roomId) => {
44603
+
44604
+ /**
44605
+ * ```js
44606
+ * import { onRoomLeft } from '@amityco/ts-sdk'
44607
+ * const dispose = onRoomLeft(room => {
44608
+ * // ...
44609
+ * })
44610
+ * ```
44611
+ *
44612
+ * Fired when a user has left a {@link Amity.Room} locally
44613
+ *
44614
+ * @param callback The function to call when the event was fired
44615
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44616
+ *
44617
+ * @category Room Events
44618
+ */
44619
+ const onRoomLeft = (callback) => {
44236
44620
  const client = getActiveClient();
44237
- client.log('room/getRoomById.locally', roomId);
44238
- // Check if room is in tombstone
44239
- isInTombstone('room', roomId);
44240
- const cachedAt = client.cache && Date.now();
44241
- const roomCache = pullFromCache(['room', 'get', roomId]);
44242
- if (!roomCache)
44243
- return;
44244
- return {
44245
- data: roomCache.data,
44246
- cachedAt,
44621
+ const filter = (payload) => {
44622
+ ingestInCache(payload);
44623
+ callback(payload.rooms[0]);
44624
+ };
44625
+ return createEventSubscriber(client, 'room/onRoomLeft', 'local.room.left', filter);
44626
+ };
44627
+
44628
+ /**
44629
+ * ```js
44630
+ * import { onRoomParticipantRemoved } from '@amityco/ts-sdk'
44631
+ * const dispose = onRoomParticipantRemoved(room => {
44632
+ * // ...
44633
+ * })
44634
+ * ```
44635
+ *
44636
+ * Fired when a participant has been removed from a {@link Amity.Room} locally
44637
+ *
44638
+ * @param callback The function to call when the event was fired
44639
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44640
+ *
44641
+ * @category Room Events
44642
+ */
44643
+ const onRoomParticipantRemovedLocal = (callback) => {
44644
+ const client = getActiveClient();
44645
+ const filter = (payload) => {
44646
+ ingestInCache(payload);
44647
+ callback(payload.rooms[0]);
44247
44648
  };
44649
+ return createEventSubscriber(client, 'room/onRoomParticipantRemoved', 'local.room.participantRemoved', filter);
44248
44650
  };
44249
44651
 
44250
44652
  const getRoom = (roomId, callback) => {
@@ -44254,7 +44656,18 @@ const getRoom = (roomId, callback) => {
44254
44656
  onRoomStartBroadcasting,
44255
44657
  onRoomWaitingReconnect,
44256
44658
  onRoomRecordedAvailable,
44257
- ]);
44659
+ onRoomParticipantJoined,
44660
+ onRoomParticipantLeft,
44661
+ onRoomParticipantRemoved,
44662
+ onRoomParticipantRemovedLocal,
44663
+ convertEventPayload(onRoomCoHostInviteAccepted, 'targetId', 'room'),
44664
+ ], {
44665
+ callbackDataSelector: (data) => {
44666
+ if (!data)
44667
+ return data;
44668
+ return LinkedObject.room(data);
44669
+ },
44670
+ });
44258
44671
  };
44259
44672
 
44260
44673
  class RoomPaginationController extends PaginationController {
@@ -44467,29 +44880,330 @@ const getRooms = (params, callback, config) => {
44467
44880
  };
44468
44881
  /* end_public_function */
44469
44882
 
44470
- var index$7 = /*#__PURE__*/Object.freeze({
44883
+ var index$9 = /*#__PURE__*/Object.freeze({
44471
44884
  __proto__: null,
44472
44885
  createRoom: createRoom,
44473
44886
  updateRoom: updateRoom,
44474
44887
  deleteRoom: deleteRoom,
44475
44888
  stopRoom: stopRoom,
44476
- getRoomToken: getRoomToken,
44889
+ getBroadcasterData: getBroadcasterData,
44477
44890
  getRecordedUrl: getRecordedUrl,
44891
+ removeParticipant: removeParticipant,
44892
+ leaveRoom: leaveRoom,
44478
44893
  onRoomStartBroadcasting: onRoomStartBroadcasting,
44479
44894
  onRoomWaitingReconnect: onRoomWaitingReconnect,
44480
44895
  onRoomEndBroadcasting: onRoomEndBroadcasting,
44481
44896
  onRoomRecordedAvailable: onRoomRecordedAvailable,
44482
- onRoomParticipantInviting: onRoomParticipantInviting,
44897
+ onRoomCoHostInvited: onRoomCoHostInvited,
44898
+ onRoomCoHostInviteAccepted: onRoomCoHostInviteAccepted,
44899
+ onRoomCoHostInviteRejected: onRoomCoHostInviteRejected,
44900
+ onRoomCoHostInviteCanceled: onRoomCoHostInviteCanceled,
44483
44901
  onRoomParticipantJoined: onRoomParticipantJoined,
44484
44902
  onRoomParticipantLeft: onRoomParticipantLeft,
44485
44903
  onRoomCreated: onRoomCreated,
44486
44904
  onRoomUpdated: onRoomUpdated,
44487
44905
  onRoomDeleted: onRoomDeleted,
44488
44906
  onRoomStopped: onRoomStopped,
44907
+ onRoomParticipantRemoved: onRoomParticipantRemoved,
44908
+ onRoomLeft: onRoomLeft,
44489
44909
  getRoom: getRoom,
44490
44910
  getRooms: getRooms
44491
44911
  });
44492
44912
 
44913
+ /* begin_public_function
44914
+ id: roomPresence.getRoomOnlineUsers
44915
+ */
44916
+ /**
44917
+ * ```js
44918
+ * import { getRoomOnlineUsers } from '@amityco/ts-sdk'
44919
+ * const result = await getRoomOnlineUsers('roomId')
44920
+ * ```
44921
+ *
44922
+ * Retrieves the list of users currently online in a specific room.
44923
+ * This function fetches all users who are actively watching or present in the room,
44924
+ * handling pagination automatically for large numbers of users.
44925
+ *
44926
+ * @param roomId The ID of the room to get online users for
44927
+ * @returns Promise that resolves with a cached list of online users
44928
+ *
44929
+ * @category Room Presence API
44930
+ * @async
44931
+ */
44932
+ const getRoomOnlineUsers = async (roomId) => {
44933
+ var _a, _b, _c;
44934
+ const client = getActiveClient();
44935
+ client.log('room/getWatchingUsers', { roomId });
44936
+ const { data } = await client.http.get(`/api/v1/presence/rooms/${roomId}/users`);
44937
+ const viewerIds = (_a = data === null || data === void 0 ? void 0 : data.viewers.map(viewer => viewer.userId)) !== null && _a !== void 0 ? _a : [];
44938
+ // getUserByIds has a maximum limit of 100 users per call
44939
+ // Split into chunks of 100 if we have more than 100 users
44940
+ const BATCH_SIZE = 100;
44941
+ const batches = [];
44942
+ for (let i = 0; i < viewerIds.length; i += BATCH_SIZE) {
44943
+ batches.push(viewerIds.slice(i, i + BATCH_SIZE));
44944
+ }
44945
+ // Fetch all batches in parallel
44946
+ const batchResults = await Promise.all(batches.map(batch => getUserByIds(batch)));
44947
+ // Merge all results
44948
+ const allViewers = [];
44949
+ batchResults.forEach(result => {
44950
+ if (result.data) {
44951
+ allViewers.push(...result.data);
44952
+ }
44953
+ });
44954
+ // Return in the same format as getUserByIds
44955
+ return {
44956
+ data: allViewers,
44957
+ cachedAt: (_c = (_b = batchResults[0]) === null || _b === void 0 ? void 0 : _b.cachedAt) !== null && _c !== void 0 ? _c : Date.now(),
44958
+ };
44959
+ };
44960
+ /* end_public_function */
44961
+
44962
+ /* begin_public_function
44963
+ id: roomPresence.getRoomUserCount
44964
+ */
44965
+ /**
44966
+ * ```js
44967
+ * import { getRoomUserCount } from '@amityco/ts-sdk'
44968
+ * const count = await getRoomUserCount('roomId')
44969
+ * ```
44970
+ *
44971
+ * Retrieves the count of users currently watching or present in a specific room.
44972
+ * This function returns the total number of online users without fetching their full user data.
44973
+ *
44974
+ * @param roomId The ID of the room to get the user count for
44975
+ * @returns Promise that resolves with the room watching count data
44976
+ *
44977
+ * @category Room Presence API
44978
+ * @async
44979
+ */
44980
+ const getRoomUserCount = async (roomId) => {
44981
+ const client = getActiveClient();
44982
+ client.log('roomPresence/getRoomUserCount', { roomId });
44983
+ const { data } = await client.http.get(`/api/v1/presence/rooms/${roomId}/users/count`);
44984
+ pushToCache(['get', 'watchingCount', roomId], data);
44985
+ fireEvent('local.room.watchingCountUpdated', data);
44986
+ return data;
44987
+ };
44988
+ /* end_public_function */
44989
+
44990
+ const getPresenceSetting = async () => {
44991
+ const client = getActiveClient();
44992
+ client.log('presence/getPresenceSetting');
44993
+ const { data } = await client.http.get('/api/v1/presence/settings');
44994
+ pushToCache(['get', 'presenceSetting'], data);
44995
+ return data;
44996
+ };
44997
+
44998
+ class RoomPresenceSyncEngine {
44999
+ constructor(roomId) {
45000
+ this.isEnabled = false;
45001
+ this.config = {
45002
+ heartbeatInterval: 30 * SECOND$1,
45003
+ };
45004
+ this.roomId = roomId;
45005
+ // Initialize config asynchronously - don't await in constructor
45006
+ this.initializeConfig().catch(error => {
45007
+ console.error('Failed to initialize RoomPresenceSyncEngine config in constructor:', error);
45008
+ });
45009
+ }
45010
+ async initializeConfig() {
45011
+ try {
45012
+ // Get presence settings from API with retry logic
45013
+ const presenceSettings = await RoomPresenceSyncEngine.getPresenceSettingWithRetry();
45014
+ if (presenceSettings) {
45015
+ // Set intervals from network settings (convert from minutes to milliseconds)
45016
+ this.config = {
45017
+ heartbeatInterval: (presenceSettings.network.heartbeatInterval || 5) * 60 * 1000,
45018
+ };
45019
+ }
45020
+ else {
45021
+ // Use default intervals if all retries failed
45022
+ this.config.heartbeatInterval = 5 * 60 * 1000; // 5 minutes
45023
+ }
45024
+ }
45025
+ catch (error) {
45026
+ console.error('Failed to initialize RoomPresenceSyncEngine config:', error);
45027
+ // Use default intervals if settings fetch fails
45028
+ this.config.heartbeatInterval = 5 * 60 * 1000; // 5 minutes
45029
+ }
45030
+ }
45031
+ static async getPresenceSettingWithRetry(maxRetries = 5) {
45032
+ for (let attempt = 0; attempt < maxRetries; attempt += 1) {
45033
+ try {
45034
+ // eslint-disable-next-line no-await-in-loop
45035
+ const presenceSettings = await getPresenceSetting();
45036
+ return presenceSettings;
45037
+ }
45038
+ catch (error) {
45039
+ if (attempt >= maxRetries - 1) {
45040
+ console.error(`Failed to get presence setting after ${maxRetries} attempts:`, error);
45041
+ return null;
45042
+ }
45043
+ // Calculate delay: 20 seconds + random jitter (0-5 seconds)
45044
+ const jitter = Math.random() * 5000; // 0-5 seconds in milliseconds
45045
+ const delay = 20000 + jitter; // 20 seconds + jitter
45046
+ console.warn(`Failed to get presence setting (attempt ${attempt + 1}/${maxRetries}), retrying in ${Math.round(delay / 1000)}s:`, error);
45047
+ // Wait before retry
45048
+ // eslint-disable-next-line no-await-in-loop
45049
+ await new Promise(resolve => {
45050
+ setTimeout(resolve, delay);
45051
+ });
45052
+ }
45053
+ }
45054
+ return null;
45055
+ }
45056
+ /**
45057
+ * Start heartbeat for the room
45058
+ */
45059
+ start() {
45060
+ if (this.isEnabled)
45061
+ return;
45062
+ this.isEnabled = true;
45063
+ // Send immediate heartbeat
45064
+ this.sendHeartbeat();
45065
+ // Start heartbeat timer
45066
+ this.heartbeatTimer = setInterval(() => {
45067
+ this.sendHeartbeat();
45068
+ }, this.config.heartbeatInterval);
45069
+ }
45070
+ /**
45071
+ * Stop heartbeat for the room
45072
+ */
45073
+ stop() {
45074
+ this.isEnabled = false;
45075
+ // Stop heartbeat timer
45076
+ if (this.heartbeatTimer) {
45077
+ clearInterval(this.heartbeatTimer);
45078
+ this.heartbeatTimer = undefined;
45079
+ }
45080
+ }
45081
+ /**
45082
+ * Send heartbeat to the room
45083
+ */
45084
+ async sendHeartbeat() {
45085
+ try {
45086
+ const client = getActiveClient();
45087
+ await client.http.post(`/api/v1/presence/rooms/${this.roomId}/heartbeat`);
45088
+ }
45089
+ catch (error) {
45090
+ console.error(`Heartbeat failed for room ${this.roomId}:`, error);
45091
+ }
45092
+ }
45093
+ /**
45094
+ * Get the room ID
45095
+ */
45096
+ getRoomId() {
45097
+ return this.roomId;
45098
+ }
45099
+ /**
45100
+ * Check if the engine is enabled
45101
+ */
45102
+ isActive() {
45103
+ return this.isEnabled;
45104
+ }
45105
+ /**
45106
+ * Cleanup method to stop all timers and release resources
45107
+ * Call this when the engine instance is no longer needed
45108
+ */
45109
+ destroy() {
45110
+ // Stop the engine
45111
+ this.stop();
45112
+ }
45113
+ // Session Management
45114
+ onSessionDestroyed() {
45115
+ // Stop all timers when session is destroyed and cleanup
45116
+ this.destroy();
45117
+ }
45118
+ onTokenExpired() {
45119
+ // Stop engine when token expires
45120
+ this.stop();
45121
+ }
45122
+ }
45123
+
45124
+ // Map to store engine instances per roomId
45125
+ const engineInstances = new Map();
45126
+ /**
45127
+ * Get or create a RoomPresenceSyncEngine instance for a specific room
45128
+ *
45129
+ * @param roomId The room ID to get/create engine for
45130
+ * @returns RoomPresenceSyncEngine instance for the room
45131
+ */
45132
+ const getRoomPresenceSyncEngine = (roomId) => {
45133
+ let engine = engineInstances.get(roomId);
45134
+ if (!engine) {
45135
+ engine = new RoomPresenceSyncEngine(roomId);
45136
+ engineInstances.set(roomId, engine);
45137
+ }
45138
+ return engine;
45139
+ };
45140
+ /**
45141
+ * Destroy the engine instance for a specific room
45142
+ *
45143
+ * @param roomId The room ID to destroy engine for
45144
+ */
45145
+ const destroyRoomPresenceSyncEngine = (roomId) => {
45146
+ const engine = engineInstances.get(roomId);
45147
+ if (engine) {
45148
+ engine.destroy();
45149
+ engineInstances.delete(roomId);
45150
+ }
45151
+ };
45152
+
45153
+ /* begin_public_function
45154
+ id: roomPresence.startHeartbeat
45155
+ */
45156
+ /**
45157
+ * ```js
45158
+ * import { startHeartbeat } from '@amityco/ts-sdk'
45159
+ * startHeartbeat('roomId')
45160
+ * ```
45161
+ *
45162
+ * Starts sending heartbeat signals for a specific room to maintain presence status.
45163
+ * This enables the room presence tracking and notifies the server that the user is actively viewing the room.
45164
+ *
45165
+ * @param roomId The ID of the room to start heartbeat for
45166
+ *
45167
+ * @category Room Presence API
45168
+ */
45169
+ const startHeartbeat = (roomId) => {
45170
+ const engine = getRoomPresenceSyncEngine(roomId);
45171
+ engine.start();
45172
+ };
45173
+ /* end_public_function */
45174
+
45175
+ /* begin_public_function
45176
+ id: roomPresence.stopHeartbeat
45177
+ */
45178
+ /**
45179
+ * ```js
45180
+ * import { stopHeartbeat } from '@amityco/ts-sdk'
45181
+ * stopHeartbeat('roomId')
45182
+ * ```
45183
+ *
45184
+ * Stops sending heartbeat signals for a specific room.
45185
+ * This disables the room presence tracking for the specified room and stops notifying the server of the user's presence.
45186
+ *
45187
+ * @param roomId The ID of the room to stop heartbeat for
45188
+ *
45189
+ * @category Room Presence API
45190
+ */
45191
+ const stopHeartbeat = (roomId) => {
45192
+ const engine = getRoomPresenceSyncEngine(roomId);
45193
+ engine.stop();
45194
+ // Clean up the engine instance
45195
+ destroyRoomPresenceSyncEngine(roomId);
45196
+ };
45197
+ /* end_public_function */
45198
+
45199
+ var index$8 = /*#__PURE__*/Object.freeze({
45200
+ __proto__: null,
45201
+ getRoomOnlineUsers: getRoomOnlineUsers,
45202
+ getRoomUserCount: getRoomUserCount,
45203
+ startHeartbeat: startHeartbeat,
45204
+ stopHeartbeat: stopHeartbeat
45205
+ });
45206
+
44493
45207
  /* begin_public_function
44494
45208
  id: poll.create
44495
45209
  */
@@ -44790,7 +45504,7 @@ const getPoll = (pollId, callback) => {
44790
45504
  };
44791
45505
  /* end_public_function */
44792
45506
 
44793
- var index$6 = /*#__PURE__*/Object.freeze({
45507
+ var index$7 = /*#__PURE__*/Object.freeze({
44794
45508
  __proto__: null,
44795
45509
  createPoll: createPoll,
44796
45510
  closePoll: closePoll,
@@ -45173,7 +45887,7 @@ const getPlayer = async (parameters) => {
45173
45887
  return video;
45174
45888
  };
45175
45889
 
45176
- var index$5 = /*#__PURE__*/Object.freeze({
45890
+ var index$6 = /*#__PURE__*/Object.freeze({
45177
45891
  __proto__: null,
45178
45892
  getPlayer: getPlayer
45179
45893
  });
@@ -46346,7 +47060,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
46346
47060
  };
46347
47061
  };
46348
47062
 
46349
- var index$4 = /*#__PURE__*/Object.freeze({
47063
+ var index$5 = /*#__PURE__*/Object.freeze({
46350
47064
  __proto__: null,
46351
47065
  createImageStory: createImageStory,
46352
47066
  createVideoStory: createVideoStory,
@@ -46383,7 +47097,7 @@ const getNetworkAds = async () => {
46383
47097
  };
46384
47098
  };
46385
47099
 
46386
- var index$3 = /*#__PURE__*/Object.freeze({
47100
+ var index$4 = /*#__PURE__*/Object.freeze({
46387
47101
  __proto__: null,
46388
47102
  getNetworkAds: getNetworkAds
46389
47103
  });
@@ -46774,7 +47488,7 @@ const markTraySeen = async (lastSeenAt) => {
46774
47488
  };
46775
47489
  /* end_public_function */
46776
47490
 
46777
- var index$2 = /*#__PURE__*/Object.freeze({
47491
+ var index$3 = /*#__PURE__*/Object.freeze({
46778
47492
  __proto__: null,
46779
47493
  getNotificationTraySeen: getNotificationTraySeen,
46780
47494
  getNotificationTrayItems: getNotificationTrayItems,
@@ -46783,6 +47497,62 @@ var index$2 = /*#__PURE__*/Object.freeze({
46783
47497
  onNotificationTraySeenUpdated: onNotificationTraySeenUpdated
46784
47498
  });
46785
47499
 
47500
+ /* begin_public_function
47501
+ id: invitation.reject
47502
+ */
47503
+ /**
47504
+ * ```js
47505
+ * import { rejectInvitation } from '@amityco/ts-sdk'
47506
+ * const isRejected = await rejectInvitation(invitationId)
47507
+ * ```
47508
+ *
47509
+ * Rejects a {@link Amity.Invitation} object
47510
+ *
47511
+ * @param invitationId the {@link Amity.Invitation} to reject
47512
+ * @returns A success boolean if the {@link Amity.Invitation} was rejected
47513
+ *
47514
+ * @category Invitation API
47515
+ * @async
47516
+ */
47517
+ const cancelInvitation = async (invitationId) => {
47518
+ var _a;
47519
+ const client = getActiveClient();
47520
+ client.log('invitation/cancelInvitation', invitationId);
47521
+ const { data } = await client.http.delete(`/api/v1/invitations/${invitationId}`);
47522
+ const invitation = (_a = pullFromCache([
47523
+ 'invitation',
47524
+ 'get',
47525
+ invitationId,
47526
+ ])) === null || _a === void 0 ? void 0 : _a.data;
47527
+ pushToTombstone('invitation', invitationId);
47528
+ if (invitation)
47529
+ fireEvent('local.invitation.canceled', [invitation]);
47530
+ return data.success;
47531
+ };
47532
+ /* end_public_function */
47533
+
47534
+ /* begin_public_function
47535
+ id: invitation.accept
47536
+ */
47537
+ /**
47538
+ * ```js
47539
+ * import { acceptInvitation } from '@amityco/ts-sdk'
47540
+ * const isAccepted = await acceptInvitation(invitationId)
47541
+ * ```
47542
+ *
47543
+ * Accepts a {@link Amity.Invitation} object
47544
+ *
47545
+ * @param invitationId the {@link Amity.Invitation} to accept
47546
+ * @returns A success boolean if the {@link Amity.Invitation} was accepted
47547
+ *
47548
+ * @category Invitation API
47549
+ * @async
47550
+ */
47551
+ const acceptInvitation = async (invitationId) => {
47552
+ return acceptInvitation$1(invitationId);
47553
+ };
47554
+ /* end_public_function */
47555
+
46786
47556
  class MyInvitationsPaginationController extends PaginationController {
46787
47557
  async getRequest(queryParams, token) {
46788
47558
  const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
@@ -46843,7 +47613,7 @@ class MyInvitationsQueryStreamController extends QueryStreamController {
46843
47613
  ]),
46844
47614
  ];
46845
47615
  }
46846
- if (action === InvitationActionsEnum.OnLocalInvitationDeleted) {
47616
+ if (action === InvitationActionsEnum.OnLocalInvitationCanceled) {
46847
47617
  collection.data = collection.data.filter(id => id !== invitations[0].invitationId);
46848
47618
  }
46849
47619
  pushToCache(this.cacheKey, collection);
@@ -46893,8 +47663,8 @@ class MyInvitationsLiveCollectionController extends LiveCollectionController {
46893
47663
  action: InvitationActionsEnum.OnLocalInvitationUpdated,
46894
47664
  },
46895
47665
  {
46896
- fn: onLocalInvitationDeleted,
46897
- action: InvitationActionsEnum.OnLocalInvitationDeleted,
47666
+ fn: onLocalInvitationCanceled,
47667
+ action: InvitationActionsEnum.OnLocalInvitationCanceled,
46898
47668
  },
46899
47669
  ]);
46900
47670
  }
@@ -46975,12 +47745,78 @@ const getMyCommunityInvitations = (params, callback, config) => {
46975
47745
  };
46976
47746
  };
46977
47747
 
46978
- var index$1 = /*#__PURE__*/Object.freeze({
47748
+ /* begin_public_function
47749
+ id: invitation.get_invitations
47750
+ */
47751
+ /**
47752
+ *
47753
+ * ```js
47754
+ * import { InvitationRepository } from '@amityco/ts-sdk';
47755
+ *
47756
+ * // For room invitations
47757
+ * const unsubscribe = InvitationRepository.getInvitations(
47758
+ * { targetId: 'room123', targetType: 'room' },
47759
+ * response => {
47760
+ * console.log('Room invitation event:', response.room, response.users, response.eventType)
47761
+ * }
47762
+ * );
47763
+ *
47764
+ * // For community invitations (when implemented)
47765
+ * const unsubscribe2 = observeInvitations(
47766
+ * { targetId: 'community456', targetType: 'community' },
47767
+ * response => {
47768
+ * console.log('Community invitation event:', response.community, response.users, response.eventType)
47769
+ * }
47770
+ * );
47771
+ * ```
47772
+ *
47773
+ * Observe invitations events including invited, accepted, rejected, and canceled
47774
+ *
47775
+ * @param params The target ID and type to observe invitations for
47776
+ * @param callback The function to call when new invitation events are available
47777
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the events
47778
+ *
47779
+ * @category Invitation Observable
47780
+ */
47781
+ const getInvitations = (params, callback) => {
47782
+ const { _id: userId } = getCurrentUser();
47783
+ if (!userId)
47784
+ throw new ASCError('The _id has not been defined in ActiveUser', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
47785
+ const { log } = getActiveClient();
47786
+ const { targetId, targetType } = params;
47787
+ const timestamp = Date.now();
47788
+ log(`observeInvitations(tmpid: ${timestamp}) > listen for ${targetType}: ${targetId}`);
47789
+ const disposers = [];
47790
+ const dispatcher = (data) => {
47791
+ callback(data.map(LinkedObject.invitation));
47792
+ };
47793
+ const realtimeRouter = (data) => {
47794
+ const invitations = (Array.isArray(data) ? data : [data]).filter(({ targetId, targetType }) => targetId === params.targetId && targetType === params.targetType);
47795
+ dispatcher(invitations);
47796
+ };
47797
+ // Only subscribe to room co-host events for now (since that's what we have implemented)
47798
+ if (targetType === 'room') {
47799
+ // Create custom event subscribers that receive the full payload
47800
+ disposers.push(onRoomCoHostInvited(realtimeRouter));
47801
+ disposers.push(onRoomCoHostInviteAccepted(realtimeRouter));
47802
+ disposers.push(onRoomCoHostInviteRejected(realtimeRouter));
47803
+ disposers.push(onRoomCoHostInviteCanceled(realtimeRouter));
47804
+ }
47805
+ return () => {
47806
+ log(`getInvitations(tmpid: ${timestamp}) > dispose for ${targetType}: ${targetId}`);
47807
+ disposers.forEach(fn => fn());
47808
+ };
47809
+ };
47810
+
47811
+ var index$2 = /*#__PURE__*/Object.freeze({
46979
47812
  __proto__: null,
47813
+ cancelInvitation: cancelInvitation,
47814
+ acceptInvitation: acceptInvitation,
46980
47815
  onLocalInvitationCreated: onLocalInvitationCreated,
46981
47816
  onLocalInvitationUpdated: onLocalInvitationUpdated,
46982
- onLocalInvitationDeleted: onLocalInvitationDeleted,
46983
- getMyCommunityInvitations: getMyCommunityInvitations
47817
+ onLocalInvitationCanceled: onLocalInvitationCanceled,
47818
+ getMyCommunityInvitations: getMyCommunityInvitations,
47819
+ getInvitations: getInvitations
46984
47820
  });
46985
47821
 
46986
47822
  // TODO: confirm id
@@ -47008,7 +47844,7 @@ var index$1 = /*#__PURE__*/Object.freeze({
47008
47844
  * @category Live Reaction API
47009
47845
  * @async
47010
47846
  */
47011
- const createReaction = async ({ referenceId, referenceType, reactionName, streamId, }) => {
47847
+ const createReaction = async ({ referenceId, referenceType, reactionName, roomId, }) => {
47012
47848
  const client = getActiveClient();
47013
47849
  client.log('live_reaction/createReaction', {
47014
47850
  referenceId,
@@ -47020,7 +47856,7 @@ const createReaction = async ({ referenceId, referenceType, reactionName, stream
47020
47856
  reactionName,
47021
47857
  referencePublicId: referenceId,
47022
47858
  referenceType,
47023
- streamId,
47859
+ roomId,
47024
47860
  occurredAt: new Date().toISOString(),
47025
47861
  };
47026
47862
  reactionSynceEngine.createLiveReaction(reaction);
@@ -47116,11 +47952,619 @@ const getReactions = (postId, callback) => {
47116
47952
  };
47117
47953
  };
47118
47954
 
47119
- var index = /*#__PURE__*/Object.freeze({
47955
+ var index$1 = /*#__PURE__*/Object.freeze({
47120
47956
  __proto__: null,
47121
47957
  createReaction: createReaction,
47122
47958
  onLiveReactionCreated: onLiveReactionCreated,
47123
47959
  getReactions: getReactions
47124
47960
  });
47125
47961
 
47126
- 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, 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 };
47962
+ const prepareEventPayload = (rawPayload) => {
47963
+ return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser) });
47964
+ };
47965
+
47966
+ const createEventEventSubscriber = (event, callback) => {
47967
+ const client = getActiveClient();
47968
+ const filter = (payload) => {
47969
+ const unpackedPayload = prepareEventPayload(payload);
47970
+ if (!client.cache) {
47971
+ callback(unpackedPayload.events[0]);
47972
+ }
47973
+ else {
47974
+ ingestInCache(unpackedPayload);
47975
+ const event = pullFromCache([
47976
+ 'event',
47977
+ 'get',
47978
+ unpackedPayload.events[0].eventId,
47979
+ ]);
47980
+ callback(event.data);
47981
+ }
47982
+ };
47983
+ return createEventSubscriber(client, event, event, filter);
47984
+ };
47985
+
47986
+ /* begin_public_function
47987
+ id: event.create
47988
+ */
47989
+ /**
47990
+ * ```js
47991
+ * import { EventRepository } from '@amityco/ts-sdk'
47992
+ * const response = await EventRepository.createEvent(bundle)
47993
+ * ```
47994
+ *
47995
+ * Creates an {@link Amity.Event}
47996
+ *
47997
+ * @param bundle The data necessary to create a new {@link Amity.Event}
47998
+ * @returns The newly created {@link Amity.Event}
47999
+ *
48000
+ * @category Event API
48001
+ * @async
48002
+ */
48003
+ const createEvent = async (bundle) => {
48004
+ const client = getActiveClient();
48005
+ client.log('event/createEvent', bundle);
48006
+ const { data: payload } = await client.http.post('/api/v1/events', bundle);
48007
+ fireEvent('local.event.created', payload);
48008
+ const preparedPayload = prepareEventPayload(payload);
48009
+ const cachedAt = client.cache && Date.now();
48010
+ if (client.cache)
48011
+ ingestInCache(preparedPayload, { cachedAt });
48012
+ return {
48013
+ data: eventLinkedObject(preparedPayload.events[0]),
48014
+ cachedAt,
48015
+ };
48016
+ };
48017
+ /* end_public_function */
48018
+
48019
+ /* begin_public_function
48020
+ id: event.update
48021
+ */
48022
+ /**
48023
+ * ```js
48024
+ * import { EventRepository } from '@amityco/ts-sdk'
48025
+ * const response = await EventRepository.updateEvent(eventId, bundle)
48026
+ * ```
48027
+ *
48028
+ * Updates an {@link Amity.Event}
48029
+ *
48030
+ * @param eventId The ID of the {@link Amity.Event} to edit
48031
+ * @param bundle The data necessary to update an existing {@link Amity.Event}
48032
+ * @returns the updated {@link Amity.Event}
48033
+ *
48034
+ * @category Event API
48035
+ * @async
48036
+ */
48037
+ const updateEvent = async (eventId, bundle) => {
48038
+ const client = getActiveClient();
48039
+ client.log('event/updateEvent', eventId, bundle);
48040
+ const { data: payload } = await client.http.put(`/api/v1/events/${eventId}`, bundle);
48041
+ fireEvent('local.event.updated', payload);
48042
+ const preparedPayload = prepareEventPayload(payload);
48043
+ const cachedAt = client.cache && Date.now();
48044
+ if (client.cache)
48045
+ ingestInCache(preparedPayload, { cachedAt });
48046
+ return {
48047
+ data: eventLinkedObject(preparedPayload.events.find(event => event.eventId === eventId)),
48048
+ cachedAt,
48049
+ };
48050
+ };
48051
+ /* end_public_function */
48052
+
48053
+ /* begin_public_function
48054
+ id: event.get
48055
+ */
48056
+ /**
48057
+ * ```js
48058
+ * import { EventRepository } from '@amityco/ts-sdk'
48059
+ * const event = await EventRepository.getEvent(eventId)
48060
+ * ```
48061
+ *
48062
+ * Fetches a {@link Amity.Event} object
48063
+ *
48064
+ * @param eventId the ID of the {@link Amity.Event} to fetch
48065
+ * @returns the associated {@link Amity.Event} object
48066
+ *
48067
+ * @category Event API
48068
+ * @async
48069
+ */
48070
+ const getEvent$1 = async (eventId) => {
48071
+ const client = getActiveClient();
48072
+ client.log('event/getEvent', eventId);
48073
+ const { data: payload } = await client.http.get(`/api/v1/events/${eventId}`);
48074
+ const data = prepareEventPayload(payload);
48075
+ const cachedAt = client.cache && Date.now();
48076
+ if (client.cache)
48077
+ ingestInCache(data, { cachedAt });
48078
+ return {
48079
+ data: data.events.find(event => event.eventId === eventId),
48080
+ cachedAt,
48081
+ };
48082
+ };
48083
+ /* end_public_function */
48084
+ /**
48085
+ * ```js
48086
+ * import { EventRepository } from '@amityco/ts-sdk'
48087
+ * const event = EventRepository.getEvent.locally(eventId)
48088
+ * ```
48089
+ *
48090
+ * Fetches a {@link Amity.Event} object in cache
48091
+ *
48092
+ * @param eventId the ID of the {@link Amity.Event} to fetch
48093
+ * @returns the associated {@link Amity.Event} object
48094
+ *
48095
+ * @category Event API
48096
+ */
48097
+ getEvent$1.locally = (eventId) => {
48098
+ const client = getActiveClient();
48099
+ client.log('event/getEvent.locally', eventId);
48100
+ if (!client.cache)
48101
+ return;
48102
+ const cache = pullFromCache(['event', 'get', eventId]);
48103
+ if (!cache)
48104
+ return;
48105
+ return {
48106
+ data: cache.data,
48107
+ cachedAt: cache.cachedAt,
48108
+ };
48109
+ };
48110
+
48111
+ /* begin_public_function
48112
+ id: event.delete
48113
+ */
48114
+ /**
48115
+ * ```js
48116
+ * import { EventRepository } from '@amityco/ts-sdk'
48117
+ * const { success } = await EventRepository.deleteEvent(eventId)
48118
+ * ```
48119
+ *
48120
+ * Deletes a {@link Amity.Event}
48121
+ *
48122
+ * @param eventId The {@link Amity.Event} ID to delete
48123
+ *
48124
+ * @category Event API
48125
+ * @async
48126
+ */
48127
+ const deleteEvent = async (eventId) => {
48128
+ const client = getActiveClient();
48129
+ client.log('event/deleteEvent', eventId);
48130
+ const event = await getEvent$1(eventId);
48131
+ await client.http.delete(`/api/v1/events/${eventId}`);
48132
+ const deletedEvent = Object.assign(Object.assign({}, event.data), { isDeleted: true });
48133
+ upsertInCache(['event', 'get', eventId], deletedEvent);
48134
+ fireEvent('local.event.deleted', {
48135
+ users: [],
48136
+ files: [],
48137
+ communities: [],
48138
+ videoStreamings: [],
48139
+ events: [deletedEvent],
48140
+ discussionCommunities: [],
48141
+ });
48142
+ };
48143
+ /* end_public_function */
48144
+
48145
+ /**
48146
+ * ```js
48147
+ * import { EventRepository } from '@amityco/ts-sdk'
48148
+ * const dispose = EventRepository.onEventCreated(event => {
48149
+ * // ...
48150
+ * })
48151
+ * ```
48152
+ *
48153
+ * Fired when a {@link Amity.Event} has been created
48154
+ *
48155
+ * @param callback The function to call when the event was fired
48156
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
48157
+ *
48158
+ * @category Event Events
48159
+ */
48160
+ const onEventCreated = (callback) => createEventEventSubscriber('event.created', callback);
48161
+
48162
+ /**
48163
+ * ```js
48164
+ * import { EventRepository } from '@amityco/ts-sdk'
48165
+ * const dispose = EventRepository.onEventUpdated(event => {
48166
+ * // ...
48167
+ * })
48168
+ * ```
48169
+ *
48170
+ * Fired when a {@link Amity.Event} has been updated
48171
+ *
48172
+ * @param callback The function to call when the event was fired
48173
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
48174
+ *
48175
+ * @category Event Events
48176
+ */
48177
+ const onEventUpdated = (callback) => createEventEventSubscriber('event.updated', callback);
48178
+
48179
+ /**
48180
+ * ```js
48181
+ * import { EventRepository } from '@amityco/ts-sdk'
48182
+ * const dispose = EventRepository.onEventDeleted(event => {
48183
+ * // ...
48184
+ * })
48185
+ * ```
48186
+ *
48187
+ * Fired when a {@link Amity.Event} has been deleted
48188
+ *
48189
+ * @param callback The function to call when the event was fired
48190
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
48191
+ *
48192
+ * @category Event Events
48193
+ */
48194
+ const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted', callback);
48195
+
48196
+ /**
48197
+ * ```js
48198
+ * import { EventRepository } from '@amityco/ts-sdk'
48199
+ * const dispose = EventRepository.onLocalEventCreated(event => {
48200
+ * // ...
48201
+ * })
48202
+ * ```
48203
+ *
48204
+ * Fired when a {@link Amity.Event} has been created
48205
+ *
48206
+ * @param callback The function to call when the event was fired
48207
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
48208
+ *
48209
+ * @category Event Events
48210
+ */
48211
+ const onLocalEventCreated = (callback) => createEventEventSubscriber('local.event.created', callback);
48212
+
48213
+ /**
48214
+ * ```js
48215
+ * import { EventRepository } from '@amityco/ts-sdk'
48216
+ * const dispose = EventRepository.onLocalEventUpdated(event => {
48217
+ * // ...
48218
+ * })
48219
+ * ```
48220
+ *
48221
+ * Fired when a {@link Amity.Event} has been updated
48222
+ *
48223
+ * @param callback The function to call when the event was fired
48224
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
48225
+ *
48226
+ * @category Event Events
48227
+ */
48228
+ const onLocalEventUpdated = (callback) => createEventEventSubscriber('local.event.updated', callback);
48229
+
48230
+ /**
48231
+ * ```js
48232
+ * import { EventRepository } from '@amityco/ts-sdk'
48233
+ * const dispose = EventRepository.onLocalEventDeleted(event => {
48234
+ * // ...
48235
+ * })
48236
+ * ```
48237
+ *
48238
+ * Fired when a {@link Amity.Event} has been deleted
48239
+ *
48240
+ * @param callback The function to call when the event was fired
48241
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
48242
+ *
48243
+ * @category Event Events
48244
+ */
48245
+ const onLocalEventDeleted = (callback) => createEventEventSubscriber('local.event.deleted', callback);
48246
+
48247
+ /* begin_public_function
48248
+ id: event.get
48249
+ */
48250
+ /**
48251
+ * ```js
48252
+ * import { EventRepository } from '@amityco/ts-sdk';
48253
+ *
48254
+ * let event;
48255
+ *
48256
+ * const unsubscribe = EventRepository.getEvent(eventId, response => {
48257
+ * event = response.data;
48258
+ * });
48259
+ * ```
48260
+ *
48261
+ * Observe all mutation on a given {@link Amity.Event}
48262
+ *
48263
+ * @param eventId the ID of the event to observe
48264
+ * @param callback the function to call when new snapshot of event are available
48265
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the event
48266
+ *
48267
+ * @category Event Live Object
48268
+ */
48269
+ const getEvent = (eventId, callback) => {
48270
+ return liveObject(eventId, callback, 'eventId', getEvent$1, [onEventUpdated, onEventDeleted, onLocalEventUpdated, onLocalEventDeleted], {
48271
+ callbackDataSelector: (data) => (data ? eventLinkedObject(data) : data),
48272
+ });
48273
+ };
48274
+ /* end_public_function */
48275
+
48276
+ var EventActionsEnum;
48277
+ (function (EventActionsEnum) {
48278
+ EventActionsEnum["OnEventCreated"] = "onEventCreated";
48279
+ EventActionsEnum["OnEventUpdated"] = "onEventUpdated";
48280
+ EventActionsEnum["OnEventDeleted"] = "onEventDeleted";
48281
+ })(EventActionsEnum || (EventActionsEnum = {}));
48282
+
48283
+ class EventPaginationController extends PaginationController {
48284
+ async getRequest(queryParams, token) {
48285
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
48286
+ const options = token ? { token } : { limit };
48287
+ const { data: response } = await this.http.get(`/api/v1/events`, { params: Object.assign(Object.assign({}, params), { options }) });
48288
+ return response;
48289
+ }
48290
+ }
48291
+
48292
+ class EventQueryStreamController extends QueryStreamController {
48293
+ constructor(query, cacheKey, notifyChange, preparePayload) {
48294
+ super(query, cacheKey);
48295
+ this.notifyChange = notifyChange;
48296
+ this.preparePayload = preparePayload;
48297
+ }
48298
+ async saveToMainDB(response) {
48299
+ const processedPayload = this.preparePayload(response);
48300
+ const client = getActiveClient();
48301
+ const cachedAt = client.cache && Date.now();
48302
+ if (client.cache)
48303
+ ingestInCache(processedPayload, { cachedAt });
48304
+ }
48305
+ appendToQueryStream(response, direction, refresh = false) {
48306
+ var _a, _b;
48307
+ if (refresh) {
48308
+ pushToCache(this.cacheKey, { data: response.events.map(getResolver('event')) });
48309
+ }
48310
+ else {
48311
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
48312
+ const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
48313
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...events, ...response.events.map(getResolver('event'))])] }));
48314
+ }
48315
+ }
48316
+ reactor(action) {
48317
+ return (event) => {
48318
+ var _a;
48319
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
48320
+ if (!collection)
48321
+ return;
48322
+ if (action === EventActionsEnum.OnEventCreated) {
48323
+ collection.data = [...new Set([event.eventId, ...collection.data])];
48324
+ }
48325
+ if (action === EventActionsEnum.OnEventDeleted) {
48326
+ collection.data = collection.data.filter(eventId => eventId !== event.eventId);
48327
+ }
48328
+ pushToCache(this.cacheKey, collection);
48329
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
48330
+ };
48331
+ }
48332
+ subscribeRTE(createSubscriber) {
48333
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
48334
+ }
48335
+ }
48336
+
48337
+ class EventLiveCollectionController extends LiveCollectionController {
48338
+ constructor(query, callback) {
48339
+ const queryStreamId = hash(query);
48340
+ const cacheKey = ['event', 'collection', queryStreamId];
48341
+ const paginationController = new EventPaginationController(query);
48342
+ super(paginationController, queryStreamId, cacheKey, callback);
48343
+ this.query = query;
48344
+ this.queryStreamController = new EventQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventPayload);
48345
+ this.callback = callback.bind(this);
48346
+ this.loadPage({ initial: true });
48347
+ }
48348
+ setup() {
48349
+ var _a;
48350
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
48351
+ if (!collection)
48352
+ pushToCache(this.cacheKey, { data: [], params: {} });
48353
+ }
48354
+ async persistModel(queryPayload) {
48355
+ await this.queryStreamController.saveToMainDB(queryPayload);
48356
+ }
48357
+ persistQueryStream({ response, direction, refresh, }) {
48358
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
48359
+ }
48360
+ startSubscription() {
48361
+ return this.queryStreamController.subscribeRTE([
48362
+ { fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
48363
+ { fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
48364
+ { fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
48365
+ { fn: onLocalEventCreated, action: EventActionsEnum.OnEventCreated },
48366
+ { fn: onLocalEventUpdated, action: EventActionsEnum.OnEventUpdated },
48367
+ { fn: onLocalEventDeleted, action: EventActionsEnum.OnEventDeleted },
48368
+ ]);
48369
+ }
48370
+ notifyChange({ origin, loading, error }) {
48371
+ var _a, _b;
48372
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
48373
+ if (!collection)
48374
+ return;
48375
+ const data = ((_b = collection.data
48376
+ .map(eventId => pullFromCache(['event', 'get', eventId]))
48377
+ .filter(isNonNullable)
48378
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
48379
+ if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
48380
+ return;
48381
+ this.callback({
48382
+ data,
48383
+ error,
48384
+ loading,
48385
+ hasNextPage: !!this.paginationController.getNextToken(),
48386
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
48387
+ });
48388
+ }
48389
+ }
48390
+
48391
+ /**
48392
+ * Get events
48393
+ *
48394
+ * @param params the query parameters
48395
+ * @param callback the callback to be called when the events are updated
48396
+ * @returns events
48397
+ *
48398
+ * @category Event Live Collection
48399
+ *
48400
+ */
48401
+ const getEvents = (params, callback, config) => {
48402
+ const { log, cache } = getActiveClient();
48403
+ if (!cache)
48404
+ console.log(ENABLE_CACHE_MESSAGE);
48405
+ const timestamp = Date.now();
48406
+ log(`getEvents: (tmpid: ${timestamp}) > listen`);
48407
+ const eventLiveCollection = new EventLiveCollectionController(params, callback);
48408
+ const disposers = eventLiveCollection.startSubscription();
48409
+ const cacheKey = eventLiveCollection.getCacheKey();
48410
+ disposers.push(() => dropFromCache(cacheKey));
48411
+ return () => {
48412
+ log(`getEvents (tmpid: ${timestamp}) > dispose`);
48413
+ disposers.forEach(fn => fn());
48414
+ };
48415
+ };
48416
+
48417
+ class MyEventPaginationController extends PaginationController {
48418
+ async getRequest(queryParams, token) {
48419
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
48420
+ const options = token ? { token } : { limit };
48421
+ const { data: response } = await this.http.get(`/api/v1/events/me/rsvps`, { params: Object.assign(Object.assign({}, params), { options }) });
48422
+ return response;
48423
+ }
48424
+ }
48425
+
48426
+ class MyEventQueryStreamController extends QueryStreamController {
48427
+ constructor(query, cacheKey, notifyChange, preparePayload) {
48428
+ super(query, cacheKey);
48429
+ this.notifyChange = notifyChange;
48430
+ this.preparePayload = preparePayload;
48431
+ }
48432
+ async saveToMainDB(response) {
48433
+ const processedPayload = this.preparePayload(response);
48434
+ const client = getActiveClient();
48435
+ const cachedAt = client.cache && Date.now();
48436
+ if (client.cache)
48437
+ ingestInCache(processedPayload, { cachedAt });
48438
+ }
48439
+ appendToQueryStream(response, direction, refresh = false) {
48440
+ var _a, _b;
48441
+ if (refresh) {
48442
+ pushToCache(this.cacheKey, { data: response.events.map(getResolver('event')) });
48443
+ }
48444
+ else {
48445
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
48446
+ const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
48447
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...events, ...response.events.map(getResolver('event'))])] }));
48448
+ }
48449
+ }
48450
+ reactor(action) {
48451
+ return (event) => {
48452
+ var _a;
48453
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
48454
+ if (!collection)
48455
+ return;
48456
+ if (action === EventActionsEnum.OnEventCreated) {
48457
+ const client = getActiveClient();
48458
+ if (client.userId !== event.userId)
48459
+ return;
48460
+ collection.data = [...new Set([event.eventId, ...collection.data])];
48461
+ }
48462
+ if (action === EventActionsEnum.OnEventDeleted) {
48463
+ collection.data = collection.data.filter(eventId => eventId !== event.eventId);
48464
+ }
48465
+ pushToCache(this.cacheKey, collection);
48466
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
48467
+ };
48468
+ }
48469
+ subscribeRTE(createSubscriber) {
48470
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
48471
+ }
48472
+ }
48473
+
48474
+ class MyEventLiveCollectionController extends LiveCollectionController {
48475
+ constructor(query, callback) {
48476
+ const queryStreamId = hash(query);
48477
+ const cacheKey = ['event', 'collection', queryStreamId];
48478
+ const paginationController = new MyEventPaginationController(query);
48479
+ super(paginationController, queryStreamId, cacheKey, callback);
48480
+ this.query = query;
48481
+ this.queryStreamController = new MyEventQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventPayload);
48482
+ this.callback = callback.bind(this);
48483
+ this.loadPage({ initial: true });
48484
+ }
48485
+ setup() {
48486
+ var _a;
48487
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
48488
+ if (!collection)
48489
+ pushToCache(this.cacheKey, { data: [], params: {} });
48490
+ }
48491
+ async persistModel(queryPayload) {
48492
+ await this.queryStreamController.saveToMainDB(queryPayload);
48493
+ }
48494
+ persistQueryStream({ response, direction, refresh, }) {
48495
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
48496
+ }
48497
+ startSubscription() {
48498
+ return this.queryStreamController.subscribeRTE([
48499
+ { fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
48500
+ { fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
48501
+ { fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
48502
+ { fn: onLocalEventCreated, action: EventActionsEnum.OnEventCreated },
48503
+ { fn: onLocalEventUpdated, action: EventActionsEnum.OnEventUpdated },
48504
+ { fn: onLocalEventDeleted, action: EventActionsEnum.OnEventDeleted },
48505
+ ]);
48506
+ }
48507
+ notifyChange({ origin, loading, error }) {
48508
+ var _a, _b;
48509
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
48510
+ if (!collection)
48511
+ return;
48512
+ const data = ((_b = collection.data
48513
+ .map(eventId => pullFromCache(['event', 'get', eventId]))
48514
+ .filter(isNonNullable)
48515
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
48516
+ if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
48517
+ return;
48518
+ this.callback({
48519
+ data,
48520
+ error,
48521
+ loading,
48522
+ hasNextPage: !!this.paginationController.getNextToken(),
48523
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
48524
+ });
48525
+ }
48526
+ }
48527
+
48528
+ /**
48529
+ * Get my events
48530
+ *
48531
+ * @param params the query parameters
48532
+ * @param callback the callback to be called when the events are updated
48533
+ * @returns events
48534
+ *
48535
+ * @category Event Live Collection
48536
+ *
48537
+ */
48538
+ const getMyEvents = (params, callback, config) => {
48539
+ const { log, cache } = getActiveClient();
48540
+ if (!cache)
48541
+ console.log(ENABLE_CACHE_MESSAGE);
48542
+ const timestamp = Date.now();
48543
+ log(`getMyEvents: (tmpid: ${timestamp}) > listen`);
48544
+ const myEventLiveCollection = new MyEventLiveCollectionController(params, callback);
48545
+ const disposers = myEventLiveCollection.startSubscription();
48546
+ const cacheKey = myEventLiveCollection.getCacheKey();
48547
+ disposers.push(() => dropFromCache(cacheKey));
48548
+ return () => {
48549
+ log(`getMyEvents (tmpid: ${timestamp}) > dispose`);
48550
+ disposers.forEach(fn => fn());
48551
+ };
48552
+ };
48553
+
48554
+ var index = /*#__PURE__*/Object.freeze({
48555
+ __proto__: null,
48556
+ createEvent: createEvent,
48557
+ updateEvent: updateEvent,
48558
+ deleteEvent: deleteEvent,
48559
+ onEventCreated: onEventCreated,
48560
+ onEventUpdated: onEventUpdated,
48561
+ onEventDeleted: onEventDeleted,
48562
+ onLocalEventCreated: onLocalEventCreated,
48563
+ onLocalEventUpdated: onLocalEventUpdated,
48564
+ onLocalEventDeleted: onLocalEventDeleted,
48565
+ getEvent: getEvent,
48566
+ getEvents: getEvents,
48567
+ getMyEvents: getMyEvents
48568
+ });
48569
+
48570
+ export { API_REGIONS, index$4 as AdRepository, AmityEventOriginType, AmityEventResponseStatus, AmityEventStatus, AmityEventType, index$e as CategoryRepository, index$i as ChannelRepository, index$r as Client, index$d as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$f as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, index as EventRepository, FeedDataTypeEnum, index$c as FeedRepository, FeedSortByEnum, FeedSourceEnum, FileAccessTypeEnum, index$o as FileRepository, FileType, GET_WATCHER_URLS, index$2 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTargetTypeEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index$1 as LiveReactionRepository, index$6 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$m as MessageRepository, index$7 as PollRepository, PostContentType, index$b as PostRepository, PostStructureType, index$n as ReactionRepository, index$8 as RoomPresenceRepository, index$9 as RoomRepository, index$5 as StoryRepository, index$a as StreamRepository, index$l as SubChannelRepository, SubscriptionLevels, index$p 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$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 };