@amityco/ts-sdk 6.32.4 → 6.32.5-a934b24.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/@types/domains/user.d.ts +2 -0
- package/dist/@types/domains/user.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/@types/domains/user.ts +2 -0
- 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.esm.js
CHANGED
|
@@ -26229,6 +26229,18 @@ class QueryStreamController {
|
|
|
26229
26229
|
}
|
|
26230
26230
|
}
|
|
26231
26231
|
|
|
26232
|
+
var EnumFollowActions;
|
|
26233
|
+
(function (EnumFollowActions) {
|
|
26234
|
+
EnumFollowActions["OnRequested"] = "onRequested";
|
|
26235
|
+
EnumFollowActions["OnAccepted"] = "onAccepted";
|
|
26236
|
+
EnumFollowActions["OnDeclined"] = "onDeclined";
|
|
26237
|
+
EnumFollowActions["OnCanceled"] = "onCanceled";
|
|
26238
|
+
EnumFollowActions["OnFollowed"] = "onFollowed";
|
|
26239
|
+
EnumFollowActions["OnUnfollowed"] = "onUnfollowed";
|
|
26240
|
+
EnumFollowActions["OnDeleted"] = "onDeleted";
|
|
26241
|
+
EnumFollowActions["OnUserDeleted"] = "onUserDeleted";
|
|
26242
|
+
})(EnumFollowActions || (EnumFollowActions = {}));
|
|
26243
|
+
|
|
26232
26244
|
class BlockedUserQueryStreamController extends QueryStreamController {
|
|
26233
26245
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
26234
26246
|
super(query, cacheKey);
|
|
@@ -26257,10 +26269,13 @@ class BlockedUserQueryStreamController extends QueryStreamController {
|
|
|
26257
26269
|
}
|
|
26258
26270
|
}
|
|
26259
26271
|
reactor(action) {
|
|
26260
|
-
return (
|
|
26272
|
+
return (targetUser) => {
|
|
26261
26273
|
var _a;
|
|
26262
|
-
|
|
26263
|
-
|
|
26274
|
+
if (action === EnumFollowActions.OnFollowed) {
|
|
26275
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
26276
|
+
const updatedCollection = collection === null || collection === void 0 ? void 0 : collection.data.filter(id => id !== targetUser.userId);
|
|
26277
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: updatedCollection }));
|
|
26278
|
+
}
|
|
26264
26279
|
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
26265
26280
|
};
|
|
26266
26281
|
}
|
|
@@ -26457,560 +26472,593 @@ var EnumUserActions;
|
|
|
26457
26472
|
EnumUserActions["OnUserFlagCleared"] = "onUserFlagCleared";
|
|
26458
26473
|
})(EnumUserActions || (EnumUserActions = {}));
|
|
26459
26474
|
|
|
26460
|
-
|
|
26461
|
-
|
|
26462
|
-
|
|
26463
|
-
const
|
|
26464
|
-
|
|
26465
|
-
|
|
26466
|
-
this.query = query;
|
|
26467
|
-
this.queryStreamController = new BlockedUserQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareBlockedUserPayload);
|
|
26468
|
-
this.callback = callback.bind(this);
|
|
26469
|
-
this.loadPage({ initial: true });
|
|
26470
|
-
}
|
|
26471
|
-
setup() {
|
|
26472
|
-
var _a;
|
|
26473
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
26474
|
-
if (!collection) {
|
|
26475
|
-
pushToCache(this.cacheKey, {
|
|
26476
|
-
data: [],
|
|
26477
|
-
params: {},
|
|
26478
|
-
});
|
|
26475
|
+
const createFollowEventSubscriber = (event, callback) => {
|
|
26476
|
+
const client = getActiveClient();
|
|
26477
|
+
const filter = (data) => {
|
|
26478
|
+
const payload = prepareFollowersPayload(data);
|
|
26479
|
+
if (!client.cache) {
|
|
26480
|
+
callback(payload.follows[0]);
|
|
26479
26481
|
}
|
|
26480
|
-
|
|
26481
|
-
|
|
26482
|
-
|
|
26483
|
-
|
|
26484
|
-
|
|
26485
|
-
|
|
26486
|
-
|
|
26487
|
-
|
|
26488
|
-
|
|
26489
|
-
|
|
26490
|
-
|
|
26491
|
-
|
|
26492
|
-
|
|
26493
|
-
|
|
26494
|
-
|
|
26495
|
-
|
|
26496
|
-
|
|
26497
|
-
|
|
26498
|
-
|
|
26499
|
-
|
|
26500
|
-
|
|
26501
|
-
.map(id => pullFromCache(['user', 'get', id]))
|
|
26502
|
-
.filter(isNonNullable)
|
|
26503
|
-
.map(({ data }) => data)
|
|
26504
|
-
.map(LinkedObject.user)) !== null && _b !== void 0 ? _b : []);
|
|
26505
|
-
if (!this.shouldNotify(data) && origin === 'event')
|
|
26506
|
-
return;
|
|
26507
|
-
this.callback({
|
|
26508
|
-
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
26509
|
-
data,
|
|
26510
|
-
hasNextPage: !!this.paginationController.getNextToken(),
|
|
26511
|
-
loading,
|
|
26512
|
-
error,
|
|
26513
|
-
});
|
|
26514
|
-
}
|
|
26515
|
-
// eslint-disable-next-line class-methods-use-this
|
|
26516
|
-
applyFilter(data) {
|
|
26517
|
-
let users = data;
|
|
26518
|
-
users = users.filter(user => user.isDeleted == null || user.isDeleted === false);
|
|
26519
|
-
return users;
|
|
26520
|
-
}
|
|
26521
|
-
}
|
|
26482
|
+
else {
|
|
26483
|
+
ingestInCache(payload);
|
|
26484
|
+
callback(payload.follows[0]);
|
|
26485
|
+
}
|
|
26486
|
+
};
|
|
26487
|
+
return createEventSubscriber(client, event, event, filter);
|
|
26488
|
+
};
|
|
26489
|
+
const createLocalFollowEventSubscriber = (event, callback) => {
|
|
26490
|
+
const client = getActiveClient();
|
|
26491
|
+
const filter = (data) => {
|
|
26492
|
+
const payload = prepareFollowStatusPayload(data);
|
|
26493
|
+
if (!client.cache) {
|
|
26494
|
+
callback(payload.follows[0]);
|
|
26495
|
+
}
|
|
26496
|
+
else {
|
|
26497
|
+
ingestInCache(payload);
|
|
26498
|
+
callback(payload.follows[0]);
|
|
26499
|
+
}
|
|
26500
|
+
};
|
|
26501
|
+
return createEventSubscriber(client, event, event, filter);
|
|
26502
|
+
};
|
|
26522
26503
|
|
|
26523
|
-
/* begin_public_function
|
|
26524
|
-
id: user.get_blocked_users
|
|
26525
|
-
*/
|
|
26526
26504
|
/**
|
|
26527
26505
|
* ```js
|
|
26528
|
-
* import {
|
|
26529
|
-
* const
|
|
26506
|
+
* import { onUserFollowed } from '@amityco/ts-sdk'
|
|
26507
|
+
* const dispose = onUserFollowed(status => {
|
|
26508
|
+
* // ...
|
|
26509
|
+
* })
|
|
26530
26510
|
* ```
|
|
26531
26511
|
*
|
|
26532
|
-
*
|
|
26512
|
+
* Fired when a user follows another users and confirmation is not required
|
|
26533
26513
|
*
|
|
26534
|
-
* @param
|
|
26535
|
-
* @
|
|
26536
|
-
* @returns {@link Amity.Unsubscriber} to unsubscribe from collection
|
|
26514
|
+
* @param callback The function to call when the event was fired
|
|
26515
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26537
26516
|
*
|
|
26538
|
-
* @category
|
|
26539
|
-
* @async
|
|
26517
|
+
* @category Follow Events
|
|
26540
26518
|
*/
|
|
26541
|
-
const
|
|
26542
|
-
const { log, cache } = getActiveClient();
|
|
26543
|
-
if (!cache) {
|
|
26544
|
-
console.log(ENABLE_CACHE_MESSAGE);
|
|
26545
|
-
}
|
|
26546
|
-
const timestamp = Date.now();
|
|
26547
|
-
log(`getBlockedUsers(tmpid: ${timestamp}) > listen`);
|
|
26548
|
-
const blockedUserLiveCollection = new BlockedUserLiveCollectionController(params, callback);
|
|
26549
|
-
const disposers = blockedUserLiveCollection.startSubscription();
|
|
26550
|
-
const cacheKey = blockedUserLiveCollection.getCacheKey();
|
|
26551
|
-
disposers.push(() => dropFromCache(cacheKey));
|
|
26552
|
-
return () => {
|
|
26553
|
-
log(`getBlockedUsers(tmpid: ${timestamp}) > dispose`);
|
|
26554
|
-
disposers.forEach(fn => fn());
|
|
26555
|
-
dropFromCache(cacheKey);
|
|
26556
|
-
};
|
|
26557
|
-
};
|
|
26558
|
-
/* end_public_function */
|
|
26559
|
-
|
|
26560
|
-
/* eslint-disable no-use-before-define */
|
|
26561
|
-
const getBlockedUsers = (params, callback, config) => {
|
|
26562
|
-
console.log('Deprecation Notice: UserRepository.Relationship.getBlockedUsers will be deprecated on 9th June 2023, please use UserRepository.getBlockedUsers instead.');
|
|
26563
|
-
return getBlockedUsers$1(params, callback);
|
|
26564
|
-
};
|
|
26519
|
+
const onUserFollowed = (callback) => createFollowEventSubscriber('follow.created', callback);
|
|
26565
26520
|
|
|
26566
|
-
/* begin_public_function
|
|
26567
|
-
id: user.relationship.follow
|
|
26568
|
-
*/
|
|
26569
26521
|
/**
|
|
26570
26522
|
* ```js
|
|
26571
|
-
* import {
|
|
26572
|
-
* const
|
|
26523
|
+
* import { onUserUnfollowed } from '@amityco/ts-sdk'
|
|
26524
|
+
* const dispose = onUserFollowed(status => {
|
|
26525
|
+
* // ...
|
|
26526
|
+
* })
|
|
26573
26527
|
* ```
|
|
26574
26528
|
*
|
|
26575
|
-
*
|
|
26529
|
+
* Fired when a user unfollows
|
|
26576
26530
|
*
|
|
26577
|
-
* @param
|
|
26578
|
-
* @returns
|
|
26531
|
+
* @param callback The function to call when the event was fired
|
|
26532
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26579
26533
|
*
|
|
26580
|
-
* @category Follow
|
|
26581
|
-
* @async
|
|
26534
|
+
* @category Follow Events
|
|
26582
26535
|
*/
|
|
26583
|
-
const
|
|
26584
|
-
const client = getActiveClient();
|
|
26585
|
-
client.log('follow/follow', userId);
|
|
26586
|
-
const { data } = await client.http.post(`/api/v4/me/following/${userId}`);
|
|
26587
|
-
const cachedAt = client.cache && Date.now();
|
|
26588
|
-
if (client.cache) {
|
|
26589
|
-
ingestInCache(data, { cachedAt });
|
|
26590
|
-
}
|
|
26591
|
-
const payload = prepareFollowStatusPayload(data);
|
|
26592
|
-
if (data.follows[0].status === 'accepted') {
|
|
26593
|
-
fireEvent('local.follow.created', payload);
|
|
26594
|
-
}
|
|
26595
|
-
else {
|
|
26596
|
-
fireEvent('local.follow.requested', payload);
|
|
26597
|
-
}
|
|
26598
|
-
return {
|
|
26599
|
-
data: data.follows[0],
|
|
26600
|
-
cachedAt,
|
|
26601
|
-
};
|
|
26602
|
-
};
|
|
26603
|
-
/* end_public_function */
|
|
26536
|
+
const onUserUnfollowed = (callback) => createFollowEventSubscriber('follow.unfollowed', callback);
|
|
26604
26537
|
|
|
26605
|
-
/* begin_public_function
|
|
26606
|
-
id: user.relationship.unfollow
|
|
26607
|
-
*/
|
|
26608
26538
|
/**
|
|
26609
26539
|
* ```js
|
|
26610
|
-
* import {
|
|
26611
|
-
*
|
|
26540
|
+
* import { onFollowerDeleted } from '@amityco/ts-sdk'
|
|
26541
|
+
* const dispose = onFollowerDeleted(status => {
|
|
26542
|
+
* // ...
|
|
26543
|
+
* })
|
|
26612
26544
|
* ```
|
|
26613
26545
|
*
|
|
26614
|
-
*
|
|
26546
|
+
* Fired when a follower has been deleted
|
|
26615
26547
|
*
|
|
26616
|
-
* @param
|
|
26617
|
-
* @returns
|
|
26548
|
+
* @param callback The function to call when the event was fired
|
|
26549
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26618
26550
|
*
|
|
26619
|
-
* @category Follow
|
|
26620
|
-
* @async
|
|
26551
|
+
* @category Follow Events
|
|
26621
26552
|
*/
|
|
26622
|
-
const
|
|
26623
|
-
const client = getActiveClient();
|
|
26624
|
-
client.log('follow/unfollow', userId);
|
|
26625
|
-
const { data } = await client.http.delete(`/api/v4/me/following/${userId}`);
|
|
26626
|
-
if (client.cache) {
|
|
26627
|
-
ingestInCache(data);
|
|
26628
|
-
}
|
|
26629
|
-
const payload = prepareFollowStatusPayload(data);
|
|
26630
|
-
fireEvent('local.follow.unfollowed', payload);
|
|
26631
|
-
return true;
|
|
26632
|
-
};
|
|
26633
|
-
/* end_public_function */
|
|
26553
|
+
const onFollowerDeleted = (callback) => createFollowEventSubscriber('follow.followerDeleted', callback);
|
|
26634
26554
|
|
|
26635
26555
|
/**
|
|
26636
|
-
* @deprecated This API renamed to `acceptMyFollower`.
|
|
26637
|
-
* Please use acceptMyFollower() instead.
|
|
26638
|
-
*
|
|
26639
26556
|
* ```js
|
|
26640
|
-
* import {
|
|
26641
|
-
*
|
|
26557
|
+
* import { onFollowerRequested } from '@amityco/ts-sdk'
|
|
26558
|
+
* const dispose = onFollowerRequested(status => {
|
|
26559
|
+
* // ...
|
|
26560
|
+
* })
|
|
26642
26561
|
* ```
|
|
26643
26562
|
*
|
|
26644
|
-
*
|
|
26563
|
+
* Fired when a user follows another users and confirmation is required
|
|
26645
26564
|
*
|
|
26646
|
-
* @param
|
|
26647
|
-
* @returns
|
|
26565
|
+
* @param callback The function to call when the event was fired
|
|
26566
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26648
26567
|
*
|
|
26649
|
-
* @category Follow
|
|
26650
|
-
* @async
|
|
26568
|
+
* @category Follow Events
|
|
26651
26569
|
*/
|
|
26652
|
-
const
|
|
26653
|
-
const client = getActiveClient();
|
|
26654
|
-
client.log('follow/acceptFollower', userId);
|
|
26655
|
-
const { data } = await client.http.post(`/api/v4/me/followers/${userId}`);
|
|
26656
|
-
if (client.cache) {
|
|
26657
|
-
ingestInCache(data);
|
|
26658
|
-
}
|
|
26659
|
-
const payload = prepareFollowStatusPayload(data);
|
|
26660
|
-
fireEvent('local.follow.accepted', payload);
|
|
26661
|
-
return true;
|
|
26662
|
-
};
|
|
26570
|
+
const onFollowerRequested = (callback) => createFollowEventSubscriber('follow.requested', callback);
|
|
26663
26571
|
|
|
26664
|
-
/* begin_public_function
|
|
26665
|
-
id: user.relationship.accept_follow
|
|
26666
|
-
*/
|
|
26667
26572
|
/**
|
|
26668
26573
|
* ```js
|
|
26669
|
-
* import {
|
|
26670
|
-
*
|
|
26671
|
-
*
|
|
26574
|
+
* import { onFollowRequestCanceled } from '@amityco/ts-sdk'
|
|
26575
|
+
* const dispose = onFollowRequestCanceled(status => {
|
|
26576
|
+
* // ...
|
|
26577
|
+
* })
|
|
26578
|
+
* ```
|
|
26672
26579
|
*
|
|
26673
|
-
*
|
|
26580
|
+
* Fired when a follow request has been canceled
|
|
26674
26581
|
*
|
|
26675
|
-
* @param
|
|
26676
|
-
* @returns
|
|
26582
|
+
* @param callback The function to call when the event was fired
|
|
26583
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26677
26584
|
*
|
|
26678
|
-
* @category Follow
|
|
26679
|
-
* @async
|
|
26585
|
+
* @category Follow Events
|
|
26680
26586
|
*/
|
|
26681
|
-
const
|
|
26682
|
-
const client = getActiveClient();
|
|
26683
|
-
client.log('follow/acceptMyFollower', userId);
|
|
26684
|
-
const { data } = await client.http.post(`/api/v4/me/followers/${userId}`);
|
|
26685
|
-
if (client.cache) {
|
|
26686
|
-
ingestInCache(data);
|
|
26687
|
-
}
|
|
26688
|
-
const payload = prepareFollowStatusPayload(data);
|
|
26689
|
-
fireEvent('local.follow.accepted', payload);
|
|
26690
|
-
return true;
|
|
26691
|
-
};
|
|
26692
|
-
/* end_public_function */
|
|
26587
|
+
const onFollowRequestCanceled = (callback) => createFollowEventSubscriber('follow.requestCanceled', callback);
|
|
26693
26588
|
|
|
26694
26589
|
/**
|
|
26695
|
-
*
|
|
26696
|
-
*
|
|
26590
|
+
* ```js
|
|
26591
|
+
* import { onFollowRequestAccepted } from '@amityco/ts-sdk'
|
|
26592
|
+
* const dispose = onFollowRequestAccepted(status => {
|
|
26593
|
+
* // ...
|
|
26594
|
+
* })
|
|
26595
|
+
* ```
|
|
26596
|
+
*
|
|
26597
|
+
* Fired when a follow request has been accepted
|
|
26598
|
+
*
|
|
26599
|
+
* @param callback The function to call when the event was fired
|
|
26600
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26697
26601
|
*
|
|
26602
|
+
* @category Follow Events
|
|
26603
|
+
*/
|
|
26604
|
+
const onFollowRequestAccepted = (callback) => createFollowEventSubscriber('follow.accepted', callback);
|
|
26605
|
+
|
|
26606
|
+
/**
|
|
26698
26607
|
* ```js
|
|
26699
|
-
* import {
|
|
26700
|
-
*
|
|
26608
|
+
* import { onFollowRequestDeclined } from '@amityco/ts-sdk'
|
|
26609
|
+
* const dispose = onFollowRequestDeclined(status => {
|
|
26610
|
+
* // ...
|
|
26611
|
+
* })
|
|
26701
26612
|
* ```
|
|
26702
26613
|
*
|
|
26703
|
-
*
|
|
26614
|
+
* Fired when a follow request has been declined
|
|
26704
26615
|
*
|
|
26705
|
-
* @param
|
|
26706
|
-
* @returns
|
|
26616
|
+
* @param callback The function to call when the event was fired
|
|
26617
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26707
26618
|
*
|
|
26708
|
-
* @category Follow
|
|
26709
|
-
* @async
|
|
26619
|
+
* @category Follow Events
|
|
26710
26620
|
*/
|
|
26711
|
-
const
|
|
26712
|
-
const client = getActiveClient();
|
|
26713
|
-
client.log('follow/declineFollower', userId);
|
|
26714
|
-
const { data } = await client.http.delete(`/api/v4/me/followers/${userId}`);
|
|
26715
|
-
if (client.cache) {
|
|
26716
|
-
ingestInCache(data);
|
|
26717
|
-
}
|
|
26718
|
-
const payload = prepareFollowStatusPayload(data);
|
|
26719
|
-
fireEvent('local.follow.requestDeclined', payload);
|
|
26720
|
-
return true;
|
|
26721
|
-
};
|
|
26621
|
+
const onFollowRequestDeclined = (callback) => createFollowEventSubscriber('follow.requestDeclined', callback);
|
|
26722
26622
|
|
|
26723
|
-
/* begin_public_function
|
|
26724
|
-
id: user.relationship.decline_follow
|
|
26725
|
-
*/
|
|
26726
26623
|
/**
|
|
26727
26624
|
* ```js
|
|
26728
|
-
* import {
|
|
26729
|
-
* await
|
|
26625
|
+
* import { getFollowInfo } from '@amityco/ts-sdk'
|
|
26626
|
+
* const { data: followInfo } = await getFollowInfo('foobar')
|
|
26730
26627
|
* ```
|
|
26731
26628
|
*
|
|
26732
|
-
*
|
|
26629
|
+
* Fetches the number of followers, followings, pending requests and the follow status for current user
|
|
26733
26630
|
*
|
|
26734
|
-
* @param userId the ID of the {@link Amity.InternalUser}
|
|
26735
|
-
* @returns
|
|
26631
|
+
* @param userId the ID of the {@link Amity.InternalUser}
|
|
26632
|
+
* @returns the associated {@link Amity.FollowInfo} object
|
|
26736
26633
|
*
|
|
26737
26634
|
* @category Follow API
|
|
26738
26635
|
* @async
|
|
26739
26636
|
*/
|
|
26740
|
-
const
|
|
26637
|
+
const getFollowInfo$1 = async (userId) => {
|
|
26638
|
+
var _a, _b;
|
|
26741
26639
|
const client = getActiveClient();
|
|
26742
|
-
client.log('follow/
|
|
26743
|
-
const { data } = await client.http.
|
|
26640
|
+
client.log('follow/getFollowInfo', userId);
|
|
26641
|
+
const { data } = await client.http.get(client.userId === userId ? `/api/v4/me/followInfo` : `/api/v5/users/${userId}/followInfo`);
|
|
26642
|
+
const cachedAt = client.cache && Date.now();
|
|
26643
|
+
const followInfo = 'follows' in data
|
|
26644
|
+
? 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];
|
|
26744
26645
|
if (client.cache) {
|
|
26745
|
-
|
|
26646
|
+
pushToCache(['followInfo', 'get', userId], followInfo, {
|
|
26647
|
+
cachedAt,
|
|
26648
|
+
});
|
|
26746
26649
|
}
|
|
26747
|
-
|
|
26748
|
-
|
|
26749
|
-
|
|
26750
|
-
};
|
|
26751
|
-
/* end_public_function */
|
|
26752
|
-
|
|
26753
|
-
const createFollowEventSubscriber = (event, callback) => {
|
|
26754
|
-
const client = getActiveClient();
|
|
26755
|
-
const filter = (data) => {
|
|
26756
|
-
const payload = prepareFollowersPayload(data);
|
|
26757
|
-
if (!client.cache) {
|
|
26758
|
-
callback(payload.follows[0]);
|
|
26759
|
-
}
|
|
26760
|
-
else {
|
|
26761
|
-
ingestInCache(payload);
|
|
26762
|
-
callback(payload.follows[0]);
|
|
26763
|
-
}
|
|
26650
|
+
return {
|
|
26651
|
+
data: followInfo,
|
|
26652
|
+
cachedAt,
|
|
26764
26653
|
};
|
|
26765
|
-
return createEventSubscriber(client, event, event, filter);
|
|
26766
26654
|
};
|
|
26767
|
-
const createLocalFollowEventSubscriber = (event, callback) => {
|
|
26768
|
-
const client = getActiveClient();
|
|
26769
|
-
const filter = (data) => {
|
|
26770
|
-
const payload = prepareFollowStatusPayload(data);
|
|
26771
|
-
if (!client.cache) {
|
|
26772
|
-
callback(payload.follows[0]);
|
|
26773
|
-
}
|
|
26774
|
-
else {
|
|
26775
|
-
ingestInCache(payload);
|
|
26776
|
-
callback(payload.follows[0]);
|
|
26777
|
-
}
|
|
26778
|
-
};
|
|
26779
|
-
return createEventSubscriber(client, event, event, filter);
|
|
26780
|
-
};
|
|
26781
|
-
|
|
26782
26655
|
/**
|
|
26783
26656
|
* ```js
|
|
26784
|
-
* import {
|
|
26785
|
-
* const
|
|
26786
|
-
* // ...
|
|
26787
|
-
* })
|
|
26657
|
+
* import { getFollowInfo } from '@amityco/ts-sdk'
|
|
26658
|
+
* const { data: followInfo } = getFollowInfo.locally('foobar')
|
|
26788
26659
|
* ```
|
|
26789
26660
|
*
|
|
26790
|
-
*
|
|
26661
|
+
* Fetches the number of followers, followings, pending requests and the follow status for current user from cache
|
|
26791
26662
|
*
|
|
26792
|
-
* @param
|
|
26793
|
-
* @returns
|
|
26663
|
+
* @param userId the ID of the {@link Amity.InternalUser}
|
|
26664
|
+
* @returns the associated {@link Amity.FollowInfo} object
|
|
26794
26665
|
*
|
|
26795
|
-
* @category Follow
|
|
26666
|
+
* @category Follow API
|
|
26796
26667
|
*/
|
|
26797
|
-
|
|
26668
|
+
getFollowInfo$1.locally = (userId) => {
|
|
26669
|
+
const client = getActiveClient();
|
|
26670
|
+
client.log('follow/getFollowInfo.locally', userId);
|
|
26671
|
+
if (!client.cache) {
|
|
26672
|
+
return;
|
|
26673
|
+
}
|
|
26674
|
+
const cached = pullFromCache(['followInfo', 'get', userId]);
|
|
26675
|
+
if (!cached) {
|
|
26676
|
+
return;
|
|
26677
|
+
}
|
|
26678
|
+
return {
|
|
26679
|
+
data: cached.data,
|
|
26680
|
+
cachedAt: cached.cachedAt,
|
|
26681
|
+
};
|
|
26682
|
+
};
|
|
26798
26683
|
|
|
26799
26684
|
/**
|
|
26800
26685
|
* ```js
|
|
26801
|
-
* import {
|
|
26802
|
-
* const dispose =
|
|
26686
|
+
* import { onFollowInfoUpdated } from '@amityco/ts-sdk'
|
|
26687
|
+
* const dispose = onFollowInfoUpdated(followInfo => {
|
|
26803
26688
|
* // ...
|
|
26804
26689
|
* })
|
|
26805
26690
|
* ```
|
|
26806
26691
|
*
|
|
26807
|
-
* Fired when a
|
|
26692
|
+
* Fired when a {@link Amity.FollowInfo} has been updated
|
|
26808
26693
|
*
|
|
26809
26694
|
* @param callback The function to call when the event was fired
|
|
26810
26695
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26811
26696
|
*
|
|
26812
26697
|
* @category Follow Events
|
|
26813
26698
|
*/
|
|
26814
|
-
const
|
|
26699
|
+
const onFollowInfoUpdated = (callback) => {
|
|
26700
|
+
const handler = async (payload) => {
|
|
26701
|
+
const [{ data: followInfoFrom }, { data: followInfoTo }] = await Promise.all([
|
|
26702
|
+
getFollowInfo$1(payload.from),
|
|
26703
|
+
getFollowInfo$1(payload.to),
|
|
26704
|
+
]);
|
|
26705
|
+
callback(followInfoFrom);
|
|
26706
|
+
callback(followInfoTo);
|
|
26707
|
+
};
|
|
26708
|
+
const disposers = [
|
|
26709
|
+
createFollowEventSubscriber('follow.created', handler),
|
|
26710
|
+
createFollowEventSubscriber('follow.requested', handler),
|
|
26711
|
+
createFollowEventSubscriber('follow.accepted', handler),
|
|
26712
|
+
createFollowEventSubscriber('follow.unfollowed', handler),
|
|
26713
|
+
createFollowEventSubscriber('follow.requestCanceled', handler),
|
|
26714
|
+
createFollowEventSubscriber('follow.requestDeclined', handler),
|
|
26715
|
+
createFollowEventSubscriber('follow.followerDeleted', handler),
|
|
26716
|
+
createLocalFollowEventSubscriber('local.follow.created', handler),
|
|
26717
|
+
createLocalFollowEventSubscriber('local.follow.requested', handler),
|
|
26718
|
+
createLocalFollowEventSubscriber('local.follow.accepted', handler),
|
|
26719
|
+
createLocalFollowEventSubscriber('local.follow.unfollowed', handler),
|
|
26720
|
+
createLocalFollowEventSubscriber('local.follow.requestDeclined', handler),
|
|
26721
|
+
];
|
|
26722
|
+
return () => {
|
|
26723
|
+
disposers.forEach(fn => fn());
|
|
26724
|
+
};
|
|
26725
|
+
};
|
|
26815
26726
|
|
|
26816
|
-
|
|
26817
|
-
|
|
26818
|
-
|
|
26819
|
-
|
|
26820
|
-
|
|
26821
|
-
|
|
26822
|
-
|
|
26823
|
-
|
|
26824
|
-
|
|
26825
|
-
|
|
26826
|
-
|
|
26827
|
-
|
|
26828
|
-
|
|
26829
|
-
|
|
26830
|
-
|
|
26831
|
-
const
|
|
26727
|
+
const onLocalUserFollowed = (callback) => createLocalFollowEventSubscriber('local.follow.created', callback);
|
|
26728
|
+
|
|
26729
|
+
const onLocalUserUnfollowed = (callback) => createLocalFollowEventSubscriber('local.follow.unfollowed', callback);
|
|
26730
|
+
|
|
26731
|
+
const onLocalFollowerRequested = (callback) => createLocalFollowEventSubscriber('local.follow.requested', callback);
|
|
26732
|
+
|
|
26733
|
+
const onLocalFollowRequestAccepted = (callback) => createLocalFollowEventSubscriber('local.follow.accepted', callback);
|
|
26734
|
+
|
|
26735
|
+
const onLocalFollowRequestDeclined = (callback) => createLocalFollowEventSubscriber('local.follow.requestDeclined', callback);
|
|
26736
|
+
|
|
26737
|
+
const convertEventPayload = (eventHandler, sourceModelProp, destinationDomain) => (callback) => eventHandler(sourceModel => {
|
|
26738
|
+
var _a, _b;
|
|
26739
|
+
if (!sourceModel) {
|
|
26740
|
+
return sourceModel;
|
|
26741
|
+
}
|
|
26742
|
+
const client = getActiveClient();
|
|
26743
|
+
const { objectSyncMap } = client;
|
|
26744
|
+
/*
|
|
26745
|
+
* 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.
|
|
26746
|
+
* 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.
|
|
26747
|
+
*/
|
|
26748
|
+
const resolvedId = isLocalId(sourceModel[sourceModelProp])
|
|
26749
|
+
? sourceModel[sourceModelProp]
|
|
26750
|
+
: (_a = objectSyncMap.get(sourceModel[sourceModelProp])) !== null && _a !== void 0 ? _a : sourceModel[sourceModelProp];
|
|
26751
|
+
const model = (_b = pullFromCache([
|
|
26752
|
+
destinationDomain,
|
|
26753
|
+
'get',
|
|
26754
|
+
`${resolvedId}`,
|
|
26755
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
26756
|
+
if (!model)
|
|
26757
|
+
return;
|
|
26758
|
+
return callback(model);
|
|
26759
|
+
});
|
|
26760
|
+
|
|
26761
|
+
class BlockedUserLiveCollectionController extends LiveCollectionController {
|
|
26762
|
+
constructor(query, callback) {
|
|
26763
|
+
const queryStreamId = hash(query);
|
|
26764
|
+
const cacheKey = ['blockedUsers', 'collection', queryStreamId];
|
|
26765
|
+
const paginationController = new BlockedUserPaginationController(query);
|
|
26766
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
26767
|
+
this.query = query;
|
|
26768
|
+
this.queryStreamController = new BlockedUserQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareBlockedUserPayload);
|
|
26769
|
+
this.callback = callback.bind(this);
|
|
26770
|
+
this.loadPage({ initial: true });
|
|
26771
|
+
}
|
|
26772
|
+
setup() {
|
|
26773
|
+
var _a;
|
|
26774
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
26775
|
+
if (!collection) {
|
|
26776
|
+
pushToCache(this.cacheKey, {
|
|
26777
|
+
data: [],
|
|
26778
|
+
params: {},
|
|
26779
|
+
});
|
|
26780
|
+
}
|
|
26781
|
+
}
|
|
26782
|
+
async persistModel(queryPayload) {
|
|
26783
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
26784
|
+
}
|
|
26785
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
26786
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
26787
|
+
}
|
|
26788
|
+
startSubscription() {
|
|
26789
|
+
return this.queryStreamController.subscribeRTE([
|
|
26790
|
+
{
|
|
26791
|
+
fn: onUserDeleted$2,
|
|
26792
|
+
action: EnumUserActions.OnUserDeleted,
|
|
26793
|
+
},
|
|
26794
|
+
// In the case of unblocking a user, we need to subscribe to the follow events
|
|
26795
|
+
{
|
|
26796
|
+
fn: convertEventPayload(onLocalUserFollowed, 'to', 'user'),
|
|
26797
|
+
action: EnumFollowActions.OnFollowed,
|
|
26798
|
+
},
|
|
26799
|
+
{
|
|
26800
|
+
fn: convertEventPayload(onUserFollowed, 'to', 'user'),
|
|
26801
|
+
action: EnumFollowActions.OnFollowed,
|
|
26802
|
+
},
|
|
26803
|
+
]);
|
|
26804
|
+
}
|
|
26805
|
+
notifyChange({ origin, loading, error }) {
|
|
26806
|
+
var _a, _b;
|
|
26807
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
26808
|
+
if (!collection)
|
|
26809
|
+
return;
|
|
26810
|
+
const data = this.applyFilter((_b = collection.data
|
|
26811
|
+
.map(id => pullFromCache(['user', 'get', id]))
|
|
26812
|
+
.filter(isNonNullable)
|
|
26813
|
+
.map(({ data }) => data)
|
|
26814
|
+
.map(LinkedObject.user)) !== null && _b !== void 0 ? _b : []);
|
|
26815
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
26816
|
+
return;
|
|
26817
|
+
this.callback({
|
|
26818
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
26819
|
+
data,
|
|
26820
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
26821
|
+
loading,
|
|
26822
|
+
error,
|
|
26823
|
+
});
|
|
26824
|
+
}
|
|
26825
|
+
// eslint-disable-next-line class-methods-use-this
|
|
26826
|
+
applyFilter(data) {
|
|
26827
|
+
let users = data;
|
|
26828
|
+
users = users.filter(user => user.isDeleted == null || user.isDeleted === false);
|
|
26829
|
+
return users;
|
|
26830
|
+
}
|
|
26831
|
+
}
|
|
26832
26832
|
|
|
26833
|
+
/* begin_public_function
|
|
26834
|
+
id: user.get_blocked_users
|
|
26835
|
+
*/
|
|
26833
26836
|
/**
|
|
26834
26837
|
* ```js
|
|
26835
|
-
* import {
|
|
26836
|
-
* const
|
|
26837
|
-
* // ...
|
|
26838
|
-
* })
|
|
26838
|
+
* import { UserRepository } from '@amityco/ts-sdk'
|
|
26839
|
+
* const unblockedUser = await UserRepository.blockUser('userId')
|
|
26839
26840
|
* ```
|
|
26840
26841
|
*
|
|
26841
|
-
*
|
|
26842
|
+
* Blocks a {@link Amity.InternalUser}
|
|
26842
26843
|
*
|
|
26843
|
-
* @param
|
|
26844
|
-
* @
|
|
26844
|
+
* @param params The params to get blocked {@link Amity.InternalUser}s
|
|
26845
|
+
* @param callback to recieve updates on unblocked {@link Amity.InternalUser}s
|
|
26846
|
+
* @returns {@link Amity.Unsubscriber} to unsubscribe from collection
|
|
26845
26847
|
*
|
|
26846
|
-
* @category
|
|
26848
|
+
* @category Post API
|
|
26849
|
+
* @async
|
|
26847
26850
|
*/
|
|
26848
|
-
const
|
|
26851
|
+
const getBlockedUsers$1 = (params, callback, config) => {
|
|
26852
|
+
const { log, cache } = getActiveClient();
|
|
26853
|
+
if (!cache) {
|
|
26854
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
26855
|
+
}
|
|
26856
|
+
const timestamp = Date.now();
|
|
26857
|
+
log(`getBlockedUsers(tmpid: ${timestamp}) > listen`);
|
|
26858
|
+
const blockedUserLiveCollection = new BlockedUserLiveCollectionController(params, callback);
|
|
26859
|
+
const disposers = blockedUserLiveCollection.startSubscription();
|
|
26860
|
+
const cacheKey = blockedUserLiveCollection.getCacheKey();
|
|
26861
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
26862
|
+
return () => {
|
|
26863
|
+
log(`getBlockedUsers(tmpid: ${timestamp}) > dispose`);
|
|
26864
|
+
disposers.forEach(fn => fn());
|
|
26865
|
+
dropFromCache(cacheKey);
|
|
26866
|
+
};
|
|
26867
|
+
};
|
|
26868
|
+
/* end_public_function */
|
|
26869
|
+
|
|
26870
|
+
/* eslint-disable no-use-before-define */
|
|
26871
|
+
const getBlockedUsers = (params, callback, config) => {
|
|
26872
|
+
console.log('Deprecation Notice: UserRepository.Relationship.getBlockedUsers will be deprecated on 9th June 2023, please use UserRepository.getBlockedUsers instead.');
|
|
26873
|
+
return getBlockedUsers$1(params, callback);
|
|
26874
|
+
};
|
|
26849
26875
|
|
|
26876
|
+
/* begin_public_function
|
|
26877
|
+
id: user.relationship.follow
|
|
26878
|
+
*/
|
|
26850
26879
|
/**
|
|
26851
26880
|
* ```js
|
|
26852
|
-
* import {
|
|
26853
|
-
* const
|
|
26854
|
-
* // ...
|
|
26855
|
-
* })
|
|
26881
|
+
* import { follow } from '@amityco/ts-sdk'
|
|
26882
|
+
* const status = await follow('foobar')
|
|
26856
26883
|
* ```
|
|
26857
26884
|
*
|
|
26858
|
-
*
|
|
26885
|
+
* Follow the user
|
|
26859
26886
|
*
|
|
26860
|
-
* @param
|
|
26861
|
-
* @returns
|
|
26887
|
+
* @param userId the ID of the {@link Amity.InternalUser}
|
|
26888
|
+
* @returns the status {@link Amity.FollowStatus}
|
|
26862
26889
|
*
|
|
26863
|
-
* @category Follow
|
|
26890
|
+
* @category Follow API
|
|
26891
|
+
* @async
|
|
26864
26892
|
*/
|
|
26865
|
-
const
|
|
26893
|
+
const follow = async (userId) => {
|
|
26894
|
+
const client = getActiveClient();
|
|
26895
|
+
client.log('follow/follow', userId);
|
|
26896
|
+
const { data } = await client.http.post(`/api/v4/me/following/${userId}`);
|
|
26897
|
+
const cachedAt = client.cache && Date.now();
|
|
26898
|
+
if (client.cache) {
|
|
26899
|
+
ingestInCache(data, { cachedAt });
|
|
26900
|
+
}
|
|
26901
|
+
const payload = prepareFollowStatusPayload(data);
|
|
26902
|
+
if (data.follows[0].status === 'accepted') {
|
|
26903
|
+
fireEvent('local.follow.created', payload);
|
|
26904
|
+
}
|
|
26905
|
+
else {
|
|
26906
|
+
fireEvent('local.follow.requested', payload);
|
|
26907
|
+
}
|
|
26908
|
+
return {
|
|
26909
|
+
data: data.follows[0],
|
|
26910
|
+
cachedAt,
|
|
26911
|
+
};
|
|
26912
|
+
};
|
|
26913
|
+
/* end_public_function */
|
|
26866
26914
|
|
|
26915
|
+
/* begin_public_function
|
|
26916
|
+
id: user.relationship.unfollow
|
|
26917
|
+
*/
|
|
26867
26918
|
/**
|
|
26868
26919
|
* ```js
|
|
26869
|
-
* import {
|
|
26870
|
-
*
|
|
26871
|
-
* // ...
|
|
26872
|
-
* })
|
|
26920
|
+
* import { unfollow } from '@amityco/ts-sdk'
|
|
26921
|
+
* await unfollow('foobar')
|
|
26873
26922
|
* ```
|
|
26874
26923
|
*
|
|
26875
|
-
*
|
|
26924
|
+
* Cancel the follow request or unfollow the user
|
|
26876
26925
|
*
|
|
26877
|
-
* @param
|
|
26878
|
-
* @returns
|
|
26926
|
+
* @param userId the ID of the {@link Amity.InternalUser}
|
|
26927
|
+
* @returns A success boolean if the user {@link Amity.InternalUser} was unfollowed
|
|
26879
26928
|
*
|
|
26880
|
-
* @category Follow
|
|
26929
|
+
* @category Follow API
|
|
26930
|
+
* @async
|
|
26881
26931
|
*/
|
|
26882
|
-
const
|
|
26932
|
+
const unfollow = async (userId) => {
|
|
26933
|
+
const client = getActiveClient();
|
|
26934
|
+
client.log('follow/unfollow', userId);
|
|
26935
|
+
const { data } = await client.http.delete(`/api/v4/me/following/${userId}`);
|
|
26936
|
+
if (client.cache) {
|
|
26937
|
+
ingestInCache(data);
|
|
26938
|
+
}
|
|
26939
|
+
const payload = prepareFollowStatusPayload(data);
|
|
26940
|
+
fireEvent('local.follow.unfollowed', payload);
|
|
26941
|
+
return true;
|
|
26942
|
+
};
|
|
26943
|
+
/* end_public_function */
|
|
26883
26944
|
|
|
26884
26945
|
/**
|
|
26946
|
+
* @deprecated This API renamed to `acceptMyFollower`.
|
|
26947
|
+
* Please use acceptMyFollower() instead.
|
|
26948
|
+
*
|
|
26885
26949
|
* ```js
|
|
26886
|
-
* import {
|
|
26887
|
-
*
|
|
26888
|
-
* // ...
|
|
26889
|
-
* })
|
|
26950
|
+
* import { acceptFollower } from '@amityco/ts-sdk'
|
|
26951
|
+
* await acceptFollower('foobar')
|
|
26890
26952
|
* ```
|
|
26891
26953
|
*
|
|
26892
|
-
*
|
|
26954
|
+
* Accept the follow request
|
|
26893
26955
|
*
|
|
26894
|
-
* @param
|
|
26895
|
-
* @returns
|
|
26956
|
+
* @param userId the ID of the {@link Amity.InternalUser} follower
|
|
26957
|
+
* @returns A success boolean if the follow request was accepted
|
|
26896
26958
|
*
|
|
26897
|
-
* @category Follow
|
|
26959
|
+
* @category Follow API
|
|
26960
|
+
* @async
|
|
26898
26961
|
*/
|
|
26899
|
-
const
|
|
26962
|
+
const acceptFollower = async (userId) => {
|
|
26963
|
+
const client = getActiveClient();
|
|
26964
|
+
client.log('follow/acceptFollower', userId);
|
|
26965
|
+
const { data } = await client.http.post(`/api/v4/me/followers/${userId}`);
|
|
26966
|
+
if (client.cache) {
|
|
26967
|
+
ingestInCache(data);
|
|
26968
|
+
}
|
|
26969
|
+
const payload = prepareFollowStatusPayload(data);
|
|
26970
|
+
fireEvent('local.follow.accepted', payload);
|
|
26971
|
+
return true;
|
|
26972
|
+
};
|
|
26900
26973
|
|
|
26974
|
+
/* begin_public_function
|
|
26975
|
+
id: user.relationship.accept_follow
|
|
26976
|
+
*/
|
|
26901
26977
|
/**
|
|
26902
26978
|
* ```js
|
|
26903
|
-
* import {
|
|
26904
|
-
*
|
|
26979
|
+
* import { UserRepository } from '@amityco/ts-sdk'
|
|
26980
|
+
* await UserRepository.Relationship.acceptMyFollower('foobar')
|
|
26905
26981
|
* ```
|
|
26906
26982
|
*
|
|
26907
|
-
*
|
|
26983
|
+
* Accept the follow request
|
|
26908
26984
|
*
|
|
26909
|
-
* @param userId the ID of the {@link Amity.InternalUser}
|
|
26910
|
-
* @returns the
|
|
26985
|
+
* @param userId the ID of the {@link Amity.InternalUser} follower
|
|
26986
|
+
* @returns A success boolean if the follow request was accepted
|
|
26911
26987
|
*
|
|
26912
26988
|
* @category Follow API
|
|
26913
26989
|
* @async
|
|
26914
26990
|
*/
|
|
26915
|
-
const
|
|
26916
|
-
var _a, _b;
|
|
26991
|
+
const acceptMyFollower = async (userId) => {
|
|
26917
26992
|
const client = getActiveClient();
|
|
26918
|
-
client.log('follow/
|
|
26919
|
-
const { data } = await client.http.
|
|
26920
|
-
const cachedAt = client.cache && Date.now();
|
|
26921
|
-
const followInfo = 'follows' in data
|
|
26922
|
-
? 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];
|
|
26993
|
+
client.log('follow/acceptMyFollower', userId);
|
|
26994
|
+
const { data } = await client.http.post(`/api/v4/me/followers/${userId}`);
|
|
26923
26995
|
if (client.cache) {
|
|
26924
|
-
|
|
26925
|
-
cachedAt,
|
|
26926
|
-
});
|
|
26996
|
+
ingestInCache(data);
|
|
26927
26997
|
}
|
|
26928
|
-
|
|
26929
|
-
|
|
26930
|
-
|
|
26931
|
-
};
|
|
26998
|
+
const payload = prepareFollowStatusPayload(data);
|
|
26999
|
+
fireEvent('local.follow.accepted', payload);
|
|
27000
|
+
return true;
|
|
26932
27001
|
};
|
|
27002
|
+
/* end_public_function */
|
|
27003
|
+
|
|
26933
27004
|
/**
|
|
27005
|
+
* @deprecated This API renamed to `declineMyFollower`.
|
|
27006
|
+
* Please use declineMyFollower() instead.
|
|
27007
|
+
*
|
|
26934
27008
|
* ```js
|
|
26935
|
-
* import {
|
|
26936
|
-
*
|
|
27009
|
+
* import { declineFollower } from '@amityco/ts-sdk'
|
|
27010
|
+
* await declineFollower('foobar')
|
|
26937
27011
|
* ```
|
|
26938
27012
|
*
|
|
26939
|
-
*
|
|
26940
|
-
*
|
|
26941
|
-
* @param userId the ID of the {@link Amity.InternalUser}
|
|
26942
|
-
* @returns the
|
|
27013
|
+
* Decline the follow request or delete the follower
|
|
27014
|
+
*
|
|
27015
|
+
* @param userId the ID of the {@link Amity.InternalUser} follower
|
|
27016
|
+
* @returns A success boolean if the follow request was decline
|
|
26943
27017
|
*
|
|
26944
27018
|
* @category Follow API
|
|
27019
|
+
* @async
|
|
26945
27020
|
*/
|
|
26946
|
-
|
|
27021
|
+
const declineFollower = async (userId) => {
|
|
26947
27022
|
const client = getActiveClient();
|
|
26948
|
-
client.log('follow/
|
|
26949
|
-
|
|
26950
|
-
|
|
26951
|
-
|
|
26952
|
-
const cached = pullFromCache(['followInfo', 'get', userId]);
|
|
26953
|
-
if (!cached) {
|
|
26954
|
-
return;
|
|
27023
|
+
client.log('follow/declineFollower', userId);
|
|
27024
|
+
const { data } = await client.http.delete(`/api/v4/me/followers/${userId}`);
|
|
27025
|
+
if (client.cache) {
|
|
27026
|
+
ingestInCache(data);
|
|
26955
27027
|
}
|
|
26956
|
-
|
|
26957
|
-
|
|
26958
|
-
|
|
26959
|
-
};
|
|
27028
|
+
const payload = prepareFollowStatusPayload(data);
|
|
27029
|
+
fireEvent('local.follow.requestDeclined', payload);
|
|
27030
|
+
return true;
|
|
26960
27031
|
};
|
|
26961
27032
|
|
|
27033
|
+
/* begin_public_function
|
|
27034
|
+
id: user.relationship.decline_follow
|
|
27035
|
+
*/
|
|
26962
27036
|
/**
|
|
26963
27037
|
* ```js
|
|
26964
|
-
* import {
|
|
26965
|
-
*
|
|
26966
|
-
* // ...
|
|
26967
|
-
* })
|
|
27038
|
+
* import { UserRepository } from '@amityco/ts-sdk'
|
|
27039
|
+
* await UserRepository.Relationship.declineMyFollower('foobar')
|
|
26968
27040
|
* ```
|
|
26969
27041
|
*
|
|
26970
|
-
*
|
|
27042
|
+
* Decline the follow request or delete the follower
|
|
26971
27043
|
*
|
|
26972
|
-
* @param
|
|
26973
|
-
* @returns
|
|
27044
|
+
* @param userId the ID of the {@link Amity.InternalUser} follower
|
|
27045
|
+
* @returns A success boolean if the follow request was decline
|
|
26974
27046
|
*
|
|
26975
|
-
* @category Follow
|
|
27047
|
+
* @category Follow API
|
|
27048
|
+
* @async
|
|
26976
27049
|
*/
|
|
26977
|
-
const
|
|
26978
|
-
const
|
|
26979
|
-
|
|
26980
|
-
|
|
26981
|
-
|
|
26982
|
-
|
|
26983
|
-
|
|
26984
|
-
|
|
26985
|
-
|
|
26986
|
-
|
|
26987
|
-
|
|
26988
|
-
|
|
26989
|
-
createFollowEventSubscriber('follow.accepted', handler),
|
|
26990
|
-
createFollowEventSubscriber('follow.unfollowed', handler),
|
|
26991
|
-
createFollowEventSubscriber('follow.requestCanceled', handler),
|
|
26992
|
-
createFollowEventSubscriber('follow.requestDeclined', handler),
|
|
26993
|
-
createFollowEventSubscriber('follow.followerDeleted', handler),
|
|
26994
|
-
createLocalFollowEventSubscriber('local.follow.created', handler),
|
|
26995
|
-
createLocalFollowEventSubscriber('local.follow.requested', handler),
|
|
26996
|
-
createLocalFollowEventSubscriber('local.follow.accepted', handler),
|
|
26997
|
-
createLocalFollowEventSubscriber('local.follow.unfollowed', handler),
|
|
26998
|
-
createLocalFollowEventSubscriber('local.follow.requestDeclined', handler),
|
|
26999
|
-
];
|
|
27000
|
-
return () => {
|
|
27001
|
-
disposers.forEach(fn => fn());
|
|
27002
|
-
};
|
|
27003
|
-
};
|
|
27004
|
-
|
|
27005
|
-
const onLocalUserFollowed = (callback) => createLocalFollowEventSubscriber('local.follow.created', callback);
|
|
27006
|
-
|
|
27007
|
-
const onLocalUserUnfollowed = (callback) => createLocalFollowEventSubscriber('local.follow.unfollowed', callback);
|
|
27008
|
-
|
|
27009
|
-
const onLocalFollowerRequested = (callback) => createLocalFollowEventSubscriber('local.follow.requested', callback);
|
|
27010
|
-
|
|
27011
|
-
const onLocalFollowRequestAccepted = (callback) => createLocalFollowEventSubscriber('local.follow.accepted', callback);
|
|
27012
|
-
|
|
27013
|
-
const onLocalFollowRequestDeclined = (callback) => createLocalFollowEventSubscriber('local.follow.requestDeclined', callback);
|
|
27050
|
+
const declineMyFollower = async (userId) => {
|
|
27051
|
+
const client = getActiveClient();
|
|
27052
|
+
client.log('follow/declineMyFollower', userId);
|
|
27053
|
+
const { data } = await client.http.delete(`/api/v4/me/followers/${userId}`);
|
|
27054
|
+
if (client.cache) {
|
|
27055
|
+
ingestInCache(data);
|
|
27056
|
+
}
|
|
27057
|
+
const payload = prepareFollowStatusPayload(data);
|
|
27058
|
+
fireEvent('local.follow.requestDeclined', payload);
|
|
27059
|
+
return true;
|
|
27060
|
+
};
|
|
27061
|
+
/* end_public_function */
|
|
27014
27062
|
|
|
27015
27063
|
/**
|
|
27016
27064
|
* ```js
|
|
@@ -27140,18 +27188,6 @@ class FollowerPaginationController extends PaginationController {
|
|
|
27140
27188
|
}
|
|
27141
27189
|
}
|
|
27142
27190
|
|
|
27143
|
-
var EnumFollowActions;
|
|
27144
|
-
(function (EnumFollowActions) {
|
|
27145
|
-
EnumFollowActions["OnRequested"] = "onRequested";
|
|
27146
|
-
EnumFollowActions["OnAccepted"] = "onAccepted";
|
|
27147
|
-
EnumFollowActions["OnDeclined"] = "onDeclined";
|
|
27148
|
-
EnumFollowActions["OnCanceled"] = "onCanceled";
|
|
27149
|
-
EnumFollowActions["OnFollowed"] = "onFollowed";
|
|
27150
|
-
EnumFollowActions["OnUnfollowed"] = "onUnfollowed";
|
|
27151
|
-
EnumFollowActions["OnDeleted"] = "onDeleted";
|
|
27152
|
-
EnumFollowActions["OnUserDeleted"] = "onUserDeleted";
|
|
27153
|
-
})(EnumFollowActions || (EnumFollowActions = {}));
|
|
27154
|
-
|
|
27155
27191
|
class FollowerQueryStreamController extends QueryStreamController {
|
|
27156
27192
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
27157
27193
|
super(query, cacheKey);
|
|
@@ -27229,7 +27265,7 @@ const onFollowerUserDeleted = ({ userId }) => (callback) => {
|
|
|
27229
27265
|
|
|
27230
27266
|
class FollowerLiveCollectionController extends LiveCollectionController {
|
|
27231
27267
|
constructor(query, callback) {
|
|
27232
|
-
const queryStreamId = hash(query);
|
|
27268
|
+
const queryStreamId = hash(Object.assign(Object.assign({}, query), { type: 'follower' }));
|
|
27233
27269
|
const cacheKey = ['follow', 'collection', queryStreamId];
|
|
27234
27270
|
const paginationController = new FollowerPaginationController(query);
|
|
27235
27271
|
super(paginationController, queryStreamId, cacheKey, callback);
|
|
@@ -27434,7 +27470,7 @@ const onFollowingUserDeleted = ({ userId }) => (callback) => {
|
|
|
27434
27470
|
|
|
27435
27471
|
class FollowingLiveCollectionController extends LiveCollectionController {
|
|
27436
27472
|
constructor(query, callback) {
|
|
27437
|
-
const queryStreamId = hash(query);
|
|
27473
|
+
const queryStreamId = hash(Object.assign(Object.assign({}, query), { type: 'following' }));
|
|
27438
27474
|
const cacheKey = ['follow', 'collection', queryStreamId];
|
|
27439
27475
|
const paginationController = new FollowingPaginationController(query);
|
|
27440
27476
|
super(paginationController, queryStreamId, cacheKey, callback);
|
|
@@ -29340,16 +29376,19 @@ function isCurrentUserPartOfCommunity(c, m) {
|
|
|
29340
29376
|
}
|
|
29341
29377
|
/*
|
|
29342
29378
|
* For mqtt events server will not send user specific data as it's broadcasted
|
|
29343
|
-
* to multiple users
|
|
29344
|
-
*
|
|
29379
|
+
* to multiple users and it also does not include communityUser
|
|
29380
|
+
*
|
|
29381
|
+
* Client SDK needs to check for the existing isJoined field in cache data before calculating.
|
|
29382
|
+
* Althought this can be calculated, it's not scalable.
|
|
29345
29383
|
*/
|
|
29346
29384
|
function updateMembershipStatus(communities, communityUsers) {
|
|
29347
29385
|
return communities.map(c => {
|
|
29348
|
-
|
|
29349
|
-
|
|
29350
|
-
return Object.assign(Object.assign({},
|
|
29386
|
+
const cachedCommunity = pullFromCache(['community', 'get', c.communityId]);
|
|
29387
|
+
if ((cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data) && (cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data.hasOwnProperty('isJoined'))) {
|
|
29388
|
+
return Object.assign(Object.assign({}, cachedCommunity.data), c);
|
|
29351
29389
|
}
|
|
29352
|
-
|
|
29390
|
+
const isJoined = communityUsers.some(m => isCurrentUserPartOfCommunity(c, m) && isMember(m.communityMembership));
|
|
29391
|
+
return Object.assign(Object.assign({}, c), { isJoined });
|
|
29353
29392
|
});
|
|
29354
29393
|
}
|
|
29355
29394
|
|
|
@@ -29450,7 +29489,7 @@ const addReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
29450
29489
|
referenceType,
|
|
29451
29490
|
reactionName,
|
|
29452
29491
|
});
|
|
29453
|
-
await client.http.post('/api/v2/reactions', {
|
|
29492
|
+
const { data } = await client.http.post('/api/v2/reactions', {
|
|
29454
29493
|
referenceId,
|
|
29455
29494
|
referenceType,
|
|
29456
29495
|
reactionName,
|
|
@@ -29468,12 +29507,33 @@ const addReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
29468
29507
|
if (referenceType === 'comment') {
|
|
29469
29508
|
fireEvent('local.comment.addReaction', {
|
|
29470
29509
|
comment: updatedModel,
|
|
29510
|
+
reactor: {
|
|
29511
|
+
userId: client.userId,
|
|
29512
|
+
reactionName,
|
|
29513
|
+
reactionId: data.addedId,
|
|
29514
|
+
},
|
|
29471
29515
|
});
|
|
29472
29516
|
return true;
|
|
29473
29517
|
}
|
|
29474
29518
|
if (referenceType === 'post') {
|
|
29475
29519
|
fireEvent('local.post.addReaction', {
|
|
29476
29520
|
post: updatedModel,
|
|
29521
|
+
reactor: {
|
|
29522
|
+
userId: client.userId,
|
|
29523
|
+
reactionName,
|
|
29524
|
+
reactionId: data.addedId,
|
|
29525
|
+
},
|
|
29526
|
+
});
|
|
29527
|
+
return true;
|
|
29528
|
+
}
|
|
29529
|
+
if (referenceType === 'story') {
|
|
29530
|
+
fireEvent('local.story.reactionAdded', {
|
|
29531
|
+
story: updatedModel,
|
|
29532
|
+
reactor: {
|
|
29533
|
+
userId: client.userId,
|
|
29534
|
+
reactionName,
|
|
29535
|
+
reactionId: data.addedId,
|
|
29536
|
+
},
|
|
29477
29537
|
});
|
|
29478
29538
|
return true;
|
|
29479
29539
|
}
|
|
@@ -29548,7 +29608,7 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
29548
29608
|
referenceType,
|
|
29549
29609
|
reactionName,
|
|
29550
29610
|
});
|
|
29551
|
-
await client.http.delete(`/api/v2/reactions`, {
|
|
29611
|
+
const { data } = await client.http.delete(`/api/v2/reactions`, {
|
|
29552
29612
|
data: {
|
|
29553
29613
|
referenceId,
|
|
29554
29614
|
referenceType,
|
|
@@ -29568,12 +29628,33 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
29568
29628
|
if (referenceType === 'comment') {
|
|
29569
29629
|
fireEvent('local.comment.removeReaction', {
|
|
29570
29630
|
comment: updatedModel,
|
|
29631
|
+
reactor: {
|
|
29632
|
+
reactionId: data.removedId,
|
|
29633
|
+
reactionName,
|
|
29634
|
+
userId: client.userId,
|
|
29635
|
+
},
|
|
29571
29636
|
});
|
|
29572
29637
|
return true;
|
|
29573
29638
|
}
|
|
29574
29639
|
if (referenceType === 'post') {
|
|
29575
29640
|
fireEvent('local.post.removeReaction', {
|
|
29576
29641
|
post: updatedModel,
|
|
29642
|
+
reactor: {
|
|
29643
|
+
reactionId: data.removedId,
|
|
29644
|
+
reactionName,
|
|
29645
|
+
userId: client.userId,
|
|
29646
|
+
},
|
|
29647
|
+
});
|
|
29648
|
+
return true;
|
|
29649
|
+
}
|
|
29650
|
+
if (referenceType === 'story') {
|
|
29651
|
+
fireEvent('local.story.reactionAdded', {
|
|
29652
|
+
story: updatedModel,
|
|
29653
|
+
reactor: {
|
|
29654
|
+
userId: client.userId,
|
|
29655
|
+
reactionName,
|
|
29656
|
+
reactionId: data.removedId,
|
|
29657
|
+
},
|
|
29577
29658
|
});
|
|
29578
29659
|
return true;
|
|
29579
29660
|
}
|
|
@@ -29597,7 +29678,7 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
29597
29678
|
* @category Reaction API
|
|
29598
29679
|
* */
|
|
29599
29680
|
removeReaction.optimistically = (referenceType, referenceId, reactionName) => {
|
|
29600
|
-
var _a, _b, _c, _d
|
|
29681
|
+
var _a, _b, _c, _d;
|
|
29601
29682
|
const client = getActiveClient();
|
|
29602
29683
|
client.log('reaction/removeReaction.optimistically', {
|
|
29603
29684
|
referenceId,
|
|
@@ -29618,7 +29699,7 @@ removeReaction.optimistically = (referenceType, referenceId, reactionName) => {
|
|
|
29618
29699
|
cachedAt: UNSYNCED_OBJECT_CACHED_AT_VALUE,
|
|
29619
29700
|
});
|
|
29620
29701
|
dispatchReactable(referenceType, reaction);
|
|
29621
|
-
return
|
|
29702
|
+
return !((_d = reaction === null || reaction === void 0 ? void 0 : reaction.myReactions) === null || _d === void 0 ? void 0 : _d.includes(reactionName));
|
|
29622
29703
|
};
|
|
29623
29704
|
|
|
29624
29705
|
const getMatchPostSetting = (value) => {
|
|
@@ -30440,67 +30521,256 @@ const onReactorRemoved = (referenceType, referenceId, callback) => {
|
|
|
30440
30521
|
|
|
30441
30522
|
const REFERENCE_API_V5 = 5;
|
|
30442
30523
|
|
|
30524
|
+
class ReactionPaginationController extends PaginationController {
|
|
30525
|
+
async getRequest(queryParams, token) {
|
|
30526
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
30527
|
+
const options = token ? { token } : { limit };
|
|
30528
|
+
const client = getActiveClient();
|
|
30529
|
+
client.log('reaction/queryReactions', queryParams);
|
|
30530
|
+
const path = '/api/v3/reactions';
|
|
30531
|
+
const { data: queryResponse } = await this.http.get(path, {
|
|
30532
|
+
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
|
|
30533
|
+
options }),
|
|
30534
|
+
});
|
|
30535
|
+
return queryResponse;
|
|
30536
|
+
}
|
|
30537
|
+
}
|
|
30538
|
+
|
|
30539
|
+
class ReactionQueryStreamController extends QueryStreamController {
|
|
30540
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
30541
|
+
super(query, cacheKey);
|
|
30542
|
+
this.notifyChange = notifyChange;
|
|
30543
|
+
this.preparePayload = preparePayload;
|
|
30544
|
+
}
|
|
30545
|
+
async saveToMainDB(response) {
|
|
30546
|
+
var _a;
|
|
30547
|
+
const processedPayload = await this.preparePayload(response);
|
|
30548
|
+
const client = getActiveClient();
|
|
30549
|
+
const cachedAt = client.cache && Date.now();
|
|
30550
|
+
if (client.cache) {
|
|
30551
|
+
const { reactions } = processedPayload, restPayload = __rest(processedPayload, ["reactions"]);
|
|
30552
|
+
ingestInCache(Object.assign(Object.assign({}, restPayload), { reactions, reactors: (_a = reactions[0]) === null || _a === void 0 ? void 0 : _a.reactors }), { cachedAt });
|
|
30553
|
+
}
|
|
30554
|
+
}
|
|
30555
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
30556
|
+
var _a, _b, _c, _d;
|
|
30557
|
+
const reactors = (_b = (_a = response.reactions[0]) === null || _a === void 0 ? void 0 : _a.reactors) !== null && _b !== void 0 ? _b : [];
|
|
30558
|
+
if (refresh) {
|
|
30559
|
+
pushToCache(this.cacheKey, {
|
|
30560
|
+
data: reactors.map(getResolver('reactor')),
|
|
30561
|
+
});
|
|
30562
|
+
}
|
|
30563
|
+
else {
|
|
30564
|
+
const collection = (_c = pullFromCache(this.cacheKey)) === null || _c === void 0 ? void 0 : _c.data;
|
|
30565
|
+
const reactions = (_d = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _d !== void 0 ? _d : [];
|
|
30566
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...reactions, ...reactors.map(getResolver('reactor'))])] }));
|
|
30567
|
+
}
|
|
30568
|
+
}
|
|
30569
|
+
reactor(action) {
|
|
30570
|
+
return (reaction) => {
|
|
30571
|
+
var _a;
|
|
30572
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30573
|
+
if (!collection)
|
|
30574
|
+
return;
|
|
30575
|
+
if (action === "onAdded" /* Amity.ReactionActionTypeEnum.OnAdded */) {
|
|
30576
|
+
collection.data = [...new Set([reaction.reactionId, ...collection.data])];
|
|
30577
|
+
}
|
|
30578
|
+
else if (action === "onRemoved" /* Amity.ReactionActionTypeEnum.OnRemoved */) {
|
|
30579
|
+
collection.data = collection.data.filter(p => p !== reaction.reactionId);
|
|
30580
|
+
}
|
|
30581
|
+
pushToCache(this.cacheKey, collection);
|
|
30582
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
30583
|
+
};
|
|
30584
|
+
}
|
|
30585
|
+
subscribeRTE(createSubscriber) {
|
|
30586
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
30587
|
+
}
|
|
30588
|
+
}
|
|
30589
|
+
|
|
30443
30590
|
/**
|
|
30444
30591
|
* ```js
|
|
30445
|
-
* import {
|
|
30446
|
-
* const
|
|
30447
|
-
*
|
|
30448
|
-
* referenceType: 'post',
|
|
30592
|
+
* import { onReactorRemovedLocal } from '@amityco/ts-sdk'
|
|
30593
|
+
* const dispose = onReactorRemoved('post', postId, reactor => {
|
|
30594
|
+
* // ...
|
|
30449
30595
|
* })
|
|
30450
30596
|
* ```
|
|
30451
30597
|
*
|
|
30452
|
-
*
|
|
30598
|
+
* Fired when an {@link Amity.InternalReactor} has been removed
|
|
30453
30599
|
*
|
|
30454
|
-
* @param
|
|
30455
|
-
* @
|
|
30600
|
+
* @param {@link Amity.ReactableType} referenceType
|
|
30601
|
+
* @param {string} referenceId
|
|
30602
|
+
* @param callback The function to call when the event was fired
|
|
30603
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30456
30604
|
*
|
|
30457
|
-
* @
|
|
30458
|
-
* @async
|
|
30605
|
+
* @category Events
|
|
30459
30606
|
* */
|
|
30460
|
-
const
|
|
30607
|
+
const onReactorRemovedLocal = (referenceType, referenceId, callback) => {
|
|
30461
30608
|
const client = getActiveClient();
|
|
30462
|
-
|
|
30463
|
-
|
|
30464
|
-
|
|
30465
|
-
|
|
30466
|
-
|
|
30467
|
-
|
|
30468
|
-
|
|
30469
|
-
|
|
30470
|
-
|
|
30471
|
-
|
|
30472
|
-
|
|
30473
|
-
|
|
30474
|
-
|
|
30475
|
-
|
|
30476
|
-
|
|
30477
|
-
|
|
30609
|
+
const callbackWrapper = (referenceType_, referenceId_, reaction) => {
|
|
30610
|
+
if (referenceType_ === referenceType && referenceId_ === referenceId) {
|
|
30611
|
+
callback(reaction);
|
|
30612
|
+
}
|
|
30613
|
+
};
|
|
30614
|
+
if (referenceType === 'message') {
|
|
30615
|
+
const filter = async (rawPayload) => {
|
|
30616
|
+
const payload = await prepareMessagePayload(rawPayload);
|
|
30617
|
+
if (!payload.reactions[0])
|
|
30618
|
+
return;
|
|
30619
|
+
ingestInCache(payload);
|
|
30620
|
+
callbackWrapper('message', payload.messages[0].messageId, payload.reactions[0]);
|
|
30621
|
+
};
|
|
30622
|
+
return createEventSubscriber(client, 'reaction/onReactorRemoved', 'message.reactionRemoved', filter);
|
|
30623
|
+
}
|
|
30624
|
+
if (referenceType === 'post') {
|
|
30625
|
+
const filter = (payload) => {
|
|
30626
|
+
callbackWrapper('post', payload.post.postId, payload.reactor);
|
|
30627
|
+
};
|
|
30628
|
+
return createEventSubscriber(client, 'local.post.removeReaction', 'local.post.removeReaction', filter);
|
|
30629
|
+
}
|
|
30630
|
+
if (referenceType === 'story') {
|
|
30631
|
+
const filter = (payload) => {
|
|
30632
|
+
const { reactions } = payload, rest = __rest(payload, ["reactions"]);
|
|
30633
|
+
ingestInCache(rest);
|
|
30634
|
+
ingestInCache({ reactors: reactions });
|
|
30635
|
+
if (payload.stories.length === 0 || payload.reactions.length === 0)
|
|
30636
|
+
return;
|
|
30637
|
+
callbackWrapper('story', payload.stories[0].storyId, payload.reactions[0]);
|
|
30638
|
+
};
|
|
30639
|
+
return createEventSubscriber(client, 'story.reactionRemoved', 'story.reactionRemoved', filter);
|
|
30640
|
+
}
|
|
30641
|
+
const filter = (payload) => {
|
|
30642
|
+
callbackWrapper('comment', payload.comment.commentId, payload.reactor);
|
|
30643
|
+
};
|
|
30644
|
+
return createEventSubscriber(client, 'local.comment.removeReaction', 'local.comment.removeReaction', filter);
|
|
30478
30645
|
};
|
|
30479
30646
|
|
|
30480
30647
|
/**
|
|
30481
30648
|
* ```js
|
|
30482
|
-
* import {
|
|
30483
|
-
* const
|
|
30484
|
-
*
|
|
30485
|
-
* referenceType: 'post',
|
|
30649
|
+
* import { onReactorAddedLocal } from '@amityco/ts-sdk'
|
|
30650
|
+
* const dispose = onReactorAdded('post', postId, reactor => {
|
|
30651
|
+
* // ...
|
|
30486
30652
|
* })
|
|
30487
30653
|
* ```
|
|
30488
30654
|
*
|
|
30489
|
-
*
|
|
30655
|
+
* Fired when an {@link Amity.InternalReactor} has been added
|
|
30490
30656
|
*
|
|
30491
|
-
* @param
|
|
30492
|
-
* @
|
|
30657
|
+
* @param {@link Amity.ReactableType} referenceType
|
|
30658
|
+
* @param {string} referenceId
|
|
30659
|
+
* @param callback The function to call when the event was fired
|
|
30660
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30493
30661
|
*
|
|
30494
|
-
* @
|
|
30495
|
-
* @async
|
|
30662
|
+
* @category Events
|
|
30496
30663
|
* */
|
|
30497
|
-
const
|
|
30664
|
+
const onReactorAddedLocal = (referenceType, referenceId, callback) => {
|
|
30498
30665
|
const client = getActiveClient();
|
|
30499
|
-
|
|
30500
|
-
|
|
30501
|
-
|
|
30666
|
+
const callbackWrapper = (referenceType_, referenceId_, reaction) => {
|
|
30667
|
+
if (referenceType_ === referenceType && referenceId_ === referenceId) {
|
|
30668
|
+
callback(reaction);
|
|
30669
|
+
}
|
|
30670
|
+
};
|
|
30671
|
+
if (referenceType === 'message') {
|
|
30672
|
+
const filter = async (rawPayload) => {
|
|
30673
|
+
const payload = await prepareMessagePayload(rawPayload);
|
|
30674
|
+
if (!payload.reactions[0])
|
|
30675
|
+
return;
|
|
30676
|
+
ingestInCache(payload);
|
|
30677
|
+
ingestInCache({ reactors: payload.reactions });
|
|
30678
|
+
callbackWrapper('message', payload.messages[0].messageId, payload.reactions[0]);
|
|
30679
|
+
};
|
|
30680
|
+
return createEventSubscriber(client, 'reaction/onReactorAdded', 'message.reactionAdded', filter);
|
|
30681
|
+
}
|
|
30682
|
+
if (referenceType === 'post') {
|
|
30683
|
+
const filter = (payload) => {
|
|
30684
|
+
callbackWrapper('post', payload.post.postId, payload.reactor);
|
|
30685
|
+
};
|
|
30686
|
+
return createEventSubscriber(client, 'local.post.addReaction', 'local.post.addReaction', filter);
|
|
30687
|
+
}
|
|
30688
|
+
if (referenceType === 'story') {
|
|
30689
|
+
const filter = (payload) => {
|
|
30690
|
+
const { reactions } = payload, rest = __rest(payload, ["reactions"]);
|
|
30691
|
+
ingestInCache(rest);
|
|
30692
|
+
ingestInCache({ reactors: reactions });
|
|
30693
|
+
if (payload.stories.length === 0 || payload.reactions.length === 0)
|
|
30694
|
+
return;
|
|
30695
|
+
callbackWrapper('story', payload.stories[0].storyId, payload.reactions[0]);
|
|
30696
|
+
};
|
|
30697
|
+
return createEventSubscriber(client, 'story.reactionAdded', 'story.reactionAdded', filter);
|
|
30698
|
+
}
|
|
30699
|
+
const filter = (payload) => {
|
|
30700
|
+
callbackWrapper('comment', payload.comment.commentId, payload.reactor);
|
|
30701
|
+
};
|
|
30702
|
+
return createEventSubscriber(client, 'local.comment.addReaction', 'local.comment.addReaction', filter);
|
|
30502
30703
|
};
|
|
30503
30704
|
|
|
30705
|
+
class ReactionLiveCollectionController extends LiveCollectionController {
|
|
30706
|
+
constructor(query, callback) {
|
|
30707
|
+
const queryStreamId = hash(query);
|
|
30708
|
+
const cacheKey = ['reaction', 'collection', queryStreamId];
|
|
30709
|
+
const paginationController = new ReactionPaginationController(query);
|
|
30710
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
30711
|
+
this.query = query;
|
|
30712
|
+
this.queryStreamController = new ReactionQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), payload => payload);
|
|
30713
|
+
this.callback = callback.bind(this);
|
|
30714
|
+
this.loadPage({ initial: true });
|
|
30715
|
+
}
|
|
30716
|
+
setup() {
|
|
30717
|
+
var _a;
|
|
30718
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30719
|
+
if (!collection) {
|
|
30720
|
+
pushToCache(this.cacheKey, {
|
|
30721
|
+
data: [],
|
|
30722
|
+
params: {},
|
|
30723
|
+
});
|
|
30724
|
+
}
|
|
30725
|
+
}
|
|
30726
|
+
async persistModel(queryPayload) {
|
|
30727
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
30728
|
+
}
|
|
30729
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
30730
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
30731
|
+
}
|
|
30732
|
+
startSubscription() {
|
|
30733
|
+
return this.queryStreamController.subscribeRTE([
|
|
30734
|
+
{
|
|
30735
|
+
fn: callback => onReactorAdded(this.query.referenceType, this.query.referenceId, callback),
|
|
30736
|
+
action: "onAdded" /* Amity.ReactionActionTypeEnum.OnAdded */,
|
|
30737
|
+
},
|
|
30738
|
+
{
|
|
30739
|
+
fn: callback => onReactorRemoved(this.query.referenceType, this.query.referenceId, callback),
|
|
30740
|
+
action: "onRemoved" /* Amity.ReactionActionTypeEnum.OnRemoved */,
|
|
30741
|
+
},
|
|
30742
|
+
{
|
|
30743
|
+
fn: callback => onReactorRemovedLocal(this.query.referenceType, this.query.referenceId, callback),
|
|
30744
|
+
action: "onRemoved" /* Amity.ReactionActionTypeEnum.OnRemoved */,
|
|
30745
|
+
},
|
|
30746
|
+
{
|
|
30747
|
+
fn: callback => onReactorAddedLocal(this.query.referenceType, this.query.referenceId, callback),
|
|
30748
|
+
action: "onRemoved" /* Amity.ReactionActionTypeEnum.OnRemoved */,
|
|
30749
|
+
},
|
|
30750
|
+
]);
|
|
30751
|
+
}
|
|
30752
|
+
notifyChange({ origin, loading, error }) {
|
|
30753
|
+
var _a, _b;
|
|
30754
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30755
|
+
if (!collection)
|
|
30756
|
+
return;
|
|
30757
|
+
const data = (_b = collection.data
|
|
30758
|
+
.map(reactorId => pullFromCache(['reactor', 'get', reactorId]))
|
|
30759
|
+
.filter(Boolean)
|
|
30760
|
+
.map(({ data }) => LinkedObject.reactor(data))) !== null && _b !== void 0 ? _b : [];
|
|
30761
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
30762
|
+
return;
|
|
30763
|
+
this.callback({
|
|
30764
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
30765
|
+
data,
|
|
30766
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
30767
|
+
loading,
|
|
30768
|
+
error,
|
|
30769
|
+
});
|
|
30770
|
+
}
|
|
30771
|
+
}
|
|
30772
|
+
|
|
30773
|
+
/* eslint-disable no-use-before-define */
|
|
30504
30774
|
/* begin_public_function
|
|
30505
30775
|
id: reaction.query
|
|
30506
30776
|
*/
|
|
@@ -30530,69 +30800,15 @@ const getReactions = (params, callback, config) => {
|
|
|
30530
30800
|
console.log('For using Live Collection feature you need to enable Cache!');
|
|
30531
30801
|
}
|
|
30532
30802
|
const timestamp = Date.now();
|
|
30533
|
-
log(`
|
|
30534
|
-
const
|
|
30535
|
-
const
|
|
30536
|
-
const
|
|
30537
|
-
|
|
30538
|
-
|
|
30539
|
-
|
|
30540
|
-
'collection',
|
|
30541
|
-
{ referenceId: params.referenceId, referenceType: params.referenceType },
|
|
30542
|
-
];
|
|
30543
|
-
const responder = (data) => {
|
|
30544
|
-
var _a, _b;
|
|
30545
|
-
const reactions = (_a = data.data
|
|
30546
|
-
.map(reactorId => pullFromCache(['reactor', 'get', reactorId]))
|
|
30547
|
-
.filter(Boolean)
|
|
30548
|
-
.map(({ data }) => LinkedObject.reactor(data))) !== null && _a !== void 0 ? _a : [];
|
|
30549
|
-
callback({
|
|
30550
|
-
onNextPage: onFetch,
|
|
30551
|
-
data: reactions,
|
|
30552
|
-
hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
|
|
30553
|
-
loading: data.loading,
|
|
30554
|
-
error: data.error,
|
|
30555
|
-
});
|
|
30556
|
-
};
|
|
30557
|
-
const realtimeRouter = (action) => (reaction) => {
|
|
30558
|
-
var _a;
|
|
30559
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30560
|
-
if (!collection)
|
|
30561
|
-
return;
|
|
30562
|
-
if (action === 'onAdded') {
|
|
30563
|
-
collection.data = [...new Set([reaction.reactionId, ...collection.data])];
|
|
30564
|
-
}
|
|
30565
|
-
else if (action === 'onRemoved') {
|
|
30566
|
-
collection.data = collection.data.filter(p => p !== reaction.reactionId);
|
|
30567
|
-
}
|
|
30568
|
-
pushToCache(cacheKey, collection);
|
|
30569
|
-
responder(collection);
|
|
30570
|
-
};
|
|
30571
|
-
const onFetch = (initial = false) => {
|
|
30572
|
-
var _a, _b, _c, _d;
|
|
30573
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30574
|
-
const reactions = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
30575
|
-
if (!initial && reactions.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
|
|
30576
|
-
return;
|
|
30577
|
-
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 } }));
|
|
30578
|
-
runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
|
|
30579
|
-
const data = {
|
|
30580
|
-
loading,
|
|
30581
|
-
error,
|
|
30582
|
-
params: { page },
|
|
30583
|
-
data: reactions,
|
|
30584
|
-
};
|
|
30585
|
-
if (result) {
|
|
30586
|
-
data.data = [...new Set([...reactions, ...result.map(getResolver('reactor'))])];
|
|
30587
|
-
}
|
|
30588
|
-
pushToCache(cacheKey, data);
|
|
30589
|
-
responder(data);
|
|
30590
|
-
}, queryOptions(policy));
|
|
30591
|
-
};
|
|
30592
|
-
disposers.push(onReactorAdded(queryParams.referenceType, queryParams.referenceId, realtimeRouter('onAdded')), onReactorRemoved(queryParams.referenceType, queryParams.referenceId, realtimeRouter('onRemoved')));
|
|
30593
|
-
onFetch(true);
|
|
30803
|
+
log(`getReactions(tmpid: ${timestamp}) > listen`);
|
|
30804
|
+
const reactionLiveCollection = new ReactionLiveCollectionController(params, callback);
|
|
30805
|
+
const disposers = reactionLiveCollection.startSubscription();
|
|
30806
|
+
const cacheKey = reactionLiveCollection.getCacheKey();
|
|
30807
|
+
disposers.push(() => {
|
|
30808
|
+
dropFromCache(cacheKey);
|
|
30809
|
+
});
|
|
30594
30810
|
return () => {
|
|
30595
|
-
log(`
|
|
30811
|
+
log(`getReactions(tmpid: ${timestamp}) > dispose`);
|
|
30596
30812
|
disposers.forEach(fn => fn());
|
|
30597
30813
|
};
|
|
30598
30814
|
};
|
|
@@ -31098,30 +31314,6 @@ const unmuteChannel = async (channelId) => {
|
|
|
31098
31314
|
};
|
|
31099
31315
|
/* end_public_function */
|
|
31100
31316
|
|
|
31101
|
-
const convertEventPayload = (eventHandler, sourceModelProp, destinationDomain) => (callback) => eventHandler(sourceModel => {
|
|
31102
|
-
var _a, _b;
|
|
31103
|
-
if (!sourceModel) {
|
|
31104
|
-
return sourceModel;
|
|
31105
|
-
}
|
|
31106
|
-
const client = getActiveClient();
|
|
31107
|
-
const { objectSyncMap } = client;
|
|
31108
|
-
/*
|
|
31109
|
-
* 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.
|
|
31110
|
-
* 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.
|
|
31111
|
-
*/
|
|
31112
|
-
const resolvedId = isLocalId(sourceModel[sourceModelProp])
|
|
31113
|
-
? sourceModel[sourceModelProp]
|
|
31114
|
-
: (_a = objectSyncMap.get(sourceModel[sourceModelProp])) !== null && _a !== void 0 ? _a : sourceModel[sourceModelProp];
|
|
31115
|
-
const model = (_b = pullFromCache([
|
|
31116
|
-
destinationDomain,
|
|
31117
|
-
'get',
|
|
31118
|
-
`${resolvedId}`,
|
|
31119
|
-
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
31120
|
-
if (!model)
|
|
31121
|
-
return;
|
|
31122
|
-
return callback(model);
|
|
31123
|
-
});
|
|
31124
|
-
|
|
31125
31317
|
/**
|
|
31126
31318
|
* ```js
|
|
31127
31319
|
* import { observeChannel } from '@amityco/ts-sdk'
|
|
@@ -35260,7 +35452,8 @@ const createCommunityMemberEventSubscriber = (event, callback) => {
|
|
|
35260
35452
|
callback(preparedPayload.communities[0], getEventRelatedMember(event, preparedPayload));
|
|
35261
35453
|
}
|
|
35262
35454
|
else {
|
|
35263
|
-
|
|
35455
|
+
// NOTE: The event payload should be merge with existing cache data
|
|
35456
|
+
ingestInCache(preparedPayload, undefined, false);
|
|
35264
35457
|
const community = pullFromCache([
|
|
35265
35458
|
'community',
|
|
35266
35459
|
'get',
|
|
@@ -35297,7 +35490,8 @@ const createLocalCommunityMemberEventSubscriber = (event, callback) => {
|
|
|
35297
35490
|
callback(preparedPayload.communities[0], getEventRelatedMember(event, preparedPayload));
|
|
35298
35491
|
}
|
|
35299
35492
|
else {
|
|
35300
|
-
|
|
35493
|
+
// NOTE: The event payload should be merge with existing cache data
|
|
35494
|
+
ingestInCache(preparedPayload, undefined, false);
|
|
35301
35495
|
const community = pullFromCache([
|
|
35302
35496
|
'community',
|
|
35303
35497
|
'get',
|
|
@@ -37387,9 +37581,10 @@ const queryGlobalFeed = async (query) => {
|
|
|
37387
37581
|
const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
|
|
37388
37582
|
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
37389
37583
|
const { posts } = data;
|
|
37584
|
+
const { communities: processedCommunity } = prepareCommunityPayload(data);
|
|
37390
37585
|
const cachedAt = client.cache && Date.now();
|
|
37391
37586
|
if (client.cache) {
|
|
37392
|
-
ingestInCache(data);
|
|
37587
|
+
ingestInCache(Object.assign(Object.assign({}, data), { communitis: processedCommunity }));
|
|
37393
37588
|
const cacheKey = [
|
|
37394
37589
|
'globalFeed',
|
|
37395
37590
|
'query',
|
|
@@ -39704,6 +39899,145 @@ const getPinnedPosts = (params, callback, config) => {
|
|
|
39704
39899
|
};
|
|
39705
39900
|
};
|
|
39706
39901
|
|
|
39902
|
+
class GlobalPinnedPostPaginationController extends PaginationController {
|
|
39903
|
+
async getRequest(queryParams, token) {
|
|
39904
|
+
__rest(queryParams, ["limit"]);
|
|
39905
|
+
const path = '/api/v1/pinned-posts/global';
|
|
39906
|
+
const { data: queryResponse } = await this.http.get(path);
|
|
39907
|
+
return queryResponse;
|
|
39908
|
+
}
|
|
39909
|
+
}
|
|
39910
|
+
|
|
39911
|
+
class GlobalPinnedPostQueryStreamController extends QueryStreamController {
|
|
39912
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
39913
|
+
super(query, cacheKey);
|
|
39914
|
+
this.notifyChange = notifyChange;
|
|
39915
|
+
this.preparePayload = preparePayload;
|
|
39916
|
+
}
|
|
39917
|
+
// eslint-disable-next-line class-methods-use-this
|
|
39918
|
+
async saveToMainDB(response) {
|
|
39919
|
+
const client = getActiveClient();
|
|
39920
|
+
const cachedAt = client.cache && Date.now();
|
|
39921
|
+
if (client.cache) {
|
|
39922
|
+
ingestInCache(response, { cachedAt });
|
|
39923
|
+
}
|
|
39924
|
+
}
|
|
39925
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
39926
|
+
var _a, _b;
|
|
39927
|
+
if (refresh) {
|
|
39928
|
+
pushToCache(this.cacheKey, {
|
|
39929
|
+
data: response.pins.map(getResolver('pin')),
|
|
39930
|
+
});
|
|
39931
|
+
}
|
|
39932
|
+
else {
|
|
39933
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
39934
|
+
const pinnedPosts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
39935
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...pinnedPosts, ...response.pins.map(getResolver('pin'))])] }));
|
|
39936
|
+
this.notifyChange({
|
|
39937
|
+
origin: "server" /* Amity.LiveDataOrigin.SERVER */,
|
|
39938
|
+
loading: false,
|
|
39939
|
+
});
|
|
39940
|
+
}
|
|
39941
|
+
}
|
|
39942
|
+
reactor(action) {
|
|
39943
|
+
return (post) => {
|
|
39944
|
+
var _a;
|
|
39945
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
39946
|
+
if (!collection)
|
|
39947
|
+
return;
|
|
39948
|
+
if (action === EnumPostActions.OnPostDeleted) {
|
|
39949
|
+
collection.data = collection.data.filter(referenceId => referenceId !== `global#${post.postId}`);
|
|
39950
|
+
}
|
|
39951
|
+
pushToCache(this.cacheKey, collection);
|
|
39952
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
39953
|
+
};
|
|
39954
|
+
}
|
|
39955
|
+
subscribeRTE(createSubscriber) {
|
|
39956
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
39957
|
+
}
|
|
39958
|
+
}
|
|
39959
|
+
|
|
39960
|
+
class GlobalPinnedPostLiveCollectionController extends LiveCollectionController {
|
|
39961
|
+
constructor(query, callback) {
|
|
39962
|
+
const queryStreamId = hash(query);
|
|
39963
|
+
const cacheKey = ['pinnedPosts', 'collection', queryStreamId];
|
|
39964
|
+
const paginationController = new GlobalPinnedPostPaginationController(query);
|
|
39965
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
39966
|
+
this.query = query;
|
|
39967
|
+
this.queryStreamController = new GlobalPinnedPostQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), response => response);
|
|
39968
|
+
this.callback = callback.bind(this);
|
|
39969
|
+
this.loadPage({ initial: true });
|
|
39970
|
+
}
|
|
39971
|
+
setup() {
|
|
39972
|
+
var _a;
|
|
39973
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
39974
|
+
if (!collection) {
|
|
39975
|
+
pushToCache(this.cacheKey, {
|
|
39976
|
+
data: [],
|
|
39977
|
+
params: {},
|
|
39978
|
+
});
|
|
39979
|
+
}
|
|
39980
|
+
}
|
|
39981
|
+
async persistModel(queryPayload) {
|
|
39982
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
39983
|
+
}
|
|
39984
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
39985
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
39986
|
+
}
|
|
39987
|
+
// eslint-disable-next-line class-methods-use-this
|
|
39988
|
+
startSubscription() {
|
|
39989
|
+
return this.queryStreamController.subscribeRTE([
|
|
39990
|
+
{ fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
|
|
39991
|
+
{
|
|
39992
|
+
fn: onPostDeleted,
|
|
39993
|
+
action: EnumPostActions.OnPostDeleted,
|
|
39994
|
+
},
|
|
39995
|
+
]);
|
|
39996
|
+
}
|
|
39997
|
+
notifyChange({ origin, loading, error }) {
|
|
39998
|
+
var _a, _b;
|
|
39999
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
40000
|
+
if (!collection)
|
|
40001
|
+
return;
|
|
40002
|
+
const data = ((_b = collection.data
|
|
40003
|
+
.map(id => pullFromCache(['pin', 'get', id]))
|
|
40004
|
+
.filter(isNonNullable)
|
|
40005
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.pinnedPost);
|
|
40006
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
40007
|
+
return;
|
|
40008
|
+
this.callback({
|
|
40009
|
+
data,
|
|
40010
|
+
loading,
|
|
40011
|
+
error,
|
|
40012
|
+
});
|
|
40013
|
+
}
|
|
40014
|
+
}
|
|
40015
|
+
|
|
40016
|
+
/**
|
|
40017
|
+
* Get global pinned posts
|
|
40018
|
+
*
|
|
40019
|
+
* @returns the global pinned post(s)
|
|
40020
|
+
*
|
|
40021
|
+
* @category Pined Posts Live Collection
|
|
40022
|
+
*
|
|
40023
|
+
*/
|
|
40024
|
+
const getGlobalPinnedPosts = (params, callback, config) => {
|
|
40025
|
+
const { log, cache } = getActiveClient();
|
|
40026
|
+
if (!cache) {
|
|
40027
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
40028
|
+
}
|
|
40029
|
+
const timestamp = Date.now();
|
|
40030
|
+
log(`getGlobalPinnedPosts(tmpid: ${timestamp}) > listen`);
|
|
40031
|
+
const globalPinnedPostLiveCollection = new GlobalPinnedPostLiveCollectionController(params, callback);
|
|
40032
|
+
const disposers = globalPinnedPostLiveCollection.startSubscription();
|
|
40033
|
+
const cacheKey = globalPinnedPostLiveCollection.getCacheKey();
|
|
40034
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
40035
|
+
return () => {
|
|
40036
|
+
log(`getGlobalPinnedPosts(tmpid: ${timestamp}) > dispose`);
|
|
40037
|
+
disposers.forEach(fn => fn());
|
|
40038
|
+
};
|
|
40039
|
+
};
|
|
40040
|
+
|
|
39707
40041
|
class SemanticSearchPostPaginationController extends PaginationController {
|
|
39708
40042
|
async getRequest(queryParams, token) {
|
|
39709
40043
|
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
@@ -39965,6 +40299,7 @@ var index$5 = /*#__PURE__*/Object.freeze({
|
|
|
39965
40299
|
getPost: getPost$1,
|
|
39966
40300
|
getPosts: getPosts,
|
|
39967
40301
|
getPinnedPosts: getPinnedPosts,
|
|
40302
|
+
getGlobalPinnedPosts: getGlobalPinnedPosts,
|
|
39968
40303
|
semanticSearchPosts: semanticSearchPosts
|
|
39969
40304
|
});
|
|
39970
40305
|
|
|
@@ -40859,7 +41194,7 @@ var index$3 = /*#__PURE__*/Object.freeze({
|
|
|
40859
41194
|
getPoll: getPoll
|
|
40860
41195
|
});
|
|
40861
41196
|
|
|
40862
|
-
const privateKey = "-----BEGIN PRIVATE KEY-----\
|
|
41197
|
+
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-----";
|
|
40863
41198
|
/*
|
|
40864
41199
|
* The crypto algorithm used for importing key and signing string
|
|
40865
41200
|
*/
|
|
@@ -41515,8 +41850,8 @@ const onStoryReactionAdded = (callback) => {
|
|
|
41515
41850
|
const onStoryReactionAddedLocal = (callback) => {
|
|
41516
41851
|
const client = getActiveClient();
|
|
41517
41852
|
const filter = async (payload) => {
|
|
41518
|
-
ingestInCache(payload);
|
|
41519
|
-
callback(payload.
|
|
41853
|
+
ingestInCache({ stories: [payload.story] });
|
|
41854
|
+
callback([payload.story]);
|
|
41520
41855
|
};
|
|
41521
41856
|
const disposers = [
|
|
41522
41857
|
createEventSubscriber(client, 'onStoryReactionAdded', 'local.story.reactionAdded', filter),
|
|
@@ -41545,8 +41880,8 @@ const onStoryReactionRemoved = (callback) => {
|
|
|
41545
41880
|
const onStoryReactionRemovedLocal = (callback) => {
|
|
41546
41881
|
const client = getActiveClient();
|
|
41547
41882
|
const filter = async (payload) => {
|
|
41548
|
-
ingestInCache(payload);
|
|
41549
|
-
callback(payload.
|
|
41883
|
+
ingestInCache({ stories: [payload.story] });
|
|
41884
|
+
callback([payload.story]);
|
|
41550
41885
|
};
|
|
41551
41886
|
const disposers = [
|
|
41552
41887
|
createEventSubscriber(client, 'onStoryReactionRemoved', 'local.story.reactionRemoved', filter),
|
|
@@ -42086,12 +42421,12 @@ const updateLocalList = (cacheKey, targetIds) => {
|
|
|
42086
42421
|
pushToCache(cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...storyTargets, ...targetIds])] }));
|
|
42087
42422
|
};
|
|
42088
42423
|
class GlobalStoryQueryStreamController extends QueryStreamController {
|
|
42089
|
-
constructor(query, cacheKey, notifyChange, paginationController) {
|
|
42424
|
+
constructor(query, cacheKey, notifyChange, paginationController, preparePayload) {
|
|
42090
42425
|
super(query, cacheKey);
|
|
42091
42426
|
this.notifyChange = notifyChange;
|
|
42092
42427
|
this.paginationController = paginationController;
|
|
42093
42428
|
// Fix ESLint, "Expected 'this' to be used by class method"
|
|
42094
|
-
this.preparePayload =
|
|
42429
|
+
this.preparePayload = preparePayload;
|
|
42095
42430
|
}
|
|
42096
42431
|
saveToMainDB(response) {
|
|
42097
42432
|
const client = getActiveClient();
|
|
@@ -42183,7 +42518,10 @@ class GlobalStoryLiveCollectionController extends LiveCollectionController {
|
|
|
42183
42518
|
const paginationController = new GlobalStoryPageController(query);
|
|
42184
42519
|
super(paginationController, queryStreamId, cacheKey, callback);
|
|
42185
42520
|
this.query = query;
|
|
42186
|
-
this.queryStreamController = new GlobalStoryQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), paginationController)
|
|
42521
|
+
this.queryStreamController = new GlobalStoryQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), paginationController, (data) => {
|
|
42522
|
+
const _a = prepareCommunityPayload(Object.assign(Object.assign({}, data), { feeds: [] })), rest = __rest(_a, ["feeds"]);
|
|
42523
|
+
return Object.assign(Object.assign({}, data), rest);
|
|
42524
|
+
});
|
|
42187
42525
|
this.paginationController = paginationController;
|
|
42188
42526
|
this.callback = callback.bind(this);
|
|
42189
42527
|
this.loadPage({ initial: true });
|