@amityco/ts-sdk 6.4.6-bdc04db.0 → 6.4.6-be7e4df.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/events.d.ts +4 -4
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/model.d.ts +3 -1
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +1 -1
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/post.d.ts +1 -1
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/@types/domains/reaction.d.ts +4 -5
- package/dist/@types/domains/reaction.d.ts.map +1 -1
- package/dist/client/observers/getTotalUnreadCount.d.ts.map +1 -1
- package/dist/client/utils/markerSyncEngine.d.ts.map +1 -1
- package/dist/commentRepository/observers/getComment.d.ts +2 -2
- package/dist/communityRepository/api/getCommunity.d.ts +4 -4
- package/dist/communityRepository/api/getRecommendedCommunities.d.ts +4 -4
- package/dist/communityRepository/api/getTopTrendingCommunities.d.ts +5 -2
- package/dist/communityRepository/api/getTopTrendingCommunities.d.ts.map +1 -1
- package/dist/communityRepository/api/getTrendingCommunities.d.ts +32 -0
- package/dist/communityRepository/api/getTrendingCommunities.d.ts.map +1 -0
- package/dist/communityRepository/api/index.d.ts +0 -1
- package/dist/communityRepository/api/index.d.ts.map +1 -1
- package/dist/communityRepository/api/test/getTrendingCommunities.test.d.ts +2 -0
- package/dist/communityRepository/api/test/getTrendingCommunities.test.d.ts.map +1 -0
- package/dist/communityRepository/observers/getCommunities.d.ts +2 -2
- package/dist/communityRepository/observers/getCommunity.d.ts +2 -2
- package/dist/communityRepository/observers/getRecommendedCommunities.d.ts +20 -0
- package/dist/communityRepository/observers/getRecommendedCommunities.d.ts.map +1 -0
- package/dist/communityRepository/observers/getTrendingCommunities.d.ts +20 -0
- package/dist/communityRepository/observers/getTrendingCommunities.d.ts.map +1 -0
- package/dist/communityRepository/observers/index.d.ts +2 -0
- package/dist/communityRepository/observers/index.d.ts.map +1 -1
- package/dist/communityRepository/utils/communityQueryFilter.d.ts +2 -0
- package/dist/communityRepository/utils/communityQueryFilter.d.ts.map +1 -0
- package/dist/core/model/idResolvers.d.ts.map +1 -1
- package/dist/core/model/identifyModel.d.ts.map +1 -1
- package/dist/index.cjs.js +371 -166
- package/dist/index.esm.js +371 -166
- package/dist/index.umd.js +4 -4
- package/dist/pollRepository/api/index.d.ts +0 -1
- package/dist/pollRepository/api/index.d.ts.map +1 -1
- package/dist/pollRepository/observers/getPoll.d.ts +21 -0
- package/dist/pollRepository/observers/getPoll.d.ts.map +1 -0
- package/dist/pollRepository/observers/index.d.ts +1 -0
- package/dist/pollRepository/observers/index.d.ts.map +1 -1
- package/dist/postRepository/observers/getPost.d.ts +2 -2
- package/dist/reactionRepository/api/addReaction.d.ts +2 -2
- package/dist/reactionRepository/api/addReaction.d.ts.map +1 -1
- package/dist/reactionRepository/api/queryReactions.d.ts +2 -2
- package/dist/reactionRepository/api/queryReactions.d.ts.map +1 -1
- package/dist/reactionRepository/api/queryReactor.d.ts +19 -0
- package/dist/reactionRepository/api/queryReactor.d.ts.map +1 -0
- package/dist/reactionRepository/api/removeReaction.d.ts +2 -2
- package/dist/reactionRepository/api/removeReaction.d.ts.map +1 -1
- package/dist/reactionRepository/observers/getReactions.d.ts +3 -3
- package/dist/reactionRepository/observers/getReactions.d.ts.map +1 -1
- package/dist/utils/tests/dummy/reaction.d.ts +1 -1
- package/dist/utils/tests/dummy/reaction.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/core/events.ts +4 -4
- package/src/@types/core/model.ts +3 -1
- package/src/@types/core/payload.ts +1 -1
- package/src/@types/domains/post.ts +1 -1
- package/src/@types/domains/reaction.ts +8 -9
- package/src/categoryRepository/api/queryCategories.ts +1 -1
- package/src/client/observers/getTotalUnreadCount.ts +1 -7
- package/src/client/observers/tests/getTotalUnreadCount.test.ts +3 -10
- package/src/client/utils/markerSyncEngine.ts +13 -2
- package/src/commentRepository/events/onCommentReactionAdded.ts +1 -1
- package/src/commentRepository/events/onCommentReactionRemoved.ts +1 -1
- package/src/commentRepository/observers/getComment.ts +2 -2
- package/src/commentRepository/observers/tests/getComment.test.ts +1 -3
- package/src/communityRepository/api/getCommunity.ts +4 -4
- package/src/communityRepository/api/getRecommendedCommunities.ts +4 -4
- package/src/communityRepository/api/getTopTrendingCommunities.ts +5 -2
- package/src/communityRepository/api/getTrendingCommunities.ts +97 -0
- package/src/communityRepository/api/index.ts +1 -1
- package/src/communityRepository/api/test/getTrendingCommunities.test.ts +102 -0
- package/src/communityRepository/observers/getCommunities.ts +2 -2
- package/src/communityRepository/observers/getCommunity.ts +2 -2
- package/src/communityRepository/observers/getRecommendedCommunities.ts +133 -0
- package/src/communityRepository/observers/getTrendingCommunities.ts +133 -0
- package/src/communityRepository/observers/index.ts +2 -0
- package/src/communityRepository/utils/communityQueryFilter.ts +55 -0
- package/src/core/model/idResolvers.ts +2 -1
- package/src/core/model/identifyModel.ts +5 -4
- package/src/pollRepository/api/index.ts +0 -2
- package/src/pollRepository/observers/getPoll.ts +33 -0
- package/src/pollRepository/observers/index.ts +1 -0
- package/src/pollRepository/observers/observePoll.ts +2 -2
- package/src/postRepository/events/tests/onPostReactionAdded.test.ts +6 -5
- package/src/postRepository/events/tests/onPostReactionRemoved.test.ts +5 -4
- package/src/postRepository/observers/getPost.ts +2 -2
- package/src/postRepository/observers/getPosts.ts +1 -1
- package/src/postRepository/observers/tests/getPost.test.ts +1 -3
- package/src/postRepository/observers/tests/getPosts.test.ts +1 -5
- package/src/reactionRepository/api/addReaction.ts +2 -2
- package/src/reactionRepository/api/queryReactions.ts +2 -2
- package/src/reactionRepository/api/queryReactor.ts +31 -0
- package/src/reactionRepository/api/removeReaction.ts +2 -2
- package/src/reactionRepository/observers/getReactions.ts +6 -8
- package/src/utils/tests/dummy/reaction.ts +6 -10
package/dist/index.esm.js
CHANGED
|
@@ -510,7 +510,8 @@ const idResolvers = {
|
|
|
510
510
|
post: ({ postId }) => postId,
|
|
511
511
|
comment: ({ commentId }) => commentId,
|
|
512
512
|
poll: ({ pollId }) => pollId,
|
|
513
|
-
reaction: ({
|
|
513
|
+
reaction: ({ referenceType, referenceId }) => `${referenceType}#${referenceId}`,
|
|
514
|
+
reactor: ({ reactionId }) => reactionId,
|
|
514
515
|
stream: ({ streamId }) => streamId,
|
|
515
516
|
follow: ({ from, to }) => `${from}#${to}`,
|
|
516
517
|
followInfo: ({ userId }) => userId,
|
|
@@ -537,10 +538,10 @@ const getResolver = (name) => idResolvers[name];
|
|
|
537
538
|
*/
|
|
538
539
|
const CRITERIAS = {
|
|
539
540
|
file: ['fileId', 'attributes'],
|
|
540
|
-
user: ['userId', 'avatarFileId'],
|
|
541
|
+
user: ['userId', 'avatarFileId', 'roles', 'permissions'],
|
|
541
542
|
role: ['roleId'],
|
|
542
|
-
channel: ['channelId', '
|
|
543
|
-
subChannel: ['subChannelId'],
|
|
543
|
+
channel: ['channelId', 'defaultSubChannelId'],
|
|
544
|
+
subChannel: ['subChannelId', 'latestMessageId'],
|
|
544
545
|
channelUsers: ['channelId', 'userId', 'membership'],
|
|
545
546
|
message: ['messageId'],
|
|
546
547
|
community: ['communityId', 'postSetting'],
|
|
@@ -549,7 +550,8 @@ const CRITERIAS = {
|
|
|
549
550
|
post: ['postId', 'feedId'],
|
|
550
551
|
comment: ['commentId', 'referenceId'],
|
|
551
552
|
poll: ['pollId'],
|
|
552
|
-
reaction: ['
|
|
553
|
+
reaction: ['referenceId', 'referenceType', 'reactors'],
|
|
554
|
+
reactor: ['reactionId'],
|
|
553
555
|
stream: ['streamId'],
|
|
554
556
|
follow: ['from', 'to'],
|
|
555
557
|
feed: ['feedId', 'feedType'],
|
|
@@ -22550,12 +22552,8 @@ const getTotalUnreadCount = (callback) => {
|
|
|
22550
22552
|
if (!userId)
|
|
22551
22553
|
throw new ASCError('The _id has not been defined in ActiveUser', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
22552
22554
|
const callbackDataSelector = (data) => { var _a; return (_a = data === null || data === void 0 ? void 0 : data.unreadCount) !== null && _a !== void 0 ? _a : 0; };
|
|
22553
|
-
// based on the mobile specs, unreadCount will not trigger observer when userMarker
|
|
22554
|
-
// is re-fetched, so apply this filter to ensure the behavior is the same.
|
|
22555
|
-
const callbackFilter = (newModel, oldModel) => (newModel === null || newModel === void 0 ? void 0 : newModel.unreadCount) !== (oldModel === null || oldModel === void 0 ? void 0 : oldModel.unreadCount);
|
|
22556
22555
|
return liveObject(userId, callback, 'userId', getUserMarker, [onUserMarkerFetched], {
|
|
22557
22556
|
callbackDataSelector,
|
|
22558
|
-
callbackFilter,
|
|
22559
22557
|
});
|
|
22560
22558
|
};
|
|
22561
22559
|
|
|
@@ -24305,6 +24303,7 @@ const onSubChannelDeleted = (callback) => {
|
|
|
24305
24303
|
};
|
|
24306
24304
|
|
|
24307
24305
|
const SYNC_TRIGGER_INTERVAL_TIME = 2000;
|
|
24306
|
+
const ON_SUB_CHANNEL_DELETE_SYNC_TRIGGER_DELAY = 2000;
|
|
24308
24307
|
let clearSyncTrigger;
|
|
24309
24308
|
let disposers = [];
|
|
24310
24309
|
let isWaitingForResponse = false;
|
|
@@ -24395,7 +24394,13 @@ const registerEventListeners = () => {
|
|
|
24395
24394
|
},
|
|
24396
24395
|
// only trigger sync from remote events to prevent an unread count equal `-1`
|
|
24397
24396
|
// when an optimistic message creation is performed.
|
|
24398
|
-
false), onChannelCreated(() => events.push("subchannel is created" /* Amity.MarkerSyncEvent.CHANNEL_CREATED */)), onChannelDeleted(() => events.push("subchannel is deleted" /* Amity.MarkerSyncEvent.CHANNEL_DELETED */)), onChannelJoined(() => events.push("subchannel is joined" /* Amity.MarkerSyncEvent.CHANNEL_JOINED */)), onChannelLeft(() => events.push("subchannel is left" /* Amity.MarkerSyncEvent.CHANNEL_LEFT */)), onSubChannelCreated(() => events.push("subchannel is created" /* Amity.MarkerSyncEvent.SUB_CHANNEL_CREATED */)), onSubChannelDeleted(() =>
|
|
24397
|
+
false), onChannelCreated(() => events.push("subchannel is created" /* Amity.MarkerSyncEvent.CHANNEL_CREATED */)), onChannelDeleted(() => events.push("subchannel is deleted" /* Amity.MarkerSyncEvent.CHANNEL_DELETED */)), onChannelJoined(() => events.push("subchannel is joined" /* Amity.MarkerSyncEvent.CHANNEL_JOINED */)), onChannelLeft(() => events.push("subchannel is left" /* Amity.MarkerSyncEvent.CHANNEL_LEFT */)), onSubChannelCreated(() => events.push("subchannel is created" /* Amity.MarkerSyncEvent.SUB_CHANNEL_CREATED */)), onSubChannelDeleted(() =>
|
|
24398
|
+
/*
|
|
24399
|
+
workaround: when receiving the event for sub-channel deletion,
|
|
24400
|
+
before triggering marker update, the SDK will have to add a 2-second delay.
|
|
24401
|
+
so that the unread count is calculated correctly.
|
|
24402
|
+
*/
|
|
24403
|
+
setTimeout(() => events.push("subchannel is deleted" /* Amity.MarkerSyncEvent.SUBCHANNEL_IS_DELETED */), ON_SUB_CHANNEL_DELETE_SYNC_TRIGGER_DELAY)), onFeedMarkerUpdated(() => events.push("feed marker updated" /* Amity.MarkerSyncEvent.MARKER_UPDATED */)), onUserMarkerSync(() => events.push("feed marker updated" /* Amity.MarkerSyncEvent.MARKER_UPDATED */)));
|
|
24399
24404
|
};
|
|
24400
24405
|
const unRegisterEventListeners = () => {
|
|
24401
24406
|
disposers.forEach(fn => fn());
|
|
@@ -27853,7 +27858,7 @@ const onReactorRemoved = (referenceType, referenceId, callback) => {
|
|
|
27853
27858
|
* })
|
|
27854
27859
|
* ```
|
|
27855
27860
|
*
|
|
27856
|
-
* Queries a paginable list of {@link Amity.
|
|
27861
|
+
* Queries a paginable list of {@link Amity.Reaction} objects
|
|
27857
27862
|
*
|
|
27858
27863
|
* @param query The query parameters
|
|
27859
27864
|
* @returns A page of {@link Amity.Reaction} objects
|
|
@@ -27880,6 +27885,30 @@ const queryReactions = async (query) => {
|
|
|
27880
27885
|
return { data: reactions, prevPage, nextPage };
|
|
27881
27886
|
};
|
|
27882
27887
|
|
|
27888
|
+
/**
|
|
27889
|
+
* ```js
|
|
27890
|
+
* import { queryReactor } from '@amityco/ts-sdk'
|
|
27891
|
+
* const { data: reactions, prevPage, nextPage } = await queryReactor({
|
|
27892
|
+
* referenceId: 'postId',
|
|
27893
|
+
* referenceType: 'post',
|
|
27894
|
+
* })
|
|
27895
|
+
* ```
|
|
27896
|
+
*
|
|
27897
|
+
* Queries a paginable list of {@link Amity.Reactor} objects
|
|
27898
|
+
*
|
|
27899
|
+
* @param query The query parameters
|
|
27900
|
+
* @returns A page of {@link Amity.Reactor} objects
|
|
27901
|
+
*
|
|
27902
|
+
* @reaction Reaction API
|
|
27903
|
+
* @async
|
|
27904
|
+
* */
|
|
27905
|
+
const queryReactor = async (query) => {
|
|
27906
|
+
const client = getActiveClient();
|
|
27907
|
+
client.log('reaction/queryReactor', query);
|
|
27908
|
+
const _a = await queryReactions(query), { data } = _a, response = __rest(_a, ["data"]);
|
|
27909
|
+
return Object.assign(Object.assign({}, response), { data: data[0].reactors });
|
|
27910
|
+
};
|
|
27911
|
+
|
|
27883
27912
|
/* begin_public_function
|
|
27884
27913
|
id: reaction.query
|
|
27885
27914
|
*/
|
|
@@ -27894,11 +27923,11 @@ const queryReactions = async (query) => {
|
|
|
27894
27923
|
* }, response => merge(reactions, response.data))
|
|
27895
27924
|
* ```
|
|
27896
27925
|
*
|
|
27897
|
-
* Observe all mutations on a list of {@link Amity.
|
|
27926
|
+
* Observe all mutations on a list of {@link Amity.Reactor} for a given target object
|
|
27898
27927
|
*
|
|
27899
|
-
* @param params
|
|
27900
|
-
* @param params.referenceId the ID of the target
|
|
27928
|
+
* @param params for querying reactions
|
|
27901
27929
|
* @param callback the function to call when new data are available
|
|
27930
|
+
* @param config the live collection configuration
|
|
27902
27931
|
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
27903
27932
|
*
|
|
27904
27933
|
* @category Reactions Live Collection
|
|
@@ -27953,7 +27982,7 @@ const getReactions = (params, callback, config) => {
|
|
|
27953
27982
|
const reactions = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
27954
27983
|
if (!initial && reactions.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
|
|
27955
27984
|
return;
|
|
27956
|
-
const query = createQuery(
|
|
27985
|
+
const query = createQuery(queryReactor, Object.assign(Object.assign({}, queryParams), { page: (_d = (!initial ? collection === null || collection === void 0 ? void 0 : collection.params.page : undefined)) !== null && _d !== void 0 ? _d : { limit } }));
|
|
27957
27986
|
runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
|
|
27958
27987
|
const data = {
|
|
27959
27988
|
loading,
|
|
@@ -27962,9 +27991,7 @@ const getReactions = (params, callback, config) => {
|
|
|
27962
27991
|
data: reactions,
|
|
27963
27992
|
};
|
|
27964
27993
|
if (result) {
|
|
27965
|
-
data.data = [
|
|
27966
|
-
...new Set([...reactions, ...result[0].reactors.map(getResolver('reaction'))]),
|
|
27967
|
-
];
|
|
27994
|
+
data.data = [...new Set([...reactions, ...result.map(getResolver('reactor'))])];
|
|
27968
27995
|
}
|
|
27969
27996
|
pushToCache(cacheKey, data);
|
|
27970
27997
|
responder(data);
|
|
@@ -29724,8 +29751,8 @@ const updateCommunity = async (communityId, patch) => {
|
|
|
29724
29751
|
|
|
29725
29752
|
/**
|
|
29726
29753
|
* ```js
|
|
29727
|
-
* import {
|
|
29728
|
-
* const community = await getCommunity('foobar')
|
|
29754
|
+
* import { CommunityRepository } from '@amityco/ts-sdk'
|
|
29755
|
+
* const community = await CommunityRepository.getCommunity('foobar')
|
|
29729
29756
|
* ```
|
|
29730
29757
|
*
|
|
29731
29758
|
* Fetches a {@link Amity.Community} object
|
|
@@ -29753,8 +29780,8 @@ const getCommunity$1 = async (communityId) => {
|
|
|
29753
29780
|
};
|
|
29754
29781
|
/**
|
|
29755
29782
|
* ```js
|
|
29756
|
-
* import {
|
|
29757
|
-
* const community = getCommunity.locally('foobar')
|
|
29783
|
+
* import { CommunityRepository } from '@amityco/ts-sdk'
|
|
29784
|
+
* const community = CommunityRepository.getCommunity.locally('foobar')
|
|
29758
29785
|
* ```
|
|
29759
29786
|
*
|
|
29760
29787
|
* Fetches a {@link Amity.Community} object from cache
|
|
@@ -29879,9 +29906,12 @@ const leaveCommunity = async (communityId) => {
|
|
|
29879
29906
|
id: community.query.trending_communities
|
|
29880
29907
|
*/
|
|
29881
29908
|
/**
|
|
29909
|
+
* @deprecated This API renamed to `getTrendingCommunities()`.
|
|
29910
|
+
* Please use getTrendingCommunities() instead.
|
|
29911
|
+
*
|
|
29882
29912
|
* ```js
|
|
29883
|
-
* import {
|
|
29884
|
-
* const trendingCommunities = await getTopTrendingCommunities()
|
|
29913
|
+
* import { CommunityRepository } from '@amityco/ts-sdk'
|
|
29914
|
+
* const trendingCommunities = await CommunityRepository.getTopTrendingCommunities()
|
|
29885
29915
|
* ```
|
|
29886
29916
|
*
|
|
29887
29917
|
* Gets a list of top trending {@link Amity.Community} objects
|
|
@@ -29943,74 +29973,6 @@ getTopTrendingCommunities.locally = (query) => {
|
|
|
29943
29973
|
: undefined;
|
|
29944
29974
|
};
|
|
29945
29975
|
|
|
29946
|
-
/* begin_public_function
|
|
29947
|
-
id: community.query.recommended_communities
|
|
29948
|
-
*/
|
|
29949
|
-
/**
|
|
29950
|
-
* ```js
|
|
29951
|
-
* import { getRecommendedCommunities } from '@amityco/ts-sdk'
|
|
29952
|
-
* const communities = await getRecommendedCommunities()
|
|
29953
|
-
* ```
|
|
29954
|
-
*
|
|
29955
|
-
* Gets a list of recommended {@link Amity.Community} objects
|
|
29956
|
-
*
|
|
29957
|
-
* @param query The query parameters
|
|
29958
|
-
* @returns A list of {@link Amity.Community} objects
|
|
29959
|
-
*
|
|
29960
|
-
* @category Community API
|
|
29961
|
-
* @async
|
|
29962
|
-
*/
|
|
29963
|
-
const getRecommendedCommunities = async (query) => {
|
|
29964
|
-
const client = getActiveClient();
|
|
29965
|
-
client.log('channel/getRecommendedCommunities', query);
|
|
29966
|
-
const { limit = 5 } = query !== null && query !== void 0 ? query : {};
|
|
29967
|
-
// API-FIX: backend doesnt answer Amity.Response
|
|
29968
|
-
// const { data: payload } = await client.http.get<Amity.Response<CommunityPayload>>(
|
|
29969
|
-
const { data: payload } = await client.http.get(`/api/v3/communities/recommended`, { params: { options: { limit } } });
|
|
29970
|
-
const data = prepareCommunityPayload(payload);
|
|
29971
|
-
const { communities } = data;
|
|
29972
|
-
const cachedAt = client.cache && Date.now();
|
|
29973
|
-
if (client.cache) {
|
|
29974
|
-
ingestInCache(data, { cachedAt });
|
|
29975
|
-
const cacheKey = ['community', 'recommended', { params: { options: { limit } } }];
|
|
29976
|
-
pushToCache(cacheKey, { communities: communities.map(getResolver('community')) });
|
|
29977
|
-
}
|
|
29978
|
-
return { data: communities, cachedAt };
|
|
29979
|
-
};
|
|
29980
|
-
/* end_public_function */
|
|
29981
|
-
/**
|
|
29982
|
-
* ```js
|
|
29983
|
-
* import { getRecommendedCommunities } from '@amityco/ts-sdk'
|
|
29984
|
-
* const communities = getRecommendedCommunities.locally()
|
|
29985
|
-
* ```
|
|
29986
|
-
*
|
|
29987
|
-
* Gets a list of recommended {@link Amity.Community} objects from cache
|
|
29988
|
-
*
|
|
29989
|
-
* @param query The query parameters
|
|
29990
|
-
* @returns communities
|
|
29991
|
-
*
|
|
29992
|
-
* @category Community API
|
|
29993
|
-
*/
|
|
29994
|
-
getRecommendedCommunities.locally = (query) => {
|
|
29995
|
-
var _a, _b;
|
|
29996
|
-
const client = getActiveClient();
|
|
29997
|
-
client.log('community/getRecommendedCommunities.locally', query);
|
|
29998
|
-
if (!client.cache)
|
|
29999
|
-
return;
|
|
30000
|
-
const { limit = 5 } = query !== null && query !== void 0 ? query : {};
|
|
30001
|
-
const queryKey = ['community', 'recommended', { params: { options: { limit } } }];
|
|
30002
|
-
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
30003
|
-
if (!(data === null || data === void 0 ? void 0 : data.communities.length))
|
|
30004
|
-
return;
|
|
30005
|
-
const communities = data.communities
|
|
30006
|
-
.map(communityId => pullFromCache(['community', 'get', communityId]))
|
|
30007
|
-
.filter(Boolean)
|
|
30008
|
-
.map(({ data }) => data);
|
|
30009
|
-
return communities.length === ((_b = data === null || data === void 0 ? void 0 : data.communities) === null || _b === void 0 ? void 0 : _b.length)
|
|
30010
|
-
? { data: communities, cachedAt }
|
|
30011
|
-
: undefined;
|
|
30012
|
-
};
|
|
30013
|
-
|
|
30014
29976
|
const createCommunityEventSubscriber = (event, callback) => {
|
|
30015
29977
|
const client = getActiveClient();
|
|
30016
29978
|
const filter = (payload) => {
|
|
@@ -30415,10 +30377,10 @@ const queryCommunities = async (query) => {
|
|
|
30415
30377
|
*/
|
|
30416
30378
|
/**
|
|
30417
30379
|
* ```js
|
|
30418
|
-
* import {
|
|
30380
|
+
* import { CommunityRepository } from '@amityco/ts-sdk'
|
|
30419
30381
|
*
|
|
30420
30382
|
* let communities = []
|
|
30421
|
-
* const unsub = getCommunities({
|
|
30383
|
+
* const unsub = CommunityRepository.getCommunities({
|
|
30422
30384
|
* displayName: Amity.Community['displayName'],
|
|
30423
30385
|
* }, response => merge(communities, response.data))
|
|
30424
30386
|
* ```
|
|
@@ -30535,11 +30497,11 @@ const getCommunities = (params, callback, config) => {
|
|
|
30535
30497
|
*/
|
|
30536
30498
|
/**
|
|
30537
30499
|
* ```js
|
|
30538
|
-
* import {
|
|
30500
|
+
* import { CommunityRepository } from '@amityco/ts-sdk';
|
|
30539
30501
|
*
|
|
30540
30502
|
* let community;
|
|
30541
30503
|
*
|
|
30542
|
-
* const
|
|
30504
|
+
* const unsub = CommunityRepository.getCommunity(communityId, response => {
|
|
30543
30505
|
* community = response.data;
|
|
30544
30506
|
* });
|
|
30545
30507
|
* ```
|
|
@@ -30565,6 +30527,221 @@ const getCommunity = (communityId, callback) => {
|
|
|
30565
30527
|
};
|
|
30566
30528
|
/* end_public_function */
|
|
30567
30529
|
|
|
30530
|
+
const communityQueryFilter = (data, params, userId) => {
|
|
30531
|
+
let communities = data;
|
|
30532
|
+
communities = filterByPropEquality(communities, 'displayName', params.displayName);
|
|
30533
|
+
if (!params.includeDeleted) {
|
|
30534
|
+
communities = filterByPropEquality(communities, 'isDeleted', false);
|
|
30535
|
+
}
|
|
30536
|
+
if (params.categoryId) {
|
|
30537
|
+
communities = communities.filter(c => { var _a; return (_a = c.categoryIds) === null || _a === void 0 ? void 0 : _a.includes(params.categoryId); });
|
|
30538
|
+
}
|
|
30539
|
+
if (params.tags) {
|
|
30540
|
+
communities = communities.filter(c => { var _a; return (_a = c.tags) === null || _a === void 0 ? void 0 : _a.some(t => { var _a; return (_a = params.tags) === null || _a === void 0 ? void 0 : _a.includes(t); }); });
|
|
30541
|
+
}
|
|
30542
|
+
if (params.membership && userId) {
|
|
30543
|
+
communities = filterByCommunityMembership(communities, params.membership, userId);
|
|
30544
|
+
}
|
|
30545
|
+
const sortBy = params.sortBy || 'lastCreated';
|
|
30546
|
+
if (sortBy === 'lastCreated' || sortBy === 'firstCreated') {
|
|
30547
|
+
communities = communities.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
30548
|
+
}
|
|
30549
|
+
/*
|
|
30550
|
+
* The server returns communities with empty | null displayName's first before
|
|
30551
|
+
* returning sorted list of communities with displayNames
|
|
30552
|
+
*
|
|
30553
|
+
* This section needs to be updated as displayNames can be null as well
|
|
30554
|
+
*/
|
|
30555
|
+
if (sortBy === 'displayName') {
|
|
30556
|
+
communities = communities
|
|
30557
|
+
// this needs to be aligned with the backend data type
|
|
30558
|
+
.map(c => (c.displayName ? c : Object.assign(Object.assign({}, c), { displayName: '' })))
|
|
30559
|
+
// @ts-ignore
|
|
30560
|
+
.sort(sortByDisplayName);
|
|
30561
|
+
}
|
|
30562
|
+
return communities;
|
|
30563
|
+
};
|
|
30564
|
+
|
|
30565
|
+
/* begin_public_function
|
|
30566
|
+
id: community.query
|
|
30567
|
+
*/
|
|
30568
|
+
/**
|
|
30569
|
+
* ```js
|
|
30570
|
+
* import { CommunityRepository } from '@amityco/ts-sdk'
|
|
30571
|
+
*
|
|
30572
|
+
* let communities = []
|
|
30573
|
+
* const unsub = CommunityRepository.getCommunities({
|
|
30574
|
+
* displayName: Amity.Community['displayName'],
|
|
30575
|
+
* }, response => merge(communities, response.data))
|
|
30576
|
+
* ```
|
|
30577
|
+
*
|
|
30578
|
+
* Observe all mutations on a list of {@link Amity.Community}s
|
|
30579
|
+
*
|
|
30580
|
+
* @param params for querying communities
|
|
30581
|
+
* @param callback the function to call when new data are available
|
|
30582
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the communities
|
|
30583
|
+
*
|
|
30584
|
+
* @category Community Live Collection
|
|
30585
|
+
*/
|
|
30586
|
+
const getTrendingCommunities = (params, callback, config) => {
|
|
30587
|
+
const { log, cache, userId } = getActiveClient();
|
|
30588
|
+
if (!cache) {
|
|
30589
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
30590
|
+
}
|
|
30591
|
+
const timestamp = Date.now();
|
|
30592
|
+
log(`getTrendingCommunities(tmpid: ${timestamp}) > listen`);
|
|
30593
|
+
const { limit: queryLimit } = params, queryParams = __rest(params, ["limit"]);
|
|
30594
|
+
const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
|
|
30595
|
+
const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
|
|
30596
|
+
const disposers = [];
|
|
30597
|
+
const cacheKey = ['community', 'top-trending', { params: { options: { limit } } }];
|
|
30598
|
+
const responder = (data, isEventModel = false) => {
|
|
30599
|
+
var _a, _b;
|
|
30600
|
+
const communities = (_a = data.data
|
|
30601
|
+
.map(communityId => pullFromCache(['community', 'get', communityId]))
|
|
30602
|
+
.filter(Boolean)
|
|
30603
|
+
.map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
|
|
30604
|
+
callback({
|
|
30605
|
+
onNextPage: onFetch,
|
|
30606
|
+
data: isEventModel ? communityQueryFilter(communities, params, userId) : communities,
|
|
30607
|
+
hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
|
|
30608
|
+
loading: data.loading,
|
|
30609
|
+
error: data.error,
|
|
30610
|
+
});
|
|
30611
|
+
};
|
|
30612
|
+
const realtimeRouter = (_) => (community) => {
|
|
30613
|
+
var _a;
|
|
30614
|
+
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30615
|
+
if (!collection)
|
|
30616
|
+
return;
|
|
30617
|
+
/*
|
|
30618
|
+
* Simply update collection and let responder decide what to do with data
|
|
30619
|
+
*/
|
|
30620
|
+
collection.data = [...new Set([community.communityId, ...collection.data])];
|
|
30621
|
+
pushToCache(cacheKey, collection);
|
|
30622
|
+
responder(collection);
|
|
30623
|
+
};
|
|
30624
|
+
const onFetch = (initial = false) => {
|
|
30625
|
+
var _a, _b, _c;
|
|
30626
|
+
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30627
|
+
const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
30628
|
+
if (!initial && communities.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
|
|
30629
|
+
return;
|
|
30630
|
+
const query = createQuery(queryCommunities, Object.assign(Object.assign({}, queryParams), { page: (_c = (!initial ? collection === null || collection === void 0 ? void 0 : collection.params.page : undefined)) !== null && _c !== void 0 ? _c : { limit } }));
|
|
30631
|
+
runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
|
|
30632
|
+
const data = {
|
|
30633
|
+
loading,
|
|
30634
|
+
error,
|
|
30635
|
+
params: { page },
|
|
30636
|
+
data: communities,
|
|
30637
|
+
};
|
|
30638
|
+
if (result) {
|
|
30639
|
+
data.data = [...new Set([...communities, ...result.map(getResolver('community'))])];
|
|
30640
|
+
}
|
|
30641
|
+
pushToCache(cacheKey, data);
|
|
30642
|
+
responder(data);
|
|
30643
|
+
}, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
|
|
30644
|
+
};
|
|
30645
|
+
disposers.push(onCommunityUserChanged(realtimeRouter()));
|
|
30646
|
+
onFetch(true);
|
|
30647
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
30648
|
+
return () => {
|
|
30649
|
+
log(`getTrendingCommunities(tmpid: ${timestamp}) > dispose`);
|
|
30650
|
+
disposers.forEach(fn => fn());
|
|
30651
|
+
};
|
|
30652
|
+
};
|
|
30653
|
+
/* end_public_function */
|
|
30654
|
+
|
|
30655
|
+
/* begin_public_function
|
|
30656
|
+
id: community.query
|
|
30657
|
+
*/
|
|
30658
|
+
/**
|
|
30659
|
+
* ```js
|
|
30660
|
+
* import { CommunityRepository } from '@amityco/ts-sdk'
|
|
30661
|
+
*
|
|
30662
|
+
* let communities = []
|
|
30663
|
+
* const unsub = CommunityRepository.getCommunities({
|
|
30664
|
+
* displayName: Amity.Community['displayName'],
|
|
30665
|
+
* }, response => merge(communities, response.data))
|
|
30666
|
+
* ```
|
|
30667
|
+
*
|
|
30668
|
+
* Observe all mutations on a list of {@link Amity.Community}s
|
|
30669
|
+
*
|
|
30670
|
+
* @param params for querying communities
|
|
30671
|
+
* @param callback the function to call when new data are available
|
|
30672
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the communities
|
|
30673
|
+
*
|
|
30674
|
+
* @category Community Live Collection
|
|
30675
|
+
*/
|
|
30676
|
+
const getRecommendedCommunities = (params, callback, config) => {
|
|
30677
|
+
const { log, cache, userId } = getActiveClient();
|
|
30678
|
+
if (!cache) {
|
|
30679
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
30680
|
+
}
|
|
30681
|
+
const timestamp = Date.now();
|
|
30682
|
+
log(`getRecommendedCommunities(tmpid: ${timestamp}) > listen`);
|
|
30683
|
+
const { limit: queryLimit } = params, queryParams = __rest(params, ["limit"]);
|
|
30684
|
+
const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
|
|
30685
|
+
const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
|
|
30686
|
+
const disposers = [];
|
|
30687
|
+
const cacheKey = ['community', 'recommended', { params: { options: { limit } } }];
|
|
30688
|
+
const responder = (data, isEventModel = false) => {
|
|
30689
|
+
var _a, _b;
|
|
30690
|
+
const communities = (_a = data.data
|
|
30691
|
+
.map(communityId => pullFromCache(['community', 'get', communityId]))
|
|
30692
|
+
.filter(Boolean)
|
|
30693
|
+
.map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
|
|
30694
|
+
callback({
|
|
30695
|
+
onNextPage: onFetch,
|
|
30696
|
+
data: isEventModel ? communityQueryFilter(communities, params, userId) : communities,
|
|
30697
|
+
hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
|
|
30698
|
+
loading: data.loading,
|
|
30699
|
+
error: data.error,
|
|
30700
|
+
});
|
|
30701
|
+
};
|
|
30702
|
+
const realtimeRouter = (_) => (community) => {
|
|
30703
|
+
var _a;
|
|
30704
|
+
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30705
|
+
if (!collection)
|
|
30706
|
+
return;
|
|
30707
|
+
/*
|
|
30708
|
+
* Simply update collection and let responder decide what to do with data
|
|
30709
|
+
*/
|
|
30710
|
+
collection.data = [...new Set([community.communityId, ...collection.data])];
|
|
30711
|
+
pushToCache(cacheKey, collection);
|
|
30712
|
+
responder(collection);
|
|
30713
|
+
};
|
|
30714
|
+
const onFetch = (initial = false) => {
|
|
30715
|
+
var _a, _b, _c;
|
|
30716
|
+
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30717
|
+
const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
30718
|
+
if (!initial && communities.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
|
|
30719
|
+
return;
|
|
30720
|
+
const query = createQuery(queryCommunities, Object.assign(Object.assign({}, queryParams), { page: (_c = (!initial ? collection === null || collection === void 0 ? void 0 : collection.params.page : undefined)) !== null && _c !== void 0 ? _c : { limit } }));
|
|
30721
|
+
runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
|
|
30722
|
+
const data = {
|
|
30723
|
+
loading,
|
|
30724
|
+
error,
|
|
30725
|
+
params: { page },
|
|
30726
|
+
data: communities,
|
|
30727
|
+
};
|
|
30728
|
+
if (result) {
|
|
30729
|
+
data.data = [...new Set([...communities, ...result.map(getResolver('community'))])];
|
|
30730
|
+
}
|
|
30731
|
+
pushToCache(cacheKey, data);
|
|
30732
|
+
responder(data);
|
|
30733
|
+
}, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
|
|
30734
|
+
};
|
|
30735
|
+
disposers.push(onCommunityUserChanged(realtimeRouter()));
|
|
30736
|
+
onFetch(true);
|
|
30737
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
30738
|
+
return () => {
|
|
30739
|
+
log(`getRecommendedCommunities(tmpid: ${timestamp}) > dispose`);
|
|
30740
|
+
disposers.forEach(fn => fn());
|
|
30741
|
+
};
|
|
30742
|
+
};
|
|
30743
|
+
/* end_public_function */
|
|
30744
|
+
|
|
30568
30745
|
/* begin_public_function
|
|
30569
30746
|
id: community.moderation.add_roles
|
|
30570
30747
|
*/
|
|
@@ -30993,13 +31170,14 @@ var index$6 = /*#__PURE__*/Object.freeze({
|
|
|
30993
31170
|
joinCommunity: joinCommunity,
|
|
30994
31171
|
leaveCommunity: leaveCommunity,
|
|
30995
31172
|
getTopTrendingCommunities: getTopTrendingCommunities,
|
|
30996
|
-
getRecommendedCommunities: getRecommendedCommunities,
|
|
30997
31173
|
onCommunityCreated: onCommunityCreated,
|
|
30998
31174
|
onCommunityUpdated: onCommunityUpdated,
|
|
30999
31175
|
onCommunityDeleted: onCommunityDeleted,
|
|
31000
31176
|
observeCommunity: observeCommunity,
|
|
31001
31177
|
getCommunities: getCommunities,
|
|
31002
|
-
getCommunity: getCommunity
|
|
31178
|
+
getCommunity: getCommunity,
|
|
31179
|
+
getTrendingCommunities: getTrendingCommunities,
|
|
31180
|
+
getRecommendedCommunities: getRecommendedCommunities
|
|
31003
31181
|
});
|
|
31004
31182
|
|
|
31005
31183
|
/* begin_public_function
|
|
@@ -31091,7 +31269,7 @@ const queryCategories = async (query) => {
|
|
|
31091
31269
|
const cacheKey = [
|
|
31092
31270
|
'category',
|
|
31093
31271
|
'query',
|
|
31094
|
-
Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
|
|
31272
|
+
Object.assign(Object.assign({}, params), { includeDeleted, options: Object.assign({}, page) }),
|
|
31095
31273
|
];
|
|
31096
31274
|
pushToCache(cacheKey, { categories: categories.map(getResolver('category')), paging });
|
|
31097
31275
|
}
|
|
@@ -31970,11 +32148,11 @@ const observePost = (postId, callback, policy = 'cache_then_server') => {
|
|
|
31970
32148
|
*/
|
|
31971
32149
|
/**
|
|
31972
32150
|
* ```js
|
|
31973
|
-
* import {
|
|
32151
|
+
* import { PostRepository } from '@amityco/ts-sdk';
|
|
31974
32152
|
*
|
|
31975
32153
|
* let post;
|
|
31976
32154
|
*
|
|
31977
|
-
* const
|
|
32155
|
+
* const unsub = PostRepository.getPost(postId, response => {
|
|
31978
32156
|
* post = response.data;
|
|
31979
32157
|
* });
|
|
31980
32158
|
* ```
|
|
@@ -32054,7 +32232,7 @@ const queryPosts = async (query) => {
|
|
|
32054
32232
|
};
|
|
32055
32233
|
|
|
32056
32234
|
/* begin_public_function
|
|
32057
|
-
id: post.query
|
|
32235
|
+
id: post.query
|
|
32058
32236
|
*/
|
|
32059
32237
|
/**
|
|
32060
32238
|
* ```js
|
|
@@ -32630,11 +32808,11 @@ const observeComment = (commentId, callback, policy = 'cache_then_server') => {
|
|
|
32630
32808
|
*/
|
|
32631
32809
|
/**
|
|
32632
32810
|
* ```js
|
|
32633
|
-
* import {
|
|
32811
|
+
* import { CommentRepository } from '@amityco/ts-sdk';
|
|
32634
32812
|
*
|
|
32635
32813
|
* let comment;
|
|
32636
32814
|
*
|
|
32637
|
-
* const
|
|
32815
|
+
* const unsub = CommentRepository.getComment(commentId, response => {
|
|
32638
32816
|
* comment = response.data;
|
|
32639
32817
|
* });
|
|
32640
32818
|
* ```
|
|
@@ -33267,64 +33445,6 @@ var index$1 = /*#__PURE__*/Object.freeze({
|
|
|
33267
33445
|
getStreams: getStreams
|
|
33268
33446
|
});
|
|
33269
33447
|
|
|
33270
|
-
/* begin_public_function
|
|
33271
|
-
id: poll.get
|
|
33272
|
-
*/
|
|
33273
|
-
/**
|
|
33274
|
-
* ```js
|
|
33275
|
-
* import { getPoll } from '@amityco/ts-sdk'
|
|
33276
|
-
* const poll = await getPoll('foobar')
|
|
33277
|
-
* ```
|
|
33278
|
-
*
|
|
33279
|
-
* Fetches a {@link Amity.Poll} object
|
|
33280
|
-
*
|
|
33281
|
-
* @param pollId the ID of the {@link Amity.Poll} to fetch
|
|
33282
|
-
* @returns the associated {@link Amity.Poll} object
|
|
33283
|
-
*
|
|
33284
|
-
* @category Poll API
|
|
33285
|
-
* @async
|
|
33286
|
-
*/
|
|
33287
|
-
const getPoll = async (pollId) => {
|
|
33288
|
-
const client = getActiveClient();
|
|
33289
|
-
client.log('poll/getPoll', pollId);
|
|
33290
|
-
const { data } = await client.http.get(`/api/v3/polls/${pollId}`);
|
|
33291
|
-
const cachedAt = client.cache && Date.now();
|
|
33292
|
-
if (client.cache)
|
|
33293
|
-
ingestInCache(data, { cachedAt });
|
|
33294
|
-
const { polls } = data;
|
|
33295
|
-
return {
|
|
33296
|
-
data: polls.find(poll => poll.pollId === pollId),
|
|
33297
|
-
cachedAt,
|
|
33298
|
-
};
|
|
33299
|
-
};
|
|
33300
|
-
/* end_public_function */
|
|
33301
|
-
/**
|
|
33302
|
-
* ```js
|
|
33303
|
-
* import { getPoll } from '@amityco/ts-sdk'
|
|
33304
|
-
* const poll = getPoll.locally('foobar')
|
|
33305
|
-
* ```
|
|
33306
|
-
*
|
|
33307
|
-
* Fetches a {@link Amity.Poll} object
|
|
33308
|
-
*
|
|
33309
|
-
* @param pollId the ID of the {@link Amity.Poll} to fetch
|
|
33310
|
-
* @returns the associated {@link Amity.Poll} object
|
|
33311
|
-
*
|
|
33312
|
-
* @category Poll API
|
|
33313
|
-
*/
|
|
33314
|
-
getPoll.locally = (pollId) => {
|
|
33315
|
-
const client = getActiveClient();
|
|
33316
|
-
client.log('poll/getPoll', pollId);
|
|
33317
|
-
if (!client.cache)
|
|
33318
|
-
return;
|
|
33319
|
-
const cached = pullFromCache(['poll', 'get', pollId]);
|
|
33320
|
-
if (!cached)
|
|
33321
|
-
return;
|
|
33322
|
-
return {
|
|
33323
|
-
data: cached.data,
|
|
33324
|
-
cachedAt: cached.cachedAt,
|
|
33325
|
-
};
|
|
33326
|
-
};
|
|
33327
|
-
|
|
33328
33448
|
/* begin_public_function
|
|
33329
33449
|
id: poll.create
|
|
33330
33450
|
*/
|
|
@@ -33397,6 +33517,64 @@ const closePoll = async (pollId) => {
|
|
|
33397
33517
|
};
|
|
33398
33518
|
/* end_public_function */
|
|
33399
33519
|
|
|
33520
|
+
/* begin_public_function
|
|
33521
|
+
id: poll.get
|
|
33522
|
+
*/
|
|
33523
|
+
/**
|
|
33524
|
+
* ```js
|
|
33525
|
+
* import { getPoll } from '@amityco/ts-sdk'
|
|
33526
|
+
* const poll = await getPoll('foobar')
|
|
33527
|
+
* ```
|
|
33528
|
+
*
|
|
33529
|
+
* Fetches a {@link Amity.Poll} object
|
|
33530
|
+
*
|
|
33531
|
+
* @param pollId the ID of the {@link Amity.Poll} to fetch
|
|
33532
|
+
* @returns the associated {@link Amity.Poll} object
|
|
33533
|
+
*
|
|
33534
|
+
* @category Poll API
|
|
33535
|
+
* @async
|
|
33536
|
+
*/
|
|
33537
|
+
const getPoll$1 = async (pollId) => {
|
|
33538
|
+
const client = getActiveClient();
|
|
33539
|
+
client.log('poll/getPoll', pollId);
|
|
33540
|
+
const { data } = await client.http.get(`/api/v3/polls/${pollId}`);
|
|
33541
|
+
const cachedAt = client.cache && Date.now();
|
|
33542
|
+
if (client.cache)
|
|
33543
|
+
ingestInCache(data, { cachedAt });
|
|
33544
|
+
const { polls } = data;
|
|
33545
|
+
return {
|
|
33546
|
+
data: polls.find(poll => poll.pollId === pollId),
|
|
33547
|
+
cachedAt,
|
|
33548
|
+
};
|
|
33549
|
+
};
|
|
33550
|
+
/* end_public_function */
|
|
33551
|
+
/**
|
|
33552
|
+
* ```js
|
|
33553
|
+
* import { getPoll } from '@amityco/ts-sdk'
|
|
33554
|
+
* const poll = getPoll.locally('foobar')
|
|
33555
|
+
* ```
|
|
33556
|
+
*
|
|
33557
|
+
* Fetches a {@link Amity.Poll} object
|
|
33558
|
+
*
|
|
33559
|
+
* @param pollId the ID of the {@link Amity.Poll} to fetch
|
|
33560
|
+
* @returns the associated {@link Amity.Poll} object
|
|
33561
|
+
*
|
|
33562
|
+
* @category Poll API
|
|
33563
|
+
*/
|
|
33564
|
+
getPoll$1.locally = (pollId) => {
|
|
33565
|
+
const client = getActiveClient();
|
|
33566
|
+
client.log('poll/getPoll', pollId);
|
|
33567
|
+
if (!client.cache)
|
|
33568
|
+
return;
|
|
33569
|
+
const cached = pullFromCache(['poll', 'get', pollId]);
|
|
33570
|
+
if (!cached)
|
|
33571
|
+
return;
|
|
33572
|
+
return {
|
|
33573
|
+
data: cached.data,
|
|
33574
|
+
cachedAt: cached.cachedAt,
|
|
33575
|
+
};
|
|
33576
|
+
};
|
|
33577
|
+
|
|
33400
33578
|
/* begin_public_function
|
|
33401
33579
|
id: poll.delete
|
|
33402
33580
|
*/
|
|
@@ -33417,7 +33595,7 @@ const closePoll = async (pollId) => {
|
|
|
33417
33595
|
const deletePoll = async (pollId) => {
|
|
33418
33596
|
const client = getActiveClient();
|
|
33419
33597
|
client.log('poll/deletePoll', pollId);
|
|
33420
|
-
const poll = await getPoll(pollId);
|
|
33598
|
+
const poll = await getPoll$1(pollId);
|
|
33421
33599
|
// API-FIX: it returns { success: boolean } but seems it should be Amity.Response<{ success: boolean }
|
|
33422
33600
|
const { data } = await client.http.delete(`/api/v3/polls/${pollId}`);
|
|
33423
33601
|
const { success } = data; // unwrapPayload(data)
|
|
@@ -33549,23 +33727,50 @@ const observePoll = (pollId, callback, policy = 'cache_then_server') => {
|
|
|
33549
33727
|
};
|
|
33550
33728
|
const disposers = [];
|
|
33551
33729
|
disposers.push(onPollUpdated(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUpdate')), onPollDeleted(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onDelete')));
|
|
33552
|
-
runQuery(createQuery(getPoll, pollId), result => (result.data || result.error) && router(result, 'onFetch'), queryOptions(policy));
|
|
33730
|
+
runQuery(createQuery(getPoll$1, pollId), result => (result.data || result.error) && router(result, 'onFetch'), queryOptions(policy));
|
|
33553
33731
|
return () => {
|
|
33554
33732
|
log(`observePoll(tmpid: ${timestamp}) > dispose`);
|
|
33555
33733
|
disposers.forEach(fn => fn());
|
|
33556
33734
|
};
|
|
33557
33735
|
};
|
|
33558
33736
|
|
|
33737
|
+
/* begin_public_function
|
|
33738
|
+
id: poll.get
|
|
33739
|
+
*/
|
|
33740
|
+
/**
|
|
33741
|
+
* ```js
|
|
33742
|
+
* import { PollRepository } from '@amityco/ts-sdk';
|
|
33743
|
+
*
|
|
33744
|
+
* let poll;
|
|
33745
|
+
*
|
|
33746
|
+
* const unsub = PollRepository.getPoll(commentId, response => {
|
|
33747
|
+
* poll = response.data;
|
|
33748
|
+
* });
|
|
33749
|
+
* ```
|
|
33750
|
+
*
|
|
33751
|
+
* Observe all mutation on a given {@link Amity.Poll}
|
|
33752
|
+
*
|
|
33753
|
+
* @param pollId the ID of the poll to observe
|
|
33754
|
+
* @param callback the function to call when new data are available
|
|
33755
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the poll
|
|
33756
|
+
*
|
|
33757
|
+
* @category Poll Live Object
|
|
33758
|
+
*/
|
|
33759
|
+
const getPoll = (pollId, callback) => {
|
|
33760
|
+
return liveObject(pollId, callback, 'pollId', getPoll$1, [onPollUpdated, onPollDeleted]);
|
|
33761
|
+
};
|
|
33762
|
+
/* end_public_function */
|
|
33763
|
+
|
|
33559
33764
|
var index = /*#__PURE__*/Object.freeze({
|
|
33560
33765
|
__proto__: null,
|
|
33561
|
-
getPoll: getPoll,
|
|
33562
33766
|
createPoll: createPoll,
|
|
33563
33767
|
closePoll: closePoll,
|
|
33564
33768
|
deletePoll: deletePoll,
|
|
33565
33769
|
votePoll: votePoll,
|
|
33566
33770
|
onPollUpdated: onPollUpdated,
|
|
33567
33771
|
onPollDeleted: onPollDeleted,
|
|
33568
|
-
observePoll: observePoll
|
|
33772
|
+
observePoll: observePoll,
|
|
33773
|
+
getPoll: getPoll
|
|
33569
33774
|
});
|
|
33570
33775
|
|
|
33571
33776
|
/**
|