@amityco/ts-sdk 7.11.1-6905f391.0 → 7.11.1-84865468.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/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/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 +354 -7
- package/dist/index.esm.js +355 -8
- 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);
|
|
@@ -46474,7 +46487,7 @@ const createEvent = async (bundle) => {
|
|
|
46474
46487
|
const client = getActiveClient();
|
|
46475
46488
|
client.log('event/createEvent', bundle);
|
|
46476
46489
|
const { data: payload } = await client.http.post('/api/v1/events', bundle);
|
|
46477
|
-
fireEvent('event.created', payload);
|
|
46490
|
+
fireEvent('local.event.created', payload);
|
|
46478
46491
|
const preparedPayload = prepareEventPayload(payload);
|
|
46479
46492
|
const cachedAt = client.cache && Date.now();
|
|
46480
46493
|
if (client.cache)
|
|
@@ -46508,7 +46521,7 @@ const updateEvent = async (eventId, bundle) => {
|
|
|
46508
46521
|
const client = getActiveClient();
|
|
46509
46522
|
client.log('event/updateEvent', eventId, bundle);
|
|
46510
46523
|
const { data: payload } = await client.http.put(`/api/v1/events/${eventId}`, bundle);
|
|
46511
|
-
fireEvent('event.updated', payload);
|
|
46524
|
+
fireEvent('local.event.updated', payload);
|
|
46512
46525
|
const preparedPayload = prepareEventPayload(payload);
|
|
46513
46526
|
const cachedAt = client.cache && Date.now();
|
|
46514
46527
|
if (client.cache)
|
|
@@ -46601,7 +46614,7 @@ const deleteEvent = async (eventId) => {
|
|
|
46601
46614
|
await client.http.delete(`/api/v3/events/${eventId}`);
|
|
46602
46615
|
const deletedEvent = Object.assign(Object.assign({}, event.data), { isDeleted: true });
|
|
46603
46616
|
upsertInCache(['event', 'get', eventId], deletedEvent);
|
|
46604
|
-
fireEvent('event.deleted', {
|
|
46617
|
+
fireEvent('local.event.deleted', {
|
|
46605
46618
|
users: [],
|
|
46606
46619
|
files: [],
|
|
46607
46620
|
communities: [],
|
|
@@ -46663,6 +46676,57 @@ const onEventUpdated = (callback) => createEventEventSubscriber('event.updated',
|
|
|
46663
46676
|
*/
|
|
46664
46677
|
const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted', callback);
|
|
46665
46678
|
|
|
46679
|
+
/**
|
|
46680
|
+
* ```js
|
|
46681
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
46682
|
+
* const dispose = EventRepository.onLocalEventCreated(event => {
|
|
46683
|
+
* // ...
|
|
46684
|
+
* })
|
|
46685
|
+
* ```
|
|
46686
|
+
*
|
|
46687
|
+
* Fired when a {@link Amity.Event} has been created
|
|
46688
|
+
*
|
|
46689
|
+
* @param callback The function to call when the event was fired
|
|
46690
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
46691
|
+
*
|
|
46692
|
+
* @category Event Events
|
|
46693
|
+
*/
|
|
46694
|
+
const onLocalEventCreated = (callback) => createEventEventSubscriber('local.event.created', callback);
|
|
46695
|
+
|
|
46696
|
+
/**
|
|
46697
|
+
* ```js
|
|
46698
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
46699
|
+
* const dispose = EventRepository.onLocalEventUpdated(event => {
|
|
46700
|
+
* // ...
|
|
46701
|
+
* })
|
|
46702
|
+
* ```
|
|
46703
|
+
*
|
|
46704
|
+
* Fired when a {@link Amity.Event} has been updated
|
|
46705
|
+
*
|
|
46706
|
+
* @param callback The function to call when the event was fired
|
|
46707
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
46708
|
+
*
|
|
46709
|
+
* @category Event Events
|
|
46710
|
+
*/
|
|
46711
|
+
const onLocalEventUpdated = (callback) => createEventEventSubscriber('local.event.updated', callback);
|
|
46712
|
+
|
|
46713
|
+
/**
|
|
46714
|
+
* ```js
|
|
46715
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
46716
|
+
* const dispose = EventRepository.onLocalEventDeleted(event => {
|
|
46717
|
+
* // ...
|
|
46718
|
+
* })
|
|
46719
|
+
* ```
|
|
46720
|
+
*
|
|
46721
|
+
* Fired when a {@link Amity.Event} has been deleted
|
|
46722
|
+
*
|
|
46723
|
+
* @param callback The function to call when the event was fired
|
|
46724
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
46725
|
+
*
|
|
46726
|
+
* @category Event Events
|
|
46727
|
+
*/
|
|
46728
|
+
const onLocalEventDeleted = (callback) => createEventEventSubscriber('local.event.deleted', callback);
|
|
46729
|
+
|
|
46666
46730
|
/* begin_public_function
|
|
46667
46731
|
id: event.get
|
|
46668
46732
|
*/
|
|
@@ -46686,12 +46750,290 @@ const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted',
|
|
|
46686
46750
|
* @category Event Live Object
|
|
46687
46751
|
*/
|
|
46688
46752
|
const getEvent = (eventId, callback) => {
|
|
46689
|
-
return liveObject(eventId, callback, 'eventId', getEvent$1, [
|
|
46753
|
+
return liveObject(eventId, callback, 'eventId', getEvent$1, [onEventUpdated, onEventDeleted, onLocalEventUpdated, onLocalEventDeleted], {
|
|
46690
46754
|
callbackDataSelector: (data) => (data ? eventLinkedObject(data) : data),
|
|
46691
46755
|
});
|
|
46692
46756
|
};
|
|
46693
46757
|
/* end_public_function */
|
|
46694
46758
|
|
|
46759
|
+
var EventActionsEnum;
|
|
46760
|
+
(function (EventActionsEnum) {
|
|
46761
|
+
EventActionsEnum["OnEventCreated"] = "onEventCreated";
|
|
46762
|
+
EventActionsEnum["OnEventUpdated"] = "onEventUpdated";
|
|
46763
|
+
EventActionsEnum["OnEventDeleted"] = "onEventDeleted";
|
|
46764
|
+
})(EventActionsEnum || (EventActionsEnum = {}));
|
|
46765
|
+
|
|
46766
|
+
class EventPaginationController extends PaginationController {
|
|
46767
|
+
async getRequest(queryParams, token) {
|
|
46768
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
46769
|
+
const options = token ? { token } : { limit };
|
|
46770
|
+
const { data: response } = await this.http.get(`/api/v1/events`, { params: Object.assign(Object.assign({}, params), { options }) });
|
|
46771
|
+
return response;
|
|
46772
|
+
}
|
|
46773
|
+
}
|
|
46774
|
+
|
|
46775
|
+
class EventQueryStreamController extends QueryStreamController {
|
|
46776
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
46777
|
+
super(query, cacheKey);
|
|
46778
|
+
this.notifyChange = notifyChange;
|
|
46779
|
+
this.preparePayload = preparePayload;
|
|
46780
|
+
}
|
|
46781
|
+
async saveToMainDB(response) {
|
|
46782
|
+
const processedPayload = this.preparePayload(response);
|
|
46783
|
+
const client = getActiveClient();
|
|
46784
|
+
const cachedAt = client.cache && Date.now();
|
|
46785
|
+
if (client.cache)
|
|
46786
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
46787
|
+
}
|
|
46788
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
46789
|
+
var _a, _b;
|
|
46790
|
+
if (refresh) {
|
|
46791
|
+
pushToCache(this.cacheKey, { data: response.events.map(getResolver('event')) });
|
|
46792
|
+
}
|
|
46793
|
+
else {
|
|
46794
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
46795
|
+
const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
46796
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...events, ...response.events.map(getResolver('event'))])] }));
|
|
46797
|
+
}
|
|
46798
|
+
}
|
|
46799
|
+
reactor(action) {
|
|
46800
|
+
return (event) => {
|
|
46801
|
+
var _a;
|
|
46802
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
46803
|
+
if (!collection)
|
|
46804
|
+
return;
|
|
46805
|
+
if (action === EventActionsEnum.OnEventCreated) {
|
|
46806
|
+
collection.data = [...new Set([event.eventId, ...collection.data])];
|
|
46807
|
+
}
|
|
46808
|
+
if (action === EventActionsEnum.OnEventDeleted) {
|
|
46809
|
+
collection.data = collection.data.filter(eventId => eventId !== event.eventId);
|
|
46810
|
+
}
|
|
46811
|
+
pushToCache(this.cacheKey, collection);
|
|
46812
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
46813
|
+
};
|
|
46814
|
+
}
|
|
46815
|
+
subscribeRTE(createSubscriber) {
|
|
46816
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
46817
|
+
}
|
|
46818
|
+
}
|
|
46819
|
+
|
|
46820
|
+
class EventLiveCollectionController extends LiveCollectionController {
|
|
46821
|
+
constructor(query, callback) {
|
|
46822
|
+
const queryStreamId = hash(query);
|
|
46823
|
+
const cacheKey = ['event', 'collection', queryStreamId];
|
|
46824
|
+
const paginationController = new EventPaginationController(query);
|
|
46825
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
46826
|
+
this.query = query;
|
|
46827
|
+
this.queryStreamController = new EventQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventPayload);
|
|
46828
|
+
this.callback = callback.bind(this);
|
|
46829
|
+
this.loadPage({ initial: true });
|
|
46830
|
+
}
|
|
46831
|
+
setup() {
|
|
46832
|
+
var _a;
|
|
46833
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
46834
|
+
if (!collection)
|
|
46835
|
+
pushToCache(this.cacheKey, { data: [], params: {} });
|
|
46836
|
+
}
|
|
46837
|
+
async persistModel(queryPayload) {
|
|
46838
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
46839
|
+
}
|
|
46840
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
46841
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
46842
|
+
}
|
|
46843
|
+
startSubscription() {
|
|
46844
|
+
return this.queryStreamController.subscribeRTE([
|
|
46845
|
+
{ fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
|
|
46846
|
+
{ fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
|
|
46847
|
+
{ fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
|
|
46848
|
+
{ fn: onLocalEventCreated, action: EventActionsEnum.OnEventCreated },
|
|
46849
|
+
{ fn: onLocalEventUpdated, action: EventActionsEnum.OnEventUpdated },
|
|
46850
|
+
{ fn: onLocalEventDeleted, action: EventActionsEnum.OnEventDeleted },
|
|
46851
|
+
]);
|
|
46852
|
+
}
|
|
46853
|
+
notifyChange({ origin, loading, error }) {
|
|
46854
|
+
var _a, _b;
|
|
46855
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
46856
|
+
if (!collection)
|
|
46857
|
+
return;
|
|
46858
|
+
const data = ((_b = collection.data
|
|
46859
|
+
.map(eventId => pullFromCache(['event', 'get', eventId]))
|
|
46860
|
+
.filter(isNonNullable)
|
|
46861
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
|
|
46862
|
+
if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
|
|
46863
|
+
return;
|
|
46864
|
+
this.callback({
|
|
46865
|
+
data,
|
|
46866
|
+
error,
|
|
46867
|
+
loading,
|
|
46868
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
46869
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
46870
|
+
});
|
|
46871
|
+
}
|
|
46872
|
+
}
|
|
46873
|
+
|
|
46874
|
+
/**
|
|
46875
|
+
* Get events
|
|
46876
|
+
*
|
|
46877
|
+
* @param params the query parameters
|
|
46878
|
+
* @param callback the callback to be called when the events are updated
|
|
46879
|
+
* @returns events
|
|
46880
|
+
*
|
|
46881
|
+
* @category Event Live Collection
|
|
46882
|
+
*
|
|
46883
|
+
*/
|
|
46884
|
+
const getEvents = (params, callback, config) => {
|
|
46885
|
+
const { log, cache } = getActiveClient();
|
|
46886
|
+
if (!cache)
|
|
46887
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
46888
|
+
const timestamp = Date.now();
|
|
46889
|
+
log(`getEvents: (tmpid: ${timestamp}) > listen`);
|
|
46890
|
+
const eventLiveCollection = new EventLiveCollectionController(params, callback);
|
|
46891
|
+
const disposers = eventLiveCollection.startSubscription();
|
|
46892
|
+
const cacheKey = eventLiveCollection.getCacheKey();
|
|
46893
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
46894
|
+
return () => {
|
|
46895
|
+
log(`getEvents (tmpid: ${timestamp}) > dispose`);
|
|
46896
|
+
disposers.forEach(fn => fn());
|
|
46897
|
+
};
|
|
46898
|
+
};
|
|
46899
|
+
|
|
46900
|
+
class MyEventPaginationController extends PaginationController {
|
|
46901
|
+
async getRequest(queryParams, token) {
|
|
46902
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
46903
|
+
const options = token ? { token } : { limit };
|
|
46904
|
+
const { data: response } = await this.http.get(`/api/v1/events/me/rsvps`, { params: Object.assign(Object.assign({}, params), { options }) });
|
|
46905
|
+
return response;
|
|
46906
|
+
}
|
|
46907
|
+
}
|
|
46908
|
+
|
|
46909
|
+
class MyEventQueryStreamController extends QueryStreamController {
|
|
46910
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
46911
|
+
super(query, cacheKey);
|
|
46912
|
+
this.notifyChange = notifyChange;
|
|
46913
|
+
this.preparePayload = preparePayload;
|
|
46914
|
+
}
|
|
46915
|
+
async saveToMainDB(response) {
|
|
46916
|
+
const processedPayload = this.preparePayload(response);
|
|
46917
|
+
const client = getActiveClient();
|
|
46918
|
+
const cachedAt = client.cache && Date.now();
|
|
46919
|
+
if (client.cache)
|
|
46920
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
46921
|
+
}
|
|
46922
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
46923
|
+
var _a, _b;
|
|
46924
|
+
if (refresh) {
|
|
46925
|
+
pushToCache(this.cacheKey, { data: response.events.map(getResolver('event')) });
|
|
46926
|
+
}
|
|
46927
|
+
else {
|
|
46928
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
46929
|
+
const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
46930
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...events, ...response.events.map(getResolver('event'))])] }));
|
|
46931
|
+
}
|
|
46932
|
+
}
|
|
46933
|
+
reactor(action) {
|
|
46934
|
+
return (event) => {
|
|
46935
|
+
var _a;
|
|
46936
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
46937
|
+
if (!collection)
|
|
46938
|
+
return;
|
|
46939
|
+
if (action === EventActionsEnum.OnEventCreated) {
|
|
46940
|
+
const client = getActiveClient();
|
|
46941
|
+
if (client.userId !== event.userId)
|
|
46942
|
+
return;
|
|
46943
|
+
collection.data = [...new Set([event.eventId, ...collection.data])];
|
|
46944
|
+
}
|
|
46945
|
+
if (action === EventActionsEnum.OnEventDeleted) {
|
|
46946
|
+
collection.data = collection.data.filter(eventId => eventId !== event.eventId);
|
|
46947
|
+
}
|
|
46948
|
+
pushToCache(this.cacheKey, collection);
|
|
46949
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
46950
|
+
};
|
|
46951
|
+
}
|
|
46952
|
+
subscribeRTE(createSubscriber) {
|
|
46953
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
46954
|
+
}
|
|
46955
|
+
}
|
|
46956
|
+
|
|
46957
|
+
class MyEventLiveCollectionController extends LiveCollectionController {
|
|
46958
|
+
constructor(query, callback) {
|
|
46959
|
+
const queryStreamId = hash(query);
|
|
46960
|
+
const cacheKey = ['event', 'collection', queryStreamId];
|
|
46961
|
+
const paginationController = new MyEventPaginationController(query);
|
|
46962
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
46963
|
+
this.query = query;
|
|
46964
|
+
this.queryStreamController = new MyEventQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventPayload);
|
|
46965
|
+
this.callback = callback.bind(this);
|
|
46966
|
+
this.loadPage({ initial: true });
|
|
46967
|
+
}
|
|
46968
|
+
setup() {
|
|
46969
|
+
var _a;
|
|
46970
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
46971
|
+
if (!collection)
|
|
46972
|
+
pushToCache(this.cacheKey, { data: [], params: {} });
|
|
46973
|
+
}
|
|
46974
|
+
async persistModel(queryPayload) {
|
|
46975
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
46976
|
+
}
|
|
46977
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
46978
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
46979
|
+
}
|
|
46980
|
+
startSubscription() {
|
|
46981
|
+
return this.queryStreamController.subscribeRTE([
|
|
46982
|
+
{ fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
|
|
46983
|
+
{ fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
|
|
46984
|
+
{ fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
|
|
46985
|
+
{ fn: onLocalEventCreated, action: EventActionsEnum.OnEventCreated },
|
|
46986
|
+
{ fn: onLocalEventUpdated, action: EventActionsEnum.OnEventUpdated },
|
|
46987
|
+
{ fn: onLocalEventDeleted, action: EventActionsEnum.OnEventDeleted },
|
|
46988
|
+
]);
|
|
46989
|
+
}
|
|
46990
|
+
notifyChange({ origin, loading, error }) {
|
|
46991
|
+
var _a, _b;
|
|
46992
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
46993
|
+
if (!collection)
|
|
46994
|
+
return;
|
|
46995
|
+
const data = ((_b = collection.data
|
|
46996
|
+
.map(eventId => pullFromCache(['event', 'get', eventId]))
|
|
46997
|
+
.filter(isNonNullable)
|
|
46998
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
|
|
46999
|
+
if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
|
|
47000
|
+
return;
|
|
47001
|
+
this.callback({
|
|
47002
|
+
data,
|
|
47003
|
+
error,
|
|
47004
|
+
loading,
|
|
47005
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
47006
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
47007
|
+
});
|
|
47008
|
+
}
|
|
47009
|
+
}
|
|
47010
|
+
|
|
47011
|
+
/**
|
|
47012
|
+
* Get my events
|
|
47013
|
+
*
|
|
47014
|
+
* @param params the query parameters
|
|
47015
|
+
* @param callback the callback to be called when the events are updated
|
|
47016
|
+
* @returns events
|
|
47017
|
+
*
|
|
47018
|
+
* @category Event Live Collection
|
|
47019
|
+
*
|
|
47020
|
+
*/
|
|
47021
|
+
const getMyEvents = (params, callback, config) => {
|
|
47022
|
+
const { log, cache } = getActiveClient();
|
|
47023
|
+
if (!cache)
|
|
47024
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
47025
|
+
const timestamp = Date.now();
|
|
47026
|
+
log(`getMyEvents: (tmpid: ${timestamp}) > listen`);
|
|
47027
|
+
const myEventLiveCollection = new MyEventLiveCollectionController(params, callback);
|
|
47028
|
+
const disposers = myEventLiveCollection.startSubscription();
|
|
47029
|
+
const cacheKey = myEventLiveCollection.getCacheKey();
|
|
47030
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
47031
|
+
return () => {
|
|
47032
|
+
log(`getMyEvents (tmpid: ${timestamp}) > dispose`);
|
|
47033
|
+
disposers.forEach(fn => fn());
|
|
47034
|
+
};
|
|
47035
|
+
};
|
|
47036
|
+
|
|
46695
47037
|
var index = /*#__PURE__*/Object.freeze({
|
|
46696
47038
|
__proto__: null,
|
|
46697
47039
|
createEvent: createEvent,
|
|
@@ -46700,7 +47042,12 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
46700
47042
|
onEventCreated: onEventCreated,
|
|
46701
47043
|
onEventUpdated: onEventUpdated,
|
|
46702
47044
|
onEventDeleted: onEventDeleted,
|
|
46703
|
-
|
|
47045
|
+
onLocalEventCreated: onLocalEventCreated,
|
|
47046
|
+
onLocalEventUpdated: onLocalEventUpdated,
|
|
47047
|
+
onLocalEventDeleted: onLocalEventDeleted,
|
|
47048
|
+
getEvent: getEvent,
|
|
47049
|
+
getEvents: getEvents,
|
|
47050
|
+
getMyEvents: getMyEvents
|
|
46704
47051
|
});
|
|
46705
47052
|
|
|
46706
|
-
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 };
|
|
47053
|
+
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 };
|