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