@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.
- package/dist/@types/core/events.d.ts +4 -0
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/model.d.ts +4 -0
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +15 -0
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/core/permissions.d.ts +5 -1
- package/dist/@types/core/permissions.d.ts.map +1 -1
- package/dist/@types/domains/community.d.ts +11 -1
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/@types/domains/event.d.ts +61 -9
- package/dist/@types/domains/event.d.ts.map +1 -1
- package/dist/@types/domains/notification.d.ts +3 -1
- package/dist/@types/domains/notification.d.ts.map +1 -1
- package/dist/@types/domains/partials.d.ts +2 -2
- package/dist/@types/domains/partials.d.ts.map +1 -1
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.d.ts.map +1 -1
- package/dist/core/model/idResolvers.d.ts.map +1 -1
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/eventRepository/events/enums.d.ts +8 -0
- package/dist/eventRepository/events/enums.d.ts.map +1 -0
- package/dist/eventRepository/events/index.d.ts +7 -0
- package/dist/eventRepository/events/index.d.ts.map +1 -1
- package/dist/eventRepository/events/onLocalEventCreated.d.ts +17 -0
- package/dist/eventRepository/events/onLocalEventCreated.d.ts.map +1 -0
- package/dist/eventRepository/events/onLocalEventDeleted.d.ts +17 -0
- package/dist/eventRepository/events/onLocalEventDeleted.d.ts.map +1 -0
- package/dist/eventRepository/events/onLocalEventUpdated.d.ts +17 -0
- package/dist/eventRepository/events/onLocalEventUpdated.d.ts.map +1 -0
- package/dist/eventRepository/events/onLocalRSVPCreated.d.ts +17 -0
- package/dist/eventRepository/events/onLocalRSVPCreated.d.ts.map +1 -0
- package/dist/eventRepository/events/onLocalRSVPUpdated.d.ts +17 -0
- package/dist/eventRepository/events/onLocalRSVPUpdated.d.ts.map +1 -0
- package/dist/eventRepository/events/onRSVPCreated.d.ts +17 -0
- package/dist/eventRepository/events/onRSVPCreated.d.ts.map +1 -0
- package/dist/eventRepository/events/onRSVPUpdated.d.ts +17 -0
- package/dist/eventRepository/events/onRSVPUpdated.d.ts.map +1 -0
- package/dist/eventRepository/internalApi/createRSVP.d.ts +16 -0
- package/dist/eventRepository/internalApi/createRSVP.d.ts.map +1 -0
- package/dist/eventRepository/internalApi/getMyRSVP.d.ts +32 -0
- package/dist/eventRepository/internalApi/getMyRSVP.d.ts.map +1 -0
- package/dist/eventRepository/internalApi/index.d.ts +3 -0
- package/dist/eventRepository/internalApi/index.d.ts.map +1 -1
- package/dist/eventRepository/internalApi/updateRSVP.d.ts +17 -0
- package/dist/eventRepository/internalApi/updateRSVP.d.ts.map +1 -0
- package/dist/eventRepository/observers/getEvent.d.ts.map +1 -1
- package/dist/eventRepository/observers/getEvents/LiveCollectionController.d.ts +13 -0
- package/dist/eventRepository/observers/getEvents/LiveCollectionController.d.ts.map +1 -0
- package/dist/eventRepository/observers/getEvents/PaginationController.d.ts +5 -0
- package/dist/eventRepository/observers/getEvents/PaginationController.d.ts.map +1 -0
- package/dist/eventRepository/observers/getEvents/QueryStreamController.d.ts +15 -0
- package/dist/eventRepository/observers/getEvents/QueryStreamController.d.ts.map +1 -0
- package/dist/eventRepository/observers/getEvents.d.ts +12 -0
- package/dist/eventRepository/observers/getEvents.d.ts.map +1 -0
- package/dist/eventRepository/observers/getMyEvents/LiveCollectionController.d.ts +13 -0
- package/dist/eventRepository/observers/getMyEvents/LiveCollectionController.d.ts.map +1 -0
- package/dist/eventRepository/observers/getMyEvents/PaginationController.d.ts +5 -0
- package/dist/eventRepository/observers/getMyEvents/PaginationController.d.ts.map +1 -0
- package/dist/eventRepository/observers/getMyEvents/QueryStreamController.d.ts +15 -0
- package/dist/eventRepository/observers/getMyEvents/QueryStreamController.d.ts.map +1 -0
- package/dist/eventRepository/observers/getMyEvents.d.ts +12 -0
- package/dist/eventRepository/observers/getMyEvents.d.ts.map +1 -0
- package/dist/eventRepository/observers/getRSVPs/LiveCollectionController.d.ts +13 -0
- package/dist/eventRepository/observers/getRSVPs/LiveCollectionController.d.ts.map +1 -0
- package/dist/eventRepository/observers/getRSVPs/PaginationController.d.ts +5 -0
- package/dist/eventRepository/observers/getRSVPs/PaginationController.d.ts.map +1 -0
- package/dist/eventRepository/observers/getRSVPs/QueryStreamController.d.ts +15 -0
- package/dist/eventRepository/observers/getRSVPs/QueryStreamController.d.ts.map +1 -0
- package/dist/eventRepository/observers/getRSVPs.d.ts +12 -0
- package/dist/eventRepository/observers/getRSVPs.d.ts.map +1 -0
- package/dist/eventRepository/observers/index.d.ts +3 -0
- package/dist/eventRepository/observers/index.d.ts.map +1 -1
- package/dist/eventRepository/utils/createEventEventSubscriber.d.ts +1 -1
- package/dist/eventRepository/utils/createEventEventSubscriber.d.ts.map +1 -1
- package/dist/eventRepository/utils/createEventResponseSubscriber.d.ts +2 -0
- package/dist/eventRepository/utils/createEventResponseSubscriber.d.ts.map +1 -0
- package/dist/eventRepository/utils/index.d.ts +2 -0
- package/dist/eventRepository/utils/index.d.ts.map +1 -1
- package/dist/eventRepository/utils/prepareEventResponsePayload.d.ts +2 -0
- package/dist/eventRepository/utils/prepareEventResponsePayload.d.ts.map +1 -0
- package/dist/index.cjs.js +835 -89
- package/dist/index.esm.js +831 -85
- package/dist/index.umd.js +3 -3
- package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts +1 -1
- package/dist/utils/linkedObject/eventLinkObject.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -209,6 +209,11 @@ exports.AmityEventStatus = void 0;
|
|
|
209
209
|
AmityEventStatus["Ended"] = "ended";
|
|
210
210
|
AmityEventStatus["Cancelled"] = "cancelled";
|
|
211
211
|
})(exports.AmityEventStatus || (exports.AmityEventStatus = {}));
|
|
212
|
+
exports.AmityEventResponseStatus = void 0;
|
|
213
|
+
(function (AmityEventResponseStatus) {
|
|
214
|
+
AmityEventResponseStatus["Going"] = "going";
|
|
215
|
+
AmityEventResponseStatus["NotGoing"] = "not_going";
|
|
216
|
+
})(exports.AmityEventResponseStatus || (exports.AmityEventResponseStatus = {}));
|
|
212
217
|
|
|
213
218
|
function getVersion() {
|
|
214
219
|
try {
|
|
@@ -658,6 +663,9 @@ const idResolvers = {
|
|
|
658
663
|
notificationTraySeen: ({ userId }) => userId,
|
|
659
664
|
invitation: ({ _id }) => _id,
|
|
660
665
|
joinRequest: ({ joinRequestId }) => joinRequestId,
|
|
666
|
+
event: ({ eventId }) => eventId,
|
|
667
|
+
eventResponse: ({ eventId }) => eventId,
|
|
668
|
+
discussionCommunity: ({ communityId }) => communityId,
|
|
661
669
|
};
|
|
662
670
|
/**
|
|
663
671
|
* Retrieve the id resolver matching a domain name
|
|
@@ -713,6 +721,9 @@ const PAYLOAD2MODEL = {
|
|
|
713
721
|
notificationTrayItems: 'notificationTrayItem',
|
|
714
722
|
invitations: 'invitation',
|
|
715
723
|
joinRequests: 'joinRequest',
|
|
724
|
+
events: 'event',
|
|
725
|
+
eventResponses: 'eventResponse',
|
|
726
|
+
discussionCommunities: 'discussionCommunity',
|
|
716
727
|
};
|
|
717
728
|
/** hidden */
|
|
718
729
|
const isOutdated = (prevData, nextData) => {
|
|
@@ -13676,6 +13687,504 @@ const communityLinkedObject = (community) => {
|
|
|
13676
13687
|
} });
|
|
13677
13688
|
};
|
|
13678
13689
|
|
|
13690
|
+
const prepareEventResponsePayload = (rawPayload) => {
|
|
13691
|
+
return {
|
|
13692
|
+
respondedAt: rawPayload.eventResponses[0].respondedAt,
|
|
13693
|
+
status: rawPayload.eventResponses[0].status,
|
|
13694
|
+
eventId: rawPayload.eventResponses[0].eventId,
|
|
13695
|
+
event: rawPayload.events,
|
|
13696
|
+
userId: rawPayload.eventResponses[0].userId,
|
|
13697
|
+
user: rawPayload.users.map(convertRawUserToInternalUser),
|
|
13698
|
+
};
|
|
13699
|
+
};
|
|
13700
|
+
|
|
13701
|
+
/* begin_public_function
|
|
13702
|
+
id: event.rsvp.create
|
|
13703
|
+
*/
|
|
13704
|
+
/**
|
|
13705
|
+
* ```js
|
|
13706
|
+
* import { event } from '@amityco/ts-sdk'
|
|
13707
|
+
* const response = await event.createRSVP(eventId, status)
|
|
13708
|
+
* ```
|
|
13709
|
+
*
|
|
13710
|
+
* Creates an {@link Amity.InternalEvent}
|
|
13711
|
+
*
|
|
13712
|
+
* @param bundle The data necessary to create a new {@link Amity.InternalEvent}
|
|
13713
|
+
* @returns The newly created {@link Amity.InternalEvent}
|
|
13714
|
+
*
|
|
13715
|
+
* @category Event API
|
|
13716
|
+
* @async
|
|
13717
|
+
*/
|
|
13718
|
+
const createRSVP = async (eventId, status) => {
|
|
13719
|
+
const client = getActiveClient();
|
|
13720
|
+
client.log('event/createRSVP', eventId, status);
|
|
13721
|
+
const { data: payload } = await client.http.post(`/api/v1/events/${eventId}/rsvp`, { status });
|
|
13722
|
+
fireEvent('local.rsvp.created', payload);
|
|
13723
|
+
const data = prepareEventResponsePayload(payload);
|
|
13724
|
+
const cachedAt = client.cache && Date.now();
|
|
13725
|
+
if (client.cache)
|
|
13726
|
+
ingestInCache({ eventResponses: [data] }, { cachedAt });
|
|
13727
|
+
return {
|
|
13728
|
+
data,
|
|
13729
|
+
cachedAt,
|
|
13730
|
+
};
|
|
13731
|
+
};
|
|
13732
|
+
/* end_public_function */
|
|
13733
|
+
|
|
13734
|
+
/* begin_public_function
|
|
13735
|
+
id: event.update
|
|
13736
|
+
*/
|
|
13737
|
+
/**
|
|
13738
|
+
* ```js
|
|
13739
|
+
* import { event } from '@amityco/ts-sdk'
|
|
13740
|
+
* const response = await event.updateRSVP(eventId, status)
|
|
13741
|
+
* ```
|
|
13742
|
+
*
|
|
13743
|
+
* Updates an {@link Amity.EventResponse}
|
|
13744
|
+
*
|
|
13745
|
+
* @param eventId The ID of the {@link Amity.EventResponse} to edit
|
|
13746
|
+
* @param bundle The data necessary to update an existing {@link Amity.EventResponse}
|
|
13747
|
+
* @returns the updated {@link Amity.EventResponse}
|
|
13748
|
+
*
|
|
13749
|
+
* @category Event API
|
|
13750
|
+
* @async
|
|
13751
|
+
*/
|
|
13752
|
+
const updateRSVP = async (eventId, status) => {
|
|
13753
|
+
const client = getActiveClient();
|
|
13754
|
+
client.log('event/updateRSVP', eventId, status);
|
|
13755
|
+
const { data: payload } = await client.http.put(`/api/v1/events/${eventId}/rsvp`, { status });
|
|
13756
|
+
fireEvent('local.rsvp.updated', payload);
|
|
13757
|
+
const data = prepareEventResponsePayload(payload);
|
|
13758
|
+
const cachedAt = client.cache && Date.now();
|
|
13759
|
+
if (client.cache)
|
|
13760
|
+
ingestInCache({ eventResponses: [data] }, { cachedAt });
|
|
13761
|
+
return {
|
|
13762
|
+
data,
|
|
13763
|
+
cachedAt,
|
|
13764
|
+
};
|
|
13765
|
+
};
|
|
13766
|
+
/* end_public_function */
|
|
13767
|
+
|
|
13768
|
+
const prepareEventPayload = (rawPayload) => {
|
|
13769
|
+
return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser) });
|
|
13770
|
+
};
|
|
13771
|
+
|
|
13772
|
+
const createEventEventSubscriber = (event, callback) => {
|
|
13773
|
+
const client = getActiveClient();
|
|
13774
|
+
const filter = (payload) => {
|
|
13775
|
+
const unpackedPayload = prepareEventPayload(payload);
|
|
13776
|
+
if (!client.cache) {
|
|
13777
|
+
callback(unpackedPayload.events[0]);
|
|
13778
|
+
}
|
|
13779
|
+
else {
|
|
13780
|
+
ingestInCache(unpackedPayload);
|
|
13781
|
+
const event = pullFromCache([
|
|
13782
|
+
'event',
|
|
13783
|
+
'get',
|
|
13784
|
+
unpackedPayload.events[0].eventId,
|
|
13785
|
+
]);
|
|
13786
|
+
callback(event.data);
|
|
13787
|
+
}
|
|
13788
|
+
};
|
|
13789
|
+
return createEventSubscriber(client, event, event, filter);
|
|
13790
|
+
};
|
|
13791
|
+
|
|
13792
|
+
const createEventResponseSubscriber = (event, callback) => {
|
|
13793
|
+
const client = getActiveClient();
|
|
13794
|
+
const filter = (payload) => {
|
|
13795
|
+
const unpackedPayload = prepareEventResponsePayload(payload);
|
|
13796
|
+
if (!client.cache) {
|
|
13797
|
+
callback(unpackedPayload);
|
|
13798
|
+
}
|
|
13799
|
+
else {
|
|
13800
|
+
ingestInCache(unpackedPayload.event[0]);
|
|
13801
|
+
const eventResponse = pullFromCache([
|
|
13802
|
+
'eventResponse',
|
|
13803
|
+
'get',
|
|
13804
|
+
payload.eventResponses[0].eventId,
|
|
13805
|
+
]);
|
|
13806
|
+
callback(eventResponse.data);
|
|
13807
|
+
}
|
|
13808
|
+
};
|
|
13809
|
+
return createEventSubscriber(client, event, event, filter);
|
|
13810
|
+
};
|
|
13811
|
+
|
|
13812
|
+
/* begin_public_function
|
|
13813
|
+
id: event.rsvp.me
|
|
13814
|
+
*/
|
|
13815
|
+
/**
|
|
13816
|
+
* ```js
|
|
13817
|
+
* import { event } from '@amityco/ts-sdk'
|
|
13818
|
+
* const myRSVP = await event.getMyRSVP()
|
|
13819
|
+
* ```
|
|
13820
|
+
*
|
|
13821
|
+
* Joins a {@link Amity.EventResponse} object
|
|
13822
|
+
*
|
|
13823
|
+
* @param eventId the {@link Amity.EventResponse} to get RSVP for
|
|
13824
|
+
* @returns A success boolean if the {@link Amity.EventResponse} RSVP was retrieved
|
|
13825
|
+
*
|
|
13826
|
+
* @category Event API
|
|
13827
|
+
* @async
|
|
13828
|
+
*/
|
|
13829
|
+
const getMyRSVP = async (eventId) => {
|
|
13830
|
+
const client = getActiveClient();
|
|
13831
|
+
client.log('event/getMyRSVP', eventId);
|
|
13832
|
+
const { data: payload } = await client.http.get(`/api/v1/events/${eventId}/me/rsvp`);
|
|
13833
|
+
const data = prepareEventResponsePayload(payload);
|
|
13834
|
+
const cachedAt = client.cache && Date.now();
|
|
13835
|
+
if (client.cache)
|
|
13836
|
+
ingestInCache({ eventResponses: [data] }, { cachedAt });
|
|
13837
|
+
return {
|
|
13838
|
+
data,
|
|
13839
|
+
cachedAt,
|
|
13840
|
+
};
|
|
13841
|
+
};
|
|
13842
|
+
/* end_public_function */
|
|
13843
|
+
/**
|
|
13844
|
+
* ```js
|
|
13845
|
+
* import { event } from '@amityco/ts-sdk'
|
|
13846
|
+
* const event = event.getMyRSVP.locally(eventId)
|
|
13847
|
+
* ```
|
|
13848
|
+
*
|
|
13849
|
+
* Fetches a {@link Amity.EventResponse} object in cache
|
|
13850
|
+
*
|
|
13851
|
+
* @param eventId the ID of the {@link Amity.EventResponse} to fetch
|
|
13852
|
+
* @returns the associated {@link Amity.EventResponse} object
|
|
13853
|
+
*
|
|
13854
|
+
* @category Event API
|
|
13855
|
+
*/
|
|
13856
|
+
getMyRSVP.locally = (eventId) => {
|
|
13857
|
+
const client = getActiveClient();
|
|
13858
|
+
client.log('event/getMyRSVP.locally', eventId);
|
|
13859
|
+
if (!client.cache)
|
|
13860
|
+
return;
|
|
13861
|
+
const cache = pullFromCache(['event', 'getMyRSVP', eventId]);
|
|
13862
|
+
if (!cache)
|
|
13863
|
+
return;
|
|
13864
|
+
return {
|
|
13865
|
+
data: cache.data,
|
|
13866
|
+
cachedAt: cache.cachedAt,
|
|
13867
|
+
};
|
|
13868
|
+
};
|
|
13869
|
+
|
|
13870
|
+
var EventActionsEnum;
|
|
13871
|
+
(function (EventActionsEnum) {
|
|
13872
|
+
EventActionsEnum["OnEventCreated"] = "onEventCreated";
|
|
13873
|
+
EventActionsEnum["OnEventUpdated"] = "onEventUpdated";
|
|
13874
|
+
EventActionsEnum["OnEventDeleted"] = "onEventDeleted";
|
|
13875
|
+
EventActionsEnum["OnRSVPCreated"] = "onRSVPCreated";
|
|
13876
|
+
EventActionsEnum["OnRSVPUpdated"] = "onRSVPUpdated";
|
|
13877
|
+
})(EventActionsEnum || (EventActionsEnum = {}));
|
|
13878
|
+
|
|
13879
|
+
class RSVPPaginationController extends PaginationController {
|
|
13880
|
+
async getRequest(queryParams, token) {
|
|
13881
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, eventId } = queryParams, params = __rest(queryParams, ["limit", "eventId"]);
|
|
13882
|
+
const options = token ? { token } : { limit };
|
|
13883
|
+
const { data: response } = await this.http.get(`/api/v1/events/${eventId}/rsvp`, { params: Object.assign(Object.assign({}, params), { options }) });
|
|
13884
|
+
return response;
|
|
13885
|
+
}
|
|
13886
|
+
}
|
|
13887
|
+
|
|
13888
|
+
class RSVPQueryStreamController extends QueryStreamController {
|
|
13889
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
13890
|
+
super(query, cacheKey);
|
|
13891
|
+
this.notifyChange = notifyChange;
|
|
13892
|
+
this.preparePayload = preparePayload;
|
|
13893
|
+
}
|
|
13894
|
+
async saveToMainDB(response) {
|
|
13895
|
+
const processedPayload = this.preparePayload(response);
|
|
13896
|
+
const client = getActiveClient();
|
|
13897
|
+
const cachedAt = client.cache && Date.now();
|
|
13898
|
+
if (client.cache)
|
|
13899
|
+
ingestInCache({ eventResponses: [processedPayload] }, { cachedAt });
|
|
13900
|
+
}
|
|
13901
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
13902
|
+
var _a, _b;
|
|
13903
|
+
if (refresh) {
|
|
13904
|
+
pushToCache(this.cacheKey, {
|
|
13905
|
+
data: response.eventResponses.map(getResolver('eventResponse')),
|
|
13906
|
+
});
|
|
13907
|
+
}
|
|
13908
|
+
else {
|
|
13909
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
13910
|
+
const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
13911
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
13912
|
+
...new Set([...events, ...response.eventResponses.map(getResolver('eventResponse'))]),
|
|
13913
|
+
] }));
|
|
13914
|
+
}
|
|
13915
|
+
}
|
|
13916
|
+
reactor(action) {
|
|
13917
|
+
return (event) => {
|
|
13918
|
+
var _a;
|
|
13919
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
13920
|
+
if (!collection)
|
|
13921
|
+
return;
|
|
13922
|
+
if (action === EventActionsEnum.OnRSVPCreated) {
|
|
13923
|
+
const client = getActiveClient();
|
|
13924
|
+
if (client.userId !== event.userId)
|
|
13925
|
+
return;
|
|
13926
|
+
collection.data = [...new Set([event.eventId, ...collection.data])];
|
|
13927
|
+
}
|
|
13928
|
+
if (action === EventActionsEnum.OnEventDeleted) {
|
|
13929
|
+
collection.data = collection.data.filter(eventId => eventId !== event.eventId);
|
|
13930
|
+
}
|
|
13931
|
+
pushToCache(this.cacheKey, collection);
|
|
13932
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
13933
|
+
};
|
|
13934
|
+
}
|
|
13935
|
+
subscribeRTE(createSubscriber) {
|
|
13936
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
13937
|
+
}
|
|
13938
|
+
}
|
|
13939
|
+
|
|
13940
|
+
/**
|
|
13941
|
+
* ```js
|
|
13942
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
13943
|
+
* const dispose = EventRepository.onEventCreated(event => {
|
|
13944
|
+
* // ...
|
|
13945
|
+
* })
|
|
13946
|
+
* ```
|
|
13947
|
+
*
|
|
13948
|
+
* Fired when a {@link Amity.Event} has been created
|
|
13949
|
+
*
|
|
13950
|
+
* @param callback The function to call when the event was fired
|
|
13951
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
13952
|
+
*
|
|
13953
|
+
* @category Event Events
|
|
13954
|
+
*/
|
|
13955
|
+
const onEventCreated = (callback) => createEventEventSubscriber('event.created', callback);
|
|
13956
|
+
|
|
13957
|
+
/**
|
|
13958
|
+
* ```js
|
|
13959
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
13960
|
+
* const dispose = EventRepository.onEventUpdated(event => {
|
|
13961
|
+
* // ...
|
|
13962
|
+
* })
|
|
13963
|
+
* ```
|
|
13964
|
+
*
|
|
13965
|
+
* Fired when a {@link Amity.Event} has been updated
|
|
13966
|
+
*
|
|
13967
|
+
* @param callback The function to call when the event was fired
|
|
13968
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
13969
|
+
*
|
|
13970
|
+
* @category Event Events
|
|
13971
|
+
*/
|
|
13972
|
+
const onEventUpdated = (callback) => createEventEventSubscriber('event.updated', callback);
|
|
13973
|
+
|
|
13974
|
+
/**
|
|
13975
|
+
* ```js
|
|
13976
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
13977
|
+
* const dispose = EventRepository.onEventDeleted(event => {
|
|
13978
|
+
* // ...
|
|
13979
|
+
* })
|
|
13980
|
+
* ```
|
|
13981
|
+
*
|
|
13982
|
+
* Fired when a {@link Amity.Event} has been deleted
|
|
13983
|
+
*
|
|
13984
|
+
* @param callback The function to call when the event was fired
|
|
13985
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
13986
|
+
*
|
|
13987
|
+
* @category Event Events
|
|
13988
|
+
*/
|
|
13989
|
+
const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted', callback);
|
|
13990
|
+
|
|
13991
|
+
/**
|
|
13992
|
+
* ```js
|
|
13993
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
13994
|
+
* const dispose = EventRepository.onLocalEventCreated(event => {
|
|
13995
|
+
* // ...
|
|
13996
|
+
* })
|
|
13997
|
+
* ```
|
|
13998
|
+
*
|
|
13999
|
+
* Fired when a {@link Amity.Event} has been created
|
|
14000
|
+
*
|
|
14001
|
+
* @param callback The function to call when the event was fired
|
|
14002
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
14003
|
+
*
|
|
14004
|
+
* @category Event Events
|
|
14005
|
+
*/
|
|
14006
|
+
const onLocalEventCreated = (callback) => createEventEventSubscriber('local.event.created', callback);
|
|
14007
|
+
|
|
14008
|
+
/**
|
|
14009
|
+
* ```js
|
|
14010
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
14011
|
+
* const dispose = EventRepository.onLocalEventUpdated(event => {
|
|
14012
|
+
* // ...
|
|
14013
|
+
* })
|
|
14014
|
+
* ```
|
|
14015
|
+
*
|
|
14016
|
+
* Fired when a {@link Amity.Event} has been updated
|
|
14017
|
+
*
|
|
14018
|
+
* @param callback The function to call when the event was fired
|
|
14019
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
14020
|
+
*
|
|
14021
|
+
* @category Event Events
|
|
14022
|
+
*/
|
|
14023
|
+
const onLocalEventUpdated = (callback) => createEventEventSubscriber('local.event.updated', callback);
|
|
14024
|
+
|
|
14025
|
+
/**
|
|
14026
|
+
* ```js
|
|
14027
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
14028
|
+
* const dispose = EventRepository.onLocalEventDeleted(event => {
|
|
14029
|
+
* // ...
|
|
14030
|
+
* })
|
|
14031
|
+
* ```
|
|
14032
|
+
*
|
|
14033
|
+
* Fired when a {@link Amity.Event} has been deleted
|
|
14034
|
+
*
|
|
14035
|
+
* @param callback The function to call when the event was fired
|
|
14036
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
14037
|
+
*
|
|
14038
|
+
* @category Event Events
|
|
14039
|
+
*/
|
|
14040
|
+
const onLocalEventDeleted = (callback) => createEventEventSubscriber('local.event.deleted', callback);
|
|
14041
|
+
|
|
14042
|
+
/**
|
|
14043
|
+
* ```js
|
|
14044
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
14045
|
+
* const dispose = EventRepository.onRSVPCreated(event => {
|
|
14046
|
+
* // ...
|
|
14047
|
+
* })
|
|
14048
|
+
* ```
|
|
14049
|
+
*
|
|
14050
|
+
* Fired when a {@link Amity.Event} has been created
|
|
14051
|
+
*
|
|
14052
|
+
* @param callback The function to call when the event was fired
|
|
14053
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
14054
|
+
*
|
|
14055
|
+
* @category Event Events
|
|
14056
|
+
*/
|
|
14057
|
+
const onRSVPCreated = (callback) => createEventResponseSubscriber('event.rsvp.created', callback);
|
|
14058
|
+
|
|
14059
|
+
/**
|
|
14060
|
+
* ```js
|
|
14061
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
14062
|
+
* const dispose = EventRepository.onRSVPUpdated(event => {
|
|
14063
|
+
* // ...
|
|
14064
|
+
* })
|
|
14065
|
+
* ```
|
|
14066
|
+
*
|
|
14067
|
+
* Fired when a {@link Amity.InternalEventResponse} has been updated
|
|
14068
|
+
*
|
|
14069
|
+
* @param callback The function to call when the event was fired
|
|
14070
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
14071
|
+
*
|
|
14072
|
+
* @category Event Events
|
|
14073
|
+
*/
|
|
14074
|
+
const onRSVPUpdated = (callback) => createEventResponseSubscriber('event.rsvp.updated', callback);
|
|
14075
|
+
|
|
14076
|
+
/**
|
|
14077
|
+
* ```js
|
|
14078
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
14079
|
+
* const dispose = EventRepository.onLocalRSVPCreated(event => {
|
|
14080
|
+
* // ...
|
|
14081
|
+
* })
|
|
14082
|
+
* ```
|
|
14083
|
+
*
|
|
14084
|
+
* Fired when a {@link Amity.Event} has been created
|
|
14085
|
+
*
|
|
14086
|
+
* @param callback The function to call when the event was fired
|
|
14087
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
14088
|
+
*
|
|
14089
|
+
* @category Event Events
|
|
14090
|
+
*/
|
|
14091
|
+
const onLocalRSVPCreated = (callback) => createEventResponseSubscriber('local.rsvp.created', callback);
|
|
14092
|
+
|
|
14093
|
+
/**
|
|
14094
|
+
* ```js
|
|
14095
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
14096
|
+
* const dispose = EventRepository.onLocalEventUpdated(event => {
|
|
14097
|
+
* // ...
|
|
14098
|
+
* })
|
|
14099
|
+
* ```
|
|
14100
|
+
*
|
|
14101
|
+
* Fired when a {@link Amity.Event} has been updated
|
|
14102
|
+
*
|
|
14103
|
+
* @param callback The function to call when the event was fired
|
|
14104
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
14105
|
+
*
|
|
14106
|
+
* @category Event Events
|
|
14107
|
+
*/
|
|
14108
|
+
const onLocalRSVPUpdated = (callback) => createEventResponseSubscriber('local.rsvp.updated', callback);
|
|
14109
|
+
|
|
14110
|
+
class RSVPLiveCollectionController extends LiveCollectionController {
|
|
14111
|
+
constructor(query, callback) {
|
|
14112
|
+
const queryStreamId = hash__default["default"](query);
|
|
14113
|
+
const cacheKey = ['eventResponse', 'collection', queryStreamId];
|
|
14114
|
+
const paginationController = new RSVPPaginationController(query);
|
|
14115
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
14116
|
+
this.query = query;
|
|
14117
|
+
this.queryStreamController = new RSVPQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventResponsePayload);
|
|
14118
|
+
this.callback = callback.bind(this);
|
|
14119
|
+
this.loadPage({ initial: true });
|
|
14120
|
+
}
|
|
14121
|
+
setup() {
|
|
14122
|
+
var _a;
|
|
14123
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
14124
|
+
if (!collection)
|
|
14125
|
+
pushToCache(this.cacheKey, { data: [], params: this.query });
|
|
14126
|
+
}
|
|
14127
|
+
async persistModel(queryPayload) {
|
|
14128
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
14129
|
+
}
|
|
14130
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
14131
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
14132
|
+
}
|
|
14133
|
+
startSubscription() {
|
|
14134
|
+
return this.queryStreamController.subscribeRTE([
|
|
14135
|
+
{ fn: onRSVPCreated, action: EventActionsEnum.OnRSVPCreated },
|
|
14136
|
+
{ fn: onRSVPUpdated, action: EventActionsEnum.OnRSVPUpdated },
|
|
14137
|
+
{ fn: onLocalRSVPCreated, action: EventActionsEnum.OnRSVPCreated },
|
|
14138
|
+
{ fn: onLocalRSVPUpdated, action: EventActionsEnum.OnRSVPUpdated },
|
|
14139
|
+
]);
|
|
14140
|
+
}
|
|
14141
|
+
notifyChange({ origin, loading, error }) {
|
|
14142
|
+
var _a, _b;
|
|
14143
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
14144
|
+
if (!collection)
|
|
14145
|
+
return;
|
|
14146
|
+
const data = (_b = collection.data
|
|
14147
|
+
.map(eventId => pullFromCache(['eventResponse', 'get', eventId]))
|
|
14148
|
+
.filter(isNonNullable)
|
|
14149
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
|
|
14150
|
+
if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
|
|
14151
|
+
return;
|
|
14152
|
+
this.callback({
|
|
14153
|
+
data,
|
|
14154
|
+
error,
|
|
14155
|
+
loading,
|
|
14156
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
14157
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
14158
|
+
});
|
|
14159
|
+
}
|
|
14160
|
+
}
|
|
14161
|
+
|
|
14162
|
+
/**
|
|
14163
|
+
* Get events
|
|
14164
|
+
*
|
|
14165
|
+
* @param params the query parameters
|
|
14166
|
+
* @param callback the callback to be called when the events are updated
|
|
14167
|
+
* @returns events
|
|
14168
|
+
*
|
|
14169
|
+
* @category RSVP Live Collection
|
|
14170
|
+
*
|
|
14171
|
+
*/
|
|
14172
|
+
const getRSVPs = (params, callback, config) => {
|
|
14173
|
+
const { log, cache } = getActiveClient();
|
|
14174
|
+
if (!cache)
|
|
14175
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
14176
|
+
const timestamp = Date.now();
|
|
14177
|
+
log(`getRSVPs: (tmpid: ${timestamp}) > listen`);
|
|
14178
|
+
const rsvpLiveCollection = new RSVPLiveCollectionController(params, callback);
|
|
14179
|
+
const disposers = rsvpLiveCollection.startSubscription();
|
|
14180
|
+
const cacheKey = rsvpLiveCollection.getCacheKey();
|
|
14181
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
14182
|
+
return () => {
|
|
14183
|
+
log(`getRSVPs (tmpid: ${timestamp}) > dispose`);
|
|
14184
|
+
disposers.forEach(fn => fn());
|
|
14185
|
+
};
|
|
14186
|
+
};
|
|
14187
|
+
|
|
13679
14188
|
const eventLinkedObject = (event) => {
|
|
13680
14189
|
return Object.assign(Object.assign({}, event), { get creator() {
|
|
13681
14190
|
const cacheData = pullFromCache(['user', 'get', event.userId]);
|
|
@@ -13684,13 +14193,33 @@ const eventLinkedObject = (event) => {
|
|
|
13684
14193
|
return userLinkedObject(cacheData.data);
|
|
13685
14194
|
},
|
|
13686
14195
|
get discussionCommunity() {
|
|
13687
|
-
if (!event.
|
|
14196
|
+
if (!event.discussionCommunityId)
|
|
13688
14197
|
return;
|
|
13689
|
-
const cacheData = pullFromCache([
|
|
14198
|
+
const cacheData = pullFromCache([
|
|
14199
|
+
'discussionCommunity',
|
|
14200
|
+
'get',
|
|
14201
|
+
event.discussionCommunityId,
|
|
14202
|
+
]);
|
|
13690
14203
|
if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
|
|
13691
14204
|
return;
|
|
13692
14205
|
return communityLinkedObject(cacheData.data);
|
|
13693
14206
|
},
|
|
14207
|
+
get targetCommunity() {
|
|
14208
|
+
if (!event.originId)
|
|
14209
|
+
return;
|
|
14210
|
+
const cacheData = pullFromCache(['community', 'get', event.originId]);
|
|
14211
|
+
if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
|
|
14212
|
+
return;
|
|
14213
|
+
return communityLinkedObject(cacheData.data);
|
|
14214
|
+
},
|
|
14215
|
+
get coverImage() {
|
|
14216
|
+
if (!event.coverImageFileId)
|
|
14217
|
+
return;
|
|
14218
|
+
const cacheData = pullFromCache(['file', 'get', event.coverImageFileId]);
|
|
14219
|
+
if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
|
|
14220
|
+
return;
|
|
14221
|
+
return cacheData.data;
|
|
14222
|
+
},
|
|
13694
14223
|
get liveStream() {
|
|
13695
14224
|
if (!event.livestreamId)
|
|
13696
14225
|
return;
|
|
@@ -13698,6 +14227,17 @@ const eventLinkedObject = (event) => {
|
|
|
13698
14227
|
if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
|
|
13699
14228
|
return;
|
|
13700
14229
|
return cacheData.data;
|
|
14230
|
+
}, createRSVP: async (status) => {
|
|
14231
|
+
const { data } = await createRSVP(event.eventId, status);
|
|
14232
|
+
return data;
|
|
14233
|
+
}, updateRSVP: async (status) => {
|
|
14234
|
+
const { data } = await updateRSVP(event.eventId, status);
|
|
14235
|
+
return data;
|
|
14236
|
+
}, getMyRSVP: async () => {
|
|
14237
|
+
const { data } = await getMyRSVP(event.eventId);
|
|
14238
|
+
return data;
|
|
14239
|
+
}, getRSVPs: (params, callback) => {
|
|
14240
|
+
return getRSVPs(Object.assign({ eventId: event.eventId }, params), callback);
|
|
13701
14241
|
} });
|
|
13702
14242
|
};
|
|
13703
14243
|
|
|
@@ -30331,35 +30871,11 @@ const getReactions = (postId, callback) => {
|
|
|
30331
30871
|
};
|
|
30332
30872
|
|
|
30333
30873
|
var index$1 = /*#__PURE__*/Object.freeze({
|
|
30334
|
-
__proto__: null,
|
|
30335
|
-
createReaction: createReaction,
|
|
30336
|
-
onLiveReactionCreated: onLiveReactionCreated,
|
|
30337
|
-
getReactions: getReactions
|
|
30338
|
-
});
|
|
30339
|
-
|
|
30340
|
-
const prepareEventPayload = (rawPayload) => {
|
|
30341
|
-
return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser) });
|
|
30342
|
-
};
|
|
30343
|
-
|
|
30344
|
-
const createEventEventSubscriber = (event, callback) => {
|
|
30345
|
-
const client = getActiveClient();
|
|
30346
|
-
const filter = (payload) => {
|
|
30347
|
-
const unpackedPayload = prepareEventPayload(payload);
|
|
30348
|
-
if (!client.cache) {
|
|
30349
|
-
callback(unpackedPayload.events[0]);
|
|
30350
|
-
}
|
|
30351
|
-
else {
|
|
30352
|
-
ingestInCache(unpackedPayload);
|
|
30353
|
-
const event = pullFromCache([
|
|
30354
|
-
'event',
|
|
30355
|
-
'get',
|
|
30356
|
-
unpackedPayload.events[0].eventId,
|
|
30357
|
-
]);
|
|
30358
|
-
callback(event.data);
|
|
30359
|
-
}
|
|
30360
|
-
};
|
|
30361
|
-
return createEventSubscriber(client, event, event, filter);
|
|
30362
|
-
};
|
|
30874
|
+
__proto__: null,
|
|
30875
|
+
createReaction: createReaction,
|
|
30876
|
+
onLiveReactionCreated: onLiveReactionCreated,
|
|
30877
|
+
getReactions: getReactions
|
|
30878
|
+
});
|
|
30363
30879
|
|
|
30364
30880
|
/* begin_public_function
|
|
30365
30881
|
id: event.create
|
|
@@ -30382,7 +30898,7 @@ const createEvent = async (bundle) => {
|
|
|
30382
30898
|
const client = getActiveClient();
|
|
30383
30899
|
client.log('event/createEvent', bundle);
|
|
30384
30900
|
const { data: payload } = await client.http.post('/api/v1/events', bundle);
|
|
30385
|
-
fireEvent('event.created', payload);
|
|
30901
|
+
fireEvent('local.event.created', payload);
|
|
30386
30902
|
const preparedPayload = prepareEventPayload(payload);
|
|
30387
30903
|
const cachedAt = client.cache && Date.now();
|
|
30388
30904
|
if (client.cache)
|
|
@@ -30416,7 +30932,7 @@ const updateEvent = async (eventId, bundle) => {
|
|
|
30416
30932
|
const client = getActiveClient();
|
|
30417
30933
|
client.log('event/updateEvent', eventId, bundle);
|
|
30418
30934
|
const { data: payload } = await client.http.put(`/api/v1/events/${eventId}`, bundle);
|
|
30419
|
-
fireEvent('event.updated', payload);
|
|
30935
|
+
fireEvent('local.event.updated', payload);
|
|
30420
30936
|
const preparedPayload = prepareEventPayload(payload);
|
|
30421
30937
|
const cachedAt = client.cache && Date.now();
|
|
30422
30938
|
if (client.cache)
|
|
@@ -30448,7 +30964,7 @@ const updateEvent = async (eventId, bundle) => {
|
|
|
30448
30964
|
const getEvent$1 = async (eventId) => {
|
|
30449
30965
|
const client = getActiveClient();
|
|
30450
30966
|
client.log('event/getEvent', eventId);
|
|
30451
|
-
const { data: payload } = await client.http.get(`/api/
|
|
30967
|
+
const { data: payload } = await client.http.get(`/api/v1/events/${eventId}`);
|
|
30452
30968
|
const data = prepareEventPayload(payload);
|
|
30453
30969
|
const cachedAt = client.cache && Date.now();
|
|
30454
30970
|
if (client.cache)
|
|
@@ -30506,10 +31022,10 @@ const deleteEvent = async (eventId) => {
|
|
|
30506
31022
|
const client = getActiveClient();
|
|
30507
31023
|
client.log('event/deleteEvent', eventId);
|
|
30508
31024
|
const event = await getEvent$1(eventId);
|
|
30509
|
-
await client.http.delete(`/api/
|
|
31025
|
+
await client.http.delete(`/api/v1/events/${eventId}`);
|
|
30510
31026
|
const deletedEvent = Object.assign(Object.assign({}, event.data), { isDeleted: true });
|
|
30511
31027
|
upsertInCache(['event', 'get', eventId], deletedEvent);
|
|
30512
|
-
fireEvent('event.deleted', {
|
|
31028
|
+
fireEvent('local.event.deleted', {
|
|
30513
31029
|
users: [],
|
|
30514
31030
|
files: [],
|
|
30515
31031
|
communities: [],
|
|
@@ -30520,57 +31036,6 @@ const deleteEvent = async (eventId) => {
|
|
|
30520
31036
|
};
|
|
30521
31037
|
/* end_public_function */
|
|
30522
31038
|
|
|
30523
|
-
/**
|
|
30524
|
-
* ```js
|
|
30525
|
-
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30526
|
-
* const dispose = EventRepository.onEventCreated(event => {
|
|
30527
|
-
* // ...
|
|
30528
|
-
* })
|
|
30529
|
-
* ```
|
|
30530
|
-
*
|
|
30531
|
-
* Fired when a {@link Amity.Event} has been created
|
|
30532
|
-
*
|
|
30533
|
-
* @param callback The function to call when the event was fired
|
|
30534
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30535
|
-
*
|
|
30536
|
-
* @category Event Events
|
|
30537
|
-
*/
|
|
30538
|
-
const onEventCreated = (callback) => createEventEventSubscriber('event.created', callback);
|
|
30539
|
-
|
|
30540
|
-
/**
|
|
30541
|
-
* ```js
|
|
30542
|
-
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30543
|
-
* const dispose = EventRepository.onEventUpdated(event => {
|
|
30544
|
-
* // ...
|
|
30545
|
-
* })
|
|
30546
|
-
* ```
|
|
30547
|
-
*
|
|
30548
|
-
* Fired when a {@link Amity.Event} has been updated
|
|
30549
|
-
*
|
|
30550
|
-
* @param callback The function to call when the event was fired
|
|
30551
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30552
|
-
*
|
|
30553
|
-
* @category Event Events
|
|
30554
|
-
*/
|
|
30555
|
-
const onEventUpdated = (callback) => createEventEventSubscriber('event.updated', callback);
|
|
30556
|
-
|
|
30557
|
-
/**
|
|
30558
|
-
* ```js
|
|
30559
|
-
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30560
|
-
* const dispose = EventRepository.onEventDeleted(event => {
|
|
30561
|
-
* // ...
|
|
30562
|
-
* })
|
|
30563
|
-
* ```
|
|
30564
|
-
*
|
|
30565
|
-
* Fired when a {@link Amity.Event} has been deleted
|
|
30566
|
-
*
|
|
30567
|
-
* @param callback The function to call when the event was fired
|
|
30568
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30569
|
-
*
|
|
30570
|
-
* @category Event Events
|
|
30571
|
-
*/
|
|
30572
|
-
const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted', callback);
|
|
30573
|
-
|
|
30574
31039
|
/* begin_public_function
|
|
30575
31040
|
id: event.get
|
|
30576
31041
|
*/
|
|
@@ -30594,12 +31059,283 @@ const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted',
|
|
|
30594
31059
|
* @category Event Live Object
|
|
30595
31060
|
*/
|
|
30596
31061
|
const getEvent = (eventId, callback) => {
|
|
30597
|
-
return liveObject(eventId, callback, 'eventId', getEvent$1, [
|
|
31062
|
+
return liveObject(eventId, callback, 'eventId', getEvent$1, [onEventUpdated, onEventDeleted, onLocalEventUpdated, onLocalEventDeleted], {
|
|
30598
31063
|
callbackDataSelector: (data) => (data ? eventLinkedObject(data) : data),
|
|
30599
31064
|
});
|
|
30600
31065
|
};
|
|
30601
31066
|
/* end_public_function */
|
|
30602
31067
|
|
|
31068
|
+
class EventPaginationController extends PaginationController {
|
|
31069
|
+
async getRequest(queryParams, token) {
|
|
31070
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
31071
|
+
const options = token ? { token } : { limit };
|
|
31072
|
+
const { data: response } = await this.http.get(`/api/v1/events`, { params: Object.assign(Object.assign({}, params), { options }) });
|
|
31073
|
+
return response;
|
|
31074
|
+
}
|
|
31075
|
+
}
|
|
31076
|
+
|
|
31077
|
+
class EventQueryStreamController extends QueryStreamController {
|
|
31078
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
31079
|
+
super(query, cacheKey);
|
|
31080
|
+
this.notifyChange = notifyChange;
|
|
31081
|
+
this.preparePayload = preparePayload;
|
|
31082
|
+
}
|
|
31083
|
+
async saveToMainDB(response) {
|
|
31084
|
+
const processedPayload = this.preparePayload(response);
|
|
31085
|
+
const client = getActiveClient();
|
|
31086
|
+
const cachedAt = client.cache && Date.now();
|
|
31087
|
+
if (client.cache)
|
|
31088
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
31089
|
+
}
|
|
31090
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
31091
|
+
var _a, _b;
|
|
31092
|
+
if (refresh) {
|
|
31093
|
+
pushToCache(this.cacheKey, { data: response.events.map(getResolver('event')) });
|
|
31094
|
+
}
|
|
31095
|
+
else {
|
|
31096
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
31097
|
+
const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
31098
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...events, ...response.events.map(getResolver('event'))])] }));
|
|
31099
|
+
}
|
|
31100
|
+
}
|
|
31101
|
+
reactor(action) {
|
|
31102
|
+
return (event) => {
|
|
31103
|
+
var _a;
|
|
31104
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
31105
|
+
if (!collection)
|
|
31106
|
+
return;
|
|
31107
|
+
if (action === EventActionsEnum.OnEventCreated) {
|
|
31108
|
+
collection.data = [...new Set([event.eventId, ...collection.data])];
|
|
31109
|
+
}
|
|
31110
|
+
if (action === EventActionsEnum.OnEventDeleted) {
|
|
31111
|
+
collection.data = collection.data.filter(eventId => eventId !== event.eventId);
|
|
31112
|
+
}
|
|
31113
|
+
pushToCache(this.cacheKey, collection);
|
|
31114
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
31115
|
+
};
|
|
31116
|
+
}
|
|
31117
|
+
subscribeRTE(createSubscriber) {
|
|
31118
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
31119
|
+
}
|
|
31120
|
+
}
|
|
31121
|
+
|
|
31122
|
+
class EventLiveCollectionController extends LiveCollectionController {
|
|
31123
|
+
constructor(query, callback) {
|
|
31124
|
+
const queryStreamId = hash__default["default"](query);
|
|
31125
|
+
const cacheKey = ['event', 'collection', queryStreamId];
|
|
31126
|
+
const paginationController = new EventPaginationController(query);
|
|
31127
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
31128
|
+
this.query = query;
|
|
31129
|
+
this.queryStreamController = new EventQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventPayload);
|
|
31130
|
+
this.callback = callback.bind(this);
|
|
31131
|
+
this.loadPage({ initial: true });
|
|
31132
|
+
}
|
|
31133
|
+
setup() {
|
|
31134
|
+
var _a;
|
|
31135
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
31136
|
+
if (!collection)
|
|
31137
|
+
pushToCache(this.cacheKey, { data: [], params: {} });
|
|
31138
|
+
}
|
|
31139
|
+
async persistModel(queryPayload) {
|
|
31140
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
31141
|
+
}
|
|
31142
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
31143
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
31144
|
+
}
|
|
31145
|
+
startSubscription() {
|
|
31146
|
+
return this.queryStreamController.subscribeRTE([
|
|
31147
|
+
{ fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
|
|
31148
|
+
{ fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
|
|
31149
|
+
{ fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
|
|
31150
|
+
{ fn: onLocalEventCreated, action: EventActionsEnum.OnEventCreated },
|
|
31151
|
+
{ fn: onLocalEventUpdated, action: EventActionsEnum.OnEventUpdated },
|
|
31152
|
+
{ fn: onLocalEventDeleted, action: EventActionsEnum.OnEventDeleted },
|
|
31153
|
+
]);
|
|
31154
|
+
}
|
|
31155
|
+
notifyChange({ origin, loading, error }) {
|
|
31156
|
+
var _a, _b;
|
|
31157
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
31158
|
+
if (!collection)
|
|
31159
|
+
return;
|
|
31160
|
+
const data = ((_b = collection.data
|
|
31161
|
+
.map(eventId => pullFromCache(['event', 'get', eventId]))
|
|
31162
|
+
.filter(isNonNullable)
|
|
31163
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
|
|
31164
|
+
if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
|
|
31165
|
+
return;
|
|
31166
|
+
this.callback({
|
|
31167
|
+
data,
|
|
31168
|
+
error,
|
|
31169
|
+
loading,
|
|
31170
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
31171
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
31172
|
+
});
|
|
31173
|
+
}
|
|
31174
|
+
}
|
|
31175
|
+
|
|
31176
|
+
/**
|
|
31177
|
+
* Get events
|
|
31178
|
+
*
|
|
31179
|
+
* @param params the query parameters
|
|
31180
|
+
* @param callback the callback to be called when the events are updated
|
|
31181
|
+
* @returns events
|
|
31182
|
+
*
|
|
31183
|
+
* @category Event Live Collection
|
|
31184
|
+
*
|
|
31185
|
+
*/
|
|
31186
|
+
const getEvents = (params, callback, config) => {
|
|
31187
|
+
const { log, cache } = getActiveClient();
|
|
31188
|
+
if (!cache)
|
|
31189
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
31190
|
+
const timestamp = Date.now();
|
|
31191
|
+
log(`getEvents: (tmpid: ${timestamp}) > listen`);
|
|
31192
|
+
const eventLiveCollection = new EventLiveCollectionController(params, callback);
|
|
31193
|
+
const disposers = eventLiveCollection.startSubscription();
|
|
31194
|
+
const cacheKey = eventLiveCollection.getCacheKey();
|
|
31195
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
31196
|
+
return () => {
|
|
31197
|
+
log(`getEvents (tmpid: ${timestamp}) > dispose`);
|
|
31198
|
+
disposers.forEach(fn => fn());
|
|
31199
|
+
};
|
|
31200
|
+
};
|
|
31201
|
+
|
|
31202
|
+
class MyEventPaginationController extends PaginationController {
|
|
31203
|
+
async getRequest(queryParams, token) {
|
|
31204
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
31205
|
+
const options = token ? { token } : { limit };
|
|
31206
|
+
const { data: response } = await this.http.get(`/api/v1/events/me/rsvps`, { params: Object.assign(Object.assign({}, params), { options }) });
|
|
31207
|
+
return response;
|
|
31208
|
+
}
|
|
31209
|
+
}
|
|
31210
|
+
|
|
31211
|
+
class MyEventQueryStreamController extends QueryStreamController {
|
|
31212
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
31213
|
+
super(query, cacheKey);
|
|
31214
|
+
this.notifyChange = notifyChange;
|
|
31215
|
+
this.preparePayload = preparePayload;
|
|
31216
|
+
}
|
|
31217
|
+
async saveToMainDB(response) {
|
|
31218
|
+
const processedPayload = this.preparePayload(response);
|
|
31219
|
+
const client = getActiveClient();
|
|
31220
|
+
const cachedAt = client.cache && Date.now();
|
|
31221
|
+
if (client.cache)
|
|
31222
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
31223
|
+
}
|
|
31224
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
31225
|
+
var _a, _b;
|
|
31226
|
+
if (refresh) {
|
|
31227
|
+
pushToCache(this.cacheKey, { data: response.events.map(getResolver('event')) });
|
|
31228
|
+
}
|
|
31229
|
+
else {
|
|
31230
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
31231
|
+
const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
31232
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...events, ...response.events.map(getResolver('event'))])] }));
|
|
31233
|
+
}
|
|
31234
|
+
}
|
|
31235
|
+
reactor(action) {
|
|
31236
|
+
return (event) => {
|
|
31237
|
+
var _a;
|
|
31238
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
31239
|
+
if (!collection)
|
|
31240
|
+
return;
|
|
31241
|
+
if (action === EventActionsEnum.OnEventCreated) {
|
|
31242
|
+
const client = getActiveClient();
|
|
31243
|
+
if (client.userId !== event.userId)
|
|
31244
|
+
return;
|
|
31245
|
+
collection.data = [...new Set([event.eventId, ...collection.data])];
|
|
31246
|
+
}
|
|
31247
|
+
if (action === EventActionsEnum.OnEventDeleted) {
|
|
31248
|
+
collection.data = collection.data.filter(eventId => eventId !== event.eventId);
|
|
31249
|
+
}
|
|
31250
|
+
pushToCache(this.cacheKey, collection);
|
|
31251
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
31252
|
+
};
|
|
31253
|
+
}
|
|
31254
|
+
subscribeRTE(createSubscriber) {
|
|
31255
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
31256
|
+
}
|
|
31257
|
+
}
|
|
31258
|
+
|
|
31259
|
+
class MyEventLiveCollectionController extends LiveCollectionController {
|
|
31260
|
+
constructor(query, callback) {
|
|
31261
|
+
const queryStreamId = hash__default["default"](query);
|
|
31262
|
+
const cacheKey = ['event', 'collection', queryStreamId];
|
|
31263
|
+
const paginationController = new MyEventPaginationController(query);
|
|
31264
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
31265
|
+
this.query = query;
|
|
31266
|
+
this.queryStreamController = new MyEventQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventPayload);
|
|
31267
|
+
this.callback = callback.bind(this);
|
|
31268
|
+
this.loadPage({ initial: true });
|
|
31269
|
+
}
|
|
31270
|
+
setup() {
|
|
31271
|
+
var _a;
|
|
31272
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
31273
|
+
if (!collection)
|
|
31274
|
+
pushToCache(this.cacheKey, { data: [], params: {} });
|
|
31275
|
+
}
|
|
31276
|
+
async persistModel(queryPayload) {
|
|
31277
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
31278
|
+
}
|
|
31279
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
31280
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
31281
|
+
}
|
|
31282
|
+
startSubscription() {
|
|
31283
|
+
return this.queryStreamController.subscribeRTE([
|
|
31284
|
+
{ fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
|
|
31285
|
+
{ fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
|
|
31286
|
+
{ fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
|
|
31287
|
+
{ fn: onLocalEventCreated, action: EventActionsEnum.OnEventCreated },
|
|
31288
|
+
{ fn: onLocalEventUpdated, action: EventActionsEnum.OnEventUpdated },
|
|
31289
|
+
{ fn: onLocalEventDeleted, action: EventActionsEnum.OnEventDeleted },
|
|
31290
|
+
]);
|
|
31291
|
+
}
|
|
31292
|
+
notifyChange({ origin, loading, error }) {
|
|
31293
|
+
var _a, _b;
|
|
31294
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
31295
|
+
if (!collection)
|
|
31296
|
+
return;
|
|
31297
|
+
const data = ((_b = collection.data
|
|
31298
|
+
.map(eventId => pullFromCache(['event', 'get', eventId]))
|
|
31299
|
+
.filter(isNonNullable)
|
|
31300
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
|
|
31301
|
+
if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
|
|
31302
|
+
return;
|
|
31303
|
+
this.callback({
|
|
31304
|
+
data,
|
|
31305
|
+
error,
|
|
31306
|
+
loading,
|
|
31307
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
31308
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
31309
|
+
});
|
|
31310
|
+
}
|
|
31311
|
+
}
|
|
31312
|
+
|
|
31313
|
+
/**
|
|
31314
|
+
* Get my events
|
|
31315
|
+
*
|
|
31316
|
+
* @param params the query parameters
|
|
31317
|
+
* @param callback the callback to be called when the events are updated
|
|
31318
|
+
* @returns events
|
|
31319
|
+
*
|
|
31320
|
+
* @category Event Live Collection
|
|
31321
|
+
*
|
|
31322
|
+
*/
|
|
31323
|
+
const getMyEvents = (params, callback, config) => {
|
|
31324
|
+
const { log, cache } = getActiveClient();
|
|
31325
|
+
if (!cache)
|
|
31326
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
31327
|
+
const timestamp = Date.now();
|
|
31328
|
+
log(`getMyEvents: (tmpid: ${timestamp}) > listen`);
|
|
31329
|
+
const myEventLiveCollection = new MyEventLiveCollectionController(params, callback);
|
|
31330
|
+
const disposers = myEventLiveCollection.startSubscription();
|
|
31331
|
+
const cacheKey = myEventLiveCollection.getCacheKey();
|
|
31332
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
31333
|
+
return () => {
|
|
31334
|
+
log(`getMyEvents (tmpid: ${timestamp}) > dispose`);
|
|
31335
|
+
disposers.forEach(fn => fn());
|
|
31336
|
+
};
|
|
31337
|
+
};
|
|
31338
|
+
|
|
30603
31339
|
var index = /*#__PURE__*/Object.freeze({
|
|
30604
31340
|
__proto__: null,
|
|
30605
31341
|
createEvent: createEvent,
|
|
@@ -30608,7 +31344,17 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
30608
31344
|
onEventCreated: onEventCreated,
|
|
30609
31345
|
onEventUpdated: onEventUpdated,
|
|
30610
31346
|
onEventDeleted: onEventDeleted,
|
|
30611
|
-
|
|
31347
|
+
onLocalEventCreated: onLocalEventCreated,
|
|
31348
|
+
onLocalEventUpdated: onLocalEventUpdated,
|
|
31349
|
+
onLocalEventDeleted: onLocalEventDeleted,
|
|
31350
|
+
onRSVPCreated: onRSVPCreated,
|
|
31351
|
+
onRSVPUpdated: onRSVPUpdated,
|
|
31352
|
+
onLocalRSVPCreated: onLocalRSVPCreated,
|
|
31353
|
+
onLocalRSVPUpdated: onLocalRSVPUpdated,
|
|
31354
|
+
getEvent: getEvent,
|
|
31355
|
+
getEvents: getEvents,
|
|
31356
|
+
getMyEvents: getMyEvents,
|
|
31357
|
+
getRSVPs: getRSVPs
|
|
30612
31358
|
});
|
|
30613
31359
|
|
|
30614
31360
|
exports.API_REGIONS = API_REGIONS;
|