@amityco/ts-sdk 7.11.1-cef76519.0 → 7.11.1-ed060e83.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 +3 -0
- 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 +15 -0
- package/dist/eventRepository/api/deleteEvent.d.ts.map +1 -0
- package/dist/eventRepository/api/index.d.ts +1 -0
- package/dist/eventRepository/api/index.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/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/index.cjs.js +370 -54
- package/dist/index.esm.js +371 -55
- 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);
|
|
@@ -30428,57 +30441,6 @@ const updateEvent = async (eventId, bundle) => {
|
|
|
30428
30441
|
};
|
|
30429
30442
|
/* end_public_function */
|
|
30430
30443
|
|
|
30431
|
-
/**
|
|
30432
|
-
* ```js
|
|
30433
|
-
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30434
|
-
* const dispose = EventRepository.onEventCreated(event => {
|
|
30435
|
-
* // ...
|
|
30436
|
-
* })
|
|
30437
|
-
* ```
|
|
30438
|
-
*
|
|
30439
|
-
* Fired when a {@link Amity.Event} has been created
|
|
30440
|
-
*
|
|
30441
|
-
* @param callback The function to call when the event was fired
|
|
30442
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30443
|
-
*
|
|
30444
|
-
* @category Event Events
|
|
30445
|
-
*/
|
|
30446
|
-
const onEventCreated = (callback) => createEventEventSubscriber('event.created', callback);
|
|
30447
|
-
|
|
30448
|
-
/**
|
|
30449
|
-
* ```js
|
|
30450
|
-
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30451
|
-
* const dispose = EventRepository.onEventUpdated(event => {
|
|
30452
|
-
* // ...
|
|
30453
|
-
* })
|
|
30454
|
-
* ```
|
|
30455
|
-
*
|
|
30456
|
-
* Fired when a {@link Amity.Event} has been updated
|
|
30457
|
-
*
|
|
30458
|
-
* @param callback The function to call when the event was fired
|
|
30459
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30460
|
-
*
|
|
30461
|
-
* @category Event Events
|
|
30462
|
-
*/
|
|
30463
|
-
const onEventUpdated = (callback) => createEventEventSubscriber('event.updated', callback);
|
|
30464
|
-
|
|
30465
|
-
/**
|
|
30466
|
-
* ```js
|
|
30467
|
-
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30468
|
-
* const dispose = EventRepository.onEventDeleted(event => {
|
|
30469
|
-
* // ...
|
|
30470
|
-
* })
|
|
30471
|
-
* ```
|
|
30472
|
-
*
|
|
30473
|
-
* Fired when a {@link Amity.Event} has been deleted
|
|
30474
|
-
*
|
|
30475
|
-
* @param callback The function to call when the event was fired
|
|
30476
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30477
|
-
*
|
|
30478
|
-
* @category Event Events
|
|
30479
|
-
*/
|
|
30480
|
-
const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted', callback);
|
|
30481
|
-
|
|
30482
30444
|
/* begin_public_function
|
|
30483
30445
|
id: event.get
|
|
30484
30446
|
*/
|
|
@@ -30537,6 +30499,91 @@ getEvent$1.locally = (eventId) => {
|
|
|
30537
30499
|
};
|
|
30538
30500
|
};
|
|
30539
30501
|
|
|
30502
|
+
/* begin_public_function
|
|
30503
|
+
id: event.delete
|
|
30504
|
+
*/
|
|
30505
|
+
/**
|
|
30506
|
+
* ```js
|
|
30507
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30508
|
+
* const { success } = await EventRepository.deleteEvent(eventId)
|
|
30509
|
+
* ```
|
|
30510
|
+
*
|
|
30511
|
+
* Deletes a {@link Amity.Event}
|
|
30512
|
+
*
|
|
30513
|
+
* @param eventId The {@link Amity.Event} ID to delete
|
|
30514
|
+
*
|
|
30515
|
+
* @category Event API
|
|
30516
|
+
* @async
|
|
30517
|
+
*/
|
|
30518
|
+
const deleteEvent = async (eventId) => {
|
|
30519
|
+
const client = getActiveClient();
|
|
30520
|
+
client.log('event/deleteEvent', eventId);
|
|
30521
|
+
const event = await getEvent$1(eventId);
|
|
30522
|
+
await client.http.delete(`/api/v3/events/${eventId}`);
|
|
30523
|
+
const deletedEvent = Object.assign(Object.assign({}, event.data), { isDeleted: true });
|
|
30524
|
+
upsertInCache(['event', 'get', eventId], deletedEvent);
|
|
30525
|
+
fireEvent('event.deleted', {
|
|
30526
|
+
users: [],
|
|
30527
|
+
files: [],
|
|
30528
|
+
communities: [],
|
|
30529
|
+
videoStreamings: [],
|
|
30530
|
+
events: [deletedEvent],
|
|
30531
|
+
discussionCommunities: [],
|
|
30532
|
+
});
|
|
30533
|
+
};
|
|
30534
|
+
/* end_public_function */
|
|
30535
|
+
|
|
30536
|
+
/**
|
|
30537
|
+
* ```js
|
|
30538
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30539
|
+
* const dispose = EventRepository.onEventCreated(event => {
|
|
30540
|
+
* // ...
|
|
30541
|
+
* })
|
|
30542
|
+
* ```
|
|
30543
|
+
*
|
|
30544
|
+
* Fired when a {@link Amity.Event} has been created
|
|
30545
|
+
*
|
|
30546
|
+
* @param callback The function to call when the event was fired
|
|
30547
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30548
|
+
*
|
|
30549
|
+
* @category Event Events
|
|
30550
|
+
*/
|
|
30551
|
+
const onEventCreated = (callback) => createEventEventSubscriber('event.created', callback);
|
|
30552
|
+
|
|
30553
|
+
/**
|
|
30554
|
+
* ```js
|
|
30555
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30556
|
+
* const dispose = EventRepository.onEventUpdated(event => {
|
|
30557
|
+
* // ...
|
|
30558
|
+
* })
|
|
30559
|
+
* ```
|
|
30560
|
+
*
|
|
30561
|
+
* Fired when a {@link Amity.Event} has been updated
|
|
30562
|
+
*
|
|
30563
|
+
* @param callback The function to call when the event was fired
|
|
30564
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30565
|
+
*
|
|
30566
|
+
* @category Event Events
|
|
30567
|
+
*/
|
|
30568
|
+
const onEventUpdated = (callback) => createEventEventSubscriber('event.updated', callback);
|
|
30569
|
+
|
|
30570
|
+
/**
|
|
30571
|
+
* ```js
|
|
30572
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30573
|
+
* const dispose = EventRepository.onEventDeleted(event => {
|
|
30574
|
+
* // ...
|
|
30575
|
+
* })
|
|
30576
|
+
* ```
|
|
30577
|
+
*
|
|
30578
|
+
* Fired when a {@link Amity.Event} has been deleted
|
|
30579
|
+
*
|
|
30580
|
+
* @param callback The function to call when the event was fired
|
|
30581
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30582
|
+
*
|
|
30583
|
+
* @category Event Events
|
|
30584
|
+
*/
|
|
30585
|
+
const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted', callback);
|
|
30586
|
+
|
|
30540
30587
|
/* begin_public_function
|
|
30541
30588
|
id: event.get
|
|
30542
30589
|
*/
|
|
@@ -30566,14 +30613,283 @@ const getEvent = (eventId, callback) => {
|
|
|
30566
30613
|
};
|
|
30567
30614
|
/* end_public_function */
|
|
30568
30615
|
|
|
30616
|
+
var EventActionsEnum;
|
|
30617
|
+
(function (EventActionsEnum) {
|
|
30618
|
+
EventActionsEnum["OnEventCreated"] = "onEventCreated";
|
|
30619
|
+
EventActionsEnum["OnEventUpdated"] = "onEventUpdated";
|
|
30620
|
+
EventActionsEnum["OnEventDeleted"] = "onEventDeleted";
|
|
30621
|
+
})(EventActionsEnum || (EventActionsEnum = {}));
|
|
30622
|
+
|
|
30623
|
+
class EventPaginationController extends PaginationController {
|
|
30624
|
+
async getRequest(queryParams, token) {
|
|
30625
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
30626
|
+
const options = token ? { token } : { limit };
|
|
30627
|
+
const { data: response } = await this.http.get(`/api/v1/events`, { params: Object.assign(Object.assign({}, params), { options }) });
|
|
30628
|
+
return response;
|
|
30629
|
+
}
|
|
30630
|
+
}
|
|
30631
|
+
|
|
30632
|
+
class EventQueryStreamController extends QueryStreamController {
|
|
30633
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
30634
|
+
super(query, cacheKey);
|
|
30635
|
+
this.notifyChange = notifyChange;
|
|
30636
|
+
this.preparePayload = preparePayload;
|
|
30637
|
+
}
|
|
30638
|
+
async saveToMainDB(response) {
|
|
30639
|
+
const processedPayload = this.preparePayload(response);
|
|
30640
|
+
const client = getActiveClient();
|
|
30641
|
+
const cachedAt = client.cache && Date.now();
|
|
30642
|
+
if (client.cache)
|
|
30643
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
30644
|
+
}
|
|
30645
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
30646
|
+
var _a, _b;
|
|
30647
|
+
if (refresh) {
|
|
30648
|
+
pushToCache(this.cacheKey, { data: response.events.map(getResolver('event')) });
|
|
30649
|
+
}
|
|
30650
|
+
else {
|
|
30651
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30652
|
+
const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
30653
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...events, ...response.events.map(getResolver('event'))])] }));
|
|
30654
|
+
}
|
|
30655
|
+
}
|
|
30656
|
+
reactor(action) {
|
|
30657
|
+
return (event) => {
|
|
30658
|
+
var _a;
|
|
30659
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30660
|
+
if (!collection)
|
|
30661
|
+
return;
|
|
30662
|
+
if (action === EventActionsEnum.OnEventCreated) {
|
|
30663
|
+
collection.data = [...new Set([event.eventId, ...collection.data])];
|
|
30664
|
+
}
|
|
30665
|
+
if (action === EventActionsEnum.OnEventDeleted) {
|
|
30666
|
+
collection.data = collection.data.filter(eventId => eventId !== event.eventId);
|
|
30667
|
+
}
|
|
30668
|
+
pushToCache(this.cacheKey, collection);
|
|
30669
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
30670
|
+
};
|
|
30671
|
+
}
|
|
30672
|
+
subscribeRTE(createSubscriber) {
|
|
30673
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
30674
|
+
}
|
|
30675
|
+
}
|
|
30676
|
+
|
|
30677
|
+
class EventLiveCollectionController extends LiveCollectionController {
|
|
30678
|
+
constructor(query, callback) {
|
|
30679
|
+
const queryStreamId = hash__default["default"](query);
|
|
30680
|
+
const cacheKey = ['event', 'collection', queryStreamId];
|
|
30681
|
+
const paginationController = new EventPaginationController(query);
|
|
30682
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
30683
|
+
this.query = query;
|
|
30684
|
+
this.queryStreamController = new EventQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventPayload);
|
|
30685
|
+
this.callback = callback.bind(this);
|
|
30686
|
+
this.loadPage({ initial: true });
|
|
30687
|
+
}
|
|
30688
|
+
setup() {
|
|
30689
|
+
var _a;
|
|
30690
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30691
|
+
if (!collection)
|
|
30692
|
+
pushToCache(this.cacheKey, { data: [], params: {} });
|
|
30693
|
+
}
|
|
30694
|
+
async persistModel(queryPayload) {
|
|
30695
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
30696
|
+
}
|
|
30697
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
30698
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
30699
|
+
}
|
|
30700
|
+
startSubscription() {
|
|
30701
|
+
return this.queryStreamController.subscribeRTE([
|
|
30702
|
+
{ fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
|
|
30703
|
+
{ fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
|
|
30704
|
+
{ fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
|
|
30705
|
+
]);
|
|
30706
|
+
}
|
|
30707
|
+
notifyChange({ origin, loading, error }) {
|
|
30708
|
+
var _a, _b;
|
|
30709
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30710
|
+
if (!collection)
|
|
30711
|
+
return;
|
|
30712
|
+
const data = ((_b = collection.data
|
|
30713
|
+
.map(eventId => pullFromCache(['event', 'get', eventId]))
|
|
30714
|
+
.filter(isNonNullable)
|
|
30715
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
|
|
30716
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
30717
|
+
return;
|
|
30718
|
+
this.callback({
|
|
30719
|
+
data,
|
|
30720
|
+
error,
|
|
30721
|
+
loading,
|
|
30722
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
30723
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
30724
|
+
});
|
|
30725
|
+
}
|
|
30726
|
+
}
|
|
30727
|
+
|
|
30728
|
+
/**
|
|
30729
|
+
* Get events
|
|
30730
|
+
*
|
|
30731
|
+
* @param params the query parameters
|
|
30732
|
+
* @param callback the callback to be called when the events are updated
|
|
30733
|
+
* @returns events
|
|
30734
|
+
*
|
|
30735
|
+
* @category Event Live Collection
|
|
30736
|
+
*
|
|
30737
|
+
*/
|
|
30738
|
+
const getEvents = (params, callback, config) => {
|
|
30739
|
+
const { log, cache } = getActiveClient();
|
|
30740
|
+
if (!cache)
|
|
30741
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
30742
|
+
const timestamp = Date.now();
|
|
30743
|
+
log(`getEvents: (tmpid: ${timestamp}) > listen`);
|
|
30744
|
+
const eventLiveCollection = new EventLiveCollectionController(params, callback);
|
|
30745
|
+
const disposers = eventLiveCollection.startSubscription();
|
|
30746
|
+
const cacheKey = eventLiveCollection.getCacheKey();
|
|
30747
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
30748
|
+
return () => {
|
|
30749
|
+
log(`getEvents (tmpid: ${timestamp}) > dispose`);
|
|
30750
|
+
disposers.forEach(fn => fn());
|
|
30751
|
+
};
|
|
30752
|
+
};
|
|
30753
|
+
|
|
30754
|
+
class MyEventPaginationController extends PaginationController {
|
|
30755
|
+
async getRequest(queryParams, token) {
|
|
30756
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
30757
|
+
const options = token ? { token } : { limit };
|
|
30758
|
+
const { data: response } = await this.http.get(`/api/v1/events/me/rsvps`, { params: Object.assign(Object.assign({}, params), { options }) });
|
|
30759
|
+
return response;
|
|
30760
|
+
}
|
|
30761
|
+
}
|
|
30762
|
+
|
|
30763
|
+
class MyEventQueryStreamController extends QueryStreamController {
|
|
30764
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
30765
|
+
super(query, cacheKey);
|
|
30766
|
+
this.notifyChange = notifyChange;
|
|
30767
|
+
this.preparePayload = preparePayload;
|
|
30768
|
+
}
|
|
30769
|
+
async saveToMainDB(response) {
|
|
30770
|
+
const processedPayload = this.preparePayload(response);
|
|
30771
|
+
const client = getActiveClient();
|
|
30772
|
+
const cachedAt = client.cache && Date.now();
|
|
30773
|
+
if (client.cache)
|
|
30774
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
30775
|
+
}
|
|
30776
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
30777
|
+
var _a, _b;
|
|
30778
|
+
if (refresh) {
|
|
30779
|
+
pushToCache(this.cacheKey, { data: response.events.map(getResolver('event')) });
|
|
30780
|
+
}
|
|
30781
|
+
else {
|
|
30782
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30783
|
+
const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
30784
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...events, ...response.events.map(getResolver('event'))])] }));
|
|
30785
|
+
}
|
|
30786
|
+
}
|
|
30787
|
+
reactor(action) {
|
|
30788
|
+
return (event) => {
|
|
30789
|
+
var _a;
|
|
30790
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30791
|
+
if (!collection)
|
|
30792
|
+
return;
|
|
30793
|
+
if (action === EventActionsEnum.OnEventDeleted) {
|
|
30794
|
+
collection.data = collection.data.filter(eventId => eventId !== event.eventId);
|
|
30795
|
+
}
|
|
30796
|
+
pushToCache(this.cacheKey, collection);
|
|
30797
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
30798
|
+
};
|
|
30799
|
+
}
|
|
30800
|
+
subscribeRTE(createSubscriber) {
|
|
30801
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
30802
|
+
}
|
|
30803
|
+
}
|
|
30804
|
+
|
|
30805
|
+
class MyEventLiveCollectionController extends LiveCollectionController {
|
|
30806
|
+
constructor(query, callback) {
|
|
30807
|
+
const queryStreamId = hash__default["default"](query);
|
|
30808
|
+
const cacheKey = ['event', 'collection', queryStreamId];
|
|
30809
|
+
const paginationController = new MyEventPaginationController(query);
|
|
30810
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
30811
|
+
this.query = query;
|
|
30812
|
+
this.queryStreamController = new MyEventQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventPayload);
|
|
30813
|
+
this.callback = callback.bind(this);
|
|
30814
|
+
this.loadPage({ initial: true });
|
|
30815
|
+
}
|
|
30816
|
+
setup() {
|
|
30817
|
+
var _a;
|
|
30818
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30819
|
+
if (!collection)
|
|
30820
|
+
pushToCache(this.cacheKey, { data: [], params: {} });
|
|
30821
|
+
}
|
|
30822
|
+
async persistModel(queryPayload) {
|
|
30823
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
30824
|
+
}
|
|
30825
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
30826
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
30827
|
+
}
|
|
30828
|
+
startSubscription() {
|
|
30829
|
+
return this.queryStreamController.subscribeRTE([
|
|
30830
|
+
{ fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
|
|
30831
|
+
{ fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
|
|
30832
|
+
{ fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
|
|
30833
|
+
]);
|
|
30834
|
+
}
|
|
30835
|
+
notifyChange({ origin, loading, error }) {
|
|
30836
|
+
var _a, _b;
|
|
30837
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30838
|
+
if (!collection)
|
|
30839
|
+
return;
|
|
30840
|
+
const data = ((_b = collection.data
|
|
30841
|
+
.map(eventId => pullFromCache(['event', 'get', eventId]))
|
|
30842
|
+
.filter(isNonNullable)
|
|
30843
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
|
|
30844
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
30845
|
+
return;
|
|
30846
|
+
this.callback({
|
|
30847
|
+
data,
|
|
30848
|
+
error,
|
|
30849
|
+
loading,
|
|
30850
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
30851
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
30852
|
+
});
|
|
30853
|
+
}
|
|
30854
|
+
}
|
|
30855
|
+
|
|
30856
|
+
/**
|
|
30857
|
+
* Get my events
|
|
30858
|
+
*
|
|
30859
|
+
* @param params the query parameters
|
|
30860
|
+
* @param callback the callback to be called when the events are updated
|
|
30861
|
+
* @returns events
|
|
30862
|
+
*
|
|
30863
|
+
* @category Event Live Collection
|
|
30864
|
+
*
|
|
30865
|
+
*/
|
|
30866
|
+
const getMyEvents = (params, callback, config) => {
|
|
30867
|
+
const { log, cache } = getActiveClient();
|
|
30868
|
+
if (!cache)
|
|
30869
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
30870
|
+
const timestamp = Date.now();
|
|
30871
|
+
log(`getMyEvents: (tmpid: ${timestamp}) > listen`);
|
|
30872
|
+
const myEventLiveCollection = new MyEventLiveCollectionController(params, callback);
|
|
30873
|
+
const disposers = myEventLiveCollection.startSubscription();
|
|
30874
|
+
const cacheKey = myEventLiveCollection.getCacheKey();
|
|
30875
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
30876
|
+
return () => {
|
|
30877
|
+
log(`getMyEvents (tmpid: ${timestamp}) > dispose`);
|
|
30878
|
+
disposers.forEach(fn => fn());
|
|
30879
|
+
};
|
|
30880
|
+
};
|
|
30881
|
+
|
|
30569
30882
|
var index = /*#__PURE__*/Object.freeze({
|
|
30570
30883
|
__proto__: null,
|
|
30571
30884
|
createEvent: createEvent,
|
|
30572
30885
|
updateEvent: updateEvent,
|
|
30886
|
+
deleteEvent: deleteEvent,
|
|
30573
30887
|
onEventCreated: onEventCreated,
|
|
30574
30888
|
onEventUpdated: onEventUpdated,
|
|
30575
30889
|
onEventDeleted: onEventDeleted,
|
|
30576
|
-
getEvent: getEvent
|
|
30890
|
+
getEvent: getEvent,
|
|
30891
|
+
getEvents: getEvents,
|
|
30892
|
+
getMyEvents: getMyEvents
|
|
30577
30893
|
});
|
|
30578
30894
|
|
|
30579
30895
|
exports.API_REGIONS = API_REGIONS;
|