@amityco/ts-sdk 7.11.1-fec87c5.0 → 7.12.1-501d118.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 (50) hide show
  1. package/dist/@types/core/events.d.ts +5 -4
  2. package/dist/@types/core/events.d.ts.map +1 -1
  3. package/dist/@types/core/linkPreviewMetadata.d.ts +12 -0
  4. package/dist/@types/core/linkPreviewMetadata.d.ts.map +1 -0
  5. package/dist/@types/domains/community.d.ts +2 -7
  6. package/dist/@types/domains/community.d.ts.map +1 -1
  7. package/dist/@types/domains/post.d.ts +10 -0
  8. package/dist/@types/domains/post.d.ts.map +1 -1
  9. package/dist/@types/domains/room.d.ts +12 -2
  10. package/dist/@types/domains/room.d.ts.map +1 -1
  11. package/dist/client/api/fetchLinkPreview.d.ts +3 -0
  12. package/dist/client/api/fetchLinkPreview.d.ts.map +1 -1
  13. package/dist/client/api/getLinkPreviewMetadata.d.ts +14 -0
  14. package/dist/client/api/getLinkPreviewMetadata.d.ts.map +1 -0
  15. package/dist/client/api/index.d.ts +1 -0
  16. package/dist/client/api/index.d.ts.map +1 -1
  17. package/dist/core/events.d.ts +3 -3
  18. package/dist/core/events.d.ts.map +1 -1
  19. package/dist/eventRepository/internalApi/getEvent.d.ts.map +1 -1
  20. package/dist/index.cjs.js +631 -475
  21. package/dist/index.esm.js +487 -331
  22. package/dist/index.umd.js +3 -3
  23. package/dist/liveReactionRepository/api/createReaction.d.ts +7 -2
  24. package/dist/liveReactionRepository/api/createReaction.d.ts.map +1 -1
  25. package/dist/liveReactionRepository/internalApi/createLiveReaction.d.ts +3 -2
  26. package/dist/liveReactionRepository/internalApi/createLiveReaction.d.ts.map +1 -1
  27. package/dist/liveReactionRepository/service/ReactionSyncEngine.d.ts +2 -1
  28. package/dist/liveReactionRepository/service/ReactionSyncEngine.d.ts.map +1 -1
  29. package/dist/postRepository/api/createPost.d.ts +1 -0
  30. package/dist/postRepository/api/createPost.d.ts.map +1 -1
  31. package/dist/postRepository/api/editPost.d.ts +1 -0
  32. package/dist/postRepository/api/editPost.d.ts.map +1 -1
  33. package/dist/roomRepository/events/index.d.ts +2 -0
  34. package/dist/roomRepository/events/index.d.ts.map +1 -1
  35. package/dist/roomRepository/events/onRoomParticipantJoined.d.ts +1 -1
  36. package/dist/roomRepository/events/onRoomParticipantJoined.d.ts.map +1 -1
  37. package/dist/roomRepository/events/onRoomParticipantLeft.d.ts +1 -1
  38. package/dist/roomRepository/events/onRoomParticipantLeft.d.ts.map +1 -1
  39. package/dist/roomRepository/events/onRoomParticipantRemoved.d.ts +1 -1
  40. package/dist/roomRepository/events/onRoomParticipantRemoved.d.ts.map +1 -1
  41. package/dist/roomRepository/events/onRoomParticipantStageJoined.d.ts +17 -0
  42. package/dist/roomRepository/events/onRoomParticipantStageJoined.d.ts.map +1 -0
  43. package/dist/roomRepository/events/onRoomParticipantStageLeft.d.ts +17 -0
  44. package/dist/roomRepository/events/onRoomParticipantStageLeft.d.ts.map +1 -0
  45. package/dist/roomRepository/observers/getRoom.d.ts.map +1 -1
  46. package/dist/roomRepository/observers/getRooms/RoomLiveCollectionController.d.ts.map +1 -1
  47. package/dist/roomRepository/observers/utils.d.ts +1 -0
  48. package/dist/roomRepository/observers/utils.d.ts.map +1 -1
  49. package/dist/utils/linkedObject/roomLinkedObject.d.ts.map +1 -1
  50. package/package.json +1 -1
package/dist/index.cjs.js CHANGED
@@ -239,8 +239,8 @@ exports.AmityEventOrderOption = void 0;
239
239
 
240
240
  function getVersion() {
241
241
  try {
242
- // the string ''v7.11.0-cjs'' should be replaced by actual value by @rollup/plugin-replace
243
- return 'v7.11.0-cjs';
242
+ // the string ''v7.12.0-cjs'' should be replaced by actual value by @rollup/plugin-replace
243
+ return 'v7.12.0-cjs';
244
244
  }
245
245
  catch (error) {
246
246
  return '__dev__';
@@ -8530,12 +8530,13 @@ var objectResolverEngineOnLoginHandler = () => {
8530
8530
  * @category Live Reaction API
8531
8531
  * @async
8532
8532
  */
8533
- const createLiveReaction = async ({ reactions, liveStreamId, }) => {
8533
+ const createLiveReaction = async ({ reactions, liveStreamId, roomId, }) => {
8534
8534
  const client = getActiveClient();
8535
8535
  client.log('live_reaction/addReaction', reactions);
8536
8536
  const { data } = await client.http.post(`/api/v1/reactions/live`, {
8537
8537
  liveStreamId,
8538
8538
  reactions,
8539
+ roomId,
8539
8540
  });
8540
8541
  return data;
8541
8542
  };
@@ -8592,19 +8593,23 @@ class LiveReactionSyncEngine {
8592
8593
  // Clear buffer
8593
8594
  this.clearBuffer();
8594
8595
  const payloads = reactions.reduce((prev, curr) => {
8595
- const { roomId } = curr, rest = __rest(curr, ["roomId"]);
8596
- if (!prev[roomId]) {
8596
+ const { roomId, streamId } = curr, rest = __rest(curr, ["roomId", "streamId"]);
8597
+ const referenceType = streamId ? 'liveStream' : 'room';
8598
+ const referenceId = streamId !== null && streamId !== void 0 ? streamId : roomId;
8599
+ if (!prev[referenceId]) {
8597
8600
  // eslint-disable-next-line no-param-reassign
8598
- prev[roomId] = [rest];
8601
+ prev[referenceId] = { referenceType, reactions: [] };
8602
+ prev[referenceId].reactions.push(rest);
8599
8603
  }
8600
8604
  else
8601
- prev[roomId].push(rest);
8605
+ prev[referenceId].reactions.push(rest);
8602
8606
  return prev;
8603
8607
  }, {});
8604
8608
  // Call server api `POST /api/v1/reactions/live` to sync live reactions
8605
- Object.entries(payloads).forEach(([roomId, reactions]) => {
8609
+ Object.entries(payloads).forEach(([referenceId, reactionPayload]) => {
8610
+ const referenceIdName = reactionPayload.referenceType === 'room' ? 'roomId' : 'liveStreamId';
8606
8611
  createLiveReaction({
8607
- liveStreamId: roomId,
8612
+ [referenceIdName]: referenceId,
8608
8613
  reactions,
8609
8614
  });
8610
8615
  });
@@ -9995,6 +10000,9 @@ function setUploadedFileAccessType(accessType) {
9995
10000
  GlobalFileAccessType$1.getInstance().setFileAccessType(accessType);
9996
10001
  }
9997
10002
 
10003
+ /**
10004
+ * @deprecated This function will to be deprecated and use the new getLinkPreviewMetadata
10005
+ */
9998
10006
  /**
9999
10007
  * ```js
10000
10008
  * import { fetchLinkPreview } from '@amityco/ts-sdk'
@@ -10017,6 +10025,24 @@ const fetchLinkPreview = async (url) => {
10017
10025
  return data;
10018
10026
  };
10019
10027
 
10028
+ /**
10029
+ * ```js
10030
+ * import { getLinkPreviewMetadata } from '@amityco/ts-sdk'
10031
+ * const { title, description, imageUrl } = getLinkPreviewMetadata('https://www.example.com/')
10032
+ * ```
10033
+ *
10034
+ *
10035
+ * @param url the url to fetch link preview
10036
+ * @returns A {@link Amity.LinkPreviewMetadata} instance
10037
+ *
10038
+ * @category Client API
10039
+ * */
10040
+ const getLinkPreviewMetadata = async (url) => {
10041
+ const client = getActiveClient();
10042
+ const { data } = await client.http.get(`/api/v1/link-preview?url=${url}`);
10043
+ return data;
10044
+ };
10045
+
10020
10046
  /**
10021
10047
  * ```js
10022
10048
  * import Client from '@amityco/ts-sdk'
@@ -10546,6 +10572,7 @@ var index$r = /*#__PURE__*/Object.freeze({
10546
10572
  enableUnreadCount: enableUnreadCount,
10547
10573
  setUploadedFileAccessType: setUploadedFileAccessType,
10548
10574
  fetchLinkPreview: fetchLinkPreview,
10575
+ getLinkPreviewMetadata: getLinkPreviewMetadata,
10549
10576
  getSocialSettings: getSocialSettings,
10550
10577
  getShareableLinkConfiguration: getShareableLinkConfiguration,
10551
10578
  loginAsVisitor: loginAsVisitor,
@@ -12446,12 +12473,9 @@ const rejectInvitation = async (invitationId) => {
12446
12473
  };
12447
12474
  /* end_public_function */
12448
12475
 
12449
- var InvitationActionsEnum;
12450
- (function (InvitationActionsEnum) {
12451
- InvitationActionsEnum["OnLocalInvitationCreated"] = "onLocalInvitationCreated";
12452
- InvitationActionsEnum["OnLocalInvitationUpdated"] = "onLocalInvitationUpdated";
12453
- InvitationActionsEnum["OnLocalInvitationCanceled"] = "onLocalInvitationCanceled";
12454
- })(InvitationActionsEnum || (InvitationActionsEnum = {}));
12476
+ const prepareMyInvitationsPayload = (rawPayload) => {
12477
+ return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser), invitations: rawPayload.invitations.map(convertRawInvitationToInternalInvitation) });
12478
+ };
12455
12479
 
12456
12480
  const invitationLinkedObject = (invitation) => {
12457
12481
  return Object.assign(Object.assign({}, invitation), { get user() {
@@ -12485,390 +12509,122 @@ const invitationLinkedObject = (invitation) => {
12485
12509
  } });
12486
12510
  };
12487
12511
 
12488
- class InvitationsPaginationController extends PaginationController {
12489
- async getRequest(queryParams, token) {
12490
- const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
12491
- const options = token ? { token } : { limit };
12492
- const { data } = await this.http.get('/api/v1/invitations', { params: Object.assign(Object.assign({}, params), { options }) });
12493
- return data;
12494
- }
12495
- }
12496
-
12497
- class InvitationsQueryStreamController extends QueryStreamController {
12498
- constructor(query, cacheKey, notifyChange, preparePayload) {
12499
- super(query, cacheKey);
12500
- this.notifyChange = notifyChange;
12501
- this.preparePayload = preparePayload;
12502
- }
12503
- async saveToMainDB(response) {
12504
- const processedPayload = await this.preparePayload(response);
12505
- const client = getActiveClient();
12506
- const cachedAt = client.cache && Date.now();
12507
- if (client.cache) {
12508
- ingestInCache(processedPayload, { cachedAt });
12509
- }
12510
- }
12511
- appendToQueryStream(response, direction, refresh = false) {
12512
- var _a, _b;
12513
- if (refresh) {
12514
- pushToCache(this.cacheKey, {
12515
- data: response.invitations.map(getResolver('invitation')),
12516
- });
12517
- }
12518
- else {
12519
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
12520
- const invitations = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
12521
- pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
12522
- ...new Set([...invitations, ...response.invitations.map(getResolver('invitation'))]),
12523
- ] }));
12524
- }
12525
- }
12526
- reactor(action) {
12527
- return (invitations) => {
12528
- var _a;
12529
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
12530
- if (!collection)
12531
- return;
12532
- if (action === InvitationActionsEnum.OnLocalInvitationUpdated) {
12533
- const isExist = collection.data.find(id => id === invitations[0].invitationId);
12534
- if (!isExist)
12535
- return;
12536
- }
12537
- if (action === InvitationActionsEnum.OnLocalInvitationCreated) {
12538
- collection.data = [
12539
- ...new Set([
12540
- ...invitations.map(invitation => invitation.invitationId),
12541
- ...collection.data,
12542
- ]),
12543
- ];
12544
- }
12545
- if (action === InvitationActionsEnum.OnLocalInvitationDeleted) {
12546
- collection.data = collection.data.filter(id => id !== invitations[0].invitationId);
12547
- }
12548
- pushToCache(this.cacheKey, collection);
12549
- this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
12550
- };
12551
- }
12552
- subscribeRTE(createSubscriber) {
12553
- return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
12554
- }
12555
- }
12556
-
12512
+ /* begin_public_function
12513
+ id: invitation.get
12514
+ */
12557
12515
  /**
12558
12516
  * ```js
12559
- * import { onLocalInvitationCreated } from '@amityco/ts-sdk'
12560
- * const dispose = onLocalInvitationCreated(data => {
12561
- * // ...
12562
- * })
12517
+ * import { getInvitation } from '@amityco/ts-sdk'
12518
+ * const { invitation } = await getInvitation(targetType, targetId)
12563
12519
  * ```
12564
12520
  *
12565
- * Fired when an {@link Amity.InvitationPayload} has been created
12521
+ * Get a {@link Amity.Invitation} object
12566
12522
  *
12567
- * @param callback The function to call when the event was fired
12568
- * @returns an {@link Amity.Unsubscriber} function to stop listening
12523
+ * @param targetType The type of the target of the {@link Amity.Invitation}
12524
+ * @param targetId The ID of the target of the {@link Amity.Invitation}
12525
+ * @returns A {@link Amity.Invitation} object
12569
12526
  *
12570
- * @category Invitation Events
12527
+ * @category Invitation API
12528
+ * @async
12571
12529
  */
12572
- const onLocalInvitationCreated = (callback) => {
12530
+ const getInvitation = async (params) => {
12573
12531
  const client = getActiveClient();
12574
- const disposers = [
12575
- createEventSubscriber(client, 'onLocalInvitationCreated', 'local.invitation.created', payload => callback(payload)),
12576
- ];
12577
- return () => {
12578
- disposers.forEach(fn => fn());
12532
+ client.log('invitation/getInvitation', params.targetType, params.targetId, params.type);
12533
+ const { data: payload } = await client.http.get(`/api/v1/invitations/me`, { params });
12534
+ const data = prepareMyInvitationsPayload(payload);
12535
+ const cachedAt = client.cache && Date.now();
12536
+ if (client.cache)
12537
+ ingestInCache(data, { cachedAt });
12538
+ return {
12539
+ data: data.invitations[0] ? invitationLinkedObject(data.invitations[0]) : undefined,
12540
+ cachedAt,
12579
12541
  };
12580
12542
  };
12543
+ /* end_public_function */
12581
12544
 
12582
- /**
12583
- * ```js
12584
- * import { onLocalInvitationUpdated } from '@amityco/ts-sdk'
12585
- * const dispose = onLocalInvitationUpdated(data => {
12586
- * // ...
12587
- * })
12588
- * ```
12589
- *
12590
- * Fired when an {@link Amity.InvitationPayload} has been updated
12591
- *
12592
- * @param callback The function to call when the event was fired
12593
- * @returns an {@link Amity.Unsubscriber} function to stop listening
12594
- *
12595
- * @category Invitation Events
12596
- */
12597
- const onLocalInvitationUpdated = (callback) => {
12598
- const client = getActiveClient();
12599
- const disposers = [
12600
- createEventSubscriber(client, 'onLocalInvitationUpdated', 'local.invitation.updated', payload => callback(payload)),
12601
- ];
12602
- return () => {
12603
- disposers.forEach(fn => fn());
12604
- };
12545
+ const roomLinkedObject = (room) => {
12546
+ return Object.assign(Object.assign({}, room), { get post() {
12547
+ var _a;
12548
+ if (room.referenceType !== 'post')
12549
+ return;
12550
+ return (_a = pullFromCache(['post', 'get', room.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
12551
+ },
12552
+ get community() {
12553
+ var _a;
12554
+ if (room.targetType !== 'community')
12555
+ return;
12556
+ return (_a = pullFromCache(['community', 'get', room.targetId])) === null || _a === void 0 ? void 0 : _a.data;
12557
+ },
12558
+ get user() {
12559
+ var _a;
12560
+ const user = (_a = pullFromCache(['user', 'get', room.createdBy])) === null || _a === void 0 ? void 0 : _a.data;
12561
+ return user ? userLinkedObject(user) : user;
12562
+ },
12563
+ get childRooms() {
12564
+ if (!room.childRoomIds || room.childRoomIds.length === 0)
12565
+ return [];
12566
+ return room.childRoomIds
12567
+ .map(id => {
12568
+ var _a;
12569
+ const roomCache = (_a = pullFromCache(['room', 'get', id])) === null || _a === void 0 ? void 0 : _a.data;
12570
+ if (!roomCache)
12571
+ return undefined;
12572
+ return roomLinkedObject(roomCache);
12573
+ })
12574
+ .filter(isNonNullable);
12575
+ }, participants: room.participants.map(participant => (Object.assign(Object.assign({}, participant), { get user() {
12576
+ var _a;
12577
+ const user = (_a = pullFromCache(['user', 'get', participant.userId])) === null || _a === void 0 ? void 0 : _a.data;
12578
+ return user ? userLinkedObject(user) : user;
12579
+ } }))), getLiveChat: () => getLiveChat(room), createInvitation: (userId) => createInvitations({
12580
+ type: "livestreamCohostInvite" /* InvitationTypeEnum.LivestreamCohostInvite */,
12581
+ targetType: 'room',
12582
+ targetId: room.roomId,
12583
+ userIds: [userId],
12584
+ }), getInvitations: async () => {
12585
+ const { data } = await getInvitation({
12586
+ targetId: room.roomId,
12587
+ targetType: 'room',
12588
+ type: "livestreamCohostInvite" /* InvitationTypeEnum.LivestreamCohostInvite */,
12589
+ });
12590
+ return data;
12591
+ } });
12605
12592
  };
12606
12593
 
12607
- /**
12608
- * ```js
12609
- * import { onLocalInvitationCanceled } from '@amityco/ts-sdk'
12610
- * const dispose = onLocalInvitationCanceled(data => {
12611
- * // ...
12612
- * })
12613
- * ```
12614
- *
12615
- * Fired when an {@link Amity.InvitationPayload} has been deleted
12616
- *
12617
- * @param callback The function to call when the event was fired
12618
- * @returns an {@link Amity.Unsubscriber} function to stop listening
12594
+ /*
12595
+ * verifies membership status
12596
+ */
12597
+ function isMember(membership) {
12598
+ return membership !== 'none';
12599
+ }
12600
+ /*
12601
+ * checks if currently logged in user is part of the community
12602
+ */
12603
+ function isCurrentUserPartOfCommunity(c, m) {
12604
+ const { userId } = getActiveUser();
12605
+ return c.communityId === m.communityId && m.userId === userId;
12606
+ }
12607
+ /*
12608
+ * For mqtt events server will not send user specific data as it's broadcasted
12609
+ * to multiple users and it also does not include communityUser
12619
12610
  *
12620
- * @category Invitation Events
12611
+ * Client SDK needs to check for the existing isJoined field in cache data before calculating.
12612
+ * Althought this can be calculated, it's not scalable.
12621
12613
  */
12622
- const onLocalInvitationCanceled = (callback) => {
12623
- const client = getActiveClient();
12624
- const disposers = [
12625
- createEventSubscriber(client, 'onLocalInvitationCanceled', 'local.invitation.canceled', payload => callback(payload)),
12626
- ];
12627
- return () => {
12628
- disposers.forEach(fn => fn());
12629
- };
12630
- };
12631
-
12632
- class InvitationsLiveCollectionController extends LiveCollectionController {
12633
- constructor(query, callback) {
12634
- const queryStreamId = hash__default["default"](query);
12635
- const cacheKey = ['invitation', 'collection', queryStreamId];
12636
- const paginationController = new InvitationsPaginationController(query);
12637
- super(paginationController, queryStreamId, cacheKey, callback);
12638
- this.query = query;
12639
- this.queryStreamController = new InvitationsQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareInvitationPayload);
12640
- this.callback = callback.bind(this);
12641
- this.loadPage({ initial: true });
12642
- }
12643
- setup() {
12644
- var _a;
12645
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
12646
- if (!collection) {
12647
- pushToCache(this.cacheKey, {
12648
- data: [],
12649
- params: this.query,
12650
- });
12651
- }
12652
- }
12653
- async persistModel(queryPayload) {
12654
- await this.queryStreamController.saveToMainDB(queryPayload);
12655
- }
12656
- persistQueryStream({ response, direction, refresh, }) {
12657
- this.queryStreamController.appendToQueryStream(response, direction, refresh);
12658
- }
12659
- startSubscription() {
12660
- return this.queryStreamController.subscribeRTE([
12661
- {
12662
- fn: onLocalInvitationCreated,
12663
- action: InvitationActionsEnum.OnLocalInvitationCreated,
12664
- },
12665
- {
12666
- fn: onLocalInvitationUpdated,
12667
- action: InvitationActionsEnum.OnLocalInvitationUpdated,
12668
- },
12669
- {
12670
- fn: onLocalInvitationCanceled,
12671
- action: InvitationActionsEnum.OnLocalInvitationCanceled,
12672
- },
12673
- ]);
12674
- }
12675
- notifyChange({ origin, loading, error }) {
12676
- var _a, _b;
12677
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
12678
- if (!collection)
12679
- return;
12680
- const data = this.applyFilter((_b = collection.data
12681
- .map(id => pullFromCache(['invitation', 'get', id]))
12682
- .filter(isNonNullable)
12683
- .map(({ data }) => invitationLinkedObject(data))) !== null && _b !== void 0 ? _b : []);
12684
- if (!this.shouldNotify(data) && origin === 'event')
12685
- return;
12686
- this.callback({
12687
- onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
12688
- data,
12689
- hasNextPage: !!this.paginationController.getNextToken(),
12690
- loading,
12691
- error,
12692
- });
12693
- }
12694
- applyFilter(data) {
12695
- let invitations = data;
12696
- if (this.query.targetId) {
12697
- invitations = invitations.filter(invitation => invitation.targetId === this.query.targetId);
12698
- }
12699
- if (this.query.statuses) {
12700
- invitations = invitations.filter(invitation => { var _a; return (_a = this.query.statuses) === null || _a === void 0 ? void 0 : _a.includes(invitation.status); });
12701
- }
12702
- if (this.query.targetType) {
12703
- invitations = invitations.filter(invitation => invitation.targetType === this.query.targetType);
12704
- }
12705
- if (this.query.type) {
12706
- invitations = invitations.filter(invitation => invitation.type === this.query.type);
12707
- }
12708
- const sortFn = (() => {
12709
- switch (this.query.sortBy) {
12710
- case 'firstCreated':
12711
- return sortByFirstCreated;
12712
- case 'lastCreated':
12713
- return sortByLastCreated;
12714
- default:
12715
- return sortByLastCreated;
12716
- }
12717
- })();
12718
- invitations = invitations.sort(sortFn);
12719
- return invitations;
12720
- }
12721
- }
12722
-
12723
- /**
12724
- * Get invitations
12725
- *
12726
- * @param params the query parameters
12727
- * @param callback the callback to be called when the invitations are updated
12728
- * @returns invitations
12729
- *
12730
- * @category Invitation Live Collection
12731
- *
12732
- */
12733
- const getInvitations$1 = (params, callback, config) => {
12734
- const { log, cache } = getActiveClient();
12735
- if (!cache) {
12736
- console.log(ENABLE_CACHE_MESSAGE);
12737
- }
12738
- const timestamp = Date.now();
12739
- log(`getInvitations: (tmpid: ${timestamp}) > listen`);
12740
- const invitationsLiveCollection = new InvitationsLiveCollectionController(params, callback);
12741
- const disposers = invitationsLiveCollection.startSubscription();
12742
- const cacheKey = invitationsLiveCollection.getCacheKey();
12743
- disposers.push(() => {
12744
- dropFromCache(cacheKey);
12745
- });
12746
- return () => {
12747
- log(`getInvitations (tmpid: ${timestamp}) > dispose`);
12748
- disposers.forEach(fn => fn());
12749
- };
12750
- };
12751
-
12752
- const prepareMyInvitationsPayload = (rawPayload) => {
12753
- return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser), invitations: rawPayload.invitations.map(convertRawInvitationToInternalInvitation) });
12754
- };
12755
-
12756
- /* begin_public_function
12757
- id: invitation.get
12758
- */
12759
- /**
12760
- * ```js
12761
- * import { getInvitation } from '@amityco/ts-sdk'
12762
- * const { invitation } = await getInvitation(targetType, targetId)
12763
- * ```
12764
- *
12765
- * Get a {@link Amity.Invitation} object
12766
- *
12767
- * @param targetType The type of the target of the {@link Amity.Invitation}
12768
- * @param targetId The ID of the target of the {@link Amity.Invitation}
12769
- * @returns A {@link Amity.Invitation} object
12770
- *
12771
- * @category Invitation API
12772
- * @async
12773
- */
12774
- const getInvitation = async (params) => {
12775
- const client = getActiveClient();
12776
- client.log('invitation/getInvitation', params.targetType, params.targetId, params.type);
12777
- const { data: payload } = await client.http.get(`/api/v1/invitations/me`, { params });
12778
- const data = prepareMyInvitationsPayload(payload);
12779
- const cachedAt = client.cache && Date.now();
12780
- if (client.cache)
12781
- ingestInCache(data, { cachedAt });
12782
- return {
12783
- data: data.invitations[0] ? invitationLinkedObject(data.invitations[0]) : undefined,
12784
- cachedAt,
12785
- };
12786
- };
12787
- /* end_public_function */
12788
-
12789
- const roomLinkedObject = (room) => {
12790
- return Object.assign(Object.assign({}, room), { get post() {
12791
- var _a;
12792
- if (room.referenceType !== 'post')
12793
- return;
12794
- return (_a = pullFromCache(['post', 'get', room.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
12795
- },
12796
- get community() {
12797
- var _a;
12798
- if (room.targetType !== 'community')
12799
- return;
12800
- return (_a = pullFromCache(['community', 'get', room.targetId])) === null || _a === void 0 ? void 0 : _a.data;
12801
- },
12802
- get user() {
12803
- var _a;
12804
- const user = (_a = pullFromCache(['user', 'get', room.createdBy])) === null || _a === void 0 ? void 0 : _a.data;
12805
- return user ? userLinkedObject(user) : user;
12806
- },
12807
- get childRooms() {
12808
- if (!room.childRoomIds || room.childRoomIds.length === 0)
12809
- return [];
12810
- return room.childRoomIds
12811
- .map(id => {
12812
- var _a;
12813
- const roomCache = (_a = pullFromCache(['room', 'get', id])) === null || _a === void 0 ? void 0 : _a.data;
12814
- if (!roomCache)
12815
- return undefined;
12816
- return roomLinkedObject(roomCache);
12817
- })
12818
- .filter(isNonNullable);
12819
- }, participants: room.participants.map(participant => (Object.assign(Object.assign({}, participant), { get user() {
12820
- var _a;
12821
- const user = (_a = pullFromCache(['user', 'get', participant.userId])) === null || _a === void 0 ? void 0 : _a.data;
12822
- return user ? userLinkedObject(user) : user;
12823
- } }))), getLiveChat: () => getLiveChat(room), createInvitation: (userId) => createInvitations({
12824
- type: "livestreamCohostInvite" /* InvitationTypeEnum.LivestreamCohostInvite */,
12825
- targetType: 'room',
12826
- targetId: room.roomId,
12827
- userIds: [userId],
12828
- }), getInvitations: (params, callback) => getInvitations$1(Object.assign(Object.assign({}, params), { targetId: room.roomId, targetType: 'room', type: "livestreamCohostInvite" /* InvitationTypeEnum.LivestreamCohostInvite */ }), callback), getMyInvitation: async () => {
12829
- const { data } = await getInvitation({
12830
- targetId: room.roomId,
12831
- targetType: 'room',
12832
- type: "livestreamCohostInvite" /* InvitationTypeEnum.LivestreamCohostInvite */,
12833
- });
12834
- return data;
12835
- } });
12836
- };
12837
-
12838
- /*
12839
- * verifies membership status
12840
- */
12841
- function isMember(membership) {
12842
- return membership !== 'none';
12843
- }
12844
- /*
12845
- * checks if currently logged in user is part of the community
12846
- */
12847
- function isCurrentUserPartOfCommunity(c, m) {
12848
- const { userId } = getActiveUser();
12849
- return c.communityId === m.communityId && m.userId === userId;
12850
- }
12851
- /*
12852
- * For mqtt events server will not send user specific data as it's broadcasted
12853
- * to multiple users and it also does not include communityUser
12854
- *
12855
- * Client SDK needs to check for the existing isJoined field in cache data before calculating.
12856
- * Althought this can be calculated, it's not scalable.
12857
- */
12858
- function updateMembershipStatus(communities, communityUsers) {
12859
- return communities.map(c => {
12860
- const cachedCommunity = pullFromCache([
12861
- 'community',
12862
- 'get',
12863
- c.communityId,
12864
- ]);
12865
- if ((cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data) && (cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data.hasOwnProperty('isJoined'))) {
12866
- return Object.assign(Object.assign({}, cachedCommunity.data), c);
12867
- }
12868
- const isJoined = communityUsers.some(m => isCurrentUserPartOfCommunity(c, m) && isMember(m.communityMembership));
12869
- return Object.assign(Object.assign({}, c), { isJoined });
12870
- });
12871
- }
12614
+ function updateMembershipStatus(communities, communityUsers) {
12615
+ return communities.map(c => {
12616
+ const cachedCommunity = pullFromCache([
12617
+ 'community',
12618
+ 'get',
12619
+ c.communityId,
12620
+ ]);
12621
+ if ((cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data) && (cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data.hasOwnProperty('isJoined'))) {
12622
+ return Object.assign(Object.assign({}, cachedCommunity.data), c);
12623
+ }
12624
+ const isJoined = communityUsers.some(m => isCurrentUserPartOfCommunity(c, m) && isMember(m.communityMembership));
12625
+ return Object.assign(Object.assign({}, c), { isJoined });
12626
+ });
12627
+ }
12872
12628
 
12873
12629
  const getMatchPostSetting = (value) => {
12874
12630
  var _a;
@@ -13234,12 +12990,267 @@ class JoinRequestsQueryStreamController extends QueryStreamController {
13234
12990
  * @param callback The function to call when the event was fired
13235
12991
  * @returns an {@link Amity.Unsubscriber} function to stop listening
13236
12992
  *
13237
- * @category JoinRequest Events
12993
+ * @category JoinRequest Events
12994
+ */
12995
+ const onJoinRequestCreated = (callback) => {
12996
+ const client = getActiveClient();
12997
+ const disposers = [
12998
+ createEventSubscriber(client, 'onJoinRequestCreated', 'local.joinRequest.created', payload => callback(payload)),
12999
+ ];
13000
+ return () => {
13001
+ disposers.forEach(fn => fn());
13002
+ };
13003
+ };
13004
+
13005
+ /**
13006
+ * ```js
13007
+ * import { onJoinRequestUpdated } from '@amityco/ts-sdk'
13008
+ * const dispose = onJoinRequestUpdated(data => {
13009
+ * // ...
13010
+ * })
13011
+ * ```
13012
+ *
13013
+ * Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
13014
+ *
13015
+ * @param callback The function to call when the event was fired
13016
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
13017
+ *
13018
+ * @category JoinRequest Events
13019
+ */
13020
+ const onJoinRequestUpdated = (callback) => {
13021
+ const client = getActiveClient();
13022
+ const disposers = [
13023
+ createEventSubscriber(client, 'onJoinRequestUpdated', 'local.joinRequest.updated', payload => callback(payload)),
13024
+ ];
13025
+ return () => {
13026
+ disposers.forEach(fn => fn());
13027
+ };
13028
+ };
13029
+
13030
+ /**
13031
+ * ```js
13032
+ * import { onJoinRequestDeleted } from '@amityco/ts-sdk'
13033
+ * const dispose = onJoinRequestDeleted(data => {
13034
+ * // ...
13035
+ * })
13036
+ * ```
13037
+ *
13038
+ * Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
13039
+ *
13040
+ * @param callback The function to call when the event was fired
13041
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
13042
+ *
13043
+ * @category JoinRequest Events
13044
+ */
13045
+ const onJoinRequestDeleted = (callback) => {
13046
+ const client = getActiveClient();
13047
+ const disposers = [
13048
+ createEventSubscriber(client, 'onJoinRequestDeleted', 'local.joinRequest.deleted', payload => callback(payload)),
13049
+ ];
13050
+ return () => {
13051
+ disposers.forEach(fn => fn());
13052
+ };
13053
+ };
13054
+
13055
+ class JoinRequestsLiveCollectionController extends LiveCollectionController {
13056
+ constructor(query, callback) {
13057
+ const queryStreamId = hash__default["default"](query);
13058
+ const cacheKey = ['joinRequest', 'collection', queryStreamId];
13059
+ const paginationController = new JoinRequestsPaginationController(query);
13060
+ super(paginationController, queryStreamId, cacheKey, callback);
13061
+ this.query = query;
13062
+ this.queryStreamController = new JoinRequestsQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityJoinRequestPayload);
13063
+ this.callback = callback.bind(this);
13064
+ this.loadPage({ initial: true });
13065
+ }
13066
+ setup() {
13067
+ var _a;
13068
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
13069
+ if (!collection) {
13070
+ pushToCache(this.cacheKey, {
13071
+ data: [],
13072
+ params: this.query,
13073
+ });
13074
+ }
13075
+ }
13076
+ async persistModel(queryPayload) {
13077
+ await this.queryStreamController.saveToMainDB(queryPayload);
13078
+ }
13079
+ persistQueryStream({ response, direction, refresh, }) {
13080
+ const joinRequestResponse = response;
13081
+ this.queryStreamController.appendToQueryStream(joinRequestResponse, direction, refresh);
13082
+ }
13083
+ startSubscription() {
13084
+ return this.queryStreamController.subscribeRTE([
13085
+ { fn: onJoinRequestCreated, action: EnumJoinRequestAction$1.OnLocalJoinRequestCreated },
13086
+ { fn: onJoinRequestUpdated, action: EnumJoinRequestAction$1.OnLocalJoinRequestUpdated },
13087
+ { fn: onJoinRequestDeleted, action: EnumJoinRequestAction$1.OnLocalJoinRequestDeleted },
13088
+ ]);
13089
+ }
13090
+ notifyChange({ origin, loading, error }) {
13091
+ var _a;
13092
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
13093
+ if (!collection)
13094
+ return;
13095
+ const data = this.applyFilter(collection.data
13096
+ .map(id => pullFromCache(['joinRequest', 'get', id]))
13097
+ .filter(isNonNullable)
13098
+ .map(({ data }) => data)
13099
+ .map(joinRequestLinkedObject));
13100
+ if (!this.shouldNotify(data) && origin === 'event')
13101
+ return;
13102
+ this.callback({
13103
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
13104
+ data,
13105
+ hasNextPage: !!this.paginationController.getNextToken(),
13106
+ loading,
13107
+ error,
13108
+ });
13109
+ }
13110
+ applyFilter(data) {
13111
+ let joinRequest = data;
13112
+ if (this.query.status) {
13113
+ joinRequest = joinRequest.filter(joinRequest => joinRequest.status === this.query.status);
13114
+ }
13115
+ const sortFn = (() => {
13116
+ switch (this.query.sortBy) {
13117
+ case 'firstCreated':
13118
+ return sortByFirstCreated;
13119
+ case 'lastCreated':
13120
+ return sortByLastCreated;
13121
+ default:
13122
+ return sortByLastCreated;
13123
+ }
13124
+ })();
13125
+ joinRequest = joinRequest.sort(sortFn);
13126
+ return joinRequest;
13127
+ }
13128
+ }
13129
+
13130
+ /**
13131
+ * Get Join Requests
13132
+ *
13133
+ * @param params the query parameters
13134
+ * @param callback the callback to be called when the join request are updated
13135
+ * @returns joinRequests
13136
+ *
13137
+ * @category joinRequest Live Collection
13138
+ *
13139
+ */
13140
+ const getJoinRequests = (params, callback, config) => {
13141
+ const { log, cache } = getActiveClient();
13142
+ if (!cache) {
13143
+ console.log(ENABLE_CACHE_MESSAGE);
13144
+ }
13145
+ const timestamp = Date.now();
13146
+ log(`getJoinRequests: (tmpid: ${timestamp}) > listen`);
13147
+ const joinRequestLiveCollection = new JoinRequestsLiveCollectionController(params, callback);
13148
+ const disposers = joinRequestLiveCollection.startSubscription();
13149
+ const cacheKey = joinRequestLiveCollection.getCacheKey();
13150
+ disposers.push(() => {
13151
+ dropFromCache(cacheKey);
13152
+ });
13153
+ return () => {
13154
+ log(`getJoinRequests (tmpid: ${timestamp}) > dispose`);
13155
+ disposers.forEach(fn => fn());
13156
+ };
13157
+ };
13158
+
13159
+ var InvitationActionsEnum;
13160
+ (function (InvitationActionsEnum) {
13161
+ InvitationActionsEnum["OnLocalInvitationCreated"] = "onLocalInvitationCreated";
13162
+ InvitationActionsEnum["OnLocalInvitationUpdated"] = "onLocalInvitationUpdated";
13163
+ InvitationActionsEnum["OnLocalInvitationCanceled"] = "onLocalInvitationCanceled";
13164
+ })(InvitationActionsEnum || (InvitationActionsEnum = {}));
13165
+
13166
+ class InvitationsPaginationController extends PaginationController {
13167
+ async getRequest(queryParams, token) {
13168
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
13169
+ const options = token ? { token } : { limit };
13170
+ const { data } = await this.http.get('/api/v1/invitations', { params: Object.assign(Object.assign({}, params), { options }) });
13171
+ return data;
13172
+ }
13173
+ }
13174
+
13175
+ class InvitationsQueryStreamController extends QueryStreamController {
13176
+ constructor(query, cacheKey, notifyChange, preparePayload) {
13177
+ super(query, cacheKey);
13178
+ this.notifyChange = notifyChange;
13179
+ this.preparePayload = preparePayload;
13180
+ }
13181
+ async saveToMainDB(response) {
13182
+ const processedPayload = await this.preparePayload(response);
13183
+ const client = getActiveClient();
13184
+ const cachedAt = client.cache && Date.now();
13185
+ if (client.cache) {
13186
+ ingestInCache(processedPayload, { cachedAt });
13187
+ }
13188
+ }
13189
+ appendToQueryStream(response, direction, refresh = false) {
13190
+ var _a, _b;
13191
+ if (refresh) {
13192
+ pushToCache(this.cacheKey, {
13193
+ data: response.invitations.map(getResolver('invitation')),
13194
+ });
13195
+ }
13196
+ else {
13197
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
13198
+ const invitations = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
13199
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
13200
+ ...new Set([...invitations, ...response.invitations.map(getResolver('invitation'))]),
13201
+ ] }));
13202
+ }
13203
+ }
13204
+ reactor(action) {
13205
+ return (invitations) => {
13206
+ var _a;
13207
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
13208
+ if (!collection)
13209
+ return;
13210
+ if (action === InvitationActionsEnum.OnLocalInvitationUpdated) {
13211
+ const isExist = collection.data.find(id => id === invitations[0].invitationId);
13212
+ if (!isExist)
13213
+ return;
13214
+ }
13215
+ if (action === InvitationActionsEnum.OnLocalInvitationCreated) {
13216
+ collection.data = [
13217
+ ...new Set([
13218
+ ...invitations.map(invitation => invitation.invitationId),
13219
+ ...collection.data,
13220
+ ]),
13221
+ ];
13222
+ }
13223
+ if (action === InvitationActionsEnum.OnLocalInvitationDeleted) {
13224
+ collection.data = collection.data.filter(id => id !== invitations[0].invitationId);
13225
+ }
13226
+ pushToCache(this.cacheKey, collection);
13227
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
13228
+ };
13229
+ }
13230
+ subscribeRTE(createSubscriber) {
13231
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
13232
+ }
13233
+ }
13234
+
13235
+ /**
13236
+ * ```js
13237
+ * import { onLocalInvitationCreated } from '@amityco/ts-sdk'
13238
+ * const dispose = onLocalInvitationCreated(data => {
13239
+ * // ...
13240
+ * })
13241
+ * ```
13242
+ *
13243
+ * Fired when an {@link Amity.InvitationPayload} has been created
13244
+ *
13245
+ * @param callback The function to call when the event was fired
13246
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
13247
+ *
13248
+ * @category Invitation Events
13238
13249
  */
13239
- const onJoinRequestCreated = (callback) => {
13250
+ const onLocalInvitationCreated = (callback) => {
13240
13251
  const client = getActiveClient();
13241
13252
  const disposers = [
13242
- createEventSubscriber(client, 'onJoinRequestCreated', 'local.joinRequest.created', payload => callback(payload)),
13253
+ createEventSubscriber(client, 'onLocalInvitationCreated', 'local.invitation.created', payload => callback(payload)),
13243
13254
  ];
13244
13255
  return () => {
13245
13256
  disposers.forEach(fn => fn());
@@ -13248,23 +13259,23 @@ const onJoinRequestCreated = (callback) => {
13248
13259
 
13249
13260
  /**
13250
13261
  * ```js
13251
- * import { onJoinRequestUpdated } from '@amityco/ts-sdk'
13252
- * const dispose = onJoinRequestUpdated(data => {
13262
+ * import { onLocalInvitationUpdated } from '@amityco/ts-sdk'
13263
+ * const dispose = onLocalInvitationUpdated(data => {
13253
13264
  * // ...
13254
13265
  * })
13255
13266
  * ```
13256
13267
  *
13257
- * Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
13268
+ * Fired when an {@link Amity.InvitationPayload} has been updated
13258
13269
  *
13259
13270
  * @param callback The function to call when the event was fired
13260
13271
  * @returns an {@link Amity.Unsubscriber} function to stop listening
13261
13272
  *
13262
- * @category JoinRequest Events
13273
+ * @category Invitation Events
13263
13274
  */
13264
- const onJoinRequestUpdated = (callback) => {
13275
+ const onLocalInvitationUpdated = (callback) => {
13265
13276
  const client = getActiveClient();
13266
13277
  const disposers = [
13267
- createEventSubscriber(client, 'onJoinRequestUpdated', 'local.joinRequest.updated', payload => callback(payload)),
13278
+ createEventSubscriber(client, 'onLocalInvitationUpdated', 'local.invitation.updated', payload => callback(payload)),
13268
13279
  ];
13269
13280
  return () => {
13270
13281
  disposers.forEach(fn => fn());
@@ -13273,37 +13284,37 @@ const onJoinRequestUpdated = (callback) => {
13273
13284
 
13274
13285
  /**
13275
13286
  * ```js
13276
- * import { onJoinRequestDeleted } from '@amityco/ts-sdk'
13277
- * const dispose = onJoinRequestDeleted(data => {
13287
+ * import { onLocalInvitationCanceled } from '@amityco/ts-sdk'
13288
+ * const dispose = onLocalInvitationCanceled(data => {
13278
13289
  * // ...
13279
13290
  * })
13280
13291
  * ```
13281
13292
  *
13282
- * Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
13293
+ * Fired when an {@link Amity.InvitationPayload} has been deleted
13283
13294
  *
13284
13295
  * @param callback The function to call when the event was fired
13285
13296
  * @returns an {@link Amity.Unsubscriber} function to stop listening
13286
13297
  *
13287
- * @category JoinRequest Events
13298
+ * @category Invitation Events
13288
13299
  */
13289
- const onJoinRequestDeleted = (callback) => {
13300
+ const onLocalInvitationCanceled = (callback) => {
13290
13301
  const client = getActiveClient();
13291
13302
  const disposers = [
13292
- createEventSubscriber(client, 'onJoinRequestDeleted', 'local.joinRequest.deleted', payload => callback(payload)),
13303
+ createEventSubscriber(client, 'onLocalInvitationCanceled', 'local.invitation.canceled', payload => callback(payload)),
13293
13304
  ];
13294
13305
  return () => {
13295
13306
  disposers.forEach(fn => fn());
13296
13307
  };
13297
13308
  };
13298
13309
 
13299
- class JoinRequestsLiveCollectionController extends LiveCollectionController {
13310
+ class InvitationsLiveCollectionController extends LiveCollectionController {
13300
13311
  constructor(query, callback) {
13301
13312
  const queryStreamId = hash__default["default"](query);
13302
- const cacheKey = ['joinRequest', 'collection', queryStreamId];
13303
- const paginationController = new JoinRequestsPaginationController(query);
13313
+ const cacheKey = ['invitation', 'collection', queryStreamId];
13314
+ const paginationController = new InvitationsPaginationController(query);
13304
13315
  super(paginationController, queryStreamId, cacheKey, callback);
13305
13316
  this.query = query;
13306
- this.queryStreamController = new JoinRequestsQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityJoinRequestPayload);
13317
+ this.queryStreamController = new InvitationsQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareInvitationPayload);
13307
13318
  this.callback = callback.bind(this);
13308
13319
  this.loadPage({ initial: true });
13309
13320
  }
@@ -13321,26 +13332,33 @@ class JoinRequestsLiveCollectionController extends LiveCollectionController {
13321
13332
  await this.queryStreamController.saveToMainDB(queryPayload);
13322
13333
  }
13323
13334
  persistQueryStream({ response, direction, refresh, }) {
13324
- const joinRequestResponse = response;
13325
- this.queryStreamController.appendToQueryStream(joinRequestResponse, direction, refresh);
13335
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
13326
13336
  }
13327
13337
  startSubscription() {
13328
13338
  return this.queryStreamController.subscribeRTE([
13329
- { fn: onJoinRequestCreated, action: EnumJoinRequestAction$1.OnLocalJoinRequestCreated },
13330
- { fn: onJoinRequestUpdated, action: EnumJoinRequestAction$1.OnLocalJoinRequestUpdated },
13331
- { fn: onJoinRequestDeleted, action: EnumJoinRequestAction$1.OnLocalJoinRequestDeleted },
13339
+ {
13340
+ fn: onLocalInvitationCreated,
13341
+ action: InvitationActionsEnum.OnLocalInvitationCreated,
13342
+ },
13343
+ {
13344
+ fn: onLocalInvitationUpdated,
13345
+ action: InvitationActionsEnum.OnLocalInvitationUpdated,
13346
+ },
13347
+ {
13348
+ fn: onLocalInvitationCanceled,
13349
+ action: InvitationActionsEnum.OnLocalInvitationCanceled,
13350
+ },
13332
13351
  ]);
13333
13352
  }
13334
13353
  notifyChange({ origin, loading, error }) {
13335
- var _a;
13354
+ var _a, _b;
13336
13355
  const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
13337
13356
  if (!collection)
13338
13357
  return;
13339
- const data = this.applyFilter(collection.data
13340
- .map(id => pullFromCache(['joinRequest', 'get', id]))
13358
+ const data = this.applyFilter((_b = collection.data
13359
+ .map(id => pullFromCache(['invitation', 'get', id]))
13341
13360
  .filter(isNonNullable)
13342
- .map(({ data }) => data)
13343
- .map(joinRequestLinkedObject));
13361
+ .map(({ data }) => invitationLinkedObject(data))) !== null && _b !== void 0 ? _b : []);
13344
13362
  if (!this.shouldNotify(data) && origin === 'event')
13345
13363
  return;
13346
13364
  this.callback({
@@ -13352,9 +13370,18 @@ class JoinRequestsLiveCollectionController extends LiveCollectionController {
13352
13370
  });
13353
13371
  }
13354
13372
  applyFilter(data) {
13355
- let joinRequest = data;
13356
- if (this.query.status) {
13357
- joinRequest = joinRequest.filter(joinRequest => joinRequest.status === this.query.status);
13373
+ let invitations = data;
13374
+ if (this.query.targetId) {
13375
+ invitations = invitations.filter(invitation => invitation.targetId === this.query.targetId);
13376
+ }
13377
+ if (this.query.statuses) {
13378
+ invitations = invitations.filter(invitation => { var _a; return (_a = this.query.statuses) === null || _a === void 0 ? void 0 : _a.includes(invitation.status); });
13379
+ }
13380
+ if (this.query.targetType) {
13381
+ invitations = invitations.filter(invitation => invitation.targetType === this.query.targetType);
13382
+ }
13383
+ if (this.query.type) {
13384
+ invitations = invitations.filter(invitation => invitation.type === this.query.type);
13358
13385
  }
13359
13386
  const sortFn = (() => {
13360
13387
  switch (this.query.sortBy) {
@@ -13366,36 +13393,36 @@ class JoinRequestsLiveCollectionController extends LiveCollectionController {
13366
13393
  return sortByLastCreated;
13367
13394
  }
13368
13395
  })();
13369
- joinRequest = joinRequest.sort(sortFn);
13370
- return joinRequest;
13396
+ invitations = invitations.sort(sortFn);
13397
+ return invitations;
13371
13398
  }
13372
13399
  }
13373
13400
 
13374
13401
  /**
13375
- * Get Join Requests
13402
+ * Get invitations
13376
13403
  *
13377
13404
  * @param params the query parameters
13378
- * @param callback the callback to be called when the join request are updated
13379
- * @returns joinRequests
13405
+ * @param callback the callback to be called when the invitations are updated
13406
+ * @returns invitations
13380
13407
  *
13381
- * @category joinRequest Live Collection
13408
+ * @category Invitation Live Collection
13382
13409
  *
13383
13410
  */
13384
- const getJoinRequests = (params, callback, config) => {
13411
+ const getInvitations$1 = (params, callback, config) => {
13385
13412
  const { log, cache } = getActiveClient();
13386
13413
  if (!cache) {
13387
13414
  console.log(ENABLE_CACHE_MESSAGE);
13388
13415
  }
13389
13416
  const timestamp = Date.now();
13390
- log(`getJoinRequests: (tmpid: ${timestamp}) > listen`);
13391
- const joinRequestLiveCollection = new JoinRequestsLiveCollectionController(params, callback);
13392
- const disposers = joinRequestLiveCollection.startSubscription();
13393
- const cacheKey = joinRequestLiveCollection.getCacheKey();
13417
+ log(`getInvitations: (tmpid: ${timestamp}) > listen`);
13418
+ const invitationsLiveCollection = new InvitationsLiveCollectionController(params, callback);
13419
+ const disposers = invitationsLiveCollection.startSubscription();
13420
+ const cacheKey = invitationsLiveCollection.getCacheKey();
13394
13421
  disposers.push(() => {
13395
13422
  dropFromCache(cacheKey);
13396
13423
  });
13397
13424
  return () => {
13398
- log(`getJoinRequests (tmpid: ${timestamp}) > dispose`);
13425
+ log(`getInvitations (tmpid: ${timestamp}) > dispose`);
13399
13426
  disposers.forEach(fn => fn());
13400
13427
  };
13401
13428
  };
@@ -28371,8 +28398,12 @@ const onRoomCoHostInviteCanceled = (callback) => {
28371
28398
  const onRoomParticipantJoined = (callback) => {
28372
28399
  const client = getActiveClient();
28373
28400
  const filter = (payload) => {
28374
- ingestInCache(payload);
28375
- callback(payload.rooms[0]);
28401
+ const { rooms, users } = payload;
28402
+ ingestInCache({ rooms, users });
28403
+ callback({
28404
+ room: roomLinkedObject(rooms[0]),
28405
+ actorInternalId: payload.eventActor.userInternalId,
28406
+ });
28376
28407
  };
28377
28408
  return createEventSubscriber(client, 'room/onRoomParticipantJoined', 'room.participantJoined', filter);
28378
28409
  };
@@ -28395,12 +28426,72 @@ const onRoomParticipantJoined = (callback) => {
28395
28426
  const onRoomParticipantLeft = (callback) => {
28396
28427
  const client = getActiveClient();
28397
28428
  const filter = (payload) => {
28398
- ingestInCache(payload);
28399
- callback(payload.rooms[0]);
28429
+ const { rooms, users } = payload;
28430
+ ingestInCache({ rooms, users });
28431
+ callback({
28432
+ room: roomLinkedObject(rooms[0]),
28433
+ actorInternalId: payload.eventActor.userInternalId,
28434
+ });
28400
28435
  };
28401
28436
  return createEventSubscriber(client, 'room/onRoomParticipantLeft', 'room.participantLeft', filter);
28402
28437
  };
28403
28438
 
28439
+ /**
28440
+ * ```js
28441
+ * import { onRoomParticipantStageLeft } from '@amityco/ts-sdk'
28442
+ * const dispose = onRoomParticipantStageLeft(room => {
28443
+ * // ...
28444
+ * })
28445
+ * ```
28446
+ *
28447
+ * Fired when a participant has left the stage of a {@link Amity.Room}
28448
+ *
28449
+ * @param callback The function to call when the event was fired
28450
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
28451
+ *
28452
+ * @category Room Events
28453
+ */
28454
+ const onRoomParticipantStageLeft = (callback) => {
28455
+ const client = getActiveClient();
28456
+ const filter = (payload) => {
28457
+ const { rooms, users } = payload;
28458
+ ingestInCache({ rooms, users });
28459
+ callback({
28460
+ room: roomLinkedObject(rooms[0]),
28461
+ actorInternalId: payload.eventActor.userInternalId,
28462
+ });
28463
+ };
28464
+ return createEventSubscriber(client, 'room/onRoomParticipantStageLeft', 'room.participantStageLeft', filter);
28465
+ };
28466
+
28467
+ /**
28468
+ * ```js
28469
+ * import { onRoomParticipantStageJoined } from '@amityco/ts-sdk'
28470
+ * const dispose = onRoomParticipantStageJoined(room => {
28471
+ * // ...
28472
+ * })
28473
+ * ```
28474
+ *
28475
+ * Fired when a participant has joined the stage of a {@link Amity.Room}
28476
+ *
28477
+ * @param callback The function to call when the event was fired
28478
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
28479
+ *
28480
+ * @category Room Events
28481
+ */
28482
+ const onRoomParticipantStageJoined = (callback) => {
28483
+ const client = getActiveClient();
28484
+ const filter = (payload) => {
28485
+ const { rooms, users } = payload;
28486
+ ingestInCache({ rooms, users });
28487
+ callback({
28488
+ room: roomLinkedObject(rooms[0]),
28489
+ actorInternalId: payload.eventActor.userInternalId,
28490
+ });
28491
+ };
28492
+ return createEventSubscriber(client, 'room/onRoomParticipantStageJoined', 'room.participantStageJoined', filter);
28493
+ };
28494
+
28404
28495
  /**
28405
28496
  * ```js
28406
28497
  * import { onRoomTerminated } from '@amityco/ts-sdk'
@@ -28539,8 +28630,12 @@ const onRoomStopped = (callback) => {
28539
28630
  const onRoomParticipantRemoved = (callback) => {
28540
28631
  const client = getActiveClient();
28541
28632
  const filter = (payload) => {
28542
- ingestInCache(payload);
28543
- callback(payload.rooms[0]);
28633
+ const { rooms, users } = payload;
28634
+ ingestInCache({ rooms, users });
28635
+ callback({
28636
+ room: roomLinkedObject(rooms[0]),
28637
+ actorInternalId: payload.eventActor.userInternalId,
28638
+ });
28544
28639
  };
28545
28640
  return createEventSubscriber(client, 'room/onRoomParticipantRemoved', 'room.participantRemoved', filter);
28546
28641
  };
@@ -28593,6 +28688,68 @@ const onRoomParticipantRemovedLocal = (callback) => {
28593
28688
  return createEventSubscriber(client, 'room/onRoomParticipantRemoved', 'local.room.participantRemoved', filter);
28594
28689
  };
28595
28690
 
28691
+ var EnumRoomActions;
28692
+ (function (EnumRoomActions) {
28693
+ EnumRoomActions["OnRoomCreated"] = "OnRoomCreated";
28694
+ EnumRoomActions["OnRoomUpdated"] = "OnRoomUpdated";
28695
+ EnumRoomActions["OnRoomDeleted"] = "OnRoomDeleted";
28696
+ EnumRoomActions["OnRoomStartBroadcasting"] = "OnRoomStartBroadcasting";
28697
+ EnumRoomActions["OnRoomEndBroadcasting"] = "OnRoomEndBroadcasting";
28698
+ EnumRoomActions["OnRoomParticipantJoined"] = "OnRoomParticipantJoined";
28699
+ EnumRoomActions["OnRoomParticipantLeft"] = "OnRoomParticipantLeft";
28700
+ })(EnumRoomActions || (EnumRoomActions = {}));
28701
+
28702
+ const convertToRoomEventPayload = (eventHandler) => (callback) => eventHandler((payload) => {
28703
+ callback(payload.room);
28704
+ });
28705
+ // TODO: confirm related events
28706
+ const getRoomSubscription = () => [
28707
+ {
28708
+ fn: onRoomStartBroadcasting,
28709
+ action: EnumRoomActions.OnRoomStartBroadcasting,
28710
+ },
28711
+ {
28712
+ fn: onRoomEndBroadcasting,
28713
+ action: EnumRoomActions.OnRoomEndBroadcasting,
28714
+ },
28715
+ {
28716
+ fn: onRoomRecordedAvailable,
28717
+ action: EnumRoomActions.OnRoomUpdated,
28718
+ },
28719
+ {
28720
+ fn: onRoomWaitingReconnect,
28721
+ action: EnumRoomActions.OnRoomUpdated,
28722
+ },
28723
+ {
28724
+ fn: onRoomTerminated,
28725
+ action: EnumRoomActions.OnRoomUpdated,
28726
+ },
28727
+ {
28728
+ fn: convertToRoomEventPayload(onRoomParticipantJoined),
28729
+ action: EnumRoomActions.OnRoomUpdated,
28730
+ },
28731
+ {
28732
+ fn: convertToRoomEventPayload(onRoomParticipantLeft),
28733
+ action: EnumRoomActions.OnRoomUpdated,
28734
+ },
28735
+ {
28736
+ fn: convertToRoomEventPayload(onRoomParticipantRemoved),
28737
+ action: EnumRoomActions.OnRoomUpdated,
28738
+ },
28739
+ {
28740
+ fn: onRoomParticipantRemovedLocal,
28741
+ action: EnumRoomActions.OnRoomUpdated,
28742
+ },
28743
+ {
28744
+ fn: convertToRoomEventPayload(onRoomParticipantStageJoined),
28745
+ action: EnumRoomActions.OnRoomUpdated,
28746
+ },
28747
+ {
28748
+ fn: convertEventPayload(onRoomCoHostInviteAccepted, 'targetId', 'room'),
28749
+ action: EnumRoomActions.OnRoomUpdated,
28750
+ },
28751
+ ];
28752
+
28596
28753
  const getRoom = (roomId, callback) => {
28597
28754
  // TODO: add callbackDataSelector if there are linked object fields
28598
28755
  return liveObject(roomId, callback, '_id', getRoomById, [
@@ -28601,10 +28758,11 @@ const getRoom = (roomId, callback) => {
28601
28758
  onRoomWaitingReconnect,
28602
28759
  onRoomTerminated,
28603
28760
  onRoomRecordedAvailable,
28604
- onRoomParticipantJoined,
28605
- onRoomParticipantLeft,
28606
- onRoomParticipantRemoved,
28761
+ convertToRoomEventPayload(onRoomParticipantJoined),
28762
+ convertToRoomEventPayload(onRoomParticipantLeft),
28763
+ convertToRoomEventPayload(onRoomParticipantRemoved),
28607
28764
  onRoomParticipantRemovedLocal,
28765
+ convertToRoomEventPayload(onRoomParticipantStageJoined),
28608
28766
  convertEventPayload(onRoomCoHostInviteAccepted, 'targetId', 'room'),
28609
28767
  ], {
28610
28768
  callbackDataSelector: (data) => {
@@ -28629,17 +28787,6 @@ class RoomPaginationController extends PaginationController {
28629
28787
  }
28630
28788
  }
28631
28789
 
28632
- var EnumRoomActions;
28633
- (function (EnumRoomActions) {
28634
- EnumRoomActions["OnRoomCreated"] = "OnRoomCreated";
28635
- EnumRoomActions["OnRoomUpdated"] = "OnRoomUpdated";
28636
- EnumRoomActions["OnRoomDeleted"] = "OnRoomDeleted";
28637
- EnumRoomActions["OnRoomStartBroadcasting"] = "OnRoomStartBroadcasting";
28638
- EnumRoomActions["OnRoomEndBroadcasting"] = "OnRoomEndBroadcasting";
28639
- EnumRoomActions["OnRoomParticipantJoined"] = "OnRoomParticipantJoined";
28640
- EnumRoomActions["OnRoomParticipantLeft"] = "OnRoomParticipantLeft";
28641
- })(EnumRoomActions || (EnumRoomActions = {}));
28642
-
28643
28790
  class RoomQueryStreamController extends QueryStreamController {
28644
28791
  constructor(query, cacheKey, notifyChange, preparePayload) {
28645
28792
  super(query, cacheKey);
@@ -28688,22 +28835,6 @@ class RoomQueryStreamController extends QueryStreamController {
28688
28835
  }
28689
28836
  }
28690
28837
 
28691
- // TODO: confirm related events
28692
- const getRoomSubscription = () => [
28693
- {
28694
- fn: onRoomStartBroadcasting,
28695
- action: EnumRoomActions.OnRoomStartBroadcasting,
28696
- },
28697
- {
28698
- fn: onRoomEndBroadcasting,
28699
- action: EnumRoomActions.OnRoomEndBroadcasting,
28700
- },
28701
- {
28702
- fn: onRoomRecordedAvailable,
28703
- action: EnumRoomActions.OnRoomUpdated,
28704
- },
28705
- ];
28706
-
28707
28838
  class RoomLiveCollectionController extends LiveCollectionController {
28708
28839
  constructor(query, callback) {
28709
28840
  const queryStreamId = hash__default["default"](query);
@@ -28742,7 +28873,7 @@ class RoomLiveCollectionController extends LiveCollectionController {
28742
28873
  const data = this.applyFilter((_b = collection.data
28743
28874
  .map(id => pullFromCache(['room', 'get', id]))
28744
28875
  .filter(isNonNullable)
28745
- .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(room => room); // Since Room is same as InternalRoom, no transformation needed
28876
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(roomLinkedObject);
28746
28877
  if (!this.shouldNotify(data) && origin === 'event')
28747
28878
  return;
28748
28879
  this.callback({
@@ -28845,6 +28976,8 @@ var index$b = /*#__PURE__*/Object.freeze({
28845
28976
  onRoomCoHostInviteCanceled: onRoomCoHostInviteCanceled,
28846
28977
  onRoomParticipantJoined: onRoomParticipantJoined,
28847
28978
  onRoomParticipantLeft: onRoomParticipantLeft,
28979
+ onRoomParticipantStageLeft: onRoomParticipantStageLeft,
28980
+ onRoomParticipantStageJoined: onRoomParticipantStageJoined,
28848
28981
  onRoomTerminated: onRoomTerminated,
28849
28982
  onRoomCreated: onRoomCreated,
28850
28983
  onRoomUpdated: onRoomUpdated,
@@ -32648,24 +32781,30 @@ var index$2 = /*#__PURE__*/Object.freeze({
32648
32781
  * @param referenceType should be 'post'
32649
32782
  * @param reactionName that is the reaction name
32650
32783
  * @param streamId stream id
32784
+ * @param roomId room id
32651
32785
  * @returns a success boolean if the reaction was added
32652
32786
  *
32653
32787
  * @category Live Reaction API
32654
32788
  * @async
32655
32789
  */
32656
- const createReaction = async ({ referenceId, referenceType, reactionName, roomId, }) => {
32790
+ const createReaction = async ({ referenceId, referenceType, reactionName, streamId, roomId, }) => {
32657
32791
  const client = getActiveClient();
32658
32792
  client.log('live_reaction/createReaction', {
32659
32793
  referenceId,
32660
32794
  referenceType,
32661
32795
  reactionName,
32796
+ streamId,
32797
+ roomId,
32662
32798
  });
32799
+ if (!streamId && !roomId)
32800
+ throw new ASCError('You have to specify either streamId or roomId', 800110 /* Amity.ClientError.INVALID_PARAMETERS */, "error" /* Amity.ErrorLevel.ERROR */);
32663
32801
  const reactionSynceEngine = ReactionSyncEngine.getInstance();
32664
32802
  const reaction = {
32665
32803
  reactionName,
32666
32804
  referencePublicId: referenceId,
32667
32805
  referenceType,
32668
32806
  roomId,
32807
+ streamId,
32669
32808
  occurredAt: new Date().toISOString(),
32670
32809
  };
32671
32810
  reactionSynceEngine.createLiveReaction(reaction);
@@ -32855,15 +32994,32 @@ const updateEvent = async (eventId, bundle) => {
32855
32994
  const getEvent$1 = async (eventId) => {
32856
32995
  const client = getActiveClient();
32857
32996
  client.log('event/getEvent', eventId);
32858
- const { data: payload } = await client.http.get(`/api/v1/events/${eventId}`);
32859
- const data = prepareEventPayload(payload);
32860
- const cachedAt = client.cache && Date.now();
32861
- if (client.cache)
32862
- ingestInCache(data, { cachedAt });
32863
- return {
32864
- data: data.events.find(event => event.eventId === eventId),
32865
- cachedAt,
32866
- };
32997
+ try {
32998
+ const { data: payload } = await client.http.get(`/api/v1/events/${eventId}`);
32999
+ const data = prepareEventPayload(payload);
33000
+ const cachedAt = client.cache && Date.now();
33001
+ if (client.cache)
33002
+ ingestInCache(data, { cachedAt });
33003
+ return {
33004
+ data: data.events.find(event => event.eventId === eventId),
33005
+ cachedAt,
33006
+ };
33007
+ }
33008
+ catch (error) {
33009
+ if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
33010
+ const event = getEvent$1.locally(eventId);
33011
+ if (!event)
33012
+ throw error;
33013
+ const deletedEvent = Object.assign(Object.assign({}, event === null || event === void 0 ? void 0 : event.data), { isDeleted: true });
33014
+ upsertInCache(['event', 'get', eventId], deletedEvent);
33015
+ const cachedAt = client.cache && Date.now();
33016
+ return {
33017
+ data: deletedEvent,
33018
+ cachedAt,
33019
+ };
33020
+ }
33021
+ throw error;
33022
+ }
32867
33023
  };
32868
33024
  /* end_public_function */
32869
33025
  /**