@amityco/ts-sdk 7.22.0 → 7.22.1-6865c1e9.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/model.d.ts +2 -0
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +4 -0
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/core/transport.d.ts +1 -0
- package/dist/@types/core/transport.d.ts.map +1 -1
- package/dist/@types/domains/analytics.d.ts +3 -2
- package/dist/@types/domains/analytics.d.ts.map +1 -1
- package/dist/@types/domains/feed.d.ts +14 -0
- package/dist/@types/domains/feed.d.ts.map +1 -1
- package/dist/@types/domains/post.d.ts +1 -0
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/analytic/service/analytic/AnalyticsEngine.d.ts +1 -0
- package/dist/analytic/service/analytic/AnalyticsEngine.d.ts.map +1 -1
- package/dist/analytic/service/analytic/AnalyticsEventCapturer.d.ts +2 -1
- package/dist/analytic/service/analytic/AnalyticsEventCapturer.d.ts.map +1 -1
- package/dist/analytic/service/analytic/AnalyticsService.d.ts +1 -0
- package/dist/analytic/service/analytic/AnalyticsService.d.ts.map +1 -1
- package/dist/client/api/setupLoginSubscriptions.d.ts.map +1 -1
- package/dist/core/model/idResolvers.d.ts.map +1 -1
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/core/query/paging.d.ts +1 -0
- package/dist/core/query/paging.d.ts.map +1 -1
- package/dist/core/subscription.d.ts +3 -0
- package/dist/core/subscription.d.ts.map +1 -1
- package/dist/feedRepository/errors/AmityForYouFeedDisabledError.d.ts +13 -0
- package/dist/feedRepository/errors/AmityForYouFeedDisabledError.d.ts.map +1 -0
- package/dist/feedRepository/index.d.ts +2 -1
- package/dist/feedRepository/index.d.ts.map +1 -1
- package/dist/feedRepository/observers/getForYouFeed/CursorController.d.ts +17 -0
- package/dist/feedRepository/observers/getForYouFeed/CursorController.d.ts.map +1 -0
- package/dist/feedRepository/observers/getForYouFeed/LiveCollectionController.d.ts +13 -0
- package/dist/feedRepository/observers/getForYouFeed/LiveCollectionController.d.ts.map +1 -0
- package/dist/feedRepository/observers/getForYouFeed/PaginationController.d.ts +12 -0
- package/dist/feedRepository/observers/getForYouFeed/PaginationController.d.ts.map +1 -0
- package/dist/feedRepository/observers/getForYouFeed/QueryStreamController.d.ts +15 -0
- package/dist/feedRepository/observers/getForYouFeed/QueryStreamController.d.ts.map +1 -0
- package/dist/feedRepository/observers/getForYouFeed.d.ts +19 -0
- package/dist/feedRepository/observers/getForYouFeed.d.ts.map +1 -0
- package/dist/feedRepository/observers/index.d.ts +1 -0
- package/dist/feedRepository/observers/index.d.ts.map +1 -1
- package/dist/feedRepository/observers/tests/integration/getForYouFeed.integration.test.d.ts +2 -0
- package/dist/feedRepository/observers/tests/integration/getForYouFeed.integration.test.d.ts.map +1 -0
- package/dist/feedRepository/observers/tests/unit/CursorController.test.d.ts +2 -0
- package/dist/feedRepository/observers/tests/unit/CursorController.test.d.ts.map +1 -0
- package/dist/index.cjs.js +302 -3
- package/dist/index.esm.js +302 -4
- package/dist/index.umd.js +3 -3
- package/dist/postRepository/tests/integration/postAnalytics.integration.test.d.ts +2 -0
- package/dist/postRepository/tests/integration/postAnalytics.integration.test.d.ts.map +1 -0
- package/dist/postRepository/tests/integration/setup.d.ts +6 -0
- package/dist/postRepository/tests/integration/setup.d.ts.map +1 -0
- package/dist/streamRepository/observers/getStreams/GetStreamsPageController.d.ts +1 -0
- package/dist/streamRepository/observers/getStreams/GetStreamsPageController.d.ts.map +1 -1
- package/dist/utils/constants.d.ts +4 -0
- package/dist/utils/constants.d.ts.map +1 -1
- package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
- package/dist/utils/tests/dummy/community.d.ts +2 -0
- package/dist/utils/tests/dummy/community.d.ts.map +1 -1
- package/dist/utils/tests/dummy/post.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -267,6 +267,7 @@ function getVersion() {
|
|
|
267
267
|
const VERSION = getVersion();
|
|
268
268
|
|
|
269
269
|
const COLLECTION_DEFAULT_PAGINATION_LIMIT = 5;
|
|
270
|
+
const COLLECTION_DEFAULT_PAGINATION_SIZE = 20;
|
|
270
271
|
const COLLECTION_DEFAULT_CACHING_POLICY = 'cache_then_server';
|
|
271
272
|
const ENABLE_CACHE_MESSAGE = 'For using Live Collection feature you need to enable Cache!';
|
|
272
273
|
const LIVE_OBJECT_ENABLE_CACHE_MESSAGE = 'For using Live Object feature you need to enable Cache!';
|
|
@@ -279,6 +280,9 @@ const DAY = 24 * HOUR;
|
|
|
279
280
|
const WEEK = 7 * DAY;
|
|
280
281
|
const YEAR = 365 * DAY;
|
|
281
282
|
const ACCESS_TOKEN_WATCHER_INTERVAL = 10 * MINUTE;
|
|
283
|
+
const API_ENDPOINTS = {
|
|
284
|
+
forYouFeed: '/api/v1/feeds/for-you',
|
|
285
|
+
};
|
|
282
286
|
|
|
283
287
|
// cache constants
|
|
284
288
|
const CACHE_KEY_GET = 'get';
|
|
@@ -708,6 +712,7 @@ const idResolvers = {
|
|
|
708
712
|
event: ({ eventId }) => eventId,
|
|
709
713
|
eventResponse: ({ userId }) => userId,
|
|
710
714
|
product: ({ productId }) => productId,
|
|
715
|
+
feedMetadata: ({ postId }) => postId,
|
|
711
716
|
};
|
|
712
717
|
/**
|
|
713
718
|
* Retrieve the id resolver matching a domain name
|
|
@@ -768,6 +773,7 @@ const PAYLOAD2MODEL = {
|
|
|
768
773
|
viewers: 'viewer',
|
|
769
774
|
eventResponses: 'eventResponse',
|
|
770
775
|
products: 'product',
|
|
776
|
+
feedMetadata: 'feedMetadata',
|
|
771
777
|
};
|
|
772
778
|
/** hidden */
|
|
773
779
|
const isOutdated = (prevData, nextData) => {
|
|
@@ -7844,6 +7850,30 @@ class AnalyticsEventCapturer {
|
|
|
7844
7850
|
activityType: "view" /* Amity.AnalyticEventActivityType.View */,
|
|
7845
7851
|
});
|
|
7846
7852
|
}
|
|
7853
|
+
markPostAsMeaningfullyViewed(postId, feedRenderPosition) {
|
|
7854
|
+
var _a;
|
|
7855
|
+
const cached = (_a = pullFromCache(['feedMetadata', 'get', postId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
7856
|
+
const metadata = {};
|
|
7857
|
+
if (feedRenderPosition !== undefined)
|
|
7858
|
+
metadata.feedRenderPosition = feedRenderPosition;
|
|
7859
|
+
if (cached) {
|
|
7860
|
+
metadata.feedSnapshotPosition = cached.feedSnapshotPosition;
|
|
7861
|
+
metadata.feedInjectionType = cached.feedInjectionType;
|
|
7862
|
+
metadata.feedRelevanceScore = cached.feedRelevanceScore;
|
|
7863
|
+
metadata.feedPopularityScore = cached.feedPopularityScore;
|
|
7864
|
+
metadata.feedFreshnessScore = cached.feedFreshnessScore;
|
|
7865
|
+
metadata.feedAffinityScore = cached.feedAffinityScore;
|
|
7866
|
+
metadata.feedFinalScore = cached.feedFinalScore;
|
|
7867
|
+
metadata.feedMmrPenalty = cached.feedMmrPenalty;
|
|
7868
|
+
}
|
|
7869
|
+
this.markAs({
|
|
7870
|
+
uniqueId: `${postId}.meaningfulView`,
|
|
7871
|
+
contentId: postId,
|
|
7872
|
+
contentType: "post" /* Amity.AnalyticEventContentType.Post */,
|
|
7873
|
+
activityType: "meaningfulView" /* Amity.AnalyticEventActivityType.MeaningfulView */,
|
|
7874
|
+
metadata: Object.keys(metadata).length > 0 ? metadata : undefined,
|
|
7875
|
+
});
|
|
7876
|
+
}
|
|
7847
7877
|
markStory(story, activityType) {
|
|
7848
7878
|
if (!story.expiresAt)
|
|
7849
7879
|
return;
|
|
@@ -7983,6 +8013,12 @@ class AnalyticsEngine {
|
|
|
7983
8013
|
this._eventCapturer.markPostAsViewed(postId);
|
|
7984
8014
|
}
|
|
7985
8015
|
}
|
|
8016
|
+
markPostAsMeaningfullyViewed(postId, feedRenderPosition) {
|
|
8017
|
+
if (this._client.sessionState === "established" /* Amity.SessionStates.ESTABLISHED */ ||
|
|
8018
|
+
this._client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */) {
|
|
8019
|
+
this._eventCapturer.markPostAsMeaningfullyViewed(postId, feedRenderPosition);
|
|
8020
|
+
}
|
|
8021
|
+
}
|
|
7986
8022
|
markStoryAsViewed(story) {
|
|
7987
8023
|
if (this._client.sessionState === "established" /* Amity.SessionStates.ESTABLISHED */ ||
|
|
7988
8024
|
this._client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */ // For case token_expired, we assume token is expired and gonna re-connect soon
|
|
@@ -9103,6 +9139,59 @@ var blockedUserSyncEngineOnLoginHandler = () => {
|
|
|
9103
9139
|
};
|
|
9104
9140
|
};
|
|
9105
9141
|
|
|
9142
|
+
class CursorController {
|
|
9143
|
+
constructor(networkId, userId) {
|
|
9144
|
+
this.networkId = networkId;
|
|
9145
|
+
this.userId = userId;
|
|
9146
|
+
}
|
|
9147
|
+
static current() {
|
|
9148
|
+
try {
|
|
9149
|
+
const user = getCurrentUser();
|
|
9150
|
+
if (!user)
|
|
9151
|
+
return null;
|
|
9152
|
+
const networkId = getNetworkId(user);
|
|
9153
|
+
const { userId } = user;
|
|
9154
|
+
return networkId && userId ? new CursorController(networkId, userId) : null;
|
|
9155
|
+
}
|
|
9156
|
+
catch (_a) {
|
|
9157
|
+
return null;
|
|
9158
|
+
}
|
|
9159
|
+
}
|
|
9160
|
+
static isExpired(expiredAt) {
|
|
9161
|
+
return Date.now() >= expiredAt;
|
|
9162
|
+
}
|
|
9163
|
+
static clearOnLogout() {
|
|
9164
|
+
return onSessionStateChange(state => {
|
|
9165
|
+
var _a;
|
|
9166
|
+
if (state === "terminated" /* Amity.SessionStates.TERMINATED */)
|
|
9167
|
+
(_a = CursorController.current()) === null || _a === void 0 ? void 0 : _a.clear();
|
|
9168
|
+
});
|
|
9169
|
+
}
|
|
9170
|
+
get key() {
|
|
9171
|
+
return `amity:forYouFeed:cursor:${this.networkId}:${this.userId}`;
|
|
9172
|
+
}
|
|
9173
|
+
async get() {
|
|
9174
|
+
const raw = await getItem(this.key);
|
|
9175
|
+
if (!raw)
|
|
9176
|
+
return null;
|
|
9177
|
+
try {
|
|
9178
|
+
const parsed = JSON.parse(raw);
|
|
9179
|
+
if (typeof (parsed === null || parsed === void 0 ? void 0 : parsed.cursor) !== 'string' || typeof (parsed === null || parsed === void 0 ? void 0 : parsed.expiredAt) !== 'number')
|
|
9180
|
+
return null;
|
|
9181
|
+
return { cursor: parsed.cursor, expiredAt: parsed.expiredAt };
|
|
9182
|
+
}
|
|
9183
|
+
catch (_a) {
|
|
9184
|
+
return null;
|
|
9185
|
+
}
|
|
9186
|
+
}
|
|
9187
|
+
async set(value) {
|
|
9188
|
+
await setItem(this.key, JSON.stringify(value));
|
|
9189
|
+
}
|
|
9190
|
+
async clear() {
|
|
9191
|
+
await setItem(this.key, '');
|
|
9192
|
+
}
|
|
9193
|
+
}
|
|
9194
|
+
|
|
9106
9195
|
const EVENTS = [
|
|
9107
9196
|
'disconnected',
|
|
9108
9197
|
'error',
|
|
@@ -9292,7 +9381,7 @@ const setupLoginSubscriptions = (unsubWatcher) => {
|
|
|
9292
9381
|
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
|
|
9293
9382
|
// the channel because currently backend can't handle this, so every time a user is banned from
|
|
9294
9383
|
// a channel or the channel is deleted the channel's unread count will not be reset to zero
|
|
9295
|
-
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler(), reactionSyncEngineOnLoginHandler(), blockedUserSyncEngineOnLoginHandler());
|
|
9384
|
+
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler(), reactionSyncEngineOnLoginHandler(), blockedUserSyncEngineOnLoginHandler(), CursorController.clearOnLogout());
|
|
9296
9385
|
if (client.useLegacyUnreadCount) {
|
|
9297
9386
|
subscriptions.push(readReceiptSyncEngineOnLoginHandler());
|
|
9298
9387
|
}
|
|
@@ -13274,7 +13363,7 @@ const getWatchSessionStorage = () => {
|
|
|
13274
13363
|
return storageInstance;
|
|
13275
13364
|
};
|
|
13276
13365
|
|
|
13277
|
-
const privateKey = "
|
|
13366
|
+
const privateKey = "MIIEpQIBAAKCAQEAwAEc/oZgYIvKSUG/C3mONYLR4ZPgAjMEX4bJ+xqqakUDRtqlNO+eZs2blQ1Ko0DBkqPExyQezvjibH5W2UZBV5RaBTlTcNVKTToMBEGesAfaEcM3qUyQHxdbFYZv6P4sb14dcwxTQ8usmaV8ooiR1Fcaso5ZWYcZ8Hb46FbQ7OoVumsBtPWwfZ4f003o5VCl6AIM6lcLv9UDLlFVYhE+PeXpRHtfWlGqxMvqC9oinlwhL6nWv6VjQXW4nhcib72dPBzfHT7k/PMKto2SxALYdb68ENiAGuJLWi3AUHSyYCJK2w7wIlWfJUAI0v26ub10IpExr6D5QuW2577jjP93iwIDAQABAoIBAFWfqXhwIIatkFY+9Z1+ZcbDQimgsmMIsUiQaX6Lk7e0cxOj6czDlxYtVtaPiNtow2pLkjNkjkCqiP7tEHnwdK9DvylZOTa2R15NJpK3WLcTqVIGhsn/FL5owfvFah6zSsmXZParZm5zY9NZE03ALZhOB9/cz0e3kf/EbpfeL2mW7MApyiUt5i09ycchroOpcWp73ipIxvgigtZyUGFmsQicWhUs28F0D7w4Qfk76yG3nqXeb+BAMhCaIaa/k/aAxhiZG/ygEQWQrcC8gfe+jyicMAQPDEVS9YuUMGsLjIjKuVLZzp2xirQnhc2i2zVNEIvG6soprPOBEMQugzrtX5ECgYEA3b7KAbBIbDl1e4ZSCWhHdHkiWVZHaopsR/LhqDDNhXjWjq3AesgV6k0j9EdziMn/HmmOso0bz99GTV3JZf4A9ztTLumJlkHbdVtlgOqSjrFLj12rH9KXTheyIhWSpUmm8+WB1xasFbqpvJaGo7F3pd2Fqj1XR4mp5BO7c/t7LJ0CgYEA3aouEzXQ9THRKYocdfY69EI1Il1t/d/RSqqd9BxEjxBgxkM13ZiYIn/R4WW/nCUrlmhxG44Aa2Gob4Ahfsui2xKTg/g/3Zk/rAxAEGkfOLGoenaJMD41fH4wUq3FRYwkvnaMb9Hd6f/TlBHslIRa2NN58bSBGJCyBP2b59+2+EcCgYEAixDVRXvV37GlYUOa/XVdosk5Zoe6oDGRuQm0xbNdoUBoZvDHDvme7ONWEiQha/8qtVsD+CyQ7awcPfb8kK9c0bBt+bTS6d4BkTcxkEkMgtrkBVR8Nqfu5jXsLH4VCv4G61zbMhZw8+ut+az5YX2yCN7Frj9sFlxapMRPQmzMEe0CgYEAumsAzM8ZqNv4mAK65Mnr0rhLj1cbxcKRdUYACOgtEFQpzxN/HZnTeFAe5nx3pI3uFlRHq3DFEYnT6dHMWaJQmAULYpVIwMi9L6gtyJ9fzoI6uqMtxRDMUqKdaSsTGOY/kJ6KhQ/unXi1K3XXjR+yd1+C0q+HUm1+CYxvrZYLfskCgYEArsEy+IQOiqniJ0NE2vVUF+UK/IRZaic9YKcpov5Ot7Vvzm/MnnW4N1ljVskocETBWMmPUvNSExVjPebi+rxd8fa5kY8BJScPTzMFbunZn/wjtGdcM10qdlVQ9doG61A/9P3ezFKCfS4AvF/H/59LcSx2Bh28fp3/efiVIOpVd4Y=";
|
|
13278
13367
|
/*
|
|
13279
13368
|
* The crypto algorithm used for importing key and signing string
|
|
13280
13369
|
*/
|
|
@@ -14596,6 +14685,10 @@ const postLinkedObject = (post) => {
|
|
|
14596
14685
|
const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
|
|
14597
14686
|
analyticsEngineInstance.markPostAsViewed(post.postId);
|
|
14598
14687
|
},
|
|
14688
|
+
markAsMeaningfullyViewed: (feedRenderPosition) => {
|
|
14689
|
+
const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
|
|
14690
|
+
analyticsEngineInstance.markPostAsMeaningfullyViewed(post.postId, feedRenderPosition);
|
|
14691
|
+
},
|
|
14599
14692
|
},
|
|
14600
14693
|
get productTags() {
|
|
14601
14694
|
var _a, _b;
|
|
@@ -27909,13 +28002,218 @@ const getCommunityFeed = (params, callback, config) => {
|
|
|
27909
28002
|
};
|
|
27910
28003
|
/* end_public_function */
|
|
27911
28004
|
|
|
28005
|
+
/**
|
|
28006
|
+
* Thrown by `getForYouFeed` when the network has the For You feature
|
|
28007
|
+
* disabled. Mapped from HTTP 404 NOT_FOUND. Distinct from a generic
|
|
28008
|
+
* not-found so consumers can hide the For You tab without retrying.
|
|
28009
|
+
*
|
|
28010
|
+
* @category Errors
|
|
28011
|
+
*/
|
|
28012
|
+
class AmityForYouFeedDisabledError extends ASCApiError {
|
|
28013
|
+
constructor(message = 'For You feed is not enabled for this network') {
|
|
28014
|
+
super(message, 400400 /* Amity.ServerError.ITEM_NOT_FOUND */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
28015
|
+
this.type = 'AmityForYouFeedDisabledError';
|
|
28016
|
+
}
|
|
28017
|
+
}
|
|
28018
|
+
|
|
28019
|
+
class ForYouFeedPaginationController extends PaginationController {
|
|
28020
|
+
constructor(query) {
|
|
28021
|
+
super(query);
|
|
28022
|
+
this.checkedDisk = false;
|
|
28023
|
+
this.cursor = CursorController.current();
|
|
28024
|
+
}
|
|
28025
|
+
async getRequest(_queryParams, token) {
|
|
28026
|
+
let effectiveToken = token;
|
|
28027
|
+
const params = {
|
|
28028
|
+
limit: COLLECTION_DEFAULT_PAGINATION_SIZE,
|
|
28029
|
+
};
|
|
28030
|
+
if (!effectiveToken && !this.checkedDisk && this.cursor) {
|
|
28031
|
+
this.checkedDisk = true;
|
|
28032
|
+
const stored = await this.cursor.get();
|
|
28033
|
+
if (stored && !CursorController.isExpired(stored.expiredAt)) {
|
|
28034
|
+
effectiveToken = stored.cursor;
|
|
28035
|
+
}
|
|
28036
|
+
else if (stored) {
|
|
28037
|
+
await this.cursor.clear();
|
|
28038
|
+
}
|
|
28039
|
+
}
|
|
28040
|
+
if (effectiveToken)
|
|
28041
|
+
params.cursor = effectiveToken;
|
|
28042
|
+
let queryResponse;
|
|
28043
|
+
try {
|
|
28044
|
+
({ data: queryResponse } = await this.http.get(API_ENDPOINTS.forYouFeed, { params }));
|
|
28045
|
+
}
|
|
28046
|
+
catch (error) {
|
|
28047
|
+
if (error instanceof ASCApiError && error.code === 400400 /* Amity.ServerError.ITEM_NOT_FOUND */) {
|
|
28048
|
+
throw new AmityForYouFeedDisabledError();
|
|
28049
|
+
}
|
|
28050
|
+
const recoverable = error instanceof ASCApiError && error.code === 400000 /* Amity.ServerError.BAD_REQUEST */;
|
|
28051
|
+
if (recoverable && effectiveToken !== undefined) {
|
|
28052
|
+
if (this.cursor)
|
|
28053
|
+
await this.cursor.clear();
|
|
28054
|
+
({ data: queryResponse } = await this.http.get(API_ENDPOINTS.forYouFeed, { params: { limit: COLLECTION_DEFAULT_PAGINATION_SIZE } }));
|
|
28055
|
+
}
|
|
28056
|
+
else {
|
|
28057
|
+
throw error;
|
|
28058
|
+
}
|
|
28059
|
+
}
|
|
28060
|
+
await this.persistCursor(queryResponse);
|
|
28061
|
+
return queryResponse;
|
|
28062
|
+
}
|
|
28063
|
+
async persistCursor(response) {
|
|
28064
|
+
var _a, _b;
|
|
28065
|
+
if (!this.cursor)
|
|
28066
|
+
return;
|
|
28067
|
+
const cursor = (_a = response.paging) === null || _a === void 0 ? void 0 : _a.next;
|
|
28068
|
+
const expiredAtIso = (_b = response.paging) === null || _b === void 0 ? void 0 : _b.expiredAt;
|
|
28069
|
+
if (!cursor || !expiredAtIso)
|
|
28070
|
+
return;
|
|
28071
|
+
const expiredAt = Date.parse(expiredAtIso);
|
|
28072
|
+
if (Number.isNaN(expiredAt))
|
|
28073
|
+
return;
|
|
28074
|
+
await this.cursor.set({ cursor, expiredAt });
|
|
28075
|
+
}
|
|
28076
|
+
}
|
|
28077
|
+
|
|
28078
|
+
class ForYouFeedQueryStreamController extends QueryStreamController {
|
|
28079
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
28080
|
+
super(query, cacheKey);
|
|
28081
|
+
this.notifyChange = notifyChange;
|
|
28082
|
+
this.preparePayload = preparePayload;
|
|
28083
|
+
}
|
|
28084
|
+
async saveToMainDB(response) {
|
|
28085
|
+
const processedPayload = await this.preparePayload(response);
|
|
28086
|
+
const client = getActiveClient();
|
|
28087
|
+
const cachedAt = client.cache && Date.now();
|
|
28088
|
+
if (client.cache)
|
|
28089
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
28090
|
+
}
|
|
28091
|
+
appendToQueryStream(response, _direction, refresh = false) {
|
|
28092
|
+
var _a, _b;
|
|
28093
|
+
if (refresh) {
|
|
28094
|
+
pushToCache(this.cacheKey, {
|
|
28095
|
+
data: response.posts.map(getResolver('post')),
|
|
28096
|
+
});
|
|
28097
|
+
}
|
|
28098
|
+
else {
|
|
28099
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
28100
|
+
const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
28101
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
|
|
28102
|
+
}
|
|
28103
|
+
}
|
|
28104
|
+
reactor(action) {
|
|
28105
|
+
return (post) => {
|
|
28106
|
+
var _a;
|
|
28107
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
28108
|
+
if (!collection)
|
|
28109
|
+
return;
|
|
28110
|
+
if (post.parentPostId && !collection.data.includes(post.parentPostId))
|
|
28111
|
+
return;
|
|
28112
|
+
if (action === EnumPostActions.OnPostDeleted || action === EnumPostActions.OnPostDeclined) {
|
|
28113
|
+
collection.data = collection.data.filter(postId => postId !== post.postId);
|
|
28114
|
+
}
|
|
28115
|
+
pushToCache(this.cacheKey, collection);
|
|
28116
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
28117
|
+
};
|
|
28118
|
+
}
|
|
28119
|
+
subscribeRTE(createSubscriber) {
|
|
28120
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
28121
|
+
}
|
|
28122
|
+
}
|
|
28123
|
+
|
|
28124
|
+
const FOR_YOU_FEED_CACHE_KEY = ['forYouFeed', 'collection'];
|
|
28125
|
+
class ForYouFeedLiveCollectionController extends LiveCollectionController {
|
|
28126
|
+
constructor(callback) {
|
|
28127
|
+
const queryStreamId = `for-you-feed-${getActiveClient().userId}`;
|
|
28128
|
+
const query = {};
|
|
28129
|
+
const paginationController = new ForYouFeedPaginationController(query);
|
|
28130
|
+
super(paginationController, queryStreamId, FOR_YOU_FEED_CACHE_KEY, callback);
|
|
28131
|
+
this.queryStreamController = new ForYouFeedQueryStreamController(query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
|
|
28132
|
+
this.callback = callback.bind(this);
|
|
28133
|
+
this.loadPage({ initial: true });
|
|
28134
|
+
}
|
|
28135
|
+
setup() {
|
|
28136
|
+
var _a;
|
|
28137
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
28138
|
+
if (!collection)
|
|
28139
|
+
pushToCache(this.cacheKey, { data: [], params: {} });
|
|
28140
|
+
}
|
|
28141
|
+
async persistModel(payload) {
|
|
28142
|
+
await this.queryStreamController.saveToMainDB(payload);
|
|
28143
|
+
}
|
|
28144
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
28145
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
28146
|
+
}
|
|
28147
|
+
startSubscription() {
|
|
28148
|
+
return this.queryStreamController.subscribeRTE(getGlobalFeedSubscriptions(this.cacheKey));
|
|
28149
|
+
}
|
|
28150
|
+
notifyChange({ origin, loading, error }) {
|
|
28151
|
+
var _a, _b;
|
|
28152
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
28153
|
+
if (!collection)
|
|
28154
|
+
return;
|
|
28155
|
+
const data = ((_b = collection.data
|
|
28156
|
+
.map(id => pullFromCache(['post', 'get', id]))
|
|
28157
|
+
.filter(isNonNullable)
|
|
28158
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
|
|
28159
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
28160
|
+
return;
|
|
28161
|
+
this.callback({
|
|
28162
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
28163
|
+
data,
|
|
28164
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
28165
|
+
loading,
|
|
28166
|
+
error,
|
|
28167
|
+
});
|
|
28168
|
+
}
|
|
28169
|
+
}
|
|
28170
|
+
|
|
28171
|
+
/* begin_public_function
|
|
28172
|
+
id: feed.query.for_you_feed
|
|
28173
|
+
*/
|
|
28174
|
+
/**
|
|
28175
|
+
* ```js
|
|
28176
|
+
* import { FeedRepository } from '@amityco/ts-sdk'
|
|
28177
|
+
*
|
|
28178
|
+
* const unsub = FeedRepository.getForYouFeed(({ data, loading, error, hasNextPage, onNextPage }) => {
|
|
28179
|
+
* // render posts; call onNextPage() to load the next page (20 posts)
|
|
28180
|
+
* })
|
|
28181
|
+
* ```
|
|
28182
|
+
*
|
|
28183
|
+
* Observe the For You feed — a personalized, server-ranked
|
|
28184
|
+
* {@link Amity.LiveCollection} of {@link Amity.Post}.
|
|
28185
|
+
*
|
|
28186
|
+
* @param callback the function to call when new data is available
|
|
28187
|
+
* @returns an {@link Amity.Unsubscriber} function to stop observing
|
|
28188
|
+
*
|
|
28189
|
+
* @category Posts Live Collection
|
|
28190
|
+
*/
|
|
28191
|
+
const getForYouFeed = (callback) => {
|
|
28192
|
+
const { log, cache } = getActiveClient();
|
|
28193
|
+
if (!cache)
|
|
28194
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
28195
|
+
const timestamp = Date.now();
|
|
28196
|
+
log(`getForYouFeed(tmpid: ${timestamp}) > listen`);
|
|
28197
|
+
const forYouFeedLiveCollection = new ForYouFeedLiveCollectionController(callback);
|
|
28198
|
+
const disposers = forYouFeedLiveCollection.startSubscription();
|
|
28199
|
+
const cacheKey = forYouFeedLiveCollection.getCacheKey();
|
|
28200
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
28201
|
+
return () => {
|
|
28202
|
+
log(`getForYouFeed(tmpid: ${timestamp}) > dispose`);
|
|
28203
|
+
disposers.forEach(fn => fn());
|
|
28204
|
+
};
|
|
28205
|
+
};
|
|
28206
|
+
/* end_public_function */
|
|
28207
|
+
|
|
27912
28208
|
var index$d = /*#__PURE__*/Object.freeze({
|
|
27913
28209
|
__proto__: null,
|
|
27914
28210
|
queryGlobalFeed: queryGlobalFeed,
|
|
27915
28211
|
getCustomRankingGlobalFeed: getCustomRankingGlobalFeed,
|
|
27916
28212
|
getGlobalFeed: getGlobalFeed,
|
|
27917
28213
|
getUserFeed: getUserFeed,
|
|
27918
|
-
getCommunityFeed: getCommunityFeed
|
|
28214
|
+
getCommunityFeed: getCommunityFeed,
|
|
28215
|
+
getForYouFeed: getForYouFeed,
|
|
28216
|
+
AmityForYouFeedDisabledError: AmityForYouFeedDisabledError
|
|
27919
28217
|
});
|
|
27920
28218
|
|
|
27921
28219
|
/* begin_public_function
|
|
@@ -35707,6 +36005,7 @@ exports.getMarkerUserFeedTopic = getMarkerUserFeedTopic;
|
|
|
35707
36005
|
exports.getMessageTopic = getMessageTopic;
|
|
35708
36006
|
exports.getMyFollowersTopic = getMyFollowersTopic;
|
|
35709
36007
|
exports.getMyFollowingsTopic = getMyFollowingsTopic;
|
|
36008
|
+
exports.getNetworkId = getNetworkId;
|
|
35710
36009
|
exports.getNetworkTopic = getNetworkTopic;
|
|
35711
36010
|
exports.getPostTopic = getPostTopic;
|
|
35712
36011
|
exports.getRole = getRole;
|