@amityco/ts-sdk 6.32.4 → 6.32.5-2690585.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env +26 -26
- package/dist/@types/core/events.d.ts +16 -2
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +3 -0
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/pinnedPost.d.ts +1 -0
- package/dist/@types/domains/pinnedPost.d.ts.map +1 -1
- package/dist/@types/domains/reaction.d.ts +8 -2
- package/dist/@types/domains/reaction.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/utils.d.ts.map +1 -1
- package/dist/communityRepository/utils/communityWithMembership.d.ts.map +1 -1
- package/dist/feedRepository/api/queryGlobalFeed.d.ts.map +1 -1
- package/dist/index.cjs.js +906 -568
- package/dist/index.esm.js +906 -568
- package/dist/index.umd.js +4 -4
- package/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostLiveCollectionController.d.ts +13 -0
- package/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostLiveCollectionController.d.ts.map +1 -0
- package/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostPaginationController.d.ts +13 -0
- package/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostPaginationController.d.ts.map +1 -0
- package/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostQueryStreamController.d.ts +15 -0
- package/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostQueryStreamController.d.ts.map +1 -0
- package/dist/postRepository/observers/getGlobalPinnedPosts.d.ts +10 -0
- package/dist/postRepository/observers/getGlobalPinnedPosts.d.ts.map +1 -0
- package/dist/postRepository/observers/index.d.ts +1 -0
- package/dist/postRepository/observers/index.d.ts.map +1 -1
- package/dist/reactionRepository/api/addReaction.d.ts.map +1 -1
- package/dist/reactionRepository/api/removeReaction.d.ts.map +1 -1
- package/dist/reactionRepository/events/onReactorAddedLocal.d.ts +19 -0
- package/dist/reactionRepository/events/onReactorAddedLocal.d.ts.map +1 -0
- package/dist/reactionRepository/events/onReactorRemovedLocal.d.ts +19 -0
- package/dist/reactionRepository/events/onReactorRemovedLocal.d.ts.map +1 -0
- package/dist/reactionRepository/observers/getReactions/ReactionLiveCollectionController.d.ts +13 -0
- package/dist/reactionRepository/observers/getReactions/ReactionLiveCollectionController.d.ts.map +1 -0
- package/dist/reactionRepository/observers/getReactions/ReactionPaginationController.d.ts +5 -0
- package/dist/reactionRepository/observers/getReactions/ReactionPaginationController.d.ts.map +1 -0
- package/dist/reactionRepository/observers/getReactions/ReactionQueryStreamController.d.ts +14 -0
- package/dist/reactionRepository/observers/getReactions/ReactionQueryStreamController.d.ts.map +1 -0
- package/dist/reactionRepository/observers/getReactions/getReactions.d.ts.map +1 -0
- package/dist/reactionRepository/observers/getReactions/index.d.ts +2 -0
- package/dist/reactionRepository/observers/getReactions/index.d.ts.map +1 -0
- package/dist/reactionRepository/observers/index.d.ts +1 -1
- package/dist/reactionRepository/observers/index.d.ts.map +1 -1
- package/dist/storyRepository/observers/getGlobalStoryTargets/GlobalStoryLiveCollectionController.d.ts.map +1 -1
- package/dist/storyRepository/observers/getGlobalStoryTargets/GlobalStoryQueryStreamController.d.ts +1 -1
- package/dist/storyRepository/observers/getGlobalStoryTargets/GlobalStoryQueryStreamController.d.ts.map +1 -1
- package/dist/userRepository/observers/getBlockedUsers/BlockedUserLiveCollectionController.d.ts.map +1 -1
- package/dist/userRepository/observers/getBlockedUsers/BlockedUserQueryStreamController.d.ts +3 -2
- package/dist/userRepository/observers/getBlockedUsers/BlockedUserQueryStreamController.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/core/events.ts +18 -6
- package/src/@types/core/payload.ts +4 -0
- package/src/@types/domains/pin.ts +1 -1
- package/src/@types/domains/pinnedPost.ts +2 -0
- package/src/@types/domains/reaction.ts +9 -3
- package/src/communityRepository/communityMembership/events/utils.ts +4 -2
- package/src/communityRepository/utils/communityWithMembership.ts +15 -8
- package/src/feedRepository/api/queryGlobalFeed.ts +4 -1
- package/src/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostLiveCollectionController.ts +96 -0
- package/src/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostPaginationController.ts +19 -0
- package/src/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostQueryStreamController.ts +88 -0
- package/src/postRepository/observers/getGlobalPinnedPosts.ts +42 -0
- package/src/postRepository/observers/index.ts +1 -0
- package/src/reactionRepository/api/addReaction.ts +23 -1
- package/src/reactionRepository/api/removeReaction.ts +25 -2
- package/src/reactionRepository/events/onReactorAddedLocal.ts +95 -0
- package/src/reactionRepository/events/onReactorRemovedLocal.ts +94 -0
- package/src/reactionRepository/observers/getReactions/ReactionLiveCollectionController.ts +111 -0
- package/src/reactionRepository/observers/getReactions/ReactionPaginationController.ts +30 -0
- package/src/reactionRepository/observers/getReactions/ReactionQueryStreamController.ts +92 -0
- package/src/reactionRepository/observers/getReactions/getReactions.ts +57 -0
- package/src/reactionRepository/observers/getReactions/index.ts +1 -0
- package/src/reactionRepository/observers/index.ts +1 -1
- package/src/storyRepository/events/onStoryReactionAdded.ts +3 -3
- package/src/storyRepository/events/onStoryReactionRemoved.ts +3 -3
- package/src/storyRepository/observers/getGlobalStoryTargets/GlobalStoryLiveCollectionController.ts +5 -0
- package/src/storyRepository/observers/getGlobalStoryTargets/GlobalStoryQueryStreamController.ts +5 -2
- package/src/userRepository/observers/getBlockedUsers/BlockedUserLiveCollectionController.ts +12 -1
- package/src/userRepository/observers/getBlockedUsers/BlockedUserQueryStreamController.ts +13 -5
- package/src/userRepository/relationship/follow/observers/getFollowers/FollowerLiveCollectionController.ts +1 -1
- package/src/userRepository/relationship/follow/observers/getFollowings/FollowingLiveCollectionController.ts +1 -1
- package/dist/reactionRepository/observers/getReactions.d.ts.map +0 -1
- package/src/reactionRepository/observers/getReactions.ts +0 -146
- /package/dist/reactionRepository/observers/{getReactions.d.ts → getReactions/getReactions.d.ts} +0 -0
package/dist/index.cjs.js
CHANGED
|
@@ -10137,6 +10137,18 @@ class QueryStreamController {
|
|
|
10137
10137
|
}
|
|
10138
10138
|
}
|
|
10139
10139
|
|
|
10140
|
+
var EnumFollowActions;
|
|
10141
|
+
(function (EnumFollowActions) {
|
|
10142
|
+
EnumFollowActions["OnRequested"] = "onRequested";
|
|
10143
|
+
EnumFollowActions["OnAccepted"] = "onAccepted";
|
|
10144
|
+
EnumFollowActions["OnDeclined"] = "onDeclined";
|
|
10145
|
+
EnumFollowActions["OnCanceled"] = "onCanceled";
|
|
10146
|
+
EnumFollowActions["OnFollowed"] = "onFollowed";
|
|
10147
|
+
EnumFollowActions["OnUnfollowed"] = "onUnfollowed";
|
|
10148
|
+
EnumFollowActions["OnDeleted"] = "onDeleted";
|
|
10149
|
+
EnumFollowActions["OnUserDeleted"] = "onUserDeleted";
|
|
10150
|
+
})(EnumFollowActions || (EnumFollowActions = {}));
|
|
10151
|
+
|
|
10140
10152
|
class BlockedUserQueryStreamController extends QueryStreamController {
|
|
10141
10153
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
10142
10154
|
super(query, cacheKey);
|
|
@@ -10165,10 +10177,13 @@ class BlockedUserQueryStreamController extends QueryStreamController {
|
|
|
10165
10177
|
}
|
|
10166
10178
|
}
|
|
10167
10179
|
reactor(action) {
|
|
10168
|
-
return (
|
|
10180
|
+
return (targetUser) => {
|
|
10169
10181
|
var _a;
|
|
10170
|
-
|
|
10171
|
-
|
|
10182
|
+
if (action === EnumFollowActions.OnFollowed) {
|
|
10183
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
10184
|
+
const updatedCollection = collection === null || collection === void 0 ? void 0 : collection.data.filter(id => id !== targetUser.userId);
|
|
10185
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: updatedCollection }));
|
|
10186
|
+
}
|
|
10172
10187
|
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
10173
10188
|
};
|
|
10174
10189
|
}
|
|
@@ -10365,560 +10380,593 @@ var EnumUserActions;
|
|
|
10365
10380
|
EnumUserActions["OnUserFlagCleared"] = "onUserFlagCleared";
|
|
10366
10381
|
})(EnumUserActions || (EnumUserActions = {}));
|
|
10367
10382
|
|
|
10368
|
-
|
|
10369
|
-
|
|
10370
|
-
|
|
10371
|
-
const
|
|
10372
|
-
|
|
10373
|
-
|
|
10374
|
-
this.query = query;
|
|
10375
|
-
this.queryStreamController = new BlockedUserQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareBlockedUserPayload);
|
|
10376
|
-
this.callback = callback.bind(this);
|
|
10377
|
-
this.loadPage({ initial: true });
|
|
10378
|
-
}
|
|
10379
|
-
setup() {
|
|
10380
|
-
var _a;
|
|
10381
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
10382
|
-
if (!collection) {
|
|
10383
|
-
pushToCache(this.cacheKey, {
|
|
10384
|
-
data: [],
|
|
10385
|
-
params: {},
|
|
10386
|
-
});
|
|
10383
|
+
const createFollowEventSubscriber = (event, callback) => {
|
|
10384
|
+
const client = getActiveClient();
|
|
10385
|
+
const filter = (data) => {
|
|
10386
|
+
const payload = prepareFollowersPayload(data);
|
|
10387
|
+
if (!client.cache) {
|
|
10388
|
+
callback(payload.follows[0]);
|
|
10387
10389
|
}
|
|
10388
|
-
|
|
10389
|
-
|
|
10390
|
-
|
|
10391
|
-
|
|
10392
|
-
|
|
10393
|
-
|
|
10394
|
-
|
|
10395
|
-
|
|
10396
|
-
|
|
10397
|
-
|
|
10398
|
-
|
|
10399
|
-
|
|
10400
|
-
|
|
10401
|
-
|
|
10402
|
-
|
|
10403
|
-
|
|
10404
|
-
|
|
10405
|
-
|
|
10406
|
-
|
|
10407
|
-
|
|
10408
|
-
|
|
10409
|
-
.map(id => pullFromCache(['user', 'get', id]))
|
|
10410
|
-
.filter(isNonNullable)
|
|
10411
|
-
.map(({ data }) => data)
|
|
10412
|
-
.map(LinkedObject.user)) !== null && _b !== void 0 ? _b : []);
|
|
10413
|
-
if (!this.shouldNotify(data) && origin === 'event')
|
|
10414
|
-
return;
|
|
10415
|
-
this.callback({
|
|
10416
|
-
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
10417
|
-
data,
|
|
10418
|
-
hasNextPage: !!this.paginationController.getNextToken(),
|
|
10419
|
-
loading,
|
|
10420
|
-
error,
|
|
10421
|
-
});
|
|
10422
|
-
}
|
|
10423
|
-
// eslint-disable-next-line class-methods-use-this
|
|
10424
|
-
applyFilter(data) {
|
|
10425
|
-
let users = data;
|
|
10426
|
-
users = users.filter(user => user.isDeleted == null || user.isDeleted === false);
|
|
10427
|
-
return users;
|
|
10428
|
-
}
|
|
10429
|
-
}
|
|
10390
|
+
else {
|
|
10391
|
+
ingestInCache(payload);
|
|
10392
|
+
callback(payload.follows[0]);
|
|
10393
|
+
}
|
|
10394
|
+
};
|
|
10395
|
+
return createEventSubscriber(client, event, event, filter);
|
|
10396
|
+
};
|
|
10397
|
+
const createLocalFollowEventSubscriber = (event, callback) => {
|
|
10398
|
+
const client = getActiveClient();
|
|
10399
|
+
const filter = (data) => {
|
|
10400
|
+
const payload = prepareFollowStatusPayload(data);
|
|
10401
|
+
if (!client.cache) {
|
|
10402
|
+
callback(payload.follows[0]);
|
|
10403
|
+
}
|
|
10404
|
+
else {
|
|
10405
|
+
ingestInCache(payload);
|
|
10406
|
+
callback(payload.follows[0]);
|
|
10407
|
+
}
|
|
10408
|
+
};
|
|
10409
|
+
return createEventSubscriber(client, event, event, filter);
|
|
10410
|
+
};
|
|
10430
10411
|
|
|
10431
|
-
/* begin_public_function
|
|
10432
|
-
id: user.get_blocked_users
|
|
10433
|
-
*/
|
|
10434
10412
|
/**
|
|
10435
10413
|
* ```js
|
|
10436
|
-
* import {
|
|
10437
|
-
* const
|
|
10414
|
+
* import { onUserFollowed } from '@amityco/ts-sdk'
|
|
10415
|
+
* const dispose = onUserFollowed(status => {
|
|
10416
|
+
* // ...
|
|
10417
|
+
* })
|
|
10438
10418
|
* ```
|
|
10439
10419
|
*
|
|
10440
|
-
*
|
|
10420
|
+
* Fired when a user follows another users and confirmation is not required
|
|
10441
10421
|
*
|
|
10442
|
-
* @param
|
|
10443
|
-
* @
|
|
10444
|
-
* @returns {@link Amity.Unsubscriber} to unsubscribe from collection
|
|
10422
|
+
* @param callback The function to call when the event was fired
|
|
10423
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
10445
10424
|
*
|
|
10446
|
-
* @category
|
|
10447
|
-
* @async
|
|
10425
|
+
* @category Follow Events
|
|
10448
10426
|
*/
|
|
10449
|
-
const
|
|
10450
|
-
const { log, cache } = getActiveClient();
|
|
10451
|
-
if (!cache) {
|
|
10452
|
-
console.log(ENABLE_CACHE_MESSAGE);
|
|
10453
|
-
}
|
|
10454
|
-
const timestamp = Date.now();
|
|
10455
|
-
log(`getBlockedUsers(tmpid: ${timestamp}) > listen`);
|
|
10456
|
-
const blockedUserLiveCollection = new BlockedUserLiveCollectionController(params, callback);
|
|
10457
|
-
const disposers = blockedUserLiveCollection.startSubscription();
|
|
10458
|
-
const cacheKey = blockedUserLiveCollection.getCacheKey();
|
|
10459
|
-
disposers.push(() => dropFromCache(cacheKey));
|
|
10460
|
-
return () => {
|
|
10461
|
-
log(`getBlockedUsers(tmpid: ${timestamp}) > dispose`);
|
|
10462
|
-
disposers.forEach(fn => fn());
|
|
10463
|
-
dropFromCache(cacheKey);
|
|
10464
|
-
};
|
|
10465
|
-
};
|
|
10466
|
-
/* end_public_function */
|
|
10467
|
-
|
|
10468
|
-
/* eslint-disable no-use-before-define */
|
|
10469
|
-
const getBlockedUsers = (params, callback, config) => {
|
|
10470
|
-
console.log('Deprecation Notice: UserRepository.Relationship.getBlockedUsers will be deprecated on 9th June 2023, please use UserRepository.getBlockedUsers instead.');
|
|
10471
|
-
return getBlockedUsers$1(params, callback);
|
|
10472
|
-
};
|
|
10427
|
+
const onUserFollowed = (callback) => createFollowEventSubscriber('follow.created', callback);
|
|
10473
10428
|
|
|
10474
|
-
/* begin_public_function
|
|
10475
|
-
id: user.relationship.follow
|
|
10476
|
-
*/
|
|
10477
10429
|
/**
|
|
10478
10430
|
* ```js
|
|
10479
|
-
* import {
|
|
10480
|
-
* const
|
|
10431
|
+
* import { onUserUnfollowed } from '@amityco/ts-sdk'
|
|
10432
|
+
* const dispose = onUserFollowed(status => {
|
|
10433
|
+
* // ...
|
|
10434
|
+
* })
|
|
10481
10435
|
* ```
|
|
10482
10436
|
*
|
|
10483
|
-
*
|
|
10437
|
+
* Fired when a user unfollows
|
|
10484
10438
|
*
|
|
10485
|
-
* @param
|
|
10486
|
-
* @returns
|
|
10439
|
+
* @param callback The function to call when the event was fired
|
|
10440
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
10487
10441
|
*
|
|
10488
|
-
* @category Follow
|
|
10489
|
-
* @async
|
|
10442
|
+
* @category Follow Events
|
|
10490
10443
|
*/
|
|
10491
|
-
const
|
|
10492
|
-
const client = getActiveClient();
|
|
10493
|
-
client.log('follow/follow', userId);
|
|
10494
|
-
const { data } = await client.http.post(`/api/v4/me/following/${userId}`);
|
|
10495
|
-
const cachedAt = client.cache && Date.now();
|
|
10496
|
-
if (client.cache) {
|
|
10497
|
-
ingestInCache(data, { cachedAt });
|
|
10498
|
-
}
|
|
10499
|
-
const payload = prepareFollowStatusPayload(data);
|
|
10500
|
-
if (data.follows[0].status === 'accepted') {
|
|
10501
|
-
fireEvent('local.follow.created', payload);
|
|
10502
|
-
}
|
|
10503
|
-
else {
|
|
10504
|
-
fireEvent('local.follow.requested', payload);
|
|
10505
|
-
}
|
|
10506
|
-
return {
|
|
10507
|
-
data: data.follows[0],
|
|
10508
|
-
cachedAt,
|
|
10509
|
-
};
|
|
10510
|
-
};
|
|
10511
|
-
/* end_public_function */
|
|
10444
|
+
const onUserUnfollowed = (callback) => createFollowEventSubscriber('follow.unfollowed', callback);
|
|
10512
10445
|
|
|
10513
|
-
/* begin_public_function
|
|
10514
|
-
id: user.relationship.unfollow
|
|
10515
|
-
*/
|
|
10516
10446
|
/**
|
|
10517
10447
|
* ```js
|
|
10518
|
-
* import {
|
|
10519
|
-
*
|
|
10448
|
+
* import { onFollowerDeleted } from '@amityco/ts-sdk'
|
|
10449
|
+
* const dispose = onFollowerDeleted(status => {
|
|
10450
|
+
* // ...
|
|
10451
|
+
* })
|
|
10520
10452
|
* ```
|
|
10521
10453
|
*
|
|
10522
|
-
*
|
|
10454
|
+
* Fired when a follower has been deleted
|
|
10523
10455
|
*
|
|
10524
|
-
* @param
|
|
10525
|
-
* @returns
|
|
10456
|
+
* @param callback The function to call when the event was fired
|
|
10457
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
10526
10458
|
*
|
|
10527
|
-
* @category Follow
|
|
10528
|
-
* @async
|
|
10459
|
+
* @category Follow Events
|
|
10529
10460
|
*/
|
|
10530
|
-
const
|
|
10531
|
-
const client = getActiveClient();
|
|
10532
|
-
client.log('follow/unfollow', userId);
|
|
10533
|
-
const { data } = await client.http.delete(`/api/v4/me/following/${userId}`);
|
|
10534
|
-
if (client.cache) {
|
|
10535
|
-
ingestInCache(data);
|
|
10536
|
-
}
|
|
10537
|
-
const payload = prepareFollowStatusPayload(data);
|
|
10538
|
-
fireEvent('local.follow.unfollowed', payload);
|
|
10539
|
-
return true;
|
|
10540
|
-
};
|
|
10541
|
-
/* end_public_function */
|
|
10461
|
+
const onFollowerDeleted = (callback) => createFollowEventSubscriber('follow.followerDeleted', callback);
|
|
10542
10462
|
|
|
10543
10463
|
/**
|
|
10544
|
-
* @deprecated This API renamed to `acceptMyFollower`.
|
|
10545
|
-
* Please use acceptMyFollower() instead.
|
|
10546
|
-
*
|
|
10547
10464
|
* ```js
|
|
10548
|
-
* import {
|
|
10549
|
-
*
|
|
10465
|
+
* import { onFollowerRequested } from '@amityco/ts-sdk'
|
|
10466
|
+
* const dispose = onFollowerRequested(status => {
|
|
10467
|
+
* // ...
|
|
10468
|
+
* })
|
|
10550
10469
|
* ```
|
|
10551
10470
|
*
|
|
10552
|
-
*
|
|
10471
|
+
* Fired when a user follows another users and confirmation is required
|
|
10553
10472
|
*
|
|
10554
|
-
* @param
|
|
10555
|
-
* @returns
|
|
10473
|
+
* @param callback The function to call when the event was fired
|
|
10474
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
10556
10475
|
*
|
|
10557
|
-
* @category Follow
|
|
10558
|
-
* @async
|
|
10476
|
+
* @category Follow Events
|
|
10559
10477
|
*/
|
|
10560
|
-
const
|
|
10561
|
-
const client = getActiveClient();
|
|
10562
|
-
client.log('follow/acceptFollower', userId);
|
|
10563
|
-
const { data } = await client.http.post(`/api/v4/me/followers/${userId}`);
|
|
10564
|
-
if (client.cache) {
|
|
10565
|
-
ingestInCache(data);
|
|
10566
|
-
}
|
|
10567
|
-
const payload = prepareFollowStatusPayload(data);
|
|
10568
|
-
fireEvent('local.follow.accepted', payload);
|
|
10569
|
-
return true;
|
|
10570
|
-
};
|
|
10478
|
+
const onFollowerRequested = (callback) => createFollowEventSubscriber('follow.requested', callback);
|
|
10571
10479
|
|
|
10572
|
-
/* begin_public_function
|
|
10573
|
-
id: user.relationship.accept_follow
|
|
10574
|
-
*/
|
|
10575
10480
|
/**
|
|
10576
10481
|
* ```js
|
|
10577
|
-
* import {
|
|
10578
|
-
*
|
|
10579
|
-
*
|
|
10482
|
+
* import { onFollowRequestCanceled } from '@amityco/ts-sdk'
|
|
10483
|
+
* const dispose = onFollowRequestCanceled(status => {
|
|
10484
|
+
* // ...
|
|
10485
|
+
* })
|
|
10486
|
+
* ```
|
|
10580
10487
|
*
|
|
10581
|
-
*
|
|
10488
|
+
* Fired when a follow request has been canceled
|
|
10582
10489
|
*
|
|
10583
|
-
* @param
|
|
10584
|
-
* @returns
|
|
10490
|
+
* @param callback The function to call when the event was fired
|
|
10491
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
10585
10492
|
*
|
|
10586
|
-
* @category Follow
|
|
10587
|
-
* @async
|
|
10493
|
+
* @category Follow Events
|
|
10588
10494
|
*/
|
|
10589
|
-
const
|
|
10590
|
-
const client = getActiveClient();
|
|
10591
|
-
client.log('follow/acceptMyFollower', userId);
|
|
10592
|
-
const { data } = await client.http.post(`/api/v4/me/followers/${userId}`);
|
|
10593
|
-
if (client.cache) {
|
|
10594
|
-
ingestInCache(data);
|
|
10595
|
-
}
|
|
10596
|
-
const payload = prepareFollowStatusPayload(data);
|
|
10597
|
-
fireEvent('local.follow.accepted', payload);
|
|
10598
|
-
return true;
|
|
10599
|
-
};
|
|
10600
|
-
/* end_public_function */
|
|
10495
|
+
const onFollowRequestCanceled = (callback) => createFollowEventSubscriber('follow.requestCanceled', callback);
|
|
10601
10496
|
|
|
10602
10497
|
/**
|
|
10603
|
-
*
|
|
10604
|
-
*
|
|
10498
|
+
* ```js
|
|
10499
|
+
* import { onFollowRequestAccepted } from '@amityco/ts-sdk'
|
|
10500
|
+
* const dispose = onFollowRequestAccepted(status => {
|
|
10501
|
+
* // ...
|
|
10502
|
+
* })
|
|
10503
|
+
* ```
|
|
10504
|
+
*
|
|
10505
|
+
* Fired when a follow request has been accepted
|
|
10506
|
+
*
|
|
10507
|
+
* @param callback The function to call when the event was fired
|
|
10508
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
10605
10509
|
*
|
|
10510
|
+
* @category Follow Events
|
|
10511
|
+
*/
|
|
10512
|
+
const onFollowRequestAccepted = (callback) => createFollowEventSubscriber('follow.accepted', callback);
|
|
10513
|
+
|
|
10514
|
+
/**
|
|
10606
10515
|
* ```js
|
|
10607
|
-
* import {
|
|
10608
|
-
*
|
|
10516
|
+
* import { onFollowRequestDeclined } from '@amityco/ts-sdk'
|
|
10517
|
+
* const dispose = onFollowRequestDeclined(status => {
|
|
10518
|
+
* // ...
|
|
10519
|
+
* })
|
|
10609
10520
|
* ```
|
|
10610
10521
|
*
|
|
10611
|
-
*
|
|
10522
|
+
* Fired when a follow request has been declined
|
|
10612
10523
|
*
|
|
10613
|
-
* @param
|
|
10614
|
-
* @returns
|
|
10524
|
+
* @param callback The function to call when the event was fired
|
|
10525
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
10615
10526
|
*
|
|
10616
|
-
* @category Follow
|
|
10617
|
-
* @async
|
|
10527
|
+
* @category Follow Events
|
|
10618
10528
|
*/
|
|
10619
|
-
const
|
|
10620
|
-
const client = getActiveClient();
|
|
10621
|
-
client.log('follow/declineFollower', userId);
|
|
10622
|
-
const { data } = await client.http.delete(`/api/v4/me/followers/${userId}`);
|
|
10623
|
-
if (client.cache) {
|
|
10624
|
-
ingestInCache(data);
|
|
10625
|
-
}
|
|
10626
|
-
const payload = prepareFollowStatusPayload(data);
|
|
10627
|
-
fireEvent('local.follow.requestDeclined', payload);
|
|
10628
|
-
return true;
|
|
10629
|
-
};
|
|
10529
|
+
const onFollowRequestDeclined = (callback) => createFollowEventSubscriber('follow.requestDeclined', callback);
|
|
10630
10530
|
|
|
10631
|
-
/* begin_public_function
|
|
10632
|
-
id: user.relationship.decline_follow
|
|
10633
|
-
*/
|
|
10634
10531
|
/**
|
|
10635
10532
|
* ```js
|
|
10636
|
-
* import {
|
|
10637
|
-
* await
|
|
10533
|
+
* import { getFollowInfo } from '@amityco/ts-sdk'
|
|
10534
|
+
* const { data: followInfo } = await getFollowInfo('foobar')
|
|
10638
10535
|
* ```
|
|
10639
10536
|
*
|
|
10640
|
-
*
|
|
10537
|
+
* Fetches the number of followers, followings, pending requests and the follow status for current user
|
|
10641
10538
|
*
|
|
10642
|
-
* @param userId the ID of the {@link Amity.InternalUser}
|
|
10643
|
-
* @returns
|
|
10539
|
+
* @param userId the ID of the {@link Amity.InternalUser}
|
|
10540
|
+
* @returns the associated {@link Amity.FollowInfo} object
|
|
10644
10541
|
*
|
|
10645
10542
|
* @category Follow API
|
|
10646
10543
|
* @async
|
|
10647
10544
|
*/
|
|
10648
|
-
const
|
|
10545
|
+
const getFollowInfo$1 = async (userId) => {
|
|
10546
|
+
var _a, _b;
|
|
10649
10547
|
const client = getActiveClient();
|
|
10650
|
-
client.log('follow/
|
|
10651
|
-
const { data } = await client.http.
|
|
10548
|
+
client.log('follow/getFollowInfo', userId);
|
|
10549
|
+
const { data } = await client.http.get(client.userId === userId ? `/api/v4/me/followInfo` : `/api/v5/users/${userId}/followInfo`);
|
|
10550
|
+
const cachedAt = client.cache && Date.now();
|
|
10551
|
+
const followInfo = 'follows' in data
|
|
10552
|
+
? Object.assign(Object.assign({}, data.followCounts[0]), { status: (_b = (_a = data.follows) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.status }) : data.followCounts[0];
|
|
10652
10553
|
if (client.cache) {
|
|
10653
|
-
|
|
10554
|
+
pushToCache(['followInfo', 'get', userId], followInfo, {
|
|
10555
|
+
cachedAt,
|
|
10556
|
+
});
|
|
10654
10557
|
}
|
|
10655
|
-
|
|
10656
|
-
|
|
10657
|
-
|
|
10658
|
-
};
|
|
10659
|
-
/* end_public_function */
|
|
10660
|
-
|
|
10661
|
-
const createFollowEventSubscriber = (event, callback) => {
|
|
10662
|
-
const client = getActiveClient();
|
|
10663
|
-
const filter = (data) => {
|
|
10664
|
-
const payload = prepareFollowersPayload(data);
|
|
10665
|
-
if (!client.cache) {
|
|
10666
|
-
callback(payload.follows[0]);
|
|
10667
|
-
}
|
|
10668
|
-
else {
|
|
10669
|
-
ingestInCache(payload);
|
|
10670
|
-
callback(payload.follows[0]);
|
|
10671
|
-
}
|
|
10558
|
+
return {
|
|
10559
|
+
data: followInfo,
|
|
10560
|
+
cachedAt,
|
|
10672
10561
|
};
|
|
10673
|
-
return createEventSubscriber(client, event, event, filter);
|
|
10674
10562
|
};
|
|
10675
|
-
const createLocalFollowEventSubscriber = (event, callback) => {
|
|
10676
|
-
const client = getActiveClient();
|
|
10677
|
-
const filter = (data) => {
|
|
10678
|
-
const payload = prepareFollowStatusPayload(data);
|
|
10679
|
-
if (!client.cache) {
|
|
10680
|
-
callback(payload.follows[0]);
|
|
10681
|
-
}
|
|
10682
|
-
else {
|
|
10683
|
-
ingestInCache(payload);
|
|
10684
|
-
callback(payload.follows[0]);
|
|
10685
|
-
}
|
|
10686
|
-
};
|
|
10687
|
-
return createEventSubscriber(client, event, event, filter);
|
|
10688
|
-
};
|
|
10689
|
-
|
|
10690
10563
|
/**
|
|
10691
10564
|
* ```js
|
|
10692
|
-
* import {
|
|
10693
|
-
* const
|
|
10694
|
-
* // ...
|
|
10695
|
-
* })
|
|
10565
|
+
* import { getFollowInfo } from '@amityco/ts-sdk'
|
|
10566
|
+
* const { data: followInfo } = getFollowInfo.locally('foobar')
|
|
10696
10567
|
* ```
|
|
10697
10568
|
*
|
|
10698
|
-
*
|
|
10569
|
+
* Fetches the number of followers, followings, pending requests and the follow status for current user from cache
|
|
10699
10570
|
*
|
|
10700
|
-
* @param
|
|
10701
|
-
* @returns
|
|
10571
|
+
* @param userId the ID of the {@link Amity.InternalUser}
|
|
10572
|
+
* @returns the associated {@link Amity.FollowInfo} object
|
|
10702
10573
|
*
|
|
10703
|
-
* @category Follow
|
|
10574
|
+
* @category Follow API
|
|
10704
10575
|
*/
|
|
10705
|
-
|
|
10576
|
+
getFollowInfo$1.locally = (userId) => {
|
|
10577
|
+
const client = getActiveClient();
|
|
10578
|
+
client.log('follow/getFollowInfo.locally', userId);
|
|
10579
|
+
if (!client.cache) {
|
|
10580
|
+
return;
|
|
10581
|
+
}
|
|
10582
|
+
const cached = pullFromCache(['followInfo', 'get', userId]);
|
|
10583
|
+
if (!cached) {
|
|
10584
|
+
return;
|
|
10585
|
+
}
|
|
10586
|
+
return {
|
|
10587
|
+
data: cached.data,
|
|
10588
|
+
cachedAt: cached.cachedAt,
|
|
10589
|
+
};
|
|
10590
|
+
};
|
|
10706
10591
|
|
|
10707
10592
|
/**
|
|
10708
10593
|
* ```js
|
|
10709
|
-
* import {
|
|
10710
|
-
* const dispose =
|
|
10594
|
+
* import { onFollowInfoUpdated } from '@amityco/ts-sdk'
|
|
10595
|
+
* const dispose = onFollowInfoUpdated(followInfo => {
|
|
10711
10596
|
* // ...
|
|
10712
10597
|
* })
|
|
10713
10598
|
* ```
|
|
10714
10599
|
*
|
|
10715
|
-
* Fired when a
|
|
10600
|
+
* Fired when a {@link Amity.FollowInfo} has been updated
|
|
10716
10601
|
*
|
|
10717
10602
|
* @param callback The function to call when the event was fired
|
|
10718
10603
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
10719
10604
|
*
|
|
10720
10605
|
* @category Follow Events
|
|
10721
10606
|
*/
|
|
10722
|
-
const
|
|
10607
|
+
const onFollowInfoUpdated = (callback) => {
|
|
10608
|
+
const handler = async (payload) => {
|
|
10609
|
+
const [{ data: followInfoFrom }, { data: followInfoTo }] = await Promise.all([
|
|
10610
|
+
getFollowInfo$1(payload.from),
|
|
10611
|
+
getFollowInfo$1(payload.to),
|
|
10612
|
+
]);
|
|
10613
|
+
callback(followInfoFrom);
|
|
10614
|
+
callback(followInfoTo);
|
|
10615
|
+
};
|
|
10616
|
+
const disposers = [
|
|
10617
|
+
createFollowEventSubscriber('follow.created', handler),
|
|
10618
|
+
createFollowEventSubscriber('follow.requested', handler),
|
|
10619
|
+
createFollowEventSubscriber('follow.accepted', handler),
|
|
10620
|
+
createFollowEventSubscriber('follow.unfollowed', handler),
|
|
10621
|
+
createFollowEventSubscriber('follow.requestCanceled', handler),
|
|
10622
|
+
createFollowEventSubscriber('follow.requestDeclined', handler),
|
|
10623
|
+
createFollowEventSubscriber('follow.followerDeleted', handler),
|
|
10624
|
+
createLocalFollowEventSubscriber('local.follow.created', handler),
|
|
10625
|
+
createLocalFollowEventSubscriber('local.follow.requested', handler),
|
|
10626
|
+
createLocalFollowEventSubscriber('local.follow.accepted', handler),
|
|
10627
|
+
createLocalFollowEventSubscriber('local.follow.unfollowed', handler),
|
|
10628
|
+
createLocalFollowEventSubscriber('local.follow.requestDeclined', handler),
|
|
10629
|
+
];
|
|
10630
|
+
return () => {
|
|
10631
|
+
disposers.forEach(fn => fn());
|
|
10632
|
+
};
|
|
10633
|
+
};
|
|
10723
10634
|
|
|
10724
|
-
|
|
10725
|
-
|
|
10726
|
-
|
|
10727
|
-
|
|
10728
|
-
|
|
10729
|
-
|
|
10730
|
-
|
|
10731
|
-
|
|
10732
|
-
|
|
10733
|
-
|
|
10734
|
-
|
|
10735
|
-
|
|
10736
|
-
|
|
10737
|
-
|
|
10738
|
-
|
|
10739
|
-
const
|
|
10635
|
+
const onLocalUserFollowed = (callback) => createLocalFollowEventSubscriber('local.follow.created', callback);
|
|
10636
|
+
|
|
10637
|
+
const onLocalUserUnfollowed = (callback) => createLocalFollowEventSubscriber('local.follow.unfollowed', callback);
|
|
10638
|
+
|
|
10639
|
+
const onLocalFollowerRequested = (callback) => createLocalFollowEventSubscriber('local.follow.requested', callback);
|
|
10640
|
+
|
|
10641
|
+
const onLocalFollowRequestAccepted = (callback) => createLocalFollowEventSubscriber('local.follow.accepted', callback);
|
|
10642
|
+
|
|
10643
|
+
const onLocalFollowRequestDeclined = (callback) => createLocalFollowEventSubscriber('local.follow.requestDeclined', callback);
|
|
10644
|
+
|
|
10645
|
+
const convertEventPayload = (eventHandler, sourceModelProp, destinationDomain) => (callback) => eventHandler(sourceModel => {
|
|
10646
|
+
var _a, _b;
|
|
10647
|
+
if (!sourceModel) {
|
|
10648
|
+
return sourceModel;
|
|
10649
|
+
}
|
|
10650
|
+
const client = getActiveClient();
|
|
10651
|
+
const { objectSyncMap } = client;
|
|
10652
|
+
/*
|
|
10653
|
+
* NOTE: For objects created locally (optimistic creation), the SDK stores them with their local ID as the cache key, which is used throughout the entire SDK session (in-memory) for syncing updates.
|
|
10654
|
+
* If the payload or response only contains the remote ID of the same object, the SDK will look up the corresponding local ID to retrieve the object.
|
|
10655
|
+
*/
|
|
10656
|
+
const resolvedId = isLocalId(sourceModel[sourceModelProp])
|
|
10657
|
+
? sourceModel[sourceModelProp]
|
|
10658
|
+
: (_a = objectSyncMap.get(sourceModel[sourceModelProp])) !== null && _a !== void 0 ? _a : sourceModel[sourceModelProp];
|
|
10659
|
+
const model = (_b = pullFromCache([
|
|
10660
|
+
destinationDomain,
|
|
10661
|
+
'get',
|
|
10662
|
+
`${resolvedId}`,
|
|
10663
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
10664
|
+
if (!model)
|
|
10665
|
+
return;
|
|
10666
|
+
return callback(model);
|
|
10667
|
+
});
|
|
10668
|
+
|
|
10669
|
+
class BlockedUserLiveCollectionController extends LiveCollectionController {
|
|
10670
|
+
constructor(query, callback) {
|
|
10671
|
+
const queryStreamId = hash__default["default"](query);
|
|
10672
|
+
const cacheKey = ['blockedUsers', 'collection', queryStreamId];
|
|
10673
|
+
const paginationController = new BlockedUserPaginationController(query);
|
|
10674
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
10675
|
+
this.query = query;
|
|
10676
|
+
this.queryStreamController = new BlockedUserQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareBlockedUserPayload);
|
|
10677
|
+
this.callback = callback.bind(this);
|
|
10678
|
+
this.loadPage({ initial: true });
|
|
10679
|
+
}
|
|
10680
|
+
setup() {
|
|
10681
|
+
var _a;
|
|
10682
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
10683
|
+
if (!collection) {
|
|
10684
|
+
pushToCache(this.cacheKey, {
|
|
10685
|
+
data: [],
|
|
10686
|
+
params: {},
|
|
10687
|
+
});
|
|
10688
|
+
}
|
|
10689
|
+
}
|
|
10690
|
+
async persistModel(queryPayload) {
|
|
10691
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
10692
|
+
}
|
|
10693
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
10694
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
10695
|
+
}
|
|
10696
|
+
startSubscription() {
|
|
10697
|
+
return this.queryStreamController.subscribeRTE([
|
|
10698
|
+
{
|
|
10699
|
+
fn: onUserDeleted$2,
|
|
10700
|
+
action: EnumUserActions.OnUserDeleted,
|
|
10701
|
+
},
|
|
10702
|
+
// In the case of unblocking a user, we need to subscribe to the follow events
|
|
10703
|
+
{
|
|
10704
|
+
fn: convertEventPayload(onLocalUserFollowed, 'to', 'user'),
|
|
10705
|
+
action: EnumFollowActions.OnFollowed,
|
|
10706
|
+
},
|
|
10707
|
+
{
|
|
10708
|
+
fn: convertEventPayload(onUserFollowed, 'to', 'user'),
|
|
10709
|
+
action: EnumFollowActions.OnFollowed,
|
|
10710
|
+
},
|
|
10711
|
+
]);
|
|
10712
|
+
}
|
|
10713
|
+
notifyChange({ origin, loading, error }) {
|
|
10714
|
+
var _a, _b;
|
|
10715
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
10716
|
+
if (!collection)
|
|
10717
|
+
return;
|
|
10718
|
+
const data = this.applyFilter((_b = collection.data
|
|
10719
|
+
.map(id => pullFromCache(['user', 'get', id]))
|
|
10720
|
+
.filter(isNonNullable)
|
|
10721
|
+
.map(({ data }) => data)
|
|
10722
|
+
.map(LinkedObject.user)) !== null && _b !== void 0 ? _b : []);
|
|
10723
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
10724
|
+
return;
|
|
10725
|
+
this.callback({
|
|
10726
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
10727
|
+
data,
|
|
10728
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
10729
|
+
loading,
|
|
10730
|
+
error,
|
|
10731
|
+
});
|
|
10732
|
+
}
|
|
10733
|
+
// eslint-disable-next-line class-methods-use-this
|
|
10734
|
+
applyFilter(data) {
|
|
10735
|
+
let users = data;
|
|
10736
|
+
users = users.filter(user => user.isDeleted == null || user.isDeleted === false);
|
|
10737
|
+
return users;
|
|
10738
|
+
}
|
|
10739
|
+
}
|
|
10740
10740
|
|
|
10741
|
+
/* begin_public_function
|
|
10742
|
+
id: user.get_blocked_users
|
|
10743
|
+
*/
|
|
10741
10744
|
/**
|
|
10742
10745
|
* ```js
|
|
10743
|
-
* import {
|
|
10744
|
-
* const
|
|
10745
|
-
* // ...
|
|
10746
|
-
* })
|
|
10746
|
+
* import { UserRepository } from '@amityco/ts-sdk'
|
|
10747
|
+
* const unblockedUser = await UserRepository.blockUser('userId')
|
|
10747
10748
|
* ```
|
|
10748
10749
|
*
|
|
10749
|
-
*
|
|
10750
|
+
* Blocks a {@link Amity.InternalUser}
|
|
10750
10751
|
*
|
|
10751
|
-
* @param
|
|
10752
|
-
* @
|
|
10752
|
+
* @param params The params to get blocked {@link Amity.InternalUser}s
|
|
10753
|
+
* @param callback to recieve updates on unblocked {@link Amity.InternalUser}s
|
|
10754
|
+
* @returns {@link Amity.Unsubscriber} to unsubscribe from collection
|
|
10753
10755
|
*
|
|
10754
|
-
* @category
|
|
10756
|
+
* @category Post API
|
|
10757
|
+
* @async
|
|
10755
10758
|
*/
|
|
10756
|
-
const
|
|
10759
|
+
const getBlockedUsers$1 = (params, callback, config) => {
|
|
10760
|
+
const { log, cache } = getActiveClient();
|
|
10761
|
+
if (!cache) {
|
|
10762
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
10763
|
+
}
|
|
10764
|
+
const timestamp = Date.now();
|
|
10765
|
+
log(`getBlockedUsers(tmpid: ${timestamp}) > listen`);
|
|
10766
|
+
const blockedUserLiveCollection = new BlockedUserLiveCollectionController(params, callback);
|
|
10767
|
+
const disposers = blockedUserLiveCollection.startSubscription();
|
|
10768
|
+
const cacheKey = blockedUserLiveCollection.getCacheKey();
|
|
10769
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
10770
|
+
return () => {
|
|
10771
|
+
log(`getBlockedUsers(tmpid: ${timestamp}) > dispose`);
|
|
10772
|
+
disposers.forEach(fn => fn());
|
|
10773
|
+
dropFromCache(cacheKey);
|
|
10774
|
+
};
|
|
10775
|
+
};
|
|
10776
|
+
/* end_public_function */
|
|
10777
|
+
|
|
10778
|
+
/* eslint-disable no-use-before-define */
|
|
10779
|
+
const getBlockedUsers = (params, callback, config) => {
|
|
10780
|
+
console.log('Deprecation Notice: UserRepository.Relationship.getBlockedUsers will be deprecated on 9th June 2023, please use UserRepository.getBlockedUsers instead.');
|
|
10781
|
+
return getBlockedUsers$1(params, callback);
|
|
10782
|
+
};
|
|
10757
10783
|
|
|
10784
|
+
/* begin_public_function
|
|
10785
|
+
id: user.relationship.follow
|
|
10786
|
+
*/
|
|
10758
10787
|
/**
|
|
10759
10788
|
* ```js
|
|
10760
|
-
* import {
|
|
10761
|
-
* const
|
|
10762
|
-
* // ...
|
|
10763
|
-
* })
|
|
10789
|
+
* import { follow } from '@amityco/ts-sdk'
|
|
10790
|
+
* const status = await follow('foobar')
|
|
10764
10791
|
* ```
|
|
10765
10792
|
*
|
|
10766
|
-
*
|
|
10793
|
+
* Follow the user
|
|
10767
10794
|
*
|
|
10768
|
-
* @param
|
|
10769
|
-
* @returns
|
|
10795
|
+
* @param userId the ID of the {@link Amity.InternalUser}
|
|
10796
|
+
* @returns the status {@link Amity.FollowStatus}
|
|
10770
10797
|
*
|
|
10771
|
-
* @category Follow
|
|
10798
|
+
* @category Follow API
|
|
10799
|
+
* @async
|
|
10772
10800
|
*/
|
|
10773
|
-
const
|
|
10801
|
+
const follow = async (userId) => {
|
|
10802
|
+
const client = getActiveClient();
|
|
10803
|
+
client.log('follow/follow', userId);
|
|
10804
|
+
const { data } = await client.http.post(`/api/v4/me/following/${userId}`);
|
|
10805
|
+
const cachedAt = client.cache && Date.now();
|
|
10806
|
+
if (client.cache) {
|
|
10807
|
+
ingestInCache(data, { cachedAt });
|
|
10808
|
+
}
|
|
10809
|
+
const payload = prepareFollowStatusPayload(data);
|
|
10810
|
+
if (data.follows[0].status === 'accepted') {
|
|
10811
|
+
fireEvent('local.follow.created', payload);
|
|
10812
|
+
}
|
|
10813
|
+
else {
|
|
10814
|
+
fireEvent('local.follow.requested', payload);
|
|
10815
|
+
}
|
|
10816
|
+
return {
|
|
10817
|
+
data: data.follows[0],
|
|
10818
|
+
cachedAt,
|
|
10819
|
+
};
|
|
10820
|
+
};
|
|
10821
|
+
/* end_public_function */
|
|
10774
10822
|
|
|
10823
|
+
/* begin_public_function
|
|
10824
|
+
id: user.relationship.unfollow
|
|
10825
|
+
*/
|
|
10775
10826
|
/**
|
|
10776
10827
|
* ```js
|
|
10777
|
-
* import {
|
|
10778
|
-
*
|
|
10779
|
-
* // ...
|
|
10780
|
-
* })
|
|
10828
|
+
* import { unfollow } from '@amityco/ts-sdk'
|
|
10829
|
+
* await unfollow('foobar')
|
|
10781
10830
|
* ```
|
|
10782
10831
|
*
|
|
10783
|
-
*
|
|
10832
|
+
* Cancel the follow request or unfollow the user
|
|
10784
10833
|
*
|
|
10785
|
-
* @param
|
|
10786
|
-
* @returns
|
|
10834
|
+
* @param userId the ID of the {@link Amity.InternalUser}
|
|
10835
|
+
* @returns A success boolean if the user {@link Amity.InternalUser} was unfollowed
|
|
10787
10836
|
*
|
|
10788
|
-
* @category Follow
|
|
10837
|
+
* @category Follow API
|
|
10838
|
+
* @async
|
|
10789
10839
|
*/
|
|
10790
|
-
const
|
|
10840
|
+
const unfollow = async (userId) => {
|
|
10841
|
+
const client = getActiveClient();
|
|
10842
|
+
client.log('follow/unfollow', userId);
|
|
10843
|
+
const { data } = await client.http.delete(`/api/v4/me/following/${userId}`);
|
|
10844
|
+
if (client.cache) {
|
|
10845
|
+
ingestInCache(data);
|
|
10846
|
+
}
|
|
10847
|
+
const payload = prepareFollowStatusPayload(data);
|
|
10848
|
+
fireEvent('local.follow.unfollowed', payload);
|
|
10849
|
+
return true;
|
|
10850
|
+
};
|
|
10851
|
+
/* end_public_function */
|
|
10791
10852
|
|
|
10792
10853
|
/**
|
|
10854
|
+
* @deprecated This API renamed to `acceptMyFollower`.
|
|
10855
|
+
* Please use acceptMyFollower() instead.
|
|
10856
|
+
*
|
|
10793
10857
|
* ```js
|
|
10794
|
-
* import {
|
|
10795
|
-
*
|
|
10796
|
-
* // ...
|
|
10797
|
-
* })
|
|
10858
|
+
* import { acceptFollower } from '@amityco/ts-sdk'
|
|
10859
|
+
* await acceptFollower('foobar')
|
|
10798
10860
|
* ```
|
|
10799
10861
|
*
|
|
10800
|
-
*
|
|
10862
|
+
* Accept the follow request
|
|
10801
10863
|
*
|
|
10802
|
-
* @param
|
|
10803
|
-
* @returns
|
|
10864
|
+
* @param userId the ID of the {@link Amity.InternalUser} follower
|
|
10865
|
+
* @returns A success boolean if the follow request was accepted
|
|
10804
10866
|
*
|
|
10805
|
-
* @category Follow
|
|
10867
|
+
* @category Follow API
|
|
10868
|
+
* @async
|
|
10806
10869
|
*/
|
|
10807
|
-
const
|
|
10870
|
+
const acceptFollower = async (userId) => {
|
|
10871
|
+
const client = getActiveClient();
|
|
10872
|
+
client.log('follow/acceptFollower', userId);
|
|
10873
|
+
const { data } = await client.http.post(`/api/v4/me/followers/${userId}`);
|
|
10874
|
+
if (client.cache) {
|
|
10875
|
+
ingestInCache(data);
|
|
10876
|
+
}
|
|
10877
|
+
const payload = prepareFollowStatusPayload(data);
|
|
10878
|
+
fireEvent('local.follow.accepted', payload);
|
|
10879
|
+
return true;
|
|
10880
|
+
};
|
|
10808
10881
|
|
|
10882
|
+
/* begin_public_function
|
|
10883
|
+
id: user.relationship.accept_follow
|
|
10884
|
+
*/
|
|
10809
10885
|
/**
|
|
10810
10886
|
* ```js
|
|
10811
|
-
* import {
|
|
10812
|
-
*
|
|
10887
|
+
* import { UserRepository } from '@amityco/ts-sdk'
|
|
10888
|
+
* await UserRepository.Relationship.acceptMyFollower('foobar')
|
|
10813
10889
|
* ```
|
|
10814
10890
|
*
|
|
10815
|
-
*
|
|
10891
|
+
* Accept the follow request
|
|
10816
10892
|
*
|
|
10817
|
-
* @param userId the ID of the {@link Amity.InternalUser}
|
|
10818
|
-
* @returns the
|
|
10893
|
+
* @param userId the ID of the {@link Amity.InternalUser} follower
|
|
10894
|
+
* @returns A success boolean if the follow request was accepted
|
|
10819
10895
|
*
|
|
10820
10896
|
* @category Follow API
|
|
10821
10897
|
* @async
|
|
10822
10898
|
*/
|
|
10823
|
-
const
|
|
10824
|
-
var _a, _b;
|
|
10899
|
+
const acceptMyFollower = async (userId) => {
|
|
10825
10900
|
const client = getActiveClient();
|
|
10826
|
-
client.log('follow/
|
|
10827
|
-
const { data } = await client.http.
|
|
10828
|
-
const cachedAt = client.cache && Date.now();
|
|
10829
|
-
const followInfo = 'follows' in data
|
|
10830
|
-
? Object.assign(Object.assign({}, data.followCounts[0]), { status: (_b = (_a = data.follows) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.status }) : data.followCounts[0];
|
|
10901
|
+
client.log('follow/acceptMyFollower', userId);
|
|
10902
|
+
const { data } = await client.http.post(`/api/v4/me/followers/${userId}`);
|
|
10831
10903
|
if (client.cache) {
|
|
10832
|
-
|
|
10833
|
-
cachedAt,
|
|
10834
|
-
});
|
|
10904
|
+
ingestInCache(data);
|
|
10835
10905
|
}
|
|
10836
|
-
|
|
10837
|
-
|
|
10838
|
-
|
|
10839
|
-
};
|
|
10906
|
+
const payload = prepareFollowStatusPayload(data);
|
|
10907
|
+
fireEvent('local.follow.accepted', payload);
|
|
10908
|
+
return true;
|
|
10840
10909
|
};
|
|
10910
|
+
/* end_public_function */
|
|
10911
|
+
|
|
10841
10912
|
/**
|
|
10913
|
+
* @deprecated This API renamed to `declineMyFollower`.
|
|
10914
|
+
* Please use declineMyFollower() instead.
|
|
10915
|
+
*
|
|
10842
10916
|
* ```js
|
|
10843
|
-
* import {
|
|
10844
|
-
*
|
|
10917
|
+
* import { declineFollower } from '@amityco/ts-sdk'
|
|
10918
|
+
* await declineFollower('foobar')
|
|
10845
10919
|
* ```
|
|
10846
10920
|
*
|
|
10847
|
-
*
|
|
10848
|
-
*
|
|
10849
|
-
* @param userId the ID of the {@link Amity.InternalUser}
|
|
10850
|
-
* @returns the
|
|
10921
|
+
* Decline the follow request or delete the follower
|
|
10922
|
+
*
|
|
10923
|
+
* @param userId the ID of the {@link Amity.InternalUser} follower
|
|
10924
|
+
* @returns A success boolean if the follow request was decline
|
|
10851
10925
|
*
|
|
10852
10926
|
* @category Follow API
|
|
10927
|
+
* @async
|
|
10853
10928
|
*/
|
|
10854
|
-
|
|
10929
|
+
const declineFollower = async (userId) => {
|
|
10855
10930
|
const client = getActiveClient();
|
|
10856
|
-
client.log('follow/
|
|
10857
|
-
|
|
10858
|
-
|
|
10859
|
-
|
|
10860
|
-
const cached = pullFromCache(['followInfo', 'get', userId]);
|
|
10861
|
-
if (!cached) {
|
|
10862
|
-
return;
|
|
10931
|
+
client.log('follow/declineFollower', userId);
|
|
10932
|
+
const { data } = await client.http.delete(`/api/v4/me/followers/${userId}`);
|
|
10933
|
+
if (client.cache) {
|
|
10934
|
+
ingestInCache(data);
|
|
10863
10935
|
}
|
|
10864
|
-
|
|
10865
|
-
|
|
10866
|
-
|
|
10867
|
-
};
|
|
10936
|
+
const payload = prepareFollowStatusPayload(data);
|
|
10937
|
+
fireEvent('local.follow.requestDeclined', payload);
|
|
10938
|
+
return true;
|
|
10868
10939
|
};
|
|
10869
10940
|
|
|
10941
|
+
/* begin_public_function
|
|
10942
|
+
id: user.relationship.decline_follow
|
|
10943
|
+
*/
|
|
10870
10944
|
/**
|
|
10871
10945
|
* ```js
|
|
10872
|
-
* import {
|
|
10873
|
-
*
|
|
10874
|
-
* // ...
|
|
10875
|
-
* })
|
|
10946
|
+
* import { UserRepository } from '@amityco/ts-sdk'
|
|
10947
|
+
* await UserRepository.Relationship.declineMyFollower('foobar')
|
|
10876
10948
|
* ```
|
|
10877
10949
|
*
|
|
10878
|
-
*
|
|
10950
|
+
* Decline the follow request or delete the follower
|
|
10879
10951
|
*
|
|
10880
|
-
* @param
|
|
10881
|
-
* @returns
|
|
10952
|
+
* @param userId the ID of the {@link Amity.InternalUser} follower
|
|
10953
|
+
* @returns A success boolean if the follow request was decline
|
|
10882
10954
|
*
|
|
10883
|
-
* @category Follow
|
|
10955
|
+
* @category Follow API
|
|
10956
|
+
* @async
|
|
10884
10957
|
*/
|
|
10885
|
-
const
|
|
10886
|
-
const
|
|
10887
|
-
|
|
10888
|
-
|
|
10889
|
-
|
|
10890
|
-
|
|
10891
|
-
|
|
10892
|
-
|
|
10893
|
-
|
|
10894
|
-
|
|
10895
|
-
|
|
10896
|
-
|
|
10897
|
-
createFollowEventSubscriber('follow.accepted', handler),
|
|
10898
|
-
createFollowEventSubscriber('follow.unfollowed', handler),
|
|
10899
|
-
createFollowEventSubscriber('follow.requestCanceled', handler),
|
|
10900
|
-
createFollowEventSubscriber('follow.requestDeclined', handler),
|
|
10901
|
-
createFollowEventSubscriber('follow.followerDeleted', handler),
|
|
10902
|
-
createLocalFollowEventSubscriber('local.follow.created', handler),
|
|
10903
|
-
createLocalFollowEventSubscriber('local.follow.requested', handler),
|
|
10904
|
-
createLocalFollowEventSubscriber('local.follow.accepted', handler),
|
|
10905
|
-
createLocalFollowEventSubscriber('local.follow.unfollowed', handler),
|
|
10906
|
-
createLocalFollowEventSubscriber('local.follow.requestDeclined', handler),
|
|
10907
|
-
];
|
|
10908
|
-
return () => {
|
|
10909
|
-
disposers.forEach(fn => fn());
|
|
10910
|
-
};
|
|
10911
|
-
};
|
|
10912
|
-
|
|
10913
|
-
const onLocalUserFollowed = (callback) => createLocalFollowEventSubscriber('local.follow.created', callback);
|
|
10914
|
-
|
|
10915
|
-
const onLocalUserUnfollowed = (callback) => createLocalFollowEventSubscriber('local.follow.unfollowed', callback);
|
|
10916
|
-
|
|
10917
|
-
const onLocalFollowerRequested = (callback) => createLocalFollowEventSubscriber('local.follow.requested', callback);
|
|
10918
|
-
|
|
10919
|
-
const onLocalFollowRequestAccepted = (callback) => createLocalFollowEventSubscriber('local.follow.accepted', callback);
|
|
10920
|
-
|
|
10921
|
-
const onLocalFollowRequestDeclined = (callback) => createLocalFollowEventSubscriber('local.follow.requestDeclined', callback);
|
|
10958
|
+
const declineMyFollower = async (userId) => {
|
|
10959
|
+
const client = getActiveClient();
|
|
10960
|
+
client.log('follow/declineMyFollower', userId);
|
|
10961
|
+
const { data } = await client.http.delete(`/api/v4/me/followers/${userId}`);
|
|
10962
|
+
if (client.cache) {
|
|
10963
|
+
ingestInCache(data);
|
|
10964
|
+
}
|
|
10965
|
+
const payload = prepareFollowStatusPayload(data);
|
|
10966
|
+
fireEvent('local.follow.requestDeclined', payload);
|
|
10967
|
+
return true;
|
|
10968
|
+
};
|
|
10969
|
+
/* end_public_function */
|
|
10922
10970
|
|
|
10923
10971
|
/**
|
|
10924
10972
|
* ```js
|
|
@@ -11048,18 +11096,6 @@ class FollowerPaginationController extends PaginationController {
|
|
|
11048
11096
|
}
|
|
11049
11097
|
}
|
|
11050
11098
|
|
|
11051
|
-
var EnumFollowActions;
|
|
11052
|
-
(function (EnumFollowActions) {
|
|
11053
|
-
EnumFollowActions["OnRequested"] = "onRequested";
|
|
11054
|
-
EnumFollowActions["OnAccepted"] = "onAccepted";
|
|
11055
|
-
EnumFollowActions["OnDeclined"] = "onDeclined";
|
|
11056
|
-
EnumFollowActions["OnCanceled"] = "onCanceled";
|
|
11057
|
-
EnumFollowActions["OnFollowed"] = "onFollowed";
|
|
11058
|
-
EnumFollowActions["OnUnfollowed"] = "onUnfollowed";
|
|
11059
|
-
EnumFollowActions["OnDeleted"] = "onDeleted";
|
|
11060
|
-
EnumFollowActions["OnUserDeleted"] = "onUserDeleted";
|
|
11061
|
-
})(EnumFollowActions || (EnumFollowActions = {}));
|
|
11062
|
-
|
|
11063
11099
|
class FollowerQueryStreamController extends QueryStreamController {
|
|
11064
11100
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
11065
11101
|
super(query, cacheKey);
|
|
@@ -11137,7 +11173,7 @@ const onFollowerUserDeleted = ({ userId }) => (callback) => {
|
|
|
11137
11173
|
|
|
11138
11174
|
class FollowerLiveCollectionController extends LiveCollectionController {
|
|
11139
11175
|
constructor(query, callback) {
|
|
11140
|
-
const queryStreamId = hash__default["default"](query);
|
|
11176
|
+
const queryStreamId = hash__default["default"](Object.assign(Object.assign({}, query), { type: 'follower' }));
|
|
11141
11177
|
const cacheKey = ['follow', 'collection', queryStreamId];
|
|
11142
11178
|
const paginationController = new FollowerPaginationController(query);
|
|
11143
11179
|
super(paginationController, queryStreamId, cacheKey, callback);
|
|
@@ -11342,7 +11378,7 @@ const onFollowingUserDeleted = ({ userId }) => (callback) => {
|
|
|
11342
11378
|
|
|
11343
11379
|
class FollowingLiveCollectionController extends LiveCollectionController {
|
|
11344
11380
|
constructor(query, callback) {
|
|
11345
|
-
const queryStreamId = hash__default["default"](query);
|
|
11381
|
+
const queryStreamId = hash__default["default"](Object.assign(Object.assign({}, query), { type: 'following' }));
|
|
11346
11382
|
const cacheKey = ['follow', 'collection', queryStreamId];
|
|
11347
11383
|
const paginationController = new FollowingPaginationController(query);
|
|
11348
11384
|
super(paginationController, queryStreamId, cacheKey, callback);
|
|
@@ -13248,16 +13284,19 @@ function isCurrentUserPartOfCommunity(c, m) {
|
|
|
13248
13284
|
}
|
|
13249
13285
|
/*
|
|
13250
13286
|
* For mqtt events server will not send user specific data as it's broadcasted
|
|
13251
|
-
* to multiple users
|
|
13252
|
-
*
|
|
13287
|
+
* to multiple users and it also does not include communityUser
|
|
13288
|
+
*
|
|
13289
|
+
* Client SDK needs to check for the existing isJoined field in cache data before calculating.
|
|
13290
|
+
* Althought this can be calculated, it's not scalable.
|
|
13253
13291
|
*/
|
|
13254
13292
|
function updateMembershipStatus(communities, communityUsers) {
|
|
13255
13293
|
return communities.map(c => {
|
|
13256
|
-
|
|
13257
|
-
|
|
13258
|
-
return Object.assign(Object.assign({},
|
|
13294
|
+
const cachedCommunity = pullFromCache(['community', 'get', c.communityId]);
|
|
13295
|
+
if ((cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data) && (cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data.hasOwnProperty('isJoined'))) {
|
|
13296
|
+
return Object.assign(Object.assign({}, cachedCommunity.data), c);
|
|
13259
13297
|
}
|
|
13260
|
-
|
|
13298
|
+
const isJoined = communityUsers.some(m => isCurrentUserPartOfCommunity(c, m) && isMember(m.communityMembership));
|
|
13299
|
+
return Object.assign(Object.assign({}, c), { isJoined });
|
|
13261
13300
|
});
|
|
13262
13301
|
}
|
|
13263
13302
|
|
|
@@ -13358,7 +13397,7 @@ const addReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
13358
13397
|
referenceType,
|
|
13359
13398
|
reactionName,
|
|
13360
13399
|
});
|
|
13361
|
-
await client.http.post('/api/v2/reactions', {
|
|
13400
|
+
const { data } = await client.http.post('/api/v2/reactions', {
|
|
13362
13401
|
referenceId,
|
|
13363
13402
|
referenceType,
|
|
13364
13403
|
reactionName,
|
|
@@ -13376,12 +13415,33 @@ const addReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
13376
13415
|
if (referenceType === 'comment') {
|
|
13377
13416
|
fireEvent('local.comment.addReaction', {
|
|
13378
13417
|
comment: updatedModel,
|
|
13418
|
+
reactor: {
|
|
13419
|
+
userId: client.userId,
|
|
13420
|
+
reactionName,
|
|
13421
|
+
reactionId: data.addedId,
|
|
13422
|
+
},
|
|
13379
13423
|
});
|
|
13380
13424
|
return true;
|
|
13381
13425
|
}
|
|
13382
13426
|
if (referenceType === 'post') {
|
|
13383
13427
|
fireEvent('local.post.addReaction', {
|
|
13384
13428
|
post: updatedModel,
|
|
13429
|
+
reactor: {
|
|
13430
|
+
userId: client.userId,
|
|
13431
|
+
reactionName,
|
|
13432
|
+
reactionId: data.addedId,
|
|
13433
|
+
},
|
|
13434
|
+
});
|
|
13435
|
+
return true;
|
|
13436
|
+
}
|
|
13437
|
+
if (referenceType === 'story') {
|
|
13438
|
+
fireEvent('local.story.reactionAdded', {
|
|
13439
|
+
story: updatedModel,
|
|
13440
|
+
reactor: {
|
|
13441
|
+
userId: client.userId,
|
|
13442
|
+
reactionName,
|
|
13443
|
+
reactionId: data.addedId,
|
|
13444
|
+
},
|
|
13385
13445
|
});
|
|
13386
13446
|
return true;
|
|
13387
13447
|
}
|
|
@@ -13456,7 +13516,7 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
13456
13516
|
referenceType,
|
|
13457
13517
|
reactionName,
|
|
13458
13518
|
});
|
|
13459
|
-
await client.http.delete(`/api/v2/reactions`, {
|
|
13519
|
+
const { data } = await client.http.delete(`/api/v2/reactions`, {
|
|
13460
13520
|
data: {
|
|
13461
13521
|
referenceId,
|
|
13462
13522
|
referenceType,
|
|
@@ -13476,12 +13536,33 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
13476
13536
|
if (referenceType === 'comment') {
|
|
13477
13537
|
fireEvent('local.comment.removeReaction', {
|
|
13478
13538
|
comment: updatedModel,
|
|
13539
|
+
reactor: {
|
|
13540
|
+
reactionId: data.removedId,
|
|
13541
|
+
reactionName,
|
|
13542
|
+
userId: client.userId,
|
|
13543
|
+
},
|
|
13479
13544
|
});
|
|
13480
13545
|
return true;
|
|
13481
13546
|
}
|
|
13482
13547
|
if (referenceType === 'post') {
|
|
13483
13548
|
fireEvent('local.post.removeReaction', {
|
|
13484
13549
|
post: updatedModel,
|
|
13550
|
+
reactor: {
|
|
13551
|
+
reactionId: data.removedId,
|
|
13552
|
+
reactionName,
|
|
13553
|
+
userId: client.userId,
|
|
13554
|
+
},
|
|
13555
|
+
});
|
|
13556
|
+
return true;
|
|
13557
|
+
}
|
|
13558
|
+
if (referenceType === 'story') {
|
|
13559
|
+
fireEvent('local.story.reactionAdded', {
|
|
13560
|
+
story: updatedModel,
|
|
13561
|
+
reactor: {
|
|
13562
|
+
userId: client.userId,
|
|
13563
|
+
reactionName,
|
|
13564
|
+
reactionId: data.removedId,
|
|
13565
|
+
},
|
|
13485
13566
|
});
|
|
13486
13567
|
return true;
|
|
13487
13568
|
}
|
|
@@ -13505,7 +13586,7 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
13505
13586
|
* @category Reaction API
|
|
13506
13587
|
* */
|
|
13507
13588
|
removeReaction.optimistically = (referenceType, referenceId, reactionName) => {
|
|
13508
|
-
var _a, _b, _c, _d
|
|
13589
|
+
var _a, _b, _c, _d;
|
|
13509
13590
|
const client = getActiveClient();
|
|
13510
13591
|
client.log('reaction/removeReaction.optimistically', {
|
|
13511
13592
|
referenceId,
|
|
@@ -13526,7 +13607,7 @@ removeReaction.optimistically = (referenceType, referenceId, reactionName) => {
|
|
|
13526
13607
|
cachedAt: UNSYNCED_OBJECT_CACHED_AT_VALUE,
|
|
13527
13608
|
});
|
|
13528
13609
|
dispatchReactable(referenceType, reaction);
|
|
13529
|
-
return
|
|
13610
|
+
return !((_d = reaction === null || reaction === void 0 ? void 0 : reaction.myReactions) === null || _d === void 0 ? void 0 : _d.includes(reactionName));
|
|
13530
13611
|
};
|
|
13531
13612
|
|
|
13532
13613
|
const getMatchPostSetting = (value) => {
|
|
@@ -14348,67 +14429,256 @@ const onReactorRemoved = (referenceType, referenceId, callback) => {
|
|
|
14348
14429
|
|
|
14349
14430
|
const REFERENCE_API_V5 = 5;
|
|
14350
14431
|
|
|
14432
|
+
class ReactionPaginationController extends PaginationController {
|
|
14433
|
+
async getRequest(queryParams, token) {
|
|
14434
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
14435
|
+
const options = token ? { token } : { limit };
|
|
14436
|
+
const client = getActiveClient();
|
|
14437
|
+
client.log('reaction/queryReactions', queryParams);
|
|
14438
|
+
const path = '/api/v3/reactions';
|
|
14439
|
+
const { data: queryResponse } = await this.http.get(path, {
|
|
14440
|
+
params: Object.assign(Object.assign({}, params), { referenceVersion: REFERENCE_API_V5, // Need to put this param to make it can query reaction for message in sub-channel
|
|
14441
|
+
options }),
|
|
14442
|
+
});
|
|
14443
|
+
return queryResponse;
|
|
14444
|
+
}
|
|
14445
|
+
}
|
|
14446
|
+
|
|
14447
|
+
class ReactionQueryStreamController extends QueryStreamController {
|
|
14448
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
14449
|
+
super(query, cacheKey);
|
|
14450
|
+
this.notifyChange = notifyChange;
|
|
14451
|
+
this.preparePayload = preparePayload;
|
|
14452
|
+
}
|
|
14453
|
+
async saveToMainDB(response) {
|
|
14454
|
+
var _a;
|
|
14455
|
+
const processedPayload = await this.preparePayload(response);
|
|
14456
|
+
const client = getActiveClient();
|
|
14457
|
+
const cachedAt = client.cache && Date.now();
|
|
14458
|
+
if (client.cache) {
|
|
14459
|
+
const { reactions } = processedPayload, restPayload = __rest(processedPayload, ["reactions"]);
|
|
14460
|
+
ingestInCache(Object.assign(Object.assign({}, restPayload), { reactions, reactors: (_a = reactions[0]) === null || _a === void 0 ? void 0 : _a.reactors }), { cachedAt });
|
|
14461
|
+
}
|
|
14462
|
+
}
|
|
14463
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
14464
|
+
var _a, _b, _c, _d;
|
|
14465
|
+
const reactors = (_b = (_a = response.reactions[0]) === null || _a === void 0 ? void 0 : _a.reactors) !== null && _b !== void 0 ? _b : [];
|
|
14466
|
+
if (refresh) {
|
|
14467
|
+
pushToCache(this.cacheKey, {
|
|
14468
|
+
data: reactors.map(getResolver('reactor')),
|
|
14469
|
+
});
|
|
14470
|
+
}
|
|
14471
|
+
else {
|
|
14472
|
+
const collection = (_c = pullFromCache(this.cacheKey)) === null || _c === void 0 ? void 0 : _c.data;
|
|
14473
|
+
const reactions = (_d = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _d !== void 0 ? _d : [];
|
|
14474
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...reactions, ...reactors.map(getResolver('reactor'))])] }));
|
|
14475
|
+
}
|
|
14476
|
+
}
|
|
14477
|
+
reactor(action) {
|
|
14478
|
+
return (reaction) => {
|
|
14479
|
+
var _a;
|
|
14480
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
14481
|
+
if (!collection)
|
|
14482
|
+
return;
|
|
14483
|
+
if (action === "onAdded" /* Amity.ReactionActionTypeEnum.OnAdded */) {
|
|
14484
|
+
collection.data = [...new Set([reaction.reactionId, ...collection.data])];
|
|
14485
|
+
}
|
|
14486
|
+
else if (action === "onRemoved" /* Amity.ReactionActionTypeEnum.OnRemoved */) {
|
|
14487
|
+
collection.data = collection.data.filter(p => p !== reaction.reactionId);
|
|
14488
|
+
}
|
|
14489
|
+
pushToCache(this.cacheKey, collection);
|
|
14490
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
14491
|
+
};
|
|
14492
|
+
}
|
|
14493
|
+
subscribeRTE(createSubscriber) {
|
|
14494
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
14495
|
+
}
|
|
14496
|
+
}
|
|
14497
|
+
|
|
14351
14498
|
/**
|
|
14352
14499
|
* ```js
|
|
14353
|
-
* import {
|
|
14354
|
-
* const
|
|
14355
|
-
*
|
|
14356
|
-
* referenceType: 'post',
|
|
14500
|
+
* import { onReactorRemovedLocal } from '@amityco/ts-sdk'
|
|
14501
|
+
* const dispose = onReactorRemoved('post', postId, reactor => {
|
|
14502
|
+
* // ...
|
|
14357
14503
|
* })
|
|
14358
14504
|
* ```
|
|
14359
14505
|
*
|
|
14360
|
-
*
|
|
14506
|
+
* Fired when an {@link Amity.InternalReactor} has been removed
|
|
14361
14507
|
*
|
|
14362
|
-
* @param
|
|
14363
|
-
* @
|
|
14508
|
+
* @param {@link Amity.ReactableType} referenceType
|
|
14509
|
+
* @param {string} referenceId
|
|
14510
|
+
* @param callback The function to call when the event was fired
|
|
14511
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
14364
14512
|
*
|
|
14365
|
-
* @
|
|
14366
|
-
* @async
|
|
14513
|
+
* @category Events
|
|
14367
14514
|
* */
|
|
14368
|
-
const
|
|
14515
|
+
const onReactorRemovedLocal = (referenceType, referenceId, callback) => {
|
|
14369
14516
|
const client = getActiveClient();
|
|
14370
|
-
|
|
14371
|
-
|
|
14372
|
-
|
|
14373
|
-
|
|
14374
|
-
|
|
14375
|
-
|
|
14376
|
-
|
|
14377
|
-
|
|
14378
|
-
|
|
14379
|
-
|
|
14380
|
-
|
|
14381
|
-
|
|
14382
|
-
|
|
14383
|
-
|
|
14384
|
-
|
|
14385
|
-
|
|
14517
|
+
const callbackWrapper = (referenceType_, referenceId_, reaction) => {
|
|
14518
|
+
if (referenceType_ === referenceType && referenceId_ === referenceId) {
|
|
14519
|
+
callback(reaction);
|
|
14520
|
+
}
|
|
14521
|
+
};
|
|
14522
|
+
if (referenceType === 'message') {
|
|
14523
|
+
const filter = async (rawPayload) => {
|
|
14524
|
+
const payload = await prepareMessagePayload(rawPayload);
|
|
14525
|
+
if (!payload.reactions[0])
|
|
14526
|
+
return;
|
|
14527
|
+
ingestInCache(payload);
|
|
14528
|
+
callbackWrapper('message', payload.messages[0].messageId, payload.reactions[0]);
|
|
14529
|
+
};
|
|
14530
|
+
return createEventSubscriber(client, 'reaction/onReactorRemoved', 'message.reactionRemoved', filter);
|
|
14531
|
+
}
|
|
14532
|
+
if (referenceType === 'post') {
|
|
14533
|
+
const filter = (payload) => {
|
|
14534
|
+
callbackWrapper('post', payload.post.postId, payload.reactor);
|
|
14535
|
+
};
|
|
14536
|
+
return createEventSubscriber(client, 'local.post.removeReaction', 'local.post.removeReaction', filter);
|
|
14537
|
+
}
|
|
14538
|
+
if (referenceType === 'story') {
|
|
14539
|
+
const filter = (payload) => {
|
|
14540
|
+
const { reactions } = payload, rest = __rest(payload, ["reactions"]);
|
|
14541
|
+
ingestInCache(rest);
|
|
14542
|
+
ingestInCache({ reactors: reactions });
|
|
14543
|
+
if (payload.stories.length === 0 || payload.reactions.length === 0)
|
|
14544
|
+
return;
|
|
14545
|
+
callbackWrapper('story', payload.stories[0].storyId, payload.reactions[0]);
|
|
14546
|
+
};
|
|
14547
|
+
return createEventSubscriber(client, 'story.reactionRemoved', 'story.reactionRemoved', filter);
|
|
14548
|
+
}
|
|
14549
|
+
const filter = (payload) => {
|
|
14550
|
+
callbackWrapper('comment', payload.comment.commentId, payload.reactor);
|
|
14551
|
+
};
|
|
14552
|
+
return createEventSubscriber(client, 'local.comment.removeReaction', 'local.comment.removeReaction', filter);
|
|
14386
14553
|
};
|
|
14387
14554
|
|
|
14388
14555
|
/**
|
|
14389
14556
|
* ```js
|
|
14390
|
-
* import {
|
|
14391
|
-
* const
|
|
14392
|
-
*
|
|
14393
|
-
* referenceType: 'post',
|
|
14557
|
+
* import { onReactorAddedLocal } from '@amityco/ts-sdk'
|
|
14558
|
+
* const dispose = onReactorAdded('post', postId, reactor => {
|
|
14559
|
+
* // ...
|
|
14394
14560
|
* })
|
|
14395
14561
|
* ```
|
|
14396
14562
|
*
|
|
14397
|
-
*
|
|
14563
|
+
* Fired when an {@link Amity.InternalReactor} has been added
|
|
14398
14564
|
*
|
|
14399
|
-
* @param
|
|
14400
|
-
* @
|
|
14565
|
+
* @param {@link Amity.ReactableType} referenceType
|
|
14566
|
+
* @param {string} referenceId
|
|
14567
|
+
* @param callback The function to call when the event was fired
|
|
14568
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
14401
14569
|
*
|
|
14402
|
-
* @
|
|
14403
|
-
* @async
|
|
14570
|
+
* @category Events
|
|
14404
14571
|
* */
|
|
14405
|
-
const
|
|
14572
|
+
const onReactorAddedLocal = (referenceType, referenceId, callback) => {
|
|
14406
14573
|
const client = getActiveClient();
|
|
14407
|
-
|
|
14408
|
-
|
|
14409
|
-
|
|
14574
|
+
const callbackWrapper = (referenceType_, referenceId_, reaction) => {
|
|
14575
|
+
if (referenceType_ === referenceType && referenceId_ === referenceId) {
|
|
14576
|
+
callback(reaction);
|
|
14577
|
+
}
|
|
14578
|
+
};
|
|
14579
|
+
if (referenceType === 'message') {
|
|
14580
|
+
const filter = async (rawPayload) => {
|
|
14581
|
+
const payload = await prepareMessagePayload(rawPayload);
|
|
14582
|
+
if (!payload.reactions[0])
|
|
14583
|
+
return;
|
|
14584
|
+
ingestInCache(payload);
|
|
14585
|
+
ingestInCache({ reactors: payload.reactions });
|
|
14586
|
+
callbackWrapper('message', payload.messages[0].messageId, payload.reactions[0]);
|
|
14587
|
+
};
|
|
14588
|
+
return createEventSubscriber(client, 'reaction/onReactorAdded', 'message.reactionAdded', filter);
|
|
14589
|
+
}
|
|
14590
|
+
if (referenceType === 'post') {
|
|
14591
|
+
const filter = (payload) => {
|
|
14592
|
+
callbackWrapper('post', payload.post.postId, payload.reactor);
|
|
14593
|
+
};
|
|
14594
|
+
return createEventSubscriber(client, 'local.post.addReaction', 'local.post.addReaction', filter);
|
|
14595
|
+
}
|
|
14596
|
+
if (referenceType === 'story') {
|
|
14597
|
+
const filter = (payload) => {
|
|
14598
|
+
const { reactions } = payload, rest = __rest(payload, ["reactions"]);
|
|
14599
|
+
ingestInCache(rest);
|
|
14600
|
+
ingestInCache({ reactors: reactions });
|
|
14601
|
+
if (payload.stories.length === 0 || payload.reactions.length === 0)
|
|
14602
|
+
return;
|
|
14603
|
+
callbackWrapper('story', payload.stories[0].storyId, payload.reactions[0]);
|
|
14604
|
+
};
|
|
14605
|
+
return createEventSubscriber(client, 'story.reactionAdded', 'story.reactionAdded', filter);
|
|
14606
|
+
}
|
|
14607
|
+
const filter = (payload) => {
|
|
14608
|
+
callbackWrapper('comment', payload.comment.commentId, payload.reactor);
|
|
14609
|
+
};
|
|
14610
|
+
return createEventSubscriber(client, 'local.comment.addReaction', 'local.comment.addReaction', filter);
|
|
14410
14611
|
};
|
|
14411
14612
|
|
|
14613
|
+
class ReactionLiveCollectionController extends LiveCollectionController {
|
|
14614
|
+
constructor(query, callback) {
|
|
14615
|
+
const queryStreamId = hash__default["default"](query);
|
|
14616
|
+
const cacheKey = ['reaction', 'collection', queryStreamId];
|
|
14617
|
+
const paginationController = new ReactionPaginationController(query);
|
|
14618
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
14619
|
+
this.query = query;
|
|
14620
|
+
this.queryStreamController = new ReactionQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), payload => payload);
|
|
14621
|
+
this.callback = callback.bind(this);
|
|
14622
|
+
this.loadPage({ initial: true });
|
|
14623
|
+
}
|
|
14624
|
+
setup() {
|
|
14625
|
+
var _a;
|
|
14626
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
14627
|
+
if (!collection) {
|
|
14628
|
+
pushToCache(this.cacheKey, {
|
|
14629
|
+
data: [],
|
|
14630
|
+
params: {},
|
|
14631
|
+
});
|
|
14632
|
+
}
|
|
14633
|
+
}
|
|
14634
|
+
async persistModel(queryPayload) {
|
|
14635
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
14636
|
+
}
|
|
14637
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
14638
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
14639
|
+
}
|
|
14640
|
+
startSubscription() {
|
|
14641
|
+
return this.queryStreamController.subscribeRTE([
|
|
14642
|
+
{
|
|
14643
|
+
fn: callback => onReactorAdded(this.query.referenceType, this.query.referenceId, callback),
|
|
14644
|
+
action: "onAdded" /* Amity.ReactionActionTypeEnum.OnAdded */,
|
|
14645
|
+
},
|
|
14646
|
+
{
|
|
14647
|
+
fn: callback => onReactorRemoved(this.query.referenceType, this.query.referenceId, callback),
|
|
14648
|
+
action: "onRemoved" /* Amity.ReactionActionTypeEnum.OnRemoved */,
|
|
14649
|
+
},
|
|
14650
|
+
{
|
|
14651
|
+
fn: callback => onReactorRemovedLocal(this.query.referenceType, this.query.referenceId, callback),
|
|
14652
|
+
action: "onRemoved" /* Amity.ReactionActionTypeEnum.OnRemoved */,
|
|
14653
|
+
},
|
|
14654
|
+
{
|
|
14655
|
+
fn: callback => onReactorAddedLocal(this.query.referenceType, this.query.referenceId, callback),
|
|
14656
|
+
action: "onRemoved" /* Amity.ReactionActionTypeEnum.OnRemoved */,
|
|
14657
|
+
},
|
|
14658
|
+
]);
|
|
14659
|
+
}
|
|
14660
|
+
notifyChange({ origin, loading, error }) {
|
|
14661
|
+
var _a, _b;
|
|
14662
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
14663
|
+
if (!collection)
|
|
14664
|
+
return;
|
|
14665
|
+
const data = (_b = collection.data
|
|
14666
|
+
.map(reactorId => pullFromCache(['reactor', 'get', reactorId]))
|
|
14667
|
+
.filter(Boolean)
|
|
14668
|
+
.map(({ data }) => LinkedObject.reactor(data))) !== null && _b !== void 0 ? _b : [];
|
|
14669
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
14670
|
+
return;
|
|
14671
|
+
this.callback({
|
|
14672
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
14673
|
+
data,
|
|
14674
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
14675
|
+
loading,
|
|
14676
|
+
error,
|
|
14677
|
+
});
|
|
14678
|
+
}
|
|
14679
|
+
}
|
|
14680
|
+
|
|
14681
|
+
/* eslint-disable no-use-before-define */
|
|
14412
14682
|
/* begin_public_function
|
|
14413
14683
|
id: reaction.query
|
|
14414
14684
|
*/
|
|
@@ -14438,69 +14708,15 @@ const getReactions = (params, callback, config) => {
|
|
|
14438
14708
|
console.log('For using Live Collection feature you need to enable Cache!');
|
|
14439
14709
|
}
|
|
14440
14710
|
const timestamp = Date.now();
|
|
14441
|
-
log(`
|
|
14442
|
-
const
|
|
14443
|
-
const
|
|
14444
|
-
const
|
|
14445
|
-
|
|
14446
|
-
|
|
14447
|
-
|
|
14448
|
-
'collection',
|
|
14449
|
-
{ referenceId: params.referenceId, referenceType: params.referenceType },
|
|
14450
|
-
];
|
|
14451
|
-
const responder = (data) => {
|
|
14452
|
-
var _a, _b;
|
|
14453
|
-
const reactions = (_a = data.data
|
|
14454
|
-
.map(reactorId => pullFromCache(['reactor', 'get', reactorId]))
|
|
14455
|
-
.filter(Boolean)
|
|
14456
|
-
.map(({ data }) => LinkedObject.reactor(data))) !== null && _a !== void 0 ? _a : [];
|
|
14457
|
-
callback({
|
|
14458
|
-
onNextPage: onFetch,
|
|
14459
|
-
data: reactions,
|
|
14460
|
-
hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
|
|
14461
|
-
loading: data.loading,
|
|
14462
|
-
error: data.error,
|
|
14463
|
-
});
|
|
14464
|
-
};
|
|
14465
|
-
const realtimeRouter = (action) => (reaction) => {
|
|
14466
|
-
var _a;
|
|
14467
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
14468
|
-
if (!collection)
|
|
14469
|
-
return;
|
|
14470
|
-
if (action === 'onAdded') {
|
|
14471
|
-
collection.data = [...new Set([reaction.reactionId, ...collection.data])];
|
|
14472
|
-
}
|
|
14473
|
-
else if (action === 'onRemoved') {
|
|
14474
|
-
collection.data = collection.data.filter(p => p !== reaction.reactionId);
|
|
14475
|
-
}
|
|
14476
|
-
pushToCache(cacheKey, collection);
|
|
14477
|
-
responder(collection);
|
|
14478
|
-
};
|
|
14479
|
-
const onFetch = (initial = false) => {
|
|
14480
|
-
var _a, _b, _c, _d;
|
|
14481
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
14482
|
-
const reactions = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
14483
|
-
if (!initial && reactions.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
|
|
14484
|
-
return;
|
|
14485
|
-
const query = createQuery(queryReactor, Object.assign(Object.assign({}, queryParams), { page: (_d = (!initial ? collection === null || collection === void 0 ? void 0 : collection.params.page : undefined)) !== null && _d !== void 0 ? _d : { limit } }));
|
|
14486
|
-
runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
|
|
14487
|
-
const data = {
|
|
14488
|
-
loading,
|
|
14489
|
-
error,
|
|
14490
|
-
params: { page },
|
|
14491
|
-
data: reactions,
|
|
14492
|
-
};
|
|
14493
|
-
if (result) {
|
|
14494
|
-
data.data = [...new Set([...reactions, ...result.map(getResolver('reactor'))])];
|
|
14495
|
-
}
|
|
14496
|
-
pushToCache(cacheKey, data);
|
|
14497
|
-
responder(data);
|
|
14498
|
-
}, queryOptions(policy));
|
|
14499
|
-
};
|
|
14500
|
-
disposers.push(onReactorAdded(queryParams.referenceType, queryParams.referenceId, realtimeRouter('onAdded')), onReactorRemoved(queryParams.referenceType, queryParams.referenceId, realtimeRouter('onRemoved')));
|
|
14501
|
-
onFetch(true);
|
|
14711
|
+
log(`getReactions(tmpid: ${timestamp}) > listen`);
|
|
14712
|
+
const reactionLiveCollection = new ReactionLiveCollectionController(params, callback);
|
|
14713
|
+
const disposers = reactionLiveCollection.startSubscription();
|
|
14714
|
+
const cacheKey = reactionLiveCollection.getCacheKey();
|
|
14715
|
+
disposers.push(() => {
|
|
14716
|
+
dropFromCache(cacheKey);
|
|
14717
|
+
});
|
|
14502
14718
|
return () => {
|
|
14503
|
-
log(`
|
|
14719
|
+
log(`getReactions(tmpid: ${timestamp}) > dispose`);
|
|
14504
14720
|
disposers.forEach(fn => fn());
|
|
14505
14721
|
};
|
|
14506
14722
|
};
|
|
@@ -15006,30 +15222,6 @@ const unmuteChannel = async (channelId) => {
|
|
|
15006
15222
|
};
|
|
15007
15223
|
/* end_public_function */
|
|
15008
15224
|
|
|
15009
|
-
const convertEventPayload = (eventHandler, sourceModelProp, destinationDomain) => (callback) => eventHandler(sourceModel => {
|
|
15010
|
-
var _a, _b;
|
|
15011
|
-
if (!sourceModel) {
|
|
15012
|
-
return sourceModel;
|
|
15013
|
-
}
|
|
15014
|
-
const client = getActiveClient();
|
|
15015
|
-
const { objectSyncMap } = client;
|
|
15016
|
-
/*
|
|
15017
|
-
* NOTE: For objects created locally (optimistic creation), the SDK stores them with their local ID as the cache key, which is used throughout the entire SDK session (in-memory) for syncing updates.
|
|
15018
|
-
* If the payload or response only contains the remote ID of the same object, the SDK will look up the corresponding local ID to retrieve the object.
|
|
15019
|
-
*/
|
|
15020
|
-
const resolvedId = isLocalId(sourceModel[sourceModelProp])
|
|
15021
|
-
? sourceModel[sourceModelProp]
|
|
15022
|
-
: (_a = objectSyncMap.get(sourceModel[sourceModelProp])) !== null && _a !== void 0 ? _a : sourceModel[sourceModelProp];
|
|
15023
|
-
const model = (_b = pullFromCache([
|
|
15024
|
-
destinationDomain,
|
|
15025
|
-
'get',
|
|
15026
|
-
`${resolvedId}`,
|
|
15027
|
-
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
15028
|
-
if (!model)
|
|
15029
|
-
return;
|
|
15030
|
-
return callback(model);
|
|
15031
|
-
});
|
|
15032
|
-
|
|
15033
15225
|
/**
|
|
15034
15226
|
* ```js
|
|
15035
15227
|
* import { observeChannel } from '@amityco/ts-sdk'
|
|
@@ -19168,7 +19360,8 @@ const createCommunityMemberEventSubscriber = (event, callback) => {
|
|
|
19168
19360
|
callback(preparedPayload.communities[0], getEventRelatedMember(event, preparedPayload));
|
|
19169
19361
|
}
|
|
19170
19362
|
else {
|
|
19171
|
-
|
|
19363
|
+
// NOTE: The event payload should be merge with existing cache data
|
|
19364
|
+
ingestInCache(preparedPayload, undefined, false);
|
|
19172
19365
|
const community = pullFromCache([
|
|
19173
19366
|
'community',
|
|
19174
19367
|
'get',
|
|
@@ -19205,7 +19398,8 @@ const createLocalCommunityMemberEventSubscriber = (event, callback) => {
|
|
|
19205
19398
|
callback(preparedPayload.communities[0], getEventRelatedMember(event, preparedPayload));
|
|
19206
19399
|
}
|
|
19207
19400
|
else {
|
|
19208
|
-
|
|
19401
|
+
// NOTE: The event payload should be merge with existing cache data
|
|
19402
|
+
ingestInCache(preparedPayload, undefined, false);
|
|
19209
19403
|
const community = pullFromCache([
|
|
19210
19404
|
'community',
|
|
19211
19405
|
'get',
|
|
@@ -21295,9 +21489,10 @@ const queryGlobalFeed = async (query) => {
|
|
|
21295
21489
|
const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
|
|
21296
21490
|
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
21297
21491
|
const { posts } = data;
|
|
21492
|
+
const { communities: processedCommunity } = prepareCommunityPayload(data);
|
|
21298
21493
|
const cachedAt = client.cache && Date.now();
|
|
21299
21494
|
if (client.cache) {
|
|
21300
|
-
ingestInCache(data);
|
|
21495
|
+
ingestInCache(Object.assign(Object.assign({}, data), { communitis: processedCommunity }));
|
|
21301
21496
|
const cacheKey = [
|
|
21302
21497
|
'globalFeed',
|
|
21303
21498
|
'query',
|
|
@@ -23612,6 +23807,145 @@ const getPinnedPosts = (params, callback, config) => {
|
|
|
23612
23807
|
};
|
|
23613
23808
|
};
|
|
23614
23809
|
|
|
23810
|
+
class GlobalPinnedPostPaginationController extends PaginationController {
|
|
23811
|
+
async getRequest(queryParams, token) {
|
|
23812
|
+
__rest(queryParams, ["limit"]);
|
|
23813
|
+
const path = '/api/v1/pinned-posts/global';
|
|
23814
|
+
const { data: queryResponse } = await this.http.get(path);
|
|
23815
|
+
return queryResponse;
|
|
23816
|
+
}
|
|
23817
|
+
}
|
|
23818
|
+
|
|
23819
|
+
class GlobalPinnedPostQueryStreamController extends QueryStreamController {
|
|
23820
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
23821
|
+
super(query, cacheKey);
|
|
23822
|
+
this.notifyChange = notifyChange;
|
|
23823
|
+
this.preparePayload = preparePayload;
|
|
23824
|
+
}
|
|
23825
|
+
// eslint-disable-next-line class-methods-use-this
|
|
23826
|
+
async saveToMainDB(response) {
|
|
23827
|
+
const client = getActiveClient();
|
|
23828
|
+
const cachedAt = client.cache && Date.now();
|
|
23829
|
+
if (client.cache) {
|
|
23830
|
+
ingestInCache(response, { cachedAt });
|
|
23831
|
+
}
|
|
23832
|
+
}
|
|
23833
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
23834
|
+
var _a, _b;
|
|
23835
|
+
if (refresh) {
|
|
23836
|
+
pushToCache(this.cacheKey, {
|
|
23837
|
+
data: response.pins.map(getResolver('pin')),
|
|
23838
|
+
});
|
|
23839
|
+
}
|
|
23840
|
+
else {
|
|
23841
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23842
|
+
const pinnedPosts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
23843
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...pinnedPosts, ...response.pins.map(getResolver('pin'))])] }));
|
|
23844
|
+
this.notifyChange({
|
|
23845
|
+
origin: "server" /* Amity.LiveDataOrigin.SERVER */,
|
|
23846
|
+
loading: false,
|
|
23847
|
+
});
|
|
23848
|
+
}
|
|
23849
|
+
}
|
|
23850
|
+
reactor(action) {
|
|
23851
|
+
return (post) => {
|
|
23852
|
+
var _a;
|
|
23853
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23854
|
+
if (!collection)
|
|
23855
|
+
return;
|
|
23856
|
+
if (action === EnumPostActions.OnPostDeleted) {
|
|
23857
|
+
collection.data = collection.data.filter(referenceId => referenceId !== `global#${post.postId}`);
|
|
23858
|
+
}
|
|
23859
|
+
pushToCache(this.cacheKey, collection);
|
|
23860
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
23861
|
+
};
|
|
23862
|
+
}
|
|
23863
|
+
subscribeRTE(createSubscriber) {
|
|
23864
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
23865
|
+
}
|
|
23866
|
+
}
|
|
23867
|
+
|
|
23868
|
+
class GlobalPinnedPostLiveCollectionController extends LiveCollectionController {
|
|
23869
|
+
constructor(query, callback) {
|
|
23870
|
+
const queryStreamId = hash__default["default"](query);
|
|
23871
|
+
const cacheKey = ['pinnedPosts', 'collection', queryStreamId];
|
|
23872
|
+
const paginationController = new GlobalPinnedPostPaginationController(query);
|
|
23873
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
23874
|
+
this.query = query;
|
|
23875
|
+
this.queryStreamController = new GlobalPinnedPostQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), response => response);
|
|
23876
|
+
this.callback = callback.bind(this);
|
|
23877
|
+
this.loadPage({ initial: true });
|
|
23878
|
+
}
|
|
23879
|
+
setup() {
|
|
23880
|
+
var _a;
|
|
23881
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23882
|
+
if (!collection) {
|
|
23883
|
+
pushToCache(this.cacheKey, {
|
|
23884
|
+
data: [],
|
|
23885
|
+
params: {},
|
|
23886
|
+
});
|
|
23887
|
+
}
|
|
23888
|
+
}
|
|
23889
|
+
async persistModel(queryPayload) {
|
|
23890
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
23891
|
+
}
|
|
23892
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
23893
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
23894
|
+
}
|
|
23895
|
+
// eslint-disable-next-line class-methods-use-this
|
|
23896
|
+
startSubscription() {
|
|
23897
|
+
return this.queryStreamController.subscribeRTE([
|
|
23898
|
+
{ fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
|
|
23899
|
+
{
|
|
23900
|
+
fn: onPostDeleted,
|
|
23901
|
+
action: EnumPostActions.OnPostDeleted,
|
|
23902
|
+
},
|
|
23903
|
+
]);
|
|
23904
|
+
}
|
|
23905
|
+
notifyChange({ origin, loading, error }) {
|
|
23906
|
+
var _a, _b;
|
|
23907
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23908
|
+
if (!collection)
|
|
23909
|
+
return;
|
|
23910
|
+
const data = ((_b = collection.data
|
|
23911
|
+
.map(id => pullFromCache(['pin', 'get', id]))
|
|
23912
|
+
.filter(isNonNullable)
|
|
23913
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.pinnedPost);
|
|
23914
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
23915
|
+
return;
|
|
23916
|
+
this.callback({
|
|
23917
|
+
data,
|
|
23918
|
+
loading,
|
|
23919
|
+
error,
|
|
23920
|
+
});
|
|
23921
|
+
}
|
|
23922
|
+
}
|
|
23923
|
+
|
|
23924
|
+
/**
|
|
23925
|
+
* Get global pinned posts
|
|
23926
|
+
*
|
|
23927
|
+
* @returns the global pinned post(s)
|
|
23928
|
+
*
|
|
23929
|
+
* @category Pined Posts Live Collection
|
|
23930
|
+
*
|
|
23931
|
+
*/
|
|
23932
|
+
const getGlobalPinnedPosts = (params, callback, config) => {
|
|
23933
|
+
const { log, cache } = getActiveClient();
|
|
23934
|
+
if (!cache) {
|
|
23935
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
23936
|
+
}
|
|
23937
|
+
const timestamp = Date.now();
|
|
23938
|
+
log(`getGlobalPinnedPosts(tmpid: ${timestamp}) > listen`);
|
|
23939
|
+
const globalPinnedPostLiveCollection = new GlobalPinnedPostLiveCollectionController(params, callback);
|
|
23940
|
+
const disposers = globalPinnedPostLiveCollection.startSubscription();
|
|
23941
|
+
const cacheKey = globalPinnedPostLiveCollection.getCacheKey();
|
|
23942
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
23943
|
+
return () => {
|
|
23944
|
+
log(`getGlobalPinnedPosts(tmpid: ${timestamp}) > dispose`);
|
|
23945
|
+
disposers.forEach(fn => fn());
|
|
23946
|
+
};
|
|
23947
|
+
};
|
|
23948
|
+
|
|
23615
23949
|
class SemanticSearchPostPaginationController extends PaginationController {
|
|
23616
23950
|
async getRequest(queryParams, token) {
|
|
23617
23951
|
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
@@ -23873,6 +24207,7 @@ var index$5 = /*#__PURE__*/Object.freeze({
|
|
|
23873
24207
|
getPost: getPost$1,
|
|
23874
24208
|
getPosts: getPosts,
|
|
23875
24209
|
getPinnedPosts: getPinnedPosts,
|
|
24210
|
+
getGlobalPinnedPosts: getGlobalPinnedPosts,
|
|
23876
24211
|
semanticSearchPosts: semanticSearchPosts
|
|
23877
24212
|
});
|
|
23878
24213
|
|
|
@@ -24767,7 +25102,7 @@ var index$3 = /*#__PURE__*/Object.freeze({
|
|
|
24767
25102
|
getPoll: getPoll
|
|
24768
25103
|
});
|
|
24769
25104
|
|
|
24770
|
-
const privateKey = "-----BEGIN PRIVATE KEY-----\
|
|
25105
|
+
const privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDAARz+hmBgi8pJ\nQb8LeY41gtHhk+ACMwRfhsn7GqpqRQNG2qU0755mzZuVDUqjQMGSo8THJB7O+OJs\nflbZRkFXlFoFOVNw1UpNOgwEQZ6wB9oRwzepTJAfF1sVhm/o/ixvXh1zDFNDy6yZ\npXyiiJHUVxqyjllZhxnwdvjoVtDs6hW6awG09bB9nh/TTejlUKXoAgzqVwu/1QMu\nUVViET495elEe19aUarEy+oL2iKeXCEvqda/pWNBdbieFyJvvZ08HN8dPuT88wq2\njZLEAth1vrwQ2IAa4ktaLcBQdLJgIkrbDvAiVZ8lQAjS/bq5vXQikTGvoPlC5bbn\nvuOM/3eLAgMBAAECggEAVZ+peHAghq2QVj71nX5lxsNCKaCyYwixSJBpfouTt7Rz\nE6PpzMOXFi1W1o+I22jDakuSM2SOQKqI/u0QefB0r0O/KVk5NrZHXk0mkrdYtxOp\nUgaGyf8UvmjB+8VqHrNKyZdk9qtmbnNj01kTTcAtmE4H39zPR7eR/8Rul94vaZbs\nwCnKJS3mLT3JxyGug6lxanveKkjG+CKC1nJQYWaxCJxaFSzbwXQPvDhB+TvrIbee\npd5v4EAyEJohpr+T9oDGGJkb/KARBZCtwLyB976PKJwwBA8MRVL1i5QwawuMiMq5\nUtnOnbGKtCeFzaLbNU0Qi8bqyims84EQxC6DOu1fkQKBgQDdvsoBsEhsOXV7hlIJ\naEd0eSJZVkdqimxH8uGoMM2FeNaOrcB6yBXqTSP0R3OIyf8eaY6yjRvP30ZNXcll\n/gD3O1Mu6YmWQdt1W2WA6pKOsUuPXasf0pdOF7IiFZKlSabz5YHXFqwVuqm8loaj\nsXel3YWqPVdHiankE7tz+3ssnQKBgQDdqi4TNdD1MdEpihx19jr0QjUiXW3939FK\nqp30HESPEGDGQzXdmJgif9HhZb+cJSuWaHEbjgBrYahvgCF+y6LbEpOD+D/dmT+s\nDEAQaR84sah6dokwPjV8fjBSrcVFjCS+doxv0d3p/9OUEeyUhFrY03nxtIEYkLIE\n/Zvn37b4RwKBgQCLENVFe9XfsaVhQ5r9dV2iyTlmh7qgMZG5CbTFs12hQGhm8McO\n+Z7s41YSJCFr/yq1WwP4LJDtrBw99vyQr1zRsG35tNLp3gGRNzGQSQyC2uQFVHw2\np+7mNewsfhUK/gbrXNsyFnDz6635rPlhfbII3sWuP2wWXFqkxE9CbMwR7QKBgQC6\nawDMzxmo2/iYArrkyevSuEuPVxvFwpF1RgAI6C0QVCnPE38dmdN4UB7mfHekje4W\nVEercMURidPp0cxZolCYBQtilUjAyL0vqC3In1/Ogjq6oy3FEMxSop1pKxMY5j+Q\nnoqFD+6deLUrddeNH7J3X4LSr4dSbX4JjG+tlgt+yQKBgQCuwTL4hA6KqeInQ0Ta\n9VQX5Qr8hFlqJz1gpymi/k63tW/Ob8yedbg3WWNWyShwRMFYyY9S81ITFWM95uL6\nvF3x9rmRjwElJw9PMwVu6dmf/CO0Z1wzXSp2VVD12gbrUD/0/d7MUoJ9LgC8X8f/\nn0txLHYGHbx+nf95+JUg6lV3hg==\n-----END PRIVATE KEY-----";
|
|
24771
25106
|
/*
|
|
24772
25107
|
* The crypto algorithm used for importing key and signing string
|
|
24773
25108
|
*/
|
|
@@ -25423,8 +25758,8 @@ const onStoryReactionAdded = (callback) => {
|
|
|
25423
25758
|
const onStoryReactionAddedLocal = (callback) => {
|
|
25424
25759
|
const client = getActiveClient();
|
|
25425
25760
|
const filter = async (payload) => {
|
|
25426
|
-
ingestInCache(payload);
|
|
25427
|
-
callback(payload.
|
|
25761
|
+
ingestInCache({ stories: [payload.story] });
|
|
25762
|
+
callback([payload.story]);
|
|
25428
25763
|
};
|
|
25429
25764
|
const disposers = [
|
|
25430
25765
|
createEventSubscriber(client, 'onStoryReactionAdded', 'local.story.reactionAdded', filter),
|
|
@@ -25453,8 +25788,8 @@ const onStoryReactionRemoved = (callback) => {
|
|
|
25453
25788
|
const onStoryReactionRemovedLocal = (callback) => {
|
|
25454
25789
|
const client = getActiveClient();
|
|
25455
25790
|
const filter = async (payload) => {
|
|
25456
|
-
ingestInCache(payload);
|
|
25457
|
-
callback(payload.
|
|
25791
|
+
ingestInCache({ stories: [payload.story] });
|
|
25792
|
+
callback([payload.story]);
|
|
25458
25793
|
};
|
|
25459
25794
|
const disposers = [
|
|
25460
25795
|
createEventSubscriber(client, 'onStoryReactionRemoved', 'local.story.reactionRemoved', filter),
|
|
@@ -25994,12 +26329,12 @@ const updateLocalList = (cacheKey, targetIds) => {
|
|
|
25994
26329
|
pushToCache(cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...storyTargets, ...targetIds])] }));
|
|
25995
26330
|
};
|
|
25996
26331
|
class GlobalStoryQueryStreamController extends QueryStreamController {
|
|
25997
|
-
constructor(query, cacheKey, notifyChange, paginationController) {
|
|
26332
|
+
constructor(query, cacheKey, notifyChange, paginationController, preparePayload) {
|
|
25998
26333
|
super(query, cacheKey);
|
|
25999
26334
|
this.notifyChange = notifyChange;
|
|
26000
26335
|
this.paginationController = paginationController;
|
|
26001
26336
|
// Fix ESLint, "Expected 'this' to be used by class method"
|
|
26002
|
-
this.preparePayload =
|
|
26337
|
+
this.preparePayload = preparePayload;
|
|
26003
26338
|
}
|
|
26004
26339
|
saveToMainDB(response) {
|
|
26005
26340
|
const client = getActiveClient();
|
|
@@ -26091,7 +26426,10 @@ class GlobalStoryLiveCollectionController extends LiveCollectionController {
|
|
|
26091
26426
|
const paginationController = new GlobalStoryPageController(query);
|
|
26092
26427
|
super(paginationController, queryStreamId, cacheKey, callback);
|
|
26093
26428
|
this.query = query;
|
|
26094
|
-
this.queryStreamController = new GlobalStoryQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), paginationController)
|
|
26429
|
+
this.queryStreamController = new GlobalStoryQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), paginationController, (data) => {
|
|
26430
|
+
const _a = prepareCommunityPayload(Object.assign(Object.assign({}, data), { feeds: [] })), rest = __rest(_a, ["feeds"]);
|
|
26431
|
+
return Object.assign(Object.assign({}, data), rest);
|
|
26432
|
+
});
|
|
26095
26433
|
this.paginationController = paginationController;
|
|
26096
26434
|
this.callback = callback.bind(this);
|
|
26097
26435
|
this.loadPage({ initial: true });
|