@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.esm.js
CHANGED
|
@@ -194,6 +194,11 @@ var AmityEventStatus;
|
|
|
194
194
|
AmityEventStatus["Ended"] = "ended";
|
|
195
195
|
AmityEventStatus["Cancelled"] = "cancelled";
|
|
196
196
|
})(AmityEventStatus || (AmityEventStatus = {}));
|
|
197
|
+
var AmityEventResponseStatus;
|
|
198
|
+
(function (AmityEventResponseStatus) {
|
|
199
|
+
AmityEventResponseStatus["Going"] = "going";
|
|
200
|
+
AmityEventResponseStatus["NotGoing"] = "not_going";
|
|
201
|
+
})(AmityEventResponseStatus || (AmityEventResponseStatus = {}));
|
|
197
202
|
|
|
198
203
|
function getVersion() {
|
|
199
204
|
try {
|
|
@@ -644,6 +649,8 @@ const idResolvers = {
|
|
|
644
649
|
invitation: ({ _id }) => _id,
|
|
645
650
|
joinRequest: ({ joinRequestId }) => joinRequestId,
|
|
646
651
|
event: ({ eventId }) => eventId,
|
|
652
|
+
eventResponse: ({ eventId }) => eventId,
|
|
653
|
+
discussionCommunity: ({ communityId }) => communityId,
|
|
647
654
|
};
|
|
648
655
|
/**
|
|
649
656
|
* Retrieve the id resolver matching a domain name
|
|
@@ -700,7 +707,8 @@ const PAYLOAD2MODEL = {
|
|
|
700
707
|
invitations: 'invitation',
|
|
701
708
|
joinRequests: 'joinRequest',
|
|
702
709
|
events: 'event',
|
|
703
|
-
|
|
710
|
+
eventResponses: 'eventResponse',
|
|
711
|
+
discussionCommunities: 'discussionCommunity',
|
|
704
712
|
};
|
|
705
713
|
/** hidden */
|
|
706
714
|
const isOutdated = (prevData, nextData) => {
|
|
@@ -29771,6 +29779,504 @@ const communityLinkedObject = (community) => {
|
|
|
29771
29779
|
} });
|
|
29772
29780
|
};
|
|
29773
29781
|
|
|
29782
|
+
const prepareEventResponsePayload = (rawPayload) => {
|
|
29783
|
+
return {
|
|
29784
|
+
respondedAt: rawPayload.eventResponses[0].respondedAt,
|
|
29785
|
+
status: rawPayload.eventResponses[0].status,
|
|
29786
|
+
eventId: rawPayload.eventResponses[0].eventId,
|
|
29787
|
+
event: rawPayload.events,
|
|
29788
|
+
userId: rawPayload.eventResponses[0].userId,
|
|
29789
|
+
user: rawPayload.users.map(convertRawUserToInternalUser),
|
|
29790
|
+
};
|
|
29791
|
+
};
|
|
29792
|
+
|
|
29793
|
+
/* begin_public_function
|
|
29794
|
+
id: event.rsvp.create
|
|
29795
|
+
*/
|
|
29796
|
+
/**
|
|
29797
|
+
* ```js
|
|
29798
|
+
* import { event } from '@amityco/ts-sdk'
|
|
29799
|
+
* const response = await event.createRSVP(eventId, status)
|
|
29800
|
+
* ```
|
|
29801
|
+
*
|
|
29802
|
+
* Creates an {@link Amity.InternalEvent}
|
|
29803
|
+
*
|
|
29804
|
+
* @param bundle The data necessary to create a new {@link Amity.InternalEvent}
|
|
29805
|
+
* @returns The newly created {@link Amity.InternalEvent}
|
|
29806
|
+
*
|
|
29807
|
+
* @category Event API
|
|
29808
|
+
* @async
|
|
29809
|
+
*/
|
|
29810
|
+
const createRSVP = async (eventId, status) => {
|
|
29811
|
+
const client = getActiveClient();
|
|
29812
|
+
client.log('event/createRSVP', eventId, status);
|
|
29813
|
+
const { data: payload } = await client.http.post(`/api/v1/events/${eventId}/rsvp`, { status });
|
|
29814
|
+
fireEvent('local.rsvp.created', payload);
|
|
29815
|
+
const data = prepareEventResponsePayload(payload);
|
|
29816
|
+
const cachedAt = client.cache && Date.now();
|
|
29817
|
+
if (client.cache)
|
|
29818
|
+
ingestInCache({ eventResponses: [data] }, { cachedAt });
|
|
29819
|
+
return {
|
|
29820
|
+
data,
|
|
29821
|
+
cachedAt,
|
|
29822
|
+
};
|
|
29823
|
+
};
|
|
29824
|
+
/* end_public_function */
|
|
29825
|
+
|
|
29826
|
+
/* begin_public_function
|
|
29827
|
+
id: event.update
|
|
29828
|
+
*/
|
|
29829
|
+
/**
|
|
29830
|
+
* ```js
|
|
29831
|
+
* import { event } from '@amityco/ts-sdk'
|
|
29832
|
+
* const response = await event.updateRSVP(eventId, status)
|
|
29833
|
+
* ```
|
|
29834
|
+
*
|
|
29835
|
+
* Updates an {@link Amity.EventResponse}
|
|
29836
|
+
*
|
|
29837
|
+
* @param eventId The ID of the {@link Amity.EventResponse} to edit
|
|
29838
|
+
* @param bundle The data necessary to update an existing {@link Amity.EventResponse}
|
|
29839
|
+
* @returns the updated {@link Amity.EventResponse}
|
|
29840
|
+
*
|
|
29841
|
+
* @category Event API
|
|
29842
|
+
* @async
|
|
29843
|
+
*/
|
|
29844
|
+
const updateRSVP = async (eventId, status) => {
|
|
29845
|
+
const client = getActiveClient();
|
|
29846
|
+
client.log('event/updateRSVP', eventId, status);
|
|
29847
|
+
const { data: payload } = await client.http.put(`/api/v1/events/${eventId}/rsvp`, { status });
|
|
29848
|
+
fireEvent('local.rsvp.updated', payload);
|
|
29849
|
+
const data = prepareEventResponsePayload(payload);
|
|
29850
|
+
const cachedAt = client.cache && Date.now();
|
|
29851
|
+
if (client.cache)
|
|
29852
|
+
ingestInCache({ eventResponses: [data] }, { cachedAt });
|
|
29853
|
+
return {
|
|
29854
|
+
data,
|
|
29855
|
+
cachedAt,
|
|
29856
|
+
};
|
|
29857
|
+
};
|
|
29858
|
+
/* end_public_function */
|
|
29859
|
+
|
|
29860
|
+
const prepareEventPayload = (rawPayload) => {
|
|
29861
|
+
return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser) });
|
|
29862
|
+
};
|
|
29863
|
+
|
|
29864
|
+
const createEventEventSubscriber = (event, callback) => {
|
|
29865
|
+
const client = getActiveClient();
|
|
29866
|
+
const filter = (payload) => {
|
|
29867
|
+
const unpackedPayload = prepareEventPayload(payload);
|
|
29868
|
+
if (!client.cache) {
|
|
29869
|
+
callback(unpackedPayload.events[0]);
|
|
29870
|
+
}
|
|
29871
|
+
else {
|
|
29872
|
+
ingestInCache(unpackedPayload);
|
|
29873
|
+
const event = pullFromCache([
|
|
29874
|
+
'event',
|
|
29875
|
+
'get',
|
|
29876
|
+
unpackedPayload.events[0].eventId,
|
|
29877
|
+
]);
|
|
29878
|
+
callback(event.data);
|
|
29879
|
+
}
|
|
29880
|
+
};
|
|
29881
|
+
return createEventSubscriber(client, event, event, filter);
|
|
29882
|
+
};
|
|
29883
|
+
|
|
29884
|
+
const createEventResponseSubscriber = (event, callback) => {
|
|
29885
|
+
const client = getActiveClient();
|
|
29886
|
+
const filter = (payload) => {
|
|
29887
|
+
const unpackedPayload = prepareEventResponsePayload(payload);
|
|
29888
|
+
if (!client.cache) {
|
|
29889
|
+
callback(unpackedPayload);
|
|
29890
|
+
}
|
|
29891
|
+
else {
|
|
29892
|
+
ingestInCache(unpackedPayload.event[0]);
|
|
29893
|
+
const eventResponse = pullFromCache([
|
|
29894
|
+
'eventResponse',
|
|
29895
|
+
'get',
|
|
29896
|
+
payload.eventResponses[0].eventId,
|
|
29897
|
+
]);
|
|
29898
|
+
callback(eventResponse.data);
|
|
29899
|
+
}
|
|
29900
|
+
};
|
|
29901
|
+
return createEventSubscriber(client, event, event, filter);
|
|
29902
|
+
};
|
|
29903
|
+
|
|
29904
|
+
/* begin_public_function
|
|
29905
|
+
id: event.rsvp.me
|
|
29906
|
+
*/
|
|
29907
|
+
/**
|
|
29908
|
+
* ```js
|
|
29909
|
+
* import { event } from '@amityco/ts-sdk'
|
|
29910
|
+
* const myRSVP = await event.getMyRSVP()
|
|
29911
|
+
* ```
|
|
29912
|
+
*
|
|
29913
|
+
* Joins a {@link Amity.EventResponse} object
|
|
29914
|
+
*
|
|
29915
|
+
* @param eventId the {@link Amity.EventResponse} to get RSVP for
|
|
29916
|
+
* @returns A success boolean if the {@link Amity.EventResponse} RSVP was retrieved
|
|
29917
|
+
*
|
|
29918
|
+
* @category Event API
|
|
29919
|
+
* @async
|
|
29920
|
+
*/
|
|
29921
|
+
const getMyRSVP = async (eventId) => {
|
|
29922
|
+
const client = getActiveClient();
|
|
29923
|
+
client.log('event/getMyRSVP', eventId);
|
|
29924
|
+
const { data: payload } = await client.http.get(`/api/v1/events/${eventId}/me/rsvp`);
|
|
29925
|
+
const data = prepareEventResponsePayload(payload);
|
|
29926
|
+
const cachedAt = client.cache && Date.now();
|
|
29927
|
+
if (client.cache)
|
|
29928
|
+
ingestInCache({ eventResponses: [data] }, { cachedAt });
|
|
29929
|
+
return {
|
|
29930
|
+
data,
|
|
29931
|
+
cachedAt,
|
|
29932
|
+
};
|
|
29933
|
+
};
|
|
29934
|
+
/* end_public_function */
|
|
29935
|
+
/**
|
|
29936
|
+
* ```js
|
|
29937
|
+
* import { event } from '@amityco/ts-sdk'
|
|
29938
|
+
* const event = event.getMyRSVP.locally(eventId)
|
|
29939
|
+
* ```
|
|
29940
|
+
*
|
|
29941
|
+
* Fetches a {@link Amity.EventResponse} object in cache
|
|
29942
|
+
*
|
|
29943
|
+
* @param eventId the ID of the {@link Amity.EventResponse} to fetch
|
|
29944
|
+
* @returns the associated {@link Amity.EventResponse} object
|
|
29945
|
+
*
|
|
29946
|
+
* @category Event API
|
|
29947
|
+
*/
|
|
29948
|
+
getMyRSVP.locally = (eventId) => {
|
|
29949
|
+
const client = getActiveClient();
|
|
29950
|
+
client.log('event/getMyRSVP.locally', eventId);
|
|
29951
|
+
if (!client.cache)
|
|
29952
|
+
return;
|
|
29953
|
+
const cache = pullFromCache(['event', 'getMyRSVP', eventId]);
|
|
29954
|
+
if (!cache)
|
|
29955
|
+
return;
|
|
29956
|
+
return {
|
|
29957
|
+
data: cache.data,
|
|
29958
|
+
cachedAt: cache.cachedAt,
|
|
29959
|
+
};
|
|
29960
|
+
};
|
|
29961
|
+
|
|
29962
|
+
var EventActionsEnum;
|
|
29963
|
+
(function (EventActionsEnum) {
|
|
29964
|
+
EventActionsEnum["OnEventCreated"] = "onEventCreated";
|
|
29965
|
+
EventActionsEnum["OnEventUpdated"] = "onEventUpdated";
|
|
29966
|
+
EventActionsEnum["OnEventDeleted"] = "onEventDeleted";
|
|
29967
|
+
EventActionsEnum["OnRSVPCreated"] = "onRSVPCreated";
|
|
29968
|
+
EventActionsEnum["OnRSVPUpdated"] = "onRSVPUpdated";
|
|
29969
|
+
})(EventActionsEnum || (EventActionsEnum = {}));
|
|
29970
|
+
|
|
29971
|
+
class RSVPPaginationController extends PaginationController {
|
|
29972
|
+
async getRequest(queryParams, token) {
|
|
29973
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, eventId } = queryParams, params = __rest(queryParams, ["limit", "eventId"]);
|
|
29974
|
+
const options = token ? { token } : { limit };
|
|
29975
|
+
const { data: response } = await this.http.get(`/api/v1/events/${eventId}/rsvp`, { params: Object.assign(Object.assign({}, params), { options }) });
|
|
29976
|
+
return response;
|
|
29977
|
+
}
|
|
29978
|
+
}
|
|
29979
|
+
|
|
29980
|
+
class RSVPQueryStreamController extends QueryStreamController {
|
|
29981
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
29982
|
+
super(query, cacheKey);
|
|
29983
|
+
this.notifyChange = notifyChange;
|
|
29984
|
+
this.preparePayload = preparePayload;
|
|
29985
|
+
}
|
|
29986
|
+
async saveToMainDB(response) {
|
|
29987
|
+
const processedPayload = this.preparePayload(response);
|
|
29988
|
+
const client = getActiveClient();
|
|
29989
|
+
const cachedAt = client.cache && Date.now();
|
|
29990
|
+
if (client.cache)
|
|
29991
|
+
ingestInCache({ eventResponses: [processedPayload] }, { cachedAt });
|
|
29992
|
+
}
|
|
29993
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
29994
|
+
var _a, _b;
|
|
29995
|
+
if (refresh) {
|
|
29996
|
+
pushToCache(this.cacheKey, {
|
|
29997
|
+
data: response.eventResponses.map(getResolver('eventResponse')),
|
|
29998
|
+
});
|
|
29999
|
+
}
|
|
30000
|
+
else {
|
|
30001
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30002
|
+
const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
30003
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
30004
|
+
...new Set([...events, ...response.eventResponses.map(getResolver('eventResponse'))]),
|
|
30005
|
+
] }));
|
|
30006
|
+
}
|
|
30007
|
+
}
|
|
30008
|
+
reactor(action) {
|
|
30009
|
+
return (event) => {
|
|
30010
|
+
var _a;
|
|
30011
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30012
|
+
if (!collection)
|
|
30013
|
+
return;
|
|
30014
|
+
if (action === EventActionsEnum.OnRSVPCreated) {
|
|
30015
|
+
const client = getActiveClient();
|
|
30016
|
+
if (client.userId !== event.userId)
|
|
30017
|
+
return;
|
|
30018
|
+
collection.data = [...new Set([event.eventId, ...collection.data])];
|
|
30019
|
+
}
|
|
30020
|
+
if (action === EventActionsEnum.OnEventDeleted) {
|
|
30021
|
+
collection.data = collection.data.filter(eventId => eventId !== event.eventId);
|
|
30022
|
+
}
|
|
30023
|
+
pushToCache(this.cacheKey, collection);
|
|
30024
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
30025
|
+
};
|
|
30026
|
+
}
|
|
30027
|
+
subscribeRTE(createSubscriber) {
|
|
30028
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
30029
|
+
}
|
|
30030
|
+
}
|
|
30031
|
+
|
|
30032
|
+
/**
|
|
30033
|
+
* ```js
|
|
30034
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30035
|
+
* const dispose = EventRepository.onEventCreated(event => {
|
|
30036
|
+
* // ...
|
|
30037
|
+
* })
|
|
30038
|
+
* ```
|
|
30039
|
+
*
|
|
30040
|
+
* Fired when a {@link Amity.Event} has been created
|
|
30041
|
+
*
|
|
30042
|
+
* @param callback The function to call when the event was fired
|
|
30043
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30044
|
+
*
|
|
30045
|
+
* @category Event Events
|
|
30046
|
+
*/
|
|
30047
|
+
const onEventCreated = (callback) => createEventEventSubscriber('event.created', callback);
|
|
30048
|
+
|
|
30049
|
+
/**
|
|
30050
|
+
* ```js
|
|
30051
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30052
|
+
* const dispose = EventRepository.onEventUpdated(event => {
|
|
30053
|
+
* // ...
|
|
30054
|
+
* })
|
|
30055
|
+
* ```
|
|
30056
|
+
*
|
|
30057
|
+
* Fired when a {@link Amity.Event} has been updated
|
|
30058
|
+
*
|
|
30059
|
+
* @param callback The function to call when the event was fired
|
|
30060
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30061
|
+
*
|
|
30062
|
+
* @category Event Events
|
|
30063
|
+
*/
|
|
30064
|
+
const onEventUpdated = (callback) => createEventEventSubscriber('event.updated', callback);
|
|
30065
|
+
|
|
30066
|
+
/**
|
|
30067
|
+
* ```js
|
|
30068
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30069
|
+
* const dispose = EventRepository.onEventDeleted(event => {
|
|
30070
|
+
* // ...
|
|
30071
|
+
* })
|
|
30072
|
+
* ```
|
|
30073
|
+
*
|
|
30074
|
+
* Fired when a {@link Amity.Event} has been deleted
|
|
30075
|
+
*
|
|
30076
|
+
* @param callback The function to call when the event was fired
|
|
30077
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30078
|
+
*
|
|
30079
|
+
* @category Event Events
|
|
30080
|
+
*/
|
|
30081
|
+
const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted', callback);
|
|
30082
|
+
|
|
30083
|
+
/**
|
|
30084
|
+
* ```js
|
|
30085
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30086
|
+
* const dispose = EventRepository.onLocalEventCreated(event => {
|
|
30087
|
+
* // ...
|
|
30088
|
+
* })
|
|
30089
|
+
* ```
|
|
30090
|
+
*
|
|
30091
|
+
* Fired when a {@link Amity.Event} has been created
|
|
30092
|
+
*
|
|
30093
|
+
* @param callback The function to call when the event was fired
|
|
30094
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30095
|
+
*
|
|
30096
|
+
* @category Event Events
|
|
30097
|
+
*/
|
|
30098
|
+
const onLocalEventCreated = (callback) => createEventEventSubscriber('local.event.created', callback);
|
|
30099
|
+
|
|
30100
|
+
/**
|
|
30101
|
+
* ```js
|
|
30102
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30103
|
+
* const dispose = EventRepository.onLocalEventUpdated(event => {
|
|
30104
|
+
* // ...
|
|
30105
|
+
* })
|
|
30106
|
+
* ```
|
|
30107
|
+
*
|
|
30108
|
+
* Fired when a {@link Amity.Event} has been updated
|
|
30109
|
+
*
|
|
30110
|
+
* @param callback The function to call when the event was fired
|
|
30111
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30112
|
+
*
|
|
30113
|
+
* @category Event Events
|
|
30114
|
+
*/
|
|
30115
|
+
const onLocalEventUpdated = (callback) => createEventEventSubscriber('local.event.updated', callback);
|
|
30116
|
+
|
|
30117
|
+
/**
|
|
30118
|
+
* ```js
|
|
30119
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30120
|
+
* const dispose = EventRepository.onLocalEventDeleted(event => {
|
|
30121
|
+
* // ...
|
|
30122
|
+
* })
|
|
30123
|
+
* ```
|
|
30124
|
+
*
|
|
30125
|
+
* Fired when a {@link Amity.Event} has been deleted
|
|
30126
|
+
*
|
|
30127
|
+
* @param callback The function to call when the event was fired
|
|
30128
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30129
|
+
*
|
|
30130
|
+
* @category Event Events
|
|
30131
|
+
*/
|
|
30132
|
+
const onLocalEventDeleted = (callback) => createEventEventSubscriber('local.event.deleted', callback);
|
|
30133
|
+
|
|
30134
|
+
/**
|
|
30135
|
+
* ```js
|
|
30136
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30137
|
+
* const dispose = EventRepository.onRSVPCreated(event => {
|
|
30138
|
+
* // ...
|
|
30139
|
+
* })
|
|
30140
|
+
* ```
|
|
30141
|
+
*
|
|
30142
|
+
* Fired when a {@link Amity.Event} has been created
|
|
30143
|
+
*
|
|
30144
|
+
* @param callback The function to call when the event was fired
|
|
30145
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30146
|
+
*
|
|
30147
|
+
* @category Event Events
|
|
30148
|
+
*/
|
|
30149
|
+
const onRSVPCreated = (callback) => createEventResponseSubscriber('event.rsvp.created', callback);
|
|
30150
|
+
|
|
30151
|
+
/**
|
|
30152
|
+
* ```js
|
|
30153
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30154
|
+
* const dispose = EventRepository.onRSVPUpdated(event => {
|
|
30155
|
+
* // ...
|
|
30156
|
+
* })
|
|
30157
|
+
* ```
|
|
30158
|
+
*
|
|
30159
|
+
* Fired when a {@link Amity.InternalEventResponse} has been updated
|
|
30160
|
+
*
|
|
30161
|
+
* @param callback The function to call when the event was fired
|
|
30162
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30163
|
+
*
|
|
30164
|
+
* @category Event Events
|
|
30165
|
+
*/
|
|
30166
|
+
const onRSVPUpdated = (callback) => createEventResponseSubscriber('event.rsvp.updated', callback);
|
|
30167
|
+
|
|
30168
|
+
/**
|
|
30169
|
+
* ```js
|
|
30170
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30171
|
+
* const dispose = EventRepository.onLocalRSVPCreated(event => {
|
|
30172
|
+
* // ...
|
|
30173
|
+
* })
|
|
30174
|
+
* ```
|
|
30175
|
+
*
|
|
30176
|
+
* Fired when a {@link Amity.Event} has been created
|
|
30177
|
+
*
|
|
30178
|
+
* @param callback The function to call when the event was fired
|
|
30179
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30180
|
+
*
|
|
30181
|
+
* @category Event Events
|
|
30182
|
+
*/
|
|
30183
|
+
const onLocalRSVPCreated = (callback) => createEventResponseSubscriber('local.rsvp.created', callback);
|
|
30184
|
+
|
|
30185
|
+
/**
|
|
30186
|
+
* ```js
|
|
30187
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30188
|
+
* const dispose = EventRepository.onLocalEventUpdated(event => {
|
|
30189
|
+
* // ...
|
|
30190
|
+
* })
|
|
30191
|
+
* ```
|
|
30192
|
+
*
|
|
30193
|
+
* Fired when a {@link Amity.Event} has been updated
|
|
30194
|
+
*
|
|
30195
|
+
* @param callback The function to call when the event was fired
|
|
30196
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30197
|
+
*
|
|
30198
|
+
* @category Event Events
|
|
30199
|
+
*/
|
|
30200
|
+
const onLocalRSVPUpdated = (callback) => createEventResponseSubscriber('local.rsvp.updated', callback);
|
|
30201
|
+
|
|
30202
|
+
class RSVPLiveCollectionController extends LiveCollectionController {
|
|
30203
|
+
constructor(query, callback) {
|
|
30204
|
+
const queryStreamId = hash(query);
|
|
30205
|
+
const cacheKey = ['eventResponse', 'collection', queryStreamId];
|
|
30206
|
+
const paginationController = new RSVPPaginationController(query);
|
|
30207
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
30208
|
+
this.query = query;
|
|
30209
|
+
this.queryStreamController = new RSVPQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventResponsePayload);
|
|
30210
|
+
this.callback = callback.bind(this);
|
|
30211
|
+
this.loadPage({ initial: true });
|
|
30212
|
+
}
|
|
30213
|
+
setup() {
|
|
30214
|
+
var _a;
|
|
30215
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30216
|
+
if (!collection)
|
|
30217
|
+
pushToCache(this.cacheKey, { data: [], params: this.query });
|
|
30218
|
+
}
|
|
30219
|
+
async persistModel(queryPayload) {
|
|
30220
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
30221
|
+
}
|
|
30222
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
30223
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
30224
|
+
}
|
|
30225
|
+
startSubscription() {
|
|
30226
|
+
return this.queryStreamController.subscribeRTE([
|
|
30227
|
+
{ fn: onRSVPCreated, action: EventActionsEnum.OnRSVPCreated },
|
|
30228
|
+
{ fn: onRSVPUpdated, action: EventActionsEnum.OnRSVPUpdated },
|
|
30229
|
+
{ fn: onLocalRSVPCreated, action: EventActionsEnum.OnRSVPCreated },
|
|
30230
|
+
{ fn: onLocalRSVPUpdated, action: EventActionsEnum.OnRSVPUpdated },
|
|
30231
|
+
]);
|
|
30232
|
+
}
|
|
30233
|
+
notifyChange({ origin, loading, error }) {
|
|
30234
|
+
var _a, _b;
|
|
30235
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30236
|
+
if (!collection)
|
|
30237
|
+
return;
|
|
30238
|
+
const data = (_b = collection.data
|
|
30239
|
+
.map(eventId => pullFromCache(['eventResponse', 'get', eventId]))
|
|
30240
|
+
.filter(isNonNullable)
|
|
30241
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
|
|
30242
|
+
if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
|
|
30243
|
+
return;
|
|
30244
|
+
this.callback({
|
|
30245
|
+
data,
|
|
30246
|
+
error,
|
|
30247
|
+
loading,
|
|
30248
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
30249
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
30250
|
+
});
|
|
30251
|
+
}
|
|
30252
|
+
}
|
|
30253
|
+
|
|
30254
|
+
/**
|
|
30255
|
+
* Get events
|
|
30256
|
+
*
|
|
30257
|
+
* @param params the query parameters
|
|
30258
|
+
* @param callback the callback to be called when the events are updated
|
|
30259
|
+
* @returns events
|
|
30260
|
+
*
|
|
30261
|
+
* @category RSVP Live Collection
|
|
30262
|
+
*
|
|
30263
|
+
*/
|
|
30264
|
+
const getRSVPs = (params, callback, config) => {
|
|
30265
|
+
const { log, cache } = getActiveClient();
|
|
30266
|
+
if (!cache)
|
|
30267
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
30268
|
+
const timestamp = Date.now();
|
|
30269
|
+
log(`getRSVPs: (tmpid: ${timestamp}) > listen`);
|
|
30270
|
+
const rsvpLiveCollection = new RSVPLiveCollectionController(params, callback);
|
|
30271
|
+
const disposers = rsvpLiveCollection.startSubscription();
|
|
30272
|
+
const cacheKey = rsvpLiveCollection.getCacheKey();
|
|
30273
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
30274
|
+
return () => {
|
|
30275
|
+
log(`getRSVPs (tmpid: ${timestamp}) > dispose`);
|
|
30276
|
+
disposers.forEach(fn => fn());
|
|
30277
|
+
};
|
|
30278
|
+
};
|
|
30279
|
+
|
|
29774
30280
|
const eventLinkedObject = (event) => {
|
|
29775
30281
|
return Object.assign(Object.assign({}, event), { get creator() {
|
|
29776
30282
|
const cacheData = pullFromCache(['user', 'get', event.userId]);
|
|
@@ -29782,7 +30288,7 @@ const eventLinkedObject = (event) => {
|
|
|
29782
30288
|
if (!event.discussionCommunityId)
|
|
29783
30289
|
return;
|
|
29784
30290
|
const cacheData = pullFromCache([
|
|
29785
|
-
'
|
|
30291
|
+
'discussionCommunity',
|
|
29786
30292
|
'get',
|
|
29787
30293
|
event.discussionCommunityId,
|
|
29788
30294
|
]);
|
|
@@ -29790,6 +30296,22 @@ const eventLinkedObject = (event) => {
|
|
|
29790
30296
|
return;
|
|
29791
30297
|
return communityLinkedObject(cacheData.data);
|
|
29792
30298
|
},
|
|
30299
|
+
get targetCommunity() {
|
|
30300
|
+
if (!event.originId)
|
|
30301
|
+
return;
|
|
30302
|
+
const cacheData = pullFromCache(['community', 'get', event.originId]);
|
|
30303
|
+
if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
|
|
30304
|
+
return;
|
|
30305
|
+
return communityLinkedObject(cacheData.data);
|
|
30306
|
+
},
|
|
30307
|
+
get coverImage() {
|
|
30308
|
+
if (!event.coverImageFileId)
|
|
30309
|
+
return;
|
|
30310
|
+
const cacheData = pullFromCache(['file', 'get', event.coverImageFileId]);
|
|
30311
|
+
if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
|
|
30312
|
+
return;
|
|
30313
|
+
return cacheData.data;
|
|
30314
|
+
},
|
|
29793
30315
|
get liveStream() {
|
|
29794
30316
|
if (!event.livestreamId)
|
|
29795
30317
|
return;
|
|
@@ -29797,6 +30319,17 @@ const eventLinkedObject = (event) => {
|
|
|
29797
30319
|
if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
|
|
29798
30320
|
return;
|
|
29799
30321
|
return cacheData.data;
|
|
30322
|
+
}, createRSVP: async (status) => {
|
|
30323
|
+
const { data } = await createRSVP(event.eventId, status);
|
|
30324
|
+
return data;
|
|
30325
|
+
}, updateRSVP: async (status) => {
|
|
30326
|
+
const { data } = await updateRSVP(event.eventId, status);
|
|
30327
|
+
return data;
|
|
30328
|
+
}, getMyRSVP: async () => {
|
|
30329
|
+
const { data } = await getMyRSVP(event.eventId);
|
|
30330
|
+
return data;
|
|
30331
|
+
}, getRSVPs: (params, callback) => {
|
|
30332
|
+
return getRSVPs(Object.assign({ eventId: event.eventId }, params), callback);
|
|
29800
30333
|
} });
|
|
29801
30334
|
};
|
|
29802
30335
|
|
|
@@ -46436,30 +46969,6 @@ var index$1 = /*#__PURE__*/Object.freeze({
|
|
|
46436
46969
|
getReactions: getReactions
|
|
46437
46970
|
});
|
|
46438
46971
|
|
|
46439
|
-
const prepareEventPayload = (rawPayload) => {
|
|
46440
|
-
return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser) });
|
|
46441
|
-
};
|
|
46442
|
-
|
|
46443
|
-
const createEventEventSubscriber = (event, callback) => {
|
|
46444
|
-
const client = getActiveClient();
|
|
46445
|
-
const filter = (payload) => {
|
|
46446
|
-
const unpackedPayload = prepareEventPayload(payload);
|
|
46447
|
-
if (!client.cache) {
|
|
46448
|
-
callback(unpackedPayload.events[0]);
|
|
46449
|
-
}
|
|
46450
|
-
else {
|
|
46451
|
-
ingestInCache(unpackedPayload);
|
|
46452
|
-
const event = pullFromCache([
|
|
46453
|
-
'event',
|
|
46454
|
-
'get',
|
|
46455
|
-
unpackedPayload.events[0].eventId,
|
|
46456
|
-
]);
|
|
46457
|
-
callback(event.data);
|
|
46458
|
-
}
|
|
46459
|
-
};
|
|
46460
|
-
return createEventSubscriber(client, event, event, filter);
|
|
46461
|
-
};
|
|
46462
|
-
|
|
46463
46972
|
/* begin_public_function
|
|
46464
46973
|
id: event.create
|
|
46465
46974
|
*/
|
|
@@ -46481,7 +46990,7 @@ const createEvent = async (bundle) => {
|
|
|
46481
46990
|
const client = getActiveClient();
|
|
46482
46991
|
client.log('event/createEvent', bundle);
|
|
46483
46992
|
const { data: payload } = await client.http.post('/api/v1/events', bundle);
|
|
46484
|
-
fireEvent('event.created', payload);
|
|
46993
|
+
fireEvent('local.event.created', payload);
|
|
46485
46994
|
const preparedPayload = prepareEventPayload(payload);
|
|
46486
46995
|
const cachedAt = client.cache && Date.now();
|
|
46487
46996
|
if (client.cache)
|
|
@@ -46515,7 +47024,7 @@ const updateEvent = async (eventId, bundle) => {
|
|
|
46515
47024
|
const client = getActiveClient();
|
|
46516
47025
|
client.log('event/updateEvent', eventId, bundle);
|
|
46517
47026
|
const { data: payload } = await client.http.put(`/api/v1/events/${eventId}`, bundle);
|
|
46518
|
-
fireEvent('event.updated', payload);
|
|
47027
|
+
fireEvent('local.event.updated', payload);
|
|
46519
47028
|
const preparedPayload = prepareEventPayload(payload);
|
|
46520
47029
|
const cachedAt = client.cache && Date.now();
|
|
46521
47030
|
if (client.cache)
|
|
@@ -46547,7 +47056,7 @@ const updateEvent = async (eventId, bundle) => {
|
|
|
46547
47056
|
const getEvent$1 = async (eventId) => {
|
|
46548
47057
|
const client = getActiveClient();
|
|
46549
47058
|
client.log('event/getEvent', eventId);
|
|
46550
|
-
const { data: payload } = await client.http.get(`/api/
|
|
47059
|
+
const { data: payload } = await client.http.get(`/api/v1/events/${eventId}`);
|
|
46551
47060
|
const data = prepareEventPayload(payload);
|
|
46552
47061
|
const cachedAt = client.cache && Date.now();
|
|
46553
47062
|
if (client.cache)
|
|
@@ -46605,10 +47114,10 @@ const deleteEvent = async (eventId) => {
|
|
|
46605
47114
|
const client = getActiveClient();
|
|
46606
47115
|
client.log('event/deleteEvent', eventId);
|
|
46607
47116
|
const event = await getEvent$1(eventId);
|
|
46608
|
-
await client.http.delete(`/api/
|
|
47117
|
+
await client.http.delete(`/api/v1/events/${eventId}`);
|
|
46609
47118
|
const deletedEvent = Object.assign(Object.assign({}, event.data), { isDeleted: true });
|
|
46610
47119
|
upsertInCache(['event', 'get', eventId], deletedEvent);
|
|
46611
|
-
fireEvent('event.deleted', {
|
|
47120
|
+
fireEvent('local.event.deleted', {
|
|
46612
47121
|
users: [],
|
|
46613
47122
|
files: [],
|
|
46614
47123
|
communities: [],
|
|
@@ -46619,57 +47128,6 @@ const deleteEvent = async (eventId) => {
|
|
|
46619
47128
|
};
|
|
46620
47129
|
/* end_public_function */
|
|
46621
47130
|
|
|
46622
|
-
/**
|
|
46623
|
-
* ```js
|
|
46624
|
-
* import { EventRepository } from '@amityco/ts-sdk'
|
|
46625
|
-
* const dispose = EventRepository.onEventCreated(event => {
|
|
46626
|
-
* // ...
|
|
46627
|
-
* })
|
|
46628
|
-
* ```
|
|
46629
|
-
*
|
|
46630
|
-
* Fired when a {@link Amity.Event} has been created
|
|
46631
|
-
*
|
|
46632
|
-
* @param callback The function to call when the event was fired
|
|
46633
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
46634
|
-
*
|
|
46635
|
-
* @category Event Events
|
|
46636
|
-
*/
|
|
46637
|
-
const onEventCreated = (callback) => createEventEventSubscriber('event.created', callback);
|
|
46638
|
-
|
|
46639
|
-
/**
|
|
46640
|
-
* ```js
|
|
46641
|
-
* import { EventRepository } from '@amityco/ts-sdk'
|
|
46642
|
-
* const dispose = EventRepository.onEventUpdated(event => {
|
|
46643
|
-
* // ...
|
|
46644
|
-
* })
|
|
46645
|
-
* ```
|
|
46646
|
-
*
|
|
46647
|
-
* Fired when a {@link Amity.Event} has been updated
|
|
46648
|
-
*
|
|
46649
|
-
* @param callback The function to call when the event was fired
|
|
46650
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
46651
|
-
*
|
|
46652
|
-
* @category Event Events
|
|
46653
|
-
*/
|
|
46654
|
-
const onEventUpdated = (callback) => createEventEventSubscriber('event.updated', callback);
|
|
46655
|
-
|
|
46656
|
-
/**
|
|
46657
|
-
* ```js
|
|
46658
|
-
* import { EventRepository } from '@amityco/ts-sdk'
|
|
46659
|
-
* const dispose = EventRepository.onEventDeleted(event => {
|
|
46660
|
-
* // ...
|
|
46661
|
-
* })
|
|
46662
|
-
* ```
|
|
46663
|
-
*
|
|
46664
|
-
* Fired when a {@link Amity.Event} has been deleted
|
|
46665
|
-
*
|
|
46666
|
-
* @param callback The function to call when the event was fired
|
|
46667
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
46668
|
-
*
|
|
46669
|
-
* @category Event Events
|
|
46670
|
-
*/
|
|
46671
|
-
const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted', callback);
|
|
46672
|
-
|
|
46673
47131
|
/* begin_public_function
|
|
46674
47132
|
id: event.get
|
|
46675
47133
|
*/
|
|
@@ -46693,19 +47151,12 @@ const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted',
|
|
|
46693
47151
|
* @category Event Live Object
|
|
46694
47152
|
*/
|
|
46695
47153
|
const getEvent = (eventId, callback) => {
|
|
46696
|
-
return liveObject(eventId, callback, 'eventId', getEvent$1, [
|
|
47154
|
+
return liveObject(eventId, callback, 'eventId', getEvent$1, [onEventUpdated, onEventDeleted, onLocalEventUpdated, onLocalEventDeleted], {
|
|
46697
47155
|
callbackDataSelector: (data) => (data ? eventLinkedObject(data) : data),
|
|
46698
47156
|
});
|
|
46699
47157
|
};
|
|
46700
47158
|
/* end_public_function */
|
|
46701
47159
|
|
|
46702
|
-
var EventActionsEnum;
|
|
46703
|
-
(function (EventActionsEnum) {
|
|
46704
|
-
EventActionsEnum["OnEventCreated"] = "onEventCreated";
|
|
46705
|
-
EventActionsEnum["OnEventUpdated"] = "onEventUpdated";
|
|
46706
|
-
EventActionsEnum["OnEventDeleted"] = "onEventDeleted";
|
|
46707
|
-
})(EventActionsEnum || (EventActionsEnum = {}));
|
|
46708
|
-
|
|
46709
47160
|
class EventPaginationController extends PaginationController {
|
|
46710
47161
|
async getRequest(queryParams, token) {
|
|
46711
47162
|
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
@@ -46788,6 +47239,9 @@ class EventLiveCollectionController extends LiveCollectionController {
|
|
|
46788
47239
|
{ fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
|
|
46789
47240
|
{ fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
|
|
46790
47241
|
{ fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
|
|
47242
|
+
{ fn: onLocalEventCreated, action: EventActionsEnum.OnEventCreated },
|
|
47243
|
+
{ fn: onLocalEventUpdated, action: EventActionsEnum.OnEventUpdated },
|
|
47244
|
+
{ fn: onLocalEventDeleted, action: EventActionsEnum.OnEventDeleted },
|
|
46791
47245
|
]);
|
|
46792
47246
|
}
|
|
46793
47247
|
notifyChange({ origin, loading, error }) {
|
|
@@ -46799,7 +47253,7 @@ class EventLiveCollectionController extends LiveCollectionController {
|
|
|
46799
47253
|
.map(eventId => pullFromCache(['event', 'get', eventId]))
|
|
46800
47254
|
.filter(isNonNullable)
|
|
46801
47255
|
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
|
|
46802
|
-
if (!this.shouldNotify(data) && origin ===
|
|
47256
|
+
if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
|
|
46803
47257
|
return;
|
|
46804
47258
|
this.callback({
|
|
46805
47259
|
data,
|
|
@@ -46837,6 +47291,143 @@ const getEvents = (params, callback, config) => {
|
|
|
46837
47291
|
};
|
|
46838
47292
|
};
|
|
46839
47293
|
|
|
47294
|
+
class MyEventPaginationController extends PaginationController {
|
|
47295
|
+
async getRequest(queryParams, token) {
|
|
47296
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
47297
|
+
const options = token ? { token } : { limit };
|
|
47298
|
+
const { data: response } = await this.http.get(`/api/v1/events/me/rsvps`, { params: Object.assign(Object.assign({}, params), { options }) });
|
|
47299
|
+
return response;
|
|
47300
|
+
}
|
|
47301
|
+
}
|
|
47302
|
+
|
|
47303
|
+
class MyEventQueryStreamController extends QueryStreamController {
|
|
47304
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
47305
|
+
super(query, cacheKey);
|
|
47306
|
+
this.notifyChange = notifyChange;
|
|
47307
|
+
this.preparePayload = preparePayload;
|
|
47308
|
+
}
|
|
47309
|
+
async saveToMainDB(response) {
|
|
47310
|
+
const processedPayload = this.preparePayload(response);
|
|
47311
|
+
const client = getActiveClient();
|
|
47312
|
+
const cachedAt = client.cache && Date.now();
|
|
47313
|
+
if (client.cache)
|
|
47314
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
47315
|
+
}
|
|
47316
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
47317
|
+
var _a, _b;
|
|
47318
|
+
if (refresh) {
|
|
47319
|
+
pushToCache(this.cacheKey, { data: response.events.map(getResolver('event')) });
|
|
47320
|
+
}
|
|
47321
|
+
else {
|
|
47322
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
47323
|
+
const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
47324
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...events, ...response.events.map(getResolver('event'))])] }));
|
|
47325
|
+
}
|
|
47326
|
+
}
|
|
47327
|
+
reactor(action) {
|
|
47328
|
+
return (event) => {
|
|
47329
|
+
var _a;
|
|
47330
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
47331
|
+
if (!collection)
|
|
47332
|
+
return;
|
|
47333
|
+
if (action === EventActionsEnum.OnEventCreated) {
|
|
47334
|
+
const client = getActiveClient();
|
|
47335
|
+
if (client.userId !== event.userId)
|
|
47336
|
+
return;
|
|
47337
|
+
collection.data = [...new Set([event.eventId, ...collection.data])];
|
|
47338
|
+
}
|
|
47339
|
+
if (action === EventActionsEnum.OnEventDeleted) {
|
|
47340
|
+
collection.data = collection.data.filter(eventId => eventId !== event.eventId);
|
|
47341
|
+
}
|
|
47342
|
+
pushToCache(this.cacheKey, collection);
|
|
47343
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
47344
|
+
};
|
|
47345
|
+
}
|
|
47346
|
+
subscribeRTE(createSubscriber) {
|
|
47347
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
47348
|
+
}
|
|
47349
|
+
}
|
|
47350
|
+
|
|
47351
|
+
class MyEventLiveCollectionController extends LiveCollectionController {
|
|
47352
|
+
constructor(query, callback) {
|
|
47353
|
+
const queryStreamId = hash(query);
|
|
47354
|
+
const cacheKey = ['event', 'collection', queryStreamId];
|
|
47355
|
+
const paginationController = new MyEventPaginationController(query);
|
|
47356
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
47357
|
+
this.query = query;
|
|
47358
|
+
this.queryStreamController = new MyEventQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventPayload);
|
|
47359
|
+
this.callback = callback.bind(this);
|
|
47360
|
+
this.loadPage({ initial: true });
|
|
47361
|
+
}
|
|
47362
|
+
setup() {
|
|
47363
|
+
var _a;
|
|
47364
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
47365
|
+
if (!collection)
|
|
47366
|
+
pushToCache(this.cacheKey, { data: [], params: {} });
|
|
47367
|
+
}
|
|
47368
|
+
async persistModel(queryPayload) {
|
|
47369
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
47370
|
+
}
|
|
47371
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
47372
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
47373
|
+
}
|
|
47374
|
+
startSubscription() {
|
|
47375
|
+
return this.queryStreamController.subscribeRTE([
|
|
47376
|
+
{ fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
|
|
47377
|
+
{ fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
|
|
47378
|
+
{ fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
|
|
47379
|
+
{ fn: onLocalEventCreated, action: EventActionsEnum.OnEventCreated },
|
|
47380
|
+
{ fn: onLocalEventUpdated, action: EventActionsEnum.OnEventUpdated },
|
|
47381
|
+
{ fn: onLocalEventDeleted, action: EventActionsEnum.OnEventDeleted },
|
|
47382
|
+
]);
|
|
47383
|
+
}
|
|
47384
|
+
notifyChange({ origin, loading, error }) {
|
|
47385
|
+
var _a, _b;
|
|
47386
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
47387
|
+
if (!collection)
|
|
47388
|
+
return;
|
|
47389
|
+
const data = ((_b = collection.data
|
|
47390
|
+
.map(eventId => pullFromCache(['event', 'get', eventId]))
|
|
47391
|
+
.filter(isNonNullable)
|
|
47392
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
|
|
47393
|
+
if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
|
|
47394
|
+
return;
|
|
47395
|
+
this.callback({
|
|
47396
|
+
data,
|
|
47397
|
+
error,
|
|
47398
|
+
loading,
|
|
47399
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
47400
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
47401
|
+
});
|
|
47402
|
+
}
|
|
47403
|
+
}
|
|
47404
|
+
|
|
47405
|
+
/**
|
|
47406
|
+
* Get my events
|
|
47407
|
+
*
|
|
47408
|
+
* @param params the query parameters
|
|
47409
|
+
* @param callback the callback to be called when the events are updated
|
|
47410
|
+
* @returns events
|
|
47411
|
+
*
|
|
47412
|
+
* @category Event Live Collection
|
|
47413
|
+
*
|
|
47414
|
+
*/
|
|
47415
|
+
const getMyEvents = (params, callback, config) => {
|
|
47416
|
+
const { log, cache } = getActiveClient();
|
|
47417
|
+
if (!cache)
|
|
47418
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
47419
|
+
const timestamp = Date.now();
|
|
47420
|
+
log(`getMyEvents: (tmpid: ${timestamp}) > listen`);
|
|
47421
|
+
const myEventLiveCollection = new MyEventLiveCollectionController(params, callback);
|
|
47422
|
+
const disposers = myEventLiveCollection.startSubscription();
|
|
47423
|
+
const cacheKey = myEventLiveCollection.getCacheKey();
|
|
47424
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
47425
|
+
return () => {
|
|
47426
|
+
log(`getMyEvents (tmpid: ${timestamp}) > dispose`);
|
|
47427
|
+
disposers.forEach(fn => fn());
|
|
47428
|
+
};
|
|
47429
|
+
};
|
|
47430
|
+
|
|
46840
47431
|
var index = /*#__PURE__*/Object.freeze({
|
|
46841
47432
|
__proto__: null,
|
|
46842
47433
|
createEvent: createEvent,
|
|
@@ -46845,8 +47436,17 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
46845
47436
|
onEventCreated: onEventCreated,
|
|
46846
47437
|
onEventUpdated: onEventUpdated,
|
|
46847
47438
|
onEventDeleted: onEventDeleted,
|
|
47439
|
+
onLocalEventCreated: onLocalEventCreated,
|
|
47440
|
+
onLocalEventUpdated: onLocalEventUpdated,
|
|
47441
|
+
onLocalEventDeleted: onLocalEventDeleted,
|
|
47442
|
+
onRSVPCreated: onRSVPCreated,
|
|
47443
|
+
onRSVPUpdated: onRSVPUpdated,
|
|
47444
|
+
onLocalRSVPCreated: onLocalRSVPCreated,
|
|
47445
|
+
onLocalRSVPUpdated: onLocalRSVPUpdated,
|
|
46848
47446
|
getEvent: getEvent,
|
|
46849
|
-
getEvents: getEvents
|
|
47447
|
+
getEvents: getEvents,
|
|
47448
|
+
getMyEvents: getMyEvents,
|
|
47449
|
+
getRSVPs: getRSVPs
|
|
46850
47450
|
});
|
|
46851
47451
|
|
|
46852
|
-
export { API_REGIONS, index$4 as AdRepository, AmityEventOriginType, AmityEventStatus, AmityEventType, index$c as CategoryRepository, index$g as ChannelRepository, index$p as Client, index$b as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$d as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, index as EventRepository, FeedDataTypeEnum, index$a as FeedRepository, FeedSortByEnum, FeedSourceEnum, FileAccessTypeEnum, index$m as FileRepository, FileType, GET_WATCHER_URLS, index$2 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index$1 as LiveReactionRepository, index$6 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$k as MessageRepository, index$7 as PollRepository, PostContentType, index$9 as PostRepository, PostStructureType, index$l as ReactionRepository, index$5 as StoryRepository, index$8 as StreamRepository, index$j as SubChannelRepository, SubscriptionLevels, index$n as UserRepository, UserTypeEnum, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveReactionTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$3 as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };
|
|
47452
|
+
export { API_REGIONS, index$4 as AdRepository, AmityEventOriginType, AmityEventResponseStatus, AmityEventStatus, AmityEventType, index$c as CategoryRepository, index$g as ChannelRepository, index$p as Client, index$b as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$d as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, index as EventRepository, FeedDataTypeEnum, index$a as FeedRepository, FeedSortByEnum, FeedSourceEnum, FileAccessTypeEnum, index$m as FileRepository, FileType, GET_WATCHER_URLS, index$2 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index$1 as LiveReactionRepository, index$6 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$k as MessageRepository, index$7 as PollRepository, PostContentType, index$9 as PostRepository, PostStructureType, index$l as ReactionRepository, index$5 as StoryRepository, index$8 as StreamRepository, index$j as SubChannelRepository, SubscriptionLevels, index$n as UserRepository, UserTypeEnum, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveReactionTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$3 as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };
|