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