@amityco/ts-sdk 7.11.1-6905f391.0 → 7.11.1-7696451.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 (87) 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 +4 -0
  4. package/dist/@types/core/model.d.ts.map +1 -1
  5. package/dist/@types/core/payload.d.ts +15 -0
  6. package/dist/@types/core/payload.d.ts.map +1 -1
  7. package/dist/@types/core/permissions.d.ts +5 -1
  8. package/dist/@types/core/permissions.d.ts.map +1 -1
  9. package/dist/@types/domains/community.d.ts +11 -1
  10. package/dist/@types/domains/community.d.ts.map +1 -1
  11. package/dist/@types/domains/event.d.ts +61 -9
  12. package/dist/@types/domains/event.d.ts.map +1 -1
  13. package/dist/@types/domains/notification.d.ts +3 -1
  14. package/dist/@types/domains/notification.d.ts.map +1 -1
  15. package/dist/@types/domains/partials.d.ts +2 -2
  16. package/dist/@types/domains/partials.d.ts.map +1 -1
  17. package/dist/core/events.d.ts +3 -3
  18. package/dist/core/events.d.ts.map +1 -1
  19. package/dist/core/model/idResolvers.d.ts.map +1 -1
  20. package/dist/core/model/index.d.ts.map +1 -1
  21. package/dist/eventRepository/events/enums.d.ts +8 -0
  22. package/dist/eventRepository/events/enums.d.ts.map +1 -0
  23. package/dist/eventRepository/events/index.d.ts +7 -0
  24. package/dist/eventRepository/events/index.d.ts.map +1 -1
  25. package/dist/eventRepository/events/onLocalEventCreated.d.ts +17 -0
  26. package/dist/eventRepository/events/onLocalEventCreated.d.ts.map +1 -0
  27. package/dist/eventRepository/events/onLocalEventDeleted.d.ts +17 -0
  28. package/dist/eventRepository/events/onLocalEventDeleted.d.ts.map +1 -0
  29. package/dist/eventRepository/events/onLocalEventUpdated.d.ts +17 -0
  30. package/dist/eventRepository/events/onLocalEventUpdated.d.ts.map +1 -0
  31. package/dist/eventRepository/events/onLocalRSVPCreated.d.ts +17 -0
  32. package/dist/eventRepository/events/onLocalRSVPCreated.d.ts.map +1 -0
  33. package/dist/eventRepository/events/onLocalRSVPUpdated.d.ts +17 -0
  34. package/dist/eventRepository/events/onLocalRSVPUpdated.d.ts.map +1 -0
  35. package/dist/eventRepository/events/onRSVPCreated.d.ts +17 -0
  36. package/dist/eventRepository/events/onRSVPCreated.d.ts.map +1 -0
  37. package/dist/eventRepository/events/onRSVPUpdated.d.ts +17 -0
  38. package/dist/eventRepository/events/onRSVPUpdated.d.ts.map +1 -0
  39. package/dist/eventRepository/internalApi/createRSVP.d.ts +16 -0
  40. package/dist/eventRepository/internalApi/createRSVP.d.ts.map +1 -0
  41. package/dist/eventRepository/internalApi/getMyRSVP.d.ts +32 -0
  42. package/dist/eventRepository/internalApi/getMyRSVP.d.ts.map +1 -0
  43. package/dist/eventRepository/internalApi/index.d.ts +3 -0
  44. package/dist/eventRepository/internalApi/index.d.ts.map +1 -1
  45. package/dist/eventRepository/internalApi/updateRSVP.d.ts +17 -0
  46. package/dist/eventRepository/internalApi/updateRSVP.d.ts.map +1 -0
  47. package/dist/eventRepository/observers/getEvent.d.ts.map +1 -1
  48. package/dist/eventRepository/observers/getEvents/LiveCollectionController.d.ts +13 -0
  49. package/dist/eventRepository/observers/getEvents/LiveCollectionController.d.ts.map +1 -0
  50. package/dist/eventRepository/observers/getEvents/PaginationController.d.ts +5 -0
  51. package/dist/eventRepository/observers/getEvents/PaginationController.d.ts.map +1 -0
  52. package/dist/eventRepository/observers/getEvents/QueryStreamController.d.ts +15 -0
  53. package/dist/eventRepository/observers/getEvents/QueryStreamController.d.ts.map +1 -0
  54. package/dist/eventRepository/observers/getEvents.d.ts +12 -0
  55. package/dist/eventRepository/observers/getEvents.d.ts.map +1 -0
  56. package/dist/eventRepository/observers/getMyEvents/LiveCollectionController.d.ts +13 -0
  57. package/dist/eventRepository/observers/getMyEvents/LiveCollectionController.d.ts.map +1 -0
  58. package/dist/eventRepository/observers/getMyEvents/PaginationController.d.ts +5 -0
  59. package/dist/eventRepository/observers/getMyEvents/PaginationController.d.ts.map +1 -0
  60. package/dist/eventRepository/observers/getMyEvents/QueryStreamController.d.ts +15 -0
  61. package/dist/eventRepository/observers/getMyEvents/QueryStreamController.d.ts.map +1 -0
  62. package/dist/eventRepository/observers/getMyEvents.d.ts +12 -0
  63. package/dist/eventRepository/observers/getMyEvents.d.ts.map +1 -0
  64. package/dist/eventRepository/observers/getRSVPs/LiveCollectionController.d.ts +13 -0
  65. package/dist/eventRepository/observers/getRSVPs/LiveCollectionController.d.ts.map +1 -0
  66. package/dist/eventRepository/observers/getRSVPs/PaginationController.d.ts +5 -0
  67. package/dist/eventRepository/observers/getRSVPs/PaginationController.d.ts.map +1 -0
  68. package/dist/eventRepository/observers/getRSVPs/QueryStreamController.d.ts +15 -0
  69. package/dist/eventRepository/observers/getRSVPs/QueryStreamController.d.ts.map +1 -0
  70. package/dist/eventRepository/observers/getRSVPs.d.ts +12 -0
  71. package/dist/eventRepository/observers/getRSVPs.d.ts.map +1 -0
  72. package/dist/eventRepository/observers/index.d.ts +3 -0
  73. package/dist/eventRepository/observers/index.d.ts.map +1 -1
  74. package/dist/eventRepository/utils/createEventEventSubscriber.d.ts +1 -1
  75. package/dist/eventRepository/utils/createEventEventSubscriber.d.ts.map +1 -1
  76. package/dist/eventRepository/utils/createEventResponseSubscriber.d.ts +2 -0
  77. package/dist/eventRepository/utils/createEventResponseSubscriber.d.ts.map +1 -0
  78. package/dist/eventRepository/utils/index.d.ts +2 -0
  79. package/dist/eventRepository/utils/index.d.ts.map +1 -1
  80. package/dist/eventRepository/utils/prepareEventResponsePayload.d.ts +2 -0
  81. package/dist/eventRepository/utils/prepareEventResponsePayload.d.ts.map +1 -0
  82. package/dist/index.cjs.js +835 -89
  83. package/dist/index.esm.js +831 -85
  84. package/dist/index.umd.js +3 -3
  85. package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts +1 -1
  86. package/dist/utils/linkedObject/eventLinkObject.d.ts.map +1 -1
  87. package/package.json +1 -1
package/dist/index.esm.js CHANGED
@@ -194,6 +194,11 @@ var AmityEventStatus;
194
194
  AmityEventStatus["Ended"] = "ended";
195
195
  AmityEventStatus["Cancelled"] = "cancelled";
196
196
  })(AmityEventStatus || (AmityEventStatus = {}));
197
+ var AmityEventResponseStatus;
198
+ (function (AmityEventResponseStatus) {
199
+ AmityEventResponseStatus["Going"] = "going";
200
+ AmityEventResponseStatus["NotGoing"] = "not_going";
201
+ })(AmityEventResponseStatus || (AmityEventResponseStatus = {}));
197
202
 
198
203
  function getVersion() {
199
204
  try {
@@ -643,6 +648,9 @@ const idResolvers = {
643
648
  notificationTraySeen: ({ userId }) => userId,
644
649
  invitation: ({ _id }) => _id,
645
650
  joinRequest: ({ joinRequestId }) => joinRequestId,
651
+ event: ({ eventId }) => eventId,
652
+ eventResponse: ({ eventId }) => eventId,
653
+ discussionCommunity: ({ communityId }) => communityId,
646
654
  };
647
655
  /**
648
656
  * Retrieve the id resolver matching a domain name
@@ -698,6 +706,9 @@ const PAYLOAD2MODEL = {
698
706
  notificationTrayItems: 'notificationTrayItem',
699
707
  invitations: 'invitation',
700
708
  joinRequests: 'joinRequest',
709
+ events: 'event',
710
+ eventResponses: 'eventResponse',
711
+ discussionCommunities: 'discussionCommunity',
701
712
  };
702
713
  /** hidden */
703
714
  const isOutdated = (prevData, nextData) => {
@@ -29768,6 +29779,504 @@ const communityLinkedObject = (community) => {
29768
29779
  } });
29769
29780
  };
29770
29781
 
29782
+ const prepareEventResponsePayload = (rawPayload) => {
29783
+ return {
29784
+ respondedAt: rawPayload.eventResponses[0].respondedAt,
29785
+ status: rawPayload.eventResponses[0].status,
29786
+ eventId: rawPayload.eventResponses[0].eventId,
29787
+ event: rawPayload.events,
29788
+ userId: rawPayload.eventResponses[0].userId,
29789
+ user: rawPayload.users.map(convertRawUserToInternalUser),
29790
+ };
29791
+ };
29792
+
29793
+ /* begin_public_function
29794
+ id: event.rsvp.create
29795
+ */
29796
+ /**
29797
+ * ```js
29798
+ * import { event } from '@amityco/ts-sdk'
29799
+ * const response = await event.createRSVP(eventId, status)
29800
+ * ```
29801
+ *
29802
+ * Creates an {@link Amity.InternalEvent}
29803
+ *
29804
+ * @param bundle The data necessary to create a new {@link Amity.InternalEvent}
29805
+ * @returns The newly created {@link Amity.InternalEvent}
29806
+ *
29807
+ * @category Event API
29808
+ * @async
29809
+ */
29810
+ const createRSVP = async (eventId, status) => {
29811
+ const client = getActiveClient();
29812
+ client.log('event/createRSVP', eventId, status);
29813
+ const { data: payload } = await client.http.post(`/api/v1/events/${eventId}/rsvp`, { status });
29814
+ fireEvent('local.rsvp.created', payload);
29815
+ const data = prepareEventResponsePayload(payload);
29816
+ const cachedAt = client.cache && Date.now();
29817
+ if (client.cache)
29818
+ ingestInCache({ eventResponses: [data] }, { cachedAt });
29819
+ return {
29820
+ data,
29821
+ cachedAt,
29822
+ };
29823
+ };
29824
+ /* end_public_function */
29825
+
29826
+ /* begin_public_function
29827
+ id: event.update
29828
+ */
29829
+ /**
29830
+ * ```js
29831
+ * import { event } from '@amityco/ts-sdk'
29832
+ * const response = await event.updateRSVP(eventId, status)
29833
+ * ```
29834
+ *
29835
+ * Updates an {@link Amity.EventResponse}
29836
+ *
29837
+ * @param eventId The ID of the {@link Amity.EventResponse} to edit
29838
+ * @param bundle The data necessary to update an existing {@link Amity.EventResponse}
29839
+ * @returns the updated {@link Amity.EventResponse}
29840
+ *
29841
+ * @category Event API
29842
+ * @async
29843
+ */
29844
+ const updateRSVP = async (eventId, status) => {
29845
+ const client = getActiveClient();
29846
+ client.log('event/updateRSVP', eventId, status);
29847
+ const { data: payload } = await client.http.put(`/api/v1/events/${eventId}/rsvp`, { status });
29848
+ fireEvent('local.rsvp.updated', payload);
29849
+ const data = prepareEventResponsePayload(payload);
29850
+ const cachedAt = client.cache && Date.now();
29851
+ if (client.cache)
29852
+ ingestInCache({ eventResponses: [data] }, { cachedAt });
29853
+ return {
29854
+ data,
29855
+ cachedAt,
29856
+ };
29857
+ };
29858
+ /* end_public_function */
29859
+
29860
+ const prepareEventPayload = (rawPayload) => {
29861
+ return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser) });
29862
+ };
29863
+
29864
+ const createEventEventSubscriber = (event, callback) => {
29865
+ const client = getActiveClient();
29866
+ const filter = (payload) => {
29867
+ const unpackedPayload = prepareEventPayload(payload);
29868
+ if (!client.cache) {
29869
+ callback(unpackedPayload.events[0]);
29870
+ }
29871
+ else {
29872
+ ingestInCache(unpackedPayload);
29873
+ const event = pullFromCache([
29874
+ 'event',
29875
+ 'get',
29876
+ unpackedPayload.events[0].eventId,
29877
+ ]);
29878
+ callback(event.data);
29879
+ }
29880
+ };
29881
+ return createEventSubscriber(client, event, event, filter);
29882
+ };
29883
+
29884
+ const createEventResponseSubscriber = (event, callback) => {
29885
+ const client = getActiveClient();
29886
+ const filter = (payload) => {
29887
+ const unpackedPayload = prepareEventResponsePayload(payload);
29888
+ if (!client.cache) {
29889
+ callback(unpackedPayload);
29890
+ }
29891
+ else {
29892
+ ingestInCache(unpackedPayload.event[0]);
29893
+ const eventResponse = pullFromCache([
29894
+ 'eventResponse',
29895
+ 'get',
29896
+ payload.eventResponses[0].eventId,
29897
+ ]);
29898
+ callback(eventResponse.data);
29899
+ }
29900
+ };
29901
+ return createEventSubscriber(client, event, event, filter);
29902
+ };
29903
+
29904
+ /* begin_public_function
29905
+ id: event.rsvp.me
29906
+ */
29907
+ /**
29908
+ * ```js
29909
+ * import { event } from '@amityco/ts-sdk'
29910
+ * const myRSVP = await event.getMyRSVP()
29911
+ * ```
29912
+ *
29913
+ * Joins a {@link Amity.EventResponse} object
29914
+ *
29915
+ * @param eventId the {@link Amity.EventResponse} to get RSVP for
29916
+ * @returns A success boolean if the {@link Amity.EventResponse} RSVP was retrieved
29917
+ *
29918
+ * @category Event API
29919
+ * @async
29920
+ */
29921
+ const getMyRSVP = async (eventId) => {
29922
+ const client = getActiveClient();
29923
+ client.log('event/getMyRSVP', eventId);
29924
+ const { data: payload } = await client.http.get(`/api/v1/events/${eventId}/me/rsvp`);
29925
+ const data = prepareEventResponsePayload(payload);
29926
+ const cachedAt = client.cache && Date.now();
29927
+ if (client.cache)
29928
+ ingestInCache({ eventResponses: [data] }, { cachedAt });
29929
+ return {
29930
+ data,
29931
+ cachedAt,
29932
+ };
29933
+ };
29934
+ /* end_public_function */
29935
+ /**
29936
+ * ```js
29937
+ * import { event } from '@amityco/ts-sdk'
29938
+ * const event = event.getMyRSVP.locally(eventId)
29939
+ * ```
29940
+ *
29941
+ * Fetches a {@link Amity.EventResponse} object in cache
29942
+ *
29943
+ * @param eventId the ID of the {@link Amity.EventResponse} to fetch
29944
+ * @returns the associated {@link Amity.EventResponse} object
29945
+ *
29946
+ * @category Event API
29947
+ */
29948
+ getMyRSVP.locally = (eventId) => {
29949
+ const client = getActiveClient();
29950
+ client.log('event/getMyRSVP.locally', eventId);
29951
+ if (!client.cache)
29952
+ return;
29953
+ const cache = pullFromCache(['event', 'getMyRSVP', eventId]);
29954
+ if (!cache)
29955
+ return;
29956
+ return {
29957
+ data: cache.data,
29958
+ cachedAt: cache.cachedAt,
29959
+ };
29960
+ };
29961
+
29962
+ var EventActionsEnum;
29963
+ (function (EventActionsEnum) {
29964
+ EventActionsEnum["OnEventCreated"] = "onEventCreated";
29965
+ EventActionsEnum["OnEventUpdated"] = "onEventUpdated";
29966
+ EventActionsEnum["OnEventDeleted"] = "onEventDeleted";
29967
+ EventActionsEnum["OnRSVPCreated"] = "onRSVPCreated";
29968
+ EventActionsEnum["OnRSVPUpdated"] = "onRSVPUpdated";
29969
+ })(EventActionsEnum || (EventActionsEnum = {}));
29970
+
29971
+ class RSVPPaginationController extends PaginationController {
29972
+ async getRequest(queryParams, token) {
29973
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, eventId } = queryParams, params = __rest(queryParams, ["limit", "eventId"]);
29974
+ const options = token ? { token } : { limit };
29975
+ const { data: response } = await this.http.get(`/api/v1/events/${eventId}/rsvp`, { params: Object.assign(Object.assign({}, params), { options }) });
29976
+ return response;
29977
+ }
29978
+ }
29979
+
29980
+ class RSVPQueryStreamController extends QueryStreamController {
29981
+ constructor(query, cacheKey, notifyChange, preparePayload) {
29982
+ super(query, cacheKey);
29983
+ this.notifyChange = notifyChange;
29984
+ this.preparePayload = preparePayload;
29985
+ }
29986
+ async saveToMainDB(response) {
29987
+ const processedPayload = this.preparePayload(response);
29988
+ const client = getActiveClient();
29989
+ const cachedAt = client.cache && Date.now();
29990
+ if (client.cache)
29991
+ ingestInCache({ eventResponses: [processedPayload] }, { cachedAt });
29992
+ }
29993
+ appendToQueryStream(response, direction, refresh = false) {
29994
+ var _a, _b;
29995
+ if (refresh) {
29996
+ pushToCache(this.cacheKey, {
29997
+ data: response.eventResponses.map(getResolver('eventResponse')),
29998
+ });
29999
+ }
30000
+ else {
30001
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
30002
+ const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
30003
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
30004
+ ...new Set([...events, ...response.eventResponses.map(getResolver('eventResponse'))]),
30005
+ ] }));
30006
+ }
30007
+ }
30008
+ reactor(action) {
30009
+ return (event) => {
30010
+ var _a;
30011
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
30012
+ if (!collection)
30013
+ return;
30014
+ if (action === EventActionsEnum.OnRSVPCreated) {
30015
+ const client = getActiveClient();
30016
+ if (client.userId !== event.userId)
30017
+ return;
30018
+ collection.data = [...new Set([event.eventId, ...collection.data])];
30019
+ }
30020
+ if (action === EventActionsEnum.OnEventDeleted) {
30021
+ collection.data = collection.data.filter(eventId => eventId !== event.eventId);
30022
+ }
30023
+ pushToCache(this.cacheKey, collection);
30024
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
30025
+ };
30026
+ }
30027
+ subscribeRTE(createSubscriber) {
30028
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
30029
+ }
30030
+ }
30031
+
30032
+ /**
30033
+ * ```js
30034
+ * import { EventRepository } from '@amityco/ts-sdk'
30035
+ * const dispose = EventRepository.onEventCreated(event => {
30036
+ * // ...
30037
+ * })
30038
+ * ```
30039
+ *
30040
+ * Fired when a {@link Amity.Event} has been created
30041
+ *
30042
+ * @param callback The function to call when the event was fired
30043
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30044
+ *
30045
+ * @category Event Events
30046
+ */
30047
+ const onEventCreated = (callback) => createEventEventSubscriber('event.created', callback);
30048
+
30049
+ /**
30050
+ * ```js
30051
+ * import { EventRepository } from '@amityco/ts-sdk'
30052
+ * const dispose = EventRepository.onEventUpdated(event => {
30053
+ * // ...
30054
+ * })
30055
+ * ```
30056
+ *
30057
+ * Fired when a {@link Amity.Event} has been updated
30058
+ *
30059
+ * @param callback The function to call when the event was fired
30060
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30061
+ *
30062
+ * @category Event Events
30063
+ */
30064
+ const onEventUpdated = (callback) => createEventEventSubscriber('event.updated', callback);
30065
+
30066
+ /**
30067
+ * ```js
30068
+ * import { EventRepository } from '@amityco/ts-sdk'
30069
+ * const dispose = EventRepository.onEventDeleted(event => {
30070
+ * // ...
30071
+ * })
30072
+ * ```
30073
+ *
30074
+ * Fired when a {@link Amity.Event} has been deleted
30075
+ *
30076
+ * @param callback The function to call when the event was fired
30077
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30078
+ *
30079
+ * @category Event Events
30080
+ */
30081
+ const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted', callback);
30082
+
30083
+ /**
30084
+ * ```js
30085
+ * import { EventRepository } from '@amityco/ts-sdk'
30086
+ * const dispose = EventRepository.onLocalEventCreated(event => {
30087
+ * // ...
30088
+ * })
30089
+ * ```
30090
+ *
30091
+ * Fired when a {@link Amity.Event} has been created
30092
+ *
30093
+ * @param callback The function to call when the event was fired
30094
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30095
+ *
30096
+ * @category Event Events
30097
+ */
30098
+ const onLocalEventCreated = (callback) => createEventEventSubscriber('local.event.created', callback);
30099
+
30100
+ /**
30101
+ * ```js
30102
+ * import { EventRepository } from '@amityco/ts-sdk'
30103
+ * const dispose = EventRepository.onLocalEventUpdated(event => {
30104
+ * // ...
30105
+ * })
30106
+ * ```
30107
+ *
30108
+ * Fired when a {@link Amity.Event} has been updated
30109
+ *
30110
+ * @param callback The function to call when the event was fired
30111
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30112
+ *
30113
+ * @category Event Events
30114
+ */
30115
+ const onLocalEventUpdated = (callback) => createEventEventSubscriber('local.event.updated', callback);
30116
+
30117
+ /**
30118
+ * ```js
30119
+ * import { EventRepository } from '@amityco/ts-sdk'
30120
+ * const dispose = EventRepository.onLocalEventDeleted(event => {
30121
+ * // ...
30122
+ * })
30123
+ * ```
30124
+ *
30125
+ * Fired when a {@link Amity.Event} has been deleted
30126
+ *
30127
+ * @param callback The function to call when the event was fired
30128
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30129
+ *
30130
+ * @category Event Events
30131
+ */
30132
+ const onLocalEventDeleted = (callback) => createEventEventSubscriber('local.event.deleted', callback);
30133
+
30134
+ /**
30135
+ * ```js
30136
+ * import { EventRepository } from '@amityco/ts-sdk'
30137
+ * const dispose = EventRepository.onRSVPCreated(event => {
30138
+ * // ...
30139
+ * })
30140
+ * ```
30141
+ *
30142
+ * Fired when a {@link Amity.Event} has been created
30143
+ *
30144
+ * @param callback The function to call when the event was fired
30145
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30146
+ *
30147
+ * @category Event Events
30148
+ */
30149
+ const onRSVPCreated = (callback) => createEventResponseSubscriber('event.rsvp.created', callback);
30150
+
30151
+ /**
30152
+ * ```js
30153
+ * import { EventRepository } from '@amityco/ts-sdk'
30154
+ * const dispose = EventRepository.onRSVPUpdated(event => {
30155
+ * // ...
30156
+ * })
30157
+ * ```
30158
+ *
30159
+ * Fired when a {@link Amity.InternalEventResponse} has been updated
30160
+ *
30161
+ * @param callback The function to call when the event was fired
30162
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30163
+ *
30164
+ * @category Event Events
30165
+ */
30166
+ const onRSVPUpdated = (callback) => createEventResponseSubscriber('event.rsvp.updated', callback);
30167
+
30168
+ /**
30169
+ * ```js
30170
+ * import { EventRepository } from '@amityco/ts-sdk'
30171
+ * const dispose = EventRepository.onLocalRSVPCreated(event => {
30172
+ * // ...
30173
+ * })
30174
+ * ```
30175
+ *
30176
+ * Fired when a {@link Amity.Event} has been created
30177
+ *
30178
+ * @param callback The function to call when the event was fired
30179
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30180
+ *
30181
+ * @category Event Events
30182
+ */
30183
+ const onLocalRSVPCreated = (callback) => createEventResponseSubscriber('local.rsvp.created', callback);
30184
+
30185
+ /**
30186
+ * ```js
30187
+ * import { EventRepository } from '@amityco/ts-sdk'
30188
+ * const dispose = EventRepository.onLocalEventUpdated(event => {
30189
+ * // ...
30190
+ * })
30191
+ * ```
30192
+ *
30193
+ * Fired when a {@link Amity.Event} has been updated
30194
+ *
30195
+ * @param callback The function to call when the event was fired
30196
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30197
+ *
30198
+ * @category Event Events
30199
+ */
30200
+ const onLocalRSVPUpdated = (callback) => createEventResponseSubscriber('local.rsvp.updated', callback);
30201
+
30202
+ class RSVPLiveCollectionController extends LiveCollectionController {
30203
+ constructor(query, callback) {
30204
+ const queryStreamId = hash(query);
30205
+ const cacheKey = ['eventResponse', 'collection', queryStreamId];
30206
+ const paginationController = new RSVPPaginationController(query);
30207
+ super(paginationController, queryStreamId, cacheKey, callback);
30208
+ this.query = query;
30209
+ this.queryStreamController = new RSVPQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventResponsePayload);
30210
+ this.callback = callback.bind(this);
30211
+ this.loadPage({ initial: true });
30212
+ }
30213
+ setup() {
30214
+ var _a;
30215
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
30216
+ if (!collection)
30217
+ pushToCache(this.cacheKey, { data: [], params: this.query });
30218
+ }
30219
+ async persistModel(queryPayload) {
30220
+ await this.queryStreamController.saveToMainDB(queryPayload);
30221
+ }
30222
+ persistQueryStream({ response, direction, refresh, }) {
30223
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
30224
+ }
30225
+ startSubscription() {
30226
+ return this.queryStreamController.subscribeRTE([
30227
+ { fn: onRSVPCreated, action: EventActionsEnum.OnRSVPCreated },
30228
+ { fn: onRSVPUpdated, action: EventActionsEnum.OnRSVPUpdated },
30229
+ { fn: onLocalRSVPCreated, action: EventActionsEnum.OnRSVPCreated },
30230
+ { fn: onLocalRSVPUpdated, action: EventActionsEnum.OnRSVPUpdated },
30231
+ ]);
30232
+ }
30233
+ notifyChange({ origin, loading, error }) {
30234
+ var _a, _b;
30235
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
30236
+ if (!collection)
30237
+ return;
30238
+ const data = (_b = collection.data
30239
+ .map(eventId => pullFromCache(['eventResponse', 'get', eventId]))
30240
+ .filter(isNonNullable)
30241
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
30242
+ if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
30243
+ return;
30244
+ this.callback({
30245
+ data,
30246
+ error,
30247
+ loading,
30248
+ hasNextPage: !!this.paginationController.getNextToken(),
30249
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
30250
+ });
30251
+ }
30252
+ }
30253
+
30254
+ /**
30255
+ * Get events
30256
+ *
30257
+ * @param params the query parameters
30258
+ * @param callback the callback to be called when the events are updated
30259
+ * @returns events
30260
+ *
30261
+ * @category RSVP Live Collection
30262
+ *
30263
+ */
30264
+ const getRSVPs = (params, callback, config) => {
30265
+ const { log, cache } = getActiveClient();
30266
+ if (!cache)
30267
+ console.log(ENABLE_CACHE_MESSAGE);
30268
+ const timestamp = Date.now();
30269
+ log(`getRSVPs: (tmpid: ${timestamp}) > listen`);
30270
+ const rsvpLiveCollection = new RSVPLiveCollectionController(params, callback);
30271
+ const disposers = rsvpLiveCollection.startSubscription();
30272
+ const cacheKey = rsvpLiveCollection.getCacheKey();
30273
+ disposers.push(() => dropFromCache(cacheKey));
30274
+ return () => {
30275
+ log(`getRSVPs (tmpid: ${timestamp}) > dispose`);
30276
+ disposers.forEach(fn => fn());
30277
+ };
30278
+ };
30279
+
29771
30280
  const eventLinkedObject = (event) => {
29772
30281
  return Object.assign(Object.assign({}, event), { get creator() {
29773
30282
  const cacheData = pullFromCache(['user', 'get', event.userId]);
@@ -29776,13 +30285,33 @@ const eventLinkedObject = (event) => {
29776
30285
  return userLinkedObject(cacheData.data);
29777
30286
  },
29778
30287
  get discussionCommunity() {
29779
- if (!event.communityId)
30288
+ if (!event.discussionCommunityId)
30289
+ return;
30290
+ const cacheData = pullFromCache([
30291
+ 'discussionCommunity',
30292
+ 'get',
30293
+ event.discussionCommunityId,
30294
+ ]);
30295
+ if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
30296
+ return;
30297
+ return communityLinkedObject(cacheData.data);
30298
+ },
30299
+ get targetCommunity() {
30300
+ if (!event.originId)
29780
30301
  return;
29781
- const cacheData = pullFromCache(['community', 'get', event.communityId]);
30302
+ const cacheData = pullFromCache(['community', 'get', event.originId]);
29782
30303
  if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
29783
30304
  return;
29784
30305
  return communityLinkedObject(cacheData.data);
29785
30306
  },
30307
+ get coverImage() {
30308
+ if (!event.coverImageFileId)
30309
+ return;
30310
+ const cacheData = pullFromCache(['file', 'get', event.coverImageFileId]);
30311
+ if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
30312
+ return;
30313
+ return cacheData.data;
30314
+ },
29786
30315
  get liveStream() {
29787
30316
  if (!event.livestreamId)
29788
30317
  return;
@@ -29790,6 +30319,17 @@ const eventLinkedObject = (event) => {
29790
30319
  if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
29791
30320
  return;
29792
30321
  return cacheData.data;
30322
+ }, createRSVP: async (status) => {
30323
+ const { data } = await createRSVP(event.eventId, status);
30324
+ return data;
30325
+ }, updateRSVP: async (status) => {
30326
+ const { data } = await updateRSVP(event.eventId, status);
30327
+ return data;
30328
+ }, getMyRSVP: async () => {
30329
+ const { data } = await getMyRSVP(event.eventId);
30330
+ return data;
30331
+ }, getRSVPs: (params, callback) => {
30332
+ return getRSVPs(Object.assign({ eventId: event.eventId }, params), callback);
29793
30333
  } });
29794
30334
  };
29795
30335
 
@@ -46429,30 +46969,6 @@ var index$1 = /*#__PURE__*/Object.freeze({
46429
46969
  getReactions: getReactions
46430
46970
  });
46431
46971
 
46432
- const prepareEventPayload = (rawPayload) => {
46433
- return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser) });
46434
- };
46435
-
46436
- const createEventEventSubscriber = (event, callback) => {
46437
- const client = getActiveClient();
46438
- const filter = (payload) => {
46439
- const unpackedPayload = prepareEventPayload(payload);
46440
- if (!client.cache) {
46441
- callback(unpackedPayload.events[0]);
46442
- }
46443
- else {
46444
- ingestInCache(unpackedPayload);
46445
- const event = pullFromCache([
46446
- 'event',
46447
- 'get',
46448
- unpackedPayload.events[0].eventId,
46449
- ]);
46450
- callback(event.data);
46451
- }
46452
- };
46453
- return createEventSubscriber(client, event, event, filter);
46454
- };
46455
-
46456
46972
  /* begin_public_function
46457
46973
  id: event.create
46458
46974
  */
@@ -46474,7 +46990,7 @@ const createEvent = async (bundle) => {
46474
46990
  const client = getActiveClient();
46475
46991
  client.log('event/createEvent', bundle);
46476
46992
  const { data: payload } = await client.http.post('/api/v1/events', bundle);
46477
- fireEvent('event.created', payload);
46993
+ fireEvent('local.event.created', payload);
46478
46994
  const preparedPayload = prepareEventPayload(payload);
46479
46995
  const cachedAt = client.cache && Date.now();
46480
46996
  if (client.cache)
@@ -46508,7 +47024,7 @@ const updateEvent = async (eventId, bundle) => {
46508
47024
  const client = getActiveClient();
46509
47025
  client.log('event/updateEvent', eventId, bundle);
46510
47026
  const { data: payload } = await client.http.put(`/api/v1/events/${eventId}`, bundle);
46511
- fireEvent('event.updated', payload);
47027
+ fireEvent('local.event.updated', payload);
46512
47028
  const preparedPayload = prepareEventPayload(payload);
46513
47029
  const cachedAt = client.cache && Date.now();
46514
47030
  if (client.cache)
@@ -46540,7 +47056,7 @@ const updateEvent = async (eventId, bundle) => {
46540
47056
  const getEvent$1 = async (eventId) => {
46541
47057
  const client = getActiveClient();
46542
47058
  client.log('event/getEvent', eventId);
46543
- const { data: payload } = await client.http.get(`/api/v3/events/${eventId}`);
47059
+ const { data: payload } = await client.http.get(`/api/v1/events/${eventId}`);
46544
47060
  const data = prepareEventPayload(payload);
46545
47061
  const cachedAt = client.cache && Date.now();
46546
47062
  if (client.cache)
@@ -46598,10 +47114,10 @@ const deleteEvent = async (eventId) => {
46598
47114
  const client = getActiveClient();
46599
47115
  client.log('event/deleteEvent', eventId);
46600
47116
  const event = await getEvent$1(eventId);
46601
- await client.http.delete(`/api/v3/events/${eventId}`);
47117
+ await client.http.delete(`/api/v1/events/${eventId}`);
46602
47118
  const deletedEvent = Object.assign(Object.assign({}, event.data), { isDeleted: true });
46603
47119
  upsertInCache(['event', 'get', eventId], deletedEvent);
46604
- fireEvent('event.deleted', {
47120
+ fireEvent('local.event.deleted', {
46605
47121
  users: [],
46606
47122
  files: [],
46607
47123
  communities: [],
@@ -46612,57 +47128,6 @@ const deleteEvent = async (eventId) => {
46612
47128
  };
46613
47129
  /* end_public_function */
46614
47130
 
46615
- /**
46616
- * ```js
46617
- * import { EventRepository } from '@amityco/ts-sdk'
46618
- * const dispose = EventRepository.onEventCreated(event => {
46619
- * // ...
46620
- * })
46621
- * ```
46622
- *
46623
- * Fired when a {@link Amity.Event} has been created
46624
- *
46625
- * @param callback The function to call when the event was fired
46626
- * @returns an {@link Amity.Unsubscriber} function to stop listening
46627
- *
46628
- * @category Event Events
46629
- */
46630
- const onEventCreated = (callback) => createEventEventSubscriber('event.created', callback);
46631
-
46632
- /**
46633
- * ```js
46634
- * import { EventRepository } from '@amityco/ts-sdk'
46635
- * const dispose = EventRepository.onEventUpdated(event => {
46636
- * // ...
46637
- * })
46638
- * ```
46639
- *
46640
- * Fired when a {@link Amity.Event} has been updated
46641
- *
46642
- * @param callback The function to call when the event was fired
46643
- * @returns an {@link Amity.Unsubscriber} function to stop listening
46644
- *
46645
- * @category Event Events
46646
- */
46647
- const onEventUpdated = (callback) => createEventEventSubscriber('event.updated', callback);
46648
-
46649
- /**
46650
- * ```js
46651
- * import { EventRepository } from '@amityco/ts-sdk'
46652
- * const dispose = EventRepository.onEventDeleted(event => {
46653
- * // ...
46654
- * })
46655
- * ```
46656
- *
46657
- * Fired when a {@link Amity.Event} has been deleted
46658
- *
46659
- * @param callback The function to call when the event was fired
46660
- * @returns an {@link Amity.Unsubscriber} function to stop listening
46661
- *
46662
- * @category Event Events
46663
- */
46664
- const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted', callback);
46665
-
46666
47131
  /* begin_public_function
46667
47132
  id: event.get
46668
47133
  */
@@ -46686,12 +47151,283 @@ const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted',
46686
47151
  * @category Event Live Object
46687
47152
  */
46688
47153
  const getEvent = (eventId, callback) => {
46689
- return liveObject(eventId, callback, 'eventId', getEvent$1, [onEventCreated, onEventUpdated, onEventDeleted], {
47154
+ return liveObject(eventId, callback, 'eventId', getEvent$1, [onEventUpdated, onEventDeleted, onLocalEventUpdated, onLocalEventDeleted], {
46690
47155
  callbackDataSelector: (data) => (data ? eventLinkedObject(data) : data),
46691
47156
  });
46692
47157
  };
46693
47158
  /* end_public_function */
46694
47159
 
47160
+ class EventPaginationController extends PaginationController {
47161
+ async getRequest(queryParams, token) {
47162
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
47163
+ const options = token ? { token } : { limit };
47164
+ const { data: response } = await this.http.get(`/api/v1/events`, { params: Object.assign(Object.assign({}, params), { options }) });
47165
+ return response;
47166
+ }
47167
+ }
47168
+
47169
+ class EventQueryStreamController extends QueryStreamController {
47170
+ constructor(query, cacheKey, notifyChange, preparePayload) {
47171
+ super(query, cacheKey);
47172
+ this.notifyChange = notifyChange;
47173
+ this.preparePayload = preparePayload;
47174
+ }
47175
+ async saveToMainDB(response) {
47176
+ const processedPayload = this.preparePayload(response);
47177
+ const client = getActiveClient();
47178
+ const cachedAt = client.cache && Date.now();
47179
+ if (client.cache)
47180
+ ingestInCache(processedPayload, { cachedAt });
47181
+ }
47182
+ appendToQueryStream(response, direction, refresh = false) {
47183
+ var _a, _b;
47184
+ if (refresh) {
47185
+ pushToCache(this.cacheKey, { data: response.events.map(getResolver('event')) });
47186
+ }
47187
+ else {
47188
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
47189
+ const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
47190
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...events, ...response.events.map(getResolver('event'))])] }));
47191
+ }
47192
+ }
47193
+ reactor(action) {
47194
+ return (event) => {
47195
+ var _a;
47196
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
47197
+ if (!collection)
47198
+ return;
47199
+ if (action === EventActionsEnum.OnEventCreated) {
47200
+ collection.data = [...new Set([event.eventId, ...collection.data])];
47201
+ }
47202
+ if (action === EventActionsEnum.OnEventDeleted) {
47203
+ collection.data = collection.data.filter(eventId => eventId !== event.eventId);
47204
+ }
47205
+ pushToCache(this.cacheKey, collection);
47206
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
47207
+ };
47208
+ }
47209
+ subscribeRTE(createSubscriber) {
47210
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
47211
+ }
47212
+ }
47213
+
47214
+ class EventLiveCollectionController extends LiveCollectionController {
47215
+ constructor(query, callback) {
47216
+ const queryStreamId = hash(query);
47217
+ const cacheKey = ['event', 'collection', queryStreamId];
47218
+ const paginationController = new EventPaginationController(query);
47219
+ super(paginationController, queryStreamId, cacheKey, callback);
47220
+ this.query = query;
47221
+ this.queryStreamController = new EventQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventPayload);
47222
+ this.callback = callback.bind(this);
47223
+ this.loadPage({ initial: true });
47224
+ }
47225
+ setup() {
47226
+ var _a;
47227
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
47228
+ if (!collection)
47229
+ pushToCache(this.cacheKey, { data: [], params: {} });
47230
+ }
47231
+ async persistModel(queryPayload) {
47232
+ await this.queryStreamController.saveToMainDB(queryPayload);
47233
+ }
47234
+ persistQueryStream({ response, direction, refresh, }) {
47235
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
47236
+ }
47237
+ startSubscription() {
47238
+ return this.queryStreamController.subscribeRTE([
47239
+ { fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
47240
+ { fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
47241
+ { fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
47242
+ { fn: onLocalEventCreated, action: EventActionsEnum.OnEventCreated },
47243
+ { fn: onLocalEventUpdated, action: EventActionsEnum.OnEventUpdated },
47244
+ { fn: onLocalEventDeleted, action: EventActionsEnum.OnEventDeleted },
47245
+ ]);
47246
+ }
47247
+ notifyChange({ origin, loading, error }) {
47248
+ var _a, _b;
47249
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
47250
+ if (!collection)
47251
+ return;
47252
+ const data = ((_b = collection.data
47253
+ .map(eventId => pullFromCache(['event', 'get', eventId]))
47254
+ .filter(isNonNullable)
47255
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
47256
+ if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
47257
+ return;
47258
+ this.callback({
47259
+ data,
47260
+ error,
47261
+ loading,
47262
+ hasNextPage: !!this.paginationController.getNextToken(),
47263
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
47264
+ });
47265
+ }
47266
+ }
47267
+
47268
+ /**
47269
+ * Get events
47270
+ *
47271
+ * @param params the query parameters
47272
+ * @param callback the callback to be called when the events are updated
47273
+ * @returns events
47274
+ *
47275
+ * @category Event Live Collection
47276
+ *
47277
+ */
47278
+ const getEvents = (params, callback, config) => {
47279
+ const { log, cache } = getActiveClient();
47280
+ if (!cache)
47281
+ console.log(ENABLE_CACHE_MESSAGE);
47282
+ const timestamp = Date.now();
47283
+ log(`getEvents: (tmpid: ${timestamp}) > listen`);
47284
+ const eventLiveCollection = new EventLiveCollectionController(params, callback);
47285
+ const disposers = eventLiveCollection.startSubscription();
47286
+ const cacheKey = eventLiveCollection.getCacheKey();
47287
+ disposers.push(() => dropFromCache(cacheKey));
47288
+ return () => {
47289
+ log(`getEvents (tmpid: ${timestamp}) > dispose`);
47290
+ disposers.forEach(fn => fn());
47291
+ };
47292
+ };
47293
+
47294
+ class MyEventPaginationController extends PaginationController {
47295
+ async getRequest(queryParams, token) {
47296
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
47297
+ const options = token ? { token } : { limit };
47298
+ const { data: response } = await this.http.get(`/api/v1/events/me/rsvps`, { params: Object.assign(Object.assign({}, params), { options }) });
47299
+ return response;
47300
+ }
47301
+ }
47302
+
47303
+ class MyEventQueryStreamController extends QueryStreamController {
47304
+ constructor(query, cacheKey, notifyChange, preparePayload) {
47305
+ super(query, cacheKey);
47306
+ this.notifyChange = notifyChange;
47307
+ this.preparePayload = preparePayload;
47308
+ }
47309
+ async saveToMainDB(response) {
47310
+ const processedPayload = this.preparePayload(response);
47311
+ const client = getActiveClient();
47312
+ const cachedAt = client.cache && Date.now();
47313
+ if (client.cache)
47314
+ ingestInCache(processedPayload, { cachedAt });
47315
+ }
47316
+ appendToQueryStream(response, direction, refresh = false) {
47317
+ var _a, _b;
47318
+ if (refresh) {
47319
+ pushToCache(this.cacheKey, { data: response.events.map(getResolver('event')) });
47320
+ }
47321
+ else {
47322
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
47323
+ const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
47324
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...events, ...response.events.map(getResolver('event'))])] }));
47325
+ }
47326
+ }
47327
+ reactor(action) {
47328
+ return (event) => {
47329
+ var _a;
47330
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
47331
+ if (!collection)
47332
+ return;
47333
+ if (action === EventActionsEnum.OnEventCreated) {
47334
+ const client = getActiveClient();
47335
+ if (client.userId !== event.userId)
47336
+ return;
47337
+ collection.data = [...new Set([event.eventId, ...collection.data])];
47338
+ }
47339
+ if (action === EventActionsEnum.OnEventDeleted) {
47340
+ collection.data = collection.data.filter(eventId => eventId !== event.eventId);
47341
+ }
47342
+ pushToCache(this.cacheKey, collection);
47343
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
47344
+ };
47345
+ }
47346
+ subscribeRTE(createSubscriber) {
47347
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
47348
+ }
47349
+ }
47350
+
47351
+ class MyEventLiveCollectionController extends LiveCollectionController {
47352
+ constructor(query, callback) {
47353
+ const queryStreamId = hash(query);
47354
+ const cacheKey = ['event', 'collection', queryStreamId];
47355
+ const paginationController = new MyEventPaginationController(query);
47356
+ super(paginationController, queryStreamId, cacheKey, callback);
47357
+ this.query = query;
47358
+ this.queryStreamController = new MyEventQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventPayload);
47359
+ this.callback = callback.bind(this);
47360
+ this.loadPage({ initial: true });
47361
+ }
47362
+ setup() {
47363
+ var _a;
47364
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
47365
+ if (!collection)
47366
+ pushToCache(this.cacheKey, { data: [], params: {} });
47367
+ }
47368
+ async persistModel(queryPayload) {
47369
+ await this.queryStreamController.saveToMainDB(queryPayload);
47370
+ }
47371
+ persistQueryStream({ response, direction, refresh, }) {
47372
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
47373
+ }
47374
+ startSubscription() {
47375
+ return this.queryStreamController.subscribeRTE([
47376
+ { fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
47377
+ { fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
47378
+ { fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
47379
+ { fn: onLocalEventCreated, action: EventActionsEnum.OnEventCreated },
47380
+ { fn: onLocalEventUpdated, action: EventActionsEnum.OnEventUpdated },
47381
+ { fn: onLocalEventDeleted, action: EventActionsEnum.OnEventDeleted },
47382
+ ]);
47383
+ }
47384
+ notifyChange({ origin, loading, error }) {
47385
+ var _a, _b;
47386
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
47387
+ if (!collection)
47388
+ return;
47389
+ const data = ((_b = collection.data
47390
+ .map(eventId => pullFromCache(['event', 'get', eventId]))
47391
+ .filter(isNonNullable)
47392
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
47393
+ if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
47394
+ return;
47395
+ this.callback({
47396
+ data,
47397
+ error,
47398
+ loading,
47399
+ hasNextPage: !!this.paginationController.getNextToken(),
47400
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
47401
+ });
47402
+ }
47403
+ }
47404
+
47405
+ /**
47406
+ * Get my events
47407
+ *
47408
+ * @param params the query parameters
47409
+ * @param callback the callback to be called when the events are updated
47410
+ * @returns events
47411
+ *
47412
+ * @category Event Live Collection
47413
+ *
47414
+ */
47415
+ const getMyEvents = (params, callback, config) => {
47416
+ const { log, cache } = getActiveClient();
47417
+ if (!cache)
47418
+ console.log(ENABLE_CACHE_MESSAGE);
47419
+ const timestamp = Date.now();
47420
+ log(`getMyEvents: (tmpid: ${timestamp}) > listen`);
47421
+ const myEventLiveCollection = new MyEventLiveCollectionController(params, callback);
47422
+ const disposers = myEventLiveCollection.startSubscription();
47423
+ const cacheKey = myEventLiveCollection.getCacheKey();
47424
+ disposers.push(() => dropFromCache(cacheKey));
47425
+ return () => {
47426
+ log(`getMyEvents (tmpid: ${timestamp}) > dispose`);
47427
+ disposers.forEach(fn => fn());
47428
+ };
47429
+ };
47430
+
46695
47431
  var index = /*#__PURE__*/Object.freeze({
46696
47432
  __proto__: null,
46697
47433
  createEvent: createEvent,
@@ -46700,7 +47436,17 @@ var index = /*#__PURE__*/Object.freeze({
46700
47436
  onEventCreated: onEventCreated,
46701
47437
  onEventUpdated: onEventUpdated,
46702
47438
  onEventDeleted: onEventDeleted,
46703
- getEvent: getEvent
47439
+ onLocalEventCreated: onLocalEventCreated,
47440
+ onLocalEventUpdated: onLocalEventUpdated,
47441
+ onLocalEventDeleted: onLocalEventDeleted,
47442
+ onRSVPCreated: onRSVPCreated,
47443
+ onRSVPUpdated: onRSVPUpdated,
47444
+ onLocalRSVPCreated: onLocalRSVPCreated,
47445
+ onLocalRSVPUpdated: onLocalRSVPUpdated,
47446
+ getEvent: getEvent,
47447
+ getEvents: getEvents,
47448
+ getMyEvents: getMyEvents,
47449
+ getRSVPs: getRSVPs
46704
47450
  });
46705
47451
 
46706
- export { API_REGIONS, index$4 as AdRepository, AmityEventOriginType, AmityEventStatus, AmityEventType, index$c as CategoryRepository, index$g as ChannelRepository, index$p as Client, index$b as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$d as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, index as EventRepository, FeedDataTypeEnum, index$a as FeedRepository, FeedSortByEnum, FeedSourceEnum, FileAccessTypeEnum, index$m as FileRepository, FileType, GET_WATCHER_URLS, index$2 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index$1 as LiveReactionRepository, index$6 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$k as MessageRepository, index$7 as PollRepository, PostContentType, index$9 as PostRepository, PostStructureType, index$l as ReactionRepository, index$5 as StoryRepository, index$8 as StreamRepository, index$j as SubChannelRepository, SubscriptionLevels, index$n as UserRepository, UserTypeEnum, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveReactionTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$3 as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };
47452
+ export { API_REGIONS, index$4 as AdRepository, AmityEventOriginType, AmityEventResponseStatus, AmityEventStatus, AmityEventType, index$c as CategoryRepository, index$g as ChannelRepository, index$p as Client, index$b as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$d as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, index as EventRepository, FeedDataTypeEnum, index$a as FeedRepository, FeedSortByEnum, FeedSourceEnum, FileAccessTypeEnum, index$m as FileRepository, FileType, GET_WATCHER_URLS, index$2 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index$1 as LiveReactionRepository, index$6 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$k as MessageRepository, index$7 as PollRepository, PostContentType, index$9 as PostRepository, PostStructureType, index$l as ReactionRepository, index$5 as StoryRepository, index$8 as StreamRepository, index$j as SubChannelRepository, SubscriptionLevels, index$n as UserRepository, UserTypeEnum, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveReactionTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$3 as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };