@amityco/ts-sdk 7.11.1-38ad45e1.0 → 7.11.1-4788cb4b.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@types/core/permissions.d.ts +5 -1
- package/dist/@types/core/permissions.d.ts.map +1 -1
- package/dist/@types/core/transport.d.ts +1 -1
- package/dist/@types/core/transport.d.ts.map +1 -1
- package/dist/@types/domains/community.d.ts +8 -1
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/@types/domains/event.d.ts +33 -9
- package/dist/@types/domains/event.d.ts.map +1 -1
- package/dist/@types/domains/partials.d.ts +2 -2
- package/dist/@types/domains/partials.d.ts.map +1 -1
- package/dist/core/model/idResolvers.d.ts.map +1 -1
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/eventRepository/api/deleteEvent.d.ts +0 -1
- package/dist/eventRepository/api/deleteEvent.d.ts.map +1 -1
- package/dist/eventRepository/events/enums.d.ts +6 -0
- package/dist/eventRepository/events/enums.d.ts.map +1 -0
- package/dist/eventRepository/events/index.d.ts +3 -0
- package/dist/eventRepository/events/index.d.ts.map +1 -1
- package/dist/eventRepository/events/onLocalEventCreated.d.ts +17 -0
- package/dist/eventRepository/events/onLocalEventCreated.d.ts.map +1 -0
- package/dist/eventRepository/events/onLocalEventDeleted.d.ts +17 -0
- package/dist/eventRepository/events/onLocalEventDeleted.d.ts.map +1 -0
- package/dist/eventRepository/events/onLocalEventUpdated.d.ts +17 -0
- package/dist/eventRepository/events/onLocalEventUpdated.d.ts.map +1 -0
- package/dist/eventRepository/observers/getEvent.d.ts.map +1 -1
- package/dist/eventRepository/observers/getEvents/LiveCollectionController.d.ts +13 -0
- package/dist/eventRepository/observers/getEvents/LiveCollectionController.d.ts.map +1 -0
- package/dist/eventRepository/observers/getEvents/PaginationController.d.ts +5 -0
- package/dist/eventRepository/observers/getEvents/PaginationController.d.ts.map +1 -0
- package/dist/eventRepository/observers/getEvents/QueryStreamController.d.ts +15 -0
- package/dist/eventRepository/observers/getEvents/QueryStreamController.d.ts.map +1 -0
- package/dist/eventRepository/observers/getEvents.d.ts +12 -0
- package/dist/eventRepository/observers/getEvents.d.ts.map +1 -0
- package/dist/eventRepository/observers/getMyEvents/LiveCollectionController.d.ts +13 -0
- package/dist/eventRepository/observers/getMyEvents/LiveCollectionController.d.ts.map +1 -0
- package/dist/eventRepository/observers/getMyEvents/PaginationController.d.ts +5 -0
- package/dist/eventRepository/observers/getMyEvents/PaginationController.d.ts.map +1 -0
- package/dist/eventRepository/observers/getMyEvents/QueryStreamController.d.ts +15 -0
- package/dist/eventRepository/observers/getMyEvents/QueryStreamController.d.ts.map +1 -0
- package/dist/eventRepository/observers/getMyEvents.d.ts +12 -0
- package/dist/eventRepository/observers/getMyEvents.d.ts.map +1 -0
- package/dist/eventRepository/observers/index.d.ts +2 -0
- package/dist/eventRepository/observers/index.d.ts.map +1 -1
- package/dist/eventRepository/utils/createEventEventSubscriber.d.ts +1 -1
- package/dist/eventRepository/utils/createEventEventSubscriber.d.ts.map +1 -1
- package/dist/index.cjs.js +372 -10
- package/dist/index.esm.js +373 -11
- package/dist/index.umd.js +3 -3
- package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts +1 -1
- package/dist/utils/linkedObject/eventLinkObject.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.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,13 +29785,33 @@ 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);
|
|
29785
29798
|
},
|
|
29799
|
+
get targetCommunity() {
|
|
29800
|
+
if (!event.originId)
|
|
29801
|
+
return;
|
|
29802
|
+
const cacheData = pullFromCache(['community', 'get', event.originId]);
|
|
29803
|
+
if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
|
|
29804
|
+
return;
|
|
29805
|
+
return communityLinkedObject(cacheData.data);
|
|
29806
|
+
},
|
|
29807
|
+
get coverImage() {
|
|
29808
|
+
if (!event.coverImageFileId)
|
|
29809
|
+
return;
|
|
29810
|
+
const cacheData = pullFromCache(['file', 'get', event.coverImageFileId]);
|
|
29811
|
+
if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
|
|
29812
|
+
return;
|
|
29813
|
+
return cacheData.data;
|
|
29814
|
+
},
|
|
29786
29815
|
get liveStream() {
|
|
29787
29816
|
if (!event.livestreamId)
|
|
29788
29817
|
return;
|
|
@@ -46474,7 +46503,7 @@ const createEvent = async (bundle) => {
|
|
|
46474
46503
|
const client = getActiveClient();
|
|
46475
46504
|
client.log('event/createEvent', bundle);
|
|
46476
46505
|
const { data: payload } = await client.http.post('/api/v1/events', bundle);
|
|
46477
|
-
fireEvent('event.created', payload);
|
|
46506
|
+
fireEvent('local.event.created', payload);
|
|
46478
46507
|
const preparedPayload = prepareEventPayload(payload);
|
|
46479
46508
|
const cachedAt = client.cache && Date.now();
|
|
46480
46509
|
if (client.cache)
|
|
@@ -46508,7 +46537,7 @@ const updateEvent = async (eventId, bundle) => {
|
|
|
46508
46537
|
const client = getActiveClient();
|
|
46509
46538
|
client.log('event/updateEvent', eventId, bundle);
|
|
46510
46539
|
const { data: payload } = await client.http.put(`/api/v1/events/${eventId}`, bundle);
|
|
46511
|
-
fireEvent('event.updated', payload);
|
|
46540
|
+
fireEvent('local.event.updated', payload);
|
|
46512
46541
|
const preparedPayload = prepareEventPayload(payload);
|
|
46513
46542
|
const cachedAt = client.cache && Date.now();
|
|
46514
46543
|
if (client.cache)
|
|
@@ -46590,7 +46619,6 @@ getEvent$1.locally = (eventId) => {
|
|
|
46590
46619
|
* Deletes a {@link Amity.Event}
|
|
46591
46620
|
*
|
|
46592
46621
|
* @param eventId The {@link Amity.Event} ID to delete
|
|
46593
|
-
* @return A success boolean if the {@link Amity.Event} was deleted
|
|
46594
46622
|
*
|
|
46595
46623
|
* @category Event API
|
|
46596
46624
|
* @async
|
|
@@ -46599,10 +46627,10 @@ const deleteEvent = async (eventId) => {
|
|
|
46599
46627
|
const client = getActiveClient();
|
|
46600
46628
|
client.log('event/deleteEvent', eventId);
|
|
46601
46629
|
const event = await getEvent$1(eventId);
|
|
46602
|
-
|
|
46603
|
-
const deletedEvent = Object.assign(Object.assign({}, event.data), { isDeleted:
|
|
46630
|
+
await client.http.delete(`/api/v3/events/${eventId}`);
|
|
46631
|
+
const deletedEvent = Object.assign(Object.assign({}, event.data), { isDeleted: true });
|
|
46604
46632
|
upsertInCache(['event', 'get', eventId], deletedEvent);
|
|
46605
|
-
fireEvent('event.deleted', {
|
|
46633
|
+
fireEvent('local.event.deleted', {
|
|
46606
46634
|
users: [],
|
|
46607
46635
|
files: [],
|
|
46608
46636
|
communities: [],
|
|
@@ -46664,6 +46692,57 @@ const onEventUpdated = (callback) => createEventEventSubscriber('event.updated',
|
|
|
46664
46692
|
*/
|
|
46665
46693
|
const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted', callback);
|
|
46666
46694
|
|
|
46695
|
+
/**
|
|
46696
|
+
* ```js
|
|
46697
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
46698
|
+
* const dispose = EventRepository.onLocalEventCreated(event => {
|
|
46699
|
+
* // ...
|
|
46700
|
+
* })
|
|
46701
|
+
* ```
|
|
46702
|
+
*
|
|
46703
|
+
* Fired when a {@link Amity.Event} has been created
|
|
46704
|
+
*
|
|
46705
|
+
* @param callback The function to call when the event was fired
|
|
46706
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
46707
|
+
*
|
|
46708
|
+
* @category Event Events
|
|
46709
|
+
*/
|
|
46710
|
+
const onLocalEventCreated = (callback) => createEventEventSubscriber('local.event.created', callback);
|
|
46711
|
+
|
|
46712
|
+
/**
|
|
46713
|
+
* ```js
|
|
46714
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
46715
|
+
* const dispose = EventRepository.onLocalEventUpdated(event => {
|
|
46716
|
+
* // ...
|
|
46717
|
+
* })
|
|
46718
|
+
* ```
|
|
46719
|
+
*
|
|
46720
|
+
* Fired when a {@link Amity.Event} has been updated
|
|
46721
|
+
*
|
|
46722
|
+
* @param callback The function to call when the event was fired
|
|
46723
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
46724
|
+
*
|
|
46725
|
+
* @category Event Events
|
|
46726
|
+
*/
|
|
46727
|
+
const onLocalEventUpdated = (callback) => createEventEventSubscriber('local.event.updated', callback);
|
|
46728
|
+
|
|
46729
|
+
/**
|
|
46730
|
+
* ```js
|
|
46731
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
46732
|
+
* const dispose = EventRepository.onLocalEventDeleted(event => {
|
|
46733
|
+
* // ...
|
|
46734
|
+
* })
|
|
46735
|
+
* ```
|
|
46736
|
+
*
|
|
46737
|
+
* Fired when a {@link Amity.Event} has been deleted
|
|
46738
|
+
*
|
|
46739
|
+
* @param callback The function to call when the event was fired
|
|
46740
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
46741
|
+
*
|
|
46742
|
+
* @category Event Events
|
|
46743
|
+
*/
|
|
46744
|
+
const onLocalEventDeleted = (callback) => createEventEventSubscriber('local.event.deleted', callback);
|
|
46745
|
+
|
|
46667
46746
|
/* begin_public_function
|
|
46668
46747
|
id: event.get
|
|
46669
46748
|
*/
|
|
@@ -46687,12 +46766,290 @@ const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted',
|
|
|
46687
46766
|
* @category Event Live Object
|
|
46688
46767
|
*/
|
|
46689
46768
|
const getEvent = (eventId, callback) => {
|
|
46690
|
-
return liveObject(eventId, callback, 'eventId', getEvent$1, [
|
|
46769
|
+
return liveObject(eventId, callback, 'eventId', getEvent$1, [onEventUpdated, onEventDeleted, onLocalEventUpdated, onLocalEventDeleted], {
|
|
46691
46770
|
callbackDataSelector: (data) => (data ? eventLinkedObject(data) : data),
|
|
46692
46771
|
});
|
|
46693
46772
|
};
|
|
46694
46773
|
/* end_public_function */
|
|
46695
46774
|
|
|
46775
|
+
var EventActionsEnum;
|
|
46776
|
+
(function (EventActionsEnum) {
|
|
46777
|
+
EventActionsEnum["OnEventCreated"] = "onEventCreated";
|
|
46778
|
+
EventActionsEnum["OnEventUpdated"] = "onEventUpdated";
|
|
46779
|
+
EventActionsEnum["OnEventDeleted"] = "onEventDeleted";
|
|
46780
|
+
})(EventActionsEnum || (EventActionsEnum = {}));
|
|
46781
|
+
|
|
46782
|
+
class EventPaginationController extends PaginationController {
|
|
46783
|
+
async getRequest(queryParams, token) {
|
|
46784
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
46785
|
+
const options = token ? { token } : { limit };
|
|
46786
|
+
const { data: response } = await this.http.get(`/api/v1/events`, { params: Object.assign(Object.assign({}, params), { options }) });
|
|
46787
|
+
return response;
|
|
46788
|
+
}
|
|
46789
|
+
}
|
|
46790
|
+
|
|
46791
|
+
class EventQueryStreamController extends QueryStreamController {
|
|
46792
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
46793
|
+
super(query, cacheKey);
|
|
46794
|
+
this.notifyChange = notifyChange;
|
|
46795
|
+
this.preparePayload = preparePayload;
|
|
46796
|
+
}
|
|
46797
|
+
async saveToMainDB(response) {
|
|
46798
|
+
const processedPayload = this.preparePayload(response);
|
|
46799
|
+
const client = getActiveClient();
|
|
46800
|
+
const cachedAt = client.cache && Date.now();
|
|
46801
|
+
if (client.cache)
|
|
46802
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
46803
|
+
}
|
|
46804
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
46805
|
+
var _a, _b;
|
|
46806
|
+
if (refresh) {
|
|
46807
|
+
pushToCache(this.cacheKey, { data: response.events.map(getResolver('event')) });
|
|
46808
|
+
}
|
|
46809
|
+
else {
|
|
46810
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
46811
|
+
const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
46812
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...events, ...response.events.map(getResolver('event'))])] }));
|
|
46813
|
+
}
|
|
46814
|
+
}
|
|
46815
|
+
reactor(action) {
|
|
46816
|
+
return (event) => {
|
|
46817
|
+
var _a;
|
|
46818
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
46819
|
+
if (!collection)
|
|
46820
|
+
return;
|
|
46821
|
+
if (action === EventActionsEnum.OnEventCreated) {
|
|
46822
|
+
collection.data = [...new Set([event.eventId, ...collection.data])];
|
|
46823
|
+
}
|
|
46824
|
+
if (action === EventActionsEnum.OnEventDeleted) {
|
|
46825
|
+
collection.data = collection.data.filter(eventId => eventId !== event.eventId);
|
|
46826
|
+
}
|
|
46827
|
+
pushToCache(this.cacheKey, collection);
|
|
46828
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
46829
|
+
};
|
|
46830
|
+
}
|
|
46831
|
+
subscribeRTE(createSubscriber) {
|
|
46832
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
46833
|
+
}
|
|
46834
|
+
}
|
|
46835
|
+
|
|
46836
|
+
class EventLiveCollectionController extends LiveCollectionController {
|
|
46837
|
+
constructor(query, callback) {
|
|
46838
|
+
const queryStreamId = hash(query);
|
|
46839
|
+
const cacheKey = ['event', 'collection', queryStreamId];
|
|
46840
|
+
const paginationController = new EventPaginationController(query);
|
|
46841
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
46842
|
+
this.query = query;
|
|
46843
|
+
this.queryStreamController = new EventQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventPayload);
|
|
46844
|
+
this.callback = callback.bind(this);
|
|
46845
|
+
this.loadPage({ initial: true });
|
|
46846
|
+
}
|
|
46847
|
+
setup() {
|
|
46848
|
+
var _a;
|
|
46849
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
46850
|
+
if (!collection)
|
|
46851
|
+
pushToCache(this.cacheKey, { data: [], params: {} });
|
|
46852
|
+
}
|
|
46853
|
+
async persistModel(queryPayload) {
|
|
46854
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
46855
|
+
}
|
|
46856
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
46857
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
46858
|
+
}
|
|
46859
|
+
startSubscription() {
|
|
46860
|
+
return this.queryStreamController.subscribeRTE([
|
|
46861
|
+
{ fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
|
|
46862
|
+
{ fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
|
|
46863
|
+
{ fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
|
|
46864
|
+
{ fn: onLocalEventCreated, action: EventActionsEnum.OnEventCreated },
|
|
46865
|
+
{ fn: onLocalEventUpdated, action: EventActionsEnum.OnEventUpdated },
|
|
46866
|
+
{ fn: onLocalEventDeleted, action: EventActionsEnum.OnEventDeleted },
|
|
46867
|
+
]);
|
|
46868
|
+
}
|
|
46869
|
+
notifyChange({ origin, loading, error }) {
|
|
46870
|
+
var _a, _b;
|
|
46871
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
46872
|
+
if (!collection)
|
|
46873
|
+
return;
|
|
46874
|
+
const data = ((_b = collection.data
|
|
46875
|
+
.map(eventId => pullFromCache(['event', 'get', eventId]))
|
|
46876
|
+
.filter(isNonNullable)
|
|
46877
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
|
|
46878
|
+
if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
|
|
46879
|
+
return;
|
|
46880
|
+
this.callback({
|
|
46881
|
+
data,
|
|
46882
|
+
error,
|
|
46883
|
+
loading,
|
|
46884
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
46885
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
46886
|
+
});
|
|
46887
|
+
}
|
|
46888
|
+
}
|
|
46889
|
+
|
|
46890
|
+
/**
|
|
46891
|
+
* Get events
|
|
46892
|
+
*
|
|
46893
|
+
* @param params the query parameters
|
|
46894
|
+
* @param callback the callback to be called when the events are updated
|
|
46895
|
+
* @returns events
|
|
46896
|
+
*
|
|
46897
|
+
* @category Event Live Collection
|
|
46898
|
+
*
|
|
46899
|
+
*/
|
|
46900
|
+
const getEvents = (params, callback, config) => {
|
|
46901
|
+
const { log, cache } = getActiveClient();
|
|
46902
|
+
if (!cache)
|
|
46903
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
46904
|
+
const timestamp = Date.now();
|
|
46905
|
+
log(`getEvents: (tmpid: ${timestamp}) > listen`);
|
|
46906
|
+
const eventLiveCollection = new EventLiveCollectionController(params, callback);
|
|
46907
|
+
const disposers = eventLiveCollection.startSubscription();
|
|
46908
|
+
const cacheKey = eventLiveCollection.getCacheKey();
|
|
46909
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
46910
|
+
return () => {
|
|
46911
|
+
log(`getEvents (tmpid: ${timestamp}) > dispose`);
|
|
46912
|
+
disposers.forEach(fn => fn());
|
|
46913
|
+
};
|
|
46914
|
+
};
|
|
46915
|
+
|
|
46916
|
+
class MyEventPaginationController extends PaginationController {
|
|
46917
|
+
async getRequest(queryParams, token) {
|
|
46918
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
46919
|
+
const options = token ? { token } : { limit };
|
|
46920
|
+
const { data: response } = await this.http.get(`/api/v1/events/me/rsvps`, { params: Object.assign(Object.assign({}, params), { options }) });
|
|
46921
|
+
return response;
|
|
46922
|
+
}
|
|
46923
|
+
}
|
|
46924
|
+
|
|
46925
|
+
class MyEventQueryStreamController extends QueryStreamController {
|
|
46926
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
46927
|
+
super(query, cacheKey);
|
|
46928
|
+
this.notifyChange = notifyChange;
|
|
46929
|
+
this.preparePayload = preparePayload;
|
|
46930
|
+
}
|
|
46931
|
+
async saveToMainDB(response) {
|
|
46932
|
+
const processedPayload = this.preparePayload(response);
|
|
46933
|
+
const client = getActiveClient();
|
|
46934
|
+
const cachedAt = client.cache && Date.now();
|
|
46935
|
+
if (client.cache)
|
|
46936
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
46937
|
+
}
|
|
46938
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
46939
|
+
var _a, _b;
|
|
46940
|
+
if (refresh) {
|
|
46941
|
+
pushToCache(this.cacheKey, { data: response.events.map(getResolver('event')) });
|
|
46942
|
+
}
|
|
46943
|
+
else {
|
|
46944
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
46945
|
+
const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
46946
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...events, ...response.events.map(getResolver('event'))])] }));
|
|
46947
|
+
}
|
|
46948
|
+
}
|
|
46949
|
+
reactor(action) {
|
|
46950
|
+
return (event) => {
|
|
46951
|
+
var _a;
|
|
46952
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
46953
|
+
if (!collection)
|
|
46954
|
+
return;
|
|
46955
|
+
if (action === EventActionsEnum.OnEventCreated) {
|
|
46956
|
+
const client = getActiveClient();
|
|
46957
|
+
if (client.userId !== event.userId)
|
|
46958
|
+
return;
|
|
46959
|
+
collection.data = [...new Set([event.eventId, ...collection.data])];
|
|
46960
|
+
}
|
|
46961
|
+
if (action === EventActionsEnum.OnEventDeleted) {
|
|
46962
|
+
collection.data = collection.data.filter(eventId => eventId !== event.eventId);
|
|
46963
|
+
}
|
|
46964
|
+
pushToCache(this.cacheKey, collection);
|
|
46965
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
46966
|
+
};
|
|
46967
|
+
}
|
|
46968
|
+
subscribeRTE(createSubscriber) {
|
|
46969
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
46970
|
+
}
|
|
46971
|
+
}
|
|
46972
|
+
|
|
46973
|
+
class MyEventLiveCollectionController extends LiveCollectionController {
|
|
46974
|
+
constructor(query, callback) {
|
|
46975
|
+
const queryStreamId = hash(query);
|
|
46976
|
+
const cacheKey = ['event', 'collection', queryStreamId];
|
|
46977
|
+
const paginationController = new MyEventPaginationController(query);
|
|
46978
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
46979
|
+
this.query = query;
|
|
46980
|
+
this.queryStreamController = new MyEventQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventPayload);
|
|
46981
|
+
this.callback = callback.bind(this);
|
|
46982
|
+
this.loadPage({ initial: true });
|
|
46983
|
+
}
|
|
46984
|
+
setup() {
|
|
46985
|
+
var _a;
|
|
46986
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
46987
|
+
if (!collection)
|
|
46988
|
+
pushToCache(this.cacheKey, { data: [], params: {} });
|
|
46989
|
+
}
|
|
46990
|
+
async persistModel(queryPayload) {
|
|
46991
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
46992
|
+
}
|
|
46993
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
46994
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
46995
|
+
}
|
|
46996
|
+
startSubscription() {
|
|
46997
|
+
return this.queryStreamController.subscribeRTE([
|
|
46998
|
+
{ fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
|
|
46999
|
+
{ fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
|
|
47000
|
+
{ fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
|
|
47001
|
+
{ fn: onLocalEventCreated, action: EventActionsEnum.OnEventCreated },
|
|
47002
|
+
{ fn: onLocalEventUpdated, action: EventActionsEnum.OnEventUpdated },
|
|
47003
|
+
{ fn: onLocalEventDeleted, action: EventActionsEnum.OnEventDeleted },
|
|
47004
|
+
]);
|
|
47005
|
+
}
|
|
47006
|
+
notifyChange({ origin, loading, error }) {
|
|
47007
|
+
var _a, _b;
|
|
47008
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
47009
|
+
if (!collection)
|
|
47010
|
+
return;
|
|
47011
|
+
const data = ((_b = collection.data
|
|
47012
|
+
.map(eventId => pullFromCache(['event', 'get', eventId]))
|
|
47013
|
+
.filter(isNonNullable)
|
|
47014
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
|
|
47015
|
+
if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
|
|
47016
|
+
return;
|
|
47017
|
+
this.callback({
|
|
47018
|
+
data,
|
|
47019
|
+
error,
|
|
47020
|
+
loading,
|
|
47021
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
47022
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
47023
|
+
});
|
|
47024
|
+
}
|
|
47025
|
+
}
|
|
47026
|
+
|
|
47027
|
+
/**
|
|
47028
|
+
* Get my events
|
|
47029
|
+
*
|
|
47030
|
+
* @param params the query parameters
|
|
47031
|
+
* @param callback the callback to be called when the events are updated
|
|
47032
|
+
* @returns events
|
|
47033
|
+
*
|
|
47034
|
+
* @category Event Live Collection
|
|
47035
|
+
*
|
|
47036
|
+
*/
|
|
47037
|
+
const getMyEvents = (params, callback, config) => {
|
|
47038
|
+
const { log, cache } = getActiveClient();
|
|
47039
|
+
if (!cache)
|
|
47040
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
47041
|
+
const timestamp = Date.now();
|
|
47042
|
+
log(`getMyEvents: (tmpid: ${timestamp}) > listen`);
|
|
47043
|
+
const myEventLiveCollection = new MyEventLiveCollectionController(params, callback);
|
|
47044
|
+
const disposers = myEventLiveCollection.startSubscription();
|
|
47045
|
+
const cacheKey = myEventLiveCollection.getCacheKey();
|
|
47046
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
47047
|
+
return () => {
|
|
47048
|
+
log(`getMyEvents (tmpid: ${timestamp}) > dispose`);
|
|
47049
|
+
disposers.forEach(fn => fn());
|
|
47050
|
+
};
|
|
47051
|
+
};
|
|
47052
|
+
|
|
46696
47053
|
var index = /*#__PURE__*/Object.freeze({
|
|
46697
47054
|
__proto__: null,
|
|
46698
47055
|
createEvent: createEvent,
|
|
@@ -46701,7 +47058,12 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
46701
47058
|
onEventCreated: onEventCreated,
|
|
46702
47059
|
onEventUpdated: onEventUpdated,
|
|
46703
47060
|
onEventDeleted: onEventDeleted,
|
|
46704
|
-
|
|
47061
|
+
onLocalEventCreated: onLocalEventCreated,
|
|
47062
|
+
onLocalEventUpdated: onLocalEventUpdated,
|
|
47063
|
+
onLocalEventDeleted: onLocalEventDeleted,
|
|
47064
|
+
getEvent: getEvent,
|
|
47065
|
+
getEvents: getEvents,
|
|
47066
|
+
getMyEvents: getMyEvents
|
|
46705
47067
|
});
|
|
46706
47068
|
|
|
46707
|
-
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 };
|
|
47069
|
+
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 };
|