@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.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);
|
|
@@ -46520,57 +46533,6 @@ const updateEvent = async (eventId, bundle) => {
|
|
|
46520
46533
|
};
|
|
46521
46534
|
/* end_public_function */
|
|
46522
46535
|
|
|
46523
|
-
/**
|
|
46524
|
-
* ```js
|
|
46525
|
-
* import { EventRepository } from '@amityco/ts-sdk'
|
|
46526
|
-
* const dispose = EventRepository.onEventCreated(event => {
|
|
46527
|
-
* // ...
|
|
46528
|
-
* })
|
|
46529
|
-
* ```
|
|
46530
|
-
*
|
|
46531
|
-
* Fired when a {@link Amity.Event} has been created
|
|
46532
|
-
*
|
|
46533
|
-
* @param callback The function to call when the event was fired
|
|
46534
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
46535
|
-
*
|
|
46536
|
-
* @category Event Events
|
|
46537
|
-
*/
|
|
46538
|
-
const onEventCreated = (callback) => createEventEventSubscriber('event.created', callback);
|
|
46539
|
-
|
|
46540
|
-
/**
|
|
46541
|
-
* ```js
|
|
46542
|
-
* import { EventRepository } from '@amityco/ts-sdk'
|
|
46543
|
-
* const dispose = EventRepository.onEventUpdated(event => {
|
|
46544
|
-
* // ...
|
|
46545
|
-
* })
|
|
46546
|
-
* ```
|
|
46547
|
-
*
|
|
46548
|
-
* Fired when a {@link Amity.Event} has been updated
|
|
46549
|
-
*
|
|
46550
|
-
* @param callback The function to call when the event was fired
|
|
46551
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
46552
|
-
*
|
|
46553
|
-
* @category Event Events
|
|
46554
|
-
*/
|
|
46555
|
-
const onEventUpdated = (callback) => createEventEventSubscriber('event.updated', callback);
|
|
46556
|
-
|
|
46557
|
-
/**
|
|
46558
|
-
* ```js
|
|
46559
|
-
* import { EventRepository } from '@amityco/ts-sdk'
|
|
46560
|
-
* const dispose = EventRepository.onEventDeleted(event => {
|
|
46561
|
-
* // ...
|
|
46562
|
-
* })
|
|
46563
|
-
* ```
|
|
46564
|
-
*
|
|
46565
|
-
* Fired when a {@link Amity.Event} has been deleted
|
|
46566
|
-
*
|
|
46567
|
-
* @param callback The function to call when the event was fired
|
|
46568
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
46569
|
-
*
|
|
46570
|
-
* @category Event Events
|
|
46571
|
-
*/
|
|
46572
|
-
const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted', callback);
|
|
46573
|
-
|
|
46574
46536
|
/* begin_public_function
|
|
46575
46537
|
id: event.get
|
|
46576
46538
|
*/
|
|
@@ -46629,6 +46591,91 @@ getEvent$1.locally = (eventId) => {
|
|
|
46629
46591
|
};
|
|
46630
46592
|
};
|
|
46631
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
|
+
|
|
46632
46679
|
/* begin_public_function
|
|
46633
46680
|
id: event.get
|
|
46634
46681
|
*/
|
|
@@ -46658,14 +46705,283 @@ const getEvent = (eventId, callback) => {
|
|
|
46658
46705
|
};
|
|
46659
46706
|
/* end_public_function */
|
|
46660
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
|
+
|
|
46661
46974
|
var index = /*#__PURE__*/Object.freeze({
|
|
46662
46975
|
__proto__: null,
|
|
46663
46976
|
createEvent: createEvent,
|
|
46664
46977
|
updateEvent: updateEvent,
|
|
46978
|
+
deleteEvent: deleteEvent,
|
|
46665
46979
|
onEventCreated: onEventCreated,
|
|
46666
46980
|
onEventUpdated: onEventUpdated,
|
|
46667
46981
|
onEventDeleted: onEventDeleted,
|
|
46668
|
-
getEvent: getEvent
|
|
46982
|
+
getEvent: getEvent,
|
|
46983
|
+
getEvents: getEvents,
|
|
46984
|
+
getMyEvents: getMyEvents
|
|
46669
46985
|
});
|
|
46670
46986
|
|
|
46671
|
-
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 };
|