@amityco/ts-sdk 6.29.3-b60ec74.0 → 6.29.3-bd024fd.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@types/core/events.d.ts +41 -11
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/model.d.ts +1 -1
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +18 -4
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/core/permissions.d.ts +4 -4
- package/dist/@types/core/permissions.d.ts.map +1 -1
- package/dist/@types/domains/follow.d.ts +21 -3
- package/dist/@types/domains/follow.d.ts.map +1 -1
- package/dist/@types/domains/post.d.ts +3 -3
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/@types/domains/user.d.ts +2 -2
- package/dist/@types/domains/user.d.ts.map +1 -1
- package/dist/channelRepository/channelMembership/observers/getMembers/ChannelMemberLiveCollectionController.d.ts.map +1 -1
- package/dist/channelRepository/channelMembership/observers/getMembers/ChannelMemberPaginationController.d.ts.map +1 -1
- package/dist/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberLiveCollectionController.d.ts.map +1 -1
- package/dist/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberPaginationController.d.ts.map +1 -1
- package/dist/channelRepository/events/onUserDeleted.d.ts +2 -0
- package/dist/channelRepository/events/onUserDeleted.d.ts.map +1 -0
- package/dist/commentRepository/api/createComment.d.ts.map +1 -1
- package/dist/commentRepository/api/deleteComment.d.ts.map +1 -1
- package/dist/commentRepository/events/onCommentCreatedLocal.d.ts +17 -0
- package/dist/commentRepository/events/onCommentCreatedLocal.d.ts.map +1 -0
- package/dist/commentRepository/events/onCommentDeletedLocal.d.ts +17 -0
- package/dist/commentRepository/events/onCommentDeletedLocal.d.ts.map +1 -0
- package/dist/commentRepository/events/onLocalCommentReactionAdded.d.ts +17 -0
- package/dist/commentRepository/events/onLocalCommentReactionAdded.d.ts.map +1 -0
- package/dist/commentRepository/events/onLocalCommentReactionRemoved.d.ts +17 -0
- package/dist/commentRepository/events/onLocalCommentReactionRemoved.d.ts.map +1 -0
- package/dist/commentRepository/events/utils.d.ts +1 -0
- package/dist/commentRepository/events/utils.d.ts.map +1 -1
- package/dist/commentRepository/observers/getComment.d.ts.map +1 -1
- package/dist/commentRepository/observers/getComments/CommentLiveCollectionController.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/index.d.ts +2 -0
- package/dist/communityRepository/communityMembership/events/index.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/onLocalCommunityUserAdded.d.ts +17 -0
- package/dist/communityRepository/communityMembership/events/onLocalCommunityUserAdded.d.ts.map +1 -0
- package/dist/communityRepository/communityMembership/events/onLocalCommunityUserRemoved.d.ts +17 -0
- package/dist/communityRepository/communityMembership/events/onLocalCommunityUserRemoved.d.ts.map +1 -0
- package/dist/communityRepository/communityMembership/events/onUserDeleted.d.ts +17 -0
- package/dist/communityRepository/communityMembership/events/onUserDeleted.d.ts.map +1 -0
- package/dist/communityRepository/communityMembership/events/utils.d.ts +1 -0
- package/dist/communityRepository/communityMembership/events/utils.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersLiveCollectionController.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersPaginationController.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/observers/getMembers/enums.d.ts +4 -1
- package/dist/communityRepository/communityMembership/observers/getMembers/enums.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersLiveCollectionController.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersPaginationController.d.ts.map +1 -1
- package/dist/communityRepository/communityModeration/api/addRoles.d.ts.map +1 -1
- package/dist/communityRepository/communityModeration/api/removeRoles.d.ts.map +1 -1
- package/dist/communityRepository/communityModeration/events/onLocalCommunityRoleAdded.d.ts +17 -0
- package/dist/communityRepository/communityModeration/events/onLocalCommunityRoleAdded.d.ts.map +1 -0
- package/dist/communityRepository/communityModeration/events/onLocalCommunityRoleRemoved.d.ts +17 -0
- package/dist/communityRepository/communityModeration/events/onLocalCommunityRoleRemoved.d.ts.map +1 -0
- package/dist/communityRepository/utils/payload.d.ts +1 -0
- package/dist/communityRepository/utils/payload.d.ts.map +1 -1
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.d.ts.map +1 -1
- package/dist/index.cjs.js +1622 -925
- package/dist/index.esm.js +1551 -854
- package/dist/index.umd.js +4 -4
- package/dist/postRepository/events/onLocalPostDeleted.d.ts +17 -0
- package/dist/postRepository/events/onLocalPostDeleted.d.ts.map +1 -0
- package/dist/postRepository/events/onLocalPostReactionAdded.d.ts +17 -0
- package/dist/postRepository/events/onLocalPostReactionAdded.d.ts.map +1 -0
- package/dist/postRepository/events/onLocalPostReactionRemoved.d.ts +17 -0
- package/dist/postRepository/events/onLocalPostReactionRemoved.d.ts.map +1 -0
- package/dist/postRepository/events/onPostUpdatedLocal.d.ts +17 -0
- package/dist/postRepository/events/onPostUpdatedLocal.d.ts.map +1 -0
- package/dist/postRepository/events/utils.d.ts +1 -0
- package/dist/postRepository/events/utils.d.ts.map +1 -1
- package/dist/postRepository/internalApi/index.d.ts +1 -12
- package/dist/postRepository/internalApi/index.d.ts.map +1 -1
- package/dist/postRepository/observers/getPost.d.ts.map +1 -1
- package/dist/postRepository/observers/getPosts/PostLiveCollectionController.d.ts.map +1 -1
- package/dist/postRepository/utils/payload.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/userRepository/observers/getBlockedUsers/BlockedUserLiveCollectionController.d.ts +14 -0
- package/dist/userRepository/observers/getBlockedUsers/BlockedUserLiveCollectionController.d.ts.map +1 -0
- package/dist/userRepository/observers/getBlockedUsers/BlockedUserPaginationController.d.ts +5 -0
- package/dist/userRepository/observers/getBlockedUsers/BlockedUserPaginationController.d.ts.map +1 -0
- package/dist/userRepository/observers/getBlockedUsers/BlockedUserQueryStreamController.d.ts +15 -0
- package/dist/userRepository/observers/getBlockedUsers/BlockedUserQueryStreamController.d.ts.map +1 -0
- package/dist/userRepository/observers/getBlockedUsers.d.ts.map +1 -1
- package/dist/userRepository/relationship/block/api/blockUser.d.ts.map +1 -1
- package/dist/userRepository/relationship/block/api/unBlockUser.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/api/acceptFollower.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/api/acceptMyFollower.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/api/declineFollower.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/api/declineMyFollower.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/api/follow.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/api/unfollow.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/api/utils.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/enums.d.ts +11 -0
- package/dist/userRepository/relationship/follow/enums.d.ts.map +1 -0
- package/dist/userRepository/relationship/follow/events/index.d.ts +5 -0
- package/dist/userRepository/relationship/follow/events/index.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/events/onFollowInfoUpdated.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/events/onFollowerUserDeleted.d.ts +4 -0
- package/dist/userRepository/relationship/follow/events/onFollowerUserDeleted.d.ts.map +1 -0
- package/dist/userRepository/relationship/follow/events/onFollowingUserDeleted.d.ts +4 -0
- package/dist/userRepository/relationship/follow/events/onFollowingUserDeleted.d.ts.map +1 -0
- package/dist/userRepository/relationship/follow/events/onLocalFollowRequestAccepted.d.ts +2 -0
- package/dist/userRepository/relationship/follow/events/onLocalFollowRequestAccepted.d.ts.map +1 -0
- package/dist/userRepository/relationship/follow/events/onLocalFollowRequestDeclined.d.ts +2 -0
- package/dist/userRepository/relationship/follow/events/onLocalFollowRequestDeclined.d.ts.map +1 -0
- package/dist/userRepository/relationship/follow/events/onLocalFollowerRequested.d.ts +2 -0
- package/dist/userRepository/relationship/follow/events/onLocalFollowerRequested.d.ts.map +1 -0
- package/dist/userRepository/relationship/follow/events/onLocalUserFollowed.d.ts +2 -0
- package/dist/userRepository/relationship/follow/events/onLocalUserFollowed.d.ts.map +1 -0
- package/dist/userRepository/relationship/follow/events/onLocalUserUnfollowed.d.ts +2 -0
- package/dist/userRepository/relationship/follow/events/onLocalUserUnfollowed.d.ts.map +1 -0
- package/dist/userRepository/relationship/follow/events/utils.d.ts +2 -1
- package/dist/userRepository/relationship/follow/events/utils.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/observers/getFollowers/FollowerLiveCollectionController.d.ts +14 -0
- package/dist/userRepository/relationship/follow/observers/getFollowers/FollowerLiveCollectionController.d.ts.map +1 -0
- package/dist/userRepository/relationship/follow/observers/getFollowers/FollowerPaginationController.d.ts +5 -0
- package/dist/userRepository/relationship/follow/observers/getFollowers/FollowerPaginationController.d.ts.map +1 -0
- package/dist/userRepository/relationship/follow/observers/getFollowers/FollowerQueryStreamController.d.ts +15 -0
- package/dist/userRepository/relationship/follow/observers/getFollowers/FollowerQueryStreamController.d.ts.map +1 -0
- package/dist/userRepository/relationship/follow/observers/getFollowers.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/observers/getFollowings/FollowingLiveCollectionController.d.ts +14 -0
- package/dist/userRepository/relationship/follow/observers/getFollowings/FollowingLiveCollectionController.d.ts.map +1 -0
- package/dist/userRepository/relationship/follow/observers/getFollowings/FollowingPaginationController.d.ts +5 -0
- package/dist/userRepository/relationship/follow/observers/getFollowings/FollowingPaginationController.d.ts.map +1 -0
- package/dist/userRepository/relationship/follow/observers/getFollowings/FollowingQueryStreamController.d.ts +15 -0
- package/dist/userRepository/relationship/follow/observers/getFollowings/FollowingQueryStreamController.d.ts.map +1 -0
- package/dist/userRepository/relationship/follow/observers/getFollowings.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/observers/observeFollowers.d.ts +1 -1
- package/dist/userRepository/relationship/follow/observers/observeFollowers.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/observers/observeFollowings.d.ts +1 -1
- package/dist/userRepository/relationship/follow/observers/observeFollowings.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/utils.d.ts +4 -0
- package/dist/userRepository/relationship/follow/utils.d.ts.map +1 -0
- package/dist/userRepository/utils/convertRawUserToInternalUser.d.ts +2 -0
- package/dist/userRepository/utils/convertRawUserToInternalUser.d.ts.map +1 -0
- package/dist/userRepository/utils/prepareBlockedUserPayload.d.ts +2 -0
- package/dist/userRepository/utils/prepareBlockedUserPayload.d.ts.map +1 -0
- package/dist/userRepository/utils/prepareUserPayload.d.ts +2 -0
- package/dist/userRepository/utils/prepareUserPayload.d.ts.map +1 -0
- package/dist/utils/linkedObject/commentLinkedObject.d.ts.map +1 -1
- package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
- package/dist/utils/tests/dummy/block.d.ts +2 -2
- package/dist/utils/tests/dummy/follow.d.ts +2 -2
- package/package.json +1 -1
- package/src/@types/core/events.ts +40 -13
- package/src/@types/core/model.ts +1 -1
- package/src/@types/core/payload.ts +27 -7
- package/src/@types/core/permissions.ts +4 -4
- package/src/@types/domains/follow.ts +26 -12
- package/src/@types/domains/post.ts +3 -3
- package/src/@types/domains/user.ts +2 -2
- package/src/channelRepository/channelMembership/observers/getMembers/ChannelMemberLiveCollectionController.ts +4 -4
- package/src/channelRepository/channelMembership/observers/getMembers/ChannelMemberPaginationController.ts +4 -1
- package/src/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberLiveCollectionController.ts +6 -0
- package/src/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberPaginationController.ts +4 -1
- package/src/channelRepository/events/onUserDeleted.ts +46 -0
- package/src/channelRepository/utils/prepareChannelPayload.ts +1 -1
- package/src/commentRepository/api/createComment.ts +16 -12
- package/src/commentRepository/api/deleteComment.ts +23 -13
- package/src/commentRepository/events/onCommentCreatedLocal.ts +22 -0
- package/src/commentRepository/events/onCommentDeletedLocal.ts +20 -0
- package/src/commentRepository/events/onLocalCommentReactionAdded.ts +42 -0
- package/src/commentRepository/events/onLocalCommentReactionRemoved.ts +42 -0
- package/src/commentRepository/events/utils.ts +78 -1
- package/src/commentRepository/observers/getComment.ts +6 -19
- package/src/commentRepository/observers/getComments/CommentLiveCollectionController.ts +8 -0
- package/src/communityRepository/communityMembership/api/addMembers.ts +1 -1
- package/src/communityRepository/communityMembership/api/removeMembers.ts +1 -1
- package/src/communityRepository/communityMembership/events/index.ts +2 -0
- package/src/communityRepository/communityMembership/events/onLocalCommunityUserAdded.ts +20 -0
- package/src/communityRepository/communityMembership/events/onLocalCommunityUserRemoved.ts +20 -0
- package/src/communityRepository/communityMembership/events/onUserDeleted.ts +64 -0
- package/src/communityRepository/communityMembership/events/utils.ts +50 -2
- package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersLiveCollectionController.ts +24 -5
- package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersPaginationController.ts +4 -1
- package/src/communityRepository/communityMembership/observers/getMembers/enums.ts +3 -0
- package/src/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersLiveCollectionController.ts +12 -4
- package/src/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersPaginationController.ts +4 -1
- package/src/communityRepository/communityModeration/api/addRoles.ts +5 -2
- package/src/communityRepository/communityModeration/api/removeRoles.ts +5 -2
- package/src/communityRepository/communityModeration/events/onLocalCommunityRoleAdded.ts +38 -0
- package/src/communityRepository/communityModeration/events/onLocalCommunityRoleRemoved.ts +38 -0
- package/src/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.ts +3 -3
- package/src/communityRepository/utils/payload.ts +29 -0
- package/src/core/model/idResolvers.ts +1 -1
- package/src/postRepository/api/deletePost.ts +9 -9
- package/src/postRepository/api/updatePost.ts +1 -1
- package/src/postRepository/events/onLocalPostDeleted.ts +20 -0
- package/src/postRepository/events/onLocalPostReactionAdded.ts +38 -0
- package/src/postRepository/events/onLocalPostReactionRemoved.ts +41 -0
- package/src/postRepository/events/onPostUpdatedLocal.ts +20 -0
- package/src/postRepository/events/utils.ts +41 -6
- package/src/postRepository/internalApi/index.ts +1 -16
- package/src/postRepository/observers/getPost.ts +8 -0
- package/src/postRepository/observers/getPosts/PostLiveCollectionController.ts +8 -0
- package/src/postRepository/utils/payload.ts +10 -2
- package/src/reactionRepository/api/addReaction.ts +27 -2
- package/src/reactionRepository/api/removeReaction.ts +27 -2
- package/src/report/api/createReport.ts +1 -1
- package/src/report/api/deleteReport.ts +1 -1
- package/src/userRepository/api/flagUser.ts +1 -1
- package/src/userRepository/api/getUserByIds.ts +1 -1
- package/src/userRepository/api/queryBlockedUsers.ts +1 -1
- package/src/userRepository/api/unflagUser.ts +1 -1
- package/src/userRepository/api/updateUser.ts +1 -1
- package/src/userRepository/events/utils.ts +1 -1
- package/src/userRepository/internalApi/getUser.ts +1 -1
- package/src/userRepository/internalApi/queryUsers.ts +1 -1
- package/src/userRepository/observers/getBlockedUsers/BlockedUserLiveCollectionController.ts +106 -0
- package/src/userRepository/observers/getBlockedUsers/BlockedUserPaginationController.ts +24 -0
- package/src/userRepository/observers/getBlockedUsers/BlockedUserQueryStreamController.ts +76 -0
- package/src/userRepository/observers/getBlockedUsers.ts +8 -81
- package/src/userRepository/observers/getUsers/UserLiveCollectionController.ts +4 -4
- package/src/userRepository/observers/searchUserByDisplayName/SearchUserLiveCollectionController.ts +1 -1
- package/src/userRepository/relationship/block/api/blockUser.ts +4 -1
- package/src/userRepository/relationship/block/api/unBlockUser.ts +4 -1
- package/src/userRepository/relationship/follow/api/acceptFollower.ts +4 -1
- package/src/userRepository/relationship/follow/api/acceptMyFollower.ts +4 -1
- package/src/userRepository/relationship/follow/api/declineFollower.ts +5 -2
- package/src/userRepository/relationship/follow/api/declineMyFollower.ts +5 -2
- package/src/userRepository/relationship/follow/api/follow.ts +8 -1
- package/src/userRepository/relationship/follow/api/unfollow.ts +4 -1
- package/src/userRepository/relationship/follow/api/utils.ts +6 -2
- package/src/userRepository/relationship/follow/enums.ts +10 -0
- package/src/userRepository/relationship/follow/events/index.ts +6 -0
- package/src/userRepository/relationship/follow/events/onFollowInfoUpdated.ts +6 -1
- package/src/userRepository/relationship/follow/events/onFollowerUserDeleted.ts +33 -0
- package/src/userRepository/relationship/follow/events/onFollowingUserDeleted.ts +33 -0
- package/src/userRepository/relationship/follow/events/onLocalFollowRequestAccepted.ts +5 -0
- package/src/userRepository/relationship/follow/events/onLocalFollowRequestDeclined.ts +5 -0
- package/src/userRepository/relationship/follow/events/onLocalFollowerRequested.ts +5 -0
- package/src/userRepository/relationship/follow/events/onLocalUserFollowed.ts +5 -0
- package/src/userRepository/relationship/follow/events/onLocalUserUnfollowed.ts +5 -0
- package/src/userRepository/relationship/follow/events/utils.ts +25 -14
- package/src/userRepository/relationship/follow/observers/getFollowers/FollowerLiveCollectionController.ts +132 -0
- package/src/userRepository/relationship/follow/observers/getFollowers/FollowerPaginationController.ts +29 -0
- package/src/userRepository/relationship/follow/observers/getFollowers/FollowerQueryStreamController.ts +95 -0
- package/src/userRepository/relationship/follow/observers/getFollowers.ts +8 -106
- package/src/userRepository/relationship/follow/observers/getFollowings/FollowingLiveCollectionController.ts +136 -0
- package/src/userRepository/relationship/follow/observers/getFollowings/FollowingPaginationController.ts +29 -0
- package/src/userRepository/relationship/follow/observers/getFollowings/FollowingQueryStreamController.ts +95 -0
- package/src/userRepository/relationship/follow/observers/getFollowings.ts +6 -106
- package/src/userRepository/relationship/follow/observers/observeFollowers.ts +11 -0
- package/src/userRepository/relationship/follow/observers/observeFollowings.ts +11 -0
- package/src/userRepository/relationship/follow/utils.ts +36 -0
- package/src/userRepository/utils/convertRawUserToInternalUser.ts +6 -0
- package/src/userRepository/utils/prepareBlockedUserPayload.ts +19 -0
- package/src/userRepository/utils/{index.ts → prepareUserPayload.ts} +1 -6
- package/src/utils/linkedObject/commentLinkedObject.ts +13 -16
- package/src/utils/linkedObject/postLinkedObject.ts +0 -6
- package/dist/postRepository/internalApi/pinPost.d.ts +0 -6
- package/dist/postRepository/internalApi/pinPost.d.ts.map +0 -1
- package/dist/postRepository/internalApi/unpinPost.d.ts +0 -6
- package/dist/postRepository/internalApi/unpinPost.d.ts.map +0 -1
- package/dist/userRepository/utils/index.d.ts +0 -3
- package/dist/userRepository/utils/index.d.ts.map +0 -1
- package/src/postRepository/internalApi/pinPost.ts +0 -28
- package/src/postRepository/internalApi/unpinPost.ts +0 -28
package/dist/index.esm.js
CHANGED
|
@@ -525,7 +525,7 @@ const idResolvers = {
|
|
|
525
525
|
storyTarget: ({ targetId }) => targetId,
|
|
526
526
|
ad: ({ adId }) => adId,
|
|
527
527
|
advertiser: ({ advertiserId }) => advertiserId,
|
|
528
|
-
pin: ({ referenceId }) => referenceId
|
|
528
|
+
pin: ({ placement, referenceId }) => `${placement}#${referenceId}`,
|
|
529
529
|
pinTarget: ({ targetId }) => targetId,
|
|
530
530
|
};
|
|
531
531
|
/**
|
|
@@ -21482,6 +21482,80 @@ const categoryLinkedObject = (category) => {
|
|
|
21482
21482
|
} });
|
|
21483
21483
|
};
|
|
21484
21484
|
|
|
21485
|
+
/**
|
|
21486
|
+
* ```js
|
|
21487
|
+
* import { isEqual } from '~/utils/isEqual'
|
|
21488
|
+
* const isEqual = isEqual(post1, post2)
|
|
21489
|
+
* ```
|
|
21490
|
+
*
|
|
21491
|
+
* Compares two Amity.Model
|
|
21492
|
+
*
|
|
21493
|
+
* @param x the Amity.Model to compare
|
|
21494
|
+
* @param y the Amity.Model to compare wit x
|
|
21495
|
+
* @returns a boolean based on equality
|
|
21496
|
+
*
|
|
21497
|
+
* @category utility
|
|
21498
|
+
* @private
|
|
21499
|
+
*/
|
|
21500
|
+
function isEqual(x, y) {
|
|
21501
|
+
if (x === null || x === undefined || y === null || y === undefined) {
|
|
21502
|
+
return x === y;
|
|
21503
|
+
}
|
|
21504
|
+
// after this just checking type of one would be enough
|
|
21505
|
+
if (x.constructor !== y.constructor) {
|
|
21506
|
+
return false;
|
|
21507
|
+
}
|
|
21508
|
+
// if they are functions, they should exactly refer to same one (because of closures)
|
|
21509
|
+
if (x instanceof Function) {
|
|
21510
|
+
return x === y;
|
|
21511
|
+
}
|
|
21512
|
+
// if they are regexps, they should exactly refer to same one
|
|
21513
|
+
if (x instanceof RegExp) {
|
|
21514
|
+
return x === y;
|
|
21515
|
+
}
|
|
21516
|
+
if (x === y || x.valueOf() === y.valueOf()) {
|
|
21517
|
+
return true;
|
|
21518
|
+
}
|
|
21519
|
+
if (Array.isArray(x) && x.length !== y.length) {
|
|
21520
|
+
return false;
|
|
21521
|
+
}
|
|
21522
|
+
// check each element of the array for equality
|
|
21523
|
+
if (Array.isArray(x) && Array.isArray(y)) {
|
|
21524
|
+
if (x.length !== y.length)
|
|
21525
|
+
return false;
|
|
21526
|
+
for (let i = 0; i < x.length; i += 1) {
|
|
21527
|
+
if (!isEqual(x[i], y[i]))
|
|
21528
|
+
return false;
|
|
21529
|
+
}
|
|
21530
|
+
// if all elements are equal, the arrays are equal
|
|
21531
|
+
return true;
|
|
21532
|
+
}
|
|
21533
|
+
// if they are dates, they must had equal valueOf
|
|
21534
|
+
if (x instanceof Date) {
|
|
21535
|
+
return false;
|
|
21536
|
+
}
|
|
21537
|
+
// if they are strictly equal, they both need to be object at least
|
|
21538
|
+
if (!(x instanceof Object)) {
|
|
21539
|
+
return false;
|
|
21540
|
+
}
|
|
21541
|
+
if (!(y instanceof Object)) {
|
|
21542
|
+
return false;
|
|
21543
|
+
}
|
|
21544
|
+
// recursive object equality check
|
|
21545
|
+
const p = Object.keys(x);
|
|
21546
|
+
return (Object.keys(y).every(i => {
|
|
21547
|
+
// @ts-ignore
|
|
21548
|
+
return p.indexOf(i) !== -1;
|
|
21549
|
+
}) &&
|
|
21550
|
+
p.every(i => {
|
|
21551
|
+
return isEqual(x[i], y[i]);
|
|
21552
|
+
}));
|
|
21553
|
+
}
|
|
21554
|
+
|
|
21555
|
+
function isNonNullable(value) {
|
|
21556
|
+
return value != null;
|
|
21557
|
+
}
|
|
21558
|
+
|
|
21485
21559
|
const commentLinkedObject = (comment) => {
|
|
21486
21560
|
return Object.assign(Object.assign({}, comment), { get target() {
|
|
21487
21561
|
const commentTypes = {
|
|
@@ -21512,7 +21586,7 @@ const commentLinkedObject = (comment) => {
|
|
|
21512
21586
|
return undefined;
|
|
21513
21587
|
},
|
|
21514
21588
|
get childrenComment() {
|
|
21515
|
-
return
|
|
21589
|
+
return comment.children
|
|
21516
21590
|
.map(childCommentId => {
|
|
21517
21591
|
const commentCache = pullFromCache([
|
|
21518
21592
|
'comment',
|
|
@@ -21523,46 +21597,18 @@ const commentLinkedObject = (comment) => {
|
|
|
21523
21597
|
return;
|
|
21524
21598
|
return commentCache === null || commentCache === void 0 ? void 0 : commentCache.data;
|
|
21525
21599
|
})
|
|
21526
|
-
.filter(
|
|
21527
|
-
|
|
21528
|
-
// TS always alert returned value is possibly undefined
|
|
21529
|
-
.map(item => commentLinkedObject(item)));
|
|
21600
|
+
.filter(isNonNullable)
|
|
21601
|
+
.map(item => commentLinkedObject(item));
|
|
21530
21602
|
} });
|
|
21531
21603
|
};
|
|
21532
21604
|
|
|
21533
|
-
const pinPost = async ({ communityId, placement, postId, }) => {
|
|
21534
|
-
const client = getActiveClient();
|
|
21535
|
-
client.log('post/getPost', postId);
|
|
21536
|
-
const { data } = await client.http.post(`/api/v1/pinned-posts/communities/${communityId}/${placement}/${postId}`);
|
|
21537
|
-
const cachedAt = client.cache && Date.now();
|
|
21538
|
-
if (client.cache)
|
|
21539
|
-
ingestInCache(data, { cachedAt });
|
|
21540
|
-
return {
|
|
21541
|
-
data,
|
|
21542
|
-
cachedAt,
|
|
21543
|
-
};
|
|
21544
|
-
};
|
|
21545
|
-
|
|
21546
|
-
const unpinPost = async ({ communityId, placement, postId, }) => {
|
|
21547
|
-
const client = getActiveClient();
|
|
21548
|
-
client.log('post/getPost', postId);
|
|
21549
|
-
const { data } = await client.http.delete(`/api/v1/pinned-posts/communities/${communityId}/${placement}/${postId}`);
|
|
21550
|
-
const cachedAt = client.cache && Date.now();
|
|
21551
|
-
if (client.cache)
|
|
21552
|
-
ingestInCache(data, { cachedAt });
|
|
21553
|
-
return {
|
|
21554
|
-
data,
|
|
21555
|
-
cachedAt,
|
|
21556
|
-
};
|
|
21557
|
-
};
|
|
21558
|
-
|
|
21559
21605
|
const postLinkedObject = (post) => {
|
|
21560
21606
|
return Object.assign(Object.assign({}, post), { analytics: {
|
|
21561
21607
|
markAsViewed: () => {
|
|
21562
21608
|
const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
|
|
21563
21609
|
analyticsEngineInstance.markPostAsViewed(post.postId);
|
|
21564
21610
|
},
|
|
21565
|
-
},
|
|
21611
|
+
}, get latestComments() {
|
|
21566
21612
|
if (!post.comments)
|
|
21567
21613
|
return [];
|
|
21568
21614
|
return (post.comments
|
|
@@ -22382,13 +22428,7 @@ const getChannelIsMentioned = (channel, marker) => {
|
|
|
22382
22428
|
};
|
|
22383
22429
|
|
|
22384
22430
|
function convertRawUserToInternalUser(rawUser) {
|
|
22385
|
-
return Object.assign(Object.assign({}, rawUser), { isGlobalBanned: rawUser.isGlobalBan });
|
|
22386
|
-
}
|
|
22387
|
-
function prepareUserPayload(response) {
|
|
22388
|
-
return {
|
|
22389
|
-
users: response.users.map(convertRawUserToInternalUser),
|
|
22390
|
-
files: response.files,
|
|
22391
|
-
};
|
|
22431
|
+
return Object.assign(Object.assign({}, rawUser), { isGlobalBanned: (rawUser === null || rawUser === void 0 ? void 0 : rawUser.isGlobalBan) || false });
|
|
22392
22432
|
}
|
|
22393
22433
|
|
|
22394
22434
|
const MARKER_INCLUDED_CHANNEL_TYPE = ['broadcast', 'conversation', 'community'];
|
|
@@ -23876,6 +23916,13 @@ const onChannelMemberBanned = (callback) => {
|
|
|
23876
23916
|
return createEventSubscriber(client, 'onChannelMemberBanned', 'channel.banned', filter);
|
|
23877
23917
|
};
|
|
23878
23918
|
|
|
23919
|
+
function prepareUserPayload(response) {
|
|
23920
|
+
return {
|
|
23921
|
+
users: response.users.map(convertRawUserToInternalUser),
|
|
23922
|
+
files: response.files,
|
|
23923
|
+
};
|
|
23924
|
+
}
|
|
23925
|
+
|
|
23879
23926
|
const createUserEventSubscriber = (event, callback) => {
|
|
23880
23927
|
const client = getActiveClient();
|
|
23881
23928
|
const filter = (data) => {
|
|
@@ -23903,7 +23950,7 @@ const createUserEventSubscriber = (event, callback) => {
|
|
|
23903
23950
|
*
|
|
23904
23951
|
* @category User Events
|
|
23905
23952
|
*/
|
|
23906
|
-
const onUserDeleted = (callback) => createUserEventSubscriber('user.deleted', callback);
|
|
23953
|
+
const onUserDeleted$2 = (callback) => createUserEventSubscriber('user.deleted', callback);
|
|
23907
23954
|
|
|
23908
23955
|
var analyticsEngineOnLoginHandler = () => {
|
|
23909
23956
|
const analyticsEngine = AnalyticsEngine$1.getInstance();
|
|
@@ -25165,7 +25212,7 @@ const login = async (params, sessionHandler, config) => {
|
|
|
25165
25212
|
terminateClient();
|
|
25166
25213
|
subscriptions.forEach(fn => fn());
|
|
25167
25214
|
unsubWatcher();
|
|
25168
|
-
}), onUserDeleted((user) => {
|
|
25215
|
+
}), onUserDeleted$2((user) => {
|
|
25169
25216
|
if (user.userId === client.userId) {
|
|
25170
25217
|
terminateClient("userDeleted" /* Amity.TokenTerminationReason.USER_DELETED */);
|
|
25171
25218
|
subscriptions.forEach(fn => fn());
|
|
@@ -25717,76 +25764,6 @@ const removeFunctionProperties = (obj) => {
|
|
|
25717
25764
|
return Object.fromEntries(entries);
|
|
25718
25765
|
};
|
|
25719
25766
|
|
|
25720
|
-
/**
|
|
25721
|
-
* ```js
|
|
25722
|
-
* import { isEqual } from '~/utils/isEqual'
|
|
25723
|
-
* const isEqual = isEqual(post1, post2)
|
|
25724
|
-
* ```
|
|
25725
|
-
*
|
|
25726
|
-
* Compares two Amity.Model
|
|
25727
|
-
*
|
|
25728
|
-
* @param x the Amity.Model to compare
|
|
25729
|
-
* @param y the Amity.Model to compare wit x
|
|
25730
|
-
* @returns a boolean based on equality
|
|
25731
|
-
*
|
|
25732
|
-
* @category utility
|
|
25733
|
-
* @private
|
|
25734
|
-
*/
|
|
25735
|
-
function isEqual(x, y) {
|
|
25736
|
-
if (x === null || x === undefined || y === null || y === undefined) {
|
|
25737
|
-
return x === y;
|
|
25738
|
-
}
|
|
25739
|
-
// after this just checking type of one would be enough
|
|
25740
|
-
if (x.constructor !== y.constructor) {
|
|
25741
|
-
return false;
|
|
25742
|
-
}
|
|
25743
|
-
// if they are functions, they should exactly refer to same one (because of closures)
|
|
25744
|
-
if (x instanceof Function) {
|
|
25745
|
-
return x === y;
|
|
25746
|
-
}
|
|
25747
|
-
// if they are regexps, they should exactly refer to same one
|
|
25748
|
-
if (x instanceof RegExp) {
|
|
25749
|
-
return x === y;
|
|
25750
|
-
}
|
|
25751
|
-
if (x === y || x.valueOf() === y.valueOf()) {
|
|
25752
|
-
return true;
|
|
25753
|
-
}
|
|
25754
|
-
if (Array.isArray(x) && x.length !== y.length) {
|
|
25755
|
-
return false;
|
|
25756
|
-
}
|
|
25757
|
-
// check each element of the array for equality
|
|
25758
|
-
if (Array.isArray(x) && Array.isArray(y)) {
|
|
25759
|
-
if (x.length !== y.length)
|
|
25760
|
-
return false;
|
|
25761
|
-
for (let i = 0; i < x.length; i += 1) {
|
|
25762
|
-
if (!isEqual(x[i], y[i]))
|
|
25763
|
-
return false;
|
|
25764
|
-
}
|
|
25765
|
-
// if all elements are equal, the arrays are equal
|
|
25766
|
-
return true;
|
|
25767
|
-
}
|
|
25768
|
-
// if they are dates, they must had equal valueOf
|
|
25769
|
-
if (x instanceof Date) {
|
|
25770
|
-
return false;
|
|
25771
|
-
}
|
|
25772
|
-
// if they are strictly equal, they both need to be object at least
|
|
25773
|
-
if (!(x instanceof Object)) {
|
|
25774
|
-
return false;
|
|
25775
|
-
}
|
|
25776
|
-
if (!(y instanceof Object)) {
|
|
25777
|
-
return false;
|
|
25778
|
-
}
|
|
25779
|
-
// recursive object equality check
|
|
25780
|
-
const p = Object.keys(x);
|
|
25781
|
-
return (Object.keys(y).every(i => {
|
|
25782
|
-
// @ts-ignore
|
|
25783
|
-
return p.indexOf(i) !== -1;
|
|
25784
|
-
}) &&
|
|
25785
|
-
p.every(i => {
|
|
25786
|
-
return isEqual(x[i], y[i]);
|
|
25787
|
-
}));
|
|
25788
|
-
}
|
|
25789
|
-
|
|
25790
25767
|
/**
|
|
25791
25768
|
* @deprecated This function is deprecated
|
|
25792
25769
|
*/
|
|
@@ -26023,6 +26000,19 @@ var index$l = /*#__PURE__*/Object.freeze({
|
|
|
26023
26000
|
getMarkerSyncConsistentMode: getMarkerSyncConsistentMode
|
|
26024
26001
|
});
|
|
26025
26002
|
|
|
26003
|
+
function prepareFollowersPayload(response) {
|
|
26004
|
+
const { users, follows } = response, rest = __rest(response, ["users", "follows"]);
|
|
26005
|
+
return Object.assign(Object.assign({}, rest), { follows, users: users.map(convertRawUserToInternalUser) });
|
|
26006
|
+
}
|
|
26007
|
+
function prepareFollowingsPayload(response) {
|
|
26008
|
+
const { users, follows } = response, rest = __rest(response, ["users", "follows"]);
|
|
26009
|
+
return Object.assign(Object.assign({}, rest), { follows, users: users.map(convertRawUserToInternalUser) });
|
|
26010
|
+
}
|
|
26011
|
+
function prepareFollowStatusPayload(response) {
|
|
26012
|
+
const { follows } = response, rest = __rest(response, ["follows"]);
|
|
26013
|
+
return Object.assign(Object.assign({}, rest), { follows });
|
|
26014
|
+
}
|
|
26015
|
+
|
|
26026
26016
|
/* begin_public_function
|
|
26027
26017
|
id: user.relationship.block
|
|
26028
26018
|
*/
|
|
@@ -26051,7 +26041,8 @@ const blockUser = async (userId) => {
|
|
|
26051
26041
|
ingestInCache(followStatus, { cachedAt });
|
|
26052
26042
|
upsertInCache(['followInfo', 'get', userId], followCounts[0], { cachedAt });
|
|
26053
26043
|
}
|
|
26054
|
-
|
|
26044
|
+
const payload = prepareFollowStatusPayload(followStatus);
|
|
26045
|
+
fireEvent('local.follow.unfollowed', payload);
|
|
26055
26046
|
return data;
|
|
26056
26047
|
};
|
|
26057
26048
|
/* end_public_function */
|
|
@@ -26084,170 +26075,397 @@ const unBlockUser = async (userId) => {
|
|
|
26084
26075
|
ingestInCache(followStatus, { cachedAt });
|
|
26085
26076
|
upsertInCache(['followInfo', 'get', userId], followCounts[0], { cachedAt });
|
|
26086
26077
|
}
|
|
26087
|
-
|
|
26078
|
+
const payload = prepareFollowStatusPayload(followStatus);
|
|
26079
|
+
fireEvent('local.follow.created', payload);
|
|
26088
26080
|
return data;
|
|
26089
26081
|
};
|
|
26090
26082
|
/* end_public_function */
|
|
26091
26083
|
|
|
26084
|
+
class PaginationController {
|
|
26085
|
+
constructor(queryParams) {
|
|
26086
|
+
const { http } = getActiveClient();
|
|
26087
|
+
this.queryParams = queryParams;
|
|
26088
|
+
this.http = http;
|
|
26089
|
+
}
|
|
26090
|
+
loadFirstPage() {
|
|
26091
|
+
return this.onFetch("first" /* Amity.LiveCollectionPageDirection.FIRST */);
|
|
26092
|
+
}
|
|
26093
|
+
loadNextPage() {
|
|
26094
|
+
return this.onFetch("next" /* Amity.LiveCollectionPageDirection.NEXT */);
|
|
26095
|
+
}
|
|
26096
|
+
loadPreviousPage() {
|
|
26097
|
+
return this.onFetch("prev" /* Amity.LiveCollectionPageDirection.PREV */);
|
|
26098
|
+
}
|
|
26099
|
+
async onFetch(direction = "first" /* Amity.LiveCollectionPageDirection.FIRST */) {
|
|
26100
|
+
var _a, _b, _c, _d;
|
|
26101
|
+
if (direction === 'prev' && !this.previousToken)
|
|
26102
|
+
return;
|
|
26103
|
+
if (direction === 'next' && !this.nextToken)
|
|
26104
|
+
return;
|
|
26105
|
+
let token;
|
|
26106
|
+
if (direction === 'prev')
|
|
26107
|
+
token = this.previousToken;
|
|
26108
|
+
if (direction === 'next')
|
|
26109
|
+
token = this.nextToken;
|
|
26110
|
+
const queryResponse = await this.getRequest(this.queryParams, token);
|
|
26111
|
+
if (direction === 'first') {
|
|
26112
|
+
this.nextToken = (_a = queryResponse.paging) === null || _a === void 0 ? void 0 : _a.next;
|
|
26113
|
+
this.previousToken = (_b = queryResponse.paging) === null || _b === void 0 ? void 0 : _b.previous;
|
|
26114
|
+
}
|
|
26115
|
+
if (direction === 'prev')
|
|
26116
|
+
this.previousToken = (_c = queryResponse.paging) === null || _c === void 0 ? void 0 : _c.previous;
|
|
26117
|
+
if (direction === 'next')
|
|
26118
|
+
this.nextToken = (_d = queryResponse.paging) === null || _d === void 0 ? void 0 : _d.next;
|
|
26119
|
+
return queryResponse;
|
|
26120
|
+
}
|
|
26121
|
+
getNextToken() {
|
|
26122
|
+
return this.nextToken;
|
|
26123
|
+
}
|
|
26124
|
+
getPrevToken() {
|
|
26125
|
+
return this.previousToken;
|
|
26126
|
+
}
|
|
26127
|
+
}
|
|
26128
|
+
|
|
26129
|
+
class BlockedUserPaginationController extends PaginationController {
|
|
26130
|
+
async getRequest(queryParams, token) {
|
|
26131
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
26132
|
+
const options = token ? { token } : { limit };
|
|
26133
|
+
const { data: queryResponse } = await this.http.get('/api/v4/me/user-blocks', {
|
|
26134
|
+
params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
|
|
26135
|
+
});
|
|
26136
|
+
return queryResponse;
|
|
26137
|
+
}
|
|
26138
|
+
}
|
|
26139
|
+
|
|
26140
|
+
class QueryStreamController {
|
|
26141
|
+
constructor(query, cacheKey) {
|
|
26142
|
+
this.query = query;
|
|
26143
|
+
this.cacheKey = cacheKey;
|
|
26144
|
+
}
|
|
26145
|
+
}
|
|
26146
|
+
|
|
26147
|
+
class BlockedUserQueryStreamController extends QueryStreamController {
|
|
26148
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
26149
|
+
super(query, cacheKey);
|
|
26150
|
+
this.notifyChange = notifyChange;
|
|
26151
|
+
this.preparePayload = preparePayload;
|
|
26152
|
+
}
|
|
26153
|
+
async saveToMainDB(response) {
|
|
26154
|
+
const processedPayload = await this.preparePayload(response);
|
|
26155
|
+
const client = getActiveClient();
|
|
26156
|
+
const cachedAt = client.cache && Date.now();
|
|
26157
|
+
if (client.cache) {
|
|
26158
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
26159
|
+
}
|
|
26160
|
+
}
|
|
26161
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
26162
|
+
var _a, _b;
|
|
26163
|
+
if (refresh) {
|
|
26164
|
+
pushToCache(this.cacheKey, {
|
|
26165
|
+
data: response.users.map(getResolver('user')),
|
|
26166
|
+
});
|
|
26167
|
+
}
|
|
26168
|
+
else {
|
|
26169
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
26170
|
+
const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
26171
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...users, ...response.users.map(getResolver('user'))])] }));
|
|
26172
|
+
}
|
|
26173
|
+
}
|
|
26174
|
+
reactor(action) {
|
|
26175
|
+
return (followStatus) => {
|
|
26176
|
+
var _a;
|
|
26177
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
26178
|
+
pushToCache(this.cacheKey, collection);
|
|
26179
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
26180
|
+
};
|
|
26181
|
+
}
|
|
26182
|
+
subscribeRTE(createSubscriber) {
|
|
26183
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
26184
|
+
}
|
|
26185
|
+
}
|
|
26186
|
+
|
|
26187
|
+
class PaginationNoPageController {
|
|
26188
|
+
constructor(queryParams) {
|
|
26189
|
+
const { http } = getActiveClient();
|
|
26190
|
+
this.queryParams = queryParams;
|
|
26191
|
+
this.http = http;
|
|
26192
|
+
}
|
|
26193
|
+
async onFetch() {
|
|
26194
|
+
const queryResponse = await this.getRequest(this.queryParams);
|
|
26195
|
+
return queryResponse;
|
|
26196
|
+
}
|
|
26197
|
+
}
|
|
26198
|
+
|
|
26199
|
+
class LiveCollectionController {
|
|
26200
|
+
constructor(paginationController, queryStreamId, cacheKey, callback) {
|
|
26201
|
+
this.paginationController = paginationController;
|
|
26202
|
+
this.queryStreamId = queryStreamId;
|
|
26203
|
+
this.cacheKey = cacheKey;
|
|
26204
|
+
this.callback = callback;
|
|
26205
|
+
}
|
|
26206
|
+
async refresh() {
|
|
26207
|
+
try {
|
|
26208
|
+
let result;
|
|
26209
|
+
if (this.paginationController instanceof PaginationNoPageController) {
|
|
26210
|
+
result = await this.paginationController.onFetch();
|
|
26211
|
+
}
|
|
26212
|
+
else {
|
|
26213
|
+
result = await this.paginationController.loadFirstPage();
|
|
26214
|
+
}
|
|
26215
|
+
if (!result)
|
|
26216
|
+
return;
|
|
26217
|
+
await this.persistModel(result);
|
|
26218
|
+
this.persistQueryStream({
|
|
26219
|
+
response: result,
|
|
26220
|
+
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
26221
|
+
refresh: true,
|
|
26222
|
+
});
|
|
26223
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
26224
|
+
}
|
|
26225
|
+
catch (e) {
|
|
26226
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
26227
|
+
}
|
|
26228
|
+
}
|
|
26229
|
+
loadPage({ initial = false, direction = "next" /* Amity.LiveCollectionPageDirection.NEXT */, }) {
|
|
26230
|
+
this.setup();
|
|
26231
|
+
this.notifyChange({ origin: "local" /* Amity.LiveDataOrigin.LOCAL */, loading: true });
|
|
26232
|
+
if (initial) {
|
|
26233
|
+
this.refresh();
|
|
26234
|
+
}
|
|
26235
|
+
else if (direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */) {
|
|
26236
|
+
this.loadPrevPage();
|
|
26237
|
+
}
|
|
26238
|
+
else if (direction === "next" /* Amity.LiveCollectionPageDirection.NEXT */) {
|
|
26239
|
+
this.loadNextPage();
|
|
26240
|
+
}
|
|
26241
|
+
}
|
|
26242
|
+
async loadNextPage() {
|
|
26243
|
+
try {
|
|
26244
|
+
if (this.paginationController instanceof PaginationNoPageController)
|
|
26245
|
+
return;
|
|
26246
|
+
const result = await this.paginationController.loadNextPage();
|
|
26247
|
+
if (!result)
|
|
26248
|
+
return;
|
|
26249
|
+
await this.persistModel(result);
|
|
26250
|
+
this.persistQueryStream({
|
|
26251
|
+
response: result,
|
|
26252
|
+
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
26253
|
+
});
|
|
26254
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
26255
|
+
}
|
|
26256
|
+
catch (e) {
|
|
26257
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
26258
|
+
}
|
|
26259
|
+
}
|
|
26260
|
+
async loadPrevPage() {
|
|
26261
|
+
try {
|
|
26262
|
+
if (this.paginationController instanceof PaginationNoPageController)
|
|
26263
|
+
return;
|
|
26264
|
+
const result = await this.paginationController.loadPreviousPage();
|
|
26265
|
+
if (!result)
|
|
26266
|
+
return;
|
|
26267
|
+
await this.persistModel(result);
|
|
26268
|
+
this.persistQueryStream({
|
|
26269
|
+
response: result,
|
|
26270
|
+
direction: "prev" /* Amity.LiveCollectionPageDirection.PREV */,
|
|
26271
|
+
});
|
|
26272
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
26273
|
+
}
|
|
26274
|
+
catch (e) {
|
|
26275
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
26276
|
+
}
|
|
26277
|
+
}
|
|
26278
|
+
shouldNotify(data) {
|
|
26279
|
+
const newData = data.map(convertGetterPropsToStatic).map(removeFunctionProperties);
|
|
26280
|
+
if (isEqual(this.snapshot, newData))
|
|
26281
|
+
return false;
|
|
26282
|
+
this.snapshot = newData;
|
|
26283
|
+
return true;
|
|
26284
|
+
}
|
|
26285
|
+
getCacheKey() {
|
|
26286
|
+
return this.cacheKey;
|
|
26287
|
+
}
|
|
26288
|
+
}
|
|
26289
|
+
|
|
26290
|
+
function prepareBlockedUserPayload(response) {
|
|
26291
|
+
const { users, follows } = response, rest = __rest(response, ["users", "follows"]);
|
|
26292
|
+
return Object.assign(Object.assign({}, rest), { follows: follows.map(follow => {
|
|
26293
|
+
const followUser = users.find(user => user.userId === follow.from);
|
|
26294
|
+
return Object.assign(Object.assign({}, follow), { user: convertRawUserToInternalUser(followUser) });
|
|
26295
|
+
}), users: users.map(convertRawUserToInternalUser) });
|
|
26296
|
+
}
|
|
26297
|
+
|
|
26092
26298
|
/**
|
|
26093
26299
|
* ```js
|
|
26094
|
-
* import {
|
|
26095
|
-
* const
|
|
26300
|
+
* import { onUserUpdated } from '@amityco/ts-sdk'
|
|
26301
|
+
* const dispose = onUserUpdated(user => {
|
|
26302
|
+
* // ...
|
|
26303
|
+
* })
|
|
26096
26304
|
* ```
|
|
26097
26305
|
*
|
|
26098
|
-
* @
|
|
26099
|
-
* @returns A page of {@link Amity.User} objects
|
|
26306
|
+
* Fired when a {@link Amity.InternalUser} has been updated
|
|
26100
26307
|
*
|
|
26101
|
-
* @
|
|
26102
|
-
* @
|
|
26308
|
+
* @param callback The function to call when the event was fired
|
|
26309
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26310
|
+
*
|
|
26311
|
+
* @category User Events
|
|
26103
26312
|
*/
|
|
26104
|
-
const
|
|
26105
|
-
|
|
26106
|
-
let params = {};
|
|
26107
|
-
if (query) {
|
|
26108
|
-
const { token, limit } = query;
|
|
26109
|
-
params = {
|
|
26110
|
-
limit,
|
|
26111
|
-
token,
|
|
26112
|
-
};
|
|
26113
|
-
}
|
|
26114
|
-
client.log('user/queryBlockedUsers');
|
|
26115
|
-
const { data } = await client.http.get('/api/v4/me/user-blocks', {
|
|
26116
|
-
params,
|
|
26117
|
-
});
|
|
26118
|
-
const payload = prepareUserPayload(data);
|
|
26119
|
-
const cachedAt = client.cache && Date.now();
|
|
26120
|
-
if (client.cache) {
|
|
26121
|
-
ingestInCache(payload, { cachedAt });
|
|
26122
|
-
const cacheKey = ['blockedUsers', 'query', params];
|
|
26123
|
-
pushToCache(cacheKey, { users: payload.users.map(getResolver('user')), paging: data.paging });
|
|
26124
|
-
}
|
|
26125
|
-
const { next, previous, total } = data.paging;
|
|
26126
|
-
const nextPage = toPageRaw(next);
|
|
26127
|
-
const prevPage = toPageRaw(previous);
|
|
26128
|
-
return { data: payload.users, prevPage, nextPage, total, cachedAt };
|
|
26129
|
-
};
|
|
26313
|
+
const onUserUpdated = (callback) => createUserEventSubscriber('user.updated', callback);
|
|
26314
|
+
|
|
26130
26315
|
/**
|
|
26131
26316
|
* ```js
|
|
26132
|
-
* import {
|
|
26133
|
-
* const
|
|
26317
|
+
* import { onUserFlagged } from '@amityco/ts-sdk'
|
|
26318
|
+
* const dispose = onUserFlagged(user => {
|
|
26319
|
+
* // ...
|
|
26320
|
+
* })
|
|
26134
26321
|
* ```
|
|
26135
26322
|
*
|
|
26136
|
-
*
|
|
26137
|
-
* Search is performed by displayName such as `.startsWith(search)`
|
|
26323
|
+
* Fired when a {@link Amity.InternalUser} has been flagged
|
|
26138
26324
|
*
|
|
26139
|
-
* @param
|
|
26140
|
-
* @returns
|
|
26325
|
+
* @param callback The function to call when the event was fired
|
|
26326
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26141
26327
|
*
|
|
26142
|
-
* @category
|
|
26328
|
+
* @category User Events
|
|
26143
26329
|
*/
|
|
26144
|
-
|
|
26145
|
-
var _a, _b, _c;
|
|
26146
|
-
const client = getActiveClient();
|
|
26147
|
-
client.log('user/queryBlockedUsers.locally');
|
|
26148
|
-
if (!client.cache)
|
|
26149
|
-
return;
|
|
26150
|
-
let params = {};
|
|
26151
|
-
if (query) {
|
|
26152
|
-
const { token, limit } = query;
|
|
26153
|
-
params = {
|
|
26154
|
-
token,
|
|
26155
|
-
limit,
|
|
26156
|
-
};
|
|
26157
|
-
}
|
|
26158
|
-
const cacheKey = ['blockedUsers', 'query', params];
|
|
26159
|
-
const { data, cachedAt } = (_a = pullFromCache(cacheKey)) !== null && _a !== void 0 ? _a : {};
|
|
26160
|
-
const users = (_b = data === null || data === void 0 ? void 0 : data.users.map(userId => pullFromCache(['user', 'get', userId])).filter(Boolean).map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
|
|
26161
|
-
const nextPage = toPageRaw(data === null || data === void 0 ? void 0 : data.paging.next);
|
|
26162
|
-
const prevPage = toPageRaw(data === null || data === void 0 ? void 0 : data.paging.previous);
|
|
26163
|
-
return users.length > 0 && users.length === ((_c = data === null || data === void 0 ? void 0 : data.users) === null || _c === void 0 ? void 0 : _c.length)
|
|
26164
|
-
? { data: users, nextPage, prevPage, total: data === null || data === void 0 ? void 0 : data.paging.total, cachedAt }
|
|
26165
|
-
: undefined;
|
|
26166
|
-
};
|
|
26330
|
+
const onUserFlagged = (callback) => createUserEventSubscriber('user.flagged', callback);
|
|
26167
26331
|
|
|
26168
|
-
/* eslint-disable no-use-before-define */
|
|
26169
|
-
/* begin_public_function
|
|
26170
|
-
id: user.get_blocked_users
|
|
26171
|
-
*/
|
|
26172
26332
|
/**
|
|
26173
26333
|
* ```js
|
|
26174
|
-
* import {
|
|
26175
|
-
* const
|
|
26334
|
+
* import { onUserUnflagged } from '@amityco/ts-sdk'
|
|
26335
|
+
* const dispose = onUserUnflagged(user => {
|
|
26336
|
+
* // ...
|
|
26337
|
+
* })
|
|
26176
26338
|
* ```
|
|
26177
26339
|
*
|
|
26178
|
-
*
|
|
26340
|
+
* Fired when a flag has been removed from a {@link Amity.InternalUser}
|
|
26179
26341
|
*
|
|
26180
|
-
* @param
|
|
26181
|
-
* @
|
|
26182
|
-
* @returns {@link Amity.Unsubscriber} to unsubscribe from collection
|
|
26342
|
+
* @param callback The function to call when the event was fired
|
|
26343
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26183
26344
|
*
|
|
26184
|
-
* @category
|
|
26185
|
-
* @async
|
|
26345
|
+
* @category User Events
|
|
26186
26346
|
*/
|
|
26187
|
-
const
|
|
26188
|
-
|
|
26189
|
-
|
|
26190
|
-
|
|
26347
|
+
const onUserUnflagged = (callback) => createUserEventSubscriber('user.unflagged', callback);
|
|
26348
|
+
|
|
26349
|
+
/**
|
|
26350
|
+
* ```js
|
|
26351
|
+
* import { onUserFlagCleared } from '@amityco/ts-sdk'
|
|
26352
|
+
* const dispose = onUserFlagCleared(user => {
|
|
26353
|
+
* // ...
|
|
26354
|
+
* })
|
|
26355
|
+
* ```
|
|
26356
|
+
*
|
|
26357
|
+
* Fired when flags have been cleared for a {@link Amity.InternalUser}
|
|
26358
|
+
*
|
|
26359
|
+
* @param callback The function to call when the event was fired
|
|
26360
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26361
|
+
*
|
|
26362
|
+
* @category User Events
|
|
26363
|
+
*/
|
|
26364
|
+
const onUserFlagCleared = (callback) => createUserEventSubscriber('user.flagCleared', callback);
|
|
26365
|
+
|
|
26366
|
+
var EnumUserActions;
|
|
26367
|
+
(function (EnumUserActions) {
|
|
26368
|
+
EnumUserActions["OnUserDeleted"] = "onUserDeleted";
|
|
26369
|
+
EnumUserActions["OnUserUpdated"] = "onUserUpdated";
|
|
26370
|
+
EnumUserActions["OnUserFlagged"] = "onUserFlagged";
|
|
26371
|
+
EnumUserActions["OnUserUnflagged"] = "onUserUnflagged";
|
|
26372
|
+
EnumUserActions["OnUserFlagCleared"] = "onUserFlagCleared";
|
|
26373
|
+
})(EnumUserActions || (EnumUserActions = {}));
|
|
26374
|
+
|
|
26375
|
+
class BlockedUserLiveCollectionController extends LiveCollectionController {
|
|
26376
|
+
constructor(query, callback) {
|
|
26377
|
+
const queryStreamId = hash(query);
|
|
26378
|
+
const cacheKey = ['blockedUsers', 'collection', queryStreamId];
|
|
26379
|
+
const paginationController = new BlockedUserPaginationController(query);
|
|
26380
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
26381
|
+
this.query = query;
|
|
26382
|
+
this.queryStreamController = new BlockedUserQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareBlockedUserPayload);
|
|
26383
|
+
this.callback = callback.bind(this);
|
|
26384
|
+
this.loadPage({ initial: true });
|
|
26191
26385
|
}
|
|
26192
|
-
|
|
26193
|
-
|
|
26194
|
-
|
|
26195
|
-
|
|
26196
|
-
|
|
26197
|
-
|
|
26198
|
-
|
|
26199
|
-
|
|
26200
|
-
|
|
26201
|
-
|
|
26202
|
-
|
|
26203
|
-
|
|
26204
|
-
|
|
26205
|
-
|
|
26206
|
-
|
|
26207
|
-
|
|
26208
|
-
|
|
26209
|
-
|
|
26210
|
-
|
|
26211
|
-
|
|
26212
|
-
|
|
26213
|
-
|
|
26214
|
-
|
|
26215
|
-
|
|
26216
|
-
|
|
26217
|
-
*};
|
|
26218
|
-
*/
|
|
26219
|
-
const onFetch = (initial = false) => {
|
|
26386
|
+
setup() {
|
|
26387
|
+
var _a;
|
|
26388
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
26389
|
+
if (!collection) {
|
|
26390
|
+
pushToCache(this.cacheKey, {
|
|
26391
|
+
data: [],
|
|
26392
|
+
params: {},
|
|
26393
|
+
});
|
|
26394
|
+
}
|
|
26395
|
+
}
|
|
26396
|
+
async persistModel(queryPayload) {
|
|
26397
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
26398
|
+
}
|
|
26399
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
26400
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
26401
|
+
}
|
|
26402
|
+
startSubscription() {
|
|
26403
|
+
return this.queryStreamController.subscribeRTE([
|
|
26404
|
+
{
|
|
26405
|
+
fn: onUserDeleted$2,
|
|
26406
|
+
action: EnumUserActions.OnUserDeleted,
|
|
26407
|
+
},
|
|
26408
|
+
]);
|
|
26409
|
+
}
|
|
26410
|
+
notifyChange({ origin, loading, error }) {
|
|
26220
26411
|
var _a, _b;
|
|
26221
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
26222
|
-
|
|
26223
|
-
if (!initial && users.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
|
|
26412
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
26413
|
+
if (!collection)
|
|
26224
26414
|
return;
|
|
26225
|
-
const
|
|
26226
|
-
|
|
26227
|
-
|
|
26415
|
+
const data = this.applyFilter((_b = collection.data
|
|
26416
|
+
.map(id => pullFromCache(['user', 'get', id]))
|
|
26417
|
+
.filter(isNonNullable)
|
|
26418
|
+
.map(({ data }) => data)
|
|
26419
|
+
.map(LinkedObject.user)) !== null && _b !== void 0 ? _b : []);
|
|
26420
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
26421
|
+
return;
|
|
26422
|
+
this.callback({
|
|
26423
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
26424
|
+
data,
|
|
26425
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
26426
|
+
loading,
|
|
26427
|
+
error,
|
|
26228
26428
|
});
|
|
26229
|
-
|
|
26230
|
-
|
|
26231
|
-
|
|
26232
|
-
|
|
26233
|
-
|
|
26234
|
-
|
|
26235
|
-
|
|
26236
|
-
|
|
26237
|
-
|
|
26238
|
-
|
|
26239
|
-
|
|
26240
|
-
|
|
26241
|
-
|
|
26242
|
-
|
|
26243
|
-
|
|
26244
|
-
|
|
26245
|
-
|
|
26246
|
-
|
|
26247
|
-
|
|
26248
|
-
|
|
26429
|
+
}
|
|
26430
|
+
// eslint-disable-next-line class-methods-use-this
|
|
26431
|
+
applyFilter(data) {
|
|
26432
|
+
let users = data;
|
|
26433
|
+
users = users.filter(user => user.isDeleted == null || user.isDeleted === false);
|
|
26434
|
+
return users;
|
|
26435
|
+
}
|
|
26436
|
+
}
|
|
26437
|
+
|
|
26438
|
+
/* begin_public_function
|
|
26439
|
+
id: user.get_blocked_users
|
|
26440
|
+
*/
|
|
26441
|
+
/**
|
|
26442
|
+
* ```js
|
|
26443
|
+
* import { UserRepository } from '@amityco/ts-sdk'
|
|
26444
|
+
* const unblockedUser = await UserRepository.blockUser('userId')
|
|
26445
|
+
* ```
|
|
26446
|
+
*
|
|
26447
|
+
* Blocks a {@link Amity.InternalUser}
|
|
26448
|
+
*
|
|
26449
|
+
* @param params The params to get blocked {@link Amity.InternalUser}s
|
|
26450
|
+
* @param callback to recieve updates on unblocked {@link Amity.InternalUser}s
|
|
26451
|
+
* @returns {@link Amity.Unsubscriber} to unsubscribe from collection
|
|
26452
|
+
*
|
|
26453
|
+
* @category Post API
|
|
26454
|
+
* @async
|
|
26455
|
+
*/
|
|
26456
|
+
const getBlockedUsers$1 = (params, callback, config) => {
|
|
26457
|
+
const { log, cache } = getActiveClient();
|
|
26458
|
+
if (!cache) {
|
|
26459
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
26460
|
+
}
|
|
26461
|
+
const timestamp = Date.now();
|
|
26462
|
+
log(`getBlockedUsers(tmpid: ${timestamp}) > listen`);
|
|
26463
|
+
const blockedUserLiveCollection = new BlockedUserLiveCollectionController(params, callback);
|
|
26464
|
+
const disposers = blockedUserLiveCollection.startSubscription();
|
|
26465
|
+
const cacheKey = blockedUserLiveCollection.getCacheKey();
|
|
26466
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
26249
26467
|
return () => {
|
|
26250
|
-
log(`
|
|
26468
|
+
log(`getBlockedUsers(tmpid: ${timestamp}) > dispose`);
|
|
26251
26469
|
disposers.forEach(fn => fn());
|
|
26252
26470
|
dropFromCache(cacheKey);
|
|
26253
26471
|
};
|
|
@@ -26257,7 +26475,7 @@ const getBlockedUsers$1 = (params, callback, config) => {
|
|
|
26257
26475
|
/* eslint-disable no-use-before-define */
|
|
26258
26476
|
const getBlockedUsers = (params, callback, config) => {
|
|
26259
26477
|
console.log('Deprecation Notice: UserRepository.Relationship.getBlockedUsers will be deprecated on 9th June 2023, please use UserRepository.getBlockedUsers instead.');
|
|
26260
|
-
return getBlockedUsers$1(params, callback
|
|
26478
|
+
return getBlockedUsers$1(params, callback);
|
|
26261
26479
|
};
|
|
26262
26480
|
|
|
26263
26481
|
/* begin_public_function
|
|
@@ -26285,7 +26503,13 @@ const follow = async (userId) => {
|
|
|
26285
26503
|
if (client.cache) {
|
|
26286
26504
|
ingestInCache(data, { cachedAt });
|
|
26287
26505
|
}
|
|
26288
|
-
|
|
26506
|
+
const payload = prepareFollowStatusPayload(data);
|
|
26507
|
+
if (data.follows[0].status === 'accepted') {
|
|
26508
|
+
fireEvent('local.follow.created', payload);
|
|
26509
|
+
}
|
|
26510
|
+
else {
|
|
26511
|
+
fireEvent('local.follow.requested', payload);
|
|
26512
|
+
}
|
|
26289
26513
|
return {
|
|
26290
26514
|
data: data.follows[0],
|
|
26291
26515
|
cachedAt,
|
|
@@ -26317,7 +26541,8 @@ const unfollow = async (userId) => {
|
|
|
26317
26541
|
if (client.cache) {
|
|
26318
26542
|
ingestInCache(data);
|
|
26319
26543
|
}
|
|
26320
|
-
|
|
26544
|
+
const payload = prepareFollowStatusPayload(data);
|
|
26545
|
+
fireEvent('local.follow.unfollowed', payload);
|
|
26321
26546
|
return true;
|
|
26322
26547
|
};
|
|
26323
26548
|
/* end_public_function */
|
|
@@ -26346,7 +26571,8 @@ const acceptFollower = async (userId) => {
|
|
|
26346
26571
|
if (client.cache) {
|
|
26347
26572
|
ingestInCache(data);
|
|
26348
26573
|
}
|
|
26349
|
-
|
|
26574
|
+
const payload = prepareFollowStatusPayload(data);
|
|
26575
|
+
fireEvent('local.follow.accepted', payload);
|
|
26350
26576
|
return true;
|
|
26351
26577
|
};
|
|
26352
26578
|
|
|
@@ -26374,7 +26600,8 @@ const acceptMyFollower = async (userId) => {
|
|
|
26374
26600
|
if (client.cache) {
|
|
26375
26601
|
ingestInCache(data);
|
|
26376
26602
|
}
|
|
26377
|
-
|
|
26603
|
+
const payload = prepareFollowStatusPayload(data);
|
|
26604
|
+
fireEvent('local.follow.accepted', payload);
|
|
26378
26605
|
return true;
|
|
26379
26606
|
};
|
|
26380
26607
|
/* end_public_function */
|
|
@@ -26403,7 +26630,8 @@ const declineFollower = async (userId) => {
|
|
|
26403
26630
|
if (client.cache) {
|
|
26404
26631
|
ingestInCache(data);
|
|
26405
26632
|
}
|
|
26406
|
-
|
|
26633
|
+
const payload = prepareFollowStatusPayload(data);
|
|
26634
|
+
fireEvent('local.follow.requestDeclined', payload);
|
|
26407
26635
|
return true;
|
|
26408
26636
|
};
|
|
26409
26637
|
|
|
@@ -26431,29 +26659,35 @@ const declineMyFollower = async (userId) => {
|
|
|
26431
26659
|
if (client.cache) {
|
|
26432
26660
|
ingestInCache(data);
|
|
26433
26661
|
}
|
|
26434
|
-
|
|
26662
|
+
const payload = prepareFollowStatusPayload(data);
|
|
26663
|
+
fireEvent('local.follow.requestDeclined', payload);
|
|
26435
26664
|
return true;
|
|
26436
26665
|
};
|
|
26437
26666
|
/* end_public_function */
|
|
26438
26667
|
|
|
26439
26668
|
const createFollowEventSubscriber = (event, callback) => {
|
|
26440
26669
|
const client = getActiveClient();
|
|
26441
|
-
const filter = (
|
|
26442
|
-
|
|
26670
|
+
const filter = (data) => {
|
|
26671
|
+
const payload = prepareFollowersPayload(data);
|
|
26672
|
+
if (!client.cache) {
|
|
26673
|
+
callback(payload.follows[0]);
|
|
26674
|
+
}
|
|
26675
|
+
else {
|
|
26676
|
+
ingestInCache(payload);
|
|
26677
|
+
callback(payload.follows[0]);
|
|
26678
|
+
}
|
|
26679
|
+
};
|
|
26680
|
+
return createEventSubscriber(client, event, event, filter);
|
|
26681
|
+
};
|
|
26682
|
+
const createLocalFollowEventSubscriber = (event, callback) => {
|
|
26683
|
+
const client = getActiveClient();
|
|
26684
|
+
const filter = (data) => {
|
|
26685
|
+
const payload = prepareFollowStatusPayload(data);
|
|
26443
26686
|
if (!client.cache) {
|
|
26444
26687
|
callback(payload.follows[0]);
|
|
26445
26688
|
}
|
|
26446
26689
|
else {
|
|
26447
26690
|
ingestInCache(payload);
|
|
26448
|
-
const queries = [
|
|
26449
|
-
...((_a = queryCache(['followers', 'query'])) !== null && _a !== void 0 ? _a : []),
|
|
26450
|
-
...((_b = queryCache(['followings', 'query'])) !== null && _b !== void 0 ? _b : []),
|
|
26451
|
-
];
|
|
26452
|
-
queries
|
|
26453
|
-
.filter(({ key }) =>
|
|
26454
|
-
// @ts-ignore
|
|
26455
|
-
key[2].userId === payload.follows[0].from || key[2].userId === payload.follows[0].to)
|
|
26456
|
-
.forEach(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
|
|
26457
26691
|
callback(payload.follows[0]);
|
|
26458
26692
|
}
|
|
26459
26693
|
};
|
|
@@ -26672,12 +26906,27 @@ const onFollowInfoUpdated = (callback) => {
|
|
|
26672
26906
|
createFollowEventSubscriber('follow.requestCanceled', handler),
|
|
26673
26907
|
createFollowEventSubscriber('follow.requestDeclined', handler),
|
|
26674
26908
|
createFollowEventSubscriber('follow.followerDeleted', handler),
|
|
26909
|
+
createLocalFollowEventSubscriber('local.follow.created', handler),
|
|
26910
|
+
createLocalFollowEventSubscriber('local.follow.requested', handler),
|
|
26911
|
+
createLocalFollowEventSubscriber('local.follow.accepted', handler),
|
|
26912
|
+
createLocalFollowEventSubscriber('local.follow.unfollowed', handler),
|
|
26913
|
+
createLocalFollowEventSubscriber('local.follow.requestDeclined', handler),
|
|
26675
26914
|
];
|
|
26676
26915
|
return () => {
|
|
26677
26916
|
disposers.forEach(fn => fn());
|
|
26678
26917
|
};
|
|
26679
26918
|
};
|
|
26680
26919
|
|
|
26920
|
+
const onLocalUserFollowed = (callback) => createLocalFollowEventSubscriber('local.follow.created', callback);
|
|
26921
|
+
|
|
26922
|
+
const onLocalUserUnfollowed = (callback) => createLocalFollowEventSubscriber('local.follow.unfollowed', callback);
|
|
26923
|
+
|
|
26924
|
+
const onLocalFollowerRequested = (callback) => createLocalFollowEventSubscriber('local.follow.requested', callback);
|
|
26925
|
+
|
|
26926
|
+
const onLocalFollowRequestAccepted = (callback) => createLocalFollowEventSubscriber('local.follow.accepted', callback);
|
|
26927
|
+
|
|
26928
|
+
const onLocalFollowRequestDeclined = (callback) => createLocalFollowEventSubscriber('local.follow.requestDeclined', callback);
|
|
26929
|
+
|
|
26681
26930
|
/**
|
|
26682
26931
|
* ```js
|
|
26683
26932
|
* import { observeFollowInfo } from '@amityco/ts-sdk'
|
|
@@ -26750,7 +26999,7 @@ const observeFollowers = (userId, callback) => {
|
|
|
26750
26999
|
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, status);
|
|
26751
27000
|
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, status);
|
|
26752
27001
|
};
|
|
26753
|
-
disposers.push(onFollowerRequested(x => router(x, 'onRequested')), onFollowRequestAccepted(x => router(x, 'onAccepted')), onFollowRequestDeclined(x => router(x, 'onDeclined')), onFollowRequestCanceled(x => router(x, 'onCanceled')), onUserFollowed(x => router(x, 'onFollowed')), onUserUnfollowed(x => router(x, 'onUnfollowed')), onFollowerDeleted(x => router(x, 'onDeleted')));
|
|
27002
|
+
disposers.push(onFollowerRequested(x => router(x, 'onRequested')), onFollowRequestAccepted(x => router(x, 'onAccepted')), onFollowRequestDeclined(x => router(x, 'onDeclined')), onFollowRequestCanceled(x => router(x, 'onCanceled')), onUserFollowed(x => router(x, 'onFollowed')), onUserUnfollowed(x => router(x, 'onUnfollowed')), onFollowerDeleted(x => router(x, 'onDeleted')), onLocalFollowerRequested(x => router(x, 'onRequested')), onLocalFollowRequestAccepted(x => router(x, 'onAccepted')), onLocalFollowRequestDeclined(x => router(x, 'onDeclined')), onLocalUserFollowed(x => router(x, 'onFollowed')), onLocalUserUnfollowed(x => router(x, 'onUnfollowed')));
|
|
26754
27003
|
return () => {
|
|
26755
27004
|
log(`observeFollowers(tmpid: ${timestamp}) > dispose`);
|
|
26756
27005
|
disposers.forEach(fn => fn());
|
|
@@ -26786,92 +27035,190 @@ const observeFollowings = (userId, callback) => {
|
|
|
26786
27035
|
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, status);
|
|
26787
27036
|
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, status);
|
|
26788
27037
|
};
|
|
26789
|
-
disposers.push(onFollowerRequested(x => router(x, 'onRequested')), onFollowRequestAccepted(x => router(x, 'onAccepted')), onFollowRequestDeclined(x => router(x, 'onDeclined')), onFollowRequestCanceled(x => router(x, 'onCanceled')), onUserFollowed(x => router(x, 'onFollowed')), onUserUnfollowed(x => router(x, 'onUnfollowed')), onFollowerDeleted(x => router(x, 'onDeleted')));
|
|
27038
|
+
disposers.push(onFollowerRequested(x => router(x, 'onRequested')), onFollowRequestAccepted(x => router(x, 'onAccepted')), onFollowRequestDeclined(x => router(x, 'onDeclined')), onFollowRequestCanceled(x => router(x, 'onCanceled')), onUserFollowed(x => router(x, 'onFollowed')), onUserUnfollowed(x => router(x, 'onUnfollowed')), onFollowerDeleted(x => router(x, 'onDeleted')), onLocalFollowerRequested(x => router(x, 'onRequested')), onLocalFollowRequestAccepted(x => router(x, 'onAccepted')), onLocalFollowRequestDeclined(x => router(x, 'onDeclined')), onLocalUserFollowed(x => router(x, 'onFollowed')), onLocalUserUnfollowed(x => router(x, 'onUnfollowed')));
|
|
26790
27039
|
return () => {
|
|
26791
27040
|
log(`observeFollowings(tmpid: ${timestamp}) > dispose`);
|
|
26792
27041
|
disposers.forEach(fn => fn());
|
|
26793
27042
|
};
|
|
26794
27043
|
};
|
|
26795
27044
|
|
|
26796
|
-
|
|
26797
|
-
|
|
26798
|
-
|
|
26799
|
-
|
|
26800
|
-
|
|
26801
|
-
|
|
26802
|
-
|
|
26803
|
-
|
|
26804
|
-
|
|
26805
|
-
|
|
26806
|
-
if (client.cache) {
|
|
26807
|
-
ingestInCache(payload, { cachedAt });
|
|
26808
|
-
const cacheKey = [
|
|
26809
|
-
'follow',
|
|
26810
|
-
'query',
|
|
26811
|
-
Object.assign(Object.assign({}, params), { userId, options: Object.assign({}, page), type: key }),
|
|
26812
|
-
];
|
|
26813
|
-
pushToCache(cacheKey, { follows: follows.map(getResolver('follow')), paging });
|
|
27045
|
+
class FollowerPaginationController extends PaginationController {
|
|
27046
|
+
async getRequest(queryParams, token) {
|
|
27047
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, userId } = queryParams, params = __rest(queryParams, ["limit", "userId"]);
|
|
27048
|
+
const options = token ? { token } : { limit };
|
|
27049
|
+
const client = getActiveClient();
|
|
27050
|
+
const path = client.userId === userId ? `/api/v4/me/followers` : `/api/v4/users/${userId}/followers`;
|
|
27051
|
+
const { data: queryResponse } = await this.http.get(path, {
|
|
27052
|
+
params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
|
|
27053
|
+
});
|
|
27054
|
+
return queryResponse;
|
|
26814
27055
|
}
|
|
26815
|
-
|
|
26816
|
-
|
|
26817
|
-
|
|
26818
|
-
|
|
26819
|
-
|
|
26820
|
-
|
|
26821
|
-
|
|
26822
|
-
|
|
26823
|
-
|
|
26824
|
-
|
|
26825
|
-
|
|
26826
|
-
|
|
26827
|
-
|
|
26828
|
-
|
|
26829
|
-
|
|
26830
|
-
|
|
26831
|
-
|
|
26832
|
-
|
|
26833
|
-
|
|
27056
|
+
}
|
|
27057
|
+
|
|
27058
|
+
var EnumFollowActions;
|
|
27059
|
+
(function (EnumFollowActions) {
|
|
27060
|
+
EnumFollowActions["OnRequested"] = "onRequested";
|
|
27061
|
+
EnumFollowActions["OnAccepted"] = "onAccepted";
|
|
27062
|
+
EnumFollowActions["OnDeclined"] = "onDeclined";
|
|
27063
|
+
EnumFollowActions["OnCanceled"] = "onCanceled";
|
|
27064
|
+
EnumFollowActions["OnFollowed"] = "onFollowed";
|
|
27065
|
+
EnumFollowActions["OnUnfollowed"] = "onUnfollowed";
|
|
27066
|
+
EnumFollowActions["OnDeleted"] = "onDeleted";
|
|
27067
|
+
EnumFollowActions["OnUserDeleted"] = "onUserDeleted";
|
|
27068
|
+
})(EnumFollowActions || (EnumFollowActions = {}));
|
|
27069
|
+
|
|
27070
|
+
class FollowerQueryStreamController extends QueryStreamController {
|
|
27071
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
27072
|
+
super(query, cacheKey);
|
|
27073
|
+
this.notifyChange = notifyChange;
|
|
27074
|
+
this.preparePayload = preparePayload;
|
|
26834
27075
|
}
|
|
26835
|
-
|
|
26836
|
-
|
|
26837
|
-
|
|
26838
|
-
|
|
26839
|
-
|
|
26840
|
-
|
|
26841
|
-
|
|
26842
|
-
|
|
26843
|
-
|
|
27076
|
+
async saveToMainDB(response) {
|
|
27077
|
+
const processedPayload = await this.preparePayload(response);
|
|
27078
|
+
const client = getActiveClient();
|
|
27079
|
+
const cachedAt = client.cache && Date.now();
|
|
27080
|
+
if (client.cache) {
|
|
27081
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
27082
|
+
}
|
|
27083
|
+
}
|
|
27084
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
27085
|
+
var _a, _b;
|
|
27086
|
+
if (refresh) {
|
|
27087
|
+
pushToCache(this.cacheKey, {
|
|
27088
|
+
data: response.follows.map(getResolver('follow')),
|
|
27089
|
+
});
|
|
27090
|
+
}
|
|
27091
|
+
else {
|
|
27092
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27093
|
+
const follows = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
27094
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...follows, ...response.follows.map(getResolver('follow'))])] }));
|
|
27095
|
+
}
|
|
27096
|
+
}
|
|
27097
|
+
reactor(action) {
|
|
27098
|
+
return (followStatus) => {
|
|
27099
|
+
var _a;
|
|
27100
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27101
|
+
if (this.query.userId !== followStatus.to || !collection)
|
|
27102
|
+
return;
|
|
27103
|
+
switch (action) {
|
|
27104
|
+
case EnumFollowActions.OnDeclined:
|
|
27105
|
+
case EnumFollowActions.OnCanceled:
|
|
27106
|
+
case EnumFollowActions.OnUnfollowed:
|
|
27107
|
+
case EnumFollowActions.OnDeleted:
|
|
27108
|
+
collection.data = collection.data.filter(p => p !== getResolver('follow')(followStatus));
|
|
27109
|
+
break;
|
|
27110
|
+
case EnumFollowActions.OnRequested:
|
|
27111
|
+
case EnumFollowActions.OnAccepted:
|
|
27112
|
+
case EnumFollowActions.OnFollowed:
|
|
27113
|
+
collection.data = [...new Set([getResolver('follow')(followStatus), ...collection.data])];
|
|
27114
|
+
break;
|
|
27115
|
+
}
|
|
27116
|
+
pushToCache(this.cacheKey, collection);
|
|
27117
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
27118
|
+
};
|
|
27119
|
+
}
|
|
27120
|
+
subscribeRTE(createSubscriber) {
|
|
27121
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
27122
|
+
}
|
|
27123
|
+
}
|
|
27124
|
+
|
|
27125
|
+
const onFollowerUserDeleted = ({ userId }) => (callback) => {
|
|
27126
|
+
const client = getActiveClient();
|
|
27127
|
+
const filter = (data) => {
|
|
27128
|
+
const userPayload = prepareUserPayload(data);
|
|
27129
|
+
ingestInCache(userPayload);
|
|
27130
|
+
const cacheData = pullFromCache([
|
|
27131
|
+
'follow',
|
|
27132
|
+
'get',
|
|
27133
|
+
getResolver('follow')({
|
|
27134
|
+
from: userPayload.users[0].userId,
|
|
27135
|
+
to: userId,
|
|
27136
|
+
}),
|
|
27137
|
+
]);
|
|
27138
|
+
if (!cacheData)
|
|
27139
|
+
return;
|
|
27140
|
+
callback(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data);
|
|
27141
|
+
};
|
|
27142
|
+
return createEventSubscriber(client, 'user.deleted', 'user.deleted', filter);
|
|
26844
27143
|
};
|
|
26845
27144
|
|
|
26846
|
-
|
|
26847
|
-
|
|
26848
|
-
|
|
26849
|
-
|
|
26850
|
-
|
|
26851
|
-
|
|
26852
|
-
|
|
26853
|
-
|
|
26854
|
-
|
|
26855
|
-
|
|
26856
|
-
|
|
26857
|
-
|
|
26858
|
-
|
|
26859
|
-
|
|
26860
|
-
|
|
26861
|
-
|
|
26862
|
-
|
|
26863
|
-
|
|
26864
|
-
|
|
26865
|
-
|
|
26866
|
-
|
|
26867
|
-
|
|
26868
|
-
|
|
26869
|
-
|
|
26870
|
-
|
|
26871
|
-
|
|
26872
|
-
|
|
26873
|
-
|
|
26874
|
-
|
|
27145
|
+
class FollowerLiveCollectionController extends LiveCollectionController {
|
|
27146
|
+
constructor(query, callback) {
|
|
27147
|
+
const queryStreamId = hash(query);
|
|
27148
|
+
const cacheKey = ['follow', 'collection', queryStreamId];
|
|
27149
|
+
const paginationController = new FollowerPaginationController(query);
|
|
27150
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
27151
|
+
this.query = query;
|
|
27152
|
+
this.queryStreamController = new FollowerQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareFollowersPayload);
|
|
27153
|
+
this.callback = callback.bind(this);
|
|
27154
|
+
this.loadPage({ initial: true });
|
|
27155
|
+
}
|
|
27156
|
+
setup() {
|
|
27157
|
+
var _a;
|
|
27158
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27159
|
+
if (!collection) {
|
|
27160
|
+
pushToCache(this.cacheKey, {
|
|
27161
|
+
data: [],
|
|
27162
|
+
params: {},
|
|
27163
|
+
});
|
|
27164
|
+
}
|
|
27165
|
+
}
|
|
27166
|
+
async persistModel(queryPayload) {
|
|
27167
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
27168
|
+
}
|
|
27169
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
27170
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
27171
|
+
}
|
|
27172
|
+
startSubscription() {
|
|
27173
|
+
return this.queryStreamController.subscribeRTE([
|
|
27174
|
+
{ fn: onUserFollowed, action: EnumFollowActions.OnFollowed },
|
|
27175
|
+
{ fn: onUserUnfollowed, action: EnumFollowActions.OnUnfollowed },
|
|
27176
|
+
{ fn: onFollowRequestAccepted, action: EnumFollowActions.OnAccepted },
|
|
27177
|
+
{ fn: onFollowRequestDeclined, action: EnumFollowActions.OnDeclined },
|
|
27178
|
+
{ fn: onFollowRequestCanceled, action: EnumFollowActions.OnCanceled },
|
|
27179
|
+
{ fn: onFollowerDeleted, action: EnumFollowActions.OnDeleted },
|
|
27180
|
+
{ fn: onLocalFollowRequestAccepted, action: EnumFollowActions.OnAccepted },
|
|
27181
|
+
{ fn: onLocalFollowRequestDeclined, action: EnumFollowActions.OnDeclined },
|
|
27182
|
+
{ fn: onLocalUserFollowed, action: EnumFollowActions.OnFollowed },
|
|
27183
|
+
{ fn: onLocalUserUnfollowed, action: EnumFollowActions.OnUnfollowed },
|
|
27184
|
+
{
|
|
27185
|
+
fn: onFollowerUserDeleted({ userId: this.query.userId }),
|
|
27186
|
+
action: EnumFollowActions.OnUserDeleted,
|
|
27187
|
+
},
|
|
27188
|
+
]);
|
|
27189
|
+
}
|
|
27190
|
+
notifyChange({ origin, loading, error }) {
|
|
27191
|
+
var _a, _b;
|
|
27192
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27193
|
+
if (!collection)
|
|
27194
|
+
return;
|
|
27195
|
+
const data = this.applyFilter((_b = collection.data
|
|
27196
|
+
.map(id => pullFromCache(['follow', 'get', id]))
|
|
27197
|
+
.filter(isNonNullable)
|
|
27198
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
|
|
27199
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
27200
|
+
return;
|
|
27201
|
+
this.callback({
|
|
27202
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
27203
|
+
data,
|
|
27204
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
27205
|
+
loading,
|
|
27206
|
+
error,
|
|
27207
|
+
});
|
|
27208
|
+
}
|
|
27209
|
+
applyFilter(data) {
|
|
27210
|
+
let followers = data;
|
|
27211
|
+
if (this.query.status && this.query.status !== "all" /* Amity.FollowStatusTypeEnum.All */) {
|
|
27212
|
+
followers = followers.filter(follower => follower.status === this.query.status);
|
|
27213
|
+
}
|
|
27214
|
+
followers = followers.filter(follower => {
|
|
27215
|
+
var _a;
|
|
27216
|
+
const fromUser = (_a = pullFromCache(['user', 'get', follower.from])) === null || _a === void 0 ? void 0 : _a.data;
|
|
27217
|
+
return (fromUser === null || fromUser === void 0 ? void 0 : fromUser.isDeleted) == null || (fromUser === null || fromUser === void 0 ? void 0 : fromUser.isDeleted) === false;
|
|
27218
|
+
});
|
|
27219
|
+
return followers;
|
|
27220
|
+
}
|
|
27221
|
+
}
|
|
26875
27222
|
|
|
26876
27223
|
/* begin_public_function
|
|
26877
27224
|
id: user.relationship.query_my_followers, user.relationship.query_followers
|
|
@@ -26897,69 +27244,14 @@ queryFollowers.locally = (query) => queryFollows.locally('followers', query);
|
|
|
26897
27244
|
const getFollowers = (params, callback, config) => {
|
|
26898
27245
|
const { log, cache } = getActiveClient();
|
|
26899
27246
|
if (!cache) {
|
|
26900
|
-
console.log(
|
|
27247
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
26901
27248
|
}
|
|
26902
27249
|
const timestamp = Date.now();
|
|
26903
27250
|
log(`getFollowers(tmpid: ${timestamp}) > listen`);
|
|
26904
|
-
const
|
|
26905
|
-
const
|
|
26906
|
-
const
|
|
26907
|
-
|
|
26908
|
-
const cacheKey = ['follow', 'collection', { userId: params.userId, type: 'follower' }];
|
|
26909
|
-
const responder = (data) => {
|
|
26910
|
-
var _a, _b;
|
|
26911
|
-
let followers = (_a = data.data
|
|
26912
|
-
.map(key => pullFromCache(['follow', 'get', key]))
|
|
26913
|
-
.filter(Boolean)
|
|
26914
|
-
.map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
|
|
26915
|
-
if (params.status && params.status !== 'all') {
|
|
26916
|
-
followers = filterByPropEquality(followers, 'status', params.status);
|
|
26917
|
-
}
|
|
26918
|
-
callback({
|
|
26919
|
-
onNextPage: onFetch,
|
|
26920
|
-
data: followers,
|
|
26921
|
-
hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
|
|
26922
|
-
loading: data.loading,
|
|
26923
|
-
error: data.error,
|
|
26924
|
-
});
|
|
26925
|
-
};
|
|
26926
|
-
const realtimeRouter = (action) => (followStatus) => {
|
|
26927
|
-
var _a;
|
|
26928
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
26929
|
-
if (params.userId !== followStatus.to || !collection)
|
|
26930
|
-
return;
|
|
26931
|
-
if (['onDeclined', 'onCanceled', 'onUnfollowed', 'onDeleted'].includes(action)) {
|
|
26932
|
-
collection.data = collection.data.filter(p => p !== getResolver('follow')(followStatus));
|
|
26933
|
-
}
|
|
26934
|
-
else if (['onRequested', 'onAccepted', 'onFollowed'].includes(action)) {
|
|
26935
|
-
collection.data = [...new Set([getResolver('follow')(followStatus), ...collection.data])];
|
|
26936
|
-
}
|
|
26937
|
-
pushToCache(cacheKey, collection);
|
|
26938
|
-
responder(collection);
|
|
26939
|
-
};
|
|
26940
|
-
const onFetch = (initial = false) => {
|
|
26941
|
-
var _a, _b, _c, _d;
|
|
26942
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
26943
|
-
const followers = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
26944
|
-
if (!initial && followers.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
|
|
26945
|
-
return;
|
|
26946
|
-
const query = createQuery(queryFollowers, 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 } }));
|
|
26947
|
-
runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
|
|
26948
|
-
const data = {
|
|
26949
|
-
loading,
|
|
26950
|
-
error,
|
|
26951
|
-
params: { page },
|
|
26952
|
-
data: followers,
|
|
26953
|
-
};
|
|
26954
|
-
if (result) {
|
|
26955
|
-
data.data = [...new Set([...followers, ...result.map(getResolver('follow'))])];
|
|
26956
|
-
}
|
|
26957
|
-
pushToCache(cacheKey, data);
|
|
26958
|
-
responder(data);
|
|
26959
|
-
}, queryOptions(policy));
|
|
26960
|
-
};
|
|
26961
|
-
disposers.push(onFollowerRequested(realtimeRouter('onRequested')), onFollowRequestAccepted(realtimeRouter('onAccepted')), onFollowRequestDeclined(realtimeRouter('onDeclined')), onFollowRequestCanceled(realtimeRouter('onCanceled')), onUserFollowed(realtimeRouter('onFollowed')), onUserUnfollowed(realtimeRouter('onUnfollowed')), onFollowerDeleted(realtimeRouter('onDeleted')));
|
|
26962
|
-
onFetch(true);
|
|
27251
|
+
const followerLiveCollection = new FollowerLiveCollectionController(params, callback);
|
|
27252
|
+
const disposers = followerLiveCollection.startSubscription();
|
|
27253
|
+
const cacheKey = followerLiveCollection.getCacheKey();
|
|
27254
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
26963
27255
|
return () => {
|
|
26964
27256
|
log(`getFollowers(tmpid: ${timestamp}) > dispose`);
|
|
26965
27257
|
disposers.forEach(fn => fn());
|
|
@@ -26967,35 +27259,173 @@ const getFollowers = (params, callback, config) => {
|
|
|
26967
27259
|
};
|
|
26968
27260
|
/* end_public_function */
|
|
26969
27261
|
|
|
26970
|
-
|
|
26971
|
-
|
|
26972
|
-
|
|
26973
|
-
|
|
26974
|
-
|
|
26975
|
-
|
|
26976
|
-
|
|
26977
|
-
|
|
26978
|
-
|
|
26979
|
-
|
|
26980
|
-
|
|
26981
|
-
|
|
26982
|
-
|
|
26983
|
-
|
|
26984
|
-
|
|
26985
|
-
|
|
26986
|
-
|
|
26987
|
-
|
|
26988
|
-
|
|
26989
|
-
|
|
26990
|
-
|
|
26991
|
-
|
|
26992
|
-
|
|
26993
|
-
|
|
26994
|
-
|
|
26995
|
-
|
|
26996
|
-
|
|
26997
|
-
|
|
26998
|
-
|
|
27262
|
+
class FollowingPaginationController extends PaginationController {
|
|
27263
|
+
async getRequest(queryParams, token) {
|
|
27264
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, userId } = queryParams, params = __rest(queryParams, ["limit", "userId"]);
|
|
27265
|
+
const options = token ? { token } : { limit };
|
|
27266
|
+
const client = getActiveClient();
|
|
27267
|
+
const path = client.userId === userId ? `/api/v4/me/following` : `/api/v4/users/${userId}/following`;
|
|
27268
|
+
const { data: queryResponse } = await this.http.get(path, {
|
|
27269
|
+
params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
|
|
27270
|
+
});
|
|
27271
|
+
return queryResponse;
|
|
27272
|
+
}
|
|
27273
|
+
}
|
|
27274
|
+
|
|
27275
|
+
class FollowingQueryStreamController extends QueryStreamController {
|
|
27276
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
27277
|
+
super(query, cacheKey);
|
|
27278
|
+
this.notifyChange = notifyChange;
|
|
27279
|
+
this.preparePayload = preparePayload;
|
|
27280
|
+
}
|
|
27281
|
+
async saveToMainDB(response) {
|
|
27282
|
+
const processedPayload = await this.preparePayload(response);
|
|
27283
|
+
const client = getActiveClient();
|
|
27284
|
+
const cachedAt = client.cache && Date.now();
|
|
27285
|
+
if (client.cache) {
|
|
27286
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
27287
|
+
}
|
|
27288
|
+
}
|
|
27289
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
27290
|
+
var _a, _b;
|
|
27291
|
+
if (refresh) {
|
|
27292
|
+
pushToCache(this.cacheKey, {
|
|
27293
|
+
data: response.follows.map(getResolver('follow')),
|
|
27294
|
+
});
|
|
27295
|
+
}
|
|
27296
|
+
else {
|
|
27297
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27298
|
+
const follows = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
27299
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...follows, ...response.follows.map(getResolver('follow'))])] }));
|
|
27300
|
+
}
|
|
27301
|
+
}
|
|
27302
|
+
reactor(action) {
|
|
27303
|
+
return (followStatus) => {
|
|
27304
|
+
var _a;
|
|
27305
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27306
|
+
if (this.query.userId !== followStatus.from || !collection)
|
|
27307
|
+
return;
|
|
27308
|
+
switch (action) {
|
|
27309
|
+
case EnumFollowActions.OnDeclined:
|
|
27310
|
+
case EnumFollowActions.OnCanceled:
|
|
27311
|
+
case EnumFollowActions.OnUnfollowed:
|
|
27312
|
+
case EnumFollowActions.OnDeleted:
|
|
27313
|
+
collection.data = collection.data.filter(p => p !== getResolver('follow')(followStatus));
|
|
27314
|
+
break;
|
|
27315
|
+
case EnumFollowActions.OnRequested:
|
|
27316
|
+
case EnumFollowActions.OnAccepted:
|
|
27317
|
+
case EnumFollowActions.OnFollowed:
|
|
27318
|
+
collection.data = [...new Set([getResolver('follow')(followStatus), ...collection.data])];
|
|
27319
|
+
break;
|
|
27320
|
+
}
|
|
27321
|
+
pushToCache(this.cacheKey, collection);
|
|
27322
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
27323
|
+
};
|
|
27324
|
+
}
|
|
27325
|
+
subscribeRTE(createSubscriber) {
|
|
27326
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
27327
|
+
}
|
|
27328
|
+
}
|
|
27329
|
+
|
|
27330
|
+
const onFollowingUserDeleted = ({ userId }) => (callback) => {
|
|
27331
|
+
const client = getActiveClient();
|
|
27332
|
+
const filter = (data) => {
|
|
27333
|
+
const userPayload = prepareUserPayload(data);
|
|
27334
|
+
ingestInCache(userPayload);
|
|
27335
|
+
const cacheData = pullFromCache([
|
|
27336
|
+
'follow',
|
|
27337
|
+
'get',
|
|
27338
|
+
getResolver('follow')({
|
|
27339
|
+
from: userId,
|
|
27340
|
+
to: userPayload.users[0].userId,
|
|
27341
|
+
}),
|
|
27342
|
+
]);
|
|
27343
|
+
if (!cacheData)
|
|
27344
|
+
return;
|
|
27345
|
+
callback(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data);
|
|
27346
|
+
};
|
|
27347
|
+
return createEventSubscriber(client, 'user.deleted', 'user.deleted', filter);
|
|
27348
|
+
};
|
|
27349
|
+
|
|
27350
|
+
class FollowingLiveCollectionController extends LiveCollectionController {
|
|
27351
|
+
constructor(query, callback) {
|
|
27352
|
+
const queryStreamId = hash(query);
|
|
27353
|
+
const cacheKey = ['follow', 'collection', queryStreamId];
|
|
27354
|
+
const paginationController = new FollowingPaginationController(query);
|
|
27355
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
27356
|
+
this.query = query;
|
|
27357
|
+
this.queryStreamController = new FollowingQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareFollowingsPayload);
|
|
27358
|
+
this.callback = callback.bind(this);
|
|
27359
|
+
this.loadPage({ initial: true });
|
|
27360
|
+
}
|
|
27361
|
+
setup() {
|
|
27362
|
+
var _a;
|
|
27363
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27364
|
+
if (!collection) {
|
|
27365
|
+
pushToCache(this.cacheKey, {
|
|
27366
|
+
data: [],
|
|
27367
|
+
params: {},
|
|
27368
|
+
});
|
|
27369
|
+
}
|
|
27370
|
+
}
|
|
27371
|
+
async persistModel(queryPayload) {
|
|
27372
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
27373
|
+
}
|
|
27374
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
27375
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
27376
|
+
}
|
|
27377
|
+
startSubscription() {
|
|
27378
|
+
return this.queryStreamController.subscribeRTE([
|
|
27379
|
+
{ fn: onFollowerRequested, action: EnumFollowActions.OnRequested },
|
|
27380
|
+
{ fn: onFollowRequestAccepted, action: EnumFollowActions.OnAccepted },
|
|
27381
|
+
{ fn: onFollowRequestDeclined, action: EnumFollowActions.OnDeclined },
|
|
27382
|
+
{ fn: onFollowRequestCanceled, action: EnumFollowActions.OnCanceled },
|
|
27383
|
+
{ fn: onUserFollowed, action: EnumFollowActions.OnFollowed },
|
|
27384
|
+
{ fn: onUserUnfollowed, action: EnumFollowActions.OnUnfollowed },
|
|
27385
|
+
{ fn: onFollowerDeleted, action: EnumFollowActions.OnDeleted },
|
|
27386
|
+
{ fn: onLocalFollowerRequested, action: EnumFollowActions.OnRequested },
|
|
27387
|
+
{ fn: onLocalFollowRequestAccepted, action: EnumFollowActions.OnAccepted },
|
|
27388
|
+
{ fn: onLocalFollowRequestDeclined, action: EnumFollowActions.OnDeclined },
|
|
27389
|
+
{ fn: onLocalUserFollowed, action: EnumFollowActions.OnFollowed },
|
|
27390
|
+
{ fn: onLocalUserUnfollowed, action: EnumFollowActions.OnUnfollowed },
|
|
27391
|
+
{
|
|
27392
|
+
fn: onFollowingUserDeleted({ userId: this.query.userId }),
|
|
27393
|
+
action: EnumFollowActions.OnUserDeleted,
|
|
27394
|
+
},
|
|
27395
|
+
]);
|
|
27396
|
+
}
|
|
27397
|
+
notifyChange({ origin, loading, error }) {
|
|
27398
|
+
var _a, _b;
|
|
27399
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27400
|
+
if (!collection)
|
|
27401
|
+
return;
|
|
27402
|
+
const data = this.applyFilter((_b = collection.data
|
|
27403
|
+
.map(id => pullFromCache(['follow', 'get', id]))
|
|
27404
|
+
.filter(isNonNullable)
|
|
27405
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
|
|
27406
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
27407
|
+
return;
|
|
27408
|
+
this.callback({
|
|
27409
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
27410
|
+
data,
|
|
27411
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
27412
|
+
loading,
|
|
27413
|
+
error,
|
|
27414
|
+
});
|
|
27415
|
+
}
|
|
27416
|
+
applyFilter(data) {
|
|
27417
|
+
let followings = data;
|
|
27418
|
+
if (this.query.status && this.query.status !== "all" /* Amity.FollowStatusTypeEnum.All */) {
|
|
27419
|
+
followings = followings.filter(following => following.status === this.query.status);
|
|
27420
|
+
}
|
|
27421
|
+
followings = followings.filter(following => {
|
|
27422
|
+
var _a;
|
|
27423
|
+
const toUser = (_a = pullFromCache(['user', 'get', following.to])) === null || _a === void 0 ? void 0 : _a.data;
|
|
27424
|
+
return (toUser === null || toUser === void 0 ? void 0 : toUser.isDeleted) == null || (toUser === null || toUser === void 0 ? void 0 : toUser.isDeleted) === false;
|
|
27425
|
+
});
|
|
27426
|
+
return followings;
|
|
27427
|
+
}
|
|
27428
|
+
}
|
|
26999
27429
|
|
|
27000
27430
|
/* begin_public_function
|
|
27001
27431
|
id: user.relationship.query_my_followings, user.relationship.query_followings
|
|
@@ -27025,65 +27455,10 @@ const getFollowings = (params, callback, config) => {
|
|
|
27025
27455
|
}
|
|
27026
27456
|
const timestamp = Date.now();
|
|
27027
27457
|
log(`getFollowings(tmpid: ${timestamp}) > listen`);
|
|
27028
|
-
const
|
|
27029
|
-
const
|
|
27030
|
-
const
|
|
27031
|
-
|
|
27032
|
-
const cacheKey = ['follow', 'collection', { userId: params.userId, type: 'following' }];
|
|
27033
|
-
const responder = (data) => {
|
|
27034
|
-
var _a, _b;
|
|
27035
|
-
let followings = (_a = data.data
|
|
27036
|
-
.map(key => pullFromCache(['follow', 'get', key]))
|
|
27037
|
-
.filter(Boolean)
|
|
27038
|
-
.map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
|
|
27039
|
-
if (params.status && params.status !== 'all') {
|
|
27040
|
-
followings = filterByPropEquality(followings, 'status', params.status);
|
|
27041
|
-
}
|
|
27042
|
-
callback({
|
|
27043
|
-
onNextPage: onFetch,
|
|
27044
|
-
data: followings,
|
|
27045
|
-
hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
|
|
27046
|
-
loading: data.loading,
|
|
27047
|
-
error: data.error,
|
|
27048
|
-
});
|
|
27049
|
-
};
|
|
27050
|
-
const realtimeRouter = (action) => (followStatus) => {
|
|
27051
|
-
var _a;
|
|
27052
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27053
|
-
if (params.userId !== followStatus.from || !collection)
|
|
27054
|
-
return;
|
|
27055
|
-
if (['onDeclined', 'onCanceled', 'onUnfollowed', 'onDeleted'].includes(action)) {
|
|
27056
|
-
collection.data = collection.data.filter(p => p !== getResolver('follow')(followStatus));
|
|
27057
|
-
}
|
|
27058
|
-
else if (['onRequested', 'onAccepted', 'onFollowed'].includes(action)) {
|
|
27059
|
-
collection.data = [...new Set([getResolver('follow')(followStatus), ...collection.data])];
|
|
27060
|
-
}
|
|
27061
|
-
pushToCache(cacheKey, collection);
|
|
27062
|
-
responder(collection);
|
|
27063
|
-
};
|
|
27064
|
-
const onFetch = (initial = false) => {
|
|
27065
|
-
var _a, _b, _c, _d;
|
|
27066
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27067
|
-
const followings = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
27068
|
-
if (!initial && followings.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
|
|
27069
|
-
return;
|
|
27070
|
-
const query = createQuery(queryFollowings, 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 } }));
|
|
27071
|
-
runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
|
|
27072
|
-
const data = {
|
|
27073
|
-
loading,
|
|
27074
|
-
error,
|
|
27075
|
-
params: { page },
|
|
27076
|
-
data: followings,
|
|
27077
|
-
};
|
|
27078
|
-
if (result) {
|
|
27079
|
-
data.data = [...new Set([...followings, ...result.map(getResolver('follow'))])];
|
|
27080
|
-
}
|
|
27081
|
-
pushToCache(cacheKey, data);
|
|
27082
|
-
responder(data);
|
|
27083
|
-
}, queryOptions(policy));
|
|
27084
|
-
};
|
|
27085
|
-
disposers.push(onFollowerRequested(realtimeRouter('onRequested')), onFollowRequestAccepted(realtimeRouter('onAccepted')), onFollowRequestDeclined(realtimeRouter('onDeclined')), onFollowRequestCanceled(realtimeRouter('onCanceled')), onUserFollowed(realtimeRouter('onFollowed')), onUserUnfollowed(realtimeRouter('onUnfollowed')), onFollowerDeleted(realtimeRouter('onDeleted')));
|
|
27086
|
-
onFetch(true);
|
|
27458
|
+
const followingLiveCollection = new FollowingLiveCollectionController(params, callback);
|
|
27459
|
+
const disposers = followingLiveCollection.startSubscription();
|
|
27460
|
+
const cacheKey = followingLiveCollection.getCacheKey();
|
|
27461
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
27087
27462
|
return () => {
|
|
27088
27463
|
log(`getFollowings(tmpid: ${timestamp}) > dispose`);
|
|
27089
27464
|
disposers.forEach(fn => fn());
|
|
@@ -27171,6 +27546,11 @@ var index$k = /*#__PURE__*/Object.freeze({
|
|
|
27171
27546
|
onFollowRequestAccepted: onFollowRequestAccepted,
|
|
27172
27547
|
onFollowRequestDeclined: onFollowRequestDeclined,
|
|
27173
27548
|
onFollowInfoUpdated: onFollowInfoUpdated,
|
|
27549
|
+
onLocalUserFollowed: onLocalUserFollowed,
|
|
27550
|
+
onLocalUserUnfollowed: onLocalUserUnfollowed,
|
|
27551
|
+
onLocalFollowerRequested: onLocalFollowerRequested,
|
|
27552
|
+
onLocalFollowRequestAccepted: onLocalFollowRequestAccepted,
|
|
27553
|
+
onLocalFollowRequestDeclined: onLocalFollowRequestDeclined,
|
|
27174
27554
|
observeFollowInfo: observeFollowInfo,
|
|
27175
27555
|
observeFollowers: observeFollowers,
|
|
27176
27556
|
observeFollowings: observeFollowings,
|
|
@@ -27361,74 +27741,6 @@ const isUserFlaggedByMe = async (userId) => {
|
|
|
27361
27741
|
};
|
|
27362
27742
|
/* end_public_function */
|
|
27363
27743
|
|
|
27364
|
-
/**
|
|
27365
|
-
* ```js
|
|
27366
|
-
* import { onUserUpdated } from '@amityco/ts-sdk'
|
|
27367
|
-
* const dispose = onUserUpdated(user => {
|
|
27368
|
-
* // ...
|
|
27369
|
-
* })
|
|
27370
|
-
* ```
|
|
27371
|
-
*
|
|
27372
|
-
* Fired when a {@link Amity.InternalUser} has been updated
|
|
27373
|
-
*
|
|
27374
|
-
* @param callback The function to call when the event was fired
|
|
27375
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
27376
|
-
*
|
|
27377
|
-
* @category User Events
|
|
27378
|
-
*/
|
|
27379
|
-
const onUserUpdated = (callback) => createUserEventSubscriber('user.updated', callback);
|
|
27380
|
-
|
|
27381
|
-
/**
|
|
27382
|
-
* ```js
|
|
27383
|
-
* import { onUserFlagged } from '@amityco/ts-sdk'
|
|
27384
|
-
* const dispose = onUserFlagged(user => {
|
|
27385
|
-
* // ...
|
|
27386
|
-
* })
|
|
27387
|
-
* ```
|
|
27388
|
-
*
|
|
27389
|
-
* Fired when a {@link Amity.InternalUser} has been flagged
|
|
27390
|
-
*
|
|
27391
|
-
* @param callback The function to call when the event was fired
|
|
27392
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
27393
|
-
*
|
|
27394
|
-
* @category User Events
|
|
27395
|
-
*/
|
|
27396
|
-
const onUserFlagged = (callback) => createUserEventSubscriber('user.flagged', callback);
|
|
27397
|
-
|
|
27398
|
-
/**
|
|
27399
|
-
* ```js
|
|
27400
|
-
* import { onUserUnflagged } from '@amityco/ts-sdk'
|
|
27401
|
-
* const dispose = onUserUnflagged(user => {
|
|
27402
|
-
* // ...
|
|
27403
|
-
* })
|
|
27404
|
-
* ```
|
|
27405
|
-
*
|
|
27406
|
-
* Fired when a flag has been removed from a {@link Amity.InternalUser}
|
|
27407
|
-
*
|
|
27408
|
-
* @param callback The function to call when the event was fired
|
|
27409
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
27410
|
-
*
|
|
27411
|
-
* @category User Events
|
|
27412
|
-
*/
|
|
27413
|
-
const onUserUnflagged = (callback) => createUserEventSubscriber('user.unflagged', callback);
|
|
27414
|
-
|
|
27415
|
-
/**
|
|
27416
|
-
* ```js
|
|
27417
|
-
* import { onUserFlagCleared } from '@amityco/ts-sdk'
|
|
27418
|
-
* const dispose = onUserFlagCleared(user => {
|
|
27419
|
-
* // ...
|
|
27420
|
-
* })
|
|
27421
|
-
* ```
|
|
27422
|
-
*
|
|
27423
|
-
* Fired when flags have been cleared for a {@link Amity.InternalUser}
|
|
27424
|
-
*
|
|
27425
|
-
* @param callback The function to call when the event was fired
|
|
27426
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
27427
|
-
*
|
|
27428
|
-
* @category User Events
|
|
27429
|
-
*/
|
|
27430
|
-
const onUserFlagCleared = (callback) => createUserEventSubscriber('user.flagCleared', callback);
|
|
27431
|
-
|
|
27432
27744
|
/**
|
|
27433
27745
|
* ```js
|
|
27434
27746
|
* import { onUserFetched } from '@amityco/ts-sdk'
|
|
@@ -27539,7 +27851,7 @@ const getUser$1 = (userId, callback) => {
|
|
|
27539
27851
|
return liveObject(userId, reactor, 'userId', getUser$2, [
|
|
27540
27852
|
onUserFetched,
|
|
27541
27853
|
onUserUpdated,
|
|
27542
|
-
onUserDeleted,
|
|
27854
|
+
onUserDeleted$2,
|
|
27543
27855
|
onUserFlagged,
|
|
27544
27856
|
onUserUnflagged,
|
|
27545
27857
|
onUserFlagCleared,
|
|
@@ -27547,51 +27859,6 @@ const getUser$1 = (userId, callback) => {
|
|
|
27547
27859
|
};
|
|
27548
27860
|
/* end_public_function */
|
|
27549
27861
|
|
|
27550
|
-
class PaginationController {
|
|
27551
|
-
constructor(queryParams) {
|
|
27552
|
-
const { http } = getActiveClient();
|
|
27553
|
-
this.queryParams = queryParams;
|
|
27554
|
-
this.http = http;
|
|
27555
|
-
}
|
|
27556
|
-
loadFirstPage() {
|
|
27557
|
-
return this.onFetch("first" /* Amity.LiveCollectionPageDirection.FIRST */);
|
|
27558
|
-
}
|
|
27559
|
-
loadNextPage() {
|
|
27560
|
-
return this.onFetch("next" /* Amity.LiveCollectionPageDirection.NEXT */);
|
|
27561
|
-
}
|
|
27562
|
-
loadPreviousPage() {
|
|
27563
|
-
return this.onFetch("prev" /* Amity.LiveCollectionPageDirection.PREV */);
|
|
27564
|
-
}
|
|
27565
|
-
async onFetch(direction = "first" /* Amity.LiveCollectionPageDirection.FIRST */) {
|
|
27566
|
-
var _a, _b, _c, _d;
|
|
27567
|
-
if (direction === 'prev' && !this.previousToken)
|
|
27568
|
-
return;
|
|
27569
|
-
if (direction === 'next' && !this.nextToken)
|
|
27570
|
-
return;
|
|
27571
|
-
let token;
|
|
27572
|
-
if (direction === 'prev')
|
|
27573
|
-
token = this.previousToken;
|
|
27574
|
-
if (direction === 'next')
|
|
27575
|
-
token = this.nextToken;
|
|
27576
|
-
const queryResponse = await this.getRequest(this.queryParams, token);
|
|
27577
|
-
if (direction === 'first') {
|
|
27578
|
-
this.nextToken = (_a = queryResponse.paging) === null || _a === void 0 ? void 0 : _a.next;
|
|
27579
|
-
this.previousToken = (_b = queryResponse.paging) === null || _b === void 0 ? void 0 : _b.previous;
|
|
27580
|
-
}
|
|
27581
|
-
if (direction === 'prev')
|
|
27582
|
-
this.previousToken = (_c = queryResponse.paging) === null || _c === void 0 ? void 0 : _c.previous;
|
|
27583
|
-
if (direction === 'next')
|
|
27584
|
-
this.nextToken = (_d = queryResponse.paging) === null || _d === void 0 ? void 0 : _d.next;
|
|
27585
|
-
return queryResponse;
|
|
27586
|
-
}
|
|
27587
|
-
getNextToken() {
|
|
27588
|
-
return this.nextToken;
|
|
27589
|
-
}
|
|
27590
|
-
getPrevToken() {
|
|
27591
|
-
return this.previousToken;
|
|
27592
|
-
}
|
|
27593
|
-
}
|
|
27594
|
-
|
|
27595
27862
|
class UserPaginationController extends PaginationController {
|
|
27596
27863
|
async getRequest(queryParams, token) {
|
|
27597
27864
|
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, displayName } = queryParams, params = __rest(queryParams, ["limit", "displayName"]);
|
|
@@ -27603,13 +27870,6 @@ class UserPaginationController extends PaginationController {
|
|
|
27603
27870
|
}
|
|
27604
27871
|
}
|
|
27605
27872
|
|
|
27606
|
-
class QueryStreamController {
|
|
27607
|
-
constructor(query, cacheKey) {
|
|
27608
|
-
this.query = query;
|
|
27609
|
-
this.cacheKey = cacheKey;
|
|
27610
|
-
}
|
|
27611
|
-
}
|
|
27612
|
-
|
|
27613
27873
|
class UserQueryStreamController extends QueryStreamController {
|
|
27614
27874
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
27615
27875
|
super(query, cacheKey);
|
|
@@ -27656,122 +27916,6 @@ class UserQueryStreamController extends QueryStreamController {
|
|
|
27656
27916
|
}
|
|
27657
27917
|
}
|
|
27658
27918
|
|
|
27659
|
-
class PaginationNoPageController {
|
|
27660
|
-
constructor(queryParams) {
|
|
27661
|
-
const { http } = getActiveClient();
|
|
27662
|
-
this.queryParams = queryParams;
|
|
27663
|
-
this.http = http;
|
|
27664
|
-
}
|
|
27665
|
-
async onFetch() {
|
|
27666
|
-
const queryResponse = await this.getRequest(this.queryParams);
|
|
27667
|
-
return queryResponse;
|
|
27668
|
-
}
|
|
27669
|
-
}
|
|
27670
|
-
|
|
27671
|
-
class LiveCollectionController {
|
|
27672
|
-
constructor(paginationController, queryStreamId, cacheKey, callback) {
|
|
27673
|
-
this.paginationController = paginationController;
|
|
27674
|
-
this.queryStreamId = queryStreamId;
|
|
27675
|
-
this.cacheKey = cacheKey;
|
|
27676
|
-
this.callback = callback;
|
|
27677
|
-
}
|
|
27678
|
-
async refresh() {
|
|
27679
|
-
try {
|
|
27680
|
-
let result;
|
|
27681
|
-
if (this.paginationController instanceof PaginationNoPageController) {
|
|
27682
|
-
result = await this.paginationController.onFetch();
|
|
27683
|
-
}
|
|
27684
|
-
else {
|
|
27685
|
-
result = await this.paginationController.loadFirstPage();
|
|
27686
|
-
}
|
|
27687
|
-
if (!result)
|
|
27688
|
-
return;
|
|
27689
|
-
await this.persistModel(result);
|
|
27690
|
-
this.persistQueryStream({
|
|
27691
|
-
response: result,
|
|
27692
|
-
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
27693
|
-
refresh: true,
|
|
27694
|
-
});
|
|
27695
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
27696
|
-
}
|
|
27697
|
-
catch (e) {
|
|
27698
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
27699
|
-
}
|
|
27700
|
-
}
|
|
27701
|
-
loadPage({ initial = false, direction = "next" /* Amity.LiveCollectionPageDirection.NEXT */, }) {
|
|
27702
|
-
this.setup();
|
|
27703
|
-
this.notifyChange({ origin: "local" /* Amity.LiveDataOrigin.LOCAL */, loading: true });
|
|
27704
|
-
if (initial) {
|
|
27705
|
-
this.refresh();
|
|
27706
|
-
}
|
|
27707
|
-
else if (direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */) {
|
|
27708
|
-
this.loadPrevPage();
|
|
27709
|
-
}
|
|
27710
|
-
else if (direction === "next" /* Amity.LiveCollectionPageDirection.NEXT */) {
|
|
27711
|
-
this.loadNextPage();
|
|
27712
|
-
}
|
|
27713
|
-
}
|
|
27714
|
-
async loadNextPage() {
|
|
27715
|
-
try {
|
|
27716
|
-
if (this.paginationController instanceof PaginationNoPageController)
|
|
27717
|
-
return;
|
|
27718
|
-
const result = await this.paginationController.loadNextPage();
|
|
27719
|
-
if (!result)
|
|
27720
|
-
return;
|
|
27721
|
-
await this.persistModel(result);
|
|
27722
|
-
this.persistQueryStream({
|
|
27723
|
-
response: result,
|
|
27724
|
-
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
27725
|
-
});
|
|
27726
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
27727
|
-
}
|
|
27728
|
-
catch (e) {
|
|
27729
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
27730
|
-
}
|
|
27731
|
-
}
|
|
27732
|
-
async loadPrevPage() {
|
|
27733
|
-
try {
|
|
27734
|
-
if (this.paginationController instanceof PaginationNoPageController)
|
|
27735
|
-
return;
|
|
27736
|
-
const result = await this.paginationController.loadPreviousPage();
|
|
27737
|
-
if (!result)
|
|
27738
|
-
return;
|
|
27739
|
-
await this.persistModel(result);
|
|
27740
|
-
this.persistQueryStream({
|
|
27741
|
-
response: result,
|
|
27742
|
-
direction: "prev" /* Amity.LiveCollectionPageDirection.PREV */,
|
|
27743
|
-
});
|
|
27744
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
27745
|
-
}
|
|
27746
|
-
catch (e) {
|
|
27747
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
27748
|
-
}
|
|
27749
|
-
}
|
|
27750
|
-
shouldNotify(data) {
|
|
27751
|
-
const newData = data.map(convertGetterPropsToStatic).map(removeFunctionProperties);
|
|
27752
|
-
if (isEqual(this.snapshot, newData))
|
|
27753
|
-
return false;
|
|
27754
|
-
this.snapshot = newData;
|
|
27755
|
-
return true;
|
|
27756
|
-
}
|
|
27757
|
-
getCacheKey() {
|
|
27758
|
-
return this.cacheKey;
|
|
27759
|
-
}
|
|
27760
|
-
}
|
|
27761
|
-
|
|
27762
|
-
var EnumUserActions;
|
|
27763
|
-
(function (EnumUserActions) {
|
|
27764
|
-
EnumUserActions["OnUserDeleted"] = "onUserDeleted";
|
|
27765
|
-
EnumUserActions["OnUserUpdated"] = "onUserUpdated";
|
|
27766
|
-
EnumUserActions["OnUserFlagged"] = "onUserFlagged";
|
|
27767
|
-
EnumUserActions["OnUserUnflagged"] = "onUserUnflagged";
|
|
27768
|
-
EnumUserActions["OnUserFlagCleared"] = "onUserFlagCleared";
|
|
27769
|
-
})(EnumUserActions || (EnumUserActions = {}));
|
|
27770
|
-
|
|
27771
|
-
function isNonNullable(value) {
|
|
27772
|
-
return value != null;
|
|
27773
|
-
}
|
|
27774
|
-
|
|
27775
27919
|
class UserLiveCollectionController extends LiveCollectionController {
|
|
27776
27920
|
constructor(query, callback) {
|
|
27777
27921
|
const queryStreamId = hash(query);
|
|
@@ -27801,7 +27945,7 @@ class UserLiveCollectionController extends LiveCollectionController {
|
|
|
27801
27945
|
}
|
|
27802
27946
|
startSubscription() {
|
|
27803
27947
|
return this.queryStreamController.subscribeRTE([
|
|
27804
|
-
{ fn: onUserDeleted, action: EnumUserActions.OnUserDeleted },
|
|
27948
|
+
{ fn: onUserDeleted$2, action: EnumUserActions.OnUserDeleted },
|
|
27805
27949
|
{ fn: onUserUpdated, action: EnumUserActions.OnUserUpdated },
|
|
27806
27950
|
{ fn: onUserFlagged, action: EnumUserActions.OnUserFlagged },
|
|
27807
27951
|
{ fn: onUserUnflagged, action: EnumUserActions.OnUserUnflagged },
|
|
@@ -27833,11 +27977,11 @@ class UserLiveCollectionController extends LiveCollectionController {
|
|
|
27833
27977
|
if (!this.query.displayName) {
|
|
27834
27978
|
const sortFn = (() => {
|
|
27835
27979
|
switch (this.query.sortBy) {
|
|
27836
|
-
case
|
|
27980
|
+
case 'firstCreated':
|
|
27837
27981
|
return sortByFirstCreated;
|
|
27838
|
-
case
|
|
27982
|
+
case 'lastCreated':
|
|
27839
27983
|
return sortByLastCreated;
|
|
27840
|
-
case
|
|
27984
|
+
case 'displayName':
|
|
27841
27985
|
return sortByDisplayName;
|
|
27842
27986
|
default:
|
|
27843
27987
|
return sortByLastCreated;
|
|
@@ -27968,7 +28112,7 @@ const observeUser = (userId, callback) => {
|
|
|
27968
28112
|
(_c = callback[action]) === null || _c === void 0 ? void 0 : _c.call(callback, newResult);
|
|
27969
28113
|
};
|
|
27970
28114
|
const disposers = [];
|
|
27971
|
-
disposers.push(onUserUpdated(data => router({ data, loading: false, origin: 'event' }, 'onUpdate')), onUserDeleted(data => router({ data, loading: false, origin: 'event' }, 'onDelete')), onUserFlagged(data => router({ data, loading: false, origin: 'event' }, 'onFlagged')), onUserUnflagged(data => router({ data, loading: false, origin: 'event' }, 'onUnflagged')), onUserFlagCleared(data => router({ data, loading: false, origin: 'event' }, 'onFlagCleared')));
|
|
28115
|
+
disposers.push(onUserUpdated(data => router({ data, loading: false, origin: 'event' }, 'onUpdate')), onUserDeleted$2(data => router({ data, loading: false, origin: 'event' }, 'onDelete')), onUserFlagged(data => router({ data, loading: false, origin: 'event' }, 'onFlagged')), onUserUnflagged(data => router({ data, loading: false, origin: 'event' }, 'onUnflagged')), onUserFlagCleared(data => router({ data, loading: false, origin: 'event' }, 'onFlagCleared')));
|
|
27972
28116
|
runQuery(createQuery(getUser, userId), result => result.data && router(result, 'onFetch'));
|
|
27973
28117
|
return () => {
|
|
27974
28118
|
log(`observeUser(tmpid: ${timestamp}) > dispose`);
|
|
@@ -28063,7 +28207,7 @@ class SearchUserLiveCollectionController extends LiveCollectionController {
|
|
|
28063
28207
|
}
|
|
28064
28208
|
startSubscription() {
|
|
28065
28209
|
return this.queryStreamController.subscribeRTE([
|
|
28066
|
-
{ fn: onUserDeleted, action: EnumUserActions.OnUserDeleted },
|
|
28210
|
+
{ fn: onUserDeleted$2, action: EnumUserActions.OnUserDeleted },
|
|
28067
28211
|
{ fn: onUserUpdated, action: EnumUserActions.OnUserUpdated },
|
|
28068
28212
|
{ fn: onUserFlagged, action: EnumUserActions.OnUserFlagged },
|
|
28069
28213
|
{ fn: onUserUnflagged, action: EnumUserActions.OnUserUnflagged },
|
|
@@ -28304,7 +28448,7 @@ var index$j = /*#__PURE__*/Object.freeze({
|
|
|
28304
28448
|
unflagUser: unflagUser,
|
|
28305
28449
|
isUserFlaggedByMe: isUserFlaggedByMe,
|
|
28306
28450
|
onUserUpdated: onUserUpdated,
|
|
28307
|
-
onUserDeleted: onUserDeleted,
|
|
28451
|
+
onUserDeleted: onUserDeleted$2,
|
|
28308
28452
|
onUserFlagged: onUserFlagged,
|
|
28309
28453
|
onUserUnflagged: onUserUnflagged,
|
|
28310
28454
|
onUserFlagCleared: onUserFlagCleared,
|
|
@@ -29211,6 +29355,7 @@ const prepareCommentFromFlaggedEvent = (payload) => {
|
|
|
29211
29355
|
* @async
|
|
29212
29356
|
* */
|
|
29213
29357
|
const addReaction = async (referenceType, referenceId, reactionName) => {
|
|
29358
|
+
var _a, _b;
|
|
29214
29359
|
const client = getActiveClient();
|
|
29215
29360
|
client.log('reaction/createReaction', {
|
|
29216
29361
|
referenceId,
|
|
@@ -29229,8 +29374,21 @@ const addReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
29229
29374
|
'get',
|
|
29230
29375
|
referenceId,
|
|
29231
29376
|
]);
|
|
29232
|
-
(model
|
|
29233
|
-
|
|
29377
|
+
if (!model)
|
|
29378
|
+
return true;
|
|
29379
|
+
const updatedModel = Object.assign(Object.assign({}, model.data), { reactionsCount: model.data.reactionsCount + 1, myReactions: [...((_a = model.data.myReactions) !== null && _a !== void 0 ? _a : []), reactionName], reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: ((_b = model.data.reactions[reactionName]) !== null && _b !== void 0 ? _b : 0) + 1 }) });
|
|
29380
|
+
if (referenceType === 'comment') {
|
|
29381
|
+
fireEvent('local.comment.addReaction', {
|
|
29382
|
+
comment: updatedModel,
|
|
29383
|
+
});
|
|
29384
|
+
return true;
|
|
29385
|
+
}
|
|
29386
|
+
if (referenceType === 'post') {
|
|
29387
|
+
fireEvent('local.post.addReaction', {
|
|
29388
|
+
post: updatedModel,
|
|
29389
|
+
});
|
|
29390
|
+
return true;
|
|
29391
|
+
}
|
|
29234
29392
|
}
|
|
29235
29393
|
return true;
|
|
29236
29394
|
};
|
|
@@ -29295,6 +29453,7 @@ addReaction.optimistically = (referenceType, referenceId, reactionName) => {
|
|
|
29295
29453
|
* @async
|
|
29296
29454
|
* */
|
|
29297
29455
|
const removeReaction = async (referenceType, referenceId, reactionName) => {
|
|
29456
|
+
var _a, _b;
|
|
29298
29457
|
const client = getActiveClient();
|
|
29299
29458
|
client.log('reaction/removeReaction', {
|
|
29300
29459
|
referenceId,
|
|
@@ -29315,8 +29474,21 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
29315
29474
|
'get',
|
|
29316
29475
|
referenceId,
|
|
29317
29476
|
]);
|
|
29318
|
-
(model
|
|
29319
|
-
|
|
29477
|
+
if (!model)
|
|
29478
|
+
return true;
|
|
29479
|
+
const updatedModel = Object.assign(Object.assign({}, model.data), { reactionsCount: Math.max(0, model.data.reactionsCount - 1), myReactions: ((_a = model.data.myReactions) !== null && _a !== void 0 ? _a : []).filter(item => item !== reactionName), reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: Math.max(0, ((_b = model.data.reactions[reactionName]) !== null && _b !== void 0 ? _b : 0) - 1) }) });
|
|
29480
|
+
if (referenceType === 'comment') {
|
|
29481
|
+
fireEvent('local.comment.removeReaction', {
|
|
29482
|
+
comment: updatedModel,
|
|
29483
|
+
});
|
|
29484
|
+
return true;
|
|
29485
|
+
}
|
|
29486
|
+
if (referenceType === 'post') {
|
|
29487
|
+
fireEvent('local.post.removeReaction', {
|
|
29488
|
+
post: updatedModel,
|
|
29489
|
+
});
|
|
29490
|
+
return true;
|
|
29491
|
+
}
|
|
29320
29492
|
}
|
|
29321
29493
|
return true;
|
|
29322
29494
|
};
|
|
@@ -29361,6 +29533,66 @@ removeReaction.optimistically = (referenceType, referenceId, reactionName) => {
|
|
|
29361
29533
|
return (_e = !((_d = reaction === null || reaction === void 0 ? void 0 : reaction.myReactions) === null || _d === void 0 ? void 0 : _d.includes(reactionName))) !== null && _e !== void 0 ? _e : false;
|
|
29362
29534
|
};
|
|
29363
29535
|
|
|
29536
|
+
const getMatchPostSetting = (value) => {
|
|
29537
|
+
var _a;
|
|
29538
|
+
return (_a = Object.keys(CommunityPostSettingMaps).find(key => value.needApprovalOnPostCreation ===
|
|
29539
|
+
CommunityPostSettingMaps[key].needApprovalOnPostCreation &&
|
|
29540
|
+
value.onlyAdminCanPost === CommunityPostSettingMaps[key].onlyAdminCanPost)) !== null && _a !== void 0 ? _a : DefaultCommunityPostSetting;
|
|
29541
|
+
};
|
|
29542
|
+
function addPostSetting({ communities }) {
|
|
29543
|
+
return communities.map((_a) => {
|
|
29544
|
+
var { needApprovalOnPostCreation, onlyAdminCanPost } = _a, restCommunityPayload = __rest(_a, ["needApprovalOnPostCreation", "onlyAdminCanPost"]);
|
|
29545
|
+
return (Object.assign({ postSetting: getMatchPostSetting({
|
|
29546
|
+
needApprovalOnPostCreation,
|
|
29547
|
+
onlyAdminCanPost,
|
|
29548
|
+
}) }, restCommunityPayload));
|
|
29549
|
+
});
|
|
29550
|
+
}
|
|
29551
|
+
const prepareCommunityPayload = (rawPayload) => {
|
|
29552
|
+
const communitiesWithPostSetting = addPostSetting({ communities: rawPayload.communities });
|
|
29553
|
+
// map users with community
|
|
29554
|
+
const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
|
|
29555
|
+
const user = rawPayload.users.find(user => user.userId === communityUser.userId);
|
|
29556
|
+
return Object.assign(Object.assign({}, communityUser), { user });
|
|
29557
|
+
});
|
|
29558
|
+
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
29559
|
+
return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
29560
|
+
};
|
|
29561
|
+
const prepareCommunityMembershipPayload = (rawPayload) => {
|
|
29562
|
+
const communitiesWithPostSetting = addPostSetting({ communities: rawPayload.communities });
|
|
29563
|
+
// map users with community
|
|
29564
|
+
const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
|
|
29565
|
+
const user = rawPayload.users.find(user => user.userId === communityUser.userId);
|
|
29566
|
+
return Object.assign(Object.assign({}, communityUser), { user });
|
|
29567
|
+
});
|
|
29568
|
+
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
29569
|
+
return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
29570
|
+
};
|
|
29571
|
+
const prepareCommunityRequest = (params) => {
|
|
29572
|
+
const { postSetting = undefined, storySetting } = params, restParam = __rest(params, ["postSetting", "storySetting"]);
|
|
29573
|
+
return Object.assign(Object.assign(Object.assign({}, restParam), (postSetting ? CommunityPostSettingMaps[postSetting] : undefined)), {
|
|
29574
|
+
// Convert story setting to the actual value. (Allow by default)
|
|
29575
|
+
allowCommentInStory: typeof (storySetting === null || storySetting === void 0 ? void 0 : storySetting.enableComment) === 'boolean' ? storySetting.enableComment : true });
|
|
29576
|
+
};
|
|
29577
|
+
|
|
29578
|
+
const preparePostPayload = (postPayload) => {
|
|
29579
|
+
// Unpack community payload by mapping payload field to postSetting value.
|
|
29580
|
+
const communitiesWithPostSetting = addPostSetting({ communities: postPayload.communities });
|
|
29581
|
+
// map users with community
|
|
29582
|
+
const mappedCommunityUsers = postPayload.communityUsers.map(communityUser => {
|
|
29583
|
+
const user = postPayload.users.find(user => user.userId === communityUser.userId);
|
|
29584
|
+
return Object.assign(Object.assign({}, communityUser), { user });
|
|
29585
|
+
});
|
|
29586
|
+
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
29587
|
+
// feed type
|
|
29588
|
+
const posts = postPayload.posts.map(post => {
|
|
29589
|
+
var _a;
|
|
29590
|
+
const feedType = (_a = postPayload.feeds.find(feed => feed.feedId === post.feedId)) === null || _a === void 0 ? void 0 : _a.feedType;
|
|
29591
|
+
return Object.assign(Object.assign({}, post), { feedType });
|
|
29592
|
+
});
|
|
29593
|
+
return Object.assign(Object.assign({}, postPayload), { posts, communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
29594
|
+
};
|
|
29595
|
+
|
|
29364
29596
|
const createPostEventSubscriber = (event, callback) => {
|
|
29365
29597
|
const client = getActiveClient();
|
|
29366
29598
|
const filter = (payload) => {
|
|
@@ -29369,8 +29601,8 @@ const createPostEventSubscriber = (event, callback) => {
|
|
|
29369
29601
|
callback(payload.posts[0]);
|
|
29370
29602
|
}
|
|
29371
29603
|
else {
|
|
29372
|
-
const
|
|
29373
|
-
const
|
|
29604
|
+
const data = preparePostPayload(payload);
|
|
29605
|
+
const { communities } = data;
|
|
29374
29606
|
ingestInCache(data);
|
|
29375
29607
|
if ((communities === null || communities === void 0 ? void 0 : communities[0]) && !['post.updated'].includes(event)) {
|
|
29376
29608
|
fireEvent('community.updated', {
|
|
@@ -29397,7 +29629,7 @@ const createPostEventSubscriber = (event, callback) => {
|
|
|
29397
29629
|
// But if it is hard delete, it will pushed into tombstone before fire an event to BE. it means it will stay in tombstone already
|
|
29398
29630
|
// and will got skip to notify in a previous code block
|
|
29399
29631
|
if (postedUserId !== client.userId) {
|
|
29400
|
-
|
|
29632
|
+
dropFromCache(['post', 'get', postId]);
|
|
29401
29633
|
}
|
|
29402
29634
|
return callback(payload.posts[0]);
|
|
29403
29635
|
}
|
|
@@ -29414,6 +29646,32 @@ const createPostEventSubscriber = (event, callback) => {
|
|
|
29414
29646
|
}
|
|
29415
29647
|
};
|
|
29416
29648
|
return createEventSubscriber(client, event, event, filter);
|
|
29649
|
+
};
|
|
29650
|
+
const createLocalPostEventSubscriber = (event, callback) => {
|
|
29651
|
+
const client = getActiveClient();
|
|
29652
|
+
const filter = (payload) => {
|
|
29653
|
+
if (!client.cache) {
|
|
29654
|
+
callback(payload.posts[0]);
|
|
29655
|
+
}
|
|
29656
|
+
else {
|
|
29657
|
+
const data = preparePostPayload(payload);
|
|
29658
|
+
const { communities } = data;
|
|
29659
|
+
ingestInCache(data);
|
|
29660
|
+
if ((communities === null || communities === void 0 ? void 0 : communities[0]) && !['local.post.updated'].includes(event)) {
|
|
29661
|
+
fireEvent('community.updated', {
|
|
29662
|
+
communities,
|
|
29663
|
+
categories: [],
|
|
29664
|
+
communityUsers: data.communityUsers,
|
|
29665
|
+
feeds: [],
|
|
29666
|
+
files: [],
|
|
29667
|
+
users: [],
|
|
29668
|
+
});
|
|
29669
|
+
}
|
|
29670
|
+
const post = pullFromCache(['post', 'get', payload.posts[0].postId]);
|
|
29671
|
+
callback(post.data);
|
|
29672
|
+
}
|
|
29673
|
+
};
|
|
29674
|
+
return createEventSubscriber(client, event, event, filter);
|
|
29417
29675
|
};
|
|
29418
29676
|
|
|
29419
29677
|
/**
|
|
@@ -29620,6 +29878,9 @@ const createCommentEventSubscriber = (event, callback) => {
|
|
|
29620
29878
|
comments[0].commentId,
|
|
29621
29879
|
]);
|
|
29622
29880
|
if (['comment.created'].includes(event)) {
|
|
29881
|
+
// NOTE: skip adding comment to parent comment children if it's the same user since we use the local event to update instead.
|
|
29882
|
+
if (event === 'comment.created' && comment.data.userId === client.userId)
|
|
29883
|
+
return;
|
|
29623
29884
|
if (comments[0].parentId) {
|
|
29624
29885
|
const parentComment = pullFromCache([
|
|
29625
29886
|
'comment',
|
|
@@ -29641,6 +29902,58 @@ const createCommentEventSubscriber = (event, callback) => {
|
|
|
29641
29902
|
}
|
|
29642
29903
|
};
|
|
29643
29904
|
return createEventSubscriber(client, event, event, filter);
|
|
29905
|
+
};
|
|
29906
|
+
const createLocalCommentEventSubscriber = (event, callback) => {
|
|
29907
|
+
const client = getActiveClient();
|
|
29908
|
+
const filter = (payload) => {
|
|
29909
|
+
var _a;
|
|
29910
|
+
if (!client.cache) {
|
|
29911
|
+
// TODO: here we are missing specific properties here!
|
|
29912
|
+
callback(LinkedObject.comment(payload.comments[0]));
|
|
29913
|
+
}
|
|
29914
|
+
else {
|
|
29915
|
+
const processed = payload;
|
|
29916
|
+
ingestInCache(processed);
|
|
29917
|
+
const { comments } = processed;
|
|
29918
|
+
if (comments.length > 0) {
|
|
29919
|
+
const comment = pullFromCache([
|
|
29920
|
+
'comment',
|
|
29921
|
+
'get',
|
|
29922
|
+
comments[0].commentId,
|
|
29923
|
+
]);
|
|
29924
|
+
if (['local.comment.created'].includes(event)) {
|
|
29925
|
+
if (comments[0].parentId) {
|
|
29926
|
+
const parentComment = pullFromCache([
|
|
29927
|
+
'comment',
|
|
29928
|
+
'get',
|
|
29929
|
+
comments[0].parentId,
|
|
29930
|
+
]);
|
|
29931
|
+
if (parentComment === null || parentComment === void 0 ? void 0 : parentComment.data) {
|
|
29932
|
+
// Skip to update parent childComment if current comment already exists
|
|
29933
|
+
if (!parentComment.data.children.includes(comments[0].commentId)) {
|
|
29934
|
+
const newParentComment = Object.assign(Object.assign({}, parentComment.data), { childrenNumber: parentComment.data.childrenNumber + 1, children: [...new Set([...parentComment.data.children, comments[0].commentId])] });
|
|
29935
|
+
pushToCache(['comment', 'get', comments[0].parentId], newParentComment);
|
|
29936
|
+
setTimeout(() => {
|
|
29937
|
+
// NOTE: This is workaround solution for emitting event not work properly.
|
|
29938
|
+
fireEvent('comment.updated', {
|
|
29939
|
+
comments: [newParentComment],
|
|
29940
|
+
commentChildren: [],
|
|
29941
|
+
files: [],
|
|
29942
|
+
users: [],
|
|
29943
|
+
communityUsers: [],
|
|
29944
|
+
});
|
|
29945
|
+
}, 200);
|
|
29946
|
+
}
|
|
29947
|
+
}
|
|
29948
|
+
}
|
|
29949
|
+
const queries = (_a = queryCache(['comment', 'query'])) === null || _a === void 0 ? void 0 : _a.filter(({ key }) => { var _a; return ((_a = key[2]) === null || _a === void 0 ? void 0 : _a.referenceId) === comment.data.referenceId; });
|
|
29950
|
+
queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
|
|
29951
|
+
}
|
|
29952
|
+
callback(LinkedObject.comment(comment.data));
|
|
29953
|
+
}
|
|
29954
|
+
}
|
|
29955
|
+
};
|
|
29956
|
+
return createEventSubscriber(client, event, event, filter);
|
|
29644
29957
|
};
|
|
29645
29958
|
|
|
29646
29959
|
/**
|
|
@@ -30200,51 +30513,6 @@ var index$h = /*#__PURE__*/Object.freeze({
|
|
|
30200
30513
|
getReactions: getReactions
|
|
30201
30514
|
});
|
|
30202
30515
|
|
|
30203
|
-
const getMatchPostSetting = (value) => {
|
|
30204
|
-
var _a;
|
|
30205
|
-
return (_a = Object.keys(CommunityPostSettingMaps).find(key => value.needApprovalOnPostCreation ===
|
|
30206
|
-
CommunityPostSettingMaps[key].needApprovalOnPostCreation &&
|
|
30207
|
-
value.onlyAdminCanPost === CommunityPostSettingMaps[key].onlyAdminCanPost)) !== null && _a !== void 0 ? _a : DefaultCommunityPostSetting;
|
|
30208
|
-
};
|
|
30209
|
-
function addPostSetting({ communities }) {
|
|
30210
|
-
return communities.map((_a) => {
|
|
30211
|
-
var { needApprovalOnPostCreation, onlyAdminCanPost } = _a, restCommunityPayload = __rest(_a, ["needApprovalOnPostCreation", "onlyAdminCanPost"]);
|
|
30212
|
-
return (Object.assign({ postSetting: getMatchPostSetting({
|
|
30213
|
-
needApprovalOnPostCreation,
|
|
30214
|
-
onlyAdminCanPost,
|
|
30215
|
-
}) }, restCommunityPayload));
|
|
30216
|
-
});
|
|
30217
|
-
}
|
|
30218
|
-
const prepareCommunityPayload = (rawPayload) => {
|
|
30219
|
-
const communitiesWithPostSetting = addPostSetting({ communities: rawPayload.communities });
|
|
30220
|
-
// map users with community
|
|
30221
|
-
const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
|
|
30222
|
-
const user = rawPayload.users.find(user => user.userId === communityUser.userId);
|
|
30223
|
-
return Object.assign(Object.assign({}, communityUser), { user });
|
|
30224
|
-
});
|
|
30225
|
-
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
30226
|
-
return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
30227
|
-
};
|
|
30228
|
-
const prepareCommunityRequest = (params) => {
|
|
30229
|
-
const { postSetting = undefined, storySetting } = params, restParam = __rest(params, ["postSetting", "storySetting"]);
|
|
30230
|
-
return Object.assign(Object.assign(Object.assign({}, restParam), (postSetting ? CommunityPostSettingMaps[postSetting] : undefined)), {
|
|
30231
|
-
// Convert story setting to the actual value. (Allow by default)
|
|
30232
|
-
allowCommentInStory: typeof (storySetting === null || storySetting === void 0 ? void 0 : storySetting.enableComment) === 'boolean' ? storySetting.enableComment : true });
|
|
30233
|
-
};
|
|
30234
|
-
|
|
30235
|
-
const preparePostPayload = (postPayload) => {
|
|
30236
|
-
const { posts } = postPayload;
|
|
30237
|
-
// Unpack community payload by mapping payload field to postSetting value.
|
|
30238
|
-
const communitiesWithPostSetting = addPostSetting({ communities: postPayload.communities });
|
|
30239
|
-
// map users with community
|
|
30240
|
-
const mappedCommunityUsers = postPayload.communityUsers.map(communityUser => {
|
|
30241
|
-
const user = postPayload.users.find(user => user.userId === communityUser.userId);
|
|
30242
|
-
return Object.assign(Object.assign({}, communityUser), { user });
|
|
30243
|
-
});
|
|
30244
|
-
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
30245
|
-
return Object.assign(Object.assign({}, postPayload), { posts, communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
30246
|
-
};
|
|
30247
|
-
|
|
30248
30516
|
function prepareCommentPayload(commentPayload) {
|
|
30249
30517
|
const { comments } = commentPayload;
|
|
30250
30518
|
return Object.assign(Object.assign({}, commentPayload), { comments: comments.map(comment => {
|
|
@@ -33836,10 +34104,12 @@ const removeMembers$1 = async (channelId, userIds) => {
|
|
|
33836
34104
|
*/
|
|
33837
34105
|
class ChannelMemberPaginationController extends PaginationController {
|
|
33838
34106
|
async getRequest(queryParams, token) {
|
|
33839
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
34107
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
|
|
33840
34108
|
const options = token ? { token } : { limit };
|
|
34109
|
+
const isDeleted = includeDeleted === false ? false : undefined;
|
|
33841
34110
|
const { data: queryResponse } = await this.http.get(`/api/v4/channels/${encodeURIComponent(params.channelId)}/users`, {
|
|
33842
|
-
params: Object.assign(Object.assign({}, params), { options
|
|
34111
|
+
params: Object.assign(Object.assign({}, params), { options,
|
|
34112
|
+
isDeleted }),
|
|
33843
34113
|
});
|
|
33844
34114
|
return queryResponse;
|
|
33845
34115
|
}
|
|
@@ -33905,6 +34175,33 @@ class ChannelMemberQueryStreamController extends QueryStreamController {
|
|
|
33905
34175
|
}
|
|
33906
34176
|
}
|
|
33907
34177
|
|
|
34178
|
+
const onUserDeleted$1 = (channelId) => (callback) => {
|
|
34179
|
+
const client = getActiveClient();
|
|
34180
|
+
const filter = (payload) => {
|
|
34181
|
+
var _a, _b;
|
|
34182
|
+
const userPayload = prepareUserPayload(payload);
|
|
34183
|
+
if (userPayload.users.length === 0)
|
|
34184
|
+
return;
|
|
34185
|
+
const user = userPayload.users[0];
|
|
34186
|
+
ingestInCache(userPayload);
|
|
34187
|
+
const channelUserCacheKey = getResolver('channelUsers')({
|
|
34188
|
+
channelId,
|
|
34189
|
+
userId: user.userId,
|
|
34190
|
+
});
|
|
34191
|
+
const cacheData = (_a = pullFromCache([
|
|
34192
|
+
'channelUsers',
|
|
34193
|
+
'get',
|
|
34194
|
+
channelUserCacheKey,
|
|
34195
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
34196
|
+
upsertInCache(['channelUsers', 'get', channelUserCacheKey], Object.assign(Object.assign({}, cacheData), { user }));
|
|
34197
|
+
const channel = (_b = pullFromCache(['channel', 'get', channelId])) === null || _b === void 0 ? void 0 : _b.data;
|
|
34198
|
+
if (!channel)
|
|
34199
|
+
return;
|
|
34200
|
+
callback(channel, cacheData);
|
|
34201
|
+
};
|
|
34202
|
+
return createEventSubscriber(client, 'user.deleted', 'user.deleted', filter);
|
|
34203
|
+
};
|
|
34204
|
+
|
|
33908
34205
|
/* eslint-disable no-use-before-define */
|
|
33909
34206
|
class ChannelMemberLiveCollectionController extends LiveCollectionController {
|
|
33910
34207
|
constructor(query, callback) {
|
|
@@ -33943,6 +34240,7 @@ class ChannelMemberLiveCollectionController extends LiveCollectionController {
|
|
|
33943
34240
|
{ fn: onChannelMemberUnbanned, action: 'onChannelMemberUnbanned' },
|
|
33944
34241
|
{ fn: onChannelMemberRoleAdded, action: 'onChannelMemberRoleAdded' },
|
|
33945
34242
|
{ fn: onChannelMemberRoleRemoved, action: 'onChannelMemberRoleRemoved' },
|
|
34243
|
+
{ fn: onUserDeleted$1(this.query.channelId), action: 'onChannelMemberChanged' },
|
|
33946
34244
|
]);
|
|
33947
34245
|
}
|
|
33948
34246
|
notifyChange({ origin, loading, error }) {
|
|
@@ -33989,8 +34287,8 @@ class ChannelMemberLiveCollectionController extends LiveCollectionController {
|
|
|
33989
34287
|
console.warn('`search` param will be deprecated in the next major release. If you want to search channel members by displayName, Please use `searchMembers()` instead.');
|
|
33990
34288
|
channelMembers = filterBySearchTerm(channelMembers, this.query.search);
|
|
33991
34289
|
}
|
|
33992
|
-
if (
|
|
33993
|
-
channelMembers = channelMembers.filter(member => { var _a; return ((_a = member.user) === null || _a === void 0 ? void 0 : _a.isDeleted)
|
|
34290
|
+
if (this.query.includeDeleted === false) {
|
|
34291
|
+
channelMembers = channelMembers.filter(member => { var _a; return ((_a = member.user) === null || _a === void 0 ? void 0 : _a.isDeleted) !== true; });
|
|
33994
34292
|
}
|
|
33995
34293
|
// sort, 'lastCreated' is the default sort order
|
|
33996
34294
|
const sortBy = this.query.sortBy ? this.query.sortBy : 'lastCreated';
|
|
@@ -34808,7 +35106,7 @@ function getEventRelatedMember(event, payload) {
|
|
|
34808
35106
|
}
|
|
34809
35107
|
// NOTE: backend returns the one who took the action and the one on whom
|
|
34810
35108
|
// the action was taken. We need the 2nd one
|
|
34811
|
-
if (event === 'community.userRemoved') {
|
|
35109
|
+
if (event === 'community.userRemoved' || event === 'local.community.userRemoved') {
|
|
34812
35110
|
return payload.communityUsers.filter(x => x.communityMembership === 'none');
|
|
34813
35111
|
}
|
|
34814
35112
|
if (event === 'community.userBanned') {
|
|
@@ -34856,6 +35154,43 @@ const createCommunityMemberEventSubscriber = (event, callback) => {
|
|
|
34856
35154
|
}
|
|
34857
35155
|
};
|
|
34858
35156
|
return createEventSubscriber(client, event, event, filter);
|
|
35157
|
+
};
|
|
35158
|
+
const createLocalCommunityMemberEventSubscriber = (event, callback) => {
|
|
35159
|
+
const client = getActiveClient();
|
|
35160
|
+
const filter = (payload) => {
|
|
35161
|
+
const preparedPayload = prepareCommunityPayload(payload);
|
|
35162
|
+
const { communities, communityUsers } = preparedPayload;
|
|
35163
|
+
/*
|
|
35164
|
+
* community.isJoined is not part of the communityMembership payload, and needs
|
|
35165
|
+
* to be calculated based on the communityMembership value
|
|
35166
|
+
*/
|
|
35167
|
+
const communitiesWithMembership = updateMembershipStatus(communities, communityUsers);
|
|
35168
|
+
preparedPayload.communities = communitiesWithMembership;
|
|
35169
|
+
if (!client.cache) {
|
|
35170
|
+
// TODO: here we are missing specific properties here!
|
|
35171
|
+
callback(preparedPayload.communities[0], getEventRelatedMember(event, preparedPayload));
|
|
35172
|
+
}
|
|
35173
|
+
else {
|
|
35174
|
+
ingestInCache(preparedPayload);
|
|
35175
|
+
const community = pullFromCache([
|
|
35176
|
+
'community',
|
|
35177
|
+
'get',
|
|
35178
|
+
preparedPayload.communities[0].communityId,
|
|
35179
|
+
]);
|
|
35180
|
+
const members = getEventRelatedMember(event, preparedPayload)
|
|
35181
|
+
.map(member => {
|
|
35182
|
+
const memberCache = pullFromCache([
|
|
35183
|
+
'communityUsers',
|
|
35184
|
+
'get',
|
|
35185
|
+
getResolver('communityUsers')(member),
|
|
35186
|
+
]);
|
|
35187
|
+
return memberCache === null || memberCache === void 0 ? void 0 : memberCache.data;
|
|
35188
|
+
})
|
|
35189
|
+
.filter(isNonNullable);
|
|
35190
|
+
callback(community.data, members);
|
|
35191
|
+
}
|
|
35192
|
+
};
|
|
35193
|
+
return createEventSubscriber(client, event, event, filter);
|
|
34859
35194
|
};
|
|
34860
35195
|
|
|
34861
35196
|
/**
|
|
@@ -34977,6 +35312,40 @@ const onCommunityUserRoleAdded = (callback) => createCommunityMemberEventSubscri
|
|
|
34977
35312
|
*/
|
|
34978
35313
|
const onCommunityUserRoleRemoved = (callback) => createCommunityMemberEventSubscriber('community.roleRemoved', callback);
|
|
34979
35314
|
|
|
35315
|
+
/**
|
|
35316
|
+
* ```js
|
|
35317
|
+
* import { onLocalCommunityUserAdded } from '@amityco/ts-sdk'
|
|
35318
|
+
* const dispose = onLocalCommunityUserAdded((community, member) => {
|
|
35319
|
+
* // ...
|
|
35320
|
+
* })
|
|
35321
|
+
* ```
|
|
35322
|
+
*
|
|
35323
|
+
* Fired when a user has been added to a {@link Amity.Community}
|
|
35324
|
+
*
|
|
35325
|
+
* @param callback The function to call when the event was fired
|
|
35326
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
35327
|
+
*
|
|
35328
|
+
* @category Community Events
|
|
35329
|
+
*/
|
|
35330
|
+
const onLocalCommunityUserAdded = (callback) => createLocalCommunityMemberEventSubscriber('local.community.userAdded', callback);
|
|
35331
|
+
|
|
35332
|
+
/**
|
|
35333
|
+
* ```js
|
|
35334
|
+
* import { onLocalCommunityUserRemoved } from '@amityco/ts-sdk'
|
|
35335
|
+
* const dispose = onLocalCommunityUserRemoved((community, member) => {
|
|
35336
|
+
* // ...
|
|
35337
|
+
* })
|
|
35338
|
+
* ```
|
|
35339
|
+
*
|
|
35340
|
+
* Fired when a user has been removed from a {@link Amity.Community}
|
|
35341
|
+
*
|
|
35342
|
+
* @param callback The function to call when the event was fired
|
|
35343
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
35344
|
+
*
|
|
35345
|
+
* @category Community Events
|
|
35346
|
+
*/
|
|
35347
|
+
const onLocalCommunityUserRemoved = (callback) => createLocalCommunityMemberEventSubscriber('local.community.userRemoved', callback);
|
|
35348
|
+
|
|
34980
35349
|
/**
|
|
34981
35350
|
* ```js
|
|
34982
35351
|
* import { onCommunityJoined } from '@amityco/ts-sdk'
|
|
@@ -35129,6 +35498,9 @@ var EnumCommunityMemberActions$1;
|
|
|
35129
35498
|
EnumCommunityMemberActions["OnCommunityUserRoleRemoved"] = "onCommunityUserRoleRemoved";
|
|
35130
35499
|
EnumCommunityMemberActions["OnCommunityUserUnbanned"] = "onCommunityUserUnbanned";
|
|
35131
35500
|
EnumCommunityMemberActions["OnMemberCountChanged"] = "OnMemberCountChanged";
|
|
35501
|
+
EnumCommunityMemberActions["OnCommunityUserAdded"] = "OnCommunityUserAdded";
|
|
35502
|
+
EnumCommunityMemberActions["onCommunityUserRemoved"] = "onCommunityUserRemoved";
|
|
35503
|
+
EnumCommunityMemberActions["OnUserDeleted"] = "OnUserDeleted";
|
|
35132
35504
|
})(EnumCommunityMemberActions$1 || (EnumCommunityMemberActions$1 = {}));
|
|
35133
35505
|
|
|
35134
35506
|
/* begin_public_function
|
|
@@ -35153,7 +35525,7 @@ const addMembers = async (communityId, userIds) => {
|
|
|
35153
35525
|
const client = getActiveClient();
|
|
35154
35526
|
client.log('community/moderation/addMembers', communityId, userIds);
|
|
35155
35527
|
const { data: payload } = await client.http.post(`/api/v3/communities/${communityId}/users`, { communityId, userIds });
|
|
35156
|
-
fireEvent('community.userAdded', payload);
|
|
35528
|
+
fireEvent('local.community.userAdded', payload);
|
|
35157
35529
|
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
35158
35530
|
if (client.cache)
|
|
35159
35531
|
ingestInCache(data);
|
|
@@ -35184,7 +35556,7 @@ const removeMembers = async (communityId, userIds) => {
|
|
|
35184
35556
|
const client = getActiveClient();
|
|
35185
35557
|
client.log('community/moderation/removeMembers', communityId, userIds);
|
|
35186
35558
|
const { data: payload } = await client.http.delete(`/api/v3/communities/${communityId}/users`, { data: { communityId, userIds } });
|
|
35187
|
-
fireEvent('community.userRemoved', payload);
|
|
35559
|
+
fireEvent('local.community.userRemoved', payload);
|
|
35188
35560
|
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
35189
35561
|
if (client.cache)
|
|
35190
35562
|
ingestInCache(data);
|
|
@@ -35199,10 +35571,12 @@ const removeMembers = async (communityId, userIds) => {
|
|
|
35199
35571
|
*/
|
|
35200
35572
|
class CommunityMembersPaginationController extends PaginationController {
|
|
35201
35573
|
async getRequest(queryParams, token) {
|
|
35202
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
35574
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
|
|
35203
35575
|
const options = token ? { token } : { limit };
|
|
35576
|
+
const isDeleted = includeDeleted === false ? false : undefined;
|
|
35204
35577
|
const { data: queryResponse } = await this.http.get(`/api/v3/communities/${params.communityId}/users`, {
|
|
35205
|
-
params: Object.assign(Object.assign({}, params), { options
|
|
35578
|
+
params: Object.assign(Object.assign({}, params), { options,
|
|
35579
|
+
isDeleted }),
|
|
35206
35580
|
});
|
|
35207
35581
|
return queryResponse;
|
|
35208
35582
|
}
|
|
@@ -35271,6 +35645,96 @@ class CommunityMembersQueryStreamController extends QueryStreamController {
|
|
|
35271
35645
|
}
|
|
35272
35646
|
}
|
|
35273
35647
|
|
|
35648
|
+
/**
|
|
35649
|
+
* ```js
|
|
35650
|
+
* import { onLocalCommunityRoleRemoved } from '@amityco/ts-sdk'
|
|
35651
|
+
* const dispose = onLocalCommunityRoleRemoved((community, member) => {
|
|
35652
|
+
* // ...
|
|
35653
|
+
* })
|
|
35654
|
+
* ```
|
|
35655
|
+
*
|
|
35656
|
+
* Fired when any {@link Amity.communityUsers} 's role has been added to any {@link Amity.Community}
|
|
35657
|
+
*
|
|
35658
|
+
* @param callback The function to call when the event was fired
|
|
35659
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
35660
|
+
*
|
|
35661
|
+
* @category Community Events
|
|
35662
|
+
*/
|
|
35663
|
+
const onLocalCommunityRoleRemoved = (callback) => {
|
|
35664
|
+
const client = getActiveClient();
|
|
35665
|
+
const filter = async (payload) => {
|
|
35666
|
+
const { communities, communityUsers } = payload;
|
|
35667
|
+
callback(communities[0], communityUsers.filter(communityUser => communityUser.communityMembership === 'member'));
|
|
35668
|
+
};
|
|
35669
|
+
return createEventSubscriber(client, 'onLocalCommunityRoleRemoved', 'local.community.roleRemoved', filter);
|
|
35670
|
+
};
|
|
35671
|
+
|
|
35672
|
+
/**
|
|
35673
|
+
* ```js
|
|
35674
|
+
* import { onLocalCommunityRoleAdded } from '@amityco/ts-sdk'
|
|
35675
|
+
* const dispose = onLocalCommunityRoleAdded((community, member) => {
|
|
35676
|
+
* // ...
|
|
35677
|
+
* })
|
|
35678
|
+
* ```
|
|
35679
|
+
*
|
|
35680
|
+
* Fired when any {@link Amity.communityUsers} 's role has been added to any {@link Amity.Community}
|
|
35681
|
+
*
|
|
35682
|
+
* @param callback The function to call when the event was fired
|
|
35683
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
35684
|
+
*
|
|
35685
|
+
* @category Community Events
|
|
35686
|
+
*/
|
|
35687
|
+
const onLocalCommunityRoleAdded = (callback) => {
|
|
35688
|
+
const client = getActiveClient();
|
|
35689
|
+
const filter = async (payload) => {
|
|
35690
|
+
const { communities, communityUsers } = payload;
|
|
35691
|
+
callback(communities[0], communityUsers.filter(communityUser => communityUser.communityMembership === 'member'));
|
|
35692
|
+
};
|
|
35693
|
+
return createEventSubscriber(client, 'onLocalCommunityRoleAdded', 'local.community.roleAdded', filter);
|
|
35694
|
+
};
|
|
35695
|
+
|
|
35696
|
+
/**
|
|
35697
|
+
* ```js
|
|
35698
|
+
* import { onUserDeleted } from '@amityco/ts-sdk'
|
|
35699
|
+
* const dispose = onUserDeleted((community, member) => {
|
|
35700
|
+
* // ...
|
|
35701
|
+
* })
|
|
35702
|
+
* ```
|
|
35703
|
+
*
|
|
35704
|
+
* Fired when a {@link Amity.Community} has been joined
|
|
35705
|
+
*
|
|
35706
|
+
* @param callback The function to call when the event was fired
|
|
35707
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
35708
|
+
*
|
|
35709
|
+
* @category Community Events
|
|
35710
|
+
*/
|
|
35711
|
+
const onUserDeleted = (communityId) => (callback) => {
|
|
35712
|
+
const client = getActiveClient();
|
|
35713
|
+
const filter = (payload) => {
|
|
35714
|
+
var _a, _b;
|
|
35715
|
+
const userPayload = prepareUserPayload(payload);
|
|
35716
|
+
if (userPayload.users.length === 0)
|
|
35717
|
+
return;
|
|
35718
|
+
const user = userPayload.users[0];
|
|
35719
|
+
ingestInCache(userPayload);
|
|
35720
|
+
const communityUserCacheKey = getResolver('communityUsers')({
|
|
35721
|
+
communityId,
|
|
35722
|
+
userId: user.userId,
|
|
35723
|
+
});
|
|
35724
|
+
const cacheData = (_a = pullFromCache([
|
|
35725
|
+
'communityUsers',
|
|
35726
|
+
'get',
|
|
35727
|
+
communityUserCacheKey,
|
|
35728
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
35729
|
+
pushToCache(['communityUsers', 'get', communityUserCacheKey], Object.assign(Object.assign({}, cacheData), { user }));
|
|
35730
|
+
const community = (_b = pullFromCache(['community', 'get', communityId])) === null || _b === void 0 ? void 0 : _b.data;
|
|
35731
|
+
callback(community, [
|
|
35732
|
+
Object.assign(Object.assign({}, cacheData), { user }),
|
|
35733
|
+
]);
|
|
35734
|
+
};
|
|
35735
|
+
return createEventSubscriber(client, 'user.deleted', 'user.deleted', filter);
|
|
35736
|
+
};
|
|
35737
|
+
|
|
35274
35738
|
class CommunityMembersLiveCollectionController extends LiveCollectionController {
|
|
35275
35739
|
constructor(query, callback) {
|
|
35276
35740
|
const queryStreamId = hash(query);
|
|
@@ -35309,7 +35773,24 @@ class CommunityMembersLiveCollectionController extends LiveCollectionController
|
|
|
35309
35773
|
fn: onCommunityUserRoleRemoved,
|
|
35310
35774
|
action: EnumCommunityMemberActions$1.OnCommunityUserRoleRemoved,
|
|
35311
35775
|
},
|
|
35776
|
+
{
|
|
35777
|
+
fn: onLocalCommunityRoleAdded,
|
|
35778
|
+
action: EnumCommunityMemberActions$1.OnCommunityUserRoleAdded,
|
|
35779
|
+
},
|
|
35780
|
+
{
|
|
35781
|
+
fn: onLocalCommunityRoleRemoved,
|
|
35782
|
+
action: EnumCommunityMemberActions$1.OnCommunityUserRoleRemoved,
|
|
35783
|
+
},
|
|
35312
35784
|
{ fn: onCommunityUserUnbanned, action: EnumCommunityMemberActions$1.OnCommunityUserUnbanned },
|
|
35785
|
+
{ fn: onLocalCommunityUserAdded, action: EnumCommunityMemberActions$1.OnCommunityUserAdded },
|
|
35786
|
+
{
|
|
35787
|
+
fn: onLocalCommunityUserRemoved,
|
|
35788
|
+
action: EnumCommunityMemberActions$1.onCommunityUserRemoved,
|
|
35789
|
+
},
|
|
35790
|
+
{
|
|
35791
|
+
fn: onUserDeleted(this.query.communityId),
|
|
35792
|
+
action: EnumCommunityMemberActions$1.OnCommunityUserChanged,
|
|
35793
|
+
},
|
|
35313
35794
|
]);
|
|
35314
35795
|
}
|
|
35315
35796
|
notifyChange({ origin, loading, error }) {
|
|
@@ -35342,8 +35823,8 @@ class CommunityMembersLiveCollectionController extends LiveCollectionController
|
|
|
35342
35823
|
if (this.query.search) {
|
|
35343
35824
|
communityMembers = filterBySearchTerm(communityMembers, this.query.search);
|
|
35344
35825
|
}
|
|
35345
|
-
if (
|
|
35346
|
-
communityMembers = communityMembers.filter(({ user }) => (user === null || user === void 0 ? void 0 : user.isDeleted)
|
|
35826
|
+
if (this.query.includeDeleted === false) {
|
|
35827
|
+
communityMembers = communityMembers.filter(({ user }) => (user === null || user === void 0 ? void 0 : user.isDeleted) !== true);
|
|
35347
35828
|
}
|
|
35348
35829
|
switch (this.query.sortBy) {
|
|
35349
35830
|
case 'firstCreated':
|
|
@@ -35435,10 +35916,12 @@ const getMembers = (params, callback, config) => {
|
|
|
35435
35916
|
*/
|
|
35436
35917
|
class SearchCommunityMembersPaginationController extends PaginationController {
|
|
35437
35918
|
async getRequest(queryParams, token) {
|
|
35438
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
35919
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
|
|
35439
35920
|
const options = token ? { token } : { limit };
|
|
35921
|
+
const isDeleted = includeDeleted === false ? false : undefined;
|
|
35440
35922
|
const { data: queryResponse } = await this.http.get(`/api/v3/communities/${params.communityId}/users`, {
|
|
35441
|
-
params: Object.assign(Object.assign({}, params), { options
|
|
35923
|
+
params: Object.assign(Object.assign({}, params), { options,
|
|
35924
|
+
isDeleted }),
|
|
35442
35925
|
});
|
|
35443
35926
|
return queryResponse;
|
|
35444
35927
|
}
|
|
@@ -35545,11 +36028,19 @@ class SearchCommunityMembersLiveCollectionController extends LiveCollectionContr
|
|
|
35545
36028
|
{ fn: onCommunityLeft, action: EnumCommunityMemberActions.OnCommunityLeft },
|
|
35546
36029
|
{ fn: onCommunityUserBanned, action: EnumCommunityMemberActions.OnCommunityUserBanned },
|
|
35547
36030
|
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions.OnCommunityUserChanged },
|
|
36031
|
+
{
|
|
36032
|
+
fn: onLocalCommunityRoleRemoved,
|
|
36033
|
+
action: EnumCommunityMemberActions.OnCommunityUserRoleRemoved,
|
|
36034
|
+
},
|
|
35548
36035
|
{
|
|
35549
36036
|
fn: onCommunityUserRoleRemoved,
|
|
35550
36037
|
action: EnumCommunityMemberActions.OnCommunityUserRoleRemoved,
|
|
35551
36038
|
},
|
|
35552
36039
|
{ fn: onCommunityUserUnbanned, action: EnumCommunityMemberActions.OnCommunityUserUnbanned },
|
|
36040
|
+
{
|
|
36041
|
+
fn: onUserDeleted(this.query.communityId),
|
|
36042
|
+
action: EnumCommunityMemberActions.OnCommunityUserChanged,
|
|
36043
|
+
},
|
|
35553
36044
|
]);
|
|
35554
36045
|
}
|
|
35555
36046
|
notifyChange({ origin, loading, error }) {
|
|
@@ -35582,8 +36073,8 @@ class SearchCommunityMembersLiveCollectionController extends LiveCollectionContr
|
|
|
35582
36073
|
if (this.query.search) {
|
|
35583
36074
|
communityMembers = filterBySearchTerm(communityMembers, this.query.search);
|
|
35584
36075
|
}
|
|
35585
|
-
if (
|
|
35586
|
-
communityMembers = communityMembers.filter(({ user }) => (user === null || user === void 0 ? void 0 : user.isDeleted)
|
|
36076
|
+
if (this.query.includeDeleted === false) {
|
|
36077
|
+
communityMembers = communityMembers.filter(({ user }) => (user === null || user === void 0 ? void 0 : user.isDeleted) !== true);
|
|
35587
36078
|
}
|
|
35588
36079
|
return communityMembers;
|
|
35589
36080
|
}
|
|
@@ -35646,6 +36137,8 @@ var index$b = /*#__PURE__*/Object.freeze({
|
|
|
35646
36137
|
onCommunityUserUnbanned: onCommunityUserUnbanned,
|
|
35647
36138
|
onCommunityUserRoleAdded: onCommunityUserRoleAdded,
|
|
35648
36139
|
onCommunityUserRoleRemoved: onCommunityUserRoleRemoved,
|
|
36140
|
+
onLocalCommunityUserAdded: onLocalCommunityUserAdded,
|
|
36141
|
+
onLocalCommunityUserRemoved: onLocalCommunityUserRemoved,
|
|
35649
36142
|
onCommunityJoined: onCommunityJoined,
|
|
35650
36143
|
onCommunityLeft: onCommunityLeft
|
|
35651
36144
|
});
|
|
@@ -35909,11 +36402,11 @@ class CommunityLiveCollectionController extends LiveCollectionController {
|
|
|
35909
36402
|
if (!this.query.displayName) {
|
|
35910
36403
|
const sortFn = (() => {
|
|
35911
36404
|
switch (this.query.sortBy) {
|
|
35912
|
-
case
|
|
36405
|
+
case 'firstCreated':
|
|
35913
36406
|
return sortByFirstCreated;
|
|
35914
|
-
case
|
|
36407
|
+
case 'lastCreated':
|
|
35915
36408
|
return sortByLastCreated;
|
|
35916
|
-
case
|
|
36409
|
+
case 'displayName':
|
|
35917
36410
|
return sortByDisplayName;
|
|
35918
36411
|
default:
|
|
35919
36412
|
return sortByLastCreated;
|
|
@@ -36302,9 +36795,10 @@ const addRoles = async (communityId, roleIds, userIds) => {
|
|
|
36302
36795
|
const client = getActiveClient();
|
|
36303
36796
|
client.log('community/moderation/addRoles', communityId, roleIds, userIds);
|
|
36304
36797
|
const { data: payload } = await client.http.post(`/api/v4/communities/${communityId}/users/roles`, { communityId, roles: roleIds, userIds });
|
|
36305
|
-
const data =
|
|
36798
|
+
const data = prepareCommunityMembershipPayload(payload);
|
|
36306
36799
|
if (client.cache)
|
|
36307
36800
|
ingestInCache(data);
|
|
36801
|
+
fireEvent('local.community.roleAdded', data);
|
|
36308
36802
|
const { communityUsers } = data;
|
|
36309
36803
|
return !!communityUsers.find(communityUser => communityUser.communityId === communityId &&
|
|
36310
36804
|
roleIds.some(role => communityUser.roles.includes(role)));
|
|
@@ -36334,9 +36828,10 @@ const removeRoles = async (communityId, roleIds, userIds) => {
|
|
|
36334
36828
|
const client = getActiveClient();
|
|
36335
36829
|
client.log('community/moderation/removeRoles', communityId, roleIds, userIds);
|
|
36336
36830
|
const { data: payload } = await client.http.delete(`/api/v4/communities/${communityId}/users/roles`, { data: { communityId, roles: roleIds, userIds } });
|
|
36337
|
-
const data =
|
|
36831
|
+
const data = prepareCommunityMembershipPayload(payload);
|
|
36338
36832
|
if (client.cache)
|
|
36339
36833
|
ingestInCache(data);
|
|
36834
|
+
fireEvent('local.community.roleRemoved', data);
|
|
36340
36835
|
const { communityUsers } = data;
|
|
36341
36836
|
return !!communityUsers.find(communityUser => communityUser.communityId === communityId &&
|
|
36342
36837
|
!roleIds.some(role => communityUser.roles.includes(role)));
|
|
@@ -37023,7 +37518,7 @@ const updatePost = async (postId, patch) => {
|
|
|
37023
37518
|
const cachedAt = client.cache && Date.now();
|
|
37024
37519
|
if (client.cache)
|
|
37025
37520
|
ingestInCache(data, { cachedAt });
|
|
37026
|
-
fireEvent('local.post.updated',
|
|
37521
|
+
fireEvent('local.post.updated', payload);
|
|
37027
37522
|
const { posts } = data;
|
|
37028
37523
|
return {
|
|
37029
37524
|
data: LinkedObject.post(posts.find(post => post.postId === postId)),
|
|
@@ -37123,7 +37618,15 @@ const deletePost = async (postId, permanent = false) => {
|
|
|
37123
37618
|
}
|
|
37124
37619
|
// to support hard deletion
|
|
37125
37620
|
const deleted = Object.assign(Object.assign({}, post.data), { isDeleted: true });
|
|
37126
|
-
|
|
37621
|
+
if (permanent) {
|
|
37622
|
+
setTimeout(() => {
|
|
37623
|
+
pushToTombstone('post', postId);
|
|
37624
|
+
}, 0);
|
|
37625
|
+
}
|
|
37626
|
+
else {
|
|
37627
|
+
upsertInCache(['post', 'get', postId], { isDeleted: true });
|
|
37628
|
+
}
|
|
37629
|
+
fireEvent('local.post.deleted', {
|
|
37127
37630
|
posts: [deleted],
|
|
37128
37631
|
categories: [],
|
|
37129
37632
|
comments: [],
|
|
@@ -37134,14 +37637,6 @@ const deletePost = async (postId, permanent = false) => {
|
|
|
37134
37637
|
postChildren: [],
|
|
37135
37638
|
users: [],
|
|
37136
37639
|
});
|
|
37137
|
-
if (permanent) {
|
|
37138
|
-
setTimeout(() => {
|
|
37139
|
-
pushToTombstone('post', postId);
|
|
37140
|
-
}, 0);
|
|
37141
|
-
}
|
|
37142
|
-
else {
|
|
37143
|
-
upsertInCache(['post', 'get', postId], { isDeleted: true });
|
|
37144
|
-
}
|
|
37145
37640
|
return LinkedObject.post(deleted);
|
|
37146
37641
|
};
|
|
37147
37642
|
|
|
@@ -37529,6 +38024,7 @@ getCommentByIds.locally = (commentIds) => {
|
|
|
37529
38024
|
* @async
|
|
37530
38025
|
*/
|
|
37531
38026
|
const createComment = async (bundle) => {
|
|
38027
|
+
var _a;
|
|
37532
38028
|
const client = getActiveClient();
|
|
37533
38029
|
client.log('comment/createComment', bundle);
|
|
37534
38030
|
const { data } = await client.http.post('/api/v3/comments', bundle);
|
|
@@ -37540,18 +38036,21 @@ const createComment = async (bundle) => {
|
|
|
37540
38036
|
if (client.cache)
|
|
37541
38037
|
ingestInCache(data, { cachedAt });
|
|
37542
38038
|
if (['post', 'content'].includes(bundle.referenceType)) {
|
|
37543
|
-
const post =
|
|
37544
|
-
|
|
37545
|
-
|
|
37546
|
-
|
|
37547
|
-
|
|
37548
|
-
|
|
37549
|
-
|
|
37550
|
-
|
|
37551
|
-
|
|
37552
|
-
|
|
37553
|
-
|
|
37554
|
-
|
|
38039
|
+
const post = (_a = pullFromCache(['post', 'get', bundle.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
38040
|
+
if (post) {
|
|
38041
|
+
post.commentsCount += 1;
|
|
38042
|
+
fireEvent('local.post.updated', {
|
|
38043
|
+
posts: [post],
|
|
38044
|
+
categories: [],
|
|
38045
|
+
comments: [],
|
|
38046
|
+
communities: [],
|
|
38047
|
+
communityUsers: data.communityUsers,
|
|
38048
|
+
feeds: [],
|
|
38049
|
+
files: data.files,
|
|
38050
|
+
postChildren: [],
|
|
38051
|
+
users: data.users,
|
|
38052
|
+
});
|
|
38053
|
+
}
|
|
37555
38054
|
}
|
|
37556
38055
|
else if (bundle.referenceType === 'story') {
|
|
37557
38056
|
const storyIndex = pullFromCache([
|
|
@@ -37710,6 +38209,7 @@ getStoryByStoryId$1.locally = (storyId) => {
|
|
|
37710
38209
|
* @async
|
|
37711
38210
|
*/
|
|
37712
38211
|
const deleteComment = async (commentId, permanent = false) => {
|
|
38212
|
+
var _a;
|
|
37713
38213
|
const client = getActiveClient();
|
|
37714
38214
|
const comment = await getComment$2(commentId);
|
|
37715
38215
|
// API-FIX: This endpoint has not been implemented yet.
|
|
@@ -37734,18 +38234,28 @@ const deleteComment = async (commentId, permanent = false) => {
|
|
|
37734
38234
|
});
|
|
37735
38235
|
}
|
|
37736
38236
|
else {
|
|
37737
|
-
const post =
|
|
37738
|
-
|
|
37739
|
-
|
|
37740
|
-
|
|
37741
|
-
|
|
37742
|
-
|
|
37743
|
-
|
|
37744
|
-
|
|
37745
|
-
|
|
37746
|
-
|
|
37747
|
-
|
|
37748
|
-
|
|
38237
|
+
const post = (_a = pullFromCache(['post', 'get', comment.data.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
38238
|
+
if (post) {
|
|
38239
|
+
let removeCount;
|
|
38240
|
+
if (!deleted.parentId) {
|
|
38241
|
+
// NOTE: delete the parent comment will remove all children comments
|
|
38242
|
+
removeCount = deleted.childrenNumber + 1;
|
|
38243
|
+
}
|
|
38244
|
+
else
|
|
38245
|
+
removeCount = 1;
|
|
38246
|
+
post.commentsCount -= removeCount;
|
|
38247
|
+
fireEvent('local.post.updated', {
|
|
38248
|
+
posts: [post],
|
|
38249
|
+
categories: [],
|
|
38250
|
+
comments: [],
|
|
38251
|
+
communities: [],
|
|
38252
|
+
communityUsers: [],
|
|
38253
|
+
feeds: [],
|
|
38254
|
+
files: [],
|
|
38255
|
+
postChildren: [],
|
|
38256
|
+
users: [],
|
|
38257
|
+
});
|
|
38258
|
+
}
|
|
37749
38259
|
}
|
|
37750
38260
|
fireEvent('local.comment.deleted', {
|
|
37751
38261
|
comments: [deleted],
|
|
@@ -38011,6 +38521,81 @@ const observeComment = (commentId, callback, policy = 'cache_then_server') => {
|
|
|
38011
38521
|
};
|
|
38012
38522
|
};
|
|
38013
38523
|
|
|
38524
|
+
/**
|
|
38525
|
+
* ```js
|
|
38526
|
+
* import { onCommentDeleteLocal } from '@amityco/ts-sdk'
|
|
38527
|
+
* const dispose = onCommentDeleteLocal(comment => {
|
|
38528
|
+
* // ...
|
|
38529
|
+
* })
|
|
38530
|
+
* ```
|
|
38531
|
+
*
|
|
38532
|
+
* Fired when a {@link Amity.InternalComment} has been deleted
|
|
38533
|
+
*
|
|
38534
|
+
* @param callback The function to call when the event was fired
|
|
38535
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
38536
|
+
*
|
|
38537
|
+
* @category Comment Events
|
|
38538
|
+
*/
|
|
38539
|
+
const onCommentDeleteLocal = (callback) => createLocalCommentEventSubscriber('local.comment.deleted', callback);
|
|
38540
|
+
|
|
38541
|
+
/**
|
|
38542
|
+
* ```js
|
|
38543
|
+
* import { onLocalCommentReactionAdded } from '@amityco/ts-sdk'
|
|
38544
|
+
* const dispose = onLocalCommentReactionAdded(comment => {
|
|
38545
|
+
* // ...
|
|
38546
|
+
* })
|
|
38547
|
+
* ```
|
|
38548
|
+
*
|
|
38549
|
+
* Fired when a {@link Amity.InternalComment} has been reacted
|
|
38550
|
+
*
|
|
38551
|
+
* @param callback The function to call when the event was fired
|
|
38552
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
38553
|
+
*
|
|
38554
|
+
* @category Comment Events
|
|
38555
|
+
*/
|
|
38556
|
+
const onLocalCommentReactionAdded = (callback) => {
|
|
38557
|
+
const client = getActiveClient();
|
|
38558
|
+
const filter = ({ comment }) => {
|
|
38559
|
+
if (!client.cache) {
|
|
38560
|
+
callback(comment);
|
|
38561
|
+
}
|
|
38562
|
+
else {
|
|
38563
|
+
upsertInCache(['comment', 'get', comment.commentId], comment);
|
|
38564
|
+
callback(commentLinkedObject(comment));
|
|
38565
|
+
}
|
|
38566
|
+
};
|
|
38567
|
+
return createEventSubscriber(client, 'local.comment.addReaction', 'local.comment.addReaction', filter);
|
|
38568
|
+
};
|
|
38569
|
+
|
|
38570
|
+
/**
|
|
38571
|
+
* ```js
|
|
38572
|
+
* import { onLocalCommentReactionRemoved } from '@amityco/ts-sdk'
|
|
38573
|
+
* const dispose = onLocalCommentReactionRemoved(comment => {
|
|
38574
|
+
* // ...
|
|
38575
|
+
* })
|
|
38576
|
+
* ```
|
|
38577
|
+
*
|
|
38578
|
+
* Fired when a {@link Amity.InternalComment} has been reacted
|
|
38579
|
+
*
|
|
38580
|
+
* @param callback The function to call when the event was fired
|
|
38581
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
38582
|
+
*
|
|
38583
|
+
* @category Comment Events
|
|
38584
|
+
*/
|
|
38585
|
+
const onLocalCommentReactionRemoved = (callback) => {
|
|
38586
|
+
const client = getActiveClient();
|
|
38587
|
+
const filter = ({ comment }) => {
|
|
38588
|
+
if (!client.cache) {
|
|
38589
|
+
callback(comment);
|
|
38590
|
+
}
|
|
38591
|
+
else {
|
|
38592
|
+
upsertInCache(['comment', 'get', comment.commentId], comment);
|
|
38593
|
+
callback(commentLinkedObject(comment));
|
|
38594
|
+
}
|
|
38595
|
+
};
|
|
38596
|
+
return createEventSubscriber(client, 'local.comment.removeReaction', 'local.comment.removeReaction', filter);
|
|
38597
|
+
};
|
|
38598
|
+
|
|
38014
38599
|
/* begin_public_function
|
|
38015
38600
|
id: comment.get
|
|
38016
38601
|
*/
|
|
@@ -38035,26 +38620,15 @@ const observeComment = (commentId, callback, policy = 'cache_then_server') => {
|
|
|
38035
38620
|
*/
|
|
38036
38621
|
const getComment = (commentId, callback) => {
|
|
38037
38622
|
return liveObject(commentId, callback, 'commentId', getComment$1, [
|
|
38623
|
+
onCommentDeleteLocal,
|
|
38038
38624
|
onCommentDeleted,
|
|
38039
38625
|
onCommentFlagged,
|
|
38040
38626
|
onCommentReactionAdded,
|
|
38041
38627
|
onCommentReactionRemoved,
|
|
38042
38628
|
onCommentUnflagged,
|
|
38043
38629
|
onCommentUpdated,
|
|
38044
|
-
|
|
38045
|
-
|
|
38046
|
-
if (comment.parentId !== commentId)
|
|
38047
|
-
return;
|
|
38048
|
-
const cacheParent = pullFromCache([
|
|
38049
|
-
'comment',
|
|
38050
|
-
'get',
|
|
38051
|
-
comment.parentId,
|
|
38052
|
-
]);
|
|
38053
|
-
if (!(cacheParent === null || cacheParent === void 0 ? void 0 : cacheParent.data))
|
|
38054
|
-
return;
|
|
38055
|
-
callback(Object.assign(Object.assign({}, cacheParent.data), { childrenNumber: cacheParent.data.childrenNumber + 1, children: [...new Set([...cacheParent.data.children, comment.commentId])] }));
|
|
38056
|
-
});
|
|
38057
|
-
},
|
|
38630
|
+
onLocalCommentReactionAdded,
|
|
38631
|
+
onLocalCommentReactionRemoved,
|
|
38058
38632
|
]);
|
|
38059
38633
|
};
|
|
38060
38634
|
/* end_public_function */
|
|
@@ -38138,6 +38712,25 @@ class CommentQueryStreamController extends QueryStreamController {
|
|
|
38138
38712
|
}
|
|
38139
38713
|
}
|
|
38140
38714
|
|
|
38715
|
+
/**
|
|
38716
|
+
* ```js
|
|
38717
|
+
* import { onCommentCreated } from '@amityco/ts-sdk'
|
|
38718
|
+
* const dispose = onCommentCreated(comment => {
|
|
38719
|
+
* // ...
|
|
38720
|
+
* })
|
|
38721
|
+
* ```
|
|
38722
|
+
*
|
|
38723
|
+
* Fired when a {@link Amity.InternalComment} has been created
|
|
38724
|
+
*
|
|
38725
|
+
* @param callback The function to call when the event was fired
|
|
38726
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
38727
|
+
*
|
|
38728
|
+
* @category Comment Events
|
|
38729
|
+
*/
|
|
38730
|
+
const onCommentCreatedLocal = (callback) => {
|
|
38731
|
+
return createLocalCommentEventSubscriber('local.comment.created', callback);
|
|
38732
|
+
};
|
|
38733
|
+
|
|
38141
38734
|
class CommentLiveCollectionController extends LiveCollectionController {
|
|
38142
38735
|
constructor(query, callback) {
|
|
38143
38736
|
const queryStreamId = hash(query);
|
|
@@ -38167,6 +38760,8 @@ class CommentLiveCollectionController extends LiveCollectionController {
|
|
|
38167
38760
|
}
|
|
38168
38761
|
startSubscription() {
|
|
38169
38762
|
return this.queryStreamController.subscribeRTE([
|
|
38763
|
+
{ fn: onCommentCreatedLocal, action: EnumCommentActions.OnCommentCreated },
|
|
38764
|
+
{ fn: onCommentDeleteLocal, action: EnumCommentActions.OnCommentDeleted },
|
|
38170
38765
|
{ fn: onCommentCreated, action: EnumCommentActions.OnCommentCreated },
|
|
38171
38766
|
{ fn: onCommentUpdated, action: EnumCommentActions.OnCommentUpdated },
|
|
38172
38767
|
{ fn: onCommentDeleted, action: EnumCommentActions.OnCommentDeleted },
|
|
@@ -38174,6 +38769,8 @@ class CommentLiveCollectionController extends LiveCollectionController {
|
|
|
38174
38769
|
{ fn: onCommentUnflagged, action: EnumCommentActions.OnCommentUnflagged },
|
|
38175
38770
|
{ fn: onCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
|
|
38176
38771
|
{ fn: onCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
|
|
38772
|
+
{ fn: onLocalCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
|
|
38773
|
+
{ fn: onLocalCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
|
|
38177
38774
|
]);
|
|
38178
38775
|
}
|
|
38179
38776
|
notifyChange({ origin, loading, error }) {
|
|
@@ -38305,6 +38902,98 @@ var index$6 = /*#__PURE__*/Object.freeze({
|
|
|
38305
38902
|
getComments: getComments
|
|
38306
38903
|
});
|
|
38307
38904
|
|
|
38905
|
+
/**
|
|
38906
|
+
* ```js
|
|
38907
|
+
* import { onPostUpdatedLocal } from '@amityco/ts-sdk'
|
|
38908
|
+
* const dispose = onPostUpdatedLocal(post => {
|
|
38909
|
+
* // ...
|
|
38910
|
+
* })
|
|
38911
|
+
* ```
|
|
38912
|
+
*
|
|
38913
|
+
* Fired when a {@link Amity.InternalPost} has been updated
|
|
38914
|
+
*
|
|
38915
|
+
* @param callback The function to call when the event was fired
|
|
38916
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
38917
|
+
*
|
|
38918
|
+
* @category Post Events
|
|
38919
|
+
*/
|
|
38920
|
+
const onPostUpdatedLocal = (callback) => createLocalPostEventSubscriber('local.post.updated', callback);
|
|
38921
|
+
|
|
38922
|
+
/**
|
|
38923
|
+
* ```js
|
|
38924
|
+
* import { onLocalPostReactionAdded } from '@amityco/ts-sdk'
|
|
38925
|
+
* const dispose = onPostReactionAdded(post => {
|
|
38926
|
+
* // ...
|
|
38927
|
+
* })
|
|
38928
|
+
* ```
|
|
38929
|
+
*
|
|
38930
|
+
* Fired when a {@link Amity.InternalPost} has been reacted
|
|
38931
|
+
*
|
|
38932
|
+
* @param callback The function to call when the event was fired
|
|
38933
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
38934
|
+
*
|
|
38935
|
+
* @category Post Events
|
|
38936
|
+
*/
|
|
38937
|
+
const onLocalPostReactionAdded = (callback) => {
|
|
38938
|
+
const client = getActiveClient();
|
|
38939
|
+
const filter = ({ post }) => {
|
|
38940
|
+
if (!client.cache) {
|
|
38941
|
+
callback(post);
|
|
38942
|
+
}
|
|
38943
|
+
else {
|
|
38944
|
+
upsertInCache(['post', 'get', post.postId], post);
|
|
38945
|
+
callback(post);
|
|
38946
|
+
}
|
|
38947
|
+
};
|
|
38948
|
+
return createEventSubscriber(client, 'local.post.addReaction', 'local.post.addReaction', filter);
|
|
38949
|
+
};
|
|
38950
|
+
|
|
38951
|
+
/**
|
|
38952
|
+
* ```js
|
|
38953
|
+
* import { onLocalPostReactionRemoved } from '@amityco/ts-sdk'
|
|
38954
|
+
* const dispose = onPostReactionRemoved(post => {
|
|
38955
|
+
* // ...
|
|
38956
|
+
* })
|
|
38957
|
+
* ```
|
|
38958
|
+
*
|
|
38959
|
+
* Fired when a {@link Amity.InternalPost} has been reacted
|
|
38960
|
+
*
|
|
38961
|
+
* @param callback The function to call when the event was fired
|
|
38962
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
38963
|
+
*
|
|
38964
|
+
* @category Post Events
|
|
38965
|
+
*/
|
|
38966
|
+
const onLocalPostReactionRemoved = (callback) => {
|
|
38967
|
+
const client = getActiveClient();
|
|
38968
|
+
const filter = ({ post }) => {
|
|
38969
|
+
if (!client.cache) {
|
|
38970
|
+
callback(post);
|
|
38971
|
+
}
|
|
38972
|
+
else {
|
|
38973
|
+
upsertInCache(['post', 'get', post.postId], post);
|
|
38974
|
+
callback(post);
|
|
38975
|
+
}
|
|
38976
|
+
};
|
|
38977
|
+
return createEventSubscriber(client, 'local.post.removeReaction', 'local.post.removeReaction', filter);
|
|
38978
|
+
};
|
|
38979
|
+
|
|
38980
|
+
/**
|
|
38981
|
+
* ```js
|
|
38982
|
+
* import { onLocalPostDeleted } from '@amityco/ts-sdk'
|
|
38983
|
+
* const dispose = onLocalPostDeleted(post => {
|
|
38984
|
+
* // ...
|
|
38985
|
+
* })
|
|
38986
|
+
* ```
|
|
38987
|
+
*
|
|
38988
|
+
* Fired when a {@link Amity.InternalPost} has been deleted
|
|
38989
|
+
*
|
|
38990
|
+
* @param callback The function to call when the event was fired
|
|
38991
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
38992
|
+
*
|
|
38993
|
+
* @category Post Events
|
|
38994
|
+
*/
|
|
38995
|
+
const onLocalPostDeleted = (callback) => createLocalPostEventSubscriber('local.post.deleted', callback);
|
|
38996
|
+
|
|
38308
38997
|
/* begin_public_function
|
|
38309
38998
|
id: post.get
|
|
38310
38999
|
*/
|
|
@@ -38335,6 +39024,8 @@ const getPost$1 = (postId, callback) => {
|
|
|
38335
39024
|
return liveObject(postId, responder, 'postId', getPost$2, [
|
|
38336
39025
|
onPostApproved,
|
|
38337
39026
|
onPostDeclined,
|
|
39027
|
+
onLocalPostReactionAdded,
|
|
39028
|
+
onLocalPostReactionRemoved,
|
|
38338
39029
|
(callback) => {
|
|
38339
39030
|
return onPostDeleted((post) => {
|
|
38340
39031
|
var _a;
|
|
@@ -38369,6 +39060,8 @@ const getPost$1 = (postId, callback) => {
|
|
|
38369
39060
|
},
|
|
38370
39061
|
onPostUnflagged,
|
|
38371
39062
|
onPostUpdated,
|
|
39063
|
+
onPostUpdatedLocal,
|
|
39064
|
+
onLocalPostDeleted,
|
|
38372
39065
|
convertEventPayload((callback) => {
|
|
38373
39066
|
return onCommentCreated(async (comment) => {
|
|
38374
39067
|
if (comment.referenceId === postId) {
|
|
@@ -38562,6 +39255,7 @@ class PostLiveCollectionController extends LiveCollectionController {
|
|
|
38562
39255
|
return this.queryStreamController.subscribeRTE([
|
|
38563
39256
|
{ fn: onPostCreated, action: EnumPostActions.OnPostCreated },
|
|
38564
39257
|
{ fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
|
|
39258
|
+
{ fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
|
|
38565
39259
|
{ fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
|
|
38566
39260
|
{ fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
|
|
38567
39261
|
{ fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
|
|
@@ -38569,6 +39263,9 @@ class PostLiveCollectionController extends LiveCollectionController {
|
|
|
38569
39263
|
{ fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
|
|
38570
39264
|
{ fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
|
|
38571
39265
|
{ fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
|
|
39266
|
+
{ fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
|
|
39267
|
+
{ fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
|
|
39268
|
+
{ fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
|
|
38572
39269
|
{
|
|
38573
39270
|
fn: convertEventPayload((callback) => {
|
|
38574
39271
|
return onCommentCreated(async (comment) => {
|