@amityco/ts-sdk 7.11.1-a356db4f.0 → 7.11.1-b364881.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 (96) hide show
  1. package/dist/@types/core/events.d.ts +4 -0
  2. package/dist/@types/core/events.d.ts.map +1 -1
  3. package/dist/@types/core/model.d.ts +3 -4
  4. package/dist/@types/core/model.d.ts.map +1 -1
  5. package/dist/@types/core/payload.d.ts +18 -4
  6. package/dist/@types/core/payload.d.ts.map +1 -1
  7. package/dist/@types/domains/client.d.ts +1 -0
  8. package/dist/@types/domains/client.d.ts.map +1 -1
  9. package/dist/@types/domains/community.d.ts +13 -3
  10. package/dist/@types/domains/community.d.ts.map +1 -1
  11. package/dist/@types/domains/event.d.ts +50 -9
  12. package/dist/@types/domains/event.d.ts.map +1 -1
  13. package/dist/@types/domains/notification.d.ts +11 -4
  14. package/dist/@types/domains/notification.d.ts.map +1 -1
  15. package/dist/@types/domains/post.d.ts +12 -0
  16. package/dist/@types/domains/post.d.ts.map +1 -1
  17. package/dist/client/api/getCurrentUser.d.ts +1 -1
  18. package/dist/client/api/getCurrentUser.d.ts.map +1 -1
  19. package/dist/client/events/onUserDeleted.d.ts.map +1 -1
  20. package/dist/client/utils/setBotClientToken.d.ts.map +1 -1
  21. package/dist/client/utils/setClientToken.d.ts.map +1 -1
  22. package/dist/client/utils/setCurrentUser.d.ts.map +1 -1
  23. package/dist/client/utils/setVisitorClientToken.d.ts.map +1 -1
  24. package/dist/core/events.d.ts +3 -3
  25. package/dist/core/events.d.ts.map +1 -1
  26. package/dist/core/model/idResolvers.d.ts.map +1 -1
  27. package/dist/eventRepository/events/enums.d.ts +3 -1
  28. package/dist/eventRepository/events/enums.d.ts.map +1 -1
  29. package/dist/eventRepository/events/index.d.ts +4 -0
  30. package/dist/eventRepository/events/index.d.ts.map +1 -1
  31. package/dist/eventRepository/events/onEventCreated.d.ts +1 -1
  32. package/dist/eventRepository/events/onLocalRSVPCreated.d.ts +17 -0
  33. package/dist/eventRepository/events/onLocalRSVPCreated.d.ts.map +1 -0
  34. package/dist/eventRepository/events/onLocalRSVPUpdated.d.ts +17 -0
  35. package/dist/eventRepository/events/onLocalRSVPUpdated.d.ts.map +1 -0
  36. package/dist/eventRepository/events/onRSVPCreated.d.ts +17 -0
  37. package/dist/eventRepository/events/onRSVPCreated.d.ts.map +1 -0
  38. package/dist/eventRepository/events/onRSVPUpdated.d.ts +17 -0
  39. package/dist/eventRepository/events/onRSVPUpdated.d.ts.map +1 -0
  40. package/dist/eventRepository/internalApi/createRSVP.d.ts +17 -0
  41. package/dist/eventRepository/internalApi/createRSVP.d.ts.map +1 -0
  42. package/dist/eventRepository/internalApi/getMyRSVP.d.ts +32 -0
  43. package/dist/eventRepository/internalApi/getMyRSVP.d.ts.map +1 -0
  44. package/dist/eventRepository/internalApi/index.d.ts +3 -0
  45. package/dist/eventRepository/internalApi/index.d.ts.map +1 -1
  46. package/dist/eventRepository/internalApi/updateRSVP.d.ts +17 -0
  47. package/dist/eventRepository/internalApi/updateRSVP.d.ts.map +1 -0
  48. package/dist/eventRepository/observers/getRSVPs/LiveCollectionController.d.ts +13 -0
  49. package/dist/eventRepository/observers/getRSVPs/LiveCollectionController.d.ts.map +1 -0
  50. package/dist/eventRepository/observers/getRSVPs/PaginationController.d.ts +5 -0
  51. package/dist/eventRepository/observers/getRSVPs/PaginationController.d.ts.map +1 -0
  52. package/dist/eventRepository/observers/getRSVPs/QueryStreamController.d.ts +15 -0
  53. package/dist/eventRepository/observers/getRSVPs/QueryStreamController.d.ts.map +1 -0
  54. package/dist/eventRepository/observers/getRSVPs.d.ts +12 -0
  55. package/dist/eventRepository/observers/getRSVPs.d.ts.map +1 -0
  56. package/dist/eventRepository/observers/index.d.ts +1 -0
  57. package/dist/eventRepository/observers/index.d.ts.map +1 -1
  58. package/dist/eventRepository/utils/createEventResponseSubscriber.d.ts +2 -0
  59. package/dist/eventRepository/utils/createEventResponseSubscriber.d.ts.map +1 -0
  60. package/dist/eventRepository/utils/index.d.ts +2 -0
  61. package/dist/eventRepository/utils/index.d.ts.map +1 -1
  62. package/dist/eventRepository/utils/prepareEventResponsePayload.d.ts +2 -0
  63. package/dist/eventRepository/utils/prepareEventResponsePayload.d.ts.map +1 -0
  64. package/dist/index.cjs.js +2527 -1751
  65. package/dist/index.esm.js +2340 -1564
  66. package/dist/index.umd.js +3 -3
  67. package/dist/postRepository/observers/getCommunityLiveRoomPosts/CommunityLiveRoomPostLiveCollectionController.d.ts +14 -0
  68. package/dist/postRepository/observers/getCommunityLiveRoomPosts/CommunityLiveRoomPostLiveCollectionController.d.ts.map +1 -0
  69. package/dist/postRepository/observers/getCommunityLiveRoomPosts/CommunityLiveRoomPostPaginationController.d.ts +5 -0
  70. package/dist/postRepository/observers/getCommunityLiveRoomPosts/CommunityLiveRoomPostPaginationController.d.ts.map +1 -0
  71. package/dist/postRepository/observers/getCommunityLiveRoomPosts/CommunityLiveRoomPostQueryStreamController.d.ts +15 -0
  72. package/dist/postRepository/observers/getCommunityLiveRoomPosts/CommunityLiveRoomPostQueryStreamController.d.ts.map +1 -0
  73. package/dist/postRepository/observers/getCommunityLiveRoomPosts.d.ts +22 -0
  74. package/dist/postRepository/observers/getCommunityLiveRoomPosts.d.ts.map +1 -0
  75. package/dist/postRepository/observers/getLiveRoomPosts/LiveRoomPostLiveCollectionController.d.ts +14 -0
  76. package/dist/postRepository/observers/getLiveRoomPosts/LiveRoomPostLiveCollectionController.d.ts.map +1 -0
  77. package/dist/postRepository/observers/getLiveRoomPosts/LiveRoomPostPaginationController.d.ts +5 -0
  78. package/dist/postRepository/observers/getLiveRoomPosts/LiveRoomPostPaginationController.d.ts.map +1 -0
  79. package/dist/postRepository/observers/getLiveRoomPosts/LiveRoomPostQueryStreamController.d.ts +15 -0
  80. package/dist/postRepository/observers/getLiveRoomPosts/LiveRoomPostQueryStreamController.d.ts.map +1 -0
  81. package/dist/postRepository/observers/getLiveRoomPosts.d.ts +23 -0
  82. package/dist/postRepository/observers/getLiveRoomPosts.d.ts.map +1 -0
  83. package/dist/postRepository/observers/index.d.ts +2 -0
  84. package/dist/postRepository/observers/index.d.ts.map +1 -1
  85. package/dist/postRepository/observers/utils.d.ts +1 -0
  86. package/dist/postRepository/observers/utils.d.ts.map +1 -1
  87. package/dist/roomPresenceRepository/api/getRoomUserCount.d.ts.map +1 -1
  88. package/dist/utils/linkedObject/communityLinkedObject.d.ts.map +1 -1
  89. package/dist/utils/linkedObject/eventLinkObject.d.ts.map +1 -1
  90. package/dist/utils/linkedObject/eventResponseLinkObject.d.ts +2 -0
  91. package/dist/utils/linkedObject/eventResponseLinkObject.d.ts.map +1 -0
  92. package/dist/utils/linkedObject/index.d.ts +1 -0
  93. package/dist/utils/linkedObject/index.d.ts.map +1 -1
  94. package/dist/utils/linkedObject/notificationTrayLinkedObject.d.ts.map +1 -1
  95. package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
  96. package/package.json +1 -1
package/dist/index.esm.js CHANGED
@@ -73,6 +73,11 @@ const CommunityPostSettingMaps = Object.freeze({
73
73
  },
74
74
  });
75
75
  const DefaultCommunityPostSetting = 'ONLY_ADMIN_CAN_POST';
76
+ var AmityCommunityType;
77
+ (function (AmityCommunityType) {
78
+ AmityCommunityType["Default"] = "default";
79
+ AmityCommunityType["Event"] = "event";
80
+ })(AmityCommunityType || (AmityCommunityType = {}));
76
81
 
77
82
  const ContentFeedType = Object.freeze({
78
83
  STORY: 'story',
@@ -204,9 +209,18 @@ var AmityEventStatus;
204
209
  var AmityEventResponseStatus;
205
210
  (function (AmityEventResponseStatus) {
206
211
  AmityEventResponseStatus["Going"] = "going";
207
- AmityEventResponseStatus["Interested"] = "interested";
208
212
  AmityEventResponseStatus["NotGoing"] = "not_going";
209
213
  })(AmityEventResponseStatus || (AmityEventResponseStatus = {}));
214
+ var AmityEventSortOption;
215
+ (function (AmityEventSortOption) {
216
+ AmityEventSortOption["StartTime"] = "startTime";
217
+ AmityEventSortOption["CreatedAt"] = "createdAt";
218
+ })(AmityEventSortOption || (AmityEventSortOption = {}));
219
+ var AmityEventOrderOption;
220
+ (function (AmityEventOrderOption) {
221
+ AmityEventOrderOption["Ascending"] = "asc";
222
+ AmityEventOrderOption["Descending"] = "desc";
223
+ })(AmityEventOrderOption || (AmityEventOrderOption = {}));
210
224
 
211
225
  function getVersion() {
212
226
  try {
@@ -657,8 +671,9 @@ const idResolvers = {
657
671
  invitation: ({ _id }) => _id,
658
672
  joinRequest: ({ joinRequestId }) => joinRequestId,
659
673
  room: ({ roomId }) => roomId,
674
+ viewer: ({ userId }) => userId,
660
675
  event: ({ eventId }) => eventId,
661
- discussionCommunity: ({ communityId }) => communityId,
676
+ eventResponse: ({ userId }) => userId,
662
677
  };
663
678
  /**
664
679
  * Retrieve the id resolver matching a domain name
@@ -716,8 +731,8 @@ const PAYLOAD2MODEL = {
716
731
  joinRequests: 'joinRequest',
717
732
  rooms: 'room',
718
733
  events: 'event',
719
- discussionCommunities: 'discussionCommunity',
720
734
  viewers: 'viewer',
735
+ eventResponses: 'eventResponse',
721
736
  };
722
737
  /** hidden */
723
738
  const isOutdated = (prevData, nextData) => {
@@ -1541,10 +1556,7 @@ const getCurrentUser = () => {
1541
1556
  throw new ASCError('Connect client first', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "fatal" /* Amity.ErrorLevel.FATAL */);
1542
1557
  }
1543
1558
  const cache = (_a = pullFromCache(['user', 'get', client.userId])) === null || _a === void 0 ? void 0 : _a.data;
1544
- if (!cache) {
1545
- throw new ASCError('Connect client first', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "fatal" /* Amity.ErrorLevel.FATAL */);
1546
- }
1547
- return userLinkedObject(cache);
1559
+ return cache ? userLinkedObject(cache) : null;
1548
1560
  };
1549
1561
  /* end_public_function */
1550
1562
 
@@ -23392,6 +23404,13 @@ const getToken = async ({ params, options, }) => {
23392
23404
  return data;
23393
23405
  };
23394
23406
 
23407
+ function prepareUserPayload(response) {
23408
+ return {
23409
+ users: response.users.map(convertRawUserToInternalUser),
23410
+ files: response.files,
23411
+ };
23412
+ }
23413
+
23395
23414
  /**
23396
23415
  * A util to set or refresh client token
23397
23416
  *
@@ -23408,7 +23427,7 @@ const setClientToken = async (params) => {
23408
23427
  const client = getActiveClient();
23409
23428
  // begin establishing session
23410
23429
  setSessionState("establishing" /* Amity.SessionStates.ESTABLISHING */);
23411
- const { accessToken, users, expiresAt, issuedAt, userType } = await getToken(params);
23430
+ const { accessToken, users, expiresAt, issuedAt, userType, files } = await getToken(params);
23412
23431
  // manually setup the token for http transport
23413
23432
  client.http.defaults.headers.common.Authorization = `Bearer ${accessToken}`;
23414
23433
  client.http.defaults.metadata = {
@@ -23424,6 +23443,10 @@ const setClientToken = async (params) => {
23424
23443
  };
23425
23444
  client.token = { accessToken, issuedAt, expiresAt };
23426
23445
  setSessionState("established" /* Amity.SessionStates.ESTABLISHED */);
23446
+ ingestInCache(prepareUserPayload({
23447
+ users,
23448
+ files,
23449
+ }));
23427
23450
  return { accessToken, users, userType };
23428
23451
  };
23429
23452
 
@@ -23473,7 +23496,7 @@ const setVisitorClientToken = async (params) => {
23473
23496
  const client = getActiveClient();
23474
23497
  // begin establishing session
23475
23498
  setSessionState("establishing" /* Amity.SessionStates.ESTABLISHING */);
23476
- const { accessToken, users, expiresAt, issuedAt, userType } = await getVisitorToken(params);
23499
+ const { accessToken, users, expiresAt, issuedAt, userType, files } = await getVisitorToken(params);
23477
23500
  // manually setup the token for http transport
23478
23501
  client.http.defaults.headers.common.Authorization = `Bearer ${accessToken}`;
23479
23502
  client.http.defaults.metadata = {
@@ -23483,16 +23506,13 @@ const setVisitorClientToken = async (params) => {
23483
23506
  };
23484
23507
  client.token = { accessToken, issuedAt, expiresAt };
23485
23508
  setSessionState("established" /* Amity.SessionStates.ESTABLISHED */);
23509
+ ingestInCache(prepareUserPayload({
23510
+ users,
23511
+ files,
23512
+ }));
23486
23513
  return { accessToken, users, userType };
23487
23514
  };
23488
23515
 
23489
- function prepareUserPayload(response) {
23490
- return {
23491
- users: response.users.map(convertRawUserToInternalUser),
23492
- files: response.files,
23493
- };
23494
- }
23495
-
23496
23516
  const createUserEventSubscriber = (event, callback) => {
23497
23517
  const client = getActiveClient();
23498
23518
  const filter = (data) => {
@@ -24961,7 +24981,6 @@ const setCurrentUserType = (userType) => {
24961
24981
  const setCurrentUser = ({ user, userType, }) => {
24962
24982
  setActiveUser(user);
24963
24983
  setCurrentUserType(userType);
24964
- pushToCache(['user', 'get', user.userId], user);
24965
24984
  };
24966
24985
 
24967
24986
  /* eslint-disable no-param-reassign */
@@ -26148,7 +26167,7 @@ const setBotClientToken = async (params) => {
26148
26167
  const client = getActiveClient();
26149
26168
  // begin establishing session
26150
26169
  setSessionState("establishing" /* Amity.SessionStates.ESTABLISHING */);
26151
- const { accessToken, users, expiresAt, issuedAt, userType } = await getBotToken(params);
26170
+ const { accessToken, users, expiresAt, issuedAt, userType, files } = await getBotToken(params);
26152
26171
  // manually setup the token for http transport
26153
26172
  client.http.defaults.headers.common.Authorization = `Bearer ${accessToken}`;
26154
26173
  client.http.defaults.metadata = {
@@ -26158,6 +26177,10 @@ const setBotClientToken = async (params) => {
26158
26177
  };
26159
26178
  client.token = { accessToken, issuedAt, expiresAt };
26160
26179
  setSessionState("established" /* Amity.SessionStates.ESTABLISHED */);
26180
+ ingestInCache(prepareUserPayload({
26181
+ users,
26182
+ files,
26183
+ }));
26161
26184
  return { accessToken, users, userType };
26162
26185
  };
26163
26186
 
@@ -28908,411 +28931,6 @@ const roomLinkedObject = (room) => {
28908
28931
  } });
28909
28932
  };
28910
28933
 
28911
- const postLinkedObject = (post) => {
28912
- return shallowClone(post, {
28913
- childrenPosts: post.children
28914
- .map(childPost => { var _a; return (_a = pullFromCache(['post', 'get', childPost])) === null || _a === void 0 ? void 0 : _a.data; })
28915
- .filter(isNonNullable)
28916
- .map(postLinkedObject),
28917
- analytics: {
28918
- markAsViewed: () => {
28919
- const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
28920
- analyticsEngineInstance.markPostAsViewed(post.postId);
28921
- },
28922
- },
28923
- get latestComments() {
28924
- if (!post.comments)
28925
- return [];
28926
- return (post.comments
28927
- .map(commentId => {
28928
- var _a;
28929
- const commentCached = (_a = pullFromCache([
28930
- 'comment',
28931
- 'get',
28932
- commentId,
28933
- ])) === null || _a === void 0 ? void 0 : _a.data;
28934
- if (!commentCached)
28935
- return null;
28936
- return commentLinkedObject(commentCached);
28937
- })
28938
- .filter(Boolean) || []);
28939
- },
28940
- get creator() {
28941
- const cacheData = pullFromCache(['user', 'get', post.postedUserId]);
28942
- if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
28943
- return;
28944
- return userLinkedObject(cacheData.data);
28945
- },
28946
- getImageInfo() {
28947
- var _a, _b;
28948
- return isAmityImagePost(post)
28949
- ? (_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
28950
- : undefined;
28951
- },
28952
- getVideoInfo() {
28953
- var _a, _b, _c;
28954
- return isAmityVideoPost(post)
28955
- ? (_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
28956
- : undefined;
28957
- },
28958
- getVideoThumbnailInfo() {
28959
- var _a, _b;
28960
- return isAmityVideoPost(post)
28961
- ? (_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
28962
- : undefined;
28963
- },
28964
- getFileInfo() {
28965
- var _a, _b;
28966
- return isAmityFilePost(post)
28967
- ? (_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
28968
- : undefined;
28969
- },
28970
- getLivestreamInfo() {
28971
- var _a, _b;
28972
- if (!isAmityLivestreamPost(post))
28973
- return;
28974
- const cache = (_b = pullFromCache([
28975
- 'stream',
28976
- 'get',
28977
- (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.streamId,
28978
- ])) === null || _b === void 0 ? void 0 : _b.data;
28979
- if (!cache)
28980
- return;
28981
- return streamLinkedObject(cache);
28982
- },
28983
- getPollInfo() {
28984
- var _a, _b;
28985
- if (!isAmityPollPost(post))
28986
- return;
28987
- 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;
28988
- if (!cache)
28989
- return;
28990
- return cache;
28991
- },
28992
- getClipInfo() {
28993
- var _a, _b;
28994
- return isAmityClipPost(post)
28995
- ? (_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
28996
- : undefined;
28997
- },
28998
- getAudioInfo() {
28999
- var _a, _b;
29000
- return isAmityAudioPost(post)
29001
- ? (_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
29002
- : undefined;
29003
- },
29004
- getRoomInfo() {
29005
- var _a, _b;
29006
- if (!isAmityRoomPost(post))
29007
- return;
29008
- 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;
29009
- return room ? roomLinkedObject(room) : undefined;
29010
- },
29011
- });
29012
- };
29013
-
29014
- /** @hidden */
29015
- const dispatchReactable = (referenceType, model) => {
29016
- if (referenceType === 'message')
29017
- // @ts-ignore: refactor later
29018
- fireEvent('local.message.updated', { messages: [model] });
29019
- else if (referenceType === 'post')
29020
- // @ts-ignore: refactor later
29021
- fireEvent('post.updated', { posts: [model] });
29022
- else if (referenceType === 'comment')
29023
- // @ts-ignore: refactor later
29024
- fireEvent('comment.updated', { comments: [model] });
29025
- else if (referenceType === 'story')
29026
- // Need to provide all data same StoryPayload from BE
29027
- fireEvent('story.updated', {
29028
- categories: [],
29029
- comments: [],
29030
- communities: [],
29031
- communityUsers: [],
29032
- files: [],
29033
- users: [],
29034
- stories: [model],
29035
- });
29036
- };
29037
-
29038
- const addReaction$1 = async (referenceType, referenceId, reactionName, referenceVersion) => {
29039
- var _a, _b, _c;
29040
- const client = getActiveClient();
29041
- client.log('reaction/createReaction', {
29042
- referenceId,
29043
- referenceType,
29044
- reactionName,
29045
- });
29046
- if (!['post', 'comment', 'story', 'message'].includes(referenceType))
29047
- 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 */);
29048
- const { data } = await client.http.post('/api/v2/reactions', {
29049
- referenceId,
29050
- referenceType,
29051
- reactionName,
29052
- referenceVersion,
29053
- });
29054
- if (client.cache) {
29055
- const model = pullFromCache([
29056
- referenceType,
29057
- 'get',
29058
- referenceId,
29059
- ]);
29060
- if (!model || ((_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName)))
29061
- return true;
29062
- 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() });
29063
- if (referenceType === 'comment') {
29064
- fireEvent('local.comment.addReaction', {
29065
- comment: updatedModel,
29066
- reactor: {
29067
- userId: client.userId,
29068
- reactionName,
29069
- reactionId: data.addedId,
29070
- },
29071
- });
29072
- return true;
29073
- }
29074
- if (referenceType === 'post') {
29075
- fireEvent('local.post.addReaction', {
29076
- post: updatedModel,
29077
- reactor: {
29078
- userId: client.userId,
29079
- reactionName,
29080
- reactionId: data.addedId,
29081
- },
29082
- });
29083
- return true;
29084
- }
29085
- if (referenceType === 'story') {
29086
- fireEvent('local.story.reactionAdded', {
29087
- story: updatedModel,
29088
- reactor: {
29089
- userId: client.userId,
29090
- reactionName,
29091
- reactionId: data.addedId,
29092
- },
29093
- });
29094
- return true;
29095
- }
29096
- }
29097
- return true;
29098
- };
29099
- addReaction$1.optimistically = (referenceType, referenceId, reactionName) => {
29100
- var _a, _b, _c, _d, _e;
29101
- const client = getActiveClient();
29102
- client.log('reaction/createReaction.optimistically', {
29103
- referenceId,
29104
- referenceType,
29105
- reactionName,
29106
- });
29107
- if (!client.cache)
29108
- return;
29109
- const model = pullFromCache([
29110
- referenceType,
29111
- 'get',
29112
- referenceId,
29113
- ]);
29114
- if (!(model === null || model === void 0 ? void 0 : model.data) || ((_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName)))
29115
- return;
29116
- 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 }) });
29117
- upsertInCache([referenceType, 'get', referenceId], reaction, {
29118
- cachedAt: UNSYNCED_OBJECT_CACHED_AT_VALUE,
29119
- });
29120
- dispatchReactable(referenceType, reaction);
29121
- 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;
29122
- };
29123
-
29124
- const removeReaction$1 = async (referenceType, referenceId, reactionName, referenceVersion) => {
29125
- var _a, _b;
29126
- const client = getActiveClient();
29127
- client.log('reaction/removeReaction', {
29128
- referenceId,
29129
- referenceType,
29130
- reactionName,
29131
- });
29132
- if (!['post', 'comment', 'story', 'message'].includes(referenceType))
29133
- 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 */);
29134
- const { data } = await client.http.delete(`/api/v2/reactions`, {
29135
- data: {
29136
- referenceId,
29137
- referenceType,
29138
- reactionName,
29139
- referenceVersion,
29140
- },
29141
- });
29142
- if (client.cache) {
29143
- const model = pullFromCache([
29144
- referenceType,
29145
- 'get',
29146
- referenceId,
29147
- ]);
29148
- if (!model)
29149
- return true;
29150
- 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() });
29151
- if (referenceType === 'comment') {
29152
- fireEvent('local.comment.removeReaction', {
29153
- comment: updatedModel,
29154
- reactor: {
29155
- reactionId: data.removedId,
29156
- reactionName,
29157
- userId: client.userId,
29158
- },
29159
- });
29160
- return true;
29161
- }
29162
- if (referenceType === 'post') {
29163
- fireEvent('local.post.removeReaction', {
29164
- post: updatedModel,
29165
- reactor: {
29166
- reactionId: data.removedId,
29167
- reactionName,
29168
- userId: client.userId,
29169
- },
29170
- });
29171
- return true;
29172
- }
29173
- if (referenceType === 'story') {
29174
- fireEvent('local.story.reactionAdded', {
29175
- story: updatedModel,
29176
- reactor: {
29177
- userId: client.userId,
29178
- reactionName,
29179
- reactionId: data.removedId,
29180
- },
29181
- });
29182
- return true;
29183
- }
29184
- }
29185
- return true;
29186
- };
29187
-
29188
- const addReactionToMessage = (reactionName, message) => {
29189
- const isMessageV3 = message.publicId !== message.messageId;
29190
- return addReaction$1('message', isMessageV3 ? message.publicId : message.messageId, reactionName, isMessageV3 ? 3 : 5);
29191
- };
29192
-
29193
- const getCachedMarker = (message) => {
29194
- var _a, _b;
29195
- const key = {
29196
- creatorId: 'creatorPrivateId' in message ? message.creatorPrivateId : message.creatorId,
29197
- feedId: (_a = message.messageFeedId) !== null && _a !== void 0 ? _a : message.subChannelId,
29198
- contentId: message.messageId,
29199
- };
29200
- return (_b = pullFromCache([
29201
- 'messageMarker',
29202
- 'get',
29203
- getResolver('messageMarker')(key),
29204
- ])) === null || _b === void 0 ? void 0 : _b.data;
29205
- };
29206
- const getMessageReadCount = (message, marker) => {
29207
- var _a;
29208
- // Look in the marker param first
29209
- return (_a = marker !== null && marker !== void 0 ? marker :
29210
- // If the marker param is not set, look in the cache
29211
- getCachedMarker(message)) !== null && _a !== void 0 ? _a : { readCount: 0, deliveredCount: 0 };
29212
- }; // and if not found in cache use default value `0`
29213
-
29214
- const removeReactionToMessage = (reactionName, message) => {
29215
- const isMessageV3 = message.publicId !== message.messageId;
29216
- return removeReaction$1('message', isMessageV3 ? message.publicId : message.messageId, reactionName, isMessageV3 ? 3 : 5);
29217
- };
29218
-
29219
- const messageLinkedObject = (message) => {
29220
- const rest = __rest(message, ["creatorPrivateId"]);
29221
- return Object.assign(Object.assign({}, rest), { get readCount() {
29222
- return getMessageReadCount(message).readCount;
29223
- },
29224
- get deliveredCount() {
29225
- return getMessageReadCount(message).deliveredCount;
29226
- },
29227
- get creator() {
29228
- var _a;
29229
- return (_a = pullFromCache(['user', 'get', message.creatorId])) === null || _a === void 0 ? void 0 : _a.data;
29230
- }, markRead: () => markReadMessage(message), addReaction: (reactionName) => addReactionToMessage(reactionName, message), removeReaction: (reactionName) => removeReactionToMessage(reactionName, message) });
29231
- };
29232
-
29233
- const reactorLinkedObject = (reactor) => {
29234
- return Object.assign(Object.assign({}, reactor), { get user() {
29235
- var _a;
29236
- const user = (_a = pullFromCache(['user', 'get', reactor.userId])) === null || _a === void 0 ? void 0 : _a.data;
29237
- if (!user)
29238
- return undefined;
29239
- return userLinkedObject(user);
29240
- } });
29241
- };
29242
-
29243
- const adLinkedObject = (ad) => {
29244
- const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
29245
- const { image9_16: image916, image1_1: image11 } = ad, restAds = __rest(ad, ["image9_16", "image1_1"]);
29246
- return Object.assign(Object.assign({}, restAds), { analytics: {
29247
- markAsSeen: (placement) => {
29248
- analyticsEngineInstance.markAdAsViewed(ad, placement);
29249
- },
29250
- markLinkAsClicked: (placement) => {
29251
- analyticsEngineInstance.markAdAsClicked(ad, placement);
29252
- },
29253
- }, get advertiser() {
29254
- var _a, _b;
29255
- const advertiserData = (_a = pullFromCache([
29256
- 'advertiser',
29257
- 'get',
29258
- ad.advertiserId,
29259
- ])) === null || _a === void 0 ? void 0 : _a.data;
29260
- if (!advertiserData)
29261
- return;
29262
- const avatarFile = (_b = pullFromCache([
29263
- 'file',
29264
- 'get',
29265
- advertiserData.avatarFileId,
29266
- ])) === null || _b === void 0 ? void 0 : _b.data;
29267
- return Object.assign(Object.assign({}, advertiserData), { avatar: avatarFile });
29268
- },
29269
- get image1_1() {
29270
- const cacheData = pullFromCache(['file', 'get', image11]);
29271
- if (!cacheData)
29272
- return undefined;
29273
- return cacheData.data || undefined;
29274
- },
29275
- get image9_16() {
29276
- const cacheData = pullFromCache(['file', 'get', image916]);
29277
- if (!cacheData)
29278
- return undefined;
29279
- return cacheData.data || undefined;
29280
- } });
29281
- };
29282
-
29283
- const pinnedPostLinkedObject = (pinnedPost) => {
29284
- var _a;
29285
- const postCached = pullFromCache(['post', 'get', pinnedPost.referenceId]);
29286
- const pinnedBy = (_a = queryCache(['user', 'get']).find(cache => {
29287
- var _a;
29288
- return ((_a = cache.data) === null || _a === void 0 ? void 0 : _a.userInternalId) === pinnedPost.pinnedBy;
29289
- })) === null || _a === void 0 ? void 0 : _a.data;
29290
- return Object.assign(Object.assign({}, pinnedPost), { pinnedBy,
29291
- get post() {
29292
- if (!(postCached === null || postCached === void 0 ? void 0 : postCached.data))
29293
- return;
29294
- return postLinkedObject(postCached.data);
29295
- },
29296
- get target() {
29297
- const pinTarget = pullFromCache([
29298
- 'pinTarget',
29299
- 'get',
29300
- postCached === null || postCached === void 0 ? void 0 : postCached.data.targetId,
29301
- ]);
29302
- if (!(pinTarget === null || pinTarget === void 0 ? void 0 : pinTarget.data))
29303
- return;
29304
- return pinTarget === null || pinTarget === void 0 ? void 0 : pinTarget.data;
29305
- } });
29306
- };
29307
-
29308
- const notificationTrayLinkedObject = (noti) => {
29309
- return Object.assign(Object.assign({}, noti), { isSeen: noti.lastSeenAt > noti.lastOccurredAt, isRecent: new Date(noti.lastOccurredAt).getTime() >= Date.now() - WEEK, users: noti.actors
29310
- .map(({ publicId }) => pullFromCache(['user', 'get', publicId]))
29311
- .filter(isNonNullable)
29312
- .map(({ data }) => data)
29313
- .map(user => userLinkedObject(user)) });
29314
- };
29315
-
29316
28934
  /*
29317
28935
  * verifies membership status
29318
28936
  */
@@ -29889,6 +29507,17 @@ const communityLinkedObject = (community) => {
29889
29507
  return undefined;
29890
29508
  })
29891
29509
  .filter(category => !!category);
29510
+ },
29511
+ get avatar() {
29512
+ var _a;
29513
+ if (!community.avatarFileId)
29514
+ return undefined;
29515
+ const avatar = (_a = pullFromCache([
29516
+ 'file',
29517
+ 'get',
29518
+ community.avatarFileId,
29519
+ ])) === null || _a === void 0 ? void 0 : _a.data;
29520
+ return avatar;
29892
29521
  }, createInvitations: async (userIds) => {
29893
29522
  await createInvitations({
29894
29523
  type: "communityMemberInvite" /* InvitationTypeEnum.CommunityMemberInvite */,
@@ -29912,24 +29541,949 @@ const communityLinkedObject = (community) => {
29912
29541
  } });
29913
29542
  };
29914
29543
 
29915
- const eventLinkedObject = (event) => {
29916
- return Object.assign(Object.assign({}, event), { get creator() {
29917
- const cacheData = pullFromCache(['user', 'get', event.userId]);
29544
+ const postLinkedObject = (post) => {
29545
+ return shallowClone(post, {
29546
+ childrenPosts: post.children
29547
+ .map(childPost => { var _a; return (_a = pullFromCache(['post', 'get', childPost])) === null || _a === void 0 ? void 0 : _a.data; })
29548
+ .filter(isNonNullable)
29549
+ .map(postLinkedObject),
29550
+ analytics: {
29551
+ markAsViewed: () => {
29552
+ const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
29553
+ analyticsEngineInstance.markPostAsViewed(post.postId);
29554
+ },
29555
+ },
29556
+ get latestComments() {
29557
+ if (!post.comments)
29558
+ return [];
29559
+ return (post.comments
29560
+ .map(commentId => {
29561
+ var _a;
29562
+ const commentCached = (_a = pullFromCache([
29563
+ 'comment',
29564
+ 'get',
29565
+ commentId,
29566
+ ])) === null || _a === void 0 ? void 0 : _a.data;
29567
+ if (!commentCached)
29568
+ return null;
29569
+ return commentLinkedObject(commentCached);
29570
+ })
29571
+ .filter(Boolean) || []);
29572
+ },
29573
+ get creator() {
29574
+ const cacheData = pullFromCache(['user', 'get', post.postedUserId]);
29918
29575
  if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
29919
29576
  return;
29920
29577
  return userLinkedObject(cacheData.data);
29921
29578
  },
29922
- get discussionCommunity() {
29923
- if (!event.discussionCommunityId)
29579
+ get targetCommunity() {
29580
+ var _a;
29581
+ const communityCache = (_a = pullFromCache([
29582
+ 'community',
29583
+ 'get',
29584
+ post.targetId,
29585
+ ])) === null || _a === void 0 ? void 0 : _a.data;
29586
+ if (!communityCache)
29587
+ return;
29588
+ return communityLinkedObject(communityCache);
29589
+ },
29590
+ getImageInfo() {
29591
+ var _a, _b;
29592
+ return isAmityImagePost(post)
29593
+ ? (_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
29594
+ : undefined;
29595
+ },
29596
+ getVideoInfo() {
29597
+ var _a, _b, _c;
29598
+ return isAmityVideoPost(post)
29599
+ ? (_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
29600
+ : undefined;
29601
+ },
29602
+ getVideoThumbnailInfo() {
29603
+ var _a, _b;
29604
+ return isAmityVideoPost(post)
29605
+ ? (_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
29606
+ : undefined;
29607
+ },
29608
+ getFileInfo() {
29609
+ var _a, _b;
29610
+ return isAmityFilePost(post)
29611
+ ? (_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
29612
+ : undefined;
29613
+ },
29614
+ getLivestreamInfo() {
29615
+ var _a, _b;
29616
+ if (!isAmityLivestreamPost(post))
29617
+ return;
29618
+ const cache = (_b = pullFromCache([
29619
+ 'stream',
29620
+ 'get',
29621
+ (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.streamId,
29622
+ ])) === null || _b === void 0 ? void 0 : _b.data;
29623
+ if (!cache)
29624
+ return;
29625
+ return streamLinkedObject(cache);
29626
+ },
29627
+ getPollInfo() {
29628
+ var _a, _b;
29629
+ if (!isAmityPollPost(post))
29630
+ return;
29631
+ 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;
29632
+ if (!cache)
29633
+ return;
29634
+ return cache;
29635
+ },
29636
+ getClipInfo() {
29637
+ var _a, _b;
29638
+ return isAmityClipPost(post)
29639
+ ? (_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
29640
+ : undefined;
29641
+ },
29642
+ getAudioInfo() {
29643
+ var _a, _b;
29644
+ return isAmityAudioPost(post)
29645
+ ? (_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
29646
+ : undefined;
29647
+ },
29648
+ getRoomInfo() {
29649
+ var _a, _b;
29650
+ if (!isAmityRoomPost(post))
29651
+ return;
29652
+ 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;
29653
+ return room ? roomLinkedObject(room) : undefined;
29654
+ },
29655
+ });
29656
+ };
29657
+
29658
+ /** @hidden */
29659
+ const dispatchReactable = (referenceType, model) => {
29660
+ if (referenceType === 'message')
29661
+ // @ts-ignore: refactor later
29662
+ fireEvent('local.message.updated', { messages: [model] });
29663
+ else if (referenceType === 'post')
29664
+ // @ts-ignore: refactor later
29665
+ fireEvent('post.updated', { posts: [model] });
29666
+ else if (referenceType === 'comment')
29667
+ // @ts-ignore: refactor later
29668
+ fireEvent('comment.updated', { comments: [model] });
29669
+ else if (referenceType === 'story')
29670
+ // Need to provide all data same StoryPayload from BE
29671
+ fireEvent('story.updated', {
29672
+ categories: [],
29673
+ comments: [],
29674
+ communities: [],
29675
+ communityUsers: [],
29676
+ files: [],
29677
+ users: [],
29678
+ stories: [model],
29679
+ });
29680
+ };
29681
+
29682
+ const addReaction$1 = async (referenceType, referenceId, reactionName, referenceVersion) => {
29683
+ var _a, _b, _c;
29684
+ const client = getActiveClient();
29685
+ client.log('reaction/createReaction', {
29686
+ referenceId,
29687
+ referenceType,
29688
+ reactionName,
29689
+ });
29690
+ if (!['post', 'comment', 'story', 'message'].includes(referenceType))
29691
+ 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 */);
29692
+ const { data } = await client.http.post('/api/v2/reactions', {
29693
+ referenceId,
29694
+ referenceType,
29695
+ reactionName,
29696
+ referenceVersion,
29697
+ });
29698
+ if (client.cache) {
29699
+ const model = pullFromCache([
29700
+ referenceType,
29701
+ 'get',
29702
+ referenceId,
29703
+ ]);
29704
+ if (!model || ((_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName)))
29705
+ return true;
29706
+ 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() });
29707
+ if (referenceType === 'comment') {
29708
+ fireEvent('local.comment.addReaction', {
29709
+ comment: updatedModel,
29710
+ reactor: {
29711
+ userId: client.userId,
29712
+ reactionName,
29713
+ reactionId: data.addedId,
29714
+ },
29715
+ });
29716
+ return true;
29717
+ }
29718
+ if (referenceType === 'post') {
29719
+ fireEvent('local.post.addReaction', {
29720
+ post: updatedModel,
29721
+ reactor: {
29722
+ userId: client.userId,
29723
+ reactionName,
29724
+ reactionId: data.addedId,
29725
+ },
29726
+ });
29727
+ return true;
29728
+ }
29729
+ if (referenceType === 'story') {
29730
+ fireEvent('local.story.reactionAdded', {
29731
+ story: updatedModel,
29732
+ reactor: {
29733
+ userId: client.userId,
29734
+ reactionName,
29735
+ reactionId: data.addedId,
29736
+ },
29737
+ });
29738
+ return true;
29739
+ }
29740
+ }
29741
+ return true;
29742
+ };
29743
+ addReaction$1.optimistically = (referenceType, referenceId, reactionName) => {
29744
+ var _a, _b, _c, _d, _e;
29745
+ const client = getActiveClient();
29746
+ client.log('reaction/createReaction.optimistically', {
29747
+ referenceId,
29748
+ referenceType,
29749
+ reactionName,
29750
+ });
29751
+ if (!client.cache)
29752
+ return;
29753
+ const model = pullFromCache([
29754
+ referenceType,
29755
+ 'get',
29756
+ referenceId,
29757
+ ]);
29758
+ if (!(model === null || model === void 0 ? void 0 : model.data) || ((_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName)))
29759
+ return;
29760
+ 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 }) });
29761
+ upsertInCache([referenceType, 'get', referenceId], reaction, {
29762
+ cachedAt: UNSYNCED_OBJECT_CACHED_AT_VALUE,
29763
+ });
29764
+ dispatchReactable(referenceType, reaction);
29765
+ 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;
29766
+ };
29767
+
29768
+ const removeReaction$1 = async (referenceType, referenceId, reactionName, referenceVersion) => {
29769
+ var _a, _b;
29770
+ const client = getActiveClient();
29771
+ client.log('reaction/removeReaction', {
29772
+ referenceId,
29773
+ referenceType,
29774
+ reactionName,
29775
+ });
29776
+ if (!['post', 'comment', 'story', 'message'].includes(referenceType))
29777
+ 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 */);
29778
+ const { data } = await client.http.delete(`/api/v2/reactions`, {
29779
+ data: {
29780
+ referenceId,
29781
+ referenceType,
29782
+ reactionName,
29783
+ referenceVersion,
29784
+ },
29785
+ });
29786
+ if (client.cache) {
29787
+ const model = pullFromCache([
29788
+ referenceType,
29789
+ 'get',
29790
+ referenceId,
29791
+ ]);
29792
+ if (!model)
29793
+ return true;
29794
+ 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() });
29795
+ if (referenceType === 'comment') {
29796
+ fireEvent('local.comment.removeReaction', {
29797
+ comment: updatedModel,
29798
+ reactor: {
29799
+ reactionId: data.removedId,
29800
+ reactionName,
29801
+ userId: client.userId,
29802
+ },
29803
+ });
29804
+ return true;
29805
+ }
29806
+ if (referenceType === 'post') {
29807
+ fireEvent('local.post.removeReaction', {
29808
+ post: updatedModel,
29809
+ reactor: {
29810
+ reactionId: data.removedId,
29811
+ reactionName,
29812
+ userId: client.userId,
29813
+ },
29814
+ });
29815
+ return true;
29816
+ }
29817
+ if (referenceType === 'story') {
29818
+ fireEvent('local.story.reactionAdded', {
29819
+ story: updatedModel,
29820
+ reactor: {
29821
+ userId: client.userId,
29822
+ reactionName,
29823
+ reactionId: data.removedId,
29824
+ },
29825
+ });
29826
+ return true;
29827
+ }
29828
+ }
29829
+ return true;
29830
+ };
29831
+
29832
+ const addReactionToMessage = (reactionName, message) => {
29833
+ const isMessageV3 = message.publicId !== message.messageId;
29834
+ return addReaction$1('message', isMessageV3 ? message.publicId : message.messageId, reactionName, isMessageV3 ? 3 : 5);
29835
+ };
29836
+
29837
+ const getCachedMarker = (message) => {
29838
+ var _a, _b;
29839
+ const key = {
29840
+ creatorId: 'creatorPrivateId' in message ? message.creatorPrivateId : message.creatorId,
29841
+ feedId: (_a = message.messageFeedId) !== null && _a !== void 0 ? _a : message.subChannelId,
29842
+ contentId: message.messageId,
29843
+ };
29844
+ return (_b = pullFromCache([
29845
+ 'messageMarker',
29846
+ 'get',
29847
+ getResolver('messageMarker')(key),
29848
+ ])) === null || _b === void 0 ? void 0 : _b.data;
29849
+ };
29850
+ const getMessageReadCount = (message, marker) => {
29851
+ var _a;
29852
+ // Look in the marker param first
29853
+ return (_a = marker !== null && marker !== void 0 ? marker :
29854
+ // If the marker param is not set, look in the cache
29855
+ getCachedMarker(message)) !== null && _a !== void 0 ? _a : { readCount: 0, deliveredCount: 0 };
29856
+ }; // and if not found in cache use default value `0`
29857
+
29858
+ const removeReactionToMessage = (reactionName, message) => {
29859
+ const isMessageV3 = message.publicId !== message.messageId;
29860
+ return removeReaction$1('message', isMessageV3 ? message.publicId : message.messageId, reactionName, isMessageV3 ? 3 : 5);
29861
+ };
29862
+
29863
+ const messageLinkedObject = (message) => {
29864
+ const rest = __rest(message, ["creatorPrivateId"]);
29865
+ return Object.assign(Object.assign({}, rest), { get readCount() {
29866
+ return getMessageReadCount(message).readCount;
29867
+ },
29868
+ get deliveredCount() {
29869
+ return getMessageReadCount(message).deliveredCount;
29870
+ },
29871
+ get creator() {
29872
+ var _a;
29873
+ return (_a = pullFromCache(['user', 'get', message.creatorId])) === null || _a === void 0 ? void 0 : _a.data;
29874
+ }, markRead: () => markReadMessage(message), addReaction: (reactionName) => addReactionToMessage(reactionName, message), removeReaction: (reactionName) => removeReactionToMessage(reactionName, message) });
29875
+ };
29876
+
29877
+ const reactorLinkedObject = (reactor) => {
29878
+ return Object.assign(Object.assign({}, reactor), { get user() {
29879
+ var _a;
29880
+ const user = (_a = pullFromCache(['user', 'get', reactor.userId])) === null || _a === void 0 ? void 0 : _a.data;
29881
+ if (!user)
29882
+ return undefined;
29883
+ return userLinkedObject(user);
29884
+ } });
29885
+ };
29886
+
29887
+ const adLinkedObject = (ad) => {
29888
+ const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
29889
+ const { image9_16: image916, image1_1: image11 } = ad, restAds = __rest(ad, ["image9_16", "image1_1"]);
29890
+ return Object.assign(Object.assign({}, restAds), { analytics: {
29891
+ markAsSeen: (placement) => {
29892
+ analyticsEngineInstance.markAdAsViewed(ad, placement);
29893
+ },
29894
+ markLinkAsClicked: (placement) => {
29895
+ analyticsEngineInstance.markAdAsClicked(ad, placement);
29896
+ },
29897
+ }, get advertiser() {
29898
+ var _a, _b;
29899
+ const advertiserData = (_a = pullFromCache([
29900
+ 'advertiser',
29901
+ 'get',
29902
+ ad.advertiserId,
29903
+ ])) === null || _a === void 0 ? void 0 : _a.data;
29904
+ if (!advertiserData)
29905
+ return;
29906
+ const avatarFile = (_b = pullFromCache([
29907
+ 'file',
29908
+ 'get',
29909
+ advertiserData.avatarFileId,
29910
+ ])) === null || _b === void 0 ? void 0 : _b.data;
29911
+ return Object.assign(Object.assign({}, advertiserData), { avatar: avatarFile });
29912
+ },
29913
+ get image1_1() {
29914
+ const cacheData = pullFromCache(['file', 'get', image11]);
29915
+ if (!cacheData)
29916
+ return undefined;
29917
+ return cacheData.data || undefined;
29918
+ },
29919
+ get image9_16() {
29920
+ const cacheData = pullFromCache(['file', 'get', image916]);
29921
+ if (!cacheData)
29922
+ return undefined;
29923
+ return cacheData.data || undefined;
29924
+ } });
29925
+ };
29926
+
29927
+ const pinnedPostLinkedObject = (pinnedPost) => {
29928
+ var _a;
29929
+ const postCached = pullFromCache(['post', 'get', pinnedPost.referenceId]);
29930
+ const pinnedBy = (_a = queryCache(['user', 'get']).find(cache => {
29931
+ var _a;
29932
+ return ((_a = cache.data) === null || _a === void 0 ? void 0 : _a.userInternalId) === pinnedPost.pinnedBy;
29933
+ })) === null || _a === void 0 ? void 0 : _a.data;
29934
+ return Object.assign(Object.assign({}, pinnedPost), { pinnedBy,
29935
+ get post() {
29936
+ if (!(postCached === null || postCached === void 0 ? void 0 : postCached.data))
29924
29937
  return;
29925
- const cacheData = pullFromCache([
29926
- 'discussionCommunity',
29938
+ return postLinkedObject(postCached.data);
29939
+ },
29940
+ get target() {
29941
+ const pinTarget = pullFromCache([
29942
+ 'pinTarget',
29927
29943
  'get',
29928
- event.discussionCommunityId,
29944
+ postCached === null || postCached === void 0 ? void 0 : postCached.data.targetId,
29929
29945
  ]);
29946
+ if (!(pinTarget === null || pinTarget === void 0 ? void 0 : pinTarget.data))
29947
+ return;
29948
+ return pinTarget === null || pinTarget === void 0 ? void 0 : pinTarget.data;
29949
+ } });
29950
+ };
29951
+
29952
+ const notificationTrayLinkedObject = (noti) => {
29953
+ return Object.assign(Object.assign({}, noti), { isSeen: noti.lastSeenAt > noti.lastOccurredAt, isRecent: new Date(noti.lastOccurredAt).getTime() >= Date.now() - WEEK, users: noti.actors
29954
+ .map(({ publicId }) => pullFromCache(['user', 'get', publicId]))
29955
+ .filter(isNonNullable)
29956
+ .map(({ data }) => data)
29957
+ .map(user => userLinkedObject(user)), get event() {
29958
+ const cacheData = pullFromCache(['event', 'get', noti.actionReferenceId]);
29930
29959
  if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
29931
29960
  return;
29932
- return communityLinkedObject(cacheData.data);
29961
+ return cacheData.data;
29962
+ } });
29963
+ };
29964
+
29965
+ const prepareEventResponsePayload = (rawPayload) => {
29966
+ return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser) });
29967
+ };
29968
+
29969
+ const eventResponseLinkedObject = (event) => {
29970
+ return Object.assign(Object.assign({}, event), { get status() {
29971
+ return event.status;
29972
+ },
29973
+ get userId() {
29974
+ return event.userId;
29975
+ },
29976
+ get eventId() {
29977
+ return event.eventId;
29978
+ },
29979
+ get respondedAt() {
29980
+ return event.respondedAt;
29981
+ },
29982
+ get event() {
29983
+ const cacheData = pullFromCache(['event', 'get', event.eventId]);
29984
+ if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
29985
+ return;
29986
+ return cacheData.data;
29987
+ },
29988
+ get user() {
29989
+ const cacheData = pullFromCache(['user', 'get', event.userId]);
29990
+ if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
29991
+ return;
29992
+ return userLinkedObject(cacheData.data);
29993
+ } });
29994
+ };
29995
+
29996
+ /* begin_public_function
29997
+ id: event.rsvp.create
29998
+ */
29999
+ /**
30000
+ * ```js
30001
+ * import { event } from '@amityco/ts-sdk'
30002
+ * const response = await event.createRSVP(eventId, status)
30003
+ * ```
30004
+ *
30005
+ * Creates an {@link Amity.EventResponse} for the active user for a specific event.
30006
+ *
30007
+ * @param eventId The ID of the {@link Amity.EventResponse} to create an RSVP for
30008
+ * @param status The RSVP status to set for the event
30009
+ * @returns The {@link Amity.EventResponse} with updated RSVP information
30010
+ *
30011
+ * @category Event API
30012
+ * @async
30013
+ */
30014
+ const createRSVP = async (eventId, status) => {
30015
+ const client = getActiveClient();
30016
+ client.log('event/createRSVP', eventId, status);
30017
+ const { data: payload } = await client.http.post(`/api/v1/events/${eventId}/rsvp`, { status });
30018
+ fireEvent('local.rsvp.created', payload);
30019
+ const data = prepareEventResponsePayload(payload);
30020
+ const cachedAt = client.cache && Date.now();
30021
+ if (client.cache)
30022
+ ingestInCache(data, { cachedAt });
30023
+ return {
30024
+ data: eventResponseLinkedObject(data.eventResponses[0]),
30025
+ cachedAt,
30026
+ };
30027
+ };
30028
+ /* end_public_function */
30029
+
30030
+ /* begin_public_function
30031
+ id: event.update
30032
+ */
30033
+ /**
30034
+ * ```js
30035
+ * import { event } from '@amityco/ts-sdk'
30036
+ * const response = await event.updateRSVP(eventId, status)
30037
+ * ```
30038
+ *
30039
+ * Updates an {@link Amity.EventResponse}
30040
+ *
30041
+ * @param eventId The ID of the {@link Amity.EventResponse} to edit
30042
+ * @param bundle The data necessary to update an existing {@link Amity.EventResponse}
30043
+ * @returns the updated {@link Amity.EventResponse}
30044
+ *
30045
+ * @category Event API
30046
+ * @async
30047
+ */
30048
+ const updateRSVP = async (eventId, status) => {
30049
+ const client = getActiveClient();
30050
+ client.log('event/updateRSVP', eventId, status);
30051
+ const { data: payload } = await client.http.put(`/api/v1/events/${eventId}/rsvp`, { status });
30052
+ fireEvent('local.rsvp.updated', payload);
30053
+ const data = prepareEventResponsePayload(payload);
30054
+ const cachedAt = client.cache && Date.now();
30055
+ if (client.cache)
30056
+ ingestInCache(data, { cachedAt });
30057
+ return {
30058
+ data: eventResponseLinkedObject(data.eventResponses[0]),
30059
+ cachedAt,
30060
+ };
30061
+ };
30062
+ /* end_public_function */
30063
+
30064
+ const prepareEventPayload = (rawPayload) => {
30065
+ return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser) });
30066
+ };
30067
+
30068
+ const createEventEventSubscriber = (event, callback) => {
30069
+ const client = getActiveClient();
30070
+ const filter = (payload) => {
30071
+ const unpackedPayload = prepareEventPayload(payload);
30072
+ if (!client.cache) {
30073
+ callback(unpackedPayload.events[0]);
30074
+ }
30075
+ else {
30076
+ ingestInCache(unpackedPayload);
30077
+ const event = pullFromCache([
30078
+ 'event',
30079
+ 'get',
30080
+ unpackedPayload.events[0].eventId,
30081
+ ]);
30082
+ callback(event.data);
30083
+ }
30084
+ };
30085
+ return createEventSubscriber(client, event, event, filter);
30086
+ };
30087
+
30088
+ const createEventResponseSubscriber = (event, callback) => {
30089
+ const client = getActiveClient();
30090
+ const filter = (payload) => {
30091
+ const unpackedPayload = prepareEventResponsePayload(payload);
30092
+ if (!client.cache) {
30093
+ callback(unpackedPayload);
30094
+ }
30095
+ else {
30096
+ ingestInCache(unpackedPayload.event[0]);
30097
+ const eventResponse = pullFromCache([
30098
+ 'eventResponse',
30099
+ 'get',
30100
+ payload.eventResponses[0].eventId,
30101
+ ]);
30102
+ callback(eventResponse.data);
30103
+ }
30104
+ };
30105
+ return createEventSubscriber(client, event, event, filter);
30106
+ };
30107
+
30108
+ /* begin_public_function
30109
+ id: event.rsvp.me
30110
+ */
30111
+ /**
30112
+ * ```js
30113
+ * import { event } from '@amityco/ts-sdk'
30114
+ * const myRSVP = await event.getMyRSVP()
30115
+ * ```
30116
+ *
30117
+ * Joins a {@link Amity.EventResponse} object
30118
+ *
30119
+ * @param eventId the {@link Amity.EventResponse} to get RSVP for
30120
+ * @returns A success boolean if the {@link Amity.EventResponse} RSVP was retrieved
30121
+ *
30122
+ * @category Event API
30123
+ * @async
30124
+ */
30125
+ const getMyRSVP = async (eventId) => {
30126
+ const client = getActiveClient();
30127
+ client.log('event/getMyRSVP', eventId);
30128
+ const { data: payload } = await client.http.get(`/api/v1/events/${eventId}/me/rsvp`);
30129
+ const data = prepareEventResponsePayload(payload);
30130
+ const cachedAt = client.cache && Date.now();
30131
+ if (client.cache)
30132
+ ingestInCache(data, { cachedAt });
30133
+ return {
30134
+ data: eventResponseLinkedObject(data.eventResponses[0]),
30135
+ cachedAt,
30136
+ };
30137
+ };
30138
+ /* end_public_function */
30139
+ /**
30140
+ * ```js
30141
+ * import { event } from '@amityco/ts-sdk'
30142
+ * const event = event.getMyRSVP.locally(eventId)
30143
+ * ```
30144
+ *
30145
+ * Fetches a {@link Amity.EventResponse} object in cache
30146
+ *
30147
+ * @param eventId the ID of the {@link Amity.EventResponse} to fetch
30148
+ * @returns the associated {@link Amity.EventResponse} object
30149
+ *
30150
+ * @category Event API
30151
+ */
30152
+ getMyRSVP.locally = (eventId) => {
30153
+ const client = getActiveClient();
30154
+ client.log('event/getMyRSVP.locally', eventId);
30155
+ if (!client.cache)
30156
+ return;
30157
+ const cache = pullFromCache(['event', 'getMyRSVP', eventId]);
30158
+ if (!cache)
30159
+ return;
30160
+ return {
30161
+ data: cache.data,
30162
+ cachedAt: cache.cachedAt,
30163
+ };
30164
+ };
30165
+
30166
+ var EventActionsEnum;
30167
+ (function (EventActionsEnum) {
30168
+ EventActionsEnum["OnEventCreated"] = "onEventCreated";
30169
+ EventActionsEnum["OnEventUpdated"] = "onEventUpdated";
30170
+ EventActionsEnum["OnEventDeleted"] = "onEventDeleted";
30171
+ EventActionsEnum["OnRSVPCreated"] = "onRSVPCreated";
30172
+ EventActionsEnum["OnRSVPUpdated"] = "onRSVPUpdated";
30173
+ })(EventActionsEnum || (EventActionsEnum = {}));
30174
+
30175
+ class RSVPPaginationController extends PaginationController {
30176
+ async getRequest(queryParams, token) {
30177
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, eventId } = queryParams, params = __rest(queryParams, ["limit", "eventId"]);
30178
+ const options = token ? { token } : { limit };
30179
+ const { data: response } = await this.http.get(`/api/v1/events/${eventId}/rsvp`, { params: Object.assign(Object.assign({}, params), { options }) });
30180
+ return response;
30181
+ }
30182
+ }
30183
+
30184
+ class RSVPQueryStreamController extends QueryStreamController {
30185
+ constructor(query, cacheKey, notifyChange, preparePayload) {
30186
+ super(query, cacheKey);
30187
+ this.notifyChange = notifyChange;
30188
+ this.preparePayload = preparePayload;
30189
+ }
30190
+ async saveToMainDB(response) {
30191
+ const processedPayload = this.preparePayload(response);
30192
+ const client = getActiveClient();
30193
+ const cachedAt = client.cache && Date.now();
30194
+ if (client.cache)
30195
+ ingestInCache(processedPayload, { cachedAt });
30196
+ }
30197
+ appendToQueryStream(response, direction, refresh = false) {
30198
+ var _a, _b;
30199
+ if (refresh) {
30200
+ pushToCache(this.cacheKey, {
30201
+ data: response.eventResponses.map(getResolver('eventResponse')),
30202
+ });
30203
+ }
30204
+ else {
30205
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
30206
+ const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
30207
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
30208
+ ...new Set([...events, ...response.eventResponses.map(getResolver('eventResponse'))]),
30209
+ ] }));
30210
+ }
30211
+ }
30212
+ reactor(action) {
30213
+ return (event) => {
30214
+ var _a;
30215
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
30216
+ if (!collection)
30217
+ return;
30218
+ if (action === EventActionsEnum.OnRSVPCreated) {
30219
+ collection.data = [...new Set([event.userId, ...collection.data])];
30220
+ }
30221
+ if (action === EventActionsEnum.OnEventDeleted) {
30222
+ collection.data = collection.data.filter(eventId => eventId !== event.eventId);
30223
+ }
30224
+ pushToCache(this.cacheKey, collection);
30225
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
30226
+ };
30227
+ }
30228
+ subscribeRTE(createSubscriber) {
30229
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
30230
+ }
30231
+ }
30232
+
30233
+ /**
30234
+ * ```js
30235
+ * import { EventRepository } from '@amityco/ts-sdk'
30236
+ * const dispose = EventRepository.onEventCreated(event => {
30237
+ * // ...
30238
+ * })
30239
+ * ```
30240
+ *
30241
+ * Fired when an RSVP response for a {@link Amity.Event} has been created
30242
+ *
30243
+ * @param callback The function to call when the event was fired
30244
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30245
+ *
30246
+ * @category Event Events
30247
+ */
30248
+ const onEventCreated = (callback) => createEventEventSubscriber('event.created', callback);
30249
+
30250
+ /**
30251
+ * ```js
30252
+ * import { EventRepository } from '@amityco/ts-sdk'
30253
+ * const dispose = EventRepository.onEventUpdated(event => {
30254
+ * // ...
30255
+ * })
30256
+ * ```
30257
+ *
30258
+ * Fired when a {@link Amity.Event} has been updated
30259
+ *
30260
+ * @param callback The function to call when the event was fired
30261
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30262
+ *
30263
+ * @category Event Events
30264
+ */
30265
+ const onEventUpdated = (callback) => createEventEventSubscriber('event.updated', callback);
30266
+
30267
+ /**
30268
+ * ```js
30269
+ * import { EventRepository } from '@amityco/ts-sdk'
30270
+ * const dispose = EventRepository.onEventDeleted(event => {
30271
+ * // ...
30272
+ * })
30273
+ * ```
30274
+ *
30275
+ * Fired when a {@link Amity.Event} has been deleted
30276
+ *
30277
+ * @param callback The function to call when the event was fired
30278
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30279
+ *
30280
+ * @category Event Events
30281
+ */
30282
+ const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted', callback);
30283
+
30284
+ /**
30285
+ * ```js
30286
+ * import { EventRepository } from '@amityco/ts-sdk'
30287
+ * const dispose = EventRepository.onLocalEventCreated(event => {
30288
+ * // ...
30289
+ * })
30290
+ * ```
30291
+ *
30292
+ * Fired when a {@link Amity.Event} has been created
30293
+ *
30294
+ * @param callback The function to call when the event was fired
30295
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30296
+ *
30297
+ * @category Event Events
30298
+ */
30299
+ const onLocalEventCreated = (callback) => createEventEventSubscriber('local.event.created', callback);
30300
+
30301
+ /**
30302
+ * ```js
30303
+ * import { EventRepository } from '@amityco/ts-sdk'
30304
+ * const dispose = EventRepository.onLocalEventUpdated(event => {
30305
+ * // ...
30306
+ * })
30307
+ * ```
30308
+ *
30309
+ * Fired when a {@link Amity.Event} has been updated
30310
+ *
30311
+ * @param callback The function to call when the event was fired
30312
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30313
+ *
30314
+ * @category Event Events
30315
+ */
30316
+ const onLocalEventUpdated = (callback) => createEventEventSubscriber('local.event.updated', callback);
30317
+
30318
+ /**
30319
+ * ```js
30320
+ * import { EventRepository } from '@amityco/ts-sdk'
30321
+ * const dispose = EventRepository.onLocalEventDeleted(event => {
30322
+ * // ...
30323
+ * })
30324
+ * ```
30325
+ *
30326
+ * Fired when a {@link Amity.Event} has been deleted
30327
+ *
30328
+ * @param callback The function to call when the event was fired
30329
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30330
+ *
30331
+ * @category Event Events
30332
+ */
30333
+ const onLocalEventDeleted = (callback) => createEventEventSubscriber('local.event.deleted', callback);
30334
+
30335
+ /**
30336
+ * ```js
30337
+ * import { EventRepository } from '@amityco/ts-sdk'
30338
+ * const dispose = EventRepository.onRSVPCreated(event => {
30339
+ * // ...
30340
+ * })
30341
+ * ```
30342
+ *
30343
+ * Fired when a {@link Amity.Event} has been created
30344
+ *
30345
+ * @param callback The function to call when the event was fired
30346
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30347
+ *
30348
+ * @category Event Events
30349
+ */
30350
+ const onRSVPCreated = (callback) => createEventResponseSubscriber('event.rsvp.created', callback);
30351
+
30352
+ /**
30353
+ * ```js
30354
+ * import { EventRepository } from '@amityco/ts-sdk'
30355
+ * const dispose = EventRepository.onRSVPUpdated(event => {
30356
+ * // ...
30357
+ * })
30358
+ * ```
30359
+ *
30360
+ * Fired when a {@link Amity.InternalEventResponse} has been updated
30361
+ *
30362
+ * @param callback The function to call when the event was fired
30363
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30364
+ *
30365
+ * @category Event Events
30366
+ */
30367
+ const onRSVPUpdated = (callback) => createEventResponseSubscriber('event.rsvp.updated', callback);
30368
+
30369
+ /**
30370
+ * ```js
30371
+ * import { EventRepository } from '@amityco/ts-sdk'
30372
+ * const dispose = EventRepository.onLocalRSVPCreated(event => {
30373
+ * // ...
30374
+ * })
30375
+ * ```
30376
+ *
30377
+ * Fired when an RSVP response for a {@link Amity.EventResponse} has been created
30378
+ *
30379
+ * @param callback The function to call when the event was fired
30380
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30381
+ *
30382
+ * @category Event Events
30383
+ */
30384
+ const onLocalRSVPCreated = (callback) => createEventResponseSubscriber('local.rsvp.created', callback);
30385
+
30386
+ /**
30387
+ * ```js
30388
+ * import { EventRepository } from '@amityco/ts-sdk'
30389
+ * const dispose = EventRepository.onLocalEventUpdated(event => {
30390
+ * // ...
30391
+ * })
30392
+ * ```
30393
+ *
30394
+ * Fired when an RSVP response for a {@link Amity.EventResponse} has been updated
30395
+ *
30396
+ * @param callback The function to call when the event was fired
30397
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30398
+ *
30399
+ * @category Event Events
30400
+ */
30401
+ const onLocalRSVPUpdated = (callback) => createEventResponseSubscriber('local.rsvp.updated', callback);
30402
+
30403
+ class RSVPLiveCollectionController extends LiveCollectionController {
30404
+ constructor(query, callback) {
30405
+ const queryStreamId = hash(query);
30406
+ const cacheKey = ['eventResponse', 'collection', queryStreamId];
30407
+ const paginationController = new RSVPPaginationController(query);
30408
+ super(paginationController, queryStreamId, cacheKey, callback);
30409
+ this.query = query;
30410
+ this.queryStreamController = new RSVPQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventResponsePayload);
30411
+ this.callback = callback.bind(this);
30412
+ this.loadPage({ initial: true });
30413
+ }
30414
+ setup() {
30415
+ var _a;
30416
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
30417
+ if (!collection)
30418
+ pushToCache(this.cacheKey, { data: [], params: this.query });
30419
+ }
30420
+ async persistModel(queryPayload) {
30421
+ await this.queryStreamController.saveToMainDB(queryPayload);
30422
+ }
30423
+ persistQueryStream({ response, direction, refresh, }) {
30424
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
30425
+ }
30426
+ startSubscription() {
30427
+ return this.queryStreamController.subscribeRTE([
30428
+ { fn: onRSVPCreated, action: EventActionsEnum.OnRSVPCreated },
30429
+ { fn: onRSVPUpdated, action: EventActionsEnum.OnRSVPUpdated },
30430
+ { fn: onLocalRSVPCreated, action: EventActionsEnum.OnRSVPCreated },
30431
+ { fn: onLocalRSVPUpdated, action: EventActionsEnum.OnRSVPUpdated },
30432
+ ]);
30433
+ }
30434
+ notifyChange({ origin, loading, error }) {
30435
+ var _a;
30436
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
30437
+ if (!collection)
30438
+ return;
30439
+ const data = collection.data
30440
+ .map(userId => pullFromCache(['eventResponse', 'get', userId]))
30441
+ .filter(isNonNullable)
30442
+ .map(({ data }) => eventResponseLinkedObject(data));
30443
+ if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
30444
+ return;
30445
+ this.callback({
30446
+ data,
30447
+ error,
30448
+ loading,
30449
+ hasNextPage: !!this.paginationController.getNextToken(),
30450
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
30451
+ });
30452
+ }
30453
+ }
30454
+
30455
+ /**
30456
+ * Get events
30457
+ *
30458
+ * @param params the query parameters
30459
+ * @param callback the callback to be called when the events are updated
30460
+ * @returns events
30461
+ *
30462
+ * @category RSVP Live Collection
30463
+ *
30464
+ */
30465
+ const getRSVPs = (params, callback, config) => {
30466
+ const { log, cache } = getActiveClient();
30467
+ if (!cache)
30468
+ console.log(ENABLE_CACHE_MESSAGE);
30469
+ const timestamp = Date.now();
30470
+ log(`getRSVPs: (tmpid: ${timestamp}) > listen`);
30471
+ const rsvpLiveCollection = new RSVPLiveCollectionController(params, callback);
30472
+ const disposers = rsvpLiveCollection.startSubscription();
30473
+ const cacheKey = rsvpLiveCollection.getCacheKey();
30474
+ disposers.push(() => dropFromCache(cacheKey));
30475
+ return () => {
30476
+ log(`getRSVPs (tmpid: ${timestamp}) > dispose`);
30477
+ disposers.forEach(fn => fn());
30478
+ };
30479
+ };
30480
+
30481
+ const eventLinkedObject = (event) => {
30482
+ return Object.assign(Object.assign({}, event), { get creator() {
30483
+ const cacheData = pullFromCache(['user', 'get', event.userId]);
30484
+ if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
30485
+ return;
30486
+ return userLinkedObject(cacheData.data);
29933
30487
  },
29934
30488
  get targetCommunity() {
29935
30489
  if (!event.originId)
@@ -29947,13 +30501,33 @@ const eventLinkedObject = (event) => {
29947
30501
  return;
29948
30502
  return cacheData.data;
29949
30503
  },
29950
- get liveStream() {
29951
- if (!event.livestreamId)
30504
+ get post() {
30505
+ if (!event.postId)
29952
30506
  return;
29953
- const cacheData = pullFromCache(['stream', 'get', event.livestreamId]);
30507
+ const cacheData = pullFromCache(['post', 'get', event.postId]);
29954
30508
  if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
29955
30509
  return;
29956
- return cacheData.data;
30510
+ return postLinkedObject(cacheData.data);
30511
+ },
30512
+ get room() {
30513
+ var _a;
30514
+ if (!event.postId)
30515
+ return;
30516
+ const cacheData = (_a = queryCache(['room', 'get'])) === null || _a === void 0 ? void 0 : _a.filter(room => room.data.referenceId === event.postId);
30517
+ if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.length) || !cacheData[0].data)
30518
+ return;
30519
+ return roomLinkedObject(cacheData[0].data);
30520
+ }, createRSVP: async (status) => {
30521
+ const { data } = await createRSVP(event.eventId, status);
30522
+ return data;
30523
+ }, updateRSVP: async (status) => {
30524
+ const { data } = await updateRSVP(event.eventId, status);
30525
+ return data;
30526
+ }, getMyRSVP: async () => {
30527
+ const { data } = await getMyRSVP(event.eventId);
30528
+ return data;
30529
+ }, getRSVPs: (params, callback) => {
30530
+ return getRSVPs(Object.assign({ eventId: event.eventId }, params), callback);
29957
30531
  } });
29958
30532
  };
29959
30533
 
@@ -29977,6 +30551,7 @@ const LinkedObject = {
29977
30551
  channelMember: channelMemberLinkedObject,
29978
30552
  room: roomLinkedObject,
29979
30553
  event: eventLinkedObject,
30554
+ eventResponse: eventResponseLinkedObject,
29980
30555
  };
29981
30556
 
29982
30557
  /* begin_public_function
@@ -42450,6 +43025,15 @@ const getPostSubscription = (cacheKey) => {
42450
43025
  ...generateCommentSubscriptions({ cacheKey }),
42451
43026
  ];
42452
43027
  };
43028
+ const resolvePostIdsFromRooms = (rooms, posts) => {
43029
+ var _a;
43030
+ return ((_a = rooms
43031
+ .map(room => {
43032
+ const post = posts.find(post => post.postId === room.referenceId);
43033
+ return post ? getResolver('post')({ postId: post === null || post === void 0 ? void 0 : post.postId }) : undefined;
43034
+ })
43035
+ .filter(isNonNullable)) !== null && _a !== void 0 ? _a : []);
43036
+ };
42453
43037
 
42454
43038
  class PostLiveCollectionController extends LiveCollectionController {
42455
43039
  constructor(query, callback) {
@@ -43333,522 +43917,839 @@ const searchPostsByHashtag = (params, callback, config) => {
43333
43917
  disposers.forEach(fn => fn());
43334
43918
  };
43335
43919
  };
43336
- /* end_public_function */
43337
-
43338
- var index$b = /*#__PURE__*/Object.freeze({
43339
- __proto__: null,
43340
- getPostByIds: getPostByIds,
43341
- createPost: createPost,
43342
- editPost: editPost,
43343
- deletePost: deletePost,
43344
- softDeletePost: softDeletePost,
43345
- hardDeletePost: hardDeletePost,
43346
- approvePost: approvePost,
43347
- declinePost: declinePost,
43348
- flagPost: flagPost,
43349
- unflagPost: unflagPost,
43350
- isPostFlaggedByMe: isPostFlaggedByMe,
43351
- createClipPost: createClipPost,
43352
- createAudioPost: createAudioPost,
43353
- createMixedMediaPost: createMixedMediaPost,
43354
- onPostCreated: onPostCreated,
43355
- onPostUpdated: onPostUpdated,
43356
- onPostDeleted: onPostDeleted,
43357
- onPostApproved: onPostApproved,
43358
- onPostDeclined: onPostDeclined,
43359
- onPostFlagged: onPostFlagged,
43360
- onPostUnflagged: onPostUnflagged,
43361
- onPostReactionAdded: onPostReactionAdded,
43362
- onPostReactionRemoved: onPostReactionRemoved,
43363
- getPost: getPost,
43364
- getPosts: getPosts,
43365
- getPinnedPosts: getPinnedPosts,
43366
- getGlobalPinnedPosts: getGlobalPinnedPosts,
43367
- semanticSearchPosts: semanticSearchPosts,
43368
- searchPostsByHashtag: searchPostsByHashtag
43369
- });
43920
+ /* end_public_function */
43921
+
43922
+ class LiveRoomPostPaginationController extends PaginationNoPageController {
43923
+ async getRequest(queryParams) {
43924
+ const { limit = 100 } = queryParams;
43925
+ const { data: queryResponse } = await this.http.get(`/api/v1/rooms/lives`, {
43926
+ params: {
43927
+ targetTypes: ['all'],
43928
+ options: {
43929
+ limit,
43930
+ sortBy: 'lastCreated',
43931
+ },
43932
+ },
43933
+ });
43934
+ return queryResponse;
43935
+ }
43936
+ }
43937
+
43938
+ class LiveRoomPostQueryStreamController extends QueryStreamController {
43939
+ constructor(query, cacheKey, notifyChange, preparePayload) {
43940
+ super(query, cacheKey);
43941
+ this.notifyChange = notifyChange;
43942
+ this.preparePayload = preparePayload;
43943
+ }
43944
+ async saveToMainDB(response) {
43945
+ const processedPayload = await this.preparePayload(response);
43946
+ const client = getActiveClient();
43947
+ const cachedAt = client.cache && Date.now();
43948
+ if (client.cache) {
43949
+ ingestInCache(processedPayload, { cachedAt });
43950
+ }
43951
+ }
43952
+ appendToQueryStream(response, direction, refresh = false) {
43953
+ var _a, _b;
43954
+ if (refresh) {
43955
+ pushToCache(this.cacheKey, {
43956
+ data: resolvePostIdsFromRooms(response.rooms, response.posts),
43957
+ });
43958
+ }
43959
+ else {
43960
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
43961
+ const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
43962
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...resolvePostIdsFromRooms(response.rooms, response.posts)])] }));
43963
+ }
43964
+ }
43965
+ reactor(action) {
43966
+ return (room) => {
43967
+ var _a;
43968
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
43969
+ if (!collection)
43970
+ return;
43971
+ if (room.status === 'ended') {
43972
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: collection.data.filter(postId => room.referenceId !== postId) }));
43973
+ }
43974
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
43975
+ };
43976
+ }
43977
+ subscribeRTE(createSubscriber) {
43978
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
43979
+ }
43980
+ }
43981
+
43982
+ /* begin_public_function
43983
+ id: room.create
43984
+ */
43985
+ /**
43986
+ * ```js
43987
+ * import { createRoom } from '@amityco/ts-sdk'
43988
+ * const created = await createRoom({ title: 'my room', 'thumbnailFileId': fileId })
43989
+ * ```
43990
+ *
43991
+ * Creates an {@link Amity.Room}
43992
+ *
43993
+ * @param bundle The data necessary to create a new {@link Amity.Room}
43994
+ * @returns The newly created {@link Amity.Room}
43995
+ *
43996
+ * @category Room API
43997
+ * @async
43998
+ */
43999
+ const createRoom = async (bundle) => {
44000
+ const client = getActiveClient();
44001
+ client.log('room/createRoom', bundle);
44002
+ const { data } = await client.http.post('/api/v1/rooms', bundle);
44003
+ fireEvent('local.room.created', data);
44004
+ const cachedAt = client.cache && Date.now();
44005
+ // TODO: check if should pick `users` filed which contains participants - if no need to ingest in the cache
44006
+ if (client.cache)
44007
+ ingestInCache(data, { cachedAt });
44008
+ const { rooms } = data;
44009
+ return {
44010
+ data: roomLinkedObject(rooms[0]),
44011
+ cachedAt,
44012
+ };
44013
+ };
44014
+ /* end_public_function */
44015
+
44016
+ /* begin_public_function
44017
+ id: room.update
44018
+ */
44019
+ /**
44020
+ * ```js
44021
+ * import { updateRoom } from '@amityco/ts-sdk'
44022
+ * const updated = await updateRoom('roomId', { title: 'updated title' })
44023
+ * ```
44024
+ *
44025
+ * Updates an {@link Amity.InternalRoom}
44026
+ *
44027
+ * @param roomId The ID of the room to update
44028
+ * @param bundle The data to update the room with
44029
+ * @returns The updated {@link Amity.InternalRoom}
44030
+ *
44031
+ * @category Room API
44032
+ * @async
44033
+ */
44034
+ const updateRoom = async (roomId, bundle) => {
44035
+ const client = getActiveClient();
44036
+ client.log('room/updateRoom', { roomId, bundle });
44037
+ const { data } = await client.http.put(`/api/v1/rooms/${roomId}`, bundle);
44038
+ fireEvent('local.room.updated', data);
44039
+ const cachedAt = client.cache && Date.now();
44040
+ if (client.cache)
44041
+ ingestInCache(data, { cachedAt });
44042
+ const { rooms } = data;
44043
+ return {
44044
+ data: roomLinkedObject(rooms[0]),
44045
+ cachedAt,
44046
+ };
44047
+ };
44048
+ /* end_public_function */
44049
+
44050
+ /* begin_public_function
44051
+ id: room.delete
44052
+ */
44053
+ /**
44054
+ * ```js
44055
+ * import { deleteRoom } from '@amityco/ts-sdk'
44056
+ * const result = await deleteRoom('roomId')
44057
+ * ```
44058
+ *
44059
+ * Deletes an {@link Amity.Room}
44060
+ *
44061
+ * @param roomId The ID of the room to delete
44062
+ * @returns Promise that resolves when the room is deleted
44063
+ *
44064
+ * @category Room API
44065
+ * @async
44066
+ */
44067
+ const deleteRoom = async (roomId) => {
44068
+ const client = getActiveClient();
44069
+ client.log('room/deleteRoom', { roomId });
44070
+ await client.http.delete(`/api/v1/rooms/${roomId}`);
44071
+ fireEvent('local.room.deleted', { rooms: [{ _id: roomId }] });
44072
+ };
44073
+ /* end_public_function */
44074
+
44075
+ /* begin_public_function
44076
+ id: room.stop
44077
+ */
44078
+ /**
44079
+ * ```js
44080
+ * import { stopRoom } from '@amityco/ts-sdk'
44081
+ * const result = await stopRoom('roomId')
44082
+ * ```
44083
+ *
44084
+ * Stops a room's broadcasting
44085
+ *
44086
+ * @param roomId The ID of the room to stop
44087
+ * @returns The updated room data
44088
+ *
44089
+ * @category Room API
44090
+ * @async
44091
+ */
44092
+ const stopRoom = async (roomId) => {
44093
+ const client = getActiveClient();
44094
+ client.log('room/stopRoom', { roomId });
44095
+ const { data } = await client.http.post(`/api/v1/rooms/${roomId}/stop`);
44096
+ fireEvent('local.room.stopped', data);
44097
+ const cachedAt = client.cache && Date.now();
44098
+ if (client.cache)
44099
+ ingestInCache(data, { cachedAt });
44100
+ const { rooms } = data;
44101
+ return {
44102
+ data: rooms[0],
44103
+ cachedAt,
44104
+ };
44105
+ };
44106
+ /* end_public_function */
44107
+
44108
+ /* begin_public_function
44109
+ id: room.getBroadcasterData
44110
+ */
44111
+ /**
44112
+ * ```js
44113
+ * import { getBroadcasterData } from '@amityco/ts-sdk'
44114
+ * const token = await getBroadcasterData('roomId')
44115
+ * ```
44116
+ *
44117
+ * Gets broadcaster data for a room
44118
+ *
44119
+ * @param roomId The ID of the room to get token for
44120
+ * @returns The broadcaster data of the room including coHostToken, coHostUrl and direactStreamUrl
44121
+ *
44122
+ * @category Room API
44123
+ * @async
44124
+ */
44125
+ const getBroadcasterData = async (roomId) => {
44126
+ const client = getActiveClient();
44127
+ client.log('room/getBroadcasterData', { roomId });
44128
+ const { data } = await client.http.get(`/api/v1/rooms/${roomId}/token`);
44129
+ return data;
44130
+ };
44131
+ /* end_public_function */
44132
+
44133
+ /* begin_public_function
44134
+ id: room.getRecordedUrl
44135
+ */
44136
+ /**
44137
+ * ```js
44138
+ * import { getRecordedUrl } from '@amityco/ts-sdk'
44139
+ * const recordedUrl = await getRecordedUrl('roomId')
44140
+ * ```
44141
+ *
44142
+ * Gets the recorded URL for a room
44143
+ *
44144
+ * @param roomId The ID of the room to get recorded URL for
44145
+ * @returns The recorded URL information
44146
+ *
44147
+ * @category Room API
44148
+ * @async
44149
+ */
44150
+ const getRecordedUrl = async (roomId) => {
44151
+ const client = getActiveClient();
44152
+ client.log('room/getRecordedUrl', { roomId });
44153
+ const { data } = await client.http.get(`/api/v1/rooms/${roomId}/recorded`);
44154
+ return data;
44155
+ };
44156
+ /* end_public_function */
44157
+
44158
+ /* begin_public_function
44159
+ id: room.removeParticipant
44160
+ */
44161
+ /**
44162
+ * ```js
44163
+ * import { removeParticipant } from '@amityco/ts-sdk'
44164
+ * const result = await removeParticipant('roomId', 'participantUserId')
44165
+ * ```
44166
+ *
44167
+ * Removes a participant from an {@link Amity.Room}
44168
+ *
44169
+ * @param roomId The ID of the room to remove participant from
44170
+ * @param participantUserId The ID of the user to remove as participant
44171
+ * @returns Promise that resolves when the participant is removed
44172
+ *
44173
+ * @category Room API
44174
+ * @async
44175
+ */
44176
+ const removeParticipant = async (roomId, participantUserId) => {
44177
+ const client = getActiveClient();
44178
+ client.log('room/removeParticipant', { roomId, participantUserId });
44179
+ await client.http.delete(`/api/v1/rooms/${roomId}/participants/${participantUserId}`);
44180
+ fireEvent('local.room.participantRemoved', {
44181
+ rooms: [{ _id: roomId }],
44182
+ users: [{ _id: participantUserId }],
44183
+ });
44184
+ };
44185
+ /* end_public_function */
44186
+
44187
+ /* begin_public_function
44188
+ id: room.leave
44189
+ */
44190
+ /**
44191
+ * ```js
44192
+ * import { leaveRoom } from '@amityco/ts-sdk'
44193
+ * const result = await leaveRoom('roomId')
44194
+ * ```
44195
+ *
44196
+ * Leaves an {@link Amity.Room}
44197
+ *
44198
+ * @param roomId The ID of the room to leave
44199
+ * @returns Promise that resolves when the user has left the room
44200
+ *
44201
+ * @category Room API
44202
+ * @async
44203
+ */
44204
+ const leaveRoom = async (roomId) => {
44205
+ const client = getActiveClient();
44206
+ client.log('room/leaveRoom', { roomId });
44207
+ await client.http.post(`/api/v1/rooms/${roomId}/leave`);
44208
+ fireEvent('local.room.left', {
44209
+ rooms: [{ _id: roomId }],
44210
+ });
44211
+ };
44212
+ /* end_public_function */
44213
+
44214
+ /**
44215
+ * ```js
44216
+ * import { onRoomStartBroadcasting } from '@amityco/ts-sdk'
44217
+ * const dispose = onRoomStartBroadcasting(room => {
44218
+ * // ...
44219
+ * })
44220
+ * ```
44221
+ *
44222
+ * Fired when a {@link Amity.Room} has started broadcasting
44223
+ *
44224
+ * @param callback The function to call when the event was fired
44225
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44226
+ *
44227
+ * @category Room Events
44228
+ */
44229
+ const onRoomStartBroadcasting = (callback) => {
44230
+ const client = getActiveClient();
44231
+ const filter = (payload) => {
44232
+ ingestInCache(payload);
44233
+ callback(payload.rooms[0]);
44234
+ };
44235
+ return createEventSubscriber(client, 'room/onRoomStartBroadcasting', 'room.startBroadcasting', filter);
44236
+ };
44237
+
44238
+ /**
44239
+ * ```js
44240
+ * import { onRoomWaitingReconnect } from '@amityco/ts-sdk'
44241
+ * const dispose = onRoomWaitingReconnect(room => {
44242
+ * // ...
44243
+ * })
44244
+ * ```
44245
+ *
44246
+ * Fired when a {@link Amity.Room} is waiting for reconnection
44247
+ *
44248
+ * @param callback The function to call when the event was fired
44249
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44250
+ *
44251
+ * @category Room Events
44252
+ */
44253
+ const onRoomWaitingReconnect = (callback) => {
44254
+ const client = getActiveClient();
44255
+ const filter = (payload) => {
44256
+ ingestInCache(payload);
44257
+ callback(payload.rooms[0]);
44258
+ };
44259
+ return createEventSubscriber(client, 'room/onRoomWaitingReconnect', 'room.waitingReconnect', filter);
44260
+ };
43370
44261
 
43371
- /* begin_public_function
43372
- id: stream.create
43373
- */
43374
44262
  /**
43375
44263
  * ```js
43376
- * import { createStream } from '@amityco/ts-sdk'
43377
- * const created = await createStream({ title: 'my stream', 'thumbnailFileId': fileId })
44264
+ * import { onRoomEndBroadcasting } from '@amityco/ts-sdk'
44265
+ * const dispose = onRoomEndBroadcasting(room => {
44266
+ * // ...
44267
+ * })
43378
44268
  * ```
43379
44269
  *
43380
- * Creates an {@link Amity.InternalStream}
44270
+ * Fired when a {@link Amity.Room} has ended broadcasting
43381
44271
  *
43382
- * @param bundle The data necessary to create a new {@link Amity.InternalStream}
43383
- * @returns The newly created {@link Amity.InternalStream}
44272
+ * @param callback The function to call when the event was fired
44273
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
43384
44274
  *
43385
- * @category Stream API
43386
- * @async
44275
+ * @category Room Events
43387
44276
  */
43388
- const createStream = async (bundle) => {
44277
+ const onRoomEndBroadcasting = (callback) => {
43389
44278
  const client = getActiveClient();
43390
- client.log('stream/createStream', bundle);
43391
- const { data } = await client.http.post('/api/v3/video-streaming', bundle);
43392
- const cachedAt = client.cache && Date.now();
43393
- if (client.cache)
43394
- ingestInCache(data, { cachedAt });
43395
- const { videoStreamings } = data;
43396
- return {
43397
- data: LinkedObject.stream(videoStreamings[0]),
43398
- cachedAt,
44279
+ const filter = (payload) => {
44280
+ ingestInCache(payload);
44281
+ callback(payload.rooms[0]);
43399
44282
  };
44283
+ return createEventSubscriber(client, 'room/onRoomEndBroadcasting', 'room.endBroadcasting', filter);
43400
44284
  };
43401
- /* end_public_function */
43402
44285
 
43403
- /* begin_public_function
43404
- id: stream.update
43405
- */
43406
44286
  /**
43407
- * @deprecated this function is deprecated,
43408
- * please use {@link Amity.StreamRepository.editStream} instead.
43409
- *
43410
44287
  * ```js
43411
- * import { updateStream } from '@amityco/ts-sdk'
43412
- * const updated = await updateStream(streamId, { title: 'foobar' })
44288
+ * import { onRoomRecordedAvailable } from '@amityco/ts-sdk'
44289
+ * const dispose = onRoomRecordedAvailable(room => {
44290
+ * // ...
44291
+ * })
43413
44292
  * ```
43414
44293
  *
43415
- * Updates an {@link Amity.Stream}
44294
+ * Fired when a {@link Amity.Room} recorded content becomes available
43416
44295
  *
43417
- * @param streamId The ID of the {@link Amity.Stream} to edit
43418
- * @param patch The patch data to apply
43419
- * @returns the updated {@link Amity.Stream} object
44296
+ * @param callback The function to call when the event was fired
44297
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
43420
44298
  *
43421
- * @category Stream API
43422
- * @async
44299
+ * @category Room Events
43423
44300
  */
43424
- const updateStream = async (streamId, patch) => {
44301
+ const onRoomRecordedAvailable = (callback) => {
43425
44302
  const client = getActiveClient();
43426
- client.log('stream/updateStream', streamId, patch);
43427
- const { data } = await client.http.put(`/api/v3/video-streaming/${streamId}`, patch);
43428
- const cachedAt = client.cache && Date.now();
43429
- if (client.cache)
43430
- ingestInCache(data, { cachedAt });
43431
- const { videoStreamings } = data;
43432
- return {
43433
- data: LinkedObject.stream(videoStreamings.find(stream => stream.streamId === streamId)),
43434
- cachedAt,
44303
+ const filter = (payload) => {
44304
+ ingestInCache(payload);
44305
+ callback(payload.rooms[0]);
43435
44306
  };
44307
+ return createEventSubscriber(client, 'room/onRoomRecordedAvailable', 'room.recordedAvailable', filter);
43436
44308
  };
43437
- /* end_public_function */
43438
44309
 
43439
- /* begin_public_function
43440
- id: stream.get
43441
- */
43442
44310
  /**
43443
44311
  * ```js
43444
- * import { getStream } from '@amityco/ts-sdk'
43445
- * const stream = await getStream('foobar')
44312
+ * import { onRoomParticipantInviting } from '@amityco/ts-sdk'
44313
+ * const dispose = onRoomParticipantInviting(room => {
44314
+ * // ...
44315
+ * })
43446
44316
  * ```
43447
44317
  *
43448
- * Fetches a {@link Amity.Stream} object
44318
+ * Fired when a participant is being invited to a {@link Amity.Room}
43449
44319
  *
43450
- * @param streamId the ID of the {@link Amity.Stream} to fetch
43451
- * @returns the associated {@link Amity.Stream} object
44320
+ * @param callback The function to call when the event was fired
44321
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
43452
44322
  *
43453
- * @category Stream API
43454
- * @async
44323
+ * @category Room Events
43455
44324
  */
43456
- const getStream = async (streamId) => {
44325
+ const onRoomCoHostInvited = (callback) => {
43457
44326
  const client = getActiveClient();
43458
- client.log('stream/getStream', streamId);
43459
- const { data } = await client.http.get(`/api/v3/video-streaming/${streamId}`);
44327
+ const filter = (payload) => {
44328
+ const data = prepareMyInvitationsPayload(payload);
44329
+ ingestInCache(data);
44330
+ callback(data.invitations);
44331
+ };
44332
+ return createEventSubscriber(client, 'room/onRoomCoHostInvited', 'room.didCohostInvite', filter);
44333
+ };
44334
+
44335
+ const getRoomById = async (roomId) => {
44336
+ const client = getActiveClient();
44337
+ client.log('room/getRoomById', roomId);
44338
+ // Check if room is in tombstone
44339
+ isInTombstone('room', roomId);
44340
+ let data;
44341
+ try {
44342
+ const response = await client.http.get(`/api/v1/rooms/${roomId}`);
44343
+ data = response.data;
44344
+ }
44345
+ catch (error) {
44346
+ if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
44347
+ pushToTombstone('room', roomId);
44348
+ }
44349
+ throw error;
44350
+ }
43460
44351
  const cachedAt = client.cache && Date.now();
43461
- if (client.cache)
44352
+ if (client.cache) {
43462
44353
  ingestInCache(data, { cachedAt });
43463
- const { videoStreamings } = data;
44354
+ }
43464
44355
  return {
43465
- data: videoStreamings.find(stream => stream.streamId === streamId),
44356
+ data: data.rooms[0],
43466
44357
  cachedAt,
43467
44358
  };
43468
44359
  };
43469
- /* end_public_function */
44360
+ getRoomById.locally = (roomId) => {
44361
+ const client = getActiveClient();
44362
+ client.log('room/getRoomById.locally', roomId);
44363
+ // Check if room is in tombstone
44364
+ isInTombstone('room', roomId);
44365
+ const cachedAt = client.cache && Date.now();
44366
+ const roomCache = pullFromCache(['room', 'get', roomId]);
44367
+ if (!roomCache)
44368
+ return;
44369
+ return {
44370
+ data: roomCache.data,
44371
+ cachedAt,
44372
+ };
44373
+ };
44374
+
43470
44375
  /**
43471
44376
  * ```js
43472
- * import { getStream } from '@amityco/ts-sdk'
43473
- * const stream = getStream.locally('foobar')
44377
+ * import { onRoomCoHostInviteAccepted } from '@amityco/ts-sdk'
44378
+ * const dispose = onRoomCoHostInviteAccepted(room => {
44379
+ * // ...
44380
+ * })
43474
44381
  * ```
43475
44382
  *
43476
- * Fetches a {@link Amity.Stream} object
44383
+ * Fired when a co-host invitation is accepted for a {@link Amity.Room}
43477
44384
  *
43478
- * @param streamId the ID of the {@link Amity.Stream} to fetch
43479
- * @returns the associated {@link Amity.Stream} object
44385
+ * @param callback The function to call when the event was fired
44386
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
43480
44387
  *
43481
- * @category Stream API
44388
+ * @category Room Events
43482
44389
  */
43483
- getStream.locally = (streamId) => {
44390
+ const onRoomCoHostInviteAccepted = (callback) => {
43484
44391
  const client = getActiveClient();
43485
- client.log('stream/getStream', streamId);
43486
- if (!client.cache)
43487
- return;
43488
- const cached = pullFromCache(['stream', 'get', streamId]);
43489
- if (!cached)
43490
- return;
43491
- return {
43492
- data: cached.data,
43493
- cachedAt: cached.cachedAt,
44392
+ const filter = async (payload) => {
44393
+ var _a;
44394
+ const data = prepareMyInvitationsPayload(payload);
44395
+ await getRoomById((_a = data.invitations) === null || _a === void 0 ? void 0 : _a[0].targetId);
44396
+ ingestInCache(data);
44397
+ callback(data.invitations[0]);
43494
44398
  };
44399
+ return createEventSubscriber(client, 'room/onRoomCoHostInviteAccepted', 'room.didCohostInviteAccept', filter);
43495
44400
  };
43496
44401
 
43497
- // import { unwrapPayload } from '~/core/transports'
43498
- /* begin_public_function
43499
- id: stream.delete
43500
- */
43501
44402
  /**
43502
44403
  * ```js
43503
- * import { deleteStream } from '@amityco/ts-sdk'
43504
- * const success = await deleteStream(streamId)
44404
+ * import { onRoomCoHostInviteRejected } from '@amityco/ts-sdk'
44405
+ * const dispose = onRoomCoHostInviteRejected(room => {
44406
+ * // ...
44407
+ * })
43505
44408
  * ```
43506
44409
  *
43507
- * Deletes a {@link Amity.InternalStream}
44410
+ * Fired when a co-host invitation is rejected for a {@link Amity.Room}
43508
44411
  *
43509
- * @param streamId The {@link Amity.InternalStream} ID to delete
43510
- * @return A success boolean if the {@link Amity.InternalStream} was deleted
44412
+ * @param callback The function to call when the event was fired
44413
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
43511
44414
  *
43512
- * @category Stream API
43513
- * @async
44415
+ * @category Room Events
43514
44416
  */
43515
- const deleteStream = async (streamId) => {
44417
+ const onRoomCoHostInviteRejected = (callback) => {
43516
44418
  const client = getActiveClient();
43517
- client.log('stream/deleteStream', streamId);
43518
- const stream = await getStream(streamId);
43519
- // API-FIX: it returns { success: boolean } but seems it should be Amity.Response<{ success: boolean }
43520
- // API-FIX: swagger docs are wrong!
43521
- const { data } = await client.http.delete(`/api/v3/video-streaming/${streamId}`);
43522
- const { success } = data; // unwrapPayload(data)
43523
- const deleted = Object.assign(Object.assign({}, stream.data), { isDeleted: true });
43524
- upsertInCache(['stream', 'get', streamId], deleted);
43525
- return success;
44419
+ const filter = (payload) => {
44420
+ const data = prepareMyInvitationsPayload(payload);
44421
+ ingestInCache(data);
44422
+ callback(data.invitations);
44423
+ };
44424
+ return createEventSubscriber(client, 'room/onRoomCoHostInviteRejected', 'room.didCohostInviteReject', filter);
43526
44425
  };
43527
- /* end_public_function */
43528
44426
 
43529
44427
  /**
43530
44428
  * ```js
43531
- * import { disposeStream } from '@amityco/ts-sdk'
43532
- * const stream = await disposeStream(streamId)
44429
+ * import { onRoomCoHostInviteCanceled } from '@amityco/ts-sdk'
44430
+ * const dispose = onRoomCoHostInviteCanceled(room => {
44431
+ * // ...
44432
+ * })
43533
44433
  * ```
43534
44434
  *
43535
- * Dispose a {@link Amity.InternalStream}.
43536
- * Streaming status will be updated to "ended" and streaming url will be invalidated
44435
+ * Fired when a co-host invitation is canceled for a {@link Amity.Room}
43537
44436
  *
43538
- * @param streamId The {@link Amity.InternalStream} ID to dispose
43539
- * @returns the associated {@link Amity.InternalStream} object
44437
+ * @param callback The function to call when the event was fired
44438
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
43540
44439
  *
43541
- * @category Stream API
43542
- * @async
44440
+ * @category Room Events
43543
44441
  */
43544
- const disposeStream = async (streamId) => {
44442
+ const onRoomCoHostInviteCanceled = (callback) => {
43545
44443
  const client = getActiveClient();
43546
- client.log('stream/disposeStream', streamId);
43547
- const { data } = await client.http.delete(`/api/v3/video-streaming/${streamId}/streaming-url`);
43548
- const cachedAt = client.cache && Date.now();
43549
- if (client.cache)
43550
- ingestInCache(data, { cachedAt });
43551
- const { videoStreamings } = data;
43552
- return {
43553
- data: videoStreamings.find(stream => stream.streamId === streamId),
43554
- cachedAt,
44444
+ const filter = (payload) => {
44445
+ const data = prepareMyInvitationsPayload(payload);
44446
+ ingestInCache(data);
44447
+ callback(data.invitations);
43555
44448
  };
44449
+ return createEventSubscriber(client, 'room/onRoomCoHostInviteCanceled', 'room.didCohostInviteCancel', filter);
43556
44450
  };
43557
- /* end_public_function */
43558
44451
 
43559
- /* begin_public_function
43560
- id: stream.update
43561
- */
43562
44452
  /**
43563
- *
43564
44453
  * ```js
43565
- * import { StreamRepository } from '@amityco/ts-sdk'
43566
- * const updated = await StreamRepository.editStream(streamId, { title: 'foobar' })
44454
+ * import { onRoomParticipantJoined } from '@amityco/ts-sdk'
44455
+ * const dispose = onRoomParticipantJoined(room => {
44456
+ * // ...
44457
+ * })
43567
44458
  * ```
43568
44459
  *
43569
- * Updates an {@link Amity.Stream}
44460
+ * Fired when a participant has joined a {@link Amity.Room}
43570
44461
  *
43571
- * @param streamId The ID of the {@link Amity.Stream} to edit
43572
- * @param patch The patch data to apply
43573
- * @returns the updated {@link Amity.Stream} object
44462
+ * @param callback The function to call when the event was fired
44463
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
43574
44464
  *
43575
- * @category Stream API
43576
- * @async
44465
+ * @category Room Events
43577
44466
  */
43578
- const editStream = async (streamId, patch) => {
44467
+ const onRoomParticipantJoined = (callback) => {
43579
44468
  const client = getActiveClient();
43580
- client.log('stream/updateStream', streamId, patch);
43581
- const { data } = await client.http.put(`/api/v3/video-streaming/${streamId}`, patch);
43582
- const cachedAt = client.cache && Date.now();
43583
- if (client.cache)
43584
- ingestInCache(data, { cachedAt });
43585
- const { videoStreamings } = data;
43586
- return {
43587
- data: LinkedObject.stream(videoStreamings.find(stream => stream.streamId === streamId)),
43588
- cachedAt,
44469
+ const filter = (payload) => {
44470
+ ingestInCache(payload);
44471
+ callback(payload.rooms[0]);
43589
44472
  };
44473
+ return createEventSubscriber(client, 'room/onRoomParticipantJoined', 'room.participantJoined', filter);
43590
44474
  };
43591
- /* end_public_function */
43592
44475
 
43593
44476
  /**
43594
44477
  * ```js
43595
- * import { onStreamStarted } from '@amityco/ts-sdk'
43596
- * const dispose = onStreamStarted(stream => {
44478
+ * import { onRoomParticipantLeft } from '@amityco/ts-sdk'
44479
+ * const dispose = onRoomParticipantLeft(room => {
43597
44480
  * // ...
43598
44481
  * })
43599
44482
  * ```
43600
44483
  *
43601
- * Fired when a {@link Amity.InternalStream} has started airing
44484
+ * Fired when a participant has left a {@link Amity.Room}
43602
44485
  *
43603
44486
  * @param callback The function to call when the event was fired
43604
44487
  * @returns an {@link Amity.Unsubscriber} function to stop listening
43605
44488
  *
43606
- * @category Stream Events
44489
+ * @category Room Events
43607
44490
  */
43608
- const onStreamStarted = (callback) => {
44491
+ const onRoomParticipantLeft = (callback) => {
43609
44492
  const client = getActiveClient();
43610
44493
  const filter = (payload) => {
43611
44494
  ingestInCache(payload);
43612
- callback(payload.videoStreamings[0]);
44495
+ callback(payload.rooms[0]);
43613
44496
  };
43614
- return createEventSubscriber(client, 'stream/onStreamStarted', 'video-streaming.didStart', filter);
44497
+ return createEventSubscriber(client, 'room/onRoomParticipantLeft', 'room.participantLeft', filter);
43615
44498
  };
43616
44499
 
43617
44500
  /**
43618
44501
  * ```js
43619
- * import { onStreamStopped } from '@amityco/ts-sdk'
43620
- * const dispose = onStreamStopped(stream => {
44502
+ * import { onRoomCreated } from '@amityco/ts-sdk'
44503
+ * const dispose = onRoomCreated(room => {
43621
44504
  * // ...
43622
44505
  * })
43623
44506
  * ```
43624
44507
  *
43625
- * Fired when a {@link Amity.InternalStream} has stopped airing
44508
+ * Fired when a {@link Amity.Room} has been created locally
43626
44509
  *
43627
44510
  * @param callback The function to call when the event was fired
43628
44511
  * @returns an {@link Amity.Unsubscriber} function to stop listening
43629
44512
  *
43630
- * @category Stream Events
44513
+ * @category Room Events
43631
44514
  */
43632
- const onStreamStopped = (callback) => {
44515
+ const onRoomCreated = (callback) => {
43633
44516
  const client = getActiveClient();
43634
44517
  const filter = (payload) => {
43635
44518
  ingestInCache(payload);
43636
- callback(payload.videoStreamings[0]);
44519
+ callback(payload.rooms[0]);
43637
44520
  };
43638
- return createEventSubscriber(client, 'stream/onStreamStropped', 'video-streaming.didStop', filter);
44521
+ return createEventSubscriber(client, 'room/onRoomCreated', 'local.room.created', filter);
43639
44522
  };
43640
44523
 
43641
44524
  /**
43642
44525
  * ```js
43643
- * import { onStreamRecorded } from '@amityco/ts-sdk'
43644
- * const dispose = onStreamRecorded(stream => {
44526
+ * import { onRoomUpdated } from '@amityco/ts-sdk'
44527
+ * const dispose = onRoomUpdated(room => {
43645
44528
  * // ...
43646
44529
  * })
43647
44530
  * ```
43648
44531
  *
43649
- * Fired when the recordings of a {@link Amity.InternalStream} are available
44532
+ * Fired when a {@link Amity.Room} has been updated locally
43650
44533
  *
43651
44534
  * @param callback The function to call when the event was fired
43652
44535
  * @returns an {@link Amity.Unsubscriber} function to stop listening
43653
44536
  *
43654
- * @category Stream Events
44537
+ * @category Room Events
43655
44538
  */
43656
- const onStreamRecorded = (callback) => {
44539
+ const onRoomUpdated = (callback) => {
43657
44540
  const client = getActiveClient();
43658
44541
  const filter = (payload) => {
43659
44542
  ingestInCache(payload);
43660
- callback(payload.videoStreamings[0]);
44543
+ callback(payload.rooms[0]);
43661
44544
  };
43662
- return createEventSubscriber(client, 'stream/onStreamRecorded', 'video-streaming.didRecord', filter);
44545
+ return createEventSubscriber(client, 'room/onRoomUpdated', 'local.room.updated', filter);
43663
44546
  };
43664
44547
 
43665
44548
  /**
43666
44549
  * ```js
43667
- * import { onStreamFlagged } from '@amityco/ts-sdk'
43668
- * const dispose = onStreamFlagged(stream => {
44550
+ * import { onRoomDeleted } from '@amityco/ts-sdk'
44551
+ * const dispose = onRoomDeleted(room => {
43669
44552
  * // ...
43670
44553
  * })
43671
44554
  * ```
43672
44555
  *
43673
- * Fired when a {@link Amity.InternalStream} has started airing
44556
+ * Fired when a {@link Amity.Room} has been deleted locally
43674
44557
  *
43675
44558
  * @param callback The function to call when the event was fired
43676
44559
  * @returns an {@link Amity.Unsubscriber} function to stop listening
43677
44560
  *
43678
- * @category Stream Events
44561
+ * @category Room Events
43679
44562
  */
43680
- const onStreamFlagged = (callback) => {
44563
+ const onRoomDeleted = (callback) => {
43681
44564
  const client = getActiveClient();
43682
44565
  const filter = (payload) => {
43683
44566
  ingestInCache(payload);
43684
- callback(payload.videoStreamings[0]);
44567
+ callback(payload.rooms[0]);
43685
44568
  };
43686
- return createEventSubscriber(client, 'stream/onStreamFlagged', 'video-streaming.didFlag', filter);
44569
+ return createEventSubscriber(client, 'room/onRoomDeleted', 'local.room.deleted', filter);
43687
44570
  };
43688
44571
 
43689
44572
  /**
43690
44573
  * ```js
43691
- * import { onStreamTerminated } from '@amityco/ts-sdk'
43692
- * const dispose = onStreamTerminated(stream => {
44574
+ * import { onRoomStopped } from '@amityco/ts-sdk'
44575
+ * const dispose = onRoomStopped(room => {
43693
44576
  * // ...
43694
44577
  * })
43695
44578
  * ```
43696
44579
  *
43697
- * Fired when a {@link Amity.InternalStream} has started airing
44580
+ * Fired when a {@link Amity.Room} has been stopped locally
43698
44581
  *
43699
44582
  * @param callback The function to call when the event was fired
43700
44583
  * @returns an {@link Amity.Unsubscriber} function to stop listening
43701
44584
  *
43702
- * @category Stream Events
44585
+ * @category Room Events
43703
44586
  */
43704
- const onStreamTerminated = (callback) => {
44587
+ const onRoomStopped = (callback) => {
43705
44588
  const client = getActiveClient();
43706
44589
  const filter = (payload) => {
43707
44590
  ingestInCache(payload);
43708
- callback(payload.videoStreamings[0]);
44591
+ callback(payload.rooms[0]);
43709
44592
  };
43710
- return createEventSubscriber(client, 'stream/onStreamTerminated', 'video-streaming.didTerminate', filter);
44593
+ return createEventSubscriber(client, 'room/onRoomStopped', 'local.room.stopped', filter);
43711
44594
  };
43712
44595
 
43713
44596
  /**
43714
44597
  * ```js
43715
- * import { onStreamViewerUnbanned } from '@amityco/ts-sdk'
43716
- * const dispose = onStreamViewerBanned(stream => {
44598
+ * import { onRoomParticipantRemoved } from '@amityco/ts-sdk'
44599
+ * const dispose = onRoomParticipantRemoved(room => {
43717
44600
  * // ...
43718
44601
  * })
43719
44602
  * ```
43720
44603
  *
43721
- * Fired when a user in channel linked to stream has been unbanned
44604
+ * Fired when a participant has been removed from a {@link Amity.Room} locally
43722
44605
  *
43723
44606
  * @param callback The function to call when the event was fired
43724
44607
  * @returns an {@link Amity.Unsubscriber} function to stop listening
43725
44608
  *
43726
- * @category Stream Events
44609
+ * @category Room Events
43727
44610
  */
43728
- const onStreamViewerUnbanned = (callback) => {
44611
+ const onRoomParticipantRemoved = (callback) => {
43729
44612
  const client = getActiveClient();
43730
- const filter = async (payloads) => {
43731
- var _a;
43732
- // Get new stream object to restore stream watcherUrl in cache
43733
- const { list } = payloads;
43734
- await Promise.all(list.map(({ streamId }) => getStream(streamId)));
43735
- const stream = (_a = pullFromCache(['stream', 'get', list[0].streamId])) === null || _a === void 0 ? void 0 : _a.data;
43736
- if (!stream)
43737
- return;
43738
- callback(stream);
44613
+ const filter = (payload) => {
44614
+ ingestInCache(payload);
44615
+ callback(payload.rooms[0]);
43739
44616
  };
43740
- return createEventSubscriber(client, 'stream/onStreamViewerDidUnban', 'video-streaming.viewerDidUnban', filter);
44617
+ return createEventSubscriber(client, 'room/onRoomParticipantRemoved', 'room.participantRemoved', filter);
43741
44618
  };
43742
44619
 
43743
- /* eslint-disable no-use-before-define */
43744
- /* begin_public_function
43745
- id: stream.get
43746
- */
43747
44620
  /**
43748
44621
  * ```js
43749
- * import { StreamRepository } from '@amityco/ts-sdk'
43750
- * const unsub = StreamRepository.getStreamById('foobar')
43751
- * unsub()
44622
+ * import { onRoomLeft } from '@amityco/ts-sdk'
44623
+ * const dispose = onRoomLeft(room => {
44624
+ * // ...
44625
+ * })
43752
44626
  * ```
43753
44627
  *
43754
- * Fetches a {@link Amity.Stream} object
44628
+ * Fired when a user has left a {@link Amity.Room} locally
43755
44629
  *
43756
- * @param streamId the ID of the {@link Amity.Stream} to get
43757
- * @param callback
43758
- * @returns the associated {@link Amity.Stream} object
44630
+ * @param callback The function to call when the event was fired
44631
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
43759
44632
  *
43760
- * @category Stream Live Object
44633
+ * @category Room Events
43761
44634
  */
43762
- const getStreamById = (streamId, callback) => {
43763
- const reactor = (snapshot) => {
43764
- const { data } = snapshot;
43765
- callback(Object.assign(Object.assign({}, snapshot), { data: data ? LinkedObject.stream(snapshot.data) : data }));
44635
+ const onRoomLeft = (callback) => {
44636
+ const client = getActiveClient();
44637
+ const filter = (payload) => {
44638
+ ingestInCache(payload);
44639
+ callback(payload.rooms[0]);
43766
44640
  };
43767
- return liveObject(streamId, reactor, 'streamId', getStream, [
43768
- onStreamRecorded,
43769
- onStreamStarted,
43770
- onStreamStopped,
43771
- onStreamFlagged,
43772
- onStreamTerminated,
43773
- onStreamViewerBanned,
43774
- ]);
44641
+ return createEventSubscriber(client, 'room/onRoomLeft', 'local.room.left', filter);
43775
44642
  };
43776
- /* end_public_function */
44643
+
43777
44644
  /**
43778
44645
  * ```js
43779
- * import { StreamRepository } from '@amityco/ts-sdk'
43780
- * const stream = StreamRepository.getStreamById.locally('foobar')
44646
+ * import { onRoomParticipantRemoved } from '@amityco/ts-sdk'
44647
+ * const dispose = onRoomParticipantRemoved(room => {
44648
+ * // ...
44649
+ * })
43781
44650
  * ```
43782
44651
  *
43783
- * Fetches a {@link Amity.Stream} live object
44652
+ * Fired when a participant has been removed from a {@link Amity.Room} locally
43784
44653
  *
43785
- * @param streamId the ID of the {@link Amity.Stream} to fetch
43786
- * @returns the associated {@link Amity.Stream} live object
44654
+ * @param callback The function to call when the event was fired
44655
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
43787
44656
  *
43788
- * @category Stream API
44657
+ * @category Room Events
43789
44658
  */
43790
- getStreamById.locally = (streamId) => {
44659
+ const onRoomParticipantRemovedLocal = (callback) => {
43791
44660
  const client = getActiveClient();
43792
- client.log('stream/getStreamById', streamId);
43793
- if (!client.cache)
43794
- return;
43795
- const cached = pullFromCache(['stream', 'get', streamId]);
43796
- if (!cached)
43797
- return;
43798
- return {
43799
- data: LinkedObject.stream(cached.data),
43800
- cachedAt: cached.cachedAt,
44661
+ const filter = (payload) => {
44662
+ ingestInCache(payload);
44663
+ callback(payload.rooms[0]);
43801
44664
  };
44665
+ return createEventSubscriber(client, 'room/onRoomParticipantRemoved', 'local.room.participantRemoved', filter);
43802
44666
  };
43803
44667
 
43804
- class GetStreamsPageController extends PaginationController {
44668
+ const getRoom = (roomId, callback) => {
44669
+ // TODO: add callbackDataSelector if there are linked object fields
44670
+ return liveObject(roomId, callback, '_id', getRoomById, [
44671
+ onRoomEndBroadcasting,
44672
+ onRoomStartBroadcasting,
44673
+ onRoomWaitingReconnect,
44674
+ onRoomRecordedAvailable,
44675
+ onRoomParticipantJoined,
44676
+ onRoomParticipantLeft,
44677
+ onRoomParticipantRemoved,
44678
+ onRoomParticipantRemovedLocal,
44679
+ convertEventPayload(onRoomCoHostInviteAccepted, 'targetId', 'room'),
44680
+ ], {
44681
+ callbackDataSelector: (data) => {
44682
+ if (!data)
44683
+ return data;
44684
+ return LinkedObject.room(data);
44685
+ },
44686
+ });
44687
+ };
44688
+
44689
+ class RoomPaginationController extends PaginationController {
43805
44690
  async getRequest(queryParams, token) {
43806
- const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
43807
- const options = token ? { token } : { limit };
43808
- const { data: queryResponse } = await this.http.get(`/api/v3/video-streaming`, {
43809
- params: Object.assign(Object.assign({}, params), { options }),
44691
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
44692
+ const baseOptions = {
44693
+ type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
44694
+ };
44695
+ const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
44696
+ const { data: queryResponse } = await this.http.get(`/api/v1/rooms`, {
44697
+ params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options }),
43810
44698
  });
43811
- return Object.assign(Object.assign({}, queryResponse.results), { paging: queryResponse.paging });
44699
+ return queryResponse;
43812
44700
  }
43813
44701
  }
43814
44702
 
43815
- class GetStreamsQueryStreamController extends QueryStreamController {
43816
- constructor(query, cacheKey, notifyChange, paginationController) {
44703
+ var EnumRoomActions;
44704
+ (function (EnumRoomActions) {
44705
+ EnumRoomActions["OnRoomCreated"] = "OnRoomCreated";
44706
+ EnumRoomActions["OnRoomUpdated"] = "OnRoomUpdated";
44707
+ EnumRoomActions["OnRoomDeleted"] = "OnRoomDeleted";
44708
+ EnumRoomActions["OnRoomStartBroadcasting"] = "OnRoomStartBroadcasting";
44709
+ EnumRoomActions["OnRoomEndBroadcasting"] = "OnRoomEndBroadcasting";
44710
+ EnumRoomActions["OnRoomParticipantJoined"] = "OnRoomParticipantJoined";
44711
+ EnumRoomActions["OnRoomParticipantLeft"] = "OnRoomParticipantLeft";
44712
+ })(EnumRoomActions || (EnumRoomActions = {}));
44713
+
44714
+ class RoomQueryStreamController extends QueryStreamController {
44715
+ constructor(query, cacheKey, notifyChange, preparePayload) {
43817
44716
  super(query, cacheKey);
43818
44717
  this.notifyChange = notifyChange;
43819
- this.paginationController = paginationController;
44718
+ this.preparePayload = preparePayload;
43820
44719
  }
43821
- // eslint-disable-next-line class-methods-use-this
43822
- saveToMainDB(response) {
44720
+ async saveToMainDB(response) {
44721
+ const processedPayload = await this.preparePayload(response);
43823
44722
  const client = getActiveClient();
43824
44723
  const cachedAt = client.cache && Date.now();
43825
44724
  if (client.cache) {
43826
- ingestInCache(response, { cachedAt });
44725
+ ingestInCache(processedPayload, { cachedAt });
43827
44726
  }
43828
44727
  }
43829
44728
  appendToQueryStream(response, direction, refresh = false) {
43830
44729
  var _a, _b;
43831
44730
  if (refresh) {
43832
44731
  pushToCache(this.cacheKey, {
43833
- data: response.videoStreamings.map(getResolver('stream')),
43834
- query: this.query,
44732
+ data: response.rooms.map(getResolver('room')),
43835
44733
  });
43836
44734
  }
43837
44735
  else {
43838
44736
  const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
43839
- const messages = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
43840
- pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: direction === 'next'
43841
- ? [...new Set([...messages, ...response.videoStreamings.map(getResolver('stream'))])]
43842
- : [...new Set([...response.videoStreamings.map(getResolver('stream')), ...messages])] }));
44737
+ const rooms = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
44738
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...rooms, ...response.rooms.map(getResolver('room'))])] }));
43843
44739
  }
43844
44740
  }
43845
44741
  reactor(action) {
43846
- return (payload) => {
44742
+ return (room) => {
43847
44743
  var _a;
43848
44744
  const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
43849
44745
  if (!collection)
43850
44746
  return;
43851
- collection.data = [...new Set([payload.streamId, ...collection.data])];
44747
+ if (action === EnumRoomActions.OnRoomDeleted) {
44748
+ collection.data = collection.data.filter(roomId => roomId !== room._id);
44749
+ }
44750
+ if (action === EnumRoomActions.OnRoomCreated) {
44751
+ collection.data = [...new Set([room._id, ...collection.data])];
44752
+ }
43852
44753
  pushToCache(this.cacheKey, collection);
43853
44754
  this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
43854
44755
  };
@@ -43858,53 +44759,184 @@ class GetStreamsQueryStreamController extends QueryStreamController {
43858
44759
  }
43859
44760
  }
43860
44761
 
43861
- class GetStreamsLiveCollectionController extends LiveCollectionController {
44762
+ // TODO: confirm related events
44763
+ const getRoomSubscription = () => [
44764
+ {
44765
+ fn: onRoomStartBroadcasting,
44766
+ action: EnumRoomActions.OnRoomStartBroadcasting,
44767
+ },
44768
+ {
44769
+ fn: onRoomEndBroadcasting,
44770
+ action: EnumRoomActions.OnRoomEndBroadcasting,
44771
+ },
44772
+ {
44773
+ fn: onRoomRecordedAvailable,
44774
+ action: EnumRoomActions.OnRoomUpdated,
44775
+ },
44776
+ ];
44777
+
44778
+ class RoomLiveCollectionController extends LiveCollectionController {
43862
44779
  constructor(query, callback) {
43863
44780
  const queryStreamId = hash(query);
43864
- const cacheKey = ['streams', 'collection', queryStreamId];
43865
- const paginationController = new GetStreamsPageController(query);
44781
+ const cacheKey = ['rooms', 'collection', queryStreamId];
44782
+ const paginationController = new RoomPaginationController(query);
43866
44783
  super(paginationController, queryStreamId, cacheKey, callback);
43867
- this.applyFilter = (data) => {
43868
- let streams = filterByPropEquality(data, 'isDeleted', this.query.isDeleted);
43869
- streams = streams.sort(this.query.sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
43870
- return streams;
43871
- };
43872
44784
  this.query = query;
43873
- this.queryStreamController = new GetStreamsQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), paginationController);
43874
- this.paginationController = paginationController;
44785
+ this.queryStreamController = new RoomQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), response => response);
43875
44786
  this.callback = callback.bind(this);
43876
44787
  this.loadPage({ initial: true });
43877
44788
  }
43878
- notifyChange({ origin, loading, error }) {
44789
+ setup() {
43879
44790
  var _a;
43880
44791
  const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
44792
+ if (!collection) {
44793
+ pushToCache(this.cacheKey, {
44794
+ data: [],
44795
+ params: {},
44796
+ });
44797
+ }
44798
+ }
44799
+ async persistModel(queryPayload) {
44800
+ await this.queryStreamController.saveToMainDB(queryPayload);
44801
+ }
44802
+ persistQueryStream({ response, direction, refresh, }) {
44803
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
44804
+ }
44805
+ startSubscription() {
44806
+ return this.queryStreamController.subscribeRTE(getRoomSubscription());
44807
+ }
44808
+ notifyChange({ origin, loading, error }) {
44809
+ var _a, _b;
44810
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
43881
44811
  if (!collection)
43882
44812
  return;
43883
- let data = collection.data
43884
- .map(streamId => pullFromCache(['stream', 'get', streamId]))
43885
- .filter(Boolean)
43886
- .map(stream => LinkedObject.stream(stream.data));
44813
+ const data = this.applyFilter((_b = collection.data
44814
+ .map(id => pullFromCache(['room', 'get', id]))
44815
+ .filter(isNonNullable)
44816
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(room => room); // Since Room is same as InternalRoom, no transformation needed
43887
44817
  if (!this.shouldNotify(data) && origin === 'event')
43888
44818
  return;
43889
- data = this.applyFilter(data);
43890
44819
  this.callback({
43891
- onNextPage: () => this.loadPage({ initial: false, direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
44820
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
43892
44821
  data,
43893
44822
  hasNextPage: !!this.paginationController.getNextToken(),
43894
44823
  loading,
43895
44824
  error,
43896
44825
  });
43897
44826
  }
43898
- startSubscription() {
43899
- return this.queryStreamController.subscribeRTE([
43900
- { fn: onStreamRecorded, action: 'onStreamRecorded' },
43901
- { fn: onStreamStarted, action: 'onStreamStarted' },
43902
- { fn: onStreamStopped, action: 'onStreamStopped' },
43903
- { fn: onStreamFlagged, action: 'onStreamFlagged' },
43904
- { fn: onStreamTerminated, action: 'onStreamTerminated' },
43905
- { fn: onStreamViewerBanned, action: 'onStreamViewerBanned' },
43906
- { fn: onStreamViewerUnbanned, action: 'onStreamViewerUnbanned' },
43907
- ]);
44827
+ applyFilter(data) {
44828
+ let rooms = data;
44829
+ if (!this.query.includeDeleted) {
44830
+ rooms = filterByPropEquality(rooms, 'isDeleted', false);
44831
+ }
44832
+ if (this.query.statuses && this.query.statuses.length > 0) {
44833
+ rooms = rooms.filter(room => { var _a; return (_a = this.query.statuses) === null || _a === void 0 ? void 0 : _a.includes(room.status); });
44834
+ }
44835
+ if (this.query.type) {
44836
+ rooms = filterByPropEquality(rooms, 'type', this.query.type);
44837
+ }
44838
+ switch (this.query.sortBy) {
44839
+ case 'firstCreated':
44840
+ rooms = rooms.sort(sortByFirstCreated);
44841
+ break;
44842
+ case 'lastCreated':
44843
+ default:
44844
+ rooms = rooms.sort(sortByLastCreated);
44845
+ break;
44846
+ }
44847
+ return rooms;
44848
+ }
44849
+ }
44850
+
44851
+ /* begin_public_function
44852
+ id: room.get_rooms
44853
+ */
44854
+ /**
44855
+ * ```js
44856
+ * import { RoomRepository } from '@amityco/ts-sdk'
44857
+ *
44858
+ * let rooms = []
44859
+ * const unsub = RoomRepository.getRooms({
44860
+ * type: 'direct_streaming',
44861
+ * statuses: ['live', 'idle'],
44862
+ * sortBy: 'lastCreated',
44863
+ * limit: 20,
44864
+ * includeDeleted: false
44865
+ * }, response => merge(rooms, response.data))
44866
+ * ```
44867
+ *
44868
+ * Observe all mutations on a list of {@link Amity.Room} for a given query
44869
+ *
44870
+ * @param params.type the type of rooms to filter by ('direct_streaming' | 'co_hosts')
44871
+ * @param params.statuses array of room statuses to filter by (['idle', 'live', 'waiting_reconnect', 'ended', 'recorded'])
44872
+ * @param params.sortBy sort rooms by creation time ('firstCreated' | 'lastCreated')
44873
+ * @param params.limit maximum number of rooms to retrieve per page
44874
+ * @param params.includeDeleted whether to include deleted rooms in the results
44875
+ * @param callback the function to call when new data are available
44876
+ * @param config optional configuration for the live collection
44877
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the rooms
44878
+ *
44879
+ * @category Rooms Live Collection
44880
+ */
44881
+ const getRooms = (params, callback, config) => {
44882
+ const { log, cache } = getActiveClient();
44883
+ if (!cache) {
44884
+ console.log(ENABLE_CACHE_MESSAGE);
44885
+ }
44886
+ const timestamp = Date.now();
44887
+ log(`getRooms(tmpid: ${timestamp}) > listen`);
44888
+ const roomsLiveCollection = new RoomLiveCollectionController(params, callback);
44889
+ const disposers = roomsLiveCollection.startSubscription();
44890
+ const cacheKey = roomsLiveCollection.getCacheKey();
44891
+ disposers.push(() => dropFromCache(cacheKey));
44892
+ return () => {
44893
+ log(`getRooms(tmpid: ${timestamp}) > dispose`);
44894
+ disposers.forEach(fn => fn());
44895
+ };
44896
+ };
44897
+ /* end_public_function */
44898
+
44899
+ var index$b = /*#__PURE__*/Object.freeze({
44900
+ __proto__: null,
44901
+ createRoom: createRoom,
44902
+ updateRoom: updateRoom,
44903
+ deleteRoom: deleteRoom,
44904
+ stopRoom: stopRoom,
44905
+ getBroadcasterData: getBroadcasterData,
44906
+ getRecordedUrl: getRecordedUrl,
44907
+ removeParticipant: removeParticipant,
44908
+ leaveRoom: leaveRoom,
44909
+ onRoomStartBroadcasting: onRoomStartBroadcasting,
44910
+ onRoomWaitingReconnect: onRoomWaitingReconnect,
44911
+ onRoomEndBroadcasting: onRoomEndBroadcasting,
44912
+ onRoomRecordedAvailable: onRoomRecordedAvailable,
44913
+ onRoomCoHostInvited: onRoomCoHostInvited,
44914
+ onRoomCoHostInviteAccepted: onRoomCoHostInviteAccepted,
44915
+ onRoomCoHostInviteRejected: onRoomCoHostInviteRejected,
44916
+ onRoomCoHostInviteCanceled: onRoomCoHostInviteCanceled,
44917
+ onRoomParticipantJoined: onRoomParticipantJoined,
44918
+ onRoomParticipantLeft: onRoomParticipantLeft,
44919
+ onRoomCreated: onRoomCreated,
44920
+ onRoomUpdated: onRoomUpdated,
44921
+ onRoomDeleted: onRoomDeleted,
44922
+ onRoomStopped: onRoomStopped,
44923
+ onRoomParticipantRemoved: onRoomParticipantRemoved,
44924
+ onRoomLeft: onRoomLeft,
44925
+ getRoom: getRoom,
44926
+ getRooms: getRooms
44927
+ });
44928
+
44929
+ class LiveRoomPostLiveCollectionController extends LiveCollectionController {
44930
+ constructor(callback) {
44931
+ const query = { limit: 100 };
44932
+ const queryStreamId = hash(query);
44933
+ const cacheKey = ['liveRoomPosts', 'collection', queryStreamId];
44934
+ const paginationController = new LiveRoomPostPaginationController(query);
44935
+ super(paginationController, queryStreamId, cacheKey, callback);
44936
+ this.query = query;
44937
+ this.queryStreamController = new LiveRoomPostQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
44938
+ this.callback = callback.bind(this);
44939
+ this.loadPage({ initial: true });
43908
44940
  }
43909
44941
  setup() {
43910
44942
  var _a;
@@ -43916,822 +44948,759 @@ class GetStreamsLiveCollectionController extends LiveCollectionController {
43916
44948
  });
43917
44949
  }
43918
44950
  }
43919
- persistModel(response) {
43920
- this.queryStreamController.saveToMainDB(response);
44951
+ async persistModel(queryPayload) {
44952
+ await this.queryStreamController.saveToMainDB(queryPayload);
43921
44953
  }
43922
44954
  persistQueryStream({ response, direction, refresh, }) {
43923
44955
  this.queryStreamController.appendToQueryStream(response, direction, refresh);
43924
44956
  }
43925
- }
43926
-
43927
- const getStreams = (params, callback, config) => {
43928
- const { log, cache, userId } = getActiveClient();
43929
- if (!cache) {
43930
- console.log(ENABLE_CACHE_MESSAGE);
44957
+ startSubscription() {
44958
+ return this.queryStreamController.subscribeRTE([
44959
+ { fn: onRoomEndBroadcasting, action: EnumPostActions.OnPostUpdated },
44960
+ ]);
43931
44961
  }
43932
- const timestamp = Date.now();
43933
- log(`getStreams(tmpid: ${timestamp}) > listen`);
43934
- const liveCollection = new GetStreamsLiveCollectionController(params, callback);
43935
- const disposers = liveCollection.startSubscription();
43936
- const cacheKey = liveCollection.getCacheKey();
43937
- disposers.push(() => {
43938
- dropFromCache(cacheKey);
43939
- });
43940
- return () => {
43941
- log(`getStreams(tmpid: ${timestamp}) > dispose`);
43942
- disposers.forEach(fn => fn());
43943
- };
43944
- };
43945
-
43946
- var index$a = /*#__PURE__*/Object.freeze({
43947
- __proto__: null,
43948
- createStream: createStream,
43949
- updateStream: updateStream,
43950
- deleteStream: deleteStream,
43951
- disposeStream: disposeStream,
43952
- editStream: editStream,
43953
- onStreamStarted: onStreamStarted,
43954
- onStreamStopped: onStreamStopped,
43955
- onStreamRecorded: onStreamRecorded,
43956
- onStreamFlagged: onStreamFlagged,
43957
- onStreamTerminated: onStreamTerminated,
43958
- onStreamViewerBanned: onStreamViewerBanned,
43959
- onStreamViewerUnbanned: onStreamViewerUnbanned,
43960
- getStreamById: getStreamById,
43961
- getStreams: getStreams
43962
- });
44962
+ notifyChange({ origin, loading, error }) {
44963
+ var _a, _b;
44964
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
44965
+ if (!collection)
44966
+ return;
44967
+ const data = this.applyFilter((_b = collection.data
44968
+ .map(id => pullFromCache(['post', 'get', id]))
44969
+ .filter(isNonNullable)
44970
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
44971
+ if (!this.shouldNotify(data) && origin === 'event')
44972
+ return;
44973
+ this.callback({
44974
+ data,
44975
+ loading,
44976
+ error,
44977
+ });
44978
+ }
44979
+ // eslint-disable-next-line class-methods-use-this
44980
+ applyFilter(data) {
44981
+ // No additional filtering needed for live room posts
44982
+ // API handles all filtering based on targetId and targetType
44983
+ return data;
44984
+ }
44985
+ }
43963
44986
 
43964
44987
  /* begin_public_function
43965
- id: room.create
44988
+ id: post.liveRoom.query
43966
44989
  */
43967
44990
  /**
43968
44991
  * ```js
43969
- * import { createRoom } from '@amityco/ts-sdk'
43970
- * const created = await createRoom({ title: 'my room', 'thumbnailFileId': fileId })
43971
- * ```
43972
- *
43973
- * Creates an {@link Amity.Room}
43974
- *
43975
- * @param bundle The data necessary to create a new {@link Amity.Room}
43976
- * @returns The newly created {@link Amity.Room}
44992
+ * import { PostRepository } from '@amityco/ts-sdk'
43977
44993
  *
43978
- * @category Room API
43979
- * @async
43980
- */
43981
- const createRoom = async (bundle) => {
43982
- const client = getActiveClient();
43983
- client.log('room/createRoom', bundle);
43984
- const { data } = await client.http.post('/api/v1/rooms', bundle);
43985
- fireEvent('local.room.created', data);
43986
- const cachedAt = client.cache && Date.now();
43987
- // TODO: check if should pick `users` filed which contains participants - if no need to ingest in the cache
43988
- if (client.cache)
43989
- ingestInCache(data, { cachedAt });
43990
- const { rooms } = data;
43991
- return {
43992
- data: roomLinkedObject(rooms[0]),
43993
- cachedAt,
43994
- };
43995
- };
43996
- /* end_public_function */
43997
-
43998
- /* begin_public_function
43999
- id: room.update
44000
- */
44001
- /**
44002
- * ```js
44003
- * import { updateRoom } from '@amityco/ts-sdk'
44004
- * const updated = await updateRoom('roomId', { title: 'updated title' })
44994
+ * let posts = []
44995
+ * const unsub = PostRepository.getLiveRoomPosts({
44996
+ * targetType: Amity.PostTargetType,
44997
+ * targetId: Amity.Post['targetId'],
44998
+ * }, response => merge(posts, response.data))
44005
44999
  * ```
44006
45000
  *
44007
- * Updates an {@link Amity.InternalRoom}
45001
+ * Observe all mutations on a list of {@link Amity.Post} for a given live room
44008
45002
  *
44009
- * @param roomId The ID of the room to update
44010
- * @param bundle The data to update the room with
44011
- * @returns The updated {@link Amity.InternalRoom}
45003
+ * @param params.targetType the type of the target
45004
+ * @param params.targetId the ID of the target
45005
+ * @param callback the function to call when new data are available
45006
+ * @param config
45007
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the posts
44012
45008
  *
44013
- * @category Room API
44014
- * @async
45009
+ * @category Posts Live Collection
44015
45010
  */
44016
- const updateRoom = async (roomId, bundle) => {
44017
- const client = getActiveClient();
44018
- client.log('room/updateRoom', { roomId, bundle });
44019
- const { data } = await client.http.put(`/api/v1/rooms/${roomId}`, bundle);
44020
- fireEvent('local.room.updated', data);
44021
- const cachedAt = client.cache && Date.now();
44022
- if (client.cache)
44023
- ingestInCache(data, { cachedAt });
44024
- const { rooms } = data;
44025
- return {
44026
- data: roomLinkedObject(rooms[0]),
44027
- cachedAt,
45011
+ const getLiveRoomPosts = (callback) => {
45012
+ const { log, cache } = getActiveClient();
45013
+ if (!cache) {
45014
+ console.log(ENABLE_CACHE_MESSAGE);
45015
+ }
45016
+ const timestamp = Date.now();
45017
+ log(`getLiveRoomPosts(tmpid: ${timestamp}) > listen`);
45018
+ const liveRoomPostsLiveCollection = new LiveRoomPostLiveCollectionController(callback);
45019
+ const disposers = liveRoomPostsLiveCollection.startSubscription();
45020
+ const cacheKey = liveRoomPostsLiveCollection.getCacheKey();
45021
+ disposers.push(() => dropFromCache(cacheKey));
45022
+ return () => {
45023
+ log(`getLiveRoomPosts(tmpid: ${timestamp}) > dispose`);
45024
+ disposers.forEach(fn => fn());
44028
45025
  };
44029
45026
  };
44030
45027
  /* end_public_function */
44031
45028
 
44032
- /* begin_public_function
44033
- id: room.delete
44034
- */
44035
- /**
44036
- * ```js
44037
- * import { deleteRoom } from '@amityco/ts-sdk'
44038
- * const result = await deleteRoom('roomId')
44039
- * ```
44040
- *
44041
- * Deletes an {@link Amity.Room}
44042
- *
44043
- * @param roomId The ID of the room to delete
44044
- * @returns Promise that resolves when the room is deleted
44045
- *
44046
- * @category Room API
44047
- * @async
44048
- */
44049
- const deleteRoom = async (roomId) => {
44050
- const client = getActiveClient();
44051
- client.log('room/deleteRoom', { roomId });
44052
- await client.http.delete(`/api/v1/rooms/${roomId}`);
44053
- fireEvent('local.room.deleted', { rooms: [{ _id: roomId }] });
44054
- };
44055
- /* end_public_function */
45029
+ class CommunityLiveRoomPostPaginationController extends PaginationNoPageController {
45030
+ async getRequest(queryParams) {
45031
+ const { limit = 100, communityIds } = queryParams;
45032
+ const { data: queryResponse } = await this.http.get(`/api/v1/rooms/lives`, {
45033
+ params: {
45034
+ targetTypes: ['community'],
45035
+ targetIds: communityIds,
45036
+ options: {
45037
+ limit,
45038
+ sortBy: 'lastCreated',
45039
+ },
45040
+ },
45041
+ });
45042
+ return queryResponse;
45043
+ }
45044
+ }
44056
45045
 
44057
- /* begin_public_function
44058
- id: room.stop
44059
- */
44060
- /**
44061
- * ```js
44062
- * import { stopRoom } from '@amityco/ts-sdk'
44063
- * const result = await stopRoom('roomId')
44064
- * ```
44065
- *
44066
- * Stops a room's broadcasting
44067
- *
44068
- * @param roomId The ID of the room to stop
44069
- * @returns The updated room data
44070
- *
44071
- * @category Room API
44072
- * @async
44073
- */
44074
- const stopRoom = async (roomId) => {
44075
- const client = getActiveClient();
44076
- client.log('room/stopRoom', { roomId });
44077
- const { data } = await client.http.post(`/api/v1/rooms/${roomId}/stop`);
44078
- fireEvent('local.room.stopped', data);
44079
- const cachedAt = client.cache && Date.now();
44080
- if (client.cache)
44081
- ingestInCache(data, { cachedAt });
44082
- const { rooms } = data;
44083
- return {
44084
- data: rooms[0],
44085
- cachedAt,
44086
- };
44087
- };
44088
- /* end_public_function */
45046
+ class CommunityLiveRoomPostQueryStreamController extends QueryStreamController {
45047
+ constructor(query, cacheKey, notifyChange, preparePayload) {
45048
+ super(query, cacheKey);
45049
+ this.notifyChange = notifyChange;
45050
+ this.preparePayload = preparePayload;
45051
+ }
45052
+ async saveToMainDB(response) {
45053
+ const processedPayload = await this.preparePayload(response);
45054
+ const client = getActiveClient();
45055
+ const cachedAt = client.cache && Date.now();
45056
+ if (client.cache) {
45057
+ ingestInCache(processedPayload, { cachedAt });
45058
+ }
45059
+ }
45060
+ appendToQueryStream(response, direction, refresh = false) {
45061
+ var _a, _b;
45062
+ if (refresh) {
45063
+ pushToCache(this.cacheKey, {
45064
+ data: resolvePostIdsFromRooms(response.rooms, response.posts),
45065
+ });
45066
+ }
45067
+ else {
45068
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
45069
+ const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
45070
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...resolvePostIdsFromRooms(response.rooms, response.posts)])] }));
45071
+ }
45072
+ }
45073
+ reactor(action) {
45074
+ return (room) => {
45075
+ var _a;
45076
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
45077
+ if (!collection)
45078
+ return;
45079
+ if (room.status === 'ended') {
45080
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: collection.data.filter(postId => room.referenceId !== postId) }));
45081
+ }
45082
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
45083
+ };
45084
+ }
45085
+ subscribeRTE(createSubscriber) {
45086
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
45087
+ }
45088
+ }
45089
+
45090
+ class CommunityLiveRoomPostLiveCollectionController extends LiveCollectionController {
45091
+ constructor(query, callback) {
45092
+ const queryStreamId = hash(query);
45093
+ const cacheKey = ['communityLiveRoomPosts', 'collection', queryStreamId];
45094
+ const paginationController = new CommunityLiveRoomPostPaginationController(query);
45095
+ super(paginationController, queryStreamId, cacheKey, callback);
45096
+ this.query = query;
45097
+ this.queryStreamController = new CommunityLiveRoomPostQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
45098
+ this.callback = callback.bind(this);
45099
+ this.loadPage({ initial: true });
45100
+ }
45101
+ setup() {
45102
+ var _a;
45103
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
45104
+ if (!collection) {
45105
+ pushToCache(this.cacheKey, {
45106
+ data: [],
45107
+ params: {},
45108
+ });
45109
+ }
45110
+ }
45111
+ async persistModel(queryPayload) {
45112
+ await this.queryStreamController.saveToMainDB(queryPayload);
45113
+ }
45114
+ persistQueryStream({ response, direction, refresh, }) {
45115
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
45116
+ }
45117
+ startSubscription() {
45118
+ return this.queryStreamController.subscribeRTE([
45119
+ { fn: onRoomEndBroadcasting, action: EnumPostActions.OnPostUpdated },
45120
+ ]);
45121
+ }
45122
+ notifyChange({ origin, loading, error }) {
45123
+ var _a, _b;
45124
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
45125
+ if (!collection)
45126
+ return;
45127
+ const data = this.applyFilter((_b = collection.data
45128
+ .map((id) => pullFromCache(['post', 'get', id]))
45129
+ .filter(isNonNullable)
45130
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
45131
+ if (!this.shouldNotify(data) && origin === 'event')
45132
+ return;
45133
+ this.callback({
45134
+ data,
45135
+ loading,
45136
+ error,
45137
+ });
45138
+ }
45139
+ // eslint-disable-next-line class-methods-use-this
45140
+ applyFilter(data) {
45141
+ // No additional filtering needed for live room posts
45142
+ // API handles all filtering based on targetId and targetType
45143
+ return data;
45144
+ }
45145
+ }
44089
45146
 
44090
45147
  /* begin_public_function
44091
- id: room.getBroadcasterData
45148
+ id: post.communityLiveRoom.query
44092
45149
  */
44093
45150
  /**
44094
45151
  * ```js
44095
- * import { getBroadcasterData } from '@amityco/ts-sdk'
44096
- * const token = await getBroadcasterData('roomId')
45152
+ * import { PostRepository } from '@amityco/ts-sdk'
45153
+ *
45154
+ * let posts = []
45155
+ * const unsub = PostRepository.getCommunityLiveRoomPosts({
45156
+ * targetId: 'communityId',
45157
+ * }, response => merge(posts, response.data))
44097
45158
  * ```
44098
45159
  *
44099
- * Gets broadcaster data for a room
45160
+ * Observe all mutations on a list of {@link Amity.Post} for live rooms in a specific community
44100
45161
  *
44101
- * @param roomId The ID of the room to get token for
44102
- * @returns The broadcaster data of the room including coHostToken, coHostUrl and direactStreamUrl
45162
+ * @param params.targetId the ID of the community
45163
+ * @param params.limit optional limit for the number of posts to fetch
45164
+ * @param callback the function to call when new data are available
45165
+ * @param config
45166
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the posts
44103
45167
  *
44104
- * @category Room API
44105
- * @async
45168
+ * @category Posts Live Collection
44106
45169
  */
44107
- const getBroadcasterData = async (roomId) => {
44108
- const client = getActiveClient();
44109
- client.log('room/getBroadcasterData', { roomId });
44110
- const { data } = await client.http.get(`/api/v1/rooms/${roomId}/token`);
44111
- return data;
45170
+ const getCommunityLiveRoomPosts = (params, callback, config) => {
45171
+ const { log, cache } = getActiveClient();
45172
+ if (!cache) {
45173
+ console.log(ENABLE_CACHE_MESSAGE);
45174
+ }
45175
+ const timestamp = Date.now();
45176
+ log(`getCommunityLiveRoomPosts(tmpid: ${timestamp}) > listen`);
45177
+ const communityLiveRoomPostsLiveCollection = new CommunityLiveRoomPostLiveCollectionController(params, callback);
45178
+ const disposers = communityLiveRoomPostsLiveCollection.startSubscription();
45179
+ const cacheKey = communityLiveRoomPostsLiveCollection.getCacheKey();
45180
+ disposers.push(() => dropFromCache(cacheKey));
45181
+ return () => {
45182
+ log(`getCommunityLiveRoomPosts(tmpid: ${timestamp}) > dispose`);
45183
+ disposers.forEach(fn => fn());
45184
+ };
44112
45185
  };
44113
45186
  /* end_public_function */
44114
45187
 
45188
+ var index$a = /*#__PURE__*/Object.freeze({
45189
+ __proto__: null,
45190
+ getPostByIds: getPostByIds,
45191
+ createPost: createPost,
45192
+ editPost: editPost,
45193
+ deletePost: deletePost,
45194
+ softDeletePost: softDeletePost,
45195
+ hardDeletePost: hardDeletePost,
45196
+ approvePost: approvePost,
45197
+ declinePost: declinePost,
45198
+ flagPost: flagPost,
45199
+ unflagPost: unflagPost,
45200
+ isPostFlaggedByMe: isPostFlaggedByMe,
45201
+ createClipPost: createClipPost,
45202
+ createAudioPost: createAudioPost,
45203
+ createMixedMediaPost: createMixedMediaPost,
45204
+ onPostCreated: onPostCreated,
45205
+ onPostUpdated: onPostUpdated,
45206
+ onPostDeleted: onPostDeleted,
45207
+ onPostApproved: onPostApproved,
45208
+ onPostDeclined: onPostDeclined,
45209
+ onPostFlagged: onPostFlagged,
45210
+ onPostUnflagged: onPostUnflagged,
45211
+ onPostReactionAdded: onPostReactionAdded,
45212
+ onPostReactionRemoved: onPostReactionRemoved,
45213
+ getPost: getPost,
45214
+ getPosts: getPosts,
45215
+ getPinnedPosts: getPinnedPosts,
45216
+ getGlobalPinnedPosts: getGlobalPinnedPosts,
45217
+ semanticSearchPosts: semanticSearchPosts,
45218
+ searchPostsByHashtag: searchPostsByHashtag,
45219
+ getLiveRoomPosts: getLiveRoomPosts,
45220
+ getCommunityLiveRoomPosts: getCommunityLiveRoomPosts
45221
+ });
45222
+
44115
45223
  /* begin_public_function
44116
- id: room.getRecordedUrl
45224
+ id: stream.create
44117
45225
  */
44118
45226
  /**
44119
45227
  * ```js
44120
- * import { getRecordedUrl } from '@amityco/ts-sdk'
44121
- * const recordedUrl = await getRecordedUrl('roomId')
45228
+ * import { createStream } from '@amityco/ts-sdk'
45229
+ * const created = await createStream({ title: 'my stream', 'thumbnailFileId': fileId })
44122
45230
  * ```
44123
45231
  *
44124
- * Gets the recorded URL for a room
45232
+ * Creates an {@link Amity.InternalStream}
44125
45233
  *
44126
- * @param roomId The ID of the room to get recorded URL for
44127
- * @returns The recorded URL information
45234
+ * @param bundle The data necessary to create a new {@link Amity.InternalStream}
45235
+ * @returns The newly created {@link Amity.InternalStream}
44128
45236
  *
44129
- * @category Room API
45237
+ * @category Stream API
44130
45238
  * @async
44131
45239
  */
44132
- const getRecordedUrl = async (roomId) => {
45240
+ const createStream = async (bundle) => {
44133
45241
  const client = getActiveClient();
44134
- client.log('room/getRecordedUrl', { roomId });
44135
- const { data } = await client.http.get(`/api/v1/rooms/${roomId}/recorded`);
44136
- return data;
45242
+ client.log('stream/createStream', bundle);
45243
+ const { data } = await client.http.post('/api/v3/video-streaming', bundle);
45244
+ const cachedAt = client.cache && Date.now();
45245
+ if (client.cache)
45246
+ ingestInCache(data, { cachedAt });
45247
+ const { videoStreamings } = data;
45248
+ return {
45249
+ data: LinkedObject.stream(videoStreamings[0]),
45250
+ cachedAt,
45251
+ };
44137
45252
  };
44138
45253
  /* end_public_function */
44139
45254
 
44140
45255
  /* begin_public_function
44141
- id: room.removeParticipant
45256
+ id: stream.update
44142
45257
  */
44143
45258
  /**
45259
+ * @deprecated this function is deprecated,
45260
+ * please use {@link Amity.StreamRepository.editStream} instead.
45261
+ *
44144
45262
  * ```js
44145
- * import { removeParticipant } from '@amityco/ts-sdk'
44146
- * const result = await removeParticipant('roomId', 'participantUserId')
45263
+ * import { updateStream } from '@amityco/ts-sdk'
45264
+ * const updated = await updateStream(streamId, { title: 'foobar' })
44147
45265
  * ```
44148
45266
  *
44149
- * Removes a participant from an {@link Amity.Room}
45267
+ * Updates an {@link Amity.Stream}
44150
45268
  *
44151
- * @param roomId The ID of the room to remove participant from
44152
- * @param participantUserId The ID of the user to remove as participant
44153
- * @returns Promise that resolves when the participant is removed
45269
+ * @param streamId The ID of the {@link Amity.Stream} to edit
45270
+ * @param patch The patch data to apply
45271
+ * @returns the updated {@link Amity.Stream} object
44154
45272
  *
44155
- * @category Room API
45273
+ * @category Stream API
44156
45274
  * @async
44157
45275
  */
44158
- const removeParticipant = async (roomId, participantUserId) => {
45276
+ const updateStream = async (streamId, patch) => {
44159
45277
  const client = getActiveClient();
44160
- client.log('room/removeParticipant', { roomId, participantUserId });
44161
- await client.http.delete(`/api/v1/rooms/${roomId}/participants/${participantUserId}`);
44162
- fireEvent('local.room.participantRemoved', {
44163
- rooms: [{ _id: roomId }],
44164
- users: [{ _id: participantUserId }],
44165
- });
45278
+ client.log('stream/updateStream', streamId, patch);
45279
+ const { data } = await client.http.put(`/api/v3/video-streaming/${streamId}`, patch);
45280
+ const cachedAt = client.cache && Date.now();
45281
+ if (client.cache)
45282
+ ingestInCache(data, { cachedAt });
45283
+ const { videoStreamings } = data;
45284
+ return {
45285
+ data: LinkedObject.stream(videoStreamings.find(stream => stream.streamId === streamId)),
45286
+ cachedAt,
45287
+ };
44166
45288
  };
44167
45289
  /* end_public_function */
44168
45290
 
44169
45291
  /* begin_public_function
44170
- id: room.leave
45292
+ id: stream.get
44171
45293
  */
44172
45294
  /**
44173
45295
  * ```js
44174
- * import { leaveRoom } from '@amityco/ts-sdk'
44175
- * const result = await leaveRoom('roomId')
45296
+ * import { getStream } from '@amityco/ts-sdk'
45297
+ * const stream = await getStream('foobar')
44176
45298
  * ```
44177
45299
  *
44178
- * Leaves an {@link Amity.Room}
45300
+ * Fetches a {@link Amity.Stream} object
44179
45301
  *
44180
- * @param roomId The ID of the room to leave
44181
- * @returns Promise that resolves when the user has left the room
45302
+ * @param streamId the ID of the {@link Amity.Stream} to fetch
45303
+ * @returns the associated {@link Amity.Stream} object
44182
45304
  *
44183
- * @category Room API
45305
+ * @category Stream API
44184
45306
  * @async
44185
45307
  */
44186
- const leaveRoom = async (roomId) => {
44187
- const client = getActiveClient();
44188
- client.log('room/leaveRoom', { roomId });
44189
- await client.http.post(`/api/v1/rooms/${roomId}/leave`);
44190
- fireEvent('local.room.left', {
44191
- rooms: [{ _id: roomId }],
44192
- });
44193
- };
44194
- /* end_public_function */
44195
-
44196
- /**
44197
- * ```js
44198
- * import { onRoomStartBroadcasting } from '@amityco/ts-sdk'
44199
- * const dispose = onRoomStartBroadcasting(room => {
44200
- * // ...
44201
- * })
44202
- * ```
44203
- *
44204
- * Fired when a {@link Amity.Room} has started broadcasting
44205
- *
44206
- * @param callback The function to call when the event was fired
44207
- * @returns an {@link Amity.Unsubscriber} function to stop listening
44208
- *
44209
- * @category Room Events
44210
- */
44211
- const onRoomStartBroadcasting = (callback) => {
44212
- const client = getActiveClient();
44213
- const filter = (payload) => {
44214
- ingestInCache(payload);
44215
- callback(payload.rooms[0]);
44216
- };
44217
- return createEventSubscriber(client, 'room/onRoomStartBroadcasting', 'room.startBroadcasting', filter);
44218
- };
44219
-
44220
- /**
44221
- * ```js
44222
- * import { onRoomWaitingReconnect } from '@amityco/ts-sdk'
44223
- * const dispose = onRoomWaitingReconnect(room => {
44224
- * // ...
44225
- * })
44226
- * ```
44227
- *
44228
- * Fired when a {@link Amity.Room} is waiting for reconnection
44229
- *
44230
- * @param callback The function to call when the event was fired
44231
- * @returns an {@link Amity.Unsubscriber} function to stop listening
44232
- *
44233
- * @category Room Events
44234
- */
44235
- const onRoomWaitingReconnect = (callback) => {
45308
+ const getStream = async (streamId) => {
44236
45309
  const client = getActiveClient();
44237
- const filter = (payload) => {
44238
- ingestInCache(payload);
44239
- callback(payload.rooms[0]);
45310
+ client.log('stream/getStream', streamId);
45311
+ const { data } = await client.http.get(`/api/v3/video-streaming/${streamId}`);
45312
+ const cachedAt = client.cache && Date.now();
45313
+ if (client.cache)
45314
+ ingestInCache(data, { cachedAt });
45315
+ const { videoStreamings } = data;
45316
+ return {
45317
+ data: videoStreamings.find(stream => stream.streamId === streamId),
45318
+ cachedAt,
44240
45319
  };
44241
- return createEventSubscriber(client, 'room/onRoomWaitingReconnect', 'room.waitingReconnect', filter);
44242
45320
  };
44243
-
45321
+ /* end_public_function */
44244
45322
  /**
44245
45323
  * ```js
44246
- * import { onRoomEndBroadcasting } from '@amityco/ts-sdk'
44247
- * const dispose = onRoomEndBroadcasting(room => {
44248
- * // ...
44249
- * })
45324
+ * import { getStream } from '@amityco/ts-sdk'
45325
+ * const stream = getStream.locally('foobar')
44250
45326
  * ```
44251
45327
  *
44252
- * Fired when a {@link Amity.Room} has ended broadcasting
45328
+ * Fetches a {@link Amity.Stream} object
44253
45329
  *
44254
- * @param callback The function to call when the event was fired
44255
- * @returns an {@link Amity.Unsubscriber} function to stop listening
45330
+ * @param streamId the ID of the {@link Amity.Stream} to fetch
45331
+ * @returns the associated {@link Amity.Stream} object
44256
45332
  *
44257
- * @category Room Events
45333
+ * @category Stream API
44258
45334
  */
44259
- const onRoomEndBroadcasting = (callback) => {
45335
+ getStream.locally = (streamId) => {
44260
45336
  const client = getActiveClient();
44261
- const filter = (payload) => {
44262
- ingestInCache(payload);
44263
- callback(payload.rooms[0]);
45337
+ client.log('stream/getStream', streamId);
45338
+ if (!client.cache)
45339
+ return;
45340
+ const cached = pullFromCache(['stream', 'get', streamId]);
45341
+ if (!cached)
45342
+ return;
45343
+ return {
45344
+ data: cached.data,
45345
+ cachedAt: cached.cachedAt,
44264
45346
  };
44265
- return createEventSubscriber(client, 'room/onRoomEndBroadcasting', 'room.endBroadcasting', filter);
44266
45347
  };
44267
45348
 
45349
+ // import { unwrapPayload } from '~/core/transports'
45350
+ /* begin_public_function
45351
+ id: stream.delete
45352
+ */
44268
45353
  /**
44269
45354
  * ```js
44270
- * import { onRoomRecordedAvailable } from '@amityco/ts-sdk'
44271
- * const dispose = onRoomRecordedAvailable(room => {
44272
- * // ...
44273
- * })
45355
+ * import { deleteStream } from '@amityco/ts-sdk'
45356
+ * const success = await deleteStream(streamId)
44274
45357
  * ```
44275
45358
  *
44276
- * Fired when a {@link Amity.Room} recorded content becomes available
45359
+ * Deletes a {@link Amity.InternalStream}
44277
45360
  *
44278
- * @param callback The function to call when the event was fired
44279
- * @returns an {@link Amity.Unsubscriber} function to stop listening
45361
+ * @param streamId The {@link Amity.InternalStream} ID to delete
45362
+ * @return A success boolean if the {@link Amity.InternalStream} was deleted
44280
45363
  *
44281
- * @category Room Events
45364
+ * @category Stream API
45365
+ * @async
44282
45366
  */
44283
- const onRoomRecordedAvailable = (callback) => {
45367
+ const deleteStream = async (streamId) => {
44284
45368
  const client = getActiveClient();
44285
- const filter = (payload) => {
44286
- ingestInCache(payload);
44287
- callback(payload.rooms[0]);
44288
- };
44289
- return createEventSubscriber(client, 'room/onRoomRecordedAvailable', 'room.recordedAvailable', filter);
45369
+ client.log('stream/deleteStream', streamId);
45370
+ const stream = await getStream(streamId);
45371
+ // API-FIX: it returns { success: boolean } but seems it should be Amity.Response<{ success: boolean }
45372
+ // API-FIX: swagger docs are wrong!
45373
+ const { data } = await client.http.delete(`/api/v3/video-streaming/${streamId}`);
45374
+ const { success } = data; // unwrapPayload(data)
45375
+ const deleted = Object.assign(Object.assign({}, stream.data), { isDeleted: true });
45376
+ upsertInCache(['stream', 'get', streamId], deleted);
45377
+ return success;
44290
45378
  };
45379
+ /* end_public_function */
44291
45380
 
44292
45381
  /**
44293
45382
  * ```js
44294
- * import { onRoomParticipantInviting } from '@amityco/ts-sdk'
44295
- * const dispose = onRoomParticipantInviting(room => {
44296
- * // ...
44297
- * })
45383
+ * import { disposeStream } from '@amityco/ts-sdk'
45384
+ * const stream = await disposeStream(streamId)
44298
45385
  * ```
44299
45386
  *
44300
- * Fired when a participant is being invited to a {@link Amity.Room}
45387
+ * Dispose a {@link Amity.InternalStream}.
45388
+ * Streaming status will be updated to "ended" and streaming url will be invalidated
44301
45389
  *
44302
- * @param callback The function to call when the event was fired
44303
- * @returns an {@link Amity.Unsubscriber} function to stop listening
45390
+ * @param streamId The {@link Amity.InternalStream} ID to dispose
45391
+ * @returns the associated {@link Amity.InternalStream} object
44304
45392
  *
44305
- * @category Room Events
45393
+ * @category Stream API
45394
+ * @async
44306
45395
  */
44307
- const onRoomCoHostInvited = (callback) => {
44308
- const client = getActiveClient();
44309
- const filter = (payload) => {
44310
- const data = prepareMyInvitationsPayload(payload);
44311
- ingestInCache(data);
44312
- callback(data.invitations);
44313
- };
44314
- return createEventSubscriber(client, 'room/onRoomCoHostInvited', 'room.didCohostInvite', filter);
44315
- };
44316
-
44317
- const getRoomById = async (roomId) => {
45396
+ const disposeStream = async (streamId) => {
44318
45397
  const client = getActiveClient();
44319
- client.log('room/getRoomById', roomId);
44320
- // Check if room is in tombstone
44321
- isInTombstone('room', roomId);
44322
- let data;
44323
- try {
44324
- const response = await client.http.get(`/api/v1/rooms/${roomId}`);
44325
- data = response.data;
44326
- }
44327
- catch (error) {
44328
- if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
44329
- pushToTombstone('room', roomId);
44330
- }
44331
- throw error;
44332
- }
45398
+ client.log('stream/disposeStream', streamId);
45399
+ const { data } = await client.http.delete(`/api/v3/video-streaming/${streamId}/streaming-url`);
44333
45400
  const cachedAt = client.cache && Date.now();
44334
- if (client.cache) {
45401
+ if (client.cache)
44335
45402
  ingestInCache(data, { cachedAt });
44336
- }
44337
- return {
44338
- data: data.rooms[0],
44339
- cachedAt,
44340
- };
44341
- };
44342
- getRoomById.locally = (roomId) => {
44343
- const client = getActiveClient();
44344
- client.log('room/getRoomById.locally', roomId);
44345
- // Check if room is in tombstone
44346
- isInTombstone('room', roomId);
44347
- const cachedAt = client.cache && Date.now();
44348
- const roomCache = pullFromCache(['room', 'get', roomId]);
44349
- if (!roomCache)
44350
- return;
45403
+ const { videoStreamings } = data;
44351
45404
  return {
44352
- data: roomCache.data,
45405
+ data: videoStreamings.find(stream => stream.streamId === streamId),
44353
45406
  cachedAt,
44354
45407
  };
44355
45408
  };
45409
+ /* end_public_function */
44356
45410
 
45411
+ /* begin_public_function
45412
+ id: stream.update
45413
+ */
44357
45414
  /**
44358
- * ```js
44359
- * import { onRoomCoHostInviteAccepted } from '@amityco/ts-sdk'
44360
- * const dispose = onRoomCoHostInviteAccepted(room => {
44361
- * // ...
44362
- * })
44363
- * ```
44364
- *
44365
- * Fired when a co-host invitation is accepted for a {@link Amity.Room}
44366
- *
44367
- * @param callback The function to call when the event was fired
44368
- * @returns an {@link Amity.Unsubscriber} function to stop listening
44369
- *
44370
- * @category Room Events
44371
- */
44372
- const onRoomCoHostInviteAccepted = (callback) => {
44373
- const client = getActiveClient();
44374
- const filter = async (payload) => {
44375
- var _a;
44376
- const data = prepareMyInvitationsPayload(payload);
44377
- await getRoomById((_a = data.invitations) === null || _a === void 0 ? void 0 : _a[0].targetId);
44378
- ingestInCache(data);
44379
- callback(data.invitations[0]);
44380
- };
44381
- return createEventSubscriber(client, 'room/onRoomCoHostInviteAccepted', 'room.didCohostInviteAccept', filter);
44382
- };
44383
-
44384
- /**
44385
- * ```js
44386
- * import { onRoomCoHostInviteRejected } from '@amityco/ts-sdk'
44387
- * const dispose = onRoomCoHostInviteRejected(room => {
44388
- * // ...
44389
- * })
44390
- * ```
44391
- *
44392
- * Fired when a co-host invitation is rejected for a {@link Amity.Room}
44393
- *
44394
- * @param callback The function to call when the event was fired
44395
- * @returns an {@link Amity.Unsubscriber} function to stop listening
44396
- *
44397
- * @category Room Events
44398
- */
44399
- const onRoomCoHostInviteRejected = (callback) => {
44400
- const client = getActiveClient();
44401
- const filter = (payload) => {
44402
- const data = prepareMyInvitationsPayload(payload);
44403
- ingestInCache(data);
44404
- callback(data.invitations);
44405
- };
44406
- return createEventSubscriber(client, 'room/onRoomCoHostInviteRejected', 'room.didCohostInviteReject', filter);
44407
- };
44408
-
44409
- /**
44410
- * ```js
44411
- * import { onRoomCoHostInviteCanceled } from '@amityco/ts-sdk'
44412
- * const dispose = onRoomCoHostInviteCanceled(room => {
44413
- * // ...
44414
- * })
44415
- * ```
44416
- *
44417
- * Fired when a co-host invitation is canceled for a {@link Amity.Room}
44418
- *
44419
- * @param callback The function to call when the event was fired
44420
- * @returns an {@link Amity.Unsubscriber} function to stop listening
44421
45415
  *
44422
- * @category Room Events
44423
- */
44424
- const onRoomCoHostInviteCanceled = (callback) => {
44425
- const client = getActiveClient();
44426
- const filter = (payload) => {
44427
- const data = prepareMyInvitationsPayload(payload);
44428
- ingestInCache(data);
44429
- callback(data.invitations);
44430
- };
44431
- return createEventSubscriber(client, 'room/onRoomCoHostInviteCanceled', 'room.didCohostInviteCancel', filter);
44432
- };
44433
-
44434
- /**
44435
45416
  * ```js
44436
- * import { onRoomParticipantJoined } from '@amityco/ts-sdk'
44437
- * const dispose = onRoomParticipantJoined(room => {
44438
- * // ...
44439
- * })
45417
+ * import { StreamRepository } from '@amityco/ts-sdk'
45418
+ * const updated = await StreamRepository.editStream(streamId, { title: 'foobar' })
44440
45419
  * ```
44441
45420
  *
44442
- * Fired when a participant has joined a {@link Amity.Room}
45421
+ * Updates an {@link Amity.Stream}
44443
45422
  *
44444
- * @param callback The function to call when the event was fired
44445
- * @returns an {@link Amity.Unsubscriber} function to stop listening
45423
+ * @param streamId The ID of the {@link Amity.Stream} to edit
45424
+ * @param patch The patch data to apply
45425
+ * @returns the updated {@link Amity.Stream} object
44446
45426
  *
44447
- * @category Room Events
45427
+ * @category Stream API
45428
+ * @async
44448
45429
  */
44449
- const onRoomParticipantJoined = (callback) => {
45430
+ const editStream = async (streamId, patch) => {
44450
45431
  const client = getActiveClient();
44451
- const filter = (payload) => {
44452
- ingestInCache(payload);
44453
- callback(payload.rooms[0]);
45432
+ client.log('stream/updateStream', streamId, patch);
45433
+ const { data } = await client.http.put(`/api/v3/video-streaming/${streamId}`, patch);
45434
+ const cachedAt = client.cache && Date.now();
45435
+ if (client.cache)
45436
+ ingestInCache(data, { cachedAt });
45437
+ const { videoStreamings } = data;
45438
+ return {
45439
+ data: LinkedObject.stream(videoStreamings.find(stream => stream.streamId === streamId)),
45440
+ cachedAt,
44454
45441
  };
44455
- return createEventSubscriber(client, 'room/onRoomParticipantJoined', 'room.participantJoined', filter);
44456
45442
  };
45443
+ /* end_public_function */
44457
45444
 
44458
45445
  /**
44459
45446
  * ```js
44460
- * import { onRoomParticipantLeft } from '@amityco/ts-sdk'
44461
- * const dispose = onRoomParticipantLeft(room => {
45447
+ * import { onStreamStarted } from '@amityco/ts-sdk'
45448
+ * const dispose = onStreamStarted(stream => {
44462
45449
  * // ...
44463
45450
  * })
44464
45451
  * ```
44465
45452
  *
44466
- * Fired when a participant has left a {@link Amity.Room}
45453
+ * Fired when a {@link Amity.InternalStream} has started airing
44467
45454
  *
44468
45455
  * @param callback The function to call when the event was fired
44469
45456
  * @returns an {@link Amity.Unsubscriber} function to stop listening
44470
45457
  *
44471
- * @category Room Events
45458
+ * @category Stream Events
44472
45459
  */
44473
- const onRoomParticipantLeft = (callback) => {
45460
+ const onStreamStarted = (callback) => {
44474
45461
  const client = getActiveClient();
44475
45462
  const filter = (payload) => {
44476
45463
  ingestInCache(payload);
44477
- callback(payload.rooms[0]);
45464
+ callback(payload.videoStreamings[0]);
44478
45465
  };
44479
- return createEventSubscriber(client, 'room/onRoomParticipantLeft', 'room.participantLeft', filter);
45466
+ return createEventSubscriber(client, 'stream/onStreamStarted', 'video-streaming.didStart', filter);
44480
45467
  };
44481
45468
 
44482
45469
  /**
44483
45470
  * ```js
44484
- * import { onRoomCreated } from '@amityco/ts-sdk'
44485
- * const dispose = onRoomCreated(room => {
45471
+ * import { onStreamStopped } from '@amityco/ts-sdk'
45472
+ * const dispose = onStreamStopped(stream => {
44486
45473
  * // ...
44487
45474
  * })
44488
45475
  * ```
44489
45476
  *
44490
- * Fired when a {@link Amity.Room} has been created locally
45477
+ * Fired when a {@link Amity.InternalStream} has stopped airing
44491
45478
  *
44492
45479
  * @param callback The function to call when the event was fired
44493
45480
  * @returns an {@link Amity.Unsubscriber} function to stop listening
44494
45481
  *
44495
- * @category Room Events
45482
+ * @category Stream Events
44496
45483
  */
44497
- const onRoomCreated = (callback) => {
45484
+ const onStreamStopped = (callback) => {
44498
45485
  const client = getActiveClient();
44499
45486
  const filter = (payload) => {
44500
45487
  ingestInCache(payload);
44501
- callback(payload.rooms[0]);
45488
+ callback(payload.videoStreamings[0]);
44502
45489
  };
44503
- return createEventSubscriber(client, 'room/onRoomCreated', 'local.room.created', filter);
45490
+ return createEventSubscriber(client, 'stream/onStreamStropped', 'video-streaming.didStop', filter);
44504
45491
  };
44505
45492
 
44506
45493
  /**
44507
45494
  * ```js
44508
- * import { onRoomUpdated } from '@amityco/ts-sdk'
44509
- * const dispose = onRoomUpdated(room => {
45495
+ * import { onStreamRecorded } from '@amityco/ts-sdk'
45496
+ * const dispose = onStreamRecorded(stream => {
44510
45497
  * // ...
44511
45498
  * })
44512
45499
  * ```
44513
45500
  *
44514
- * Fired when a {@link Amity.Room} has been updated locally
45501
+ * Fired when the recordings of a {@link Amity.InternalStream} are available
44515
45502
  *
44516
45503
  * @param callback The function to call when the event was fired
44517
45504
  * @returns an {@link Amity.Unsubscriber} function to stop listening
44518
45505
  *
44519
- * @category Room Events
45506
+ * @category Stream Events
44520
45507
  */
44521
- const onRoomUpdated = (callback) => {
45508
+ const onStreamRecorded = (callback) => {
44522
45509
  const client = getActiveClient();
44523
45510
  const filter = (payload) => {
44524
45511
  ingestInCache(payload);
44525
- callback(payload.rooms[0]);
45512
+ callback(payload.videoStreamings[0]);
44526
45513
  };
44527
- return createEventSubscriber(client, 'room/onRoomUpdated', 'local.room.updated', filter);
45514
+ return createEventSubscriber(client, 'stream/onStreamRecorded', 'video-streaming.didRecord', filter);
44528
45515
  };
44529
45516
 
44530
45517
  /**
44531
45518
  * ```js
44532
- * import { onRoomDeleted } from '@amityco/ts-sdk'
44533
- * const dispose = onRoomDeleted(room => {
45519
+ * import { onStreamFlagged } from '@amityco/ts-sdk'
45520
+ * const dispose = onStreamFlagged(stream => {
44534
45521
  * // ...
44535
45522
  * })
44536
45523
  * ```
44537
45524
  *
44538
- * Fired when a {@link Amity.Room} has been deleted locally
45525
+ * Fired when a {@link Amity.InternalStream} has started airing
44539
45526
  *
44540
45527
  * @param callback The function to call when the event was fired
44541
45528
  * @returns an {@link Amity.Unsubscriber} function to stop listening
44542
45529
  *
44543
- * @category Room Events
45530
+ * @category Stream Events
44544
45531
  */
44545
- const onRoomDeleted = (callback) => {
45532
+ const onStreamFlagged = (callback) => {
44546
45533
  const client = getActiveClient();
44547
45534
  const filter = (payload) => {
44548
45535
  ingestInCache(payload);
44549
- callback(payload.rooms[0]);
45536
+ callback(payload.videoStreamings[0]);
44550
45537
  };
44551
- return createEventSubscriber(client, 'room/onRoomDeleted', 'local.room.deleted', filter);
45538
+ return createEventSubscriber(client, 'stream/onStreamFlagged', 'video-streaming.didFlag', filter);
44552
45539
  };
44553
45540
 
44554
45541
  /**
44555
45542
  * ```js
44556
- * import { onRoomStopped } from '@amityco/ts-sdk'
44557
- * const dispose = onRoomStopped(room => {
45543
+ * import { onStreamTerminated } from '@amityco/ts-sdk'
45544
+ * const dispose = onStreamTerminated(stream => {
44558
45545
  * // ...
44559
45546
  * })
44560
45547
  * ```
44561
45548
  *
44562
- * Fired when a {@link Amity.Room} has been stopped locally
45549
+ * Fired when a {@link Amity.InternalStream} has started airing
44563
45550
  *
44564
45551
  * @param callback The function to call when the event was fired
44565
45552
  * @returns an {@link Amity.Unsubscriber} function to stop listening
44566
45553
  *
44567
- * @category Room Events
45554
+ * @category Stream Events
44568
45555
  */
44569
- const onRoomStopped = (callback) => {
45556
+ const onStreamTerminated = (callback) => {
44570
45557
  const client = getActiveClient();
44571
45558
  const filter = (payload) => {
44572
45559
  ingestInCache(payload);
44573
- callback(payload.rooms[0]);
45560
+ callback(payload.videoStreamings[0]);
44574
45561
  };
44575
- return createEventSubscriber(client, 'room/onRoomStopped', 'local.room.stopped', filter);
45562
+ return createEventSubscriber(client, 'stream/onStreamTerminated', 'video-streaming.didTerminate', filter);
44576
45563
  };
44577
45564
 
44578
45565
  /**
44579
45566
  * ```js
44580
- * import { onRoomParticipantRemoved } from '@amityco/ts-sdk'
44581
- * const dispose = onRoomParticipantRemoved(room => {
45567
+ * import { onStreamViewerUnbanned } from '@amityco/ts-sdk'
45568
+ * const dispose = onStreamViewerBanned(stream => {
44582
45569
  * // ...
44583
45570
  * })
44584
45571
  * ```
44585
45572
  *
44586
- * Fired when a participant has been removed from a {@link Amity.Room} locally
45573
+ * Fired when a user in channel linked to stream has been unbanned
44587
45574
  *
44588
45575
  * @param callback The function to call when the event was fired
44589
45576
  * @returns an {@link Amity.Unsubscriber} function to stop listening
44590
45577
  *
44591
- * @category Room Events
45578
+ * @category Stream Events
44592
45579
  */
44593
- const onRoomParticipantRemoved = (callback) => {
45580
+ const onStreamViewerUnbanned = (callback) => {
44594
45581
  const client = getActiveClient();
44595
- const filter = (payload) => {
44596
- ingestInCache(payload);
44597
- callback(payload.rooms[0]);
45582
+ const filter = async (payloads) => {
45583
+ var _a;
45584
+ // Get new stream object to restore stream watcherUrl in cache
45585
+ const { list } = payloads;
45586
+ await Promise.all(list.map(({ streamId }) => getStream(streamId)));
45587
+ const stream = (_a = pullFromCache(['stream', 'get', list[0].streamId])) === null || _a === void 0 ? void 0 : _a.data;
45588
+ if (!stream)
45589
+ return;
45590
+ callback(stream);
44598
45591
  };
44599
- return createEventSubscriber(client, 'room/onRoomParticipantRemoved', 'room.participantRemoved', filter);
45592
+ return createEventSubscriber(client, 'stream/onStreamViewerDidUnban', 'video-streaming.viewerDidUnban', filter);
44600
45593
  };
44601
45594
 
45595
+ /* eslint-disable no-use-before-define */
45596
+ /* begin_public_function
45597
+ id: stream.get
45598
+ */
44602
45599
  /**
44603
45600
  * ```js
44604
- * import { onRoomLeft } from '@amityco/ts-sdk'
44605
- * const dispose = onRoomLeft(room => {
44606
- * // ...
44607
- * })
45601
+ * import { StreamRepository } from '@amityco/ts-sdk'
45602
+ * const unsub = StreamRepository.getStreamById('foobar')
45603
+ * unsub()
44608
45604
  * ```
44609
45605
  *
44610
- * Fired when a user has left a {@link Amity.Room} locally
45606
+ * Fetches a {@link Amity.Stream} object
44611
45607
  *
44612
- * @param callback The function to call when the event was fired
44613
- * @returns an {@link Amity.Unsubscriber} function to stop listening
45608
+ * @param streamId the ID of the {@link Amity.Stream} to get
45609
+ * @param callback
45610
+ * @returns the associated {@link Amity.Stream} object
44614
45611
  *
44615
- * @category Room Events
45612
+ * @category Stream Live Object
44616
45613
  */
44617
- const onRoomLeft = (callback) => {
44618
- const client = getActiveClient();
44619
- const filter = (payload) => {
44620
- ingestInCache(payload);
44621
- callback(payload.rooms[0]);
45614
+ const getStreamById = (streamId, callback) => {
45615
+ const reactor = (snapshot) => {
45616
+ const { data } = snapshot;
45617
+ callback(Object.assign(Object.assign({}, snapshot), { data: data ? LinkedObject.stream(snapshot.data) : data }));
44622
45618
  };
44623
- return createEventSubscriber(client, 'room/onRoomLeft', 'local.room.left', filter);
45619
+ return liveObject(streamId, reactor, 'streamId', getStream, [
45620
+ onStreamRecorded,
45621
+ onStreamStarted,
45622
+ onStreamStopped,
45623
+ onStreamFlagged,
45624
+ onStreamTerminated,
45625
+ onStreamViewerBanned,
45626
+ ]);
44624
45627
  };
44625
-
45628
+ /* end_public_function */
44626
45629
  /**
44627
45630
  * ```js
44628
- * import { onRoomParticipantRemoved } from '@amityco/ts-sdk'
44629
- * const dispose = onRoomParticipantRemoved(room => {
44630
- * // ...
44631
- * })
45631
+ * import { StreamRepository } from '@amityco/ts-sdk'
45632
+ * const stream = StreamRepository.getStreamById.locally('foobar')
44632
45633
  * ```
44633
45634
  *
44634
- * Fired when a participant has been removed from a {@link Amity.Room} locally
45635
+ * Fetches a {@link Amity.Stream} live object
44635
45636
  *
44636
- * @param callback The function to call when the event was fired
44637
- * @returns an {@link Amity.Unsubscriber} function to stop listening
45637
+ * @param streamId the ID of the {@link Amity.Stream} to fetch
45638
+ * @returns the associated {@link Amity.Stream} live object
44638
45639
  *
44639
- * @category Room Events
45640
+ * @category Stream API
44640
45641
  */
44641
- const onRoomParticipantRemovedLocal = (callback) => {
45642
+ getStreamById.locally = (streamId) => {
44642
45643
  const client = getActiveClient();
44643
- const filter = (payload) => {
44644
- ingestInCache(payload);
44645
- callback(payload.rooms[0]);
45644
+ client.log('stream/getStreamById', streamId);
45645
+ if (!client.cache)
45646
+ return;
45647
+ const cached = pullFromCache(['stream', 'get', streamId]);
45648
+ if (!cached)
45649
+ return;
45650
+ return {
45651
+ data: LinkedObject.stream(cached.data),
45652
+ cachedAt: cached.cachedAt,
44646
45653
  };
44647
- return createEventSubscriber(client, 'room/onRoomParticipantRemoved', 'local.room.participantRemoved', filter);
44648
- };
44649
-
44650
- const getRoom = (roomId, callback) => {
44651
- // TODO: add callbackDataSelector if there are linked object fields
44652
- return liveObject(roomId, callback, '_id', getRoomById, [
44653
- onRoomEndBroadcasting,
44654
- onRoomStartBroadcasting,
44655
- onRoomWaitingReconnect,
44656
- onRoomRecordedAvailable,
44657
- onRoomParticipantJoined,
44658
- onRoomParticipantLeft,
44659
- onRoomParticipantRemoved,
44660
- onRoomParticipantRemovedLocal,
44661
- convertEventPayload(onRoomCoHostInviteAccepted, 'targetId', 'room'),
44662
- ], {
44663
- callbackDataSelector: (data) => {
44664
- if (!data)
44665
- return data;
44666
- return LinkedObject.room(data);
44667
- },
44668
- });
44669
45654
  };
44670
45655
 
44671
- class RoomPaginationController extends PaginationController {
45656
+ class GetStreamsPageController extends PaginationController {
44672
45657
  async getRequest(queryParams, token) {
44673
- const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
44674
- const baseOptions = {
44675
- type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
44676
- };
44677
- const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
44678
- const { data: queryResponse } = await this.http.get(`/api/v1/rooms`, {
44679
- params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options }),
45658
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
45659
+ const options = token ? { token } : { limit };
45660
+ const { data: queryResponse } = await this.http.get(`/api/v3/video-streaming`, {
45661
+ params: Object.assign(Object.assign({}, params), { options }),
44680
45662
  });
44681
- return queryResponse;
45663
+ return Object.assign(Object.assign({}, queryResponse.results), { paging: queryResponse.paging });
44682
45664
  }
44683
45665
  }
44684
45666
 
44685
- var EnumRoomActions;
44686
- (function (EnumRoomActions) {
44687
- EnumRoomActions["OnRoomCreated"] = "OnRoomCreated";
44688
- EnumRoomActions["OnRoomUpdated"] = "OnRoomUpdated";
44689
- EnumRoomActions["OnRoomDeleted"] = "OnRoomDeleted";
44690
- EnumRoomActions["OnRoomStartBroadcasting"] = "OnRoomStartBroadcasting";
44691
- EnumRoomActions["OnRoomEndBroadcasting"] = "OnRoomEndBroadcasting";
44692
- EnumRoomActions["OnRoomParticipantJoined"] = "OnRoomParticipantJoined";
44693
- EnumRoomActions["OnRoomParticipantLeft"] = "OnRoomParticipantLeft";
44694
- })(EnumRoomActions || (EnumRoomActions = {}));
44695
-
44696
- class RoomQueryStreamController extends QueryStreamController {
44697
- constructor(query, cacheKey, notifyChange, preparePayload) {
45667
+ class GetStreamsQueryStreamController extends QueryStreamController {
45668
+ constructor(query, cacheKey, notifyChange, paginationController) {
44698
45669
  super(query, cacheKey);
44699
45670
  this.notifyChange = notifyChange;
44700
- this.preparePayload = preparePayload;
45671
+ this.paginationController = paginationController;
44701
45672
  }
44702
- async saveToMainDB(response) {
44703
- const processedPayload = await this.preparePayload(response);
45673
+ // eslint-disable-next-line class-methods-use-this
45674
+ saveToMainDB(response) {
44704
45675
  const client = getActiveClient();
44705
45676
  const cachedAt = client.cache && Date.now();
44706
45677
  if (client.cache) {
44707
- ingestInCache(processedPayload, { cachedAt });
45678
+ ingestInCache(response, { cachedAt });
44708
45679
  }
44709
45680
  }
44710
45681
  appendToQueryStream(response, direction, refresh = false) {
44711
45682
  var _a, _b;
44712
45683
  if (refresh) {
44713
45684
  pushToCache(this.cacheKey, {
44714
- data: response.rooms.map(getResolver('room')),
45685
+ data: response.videoStreamings.map(getResolver('stream')),
45686
+ query: this.query,
44715
45687
  });
44716
45688
  }
44717
45689
  else {
44718
45690
  const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
44719
- const rooms = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
44720
- pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...rooms, ...response.rooms.map(getResolver('room'))])] }));
45691
+ const messages = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
45692
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: direction === 'next'
45693
+ ? [...new Set([...messages, ...response.videoStreamings.map(getResolver('stream'))])]
45694
+ : [...new Set([...response.videoStreamings.map(getResolver('stream')), ...messages])] }));
44721
45695
  }
44722
45696
  }
44723
45697
  reactor(action) {
44724
- return (room) => {
45698
+ return (payload) => {
44725
45699
  var _a;
44726
45700
  const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
44727
45701
  if (!collection)
44728
45702
  return;
44729
- if (action === EnumRoomActions.OnRoomDeleted) {
44730
- collection.data = collection.data.filter(roomId => roomId !== room._id);
44731
- }
44732
- if (action === EnumRoomActions.OnRoomCreated) {
44733
- collection.data = [...new Set([room._id, ...collection.data])];
44734
- }
45703
+ collection.data = [...new Set([payload.streamId, ...collection.data])];
44735
45704
  pushToCache(this.cacheKey, collection);
44736
45705
  this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
44737
45706
  };
@@ -44741,171 +45710,107 @@ class RoomQueryStreamController extends QueryStreamController {
44741
45710
  }
44742
45711
  }
44743
45712
 
44744
- // TODO: confirm related events
44745
- const getRoomSubscription = () => [
44746
- {
44747
- fn: onRoomStartBroadcasting,
44748
- action: EnumRoomActions.OnRoomStartBroadcasting,
44749
- },
44750
- {
44751
- fn: onRoomEndBroadcasting,
44752
- action: EnumRoomActions.OnRoomEndBroadcasting,
44753
- },
44754
- {
44755
- fn: onRoomRecordedAvailable,
44756
- action: EnumRoomActions.OnRoomUpdated,
44757
- },
44758
- ];
44759
-
44760
- class RoomLiveCollectionController extends LiveCollectionController {
45713
+ class GetStreamsLiveCollectionController extends LiveCollectionController {
44761
45714
  constructor(query, callback) {
44762
45715
  const queryStreamId = hash(query);
44763
- const cacheKey = ['rooms', 'collection', queryStreamId];
44764
- const paginationController = new RoomPaginationController(query);
45716
+ const cacheKey = ['streams', 'collection', queryStreamId];
45717
+ const paginationController = new GetStreamsPageController(query);
44765
45718
  super(paginationController, queryStreamId, cacheKey, callback);
45719
+ this.applyFilter = (data) => {
45720
+ let streams = filterByPropEquality(data, 'isDeleted', this.query.isDeleted);
45721
+ streams = streams.sort(this.query.sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
45722
+ return streams;
45723
+ };
44766
45724
  this.query = query;
44767
- this.queryStreamController = new RoomQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), response => response);
45725
+ this.queryStreamController = new GetStreamsQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), paginationController);
45726
+ this.paginationController = paginationController;
44768
45727
  this.callback = callback.bind(this);
44769
45728
  this.loadPage({ initial: true });
44770
45729
  }
44771
- setup() {
44772
- var _a;
44773
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
44774
- if (!collection) {
44775
- pushToCache(this.cacheKey, {
44776
- data: [],
44777
- params: {},
44778
- });
44779
- }
44780
- }
44781
- async persistModel(queryPayload) {
44782
- await this.queryStreamController.saveToMainDB(queryPayload);
44783
- }
44784
- persistQueryStream({ response, direction, refresh, }) {
44785
- this.queryStreamController.appendToQueryStream(response, direction, refresh);
44786
- }
44787
- startSubscription() {
44788
- return this.queryStreamController.subscribeRTE(getRoomSubscription());
44789
- }
44790
45730
  notifyChange({ origin, loading, error }) {
44791
- var _a, _b;
45731
+ var _a;
44792
45732
  const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
44793
45733
  if (!collection)
44794
45734
  return;
44795
- const data = this.applyFilter((_b = collection.data
44796
- .map(id => pullFromCache(['room', 'get', id]))
44797
- .filter(isNonNullable)
44798
- .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(room => room); // Since Room is same as InternalRoom, no transformation needed
45735
+ let data = collection.data
45736
+ .map(streamId => pullFromCache(['stream', 'get', streamId]))
45737
+ .filter(Boolean)
45738
+ .map(stream => LinkedObject.stream(stream.data));
44799
45739
  if (!this.shouldNotify(data) && origin === 'event')
44800
45740
  return;
45741
+ data = this.applyFilter(data);
44801
45742
  this.callback({
44802
- onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
45743
+ onNextPage: () => this.loadPage({ initial: false, direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
44803
45744
  data,
44804
45745
  hasNextPage: !!this.paginationController.getNextToken(),
44805
45746
  loading,
44806
45747
  error,
44807
45748
  });
44808
45749
  }
44809
- applyFilter(data) {
44810
- let rooms = data;
44811
- if (!this.query.includeDeleted) {
44812
- rooms = filterByPropEquality(rooms, 'isDeleted', false);
44813
- }
44814
- if (this.query.statuses && this.query.statuses.length > 0) {
44815
- rooms = rooms.filter(room => { var _a; return (_a = this.query.statuses) === null || _a === void 0 ? void 0 : _a.includes(room.status); });
44816
- }
44817
- if (this.query.type) {
44818
- rooms = filterByPropEquality(rooms, 'type', this.query.type);
44819
- }
44820
- switch (this.query.sortBy) {
44821
- case 'firstCreated':
44822
- rooms = rooms.sort(sortByFirstCreated);
44823
- break;
44824
- case 'lastCreated':
44825
- default:
44826
- rooms = rooms.sort(sortByLastCreated);
44827
- break;
45750
+ startSubscription() {
45751
+ return this.queryStreamController.subscribeRTE([
45752
+ { fn: onStreamRecorded, action: 'onStreamRecorded' },
45753
+ { fn: onStreamStarted, action: 'onStreamStarted' },
45754
+ { fn: onStreamStopped, action: 'onStreamStopped' },
45755
+ { fn: onStreamFlagged, action: 'onStreamFlagged' },
45756
+ { fn: onStreamTerminated, action: 'onStreamTerminated' },
45757
+ { fn: onStreamViewerBanned, action: 'onStreamViewerBanned' },
45758
+ { fn: onStreamViewerUnbanned, action: 'onStreamViewerUnbanned' },
45759
+ ]);
45760
+ }
45761
+ setup() {
45762
+ var _a;
45763
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
45764
+ if (!collection) {
45765
+ pushToCache(this.cacheKey, {
45766
+ data: [],
45767
+ params: {},
45768
+ });
44828
45769
  }
44829
- return rooms;
45770
+ }
45771
+ persistModel(response) {
45772
+ this.queryStreamController.saveToMainDB(response);
45773
+ }
45774
+ persistQueryStream({ response, direction, refresh, }) {
45775
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
44830
45776
  }
44831
45777
  }
44832
45778
 
44833
- /* begin_public_function
44834
- id: room.get_rooms
44835
- */
44836
- /**
44837
- * ```js
44838
- * import { RoomRepository } from '@amityco/ts-sdk'
44839
- *
44840
- * let rooms = []
44841
- * const unsub = RoomRepository.getRooms({
44842
- * type: 'direct_streaming',
44843
- * statuses: ['live', 'idle'],
44844
- * sortBy: 'lastCreated',
44845
- * limit: 20,
44846
- * includeDeleted: false
44847
- * }, response => merge(rooms, response.data))
44848
- * ```
44849
- *
44850
- * Observe all mutations on a list of {@link Amity.Room} for a given query
44851
- *
44852
- * @param params.type the type of rooms to filter by ('direct_streaming' | 'co_hosts')
44853
- * @param params.statuses array of room statuses to filter by (['idle', 'live', 'waiting_reconnect', 'ended', 'recorded'])
44854
- * @param params.sortBy sort rooms by creation time ('firstCreated' | 'lastCreated')
44855
- * @param params.limit maximum number of rooms to retrieve per page
44856
- * @param params.includeDeleted whether to include deleted rooms in the results
44857
- * @param callback the function to call when new data are available
44858
- * @param config optional configuration for the live collection
44859
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the rooms
44860
- *
44861
- * @category Rooms Live Collection
44862
- */
44863
- const getRooms = (params, callback, config) => {
44864
- const { log, cache } = getActiveClient();
45779
+ const getStreams = (params, callback, config) => {
45780
+ const { log, cache, userId } = getActiveClient();
44865
45781
  if (!cache) {
44866
45782
  console.log(ENABLE_CACHE_MESSAGE);
44867
45783
  }
44868
45784
  const timestamp = Date.now();
44869
- log(`getRooms(tmpid: ${timestamp}) > listen`);
44870
- const roomsLiveCollection = new RoomLiveCollectionController(params, callback);
44871
- const disposers = roomsLiveCollection.startSubscription();
44872
- const cacheKey = roomsLiveCollection.getCacheKey();
44873
- disposers.push(() => dropFromCache(cacheKey));
45785
+ log(`getStreams(tmpid: ${timestamp}) > listen`);
45786
+ const liveCollection = new GetStreamsLiveCollectionController(params, callback);
45787
+ const disposers = liveCollection.startSubscription();
45788
+ const cacheKey = liveCollection.getCacheKey();
45789
+ disposers.push(() => {
45790
+ dropFromCache(cacheKey);
45791
+ });
44874
45792
  return () => {
44875
- log(`getRooms(tmpid: ${timestamp}) > dispose`);
45793
+ log(`getStreams(tmpid: ${timestamp}) > dispose`);
44876
45794
  disposers.forEach(fn => fn());
44877
45795
  };
44878
45796
  };
44879
- /* end_public_function */
44880
45797
 
44881
45798
  var index$9 = /*#__PURE__*/Object.freeze({
44882
45799
  __proto__: null,
44883
- createRoom: createRoom,
44884
- updateRoom: updateRoom,
44885
- deleteRoom: deleteRoom,
44886
- stopRoom: stopRoom,
44887
- getBroadcasterData: getBroadcasterData,
44888
- getRecordedUrl: getRecordedUrl,
44889
- removeParticipant: removeParticipant,
44890
- leaveRoom: leaveRoom,
44891
- onRoomStartBroadcasting: onRoomStartBroadcasting,
44892
- onRoomWaitingReconnect: onRoomWaitingReconnect,
44893
- onRoomEndBroadcasting: onRoomEndBroadcasting,
44894
- onRoomRecordedAvailable: onRoomRecordedAvailable,
44895
- onRoomCoHostInvited: onRoomCoHostInvited,
44896
- onRoomCoHostInviteAccepted: onRoomCoHostInviteAccepted,
44897
- onRoomCoHostInviteRejected: onRoomCoHostInviteRejected,
44898
- onRoomCoHostInviteCanceled: onRoomCoHostInviteCanceled,
44899
- onRoomParticipantJoined: onRoomParticipantJoined,
44900
- onRoomParticipantLeft: onRoomParticipantLeft,
44901
- onRoomCreated: onRoomCreated,
44902
- onRoomUpdated: onRoomUpdated,
44903
- onRoomDeleted: onRoomDeleted,
44904
- onRoomStopped: onRoomStopped,
44905
- onRoomParticipantRemoved: onRoomParticipantRemoved,
44906
- onRoomLeft: onRoomLeft,
44907
- getRoom: getRoom,
44908
- getRooms: getRooms
45800
+ createStream: createStream,
45801
+ updateStream: updateStream,
45802
+ deleteStream: deleteStream,
45803
+ disposeStream: disposeStream,
45804
+ editStream: editStream,
45805
+ onStreamStarted: onStreamStarted,
45806
+ onStreamStopped: onStreamStopped,
45807
+ onStreamRecorded: onStreamRecorded,
45808
+ onStreamFlagged: onStreamFlagged,
45809
+ onStreamTerminated: onStreamTerminated,
45810
+ onStreamViewerBanned: onStreamViewerBanned,
45811
+ onStreamViewerUnbanned: onStreamViewerUnbanned,
45812
+ getStreamById: getStreamById,
45813
+ getStreams: getStreams
44909
45814
  });
44910
45815
 
44911
45816
  /* begin_public_function
@@ -44980,7 +45885,6 @@ const getRoomUserCount = async (roomId) => {
44980
45885
  client.log('roomPresence/getRoomUserCount', { roomId });
44981
45886
  const { data } = await client.http.get(`/api/v1/presence/rooms/${roomId}/users/count`);
44982
45887
  pushToCache(['get', 'watchingCount', roomId], data);
44983
- fireEvent('local.room.watchingCountUpdated', data);
44984
45888
  return data;
44985
45889
  };
44986
45890
  /* end_public_function */
@@ -47934,30 +48838,6 @@ var index$1 = /*#__PURE__*/Object.freeze({
47934
48838
  getReactions: getReactions
47935
48839
  });
47936
48840
 
47937
- const prepareEventPayload = (rawPayload) => {
47938
- return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser) });
47939
- };
47940
-
47941
- const createEventEventSubscriber = (event, callback) => {
47942
- const client = getActiveClient();
47943
- const filter = (payload) => {
47944
- const unpackedPayload = prepareEventPayload(payload);
47945
- if (!client.cache) {
47946
- callback(unpackedPayload.events[0]);
47947
- }
47948
- else {
47949
- ingestInCache(unpackedPayload);
47950
- const event = pullFromCache([
47951
- 'event',
47952
- 'get',
47953
- unpackedPayload.events[0].eventId,
47954
- ]);
47955
- callback(event.data);
47956
- }
47957
- };
47958
- return createEventSubscriber(client, event, event, filter);
47959
- };
47960
-
47961
48841
  /* begin_public_function
47962
48842
  id: event.create
47963
48843
  */
@@ -48110,115 +48990,13 @@ const deleteEvent = async (eventId) => {
48110
48990
  users: [],
48111
48991
  files: [],
48112
48992
  communities: [],
48113
- videoStreamings: [],
48993
+ posts: [],
48994
+ rooms: [],
48114
48995
  events: [deletedEvent],
48115
- discussionCommunities: [],
48116
48996
  });
48117
48997
  };
48118
48998
  /* end_public_function */
48119
48999
 
48120
- /**
48121
- * ```js
48122
- * import { EventRepository } from '@amityco/ts-sdk'
48123
- * const dispose = EventRepository.onEventCreated(event => {
48124
- * // ...
48125
- * })
48126
- * ```
48127
- *
48128
- * Fired when a {@link Amity.Event} has been created
48129
- *
48130
- * @param callback The function to call when the event was fired
48131
- * @returns an {@link Amity.Unsubscriber} function to stop listening
48132
- *
48133
- * @category Event Events
48134
- */
48135
- const onEventCreated = (callback) => createEventEventSubscriber('event.created', callback);
48136
-
48137
- /**
48138
- * ```js
48139
- * import { EventRepository } from '@amityco/ts-sdk'
48140
- * const dispose = EventRepository.onEventUpdated(event => {
48141
- * // ...
48142
- * })
48143
- * ```
48144
- *
48145
- * Fired when a {@link Amity.Event} has been updated
48146
- *
48147
- * @param callback The function to call when the event was fired
48148
- * @returns an {@link Amity.Unsubscriber} function to stop listening
48149
- *
48150
- * @category Event Events
48151
- */
48152
- const onEventUpdated = (callback) => createEventEventSubscriber('event.updated', callback);
48153
-
48154
- /**
48155
- * ```js
48156
- * import { EventRepository } from '@amityco/ts-sdk'
48157
- * const dispose = EventRepository.onEventDeleted(event => {
48158
- * // ...
48159
- * })
48160
- * ```
48161
- *
48162
- * Fired when a {@link Amity.Event} has been deleted
48163
- *
48164
- * @param callback The function to call when the event was fired
48165
- * @returns an {@link Amity.Unsubscriber} function to stop listening
48166
- *
48167
- * @category Event Events
48168
- */
48169
- const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted', callback);
48170
-
48171
- /**
48172
- * ```js
48173
- * import { EventRepository } from '@amityco/ts-sdk'
48174
- * const dispose = EventRepository.onLocalEventCreated(event => {
48175
- * // ...
48176
- * })
48177
- * ```
48178
- *
48179
- * Fired when a {@link Amity.Event} has been created
48180
- *
48181
- * @param callback The function to call when the event was fired
48182
- * @returns an {@link Amity.Unsubscriber} function to stop listening
48183
- *
48184
- * @category Event Events
48185
- */
48186
- const onLocalEventCreated = (callback) => createEventEventSubscriber('local.event.created', callback);
48187
-
48188
- /**
48189
- * ```js
48190
- * import { EventRepository } from '@amityco/ts-sdk'
48191
- * const dispose = EventRepository.onLocalEventUpdated(event => {
48192
- * // ...
48193
- * })
48194
- * ```
48195
- *
48196
- * Fired when a {@link Amity.Event} has been updated
48197
- *
48198
- * @param callback The function to call when the event was fired
48199
- * @returns an {@link Amity.Unsubscriber} function to stop listening
48200
- *
48201
- * @category Event Events
48202
- */
48203
- const onLocalEventUpdated = (callback) => createEventEventSubscriber('local.event.updated', callback);
48204
-
48205
- /**
48206
- * ```js
48207
- * import { EventRepository } from '@amityco/ts-sdk'
48208
- * const dispose = EventRepository.onLocalEventDeleted(event => {
48209
- * // ...
48210
- * })
48211
- * ```
48212
- *
48213
- * Fired when a {@link Amity.Event} has been deleted
48214
- *
48215
- * @param callback The function to call when the event was fired
48216
- * @returns an {@link Amity.Unsubscriber} function to stop listening
48217
- *
48218
- * @category Event Events
48219
- */
48220
- const onLocalEventDeleted = (callback) => createEventEventSubscriber('local.event.deleted', callback);
48221
-
48222
49000
  /* begin_public_function
48223
49001
  id: event.get
48224
49002
  */
@@ -48248,13 +49026,6 @@ const getEvent = (eventId, callback) => {
48248
49026
  };
48249
49027
  /* end_public_function */
48250
49028
 
48251
- var EventActionsEnum;
48252
- (function (EventActionsEnum) {
48253
- EventActionsEnum["OnEventCreated"] = "onEventCreated";
48254
- EventActionsEnum["OnEventUpdated"] = "onEventUpdated";
48255
- EventActionsEnum["OnEventDeleted"] = "onEventDeleted";
48256
- })(EventActionsEnum || (EventActionsEnum = {}));
48257
-
48258
49029
  class EventPaginationController extends PaginationController {
48259
49030
  async getRequest(queryParams, token) {
48260
49031
  const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
@@ -48537,9 +49308,14 @@ var index = /*#__PURE__*/Object.freeze({
48537
49308
  onLocalEventCreated: onLocalEventCreated,
48538
49309
  onLocalEventUpdated: onLocalEventUpdated,
48539
49310
  onLocalEventDeleted: onLocalEventDeleted,
49311
+ onRSVPCreated: onRSVPCreated,
49312
+ onRSVPUpdated: onRSVPUpdated,
49313
+ onLocalRSVPCreated: onLocalRSVPCreated,
49314
+ onLocalRSVPUpdated: onLocalRSVPUpdated,
48540
49315
  getEvent: getEvent,
48541
49316
  getEvents: getEvents,
48542
- getMyEvents: getMyEvents
49317
+ getMyEvents: getMyEvents,
49318
+ getRSVPs: getRSVPs
48543
49319
  });
48544
49320
 
48545
- 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 };
49321
+ export { API_REGIONS, index$4 as AdRepository, AmityCommunityType, AmityEventOrderOption, AmityEventOriginType, AmityEventResponseStatus, AmityEventSortOption, 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$a as PostRepository, PostStructureType, index$n as ReactionRepository, index$8 as RoomPresenceRepository, index$b as RoomRepository, index$5 as StoryRepository, index$9 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 };