@amityco/ts-sdk 7.4.0 → 7.4.1-0e170b02.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env +26 -26
- package/dist/@types/core/events.d.ts +7 -0
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/model.d.ts +5 -1
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +38 -5
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/client.d.ts +10 -0
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/@types/domains/community.d.ts +37 -1
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/@types/domains/invitation.d.ts +88 -0
- package/dist/@types/domains/invitation.d.ts.map +1 -0
- package/dist/@types/domains/joinRequest.d.ts +53 -0
- package/dist/@types/domains/joinRequest.d.ts.map +1 -0
- package/dist/@types/index.d.ts +3 -0
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/communityRepository/api/createCommunity.d.ts +2 -2
- package/dist/communityRepository/api/createCommunity.d.ts.map +1 -1
- package/dist/communityRepository/api/getCommunities.d.ts +1 -1
- package/dist/communityRepository/api/getCommunities.d.ts.map +1 -1
- package/dist/communityRepository/api/getCommunity.d.ts +1 -1
- package/dist/communityRepository/api/getCommunity.d.ts.map +1 -1
- package/dist/communityRepository/api/getRecommendedCommunities.d.ts +3 -1
- package/dist/communityRepository/api/getRecommendedCommunities.d.ts.map +1 -1
- package/dist/communityRepository/api/getTrendingCommunities.d.ts +3 -1
- package/dist/communityRepository/api/getTrendingCommunities.d.ts.map +1 -1
- package/dist/communityRepository/api/joinCommunity.d.ts +3 -0
- package/dist/communityRepository/api/joinCommunity.d.ts.map +1 -1
- package/dist/communityRepository/api/queryCommunities.d.ts.map +1 -1
- package/dist/communityRepository/api/updateCommunity.d.ts +2 -2
- package/dist/communityRepository/api/updateCommunity.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/onCommunityJoined.d.ts +1 -1
- package/dist/communityRepository/communityMembership/events/onCommunityJoined.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/onCommunityLeft.d.ts +1 -1
- package/dist/communityRepository/communityMembership/events/onCommunityLeft.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/onCommunityUserAdded.d.ts +1 -1
- package/dist/communityRepository/communityMembership/events/onCommunityUserAdded.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/onCommunityUserBanned.d.ts +1 -1
- package/dist/communityRepository/communityMembership/events/onCommunityUserBanned.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/onCommunityUserChanged.d.ts +1 -1
- package/dist/communityRepository/communityMembership/events/onCommunityUserChanged.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/onCommunityUserRemoved.d.ts +1 -1
- package/dist/communityRepository/communityMembership/events/onCommunityUserRemoved.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/onCommunityUserRoleAdded.d.ts +1 -1
- package/dist/communityRepository/communityMembership/events/onCommunityUserRoleAdded.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/onCommunityUserRoleRemoved.d.ts +1 -1
- package/dist/communityRepository/communityMembership/events/onCommunityUserRoleRemoved.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/onCommunityUserUnbanned.d.ts +1 -1
- package/dist/communityRepository/communityMembership/events/onCommunityUserUnbanned.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/onLocalCommunityJoined.d.ts +1 -1
- package/dist/communityRepository/communityMembership/events/onLocalCommunityJoined.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/onLocalCommunityLeft.d.ts +1 -1
- package/dist/communityRepository/communityMembership/events/onLocalCommunityLeft.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/onLocalCommunityUserAdded.d.ts +1 -1
- package/dist/communityRepository/communityMembership/events/onLocalCommunityUserAdded.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/onLocalCommunityUserRemoved.d.ts +1 -1
- package/dist/communityRepository/communityMembership/events/onLocalCommunityUserRemoved.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/onUserDeleted.d.ts +1 -1
- package/dist/communityRepository/communityMembership/events/onUserDeleted.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/utils.d.ts +2 -2
- package/dist/communityRepository/communityMembership/events/utils.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.d.ts +2 -2
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersQueryStreamController.d.ts +2 -2
- package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersQueryStreamController.d.ts.map +1 -1
- package/dist/communityRepository/communityModeration/events/onLocalCommunityRoleAdded.d.ts +1 -1
- package/dist/communityRepository/communityModeration/events/onLocalCommunityRoleAdded.d.ts.map +1 -1
- package/dist/communityRepository/communityModeration/events/onLocalCommunityRoleRemoved.d.ts +1 -1
- package/dist/communityRepository/communityModeration/events/onLocalCommunityRoleRemoved.d.ts.map +1 -1
- package/dist/communityRepository/events/onCommunityCreated.d.ts +1 -1
- package/dist/communityRepository/events/onCommunityCreated.d.ts.map +1 -1
- package/dist/communityRepository/events/onCommunityDeleted.d.ts +1 -1
- package/dist/communityRepository/events/onCommunityDeleted.d.ts.map +1 -1
- package/dist/communityRepository/events/onCommunityUpdated.d.ts +1 -1
- package/dist/communityRepository/events/onCommunityUpdated.d.ts.map +1 -1
- package/dist/communityRepository/events/utils.d.ts +1 -1
- package/dist/communityRepository/events/utils.d.ts.map +1 -1
- package/dist/communityRepository/internalAPI/getMyJoinRequest.d.ts +16 -0
- package/dist/communityRepository/internalAPI/getMyJoinRequest.d.ts.map +1 -0
- package/dist/communityRepository/internalAPI/joinCommunity.d.ts +16 -0
- package/dist/communityRepository/internalAPI/joinCommunity.d.ts.map +1 -0
- package/dist/communityRepository/joinRequest/events/index.d.ts +4 -0
- package/dist/communityRepository/joinRequest/events/index.d.ts.map +1 -0
- package/dist/communityRepository/joinRequest/events/onJoinRequestCreated.d.ts +17 -0
- package/dist/communityRepository/joinRequest/events/onJoinRequestCreated.d.ts.map +1 -0
- package/dist/communityRepository/joinRequest/events/onJoinRequestDeleted.d.ts +17 -0
- package/dist/communityRepository/joinRequest/events/onJoinRequestDeleted.d.ts.map +1 -0
- package/dist/communityRepository/joinRequest/events/onJoinRequestUpdated.d.ts +17 -0
- package/dist/communityRepository/joinRequest/events/onJoinRequestUpdated.d.ts.map +1 -0
- package/dist/communityRepository/joinRequest/internalAPI/approveJoinRequest.d.ts +16 -0
- package/dist/communityRepository/joinRequest/internalAPI/approveJoinRequest.d.ts.map +1 -0
- package/dist/communityRepository/joinRequest/internalAPI/cancelJoinRequest.d.ts +16 -0
- package/dist/communityRepository/joinRequest/internalAPI/cancelJoinRequest.d.ts.map +1 -0
- package/dist/communityRepository/joinRequest/internalAPI/rejectJoinRequest.d.ts +16 -0
- package/dist/communityRepository/joinRequest/internalAPI/rejectJoinRequest.d.ts.map +1 -0
- package/dist/communityRepository/observers/getCommunities/CommunitiesQueryStreamController.d.ts +2 -2
- package/dist/communityRepository/observers/getCommunities/CommunitiesQueryStreamController.d.ts.map +1 -1
- package/dist/communityRepository/observers/getJoinRequests/JoinRequestsLiveCollectionController.d.ts +14 -0
- package/dist/communityRepository/observers/getJoinRequests/JoinRequestsLiveCollectionController.d.ts.map +1 -0
- package/dist/communityRepository/observers/getJoinRequests/JoinRequestsPaginationController.d.ts +9 -0
- package/dist/communityRepository/observers/getJoinRequests/JoinRequestsPaginationController.d.ts.map +1 -0
- package/dist/communityRepository/observers/getJoinRequests/JoinRequestsQueryStreamController.d.ts +15 -0
- package/dist/communityRepository/observers/getJoinRequests/JoinRequestsQueryStreamController.d.ts.map +1 -0
- package/dist/communityRepository/observers/getJoinRequests/enum.d.ts +6 -0
- package/dist/communityRepository/observers/getJoinRequests/enum.d.ts.map +1 -0
- package/dist/communityRepository/observers/getJoinRequests.d.ts +12 -0
- package/dist/communityRepository/observers/getJoinRequests.d.ts.map +1 -0
- package/dist/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesLiveCollectionController.d.ts.map +1 -1
- package/dist/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesQueryStreamController.d.ts +2 -2
- package/dist/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesQueryStreamController.d.ts.map +1 -1
- package/dist/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesLiveCollectionController.d.ts.map +1 -1
- package/dist/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesQueryStreamController.d.ts +2 -2
- package/dist/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesQueryStreamController.d.ts.map +1 -1
- package/dist/communityRepository/observers/searchCommunities/SearchCommunitiesPaginationController.d.ts.map +1 -1
- package/dist/communityRepository/observers/searchCommunities/SearchCommunitiesQueryStreamController.d.ts +2 -2
- package/dist/communityRepository/observers/searchCommunities/SearchCommunitiesQueryStreamController.d.ts.map +1 -1
- package/dist/communityRepository/observers/semanticSearch/SemanticSearchCommunityQueryStreamController.d.ts +2 -2
- package/dist/communityRepository/observers/semanticSearch/SemanticSearchCommunityQueryStreamController.d.ts.map +1 -1
- package/dist/communityRepository/utils/communityWithMembership.d.ts +1 -1
- package/dist/communityRepository/utils/communityWithMembership.d.ts.map +1 -1
- package/dist/communityRepository/utils/payload.d.ts +2 -1
- 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/core/model/idResolvers.d.ts.map +1 -1
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/index.cjs.js +2672 -1415
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +2934 -1678
- package/dist/index.umd.js +4 -4
- package/dist/invitationRepository/events/index.d.ts +4 -0
- package/dist/invitationRepository/events/index.d.ts.map +1 -0
- package/dist/invitationRepository/events/onLocalInvitationCreated.d.ts +17 -0
- package/dist/invitationRepository/events/onLocalInvitationCreated.d.ts.map +1 -0
- package/dist/invitationRepository/events/onLocalInvitationDeleted.d.ts +17 -0
- package/dist/invitationRepository/events/onLocalInvitationDeleted.d.ts.map +1 -0
- package/dist/invitationRepository/events/onLocalInvitationUpdated.d.ts +17 -0
- package/dist/invitationRepository/events/onLocalInvitationUpdated.d.ts.map +1 -0
- package/dist/invitationRepository/index.d.ts +3 -0
- package/dist/invitationRepository/index.d.ts.map +1 -0
- package/dist/invitationRepository/internalApi/acceptInvitation.d.ts +16 -0
- package/dist/invitationRepository/internalApi/acceptInvitation.d.ts.map +1 -0
- package/dist/invitationRepository/internalApi/cancelInvitation.d.ts +16 -0
- package/dist/invitationRepository/internalApi/cancelInvitation.d.ts.map +1 -0
- package/dist/invitationRepository/internalApi/createInvitations.d.ts +21 -0
- package/dist/invitationRepository/internalApi/createInvitations.d.ts.map +1 -0
- package/dist/invitationRepository/internalApi/getInvitation.d.ts +17 -0
- package/dist/invitationRepository/internalApi/getInvitation.d.ts.map +1 -0
- package/dist/invitationRepository/internalApi/index.d.ts +5 -0
- package/dist/invitationRepository/internalApi/index.d.ts.map +1 -0
- package/dist/invitationRepository/internalApi/rejectInvitation.d.ts +16 -0
- package/dist/invitationRepository/internalApi/rejectInvitation.d.ts.map +1 -0
- package/dist/invitationRepository/observers/getInvitations/InvitationsLiveCollectionController.d.ts +14 -0
- package/dist/invitationRepository/observers/getInvitations/InvitationsLiveCollectionController.d.ts.map +1 -0
- package/dist/invitationRepository/observers/getInvitations/InvitationsPaginationController.d.ts +5 -0
- package/dist/invitationRepository/observers/getInvitations/InvitationsPaginationController.d.ts.map +1 -0
- package/dist/invitationRepository/observers/getInvitations/InvitationsQueryStreamController.d.ts +15 -0
- package/dist/invitationRepository/observers/getInvitations/InvitationsQueryStreamController.d.ts.map +1 -0
- package/dist/invitationRepository/observers/getInvitations/enums.d.ts +6 -0
- package/dist/invitationRepository/observers/getInvitations/enums.d.ts.map +1 -0
- package/dist/invitationRepository/observers/getInvitations.d.ts +12 -0
- package/dist/invitationRepository/observers/getInvitations.d.ts.map +1 -0
- package/dist/invitationRepository/observers/getMyCommunityInvitations.d.ts +12 -0
- package/dist/invitationRepository/observers/getMyCommunityInvitations.d.ts.map +1 -0
- package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsLiveCollectionController.d.ts +14 -0
- package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsLiveCollectionController.d.ts.map +1 -0
- package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsPaginationController.d.ts +5 -0
- package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsPaginationController.d.ts.map +1 -0
- package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsQueryStreamController.d.ts +15 -0
- package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsQueryStreamController.d.ts.map +1 -0
- package/dist/invitationRepository/observers/index.d.ts +2 -0
- package/dist/invitationRepository/observers/index.d.ts.map +1 -0
- package/dist/invitationRepository/utils/convertRawInvitationToInternalInvitation.d.ts +2 -0
- package/dist/invitationRepository/utils/convertRawInvitationToInternalInvitation.d.ts.map +1 -0
- package/dist/invitationRepository/utils/index.d.ts +2 -0
- package/dist/invitationRepository/utils/index.d.ts.map +1 -0
- package/dist/invitationRepository/utils/prepareInvitationPayload.d.ts +2 -0
- package/dist/invitationRepository/utils/prepareInvitationPayload.d.ts.map +1 -0
- package/dist/invitationRepository/utils/prepareMyInvitationsPayload.d.ts +2 -0
- package/dist/invitationRepository/utils/prepareMyInvitationsPayload.d.ts.map +1 -0
- package/dist/messageRepository/api/flagMessage.d.ts +3 -2
- package/dist/messageRepository/api/flagMessage.d.ts.map +1 -1
- package/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostQueryStreamController.d.ts.map +1 -1
- package/dist/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.d.ts.map +1 -1
- package/dist/subChannelRepository/utils/prepareSubChannelPayload.d.ts.map +1 -1
- package/dist/utils/linkedObject/communityLinkedObject.d.ts +2 -0
- package/dist/utils/linkedObject/communityLinkedObject.d.ts.map +1 -0
- package/dist/utils/linkedObject/index.d.ts +3 -0
- package/dist/utils/linkedObject/index.d.ts.map +1 -1
- package/dist/utils/linkedObject/invitationLinkedObject.d.ts +2 -0
- package/dist/utils/linkedObject/invitationLinkedObject.d.ts.map +1 -0
- package/dist/utils/linkedObject/joinRequestLinkedObject.d.ts +2 -0
- package/dist/utils/linkedObject/joinRequestLinkedObject.d.ts.map +1 -0
- package/dist/utils/tests/dummy/comment.d.ts +1 -1
- package/dist/utils/tests/dummy/post.d.ts +3 -3
- package/package.json +1 -1
- package/src/@types/core/events.ts +11 -1
- package/src/@types/core/model.ts +8 -1
- package/src/@types/core/payload.ts +48 -5
- package/src/@types/domains/client.ts +12 -0
- package/src/@types/domains/community.ts +56 -1
- package/src/@types/domains/invitation.ts +116 -0
- package/src/@types/domains/joinRequest.ts +66 -0
- package/src/@types/index.ts +3 -0
- package/src/communityRepository/api/createCommunity.ts +5 -2
- package/src/communityRepository/api/getCommunities.ts +7 -2
- package/src/communityRepository/api/getCommunity.ts +13 -2
- package/src/communityRepository/api/getRecommendedCommunities.ts +11 -4
- package/src/communityRepository/api/getTrendingCommunities.ts +11 -4
- package/src/communityRepository/api/joinCommunity.ts +4 -1
- package/src/communityRepository/api/queryCommunities.ts +6 -1
- package/src/communityRepository/api/updateCommunity.ts +13 -3
- package/src/communityRepository/communityMembership/events/onCommunityJoined.ts +1 -1
- package/src/communityRepository/communityMembership/events/onCommunityLeft.ts +1 -1
- package/src/communityRepository/communityMembership/events/onCommunityUserAdded.ts +1 -1
- package/src/communityRepository/communityMembership/events/onCommunityUserBanned.ts +1 -1
- package/src/communityRepository/communityMembership/events/onCommunityUserChanged.ts +1 -1
- package/src/communityRepository/communityMembership/events/onCommunityUserRemoved.ts +1 -1
- package/src/communityRepository/communityMembership/events/onCommunityUserRoleAdded.ts +1 -1
- package/src/communityRepository/communityMembership/events/onCommunityUserRoleRemoved.ts +1 -1
- package/src/communityRepository/communityMembership/events/onCommunityUserUnbanned.ts +1 -1
- package/src/communityRepository/communityMembership/events/onLocalCommunityJoined.ts +1 -1
- package/src/communityRepository/communityMembership/events/onLocalCommunityLeft.ts +1 -1
- package/src/communityRepository/communityMembership/events/onLocalCommunityUserAdded.ts +1 -1
- package/src/communityRepository/communityMembership/events/onLocalCommunityUserRemoved.ts +1 -1
- package/src/communityRepository/communityMembership/events/onUserDeleted.ts +3 -1
- package/src/communityRepository/communityMembership/events/utils.ts +2 -2
- package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.ts +8 -2
- package/src/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersQueryStreamController.ts +8 -2
- package/src/communityRepository/communityModeration/events/onLocalCommunityRoleAdded.ts +1 -1
- package/src/communityRepository/communityModeration/events/onLocalCommunityRoleRemoved.ts +1 -1
- package/src/communityRepository/events/onCommunityCreated.ts +1 -1
- package/src/communityRepository/events/onCommunityDeleted.ts +1 -1
- package/src/communityRepository/events/onCommunityUpdated.ts +1 -1
- package/src/communityRepository/events/utils.ts +1 -1
- package/src/communityRepository/internalAPI/getMyJoinRequest.ts +43 -0
- package/src/communityRepository/internalAPI/joinCommunity.ts +49 -0
- package/src/communityRepository/joinRequest/events/index.ts +3 -0
- package/src/communityRepository/joinRequest/events/onJoinRequestCreated.ts +33 -0
- package/src/communityRepository/joinRequest/events/onJoinRequestDeleted.ts +33 -0
- package/src/communityRepository/joinRequest/events/onJoinRequestUpdated.ts +33 -0
- package/src/communityRepository/joinRequest/internalAPI/approveJoinRequest.ts +56 -0
- package/src/communityRepository/joinRequest/internalAPI/cancelJoinRequest.ts +51 -0
- package/src/communityRepository/joinRequest/internalAPI/rejectJoinRequest.ts +49 -0
- package/src/communityRepository/observers/getCommunities/CommunitiesQueryStreamController.ts +2 -2
- package/src/communityRepository/observers/getJoinRequests/JoinRequestsLiveCollectionController.ts +126 -0
- package/src/communityRepository/observers/getJoinRequests/JoinRequestsPaginationController.ts +26 -0
- package/src/communityRepository/observers/getJoinRequests/JoinRequestsQueryStreamController.ts +108 -0
- package/src/communityRepository/observers/getJoinRequests/enum.ts +5 -0
- package/src/communityRepository/observers/getJoinRequests.ts +44 -0
- package/src/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesLiveCollectionController.ts +2 -1
- package/src/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesQueryStreamController.ts +2 -2
- package/src/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesLiveCollectionController.ts +2 -1
- package/src/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesQueryStreamController.ts +2 -2
- package/src/communityRepository/observers/searchCommunities/SearchCommunitiesPaginationController.ts +1 -0
- package/src/communityRepository/observers/searchCommunities/SearchCommunitiesQueryStreamController.ts +2 -2
- package/src/communityRepository/observers/semanticSearch/SemanticSearchCommunityQueryStreamController.ts +2 -2
- package/src/communityRepository/utils/communityWithMembership.ts +9 -5
- package/src/communityRepository/utils/payload.ts +28 -2
- package/src/core/liveCollection/PaginationController.ts +1 -1
- package/src/core/liveCollection/PaginationNoPageController.ts +1 -1
- package/src/core/model/idResolvers.ts +3 -0
- package/src/core/model/index.ts +2 -0
- package/src/index.ts +2 -0
- package/src/invitationRepository/events/index.ts +3 -0
- package/src/invitationRepository/events/onLocalInvitationCreated.ts +33 -0
- package/src/invitationRepository/events/onLocalInvitationDeleted.ts +33 -0
- package/src/invitationRepository/events/onLocalInvitationUpdated.ts +33 -0
- package/src/invitationRepository/index.ts +2 -0
- package/src/invitationRepository/internalApi/acceptInvitation.ts +45 -0
- package/src/invitationRepository/internalApi/cancelInvitation.ts +44 -0
- package/src/invitationRepository/internalApi/createInvitations.ts +52 -0
- package/src/invitationRepository/internalApi/getInvitation.ts +47 -0
- package/src/invitationRepository/internalApi/index.ts +4 -0
- package/src/invitationRepository/internalApi/rejectInvitation.ts +45 -0
- package/src/invitationRepository/observers/getInvitations/InvitationsLiveCollectionController.ts +148 -0
- package/src/invitationRepository/observers/getInvitations/InvitationsPaginationController.ts +19 -0
- package/src/invitationRepository/observers/getInvitations/InvitationsQueryStreamController.ts +97 -0
- package/src/invitationRepository/observers/getInvitations/enums.ts +5 -0
- package/src/invitationRepository/observers/getInvitations.ts +44 -0
- package/src/invitationRepository/observers/getMyCommunityInvitations.ts +48 -0
- package/src/invitationRepository/observers/getMyInvitations/MyInvitationsLiveCollectionController.ts +148 -0
- package/src/invitationRepository/observers/getMyInvitations/MyInvitationsPaginationController.ts +22 -0
- package/src/invitationRepository/observers/getMyInvitations/MyInvitationsQueryStreamController.ts +105 -0
- package/src/invitationRepository/observers/index.ts +1 -0
- package/src/invitationRepository/utils/convertRawInvitationToInternalInvitation.ts +8 -0
- package/src/invitationRepository/utils/index.ts +1 -0
- package/src/invitationRepository/utils/prepareInvitationPayload.ts +12 -0
- package/src/invitationRepository/utils/prepareMyInvitationsPayload.ts +12 -0
- package/src/messagePreview/utils/getChannelMessagePreviewWithUser.ts +3 -3
- package/src/messageRepository/api/flagMessage.ts +19 -2
- package/src/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostQueryStreamController.ts +7 -1
- package/src/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.ts +7 -1
- package/src/subChannelRepository/utils/prepareSubChannelPayload.ts +4 -0
- package/src/utils/linkedObject/communityLinkedObject.ts +58 -0
- package/src/utils/linkedObject/index.ts +6 -0
- package/src/utils/linkedObject/invitationLinkedObject.ts +44 -0
- package/src/utils/linkedObject/joinRequestLinkedObject.ts +27 -0
package/dist/index.cjs.js
CHANGED
|
@@ -23,6 +23,12 @@ var uuid__default = /*#__PURE__*/_interopDefaultLegacy(uuid$1);
|
|
|
23
23
|
var hash__default = /*#__PURE__*/_interopDefaultLegacy(hash);
|
|
24
24
|
var Hls__default = /*#__PURE__*/_interopDefaultLegacy(Hls);
|
|
25
25
|
|
|
26
|
+
exports.MembershipAcceptanceTypeEnum = void 0;
|
|
27
|
+
(function (MembershipAcceptanceTypeEnum) {
|
|
28
|
+
MembershipAcceptanceTypeEnum["AUTOMATIC"] = "automatic";
|
|
29
|
+
MembershipAcceptanceTypeEnum["INVITATION"] = "invitation";
|
|
30
|
+
})(exports.MembershipAcceptanceTypeEnum || (exports.MembershipAcceptanceTypeEnum = {}));
|
|
31
|
+
|
|
26
32
|
const FileType = Object.freeze({
|
|
27
33
|
FILE: 'file',
|
|
28
34
|
IMAGE: 'image',
|
|
@@ -112,6 +118,37 @@ const PostContentType = Object.freeze({
|
|
|
112
118
|
POLL: 'poll',
|
|
113
119
|
});
|
|
114
120
|
|
|
121
|
+
exports.InvitationTypeEnum = void 0;
|
|
122
|
+
(function (InvitationTypeEnum) {
|
|
123
|
+
InvitationTypeEnum["CommunityMemberInvite"] = "communityMemberInvite";
|
|
124
|
+
InvitationTypeEnum["LivestreamInvite"] = "livestreamInvite";
|
|
125
|
+
})(exports.InvitationTypeEnum || (exports.InvitationTypeEnum = {}));
|
|
126
|
+
exports.InvitationStatusEnum = void 0;
|
|
127
|
+
(function (InvitationStatusEnum) {
|
|
128
|
+
InvitationStatusEnum["Pending"] = "pending";
|
|
129
|
+
InvitationStatusEnum["Approved"] = "approved";
|
|
130
|
+
InvitationStatusEnum["Rejected"] = "rejected";
|
|
131
|
+
InvitationStatusEnum["Cancelled"] = "cancelled";
|
|
132
|
+
})(exports.InvitationStatusEnum || (exports.InvitationStatusEnum = {}));
|
|
133
|
+
exports.InvitationSortByEnum = void 0;
|
|
134
|
+
(function (InvitationSortByEnum) {
|
|
135
|
+
InvitationSortByEnum["FirstCreated"] = "firstCreated";
|
|
136
|
+
InvitationSortByEnum["LastCreated"] = "lastCreated";
|
|
137
|
+
})(exports.InvitationSortByEnum || (exports.InvitationSortByEnum = {}));
|
|
138
|
+
|
|
139
|
+
exports.JoinRequestStatusEnum = void 0;
|
|
140
|
+
(function (JoinRequestStatusEnum) {
|
|
141
|
+
JoinRequestStatusEnum["Pending"] = "pending";
|
|
142
|
+
JoinRequestStatusEnum["Approved"] = "approved";
|
|
143
|
+
JoinRequestStatusEnum["Rejected"] = "rejected";
|
|
144
|
+
JoinRequestStatusEnum["Cancelled"] = "cancelled";
|
|
145
|
+
})(exports.JoinRequestStatusEnum || (exports.JoinRequestStatusEnum = {}));
|
|
146
|
+
exports.JoinResultStatusEnum = void 0;
|
|
147
|
+
(function (JoinResultStatusEnum) {
|
|
148
|
+
JoinResultStatusEnum["Success"] = "success";
|
|
149
|
+
JoinResultStatusEnum["Pending"] = "pending";
|
|
150
|
+
})(exports.JoinResultStatusEnum || (exports.JoinResultStatusEnum = {}));
|
|
151
|
+
|
|
115
152
|
function getVersion() {
|
|
116
153
|
try {
|
|
117
154
|
// the string ''v7.4.0-cjs'' should be replaced by actual value by @rollup/plugin-replace
|
|
@@ -558,6 +595,8 @@ const idResolvers = {
|
|
|
558
595
|
pinTarget: ({ targetId }) => targetId,
|
|
559
596
|
notificationTrayItem: ({ _id }) => _id,
|
|
560
597
|
notificationTraySeen: ({ userId }) => userId,
|
|
598
|
+
invitation: ({ _id }) => _id,
|
|
599
|
+
joinRequest: ({ joinRequestId }) => joinRequestId,
|
|
561
600
|
};
|
|
562
601
|
/**
|
|
563
602
|
* Retrieve the id resolver matching a domain name
|
|
@@ -610,6 +649,7 @@ const PAYLOAD2MODEL = {
|
|
|
610
649
|
pinTargets: 'pinTarget',
|
|
611
650
|
pins: 'pin',
|
|
612
651
|
notificationTrayItems: 'notificationTrayItem',
|
|
652
|
+
invitations: 'invitation',
|
|
613
653
|
};
|
|
614
654
|
/** hidden */
|
|
615
655
|
const isOutdated = (prevData, nextData) => {
|
|
@@ -4877,122 +4917,1219 @@ const getChannelMessagePreview = (channelId) => {
|
|
|
4877
4917
|
return ((_b = (_a = pullFromCache(['messagePreviewChannel', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : null);
|
|
4878
4918
|
};
|
|
4879
4919
|
|
|
4880
|
-
const
|
|
4881
|
-
|
|
4920
|
+
const userLinkedObject = (user) => {
|
|
4921
|
+
return Object.assign(Object.assign({}, user), { get avatar() {
|
|
4922
|
+
var _a;
|
|
4923
|
+
if (!user.avatarFileId)
|
|
4924
|
+
return undefined;
|
|
4925
|
+
const avatar = (_a = pullFromCache([
|
|
4926
|
+
'file',
|
|
4927
|
+
'get',
|
|
4928
|
+
`${user.avatarFileId}`,
|
|
4929
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
4930
|
+
return avatar;
|
|
4931
|
+
} });
|
|
4932
|
+
};
|
|
4882
4933
|
|
|
4883
|
-
const
|
|
4884
|
-
|
|
4885
|
-
const
|
|
4886
|
-
|
|
4934
|
+
const getChannelMessagePreviewWithUser = (channel) => {
|
|
4935
|
+
var _a;
|
|
4936
|
+
const messagePreview = channel.messagePreviewId
|
|
4937
|
+
? getChannelMessagePreview(channel.channelId)
|
|
4938
|
+
: null;
|
|
4939
|
+
const internalUser = (_a = pullFromCache([
|
|
4940
|
+
'user',
|
|
4941
|
+
'get',
|
|
4942
|
+
messagePreview === null || messagePreview === void 0 ? void 0 : messagePreview.creatorId,
|
|
4943
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
4944
|
+
const messagePreviewWithUser = messagePreview
|
|
4945
|
+
? Object.assign(Object.assign({}, messagePreview), { user: internalUser ? userLinkedObject(internalUser) : undefined }) : null;
|
|
4946
|
+
return Object.assign(Object.assign({}, channel), { messagePreview: messagePreviewWithUser });
|
|
4947
|
+
};
|
|
4948
|
+
|
|
4949
|
+
const updateChannelMessagePreviewCache = (rawPayload) => {
|
|
4950
|
+
var _a, _b;
|
|
4951
|
+
const withMessageFeedInfo = (messagePreview) => {
|
|
4952
|
+
var _a;
|
|
4953
|
+
const messageFeedInfo = (_a = rawPayload.messageFeedsInfo) === null || _a === void 0 ? void 0 : _a.find(messageFeed => {
|
|
4954
|
+
return messageFeed.messageFeedId === messagePreview.messageFeedId;
|
|
4955
|
+
});
|
|
4956
|
+
const { channelPublicId: channelId, messageFeedId: subChannelId, data, dataType, isDeleted, segment, creatorPublicId: creatorId, createdAt, updatedAt, } = messagePreview;
|
|
4957
|
+
return {
|
|
4958
|
+
channelId,
|
|
4959
|
+
subChannelId,
|
|
4960
|
+
data,
|
|
4961
|
+
dataType,
|
|
4962
|
+
isDeleted,
|
|
4963
|
+
segment,
|
|
4964
|
+
creatorId,
|
|
4965
|
+
createdAt,
|
|
4966
|
+
updatedAt,
|
|
4967
|
+
subChannelName: messageFeedInfo === null || messageFeedInfo === void 0 ? void 0 : messageFeedInfo.name,
|
|
4968
|
+
messagePreviewId: messageFeedInfo === null || messageFeedInfo === void 0 ? void 0 : messageFeedInfo.messagePreviewId,
|
|
4969
|
+
subChannelUpdatedAt: messageFeedInfo === null || messageFeedInfo === void 0 ? void 0 : messageFeedInfo.updatedAt,
|
|
4970
|
+
};
|
|
4887
4971
|
};
|
|
4888
|
-
|
|
4972
|
+
const newData = {
|
|
4973
|
+
messagePreviewChannel: (_b = (_a = rawPayload.messagePreviews) === null || _a === void 0 ? void 0 : _a.map(messagePreview => withMessageFeedInfo(messagePreview))) !== null && _b !== void 0 ? _b : [],
|
|
4974
|
+
};
|
|
4975
|
+
ingestInCache(newData);
|
|
4889
4976
|
};
|
|
4890
4977
|
|
|
4891
|
-
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
|
|
4899
|
-
|
|
4900
|
-
|
|
4901
|
-
|
|
4902
|
-
|
|
4903
|
-
|
|
4904
|
-
|
|
4905
|
-
|
|
4906
|
-
|
|
4907
|
-
|
|
4908
|
-
|
|
4909
|
-
|
|
4910
|
-
|
|
4911
|
-
|
|
4912
|
-
|
|
4913
|
-
}
|
|
4914
|
-
|
|
4915
|
-
|
|
4916
|
-
|
|
4917
|
-
|
|
4918
|
-
|
|
4919
|
-
|
|
4920
|
-
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
|
|
4925
|
-
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
|
|
4933
|
-
|
|
4934
|
-
|
|
4935
|
-
|
|
4936
|
-
|
|
4937
|
-
|
|
4938
|
-
|
|
4939
|
-
|
|
4940
|
-
|
|
4941
|
-
|
|
4942
|
-
|
|
4943
|
-
|
|
4944
|
-
|
|
4945
|
-
|
|
4946
|
-
|
|
4947
|
-
|
|
4948
|
-
|
|
4949
|
-
|
|
4950
|
-
|
|
4951
|
-
catch (error) {
|
|
4952
|
-
// stop and destroy all events
|
|
4953
|
-
this.stop();
|
|
4954
|
-
dropFromCache(HIGH_PRIORITY_ANALYTIC_CACHE_KEY);
|
|
4955
|
-
}
|
|
4956
|
-
}
|
|
4978
|
+
const getSubChannelMessagePreview = (subChannelId) => {
|
|
4979
|
+
var _a, _b;
|
|
4980
|
+
return ((_b = (_a = pullFromCache(['messagePreviewSubChannel', 'get', subChannelId])) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : null);
|
|
4981
|
+
};
|
|
4982
|
+
|
|
4983
|
+
const getSubChannelMessagePreviewWithUser = (subChannel) => {
|
|
4984
|
+
var _a;
|
|
4985
|
+
const messagePreview = subChannel.messagePreviewId
|
|
4986
|
+
? getSubChannelMessagePreview(subChannel.subChannelId)
|
|
4987
|
+
: null;
|
|
4988
|
+
const messagePreviewWithUser = messagePreview
|
|
4989
|
+
? Object.assign(Object.assign({}, messagePreview), { user: (_a = pullFromCache(['user', 'get', messagePreview === null || messagePreview === void 0 ? void 0 : messagePreview.creatorId])) === null || _a === void 0 ? void 0 : _a.data }) : null;
|
|
4990
|
+
return Object.assign(Object.assign({}, subChannel), { messagePreview: messagePreviewWithUser });
|
|
4991
|
+
};
|
|
4992
|
+
|
|
4993
|
+
const updateSubChannelMessagePreviewCache = (rawPayload) => {
|
|
4994
|
+
var _a, _b;
|
|
4995
|
+
const withMessageFeedInfo = (messagePreview) => {
|
|
4996
|
+
var _a;
|
|
4997
|
+
const messageFeedInfo = (_a = rawPayload.messageFeeds) === null || _a === void 0 ? void 0 : _a.find(messageFeed => {
|
|
4998
|
+
return messageFeed.messageFeedId === messagePreview.messageFeedId;
|
|
4999
|
+
});
|
|
5000
|
+
const { channelPublicId: channelId, messageFeedId: subChannelId, messageId: messagePreviewId, creatorPublicId: creatorId, data, dataType, isDeleted, segment, createdAt, updatedAt, } = messagePreview;
|
|
5001
|
+
return {
|
|
5002
|
+
messagePreviewId,
|
|
5003
|
+
channelId,
|
|
5004
|
+
subChannelId,
|
|
5005
|
+
data,
|
|
5006
|
+
dataType,
|
|
5007
|
+
isDeleted,
|
|
5008
|
+
segment,
|
|
5009
|
+
creatorId,
|
|
5010
|
+
createdAt,
|
|
5011
|
+
updatedAt,
|
|
5012
|
+
subChannelName: messageFeedInfo === null || messageFeedInfo === void 0 ? void 0 : messageFeedInfo.name,
|
|
5013
|
+
subChannelUpdatedAt: messageFeedInfo === null || messageFeedInfo === void 0 ? void 0 : messageFeedInfo.updatedAt,
|
|
5014
|
+
};
|
|
5015
|
+
};
|
|
5016
|
+
const newData = {
|
|
5017
|
+
messagePreviewSubChannel: (_b = (_a = rawPayload.messages) === null || _a === void 0 ? void 0 : _a.map(messagePreview => withMessageFeedInfo(messagePreview))) !== null && _b !== void 0 ? _b : [],
|
|
5018
|
+
};
|
|
5019
|
+
ingestInCache(newData);
|
|
5020
|
+
};
|
|
5021
|
+
|
|
5022
|
+
/**
|
|
5023
|
+
* ```js
|
|
5024
|
+
* import { shallowClone } from '~/utils/shallowClone'
|
|
5025
|
+
* const newObj = shallowClone(obj)
|
|
5026
|
+
* ```
|
|
5027
|
+
*
|
|
5028
|
+
* Clone an object with same prototype and properties
|
|
5029
|
+
*
|
|
5030
|
+
* @param obj the object to clone
|
|
5031
|
+
* @returns new object with same prototype and properties
|
|
5032
|
+
*
|
|
5033
|
+
* @category utility
|
|
5034
|
+
* @private
|
|
5035
|
+
*/
|
|
5036
|
+
function shallowClone(source, target) {
|
|
5037
|
+
return Object.create(Object.getPrototypeOf(source), Object.assign(Object.assign({}, Object.getOwnPropertyDescriptors(source)), Object.getOwnPropertyDescriptors(target)));
|
|
4957
5038
|
}
|
|
4958
5039
|
|
|
4959
|
-
|
|
4960
|
-
|
|
4961
|
-
|
|
4962
|
-
|
|
4963
|
-
|
|
4964
|
-
|
|
4965
|
-
|
|
4966
|
-
|
|
4967
|
-
|
|
4968
|
-
|
|
4969
|
-
|
|
4970
|
-
|
|
4971
|
-
|
|
4972
|
-
|
|
4973
|
-
|
|
4974
|
-
|
|
4975
|
-
|
|
4976
|
-
|
|
4977
|
-
|
|
4978
|
-
|
|
4979
|
-
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
|
|
4984
|
-
|
|
5040
|
+
function updateSubChannelCache(subChannelId, subChannel, params) {
|
|
5041
|
+
pushToCache(['subChannel', 'get', subChannelId],
|
|
5042
|
+
// eslint-disable-next-line prefer-object-spread
|
|
5043
|
+
shallowClone(subChannel, params));
|
|
5044
|
+
}
|
|
5045
|
+
|
|
5046
|
+
/**
|
|
5047
|
+
* ```js
|
|
5048
|
+
* import { isInTombstone } from '@amityco/ts-sdk'
|
|
5049
|
+
* const user = isInTombstone(["message", "messageId"])
|
|
5050
|
+
* ```
|
|
5051
|
+
*
|
|
5052
|
+
* Checks if the {@link Amity.TombstoneCacheOptions} exists
|
|
5053
|
+
* in cache and it's not expired means it's in tombstone
|
|
5054
|
+
* and we throw an Error
|
|
5055
|
+
*
|
|
5056
|
+
* @param model the model to check
|
|
5057
|
+
* @param modelId the object id to check
|
|
5058
|
+
* @returns the matching cache entry, or undefined.
|
|
5059
|
+
*
|
|
5060
|
+
* @category Cache API
|
|
5061
|
+
*/
|
|
5062
|
+
const isInTombstone = (model, modelId) => {
|
|
5063
|
+
const { log, cache } = getActiveClient();
|
|
5064
|
+
const key = [model, CACHE_KEY_TOMBSTONE, modelId];
|
|
5065
|
+
if (!cache)
|
|
5066
|
+
return;
|
|
5067
|
+
log('cache/api/isInTombstone', key);
|
|
5068
|
+
const isInTombstone = pullFromCache(key);
|
|
5069
|
+
const { lifeSpan } = queryOptions('cache_then_server', CACHE_LIFESPAN_TOMBSTONE);
|
|
5070
|
+
if (isInTombstone && isFresh(isInTombstone.data, lifeSpan)) {
|
|
5071
|
+
throw new ASCApiError('Item not found!', 400400 /* Amity.ServerError.ITEM_NOT_FOUND */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
4985
5072
|
}
|
|
4986
|
-
|
|
4987
|
-
|
|
4988
|
-
|
|
4989
|
-
|
|
4990
|
-
|
|
4991
|
-
|
|
4992
|
-
|
|
4993
|
-
|
|
4994
|
-
|
|
4995
|
-
|
|
5073
|
+
};
|
|
5074
|
+
|
|
5075
|
+
/**
|
|
5076
|
+
* ```js
|
|
5077
|
+
* import { getMessageMarkers } from '@amityco/ts-sdk'
|
|
5078
|
+
* const messageMarkers = await getMessageMarkers(['sch1', 'sch2'])
|
|
5079
|
+
* ```
|
|
5080
|
+
*
|
|
5081
|
+
* Fetches a list of {@link Amity.MessageMarker} by messageIds
|
|
5082
|
+
*
|
|
5083
|
+
* @param messageIds the feed IDs of the {@link Amity.RawMessage} marker to fetch
|
|
5084
|
+
* @returns A list of {@link Amity.MessageMarker} by messageIds
|
|
5085
|
+
*
|
|
5086
|
+
* @category Channel API
|
|
5087
|
+
* @async
|
|
5088
|
+
* @private
|
|
5089
|
+
*/
|
|
5090
|
+
const getMessageMarkers = async (messageIds) => {
|
|
5091
|
+
const client = getActiveClient();
|
|
5092
|
+
client.log('channel/getMessageMarkers', messageIds);
|
|
5093
|
+
const { data: queryPayload } = await client.http.get(`/api/v1/markers/messages`, {
|
|
5094
|
+
params: {
|
|
5095
|
+
messageIds,
|
|
5096
|
+
},
|
|
5097
|
+
});
|
|
5098
|
+
const { contentMarkers, feedMarkers, userMarkers } = queryPayload;
|
|
5099
|
+
const cachedAt = client.cache && Date.now();
|
|
5100
|
+
if (client.cache)
|
|
5101
|
+
ingestInCache({ contentMarkers, feedMarkers, userMarkers }, { cachedAt });
|
|
5102
|
+
fireEvent('local.feedMarker.fetched', { feedMarkers });
|
|
5103
|
+
fireEvent('local.messageMarker.fetched', { contentMarkers });
|
|
5104
|
+
fireEvent('local.userMarker.fetched', { userMarkers });
|
|
5105
|
+
return { data: contentMarkers, cachedAt };
|
|
5106
|
+
};
|
|
5107
|
+
|
|
5108
|
+
const reCalculateChannelUnreadInfo = (channelId) => {
|
|
5109
|
+
var _a;
|
|
5110
|
+
const cacheKeyChannelUnread = ['channelUnreadInfo', 'get', channelId];
|
|
5111
|
+
const cacheChannelUnreadInfo = (_a = pullFromCache(cacheKeyChannelUnread)) === null || _a === void 0 ? void 0 : _a.data;
|
|
5112
|
+
const cacheKeySubChannelUnread = ['subChannelUnreadInfo', 'get'];
|
|
5113
|
+
const cachedSubChannelUnreadInfo = queryCache(cacheKeySubChannelUnread);
|
|
5114
|
+
let channelUnreads = 0;
|
|
5115
|
+
let isMentioned = false;
|
|
5116
|
+
if (cachedSubChannelUnreadInfo && (cachedSubChannelUnreadInfo === null || cachedSubChannelUnreadInfo === void 0 ? void 0 : cachedSubChannelUnreadInfo.length) > 0) {
|
|
5117
|
+
const subChannelUnreadsInfo = cachedSubChannelUnreadInfo === null || cachedSubChannelUnreadInfo === void 0 ? void 0 : cachedSubChannelUnreadInfo.filter(({ data }) => {
|
|
5118
|
+
return data.channelId === channelId && !data.isDeleted;
|
|
5119
|
+
});
|
|
5120
|
+
channelUnreads = subChannelUnreadsInfo
|
|
5121
|
+
.map(({ data }) => data.unreadCount)
|
|
5122
|
+
.reduce((acc, cur) => acc + cur, 0);
|
|
5123
|
+
isMentioned = subChannelUnreadsInfo.some(({ data }) => data.isMentioned);
|
|
5124
|
+
}
|
|
5125
|
+
const channelUnreadInfo = Object.assign(Object.assign({}, (cacheChannelUnreadInfo !== null && cacheChannelUnreadInfo !== void 0 ? cacheChannelUnreadInfo : {
|
|
5126
|
+
channelId,
|
|
5127
|
+
createdAt: new Date().toISOString(),
|
|
5128
|
+
})), { updatedAt: new Date().toISOString(), unreadCount: channelUnreads, isMentioned });
|
|
5129
|
+
pushToCache(cacheKeyChannelUnread, channelUnreadInfo);
|
|
5130
|
+
return channelUnreadInfo;
|
|
5131
|
+
};
|
|
5132
|
+
|
|
5133
|
+
const persistUnreadCountInfo = (payload) => {
|
|
5134
|
+
const { feedMarkers, userFeedMarkers } = payload;
|
|
5135
|
+
// calculate sub channel unread info and channel unread info
|
|
5136
|
+
if (feedMarkers.length > 0 && userFeedMarkers.length > 0) {
|
|
5137
|
+
const channelIds = [];
|
|
5138
|
+
const feedMarkerMap = new Map(feedMarkers.map(fm => [fm.feedId, fm]));
|
|
5139
|
+
userFeedMarkers.forEach(userFeedMarker => {
|
|
5140
|
+
const feedMarker = feedMarkerMap.get(userFeedMarker.feedId);
|
|
5141
|
+
if (!feedMarker)
|
|
5142
|
+
return;
|
|
5143
|
+
if (feedMarker.feedId === userFeedMarker.feedId) {
|
|
5144
|
+
const unreadCount = feedMarker.lastSegment - userFeedMarker.readToSegment;
|
|
5145
|
+
const subChannelUnreadInfo = {
|
|
5146
|
+
subChannelId: feedMarker.feedId,
|
|
5147
|
+
channelId: feedMarker.entityId,
|
|
5148
|
+
readToSegment: userFeedMarker.readToSegment,
|
|
5149
|
+
lastSegment: feedMarker.lastSegment,
|
|
5150
|
+
lastMentionSegment: userFeedMarker.lastMentionSegment,
|
|
5151
|
+
unreadCount: Math.max(0, unreadCount),
|
|
5152
|
+
isMentioned: userFeedMarker.isMentioned,
|
|
5153
|
+
isDeleted: feedMarker.isDeleted,
|
|
5154
|
+
createdAt: userFeedMarker.createdAt,
|
|
5155
|
+
updatedAt: userFeedMarker.updatedAt,
|
|
5156
|
+
};
|
|
5157
|
+
// update sub channel unread info in cache
|
|
5158
|
+
ingestInCache({ subChannelUnreadInfo: [subChannelUnreadInfo] });
|
|
5159
|
+
if (!channelIds.includes(feedMarker.entityId)) {
|
|
5160
|
+
channelIds.push(feedMarker.entityId);
|
|
5161
|
+
}
|
|
5162
|
+
}
|
|
5163
|
+
});
|
|
5164
|
+
// re-calculate channel unread info in cache
|
|
5165
|
+
channelIds.forEach(channelId => {
|
|
5166
|
+
reCalculateChannelUnreadInfo(channelId);
|
|
5167
|
+
});
|
|
5168
|
+
}
|
|
5169
|
+
};
|
|
5170
|
+
|
|
5171
|
+
/**
|
|
5172
|
+
* ```js
|
|
5173
|
+
* import { getSubChannelMarkers } from '@amityco/ts-sdk'
|
|
5174
|
+
* const subChannelMarkers = await getSubChannelMarkers(['sch1', 'sch2'])
|
|
5175
|
+
* ```
|
|
5176
|
+
*
|
|
5177
|
+
* Fetches a paginable list of {@link Amity.SubChannelMarker} objects
|
|
5178
|
+
*
|
|
5179
|
+
* @param messageFeedIds the feed IDs of the {@link Amity.RawSubChannel} marker to fetch
|
|
5180
|
+
* @param page
|
|
5181
|
+
* @returns A page of {@link Amity.SubChannelMarker} objects
|
|
5182
|
+
*
|
|
5183
|
+
* @category Channel API
|
|
5184
|
+
* @async
|
|
5185
|
+
* @private
|
|
5186
|
+
*/
|
|
5187
|
+
const getSubChannelMarkers = async (messageFeedIds, page = { limit: 100 }) => {
|
|
5188
|
+
const client = getActiveClient();
|
|
5189
|
+
client.log('channel/getSubChannelMarkers', messageFeedIds, page);
|
|
5190
|
+
const { data: queryPayload } = await client.http.get(`/api/v1/markers/message-feeds`, {
|
|
5191
|
+
params: {
|
|
5192
|
+
messageFeedIds,
|
|
5193
|
+
options: {
|
|
5194
|
+
token: toToken(page, 'skiplimit'),
|
|
5195
|
+
},
|
|
5196
|
+
},
|
|
5197
|
+
});
|
|
5198
|
+
const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
|
|
5199
|
+
const { userEntityMarkers: userEntityMarkersPayload, userFeedMarkers: userFeedMarkersPayload, userMarkers, feedMarkers: feedMarkersPayload, } = payload;
|
|
5200
|
+
// if consistent mode is enabled, persist the unread count info to the cache
|
|
5201
|
+
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
5202
|
+
persistUnreadCountInfo({
|
|
5203
|
+
feedMarkers: feedMarkersPayload,
|
|
5204
|
+
userFeedMarkers: userFeedMarkersPayload,
|
|
5205
|
+
});
|
|
5206
|
+
}
|
|
5207
|
+
const userEntityMarkers = convertChannelMarkerResponse(userEntityMarkersPayload);
|
|
5208
|
+
const userFeedMarkers = convertSubChannelMarkerResponse(userFeedMarkersPayload);
|
|
5209
|
+
const cachedAt = client.cache && Date.now();
|
|
5210
|
+
if (client.cache)
|
|
5211
|
+
ingestInCache({ userEntityMarkers, userFeedMarkers, userMarkers }, { cachedAt });
|
|
5212
|
+
fireEvent('local.channelMarker.fetched', { userEntityMarkers });
|
|
5213
|
+
fireEvent('local.subChannelMarker.fetched', { userFeedMarkers });
|
|
5214
|
+
fireEvent('local.userMarker.fetched', { userMarkers });
|
|
5215
|
+
const nextPage = toPage(paging.next);
|
|
5216
|
+
const prevPage = toPage(paging.previous);
|
|
5217
|
+
return { data: userFeedMarkers, cachedAt, prevPage, nextPage };
|
|
5218
|
+
};
|
|
5219
|
+
|
|
5220
|
+
const getUserMarker = async () => {
|
|
5221
|
+
const client = getActiveClient();
|
|
5222
|
+
client.log('channel/getUserMarker');
|
|
5223
|
+
const { data: payload } = await client.http.get(`/api/v1/markers/userMarker`);
|
|
5224
|
+
const { userMarkers } = payload;
|
|
5225
|
+
const cachedAt = client.cache && Date.now();
|
|
5226
|
+
if (client.cache)
|
|
5227
|
+
ingestInCache({ userMarkers }, { cachedAt });
|
|
5228
|
+
fireEvent('local.userMarker.fetched', { userMarkers });
|
|
5229
|
+
const latestUserMarker = userMarkers.reduce((maxUserMarker, userMarker) => {
|
|
5230
|
+
if (maxUserMarker == null ||
|
|
5231
|
+
new Date(maxUserMarker.lastSyncAt).getTime() < new Date(userMarker.lastSyncAt).getTime()) {
|
|
5232
|
+
return userMarker;
|
|
5233
|
+
}
|
|
5234
|
+
return maxUserMarker;
|
|
5235
|
+
}, undefined);
|
|
5236
|
+
return { data: latestUserMarker, cachedAt };
|
|
5237
|
+
};
|
|
5238
|
+
|
|
5239
|
+
/** @hidden */
|
|
5240
|
+
/*
|
|
5241
|
+
* @param message payload from http request without myReactions
|
|
5242
|
+
* add myReactions to http response if the event was a reaction event
|
|
5243
|
+
*/
|
|
5244
|
+
const prepareMessagePayloadForCache = (payload, reactors, event) => {
|
|
5245
|
+
const client = getActiveClient();
|
|
5246
|
+
const cached = pullFromCache(['message', 'get', payload.messageId]);
|
|
5247
|
+
// '[]' in cases where the new reaction is the first one
|
|
5248
|
+
const myReactions = (cached === null || cached === void 0 ? void 0 : cached.data.myReactions) || [];
|
|
5249
|
+
// add myReactions to the payload
|
|
5250
|
+
Object.assign(payload, { myReactions });
|
|
5251
|
+
// check if there are any updates to the reactions
|
|
5252
|
+
const latestReaction = reactors[0];
|
|
5253
|
+
const isLatestReactionMine = latestReaction && latestReaction.userId === client.userId;
|
|
5254
|
+
if (!isLatestReactionMine) {
|
|
5255
|
+
return;
|
|
5256
|
+
}
|
|
5257
|
+
// new reaction added
|
|
5258
|
+
if (event === 'message.reactionAdded' && !myReactions.includes(latestReaction.reactionName)) {
|
|
5259
|
+
Object.assign(payload, {
|
|
5260
|
+
myReactions: [...myReactions, latestReaction.reactionName],
|
|
5261
|
+
});
|
|
5262
|
+
}
|
|
5263
|
+
// existing reaction removed
|
|
5264
|
+
if (event === 'message.reactionRemoved' && myReactions.includes(latestReaction.reactionName)) {
|
|
5265
|
+
Object.assign(payload, {
|
|
5266
|
+
myReactions: myReactions.filter(x => x !== latestReaction.reactionName),
|
|
5267
|
+
});
|
|
5268
|
+
}
|
|
5269
|
+
};
|
|
5270
|
+
|
|
5271
|
+
/*
|
|
5272
|
+
* This is a simple utility that infers the value of isDeleted based on the
|
|
5273
|
+
* value of includeDeleted
|
|
5274
|
+
*
|
|
5275
|
+
* There are two important things to note here:
|
|
5276
|
+
* 1. `includeDeleted` is purely client side query param and not recognized by
|
|
5277
|
+
* the server
|
|
5278
|
+
* 2. The only values we wish to expose with regards to `isDeleted` (the server
|
|
5279
|
+
* param for queries) is false | undefined and want to disallow users to query
|
|
5280
|
+
* for deleted entities
|
|
5281
|
+
*
|
|
5282
|
+
* Although this is a very simple utility, it's only purpose is to keep things
|
|
5283
|
+
* DRY
|
|
5284
|
+
*/
|
|
5285
|
+
const inferIsDeleted = (includeDeleted) => includeDeleted === true ? undefined : false;
|
|
5286
|
+
|
|
5287
|
+
function getSubChannelIsMentioned(channelId, subChannelId, marker) {
|
|
5288
|
+
var _a, _b;
|
|
5289
|
+
// Look for `unreadCount` in the marker param first
|
|
5290
|
+
if (marker) {
|
|
5291
|
+
return marker.hasMentioned;
|
|
5292
|
+
}
|
|
5293
|
+
const client = getActiveClient();
|
|
5294
|
+
// If consistent mode is enabled, look in the SubChannelUnreadCountInfo cache
|
|
5295
|
+
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
5296
|
+
const cachedUnreadCount = (_a = pullFromCache([
|
|
5297
|
+
'subChannelUnreadInfo',
|
|
5298
|
+
'get',
|
|
5299
|
+
subChannelId,
|
|
5300
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
5301
|
+
if (cachedUnreadCount) {
|
|
5302
|
+
return cachedUnreadCount.isMentioned;
|
|
5303
|
+
}
|
|
5304
|
+
return false;
|
|
5305
|
+
}
|
|
5306
|
+
const key = {
|
|
5307
|
+
entityId: channelId,
|
|
5308
|
+
feedId: subChannelId,
|
|
5309
|
+
userId: getActiveUser()._id,
|
|
5310
|
+
};
|
|
5311
|
+
// If the marker param is not set, look in the cache
|
|
5312
|
+
const cachedMarker = (_b = pullFromCache([
|
|
5313
|
+
'subChannelMarker',
|
|
5314
|
+
'get',
|
|
5315
|
+
getResolver('subChannelMarker')(key),
|
|
5316
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
5317
|
+
if (cachedMarker) {
|
|
5318
|
+
return cachedMarker.hasMentioned;
|
|
5319
|
+
}
|
|
5320
|
+
// and if not found in cache use default value `false`
|
|
5321
|
+
return false;
|
|
5322
|
+
}
|
|
5323
|
+
|
|
5324
|
+
function getSubChannelUnreadCount(channelId, subChannelId, marker) {
|
|
5325
|
+
var _a, _b;
|
|
5326
|
+
// Look for `unreadCount` in the marker param first
|
|
5327
|
+
if (marker) {
|
|
5328
|
+
return marker.unreadCount;
|
|
5329
|
+
}
|
|
5330
|
+
const client = getActiveClient();
|
|
5331
|
+
// If consistent mode is enabled, look in the SubChannelUnreadCountInfo cache
|
|
5332
|
+
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
5333
|
+
const cachedUnreadCount = (_a = pullFromCache([
|
|
5334
|
+
'subChannelUnreadInfo',
|
|
5335
|
+
'get',
|
|
5336
|
+
subChannelId,
|
|
5337
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
5338
|
+
if (cachedUnreadCount) {
|
|
5339
|
+
return cachedUnreadCount.isDeleted ? 0 : cachedUnreadCount.unreadCount;
|
|
5340
|
+
}
|
|
5341
|
+
return 0;
|
|
5342
|
+
}
|
|
5343
|
+
const key = {
|
|
5344
|
+
entityId: channelId,
|
|
5345
|
+
feedId: subChannelId,
|
|
5346
|
+
userId: getActiveUser()._id,
|
|
5347
|
+
};
|
|
5348
|
+
// If the marker param is not set, look in the cache
|
|
5349
|
+
const cachedMarker = (_b = pullFromCache([
|
|
5350
|
+
'subChannelMarker',
|
|
5351
|
+
'get',
|
|
5352
|
+
getResolver('subChannelMarker')(key),
|
|
5353
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
5354
|
+
if (cachedMarker) {
|
|
5355
|
+
return cachedMarker.unreadCount;
|
|
5356
|
+
}
|
|
5357
|
+
// and if not found in cache use default value `0`
|
|
5358
|
+
return 0;
|
|
5359
|
+
}
|
|
5360
|
+
|
|
5361
|
+
const MARKER_INCLUDED_SUB_CHANNEL_TYPE$1 = ['broadcast', 'conversation', 'community'];
|
|
5362
|
+
const isUnreadCountSupport$2 = ({ channelType }) => MARKER_INCLUDED_SUB_CHANNEL_TYPE$1.includes(channelType);
|
|
5363
|
+
function convertFromRaw$2(_a) {
|
|
5364
|
+
var { channelId, channelPublicId, channelType, childCount, creatorId, creatorPublicId, lastMessageId, lastMessageTimestamp, messageFeedId, name } = _a, rest = __rest(_a, ["channelId", "channelPublicId", "channelType", "childCount", "creatorId", "creatorPublicId", "lastMessageId", "lastMessageTimestamp", "messageFeedId", "name"]);
|
|
5365
|
+
return Object.assign(Object.assign({ get unreadCount() {
|
|
5366
|
+
return getSubChannelUnreadCount(channelId, messageFeedId);
|
|
5367
|
+
},
|
|
5368
|
+
get hasMentioned() {
|
|
5369
|
+
return getSubChannelIsMentioned(channelId, messageFeedId);
|
|
5370
|
+
},
|
|
5371
|
+
get isMentioned() {
|
|
5372
|
+
return getSubChannelIsMentioned(channelId, messageFeedId);
|
|
5373
|
+
} }, rest), { channelId: channelPublicId, creatorId: creatorPublicId, displayName: name, lastActivity: lastMessageTimestamp, latestMessageId: lastMessageId, messageCount: childCount, subChannelId: messageFeedId, isUnreadCountSupport: isUnreadCountSupport$2({ channelType }) });
|
|
5374
|
+
}
|
|
5375
|
+
|
|
5376
|
+
const mergePayloadWithLocal = (payload) => {
|
|
5377
|
+
var _a, _b, _c;
|
|
5378
|
+
const localMessage = (_b = (_a = queryCache(['message', 'get'])) === null || _a === void 0 ? void 0 : _a.find(({ data }) => data.messageId === payload.messageId)) === null || _b === void 0 ? void 0 : _b.data;
|
|
5379
|
+
if (localMessage) {
|
|
5380
|
+
return Object.assign(Object.assign(Object.assign({}, localMessage), payload), {
|
|
5381
|
+
// NOTE: referenceId is missing in the some payload event. If we have local message data with referenceId, use it instead.
|
|
5382
|
+
referenceId: (_c = localMessage.referenceId) !== null && _c !== void 0 ? _c : payload.referenceId });
|
|
5383
|
+
}
|
|
5384
|
+
return payload;
|
|
5385
|
+
};
|
|
5386
|
+
function convertFromRaw$1(message, reactors, event) {
|
|
5387
|
+
var _a;
|
|
5388
|
+
const mergeMessage = mergePayloadWithLocal(message);
|
|
5389
|
+
const { channelPublicId, childCount, creatorPublicId, mentionedUsers, messageFeedId, myReactions, reactionCount, reactions, referenceId, segment, messageId, creatorId } = mergeMessage, rest = __rest(mergeMessage, ["channelPublicId", "childCount", "creatorPublicId", "mentionedUsers", "messageFeedId", "myReactions", "reactionCount", "reactions", "referenceId", "segment", "messageId", "creatorId"]);
|
|
5390
|
+
let cache;
|
|
5391
|
+
if (referenceId) {
|
|
5392
|
+
cache = pullFromCache(['message', 'get', referenceId]);
|
|
5393
|
+
}
|
|
5394
|
+
if (!cache) {
|
|
5395
|
+
cache = pullFromCache(['message', 'get', messageId]);
|
|
5396
|
+
}
|
|
5397
|
+
const out = Object.assign(Object.assign({}, rest), { messageId, channelId: channelPublicId, channelSegment: segment, childrenNumber: childCount, creatorId: creatorPublicId, creatorPrivateId: message.creatorId, reactions: reactions !== null && reactions !== void 0 ? reactions : {},
|
|
5398
|
+
/*
|
|
5399
|
+
* Previously, myReactions were added only if it was part of the payload.
|
|
5400
|
+
* So empty myReactions were not present. So I've edited the payload to add
|
|
5401
|
+
* a default for those cases.
|
|
5402
|
+
*
|
|
5403
|
+
* Check git blame for previous iteration
|
|
5404
|
+
*/
|
|
5405
|
+
myReactions: myReactions || ((_a = cache === null || cache === void 0 ? void 0 : cache.data.myReactions) !== null && _a !== void 0 ? _a : []), reactionsCount: reactionCount, subChannelId: messageFeedId, uniqueId: cache ? cache.data.uniqueId : messageId, referenceId, syncState: "synced" /* Amity.SyncState.Synced */ });
|
|
5406
|
+
if (mentionedUsers) {
|
|
5407
|
+
out.mentionees = mentionedUsers.map(mention => {
|
|
5408
|
+
if (mention.type === 'channel') {
|
|
5409
|
+
return mention;
|
|
5410
|
+
}
|
|
5411
|
+
return { type: 'user', userIds: mention.userPublicIds };
|
|
5412
|
+
});
|
|
5413
|
+
}
|
|
5414
|
+
if (reactors && reactors.length && event) {
|
|
5415
|
+
// mqtt event
|
|
5416
|
+
prepareMessagePayloadForCache(out, reactors, event);
|
|
5417
|
+
}
|
|
5418
|
+
return out;
|
|
5419
|
+
}
|
|
5420
|
+
const preUpdateMessageCache = (rawPayload) => {
|
|
5421
|
+
ingestInCache({
|
|
5422
|
+
messages: rawPayload.messages.map(message => convertFromRaw$1(message, rawPayload.reactions)),
|
|
5423
|
+
});
|
|
5424
|
+
};
|
|
5425
|
+
const DEBOUNCE_TIME = 2000;
|
|
5426
|
+
const currentDebounceMap = {};
|
|
5427
|
+
const prepareMessagePayload = async (payload, event) => {
|
|
5428
|
+
const markerIds = payload.messages.map(({ messageId }) => messageId);
|
|
5429
|
+
if (markerIds.length > 0) {
|
|
5430
|
+
// since the get markers method requires a channel cache to function with the reducer.
|
|
5431
|
+
preUpdateMessageCache(payload);
|
|
5432
|
+
const markerIdsKey = markerIds.join('');
|
|
5433
|
+
if (currentDebounceMap[markerIdsKey]) {
|
|
5434
|
+
clearTimeout(currentDebounceMap[markerIdsKey]);
|
|
5435
|
+
}
|
|
5436
|
+
currentDebounceMap[markerIdsKey] = setTimeout(() => {
|
|
5437
|
+
try {
|
|
5438
|
+
getMessageMarkers(markerIds);
|
|
5439
|
+
}
|
|
5440
|
+
catch (_error) {
|
|
5441
|
+
// do nothing
|
|
5442
|
+
}
|
|
5443
|
+
}, DEBOUNCE_TIME);
|
|
5444
|
+
}
|
|
5445
|
+
const { messageFeeds } = payload, restPayload = __rest(payload, ["messageFeeds"]);
|
|
5446
|
+
// upsert messageFeeds to subchannel cache because messageFeeds from event payload not include messagePreviewId
|
|
5447
|
+
if (messageFeeds && messageFeeds.length > 0) {
|
|
5448
|
+
messageFeeds === null || messageFeeds === void 0 ? void 0 : messageFeeds.forEach(messageFeed => {
|
|
5449
|
+
var _a, _b;
|
|
5450
|
+
const subChannelCache = (_b = (_a = pullFromCache(['subChannel', 'get', messageFeed.messageFeedId])) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : {};
|
|
5451
|
+
// exclude getter properties from existing subChannel cache, update only other properties to existing subChannel cache
|
|
5452
|
+
const _c = convertFromRaw$2(messageFeed), restSubChannel = __rest(_c, ["unreadCount", "isMentioned"]);
|
|
5453
|
+
updateSubChannelCache(messageFeed.messageFeedId, subChannelCache, restSubChannel);
|
|
5454
|
+
});
|
|
5455
|
+
}
|
|
5456
|
+
return Object.assign(Object.assign({}, restPayload), { messages: payload.messages.map(m => convertFromRaw$1(m, payload.reactions, event)) });
|
|
5457
|
+
};
|
|
5458
|
+
function convertParams(_a) {
|
|
5459
|
+
var { subChannelId, mentionees, dataType, data } = _a, rest = __rest(_a, ["subChannelId", "mentionees", "dataType", "data"]);
|
|
5460
|
+
if (dataType === MessageContentType.IMAGE || dataType === MessageContentType.FILE) {
|
|
5461
|
+
return Object.assign({ messageFeedId: subChannelId, mentionedUsers: mentionees, dataType, data: Object.assign({ caption: '' }, data) }, rest);
|
|
5462
|
+
}
|
|
5463
|
+
return Object.assign({ messageFeedId: subChannelId, mentionedUsers: mentionees, dataType, data }, rest);
|
|
5464
|
+
}
|
|
5465
|
+
function convertQueryParams$1(_a) {
|
|
5466
|
+
var { sortBy, subChannelId, includingTags, excludingTags, includeDeleted, aroundMessageId, limit, type } = _a, rest = __rest(_a, ["sortBy", "subChannelId", "includingTags", "excludingTags", "includeDeleted", "aroundMessageId", "limit", "type"]);
|
|
5467
|
+
const out = Object.assign(Object.assign({}, rest), { messageFeedId: subChannelId, isDeleted: inferIsDeleted(includeDeleted), options: {
|
|
5468
|
+
sortBy,
|
|
5469
|
+
limit: limit || COLLECTION_DEFAULT_PAGINATION_LIMIT,
|
|
5470
|
+
around: aroundMessageId,
|
|
5471
|
+
} });
|
|
5472
|
+
if (includingTags) {
|
|
5473
|
+
out.includeTags = includingTags;
|
|
5474
|
+
}
|
|
5475
|
+
if (type) {
|
|
5476
|
+
out.dataType = type;
|
|
5477
|
+
}
|
|
5478
|
+
if (excludingTags) {
|
|
5479
|
+
out.excludeTags = excludingTags;
|
|
5480
|
+
}
|
|
5481
|
+
return out;
|
|
5482
|
+
}
|
|
5483
|
+
|
|
5484
|
+
function convertRawUserToInternalUser(rawUser) {
|
|
5485
|
+
return Object.assign(Object.assign({}, rawUser), { isGlobalBanned: (rawUser === null || rawUser === void 0 ? void 0 : rawUser.isGlobalBan) || false });
|
|
5486
|
+
}
|
|
5487
|
+
|
|
5488
|
+
const MARKER_INCLUDED_SUB_CHANNEL_TYPE = ['broadcast', 'conversation', 'community'];
|
|
5489
|
+
/**
|
|
5490
|
+
* Filter sub channel by type. Only conversation, community and broadcast type are included.
|
|
5491
|
+
*/
|
|
5492
|
+
const isUnreadCountSupport$1 = ({ channelType }) => MARKER_INCLUDED_SUB_CHANNEL_TYPE.includes(channelType);
|
|
5493
|
+
const preUpdateSubChannelCache = (rawPayload) => {
|
|
5494
|
+
ingestInCache({
|
|
5495
|
+
messageFeeds: rawPayload.messageFeeds.map(messageFeed => convertFromRaw$2(messageFeed)),
|
|
5496
|
+
});
|
|
5497
|
+
};
|
|
5498
|
+
const prepareSubChannelPayload = async (rawPayload) => {
|
|
5499
|
+
const markerIds = rawPayload.messageFeeds
|
|
5500
|
+
.filter(isUnreadCountSupport$1)
|
|
5501
|
+
.map(({ messageFeedId }) => messageFeedId);
|
|
5502
|
+
if (markerIds.length > 0) {
|
|
5503
|
+
// since the get markers method requires a channel cache to function with the reducer.
|
|
5504
|
+
preUpdateSubChannelCache(rawPayload);
|
|
5505
|
+
try {
|
|
5506
|
+
await getSubChannelMarkers(markerIds);
|
|
5507
|
+
}
|
|
5508
|
+
catch (e) {
|
|
5509
|
+
// empty block (from the spec, allow marker fetch to fail without having to do anything)
|
|
5510
|
+
}
|
|
5511
|
+
}
|
|
5512
|
+
updateSubChannelMessagePreviewCache(rawPayload);
|
|
5513
|
+
// attach marker to sub channel
|
|
5514
|
+
const messageFeeds = rawPayload.messageFeeds.map(convertFromRaw$2);
|
|
5515
|
+
const messages = rawPayload.messages.map(m => convertFromRaw$1(m));
|
|
5516
|
+
const user = rawPayload.users.map(convertRawUserToInternalUser);
|
|
5517
|
+
return Object.assign(Object.assign({}, rawPayload), { messageFeeds,
|
|
5518
|
+
messages, users: user });
|
|
5519
|
+
};
|
|
5520
|
+
function convertQueryParams(_a) {
|
|
5521
|
+
var { excludeDefaultSubChannel } = _a, rest = __rest(_a, ["excludeDefaultSubChannel"]);
|
|
5522
|
+
const out = Object.assign({}, rest);
|
|
5523
|
+
if (excludeDefaultSubChannel !== undefined) {
|
|
5524
|
+
out.excludeDefaultMessageFeed = excludeDefaultSubChannel;
|
|
5525
|
+
}
|
|
5526
|
+
return out;
|
|
5527
|
+
}
|
|
5528
|
+
|
|
5529
|
+
/**
|
|
5530
|
+
* ```js
|
|
5531
|
+
* import { getSubChannel } from '@amityco/ts-sdk'
|
|
5532
|
+
* const subChannel = await getSubChannel('foobar')
|
|
5533
|
+
* ```
|
|
5534
|
+
*
|
|
5535
|
+
* Fetches a {@link Amity.SubChannel} object
|
|
5536
|
+
*
|
|
5537
|
+
* @param subChannelId the ID of the {@link Amity.SubChannel} to fetch
|
|
5538
|
+
* @returns the associated {@link Amity.SubChannel} object
|
|
5539
|
+
*
|
|
5540
|
+
* @category Channel API
|
|
5541
|
+
* @async
|
|
5542
|
+
*/
|
|
5543
|
+
const getSubChannel$1 = async (subChannelId) => {
|
|
5544
|
+
const client = getActiveClient();
|
|
5545
|
+
client.log('channel/getSubChannel', subChannelId);
|
|
5546
|
+
isInTombstone('subChannel', subChannelId);
|
|
5547
|
+
try {
|
|
5548
|
+
const response = await client.http.get(`/api/v5/message-feeds/${encodeURIComponent(subChannelId)}`);
|
|
5549
|
+
const data = await prepareSubChannelPayload(response.data);
|
|
5550
|
+
const cachedAt = client.cache && Date.now();
|
|
5551
|
+
if (client.cache)
|
|
5552
|
+
ingestInCache(data, { cachedAt });
|
|
5553
|
+
fireEvent('local.message-feed.fetched', data);
|
|
5554
|
+
return {
|
|
5555
|
+
data: data.messageFeeds[0],
|
|
5556
|
+
cachedAt,
|
|
5557
|
+
};
|
|
5558
|
+
}
|
|
5559
|
+
catch (error) {
|
|
5560
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
5561
|
+
pushToTombstone('subChannel', subChannelId);
|
|
5562
|
+
}
|
|
5563
|
+
throw error;
|
|
5564
|
+
}
|
|
5565
|
+
};
|
|
5566
|
+
/**
|
|
5567
|
+
* ```js
|
|
5568
|
+
* import { getSubChannel } from '@amityco/ts-sdk'
|
|
5569
|
+
* const subChannel = getSubChannel.locally('foobar')
|
|
5570
|
+
* ```
|
|
5571
|
+
*
|
|
5572
|
+
* Fetches a {@link Amity.SubChannel} object from cache
|
|
5573
|
+
*
|
|
5574
|
+
* @param subChannelId the ID of the {@link Amity.SubChannel} to fetch
|
|
5575
|
+
* @returns the associated {@link Amity.SubChannel} object
|
|
5576
|
+
*
|
|
5577
|
+
* @category Channel API
|
|
5578
|
+
*/
|
|
5579
|
+
getSubChannel$1.locally = (subChannelId) => {
|
|
5580
|
+
const client = getActiveClient();
|
|
5581
|
+
client.log('channel/getSubChannel.locally', subChannelId);
|
|
5582
|
+
if (!client.cache)
|
|
5583
|
+
return;
|
|
5584
|
+
const cached = pullFromCache(['subChannel', 'get', subChannelId]);
|
|
5585
|
+
if (!cached)
|
|
5586
|
+
return;
|
|
5587
|
+
return {
|
|
5588
|
+
data: cached.data,
|
|
5589
|
+
cachedAt: cached.cachedAt,
|
|
5590
|
+
};
|
|
5591
|
+
};
|
|
5592
|
+
|
|
5593
|
+
const convertDateStringToTimestamp = (dateString) => {
|
|
5594
|
+
return new Date(dateString).getTime();
|
|
5595
|
+
};
|
|
5596
|
+
|
|
5597
|
+
const getMessagePreviewSetting$1 = async () => {
|
|
5598
|
+
const client = getActiveClient();
|
|
5599
|
+
return client.getMessagePreviewSetting(false);
|
|
5600
|
+
};
|
|
5601
|
+
const getSubChannelCache = async (subChannelId) => {
|
|
5602
|
+
var _a;
|
|
5603
|
+
let subChannelCache = (_a = pullFromCache(['subChannel', 'get', subChannelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
5604
|
+
if (!subChannelCache) {
|
|
5605
|
+
subChannelCache = (await getSubChannel$1(subChannelId)).data;
|
|
5606
|
+
}
|
|
5607
|
+
return subChannelCache;
|
|
5608
|
+
};
|
|
5609
|
+
const isLastestMessageOnSubchannel = (message) => {
|
|
5610
|
+
var _a;
|
|
5611
|
+
const cache = (_a = pullFromCache([
|
|
5612
|
+
'messagePreviewSubChannel',
|
|
5613
|
+
'get',
|
|
5614
|
+
message.subChannelId,
|
|
5615
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
5616
|
+
// The message payload from optimistic created event has no segment, so we check createdAt instead.
|
|
5617
|
+
return (!cache ||
|
|
5618
|
+
cache.segment <= message.channelSegment ||
|
|
5619
|
+
convertDateStringToTimestamp(cache.createdAt) <= convertDateStringToTimestamp(message.createdAt));
|
|
5620
|
+
};
|
|
5621
|
+
const isLastestMessageOnChannel = (message) => {
|
|
5622
|
+
var _a;
|
|
5623
|
+
const cache = (_a = pullFromCache([
|
|
5624
|
+
'messagePreviewChannel',
|
|
5625
|
+
'get',
|
|
5626
|
+
message.channelId,
|
|
5627
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
5628
|
+
return (!cache ||
|
|
5629
|
+
convertDateStringToTimestamp(cache.createdAt) <= convertDateStringToTimestamp(message.createdAt));
|
|
5630
|
+
};
|
|
5631
|
+
const handleMessageCreatedOnSubChannel = async (message) => {
|
|
5632
|
+
const messagePreviewSetting = await getMessagePreviewSetting$1();
|
|
5633
|
+
const { channelId, messageId: messagePreviewId, creatorId, createdAt, updatedAt, data, dataType, subChannelId, channelSegment: segment, isDeleted, } = message;
|
|
5634
|
+
// 1. get subChannel from cache, if not exist fetch from server
|
|
5635
|
+
const subChannelCache = await getSubChannelCache(subChannelId);
|
|
5636
|
+
// 2. if messagePreviewSetting is NO_MESSAGE_PREVEIW, update only lastActiviy in subChannel cache
|
|
5637
|
+
if (messagePreviewSetting === "no-message-preview" /* Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW */) {
|
|
5638
|
+
// 2.1 if the message is the latest message, update lastActivity to be createdAt in subChannel cache
|
|
5639
|
+
if (convertDateStringToTimestamp(subChannelCache.lastActivity) <
|
|
5640
|
+
convertDateStringToTimestamp(createdAt))
|
|
5641
|
+
updateSubChannelCache(message.subChannelId, subChannelCache, {
|
|
5642
|
+
lastActivity: createdAt,
|
|
5643
|
+
});
|
|
5644
|
+
return;
|
|
5645
|
+
}
|
|
5646
|
+
// 3. if messagePreviewSetting is `NOT` NO_MESSAGE_PREVEIW, update messagePreviewSubChannel and subChannel cache
|
|
5647
|
+
// 3.1 check if the message is the latest message, if not ignore the message.
|
|
5648
|
+
if (!isLastestMessageOnSubchannel(message))
|
|
5649
|
+
return;
|
|
5650
|
+
// 3.2 if the message is the latest message, update messagePreviewSubChannel and subChannel cache
|
|
5651
|
+
pushToCache(['messagePreviewSubChannel', 'get', message.subChannelId], {
|
|
5652
|
+
channelId,
|
|
5653
|
+
creatorId,
|
|
5654
|
+
messagePreviewId,
|
|
5655
|
+
createdAt,
|
|
5656
|
+
updatedAt,
|
|
5657
|
+
subChannelId,
|
|
5658
|
+
data,
|
|
5659
|
+
dataType,
|
|
5660
|
+
segment,
|
|
5661
|
+
isDeleted,
|
|
5662
|
+
subChannelUpdatedAt: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.updatedAt,
|
|
5663
|
+
subChannelName: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.displayName,
|
|
5664
|
+
});
|
|
5665
|
+
updateSubChannelCache(message.subChannelId, subChannelCache, {
|
|
5666
|
+
lastActivity: createdAt,
|
|
5667
|
+
messagePreviewId,
|
|
5668
|
+
});
|
|
5669
|
+
};
|
|
5670
|
+
const handleMessageUpdatedOnSubChannel = async (message) => {
|
|
5671
|
+
var _a;
|
|
5672
|
+
const { channelId, messageId: messagePreviewId, creatorId, createdAt, updatedAt, data, dataType, subChannelId, channelSegment: segment, isDeleted, } = message;
|
|
5673
|
+
const messagePreviewSubChannelCache = (_a = pullFromCache([
|
|
5674
|
+
'messagePreviewSubChannel',
|
|
5675
|
+
'get',
|
|
5676
|
+
message.subChannelId,
|
|
5677
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
5678
|
+
// if messagePreviewSubChannel is not exist, ignore the message.
|
|
5679
|
+
if (messagePreviewSubChannelCache &&
|
|
5680
|
+
messagePreviewSubChannelCache.messagePreviewId === message.messageId) {
|
|
5681
|
+
const subChannelCache = await getSubChannelCache(subChannelId);
|
|
5682
|
+
pushToCache(['messagePreviewSubChannel', 'get', message.subChannelId], {
|
|
5683
|
+
channelId,
|
|
5684
|
+
creatorId,
|
|
5685
|
+
messagePreviewId,
|
|
5686
|
+
createdAt,
|
|
5687
|
+
updatedAt,
|
|
5688
|
+
subChannelId,
|
|
5689
|
+
data,
|
|
5690
|
+
dataType,
|
|
5691
|
+
segment,
|
|
5692
|
+
isDeleted,
|
|
5693
|
+
subChannelUpdatedAt: subChannelCache.updatedAt,
|
|
5694
|
+
subChannelName: messagePreviewSubChannelCache.subChannelName,
|
|
5695
|
+
});
|
|
5696
|
+
}
|
|
5697
|
+
};
|
|
5698
|
+
const handleMessageCreated = async (message) => {
|
|
5699
|
+
const { channelId, messageId: messagePreviewId, creatorId, createdAt, updatedAt, data, dataType, subChannelId, channelSegment: segment, isDeleted, } = message;
|
|
5700
|
+
if (isLastestMessageOnChannel(message)) {
|
|
5701
|
+
const subChannelCache = await getSubChannelCache(subChannelId);
|
|
5702
|
+
pushToCache(['messagePreviewChannel', 'get', message.channelId], {
|
|
5703
|
+
channelId,
|
|
5704
|
+
creatorId,
|
|
5705
|
+
messagePreviewId,
|
|
5706
|
+
createdAt,
|
|
5707
|
+
updatedAt,
|
|
5708
|
+
subChannelId,
|
|
5709
|
+
data,
|
|
5710
|
+
dataType,
|
|
5711
|
+
segment,
|
|
5712
|
+
isDeleted,
|
|
5713
|
+
subChannelUpdatedAt: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.updatedAt,
|
|
5714
|
+
subChannelName: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.displayName,
|
|
5715
|
+
});
|
|
5716
|
+
}
|
|
5717
|
+
};
|
|
5718
|
+
const handleMessageUpdated = async (message) => {
|
|
5719
|
+
/**
|
|
5720
|
+
* Channel Case
|
|
5721
|
+
*/
|
|
5722
|
+
var _a;
|
|
5723
|
+
const { channelId, messageId: messagePreviewId, creatorId, createdAt, updatedAt, data, dataType, subChannelId, channelSegment: segment, isDeleted, } = message;
|
|
5724
|
+
const messagePreviewChannelCache = (_a = pullFromCache([
|
|
5725
|
+
'messagePreviewChannel',
|
|
5726
|
+
'get',
|
|
5727
|
+
message.channelId,
|
|
5728
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
5729
|
+
if (messagePreviewChannelCache &&
|
|
5730
|
+
messagePreviewChannelCache.messagePreviewId === message.messageId) {
|
|
5731
|
+
const subChannelCache = await getSubChannelCache(subChannelId);
|
|
5732
|
+
pushToCache(['messagePreviewChannel', 'get', message.channelId], {
|
|
5733
|
+
channelId,
|
|
5734
|
+
creatorId,
|
|
5735
|
+
messagePreviewId,
|
|
5736
|
+
createdAt,
|
|
5737
|
+
updatedAt,
|
|
5738
|
+
subChannelId,
|
|
5739
|
+
data,
|
|
5740
|
+
dataType,
|
|
5741
|
+
segment,
|
|
5742
|
+
isDeleted,
|
|
5743
|
+
subChannelUpdatedAt: subChannelCache.updatedAt,
|
|
5744
|
+
subChannelName: messagePreviewChannelCache.subChannelName,
|
|
5745
|
+
});
|
|
5746
|
+
}
|
|
5747
|
+
};
|
|
5748
|
+
const handleSubChannelUpdated = async (subChannel) => {
|
|
5749
|
+
var _a, _b, _c, _d;
|
|
5750
|
+
const { channelId, subChannelId } = subChannel;
|
|
5751
|
+
/** Channel Case */
|
|
5752
|
+
const messagePreviewChannelCache = (_a = pullFromCache([
|
|
5753
|
+
'messagePreviewChannel',
|
|
5754
|
+
'get',
|
|
5755
|
+
channelId,
|
|
5756
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
5757
|
+
if ((messagePreviewChannelCache === null || messagePreviewChannelCache === void 0 ? void 0 : messagePreviewChannelCache.subChannelId) === subChannelId) {
|
|
5758
|
+
const subChannelCache = (_b = pullFromCache([
|
|
5759
|
+
'subChannel',
|
|
5760
|
+
'get',
|
|
5761
|
+
subChannelId,
|
|
5762
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
5763
|
+
pushToCache(['messagePreviewChannel', 'get', channelId], Object.assign(Object.assign({}, messagePreviewChannelCache), { subChannelName: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.displayName, subChannelUpdatedAt: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.updatedAt }));
|
|
5764
|
+
}
|
|
5765
|
+
/** SubChannel Case */
|
|
5766
|
+
const messagePreviewSubChannelCache = (_c = pullFromCache([
|
|
5767
|
+
'messagePreviewSubChannel',
|
|
5768
|
+
'get',
|
|
5769
|
+
subChannelId,
|
|
5770
|
+
])) === null || _c === void 0 ? void 0 : _c.data;
|
|
5771
|
+
if (messagePreviewSubChannelCache &&
|
|
5772
|
+
new Date(messagePreviewSubChannelCache.updatedAt).valueOf() >
|
|
5773
|
+
new Date(subChannel.updatedAt).valueOf()) {
|
|
5774
|
+
const subChannelCache = (_d = pullFromCache([
|
|
5775
|
+
'subChannel',
|
|
5776
|
+
'get',
|
|
5777
|
+
subChannelId,
|
|
5778
|
+
])) === null || _d === void 0 ? void 0 : _d.data;
|
|
5779
|
+
pushToCache(['messagePreviewSubChannel', 'get', subChannelId], Object.assign(Object.assign({}, messagePreviewSubChannelCache), { subChannelName: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.displayName, subChannelUpdatedAt: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.updatedAt }));
|
|
5780
|
+
}
|
|
5781
|
+
};
|
|
5782
|
+
|
|
5783
|
+
const MARKER_INCLUDED_CHANNEL_TYPE = ['broadcast', 'conversation', 'community'];
|
|
5784
|
+
const isUnreadCountSupport = ({ type }) => MARKER_INCLUDED_CHANNEL_TYPE.includes(type);
|
|
5785
|
+
function convertFromRaw(channel, options = { isMessagePreviewUpdated: true }) {
|
|
5786
|
+
var _a;
|
|
5787
|
+
let { messagePreviewId } = channel;
|
|
5788
|
+
const messagePreviewChannelCache = (_a = pullFromCache([
|
|
5789
|
+
'messagePreviewChannel',
|
|
5790
|
+
'get',
|
|
5791
|
+
channel.channelId,
|
|
5792
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
5793
|
+
if ((messagePreviewChannelCache === null || messagePreviewChannelCache === void 0 ? void 0 : messagePreviewChannelCache.messagePreviewId) && !options.isMessagePreviewUpdated) {
|
|
5794
|
+
messagePreviewId = messagePreviewChannelCache.messagePreviewId;
|
|
5795
|
+
}
|
|
5796
|
+
return Object.assign(Object.assign({}, channel), { defaultSubChannelId: channel.channelInternalId, isUnreadCountSupport: isUnreadCountSupport(channel), messagePreviewId });
|
|
5797
|
+
}
|
|
5798
|
+
const preUpdateChannelCache = (rawPayload, options = { isMessagePreviewUpdated: true }) => {
|
|
5799
|
+
ingestInCache({
|
|
5800
|
+
channels: rawPayload.channels.map(channel => convertFromRaw(channel, { isMessagePreviewUpdated: options.isMessagePreviewUpdated })),
|
|
5801
|
+
});
|
|
5802
|
+
};
|
|
5803
|
+
const updateChannelUnread = ({ currentUserId, channels, channelUsers, }) => {
|
|
5804
|
+
for (let i = 0; i < channels.length; i += 1) {
|
|
5805
|
+
const cacheKey = ['channelUnread', 'get', channels[i].channelId];
|
|
5806
|
+
const channelUser = channelUsers.find(channelUser => channelUser.channelId === channels[i].channelId && channelUser.userId === currentUserId);
|
|
5807
|
+
let unreadCount = 0;
|
|
5808
|
+
let readToSegment = null;
|
|
5809
|
+
let lastMentionedSegment = null;
|
|
5810
|
+
let isMentioned = false;
|
|
5811
|
+
if (channelUser) {
|
|
5812
|
+
readToSegment = channelUser.readToSegment;
|
|
5813
|
+
lastMentionedSegment = channelUser.lastMentionedSegment;
|
|
5814
|
+
unreadCount = Math.max(channels[i].messageCount - readToSegment, 0);
|
|
5815
|
+
isMentioned = lastMentionedSegment > readToSegment;
|
|
5816
|
+
}
|
|
5817
|
+
const cacheChannelUnread = {
|
|
5818
|
+
channelId: channels[i].channelId,
|
|
5819
|
+
lastSegment: channels[i].messageCount,
|
|
5820
|
+
readToSegment,
|
|
5821
|
+
lastMentionedSegment,
|
|
5822
|
+
unreadCount,
|
|
5823
|
+
isMentioned,
|
|
5824
|
+
isDeleted: channels[i].isDeleted || false,
|
|
5825
|
+
};
|
|
5826
|
+
pushToCache(cacheKey, cacheChannelUnread);
|
|
5827
|
+
}
|
|
5828
|
+
};
|
|
5829
|
+
const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpdated: true }) => {
|
|
5830
|
+
const client = getActiveClient();
|
|
5831
|
+
const networkPreviewSetting = await client.getMessagePreviewSetting(false);
|
|
5832
|
+
if (options.isMessagePreviewUpdated &&
|
|
5833
|
+
networkPreviewSetting !== "no-message-preview" /* Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW */ &&
|
|
5834
|
+
rawPayload.messagePreviews &&
|
|
5835
|
+
rawPayload.messagePreviews.length > 0) {
|
|
5836
|
+
updateChannelMessagePreviewCache(rawPayload);
|
|
5837
|
+
}
|
|
5838
|
+
if (client.useLegacyUnreadCount) {
|
|
5839
|
+
updateChannelUnread({
|
|
5840
|
+
channels: rawPayload.channels,
|
|
5841
|
+
channelUsers: rawPayload.channelUsers,
|
|
5842
|
+
currentUserId: client.userId,
|
|
5843
|
+
});
|
|
5844
|
+
}
|
|
5845
|
+
else {
|
|
5846
|
+
const markerIds = rawPayload.channels
|
|
5847
|
+
// filter channel by type. Only conversation, community and broadcast type are included.
|
|
5848
|
+
.filter(isUnreadCountSupport)
|
|
5849
|
+
.map(({ channelInternalId }) => channelInternalId);
|
|
5850
|
+
if (markerIds.length > 0) {
|
|
5851
|
+
// since the get markers method requires a channel cache to function with the reducer.
|
|
5852
|
+
preUpdateChannelCache(rawPayload, {
|
|
5853
|
+
isMessagePreviewUpdated: options.isMessagePreviewUpdated,
|
|
5854
|
+
});
|
|
5855
|
+
try {
|
|
5856
|
+
await getChannelMarkers(markerIds);
|
|
5857
|
+
}
|
|
5858
|
+
catch (e) {
|
|
5859
|
+
// empty block (from the spec, allow marker fetch to fail without having to do anything)
|
|
5860
|
+
}
|
|
5861
|
+
}
|
|
5862
|
+
}
|
|
5863
|
+
// convert raw channel to internal channel
|
|
5864
|
+
const channels = rawPayload.channels.map(payload => convertFromRaw(payload, { isMessagePreviewUpdated: options.isMessagePreviewUpdated }));
|
|
5865
|
+
// convert raw channel user to membership (add user object)
|
|
5866
|
+
const channelUsers = rawPayload.channelUsers.map(channelUser => {
|
|
5867
|
+
return convertRawMembershipToMembership(channelUser);
|
|
5868
|
+
});
|
|
5869
|
+
const users = rawPayload.users.map(convertRawUserToInternalUser);
|
|
5870
|
+
const restRawPayload = __rest(rawPayload, ["messageFeedsInfo", "messagePreviews"]);
|
|
5871
|
+
return Object.assign(Object.assign({}, restRawPayload), { users,
|
|
5872
|
+
channels,
|
|
5873
|
+
channelUsers });
|
|
5874
|
+
};
|
|
5875
|
+
|
|
5876
|
+
/**
|
|
5877
|
+
* ```js
|
|
5878
|
+
* import { getSubChannelMarkers } from '@amityco/ts-sdk'
|
|
5879
|
+
* const subChannelMarkers = await getSubChannelMarkers(['sch1', 'sch2'])
|
|
5880
|
+
* ```
|
|
5881
|
+
*
|
|
5882
|
+
* Fetches a paginable list of {@link Amity.SubChannelMarker} objects
|
|
5883
|
+
*
|
|
5884
|
+
* @param messageFeedIds the feed IDs of the {@link Amity.RawSubChannel} marker to fetch
|
|
5885
|
+
* @param page
|
|
5886
|
+
* @returns A page of {@link Amity.SubChannelMarker} objects
|
|
5887
|
+
*
|
|
5888
|
+
* @category Channel API
|
|
5889
|
+
* @async
|
|
5890
|
+
* @private
|
|
5891
|
+
*/
|
|
5892
|
+
const getUserMessageFeedMakers = async (channelIds) => {
|
|
5893
|
+
const client = getActiveClient();
|
|
5894
|
+
client.log('channel/getUserMessageFeedMakers', channelIds);
|
|
5895
|
+
const { data } = await client.http.get(`/api/v1/markers/user-message-feed`, {
|
|
5896
|
+
params: {
|
|
5897
|
+
channelIds,
|
|
5898
|
+
},
|
|
5899
|
+
});
|
|
5900
|
+
fireEvent('local.userMessageFeedMarker.fetched', { userMessageFeedMarker: data });
|
|
5901
|
+
return data;
|
|
5902
|
+
};
|
|
5903
|
+
|
|
5904
|
+
const prepareUnreadCountInfo = async (rawPayload) => {
|
|
5905
|
+
const client = getActiveClient();
|
|
5906
|
+
// if consistent mode is enabled, persist the unread count info to the cache
|
|
5907
|
+
// Marker service API uses channelInternalId as channelId
|
|
5908
|
+
const queryPayload = await getUserMessageFeedMakers(rawPayload.channels.map(({ channelInternalId }) => channelInternalId));
|
|
5909
|
+
const { feedMarkers, userFeedMarkers } = queryPayload;
|
|
5910
|
+
persistUnreadCountInfo({
|
|
5911
|
+
feedMarkers,
|
|
5912
|
+
userFeedMarkers,
|
|
5913
|
+
});
|
|
5914
|
+
client.log('channel/prepareUnreadCountInfo', rawPayload.channels);
|
|
5915
|
+
};
|
|
5916
|
+
|
|
5917
|
+
const getCachedMarker$2 = (entityId) => {
|
|
5918
|
+
var _a;
|
|
5919
|
+
const key = {
|
|
5920
|
+
entityId,
|
|
5921
|
+
userId: getActiveUser()._id,
|
|
5922
|
+
};
|
|
5923
|
+
return (_a = pullFromCache([
|
|
5924
|
+
'channelMarker',
|
|
5925
|
+
'get',
|
|
5926
|
+
getResolver('channelMarker')(key),
|
|
5927
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
5928
|
+
};
|
|
5929
|
+
const getUnreadInfoCached$1 = (channelId) => {
|
|
5930
|
+
var _a;
|
|
5931
|
+
return (_a = pullFromCache(['channelUnreadInfo', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
5932
|
+
};
|
|
5933
|
+
/**
|
|
5934
|
+
* The function use to get value of hasMentioned or isMentioned field.
|
|
5935
|
+
* function will get the value from marker params first, if there is no hasMentioned field, will look in to the cache.
|
|
5936
|
+
*
|
|
5937
|
+
* If consistent mode is enabled, the function will return the value from the channelUnreadCountInfo cache.
|
|
5938
|
+
* If not, the function will return the value from the channelMarker cache.
|
|
5939
|
+
* If not found in the both cache, use `false` as defaul value.
|
|
5940
|
+
*/
|
|
5941
|
+
const getChannelIsMentioned = (channel, marker) => {
|
|
5942
|
+
var _a, _b, _c, _d;
|
|
5943
|
+
const client = getActiveClient();
|
|
5944
|
+
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
5945
|
+
return (_b = (_a = getUnreadInfoCached$1(channel.channelPublicId)) === null || _a === void 0 ? void 0 : _a.isMentioned) !== null && _b !== void 0 ? _b : false;
|
|
5946
|
+
}
|
|
5947
|
+
return (marker === null || marker === void 0 ? void 0 : marker.hasMentioned) !== undefined
|
|
5948
|
+
? marker === null || marker === void 0 ? void 0 : marker.hasMentioned
|
|
5949
|
+
: (_d = (_c = getCachedMarker$2(channel.channelPublicId)) === null || _c === void 0 ? void 0 : _c.hasMentioned) !== null && _d !== void 0 ? _d : false;
|
|
5950
|
+
};
|
|
5951
|
+
|
|
5952
|
+
const getCachedMarker$1 = (entityId) => {
|
|
5953
|
+
var _a;
|
|
5954
|
+
const key = {
|
|
5955
|
+
entityId,
|
|
5956
|
+
userId: getActiveUser()._id,
|
|
5957
|
+
};
|
|
5958
|
+
return (_a = pullFromCache([
|
|
5959
|
+
'channelMarker',
|
|
5960
|
+
'get',
|
|
5961
|
+
getResolver('channelMarker')(key),
|
|
5962
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
5963
|
+
};
|
|
5964
|
+
const getUnreadInfoCached = (channelId) => {
|
|
5965
|
+
var _a;
|
|
5966
|
+
return (_a = pullFromCache(['channelUnreadInfo', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
5967
|
+
};
|
|
5968
|
+
/**
|
|
5969
|
+
* The function use to get value of unreadCount field.
|
|
5970
|
+
* function will get the value from marker params first, if there is no hasMentioned field, will look in to the cache.
|
|
5971
|
+
*
|
|
5972
|
+
* If consistent mode is enabled, the function will return the value from the channelUnreadCountInfo cache.
|
|
5973
|
+
* If not, the function will return the value from the channelMarker cache.
|
|
5974
|
+
* If not found in the both cache, use `0` as defaul value.
|
|
5975
|
+
*/
|
|
5976
|
+
const getSubChannelsUnreadCount = (channel, marker) => {
|
|
5977
|
+
var _a, _b, _c, _d, _e;
|
|
5978
|
+
const client = getActiveClient();
|
|
5979
|
+
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
5980
|
+
// Marker service API uses channelInternalId as channelId
|
|
5981
|
+
return (_b = (_a = getUnreadInfoCached(channel.channelInternalId)) === null || _a === void 0 ? void 0 : _a.unreadCount) !== null && _b !== void 0 ? _b : 0;
|
|
5982
|
+
}
|
|
5983
|
+
if (marker === null || marker === void 0 ? void 0 : marker.isDeleted) {
|
|
5984
|
+
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to
|
|
5985
|
+
// leave the channel because currently backend can't handle this, so every time a user is banned
|
|
5986
|
+
// from a channel or the channel is deleted the channel's unread count will reset to zero
|
|
5987
|
+
return 0;
|
|
5988
|
+
}
|
|
5989
|
+
return (_e = (_c = marker === null || marker === void 0 ? void 0 : marker.unreadCount) !== null && _c !== void 0 ? _c : (_d = getCachedMarker$1(channel.channelInternalId)) === null || _d === void 0 ? void 0 : _d.unreadCount) !== null && _e !== void 0 ? _e : 0;
|
|
5990
|
+
};
|
|
5991
|
+
|
|
5992
|
+
const getLegacyChannelUnread = (channelId) => {
|
|
5993
|
+
var _a;
|
|
5994
|
+
return (_a = pullFromCache(['channelUnread', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
5995
|
+
};
|
|
5996
|
+
|
|
5997
|
+
const constructChannelDynamicValue = (channel) => {
|
|
5998
|
+
const client = getActiveClient();
|
|
5999
|
+
const rest = __rest(channel, ["messageCount"]);
|
|
6000
|
+
return shallowClone(rest, {
|
|
6001
|
+
get unreadCount() {
|
|
6002
|
+
var _a, _b;
|
|
6003
|
+
return (_b = (_a = getLegacyChannelUnread(rest.channelId)) === null || _a === void 0 ? void 0 : _a.unreadCount) !== null && _b !== void 0 ? _b : 0;
|
|
6004
|
+
},
|
|
6005
|
+
get subChannelsUnreadCount() {
|
|
6006
|
+
return getSubChannelsUnreadCount(rest);
|
|
6007
|
+
},
|
|
6008
|
+
get isMentioned() {
|
|
6009
|
+
var _a, _b;
|
|
6010
|
+
if (client.useLegacyUnreadCount)
|
|
6011
|
+
return (_b = (_a = getLegacyChannelUnread(rest.channelId)) === null || _a === void 0 ? void 0 : _a.isMentioned) !== null && _b !== void 0 ? _b : false;
|
|
6012
|
+
return getChannelIsMentioned(rest);
|
|
6013
|
+
},
|
|
6014
|
+
});
|
|
6015
|
+
};
|
|
6016
|
+
|
|
6017
|
+
const ANALYTIC_CACHE_KEY = ['analytic', 'normal-priority'];
|
|
6018
|
+
const HIGH_PRIORITY_ANALYTIC_CACHE_KEY = ['analytic', 'high-priority'];
|
|
6019
|
+
|
|
6020
|
+
const syncEvent = async (events) => {
|
|
6021
|
+
const client = getActiveClient();
|
|
6022
|
+
const params = {
|
|
6023
|
+
activities: events,
|
|
6024
|
+
};
|
|
6025
|
+
await client.http.post('/api/v1/analytics/activities', params);
|
|
6026
|
+
};
|
|
6027
|
+
|
|
6028
|
+
class AnalyticsEventSyncer {
|
|
6029
|
+
constructor() {
|
|
6030
|
+
this._timer = undefined;
|
|
6031
|
+
this._high_priority_timer = undefined;
|
|
6032
|
+
}
|
|
6033
|
+
start() {
|
|
6034
|
+
this.syncCapturedEvent();
|
|
6035
|
+
this._timer = setInterval(() => {
|
|
6036
|
+
this.syncCapturedEvent();
|
|
6037
|
+
}, 1 * MINUTE);
|
|
6038
|
+
this._high_priority_timer = setInterval(() => {
|
|
6039
|
+
this.syncHighPriorityCapturedEvent();
|
|
6040
|
+
}, 10 * SECOND$1);
|
|
6041
|
+
}
|
|
6042
|
+
stop() {
|
|
6043
|
+
if (this._timer) {
|
|
6044
|
+
clearInterval(this._timer);
|
|
6045
|
+
this._timer = undefined;
|
|
6046
|
+
}
|
|
6047
|
+
if (this._high_priority_timer) {
|
|
6048
|
+
clearInterval(this._high_priority_timer);
|
|
6049
|
+
this._high_priority_timer = undefined;
|
|
6050
|
+
}
|
|
6051
|
+
}
|
|
6052
|
+
async syncCapturedEvent() {
|
|
6053
|
+
try {
|
|
6054
|
+
// Must query only objects that have same userId with current logged-in user.
|
|
6055
|
+
// Query captured event with maximum of 1000
|
|
6056
|
+
// Order by latest first
|
|
6057
|
+
// e.g., If there are 2000 events we will query 1000-2000 first
|
|
6058
|
+
const cache = pullFromCache(ANALYTIC_CACHE_KEY);
|
|
6059
|
+
if (!(cache === null || cache === void 0 ? void 0 : cache.data))
|
|
6060
|
+
return;
|
|
6061
|
+
if (cache.data.event.length === 0)
|
|
6062
|
+
return;
|
|
6063
|
+
const capturedEvents = cache.data.event;
|
|
6064
|
+
await syncEvent(capturedEvents);
|
|
6065
|
+
dropFromCache(ANALYTIC_CACHE_KEY);
|
|
6066
|
+
}
|
|
6067
|
+
catch (error) {
|
|
6068
|
+
// stop and destroy all events
|
|
6069
|
+
this.stop();
|
|
6070
|
+
dropFromCache(ANALYTIC_CACHE_KEY);
|
|
6071
|
+
}
|
|
6072
|
+
}
|
|
6073
|
+
async syncHighPriorityCapturedEvent() {
|
|
6074
|
+
try {
|
|
6075
|
+
// Must query only objects that have same userId with current logged-in user.
|
|
6076
|
+
// Query captured event with maximum of 1000
|
|
6077
|
+
// Order by latest first
|
|
6078
|
+
// e.g., If there are 2000 events we will query 1000-2000 first
|
|
6079
|
+
const cache = pullFromCache(HIGH_PRIORITY_ANALYTIC_CACHE_KEY);
|
|
6080
|
+
if (!(cache === null || cache === void 0 ? void 0 : cache.data))
|
|
6081
|
+
return;
|
|
6082
|
+
if (cache.data.event.length === 0)
|
|
6083
|
+
return;
|
|
6084
|
+
const capturedEvents = cache.data.event;
|
|
6085
|
+
await syncEvent(capturedEvents);
|
|
6086
|
+
dropFromCache(HIGH_PRIORITY_ANALYTIC_CACHE_KEY);
|
|
6087
|
+
}
|
|
6088
|
+
catch (error) {
|
|
6089
|
+
// stop and destroy all events
|
|
6090
|
+
this.stop();
|
|
6091
|
+
dropFromCache(HIGH_PRIORITY_ANALYTIC_CACHE_KEY);
|
|
6092
|
+
}
|
|
6093
|
+
}
|
|
6094
|
+
}
|
|
6095
|
+
|
|
6096
|
+
class AnalyticsEventCapturer {
|
|
6097
|
+
constructor() {
|
|
6098
|
+
this._expireTime = 5 * MINUTE;
|
|
6099
|
+
this._poolLimit = 1000;
|
|
6100
|
+
this._recentViewed = {};
|
|
6101
|
+
this._recentHighPriorityViewed = {};
|
|
6102
|
+
// Story
|
|
6103
|
+
this._throttleStoryTimer = undefined;
|
|
6104
|
+
this._bufferNewSeenStoryReferenceIds = [];
|
|
6105
|
+
}
|
|
6106
|
+
isAbleToEnqueue({ uniqueId, expireTime, isHighPriority = false, }) {
|
|
6107
|
+
const now = new Date();
|
|
6108
|
+
// Get the recent view date (if any)
|
|
6109
|
+
const recentViewedDate = isHighPriority
|
|
6110
|
+
? this._recentHighPriorityViewed[uniqueId]
|
|
6111
|
+
: this._recentViewed[uniqueId];
|
|
6112
|
+
// If this is the first view, always allow it
|
|
6113
|
+
if (!recentViewedDate) {
|
|
6114
|
+
return true;
|
|
6115
|
+
}
|
|
6116
|
+
const timeDiff = now.getTime() - recentViewedDate.getTime();
|
|
6117
|
+
if (timeDiff < expireTime) {
|
|
6118
|
+
// just recently view this post, ignore the event.
|
|
6119
|
+
return false;
|
|
6120
|
+
}
|
|
6121
|
+
return true;
|
|
6122
|
+
}
|
|
6123
|
+
markAs({ uniqueId, contentId, contentType, activityType, metadata, }) {
|
|
6124
|
+
if (!this.isAbleToEnqueue({ uniqueId, expireTime: this._expireTime }))
|
|
6125
|
+
return;
|
|
6126
|
+
const now = new Date();
|
|
6127
|
+
const currentData = { event: [] };
|
|
6128
|
+
const cache = pullFromCache(ANALYTIC_CACHE_KEY);
|
|
6129
|
+
if (cache === null || cache === void 0 ? void 0 : cache.data) {
|
|
6130
|
+
currentData.event = cache.data.event;
|
|
6131
|
+
}
|
|
6132
|
+
// If the pool is full (Max 1000 items), remove the oldest data
|
|
4996
6133
|
if (currentData.event.length >= this._poolLimit) {
|
|
4997
6134
|
// Remove oldest data
|
|
4998
6135
|
currentData.event.shift();
|
|
@@ -5176,20 +6313,6 @@ var AnalyticsEngine$1 = {
|
|
|
5176
6313
|
},
|
|
5177
6314
|
};
|
|
5178
6315
|
|
|
5179
|
-
const userLinkedObject = (user) => {
|
|
5180
|
-
return Object.assign(Object.assign({}, user), { get avatar() {
|
|
5181
|
-
var _a;
|
|
5182
|
-
if (!user.avatarFileId)
|
|
5183
|
-
return undefined;
|
|
5184
|
-
const avatar = (_a = pullFromCache([
|
|
5185
|
-
'file',
|
|
5186
|
-
'get',
|
|
5187
|
-
`${user.avatarFileId}`,
|
|
5188
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
5189
|
-
return avatar;
|
|
5190
|
-
} });
|
|
5191
|
-
};
|
|
5192
|
-
|
|
5193
6316
|
class StoryComputedValue {
|
|
5194
6317
|
constructor(targetId, lastStoryExpiresAt, lastStorySeenExpiresAt) {
|
|
5195
6318
|
this._syncingStoriesCount = 0;
|
|
@@ -5621,7 +6744,7 @@ const postLinkedObject = (post) => {
|
|
|
5621
6744
|
} });
|
|
5622
6745
|
};
|
|
5623
6746
|
|
|
5624
|
-
const getCachedMarker
|
|
6747
|
+
const getCachedMarker = (message) => {
|
|
5625
6748
|
var _a, _b;
|
|
5626
6749
|
const key = {
|
|
5627
6750
|
creatorId: 'creatorPrivateId' in message ? message.creatorPrivateId : message.creatorId,
|
|
@@ -5639,7 +6762,7 @@ const getMessageReadCount = (message, marker) => {
|
|
|
5639
6762
|
// Look in the marker param first
|
|
5640
6763
|
return (_a = marker !== null && marker !== void 0 ? marker :
|
|
5641
6764
|
// If the marker param is not set, look in the cache
|
|
5642
|
-
getCachedMarker
|
|
6765
|
+
getCachedMarker(message)) !== null && _a !== void 0 ? _a : { readCount: 0, deliveredCount: 0 };
|
|
5643
6766
|
}; // and if not found in cache use default value `0`
|
|
5644
6767
|
|
|
5645
6768
|
/**
|
|
@@ -5882,31 +7005,6 @@ const markAsReadBySegment = async ({ subChannelId, readToSegment, }) => {
|
|
|
5882
7005
|
}
|
|
5883
7006
|
};
|
|
5884
7007
|
|
|
5885
|
-
const reCalculateChannelUnreadInfo = (channelId) => {
|
|
5886
|
-
var _a;
|
|
5887
|
-
const cacheKeyChannelUnread = ['channelUnreadInfo', 'get', channelId];
|
|
5888
|
-
const cacheChannelUnreadInfo = (_a = pullFromCache(cacheKeyChannelUnread)) === null || _a === void 0 ? void 0 : _a.data;
|
|
5889
|
-
const cacheKeySubChannelUnread = ['subChannelUnreadInfo', 'get'];
|
|
5890
|
-
const cachedSubChannelUnreadInfo = queryCache(cacheKeySubChannelUnread);
|
|
5891
|
-
let channelUnreads = 0;
|
|
5892
|
-
let isMentioned = false;
|
|
5893
|
-
if (cachedSubChannelUnreadInfo && (cachedSubChannelUnreadInfo === null || cachedSubChannelUnreadInfo === void 0 ? void 0 : cachedSubChannelUnreadInfo.length) > 0) {
|
|
5894
|
-
const subChannelUnreadsInfo = cachedSubChannelUnreadInfo === null || cachedSubChannelUnreadInfo === void 0 ? void 0 : cachedSubChannelUnreadInfo.filter(({ data }) => {
|
|
5895
|
-
return data.channelId === channelId && !data.isDeleted;
|
|
5896
|
-
});
|
|
5897
|
-
channelUnreads = subChannelUnreadsInfo
|
|
5898
|
-
.map(({ data }) => data.unreadCount)
|
|
5899
|
-
.reduce((acc, cur) => acc + cur, 0);
|
|
5900
|
-
isMentioned = subChannelUnreadsInfo.some(({ data }) => data.isMentioned);
|
|
5901
|
-
}
|
|
5902
|
-
const channelUnreadInfo = Object.assign(Object.assign({}, (cacheChannelUnreadInfo !== null && cacheChannelUnreadInfo !== void 0 ? cacheChannelUnreadInfo : {
|
|
5903
|
-
channelId,
|
|
5904
|
-
createdAt: new Date().toISOString(),
|
|
5905
|
-
})), { updatedAt: new Date().toISOString(), unreadCount: channelUnreads, isMentioned });
|
|
5906
|
-
pushToCache(cacheKeyChannelUnread, channelUnreadInfo);
|
|
5907
|
-
return channelUnreadInfo;
|
|
5908
|
-
};
|
|
5909
|
-
|
|
5910
7008
|
class LegacyMessageReadReceiptSyncEngine {
|
|
5911
7009
|
constructor() {
|
|
5912
7010
|
this.isActive = true;
|
|
@@ -6192,24 +7290,6 @@ const markAsRead = async (channelId) => {
|
|
|
6192
7290
|
return true;
|
|
6193
7291
|
};
|
|
6194
7292
|
|
|
6195
|
-
/**
|
|
6196
|
-
* ```js
|
|
6197
|
-
* import { shallowClone } from '~/utils/shallowClone'
|
|
6198
|
-
* const newObj = shallowClone(obj)
|
|
6199
|
-
* ```
|
|
6200
|
-
*
|
|
6201
|
-
* Clone an object with same prototype and properties
|
|
6202
|
-
*
|
|
6203
|
-
* @param obj the object to clone
|
|
6204
|
-
* @returns new object with same prototype and properties
|
|
6205
|
-
*
|
|
6206
|
-
* @category utility
|
|
6207
|
-
* @private
|
|
6208
|
-
*/
|
|
6209
|
-
function shallowClone(source, target) {
|
|
6210
|
-
return Object.create(Object.getPrototypeOf(source), Object.assign(Object.assign({}, Object.getOwnPropertyDescriptors(source)), Object.getOwnPropertyDescriptors(target)));
|
|
6211
|
-
}
|
|
6212
|
-
|
|
6213
7293
|
const channelLinkedObject = (channel) => {
|
|
6214
7294
|
return shallowClone(channel, {
|
|
6215
7295
|
markAsRead: () => markAsRead(channel.channelInternalId),
|
|
@@ -6285,1063 +7365,1283 @@ const notificationTrayLinkedObject = (noti) => {
|
|
|
6285
7365
|
return Object.assign(Object.assign({}, noti), { isSeen: noti.lastSeenAt > noti.lastOccurredAt, isRecent: new Date(noti.lastOccurredAt).getTime() >= Date.now() - WEEK, users: noti.actors
|
|
6286
7366
|
.map(({ publicId }) => pullFromCache(['user', 'get', publicId]))
|
|
6287
7367
|
.filter(isNonNullable)
|
|
6288
|
-
.map(({ data }) => data)
|
|
6289
|
-
.map(user => userLinkedObject(user)) });
|
|
6290
|
-
};
|
|
6291
|
-
|
|
6292
|
-
const LinkedObject = {
|
|
6293
|
-
ad: adLinkedObject,
|
|
6294
|
-
comment: commentLinkedObject,
|
|
6295
|
-
post: postLinkedObject,
|
|
6296
|
-
user: userLinkedObject,
|
|
6297
|
-
category: categoryLinkedObject,
|
|
6298
|
-
stream: streamLinkedObject,
|
|
6299
|
-
story: storyLinkedObject,
|
|
6300
|
-
storyTarget: storyTargetLinkedObject,
|
|
6301
|
-
message: messageLinkedObject,
|
|
6302
|
-
reactor: reactorLinkedObject,
|
|
6303
|
-
channel: channelLinkedObject,
|
|
6304
|
-
pinnedPost: pinnedPostLinkedObject,
|
|
6305
|
-
notificationTray: notificationTrayLinkedObject,
|
|
6306
|
-
};
|
|
6307
|
-
|
|
6308
|
-
const getChannelMessagePreviewWithUser = (channel) => {
|
|
6309
|
-
var _a;
|
|
6310
|
-
const messagePreview = channel.messagePreviewId
|
|
6311
|
-
? getChannelMessagePreview(channel.channelId)
|
|
6312
|
-
: null;
|
|
6313
|
-
const internalUser = (_a = pullFromCache([
|
|
6314
|
-
'user',
|
|
6315
|
-
'get',
|
|
6316
|
-
messagePreview === null || messagePreview === void 0 ? void 0 : messagePreview.creatorId,
|
|
6317
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
6318
|
-
const messagePreviewWithUser = messagePreview
|
|
6319
|
-
? Object.assign(Object.assign({}, messagePreview), { user: internalUser ? LinkedObject.user(internalUser) : undefined }) : null;
|
|
6320
|
-
return Object.assign(Object.assign({}, channel), { messagePreview: messagePreviewWithUser });
|
|
6321
|
-
};
|
|
6322
|
-
|
|
6323
|
-
const updateChannelMessagePreviewCache = (rawPayload) => {
|
|
6324
|
-
var _a, _b;
|
|
6325
|
-
const withMessageFeedInfo = (messagePreview) => {
|
|
6326
|
-
var _a;
|
|
6327
|
-
const messageFeedInfo = (_a = rawPayload.messageFeedsInfo) === null || _a === void 0 ? void 0 : _a.find(messageFeed => {
|
|
6328
|
-
return messageFeed.messageFeedId === messagePreview.messageFeedId;
|
|
6329
|
-
});
|
|
6330
|
-
const { channelPublicId: channelId, messageFeedId: subChannelId, data, dataType, isDeleted, segment, creatorPublicId: creatorId, createdAt, updatedAt, } = messagePreview;
|
|
6331
|
-
return {
|
|
6332
|
-
channelId,
|
|
6333
|
-
subChannelId,
|
|
6334
|
-
data,
|
|
6335
|
-
dataType,
|
|
6336
|
-
isDeleted,
|
|
6337
|
-
segment,
|
|
6338
|
-
creatorId,
|
|
6339
|
-
createdAt,
|
|
6340
|
-
updatedAt,
|
|
6341
|
-
subChannelName: messageFeedInfo === null || messageFeedInfo === void 0 ? void 0 : messageFeedInfo.name,
|
|
6342
|
-
messagePreviewId: messageFeedInfo === null || messageFeedInfo === void 0 ? void 0 : messageFeedInfo.messagePreviewId,
|
|
6343
|
-
subChannelUpdatedAt: messageFeedInfo === null || messageFeedInfo === void 0 ? void 0 : messageFeedInfo.updatedAt,
|
|
6344
|
-
};
|
|
6345
|
-
};
|
|
6346
|
-
const newData = {
|
|
6347
|
-
messagePreviewChannel: (_b = (_a = rawPayload.messagePreviews) === null || _a === void 0 ? void 0 : _a.map(messagePreview => withMessageFeedInfo(messagePreview))) !== null && _b !== void 0 ? _b : [],
|
|
6348
|
-
};
|
|
6349
|
-
ingestInCache(newData);
|
|
6350
|
-
};
|
|
6351
|
-
|
|
6352
|
-
const getSubChannelMessagePreview = (subChannelId) => {
|
|
6353
|
-
var _a, _b;
|
|
6354
|
-
return ((_b = (_a = pullFromCache(['messagePreviewSubChannel', 'get', subChannelId])) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : null);
|
|
6355
|
-
};
|
|
6356
|
-
|
|
6357
|
-
const getSubChannelMessagePreviewWithUser = (subChannel) => {
|
|
6358
|
-
var _a;
|
|
6359
|
-
const messagePreview = subChannel.messagePreviewId
|
|
6360
|
-
? getSubChannelMessagePreview(subChannel.subChannelId)
|
|
6361
|
-
: null;
|
|
6362
|
-
const messagePreviewWithUser = messagePreview
|
|
6363
|
-
? Object.assign(Object.assign({}, messagePreview), { user: (_a = pullFromCache(['user', 'get', messagePreview === null || messagePreview === void 0 ? void 0 : messagePreview.creatorId])) === null || _a === void 0 ? void 0 : _a.data }) : null;
|
|
6364
|
-
return Object.assign(Object.assign({}, subChannel), { messagePreview: messagePreviewWithUser });
|
|
6365
|
-
};
|
|
6366
|
-
|
|
6367
|
-
const updateSubChannelMessagePreviewCache = (rawPayload) => {
|
|
6368
|
-
var _a, _b;
|
|
6369
|
-
const withMessageFeedInfo = (messagePreview) => {
|
|
6370
|
-
var _a;
|
|
6371
|
-
const messageFeedInfo = (_a = rawPayload.messageFeeds) === null || _a === void 0 ? void 0 : _a.find(messageFeed => {
|
|
6372
|
-
return messageFeed.messageFeedId === messagePreview.messageFeedId;
|
|
6373
|
-
});
|
|
6374
|
-
const { channelPublicId: channelId, messageFeedId: subChannelId, messageId: messagePreviewId, creatorPublicId: creatorId, data, dataType, isDeleted, segment, createdAt, updatedAt, } = messagePreview;
|
|
6375
|
-
return {
|
|
6376
|
-
messagePreviewId,
|
|
6377
|
-
channelId,
|
|
6378
|
-
subChannelId,
|
|
6379
|
-
data,
|
|
6380
|
-
dataType,
|
|
6381
|
-
isDeleted,
|
|
6382
|
-
segment,
|
|
6383
|
-
creatorId,
|
|
6384
|
-
createdAt,
|
|
6385
|
-
updatedAt,
|
|
6386
|
-
subChannelName: messageFeedInfo === null || messageFeedInfo === void 0 ? void 0 : messageFeedInfo.name,
|
|
6387
|
-
subChannelUpdatedAt: messageFeedInfo === null || messageFeedInfo === void 0 ? void 0 : messageFeedInfo.updatedAt,
|
|
6388
|
-
};
|
|
6389
|
-
};
|
|
6390
|
-
const newData = {
|
|
6391
|
-
messagePreviewSubChannel: (_b = (_a = rawPayload.messages) === null || _a === void 0 ? void 0 : _a.map(messagePreview => withMessageFeedInfo(messagePreview))) !== null && _b !== void 0 ? _b : [],
|
|
6392
|
-
};
|
|
6393
|
-
ingestInCache(newData);
|
|
7368
|
+
.map(({ data }) => data)
|
|
7369
|
+
.map(user => userLinkedObject(user)) });
|
|
6394
7370
|
};
|
|
6395
7371
|
|
|
6396
|
-
|
|
6397
|
-
|
|
6398
|
-
|
|
6399
|
-
|
|
6400
|
-
|
|
6401
|
-
|
|
6402
|
-
|
|
6403
|
-
*
|
|
6404
|
-
|
|
6405
|
-
|
|
6406
|
-
|
|
6407
|
-
|
|
6408
|
-
|
|
6409
|
-
|
|
6410
|
-
*
|
|
6411
|
-
*
|
|
6412
|
-
* @param model the model to check
|
|
6413
|
-
* @param modelId the object id to check
|
|
6414
|
-
* @returns the matching cache entry, or undefined.
|
|
7372
|
+
/*
|
|
7373
|
+
* verifies membership status
|
|
7374
|
+
*/
|
|
7375
|
+
function isMember(membership) {
|
|
7376
|
+
return membership !== 'none';
|
|
7377
|
+
}
|
|
7378
|
+
/*
|
|
7379
|
+
* checks if currently logged in user is part of the community
|
|
7380
|
+
*/
|
|
7381
|
+
function isCurrentUserPartOfCommunity(c, m) {
|
|
7382
|
+
const { userId } = getActiveUser();
|
|
7383
|
+
return c.communityId === m.communityId && m.userId === userId;
|
|
7384
|
+
}
|
|
7385
|
+
/*
|
|
7386
|
+
* For mqtt events server will not send user specific data as it's broadcasted
|
|
7387
|
+
* to multiple users and it also does not include communityUser
|
|
6415
7388
|
*
|
|
6416
|
-
*
|
|
7389
|
+
* Client SDK needs to check for the existing isJoined field in cache data before calculating.
|
|
7390
|
+
* Althought this can be calculated, it's not scalable.
|
|
6417
7391
|
*/
|
|
6418
|
-
|
|
6419
|
-
|
|
6420
|
-
|
|
6421
|
-
|
|
6422
|
-
|
|
6423
|
-
|
|
6424
|
-
|
|
6425
|
-
|
|
6426
|
-
|
|
6427
|
-
|
|
6428
|
-
|
|
7392
|
+
function updateMembershipStatus(communities, communityUsers) {
|
|
7393
|
+
return communities.map(c => {
|
|
7394
|
+
const cachedCommunity = pullFromCache([
|
|
7395
|
+
'community',
|
|
7396
|
+
'get',
|
|
7397
|
+
c.communityId,
|
|
7398
|
+
]);
|
|
7399
|
+
if ((cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data) && (cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data.hasOwnProperty('isJoined'))) {
|
|
7400
|
+
return Object.assign(Object.assign({}, cachedCommunity.data), c);
|
|
7401
|
+
}
|
|
7402
|
+
const isJoined = communityUsers.some(m => isCurrentUserPartOfCommunity(c, m) && isMember(m.communityMembership));
|
|
7403
|
+
return Object.assign(Object.assign({}, c), { isJoined });
|
|
7404
|
+
});
|
|
7405
|
+
}
|
|
7406
|
+
|
|
7407
|
+
const getMatchPostSetting = (value) => {
|
|
7408
|
+
var _a;
|
|
7409
|
+
return (_a = Object.keys(CommunityPostSettingMaps).find(key => value.needApprovalOnPostCreation ===
|
|
7410
|
+
CommunityPostSettingMaps[key].needApprovalOnPostCreation &&
|
|
7411
|
+
value.onlyAdminCanPost === CommunityPostSettingMaps[key].onlyAdminCanPost)) !== null && _a !== void 0 ? _a : DefaultCommunityPostSetting;
|
|
7412
|
+
};
|
|
7413
|
+
function addPostSetting({ communities }) {
|
|
7414
|
+
return communities.map((_a) => {
|
|
7415
|
+
var { needApprovalOnPostCreation, onlyAdminCanPost } = _a, restCommunityPayload = __rest(_a, ["needApprovalOnPostCreation", "onlyAdminCanPost"]);
|
|
7416
|
+
return (Object.assign({ postSetting: getMatchPostSetting({
|
|
7417
|
+
needApprovalOnPostCreation,
|
|
7418
|
+
onlyAdminCanPost,
|
|
7419
|
+
}) }, restCommunityPayload));
|
|
7420
|
+
});
|
|
7421
|
+
}
|
|
7422
|
+
const prepareCommunityPayload = (rawPayload) => {
|
|
7423
|
+
const communitiesWithPostSetting = addPostSetting({ communities: rawPayload.communities });
|
|
7424
|
+
// Convert users to internal format
|
|
7425
|
+
const internalUsers = rawPayload.users.map(convertRawUserToInternalUser);
|
|
7426
|
+
// map users with community
|
|
7427
|
+
const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
|
|
7428
|
+
const user = internalUsers.find(user => user.userId === communityUser.userId);
|
|
7429
|
+
return Object.assign(Object.assign({}, communityUser), { user });
|
|
7430
|
+
});
|
|
7431
|
+
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
7432
|
+
return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser), communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
7433
|
+
};
|
|
7434
|
+
const prepareCommunityJoinRequestPayload = (rawPayload) => {
|
|
7435
|
+
const mappedJoinRequests = rawPayload.joinRequests.map(joinRequest => {
|
|
7436
|
+
return Object.assign(Object.assign({}, joinRequest), { joinRequestId: joinRequest._id });
|
|
7437
|
+
});
|
|
7438
|
+
const users = rawPayload.users.map(convertRawUserToInternalUser);
|
|
7439
|
+
return Object.assign(Object.assign({}, rawPayload), { joinRequests: mappedJoinRequests, users });
|
|
7440
|
+
};
|
|
7441
|
+
const prepareCommunityMembershipPayload = (rawPayload) => {
|
|
7442
|
+
const communitiesWithPostSetting = addPostSetting({ communities: rawPayload.communities });
|
|
7443
|
+
// map users with community
|
|
7444
|
+
const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
|
|
7445
|
+
const user = rawPayload.users.find(user => user.userId === communityUser.userId);
|
|
7446
|
+
return Object.assign(Object.assign({}, communityUser), { user });
|
|
7447
|
+
});
|
|
7448
|
+
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
7449
|
+
return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
7450
|
+
};
|
|
7451
|
+
const prepareCommunityRequest = (params) => {
|
|
7452
|
+
const { postSetting = undefined, storySetting } = params, restParam = __rest(params, ["postSetting", "storySetting"]);
|
|
7453
|
+
return Object.assign(Object.assign(Object.assign({}, restParam), (postSetting ? CommunityPostSettingMaps[postSetting] : undefined)), {
|
|
7454
|
+
// Convert story setting to the actual value. (Allow by default)
|
|
7455
|
+
allowCommentInStory: typeof (storySetting === null || storySetting === void 0 ? void 0 : storySetting.enableComment) === 'boolean' ? storySetting.enableComment : true });
|
|
7456
|
+
};
|
|
7457
|
+
const prepareSemanticSearchCommunityPayload = (_a) => {
|
|
7458
|
+
var communityPayload = __rest(_a, ["searchResult"]);
|
|
7459
|
+
const processedCommunityPayload = prepareCommunityPayload(communityPayload);
|
|
7460
|
+
return Object.assign({}, processedCommunityPayload);
|
|
6429
7461
|
};
|
|
6430
7462
|
|
|
7463
|
+
/* begin_public_function
|
|
7464
|
+
id: joinRequest.approve
|
|
7465
|
+
*/
|
|
6431
7466
|
/**
|
|
6432
7467
|
* ```js
|
|
6433
|
-
* import {
|
|
6434
|
-
* const
|
|
7468
|
+
* import { joinRequest } from '@amityco/ts-sdk'
|
|
7469
|
+
* const isAccepted = await joinRequest.approve()
|
|
6435
7470
|
* ```
|
|
6436
7471
|
*
|
|
6437
|
-
*
|
|
7472
|
+
* Accepts a {@link Amity.JoinRequest} object
|
|
6438
7473
|
*
|
|
6439
|
-
* @param
|
|
6440
|
-
* @returns A
|
|
7474
|
+
* @param joinRequest the {@link Amity.JoinRequest} to accept
|
|
7475
|
+
* @returns A success boolean if the {@link Amity.JoinRequest} was accepted
|
|
6441
7476
|
*
|
|
6442
|
-
* @category
|
|
7477
|
+
* @category Join Request API
|
|
6443
7478
|
* @async
|
|
6444
|
-
* @private
|
|
6445
7479
|
*/
|
|
6446
|
-
const
|
|
7480
|
+
const approveJoinRequest = async (joinRequest) => {
|
|
7481
|
+
var _a;
|
|
6447
7482
|
const client = getActiveClient();
|
|
6448
|
-
client.log('
|
|
6449
|
-
const { data
|
|
7483
|
+
client.log('joinRequest/approveJoinRequest', joinRequest.joinRequestId);
|
|
7484
|
+
const { data } = await client.http.post(`/api/v4/communities/${joinRequest.targetId}/join/approve`, {
|
|
6450
7485
|
params: {
|
|
6451
|
-
|
|
7486
|
+
userId: joinRequest.userId,
|
|
6452
7487
|
},
|
|
6453
7488
|
});
|
|
6454
|
-
|
|
6455
|
-
const
|
|
6456
|
-
|
|
6457
|
-
|
|
6458
|
-
|
|
6459
|
-
|
|
6460
|
-
|
|
6461
|
-
|
|
6462
|
-
|
|
6463
|
-
|
|
6464
|
-
const persistUnreadCountInfo = (payload) => {
|
|
6465
|
-
const { feedMarkers, userFeedMarkers } = payload;
|
|
6466
|
-
// calculate sub channel unread info and channel unread info
|
|
6467
|
-
if (feedMarkers.length > 0 && userFeedMarkers.length > 0) {
|
|
6468
|
-
const channelIds = [];
|
|
6469
|
-
const feedMarkerMap = new Map(feedMarkers.map(fm => [fm.feedId, fm]));
|
|
6470
|
-
userFeedMarkers.forEach(userFeedMarker => {
|
|
6471
|
-
const feedMarker = feedMarkerMap.get(userFeedMarker.feedId);
|
|
6472
|
-
if (!feedMarker)
|
|
6473
|
-
return;
|
|
6474
|
-
if (feedMarker.feedId === userFeedMarker.feedId) {
|
|
6475
|
-
const unreadCount = feedMarker.lastSegment - userFeedMarker.readToSegment;
|
|
6476
|
-
const subChannelUnreadInfo = {
|
|
6477
|
-
subChannelId: feedMarker.feedId,
|
|
6478
|
-
channelId: feedMarker.entityId,
|
|
6479
|
-
readToSegment: userFeedMarker.readToSegment,
|
|
6480
|
-
lastSegment: feedMarker.lastSegment,
|
|
6481
|
-
lastMentionSegment: userFeedMarker.lastMentionSegment,
|
|
6482
|
-
unreadCount: Math.max(0, unreadCount),
|
|
6483
|
-
isMentioned: userFeedMarker.isMentioned,
|
|
6484
|
-
isDeleted: feedMarker.isDeleted,
|
|
6485
|
-
createdAt: userFeedMarker.createdAt,
|
|
6486
|
-
updatedAt: userFeedMarker.updatedAt,
|
|
6487
|
-
};
|
|
6488
|
-
// update sub channel unread info in cache
|
|
6489
|
-
ingestInCache({ subChannelUnreadInfo: [subChannelUnreadInfo] });
|
|
6490
|
-
if (!channelIds.includes(feedMarker.entityId)) {
|
|
6491
|
-
channelIds.push(feedMarker.entityId);
|
|
6492
|
-
}
|
|
6493
|
-
}
|
|
6494
|
-
});
|
|
6495
|
-
// re-calculate channel unread info in cache
|
|
6496
|
-
channelIds.forEach(channelId => {
|
|
6497
|
-
reCalculateChannelUnreadInfo(channelId);
|
|
7489
|
+
// TODO : Check cache id
|
|
7490
|
+
const joinRequestCache = (_a = pullFromCache([
|
|
7491
|
+
'joinRequest',
|
|
7492
|
+
'get',
|
|
7493
|
+
joinRequest.joinRequestId,
|
|
7494
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
7495
|
+
if (joinRequestCache) {
|
|
7496
|
+
upsertInCache(['joinRequest', 'get', joinRequest.joinRequestId], {
|
|
7497
|
+
status: "approved" /* JoinRequestStatusEnum.Approved */,
|
|
6498
7498
|
});
|
|
7499
|
+
fireEvent('local.joinRequest.updated', [joinRequestCache]);
|
|
6499
7500
|
}
|
|
6500
|
-
|
|
7501
|
+
return data.success;
|
|
7502
|
+
};
|
|
7503
|
+
/* end_public_function */
|
|
6501
7504
|
|
|
7505
|
+
/* begin_public_function
|
|
7506
|
+
id: joinRequest.cancel
|
|
7507
|
+
*/
|
|
6502
7508
|
/**
|
|
6503
7509
|
* ```js
|
|
6504
|
-
* import {
|
|
6505
|
-
* const
|
|
7510
|
+
* import { joinRequest } from '@amityco/ts-sdk'
|
|
7511
|
+
* const isCanceled = await joinRequest.cancel()
|
|
6506
7512
|
* ```
|
|
6507
7513
|
*
|
|
6508
|
-
*
|
|
7514
|
+
* Cancels a {@link Amity.JoinRequest} object
|
|
6509
7515
|
*
|
|
6510
|
-
* @param
|
|
6511
|
-
* @
|
|
6512
|
-
* @returns A page of {@link Amity.SubChannelMarker} objects
|
|
7516
|
+
* @param joinRequest the {@link Amity.JoinRequest} to cancel
|
|
7517
|
+
* @returns A success boolean if the {@link Amity.JoinRequest} was canceled
|
|
6513
7518
|
*
|
|
6514
|
-
* @category
|
|
7519
|
+
* @category Join Request API
|
|
6515
7520
|
* @async
|
|
6516
|
-
* @private
|
|
6517
7521
|
*/
|
|
6518
|
-
const
|
|
7522
|
+
const cancelJoinRequest = async (joinRequest) => {
|
|
7523
|
+
var _a;
|
|
6519
7524
|
const client = getActiveClient();
|
|
6520
|
-
client.log('
|
|
6521
|
-
const { data
|
|
7525
|
+
client.log('joinRequest/cancelJoinRequest', joinRequest.joinRequestId);
|
|
7526
|
+
const { data } = await client.http.delete(`/api/v4/communities/${joinRequest.targetId}/join`, {
|
|
6522
7527
|
params: {
|
|
6523
|
-
|
|
6524
|
-
options: {
|
|
6525
|
-
token: toToken(page, 'skiplimit'),
|
|
6526
|
-
},
|
|
7528
|
+
userId: joinRequest.userId,
|
|
6527
7529
|
},
|
|
6528
7530
|
});
|
|
6529
|
-
const
|
|
6530
|
-
|
|
6531
|
-
|
|
6532
|
-
|
|
6533
|
-
|
|
6534
|
-
|
|
6535
|
-
|
|
6536
|
-
|
|
6537
|
-
}
|
|
6538
|
-
const userEntityMarkers = convertChannelMarkerResponse(userEntityMarkersPayload);
|
|
6539
|
-
const userFeedMarkers = convertSubChannelMarkerResponse(userFeedMarkersPayload);
|
|
6540
|
-
const cachedAt = client.cache && Date.now();
|
|
6541
|
-
if (client.cache)
|
|
6542
|
-
ingestInCache({ userEntityMarkers, userFeedMarkers, userMarkers }, { cachedAt });
|
|
6543
|
-
fireEvent('local.channelMarker.fetched', { userEntityMarkers });
|
|
6544
|
-
fireEvent('local.subChannelMarker.fetched', { userFeedMarkers });
|
|
6545
|
-
fireEvent('local.userMarker.fetched', { userMarkers });
|
|
6546
|
-
const nextPage = toPage(paging.next);
|
|
6547
|
-
const prevPage = toPage(paging.previous);
|
|
6548
|
-
return { data: userFeedMarkers, cachedAt, prevPage, nextPage };
|
|
6549
|
-
};
|
|
6550
|
-
|
|
6551
|
-
const getUserMarker = async () => {
|
|
6552
|
-
const client = getActiveClient();
|
|
6553
|
-
client.log('channel/getUserMarker');
|
|
6554
|
-
const { data: payload } = await client.http.get(`/api/v1/markers/userMarker`);
|
|
6555
|
-
const { userMarkers } = payload;
|
|
6556
|
-
const cachedAt = client.cache && Date.now();
|
|
6557
|
-
if (client.cache)
|
|
6558
|
-
ingestInCache({ userMarkers }, { cachedAt });
|
|
6559
|
-
fireEvent('local.userMarker.fetched', { userMarkers });
|
|
6560
|
-
const latestUserMarker = userMarkers.reduce((maxUserMarker, userMarker) => {
|
|
6561
|
-
if (maxUserMarker == null ||
|
|
6562
|
-
new Date(maxUserMarker.lastSyncAt).getTime() < new Date(userMarker.lastSyncAt).getTime()) {
|
|
6563
|
-
return userMarker;
|
|
6564
|
-
}
|
|
6565
|
-
return maxUserMarker;
|
|
6566
|
-
}, undefined);
|
|
6567
|
-
return { data: latestUserMarker, cachedAt };
|
|
6568
|
-
};
|
|
6569
|
-
|
|
6570
|
-
/** @hidden */
|
|
6571
|
-
/*
|
|
6572
|
-
* @param message payload from http request without myReactions
|
|
6573
|
-
* add myReactions to http response if the event was a reaction event
|
|
6574
|
-
*/
|
|
6575
|
-
const prepareMessagePayloadForCache = (payload, reactors, event) => {
|
|
6576
|
-
const client = getActiveClient();
|
|
6577
|
-
const cached = pullFromCache(['message', 'get', payload.messageId]);
|
|
6578
|
-
// '[]' in cases where the new reaction is the first one
|
|
6579
|
-
const myReactions = (cached === null || cached === void 0 ? void 0 : cached.data.myReactions) || [];
|
|
6580
|
-
// add myReactions to the payload
|
|
6581
|
-
Object.assign(payload, { myReactions });
|
|
6582
|
-
// check if there are any updates to the reactions
|
|
6583
|
-
const latestReaction = reactors[0];
|
|
6584
|
-
const isLatestReactionMine = latestReaction && latestReaction.userId === client.userId;
|
|
6585
|
-
if (!isLatestReactionMine) {
|
|
6586
|
-
return;
|
|
6587
|
-
}
|
|
6588
|
-
// new reaction added
|
|
6589
|
-
if (event === 'message.reactionAdded' && !myReactions.includes(latestReaction.reactionName)) {
|
|
6590
|
-
Object.assign(payload, {
|
|
6591
|
-
myReactions: [...myReactions, latestReaction.reactionName],
|
|
6592
|
-
});
|
|
7531
|
+
const joinRequestCache = (_a = pullFromCache([
|
|
7532
|
+
'joinRequest',
|
|
7533
|
+
'get',
|
|
7534
|
+
joinRequest.joinRequestId,
|
|
7535
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
7536
|
+
if (joinRequestCache) {
|
|
7537
|
+
dropFromCache(['joinRequest', 'get', joinRequest.joinRequestId]);
|
|
7538
|
+
fireEvent('local.joinRequest.deleted', [joinRequestCache]);
|
|
6593
7539
|
}
|
|
6594
|
-
|
|
6595
|
-
|
|
6596
|
-
|
|
6597
|
-
|
|
7540
|
+
return data.success;
|
|
7541
|
+
};
|
|
7542
|
+
/* end_public_function */
|
|
7543
|
+
|
|
7544
|
+
/* begin_public_function
|
|
7545
|
+
id: joinRequest.reject
|
|
7546
|
+
*/
|
|
7547
|
+
/**
|
|
7548
|
+
* ```js
|
|
7549
|
+
* import { joinRequest } from '@amityco/ts-sdk'
|
|
7550
|
+
* const isRejected = await joinRequest.reject()
|
|
7551
|
+
* ```
|
|
7552
|
+
*
|
|
7553
|
+
* Rejects a {@link Amity.JoinRequest} object
|
|
7554
|
+
*
|
|
7555
|
+
* @param joinRequest the {@link Amity.JoinRequest} to reject
|
|
7556
|
+
* @returns A success boolean if the {@link Amity.JoinRequest} was rejected
|
|
7557
|
+
*
|
|
7558
|
+
* @category Join Request API
|
|
7559
|
+
* @async
|
|
7560
|
+
*/
|
|
7561
|
+
const rejectJoinRequest = async (joinRequest) => {
|
|
7562
|
+
var _a;
|
|
7563
|
+
const client = getActiveClient();
|
|
7564
|
+
client.log('joinRequest/rejectJoinRequest', joinRequest.joinRequestId);
|
|
7565
|
+
const { data } = await client.http.post(`/api/v4/communities/${joinRequest.targetId}/join/reject`);
|
|
7566
|
+
const joinRequestCache = (_a = pullFromCache([
|
|
7567
|
+
'joinRequest',
|
|
7568
|
+
'get',
|
|
7569
|
+
joinRequest.joinRequestId,
|
|
7570
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
7571
|
+
if (joinRequestCache) {
|
|
7572
|
+
upsertInCache(['joinRequest', 'get', joinRequest.joinRequestId], {
|
|
7573
|
+
status: "rejected" /* JoinRequestStatusEnum.Rejected */,
|
|
6598
7574
|
});
|
|
7575
|
+
fireEvent('local.joinRequest.updated', [joinRequestCache]);
|
|
6599
7576
|
}
|
|
7577
|
+
return data.success;
|
|
7578
|
+
};
|
|
7579
|
+
/* end_public_function */
|
|
7580
|
+
|
|
7581
|
+
const joinRequestLinkedObject = (joinRequest) => {
|
|
7582
|
+
return Object.assign(Object.assign({}, joinRequest), { get user() {
|
|
7583
|
+
const cacheData = pullFromCache(['user', 'get', joinRequest.userId]);
|
|
7584
|
+
if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
|
|
7585
|
+
return userLinkedObject(cacheData.data);
|
|
7586
|
+
return undefined;
|
|
7587
|
+
}, cancel: async () => {
|
|
7588
|
+
await cancelJoinRequest(joinRequest);
|
|
7589
|
+
}, approve: async () => {
|
|
7590
|
+
await approveJoinRequest(joinRequest);
|
|
7591
|
+
}, reject: async () => {
|
|
7592
|
+
await rejectJoinRequest(joinRequest);
|
|
7593
|
+
} });
|
|
6600
7594
|
};
|
|
6601
7595
|
|
|
6602
|
-
/*
|
|
6603
|
-
|
|
6604
|
-
|
|
7596
|
+
/* begin_public_function
|
|
7597
|
+
id: community.getMyJoinRequest
|
|
7598
|
+
*/
|
|
7599
|
+
/**
|
|
7600
|
+
* ```js
|
|
7601
|
+
* import { community } from '@amityco/ts-sdk'
|
|
7602
|
+
* const isJoined = await community.getMyJoinRequest('foobar')
|
|
7603
|
+
* ```
|
|
6605
7604
|
*
|
|
6606
|
-
*
|
|
6607
|
-
* 1. `includeDeleted` is purely client side query param and not recognized by
|
|
6608
|
-
* the server
|
|
6609
|
-
* 2. The only values we wish to expose with regards to `isDeleted` (the server
|
|
6610
|
-
* param for queries) is false | undefined and want to disallow users to query
|
|
6611
|
-
* for deleted entities
|
|
7605
|
+
* Joins a {@link Amity.Community} object
|
|
6612
7606
|
*
|
|
6613
|
-
*
|
|
6614
|
-
*
|
|
7607
|
+
* @param communityId the {@link Amity.Community} to join
|
|
7608
|
+
* @returns A success boolean if the {@link Amity.Community} was joined
|
|
7609
|
+
*
|
|
7610
|
+
* @category Community API
|
|
7611
|
+
* @async
|
|
6615
7612
|
*/
|
|
6616
|
-
const
|
|
7613
|
+
const getMyJoinRequest = async (communityId) => {
|
|
7614
|
+
const client = getActiveClient();
|
|
7615
|
+
client.log('community/myJoinRequest', communityId);
|
|
7616
|
+
const { data: payload } = await client.http.get(`/api/v4/communities/${communityId}/join/me`);
|
|
7617
|
+
const data = prepareCommunityJoinRequestPayload(payload);
|
|
7618
|
+
const cachedAt = client.cache && Date.now();
|
|
7619
|
+
if (client.cache)
|
|
7620
|
+
ingestInCache(data, { cachedAt });
|
|
7621
|
+
return {
|
|
7622
|
+
data: data.joinRequests[0] ? joinRequestLinkedObject(data.joinRequests[0]) : undefined,
|
|
7623
|
+
cachedAt,
|
|
7624
|
+
};
|
|
7625
|
+
};
|
|
7626
|
+
/* end_public_function */
|
|
6617
7627
|
|
|
6618
|
-
|
|
6619
|
-
|
|
6620
|
-
|
|
6621
|
-
|
|
6622
|
-
|
|
6623
|
-
|
|
7628
|
+
/* begin_public_function
|
|
7629
|
+
id: community.join
|
|
7630
|
+
*/
|
|
7631
|
+
/**
|
|
7632
|
+
* ```js
|
|
7633
|
+
* import { community } from '@amityco/ts-sdk'
|
|
7634
|
+
* const isJoined = await community.join('foobar')
|
|
7635
|
+
* ```
|
|
7636
|
+
*
|
|
7637
|
+
* Joins a {@link Amity.Community} object
|
|
7638
|
+
*
|
|
7639
|
+
* @param communityId the {@link Amity.Community} to join
|
|
7640
|
+
* @returns A status join result
|
|
7641
|
+
*
|
|
7642
|
+
* @category Community API
|
|
7643
|
+
* @async
|
|
7644
|
+
*/
|
|
7645
|
+
const joinRequest = async (communityId) => {
|
|
6624
7646
|
const client = getActiveClient();
|
|
6625
|
-
|
|
6626
|
-
|
|
6627
|
-
|
|
6628
|
-
|
|
6629
|
-
|
|
6630
|
-
|
|
6631
|
-
|
|
6632
|
-
|
|
6633
|
-
|
|
6634
|
-
}
|
|
6635
|
-
|
|
7647
|
+
client.log('community/joinRequest', communityId);
|
|
7648
|
+
const { data: payload } = await client.http.post(`/api/v4/communities/${communityId}/join`);
|
|
7649
|
+
const data = prepareCommunityJoinRequestPayload(payload);
|
|
7650
|
+
const cachedAt = client.cache && Date.now();
|
|
7651
|
+
if (client.cache)
|
|
7652
|
+
ingestInCache(data, { cachedAt });
|
|
7653
|
+
fireEvent('local.community.join', data.joinRequests);
|
|
7654
|
+
const status = data.joinRequests.length === 0 ? "success" /* JoinResultStatusEnum.Success */ : "pending" /* JoinResultStatusEnum.Pending */;
|
|
7655
|
+
return status === "success" /* JoinResultStatusEnum.Success */
|
|
7656
|
+
? { status }
|
|
7657
|
+
: { status, request: joinRequestLinkedObject(data.joinRequests[0]) };
|
|
7658
|
+
};
|
|
7659
|
+
/* end_public_function */
|
|
7660
|
+
|
|
7661
|
+
class PaginationController {
|
|
7662
|
+
constructor(queryParams) {
|
|
7663
|
+
const { http } = getActiveClient();
|
|
7664
|
+
this.queryParams = queryParams;
|
|
7665
|
+
this.http = http;
|
|
6636
7666
|
}
|
|
6637
|
-
|
|
6638
|
-
|
|
6639
|
-
feedId: subChannelId,
|
|
6640
|
-
userId: getActiveUser()._id,
|
|
6641
|
-
};
|
|
6642
|
-
// If the marker param is not set, look in the cache
|
|
6643
|
-
const cachedMarker = (_b = pullFromCache([
|
|
6644
|
-
'subChannelMarker',
|
|
6645
|
-
'get',
|
|
6646
|
-
getResolver('subChannelMarker')(key),
|
|
6647
|
-
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
6648
|
-
if (cachedMarker) {
|
|
6649
|
-
return cachedMarker.hasMentioned;
|
|
7667
|
+
loadFirstPage() {
|
|
7668
|
+
return this.onFetch("first" /* Amity.LiveCollectionPageDirection.FIRST */);
|
|
6650
7669
|
}
|
|
6651
|
-
|
|
6652
|
-
|
|
6653
|
-
}
|
|
6654
|
-
|
|
6655
|
-
function getSubChannelUnreadCount(channelId, subChannelId, marker) {
|
|
6656
|
-
var _a, _b;
|
|
6657
|
-
// Look for `unreadCount` in the marker param first
|
|
6658
|
-
if (marker) {
|
|
6659
|
-
return marker.unreadCount;
|
|
7670
|
+
loadNextPage() {
|
|
7671
|
+
return this.onFetch("next" /* Amity.LiveCollectionPageDirection.NEXT */);
|
|
6660
7672
|
}
|
|
6661
|
-
|
|
6662
|
-
|
|
6663
|
-
|
|
6664
|
-
|
|
6665
|
-
|
|
6666
|
-
|
|
6667
|
-
|
|
6668
|
-
|
|
6669
|
-
|
|
6670
|
-
|
|
7673
|
+
loadPreviousPage() {
|
|
7674
|
+
return this.onFetch("prev" /* Amity.LiveCollectionPageDirection.PREV */);
|
|
7675
|
+
}
|
|
7676
|
+
async onFetch(direction = "first" /* Amity.LiveCollectionPageDirection.FIRST */) {
|
|
7677
|
+
var _a, _b, _c, _d;
|
|
7678
|
+
if (direction === 'prev' && !this.previousToken)
|
|
7679
|
+
return;
|
|
7680
|
+
if (direction === 'next' && !this.nextToken)
|
|
7681
|
+
return;
|
|
7682
|
+
let token;
|
|
7683
|
+
if (direction === 'prev')
|
|
7684
|
+
token = this.previousToken;
|
|
7685
|
+
if (direction === 'next')
|
|
7686
|
+
token = this.nextToken;
|
|
7687
|
+
const queryResponse = await this.getRequest(this.queryParams, token);
|
|
7688
|
+
if (direction === 'first') {
|
|
7689
|
+
this.nextToken = (_a = queryResponse.paging) === null || _a === void 0 ? void 0 : _a.next;
|
|
7690
|
+
this.previousToken = (_b = queryResponse.paging) === null || _b === void 0 ? void 0 : _b.previous;
|
|
6671
7691
|
}
|
|
6672
|
-
|
|
7692
|
+
if (direction === 'prev')
|
|
7693
|
+
this.previousToken = (_c = queryResponse.paging) === null || _c === void 0 ? void 0 : _c.previous;
|
|
7694
|
+
if (direction === 'next')
|
|
7695
|
+
this.nextToken = (_d = queryResponse.paging) === null || _d === void 0 ? void 0 : _d.next;
|
|
7696
|
+
return queryResponse;
|
|
6673
7697
|
}
|
|
6674
|
-
|
|
6675
|
-
|
|
6676
|
-
|
|
6677
|
-
|
|
6678
|
-
|
|
6679
|
-
// If the marker param is not set, look in the cache
|
|
6680
|
-
const cachedMarker = (_b = pullFromCache([
|
|
6681
|
-
'subChannelMarker',
|
|
6682
|
-
'get',
|
|
6683
|
-
getResolver('subChannelMarker')(key),
|
|
6684
|
-
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
6685
|
-
if (cachedMarker) {
|
|
6686
|
-
return cachedMarker.unreadCount;
|
|
7698
|
+
getNextToken() {
|
|
7699
|
+
return this.nextToken;
|
|
7700
|
+
}
|
|
7701
|
+
getPrevToken() {
|
|
7702
|
+
return this.previousToken;
|
|
6687
7703
|
}
|
|
6688
|
-
// and if not found in cache use default value `0`
|
|
6689
|
-
return 0;
|
|
6690
7704
|
}
|
|
6691
7705
|
|
|
6692
|
-
|
|
6693
|
-
|
|
6694
|
-
|
|
6695
|
-
|
|
6696
|
-
|
|
6697
|
-
|
|
6698
|
-
},
|
|
6699
|
-
|
|
6700
|
-
|
|
6701
|
-
|
|
6702
|
-
|
|
6703
|
-
|
|
6704
|
-
|
|
7706
|
+
/**
|
|
7707
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
7708
|
+
* TODO: check if querybyIds is supported
|
|
7709
|
+
*/
|
|
7710
|
+
class JoinRequestsPaginationController extends PaginationController {
|
|
7711
|
+
async getRequest(queryParams, token) {
|
|
7712
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, communityId } = queryParams, params = __rest(queryParams, ["limit", "communityId"]);
|
|
7713
|
+
const options = token ? { token } : { limit };
|
|
7714
|
+
const { data: queryResponse } = await this.http.get(`/api/v4/communities/${communityId}/join`, {
|
|
7715
|
+
params: Object.assign(Object.assign({}, params), { options }),
|
|
7716
|
+
});
|
|
7717
|
+
return queryResponse;
|
|
7718
|
+
}
|
|
6705
7719
|
}
|
|
6706
7720
|
|
|
6707
|
-
|
|
6708
|
-
|
|
6709
|
-
|
|
6710
|
-
|
|
6711
|
-
return Object.assign(Object.assign(Object.assign({}, localMessage), payload), {
|
|
6712
|
-
// NOTE: referenceId is missing in the some payload event. If we have local message data with referenceId, use it instead.
|
|
6713
|
-
referenceId: (_c = localMessage.referenceId) !== null && _c !== void 0 ? _c : payload.referenceId });
|
|
7721
|
+
class QueryStreamController {
|
|
7722
|
+
constructor(query, cacheKey) {
|
|
7723
|
+
this.query = query;
|
|
7724
|
+
this.cacheKey = cacheKey;
|
|
6714
7725
|
}
|
|
6715
|
-
|
|
6716
|
-
|
|
6717
|
-
|
|
6718
|
-
|
|
6719
|
-
|
|
6720
|
-
|
|
6721
|
-
|
|
6722
|
-
|
|
6723
|
-
|
|
7726
|
+
}
|
|
7727
|
+
|
|
7728
|
+
var EnumJoinRequestAction;
|
|
7729
|
+
(function (EnumJoinRequestAction) {
|
|
7730
|
+
EnumJoinRequestAction["OnLocalJoinRequestCreated"] = "OnLocalJoinRequestCreated";
|
|
7731
|
+
EnumJoinRequestAction["OnLocalJoinRequestUpdated"] = "OnLocalJoinRequestUpdated";
|
|
7732
|
+
EnumJoinRequestAction["OnLocalJoinRequestDeleted"] = "OnLocalJoinRequestDeleted";
|
|
7733
|
+
})(EnumJoinRequestAction || (EnumJoinRequestAction = {}));
|
|
7734
|
+
|
|
7735
|
+
class JoinRequestsQueryStreamController extends QueryStreamController {
|
|
7736
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
7737
|
+
super(query, cacheKey);
|
|
7738
|
+
this.notifyChange = notifyChange;
|
|
7739
|
+
this.preparePayload = preparePayload;
|
|
6724
7740
|
}
|
|
6725
|
-
|
|
6726
|
-
|
|
7741
|
+
async saveToMainDB(response) {
|
|
7742
|
+
const processedPayload = await this.preparePayload(response);
|
|
7743
|
+
const client = getActiveClient();
|
|
7744
|
+
const cachedAt = client.cache && Date.now();
|
|
7745
|
+
if (client.cache) {
|
|
7746
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
7747
|
+
}
|
|
6727
7748
|
}
|
|
6728
|
-
|
|
6729
|
-
|
|
6730
|
-
|
|
6731
|
-
|
|
6732
|
-
|
|
6733
|
-
|
|
6734
|
-
|
|
6735
|
-
|
|
6736
|
-
|
|
6737
|
-
|
|
6738
|
-
|
|
6739
|
-
|
|
6740
|
-
|
|
7749
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
7750
|
+
var _a, _b;
|
|
7751
|
+
if (refresh) {
|
|
7752
|
+
pushToCache(this.cacheKey, {
|
|
7753
|
+
data: response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
|
|
7754
|
+
});
|
|
7755
|
+
}
|
|
7756
|
+
else {
|
|
7757
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
7758
|
+
const joinRequests = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
7759
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
7760
|
+
...new Set([
|
|
7761
|
+
...joinRequests,
|
|
7762
|
+
...response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
|
|
7763
|
+
]),
|
|
7764
|
+
] }));
|
|
7765
|
+
}
|
|
7766
|
+
}
|
|
7767
|
+
reactor(action) {
|
|
7768
|
+
return (joinRequest) => {
|
|
7769
|
+
var _a;
|
|
7770
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
7771
|
+
if (!collection)
|
|
7772
|
+
return;
|
|
7773
|
+
if (action === EnumJoinRequestAction.OnLocalJoinRequestUpdated) {
|
|
7774
|
+
const isExist = collection.data.find(id => id === joinRequest[0].joinRequestId);
|
|
7775
|
+
if (!isExist)
|
|
7776
|
+
return;
|
|
6741
7777
|
}
|
|
6742
|
-
|
|
6743
|
-
|
|
7778
|
+
if (action === EnumJoinRequestAction.OnLocalJoinRequestCreated) {
|
|
7779
|
+
collection.data = [
|
|
7780
|
+
...new Set([
|
|
7781
|
+
...joinRequest.map(joinRequest => joinRequest.joinRequestId),
|
|
7782
|
+
...collection.data,
|
|
7783
|
+
]),
|
|
7784
|
+
];
|
|
7785
|
+
}
|
|
7786
|
+
if (action === EnumJoinRequestAction.OnLocalJoinRequestDeleted) {
|
|
7787
|
+
collection.data = collection.data.filter(id => id !== joinRequest[0].joinRequestId);
|
|
7788
|
+
}
|
|
7789
|
+
pushToCache(this.cacheKey, collection);
|
|
7790
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
7791
|
+
};
|
|
6744
7792
|
}
|
|
6745
|
-
|
|
6746
|
-
|
|
6747
|
-
prepareMessagePayloadForCache(out, reactors, event);
|
|
7793
|
+
subscribeRTE(createSubscriber) {
|
|
7794
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
6748
7795
|
}
|
|
6749
|
-
|
|
7796
|
+
}
|
|
7797
|
+
|
|
7798
|
+
function isObject(value) {
|
|
7799
|
+
return typeof value === 'object' && value !== null;
|
|
6750
7800
|
}
|
|
6751
|
-
|
|
6752
|
-
|
|
6753
|
-
|
|
7801
|
+
/**
|
|
7802
|
+
* convert all object getter property to static value
|
|
7803
|
+
*/
|
|
7804
|
+
const convertGetterPropsToStatic = (obj) => {
|
|
7805
|
+
if (!isObject(obj)) {
|
|
7806
|
+
return obj;
|
|
7807
|
+
}
|
|
7808
|
+
const entries = Object.entries(obj).map(([key, value]) => {
|
|
7809
|
+
const descriptor = Object.getOwnPropertyDescriptor(obj, key);
|
|
7810
|
+
if (typeof (descriptor === null || descriptor === void 0 ? void 0 : descriptor.get) === 'function') {
|
|
7811
|
+
return [key, descriptor.get.call(obj)];
|
|
7812
|
+
}
|
|
7813
|
+
return [key, value];
|
|
6754
7814
|
});
|
|
7815
|
+
return Object.fromEntries(entries);
|
|
6755
7816
|
};
|
|
6756
|
-
const
|
|
6757
|
-
|
|
6758
|
-
|
|
6759
|
-
|
|
6760
|
-
|
|
6761
|
-
|
|
6762
|
-
|
|
6763
|
-
const markerIdsKey = markerIds.join('');
|
|
6764
|
-
if (currentDebounceMap[markerIdsKey]) {
|
|
6765
|
-
clearTimeout(currentDebounceMap[markerIdsKey]);
|
|
7817
|
+
const removeFunctionProperties = (obj) => {
|
|
7818
|
+
if (!isObject(obj)) {
|
|
7819
|
+
return obj;
|
|
7820
|
+
}
|
|
7821
|
+
const entries = Object.entries(obj).map(([key, value]) => {
|
|
7822
|
+
if (typeof value === 'function') {
|
|
7823
|
+
return [key, undefined];
|
|
6766
7824
|
}
|
|
6767
|
-
|
|
6768
|
-
|
|
6769
|
-
|
|
6770
|
-
|
|
6771
|
-
|
|
6772
|
-
|
|
6773
|
-
|
|
6774
|
-
}
|
|
7825
|
+
return [key, value];
|
|
7826
|
+
});
|
|
7827
|
+
return Object.fromEntries(entries);
|
|
7828
|
+
};
|
|
7829
|
+
|
|
7830
|
+
class PaginationNoPageController {
|
|
7831
|
+
constructor(queryParams) {
|
|
7832
|
+
const { http } = getActiveClient();
|
|
7833
|
+
this.queryParams = queryParams;
|
|
7834
|
+
this.http = http;
|
|
6775
7835
|
}
|
|
6776
|
-
|
|
6777
|
-
|
|
6778
|
-
|
|
6779
|
-
messageFeeds === null || messageFeeds === void 0 ? void 0 : messageFeeds.forEach(messageFeed => {
|
|
6780
|
-
var _a, _b;
|
|
6781
|
-
const subChannelCache = (_b = (_a = pullFromCache(['subChannel', 'get', messageFeed.messageFeedId])) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : {};
|
|
6782
|
-
// exclude getter properties from existing subChannel cache, update only other properties to existing subChannel cache
|
|
6783
|
-
const _c = convertFromRaw$2(messageFeed), restSubChannel = __rest(_c, ["unreadCount", "isMentioned"]);
|
|
6784
|
-
updateSubChannelCache(messageFeed.messageFeedId, subChannelCache, restSubChannel);
|
|
6785
|
-
});
|
|
7836
|
+
async onFetch() {
|
|
7837
|
+
const queryResponse = await this.getRequest(this.queryParams);
|
|
7838
|
+
return queryResponse;
|
|
6786
7839
|
}
|
|
6787
|
-
|
|
6788
|
-
|
|
6789
|
-
|
|
6790
|
-
|
|
6791
|
-
|
|
6792
|
-
|
|
7840
|
+
}
|
|
7841
|
+
|
|
7842
|
+
class LiveCollectionController {
|
|
7843
|
+
constructor(paginationController, queryStreamId, cacheKey, callback) {
|
|
7844
|
+
this.paginationController = paginationController;
|
|
7845
|
+
this.queryStreamId = queryStreamId;
|
|
7846
|
+
this.cacheKey = cacheKey;
|
|
7847
|
+
this.callback = callback;
|
|
6793
7848
|
}
|
|
6794
|
-
|
|
6795
|
-
|
|
6796
|
-
|
|
6797
|
-
|
|
6798
|
-
|
|
6799
|
-
|
|
6800
|
-
|
|
6801
|
-
|
|
6802
|
-
|
|
6803
|
-
|
|
6804
|
-
|
|
7849
|
+
async refresh() {
|
|
7850
|
+
try {
|
|
7851
|
+
let result;
|
|
7852
|
+
if (this.paginationController instanceof PaginationNoPageController) {
|
|
7853
|
+
result = await this.paginationController.onFetch();
|
|
7854
|
+
}
|
|
7855
|
+
else {
|
|
7856
|
+
result = await this.paginationController.loadFirstPage();
|
|
7857
|
+
}
|
|
7858
|
+
if (!result)
|
|
7859
|
+
return;
|
|
7860
|
+
await this.persistModel(result);
|
|
7861
|
+
this.persistQueryStream({
|
|
7862
|
+
response: result,
|
|
7863
|
+
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
7864
|
+
refresh: true,
|
|
7865
|
+
});
|
|
7866
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
7867
|
+
}
|
|
7868
|
+
catch (e) {
|
|
7869
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
7870
|
+
}
|
|
6805
7871
|
}
|
|
6806
|
-
|
|
6807
|
-
|
|
7872
|
+
loadPage({ initial = false, direction = "next" /* Amity.LiveCollectionPageDirection.NEXT */, }) {
|
|
7873
|
+
this.setup();
|
|
7874
|
+
this.notifyChange({ origin: "local" /* Amity.LiveDataOrigin.LOCAL */, loading: true });
|
|
7875
|
+
if (initial) {
|
|
7876
|
+
this.refresh();
|
|
7877
|
+
}
|
|
7878
|
+
else if (direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */) {
|
|
7879
|
+
this.loadPrevPage();
|
|
7880
|
+
}
|
|
7881
|
+
else if (direction === "next" /* Amity.LiveCollectionPageDirection.NEXT */) {
|
|
7882
|
+
this.loadNextPage();
|
|
7883
|
+
}
|
|
6808
7884
|
}
|
|
6809
|
-
|
|
6810
|
-
|
|
7885
|
+
async loadNextPage() {
|
|
7886
|
+
try {
|
|
7887
|
+
if (this.paginationController instanceof PaginationNoPageController)
|
|
7888
|
+
return;
|
|
7889
|
+
const result = await this.paginationController.loadNextPage();
|
|
7890
|
+
if (!result)
|
|
7891
|
+
return;
|
|
7892
|
+
await this.persistModel(result);
|
|
7893
|
+
this.persistQueryStream({
|
|
7894
|
+
response: result,
|
|
7895
|
+
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
7896
|
+
});
|
|
7897
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
7898
|
+
}
|
|
7899
|
+
catch (e) {
|
|
7900
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
7901
|
+
}
|
|
6811
7902
|
}
|
|
6812
|
-
|
|
6813
|
-
}
|
|
6814
|
-
|
|
6815
|
-
const MARKER_INCLUDED_SUB_CHANNEL_TYPE = ['broadcast', 'conversation', 'community'];
|
|
6816
|
-
/**
|
|
6817
|
-
* Filter sub channel by type. Only conversation, community and broadcast type are included.
|
|
6818
|
-
*/
|
|
6819
|
-
const isUnreadCountSupport$1 = ({ channelType }) => MARKER_INCLUDED_SUB_CHANNEL_TYPE.includes(channelType);
|
|
6820
|
-
const preUpdateSubChannelCache = (rawPayload) => {
|
|
6821
|
-
ingestInCache({
|
|
6822
|
-
messageFeeds: rawPayload.messageFeeds.map(messageFeed => convertFromRaw$2(messageFeed)),
|
|
6823
|
-
});
|
|
6824
|
-
};
|
|
6825
|
-
const prepareSubChannelPayload = async (rawPayload) => {
|
|
6826
|
-
const markerIds = rawPayload.messageFeeds
|
|
6827
|
-
.filter(isUnreadCountSupport$1)
|
|
6828
|
-
.map(({ messageFeedId }) => messageFeedId);
|
|
6829
|
-
if (markerIds.length > 0) {
|
|
6830
|
-
// since the get markers method requires a channel cache to function with the reducer.
|
|
6831
|
-
preUpdateSubChannelCache(rawPayload);
|
|
7903
|
+
async loadPrevPage() {
|
|
6832
7904
|
try {
|
|
6833
|
-
|
|
7905
|
+
if (this.paginationController instanceof PaginationNoPageController)
|
|
7906
|
+
return;
|
|
7907
|
+
const result = await this.paginationController.loadPreviousPage();
|
|
7908
|
+
if (!result)
|
|
7909
|
+
return;
|
|
7910
|
+
await this.persistModel(result);
|
|
7911
|
+
this.persistQueryStream({
|
|
7912
|
+
response: result,
|
|
7913
|
+
direction: "prev" /* Amity.LiveCollectionPageDirection.PREV */,
|
|
7914
|
+
});
|
|
7915
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
6834
7916
|
}
|
|
6835
7917
|
catch (e) {
|
|
6836
|
-
|
|
7918
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
6837
7919
|
}
|
|
6838
7920
|
}
|
|
6839
|
-
|
|
6840
|
-
|
|
6841
|
-
|
|
6842
|
-
|
|
6843
|
-
|
|
6844
|
-
|
|
6845
|
-
}
|
|
6846
|
-
|
|
6847
|
-
|
|
6848
|
-
const out = Object.assign({}, rest);
|
|
6849
|
-
if (excludeDefaultSubChannel !== undefined) {
|
|
6850
|
-
out.excludeDefaultMessageFeed = excludeDefaultSubChannel;
|
|
7921
|
+
shouldNotify(data) {
|
|
7922
|
+
const newData = data.map(convertGetterPropsToStatic).map(removeFunctionProperties);
|
|
7923
|
+
if (isEqual(this.snapshot, newData))
|
|
7924
|
+
return false;
|
|
7925
|
+
this.snapshot = newData;
|
|
7926
|
+
return true;
|
|
7927
|
+
}
|
|
7928
|
+
getCacheKey() {
|
|
7929
|
+
return this.cacheKey;
|
|
6851
7930
|
}
|
|
6852
|
-
return out;
|
|
6853
7931
|
}
|
|
6854
7932
|
|
|
6855
7933
|
/**
|
|
6856
7934
|
* ```js
|
|
6857
|
-
* import {
|
|
6858
|
-
* const
|
|
7935
|
+
* import { onJoinRequestCreated } from '@amityco/ts-sdk'
|
|
7936
|
+
* const dispose = onJoinRequestCreated(data => {
|
|
7937
|
+
* // ...
|
|
7938
|
+
* })
|
|
7939
|
+
* ```
|
|
7940
|
+
*
|
|
7941
|
+
* Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
|
|
7942
|
+
*
|
|
7943
|
+
* @param callback The function to call when the event was fired
|
|
7944
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
7945
|
+
*
|
|
7946
|
+
* @category JoinRequest Events
|
|
7947
|
+
*/
|
|
7948
|
+
const onJoinRequestCreated = (callback) => {
|
|
7949
|
+
const client = getActiveClient();
|
|
7950
|
+
const disposers = [
|
|
7951
|
+
createEventSubscriber(client, 'onJoinRequestCreated', 'local.joinRequest.created', payload => callback(payload)),
|
|
7952
|
+
];
|
|
7953
|
+
return () => {
|
|
7954
|
+
disposers.forEach(fn => fn());
|
|
7955
|
+
};
|
|
7956
|
+
};
|
|
7957
|
+
|
|
7958
|
+
/**
|
|
7959
|
+
* ```js
|
|
7960
|
+
* import { onJoinRequestUpdated } from '@amityco/ts-sdk'
|
|
7961
|
+
* const dispose = onJoinRequestUpdated(data => {
|
|
7962
|
+
* // ...
|
|
7963
|
+
* })
|
|
6859
7964
|
* ```
|
|
6860
7965
|
*
|
|
6861
|
-
*
|
|
7966
|
+
* Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
|
|
6862
7967
|
*
|
|
6863
|
-
* @param
|
|
6864
|
-
* @returns
|
|
7968
|
+
* @param callback The function to call when the event was fired
|
|
7969
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
6865
7970
|
*
|
|
6866
|
-
* @category
|
|
6867
|
-
* @async
|
|
7971
|
+
* @category JoinRequest Events
|
|
6868
7972
|
*/
|
|
6869
|
-
const
|
|
7973
|
+
const onJoinRequestUpdated = (callback) => {
|
|
6870
7974
|
const client = getActiveClient();
|
|
6871
|
-
|
|
6872
|
-
|
|
6873
|
-
|
|
6874
|
-
|
|
6875
|
-
|
|
6876
|
-
|
|
6877
|
-
|
|
6878
|
-
|
|
6879
|
-
fireEvent('local.message-feed.fetched', data);
|
|
6880
|
-
return {
|
|
6881
|
-
data: data.messageFeeds[0],
|
|
6882
|
-
cachedAt,
|
|
6883
|
-
};
|
|
6884
|
-
}
|
|
6885
|
-
catch (error) {
|
|
6886
|
-
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
6887
|
-
pushToTombstone('subChannel', subChannelId);
|
|
6888
|
-
}
|
|
6889
|
-
throw error;
|
|
6890
|
-
}
|
|
6891
|
-
};
|
|
7975
|
+
const disposers = [
|
|
7976
|
+
createEventSubscriber(client, 'onJoinRequestUpdated', 'local.joinRequest.updated', payload => callback(payload)),
|
|
7977
|
+
];
|
|
7978
|
+
return () => {
|
|
7979
|
+
disposers.forEach(fn => fn());
|
|
7980
|
+
};
|
|
7981
|
+
};
|
|
7982
|
+
|
|
6892
7983
|
/**
|
|
6893
7984
|
* ```js
|
|
6894
|
-
* import {
|
|
6895
|
-
* const
|
|
7985
|
+
* import { onJoinRequestDeleted } from '@amityco/ts-sdk'
|
|
7986
|
+
* const dispose = onJoinRequestDeleted(data => {
|
|
7987
|
+
* // ...
|
|
7988
|
+
* })
|
|
6896
7989
|
* ```
|
|
6897
7990
|
*
|
|
6898
|
-
*
|
|
7991
|
+
* Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
|
|
6899
7992
|
*
|
|
6900
|
-
* @param
|
|
6901
|
-
* @returns
|
|
7993
|
+
* @param callback The function to call when the event was fired
|
|
7994
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
6902
7995
|
*
|
|
6903
|
-
* @category
|
|
7996
|
+
* @category JoinRequest Events
|
|
6904
7997
|
*/
|
|
6905
|
-
|
|
7998
|
+
const onJoinRequestDeleted = (callback) => {
|
|
6906
7999
|
const client = getActiveClient();
|
|
6907
|
-
|
|
6908
|
-
|
|
6909
|
-
|
|
6910
|
-
|
|
6911
|
-
|
|
6912
|
-
return;
|
|
6913
|
-
return {
|
|
6914
|
-
data: cached.data,
|
|
6915
|
-
cachedAt: cached.cachedAt,
|
|
8000
|
+
const disposers = [
|
|
8001
|
+
createEventSubscriber(client, 'onJoinRequestDeleted', 'local.joinRequest.deleted', payload => callback(payload)),
|
|
8002
|
+
];
|
|
8003
|
+
return () => {
|
|
8004
|
+
disposers.forEach(fn => fn());
|
|
6916
8005
|
};
|
|
6917
8006
|
};
|
|
6918
8007
|
|
|
6919
|
-
|
|
6920
|
-
|
|
6921
|
-
|
|
6922
|
-
|
|
6923
|
-
const
|
|
6924
|
-
|
|
6925
|
-
|
|
6926
|
-
|
|
6927
|
-
|
|
6928
|
-
|
|
6929
|
-
let subChannelCache = (_a = pullFromCache(['subChannel', 'get', subChannelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
6930
|
-
if (!subChannelCache) {
|
|
6931
|
-
subChannelCache = (await getSubChannel$1(subChannelId)).data;
|
|
8008
|
+
class JoinRequestsLiveCollectionController extends LiveCollectionController {
|
|
8009
|
+
constructor(query, callback) {
|
|
8010
|
+
const queryStreamId = hash__default["default"](query);
|
|
8011
|
+
const cacheKey = ['joinRequest', 'collection', queryStreamId];
|
|
8012
|
+
const paginationController = new JoinRequestsPaginationController(query);
|
|
8013
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
8014
|
+
this.query = query;
|
|
8015
|
+
this.queryStreamController = new JoinRequestsQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityJoinRequestPayload);
|
|
8016
|
+
this.callback = callback.bind(this);
|
|
8017
|
+
this.loadPage({ initial: true });
|
|
6932
8018
|
}
|
|
6933
|
-
|
|
6934
|
-
|
|
6935
|
-
const
|
|
6936
|
-
|
|
6937
|
-
|
|
6938
|
-
|
|
6939
|
-
|
|
6940
|
-
message.subChannelId,
|
|
6941
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
6942
|
-
// The message payload from optimistic created event has no segment, so we check createdAt instead.
|
|
6943
|
-
return (!cache ||
|
|
6944
|
-
cache.segment <= message.channelSegment ||
|
|
6945
|
-
convertDateStringToTimestamp(cache.createdAt) <= convertDateStringToTimestamp(message.createdAt));
|
|
6946
|
-
};
|
|
6947
|
-
const isLastestMessageOnChannel = (message) => {
|
|
6948
|
-
var _a;
|
|
6949
|
-
const cache = (_a = pullFromCache([
|
|
6950
|
-
'messagePreviewChannel',
|
|
6951
|
-
'get',
|
|
6952
|
-
message.channelId,
|
|
6953
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
6954
|
-
return (!cache ||
|
|
6955
|
-
convertDateStringToTimestamp(cache.createdAt) <= convertDateStringToTimestamp(message.createdAt));
|
|
6956
|
-
};
|
|
6957
|
-
const handleMessageCreatedOnSubChannel = async (message) => {
|
|
6958
|
-
const messagePreviewSetting = await getMessagePreviewSetting$1();
|
|
6959
|
-
const { channelId, messageId: messagePreviewId, creatorId, createdAt, updatedAt, data, dataType, subChannelId, channelSegment: segment, isDeleted, } = message;
|
|
6960
|
-
// 1. get subChannel from cache, if not exist fetch from server
|
|
6961
|
-
const subChannelCache = await getSubChannelCache(subChannelId);
|
|
6962
|
-
// 2. if messagePreviewSetting is NO_MESSAGE_PREVEIW, update only lastActiviy in subChannel cache
|
|
6963
|
-
if (messagePreviewSetting === "no-message-preview" /* Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW */) {
|
|
6964
|
-
// 2.1 if the message is the latest message, update lastActivity to be createdAt in subChannel cache
|
|
6965
|
-
if (convertDateStringToTimestamp(subChannelCache.lastActivity) <
|
|
6966
|
-
convertDateStringToTimestamp(createdAt))
|
|
6967
|
-
updateSubChannelCache(message.subChannelId, subChannelCache, {
|
|
6968
|
-
lastActivity: createdAt,
|
|
8019
|
+
setup() {
|
|
8020
|
+
var _a;
|
|
8021
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
8022
|
+
if (!collection) {
|
|
8023
|
+
pushToCache(this.cacheKey, {
|
|
8024
|
+
data: [],
|
|
8025
|
+
params: this.query,
|
|
6969
8026
|
});
|
|
6970
|
-
|
|
8027
|
+
}
|
|
6971
8028
|
}
|
|
6972
|
-
|
|
6973
|
-
|
|
6974
|
-
if (!isLastestMessageOnSubchannel(message))
|
|
6975
|
-
return;
|
|
6976
|
-
// 3.2 if the message is the latest message, update messagePreviewSubChannel and subChannel cache
|
|
6977
|
-
pushToCache(['messagePreviewSubChannel', 'get', message.subChannelId], {
|
|
6978
|
-
channelId,
|
|
6979
|
-
creatorId,
|
|
6980
|
-
messagePreviewId,
|
|
6981
|
-
createdAt,
|
|
6982
|
-
updatedAt,
|
|
6983
|
-
subChannelId,
|
|
6984
|
-
data,
|
|
6985
|
-
dataType,
|
|
6986
|
-
segment,
|
|
6987
|
-
isDeleted,
|
|
6988
|
-
subChannelUpdatedAt: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.updatedAt,
|
|
6989
|
-
subChannelName: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.displayName,
|
|
6990
|
-
});
|
|
6991
|
-
updateSubChannelCache(message.subChannelId, subChannelCache, {
|
|
6992
|
-
lastActivity: createdAt,
|
|
6993
|
-
messagePreviewId,
|
|
6994
|
-
});
|
|
6995
|
-
};
|
|
6996
|
-
const handleMessageUpdatedOnSubChannel = async (message) => {
|
|
6997
|
-
var _a;
|
|
6998
|
-
const { channelId, messageId: messagePreviewId, creatorId, createdAt, updatedAt, data, dataType, subChannelId, channelSegment: segment, isDeleted, } = message;
|
|
6999
|
-
const messagePreviewSubChannelCache = (_a = pullFromCache([
|
|
7000
|
-
'messagePreviewSubChannel',
|
|
7001
|
-
'get',
|
|
7002
|
-
message.subChannelId,
|
|
7003
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
7004
|
-
// if messagePreviewSubChannel is not exist, ignore the message.
|
|
7005
|
-
if (messagePreviewSubChannelCache &&
|
|
7006
|
-
messagePreviewSubChannelCache.messagePreviewId === message.messageId) {
|
|
7007
|
-
const subChannelCache = await getSubChannelCache(subChannelId);
|
|
7008
|
-
pushToCache(['messagePreviewSubChannel', 'get', message.subChannelId], {
|
|
7009
|
-
channelId,
|
|
7010
|
-
creatorId,
|
|
7011
|
-
messagePreviewId,
|
|
7012
|
-
createdAt,
|
|
7013
|
-
updatedAt,
|
|
7014
|
-
subChannelId,
|
|
7015
|
-
data,
|
|
7016
|
-
dataType,
|
|
7017
|
-
segment,
|
|
7018
|
-
isDeleted,
|
|
7019
|
-
subChannelUpdatedAt: subChannelCache.updatedAt,
|
|
7020
|
-
subChannelName: messagePreviewSubChannelCache.subChannelName,
|
|
7021
|
-
});
|
|
8029
|
+
async persistModel(queryPayload) {
|
|
8030
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
7022
8031
|
}
|
|
7023
|
-
}
|
|
7024
|
-
const
|
|
7025
|
-
|
|
7026
|
-
|
|
7027
|
-
|
|
7028
|
-
|
|
7029
|
-
|
|
7030
|
-
|
|
7031
|
-
|
|
7032
|
-
|
|
7033
|
-
|
|
7034
|
-
|
|
8032
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
8033
|
+
const joinRequestResponse = response;
|
|
8034
|
+
this.queryStreamController.appendToQueryStream(joinRequestResponse, direction, refresh);
|
|
8035
|
+
}
|
|
8036
|
+
startSubscription() {
|
|
8037
|
+
return this.queryStreamController.subscribeRTE([
|
|
8038
|
+
{ fn: onJoinRequestCreated, action: EnumJoinRequestAction.OnLocalJoinRequestCreated },
|
|
8039
|
+
{ fn: onJoinRequestUpdated, action: EnumJoinRequestAction.OnLocalJoinRequestUpdated },
|
|
8040
|
+
{ fn: onJoinRequestDeleted, action: EnumJoinRequestAction.OnLocalJoinRequestDeleted },
|
|
8041
|
+
]);
|
|
8042
|
+
}
|
|
8043
|
+
notifyChange({ origin, loading, error }) {
|
|
8044
|
+
var _a;
|
|
8045
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
8046
|
+
if (!collection)
|
|
8047
|
+
return;
|
|
8048
|
+
const data = this.applyFilter(collection.data
|
|
8049
|
+
.map(id => pullFromCache(['joinRequest', 'get', id]))
|
|
8050
|
+
.filter(isNonNullable)
|
|
8051
|
+
.map(({ data }) => data)
|
|
8052
|
+
.map(joinRequestLinkedObject));
|
|
8053
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
8054
|
+
return;
|
|
8055
|
+
this.callback({
|
|
8056
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
7035
8057
|
data,
|
|
7036
|
-
|
|
7037
|
-
|
|
7038
|
-
|
|
7039
|
-
subChannelUpdatedAt: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.updatedAt,
|
|
7040
|
-
subChannelName: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.displayName,
|
|
8058
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
8059
|
+
loading,
|
|
8060
|
+
error,
|
|
7041
8061
|
});
|
|
7042
8062
|
}
|
|
8063
|
+
applyFilter(data) {
|
|
8064
|
+
let joinRequest = data;
|
|
8065
|
+
if (this.query.status) {
|
|
8066
|
+
joinRequest = joinRequest.filter(joinRequest => joinRequest.status === this.query.status);
|
|
8067
|
+
}
|
|
8068
|
+
const sortFn = (() => {
|
|
8069
|
+
switch (this.query.sortBy) {
|
|
8070
|
+
case 'firstCreated':
|
|
8071
|
+
return sortByFirstCreated;
|
|
8072
|
+
case 'lastCreated':
|
|
8073
|
+
return sortByLastCreated;
|
|
8074
|
+
default:
|
|
8075
|
+
return sortByLastCreated;
|
|
8076
|
+
}
|
|
8077
|
+
})();
|
|
8078
|
+
joinRequest = joinRequest.sort(sortFn);
|
|
8079
|
+
return joinRequest;
|
|
8080
|
+
}
|
|
8081
|
+
}
|
|
8082
|
+
|
|
8083
|
+
/**
|
|
8084
|
+
* Get Join Requests
|
|
8085
|
+
*
|
|
8086
|
+
* @param params the query parameters
|
|
8087
|
+
* @param callback the callback to be called when the join request are updated
|
|
8088
|
+
* @returns joinRequests
|
|
8089
|
+
*
|
|
8090
|
+
* @category joinRequest Live Collection
|
|
8091
|
+
*
|
|
8092
|
+
*/
|
|
8093
|
+
const getJoinRequests = (params, callback, config) => {
|
|
8094
|
+
const { log, cache } = getActiveClient();
|
|
8095
|
+
if (!cache) {
|
|
8096
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
8097
|
+
}
|
|
8098
|
+
const timestamp = Date.now();
|
|
8099
|
+
log(`getJoinRequests: (tmpid: ${timestamp}) > listen`);
|
|
8100
|
+
const joinRequestLiveCollection = new JoinRequestsLiveCollectionController(params, callback);
|
|
8101
|
+
const disposers = joinRequestLiveCollection.startSubscription();
|
|
8102
|
+
const cacheKey = joinRequestLiveCollection.getCacheKey();
|
|
8103
|
+
disposers.push(() => {
|
|
8104
|
+
dropFromCache(cacheKey);
|
|
8105
|
+
});
|
|
8106
|
+
return () => {
|
|
8107
|
+
log(`getJoinRequests (tmpid: ${timestamp}) > dispose`);
|
|
8108
|
+
disposers.forEach(fn => fn());
|
|
8109
|
+
};
|
|
8110
|
+
};
|
|
8111
|
+
|
|
8112
|
+
const convertRawInvitationToInternalInvitation = (rawInvitation) => {
|
|
8113
|
+
return Object.assign(Object.assign({}, rawInvitation), { createdById: rawInvitation.createdBy });
|
|
8114
|
+
};
|
|
8115
|
+
|
|
8116
|
+
const prepareInvitationPayload = (rawPayload) => {
|
|
8117
|
+
return Object.assign(Object.assign({}, rawPayload), { invitations: rawPayload.invitations.map(convertRawInvitationToInternalInvitation), users: rawPayload.users.map(convertRawUserToInternalUser) });
|
|
8118
|
+
};
|
|
8119
|
+
|
|
8120
|
+
/* begin_public_function
|
|
8121
|
+
id: invitation.createInvitations
|
|
8122
|
+
*/
|
|
8123
|
+
/**
|
|
8124
|
+
* ```js
|
|
8125
|
+
* import { createInvitations } from '@amityco/ts-sdk'
|
|
8126
|
+
* const created = await createInvitations({
|
|
8127
|
+
* type: string,
|
|
8128
|
+
* targetType: string,
|
|
8129
|
+
* targetId: string,
|
|
8130
|
+
* userIds: string[]
|
|
8131
|
+
* }))
|
|
8132
|
+
* ```
|
|
8133
|
+
*
|
|
8134
|
+
* Creates an {@link Amity.Invitation}
|
|
8135
|
+
*
|
|
8136
|
+
* @param bundle The data necessary to create a new {@link Amity.Invitation}
|
|
8137
|
+
* @returns The newly created {@link Amity.Invitation}
|
|
8138
|
+
*
|
|
8139
|
+
* @category Invitation API
|
|
8140
|
+
* @async
|
|
8141
|
+
*/
|
|
8142
|
+
const createInvitations = async (bundle) => {
|
|
8143
|
+
const client = getActiveClient();
|
|
8144
|
+
client.log('invitation/createInvitations', bundle);
|
|
8145
|
+
const { data: payload } = await client.http.post('/api/v1/invitations', bundle);
|
|
8146
|
+
const data = prepareInvitationPayload(payload);
|
|
8147
|
+
const cachedAt = client.cache && Date.now();
|
|
8148
|
+
if (client.cache)
|
|
8149
|
+
ingestInCache(data, { cachedAt });
|
|
8150
|
+
fireEvent('local.invitation.created', data.invitations);
|
|
8151
|
+
return {
|
|
8152
|
+
data: data.invitations,
|
|
8153
|
+
cachedAt,
|
|
8154
|
+
};
|
|
7043
8155
|
};
|
|
7044
|
-
|
|
7045
|
-
|
|
7046
|
-
|
|
7047
|
-
|
|
8156
|
+
/* end_public_function */
|
|
8157
|
+
|
|
8158
|
+
/* begin_public_function
|
|
8159
|
+
id: invitation.accept
|
|
8160
|
+
*/
|
|
8161
|
+
/**
|
|
8162
|
+
* ```js
|
|
8163
|
+
* import { acceptInvitation } from '@amityco/ts-sdk'
|
|
8164
|
+
* const isAccepted = await acceptInvitation(invitationId)
|
|
8165
|
+
* ```
|
|
8166
|
+
*
|
|
8167
|
+
* Accepts a {@link Amity.Invitation} object
|
|
8168
|
+
*
|
|
8169
|
+
* @param invitationId the {@link Amity.Invitation} to accept
|
|
8170
|
+
* @returns A success boolean if the {@link Amity.Invitation} was accepted
|
|
8171
|
+
*
|
|
8172
|
+
* @category Invitation API
|
|
8173
|
+
* @async
|
|
8174
|
+
*/
|
|
8175
|
+
const acceptInvitation = async (invitationId) => {
|
|
7048
8176
|
var _a;
|
|
7049
|
-
const
|
|
7050
|
-
|
|
7051
|
-
|
|
8177
|
+
const client = getActiveClient();
|
|
8178
|
+
client.log('invitation/acceptInvitation', invitationId);
|
|
8179
|
+
const { data } = await client.http.post(`/api/v1/invitations/${invitationId}/accept`);
|
|
8180
|
+
const invitation = (_a = pullFromCache([
|
|
8181
|
+
'invitation',
|
|
7052
8182
|
'get',
|
|
7053
|
-
|
|
8183
|
+
invitationId,
|
|
7054
8184
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
7055
|
-
if (
|
|
7056
|
-
|
|
7057
|
-
|
|
7058
|
-
pushToCache(['messagePreviewChannel', 'get', message.channelId], {
|
|
7059
|
-
channelId,
|
|
7060
|
-
creatorId,
|
|
7061
|
-
messagePreviewId,
|
|
7062
|
-
createdAt,
|
|
7063
|
-
updatedAt,
|
|
7064
|
-
subChannelId,
|
|
7065
|
-
data,
|
|
7066
|
-
dataType,
|
|
7067
|
-
segment,
|
|
7068
|
-
isDeleted,
|
|
7069
|
-
subChannelUpdatedAt: subChannelCache.updatedAt,
|
|
7070
|
-
subChannelName: messagePreviewChannelCache.subChannelName,
|
|
7071
|
-
});
|
|
8185
|
+
if (invitation) {
|
|
8186
|
+
upsertInCache(['invitation', 'get', invitationId], { status: "approved" /* InvitationStatusEnum.Approved */ });
|
|
8187
|
+
fireEvent('local.invitation.updated', [invitation]);
|
|
7072
8188
|
}
|
|
8189
|
+
return data.success;
|
|
7073
8190
|
};
|
|
7074
|
-
|
|
7075
|
-
|
|
7076
|
-
|
|
7077
|
-
|
|
7078
|
-
|
|
7079
|
-
|
|
8191
|
+
/* end_public_function */
|
|
8192
|
+
|
|
8193
|
+
/* begin_public_function
|
|
8194
|
+
id: invitation.reject
|
|
8195
|
+
*/
|
|
8196
|
+
/**
|
|
8197
|
+
* ```js
|
|
8198
|
+
* import { rejectInvitation } from '@amityco/ts-sdk'
|
|
8199
|
+
* const isRejected = await rejectInvitation(invitationId)
|
|
8200
|
+
* ```
|
|
8201
|
+
*
|
|
8202
|
+
* Rejects a {@link Amity.Invitation} object
|
|
8203
|
+
*
|
|
8204
|
+
* @param invitationId the {@link Amity.Invitation} to reject
|
|
8205
|
+
* @returns A success boolean if the {@link Amity.Invitation} was rejected
|
|
8206
|
+
*
|
|
8207
|
+
* @category Invitation API
|
|
8208
|
+
* @async
|
|
8209
|
+
*/
|
|
8210
|
+
const rejectInvitation = async (invitationId) => {
|
|
8211
|
+
var _a;
|
|
8212
|
+
const client = getActiveClient();
|
|
8213
|
+
client.log('invitation/rejectInvitation', invitationId);
|
|
8214
|
+
const { data } = await client.http.post(`/api/v1/invitations/${invitationId}/reject`);
|
|
8215
|
+
const invitation = (_a = pullFromCache([
|
|
8216
|
+
'invitation',
|
|
7080
8217
|
'get',
|
|
7081
|
-
|
|
8218
|
+
invitationId,
|
|
7082
8219
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
7083
|
-
if (
|
|
7084
|
-
|
|
7085
|
-
|
|
7086
|
-
'get',
|
|
7087
|
-
subChannelId,
|
|
7088
|
-
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
7089
|
-
pushToCache(['messagePreviewChannel', 'get', channelId], Object.assign(Object.assign({}, messagePreviewChannelCache), { subChannelName: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.displayName, subChannelUpdatedAt: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.updatedAt }));
|
|
7090
|
-
}
|
|
7091
|
-
/** SubChannel Case */
|
|
7092
|
-
const messagePreviewSubChannelCache = (_c = pullFromCache([
|
|
7093
|
-
'messagePreviewSubChannel',
|
|
7094
|
-
'get',
|
|
7095
|
-
subChannelId,
|
|
7096
|
-
])) === null || _c === void 0 ? void 0 : _c.data;
|
|
7097
|
-
if (messagePreviewSubChannelCache &&
|
|
7098
|
-
new Date(messagePreviewSubChannelCache.updatedAt).valueOf() >
|
|
7099
|
-
new Date(subChannel.updatedAt).valueOf()) {
|
|
7100
|
-
const subChannelCache = (_d = pullFromCache([
|
|
7101
|
-
'subChannel',
|
|
7102
|
-
'get',
|
|
7103
|
-
subChannelId,
|
|
7104
|
-
])) === null || _d === void 0 ? void 0 : _d.data;
|
|
7105
|
-
pushToCache(['messagePreviewSubChannel', 'get', subChannelId], Object.assign(Object.assign({}, messagePreviewSubChannelCache), { subChannelName: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.displayName, subChannelUpdatedAt: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.updatedAt }));
|
|
8220
|
+
if (invitation) {
|
|
8221
|
+
upsertInCache(['invitation', 'get', invitationId], { status: "rejected" /* InvitationStatusEnum.Rejected */ });
|
|
8222
|
+
fireEvent('local.invitation.updated', [invitation]);
|
|
7106
8223
|
}
|
|
7107
|
-
|
|
7108
|
-
|
|
7109
|
-
|
|
7110
|
-
return Object.assign(Object.assign({}, rawUser), { isGlobalBanned: (rawUser === null || rawUser === void 0 ? void 0 : rawUser.isGlobalBan) || false });
|
|
7111
|
-
}
|
|
8224
|
+
return data.success;
|
|
8225
|
+
};
|
|
8226
|
+
/* end_public_function */
|
|
7112
8227
|
|
|
7113
|
-
|
|
7114
|
-
|
|
7115
|
-
|
|
8228
|
+
/* begin_public_function
|
|
8229
|
+
id: invitation.cancel
|
|
8230
|
+
*/
|
|
8231
|
+
/**
|
|
8232
|
+
* ```js
|
|
8233
|
+
* import { cancelInvitation } from '@amityco/ts-sdk'
|
|
8234
|
+
* const isCanceled = await cancelInvitation(invitationId)
|
|
8235
|
+
* ```
|
|
8236
|
+
*
|
|
8237
|
+
* Cancels a {@link Amity.Invitation} object
|
|
8238
|
+
*
|
|
8239
|
+
* @param invitationId the {@link Amity.Invitation} to cancel
|
|
8240
|
+
* @returns A success boolean if the {@link Amity.Invitation} was canceled
|
|
8241
|
+
*
|
|
8242
|
+
* @category Invitation API
|
|
8243
|
+
* @async
|
|
8244
|
+
*/
|
|
8245
|
+
const cancelInvitation = async (invitationId) => {
|
|
7116
8246
|
var _a;
|
|
7117
|
-
|
|
7118
|
-
|
|
7119
|
-
|
|
8247
|
+
const client = getActiveClient();
|
|
8248
|
+
client.log('invitation/cancelInvitation', invitationId);
|
|
8249
|
+
const { data } = await client.http.delete(`/api/v1/invitations/${invitationId}`);
|
|
8250
|
+
const invitation = (_a = pullFromCache([
|
|
8251
|
+
'invitation',
|
|
7120
8252
|
'get',
|
|
7121
|
-
|
|
8253
|
+
invitationId,
|
|
7122
8254
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
7123
|
-
if (
|
|
7124
|
-
|
|
7125
|
-
|
|
7126
|
-
return Object.assign(Object.assign({}, channel), { defaultSubChannelId: channel.channelInternalId, isUnreadCountSupport: isUnreadCountSupport(channel), messagePreviewId });
|
|
7127
|
-
}
|
|
7128
|
-
const preUpdateChannelCache = (rawPayload, options = { isMessagePreviewUpdated: true }) => {
|
|
7129
|
-
ingestInCache({
|
|
7130
|
-
channels: rawPayload.channels.map(channel => convertFromRaw(channel, { isMessagePreviewUpdated: options.isMessagePreviewUpdated })),
|
|
7131
|
-
});
|
|
7132
|
-
};
|
|
7133
|
-
const updateChannelUnread = ({ currentUserId, channels, channelUsers, }) => {
|
|
7134
|
-
for (let i = 0; i < channels.length; i += 1) {
|
|
7135
|
-
const cacheKey = ['channelUnread', 'get', channels[i].channelId];
|
|
7136
|
-
const channelUser = channelUsers.find(channelUser => channelUser.channelId === channels[i].channelId && channelUser.userId === currentUserId);
|
|
7137
|
-
let unreadCount = 0;
|
|
7138
|
-
let readToSegment = null;
|
|
7139
|
-
let lastMentionedSegment = null;
|
|
7140
|
-
let isMentioned = false;
|
|
7141
|
-
if (channelUser) {
|
|
7142
|
-
readToSegment = channelUser.readToSegment;
|
|
7143
|
-
lastMentionedSegment = channelUser.lastMentionedSegment;
|
|
7144
|
-
unreadCount = Math.max(channels[i].messageCount - readToSegment, 0);
|
|
7145
|
-
isMentioned = lastMentionedSegment > readToSegment;
|
|
7146
|
-
}
|
|
7147
|
-
const cacheChannelUnread = {
|
|
7148
|
-
channelId: channels[i].channelId,
|
|
7149
|
-
lastSegment: channels[i].messageCount,
|
|
7150
|
-
readToSegment,
|
|
7151
|
-
lastMentionedSegment,
|
|
7152
|
-
unreadCount,
|
|
7153
|
-
isMentioned,
|
|
7154
|
-
isDeleted: channels[i].isDeleted || false,
|
|
7155
|
-
};
|
|
7156
|
-
pushToCache(cacheKey, cacheChannelUnread);
|
|
8255
|
+
if (invitation) {
|
|
8256
|
+
dropFromCache(['invitation', 'get', invitationId]);
|
|
8257
|
+
fireEvent('local.invitation.deleted', [invitation]);
|
|
7157
8258
|
}
|
|
8259
|
+
return data.success;
|
|
7158
8260
|
};
|
|
7159
|
-
|
|
8261
|
+
/* end_public_function */
|
|
8262
|
+
|
|
8263
|
+
const prepareMyInvitationsPayload = (rawPayload) => {
|
|
8264
|
+
return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser), invitations: rawPayload.invitations.map(convertRawInvitationToInternalInvitation) });
|
|
8265
|
+
};
|
|
8266
|
+
|
|
8267
|
+
const invitationLinkedObject = (invitation) => {
|
|
8268
|
+
return Object.assign(Object.assign({}, invitation), { get user() {
|
|
8269
|
+
const cacheData = pullFromCache(['user', 'get', invitation.invitedUserPublicId]);
|
|
8270
|
+
if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
|
|
8271
|
+
return userLinkedObject(cacheData.data);
|
|
8272
|
+
return undefined;
|
|
8273
|
+
},
|
|
8274
|
+
get createdBy() {
|
|
8275
|
+
const cacheData = pullFromCache(['user', 'get', invitation.inviterUserPublicId]);
|
|
8276
|
+
if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
|
|
8277
|
+
return userLinkedObject(cacheData.data);
|
|
8278
|
+
return undefined;
|
|
8279
|
+
},
|
|
8280
|
+
get target() {
|
|
8281
|
+
if (invitation.targetType === 'community') {
|
|
8282
|
+
const cacheData = pullFromCache([
|
|
8283
|
+
'community',
|
|
8284
|
+
'get',
|
|
8285
|
+
invitation.targetId,
|
|
8286
|
+
]);
|
|
8287
|
+
if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
|
|
8288
|
+
return cacheData.data;
|
|
8289
|
+
return undefined;
|
|
8290
|
+
}
|
|
8291
|
+
return undefined;
|
|
8292
|
+
}, accept: async () => {
|
|
8293
|
+
await acceptInvitation(invitation._id);
|
|
8294
|
+
}, reject: async () => {
|
|
8295
|
+
await rejectInvitation(invitation._id);
|
|
8296
|
+
}, cancel: async () => {
|
|
8297
|
+
await cancelInvitation(invitation._id);
|
|
8298
|
+
} });
|
|
8299
|
+
};
|
|
8300
|
+
|
|
8301
|
+
/* begin_public_function
|
|
8302
|
+
id: invitation.get
|
|
8303
|
+
*/
|
|
8304
|
+
/**
|
|
8305
|
+
* ```js
|
|
8306
|
+
* import { getInvitation } from '@amityco/ts-sdk'
|
|
8307
|
+
* const { invitation } = await getInvitation(targetType, targetId)
|
|
8308
|
+
* ```
|
|
8309
|
+
*
|
|
8310
|
+
* Get a {@link Amity.Invitation} object
|
|
8311
|
+
*
|
|
8312
|
+
* @param targetType The type of the target of the {@link Amity.Invitation}
|
|
8313
|
+
* @param targetId The ID of the target of the {@link Amity.Invitation}
|
|
8314
|
+
* @returns A {@link Amity.Invitation} object
|
|
8315
|
+
*
|
|
8316
|
+
* @category Invitation API
|
|
8317
|
+
* @async
|
|
8318
|
+
*/
|
|
8319
|
+
const getInvitation = async (targetType, targetId) => {
|
|
7160
8320
|
const client = getActiveClient();
|
|
7161
|
-
|
|
7162
|
-
|
|
7163
|
-
|
|
7164
|
-
|
|
7165
|
-
|
|
7166
|
-
|
|
8321
|
+
client.log('invitation/getInvitation', targetType, targetId);
|
|
8322
|
+
const { data: payload } = await client.http.get(`/api/v1/invitations/me`, { params: { targetType, targetId } });
|
|
8323
|
+
const data = prepareMyInvitationsPayload(payload);
|
|
8324
|
+
const cachedAt = client.cache && Date.now();
|
|
8325
|
+
if (client.cache)
|
|
8326
|
+
ingestInCache(data, { cachedAt });
|
|
8327
|
+
return {
|
|
8328
|
+
data: data.invitations[0] ? invitationLinkedObject(data.invitations[0]) : undefined,
|
|
8329
|
+
cachedAt,
|
|
8330
|
+
};
|
|
8331
|
+
};
|
|
8332
|
+
/* end_public_function */
|
|
8333
|
+
|
|
8334
|
+
var InvitationActionsEnum;
|
|
8335
|
+
(function (InvitationActionsEnum) {
|
|
8336
|
+
InvitationActionsEnum["OnLocalInvitationCreated"] = "onLocalInvitationCreated";
|
|
8337
|
+
InvitationActionsEnum["OnLocalInvitationUpdated"] = "onLocalInvitationUpdated";
|
|
8338
|
+
InvitationActionsEnum["OnLocalInvitationDeleted"] = "onLocalInvitationDeleted";
|
|
8339
|
+
})(InvitationActionsEnum || (InvitationActionsEnum = {}));
|
|
8340
|
+
|
|
8341
|
+
class InvitationsPaginationController extends PaginationController {
|
|
8342
|
+
async getRequest(queryParams, token) {
|
|
8343
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
8344
|
+
const options = token ? { token } : { limit };
|
|
8345
|
+
const { data } = await this.http.get('/api/v1/invitations', { params: Object.assign(Object.assign({}, params), { options }) });
|
|
8346
|
+
return data;
|
|
7167
8347
|
}
|
|
7168
|
-
|
|
7169
|
-
|
|
7170
|
-
|
|
7171
|
-
|
|
7172
|
-
|
|
7173
|
-
|
|
8348
|
+
}
|
|
8349
|
+
|
|
8350
|
+
class InvitationsQueryStreamController extends QueryStreamController {
|
|
8351
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
8352
|
+
super(query, cacheKey);
|
|
8353
|
+
this.notifyChange = notifyChange;
|
|
8354
|
+
this.preparePayload = preparePayload;
|
|
7174
8355
|
}
|
|
7175
|
-
|
|
7176
|
-
const
|
|
7177
|
-
|
|
7178
|
-
|
|
7179
|
-
|
|
7180
|
-
|
|
7181
|
-
|
|
7182
|
-
|
|
7183
|
-
|
|
8356
|
+
async saveToMainDB(response) {
|
|
8357
|
+
const processedPayload = await this.preparePayload(response);
|
|
8358
|
+
const client = getActiveClient();
|
|
8359
|
+
const cachedAt = client.cache && Date.now();
|
|
8360
|
+
if (client.cache) {
|
|
8361
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
8362
|
+
}
|
|
8363
|
+
}
|
|
8364
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
8365
|
+
var _a, _b;
|
|
8366
|
+
if (refresh) {
|
|
8367
|
+
pushToCache(this.cacheKey, {
|
|
8368
|
+
data: response.invitations.map(getResolver('invitation')),
|
|
7184
8369
|
});
|
|
7185
|
-
|
|
7186
|
-
|
|
8370
|
+
}
|
|
8371
|
+
else {
|
|
8372
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
8373
|
+
const invitations = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
8374
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
8375
|
+
...new Set([...invitations, ...response.invitations.map(getResolver('invitation'))]),
|
|
8376
|
+
] }));
|
|
8377
|
+
}
|
|
8378
|
+
}
|
|
8379
|
+
reactor(action) {
|
|
8380
|
+
return (invitations) => {
|
|
8381
|
+
var _a;
|
|
8382
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
8383
|
+
if (!collection)
|
|
8384
|
+
return;
|
|
8385
|
+
if (action === InvitationActionsEnum.OnLocalInvitationUpdated) {
|
|
8386
|
+
const isExist = collection.data.find(id => id === invitations[0].invitationId);
|
|
8387
|
+
if (!isExist)
|
|
8388
|
+
return;
|
|
7187
8389
|
}
|
|
7188
|
-
|
|
7189
|
-
|
|
8390
|
+
if (action === InvitationActionsEnum.OnLocalInvitationCreated) {
|
|
8391
|
+
collection.data = [
|
|
8392
|
+
...new Set([
|
|
8393
|
+
...invitations.map(invitation => invitation.invitationId),
|
|
8394
|
+
...collection.data,
|
|
8395
|
+
]),
|
|
8396
|
+
];
|
|
7190
8397
|
}
|
|
7191
|
-
|
|
8398
|
+
if (action === InvitationActionsEnum.OnLocalInvitationDeleted) {
|
|
8399
|
+
collection.data = collection.data.filter(id => id !== invitations[0].invitationId);
|
|
8400
|
+
}
|
|
8401
|
+
pushToCache(this.cacheKey, collection);
|
|
8402
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
8403
|
+
};
|
|
7192
8404
|
}
|
|
7193
|
-
|
|
7194
|
-
|
|
7195
|
-
|
|
7196
|
-
|
|
7197
|
-
return convertRawMembershipToMembership(channelUser);
|
|
7198
|
-
});
|
|
7199
|
-
const users = rawPayload.users.map(convertRawUserToInternalUser);
|
|
7200
|
-
const restRawPayload = __rest(rawPayload, ["messageFeedsInfo", "messagePreviews"]);
|
|
7201
|
-
return Object.assign(Object.assign({}, restRawPayload), { users,
|
|
7202
|
-
channels,
|
|
7203
|
-
channelUsers });
|
|
7204
|
-
};
|
|
8405
|
+
subscribeRTE(createSubscriber) {
|
|
8406
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
8407
|
+
}
|
|
8408
|
+
}
|
|
7205
8409
|
|
|
7206
8410
|
/**
|
|
7207
8411
|
* ```js
|
|
7208
|
-
* import {
|
|
7209
|
-
* const
|
|
8412
|
+
* import { onLocalInvitationCreated } from '@amityco/ts-sdk'
|
|
8413
|
+
* const dispose = onLocalInvitationCreated(data => {
|
|
8414
|
+
* // ...
|
|
8415
|
+
* })
|
|
7210
8416
|
* ```
|
|
7211
8417
|
*
|
|
7212
|
-
*
|
|
8418
|
+
* Fired when an {@link Amity.InvitationPayload} has been created
|
|
7213
8419
|
*
|
|
7214
|
-
* @param
|
|
7215
|
-
* @
|
|
7216
|
-
* @returns A page of {@link Amity.SubChannelMarker} objects
|
|
8420
|
+
* @param callback The function to call when the event was fired
|
|
8421
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
7217
8422
|
*
|
|
7218
|
-
* @category
|
|
7219
|
-
* @async
|
|
7220
|
-
* @private
|
|
8423
|
+
* @category Invitation Events
|
|
7221
8424
|
*/
|
|
7222
|
-
const
|
|
7223
|
-
const client = getActiveClient();
|
|
7224
|
-
client.log('channel/getUserMessageFeedMakers', channelIds);
|
|
7225
|
-
const { data } = await client.http.get(`/api/v1/markers/user-message-feed`, {
|
|
7226
|
-
params: {
|
|
7227
|
-
channelIds,
|
|
7228
|
-
},
|
|
7229
|
-
});
|
|
7230
|
-
fireEvent('local.userMessageFeedMarker.fetched', { userMessageFeedMarker: data });
|
|
7231
|
-
return data;
|
|
7232
|
-
};
|
|
7233
|
-
|
|
7234
|
-
const prepareUnreadCountInfo = async (rawPayload) => {
|
|
8425
|
+
const onLocalInvitationCreated = (callback) => {
|
|
7235
8426
|
const client = getActiveClient();
|
|
7236
|
-
|
|
7237
|
-
|
|
7238
|
-
|
|
7239
|
-
|
|
7240
|
-
|
|
7241
|
-
|
|
7242
|
-
userFeedMarkers,
|
|
7243
|
-
});
|
|
7244
|
-
client.log('channel/prepareUnreadCountInfo', rawPayload.channels);
|
|
8427
|
+
const disposers = [
|
|
8428
|
+
createEventSubscriber(client, 'onLocalInvitationCreated', 'local.invitation.created', payload => callback(payload)),
|
|
8429
|
+
];
|
|
8430
|
+
return () => {
|
|
8431
|
+
disposers.forEach(fn => fn());
|
|
8432
|
+
};
|
|
7245
8433
|
};
|
|
7246
8434
|
|
|
7247
|
-
const getCachedMarker$1 = (entityId) => {
|
|
7248
|
-
var _a;
|
|
7249
|
-
const key = {
|
|
7250
|
-
entityId,
|
|
7251
|
-
userId: getActiveUser()._id,
|
|
7252
|
-
};
|
|
7253
|
-
return (_a = pullFromCache([
|
|
7254
|
-
'channelMarker',
|
|
7255
|
-
'get',
|
|
7256
|
-
getResolver('channelMarker')(key),
|
|
7257
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
7258
|
-
};
|
|
7259
|
-
const getUnreadInfoCached$1 = (channelId) => {
|
|
7260
|
-
var _a;
|
|
7261
|
-
return (_a = pullFromCache(['channelUnreadInfo', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
7262
|
-
};
|
|
7263
8435
|
/**
|
|
7264
|
-
*
|
|
7265
|
-
*
|
|
8436
|
+
* ```js
|
|
8437
|
+
* import { onLocalInvitationUpdated } from '@amityco/ts-sdk'
|
|
8438
|
+
* const dispose = onLocalInvitationUpdated(data => {
|
|
8439
|
+
* // ...
|
|
8440
|
+
* })
|
|
8441
|
+
* ```
|
|
7266
8442
|
*
|
|
7267
|
-
*
|
|
7268
|
-
*
|
|
7269
|
-
*
|
|
8443
|
+
* Fired when an {@link Amity.InvitationPayload} has been updated
|
|
8444
|
+
*
|
|
8445
|
+
* @param callback The function to call when the event was fired
|
|
8446
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
8447
|
+
*
|
|
8448
|
+
* @category Invitation Events
|
|
7270
8449
|
*/
|
|
7271
|
-
const
|
|
7272
|
-
var _a, _b, _c, _d;
|
|
8450
|
+
const onLocalInvitationUpdated = (callback) => {
|
|
7273
8451
|
const client = getActiveClient();
|
|
7274
|
-
|
|
7275
|
-
|
|
7276
|
-
|
|
7277
|
-
return (
|
|
7278
|
-
|
|
7279
|
-
|
|
8452
|
+
const disposers = [
|
|
8453
|
+
createEventSubscriber(client, 'onLocalInvitationUpdated', 'local.invitation.updated', payload => callback(payload)),
|
|
8454
|
+
];
|
|
8455
|
+
return () => {
|
|
8456
|
+
disposers.forEach(fn => fn());
|
|
8457
|
+
};
|
|
7280
8458
|
};
|
|
7281
8459
|
|
|
7282
|
-
const getCachedMarker = (entityId) => {
|
|
7283
|
-
var _a;
|
|
7284
|
-
const key = {
|
|
7285
|
-
entityId,
|
|
7286
|
-
userId: getActiveUser()._id,
|
|
7287
|
-
};
|
|
7288
|
-
return (_a = pullFromCache([
|
|
7289
|
-
'channelMarker',
|
|
7290
|
-
'get',
|
|
7291
|
-
getResolver('channelMarker')(key),
|
|
7292
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
7293
|
-
};
|
|
7294
|
-
const getUnreadInfoCached = (channelId) => {
|
|
7295
|
-
var _a;
|
|
7296
|
-
return (_a = pullFromCache(['channelUnreadInfo', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
7297
|
-
};
|
|
7298
8460
|
/**
|
|
7299
|
-
*
|
|
7300
|
-
*
|
|
8461
|
+
* ```js
|
|
8462
|
+
* import { onLocalInvitationDeleted } from '@amityco/ts-sdk'
|
|
8463
|
+
* const dispose = onLocalInvitationDeleted(data => {
|
|
8464
|
+
* // ...
|
|
8465
|
+
* })
|
|
8466
|
+
* ```
|
|
7301
8467
|
*
|
|
7302
|
-
*
|
|
7303
|
-
*
|
|
7304
|
-
*
|
|
8468
|
+
* Fired when an {@link Amity.InvitationPayload} has been deleted
|
|
8469
|
+
*
|
|
8470
|
+
* @param callback The function to call when the event was fired
|
|
8471
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
8472
|
+
*
|
|
8473
|
+
* @category Invitation Events
|
|
7305
8474
|
*/
|
|
7306
|
-
const
|
|
7307
|
-
var _a, _b, _c, _d, _e;
|
|
8475
|
+
const onLocalInvitationDeleted = (callback) => {
|
|
7308
8476
|
const client = getActiveClient();
|
|
7309
|
-
|
|
7310
|
-
|
|
7311
|
-
|
|
7312
|
-
|
|
7313
|
-
|
|
7314
|
-
|
|
7315
|
-
// leave the channel because currently backend can't handle this, so every time a user is banned
|
|
7316
|
-
// from a channel or the channel is deleted the channel's unread count will reset to zero
|
|
7317
|
-
return 0;
|
|
7318
|
-
}
|
|
7319
|
-
return (_e = (_c = marker === null || marker === void 0 ? void 0 : marker.unreadCount) !== null && _c !== void 0 ? _c : (_d = getCachedMarker(channel.channelInternalId)) === null || _d === void 0 ? void 0 : _d.unreadCount) !== null && _e !== void 0 ? _e : 0;
|
|
8477
|
+
const disposers = [
|
|
8478
|
+
createEventSubscriber(client, 'onLocalInvitationDeleted', 'local.invitation.deleted', payload => callback(payload)),
|
|
8479
|
+
];
|
|
8480
|
+
return () => {
|
|
8481
|
+
disposers.forEach(fn => fn());
|
|
8482
|
+
};
|
|
7320
8483
|
};
|
|
7321
8484
|
|
|
7322
|
-
|
|
7323
|
-
|
|
7324
|
-
|
|
7325
|
-
|
|
8485
|
+
class InvitationsLiveCollectionController extends LiveCollectionController {
|
|
8486
|
+
constructor(query, callback) {
|
|
8487
|
+
const queryStreamId = hash__default["default"](query);
|
|
8488
|
+
const cacheKey = ['invitation', 'collection', queryStreamId];
|
|
8489
|
+
const paginationController = new InvitationsPaginationController(query);
|
|
8490
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
8491
|
+
this.query = query;
|
|
8492
|
+
this.queryStreamController = new InvitationsQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareInvitationPayload);
|
|
8493
|
+
this.callback = callback.bind(this);
|
|
8494
|
+
this.loadPage({ initial: true });
|
|
8495
|
+
}
|
|
8496
|
+
setup() {
|
|
8497
|
+
var _a;
|
|
8498
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
8499
|
+
if (!collection) {
|
|
8500
|
+
pushToCache(this.cacheKey, {
|
|
8501
|
+
data: [],
|
|
8502
|
+
params: this.query,
|
|
8503
|
+
});
|
|
8504
|
+
}
|
|
8505
|
+
}
|
|
8506
|
+
async persistModel(queryPayload) {
|
|
8507
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
8508
|
+
}
|
|
8509
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
8510
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
8511
|
+
}
|
|
8512
|
+
startSubscription() {
|
|
8513
|
+
return this.queryStreamController.subscribeRTE([
|
|
8514
|
+
{
|
|
8515
|
+
fn: onLocalInvitationCreated,
|
|
8516
|
+
action: InvitationActionsEnum.OnLocalInvitationCreated,
|
|
8517
|
+
},
|
|
8518
|
+
{
|
|
8519
|
+
fn: onLocalInvitationUpdated,
|
|
8520
|
+
action: InvitationActionsEnum.OnLocalInvitationUpdated,
|
|
8521
|
+
},
|
|
8522
|
+
{
|
|
8523
|
+
fn: onLocalInvitationDeleted,
|
|
8524
|
+
action: InvitationActionsEnum.OnLocalInvitationDeleted,
|
|
8525
|
+
},
|
|
8526
|
+
]);
|
|
8527
|
+
}
|
|
8528
|
+
notifyChange({ origin, loading, error }) {
|
|
8529
|
+
var _a, _b;
|
|
8530
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
8531
|
+
if (!collection)
|
|
8532
|
+
return;
|
|
8533
|
+
const data = this.applyFilter((_b = collection.data
|
|
8534
|
+
.map(id => pullFromCache(['invitation', 'get', id]))
|
|
8535
|
+
.filter(isNonNullable)
|
|
8536
|
+
.map(({ data }) => invitationLinkedObject(data))) !== null && _b !== void 0 ? _b : []);
|
|
8537
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
8538
|
+
return;
|
|
8539
|
+
this.callback({
|
|
8540
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
8541
|
+
data,
|
|
8542
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
8543
|
+
loading,
|
|
8544
|
+
error,
|
|
8545
|
+
});
|
|
8546
|
+
}
|
|
8547
|
+
applyFilter(data) {
|
|
8548
|
+
let invitations = data;
|
|
8549
|
+
if (this.query.targetId) {
|
|
8550
|
+
invitations = invitations.filter(invitation => invitation.targetId === this.query.targetId);
|
|
8551
|
+
}
|
|
8552
|
+
if (this.query.statuses) {
|
|
8553
|
+
invitations = invitations.filter(invitation => { var _a; return (_a = this.query.statuses) === null || _a === void 0 ? void 0 : _a.includes(invitation.status); });
|
|
8554
|
+
}
|
|
8555
|
+
if (this.query.targetType) {
|
|
8556
|
+
invitations = invitations.filter(invitation => invitation.targetType === this.query.targetType);
|
|
8557
|
+
}
|
|
8558
|
+
if (this.query.type) {
|
|
8559
|
+
invitations = invitations.filter(invitation => invitation.type === this.query.type);
|
|
8560
|
+
}
|
|
8561
|
+
const sortFn = (() => {
|
|
8562
|
+
switch (this.query.sortBy) {
|
|
8563
|
+
case 'firstCreated':
|
|
8564
|
+
return sortByFirstCreated;
|
|
8565
|
+
case 'lastCreated':
|
|
8566
|
+
return sortByLastCreated;
|
|
8567
|
+
default:
|
|
8568
|
+
return sortByLastCreated;
|
|
8569
|
+
}
|
|
8570
|
+
})();
|
|
8571
|
+
invitations = invitations.sort(sortFn);
|
|
8572
|
+
return invitations;
|
|
8573
|
+
}
|
|
8574
|
+
}
|
|
7326
8575
|
|
|
7327
|
-
|
|
7328
|
-
|
|
7329
|
-
|
|
7330
|
-
|
|
7331
|
-
|
|
7332
|
-
|
|
7333
|
-
|
|
7334
|
-
|
|
7335
|
-
|
|
7336
|
-
|
|
7337
|
-
|
|
7338
|
-
|
|
7339
|
-
|
|
7340
|
-
|
|
7341
|
-
|
|
7342
|
-
|
|
7343
|
-
|
|
8576
|
+
/**
|
|
8577
|
+
* Get invitations
|
|
8578
|
+
*
|
|
8579
|
+
* @param params the query parameters
|
|
8580
|
+
* @param callback the callback to be called when the invitations are updated
|
|
8581
|
+
* @returns invitations
|
|
8582
|
+
*
|
|
8583
|
+
* @category Invitation Live Collection
|
|
8584
|
+
*
|
|
8585
|
+
*/
|
|
8586
|
+
const getInvitations = (params, callback, config) => {
|
|
8587
|
+
const { log, cache } = getActiveClient();
|
|
8588
|
+
if (!cache) {
|
|
8589
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
8590
|
+
}
|
|
8591
|
+
const timestamp = Date.now();
|
|
8592
|
+
log(`getInvitations: (tmpid: ${timestamp}) > listen`);
|
|
8593
|
+
const invitationsLiveCollection = new InvitationsLiveCollectionController(params, callback);
|
|
8594
|
+
const disposers = invitationsLiveCollection.startSubscription();
|
|
8595
|
+
const cacheKey = invitationsLiveCollection.getCacheKey();
|
|
8596
|
+
disposers.push(() => {
|
|
8597
|
+
dropFromCache(cacheKey);
|
|
7344
8598
|
});
|
|
8599
|
+
return () => {
|
|
8600
|
+
log(`getInvitations (tmpid: ${timestamp}) > dispose`);
|
|
8601
|
+
disposers.forEach(fn => fn());
|
|
8602
|
+
};
|
|
8603
|
+
};
|
|
8604
|
+
|
|
8605
|
+
const communityLinkedObject = (community) => {
|
|
8606
|
+
return Object.assign(Object.assign({}, community), { createInvitations: async (userIds) => {
|
|
8607
|
+
await createInvitations({
|
|
8608
|
+
type: "communityMemberInvite" /* InvitationTypeEnum.CommunityMemberInvite */,
|
|
8609
|
+
targetType: 'community',
|
|
8610
|
+
targetId: community.communityId,
|
|
8611
|
+
userIds,
|
|
8612
|
+
});
|
|
8613
|
+
}, getMemberInvitations: (params, callback) => {
|
|
8614
|
+
return getInvitations(Object.assign(Object.assign({}, params), { targetId: community.communityId, targetType: 'community', type: "communityMemberInvite" /* InvitationTypeEnum.CommunityMemberInvite */ }), callback);
|
|
8615
|
+
}, getInvitation: async () => {
|
|
8616
|
+
const { data } = await getInvitation('community', community.communityId);
|
|
8617
|
+
return data;
|
|
8618
|
+
}, join: async () => {
|
|
8619
|
+
return joinRequest(community.communityId);
|
|
8620
|
+
}, getJoinRequests: (params, callback) => {
|
|
8621
|
+
return getJoinRequests(Object.assign(Object.assign({}, params), { communityId: community.communityId }), callback);
|
|
8622
|
+
}, getMyJoinRequest: async () => {
|
|
8623
|
+
const { data } = await getMyJoinRequest(community.communityId);
|
|
8624
|
+
return data;
|
|
8625
|
+
} });
|
|
8626
|
+
};
|
|
8627
|
+
|
|
8628
|
+
const LinkedObject = {
|
|
8629
|
+
ad: adLinkedObject,
|
|
8630
|
+
comment: commentLinkedObject,
|
|
8631
|
+
post: postLinkedObject,
|
|
8632
|
+
user: userLinkedObject,
|
|
8633
|
+
category: categoryLinkedObject,
|
|
8634
|
+
stream: streamLinkedObject,
|
|
8635
|
+
story: storyLinkedObject,
|
|
8636
|
+
storyTarget: storyTargetLinkedObject,
|
|
8637
|
+
message: messageLinkedObject,
|
|
8638
|
+
reactor: reactorLinkedObject,
|
|
8639
|
+
channel: channelLinkedObject,
|
|
8640
|
+
pinnedPost: pinnedPostLinkedObject,
|
|
8641
|
+
notificationTray: notificationTrayLinkedObject,
|
|
8642
|
+
community: communityLinkedObject,
|
|
8643
|
+
invitation: invitationLinkedObject,
|
|
8644
|
+
joinRequest: joinRequestLinkedObject,
|
|
7345
8645
|
};
|
|
7346
8646
|
|
|
7347
8647
|
const constructChannelObject = (channel) => {
|
|
@@ -10063,38 +11363,6 @@ const onMessageMarked = (callback) => {
|
|
|
10063
11363
|
return createEventSubscriber(client, 'messageMarker/onMessageMarked', 'marker.marked-message', filter);
|
|
10064
11364
|
};
|
|
10065
11365
|
|
|
10066
|
-
function isObject(value) {
|
|
10067
|
-
return typeof value === 'object' && value !== null;
|
|
10068
|
-
}
|
|
10069
|
-
/**
|
|
10070
|
-
* convert all object getter property to static value
|
|
10071
|
-
*/
|
|
10072
|
-
const convertGetterPropsToStatic = (obj) => {
|
|
10073
|
-
if (!isObject(obj)) {
|
|
10074
|
-
return obj;
|
|
10075
|
-
}
|
|
10076
|
-
const entries = Object.entries(obj).map(([key, value]) => {
|
|
10077
|
-
const descriptor = Object.getOwnPropertyDescriptor(obj, key);
|
|
10078
|
-
if (typeof (descriptor === null || descriptor === void 0 ? void 0 : descriptor.get) === 'function') {
|
|
10079
|
-
return [key, descriptor.get.call(obj)];
|
|
10080
|
-
}
|
|
10081
|
-
return [key, value];
|
|
10082
|
-
});
|
|
10083
|
-
return Object.fromEntries(entries);
|
|
10084
|
-
};
|
|
10085
|
-
const removeFunctionProperties = (obj) => {
|
|
10086
|
-
if (!isObject(obj)) {
|
|
10087
|
-
return obj;
|
|
10088
|
-
}
|
|
10089
|
-
const entries = Object.entries(obj).map(([key, value]) => {
|
|
10090
|
-
if (typeof value === 'function') {
|
|
10091
|
-
return [key, undefined];
|
|
10092
|
-
}
|
|
10093
|
-
return [key, value];
|
|
10094
|
-
});
|
|
10095
|
-
return Object.fromEntries(entries);
|
|
10096
|
-
};
|
|
10097
|
-
|
|
10098
11366
|
/**
|
|
10099
11367
|
*
|
|
10100
11368
|
* ```js
|
|
@@ -10204,7 +11472,7 @@ const getUserUnread = (callback) => {
|
|
|
10204
11472
|
};
|
|
10205
11473
|
};
|
|
10206
11474
|
|
|
10207
|
-
var index$
|
|
11475
|
+
var index$n = /*#__PURE__*/Object.freeze({
|
|
10208
11476
|
__proto__: null,
|
|
10209
11477
|
getActiveClient: getActiveClient,
|
|
10210
11478
|
getActiveUser: getActiveUser,
|
|
@@ -10708,51 +11976,6 @@ const onLocalFollowRequestAccepted = (callback) => createLocalFollowEventSubscri
|
|
|
10708
11976
|
|
|
10709
11977
|
const onLocalFollowRequestDeclined = (callback) => createLocalFollowEventSubscriber('local.follow.requestDeclined', callback);
|
|
10710
11978
|
|
|
10711
|
-
class PaginationController {
|
|
10712
|
-
constructor(queryParams) {
|
|
10713
|
-
const { http } = getActiveClient();
|
|
10714
|
-
this.queryParams = queryParams;
|
|
10715
|
-
this.http = http;
|
|
10716
|
-
}
|
|
10717
|
-
loadFirstPage() {
|
|
10718
|
-
return this.onFetch("first" /* Amity.LiveCollectionPageDirection.FIRST */);
|
|
10719
|
-
}
|
|
10720
|
-
loadNextPage() {
|
|
10721
|
-
return this.onFetch("next" /* Amity.LiveCollectionPageDirection.NEXT */);
|
|
10722
|
-
}
|
|
10723
|
-
loadPreviousPage() {
|
|
10724
|
-
return this.onFetch("prev" /* Amity.LiveCollectionPageDirection.PREV */);
|
|
10725
|
-
}
|
|
10726
|
-
async onFetch(direction = "first" /* Amity.LiveCollectionPageDirection.FIRST */) {
|
|
10727
|
-
var _a, _b, _c, _d;
|
|
10728
|
-
if (direction === 'prev' && !this.previousToken)
|
|
10729
|
-
return;
|
|
10730
|
-
if (direction === 'next' && !this.nextToken)
|
|
10731
|
-
return;
|
|
10732
|
-
let token;
|
|
10733
|
-
if (direction === 'prev')
|
|
10734
|
-
token = this.previousToken;
|
|
10735
|
-
if (direction === 'next')
|
|
10736
|
-
token = this.nextToken;
|
|
10737
|
-
const queryResponse = await this.getRequest(this.queryParams, token);
|
|
10738
|
-
if (direction === 'first') {
|
|
10739
|
-
this.nextToken = (_a = queryResponse.paging) === null || _a === void 0 ? void 0 : _a.next;
|
|
10740
|
-
this.previousToken = (_b = queryResponse.paging) === null || _b === void 0 ? void 0 : _b.previous;
|
|
10741
|
-
}
|
|
10742
|
-
if (direction === 'prev')
|
|
10743
|
-
this.previousToken = (_c = queryResponse.paging) === null || _c === void 0 ? void 0 : _c.previous;
|
|
10744
|
-
if (direction === 'next')
|
|
10745
|
-
this.nextToken = (_d = queryResponse.paging) === null || _d === void 0 ? void 0 : _d.next;
|
|
10746
|
-
return queryResponse;
|
|
10747
|
-
}
|
|
10748
|
-
getNextToken() {
|
|
10749
|
-
return this.nextToken;
|
|
10750
|
-
}
|
|
10751
|
-
getPrevToken() {
|
|
10752
|
-
return this.previousToken;
|
|
10753
|
-
}
|
|
10754
|
-
}
|
|
10755
|
-
|
|
10756
11979
|
class FollowerPaginationController extends PaginationController {
|
|
10757
11980
|
async getRequest(queryParams, token) {
|
|
10758
11981
|
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, userId } = queryParams, params = __rest(queryParams, ["limit", "userId"]);
|
|
@@ -10766,13 +11989,6 @@ class FollowerPaginationController extends PaginationController {
|
|
|
10766
11989
|
}
|
|
10767
11990
|
}
|
|
10768
11991
|
|
|
10769
|
-
class QueryStreamController {
|
|
10770
|
-
constructor(query, cacheKey) {
|
|
10771
|
-
this.query = query;
|
|
10772
|
-
this.cacheKey = cacheKey;
|
|
10773
|
-
}
|
|
10774
|
-
}
|
|
10775
|
-
|
|
10776
11992
|
var EnumFollowActions;
|
|
10777
11993
|
(function (EnumFollowActions) {
|
|
10778
11994
|
EnumFollowActions["OnRequested"] = "onRequested";
|
|
@@ -10840,109 +12056,6 @@ class FollowerQueryStreamController extends QueryStreamController {
|
|
|
10840
12056
|
}
|
|
10841
12057
|
}
|
|
10842
12058
|
|
|
10843
|
-
class PaginationNoPageController {
|
|
10844
|
-
constructor(queryParams) {
|
|
10845
|
-
const { http } = getActiveClient();
|
|
10846
|
-
this.queryParams = queryParams;
|
|
10847
|
-
this.http = http;
|
|
10848
|
-
}
|
|
10849
|
-
async onFetch() {
|
|
10850
|
-
const queryResponse = await this.getRequest(this.queryParams);
|
|
10851
|
-
return queryResponse;
|
|
10852
|
-
}
|
|
10853
|
-
}
|
|
10854
|
-
|
|
10855
|
-
class LiveCollectionController {
|
|
10856
|
-
constructor(paginationController, queryStreamId, cacheKey, callback) {
|
|
10857
|
-
this.paginationController = paginationController;
|
|
10858
|
-
this.queryStreamId = queryStreamId;
|
|
10859
|
-
this.cacheKey = cacheKey;
|
|
10860
|
-
this.callback = callback;
|
|
10861
|
-
}
|
|
10862
|
-
async refresh() {
|
|
10863
|
-
try {
|
|
10864
|
-
let result;
|
|
10865
|
-
if (this.paginationController instanceof PaginationNoPageController) {
|
|
10866
|
-
result = await this.paginationController.onFetch();
|
|
10867
|
-
}
|
|
10868
|
-
else {
|
|
10869
|
-
result = await this.paginationController.loadFirstPage();
|
|
10870
|
-
}
|
|
10871
|
-
if (!result)
|
|
10872
|
-
return;
|
|
10873
|
-
await this.persistModel(result);
|
|
10874
|
-
this.persistQueryStream({
|
|
10875
|
-
response: result,
|
|
10876
|
-
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
10877
|
-
refresh: true,
|
|
10878
|
-
});
|
|
10879
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
10880
|
-
}
|
|
10881
|
-
catch (e) {
|
|
10882
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
10883
|
-
}
|
|
10884
|
-
}
|
|
10885
|
-
loadPage({ initial = false, direction = "next" /* Amity.LiveCollectionPageDirection.NEXT */, }) {
|
|
10886
|
-
this.setup();
|
|
10887
|
-
this.notifyChange({ origin: "local" /* Amity.LiveDataOrigin.LOCAL */, loading: true });
|
|
10888
|
-
if (initial) {
|
|
10889
|
-
this.refresh();
|
|
10890
|
-
}
|
|
10891
|
-
else if (direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */) {
|
|
10892
|
-
this.loadPrevPage();
|
|
10893
|
-
}
|
|
10894
|
-
else if (direction === "next" /* Amity.LiveCollectionPageDirection.NEXT */) {
|
|
10895
|
-
this.loadNextPage();
|
|
10896
|
-
}
|
|
10897
|
-
}
|
|
10898
|
-
async loadNextPage() {
|
|
10899
|
-
try {
|
|
10900
|
-
if (this.paginationController instanceof PaginationNoPageController)
|
|
10901
|
-
return;
|
|
10902
|
-
const result = await this.paginationController.loadNextPage();
|
|
10903
|
-
if (!result)
|
|
10904
|
-
return;
|
|
10905
|
-
await this.persistModel(result);
|
|
10906
|
-
this.persistQueryStream({
|
|
10907
|
-
response: result,
|
|
10908
|
-
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
10909
|
-
});
|
|
10910
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
10911
|
-
}
|
|
10912
|
-
catch (e) {
|
|
10913
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
10914
|
-
}
|
|
10915
|
-
}
|
|
10916
|
-
async loadPrevPage() {
|
|
10917
|
-
try {
|
|
10918
|
-
if (this.paginationController instanceof PaginationNoPageController)
|
|
10919
|
-
return;
|
|
10920
|
-
const result = await this.paginationController.loadPreviousPage();
|
|
10921
|
-
if (!result)
|
|
10922
|
-
return;
|
|
10923
|
-
await this.persistModel(result);
|
|
10924
|
-
this.persistQueryStream({
|
|
10925
|
-
response: result,
|
|
10926
|
-
direction: "prev" /* Amity.LiveCollectionPageDirection.PREV */,
|
|
10927
|
-
});
|
|
10928
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
10929
|
-
}
|
|
10930
|
-
catch (e) {
|
|
10931
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
10932
|
-
}
|
|
10933
|
-
}
|
|
10934
|
-
shouldNotify(data) {
|
|
10935
|
-
const newData = data.map(convertGetterPropsToStatic).map(removeFunctionProperties);
|
|
10936
|
-
if (isEqual(this.snapshot, newData))
|
|
10937
|
-
return false;
|
|
10938
|
-
this.snapshot = newData;
|
|
10939
|
-
return true;
|
|
10940
|
-
}
|
|
10941
|
-
getCacheKey() {
|
|
10942
|
-
return this.cacheKey;
|
|
10943
|
-
}
|
|
10944
|
-
}
|
|
10945
|
-
|
|
10946
12059
|
const onFollowerUserDeleted = ({ userId }) => (callback) => {
|
|
10947
12060
|
const client = getActiveClient();
|
|
10948
12061
|
const filter = (data) => {
|
|
@@ -11411,7 +12524,7 @@ const getMyFollowInfo = (callback) => {
|
|
|
11411
12524
|
};
|
|
11412
12525
|
/* end_public_function */
|
|
11413
12526
|
|
|
11414
|
-
var index$
|
|
12527
|
+
var index$m = /*#__PURE__*/Object.freeze({
|
|
11415
12528
|
__proto__: null,
|
|
11416
12529
|
blockUser: blockUser,
|
|
11417
12530
|
unBlockUser: unBlockUser,
|
|
@@ -12426,9 +13539,9 @@ var AmityUserSearchMatchType;
|
|
|
12426
13539
|
AmityUserSearchMatchType["PARTIAL"] = "partial";
|
|
12427
13540
|
})(AmityUserSearchMatchType || (AmityUserSearchMatchType = {}));
|
|
12428
13541
|
|
|
12429
|
-
var index$
|
|
13542
|
+
var index$l = /*#__PURE__*/Object.freeze({
|
|
12430
13543
|
__proto__: null,
|
|
12431
|
-
Relationship: index$
|
|
13544
|
+
Relationship: index$m,
|
|
12432
13545
|
getUserByIds: getUserByIds,
|
|
12433
13546
|
updateUser: updateUser,
|
|
12434
13547
|
flagUser: flagUser,
|
|
@@ -12736,7 +13849,7 @@ const updateAltText = async (fileId, altText) => {
|
|
|
12736
13849
|
};
|
|
12737
13850
|
/* end_public_function */
|
|
12738
13851
|
|
|
12739
|
-
var index$
|
|
13852
|
+
var index$k = /*#__PURE__*/Object.freeze({
|
|
12740
13853
|
__proto__: null,
|
|
12741
13854
|
getFile: getFile,
|
|
12742
13855
|
uploadFile: uploadFile,
|
|
@@ -13075,46 +14188,15 @@ getComment$2.locally = (commentId) => {
|
|
|
13075
14188
|
const client = getActiveClient();
|
|
13076
14189
|
client.log('comment/getComment.locally', commentId);
|
|
13077
14190
|
if (!client.cache)
|
|
13078
|
-
return;
|
|
13079
|
-
const cached = pullFromCache(['comment', 'get', commentId]);
|
|
13080
|
-
if (!cached)
|
|
13081
|
-
return;
|
|
13082
|
-
return {
|
|
13083
|
-
data: LinkedObject.comment(cached.data),
|
|
13084
|
-
cachedAt: cached.cachedAt,
|
|
13085
|
-
};
|
|
13086
|
-
};
|
|
13087
|
-
|
|
13088
|
-
/*
|
|
13089
|
-
* verifies membership status
|
|
13090
|
-
*/
|
|
13091
|
-
function isMember(membership) {
|
|
13092
|
-
return membership !== 'none';
|
|
13093
|
-
}
|
|
13094
|
-
/*
|
|
13095
|
-
* checks if currently logged in user is part of the community
|
|
13096
|
-
*/
|
|
13097
|
-
function isCurrentUserPartOfCommunity(c, m) {
|
|
13098
|
-
const { userId } = getActiveUser();
|
|
13099
|
-
return c.communityId === m.communityId && m.userId === userId;
|
|
13100
|
-
}
|
|
13101
|
-
/*
|
|
13102
|
-
* For mqtt events server will not send user specific data as it's broadcasted
|
|
13103
|
-
* to multiple users and it also does not include communityUser
|
|
13104
|
-
*
|
|
13105
|
-
* Client SDK needs to check for the existing isJoined field in cache data before calculating.
|
|
13106
|
-
* Althought this can be calculated, it's not scalable.
|
|
13107
|
-
*/
|
|
13108
|
-
function updateMembershipStatus(communities, communityUsers) {
|
|
13109
|
-
return communities.map(c => {
|
|
13110
|
-
const cachedCommunity = pullFromCache(['community', 'get', c.communityId]);
|
|
13111
|
-
if ((cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data) && (cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data.hasOwnProperty('isJoined'))) {
|
|
13112
|
-
return Object.assign(Object.assign({}, cachedCommunity.data), c);
|
|
13113
|
-
}
|
|
13114
|
-
const isJoined = communityUsers.some(m => isCurrentUserPartOfCommunity(c, m) && isMember(m.communityMembership));
|
|
13115
|
-
return Object.assign(Object.assign({}, c), { isJoined });
|
|
13116
|
-
});
|
|
13117
|
-
}
|
|
14191
|
+
return;
|
|
14192
|
+
const cached = pullFromCache(['comment', 'get', commentId]);
|
|
14193
|
+
if (!cached)
|
|
14194
|
+
return;
|
|
14195
|
+
return {
|
|
14196
|
+
data: LinkedObject.comment(cached.data),
|
|
14197
|
+
cachedAt: cached.cachedAt,
|
|
14198
|
+
};
|
|
14199
|
+
};
|
|
13118
14200
|
|
|
13119
14201
|
const getMyReactionsInCache = (payload, eventPrefix) => {
|
|
13120
14202
|
var _a, _b;
|
|
@@ -13430,53 +14512,6 @@ removeReaction.optimistically = (referenceType, referenceId, reactionName) => {
|
|
|
13430
14512
|
return !((_d = reaction === null || reaction === void 0 ? void 0 : reaction.myReactions) === null || _d === void 0 ? void 0 : _d.includes(reactionName));
|
|
13431
14513
|
};
|
|
13432
14514
|
|
|
13433
|
-
const getMatchPostSetting = (value) => {
|
|
13434
|
-
var _a;
|
|
13435
|
-
return (_a = Object.keys(CommunityPostSettingMaps).find(key => value.needApprovalOnPostCreation ===
|
|
13436
|
-
CommunityPostSettingMaps[key].needApprovalOnPostCreation &&
|
|
13437
|
-
value.onlyAdminCanPost === CommunityPostSettingMaps[key].onlyAdminCanPost)) !== null && _a !== void 0 ? _a : DefaultCommunityPostSetting;
|
|
13438
|
-
};
|
|
13439
|
-
function addPostSetting({ communities }) {
|
|
13440
|
-
return communities.map((_a) => {
|
|
13441
|
-
var { needApprovalOnPostCreation, onlyAdminCanPost } = _a, restCommunityPayload = __rest(_a, ["needApprovalOnPostCreation", "onlyAdminCanPost"]);
|
|
13442
|
-
return (Object.assign({ postSetting: getMatchPostSetting({
|
|
13443
|
-
needApprovalOnPostCreation,
|
|
13444
|
-
onlyAdminCanPost,
|
|
13445
|
-
}) }, restCommunityPayload));
|
|
13446
|
-
});
|
|
13447
|
-
}
|
|
13448
|
-
const prepareCommunityPayload = (rawPayload) => {
|
|
13449
|
-
const communitiesWithPostSetting = addPostSetting({ communities: rawPayload.communities });
|
|
13450
|
-
// map users with community
|
|
13451
|
-
const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
|
|
13452
|
-
const user = rawPayload.users.find(user => user.userId === communityUser.userId);
|
|
13453
|
-
return Object.assign(Object.assign({}, communityUser), { user });
|
|
13454
|
-
});
|
|
13455
|
-
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
13456
|
-
return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
13457
|
-
};
|
|
13458
|
-
const prepareCommunityMembershipPayload = (rawPayload) => {
|
|
13459
|
-
const communitiesWithPostSetting = addPostSetting({ communities: rawPayload.communities });
|
|
13460
|
-
// map users with community
|
|
13461
|
-
const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
|
|
13462
|
-
const user = rawPayload.users.find(user => user.userId === communityUser.userId);
|
|
13463
|
-
return Object.assign(Object.assign({}, communityUser), { user });
|
|
13464
|
-
});
|
|
13465
|
-
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
13466
|
-
return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
13467
|
-
};
|
|
13468
|
-
const prepareCommunityRequest = (params) => {
|
|
13469
|
-
const { postSetting = undefined, storySetting } = params, restParam = __rest(params, ["postSetting", "storySetting"]);
|
|
13470
|
-
return Object.assign(Object.assign(Object.assign({}, restParam), (postSetting ? CommunityPostSettingMaps[postSetting] : undefined)), {
|
|
13471
|
-
// Convert story setting to the actual value. (Allow by default)
|
|
13472
|
-
allowCommentInStory: typeof (storySetting === null || storySetting === void 0 ? void 0 : storySetting.enableComment) === 'boolean' ? storySetting.enableComment : true });
|
|
13473
|
-
};
|
|
13474
|
-
const prepareSemanticSearchCommunityPayload = (_a) => {
|
|
13475
|
-
var communityPayload = __rest(_a, ["searchResult"]);
|
|
13476
|
-
const processedCommunityPayload = prepareCommunityPayload(communityPayload);
|
|
13477
|
-
return Object.assign({}, processedCommunityPayload);
|
|
13478
|
-
};
|
|
13479
|
-
|
|
13480
14515
|
const preparePostPayload = (payload) => {
|
|
13481
14516
|
const { posts: postsData } = payload, postPayload = __rest(payload, ["posts"]);
|
|
13482
14517
|
// Unpack community payload by mapping payload field to postSetting value.
|
|
@@ -14604,7 +15639,7 @@ const getReactions = (params, callback, config) => {
|
|
|
14604
15639
|
};
|
|
14605
15640
|
/* end_public_function */
|
|
14606
15641
|
|
|
14607
|
-
var index$
|
|
15642
|
+
var index$j = /*#__PURE__*/Object.freeze({
|
|
14608
15643
|
__proto__: null,
|
|
14609
15644
|
addReaction: addReaction,
|
|
14610
15645
|
removeReaction: removeReaction,
|
|
@@ -15921,19 +16956,26 @@ getDeliveredUsers.locally = (query) => {
|
|
|
15921
16956
|
/**
|
|
15922
16957
|
* ```js
|
|
15923
16958
|
* import { MessageRepository } from '@amityco/ts-sdk'
|
|
15924
|
-
* const flagged = await MessageRepository.flagMessage(messageId)
|
|
16959
|
+
* const flagged = await MessageRepository.flagMessage(messageId, reason)
|
|
15925
16960
|
* ```
|
|
15926
16961
|
*
|
|
15927
16962
|
* @param messageId of the message to flag
|
|
16963
|
+
* @param reason the reason to flag the message
|
|
15928
16964
|
* @returns the created report result
|
|
15929
16965
|
*
|
|
15930
16966
|
* @category Message API
|
|
15931
16967
|
* @async
|
|
15932
16968
|
* */
|
|
15933
|
-
const flagMessage = async (messageId) => {
|
|
16969
|
+
const flagMessage = async (messageId, reason) => {
|
|
15934
16970
|
const client = getActiveClient();
|
|
15935
16971
|
client.log('message/flag', messageId);
|
|
15936
|
-
const
|
|
16972
|
+
const isPredefinedReason = reason &&
|
|
16973
|
+
Object.entries(exports.ContentFlagReasonEnum).some(([key, value]) => key !== exports.ContentFlagReasonEnum.Others && value === reason);
|
|
16974
|
+
const body = {
|
|
16975
|
+
reason: isPredefinedReason ? reason : exports.ContentFlagReasonEnum.Others,
|
|
16976
|
+
detail: !isPredefinedReason ? reason : '',
|
|
16977
|
+
};
|
|
16978
|
+
const { data: payload } = await client.http.post(`/api/v5/messages/${encodeURIComponent(messageId)}/flags`, body);
|
|
15937
16979
|
if (client.cache) {
|
|
15938
16980
|
const messagePayload = await prepareMessagePayload(payload);
|
|
15939
16981
|
ingestInCache(messagePayload);
|
|
@@ -16420,7 +17462,7 @@ const getMessages = (params, callback, config) => {
|
|
|
16420
17462
|
};
|
|
16421
17463
|
/* end_public_function */
|
|
16422
17464
|
|
|
16423
|
-
var index$
|
|
17465
|
+
var index$i = /*#__PURE__*/Object.freeze({
|
|
16424
17466
|
__proto__: null,
|
|
16425
17467
|
createMessage: createMessage,
|
|
16426
17468
|
updateMessage: updateMessage,
|
|
@@ -16946,7 +17988,7 @@ const stopMessageReceiptSync = (subChannelId) => {
|
|
|
16946
17988
|
};
|
|
16947
17989
|
/* end_public_function */
|
|
16948
17990
|
|
|
16949
|
-
var index$
|
|
17991
|
+
var index$h = /*#__PURE__*/Object.freeze({
|
|
16950
17992
|
__proto__: null,
|
|
16951
17993
|
getSubChannelByIds: getSubChannels$1,
|
|
16952
17994
|
createSubChannel: createSubChannel,
|
|
@@ -18260,7 +19302,7 @@ const searchMembers$1 = (params, callback, config) => {
|
|
|
18260
19302
|
};
|
|
18261
19303
|
/* end_public_function */
|
|
18262
19304
|
|
|
18263
|
-
var index$
|
|
19305
|
+
var index$g = /*#__PURE__*/Object.freeze({
|
|
18264
19306
|
__proto__: null,
|
|
18265
19307
|
addMembers: addMembers$1,
|
|
18266
19308
|
removeMembers: removeMembers$1,
|
|
@@ -18463,7 +19505,7 @@ const unmuteMembers = async (channelId, userIds) => {
|
|
|
18463
19505
|
};
|
|
18464
19506
|
/* end_public_function */
|
|
18465
19507
|
|
|
18466
|
-
var index$
|
|
19508
|
+
var index$f = /*#__PURE__*/Object.freeze({
|
|
18467
19509
|
__proto__: null,
|
|
18468
19510
|
addRole: addRole,
|
|
18469
19511
|
removeRole: removeRole,
|
|
@@ -18473,10 +19515,10 @@ var index$e = /*#__PURE__*/Object.freeze({
|
|
|
18473
19515
|
unmuteMembers: unmuteMembers
|
|
18474
19516
|
});
|
|
18475
19517
|
|
|
18476
|
-
var index$
|
|
19518
|
+
var index$e = /*#__PURE__*/Object.freeze({
|
|
18477
19519
|
__proto__: null,
|
|
18478
|
-
Membership: index$
|
|
18479
|
-
Moderation: index$
|
|
19520
|
+
Membership: index$g,
|
|
19521
|
+
Moderation: index$f,
|
|
18480
19522
|
getChannelByIds: getChannelByIds$1,
|
|
18481
19523
|
createChannel: createChannel,
|
|
18482
19524
|
updateChannel: updateChannel,
|
|
@@ -18530,12 +19572,15 @@ const saveCommunityUsers = (communities, communityUsers) => {
|
|
|
18530
19572
|
* @category Community API
|
|
18531
19573
|
* @async
|
|
18532
19574
|
*/
|
|
18533
|
-
const getCommunities$1 = async (communityIds) => {
|
|
19575
|
+
const getCommunities$1 = async (communityIds, includeDiscoverablePrivateCommunity) => {
|
|
18534
19576
|
const client = getActiveClient();
|
|
18535
19577
|
client.log('community/getCommunities', communityIds);
|
|
18536
19578
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
18537
19579
|
const { data: payload } = await client.http.get(`/api/v3/communities/list`, {
|
|
18538
|
-
params: {
|
|
19580
|
+
params: {
|
|
19581
|
+
communityIds,
|
|
19582
|
+
includeDiscoverablePrivateCommunity: includeDiscoverablePrivateCommunity !== null && includeDiscoverablePrivateCommunity !== void 0 ? includeDiscoverablePrivateCommunity : true,
|
|
19583
|
+
},
|
|
18539
19584
|
});
|
|
18540
19585
|
const data = prepareCommunityPayload(payload);
|
|
18541
19586
|
const cachedAt = client.cache && Date.now();
|
|
@@ -18544,7 +19589,7 @@ const getCommunities$1 = async (communityIds) => {
|
|
|
18544
19589
|
saveCommunityUsers(data.communities, data.communityUsers);
|
|
18545
19590
|
}
|
|
18546
19591
|
return {
|
|
18547
|
-
data: data.communities,
|
|
19592
|
+
data: data.communities.map(community => LinkedObject.community(community)),
|
|
18548
19593
|
cachedAt,
|
|
18549
19594
|
};
|
|
18550
19595
|
};
|
|
@@ -18586,7 +19631,7 @@ getCommunities$1.locally = (communityIds) => {
|
|
|
18586
19631
|
/**
|
|
18587
19632
|
* ```js
|
|
18588
19633
|
* import { createCommunity } from '@amityco/ts-sdk'
|
|
18589
|
-
* const created = await createCommunity({ communityId: 'foobar', displayName: 'foobar' })
|
|
19634
|
+
* const created = await createCommunity({ communityId: 'foobar', displayName: 'foobar', isDiscoverable: true, requiresJoinApproval: false })
|
|
18590
19635
|
* ```
|
|
18591
19636
|
*
|
|
18592
19637
|
* Creates an {@link Amity.Community}
|
|
@@ -18610,7 +19655,7 @@ const createCommunity = async (bundle) => {
|
|
|
18610
19655
|
}
|
|
18611
19656
|
const { communities } = data;
|
|
18612
19657
|
return {
|
|
18613
|
-
data: communities[0],
|
|
19658
|
+
data: LinkedObject.community(communities[0]),
|
|
18614
19659
|
cachedAt,
|
|
18615
19660
|
};
|
|
18616
19661
|
};
|
|
@@ -18622,7 +19667,7 @@ const createCommunity = async (bundle) => {
|
|
|
18622
19667
|
/**
|
|
18623
19668
|
* ```js
|
|
18624
19669
|
* import { updateCommunity } from '@amityco/ts-sdk'
|
|
18625
|
-
* const updated = await updateCommunity(communityId, { displayName: 'foobar' })
|
|
19670
|
+
* const updated = await updateCommunity(communityId, { displayName: 'foobar', isDiscoverable: true, requiresJoinApproval: false })
|
|
18626
19671
|
* ```
|
|
18627
19672
|
*
|
|
18628
19673
|
* Updates an {@link Amity.Community}
|
|
@@ -18647,7 +19692,7 @@ const updateCommunity = async (communityId, patch) => {
|
|
|
18647
19692
|
}
|
|
18648
19693
|
const { communities } = data;
|
|
18649
19694
|
return {
|
|
18650
|
-
data: communities.find(community => community.communityId === communityId),
|
|
19695
|
+
data: LinkedObject.community(communities.find(community => community.communityId === communityId)),
|
|
18651
19696
|
cachedAt,
|
|
18652
19697
|
};
|
|
18653
19698
|
};
|
|
@@ -18667,11 +19712,16 @@ const updateCommunity = async (communityId, patch) => {
|
|
|
18667
19712
|
* @category Community API
|
|
18668
19713
|
* @async
|
|
18669
19714
|
*/
|
|
18670
|
-
const getCommunity$1 = async (communityId) => {
|
|
19715
|
+
const getCommunity$1 = async (communityId, type, includeDiscoverablePrivateCommunity) => {
|
|
18671
19716
|
const client = getActiveClient();
|
|
18672
19717
|
client.log('community/getCommunity', communityId);
|
|
18673
19718
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
18674
|
-
const { data: payload } = await client.http.get(`/api/v3/communities/${communityId}
|
|
19719
|
+
const { data: payload } = await client.http.get(`/api/v3/communities/${communityId}`, {
|
|
19720
|
+
params: {
|
|
19721
|
+
type: 'communityJoinRequest',
|
|
19722
|
+
includeDiscoverablePrivateCommunity: includeDiscoverablePrivateCommunity !== null && includeDiscoverablePrivateCommunity !== void 0 ? includeDiscoverablePrivateCommunity : true,
|
|
19723
|
+
},
|
|
19724
|
+
});
|
|
18675
19725
|
const data = prepareCommunityPayload(payload);
|
|
18676
19726
|
const cachedAt = client.cache && Date.now();
|
|
18677
19727
|
if (client.cache) {
|
|
@@ -18680,7 +19730,7 @@ const getCommunity$1 = async (communityId) => {
|
|
|
18680
19730
|
}
|
|
18681
19731
|
const { communities } = data;
|
|
18682
19732
|
return {
|
|
18683
|
-
data: communities.find(community => community.communityId === communityId),
|
|
19733
|
+
data: LinkedObject.community(communities.find(community => community.communityId === communityId)),
|
|
18684
19734
|
cachedAt,
|
|
18685
19735
|
};
|
|
18686
19736
|
};
|
|
@@ -18706,7 +19756,7 @@ getCommunity$1.locally = (communityId) => {
|
|
|
18706
19756
|
if (!cached)
|
|
18707
19757
|
return;
|
|
18708
19758
|
return {
|
|
18709
|
-
data: cached.data,
|
|
19759
|
+
data: LinkedObject.community(cached.data),
|
|
18710
19760
|
cachedAt: cached.cachedAt,
|
|
18711
19761
|
};
|
|
18712
19762
|
};
|
|
@@ -18746,6 +19796,9 @@ const deleteCommunity = async (communityId) => {
|
|
|
18746
19796
|
};
|
|
18747
19797
|
/* end_public_function */
|
|
18748
19798
|
|
|
19799
|
+
/**
|
|
19800
|
+
* @deprecated This function will to be deprecated and use the new community.join().
|
|
19801
|
+
*/
|
|
18749
19802
|
/* begin_public_function
|
|
18750
19803
|
id: community.join
|
|
18751
19804
|
*/
|
|
@@ -18886,10 +19939,11 @@ const onCommunityDeleted = (callback) => createCommunityEventSubscriber('communi
|
|
|
18886
19939
|
*/
|
|
18887
19940
|
class CommunitiesPaginationController$1 extends PaginationController {
|
|
18888
19941
|
async getRequest(queryParams, token) {
|
|
19942
|
+
var _a;
|
|
18889
19943
|
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
18890
19944
|
const options = token ? { token } : { limit };
|
|
18891
19945
|
const { data: queryResponse } = await this.http.get(`/api/v3/communities`, {
|
|
18892
|
-
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(params.includeDeleted), keyword: params.displayName, filter: params.membership, options }),
|
|
19946
|
+
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(params.includeDeleted), keyword: params.displayName, filter: params.membership, includeDiscoverablePrivateCommunity: (_a = params.includeDiscoverablePrivateCommunity) !== null && _a !== void 0 ? _a : true, options }),
|
|
18893
19947
|
});
|
|
18894
19948
|
return queryResponse;
|
|
18895
19949
|
}
|
|
@@ -19856,7 +20910,7 @@ const searchMembers = (params, callback, config) => {
|
|
|
19856
20910
|
};
|
|
19857
20911
|
/* end_public_function */
|
|
19858
20912
|
|
|
19859
|
-
var index$
|
|
20913
|
+
var index$d = /*#__PURE__*/Object.freeze({
|
|
19860
20914
|
__proto__: null,
|
|
19861
20915
|
addMembers: addMembers,
|
|
19862
20916
|
removeMembers: removeMembers,
|
|
@@ -20336,7 +21390,7 @@ class TrendingCommunityLiveCollectionController extends LiveCollectionController
|
|
|
20336
21390
|
const data = (_b = collection.data
|
|
20337
21391
|
.map(id => pullFromCache(['community', 'get', id]))
|
|
20338
21392
|
.filter(isNonNullable)
|
|
20339
|
-
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
|
|
21393
|
+
.map(({ data }) => communityLinkedObject(data))) !== null && _b !== void 0 ? _b : [];
|
|
20340
21394
|
if (!this.shouldNotify(data) && origin === 'event')
|
|
20341
21395
|
return;
|
|
20342
21396
|
this.callback({
|
|
@@ -20498,7 +21552,7 @@ class RecommendedCommunityLiveCollectionController extends LiveCollectionControl
|
|
|
20498
21552
|
const data = (_b = collection.data
|
|
20499
21553
|
.map(id => pullFromCache(['community', 'get', id]))
|
|
20500
21554
|
.filter(isNonNullable)
|
|
20501
|
-
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
|
|
21555
|
+
.map(({ data }) => communityLinkedObject(data))) !== null && _b !== void 0 ? _b : [];
|
|
20502
21556
|
if (!this.shouldNotify(data) && origin === 'event')
|
|
20503
21557
|
return;
|
|
20504
21558
|
this.callback({
|
|
@@ -20881,7 +21935,7 @@ const unbanMembers = async (communityId, userIds) => {
|
|
|
20881
21935
|
};
|
|
20882
21936
|
/* end_public_function */
|
|
20883
21937
|
|
|
20884
|
-
var index$
|
|
21938
|
+
var index$c = /*#__PURE__*/Object.freeze({
|
|
20885
21939
|
__proto__: null,
|
|
20886
21940
|
addRoles: addRoles,
|
|
20887
21941
|
removeRoles: removeRoles,
|
|
@@ -20889,10 +21943,10 @@ var index$b = /*#__PURE__*/Object.freeze({
|
|
|
20889
21943
|
unbanMembers: unbanMembers
|
|
20890
21944
|
});
|
|
20891
21945
|
|
|
20892
|
-
var index$
|
|
21946
|
+
var index$b = /*#__PURE__*/Object.freeze({
|
|
20893
21947
|
__proto__: null,
|
|
20894
|
-
Moderation: index$
|
|
20895
|
-
Membership: index$
|
|
21948
|
+
Moderation: index$c,
|
|
21949
|
+
Membership: index$d,
|
|
20896
21950
|
getCommunityByIds: getCommunities$1,
|
|
20897
21951
|
createCommunity: createCommunity,
|
|
20898
21952
|
updateCommunity: updateCommunity,
|
|
@@ -21125,7 +22179,7 @@ const getCategories = (params, callback, config) => {
|
|
|
21125
22179
|
};
|
|
21126
22180
|
/* end_public_function */
|
|
21127
22181
|
|
|
21128
|
-
var index$
|
|
22182
|
+
var index$a = /*#__PURE__*/Object.freeze({
|
|
21129
22183
|
__proto__: null,
|
|
21130
22184
|
getCategory: getCategory,
|
|
21131
22185
|
getCategories: getCategories
|
|
@@ -21293,7 +22347,7 @@ getCustomRankingGlobalFeed.locally = (query) => {
|
|
|
21293
22347
|
: undefined;
|
|
21294
22348
|
};
|
|
21295
22349
|
|
|
21296
|
-
var index$
|
|
22350
|
+
var index$9 = /*#__PURE__*/Object.freeze({
|
|
21297
22351
|
__proto__: null,
|
|
21298
22352
|
queryGlobalFeed: queryGlobalFeed,
|
|
21299
22353
|
getCustomRankingGlobalFeed: getCustomRankingGlobalFeed
|
|
@@ -22622,7 +23676,7 @@ const getComments = (params, callback, config) => {
|
|
|
22622
23676
|
};
|
|
22623
23677
|
/* end_public_function */
|
|
22624
23678
|
|
|
22625
|
-
var index$
|
|
23679
|
+
var index$8 = /*#__PURE__*/Object.freeze({
|
|
22626
23680
|
__proto__: null,
|
|
22627
23681
|
getCommentByIds: getCommentByIds,
|
|
22628
23682
|
createComment: createComment,
|
|
@@ -23148,7 +24202,8 @@ class PinnedPostQueryStreamController extends QueryStreamController {
|
|
|
23148
24202
|
const client = getActiveClient();
|
|
23149
24203
|
const cachedAt = client.cache && Date.now();
|
|
23150
24204
|
if (client.cache) {
|
|
23151
|
-
|
|
24205
|
+
const processedPayload = Object.assign(Object.assign({}, response), { users: response.users ? response.users.map(convertRawUserToInternalUser) : [] });
|
|
24206
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
23152
24207
|
}
|
|
23153
24208
|
}
|
|
23154
24209
|
appendToQueryStream(response, direction, refresh = false) {
|
|
@@ -23277,7 +24332,8 @@ class GlobalPinnedPostQueryStreamController extends QueryStreamController {
|
|
|
23277
24332
|
const client = getActiveClient();
|
|
23278
24333
|
const cachedAt = client.cache && Date.now();
|
|
23279
24334
|
if (client.cache) {
|
|
23280
|
-
|
|
24335
|
+
const processedPayload = Object.assign(Object.assign({}, response), { users: response.users.map(convertRawUserToInternalUser) });
|
|
24336
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
23281
24337
|
}
|
|
23282
24338
|
}
|
|
23283
24339
|
appendToQueryStream(response, direction, refresh = false) {
|
|
@@ -23629,7 +24685,7 @@ const semanticSearchPosts = (params, callback, config) => {
|
|
|
23629
24685
|
};
|
|
23630
24686
|
};
|
|
23631
24687
|
|
|
23632
|
-
var index$
|
|
24688
|
+
var index$7 = /*#__PURE__*/Object.freeze({
|
|
23633
24689
|
__proto__: null,
|
|
23634
24690
|
getPostByIds: getPostByIds,
|
|
23635
24691
|
createPost: createPost,
|
|
@@ -24163,7 +25219,7 @@ const getStreams = (params, callback, config) => {
|
|
|
24163
25219
|
};
|
|
24164
25220
|
};
|
|
24165
25221
|
|
|
24166
|
-
var index$
|
|
25222
|
+
var index$6 = /*#__PURE__*/Object.freeze({
|
|
24167
25223
|
__proto__: null,
|
|
24168
25224
|
createStream: createStream,
|
|
24169
25225
|
updateStream: updateStream,
|
|
@@ -24450,7 +25506,7 @@ const getPoll = (pollId, callback) => {
|
|
|
24450
25506
|
};
|
|
24451
25507
|
/* end_public_function */
|
|
24452
25508
|
|
|
24453
|
-
var index$
|
|
25509
|
+
var index$5 = /*#__PURE__*/Object.freeze({
|
|
24454
25510
|
__proto__: null,
|
|
24455
25511
|
createPoll: createPoll,
|
|
24456
25512
|
closePoll: closePoll,
|
|
@@ -24461,7 +25517,7 @@ var index$4 = /*#__PURE__*/Object.freeze({
|
|
|
24461
25517
|
getPoll: getPoll
|
|
24462
25518
|
});
|
|
24463
25519
|
|
|
24464
|
-
const privateKey = "-----BEGIN PRIVATE KEY-----\
|
|
25520
|
+
const privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDAARz+hmBgi8pJ\nQb8LeY41gtHhk+ACMwRfhsn7GqpqRQNG2qU0755mzZuVDUqjQMGSo8THJB7O+OJs\nflbZRkFXlFoFOVNw1UpNOgwEQZ6wB9oRwzepTJAfF1sVhm/o/ixvXh1zDFNDy6yZ\npXyiiJHUVxqyjllZhxnwdvjoVtDs6hW6awG09bB9nh/TTejlUKXoAgzqVwu/1QMu\nUVViET495elEe19aUarEy+oL2iKeXCEvqda/pWNBdbieFyJvvZ08HN8dPuT88wq2\njZLEAth1vrwQ2IAa4ktaLcBQdLJgIkrbDvAiVZ8lQAjS/bq5vXQikTGvoPlC5bbn\nvuOM/3eLAgMBAAECggEAVZ+peHAghq2QVj71nX5lxsNCKaCyYwixSJBpfouTt7Rz\nE6PpzMOXFi1W1o+I22jDakuSM2SOQKqI/u0QefB0r0O/KVk5NrZHXk0mkrdYtxOp\nUgaGyf8UvmjB+8VqHrNKyZdk9qtmbnNj01kTTcAtmE4H39zPR7eR/8Rul94vaZbs\nwCnKJS3mLT3JxyGug6lxanveKkjG+CKC1nJQYWaxCJxaFSzbwXQPvDhB+TvrIbee\npd5v4EAyEJohpr+T9oDGGJkb/KARBZCtwLyB976PKJwwBA8MRVL1i5QwawuMiMq5\nUtnOnbGKtCeFzaLbNU0Qi8bqyims84EQxC6DOu1fkQKBgQDdvsoBsEhsOXV7hlIJ\naEd0eSJZVkdqimxH8uGoMM2FeNaOrcB6yBXqTSP0R3OIyf8eaY6yjRvP30ZNXcll\n/gD3O1Mu6YmWQdt1W2WA6pKOsUuPXasf0pdOF7IiFZKlSabz5YHXFqwVuqm8loaj\nsXel3YWqPVdHiankE7tz+3ssnQKBgQDdqi4TNdD1MdEpihx19jr0QjUiXW3939FK\nqp30HESPEGDGQzXdmJgif9HhZb+cJSuWaHEbjgBrYahvgCF+y6LbEpOD+D/dmT+s\nDEAQaR84sah6dokwPjV8fjBSrcVFjCS+doxv0d3p/9OUEeyUhFrY03nxtIEYkLIE\n/Zvn37b4RwKBgQCLENVFe9XfsaVhQ5r9dV2iyTlmh7qgMZG5CbTFs12hQGhm8McO\n+Z7s41YSJCFr/yq1WwP4LJDtrBw99vyQr1zRsG35tNLp3gGRNzGQSQyC2uQFVHw2\np+7mNewsfhUK/gbrXNsyFnDz6635rPlhfbII3sWuP2wWXFqkxE9CbMwR7QKBgQC6\nawDMzxmo2/iYArrkyevSuEuPVxvFwpF1RgAI6C0QVCnPE38dmdN4UB7mfHekje4W\nVEercMURidPp0cxZolCYBQtilUjAyL0vqC3In1/Ogjq6oy3FEMxSop1pKxMY5j+Q\nnoqFD+6deLUrddeNH7J3X4LSr4dSbX4JjG+tlgt+yQKBgQCuwTL4hA6KqeInQ0Ta\n9VQX5Qr8hFlqJz1gpymi/k63tW/Ob8yedbg3WWNWyShwRMFYyY9S81ITFWM95uL6\nvF3x9rmRjwElJw9PMwVu6dmf/CO0Z1wzXSp2VVD12gbrUD/0/d7MUoJ9LgC8X8f/\nn0txLHYGHbx+nf95+JUg6lV3hg==\n-----END PRIVATE KEY-----";
|
|
24465
25521
|
/*
|
|
24466
25522
|
* The crypto algorithm used for importing key and signing string
|
|
24467
25523
|
*/
|
|
@@ -24821,7 +25877,7 @@ const getPlayer = async (parameters) => {
|
|
|
24821
25877
|
return video;
|
|
24822
25878
|
};
|
|
24823
25879
|
|
|
24824
|
-
var index$
|
|
25880
|
+
var index$4 = /*#__PURE__*/Object.freeze({
|
|
24825
25881
|
__proto__: null,
|
|
24826
25882
|
getPlayer: getPlayer
|
|
24827
25883
|
});
|
|
@@ -25994,7 +27050,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
|
|
|
25994
27050
|
};
|
|
25995
27051
|
};
|
|
25996
27052
|
|
|
25997
|
-
var index$
|
|
27053
|
+
var index$3 = /*#__PURE__*/Object.freeze({
|
|
25998
27054
|
__proto__: null,
|
|
25999
27055
|
createImageStory: createImageStory,
|
|
26000
27056
|
createVideoStory: createVideoStory,
|
|
@@ -26031,7 +27087,7 @@ const getNetworkAds = async () => {
|
|
|
26031
27087
|
};
|
|
26032
27088
|
};
|
|
26033
27089
|
|
|
26034
|
-
var index$
|
|
27090
|
+
var index$2 = /*#__PURE__*/Object.freeze({
|
|
26035
27091
|
__proto__: null,
|
|
26036
27092
|
getNetworkAds: getNetworkAds
|
|
26037
27093
|
});
|
|
@@ -26422,7 +27478,7 @@ const markTraySeen = async (lastSeenAt) => {
|
|
|
26422
27478
|
};
|
|
26423
27479
|
/* end_public_function */
|
|
26424
27480
|
|
|
26425
|
-
var index = /*#__PURE__*/Object.freeze({
|
|
27481
|
+
var index$1 = /*#__PURE__*/Object.freeze({
|
|
26426
27482
|
__proto__: null,
|
|
26427
27483
|
getNotificationTraySeen: getNotificationTraySeen,
|
|
26428
27484
|
getNotificationTrayItems: getNotificationTrayItems,
|
|
@@ -26431,31 +27487,232 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
26431
27487
|
onNotificationTraySeenUpdated: onNotificationTraySeenUpdated
|
|
26432
27488
|
});
|
|
26433
27489
|
|
|
27490
|
+
class MyInvitationsPaginationController extends PaginationController {
|
|
27491
|
+
async getRequest(queryParams, token) {
|
|
27492
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
27493
|
+
const options = token ? { token } : { limit };
|
|
27494
|
+
const { data } = await this.http.get('/api/v1/invitations/me', { params: Object.assign(Object.assign({}, params), { options }) });
|
|
27495
|
+
await getCommunities$1(data.invitations.map(invitation => invitation.targetId));
|
|
27496
|
+
return data;
|
|
27497
|
+
}
|
|
27498
|
+
}
|
|
27499
|
+
|
|
27500
|
+
class MyInvitationsQueryStreamController extends QueryStreamController {
|
|
27501
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
27502
|
+
super(query, cacheKey);
|
|
27503
|
+
this.notifyChange = notifyChange;
|
|
27504
|
+
this.preparePayload = preparePayload;
|
|
27505
|
+
}
|
|
27506
|
+
async saveToMainDB(response) {
|
|
27507
|
+
const processedPayload = await this.preparePayload(response);
|
|
27508
|
+
const client = getActiveClient();
|
|
27509
|
+
const cachedAt = client.cache && Date.now();
|
|
27510
|
+
if (client.cache) {
|
|
27511
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
27512
|
+
}
|
|
27513
|
+
}
|
|
27514
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
27515
|
+
var _a, _b;
|
|
27516
|
+
if (refresh) {
|
|
27517
|
+
pushToCache(this.cacheKey, {
|
|
27518
|
+
data: response.invitations.map(getResolver('invitation')),
|
|
27519
|
+
});
|
|
27520
|
+
}
|
|
27521
|
+
else {
|
|
27522
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27523
|
+
const invitations = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
27524
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
27525
|
+
...new Set([...invitations, ...response.invitations.map(getResolver('invitation'))]),
|
|
27526
|
+
] }));
|
|
27527
|
+
}
|
|
27528
|
+
}
|
|
27529
|
+
reactor(action) {
|
|
27530
|
+
return (invitations) => {
|
|
27531
|
+
var _a;
|
|
27532
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27533
|
+
if (!collection)
|
|
27534
|
+
return;
|
|
27535
|
+
if (action === InvitationActionsEnum.OnLocalInvitationUpdated) {
|
|
27536
|
+
const isExist = collection.data.find(id => id === invitations[0].invitationId);
|
|
27537
|
+
if (!isExist)
|
|
27538
|
+
return;
|
|
27539
|
+
}
|
|
27540
|
+
if (action === InvitationActionsEnum.OnLocalInvitationCreated) {
|
|
27541
|
+
const client = getActiveClient();
|
|
27542
|
+
const myInvitations = invitations.filter(invitation => invitation.invitedUserId === client.userId);
|
|
27543
|
+
collection.data = [
|
|
27544
|
+
...new Set([
|
|
27545
|
+
...myInvitations.map(invitation => invitation.invitationId),
|
|
27546
|
+
...collection.data,
|
|
27547
|
+
]),
|
|
27548
|
+
];
|
|
27549
|
+
}
|
|
27550
|
+
if (action === InvitationActionsEnum.OnLocalInvitationDeleted) {
|
|
27551
|
+
collection.data = collection.data.filter(id => id !== invitations[0].invitationId);
|
|
27552
|
+
}
|
|
27553
|
+
pushToCache(this.cacheKey, collection);
|
|
27554
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
27555
|
+
};
|
|
27556
|
+
}
|
|
27557
|
+
subscribeRTE(createSubscriber) {
|
|
27558
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
27559
|
+
}
|
|
27560
|
+
}
|
|
27561
|
+
|
|
27562
|
+
class MyInvitationsLiveCollectionController extends LiveCollectionController {
|
|
27563
|
+
constructor(query, callback) {
|
|
27564
|
+
const queryStreamId = hash__default["default"](query);
|
|
27565
|
+
const cacheKey = ['invitation', 'collection', queryStreamId];
|
|
27566
|
+
const paginationController = new MyInvitationsPaginationController(query);
|
|
27567
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
27568
|
+
this.query = query;
|
|
27569
|
+
this.queryStreamController = new MyInvitationsQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareMyInvitationsPayload);
|
|
27570
|
+
this.callback = callback.bind(this);
|
|
27571
|
+
this.loadPage({ initial: true });
|
|
27572
|
+
}
|
|
27573
|
+
setup() {
|
|
27574
|
+
var _a;
|
|
27575
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27576
|
+
if (!collection) {
|
|
27577
|
+
pushToCache(this.cacheKey, {
|
|
27578
|
+
data: [],
|
|
27579
|
+
params: this.query,
|
|
27580
|
+
});
|
|
27581
|
+
}
|
|
27582
|
+
}
|
|
27583
|
+
async persistModel(queryPayload) {
|
|
27584
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
27585
|
+
}
|
|
27586
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
27587
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
27588
|
+
}
|
|
27589
|
+
startSubscription() {
|
|
27590
|
+
return this.queryStreamController.subscribeRTE([
|
|
27591
|
+
{
|
|
27592
|
+
fn: onLocalInvitationCreated,
|
|
27593
|
+
action: InvitationActionsEnum.OnLocalInvitationCreated,
|
|
27594
|
+
},
|
|
27595
|
+
{
|
|
27596
|
+
fn: onLocalInvitationUpdated,
|
|
27597
|
+
action: InvitationActionsEnum.OnLocalInvitationUpdated,
|
|
27598
|
+
},
|
|
27599
|
+
{
|
|
27600
|
+
fn: onLocalInvitationDeleted,
|
|
27601
|
+
action: InvitationActionsEnum.OnLocalInvitationDeleted,
|
|
27602
|
+
},
|
|
27603
|
+
]);
|
|
27604
|
+
}
|
|
27605
|
+
notifyChange({ origin, loading, error }) {
|
|
27606
|
+
var _a, _b;
|
|
27607
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27608
|
+
if (!collection)
|
|
27609
|
+
return;
|
|
27610
|
+
const data = this.applyFilter((_b = collection.data
|
|
27611
|
+
.map(id => pullFromCache(['invitation', 'get', id]))
|
|
27612
|
+
.filter(isNonNullable)
|
|
27613
|
+
.map(({ data }) => invitationLinkedObject(data))) !== null && _b !== void 0 ? _b : []);
|
|
27614
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
27615
|
+
return;
|
|
27616
|
+
this.callback({
|
|
27617
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
27618
|
+
data,
|
|
27619
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
27620
|
+
loading,
|
|
27621
|
+
error,
|
|
27622
|
+
});
|
|
27623
|
+
}
|
|
27624
|
+
applyFilter(data) {
|
|
27625
|
+
let invitations = data;
|
|
27626
|
+
if (this.query.targetId) {
|
|
27627
|
+
invitations = invitations.filter(invitation => invitation.targetId === this.query.targetId);
|
|
27628
|
+
}
|
|
27629
|
+
if (this.query.statuses) {
|
|
27630
|
+
invitations = invitations.filter(invitation => { var _a; return (_a = this.query.statuses) === null || _a === void 0 ? void 0 : _a.includes(invitation.status); });
|
|
27631
|
+
}
|
|
27632
|
+
if (this.query.targetType) {
|
|
27633
|
+
invitations = invitations.filter(invitation => invitation.targetType === this.query.targetType);
|
|
27634
|
+
}
|
|
27635
|
+
if (this.query.type) {
|
|
27636
|
+
invitations = invitations.filter(invitation => invitation.type === this.query.type);
|
|
27637
|
+
}
|
|
27638
|
+
const sortFn = (() => {
|
|
27639
|
+
switch (this.query.sortBy) {
|
|
27640
|
+
case 'firstCreated':
|
|
27641
|
+
return sortByFirstCreated;
|
|
27642
|
+
case 'lastCreated':
|
|
27643
|
+
return sortByLastCreated;
|
|
27644
|
+
default:
|
|
27645
|
+
return sortByLastCreated;
|
|
27646
|
+
}
|
|
27647
|
+
})();
|
|
27648
|
+
invitations = invitations.sort(sortFn);
|
|
27649
|
+
return invitations;
|
|
27650
|
+
}
|
|
27651
|
+
}
|
|
27652
|
+
|
|
27653
|
+
/**
|
|
27654
|
+
* Get my community invitations
|
|
27655
|
+
*
|
|
27656
|
+
* @param params the query parameters
|
|
27657
|
+
* @param callback the callback to be called when the invitations are fetched
|
|
27658
|
+
* @returns invitations
|
|
27659
|
+
*
|
|
27660
|
+
* @category My Community Invitations Live Collection
|
|
27661
|
+
*
|
|
27662
|
+
*/
|
|
27663
|
+
const getMyCommunityInvitations = (params, callback, config) => {
|
|
27664
|
+
const { log, cache } = getActiveClient();
|
|
27665
|
+
if (!cache) {
|
|
27666
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
27667
|
+
}
|
|
27668
|
+
const timestamp = Date.now();
|
|
27669
|
+
log(`getMyCommunityInvitations: (tmpid: ${timestamp}) > listen`);
|
|
27670
|
+
const invitationsLiveCollection = new MyInvitationsLiveCollectionController(Object.assign(Object.assign({}, params), { targetType: 'community', statuses: ["pending" /* InvitationStatusEnum.Pending */] }), callback);
|
|
27671
|
+
const disposers = invitationsLiveCollection.startSubscription();
|
|
27672
|
+
const cacheKey = invitationsLiveCollection.getCacheKey();
|
|
27673
|
+
disposers.push(() => {
|
|
27674
|
+
dropFromCache(cacheKey);
|
|
27675
|
+
});
|
|
27676
|
+
return () => {
|
|
27677
|
+
log(`getInvitations (tmpid: ${timestamp}) > dispose`);
|
|
27678
|
+
disposers.forEach(fn => fn());
|
|
27679
|
+
};
|
|
27680
|
+
};
|
|
27681
|
+
|
|
27682
|
+
var index = /*#__PURE__*/Object.freeze({
|
|
27683
|
+
__proto__: null,
|
|
27684
|
+
onLocalInvitationCreated: onLocalInvitationCreated,
|
|
27685
|
+
onLocalInvitationUpdated: onLocalInvitationUpdated,
|
|
27686
|
+
onLocalInvitationDeleted: onLocalInvitationDeleted,
|
|
27687
|
+
getMyCommunityInvitations: getMyCommunityInvitations
|
|
27688
|
+
});
|
|
27689
|
+
|
|
26434
27690
|
exports.API_REGIONS = API_REGIONS;
|
|
26435
|
-
exports.AdRepository = index$
|
|
26436
|
-
exports.CategoryRepository = index$
|
|
26437
|
-
exports.ChannelRepository = index$
|
|
26438
|
-
exports.Client = index$
|
|
26439
|
-
exports.CommentRepository = index$
|
|
27691
|
+
exports.AdRepository = index$2;
|
|
27692
|
+
exports.CategoryRepository = index$a;
|
|
27693
|
+
exports.ChannelRepository = index$e;
|
|
27694
|
+
exports.Client = index$n;
|
|
27695
|
+
exports.CommentRepository = index$8;
|
|
26440
27696
|
exports.CommunityPostSettingMaps = CommunityPostSettingMaps;
|
|
26441
27697
|
exports.CommunityPostSettings = CommunityPostSettings;
|
|
26442
|
-
exports.CommunityRepository = index$
|
|
27698
|
+
exports.CommunityRepository = index$b;
|
|
26443
27699
|
exports.ContentFeedType = ContentFeedType;
|
|
26444
27700
|
exports.DefaultCommunityPostSetting = DefaultCommunityPostSetting;
|
|
26445
|
-
exports.FeedRepository = index$
|
|
26446
|
-
exports.FileRepository = index$
|
|
27701
|
+
exports.FeedRepository = index$9;
|
|
27702
|
+
exports.FileRepository = index$k;
|
|
26447
27703
|
exports.FileType = FileType;
|
|
26448
|
-
exports.
|
|
27704
|
+
exports.InvitationRepository = index;
|
|
27705
|
+
exports.LiveStreamPlayer = index$4;
|
|
26449
27706
|
exports.MessageContentType = MessageContentType;
|
|
26450
|
-
exports.MessageRepository = index$
|
|
26451
|
-
exports.PollRepository = index$
|
|
27707
|
+
exports.MessageRepository = index$i;
|
|
27708
|
+
exports.PollRepository = index$5;
|
|
26452
27709
|
exports.PostContentType = PostContentType;
|
|
26453
|
-
exports.PostRepository = index$
|
|
26454
|
-
exports.ReactionRepository = index$
|
|
26455
|
-
exports.StoryRepository = index$
|
|
26456
|
-
exports.StreamRepository = index$
|
|
26457
|
-
exports.SubChannelRepository = index$
|
|
26458
|
-
exports.UserRepository = index$
|
|
27710
|
+
exports.PostRepository = index$7;
|
|
27711
|
+
exports.ReactionRepository = index$j;
|
|
27712
|
+
exports.StoryRepository = index$3;
|
|
27713
|
+
exports.StreamRepository = index$6;
|
|
27714
|
+
exports.SubChannelRepository = index$h;
|
|
27715
|
+
exports.UserRepository = index$l;
|
|
26459
27716
|
exports.VERSION = VERSION;
|
|
26460
27717
|
exports.VideoResolution = VideoResolution;
|
|
26461
27718
|
exports.VideoSize = VideoSize;
|
|
@@ -26508,7 +27765,7 @@ exports.isPaged = isPaged;
|
|
|
26508
27765
|
exports.isReportedByMe = isReportedByMe;
|
|
26509
27766
|
exports.isSkip = isSkip;
|
|
26510
27767
|
exports.mergeInCache = mergeInCache;
|
|
26511
|
-
exports.notificationTray = index;
|
|
27768
|
+
exports.notificationTray = index$1;
|
|
26512
27769
|
exports.onChannelMarkerFetched = onChannelMarkerFetched;
|
|
26513
27770
|
exports.onFeedMarkerFetched = onFeedMarkerFetched;
|
|
26514
27771
|
exports.onFeedMarkerUpdated = onFeedMarkerUpdated;
|