@amityco/ts-sdk 7.11.1-38ad45e1.0 → 7.11.1-3c94a340.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/permissions.d.ts +5 -1
- package/dist/@types/core/permissions.d.ts.map +1 -1
- package/dist/@types/core/transport.d.ts +1 -1
- package/dist/@types/core/transport.d.ts.map +1 -1
- package/dist/@types/domains/community.d.ts +8 -1
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/@types/domains/event.d.ts +27 -3
- package/dist/@types/domains/event.d.ts.map +1 -1
- package/dist/@types/domains/partials.d.ts +2 -2
- package/dist/@types/domains/partials.d.ts.map +1 -1
- package/dist/core/model/idResolvers.d.ts.map +1 -1
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/eventRepository/api/deleteEvent.d.ts +0 -1
- package/dist/eventRepository/api/deleteEvent.d.ts.map +1 -1
- package/dist/eventRepository/events/enums.d.ts +6 -0
- package/dist/eventRepository/events/enums.d.ts.map +1 -0
- package/dist/eventRepository/events/index.d.ts +3 -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/observers/getEvent.d.ts.map +1 -1
- package/dist/eventRepository/observers/getEvents/LiveCollectionController.d.ts +13 -0
- package/dist/eventRepository/observers/getEvents/LiveCollectionController.d.ts.map +1 -0
- package/dist/eventRepository/observers/getEvents/PaginationController.d.ts +5 -0
- package/dist/eventRepository/observers/getEvents/PaginationController.d.ts.map +1 -0
- package/dist/eventRepository/observers/getEvents/QueryStreamController.d.ts +15 -0
- package/dist/eventRepository/observers/getEvents/QueryStreamController.d.ts.map +1 -0
- package/dist/eventRepository/observers/getEvents.d.ts +12 -0
- package/dist/eventRepository/observers/getEvents.d.ts.map +1 -0
- package/dist/eventRepository/observers/getMyEvents/LiveCollectionController.d.ts +13 -0
- package/dist/eventRepository/observers/getMyEvents/LiveCollectionController.d.ts.map +1 -0
- package/dist/eventRepository/observers/getMyEvents/PaginationController.d.ts +5 -0
- package/dist/eventRepository/observers/getMyEvents/PaginationController.d.ts.map +1 -0
- package/dist/eventRepository/observers/getMyEvents/QueryStreamController.d.ts +15 -0
- package/dist/eventRepository/observers/getMyEvents/QueryStreamController.d.ts.map +1 -0
- package/dist/eventRepository/observers/getMyEvents.d.ts +12 -0
- package/dist/eventRepository/observers/getMyEvents.d.ts.map +1 -0
- package/dist/eventRepository/observers/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/index.cjs.js +356 -10
- package/dist/index.esm.js +357 -11
- package/dist/index.umd.js +3 -3
- package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts +1 -1
- package/dist/utils/linkedObject/eventLinkObject.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -209,6 +209,12 @@ 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["Interested"] = "interested";
|
|
216
|
+
AmityEventResponseStatus["NotGoing"] = "not_going";
|
|
217
|
+
})(exports.AmityEventResponseStatus || (exports.AmityEventResponseStatus = {}));
|
|
212
218
|
|
|
213
219
|
function getVersion() {
|
|
214
220
|
try {
|
|
@@ -658,6 +664,7 @@ const idResolvers = {
|
|
|
658
664
|
notificationTraySeen: ({ userId }) => userId,
|
|
659
665
|
invitation: ({ _id }) => _id,
|
|
660
666
|
joinRequest: ({ joinRequestId }) => joinRequestId,
|
|
667
|
+
event: ({ eventId }) => eventId,
|
|
661
668
|
};
|
|
662
669
|
/**
|
|
663
670
|
* Retrieve the id resolver matching a domain name
|
|
@@ -713,6 +720,8 @@ const PAYLOAD2MODEL = {
|
|
|
713
720
|
notificationTrayItems: 'notificationTrayItem',
|
|
714
721
|
invitations: 'invitation',
|
|
715
722
|
joinRequests: 'joinRequest',
|
|
723
|
+
events: 'event',
|
|
724
|
+
discussionCommunities: 'community',
|
|
716
725
|
};
|
|
717
726
|
/** hidden */
|
|
718
727
|
const isOutdated = (prevData, nextData) => {
|
|
@@ -13684,9 +13693,13 @@ const eventLinkedObject = (event) => {
|
|
|
13684
13693
|
return userLinkedObject(cacheData.data);
|
|
13685
13694
|
},
|
|
13686
13695
|
get discussionCommunity() {
|
|
13687
|
-
if (!event.
|
|
13696
|
+
if (!event.discussionCommunityId)
|
|
13688
13697
|
return;
|
|
13689
|
-
const cacheData = pullFromCache([
|
|
13698
|
+
const cacheData = pullFromCache([
|
|
13699
|
+
'community',
|
|
13700
|
+
'get',
|
|
13701
|
+
event.discussionCommunityId,
|
|
13702
|
+
]);
|
|
13690
13703
|
if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
|
|
13691
13704
|
return;
|
|
13692
13705
|
return communityLinkedObject(cacheData.data);
|
|
@@ -30382,7 +30395,7 @@ const createEvent = async (bundle) => {
|
|
|
30382
30395
|
const client = getActiveClient();
|
|
30383
30396
|
client.log('event/createEvent', bundle);
|
|
30384
30397
|
const { data: payload } = await client.http.post('/api/v1/events', bundle);
|
|
30385
|
-
fireEvent('event.created', payload);
|
|
30398
|
+
fireEvent('local.event.created', payload);
|
|
30386
30399
|
const preparedPayload = prepareEventPayload(payload);
|
|
30387
30400
|
const cachedAt = client.cache && Date.now();
|
|
30388
30401
|
if (client.cache)
|
|
@@ -30416,7 +30429,7 @@ const updateEvent = async (eventId, bundle) => {
|
|
|
30416
30429
|
const client = getActiveClient();
|
|
30417
30430
|
client.log('event/updateEvent', eventId, bundle);
|
|
30418
30431
|
const { data: payload } = await client.http.put(`/api/v1/events/${eventId}`, bundle);
|
|
30419
|
-
fireEvent('event.updated', payload);
|
|
30432
|
+
fireEvent('local.event.updated', payload);
|
|
30420
30433
|
const preparedPayload = prepareEventPayload(payload);
|
|
30421
30434
|
const cachedAt = client.cache && Date.now();
|
|
30422
30435
|
if (client.cache)
|
|
@@ -30498,7 +30511,6 @@ getEvent$1.locally = (eventId) => {
|
|
|
30498
30511
|
* Deletes a {@link Amity.Event}
|
|
30499
30512
|
*
|
|
30500
30513
|
* @param eventId The {@link Amity.Event} ID to delete
|
|
30501
|
-
* @return A success boolean if the {@link Amity.Event} was deleted
|
|
30502
30514
|
*
|
|
30503
30515
|
* @category Event API
|
|
30504
30516
|
* @async
|
|
@@ -30507,10 +30519,10 @@ const deleteEvent = async (eventId) => {
|
|
|
30507
30519
|
const client = getActiveClient();
|
|
30508
30520
|
client.log('event/deleteEvent', eventId);
|
|
30509
30521
|
const event = await getEvent$1(eventId);
|
|
30510
|
-
|
|
30511
|
-
const deletedEvent = Object.assign(Object.assign({}, event.data), { isDeleted:
|
|
30522
|
+
await client.http.delete(`/api/v3/events/${eventId}`);
|
|
30523
|
+
const deletedEvent = Object.assign(Object.assign({}, event.data), { isDeleted: true });
|
|
30512
30524
|
upsertInCache(['event', 'get', eventId], deletedEvent);
|
|
30513
|
-
fireEvent('event.deleted', {
|
|
30525
|
+
fireEvent('local.event.deleted', {
|
|
30514
30526
|
users: [],
|
|
30515
30527
|
files: [],
|
|
30516
30528
|
communities: [],
|
|
@@ -30572,6 +30584,57 @@ const onEventUpdated = (callback) => createEventEventSubscriber('event.updated',
|
|
|
30572
30584
|
*/
|
|
30573
30585
|
const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted', callback);
|
|
30574
30586
|
|
|
30587
|
+
/**
|
|
30588
|
+
* ```js
|
|
30589
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30590
|
+
* const dispose = EventRepository.onLocalEventCreated(event => {
|
|
30591
|
+
* // ...
|
|
30592
|
+
* })
|
|
30593
|
+
* ```
|
|
30594
|
+
*
|
|
30595
|
+
* Fired when a {@link Amity.Event} has been created
|
|
30596
|
+
*
|
|
30597
|
+
* @param callback The function to call when the event was fired
|
|
30598
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30599
|
+
*
|
|
30600
|
+
* @category Event Events
|
|
30601
|
+
*/
|
|
30602
|
+
const onLocalEventCreated = (callback) => createEventEventSubscriber('local.event.created', callback);
|
|
30603
|
+
|
|
30604
|
+
/**
|
|
30605
|
+
* ```js
|
|
30606
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30607
|
+
* const dispose = EventRepository.onLocalEventUpdated(event => {
|
|
30608
|
+
* // ...
|
|
30609
|
+
* })
|
|
30610
|
+
* ```
|
|
30611
|
+
*
|
|
30612
|
+
* Fired when a {@link Amity.Event} has been updated
|
|
30613
|
+
*
|
|
30614
|
+
* @param callback The function to call when the event was fired
|
|
30615
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30616
|
+
*
|
|
30617
|
+
* @category Event Events
|
|
30618
|
+
*/
|
|
30619
|
+
const onLocalEventUpdated = (callback) => createEventEventSubscriber('local.event.updated', callback);
|
|
30620
|
+
|
|
30621
|
+
/**
|
|
30622
|
+
* ```js
|
|
30623
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30624
|
+
* const dispose = EventRepository.onLocalEventDeleted(event => {
|
|
30625
|
+
* // ...
|
|
30626
|
+
* })
|
|
30627
|
+
* ```
|
|
30628
|
+
*
|
|
30629
|
+
* Fired when a {@link Amity.Event} has been deleted
|
|
30630
|
+
*
|
|
30631
|
+
* @param callback The function to call when the event was fired
|
|
30632
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30633
|
+
*
|
|
30634
|
+
* @category Event Events
|
|
30635
|
+
*/
|
|
30636
|
+
const onLocalEventDeleted = (callback) => createEventEventSubscriber('local.event.deleted', callback);
|
|
30637
|
+
|
|
30575
30638
|
/* begin_public_function
|
|
30576
30639
|
id: event.get
|
|
30577
30640
|
*/
|
|
@@ -30595,12 +30658,290 @@ const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted',
|
|
|
30595
30658
|
* @category Event Live Object
|
|
30596
30659
|
*/
|
|
30597
30660
|
const getEvent = (eventId, callback) => {
|
|
30598
|
-
return liveObject(eventId, callback, 'eventId', getEvent$1, [
|
|
30661
|
+
return liveObject(eventId, callback, 'eventId', getEvent$1, [onEventUpdated, onEventDeleted, onLocalEventUpdated, onLocalEventDeleted], {
|
|
30599
30662
|
callbackDataSelector: (data) => (data ? eventLinkedObject(data) : data),
|
|
30600
30663
|
});
|
|
30601
30664
|
};
|
|
30602
30665
|
/* end_public_function */
|
|
30603
30666
|
|
|
30667
|
+
var EventActionsEnum;
|
|
30668
|
+
(function (EventActionsEnum) {
|
|
30669
|
+
EventActionsEnum["OnEventCreated"] = "onEventCreated";
|
|
30670
|
+
EventActionsEnum["OnEventUpdated"] = "onEventUpdated";
|
|
30671
|
+
EventActionsEnum["OnEventDeleted"] = "onEventDeleted";
|
|
30672
|
+
})(EventActionsEnum || (EventActionsEnum = {}));
|
|
30673
|
+
|
|
30674
|
+
class EventPaginationController extends PaginationController {
|
|
30675
|
+
async getRequest(queryParams, token) {
|
|
30676
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
30677
|
+
const options = token ? { token } : { limit };
|
|
30678
|
+
const { data: response } = await this.http.get(`/api/v1/events`, { params: Object.assign(Object.assign({}, params), { options }) });
|
|
30679
|
+
return response;
|
|
30680
|
+
}
|
|
30681
|
+
}
|
|
30682
|
+
|
|
30683
|
+
class EventQueryStreamController extends QueryStreamController {
|
|
30684
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
30685
|
+
super(query, cacheKey);
|
|
30686
|
+
this.notifyChange = notifyChange;
|
|
30687
|
+
this.preparePayload = preparePayload;
|
|
30688
|
+
}
|
|
30689
|
+
async saveToMainDB(response) {
|
|
30690
|
+
const processedPayload = this.preparePayload(response);
|
|
30691
|
+
const client = getActiveClient();
|
|
30692
|
+
const cachedAt = client.cache && Date.now();
|
|
30693
|
+
if (client.cache)
|
|
30694
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
30695
|
+
}
|
|
30696
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
30697
|
+
var _a, _b;
|
|
30698
|
+
if (refresh) {
|
|
30699
|
+
pushToCache(this.cacheKey, { data: response.events.map(getResolver('event')) });
|
|
30700
|
+
}
|
|
30701
|
+
else {
|
|
30702
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30703
|
+
const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
30704
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...events, ...response.events.map(getResolver('event'))])] }));
|
|
30705
|
+
}
|
|
30706
|
+
}
|
|
30707
|
+
reactor(action) {
|
|
30708
|
+
return (event) => {
|
|
30709
|
+
var _a;
|
|
30710
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30711
|
+
if (!collection)
|
|
30712
|
+
return;
|
|
30713
|
+
if (action === EventActionsEnum.OnEventCreated) {
|
|
30714
|
+
collection.data = [...new Set([event.eventId, ...collection.data])];
|
|
30715
|
+
}
|
|
30716
|
+
if (action === EventActionsEnum.OnEventDeleted) {
|
|
30717
|
+
collection.data = collection.data.filter(eventId => eventId !== event.eventId);
|
|
30718
|
+
}
|
|
30719
|
+
pushToCache(this.cacheKey, collection);
|
|
30720
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
30721
|
+
};
|
|
30722
|
+
}
|
|
30723
|
+
subscribeRTE(createSubscriber) {
|
|
30724
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
30725
|
+
}
|
|
30726
|
+
}
|
|
30727
|
+
|
|
30728
|
+
class EventLiveCollectionController extends LiveCollectionController {
|
|
30729
|
+
constructor(query, callback) {
|
|
30730
|
+
const queryStreamId = hash__default["default"](query);
|
|
30731
|
+
const cacheKey = ['event', 'collection', queryStreamId];
|
|
30732
|
+
const paginationController = new EventPaginationController(query);
|
|
30733
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
30734
|
+
this.query = query;
|
|
30735
|
+
this.queryStreamController = new EventQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventPayload);
|
|
30736
|
+
this.callback = callback.bind(this);
|
|
30737
|
+
this.loadPage({ initial: true });
|
|
30738
|
+
}
|
|
30739
|
+
setup() {
|
|
30740
|
+
var _a;
|
|
30741
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30742
|
+
if (!collection)
|
|
30743
|
+
pushToCache(this.cacheKey, { data: [], params: {} });
|
|
30744
|
+
}
|
|
30745
|
+
async persistModel(queryPayload) {
|
|
30746
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
30747
|
+
}
|
|
30748
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
30749
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
30750
|
+
}
|
|
30751
|
+
startSubscription() {
|
|
30752
|
+
return this.queryStreamController.subscribeRTE([
|
|
30753
|
+
{ fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
|
|
30754
|
+
{ fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
|
|
30755
|
+
{ fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
|
|
30756
|
+
{ fn: onLocalEventCreated, action: EventActionsEnum.OnEventCreated },
|
|
30757
|
+
{ fn: onLocalEventUpdated, action: EventActionsEnum.OnEventUpdated },
|
|
30758
|
+
{ fn: onLocalEventDeleted, action: EventActionsEnum.OnEventDeleted },
|
|
30759
|
+
]);
|
|
30760
|
+
}
|
|
30761
|
+
notifyChange({ origin, loading, error }) {
|
|
30762
|
+
var _a, _b;
|
|
30763
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30764
|
+
if (!collection)
|
|
30765
|
+
return;
|
|
30766
|
+
const data = ((_b = collection.data
|
|
30767
|
+
.map(eventId => pullFromCache(['event', 'get', eventId]))
|
|
30768
|
+
.filter(isNonNullable)
|
|
30769
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
|
|
30770
|
+
if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
|
|
30771
|
+
return;
|
|
30772
|
+
this.callback({
|
|
30773
|
+
data,
|
|
30774
|
+
error,
|
|
30775
|
+
loading,
|
|
30776
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
30777
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
30778
|
+
});
|
|
30779
|
+
}
|
|
30780
|
+
}
|
|
30781
|
+
|
|
30782
|
+
/**
|
|
30783
|
+
* Get events
|
|
30784
|
+
*
|
|
30785
|
+
* @param params the query parameters
|
|
30786
|
+
* @param callback the callback to be called when the events are updated
|
|
30787
|
+
* @returns events
|
|
30788
|
+
*
|
|
30789
|
+
* @category Event Live Collection
|
|
30790
|
+
*
|
|
30791
|
+
*/
|
|
30792
|
+
const getEvents = (params, callback, config) => {
|
|
30793
|
+
const { log, cache } = getActiveClient();
|
|
30794
|
+
if (!cache)
|
|
30795
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
30796
|
+
const timestamp = Date.now();
|
|
30797
|
+
log(`getEvents: (tmpid: ${timestamp}) > listen`);
|
|
30798
|
+
const eventLiveCollection = new EventLiveCollectionController(params, callback);
|
|
30799
|
+
const disposers = eventLiveCollection.startSubscription();
|
|
30800
|
+
const cacheKey = eventLiveCollection.getCacheKey();
|
|
30801
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
30802
|
+
return () => {
|
|
30803
|
+
log(`getEvents (tmpid: ${timestamp}) > dispose`);
|
|
30804
|
+
disposers.forEach(fn => fn());
|
|
30805
|
+
};
|
|
30806
|
+
};
|
|
30807
|
+
|
|
30808
|
+
class MyEventPaginationController extends PaginationController {
|
|
30809
|
+
async getRequest(queryParams, token) {
|
|
30810
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
30811
|
+
const options = token ? { token } : { limit };
|
|
30812
|
+
const { data: response } = await this.http.get(`/api/v1/events/me/rsvps`, { params: Object.assign(Object.assign({}, params), { options }) });
|
|
30813
|
+
return response;
|
|
30814
|
+
}
|
|
30815
|
+
}
|
|
30816
|
+
|
|
30817
|
+
class MyEventQueryStreamController extends QueryStreamController {
|
|
30818
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
30819
|
+
super(query, cacheKey);
|
|
30820
|
+
this.notifyChange = notifyChange;
|
|
30821
|
+
this.preparePayload = preparePayload;
|
|
30822
|
+
}
|
|
30823
|
+
async saveToMainDB(response) {
|
|
30824
|
+
const processedPayload = this.preparePayload(response);
|
|
30825
|
+
const client = getActiveClient();
|
|
30826
|
+
const cachedAt = client.cache && Date.now();
|
|
30827
|
+
if (client.cache)
|
|
30828
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
30829
|
+
}
|
|
30830
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
30831
|
+
var _a, _b;
|
|
30832
|
+
if (refresh) {
|
|
30833
|
+
pushToCache(this.cacheKey, { data: response.events.map(getResolver('event')) });
|
|
30834
|
+
}
|
|
30835
|
+
else {
|
|
30836
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30837
|
+
const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
30838
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...events, ...response.events.map(getResolver('event'))])] }));
|
|
30839
|
+
}
|
|
30840
|
+
}
|
|
30841
|
+
reactor(action) {
|
|
30842
|
+
return (event) => {
|
|
30843
|
+
var _a;
|
|
30844
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30845
|
+
if (!collection)
|
|
30846
|
+
return;
|
|
30847
|
+
if (action === EventActionsEnum.OnEventCreated) {
|
|
30848
|
+
const client = getActiveClient();
|
|
30849
|
+
if (client.userId !== event.userId)
|
|
30850
|
+
return;
|
|
30851
|
+
collection.data = [...new Set([event.eventId, ...collection.data])];
|
|
30852
|
+
}
|
|
30853
|
+
if (action === EventActionsEnum.OnEventDeleted) {
|
|
30854
|
+
collection.data = collection.data.filter(eventId => eventId !== event.eventId);
|
|
30855
|
+
}
|
|
30856
|
+
pushToCache(this.cacheKey, collection);
|
|
30857
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
30858
|
+
};
|
|
30859
|
+
}
|
|
30860
|
+
subscribeRTE(createSubscriber) {
|
|
30861
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
30862
|
+
}
|
|
30863
|
+
}
|
|
30864
|
+
|
|
30865
|
+
class MyEventLiveCollectionController extends LiveCollectionController {
|
|
30866
|
+
constructor(query, callback) {
|
|
30867
|
+
const queryStreamId = hash__default["default"](query);
|
|
30868
|
+
const cacheKey = ['event', 'collection', queryStreamId];
|
|
30869
|
+
const paginationController = new MyEventPaginationController(query);
|
|
30870
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
30871
|
+
this.query = query;
|
|
30872
|
+
this.queryStreamController = new MyEventQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventPayload);
|
|
30873
|
+
this.callback = callback.bind(this);
|
|
30874
|
+
this.loadPage({ initial: true });
|
|
30875
|
+
}
|
|
30876
|
+
setup() {
|
|
30877
|
+
var _a;
|
|
30878
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30879
|
+
if (!collection)
|
|
30880
|
+
pushToCache(this.cacheKey, { data: [], params: {} });
|
|
30881
|
+
}
|
|
30882
|
+
async persistModel(queryPayload) {
|
|
30883
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
30884
|
+
}
|
|
30885
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
30886
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
30887
|
+
}
|
|
30888
|
+
startSubscription() {
|
|
30889
|
+
return this.queryStreamController.subscribeRTE([
|
|
30890
|
+
{ fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
|
|
30891
|
+
{ fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
|
|
30892
|
+
{ fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
|
|
30893
|
+
{ fn: onLocalEventCreated, action: EventActionsEnum.OnEventCreated },
|
|
30894
|
+
{ fn: onLocalEventUpdated, action: EventActionsEnum.OnEventUpdated },
|
|
30895
|
+
{ fn: onLocalEventDeleted, action: EventActionsEnum.OnEventDeleted },
|
|
30896
|
+
]);
|
|
30897
|
+
}
|
|
30898
|
+
notifyChange({ origin, loading, error }) {
|
|
30899
|
+
var _a, _b;
|
|
30900
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30901
|
+
if (!collection)
|
|
30902
|
+
return;
|
|
30903
|
+
const data = ((_b = collection.data
|
|
30904
|
+
.map(eventId => pullFromCache(['event', 'get', eventId]))
|
|
30905
|
+
.filter(isNonNullable)
|
|
30906
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
|
|
30907
|
+
if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
|
|
30908
|
+
return;
|
|
30909
|
+
this.callback({
|
|
30910
|
+
data,
|
|
30911
|
+
error,
|
|
30912
|
+
loading,
|
|
30913
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
30914
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
30915
|
+
});
|
|
30916
|
+
}
|
|
30917
|
+
}
|
|
30918
|
+
|
|
30919
|
+
/**
|
|
30920
|
+
* Get my events
|
|
30921
|
+
*
|
|
30922
|
+
* @param params the query parameters
|
|
30923
|
+
* @param callback the callback to be called when the events are updated
|
|
30924
|
+
* @returns events
|
|
30925
|
+
*
|
|
30926
|
+
* @category Event Live Collection
|
|
30927
|
+
*
|
|
30928
|
+
*/
|
|
30929
|
+
const getMyEvents = (params, callback, config) => {
|
|
30930
|
+
const { log, cache } = getActiveClient();
|
|
30931
|
+
if (!cache)
|
|
30932
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
30933
|
+
const timestamp = Date.now();
|
|
30934
|
+
log(`getMyEvents: (tmpid: ${timestamp}) > listen`);
|
|
30935
|
+
const myEventLiveCollection = new MyEventLiveCollectionController(params, callback);
|
|
30936
|
+
const disposers = myEventLiveCollection.startSubscription();
|
|
30937
|
+
const cacheKey = myEventLiveCollection.getCacheKey();
|
|
30938
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
30939
|
+
return () => {
|
|
30940
|
+
log(`getMyEvents (tmpid: ${timestamp}) > dispose`);
|
|
30941
|
+
disposers.forEach(fn => fn());
|
|
30942
|
+
};
|
|
30943
|
+
};
|
|
30944
|
+
|
|
30604
30945
|
var index = /*#__PURE__*/Object.freeze({
|
|
30605
30946
|
__proto__: null,
|
|
30606
30947
|
createEvent: createEvent,
|
|
@@ -30609,7 +30950,12 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
30609
30950
|
onEventCreated: onEventCreated,
|
|
30610
30951
|
onEventUpdated: onEventUpdated,
|
|
30611
30952
|
onEventDeleted: onEventDeleted,
|
|
30612
|
-
|
|
30953
|
+
onLocalEventCreated: onLocalEventCreated,
|
|
30954
|
+
onLocalEventUpdated: onLocalEventUpdated,
|
|
30955
|
+
onLocalEventDeleted: onLocalEventDeleted,
|
|
30956
|
+
getEvent: getEvent,
|
|
30957
|
+
getEvents: getEvents,
|
|
30958
|
+
getMyEvents: getMyEvents
|
|
30613
30959
|
});
|
|
30614
30960
|
|
|
30615
30961
|
exports.API_REGIONS = API_REGIONS;
|