@amityco/ts-sdk 7.11.1-b8fc6951.0 → 7.11.1-b94657c5.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 +3 -0
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/@types/domains/event.d.ts +53 -10
- package/dist/@types/domains/event.d.ts.map +1 -1
- package/dist/@types/domains/notification.d.ts +4 -1
- package/dist/@types/domains/notification.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 +3 -1
- package/dist/eventRepository/events/enums.d.ts.map +1 -1
- 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.map +1 -1
- 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 +2 -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 +692 -92
- package/dist/index.esm.js +693 -93
- package/dist/index.umd.js +3 -3
- 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 {
|
|
@@ -659,6 +664,8 @@ const idResolvers = {
|
|
|
659
664
|
invitation: ({ _id }) => _id,
|
|
660
665
|
joinRequest: ({ joinRequestId }) => joinRequestId,
|
|
661
666
|
event: ({ eventId }) => eventId,
|
|
667
|
+
eventResponse: ({ eventId }) => eventId,
|
|
668
|
+
discussionCommunity: ({ communityId }) => communityId,
|
|
662
669
|
};
|
|
663
670
|
/**
|
|
664
671
|
* Retrieve the id resolver matching a domain name
|
|
@@ -715,7 +722,8 @@ const PAYLOAD2MODEL = {
|
|
|
715
722
|
invitations: 'invitation',
|
|
716
723
|
joinRequests: 'joinRequest',
|
|
717
724
|
events: 'event',
|
|
718
|
-
|
|
725
|
+
eventResponses: 'eventResponse',
|
|
726
|
+
discussionCommunities: 'discussionCommunity',
|
|
719
727
|
};
|
|
720
728
|
/** hidden */
|
|
721
729
|
const isOutdated = (prevData, nextData) => {
|
|
@@ -13679,6 +13687,504 @@ const communityLinkedObject = (community) => {
|
|
|
13679
13687
|
} });
|
|
13680
13688
|
};
|
|
13681
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
|
+
|
|
13682
14188
|
const eventLinkedObject = (event) => {
|
|
13683
14189
|
return Object.assign(Object.assign({}, event), { get creator() {
|
|
13684
14190
|
const cacheData = pullFromCache(['user', 'get', event.userId]);
|
|
@@ -13690,7 +14196,7 @@ const eventLinkedObject = (event) => {
|
|
|
13690
14196
|
if (!event.discussionCommunityId)
|
|
13691
14197
|
return;
|
|
13692
14198
|
const cacheData = pullFromCache([
|
|
13693
|
-
'
|
|
14199
|
+
'discussionCommunity',
|
|
13694
14200
|
'get',
|
|
13695
14201
|
event.discussionCommunityId,
|
|
13696
14202
|
]);
|
|
@@ -13698,6 +14204,22 @@ const eventLinkedObject = (event) => {
|
|
|
13698
14204
|
return;
|
|
13699
14205
|
return communityLinkedObject(cacheData.data);
|
|
13700
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
|
+
},
|
|
13701
14223
|
get liveStream() {
|
|
13702
14224
|
if (!event.livestreamId)
|
|
13703
14225
|
return;
|
|
@@ -13705,6 +14227,17 @@ const eventLinkedObject = (event) => {
|
|
|
13705
14227
|
if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
|
|
13706
14228
|
return;
|
|
13707
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);
|
|
13708
14241
|
} });
|
|
13709
14242
|
};
|
|
13710
14243
|
|
|
@@ -30344,30 +30877,6 @@ var index$1 = /*#__PURE__*/Object.freeze({
|
|
|
30344
30877
|
getReactions: getReactions
|
|
30345
30878
|
});
|
|
30346
30879
|
|
|
30347
|
-
const prepareEventPayload = (rawPayload) => {
|
|
30348
|
-
return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser) });
|
|
30349
|
-
};
|
|
30350
|
-
|
|
30351
|
-
const createEventEventSubscriber = (event, callback) => {
|
|
30352
|
-
const client = getActiveClient();
|
|
30353
|
-
const filter = (payload) => {
|
|
30354
|
-
const unpackedPayload = prepareEventPayload(payload);
|
|
30355
|
-
if (!client.cache) {
|
|
30356
|
-
callback(unpackedPayload.events[0]);
|
|
30357
|
-
}
|
|
30358
|
-
else {
|
|
30359
|
-
ingestInCache(unpackedPayload);
|
|
30360
|
-
const event = pullFromCache([
|
|
30361
|
-
'event',
|
|
30362
|
-
'get',
|
|
30363
|
-
unpackedPayload.events[0].eventId,
|
|
30364
|
-
]);
|
|
30365
|
-
callback(event.data);
|
|
30366
|
-
}
|
|
30367
|
-
};
|
|
30368
|
-
return createEventSubscriber(client, event, event, filter);
|
|
30369
|
-
};
|
|
30370
|
-
|
|
30371
30880
|
/* begin_public_function
|
|
30372
30881
|
id: event.create
|
|
30373
30882
|
*/
|
|
@@ -30389,7 +30898,7 @@ const createEvent = async (bundle) => {
|
|
|
30389
30898
|
const client = getActiveClient();
|
|
30390
30899
|
client.log('event/createEvent', bundle);
|
|
30391
30900
|
const { data: payload } = await client.http.post('/api/v1/events', bundle);
|
|
30392
|
-
fireEvent('event.created', payload);
|
|
30901
|
+
fireEvent('local.event.created', payload);
|
|
30393
30902
|
const preparedPayload = prepareEventPayload(payload);
|
|
30394
30903
|
const cachedAt = client.cache && Date.now();
|
|
30395
30904
|
if (client.cache)
|
|
@@ -30423,7 +30932,7 @@ const updateEvent = async (eventId, bundle) => {
|
|
|
30423
30932
|
const client = getActiveClient();
|
|
30424
30933
|
client.log('event/updateEvent', eventId, bundle);
|
|
30425
30934
|
const { data: payload } = await client.http.put(`/api/v1/events/${eventId}`, bundle);
|
|
30426
|
-
fireEvent('event.updated', payload);
|
|
30935
|
+
fireEvent('local.event.updated', payload);
|
|
30427
30936
|
const preparedPayload = prepareEventPayload(payload);
|
|
30428
30937
|
const cachedAt = client.cache && Date.now();
|
|
30429
30938
|
if (client.cache)
|
|
@@ -30455,7 +30964,7 @@ const updateEvent = async (eventId, bundle) => {
|
|
|
30455
30964
|
const getEvent$1 = async (eventId) => {
|
|
30456
30965
|
const client = getActiveClient();
|
|
30457
30966
|
client.log('event/getEvent', eventId);
|
|
30458
|
-
const { data: payload } = await client.http.get(`/api/
|
|
30967
|
+
const { data: payload } = await client.http.get(`/api/v1/events/${eventId}`);
|
|
30459
30968
|
const data = prepareEventPayload(payload);
|
|
30460
30969
|
const cachedAt = client.cache && Date.now();
|
|
30461
30970
|
if (client.cache)
|
|
@@ -30513,10 +31022,10 @@ const deleteEvent = async (eventId) => {
|
|
|
30513
31022
|
const client = getActiveClient();
|
|
30514
31023
|
client.log('event/deleteEvent', eventId);
|
|
30515
31024
|
const event = await getEvent$1(eventId);
|
|
30516
|
-
await client.http.delete(`/api/
|
|
31025
|
+
await client.http.delete(`/api/v1/events/${eventId}`);
|
|
30517
31026
|
const deletedEvent = Object.assign(Object.assign({}, event.data), { isDeleted: true });
|
|
30518
31027
|
upsertInCache(['event', 'get', eventId], deletedEvent);
|
|
30519
|
-
fireEvent('event.deleted', {
|
|
31028
|
+
fireEvent('local.event.deleted', {
|
|
30520
31029
|
users: [],
|
|
30521
31030
|
files: [],
|
|
30522
31031
|
communities: [],
|
|
@@ -30527,57 +31036,6 @@ const deleteEvent = async (eventId) => {
|
|
|
30527
31036
|
};
|
|
30528
31037
|
/* end_public_function */
|
|
30529
31038
|
|
|
30530
|
-
/**
|
|
30531
|
-
* ```js
|
|
30532
|
-
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30533
|
-
* const dispose = EventRepository.onEventCreated(event => {
|
|
30534
|
-
* // ...
|
|
30535
|
-
* })
|
|
30536
|
-
* ```
|
|
30537
|
-
*
|
|
30538
|
-
* Fired when a {@link Amity.Event} has been created
|
|
30539
|
-
*
|
|
30540
|
-
* @param callback The function to call when the event was fired
|
|
30541
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30542
|
-
*
|
|
30543
|
-
* @category Event Events
|
|
30544
|
-
*/
|
|
30545
|
-
const onEventCreated = (callback) => createEventEventSubscriber('event.created', callback);
|
|
30546
|
-
|
|
30547
|
-
/**
|
|
30548
|
-
* ```js
|
|
30549
|
-
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30550
|
-
* const dispose = EventRepository.onEventUpdated(event => {
|
|
30551
|
-
* // ...
|
|
30552
|
-
* })
|
|
30553
|
-
* ```
|
|
30554
|
-
*
|
|
30555
|
-
* Fired when a {@link Amity.Event} has been updated
|
|
30556
|
-
*
|
|
30557
|
-
* @param callback The function to call when the event was fired
|
|
30558
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30559
|
-
*
|
|
30560
|
-
* @category Event Events
|
|
30561
|
-
*/
|
|
30562
|
-
const onEventUpdated = (callback) => createEventEventSubscriber('event.updated', callback);
|
|
30563
|
-
|
|
30564
|
-
/**
|
|
30565
|
-
* ```js
|
|
30566
|
-
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30567
|
-
* const dispose = EventRepository.onEventDeleted(event => {
|
|
30568
|
-
* // ...
|
|
30569
|
-
* })
|
|
30570
|
-
* ```
|
|
30571
|
-
*
|
|
30572
|
-
* Fired when a {@link Amity.Event} has been deleted
|
|
30573
|
-
*
|
|
30574
|
-
* @param callback The function to call when the event was fired
|
|
30575
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30576
|
-
*
|
|
30577
|
-
* @category Event Events
|
|
30578
|
-
*/
|
|
30579
|
-
const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted', callback);
|
|
30580
|
-
|
|
30581
31039
|
/* begin_public_function
|
|
30582
31040
|
id: event.get
|
|
30583
31041
|
*/
|
|
@@ -30601,19 +31059,12 @@ const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted',
|
|
|
30601
31059
|
* @category Event Live Object
|
|
30602
31060
|
*/
|
|
30603
31061
|
const getEvent = (eventId, callback) => {
|
|
30604
|
-
return liveObject(eventId, callback, 'eventId', getEvent$1, [
|
|
31062
|
+
return liveObject(eventId, callback, 'eventId', getEvent$1, [onEventUpdated, onEventDeleted, onLocalEventUpdated, onLocalEventDeleted], {
|
|
30605
31063
|
callbackDataSelector: (data) => (data ? eventLinkedObject(data) : data),
|
|
30606
31064
|
});
|
|
30607
31065
|
};
|
|
30608
31066
|
/* end_public_function */
|
|
30609
31067
|
|
|
30610
|
-
var EventActionsEnum;
|
|
30611
|
-
(function (EventActionsEnum) {
|
|
30612
|
-
EventActionsEnum["OnEventCreated"] = "onEventCreated";
|
|
30613
|
-
EventActionsEnum["OnEventUpdated"] = "onEventUpdated";
|
|
30614
|
-
EventActionsEnum["OnEventDeleted"] = "onEventDeleted";
|
|
30615
|
-
})(EventActionsEnum || (EventActionsEnum = {}));
|
|
30616
|
-
|
|
30617
31068
|
class EventPaginationController extends PaginationController {
|
|
30618
31069
|
async getRequest(queryParams, token) {
|
|
30619
31070
|
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
@@ -30696,6 +31147,9 @@ class EventLiveCollectionController extends LiveCollectionController {
|
|
|
30696
31147
|
{ fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
|
|
30697
31148
|
{ fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
|
|
30698
31149
|
{ fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
|
|
31150
|
+
{ fn: onLocalEventCreated, action: EventActionsEnum.OnEventCreated },
|
|
31151
|
+
{ fn: onLocalEventUpdated, action: EventActionsEnum.OnEventUpdated },
|
|
31152
|
+
{ fn: onLocalEventDeleted, action: EventActionsEnum.OnEventDeleted },
|
|
30699
31153
|
]);
|
|
30700
31154
|
}
|
|
30701
31155
|
notifyChange({ origin, loading, error }) {
|
|
@@ -30707,7 +31161,7 @@ class EventLiveCollectionController extends LiveCollectionController {
|
|
|
30707
31161
|
.map(eventId => pullFromCache(['event', 'get', eventId]))
|
|
30708
31162
|
.filter(isNonNullable)
|
|
30709
31163
|
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
|
|
30710
|
-
if (!this.shouldNotify(data) && origin ===
|
|
31164
|
+
if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
|
|
30711
31165
|
return;
|
|
30712
31166
|
this.callback({
|
|
30713
31167
|
data,
|
|
@@ -30745,6 +31199,143 @@ const getEvents = (params, callback, config) => {
|
|
|
30745
31199
|
};
|
|
30746
31200
|
};
|
|
30747
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
|
+
|
|
30748
31339
|
var index = /*#__PURE__*/Object.freeze({
|
|
30749
31340
|
__proto__: null,
|
|
30750
31341
|
createEvent: createEvent,
|
|
@@ -30753,8 +31344,17 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
30753
31344
|
onEventCreated: onEventCreated,
|
|
30754
31345
|
onEventUpdated: onEventUpdated,
|
|
30755
31346
|
onEventDeleted: onEventDeleted,
|
|
31347
|
+
onLocalEventCreated: onLocalEventCreated,
|
|
31348
|
+
onLocalEventUpdated: onLocalEventUpdated,
|
|
31349
|
+
onLocalEventDeleted: onLocalEventDeleted,
|
|
31350
|
+
onRSVPCreated: onRSVPCreated,
|
|
31351
|
+
onRSVPUpdated: onRSVPUpdated,
|
|
31352
|
+
onLocalRSVPCreated: onLocalRSVPCreated,
|
|
31353
|
+
onLocalRSVPUpdated: onLocalRSVPUpdated,
|
|
30756
31354
|
getEvent: getEvent,
|
|
30757
|
-
getEvents: getEvents
|
|
31355
|
+
getEvents: getEvents,
|
|
31356
|
+
getMyEvents: getMyEvents,
|
|
31357
|
+
getRSVPs: getRSVPs
|
|
30758
31358
|
});
|
|
30759
31359
|
|
|
30760
31360
|
exports.API_REGIONS = API_REGIONS;
|