@amityco/ts-sdk
Version:
Amity Social Cloud Typescript SDK
45 lines (36 loc) • 1.27 kB
text/typescript
import { dropFromCache } from '~/cache/api';
import { getActiveClient } from '~/client/api/activeClient';
import { ENABLE_CACHE_MESSAGE } from '~/utils/constants';
import { InvitationsLiveCollectionController } from './getInvitations/InvitationsLiveCollectionController';
/**
* Get invitations
*
* @param params the query parameters
* @param callback the callback to be called when the invitations are updated
* @returns invitations
*
* @category Invitation Live Collection
*
*/
export const getInvitations = (
params: Amity.InvitationLiveCollection,
callback: Amity.LiveCollectionCallback<Amity.Invitation>,
config?: Amity.LiveCollectionConfig,
) => {
const { log, cache } = getActiveClient();
if (!cache) {
console.log(ENABLE_CACHE_MESSAGE);
}
const timestamp = Date.now();
log(`getInvitations: (tmpid: ${timestamp}) > listen`);
const invitationsLiveCollection = new InvitationsLiveCollectionController(params, callback);
const disposers = invitationsLiveCollection.startSubscription();
const cacheKey = invitationsLiveCollection.getCacheKey();
disposers.push(() => {
dropFromCache(cacheKey);
});
return () => {
log(`getInvitations (tmpid: ${timestamp}) > dispose`);
disposers.forEach(fn => fn());
};
};