@amityco/ts-sdk-react-native 6.23.0 → 6.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@types/core/events.d.ts +5 -0
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/domains/community.d.ts +15 -0
- 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/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/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 +582 -334
- package/dist/index.esm.js +573 -325
- 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/package.json +1 -1
- package/src/@types/core/events.ts +8 -0
- package/src/@types/domains/community.ts +25 -0
- 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/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/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/dist/index.esm.js
CHANGED
|
@@ -83,8 +83,8 @@ const PostContentType = Object.freeze({
|
|
|
83
83
|
|
|
84
84
|
function getVersion() {
|
|
85
85
|
try {
|
|
86
|
-
// the string ''v6.
|
|
87
|
-
return 'v6.
|
|
86
|
+
// the string ''v6.24.0-esm'' should be replaced by actual value by @rollup/plugin-replace
|
|
87
|
+
return 'v6.24.0-esm';
|
|
88
88
|
}
|
|
89
89
|
catch (error) {
|
|
90
90
|
return '__dev__';
|
|
@@ -21499,7 +21499,7 @@ const markAsReadBySegment = async ({ subChannelId, readToSegment, }) => {
|
|
|
21499
21499
|
}
|
|
21500
21500
|
};
|
|
21501
21501
|
|
|
21502
|
-
const reCalculateChannelUnreadInfo =
|
|
21502
|
+
const reCalculateChannelUnreadInfo = (channelId) => {
|
|
21503
21503
|
var _a;
|
|
21504
21504
|
const cacheKeyChannelUnread = ['channelUnreadInfo', 'get', channelId];
|
|
21505
21505
|
const cacheChannelUnreadInfo = (_a = pullFromCache(cacheKeyChannelUnread)) === null || _a === void 0 ? void 0 : _a.data;
|
|
@@ -21516,10 +21516,12 @@ const reCalculateChannelUnreadInfo = async (channelId) => {
|
|
|
21516
21516
|
.reduce((acc, cur) => acc + cur, 0);
|
|
21517
21517
|
isMentioned = subChannelUnreadsInfo.some(({ data }) => data.isMentioned);
|
|
21518
21518
|
}
|
|
21519
|
-
|
|
21519
|
+
const channelUnreadInfo = Object.assign(Object.assign({}, (cacheChannelUnreadInfo !== null && cacheChannelUnreadInfo !== void 0 ? cacheChannelUnreadInfo : {
|
|
21520
21520
|
channelId,
|
|
21521
21521
|
createdAt: new Date().toISOString(),
|
|
21522
|
-
})), { updatedAt: new Date().toISOString(), unreadCount: channelUnreads, isMentioned })
|
|
21522
|
+
})), { updatedAt: new Date().toISOString(), unreadCount: channelUnreads, isMentioned });
|
|
21523
|
+
pushToCache(cacheKeyChannelUnread, channelUnreadInfo);
|
|
21524
|
+
return channelUnreadInfo;
|
|
21523
21525
|
};
|
|
21524
21526
|
|
|
21525
21527
|
class MessageReadReceiptSyncEngine {
|
|
@@ -21664,9 +21666,11 @@ class MessageReadReceiptSyncEngine {
|
|
|
21664
21666
|
if (subChannelUnreadInfo && segment > subChannelUnreadInfo.readToSegment) {
|
|
21665
21667
|
subChannelUnreadInfo.readToSegment = segment;
|
|
21666
21668
|
subChannelUnreadInfo.unreadCount = Math.max(subChannelUnreadInfo.lastSegment - segment, 0);
|
|
21667
|
-
reCalculateChannelUnreadInfo(subChannelUnreadInfo.channelId);
|
|
21669
|
+
const channelUnreadInfo = reCalculateChannelUnreadInfo(subChannelUnreadInfo.channelId);
|
|
21670
|
+
fireEvent('local.channelUnread.updated', channelUnreadInfo);
|
|
21671
|
+
pushToCache(cacheKey, subChannelUnreadInfo);
|
|
21672
|
+
fireEvent('local.subChannelUnread.updated', subChannelUnreadInfo);
|
|
21668
21673
|
}
|
|
21669
|
-
pushToCache(cacheKey, subChannelUnreadInfo);
|
|
21670
21674
|
// Step 2: Enqueue the read receipt
|
|
21671
21675
|
this.enqueueReadReceipt(subChannelId, segment);
|
|
21672
21676
|
}
|
|
@@ -24661,9 +24665,9 @@ const enableUnreadCount = () => {
|
|
|
24661
24665
|
const onUserFeedMarkerUpdated = (callback) => {
|
|
24662
24666
|
const client = getActiveClient();
|
|
24663
24667
|
const filter = (payload) => {
|
|
24664
|
-
|
|
24665
|
-
|
|
24666
|
-
|
|
24668
|
+
payload.feedMarkers.forEach(feedMarker => {
|
|
24669
|
+
callback(feedMarker);
|
|
24670
|
+
});
|
|
24667
24671
|
};
|
|
24668
24672
|
return createEventSubscriber(client, 'feedMarker/onUserFeedMarkerUpdated', 'marker.userFeed-updated', filter);
|
|
24669
24673
|
};
|
|
@@ -25259,7 +25263,7 @@ const onChannelMarkerFetched = (callback) => {
|
|
|
25259
25263
|
const onSubChannelMarkerFetched = (callback) => {
|
|
25260
25264
|
const client = getActiveClient();
|
|
25261
25265
|
const filter = (payload) => {
|
|
25262
|
-
|
|
25266
|
+
payload.userFeedMarkers.forEach(callback);
|
|
25263
25267
|
};
|
|
25264
25268
|
return createEventSubscriber(client, 'subChannelMarker/onSubChannelMarkerFetched', 'local.subChannelMarker.fetched', filter);
|
|
25265
25269
|
};
|
|
@@ -31514,7 +31518,7 @@ class LiveCollectionController {
|
|
|
31514
31518
|
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
31515
31519
|
}
|
|
31516
31520
|
}
|
|
31517
|
-
loadPage(initial = false, direction = "next" /* Amity.LiveCollectionPageDirection.NEXT
|
|
31521
|
+
loadPage({ initial = false, direction = "next" /* Amity.LiveCollectionPageDirection.NEXT */, }) {
|
|
31518
31522
|
this.setup();
|
|
31519
31523
|
this.notifyChange({ origin: "local" /* Amity.LiveDataOrigin.LOCAL */, loading: true });
|
|
31520
31524
|
if (initial) {
|
|
@@ -31584,7 +31588,7 @@ class MessageLiveCollectionController extends LiveCollectionController {
|
|
|
31584
31588
|
this.query = query;
|
|
31585
31589
|
this.queryStreamController = new MessageQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareMessagePayload, this.paginationController);
|
|
31586
31590
|
this.callback = callback.bind(this);
|
|
31587
|
-
this.loadPage(true);
|
|
31591
|
+
this.loadPage({ initial: true });
|
|
31588
31592
|
}
|
|
31589
31593
|
setup() {
|
|
31590
31594
|
var _a;
|
|
@@ -31632,8 +31636,8 @@ class MessageLiveCollectionController extends LiveCollectionController {
|
|
|
31632
31636
|
if (!this.shouldNotify(data) && origin === 'event')
|
|
31633
31637
|
return;
|
|
31634
31638
|
this.callback({
|
|
31635
|
-
onNextPage: () => this.loadPage(
|
|
31636
|
-
onPrevPage: () => this.loadPage(
|
|
31639
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
31640
|
+
onPrevPage: () => this.loadPage({ direction: "prev" /* Amity.LiveCollectionPageDirection.PREV */ }),
|
|
31637
31641
|
data,
|
|
31638
31642
|
hasNextPage: !!this.paginationController.getNextToken(),
|
|
31639
31643
|
hasPrevPage: !!this.paginationController.getPrevToken(),
|
|
@@ -31915,6 +31919,24 @@ var index$f = /*#__PURE__*/Object.freeze({
|
|
|
31915
31919
|
convertQueryParams: convertQueryParams$1
|
|
31916
31920
|
});
|
|
31917
31921
|
|
|
31922
|
+
/**
|
|
31923
|
+
* Internal used only
|
|
31924
|
+
*
|
|
31925
|
+
* Fired when an {@link Amity.userMessageFeedMarkers} has been resolved by Object Rsesolver
|
|
31926
|
+
*
|
|
31927
|
+
* @param callback The function to call when the event was fired
|
|
31928
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
31929
|
+
*
|
|
31930
|
+
* @category MessageMarker Events
|
|
31931
|
+
*/
|
|
31932
|
+
const onSubChannelUnreadUpdatedLocal = (callback) => {
|
|
31933
|
+
const client = getActiveClient();
|
|
31934
|
+
const filter = (payload) => {
|
|
31935
|
+
callback(payload);
|
|
31936
|
+
};
|
|
31937
|
+
return createEventSubscriber(client, 'subChannelMarker/onSubChannelUnreadUpdatedLocal', 'local.subChannelUnread.updated', filter);
|
|
31938
|
+
};
|
|
31939
|
+
|
|
31918
31940
|
/* begin_public_function
|
|
31919
31941
|
id: subchannel.get
|
|
31920
31942
|
*/
|
|
@@ -32067,7 +32089,7 @@ const getSubChannel = (subChannelId, callback) => {
|
|
|
32067
32089
|
};
|
|
32068
32090
|
return onMessageDeleted(updateMessagePreview);
|
|
32069
32091
|
}, 'subChannelId', 'subChannel'),
|
|
32070
|
-
convertEventPayload(
|
|
32092
|
+
convertEventPayload(onSubChannelUnreadUpdatedLocal, 'subChannelId', 'subChannel'),
|
|
32071
32093
|
], {
|
|
32072
32094
|
forceDispatch: true,
|
|
32073
32095
|
});
|
|
@@ -32157,7 +32179,7 @@ class SubChannelLiveCollectionController extends LiveCollectionController {
|
|
|
32157
32179
|
this.query = query;
|
|
32158
32180
|
this.queryStreamController = new SubChannelQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareSubChannelPayload);
|
|
32159
32181
|
this.callback = callback.bind(this);
|
|
32160
|
-
this.loadPage(true);
|
|
32182
|
+
this.loadPage({ initial: true });
|
|
32161
32183
|
}
|
|
32162
32184
|
setup() {
|
|
32163
32185
|
var _a;
|
|
@@ -32334,7 +32356,7 @@ class SubChannelLiveCollectionController extends LiveCollectionController {
|
|
|
32334
32356
|
action: 'onUpdate',
|
|
32335
32357
|
},
|
|
32336
32358
|
{
|
|
32337
|
-
fn: convertEventPayload(
|
|
32359
|
+
fn: convertEventPayload(onSubChannelUnreadUpdatedLocal, 'subChannelId', 'subChannel'),
|
|
32338
32360
|
action: 'onUpdate',
|
|
32339
32361
|
},
|
|
32340
32362
|
]);
|
|
@@ -32352,7 +32374,7 @@ class SubChannelLiveCollectionController extends LiveCollectionController {
|
|
|
32352
32374
|
if (!this.shouldNotify(data) && origin === 'event')
|
|
32353
32375
|
return;
|
|
32354
32376
|
this.callback({
|
|
32355
|
-
onNextPage: () => this.loadPage(
|
|
32377
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
32356
32378
|
data,
|
|
32357
32379
|
hasNextPage: !!this.paginationController.getNextToken(),
|
|
32358
32380
|
loading,
|
|
@@ -32492,6 +32514,24 @@ var index$e = /*#__PURE__*/Object.freeze({
|
|
|
32492
32514
|
stopMessageReceiptSync: stopMessageReceiptSync
|
|
32493
32515
|
});
|
|
32494
32516
|
|
|
32517
|
+
/**
|
|
32518
|
+
* Internal used only
|
|
32519
|
+
*
|
|
32520
|
+
* Fired when an {@link Amity.userMessageFeedMarkers} has been resolved by Object Rsesolver
|
|
32521
|
+
*
|
|
32522
|
+
* @param callback The function to call when the event was fired
|
|
32523
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
32524
|
+
*
|
|
32525
|
+
* @category MessageMarker Events
|
|
32526
|
+
*/
|
|
32527
|
+
const onChannelUnreadUpdatedLocal = (callback) => {
|
|
32528
|
+
const client = getActiveClient();
|
|
32529
|
+
const filter = (payload) => {
|
|
32530
|
+
callback(payload);
|
|
32531
|
+
};
|
|
32532
|
+
return createEventSubscriber(client, 'channelMarker/onChannelUnreadUpdatedLocal', 'local.channelUnread.updated', filter);
|
|
32533
|
+
};
|
|
32534
|
+
|
|
32495
32535
|
/* begin_public_function
|
|
32496
32536
|
id: channel.get
|
|
32497
32537
|
*/
|
|
@@ -32667,7 +32707,7 @@ const getChannel = (channelId, callback) => {
|
|
|
32667
32707
|
return onSubChannelUpdated(updateMessagePreview);
|
|
32668
32708
|
}, 'channelId', 'channel'),
|
|
32669
32709
|
convertEventPayload(onSubChannelCreated, 'channelId', 'channel'),
|
|
32670
|
-
convertEventPayload(
|
|
32710
|
+
convertEventPayload(onChannelUnreadUpdatedLocal, 'channelId', 'channel'),
|
|
32671
32711
|
], {
|
|
32672
32712
|
forceDispatch: true,
|
|
32673
32713
|
});
|
|
@@ -32827,7 +32867,7 @@ class ChannelLiveCollectionController extends LiveCollectionController {
|
|
|
32827
32867
|
}, paginationController);
|
|
32828
32868
|
this.paginationController = paginationController;
|
|
32829
32869
|
this.callback = callback.bind(this);
|
|
32830
|
-
this.loadPage(true);
|
|
32870
|
+
this.loadPage({ initial: true });
|
|
32831
32871
|
}
|
|
32832
32872
|
setup() {
|
|
32833
32873
|
var _a;
|
|
@@ -32866,7 +32906,7 @@ class ChannelLiveCollectionController extends LiveCollectionController {
|
|
|
32866
32906
|
return;
|
|
32867
32907
|
this.callback({
|
|
32868
32908
|
onNextPage: this.paginationController instanceof ChannelPaginationController
|
|
32869
|
-
? () => this.loadPage(
|
|
32909
|
+
? () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ })
|
|
32870
32910
|
: undefined,
|
|
32871
32911
|
data,
|
|
32872
32912
|
hasNextPage: this.paginationController instanceof ChannelPaginationController
|
|
@@ -33146,10 +33186,6 @@ class ChannelLiveCollectionController extends LiveCollectionController {
|
|
|
33146
33186
|
}, 'channelId', 'channel'),
|
|
33147
33187
|
action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
|
|
33148
33188
|
},
|
|
33149
|
-
{
|
|
33150
|
-
fn: convertEventPayload(onUserFeedMarkerUpdated, 'entityId', 'channel'),
|
|
33151
|
-
action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
|
|
33152
|
-
},
|
|
33153
33189
|
{
|
|
33154
33190
|
fn: convertEventPayload(onSubChannelCreated, 'channelId', 'channel'),
|
|
33155
33191
|
action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
|
|
@@ -33175,6 +33211,10 @@ class ChannelLiveCollectionController extends LiveCollectionController {
|
|
|
33175
33211
|
},
|
|
33176
33212
|
action: "onResolve" /* Amity.ChannelActionType.OnResolve */,
|
|
33177
33213
|
},
|
|
33214
|
+
{
|
|
33215
|
+
fn: convertEventPayload(onChannelUnreadUpdatedLocal, 'channelId', 'channel'),
|
|
33216
|
+
action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
|
|
33217
|
+
},
|
|
33178
33218
|
];
|
|
33179
33219
|
if (this.paginationController instanceof PaginationController) {
|
|
33180
33220
|
return [
|
|
@@ -33389,7 +33429,7 @@ class ChannelMemberLiveCollectionController extends LiveCollectionController {
|
|
|
33389
33429
|
this.query = query;
|
|
33390
33430
|
this.queryStreamController = new ChannelMemberQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareChannelPayload);
|
|
33391
33431
|
this.callback = callback.bind(this);
|
|
33392
|
-
this.loadPage(true);
|
|
33432
|
+
this.loadPage({ initial: true });
|
|
33393
33433
|
}
|
|
33394
33434
|
setup() {
|
|
33395
33435
|
var _a;
|
|
@@ -33431,7 +33471,7 @@ class ChannelMemberLiveCollectionController extends LiveCollectionController {
|
|
|
33431
33471
|
if (!this.shouldNotify(data) && origin === 'event')
|
|
33432
33472
|
return;
|
|
33433
33473
|
this.callback({
|
|
33434
|
-
onNextPage: () => this.loadPage(
|
|
33474
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
33435
33475
|
data,
|
|
33436
33476
|
hasNextPage: !!this.paginationController.getNextToken(),
|
|
33437
33477
|
loading,
|
|
@@ -34539,6 +34579,181 @@ const observeCommunity = (communityId, callback) => {
|
|
|
34539
34579
|
};
|
|
34540
34580
|
};
|
|
34541
34581
|
|
|
34582
|
+
/**
|
|
34583
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
34584
|
+
* TODO: check if querybyIds is supported
|
|
34585
|
+
*/
|
|
34586
|
+
class CommunitiesPaginationController extends PaginationController {
|
|
34587
|
+
async getRequest(queryParams, token) {
|
|
34588
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
34589
|
+
const options = token ? { token } : { limit };
|
|
34590
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/communities`, {
|
|
34591
|
+
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(params.includeDeleted), keyword: params.displayName, filter: params.membership, options }),
|
|
34592
|
+
});
|
|
34593
|
+
return queryResponse;
|
|
34594
|
+
}
|
|
34595
|
+
}
|
|
34596
|
+
|
|
34597
|
+
class CommunitiesQueryStreamController extends QueryStreamController {
|
|
34598
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
34599
|
+
super(query, cacheKey);
|
|
34600
|
+
this.notifyChange = notifyChange;
|
|
34601
|
+
this.preparePayload = preparePayload;
|
|
34602
|
+
}
|
|
34603
|
+
async saveToMainDB(response) {
|
|
34604
|
+
const processedPayload = await this.preparePayload(response);
|
|
34605
|
+
const client = getActiveClient();
|
|
34606
|
+
const cachedAt = client.cache && Date.now();
|
|
34607
|
+
if (client.cache) {
|
|
34608
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
34609
|
+
}
|
|
34610
|
+
}
|
|
34611
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
34612
|
+
var _a, _b;
|
|
34613
|
+
if (refresh) {
|
|
34614
|
+
pushToCache(this.cacheKey, {
|
|
34615
|
+
data: response.communities.map(getResolver('community')),
|
|
34616
|
+
});
|
|
34617
|
+
}
|
|
34618
|
+
else {
|
|
34619
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
34620
|
+
const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
34621
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...communities, ...response.communities.map(getResolver('community'))])] }));
|
|
34622
|
+
}
|
|
34623
|
+
}
|
|
34624
|
+
reactor(action) {
|
|
34625
|
+
return (community) => {
|
|
34626
|
+
var _a;
|
|
34627
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
34628
|
+
if (!collection)
|
|
34629
|
+
return;
|
|
34630
|
+
pushToCache(this.cacheKey, collection);
|
|
34631
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
34632
|
+
};
|
|
34633
|
+
}
|
|
34634
|
+
subscribeRTE(createSubscriber) {
|
|
34635
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
34636
|
+
}
|
|
34637
|
+
}
|
|
34638
|
+
|
|
34639
|
+
var EnumCommunityActions;
|
|
34640
|
+
(function (EnumCommunityActions) {
|
|
34641
|
+
EnumCommunityActions["OnCommunityCreated"] = "onCommunityCreated";
|
|
34642
|
+
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
34643
|
+
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
34644
|
+
})(EnumCommunityActions || (EnumCommunityActions = {}));
|
|
34645
|
+
|
|
34646
|
+
/* eslint-disable no-use-before-define */
|
|
34647
|
+
class SearchCommunityLiveCollectionController extends LiveCollectionController {
|
|
34648
|
+
constructor(query, callback) {
|
|
34649
|
+
const queryStreamId = hash(query);
|
|
34650
|
+
const cacheKey = ['community', 'collection', queryStreamId];
|
|
34651
|
+
const paginationController = new CommunitiesPaginationController(query);
|
|
34652
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
34653
|
+
this.query = query;
|
|
34654
|
+
this.queryStreamController = new CommunitiesQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityPayload);
|
|
34655
|
+
this.callback = callback.bind(this);
|
|
34656
|
+
this.loadPage({ initial: true });
|
|
34657
|
+
}
|
|
34658
|
+
setup() {
|
|
34659
|
+
var _a;
|
|
34660
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
34661
|
+
if (!collection) {
|
|
34662
|
+
pushToCache(this.cacheKey, {
|
|
34663
|
+
data: [],
|
|
34664
|
+
params: {},
|
|
34665
|
+
});
|
|
34666
|
+
}
|
|
34667
|
+
}
|
|
34668
|
+
async persistModel(queryPayload) {
|
|
34669
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
34670
|
+
}
|
|
34671
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
34672
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
34673
|
+
}
|
|
34674
|
+
startSubscription() {
|
|
34675
|
+
return this.queryStreamController.subscribeRTE([
|
|
34676
|
+
{ fn: onCommunityDeleted, action: EnumCommunityActions.OnCommunityDeleted },
|
|
34677
|
+
{ fn: onCommunityUpdated, action: EnumCommunityActions.OnCommunityUpdated },
|
|
34678
|
+
]);
|
|
34679
|
+
}
|
|
34680
|
+
notifyChange({ origin, loading, error }) {
|
|
34681
|
+
var _a, _b;
|
|
34682
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
34683
|
+
if (!collection)
|
|
34684
|
+
return;
|
|
34685
|
+
const data = this.applyFilter((_b = collection.data
|
|
34686
|
+
.map(id => pullFromCache(['community', 'get', id]))
|
|
34687
|
+
.filter(Boolean)
|
|
34688
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
|
|
34689
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
34690
|
+
return;
|
|
34691
|
+
this.callback({
|
|
34692
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
34693
|
+
data,
|
|
34694
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
34695
|
+
loading,
|
|
34696
|
+
error,
|
|
34697
|
+
});
|
|
34698
|
+
}
|
|
34699
|
+
applyFilter(data) {
|
|
34700
|
+
const { userId } = getActiveClient();
|
|
34701
|
+
let communities = data;
|
|
34702
|
+
if (this.query.includeDeleted) {
|
|
34703
|
+
communities = filterByPropEquality(communities, 'isDeleted', false);
|
|
34704
|
+
}
|
|
34705
|
+
if (this.query.categoryId) {
|
|
34706
|
+
communities = communities.filter(c => { var _a; return (_a = c.categoryIds) === null || _a === void 0 ? void 0 : _a.includes(this.query.categoryId); });
|
|
34707
|
+
}
|
|
34708
|
+
if (this.query.tags) {
|
|
34709
|
+
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); }); });
|
|
34710
|
+
}
|
|
34711
|
+
if (this.query.membership && userId) {
|
|
34712
|
+
communities = filterByCommunityMembership(communities, this.query.membership, userId);
|
|
34713
|
+
}
|
|
34714
|
+
return communities;
|
|
34715
|
+
}
|
|
34716
|
+
}
|
|
34717
|
+
|
|
34718
|
+
/* begin_public_function
|
|
34719
|
+
id: community.query
|
|
34720
|
+
*/
|
|
34721
|
+
/**
|
|
34722
|
+
* ```js
|
|
34723
|
+
* import { CommunityRepository } from '@amityco/ts-sdk'
|
|
34724
|
+
*
|
|
34725
|
+
* let communities = []
|
|
34726
|
+
* const unsub = CommunityRepository.searchCommunities({
|
|
34727
|
+
* displayName: Amity.Community['displayName'],
|
|
34728
|
+
* }, response => merge(communities, response.data))
|
|
34729
|
+
* ```
|
|
34730
|
+
*
|
|
34731
|
+
* Observe all mutations on a list of {@link Amity.Community}s
|
|
34732
|
+
*
|
|
34733
|
+
* @param params for querying communities
|
|
34734
|
+
* @param callback the function to call when new data are available
|
|
34735
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the communities
|
|
34736
|
+
*
|
|
34737
|
+
* @category Community Live Collection
|
|
34738
|
+
*/
|
|
34739
|
+
const searchCommunities = (params, callback, config) => {
|
|
34740
|
+
const { log, cache } = getActiveClient();
|
|
34741
|
+
if (!cache) {
|
|
34742
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
34743
|
+
}
|
|
34744
|
+
const timestamp = Date.now();
|
|
34745
|
+
log(`searchCommunities(tmpid: ${timestamp}) > listen`);
|
|
34746
|
+
const searchCommunitiesLiveCollection = new SearchCommunityLiveCollectionController(params, callback);
|
|
34747
|
+
const disposers = searchCommunitiesLiveCollection.startSubscription();
|
|
34748
|
+
const cacheKey = searchCommunitiesLiveCollection.getCacheKey();
|
|
34749
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
34750
|
+
return () => {
|
|
34751
|
+
log(`searchCommunities(tmpid: ${timestamp}) > dispose`);
|
|
34752
|
+
disposers.forEach(fn => fn());
|
|
34753
|
+
};
|
|
34754
|
+
};
|
|
34755
|
+
/* end_public_function */
|
|
34756
|
+
|
|
34542
34757
|
/**
|
|
34543
34758
|
* ```js
|
|
34544
34759
|
* import { queryCommunities } from '@amityco/ts-sdk-react-native'
|
|
@@ -35468,6 +35683,7 @@ var index$8 = /*#__PURE__*/Object.freeze({
|
|
|
35468
35683
|
onCommunityUpdated: onCommunityUpdated,
|
|
35469
35684
|
onCommunityDeleted: onCommunityDeleted,
|
|
35470
35685
|
observeCommunity: observeCommunity,
|
|
35686
|
+
searchCommunities: searchCommunities,
|
|
35471
35687
|
getCommunities: getCommunities,
|
|
35472
35688
|
getCommunity: getCommunity,
|
|
35473
35689
|
getTrendingCommunities: getTrendingCommunities,
|
|
@@ -36054,7 +36270,7 @@ const updatePost = async (postId, patch) => {
|
|
|
36054
36270
|
const cachedAt = client.cache && Date.now();
|
|
36055
36271
|
if (client.cache)
|
|
36056
36272
|
ingestInCache(data, { cachedAt });
|
|
36057
|
-
fireEvent('post.updated', data);
|
|
36273
|
+
fireEvent('local.post.updated', data);
|
|
36058
36274
|
const { posts } = data;
|
|
36059
36275
|
return {
|
|
36060
36276
|
data: LinkedObject.post(posts.find(post => post.postId === postId)),
|
|
@@ -36091,7 +36307,7 @@ const editPost = async (postId, patch) => {
|
|
|
36091
36307
|
const cachedAt = client.cache && Date.now();
|
|
36092
36308
|
if (client.cache)
|
|
36093
36309
|
ingestInCache(data, { cachedAt });
|
|
36094
|
-
fireEvent('post.updated', data);
|
|
36310
|
+
fireEvent('local.post.updated', data);
|
|
36095
36311
|
const { posts } = data;
|
|
36096
36312
|
return {
|
|
36097
36313
|
data: LinkedObject.post(posts.find(post => post.postId === postId)),
|
|
@@ -36464,290 +36680,6 @@ const observePost = (postId, callback, policy = 'cache_then_server') => {
|
|
|
36464
36680
|
};
|
|
36465
36681
|
};
|
|
36466
36682
|
|
|
36467
|
-
/* begin_public_function
|
|
36468
|
-
id: post.get
|
|
36469
|
-
*/
|
|
36470
|
-
/**
|
|
36471
|
-
* ```js
|
|
36472
|
-
* import { PostRepository } from '@amityco/ts-sdk-react-native';
|
|
36473
|
-
*
|
|
36474
|
-
* let post;
|
|
36475
|
-
*
|
|
36476
|
-
* const unsub = PostRepository.getPost(postId, response => {
|
|
36477
|
-
* post = response.data;
|
|
36478
|
-
* });
|
|
36479
|
-
* ```
|
|
36480
|
-
*
|
|
36481
|
-
* Observe all mutation on a given {@link Amity.Post}
|
|
36482
|
-
*
|
|
36483
|
-
* @param postId the ID of the message to observe
|
|
36484
|
-
* @param callback the function to call when new data are available
|
|
36485
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the sub channel
|
|
36486
|
-
*
|
|
36487
|
-
* @category Post Live Object
|
|
36488
|
-
*/
|
|
36489
|
-
const getPost = (postId, callback) => {
|
|
36490
|
-
return liveObject(postId, callback, 'postId', getPost$1, [
|
|
36491
|
-
onPostApproved,
|
|
36492
|
-
onPostDeclined,
|
|
36493
|
-
(callback) => {
|
|
36494
|
-
return onPostDeleted((post) => {
|
|
36495
|
-
var _a;
|
|
36496
|
-
let targetPost = post;
|
|
36497
|
-
// check if the deleted post is a child of the target post
|
|
36498
|
-
if (post.parentPostId === postId && post.isDeleted) {
|
|
36499
|
-
const parentPost = (_a = pullFromCache([
|
|
36500
|
-
'post',
|
|
36501
|
-
'get',
|
|
36502
|
-
post.parentPostId,
|
|
36503
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
36504
|
-
if (parentPost) {
|
|
36505
|
-
parentPost.children = parentPost.children.filter(childId => childId !== post.postId);
|
|
36506
|
-
pushToCache(['post', 'get', parentPost.postId], parentPost);
|
|
36507
|
-
// if the deleted post is a child of the target post, then the target post is the parent post
|
|
36508
|
-
targetPost = parentPost;
|
|
36509
|
-
}
|
|
36510
|
-
}
|
|
36511
|
-
callback(targetPost);
|
|
36512
|
-
});
|
|
36513
|
-
},
|
|
36514
|
-
onPostFlagged,
|
|
36515
|
-
(callback) => {
|
|
36516
|
-
return onPostReactionAdded((post) => {
|
|
36517
|
-
callback(LinkedObject.post(post));
|
|
36518
|
-
});
|
|
36519
|
-
},
|
|
36520
|
-
(callback) => {
|
|
36521
|
-
return onPostReactionRemoved((post) => {
|
|
36522
|
-
callback(LinkedObject.post(post));
|
|
36523
|
-
});
|
|
36524
|
-
},
|
|
36525
|
-
onPostUnflagged,
|
|
36526
|
-
onPostUpdated,
|
|
36527
|
-
]);
|
|
36528
|
-
};
|
|
36529
|
-
/* end_public_function */
|
|
36530
|
-
|
|
36531
|
-
/**
|
|
36532
|
-
* ```js
|
|
36533
|
-
* import { queryPosts } from '@amityco/ts-sdk-react-native'
|
|
36534
|
-
* const { data: posts, prevPage, nextPage } = await queryPosts({ targetId, targetType })
|
|
36535
|
-
* ```
|
|
36536
|
-
*
|
|
36537
|
-
* Queries a paginable list of {@link Amity.Post} objects
|
|
36538
|
-
*
|
|
36539
|
-
* @param query The query parameters
|
|
36540
|
-
* @returns posts
|
|
36541
|
-
*
|
|
36542
|
-
* @category Post API
|
|
36543
|
-
* @async
|
|
36544
|
-
*/
|
|
36545
|
-
const queryPosts = async (query) => {
|
|
36546
|
-
const client = getActiveClient();
|
|
36547
|
-
client.log('post/queryPosts', query);
|
|
36548
|
-
const { page, limit = 10, includeDeleted } = query, params = __rest(query, ["page", "limit", "includeDeleted"]);
|
|
36549
|
-
const { dataTypes, matchingOnlyParentPost } = params;
|
|
36550
|
-
const options = (() => {
|
|
36551
|
-
if (page)
|
|
36552
|
-
return { token: page };
|
|
36553
|
-
if (limit)
|
|
36554
|
-
return { limit };
|
|
36555
|
-
return undefined;
|
|
36556
|
-
})();
|
|
36557
|
-
// API-FIX: parameters should be querystring. (1)
|
|
36558
|
-
// API-FIX: backend should answer Amity.Response (2)
|
|
36559
|
-
// const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<Amity.PostPayload>>>(
|
|
36560
|
-
const { data } = await client.http.get(`/api/v4/posts`, {
|
|
36561
|
-
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted),
|
|
36562
|
-
/*
|
|
36563
|
-
* when creating post like image, file, video BE will create 2 posts
|
|
36564
|
-
* 1. parent post to store text with dataType=text
|
|
36565
|
-
* 2. child post to store dataTypes post data
|
|
36566
|
-
*
|
|
36567
|
-
* By default, BE queries only parent post
|
|
36568
|
-
*/
|
|
36569
|
-
matchingOnlyParentPost: matchingOnlyParentPost !== null && matchingOnlyParentPost !== void 0 ? matchingOnlyParentPost : !(dataTypes === null || dataTypes === void 0 ? void 0 : dataTypes.length), options }),
|
|
36570
|
-
});
|
|
36571
|
-
// API-FIX: backend should answer Amity.Response (2)
|
|
36572
|
-
// const { paging, posts } = unwrapPayload(data)
|
|
36573
|
-
// unpacking
|
|
36574
|
-
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
36575
|
-
const paperedPayload = prepareMembershipPayload(payload, 'communityUsers');
|
|
36576
|
-
const { posts } = payload;
|
|
36577
|
-
const cachedAt = client.cache && Date.now();
|
|
36578
|
-
if (client.cache) {
|
|
36579
|
-
ingestInCache(paperedPayload, { cachedAt });
|
|
36580
|
-
const cacheKey = ['post', 'query', Object.assign(Object.assign({}, params), { options })];
|
|
36581
|
-
pushToCache(cacheKey, { posts: posts.map(getResolver('post')), paging });
|
|
36582
|
-
}
|
|
36583
|
-
return { data: posts.map(LinkedObject.post), cachedAt, paging };
|
|
36584
|
-
};
|
|
36585
|
-
|
|
36586
|
-
/* begin_public_function
|
|
36587
|
-
id: post.query
|
|
36588
|
-
*/
|
|
36589
|
-
/**
|
|
36590
|
-
* ```js
|
|
36591
|
-
* import { PostRepository } from '@amityco/ts-sdk-react-native'
|
|
36592
|
-
*
|
|
36593
|
-
* let posts = []
|
|
36594
|
-
* const unsub = PostRepository.getPosts({
|
|
36595
|
-
* targetType: Amity.PostTargetType,
|
|
36596
|
-
* targetId: Amity.Post['targetId'],
|
|
36597
|
-
* }, response => merge(posts, response.data))
|
|
36598
|
-
* ```
|
|
36599
|
-
*
|
|
36600
|
-
* Observe all mutations on a list of {@link Amity.Post} for a given target object
|
|
36601
|
-
*
|
|
36602
|
-
* @param params.targetType the type of the target
|
|
36603
|
-
* @param params.targetId the ID of the target
|
|
36604
|
-
* @param callback the function to call when new data are available
|
|
36605
|
-
* @param config
|
|
36606
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
36607
|
-
*
|
|
36608
|
-
* @category Posts Live Collection
|
|
36609
|
-
*/
|
|
36610
|
-
const getPosts = (params, callback, config) => {
|
|
36611
|
-
const { log, cache } = getActiveClient();
|
|
36612
|
-
if (!cache) {
|
|
36613
|
-
console.log(ENABLE_CACHE_MESSAGE);
|
|
36614
|
-
}
|
|
36615
|
-
const timestamp = Date.now();
|
|
36616
|
-
log(`getPosts(tmpid: ${timestamp}) > listen`);
|
|
36617
|
-
const { limit: queryLimit } = params, queryParams = __rest(params, ["limit"]);
|
|
36618
|
-
const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
|
|
36619
|
-
const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
|
|
36620
|
-
const disposers = [];
|
|
36621
|
-
const cacheKey = [
|
|
36622
|
-
'post',
|
|
36623
|
-
'collection',
|
|
36624
|
-
{ targetId: params.targetId, targetType: params.targetType },
|
|
36625
|
-
];
|
|
36626
|
-
const responder = (data) => {
|
|
36627
|
-
var _a, _b, _c;
|
|
36628
|
-
let posts = (_a = data.data
|
|
36629
|
-
.map(postId => pullFromCache(['post', 'get', postId]))
|
|
36630
|
-
.filter(Boolean)
|
|
36631
|
-
.map(({ data }) => LinkedObject.post(data))) !== null && _a !== void 0 ? _a : [];
|
|
36632
|
-
const sortBy = params.sortBy ? params.sortBy : 'lastCreated';
|
|
36633
|
-
posts = posts.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
36634
|
-
if (!params.includeDeleted) {
|
|
36635
|
-
posts = filterByPropEquality(posts, 'isDeleted', false);
|
|
36636
|
-
}
|
|
36637
|
-
if (params.tags) {
|
|
36638
|
-
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); }); });
|
|
36639
|
-
}
|
|
36640
|
-
if (params.targetType === 'community' && params.feedType) {
|
|
36641
|
-
posts = filterByFeedType(posts, params.feedType);
|
|
36642
|
-
}
|
|
36643
|
-
if ((_b = params.dataTypes) === null || _b === void 0 ? void 0 : _b.length) {
|
|
36644
|
-
posts = filterByPostDataTypes(posts, params.dataTypes);
|
|
36645
|
-
}
|
|
36646
|
-
callback({
|
|
36647
|
-
onNextPage: onFetch,
|
|
36648
|
-
data: posts,
|
|
36649
|
-
hasNextPage: !!((_c = data.params) === null || _c === void 0 ? void 0 : _c.page),
|
|
36650
|
-
loading: data.loading,
|
|
36651
|
-
error: data.error,
|
|
36652
|
-
});
|
|
36653
|
-
};
|
|
36654
|
-
const realtimeRouter = (action) => (post) => {
|
|
36655
|
-
var _a, _b;
|
|
36656
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
36657
|
-
if (!collection)
|
|
36658
|
-
return;
|
|
36659
|
-
if (post.parentPostId && post.isDeleted) {
|
|
36660
|
-
const parentPost = (_b = pullFromCache([
|
|
36661
|
-
'post',
|
|
36662
|
-
'get',
|
|
36663
|
-
post.parentPostId,
|
|
36664
|
-
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
36665
|
-
if (!parentPost || (parentPost === null || parentPost === void 0 ? void 0 : parentPost.targetId) !== params.targetId)
|
|
36666
|
-
return;
|
|
36667
|
-
parentPost.children = parentPost.children.filter(childId => childId !== post.postId);
|
|
36668
|
-
pushToCache(['post', 'get', parentPost.postId], parentPost);
|
|
36669
|
-
}
|
|
36670
|
-
else {
|
|
36671
|
-
if (params.targetId !== post.targetId)
|
|
36672
|
-
return;
|
|
36673
|
-
if (params.targetType !== post.targetType)
|
|
36674
|
-
return;
|
|
36675
|
-
}
|
|
36676
|
-
/*
|
|
36677
|
-
* This is not ideal, but currently this is the only way to update the
|
|
36678
|
-
* collection on post declined
|
|
36679
|
-
*/
|
|
36680
|
-
if (action === 'onDeclined') {
|
|
36681
|
-
collection.data = collection.data.filter(postId => postId !== post.postId);
|
|
36682
|
-
}
|
|
36683
|
-
else {
|
|
36684
|
-
collection.data = [...new Set([post.postId, ...collection.data])];
|
|
36685
|
-
}
|
|
36686
|
-
pushToCache(cacheKey, collection);
|
|
36687
|
-
responder(collection);
|
|
36688
|
-
};
|
|
36689
|
-
const onFetch = (initial = false) => {
|
|
36690
|
-
var _a, _b, _c;
|
|
36691
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
36692
|
-
const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
36693
|
-
if (!initial && posts.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
|
|
36694
|
-
return;
|
|
36695
|
-
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 }));
|
|
36696
|
-
runQuery(query, ({ data: result, error, loading, paging }) => {
|
|
36697
|
-
const data = {
|
|
36698
|
-
loading,
|
|
36699
|
-
error,
|
|
36700
|
-
params: { page: paging === null || paging === void 0 ? void 0 : paging.next },
|
|
36701
|
-
data: posts,
|
|
36702
|
-
};
|
|
36703
|
-
if (result) {
|
|
36704
|
-
data.data = initial
|
|
36705
|
-
? result.map(getResolver('post'))
|
|
36706
|
-
: [...new Set([...posts, ...result.map(getResolver('post'))])];
|
|
36707
|
-
}
|
|
36708
|
-
pushToCache(cacheKey, data);
|
|
36709
|
-
responder(data);
|
|
36710
|
-
}, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
|
|
36711
|
-
};
|
|
36712
|
-
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')));
|
|
36713
|
-
onFetch(true);
|
|
36714
|
-
disposers.push(() => dropFromCache(cacheKey));
|
|
36715
|
-
return () => {
|
|
36716
|
-
log(`getPosts(tmpid: ${timestamp}) > dispose`);
|
|
36717
|
-
disposers.forEach(fn => fn());
|
|
36718
|
-
};
|
|
36719
|
-
};
|
|
36720
|
-
/* end_public_function */
|
|
36721
|
-
|
|
36722
|
-
var index$5 = /*#__PURE__*/Object.freeze({
|
|
36723
|
-
__proto__: null,
|
|
36724
|
-
getPostByIds: getPostByIds,
|
|
36725
|
-
createPost: createPost,
|
|
36726
|
-
updatePost: updatePost,
|
|
36727
|
-
editPost: editPost,
|
|
36728
|
-
deletePost: deletePost,
|
|
36729
|
-
softDeletePost: softDeletePost,
|
|
36730
|
-
hardDeletePost: hardDeletePost,
|
|
36731
|
-
approvePost: approvePost,
|
|
36732
|
-
declinePost: declinePost,
|
|
36733
|
-
flagPost: flagPost,
|
|
36734
|
-
unflagPost: unflagPost,
|
|
36735
|
-
isPostFlaggedByMe: isPostFlaggedByMe,
|
|
36736
|
-
onPostCreated: onPostCreated,
|
|
36737
|
-
onPostUpdated: onPostUpdated,
|
|
36738
|
-
onPostDeleted: onPostDeleted,
|
|
36739
|
-
onPostApproved: onPostApproved,
|
|
36740
|
-
onPostDeclined: onPostDeclined,
|
|
36741
|
-
onPostFlagged: onPostFlagged,
|
|
36742
|
-
onPostUnflagged: onPostUnflagged,
|
|
36743
|
-
onPostReactionAdded: onPostReactionAdded,
|
|
36744
|
-
onPostReactionRemoved: onPostReactionRemoved,
|
|
36745
|
-
observePosts: observePosts,
|
|
36746
|
-
observePost: observePost,
|
|
36747
|
-
getPost: getPost,
|
|
36748
|
-
getPosts: getPosts
|
|
36749
|
-
});
|
|
36750
|
-
|
|
36751
36683
|
/* begin_public_function
|
|
36752
36684
|
id: comment.get_by_ids
|
|
36753
36685
|
*/
|
|
@@ -36856,7 +36788,7 @@ const createComment = async (bundle) => {
|
|
|
36856
36788
|
ingestInCache(data, { cachedAt });
|
|
36857
36789
|
if (['post', 'content'].includes(bundle.referenceType)) {
|
|
36858
36790
|
const post = await getPost$1(bundle.referenceId);
|
|
36859
|
-
fireEvent('post.updated', {
|
|
36791
|
+
fireEvent('local.post.updated', {
|
|
36860
36792
|
posts: [post.data],
|
|
36861
36793
|
categories: [],
|
|
36862
36794
|
comments: [],
|
|
@@ -36894,7 +36826,7 @@ const createComment = async (bundle) => {
|
|
|
36894
36826
|
}
|
|
36895
36827
|
}
|
|
36896
36828
|
}
|
|
36897
|
-
fireEvent('comment.created', data);
|
|
36829
|
+
fireEvent('local.comment.created', data);
|
|
36898
36830
|
return {
|
|
36899
36831
|
data: LinkedObject.comment(comments[0]),
|
|
36900
36832
|
cachedAt,
|
|
@@ -37050,8 +36982,7 @@ const deleteComment = async (commentId, permanent = false) => {
|
|
|
37050
36982
|
}
|
|
37051
36983
|
else {
|
|
37052
36984
|
const post = await getPost$1(comment.data.referenceId);
|
|
37053
|
-
|
|
37054
|
-
fireEvent('post.updated', {
|
|
36985
|
+
fireEvent('local.post.updated', {
|
|
37055
36986
|
posts: [post.data],
|
|
37056
36987
|
categories: [],
|
|
37057
36988
|
comments: [],
|
|
@@ -37063,8 +36994,7 @@ const deleteComment = async (commentId, permanent = false) => {
|
|
|
37063
36994
|
users: [],
|
|
37064
36995
|
});
|
|
37065
36996
|
}
|
|
37066
|
-
|
|
37067
|
-
fireEvent('comment.deleted', {
|
|
36997
|
+
fireEvent('local.comment.deleted', {
|
|
37068
36998
|
comments: [deleted],
|
|
37069
36999
|
commentChildren: [],
|
|
37070
37000
|
files: [],
|
|
@@ -37533,7 +37463,7 @@ const getComments = (params, callback, config) => {
|
|
|
37533
37463
|
};
|
|
37534
37464
|
/* end_public_function */
|
|
37535
37465
|
|
|
37536
|
-
var index$
|
|
37466
|
+
var index$5 = /*#__PURE__*/Object.freeze({
|
|
37537
37467
|
__proto__: null,
|
|
37538
37468
|
getCommentByIds: getCommentByIds,
|
|
37539
37469
|
createComment: createComment,
|
|
@@ -37557,6 +37487,324 @@ var index$4 = /*#__PURE__*/Object.freeze({
|
|
|
37557
37487
|
getComments: getComments
|
|
37558
37488
|
});
|
|
37559
37489
|
|
|
37490
|
+
/* begin_public_function
|
|
37491
|
+
id: post.get
|
|
37492
|
+
*/
|
|
37493
|
+
/**
|
|
37494
|
+
* ```js
|
|
37495
|
+
* import { PostRepository } from '@amityco/ts-sdk-react-native';
|
|
37496
|
+
*
|
|
37497
|
+
* let post;
|
|
37498
|
+
*
|
|
37499
|
+
* const unsub = PostRepository.getPost(postId, response => {
|
|
37500
|
+
* post = response.data;
|
|
37501
|
+
* });
|
|
37502
|
+
* ```
|
|
37503
|
+
*
|
|
37504
|
+
* Observe all mutation on a given {@link Amity.Post}
|
|
37505
|
+
*
|
|
37506
|
+
* @param postId the ID of the message to observe
|
|
37507
|
+
* @param callback the function to call when new data are available
|
|
37508
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the sub channel
|
|
37509
|
+
*
|
|
37510
|
+
* @category Post Live Object
|
|
37511
|
+
*/
|
|
37512
|
+
const getPost = (postId, callback) => {
|
|
37513
|
+
return liveObject(postId, callback, 'postId', getPost$1, [
|
|
37514
|
+
onPostApproved,
|
|
37515
|
+
onPostDeclined,
|
|
37516
|
+
(callback) => {
|
|
37517
|
+
return onPostDeleted((post) => {
|
|
37518
|
+
var _a;
|
|
37519
|
+
let targetPost = post;
|
|
37520
|
+
// check if the deleted post is a child of the target post
|
|
37521
|
+
if (post.parentPostId === postId && post.isDeleted) {
|
|
37522
|
+
const parentPost = (_a = pullFromCache([
|
|
37523
|
+
'post',
|
|
37524
|
+
'get',
|
|
37525
|
+
post.parentPostId,
|
|
37526
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
37527
|
+
if (parentPost) {
|
|
37528
|
+
parentPost.children = parentPost.children.filter(childId => childId !== post.postId);
|
|
37529
|
+
pushToCache(['post', 'get', parentPost.postId], parentPost);
|
|
37530
|
+
// if the deleted post is a child of the target post, then the target post is the parent post
|
|
37531
|
+
targetPost = parentPost;
|
|
37532
|
+
}
|
|
37533
|
+
}
|
|
37534
|
+
callback(targetPost);
|
|
37535
|
+
});
|
|
37536
|
+
},
|
|
37537
|
+
onPostFlagged,
|
|
37538
|
+
(callback) => {
|
|
37539
|
+
return onPostReactionAdded((post) => {
|
|
37540
|
+
callback(LinkedObject.post(post));
|
|
37541
|
+
});
|
|
37542
|
+
},
|
|
37543
|
+
(callback) => {
|
|
37544
|
+
return onPostReactionRemoved((post) => {
|
|
37545
|
+
callback(LinkedObject.post(post));
|
|
37546
|
+
});
|
|
37547
|
+
},
|
|
37548
|
+
onPostUnflagged,
|
|
37549
|
+
onPostUpdated,
|
|
37550
|
+
convertEventPayload((callback) => {
|
|
37551
|
+
return onCommentCreated(async (comment) => {
|
|
37552
|
+
if (comment.referenceId === postId) {
|
|
37553
|
+
await getPost$1(postId);
|
|
37554
|
+
callback(comment);
|
|
37555
|
+
}
|
|
37556
|
+
});
|
|
37557
|
+
}, 'referenceId', 'post'),
|
|
37558
|
+
convertEventPayload((callback) => {
|
|
37559
|
+
return onCommentDeleted(async (comment) => {
|
|
37560
|
+
if (comment.referenceId === postId) {
|
|
37561
|
+
await getPost$1(postId);
|
|
37562
|
+
callback(comment);
|
|
37563
|
+
}
|
|
37564
|
+
});
|
|
37565
|
+
}, 'referenceId', 'post'),
|
|
37566
|
+
]);
|
|
37567
|
+
};
|
|
37568
|
+
/* end_public_function */
|
|
37569
|
+
|
|
37570
|
+
/**
|
|
37571
|
+
* ```js
|
|
37572
|
+
* import { queryPosts } from '@amityco/ts-sdk-react-native'
|
|
37573
|
+
* const { data: posts, prevPage, nextPage } = await queryPosts({ targetId, targetType })
|
|
37574
|
+
* ```
|
|
37575
|
+
*
|
|
37576
|
+
* Queries a paginable list of {@link Amity.Post} objects
|
|
37577
|
+
*
|
|
37578
|
+
* @param query The query parameters
|
|
37579
|
+
* @returns posts
|
|
37580
|
+
*
|
|
37581
|
+
* @category Post API
|
|
37582
|
+
* @async
|
|
37583
|
+
*/
|
|
37584
|
+
const queryPosts = async (query) => {
|
|
37585
|
+
const client = getActiveClient();
|
|
37586
|
+
client.log('post/queryPosts', query);
|
|
37587
|
+
const { page, limit = 10, includeDeleted } = query, params = __rest(query, ["page", "limit", "includeDeleted"]);
|
|
37588
|
+
const { dataTypes, matchingOnlyParentPost } = params;
|
|
37589
|
+
const options = (() => {
|
|
37590
|
+
if (page)
|
|
37591
|
+
return { token: page };
|
|
37592
|
+
if (limit)
|
|
37593
|
+
return { limit };
|
|
37594
|
+
return undefined;
|
|
37595
|
+
})();
|
|
37596
|
+
// API-FIX: parameters should be querystring. (1)
|
|
37597
|
+
// API-FIX: backend should answer Amity.Response (2)
|
|
37598
|
+
// const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<Amity.PostPayload>>>(
|
|
37599
|
+
const { data } = await client.http.get(`/api/v4/posts`, {
|
|
37600
|
+
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted),
|
|
37601
|
+
/*
|
|
37602
|
+
* when creating post like image, file, video BE will create 2 posts
|
|
37603
|
+
* 1. parent post to store text with dataType=text
|
|
37604
|
+
* 2. child post to store dataTypes post data
|
|
37605
|
+
*
|
|
37606
|
+
* By default, BE queries only parent post
|
|
37607
|
+
*/
|
|
37608
|
+
matchingOnlyParentPost: matchingOnlyParentPost !== null && matchingOnlyParentPost !== void 0 ? matchingOnlyParentPost : !(dataTypes === null || dataTypes === void 0 ? void 0 : dataTypes.length), options }),
|
|
37609
|
+
});
|
|
37610
|
+
// API-FIX: backend should answer Amity.Response (2)
|
|
37611
|
+
// const { paging, posts } = unwrapPayload(data)
|
|
37612
|
+
// unpacking
|
|
37613
|
+
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
37614
|
+
const paperedPayload = prepareMembershipPayload(payload, 'communityUsers');
|
|
37615
|
+
const { posts } = payload;
|
|
37616
|
+
const cachedAt = client.cache && Date.now();
|
|
37617
|
+
if (client.cache) {
|
|
37618
|
+
ingestInCache(paperedPayload, { cachedAt });
|
|
37619
|
+
const cacheKey = ['post', 'query', Object.assign(Object.assign({}, params), { options })];
|
|
37620
|
+
pushToCache(cacheKey, { posts: posts.map(getResolver('post')), paging });
|
|
37621
|
+
}
|
|
37622
|
+
return { data: posts.map(LinkedObject.post), cachedAt, paging };
|
|
37623
|
+
};
|
|
37624
|
+
|
|
37625
|
+
/* begin_public_function
|
|
37626
|
+
id: post.query
|
|
37627
|
+
*/
|
|
37628
|
+
/**
|
|
37629
|
+
* ```js
|
|
37630
|
+
* import { PostRepository } from '@amityco/ts-sdk-react-native'
|
|
37631
|
+
*
|
|
37632
|
+
* let posts = []
|
|
37633
|
+
* const unsub = PostRepository.getPosts({
|
|
37634
|
+
* targetType: Amity.PostTargetType,
|
|
37635
|
+
* targetId: Amity.Post['targetId'],
|
|
37636
|
+
* }, response => merge(posts, response.data))
|
|
37637
|
+
* ```
|
|
37638
|
+
*
|
|
37639
|
+
* Observe all mutations on a list of {@link Amity.Post} for a given target object
|
|
37640
|
+
*
|
|
37641
|
+
* @param params.targetType the type of the target
|
|
37642
|
+
* @param params.targetId the ID of the target
|
|
37643
|
+
* @param callback the function to call when new data are available
|
|
37644
|
+
* @param config
|
|
37645
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
37646
|
+
*
|
|
37647
|
+
* @category Posts Live Collection
|
|
37648
|
+
*/
|
|
37649
|
+
const getPosts = (params, callback, config) => {
|
|
37650
|
+
const { log, cache } = getActiveClient();
|
|
37651
|
+
if (!cache) {
|
|
37652
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
37653
|
+
}
|
|
37654
|
+
const timestamp = Date.now();
|
|
37655
|
+
log(`getPosts(tmpid: ${timestamp}) > listen`);
|
|
37656
|
+
const { limit: queryLimit } = params, queryParams = __rest(params, ["limit"]);
|
|
37657
|
+
const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
|
|
37658
|
+
const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
|
|
37659
|
+
const disposers = [];
|
|
37660
|
+
const cacheKey = [
|
|
37661
|
+
'post',
|
|
37662
|
+
'collection',
|
|
37663
|
+
{ targetId: params.targetId, targetType: params.targetType },
|
|
37664
|
+
];
|
|
37665
|
+
const responder = (data) => {
|
|
37666
|
+
var _a, _b, _c;
|
|
37667
|
+
let posts = (_a = data.data
|
|
37668
|
+
.map(postId => pullFromCache(['post', 'get', postId]))
|
|
37669
|
+
.filter(Boolean)
|
|
37670
|
+
.map(({ data }) => LinkedObject.post(data))) !== null && _a !== void 0 ? _a : [];
|
|
37671
|
+
const sortBy = params.sortBy ? params.sortBy : 'lastCreated';
|
|
37672
|
+
posts = posts.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
37673
|
+
if (!params.includeDeleted) {
|
|
37674
|
+
posts = filterByPropEquality(posts, 'isDeleted', false);
|
|
37675
|
+
}
|
|
37676
|
+
if (params.tags) {
|
|
37677
|
+
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); }); });
|
|
37678
|
+
}
|
|
37679
|
+
if (params.targetType === 'community' && params.feedType) {
|
|
37680
|
+
posts = filterByFeedType(posts, params.feedType);
|
|
37681
|
+
}
|
|
37682
|
+
if ((_b = params.dataTypes) === null || _b === void 0 ? void 0 : _b.length) {
|
|
37683
|
+
posts = filterByPostDataTypes(posts, params.dataTypes);
|
|
37684
|
+
}
|
|
37685
|
+
callback({
|
|
37686
|
+
onNextPage: onFetch,
|
|
37687
|
+
data: posts,
|
|
37688
|
+
hasNextPage: !!((_c = data.params) === null || _c === void 0 ? void 0 : _c.page),
|
|
37689
|
+
loading: data.loading,
|
|
37690
|
+
error: data.error,
|
|
37691
|
+
});
|
|
37692
|
+
};
|
|
37693
|
+
const realtimeRouter = (action) => (post) => {
|
|
37694
|
+
var _a, _b;
|
|
37695
|
+
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
37696
|
+
if (!collection)
|
|
37697
|
+
return;
|
|
37698
|
+
if (post.parentPostId && post.isDeleted) {
|
|
37699
|
+
const parentPost = (_b = pullFromCache([
|
|
37700
|
+
'post',
|
|
37701
|
+
'get',
|
|
37702
|
+
post.parentPostId,
|
|
37703
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
37704
|
+
if (!parentPost || (parentPost === null || parentPost === void 0 ? void 0 : parentPost.targetId) !== params.targetId)
|
|
37705
|
+
return;
|
|
37706
|
+
parentPost.children = parentPost.children.filter(childId => childId !== post.postId);
|
|
37707
|
+
pushToCache(['post', 'get', parentPost.postId], parentPost);
|
|
37708
|
+
}
|
|
37709
|
+
else {
|
|
37710
|
+
if (params.targetId !== post.targetId)
|
|
37711
|
+
return;
|
|
37712
|
+
if (params.targetType !== post.targetType)
|
|
37713
|
+
return;
|
|
37714
|
+
}
|
|
37715
|
+
/*
|
|
37716
|
+
* This is not ideal, but currently this is the only way to update the
|
|
37717
|
+
* collection on post declined
|
|
37718
|
+
*/
|
|
37719
|
+
if (action === 'onDeclined') {
|
|
37720
|
+
collection.data = collection.data.filter(postId => postId !== post.postId);
|
|
37721
|
+
}
|
|
37722
|
+
else {
|
|
37723
|
+
collection.data = [...new Set([post.postId, ...collection.data])];
|
|
37724
|
+
}
|
|
37725
|
+
pushToCache(cacheKey, collection);
|
|
37726
|
+
responder(collection);
|
|
37727
|
+
};
|
|
37728
|
+
const onFetch = (initial = false) => {
|
|
37729
|
+
var _a, _b, _c;
|
|
37730
|
+
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
37731
|
+
const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
37732
|
+
if (!initial && posts.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
|
|
37733
|
+
return;
|
|
37734
|
+
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 }));
|
|
37735
|
+
runQuery(query, ({ data: result, error, loading, paging }) => {
|
|
37736
|
+
const data = {
|
|
37737
|
+
loading,
|
|
37738
|
+
error,
|
|
37739
|
+
params: { page: paging === null || paging === void 0 ? void 0 : paging.next },
|
|
37740
|
+
data: posts,
|
|
37741
|
+
};
|
|
37742
|
+
if (result) {
|
|
37743
|
+
data.data = initial
|
|
37744
|
+
? result.map(getResolver('post'))
|
|
37745
|
+
: [...new Set([...posts, ...result.map(getResolver('post'))])];
|
|
37746
|
+
}
|
|
37747
|
+
pushToCache(cacheKey, data);
|
|
37748
|
+
responder(data);
|
|
37749
|
+
}, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
|
|
37750
|
+
};
|
|
37751
|
+
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) => {
|
|
37752
|
+
return onCommentCreated(async (comment) => {
|
|
37753
|
+
var _a;
|
|
37754
|
+
const currentCollection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
37755
|
+
if (!currentCollection || currentCollection.data.includes(comment.referenceId))
|
|
37756
|
+
return;
|
|
37757
|
+
await getPost$1(comment.referenceId);
|
|
37758
|
+
callback(comment);
|
|
37759
|
+
});
|
|
37760
|
+
}, 'referenceId', 'post')(realtimeRouter('onUpdate')), convertEventPayload((callback) => {
|
|
37761
|
+
return onCommentDeleted(async (comment) => {
|
|
37762
|
+
var _a;
|
|
37763
|
+
const currentCollection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
37764
|
+
if (!currentCollection || currentCollection.data.includes(comment.referenceId))
|
|
37765
|
+
return;
|
|
37766
|
+
await getPost$1(comment.referenceId);
|
|
37767
|
+
callback(comment);
|
|
37768
|
+
});
|
|
37769
|
+
}, 'referenceId', 'post')(realtimeRouter('onUpdate')));
|
|
37770
|
+
onFetch(true);
|
|
37771
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
37772
|
+
return () => {
|
|
37773
|
+
log(`getPosts(tmpid: ${timestamp}) > dispose`);
|
|
37774
|
+
disposers.forEach(fn => fn());
|
|
37775
|
+
};
|
|
37776
|
+
};
|
|
37777
|
+
/* end_public_function */
|
|
37778
|
+
|
|
37779
|
+
var index$4 = /*#__PURE__*/Object.freeze({
|
|
37780
|
+
__proto__: null,
|
|
37781
|
+
getPostByIds: getPostByIds,
|
|
37782
|
+
createPost: createPost,
|
|
37783
|
+
updatePost: updatePost,
|
|
37784
|
+
editPost: editPost,
|
|
37785
|
+
deletePost: deletePost,
|
|
37786
|
+
softDeletePost: softDeletePost,
|
|
37787
|
+
hardDeletePost: hardDeletePost,
|
|
37788
|
+
approvePost: approvePost,
|
|
37789
|
+
declinePost: declinePost,
|
|
37790
|
+
flagPost: flagPost,
|
|
37791
|
+
unflagPost: unflagPost,
|
|
37792
|
+
isPostFlaggedByMe: isPostFlaggedByMe,
|
|
37793
|
+
onPostCreated: onPostCreated,
|
|
37794
|
+
onPostUpdated: onPostUpdated,
|
|
37795
|
+
onPostDeleted: onPostDeleted,
|
|
37796
|
+
onPostApproved: onPostApproved,
|
|
37797
|
+
onPostDeclined: onPostDeclined,
|
|
37798
|
+
onPostFlagged: onPostFlagged,
|
|
37799
|
+
onPostUnflagged: onPostUnflagged,
|
|
37800
|
+
onPostReactionAdded: onPostReactionAdded,
|
|
37801
|
+
onPostReactionRemoved: onPostReactionRemoved,
|
|
37802
|
+
observePosts: observePosts,
|
|
37803
|
+
observePost: observePost,
|
|
37804
|
+
getPost: getPost,
|
|
37805
|
+
getPosts: getPosts
|
|
37806
|
+
});
|
|
37807
|
+
|
|
37560
37808
|
/* begin_public_function
|
|
37561
37809
|
id: stream.create
|
|
37562
37810
|
*/
|
|
@@ -39531,7 +39779,7 @@ class StoryLiveCollectionController extends LiveCollectionController {
|
|
|
39531
39779
|
this.queryStreamController = new StoryQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), paginationController);
|
|
39532
39780
|
this.paginationController = paginationController;
|
|
39533
39781
|
this.callback = callback.bind(this);
|
|
39534
|
-
this.loadPage(true);
|
|
39782
|
+
this.loadPage({ initial: true });
|
|
39535
39783
|
}
|
|
39536
39784
|
setup() {
|
|
39537
39785
|
var _a;
|
|
@@ -39713,7 +39961,7 @@ class GlobalStoryLiveCollectionController extends LiveCollectionController {
|
|
|
39713
39961
|
this.queryStreamController = new GlobalStoryQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), paginationController);
|
|
39714
39962
|
this.paginationController = paginationController;
|
|
39715
39963
|
this.callback = callback.bind(this);
|
|
39716
|
-
this.loadPage(true);
|
|
39964
|
+
this.loadPage({ initial: true });
|
|
39717
39965
|
}
|
|
39718
39966
|
setup() {
|
|
39719
39967
|
var _a;
|
|
@@ -39749,7 +39997,7 @@ class GlobalStoryLiveCollectionController extends LiveCollectionController {
|
|
|
39749
39997
|
return rest;
|
|
39750
39998
|
});
|
|
39751
39999
|
this.callback({
|
|
39752
|
-
onNextPage: () => this.loadPage(
|
|
40000
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
39753
40001
|
data,
|
|
39754
40002
|
hasNextPage: !!this.paginationController.getNextToken(),
|
|
39755
40003
|
loading,
|
|
@@ -39855,4 +40103,4 @@ const createUserToken = async (apiKey, apiRegion, params) => {
|
|
|
39855
40103
|
return { accessToken: data.accessToken };
|
|
39856
40104
|
};
|
|
39857
40105
|
|
|
39858
|
-
export { API_REGIONS, index$7 as CategoryRepository, index$b as ChannelRepository, index$k as Client, index$
|
|
40106
|
+
export { API_REGIONS, index$7 as CategoryRepository, index$b as ChannelRepository, index$k as Client, index$5 as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$8 as CommunityRepository, ContentFeedType, DefaultCommunityPostSetting, index$6 as FeedRepository, index$h as FileRepository, FileType, index$1 as LiveStreamPlayer, MessageContentType, index$f as MessageRepository, index$2 as PollRepository, PostContentType, index$4 as PostRepository, index$g as ReactionRepository, index as StoryRepository, index$3 as StreamRepository, index$e as SubChannelRepository, SubscriptionLevels, index$i as UserRepository, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };
|