@amityco/ts-sdk 6.23.0 → 6.23.1-303013.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/.env +26 -26
- package/dist/@types/core/events.d.ts +5 -0
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/domains/community.d.ts +16 -1
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/client/utils/ReadReceiptSync/readReceiptSyncEngine.d.ts.map +1 -1
- package/dist/commentRepository/api/deleteComment.d.ts.map +1 -1
- package/dist/commentRepository/internalApi/createComment.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersLiveCollectionController.d.ts +14 -0
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersLiveCollectionController.d.ts.map +1 -0
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersPaginationController.d.ts +9 -0
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersPaginationController.d.ts.map +1 -0
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.d.ts +15 -0
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.d.ts.map +1 -0
- package/dist/communityRepository/communityMembership/observers/getMembers/enums.d.ts +10 -0
- package/dist/communityRepository/communityMembership/observers/getMembers/enums.d.ts.map +1 -0
- package/dist/communityRepository/communityMembership/observers/getMembers.d.ts.map +1 -1
- package/dist/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.d.ts +14 -0
- package/dist/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.d.ts.map +1 -0
- package/dist/communityRepository/observers/getCommunities/CommunitiesPaginationController.d.ts +9 -0
- package/dist/communityRepository/observers/getCommunities/CommunitiesPaginationController.d.ts.map +1 -0
- package/dist/communityRepository/observers/getCommunities/CommunitiesQueryStreamController.d.ts +15 -0
- package/dist/communityRepository/observers/getCommunities/CommunitiesQueryStreamController.d.ts.map +1 -0
- package/dist/communityRepository/observers/getCommunities/enums.d.ts +6 -0
- package/dist/communityRepository/observers/getCommunities/enums.d.ts.map +1 -0
- package/dist/communityRepository/observers/getCommunities.d.ts.map +1 -1
- package/dist/communityRepository/observers/index.d.ts +1 -0
- package/dist/communityRepository/observers/index.d.ts.map +1 -1
- package/dist/communityRepository/observers/searchCommunities/SearchCommunitiesLiveCollectionController.d.ts +14 -0
- package/dist/communityRepository/observers/searchCommunities/SearchCommunitiesLiveCollectionController.d.ts.map +1 -0
- package/dist/communityRepository/observers/searchCommunities/SearchCommunitiesPaginationController.d.ts +9 -0
- package/dist/communityRepository/observers/searchCommunities/SearchCommunitiesPaginationController.d.ts.map +1 -0
- package/dist/communityRepository/observers/searchCommunities/SearchCommunitiesQueryStreamController.d.ts +15 -0
- package/dist/communityRepository/observers/searchCommunities/SearchCommunitiesQueryStreamController.d.ts.map +1 -0
- package/dist/communityRepository/observers/searchCommunities/enums.d.ts +6 -0
- package/dist/communityRepository/observers/searchCommunities/enums.d.ts.map +1 -0
- package/dist/communityRepository/observers/searchCommunities.d.ts +20 -0
- package/dist/communityRepository/observers/searchCommunities.d.ts.map +1 -0
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.d.ts.map +1 -1
- package/dist/core/liveCollection/LiveCollectionController.d.ts +4 -1
- package/dist/core/liveCollection/LiveCollectionController.d.ts.map +1 -1
- package/dist/index.cjs.js +963 -652
- package/dist/index.esm.js +962 -651
- package/dist/index.umd.js +4 -4
- package/dist/marker/events/onChannelUnreadUpdatedLocal.d.ts +12 -0
- package/dist/marker/events/onChannelUnreadUpdatedLocal.d.ts.map +1 -0
- package/dist/marker/events/onSubChannelUnreadUpdatedLocal.d.ts +12 -0
- package/dist/marker/events/onSubChannelUnreadUpdatedLocal.d.ts.map +1 -0
- package/dist/marker/events/onUserFeedMarkerUpdated.d.ts.map +1 -1
- package/dist/marker/utils/reCalculateChannelUnreadInfo.d.ts +1 -1
- package/dist/marker/utils/reCalculateChannelUnreadInfo.d.ts.map +1 -1
- package/dist/postRepository/observers/getPost.d.ts.map +1 -1
- package/dist/postRepository/observers/getPosts.d.ts.map +1 -1
- package/dist/utils/liveObject.d.ts +3 -0
- package/dist/utils/liveObject.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/core/events.ts +8 -0
- package/src/@types/domains/community.ts +26 -1
- package/src/channelRepository/channelMembership/observers/getMembers/ChannelMemberLiveCollectionController.ts +2 -2
- package/src/channelRepository/observers/getChannel.ts +2 -2
- package/src/channelRepository/observers/getChannels/ChannelLiveCollectionController.ts +7 -7
- package/src/client/utils/ReadReceiptSync/readReceiptSyncEngine.ts +6 -3
- package/src/commentRepository/api/createComment.ts +2 -2
- package/src/commentRepository/api/deleteComment.ts +2 -4
- package/src/commentRepository/events/utils.ts +1 -1
- package/src/commentRepository/internalApi/createComment.ts +3 -2
- package/src/commentRepository/internalApi/deleteComment.ts +2 -2
- package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersLiveCollectionController.ts +152 -0
- package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersPaginationController.ts +26 -0
- package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.ts +107 -0
- package/src/communityRepository/communityMembership/observers/getMembers/enums.ts +9 -0
- package/src/communityRepository/communityMembership/observers/getMembers.ts +15 -128
- package/src/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.ts +147 -0
- package/src/communityRepository/observers/getCommunities/CommunitiesPaginationController.ts +31 -0
- package/src/communityRepository/observers/getCommunities/CommunitiesQueryStreamController.ts +86 -0
- package/src/communityRepository/observers/getCommunities/enums.ts +5 -0
- package/src/communityRepository/observers/getCommunities.ts +7 -150
- package/src/communityRepository/observers/index.ts +1 -0
- package/src/communityRepository/observers/searchCommunities/SearchCommunitiesLiveCollectionController.ts +129 -0
- package/src/communityRepository/observers/searchCommunities/SearchCommunitiesPaginationController.ts +31 -0
- package/src/communityRepository/observers/searchCommunities/SearchCommunitiesQueryStreamController.ts +81 -0
- package/src/communityRepository/observers/searchCommunities/enums.ts +5 -0
- package/src/communityRepository/observers/searchCommunities.ts +56 -0
- package/src/core/liveCollection/LiveCollectionController.ts +6 -3
- package/src/marker/events/onChannelUnreadUpdatedLocal.ts +29 -0
- package/src/marker/events/onSubChannelMarkerFetched.ts +1 -1
- package/src/marker/events/onSubChannelUnreadUpdatedLocal.ts +29 -0
- package/src/marker/events/onUserFeedMarkerUpdated.ts +3 -4
- package/src/marker/utils/reCalculateChannelUnreadInfo.ts +7 -3
- package/src/messageRepository/observers/getMessages/MessageLiveCollectionController.ts +3 -3
- package/src/postRepository/api/editPost.ts +1 -1
- package/src/postRepository/api/updatePost.ts +1 -1
- package/src/postRepository/observers/getPost.ts +26 -0
- package/src/postRepository/observers/getPosts.ts +31 -0
- package/src/storyRepository/observers/getGlobalStoryTargets/GlobalStoryLiveCollectionController.ts +2 -2
- package/src/storyRepository/observers/getStoriesByTargetIds/StoryLiveCollectionController.ts +1 -1
- package/src/subChannelRepository/observers/getSubChannel.ts +2 -2
- package/src/subChannelRepository/observers/getSubChannels/SubChannelLiveCollectionController.ts +4 -4
- package/src/utils/liveObject.ts +3 -0
package/dist/index.cjs.js
CHANGED
|
@@ -5400,7 +5400,7 @@ const markAsReadBySegment = async ({ subChannelId, readToSegment, }) => {
|
|
|
5400
5400
|
}
|
|
5401
5401
|
};
|
|
5402
5402
|
|
|
5403
|
-
const reCalculateChannelUnreadInfo =
|
|
5403
|
+
const reCalculateChannelUnreadInfo = (channelId) => {
|
|
5404
5404
|
var _a;
|
|
5405
5405
|
const cacheKeyChannelUnread = ['channelUnreadInfo', 'get', channelId];
|
|
5406
5406
|
const cacheChannelUnreadInfo = (_a = pullFromCache(cacheKeyChannelUnread)) === null || _a === void 0 ? void 0 : _a.data;
|
|
@@ -5417,10 +5417,12 @@ const reCalculateChannelUnreadInfo = async (channelId) => {
|
|
|
5417
5417
|
.reduce((acc, cur) => acc + cur, 0);
|
|
5418
5418
|
isMentioned = subChannelUnreadsInfo.some(({ data }) => data.isMentioned);
|
|
5419
5419
|
}
|
|
5420
|
-
|
|
5420
|
+
const channelUnreadInfo = Object.assign(Object.assign({}, (cacheChannelUnreadInfo !== null && cacheChannelUnreadInfo !== void 0 ? cacheChannelUnreadInfo : {
|
|
5421
5421
|
channelId,
|
|
5422
5422
|
createdAt: new Date().toISOString(),
|
|
5423
|
-
})), { updatedAt: new Date().toISOString(), unreadCount: channelUnreads, isMentioned })
|
|
5423
|
+
})), { updatedAt: new Date().toISOString(), unreadCount: channelUnreads, isMentioned });
|
|
5424
|
+
pushToCache(cacheKeyChannelUnread, channelUnreadInfo);
|
|
5425
|
+
return channelUnreadInfo;
|
|
5424
5426
|
};
|
|
5425
5427
|
|
|
5426
5428
|
class MessageReadReceiptSyncEngine {
|
|
@@ -5565,9 +5567,11 @@ class MessageReadReceiptSyncEngine {
|
|
|
5565
5567
|
if (subChannelUnreadInfo && segment > subChannelUnreadInfo.readToSegment) {
|
|
5566
5568
|
subChannelUnreadInfo.readToSegment = segment;
|
|
5567
5569
|
subChannelUnreadInfo.unreadCount = Math.max(subChannelUnreadInfo.lastSegment - segment, 0);
|
|
5568
|
-
reCalculateChannelUnreadInfo(subChannelUnreadInfo.channelId);
|
|
5570
|
+
const channelUnreadInfo = reCalculateChannelUnreadInfo(subChannelUnreadInfo.channelId);
|
|
5571
|
+
fireEvent('local.channelUnread.updated', channelUnreadInfo);
|
|
5572
|
+
pushToCache(cacheKey, subChannelUnreadInfo);
|
|
5573
|
+
fireEvent('local.subChannelUnread.updated', subChannelUnreadInfo);
|
|
5569
5574
|
}
|
|
5570
|
-
pushToCache(cacheKey, subChannelUnreadInfo);
|
|
5571
5575
|
// Step 2: Enqueue the read receipt
|
|
5572
5576
|
this.enqueueReadReceipt(subChannelId, segment);
|
|
5573
5577
|
}
|
|
@@ -8532,9 +8536,9 @@ const enableUnreadCount = () => {
|
|
|
8532
8536
|
const onUserFeedMarkerUpdated = (callback) => {
|
|
8533
8537
|
const client = getActiveClient();
|
|
8534
8538
|
const filter = (payload) => {
|
|
8535
|
-
|
|
8536
|
-
|
|
8537
|
-
|
|
8539
|
+
payload.feedMarkers.forEach(feedMarker => {
|
|
8540
|
+
callback(feedMarker);
|
|
8541
|
+
});
|
|
8538
8542
|
};
|
|
8539
8543
|
return createEventSubscriber(client, 'feedMarker/onUserFeedMarkerUpdated', 'marker.userFeed-updated', filter);
|
|
8540
8544
|
};
|
|
@@ -9130,7 +9134,7 @@ const onChannelMarkerFetched = (callback) => {
|
|
|
9130
9134
|
const onSubChannelMarkerFetched = (callback) => {
|
|
9131
9135
|
const client = getActiveClient();
|
|
9132
9136
|
const filter = (payload) => {
|
|
9133
|
-
|
|
9137
|
+
payload.userFeedMarkers.forEach(callback);
|
|
9134
9138
|
};
|
|
9135
9139
|
return createEventSubscriber(client, 'subChannelMarker/onSubChannelMarkerFetched', 'local.subChannelMarker.fetched', filter);
|
|
9136
9140
|
};
|
|
@@ -9400,6 +9404,9 @@ function isEqual(x, y) {
|
|
|
9400
9404
|
}));
|
|
9401
9405
|
}
|
|
9402
9406
|
|
|
9407
|
+
/**
|
|
9408
|
+
* @deprecated This function is deprecated
|
|
9409
|
+
*/
|
|
9403
9410
|
const liveObject = (id, callback, key, fetcher, eventHandlers, options) => {
|
|
9404
9411
|
const { forceDispatch, callbackDataSelector, callbackFilter } = Object.assign({ forceDispatch: false, callbackDataSelector: (data) => data }, options);
|
|
9405
9412
|
const { cache } = getActiveClient();
|
|
@@ -15385,7 +15392,7 @@ class LiveCollectionController {
|
|
|
15385
15392
|
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
15386
15393
|
}
|
|
15387
15394
|
}
|
|
15388
|
-
loadPage(initial = false, direction = "next" /* Amity.LiveCollectionPageDirection.NEXT
|
|
15395
|
+
loadPage({ initial = false, direction = "next" /* Amity.LiveCollectionPageDirection.NEXT */, }) {
|
|
15389
15396
|
this.setup();
|
|
15390
15397
|
this.notifyChange({ origin: "local" /* Amity.LiveDataOrigin.LOCAL */, loading: true });
|
|
15391
15398
|
if (initial) {
|
|
@@ -15455,7 +15462,7 @@ class MessageLiveCollectionController extends LiveCollectionController {
|
|
|
15455
15462
|
this.query = query;
|
|
15456
15463
|
this.queryStreamController = new MessageQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareMessagePayload, this.paginationController);
|
|
15457
15464
|
this.callback = callback.bind(this);
|
|
15458
|
-
this.loadPage(true);
|
|
15465
|
+
this.loadPage({ initial: true });
|
|
15459
15466
|
}
|
|
15460
15467
|
setup() {
|
|
15461
15468
|
var _a;
|
|
@@ -15503,8 +15510,8 @@ class MessageLiveCollectionController extends LiveCollectionController {
|
|
|
15503
15510
|
if (!this.shouldNotify(data) && origin === 'event')
|
|
15504
15511
|
return;
|
|
15505
15512
|
this.callback({
|
|
15506
|
-
onNextPage: () => this.loadPage(
|
|
15507
|
-
onPrevPage: () => this.loadPage(
|
|
15513
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
15514
|
+
onPrevPage: () => this.loadPage({ direction: "prev" /* Amity.LiveCollectionPageDirection.PREV */ }),
|
|
15508
15515
|
data,
|
|
15509
15516
|
hasNextPage: !!this.paginationController.getNextToken(),
|
|
15510
15517
|
hasPrevPage: !!this.paginationController.getPrevToken(),
|
|
@@ -15786,6 +15793,24 @@ var index$f = /*#__PURE__*/Object.freeze({
|
|
|
15786
15793
|
convertQueryParams: convertQueryParams$1
|
|
15787
15794
|
});
|
|
15788
15795
|
|
|
15796
|
+
/**
|
|
15797
|
+
* Internal used only
|
|
15798
|
+
*
|
|
15799
|
+
* Fired when an {@link Amity.userMessageFeedMarkers} has been resolved by Object Rsesolver
|
|
15800
|
+
*
|
|
15801
|
+
* @param callback The function to call when the event was fired
|
|
15802
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
15803
|
+
*
|
|
15804
|
+
* @category MessageMarker Events
|
|
15805
|
+
*/
|
|
15806
|
+
const onSubChannelUnreadUpdatedLocal = (callback) => {
|
|
15807
|
+
const client = getActiveClient();
|
|
15808
|
+
const filter = (payload) => {
|
|
15809
|
+
callback(payload);
|
|
15810
|
+
};
|
|
15811
|
+
return createEventSubscriber(client, 'subChannelMarker/onSubChannelUnreadUpdatedLocal', 'local.subChannelUnread.updated', filter);
|
|
15812
|
+
};
|
|
15813
|
+
|
|
15789
15814
|
/* begin_public_function
|
|
15790
15815
|
id: subchannel.get
|
|
15791
15816
|
*/
|
|
@@ -15938,7 +15963,7 @@ const getSubChannel = (subChannelId, callback) => {
|
|
|
15938
15963
|
};
|
|
15939
15964
|
return onMessageDeleted(updateMessagePreview);
|
|
15940
15965
|
}, 'subChannelId', 'subChannel'),
|
|
15941
|
-
convertEventPayload(
|
|
15966
|
+
convertEventPayload(onSubChannelUnreadUpdatedLocal, 'subChannelId', 'subChannel'),
|
|
15942
15967
|
], {
|
|
15943
15968
|
forceDispatch: true,
|
|
15944
15969
|
});
|
|
@@ -16028,7 +16053,7 @@ class SubChannelLiveCollectionController extends LiveCollectionController {
|
|
|
16028
16053
|
this.query = query;
|
|
16029
16054
|
this.queryStreamController = new SubChannelQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareSubChannelPayload);
|
|
16030
16055
|
this.callback = callback.bind(this);
|
|
16031
|
-
this.loadPage(true);
|
|
16056
|
+
this.loadPage({ initial: true });
|
|
16032
16057
|
}
|
|
16033
16058
|
setup() {
|
|
16034
16059
|
var _a;
|
|
@@ -16205,7 +16230,7 @@ class SubChannelLiveCollectionController extends LiveCollectionController {
|
|
|
16205
16230
|
action: 'onUpdate',
|
|
16206
16231
|
},
|
|
16207
16232
|
{
|
|
16208
|
-
fn: convertEventPayload(
|
|
16233
|
+
fn: convertEventPayload(onSubChannelUnreadUpdatedLocal, 'subChannelId', 'subChannel'),
|
|
16209
16234
|
action: 'onUpdate',
|
|
16210
16235
|
},
|
|
16211
16236
|
]);
|
|
@@ -16223,7 +16248,7 @@ class SubChannelLiveCollectionController extends LiveCollectionController {
|
|
|
16223
16248
|
if (!this.shouldNotify(data) && origin === 'event')
|
|
16224
16249
|
return;
|
|
16225
16250
|
this.callback({
|
|
16226
|
-
onNextPage: () => this.loadPage(
|
|
16251
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
16227
16252
|
data,
|
|
16228
16253
|
hasNextPage: !!this.paginationController.getNextToken(),
|
|
16229
16254
|
loading,
|
|
@@ -16363,6 +16388,24 @@ var index$e = /*#__PURE__*/Object.freeze({
|
|
|
16363
16388
|
stopMessageReceiptSync: stopMessageReceiptSync
|
|
16364
16389
|
});
|
|
16365
16390
|
|
|
16391
|
+
/**
|
|
16392
|
+
* Internal used only
|
|
16393
|
+
*
|
|
16394
|
+
* Fired when an {@link Amity.userMessageFeedMarkers} has been resolved by Object Rsesolver
|
|
16395
|
+
*
|
|
16396
|
+
* @param callback The function to call when the event was fired
|
|
16397
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
16398
|
+
*
|
|
16399
|
+
* @category MessageMarker Events
|
|
16400
|
+
*/
|
|
16401
|
+
const onChannelUnreadUpdatedLocal = (callback) => {
|
|
16402
|
+
const client = getActiveClient();
|
|
16403
|
+
const filter = (payload) => {
|
|
16404
|
+
callback(payload);
|
|
16405
|
+
};
|
|
16406
|
+
return createEventSubscriber(client, 'channelMarker/onChannelUnreadUpdatedLocal', 'local.channelUnread.updated', filter);
|
|
16407
|
+
};
|
|
16408
|
+
|
|
16366
16409
|
/* begin_public_function
|
|
16367
16410
|
id: channel.get
|
|
16368
16411
|
*/
|
|
@@ -16538,7 +16581,7 @@ const getChannel = (channelId, callback) => {
|
|
|
16538
16581
|
return onSubChannelUpdated(updateMessagePreview);
|
|
16539
16582
|
}, 'channelId', 'channel'),
|
|
16540
16583
|
convertEventPayload(onSubChannelCreated, 'channelId', 'channel'),
|
|
16541
|
-
convertEventPayload(
|
|
16584
|
+
convertEventPayload(onChannelUnreadUpdatedLocal, 'channelId', 'channel'),
|
|
16542
16585
|
], {
|
|
16543
16586
|
forceDispatch: true,
|
|
16544
16587
|
});
|
|
@@ -16698,7 +16741,7 @@ class ChannelLiveCollectionController extends LiveCollectionController {
|
|
|
16698
16741
|
}, paginationController);
|
|
16699
16742
|
this.paginationController = paginationController;
|
|
16700
16743
|
this.callback = callback.bind(this);
|
|
16701
|
-
this.loadPage(true);
|
|
16744
|
+
this.loadPage({ initial: true });
|
|
16702
16745
|
}
|
|
16703
16746
|
setup() {
|
|
16704
16747
|
var _a;
|
|
@@ -16737,7 +16780,7 @@ class ChannelLiveCollectionController extends LiveCollectionController {
|
|
|
16737
16780
|
return;
|
|
16738
16781
|
this.callback({
|
|
16739
16782
|
onNextPage: this.paginationController instanceof ChannelPaginationController
|
|
16740
|
-
? () => this.loadPage(
|
|
16783
|
+
? () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ })
|
|
16741
16784
|
: undefined,
|
|
16742
16785
|
data,
|
|
16743
16786
|
hasNextPage: this.paginationController instanceof ChannelPaginationController
|
|
@@ -17017,10 +17060,6 @@ class ChannelLiveCollectionController extends LiveCollectionController {
|
|
|
17017
17060
|
}, 'channelId', 'channel'),
|
|
17018
17061
|
action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
|
|
17019
17062
|
},
|
|
17020
|
-
{
|
|
17021
|
-
fn: convertEventPayload(onUserFeedMarkerUpdated, 'entityId', 'channel'),
|
|
17022
|
-
action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
|
|
17023
|
-
},
|
|
17024
17063
|
{
|
|
17025
17064
|
fn: convertEventPayload(onSubChannelCreated, 'channelId', 'channel'),
|
|
17026
17065
|
action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
|
|
@@ -17046,6 +17085,10 @@ class ChannelLiveCollectionController extends LiveCollectionController {
|
|
|
17046
17085
|
},
|
|
17047
17086
|
action: "onResolve" /* Amity.ChannelActionType.OnResolve */,
|
|
17048
17087
|
},
|
|
17088
|
+
{
|
|
17089
|
+
fn: convertEventPayload(onChannelUnreadUpdatedLocal, 'channelId', 'channel'),
|
|
17090
|
+
action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
|
|
17091
|
+
},
|
|
17049
17092
|
];
|
|
17050
17093
|
if (this.paginationController instanceof PaginationController) {
|
|
17051
17094
|
return [
|
|
@@ -17260,7 +17303,7 @@ class ChannelMemberLiveCollectionController extends LiveCollectionController {
|
|
|
17260
17303
|
this.query = query;
|
|
17261
17304
|
this.queryStreamController = new ChannelMemberQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareChannelPayload);
|
|
17262
17305
|
this.callback = callback.bind(this);
|
|
17263
|
-
this.loadPage(true);
|
|
17306
|
+
this.loadPage({ initial: true });
|
|
17264
17307
|
}
|
|
17265
17308
|
setup() {
|
|
17266
17309
|
var _a;
|
|
@@ -17302,7 +17345,7 @@ class ChannelMemberLiveCollectionController extends LiveCollectionController {
|
|
|
17302
17345
|
if (!this.shouldNotify(data) && origin === 'event')
|
|
17303
17346
|
return;
|
|
17304
17347
|
this.callback({
|
|
17305
|
-
onNextPage: () => this.loadPage(
|
|
17348
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
17306
17349
|
data,
|
|
17307
17350
|
hasNextPage: !!this.paginationController.getNextToken(),
|
|
17308
17351
|
loading,
|
|
@@ -18411,50 +18454,140 @@ const observeCommunity = (communityId, callback) => {
|
|
|
18411
18454
|
};
|
|
18412
18455
|
|
|
18413
18456
|
/**
|
|
18414
|
-
*
|
|
18415
|
-
*
|
|
18416
|
-
* const communities = await queryCommunities()
|
|
18417
|
-
* ```
|
|
18418
|
-
*
|
|
18419
|
-
* Queries a paginable list of {@link Amity.Community} objects
|
|
18420
|
-
* Search is performed by displayName such as `.startsWith(search)`
|
|
18421
|
-
*
|
|
18422
|
-
* @param query The query parameters
|
|
18423
|
-
* @returns A page of {@link Amity.Community} objects
|
|
18424
|
-
*
|
|
18425
|
-
* @category Community API
|
|
18426
|
-
* @async
|
|
18457
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
18458
|
+
* TODO: check if querybyIds is supported
|
|
18427
18459
|
*/
|
|
18428
|
-
|
|
18429
|
-
|
|
18430
|
-
|
|
18431
|
-
|
|
18432
|
-
|
|
18433
|
-
|
|
18434
|
-
|
|
18435
|
-
|
|
18436
|
-
return { token: page };
|
|
18437
|
-
if (limit)
|
|
18438
|
-
return { limit };
|
|
18439
|
-
return undefined;
|
|
18440
|
-
})();
|
|
18441
|
-
// API-FIX: parameters should be querystring.
|
|
18442
|
-
// API-FIX: backend doesn't answer Amity.Response
|
|
18443
|
-
// const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<CommunityPayload>>>(
|
|
18444
|
-
const { data } = await client.http.get(`/api/v3/communities`, {
|
|
18445
|
-
params: Object.assign(Object.assign({}, restParams), { isDeleted: inferIsDeleted(includeDeleted), keyword: displayName, filter: membership, options }),
|
|
18446
|
-
});
|
|
18447
|
-
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
18448
|
-
const unpackedPayload = prepareCommunityPayload(payload);
|
|
18449
|
-
const { communities } = unpackedPayload;
|
|
18450
|
-
const cachedAt = client.cache && Date.now();
|
|
18451
|
-
if (client.cache) {
|
|
18452
|
-
ingestInCache(unpackedPayload, { cachedAt });
|
|
18453
|
-
const cacheKey = ['community', 'query', Object.assign(Object.assign({}, params), { options })];
|
|
18454
|
-
pushToCache(cacheKey, { communities: communities.map(getResolver('community')), paging });
|
|
18460
|
+
class CommunitiesPaginationController$1 extends PaginationController {
|
|
18461
|
+
async getRequest(queryParams, token) {
|
|
18462
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
18463
|
+
const options = token ? { token } : { limit };
|
|
18464
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/communities`, {
|
|
18465
|
+
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(params.includeDeleted), keyword: params.displayName, filter: params.membership, options }),
|
|
18466
|
+
});
|
|
18467
|
+
return queryResponse;
|
|
18455
18468
|
}
|
|
18456
|
-
|
|
18457
|
-
|
|
18469
|
+
}
|
|
18470
|
+
|
|
18471
|
+
class CommunitiesQueryStreamController$1 extends QueryStreamController {
|
|
18472
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
18473
|
+
super(query, cacheKey);
|
|
18474
|
+
this.notifyChange = notifyChange;
|
|
18475
|
+
this.preparePayload = preparePayload;
|
|
18476
|
+
}
|
|
18477
|
+
async saveToMainDB(response) {
|
|
18478
|
+
const processedPayload = await this.preparePayload(response);
|
|
18479
|
+
const client = getActiveClient();
|
|
18480
|
+
const cachedAt = client.cache && Date.now();
|
|
18481
|
+
if (client.cache) {
|
|
18482
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
18483
|
+
}
|
|
18484
|
+
}
|
|
18485
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
18486
|
+
var _a, _b;
|
|
18487
|
+
if (refresh) {
|
|
18488
|
+
pushToCache(this.cacheKey, {
|
|
18489
|
+
data: response.communities.map(getResolver('community')),
|
|
18490
|
+
});
|
|
18491
|
+
}
|
|
18492
|
+
else {
|
|
18493
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
18494
|
+
const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
18495
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...communities, ...response.communities.map(getResolver('community'))])] }));
|
|
18496
|
+
}
|
|
18497
|
+
}
|
|
18498
|
+
reactor(action) {
|
|
18499
|
+
return (community) => {
|
|
18500
|
+
var _a;
|
|
18501
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
18502
|
+
if (!collection)
|
|
18503
|
+
return;
|
|
18504
|
+
pushToCache(this.cacheKey, collection);
|
|
18505
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
18506
|
+
};
|
|
18507
|
+
}
|
|
18508
|
+
subscribeRTE(createSubscriber) {
|
|
18509
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
18510
|
+
}
|
|
18511
|
+
}
|
|
18512
|
+
|
|
18513
|
+
var EnumCommunityActions$1;
|
|
18514
|
+
(function (EnumCommunityActions) {
|
|
18515
|
+
EnumCommunityActions["OnCommunityCreated"] = "onCommunityCreated";
|
|
18516
|
+
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
18517
|
+
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
18518
|
+
})(EnumCommunityActions$1 || (EnumCommunityActions$1 = {}));
|
|
18519
|
+
|
|
18520
|
+
/* eslint-disable no-use-before-define */
|
|
18521
|
+
class SearchCommunityLiveCollectionController extends LiveCollectionController {
|
|
18522
|
+
constructor(query, callback) {
|
|
18523
|
+
const queryStreamId = hash__default["default"](query);
|
|
18524
|
+
const cacheKey = ['community', 'collection', queryStreamId];
|
|
18525
|
+
const paginationController = new CommunitiesPaginationController$1(query);
|
|
18526
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
18527
|
+
this.query = query;
|
|
18528
|
+
this.queryStreamController = new CommunitiesQueryStreamController$1(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityPayload);
|
|
18529
|
+
this.callback = callback.bind(this);
|
|
18530
|
+
this.loadPage({ initial: true });
|
|
18531
|
+
}
|
|
18532
|
+
setup() {
|
|
18533
|
+
var _a;
|
|
18534
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
18535
|
+
if (!collection) {
|
|
18536
|
+
pushToCache(this.cacheKey, {
|
|
18537
|
+
data: [],
|
|
18538
|
+
params: {},
|
|
18539
|
+
});
|
|
18540
|
+
}
|
|
18541
|
+
}
|
|
18542
|
+
async persistModel(queryPayload) {
|
|
18543
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
18544
|
+
}
|
|
18545
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
18546
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
18547
|
+
}
|
|
18548
|
+
startSubscription() {
|
|
18549
|
+
return this.queryStreamController.subscribeRTE([
|
|
18550
|
+
{ fn: onCommunityDeleted, action: EnumCommunityActions$1.OnCommunityDeleted },
|
|
18551
|
+
{ fn: onCommunityUpdated, action: EnumCommunityActions$1.OnCommunityUpdated },
|
|
18552
|
+
]);
|
|
18553
|
+
}
|
|
18554
|
+
notifyChange({ origin, loading, error }) {
|
|
18555
|
+
var _a, _b;
|
|
18556
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
18557
|
+
if (!collection)
|
|
18558
|
+
return;
|
|
18559
|
+
const data = this.applyFilter((_b = collection.data
|
|
18560
|
+
.map(id => pullFromCache(['community', 'get', id]))
|
|
18561
|
+
.filter(Boolean)
|
|
18562
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
|
|
18563
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
18564
|
+
return;
|
|
18565
|
+
this.callback({
|
|
18566
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
18567
|
+
data,
|
|
18568
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
18569
|
+
loading,
|
|
18570
|
+
error,
|
|
18571
|
+
});
|
|
18572
|
+
}
|
|
18573
|
+
applyFilter(data) {
|
|
18574
|
+
const { userId } = getActiveClient();
|
|
18575
|
+
let communities = data;
|
|
18576
|
+
if (this.query.includeDeleted) {
|
|
18577
|
+
communities = filterByPropEquality(communities, 'isDeleted', false);
|
|
18578
|
+
}
|
|
18579
|
+
if (this.query.categoryId) {
|
|
18580
|
+
communities = communities.filter(c => { var _a; return (_a = c.categoryIds) === null || _a === void 0 ? void 0 : _a.includes(this.query.categoryId); });
|
|
18581
|
+
}
|
|
18582
|
+
if (this.query.tags) {
|
|
18583
|
+
communities = communities.filter(c => { var _a; return (_a = c.tags) === null || _a === void 0 ? void 0 : _a.some(t => { var _a; return (_a = this.query.tags) === null || _a === void 0 ? void 0 : _a.includes(t); }); });
|
|
18584
|
+
}
|
|
18585
|
+
if (this.query.membership && userId) {
|
|
18586
|
+
communities = filterByCommunityMembership(communities, this.query.membership, userId);
|
|
18587
|
+
}
|
|
18588
|
+
return communities;
|
|
18589
|
+
}
|
|
18590
|
+
}
|
|
18458
18591
|
|
|
18459
18592
|
/* begin_public_function
|
|
18460
18593
|
id: community.query
|
|
@@ -18464,7 +18597,7 @@ const queryCommunities = async (query) => {
|
|
|
18464
18597
|
* import { CommunityRepository } from '@amityco/ts-sdk'
|
|
18465
18598
|
*
|
|
18466
18599
|
* let communities = []
|
|
18467
|
-
* const unsub = CommunityRepository.
|
|
18600
|
+
* const unsub = CommunityRepository.searchCommunities({
|
|
18468
18601
|
* displayName: Amity.Community['displayName'],
|
|
18469
18602
|
* }, response => merge(communities, response.data))
|
|
18470
18603
|
* ```
|
|
@@ -18477,127 +18610,242 @@ const queryCommunities = async (query) => {
|
|
|
18477
18610
|
*
|
|
18478
18611
|
* @category Community Live Collection
|
|
18479
18612
|
*/
|
|
18480
|
-
const
|
|
18481
|
-
const { log, cache
|
|
18613
|
+
const searchCommunities = (params, callback, config) => {
|
|
18614
|
+
const { log, cache } = getActiveClient();
|
|
18482
18615
|
if (!cache) {
|
|
18483
18616
|
console.log(ENABLE_CACHE_MESSAGE);
|
|
18484
18617
|
}
|
|
18485
18618
|
const timestamp = Date.now();
|
|
18486
|
-
log(`
|
|
18487
|
-
const
|
|
18488
|
-
const
|
|
18489
|
-
const
|
|
18490
|
-
const disposers = [];
|
|
18491
|
-
const cacheKey = ['community', 'collection', queryParams];
|
|
18492
|
-
const responder = (data) => {
|
|
18493
|
-
var _a, _b;
|
|
18494
|
-
let communities = (_a = data.data
|
|
18495
|
-
.map(communityId => pullFromCache(['community', 'get', communityId]))
|
|
18496
|
-
.filter(Boolean)
|
|
18497
|
-
.map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
|
|
18498
|
-
communities = filterByStringComparePartially(communities, 'displayName', params.displayName);
|
|
18499
|
-
if (!params.includeDeleted) {
|
|
18500
|
-
communities = filterByPropEquality(communities, 'isDeleted', false);
|
|
18501
|
-
}
|
|
18502
|
-
if (params.categoryId) {
|
|
18503
|
-
communities = communities.filter(c => { var _a; return (_a = c.categoryIds) === null || _a === void 0 ? void 0 : _a.includes(params.categoryId); });
|
|
18504
|
-
}
|
|
18505
|
-
if (params.tags) {
|
|
18506
|
-
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); }); });
|
|
18507
|
-
}
|
|
18508
|
-
if (params.membership && userId) {
|
|
18509
|
-
communities = filterByCommunityMembership(communities, params.membership, userId);
|
|
18510
|
-
}
|
|
18511
|
-
const sortBy = params.sortBy || 'lastCreated';
|
|
18512
|
-
if (sortBy === 'lastCreated' || sortBy === 'firstCreated') {
|
|
18513
|
-
communities = communities.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
18514
|
-
}
|
|
18515
|
-
/*
|
|
18516
|
-
* The server returns communities with empty | null displayName's first before
|
|
18517
|
-
* returning sorted list of communities with displayNames
|
|
18518
|
-
*
|
|
18519
|
-
* This section needs to be updated as displayNames can be null as well
|
|
18520
|
-
*/
|
|
18521
|
-
if (sortBy === 'displayName') {
|
|
18522
|
-
communities = communities
|
|
18523
|
-
// this needs to be aligned with the backend data type
|
|
18524
|
-
.map(c => (c.displayName ? c : Object.assign(Object.assign({}, c), { displayName: '' })))
|
|
18525
|
-
// @ts-ignore
|
|
18526
|
-
.sort(sortByDisplayName);
|
|
18527
|
-
}
|
|
18528
|
-
callback({
|
|
18529
|
-
onNextPage: onFetch,
|
|
18530
|
-
data: communities,
|
|
18531
|
-
hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
|
|
18532
|
-
loading: data.loading,
|
|
18533
|
-
error: data.error,
|
|
18534
|
-
});
|
|
18535
|
-
};
|
|
18536
|
-
const realtimeRouter = (_) => (community) => {
|
|
18537
|
-
var _a;
|
|
18538
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
18539
|
-
if (!collection)
|
|
18540
|
-
return;
|
|
18541
|
-
/*
|
|
18542
|
-
* Simply update collection and let responder decide what to do with data
|
|
18543
|
-
*/
|
|
18544
|
-
collection.data = [...new Set([community.communityId, ...collection.data])];
|
|
18545
|
-
pushToCache(cacheKey, collection);
|
|
18546
|
-
responder(collection);
|
|
18547
|
-
};
|
|
18548
|
-
const onFetch = (initial = false) => {
|
|
18549
|
-
var _a, _b;
|
|
18550
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
18551
|
-
const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
18552
|
-
if (!initial && communities.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
|
|
18553
|
-
return;
|
|
18554
|
-
const query = createQuery(queryCommunities, Object.assign(Object.assign({}, queryParams), { limit: initial ? limit : undefined, page: !initial ? collection === null || collection === void 0 ? void 0 : collection.params.page : undefined }));
|
|
18555
|
-
runQuery(query, ({ data: result, error, loading, paging }) => {
|
|
18556
|
-
const data = {
|
|
18557
|
-
loading,
|
|
18558
|
-
error,
|
|
18559
|
-
params: { page: paging === null || paging === void 0 ? void 0 : paging.next },
|
|
18560
|
-
data: communities,
|
|
18561
|
-
};
|
|
18562
|
-
if (result) {
|
|
18563
|
-
data.data = initial
|
|
18564
|
-
? result.map(getResolver('community'))
|
|
18565
|
-
: [...new Set([...communities, ...result.map(getResolver('community'))])];
|
|
18566
|
-
}
|
|
18567
|
-
pushToCache(cacheKey, data);
|
|
18568
|
-
responder(data);
|
|
18569
|
-
}, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
|
|
18570
|
-
};
|
|
18571
|
-
disposers.push(onCommunityCreated(realtimeRouter()), onCommunityDeleted(realtimeRouter()), onCommunityUpdated(realtimeRouter()), onCommunityJoined(realtimeRouter()), onCommunityLeft(realtimeRouter()), onCommunityUserChanged(realtimeRouter()));
|
|
18572
|
-
onFetch(true);
|
|
18619
|
+
log(`searchCommunities(tmpid: ${timestamp}) > listen`);
|
|
18620
|
+
const searchCommunitiesLiveCollection = new SearchCommunityLiveCollectionController(params, callback);
|
|
18621
|
+
const disposers = searchCommunitiesLiveCollection.startSubscription();
|
|
18622
|
+
const cacheKey = searchCommunitiesLiveCollection.getCacheKey();
|
|
18573
18623
|
disposers.push(() => dropFromCache(cacheKey));
|
|
18574
18624
|
return () => {
|
|
18575
|
-
log(`
|
|
18625
|
+
log(`searchCommunities(tmpid: ${timestamp}) > dispose`);
|
|
18576
18626
|
disposers.forEach(fn => fn());
|
|
18577
18627
|
};
|
|
18578
18628
|
};
|
|
18579
18629
|
/* end_public_function */
|
|
18580
18630
|
|
|
18581
|
-
/* begin_public_function
|
|
18582
|
-
id: community.get
|
|
18583
|
-
*/
|
|
18584
18631
|
/**
|
|
18585
|
-
*
|
|
18586
|
-
*
|
|
18587
|
-
|
|
18588
|
-
|
|
18589
|
-
|
|
18590
|
-
|
|
18591
|
-
|
|
18592
|
-
|
|
18593
|
-
|
|
18594
|
-
|
|
18595
|
-
|
|
18596
|
-
|
|
18597
|
-
|
|
18598
|
-
|
|
18599
|
-
|
|
18600
|
-
|
|
18632
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
18633
|
+
* TODO: check if querybyIds is supported
|
|
18634
|
+
*/
|
|
18635
|
+
class CommunitiesPaginationController extends PaginationController {
|
|
18636
|
+
async getRequest(queryParams, token) {
|
|
18637
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
18638
|
+
const options = token ? { token } : { limit };
|
|
18639
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/communities`, {
|
|
18640
|
+
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(params.includeDeleted), keyword: params.displayName, filter: params.membership, options }),
|
|
18641
|
+
});
|
|
18642
|
+
return queryResponse;
|
|
18643
|
+
}
|
|
18644
|
+
}
|
|
18645
|
+
|
|
18646
|
+
var EnumCommunityActions;
|
|
18647
|
+
(function (EnumCommunityActions) {
|
|
18648
|
+
EnumCommunityActions["OnCommunityCreated"] = "onCommunityCreated";
|
|
18649
|
+
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
18650
|
+
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
18651
|
+
})(EnumCommunityActions || (EnumCommunityActions = {}));
|
|
18652
|
+
|
|
18653
|
+
class CommunitiesQueryStreamController extends QueryStreamController {
|
|
18654
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
18655
|
+
super(query, cacheKey);
|
|
18656
|
+
this.notifyChange = notifyChange;
|
|
18657
|
+
this.preparePayload = preparePayload;
|
|
18658
|
+
}
|
|
18659
|
+
async saveToMainDB(response) {
|
|
18660
|
+
const processedPayload = await this.preparePayload(response);
|
|
18661
|
+
const client = getActiveClient();
|
|
18662
|
+
const cachedAt = client.cache && Date.now();
|
|
18663
|
+
if (client.cache) {
|
|
18664
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
18665
|
+
}
|
|
18666
|
+
}
|
|
18667
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
18668
|
+
var _a, _b;
|
|
18669
|
+
if (refresh) {
|
|
18670
|
+
pushToCache(this.cacheKey, {
|
|
18671
|
+
data: response.communities.map(getResolver('community')),
|
|
18672
|
+
});
|
|
18673
|
+
}
|
|
18674
|
+
else {
|
|
18675
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
18676
|
+
const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
18677
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...communities, ...response.communities.map(getResolver('community'))])] }));
|
|
18678
|
+
}
|
|
18679
|
+
}
|
|
18680
|
+
reactor(action) {
|
|
18681
|
+
return (community) => {
|
|
18682
|
+
var _a;
|
|
18683
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
18684
|
+
if (!collection)
|
|
18685
|
+
return;
|
|
18686
|
+
if (this.query.displayName && action === EnumCommunityActions.OnCommunityCreated) {
|
|
18687
|
+
return;
|
|
18688
|
+
}
|
|
18689
|
+
/*
|
|
18690
|
+
* Simply update collection and let responder decide what to do with data
|
|
18691
|
+
*/
|
|
18692
|
+
collection.data = [...new Set([community.communityId, ...collection.data])];
|
|
18693
|
+
pushToCache(this.cacheKey, collection);
|
|
18694
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
18695
|
+
};
|
|
18696
|
+
}
|
|
18697
|
+
subscribeRTE(createSubscriber) {
|
|
18698
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
18699
|
+
}
|
|
18700
|
+
}
|
|
18701
|
+
|
|
18702
|
+
/* eslint-disable no-use-before-define */
|
|
18703
|
+
class CommunityLiveCollectionController extends LiveCollectionController {
|
|
18704
|
+
constructor(query, callback) {
|
|
18705
|
+
const queryStreamId = hash__default["default"](query);
|
|
18706
|
+
const cacheKey = ['community', 'collection', queryStreamId];
|
|
18707
|
+
const paginationController = new CommunitiesPaginationController(query);
|
|
18708
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
18709
|
+
this.query = query;
|
|
18710
|
+
this.queryStreamController = new CommunitiesQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityPayload);
|
|
18711
|
+
this.callback = callback.bind(this);
|
|
18712
|
+
this.loadPage({ initial: true });
|
|
18713
|
+
}
|
|
18714
|
+
setup() {
|
|
18715
|
+
var _a;
|
|
18716
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
18717
|
+
if (!collection) {
|
|
18718
|
+
pushToCache(this.cacheKey, {
|
|
18719
|
+
data: [],
|
|
18720
|
+
params: {},
|
|
18721
|
+
});
|
|
18722
|
+
}
|
|
18723
|
+
}
|
|
18724
|
+
async persistModel(queryPayload) {
|
|
18725
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
18726
|
+
}
|
|
18727
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
18728
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
18729
|
+
}
|
|
18730
|
+
startSubscription() {
|
|
18731
|
+
return this.queryStreamController.subscribeRTE([
|
|
18732
|
+
{ fn: onCommunityCreated, action: EnumCommunityActions.OnCommunityCreated },
|
|
18733
|
+
{ fn: onCommunityDeleted, action: EnumCommunityActions.OnCommunityDeleted },
|
|
18734
|
+
{ fn: onCommunityUpdated, action: EnumCommunityActions.OnCommunityUpdated },
|
|
18735
|
+
]);
|
|
18736
|
+
}
|
|
18737
|
+
notifyChange({ origin, loading, error }) {
|
|
18738
|
+
var _a, _b;
|
|
18739
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
18740
|
+
if (!collection)
|
|
18741
|
+
return;
|
|
18742
|
+
const data = this.applyFilter((_b = collection.data
|
|
18743
|
+
.map(id => pullFromCache(['community', 'get', id]))
|
|
18744
|
+
.filter(Boolean)
|
|
18745
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
|
|
18746
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
18747
|
+
return;
|
|
18748
|
+
this.callback({
|
|
18749
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
18750
|
+
data,
|
|
18751
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
18752
|
+
loading,
|
|
18753
|
+
error,
|
|
18754
|
+
});
|
|
18755
|
+
}
|
|
18756
|
+
applyFilter(data) {
|
|
18757
|
+
const { userId } = getActiveClient();
|
|
18758
|
+
let communities = data;
|
|
18759
|
+
if (this.query.includeDeleted) {
|
|
18760
|
+
communities = filterByPropEquality(communities, 'isDeleted', false);
|
|
18761
|
+
}
|
|
18762
|
+
if (this.query.categoryId) {
|
|
18763
|
+
communities = communities.filter(c => { var _a; return (_a = c.categoryIds) === null || _a === void 0 ? void 0 : _a.includes(this.query.categoryId); });
|
|
18764
|
+
}
|
|
18765
|
+
if (this.query.tags) {
|
|
18766
|
+
communities = communities.filter(c => { var _a; return (_a = c.tags) === null || _a === void 0 ? void 0 : _a.some(t => { var _a; return (_a = this.query.tags) === null || _a === void 0 ? void 0 : _a.includes(t); }); });
|
|
18767
|
+
}
|
|
18768
|
+
if (this.query.membership && userId) {
|
|
18769
|
+
communities = filterByCommunityMembership(communities, this.query.membership, userId);
|
|
18770
|
+
}
|
|
18771
|
+
if (!this.query.displayName) {
|
|
18772
|
+
const sortFn = (() => {
|
|
18773
|
+
switch (this.query.sortBy) {
|
|
18774
|
+
case 'firstCreated':
|
|
18775
|
+
return sortByFirstCreated;
|
|
18776
|
+
case 'lastCreated':
|
|
18777
|
+
return sortByLastCreated;
|
|
18778
|
+
case 'displayName':
|
|
18779
|
+
return sortByDisplayName;
|
|
18780
|
+
default:
|
|
18781
|
+
return sortByLastCreated;
|
|
18782
|
+
}
|
|
18783
|
+
})();
|
|
18784
|
+
communities = communities.sort(sortFn);
|
|
18785
|
+
}
|
|
18786
|
+
return communities;
|
|
18787
|
+
}
|
|
18788
|
+
}
|
|
18789
|
+
|
|
18790
|
+
/* begin_public_function
|
|
18791
|
+
id: community.query
|
|
18792
|
+
*/
|
|
18793
|
+
/**
|
|
18794
|
+
* ```js
|
|
18795
|
+
* import { CommunityRepository } from '@amityco/ts-sdk'
|
|
18796
|
+
*
|
|
18797
|
+
* let communities = []
|
|
18798
|
+
* const unsub = CommunityRepository.getCommunities({
|
|
18799
|
+
* displayName: Amity.Community['displayName'],
|
|
18800
|
+
* }, response => merge(communities, response.data))
|
|
18801
|
+
* ```
|
|
18802
|
+
*
|
|
18803
|
+
* Observe all mutations on a list of {@link Amity.Community}s
|
|
18804
|
+
*
|
|
18805
|
+
* @param params for querying communities
|
|
18806
|
+
* @param callback the function to call when new data are available
|
|
18807
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the communities
|
|
18808
|
+
*
|
|
18809
|
+
* @category Community Live Collection
|
|
18810
|
+
*/
|
|
18811
|
+
const getCommunities = (params, callback, config) => {
|
|
18812
|
+
const { log, cache } = getActiveClient();
|
|
18813
|
+
if (!cache) {
|
|
18814
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
18815
|
+
}
|
|
18816
|
+
const timestamp = Date.now();
|
|
18817
|
+
log(`getCommunities(tmpid: ${timestamp}) > listen`);
|
|
18818
|
+
const communitiesLiveCollection = new CommunityLiveCollectionController(params, callback);
|
|
18819
|
+
const disposers = communitiesLiveCollection.startSubscription();
|
|
18820
|
+
const cacheKey = communitiesLiveCollection.getCacheKey();
|
|
18821
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
18822
|
+
return () => {
|
|
18823
|
+
log(`getCommunities(tmpid: ${timestamp}) > dispose`);
|
|
18824
|
+
disposers.forEach(fn => fn());
|
|
18825
|
+
};
|
|
18826
|
+
};
|
|
18827
|
+
/* end_public_function */
|
|
18828
|
+
|
|
18829
|
+
/* begin_public_function
|
|
18830
|
+
id: community.get
|
|
18831
|
+
*/
|
|
18832
|
+
/**
|
|
18833
|
+
* ```js
|
|
18834
|
+
* import { CommunityRepository } from '@amityco/ts-sdk';
|
|
18835
|
+
*
|
|
18836
|
+
* let community;
|
|
18837
|
+
*
|
|
18838
|
+
* const unsub = CommunityRepository.getCommunity(communityId, response => {
|
|
18839
|
+
* community = response.data;
|
|
18840
|
+
* });
|
|
18841
|
+
* ```
|
|
18842
|
+
*
|
|
18843
|
+
* Observe all mutation on a given {@link Amity.Community}
|
|
18844
|
+
*
|
|
18845
|
+
* @param communityId the ID of the message to observe
|
|
18846
|
+
* @param callback the function to call when new data are available
|
|
18847
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the community
|
|
18848
|
+
*
|
|
18601
18849
|
* @category Community Live Object
|
|
18602
18850
|
*/
|
|
18603
18851
|
const getCommunity = (communityId, callback) => {
|
|
@@ -19098,105 +19346,199 @@ const removeMembers = async (communityId, userIds) => {
|
|
|
19098
19346
|
/* end_public_function */
|
|
19099
19347
|
|
|
19100
19348
|
/**
|
|
19101
|
-
*
|
|
19102
|
-
*
|
|
19103
|
-
|
|
19104
|
-
|
|
19105
|
-
|
|
19106
|
-
|
|
19107
|
-
|
|
19108
|
-
|
|
19109
|
-
|
|
19110
|
-
*
|
|
19111
|
-
* @category Community API
|
|
19112
|
-
* @async
|
|
19113
|
-
* */
|
|
19114
|
-
const queryCommunityMembers = async (query) => {
|
|
19115
|
-
const client = getActiveClient();
|
|
19116
|
-
client.log('community/queryCommunityMembers', query);
|
|
19117
|
-
const _a = query !== null && query !== void 0 ? query : {}, { page, limit } = _a, params = __rest(_a, ["page", "limit"]);
|
|
19118
|
-
const options = (() => {
|
|
19119
|
-
if (page)
|
|
19120
|
-
return { token: page };
|
|
19121
|
-
if (limit)
|
|
19122
|
-
return { limit };
|
|
19123
|
-
return undefined;
|
|
19124
|
-
})();
|
|
19125
|
-
const { data: queryPayload } = await client.http.get(`/api/v3/communities/${params.communityId}/users`, {
|
|
19126
|
-
params: Object.assign(Object.assign({}, params), { options }),
|
|
19127
|
-
});
|
|
19128
|
-
const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
|
|
19129
|
-
const preparedPayload = prepareMembershipPayload(payload, 'communityUsers');
|
|
19130
|
-
const { communityUsers } = preparedPayload;
|
|
19131
|
-
const cachedAt = client.cache && Date.now();
|
|
19132
|
-
if (client.cache) {
|
|
19133
|
-
ingestInCache(preparedPayload, { cachedAt });
|
|
19134
|
-
const cacheKey = ['communityUsers', 'query', Object.assign(Object.assign({}, params), { options })];
|
|
19135
|
-
pushToCache(cacheKey, {
|
|
19136
|
-
communityUsers: communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
|
|
19137
|
-
paging,
|
|
19349
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
19350
|
+
* TODO: check if querybyIds is supported
|
|
19351
|
+
*/
|
|
19352
|
+
class CommunityMembersPaginationController extends PaginationController {
|
|
19353
|
+
async getRequest(queryParams, token) {
|
|
19354
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
19355
|
+
const options = token ? { token } : { limit };
|
|
19356
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/communities/${params.communityId}/users`, {
|
|
19357
|
+
params: Object.assign(Object.assign({}, params), { options }),
|
|
19138
19358
|
});
|
|
19359
|
+
return queryResponse;
|
|
19139
19360
|
}
|
|
19140
|
-
|
|
19141
|
-
};
|
|
19142
|
-
/**
|
|
19143
|
-
* ```js
|
|
19144
|
-
* import { queryCommunityMembers } from '@amityco/ts-sdk'
|
|
19145
|
-
* const communityMembers = await queryCommunityMembers(query)
|
|
19146
|
-
* ```
|
|
19147
|
-
*
|
|
19148
|
-
* Queries a paginable list of {@link Amity.InternalPost} objects from cache
|
|
19149
|
-
*
|
|
19150
|
-
* @param query The query parameters
|
|
19151
|
-
* @returns posts
|
|
19152
|
-
*
|
|
19153
|
-
* @category Post API
|
|
19154
|
-
*/
|
|
19155
|
-
queryCommunityMembers.locally = (query) => {
|
|
19156
|
-
var _a, _b;
|
|
19157
|
-
const client = getActiveClient();
|
|
19158
|
-
client.log('community/queryCommunityMembers', query);
|
|
19159
|
-
if (!client.cache)
|
|
19160
|
-
return;
|
|
19161
|
-
const _c = query !== null && query !== void 0 ? query : {}, { page, limit } = _c, params = __rest(_c, ["page", "limit"]);
|
|
19162
|
-
const options = (() => {
|
|
19163
|
-
if (page)
|
|
19164
|
-
return { token: page };
|
|
19165
|
-
if (limit)
|
|
19166
|
-
return { limit };
|
|
19167
|
-
return undefined;
|
|
19168
|
-
})();
|
|
19169
|
-
const cacheKey = ['communityUsers', 'query', Object.assign(Object.assign({}, params), { options })];
|
|
19170
|
-
const { data, cachedAt } = (_a = pullFromCache(cacheKey)) !== null && _a !== void 0 ? _a : {};
|
|
19171
|
-
if (!(data === null || data === void 0 ? void 0 : data.communityUsers.length))
|
|
19172
|
-
return;
|
|
19173
|
-
const communityUsers = data.communityUsers
|
|
19174
|
-
.map(key => pullFromCache(['communityUsers', 'get', key]))
|
|
19175
|
-
.filter(Boolean)
|
|
19176
|
-
.map(({ data }) => data);
|
|
19177
|
-
const { paging } = data;
|
|
19178
|
-
return communityUsers.length === ((_b = data === null || data === void 0 ? void 0 : data.communityUsers) === null || _b === void 0 ? void 0 : _b.length)
|
|
19179
|
-
? { data: communityUsers, cachedAt, paging }
|
|
19180
|
-
: undefined;
|
|
19181
|
-
};
|
|
19361
|
+
}
|
|
19182
19362
|
|
|
19183
|
-
|
|
19184
|
-
|
|
19185
|
-
|
|
19186
|
-
|
|
19187
|
-
|
|
19188
|
-
let communityMembers = filterByPropIntersection(data, 'roles', params.roles);
|
|
19189
|
-
if (params.memberships) {
|
|
19190
|
-
communityMembers = communityMembers.filter(({ communityMembership }) => {
|
|
19191
|
-
const membership = params.memberships;
|
|
19192
|
-
return membership.includes(communityMembership);
|
|
19193
|
-
});
|
|
19363
|
+
class CommunityMembersQueryStreamController extends QueryStreamController {
|
|
19364
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
19365
|
+
super(query, cacheKey);
|
|
19366
|
+
this.notifyChange = notifyChange;
|
|
19367
|
+
this.preparePayload = preparePayload;
|
|
19194
19368
|
}
|
|
19195
|
-
|
|
19196
|
-
|
|
19369
|
+
async saveToMainDB(response) {
|
|
19370
|
+
const processedPayload = await this.preparePayload(response);
|
|
19371
|
+
const client = getActiveClient();
|
|
19372
|
+
const cachedAt = client.cache && Date.now();
|
|
19373
|
+
if (client.cache) {
|
|
19374
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
19375
|
+
}
|
|
19197
19376
|
}
|
|
19198
|
-
|
|
19199
|
-
|
|
19377
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
19378
|
+
var _a, _b;
|
|
19379
|
+
if (refresh) {
|
|
19380
|
+
pushToCache(this.cacheKey, {
|
|
19381
|
+
data: response.communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
|
|
19382
|
+
});
|
|
19383
|
+
}
|
|
19384
|
+
else {
|
|
19385
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
19386
|
+
const communityUsers = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
19387
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
19388
|
+
...new Set([
|
|
19389
|
+
...communityUsers,
|
|
19390
|
+
...response.communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
|
|
19391
|
+
]),
|
|
19392
|
+
] }));
|
|
19393
|
+
}
|
|
19394
|
+
}
|
|
19395
|
+
reactor(action) {
|
|
19396
|
+
return (community, communityMembers) => {
|
|
19397
|
+
var _a;
|
|
19398
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
19399
|
+
if (!collection)
|
|
19400
|
+
return;
|
|
19401
|
+
communityMembers.forEach(communityMember => {
|
|
19402
|
+
const communityMemberCacheId = getResolver('communityUsers')({
|
|
19403
|
+
communityId: this.query.communityId,
|
|
19404
|
+
userId: communityMember.userId,
|
|
19405
|
+
});
|
|
19406
|
+
if (communityMember.communityMembership === 'none') {
|
|
19407
|
+
collection.data = collection.data.filter(m => m !== communityMemberCacheId);
|
|
19408
|
+
}
|
|
19409
|
+
else if (!collection.data.includes(communityMemberCacheId)) {
|
|
19410
|
+
collection.data = [communityMemberCacheId, ...collection.data];
|
|
19411
|
+
}
|
|
19412
|
+
});
|
|
19413
|
+
pushToCache(this.cacheKey, collection);
|
|
19414
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
19415
|
+
};
|
|
19416
|
+
}
|
|
19417
|
+
subscribeRTE(createSubscriber) {
|
|
19418
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
19419
|
+
}
|
|
19420
|
+
}
|
|
19421
|
+
|
|
19422
|
+
var EnumCommunityMemberActions;
|
|
19423
|
+
(function (EnumCommunityMemberActions) {
|
|
19424
|
+
EnumCommunityMemberActions["OnCommunityJoined"] = "onCommunityJoined";
|
|
19425
|
+
EnumCommunityMemberActions["OnCommunityLeft"] = "onCommunityLeft";
|
|
19426
|
+
EnumCommunityMemberActions["OnCommunityUserBanned"] = "onCommunityUserBanned";
|
|
19427
|
+
EnumCommunityMemberActions["OnCommunityUserChanged"] = "onCommunityUserChanged";
|
|
19428
|
+
EnumCommunityMemberActions["OnCommunityUserRoleAdded"] = "onCommunityUserRoleAdded";
|
|
19429
|
+
EnumCommunityMemberActions["OnCommunityUserRoleRemoved"] = "onCommunityUserRoleRemoved";
|
|
19430
|
+
EnumCommunityMemberActions["OnCommunityUserUnbanned"] = "onCommunityUserUnbanned";
|
|
19431
|
+
})(EnumCommunityMemberActions || (EnumCommunityMemberActions = {}));
|
|
19432
|
+
|
|
19433
|
+
/* eslint-disable no-use-before-define */
|
|
19434
|
+
class CommunityMembersLiveCollectionController extends LiveCollectionController {
|
|
19435
|
+
constructor(query, callback) {
|
|
19436
|
+
const queryStreamId = hash__default["default"](query);
|
|
19437
|
+
const cacheKey = ['communityUsers', 'collection', queryStreamId];
|
|
19438
|
+
const paginationController = new CommunityMembersPaginationController(query);
|
|
19439
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
19440
|
+
this.query = query;
|
|
19441
|
+
this.queryStreamController = new CommunityMembersQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityPayload);
|
|
19442
|
+
this.callback = callback.bind(this);
|
|
19443
|
+
this.loadPage({ initial: true });
|
|
19444
|
+
}
|
|
19445
|
+
setup() {
|
|
19446
|
+
var _a;
|
|
19447
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
19448
|
+
if (!collection) {
|
|
19449
|
+
pushToCache(this.cacheKey, {
|
|
19450
|
+
data: [],
|
|
19451
|
+
params: {},
|
|
19452
|
+
});
|
|
19453
|
+
}
|
|
19454
|
+
}
|
|
19455
|
+
async persistModel(queryPayload) {
|
|
19456
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
19457
|
+
}
|
|
19458
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
19459
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
19460
|
+
}
|
|
19461
|
+
startSubscription() {
|
|
19462
|
+
return this.queryStreamController.subscribeRTE([
|
|
19463
|
+
{ fn: onCommunityJoined, action: EnumCommunityMemberActions.OnCommunityJoined },
|
|
19464
|
+
{ fn: onCommunityLeft, action: EnumCommunityMemberActions.OnCommunityLeft },
|
|
19465
|
+
{ fn: onCommunityUserBanned, action: EnumCommunityMemberActions.OnCommunityUserBanned },
|
|
19466
|
+
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions.OnCommunityUserChanged },
|
|
19467
|
+
{ fn: onCommunityUserRoleAdded, action: EnumCommunityMemberActions.OnCommunityUserRoleAdded },
|
|
19468
|
+
{
|
|
19469
|
+
fn: onCommunityUserRoleRemoved,
|
|
19470
|
+
action: EnumCommunityMemberActions.OnCommunityUserRoleRemoved,
|
|
19471
|
+
},
|
|
19472
|
+
{ fn: onCommunityUserUnbanned, action: EnumCommunityMemberActions.OnCommunityUserUnbanned },
|
|
19473
|
+
]);
|
|
19474
|
+
}
|
|
19475
|
+
notifyChange({ origin, loading, error }) {
|
|
19476
|
+
var _a, _b;
|
|
19477
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
19478
|
+
if (!collection)
|
|
19479
|
+
return;
|
|
19480
|
+
const data = this.applyFilter((_b = collection.data
|
|
19481
|
+
.map(id => pullFromCache(['communityUsers', 'get', id]))
|
|
19482
|
+
.filter(isNonNullable)
|
|
19483
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
|
|
19484
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
19485
|
+
return;
|
|
19486
|
+
this.callback({
|
|
19487
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
19488
|
+
data,
|
|
19489
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
19490
|
+
loading,
|
|
19491
|
+
error,
|
|
19492
|
+
});
|
|
19493
|
+
}
|
|
19494
|
+
applyFilter(data) {
|
|
19495
|
+
let communityMembers = filterByPropIntersection(data, 'roles', this.query.roles);
|
|
19496
|
+
if (this.query.memberships) {
|
|
19497
|
+
communityMembers = communityMembers.filter(({ communityMembership }) => {
|
|
19498
|
+
const memberships = this.query.memberships || [];
|
|
19499
|
+
return memberships.includes(communityMembership);
|
|
19500
|
+
});
|
|
19501
|
+
}
|
|
19502
|
+
if (this.query.search) {
|
|
19503
|
+
communityMembers = filterBySearchTerm(communityMembers, this.query.search);
|
|
19504
|
+
}
|
|
19505
|
+
const sortBy = this.query.sortBy ? this.query.sortBy : 'lastCreated';
|
|
19506
|
+
switch (sortBy) {
|
|
19507
|
+
case 'lastCreated':
|
|
19508
|
+
communityMembers = communityMembers.sort(sortByLastCreated);
|
|
19509
|
+
break;
|
|
19510
|
+
case 'firstCreated':
|
|
19511
|
+
communityMembers = communityMembers.sort(sortByFirstCreated);
|
|
19512
|
+
break;
|
|
19513
|
+
case 'displayName':
|
|
19514
|
+
communityMembers = communityMembers.sort((memberA, memberB) => {
|
|
19515
|
+
if (!memberA.user || !memberB.user)
|
|
19516
|
+
return 0;
|
|
19517
|
+
return sortByDisplayName(memberA.user, memberB.user);
|
|
19518
|
+
});
|
|
19519
|
+
break;
|
|
19520
|
+
}
|
|
19521
|
+
return communityMembers;
|
|
19522
|
+
}
|
|
19523
|
+
}
|
|
19524
|
+
|
|
19525
|
+
/*
|
|
19526
|
+
* Exported for testing
|
|
19527
|
+
* @hidden
|
|
19528
|
+
*/
|
|
19529
|
+
const applyFilter = (data, params) => {
|
|
19530
|
+
let communityMembers = filterByPropIntersection(data, 'roles', params.roles);
|
|
19531
|
+
if (params.memberships) {
|
|
19532
|
+
communityMembers = communityMembers.filter(({ communityMembership }) => {
|
|
19533
|
+
const membership = params.memberships;
|
|
19534
|
+
return membership.includes(communityMembership);
|
|
19535
|
+
});
|
|
19536
|
+
}
|
|
19537
|
+
if (params.search) {
|
|
19538
|
+
communityMembers = filterBySearchTerm(communityMembers, params.search);
|
|
19539
|
+
}
|
|
19540
|
+
const sortBy = params.sortBy ? params.sortBy : 'lastCreated';
|
|
19541
|
+
communityMembers = communityMembers.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
19200
19542
|
return communityMembers;
|
|
19201
19543
|
};
|
|
19202
19544
|
/* begin_public_function
|
|
@@ -19227,79 +19569,15 @@ const getMembers = (params, callback, config) => {
|
|
|
19227
19569
|
}
|
|
19228
19570
|
const timestamp = Date.now();
|
|
19229
19571
|
log(`getMembers(tmpid: ${timestamp}) > listen`);
|
|
19230
|
-
const
|
|
19231
|
-
|
|
19232
|
-
|
|
19233
|
-
|
|
19234
|
-
const
|
|
19235
|
-
const
|
|
19236
|
-
|
|
19237
|
-
|
|
19238
|
-
|
|
19239
|
-
];
|
|
19240
|
-
const responder = (data, isEventModel = false) => {
|
|
19241
|
-
var _a, _b;
|
|
19242
|
-
const communityMembers = (_a = data.data
|
|
19243
|
-
.map(id => pullFromCache(['communityUsers', 'get', id]))
|
|
19244
|
-
.filter(Boolean)
|
|
19245
|
-
.map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
|
|
19246
|
-
callback({
|
|
19247
|
-
onNextPage: onFetch,
|
|
19248
|
-
data: isEventModel ? applyFilter(communityMembers, params) : communityMembers,
|
|
19249
|
-
hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
|
|
19250
|
-
loading: data.loading,
|
|
19251
|
-
error: data.error,
|
|
19252
|
-
});
|
|
19253
|
-
};
|
|
19254
|
-
const realtimeRouter = (_) => (_, communityMembers) => {
|
|
19255
|
-
var _a;
|
|
19256
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
19257
|
-
if (!collection) {
|
|
19258
|
-
return;
|
|
19259
|
-
}
|
|
19260
|
-
const communityMemberCacheIds = communityMembers
|
|
19261
|
-
.map(communityMember => {
|
|
19262
|
-
if (params.communityId !== communityMember.communityId) {
|
|
19263
|
-
return;
|
|
19264
|
-
}
|
|
19265
|
-
const communityMemberCacheId = getResolver('communityUsers')({
|
|
19266
|
-
communityId: params.communityId,
|
|
19267
|
-
userId: communityMember.userId,
|
|
19268
|
-
});
|
|
19269
|
-
return communityMemberCacheId;
|
|
19270
|
-
})
|
|
19271
|
-
.filter(isNonNullable);
|
|
19272
|
-
collection.data = [...new Set([...communityMemberCacheIds, ...collection.data])];
|
|
19273
|
-
pushToCache(cacheKey, collection);
|
|
19274
|
-
pushToCache(cacheByCommunityIdKey, collection);
|
|
19275
|
-
responder(collection, true);
|
|
19276
|
-
};
|
|
19277
|
-
const onFetch = (initial = false) => {
|
|
19278
|
-
var _a, _b;
|
|
19279
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
19280
|
-
const communityMembers = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
19281
|
-
if (!initial && communityMembers.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
|
|
19282
|
-
return;
|
|
19283
|
-
const query = createQuery(queryCommunityMembers, Object.assign(Object.assign({}, queryParams), { limit: initial ? limit : undefined, page: !initial ? collection === null || collection === void 0 ? void 0 : collection.params.page : undefined }));
|
|
19284
|
-
runQuery(query, ({ data: result, error, loading, paging }) => {
|
|
19285
|
-
const data = {
|
|
19286
|
-
loading,
|
|
19287
|
-
error,
|
|
19288
|
-
params: { page: paging === null || paging === void 0 ? void 0 : paging.next },
|
|
19289
|
-
data: communityMembers,
|
|
19290
|
-
};
|
|
19291
|
-
if (result) {
|
|
19292
|
-
data.data = [
|
|
19293
|
-
...new Set([...communityMembers, ...result.map(getResolver('communityUsers'))]),
|
|
19294
|
-
];
|
|
19295
|
-
}
|
|
19296
|
-
pushToCache(cacheKey, data);
|
|
19297
|
-
pushToCache(cacheByCommunityIdKey, data);
|
|
19298
|
-
responder(data);
|
|
19299
|
-
}, queryOptions(policy));
|
|
19300
|
-
};
|
|
19301
|
-
disposers.push(onCommunityLeft(realtimeRouter()), onCommunityJoined(realtimeRouter()), onCommunityUserBanned(realtimeRouter()), onCommunityUserUnbanned(realtimeRouter()), onCommunityUserChanged(realtimeRouter()), onCommunityUserRoleAdded(realtimeRouter()), onCommunityUserRoleRemoved(realtimeRouter()));
|
|
19302
|
-
onFetch(true);
|
|
19572
|
+
const communityMemberLiveCollection = new CommunityMembersLiveCollectionController(params, resp => {
|
|
19573
|
+
console.log('resp', resp);
|
|
19574
|
+
callback(resp);
|
|
19575
|
+
});
|
|
19576
|
+
const disposers = communityMemberLiveCollection.startSubscription();
|
|
19577
|
+
const cacheKey = communityMemberLiveCollection.getCacheKey();
|
|
19578
|
+
disposers.push(() => {
|
|
19579
|
+
dropFromCache(cacheKey);
|
|
19580
|
+
});
|
|
19303
19581
|
return () => {
|
|
19304
19582
|
log(`getMembers(tmpid: ${timestamp}) > dispose`);
|
|
19305
19583
|
disposers.forEach(fn => fn());
|
|
@@ -19339,6 +19617,7 @@ var index$8 = /*#__PURE__*/Object.freeze({
|
|
|
19339
19617
|
onCommunityUpdated: onCommunityUpdated,
|
|
19340
19618
|
onCommunityDeleted: onCommunityDeleted,
|
|
19341
19619
|
observeCommunity: observeCommunity,
|
|
19620
|
+
searchCommunities: searchCommunities,
|
|
19342
19621
|
getCommunities: getCommunities,
|
|
19343
19622
|
getCommunity: getCommunity,
|
|
19344
19623
|
getTrendingCommunities: getTrendingCommunities,
|
|
@@ -19925,7 +20204,7 @@ const updatePost = async (postId, patch) => {
|
|
|
19925
20204
|
const cachedAt = client.cache && Date.now();
|
|
19926
20205
|
if (client.cache)
|
|
19927
20206
|
ingestInCache(data, { cachedAt });
|
|
19928
|
-
fireEvent('post.updated', data);
|
|
20207
|
+
fireEvent('local.post.updated', data);
|
|
19929
20208
|
const { posts } = data;
|
|
19930
20209
|
return {
|
|
19931
20210
|
data: LinkedObject.post(posts.find(post => post.postId === postId)),
|
|
@@ -19962,7 +20241,7 @@ const editPost = async (postId, patch) => {
|
|
|
19962
20241
|
const cachedAt = client.cache && Date.now();
|
|
19963
20242
|
if (client.cache)
|
|
19964
20243
|
ingestInCache(data, { cachedAt });
|
|
19965
|
-
fireEvent('post.updated', data);
|
|
20244
|
+
fireEvent('local.post.updated', data);
|
|
19966
20245
|
const { posts } = data;
|
|
19967
20246
|
return {
|
|
19968
20247
|
data: LinkedObject.post(posts.find(post => post.postId === postId)),
|
|
@@ -20336,307 +20615,23 @@ const observePost = (postId, callback, policy = 'cache_then_server') => {
|
|
|
20336
20615
|
};
|
|
20337
20616
|
|
|
20338
20617
|
/* begin_public_function
|
|
20339
|
-
id:
|
|
20618
|
+
id: comment.get_by_ids
|
|
20340
20619
|
*/
|
|
20341
20620
|
/**
|
|
20342
20621
|
* ```js
|
|
20343
|
-
* import {
|
|
20344
|
-
*
|
|
20345
|
-
* let post;
|
|
20346
|
-
*
|
|
20347
|
-
* const unsub = PostRepository.getPost(postId, response => {
|
|
20348
|
-
* post = response.data;
|
|
20349
|
-
* });
|
|
20350
|
-
* ```
|
|
20351
|
-
*
|
|
20352
|
-
* Observe all mutation on a given {@link Amity.Post}
|
|
20353
|
-
*
|
|
20354
|
-
* @param postId the ID of the message to observe
|
|
20355
|
-
* @param callback the function to call when new data are available
|
|
20356
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the sub channel
|
|
20357
|
-
*
|
|
20358
|
-
* @category Post Live Object
|
|
20359
|
-
*/
|
|
20360
|
-
const getPost = (postId, callback) => {
|
|
20361
|
-
return liveObject(postId, callback, 'postId', getPost$1, [
|
|
20362
|
-
onPostApproved,
|
|
20363
|
-
onPostDeclined,
|
|
20364
|
-
(callback) => {
|
|
20365
|
-
return onPostDeleted((post) => {
|
|
20366
|
-
var _a;
|
|
20367
|
-
let targetPost = post;
|
|
20368
|
-
// check if the deleted post is a child of the target post
|
|
20369
|
-
if (post.parentPostId === postId && post.isDeleted) {
|
|
20370
|
-
const parentPost = (_a = pullFromCache([
|
|
20371
|
-
'post',
|
|
20372
|
-
'get',
|
|
20373
|
-
post.parentPostId,
|
|
20374
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
20375
|
-
if (parentPost) {
|
|
20376
|
-
parentPost.children = parentPost.children.filter(childId => childId !== post.postId);
|
|
20377
|
-
pushToCache(['post', 'get', parentPost.postId], parentPost);
|
|
20378
|
-
// if the deleted post is a child of the target post, then the target post is the parent post
|
|
20379
|
-
targetPost = parentPost;
|
|
20380
|
-
}
|
|
20381
|
-
}
|
|
20382
|
-
callback(targetPost);
|
|
20383
|
-
});
|
|
20384
|
-
},
|
|
20385
|
-
onPostFlagged,
|
|
20386
|
-
(callback) => {
|
|
20387
|
-
return onPostReactionAdded((post) => {
|
|
20388
|
-
callback(LinkedObject.post(post));
|
|
20389
|
-
});
|
|
20390
|
-
},
|
|
20391
|
-
(callback) => {
|
|
20392
|
-
return onPostReactionRemoved((post) => {
|
|
20393
|
-
callback(LinkedObject.post(post));
|
|
20394
|
-
});
|
|
20395
|
-
},
|
|
20396
|
-
onPostUnflagged,
|
|
20397
|
-
onPostUpdated,
|
|
20398
|
-
]);
|
|
20399
|
-
};
|
|
20400
|
-
/* end_public_function */
|
|
20401
|
-
|
|
20402
|
-
/**
|
|
20403
|
-
* ```js
|
|
20404
|
-
* import { queryPosts } from '@amityco/ts-sdk'
|
|
20405
|
-
* const { data: posts, prevPage, nextPage } = await queryPosts({ targetId, targetType })
|
|
20622
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
20623
|
+
* const comments = await CommentRepository.getCommentByIds(['foo', 'bar'])
|
|
20406
20624
|
* ```
|
|
20407
20625
|
*
|
|
20408
|
-
*
|
|
20626
|
+
* Fetches a collection of {@link Amity.Comment} objects
|
|
20409
20627
|
*
|
|
20410
|
-
* @param
|
|
20411
|
-
* @returns
|
|
20628
|
+
* @param commentIds the IDs of the {@link Amity.Comment} to fetch
|
|
20629
|
+
* @returns the associated collection of {@link Amity.Comment} objects
|
|
20412
20630
|
*
|
|
20413
|
-
* @category
|
|
20631
|
+
* @category Comment API
|
|
20414
20632
|
* @async
|
|
20415
20633
|
*/
|
|
20416
|
-
const
|
|
20417
|
-
const client = getActiveClient();
|
|
20418
|
-
client.log('post/queryPosts', query);
|
|
20419
|
-
const { page, limit = 10, includeDeleted } = query, params = __rest(query, ["page", "limit", "includeDeleted"]);
|
|
20420
|
-
const { dataTypes, matchingOnlyParentPost } = params;
|
|
20421
|
-
const options = (() => {
|
|
20422
|
-
if (page)
|
|
20423
|
-
return { token: page };
|
|
20424
|
-
if (limit)
|
|
20425
|
-
return { limit };
|
|
20426
|
-
return undefined;
|
|
20427
|
-
})();
|
|
20428
|
-
// API-FIX: parameters should be querystring. (1)
|
|
20429
|
-
// API-FIX: backend should answer Amity.Response (2)
|
|
20430
|
-
// const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<Amity.PostPayload>>>(
|
|
20431
|
-
const { data } = await client.http.get(`/api/v4/posts`, {
|
|
20432
|
-
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted),
|
|
20433
|
-
/*
|
|
20434
|
-
* when creating post like image, file, video BE will create 2 posts
|
|
20435
|
-
* 1. parent post to store text with dataType=text
|
|
20436
|
-
* 2. child post to store dataTypes post data
|
|
20437
|
-
*
|
|
20438
|
-
* By default, BE queries only parent post
|
|
20439
|
-
*/
|
|
20440
|
-
matchingOnlyParentPost: matchingOnlyParentPost !== null && matchingOnlyParentPost !== void 0 ? matchingOnlyParentPost : !(dataTypes === null || dataTypes === void 0 ? void 0 : dataTypes.length), options }),
|
|
20441
|
-
});
|
|
20442
|
-
// API-FIX: backend should answer Amity.Response (2)
|
|
20443
|
-
// const { paging, posts } = unwrapPayload(data)
|
|
20444
|
-
// unpacking
|
|
20445
|
-
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
20446
|
-
const paperedPayload = prepareMembershipPayload(payload, 'communityUsers');
|
|
20447
|
-
const { posts } = payload;
|
|
20448
|
-
const cachedAt = client.cache && Date.now();
|
|
20449
|
-
if (client.cache) {
|
|
20450
|
-
ingestInCache(paperedPayload, { cachedAt });
|
|
20451
|
-
const cacheKey = ['post', 'query', Object.assign(Object.assign({}, params), { options })];
|
|
20452
|
-
pushToCache(cacheKey, { posts: posts.map(getResolver('post')), paging });
|
|
20453
|
-
}
|
|
20454
|
-
return { data: posts.map(LinkedObject.post), cachedAt, paging };
|
|
20455
|
-
};
|
|
20456
|
-
|
|
20457
|
-
/* begin_public_function
|
|
20458
|
-
id: post.query
|
|
20459
|
-
*/
|
|
20460
|
-
/**
|
|
20461
|
-
* ```js
|
|
20462
|
-
* import { PostRepository } from '@amityco/ts-sdk'
|
|
20463
|
-
*
|
|
20464
|
-
* let posts = []
|
|
20465
|
-
* const unsub = PostRepository.getPosts({
|
|
20466
|
-
* targetType: Amity.PostTargetType,
|
|
20467
|
-
* targetId: Amity.Post['targetId'],
|
|
20468
|
-
* }, response => merge(posts, response.data))
|
|
20469
|
-
* ```
|
|
20470
|
-
*
|
|
20471
|
-
* Observe all mutations on a list of {@link Amity.Post} for a given target object
|
|
20472
|
-
*
|
|
20473
|
-
* @param params.targetType the type of the target
|
|
20474
|
-
* @param params.targetId the ID of the target
|
|
20475
|
-
* @param callback the function to call when new data are available
|
|
20476
|
-
* @param config
|
|
20477
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
20478
|
-
*
|
|
20479
|
-
* @category Posts Live Collection
|
|
20480
|
-
*/
|
|
20481
|
-
const getPosts = (params, callback, config) => {
|
|
20482
|
-
const { log, cache } = getActiveClient();
|
|
20483
|
-
if (!cache) {
|
|
20484
|
-
console.log(ENABLE_CACHE_MESSAGE);
|
|
20485
|
-
}
|
|
20486
|
-
const timestamp = Date.now();
|
|
20487
|
-
log(`getPosts(tmpid: ${timestamp}) > listen`);
|
|
20488
|
-
const { limit: queryLimit } = params, queryParams = __rest(params, ["limit"]);
|
|
20489
|
-
const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
|
|
20490
|
-
const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
|
|
20491
|
-
const disposers = [];
|
|
20492
|
-
const cacheKey = [
|
|
20493
|
-
'post',
|
|
20494
|
-
'collection',
|
|
20495
|
-
{ targetId: params.targetId, targetType: params.targetType },
|
|
20496
|
-
];
|
|
20497
|
-
const responder = (data) => {
|
|
20498
|
-
var _a, _b, _c;
|
|
20499
|
-
let posts = (_a = data.data
|
|
20500
|
-
.map(postId => pullFromCache(['post', 'get', postId]))
|
|
20501
|
-
.filter(Boolean)
|
|
20502
|
-
.map(({ data }) => LinkedObject.post(data))) !== null && _a !== void 0 ? _a : [];
|
|
20503
|
-
const sortBy = params.sortBy ? params.sortBy : 'lastCreated';
|
|
20504
|
-
posts = posts.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
20505
|
-
if (!params.includeDeleted) {
|
|
20506
|
-
posts = filterByPropEquality(posts, 'isDeleted', false);
|
|
20507
|
-
}
|
|
20508
|
-
if (params.tags) {
|
|
20509
|
-
posts = posts.filter(p => { var _a; return (_a = p.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); }); });
|
|
20510
|
-
}
|
|
20511
|
-
if (params.targetType === 'community' && params.feedType) {
|
|
20512
|
-
posts = filterByFeedType(posts, params.feedType);
|
|
20513
|
-
}
|
|
20514
|
-
if ((_b = params.dataTypes) === null || _b === void 0 ? void 0 : _b.length) {
|
|
20515
|
-
posts = filterByPostDataTypes(posts, params.dataTypes);
|
|
20516
|
-
}
|
|
20517
|
-
callback({
|
|
20518
|
-
onNextPage: onFetch,
|
|
20519
|
-
data: posts,
|
|
20520
|
-
hasNextPage: !!((_c = data.params) === null || _c === void 0 ? void 0 : _c.page),
|
|
20521
|
-
loading: data.loading,
|
|
20522
|
-
error: data.error,
|
|
20523
|
-
});
|
|
20524
|
-
};
|
|
20525
|
-
const realtimeRouter = (action) => (post) => {
|
|
20526
|
-
var _a, _b;
|
|
20527
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
20528
|
-
if (!collection)
|
|
20529
|
-
return;
|
|
20530
|
-
if (post.parentPostId && post.isDeleted) {
|
|
20531
|
-
const parentPost = (_b = pullFromCache([
|
|
20532
|
-
'post',
|
|
20533
|
-
'get',
|
|
20534
|
-
post.parentPostId,
|
|
20535
|
-
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
20536
|
-
if (!parentPost || (parentPost === null || parentPost === void 0 ? void 0 : parentPost.targetId) !== params.targetId)
|
|
20537
|
-
return;
|
|
20538
|
-
parentPost.children = parentPost.children.filter(childId => childId !== post.postId);
|
|
20539
|
-
pushToCache(['post', 'get', parentPost.postId], parentPost);
|
|
20540
|
-
}
|
|
20541
|
-
else {
|
|
20542
|
-
if (params.targetId !== post.targetId)
|
|
20543
|
-
return;
|
|
20544
|
-
if (params.targetType !== post.targetType)
|
|
20545
|
-
return;
|
|
20546
|
-
}
|
|
20547
|
-
/*
|
|
20548
|
-
* This is not ideal, but currently this is the only way to update the
|
|
20549
|
-
* collection on post declined
|
|
20550
|
-
*/
|
|
20551
|
-
if (action === 'onDeclined') {
|
|
20552
|
-
collection.data = collection.data.filter(postId => postId !== post.postId);
|
|
20553
|
-
}
|
|
20554
|
-
else {
|
|
20555
|
-
collection.data = [...new Set([post.postId, ...collection.data])];
|
|
20556
|
-
}
|
|
20557
|
-
pushToCache(cacheKey, collection);
|
|
20558
|
-
responder(collection);
|
|
20559
|
-
};
|
|
20560
|
-
const onFetch = (initial = false) => {
|
|
20561
|
-
var _a, _b, _c;
|
|
20562
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
20563
|
-
const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
20564
|
-
if (!initial && posts.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
|
|
20565
|
-
return;
|
|
20566
|
-
const query = createQuery(queryPosts, Object.assign(Object.assign({}, queryParams), { limit: initial ? limit : undefined, page: !initial ? collection === null || collection === void 0 ? void 0 : collection.params.page : undefined }));
|
|
20567
|
-
runQuery(query, ({ data: result, error, loading, paging }) => {
|
|
20568
|
-
const data = {
|
|
20569
|
-
loading,
|
|
20570
|
-
error,
|
|
20571
|
-
params: { page: paging === null || paging === void 0 ? void 0 : paging.next },
|
|
20572
|
-
data: posts,
|
|
20573
|
-
};
|
|
20574
|
-
if (result) {
|
|
20575
|
-
data.data = initial
|
|
20576
|
-
? result.map(getResolver('post'))
|
|
20577
|
-
: [...new Set([...posts, ...result.map(getResolver('post'))])];
|
|
20578
|
-
}
|
|
20579
|
-
pushToCache(cacheKey, data);
|
|
20580
|
-
responder(data);
|
|
20581
|
-
}, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
|
|
20582
|
-
};
|
|
20583
|
-
disposers.push(onPostCreated(realtimeRouter('onCreate')), onPostApproved(realtimeRouter('onApproved')), onPostDeclined(realtimeRouter('onDeclined')), onPostDeleted(realtimeRouter('onDelete')), onPostUpdated(realtimeRouter('onUpdate')), onPostFlagged(realtimeRouter('onFlagged')), onPostUnflagged(realtimeRouter('onUnflagged')), onPostReactionAdded(realtimeRouter('onReactionAdded')), onPostReactionRemoved(realtimeRouter('onReactionRemoved')));
|
|
20584
|
-
onFetch(true);
|
|
20585
|
-
disposers.push(() => dropFromCache(cacheKey));
|
|
20586
|
-
return () => {
|
|
20587
|
-
log(`getPosts(tmpid: ${timestamp}) > dispose`);
|
|
20588
|
-
disposers.forEach(fn => fn());
|
|
20589
|
-
};
|
|
20590
|
-
};
|
|
20591
|
-
/* end_public_function */
|
|
20592
|
-
|
|
20593
|
-
var index$5 = /*#__PURE__*/Object.freeze({
|
|
20594
|
-
__proto__: null,
|
|
20595
|
-
getPostByIds: getPostByIds,
|
|
20596
|
-
createPost: createPost,
|
|
20597
|
-
updatePost: updatePost,
|
|
20598
|
-
editPost: editPost,
|
|
20599
|
-
deletePost: deletePost,
|
|
20600
|
-
softDeletePost: softDeletePost,
|
|
20601
|
-
hardDeletePost: hardDeletePost,
|
|
20602
|
-
approvePost: approvePost,
|
|
20603
|
-
declinePost: declinePost,
|
|
20604
|
-
flagPost: flagPost,
|
|
20605
|
-
unflagPost: unflagPost,
|
|
20606
|
-
isPostFlaggedByMe: isPostFlaggedByMe,
|
|
20607
|
-
onPostCreated: onPostCreated,
|
|
20608
|
-
onPostUpdated: onPostUpdated,
|
|
20609
|
-
onPostDeleted: onPostDeleted,
|
|
20610
|
-
onPostApproved: onPostApproved,
|
|
20611
|
-
onPostDeclined: onPostDeclined,
|
|
20612
|
-
onPostFlagged: onPostFlagged,
|
|
20613
|
-
onPostUnflagged: onPostUnflagged,
|
|
20614
|
-
onPostReactionAdded: onPostReactionAdded,
|
|
20615
|
-
onPostReactionRemoved: onPostReactionRemoved,
|
|
20616
|
-
observePosts: observePosts,
|
|
20617
|
-
observePost: observePost,
|
|
20618
|
-
getPost: getPost,
|
|
20619
|
-
getPosts: getPosts
|
|
20620
|
-
});
|
|
20621
|
-
|
|
20622
|
-
/* begin_public_function
|
|
20623
|
-
id: comment.get_by_ids
|
|
20624
|
-
*/
|
|
20625
|
-
/**
|
|
20626
|
-
* ```js
|
|
20627
|
-
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
20628
|
-
* const comments = await CommentRepository.getCommentByIds(['foo', 'bar'])
|
|
20629
|
-
* ```
|
|
20630
|
-
*
|
|
20631
|
-
* Fetches a collection of {@link Amity.Comment} objects
|
|
20632
|
-
*
|
|
20633
|
-
* @param commentIds the IDs of the {@link Amity.Comment} to fetch
|
|
20634
|
-
* @returns the associated collection of {@link Amity.Comment} objects
|
|
20635
|
-
*
|
|
20636
|
-
* @category Comment API
|
|
20637
|
-
* @async
|
|
20638
|
-
*/
|
|
20639
|
-
const getCommentByIds = async (commentIds) => {
|
|
20634
|
+
const getCommentByIds = async (commentIds) => {
|
|
20640
20635
|
const client = getActiveClient();
|
|
20641
20636
|
client.log('comment/getCommentByIds', commentIds);
|
|
20642
20637
|
const encodedCommentIds = commentIds.map(commentId => encodeURIComponent(commentId));
|
|
@@ -20727,7 +20722,7 @@ const createComment = async (bundle) => {
|
|
|
20727
20722
|
ingestInCache(data, { cachedAt });
|
|
20728
20723
|
if (['post', 'content'].includes(bundle.referenceType)) {
|
|
20729
20724
|
const post = await getPost$1(bundle.referenceId);
|
|
20730
|
-
fireEvent('post.updated', {
|
|
20725
|
+
fireEvent('local.post.updated', {
|
|
20731
20726
|
posts: [post.data],
|
|
20732
20727
|
categories: [],
|
|
20733
20728
|
comments: [],
|
|
@@ -20765,7 +20760,7 @@ const createComment = async (bundle) => {
|
|
|
20765
20760
|
}
|
|
20766
20761
|
}
|
|
20767
20762
|
}
|
|
20768
|
-
fireEvent('comment.created', data);
|
|
20763
|
+
fireEvent('local.comment.created', data);
|
|
20769
20764
|
return {
|
|
20770
20765
|
data: LinkedObject.comment(comments[0]),
|
|
20771
20766
|
cachedAt,
|
|
@@ -20921,8 +20916,7 @@ const deleteComment = async (commentId, permanent = false) => {
|
|
|
20921
20916
|
}
|
|
20922
20917
|
else {
|
|
20923
20918
|
const post = await getPost$1(comment.data.referenceId);
|
|
20924
|
-
|
|
20925
|
-
fireEvent('post.updated', {
|
|
20919
|
+
fireEvent('local.post.updated', {
|
|
20926
20920
|
posts: [post.data],
|
|
20927
20921
|
categories: [],
|
|
20928
20922
|
comments: [],
|
|
@@ -20934,8 +20928,7 @@ const deleteComment = async (commentId, permanent = false) => {
|
|
|
20934
20928
|
users: [],
|
|
20935
20929
|
});
|
|
20936
20930
|
}
|
|
20937
|
-
|
|
20938
|
-
fireEvent('comment.deleted', {
|
|
20931
|
+
fireEvent('local.comment.deleted', {
|
|
20939
20932
|
comments: [deleted],
|
|
20940
20933
|
commentChildren: [],
|
|
20941
20934
|
files: [],
|
|
@@ -21404,7 +21397,7 @@ const getComments = (params, callback, config) => {
|
|
|
21404
21397
|
};
|
|
21405
21398
|
/* end_public_function */
|
|
21406
21399
|
|
|
21407
|
-
var index$
|
|
21400
|
+
var index$5 = /*#__PURE__*/Object.freeze({
|
|
21408
21401
|
__proto__: null,
|
|
21409
21402
|
getCommentByIds: getCommentByIds,
|
|
21410
21403
|
createComment: createComment,
|
|
@@ -21428,6 +21421,324 @@ var index$4 = /*#__PURE__*/Object.freeze({
|
|
|
21428
21421
|
getComments: getComments
|
|
21429
21422
|
});
|
|
21430
21423
|
|
|
21424
|
+
/* begin_public_function
|
|
21425
|
+
id: post.get
|
|
21426
|
+
*/
|
|
21427
|
+
/**
|
|
21428
|
+
* ```js
|
|
21429
|
+
* import { PostRepository } from '@amityco/ts-sdk';
|
|
21430
|
+
*
|
|
21431
|
+
* let post;
|
|
21432
|
+
*
|
|
21433
|
+
* const unsub = PostRepository.getPost(postId, response => {
|
|
21434
|
+
* post = response.data;
|
|
21435
|
+
* });
|
|
21436
|
+
* ```
|
|
21437
|
+
*
|
|
21438
|
+
* Observe all mutation on a given {@link Amity.Post}
|
|
21439
|
+
*
|
|
21440
|
+
* @param postId the ID of the message to observe
|
|
21441
|
+
* @param callback the function to call when new data are available
|
|
21442
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the sub channel
|
|
21443
|
+
*
|
|
21444
|
+
* @category Post Live Object
|
|
21445
|
+
*/
|
|
21446
|
+
const getPost = (postId, callback) => {
|
|
21447
|
+
return liveObject(postId, callback, 'postId', getPost$1, [
|
|
21448
|
+
onPostApproved,
|
|
21449
|
+
onPostDeclined,
|
|
21450
|
+
(callback) => {
|
|
21451
|
+
return onPostDeleted((post) => {
|
|
21452
|
+
var _a;
|
|
21453
|
+
let targetPost = post;
|
|
21454
|
+
// check if the deleted post is a child of the target post
|
|
21455
|
+
if (post.parentPostId === postId && post.isDeleted) {
|
|
21456
|
+
const parentPost = (_a = pullFromCache([
|
|
21457
|
+
'post',
|
|
21458
|
+
'get',
|
|
21459
|
+
post.parentPostId,
|
|
21460
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21461
|
+
if (parentPost) {
|
|
21462
|
+
parentPost.children = parentPost.children.filter(childId => childId !== post.postId);
|
|
21463
|
+
pushToCache(['post', 'get', parentPost.postId], parentPost);
|
|
21464
|
+
// if the deleted post is a child of the target post, then the target post is the parent post
|
|
21465
|
+
targetPost = parentPost;
|
|
21466
|
+
}
|
|
21467
|
+
}
|
|
21468
|
+
callback(targetPost);
|
|
21469
|
+
});
|
|
21470
|
+
},
|
|
21471
|
+
onPostFlagged,
|
|
21472
|
+
(callback) => {
|
|
21473
|
+
return onPostReactionAdded((post) => {
|
|
21474
|
+
callback(LinkedObject.post(post));
|
|
21475
|
+
});
|
|
21476
|
+
},
|
|
21477
|
+
(callback) => {
|
|
21478
|
+
return onPostReactionRemoved((post) => {
|
|
21479
|
+
callback(LinkedObject.post(post));
|
|
21480
|
+
});
|
|
21481
|
+
},
|
|
21482
|
+
onPostUnflagged,
|
|
21483
|
+
onPostUpdated,
|
|
21484
|
+
convertEventPayload((callback) => {
|
|
21485
|
+
return onCommentCreated(async (comment) => {
|
|
21486
|
+
if (comment.referenceId === postId) {
|
|
21487
|
+
await getPost$1(postId);
|
|
21488
|
+
callback(comment);
|
|
21489
|
+
}
|
|
21490
|
+
});
|
|
21491
|
+
}, 'referenceId', 'post'),
|
|
21492
|
+
convertEventPayload((callback) => {
|
|
21493
|
+
return onCommentDeleted(async (comment) => {
|
|
21494
|
+
if (comment.referenceId === postId) {
|
|
21495
|
+
await getPost$1(postId);
|
|
21496
|
+
callback(comment);
|
|
21497
|
+
}
|
|
21498
|
+
});
|
|
21499
|
+
}, 'referenceId', 'post'),
|
|
21500
|
+
]);
|
|
21501
|
+
};
|
|
21502
|
+
/* end_public_function */
|
|
21503
|
+
|
|
21504
|
+
/**
|
|
21505
|
+
* ```js
|
|
21506
|
+
* import { queryPosts } from '@amityco/ts-sdk'
|
|
21507
|
+
* const { data: posts, prevPage, nextPage } = await queryPosts({ targetId, targetType })
|
|
21508
|
+
* ```
|
|
21509
|
+
*
|
|
21510
|
+
* Queries a paginable list of {@link Amity.Post} objects
|
|
21511
|
+
*
|
|
21512
|
+
* @param query The query parameters
|
|
21513
|
+
* @returns posts
|
|
21514
|
+
*
|
|
21515
|
+
* @category Post API
|
|
21516
|
+
* @async
|
|
21517
|
+
*/
|
|
21518
|
+
const queryPosts = async (query) => {
|
|
21519
|
+
const client = getActiveClient();
|
|
21520
|
+
client.log('post/queryPosts', query);
|
|
21521
|
+
const { page, limit = 10, includeDeleted } = query, params = __rest(query, ["page", "limit", "includeDeleted"]);
|
|
21522
|
+
const { dataTypes, matchingOnlyParentPost } = params;
|
|
21523
|
+
const options = (() => {
|
|
21524
|
+
if (page)
|
|
21525
|
+
return { token: page };
|
|
21526
|
+
if (limit)
|
|
21527
|
+
return { limit };
|
|
21528
|
+
return undefined;
|
|
21529
|
+
})();
|
|
21530
|
+
// API-FIX: parameters should be querystring. (1)
|
|
21531
|
+
// API-FIX: backend should answer Amity.Response (2)
|
|
21532
|
+
// const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<Amity.PostPayload>>>(
|
|
21533
|
+
const { data } = await client.http.get(`/api/v4/posts`, {
|
|
21534
|
+
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted),
|
|
21535
|
+
/*
|
|
21536
|
+
* when creating post like image, file, video BE will create 2 posts
|
|
21537
|
+
* 1. parent post to store text with dataType=text
|
|
21538
|
+
* 2. child post to store dataTypes post data
|
|
21539
|
+
*
|
|
21540
|
+
* By default, BE queries only parent post
|
|
21541
|
+
*/
|
|
21542
|
+
matchingOnlyParentPost: matchingOnlyParentPost !== null && matchingOnlyParentPost !== void 0 ? matchingOnlyParentPost : !(dataTypes === null || dataTypes === void 0 ? void 0 : dataTypes.length), options }),
|
|
21543
|
+
});
|
|
21544
|
+
// API-FIX: backend should answer Amity.Response (2)
|
|
21545
|
+
// const { paging, posts } = unwrapPayload(data)
|
|
21546
|
+
// unpacking
|
|
21547
|
+
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
21548
|
+
const paperedPayload = prepareMembershipPayload(payload, 'communityUsers');
|
|
21549
|
+
const { posts } = payload;
|
|
21550
|
+
const cachedAt = client.cache && Date.now();
|
|
21551
|
+
if (client.cache) {
|
|
21552
|
+
ingestInCache(paperedPayload, { cachedAt });
|
|
21553
|
+
const cacheKey = ['post', 'query', Object.assign(Object.assign({}, params), { options })];
|
|
21554
|
+
pushToCache(cacheKey, { posts: posts.map(getResolver('post')), paging });
|
|
21555
|
+
}
|
|
21556
|
+
return { data: posts.map(LinkedObject.post), cachedAt, paging };
|
|
21557
|
+
};
|
|
21558
|
+
|
|
21559
|
+
/* begin_public_function
|
|
21560
|
+
id: post.query
|
|
21561
|
+
*/
|
|
21562
|
+
/**
|
|
21563
|
+
* ```js
|
|
21564
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
21565
|
+
*
|
|
21566
|
+
* let posts = []
|
|
21567
|
+
* const unsub = PostRepository.getPosts({
|
|
21568
|
+
* targetType: Amity.PostTargetType,
|
|
21569
|
+
* targetId: Amity.Post['targetId'],
|
|
21570
|
+
* }, response => merge(posts, response.data))
|
|
21571
|
+
* ```
|
|
21572
|
+
*
|
|
21573
|
+
* Observe all mutations on a list of {@link Amity.Post} for a given target object
|
|
21574
|
+
*
|
|
21575
|
+
* @param params.targetType the type of the target
|
|
21576
|
+
* @param params.targetId the ID of the target
|
|
21577
|
+
* @param callback the function to call when new data are available
|
|
21578
|
+
* @param config
|
|
21579
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
21580
|
+
*
|
|
21581
|
+
* @category Posts Live Collection
|
|
21582
|
+
*/
|
|
21583
|
+
const getPosts = (params, callback, config) => {
|
|
21584
|
+
const { log, cache } = getActiveClient();
|
|
21585
|
+
if (!cache) {
|
|
21586
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
21587
|
+
}
|
|
21588
|
+
const timestamp = Date.now();
|
|
21589
|
+
log(`getPosts(tmpid: ${timestamp}) > listen`);
|
|
21590
|
+
const { limit: queryLimit } = params, queryParams = __rest(params, ["limit"]);
|
|
21591
|
+
const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
|
|
21592
|
+
const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
|
|
21593
|
+
const disposers = [];
|
|
21594
|
+
const cacheKey = [
|
|
21595
|
+
'post',
|
|
21596
|
+
'collection',
|
|
21597
|
+
{ targetId: params.targetId, targetType: params.targetType },
|
|
21598
|
+
];
|
|
21599
|
+
const responder = (data) => {
|
|
21600
|
+
var _a, _b, _c;
|
|
21601
|
+
let posts = (_a = data.data
|
|
21602
|
+
.map(postId => pullFromCache(['post', 'get', postId]))
|
|
21603
|
+
.filter(Boolean)
|
|
21604
|
+
.map(({ data }) => LinkedObject.post(data))) !== null && _a !== void 0 ? _a : [];
|
|
21605
|
+
const sortBy = params.sortBy ? params.sortBy : 'lastCreated';
|
|
21606
|
+
posts = posts.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
21607
|
+
if (!params.includeDeleted) {
|
|
21608
|
+
posts = filterByPropEquality(posts, 'isDeleted', false);
|
|
21609
|
+
}
|
|
21610
|
+
if (params.tags) {
|
|
21611
|
+
posts = posts.filter(p => { var _a; return (_a = p.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); }); });
|
|
21612
|
+
}
|
|
21613
|
+
if (params.targetType === 'community' && params.feedType) {
|
|
21614
|
+
posts = filterByFeedType(posts, params.feedType);
|
|
21615
|
+
}
|
|
21616
|
+
if ((_b = params.dataTypes) === null || _b === void 0 ? void 0 : _b.length) {
|
|
21617
|
+
posts = filterByPostDataTypes(posts, params.dataTypes);
|
|
21618
|
+
}
|
|
21619
|
+
callback({
|
|
21620
|
+
onNextPage: onFetch,
|
|
21621
|
+
data: posts,
|
|
21622
|
+
hasNextPage: !!((_c = data.params) === null || _c === void 0 ? void 0 : _c.page),
|
|
21623
|
+
loading: data.loading,
|
|
21624
|
+
error: data.error,
|
|
21625
|
+
});
|
|
21626
|
+
};
|
|
21627
|
+
const realtimeRouter = (action) => (post) => {
|
|
21628
|
+
var _a, _b;
|
|
21629
|
+
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
21630
|
+
if (!collection)
|
|
21631
|
+
return;
|
|
21632
|
+
if (post.parentPostId && post.isDeleted) {
|
|
21633
|
+
const parentPost = (_b = pullFromCache([
|
|
21634
|
+
'post',
|
|
21635
|
+
'get',
|
|
21636
|
+
post.parentPostId,
|
|
21637
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
21638
|
+
if (!parentPost || (parentPost === null || parentPost === void 0 ? void 0 : parentPost.targetId) !== params.targetId)
|
|
21639
|
+
return;
|
|
21640
|
+
parentPost.children = parentPost.children.filter(childId => childId !== post.postId);
|
|
21641
|
+
pushToCache(['post', 'get', parentPost.postId], parentPost);
|
|
21642
|
+
}
|
|
21643
|
+
else {
|
|
21644
|
+
if (params.targetId !== post.targetId)
|
|
21645
|
+
return;
|
|
21646
|
+
if (params.targetType !== post.targetType)
|
|
21647
|
+
return;
|
|
21648
|
+
}
|
|
21649
|
+
/*
|
|
21650
|
+
* This is not ideal, but currently this is the only way to update the
|
|
21651
|
+
* collection on post declined
|
|
21652
|
+
*/
|
|
21653
|
+
if (action === 'onDeclined') {
|
|
21654
|
+
collection.data = collection.data.filter(postId => postId !== post.postId);
|
|
21655
|
+
}
|
|
21656
|
+
else {
|
|
21657
|
+
collection.data = [...new Set([post.postId, ...collection.data])];
|
|
21658
|
+
}
|
|
21659
|
+
pushToCache(cacheKey, collection);
|
|
21660
|
+
responder(collection);
|
|
21661
|
+
};
|
|
21662
|
+
const onFetch = (initial = false) => {
|
|
21663
|
+
var _a, _b, _c;
|
|
21664
|
+
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
21665
|
+
const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
21666
|
+
if (!initial && posts.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
|
|
21667
|
+
return;
|
|
21668
|
+
const query = createQuery(queryPosts, Object.assign(Object.assign({}, queryParams), { limit: initial ? limit : undefined, page: !initial ? collection === null || collection === void 0 ? void 0 : collection.params.page : undefined }));
|
|
21669
|
+
runQuery(query, ({ data: result, error, loading, paging }) => {
|
|
21670
|
+
const data = {
|
|
21671
|
+
loading,
|
|
21672
|
+
error,
|
|
21673
|
+
params: { page: paging === null || paging === void 0 ? void 0 : paging.next },
|
|
21674
|
+
data: posts,
|
|
21675
|
+
};
|
|
21676
|
+
if (result) {
|
|
21677
|
+
data.data = initial
|
|
21678
|
+
? result.map(getResolver('post'))
|
|
21679
|
+
: [...new Set([...posts, ...result.map(getResolver('post'))])];
|
|
21680
|
+
}
|
|
21681
|
+
pushToCache(cacheKey, data);
|
|
21682
|
+
responder(data);
|
|
21683
|
+
}, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
|
|
21684
|
+
};
|
|
21685
|
+
disposers.push(onPostCreated(realtimeRouter('onCreate')), onPostApproved(realtimeRouter('onApproved')), onPostDeclined(realtimeRouter('onDeclined')), onPostDeleted(realtimeRouter('onDelete')), onPostUpdated(realtimeRouter('onUpdate')), onPostFlagged(realtimeRouter('onFlagged')), onPostUnflagged(realtimeRouter('onUnflagged')), onPostReactionAdded(realtimeRouter('onReactionAdded')), onPostReactionRemoved(realtimeRouter('onReactionRemoved')), convertEventPayload((callback) => {
|
|
21686
|
+
return onCommentCreated(async (comment) => {
|
|
21687
|
+
var _a;
|
|
21688
|
+
const currentCollection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
21689
|
+
if (!currentCollection || currentCollection.data.includes(comment.referenceId))
|
|
21690
|
+
return;
|
|
21691
|
+
await getPost$1(comment.referenceId);
|
|
21692
|
+
callback(comment);
|
|
21693
|
+
});
|
|
21694
|
+
}, 'referenceId', 'post')(realtimeRouter('onUpdate')), convertEventPayload((callback) => {
|
|
21695
|
+
return onCommentDeleted(async (comment) => {
|
|
21696
|
+
var _a;
|
|
21697
|
+
const currentCollection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
21698
|
+
if (!currentCollection || currentCollection.data.includes(comment.referenceId))
|
|
21699
|
+
return;
|
|
21700
|
+
await getPost$1(comment.referenceId);
|
|
21701
|
+
callback(comment);
|
|
21702
|
+
});
|
|
21703
|
+
}, 'referenceId', 'post')(realtimeRouter('onUpdate')));
|
|
21704
|
+
onFetch(true);
|
|
21705
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
21706
|
+
return () => {
|
|
21707
|
+
log(`getPosts(tmpid: ${timestamp}) > dispose`);
|
|
21708
|
+
disposers.forEach(fn => fn());
|
|
21709
|
+
};
|
|
21710
|
+
};
|
|
21711
|
+
/* end_public_function */
|
|
21712
|
+
|
|
21713
|
+
var index$4 = /*#__PURE__*/Object.freeze({
|
|
21714
|
+
__proto__: null,
|
|
21715
|
+
getPostByIds: getPostByIds,
|
|
21716
|
+
createPost: createPost,
|
|
21717
|
+
updatePost: updatePost,
|
|
21718
|
+
editPost: editPost,
|
|
21719
|
+
deletePost: deletePost,
|
|
21720
|
+
softDeletePost: softDeletePost,
|
|
21721
|
+
hardDeletePost: hardDeletePost,
|
|
21722
|
+
approvePost: approvePost,
|
|
21723
|
+
declinePost: declinePost,
|
|
21724
|
+
flagPost: flagPost,
|
|
21725
|
+
unflagPost: unflagPost,
|
|
21726
|
+
isPostFlaggedByMe: isPostFlaggedByMe,
|
|
21727
|
+
onPostCreated: onPostCreated,
|
|
21728
|
+
onPostUpdated: onPostUpdated,
|
|
21729
|
+
onPostDeleted: onPostDeleted,
|
|
21730
|
+
onPostApproved: onPostApproved,
|
|
21731
|
+
onPostDeclined: onPostDeclined,
|
|
21732
|
+
onPostFlagged: onPostFlagged,
|
|
21733
|
+
onPostUnflagged: onPostUnflagged,
|
|
21734
|
+
onPostReactionAdded: onPostReactionAdded,
|
|
21735
|
+
onPostReactionRemoved: onPostReactionRemoved,
|
|
21736
|
+
observePosts: observePosts,
|
|
21737
|
+
observePost: observePost,
|
|
21738
|
+
getPost: getPost,
|
|
21739
|
+
getPosts: getPosts
|
|
21740
|
+
});
|
|
21741
|
+
|
|
21431
21742
|
/* begin_public_function
|
|
21432
21743
|
id: stream.create
|
|
21433
21744
|
*/
|
|
@@ -22257,7 +22568,7 @@ var index$2 = /*#__PURE__*/Object.freeze({
|
|
|
22257
22568
|
getPoll: getPoll
|
|
22258
22569
|
});
|
|
22259
22570
|
|
|
22260
|
-
const privateKey = "-----BEGIN PRIVATE KEY-----\
|
|
22571
|
+
const privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDAARz+hmBgi8pJ\nQb8LeY41gtHhk+ACMwRfhsn7GqpqRQNG2qU0755mzZuVDUqjQMGSo8THJB7O+OJs\nflbZRkFXlFoFOVNw1UpNOgwEQZ6wB9oRwzepTJAfF1sVhm/o/ixvXh1zDFNDy6yZ\npXyiiJHUVxqyjllZhxnwdvjoVtDs6hW6awG09bB9nh/TTejlUKXoAgzqVwu/1QMu\nUVViET495elEe19aUarEy+oL2iKeXCEvqda/pWNBdbieFyJvvZ08HN8dPuT88wq2\njZLEAth1vrwQ2IAa4ktaLcBQdLJgIkrbDvAiVZ8lQAjS/bq5vXQikTGvoPlC5bbn\nvuOM/3eLAgMBAAECggEAVZ+peHAghq2QVj71nX5lxsNCKaCyYwixSJBpfouTt7Rz\nE6PpzMOXFi1W1o+I22jDakuSM2SOQKqI/u0QefB0r0O/KVk5NrZHXk0mkrdYtxOp\nUgaGyf8UvmjB+8VqHrNKyZdk9qtmbnNj01kTTcAtmE4H39zPR7eR/8Rul94vaZbs\nwCnKJS3mLT3JxyGug6lxanveKkjG+CKC1nJQYWaxCJxaFSzbwXQPvDhB+TvrIbee\npd5v4EAyEJohpr+T9oDGGJkb/KARBZCtwLyB976PKJwwBA8MRVL1i5QwawuMiMq5\nUtnOnbGKtCeFzaLbNU0Qi8bqyims84EQxC6DOu1fkQKBgQDdvsoBsEhsOXV7hlIJ\naEd0eSJZVkdqimxH8uGoMM2FeNaOrcB6yBXqTSP0R3OIyf8eaY6yjRvP30ZNXcll\n/gD3O1Mu6YmWQdt1W2WA6pKOsUuPXasf0pdOF7IiFZKlSabz5YHXFqwVuqm8loaj\nsXel3YWqPVdHiankE7tz+3ssnQKBgQDdqi4TNdD1MdEpihx19jr0QjUiXW3939FK\nqp30HESPEGDGQzXdmJgif9HhZb+cJSuWaHEbjgBrYahvgCF+y6LbEpOD+D/dmT+s\nDEAQaR84sah6dokwPjV8fjBSrcVFjCS+doxv0d3p/9OUEeyUhFrY03nxtIEYkLIE\n/Zvn37b4RwKBgQCLENVFe9XfsaVhQ5r9dV2iyTlmh7qgMZG5CbTFs12hQGhm8McO\n+Z7s41YSJCFr/yq1WwP4LJDtrBw99vyQr1zRsG35tNLp3gGRNzGQSQyC2uQFVHw2\np+7mNewsfhUK/gbrXNsyFnDz6635rPlhfbII3sWuP2wWXFqkxE9CbMwR7QKBgQC6\nawDMzxmo2/iYArrkyevSuEuPVxvFwpF1RgAI6C0QVCnPE38dmdN4UB7mfHekje4W\nVEercMURidPp0cxZolCYBQtilUjAyL0vqC3In1/Ogjq6oy3FEMxSop1pKxMY5j+Q\nnoqFD+6deLUrddeNH7J3X4LSr4dSbX4JjG+tlgt+yQKBgQCuwTL4hA6KqeInQ0Ta\n9VQX5Qr8hFlqJz1gpymi/k63tW/Ob8yedbg3WWNWyShwRMFYyY9S81ITFWM95uL6\nvF3x9rmRjwElJw9PMwVu6dmf/CO0Z1wzXSp2VVD12gbrUD/0/d7MUoJ9LgC8X8f/\nn0txLHYGHbx+nf95+JUg6lV3hg==\n-----END PRIVATE KEY-----";
|
|
22261
22572
|
/*
|
|
22262
22573
|
* The crypto algorithm used for importing key and signing string
|
|
22263
22574
|
*/
|
|
@@ -23402,7 +23713,7 @@ class StoryLiveCollectionController extends LiveCollectionController {
|
|
|
23402
23713
|
this.queryStreamController = new StoryQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), paginationController);
|
|
23403
23714
|
this.paginationController = paginationController;
|
|
23404
23715
|
this.callback = callback.bind(this);
|
|
23405
|
-
this.loadPage(true);
|
|
23716
|
+
this.loadPage({ initial: true });
|
|
23406
23717
|
}
|
|
23407
23718
|
setup() {
|
|
23408
23719
|
var _a;
|
|
@@ -23584,7 +23895,7 @@ class GlobalStoryLiveCollectionController extends LiveCollectionController {
|
|
|
23584
23895
|
this.queryStreamController = new GlobalStoryQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), paginationController);
|
|
23585
23896
|
this.paginationController = paginationController;
|
|
23586
23897
|
this.callback = callback.bind(this);
|
|
23587
|
-
this.loadPage(true);
|
|
23898
|
+
this.loadPage({ initial: true });
|
|
23588
23899
|
}
|
|
23589
23900
|
setup() {
|
|
23590
23901
|
var _a;
|
|
@@ -23620,7 +23931,7 @@ class GlobalStoryLiveCollectionController extends LiveCollectionController {
|
|
|
23620
23931
|
return rest;
|
|
23621
23932
|
});
|
|
23622
23933
|
this.callback({
|
|
23623
|
-
onNextPage: () => this.loadPage(
|
|
23934
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
23624
23935
|
data,
|
|
23625
23936
|
hasNextPage: !!this.paginationController.getNextToken(),
|
|
23626
23937
|
loading,
|
|
@@ -23730,7 +24041,7 @@ exports.API_REGIONS = API_REGIONS;
|
|
|
23730
24041
|
exports.CategoryRepository = index$7;
|
|
23731
24042
|
exports.ChannelRepository = index$b;
|
|
23732
24043
|
exports.Client = index$k;
|
|
23733
|
-
exports.CommentRepository = index$
|
|
24044
|
+
exports.CommentRepository = index$5;
|
|
23734
24045
|
exports.CommunityPostSettingMaps = CommunityPostSettingMaps;
|
|
23735
24046
|
exports.CommunityPostSettings = CommunityPostSettings;
|
|
23736
24047
|
exports.CommunityRepository = index$8;
|
|
@@ -23744,7 +24055,7 @@ exports.MessageContentType = MessageContentType;
|
|
|
23744
24055
|
exports.MessageRepository = index$f;
|
|
23745
24056
|
exports.PollRepository = index$2;
|
|
23746
24057
|
exports.PostContentType = PostContentType;
|
|
23747
|
-
exports.PostRepository = index$
|
|
24058
|
+
exports.PostRepository = index$4;
|
|
23748
24059
|
exports.ReactionRepository = index$g;
|
|
23749
24060
|
exports.StoryRepository = index;
|
|
23750
24061
|
exports.StreamRepository = index$3;
|