@amityco/ts-sdk 7.33.2-aa939e12.0 → 7.33.2-e5a19559.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/payload.d.ts +4 -0
- package/dist/@types/core/payload.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/follow.d.ts +7 -7
- package/dist/@types/domains/follow.d.ts.map +1 -1
- package/dist/client/api/setupLoginSubscriptions.d.ts.map +1 -1
- package/dist/feedRepository/index.d.ts +1 -1
- package/dist/feedRepository/index.d.ts.map +1 -1
- package/dist/feedRepository/observers/getFollowingFeed/LiveCollectionController.d.ts +13 -0
- package/dist/feedRepository/observers/getFollowingFeed/LiveCollectionController.d.ts.map +1 -0
- package/dist/feedRepository/observers/getFollowingFeed/PaginationController.d.ts +10 -0
- package/dist/feedRepository/observers/getFollowingFeed/PaginationController.d.ts.map +1 -0
- package/dist/feedRepository/observers/getFollowingFeed/QueryStreamController.d.ts +22 -0
- package/dist/feedRepository/observers/getFollowingFeed/QueryStreamController.d.ts.map +1 -0
- package/dist/feedRepository/observers/getFollowingFeed.d.ts +35 -0
- package/dist/feedRepository/observers/getFollowingFeed.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/getFollowingFeed.integration.test.d.ts +2 -0
- package/dist/feedRepository/observers/tests/integration/getFollowingFeed.integration.test.d.ts.map +1 -0
- package/dist/feedRepository/observers/tests/unit/FollowingFeedQueryStreamController.test.d.ts +2 -0
- package/dist/feedRepository/observers/tests/unit/FollowingFeedQueryStreamController.test.d.ts.map +1 -0
- package/dist/index.cjs.js +663 -300
- package/dist/index.esm.js +622 -259
- package/dist/index.umd.js +2 -2
- package/dist/userRepository/relationship/block/api/blockUser.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/api/follow.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/api/getAllFollowings.d.ts +34 -0
- package/dist/userRepository/relationship/follow/api/getAllFollowings.d.ts.map +1 -0
- package/dist/userRepository/relationship/follow/api/index.d.ts +1 -0
- package/dist/userRepository/relationship/follow/api/index.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/api/tests/getAllFollowings.test.d.ts +2 -0
- package/dist/userRepository/relationship/follow/api/tests/getAllFollowings.test.d.ts.map +1 -0
- package/dist/userRepository/relationship/follow/api/tests/integration/getAllFollowings.integration.test.d.ts +2 -0
- package/dist/userRepository/relationship/follow/api/tests/integration/getAllFollowings.integration.test.d.ts.map +1 -0
- package/dist/userRepository/relationship/follow/api/unfollow.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/observers/getFollowers/FollowerLiveCollectionController.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/observers/getFollowers/FollowerPaginationController.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/observers/getFollowers.d.ts +1 -14
- package/dist/userRepository/relationship/follow/observers/getFollowers.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/observers/getFollowings/FollowingLiveCollectionController.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/observers/getFollowings/FollowingPaginationController.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/observers/getFollowings.d.ts +1 -14
- package/dist/userRepository/relationship/follow/observers/getFollowings.d.ts.map +1 -1
- package/dist/userRepository/services/FollowingSyncEngine/followRealtimeOnLoginHandler.d.ts +19 -0
- package/dist/userRepository/services/FollowingSyncEngine/followRealtimeOnLoginHandler.d.ts.map +1 -0
- package/dist/userRepository/services/FollowingSyncEngine/followingSyncEngine.d.ts +61 -0
- package/dist/userRepository/services/FollowingSyncEngine/followingSyncEngine.d.ts.map +1 -0
- package/dist/userRepository/services/FollowingSyncEngine/followingSyncEngineOnLoginHandler.d.ts +3 -0
- package/dist/userRepository/services/FollowingSyncEngine/followingSyncEngineOnLoginHandler.d.ts.map +1 -0
- package/dist/utils/constants.d.ts +1 -1
- package/dist/utils/constants.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/userRepository/relationship/follow/observers/tests/getFollowsByUserIds.test.d.ts +0 -2
- package/dist/userRepository/relationship/follow/observers/tests/getFollowsByUserIds.test.d.ts.map +0 -1
package/dist/index.cjs.js
CHANGED
|
@@ -262,6 +262,14 @@ exports.FeedSortByEnum = void 0;
|
|
|
262
262
|
FeedSortByEnum["LastUpdated"] = "lastUpdated";
|
|
263
263
|
FeedSortByEnum["FirstUpdated"] = "firstUpdated";
|
|
264
264
|
})(exports.FeedSortByEnum || (exports.FeedSortByEnum = {}));
|
|
265
|
+
/** Sort order of the following feed (`GET /api/v1/me/following-feeds`). */
|
|
266
|
+
exports.FollowingFeedSortByEnum = void 0;
|
|
267
|
+
(function (FollowingFeedSortByEnum) {
|
|
268
|
+
/** Server-ranked. The backend default when `sortBy` is not sent. */
|
|
269
|
+
FollowingFeedSortByEnum["CustomRanking"] = "customRanking";
|
|
270
|
+
/** Newest first. */
|
|
271
|
+
FollowingFeedSortByEnum["LastCreated"] = "lastCreated";
|
|
272
|
+
})(exports.FollowingFeedSortByEnum || (exports.FollowingFeedSortByEnum = {}));
|
|
265
273
|
exports.FeedSourceEnum = void 0;
|
|
266
274
|
(function (FeedSourceEnum) {
|
|
267
275
|
FeedSourceEnum["Community"] = "community";
|
|
@@ -390,13 +398,12 @@ const YEAR = 365 * DAY;
|
|
|
390
398
|
const ACCESS_TOKEN_WATCHER_INTERVAL = 10 * MINUTE;
|
|
391
399
|
const API_ENDPOINTS = {
|
|
392
400
|
forYouFeed: '/api/v1/feeds/for-you',
|
|
401
|
+
followingFeed: '/api/v1/me/following-feeds',
|
|
393
402
|
commentReviewQueue: (communityId) => `/api/v3/communities/${encodeURIComponent(communityId)}/comments/review-queue`,
|
|
394
403
|
};
|
|
395
404
|
// The review-queue route defaults to 10, not the SDK-wide page size, and caps at 100
|
|
396
405
|
const COMMENT_REVIEW_QUEUE_DEFAULT_PAGINATION_SIZE = 10;
|
|
397
406
|
const COMMENT_REVIEW_QUEUE_MAX_PAGINATION_SIZE = 100;
|
|
398
|
-
// The me/followers and me/following `userIds` filter takes up to 100 ids, answered in one page
|
|
399
|
-
const FOLLOW_USER_IDS_PAGINATION_LIMIT = 100;
|
|
400
407
|
|
|
401
408
|
// cache constants
|
|
402
409
|
const CACHE_KEY_GET = 'get';
|
|
@@ -1985,13 +1992,13 @@ class SessionWatcher {
|
|
|
1985
1992
|
this._listener.clear();
|
|
1986
1993
|
}
|
|
1987
1994
|
}
|
|
1988
|
-
let instance$
|
|
1995
|
+
let instance$c;
|
|
1989
1996
|
var SessionWatcher$1 = {
|
|
1990
1997
|
getInstance: () => {
|
|
1991
|
-
if (!instance$
|
|
1992
|
-
instance$
|
|
1998
|
+
if (!instance$c) {
|
|
1999
|
+
instance$c = new SessionWatcher();
|
|
1993
2000
|
}
|
|
1994
|
-
return instance$
|
|
2001
|
+
return instance$c;
|
|
1995
2002
|
},
|
|
1996
2003
|
};
|
|
1997
2004
|
|
|
@@ -2658,13 +2665,13 @@ class NetworkActivitiesWatcher {
|
|
|
2658
2665
|
this._listener.clear();
|
|
2659
2666
|
}
|
|
2660
2667
|
}
|
|
2661
|
-
let instance$
|
|
2668
|
+
let instance$b;
|
|
2662
2669
|
var NetworkActivitiesWatcher$1 = {
|
|
2663
2670
|
getInstance: () => {
|
|
2664
|
-
if (!instance$
|
|
2665
|
-
instance$
|
|
2671
|
+
if (!instance$b) {
|
|
2672
|
+
instance$b = new NetworkActivitiesWatcher();
|
|
2666
2673
|
}
|
|
2667
|
-
return instance$
|
|
2674
|
+
return instance$b;
|
|
2668
2675
|
},
|
|
2669
2676
|
};
|
|
2670
2677
|
|
|
@@ -2925,11 +2932,11 @@ class AutoSubscriptionManager {
|
|
|
2925
2932
|
this.seed();
|
|
2926
2933
|
}
|
|
2927
2934
|
}
|
|
2928
|
-
let instance$
|
|
2935
|
+
let instance$a = null;
|
|
2929
2936
|
const getAutoSubscriptionManager = () => {
|
|
2930
|
-
if (!instance$
|
|
2931
|
-
instance$
|
|
2932
|
-
return instance$
|
|
2937
|
+
if (!instance$a)
|
|
2938
|
+
instance$a = new AutoSubscriptionManager();
|
|
2939
|
+
return instance$a;
|
|
2933
2940
|
};
|
|
2934
2941
|
/** Resets the registry to its default baseline when the session ends. */
|
|
2935
2942
|
const resetAutoSubscriptionsOnLogout = () => onSessionStateChange(state => {
|
|
@@ -7012,13 +7019,13 @@ class AnalyticsEngine {
|
|
|
7012
7019
|
this._eventCapturer.resetAllBuckets();
|
|
7013
7020
|
}
|
|
7014
7021
|
}
|
|
7015
|
-
let instance$
|
|
7022
|
+
let instance$9;
|
|
7016
7023
|
var AnalyticsEngine$1 = {
|
|
7017
7024
|
getInstance: () => {
|
|
7018
|
-
if (!instance$
|
|
7019
|
-
instance$
|
|
7025
|
+
if (!instance$9) {
|
|
7026
|
+
instance$9 = new AnalyticsEngine();
|
|
7020
7027
|
}
|
|
7021
|
-
return instance$
|
|
7028
|
+
return instance$9;
|
|
7022
7029
|
},
|
|
7023
7030
|
};
|
|
7024
7031
|
|
|
@@ -7245,12 +7252,12 @@ class MessageReadReceiptSyncEngine {
|
|
|
7245
7252
|
}
|
|
7246
7253
|
}
|
|
7247
7254
|
}
|
|
7248
|
-
let instance$
|
|
7255
|
+
let instance$8 = null;
|
|
7249
7256
|
var ReadReceiptSyncEngine = {
|
|
7250
7257
|
getInstance: () => {
|
|
7251
|
-
if (!instance$
|
|
7252
|
-
instance$
|
|
7253
|
-
return instance$
|
|
7258
|
+
if (!instance$8)
|
|
7259
|
+
instance$8 = new MessageReadReceiptSyncEngine();
|
|
7260
|
+
return instance$8;
|
|
7254
7261
|
},
|
|
7255
7262
|
};
|
|
7256
7263
|
|
|
@@ -7504,12 +7511,12 @@ class LegacyMessageReadReceiptSyncEngine {
|
|
|
7504
7511
|
}
|
|
7505
7512
|
}
|
|
7506
7513
|
}
|
|
7507
|
-
let instance$
|
|
7514
|
+
let instance$7 = null;
|
|
7508
7515
|
var LegacyReadReceiptSyncEngine = {
|
|
7509
7516
|
getInstance: () => {
|
|
7510
|
-
if (!instance$
|
|
7511
|
-
instance$
|
|
7512
|
-
return instance$
|
|
7517
|
+
if (!instance$7)
|
|
7518
|
+
instance$7 = new LegacyMessageReadReceiptSyncEngine();
|
|
7519
|
+
return instance$7;
|
|
7513
7520
|
},
|
|
7514
7521
|
};
|
|
7515
7522
|
|
|
@@ -7755,12 +7762,12 @@ class ObjectResolverEngine {
|
|
|
7755
7762
|
this.stopResolver();
|
|
7756
7763
|
}
|
|
7757
7764
|
}
|
|
7758
|
-
let instance$
|
|
7765
|
+
let instance$6 = null;
|
|
7759
7766
|
var ObjectResolverEngine$1 = {
|
|
7760
7767
|
getInstance: () => {
|
|
7761
|
-
if (!instance$
|
|
7762
|
-
instance$
|
|
7763
|
-
return instance$
|
|
7768
|
+
if (!instance$6)
|
|
7769
|
+
instance$6 = new ObjectResolverEngine();
|
|
7770
|
+
return instance$6;
|
|
7764
7771
|
},
|
|
7765
7772
|
};
|
|
7766
7773
|
|
|
@@ -7910,13 +7917,13 @@ class LiveReactionSyncEngine {
|
|
|
7910
7917
|
this.stopReactionsSync();
|
|
7911
7918
|
}
|
|
7912
7919
|
}
|
|
7913
|
-
let instance$
|
|
7920
|
+
let instance$5;
|
|
7914
7921
|
var ReactionSyncEngine = {
|
|
7915
7922
|
getInstance: () => {
|
|
7916
|
-
if (!instance$
|
|
7917
|
-
instance$
|
|
7923
|
+
if (!instance$5) {
|
|
7924
|
+
instance$5 = new LiveReactionSyncEngine();
|
|
7918
7925
|
}
|
|
7919
|
-
return instance$
|
|
7926
|
+
return instance$5;
|
|
7920
7927
|
},
|
|
7921
7928
|
};
|
|
7922
7929
|
|
|
@@ -7947,7 +7954,7 @@ function prepareBlockedUserPayload(response) {
|
|
|
7947
7954
|
}
|
|
7948
7955
|
|
|
7949
7956
|
const BLOCK_LIST_LIMIT$1 = 100;
|
|
7950
|
-
const TTL_MS$
|
|
7957
|
+
const TTL_MS$2 = 5 * 60 * 1000; // 5 minutes
|
|
7951
7958
|
/**
|
|
7952
7959
|
* Session-scoped singleton engine that manages TTL-based fetching and caching
|
|
7953
7960
|
* of blocked users. Provides a lazy `ensureFetched()` gate for the
|
|
@@ -7985,7 +7992,7 @@ class BlockedUserSyncEngine {
|
|
|
7985
7992
|
isCacheExpired() {
|
|
7986
7993
|
if (this.lastFetchedAt === null)
|
|
7987
7994
|
return true;
|
|
7988
|
-
return Date.now() - this.lastFetchedAt > TTL_MS$
|
|
7995
|
+
return Date.now() - this.lastFetchedAt > TTL_MS$2;
|
|
7989
7996
|
}
|
|
7990
7997
|
/**
|
|
7991
7998
|
* Ensures the local store is populated with fresh blocked-user data.
|
|
@@ -8040,12 +8047,12 @@ class BlockedUserSyncEngine {
|
|
|
8040
8047
|
.map(userLinkedObject);
|
|
8041
8048
|
}
|
|
8042
8049
|
}
|
|
8043
|
-
let instance$
|
|
8050
|
+
let instance$4 = null;
|
|
8044
8051
|
var BlockedUserSyncEngine$1 = {
|
|
8045
8052
|
getInstance: () => {
|
|
8046
|
-
if (!instance$
|
|
8047
|
-
instance$
|
|
8048
|
-
return instance$
|
|
8053
|
+
if (!instance$4)
|
|
8054
|
+
instance$4 = new BlockedUserSyncEngine();
|
|
8055
|
+
return instance$4;
|
|
8049
8056
|
},
|
|
8050
8057
|
};
|
|
8051
8058
|
|
|
@@ -8076,7 +8083,7 @@ function prepareBlockingUserPayload(response) {
|
|
|
8076
8083
|
}
|
|
8077
8084
|
|
|
8078
8085
|
const BLOCK_LIST_LIMIT = 100;
|
|
8079
|
-
const TTL_MS = 5 * 60 * 1000; // 5 minutes
|
|
8086
|
+
const TTL_MS$1 = 5 * 60 * 1000; // 5 minutes
|
|
8080
8087
|
/**
|
|
8081
8088
|
* Session-scoped singleton engine that manages TTL-based fetching and caching
|
|
8082
8089
|
* of blocking users (the "blocked-by" list — users who blocked the current
|
|
@@ -8115,7 +8122,7 @@ class BlockingUserSyncEngine {
|
|
|
8115
8122
|
isCacheExpired() {
|
|
8116
8123
|
if (this.lastFetchedAt === null)
|
|
8117
8124
|
return true;
|
|
8118
|
-
return Date.now() - this.lastFetchedAt > TTL_MS;
|
|
8125
|
+
return Date.now() - this.lastFetchedAt > TTL_MS$1;
|
|
8119
8126
|
}
|
|
8120
8127
|
/**
|
|
8121
8128
|
* Ensures the local store is populated with fresh blocking-user data.
|
|
@@ -8170,12 +8177,12 @@ class BlockingUserSyncEngine {
|
|
|
8170
8177
|
.map(userLinkedObject);
|
|
8171
8178
|
}
|
|
8172
8179
|
}
|
|
8173
|
-
let instance$
|
|
8180
|
+
let instance$3 = null;
|
|
8174
8181
|
var BlockingUserSyncEngine$1 = {
|
|
8175
8182
|
getInstance: () => {
|
|
8176
|
-
if (!instance$
|
|
8177
|
-
instance$
|
|
8178
|
-
return instance$
|
|
8183
|
+
if (!instance$3)
|
|
8184
|
+
instance$3 = new BlockingUserSyncEngine();
|
|
8185
|
+
return instance$3;
|
|
8179
8186
|
},
|
|
8180
8187
|
};
|
|
8181
8188
|
|
|
@@ -8285,6 +8292,336 @@ var blockRealtimeOnLoginHandler = () => {
|
|
|
8285
8292
|
return () => disposers.forEach(dispose => dispose());
|
|
8286
8293
|
};
|
|
8287
8294
|
|
|
8295
|
+
const TTL_MS = 5 * 60 * 1000; // 5 minutes, as BlockedUserSyncEngine
|
|
8296
|
+
const isKept = (status) => status === 'accepted' || status === 'pending';
|
|
8297
|
+
/**
|
|
8298
|
+
* Session-scoped singleton engine behind `getAllFollowings()`: a 5-minute fetch gate
|
|
8299
|
+
* on `GET /api/v4/me/following-ids`, copied from BlockedUserSyncEngine.
|
|
8300
|
+
*
|
|
8301
|
+
* - `onSessionEstablished()` is a no-op — the fetch is lazy, on the first call
|
|
8302
|
+
* - `onSessionDestroyed()` resets `lastFetchedAt` and empties the list, so the next
|
|
8303
|
+
* session fetches again
|
|
8304
|
+
* - `ensureFetched()` fetches only when the window expired or nothing was fetched yet;
|
|
8305
|
+
* `lastFetchedAt` moves only on success
|
|
8306
|
+
* - the answer holds ids and statuses only, so the engine keeps it in memory — user id →
|
|
8307
|
+
* status — replaced on each fetch, never merged: a follow removed on another device
|
|
8308
|
+
* drops out at the next fetch. Nothing is written to the follow or user cache.
|
|
8309
|
+
* - `onFollowChanged()` applies every follow change of the session by its status; a change
|
|
8310
|
+
* that arrives while a fetch is in flight is replayed on top of the answer, so the older
|
|
8311
|
+
* answer does not drop it. Concurrent calls share one in-flight fetch.
|
|
8312
|
+
*
|
|
8313
|
+
* @internal
|
|
8314
|
+
*/
|
|
8315
|
+
class FollowingSyncEngine {
|
|
8316
|
+
constructor() {
|
|
8317
|
+
/** Epoch ms of the last successful fetch. null = never fetched in this session. */
|
|
8318
|
+
this.lastFetchedAt = null;
|
|
8319
|
+
/** user id → status, in order: the session's changes first, then the answer's order. */
|
|
8320
|
+
this.followings = new Map();
|
|
8321
|
+
/** Bumped on sign-out, so a fetch from the old session cannot fill the new one. */
|
|
8322
|
+
this.session = 0;
|
|
8323
|
+
/** The in-flight fetch, shared by concurrent calls. */
|
|
8324
|
+
this.fetching = null;
|
|
8325
|
+
/** Changes applied while `fetching` is in flight, replayed on top of its answer. */
|
|
8326
|
+
this.changesDuringFetch = [];
|
|
8327
|
+
}
|
|
8328
|
+
/** No-op — the fetch is lazy, triggered by getAllFollowings(). */
|
|
8329
|
+
// eslint-disable-next-line class-methods-use-this
|
|
8330
|
+
onSessionEstablished() {
|
|
8331
|
+
// intentionally empty
|
|
8332
|
+
}
|
|
8333
|
+
/** Resets the window so the next session starts with a fresh fetch. */
|
|
8334
|
+
onSessionDestroyed() {
|
|
8335
|
+
this.lastFetchedAt = null;
|
|
8336
|
+
this.followings = new Map();
|
|
8337
|
+
this.fetching = null;
|
|
8338
|
+
this.changesDuringFetch = [];
|
|
8339
|
+
this.session += 1;
|
|
8340
|
+
}
|
|
8341
|
+
/** No-op — the window does not depend on the token. */
|
|
8342
|
+
// eslint-disable-next-line class-methods-use-this
|
|
8343
|
+
onTokenExpired() {
|
|
8344
|
+
// intentionally empty
|
|
8345
|
+
}
|
|
8346
|
+
/**
|
|
8347
|
+
* Called for every follow change the SDK sees during the session. A follow whose
|
|
8348
|
+
* `from` is another user is ignored. Status `accepted` or `pending` sets the user with
|
|
8349
|
+
* that status and moves them to the front; any other status (`none` after an unfollow,
|
|
8350
|
+
* a cancel, a decline or a removed follower; `blocked`) removes them.
|
|
8351
|
+
*/
|
|
8352
|
+
onFollowChanged(follow) {
|
|
8353
|
+
if (!follow || follow.from !== getActiveClient().userId)
|
|
8354
|
+
return;
|
|
8355
|
+
if (this.fetching)
|
|
8356
|
+
this.changesDuringFetch.push(follow);
|
|
8357
|
+
this.apply(follow);
|
|
8358
|
+
}
|
|
8359
|
+
apply(follow) {
|
|
8360
|
+
const rest = [...this.followings].filter(([userId]) => userId !== follow.to);
|
|
8361
|
+
this.followings = new Map(isKept(follow.status) ? [[follow.to, follow.status], ...rest] : rest);
|
|
8362
|
+
}
|
|
8363
|
+
isCacheExpired() {
|
|
8364
|
+
if (this.lastFetchedAt === null)
|
|
8365
|
+
return true;
|
|
8366
|
+
return Date.now() - this.lastFetchedAt > TTL_MS;
|
|
8367
|
+
}
|
|
8368
|
+
/**
|
|
8369
|
+
* Fetches whom the user follows (up to 5,000 ids and statuses, one response, no
|
|
8370
|
+
* `status` so both accepted and pending come back) when the window has expired. A
|
|
8371
|
+
* failure propagates and leaves the window and the list unchanged, so the next call
|
|
8372
|
+
* retries.
|
|
8373
|
+
*/
|
|
8374
|
+
async ensureFetched() {
|
|
8375
|
+
if (!this.isCacheExpired())
|
|
8376
|
+
return;
|
|
8377
|
+
if (!this.fetching) {
|
|
8378
|
+
const { session } = this;
|
|
8379
|
+
this.changesDuringFetch = [];
|
|
8380
|
+
this.fetching = this.fetch(session).finally(() => {
|
|
8381
|
+
if (session !== this.session)
|
|
8382
|
+
return;
|
|
8383
|
+
this.fetching = null;
|
|
8384
|
+
this.changesDuringFetch = [];
|
|
8385
|
+
});
|
|
8386
|
+
}
|
|
8387
|
+
await this.fetching;
|
|
8388
|
+
}
|
|
8389
|
+
async fetch(session) {
|
|
8390
|
+
var _a;
|
|
8391
|
+
const client = getActiveClient();
|
|
8392
|
+
const { data } = await client.http.get('/api/v4/me/following-ids');
|
|
8393
|
+
if (session !== this.session)
|
|
8394
|
+
return; // signed out while in flight
|
|
8395
|
+
// replaced, never merged
|
|
8396
|
+
this.followings = new Map(((_a = data === null || data === void 0 ? void 0 : data.follows) !== null && _a !== void 0 ? _a : [])
|
|
8397
|
+
.filter(follow => isKept(follow.status))
|
|
8398
|
+
.map(follow => [follow.userId, follow.status]));
|
|
8399
|
+
// a change made while the request was in flight is newer than the answer
|
|
8400
|
+
this.changesDuringFetch.forEach(change => this.apply(change));
|
|
8401
|
+
this.lastFetchedAt = Date.now();
|
|
8402
|
+
}
|
|
8403
|
+
/** The kept entries, in order. */
|
|
8404
|
+
getFollowings() {
|
|
8405
|
+
return [...this.followings].map(([userId, status]) => ({ userId, status }));
|
|
8406
|
+
}
|
|
8407
|
+
}
|
|
8408
|
+
let instance$2 = null;
|
|
8409
|
+
var FollowingSyncEngine$1 = {
|
|
8410
|
+
getInstance: () => {
|
|
8411
|
+
if (!instance$2)
|
|
8412
|
+
instance$2 = new FollowingSyncEngine();
|
|
8413
|
+
return instance$2;
|
|
8414
|
+
},
|
|
8415
|
+
};
|
|
8416
|
+
|
|
8417
|
+
var followingSyncEngineOnLoginHandler = () => {
|
|
8418
|
+
const followingSyncEngine = FollowingSyncEngine$1.getInstance();
|
|
8419
|
+
onSessionStateChange(state => {
|
|
8420
|
+
if (state === "established" /* Amity.SessionStates.ESTABLISHED */) {
|
|
8421
|
+
followingSyncEngine.onSessionEstablished();
|
|
8422
|
+
}
|
|
8423
|
+
else if (state === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */) {
|
|
8424
|
+
followingSyncEngine.onTokenExpired();
|
|
8425
|
+
}
|
|
8426
|
+
else {
|
|
8427
|
+
followingSyncEngine.onSessionDestroyed();
|
|
8428
|
+
}
|
|
8429
|
+
});
|
|
8430
|
+
return () => {
|
|
8431
|
+
followingSyncEngine.onSessionDestroyed();
|
|
8432
|
+
};
|
|
8433
|
+
};
|
|
8434
|
+
|
|
8435
|
+
const createFollowEventSubscriber = (event, callback) => {
|
|
8436
|
+
const client = getActiveClient();
|
|
8437
|
+
const filter = (data) => {
|
|
8438
|
+
const payload = prepareFollowersPayload(data);
|
|
8439
|
+
if (!client.cache) {
|
|
8440
|
+
callback(payload.follows[0]);
|
|
8441
|
+
}
|
|
8442
|
+
else {
|
|
8443
|
+
ingestInCache(payload);
|
|
8444
|
+
callback(payload.follows[0]);
|
|
8445
|
+
}
|
|
8446
|
+
};
|
|
8447
|
+
return createEventSubscriber(client, event, event, filter);
|
|
8448
|
+
};
|
|
8449
|
+
const createLocalFollowEventSubscriber = (event, callback) => {
|
|
8450
|
+
const client = getActiveClient();
|
|
8451
|
+
const filter = (data) => {
|
|
8452
|
+
const payload = prepareFollowStatusPayload(data);
|
|
8453
|
+
if (!client.cache) {
|
|
8454
|
+
callback(payload.follows[0]);
|
|
8455
|
+
}
|
|
8456
|
+
else {
|
|
8457
|
+
ingestInCache(payload);
|
|
8458
|
+
callback(payload.follows[0]);
|
|
8459
|
+
}
|
|
8460
|
+
};
|
|
8461
|
+
return createEventSubscriber(client, event, event, filter);
|
|
8462
|
+
};
|
|
8463
|
+
|
|
8464
|
+
/**
|
|
8465
|
+
* ```js
|
|
8466
|
+
* import { onUserFollowed } from '@amityco/ts-sdk'
|
|
8467
|
+
* const dispose = onUserFollowed(status => {
|
|
8468
|
+
* // ...
|
|
8469
|
+
* })
|
|
8470
|
+
* ```
|
|
8471
|
+
*
|
|
8472
|
+
* Fired when a user follows another users and confirmation is not required
|
|
8473
|
+
*
|
|
8474
|
+
* @param callback The function to call when the event was fired
|
|
8475
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
8476
|
+
*
|
|
8477
|
+
* @category Follow Events
|
|
8478
|
+
*/
|
|
8479
|
+
const onUserFollowed = (callback) => createFollowEventSubscriber('follow.created', callback);
|
|
8480
|
+
|
|
8481
|
+
/**
|
|
8482
|
+
* ```js
|
|
8483
|
+
* import { onFollowerRequested } from '@amityco/ts-sdk'
|
|
8484
|
+
* const dispose = onFollowerRequested(status => {
|
|
8485
|
+
* // ...
|
|
8486
|
+
* })
|
|
8487
|
+
* ```
|
|
8488
|
+
*
|
|
8489
|
+
* Fired when a user follows another users and confirmation is required
|
|
8490
|
+
*
|
|
8491
|
+
* @param callback The function to call when the event was fired
|
|
8492
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
8493
|
+
*
|
|
8494
|
+
* @category Follow Events
|
|
8495
|
+
*/
|
|
8496
|
+
const onFollowerRequested = (callback) => createFollowEventSubscriber('follow.requested', callback);
|
|
8497
|
+
|
|
8498
|
+
/**
|
|
8499
|
+
* ```js
|
|
8500
|
+
* import { onFollowRequestAccepted } from '@amityco/ts-sdk'
|
|
8501
|
+
* const dispose = onFollowRequestAccepted(status => {
|
|
8502
|
+
* // ...
|
|
8503
|
+
* })
|
|
8504
|
+
* ```
|
|
8505
|
+
*
|
|
8506
|
+
* Fired when a follow request has been accepted
|
|
8507
|
+
*
|
|
8508
|
+
* @param callback The function to call when the event was fired
|
|
8509
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
8510
|
+
*
|
|
8511
|
+
* @category Follow Events
|
|
8512
|
+
*/
|
|
8513
|
+
const onFollowRequestAccepted = (callback) => createFollowEventSubscriber('follow.accepted', callback);
|
|
8514
|
+
|
|
8515
|
+
/**
|
|
8516
|
+
* ```js
|
|
8517
|
+
* import { onUserUnfollowed } from '@amityco/ts-sdk'
|
|
8518
|
+
* const dispose = onUserFollowed(status => {
|
|
8519
|
+
* // ...
|
|
8520
|
+
* })
|
|
8521
|
+
* ```
|
|
8522
|
+
*
|
|
8523
|
+
* Fired when a user unfollows
|
|
8524
|
+
*
|
|
8525
|
+
* @param callback The function to call when the event was fired
|
|
8526
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
8527
|
+
*
|
|
8528
|
+
* @category Follow Events
|
|
8529
|
+
*/
|
|
8530
|
+
const onUserUnfollowed = (callback) => createFollowEventSubscriber('follow.unfollowed', callback);
|
|
8531
|
+
|
|
8532
|
+
/**
|
|
8533
|
+
* ```js
|
|
8534
|
+
* import { onFollowRequestCanceled } from '@amityco/ts-sdk'
|
|
8535
|
+
* const dispose = onFollowRequestCanceled(status => {
|
|
8536
|
+
* // ...
|
|
8537
|
+
* })
|
|
8538
|
+
* ```
|
|
8539
|
+
*
|
|
8540
|
+
* Fired when a follow request has been canceled
|
|
8541
|
+
*
|
|
8542
|
+
* @param callback The function to call when the event was fired
|
|
8543
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
8544
|
+
*
|
|
8545
|
+
* @category Follow Events
|
|
8546
|
+
*/
|
|
8547
|
+
const onFollowRequestCanceled = (callback) => createFollowEventSubscriber('follow.requestCanceled', callback);
|
|
8548
|
+
|
|
8549
|
+
/**
|
|
8550
|
+
* ```js
|
|
8551
|
+
* import { onFollowRequestDeclined } from '@amityco/ts-sdk'
|
|
8552
|
+
* const dispose = onFollowRequestDeclined(status => {
|
|
8553
|
+
* // ...
|
|
8554
|
+
* })
|
|
8555
|
+
* ```
|
|
8556
|
+
*
|
|
8557
|
+
* Fired when a follow request has been declined
|
|
8558
|
+
*
|
|
8559
|
+
* @param callback The function to call when the event was fired
|
|
8560
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
8561
|
+
*
|
|
8562
|
+
* @category Follow Events
|
|
8563
|
+
*/
|
|
8564
|
+
const onFollowRequestDeclined = (callback) => createFollowEventSubscriber('follow.requestDeclined', callback);
|
|
8565
|
+
|
|
8566
|
+
/**
|
|
8567
|
+
* ```js
|
|
8568
|
+
* import { onFollowerDeleted } from '@amityco/ts-sdk'
|
|
8569
|
+
* const dispose = onFollowerDeleted(status => {
|
|
8570
|
+
* // ...
|
|
8571
|
+
* })
|
|
8572
|
+
* ```
|
|
8573
|
+
*
|
|
8574
|
+
* Fired when a follower has been deleted
|
|
8575
|
+
*
|
|
8576
|
+
* @param callback The function to call when the event was fired
|
|
8577
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
8578
|
+
*
|
|
8579
|
+
* @category Follow Events
|
|
8580
|
+
*/
|
|
8581
|
+
const onFollowerDeleted = (callback) => createFollowEventSubscriber('follow.followerDeleted', callback);
|
|
8582
|
+
|
|
8583
|
+
const onLocalUserFollowed = (callback) => createLocalFollowEventSubscriber('local.follow.created', callback);
|
|
8584
|
+
|
|
8585
|
+
const onLocalFollowerRequested = (callback) => createLocalFollowEventSubscriber('local.follow.requested', callback);
|
|
8586
|
+
|
|
8587
|
+
const onLocalUserUnfollowed = (callback) => createLocalFollowEventSubscriber('local.follow.unfollowed', callback);
|
|
8588
|
+
|
|
8589
|
+
// Each event file directly, not the events barrel: the barrel's onFollowInfoUpdated imports
|
|
8590
|
+
/**
|
|
8591
|
+
* Keeps `getAllFollowings()` current for the whole session: every follow change — from
|
|
8592
|
+
* this device (local echo) or another (MQTT) — goes to `FollowingSyncEngine.onFollowChanged`,
|
|
8593
|
+
* which ignores follows of other users and applies the rest by status: a follow adds the
|
|
8594
|
+
* user as accepted, a request as pending, an accepted request turns accepted, and an
|
|
8595
|
+
* unfollow, a canceled or declined request, a removed follower or a block takes the user out.
|
|
8596
|
+
* `blockUser` also calls the engine itself: its local event swaps `from` and `to`.
|
|
8597
|
+
* `user.didBlock` is read here rather than through `onUserDidBlock`, which passes on only
|
|
8598
|
+
* the payload's first follow: every follow in it goes to the engine, as on Android and iOS,
|
|
8599
|
+
* so the signed-in user's block is applied wherever it sits in the payload.
|
|
8600
|
+
* The MQTT events arrive on the followers and followings topics of the BLOCK
|
|
8601
|
+
* auto-subscription (on by default).
|
|
8602
|
+
*
|
|
8603
|
+
* Registered via `setupLoginSubscriptions`; the returned unsubscriber is torn
|
|
8604
|
+
* down on logout.
|
|
8605
|
+
*/
|
|
8606
|
+
var followRealtimeOnLoginHandler = () => {
|
|
8607
|
+
const engine = FollowingSyncEngine$1.getInstance();
|
|
8608
|
+
const apply = (follow) => engine.onFollowChanged(follow);
|
|
8609
|
+
const disposers = [
|
|
8610
|
+
onUserFollowed(apply),
|
|
8611
|
+
onFollowerRequested(apply),
|
|
8612
|
+
onFollowRequestAccepted(apply),
|
|
8613
|
+
onUserUnfollowed(apply),
|
|
8614
|
+
onFollowRequestCanceled(apply),
|
|
8615
|
+
onFollowRequestDeclined(apply),
|
|
8616
|
+
onFollowerDeleted(apply),
|
|
8617
|
+
createEventSubscriber(getActiveClient(), 'user.didBlock', 'user.didBlock', payload => { var _a; return ((_a = payload === null || payload === void 0 ? void 0 : payload.follows) !== null && _a !== void 0 ? _a : []).forEach(apply); }),
|
|
8618
|
+
onLocalUserFollowed(apply),
|
|
8619
|
+
onLocalFollowerRequested(apply),
|
|
8620
|
+
onLocalUserUnfollowed(apply),
|
|
8621
|
+
];
|
|
8622
|
+
return () => disposers.forEach(dispose => dispose());
|
|
8623
|
+
};
|
|
8624
|
+
|
|
8288
8625
|
class CursorController {
|
|
8289
8626
|
constructor(networkId, userId) {
|
|
8290
8627
|
this.networkId = networkId;
|
|
@@ -8933,7 +9270,7 @@ const setupLoginSubscriptions = (unsubWatcher) => {
|
|
|
8933
9270
|
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
|
|
8934
9271
|
// the channel because currently backend can't handle this, so every time a user is banned from
|
|
8935
9272
|
// a channel or the channel is deleted the channel's unread count will not be reset to zero
|
|
8936
|
-
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler(), reactionSyncEngineOnLoginHandler(), blockedUserSyncEngineOnLoginHandler(), blockingUserSyncEngineOnLoginHandler(), blockRealtimeOnLoginHandler(), resetAutoSubscriptionsOnLogout(), CursorController.clearOnLogout(), postCommentCountEngineOnLoginHandler(), channelActivityOnLoginHandler(), userFlagByMeOnLoginHandler());
|
|
9273
|
+
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler(), reactionSyncEngineOnLoginHandler(), blockedUserSyncEngineOnLoginHandler(), blockingUserSyncEngineOnLoginHandler(), blockRealtimeOnLoginHandler(), followingSyncEngineOnLoginHandler(), followRealtimeOnLoginHandler(), resetAutoSubscriptionsOnLogout(), CursorController.clearOnLogout(), postCommentCountEngineOnLoginHandler(), channelActivityOnLoginHandler(), userFlagByMeOnLoginHandler());
|
|
8937
9274
|
if (client.useLegacyUnreadCount) {
|
|
8938
9275
|
subscriptions.push(readReceiptSyncEngineOnLoginHandler());
|
|
8939
9276
|
}
|
|
@@ -11262,6 +11599,14 @@ const blockUser = async (userId) => {
|
|
|
11262
11599
|
};
|
|
11263
11600
|
const payload = prepareFollowStatusPayload(blockedUnfollowStatus);
|
|
11264
11601
|
fireEvent('local.follow.unfollowed', payload);
|
|
11602
|
+
// the local event above swaps from and to, so getAllFollowings() cannot see this block in it
|
|
11603
|
+
if (client.userId) {
|
|
11604
|
+
FollowingSyncEngine$1.getInstance().onFollowChanged({
|
|
11605
|
+
from: client.userId,
|
|
11606
|
+
to: userId,
|
|
11607
|
+
status: 'blocked',
|
|
11608
|
+
});
|
|
11609
|
+
}
|
|
11265
11610
|
return data;
|
|
11266
11611
|
};
|
|
11267
11612
|
/* end_public_function */
|
|
@@ -11326,6 +11671,8 @@ const follow = async (userId) => {
|
|
|
11326
11671
|
ingestInCache(data, { cachedAt });
|
|
11327
11672
|
}
|
|
11328
11673
|
const payload = prepareFollowStatusPayload(data);
|
|
11674
|
+
// at once: the local event below is delivered on a later tick
|
|
11675
|
+
FollowingSyncEngine$1.getInstance().onFollowChanged(data.follows[0]);
|
|
11329
11676
|
if (data.follows[0].status === 'accepted') {
|
|
11330
11677
|
fireEvent('local.follow.created', payload);
|
|
11331
11678
|
}
|
|
@@ -11364,6 +11711,8 @@ const unfollow = async (userId) => {
|
|
|
11364
11711
|
ingestInCache(data);
|
|
11365
11712
|
}
|
|
11366
11713
|
const payload = prepareFollowStatusPayload(data);
|
|
11714
|
+
// at once: the local event below is delivered on a later tick
|
|
11715
|
+
FollowingSyncEngine$1.getInstance().onFollowChanged(data.follows[0]);
|
|
11367
11716
|
fireEvent('local.follow.unfollowed', payload);
|
|
11368
11717
|
return true;
|
|
11369
11718
|
};
|
|
@@ -11374,208 +11723,105 @@ const unfollow = async (userId) => {
|
|
|
11374
11723
|
*/
|
|
11375
11724
|
/**
|
|
11376
11725
|
* ```js
|
|
11377
|
-
* import { UserRepository } from '@amityco/ts-sdk'
|
|
11378
|
-
* await UserRepository.Relationship.acceptMyFollower('foobar')
|
|
11379
|
-
* ```
|
|
11380
|
-
*
|
|
11381
|
-
* Accept the follow request
|
|
11382
|
-
*
|
|
11383
|
-
* @param userId the ID of the {@link Amity.InternalUser} follower
|
|
11384
|
-
* @returns A success boolean if the follow request was accepted
|
|
11385
|
-
*
|
|
11386
|
-
* @category Follow API
|
|
11387
|
-
* @async
|
|
11388
|
-
*/
|
|
11389
|
-
const acceptMyFollower = async (userId) => {
|
|
11390
|
-
const client = getActiveClient();
|
|
11391
|
-
client.log('follow/acceptMyFollower', userId);
|
|
11392
|
-
const { data } = await client.http.post(`/api/v4/me/followers/${userId}`);
|
|
11393
|
-
if (client.cache) {
|
|
11394
|
-
ingestInCache(data);
|
|
11395
|
-
}
|
|
11396
|
-
const payload = prepareFollowStatusPayload(data);
|
|
11397
|
-
fireEvent('local.follow.accepted', payload);
|
|
11398
|
-
return true;
|
|
11399
|
-
};
|
|
11400
|
-
/* end_public_function */
|
|
11401
|
-
|
|
11402
|
-
/* begin_public_function
|
|
11403
|
-
id: user.relationship.decline_follow
|
|
11404
|
-
*/
|
|
11405
|
-
/**
|
|
11406
|
-
* ```js
|
|
11407
|
-
* import { UserRepository } from '@amityco/ts-sdk'
|
|
11408
|
-
* await UserRepository.Relationship.declineMyFollower('foobar')
|
|
11409
|
-
* ```
|
|
11410
|
-
*
|
|
11411
|
-
* Decline the follow request or delete the follower
|
|
11412
|
-
*
|
|
11413
|
-
* @param userId the ID of the {@link Amity.InternalUser} follower
|
|
11414
|
-
* @returns A success boolean if the follow request was decline
|
|
11415
|
-
*
|
|
11416
|
-
* @category Follow API
|
|
11417
|
-
* @async
|
|
11418
|
-
*/
|
|
11419
|
-
const declineMyFollower = async (userId) => {
|
|
11420
|
-
const client = getActiveClient();
|
|
11421
|
-
client.log('follow/declineMyFollower', userId);
|
|
11422
|
-
const { data } = await client.http.delete(`/api/v4/me/followers/${userId}`);
|
|
11423
|
-
if (client.cache) {
|
|
11424
|
-
ingestInCache(data);
|
|
11425
|
-
}
|
|
11426
|
-
const payload = prepareFollowStatusPayload(data);
|
|
11427
|
-
fireEvent('local.follow.requestDeclined', payload);
|
|
11428
|
-
return true;
|
|
11429
|
-
};
|
|
11430
|
-
/* end_public_function */
|
|
11431
|
-
|
|
11432
|
-
const createFollowEventSubscriber = (event, callback) => {
|
|
11433
|
-
const client = getActiveClient();
|
|
11434
|
-
const filter = (data) => {
|
|
11435
|
-
const payload = prepareFollowersPayload(data);
|
|
11436
|
-
if (!client.cache) {
|
|
11437
|
-
callback(payload.follows[0]);
|
|
11438
|
-
}
|
|
11439
|
-
else {
|
|
11440
|
-
ingestInCache(payload);
|
|
11441
|
-
callback(payload.follows[0]);
|
|
11442
|
-
}
|
|
11443
|
-
};
|
|
11444
|
-
return createEventSubscriber(client, event, event, filter);
|
|
11445
|
-
};
|
|
11446
|
-
const createLocalFollowEventSubscriber = (event, callback) => {
|
|
11447
|
-
const client = getActiveClient();
|
|
11448
|
-
const filter = (data) => {
|
|
11449
|
-
const payload = prepareFollowStatusPayload(data);
|
|
11450
|
-
if (!client.cache) {
|
|
11451
|
-
callback(payload.follows[0]);
|
|
11452
|
-
}
|
|
11453
|
-
else {
|
|
11454
|
-
ingestInCache(payload);
|
|
11455
|
-
callback(payload.follows[0]);
|
|
11456
|
-
}
|
|
11457
|
-
};
|
|
11458
|
-
return createEventSubscriber(client, event, event, filter);
|
|
11459
|
-
};
|
|
11460
|
-
|
|
11461
|
-
/**
|
|
11462
|
-
* ```js
|
|
11463
|
-
* import { onUserFollowed } from '@amityco/ts-sdk'
|
|
11464
|
-
* const dispose = onUserFollowed(status => {
|
|
11465
|
-
* // ...
|
|
11466
|
-
* })
|
|
11467
|
-
* ```
|
|
11468
|
-
*
|
|
11469
|
-
* Fired when a user follows another users and confirmation is not required
|
|
11470
|
-
*
|
|
11471
|
-
* @param callback The function to call when the event was fired
|
|
11472
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
11473
|
-
*
|
|
11474
|
-
* @category Follow Events
|
|
11475
|
-
*/
|
|
11476
|
-
const onUserFollowed = (callback) => createFollowEventSubscriber('follow.created', callback);
|
|
11477
|
-
|
|
11478
|
-
/**
|
|
11479
|
-
* ```js
|
|
11480
|
-
* import { onUserUnfollowed } from '@amityco/ts-sdk'
|
|
11481
|
-
* const dispose = onUserFollowed(status => {
|
|
11482
|
-
* // ...
|
|
11483
|
-
* })
|
|
11484
|
-
* ```
|
|
11485
|
-
*
|
|
11486
|
-
* Fired when a user unfollows
|
|
11487
|
-
*
|
|
11488
|
-
* @param callback The function to call when the event was fired
|
|
11489
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
11490
|
-
*
|
|
11491
|
-
* @category Follow Events
|
|
11492
|
-
*/
|
|
11493
|
-
const onUserUnfollowed = (callback) => createFollowEventSubscriber('follow.unfollowed', callback);
|
|
11494
|
-
|
|
11495
|
-
/**
|
|
11496
|
-
* ```js
|
|
11497
|
-
* import { onFollowerDeleted } from '@amityco/ts-sdk'
|
|
11498
|
-
* const dispose = onFollowerDeleted(status => {
|
|
11499
|
-
* // ...
|
|
11500
|
-
* })
|
|
11501
|
-
* ```
|
|
11502
|
-
*
|
|
11503
|
-
* Fired when a follower has been deleted
|
|
11504
|
-
*
|
|
11505
|
-
* @param callback The function to call when the event was fired
|
|
11506
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
11507
|
-
*
|
|
11508
|
-
* @category Follow Events
|
|
11509
|
-
*/
|
|
11510
|
-
const onFollowerDeleted = (callback) => createFollowEventSubscriber('follow.followerDeleted', callback);
|
|
11511
|
-
|
|
11512
|
-
/**
|
|
11513
|
-
* ```js
|
|
11514
|
-
* import { onFollowerRequested } from '@amityco/ts-sdk'
|
|
11515
|
-
* const dispose = onFollowerRequested(status => {
|
|
11516
|
-
* // ...
|
|
11517
|
-
* })
|
|
11726
|
+
* import { UserRepository } from '@amityco/ts-sdk'
|
|
11727
|
+
* await UserRepository.Relationship.acceptMyFollower('foobar')
|
|
11518
11728
|
* ```
|
|
11519
11729
|
*
|
|
11520
|
-
*
|
|
11730
|
+
* Accept the follow request
|
|
11521
11731
|
*
|
|
11522
|
-
* @param
|
|
11523
|
-
* @returns
|
|
11732
|
+
* @param userId the ID of the {@link Amity.InternalUser} follower
|
|
11733
|
+
* @returns A success boolean if the follow request was accepted
|
|
11524
11734
|
*
|
|
11525
|
-
* @category Follow
|
|
11735
|
+
* @category Follow API
|
|
11736
|
+
* @async
|
|
11526
11737
|
*/
|
|
11527
|
-
const
|
|
11738
|
+
const acceptMyFollower = async (userId) => {
|
|
11739
|
+
const client = getActiveClient();
|
|
11740
|
+
client.log('follow/acceptMyFollower', userId);
|
|
11741
|
+
const { data } = await client.http.post(`/api/v4/me/followers/${userId}`);
|
|
11742
|
+
if (client.cache) {
|
|
11743
|
+
ingestInCache(data);
|
|
11744
|
+
}
|
|
11745
|
+
const payload = prepareFollowStatusPayload(data);
|
|
11746
|
+
fireEvent('local.follow.accepted', payload);
|
|
11747
|
+
return true;
|
|
11748
|
+
};
|
|
11749
|
+
/* end_public_function */
|
|
11528
11750
|
|
|
11751
|
+
/* begin_public_function
|
|
11752
|
+
id: user.relationship.decline_follow
|
|
11753
|
+
*/
|
|
11529
11754
|
/**
|
|
11530
11755
|
* ```js
|
|
11531
|
-
* import {
|
|
11532
|
-
*
|
|
11533
|
-
* // ...
|
|
11534
|
-
* })
|
|
11756
|
+
* import { UserRepository } from '@amityco/ts-sdk'
|
|
11757
|
+
* await UserRepository.Relationship.declineMyFollower('foobar')
|
|
11535
11758
|
* ```
|
|
11536
11759
|
*
|
|
11537
|
-
*
|
|
11760
|
+
* Decline the follow request or delete the follower
|
|
11538
11761
|
*
|
|
11539
|
-
* @param
|
|
11540
|
-
* @returns
|
|
11762
|
+
* @param userId the ID of the {@link Amity.InternalUser} follower
|
|
11763
|
+
* @returns A success boolean if the follow request was decline
|
|
11541
11764
|
*
|
|
11542
|
-
* @category Follow
|
|
11765
|
+
* @category Follow API
|
|
11766
|
+
* @async
|
|
11543
11767
|
*/
|
|
11544
|
-
const
|
|
11768
|
+
const declineMyFollower = async (userId) => {
|
|
11769
|
+
const client = getActiveClient();
|
|
11770
|
+
client.log('follow/declineMyFollower', userId);
|
|
11771
|
+
const { data } = await client.http.delete(`/api/v4/me/followers/${userId}`);
|
|
11772
|
+
if (client.cache) {
|
|
11773
|
+
ingestInCache(data);
|
|
11774
|
+
}
|
|
11775
|
+
const payload = prepareFollowStatusPayload(data);
|
|
11776
|
+
fireEvent('local.follow.requestDeclined', payload);
|
|
11777
|
+
return true;
|
|
11778
|
+
};
|
|
11779
|
+
/* end_public_function */
|
|
11545
11780
|
|
|
11781
|
+
/* begin_public_function
|
|
11782
|
+
id: user.relationship.get_all_followings
|
|
11783
|
+
*/
|
|
11546
11784
|
/**
|
|
11547
11785
|
* ```js
|
|
11548
|
-
* import {
|
|
11549
|
-
* const dispose = onFollowRequestAccepted(status => {
|
|
11550
|
-
* // ...
|
|
11551
|
-
* })
|
|
11552
|
-
* ```
|
|
11786
|
+
* import { UserRepository } from '@amityco/ts-sdk'
|
|
11553
11787
|
*
|
|
11554
|
-
*
|
|
11788
|
+
* const followings = await UserRepository.Relationship.getAllFollowings()
|
|
11789
|
+
* const statusOf = new Map(followings.map(f => [f.userId, f.status]))
|
|
11790
|
+
* // 'accepted' → no button; 'pending' → Pending; missing → Follow
|
|
11791
|
+
* ```
|
|
11555
11792
|
*
|
|
11556
|
-
*
|
|
11557
|
-
*
|
|
11793
|
+
* Returns whom the signed-in user follows as a one-shot list of at most 5,000 (the most a
|
|
11794
|
+
* user can follow), from one request with no paging: each followed user's id and the
|
|
11795
|
+
* follow's status — `accepted`, or `pending` for a request not yet accepted. A user
|
|
11796
|
+
* missing from the list is not followed. The list holds ids and statuses only, no user
|
|
11797
|
+
* profiles.
|
|
11558
11798
|
*
|
|
11559
|
-
*
|
|
11560
|
-
|
|
11561
|
-
const onFollowRequestAccepted = (callback) => createFollowEventSubscriber('follow.accepted', callback);
|
|
11562
|
-
|
|
11563
|
-
/**
|
|
11564
|
-
* ```js
|
|
11565
|
-
* import { onFollowRequestDeclined } from '@amityco/ts-sdk'
|
|
11566
|
-
* const dispose = onFollowRequestDeclined(status => {
|
|
11567
|
-
* // ...
|
|
11568
|
-
* })
|
|
11569
|
-
* ```
|
|
11799
|
+
* Use it to show the follow button next to each author in the post feed: match each
|
|
11800
|
+
* author by user id against `userId`.
|
|
11570
11801
|
*
|
|
11571
|
-
*
|
|
11802
|
+
* Keeping the app current: the function answers once, so call it again to see changes —
|
|
11803
|
+
* for example when more posts load or when the feed comes back into view. The answer is
|
|
11804
|
+
* kept on the device for 5 minutes, so a call within that window costs no request. Changes
|
|
11805
|
+
* made in this app show at once. Changes made elsewhere — on another device, or by the
|
|
11806
|
+
* other user accepting a request or removing the user as a follower — show once their
|
|
11807
|
+
* real-time event arrives; the SDK receives these on the followers and followings topics
|
|
11808
|
+
* of `AmityAutoSubscription.BLOCK`, on by default. An event missed while offline, or with
|
|
11809
|
+
* that subscription turned off, shows at the next fetch, after the 5 minutes.
|
|
11572
11810
|
*
|
|
11573
|
-
* @
|
|
11574
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
11811
|
+
* @returns A promise that resolves to the signed-in user's {@link Amity.FollowingUserStatus} list
|
|
11575
11812
|
*
|
|
11576
|
-
* @category Follow
|
|
11813
|
+
* @category Follow API
|
|
11814
|
+
* @async
|
|
11577
11815
|
*/
|
|
11578
|
-
const
|
|
11816
|
+
const getAllFollowings = async () => {
|
|
11817
|
+
const client = getActiveClient();
|
|
11818
|
+
client.log('follow/getAllFollowings');
|
|
11819
|
+
const engine = FollowingSyncEngine$1.getInstance();
|
|
11820
|
+
// Fetch only when the 5-minute window has expired (no-op otherwise)
|
|
11821
|
+
await engine.ensureFetched();
|
|
11822
|
+
return engine.getFollowings();
|
|
11823
|
+
};
|
|
11824
|
+
/* end_public_function */
|
|
11579
11825
|
|
|
11580
11826
|
/**
|
|
11581
11827
|
* ```js
|
|
@@ -11681,12 +11927,6 @@ const onFollowInfoUpdated = (callback) => {
|
|
|
11681
11927
|
};
|
|
11682
11928
|
};
|
|
11683
11929
|
|
|
11684
|
-
const onLocalUserFollowed = (callback) => createLocalFollowEventSubscriber('local.follow.created', callback);
|
|
11685
|
-
|
|
11686
|
-
const onLocalUserUnfollowed = (callback) => createLocalFollowEventSubscriber('local.follow.unfollowed', callback);
|
|
11687
|
-
|
|
11688
|
-
const onLocalFollowerRequested = (callback) => createLocalFollowEventSubscriber('local.follow.requested', callback);
|
|
11689
|
-
|
|
11690
11930
|
const onLocalFollowRequestAccepted = (callback) => createLocalFollowEventSubscriber('local.follow.accepted', callback);
|
|
11691
11931
|
|
|
11692
11932
|
const onLocalFollowRequestDeclined = (callback) => createLocalFollowEventSubscriber('local.follow.requestDeclined', callback);
|
|
@@ -11738,22 +11978,9 @@ class PaginationController {
|
|
|
11738
11978
|
|
|
11739
11979
|
class FollowerPaginationController extends PaginationController {
|
|
11740
11980
|
async getRequest(queryParams, token) {
|
|
11741
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, userId
|
|
11742
|
-
const client = getActiveClient();
|
|
11743
|
-
if (userIds) {
|
|
11744
|
-
// An empty filter matches nobody; sending no ids would return the whole list instead
|
|
11745
|
-
if (userIds.length === 0)
|
|
11746
|
-
return { follows: [], users: [], files: [], paging: {} };
|
|
11747
|
-
if (client.userId !== userId) {
|
|
11748
|
-
throw new ASCInvalidParameterError("userIds can only be used on the signed-in user's own followers list");
|
|
11749
|
-
}
|
|
11750
|
-
// core reads `limit` and `token` only as top-level params, never inside `options`
|
|
11751
|
-
const { data: queryResponse } = await this.http.get(`/api/v4/me/followers`, {
|
|
11752
|
-
params: Object.assign(Object.assign(Object.assign(Object.assign({}, params), { userIds, limit: FOLLOW_USER_IDS_PAGINATION_LIMIT }), (token && { token })), { isDeleted: false }),
|
|
11753
|
-
});
|
|
11754
|
-
return queryResponse;
|
|
11755
|
-
}
|
|
11981
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, userId } = queryParams, params = __rest(queryParams, ["limit", "userId"]);
|
|
11756
11982
|
const options = token ? { token } : { limit };
|
|
11983
|
+
const client = getActiveClient();
|
|
11757
11984
|
const path = client.userId === userId ? `/api/v4/me/followers` : `/api/v4/users/${userId}/followers`;
|
|
11758
11985
|
const { data: queryResponse } = await this.http.get(path, {
|
|
11759
11986
|
params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
|
|
@@ -12037,11 +12264,6 @@ class FollowerLiveCollectionController extends LiveCollectionController {
|
|
|
12037
12264
|
const fromUser = (_a = pullFromCache(['user', 'get', follower.from])) === null || _a === void 0 ? void 0 : _a.data;
|
|
12038
12265
|
return (fromUser === null || fromUser === void 0 ? void 0 : fromUser.isDeleted) == null || (fromUser === null || fromUser === void 0 ? void 0 : fromUser.isDeleted) === false;
|
|
12039
12266
|
});
|
|
12040
|
-
// With a userIds filter, keep realtime follows with other users out of the list
|
|
12041
|
-
if (this.query.userIds) {
|
|
12042
|
-
const userIds = new Set(this.query.userIds);
|
|
12043
|
-
followers = followers.filter(follower => userIds.has(follower.from));
|
|
12044
|
-
}
|
|
12045
12267
|
return followers;
|
|
12046
12268
|
}
|
|
12047
12269
|
}
|
|
@@ -12061,20 +12283,7 @@ class FollowerLiveCollectionController extends LiveCollectionController {
|
|
|
12061
12283
|
*
|
|
12062
12284
|
* Observe all mutations on a list of {@link Amity.FollowStatus} followers for a given userId
|
|
12063
12285
|
*
|
|
12064
|
-
*
|
|
12065
|
-
* user's `userId` and up to 100 `userIds`. The result only holds those users, in one page:
|
|
12066
|
-
*
|
|
12067
|
-
* ```js
|
|
12068
|
-
* getFollowers({ userId: client.userId, userIds: ['a', 'b', 'c'] }, ({ data }) => {
|
|
12069
|
-
* // users missing from `data` have no relationship
|
|
12070
|
-
* })
|
|
12071
|
-
* ```
|
|
12072
|
-
*
|
|
12073
|
-
* @param params.userId the user
|
|
12074
|
-
* @param params.status filter by follow status, defaults to all
|
|
12075
|
-
* @param params.userIds only return the followers with these users (up to 100 ids, in one page).
|
|
12076
|
-
* A user missing from the result has no relationship. Only allowed when `userId` is the
|
|
12077
|
-
* signed-in user, otherwise the callback gets an {@link ASCInvalidParameterError}.
|
|
12286
|
+
* @param userId the user
|
|
12078
12287
|
* @param callback the function to call when new data are available
|
|
12079
12288
|
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
12080
12289
|
*
|
|
@@ -12100,22 +12309,9 @@ const getFollowers = (params, callback, config) => {
|
|
|
12100
12309
|
|
|
12101
12310
|
class FollowingPaginationController extends PaginationController {
|
|
12102
12311
|
async getRequest(queryParams, token) {
|
|
12103
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, userId
|
|
12104
|
-
const client = getActiveClient();
|
|
12105
|
-
if (userIds) {
|
|
12106
|
-
// An empty filter matches nobody; sending no ids would return the whole list instead
|
|
12107
|
-
if (userIds.length === 0)
|
|
12108
|
-
return { follows: [], users: [], files: [], paging: {} };
|
|
12109
|
-
if (client.userId !== userId) {
|
|
12110
|
-
throw new ASCInvalidParameterError("userIds can only be used on the signed-in user's own following list");
|
|
12111
|
-
}
|
|
12112
|
-
// core reads `limit` and `token` only as top-level params, never inside `options`
|
|
12113
|
-
const { data: queryResponse } = await this.http.get(`/api/v4/me/following`, {
|
|
12114
|
-
params: Object.assign(Object.assign(Object.assign(Object.assign({}, params), { userIds, limit: FOLLOW_USER_IDS_PAGINATION_LIMIT }), (token && { token })), { isDeleted: false }),
|
|
12115
|
-
});
|
|
12116
|
-
return queryResponse;
|
|
12117
|
-
}
|
|
12312
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, userId } = queryParams, params = __rest(queryParams, ["limit", "userId"]);
|
|
12118
12313
|
const options = token ? { token } : { limit };
|
|
12314
|
+
const client = getActiveClient();
|
|
12119
12315
|
const path = client.userId === userId ? `/api/v4/me/following` : `/api/v4/users/${userId}/following`;
|
|
12120
12316
|
const { data: queryResponse } = await this.http.get(path, {
|
|
12121
12317
|
params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
|
|
@@ -12275,11 +12471,6 @@ class FollowingLiveCollectionController extends LiveCollectionController {
|
|
|
12275
12471
|
const toUser = (_a = pullFromCache(['user', 'get', following.to])) === null || _a === void 0 ? void 0 : _a.data;
|
|
12276
12472
|
return (toUser === null || toUser === void 0 ? void 0 : toUser.isDeleted) == null || (toUser === null || toUser === void 0 ? void 0 : toUser.isDeleted) === false;
|
|
12277
12473
|
});
|
|
12278
|
-
// With a userIds filter, keep realtime follows with other users out of the list
|
|
12279
|
-
if (this.query.userIds) {
|
|
12280
|
-
const userIds = new Set(this.query.userIds);
|
|
12281
|
-
followings = followings.filter(following => userIds.has(following.to));
|
|
12282
|
-
}
|
|
12283
12474
|
return followings;
|
|
12284
12475
|
}
|
|
12285
12476
|
}
|
|
@@ -12299,20 +12490,7 @@ class FollowingLiveCollectionController extends LiveCollectionController {
|
|
|
12299
12490
|
*
|
|
12300
12491
|
* Observe all mutations on a list of {@link Amity.FollowStatus} followings for a given userId
|
|
12301
12492
|
*
|
|
12302
|
-
*
|
|
12303
|
-
* user's `userId` and up to 100 `userIds`. The result only holds those users, in one page:
|
|
12304
|
-
*
|
|
12305
|
-
* ```js
|
|
12306
|
-
* getFollowings({ userId: client.userId, userIds: ['a', 'b', 'c'] }, ({ data }) => {
|
|
12307
|
-
* // users missing from `data` have no relationship
|
|
12308
|
-
* })
|
|
12309
|
-
* ```
|
|
12310
|
-
*
|
|
12311
|
-
* @param params.userId the user
|
|
12312
|
-
* @param params.status filter by follow status, defaults to all
|
|
12313
|
-
* @param params.userIds only return the followings with these users (up to 100 ids, in one page).
|
|
12314
|
-
* A user missing from the result has no relationship. Only allowed when `userId` is the
|
|
12315
|
-
* signed-in user, otherwise the callback gets an {@link ASCInvalidParameterError}.
|
|
12493
|
+
* @param userId the user
|
|
12316
12494
|
* @param callback the function to call when new data are available
|
|
12317
12495
|
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
12318
12496
|
*
|
|
@@ -12470,6 +12648,7 @@ var index$s = /*#__PURE__*/Object.freeze({
|
|
|
12470
12648
|
unfollow: unfollow,
|
|
12471
12649
|
acceptMyFollower: acceptMyFollower,
|
|
12472
12650
|
declineMyFollower: declineMyFollower,
|
|
12651
|
+
getAllFollowings: getAllFollowings,
|
|
12473
12652
|
onUserFollowed: onUserFollowed,
|
|
12474
12653
|
onUserUnfollowed: onUserUnfollowed,
|
|
12475
12654
|
onFollowerDeleted: onFollowerDeleted,
|
|
@@ -30554,6 +30733,189 @@ const getForYouFeed = (callback) => {
|
|
|
30554
30733
|
};
|
|
30555
30734
|
/* end_public_function */
|
|
30556
30735
|
|
|
30736
|
+
class FollowingFeedQueryStreamController extends QueryStreamController {
|
|
30737
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
30738
|
+
super(query, cacheKey);
|
|
30739
|
+
this.notifyChange = notifyChange;
|
|
30740
|
+
this.preparePayload = preparePayload;
|
|
30741
|
+
}
|
|
30742
|
+
async saveToMainDB(response) {
|
|
30743
|
+
const processedPayload = await this.preparePayload(response);
|
|
30744
|
+
const client = getActiveClient();
|
|
30745
|
+
const cachedAt = client.cache && Date.now();
|
|
30746
|
+
if (client.cache) {
|
|
30747
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
30748
|
+
}
|
|
30749
|
+
}
|
|
30750
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
30751
|
+
var _a, _b;
|
|
30752
|
+
if (refresh) {
|
|
30753
|
+
pushToCache(this.cacheKey, {
|
|
30754
|
+
data: response.posts.map(getResolver('post')),
|
|
30755
|
+
});
|
|
30756
|
+
}
|
|
30757
|
+
else {
|
|
30758
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30759
|
+
const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
30760
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
|
|
30761
|
+
}
|
|
30762
|
+
}
|
|
30763
|
+
/**
|
|
30764
|
+
* The SDK does not know the viewer's follow list or the network's `social.globalFeed`
|
|
30765
|
+
* switches, so it cannot tell whether a new post belongs in this feed. A created or
|
|
30766
|
+
* approved post, by anyone (the current user included), never changes the list: it
|
|
30767
|
+
* appears on the next first-page load. Deleted and declined posts are removed; any
|
|
30768
|
+
* other event re-emits so listed posts render their new state.
|
|
30769
|
+
*/
|
|
30770
|
+
reactor(action) {
|
|
30771
|
+
return (post) => {
|
|
30772
|
+
var _a;
|
|
30773
|
+
if (action === EnumPostActions.OnPostCreated || action === EnumPostActions.OnPostApproved) {
|
|
30774
|
+
return;
|
|
30775
|
+
}
|
|
30776
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30777
|
+
if (!collection)
|
|
30778
|
+
return;
|
|
30779
|
+
// A child post event never adds or removes an entry; it re-emits only when its parent is listed
|
|
30780
|
+
if (post.parentPostId) {
|
|
30781
|
+
if (!collection.data.includes(post.parentPostId))
|
|
30782
|
+
return;
|
|
30783
|
+
}
|
|
30784
|
+
else if (action === EnumPostActions.OnPostDeleted ||
|
|
30785
|
+
action === EnumPostActions.OnPostDeclined) {
|
|
30786
|
+
collection.data = collection.data.filter(postId => postId !== post.postId);
|
|
30787
|
+
}
|
|
30788
|
+
pushToCache(this.cacheKey, collection);
|
|
30789
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
30790
|
+
};
|
|
30791
|
+
}
|
|
30792
|
+
subscribeRTE(createSubscriber) {
|
|
30793
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
30794
|
+
}
|
|
30795
|
+
}
|
|
30796
|
+
|
|
30797
|
+
/**
|
|
30798
|
+
* `GET /api/v1/me/following-feeds` reads `limit` and `token` as flat query params.
|
|
30799
|
+
* Unlike the global feed, they must not be nested in `options`: the endpoint forwards
|
|
30800
|
+
* only `{ limit, token }`, so a nested token would be dropped and every page would be page one.
|
|
30801
|
+
*/
|
|
30802
|
+
class FollowingFeedPaginationController extends PaginationController {
|
|
30803
|
+
async getRequest(queryParams, token) {
|
|
30804
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_SIZE, sortBy } = queryParams;
|
|
30805
|
+
const params = token ? { token } : { limit };
|
|
30806
|
+
if (sortBy)
|
|
30807
|
+
params.sortBy = sortBy;
|
|
30808
|
+
const { data: queryResponse } = await this.http.get(API_ENDPOINTS.followingFeed, { params });
|
|
30809
|
+
return queryResponse;
|
|
30810
|
+
}
|
|
30811
|
+
}
|
|
30812
|
+
|
|
30813
|
+
class FollowingFeedLiveCollectionController extends LiveCollectionController {
|
|
30814
|
+
constructor(query, callback) {
|
|
30815
|
+
const queryStreamId = hash__default["default"](query);
|
|
30816
|
+
const cacheKey = ['followingFeed', 'collection', queryStreamId];
|
|
30817
|
+
const paginationController = new FollowingFeedPaginationController(query);
|
|
30818
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
30819
|
+
this.query = query;
|
|
30820
|
+
this.queryStreamController = new FollowingFeedQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
|
|
30821
|
+
this.callback = callback.bind(this);
|
|
30822
|
+
this.loadPage({ initial: true });
|
|
30823
|
+
}
|
|
30824
|
+
setup() {
|
|
30825
|
+
var _a;
|
|
30826
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30827
|
+
if (!collection) {
|
|
30828
|
+
pushToCache(this.cacheKey, {
|
|
30829
|
+
data: [],
|
|
30830
|
+
params: {},
|
|
30831
|
+
});
|
|
30832
|
+
}
|
|
30833
|
+
}
|
|
30834
|
+
async persistModel(queryPayload) {
|
|
30835
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
30836
|
+
}
|
|
30837
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
30838
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
30839
|
+
}
|
|
30840
|
+
startSubscription() {
|
|
30841
|
+
return this.queryStreamController.subscribeRTE(getGlobalFeedSubscriptions(this.cacheKey));
|
|
30842
|
+
}
|
|
30843
|
+
notifyChange({ origin, loading, error }) {
|
|
30844
|
+
var _a, _b;
|
|
30845
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30846
|
+
if (!collection)
|
|
30847
|
+
return;
|
|
30848
|
+
const data = ((_b = collection.data
|
|
30849
|
+
.map(id => pullFromCache(['post', 'get', id]))
|
|
30850
|
+
.filter(isNonNullable)
|
|
30851
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
|
|
30852
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
30853
|
+
return;
|
|
30854
|
+
this.callback({
|
|
30855
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
30856
|
+
data,
|
|
30857
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
30858
|
+
loading,
|
|
30859
|
+
error,
|
|
30860
|
+
});
|
|
30861
|
+
}
|
|
30862
|
+
}
|
|
30863
|
+
|
|
30864
|
+
/* begin_public_function
|
|
30865
|
+
id: feed.query.following_feed
|
|
30866
|
+
api_style: live_collection
|
|
30867
|
+
*/
|
|
30868
|
+
/**
|
|
30869
|
+
* ```js
|
|
30870
|
+
* import { FeedRepository, FollowingFeedSortByEnum } from '@amityco/ts-sdk'
|
|
30871
|
+
*
|
|
30872
|
+
* const unsub = FeedRepository.getFollowingFeed(
|
|
30873
|
+
* { sortBy: FollowingFeedSortByEnum.LastCreated, limit: 20 },
|
|
30874
|
+
* ({ data: posts, hasNextPage, onNextPage, loading, error }) => processResponse(posts),
|
|
30875
|
+
* )
|
|
30876
|
+
* ```
|
|
30877
|
+
*
|
|
30878
|
+
* Observe all mutations on a list of {@link Amity.Post} for the current user's following feed.
|
|
30879
|
+
* Which posts match is decided by the server, from the network's `social.globalFeed` setting:
|
|
30880
|
+
* - `lastCreated`: posts by the users the current user follows, plus the current user's own
|
|
30881
|
+
* posts, newest first.
|
|
30882
|
+
* - `customRanking` (the default): server-ranked posts by the current user, the users they
|
|
30883
|
+
* follow and the communities they joined.
|
|
30884
|
+
*
|
|
30885
|
+
* A new post, the current user's own included, is not added in real time: it appears
|
|
30886
|
+
* when the feed is next loaded from the first page (for example, a new subscription).
|
|
30887
|
+
* With `customRanking` the server may take up to 5 minutes to include it.
|
|
30888
|
+
* Deleted and declined posts are removed at once. Mixed-structure posts are not filtered.
|
|
30889
|
+
*
|
|
30890
|
+
* When the network enforces module entitlement and the `feed` module is not entitled,
|
|
30891
|
+
* the request fails with `400325` (`ModuleNotEntitled`), reported through `error`.
|
|
30892
|
+
*
|
|
30893
|
+
* @param params.sortBy order of the feed. When omitted, the server default (`customRanking`) applies
|
|
30894
|
+
* @param params.limit page size of the first request (1 - 100)
|
|
30895
|
+
* @param callback the function to call when new data are available
|
|
30896
|
+
* @param config
|
|
30897
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the posts
|
|
30898
|
+
*
|
|
30899
|
+
* @category Posts Live Collection
|
|
30900
|
+
*/
|
|
30901
|
+
const getFollowingFeed = (params, callback, config) => {
|
|
30902
|
+
const { log, cache } = getActiveClient();
|
|
30903
|
+
if (!cache) {
|
|
30904
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
30905
|
+
}
|
|
30906
|
+
const timestamp = Date.now();
|
|
30907
|
+
log(`getFollowingFeed(tmpid: ${timestamp}) > listen`);
|
|
30908
|
+
const liveCollection = new FollowingFeedLiveCollectionController(params, callback);
|
|
30909
|
+
const disposers = liveCollection.startSubscription();
|
|
30910
|
+
const cacheKey = liveCollection.getCacheKey();
|
|
30911
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
30912
|
+
return () => {
|
|
30913
|
+
log(`getFollowingFeed(tmpid: ${timestamp}) > dispose`);
|
|
30914
|
+
disposers.forEach(fn => fn());
|
|
30915
|
+
};
|
|
30916
|
+
};
|
|
30917
|
+
/* end_public_function */
|
|
30918
|
+
|
|
30557
30919
|
var index$e = /*#__PURE__*/Object.freeze({
|
|
30558
30920
|
__proto__: null,
|
|
30559
30921
|
queryGlobalFeed: queryGlobalFeed,
|
|
@@ -30562,6 +30924,7 @@ var index$e = /*#__PURE__*/Object.freeze({
|
|
|
30562
30924
|
getUserFeed: getUserFeed,
|
|
30563
30925
|
getCommunityFeed: getCommunityFeed,
|
|
30564
30926
|
getForYouFeed: getForYouFeed,
|
|
30927
|
+
getFollowingFeed: getFollowingFeed,
|
|
30565
30928
|
AmityForYouFeedDisabledError: AmityForYouFeedDisabledError
|
|
30566
30929
|
});
|
|
30567
30930
|
|