@amityco/ts-sdk 6.35.0 → 6.35.1-7a52b14.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 +6 -6
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/domains/analytics.d.ts +0 -3
- package/dist/@types/domains/analytics.d.ts.map +1 -1
- package/dist/@types/domains/channel.d.ts +9 -33
- package/dist/@types/domains/channel.d.ts.map +1 -1
- package/dist/@types/domains/client.d.ts +0 -4
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/@types/domains/community.d.ts +0 -6
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/@types/domains/feed.d.ts +0 -11
- package/dist/@types/domains/feed.d.ts.map +1 -1
- package/dist/@types/domains/message.d.ts +0 -12
- package/dist/@types/domains/message.d.ts.map +1 -1
- package/dist/@types/domains/subChannel.d.ts +0 -4
- package/dist/@types/domains/subChannel.d.ts.map +1 -1
- package/dist/@types/domains/user.d.ts +0 -3
- package/dist/@types/domains/user.d.ts.map +1 -1
- package/dist/channelRepository/api/deleteChannel.d.ts.map +1 -1
- package/dist/channelRepository/api/index.d.ts +0 -1
- package/dist/channelRepository/api/index.d.ts.map +1 -1
- package/dist/channelRepository/channelMembership/observers/getMembers/ChannelMemberLiveCollectionController.d.ts.map +1 -1
- package/dist/channelRepository/channelMembership/observers/getMembers/getMembers.d.ts.map +1 -1
- package/dist/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberLiveCollectionController.d.ts.map +1 -1
- package/dist/channelRepository/channelMembership/observers/searchMembers/searchMembers.d.ts.map +1 -1
- package/dist/channelRepository/{api → internalApi}/getChannel.d.ts +2 -2
- package/dist/channelRepository/internalApi/getChannel.d.ts.map +1 -0
- package/dist/channelRepository/internalApi/getChannelByIds.d.ts +32 -0
- package/dist/channelRepository/internalApi/getChannelByIds.d.ts.map +1 -0
- package/dist/channelRepository/{api → internalApi}/markAsRead.d.ts +0 -3
- package/dist/channelRepository/internalApi/markAsRead.d.ts.map +1 -0
- package/dist/channelRepository/observers/getChannel.d.ts.map +1 -1
- package/dist/channelRepository/observers/getChannels/ChannelLiveCollectionController.d.ts.map +1 -1
- package/dist/channelRepository/observers/index.d.ts +0 -2
- package/dist/channelRepository/observers/index.d.ts.map +1 -1
- package/dist/channelRepository/utils/constructChannelDynamicValue.d.ts.map +1 -1
- package/dist/channelRepository/utils/constructChannelObject.d.ts +2 -0
- package/dist/channelRepository/utils/constructChannelObject.d.ts.map +1 -0
- package/dist/channelRepository/utils/getChannelIsMentioned.d.ts +1 -1
- package/dist/channelRepository/utils/getChannelIsMentioned.d.ts.map +1 -1
- package/dist/channelRepository/utils/getSubChannelsUnreadCount.d.ts +1 -1
- package/dist/channelRepository/utils/getSubChannelsUnreadCount.d.ts.map +1 -1
- package/dist/channelRepository/utils/resolveChannels.d.ts.map +1 -1
- package/dist/client/observers/index.d.ts +0 -1
- package/dist/client/observers/index.d.ts.map +1 -1
- package/dist/client/utils/endpoints.d.ts +1 -1
- package/dist/client/utils/markerSyncEngine.d.ts +0 -4
- package/dist/client/utils/markerSyncEngine.d.ts.map +1 -1
- package/dist/client/utils/subscribeGlobalTopic.d.ts.map +1 -1
- package/dist/commentRepository/observers/index.d.ts +0 -2
- package/dist/commentRepository/observers/index.d.ts.map +1 -1
- package/dist/communityRepository/api/index.d.ts +0 -1
- package/dist/communityRepository/api/index.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersLiveCollectionController.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/observers/getMembers.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersPaginationController.d.ts +1 -1
- package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersPaginationController.d.ts.map +1 -1
- package/dist/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.d.ts.map +1 -1
- package/dist/communityRepository/observers/getCommunities/CommunitiesPaginationController.d.ts.map +1 -1
- package/dist/communityRepository/observers/getCommunities/CommunitiesQueryStreamController.d.ts.map +1 -1
- package/dist/communityRepository/observers/index.d.ts +0 -1
- package/dist/communityRepository/observers/index.d.ts.map +1 -1
- package/dist/communityRepository/observers/searchCommunities.d.ts +1 -1
- package/dist/communityRepository/observers/searchCommunities.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/subscription.d.ts +1 -0
- package/dist/core/subscription.d.ts.map +1 -1
- package/dist/feedRepository/api/getCustomRankingGlobalFeed.d.ts +2 -35
- package/dist/feedRepository/api/getCustomRankingGlobalFeed.d.ts.map +1 -1
- package/dist/feedRepository/api/queryGlobalFeed.d.ts +2 -24
- package/dist/feedRepository/api/queryGlobalFeed.d.ts.map +1 -1
- package/dist/feedRepository/internalApi/queryGlobalFeed.d.ts +0 -1
- package/dist/feedRepository/internalApi/queryGlobalFeed.d.ts.map +1 -1
- package/dist/fileRepository/api/index.d.ts +0 -3
- package/dist/fileRepository/api/index.d.ts.map +1 -1
- package/dist/fileRepository/index.d.ts +0 -1
- package/dist/fileRepository/index.d.ts.map +1 -1
- package/dist/index.cjs.js +1350 -2885
- package/dist/index.esm.js +1070 -2606
- package/dist/index.umd.js +4 -4
- package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts +1 -5
- package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts.map +1 -1
- package/dist/messagePreview/utils/getSubChannelMessagePreviewWithUser.d.ts +0 -1
- package/dist/messagePreview/utils/getSubChannelMessagePreviewWithUser.d.ts.map +1 -1
- package/dist/messageRepository/api/index.d.ts +0 -1
- package/dist/messageRepository/api/index.d.ts.map +1 -1
- package/dist/messageRepository/internalApi/getMessage.d.ts.map +1 -1
- package/dist/messageRepository/observers/getMessages/MessageLiveCollectionController.d.ts.map +1 -1
- package/dist/messageRepository/observers/getMessages/MessageQueryStreamController.d.ts.map +1 -1
- package/dist/messageRepository/observers/getMessages/getMessages.d.ts.map +1 -1
- package/dist/messageRepository/observers/index.d.ts +0 -2
- package/dist/messageRepository/observers/index.d.ts.map +1 -1
- package/dist/messageRepository/utils/prepareMessagePayload.d.ts +1 -1
- package/dist/messageRepository/utils/prepareMessagePayload.d.ts.map +1 -1
- package/dist/pollRepository/observers/index.d.ts +0 -1
- package/dist/pollRepository/observers/index.d.ts.map +1 -1
- package/dist/postRepository/api/index.d.ts +0 -1
- package/dist/postRepository/api/index.d.ts.map +1 -1
- package/dist/postRepository/observers/index.d.ts +0 -2
- package/dist/postRepository/observers/index.d.ts.map +1 -1
- package/dist/role/api/queryRoles.d.ts +0 -7
- package/dist/role/api/queryRoles.d.ts.map +1 -1
- package/dist/streamRepository/api/index.d.ts +0 -2
- package/dist/streamRepository/api/index.d.ts.map +1 -1
- package/dist/streamRepository/events/onStreamFlagged.d.ts.map +1 -1
- package/dist/streamRepository/internalApi/getStream.d.ts.map +1 -0
- package/dist/subChannelRepository/utils/markReadEngine.d.ts +0 -34
- package/dist/subChannelRepository/utils/markReadEngine.d.ts.map +1 -1
- package/dist/userRepository/observers/getUsers/UserLiveCollectionController.d.ts.map +1 -1
- package/dist/userRepository/observers/getUsers/UserPaginationController.d.ts.map +1 -1
- package/dist/userRepository/observers/index.d.ts +0 -2
- package/dist/userRepository/observers/index.d.ts.map +1 -1
- package/dist/userRepository/relationship/block/index.d.ts +0 -1
- package/dist/userRepository/relationship/block/index.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/api/index.d.ts +0 -2
- package/dist/userRepository/relationship/follow/api/index.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/observers/index.d.ts +0 -3
- package/dist/userRepository/relationship/follow/observers/index.d.ts.map +1 -1
- package/dist/utils/liveObject.d.ts +1 -1
- package/package.json +1 -1
- package/src/@types/core/events.ts +8 -9
- package/src/@types/domains/analytics.ts +0 -7
- package/src/@types/domains/channel.ts +15 -46
- package/src/@types/domains/client.ts +0 -4
- package/src/@types/domains/community.ts +0 -6
- package/src/@types/domains/feed.ts +0 -11
- package/src/@types/domains/message.ts +0 -12
- package/src/@types/domains/subChannel.ts +0 -4
- package/src/@types/domains/user.ts +0 -3
- package/src/analytic/api/queryReachUser.ts +1 -1
- package/src/channelRepository/api/deleteChannel.ts +3 -2
- package/src/channelRepository/api/index.ts +0 -2
- package/src/channelRepository/channelMembership/observers/getMembers/ChannelMemberLiveCollectionController.ts +0 -8
- package/src/channelRepository/channelMembership/observers/getMembers/getMembers.ts +0 -8
- package/src/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberLiveCollectionController.ts +0 -8
- package/src/channelRepository/channelMembership/observers/searchMembers/searchMembers.ts +0 -8
- package/src/channelRepository/{api → internalApi}/getChannel.ts +4 -4
- package/src/channelRepository/internalApi/getChannelByIds.ts +107 -0
- package/src/channelRepository/{api → internalApi}/markAsRead.ts +0 -3
- package/src/channelRepository/observers/getChannel.ts +4 -3
- package/src/channelRepository/observers/getChannels/ChannelLiveCollectionController.ts +8 -3
- package/src/channelRepository/observers/index.ts +0 -2
- package/src/channelRepository/utils/constructChannelDynamicValue.ts +4 -9
- package/src/channelRepository/utils/constructChannelObject.ts +9 -0
- package/src/channelRepository/utils/getChannelIsMentioned.ts +4 -1
- package/src/channelRepository/utils/getSubChannelsUnreadCount.ts +1 -1
- package/src/channelRepository/utils/resolveChannels.ts +6 -1
- package/src/client/observers/getUserUnread.ts +1 -1
- package/src/client/observers/index.ts +0 -1
- package/src/client/utils/endpoints.ts +1 -1
- package/src/client/utils/markerSyncEngine.ts +0 -9
- package/src/client/utils/subscribeGlobalTopic.ts +3 -0
- package/src/commentRepository/observers/index.ts +0 -2
- package/src/communityRepository/api/index.ts +0 -3
- package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersLiveCollectionController.ts +0 -12
- package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.ts +0 -7
- package/src/communityRepository/communityMembership/observers/getMembers.ts +0 -4
- package/src/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersPaginationController.ts +1 -1
- package/src/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.ts +12 -16
- package/src/communityRepository/observers/getCommunities/CommunitiesPaginationController.ts +0 -1
- package/src/communityRepository/observers/getCommunities/CommunitiesQueryStreamController.ts +0 -4
- package/src/communityRepository/observers/index.ts +0 -2
- package/src/communityRepository/observers/searchCommunities.ts +1 -1
- package/src/core/events.ts +6 -4
- package/src/core/subscription.ts +6 -0
- package/src/feedRepository/api/getCustomRankingGlobalFeed.ts +9 -51
- package/src/feedRepository/api/queryGlobalFeed.ts +6 -58
- package/src/feedRepository/internalApi/queryGlobalFeed.ts +1 -10
- package/src/fileRepository/api/index.ts +0 -5
- package/src/fileRepository/index.ts +0 -1
- package/src/liveStreamPlayer/api/getPlayer.ts +1 -1
- package/src/messagePreview/utils/getChannelMessagePreviewWithUser.ts +2 -2
- package/src/messageRepository/api/createMessage.ts +1 -1
- package/src/messageRepository/api/index.ts +0 -2
- package/src/messageRepository/internalApi/getMessage.ts +0 -6
- package/src/messageRepository/observers/getMessages/MessageLiveCollectionController.ts +0 -20
- package/src/messageRepository/observers/getMessages/MessageQueryStreamController.ts +0 -10
- package/src/messageRepository/observers/getMessages/getMessages.ts +0 -20
- package/src/messageRepository/observers/index.ts +0 -3
- package/src/messageRepository/utils/prepareMessagePayload.ts +1 -7
- package/src/pollRepository/observers/index.ts +0 -1
- package/src/postRepository/api/index.ts +0 -1
- package/src/postRepository/observers/index.ts +0 -2
- package/src/role/api/queryRoles.ts +1 -13
- package/src/streamRepository/api/deleteStream.ts +1 -1
- package/src/streamRepository/api/index.ts +0 -4
- package/src/streamRepository/api/tests/getStream.test.ts +1 -1
- package/src/streamRepository/events/onStreamFlagged.ts +1 -6
- package/src/streamRepository/events/onStreamRecorded.ts +1 -1
- package/src/streamRepository/events/onStreamStarted.ts +1 -1
- package/src/streamRepository/events/onStreamStopped.ts +1 -1
- package/src/streamRepository/events/onStreamTerminated.ts +1 -1
- package/src/streamRepository/observers/getStreamById.ts +1 -1
- package/src/subChannelRepository/utils/markReadEngine.ts +0 -62
- package/src/userRepository/observers/getUsers/UserLiveCollectionController.ts +12 -16
- package/src/userRepository/observers/getUsers/UserPaginationController.ts +1 -2
- package/src/userRepository/observers/index.ts +0 -2
- package/src/userRepository/relationship/block/index.ts +0 -1
- package/src/userRepository/relationship/follow/api/index.ts +0 -4
- package/src/userRepository/relationship/follow/observers/index.ts +0 -4
- package/src/utils/linkedObject/channelLinkedObject.ts +1 -1
- package/src/utils/liveObject.ts +2 -2
- package/dist/channelRepository/api/getChannel.d.ts.map +0 -1
- package/dist/channelRepository/api/markAsRead.d.ts.map +0 -1
- package/dist/channelRepository/observers/observeChannel.d.ts +0 -18
- package/dist/channelRepository/observers/observeChannel.d.ts.map +0 -1
- package/dist/channelRepository/observers/observeChannels.d.ts +0 -17
- package/dist/channelRepository/observers/observeChannels.d.ts.map +0 -1
- package/dist/client/observers/getTotalUnreadCount.d.ts +0 -20
- package/dist/client/observers/getTotalUnreadCount.d.ts.map +0 -1
- package/dist/client/observers/tests/getTotalUnreadCount.test.d.ts +0 -2
- package/dist/client/observers/tests/getTotalUnreadCount.test.d.ts.map +0 -1
- package/dist/commentRepository/observers/observeComment.d.ts +0 -18
- package/dist/commentRepository/observers/observeComment.d.ts.map +0 -1
- package/dist/commentRepository/observers/observeComments.d.ts +0 -26
- package/dist/commentRepository/observers/observeComments.d.ts.map +0 -1
- package/dist/communityRepository/api/getTopTrendingCommunities.d.ts +0 -35
- package/dist/communityRepository/api/getTopTrendingCommunities.d.ts.map +0 -1
- package/dist/communityRepository/observers/observeCommunity.d.ts +0 -18
- package/dist/communityRepository/observers/observeCommunity.d.ts.map +0 -1
- package/dist/fileRepository/api/createFile.d.ts +0 -17
- package/dist/fileRepository/api/createFile.d.ts.map +0 -1
- package/dist/fileRepository/api/createImage.d.ts +0 -17
- package/dist/fileRepository/api/createImage.d.ts.map +0 -1
- package/dist/fileRepository/api/createVideo.d.ts +0 -18
- package/dist/fileRepository/api/createVideo.d.ts.map +0 -1
- package/dist/fileRepository/observers/index.d.ts +0 -2
- package/dist/fileRepository/observers/index.d.ts.map +0 -1
- package/dist/fileRepository/observers/observeFile.d.ts +0 -18
- package/dist/fileRepository/observers/observeFile.d.ts.map +0 -1
- package/dist/messageRepository/api/getMessage.d.ts +0 -32
- package/dist/messageRepository/api/getMessage.d.ts.map +0 -1
- package/dist/messageRepository/api/getMessages.d.ts +0 -32
- package/dist/messageRepository/api/getMessages.d.ts.map +0 -1
- package/dist/messageRepository/observers/observeMessage.d.ts +0 -21
- package/dist/messageRepository/observers/observeMessage.d.ts.map +0 -1
- package/dist/messageRepository/observers/observeMessages.d.ts +0 -23
- package/dist/messageRepository/observers/observeMessages.d.ts.map +0 -1
- package/dist/pollRepository/observers/observePoll.d.ts +0 -18
- package/dist/pollRepository/observers/observePoll.d.ts.map +0 -1
- package/dist/postRepository/api/updatePost.d.ts +0 -24
- package/dist/postRepository/api/updatePost.d.ts.map +0 -1
- package/dist/postRepository/observers/observePost.d.ts +0 -18
- package/dist/postRepository/observers/observePost.d.ts.map +0 -1
- package/dist/postRepository/observers/observePosts.d.ts +0 -34
- package/dist/postRepository/observers/observePosts.d.ts.map +0 -1
- package/dist/streamRepository/api/getStream.d.ts.map +0 -1
- package/dist/streamRepository/api/queryStreams.d.ts +0 -25
- package/dist/streamRepository/api/queryStreams.d.ts.map +0 -1
- package/dist/userRepository/observers/getViewedUsers.d.ts +0 -7
- package/dist/userRepository/observers/getViewedUsers.d.ts.map +0 -1
- package/dist/userRepository/observers/observeUser.d.ts +0 -17
- package/dist/userRepository/observers/observeUser.d.ts.map +0 -1
- package/dist/userRepository/observers/tests/getViewedUsers.test.d.ts +0 -2
- package/dist/userRepository/observers/tests/getViewedUsers.test.d.ts.map +0 -1
- package/dist/userRepository/relationship/block/observers/getBlockedUsers.d.ts +0 -2
- package/dist/userRepository/relationship/block/observers/getBlockedUsers.d.ts.map +0 -1
- package/dist/userRepository/relationship/block/observers/index.d.ts +0 -2
- package/dist/userRepository/relationship/block/observers/index.d.ts.map +0 -1
- package/dist/userRepository/relationship/follow/api/acceptFollower.d.ts +0 -19
- package/dist/userRepository/relationship/follow/api/acceptFollower.d.ts.map +0 -1
- package/dist/userRepository/relationship/follow/api/declineFollower.d.ts +0 -19
- package/dist/userRepository/relationship/follow/api/declineFollower.d.ts.map +0 -1
- package/dist/userRepository/relationship/follow/observers/observeFollowInfo.d.ts +0 -18
- package/dist/userRepository/relationship/follow/observers/observeFollowInfo.d.ts.map +0 -1
- package/dist/userRepository/relationship/follow/observers/observeFollowers.d.ts +0 -18
- package/dist/userRepository/relationship/follow/observers/observeFollowers.d.ts.map +0 -1
- package/dist/userRepository/relationship/follow/observers/observeFollowings.d.ts +0 -18
- package/dist/userRepository/relationship/follow/observers/observeFollowings.d.ts.map +0 -1
- package/src/channelRepository/observers/observeChannel.ts +0 -109
- package/src/channelRepository/observers/observeChannels.ts +0 -74
- package/src/client/observers/getTotalUnreadCount.ts +0 -53
- package/src/client/observers/tests/getTotalUnreadCount.test.ts +0 -101
- package/src/commentRepository/observers/observeComment.ts +0 -102
- package/src/commentRepository/observers/observeComments.ts +0 -77
- package/src/communityRepository/api/getTopTrendingCommunities.ts +0 -97
- package/src/communityRepository/observers/observeCommunity.ts +0 -103
- package/src/fileRepository/api/createFile.ts +0 -59
- package/src/fileRepository/api/createImage.ts +0 -59
- package/src/fileRepository/api/createVideo.ts +0 -69
- package/src/fileRepository/observers/index.ts +0 -1
- package/src/fileRepository/observers/observeFile.ts +0 -49
- package/src/messageRepository/api/getMessage.ts +0 -102
- package/src/messageRepository/api/getMessages.ts +0 -83
- package/src/messageRepository/observers/observeMessage.ts +0 -94
- package/src/messageRepository/observers/observeMessages.ts +0 -89
- package/src/pollRepository/observers/observePoll.ts +0 -67
- package/src/postRepository/api/updatePost.ts +0 -63
- package/src/postRepository/observers/observePost.ts +0 -115
- package/src/postRepository/observers/observePosts.ts +0 -86
- package/src/streamRepository/api/queryStreams.ts +0 -63
- package/src/userRepository/observers/getViewedUsers.ts +0 -99
- package/src/userRepository/observers/observeUser.ts +0 -71
- package/src/userRepository/observers/tests/getViewedUsers.test.ts +0 -39
- package/src/userRepository/relationship/block/observers/getBlockedUsers.ts +0 -13
- package/src/userRepository/relationship/block/observers/index.ts +0 -1
- package/src/userRepository/relationship/follow/api/acceptFollower.ts +0 -40
- package/src/userRepository/relationship/follow/api/declineFollower.ts +0 -40
- package/src/userRepository/relationship/follow/observers/observeFollowInfo.ts +0 -64
- package/src/userRepository/relationship/follow/observers/observeFollowers.ts +0 -74
- package/src/userRepository/relationship/follow/observers/observeFollowings.ts +0 -74
- /package/dist/streamRepository/{api → internalApi}/getStream.d.ts +0 -0
- /package/src/streamRepository/{api → internalApi}/getStream.ts +0 -0
package/dist/index.esm.js
CHANGED
|
@@ -1304,9 +1304,6 @@ const WS_EVENTS = [
|
|
|
1304
1304
|
'sessionStateChange',
|
|
1305
1305
|
// for internal use by accessTokenExpiryWatcher
|
|
1306
1306
|
'tokenExpired',
|
|
1307
|
-
'v3.video-streaming.didRecord',
|
|
1308
|
-
'v3.video-streaming.didStart',
|
|
1309
|
-
'v3.video-streaming.didStop',
|
|
1310
1307
|
];
|
|
1311
1308
|
const MQTT_EVENTS = [
|
|
1312
1309
|
'connect',
|
|
@@ -1316,6 +1313,11 @@ const MQTT_EVENTS = [
|
|
|
1316
1313
|
'close',
|
|
1317
1314
|
'end',
|
|
1318
1315
|
'reconnect',
|
|
1316
|
+
'video-streaming.didStart',
|
|
1317
|
+
'video-streaming.didRecord',
|
|
1318
|
+
'video-streaming.didStop',
|
|
1319
|
+
'video-streaming.didFlag',
|
|
1320
|
+
'video-streaming.didTerminate',
|
|
1319
1321
|
'user.didGlobalBan',
|
|
1320
1322
|
];
|
|
1321
1323
|
/** @hidden */
|
|
@@ -1515,7 +1517,11 @@ function subscribeTopic(topic, callback) {
|
|
|
1515
1517
|
return () => null;
|
|
1516
1518
|
modifyMqttConnection();
|
|
1517
1519
|
return mqtt.subscribe(topic, callback);
|
|
1518
|
-
}
|
|
1520
|
+
}
|
|
1521
|
+
const getLiveStreamTopic = () => {
|
|
1522
|
+
const user = getActiveUser();
|
|
1523
|
+
return `${getNetworkId(user)}/videostreaming`;
|
|
1524
|
+
};
|
|
1519
1525
|
|
|
1520
1526
|
var _a;
|
|
1521
1527
|
/* eslint-disable no-undef */
|
|
@@ -1551,7 +1557,7 @@ const API_REGIONS = {
|
|
|
1551
1557
|
US: 'us',
|
|
1552
1558
|
};
|
|
1553
1559
|
const URLS = {
|
|
1554
|
-
http: 'https://
|
|
1560
|
+
http: 'https://apix.{region}.amity.co',
|
|
1555
1561
|
mqtt: 'wss://sse.{region}.amity.co:443/mqtt',
|
|
1556
1562
|
};
|
|
1557
1563
|
function computeUrl(type, region) {
|
|
@@ -20460,6 +20466,7 @@ const subscribeGlobalTopic = () => {
|
|
|
20460
20466
|
// subscribing to user topic is necessary to handle ban event
|
|
20461
20467
|
subscribeTopic(getUserTopic(getActiveUser())),
|
|
20462
20468
|
subscribeTopic(getMarkerUserFeedTopic()),
|
|
20469
|
+
subscribeTopic(getLiveStreamTopic()),
|
|
20463
20470
|
];
|
|
20464
20471
|
return () => disposers.forEach(fn => fn());
|
|
20465
20472
|
};
|
|
@@ -21972,9 +21979,6 @@ const reactorLinkedObject = (reactor) => {
|
|
|
21972
21979
|
* import { ChannelRepository } from '@amityco/ts-sdk'
|
|
21973
21980
|
* const success = await ChannelRepository.markAsRead('channelId')
|
|
21974
21981
|
* ```
|
|
21975
|
-
*
|
|
21976
|
-
* @deprecated Please use the {@link Amity.Channel.markAsRead} method instead
|
|
21977
|
-
*
|
|
21978
21982
|
* Updating all {@link Amity.SubChannel} in specify {@link Amity.Channel} as read
|
|
21979
21983
|
*
|
|
21980
21984
|
* @param channelId the ID of to specify {@link Amity.Channel}
|
|
@@ -22591,18 +22595,13 @@ const getSubChannelsUnreadCount = (channel, marker) => {
|
|
|
22591
22595
|
};
|
|
22592
22596
|
|
|
22593
22597
|
const constructChannelDynamicValue = (channel) => {
|
|
22594
|
-
|
|
22595
|
-
|
|
22596
|
-
return getSubChannelsUnreadCount(channel);
|
|
22597
|
-
},
|
|
22598
|
-
get hasMentioned() {
|
|
22599
|
-
return getChannelIsMentioned(channel);
|
|
22600
|
-
},
|
|
22598
|
+
const rest = __rest(channel, ["messageCount"]);
|
|
22599
|
+
return shallowClone(rest, {
|
|
22601
22600
|
get isMentioned() {
|
|
22602
|
-
return getChannelIsMentioned(
|
|
22601
|
+
return getChannelIsMentioned(rest);
|
|
22603
22602
|
},
|
|
22604
22603
|
get subChannelsUnreadCount() {
|
|
22605
|
-
return getSubChannelsUnreadCount(
|
|
22604
|
+
return getSubChannelsUnreadCount(rest);
|
|
22606
22605
|
},
|
|
22607
22606
|
});
|
|
22608
22607
|
};
|
|
@@ -23007,7 +23006,7 @@ const prepareMessagePayload = async (payload, event) => {
|
|
|
23007
23006
|
var _a, _b;
|
|
23008
23007
|
const subChannelCache = (_b = (_a = pullFromCache(['subChannel', 'get', messageFeed.messageFeedId])) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : {};
|
|
23009
23008
|
// exclude getter properties from existing subChannel cache, update only other properties to existing subChannel cache
|
|
23010
|
-
const _c = convertFromRaw$1(messageFeed), restSubChannel = __rest(_c, ["unreadCount", "
|
|
23009
|
+
const _c = convertFromRaw$1(messageFeed), restSubChannel = __rest(_c, ["unreadCount", "isMentioned"]);
|
|
23011
23010
|
updateSubChannelCache(messageFeed.messageFeedId, subChannelCache, restSubChannel);
|
|
23012
23011
|
});
|
|
23013
23012
|
}
|
|
@@ -23021,15 +23020,12 @@ function convertParams(_a) {
|
|
|
23021
23020
|
return Object.assign({ messageFeedId: subChannelId, mentionedUsers: mentionees, dataType, data }, rest);
|
|
23022
23021
|
}
|
|
23023
23022
|
function convertQueryParams$1(_a) {
|
|
23024
|
-
var { sortBy, subChannelId,
|
|
23023
|
+
var { sortBy, subChannelId, includingTags, excludingTags, includeDeleted, aroundMessageId, limit, type } = _a, rest = __rest(_a, ["sortBy", "subChannelId", "includingTags", "excludingTags", "includeDeleted", "aroundMessageId", "limit", "type"]);
|
|
23025
23024
|
const out = Object.assign(Object.assign({}, rest), { messageFeedId: subChannelId, isDeleted: inferIsDeleted(includeDeleted), options: {
|
|
23026
23025
|
sortBy,
|
|
23027
23026
|
limit: limit || COLLECTION_DEFAULT_PAGINATION_LIMIT,
|
|
23028
23027
|
around: aroundMessageId,
|
|
23029
23028
|
} });
|
|
23030
|
-
if (tags) {
|
|
23031
|
-
out.includeTags = tags;
|
|
23032
|
-
}
|
|
23033
23029
|
if (includingTags) {
|
|
23034
23030
|
out.includeTags = includingTags;
|
|
23035
23031
|
}
|
|
@@ -23274,73 +23270,8 @@ const readingAPI = async (messageFeedIds) => {
|
|
|
23274
23270
|
return true;
|
|
23275
23271
|
};
|
|
23276
23272
|
|
|
23277
|
-
/**
|
|
23278
|
-
* ```js
|
|
23279
|
-
* import { SubChannel } from '@amityco/ts-sdk'
|
|
23280
|
-
* const success = await SubChannel('foo')
|
|
23281
|
-
* ```
|
|
23282
|
-
*
|
|
23283
|
-
* Mark all messages as read and start reading message inside channel
|
|
23284
|
-
*
|
|
23285
|
-
* @param messageFeedId - Sub channel ID to start reading.
|
|
23286
|
-
* @return A success boolean if reading of the sub channel had begun.
|
|
23287
|
-
*
|
|
23288
|
-
* @category Channel API
|
|
23289
|
-
* @async
|
|
23290
|
-
* @private
|
|
23291
|
-
*/
|
|
23292
|
-
const startReadingAPI = async (messageFeedId) => {
|
|
23293
|
-
const client = getActiveClient();
|
|
23294
|
-
client.log('subChannel/startReadingAPI', messageFeedId);
|
|
23295
|
-
const { data: payload } = await client.http.post(`/api/v1/markers/message-feeds/${messageFeedId}/start-reading`);
|
|
23296
|
-
const { userEntityMarkers: userEntityMarkersPayload, userFeedMarkers: userFeedMarkersPayload, feedMarkers, userMarkers, } = payload;
|
|
23297
|
-
const userEntityMarkers = convertChannelMarkerResponse(userEntityMarkersPayload);
|
|
23298
|
-
const userFeedMarkers = convertSubChannelMarkerResponse(userFeedMarkersPayload);
|
|
23299
|
-
const cachedAt = client.cache && Date.now();
|
|
23300
|
-
if (client.cache)
|
|
23301
|
-
ingestInCache({ userEntityMarkers, userFeedMarkers, feedMarkers, userMarkers }, { cachedAt });
|
|
23302
|
-
fireEvent('local.feedMarker.fetched', { feedMarkers });
|
|
23303
|
-
fireEvent('local.channelMarker.fetched', { userEntityMarkers });
|
|
23304
|
-
fireEvent('local.subChannelMarker.fetched', { userFeedMarkers });
|
|
23305
|
-
fireEvent('local.userMarker.fetched', { userMarkers });
|
|
23306
|
-
return true;
|
|
23307
|
-
};
|
|
23308
|
-
|
|
23309
|
-
/**
|
|
23310
|
-
* ```js
|
|
23311
|
-
* import { stopReading } from '@amityco/ts-sdk'
|
|
23312
|
-
* const success = await stopReading('foo')
|
|
23313
|
-
* ```
|
|
23314
|
-
*
|
|
23315
|
-
* Mark all messages as read and stop reading message inside channel
|
|
23316
|
-
*
|
|
23317
|
-
* @param messageFeedId - The sub channel ID to stop reading.
|
|
23318
|
-
* @return A success boolean if reading of the sub channel had begun.
|
|
23319
|
-
*
|
|
23320
|
-
* @category Channel API
|
|
23321
|
-
* @async
|
|
23322
|
-
* @private
|
|
23323
|
-
*/
|
|
23324
|
-
const stopReadingAPI = async (messageFeedId) => {
|
|
23325
|
-
const client = getActiveClient();
|
|
23326
|
-
client.log('channel/stopReadingAPI', messageFeedId);
|
|
23327
|
-
const { data: payload } = await client.http.post(`/api/v1/markers/message-feeds/${messageFeedId}/stop-reading`);
|
|
23328
|
-
const { userEntityMarkers: userEntityMarkersPayload, userFeedMarkers: userFeedMarkersPayload, feedMarkers, userMarkers, } = payload;
|
|
23329
|
-
const userEntityMarkers = convertChannelMarkerResponse(userEntityMarkersPayload);
|
|
23330
|
-
const userFeedMarkers = convertSubChannelMarkerResponse(userFeedMarkersPayload);
|
|
23331
|
-
const cachedAt = client.cache && Date.now();
|
|
23332
|
-
if (client.cache)
|
|
23333
|
-
ingestInCache({ userEntityMarkers, userFeedMarkers, feedMarkers, userMarkers }, { cachedAt });
|
|
23334
|
-
fireEvent('local.feedMarker.fetched', { feedMarkers });
|
|
23335
|
-
fireEvent('local.channelMarker.fetched', { userEntityMarkers });
|
|
23336
|
-
fireEvent('local.subChannelMarker.fetched', { userFeedMarkers });
|
|
23337
|
-
fireEvent('local.userMarker.fetched', { userMarkers });
|
|
23338
|
-
return true;
|
|
23339
|
-
};
|
|
23340
|
-
|
|
23341
23273
|
const START_READING_INTERVAL_TIME = 30000;
|
|
23342
23274
|
let isSyncRunning$1 = false;
|
|
23343
|
-
let disposers$2 = [];
|
|
23344
23275
|
/**
|
|
23345
23276
|
* map contains subChannelId and isReading flag to determine which subChannel is on reading state
|
|
23346
23277
|
*/
|
|
@@ -23384,91 +23315,6 @@ const markReadEngineOnLoginHandler = () => {
|
|
|
23384
23315
|
stopIntervalTask();
|
|
23385
23316
|
};
|
|
23386
23317
|
};
|
|
23387
|
-
const getParentChannelId$1 = async (subChannelId) => {
|
|
23388
|
-
const cached = getSubChannel$1.locally(subChannelId);
|
|
23389
|
-
if (cached) {
|
|
23390
|
-
return cached.data.channelId;
|
|
23391
|
-
}
|
|
23392
|
-
const { data } = await getSubChannel$1(subChannelId);
|
|
23393
|
-
return data.channelId;
|
|
23394
|
-
};
|
|
23395
|
-
const registerEventListeners$1 = () => {
|
|
23396
|
-
if (disposers$2.length > 0) {
|
|
23397
|
-
return;
|
|
23398
|
-
}
|
|
23399
|
-
disposers$2.push(onOnline(() => {
|
|
23400
|
-
// Start reading the reading subChannel again when resume from offline state
|
|
23401
|
-
startReadingFromReadingList();
|
|
23402
|
-
}));
|
|
23403
|
-
};
|
|
23404
|
-
const registerTopicSubscribers$1 = async (subChannelId) => {
|
|
23405
|
-
const channelId = await getParentChannelId$1(subChannelId);
|
|
23406
|
-
const markedMessageTopic = getMarkedMessageTopic({ channelId, subChannelId });
|
|
23407
|
-
disposers$2.push(subscribeTopic(markedMessageTopic));
|
|
23408
|
-
};
|
|
23409
|
-
const disposeAll = () => {
|
|
23410
|
-
disposers$2.forEach(fn => fn());
|
|
23411
|
-
disposers$2 = [];
|
|
23412
|
-
};
|
|
23413
|
-
/* begin_public_function
|
|
23414
|
-
id: subchannel.start_reading
|
|
23415
|
-
*/
|
|
23416
|
-
/**
|
|
23417
|
-
* @deprecated Use {@link startMessageReceiptSync} instead.
|
|
23418
|
-
* ```js
|
|
23419
|
-
* import { startReading } from '@amityco/ts-sdk'
|
|
23420
|
-
* const success = await startReading('foo')
|
|
23421
|
-
* ```
|
|
23422
|
-
*
|
|
23423
|
-
* Set local reading state of channel to `true` and then call mark all
|
|
23424
|
-
* messages as read API.
|
|
23425
|
-
*
|
|
23426
|
-
* @param subChannelId - The sub channel ID to start reading.
|
|
23427
|
-
* @return A success boolean if reading of the sub channel had begun.
|
|
23428
|
-
*
|
|
23429
|
-
* @category Channel API
|
|
23430
|
-
* @async
|
|
23431
|
-
*/
|
|
23432
|
-
const startReading = async (subChannelId) => {
|
|
23433
|
-
isReadingMap[subChannelId] = true;
|
|
23434
|
-
if (disposers$2.length === 0) {
|
|
23435
|
-
registerEventListeners$1();
|
|
23436
|
-
registerTopicSubscribers$1(subChannelId);
|
|
23437
|
-
}
|
|
23438
|
-
try {
|
|
23439
|
-
return await startReadingAPI(subChannelId);
|
|
23440
|
-
}
|
|
23441
|
-
catch (e) {
|
|
23442
|
-
isReadingMap[subChannelId] = false;
|
|
23443
|
-
return false;
|
|
23444
|
-
}
|
|
23445
|
-
};
|
|
23446
|
-
/* end_public_function */
|
|
23447
|
-
/* begin_public_function
|
|
23448
|
-
id: subchannel.stop_reading
|
|
23449
|
-
*/
|
|
23450
|
-
/**
|
|
23451
|
-
* @deprecated Use {@link stopMessageReceiptSync} instead.
|
|
23452
|
-
* ```js
|
|
23453
|
-
* import { stopReading } from '@amityco/ts-sdk'
|
|
23454
|
-
* const success = await stopReading('foo')
|
|
23455
|
-
* ```
|
|
23456
|
-
*
|
|
23457
|
-
* Set local reading state of channel to `false` and then call mark all
|
|
23458
|
-
* messages as unread API.
|
|
23459
|
-
*
|
|
23460
|
-
* @param subChannelId - The sub channel ID to stop reading.
|
|
23461
|
-
* @return A success boolean if reading of the sub channel had begun.
|
|
23462
|
-
*
|
|
23463
|
-
* @category Channel API
|
|
23464
|
-
* @async
|
|
23465
|
-
*/
|
|
23466
|
-
const stopReading = (subChannelId) => {
|
|
23467
|
-
isReadingMap[subChannelId] = false;
|
|
23468
|
-
disposeAll();
|
|
23469
|
-
return stopReadingAPI(subChannelId);
|
|
23470
|
-
};
|
|
23471
|
-
/* end_public_function */
|
|
23472
23318
|
setIntervalTask(async () => {
|
|
23473
23319
|
if (!isSyncRunning$1)
|
|
23474
23320
|
return;
|
|
@@ -24036,7 +23882,9 @@ const onOffline = (callback) => {
|
|
|
24036
23882
|
};
|
|
24037
23883
|
|
|
24038
23884
|
const resolveChannels = async (channelIds) => {
|
|
24039
|
-
|
|
23885
|
+
var _a, _b, _c;
|
|
23886
|
+
await getChannelByIds(channelIds);
|
|
23887
|
+
const channels = (_c = (_b = (_a = queryCache(['channel', 'get'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => data.channelPublicId && channelIds.includes(data.channelPublicId))) === null || _b === void 0 ? void 0 : _b.map(({ data }) => data)) !== null && _c !== void 0 ? _c : [];
|
|
24040
23888
|
fireEvent('local.channel.resolved', channels);
|
|
24041
23889
|
};
|
|
24042
23890
|
|
|
@@ -25164,13 +25012,6 @@ const stopUnreadSync = () => {
|
|
|
25164
25012
|
setMarkerSyncEvents([]);
|
|
25165
25013
|
unRegisterEventListeners();
|
|
25166
25014
|
};
|
|
25167
|
-
/**
|
|
25168
|
-
* @deprecated Please use `startUnreadSync` instead
|
|
25169
|
-
*/
|
|
25170
|
-
const stopUnreadSyncing = () => {
|
|
25171
|
-
console.warn('`stopUnreadSyncing` has been deprecated, please use `stopUnreadSync` instead');
|
|
25172
|
-
return stopUnreadSync();
|
|
25173
|
-
};
|
|
25174
25015
|
setIntervalTask(async () => {
|
|
25175
25016
|
if (!isSyncRunning)
|
|
25176
25017
|
return;
|
|
@@ -25868,100 +25709,6 @@ const removeFunctionProperties = (obj) => {
|
|
|
25868
25709
|
return Object.fromEntries(entries);
|
|
25869
25710
|
};
|
|
25870
25711
|
|
|
25871
|
-
/**
|
|
25872
|
-
* @deprecated This function is deprecated
|
|
25873
|
-
*/
|
|
25874
|
-
const liveObject = (id, callback, key, fetcher, eventHandlers, options) => {
|
|
25875
|
-
const { forceDispatch, callbackDataSelector, callbackFilter } = Object.assign({ forceDispatch: false, callbackDataSelector: (data) => data }, options);
|
|
25876
|
-
const { cache } = getActiveClient();
|
|
25877
|
-
if (!cache) {
|
|
25878
|
-
console.log(LIVE_OBJECT_ENABLE_CACHE_MESSAGE);
|
|
25879
|
-
}
|
|
25880
|
-
let model;
|
|
25881
|
-
let isUnsyncedModel = false; // for messages
|
|
25882
|
-
const disposers = [];
|
|
25883
|
-
const dispatcher = (data) => {
|
|
25884
|
-
const { data: newModel } = data, rest = __rest(data, ["data"]);
|
|
25885
|
-
if (!callbackFilter || callbackFilter(newModel, model)) {
|
|
25886
|
-
callback(Object.assign({ data: callbackDataSelector(newModel) }, rest));
|
|
25887
|
-
}
|
|
25888
|
-
// resolve all getter on data model to a static value to avoid comparison problems
|
|
25889
|
-
model = convertGetterPropsToStatic(newModel);
|
|
25890
|
-
};
|
|
25891
|
-
const realtimeRouter = (eventModel, forceDispatch = false) => {
|
|
25892
|
-
if (id !== eventModel[key]) {
|
|
25893
|
-
return;
|
|
25894
|
-
}
|
|
25895
|
-
if (model) {
|
|
25896
|
-
if (!forceDispatch && isEqual(model, eventModel)) {
|
|
25897
|
-
return;
|
|
25898
|
-
}
|
|
25899
|
-
}
|
|
25900
|
-
dispatcher({ loading: false, data: eventModel, origin: 'event' });
|
|
25901
|
-
};
|
|
25902
|
-
const onFetch = () => {
|
|
25903
|
-
// TODO: Ihis `@ts-ignore` is bring back to fix the build and it needs to be removed later
|
|
25904
|
-
// @ts-ignore
|
|
25905
|
-
const query = createQuery(fetcher, id, true);
|
|
25906
|
-
runQuery(query, ({ error, data, loading, origin, cachedAt }) => {
|
|
25907
|
-
if (cachedAt === UNSYNCED_OBJECT_CACHED_AT_VALUE) {
|
|
25908
|
-
dispatcher({
|
|
25909
|
-
// @ts-ignore
|
|
25910
|
-
data,
|
|
25911
|
-
origin,
|
|
25912
|
-
loading: false,
|
|
25913
|
-
error: new ASCApiError(UNSYNCED_OBJECT_CACHED_AT_MESSAGE, 800800 /* Amity.ClientError.DISALOOW_UNSYNCED_OBJECT */, "error" /* Amity.ErrorLevel.ERROR */),
|
|
25914
|
-
});
|
|
25915
|
-
isUnsyncedModel = true;
|
|
25916
|
-
disposers.forEach(fn => fn());
|
|
25917
|
-
}
|
|
25918
|
-
else if (!isUnsyncedModel) {
|
|
25919
|
-
// @ts-ignore
|
|
25920
|
-
dispatcher({ loading, data, origin, error });
|
|
25921
|
-
}
|
|
25922
|
-
if (error) {
|
|
25923
|
-
disposers.forEach(fn => fn());
|
|
25924
|
-
}
|
|
25925
|
-
});
|
|
25926
|
-
};
|
|
25927
|
-
disposers.push(...eventHandlers.map(fn => fn(eventModel => realtimeRouter(eventModel, forceDispatch))));
|
|
25928
|
-
onFetch();
|
|
25929
|
-
return () => {
|
|
25930
|
-
disposers.forEach(fn => fn());
|
|
25931
|
-
};
|
|
25932
|
-
};
|
|
25933
|
-
|
|
25934
|
-
/**
|
|
25935
|
-
* @deprecated Please use unreadCount from `getUserUnread` instead.
|
|
25936
|
-
*
|
|
25937
|
-
* ```js
|
|
25938
|
-
* import { getTotalUnreadCount } from '@amityco/ts-sdk';
|
|
25939
|
-
*
|
|
25940
|
-
* const unsubscribe = getTotalUnreadCount(response => {
|
|
25941
|
-
* totalUnreadCount = response.data;
|
|
25942
|
-
* });
|
|
25943
|
-
* ```
|
|
25944
|
-
*
|
|
25945
|
-
* Observe current user's unread count from {@link Amity.UserMarker}
|
|
25946
|
-
*
|
|
25947
|
-
* @param callback the function to call when new data are available
|
|
25948
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the events
|
|
25949
|
-
*
|
|
25950
|
-
* @category Message Live Object
|
|
25951
|
-
*/
|
|
25952
|
-
const getTotalUnreadCount = (callback) => {
|
|
25953
|
-
const { _id: userId } = getActiveUser();
|
|
25954
|
-
if (!userId)
|
|
25955
|
-
throw new ASCError('The _id has not been defined in ActiveUser', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
25956
|
-
const callbackDataSelector = (data) => { var _a; return (_a = data === null || data === void 0 ? void 0 : data.unreadCount) !== null && _a !== void 0 ? _a : 0; };
|
|
25957
|
-
return liveObject(userId, callback, 'userId', async () => {
|
|
25958
|
-
const { data: userMarker, cachedAt } = await getUserMarker();
|
|
25959
|
-
return { data: userMarker, cachedAt };
|
|
25960
|
-
}, [onUserMarkerFetchedLegacy], {
|
|
25961
|
-
callbackDataSelector,
|
|
25962
|
-
});
|
|
25963
|
-
};
|
|
25964
|
-
|
|
25965
25712
|
/**
|
|
25966
25713
|
*
|
|
25967
25714
|
* ```js
|
|
@@ -26003,7 +25750,7 @@ const getUserUnread = (callback) => {
|
|
|
26003
25750
|
model = callbackModel ? convertGetterPropsToStatic(callbackModel) : callbackModel;
|
|
26004
25751
|
callback({
|
|
26005
25752
|
data: callbackModel
|
|
26006
|
-
? Object.assign(Object.assign({}, callbackModel), {
|
|
25753
|
+
? Object.assign(Object.assign({}, callbackModel), { isMentioned: callbackModel.isMentioned }) : callbackModel,
|
|
26007
25754
|
loading: data.loading,
|
|
26008
25755
|
error: data.error,
|
|
26009
25756
|
});
|
|
@@ -26091,7 +25838,6 @@ var index$l = /*#__PURE__*/Object.freeze({
|
|
|
26091
25838
|
onClientBanned: onClientBanned,
|
|
26092
25839
|
onSessionStateChange: onSessionStateChange,
|
|
26093
25840
|
onNetworkActivities: onNetworkActivities,
|
|
26094
|
-
getTotalUnreadCount: getTotalUnreadCount,
|
|
26095
25841
|
getUserUnread: getUserUnread,
|
|
26096
25842
|
getMarkerSyncEvents: getMarkerSyncEvents,
|
|
26097
25843
|
setMarkerSyncEvents: setMarkerSyncEvents,
|
|
@@ -26100,7 +25846,6 @@ var index$l = /*#__PURE__*/Object.freeze({
|
|
|
26100
25846
|
startMarkerSync: startMarkerSync,
|
|
26101
25847
|
startUnreadSync: startUnreadSync,
|
|
26102
25848
|
stopUnreadSync: stopUnreadSync,
|
|
26103
|
-
stopUnreadSyncing: stopUnreadSyncing,
|
|
26104
25849
|
getMarkerSyncConsistentMode: getMarkerSyncConsistentMode
|
|
26105
25850
|
});
|
|
26106
25851
|
|
|
@@ -26185,311 +25930,134 @@ const unBlockUser = async (userId) => {
|
|
|
26185
25930
|
};
|
|
26186
25931
|
/* end_public_function */
|
|
26187
25932
|
|
|
26188
|
-
|
|
26189
|
-
|
|
26190
|
-
|
|
26191
|
-
this.queryParams = queryParams;
|
|
26192
|
-
this.http = http;
|
|
26193
|
-
}
|
|
26194
|
-
loadFirstPage() {
|
|
26195
|
-
return this.onFetch("first" /* Amity.LiveCollectionPageDirection.FIRST */);
|
|
26196
|
-
}
|
|
26197
|
-
loadNextPage() {
|
|
26198
|
-
return this.onFetch("next" /* Amity.LiveCollectionPageDirection.NEXT */);
|
|
26199
|
-
}
|
|
26200
|
-
loadPreviousPage() {
|
|
26201
|
-
return this.onFetch("prev" /* Amity.LiveCollectionPageDirection.PREV */);
|
|
26202
|
-
}
|
|
26203
|
-
async onFetch(direction = "first" /* Amity.LiveCollectionPageDirection.FIRST */) {
|
|
26204
|
-
var _a, _b, _c, _d;
|
|
26205
|
-
if (direction === 'prev' && !this.previousToken)
|
|
26206
|
-
return;
|
|
26207
|
-
if (direction === 'next' && !this.nextToken)
|
|
26208
|
-
return;
|
|
26209
|
-
let token;
|
|
26210
|
-
if (direction === 'prev')
|
|
26211
|
-
token = this.previousToken;
|
|
26212
|
-
if (direction === 'next')
|
|
26213
|
-
token = this.nextToken;
|
|
26214
|
-
const queryResponse = await this.getRequest(this.queryParams, token);
|
|
26215
|
-
if (direction === 'first') {
|
|
26216
|
-
this.nextToken = (_a = queryResponse.paging) === null || _a === void 0 ? void 0 : _a.next;
|
|
26217
|
-
this.previousToken = (_b = queryResponse.paging) === null || _b === void 0 ? void 0 : _b.previous;
|
|
26218
|
-
}
|
|
26219
|
-
if (direction === 'prev')
|
|
26220
|
-
this.previousToken = (_c = queryResponse.paging) === null || _c === void 0 ? void 0 : _c.previous;
|
|
26221
|
-
if (direction === 'next')
|
|
26222
|
-
this.nextToken = (_d = queryResponse.paging) === null || _d === void 0 ? void 0 : _d.next;
|
|
26223
|
-
return queryResponse;
|
|
26224
|
-
}
|
|
26225
|
-
getNextToken() {
|
|
26226
|
-
return this.nextToken;
|
|
26227
|
-
}
|
|
26228
|
-
getPrevToken() {
|
|
26229
|
-
return this.previousToken;
|
|
26230
|
-
}
|
|
26231
|
-
}
|
|
26232
|
-
|
|
26233
|
-
class BlockedUserPaginationController extends PaginationController {
|
|
26234
|
-
async getRequest(queryParams, token) {
|
|
26235
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
26236
|
-
const options = token ? { token } : { limit };
|
|
26237
|
-
const { data: queryResponse } = await this.http.get('/api/v4/me/user-blocks', {
|
|
26238
|
-
params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
|
|
26239
|
-
});
|
|
26240
|
-
return queryResponse;
|
|
26241
|
-
}
|
|
26242
|
-
}
|
|
26243
|
-
|
|
26244
|
-
class QueryStreamController {
|
|
26245
|
-
constructor(query, cacheKey) {
|
|
26246
|
-
this.query = query;
|
|
26247
|
-
this.cacheKey = cacheKey;
|
|
26248
|
-
}
|
|
26249
|
-
}
|
|
26250
|
-
|
|
26251
|
-
var EnumFollowActions;
|
|
26252
|
-
(function (EnumFollowActions) {
|
|
26253
|
-
EnumFollowActions["OnRequested"] = "onRequested";
|
|
26254
|
-
EnumFollowActions["OnAccepted"] = "onAccepted";
|
|
26255
|
-
EnumFollowActions["OnDeclined"] = "onDeclined";
|
|
26256
|
-
EnumFollowActions["OnCanceled"] = "onCanceled";
|
|
26257
|
-
EnumFollowActions["OnFollowed"] = "onFollowed";
|
|
26258
|
-
EnumFollowActions["OnUnfollowed"] = "onUnfollowed";
|
|
26259
|
-
EnumFollowActions["OnDeleted"] = "onDeleted";
|
|
26260
|
-
EnumFollowActions["OnUserDeleted"] = "onUserDeleted";
|
|
26261
|
-
})(EnumFollowActions || (EnumFollowActions = {}));
|
|
26262
|
-
|
|
26263
|
-
class BlockedUserQueryStreamController extends QueryStreamController {
|
|
26264
|
-
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
26265
|
-
super(query, cacheKey);
|
|
26266
|
-
this.notifyChange = notifyChange;
|
|
26267
|
-
this.preparePayload = preparePayload;
|
|
26268
|
-
}
|
|
26269
|
-
async saveToMainDB(response) {
|
|
26270
|
-
const processedPayload = await this.preparePayload(response);
|
|
26271
|
-
const client = getActiveClient();
|
|
26272
|
-
const cachedAt = client.cache && Date.now();
|
|
26273
|
-
if (client.cache) {
|
|
26274
|
-
ingestInCache(processedPayload, { cachedAt });
|
|
26275
|
-
}
|
|
26276
|
-
}
|
|
26277
|
-
appendToQueryStream(response, direction, refresh = false) {
|
|
26278
|
-
var _a, _b;
|
|
26279
|
-
if (refresh) {
|
|
26280
|
-
pushToCache(this.cacheKey, {
|
|
26281
|
-
data: response.users.map(getResolver('user')),
|
|
26282
|
-
});
|
|
26283
|
-
}
|
|
26284
|
-
else {
|
|
26285
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
26286
|
-
const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
26287
|
-
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...users, ...response.users.map(getResolver('user'))])] }));
|
|
26288
|
-
}
|
|
26289
|
-
}
|
|
26290
|
-
reactor(action) {
|
|
26291
|
-
return (targetUser) => {
|
|
26292
|
-
var _a;
|
|
26293
|
-
if (action === EnumFollowActions.OnFollowed) {
|
|
26294
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
26295
|
-
const updatedCollection = collection === null || collection === void 0 ? void 0 : collection.data.filter(id => id !== targetUser.userId);
|
|
26296
|
-
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: updatedCollection }));
|
|
26297
|
-
}
|
|
26298
|
-
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
26299
|
-
};
|
|
26300
|
-
}
|
|
26301
|
-
subscribeRTE(createSubscriber) {
|
|
26302
|
-
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
26303
|
-
}
|
|
26304
|
-
}
|
|
26305
|
-
|
|
26306
|
-
class PaginationNoPageController {
|
|
26307
|
-
constructor(queryParams) {
|
|
26308
|
-
const { http } = getActiveClient();
|
|
26309
|
-
this.queryParams = queryParams;
|
|
26310
|
-
this.http = http;
|
|
26311
|
-
}
|
|
26312
|
-
async onFetch() {
|
|
26313
|
-
const queryResponse = await this.getRequest(this.queryParams);
|
|
26314
|
-
return queryResponse;
|
|
26315
|
-
}
|
|
26316
|
-
}
|
|
26317
|
-
|
|
26318
|
-
class LiveCollectionController {
|
|
26319
|
-
constructor(paginationController, queryStreamId, cacheKey, callback) {
|
|
26320
|
-
this.paginationController = paginationController;
|
|
26321
|
-
this.queryStreamId = queryStreamId;
|
|
26322
|
-
this.cacheKey = cacheKey;
|
|
26323
|
-
this.callback = callback;
|
|
26324
|
-
}
|
|
26325
|
-
async refresh() {
|
|
26326
|
-
try {
|
|
26327
|
-
let result;
|
|
26328
|
-
if (this.paginationController instanceof PaginationNoPageController) {
|
|
26329
|
-
result = await this.paginationController.onFetch();
|
|
26330
|
-
}
|
|
26331
|
-
else {
|
|
26332
|
-
result = await this.paginationController.loadFirstPage();
|
|
26333
|
-
}
|
|
26334
|
-
if (!result)
|
|
26335
|
-
return;
|
|
26336
|
-
await this.persistModel(result);
|
|
26337
|
-
this.persistQueryStream({
|
|
26338
|
-
response: result,
|
|
26339
|
-
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
26340
|
-
refresh: true,
|
|
26341
|
-
});
|
|
26342
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
26343
|
-
}
|
|
26344
|
-
catch (e) {
|
|
26345
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
26346
|
-
}
|
|
26347
|
-
}
|
|
26348
|
-
loadPage({ initial = false, direction = "next" /* Amity.LiveCollectionPageDirection.NEXT */, }) {
|
|
26349
|
-
this.setup();
|
|
26350
|
-
this.notifyChange({ origin: "local" /* Amity.LiveDataOrigin.LOCAL */, loading: true });
|
|
26351
|
-
if (initial) {
|
|
26352
|
-
this.refresh();
|
|
26353
|
-
}
|
|
26354
|
-
else if (direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */) {
|
|
26355
|
-
this.loadPrevPage();
|
|
26356
|
-
}
|
|
26357
|
-
else if (direction === "next" /* Amity.LiveCollectionPageDirection.NEXT */) {
|
|
26358
|
-
this.loadNextPage();
|
|
26359
|
-
}
|
|
26360
|
-
}
|
|
26361
|
-
async loadNextPage() {
|
|
26362
|
-
try {
|
|
26363
|
-
if (this.paginationController instanceof PaginationNoPageController)
|
|
26364
|
-
return;
|
|
26365
|
-
const result = await this.paginationController.loadNextPage();
|
|
26366
|
-
if (!result)
|
|
26367
|
-
return;
|
|
26368
|
-
await this.persistModel(result);
|
|
26369
|
-
this.persistQueryStream({
|
|
26370
|
-
response: result,
|
|
26371
|
-
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
26372
|
-
});
|
|
26373
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
26374
|
-
}
|
|
26375
|
-
catch (e) {
|
|
26376
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
26377
|
-
}
|
|
26378
|
-
}
|
|
26379
|
-
async loadPrevPage() {
|
|
26380
|
-
try {
|
|
26381
|
-
if (this.paginationController instanceof PaginationNoPageController)
|
|
26382
|
-
return;
|
|
26383
|
-
const result = await this.paginationController.loadPreviousPage();
|
|
26384
|
-
if (!result)
|
|
26385
|
-
return;
|
|
26386
|
-
await this.persistModel(result);
|
|
26387
|
-
this.persistQueryStream({
|
|
26388
|
-
response: result,
|
|
26389
|
-
direction: "prev" /* Amity.LiveCollectionPageDirection.PREV */,
|
|
26390
|
-
});
|
|
26391
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
26392
|
-
}
|
|
26393
|
-
catch (e) {
|
|
26394
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
26395
|
-
}
|
|
26396
|
-
}
|
|
26397
|
-
shouldNotify(data) {
|
|
26398
|
-
const newData = data.map(convertGetterPropsToStatic).map(removeFunctionProperties);
|
|
26399
|
-
if (isEqual(this.snapshot, newData))
|
|
26400
|
-
return false;
|
|
26401
|
-
this.snapshot = newData;
|
|
26402
|
-
return true;
|
|
26403
|
-
}
|
|
26404
|
-
getCacheKey() {
|
|
26405
|
-
return this.cacheKey;
|
|
26406
|
-
}
|
|
26407
|
-
}
|
|
26408
|
-
|
|
26409
|
-
function prepareBlockedUserPayload(response) {
|
|
26410
|
-
const { users, follows } = response, rest = __rest(response, ["users", "follows"]);
|
|
26411
|
-
return Object.assign(Object.assign({}, rest), { follows: follows.map(follow => {
|
|
26412
|
-
const followUser = users.find(user => user.userId === follow.from);
|
|
26413
|
-
return Object.assign(Object.assign({}, follow), { user: convertRawUserToInternalUser(followUser) });
|
|
26414
|
-
}), users: users.map(convertRawUserToInternalUser) });
|
|
26415
|
-
}
|
|
26416
|
-
|
|
25933
|
+
/* begin_public_function
|
|
25934
|
+
id: user.relationship.follow
|
|
25935
|
+
*/
|
|
26417
25936
|
/**
|
|
26418
25937
|
* ```js
|
|
26419
|
-
* import {
|
|
26420
|
-
* const
|
|
26421
|
-
* // ...
|
|
26422
|
-
* })
|
|
25938
|
+
* import { follow } from '@amityco/ts-sdk'
|
|
25939
|
+
* const status = await follow('foobar')
|
|
26423
25940
|
* ```
|
|
26424
25941
|
*
|
|
26425
|
-
*
|
|
25942
|
+
* Follow the user
|
|
26426
25943
|
*
|
|
26427
|
-
* @param
|
|
26428
|
-
* @returns
|
|
25944
|
+
* @param userId the ID of the {@link Amity.InternalUser}
|
|
25945
|
+
* @returns the status {@link Amity.FollowStatus}
|
|
26429
25946
|
*
|
|
26430
|
-
* @category
|
|
25947
|
+
* @category Follow API
|
|
25948
|
+
* @async
|
|
26431
25949
|
*/
|
|
26432
|
-
const
|
|
25950
|
+
const follow = async (userId) => {
|
|
25951
|
+
const client = getActiveClient();
|
|
25952
|
+
client.log('follow/follow', userId);
|
|
25953
|
+
const { data } = await client.http.post(`/api/v4/me/following/${userId}`);
|
|
25954
|
+
const cachedAt = client.cache && Date.now();
|
|
25955
|
+
if (client.cache) {
|
|
25956
|
+
ingestInCache(data, { cachedAt });
|
|
25957
|
+
}
|
|
25958
|
+
const payload = prepareFollowStatusPayload(data);
|
|
25959
|
+
if (data.follows[0].status === 'accepted') {
|
|
25960
|
+
fireEvent('local.follow.created', payload);
|
|
25961
|
+
}
|
|
25962
|
+
else {
|
|
25963
|
+
fireEvent('local.follow.requested', payload);
|
|
25964
|
+
}
|
|
25965
|
+
return {
|
|
25966
|
+
data: data.follows[0],
|
|
25967
|
+
cachedAt,
|
|
25968
|
+
};
|
|
25969
|
+
};
|
|
25970
|
+
/* end_public_function */
|
|
26433
25971
|
|
|
25972
|
+
/* begin_public_function
|
|
25973
|
+
id: user.relationship.unfollow
|
|
25974
|
+
*/
|
|
26434
25975
|
/**
|
|
26435
25976
|
* ```js
|
|
26436
|
-
* import {
|
|
26437
|
-
*
|
|
26438
|
-
* // ...
|
|
26439
|
-
* })
|
|
25977
|
+
* import { unfollow } from '@amityco/ts-sdk'
|
|
25978
|
+
* await unfollow('foobar')
|
|
26440
25979
|
* ```
|
|
26441
25980
|
*
|
|
26442
|
-
*
|
|
25981
|
+
* Cancel the follow request or unfollow the user
|
|
26443
25982
|
*
|
|
26444
|
-
* @param
|
|
26445
|
-
* @returns
|
|
25983
|
+
* @param userId the ID of the {@link Amity.InternalUser}
|
|
25984
|
+
* @returns A success boolean if the user {@link Amity.InternalUser} was unfollowed
|
|
26446
25985
|
*
|
|
26447
|
-
* @category
|
|
25986
|
+
* @category Follow API
|
|
25987
|
+
* @async
|
|
26448
25988
|
*/
|
|
26449
|
-
const
|
|
25989
|
+
const unfollow = async (userId) => {
|
|
25990
|
+
const client = getActiveClient();
|
|
25991
|
+
client.log('follow/unfollow', userId);
|
|
25992
|
+
const { data } = await client.http.delete(`/api/v4/me/following/${userId}`);
|
|
25993
|
+
if (client.cache) {
|
|
25994
|
+
ingestInCache(data);
|
|
25995
|
+
}
|
|
25996
|
+
const payload = prepareFollowStatusPayload(data);
|
|
25997
|
+
fireEvent('local.follow.unfollowed', payload);
|
|
25998
|
+
return true;
|
|
25999
|
+
};
|
|
26000
|
+
/* end_public_function */
|
|
26450
26001
|
|
|
26002
|
+
/* begin_public_function
|
|
26003
|
+
id: user.relationship.accept_follow
|
|
26004
|
+
*/
|
|
26451
26005
|
/**
|
|
26452
26006
|
* ```js
|
|
26453
|
-
* import {
|
|
26454
|
-
*
|
|
26455
|
-
* // ...
|
|
26456
|
-
* })
|
|
26007
|
+
* import { UserRepository } from '@amityco/ts-sdk'
|
|
26008
|
+
* await UserRepository.Relationship.acceptMyFollower('foobar')
|
|
26457
26009
|
* ```
|
|
26458
26010
|
*
|
|
26459
|
-
*
|
|
26011
|
+
* Accept the follow request
|
|
26460
26012
|
*
|
|
26461
|
-
* @param
|
|
26462
|
-
* @returns
|
|
26013
|
+
* @param userId the ID of the {@link Amity.InternalUser} follower
|
|
26014
|
+
* @returns A success boolean if the follow request was accepted
|
|
26463
26015
|
*
|
|
26464
|
-
* @category
|
|
26016
|
+
* @category Follow API
|
|
26017
|
+
* @async
|
|
26465
26018
|
*/
|
|
26466
|
-
const
|
|
26019
|
+
const acceptMyFollower = async (userId) => {
|
|
26020
|
+
const client = getActiveClient();
|
|
26021
|
+
client.log('follow/acceptMyFollower', userId);
|
|
26022
|
+
const { data } = await client.http.post(`/api/v4/me/followers/${userId}`);
|
|
26023
|
+
if (client.cache) {
|
|
26024
|
+
ingestInCache(data);
|
|
26025
|
+
}
|
|
26026
|
+
const payload = prepareFollowStatusPayload(data);
|
|
26027
|
+
fireEvent('local.follow.accepted', payload);
|
|
26028
|
+
return true;
|
|
26029
|
+
};
|
|
26030
|
+
/* end_public_function */
|
|
26467
26031
|
|
|
26032
|
+
/* begin_public_function
|
|
26033
|
+
id: user.relationship.decline_follow
|
|
26034
|
+
*/
|
|
26468
26035
|
/**
|
|
26469
26036
|
* ```js
|
|
26470
|
-
* import {
|
|
26471
|
-
*
|
|
26472
|
-
* // ...
|
|
26473
|
-
* })
|
|
26037
|
+
* import { UserRepository } from '@amityco/ts-sdk'
|
|
26038
|
+
* await UserRepository.Relationship.declineMyFollower('foobar')
|
|
26474
26039
|
* ```
|
|
26475
26040
|
*
|
|
26476
|
-
*
|
|
26041
|
+
* Decline the follow request or delete the follower
|
|
26477
26042
|
*
|
|
26478
|
-
* @param
|
|
26479
|
-
* @returns
|
|
26043
|
+
* @param userId the ID of the {@link Amity.InternalUser} follower
|
|
26044
|
+
* @returns A success boolean if the follow request was decline
|
|
26480
26045
|
*
|
|
26481
|
-
* @category
|
|
26046
|
+
* @category Follow API
|
|
26047
|
+
* @async
|
|
26482
26048
|
*/
|
|
26483
|
-
const
|
|
26484
|
-
|
|
26485
|
-
|
|
26486
|
-
|
|
26487
|
-
|
|
26488
|
-
|
|
26489
|
-
|
|
26490
|
-
|
|
26491
|
-
|
|
26492
|
-
|
|
26049
|
+
const declineMyFollower = async (userId) => {
|
|
26050
|
+
const client = getActiveClient();
|
|
26051
|
+
client.log('follow/declineMyFollower', userId);
|
|
26052
|
+
const { data } = await client.http.delete(`/api/v4/me/followers/${userId}`);
|
|
26053
|
+
if (client.cache) {
|
|
26054
|
+
ingestInCache(data);
|
|
26055
|
+
}
|
|
26056
|
+
const payload = prepareFollowStatusPayload(data);
|
|
26057
|
+
fireEvent('local.follow.requestDeclined', payload);
|
|
26058
|
+
return true;
|
|
26059
|
+
};
|
|
26060
|
+
/* end_public_function */
|
|
26493
26061
|
|
|
26494
26062
|
const createFollowEventSubscriber = (event, callback) => {
|
|
26495
26063
|
const client = getActiveClient();
|
|
@@ -26753,446 +26321,50 @@ const onLocalFollowRequestAccepted = (callback) => createLocalFollowEventSubscri
|
|
|
26753
26321
|
|
|
26754
26322
|
const onLocalFollowRequestDeclined = (callback) => createLocalFollowEventSubscriber('local.follow.requestDeclined', callback);
|
|
26755
26323
|
|
|
26756
|
-
|
|
26757
|
-
|
|
26758
|
-
|
|
26759
|
-
|
|
26760
|
-
|
|
26761
|
-
const client = getActiveClient();
|
|
26762
|
-
const { objectSyncMap } = client;
|
|
26763
|
-
/*
|
|
26764
|
-
* NOTE: For objects created locally (optimistic creation), the SDK stores them with their local ID as the cache key, which is used throughout the entire SDK session (in-memory) for syncing updates.
|
|
26765
|
-
* If the payload or response only contains the remote ID of the same object, the SDK will look up the corresponding local ID to retrieve the object.
|
|
26766
|
-
*/
|
|
26767
|
-
const resolvedId = isLocalId(sourceModel[sourceModelProp])
|
|
26768
|
-
? sourceModel[sourceModelProp]
|
|
26769
|
-
: (_a = objectSyncMap.get(sourceModel[sourceModelProp])) !== null && _a !== void 0 ? _a : sourceModel[sourceModelProp];
|
|
26770
|
-
const model = (_b = pullFromCache([
|
|
26771
|
-
destinationDomain,
|
|
26772
|
-
'get',
|
|
26773
|
-
`${resolvedId}`,
|
|
26774
|
-
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
26775
|
-
if (!model)
|
|
26776
|
-
return;
|
|
26777
|
-
return callback(model);
|
|
26778
|
-
});
|
|
26779
|
-
|
|
26780
|
-
class BlockedUserLiveCollectionController extends LiveCollectionController {
|
|
26781
|
-
constructor(query, callback) {
|
|
26782
|
-
const queryStreamId = hash(query);
|
|
26783
|
-
const cacheKey = ['blockedUsers', 'collection', queryStreamId];
|
|
26784
|
-
const paginationController = new BlockedUserPaginationController(query);
|
|
26785
|
-
super(paginationController, queryStreamId, cacheKey, callback);
|
|
26786
|
-
this.query = query;
|
|
26787
|
-
this.queryStreamController = new BlockedUserQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareBlockedUserPayload);
|
|
26788
|
-
this.callback = callback.bind(this);
|
|
26789
|
-
this.loadPage({ initial: true });
|
|
26790
|
-
}
|
|
26791
|
-
setup() {
|
|
26792
|
-
var _a;
|
|
26793
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
26794
|
-
if (!collection) {
|
|
26795
|
-
pushToCache(this.cacheKey, {
|
|
26796
|
-
data: [],
|
|
26797
|
-
params: {},
|
|
26798
|
-
});
|
|
26799
|
-
}
|
|
26324
|
+
class PaginationController {
|
|
26325
|
+
constructor(queryParams) {
|
|
26326
|
+
const { http } = getActiveClient();
|
|
26327
|
+
this.queryParams = queryParams;
|
|
26328
|
+
this.http = http;
|
|
26800
26329
|
}
|
|
26801
|
-
|
|
26802
|
-
|
|
26330
|
+
loadFirstPage() {
|
|
26331
|
+
return this.onFetch("first" /* Amity.LiveCollectionPageDirection.FIRST */);
|
|
26803
26332
|
}
|
|
26804
|
-
|
|
26805
|
-
this.
|
|
26333
|
+
loadNextPage() {
|
|
26334
|
+
return this.onFetch("next" /* Amity.LiveCollectionPageDirection.NEXT */);
|
|
26806
26335
|
}
|
|
26807
|
-
|
|
26808
|
-
return this.
|
|
26809
|
-
{
|
|
26810
|
-
fn: onUserDeleted$2,
|
|
26811
|
-
action: EnumUserActions.OnUserDeleted,
|
|
26812
|
-
},
|
|
26813
|
-
// In the case of unblocking a user, we need to subscribe to the follow events
|
|
26814
|
-
{
|
|
26815
|
-
fn: convertEventPayload(onLocalUserFollowed, 'to', 'user'),
|
|
26816
|
-
action: EnumFollowActions.OnFollowed,
|
|
26817
|
-
},
|
|
26818
|
-
{
|
|
26819
|
-
fn: convertEventPayload(onUserFollowed, 'to', 'user'),
|
|
26820
|
-
action: EnumFollowActions.OnFollowed,
|
|
26821
|
-
},
|
|
26822
|
-
]);
|
|
26336
|
+
loadPreviousPage() {
|
|
26337
|
+
return this.onFetch("prev" /* Amity.LiveCollectionPageDirection.PREV */);
|
|
26823
26338
|
}
|
|
26824
|
-
|
|
26825
|
-
var _a, _b;
|
|
26826
|
-
|
|
26827
|
-
if (!collection)
|
|
26339
|
+
async onFetch(direction = "first" /* Amity.LiveCollectionPageDirection.FIRST */) {
|
|
26340
|
+
var _a, _b, _c, _d;
|
|
26341
|
+
if (direction === 'prev' && !this.previousToken)
|
|
26828
26342
|
return;
|
|
26829
|
-
|
|
26830
|
-
.map(id => pullFromCache(['user', 'get', id]))
|
|
26831
|
-
.filter(isNonNullable)
|
|
26832
|
-
.map(({ data }) => data)
|
|
26833
|
-
.map(LinkedObject.user)) !== null && _b !== void 0 ? _b : []);
|
|
26834
|
-
if (!this.shouldNotify(data) && origin === 'event')
|
|
26343
|
+
if (direction === 'next' && !this.nextToken)
|
|
26835
26344
|
return;
|
|
26836
|
-
|
|
26837
|
-
|
|
26838
|
-
|
|
26839
|
-
|
|
26840
|
-
|
|
26841
|
-
|
|
26842
|
-
|
|
26843
|
-
|
|
26844
|
-
|
|
26845
|
-
|
|
26846
|
-
|
|
26847
|
-
|
|
26848
|
-
|
|
26849
|
-
|
|
26850
|
-
|
|
26851
|
-
|
|
26852
|
-
/* begin_public_function
|
|
26853
|
-
id: user.get_blocked_users
|
|
26854
|
-
*/
|
|
26855
|
-
/**
|
|
26856
|
-
* ```js
|
|
26857
|
-
* import { UserRepository } from '@amityco/ts-sdk'
|
|
26858
|
-
* const unblockedUser = await UserRepository.blockUser('userId')
|
|
26859
|
-
* ```
|
|
26860
|
-
*
|
|
26861
|
-
* Blocks a {@link Amity.InternalUser}
|
|
26862
|
-
*
|
|
26863
|
-
* @param params The params to get blocked {@link Amity.InternalUser}s
|
|
26864
|
-
* @param callback to recieve updates on unblocked {@link Amity.InternalUser}s
|
|
26865
|
-
* @returns {@link Amity.Unsubscriber} to unsubscribe from collection
|
|
26866
|
-
*
|
|
26867
|
-
* @category Post API
|
|
26868
|
-
* @async
|
|
26869
|
-
*/
|
|
26870
|
-
const getBlockedUsers$1 = (params, callback, config) => {
|
|
26871
|
-
const { log, cache } = getActiveClient();
|
|
26872
|
-
if (!cache) {
|
|
26873
|
-
console.log(ENABLE_CACHE_MESSAGE);
|
|
26874
|
-
}
|
|
26875
|
-
const timestamp = Date.now();
|
|
26876
|
-
log(`getBlockedUsers(tmpid: ${timestamp}) > listen`);
|
|
26877
|
-
const blockedUserLiveCollection = new BlockedUserLiveCollectionController(params, callback);
|
|
26878
|
-
const disposers = blockedUserLiveCollection.startSubscription();
|
|
26879
|
-
const cacheKey = blockedUserLiveCollection.getCacheKey();
|
|
26880
|
-
disposers.push(() => dropFromCache(cacheKey));
|
|
26881
|
-
return () => {
|
|
26882
|
-
log(`getBlockedUsers(tmpid: ${timestamp}) > dispose`);
|
|
26883
|
-
disposers.forEach(fn => fn());
|
|
26884
|
-
dropFromCache(cacheKey);
|
|
26885
|
-
};
|
|
26886
|
-
};
|
|
26887
|
-
/* end_public_function */
|
|
26888
|
-
|
|
26889
|
-
/* eslint-disable no-use-before-define */
|
|
26890
|
-
const getBlockedUsers = (params, callback, config) => {
|
|
26891
|
-
console.log('Deprecation Notice: UserRepository.Relationship.getBlockedUsers will be deprecated on 9th June 2023, please use UserRepository.getBlockedUsers instead.');
|
|
26892
|
-
return getBlockedUsers$1(params, callback);
|
|
26893
|
-
};
|
|
26894
|
-
|
|
26895
|
-
/* begin_public_function
|
|
26896
|
-
id: user.relationship.follow
|
|
26897
|
-
*/
|
|
26898
|
-
/**
|
|
26899
|
-
* ```js
|
|
26900
|
-
* import { follow } from '@amityco/ts-sdk'
|
|
26901
|
-
* const status = await follow('foobar')
|
|
26902
|
-
* ```
|
|
26903
|
-
*
|
|
26904
|
-
* Follow the user
|
|
26905
|
-
*
|
|
26906
|
-
* @param userId the ID of the {@link Amity.InternalUser}
|
|
26907
|
-
* @returns the status {@link Amity.FollowStatus}
|
|
26908
|
-
*
|
|
26909
|
-
* @category Follow API
|
|
26910
|
-
* @async
|
|
26911
|
-
*/
|
|
26912
|
-
const follow = async (userId) => {
|
|
26913
|
-
const client = getActiveClient();
|
|
26914
|
-
client.log('follow/follow', userId);
|
|
26915
|
-
const { data } = await client.http.post(`/api/v4/me/following/${userId}`);
|
|
26916
|
-
const cachedAt = client.cache && Date.now();
|
|
26917
|
-
if (client.cache) {
|
|
26918
|
-
ingestInCache(data, { cachedAt });
|
|
26919
|
-
}
|
|
26920
|
-
const payload = prepareFollowStatusPayload(data);
|
|
26921
|
-
if (data.follows[0].status === 'accepted') {
|
|
26922
|
-
fireEvent('local.follow.created', payload);
|
|
26923
|
-
}
|
|
26924
|
-
else {
|
|
26925
|
-
fireEvent('local.follow.requested', payload);
|
|
26926
|
-
}
|
|
26927
|
-
return {
|
|
26928
|
-
data: data.follows[0],
|
|
26929
|
-
cachedAt,
|
|
26930
|
-
};
|
|
26931
|
-
};
|
|
26932
|
-
/* end_public_function */
|
|
26933
|
-
|
|
26934
|
-
/* begin_public_function
|
|
26935
|
-
id: user.relationship.unfollow
|
|
26936
|
-
*/
|
|
26937
|
-
/**
|
|
26938
|
-
* ```js
|
|
26939
|
-
* import { unfollow } from '@amityco/ts-sdk'
|
|
26940
|
-
* await unfollow('foobar')
|
|
26941
|
-
* ```
|
|
26942
|
-
*
|
|
26943
|
-
* Cancel the follow request or unfollow the user
|
|
26944
|
-
*
|
|
26945
|
-
* @param userId the ID of the {@link Amity.InternalUser}
|
|
26946
|
-
* @returns A success boolean if the user {@link Amity.InternalUser} was unfollowed
|
|
26947
|
-
*
|
|
26948
|
-
* @category Follow API
|
|
26949
|
-
* @async
|
|
26950
|
-
*/
|
|
26951
|
-
const unfollow = async (userId) => {
|
|
26952
|
-
const client = getActiveClient();
|
|
26953
|
-
client.log('follow/unfollow', userId);
|
|
26954
|
-
const { data } = await client.http.delete(`/api/v4/me/following/${userId}`);
|
|
26955
|
-
if (client.cache) {
|
|
26956
|
-
ingestInCache(data);
|
|
26957
|
-
}
|
|
26958
|
-
const payload = prepareFollowStatusPayload(data);
|
|
26959
|
-
fireEvent('local.follow.unfollowed', payload);
|
|
26960
|
-
return true;
|
|
26961
|
-
};
|
|
26962
|
-
/* end_public_function */
|
|
26963
|
-
|
|
26964
|
-
/**
|
|
26965
|
-
* @deprecated This API renamed to `acceptMyFollower`.
|
|
26966
|
-
* Please use acceptMyFollower() instead.
|
|
26967
|
-
*
|
|
26968
|
-
* ```js
|
|
26969
|
-
* import { acceptFollower } from '@amityco/ts-sdk'
|
|
26970
|
-
* await acceptFollower('foobar')
|
|
26971
|
-
* ```
|
|
26972
|
-
*
|
|
26973
|
-
* Accept the follow request
|
|
26974
|
-
*
|
|
26975
|
-
* @param userId the ID of the {@link Amity.InternalUser} follower
|
|
26976
|
-
* @returns A success boolean if the follow request was accepted
|
|
26977
|
-
*
|
|
26978
|
-
* @category Follow API
|
|
26979
|
-
* @async
|
|
26980
|
-
*/
|
|
26981
|
-
const acceptFollower = async (userId) => {
|
|
26982
|
-
const client = getActiveClient();
|
|
26983
|
-
client.log('follow/acceptFollower', userId);
|
|
26984
|
-
const { data } = await client.http.post(`/api/v4/me/followers/${userId}`);
|
|
26985
|
-
if (client.cache) {
|
|
26986
|
-
ingestInCache(data);
|
|
26987
|
-
}
|
|
26988
|
-
const payload = prepareFollowStatusPayload(data);
|
|
26989
|
-
fireEvent('local.follow.accepted', payload);
|
|
26990
|
-
return true;
|
|
26991
|
-
};
|
|
26992
|
-
|
|
26993
|
-
/* begin_public_function
|
|
26994
|
-
id: user.relationship.accept_follow
|
|
26995
|
-
*/
|
|
26996
|
-
/**
|
|
26997
|
-
* ```js
|
|
26998
|
-
* import { UserRepository } from '@amityco/ts-sdk'
|
|
26999
|
-
* await UserRepository.Relationship.acceptMyFollower('foobar')
|
|
27000
|
-
* ```
|
|
27001
|
-
*
|
|
27002
|
-
* Accept the follow request
|
|
27003
|
-
*
|
|
27004
|
-
* @param userId the ID of the {@link Amity.InternalUser} follower
|
|
27005
|
-
* @returns A success boolean if the follow request was accepted
|
|
27006
|
-
*
|
|
27007
|
-
* @category Follow API
|
|
27008
|
-
* @async
|
|
27009
|
-
*/
|
|
27010
|
-
const acceptMyFollower = async (userId) => {
|
|
27011
|
-
const client = getActiveClient();
|
|
27012
|
-
client.log('follow/acceptMyFollower', userId);
|
|
27013
|
-
const { data } = await client.http.post(`/api/v4/me/followers/${userId}`);
|
|
27014
|
-
if (client.cache) {
|
|
27015
|
-
ingestInCache(data);
|
|
26345
|
+
let token;
|
|
26346
|
+
if (direction === 'prev')
|
|
26347
|
+
token = this.previousToken;
|
|
26348
|
+
if (direction === 'next')
|
|
26349
|
+
token = this.nextToken;
|
|
26350
|
+
const queryResponse = await this.getRequest(this.queryParams, token);
|
|
26351
|
+
if (direction === 'first') {
|
|
26352
|
+
this.nextToken = (_a = queryResponse.paging) === null || _a === void 0 ? void 0 : _a.next;
|
|
26353
|
+
this.previousToken = (_b = queryResponse.paging) === null || _b === void 0 ? void 0 : _b.previous;
|
|
26354
|
+
}
|
|
26355
|
+
if (direction === 'prev')
|
|
26356
|
+
this.previousToken = (_c = queryResponse.paging) === null || _c === void 0 ? void 0 : _c.previous;
|
|
26357
|
+
if (direction === 'next')
|
|
26358
|
+
this.nextToken = (_d = queryResponse.paging) === null || _d === void 0 ? void 0 : _d.next;
|
|
26359
|
+
return queryResponse;
|
|
27016
26360
|
}
|
|
27017
|
-
|
|
27018
|
-
|
|
27019
|
-
return true;
|
|
27020
|
-
};
|
|
27021
|
-
/* end_public_function */
|
|
27022
|
-
|
|
27023
|
-
/**
|
|
27024
|
-
* @deprecated This API renamed to `declineMyFollower`.
|
|
27025
|
-
* Please use declineMyFollower() instead.
|
|
27026
|
-
*
|
|
27027
|
-
* ```js
|
|
27028
|
-
* import { declineFollower } from '@amityco/ts-sdk'
|
|
27029
|
-
* await declineFollower('foobar')
|
|
27030
|
-
* ```
|
|
27031
|
-
*
|
|
27032
|
-
* Decline the follow request or delete the follower
|
|
27033
|
-
*
|
|
27034
|
-
* @param userId the ID of the {@link Amity.InternalUser} follower
|
|
27035
|
-
* @returns A success boolean if the follow request was decline
|
|
27036
|
-
*
|
|
27037
|
-
* @category Follow API
|
|
27038
|
-
* @async
|
|
27039
|
-
*/
|
|
27040
|
-
const declineFollower = async (userId) => {
|
|
27041
|
-
const client = getActiveClient();
|
|
27042
|
-
client.log('follow/declineFollower', userId);
|
|
27043
|
-
const { data } = await client.http.delete(`/api/v4/me/followers/${userId}`);
|
|
27044
|
-
if (client.cache) {
|
|
27045
|
-
ingestInCache(data);
|
|
26361
|
+
getNextToken() {
|
|
26362
|
+
return this.nextToken;
|
|
27046
26363
|
}
|
|
27047
|
-
|
|
27048
|
-
|
|
27049
|
-
return true;
|
|
27050
|
-
};
|
|
27051
|
-
|
|
27052
|
-
/* begin_public_function
|
|
27053
|
-
id: user.relationship.decline_follow
|
|
27054
|
-
*/
|
|
27055
|
-
/**
|
|
27056
|
-
* ```js
|
|
27057
|
-
* import { UserRepository } from '@amityco/ts-sdk'
|
|
27058
|
-
* await UserRepository.Relationship.declineMyFollower('foobar')
|
|
27059
|
-
* ```
|
|
27060
|
-
*
|
|
27061
|
-
* Decline the follow request or delete the follower
|
|
27062
|
-
*
|
|
27063
|
-
* @param userId the ID of the {@link Amity.InternalUser} follower
|
|
27064
|
-
* @returns A success boolean if the follow request was decline
|
|
27065
|
-
*
|
|
27066
|
-
* @category Follow API
|
|
27067
|
-
* @async
|
|
27068
|
-
*/
|
|
27069
|
-
const declineMyFollower = async (userId) => {
|
|
27070
|
-
const client = getActiveClient();
|
|
27071
|
-
client.log('follow/declineMyFollower', userId);
|
|
27072
|
-
const { data } = await client.http.delete(`/api/v4/me/followers/${userId}`);
|
|
27073
|
-
if (client.cache) {
|
|
27074
|
-
ingestInCache(data);
|
|
26364
|
+
getPrevToken() {
|
|
26365
|
+
return this.previousToken;
|
|
27075
26366
|
}
|
|
27076
|
-
|
|
27077
|
-
fireEvent('local.follow.requestDeclined', payload);
|
|
27078
|
-
return true;
|
|
27079
|
-
};
|
|
27080
|
-
/* end_public_function */
|
|
27081
|
-
|
|
27082
|
-
/**
|
|
27083
|
-
* ```js
|
|
27084
|
-
* import { observeFollowInfo } from '@amityco/ts-sdk'
|
|
27085
|
-
*
|
|
27086
|
-
* let followInfo = {}
|
|
27087
|
-
* const dispose = observeFollowInfo(userId, updated => followInfo = updated)
|
|
27088
|
-
* ```
|
|
27089
|
-
*
|
|
27090
|
-
* Observe all mutation on a given {@link Amity.FollowInfo}
|
|
27091
|
-
*
|
|
27092
|
-
* @param userId the ID of the user to observe
|
|
27093
|
-
* @param callback the function to call when new data are available
|
|
27094
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the post
|
|
27095
|
-
*
|
|
27096
|
-
* @category Follow Observer
|
|
27097
|
-
*/
|
|
27098
|
-
const observeFollowInfo = (userId, callback, policy = 'cache_then_server') => {
|
|
27099
|
-
const { log } = getActiveClient();
|
|
27100
|
-
const timestamp = Date.now();
|
|
27101
|
-
log(`observeFollowInfo(tmpid: ${timestamp}) > listen`);
|
|
27102
|
-
const router = (result, action) => {
|
|
27103
|
-
var _a, _b;
|
|
27104
|
-
if (callback instanceof Function)
|
|
27105
|
-
return callback(result);
|
|
27106
|
-
if (action !== 'onFetch')
|
|
27107
|
-
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, result);
|
|
27108
|
-
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, result);
|
|
27109
|
-
};
|
|
27110
|
-
const realtimeRouter = (result, action) => {
|
|
27111
|
-
var _a;
|
|
27112
|
-
if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.userId) !== userId)
|
|
27113
|
-
return;
|
|
27114
|
-
router(result, action);
|
|
27115
|
-
};
|
|
27116
|
-
const disposers = [];
|
|
27117
|
-
disposers.push(onFollowInfoUpdated(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUpdate')));
|
|
27118
|
-
runQuery(createQuery(getFollowInfo$1, userId), result => (result.data || result.error) && router(result, 'onFetch'), queryOptions(policy));
|
|
27119
|
-
return () => {
|
|
27120
|
-
log(`observeFollowInfo(tmpid: ${timestamp}) > dispose`);
|
|
27121
|
-
disposers.forEach(fn => fn());
|
|
27122
|
-
};
|
|
27123
|
-
};
|
|
27124
|
-
|
|
27125
|
-
/**
|
|
27126
|
-
* ```js
|
|
27127
|
-
* import { observeFollowers } from '@amityco/ts-sdk'
|
|
27128
|
-
*
|
|
27129
|
-
* let followers = []
|
|
27130
|
-
* const unsub = observeFollowers('userId', follower => merge(followers, follower))
|
|
27131
|
-
* ```
|
|
27132
|
-
*
|
|
27133
|
-
* Observe all mutations on a list of followers {@link Amity.FollowStatus} for a given user
|
|
27134
|
-
*
|
|
27135
|
-
* @param userId the ID of the {@link Amity.InternalUser}
|
|
27136
|
-
* @param callback the function to call when new data are available
|
|
27137
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
27138
|
-
*
|
|
27139
|
-
* @category Follow Observer
|
|
27140
|
-
*/
|
|
27141
|
-
const observeFollowers = (userId, callback) => {
|
|
27142
|
-
const { log } = getActiveClient();
|
|
27143
|
-
const timestamp = Date.now();
|
|
27144
|
-
log(`observeFollowers(tmpid: ${timestamp}) > listen`);
|
|
27145
|
-
const disposers = [];
|
|
27146
|
-
const router = (status, action) => {
|
|
27147
|
-
var _a, _b;
|
|
27148
|
-
if (callback instanceof Function) {
|
|
27149
|
-
return callback(status);
|
|
27150
|
-
}
|
|
27151
|
-
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, status);
|
|
27152
|
-
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, status);
|
|
27153
|
-
};
|
|
27154
|
-
disposers.push(onFollowerRequested(x => router(x, 'onRequested')), onFollowRequestAccepted(x => router(x, 'onAccepted')), onFollowRequestDeclined(x => router(x, 'onDeclined')), onFollowRequestCanceled(x => router(x, 'onCanceled')), onUserFollowed(x => router(x, 'onFollowed')), onUserUnfollowed(x => router(x, 'onUnfollowed')), onFollowerDeleted(x => router(x, 'onDeleted')), onLocalFollowerRequested(x => router(x, 'onRequested')), onLocalFollowRequestAccepted(x => router(x, 'onAccepted')), onLocalFollowRequestDeclined(x => router(x, 'onDeclined')), onLocalUserFollowed(x => router(x, 'onFollowed')), onLocalUserUnfollowed(x => router(x, 'onUnfollowed')));
|
|
27155
|
-
return () => {
|
|
27156
|
-
log(`observeFollowers(tmpid: ${timestamp}) > dispose`);
|
|
27157
|
-
disposers.forEach(fn => fn());
|
|
27158
|
-
};
|
|
27159
|
-
};
|
|
27160
|
-
|
|
27161
|
-
/**
|
|
27162
|
-
* ```js
|
|
27163
|
-
* import { observeFollowings } from '@amityco/ts-sdk'
|
|
27164
|
-
*
|
|
27165
|
-
* let followings = []
|
|
27166
|
-
* const unsub = observeFollowers('userId', follower => merge(followings, following))
|
|
27167
|
-
* ```
|
|
27168
|
-
*
|
|
27169
|
-
* Observe all mutations on a list of followings {@link Amity.FollowStatus} for a given user
|
|
27170
|
-
*
|
|
27171
|
-
* @param userId the ID of the {@link Amity.InternalUser}
|
|
27172
|
-
* @param callback the function to call when new data are available
|
|
27173
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
27174
|
-
*
|
|
27175
|
-
* @category Follow Observer
|
|
27176
|
-
*/
|
|
27177
|
-
const observeFollowings = (userId, callback) => {
|
|
27178
|
-
const { log } = getActiveClient();
|
|
27179
|
-
const timestamp = Date.now();
|
|
27180
|
-
log(`observeFollowings(tmpid: ${timestamp}) > listen`);
|
|
27181
|
-
const disposers = [];
|
|
27182
|
-
const router = (status, action) => {
|
|
27183
|
-
var _a, _b;
|
|
27184
|
-
if (callback instanceof Function) {
|
|
27185
|
-
return callback(status);
|
|
27186
|
-
}
|
|
27187
|
-
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, status);
|
|
27188
|
-
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, status);
|
|
27189
|
-
};
|
|
27190
|
-
disposers.push(onFollowerRequested(x => router(x, 'onRequested')), onFollowRequestAccepted(x => router(x, 'onAccepted')), onFollowRequestDeclined(x => router(x, 'onDeclined')), onFollowRequestCanceled(x => router(x, 'onCanceled')), onUserFollowed(x => router(x, 'onFollowed')), onUserUnfollowed(x => router(x, 'onUnfollowed')), onFollowerDeleted(x => router(x, 'onDeleted')), onLocalFollowerRequested(x => router(x, 'onRequested')), onLocalFollowRequestAccepted(x => router(x, 'onAccepted')), onLocalFollowRequestDeclined(x => router(x, 'onDeclined')), onLocalUserFollowed(x => router(x, 'onFollowed')), onLocalUserUnfollowed(x => router(x, 'onUnfollowed')));
|
|
27191
|
-
return () => {
|
|
27192
|
-
log(`observeFollowings(tmpid: ${timestamp}) > dispose`);
|
|
27193
|
-
disposers.forEach(fn => fn());
|
|
27194
|
-
};
|
|
27195
|
-
};
|
|
26367
|
+
}
|
|
27196
26368
|
|
|
27197
26369
|
class FollowerPaginationController extends PaginationController {
|
|
27198
26370
|
async getRequest(queryParams, token) {
|
|
@@ -27207,6 +26379,25 @@ class FollowerPaginationController extends PaginationController {
|
|
|
27207
26379
|
}
|
|
27208
26380
|
}
|
|
27209
26381
|
|
|
26382
|
+
class QueryStreamController {
|
|
26383
|
+
constructor(query, cacheKey) {
|
|
26384
|
+
this.query = query;
|
|
26385
|
+
this.cacheKey = cacheKey;
|
|
26386
|
+
}
|
|
26387
|
+
}
|
|
26388
|
+
|
|
26389
|
+
var EnumFollowActions;
|
|
26390
|
+
(function (EnumFollowActions) {
|
|
26391
|
+
EnumFollowActions["OnRequested"] = "onRequested";
|
|
26392
|
+
EnumFollowActions["OnAccepted"] = "onAccepted";
|
|
26393
|
+
EnumFollowActions["OnDeclined"] = "onDeclined";
|
|
26394
|
+
EnumFollowActions["OnCanceled"] = "onCanceled";
|
|
26395
|
+
EnumFollowActions["OnFollowed"] = "onFollowed";
|
|
26396
|
+
EnumFollowActions["OnUnfollowed"] = "onUnfollowed";
|
|
26397
|
+
EnumFollowActions["OnDeleted"] = "onDeleted";
|
|
26398
|
+
EnumFollowActions["OnUserDeleted"] = "onUserDeleted";
|
|
26399
|
+
})(EnumFollowActions || (EnumFollowActions = {}));
|
|
26400
|
+
|
|
27210
26401
|
class FollowerQueryStreamController extends QueryStreamController {
|
|
27211
26402
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
27212
26403
|
super(query, cacheKey);
|
|
@@ -27262,6 +26453,109 @@ class FollowerQueryStreamController extends QueryStreamController {
|
|
|
27262
26453
|
}
|
|
27263
26454
|
}
|
|
27264
26455
|
|
|
26456
|
+
class PaginationNoPageController {
|
|
26457
|
+
constructor(queryParams) {
|
|
26458
|
+
const { http } = getActiveClient();
|
|
26459
|
+
this.queryParams = queryParams;
|
|
26460
|
+
this.http = http;
|
|
26461
|
+
}
|
|
26462
|
+
async onFetch() {
|
|
26463
|
+
const queryResponse = await this.getRequest(this.queryParams);
|
|
26464
|
+
return queryResponse;
|
|
26465
|
+
}
|
|
26466
|
+
}
|
|
26467
|
+
|
|
26468
|
+
class LiveCollectionController {
|
|
26469
|
+
constructor(paginationController, queryStreamId, cacheKey, callback) {
|
|
26470
|
+
this.paginationController = paginationController;
|
|
26471
|
+
this.queryStreamId = queryStreamId;
|
|
26472
|
+
this.cacheKey = cacheKey;
|
|
26473
|
+
this.callback = callback;
|
|
26474
|
+
}
|
|
26475
|
+
async refresh() {
|
|
26476
|
+
try {
|
|
26477
|
+
let result;
|
|
26478
|
+
if (this.paginationController instanceof PaginationNoPageController) {
|
|
26479
|
+
result = await this.paginationController.onFetch();
|
|
26480
|
+
}
|
|
26481
|
+
else {
|
|
26482
|
+
result = await this.paginationController.loadFirstPage();
|
|
26483
|
+
}
|
|
26484
|
+
if (!result)
|
|
26485
|
+
return;
|
|
26486
|
+
await this.persistModel(result);
|
|
26487
|
+
this.persistQueryStream({
|
|
26488
|
+
response: result,
|
|
26489
|
+
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
26490
|
+
refresh: true,
|
|
26491
|
+
});
|
|
26492
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
26493
|
+
}
|
|
26494
|
+
catch (e) {
|
|
26495
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
26496
|
+
}
|
|
26497
|
+
}
|
|
26498
|
+
loadPage({ initial = false, direction = "next" /* Amity.LiveCollectionPageDirection.NEXT */, }) {
|
|
26499
|
+
this.setup();
|
|
26500
|
+
this.notifyChange({ origin: "local" /* Amity.LiveDataOrigin.LOCAL */, loading: true });
|
|
26501
|
+
if (initial) {
|
|
26502
|
+
this.refresh();
|
|
26503
|
+
}
|
|
26504
|
+
else if (direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */) {
|
|
26505
|
+
this.loadPrevPage();
|
|
26506
|
+
}
|
|
26507
|
+
else if (direction === "next" /* Amity.LiveCollectionPageDirection.NEXT */) {
|
|
26508
|
+
this.loadNextPage();
|
|
26509
|
+
}
|
|
26510
|
+
}
|
|
26511
|
+
async loadNextPage() {
|
|
26512
|
+
try {
|
|
26513
|
+
if (this.paginationController instanceof PaginationNoPageController)
|
|
26514
|
+
return;
|
|
26515
|
+
const result = await this.paginationController.loadNextPage();
|
|
26516
|
+
if (!result)
|
|
26517
|
+
return;
|
|
26518
|
+
await this.persistModel(result);
|
|
26519
|
+
this.persistQueryStream({
|
|
26520
|
+
response: result,
|
|
26521
|
+
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
26522
|
+
});
|
|
26523
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
26524
|
+
}
|
|
26525
|
+
catch (e) {
|
|
26526
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
26527
|
+
}
|
|
26528
|
+
}
|
|
26529
|
+
async loadPrevPage() {
|
|
26530
|
+
try {
|
|
26531
|
+
if (this.paginationController instanceof PaginationNoPageController)
|
|
26532
|
+
return;
|
|
26533
|
+
const result = await this.paginationController.loadPreviousPage();
|
|
26534
|
+
if (!result)
|
|
26535
|
+
return;
|
|
26536
|
+
await this.persistModel(result);
|
|
26537
|
+
this.persistQueryStream({
|
|
26538
|
+
response: result,
|
|
26539
|
+
direction: "prev" /* Amity.LiveCollectionPageDirection.PREV */,
|
|
26540
|
+
});
|
|
26541
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
26542
|
+
}
|
|
26543
|
+
catch (e) {
|
|
26544
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
26545
|
+
}
|
|
26546
|
+
}
|
|
26547
|
+
shouldNotify(data) {
|
|
26548
|
+
const newData = data.map(convertGetterPropsToStatic).map(removeFunctionProperties);
|
|
26549
|
+
if (isEqual(this.snapshot, newData))
|
|
26550
|
+
return false;
|
|
26551
|
+
this.snapshot = newData;
|
|
26552
|
+
return true;
|
|
26553
|
+
}
|
|
26554
|
+
getCacheKey() {
|
|
26555
|
+
return this.cacheKey;
|
|
26556
|
+
}
|
|
26557
|
+
}
|
|
26558
|
+
|
|
27265
26559
|
const onFollowerUserDeleted = ({ userId }) => (callback) => {
|
|
27266
26560
|
const client = getActiveClient();
|
|
27267
26561
|
const filter = (data) => {
|
|
@@ -27606,6 +26900,69 @@ const getFollowings = (params, callback, config) => {
|
|
|
27606
26900
|
};
|
|
27607
26901
|
/* end_public_function */
|
|
27608
26902
|
|
|
26903
|
+
/**
|
|
26904
|
+
* @deprecated This function will to be deprecated soon.
|
|
26905
|
+
*/
|
|
26906
|
+
const liveObject = (id, callback, key, fetcher, eventHandlers, options) => {
|
|
26907
|
+
const { forceDispatch, callbackDataSelector, callbackFilter } = Object.assign({ forceDispatch: false, callbackDataSelector: (data) => data }, options);
|
|
26908
|
+
const { cache } = getActiveClient();
|
|
26909
|
+
if (!cache) {
|
|
26910
|
+
console.log(LIVE_OBJECT_ENABLE_CACHE_MESSAGE);
|
|
26911
|
+
}
|
|
26912
|
+
let model;
|
|
26913
|
+
let isUnsyncedModel = false; // for messages
|
|
26914
|
+
const disposers = [];
|
|
26915
|
+
const dispatcher = (data) => {
|
|
26916
|
+
const { data: newModel } = data, rest = __rest(data, ["data"]);
|
|
26917
|
+
if (!callbackFilter || callbackFilter(newModel, model)) {
|
|
26918
|
+
callback(Object.assign({ data: callbackDataSelector(newModel) }, rest));
|
|
26919
|
+
}
|
|
26920
|
+
// resolve all getter on data model to a static value to avoid comparison problems
|
|
26921
|
+
model = convertGetterPropsToStatic(newModel);
|
|
26922
|
+
};
|
|
26923
|
+
const realtimeRouter = (eventModel, forceDispatch = false) => {
|
|
26924
|
+
if (id !== eventModel[key]) {
|
|
26925
|
+
return;
|
|
26926
|
+
}
|
|
26927
|
+
if (model) {
|
|
26928
|
+
if (!forceDispatch && isEqual(model, eventModel)) {
|
|
26929
|
+
return;
|
|
26930
|
+
}
|
|
26931
|
+
}
|
|
26932
|
+
dispatcher({ loading: false, data: eventModel, origin: 'event' });
|
|
26933
|
+
};
|
|
26934
|
+
const onFetch = () => {
|
|
26935
|
+
// TODO: Ihis `@ts-ignore` is bring back to fix the build and it needs to be removed later
|
|
26936
|
+
// @ts-ignore
|
|
26937
|
+
const query = createQuery(fetcher, id, true);
|
|
26938
|
+
runQuery(query, ({ error, data, loading, origin, cachedAt }) => {
|
|
26939
|
+
if (cachedAt === UNSYNCED_OBJECT_CACHED_AT_VALUE) {
|
|
26940
|
+
dispatcher({
|
|
26941
|
+
// @ts-ignore
|
|
26942
|
+
data,
|
|
26943
|
+
origin,
|
|
26944
|
+
loading: false,
|
|
26945
|
+
error: new ASCApiError(UNSYNCED_OBJECT_CACHED_AT_MESSAGE, 800800 /* Amity.ClientError.DISALOOW_UNSYNCED_OBJECT */, "error" /* Amity.ErrorLevel.ERROR */),
|
|
26946
|
+
});
|
|
26947
|
+
isUnsyncedModel = true;
|
|
26948
|
+
disposers.forEach(fn => fn());
|
|
26949
|
+
}
|
|
26950
|
+
else if (!isUnsyncedModel) {
|
|
26951
|
+
// @ts-ignore
|
|
26952
|
+
dispatcher({ loading, data, origin, error });
|
|
26953
|
+
}
|
|
26954
|
+
if (error) {
|
|
26955
|
+
disposers.forEach(fn => fn());
|
|
26956
|
+
}
|
|
26957
|
+
});
|
|
26958
|
+
};
|
|
26959
|
+
disposers.push(...eventHandlers.map(fn => fn(eventModel => realtimeRouter(eventModel, forceDispatch))));
|
|
26960
|
+
onFetch();
|
|
26961
|
+
return () => {
|
|
26962
|
+
disposers.forEach(fn => fn());
|
|
26963
|
+
};
|
|
26964
|
+
};
|
|
26965
|
+
|
|
27609
26966
|
/* begin_public_function
|
|
27610
26967
|
id: user.relationship.get_follow_info
|
|
27611
26968
|
*/
|
|
@@ -27671,12 +27028,9 @@ var index$k = /*#__PURE__*/Object.freeze({
|
|
|
27671
27028
|
__proto__: null,
|
|
27672
27029
|
blockUser: blockUser,
|
|
27673
27030
|
unBlockUser: unBlockUser,
|
|
27674
|
-
getBlockedUsers: getBlockedUsers,
|
|
27675
27031
|
follow: follow,
|
|
27676
27032
|
unfollow: unfollow,
|
|
27677
|
-
acceptFollower: acceptFollower,
|
|
27678
27033
|
acceptMyFollower: acceptMyFollower,
|
|
27679
|
-
declineFollower: declineFollower,
|
|
27680
27034
|
declineMyFollower: declineMyFollower,
|
|
27681
27035
|
onUserFollowed: onUserFollowed,
|
|
27682
27036
|
onUserUnfollowed: onUserUnfollowed,
|
|
@@ -27691,9 +27045,6 @@ var index$k = /*#__PURE__*/Object.freeze({
|
|
|
27691
27045
|
onLocalFollowerRequested: onLocalFollowerRequested,
|
|
27692
27046
|
onLocalFollowRequestAccepted: onLocalFollowRequestAccepted,
|
|
27693
27047
|
onLocalFollowRequestDeclined: onLocalFollowRequestDeclined,
|
|
27694
|
-
observeFollowInfo: observeFollowInfo,
|
|
27695
|
-
observeFollowers: observeFollowers,
|
|
27696
|
-
observeFollowings: observeFollowings,
|
|
27697
27048
|
getFollowers: getFollowers,
|
|
27698
27049
|
getFollowings: getFollowings,
|
|
27699
27050
|
getFollowInfo: getFollowInfo,
|
|
@@ -27881,6 +27232,74 @@ const isUserFlaggedByMe = async (userId) => {
|
|
|
27881
27232
|
};
|
|
27882
27233
|
/* end_public_function */
|
|
27883
27234
|
|
|
27235
|
+
/**
|
|
27236
|
+
* ```js
|
|
27237
|
+
* import { onUserUpdated } from '@amityco/ts-sdk'
|
|
27238
|
+
* const dispose = onUserUpdated(user => {
|
|
27239
|
+
* // ...
|
|
27240
|
+
* })
|
|
27241
|
+
* ```
|
|
27242
|
+
*
|
|
27243
|
+
* Fired when a {@link Amity.InternalUser} has been updated
|
|
27244
|
+
*
|
|
27245
|
+
* @param callback The function to call when the event was fired
|
|
27246
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
27247
|
+
*
|
|
27248
|
+
* @category User Events
|
|
27249
|
+
*/
|
|
27250
|
+
const onUserUpdated = (callback) => createUserEventSubscriber('user.updated', callback);
|
|
27251
|
+
|
|
27252
|
+
/**
|
|
27253
|
+
* ```js
|
|
27254
|
+
* import { onUserFlagged } from '@amityco/ts-sdk'
|
|
27255
|
+
* const dispose = onUserFlagged(user => {
|
|
27256
|
+
* // ...
|
|
27257
|
+
* })
|
|
27258
|
+
* ```
|
|
27259
|
+
*
|
|
27260
|
+
* Fired when a {@link Amity.InternalUser} has been flagged
|
|
27261
|
+
*
|
|
27262
|
+
* @param callback The function to call when the event was fired
|
|
27263
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
27264
|
+
*
|
|
27265
|
+
* @category User Events
|
|
27266
|
+
*/
|
|
27267
|
+
const onUserFlagged = (callback) => createUserEventSubscriber('user.flagged', callback);
|
|
27268
|
+
|
|
27269
|
+
/**
|
|
27270
|
+
* ```js
|
|
27271
|
+
* import { onUserUnflagged } from '@amityco/ts-sdk'
|
|
27272
|
+
* const dispose = onUserUnflagged(user => {
|
|
27273
|
+
* // ...
|
|
27274
|
+
* })
|
|
27275
|
+
* ```
|
|
27276
|
+
*
|
|
27277
|
+
* Fired when a flag has been removed from a {@link Amity.InternalUser}
|
|
27278
|
+
*
|
|
27279
|
+
* @param callback The function to call when the event was fired
|
|
27280
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
27281
|
+
*
|
|
27282
|
+
* @category User Events
|
|
27283
|
+
*/
|
|
27284
|
+
const onUserUnflagged = (callback) => createUserEventSubscriber('user.unflagged', callback);
|
|
27285
|
+
|
|
27286
|
+
/**
|
|
27287
|
+
* ```js
|
|
27288
|
+
* import { onUserFlagCleared } from '@amityco/ts-sdk'
|
|
27289
|
+
* const dispose = onUserFlagCleared(user => {
|
|
27290
|
+
* // ...
|
|
27291
|
+
* })
|
|
27292
|
+
* ```
|
|
27293
|
+
*
|
|
27294
|
+
* Fired when flags have been cleared for a {@link Amity.InternalUser}
|
|
27295
|
+
*
|
|
27296
|
+
* @param callback The function to call when the event was fired
|
|
27297
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
27298
|
+
*
|
|
27299
|
+
* @category User Events
|
|
27300
|
+
*/
|
|
27301
|
+
const onUserFlagCleared = (callback) => createUserEventSubscriber('user.flagCleared', callback);
|
|
27302
|
+
|
|
27884
27303
|
/**
|
|
27885
27304
|
* ```js
|
|
27886
27305
|
* import { onUserFetched } from '@amityco/ts-sdk'
|
|
@@ -27912,7 +27331,7 @@ const onUserFetched = (callback) => createUserEventSubscriber('user.fetched', ca
|
|
|
27912
27331
|
* @category Private
|
|
27913
27332
|
* @async
|
|
27914
27333
|
*/
|
|
27915
|
-
const getUser$
|
|
27334
|
+
const getUser$1 = async (userId) => {
|
|
27916
27335
|
const client = getActiveClient();
|
|
27917
27336
|
client.log('user/getUser', userId);
|
|
27918
27337
|
isInTombstone('user', userId);
|
|
@@ -27948,7 +27367,7 @@ const getUser$2 = async (userId) => {
|
|
|
27948
27367
|
*
|
|
27949
27368
|
* @category User API
|
|
27950
27369
|
*/
|
|
27951
|
-
getUser$
|
|
27370
|
+
getUser$1.locally = (userId) => {
|
|
27952
27371
|
const client = getActiveClient();
|
|
27953
27372
|
client.log('user/getUser.locally', userId);
|
|
27954
27373
|
if (!client.cache)
|
|
@@ -27984,11 +27403,11 @@ getUser$2.locally = (userId) => {
|
|
|
27984
27403
|
*
|
|
27985
27404
|
* @category Message Live Object
|
|
27986
27405
|
*/
|
|
27987
|
-
const getUser
|
|
27406
|
+
const getUser = (userId, callback) => {
|
|
27988
27407
|
const reactor = (response) => {
|
|
27989
27408
|
return callback(Object.assign(Object.assign({}, response), { data: response.data ? LinkedObject.user(response.data) : response.data }));
|
|
27990
27409
|
};
|
|
27991
|
-
return liveObject(userId, reactor, 'userId', getUser$
|
|
27410
|
+
return liveObject(userId, reactor, 'userId', getUser$1, [
|
|
27992
27411
|
onUserFetched,
|
|
27993
27412
|
onUserUpdated,
|
|
27994
27413
|
onUserDeleted$2,
|
|
@@ -28001,10 +27420,10 @@ const getUser$1 = (userId, callback) => {
|
|
|
28001
27420
|
|
|
28002
27421
|
class UserPaginationController extends PaginationController {
|
|
28003
27422
|
async getRequest(queryParams, token) {
|
|
28004
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT
|
|
27423
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
28005
27424
|
const options = token ? { token } : { limit };
|
|
28006
27425
|
const { data: queryResponse } = await this.http.get(`/api/v3/users`, {
|
|
28007
|
-
params: Object.assign(Object.assign({}, params), {
|
|
27426
|
+
params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
|
|
28008
27427
|
});
|
|
28009
27428
|
return queryResponse;
|
|
28010
27429
|
}
|
|
@@ -28056,6 +27475,15 @@ class UserQueryStreamController extends QueryStreamController {
|
|
|
28056
27475
|
}
|
|
28057
27476
|
}
|
|
28058
27477
|
|
|
27478
|
+
var EnumUserActions;
|
|
27479
|
+
(function (EnumUserActions) {
|
|
27480
|
+
EnumUserActions["OnUserDeleted"] = "onUserDeleted";
|
|
27481
|
+
EnumUserActions["OnUserUpdated"] = "onUserUpdated";
|
|
27482
|
+
EnumUserActions["OnUserFlagged"] = "onUserFlagged";
|
|
27483
|
+
EnumUserActions["OnUserUnflagged"] = "onUserUnflagged";
|
|
27484
|
+
EnumUserActions["OnUserFlagCleared"] = "onUserFlagCleared";
|
|
27485
|
+
})(EnumUserActions || (EnumUserActions = {}));
|
|
27486
|
+
|
|
28059
27487
|
class UserLiveCollectionController extends LiveCollectionController {
|
|
28060
27488
|
constructor(query, callback) {
|
|
28061
27489
|
const queryStreamId = hash(query);
|
|
@@ -28114,21 +27542,17 @@ class UserLiveCollectionController extends LiveCollectionController {
|
|
|
28114
27542
|
}
|
|
28115
27543
|
applyFilter(data) {
|
|
28116
27544
|
let users = data;
|
|
28117
|
-
|
|
28118
|
-
|
|
28119
|
-
|
|
28120
|
-
|
|
28121
|
-
|
|
28122
|
-
|
|
28123
|
-
|
|
28124
|
-
|
|
28125
|
-
|
|
28126
|
-
|
|
28127
|
-
|
|
28128
|
-
}
|
|
28129
|
-
})();
|
|
28130
|
-
users = users.sort(sortFn);
|
|
28131
|
-
}
|
|
27545
|
+
const sortFn = (() => {
|
|
27546
|
+
switch (this.query.sortBy) {
|
|
27547
|
+
case 'firstCreated':
|
|
27548
|
+
return sortByFirstCreated;
|
|
27549
|
+
case 'lastCreated':
|
|
27550
|
+
return sortByLastCreated;
|
|
27551
|
+
default:
|
|
27552
|
+
return sortByLastCreated;
|
|
27553
|
+
}
|
|
27554
|
+
})();
|
|
27555
|
+
users = users.sort(sortFn);
|
|
28132
27556
|
if (this.query.filter === 'flagged') {
|
|
28133
27557
|
users = users.filter(user => !!user.hashFlag);
|
|
28134
27558
|
}
|
|
@@ -28175,90 +27599,200 @@ const getUsers = (params, callback, config) => {
|
|
|
28175
27599
|
};
|
|
28176
27600
|
/* end_public_function */
|
|
28177
27601
|
|
|
28178
|
-
|
|
28179
|
-
|
|
28180
|
-
|
|
28181
|
-
|
|
28182
|
-
|
|
28183
|
-
|
|
28184
|
-
|
|
28185
|
-
|
|
28186
|
-
|
|
28187
|
-
|
|
28188
|
-
|
|
28189
|
-
|
|
28190
|
-
|
|
28191
|
-
|
|
28192
|
-
|
|
28193
|
-
|
|
28194
|
-
|
|
28195
|
-
|
|
28196
|
-
|
|
28197
|
-
|
|
28198
|
-
|
|
28199
|
-
|
|
28200
|
-
|
|
28201
|
-
|
|
28202
|
-
|
|
28203
|
-
|
|
28204
|
-
|
|
28205
|
-
|
|
28206
|
-
|
|
28207
|
-
|
|
28208
|
-
|
|
28209
|
-
|
|
28210
|
-
|
|
28211
|
-
|
|
28212
|
-
|
|
28213
|
-
|
|
28214
|
-
|
|
27602
|
+
class BlockedUserPaginationController extends PaginationController {
|
|
27603
|
+
async getRequest(queryParams, token) {
|
|
27604
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
27605
|
+
const options = token ? { token } : { limit };
|
|
27606
|
+
const { data: queryResponse } = await this.http.get('/api/v4/me/user-blocks', {
|
|
27607
|
+
params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
|
|
27608
|
+
});
|
|
27609
|
+
return queryResponse;
|
|
27610
|
+
}
|
|
27611
|
+
}
|
|
27612
|
+
|
|
27613
|
+
class BlockedUserQueryStreamController extends QueryStreamController {
|
|
27614
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
27615
|
+
super(query, cacheKey);
|
|
27616
|
+
this.notifyChange = notifyChange;
|
|
27617
|
+
this.preparePayload = preparePayload;
|
|
27618
|
+
}
|
|
27619
|
+
async saveToMainDB(response) {
|
|
27620
|
+
const processedPayload = await this.preparePayload(response);
|
|
27621
|
+
const client = getActiveClient();
|
|
27622
|
+
const cachedAt = client.cache && Date.now();
|
|
27623
|
+
if (client.cache) {
|
|
27624
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
27625
|
+
}
|
|
27626
|
+
}
|
|
27627
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
27628
|
+
var _a, _b;
|
|
27629
|
+
if (refresh) {
|
|
27630
|
+
pushToCache(this.cacheKey, {
|
|
27631
|
+
data: response.users.map(getResolver('user')),
|
|
27632
|
+
});
|
|
27633
|
+
}
|
|
27634
|
+
else {
|
|
27635
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27636
|
+
const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
27637
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...users, ...response.users.map(getResolver('user'))])] }));
|
|
27638
|
+
}
|
|
27639
|
+
}
|
|
27640
|
+
reactor(action) {
|
|
27641
|
+
return (targetUser) => {
|
|
27642
|
+
var _a;
|
|
27643
|
+
if (action === EnumFollowActions.OnFollowed) {
|
|
27644
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27645
|
+
const updatedCollection = collection === null || collection === void 0 ? void 0 : collection.data.filter(id => id !== targetUser.userId);
|
|
27646
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: updatedCollection }));
|
|
27647
|
+
}
|
|
27648
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
27649
|
+
};
|
|
27650
|
+
}
|
|
27651
|
+
subscribeRTE(createSubscriber) {
|
|
27652
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
27653
|
+
}
|
|
27654
|
+
}
|
|
27655
|
+
|
|
27656
|
+
function prepareBlockedUserPayload(response) {
|
|
27657
|
+
const { users, follows } = response, rest = __rest(response, ["users", "follows"]);
|
|
27658
|
+
return Object.assign(Object.assign({}, rest), { follows: follows.map(follow => {
|
|
27659
|
+
const followUser = users.find(user => user.userId === follow.from);
|
|
27660
|
+
return Object.assign(Object.assign({}, follow), { user: convertRawUserToInternalUser(followUser) });
|
|
27661
|
+
}), users: users.map(convertRawUserToInternalUser) });
|
|
27662
|
+
}
|
|
27663
|
+
|
|
27664
|
+
const convertEventPayload = (eventHandler, sourceModelProp, destinationDomain) => (callback) => eventHandler(sourceModel => {
|
|
27665
|
+
var _a, _b;
|
|
27666
|
+
if (!sourceModel) {
|
|
27667
|
+
return sourceModel;
|
|
27668
|
+
}
|
|
27669
|
+
const client = getActiveClient();
|
|
27670
|
+
const { objectSyncMap } = client;
|
|
27671
|
+
/*
|
|
27672
|
+
* NOTE: For objects created locally (optimistic creation), the SDK stores them with their local ID as the cache key, which is used throughout the entire SDK session (in-memory) for syncing updates.
|
|
27673
|
+
* If the payload or response only contains the remote ID of the same object, the SDK will look up the corresponding local ID to retrieve the object.
|
|
27674
|
+
*/
|
|
27675
|
+
const resolvedId = isLocalId(sourceModel[sourceModelProp])
|
|
27676
|
+
? sourceModel[sourceModelProp]
|
|
27677
|
+
: (_a = objectSyncMap.get(sourceModel[sourceModelProp])) !== null && _a !== void 0 ? _a : sourceModel[sourceModelProp];
|
|
27678
|
+
const model = (_b = pullFromCache([
|
|
27679
|
+
destinationDomain,
|
|
27680
|
+
'get',
|
|
27681
|
+
`${resolvedId}`,
|
|
27682
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
27683
|
+
if (!model)
|
|
28215
27684
|
return;
|
|
28216
|
-
return
|
|
28217
|
-
|
|
28218
|
-
cachedAt: cached.cachedAt,
|
|
28219
|
-
};
|
|
28220
|
-
};
|
|
27685
|
+
return callback(model);
|
|
27686
|
+
});
|
|
28221
27687
|
|
|
27688
|
+
class BlockedUserLiveCollectionController extends LiveCollectionController {
|
|
27689
|
+
constructor(query, callback) {
|
|
27690
|
+
const queryStreamId = hash(query);
|
|
27691
|
+
const cacheKey = ['blockedUsers', 'collection', queryStreamId];
|
|
27692
|
+
const paginationController = new BlockedUserPaginationController(query);
|
|
27693
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
27694
|
+
this.query = query;
|
|
27695
|
+
this.queryStreamController = new BlockedUserQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareBlockedUserPayload);
|
|
27696
|
+
this.callback = callback.bind(this);
|
|
27697
|
+
this.loadPage({ initial: true });
|
|
27698
|
+
}
|
|
27699
|
+
setup() {
|
|
27700
|
+
var _a;
|
|
27701
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27702
|
+
if (!collection) {
|
|
27703
|
+
pushToCache(this.cacheKey, {
|
|
27704
|
+
data: [],
|
|
27705
|
+
params: {},
|
|
27706
|
+
});
|
|
27707
|
+
}
|
|
27708
|
+
}
|
|
27709
|
+
async persistModel(queryPayload) {
|
|
27710
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
27711
|
+
}
|
|
27712
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
27713
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
27714
|
+
}
|
|
27715
|
+
startSubscription() {
|
|
27716
|
+
return this.queryStreamController.subscribeRTE([
|
|
27717
|
+
{
|
|
27718
|
+
fn: onUserDeleted$2,
|
|
27719
|
+
action: EnumUserActions.OnUserDeleted,
|
|
27720
|
+
},
|
|
27721
|
+
// In the case of unblocking a user, we need to subscribe to the follow events
|
|
27722
|
+
{
|
|
27723
|
+
fn: convertEventPayload(onLocalUserFollowed, 'to', 'user'),
|
|
27724
|
+
action: EnumFollowActions.OnFollowed,
|
|
27725
|
+
},
|
|
27726
|
+
{
|
|
27727
|
+
fn: convertEventPayload(onUserFollowed, 'to', 'user'),
|
|
27728
|
+
action: EnumFollowActions.OnFollowed,
|
|
27729
|
+
},
|
|
27730
|
+
]);
|
|
27731
|
+
}
|
|
27732
|
+
notifyChange({ origin, loading, error }) {
|
|
27733
|
+
var _a, _b;
|
|
27734
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27735
|
+
if (!collection)
|
|
27736
|
+
return;
|
|
27737
|
+
const data = this.applyFilter((_b = collection.data
|
|
27738
|
+
.map(id => pullFromCache(['user', 'get', id]))
|
|
27739
|
+
.filter(isNonNullable)
|
|
27740
|
+
.map(({ data }) => data)
|
|
27741
|
+
.map(LinkedObject.user)) !== null && _b !== void 0 ? _b : []);
|
|
27742
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
27743
|
+
return;
|
|
27744
|
+
this.callback({
|
|
27745
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
27746
|
+
data,
|
|
27747
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
27748
|
+
loading,
|
|
27749
|
+
error,
|
|
27750
|
+
});
|
|
27751
|
+
}
|
|
27752
|
+
// eslint-disable-next-line class-methods-use-this
|
|
27753
|
+
applyFilter(data) {
|
|
27754
|
+
let users = data;
|
|
27755
|
+
users = users.filter(user => user.isDeleted == null || user.isDeleted === false);
|
|
27756
|
+
return users;
|
|
27757
|
+
}
|
|
27758
|
+
}
|
|
27759
|
+
|
|
27760
|
+
/* begin_public_function
|
|
27761
|
+
id: user.get_blocked_users
|
|
27762
|
+
*/
|
|
28222
27763
|
/**
|
|
28223
27764
|
* ```js
|
|
28224
|
-
* import {
|
|
28225
|
-
*
|
|
28226
|
-
* let user = {}
|
|
28227
|
-
* const dispose = observeUser(userId, updated => user = updated)
|
|
27765
|
+
* import { UserRepository } from '@amityco/ts-sdk'
|
|
27766
|
+
* const unblockedUser = await UserRepository.blockUser('userId')
|
|
28228
27767
|
* ```
|
|
28229
27768
|
*
|
|
28230
|
-
*
|
|
28231
|
-
*
|
|
28232
|
-
* @
|
|
27769
|
+
* Blocks a {@link Amity.InternalUser}
|
|
27770
|
+
*
|
|
27771
|
+
* @param params The params to get blocked {@link Amity.InternalUser}s
|
|
27772
|
+
* @param callback to recieve updates on unblocked {@link Amity.InternalUser}s
|
|
27773
|
+
* @returns {@link Amity.Unsubscriber} to unsubscribe from collection
|
|
28233
27774
|
*
|
|
28234
|
-
*
|
|
28235
|
-
* @
|
|
27775
|
+
* @category Post API
|
|
27776
|
+
* @async
|
|
28236
27777
|
*/
|
|
28237
|
-
const
|
|
28238
|
-
const { log } = getActiveClient();
|
|
27778
|
+
const getBlockedUsers = (params, callback, config) => {
|
|
27779
|
+
const { log, cache } = getActiveClient();
|
|
27780
|
+
if (!cache) {
|
|
27781
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
27782
|
+
}
|
|
28239
27783
|
const timestamp = Date.now();
|
|
28240
|
-
log(`
|
|
28241
|
-
|
|
28242
|
-
const
|
|
28243
|
-
|
|
28244
|
-
|
|
28245
|
-
if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.userId) !== userId)
|
|
28246
|
-
return;
|
|
28247
|
-
const newResult = Object.assign(Object.assign({}, result), { data: LinkedObject.user(result.data) });
|
|
28248
|
-
if (callback instanceof Function)
|
|
28249
|
-
return callback(newResult);
|
|
28250
|
-
if (action !== 'onFetch')
|
|
28251
|
-
(_b = callback.onEvent) === null || _b === void 0 ? void 0 : _b.call(callback, action, newResult);
|
|
28252
|
-
(_c = callback[action]) === null || _c === void 0 ? void 0 : _c.call(callback, newResult);
|
|
28253
|
-
};
|
|
28254
|
-
const disposers = [];
|
|
28255
|
-
disposers.push(onUserUpdated(data => router({ data, loading: false, origin: 'event' }, 'onUpdate')), onUserDeleted$2(data => router({ data, loading: false, origin: 'event' }, 'onDelete')), onUserFlagged(data => router({ data, loading: false, origin: 'event' }, 'onFlagged')), onUserUnflagged(data => router({ data, loading: false, origin: 'event' }, 'onUnflagged')), onUserFlagCleared(data => router({ data, loading: false, origin: 'event' }, 'onFlagCleared')));
|
|
28256
|
-
runQuery(createQuery(getUser, userId), result => result.data && router(result, 'onFetch'));
|
|
27784
|
+
log(`getBlockedUsers(tmpid: ${timestamp}) > listen`);
|
|
27785
|
+
const blockedUserLiveCollection = new BlockedUserLiveCollectionController(params, callback);
|
|
27786
|
+
const disposers = blockedUserLiveCollection.startSubscription();
|
|
27787
|
+
const cacheKey = blockedUserLiveCollection.getCacheKey();
|
|
27788
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
28257
27789
|
return () => {
|
|
28258
|
-
log(`
|
|
27790
|
+
log(`getBlockedUsers(tmpid: ${timestamp}) > dispose`);
|
|
28259
27791
|
disposers.forEach(fn => fn());
|
|
27792
|
+
dropFromCache(cacheKey);
|
|
28260
27793
|
};
|
|
28261
|
-
};
|
|
27794
|
+
};
|
|
27795
|
+
/* end_public_function */
|
|
28262
27796
|
|
|
28263
27797
|
class SearchUserPaginationController extends PaginationController {
|
|
28264
27798
|
async getRequest(queryParams, token) {
|
|
@@ -28443,74 +27977,6 @@ const queryReachUser = async ({ viewId, viewedType, limit, token, }) => {
|
|
|
28443
27977
|
return response.data;
|
|
28444
27978
|
};
|
|
28445
27979
|
|
|
28446
|
-
/**
|
|
28447
|
-
* @deprecated: Please use {@link UserRepository.getReachUsers} instead
|
|
28448
|
-
* @param params
|
|
28449
|
-
* @param callback
|
|
28450
|
-
*/
|
|
28451
|
-
const getViewedUsers = (params, callback) => {
|
|
28452
|
-
const { log, cache } = getActiveClient();
|
|
28453
|
-
const cacheKey = ['postViewedUsers', 'collection', { postId: params.postId }];
|
|
28454
|
-
if (!cache) {
|
|
28455
|
-
console.log(ENABLE_CACHE_MESSAGE);
|
|
28456
|
-
}
|
|
28457
|
-
const timestamp = Date.now();
|
|
28458
|
-
log(`getViewedUsers(tmpid: ${timestamp}) > listen`);
|
|
28459
|
-
const { limit: queryLimit, postId } = params;
|
|
28460
|
-
const responder = (snapshot) => {
|
|
28461
|
-
var _a, _b;
|
|
28462
|
-
let users = [];
|
|
28463
|
-
if (snapshot === null || snapshot === void 0 ? void 0 : snapshot.data) {
|
|
28464
|
-
users =
|
|
28465
|
-
snapshot.data
|
|
28466
|
-
.map((userId) => pullFromCache(['user', 'get', userId]))
|
|
28467
|
-
.filter(Boolean)
|
|
28468
|
-
.map(data => data === null || data === void 0 ? void 0 : data.data) || [];
|
|
28469
|
-
}
|
|
28470
|
-
callback({
|
|
28471
|
-
// eslint-disable-next-line no-use-before-define
|
|
28472
|
-
onNextPage: onFetch,
|
|
28473
|
-
data: users,
|
|
28474
|
-
hasNextPage: !!((_b = (_a = snapshot.params) === null || _a === void 0 ? void 0 : _a.page) === null || _b === void 0 ? void 0 : _b.next),
|
|
28475
|
-
loading: snapshot.loading || false,
|
|
28476
|
-
});
|
|
28477
|
-
};
|
|
28478
|
-
const onFetch = (initial = false) => {
|
|
28479
|
-
var _a, _b, _c;
|
|
28480
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
28481
|
-
const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
28482
|
-
if (!initial && users.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
|
|
28483
|
-
return;
|
|
28484
|
-
const query = createQuery(queryReachUser, {
|
|
28485
|
-
viewId: postId,
|
|
28486
|
-
viewedType: "post" /* Amity.AnalyticEventContentType.Post */,
|
|
28487
|
-
limit: queryLimit || 10,
|
|
28488
|
-
token: !initial ? (_c = collection === null || collection === void 0 ? void 0 : collection.params.page) === null || _c === void 0 ? void 0 : _c.next : undefined,
|
|
28489
|
-
});
|
|
28490
|
-
runQuery(query, result => {
|
|
28491
|
-
var _a, _b, _c, _d, _e;
|
|
28492
|
-
let userIds = (_c = (_b = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.data) !== null && _c !== void 0 ? _c : [];
|
|
28493
|
-
if ((_d = result.data) === null || _d === void 0 ? void 0 : _d.users) {
|
|
28494
|
-
userIds = [
|
|
28495
|
-
...new Set([...userIds, ...result.data.users.map(({ userId }) => userId)]),
|
|
28496
|
-
];
|
|
28497
|
-
}
|
|
28498
|
-
const saveToCache = {
|
|
28499
|
-
loading: result.loading,
|
|
28500
|
-
params: { page: (_e = result.data) === null || _e === void 0 ? void 0 : _e.paging },
|
|
28501
|
-
data: userIds || [],
|
|
28502
|
-
};
|
|
28503
|
-
pushToCache(cacheKey, saveToCache);
|
|
28504
|
-
responder(saveToCache);
|
|
28505
|
-
}, queryOptions(COLLECTION_DEFAULT_CACHING_POLICY, CACHE_SHORTEN_LIFESPAN));
|
|
28506
|
-
};
|
|
28507
|
-
onFetch(true);
|
|
28508
|
-
return () => {
|
|
28509
|
-
log(`getViewedUsers(tmpid: ${timestamp}) > dispose`);
|
|
28510
|
-
dropFromCache(cacheKey);
|
|
28511
|
-
};
|
|
28512
|
-
};
|
|
28513
|
-
|
|
28514
27980
|
const getReachedUsers = (params, callback) => {
|
|
28515
27981
|
// Pre-defined function to avoid undefined function call
|
|
28516
27982
|
let onFetch = (initial = false) => undefined;
|
|
@@ -28598,12 +28064,10 @@ var index$j = /*#__PURE__*/Object.freeze({
|
|
|
28598
28064
|
onUserFlagged: onUserFlagged,
|
|
28599
28065
|
onUserUnflagged: onUserUnflagged,
|
|
28600
28066
|
onUserFlagCleared: onUserFlagCleared,
|
|
28601
|
-
getUser: getUser
|
|
28067
|
+
getUser: getUser,
|
|
28602
28068
|
getUsers: getUsers,
|
|
28603
|
-
|
|
28604
|
-
getBlockedUsers: getBlockedUsers$1,
|
|
28069
|
+
getBlockedUsers: getBlockedUsers,
|
|
28605
28070
|
searchUserByDisplayName: searchUserByDisplayName,
|
|
28606
|
-
getViewedUsers: getViewedUsers,
|
|
28607
28071
|
getReachedUsers: getReachedUsers,
|
|
28608
28072
|
get AmityUserSearchMatchType () { return AmityUserSearchMatchType; }
|
|
28609
28073
|
});
|
|
@@ -28853,181 +28317,6 @@ const uploadImage = async (formData, onProgress) => {
|
|
|
28853
28317
|
};
|
|
28854
28318
|
/* end_public_function */
|
|
28855
28319
|
|
|
28856
|
-
/**
|
|
28857
|
-
* ```js
|
|
28858
|
-
* import { createImage } from '@amityco/ts-sdk'
|
|
28859
|
-
* const created = await createImage(formData)
|
|
28860
|
-
* ```
|
|
28861
|
-
*
|
|
28862
|
-
* Creates an {@link Amity.File<'image'>}
|
|
28863
|
-
*
|
|
28864
|
-
* @param formData The data necessary to create a new {@link Amity.File<'image'>}
|
|
28865
|
-
* @param onProgress The callback to track the upload progress
|
|
28866
|
-
* @returns The newly created {@link Amity.File<'image'>}
|
|
28867
|
-
*
|
|
28868
|
-
* @category File API
|
|
28869
|
-
* @async
|
|
28870
|
-
*/
|
|
28871
|
-
const createImage = async (formData, onProgress) => {
|
|
28872
|
-
const client = getActiveClient();
|
|
28873
|
-
client.log('file/createImage', formData);
|
|
28874
|
-
const files = formData.getAll('files');
|
|
28875
|
-
if (!files.length)
|
|
28876
|
-
throw new Error('The formData object must have a `files` key.');
|
|
28877
|
-
const accessType = GlobalFileAccessType$1.getInstance().getFileAccessType();
|
|
28878
|
-
formData.append('accessType', accessType);
|
|
28879
|
-
formData.append('preferredFilename', files[0].name);
|
|
28880
|
-
const headers = 'getHeaders' in formData
|
|
28881
|
-
? formData.getHeaders()
|
|
28882
|
-
: { 'content-type': 'multipart/form-data' };
|
|
28883
|
-
const { data } = await client.http.post('/api/v4/images', formData, {
|
|
28884
|
-
headers,
|
|
28885
|
-
onUploadProgress({ loaded, total = 100 }) {
|
|
28886
|
-
onProgress && onProgress(Math.round((loaded * 100) / total));
|
|
28887
|
-
},
|
|
28888
|
-
});
|
|
28889
|
-
// API-FIX: payload should be serialized properly
|
|
28890
|
-
// const { files } = data
|
|
28891
|
-
const cachedAt = client.cache && Date.now();
|
|
28892
|
-
if (client.cache)
|
|
28893
|
-
ingestInCache({ files: data }, { cachedAt });
|
|
28894
|
-
return {
|
|
28895
|
-
data,
|
|
28896
|
-
cachedAt,
|
|
28897
|
-
};
|
|
28898
|
-
};
|
|
28899
|
-
/* end_public_function */
|
|
28900
|
-
|
|
28901
|
-
/**
|
|
28902
|
-
* ```js
|
|
28903
|
-
* import { FileRepository } from '@amityco/ts-sdk'
|
|
28904
|
-
* const created = await FileRepository.createFile(formData)
|
|
28905
|
-
* ```
|
|
28906
|
-
*
|
|
28907
|
-
* Creates an {@link Amity.File}
|
|
28908
|
-
*
|
|
28909
|
-
* @param formData The data necessary to create a new {@link Amity.File}
|
|
28910
|
-
* @param onProgress The callback to track the upload progress
|
|
28911
|
-
* @returns The newly created {@link Amity.File}
|
|
28912
|
-
*
|
|
28913
|
-
* @category File API
|
|
28914
|
-
* @async
|
|
28915
|
-
*/
|
|
28916
|
-
const createFile = async (formData, onProgress) => {
|
|
28917
|
-
const client = getActiveClient();
|
|
28918
|
-
client.log('file/createFile', formData);
|
|
28919
|
-
const files = formData.getAll('files');
|
|
28920
|
-
if (!files.length)
|
|
28921
|
-
throw new Error('The formData object must have a `files` key.');
|
|
28922
|
-
const accessType = GlobalFileAccessType$1.getInstance().getFileAccessType();
|
|
28923
|
-
formData.append('accessType', accessType);
|
|
28924
|
-
formData.append('preferredFilename', files[0].name);
|
|
28925
|
-
const headers = 'getHeaders' in formData
|
|
28926
|
-
? formData.getHeaders()
|
|
28927
|
-
: { 'content-type': 'multipart/form-data' };
|
|
28928
|
-
const { data } = await client.http.post('/api/v4/files', formData, {
|
|
28929
|
-
headers,
|
|
28930
|
-
onUploadProgress({ loaded, total = 100 }) {
|
|
28931
|
-
onProgress && onProgress(Math.round((loaded * 100) / total));
|
|
28932
|
-
},
|
|
28933
|
-
});
|
|
28934
|
-
// API-FIX: payload should be serialized properly
|
|
28935
|
-
// const { files } = data
|
|
28936
|
-
const cachedAt = client.cache && Date.now();
|
|
28937
|
-
if (client.cache)
|
|
28938
|
-
ingestInCache({ files: data }, { cachedAt });
|
|
28939
|
-
return {
|
|
28940
|
-
data,
|
|
28941
|
-
cachedAt,
|
|
28942
|
-
};
|
|
28943
|
-
};
|
|
28944
|
-
|
|
28945
|
-
/**
|
|
28946
|
-
* ```js
|
|
28947
|
-
* import { FileRepository } from '@amityco/ts-sdk'
|
|
28948
|
-
* const created = await FileRepository.createVideo(formData)
|
|
28949
|
-
* ```
|
|
28950
|
-
*
|
|
28951
|
-
* Creates an {@link Amity.File<'video'>}
|
|
28952
|
-
*
|
|
28953
|
-
* @param formData The data necessary to create a new {@link Amity.File<'video'>}
|
|
28954
|
-
* @param feedType The {@link Amity.File<'video'>} feed type
|
|
28955
|
-
* @param onProgress The callback to track the upload progress
|
|
28956
|
-
* @returns The newly uploaded {@link Amity.File<'video'>}
|
|
28957
|
-
*
|
|
28958
|
-
* @category File API
|
|
28959
|
-
* @async
|
|
28960
|
-
*/
|
|
28961
|
-
const createVideo = async (formData, feedType, onProgress) => {
|
|
28962
|
-
const client = getActiveClient();
|
|
28963
|
-
client.log('file/createVideo', formData);
|
|
28964
|
-
const files = formData.getAll('files');
|
|
28965
|
-
if (!files.length)
|
|
28966
|
-
throw new Error('The formData object must have a `files` key.');
|
|
28967
|
-
const accessType = GlobalFileAccessType$1.getInstance().getFileAccessType();
|
|
28968
|
-
formData.append('accessType', accessType);
|
|
28969
|
-
formData.append('preferredFilename', files[0].name);
|
|
28970
|
-
if (feedType) {
|
|
28971
|
-
formData.append('feedType', feedType);
|
|
28972
|
-
}
|
|
28973
|
-
const headers = 'getHeaders' in formData
|
|
28974
|
-
? formData.getHeaders()
|
|
28975
|
-
: { 'content-type': 'multipart/form-data' };
|
|
28976
|
-
const { data } = await client.http.post('/api/v4/videos', formData, {
|
|
28977
|
-
headers,
|
|
28978
|
-
onUploadProgress({ loaded, total = 100 }) {
|
|
28979
|
-
onProgress && onProgress(Math.round((loaded * 100) / total));
|
|
28980
|
-
},
|
|
28981
|
-
});
|
|
28982
|
-
// API-FIX: payload should be serialized properly
|
|
28983
|
-
// const { files } = data
|
|
28984
|
-
const cachedAt = client.cache && Date.now();
|
|
28985
|
-
if (client.cache)
|
|
28986
|
-
ingestInCache({ files: data }, { cachedAt });
|
|
28987
|
-
return {
|
|
28988
|
-
data,
|
|
28989
|
-
cachedAt,
|
|
28990
|
-
};
|
|
28991
|
-
};
|
|
28992
|
-
|
|
28993
|
-
/**
|
|
28994
|
-
* ```js
|
|
28995
|
-
* import { observeFile } from '@amityco/ts-sdk'
|
|
28996
|
-
*
|
|
28997
|
-
* let file = {}
|
|
28998
|
-
* const dispose = observeFile(fileId, updated => file = updated)
|
|
28999
|
-
* ```
|
|
29000
|
-
*
|
|
29001
|
-
* Observe all mutation on a given {@link Amity.File}
|
|
29002
|
-
*
|
|
29003
|
-
* @param fileId the ID of the file to observe
|
|
29004
|
-
* @param callback the function to call when new data are available
|
|
29005
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the file
|
|
29006
|
-
*
|
|
29007
|
-
* @category File Observer
|
|
29008
|
-
*/
|
|
29009
|
-
const observeFile = (fileId, callback) => {
|
|
29010
|
-
const { log } = getActiveClient();
|
|
29011
|
-
const timestamp = Date.now();
|
|
29012
|
-
log(`observeFile(tmpid: ${timestamp}) > listen`);
|
|
29013
|
-
// wrapper function to make sure
|
|
29014
|
-
const router = (result, action) => {
|
|
29015
|
-
var _a, _b, _c;
|
|
29016
|
-
// filter function
|
|
29017
|
-
if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.fileId) !== fileId)
|
|
29018
|
-
return;
|
|
29019
|
-
if (callback instanceof Function)
|
|
29020
|
-
return callback(result);
|
|
29021
|
-
if (action !== 'onFetch')
|
|
29022
|
-
(_b = callback.onEvent) === null || _b === void 0 ? void 0 : _b.call(callback, action, result);
|
|
29023
|
-
(_c = callback[action]) === null || _c === void 0 ? void 0 : _c.call(callback, result);
|
|
29024
|
-
};
|
|
29025
|
-
runQuery(createQuery(getFile, fileId), result => result.data && router(result, 'onFetch'));
|
|
29026
|
-
return () => {
|
|
29027
|
-
log(`observeFile(tmpid: ${timestamp}) > dispose`);
|
|
29028
|
-
};
|
|
29029
|
-
};
|
|
29030
|
-
|
|
29031
28320
|
var index$i = /*#__PURE__*/Object.freeze({
|
|
29032
28321
|
__proto__: null,
|
|
29033
28322
|
getFile: getFile,
|
|
@@ -29035,11 +28324,7 @@ var index$i = /*#__PURE__*/Object.freeze({
|
|
|
29035
28324
|
deleteFile: deleteFile,
|
|
29036
28325
|
fileUrlWithSize: fileUrlWithSize,
|
|
29037
28326
|
uploadVideo: uploadVideo,
|
|
29038
|
-
uploadImage: uploadImage
|
|
29039
|
-
createImage: createImage,
|
|
29040
|
-
createFile: createFile,
|
|
29041
|
-
createVideo: createVideo,
|
|
29042
|
-
observeFile: observeFile
|
|
28327
|
+
uploadImage: uploadImage
|
|
29043
28328
|
});
|
|
29044
28329
|
|
|
29045
28330
|
/**
|
|
@@ -29060,16 +28345,12 @@ var index$i = /*#__PURE__*/Object.freeze({
|
|
|
29060
28345
|
const queryRoles = async (query) => {
|
|
29061
28346
|
const client = getActiveClient();
|
|
29062
28347
|
client.log('role/queryRoles', query);
|
|
29063
|
-
const _a = query !== null && query !== void 0 ? query : {}, {
|
|
28348
|
+
const _a = query !== null && query !== void 0 ? query : {}, { limit = 10, queryToken, displayName, sortBy } = _a, params = __rest(_a, ["limit", "queryToken", "displayName", "sortBy"]);
|
|
29064
28349
|
const options = (() => {
|
|
29065
28350
|
if (queryToken)
|
|
29066
28351
|
return { token: queryToken };
|
|
29067
28352
|
if (limit)
|
|
29068
28353
|
return { limit };
|
|
29069
|
-
if (page)
|
|
29070
|
-
return {
|
|
29071
|
-
token: toToken(page, 'skiplimit'),
|
|
29072
|
-
};
|
|
29073
28354
|
return undefined;
|
|
29074
28355
|
})();
|
|
29075
28356
|
// API-FIX: parameters should be querystring.
|
|
@@ -29197,12 +28478,9 @@ const dispatchReactable = (referenceType, model) => {
|
|
|
29197
28478
|
* @category Message API
|
|
29198
28479
|
* @async
|
|
29199
28480
|
*/
|
|
29200
|
-
const getMessage$
|
|
28481
|
+
const getMessage$1 = async (messageId, isLive = false) => {
|
|
29201
28482
|
const client = getActiveClient();
|
|
29202
28483
|
client.log('message/getMessage', messageId);
|
|
29203
|
-
if (!isLive) {
|
|
29204
|
-
console.log('getMessage will be deprecated on 15th November 2022, please use liveMessage instead.');
|
|
29205
|
-
}
|
|
29206
28484
|
isInTombstone('message', messageId);
|
|
29207
28485
|
let data;
|
|
29208
28486
|
try {
|
|
@@ -29239,7 +28517,7 @@ const getMessage$2 = async (messageId, isLive = false) => {
|
|
|
29239
28517
|
*
|
|
29240
28518
|
* @category Message API
|
|
29241
28519
|
*/
|
|
29242
|
-
getMessage$
|
|
28520
|
+
getMessage$1.locally = (messageId) => {
|
|
29243
28521
|
const client = getActiveClient();
|
|
29244
28522
|
client.log('message/getMessage.locally', messageId);
|
|
29245
28523
|
if (!client.cache)
|
|
@@ -31168,7 +30446,7 @@ const getChannel$1 = async (channelId) => {
|
|
|
31168
30446
|
ingestInCache(data, { cachedAt });
|
|
31169
30447
|
const { channels } = data;
|
|
31170
30448
|
return {
|
|
31171
|
-
data:
|
|
30449
|
+
data: channels.find(channel => channel.channelId === channelId),
|
|
31172
30450
|
cachedAt,
|
|
31173
30451
|
};
|
|
31174
30452
|
};
|
|
@@ -31198,7 +30476,7 @@ getChannel$1.locally = (channelId) => {
|
|
|
31198
30476
|
if (!cached || (cached === null || cached === void 0 ? void 0 : cached.length) === 0)
|
|
31199
30477
|
return;
|
|
31200
30478
|
return {
|
|
31201
|
-
data:
|
|
30479
|
+
data: cached[0].data,
|
|
31202
30480
|
cachedAt: cached[0].cachedAt,
|
|
31203
30481
|
};
|
|
31204
30482
|
};
|
|
@@ -31223,7 +30501,7 @@ const deleteChannel = async (channelId) => {
|
|
|
31223
30501
|
await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}`);
|
|
31224
30502
|
const deleted = await getChannel$1(channelId);
|
|
31225
30503
|
// no need for event, fired by server
|
|
31226
|
-
return deleted.data;
|
|
30504
|
+
return constructChannelDynamicValue(deleted.data);
|
|
31227
30505
|
};
|
|
31228
30506
|
|
|
31229
30507
|
/* begin_public_function
|
|
@@ -31345,81 +30623,6 @@ const unmuteChannel = async (channelId) => {
|
|
|
31345
30623
|
};
|
|
31346
30624
|
/* end_public_function */
|
|
31347
30625
|
|
|
31348
|
-
/**
|
|
31349
|
-
* ```js
|
|
31350
|
-
* import { observeChannel } from '@amityco/ts-sdk'
|
|
31351
|
-
*
|
|
31352
|
-
* let channel = {}
|
|
31353
|
-
* const dispose = observeChannel(channelId, ({ data }) => channel = data)
|
|
31354
|
-
* ```
|
|
31355
|
-
*
|
|
31356
|
-
* Observe all mutation on a given {@link Amity.Channel}
|
|
31357
|
-
*
|
|
31358
|
-
* @param channelId the ID of the channel to observe
|
|
31359
|
-
* @param callback the function to call when new data are available
|
|
31360
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the channel
|
|
31361
|
-
*
|
|
31362
|
-
* @category Channel Observer
|
|
31363
|
-
*/
|
|
31364
|
-
const observeChannel = (channelId, callback) => {
|
|
31365
|
-
const { log } = getActiveClient();
|
|
31366
|
-
const timestamp = Date.now();
|
|
31367
|
-
log(`observeChannel(tmpid: ${timestamp}) > listen`);
|
|
31368
|
-
// wrapper function to make sure
|
|
31369
|
-
const router = (result, action) => {
|
|
31370
|
-
var _a, _b, _c;
|
|
31371
|
-
// filter function
|
|
31372
|
-
if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.channelId) !== channelId)
|
|
31373
|
-
return;
|
|
31374
|
-
if (callback instanceof Function)
|
|
31375
|
-
return callback(Object.assign(Object.assign({}, result), { data: LinkedObject.channel(constructChannelDynamicValue(result.data)) }));
|
|
31376
|
-
if (action !== 'onFetch')
|
|
31377
|
-
(_b = callback.onEvent) === null || _b === void 0 ? void 0 : _b.call(callback, action, Object.assign(Object.assign({}, result), { data: LinkedObject.channel(constructChannelDynamicValue(result.data)) }));
|
|
31378
|
-
(_c = callback[action]) === null || _c === void 0 ? void 0 : _c.call(callback, Object.assign(Object.assign({}, result), { data: LinkedObject.channel(constructChannelDynamicValue(result.data)) }));
|
|
31379
|
-
};
|
|
31380
|
-
const disposers = [];
|
|
31381
|
-
disposers.push(onChannelUpdated(data => router({ data, loading: false, origin: 'event' }, "onUpdate" /* Amity.ChannelActionType.OnUpdate */)), onChannelDeleted(data => router({ data, loading: false, origin: 'event' }, "onDelete" /* Amity.ChannelActionType.OnDelete */)), onChannelJoined(data => router({ data, loading: false, origin: 'event' }, "onJoin" /* Amity.ChannelActionType.OnJoin */)), onChannelLeft(data => router({ data, loading: false, origin: 'event' }, "onLeft" /* Amity.ChannelActionType.OnLeft */)), onChannelMuted(data => router({ data, loading: false, origin: 'event' }, "onMute" /* Amity.ChannelActionType.OnMute */)), onChannelMemberAdded(data => router({ data, loading: false, origin: 'event' }, "onMemberAdded" /* Amity.ChannelActionType.OnMemberAdded */)), onChannelMemberRemoved(data => router({ data, loading: false, origin: 'event' }, "onMemberRemoved" /* Amity.ChannelActionType.OnMemberRemoved */)), convertEventPayload(onChannelMarkerFetched, 'entityId', 'channel')(data => router({ data, loading: false, origin: 'event' }, "onUpdate" /* Amity.ChannelActionType.OnUpdate */)));
|
|
31382
|
-
runQuery(createQuery(getChannel$1, channelId), result => result.data && router(result, "onFetch" /* Amity.ChannelActionType.OnFetch */));
|
|
31383
|
-
return () => {
|
|
31384
|
-
log(`observeChannel(tmpid: ${timestamp}) > dispose`);
|
|
31385
|
-
disposers.forEach(fn => fn());
|
|
31386
|
-
};
|
|
31387
|
-
};
|
|
31388
|
-
|
|
31389
|
-
/**
|
|
31390
|
-
* ```js
|
|
31391
|
-
* import { observeChannels } from '@amityco/ts-sdk'
|
|
31392
|
-
*
|
|
31393
|
-
* let channels = []
|
|
31394
|
-
* const unsub = observeChannels(channel => merge(channels, channel))
|
|
31395
|
-
* ```
|
|
31396
|
-
*
|
|
31397
|
-
* Observe all mutations on a list of {@link Amity.Channel} for a current user
|
|
31398
|
-
*
|
|
31399
|
-
* @param callback the function to call when new data are available
|
|
31400
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the channels
|
|
31401
|
-
*
|
|
31402
|
-
* @category Channel Observer
|
|
31403
|
-
*/
|
|
31404
|
-
const observeChannels = (callback) => {
|
|
31405
|
-
const { log } = getActiveClient();
|
|
31406
|
-
const timestamp = Date.now();
|
|
31407
|
-
log(`observeChannels(tmpid: ${timestamp}) > listen`);
|
|
31408
|
-
const disposers = [];
|
|
31409
|
-
const router = (channel, action) => {
|
|
31410
|
-
var _a, _b;
|
|
31411
|
-
if (callback instanceof Function)
|
|
31412
|
-
return callback(LinkedObject.channel(constructChannelDynamicValue(channel)));
|
|
31413
|
-
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, LinkedObject.channel(constructChannelDynamicValue(channel)));
|
|
31414
|
-
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, LinkedObject.channel(constructChannelDynamicValue(channel)));
|
|
31415
|
-
};
|
|
31416
|
-
disposers.push(onChannelCreated(data => router(data, "onCreate" /* Amity.ChannelActionType.OnCreate */)), onChannelUpdated(data => router(data, "onUpdate" /* Amity.ChannelActionType.OnUpdate */)), onChannelDeleted(data => router(data, "onDelete" /* Amity.ChannelActionType.OnDelete */)), onChannelJoined(data => router(data, "onJoin" /* Amity.ChannelActionType.OnJoin */)), onChannelLeft(data => router(data, "onLeft" /* Amity.ChannelActionType.OnLeft */)), onChannelMuted(data => router(data, "onMute" /* Amity.ChannelActionType.OnMute */)), onChannelMemberAdded(data => router(data, "onMemberAdded" /* Amity.ChannelActionType.OnMemberAdded */)), onChannelMemberRemoved(data => router(data, "onMemberRemoved" /* Amity.ChannelActionType.OnMemberRemoved */)), convertEventPayload(onChannelMarkerFetched, 'entityId', 'channel')(data => router(data, "onUpdate" /* Amity.ChannelActionType.OnUpdate */)));
|
|
31417
|
-
return () => {
|
|
31418
|
-
log(`observeChannels(tmpid: ${timestamp}) > dispose`);
|
|
31419
|
-
disposers.forEach(fn => fn());
|
|
31420
|
-
};
|
|
31421
|
-
};
|
|
31422
|
-
|
|
31423
30626
|
/**
|
|
31424
30627
|
* ```js
|
|
31425
30628
|
* import { onMessageUpdated } from '@amityco/ts-sdk'
|
|
@@ -31698,69 +30901,6 @@ const onSubChannelFetched = (callback) => {
|
|
|
31698
30901
|
return createEventSubscriber(getActiveClient(), 'onSubChannelFetched', 'local.message-feed.fetched', payload => callback(payload.messageFeeds[0]));
|
|
31699
30902
|
};
|
|
31700
30903
|
|
|
31701
|
-
/**
|
|
31702
|
-
* ```js
|
|
31703
|
-
* import { getMessages } from '@amityco/ts-sdk'
|
|
31704
|
-
* const messages = await getMessages(['foo', 'bar'])
|
|
31705
|
-
* ```
|
|
31706
|
-
*
|
|
31707
|
-
* Fetches a collection of {@link Amity.Message} objects
|
|
31708
|
-
*
|
|
31709
|
-
* @param messageIds the IDs of the {@link Amity.Message} to fetch
|
|
31710
|
-
* @returns the associated collection of {@link Amity.Message} objects
|
|
31711
|
-
*
|
|
31712
|
-
* @category Message API
|
|
31713
|
-
* @async
|
|
31714
|
-
*/
|
|
31715
|
-
const getMessages$1 = async (messageIds) => {
|
|
31716
|
-
const client = getActiveClient();
|
|
31717
|
-
client.log('message/getMessages', messageIds);
|
|
31718
|
-
const { data: payload } = await client.http.get(`/api/v5/messages/list`, {
|
|
31719
|
-
params: { messageIds: messageIds.map(encodeURIComponent) },
|
|
31720
|
-
});
|
|
31721
|
-
const data = await prepareMessagePayload(payload);
|
|
31722
|
-
const cachedAt = client.cache && Date.now();
|
|
31723
|
-
if (client.cache)
|
|
31724
|
-
ingestInCache(data, { cachedAt });
|
|
31725
|
-
const { messages } = data;
|
|
31726
|
-
fireEvent('local.message.fetched', { messages });
|
|
31727
|
-
return {
|
|
31728
|
-
data: messages.map(message => LinkedObject.message(message)),
|
|
31729
|
-
cachedAt,
|
|
31730
|
-
};
|
|
31731
|
-
};
|
|
31732
|
-
/**
|
|
31733
|
-
* ```js
|
|
31734
|
-
* import { getMessages } from '@amityco/ts-sdk'
|
|
31735
|
-
* const messages = getMessages.locally(['foo', 'bar']) ?? []
|
|
31736
|
-
* ```
|
|
31737
|
-
*
|
|
31738
|
-
* Fetches a collection of {@link Amity.Message} objects from cache
|
|
31739
|
-
*
|
|
31740
|
-
* @param messageIds the IDs of the {@link Amity.Message} to fetch
|
|
31741
|
-
* @returns the associated collection of {@link Amity.Message} objects
|
|
31742
|
-
*
|
|
31743
|
-
* @category Message API
|
|
31744
|
-
*/
|
|
31745
|
-
getMessages$1.locally = (messageIds) => {
|
|
31746
|
-
var _a;
|
|
31747
|
-
const client = getActiveClient();
|
|
31748
|
-
client.log('message/getMessages.locally', messageIds);
|
|
31749
|
-
if (!client.cache)
|
|
31750
|
-
return;
|
|
31751
|
-
const cached = messageIds
|
|
31752
|
-
.map(messageId => pullFromCache(['message', 'get', messageId]))
|
|
31753
|
-
.filter(Boolean);
|
|
31754
|
-
const messages = cached.map(({ data }) => data);
|
|
31755
|
-
const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
|
|
31756
|
-
if ((cached === null || cached === void 0 ? void 0 : cached.length) < messageIds.length)
|
|
31757
|
-
return;
|
|
31758
|
-
return {
|
|
31759
|
-
data: messages,
|
|
31760
|
-
cachedAt: oldest.cachedAt,
|
|
31761
|
-
};
|
|
31762
|
-
};
|
|
31763
|
-
|
|
31764
30904
|
const getLocalId = () => `LOCAL_${uuid()}`;
|
|
31765
30905
|
// FIXME: temp solution
|
|
31766
30906
|
let uniqueId;
|
|
@@ -31787,7 +30927,7 @@ const createMessageOptimistic = (bundle) => {
|
|
|
31787
30927
|
if (subChannel.data.channelId === subChannel.data.subChannelId) {
|
|
31788
30928
|
const channel = pullFromCache(['channel', 'get', subChannel.data.channelId]);
|
|
31789
30929
|
if (channel === null || channel === void 0 ? void 0 : channel.data) {
|
|
31790
|
-
upsertInCache(['channel', 'get', subChannel.data.channelId], Object.assign(Object.assign({}, channel.data), { messageCount: ((_a =
|
|
30930
|
+
upsertInCache(['channel', 'get', subChannel.data.channelId], Object.assign(Object.assign({}, channel.data), { messageCount: ((_a = subChannel.data.messageCount) !== null && _a !== void 0 ? _a : 0) + 1 }));
|
|
31791
30931
|
}
|
|
31792
30932
|
}
|
|
31793
30933
|
}
|
|
@@ -32073,7 +31213,7 @@ const softDeleteMessage = async (messageId) => {
|
|
|
32073
31213
|
client.log('message/softDeleteMessage', messageId);
|
|
32074
31214
|
// API-FIX: This endpoint has not been implemented yet.
|
|
32075
31215
|
await client.http.delete(`/api/v5/messages/${encodeURIComponent(messageId)}`);
|
|
32076
|
-
const deleted = await getMessage$
|
|
31216
|
+
const deleted = await getMessage$1(messageId);
|
|
32077
31217
|
fireEvent('local.message.deleted', { messages: [deleted.data] });
|
|
32078
31218
|
return LinkedObject.message(deleted.data);
|
|
32079
31219
|
};
|
|
@@ -32547,12 +31687,12 @@ const onMessageFetched = (callback) => {
|
|
|
32547
31687
|
*
|
|
32548
31688
|
* @category Message Live Object
|
|
32549
31689
|
*/
|
|
32550
|
-
const getMessage
|
|
31690
|
+
const getMessage = (messageId, callback) => {
|
|
32551
31691
|
const responder = (snapshot) => {
|
|
32552
31692
|
const { data } = snapshot;
|
|
32553
31693
|
callback(Object.assign(Object.assign({}, snapshot), { data: data ? LinkedObject.message(snapshot.data) : data }));
|
|
32554
31694
|
};
|
|
32555
|
-
return liveObject(messageId, responder, 'messageId', getMessage$
|
|
31695
|
+
return liveObject(messageId, responder, 'messageId', getMessage$1, [
|
|
32556
31696
|
onMessageFetched,
|
|
32557
31697
|
onMessageUpdated,
|
|
32558
31698
|
onMessageDeleted,
|
|
@@ -32601,7 +31741,7 @@ class MessageQueryStreamController extends QueryStreamController {
|
|
|
32601
31741
|
}
|
|
32602
31742
|
reactor(action) {
|
|
32603
31743
|
return (payload) => {
|
|
32604
|
-
var _a, _b, _c
|
|
31744
|
+
var _a, _b, _c;
|
|
32605
31745
|
if (action === 'onCreate') {
|
|
32606
31746
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
32607
31747
|
const { referenceId } = payload;
|
|
@@ -32611,14 +31751,9 @@ class MessageQueryStreamController extends QueryStreamController {
|
|
|
32611
31751
|
return;
|
|
32612
31752
|
if (this.query.type && this.query.type !== payload.dataType)
|
|
32613
31753
|
return;
|
|
32614
|
-
if (this.query.dataType && this.query.dataType !== payload.dataType)
|
|
32615
|
-
return;
|
|
32616
31754
|
if (this.query.excludingTags &&
|
|
32617
31755
|
((_b = this.query.excludingTags) === null || _b === void 0 ? void 0 : _b.some(value => { var _a; return (_a = payload.tags) === null || _a === void 0 ? void 0 : _a.includes(value); })))
|
|
32618
31756
|
return;
|
|
32619
|
-
if (this.query.excludeTags &&
|
|
32620
|
-
((_c = this.query.excludeTags) === null || _c === void 0 ? void 0 : _c.some(value => { var _a; return (_a = payload.tags) === null || _a === void 0 ? void 0 : _a.includes(value); })))
|
|
32621
|
-
return;
|
|
32622
31757
|
if (!!this.query.hasFlags !== !!payload.flagCount)
|
|
32623
31758
|
return;
|
|
32624
31759
|
if (this.query.parentId && this.query.parentId !== payload.parentId)
|
|
@@ -32628,9 +31763,7 @@ class MessageQueryStreamController extends QueryStreamController {
|
|
|
32628
31763
|
payload.isDeleted)
|
|
32629
31764
|
return;
|
|
32630
31765
|
if (this.query.includingTags &&
|
|
32631
|
-
!((
|
|
32632
|
-
return;
|
|
32633
|
-
if (this.query.tags && !((_e = this.query.tags) === null || _e === void 0 ? void 0 : _e.some(value => { var _a; return (_a = payload.tags) === null || _a === void 0 ? void 0 : _a.includes(value); })))
|
|
31766
|
+
!((_c = this.query.includingTags) === null || _c === void 0 ? void 0 : _c.some(value => { var _a; return (_a = payload.tags) === null || _a === void 0 ? void 0 : _a.includes(value); })))
|
|
32634
31767
|
return;
|
|
32635
31768
|
if ((!this.query.sortBy || this.query.sortBy === 'segmentDesc') &&
|
|
32636
31769
|
!this.paginationController.getPrevToken()) {
|
|
@@ -32730,26 +31863,6 @@ class MessageLiveCollectionController extends LiveCollectionController {
|
|
|
32730
31863
|
}
|
|
32731
31864
|
applyFilter(data) {
|
|
32732
31865
|
let messages = data;
|
|
32733
|
-
messages = messages.filter(m => {
|
|
32734
|
-
if (this.query.tags) {
|
|
32735
|
-
return this.query.tags.find(value => {
|
|
32736
|
-
if (!m.tags)
|
|
32737
|
-
return false;
|
|
32738
|
-
return m.tags.includes(value);
|
|
32739
|
-
});
|
|
32740
|
-
}
|
|
32741
|
-
return true;
|
|
32742
|
-
});
|
|
32743
|
-
messages = messages.filter(m => {
|
|
32744
|
-
if (this.query.excludeTags) {
|
|
32745
|
-
return (this.query.excludeTags || []).find(value => {
|
|
32746
|
-
if (!m.tags)
|
|
32747
|
-
return true;
|
|
32748
|
-
return !m.tags.includes(value);
|
|
32749
|
-
});
|
|
32750
|
-
}
|
|
32751
|
-
return true;
|
|
32752
|
-
});
|
|
32753
31866
|
/*
|
|
32754
31867
|
* for cases when message is deleted via RTE, this flag is used to get
|
|
32755
31868
|
* items from cache that are !deleted
|
|
@@ -32829,164 +31942,8 @@ const getMessages = (params, callback, config) => {
|
|
|
32829
31942
|
};
|
|
32830
31943
|
/* end_public_function */
|
|
32831
31944
|
|
|
32832
|
-
/**
|
|
32833
|
-
* ```js
|
|
32834
|
-
* import { getMessage } from '@amityco/ts-sdk'
|
|
32835
|
-
* const message = await getMessage('foobar')
|
|
32836
|
-
* ```
|
|
32837
|
-
*
|
|
32838
|
-
* Fetches a {@link Amity.Message} object
|
|
32839
|
-
*
|
|
32840
|
-
* @param messageId the ID of the {@link Amity.Message} to fetch
|
|
32841
|
-
* @returns the associated {@link Amity.Message} object
|
|
32842
|
-
*
|
|
32843
|
-
* @category Message API
|
|
32844
|
-
* @async
|
|
32845
|
-
*/
|
|
32846
|
-
const getMessage = async (messageId, isLive = false) => {
|
|
32847
|
-
const client = getActiveClient();
|
|
32848
|
-
client.log('message/getMessage', messageId);
|
|
32849
|
-
if (!isLive) {
|
|
32850
|
-
console.log('getMessage will be deprecated on 15th November 2022, please use liveMessage instead.');
|
|
32851
|
-
}
|
|
32852
|
-
isInTombstone('message', messageId);
|
|
32853
|
-
let data;
|
|
32854
|
-
try {
|
|
32855
|
-
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
32856
|
-
const { data: payload } = await client.http.get(`/api/v5/messages/${encodeURIComponent(messageId)}`);
|
|
32857
|
-
data = await prepareMessagePayload(payload);
|
|
32858
|
-
}
|
|
32859
|
-
catch (error) {
|
|
32860
|
-
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
32861
|
-
pushToTombstone('message', messageId);
|
|
32862
|
-
}
|
|
32863
|
-
throw error;
|
|
32864
|
-
}
|
|
32865
|
-
const cachedAt = client.cache && Date.now();
|
|
32866
|
-
if (client.cache)
|
|
32867
|
-
ingestInCache(data, { cachedAt });
|
|
32868
|
-
const { messages } = data;
|
|
32869
|
-
fireEvent('local.message.fetched', { messages });
|
|
32870
|
-
return {
|
|
32871
|
-
data: LinkedObject.message(messages.find(message => message.messageId === messageId)),
|
|
32872
|
-
cachedAt,
|
|
32873
|
-
};
|
|
32874
|
-
};
|
|
32875
|
-
/**
|
|
32876
|
-
* ```js
|
|
32877
|
-
* import { getMessage } from '@amityco/ts-sdk'
|
|
32878
|
-
* const message = getMessage.locally('foobar')
|
|
32879
|
-
* ```
|
|
32880
|
-
*
|
|
32881
|
-
* Fetches a {@link Amity.Message} object
|
|
32882
|
-
*
|
|
32883
|
-
* @param messageId the ID of the {@link Amity.Message} to fetch
|
|
32884
|
-
* @returns the associated {@link Amity.Message} object
|
|
32885
|
-
*
|
|
32886
|
-
* @category Message API
|
|
32887
|
-
*/
|
|
32888
|
-
getMessage.locally = (messageId) => {
|
|
32889
|
-
const client = getActiveClient();
|
|
32890
|
-
client.log('message/getMessage.locally', messageId);
|
|
32891
|
-
if (!client.cache)
|
|
32892
|
-
return;
|
|
32893
|
-
const cached = pullFromCache(['message', 'get', messageId]);
|
|
32894
|
-
if (!cached)
|
|
32895
|
-
return;
|
|
32896
|
-
return {
|
|
32897
|
-
data: cached.data,
|
|
32898
|
-
cachedAt: cached.cachedAt,
|
|
32899
|
-
};
|
|
32900
|
-
};
|
|
32901
|
-
|
|
32902
|
-
/**
|
|
32903
|
-
* ```js
|
|
32904
|
-
* import { observeMessage } from '@amityco/ts-sdk'
|
|
32905
|
-
*
|
|
32906
|
-
* let message = {}
|
|
32907
|
-
*
|
|
32908
|
-
* const unsub = observeMessage(messageId, updated => message = updated)
|
|
32909
|
-
* ```
|
|
32910
|
-
*
|
|
32911
|
-
* Observe all mutations on a {@link Amity.Message} given a single messageId
|
|
32912
|
-
*
|
|
32913
|
-
* @param client the client to observe the message with
|
|
32914
|
-
* @param messageId the ID of the message to observe
|
|
32915
|
-
* @param callback the function to call when new data are available
|
|
32916
|
-
* @param policy a query policy option for this observer
|
|
32917
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the message
|
|
32918
|
-
*
|
|
32919
|
-
* @category Message Observer
|
|
32920
|
-
*/
|
|
32921
|
-
const observeMessage = (messageId, callback, policy = 'cache_then_server') => {
|
|
32922
|
-
const { log } = getActiveClient();
|
|
32923
|
-
const timestamp = Date.now();
|
|
32924
|
-
log(`observeMessage(tmpid: ${timestamp}) > listen`);
|
|
32925
|
-
console.log('observeMessage will be deprecated on 15th November 2022, please use liveMessage instead.');
|
|
32926
|
-
// wrapper function to make sure
|
|
32927
|
-
const router = (result, action) => {
|
|
32928
|
-
var _a, _b, _c;
|
|
32929
|
-
// filter function
|
|
32930
|
-
if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.messageId) !== messageId)
|
|
32931
|
-
return;
|
|
32932
|
-
if (callback instanceof Function)
|
|
32933
|
-
return callback(result);
|
|
32934
|
-
if (action !== 'onFetch')
|
|
32935
|
-
(_b = callback.onEvent) === null || _b === void 0 ? void 0 : _b.call(callback, action, result);
|
|
32936
|
-
(_c = callback[action]) === null || _c === void 0 ? void 0 : _c.call(callback, result);
|
|
32937
|
-
};
|
|
32938
|
-
const disposers = [];
|
|
32939
|
-
disposers.push(onMessageUpdated(data => router({ data: LinkedObject.message(data), loading: false, origin: 'event' }, 'onUpdate')), onMessageDeleted(data => router({ data: LinkedObject.message(data), loading: false, origin: 'event' }, 'onDelete')), convertEventPayload(onMessageMarkerFetched, 'contentId', 'message')(data => router({ data: LinkedObject.message(data), loading: false, origin: 'event' }, 'onUpdate')), convertEventPayload(onMessageMarked, 'contentId', 'message')(data => router({ data: LinkedObject.message(data), loading: false, origin: 'event' }, 'onUpdate')));
|
|
32940
|
-
if (policy !== 'no_fetch') {
|
|
32941
|
-
runQuery(createQuery(getMessage, messageId), result => result.data && router(result, 'onFetch'), queryOptions(policy));
|
|
32942
|
-
}
|
|
32943
|
-
return () => {
|
|
32944
|
-
log(`observeMessages(tmpid: ${timestamp}) > dispose`);
|
|
32945
|
-
disposers.forEach(fn => fn());
|
|
32946
|
-
};
|
|
32947
|
-
};
|
|
32948
|
-
|
|
32949
|
-
/**
|
|
32950
|
-
* ```js
|
|
32951
|
-
* import { observeMessages } from '@amityco/ts-sdk'
|
|
32952
|
-
*
|
|
32953
|
-
* let messages = []
|
|
32954
|
-
*
|
|
32955
|
-
* const unsubscribe = observeMessages(channelId, message => merge(messages, message))
|
|
32956
|
-
* ```
|
|
32957
|
-
*
|
|
32958
|
-
* Observe all mutations on a list of {@link Amity.Message} for a given {@link Amity.SubChannel} object
|
|
32959
|
-
*
|
|
32960
|
-
* @param subChannelId the ID of the channel where to observe the messages
|
|
32961
|
-
* @param callback the function to call when new data are available
|
|
32962
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
32963
|
-
*
|
|
32964
|
-
* @category Message Observer
|
|
32965
|
-
*/
|
|
32966
|
-
const observeMessages = (subChannelId, callback) => {
|
|
32967
|
-
const { log } = getActiveClient();
|
|
32968
|
-
const timestamp = Date.now();
|
|
32969
|
-
log(`observeMessages(tmpid: ${timestamp}) > listen`);
|
|
32970
|
-
const disposers = [];
|
|
32971
|
-
const router = (message, action) => {
|
|
32972
|
-
var _a, _b, _c;
|
|
32973
|
-
if (((_a = message.data) === null || _a === void 0 ? void 0 : _a.subChannelId) !== subChannelId)
|
|
32974
|
-
return;
|
|
32975
|
-
if (callback instanceof Function)
|
|
32976
|
-
return callback(message);
|
|
32977
|
-
(_b = callback.onEvent) === null || _b === void 0 ? void 0 : _b.call(callback, action, message);
|
|
32978
|
-
(_c = callback[action]) === null || _c === void 0 ? void 0 : _c.call(callback, message);
|
|
32979
|
-
};
|
|
32980
|
-
disposers.push(onMessageCreatedMqtt(data => router({ data: LinkedObject.message(data), loading: false, origin: 'event' }, 'onCreate')), onMessageCreatedLocal(data => router({ data: LinkedObject.message(data), loading: false, origin: 'event' }, 'onCreate')), onMessageUpdated(data => router({ data: LinkedObject.message(data), loading: false, origin: 'event' }, 'onUpdate')), onMessageDeleted(data => router({ data: LinkedObject.message(data), loading: false, origin: 'event' }, 'onDelete')), convertEventPayload(onMessageMarkerFetched, 'contentId', 'message')(data => router({ data: LinkedObject.message(data), loading: false, origin: 'event' }, 'onCreate')), convertEventPayload(onMessageMarked, 'contentId', 'message')(data => router({ data: LinkedObject.message(data), loading: false, origin: 'event' }, 'onCreate')));
|
|
32981
|
-
return () => {
|
|
32982
|
-
log(`observeMessages(tmpid: ${timestamp}) > dispose`);
|
|
32983
|
-
disposers.forEach(fn => fn());
|
|
32984
|
-
};
|
|
32985
|
-
};
|
|
32986
|
-
|
|
32987
31945
|
var index$g = /*#__PURE__*/Object.freeze({
|
|
32988
31946
|
__proto__: null,
|
|
32989
|
-
getMessageByIds: getMessages$1,
|
|
32990
31947
|
createMessage: createMessage,
|
|
32991
31948
|
updateMessage: updateMessage,
|
|
32992
31949
|
editMessage: editMessage,
|
|
@@ -33008,10 +31965,8 @@ var index$g = /*#__PURE__*/Object.freeze({
|
|
|
33008
31965
|
onMessageReactionAdded: onMessageReactionAdded,
|
|
33009
31966
|
onMessageReactionRemoved: onMessageReactionRemoved,
|
|
33010
31967
|
onMessageFetched: onMessageFetched,
|
|
33011
|
-
getMessage: getMessage
|
|
31968
|
+
getMessage: getMessage,
|
|
33012
31969
|
getMessages: getMessages,
|
|
33013
|
-
observeMessage: observeMessage,
|
|
33014
|
-
observeMessages: observeMessages,
|
|
33015
31970
|
convertFromRaw: convertFromRaw,
|
|
33016
31971
|
prepareMessagePayload: prepareMessagePayload,
|
|
33017
31972
|
convertParams: convertParams,
|
|
@@ -33608,8 +32563,6 @@ var index$f = /*#__PURE__*/Object.freeze({
|
|
|
33608
32563
|
getSubChannel: getSubChannel,
|
|
33609
32564
|
getSubChannels: getSubChannels,
|
|
33610
32565
|
markReadEngineOnLoginHandler: markReadEngineOnLoginHandler,
|
|
33611
|
-
startReading: startReading,
|
|
33612
|
-
stopReading: stopReading,
|
|
33613
32566
|
startMessageReceiptSync: startMessageReceiptSync,
|
|
33614
32567
|
stopMessageReceiptSync: stopMessageReceiptSync
|
|
33615
32568
|
});
|
|
@@ -33660,7 +32613,9 @@ const getChannel = (channelId, callback) => {
|
|
|
33660
32613
|
const reactor = async (response) => {
|
|
33661
32614
|
if (!response.data)
|
|
33662
32615
|
return callback(response);
|
|
33663
|
-
const data = Object.assign(Object.assign({}, response), {
|
|
32616
|
+
const data = Object.assign(Object.assign({}, response), {
|
|
32617
|
+
// TODO: refactor to be a function to construct public channel object
|
|
32618
|
+
data: LinkedObject.channel(constructChannelDynamicValue(getChannelMessagePreviewWithUser(response.data))) });
|
|
33664
32619
|
const newSnapshot = __rest(data, ["origin"]);
|
|
33665
32620
|
/**
|
|
33666
32621
|
* check equality of previous data and current data to avoid redundancy
|
|
@@ -33995,8 +32950,11 @@ class ChannelLiveCollectionController extends LiveCollectionController {
|
|
|
33995
32950
|
.map(channelId => pullFromCache(['channel', 'get', channelId]))
|
|
33996
32951
|
.filter(Boolean)
|
|
33997
32952
|
.map(({ data }) => data)
|
|
32953
|
+
// add messagePreview >> Amity.InternalChannel -> Amity.InternalChannel
|
|
33998
32954
|
.map(getChannelMessagePreviewWithUser)
|
|
32955
|
+
// construct getter value >> Amity.StaticInternalChannel -> Amity.Channel
|
|
33999
32956
|
.map(constructChannelDynamicValue)
|
|
32957
|
+
// add markAsRead >> Amity.InternalChannel -> Amity.Channel
|
|
34000
32958
|
.map(LinkedObject.channel)) !== null && _b !== void 0 ? _b : [];
|
|
34001
32959
|
if (this.paginationController instanceof ChannelPaginationController) {
|
|
34002
32960
|
data = this.applyFilter(data);
|
|
@@ -34644,11 +33602,6 @@ class ChannelMemberLiveCollectionController extends LiveCollectionController {
|
|
|
34644
33602
|
return false;
|
|
34645
33603
|
});
|
|
34646
33604
|
}
|
|
34647
|
-
if (this.query.search) {
|
|
34648
|
-
// eslint-disable-next-line no-console
|
|
34649
|
-
console.warn('`search` param will be deprecated in the next major release. If you want to search channel members by displayName, Please use `searchMembers()` instead.');
|
|
34650
|
-
channelMembers = filterBySearchTerm(channelMembers, this.query.search);
|
|
34651
|
-
}
|
|
34652
33605
|
if (this.query.includeDeleted === false) {
|
|
34653
33606
|
channelMembers = channelMembers.filter(member => { var _a; return ((_a = member.user) === null || _a === void 0 ? void 0 : _a.isDeleted) !== true; });
|
|
34654
33607
|
}
|
|
@@ -34682,11 +33635,6 @@ const applyFilter$1 = (data, params) => {
|
|
|
34682
33635
|
return params.memberships.includes(member.membership);
|
|
34683
33636
|
});
|
|
34684
33637
|
}
|
|
34685
|
-
if (params.search) {
|
|
34686
|
-
// eslint-disable-next-line no-console
|
|
34687
|
-
console.warn('`search` param will be deprecated in the next major release. If you want to search channel members by displayName, Please use `searchMembers()` instead.');
|
|
34688
|
-
channelMembers = filterBySearchTerm(channelMembers, params.search);
|
|
34689
|
-
}
|
|
34690
33638
|
// sort, 'lastCreated' is the default sort order
|
|
34691
33639
|
const sortBy = params.sortBy ? params.sortBy : 'lastCreated';
|
|
34692
33640
|
channelMembers = channelMembers.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
@@ -34986,7 +33934,6 @@ var index$c = /*#__PURE__*/Object.freeze({
|
|
|
34986
33934
|
leaveChannel: leaveChannel,
|
|
34987
33935
|
muteChannel: muteChannel,
|
|
34988
33936
|
unmuteChannel: unmuteChannel,
|
|
34989
|
-
markAsRead: markAsRead,
|
|
34990
33937
|
onChannelCreated: onChannelCreated,
|
|
34991
33938
|
onChannelUpdated: onChannelUpdated,
|
|
34992
33939
|
onChannelDeleted: onChannelDeleted,
|
|
@@ -34999,8 +33946,6 @@ var index$c = /*#__PURE__*/Object.freeze({
|
|
|
34999
33946
|
onChannelMemberUnbanned: onChannelMemberUnbanned,
|
|
35000
33947
|
onChannelMemberRoleAdded: onChannelMemberRoleAdded,
|
|
35001
33948
|
onChannelMemberRoleRemoved: onChannelMemberRoleRemoved,
|
|
35002
|
-
observeChannel: observeChannel,
|
|
35003
|
-
observeChannels: observeChannels,
|
|
35004
33949
|
getChannel: getChannel,
|
|
35005
33950
|
getChannels: getChannels,
|
|
35006
33951
|
MARKER_INCLUDED_CHANNEL_TYPE: MARKER_INCLUDED_CHANNEL_TYPE,
|
|
@@ -35311,77 +34256,6 @@ const leaveCommunity = async (communityId) => {
|
|
|
35311
34256
|
};
|
|
35312
34257
|
/* end_public_function */
|
|
35313
34258
|
|
|
35314
|
-
/* begin_public_function
|
|
35315
|
-
id: community.query.trending_communities
|
|
35316
|
-
*/
|
|
35317
|
-
/**
|
|
35318
|
-
* @deprecated This API renamed to `getTrendingCommunities()`.
|
|
35319
|
-
* Please use getTrendingCommunities() instead.
|
|
35320
|
-
*
|
|
35321
|
-
* ```js
|
|
35322
|
-
* import { CommunityRepository } from '@amityco/ts-sdk'
|
|
35323
|
-
* const trendingCommunities = await CommunityRepository.getTrendingCommunities()
|
|
35324
|
-
* ```
|
|
35325
|
-
*
|
|
35326
|
-
* Gets a list of top trending {@link Amity.Community} objects
|
|
35327
|
-
*
|
|
35328
|
-
* @param query The query parameters
|
|
35329
|
-
* @returns A list of {@link Amity.Community} objects
|
|
35330
|
-
*
|
|
35331
|
-
* @category Community API
|
|
35332
|
-
* @async
|
|
35333
|
-
*/
|
|
35334
|
-
const getTopTrendingCommunities = async (query) => {
|
|
35335
|
-
const client = getActiveClient();
|
|
35336
|
-
client.log('channel/getTopTrendingCommunities', query);
|
|
35337
|
-
const { limit = 5 } = query !== null && query !== void 0 ? query : {};
|
|
35338
|
-
// API-FIX: backend doesnt answer Amity.Response
|
|
35339
|
-
// const { data } = await client.http.get<Amity.Response<CommunityPayload>>(
|
|
35340
|
-
const { data: payload } = await client.http.get(`/api/v3/communities/top-trending`, { params: { options: { limit } } });
|
|
35341
|
-
const data = prepareCommunityPayload(payload);
|
|
35342
|
-
const { communities } = data;
|
|
35343
|
-
const cachedAt = client.cache && Date.now();
|
|
35344
|
-
if (client.cache) {
|
|
35345
|
-
ingestInCache(data, { cachedAt });
|
|
35346
|
-
const cacheKey = ['community', 'top-trending', { params: { options: { limit } } }];
|
|
35347
|
-
pushToCache(cacheKey, { communities: communities.map(getResolver('community')) });
|
|
35348
|
-
}
|
|
35349
|
-
return { data: communities, cachedAt };
|
|
35350
|
-
};
|
|
35351
|
-
/* end_public_function */
|
|
35352
|
-
/**
|
|
35353
|
-
* ```js
|
|
35354
|
-
* import { getTopTrendingCommunities } from '@amityco/ts-sdk'
|
|
35355
|
-
* const communities = getTopTrendingCommunities.locally()
|
|
35356
|
-
* ```
|
|
35357
|
-
*
|
|
35358
|
-
* Gets a list of top trending {@link Amity.Community} objects from cache
|
|
35359
|
-
*
|
|
35360
|
-
* @param query The query parameters
|
|
35361
|
-
* @returns communities
|
|
35362
|
-
*
|
|
35363
|
-
* @category Community API
|
|
35364
|
-
*/
|
|
35365
|
-
getTopTrendingCommunities.locally = (query) => {
|
|
35366
|
-
var _a, _b;
|
|
35367
|
-
const client = getActiveClient();
|
|
35368
|
-
client.log('community/getTopTrendingCommunities.locally', query);
|
|
35369
|
-
if (!client.cache)
|
|
35370
|
-
return;
|
|
35371
|
-
const { limit = 5 } = query !== null && query !== void 0 ? query : {};
|
|
35372
|
-
const queryKey = ['community', 'top-trending', { params: { options: { limit } } }];
|
|
35373
|
-
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
35374
|
-
if (!(data === null || data === void 0 ? void 0 : data.communities.length))
|
|
35375
|
-
return;
|
|
35376
|
-
const communities = data.communities
|
|
35377
|
-
.map(communityId => pullFromCache(['community', 'get', communityId]))
|
|
35378
|
-
.filter(Boolean)
|
|
35379
|
-
.map(({ data }) => data);
|
|
35380
|
-
return communities.length === ((_b = data === null || data === void 0 ? void 0 : data.communities) === null || _b === void 0 ? void 0 : _b.length)
|
|
35381
|
-
? { data: communities, cachedAt }
|
|
35382
|
-
: undefined;
|
|
35383
|
-
};
|
|
35384
|
-
|
|
35385
34259
|
const createCommunityEventSubscriber = (event, callback) => {
|
|
35386
34260
|
const client = getActiveClient();
|
|
35387
34261
|
const filter = (payload) => {
|
|
@@ -35452,7 +34326,224 @@ const onCommunityUpdated = (callback) => createCommunityEventSubscriber('communi
|
|
|
35452
34326
|
*
|
|
35453
34327
|
* @category Community Events
|
|
35454
34328
|
*/
|
|
35455
|
-
const onCommunityDeleted = (callback) => createCommunityEventSubscriber('community.deleted', callback);
|
|
34329
|
+
const onCommunityDeleted = (callback) => createCommunityEventSubscriber('community.deleted', callback);
|
|
34330
|
+
|
|
34331
|
+
/**
|
|
34332
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
34333
|
+
* TODO: check if querybyIds is supported
|
|
34334
|
+
*/
|
|
34335
|
+
class CommunitiesPaginationController$1 extends PaginationController {
|
|
34336
|
+
async getRequest(queryParams, token) {
|
|
34337
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
34338
|
+
const options = token ? { token } : { limit };
|
|
34339
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/communities`, {
|
|
34340
|
+
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(params.includeDeleted), keyword: params.displayName, filter: params.membership, options }),
|
|
34341
|
+
});
|
|
34342
|
+
return queryResponse;
|
|
34343
|
+
}
|
|
34344
|
+
}
|
|
34345
|
+
|
|
34346
|
+
class CommunitiesQueryStreamController$1 extends QueryStreamController {
|
|
34347
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
34348
|
+
super(query, cacheKey);
|
|
34349
|
+
this.notifyChange = notifyChange;
|
|
34350
|
+
this.preparePayload = preparePayload;
|
|
34351
|
+
}
|
|
34352
|
+
async saveToMainDB(response) {
|
|
34353
|
+
const processedPayload = await this.preparePayload(response);
|
|
34354
|
+
const client = getActiveClient();
|
|
34355
|
+
const cachedAt = client.cache && Date.now();
|
|
34356
|
+
if (client.cache) {
|
|
34357
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
34358
|
+
}
|
|
34359
|
+
}
|
|
34360
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
34361
|
+
var _a, _b;
|
|
34362
|
+
if (refresh) {
|
|
34363
|
+
pushToCache(this.cacheKey, {
|
|
34364
|
+
data: response.communities.map(getResolver('community')),
|
|
34365
|
+
});
|
|
34366
|
+
}
|
|
34367
|
+
else {
|
|
34368
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
34369
|
+
const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
34370
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...communities, ...response.communities.map(getResolver('community'))])] }));
|
|
34371
|
+
}
|
|
34372
|
+
}
|
|
34373
|
+
reactor(action) {
|
|
34374
|
+
return (community) => {
|
|
34375
|
+
var _a;
|
|
34376
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
34377
|
+
if (!collection)
|
|
34378
|
+
return;
|
|
34379
|
+
pushToCache(this.cacheKey, collection);
|
|
34380
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
34381
|
+
};
|
|
34382
|
+
}
|
|
34383
|
+
subscribeRTE(createSubscriber) {
|
|
34384
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
34385
|
+
}
|
|
34386
|
+
}
|
|
34387
|
+
|
|
34388
|
+
var EnumCommunityActions$4;
|
|
34389
|
+
(function (EnumCommunityActions) {
|
|
34390
|
+
EnumCommunityActions["OnCommunityCreated"] = "onCommunityCreated";
|
|
34391
|
+
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
34392
|
+
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
34393
|
+
})(EnumCommunityActions$4 || (EnumCommunityActions$4 = {}));
|
|
34394
|
+
|
|
34395
|
+
var EnumCommunityMemberActions$1;
|
|
34396
|
+
(function (EnumCommunityMemberActions) {
|
|
34397
|
+
EnumCommunityMemberActions["OnCommunityJoined"] = "onCommunityJoined";
|
|
34398
|
+
EnumCommunityMemberActions["OnCommunityLeft"] = "onCommunityLeft";
|
|
34399
|
+
EnumCommunityMemberActions["OnCommunityUserBanned"] = "onCommunityUserBanned";
|
|
34400
|
+
EnumCommunityMemberActions["OnCommunityUserChanged"] = "onCommunityUserChanged";
|
|
34401
|
+
EnumCommunityMemberActions["OnCommunityUserRoleAdded"] = "onCommunityUserRoleAdded";
|
|
34402
|
+
EnumCommunityMemberActions["OnCommunityUserRoleRemoved"] = "onCommunityUserRoleRemoved";
|
|
34403
|
+
EnumCommunityMemberActions["OnCommunityUserUnbanned"] = "onCommunityUserUnbanned";
|
|
34404
|
+
EnumCommunityMemberActions["OnMemberCountChanged"] = "OnMemberCountChanged";
|
|
34405
|
+
EnumCommunityMemberActions["OnCommunityUserAdded"] = "OnCommunityUserAdded";
|
|
34406
|
+
EnumCommunityMemberActions["onCommunityUserRemoved"] = "onCommunityUserRemoved";
|
|
34407
|
+
EnumCommunityMemberActions["OnUserDeleted"] = "OnUserDeleted";
|
|
34408
|
+
})(EnumCommunityMemberActions$1 || (EnumCommunityMemberActions$1 = {}));
|
|
34409
|
+
|
|
34410
|
+
/* begin_public_function
|
|
34411
|
+
id: community.membership.add_members
|
|
34412
|
+
*/
|
|
34413
|
+
/**
|
|
34414
|
+
* ```js
|
|
34415
|
+
* import { CommunityRepository } from '@amityco/ts-sdk'
|
|
34416
|
+
* const updated = await CommunityRepository.moderation.addMembers(communityId, ['foo', 'bar'])
|
|
34417
|
+
* ```
|
|
34418
|
+
*
|
|
34419
|
+
* Adds a list of {@link Amity.InternalUser} to a {@link Amity.Community} to add users to
|
|
34420
|
+
*
|
|
34421
|
+
* @param communityId The ID of the {@link Amity.Community} to perform
|
|
34422
|
+
* @param userIds The list of IDs {@link Amity.InternalUser} to add
|
|
34423
|
+
* @returns A success boolean if the {@link Amity.InternalUser} were added to the {@link Amity.Community}
|
|
34424
|
+
*
|
|
34425
|
+
* @category Community API
|
|
34426
|
+
* @async
|
|
34427
|
+
*/
|
|
34428
|
+
const addMembers = async (communityId, userIds) => {
|
|
34429
|
+
const client = getActiveClient();
|
|
34430
|
+
client.log('community/moderation/addMembers', communityId, userIds);
|
|
34431
|
+
const { data: payload } = await client.http.post(`/api/v3/communities/${communityId}/users`, { communityId, userIds });
|
|
34432
|
+
fireEvent('local.community.userAdded', payload);
|
|
34433
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
34434
|
+
if (client.cache)
|
|
34435
|
+
ingestInCache(data);
|
|
34436
|
+
const { communityUsers } = data;
|
|
34437
|
+
return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership === 'member');
|
|
34438
|
+
};
|
|
34439
|
+
/* end_public_function */
|
|
34440
|
+
|
|
34441
|
+
/* begin_public_function
|
|
34442
|
+
id: community.membership.remove_member
|
|
34443
|
+
*/
|
|
34444
|
+
/**
|
|
34445
|
+
* ```js
|
|
34446
|
+
* import { CommunityRepository } from '@amityco/ts-sdk'
|
|
34447
|
+
* const updated = await CommunityRepository.moderation.removeMembers(communityId, ['foo', 'bar'])
|
|
34448
|
+
* ```
|
|
34449
|
+
*
|
|
34450
|
+
* Removes a list of {@link Amity.InternalUser} from a {@link Amity.Community}
|
|
34451
|
+
*
|
|
34452
|
+
* @param communityId The ID of the {@link Amity.Community} to edit
|
|
34453
|
+
* @param userIds The list of IDs {@link Amity.InternalUser} to remove
|
|
34454
|
+
* @returns A success boolean if the list of {@link Amity.InternalUser} were removed from the {@link Amity.Community}
|
|
34455
|
+
*
|
|
34456
|
+
* @category Community API
|
|
34457
|
+
* @async
|
|
34458
|
+
*/
|
|
34459
|
+
const removeMembers = async (communityId, userIds) => {
|
|
34460
|
+
const client = getActiveClient();
|
|
34461
|
+
client.log('community/moderation/removeMembers', communityId, userIds);
|
|
34462
|
+
const { data: payload } = await client.http.delete(`/api/v3/communities/${communityId}/users`, { data: { communityId, userIds } });
|
|
34463
|
+
fireEvent('local.community.userRemoved', payload);
|
|
34464
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
34465
|
+
if (client.cache)
|
|
34466
|
+
ingestInCache(data);
|
|
34467
|
+
const { communityUsers } = data;
|
|
34468
|
+
return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership !== 'member');
|
|
34469
|
+
};
|
|
34470
|
+
/* end_public_function */
|
|
34471
|
+
|
|
34472
|
+
/**
|
|
34473
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
34474
|
+
* TODO: check if querybyIds is supported
|
|
34475
|
+
*/
|
|
34476
|
+
class CommunityMembersPaginationController extends PaginationController {
|
|
34477
|
+
async getRequest(queryParams, token) {
|
|
34478
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
|
|
34479
|
+
const options = token ? { token } : { limit };
|
|
34480
|
+
const isDeleted = includeDeleted === false ? false : undefined;
|
|
34481
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/communities/${params.communityId}/users`, {
|
|
34482
|
+
params: Object.assign(Object.assign({}, params), { options,
|
|
34483
|
+
isDeleted }),
|
|
34484
|
+
});
|
|
34485
|
+
return queryResponse;
|
|
34486
|
+
}
|
|
34487
|
+
}
|
|
34488
|
+
|
|
34489
|
+
class CommunityMembersQueryStreamController extends QueryStreamController {
|
|
34490
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
34491
|
+
super(query, cacheKey);
|
|
34492
|
+
this.notifyChange = notifyChange;
|
|
34493
|
+
this.preparePayload = preparePayload;
|
|
34494
|
+
}
|
|
34495
|
+
async saveToMainDB(response) {
|
|
34496
|
+
const processedPayload = await this.preparePayload(response);
|
|
34497
|
+
const client = getActiveClient();
|
|
34498
|
+
const cachedAt = client.cache && Date.now();
|
|
34499
|
+
if (client.cache) {
|
|
34500
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
34501
|
+
}
|
|
34502
|
+
}
|
|
34503
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
34504
|
+
var _a, _b;
|
|
34505
|
+
if (refresh) {
|
|
34506
|
+
pushToCache(this.cacheKey, {
|
|
34507
|
+
data: response.communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
|
|
34508
|
+
});
|
|
34509
|
+
}
|
|
34510
|
+
else {
|
|
34511
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
34512
|
+
const communityUsers = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
34513
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
34514
|
+
...new Set([
|
|
34515
|
+
...communityUsers,
|
|
34516
|
+
...response.communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
|
|
34517
|
+
]),
|
|
34518
|
+
] }));
|
|
34519
|
+
}
|
|
34520
|
+
}
|
|
34521
|
+
reactor(action) {
|
|
34522
|
+
return (community, communityMembers) => {
|
|
34523
|
+
var _a;
|
|
34524
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
34525
|
+
if (!collection)
|
|
34526
|
+
return;
|
|
34527
|
+
communityMembers.forEach(communityMember => {
|
|
34528
|
+
const communityMemberCacheId = getResolver('communityUsers')({
|
|
34529
|
+
communityId: this.query.communityId,
|
|
34530
|
+
userId: communityMember.userId,
|
|
34531
|
+
});
|
|
34532
|
+
if (communityMember.communityMembership === 'none') {
|
|
34533
|
+
collection.data = collection.data.filter(m => m !== communityMemberCacheId);
|
|
34534
|
+
}
|
|
34535
|
+
else if (!collection.data.includes(communityMemberCacheId)) {
|
|
34536
|
+
collection.data = [communityMemberCacheId, ...collection.data];
|
|
34537
|
+
}
|
|
34538
|
+
});
|
|
34539
|
+
pushToCache(this.cacheKey, collection);
|
|
34540
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
34541
|
+
};
|
|
34542
|
+
}
|
|
34543
|
+
subscribeRTE(createSubscriber) {
|
|
34544
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
34545
|
+
}
|
|
34546
|
+
}
|
|
35456
34547
|
|
|
35457
34548
|
function hasPermission(member, payload, permission) {
|
|
35458
34549
|
if (member.permissions.some(x => x === permission)) {
|
|
@@ -35746,271 +34837,6 @@ const onLocalCommunityJoined = (callback) => createLocalCommunityMemberEventSubs
|
|
|
35746
34837
|
|
|
35747
34838
|
const onLocalCommunityLeft = (callback) => createLocalCommunityMemberEventSubscriber('local.community.left', callback);
|
|
35748
34839
|
|
|
35749
|
-
/**
|
|
35750
|
-
* ```js
|
|
35751
|
-
* import { observeCommunity } from '@amityco/ts-sdk'
|
|
35752
|
-
*
|
|
35753
|
-
* let community = {}
|
|
35754
|
-
* const dispose = observeCommunity(communityId, updated => community = updated)
|
|
35755
|
-
* ```
|
|
35756
|
-
*
|
|
35757
|
-
* Observe all mutation on a given {@link Amity.Community}
|
|
35758
|
-
*
|
|
35759
|
-
* @param communityId the ID of the community to observe
|
|
35760
|
-
* @param callback the function to call when new data are available
|
|
35761
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the community
|
|
35762
|
-
*
|
|
35763
|
-
* @category Community Observer
|
|
35764
|
-
*/
|
|
35765
|
-
const observeCommunity = (communityId, callback) => {
|
|
35766
|
-
const { log } = getActiveClient();
|
|
35767
|
-
const timestamp = Date.now();
|
|
35768
|
-
log(`observeCommunity(tmpid: ${timestamp}) > listen`);
|
|
35769
|
-
// wrapper function to make sure
|
|
35770
|
-
const router = (result, action) => {
|
|
35771
|
-
var _a, _b;
|
|
35772
|
-
if (callback instanceof Function)
|
|
35773
|
-
return callback(result);
|
|
35774
|
-
if (action !== 'onFetch')
|
|
35775
|
-
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, result);
|
|
35776
|
-
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, result);
|
|
35777
|
-
};
|
|
35778
|
-
const realtimeRouter = (result, action) => {
|
|
35779
|
-
var _a;
|
|
35780
|
-
if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.communityId) !== communityId)
|
|
35781
|
-
return;
|
|
35782
|
-
router(result, action);
|
|
35783
|
-
};
|
|
35784
|
-
const disposers = [];
|
|
35785
|
-
disposers.push(onCommunityUpdated(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUpdate')), onCommunityDeleted(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onDelete')), onCommunityJoined(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onJoin')), onCommunityLeft(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onLeft')), onCommunityUserAdded(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUserAdded')), onCommunityUserRemoved(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUserRemoved')), onCommunityUserBanned(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUserBanned')), onCommunityUserUnbanned(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUserUnbanned')));
|
|
35786
|
-
runQuery(createQuery(getCommunity$1, communityId), result => (result.data || result.error) && router(result, 'onFetch'));
|
|
35787
|
-
return () => {
|
|
35788
|
-
log(`observeCommunity(tmpid: ${timestamp}) > dispose`);
|
|
35789
|
-
disposers.forEach(fn => fn());
|
|
35790
|
-
};
|
|
35791
|
-
};
|
|
35792
|
-
|
|
35793
|
-
/**
|
|
35794
|
-
* TODO: handle cache receive cache option, and cache policy
|
|
35795
|
-
* TODO: check if querybyIds is supported
|
|
35796
|
-
*/
|
|
35797
|
-
class CommunitiesPaginationController$1 extends PaginationController {
|
|
35798
|
-
async getRequest(queryParams, token) {
|
|
35799
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
35800
|
-
const options = token ? { token } : { limit };
|
|
35801
|
-
const { data: queryResponse } = await this.http.get(`/api/v3/communities`, {
|
|
35802
|
-
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(params.includeDeleted), keyword: params.displayName, filter: params.membership, options }),
|
|
35803
|
-
});
|
|
35804
|
-
return queryResponse;
|
|
35805
|
-
}
|
|
35806
|
-
}
|
|
35807
|
-
|
|
35808
|
-
class CommunitiesQueryStreamController$1 extends QueryStreamController {
|
|
35809
|
-
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
35810
|
-
super(query, cacheKey);
|
|
35811
|
-
this.notifyChange = notifyChange;
|
|
35812
|
-
this.preparePayload = preparePayload;
|
|
35813
|
-
}
|
|
35814
|
-
async saveToMainDB(response) {
|
|
35815
|
-
const processedPayload = await this.preparePayload(response);
|
|
35816
|
-
const client = getActiveClient();
|
|
35817
|
-
const cachedAt = client.cache && Date.now();
|
|
35818
|
-
if (client.cache) {
|
|
35819
|
-
ingestInCache(processedPayload, { cachedAt });
|
|
35820
|
-
}
|
|
35821
|
-
}
|
|
35822
|
-
appendToQueryStream(response, direction, refresh = false) {
|
|
35823
|
-
var _a, _b;
|
|
35824
|
-
if (refresh) {
|
|
35825
|
-
pushToCache(this.cacheKey, {
|
|
35826
|
-
data: response.communities.map(getResolver('community')),
|
|
35827
|
-
});
|
|
35828
|
-
}
|
|
35829
|
-
else {
|
|
35830
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
35831
|
-
const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
35832
|
-
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...communities, ...response.communities.map(getResolver('community'))])] }));
|
|
35833
|
-
}
|
|
35834
|
-
}
|
|
35835
|
-
reactor(action) {
|
|
35836
|
-
return (community) => {
|
|
35837
|
-
var _a;
|
|
35838
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
35839
|
-
if (!collection)
|
|
35840
|
-
return;
|
|
35841
|
-
pushToCache(this.cacheKey, collection);
|
|
35842
|
-
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
35843
|
-
};
|
|
35844
|
-
}
|
|
35845
|
-
subscribeRTE(createSubscriber) {
|
|
35846
|
-
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
35847
|
-
}
|
|
35848
|
-
}
|
|
35849
|
-
|
|
35850
|
-
var EnumCommunityActions$4;
|
|
35851
|
-
(function (EnumCommunityActions) {
|
|
35852
|
-
EnumCommunityActions["OnCommunityCreated"] = "onCommunityCreated";
|
|
35853
|
-
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
35854
|
-
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
35855
|
-
})(EnumCommunityActions$4 || (EnumCommunityActions$4 = {}));
|
|
35856
|
-
|
|
35857
|
-
var EnumCommunityMemberActions$1;
|
|
35858
|
-
(function (EnumCommunityMemberActions) {
|
|
35859
|
-
EnumCommunityMemberActions["OnCommunityJoined"] = "onCommunityJoined";
|
|
35860
|
-
EnumCommunityMemberActions["OnCommunityLeft"] = "onCommunityLeft";
|
|
35861
|
-
EnumCommunityMemberActions["OnCommunityUserBanned"] = "onCommunityUserBanned";
|
|
35862
|
-
EnumCommunityMemberActions["OnCommunityUserChanged"] = "onCommunityUserChanged";
|
|
35863
|
-
EnumCommunityMemberActions["OnCommunityUserRoleAdded"] = "onCommunityUserRoleAdded";
|
|
35864
|
-
EnumCommunityMemberActions["OnCommunityUserRoleRemoved"] = "onCommunityUserRoleRemoved";
|
|
35865
|
-
EnumCommunityMemberActions["OnCommunityUserUnbanned"] = "onCommunityUserUnbanned";
|
|
35866
|
-
EnumCommunityMemberActions["OnMemberCountChanged"] = "OnMemberCountChanged";
|
|
35867
|
-
EnumCommunityMemberActions["OnCommunityUserAdded"] = "OnCommunityUserAdded";
|
|
35868
|
-
EnumCommunityMemberActions["onCommunityUserRemoved"] = "onCommunityUserRemoved";
|
|
35869
|
-
EnumCommunityMemberActions["OnUserDeleted"] = "OnUserDeleted";
|
|
35870
|
-
})(EnumCommunityMemberActions$1 || (EnumCommunityMemberActions$1 = {}));
|
|
35871
|
-
|
|
35872
|
-
/* begin_public_function
|
|
35873
|
-
id: community.membership.add_members
|
|
35874
|
-
*/
|
|
35875
|
-
/**
|
|
35876
|
-
* ```js
|
|
35877
|
-
* import { CommunityRepository } from '@amityco/ts-sdk'
|
|
35878
|
-
* const updated = await CommunityRepository.moderation.addMembers(communityId, ['foo', 'bar'])
|
|
35879
|
-
* ```
|
|
35880
|
-
*
|
|
35881
|
-
* Adds a list of {@link Amity.InternalUser} to a {@link Amity.Community} to add users to
|
|
35882
|
-
*
|
|
35883
|
-
* @param communityId The ID of the {@link Amity.Community} to perform
|
|
35884
|
-
* @param userIds The list of IDs {@link Amity.InternalUser} to add
|
|
35885
|
-
* @returns A success boolean if the {@link Amity.InternalUser} were added to the {@link Amity.Community}
|
|
35886
|
-
*
|
|
35887
|
-
* @category Community API
|
|
35888
|
-
* @async
|
|
35889
|
-
*/
|
|
35890
|
-
const addMembers = async (communityId, userIds) => {
|
|
35891
|
-
const client = getActiveClient();
|
|
35892
|
-
client.log('community/moderation/addMembers', communityId, userIds);
|
|
35893
|
-
const { data: payload } = await client.http.post(`/api/v3/communities/${communityId}/users`, { communityId, userIds });
|
|
35894
|
-
fireEvent('local.community.userAdded', payload);
|
|
35895
|
-
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
35896
|
-
if (client.cache)
|
|
35897
|
-
ingestInCache(data);
|
|
35898
|
-
const { communityUsers } = data;
|
|
35899
|
-
return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership === 'member');
|
|
35900
|
-
};
|
|
35901
|
-
/* end_public_function */
|
|
35902
|
-
|
|
35903
|
-
/* begin_public_function
|
|
35904
|
-
id: community.membership.remove_member
|
|
35905
|
-
*/
|
|
35906
|
-
/**
|
|
35907
|
-
* ```js
|
|
35908
|
-
* import { CommunityRepository } from '@amityco/ts-sdk'
|
|
35909
|
-
* const updated = await CommunityRepository.moderation.removeMembers(communityId, ['foo', 'bar'])
|
|
35910
|
-
* ```
|
|
35911
|
-
*
|
|
35912
|
-
* Removes a list of {@link Amity.InternalUser} from a {@link Amity.Community}
|
|
35913
|
-
*
|
|
35914
|
-
* @param communityId The ID of the {@link Amity.Community} to edit
|
|
35915
|
-
* @param userIds The list of IDs {@link Amity.InternalUser} to remove
|
|
35916
|
-
* @returns A success boolean if the list of {@link Amity.InternalUser} were removed from the {@link Amity.Community}
|
|
35917
|
-
*
|
|
35918
|
-
* @category Community API
|
|
35919
|
-
* @async
|
|
35920
|
-
*/
|
|
35921
|
-
const removeMembers = async (communityId, userIds) => {
|
|
35922
|
-
const client = getActiveClient();
|
|
35923
|
-
client.log('community/moderation/removeMembers', communityId, userIds);
|
|
35924
|
-
const { data: payload } = await client.http.delete(`/api/v3/communities/${communityId}/users`, { data: { communityId, userIds } });
|
|
35925
|
-
fireEvent('local.community.userRemoved', payload);
|
|
35926
|
-
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
35927
|
-
if (client.cache)
|
|
35928
|
-
ingestInCache(data);
|
|
35929
|
-
const { communityUsers } = data;
|
|
35930
|
-
return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership !== 'member');
|
|
35931
|
-
};
|
|
35932
|
-
/* end_public_function */
|
|
35933
|
-
|
|
35934
|
-
/**
|
|
35935
|
-
* TODO: handle cache receive cache option, and cache policy
|
|
35936
|
-
* TODO: check if querybyIds is supported
|
|
35937
|
-
*/
|
|
35938
|
-
class CommunityMembersPaginationController extends PaginationController {
|
|
35939
|
-
async getRequest(queryParams, token) {
|
|
35940
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
|
|
35941
|
-
const options = token ? { token } : { limit };
|
|
35942
|
-
const isDeleted = includeDeleted === false ? false : undefined;
|
|
35943
|
-
const { data: queryResponse } = await this.http.get(`/api/v3/communities/${params.communityId}/users`, {
|
|
35944
|
-
params: Object.assign(Object.assign({}, params), { options,
|
|
35945
|
-
isDeleted }),
|
|
35946
|
-
});
|
|
35947
|
-
return queryResponse;
|
|
35948
|
-
}
|
|
35949
|
-
}
|
|
35950
|
-
|
|
35951
|
-
class CommunityMembersQueryStreamController extends QueryStreamController {
|
|
35952
|
-
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
35953
|
-
super(query, cacheKey);
|
|
35954
|
-
this.notifyChange = notifyChange;
|
|
35955
|
-
this.preparePayload = preparePayload;
|
|
35956
|
-
}
|
|
35957
|
-
async saveToMainDB(response) {
|
|
35958
|
-
const processedPayload = await this.preparePayload(response);
|
|
35959
|
-
const client = getActiveClient();
|
|
35960
|
-
const cachedAt = client.cache && Date.now();
|
|
35961
|
-
if (client.cache) {
|
|
35962
|
-
ingestInCache(processedPayload, { cachedAt });
|
|
35963
|
-
}
|
|
35964
|
-
}
|
|
35965
|
-
appendToQueryStream(response, direction, refresh = false) {
|
|
35966
|
-
var _a, _b;
|
|
35967
|
-
if (refresh) {
|
|
35968
|
-
pushToCache(this.cacheKey, {
|
|
35969
|
-
data: response.communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
|
|
35970
|
-
});
|
|
35971
|
-
}
|
|
35972
|
-
else {
|
|
35973
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
35974
|
-
const communityUsers = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
35975
|
-
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
35976
|
-
...new Set([
|
|
35977
|
-
...communityUsers,
|
|
35978
|
-
...response.communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
|
|
35979
|
-
]),
|
|
35980
|
-
] }));
|
|
35981
|
-
}
|
|
35982
|
-
}
|
|
35983
|
-
reactor(action) {
|
|
35984
|
-
return (community, communityMembers) => {
|
|
35985
|
-
var _a;
|
|
35986
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
35987
|
-
if (!collection)
|
|
35988
|
-
return;
|
|
35989
|
-
if (action === EnumCommunityMemberActions$1.OnCommunityUserRoleAdded &&
|
|
35990
|
-
this.query.sortBy === 'displayName') {
|
|
35991
|
-
return;
|
|
35992
|
-
}
|
|
35993
|
-
communityMembers.forEach(communityMember => {
|
|
35994
|
-
const communityMemberCacheId = getResolver('communityUsers')({
|
|
35995
|
-
communityId: this.query.communityId,
|
|
35996
|
-
userId: communityMember.userId,
|
|
35997
|
-
});
|
|
35998
|
-
if (communityMember.communityMembership === 'none') {
|
|
35999
|
-
collection.data = collection.data.filter(m => m !== communityMemberCacheId);
|
|
36000
|
-
}
|
|
36001
|
-
else if (!collection.data.includes(communityMemberCacheId)) {
|
|
36002
|
-
collection.data = [communityMemberCacheId, ...collection.data];
|
|
36003
|
-
}
|
|
36004
|
-
});
|
|
36005
|
-
pushToCache(this.cacheKey, collection);
|
|
36006
|
-
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
36007
|
-
};
|
|
36008
|
-
}
|
|
36009
|
-
subscribeRTE(createSubscriber) {
|
|
36010
|
-
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
36011
|
-
}
|
|
36012
|
-
}
|
|
36013
|
-
|
|
36014
34840
|
/**
|
|
36015
34841
|
* ```js
|
|
36016
34842
|
* import { onLocalCommunityRoleRemoved } from '@amityco/ts-sdk'
|
|
@@ -36188,9 +35014,6 @@ class CommunityMembersLiveCollectionController extends LiveCollectionController
|
|
|
36188
35014
|
return memberships.includes(communityMembership);
|
|
36189
35015
|
});
|
|
36190
35016
|
}
|
|
36191
|
-
if (this.query.search) {
|
|
36192
|
-
communityMembers = filterBySearchTerm(communityMembers, this.query.search);
|
|
36193
|
-
}
|
|
36194
35017
|
if (this.query.includeDeleted === false) {
|
|
36195
35018
|
communityMembers = communityMembers.filter(({ user }) => (user === null || user === void 0 ? void 0 : user.isDeleted) !== true);
|
|
36196
35019
|
}
|
|
@@ -36198,15 +35021,6 @@ class CommunityMembersLiveCollectionController extends LiveCollectionController
|
|
|
36198
35021
|
case 'firstCreated':
|
|
36199
35022
|
communityMembers = communityMembers.sort(sortByFirstCreated);
|
|
36200
35023
|
break;
|
|
36201
|
-
case 'displayName':
|
|
36202
|
-
communityMembers = communityMembers.sort((a, b) => {
|
|
36203
|
-
var _a, _b, _c, _d;
|
|
36204
|
-
if (((_a = a === null || a === void 0 ? void 0 : a.user) === null || _a === void 0 ? void 0 : _a.displayName) && ((_b = b === null || b === void 0 ? void 0 : b.user) === null || _b === void 0 ? void 0 : _b.displayName)) {
|
|
36205
|
-
return (_c = a === null || a === void 0 ? void 0 : a.user) === null || _c === void 0 ? void 0 : _c.displayName.localeCompare((_d = b === null || b === void 0 ? void 0 : b.user) === null || _d === void 0 ? void 0 : _d.displayName);
|
|
36206
|
-
}
|
|
36207
|
-
return 0;
|
|
36208
|
-
});
|
|
36209
|
-
break;
|
|
36210
35024
|
case 'lastCreated':
|
|
36211
35025
|
default:
|
|
36212
35026
|
communityMembers = communityMembers.sort(sortByLastCreated);
|
|
@@ -36228,9 +35042,6 @@ const applyFilter = (data, params) => {
|
|
|
36228
35042
|
return membership.includes(communityMembership);
|
|
36229
35043
|
});
|
|
36230
35044
|
}
|
|
36231
|
-
if (params.search) {
|
|
36232
|
-
communityMembers = filterBySearchTerm(communityMembers, params.search);
|
|
36233
|
-
}
|
|
36234
35045
|
const sortBy = params.sortBy ? params.sortBy : 'lastCreated';
|
|
36235
35046
|
communityMembers = communityMembers.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
36236
35047
|
return communityMembers;
|
|
@@ -36587,209 +35398,202 @@ class SearchCommunityLiveCollectionController extends LiveCollectionController {
|
|
|
36587
35398
|
if (this.query.membership && userId) {
|
|
36588
35399
|
communities = filterByCommunityMembership(communities, this.query.membership, userId);
|
|
36589
35400
|
}
|
|
36590
|
-
return communities;
|
|
36591
|
-
}
|
|
36592
|
-
}
|
|
36593
|
-
|
|
36594
|
-
/* begin_public_function
|
|
36595
|
-
id: community.query
|
|
36596
|
-
*/
|
|
36597
|
-
/**
|
|
36598
|
-
* ```js
|
|
36599
|
-
* import { CommunityRepository } from '@amityco/ts-sdk'
|
|
36600
|
-
*
|
|
36601
|
-
* let communities = []
|
|
36602
|
-
* const unsub = CommunityRepository.searchCommunities({
|
|
36603
|
-
* displayName: Amity.Community['displayName'],
|
|
36604
|
-
* }, response => merge(communities, response.data))
|
|
36605
|
-
* ```
|
|
36606
|
-
*
|
|
36607
|
-
* Observe all mutations on a list of {@link Amity.Community}s
|
|
36608
|
-
*
|
|
36609
|
-
* @param params for querying communities
|
|
36610
|
-
* @param callback the function to call when new data are available
|
|
36611
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the communities
|
|
36612
|
-
*
|
|
36613
|
-
* @category Community Live Collection
|
|
36614
|
-
*/
|
|
36615
|
-
const searchCommunities = (params, callback, config) => {
|
|
36616
|
-
const { log, cache } = getActiveClient();
|
|
36617
|
-
if (!cache) {
|
|
36618
|
-
console.log(ENABLE_CACHE_MESSAGE);
|
|
36619
|
-
}
|
|
36620
|
-
const timestamp = Date.now();
|
|
36621
|
-
log(`searchCommunities(tmpid: ${timestamp}) > listen`);
|
|
36622
|
-
const searchCommunitiesLiveCollection = new SearchCommunityLiveCollectionController(params, callback);
|
|
36623
|
-
const disposers = searchCommunitiesLiveCollection.startSubscription();
|
|
36624
|
-
const cacheKey = searchCommunitiesLiveCollection.getCacheKey();
|
|
36625
|
-
disposers.push(() => dropFromCache(cacheKey));
|
|
36626
|
-
return () => {
|
|
36627
|
-
log(`searchCommunities(tmpid: ${timestamp}) > dispose`);
|
|
36628
|
-
disposers.forEach(fn => fn());
|
|
36629
|
-
};
|
|
36630
|
-
};
|
|
36631
|
-
/* end_public_function */
|
|
36632
|
-
|
|
36633
|
-
/**
|
|
36634
|
-
* TODO: handle cache receive cache option, and cache policy
|
|
36635
|
-
* TODO: check if querybyIds is supported
|
|
36636
|
-
*/
|
|
36637
|
-
class CommunitiesPaginationController extends PaginationController {
|
|
36638
|
-
async getRequest(queryParams, token) {
|
|
36639
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
36640
|
-
const options = token ? { token } : { limit };
|
|
36641
|
-
const { data: queryResponse } = await this.http.get(`/api/v3/communities`, {
|
|
36642
|
-
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(params.includeDeleted),
|
|
36643
|
-
});
|
|
36644
|
-
return queryResponse;
|
|
36645
|
-
}
|
|
36646
|
-
}
|
|
36647
|
-
|
|
36648
|
-
|
|
36649
|
-
(
|
|
36650
|
-
|
|
36651
|
-
|
|
36652
|
-
|
|
36653
|
-
}
|
|
36654
|
-
|
|
36655
|
-
|
|
36656
|
-
|
|
36657
|
-
|
|
36658
|
-
|
|
36659
|
-
|
|
36660
|
-
|
|
36661
|
-
|
|
36662
|
-
|
|
36663
|
-
|
|
36664
|
-
|
|
36665
|
-
if (
|
|
36666
|
-
|
|
36667
|
-
|
|
36668
|
-
|
|
36669
|
-
|
|
36670
|
-
|
|
36671
|
-
|
|
36672
|
-
|
|
36673
|
-
pushToCache(this.cacheKey, {
|
|
36674
|
-
|
|
36675
|
-
|
|
36676
|
-
|
|
36677
|
-
|
|
36678
|
-
|
|
36679
|
-
const
|
|
36680
|
-
|
|
36681
|
-
|
|
36682
|
-
|
|
36683
|
-
|
|
36684
|
-
|
|
36685
|
-
|
|
36686
|
-
|
|
36687
|
-
|
|
36688
|
-
|
|
36689
|
-
|
|
36690
|
-
|
|
36691
|
-
|
|
36692
|
-
|
|
36693
|
-
|
|
36694
|
-
|
|
36695
|
-
|
|
36696
|
-
|
|
36697
|
-
|
|
36698
|
-
|
|
36699
|
-
|
|
36700
|
-
|
|
36701
|
-
|
|
36702
|
-
|
|
36703
|
-
|
|
36704
|
-
|
|
36705
|
-
|
|
36706
|
-
|
|
36707
|
-
|
|
36708
|
-
|
|
36709
|
-
|
|
36710
|
-
|
|
36711
|
-
this.
|
|
36712
|
-
|
|
36713
|
-
|
|
36714
|
-
|
|
36715
|
-
|
|
36716
|
-
|
|
36717
|
-
|
|
36718
|
-
|
|
36719
|
-
|
|
36720
|
-
|
|
36721
|
-
|
|
36722
|
-
|
|
36723
|
-
|
|
36724
|
-
|
|
36725
|
-
}
|
|
36726
|
-
|
|
36727
|
-
|
|
36728
|
-
}
|
|
36729
|
-
|
|
36730
|
-
this.queryStreamController.
|
|
36731
|
-
|
|
36732
|
-
|
|
36733
|
-
|
|
36734
|
-
{ fn:
|
|
36735
|
-
{ fn:
|
|
36736
|
-
{ fn:
|
|
36737
|
-
{ fn:
|
|
36738
|
-
{ fn:
|
|
36739
|
-
|
|
36740
|
-
|
|
36741
|
-
|
|
36742
|
-
|
|
36743
|
-
|
|
36744
|
-
|
|
36745
|
-
|
|
36746
|
-
const
|
|
36747
|
-
|
|
36748
|
-
|
|
36749
|
-
|
|
36750
|
-
|
|
36751
|
-
|
|
36752
|
-
|
|
36753
|
-
|
|
36754
|
-
|
|
36755
|
-
|
|
36756
|
-
|
|
36757
|
-
|
|
36758
|
-
|
|
36759
|
-
|
|
36760
|
-
|
|
36761
|
-
});
|
|
36762
|
-
|
|
36763
|
-
|
|
36764
|
-
|
|
36765
|
-
|
|
36766
|
-
if (
|
|
36767
|
-
communities =
|
|
36768
|
-
}
|
|
36769
|
-
if (this.query.
|
|
36770
|
-
communities = communities.filter(c => { var _a; return (_a = c.
|
|
36771
|
-
}
|
|
36772
|
-
if (this.query.
|
|
36773
|
-
communities = communities
|
|
36774
|
-
}
|
|
36775
|
-
if (this.query.membership && userId) {
|
|
36776
|
-
communities = filterByCommunityMembership(communities, this.query.membership, userId);
|
|
36777
|
-
}
|
|
36778
|
-
if (!this.query.displayName) {
|
|
36779
|
-
const sortFn = (() => {
|
|
36780
|
-
switch (this.query.sortBy) {
|
|
36781
|
-
case 'firstCreated':
|
|
36782
|
-
return sortByFirstCreated;
|
|
36783
|
-
case 'lastCreated':
|
|
36784
|
-
return sortByLastCreated;
|
|
36785
|
-
case 'displayName':
|
|
36786
|
-
return sortByDisplayName;
|
|
36787
|
-
default:
|
|
36788
|
-
return sortByLastCreated;
|
|
36789
|
-
}
|
|
36790
|
-
})();
|
|
36791
|
-
communities = communities.sort(sortFn);
|
|
35401
|
+
return communities;
|
|
35402
|
+
}
|
|
35403
|
+
}
|
|
35404
|
+
|
|
35405
|
+
/* begin_public_function
|
|
35406
|
+
id: community.query
|
|
35407
|
+
*/
|
|
35408
|
+
/**
|
|
35409
|
+
* ```js
|
|
35410
|
+
* import { CommunityRepository } from '@amityco/ts-sdk'
|
|
35411
|
+
*
|
|
35412
|
+
* let communities = []
|
|
35413
|
+
* const unsub = CommunityRepository.searchCommunities({
|
|
35414
|
+
* displayName: Amity.Community['displayName'],
|
|
35415
|
+
* }, response => merge(communities, response.data))
|
|
35416
|
+
* ```
|
|
35417
|
+
*
|
|
35418
|
+
* Observe all mutations on a list of {@link Amity.Community}s
|
|
35419
|
+
*
|
|
35420
|
+
* @param params for querying communities
|
|
35421
|
+
* @param callback the function to call when new data are available
|
|
35422
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the communities
|
|
35423
|
+
*
|
|
35424
|
+
* @category Community Live Collection
|
|
35425
|
+
*/
|
|
35426
|
+
const searchCommunities = (params, callback, config) => {
|
|
35427
|
+
const { log, cache } = getActiveClient();
|
|
35428
|
+
if (!cache) {
|
|
35429
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
35430
|
+
}
|
|
35431
|
+
const timestamp = Date.now();
|
|
35432
|
+
log(`searchCommunities(tmpid: ${timestamp}) > listen`);
|
|
35433
|
+
const searchCommunitiesLiveCollection = new SearchCommunityLiveCollectionController(params, callback);
|
|
35434
|
+
const disposers = searchCommunitiesLiveCollection.startSubscription();
|
|
35435
|
+
const cacheKey = searchCommunitiesLiveCollection.getCacheKey();
|
|
35436
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
35437
|
+
return () => {
|
|
35438
|
+
log(`searchCommunities(tmpid: ${timestamp}) > dispose`);
|
|
35439
|
+
disposers.forEach(fn => fn());
|
|
35440
|
+
};
|
|
35441
|
+
};
|
|
35442
|
+
/* end_public_function */
|
|
35443
|
+
|
|
35444
|
+
/**
|
|
35445
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
35446
|
+
* TODO: check if querybyIds is supported
|
|
35447
|
+
*/
|
|
35448
|
+
class CommunitiesPaginationController extends PaginationController {
|
|
35449
|
+
async getRequest(queryParams, token) {
|
|
35450
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
35451
|
+
const options = token ? { token } : { limit };
|
|
35452
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/communities`, {
|
|
35453
|
+
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(params.includeDeleted), filter: params.membership, options }),
|
|
35454
|
+
});
|
|
35455
|
+
return queryResponse;
|
|
35456
|
+
}
|
|
35457
|
+
}
|
|
35458
|
+
|
|
35459
|
+
class CommunitiesQueryStreamController extends QueryStreamController {
|
|
35460
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
35461
|
+
super(query, cacheKey);
|
|
35462
|
+
this.notifyChange = notifyChange;
|
|
35463
|
+
this.preparePayload = preparePayload;
|
|
35464
|
+
}
|
|
35465
|
+
async saveToMainDB(response) {
|
|
35466
|
+
const processedPayload = await this.preparePayload(response);
|
|
35467
|
+
const client = getActiveClient();
|
|
35468
|
+
const cachedAt = client.cache && Date.now();
|
|
35469
|
+
if (client.cache) {
|
|
35470
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
35471
|
+
saveCommunityUsers(response.communities, response.communityUsers);
|
|
35472
|
+
}
|
|
35473
|
+
}
|
|
35474
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
35475
|
+
var _a, _b;
|
|
35476
|
+
if (refresh) {
|
|
35477
|
+
pushToCache(this.cacheKey, {
|
|
35478
|
+
data: response.communities.map(getResolver('community')),
|
|
35479
|
+
});
|
|
35480
|
+
}
|
|
35481
|
+
else {
|
|
35482
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
35483
|
+
const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
35484
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...communities, ...response.communities.map(getResolver('community'))])] }));
|
|
35485
|
+
}
|
|
35486
|
+
}
|
|
35487
|
+
reactor(action) {
|
|
35488
|
+
return (community) => {
|
|
35489
|
+
var _a;
|
|
35490
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
35491
|
+
if (!collection)
|
|
35492
|
+
return;
|
|
35493
|
+
/*
|
|
35494
|
+
* Simply update a collection and let responder decide what to do with data
|
|
35495
|
+
*/
|
|
35496
|
+
collection.data = [...new Set([community.communityId, ...collection.data])];
|
|
35497
|
+
pushToCache(this.cacheKey, collection);
|
|
35498
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
35499
|
+
};
|
|
35500
|
+
}
|
|
35501
|
+
subscribeRTE(createSubscriber) {
|
|
35502
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
35503
|
+
}
|
|
35504
|
+
}
|
|
35505
|
+
|
|
35506
|
+
var EnumCommunityActions$3;
|
|
35507
|
+
(function (EnumCommunityActions) {
|
|
35508
|
+
EnumCommunityActions["OnCommunityCreated"] = "onCommunityCreated";
|
|
35509
|
+
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
35510
|
+
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
35511
|
+
})(EnumCommunityActions$3 || (EnumCommunityActions$3 = {}));
|
|
35512
|
+
|
|
35513
|
+
class CommunityLiveCollectionController extends LiveCollectionController {
|
|
35514
|
+
constructor(query, callback) {
|
|
35515
|
+
const queryStreamId = hash(query);
|
|
35516
|
+
const cacheKey = ['community', 'collection', queryStreamId];
|
|
35517
|
+
const paginationController = new CommunitiesPaginationController(query);
|
|
35518
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
35519
|
+
this.query = query;
|
|
35520
|
+
this.queryStreamController = new CommunitiesQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityPayload);
|
|
35521
|
+
this.callback = callback.bind(this);
|
|
35522
|
+
this.loadPage({ initial: true });
|
|
35523
|
+
}
|
|
35524
|
+
setup() {
|
|
35525
|
+
var _a;
|
|
35526
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
35527
|
+
if (!collection) {
|
|
35528
|
+
pushToCache(this.cacheKey, {
|
|
35529
|
+
data: [],
|
|
35530
|
+
params: {},
|
|
35531
|
+
});
|
|
35532
|
+
}
|
|
35533
|
+
}
|
|
35534
|
+
async persistModel(queryPayload) {
|
|
35535
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
35536
|
+
}
|
|
35537
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
35538
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
35539
|
+
}
|
|
35540
|
+
startSubscription() {
|
|
35541
|
+
return this.queryStreamController.subscribeRTE([
|
|
35542
|
+
{ fn: onCommunityCreated, action: EnumCommunityActions$3.OnCommunityCreated },
|
|
35543
|
+
{ fn: onCommunityDeleted, action: EnumCommunityActions$3.OnCommunityDeleted },
|
|
35544
|
+
{ fn: onCommunityUpdated, action: EnumCommunityActions$3.OnCommunityUpdated },
|
|
35545
|
+
{ fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
35546
|
+
{ fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
35547
|
+
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
|
|
35548
|
+
{ fn: onLocalCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
35549
|
+
{ fn: onLocalCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
35550
|
+
]);
|
|
35551
|
+
}
|
|
35552
|
+
notifyChange({ origin, loading, error }) {
|
|
35553
|
+
var _a, _b;
|
|
35554
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
35555
|
+
if (!collection)
|
|
35556
|
+
return;
|
|
35557
|
+
const data = this.applyFilter((_b = collection.data
|
|
35558
|
+
.map(id => pullFromCache(['community', 'get', id]))
|
|
35559
|
+
.filter(isNonNullable)
|
|
35560
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
|
|
35561
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
35562
|
+
return;
|
|
35563
|
+
this.callback({
|
|
35564
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
35565
|
+
data,
|
|
35566
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
35567
|
+
loading,
|
|
35568
|
+
error,
|
|
35569
|
+
});
|
|
35570
|
+
}
|
|
35571
|
+
applyFilter(data) {
|
|
35572
|
+
const { userId } = getActiveClient();
|
|
35573
|
+
let communities = data;
|
|
35574
|
+
if (!this.query.includeDeleted) {
|
|
35575
|
+
communities = filterByPropEquality(communities, 'isDeleted', false);
|
|
35576
|
+
}
|
|
35577
|
+
if (this.query.categoryId) {
|
|
35578
|
+
communities = communities.filter(c => { var _a; return (_a = c.categoryIds) === null || _a === void 0 ? void 0 : _a.includes(this.query.categoryId); });
|
|
35579
|
+
}
|
|
35580
|
+
if (this.query.tags) {
|
|
35581
|
+
communities = communities.filter(c => { var _a; return (_a = c.tags) === null || _a === void 0 ? void 0 : _a.some(t => { var _a; return (_a = this.query.tags) === null || _a === void 0 ? void 0 : _a.includes(t); }); });
|
|
35582
|
+
}
|
|
35583
|
+
if (this.query.membership && userId) {
|
|
35584
|
+
communities = filterByCommunityMembership(communities, this.query.membership, userId);
|
|
36792
35585
|
}
|
|
35586
|
+
const sortFn = (() => {
|
|
35587
|
+
switch (this.query.sortBy) {
|
|
35588
|
+
case 'firstCreated':
|
|
35589
|
+
return sortByFirstCreated;
|
|
35590
|
+
case 'lastCreated':
|
|
35591
|
+
return sortByLastCreated;
|
|
35592
|
+
default:
|
|
35593
|
+
return sortByLastCreated;
|
|
35594
|
+
}
|
|
35595
|
+
})();
|
|
35596
|
+
communities = communities.sort(sortFn);
|
|
36793
35597
|
return communities;
|
|
36794
35598
|
}
|
|
36795
35599
|
}
|
|
@@ -37543,11 +36347,9 @@ var index$9 = /*#__PURE__*/Object.freeze({
|
|
|
37543
36347
|
deleteCommunity: deleteCommunity,
|
|
37544
36348
|
joinCommunity: joinCommunity,
|
|
37545
36349
|
leaveCommunity: leaveCommunity,
|
|
37546
|
-
getTopTrendingCommunities: getTopTrendingCommunities,
|
|
37547
36350
|
onCommunityCreated: onCommunityCreated,
|
|
37548
36351
|
onCommunityUpdated: onCommunityUpdated,
|
|
37549
36352
|
onCommunityDeleted: onCommunityDeleted,
|
|
37550
|
-
observeCommunity: observeCommunity,
|
|
37551
36353
|
searchCommunities: searchCommunities,
|
|
37552
36354
|
getCommunities: getCommunities,
|
|
37553
36355
|
getCommunity: getCommunity,
|
|
@@ -37797,21 +36599,10 @@ var index$8 = /*#__PURE__*/Object.freeze({
|
|
|
37797
36599
|
const queryGlobalFeed = async (query) => {
|
|
37798
36600
|
const client = getActiveClient();
|
|
37799
36601
|
client.log('feed/queryGlobalFeed', query);
|
|
37800
|
-
const _a = query !== null && query !== void 0 ? query : {}, {
|
|
37801
|
-
/*
|
|
37802
|
-
* TODO: Remove useCustomRanking key from query
|
|
37803
|
-
*/
|
|
37804
|
-
if (useCustomRanking)
|
|
37805
|
-
console.warn('The param "useCustomRanking" has been deprecated. To get custom ranking feed use FeedRepository.getCustomRankingGlobalFeed instead');
|
|
37806
|
-
if (page)
|
|
37807
|
-
console.warn('The param "page" has been deprecated. Please use "queryToken" instead.');
|
|
36602
|
+
const _a = query !== null && query !== void 0 ? query : {}, { queryToken } = _a, params = __rest(_a, ["queryToken"]);
|
|
37808
36603
|
const options = (() => {
|
|
37809
36604
|
if (queryToken)
|
|
37810
36605
|
return { token: queryToken };
|
|
37811
|
-
if (page)
|
|
37812
|
-
return {
|
|
37813
|
-
token: toToken(page, 'skiplimit'),
|
|
37814
|
-
};
|
|
37815
36606
|
return undefined;
|
|
37816
36607
|
})();
|
|
37817
36608
|
const { data: queryPayload } = await client.http.get(`/api/v4/me/global-feeds`, {
|
|
@@ -37824,20 +36615,12 @@ const queryGlobalFeed = async (query) => {
|
|
|
37824
36615
|
const cachedAt = client.cache && Date.now();
|
|
37825
36616
|
if (client.cache) {
|
|
37826
36617
|
ingestInCache(Object.assign(Object.assign({}, data), { communitis: processedCommunity }));
|
|
37827
|
-
const cacheKey = [
|
|
37828
|
-
'globalFeed',
|
|
37829
|
-
'query',
|
|
37830
|
-
Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
|
|
37831
|
-
];
|
|
36618
|
+
const cacheKey = ['globalFeed', 'query', Object.assign(Object.assign({}, params), { options })];
|
|
37832
36619
|
pushToCache(cacheKey, { posts: posts.map(getResolver('post')), paging });
|
|
37833
36620
|
}
|
|
37834
|
-
const nextPage = toPage(paging.next);
|
|
37835
|
-
const prevPage = toPage(paging.previous);
|
|
37836
36621
|
return {
|
|
37837
36622
|
data: posts.map(LinkedObject.post),
|
|
37838
36623
|
cachedAt,
|
|
37839
|
-
prevPage,
|
|
37840
|
-
nextPage,
|
|
37841
36624
|
paging,
|
|
37842
36625
|
};
|
|
37843
36626
|
};
|
|
@@ -37862,12 +36645,8 @@ queryGlobalFeed.locally = (query) => {
|
|
|
37862
36645
|
client.log('post/queryGlobalFeed.locally', query);
|
|
37863
36646
|
if (!client.cache)
|
|
37864
36647
|
return;
|
|
37865
|
-
const
|
|
37866
|
-
const queryKey = [
|
|
37867
|
-
'globalFeed',
|
|
37868
|
-
'query',
|
|
37869
|
-
Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
|
|
37870
|
-
];
|
|
36648
|
+
const params = __rest(query !== null && query !== void 0 ? query : {}, []);
|
|
36649
|
+
const queryKey = ['globalFeed', 'query', Object.assign({}, params)];
|
|
37871
36650
|
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
37872
36651
|
if (!(data === null || data === void 0 ? void 0 : data.posts.length))
|
|
37873
36652
|
return;
|
|
@@ -37877,14 +36656,10 @@ queryGlobalFeed.locally = (query) => {
|
|
|
37877
36656
|
.map(({ data }) => data)
|
|
37878
36657
|
.map(LinkedObject.post);
|
|
37879
36658
|
const { paging } = data;
|
|
37880
|
-
const prevPage = toPage(data === null || data === void 0 ? void 0 : data.paging.previous);
|
|
37881
|
-
const nextPage = toPage(data === null || data === void 0 ? void 0 : data.paging.next);
|
|
37882
36659
|
return posts.length === ((_b = data === null || data === void 0 ? void 0 : data.posts) === null || _b === void 0 ? void 0 : _b.length)
|
|
37883
36660
|
? {
|
|
37884
36661
|
data: posts,
|
|
37885
36662
|
cachedAt,
|
|
37886
|
-
prevPage,
|
|
37887
|
-
nextPage,
|
|
37888
36663
|
paging,
|
|
37889
36664
|
}
|
|
37890
36665
|
: undefined;
|
|
@@ -37910,14 +36685,10 @@ queryGlobalFeed.locally = (query) => {
|
|
|
37910
36685
|
const getCustomRankingGlobalFeed = async (query) => {
|
|
37911
36686
|
const client = getActiveClient();
|
|
37912
36687
|
client.log('feed/getCustomRankingGlobalFeed', query);
|
|
37913
|
-
const _a = query !== null && query !== void 0 ? query : {}, {
|
|
36688
|
+
const _a = query !== null && query !== void 0 ? query : {}, { queryToken, limit } = _a, params = __rest(_a, ["queryToken", "limit"]);
|
|
37914
36689
|
const options = (() => {
|
|
37915
36690
|
if (queryToken)
|
|
37916
36691
|
return { token: queryToken };
|
|
37917
|
-
if (page)
|
|
37918
|
-
return {
|
|
37919
|
-
token: toToken(page, 'skiplimit'),
|
|
37920
|
-
};
|
|
37921
36692
|
return undefined;
|
|
37922
36693
|
})();
|
|
37923
36694
|
const { data: queryPayload } = await client.http.get(`/api/v5/me/global-feeds`, {
|
|
@@ -37929,16 +36700,12 @@ const getCustomRankingGlobalFeed = async (query) => {
|
|
|
37929
36700
|
const cachedAt = client.cache && Date.now();
|
|
37930
36701
|
if (client.cache) {
|
|
37931
36702
|
ingestInCache(data);
|
|
37932
|
-
const cacheKey = [
|
|
37933
|
-
'customGlobalFeed',
|
|
37934
|
-
'query',
|
|
37935
|
-
Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
|
|
37936
|
-
];
|
|
36703
|
+
const cacheKey = ['customGlobalFeed', 'query', Object.assign(Object.assign({}, params), { options })];
|
|
37937
36704
|
pushToCache(cacheKey, { posts: posts.map(getResolver('post')), paging });
|
|
37938
36705
|
}
|
|
37939
|
-
|
|
37940
|
-
|
|
37941
|
-
return { data: posts.map(LinkedObject.post), cachedAt,
|
|
36706
|
+
toPage(paging.next);
|
|
36707
|
+
toPage(paging.previous);
|
|
36708
|
+
return { data: posts.map(LinkedObject.post), cachedAt, paging };
|
|
37942
36709
|
};
|
|
37943
36710
|
/* end_public_function */
|
|
37944
36711
|
/**
|
|
@@ -37961,12 +36728,8 @@ getCustomRankingGlobalFeed.locally = (query) => {
|
|
|
37961
36728
|
client.log('post/getCustomRankingGlobalFeed.locally', query);
|
|
37962
36729
|
if (!client.cache)
|
|
37963
36730
|
return;
|
|
37964
|
-
const
|
|
37965
|
-
const queryKey = [
|
|
37966
|
-
'customGlobalFeed',
|
|
37967
|
-
'query',
|
|
37968
|
-
Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
|
|
37969
|
-
];
|
|
36731
|
+
const params = __rest(query !== null && query !== void 0 ? query : {}, []);
|
|
36732
|
+
const queryKey = ['customGlobalFeed', 'query', Object.assign({}, params)];
|
|
37970
36733
|
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
37971
36734
|
if (!(data === null || data === void 0 ? void 0 : data.posts.length))
|
|
37972
36735
|
return;
|
|
@@ -37974,11 +36737,9 @@ getCustomRankingGlobalFeed.locally = (query) => {
|
|
|
37974
36737
|
.map(postId => pullFromCache(['post', 'get', postId]))
|
|
37975
36738
|
.filter(Boolean)
|
|
37976
36739
|
.map(({ data }) => data);
|
|
37977
|
-
const prevPage = toPage(data === null || data === void 0 ? void 0 : data.paging.previous);
|
|
37978
|
-
const nextPage = toPage(data === null || data === void 0 ? void 0 : data.paging.next);
|
|
37979
36740
|
const { paging } = data;
|
|
37980
36741
|
return posts.length === ((_b = data === null || data === void 0 ? void 0 : data.posts) === null || _b === void 0 ? void 0 : _b.length)
|
|
37981
|
-
? { data: posts.map(LinkedObject.post), cachedAt,
|
|
36742
|
+
? { data: posts.map(LinkedObject.post), cachedAt, paging }
|
|
37982
36743
|
: undefined;
|
|
37983
36744
|
};
|
|
37984
36745
|
|
|
@@ -38109,44 +36870,6 @@ const createPost = async (bundle) => {
|
|
|
38109
36870
|
};
|
|
38110
36871
|
/* end_public_function */
|
|
38111
36872
|
|
|
38112
|
-
/* begin_public_function
|
|
38113
|
-
id: post.edit
|
|
38114
|
-
*/
|
|
38115
|
-
/**
|
|
38116
|
-
* ```js
|
|
38117
|
-
* import { updatePost } from '@amityco/ts-sdk'
|
|
38118
|
-
* const updated = await updatePost(postId, {
|
|
38119
|
-
* data: { text: 'hello world' }
|
|
38120
|
-
* })
|
|
38121
|
-
* ```
|
|
38122
|
-
*
|
|
38123
|
-
* Updates an {@link Amity.Post}
|
|
38124
|
-
*
|
|
38125
|
-
* @param postId The ID of the {@link Amity.Post} to edit
|
|
38126
|
-
* @param patch The patch data to apply
|
|
38127
|
-
* @returns the updated {@link Amity.Post} object
|
|
38128
|
-
*
|
|
38129
|
-
* @category Post API
|
|
38130
|
-
* @async
|
|
38131
|
-
*/
|
|
38132
|
-
const updatePost = async (postId, patch) => {
|
|
38133
|
-
const client = getActiveClient();
|
|
38134
|
-
client.log('user/updatePost', patch);
|
|
38135
|
-
console.warn('Deprecation: updatePost has been renamed to editPost. Update post API will be deprecated soon.');
|
|
38136
|
-
const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, patch);
|
|
38137
|
-
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
38138
|
-
const cachedAt = client.cache && Date.now();
|
|
38139
|
-
if (client.cache)
|
|
38140
|
-
ingestInCache(data, { cachedAt });
|
|
38141
|
-
fireEvent('local.post.updated', payload);
|
|
38142
|
-
const { posts } = data;
|
|
38143
|
-
return {
|
|
38144
|
-
data: LinkedObject.post(posts.find(post => post.postId === postId)),
|
|
38145
|
-
cachedAt,
|
|
38146
|
-
};
|
|
38147
|
-
};
|
|
38148
|
-
/* end_public_function */
|
|
38149
|
-
|
|
38150
36873
|
/* begin_public_function
|
|
38151
36874
|
id: post.edit, post.edit.custom_post
|
|
38152
36875
|
*/
|
|
@@ -38464,91 +37187,6 @@ const isPostFlaggedByMe = async (postId) => {
|
|
|
38464
37187
|
};
|
|
38465
37188
|
/* end_public_function */
|
|
38466
37189
|
|
|
38467
|
-
/**
|
|
38468
|
-
* ```js
|
|
38469
|
-
* import { PostRepository } from '@amityco/ts-sdk'
|
|
38470
|
-
*
|
|
38471
|
-
* let posts = []
|
|
38472
|
-
* const unsub = PostRepository.observePosts({
|
|
38473
|
-
* targetType: Amity.PostTargetType,
|
|
38474
|
-
* targetId: Amity.InternalPost['targetId'],
|
|
38475
|
-
* }, post => merge(posts, post))
|
|
38476
|
-
* ```
|
|
38477
|
-
*
|
|
38478
|
-
* Observe all mutations on a list of {@link Amity.Post} for a given target object
|
|
38479
|
-
*
|
|
38480
|
-
* @param params
|
|
38481
|
-
* @param callback the function to call when new data are available
|
|
38482
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
38483
|
-
*
|
|
38484
|
-
* @category Post Observer
|
|
38485
|
-
*/
|
|
38486
|
-
const observePosts = (params, callback) => {
|
|
38487
|
-
const { log } = getActiveClient();
|
|
38488
|
-
const timestamp = Date.now();
|
|
38489
|
-
log(`observePosts(tmpid: ${timestamp}) > listen`);
|
|
38490
|
-
const disposers = [];
|
|
38491
|
-
const router = (post, action) => {
|
|
38492
|
-
var _a, _b;
|
|
38493
|
-
if (params.targetId !== post.targetId || params.targetType !== post.targetType)
|
|
38494
|
-
return;
|
|
38495
|
-
if (callback instanceof Function)
|
|
38496
|
-
return callback(LinkedObject.post(post));
|
|
38497
|
-
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, LinkedObject.post(post));
|
|
38498
|
-
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, LinkedObject.post(post));
|
|
38499
|
-
};
|
|
38500
|
-
disposers.push(onPostCreated(post => router(post, 'onCreate')), onPostUpdated(post => router(post, 'onUpdate')), onPostDeleted(post => router(post, 'onDelete')), onPostApproved(post => router(post, 'onApproved')), onPostDeclined(post => router(post, 'onDeclined')), onPostFlagged(post => router(post, 'onFlagged')), onPostUnflagged(post => router(post, 'onUnflagged')), onPostReactionAdded(post => router(post, 'onReactionAdded')), onPostReactionRemoved(post => router(post, 'onReactionRemoved')));
|
|
38501
|
-
return () => {
|
|
38502
|
-
log(`observePosts(tmpid: ${timestamp}) > dispose`);
|
|
38503
|
-
disposers.forEach(fn => fn());
|
|
38504
|
-
};
|
|
38505
|
-
};
|
|
38506
|
-
|
|
38507
|
-
/**
|
|
38508
|
-
* ```js
|
|
38509
|
-
* import { observePost } from '@amityco/ts-sdk'
|
|
38510
|
-
*
|
|
38511
|
-
* let post = {}
|
|
38512
|
-
* const dispose = observePost(postId, updated => post = updated)
|
|
38513
|
-
* ```
|
|
38514
|
-
*
|
|
38515
|
-
* Observe all mutations on a given {@link Amity.Post}
|
|
38516
|
-
*
|
|
38517
|
-
* @param postId the ID of the post to observe
|
|
38518
|
-
* @param callback the function to call when new data are available
|
|
38519
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the post
|
|
38520
|
-
*
|
|
38521
|
-
* @category Post Observer
|
|
38522
|
-
*/
|
|
38523
|
-
const observePost = (postId, callback, policy = 'cache_then_server') => {
|
|
38524
|
-
const { log } = getActiveClient();
|
|
38525
|
-
const timestamp = Date.now();
|
|
38526
|
-
log(`observePost(tmpid: ${timestamp}) > listen`);
|
|
38527
|
-
// wrapper function to make sure
|
|
38528
|
-
const router = (result, action) => {
|
|
38529
|
-
var _a, _b;
|
|
38530
|
-
if (callback instanceof Function)
|
|
38531
|
-
return callback(result);
|
|
38532
|
-
if (action !== 'onFetch')
|
|
38533
|
-
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, result);
|
|
38534
|
-
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, result);
|
|
38535
|
-
};
|
|
38536
|
-
const realtimeRouter = (result, action) => {
|
|
38537
|
-
var _a;
|
|
38538
|
-
if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.postId) !== postId)
|
|
38539
|
-
return;
|
|
38540
|
-
router(Object.assign(Object.assign({}, result), { data: result.data && LinkedObject.post(result.data) }), action);
|
|
38541
|
-
};
|
|
38542
|
-
const disposers = [];
|
|
38543
|
-
disposers.push(onPostUpdated(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUpdate')), onPostDeleted(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onDelete')), onPostApproved(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onApproved')), onPostDeclined(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onDeclined')), onPostFlagged(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onFlagged')), onPostUnflagged(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUnflagged')), onPostReactionAdded(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onReactionAdded')), onPostReactionRemoved(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onReactionRemoved')));
|
|
38544
|
-
runQuery(createQuery(getPost$2, postId), result => (result.data || result.error) &&
|
|
38545
|
-
router(Object.assign(Object.assign({}, result), { data: result.data && LinkedObject.post(result.data) }), 'onFetch'), queryOptions(policy));
|
|
38546
|
-
return () => {
|
|
38547
|
-
log(`observePosts(tmpid: ${timestamp}) > dispose`);
|
|
38548
|
-
disposers.forEach(fn => fn());
|
|
38549
|
-
};
|
|
38550
|
-
};
|
|
38551
|
-
|
|
38552
37190
|
/* begin_public_function
|
|
38553
37191
|
id: comment.get_by_ids
|
|
38554
37192
|
*/
|
|
@@ -39024,43 +37662,6 @@ const isCommentFlaggedByMe = async (commentId) => {
|
|
|
39024
37662
|
};
|
|
39025
37663
|
/* end_public_function */
|
|
39026
37664
|
|
|
39027
|
-
/**
|
|
39028
|
-
* ```js
|
|
39029
|
-
* import { observeComments } from '@amityco/ts-sdk'
|
|
39030
|
-
*
|
|
39031
|
-
* let comments = []
|
|
39032
|
-
* const unsub = observeComments(postId, comment => merge(comments, comment))
|
|
39033
|
-
* ```
|
|
39034
|
-
*
|
|
39035
|
-
* Observe all mutations on a list of {@link Amity.InternalComment} for a given {@link Amity.Post} object
|
|
39036
|
-
*
|
|
39037
|
-
* @param postId the ID of the post where to observe the comments
|
|
39038
|
-
* @param callback the function to call when new data are available
|
|
39039
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the comments
|
|
39040
|
-
*
|
|
39041
|
-
* @category InternalComment Observer
|
|
39042
|
-
*/
|
|
39043
|
-
const observeComments = (postId, callback) => {
|
|
39044
|
-
const { log } = getActiveClient();
|
|
39045
|
-
const timestamp = Date.now();
|
|
39046
|
-
log(`observeComments(tmpid: ${timestamp}) > listen`);
|
|
39047
|
-
const disposers = [];
|
|
39048
|
-
const router = (comment, action) => {
|
|
39049
|
-
var _a, _b;
|
|
39050
|
-
if (comment.referenceId !== postId)
|
|
39051
|
-
return;
|
|
39052
|
-
if (callback instanceof Function)
|
|
39053
|
-
return callback(comment);
|
|
39054
|
-
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, comment);
|
|
39055
|
-
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, comment);
|
|
39056
|
-
};
|
|
39057
|
-
disposers.push(onCommentCreated(comment => router(comment, 'onCreate')), onCommentUpdated(comment => router(comment, 'onUpdate')), onCommentDeleted(comment => router(comment, 'onDelete')), onCommentFlagged(comment => router(comment, 'onFlagged')), onCommentUnflagged(comment => router(comment, 'onUnflagged')), onCommentReactionAdded(comment => router(comment, 'onReactionAdded')), onCommentReactionRemoved(comment => router(comment, 'onReactionRemoved')));
|
|
39058
|
-
return () => {
|
|
39059
|
-
log(`observeComments(tmpid: ${timestamp}) > dispose`);
|
|
39060
|
-
disposers.forEach(fn => fn());
|
|
39061
|
-
};
|
|
39062
|
-
};
|
|
39063
|
-
|
|
39064
37665
|
const getComment$1 = async (commentId) => {
|
|
39065
37666
|
const client = getActiveClient();
|
|
39066
37667
|
client.log('comment/getComment', commentId);
|
|
@@ -39100,50 +37701,6 @@ getComment$1.locally = (commentId) => {
|
|
|
39100
37701
|
};
|
|
39101
37702
|
};
|
|
39102
37703
|
|
|
39103
|
-
/**
|
|
39104
|
-
* ```js
|
|
39105
|
-
* import { observeComment } from '@amityco/ts-sdk'
|
|
39106
|
-
*
|
|
39107
|
-
* let comment = {}
|
|
39108
|
-
* const dispose = observeComment(commentId, ({ data }) => comment = data)
|
|
39109
|
-
* ```
|
|
39110
|
-
*
|
|
39111
|
-
* Observe all mutation on a given {@link Amity.InternalComment}
|
|
39112
|
-
*
|
|
39113
|
-
* @param commentId the ID of the comment to observe
|
|
39114
|
-
* @param callback the function to call when new data are available
|
|
39115
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the comment
|
|
39116
|
-
*
|
|
39117
|
-
* @category InternalComment Observer
|
|
39118
|
-
*/
|
|
39119
|
-
const observeComment = (commentId, callback, policy = 'cache_then_server') => {
|
|
39120
|
-
const { log } = getActiveClient();
|
|
39121
|
-
const timestamp = Date.now();
|
|
39122
|
-
log(`observeComment(tmpid: ${timestamp}) > listen`);
|
|
39123
|
-
// wrapper function to make sure
|
|
39124
|
-
const router = (result, action) => {
|
|
39125
|
-
var _a, _b;
|
|
39126
|
-
if (callback instanceof Function)
|
|
39127
|
-
return callback(result);
|
|
39128
|
-
if (action !== 'onFetch')
|
|
39129
|
-
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, result);
|
|
39130
|
-
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, result);
|
|
39131
|
-
};
|
|
39132
|
-
const realtimeRouter = (result, action) => {
|
|
39133
|
-
var _a;
|
|
39134
|
-
if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.commentId) !== commentId)
|
|
39135
|
-
return;
|
|
39136
|
-
router(result, action);
|
|
39137
|
-
};
|
|
39138
|
-
const disposers = [];
|
|
39139
|
-
disposers.push(onCommentUpdated(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUpdate')), onCommentDeleted(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onDelete')), onCommentFlagged(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onFlagged')), onCommentUnflagged(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUnflagged')), onCommentReactionAdded(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onReactionAdded')), onCommentReactionRemoved(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onReactionRemoved')));
|
|
39140
|
-
runQuery(createQuery(getComment$1, commentId), result => (result.data || result.error) && router(result, 'onFetch'), queryOptions(policy));
|
|
39141
|
-
return () => {
|
|
39142
|
-
log(`observeComment(tmpid: ${timestamp}) > dispose`);
|
|
39143
|
-
disposers.forEach(fn => fn());
|
|
39144
|
-
};
|
|
39145
|
-
};
|
|
39146
|
-
|
|
39147
37704
|
/**
|
|
39148
37705
|
* ```js
|
|
39149
37706
|
* import { onCommentDeleteLocal } from '@amityco/ts-sdk'
|
|
@@ -39519,8 +38076,6 @@ var index$6 = /*#__PURE__*/Object.freeze({
|
|
|
39519
38076
|
onCommentUnflagged: onCommentUnflagged,
|
|
39520
38077
|
onCommentReactionAdded: onCommentReactionAdded,
|
|
39521
38078
|
onCommentReactionRemoved: onCommentReactionRemoved,
|
|
39522
|
-
observeComments: observeComments,
|
|
39523
|
-
observeComment: observeComment,
|
|
39524
38079
|
getComment: getComment,
|
|
39525
38080
|
getComments: getComments
|
|
39526
38081
|
});
|
|
@@ -40514,7 +39069,6 @@ var index$5 = /*#__PURE__*/Object.freeze({
|
|
|
40514
39069
|
__proto__: null,
|
|
40515
39070
|
getPostByIds: getPostByIds,
|
|
40516
39071
|
createPost: createPost,
|
|
40517
|
-
updatePost: updatePost,
|
|
40518
39072
|
editPost: editPost,
|
|
40519
39073
|
deletePost: deletePost,
|
|
40520
39074
|
softDeletePost: softDeletePost,
|
|
@@ -40533,8 +39087,6 @@ var index$5 = /*#__PURE__*/Object.freeze({
|
|
|
40533
39087
|
onPostUnflagged: onPostUnflagged,
|
|
40534
39088
|
onPostReactionAdded: onPostReactionAdded,
|
|
40535
39089
|
onPostReactionRemoved: onPostReactionRemoved,
|
|
40536
|
-
observePosts: observePosts,
|
|
40537
|
-
observePost: observePost,
|
|
40538
39090
|
getPost: getPost$1,
|
|
40539
39091
|
getPosts: getPosts,
|
|
40540
39092
|
getPinnedPosts: getPinnedPosts,
|
|
@@ -40727,47 +39279,6 @@ const disposeStream = async (streamId) => {
|
|
|
40727
39279
|
};
|
|
40728
39280
|
/* end_public_function */
|
|
40729
39281
|
|
|
40730
|
-
/* begin_public_function
|
|
40731
|
-
id: stream.query
|
|
40732
|
-
*/
|
|
40733
|
-
/**
|
|
40734
|
-
* @deprecated This API renamed to `getStreams`.
|
|
40735
|
-
* Please use getStreams() instead.
|
|
40736
|
-
* ```js
|
|
40737
|
-
* import { getStreams } from '@amityco/ts-sdk'
|
|
40738
|
-
* const streams = await getStreams()
|
|
40739
|
-
* ```
|
|
40740
|
-
*
|
|
40741
|
-
* Queries a paginable list of {@link Amity.InternalStream} objects
|
|
40742
|
-
*
|
|
40743
|
-
* @param query The query parameters
|
|
40744
|
-
* @returns A page of {@link Amity.InternalStream} objects
|
|
40745
|
-
*
|
|
40746
|
-
* @category Stream API
|
|
40747
|
-
* @async
|
|
40748
|
-
*/
|
|
40749
|
-
const queryStreams = async (query) => {
|
|
40750
|
-
const client = getActiveClient();
|
|
40751
|
-
client.log('stream/queryStreams', query);
|
|
40752
|
-
const _a = query !== null && query !== void 0 ? query : {}, { page } = _a, params = __rest(_a, ["page"]);
|
|
40753
|
-
const { data } = await client.http.get(`/api/v3/video-streaming`, {
|
|
40754
|
-
params: Object.assign(Object.assign({}, params), { options: {
|
|
40755
|
-
token: toToken(page, 'skiplimit'),
|
|
40756
|
-
} }),
|
|
40757
|
-
});
|
|
40758
|
-
// API-FIX: backend to response Amity.Response: const { paging, videoStreamings } = unwrapPayload(data)
|
|
40759
|
-
// API-FIX: seems returned data has a results identifier on top of data, like no other apis, and this is beautiful
|
|
40760
|
-
const { paging, results: payload } = data;
|
|
40761
|
-
const { videoStreamings } = payload;
|
|
40762
|
-
const cachedAt = client.cache && Date.now();
|
|
40763
|
-
if (client.cache)
|
|
40764
|
-
ingestInCache(payload, { cachedAt });
|
|
40765
|
-
const nextPage = toPage(paging.next);
|
|
40766
|
-
const prevPage = toPage(paging.previous);
|
|
40767
|
-
return { data: videoStreamings, cachedAt, prevPage, nextPage };
|
|
40768
|
-
};
|
|
40769
|
-
/* end_public_function */
|
|
40770
|
-
|
|
40771
39282
|
/**
|
|
40772
39283
|
* ```js
|
|
40773
39284
|
* import { onStreamStarted } from '@amityco/ts-sdk'
|
|
@@ -40789,7 +39300,7 @@ const onStreamStarted = (callback) => {
|
|
|
40789
39300
|
ingestInCache(payload);
|
|
40790
39301
|
callback(payload.videoStreamings[0]);
|
|
40791
39302
|
};
|
|
40792
|
-
return createEventSubscriber(client, 'stream/onStreamStarted', '
|
|
39303
|
+
return createEventSubscriber(client, 'stream/onStreamStarted', 'video-streaming.didStart', filter);
|
|
40793
39304
|
};
|
|
40794
39305
|
|
|
40795
39306
|
/**
|
|
@@ -40813,7 +39324,7 @@ const onStreamStopped = (callback) => {
|
|
|
40813
39324
|
ingestInCache(payload);
|
|
40814
39325
|
callback(payload.videoStreamings[0]);
|
|
40815
39326
|
};
|
|
40816
|
-
return createEventSubscriber(client, 'stream/onStreamStropped', '
|
|
39327
|
+
return createEventSubscriber(client, 'stream/onStreamStropped', 'video-streaming.didStop', filter);
|
|
40817
39328
|
};
|
|
40818
39329
|
|
|
40819
39330
|
/**
|
|
@@ -40837,7 +39348,7 @@ const onStreamRecorded = (callback) => {
|
|
|
40837
39348
|
ingestInCache(payload);
|
|
40838
39349
|
callback(payload.videoStreamings[0]);
|
|
40839
39350
|
};
|
|
40840
|
-
return createEventSubscriber(client, 'stream/onStreamRecorded', '
|
|
39351
|
+
return createEventSubscriber(client, 'stream/onStreamRecorded', 'video-streaming.didRecord', filter);
|
|
40841
39352
|
};
|
|
40842
39353
|
|
|
40843
39354
|
/**
|
|
@@ -40861,7 +39372,7 @@ const onStreamFlagged = (callback) => {
|
|
|
40861
39372
|
ingestInCache(payload);
|
|
40862
39373
|
callback(payload.videoStreamings[0]);
|
|
40863
39374
|
};
|
|
40864
|
-
return createEventSubscriber(client, 'stream/onStreamFlagged', '
|
|
39375
|
+
return createEventSubscriber(client, 'stream/onStreamFlagged', 'video-streaming.didFlag', filter);
|
|
40865
39376
|
};
|
|
40866
39377
|
|
|
40867
39378
|
/**
|
|
@@ -40885,7 +39396,7 @@ const onStreamTerminated = (callback) => {
|
|
|
40885
39396
|
ingestInCache(payload);
|
|
40886
39397
|
callback(payload.videoStreamings[0]);
|
|
40887
39398
|
};
|
|
40888
|
-
return createEventSubscriber(client, 'stream/onStreamTerminated', '
|
|
39399
|
+
return createEventSubscriber(client, 'stream/onStreamTerminated', 'video-streaming.didTerminate', filter);
|
|
40889
39400
|
};
|
|
40890
39401
|
|
|
40891
39402
|
/* eslint-disable no-use-before-define */
|
|
@@ -41094,8 +39605,6 @@ var index$4 = /*#__PURE__*/Object.freeze({
|
|
|
41094
39605
|
updateStream: updateStream,
|
|
41095
39606
|
deleteStream: deleteStream,
|
|
41096
39607
|
disposeStream: disposeStream,
|
|
41097
|
-
queryStreams: queryStreams,
|
|
41098
|
-
getStream: getStream,
|
|
41099
39608
|
onStreamStarted: onStreamStarted,
|
|
41100
39609
|
onStreamStopped: onStreamStopped,
|
|
41101
39610
|
onStreamRecorded: onStreamRecorded,
|
|
@@ -41350,50 +39859,6 @@ const onPollDeleted = (callback) => {
|
|
|
41350
39859
|
return createEventSubscriber(client, 'poll/onPollDeleted', 'poll.deleted', filter);
|
|
41351
39860
|
};
|
|
41352
39861
|
|
|
41353
|
-
/**
|
|
41354
|
-
* ```js
|
|
41355
|
-
* import { observePoll } from '@amityco/ts-sdk'
|
|
41356
|
-
*
|
|
41357
|
-
* let poll = {}
|
|
41358
|
-
* const dispose = observePoll(pollId, updated => poll = updated)
|
|
41359
|
-
* ```
|
|
41360
|
-
*
|
|
41361
|
-
* Observe all mutation on a given {@link Amity.Poll}
|
|
41362
|
-
*
|
|
41363
|
-
* @param pollId the ID of the poll to observe
|
|
41364
|
-
* @param callback the function to call when new data are available
|
|
41365
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the poll
|
|
41366
|
-
*
|
|
41367
|
-
* @category Poll Observer
|
|
41368
|
-
*/
|
|
41369
|
-
const observePoll = (pollId, callback, policy = 'cache_then_server') => {
|
|
41370
|
-
const { log } = getActiveClient();
|
|
41371
|
-
const timestamp = Date.now();
|
|
41372
|
-
log(`observePoll(tmpid: ${timestamp}) > listen`);
|
|
41373
|
-
// wrapper function to make sure
|
|
41374
|
-
const router = (result, action) => {
|
|
41375
|
-
var _a, _b;
|
|
41376
|
-
if (callback instanceof Function)
|
|
41377
|
-
return callback(result);
|
|
41378
|
-
if (action !== 'onFetch')
|
|
41379
|
-
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, result);
|
|
41380
|
-
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, result);
|
|
41381
|
-
};
|
|
41382
|
-
const realtimeRouter = (result, action) => {
|
|
41383
|
-
var _a;
|
|
41384
|
-
if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.pollId) !== pollId)
|
|
41385
|
-
return;
|
|
41386
|
-
router(result, action);
|
|
41387
|
-
};
|
|
41388
|
-
const disposers = [];
|
|
41389
|
-
disposers.push(onPollUpdated(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUpdate')), onPollDeleted(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onDelete')));
|
|
41390
|
-
runQuery(createQuery(getPoll$1, pollId), result => (result.data || result.error) && router(result, 'onFetch'), queryOptions(policy));
|
|
41391
|
-
return () => {
|
|
41392
|
-
log(`observePoll(tmpid: ${timestamp}) > dispose`);
|
|
41393
|
-
disposers.forEach(fn => fn());
|
|
41394
|
-
};
|
|
41395
|
-
};
|
|
41396
|
-
|
|
41397
39862
|
/* begin_public_function
|
|
41398
39863
|
id: poll.get
|
|
41399
39864
|
*/
|
|
@@ -41429,11 +39894,10 @@ var index$3 = /*#__PURE__*/Object.freeze({
|
|
|
41429
39894
|
votePoll: votePoll,
|
|
41430
39895
|
onPollUpdated: onPollUpdated,
|
|
41431
39896
|
onPollDeleted: onPollDeleted,
|
|
41432
|
-
observePoll: observePoll,
|
|
41433
39897
|
getPoll: getPoll
|
|
41434
39898
|
});
|
|
41435
39899
|
|
|
41436
|
-
const privateKey = "-----BEGIN PRIVATE KEY-----\
|
|
39900
|
+
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-----";
|
|
41437
39901
|
/*
|
|
41438
39902
|
* The crypto algorithm used for importing key and signing string
|
|
41439
39903
|
*/
|
|
@@ -41887,7 +40351,7 @@ const createOptimisticTarget = async ({ targetId, targetType, }) => {
|
|
|
41887
40351
|
optimisticTarget = Object.assign(Object.assign({}, optimisticTarget), { targetPublicId: community.data.communityId, targetUpdatedAt: (_a = community.data.updatedAt) !== null && _a !== void 0 ? _a : new Date().toISOString() });
|
|
41888
40352
|
}
|
|
41889
40353
|
if (targetType === 'user') {
|
|
41890
|
-
const user = await getUser$
|
|
40354
|
+
const user = await getUser$1(targetId);
|
|
41891
40355
|
optimisticTarget = Object.assign(Object.assign({}, optimisticTarget), { targetPublicId: user.data.userPublicId, targetUpdatedAt: (_b = user.data.updatedAt) !== null && _b !== void 0 ? _b : new Date().toISOString() });
|
|
41892
40356
|
}
|
|
41893
40357
|
pushToCache(["storyTarget" /* STORY_KEY_CACHE.STORY_TARGET */, 'get', targetId], optimisticTarget);
|
|
@@ -43030,4 +41494,4 @@ const createUserToken = async (apiKey, apiRegion, params) => {
|
|
|
43030
41494
|
return { accessToken: data.accessToken };
|
|
43031
41495
|
};
|
|
43032
41496
|
|
|
43033
|
-
export { API_REGIONS, index as AdRepository, index$8 as CategoryRepository, index$c as ChannelRepository, index$l as Client, index$6 as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$9 as CommunityRepository, ContentFeedType, DefaultCommunityPostSetting, index$7 as FeedRepository, FileAccessTypeEnum, index$i as FileRepository, FileType, index$2 as LiveStreamPlayer, MessageContentType, index$g as MessageRepository, index$3 as PollRepository, PostContentType, index$5 as PostRepository, index$h as ReactionRepository, index$1 as StoryRepository, index$4 as StreamRepository, index$f as SubChannelRepository, SubscriptionLevels, index$j as UserRepository, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };
|
|
41497
|
+
export { API_REGIONS, index as AdRepository, index$8 as CategoryRepository, index$c as ChannelRepository, index$l as Client, index$6 as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$9 as CommunityRepository, ContentFeedType, DefaultCommunityPostSetting, index$7 as FeedRepository, FileAccessTypeEnum, index$i as FileRepository, FileType, index$2 as LiveStreamPlayer, MessageContentType, index$g as MessageRepository, index$3 as PollRepository, PostContentType, index$5 as PostRepository, index$h as ReactionRepository, index$1 as StoryRepository, index$4 as StreamRepository, index$f as SubChannelRepository, SubscriptionLevels, index$j as UserRepository, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };
|