@amityco/ts-sdk 7.11.1-d19e0f3d.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/payload.d.ts +4 -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/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 +33 -7
- 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/createEvent.d.ts +2 -2
- 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 +2 -0
- package/dist/eventRepository/api/index.d.ts.map +1 -1
- package/dist/eventRepository/api/updateEvent.d.ts +17 -0
- package/dist/eventRepository/api/updateEvent.d.ts.map +1 -0
- 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 +4 -0
- package/dist/eventRepository/events/index.d.ts.map +1 -0
- package/dist/eventRepository/events/onEventCreated.d.ts +17 -0
- package/dist/eventRepository/events/onEventCreated.d.ts.map +1 -0
- package/dist/eventRepository/events/onEventDeleted.d.ts +17 -0
- package/dist/eventRepository/events/onEventDeleted.d.ts.map +1 -0
- package/dist/eventRepository/events/onEventUpdated.d.ts +17 -0
- package/dist/eventRepository/events/onEventUpdated.d.ts.map +1 -0
- package/dist/eventRepository/index.d.ts +2 -0
- package/dist/eventRepository/index.d.ts.map +1 -1
- package/dist/eventRepository/internalApi/getEvent.d.ts +32 -0
- package/dist/eventRepository/internalApi/getEvent.d.ts.map +1 -0
- package/dist/eventRepository/internalApi/index.d.ts +2 -0
- package/dist/eventRepository/internalApi/index.d.ts.map +1 -0
- package/dist/eventRepository/observers/getEvent.d.ts +21 -0
- package/dist/eventRepository/observers/getEvent.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 +4 -0
- package/dist/eventRepository/observers/index.d.ts.map +1 -0
- package/dist/eventRepository/utils/createEventEventSubscriber.d.ts +2 -0
- package/dist/eventRepository/utils/createEventEventSubscriber.d.ts.map +1 -0
- package/dist/eventRepository/utils/index.d.ts +1 -0
- package/dist/eventRepository/utils/index.d.ts.map +1 -1
- package/dist/index.cjs.js +519 -6
- package/dist/index.esm.js +520 -7
- 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.esm.js
CHANGED
|
@@ -194,6 +194,12 @@ 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["Interested"] = "interested";
|
|
201
|
+
AmityEventResponseStatus["NotGoing"] = "not_going";
|
|
202
|
+
})(AmityEventResponseStatus || (AmityEventResponseStatus = {}));
|
|
197
203
|
|
|
198
204
|
function getVersion() {
|
|
199
205
|
try {
|
|
@@ -643,6 +649,7 @@ const idResolvers = {
|
|
|
643
649
|
notificationTraySeen: ({ userId }) => userId,
|
|
644
650
|
invitation: ({ _id }) => _id,
|
|
645
651
|
joinRequest: ({ joinRequestId }) => joinRequestId,
|
|
652
|
+
event: ({ eventId }) => eventId,
|
|
646
653
|
};
|
|
647
654
|
/**
|
|
648
655
|
* Retrieve the id resolver matching a domain name
|
|
@@ -698,6 +705,8 @@ const PAYLOAD2MODEL = {
|
|
|
698
705
|
notificationTrayItems: 'notificationTrayItem',
|
|
699
706
|
invitations: 'invitation',
|
|
700
707
|
joinRequests: 'joinRequest',
|
|
708
|
+
events: 'event',
|
|
709
|
+
discussionCommunities: 'community',
|
|
701
710
|
};
|
|
702
711
|
/** hidden */
|
|
703
712
|
const isOutdated = (prevData, nextData) => {
|
|
@@ -29776,9 +29785,13 @@ const eventLinkedObject = (event) => {
|
|
|
29776
29785
|
return userLinkedObject(cacheData.data);
|
|
29777
29786
|
},
|
|
29778
29787
|
get discussionCommunity() {
|
|
29779
|
-
if (!event.
|
|
29788
|
+
if (!event.discussionCommunityId)
|
|
29780
29789
|
return;
|
|
29781
|
-
const cacheData = pullFromCache([
|
|
29790
|
+
const cacheData = pullFromCache([
|
|
29791
|
+
'community',
|
|
29792
|
+
'get',
|
|
29793
|
+
event.discussionCommunityId,
|
|
29794
|
+
]);
|
|
29782
29795
|
if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
|
|
29783
29796
|
return;
|
|
29784
29797
|
return communityLinkedObject(cacheData.data);
|
|
@@ -46433,13 +46446,33 @@ const prepareEventPayload = (rawPayload) => {
|
|
|
46433
46446
|
return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser) });
|
|
46434
46447
|
};
|
|
46435
46448
|
|
|
46449
|
+
const createEventEventSubscriber = (event, callback) => {
|
|
46450
|
+
const client = getActiveClient();
|
|
46451
|
+
const filter = (payload) => {
|
|
46452
|
+
const unpackedPayload = prepareEventPayload(payload);
|
|
46453
|
+
if (!client.cache) {
|
|
46454
|
+
callback(unpackedPayload.events[0]);
|
|
46455
|
+
}
|
|
46456
|
+
else {
|
|
46457
|
+
ingestInCache(unpackedPayload);
|
|
46458
|
+
const event = pullFromCache([
|
|
46459
|
+
'event',
|
|
46460
|
+
'get',
|
|
46461
|
+
unpackedPayload.events[0].eventId,
|
|
46462
|
+
]);
|
|
46463
|
+
callback(event.data);
|
|
46464
|
+
}
|
|
46465
|
+
};
|
|
46466
|
+
return createEventSubscriber(client, event, event, filter);
|
|
46467
|
+
};
|
|
46468
|
+
|
|
46436
46469
|
/* begin_public_function
|
|
46437
46470
|
id: event.create
|
|
46438
46471
|
*/
|
|
46439
46472
|
/**
|
|
46440
46473
|
* ```js
|
|
46441
|
-
* import {
|
|
46442
|
-
* const
|
|
46474
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
46475
|
+
* const response = await EventRepository.createEvent(bundle)
|
|
46443
46476
|
* ```
|
|
46444
46477
|
*
|
|
46445
46478
|
* Creates an {@link Amity.Event}
|
|
@@ -46454,11 +46487,11 @@ const createEvent = async (bundle) => {
|
|
|
46454
46487
|
const client = getActiveClient();
|
|
46455
46488
|
client.log('event/createEvent', bundle);
|
|
46456
46489
|
const { data: payload } = await client.http.post('/api/v1/events', bundle);
|
|
46490
|
+
fireEvent('event.created', payload);
|
|
46457
46491
|
const preparedPayload = prepareEventPayload(payload);
|
|
46458
46492
|
const cachedAt = client.cache && Date.now();
|
|
46459
46493
|
if (client.cache)
|
|
46460
46494
|
ingestInCache(preparedPayload, { cachedAt });
|
|
46461
|
-
fireEvent('event.created', preparedPayload);
|
|
46462
46495
|
return {
|
|
46463
46496
|
data: eventLinkedObject(preparedPayload.events[0]),
|
|
46464
46497
|
cachedAt,
|
|
@@ -46466,9 +46499,489 @@ const createEvent = async (bundle) => {
|
|
|
46466
46499
|
};
|
|
46467
46500
|
/* end_public_function */
|
|
46468
46501
|
|
|
46502
|
+
/* begin_public_function
|
|
46503
|
+
id: event.update
|
|
46504
|
+
*/
|
|
46505
|
+
/**
|
|
46506
|
+
* ```js
|
|
46507
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
46508
|
+
* const response = await EventRepository.updateEvent(eventId, bundle)
|
|
46509
|
+
* ```
|
|
46510
|
+
*
|
|
46511
|
+
* Updates an {@link Amity.Event}
|
|
46512
|
+
*
|
|
46513
|
+
* @param eventId The ID of the {@link Amity.Event} to edit
|
|
46514
|
+
* @param bundle The data necessary to update an existing {@link Amity.Event}
|
|
46515
|
+
* @returns the updated {@link Amity.Event}
|
|
46516
|
+
*
|
|
46517
|
+
* @category Event API
|
|
46518
|
+
* @async
|
|
46519
|
+
*/
|
|
46520
|
+
const updateEvent = async (eventId, bundle) => {
|
|
46521
|
+
const client = getActiveClient();
|
|
46522
|
+
client.log('event/updateEvent', eventId, bundle);
|
|
46523
|
+
const { data: payload } = await client.http.put(`/api/v1/events/${eventId}`, bundle);
|
|
46524
|
+
fireEvent('event.updated', payload);
|
|
46525
|
+
const preparedPayload = prepareEventPayload(payload);
|
|
46526
|
+
const cachedAt = client.cache && Date.now();
|
|
46527
|
+
if (client.cache)
|
|
46528
|
+
ingestInCache(preparedPayload, { cachedAt });
|
|
46529
|
+
return {
|
|
46530
|
+
data: eventLinkedObject(preparedPayload.events.find(event => event.eventId === eventId)),
|
|
46531
|
+
cachedAt,
|
|
46532
|
+
};
|
|
46533
|
+
};
|
|
46534
|
+
/* end_public_function */
|
|
46535
|
+
|
|
46536
|
+
/* begin_public_function
|
|
46537
|
+
id: event.get
|
|
46538
|
+
*/
|
|
46539
|
+
/**
|
|
46540
|
+
* ```js
|
|
46541
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
46542
|
+
* const event = await EventRepository.getEvent(eventId)
|
|
46543
|
+
* ```
|
|
46544
|
+
*
|
|
46545
|
+
* Fetches a {@link Amity.Event} object
|
|
46546
|
+
*
|
|
46547
|
+
* @param eventId the ID of the {@link Amity.Event} to fetch
|
|
46548
|
+
* @returns the associated {@link Amity.Event} object
|
|
46549
|
+
*
|
|
46550
|
+
* @category Event API
|
|
46551
|
+
* @async
|
|
46552
|
+
*/
|
|
46553
|
+
const getEvent$1 = async (eventId) => {
|
|
46554
|
+
const client = getActiveClient();
|
|
46555
|
+
client.log('event/getEvent', eventId);
|
|
46556
|
+
const { data: payload } = await client.http.get(`/api/v3/events/${eventId}`);
|
|
46557
|
+
const data = prepareEventPayload(payload);
|
|
46558
|
+
const cachedAt = client.cache && Date.now();
|
|
46559
|
+
if (client.cache)
|
|
46560
|
+
ingestInCache(data, { cachedAt });
|
|
46561
|
+
return {
|
|
46562
|
+
data: data.events.find(event => event.eventId === eventId),
|
|
46563
|
+
cachedAt,
|
|
46564
|
+
};
|
|
46565
|
+
};
|
|
46566
|
+
/* end_public_function */
|
|
46567
|
+
/**
|
|
46568
|
+
* ```js
|
|
46569
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
46570
|
+
* const event = EventRepository.getEvent.locally(eventId)
|
|
46571
|
+
* ```
|
|
46572
|
+
*
|
|
46573
|
+
* Fetches a {@link Amity.Event} object in cache
|
|
46574
|
+
*
|
|
46575
|
+
* @param eventId the ID of the {@link Amity.Event} to fetch
|
|
46576
|
+
* @returns the associated {@link Amity.Event} object
|
|
46577
|
+
*
|
|
46578
|
+
* @category Event API
|
|
46579
|
+
*/
|
|
46580
|
+
getEvent$1.locally = (eventId) => {
|
|
46581
|
+
const client = getActiveClient();
|
|
46582
|
+
client.log('event/getEvent.locally', eventId);
|
|
46583
|
+
if (!client.cache)
|
|
46584
|
+
return;
|
|
46585
|
+
const cache = pullFromCache(['event', 'get', eventId]);
|
|
46586
|
+
if (!cache)
|
|
46587
|
+
return;
|
|
46588
|
+
return {
|
|
46589
|
+
data: cache.data,
|
|
46590
|
+
cachedAt: cache.cachedAt,
|
|
46591
|
+
};
|
|
46592
|
+
};
|
|
46593
|
+
|
|
46594
|
+
/* begin_public_function
|
|
46595
|
+
id: event.delete
|
|
46596
|
+
*/
|
|
46597
|
+
/**
|
|
46598
|
+
* ```js
|
|
46599
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
46600
|
+
* const { success } = await EventRepository.deleteEvent(eventId)
|
|
46601
|
+
* ```
|
|
46602
|
+
*
|
|
46603
|
+
* Deletes a {@link Amity.Event}
|
|
46604
|
+
*
|
|
46605
|
+
* @param eventId The {@link Amity.Event} ID to delete
|
|
46606
|
+
*
|
|
46607
|
+
* @category Event API
|
|
46608
|
+
* @async
|
|
46609
|
+
*/
|
|
46610
|
+
const deleteEvent = async (eventId) => {
|
|
46611
|
+
const client = getActiveClient();
|
|
46612
|
+
client.log('event/deleteEvent', eventId);
|
|
46613
|
+
const event = await getEvent$1(eventId);
|
|
46614
|
+
await client.http.delete(`/api/v3/events/${eventId}`);
|
|
46615
|
+
const deletedEvent = Object.assign(Object.assign({}, event.data), { isDeleted: true });
|
|
46616
|
+
upsertInCache(['event', 'get', eventId], deletedEvent);
|
|
46617
|
+
fireEvent('event.deleted', {
|
|
46618
|
+
users: [],
|
|
46619
|
+
files: [],
|
|
46620
|
+
communities: [],
|
|
46621
|
+
videoStreamings: [],
|
|
46622
|
+
events: [deletedEvent],
|
|
46623
|
+
discussionCommunities: [],
|
|
46624
|
+
});
|
|
46625
|
+
};
|
|
46626
|
+
/* end_public_function */
|
|
46627
|
+
|
|
46628
|
+
/**
|
|
46629
|
+
* ```js
|
|
46630
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
46631
|
+
* const dispose = EventRepository.onEventCreated(event => {
|
|
46632
|
+
* // ...
|
|
46633
|
+
* })
|
|
46634
|
+
* ```
|
|
46635
|
+
*
|
|
46636
|
+
* Fired when a {@link Amity.Event} has been created
|
|
46637
|
+
*
|
|
46638
|
+
* @param callback The function to call when the event was fired
|
|
46639
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
46640
|
+
*
|
|
46641
|
+
* @category Event Events
|
|
46642
|
+
*/
|
|
46643
|
+
const onEventCreated = (callback) => createEventEventSubscriber('event.created', callback);
|
|
46644
|
+
|
|
46645
|
+
/**
|
|
46646
|
+
* ```js
|
|
46647
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
46648
|
+
* const dispose = EventRepository.onEventUpdated(event => {
|
|
46649
|
+
* // ...
|
|
46650
|
+
* })
|
|
46651
|
+
* ```
|
|
46652
|
+
*
|
|
46653
|
+
* Fired when a {@link Amity.Event} has been updated
|
|
46654
|
+
*
|
|
46655
|
+
* @param callback The function to call when the event was fired
|
|
46656
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
46657
|
+
*
|
|
46658
|
+
* @category Event Events
|
|
46659
|
+
*/
|
|
46660
|
+
const onEventUpdated = (callback) => createEventEventSubscriber('event.updated', callback);
|
|
46661
|
+
|
|
46662
|
+
/**
|
|
46663
|
+
* ```js
|
|
46664
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
46665
|
+
* const dispose = EventRepository.onEventDeleted(event => {
|
|
46666
|
+
* // ...
|
|
46667
|
+
* })
|
|
46668
|
+
* ```
|
|
46669
|
+
*
|
|
46670
|
+
* Fired when a {@link Amity.Event} has been deleted
|
|
46671
|
+
*
|
|
46672
|
+
* @param callback The function to call when the event was fired
|
|
46673
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
46674
|
+
*
|
|
46675
|
+
* @category Event Events
|
|
46676
|
+
*/
|
|
46677
|
+
const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted', callback);
|
|
46678
|
+
|
|
46679
|
+
/* begin_public_function
|
|
46680
|
+
id: event.get
|
|
46681
|
+
*/
|
|
46682
|
+
/**
|
|
46683
|
+
* ```js
|
|
46684
|
+
* import { EventRepository } from '@amityco/ts-sdk';
|
|
46685
|
+
*
|
|
46686
|
+
* let event;
|
|
46687
|
+
*
|
|
46688
|
+
* const unsubscribe = EventRepository.getEvent(eventId, response => {
|
|
46689
|
+
* event = response.data;
|
|
46690
|
+
* });
|
|
46691
|
+
* ```
|
|
46692
|
+
*
|
|
46693
|
+
* Observe all mutation on a given {@link Amity.Event}
|
|
46694
|
+
*
|
|
46695
|
+
* @param eventId the ID of the event to observe
|
|
46696
|
+
* @param callback the function to call when new snapshot of event are available
|
|
46697
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the event
|
|
46698
|
+
*
|
|
46699
|
+
* @category Event Live Object
|
|
46700
|
+
*/
|
|
46701
|
+
const getEvent = (eventId, callback) => {
|
|
46702
|
+
return liveObject(eventId, callback, 'eventId', getEvent$1, [onEventCreated, onEventUpdated, onEventDeleted], {
|
|
46703
|
+
callbackDataSelector: (data) => (data ? eventLinkedObject(data) : data),
|
|
46704
|
+
});
|
|
46705
|
+
};
|
|
46706
|
+
/* end_public_function */
|
|
46707
|
+
|
|
46708
|
+
var EventActionsEnum;
|
|
46709
|
+
(function (EventActionsEnum) {
|
|
46710
|
+
EventActionsEnum["OnEventCreated"] = "onEventCreated";
|
|
46711
|
+
EventActionsEnum["OnEventUpdated"] = "onEventUpdated";
|
|
46712
|
+
EventActionsEnum["OnEventDeleted"] = "onEventDeleted";
|
|
46713
|
+
})(EventActionsEnum || (EventActionsEnum = {}));
|
|
46714
|
+
|
|
46715
|
+
class EventPaginationController extends PaginationController {
|
|
46716
|
+
async getRequest(queryParams, token) {
|
|
46717
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
46718
|
+
const options = token ? { token } : { limit };
|
|
46719
|
+
const { data: response } = await this.http.get(`/api/v1/events`, { params: Object.assign(Object.assign({}, params), { options }) });
|
|
46720
|
+
return response;
|
|
46721
|
+
}
|
|
46722
|
+
}
|
|
46723
|
+
|
|
46724
|
+
class EventQueryStreamController extends QueryStreamController {
|
|
46725
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
46726
|
+
super(query, cacheKey);
|
|
46727
|
+
this.notifyChange = notifyChange;
|
|
46728
|
+
this.preparePayload = preparePayload;
|
|
46729
|
+
}
|
|
46730
|
+
async saveToMainDB(response) {
|
|
46731
|
+
const processedPayload = this.preparePayload(response);
|
|
46732
|
+
const client = getActiveClient();
|
|
46733
|
+
const cachedAt = client.cache && Date.now();
|
|
46734
|
+
if (client.cache)
|
|
46735
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
46736
|
+
}
|
|
46737
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
46738
|
+
var _a, _b;
|
|
46739
|
+
if (refresh) {
|
|
46740
|
+
pushToCache(this.cacheKey, { data: response.events.map(getResolver('event')) });
|
|
46741
|
+
}
|
|
46742
|
+
else {
|
|
46743
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
46744
|
+
const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
46745
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...events, ...response.events.map(getResolver('event'))])] }));
|
|
46746
|
+
}
|
|
46747
|
+
}
|
|
46748
|
+
reactor(action) {
|
|
46749
|
+
return (event) => {
|
|
46750
|
+
var _a;
|
|
46751
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
46752
|
+
if (!collection)
|
|
46753
|
+
return;
|
|
46754
|
+
if (action === EventActionsEnum.OnEventCreated) {
|
|
46755
|
+
collection.data = [...new Set([event.eventId, ...collection.data])];
|
|
46756
|
+
}
|
|
46757
|
+
if (action === EventActionsEnum.OnEventDeleted) {
|
|
46758
|
+
collection.data = collection.data.filter(eventId => eventId !== event.eventId);
|
|
46759
|
+
}
|
|
46760
|
+
pushToCache(this.cacheKey, collection);
|
|
46761
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
46762
|
+
};
|
|
46763
|
+
}
|
|
46764
|
+
subscribeRTE(createSubscriber) {
|
|
46765
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
46766
|
+
}
|
|
46767
|
+
}
|
|
46768
|
+
|
|
46769
|
+
class EventLiveCollectionController extends LiveCollectionController {
|
|
46770
|
+
constructor(query, callback) {
|
|
46771
|
+
const queryStreamId = hash(query);
|
|
46772
|
+
const cacheKey = ['event', 'collection', queryStreamId];
|
|
46773
|
+
const paginationController = new EventPaginationController(query);
|
|
46774
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
46775
|
+
this.query = query;
|
|
46776
|
+
this.queryStreamController = new EventQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventPayload);
|
|
46777
|
+
this.callback = callback.bind(this);
|
|
46778
|
+
this.loadPage({ initial: true });
|
|
46779
|
+
}
|
|
46780
|
+
setup() {
|
|
46781
|
+
var _a;
|
|
46782
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
46783
|
+
if (!collection)
|
|
46784
|
+
pushToCache(this.cacheKey, { data: [], params: {} });
|
|
46785
|
+
}
|
|
46786
|
+
async persistModel(queryPayload) {
|
|
46787
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
46788
|
+
}
|
|
46789
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
46790
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
46791
|
+
}
|
|
46792
|
+
startSubscription() {
|
|
46793
|
+
return this.queryStreamController.subscribeRTE([
|
|
46794
|
+
{ fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
|
|
46795
|
+
{ fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
|
|
46796
|
+
{ fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
|
|
46797
|
+
]);
|
|
46798
|
+
}
|
|
46799
|
+
notifyChange({ origin, loading, error }) {
|
|
46800
|
+
var _a, _b;
|
|
46801
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
46802
|
+
if (!collection)
|
|
46803
|
+
return;
|
|
46804
|
+
const data = ((_b = collection.data
|
|
46805
|
+
.map(eventId => pullFromCache(['event', 'get', eventId]))
|
|
46806
|
+
.filter(isNonNullable)
|
|
46807
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
|
|
46808
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
46809
|
+
return;
|
|
46810
|
+
this.callback({
|
|
46811
|
+
data,
|
|
46812
|
+
error,
|
|
46813
|
+
loading,
|
|
46814
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
46815
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
46816
|
+
});
|
|
46817
|
+
}
|
|
46818
|
+
}
|
|
46819
|
+
|
|
46820
|
+
/**
|
|
46821
|
+
* Get events
|
|
46822
|
+
*
|
|
46823
|
+
* @param params the query parameters
|
|
46824
|
+
* @param callback the callback to be called when the events are updated
|
|
46825
|
+
* @returns events
|
|
46826
|
+
*
|
|
46827
|
+
* @category Event Live Collection
|
|
46828
|
+
*
|
|
46829
|
+
*/
|
|
46830
|
+
const getEvents = (params, callback, config) => {
|
|
46831
|
+
const { log, cache } = getActiveClient();
|
|
46832
|
+
if (!cache)
|
|
46833
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
46834
|
+
const timestamp = Date.now();
|
|
46835
|
+
log(`getEvents: (tmpid: ${timestamp}) > listen`);
|
|
46836
|
+
const eventLiveCollection = new EventLiveCollectionController(params, callback);
|
|
46837
|
+
const disposers = eventLiveCollection.startSubscription();
|
|
46838
|
+
const cacheKey = eventLiveCollection.getCacheKey();
|
|
46839
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
46840
|
+
return () => {
|
|
46841
|
+
log(`getEvents (tmpid: ${timestamp}) > dispose`);
|
|
46842
|
+
disposers.forEach(fn => fn());
|
|
46843
|
+
};
|
|
46844
|
+
};
|
|
46845
|
+
|
|
46846
|
+
class MyEventPaginationController extends PaginationController {
|
|
46847
|
+
async getRequest(queryParams, token) {
|
|
46848
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
46849
|
+
const options = token ? { token } : { limit };
|
|
46850
|
+
const { data: response } = await this.http.get(`/api/v1/events/me/rsvps`, { params: Object.assign(Object.assign({}, params), { options }) });
|
|
46851
|
+
return response;
|
|
46852
|
+
}
|
|
46853
|
+
}
|
|
46854
|
+
|
|
46855
|
+
class MyEventQueryStreamController extends QueryStreamController {
|
|
46856
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
46857
|
+
super(query, cacheKey);
|
|
46858
|
+
this.notifyChange = notifyChange;
|
|
46859
|
+
this.preparePayload = preparePayload;
|
|
46860
|
+
}
|
|
46861
|
+
async saveToMainDB(response) {
|
|
46862
|
+
const processedPayload = this.preparePayload(response);
|
|
46863
|
+
const client = getActiveClient();
|
|
46864
|
+
const cachedAt = client.cache && Date.now();
|
|
46865
|
+
if (client.cache)
|
|
46866
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
46867
|
+
}
|
|
46868
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
46869
|
+
var _a, _b;
|
|
46870
|
+
if (refresh) {
|
|
46871
|
+
pushToCache(this.cacheKey, { data: response.events.map(getResolver('event')) });
|
|
46872
|
+
}
|
|
46873
|
+
else {
|
|
46874
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
46875
|
+
const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
46876
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...events, ...response.events.map(getResolver('event'))])] }));
|
|
46877
|
+
}
|
|
46878
|
+
}
|
|
46879
|
+
reactor(action) {
|
|
46880
|
+
return (event) => {
|
|
46881
|
+
var _a;
|
|
46882
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
46883
|
+
if (!collection)
|
|
46884
|
+
return;
|
|
46885
|
+
if (action === EventActionsEnum.OnEventDeleted) {
|
|
46886
|
+
collection.data = collection.data.filter(eventId => eventId !== event.eventId);
|
|
46887
|
+
}
|
|
46888
|
+
pushToCache(this.cacheKey, collection);
|
|
46889
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
46890
|
+
};
|
|
46891
|
+
}
|
|
46892
|
+
subscribeRTE(createSubscriber) {
|
|
46893
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
46894
|
+
}
|
|
46895
|
+
}
|
|
46896
|
+
|
|
46897
|
+
class MyEventLiveCollectionController extends LiveCollectionController {
|
|
46898
|
+
constructor(query, callback) {
|
|
46899
|
+
const queryStreamId = hash(query);
|
|
46900
|
+
const cacheKey = ['event', 'collection', queryStreamId];
|
|
46901
|
+
const paginationController = new MyEventPaginationController(query);
|
|
46902
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
46903
|
+
this.query = query;
|
|
46904
|
+
this.queryStreamController = new MyEventQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventPayload);
|
|
46905
|
+
this.callback = callback.bind(this);
|
|
46906
|
+
this.loadPage({ initial: true });
|
|
46907
|
+
}
|
|
46908
|
+
setup() {
|
|
46909
|
+
var _a;
|
|
46910
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
46911
|
+
if (!collection)
|
|
46912
|
+
pushToCache(this.cacheKey, { data: [], params: {} });
|
|
46913
|
+
}
|
|
46914
|
+
async persistModel(queryPayload) {
|
|
46915
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
46916
|
+
}
|
|
46917
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
46918
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
46919
|
+
}
|
|
46920
|
+
startSubscription() {
|
|
46921
|
+
return this.queryStreamController.subscribeRTE([
|
|
46922
|
+
{ fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
|
|
46923
|
+
{ fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
|
|
46924
|
+
{ fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
|
|
46925
|
+
]);
|
|
46926
|
+
}
|
|
46927
|
+
notifyChange({ origin, loading, error }) {
|
|
46928
|
+
var _a, _b;
|
|
46929
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
46930
|
+
if (!collection)
|
|
46931
|
+
return;
|
|
46932
|
+
const data = ((_b = collection.data
|
|
46933
|
+
.map(eventId => pullFromCache(['event', 'get', eventId]))
|
|
46934
|
+
.filter(isNonNullable)
|
|
46935
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
|
|
46936
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
46937
|
+
return;
|
|
46938
|
+
this.callback({
|
|
46939
|
+
data,
|
|
46940
|
+
error,
|
|
46941
|
+
loading,
|
|
46942
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
46943
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
46944
|
+
});
|
|
46945
|
+
}
|
|
46946
|
+
}
|
|
46947
|
+
|
|
46948
|
+
/**
|
|
46949
|
+
* Get my events
|
|
46950
|
+
*
|
|
46951
|
+
* @param params the query parameters
|
|
46952
|
+
* @param callback the callback to be called when the events are updated
|
|
46953
|
+
* @returns events
|
|
46954
|
+
*
|
|
46955
|
+
* @category Event Live Collection
|
|
46956
|
+
*
|
|
46957
|
+
*/
|
|
46958
|
+
const getMyEvents = (params, callback, config) => {
|
|
46959
|
+
const { log, cache } = getActiveClient();
|
|
46960
|
+
if (!cache)
|
|
46961
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
46962
|
+
const timestamp = Date.now();
|
|
46963
|
+
log(`getMyEvents: (tmpid: ${timestamp}) > listen`);
|
|
46964
|
+
const myEventLiveCollection = new MyEventLiveCollectionController(params, callback);
|
|
46965
|
+
const disposers = myEventLiveCollection.startSubscription();
|
|
46966
|
+
const cacheKey = myEventLiveCollection.getCacheKey();
|
|
46967
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
46968
|
+
return () => {
|
|
46969
|
+
log(`getMyEvents (tmpid: ${timestamp}) > dispose`);
|
|
46970
|
+
disposers.forEach(fn => fn());
|
|
46971
|
+
};
|
|
46972
|
+
};
|
|
46973
|
+
|
|
46469
46974
|
var index = /*#__PURE__*/Object.freeze({
|
|
46470
46975
|
__proto__: null,
|
|
46471
|
-
createEvent: createEvent
|
|
46976
|
+
createEvent: createEvent,
|
|
46977
|
+
updateEvent: updateEvent,
|
|
46978
|
+
deleteEvent: deleteEvent,
|
|
46979
|
+
onEventCreated: onEventCreated,
|
|
46980
|
+
onEventUpdated: onEventUpdated,
|
|
46981
|
+
onEventDeleted: onEventDeleted,
|
|
46982
|
+
getEvent: getEvent,
|
|
46983
|
+
getEvents: getEvents,
|
|
46984
|
+
getMyEvents: getMyEvents
|
|
46472
46985
|
});
|
|
46473
46986
|
|
|
46474
|
-
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 };
|
|
46987
|
+
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 };
|