@amityco/ts-sdk 0.0.1-bc64ebf.0 → 0.0.1-bd9dae9.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/.eslintrc.json +1 -0
- package/dist/@types/core/cache.d.ts +3 -0
- package/dist/@types/core/cache.d.ts.map +1 -1
- package/dist/@types/core/errors.d.ts +2 -1
- package/dist/@types/core/errors.d.ts.map +1 -1
- package/dist/@types/core/events.d.ts +3 -0
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/live.d.ts +8 -4
- package/dist/@types/core/live.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +19 -17
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/core/query.d.ts +1 -1
- package/dist/@types/core/query.d.ts.map +1 -1
- package/dist/@types/domains/channel.d.ts +29 -1
- package/dist/@types/domains/channel.d.ts.map +1 -1
- package/dist/@types/domains/client.d.ts +4 -0
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/@types/domains/community.d.ts +24 -2
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/@types/domains/content.d.ts +27 -3
- package/dist/@types/domains/content.d.ts.map +1 -1
- package/dist/@types/domains/file.d.ts +36 -3
- package/dist/@types/domains/file.d.ts.map +1 -1
- package/dist/@types/domains/follow.d.ts +11 -0
- package/dist/@types/domains/follow.d.ts.map +1 -1
- package/dist/@types/domains/group.d.ts +7 -2
- package/dist/@types/domains/group.d.ts.map +1 -1
- package/dist/@types/domains/message.d.ts +25 -5
- package/dist/@types/domains/message.d.ts.map +1 -1
- package/dist/@types/domains/post.d.ts +10 -3
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/@types/domains/user.d.ts +1 -0
- package/dist/@types/domains/user.d.ts.map +1 -1
- package/dist/@types/global.d.ts +1 -0
- package/dist/@types/global.d.ts.map +1 -1
- package/dist/@types/index.d.ts +5 -5
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/cache/api/backupCache.d.ts.map +1 -1
- package/dist/cache/api/ingestInCache.d.ts +1 -1
- package/dist/cache/api/isInTombstone.d.ts +18 -0
- package/dist/cache/api/isInTombstone.d.ts.map +1 -0
- package/dist/cache/api/pushToTombstone.d.ts +17 -0
- package/dist/cache/api/pushToTombstone.d.ts.map +1 -0
- package/dist/cache/api/tests/dropFromCache.test.d.ts +2 -0
- package/dist/cache/api/tests/dropFromCache.test.d.ts.map +1 -0
- package/dist/cache/api/tests/ingestInCache.test.d.ts +2 -0
- package/dist/cache/api/tests/ingestInCache.test.d.ts.map +1 -0
- package/dist/cache/api/tests/pullFromCache.test.d.ts +2 -0
- package/dist/cache/api/tests/pullFromCache.test.d.ts.map +1 -0
- package/dist/cache/api/tests/pushToCache.test.d.ts +2 -0
- package/dist/cache/api/tests/pushToCache.test.d.ts.map +1 -0
- package/dist/cache/api/tests/upsertInCache.test.d.ts +2 -0
- package/dist/cache/api/tests/upsertInCache.test.d.ts.map +1 -0
- package/dist/cache/utils/index.d.ts +17 -0
- package/dist/cache/utils/index.d.ts.map +1 -1
- package/dist/cache/utils/tests/encodeKey.test.d.ts +2 -0
- package/dist/cache/utils/tests/encodeKey.test.d.ts.map +1 -0
- package/dist/cache/utils/tests/partialMatch.test.d.ts +2 -0
- package/dist/cache/utils/tests/partialMatch.test.d.ts.map +1 -0
- package/dist/channel/api/addChannelMembers.d.ts.map +1 -1
- package/dist/channel/api/addChannelMembersRole.d.ts.map +1 -1
- package/dist/channel/api/banChannelMembers.d.ts.map +1 -1
- package/dist/channel/api/createChannel.d.ts.map +1 -1
- package/dist/channel/api/getChannel.d.ts.map +1 -1
- package/dist/channel/api/getChannels.d.ts.map +1 -1
- package/dist/channel/api/index.d.ts +2 -0
- package/dist/channel/api/index.d.ts.map +1 -1
- package/dist/channel/api/joinChannel.d.ts.map +1 -1
- package/dist/channel/api/leaveChannel.d.ts.map +1 -1
- package/dist/channel/api/queryChannelMembers.d.ts +2 -9
- package/dist/channel/api/queryChannelMembers.d.ts.map +1 -1
- package/dist/channel/api/queryChannels.d.ts +2 -11
- package/dist/channel/api/queryChannels.d.ts.map +1 -1
- package/dist/channel/api/removeChannelMembers.d.ts.map +1 -1
- package/dist/channel/api/removeChannelMembersRole.d.ts.map +1 -1
- package/dist/channel/api/startReading.d.ts +17 -0
- package/dist/channel/api/startReading.d.ts.map +1 -0
- package/dist/channel/api/stopReading.d.ts +16 -0
- package/dist/channel/api/stopReading.d.ts.map +1 -0
- package/dist/channel/api/tests/addChannelMembers.test.d.ts +2 -0
- package/dist/channel/api/tests/addChannelMembers.test.d.ts.map +1 -0
- package/dist/channel/api/tests/createChannel.test.d.ts +2 -0
- package/dist/channel/api/tests/createChannel.test.d.ts.map +1 -0
- package/dist/channel/api/tests/getChannel.test.d.ts +2 -0
- package/dist/channel/api/tests/getChannel.test.d.ts.map +1 -0
- package/dist/channel/api/tests/joinChannel.test.d.ts +2 -0
- package/dist/channel/api/tests/joinChannel.test.d.ts.map +1 -0
- package/dist/channel/api/tests/queryChannelMembers.test.d.ts +2 -0
- package/dist/channel/api/tests/queryChannelMembers.test.d.ts.map +1 -0
- package/dist/channel/api/tests/queryChannels.test.d.ts +2 -0
- package/dist/channel/api/tests/queryChannels.test.d.ts.map +1 -0
- package/dist/channel/api/tests/removeChannelMembers.test.d.ts +2 -0
- package/dist/channel/api/tests/removeChannelMembers.test.d.ts.map +1 -0
- package/dist/channel/api/tests/startReading.test.d.ts +2 -0
- package/dist/channel/api/tests/startReading.test.d.ts.map +1 -0
- package/dist/channel/api/tests/stopReading.test.d.ts +2 -0
- package/dist/channel/api/tests/stopReading.test.d.ts.map +1 -0
- package/dist/channel/api/unbanChannelMembers.d.ts.map +1 -1
- package/dist/channel/api/updateChannel.d.ts.map +1 -1
- package/dist/channel/events/index.d.ts +4 -0
- package/dist/channel/events/index.d.ts.map +1 -1
- package/dist/channel/events/onChannelCreated.d.ts.map +1 -1
- package/dist/channel/events/onChannelDeleted.d.ts.map +1 -1
- package/dist/channel/events/onChannelJoined.d.ts.map +1 -1
- package/dist/channel/events/onChannelLeft.d.ts.map +1 -1
- package/dist/channel/events/onChannelMemberAdded.d.ts.map +1 -1
- package/dist/channel/events/onChannelMemberBanned.d.ts +17 -0
- package/dist/channel/events/onChannelMemberBanned.d.ts.map +1 -0
- package/dist/channel/events/onChannelMemberRead.d.ts +17 -0
- package/dist/channel/events/onChannelMemberRead.d.ts.map +1 -0
- package/dist/channel/events/onChannelMemberRemoved.d.ts.map +1 -1
- package/dist/channel/events/onChannelMemberUnbanned.d.ts +17 -0
- package/dist/channel/events/onChannelMemberUnbanned.d.ts.map +1 -0
- package/dist/channel/events/onChannelUpdated.d.ts.map +1 -1
- package/dist/channel/events/tests/onChannelMemberBanned.test.d.ts +2 -0
- package/dist/channel/events/tests/onChannelMemberBanned.test.d.ts.map +1 -0
- package/dist/channel/events/tests/onChannelMemberRead.test.d.ts +2 -0
- package/dist/channel/events/tests/onChannelMemberRead.test.d.ts.map +1 -0
- package/dist/channel/events/tests/onChannelMemberUnbanned.test.d.ts +2 -0
- package/dist/channel/events/tests/onChannelMemberUnbanned.test.d.ts.map +1 -0
- package/dist/channel/observers/index.d.ts +3 -0
- package/dist/channel/observers/index.d.ts.map +1 -1
- package/dist/channel/observers/liveChannelMembers.d.ts +20 -0
- package/dist/channel/observers/liveChannelMembers.d.ts.map +1 -0
- package/dist/channel/observers/liveChannels.d.ts +20 -0
- package/dist/channel/observers/liveChannels.d.ts.map +1 -0
- package/dist/channel/observers/observeChannel.d.ts +1 -1
- package/dist/channel/observers/observeChannel.d.ts.map +1 -1
- package/dist/channel/observers/observeChannels.d.ts +17 -0
- package/dist/channel/observers/observeChannels.d.ts.map +1 -0
- package/dist/channel/observers/tests/liveChannelMembers.test.d.ts +2 -0
- package/dist/channel/observers/tests/liveChannelMembers.test.d.ts.map +1 -0
- package/dist/channel/observers/tests/liveChannels.test.d.ts +2 -0
- package/dist/channel/observers/tests/liveChannels.test.d.ts.map +1 -0
- package/dist/channel/utils/index.d.ts +2 -0
- package/dist/channel/utils/index.d.ts.map +1 -0
- package/dist/channel/utils/prepareChannelPayload.d.ts +3 -0
- package/dist/channel/utils/prepareChannelPayload.d.ts.map +1 -0
- package/dist/channel/utils/tests/prepareChannelPayload.test.d.ts +2 -0
- package/dist/channel/utils/tests/prepareChannelPayload.test.d.ts.map +1 -0
- package/dist/client/api/connectClient.d.ts +0 -1
- package/dist/client/api/connectClient.d.ts.map +1 -1
- package/dist/client/api/createClient.d.ts.map +1 -1
- package/dist/client/api/getFeedSettings.d.ts +16 -0
- package/dist/client/api/getFeedSettings.d.ts.map +1 -0
- package/dist/client/api/getToken.d.ts +1 -3
- package/dist/client/api/getToken.d.ts.map +1 -1
- package/dist/client/api/index.d.ts +1 -0
- package/dist/client/api/index.d.ts.map +1 -1
- package/dist/client/api/tests/activeClient.test.d.ts +2 -0
- package/dist/client/api/tests/activeClient.test.d.ts.map +1 -0
- package/dist/client/api/tests/activeUser.test.d.ts +2 -0
- package/dist/client/api/tests/activeUser.test.d.ts.map +1 -0
- package/dist/community/api/createCommunity.d.ts +1 -1
- package/dist/community/api/createCommunity.d.ts.map +1 -1
- package/dist/community/api/getCommunities.d.ts.map +1 -1
- package/dist/community/api/getCommunity.d.ts.map +1 -1
- package/dist/community/api/getRecommendedCommunities.d.ts.map +1 -1
- package/dist/community/api/getTopTrendingCommunities.d.ts.map +1 -1
- package/dist/community/api/queryCommunities.d.ts.map +1 -1
- package/dist/community/api/queryCommunityMembers.d.ts +6 -1
- package/dist/community/api/queryCommunityMembers.d.ts.map +1 -1
- package/dist/community/api/test/queryCommunityMembers.test.d.ts +2 -0
- package/dist/community/api/test/queryCommunityMembers.test.d.ts.map +1 -0
- package/dist/community/api/updateCommunity.d.ts +1 -1
- package/dist/community/api/updateCommunity.d.ts.map +1 -1
- package/dist/community/events/utils.d.ts.map +1 -1
- package/dist/community/utils/index.d.ts +2 -0
- package/dist/community/utils/index.d.ts.map +1 -0
- package/dist/community/utils/payload.d.ts +11 -0
- package/dist/community/utils/payload.d.ts.map +1 -0
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.d.ts.map +1 -1
- package/dist/core/model/idResolvers.d.ts.map +1 -1
- package/dist/core/query/filtering.d.ts +12 -0
- package/dist/core/query/filtering.d.ts.map +1 -1
- package/dist/core/query/query.d.ts.map +1 -1
- package/dist/core/transports/http.d.ts +5 -0
- package/dist/core/transports/http.d.ts.map +1 -1
- package/dist/core/transports/test/http.test.d.ts +2 -0
- package/dist/core/transports/test/http.test.d.ts.map +1 -0
- package/dist/file/api/createVideo.d.ts +2 -1
- package/dist/file/api/createVideo.d.ts.map +1 -1
- package/dist/follow/api/queryFollowers.d.ts +1 -5
- package/dist/follow/api/queryFollowers.d.ts.map +1 -1
- package/dist/follow/api/queryFollowings.d.ts +1 -5
- package/dist/follow/api/queryFollowings.d.ts.map +1 -1
- package/dist/follow/observers/index.d.ts +2 -0
- package/dist/follow/observers/index.d.ts.map +1 -1
- package/dist/follow/observers/liveFollowers.d.ts +20 -0
- package/dist/follow/observers/liveFollowers.d.ts.map +1 -0
- package/dist/follow/observers/liveFollowings.d.ts +20 -0
- package/dist/follow/observers/liveFollowings.d.ts.map +1 -0
- package/dist/follow/tests/observers/liveFollowers.test.d.ts +2 -0
- package/dist/follow/tests/observers/liveFollowers.test.d.ts.map +1 -0
- package/dist/follow/tests/observers/liveFollowings.test.d.ts +2 -0
- package/dist/follow/tests/observers/liveFollowings.test.d.ts.map +1 -0
- package/dist/group/utils/index.d.ts +2 -0
- package/dist/group/utils/index.d.ts.map +1 -0
- package/dist/group/utils/test/withUsers.test.d.ts +2 -0
- package/dist/group/utils/test/withUsers.test.d.ts.map +1 -0
- package/dist/group/utils/withUser.d.ts +38 -0
- package/dist/group/utils/withUser.d.ts.map +1 -0
- package/dist/index.cjs.js +1972 -581
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +1937 -576
- package/dist/index.umd.js +4 -4
- package/dist/message/api/createMessage.d.ts +4 -1
- package/dist/message/api/createMessage.d.ts.map +1 -1
- package/dist/message/api/deleteMessage.d.ts.map +1 -1
- package/dist/message/api/getMessage.d.ts +1 -1
- package/dist/message/api/getMessage.d.ts.map +1 -1
- package/dist/message/api/getMessages.d.ts.map +1 -1
- package/dist/message/api/queryMessages.d.ts +1 -10
- package/dist/message/api/queryMessages.d.ts.map +1 -1
- package/dist/message/api/tests/createMessage.test.d.ts +2 -0
- package/dist/message/api/tests/createMessage.test.d.ts.map +1 -0
- package/dist/message/api/tests/deleteMessage.test.d.ts +2 -0
- package/dist/message/api/tests/deleteMessage.test.d.ts.map +1 -0
- package/dist/message/api/tests/getMessage.test.d.ts +2 -0
- package/dist/message/api/tests/getMessage.test.d.ts.map +1 -0
- package/dist/message/api/tests/getMessages.test.d.ts +2 -0
- package/dist/message/api/tests/getMessages.test.d.ts.map +1 -0
- package/dist/message/api/tests/queryMessages.test.d.ts +2 -0
- package/dist/message/api/tests/queryMessages.test.d.ts.map +1 -0
- package/dist/message/api/tests/updateMessage.test.d.ts +2 -0
- package/dist/message/api/tests/updateMessage.test.d.ts.map +1 -0
- package/dist/message/api/updateMessage.d.ts.map +1 -1
- package/dist/message/events/index.d.ts +1 -0
- package/dist/message/events/index.d.ts.map +1 -1
- package/dist/message/events/onMessageFetched.d.ts +17 -0
- package/dist/message/events/onMessageFetched.d.ts.map +1 -0
- package/dist/message/observers/index.d.ts +2 -0
- package/dist/message/observers/index.d.ts.map +1 -1
- package/dist/message/observers/liveMessage.d.ts +18 -0
- package/dist/message/observers/liveMessage.d.ts.map +1 -0
- package/dist/message/observers/liveMessages.d.ts +20 -0
- package/dist/message/observers/liveMessages.d.ts.map +1 -0
- package/dist/message/observers/observeMessage.d.ts.map +1 -1
- package/dist/message/observers/observeMessages.d.ts +0 -1
- package/dist/message/observers/observeMessages.d.ts.map +1 -1
- package/dist/message/tests/observers/liveMessage.test.d.ts +2 -0
- package/dist/message/tests/observers/liveMessage.test.d.ts.map +1 -0
- package/dist/message/tests/observers/liveMessages.test.d.ts +2 -0
- package/dist/message/tests/observers/liveMessages.test.d.ts.map +1 -0
- package/dist/post/api/deletePost.d.ts.map +1 -1
- package/dist/post/api/getPost.d.ts.map +1 -1
- package/dist/post/api/queryPosts.d.ts.map +1 -1
- package/dist/post/api/tests/queryPosts.test.d.ts +2 -0
- package/dist/post/api/tests/queryPosts.test.d.ts.map +1 -0
- package/dist/post/api/updatePost.d.ts +6 -1
- package/dist/post/api/updatePost.d.ts.map +1 -1
- package/dist/post/observers/livePosts.d.ts.map +1 -1
- package/dist/reaction/api/addReaction.d.ts.map +1 -1
- package/dist/reaction/api/removeReaction.d.ts.map +1 -1
- package/dist/reaction/api/tests/addReaction.test.d.ts +2 -0
- package/dist/reaction/api/tests/addReaction.test.d.ts.map +1 -0
- package/dist/reaction/api/tests/removeReaction.test.d.ts +2 -0
- package/dist/reaction/api/tests/removeReaction.test.d.ts.map +1 -0
- package/dist/user/api/getUser.d.ts +1 -1
- package/dist/user/api/getUser.d.ts.map +1 -1
- package/dist/user/api/getUsers.d.ts.map +1 -1
- package/dist/user/api/queryUsers.d.ts.map +1 -1
- package/dist/user/api/tests/queryUsers.test.d.ts +2 -0
- package/dist/user/api/tests/queryUsers.test.d.ts.map +1 -0
- package/dist/user/api/updateUser.d.ts.map +1 -1
- package/dist/user/events/index.d.ts +1 -0
- package/dist/user/events/index.d.ts.map +1 -1
- package/dist/user/events/onUserFetched.d.ts +17 -0
- package/dist/user/events/onUserFetched.d.ts.map +1 -0
- package/dist/user/observers/index.d.ts +1 -0
- package/dist/user/observers/index.d.ts.map +1 -1
- package/dist/user/observers/liveUser.d.ts +18 -0
- package/dist/user/observers/liveUser.d.ts.map +1 -0
- package/dist/user/observers/observeUser.d.ts.map +1 -1
- package/dist/user/tests/api/getUser.test.d.ts +2 -0
- package/dist/user/tests/api/getUser.test.d.ts.map +1 -0
- package/dist/user/tests/observers/liveUser.test.d.ts +2 -0
- package/dist/user/tests/observers/liveUser.test.d.ts.map +1 -0
- package/dist/utils/constants.d.ts +4 -0
- package/dist/utils/constants.d.ts.map +1 -1
- package/dist/utils/tests/client.d.ts +5 -2
- package/dist/utils/tests/client.d.ts.map +1 -1
- package/dist/utils/tests/dummy/channel.d.ts +128 -0
- package/dist/utils/tests/dummy/channel.d.ts.map +1 -0
- package/dist/utils/tests/dummy/community.d.ts +34 -0
- package/dist/utils/tests/dummy/community.d.ts.map +1 -0
- package/dist/utils/tests/dummy/file.d.ts +2 -0
- package/dist/utils/tests/dummy/file.d.ts.map +1 -0
- package/dist/utils/tests/dummy/follow.d.ts +13 -0
- package/dist/utils/tests/dummy/follow.d.ts.map +1 -0
- package/dist/utils/tests/dummy/index.d.ts +18 -0
- package/dist/utils/tests/dummy/index.d.ts.map +1 -0
- package/dist/utils/tests/dummy/member.d.ts +2 -0
- package/dist/utils/tests/dummy/member.d.ts.map +1 -0
- package/dist/utils/tests/dummy/message.d.ts +24 -0
- package/dist/utils/tests/dummy/message.d.ts.map +1 -0
- package/dist/utils/tests/dummy/poll.d.ts +3 -0
- package/dist/utils/tests/dummy/poll.d.ts.map +1 -0
- package/dist/utils/tests/dummy/post.d.ts +23 -0
- package/dist/utils/tests/dummy/post.d.ts.map +1 -0
- package/dist/utils/tests/dummy/reaction.d.ts +4 -0
- package/dist/utils/tests/dummy/reaction.d.ts.map +1 -0
- package/dist/utils/tests/dummy/role.d.ts +4 -0
- package/dist/utils/tests/dummy/role.d.ts.map +1 -0
- package/dist/utils/tests/dummy/user.d.ts +17 -0
- package/dist/utils/tests/dummy/user.d.ts.map +1 -0
- package/dist/utils/tests/index.d.ts +3 -2
- package/dist/utils/tests/index.d.ts.map +1 -1
- package/dist/utils/tests/utils.d.ts +3 -0
- package/dist/utils/tests/utils.d.ts.map +1 -0
- package/package.json +3 -2
- package/src/@types/core/cache.ts +4 -0
- package/src/@types/core/errors.ts +1 -0
- package/src/@types/core/events.ts +3 -0
- package/src/@types/core/live.ts +10 -4
- package/src/@types/core/payload.ts +23 -17
- package/src/@types/core/query.ts +1 -1
- package/src/@types/domains/channel.ts +61 -1
- package/src/@types/domains/client.ts +6 -0
- package/src/@types/domains/community.ts +27 -2
- package/src/@types/domains/content.ts +35 -3
- package/src/@types/domains/file.ts +42 -3
- package/src/@types/domains/follow.ts +28 -0
- package/src/@types/domains/group.ts +7 -2
- package/src/@types/domains/message.ts +32 -9
- package/src/@types/domains/post.ts +10 -3
- package/src/@types/domains/user.ts +8 -0
- package/src/@types/global.ts +2 -0
- package/src/@types/index.ts +6 -5
- package/src/cache/api/backupCache.ts +0 -1
- package/src/cache/api/index.ts +2 -1
- package/src/cache/api/ingestInCache.ts +2 -2
- package/src/cache/api/isInTombstone.ts +41 -0
- package/src/cache/api/pushToTombstone.ts +33 -0
- package/src/cache/api/tests/dropFromCache.test.ts +59 -0
- package/src/cache/api/tests/ingestInCache.test.ts +87 -0
- package/src/cache/api/tests/pullFromCache.test.ts +42 -0
- package/src/cache/api/tests/pushToCache.test.ts +57 -0
- package/src/cache/api/tests/upsertInCache.test.ts +60 -0
- package/src/cache/utils/index.ts +22 -0
- package/src/cache/utils/tests/encodeKey.test.ts +19 -0
- package/src/cache/utils/tests/partialMatch.test.ts +13 -0
- package/src/channel/api/addChannelMembers.ts +14 -5
- package/src/channel/api/addChannelMembersRole.ts +5 -1
- package/src/channel/api/banChannelMembers.ts +9 -3
- package/src/channel/api/createChannel.ts +6 -2
- package/src/channel/api/getChannel.ts +23 -4
- package/src/channel/api/getChannels.ts +5 -1
- package/src/channel/api/index.ts +3 -0
- package/src/channel/api/joinChannel.ts +5 -1
- package/src/channel/api/leaveChannel.ts +5 -1
- package/src/channel/api/queryChannelMembers.ts +77 -25
- package/src/channel/api/queryChannels.ts +43 -18
- package/src/channel/api/removeChannelMembers.ts +14 -5
- package/src/channel/api/removeChannelMembersRole.ts +5 -1
- package/src/channel/api/startReading.ts +46 -0
- package/src/channel/api/stopReading.ts +27 -0
- package/src/channel/api/tests/addChannelMembers.test.ts +123 -0
- package/src/channel/api/tests/createChannel.test.ts +52 -0
- package/src/channel/api/tests/getChannel.test.ts +108 -0
- package/src/channel/api/tests/joinChannel.test.ts +52 -0
- package/src/channel/api/tests/queryChannelMembers.test.ts +131 -0
- package/src/channel/api/tests/queryChannels.test.ts +121 -0
- package/src/channel/api/tests/removeChannelMembers.test.ts +95 -0
- package/src/channel/api/tests/startReading.test.ts +24 -0
- package/src/channel/api/tests/stopReading.test.ts +24 -0
- package/src/channel/api/unbanChannelMembers.ts +10 -3
- package/src/channel/api/updateChannel.ts +5 -1
- package/src/channel/events/index.ts +8 -0
- package/src/channel/events/onChannelCreated.ts +6 -2
- package/src/channel/events/onChannelDeleted.ts +6 -2
- package/src/channel/events/onChannelJoined.ts +6 -2
- package/src/channel/events/onChannelLeft.ts +6 -2
- package/src/channel/events/onChannelMemberAdded.ts +10 -4
- package/src/channel/events/onChannelMemberBanned.ts +39 -0
- package/src/channel/events/onChannelMemberRead.ts +38 -0
- package/src/channel/events/onChannelMemberRemoved.ts +9 -2
- package/src/channel/events/onChannelMemberUnbanned.ts +39 -0
- package/src/channel/events/onChannelUpdated.ts +6 -2
- package/src/channel/events/tests/onChannelMemberBanned.test.ts +60 -0
- package/src/channel/events/tests/onChannelMemberRead.test.ts +56 -0
- package/src/channel/events/tests/onChannelMemberUnbanned.test.ts +60 -0
- package/src/channel/observers/index.ts +3 -0
- package/src/channel/observers/liveChannelMembers.ts +185 -0
- package/src/channel/observers/liveChannels.ts +191 -0
- package/src/channel/observers/observeChannel.ts +3 -11
- package/src/channel/observers/observeChannels.ts +61 -0
- package/src/channel/observers/tests/liveChannelMembers.test.ts +232 -0
- package/src/channel/observers/tests/liveChannels.test.ts +219 -0
- package/src/channel/utils/index.ts +1 -0
- package/src/channel/utils/prepareChannelPayload.ts +31 -0
- package/src/channel/utils/tests/prepareChannelPayload.test.ts +120 -0
- package/src/client/api/connectClient.ts +0 -1
- package/src/client/api/createClient.ts +3 -0
- package/src/client/api/getFeedSettings.ts +29 -0
- package/src/client/api/index.ts +2 -0
- package/src/client/api/isConnected.ts +1 -1
- package/src/client/api/tests/activeClient.test.ts +20 -0
- package/src/client/api/tests/activeUser.test.ts +20 -0
- package/src/community/api/createCommunity.ts +9 -3
- package/src/community/api/getCommunities.ts +10 -3
- package/src/community/api/getCommunity.ts +5 -1
- package/src/community/api/getRecommendedCommunities.ts +5 -2
- package/src/community/api/getTopTrendingCommunities.ts +4 -1
- package/src/community/api/queryCommunities.ts +5 -2
- package/src/community/api/queryCommunityMembers.ts +59 -14
- package/src/community/api/test/queryCommunityMembers.test.ts +122 -0
- package/src/community/api/updateCommunity.ts +7 -3
- package/src/community/events/utils.ts +23 -9
- package/src/community/utils/index.ts +1 -0
- package/src/community/utils/payload.ts +44 -0
- package/src/core/events.ts +5 -2
- package/src/core/model/idResolvers.ts +1 -1
- package/src/core/model/identifyModel.ts +1 -1
- package/src/core/query/filtering.ts +55 -0
- package/src/core/query/query.ts +11 -9
- package/src/core/tests/query/query/runQuery.test.ts +2 -3
- package/src/core/tests/query/query.test.ts +103 -11
- package/src/core/transports/http.ts +3 -17
- package/src/core/transports/test/http.test.ts +83 -0
- package/src/file/api/createVideo.ts +6 -0
- package/src/follow/api/queryFollowers.ts +3 -5
- package/src/follow/api/queryFollowings.ts +3 -5
- package/src/follow/api/utils.ts +7 -3
- package/src/follow/observers/index.ts +3 -0
- package/src/follow/observers/liveFollowers.ts +149 -0
- package/src/follow/observers/liveFollowings.ts +149 -0
- package/src/follow/tests/observers/liveFollowers.test.ts +240 -0
- package/src/follow/tests/observers/liveFollowings.test.ts +239 -0
- package/src/group/utils/index.ts +1 -0
- package/src/group/utils/test/withUsers.test.ts +103 -0
- package/src/group/utils/withUser.ts +92 -0
- package/src/index.ts +1 -1
- package/src/message/api/createMessage.ts +15 -9
- package/src/message/api/deleteMessage.ts +4 -4
- package/src/message/api/getMessage.ts +32 -4
- package/src/message/api/getMessages.ts +6 -1
- package/src/message/api/queryMessages.ts +6 -10
- package/src/message/api/tests/createMessage.test.ts +99 -0
- package/src/message/api/tests/deleteMessage.test.ts +110 -0
- package/src/message/api/tests/getMessage.test.ts +121 -0
- package/src/message/api/tests/getMessages.test.ts +108 -0
- package/src/message/api/tests/queryMessages.test.ts +115 -0
- package/src/message/api/tests/updateMessage.test.ts +100 -0
- package/src/message/api/updateMessage.ts +2 -0
- package/src/message/events/index.ts +1 -0
- package/src/message/events/onMessageFetched.ts +30 -0
- package/src/message/observers/index.ts +2 -0
- package/src/message/observers/liveMessage.ts +100 -0
- package/src/message/observers/liveMessages.ts +143 -0
- package/src/message/observers/observeMessage.ts +4 -0
- package/src/message/observers/observeMessages.ts +0 -1
- package/src/message/tests/observers/liveMessage.test.ts +248 -0
- package/src/message/tests/observers/liveMessages.test.ts +339 -0
- package/src/post/api/deletePost.ts +4 -3
- package/src/post/api/getPost.ts +8 -4
- package/src/post/api/queryPosts.ts +9 -0
- package/src/post/api/tests/queryPosts.test.ts +149 -0
- package/src/post/api/updatePost.ts +6 -1
- package/src/post/observers/livePosts.ts +2 -1
- package/src/post/tests/api/getPost.test.ts +3 -3
- package/src/post/tests/api/queryPosts.test.ts +117 -18
- package/src/reaction/api/addReaction.ts +17 -6
- package/src/reaction/api/removeReaction.ts +17 -6
- package/src/reaction/api/tests/addReaction.test.ts +73 -0
- package/src/reaction/api/tests/removeReaction.test.ts +79 -0
- package/src/user/api/getUser.ts +32 -5
- package/src/user/api/getUsers.ts +3 -0
- package/src/user/api/queryUsers.ts +27 -5
- package/src/user/api/tests/queryUsers.test.ts +124 -0
- package/src/user/api/updateUser.ts +3 -0
- package/src/user/events/index.ts +1 -0
- package/src/user/events/onUserFetched.ts +19 -0
- package/src/user/observers/index.ts +1 -0
- package/src/user/observers/liveUser.ts +89 -0
- package/src/user/observers/observeUser.ts +2 -0
- package/src/user/tests/api/getUser.test.ts +112 -0
- package/src/user/tests/observers/liveUser.test.ts +224 -0
- package/src/utils/constants.ts +6 -0
- package/src/utils/tests/client.ts +31 -3
- package/src/utils/tests/dummy/channel.ts +200 -0
- package/src/utils/tests/dummy/community.ts +92 -0
- package/src/utils/tests/dummy/file.ts +20 -0
- package/src/utils/tests/dummy/follow.ts +66 -0
- package/src/utils/tests/dummy/index.ts +19 -0
- package/src/utils/tests/dummy/member.ts +18 -0
- package/src/utils/tests/dummy/message.ts +42 -0
- package/src/utils/tests/dummy/poll.ts +43 -0
- package/src/utils/tests/dummy/post.ts +92 -0
- package/src/utils/tests/dummy/reaction.ts +22 -0
- package/src/utils/tests/dummy/role.ts +21 -0
- package/src/utils/tests/dummy/user.ts +44 -0
- package/src/utils/tests/index.ts +3 -2
- package/src/utils/tests/utils.ts +13 -0
- package/dist/utils/tests/dummy.d.ts +0 -8
- package/dist/utils/tests/dummy.d.ts.map +0 -1
- package/src/utils/tests/dummy.ts +0 -7
package/dist/index.cjs.js
CHANGED
|
@@ -3,24 +3,98 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var jsBase64 = require('js-base64');
|
|
6
|
-
var mitt = require('mitt');
|
|
7
6
|
var AsyncStorage = require('@react-native-async-storage/async-storage');
|
|
7
|
+
var mitt = require('mitt');
|
|
8
8
|
var debug = require('debug');
|
|
9
9
|
var axios = require('axios');
|
|
10
|
+
var qs = require('qs');
|
|
10
11
|
var HttpAgent = require('agentkeepalive');
|
|
11
12
|
var io = require('socket.io-client');
|
|
12
13
|
var nativeIdGenerator = require('react-native-uuid');
|
|
13
14
|
|
|
14
15
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
15
16
|
|
|
16
|
-
var mitt__default = /*#__PURE__*/_interopDefaultLegacy(mitt);
|
|
17
17
|
var AsyncStorage__default = /*#__PURE__*/_interopDefaultLegacy(AsyncStorage);
|
|
18
|
+
var mitt__default = /*#__PURE__*/_interopDefaultLegacy(mitt);
|
|
18
19
|
var debug__default = /*#__PURE__*/_interopDefaultLegacy(debug);
|
|
19
20
|
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
21
|
+
var qs__default = /*#__PURE__*/_interopDefaultLegacy(qs);
|
|
20
22
|
var HttpAgent__default = /*#__PURE__*/_interopDefaultLegacy(HttpAgent);
|
|
21
23
|
var io__default = /*#__PURE__*/_interopDefaultLegacy(io);
|
|
22
24
|
var nativeIdGenerator__default = /*#__PURE__*/_interopDefaultLegacy(nativeIdGenerator);
|
|
23
25
|
|
|
26
|
+
const CommunityPostSettings = Object.freeze({
|
|
27
|
+
ONLY_ADMIN_CAN_POST: 'ONLY_ADMIN_CAN_POST',
|
|
28
|
+
ADMIN_REVIEW_POST_REQUIRED: 'ADMIN_REVIEW_POST_REQUIRED',
|
|
29
|
+
ANYONE_CAN_POST: 'ANYONE_CAN_POST',
|
|
30
|
+
});
|
|
31
|
+
const CommunityPostSettingMaps = Object.freeze({
|
|
32
|
+
ONLY_ADMIN_CAN_POST: {
|
|
33
|
+
needApprovalOnPostCreation: false,
|
|
34
|
+
onlyAdminCanPost: true,
|
|
35
|
+
},
|
|
36
|
+
ADMIN_REVIEW_POST_REQUIRED: {
|
|
37
|
+
needApprovalOnPostCreation: true,
|
|
38
|
+
onlyAdminCanPost: false,
|
|
39
|
+
},
|
|
40
|
+
ANYONE_CAN_POST: {
|
|
41
|
+
needApprovalOnPostCreation: false,
|
|
42
|
+
onlyAdminCanPost: false,
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
const DefaultCommunityPostSetting = 'ONLY_ADMIN_CAN_POST';
|
|
46
|
+
|
|
47
|
+
const ContentFeedType = Object.freeze({
|
|
48
|
+
STORY: 'story',
|
|
49
|
+
CLIP: 'clip',
|
|
50
|
+
CHAT: 'chat',
|
|
51
|
+
POST: 'post',
|
|
52
|
+
MESSAGE: 'message',
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const FileType = Object.freeze({
|
|
56
|
+
FILE: 'file',
|
|
57
|
+
IMAGE: 'image',
|
|
58
|
+
VIDEO: 'video',
|
|
59
|
+
});
|
|
60
|
+
const VideoResolution = Object.freeze({
|
|
61
|
+
'1080P': '1080p',
|
|
62
|
+
'720P': '720p',
|
|
63
|
+
'480P': '480p',
|
|
64
|
+
'360P': '360p',
|
|
65
|
+
ORIGINAL: 'original',
|
|
66
|
+
});
|
|
67
|
+
const VideoTranscodingStatus = Object.freeze({
|
|
68
|
+
UPLOADED: 'uploaded',
|
|
69
|
+
TRANSCODING: 'transcoding',
|
|
70
|
+
TRANSCODED: 'transcoded',
|
|
71
|
+
TRANSCODE_FAILED: 'transcodeFailed',
|
|
72
|
+
});
|
|
73
|
+
const VideoSize = Object.freeze({
|
|
74
|
+
LOW: 'low',
|
|
75
|
+
MEDIUM: 'medium',
|
|
76
|
+
HIGH: 'high',
|
|
77
|
+
ORIGINAL: 'original',
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const MessageContentType = Object.freeze({
|
|
81
|
+
TEXT: 'text',
|
|
82
|
+
IMAGE: 'image',
|
|
83
|
+
FILE: 'file',
|
|
84
|
+
VIDEO: 'video',
|
|
85
|
+
AUDIO: 'audio',
|
|
86
|
+
CUSTOM: 'custom',
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const PostContentType = Object.freeze({
|
|
90
|
+
TEXT: 'text',
|
|
91
|
+
IMAGE: 'image',
|
|
92
|
+
FILE: 'file',
|
|
93
|
+
VIDEO: 'video',
|
|
94
|
+
LIVESTREAM: 'liveStream',
|
|
95
|
+
POLL: 'poll',
|
|
96
|
+
});
|
|
97
|
+
|
|
24
98
|
var _a$1;
|
|
25
99
|
/* eslint-disable no-undef */
|
|
26
100
|
const theGlobal =
|
|
@@ -225,7 +299,7 @@ const CRITERIAS = {
|
|
|
225
299
|
channel: ['channelId', 'rateLimit'],
|
|
226
300
|
channelUsers: ['channelId', 'userId', 'membership'],
|
|
227
301
|
message: ['messageId'],
|
|
228
|
-
community: ['communityId', '
|
|
302
|
+
community: ['communityId', 'postSetting'],
|
|
229
303
|
category: ['categoryId'],
|
|
230
304
|
communityUsers: ['userId', 'communityId', 'communityMembership'],
|
|
231
305
|
post: ['postId', 'feedId'],
|
|
@@ -296,6 +370,78 @@ const PAYLOAD2MODEL = {
|
|
|
296
370
|
followCounts: 'followCount',
|
|
297
371
|
};
|
|
298
372
|
|
|
373
|
+
// cache constants
|
|
374
|
+
const CACHE_KEY_GET = 'get';
|
|
375
|
+
const CACHE_KEY_TOMBSTONE = 'dead';
|
|
376
|
+
const CACHE_LIFESPAN = 1 * 60 * 1000; // 1 minute
|
|
377
|
+
const CACHE_LIFESPAN_TOMBSTONE = 3 * 60 * 1000; // 3 minutes
|
|
378
|
+
/**
|
|
379
|
+
* Shallow-clones an object and sort its keys
|
|
380
|
+
*
|
|
381
|
+
* @param source a plain object to clone
|
|
382
|
+
* @returns a clone of source, with keys sorted with default javascript sorting
|
|
383
|
+
*
|
|
384
|
+
* @category Cache
|
|
385
|
+
* @hidden
|
|
386
|
+
*/
|
|
387
|
+
const normalize = (source) => Object.keys(source)
|
|
388
|
+
.sort()
|
|
389
|
+
.reduce((acc, key) => (Object.assign(Object.assign({}, acc), { [key]: source[key] })), {});
|
|
390
|
+
/**
|
|
391
|
+
* Encodes a given {@link Amity.CacheKey} to a plain string
|
|
392
|
+
*
|
|
393
|
+
* @param key the key to encode
|
|
394
|
+
* @returns an encoded string
|
|
395
|
+
*
|
|
396
|
+
* @category Cache
|
|
397
|
+
* @hidden
|
|
398
|
+
*/
|
|
399
|
+
const encodeKey = (key) => JSON.stringify(key, (_, val) => (typeof val === 'object' ? normalize(val) : val));
|
|
400
|
+
/**
|
|
401
|
+
* Decodes a string back into a {@link Amity.CacheKey}
|
|
402
|
+
|
|
403
|
+
*
|
|
404
|
+
* @param key the string key to decode
|
|
405
|
+
* @returns a plain Amity.CacheKey object.
|
|
406
|
+
*
|
|
407
|
+
* @category Cache
|
|
408
|
+
* @hidden
|
|
409
|
+
*/
|
|
410
|
+
const decodeKey = (key) => JSON.parse(key);
|
|
411
|
+
/**
|
|
412
|
+
* Performs a recursive partial deep equal check on two objects.
|
|
413
|
+
*
|
|
414
|
+
* @param predicate the reference object containing the partial information
|
|
415
|
+
* @param candidate the object to check against
|
|
416
|
+
* @returns true if the candidate contains all the values of the predicate
|
|
417
|
+
*
|
|
418
|
+
* @category Cache
|
|
419
|
+
*/
|
|
420
|
+
const partialMatch = (predicate, candidate) => {
|
|
421
|
+
if (predicate === candidate)
|
|
422
|
+
return true;
|
|
423
|
+
// if one or the other is nullish, there can't be equality
|
|
424
|
+
if (!predicate || !candidate)
|
|
425
|
+
return false;
|
|
426
|
+
// we only perform recursive check on objects
|
|
427
|
+
if (typeof predicate !== 'object') {
|
|
428
|
+
return false;
|
|
429
|
+
}
|
|
430
|
+
// recursively call for partial match based on the predicate
|
|
431
|
+
return Object.keys(predicate).every(key => partialMatch(predicate[key], candidate[key]));
|
|
432
|
+
};
|
|
433
|
+
/**
|
|
434
|
+
* checks if passed error code is included in
|
|
435
|
+
* Tombstone errors list
|
|
436
|
+
*
|
|
437
|
+
* @param errorCode as {@link Amity.ServerError}
|
|
438
|
+
* @returns success boolean if the given errorCode
|
|
439
|
+
* is included in Tombstone errors list
|
|
440
|
+
*
|
|
441
|
+
* @category Cache
|
|
442
|
+
*/
|
|
443
|
+
const checkIfShouldGoesToTombstone = (errorCode) => [400400 /* Amity.ServerError.ITEM_NOT_FOUND */, 400300 /* Amity.ServerError.FORBIDDEN */].includes(errorCode);
|
|
444
|
+
|
|
299
445
|
/* eslint-disable no-use-before-define */
|
|
300
446
|
/**
|
|
301
447
|
* Type guard to check and cast that a given async function is has the ".locally" property
|
|
@@ -354,7 +500,7 @@ const isLocal = (model) => {
|
|
|
354
500
|
*
|
|
355
501
|
* @hidden
|
|
356
502
|
*/
|
|
357
|
-
const isFresh = (model, lifeSpan =
|
|
503
|
+
const isFresh = (model, lifeSpan = CACHE_LIFESPAN) => {
|
|
358
504
|
var _a;
|
|
359
505
|
return Date.now() - ((_a = model === null || model === void 0 ? void 0 : model.cachedAt) !== null && _a !== void 0 ? _a : 0) <= lifeSpan;
|
|
360
506
|
};
|
|
@@ -388,12 +534,10 @@ const createQuery = (func, ...args) => ({ func, args });
|
|
|
388
534
|
*
|
|
389
535
|
* @category Query
|
|
390
536
|
*/
|
|
391
|
-
const queryOptions = (policy, lifeSpan =
|
|
537
|
+
const queryOptions = (policy, lifeSpan = CACHE_LIFESPAN) => {
|
|
392
538
|
if (policy === 'cache_only')
|
|
393
539
|
return { lifeSpan: Infinity };
|
|
394
|
-
|
|
395
|
-
return { lifeSpan: 0 };
|
|
396
|
-
return { lifeSpan };
|
|
540
|
+
return { lifeSpan: lifeSpan < CACHE_LIFESPAN ? CACHE_LIFESPAN : lifeSpan };
|
|
397
541
|
};
|
|
398
542
|
/**
|
|
399
543
|
* ```js
|
|
@@ -414,8 +558,9 @@ const queryOptions = (policy, lifeSpan = 2 * 60 * 1000) => {
|
|
|
414
558
|
*/
|
|
415
559
|
const runQuery = ({ func, args }, callback, options = queryOptions('cache_then_server')) => {
|
|
416
560
|
let local;
|
|
561
|
+
const { lifeSpan } = queryOptions('cache_then_server', options.lifeSpan);
|
|
417
562
|
// offline first
|
|
418
|
-
if (isOffline(func)
|
|
563
|
+
if (isOffline(func)) {
|
|
419
564
|
try {
|
|
420
565
|
local = isMutator(func) ? func.optimistically(...args) : func.locally(...args);
|
|
421
566
|
}
|
|
@@ -426,7 +571,7 @@ const runQuery = ({ func, args }, callback, options = queryOptions('cache_then_s
|
|
|
426
571
|
error,
|
|
427
572
|
}));
|
|
428
573
|
}
|
|
429
|
-
const shouldAbort = isCachable(local) && isFresh(local,
|
|
574
|
+
const shouldAbort = isCachable(local) && isFresh(local, lifeSpan);
|
|
430
575
|
callback === null || callback === void 0 ? void 0 : callback(createSnapshot(local, {
|
|
431
576
|
origin: 'local',
|
|
432
577
|
loading: !(isFetcher(func) && shouldAbort),
|
|
@@ -493,53 +638,6 @@ function createSnapshot(data, options) {
|
|
|
493
638
|
return Object.assign(Object.assign({}, options), { data });
|
|
494
639
|
}
|
|
495
640
|
|
|
496
|
-
// Note:
|
|
497
|
-
// this file should contain a suite of filtering utilities to help the
|
|
498
|
-
// local version of the query functions.
|
|
499
|
-
/**
|
|
500
|
-
* Filter a given collection with strict equality against a param
|
|
501
|
-
*
|
|
502
|
-
* @param collection the collection to filter
|
|
503
|
-
* @param key the key of the collection's items to challenge
|
|
504
|
-
* @param value the expected value
|
|
505
|
-
* @returns a filtered collection with items only matching the criteria
|
|
506
|
-
*
|
|
507
|
-
* @hidden
|
|
508
|
-
*/
|
|
509
|
-
const filterByPropEquality = (collection, key, value) => (value !== undefined ? collection.filter(item => item[key] === value) : collection);
|
|
510
|
-
|
|
511
|
-
// Note:
|
|
512
|
-
// this file should contain a suite of sorting utilities to help the
|
|
513
|
-
// local version of the query functions.
|
|
514
|
-
/**
|
|
515
|
-
* Alphabetic sorting of objects having a displayName
|
|
516
|
-
*/
|
|
517
|
-
const sortByDisplayName = ({ displayName: a }, { displayName: b }) => {
|
|
518
|
-
if (a === b)
|
|
519
|
-
return 0;
|
|
520
|
-
return a < b ? -1 : 1;
|
|
521
|
-
};
|
|
522
|
-
/**
|
|
523
|
-
* Sorting a collection by their apparition order (oldest first)
|
|
524
|
-
*/
|
|
525
|
-
const sortByChannelSegment = ({ channelSegment: a }, { channelSegment: b }) => a - b;
|
|
526
|
-
/**
|
|
527
|
-
* Sorting a collection by their apparition order (oldest first)
|
|
528
|
-
*/
|
|
529
|
-
const sortBySegmentNumber = ({ segmentNumber: a }, { segmentNumber: b }) => a - b;
|
|
530
|
-
/**
|
|
531
|
-
* Sorting a collection by its oldest items
|
|
532
|
-
*/
|
|
533
|
-
const sortByFirstCreated = ({ createdAt: a }, { createdAt: b }) => new Date(a).valueOf() - new Date(b).valueOf();
|
|
534
|
-
/**
|
|
535
|
-
* Sorting a collection by its newest items
|
|
536
|
-
*/
|
|
537
|
-
const sortByLastCreated = ({ createdAt: a }, { createdAt: b }) => new Date(b).valueOf() - new Date(a).valueOf();
|
|
538
|
-
/**
|
|
539
|
-
* Sorting a collection by the items with most recent activity
|
|
540
|
-
*/
|
|
541
|
-
const sortByLastActivity = ({ lastActivity: a }, { lastActivity: b }) => new Date(b).valueOf() - new Date(a).valueOf();
|
|
542
|
-
|
|
543
641
|
/* eslint-disable max-classes-per-file */
|
|
544
642
|
/**
|
|
545
643
|
* Generic ASC error
|
|
@@ -629,256 +727,62 @@ const setActiveClient = (client) => {
|
|
|
629
727
|
activeClient = client;
|
|
630
728
|
};
|
|
631
729
|
|
|
632
|
-
/* eslint-disable @typescript-eslint/ban-types */
|
|
633
|
-
let tasks = [];
|
|
634
|
-
let timer;
|
|
635
730
|
/**
|
|
636
|
-
*
|
|
731
|
+
* ```js
|
|
732
|
+
* import { enableCache } from '@amityco/ts-sdk'
|
|
733
|
+
* enableCache()
|
|
734
|
+
* ```
|
|
637
735
|
*
|
|
638
|
-
*
|
|
736
|
+
* Adds a new {@link Amity.Cache} object to
|
|
737
|
+
* an {@link Amity.Client} instance
|
|
738
|
+
*
|
|
739
|
+
* @param prevState a previous state of cache instance (useful for SSR)
|
|
740
|
+
* @param persistIf a function to determine if an entry inserted in cache
|
|
741
|
+
* is destined to be also saved in the persistent storage when
|
|
742
|
+
* calling {@link backupCache}
|
|
743
|
+
*
|
|
744
|
+
* @category Cache API
|
|
639
745
|
*/
|
|
640
|
-
const
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
}, 0);
|
|
746
|
+
const enableCache = (prevState = {}, persistIf) => {
|
|
747
|
+
const client = getActiveClient();
|
|
748
|
+
if (client.cache)
|
|
749
|
+
return;
|
|
750
|
+
client.log('cache/api/enableCache');
|
|
751
|
+
client.cache = { data: prevState, persistIf };
|
|
647
752
|
};
|
|
648
753
|
|
|
649
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
650
|
-
// need to sync up the list
|
|
651
|
-
const WS_EVENTS = [
|
|
652
|
-
'disconnected',
|
|
653
|
-
'error',
|
|
654
|
-
'connect_error',
|
|
655
|
-
'reconnect_error',
|
|
656
|
-
'reconnect_failed',
|
|
657
|
-
'v3.channel.didUpdate',
|
|
658
|
-
'v3.channel.didUpdate',
|
|
659
|
-
'v3.channel.didJoin',
|
|
660
|
-
'v3.channel.didLeave',
|
|
661
|
-
'v3.channel.didAddUsers',
|
|
662
|
-
'v3.channel.didRemoveUsers',
|
|
663
|
-
'v3.channel.didBan',
|
|
664
|
-
'v3.channel.didUnban',
|
|
665
|
-
'v3.message.didCreate',
|
|
666
|
-
'v3.message.didUpdate',
|
|
667
|
-
'v3.message.didDelete',
|
|
668
|
-
];
|
|
669
|
-
const MQTT_EVENTS = [
|
|
670
|
-
'connect',
|
|
671
|
-
'message',
|
|
672
|
-
'disconnect',
|
|
673
|
-
'error',
|
|
674
|
-
'close',
|
|
675
|
-
'end',
|
|
676
|
-
'reconnect',
|
|
677
|
-
];
|
|
678
|
-
/** @hidden */
|
|
679
|
-
const createEventEmitter = () => {
|
|
680
|
-
return mitt__default["default"]();
|
|
681
|
-
};
|
|
682
754
|
/**
|
|
683
|
-
*
|
|
684
|
-
*
|
|
755
|
+
* ```js
|
|
756
|
+
* import { disableCache } from '@amityco/ts-sdk'
|
|
757
|
+
* disableCache()
|
|
758
|
+
* ```
|
|
685
759
|
*
|
|
686
|
-
*
|
|
687
|
-
* @
|
|
760
|
+
* Wipes the existing {@link Amity.Cache} object attached to
|
|
761
|
+
* an {@link Amity.Client} instance
|
|
688
762
|
*
|
|
689
|
-
* @category
|
|
690
|
-
* @hidden
|
|
763
|
+
* @category Cache API
|
|
691
764
|
*/
|
|
692
|
-
const
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
mqttClient.on('message', (topic, payload) => {
|
|
703
|
-
const message = JSON.parse(payload.toString());
|
|
704
|
-
emitter.emit(message.eventType, message.data);
|
|
705
|
-
});
|
|
706
|
-
};
|
|
765
|
+
const disableCache = () => {
|
|
766
|
+
const client = getActiveClient();
|
|
767
|
+
if (!client.cache)
|
|
768
|
+
return;
|
|
769
|
+
client.log('cache/api/disableCache');
|
|
770
|
+
// we do this so that testing if cache is enabled
|
|
771
|
+
// is only `if (client.cache)
|
|
772
|
+
delete client.cache;
|
|
773
|
+
};
|
|
774
|
+
|
|
707
775
|
/**
|
|
708
|
-
*
|
|
776
|
+
* ```js
|
|
777
|
+
* import { restoreCache } from '@amityco/ts-sdk'
|
|
778
|
+
* const success = await restoreCache()
|
|
779
|
+
* ```
|
|
709
780
|
*
|
|
710
|
-
*
|
|
711
|
-
*
|
|
712
|
-
* @param event The websocket event name
|
|
713
|
-
* @param fn A wrapper for the callback.
|
|
714
|
-
* @returns A dispose function to unsubscribe to the event
|
|
781
|
+
* Reads a previously saved {@link Amity.Cache} from a persistent storage,
|
|
782
|
+
* and inserts it into the current {@link Amity.Cache} instance.
|
|
715
783
|
*
|
|
716
|
-
*
|
|
717
|
-
* @
|
|
718
|
-
*/
|
|
719
|
-
const createEventSubscriber = (client, namespace, event, fn) => {
|
|
720
|
-
const { log, emitter } = client;
|
|
721
|
-
const timestamp = Date.now();
|
|
722
|
-
log(`${namespace}(tmpid: ${timestamp}) > listen`);
|
|
723
|
-
const handler = (...payload) => {
|
|
724
|
-
log(`${namespace}(tmpid: ${timestamp}) > trigger`, payload);
|
|
725
|
-
fn(...payload);
|
|
726
|
-
};
|
|
727
|
-
emitter.on(event, handler);
|
|
728
|
-
return () => {
|
|
729
|
-
log(`${namespace}(tmpid: ${timestamp}) > dispose`);
|
|
730
|
-
emitter.off(event, handler);
|
|
731
|
-
};
|
|
732
|
-
};
|
|
733
|
-
/**
|
|
734
|
-
* Wrapper around dispatch event
|
|
735
|
-
*
|
|
736
|
-
* @hidden
|
|
737
|
-
*/
|
|
738
|
-
const fireEvent = (event, payload) => {
|
|
739
|
-
const { emitter } = getActiveClient();
|
|
740
|
-
scheduleTask(() => {
|
|
741
|
-
emitter.emit(event, payload);
|
|
742
|
-
});
|
|
743
|
-
};
|
|
744
|
-
|
|
745
|
-
let activeUser = null;
|
|
746
|
-
/**
|
|
747
|
-
* for internal use
|
|
748
|
-
*/
|
|
749
|
-
const getActiveUser = () => {
|
|
750
|
-
if (!activeUser) {
|
|
751
|
-
throw new ASCError('Connect client first', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "fatal" /* Amity.ErrorLevel.FATAL */);
|
|
752
|
-
}
|
|
753
|
-
return activeUser;
|
|
754
|
-
};
|
|
755
|
-
const setActiveUser = (user) => {
|
|
756
|
-
activeUser = {
|
|
757
|
-
_id: user._id,
|
|
758
|
-
userId: user.userId,
|
|
759
|
-
path: user.path,
|
|
760
|
-
};
|
|
761
|
-
};
|
|
762
|
-
|
|
763
|
-
exports.SubscriptionLevels = void 0;
|
|
764
|
-
(function (SubscriptionLevels) {
|
|
765
|
-
SubscriptionLevels["COMMUNITY"] = "community";
|
|
766
|
-
SubscriptionLevels["POST"] = "post";
|
|
767
|
-
SubscriptionLevels["COMMENT"] = "comment";
|
|
768
|
-
SubscriptionLevels["POST_AND_COMMENT"] = "post_and_comment";
|
|
769
|
-
SubscriptionLevels["USER"] = "user";
|
|
770
|
-
})(exports.SubscriptionLevels || (exports.SubscriptionLevels = {}));
|
|
771
|
-
const getCommunityUserTopic = (path, level) => {
|
|
772
|
-
switch (level) {
|
|
773
|
-
case 'post':
|
|
774
|
-
return `${path}/post/+`;
|
|
775
|
-
case 'comment':
|
|
776
|
-
return `${path}/post/+/comment/+`;
|
|
777
|
-
case 'post_and_comment':
|
|
778
|
-
return `${path}/post/#`;
|
|
779
|
-
default:
|
|
780
|
-
return path;
|
|
781
|
-
}
|
|
782
|
-
};
|
|
783
|
-
const getCommunityTopic = ({ path }, level = exports.SubscriptionLevels.COMMUNITY) => getCommunityUserTopic(path, level);
|
|
784
|
-
const getUserTopic = ({ path }, level = exports.SubscriptionLevels.USER) => getCommunityUserTopic(level === exports.SubscriptionLevels.USER ? path : path.replace(/^(\w*)/, '$1/social'), level);
|
|
785
|
-
const getPostTopic = ({ path }, level = exports.SubscriptionLevels.POST) => {
|
|
786
|
-
switch (level) {
|
|
787
|
-
case 'comment':
|
|
788
|
-
return `${path}/comment/+`;
|
|
789
|
-
default:
|
|
790
|
-
return path;
|
|
791
|
-
}
|
|
792
|
-
};
|
|
793
|
-
const getCommentTopic = ({ path }) => {
|
|
794
|
-
return path;
|
|
795
|
-
};
|
|
796
|
-
const getMyFollowersTopic = () => {
|
|
797
|
-
const user = getActiveUser();
|
|
798
|
-
const [networkId] = user.path.split('/user/');
|
|
799
|
-
return `${networkId}/membership/${user._id}/+/+`;
|
|
800
|
-
};
|
|
801
|
-
const getMyFollowingsTopic = () => {
|
|
802
|
-
const user = getActiveUser();
|
|
803
|
-
const [networkId] = user.path.split('/user/');
|
|
804
|
-
return `${networkId}/membership/+/${user._id}/+`;
|
|
805
|
-
};
|
|
806
|
-
/** @hidden */
|
|
807
|
-
const getNetworkTopic = () => {
|
|
808
|
-
const user = getActiveUser();
|
|
809
|
-
const [networkId] = user.path.split('/user/');
|
|
810
|
-
return networkId;
|
|
811
|
-
};
|
|
812
|
-
let mqttAccessToken;
|
|
813
|
-
let mqttUserId;
|
|
814
|
-
function subscribeTopic(topic, callback) {
|
|
815
|
-
const { mqtt, emitter, accessToken } = getActiveClient();
|
|
816
|
-
const user = getActiveUser();
|
|
817
|
-
if (mqttAccessToken !== accessToken || mqttUserId !== user._id) {
|
|
818
|
-
mqttAccessToken = accessToken;
|
|
819
|
-
mqttUserId = user._id;
|
|
820
|
-
mqtt.connect({ accessToken: mqttAccessToken, userId: mqttUserId });
|
|
821
|
-
proxyMqttEvents(mqtt, emitter);
|
|
822
|
-
}
|
|
823
|
-
return mqtt.subscribe(topic, callback);
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
/**
|
|
827
|
-
* ```js
|
|
828
|
-
* import { enableCache } from '@amityco/ts-sdk'
|
|
829
|
-
* enableCache()
|
|
830
|
-
* ```
|
|
831
|
-
*
|
|
832
|
-
* Adds a new {@link Amity.Cache} object to
|
|
833
|
-
* an {@link Amity.Client} instance
|
|
834
|
-
*
|
|
835
|
-
* @param prevState a previous state of cache instance (useful for SSR)
|
|
836
|
-
* @param persistIf a function to determine if an entry inserted in cache
|
|
837
|
-
* is destined to be also saved in the persistent storage when
|
|
838
|
-
* calling {@link backupCache}
|
|
839
|
-
*
|
|
840
|
-
* @category Cache API
|
|
841
|
-
*/
|
|
842
|
-
const enableCache = (prevState = {}, persistIf) => {
|
|
843
|
-
const client = getActiveClient();
|
|
844
|
-
if (client.cache)
|
|
845
|
-
return;
|
|
846
|
-
client.log('cache/api/enableCache');
|
|
847
|
-
client.cache = { data: prevState, persistIf };
|
|
848
|
-
};
|
|
849
|
-
|
|
850
|
-
/**
|
|
851
|
-
* ```js
|
|
852
|
-
* import { disableCache } from '@amityco/ts-sdk'
|
|
853
|
-
* disableCache()
|
|
854
|
-
* ```
|
|
855
|
-
*
|
|
856
|
-
* Wipes the existing {@link Amity.Cache} object attached to
|
|
857
|
-
* an {@link Amity.Client} instance
|
|
858
|
-
*
|
|
859
|
-
* @category Cache API
|
|
860
|
-
*/
|
|
861
|
-
const disableCache = () => {
|
|
862
|
-
const client = getActiveClient();
|
|
863
|
-
if (!client.cache)
|
|
864
|
-
return;
|
|
865
|
-
client.log('cache/api/disableCache');
|
|
866
|
-
// we do this so that testing if cache is enabled
|
|
867
|
-
// is only `if (client.cache)
|
|
868
|
-
delete client.cache;
|
|
869
|
-
};
|
|
870
|
-
|
|
871
|
-
/**
|
|
872
|
-
* ```js
|
|
873
|
-
* import { restoreCache } from '@amityco/ts-sdk'
|
|
874
|
-
* const success = await restoreCache()
|
|
875
|
-
* ```
|
|
876
|
-
*
|
|
877
|
-
* Reads a previously saved {@link Amity.Cache} from a persistent storage,
|
|
878
|
-
* and inserts it into the current {@link Amity.Cache} instance.
|
|
879
|
-
*
|
|
880
|
-
* The strategy for persistent storage will depend on the runtime,
|
|
881
|
-
* which is supported by @react-native-async-storage/async-storage.
|
|
784
|
+
* The strategy for persistent storage will depend on the runtime,
|
|
785
|
+
* which is supported by @react-native-async-storage/async-storage.
|
|
882
786
|
*
|
|
883
787
|
* The current userId will be appended to the given storageKey to ensures
|
|
884
788
|
* the cached data concerns only the current user.
|
|
@@ -907,7 +811,6 @@ const restoreCache = async (storageKey = 'amitySdk') => {
|
|
|
907
811
|
return true;
|
|
908
812
|
};
|
|
909
813
|
|
|
910
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
911
814
|
/**
|
|
912
815
|
* ```js
|
|
913
816
|
* import { backupCache } from '@amityco/ts-sdk'
|
|
@@ -974,62 +877,6 @@ const wipeCache = async (storageKey = 'amitySdk') => {
|
|
|
974
877
|
return true;
|
|
975
878
|
};
|
|
976
879
|
|
|
977
|
-
/**
|
|
978
|
-
* Shallow-clones an object and sort its keys
|
|
979
|
-
*
|
|
980
|
-
* @param source a plain object to clone
|
|
981
|
-
* @returns a clone of source, with keys sorted with default javascript sorting
|
|
982
|
-
*
|
|
983
|
-
* @category Cache
|
|
984
|
-
* @hidden
|
|
985
|
-
*/
|
|
986
|
-
const normalize = (source) => Object.keys(source)
|
|
987
|
-
.sort()
|
|
988
|
-
.reduce((acc, key) => (Object.assign(Object.assign({}, acc), { [key]: source[key] })), {});
|
|
989
|
-
/**
|
|
990
|
-
* Encodes a given {@link Amity.CacheKey} to a plain string
|
|
991
|
-
*
|
|
992
|
-
* @param key the key to encode
|
|
993
|
-
* @returns an encoded string
|
|
994
|
-
*
|
|
995
|
-
* @category Cache
|
|
996
|
-
* @hidden
|
|
997
|
-
*/
|
|
998
|
-
const encodeKey = (key) => JSON.stringify(key, (_, val) => (typeof val === 'object' ? normalize(val) : val));
|
|
999
|
-
/**
|
|
1000
|
-
* Decodes a string back into a {@link Amity.CacheKey}
|
|
1001
|
-
|
|
1002
|
-
*
|
|
1003
|
-
* @param key the string key to decode
|
|
1004
|
-
* @returns a plain Amity.CacheKey object.
|
|
1005
|
-
*
|
|
1006
|
-
* @category Cache
|
|
1007
|
-
* @hidden
|
|
1008
|
-
*/
|
|
1009
|
-
const decodeKey = (key) => JSON.parse(key);
|
|
1010
|
-
/**
|
|
1011
|
-
* Performs a recursive partial deep equal check on two objects.
|
|
1012
|
-
*
|
|
1013
|
-
* @param predicate the reference object containing the partial information
|
|
1014
|
-
* @param candidate the object to check against
|
|
1015
|
-
* @returns true if the candidate contains all the values of the predicate
|
|
1016
|
-
*
|
|
1017
|
-
* @category Cache
|
|
1018
|
-
*/
|
|
1019
|
-
const partialMatch = (predicate, candidate) => {
|
|
1020
|
-
if (predicate === candidate)
|
|
1021
|
-
return true;
|
|
1022
|
-
// if one or the other is nullish, there can't be equality
|
|
1023
|
-
if (!predicate || !candidate)
|
|
1024
|
-
return false;
|
|
1025
|
-
// we only perform recursive check on objects
|
|
1026
|
-
if (typeof predicate !== 'object') {
|
|
1027
|
-
return false;
|
|
1028
|
-
}
|
|
1029
|
-
// recursively call for partial match based on the predicate
|
|
1030
|
-
return Object.keys(predicate).every(key => partialMatch(predicate[key], candidate[key]));
|
|
1031
|
-
};
|
|
1032
|
-
|
|
1033
880
|
/**
|
|
1034
881
|
* ```js
|
|
1035
882
|
* import { queryCache } from '@amityco/ts-sdk'
|
|
@@ -1206,83 +1053,353 @@ const dropFromCache = (key, exact = false) => {
|
|
|
1206
1053
|
return false;
|
|
1207
1054
|
};
|
|
1208
1055
|
|
|
1056
|
+
// Note:
|
|
1057
|
+
// this file should contain a suite of filtering utilities to help the
|
|
1058
|
+
// local version of the query functions.
|
|
1209
1059
|
/**
|
|
1210
|
-
*
|
|
1060
|
+
* Filter a given collection with strict equality against a param
|
|
1211
1061
|
*
|
|
1212
|
-
* @param
|
|
1213
|
-
* @
|
|
1062
|
+
* @param collection the collection to filter
|
|
1063
|
+
* @param key the key of the collection's items to challenge
|
|
1064
|
+
* @param value the expected value
|
|
1065
|
+
* @returns a filtered collection with items only matching the criteria
|
|
1214
1066
|
*
|
|
1215
|
-
* @category Debug
|
|
1216
1067
|
* @hidden
|
|
1217
1068
|
*/
|
|
1218
|
-
const
|
|
1219
|
-
|
|
1220
|
-
const logger = debug__default["default"](session);
|
|
1221
|
-
const print = (topic, ...args) => {
|
|
1222
|
-
active && logger(topic, args);
|
|
1223
|
-
};
|
|
1224
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
1225
|
-
print.__instance__ = logger;
|
|
1226
|
-
return print;
|
|
1227
|
-
};
|
|
1228
|
-
|
|
1229
|
-
const API_REGIONS = {
|
|
1230
|
-
EU: 'eu',
|
|
1231
|
-
SG: 'sg',
|
|
1232
|
-
US: 'us',
|
|
1233
|
-
};
|
|
1234
|
-
const URLS = {
|
|
1235
|
-
http: 'https://api.{region}.amity.co',
|
|
1236
|
-
mqtt: 'wss://sse.{region}.amity.co:443/mqtt',
|
|
1237
|
-
};
|
|
1238
|
-
function computeUrl(type, region) {
|
|
1239
|
-
return URLS[type].replace('{region}', region);
|
|
1240
|
-
}
|
|
1241
|
-
|
|
1069
|
+
const filterByPropEquality = (collection, key, value) => (value !== undefined ? collection.filter(item => item[key] === value) : collection);
|
|
1070
|
+
const filterByPropInclusion = (collection, key, value) => (value !== undefined ? collection.filter(item => value.includes(item[key])) : collection);
|
|
1242
1071
|
/**
|
|
1243
|
-
*
|
|
1244
|
-
*
|
|
1245
|
-
* @param response A typical "v3" response (related to backend's service strategy)
|
|
1072
|
+
* Filter a channel collection by membership of the userId
|
|
1246
1073
|
*
|
|
1247
|
-
* @
|
|
1248
|
-
* @
|
|
1074
|
+
* @param collection the channel collection to filter
|
|
1075
|
+
* @param membership the membership to be filtered by
|
|
1076
|
+
* @param userId user id to be filtered by
|
|
1077
|
+
* @returns a filtered collection with items only matching the criteria
|
|
1249
1078
|
*
|
|
1250
|
-
* @category Transport
|
|
1251
1079
|
* @hidden
|
|
1252
1080
|
*/
|
|
1253
|
-
const
|
|
1254
|
-
if (
|
|
1255
|
-
return
|
|
1256
|
-
}
|
|
1257
|
-
if (response.status === 'fail') {
|
|
1258
|
-
throw new ASCUnknownError(response.code);
|
|
1259
|
-
}
|
|
1260
|
-
else if (response.status === 'error') {
|
|
1261
|
-
throw new ASCApiError(response.message, response.code, "error" /* Amity.ErrorLevel.ERROR */);
|
|
1081
|
+
const filterByChannelMembership = (collection, membership, userId) => {
|
|
1082
|
+
if (membership === 'all') {
|
|
1083
|
+
return collection;
|
|
1262
1084
|
}
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
if (
|
|
1277
|
-
return
|
|
1085
|
+
return collection.filter(c => {
|
|
1086
|
+
var _a;
|
|
1087
|
+
// get resolver for the channel by user
|
|
1088
|
+
const channelUserCacheKey = getResolver('channelUsers')({
|
|
1089
|
+
channelId: c.channelId,
|
|
1090
|
+
userId,
|
|
1091
|
+
});
|
|
1092
|
+
const channelUser = (_a = pullFromCache([
|
|
1093
|
+
'channelUsers',
|
|
1094
|
+
'get',
|
|
1095
|
+
channelUserCacheKey,
|
|
1096
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
1097
|
+
// if channel user is defined for user, user is a member
|
|
1098
|
+
if (membership === 'member' && channelUser) {
|
|
1099
|
+
return true;
|
|
1278
1100
|
}
|
|
1279
|
-
if
|
|
1280
|
-
|
|
1101
|
+
// if channel user by user id not found, user is not a member of that
|
|
1102
|
+
// channel
|
|
1103
|
+
if (membership === 'notMember' && !channelUser) {
|
|
1104
|
+
return true;
|
|
1281
1105
|
}
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1106
|
+
return false;
|
|
1107
|
+
});
|
|
1108
|
+
};
|
|
1109
|
+
|
|
1110
|
+
// Note:
|
|
1111
|
+
// this file should contain a suite of sorting utilities to help the
|
|
1112
|
+
// local version of the query functions.
|
|
1113
|
+
/**
|
|
1114
|
+
* Alphabetic sorting of objects having a displayName
|
|
1115
|
+
*/
|
|
1116
|
+
const sortByDisplayName = ({ displayName: a }, { displayName: b }) => {
|
|
1117
|
+
if (a === b)
|
|
1118
|
+
return 0;
|
|
1119
|
+
return a < b ? -1 : 1;
|
|
1120
|
+
};
|
|
1121
|
+
/**
|
|
1122
|
+
* Sorting a collection by their apparition order (oldest first)
|
|
1123
|
+
*/
|
|
1124
|
+
const sortByChannelSegment = ({ channelSegment: a }, { channelSegment: b }) => a - b;
|
|
1125
|
+
/**
|
|
1126
|
+
* Sorting a collection by their apparition order (oldest first)
|
|
1127
|
+
*/
|
|
1128
|
+
const sortBySegmentNumber = ({ segmentNumber: a }, { segmentNumber: b }) => a - b;
|
|
1129
|
+
/**
|
|
1130
|
+
* Sorting a collection by its oldest items
|
|
1131
|
+
*/
|
|
1132
|
+
const sortByFirstCreated = ({ createdAt: a }, { createdAt: b }) => new Date(a).valueOf() - new Date(b).valueOf();
|
|
1133
|
+
/**
|
|
1134
|
+
* Sorting a collection by its newest items
|
|
1135
|
+
*/
|
|
1136
|
+
const sortByLastCreated = ({ createdAt: a }, { createdAt: b }) => new Date(b).valueOf() - new Date(a).valueOf();
|
|
1137
|
+
/**
|
|
1138
|
+
* Sorting a collection by the items with most recent activity
|
|
1139
|
+
*/
|
|
1140
|
+
const sortByLastActivity = ({ lastActivity: a }, { lastActivity: b }) => new Date(b).valueOf() - new Date(a).valueOf();
|
|
1141
|
+
|
|
1142
|
+
/* eslint-disable @typescript-eslint/ban-types */
|
|
1143
|
+
let tasks = [];
|
|
1144
|
+
let timer;
|
|
1145
|
+
/**
|
|
1146
|
+
* Add a function to run just before the next tick
|
|
1147
|
+
*
|
|
1148
|
+
* @param task function to schedule for later execution
|
|
1149
|
+
*/
|
|
1150
|
+
const scheduleTask = (task) => {
|
|
1151
|
+
clearTimeout(timer);
|
|
1152
|
+
tasks.push(task);
|
|
1153
|
+
timer = setTimeout(() => {
|
|
1154
|
+
tasks.forEach(fn => fn());
|
|
1155
|
+
tasks = [];
|
|
1156
|
+
}, 0);
|
|
1157
|
+
};
|
|
1158
|
+
|
|
1159
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
1160
|
+
// need to sync up the list
|
|
1161
|
+
const WS_EVENTS = [
|
|
1162
|
+
'disconnected',
|
|
1163
|
+
'error',
|
|
1164
|
+
'connect_error',
|
|
1165
|
+
'reconnect_error',
|
|
1166
|
+
'reconnect_failed',
|
|
1167
|
+
'v3.channel.didCreate',
|
|
1168
|
+
'v3.channel.didUpdate',
|
|
1169
|
+
'v3.channel.didDelete',
|
|
1170
|
+
'v3.channel.didMarkSeen',
|
|
1171
|
+
'v3.channel.didJoin',
|
|
1172
|
+
'v3.channel.didLeave',
|
|
1173
|
+
'v3.channel.didAddUsers',
|
|
1174
|
+
'v3.channel.didRemoveUsers',
|
|
1175
|
+
'v3.channel.didBan',
|
|
1176
|
+
'v3.channel.didUnban',
|
|
1177
|
+
'v3.message.didFetch',
|
|
1178
|
+
'v3.message.didCreate',
|
|
1179
|
+
'v3.message.didUpdate',
|
|
1180
|
+
'v3.message.didDelete',
|
|
1181
|
+
];
|
|
1182
|
+
const MQTT_EVENTS = [
|
|
1183
|
+
'connect',
|
|
1184
|
+
'message',
|
|
1185
|
+
'disconnect',
|
|
1186
|
+
'error',
|
|
1187
|
+
'close',
|
|
1188
|
+
'end',
|
|
1189
|
+
'reconnect',
|
|
1190
|
+
];
|
|
1191
|
+
/** @hidden */
|
|
1192
|
+
const createEventEmitter = () => {
|
|
1193
|
+
return mitt__default["default"]();
|
|
1194
|
+
};
|
|
1195
|
+
/**
|
|
1196
|
+
* Wraps the websocket events into the client's event emitter for
|
|
1197
|
+
* abstraction of transport.
|
|
1198
|
+
*
|
|
1199
|
+
* @param ws A websocket connection to listen from
|
|
1200
|
+
* @param emitter An event emitter to wire the events to
|
|
1201
|
+
*
|
|
1202
|
+
* @category Transport
|
|
1203
|
+
* @hidden
|
|
1204
|
+
*/
|
|
1205
|
+
const proxyWebsocketEvents = (ws, emitter) => {
|
|
1206
|
+
WS_EVENTS.forEach(event => {
|
|
1207
|
+
ws.on(event, (param) => emitter.emit(event, param));
|
|
1208
|
+
});
|
|
1209
|
+
};
|
|
1210
|
+
const proxyMqttEvents = (mqttClient, emitter) => {
|
|
1211
|
+
MQTT_EVENTS.forEach(event => {
|
|
1212
|
+
mqttClient.on(event, (...params) => emitter.emit(event, params.length === 1 ? params[0] : params));
|
|
1213
|
+
});
|
|
1214
|
+
// @ts-ignore
|
|
1215
|
+
mqttClient.on('message', (topic, payload) => {
|
|
1216
|
+
const message = JSON.parse(payload.toString());
|
|
1217
|
+
emitter.emit(message.eventType, message.data);
|
|
1218
|
+
});
|
|
1219
|
+
};
|
|
1220
|
+
/**
|
|
1221
|
+
* Standardize the subscription of SSE through web sockets
|
|
1222
|
+
*
|
|
1223
|
+
* @param client The current client for which to subscribe the event to
|
|
1224
|
+
* @param namespace A unique name for the logger
|
|
1225
|
+
* @param event The websocket event name
|
|
1226
|
+
* @param fn A wrapper for the callback.
|
|
1227
|
+
* @returns A dispose function to unsubscribe to the event
|
|
1228
|
+
*
|
|
1229
|
+
* @category Transport
|
|
1230
|
+
* @hidden
|
|
1231
|
+
*/
|
|
1232
|
+
const createEventSubscriber = (client, namespace, event, fn) => {
|
|
1233
|
+
const { log, emitter } = client;
|
|
1234
|
+
const timestamp = Date.now();
|
|
1235
|
+
log(`${namespace}(tmpid: ${timestamp}) > listen`);
|
|
1236
|
+
const handler = (...payload) => {
|
|
1237
|
+
log(`${namespace}(tmpid: ${timestamp}) > trigger`, payload);
|
|
1238
|
+
fn(...payload);
|
|
1239
|
+
};
|
|
1240
|
+
emitter.on(event, handler);
|
|
1241
|
+
return () => {
|
|
1242
|
+
log(`${namespace}(tmpid: ${timestamp}) > dispose`);
|
|
1243
|
+
emitter.off(event, handler);
|
|
1244
|
+
};
|
|
1245
|
+
};
|
|
1246
|
+
/**
|
|
1247
|
+
* Wrapper around dispatch event
|
|
1248
|
+
*
|
|
1249
|
+
* @hidden
|
|
1250
|
+
*/
|
|
1251
|
+
const fireEvent = (event, payload) => {
|
|
1252
|
+
const { emitter } = getActiveClient();
|
|
1253
|
+
scheduleTask(() => {
|
|
1254
|
+
emitter.emit(event, payload);
|
|
1255
|
+
});
|
|
1256
|
+
};
|
|
1257
|
+
|
|
1258
|
+
let activeUser = null;
|
|
1259
|
+
/**
|
|
1260
|
+
* for internal use
|
|
1261
|
+
*/
|
|
1262
|
+
const getActiveUser = () => {
|
|
1263
|
+
if (!activeUser) {
|
|
1264
|
+
throw new ASCError('Connect client first', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "fatal" /* Amity.ErrorLevel.FATAL */);
|
|
1265
|
+
}
|
|
1266
|
+
return activeUser;
|
|
1267
|
+
};
|
|
1268
|
+
const setActiveUser = (user) => {
|
|
1269
|
+
activeUser = {
|
|
1270
|
+
_id: user._id,
|
|
1271
|
+
userId: user.userId,
|
|
1272
|
+
path: user.path,
|
|
1273
|
+
};
|
|
1274
|
+
};
|
|
1275
|
+
|
|
1276
|
+
exports.SubscriptionLevels = void 0;
|
|
1277
|
+
(function (SubscriptionLevels) {
|
|
1278
|
+
SubscriptionLevels["COMMUNITY"] = "community";
|
|
1279
|
+
SubscriptionLevels["POST"] = "post";
|
|
1280
|
+
SubscriptionLevels["COMMENT"] = "comment";
|
|
1281
|
+
SubscriptionLevels["POST_AND_COMMENT"] = "post_and_comment";
|
|
1282
|
+
SubscriptionLevels["USER"] = "user";
|
|
1283
|
+
})(exports.SubscriptionLevels || (exports.SubscriptionLevels = {}));
|
|
1284
|
+
const getCommunityUserTopic = (path, level) => {
|
|
1285
|
+
switch (level) {
|
|
1286
|
+
case 'post':
|
|
1287
|
+
return `${path}/post/+`;
|
|
1288
|
+
case 'comment':
|
|
1289
|
+
return `${path}/post/+/comment/+`;
|
|
1290
|
+
case 'post_and_comment':
|
|
1291
|
+
return `${path}/post/#`;
|
|
1292
|
+
default:
|
|
1293
|
+
return path;
|
|
1294
|
+
}
|
|
1295
|
+
};
|
|
1296
|
+
const getCommunityTopic = ({ path }, level = exports.SubscriptionLevels.COMMUNITY) => getCommunityUserTopic(path, level);
|
|
1297
|
+
const getUserTopic = ({ path }, level = exports.SubscriptionLevels.USER) => getCommunityUserTopic(level === exports.SubscriptionLevels.USER ? path : path.replace(/^(\w*)/, '$1/social'), level);
|
|
1298
|
+
const getPostTopic = ({ path }, level = exports.SubscriptionLevels.POST) => {
|
|
1299
|
+
switch (level) {
|
|
1300
|
+
case 'comment':
|
|
1301
|
+
return `${path}/comment/+`;
|
|
1302
|
+
default:
|
|
1303
|
+
return path;
|
|
1304
|
+
}
|
|
1305
|
+
};
|
|
1306
|
+
const getCommentTopic = ({ path }) => {
|
|
1307
|
+
return path;
|
|
1308
|
+
};
|
|
1309
|
+
const getMyFollowersTopic = () => {
|
|
1310
|
+
const user = getActiveUser();
|
|
1311
|
+
const [networkId] = user.path.split('/user/');
|
|
1312
|
+
return `${networkId}/membership/${user._id}/+/+`;
|
|
1313
|
+
};
|
|
1314
|
+
const getMyFollowingsTopic = () => {
|
|
1315
|
+
const user = getActiveUser();
|
|
1316
|
+
const [networkId] = user.path.split('/user/');
|
|
1317
|
+
return `${networkId}/membership/+/${user._id}/+`;
|
|
1318
|
+
};
|
|
1319
|
+
/** @hidden */
|
|
1320
|
+
const getNetworkTopic = () => {
|
|
1321
|
+
const user = getActiveUser();
|
|
1322
|
+
const [networkId] = user.path.split('/user/');
|
|
1323
|
+
return networkId;
|
|
1324
|
+
};
|
|
1325
|
+
let mqttAccessToken;
|
|
1326
|
+
let mqttUserId;
|
|
1327
|
+
function subscribeTopic(topic, callback) {
|
|
1328
|
+
const { mqtt, emitter, accessToken } = getActiveClient();
|
|
1329
|
+
const user = getActiveUser();
|
|
1330
|
+
if (mqttAccessToken !== accessToken || mqttUserId !== user._id) {
|
|
1331
|
+
mqttAccessToken = accessToken;
|
|
1332
|
+
mqttUserId = user._id;
|
|
1333
|
+
mqtt.connect({ accessToken: mqttAccessToken, userId: mqttUserId });
|
|
1334
|
+
proxyMqttEvents(mqtt, emitter);
|
|
1335
|
+
}
|
|
1336
|
+
return mqtt.subscribe(topic, callback);
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
/**
|
|
1340
|
+
* Creates a pre-configured logger instance
|
|
1341
|
+
*
|
|
1342
|
+
* @param session The name of the debug session
|
|
1343
|
+
* @returns A pre-configured logger function
|
|
1344
|
+
*
|
|
1345
|
+
* @category Debug
|
|
1346
|
+
* @hidden
|
|
1347
|
+
*/
|
|
1348
|
+
const createLogger = (session) => {
|
|
1349
|
+
const active = `${session === null || session === void 0 ? void 0 : session.trim()}`.length > 0 && !isProduction;
|
|
1350
|
+
const logger = debug__default["default"](session);
|
|
1351
|
+
const print = (topic, ...args) => {
|
|
1352
|
+
active && logger(topic, args);
|
|
1353
|
+
};
|
|
1354
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
1355
|
+
print.__instance__ = logger;
|
|
1356
|
+
return print;
|
|
1357
|
+
};
|
|
1358
|
+
|
|
1359
|
+
const API_REGIONS = {
|
|
1360
|
+
EU: 'eu',
|
|
1361
|
+
SG: 'sg',
|
|
1362
|
+
US: 'us',
|
|
1363
|
+
};
|
|
1364
|
+
const URLS = {
|
|
1365
|
+
http: 'https://api.{region}.amity.co',
|
|
1366
|
+
mqtt: 'wss://sse.{region}.amity.co:443/mqtt',
|
|
1367
|
+
};
|
|
1368
|
+
function computeUrl(type, region) {
|
|
1369
|
+
return URLS[type].replace('{region}', region);
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
/**
|
|
1373
|
+
* Unwraps v3 server payload (for error handling and type extraction)
|
|
1374
|
+
*
|
|
1375
|
+
* @param response A typical "v3" response (related to backend's service strategy)
|
|
1376
|
+
*
|
|
1377
|
+
* @returns The data returned by the backend
|
|
1378
|
+
* @throws An error related to backend's rejection
|
|
1379
|
+
*
|
|
1380
|
+
* @category Transport
|
|
1381
|
+
* @hidden
|
|
1382
|
+
*/
|
|
1383
|
+
const unwrapPayload = (response) => {
|
|
1384
|
+
if (response.status === 'success') {
|
|
1385
|
+
return response.data;
|
|
1386
|
+
}
|
|
1387
|
+
if (response.status === 'fail') {
|
|
1388
|
+
throw new ASCUnknownError(response.code);
|
|
1389
|
+
}
|
|
1390
|
+
else if (response.status === 'error') {
|
|
1391
|
+
throw new ASCApiError(response.message, response.code, "error" /* Amity.ErrorLevel.ERROR */);
|
|
1392
|
+
}
|
|
1393
|
+
// unjust, but helps force uncast "T | undefined" to allow deconstruction without warnings
|
|
1394
|
+
return undefined;
|
|
1395
|
+
};
|
|
1396
|
+
|
|
1397
|
+
/**
|
|
1398
|
+
* Axios param serializer (for querystring)
|
|
1399
|
+
* @hidden
|
|
1400
|
+
*/
|
|
1401
|
+
const stringify = (params) => {
|
|
1402
|
+
return qs__default["default"].stringify(params, { arrayFormat: 'brackets' });
|
|
1286
1403
|
};
|
|
1287
1404
|
/**
|
|
1288
1405
|
* Creates a pre-configured axios instance
|
|
@@ -20155,6 +20272,28 @@ const createMqttTransport = (endpoint) => {
|
|
|
20155
20272
|
};
|
|
20156
20273
|
};
|
|
20157
20274
|
|
|
20275
|
+
/**
|
|
20276
|
+
* ```js
|
|
20277
|
+
* import { getFeedSettings } from '@amityco/ts-sdk'
|
|
20278
|
+
* const feedSettings = await getFeedSettings()
|
|
20279
|
+
* const postFeedSetting = feedSettings.post
|
|
20280
|
+
* ```
|
|
20281
|
+
*
|
|
20282
|
+
* Fetches a {@link Amity.FeedSettings} object
|
|
20283
|
+
*
|
|
20284
|
+
* @returns A Promise of {@link Amity.FeedSettings} object
|
|
20285
|
+
*
|
|
20286
|
+
* @category Client API
|
|
20287
|
+
* @async
|
|
20288
|
+
*/
|
|
20289
|
+
const getFeedSettings = async () => {
|
|
20290
|
+
const client = getActiveClient();
|
|
20291
|
+
const { data } = await client.http.get(`/api/v3/network-settings/feed-setting`);
|
|
20292
|
+
return Object.fromEntries(data.feedSettings.map(({ feedType, contentSettings }) => {
|
|
20293
|
+
return [feedType, contentSettings];
|
|
20294
|
+
}));
|
|
20295
|
+
};
|
|
20296
|
+
|
|
20158
20297
|
const DEFAULT_DEBUG_SESSION = 'amity';
|
|
20159
20298
|
/**
|
|
20160
20299
|
* ```js
|
|
@@ -20194,6 +20333,7 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
|
|
|
20194
20333
|
mqtt,
|
|
20195
20334
|
emitter,
|
|
20196
20335
|
use: () => setActiveClient(client),
|
|
20336
|
+
getFeedSettings,
|
|
20197
20337
|
};
|
|
20198
20338
|
try {
|
|
20199
20339
|
getActiveClient();
|
|
@@ -20271,7 +20411,7 @@ const getDeviceInfo = () => {
|
|
|
20271
20411
|
* Ingest a payload (v3) into the cache
|
|
20272
20412
|
*
|
|
20273
20413
|
* @param payload a "backend v3" payload object
|
|
20274
|
-
* @param
|
|
20414
|
+
* @param options caching options like cachedAt or offline
|
|
20275
20415
|
*
|
|
20276
20416
|
* @category Cache
|
|
20277
20417
|
* @hidden
|
|
@@ -20283,9 +20423,7 @@ const ingestInCache = (payload = {}, options) => {
|
|
|
20283
20423
|
return;
|
|
20284
20424
|
const resolver = getResolver(type);
|
|
20285
20425
|
models.forEach(model => {
|
|
20286
|
-
upsertInCache(
|
|
20287
|
-
// eslint-disable @typescript-eslint no-explicit-any
|
|
20288
|
-
[type, 'get', resolver(model)], // this 'any' cannot be avoided, sorry.
|
|
20426
|
+
upsertInCache([type, 'get', resolver(model)], // this 'any' cannot be avoided, sorry.
|
|
20289
20427
|
model, options);
|
|
20290
20428
|
});
|
|
20291
20429
|
});
|
|
@@ -20435,7 +20573,6 @@ const onClientBanned = (callback) => {
|
|
|
20435
20573
|
* @param params.displayName the user's displayName for the current session
|
|
20436
20574
|
* @param params.deviceId Manual override of the user's device id (for device management)
|
|
20437
20575
|
* @param params.authToken The authentication token - necessary when network option is set to secure
|
|
20438
|
-
* @param config
|
|
20439
20576
|
* @returns a success boolean if connected
|
|
20440
20577
|
*
|
|
20441
20578
|
* @category Client API
|
|
@@ -20496,10 +20633,65 @@ const isConnected = () => {
|
|
|
20496
20633
|
const client = getActiveClient();
|
|
20497
20634
|
client.log('client/api/isConnected', client);
|
|
20498
20635
|
return !!(client.userId &&
|
|
20499
|
-
((_b = (_a = client.http.defaults.headers.common) === null || _a === void 0 ? void 0 : _a.Authorization) === null || _b === void 0 ? void 0 : _b.length) &&
|
|
20636
|
+
((_b = String((_a = client.http.defaults.headers.common) === null || _a === void 0 ? void 0 : _a.Authorization)) === null || _b === void 0 ? void 0 : _b.length) &&
|
|
20500
20637
|
client.ws.connected);
|
|
20501
20638
|
};
|
|
20502
20639
|
|
|
20640
|
+
/**
|
|
20641
|
+
* ```js
|
|
20642
|
+
* import { isInTombstone } from '@amityco/ts-sdk'
|
|
20643
|
+
* const user = isInTombstone(["message", "messageId"])
|
|
20644
|
+
* ```
|
|
20645
|
+
*
|
|
20646
|
+
* Checks if the {@link Amity.TombstoneCacheOptions} exists
|
|
20647
|
+
* in cache and it's not expired means it's in tombstone
|
|
20648
|
+
* and we throw an Error
|
|
20649
|
+
*
|
|
20650
|
+
* @param model the model to check
|
|
20651
|
+
* @param modelId the object id to check
|
|
20652
|
+
* @returns the matching cache entry, or undefined.
|
|
20653
|
+
*
|
|
20654
|
+
* @category Cache API
|
|
20655
|
+
*/
|
|
20656
|
+
const isInTombstone = (model, modelId) => {
|
|
20657
|
+
const { log, cache } = getActiveClient();
|
|
20658
|
+
const key = [model, CACHE_KEY_TOMBSTONE, modelId];
|
|
20659
|
+
if (!cache)
|
|
20660
|
+
return;
|
|
20661
|
+
log('cache/api/isInTombstone', key);
|
|
20662
|
+
const isInTombstone = pullFromCache(key);
|
|
20663
|
+
const { lifeSpan } = queryOptions('cache_then_server', CACHE_LIFESPAN_TOMBSTONE);
|
|
20664
|
+
if (isInTombstone && isFresh(isInTombstone.data, lifeSpan)) {
|
|
20665
|
+
throw new ASCApiError('Item not found!', 400400 /* Amity.ServerError.ITEM_NOT_FOUND */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
20666
|
+
}
|
|
20667
|
+
};
|
|
20668
|
+
|
|
20669
|
+
/**
|
|
20670
|
+
* ```js
|
|
20671
|
+
* import { pushToTombstone } from '@amityco/ts-sdk'
|
|
20672
|
+
* pushToTombstone(["message", "messageId"], { cachedAt: Date.now() })
|
|
20673
|
+
* ```
|
|
20674
|
+
*
|
|
20675
|
+
* Removes an existing {@link Amity.CacheEntry} from the {@link Amity.Client}'s
|
|
20676
|
+
* {@link Amity.Cache} from a given {@link Amity.CacheKey}
|
|
20677
|
+
*
|
|
20678
|
+
* @param model the model to remove and push to Tombstone
|
|
20679
|
+
* @param modelId the related model id
|
|
20680
|
+
*
|
|
20681
|
+
* @category Cache API
|
|
20682
|
+
* @hidden
|
|
20683
|
+
*/
|
|
20684
|
+
const pushToTombstone = (model, modelId) => {
|
|
20685
|
+
const { log, cache } = getActiveClient();
|
|
20686
|
+
const cacheKey = [model, CACHE_KEY_TOMBSTONE, modelId];
|
|
20687
|
+
const data = { cachedAt: Date.now() };
|
|
20688
|
+
if (!cache)
|
|
20689
|
+
return;
|
|
20690
|
+
log('cache/api/pushToTombstone', { cacheKey, data });
|
|
20691
|
+
dropFromCache([model, CACHE_KEY_GET, modelId], true);
|
|
20692
|
+
pushToCache(cacheKey, data);
|
|
20693
|
+
};
|
|
20694
|
+
|
|
20503
20695
|
/**
|
|
20504
20696
|
* ```js
|
|
20505
20697
|
* import { getUser } from '@amityco/ts-sdk'
|
|
@@ -20514,15 +20706,29 @@ const isConnected = () => {
|
|
|
20514
20706
|
* @category User API
|
|
20515
20707
|
* @async
|
|
20516
20708
|
*/
|
|
20517
|
-
const getUser = async (userId) => {
|
|
20709
|
+
const getUser = async (userId, isLive = false) => {
|
|
20518
20710
|
const client = getActiveClient();
|
|
20519
20711
|
client.log('user/getUser', userId);
|
|
20520
|
-
|
|
20521
|
-
|
|
20712
|
+
if (!isLive) {
|
|
20713
|
+
console.log('getUser will be deprecated on 25th November 2022, please use liveUser instead.');
|
|
20714
|
+
}
|
|
20715
|
+
isInTombstone('user', userId);
|
|
20716
|
+
let data;
|
|
20717
|
+
try {
|
|
20718
|
+
const response = await client.http.get(`/api/v3/users/${encodeURIComponent(userId)}`);
|
|
20719
|
+
data = response.data;
|
|
20720
|
+
}
|
|
20721
|
+
catch (error) {
|
|
20722
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
20723
|
+
pushToTombstone('user', userId);
|
|
20724
|
+
}
|
|
20725
|
+
throw error;
|
|
20726
|
+
}
|
|
20522
20727
|
const cachedAt = client.cache && Date.now();
|
|
20523
20728
|
if (client.cache)
|
|
20524
20729
|
ingestInCache(data, { cachedAt });
|
|
20525
20730
|
const { users } = data;
|
|
20731
|
+
fireEvent('user.fetched', data);
|
|
20526
20732
|
return {
|
|
20527
20733
|
data: users.find(user => user.userId === userId),
|
|
20528
20734
|
cachedAt,
|
|
@@ -20572,6 +20778,7 @@ const getUsers = async (userIds) => {
|
|
|
20572
20778
|
const cachedAt = client.cache && Date.now();
|
|
20573
20779
|
if (client.cache)
|
|
20574
20780
|
ingestInCache(data, { cachedAt });
|
|
20781
|
+
fireEvent('user.fetched', data);
|
|
20575
20782
|
return {
|
|
20576
20783
|
data: data.users,
|
|
20577
20784
|
cachedAt,
|
|
@@ -20654,8 +20861,7 @@ function __rest(s, e) {
|
|
|
20654
20861
|
const queryUsers = async (query = {}) => {
|
|
20655
20862
|
const client = getActiveClient();
|
|
20656
20863
|
client.log('user/queryUsers', query);
|
|
20657
|
-
const { page, displayName, filter = 'all', sortBy = 'displayName' } = query, params = __rest(query, ["page", "displayName", "filter", "sortBy"]);
|
|
20658
|
-
// API-FIX: parameters should be querystring.
|
|
20864
|
+
const { page = { limit: 10 }, displayName, filter = 'all', sortBy = 'displayName' } = query, params = __rest(query, ["page", "displayName", "filter", "sortBy"]);
|
|
20659
20865
|
const { data } = await client.http.get(`/api/v3/users`, {
|
|
20660
20866
|
params: Object.assign(Object.assign({}, params), { keyword: displayName, filter,
|
|
20661
20867
|
sortBy, options: {
|
|
@@ -20668,9 +20874,14 @@ const queryUsers = async (query = {}) => {
|
|
|
20668
20874
|
const cachedAt = client.cache && Date.now();
|
|
20669
20875
|
if (client.cache) {
|
|
20670
20876
|
ingestInCache(payload, { cachedAt });
|
|
20671
|
-
|
|
20877
|
+
/*
|
|
20878
|
+
* using query as cache key over params because if the keyword, filter, sort
|
|
20879
|
+
* change the API will NOT cache results, when it should
|
|
20880
|
+
*/
|
|
20881
|
+
const cacheKey = ['user', 'query', Object.assign(Object.assign({}, query), { options: Object.assign({}, page) })];
|
|
20672
20882
|
pushToCache(cacheKey, { users: users.map(getResolver('user')), paging });
|
|
20673
20883
|
}
|
|
20884
|
+
fireEvent('user.fetched', data);
|
|
20674
20885
|
const prevPage = toPage(paging.previous);
|
|
20675
20886
|
const nextPage = toPage(paging.next);
|
|
20676
20887
|
return { data: users, cachedAt, prevPage, nextPage };
|
|
@@ -20695,8 +20906,13 @@ queryUsers.locally = (query = {}) => {
|
|
|
20695
20906
|
client.log('user/queryUsers.locally', query);
|
|
20696
20907
|
if (!client.cache)
|
|
20697
20908
|
return;
|
|
20698
|
-
const
|
|
20699
|
-
const
|
|
20909
|
+
const { page = { limit: 10 } } = query !== null && query !== void 0 ? query : {};
|
|
20910
|
+
const cacheKey = [
|
|
20911
|
+
'user',
|
|
20912
|
+
'query',
|
|
20913
|
+
Object.assign(Object.assign({}, query), { options: Object.assign({}, page) }),
|
|
20914
|
+
];
|
|
20915
|
+
const { data, cachedAt } = (_a = pullFromCache(cacheKey)) !== null && _a !== void 0 ? _a : {};
|
|
20700
20916
|
const users = (_b = data === null || data === void 0 ? void 0 : data.users.map(userId => pullFromCache(['user', 'get', userId])).filter(Boolean).map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
|
|
20701
20917
|
const prevPage = toPage(data === null || data === void 0 ? void 0 : data.paging.previous);
|
|
20702
20918
|
const nextPage = toPage(data === null || data === void 0 ? void 0 : data.paging.next);
|
|
@@ -20734,12 +20950,30 @@ const updateUser = async (userId, patch) => {
|
|
|
20734
20950
|
if (client.cache)
|
|
20735
20951
|
ingestInCache(data, { cachedAt });
|
|
20736
20952
|
const { users } = data;
|
|
20953
|
+
fireEvent('user.updated', data);
|
|
20737
20954
|
return {
|
|
20738
20955
|
data: users.find(user => user.userId === userId),
|
|
20739
20956
|
cachedAt,
|
|
20740
20957
|
};
|
|
20741
20958
|
};
|
|
20742
20959
|
|
|
20960
|
+
/**
|
|
20961
|
+
* ```js
|
|
20962
|
+
* import { onUserFetched } from '@amityco/ts-sdk'
|
|
20963
|
+
* const dispose = onUserFetched(user => {
|
|
20964
|
+
* // ...
|
|
20965
|
+
* })
|
|
20966
|
+
* ```
|
|
20967
|
+
*
|
|
20968
|
+
* Fired when a {@link Amity.User} has been fetched
|
|
20969
|
+
*
|
|
20970
|
+
* @param callback The function to call when the event was fired
|
|
20971
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20972
|
+
*
|
|
20973
|
+
* @category User Events
|
|
20974
|
+
*/
|
|
20975
|
+
const onUserFetched = (callback) => createUserEventSubscriber('user.fetched', callback);
|
|
20976
|
+
|
|
20743
20977
|
/**
|
|
20744
20978
|
* ```js
|
|
20745
20979
|
* import { onUserUpdated } from '@amityco/ts-sdk'
|
|
@@ -20808,6 +21042,68 @@ const onUserUnflagged = (callback) => createUserEventSubscriber('user.unflagged'
|
|
|
20808
21042
|
*/
|
|
20809
21043
|
const onUserFlagCleared = (callback) => createUserEventSubscriber('user.flagCleared', callback);
|
|
20810
21044
|
|
|
21045
|
+
const COLLECTION_DEFAULT_PAGINATION_LIMIT = 5;
|
|
21046
|
+
const COLLECTION_DEFAULT_CACHING_POLICY = 'cache_then_server';
|
|
21047
|
+
const ENABLE_CACHE_MESSAGE = 'For using Live Collection feature you need to enable Cache!';
|
|
21048
|
+
const LIVE_OBJECT_ENABLE_CACHE_MESSAGE = 'For using Live Object feature you need to enable Cache!';
|
|
21049
|
+
const UNSYNCED_OBJECT_CACHED_AT_MESSAGE = 'Observing unsynced object is not supported by Live Object.';
|
|
21050
|
+
const UNSYNCED_OBJECT_CACHED_AT_VALUE = -5;
|
|
21051
|
+
|
|
21052
|
+
/**
|
|
21053
|
+
* ```js
|
|
21054
|
+
* import { liveUser } from '@amityco/ts-sdk'
|
|
21055
|
+
*
|
|
21056
|
+
* let users = []
|
|
21057
|
+
* const unsub = liveUser(userId, response => merge(users, response.data))
|
|
21058
|
+
* ```
|
|
21059
|
+
*
|
|
21060
|
+
* Observe all mutation on a given {@link Amity.User}
|
|
21061
|
+
*
|
|
21062
|
+
* @param userId the ID of the user to observe
|
|
21063
|
+
* @param callback the function to call when new data are available
|
|
21064
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the users
|
|
21065
|
+
*
|
|
21066
|
+
* @category Message Live Object
|
|
21067
|
+
*/
|
|
21068
|
+
const liveUser = (userId, callback) => {
|
|
21069
|
+
const { log, cache } = getActiveClient();
|
|
21070
|
+
let user;
|
|
21071
|
+
if (!cache) {
|
|
21072
|
+
console.log(LIVE_OBJECT_ENABLE_CACHE_MESSAGE);
|
|
21073
|
+
}
|
|
21074
|
+
const timestamp = Date.now();
|
|
21075
|
+
log(`liveUser(tmpid: ${timestamp}) > listen`);
|
|
21076
|
+
const disposers = [];
|
|
21077
|
+
const dispatcher = (data) => {
|
|
21078
|
+
var _a;
|
|
21079
|
+
// we check updatedAt to see if the current snapshot is new so
|
|
21080
|
+
// we won't send old data back, only fresh new data
|
|
21081
|
+
if (user && ((_a = data.data) === null || _a === void 0 ? void 0 : _a.updatedAt) === (user === null || user === void 0 ? void 0 : user.updatedAt) && data.origin !== 'server')
|
|
21082
|
+
return;
|
|
21083
|
+
callback(data);
|
|
21084
|
+
user = data.data;
|
|
21085
|
+
};
|
|
21086
|
+
const realtimeRouter = (user, action) => {
|
|
21087
|
+
dispatcher({ loading: false, data: user, origin: 'event' });
|
|
21088
|
+
};
|
|
21089
|
+
const onFetch = () => {
|
|
21090
|
+
const query = createQuery(getUser, userId, true);
|
|
21091
|
+
runQuery(query, ({ loading, data, error, origin }) => {
|
|
21092
|
+
dispatcher({ loading, data, origin, error });
|
|
21093
|
+
if (error) {
|
|
21094
|
+
// Terminate observe functionality on error
|
|
21095
|
+
disposers.forEach(fn => fn());
|
|
21096
|
+
}
|
|
21097
|
+
});
|
|
21098
|
+
};
|
|
21099
|
+
disposers.push(onUserFetched(user => realtimeRouter(user)), onUserUpdated(user => realtimeRouter(user)), onUserDeleted(user => realtimeRouter(user)), onUserFlagged(user => realtimeRouter(user)), onUserUnflagged(user => realtimeRouter(user)), onUserFlagCleared(user => realtimeRouter(user)));
|
|
21100
|
+
onFetch();
|
|
21101
|
+
return () => {
|
|
21102
|
+
log(`liveUser(tmpid: ${timestamp}) > dispose`);
|
|
21103
|
+
disposers.forEach(fn => fn());
|
|
21104
|
+
};
|
|
21105
|
+
};
|
|
21106
|
+
|
|
20811
21107
|
/**
|
|
20812
21108
|
* ```js
|
|
20813
21109
|
* import { observeUser } from '@amityco/ts-sdk'
|
|
@@ -20827,6 +21123,7 @@ const observeUser = (userId, callback) => {
|
|
|
20827
21123
|
const { log } = getActiveClient();
|
|
20828
21124
|
const timestamp = Date.now();
|
|
20829
21125
|
log(`observeUser(tmpid: ${timestamp}) > listen`);
|
|
21126
|
+
console.log('observeUser will be deprecated on 25th November 2022, please use liveUser instead.');
|
|
20830
21127
|
// wrapper function to make sure
|
|
20831
21128
|
const router = (result, action) => {
|
|
20832
21129
|
var _a, _b, _c;
|
|
@@ -20987,17 +21284,21 @@ const fileUrlWithSize = (fileUrl, size) => {
|
|
|
20987
21284
|
* Creates an {@link Amity.File<'video'>}
|
|
20988
21285
|
*
|
|
20989
21286
|
* @param formData The data necessary to create a new {@link Amity.File<'video'>}
|
|
21287
|
+
* @param feedType The {@link Amity.File<'video'>} feed type
|
|
20990
21288
|
* @param onProgress The callback to track the upload progress
|
|
20991
21289
|
* @returns The newly created {@link Amity.File<'video'>}
|
|
20992
21290
|
*
|
|
20993
21291
|
* @category File API
|
|
20994
21292
|
* @async
|
|
20995
21293
|
*/
|
|
20996
|
-
const createVideo = async (formData, onProgress) => {
|
|
21294
|
+
const createVideo = async (formData, feedType, onProgress) => {
|
|
20997
21295
|
const client = getActiveClient();
|
|
20998
21296
|
client.log('file/createVideo', formData);
|
|
20999
21297
|
if (!formData.getAll('files').length)
|
|
21000
21298
|
throw new Error('The formData object must have a `files` key.');
|
|
21299
|
+
if (feedType) {
|
|
21300
|
+
formData.append('feedType', feedType);
|
|
21301
|
+
}
|
|
21001
21302
|
const headers = 'getHeaders' in formData
|
|
21002
21303
|
? formData.getHeaders()
|
|
21003
21304
|
: { 'content-type': 'multipart/form-data' };
|
|
@@ -21232,15 +21533,30 @@ const dispatchReactable = (referenceType, model) => {
|
|
|
21232
21533
|
* @category Message API
|
|
21233
21534
|
* @async
|
|
21234
21535
|
*/
|
|
21235
|
-
const getMessage = async (messageId) => {
|
|
21536
|
+
const getMessage = async (messageId, isLive = false) => {
|
|
21236
21537
|
const client = getActiveClient();
|
|
21237
21538
|
client.log('message/getMessage', messageId);
|
|
21238
|
-
|
|
21239
|
-
|
|
21539
|
+
if (!isLive) {
|
|
21540
|
+
console.log('getMessage will be deprecated on 15th November 2022, please use liveMessage instead.');
|
|
21541
|
+
}
|
|
21542
|
+
isInTombstone('message', messageId);
|
|
21543
|
+
let data;
|
|
21544
|
+
try {
|
|
21545
|
+
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
21546
|
+
const response = await client.http.get(`/api/v3/messages/${encodeURIComponent(messageId)}`);
|
|
21547
|
+
data = response.data;
|
|
21548
|
+
}
|
|
21549
|
+
catch (error) {
|
|
21550
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
21551
|
+
pushToTombstone('message', messageId);
|
|
21552
|
+
}
|
|
21553
|
+
throw error;
|
|
21554
|
+
}
|
|
21240
21555
|
const cachedAt = client.cache && Date.now();
|
|
21241
21556
|
if (client.cache)
|
|
21242
21557
|
ingestInCache(data, { cachedAt });
|
|
21243
21558
|
const { messages } = data;
|
|
21559
|
+
fireEvent('v3.message.didFetch', { messages });
|
|
21244
21560
|
return {
|
|
21245
21561
|
data: messages.find(message => message.messageId === messageId),
|
|
21246
21562
|
cachedAt,
|
|
@@ -21297,8 +21613,10 @@ const getMessages = async (messageIds) => {
|
|
|
21297
21613
|
const cachedAt = client.cache && Date.now();
|
|
21298
21614
|
if (client.cache)
|
|
21299
21615
|
ingestInCache(data, { cachedAt });
|
|
21616
|
+
const { messages } = data;
|
|
21617
|
+
fireEvent('v3.message.didFetch', { messages });
|
|
21300
21618
|
return {
|
|
21301
|
-
data:
|
|
21619
|
+
data: messages,
|
|
21302
21620
|
cachedAt,
|
|
21303
21621
|
};
|
|
21304
21622
|
};
|
|
@@ -21375,6 +21693,7 @@ const queryMessages = async (query) => {
|
|
|
21375
21693
|
];
|
|
21376
21694
|
pushToCache(cacheKey, { messages: messages.map(getResolver('message')), paging });
|
|
21377
21695
|
}
|
|
21696
|
+
fireEvent('v3.message.didFetch', { messages });
|
|
21378
21697
|
const nextPage = toPage(paging.next);
|
|
21379
21698
|
const prevPage = toPage(paging.previous);
|
|
21380
21699
|
return { data: messages, cachedAt, prevPage, nextPage };
|
|
@@ -21440,8 +21759,8 @@ const createMessage = async (bundle) => {
|
|
|
21440
21759
|
const cachedAt = client.cache && Date.now();
|
|
21441
21760
|
if (client.cache)
|
|
21442
21761
|
ingestInCache(data, { cachedAt });
|
|
21443
|
-
// no need for event, fired by server
|
|
21444
21762
|
const { messages } = data;
|
|
21763
|
+
fireEvent('v3.message.didCreate', { messages });
|
|
21445
21764
|
return {
|
|
21446
21765
|
data: messages[0],
|
|
21447
21766
|
cachedAt,
|
|
@@ -21483,11 +21802,12 @@ createMessage.optimistically = (bundle) => {
|
|
|
21483
21802
|
// as reused to update created and updated time, which should be the same
|
|
21484
21803
|
const createdTime = new Date().toISOString();
|
|
21485
21804
|
const message = Object.assign({ userId: client.userId, channelSegment: ((_b = channel === null || channel === void 0 ? void 0 : channel.data.messageCount) !== null && _b !== void 0 ? _b : 0) + 1, createdAt: createdTime, updatedAt: createdTime }, bundleWithMessageId);
|
|
21486
|
-
|
|
21805
|
+
const cachedAt = UNSYNCED_OBJECT_CACHED_AT_VALUE;
|
|
21806
|
+
pushToCache(['message', 'get', message.messageId], message, { cachedAt });
|
|
21487
21807
|
fireEvent('v3.message.didCreate', { messages: [message] });
|
|
21488
21808
|
return {
|
|
21809
|
+
cachedAt,
|
|
21489
21810
|
data: message,
|
|
21490
|
-
cachedAt: -1,
|
|
21491
21811
|
};
|
|
21492
21812
|
};
|
|
21493
21813
|
|
|
@@ -21516,6 +21836,7 @@ const updateMessage = async (messageId, patch) => {
|
|
|
21516
21836
|
if (client.cache)
|
|
21517
21837
|
ingestInCache(data, { cachedAt });
|
|
21518
21838
|
const { messages } = data;
|
|
21839
|
+
fireEvent('v3.message.didUpdate', { messages });
|
|
21519
21840
|
return {
|
|
21520
21841
|
data: messages.find(message => message.messageId === messageId),
|
|
21521
21842
|
cachedAt,
|
|
@@ -21575,7 +21896,7 @@ const deleteMessage = async (messageId) => {
|
|
|
21575
21896
|
// API-FIX: This endpoint has not been implemented yet.
|
|
21576
21897
|
await client.http.delete(`/api/v3/messages/${encodeURIComponent(messageId)}`);
|
|
21577
21898
|
const deleted = await getMessage(messageId);
|
|
21578
|
-
|
|
21899
|
+
fireEvent('v3.message.didDelete', { messages: [deleted.data] });
|
|
21579
21900
|
return deleted.data;
|
|
21580
21901
|
};
|
|
21581
21902
|
/**
|
|
@@ -21625,11 +21946,20 @@ const queryPosts = async (query) => {
|
|
|
21625
21946
|
const client = getActiveClient();
|
|
21626
21947
|
client.log('post/queryPosts', query);
|
|
21627
21948
|
const { page = { limit: 10 } } = query, params = __rest(query, ["page"]);
|
|
21949
|
+
const { dataTypes, matchingOnlyParentPost } = params;
|
|
21628
21950
|
// API-FIX: parameters should be querystring. (1)
|
|
21629
21951
|
// API-FIX: backend should answer Amity.Response (2)
|
|
21630
21952
|
// const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<Amity.PostPayload>>>(
|
|
21631
21953
|
const { data } = await client.http.get(`/api/v4/posts`, {
|
|
21632
|
-
params: Object.assign(Object.assign({}, params), {
|
|
21954
|
+
params: Object.assign(Object.assign({}, params), {
|
|
21955
|
+
/*
|
|
21956
|
+
* when creating post like image, file, video BE will create 2 posts
|
|
21957
|
+
* 1. parent post to store text with dataType=text
|
|
21958
|
+
* 2. child post to store dataTypes post data
|
|
21959
|
+
*
|
|
21960
|
+
* By default BE queries only parent post
|
|
21961
|
+
*/
|
|
21962
|
+
matchingOnlyParentPost: matchingOnlyParentPost !== null && matchingOnlyParentPost !== void 0 ? matchingOnlyParentPost : !(dataTypes === null || dataTypes === void 0 ? void 0 : dataTypes.length), options: {
|
|
21633
21963
|
token: toToken(page, 'afterbeforeraw'),
|
|
21634
21964
|
} }),
|
|
21635
21965
|
});
|
|
@@ -21762,6 +22092,7 @@ getPosts.locally = (postIds) => {
|
|
|
21762
22092
|
const getPost = async (postId) => {
|
|
21763
22093
|
const client = getActiveClient();
|
|
21764
22094
|
client.log('post/getPost', postId);
|
|
22095
|
+
isInTombstone('post', postId);
|
|
21765
22096
|
let data;
|
|
21766
22097
|
try {
|
|
21767
22098
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
@@ -21769,8 +22100,8 @@ const getPost = async (postId) => {
|
|
|
21769
22100
|
data = response.data;
|
|
21770
22101
|
}
|
|
21771
22102
|
catch (error) {
|
|
21772
|
-
if ((error === null || error === void 0 ? void 0 : error.code)
|
|
21773
|
-
|
|
22103
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
22104
|
+
pushToTombstone('post', postId);
|
|
21774
22105
|
}
|
|
21775
22106
|
throw error;
|
|
21776
22107
|
}
|
|
@@ -21880,6 +22211,33 @@ const updatePost = async (postId, patch) => {
|
|
|
21880
22211
|
};
|
|
21881
22212
|
};
|
|
21882
22213
|
|
|
22214
|
+
const getMatchPostSetting = (value) => {
|
|
22215
|
+
var _a;
|
|
22216
|
+
return (_a = Object.keys(CommunityPostSettingMaps).find(key => value.needApprovalOnPostCreation ===
|
|
22217
|
+
CommunityPostSettingMaps[key].needApprovalOnPostCreation &&
|
|
22218
|
+
value.onlyAdminCanPost === CommunityPostSettingMaps[key].onlyAdminCanPost)) !== null && _a !== void 0 ? _a : DefaultCommunityPostSetting;
|
|
22219
|
+
};
|
|
22220
|
+
/*
|
|
22221
|
+
* Unpack community payload by mapping payload field to postSetting value.
|
|
22222
|
+
*/
|
|
22223
|
+
const unpackCommunityPayload = (_a) => {
|
|
22224
|
+
var { communities } = _a, restPayload = __rest(_a, ["communities"]);
|
|
22225
|
+
return (Object.assign({ communities: communities.map((_a) => {
|
|
22226
|
+
var { needApprovalOnPostCreation, onlyAdminCanPost } = _a, restCommunityPayload = __rest(_a, ["needApprovalOnPostCreation", "onlyAdminCanPost"]);
|
|
22227
|
+
return (Object.assign({ postSetting: getMatchPostSetting({
|
|
22228
|
+
needApprovalOnPostCreation,
|
|
22229
|
+
onlyAdminCanPost,
|
|
22230
|
+
}) }, restCommunityPayload));
|
|
22231
|
+
}) }, restPayload));
|
|
22232
|
+
};
|
|
22233
|
+
/*
|
|
22234
|
+
* Repack community payload by mapping postSetting to the actual value.
|
|
22235
|
+
*/
|
|
22236
|
+
const packCommunityPayload = (_a) => {
|
|
22237
|
+
var { postSetting = undefined } = _a, restParam = __rest(_a, ["postSetting"]);
|
|
22238
|
+
return (Object.assign(Object.assign({}, restParam), (postSetting ? CommunityPostSettingMaps[postSetting] : undefined)));
|
|
22239
|
+
};
|
|
22240
|
+
|
|
21883
22241
|
/**
|
|
21884
22242
|
* ```js
|
|
21885
22243
|
* import { queryCommunities } from '@amityco/ts-sdk'
|
|
@@ -21909,10 +22267,11 @@ const queryCommunities = async (query) => {
|
|
|
21909
22267
|
} }),
|
|
21910
22268
|
});
|
|
21911
22269
|
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
21912
|
-
const
|
|
22270
|
+
const unpackedPayload = unpackCommunityPayload(payload);
|
|
22271
|
+
const { communities } = unpackedPayload;
|
|
21913
22272
|
const cachedAt = client.cache && Date.now();
|
|
21914
22273
|
if (client.cache) {
|
|
21915
|
-
ingestInCache(
|
|
22274
|
+
ingestInCache(unpackedPayload, { cachedAt });
|
|
21916
22275
|
const cacheKey = [
|
|
21917
22276
|
'community',
|
|
21918
22277
|
'query',
|
|
@@ -21961,9 +22320,10 @@ const getCommunities = async (communityIds) => {
|
|
|
21961
22320
|
const client = getActiveClient();
|
|
21962
22321
|
client.log('community/getCommunities', communityIds);
|
|
21963
22322
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
21964
|
-
const { data } = await client.http.get(`/api/v3/communities/list`, {
|
|
22323
|
+
const { data: payload } = await client.http.get(`/api/v3/communities/list`, {
|
|
21965
22324
|
params: { communityIds },
|
|
21966
22325
|
});
|
|
22326
|
+
const data = unpackCommunityPayload(payload);
|
|
21967
22327
|
const cachedAt = client.cache && Date.now();
|
|
21968
22328
|
if (client.cache)
|
|
21969
22329
|
ingestInCache(data, { cachedAt });
|
|
@@ -22022,7 +22382,8 @@ const getCommunity = async (communityId) => {
|
|
|
22022
22382
|
const client = getActiveClient();
|
|
22023
22383
|
client.log('community/getCommunity', communityId);
|
|
22024
22384
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
22025
|
-
const { data } = await client.http.get(`/api/v3/communities/${communityId}`);
|
|
22385
|
+
const { data: payload } = await client.http.get(`/api/v3/communities/${communityId}`);
|
|
22386
|
+
const data = unpackCommunityPayload(payload);
|
|
22026
22387
|
const cachedAt = client.cache && Date.now();
|
|
22027
22388
|
if (client.cache)
|
|
22028
22389
|
ingestInCache(data, { cachedAt });
|
|
@@ -22076,7 +22437,8 @@ getCommunity.locally = (communityId) => {
|
|
|
22076
22437
|
const createCommunity = async (bundle) => {
|
|
22077
22438
|
const client = getActiveClient();
|
|
22078
22439
|
client.log('user/createCommunity', bundle);
|
|
22079
|
-
const { data } = await client.http.post('/api/v3/communities/', bundle);
|
|
22440
|
+
const { data: payload } = await client.http.post('/api/v3/communities/', packCommunityPayload(bundle));
|
|
22441
|
+
const data = unpackCommunityPayload(payload);
|
|
22080
22442
|
const cachedAt = client.cache && Date.now();
|
|
22081
22443
|
if (client.cache)
|
|
22082
22444
|
ingestInCache(data, { cachedAt });
|
|
@@ -22106,7 +22468,8 @@ const createCommunity = async (bundle) => {
|
|
|
22106
22468
|
const updateCommunity = async (communityId, patch) => {
|
|
22107
22469
|
const client = getActiveClient();
|
|
22108
22470
|
client.log('community/updateCommunity', communityId, patch);
|
|
22109
|
-
const { data } = await client.http.put(`/api/v3/communities/${communityId}`, patch);
|
|
22471
|
+
const { data: payload } = await client.http.put(`/api/v3/communities/${communityId}`, packCommunityPayload(patch));
|
|
22472
|
+
const data = unpackCommunityPayload(payload);
|
|
22110
22473
|
const cachedAt = client.cache && Date.now();
|
|
22111
22474
|
if (client.cache)
|
|
22112
22475
|
ingestInCache(data, { cachedAt });
|
|
@@ -22194,6 +22557,58 @@ const leaveCommunity = async (communityId) => {
|
|
|
22194
22557
|
return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership !== 'member');
|
|
22195
22558
|
};
|
|
22196
22559
|
|
|
22560
|
+
/**
|
|
22561
|
+
* Attach user object to membership model
|
|
22562
|
+
* - If cache is not enabled, set user to undefined ({..., user: undefined})
|
|
22563
|
+
* - If user object is not found in cache, set user to undefined
|
|
22564
|
+
* ({..., user: undefined})
|
|
22565
|
+
* - If a user is found in the cache, it attaches the user from the cache
|
|
22566
|
+
* ({..., user: { userId, displayName,... }})
|
|
22567
|
+
*
|
|
22568
|
+
* @param member The membership model object
|
|
22569
|
+
* @param userIdProp The user ID prop name of membership object
|
|
22570
|
+
* @param userProp The user prop name of destination object
|
|
22571
|
+
* @returns The membership model object that is already mapped to user
|
|
22572
|
+
* @hidden
|
|
22573
|
+
*/
|
|
22574
|
+
const withUser = (member, userIdProp = 'userId', userProp = 'user') => (Object.assign({ get [userProp]() {
|
|
22575
|
+
var _a;
|
|
22576
|
+
const client = getActiveClient();
|
|
22577
|
+
if (!client.cache)
|
|
22578
|
+
return undefined;
|
|
22579
|
+
const userCache = (_a = pullFromCache(['user', 'get', member[userIdProp]])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22580
|
+
if (!userCache) {
|
|
22581
|
+
return undefined;
|
|
22582
|
+
}
|
|
22583
|
+
return userCache;
|
|
22584
|
+
} }, member));
|
|
22585
|
+
/**
|
|
22586
|
+
* Mapping membership model with user object
|
|
22587
|
+
*
|
|
22588
|
+
* @param members The membership model objects
|
|
22589
|
+
* @param userIdProp The user ID prop name of membership object
|
|
22590
|
+
* @param userProp The user prop name of destination object
|
|
22591
|
+
* @returns The membership model objects that is already
|
|
22592
|
+
* mapped to users
|
|
22593
|
+
* @hidden
|
|
22594
|
+
*/
|
|
22595
|
+
const withUsers = (members, userIdProp = 'userId', userProp = 'user') => members.map(member => withUser(member, userIdProp, userProp));
|
|
22596
|
+
/**
|
|
22597
|
+
* Transform members prop in any payload with attached users members
|
|
22598
|
+
*
|
|
22599
|
+
* @param payload The payload contain members prop
|
|
22600
|
+
* @param memberProp A name of members prop
|
|
22601
|
+
* @param userIdProp The user ID prop name of membership object
|
|
22602
|
+
* @param userProp The user prop name of destination object
|
|
22603
|
+
* @returns The transforming payload
|
|
22604
|
+
* @hidden
|
|
22605
|
+
*/
|
|
22606
|
+
const prepareMembershipPayload = (payload, memberProp, userIdProp = 'userId', userProp = 'user') => {
|
|
22607
|
+
const _a = payload, _b = memberProp, memberPayload = _a[_b], rest = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
|
|
22608
|
+
const members = withUsers(memberPayload, userIdProp, userProp);
|
|
22609
|
+
return Object.assign(Object.assign({}, rest), { [memberProp]: members });
|
|
22610
|
+
};
|
|
22611
|
+
|
|
22197
22612
|
/**
|
|
22198
22613
|
* ```js
|
|
22199
22614
|
* import { queryCommunityMembers } from '@amityco/ts-sdk'
|
|
@@ -22211,17 +22626,27 @@ const leaveCommunity = async (communityId) => {
|
|
|
22211
22626
|
const queryCommunityMembers = async (query) => {
|
|
22212
22627
|
const client = getActiveClient();
|
|
22213
22628
|
client.log('community/queryCommunityMembers', query);
|
|
22214
|
-
const _a = query !== null && query !== void 0 ? query : {}, { page
|
|
22215
|
-
const { data } = await client.http.get(`/api/v3/communities/${communityId}/users`, {
|
|
22629
|
+
const _a = query !== null && query !== void 0 ? query : {}, { page } = _a, params = __rest(_a, ["page"]);
|
|
22630
|
+
const { data: queryPayload } = await client.http.get(`/api/v3/communities/${params.communityId}/users`, {
|
|
22216
22631
|
params: Object.assign(Object.assign({}, params), { options: {
|
|
22217
22632
|
token: toToken(page, 'skiplimit'),
|
|
22218
22633
|
} }),
|
|
22219
22634
|
});
|
|
22220
|
-
const { paging } =
|
|
22221
|
-
const
|
|
22635
|
+
const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
|
|
22636
|
+
const preparedPayload = prepareMembershipPayload(payload, 'communityUsers');
|
|
22637
|
+
const { communityUsers } = preparedPayload;
|
|
22222
22638
|
const cachedAt = client.cache && Date.now();
|
|
22223
22639
|
if (client.cache) {
|
|
22224
|
-
ingestInCache(
|
|
22640
|
+
ingestInCache(preparedPayload, { cachedAt });
|
|
22641
|
+
const cacheKey = [
|
|
22642
|
+
'communityUsers',
|
|
22643
|
+
'query',
|
|
22644
|
+
Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
|
|
22645
|
+
];
|
|
22646
|
+
pushToCache(cacheKey, {
|
|
22647
|
+
communityUsers: communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
|
|
22648
|
+
paging,
|
|
22649
|
+
});
|
|
22225
22650
|
}
|
|
22226
22651
|
const nextPage = toPage(paging.next);
|
|
22227
22652
|
const prevPage = toPage(paging.previous);
|
|
@@ -22241,9 +22666,29 @@ const queryCommunityMembers = async (query) => {
|
|
|
22241
22666
|
* @category Post API
|
|
22242
22667
|
*/
|
|
22243
22668
|
queryCommunityMembers.locally = (query) => {
|
|
22669
|
+
var _a, _b;
|
|
22244
22670
|
const client = getActiveClient();
|
|
22245
22671
|
client.log('community/queryCommunityMembers', query);
|
|
22246
|
-
|
|
22672
|
+
if (!client.cache)
|
|
22673
|
+
return;
|
|
22674
|
+
const _c = query !== null && query !== void 0 ? query : {}, { page } = _c, params = __rest(_c, ["page"]);
|
|
22675
|
+
const cacheKey = [
|
|
22676
|
+
'communityUsers',
|
|
22677
|
+
'query',
|
|
22678
|
+
Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
|
|
22679
|
+
];
|
|
22680
|
+
const { data, cachedAt } = (_a = pullFromCache(cacheKey)) !== null && _a !== void 0 ? _a : {};
|
|
22681
|
+
if (!(data === null || data === void 0 ? void 0 : data.communityUsers.length))
|
|
22682
|
+
return;
|
|
22683
|
+
const communityUsers = data.communityUsers
|
|
22684
|
+
.map(key => pullFromCache(['communityUsers', 'get', key]))
|
|
22685
|
+
.filter(Boolean)
|
|
22686
|
+
.map(({ data }) => data);
|
|
22687
|
+
const prevPage = toPage(data === null || data === void 0 ? void 0 : data.paging.previous);
|
|
22688
|
+
const nextPage = toPage(data === null || data === void 0 ? void 0 : data.paging.next);
|
|
22689
|
+
return communityUsers.length === ((_b = data === null || data === void 0 ? void 0 : data.communityUsers) === null || _b === void 0 ? void 0 : _b.length)
|
|
22690
|
+
? { data: communityUsers, cachedAt, prevPage, nextPage }
|
|
22691
|
+
: undefined;
|
|
22247
22692
|
};
|
|
22248
22693
|
|
|
22249
22694
|
/**
|
|
@@ -22372,7 +22817,8 @@ const getTopTrendingCommunities = async (query) => {
|
|
|
22372
22817
|
const { limit = 5 } = query !== null && query !== void 0 ? query : {};
|
|
22373
22818
|
// API-FIX: backend doesnt answer Amity.Response
|
|
22374
22819
|
// const { data } = await client.http.get<Amity.Response<CommunityPayload>>(
|
|
22375
|
-
const { data } = await client.http.get(`/api/v3/communities/top-trending`, { params: { options: { limit } } });
|
|
22820
|
+
const { data: payload } = await client.http.get(`/api/v3/communities/top-trending`, { params: { options: { limit } } });
|
|
22821
|
+
const data = unpackCommunityPayload(payload);
|
|
22376
22822
|
const { communities } = data;
|
|
22377
22823
|
const cachedAt = client.cache && Date.now();
|
|
22378
22824
|
if (client.cache) {
|
|
@@ -22434,8 +22880,9 @@ const getRecommendedCommunities = async (query) => {
|
|
|
22434
22880
|
client.log('channel/getRecommendedCommunities', query);
|
|
22435
22881
|
const { limit = 5 } = query !== null && query !== void 0 ? query : {};
|
|
22436
22882
|
// API-FIX: backend doesnt answer Amity.Response
|
|
22437
|
-
// const { data } = await client.http.get<Amity.Response<CommunityPayload>>(
|
|
22438
|
-
const { data } = await client.http.get(`/api/v3/communities/recommended`, { params: { options: { limit } } });
|
|
22883
|
+
// const { data: payload } = await client.http.get<Amity.Response<CommunityPayload>>(
|
|
22884
|
+
const { data: payload } = await client.http.get(`/api/v3/communities/recommended`, { params: { options: { limit } } });
|
|
22885
|
+
const data = unpackCommunityPayload(payload);
|
|
22439
22886
|
const { communities } = data;
|
|
22440
22887
|
const cachedAt = client.cache && Date.now();
|
|
22441
22888
|
if (client.cache) {
|
|
@@ -22516,7 +22963,7 @@ const deletePost = async (postId, permanent = false) => {
|
|
|
22516
22963
|
fireEvent('post.deleted', { posts: [deleted] });
|
|
22517
22964
|
if (permanent) {
|
|
22518
22965
|
setTimeout(() => {
|
|
22519
|
-
|
|
22966
|
+
pushToTombstone('post', postId);
|
|
22520
22967
|
}, 0);
|
|
22521
22968
|
}
|
|
22522
22969
|
else {
|
|
@@ -22912,17 +23359,6 @@ const deleteComment = async (commentId, permanent = false) => {
|
|
|
22912
23359
|
return deleted;
|
|
22913
23360
|
};
|
|
22914
23361
|
|
|
22915
|
-
/** @hidden */
|
|
22916
|
-
const fetchReference = async (referenceType, referenceId) => {
|
|
22917
|
-
if (referenceType === 'message')
|
|
22918
|
-
return getMessage(referenceId);
|
|
22919
|
-
if (referenceType === 'post')
|
|
22920
|
-
return getPost(referenceId);
|
|
22921
|
-
if (referenceType === 'comment')
|
|
22922
|
-
return getComment(referenceId);
|
|
22923
|
-
throw new Error(`Incorrect referenceType: ${referenceType}`);
|
|
22924
|
-
};
|
|
22925
|
-
|
|
22926
23362
|
/** @hidden */
|
|
22927
23363
|
const preparePayloadForCache = (event, payload) => {
|
|
22928
23364
|
var _a, _b;
|
|
@@ -23010,7 +23446,6 @@ const prepareMessagePayloadForCache = (payload) => {
|
|
|
23010
23446
|
* @async
|
|
23011
23447
|
* */
|
|
23012
23448
|
const addReaction = async (referenceType, referenceId, reactionName) => {
|
|
23013
|
-
var _a, _b;
|
|
23014
23449
|
const client = getActiveClient();
|
|
23015
23450
|
client.log('reaction/createReaction', {
|
|
23016
23451
|
referenceId,
|
|
@@ -23022,9 +23457,16 @@ const addReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
23022
23457
|
referenceType,
|
|
23023
23458
|
reactionName,
|
|
23024
23459
|
});
|
|
23025
|
-
|
|
23026
|
-
|
|
23027
|
-
|
|
23460
|
+
if (client.cache) {
|
|
23461
|
+
const model = pullFromCache([
|
|
23462
|
+
referenceType,
|
|
23463
|
+
'get',
|
|
23464
|
+
referenceId,
|
|
23465
|
+
]);
|
|
23466
|
+
(model === null || model === void 0 ? void 0 : model.data) &&
|
|
23467
|
+
pushToCache([referenceType, 'get', referenceId], model.data, { cachedAt: Date.now() });
|
|
23468
|
+
}
|
|
23469
|
+
return true;
|
|
23028
23470
|
};
|
|
23029
23471
|
/**
|
|
23030
23472
|
* ```js
|
|
@@ -23059,7 +23501,9 @@ addReaction.optimistically = (referenceType, referenceId, reactionName) => {
|
|
|
23059
23501
|
if (!(model === null || model === void 0 ? void 0 : model.data) || ((_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName)))
|
|
23060
23502
|
return;
|
|
23061
23503
|
const reaction = Object.assign(Object.assign({}, model.data), { reactionsCount: model.data.reactionsCount + 1, myReactions: [...((_b = model.data.myReactions) !== null && _b !== void 0 ? _b : []), reactionName], reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: ((_c = model.data.reactions[reactionName]) !== null && _c !== void 0 ? _c : 0) + 1 }) });
|
|
23062
|
-
upsertInCache([referenceType, 'get', referenceId], reaction, {
|
|
23504
|
+
upsertInCache([referenceType, 'get', referenceId], reaction, {
|
|
23505
|
+
cachedAt: UNSYNCED_OBJECT_CACHED_AT_VALUE,
|
|
23506
|
+
});
|
|
23063
23507
|
dispatchReactable(referenceType, reaction);
|
|
23064
23508
|
return (_e = (_d = reaction === null || reaction === void 0 ? void 0 : reaction.myReactions) === null || _d === void 0 ? void 0 : _d.includes(reactionName)) !== null && _e !== void 0 ? _e : false;
|
|
23065
23509
|
};
|
|
@@ -23081,7 +23525,6 @@ addReaction.optimistically = (referenceType, referenceId, reactionName) => {
|
|
|
23081
23525
|
* @async
|
|
23082
23526
|
* */
|
|
23083
23527
|
const removeReaction = async (referenceType, referenceId, reactionName) => {
|
|
23084
|
-
var _a, _b;
|
|
23085
23528
|
const client = getActiveClient();
|
|
23086
23529
|
client.log('reaction/removeReaction', {
|
|
23087
23530
|
referenceId,
|
|
@@ -23091,9 +23534,16 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
23091
23534
|
await client.http.delete(`/api/v2/reactions`, {
|
|
23092
23535
|
data: { referenceId, referenceType, reactionName },
|
|
23093
23536
|
});
|
|
23094
|
-
|
|
23095
|
-
|
|
23096
|
-
|
|
23537
|
+
if (client.cache) {
|
|
23538
|
+
const model = pullFromCache([
|
|
23539
|
+
referenceType,
|
|
23540
|
+
'get',
|
|
23541
|
+
referenceId,
|
|
23542
|
+
]);
|
|
23543
|
+
(model === null || model === void 0 ? void 0 : model.data) &&
|
|
23544
|
+
pushToCache([referenceType, 'get', referenceId], model.data, { cachedAt: Date.now() });
|
|
23545
|
+
}
|
|
23546
|
+
return true;
|
|
23097
23547
|
};
|
|
23098
23548
|
/**
|
|
23099
23549
|
* ```js
|
|
@@ -23128,7 +23578,9 @@ removeReaction.optimistically = (referenceType, referenceId, reactionName) => {
|
|
|
23128
23578
|
if (!(model === null || model === void 0 ? void 0 : model.data) || !((_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName)))
|
|
23129
23579
|
return;
|
|
23130
23580
|
const reaction = Object.assign(Object.assign({}, model.data), { reactionsCount: Math.max(0, model.data.reactionsCount - 1), myReactions: ((_b = model.data.myReactions) !== null && _b !== void 0 ? _b : []).filter(item => item !== reactionName), reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: Math.max(0, ((_c = model.data.reactions[reactionName]) !== null && _c !== void 0 ? _c : 0) - 1) }) });
|
|
23131
|
-
upsertInCache([referenceType, 'get', referenceId], reaction, {
|
|
23581
|
+
upsertInCache([referenceType, 'get', referenceId], reaction, {
|
|
23582
|
+
cachedAt: UNSYNCED_OBJECT_CACHED_AT_VALUE,
|
|
23583
|
+
});
|
|
23132
23584
|
dispatchReactable(referenceType, reaction);
|
|
23133
23585
|
return (_e = !((_d = reaction === null || reaction === void 0 ? void 0 : reaction.myReactions) === null || _d === void 0 ? void 0 : _d.includes(reactionName))) !== null && _e !== void 0 ? _e : false;
|
|
23134
23586
|
};
|
|
@@ -23770,9 +24222,6 @@ const onReactorRemoved = (referenceType, referenceId, callback) => {
|
|
|
23770
24222
|
return createEventSubscriber(client, 'comment.removeReaction', 'comment.removeReaction', filter);
|
|
23771
24223
|
};
|
|
23772
24224
|
|
|
23773
|
-
const COLLECTION_DEFAULT_PAGINATION_LIMIT = 5;
|
|
23774
|
-
const COLLECTION_DEFAULT_CACHING_POLICY = 'cache_then_server';
|
|
23775
|
-
|
|
23776
24225
|
/**
|
|
23777
24226
|
* ```js
|
|
23778
24227
|
* import { liveReactions } from '@amityco/ts-sdk'
|
|
@@ -23973,6 +24422,23 @@ const isReportedByMe = async (referenceType, referenceId) => {
|
|
|
23973
24422
|
return (_b = result !== null && result !== void 0 ? result : isFlagByMe) !== null && _b !== void 0 ? _b : false;
|
|
23974
24423
|
};
|
|
23975
24424
|
|
|
24425
|
+
/** @hidden */
|
|
24426
|
+
const prepareChannelPayload = (payload) => {
|
|
24427
|
+
const client = getActiveClient();
|
|
24428
|
+
const channels = payload.channels.map(channel => {
|
|
24429
|
+
const channelUser = payload.channelUsers.find(channelUser => channelUser.userId === client.userId && channel.channelId === channelUser.channelId);
|
|
24430
|
+
const hasMention = channelUser
|
|
24431
|
+
? channelUser.readToSegment < channelUser.lastMentionedSegment
|
|
24432
|
+
: false;
|
|
24433
|
+
const unreadCount = channelUser && channelUser.membership === 'member' && channel.messageCount
|
|
24434
|
+
? Math.max(0, channel.messageCount - channelUser.readToSegment)
|
|
24435
|
+
: 0;
|
|
24436
|
+
return Object.assign(Object.assign({}, channel), { hasMention,
|
|
24437
|
+
unreadCount });
|
|
24438
|
+
});
|
|
24439
|
+
return Object.assign(Object.assign({}, payload), { channels });
|
|
24440
|
+
};
|
|
24441
|
+
|
|
23976
24442
|
/**
|
|
23977
24443
|
* ```js
|
|
23978
24444
|
* import { queryChannels } from '@amityco/ts-sdk'
|
|
@@ -23996,16 +24462,17 @@ const queryChannels = async (query) => {
|
|
|
23996
24462
|
// API-FIX: parameters should be querystring.
|
|
23997
24463
|
// API-FIX: backend doesnt answer Amity.Response
|
|
23998
24464
|
// const { data } = await client.http.get<Amity.Response<Amity.Paged<ChannelPayload>>>(
|
|
23999
|
-
const { data } = await client.http.get(`/api/v3/channels`, {
|
|
24465
|
+
const { data: queryPayload } = await client.http.get(`/api/v3/channels`, {
|
|
24000
24466
|
params: Object.assign(Object.assign({}, params), { keyword: displayName, filter: membership, options: {
|
|
24001
24467
|
token: toToken(page, 'skiplimit'),
|
|
24002
24468
|
} }),
|
|
24003
24469
|
});
|
|
24004
|
-
const { paging } =
|
|
24005
|
-
const
|
|
24470
|
+
const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
|
|
24471
|
+
const data = prepareChannelPayload(payload);
|
|
24472
|
+
const { channels } = data;
|
|
24006
24473
|
const cachedAt = client.cache && Date.now();
|
|
24007
24474
|
if (client.cache) {
|
|
24008
|
-
ingestInCache(
|
|
24475
|
+
ingestInCache(data, { cachedAt });
|
|
24009
24476
|
const cacheKey = [
|
|
24010
24477
|
'channel',
|
|
24011
24478
|
'query',
|
|
@@ -24031,9 +24498,24 @@ const queryChannels = async (query) => {
|
|
|
24031
24498
|
* @category Channel API
|
|
24032
24499
|
*/
|
|
24033
24500
|
queryChannels.locally = (query) => {
|
|
24501
|
+
var _a, _b;
|
|
24034
24502
|
const client = getActiveClient();
|
|
24035
24503
|
client.log('channel/queryChannels.locally', query);
|
|
24036
|
-
|
|
24504
|
+
const _c = query !== null && query !== void 0 ? query : {}, { page = { limit: 10 } } = _c, params = __rest(_c, ["page"]);
|
|
24505
|
+
const cacheKey = ['channel', 'query', Object.assign(Object.assign({}, params), { options: Object.assign({}, page) })];
|
|
24506
|
+
const { data, cachedAt } = (_a = pullFromCache(cacheKey)) !== null && _a !== void 0 ? _a : {};
|
|
24507
|
+
if (!(data === null || data === void 0 ? void 0 : data.channels.length))
|
|
24508
|
+
return;
|
|
24509
|
+
const channels = data.channels
|
|
24510
|
+
// ck -> cacheKey, abbrevated to avoid confusion from the above cache key
|
|
24511
|
+
.map(ck => pullFromCache(['channel', 'get', ck]))
|
|
24512
|
+
.filter(Boolean)
|
|
24513
|
+
.map(({ data }) => data);
|
|
24514
|
+
const prevPage = toPage(data === null || data === void 0 ? void 0 : data.paging.previous);
|
|
24515
|
+
const nextPage = toPage(data === null || data === void 0 ? void 0 : data.paging.next);
|
|
24516
|
+
return channels.length === ((_b = data === null || data === void 0 ? void 0 : data.channels) === null || _b === void 0 ? void 0 : _b.length)
|
|
24517
|
+
? { data: channels, cachedAt, prevPage, nextPage }
|
|
24518
|
+
: undefined;
|
|
24037
24519
|
};
|
|
24038
24520
|
|
|
24039
24521
|
/**
|
|
@@ -24055,9 +24537,10 @@ const getChannels = async (channelIds) => {
|
|
|
24055
24537
|
client.log('channel/getChannels', channelIds);
|
|
24056
24538
|
const encodedChannelIds = channelIds.map(channelId => encodeURIComponent(channelId));
|
|
24057
24539
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
24058
|
-
const { data } = await client.http.get(`/api/v3/channels/list`, {
|
|
24540
|
+
const { data: payload } = await client.http.get(`/api/v3/channels/list`, {
|
|
24059
24541
|
params: { channelIds: encodedChannelIds },
|
|
24060
24542
|
});
|
|
24543
|
+
const data = prepareChannelPayload(payload);
|
|
24061
24544
|
const cachedAt = client.cache && Date.now();
|
|
24062
24545
|
if (client.cache)
|
|
24063
24546
|
ingestInCache(data, { cachedAt });
|
|
@@ -24115,8 +24598,18 @@ getChannels.locally = (channelIds) => {
|
|
|
24115
24598
|
const getChannel = async (channelId) => {
|
|
24116
24599
|
const client = getActiveClient();
|
|
24117
24600
|
client.log('channel/getChannel', channelId);
|
|
24118
|
-
|
|
24119
|
-
|
|
24601
|
+
isInTombstone('channel', channelId);
|
|
24602
|
+
let data;
|
|
24603
|
+
try {
|
|
24604
|
+
const { data: payload } = await client.http.get(`/api/v3/channels/${encodeURIComponent(channelId)}`);
|
|
24605
|
+
data = prepareChannelPayload(payload);
|
|
24606
|
+
}
|
|
24607
|
+
catch (error) {
|
|
24608
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
24609
|
+
pushToTombstone('channel', channelId);
|
|
24610
|
+
}
|
|
24611
|
+
throw error;
|
|
24612
|
+
}
|
|
24120
24613
|
const cachedAt = client.cache && Date.now();
|
|
24121
24614
|
if (client.cache)
|
|
24122
24615
|
ingestInCache(data, { cachedAt });
|
|
@@ -24177,10 +24670,11 @@ const createChannel = async (bundle) => {
|
|
|
24177
24670
|
else {
|
|
24178
24671
|
payload = await client.http.post('/api/v3/channels', bundle);
|
|
24179
24672
|
}
|
|
24673
|
+
const data = prepareChannelPayload(payload.data);
|
|
24180
24674
|
const cachedAt = client.cache && Date.now();
|
|
24181
24675
|
if (client.cache)
|
|
24182
|
-
ingestInCache(
|
|
24183
|
-
const { channels } =
|
|
24676
|
+
ingestInCache(data, { cachedAt });
|
|
24677
|
+
const { channels } = data;
|
|
24184
24678
|
return {
|
|
24185
24679
|
data: channels[0],
|
|
24186
24680
|
cachedAt,
|
|
@@ -24205,7 +24699,8 @@ const createChannel = async (bundle) => {
|
|
|
24205
24699
|
const updateChannel = async (channelId, patch) => {
|
|
24206
24700
|
const client = getActiveClient();
|
|
24207
24701
|
client.log('channel/updateChannel', channelId, patch);
|
|
24208
|
-
const { data } = await client.http.put(`/api/v3/channels/${encodeURIComponent(channelId)}`, patch);
|
|
24702
|
+
const { data: payload } = await client.http.put(`/api/v3/channels/${encodeURIComponent(channelId)}`, patch);
|
|
24703
|
+
const data = prepareChannelPayload(payload);
|
|
24209
24704
|
const cachedAt = client.cache && Date.now();
|
|
24210
24705
|
if (client.cache)
|
|
24211
24706
|
ingestInCache(data, { cachedAt });
|
|
@@ -24256,7 +24751,8 @@ const deleteChannel = async (channelId) => {
|
|
|
24256
24751
|
const joinChannel = async (channelId) => {
|
|
24257
24752
|
const client = getActiveClient();
|
|
24258
24753
|
client.log('channel/joinChannel', channelId);
|
|
24259
|
-
const { data } = await client.http.post(`/api/v3/channels/${encodeURIComponent(channelId)}/join`);
|
|
24754
|
+
const { data: payload } = await client.http.post(`/api/v3/channels/${encodeURIComponent(channelId)}/join`);
|
|
24755
|
+
const data = prepareChannelPayload(payload);
|
|
24260
24756
|
if (client.cache)
|
|
24261
24757
|
ingestInCache(data);
|
|
24262
24758
|
const { channelUsers } = data;
|
|
@@ -24280,7 +24776,8 @@ const joinChannel = async (channelId) => {
|
|
|
24280
24776
|
const leaveChannel = async (channelId) => {
|
|
24281
24777
|
const client = getActiveClient();
|
|
24282
24778
|
client.log('channel/leaveChannel', channelId);
|
|
24283
|
-
const { data } = await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}/leave`);
|
|
24779
|
+
const { data: payload } = await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}/leave`);
|
|
24780
|
+
const data = prepareChannelPayload(payload);
|
|
24284
24781
|
if (client.cache)
|
|
24285
24782
|
ingestInCache(data);
|
|
24286
24783
|
const { channelUsers } = data;
|
|
@@ -24304,21 +24801,37 @@ const leaveChannel = async (channelId) => {
|
|
|
24304
24801
|
const queryChannelMembers = async (query) => {
|
|
24305
24802
|
const client = getActiveClient();
|
|
24306
24803
|
client.log('channel/queryChannelMembers', query);
|
|
24307
|
-
const _a = query !== null && query !== void 0 ? query : {}, { page
|
|
24308
|
-
const { data } = await client.http.get(`/api/v4/channels/${encodeURIComponent(channelId)}/users`, {
|
|
24804
|
+
const _a = query !== null && query !== void 0 ? query : {}, { page } = _a, params = __rest(_a, ["page"]);
|
|
24805
|
+
const { data: queryPayload } = await client.http.get(`/api/v4/channels/${encodeURIComponent(params.channelId)}/users`, {
|
|
24309
24806
|
params: Object.assign(Object.assign({}, params), { options: {
|
|
24310
24807
|
token: toToken(page, 'skiplimit'),
|
|
24311
24808
|
} }),
|
|
24312
24809
|
});
|
|
24313
|
-
const { paging } =
|
|
24314
|
-
const
|
|
24810
|
+
const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
|
|
24811
|
+
const channelPayload = prepareChannelPayload(payload);
|
|
24812
|
+
const preparedPayload = prepareMembershipPayload(channelPayload, 'channelUsers');
|
|
24813
|
+
const { channelUsers } = preparedPayload;
|
|
24315
24814
|
const cachedAt = client.cache && Date.now();
|
|
24316
24815
|
if (client.cache) {
|
|
24317
|
-
ingestInCache(
|
|
24816
|
+
ingestInCache(preparedPayload);
|
|
24817
|
+
const cacheKey = [
|
|
24818
|
+
'channelUsers',
|
|
24819
|
+
'query',
|
|
24820
|
+
Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
|
|
24821
|
+
];
|
|
24822
|
+
pushToCache(cacheKey, {
|
|
24823
|
+
channelUsers: channelUsers.map(({ channelId, userId }) => getResolver('channelUsers')({ channelId, userId })),
|
|
24824
|
+
paging,
|
|
24825
|
+
});
|
|
24318
24826
|
}
|
|
24319
24827
|
const nextPage = toPage(paging.next);
|
|
24320
24828
|
const prevPage = toPage(paging.previous);
|
|
24321
|
-
return {
|
|
24829
|
+
return {
|
|
24830
|
+
data: channelUsers,
|
|
24831
|
+
cachedAt,
|
|
24832
|
+
nextPage,
|
|
24833
|
+
prevPage,
|
|
24834
|
+
};
|
|
24322
24835
|
};
|
|
24323
24836
|
/**
|
|
24324
24837
|
* ```js
|
|
@@ -24334,9 +24847,30 @@ const queryChannelMembers = async (query) => {
|
|
|
24334
24847
|
* @category Post API
|
|
24335
24848
|
*/
|
|
24336
24849
|
queryChannelMembers.locally = (query) => {
|
|
24850
|
+
var _a, _b;
|
|
24337
24851
|
const client = getActiveClient();
|
|
24338
|
-
client.log('channel/queryChannelMembers', query);
|
|
24339
|
-
|
|
24852
|
+
client.log('channel/queryChannelMembers.locally', query);
|
|
24853
|
+
if (!client.cache)
|
|
24854
|
+
return;
|
|
24855
|
+
const { page } = query, params = __rest(query, ["page"]);
|
|
24856
|
+
const cacheKey = [
|
|
24857
|
+
'channelUsers',
|
|
24858
|
+
'query',
|
|
24859
|
+
Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
|
|
24860
|
+
];
|
|
24861
|
+
const { data, cachedAt } = (_a = pullFromCache(cacheKey)) !== null && _a !== void 0 ? _a : {};
|
|
24862
|
+
if (!(data === null || data === void 0 ? void 0 : data.channelUsers.length))
|
|
24863
|
+
return;
|
|
24864
|
+
const channelUsers = data.channelUsers
|
|
24865
|
+
// ck -> cacheKey, abbrevated to avoid confusion from the above cache key
|
|
24866
|
+
.map(ck => pullFromCache(['channelUsers', 'get', ck]))
|
|
24867
|
+
.filter(Boolean)
|
|
24868
|
+
.map(({ data }) => data);
|
|
24869
|
+
const prevPage = toPage(data === null || data === void 0 ? void 0 : data.paging.previous);
|
|
24870
|
+
const nextPage = toPage(data === null || data === void 0 ? void 0 : data.paging.next);
|
|
24871
|
+
return channelUsers.length === ((_b = data === null || data === void 0 ? void 0 : data.channelUsers) === null || _b === void 0 ? void 0 : _b.length)
|
|
24872
|
+
? { data: channelUsers, cachedAt, prevPage, nextPage }
|
|
24873
|
+
: undefined;
|
|
24340
24874
|
};
|
|
24341
24875
|
|
|
24342
24876
|
/**
|
|
@@ -24357,13 +24891,14 @@ queryChannelMembers.locally = (query) => {
|
|
|
24357
24891
|
const addChannelMembers = async (channelId, userIds) => {
|
|
24358
24892
|
const client = getActiveClient();
|
|
24359
24893
|
client.log('channel/addChannelMembers', channelId, userIds);
|
|
24360
|
-
const { data } = await client.http.post(`/api/v3/channels/${encodeURIComponent(channelId)}/users`, { channelId, userIds });
|
|
24894
|
+
const { data: payload } = await client.http.post(`/api/v3/channels/${encodeURIComponent(channelId)}/users`, { channelId, userIds });
|
|
24895
|
+
const data = prepareChannelPayload(payload);
|
|
24361
24896
|
if (client.cache)
|
|
24362
24897
|
ingestInCache(data);
|
|
24363
|
-
|
|
24364
|
-
|
|
24365
|
-
|
|
24366
|
-
});
|
|
24898
|
+
/*
|
|
24899
|
+
* should fire event for each user that was added
|
|
24900
|
+
*/
|
|
24901
|
+
userIds.forEach(id => fireEvent('v3.channel.didAddUsers', Object.assign(Object.assign({}, data), { channelUsers: data.channelUsers.filter(u => u.userId === id) })));
|
|
24367
24902
|
const { channelUsers } = data;
|
|
24368
24903
|
return !!channelUsers.find(channelUser => channelUser.channelId === channelId && channelUser.membership === 'member');
|
|
24369
24904
|
};
|
|
@@ -24386,13 +24921,14 @@ const addChannelMembers = async (channelId, userIds) => {
|
|
|
24386
24921
|
const removeChannelMembers = async (channelId, userIds) => {
|
|
24387
24922
|
const client = getActiveClient();
|
|
24388
24923
|
client.log('channel/removeChannelMembers', channelId, userIds);
|
|
24389
|
-
const { data } = await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}/users`, { data: { channelId, userIds } });
|
|
24924
|
+
const { data: payload } = await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}/users`, { data: { channelId, userIds } });
|
|
24925
|
+
const data = prepareChannelPayload(payload);
|
|
24390
24926
|
if (client.cache)
|
|
24391
24927
|
ingestInCache(data);
|
|
24392
|
-
|
|
24393
|
-
|
|
24394
|
-
|
|
24395
|
-
});
|
|
24928
|
+
/*
|
|
24929
|
+
* should fire event for each user that was removed
|
|
24930
|
+
*/
|
|
24931
|
+
userIds.forEach(id => fireEvent('v3.channel.didRemoveUsers', Object.assign(Object.assign({}, data), { channelUsers: data.channelUsers.filter(u => u.userId === id) })));
|
|
24396
24932
|
const { channelUsers } = data;
|
|
24397
24933
|
return !!channelUsers.find(channelUser => channelUser.channelId === channelId && channelUser.membership !== 'member');
|
|
24398
24934
|
};
|
|
@@ -24416,7 +24952,8 @@ const removeChannelMembers = async (channelId, userIds) => {
|
|
|
24416
24952
|
const addChannelMembersRole = async (channelId, roleId, userIds) => {
|
|
24417
24953
|
const client = getActiveClient();
|
|
24418
24954
|
client.log('channel/addChannelMembersRole', channelId, roleId, userIds);
|
|
24419
|
-
const { data } = await client.http.post(`/api/v3/channels/${encodeURIComponent(channelId)}/users/roles`, { channelId, role: roleId, userIds });
|
|
24955
|
+
const { data: payload } = await client.http.post(`/api/v3/channels/${encodeURIComponent(channelId)}/users/roles`, { channelId, role: roleId, userIds });
|
|
24956
|
+
const data = prepareChannelPayload(payload);
|
|
24420
24957
|
if (client.cache)
|
|
24421
24958
|
ingestInCache(data);
|
|
24422
24959
|
const { channelUsers } = data;
|
|
@@ -24442,7 +24979,8 @@ const addChannelMembersRole = async (channelId, roleId, userIds) => {
|
|
|
24442
24979
|
const removeChannelMembersRole = async (channelId, roleId, userIds) => {
|
|
24443
24980
|
const client = getActiveClient();
|
|
24444
24981
|
client.log('channel/removeChannelMembersRole', channelId, roleId, userIds);
|
|
24445
|
-
const { data } = await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}/users/roles`, { data: { channelId, role: roleId, userIds } });
|
|
24982
|
+
const { data: payload } = await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}/users/roles`, { data: { channelId, role: roleId, userIds } });
|
|
24983
|
+
const data = prepareChannelPayload(payload);
|
|
24446
24984
|
if (client.cache)
|
|
24447
24985
|
ingestInCache(data);
|
|
24448
24986
|
const { channelUsers } = data;
|
|
@@ -24456,57 +24994,150 @@ const removeChannelMembersRole = async (channelId, roleId, userIds) => {
|
|
|
24456
24994
|
* await banChannelMembers('channel-id-1', ['userId1', 'userId2'])
|
|
24457
24995
|
* ```
|
|
24458
24996
|
*
|
|
24459
|
-
* @param channelId of {@link Amity.Channel} from which the users should be banned
|
|
24460
|
-
* @param userIds of the {@link Amity.User}'s to be banned
|
|
24461
|
-
* @returns the updated {@link Amity.Membership}'s object
|
|
24997
|
+
* @param channelId of {@link Amity.Channel} from which the users should be banned
|
|
24998
|
+
* @param userIds of the {@link Amity.User}'s to be banned
|
|
24999
|
+
* @returns the updated {@link Amity.Membership}'s object
|
|
25000
|
+
*
|
|
25001
|
+
* @category Channel API
|
|
25002
|
+
* @async
|
|
25003
|
+
* */
|
|
25004
|
+
const banChannelMembers = async (channelId, userIds) => {
|
|
25005
|
+
const client = getActiveClient();
|
|
25006
|
+
client.log('channel/banChannelMembers', { userIds, channelId });
|
|
25007
|
+
const { data: payload } = await client.http.put(`/api/v3/channels/${channelId}/users/ban`, {
|
|
25008
|
+
userIds,
|
|
25009
|
+
});
|
|
25010
|
+
const channelPayload = prepareChannelPayload(payload);
|
|
25011
|
+
const preparedPayload = prepareMembershipPayload(channelPayload, 'channelUsers');
|
|
25012
|
+
const { channelUsers } = preparedPayload;
|
|
25013
|
+
const cachedAt = client.cache && Date.now();
|
|
25014
|
+
if (client.cache)
|
|
25015
|
+
ingestInCache(preparedPayload, { cachedAt });
|
|
25016
|
+
return {
|
|
25017
|
+
data: channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(user => user.membership === 'banned'),
|
|
25018
|
+
cachedAt,
|
|
25019
|
+
};
|
|
25020
|
+
};
|
|
25021
|
+
|
|
25022
|
+
/**
|
|
25023
|
+
* ```js
|
|
25024
|
+
* import { unbanChannelMembers } from '@amityco/ts-sdk'
|
|
25025
|
+
*
|
|
25026
|
+
* await unbanChannelMembers('channel-id-1', ['userId1', 'userId2'])
|
|
25027
|
+
* ```
|
|
25028
|
+
*
|
|
25029
|
+
* @param channelId of {@link Amity.Channel} where the users should be unbanned
|
|
25030
|
+
* @param userIds of the {@link Amity.User}'s to be unbanned
|
|
25031
|
+
* @returns the updated {@link Amity.Membership}'s object
|
|
25032
|
+
*
|
|
25033
|
+
* @category Channel API
|
|
25034
|
+
* @async
|
|
25035
|
+
* */
|
|
25036
|
+
const unbanChannelMembers = async (channelId, userIds) => {
|
|
25037
|
+
const client = getActiveClient();
|
|
25038
|
+
client.log('channel/unbanChannelMembers', { userIds, channelId });
|
|
25039
|
+
const { data: payload } = await client.http.put(`/api/v3/channels/${encodeURIComponent(channelId)}/users/unban`, {
|
|
25040
|
+
userIds,
|
|
25041
|
+
});
|
|
25042
|
+
const channelPayload = prepareChannelPayload(payload);
|
|
25043
|
+
const preparedPayload = prepareMembershipPayload(channelPayload, 'channelUsers');
|
|
25044
|
+
const cachedAt = client.cache && Date.now();
|
|
25045
|
+
if (client.cache)
|
|
25046
|
+
ingestInCache(preparedPayload, { cachedAt });
|
|
25047
|
+
const { channelUsers } = preparedPayload;
|
|
25048
|
+
return {
|
|
25049
|
+
data: channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(user => user.membership === 'member'),
|
|
25050
|
+
cachedAt,
|
|
25051
|
+
};
|
|
25052
|
+
};
|
|
25053
|
+
|
|
25054
|
+
/**
|
|
25055
|
+
* ```js
|
|
25056
|
+
* import { startReading } from '@amityco/ts-sdk'
|
|
25057
|
+
* const success = await startReading('foo')
|
|
25058
|
+
* ```
|
|
25059
|
+
*
|
|
25060
|
+
* Mark all messages as read and start reading message inside channel
|
|
25061
|
+
*
|
|
25062
|
+
* @param {string} channelId - The channel ID to start reading.
|
|
25063
|
+
* @param {string} userId - The user ID of channel member.
|
|
25064
|
+
* @return {Promise<boolean>>} A success boolean if the channel reading of the channel had begun.
|
|
25065
|
+
*
|
|
25066
|
+
* @category Message API
|
|
25067
|
+
* @async
|
|
25068
|
+
*/
|
|
25069
|
+
const startReading = async (channelId, userId = getActiveClient().userId) => {
|
|
25070
|
+
const client = getActiveClient();
|
|
25071
|
+
client.log('message/startReading', { channelId });
|
|
25072
|
+
const result = await synchronousWSCall(client, 'channel.startReading', {
|
|
25073
|
+
channelId,
|
|
25074
|
+
});
|
|
25075
|
+
// TODO: Implement optimistic update for `readyToSegment`
|
|
25076
|
+
// const cachedChannel = pullFromCache<Amity.Channel>(['channel', 'get', channelId]);
|
|
25077
|
+
// const cachedMember = pullFromCache<Amity.Membership<'channel'>>(['channelUsers', 'get', userId]);
|
|
25078
|
+
//
|
|
25079
|
+
// if (cachedChannel && cachedMember) {
|
|
25080
|
+
// fireEvent('v3.channel.didMarkSeen', {
|
|
25081
|
+
// channelUsers: [
|
|
25082
|
+
// {
|
|
25083
|
+
// ...cachedMember.data,
|
|
25084
|
+
// readToSegment: cachedChannel.data.messageCount ?? 0,
|
|
25085
|
+
// },
|
|
25086
|
+
// ],
|
|
25087
|
+
// channels: [],
|
|
25088
|
+
// users: [],
|
|
25089
|
+
// files: [],
|
|
25090
|
+
// });
|
|
25091
|
+
// }
|
|
25092
|
+
return !!result;
|
|
25093
|
+
};
|
|
25094
|
+
|
|
25095
|
+
/**
|
|
25096
|
+
* ```js
|
|
25097
|
+
* import { stopReading } from '@amityco/ts-sdk'
|
|
25098
|
+
* const success = await stopReading('foo')
|
|
25099
|
+
* ```
|
|
25100
|
+
*
|
|
25101
|
+
* Stop reading message inside channel
|
|
25102
|
+
*
|
|
25103
|
+
* @param {string} channelId - The channel ID to stop reading.
|
|
25104
|
+
* @return {Promise<boolean>>} A success boolean if the channel reading was halted.
|
|
24462
25105
|
*
|
|
24463
|
-
* @category
|
|
25106
|
+
* @category Message API
|
|
24464
25107
|
* @async
|
|
24465
|
-
|
|
24466
|
-
const
|
|
25108
|
+
*/
|
|
25109
|
+
const stopReading = async (channelId) => {
|
|
24467
25110
|
const client = getActiveClient();
|
|
24468
|
-
client.log('
|
|
24469
|
-
const
|
|
24470
|
-
|
|
25111
|
+
client.log('message/stopReading', { channelId });
|
|
25112
|
+
const result = await synchronousWSCall(client, 'channel.stopReading', {
|
|
25113
|
+
channelId,
|
|
24471
25114
|
});
|
|
24472
|
-
|
|
24473
|
-
if (client.cache)
|
|
24474
|
-
ingestInCache(payload.data, { cachedAt });
|
|
24475
|
-
const { channelUsers } = payload.data;
|
|
24476
|
-
return {
|
|
24477
|
-
data: channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(user => user.membership === 'banned'),
|
|
24478
|
-
cachedAt,
|
|
24479
|
-
};
|
|
25115
|
+
return !!result;
|
|
24480
25116
|
};
|
|
24481
25117
|
|
|
24482
25118
|
/**
|
|
24483
25119
|
* ```js
|
|
24484
|
-
* import {
|
|
24485
|
-
*
|
|
24486
|
-
*
|
|
25120
|
+
* import { onChannelCreated } from '@amityco/ts-sdk'
|
|
25121
|
+
* const dispose = onChannelCreated(channel => {
|
|
25122
|
+
* // ...
|
|
25123
|
+
* })
|
|
24487
25124
|
* ```
|
|
24488
25125
|
*
|
|
24489
|
-
*
|
|
24490
|
-
* @param userIds of the {@link Amity.User}'s to be unbanned
|
|
24491
|
-
* @returns the updated {@link Amity.Membership}'s object
|
|
25126
|
+
* Fired when any {@link Amity.Channel} have been created
|
|
24492
25127
|
*
|
|
24493
|
-
* @
|
|
24494
|
-
* @
|
|
24495
|
-
*
|
|
24496
|
-
|
|
25128
|
+
* @param callback The function to call when the event was fired
|
|
25129
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
25130
|
+
*
|
|
25131
|
+
* @category Channel Events
|
|
25132
|
+
*/
|
|
25133
|
+
const onChannelCreated = (callback) => {
|
|
24497
25134
|
const client = getActiveClient();
|
|
24498
|
-
|
|
24499
|
-
|
|
24500
|
-
|
|
24501
|
-
|
|
24502
|
-
const cachedAt = client.cache && Date.now();
|
|
24503
|
-
if (client.cache)
|
|
24504
|
-
ingestInCache(payload.data, { cachedAt });
|
|
24505
|
-
const { channelUsers } = payload.data;
|
|
24506
|
-
return {
|
|
24507
|
-
data: channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(user => user.membership === 'member'),
|
|
24508
|
-
cachedAt,
|
|
25135
|
+
const filter = (payload) => {
|
|
25136
|
+
const data = prepareChannelPayload(payload);
|
|
25137
|
+
ingestInCache(data);
|
|
25138
|
+
callback(data.channels[0]);
|
|
24509
25139
|
};
|
|
25140
|
+
return createEventSubscriber(client, 'onChannelCreated', 'v3.channel.didCreate', filter);
|
|
24510
25141
|
};
|
|
24511
25142
|
|
|
24512
25143
|
/**
|
|
@@ -24527,8 +25158,9 @@ const unbanChannelMembers = async (channelId, userIds) => {
|
|
|
24527
25158
|
const onChannelUpdated = (callback) => {
|
|
24528
25159
|
const client = getActiveClient();
|
|
24529
25160
|
const filter = (payload) => {
|
|
24530
|
-
|
|
24531
|
-
|
|
25161
|
+
const data = prepareChannelPayload(payload);
|
|
25162
|
+
ingestInCache(data);
|
|
25163
|
+
callback(data.channels[0]);
|
|
24532
25164
|
};
|
|
24533
25165
|
return createEventSubscriber(client, 'onChannelUpdated', 'v3.channel.didUpdate', filter);
|
|
24534
25166
|
};
|
|
@@ -24551,8 +25183,9 @@ const onChannelUpdated = (callback) => {
|
|
|
24551
25183
|
const onChannelDeleted = (callback) => {
|
|
24552
25184
|
const client = getActiveClient();
|
|
24553
25185
|
const filter = (payload) => {
|
|
24554
|
-
|
|
24555
|
-
|
|
25186
|
+
const data = prepareChannelPayload(payload);
|
|
25187
|
+
ingestInCache(data);
|
|
25188
|
+
callback(data.channels[0]);
|
|
24556
25189
|
};
|
|
24557
25190
|
return createEventSubscriber(client, 'onChannelDeleted', 'v3.channel.didDelete', filter);
|
|
24558
25191
|
};
|
|
@@ -24575,8 +25208,9 @@ const onChannelDeleted = (callback) => {
|
|
|
24575
25208
|
const onChannelJoined = (callback) => {
|
|
24576
25209
|
const client = getActiveClient();
|
|
24577
25210
|
const filter = (payload) => {
|
|
24578
|
-
|
|
24579
|
-
|
|
25211
|
+
const data = prepareChannelPayload(payload);
|
|
25212
|
+
ingestInCache(data);
|
|
25213
|
+
callback(data.channels[0]);
|
|
24580
25214
|
};
|
|
24581
25215
|
return createEventSubscriber(client, 'onChannelJoined', 'v3.channel.didJoin', filter);
|
|
24582
25216
|
};
|
|
@@ -24599,8 +25233,9 @@ const onChannelJoined = (callback) => {
|
|
|
24599
25233
|
const onChannelLeft = (callback) => {
|
|
24600
25234
|
const client = getActiveClient();
|
|
24601
25235
|
const filter = (payload) => {
|
|
24602
|
-
|
|
24603
|
-
|
|
25236
|
+
const data = prepareChannelPayload(payload);
|
|
25237
|
+
ingestInCache(data);
|
|
25238
|
+
callback(data.channels[0]);
|
|
24604
25239
|
};
|
|
24605
25240
|
return createEventSubscriber(client, 'onChannelLeft', 'v3.channel.didLeave', filter);
|
|
24606
25241
|
};
|
|
@@ -24623,8 +25258,11 @@ const onChannelLeft = (callback) => {
|
|
|
24623
25258
|
const onChannelMemberAdded = (callback) => {
|
|
24624
25259
|
const client = getActiveClient();
|
|
24625
25260
|
const filter = (payload) => {
|
|
24626
|
-
|
|
24627
|
-
|
|
25261
|
+
const channelPayload = prepareChannelPayload(payload);
|
|
25262
|
+
const preparedPayload = prepareMembershipPayload(channelPayload, 'channelUsers');
|
|
25263
|
+
const { channels, channelUsers } = preparedPayload;
|
|
25264
|
+
ingestInCache(preparedPayload);
|
|
25265
|
+
callback(channels[0], channelUsers.find(cu => cu.membership === 'member'));
|
|
24628
25266
|
};
|
|
24629
25267
|
return createEventSubscriber(client, 'onChannelMemberAdded', 'v3.channel.didAddUsers', filter);
|
|
24630
25268
|
};
|
|
@@ -24647,12 +25285,95 @@ const onChannelMemberAdded = (callback) => {
|
|
|
24647
25285
|
const onChannelMemberRemoved = (callback) => {
|
|
24648
25286
|
const client = getActiveClient();
|
|
24649
25287
|
const filter = (payload) => {
|
|
24650
|
-
|
|
24651
|
-
|
|
25288
|
+
const channelPayload = prepareChannelPayload(payload);
|
|
25289
|
+
const preparedPayload = prepareMembershipPayload(channelPayload, 'channelUsers');
|
|
25290
|
+
const { channels, channelUsers } = preparedPayload;
|
|
25291
|
+
ingestInCache(preparedPayload);
|
|
25292
|
+
callback(channels[0], channelUsers[0]);
|
|
24652
25293
|
};
|
|
24653
25294
|
return createEventSubscriber(client, 'onChannelMemberRemoved', 'v3.channel.didRemoveUsers', filter);
|
|
24654
25295
|
};
|
|
24655
25296
|
|
|
25297
|
+
/**
|
|
25298
|
+
* ```js
|
|
25299
|
+
* import { onChannelMemberBanned } from '@amityco/ts-sdk'
|
|
25300
|
+
* const dispose = onChannelMemberBanned((channel, member) => {
|
|
25301
|
+
* // ...
|
|
25302
|
+
* })
|
|
25303
|
+
* ```
|
|
25304
|
+
*
|
|
25305
|
+
* Fired when any {@link Amity.User} has been banned from any {@link Amity.Channel}
|
|
25306
|
+
*
|
|
25307
|
+
* @param callback The function to call when the event was fired
|
|
25308
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
25309
|
+
*
|
|
25310
|
+
* @category Channel Events
|
|
25311
|
+
*/
|
|
25312
|
+
const onChannelMemberBanned = (callback) => {
|
|
25313
|
+
const client = getActiveClient();
|
|
25314
|
+
const filter = (payload) => {
|
|
25315
|
+
const channelPayload = prepareChannelPayload(payload);
|
|
25316
|
+
const preparedPayload = prepareMembershipPayload(channelPayload, 'channelUsers');
|
|
25317
|
+
const { channels, channelUsers } = preparedPayload;
|
|
25318
|
+
ingestInCache(preparedPayload);
|
|
25319
|
+
callback(channels[0], channelUsers.find(cu => cu.membership === 'banned'));
|
|
25320
|
+
};
|
|
25321
|
+
return createEventSubscriber(client, 'onChannelMemberBanned', 'v3.channel.didBan', filter);
|
|
25322
|
+
};
|
|
25323
|
+
|
|
25324
|
+
/**
|
|
25325
|
+
* ```js
|
|
25326
|
+
* import { onChannelMemberUnbanned } from '@amityco/ts-sdk'
|
|
25327
|
+
* const dispose = onChannelMemberUnbanned((channel, member) => {
|
|
25328
|
+
* // ...
|
|
25329
|
+
* })
|
|
25330
|
+
* ```
|
|
25331
|
+
*
|
|
25332
|
+
* Fired when any {@link Amity.User} has been unbanned from any {@link Amity.Channel}
|
|
25333
|
+
*
|
|
25334
|
+
* @param callback The function to call when the event was fired
|
|
25335
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
25336
|
+
*
|
|
25337
|
+
* @category Channel Events
|
|
25338
|
+
*/
|
|
25339
|
+
const onChannelMemberUnbanned = (callback) => {
|
|
25340
|
+
const client = getActiveClient();
|
|
25341
|
+
const filter = (payload) => {
|
|
25342
|
+
const channelPayload = prepareChannelPayload(payload);
|
|
25343
|
+
const preparedPayload = prepareMembershipPayload(channelPayload, 'channelUsers');
|
|
25344
|
+
const { channels, channelUsers } = preparedPayload;
|
|
25345
|
+
ingestInCache(preparedPayload);
|
|
25346
|
+
callback(channels[0], channelUsers.find(cu => cu.membership === 'none'));
|
|
25347
|
+
};
|
|
25348
|
+
return createEventSubscriber(client, 'onChannelMemberUnbanned', 'v3.channel.didUnban', filter);
|
|
25349
|
+
};
|
|
25350
|
+
|
|
25351
|
+
/**
|
|
25352
|
+
* ```js
|
|
25353
|
+
* import { onChannelMemberRead } from '@amityco/ts-sdk'
|
|
25354
|
+
* const dispose = onChannelMemberRead((channel, member) => {
|
|
25355
|
+
* // ...
|
|
25356
|
+
* })
|
|
25357
|
+
* ```
|
|
25358
|
+
*
|
|
25359
|
+
* Fired when any {@link Amity.User} has been read from any {@link Amity.Channel}
|
|
25360
|
+
*
|
|
25361
|
+
* @param callback The function to call when the event was fired
|
|
25362
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
25363
|
+
*
|
|
25364
|
+
* @category Channel Events
|
|
25365
|
+
*/
|
|
25366
|
+
const onChannelMemberRead = (callback) => {
|
|
25367
|
+
const client = getActiveClient();
|
|
25368
|
+
const filter = (payload) => {
|
|
25369
|
+
const channelPayload = prepareChannelPayload(payload);
|
|
25370
|
+
const preparedPayload = prepareMembershipPayload(channelPayload, 'channelUsers');
|
|
25371
|
+
ingestInCache(preparedPayload);
|
|
25372
|
+
callback(preparedPayload.channels[0], preparedPayload.channelUsers[0]);
|
|
25373
|
+
};
|
|
25374
|
+
return createEventSubscriber(client, 'onChannelMemberRead', 'v3.channel.didMarkSeen', filter);
|
|
25375
|
+
};
|
|
25376
|
+
|
|
24656
25377
|
/**
|
|
24657
25378
|
* ```js
|
|
24658
25379
|
* import { observeChannel } from '@amityco/ts-sdk'
|
|
@@ -24685,11 +25406,281 @@ const observeChannel = (channelId, callback) => {
|
|
|
24685
25406
|
(_b = callback.onEvent) === null || _b === void 0 ? void 0 : _b.call(callback, action, result);
|
|
24686
25407
|
(_c = callback[action]) === null || _c === void 0 ? void 0 : _c.call(callback, result);
|
|
24687
25408
|
};
|
|
24688
|
-
const disposers = [];
|
|
24689
|
-
disposers.push(onChannelUpdated(data => router({ data, loading: false, origin: 'event' }, 'onUpdate')), onChannelDeleted(data => router({ data, loading: false, origin: 'event' }, 'onDelete')), onChannelJoined(data => router({ data, loading: false, origin: 'event' }, 'onJoin')), onChannelLeft(data => router({ data, loading: false, origin: 'event' }, 'onLeft')), onChannelMemberAdded(data => router({ data, loading: false, origin: 'event' }, 'onMemberAdded')), onChannelMemberRemoved(data => router({ data, loading: false, origin: 'event' }, 'onMemberRemoved')));
|
|
24690
|
-
runQuery(createQuery(getChannel, channelId), result => result.data && router(result, 'onFetch'));
|
|
25409
|
+
const disposers = [];
|
|
25410
|
+
disposers.push(onChannelUpdated(data => router({ data, loading: false, origin: 'event' }, 'onUpdate')), onChannelDeleted(data => router({ data, loading: false, origin: 'event' }, 'onDelete')), onChannelJoined(data => router({ data, loading: false, origin: 'event' }, 'onJoin')), onChannelLeft(data => router({ data, loading: false, origin: 'event' }, 'onLeft')), onChannelMemberAdded(data => router({ data, loading: false, origin: 'event' }, 'onMemberAdded')), onChannelMemberRemoved(data => router({ data, loading: false, origin: 'event' }, 'onMemberRemoved')), onChannelMemberRead(data => router({ data, loading: false, origin: 'event' }, 'onRead')));
|
|
25411
|
+
runQuery(createQuery(getChannel, channelId), result => result.data && router(result, 'onFetch'));
|
|
25412
|
+
return () => {
|
|
25413
|
+
log(`observeChannel(tmpid: ${timestamp}) > dispose`);
|
|
25414
|
+
disposers.forEach(fn => fn());
|
|
25415
|
+
};
|
|
25416
|
+
};
|
|
25417
|
+
|
|
25418
|
+
/**
|
|
25419
|
+
* ```js
|
|
25420
|
+
* import { observeChannels } from '@amityco/ts-sdk'
|
|
25421
|
+
*
|
|
25422
|
+
* let channels = []
|
|
25423
|
+
* const unsub = observeChannels(channel => merge(channels, channel))
|
|
25424
|
+
* ```
|
|
25425
|
+
*
|
|
25426
|
+
* Observe all mutations on a list of {@link Amity.Channel} for a current user
|
|
25427
|
+
*
|
|
25428
|
+
* @param callback the function to call when new data are available
|
|
25429
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the channels
|
|
25430
|
+
*
|
|
25431
|
+
* @category Channel Observer
|
|
25432
|
+
*/
|
|
25433
|
+
const observeChannels = (callback) => {
|
|
25434
|
+
const { log } = getActiveClient();
|
|
25435
|
+
const timestamp = Date.now();
|
|
25436
|
+
log(`observeChannels(tmpid: ${timestamp}) > listen`);
|
|
25437
|
+
const disposers = [];
|
|
25438
|
+
const router = (channel, action) => {
|
|
25439
|
+
var _a, _b;
|
|
25440
|
+
if (callback instanceof Function)
|
|
25441
|
+
return callback(channel);
|
|
25442
|
+
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, channel);
|
|
25443
|
+
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, channel);
|
|
25444
|
+
};
|
|
25445
|
+
disposers.push(onChannelCreated(data => router(data, 'onCreate')), onChannelUpdated(data => router(data, 'onUpdate')), onChannelDeleted(data => router(data, 'onDelete')), onChannelJoined(data => router(data, 'onJoin')), onChannelLeft(data => router(data, 'onLeft')), onChannelMemberAdded(data => router(data, 'onMemberAdded')), onChannelMemberRemoved(data => router(data, 'onMemberRemoved')), onChannelMemberRead(data => router(data, 'onRead')));
|
|
25446
|
+
return () => {
|
|
25447
|
+
log(`observeChannels(tmpid: ${timestamp}) > dispose`);
|
|
25448
|
+
disposers.forEach(fn => fn());
|
|
25449
|
+
};
|
|
25450
|
+
};
|
|
25451
|
+
|
|
25452
|
+
/**
|
|
25453
|
+
* ```js
|
|
25454
|
+
* import { liveChannels } from '@amityco/ts-sdk'
|
|
25455
|
+
*
|
|
25456
|
+
* let channels = []
|
|
25457
|
+
* const unsub = liveChannels({
|
|
25458
|
+
* displayName: Amity.Channel['displayName'],
|
|
25459
|
+
* }, response => merge(channels, response.data))
|
|
25460
|
+
* ```
|
|
25461
|
+
*
|
|
25462
|
+
* Observe all mutations on a list of {@link Amity.Channel}s
|
|
25463
|
+
*
|
|
25464
|
+
* @param params for querying channels
|
|
25465
|
+
* @param callback the function to call when new data are available
|
|
25466
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the channels
|
|
25467
|
+
*
|
|
25468
|
+
* @category Channel Live Collection
|
|
25469
|
+
*/
|
|
25470
|
+
const liveChannels = (params, callback, config) => {
|
|
25471
|
+
const { log, cache, userId } = getActiveClient();
|
|
25472
|
+
if (!cache) {
|
|
25473
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
25474
|
+
}
|
|
25475
|
+
const timestamp = Date.now();
|
|
25476
|
+
log(`liveChannels(tmpid: ${timestamp}) > listen`);
|
|
25477
|
+
const { limit: queryLimit } = params, queryParams = __rest(params, ["limit"]);
|
|
25478
|
+
const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
|
|
25479
|
+
const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
|
|
25480
|
+
const disposers = [];
|
|
25481
|
+
const cacheKey = ['channel', 'collection', {}];
|
|
25482
|
+
const responder = (data) => {
|
|
25483
|
+
var _a, _b;
|
|
25484
|
+
let channels = (_a = data.data
|
|
25485
|
+
.map(channelId => pullFromCache(['channel', 'get', channelId]))
|
|
25486
|
+
.filter(Boolean)
|
|
25487
|
+
.map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
|
|
25488
|
+
channels = filterByPropEquality(channels, 'isDeleted', params.isDeleted);
|
|
25489
|
+
channels = filterByPropEquality(channels, 'displayName', params.displayName);
|
|
25490
|
+
if (params.types) {
|
|
25491
|
+
channels = channels.filter(c => { var _a; return (_a = params.types) === null || _a === void 0 ? void 0 : _a.includes(c.type); });
|
|
25492
|
+
}
|
|
25493
|
+
if (params.tags) {
|
|
25494
|
+
channels = channels.filter(c => { var _a; return (_a = c.tags) === null || _a === void 0 ? void 0 : _a.some(t => { var _a; return (_a = params.tags) === null || _a === void 0 ? void 0 : _a.includes(t); }); });
|
|
25495
|
+
}
|
|
25496
|
+
if (params.excludeTags) {
|
|
25497
|
+
channels = channels.filter(c => { var _a; return !((_a = c.tags) === null || _a === void 0 ? void 0 : _a.some(t => { var _a; return (_a = params.excludeTags) === null || _a === void 0 ? void 0 : _a.includes(t); })); });
|
|
25498
|
+
}
|
|
25499
|
+
// userId is required to be able to filter channel by current active user
|
|
25500
|
+
if (params.membership && userId) {
|
|
25501
|
+
channels = filterByChannelMembership(channels, params.membership, userId);
|
|
25502
|
+
}
|
|
25503
|
+
const sortBy = params.sortBy || 'lastCreated';
|
|
25504
|
+
if (sortBy === 'lastCreated' || sortBy === 'firstCreated') {
|
|
25505
|
+
channels = channels.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
25506
|
+
}
|
|
25507
|
+
/*
|
|
25508
|
+
* The server returns channels with empty | null displayName's first before
|
|
25509
|
+
* returning sorted list of channels with displayNames
|
|
25510
|
+
*
|
|
25511
|
+
* This section needs to be updated as displayNames can be null as well
|
|
25512
|
+
*/
|
|
25513
|
+
if (sortBy === 'displayName') {
|
|
25514
|
+
channels = channels
|
|
25515
|
+
// this needs to be aligned with the backend data type
|
|
25516
|
+
.map(c => (c.displayName ? c : Object.assign(Object.assign({}, c), { displayName: '' })))
|
|
25517
|
+
// @ts-ignore
|
|
25518
|
+
.sort(sortByDisplayName);
|
|
25519
|
+
}
|
|
25520
|
+
callback({
|
|
25521
|
+
onNextPage: onFetch,
|
|
25522
|
+
data: channels,
|
|
25523
|
+
hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
|
|
25524
|
+
loading: data.loading,
|
|
25525
|
+
error: data.error,
|
|
25526
|
+
});
|
|
25527
|
+
};
|
|
25528
|
+
const realtimeRouter = (channel, action) => {
|
|
25529
|
+
var _a;
|
|
25530
|
+
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
25531
|
+
if (!collection)
|
|
25532
|
+
return;
|
|
25533
|
+
if (action === 'onCreate') {
|
|
25534
|
+
collection.data = [...new Set([channel.channelId, ...collection.data])];
|
|
25535
|
+
/*
|
|
25536
|
+
* if the filter isDeleted is set, only collection item must be updated and not
|
|
25537
|
+
* the collection
|
|
25538
|
+
*/
|
|
25539
|
+
}
|
|
25540
|
+
else if (action === 'onDelete' && !params.isDeleted) {
|
|
25541
|
+
collection.data = collection.data.filter(c => c !== channel.channelId);
|
|
25542
|
+
}
|
|
25543
|
+
pushToCache(cacheKey, collection);
|
|
25544
|
+
responder(collection);
|
|
25545
|
+
};
|
|
25546
|
+
const onFetch = () => {
|
|
25547
|
+
var _a, _b, _c;
|
|
25548
|
+
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
25549
|
+
const channels = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
25550
|
+
if (channels.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
|
|
25551
|
+
return;
|
|
25552
|
+
const query = createQuery(queryChannels, Object.assign(Object.assign({}, queryParams), { page: (_c = collection === null || collection === void 0 ? void 0 : collection.params.page) !== null && _c !== void 0 ? _c : { limit } }));
|
|
25553
|
+
runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
|
|
25554
|
+
const data = {
|
|
25555
|
+
loading,
|
|
25556
|
+
error,
|
|
25557
|
+
params: { page },
|
|
25558
|
+
data: channels,
|
|
25559
|
+
};
|
|
25560
|
+
if (result) {
|
|
25561
|
+
data.data = [...new Set([...channels, ...result.map(getResolver('channel'))])];
|
|
25562
|
+
}
|
|
25563
|
+
pushToCache(cacheKey, data);
|
|
25564
|
+
responder(data);
|
|
25565
|
+
}, queryOptions(policy));
|
|
25566
|
+
};
|
|
25567
|
+
disposers.push(onChannelCreated(channel => realtimeRouter(channel, 'onCreate')), onChannelDeleted(channel => realtimeRouter(channel, 'onDelete')), onChannelUpdated(channel => realtimeRouter(channel, 'onUpdate')), onChannelMemberRead(channel => realtimeRouter(channel, 'onRead')));
|
|
25568
|
+
onFetch();
|
|
25569
|
+
return () => {
|
|
25570
|
+
log(`liveChannels(tmpid: ${timestamp}) > dispose`);
|
|
25571
|
+
disposers.forEach(fn => fn());
|
|
25572
|
+
};
|
|
25573
|
+
};
|
|
25574
|
+
|
|
25575
|
+
/**
|
|
25576
|
+
* ```js
|
|
25577
|
+
* import { liveChannelMembers } from '@amityco/ts-sdk'
|
|
25578
|
+
*
|
|
25579
|
+
* let channelMembers = []
|
|
25580
|
+
* const unsub = liveChannelMembers({
|
|
25581
|
+
* channelId: Amity.Channel['channelId'],
|
|
25582
|
+
* }, response => merge(channelMembers, response.data))
|
|
25583
|
+
* ```
|
|
25584
|
+
*
|
|
25585
|
+
* Observe all mutations on a list of {@link Amity.ChannelUser}s
|
|
25586
|
+
*
|
|
25587
|
+
* @param params for querying channel users
|
|
25588
|
+
* @param callback the function to call when new data are available
|
|
25589
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the channel users
|
|
25590
|
+
*
|
|
25591
|
+
* @category Channel Live Collection
|
|
25592
|
+
*/
|
|
25593
|
+
const liveChannelMembers = (params, callback, config) => {
|
|
25594
|
+
const { log, cache } = getActiveClient();
|
|
25595
|
+
if (!cache) {
|
|
25596
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
25597
|
+
}
|
|
25598
|
+
const timestamp = Date.now();
|
|
25599
|
+
log(`liveChannelMembers(tmpid: ${timestamp}) > listen`);
|
|
25600
|
+
const { limit: queryLimit } = params, queryParams = __rest(params, ["limit"]);
|
|
25601
|
+
const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
|
|
25602
|
+
const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
|
|
25603
|
+
const disposers = [];
|
|
25604
|
+
const cacheKey = ['channelUsers', 'collection', { channelId: params.channelId }];
|
|
25605
|
+
const responder = (data) => {
|
|
25606
|
+
var _a, _b;
|
|
25607
|
+
let channelMembers = (_a = data.data
|
|
25608
|
+
.map(id => pullFromCache(['channelUsers', 'get', id]))
|
|
25609
|
+
.filter(Boolean)
|
|
25610
|
+
.map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
|
|
25611
|
+
channelMembers = filterByPropEquality(channelMembers, 'roles', params.roles);
|
|
25612
|
+
if (params.memberships) {
|
|
25613
|
+
/*
|
|
25614
|
+
* even though membership includes muted as a possible value
|
|
25615
|
+
* when querying the server.
|
|
25616
|
+
* Muted is specified under seperarte property namely isMuted
|
|
25617
|
+
* Hence why I've seperately checked for it's equality
|
|
25618
|
+
*/
|
|
25619
|
+
if (params.memberships.some(m => ['member', 'banned'].includes(m))) {
|
|
25620
|
+
channelMembers = filterByPropInclusion(channelMembers, 'membership', params.memberships);
|
|
25621
|
+
}
|
|
25622
|
+
if (params.memberships.includes('muted')) {
|
|
25623
|
+
channelMembers = filterByPropEquality(channelMembers, 'isMuted', true);
|
|
25624
|
+
}
|
|
25625
|
+
}
|
|
25626
|
+
if (params.search) {
|
|
25627
|
+
const containsMatcher = new RegExp(params.search);
|
|
25628
|
+
channelMembers = channelMembers.filter(m => m.userId.match(containsMatcher));
|
|
25629
|
+
}
|
|
25630
|
+
// sort, 'lastCreated' is the default sort order
|
|
25631
|
+
const sortBy = params.sortBy ? params.sortBy : 'lastCreated';
|
|
25632
|
+
channelMembers = channelMembers.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
25633
|
+
callback({
|
|
25634
|
+
onNextPage: onFetch,
|
|
25635
|
+
data: channelMembers,
|
|
25636
|
+
hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
|
|
25637
|
+
loading: data.loading,
|
|
25638
|
+
error: data.error,
|
|
25639
|
+
});
|
|
25640
|
+
};
|
|
25641
|
+
const realtimeRouter = (channelMember, action) => {
|
|
25642
|
+
var _a;
|
|
25643
|
+
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
25644
|
+
if (!collection)
|
|
25645
|
+
return;
|
|
25646
|
+
const channelMemberCacheId = getResolver('channelUsers')({
|
|
25647
|
+
channelId: params.channelId,
|
|
25648
|
+
userId: channelMember.userId,
|
|
25649
|
+
});
|
|
25650
|
+
if (action === 'onMemberAdded') {
|
|
25651
|
+
collection.data = [...new Set([channelMemberCacheId, ...collection.data])];
|
|
25652
|
+
}
|
|
25653
|
+
if (action === 'onMemberRemoved') {
|
|
25654
|
+
collection.data = collection.data.filter(m => m !== channelMemberCacheId);
|
|
25655
|
+
}
|
|
25656
|
+
pushToCache(cacheKey, collection);
|
|
25657
|
+
responder(collection);
|
|
25658
|
+
};
|
|
25659
|
+
const onFetch = () => {
|
|
25660
|
+
var _a, _b, _c;
|
|
25661
|
+
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
25662
|
+
const channelMembers = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
25663
|
+
if (channelMembers.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
|
|
25664
|
+
return;
|
|
25665
|
+
const query = createQuery(queryChannelMembers, Object.assign(Object.assign({}, queryParams), { page: (_c = collection === null || collection === void 0 ? void 0 : collection.params.page) !== null && _c !== void 0 ? _c : { limit } }));
|
|
25666
|
+
runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
|
|
25667
|
+
const data = {
|
|
25668
|
+
loading,
|
|
25669
|
+
error,
|
|
25670
|
+
params: { page },
|
|
25671
|
+
data: channelMembers,
|
|
25672
|
+
};
|
|
25673
|
+
if (result) {
|
|
25674
|
+
data.data = [...new Set([...channelMembers, ...result.map(getResolver('channelUsers'))])];
|
|
25675
|
+
}
|
|
25676
|
+
pushToCache(cacheKey, data);
|
|
25677
|
+
responder(data);
|
|
25678
|
+
}, queryOptions(policy));
|
|
25679
|
+
};
|
|
25680
|
+
disposers.push(onChannelMemberAdded((_, member) => realtimeRouter(member, 'onMemberAdded')), onChannelMemberRemoved((_, member) => realtimeRouter(member, 'onMemberRemoved')), onChannelMemberBanned((_, member) => realtimeRouter(member, 'onChannelMemberBanned')), onChannelMemberUnbanned((_, member) => realtimeRouter(member, 'onChannelMemberUnbanned')), onChannelMemberRead((_, member) => realtimeRouter(member, 'onMemberRead')));
|
|
25681
|
+
onFetch();
|
|
24691
25682
|
return () => {
|
|
24692
|
-
log(`
|
|
25683
|
+
log(`liveChannelMembers(tmpid: ${timestamp}) > dispose`);
|
|
24693
25684
|
disposers.forEach(fn => fn());
|
|
24694
25685
|
};
|
|
24695
25686
|
};
|
|
@@ -24771,6 +25762,190 @@ const onMessageDeleted = (callback) => {
|
|
|
24771
25762
|
return createEventSubscriber(client, 'message/onMessageDeleted', 'v3.message.didDelete', filter);
|
|
24772
25763
|
};
|
|
24773
25764
|
|
|
25765
|
+
/**
|
|
25766
|
+
* ```js
|
|
25767
|
+
* import { onMessageFetched } from '@amityco/ts-sdk'
|
|
25768
|
+
* const dispose = onMessageFetched(message => {
|
|
25769
|
+
* // ...
|
|
25770
|
+
* })
|
|
25771
|
+
* ```
|
|
25772
|
+
*
|
|
25773
|
+
* Fired when an {@link Amity.Message} has been fetched
|
|
25774
|
+
*
|
|
25775
|
+
* @param callback The function to call when the event was fired
|
|
25776
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
25777
|
+
*
|
|
25778
|
+
* @category Message Events
|
|
25779
|
+
*/
|
|
25780
|
+
const onMessageFetched = (callback) => {
|
|
25781
|
+
const client = getActiveClient();
|
|
25782
|
+
const filter = (payload) => {
|
|
25783
|
+
ingestInCache(payload);
|
|
25784
|
+
callback(payload.messages[0]);
|
|
25785
|
+
};
|
|
25786
|
+
return createEventSubscriber(client, 'message/onMessageFetched', 'v3.message.didFetch', filter);
|
|
25787
|
+
};
|
|
25788
|
+
|
|
25789
|
+
/**
|
|
25790
|
+
* ```js
|
|
25791
|
+
* import { liveMessage } from '@amityco/ts-sdk'
|
|
25792
|
+
*
|
|
25793
|
+
* let messages = []
|
|
25794
|
+
* const unsub = liveMessage(messageId, response => merge(messages, response.data))
|
|
25795
|
+
* ```
|
|
25796
|
+
*
|
|
25797
|
+
* Observe all mutation on a given {@link Amity.Message}
|
|
25798
|
+
*
|
|
25799
|
+
* @param messageId the ID of the message to observe
|
|
25800
|
+
* @param callback the function to call when new data are available
|
|
25801
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
25802
|
+
*
|
|
25803
|
+
* @category Message Live Object
|
|
25804
|
+
*/
|
|
25805
|
+
const liveMessage = (messageId, callback) => {
|
|
25806
|
+
const { log, cache } = getActiveClient();
|
|
25807
|
+
let message;
|
|
25808
|
+
let isUnsyncedObject = false;
|
|
25809
|
+
if (!cache) {
|
|
25810
|
+
console.log(LIVE_OBJECT_ENABLE_CACHE_MESSAGE);
|
|
25811
|
+
}
|
|
25812
|
+
const timestamp = Date.now();
|
|
25813
|
+
log(`liveMessage(tmpid: ${timestamp}) > listen`);
|
|
25814
|
+
const disposers = [];
|
|
25815
|
+
const dispatcher = (data) => {
|
|
25816
|
+
var _a;
|
|
25817
|
+
// we check updatedAt to see if the current snapshot is new so
|
|
25818
|
+
// we won't send old data back, only fresh new data
|
|
25819
|
+
if (message && ((_a = data.data) === null || _a === void 0 ? void 0 : _a.updatedAt) === (message === null || message === void 0 ? void 0 : message.updatedAt) && data.origin !== 'server')
|
|
25820
|
+
return;
|
|
25821
|
+
callback(data);
|
|
25822
|
+
message = data.data;
|
|
25823
|
+
};
|
|
25824
|
+
const realtimeRouter = (message, action) => {
|
|
25825
|
+
dispatcher({ loading: false, data: message, origin: 'event' });
|
|
25826
|
+
};
|
|
25827
|
+
const onFetch = () => {
|
|
25828
|
+
const query = createQuery(getMessage, messageId, true);
|
|
25829
|
+
runQuery(query, ({ loading, data, error, origin, cachedAt }) => {
|
|
25830
|
+
if (cachedAt === UNSYNCED_OBJECT_CACHED_AT_VALUE) {
|
|
25831
|
+
dispatcher({
|
|
25832
|
+
data,
|
|
25833
|
+
origin,
|
|
25834
|
+
loading: false,
|
|
25835
|
+
error: new ASCApiError(UNSYNCED_OBJECT_CACHED_AT_MESSAGE, 800800 /* Amity.ClientError.DISALOOW_UNSYNCED_OBJECT */, "error" /* Amity.ErrorLevel.ERROR */),
|
|
25836
|
+
});
|
|
25837
|
+
isUnsyncedObject = true;
|
|
25838
|
+
disposers.forEach(fn => fn());
|
|
25839
|
+
}
|
|
25840
|
+
else if (!isUnsyncedObject) {
|
|
25841
|
+
dispatcher({ loading, data, origin, error });
|
|
25842
|
+
}
|
|
25843
|
+
if (error) {
|
|
25844
|
+
// Terminate observe functionality on error
|
|
25845
|
+
disposers.forEach(fn => fn());
|
|
25846
|
+
}
|
|
25847
|
+
});
|
|
25848
|
+
};
|
|
25849
|
+
disposers.push(onMessageFetched(message => realtimeRouter(message)), onMessageUpdated(message => realtimeRouter(message)), onMessageDeleted(message => realtimeRouter(message)));
|
|
25850
|
+
onFetch();
|
|
25851
|
+
return () => {
|
|
25852
|
+
log(`liveMessage(tmpid: ${timestamp}) > dispose`);
|
|
25853
|
+
disposers.forEach(fn => fn());
|
|
25854
|
+
};
|
|
25855
|
+
};
|
|
25856
|
+
|
|
25857
|
+
/**
|
|
25858
|
+
* ```js
|
|
25859
|
+
* import { liveMessages } from '@amityco/ts-sdk'
|
|
25860
|
+
*
|
|
25861
|
+
* let messages = []
|
|
25862
|
+
* const unsub = liveMessages({
|
|
25863
|
+
* channelId: Amity.Channel['channelId'];
|
|
25864
|
+
* }, response => merge(messages, response.data))
|
|
25865
|
+
* ```
|
|
25866
|
+
*
|
|
25867
|
+
* Observe all mutations on a list of {@link Amity.Message} for a given target object
|
|
25868
|
+
*
|
|
25869
|
+
* @param params for querying memssages from a channel
|
|
25870
|
+
* @param callback the function to call when new data are available
|
|
25871
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
25872
|
+
*
|
|
25873
|
+
* @category Messages Live Collection
|
|
25874
|
+
*/
|
|
25875
|
+
const liveMessages = (params, callback, config) => {
|
|
25876
|
+
const { log, cache } = getActiveClient();
|
|
25877
|
+
if (!cache) {
|
|
25878
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
25879
|
+
}
|
|
25880
|
+
const timestamp = Date.now();
|
|
25881
|
+
log(`liveMessages(tmpid: ${timestamp}) > listen`);
|
|
25882
|
+
const { limit: queryLimit } = params, queryParams = __rest(params, ["limit"]);
|
|
25883
|
+
const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
|
|
25884
|
+
const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
|
|
25885
|
+
const disposers = [];
|
|
25886
|
+
const cacheKey = ['message', 'collection', { channelId: params.channelId }];
|
|
25887
|
+
const responder = (data) => {
|
|
25888
|
+
var _a, _b;
|
|
25889
|
+
let messages = (_a = data.data
|
|
25890
|
+
.map(messageId => pullFromCache(['message', 'get', messageId]))
|
|
25891
|
+
.filter(Boolean)
|
|
25892
|
+
.map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
|
|
25893
|
+
/*
|
|
25894
|
+
* for cases when message is deleted via RTE, this flag is used to get
|
|
25895
|
+
* items fro cache that are deleted | !deleted
|
|
25896
|
+
*/
|
|
25897
|
+
messages = filterByPropEquality(messages, 'isDeleted', params.isDeleted);
|
|
25898
|
+
callback({
|
|
25899
|
+
onNextPage: onFetch,
|
|
25900
|
+
data: messages,
|
|
25901
|
+
hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
|
|
25902
|
+
loading: data.loading,
|
|
25903
|
+
error: data.error,
|
|
25904
|
+
});
|
|
25905
|
+
};
|
|
25906
|
+
const realtimeRouter = (message, action) => {
|
|
25907
|
+
var _a;
|
|
25908
|
+
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
25909
|
+
if (params.channelId !== message.channelId || !collection)
|
|
25910
|
+
return;
|
|
25911
|
+
if (action === 'onCreate') {
|
|
25912
|
+
collection.data = [...new Set([message.messageId, ...collection.data])];
|
|
25913
|
+
}
|
|
25914
|
+
else if (['onDelete'].includes(action)) {
|
|
25915
|
+
collection.data = collection.data.filter(m => m !== message.messageId);
|
|
25916
|
+
}
|
|
25917
|
+
pushToCache(cacheKey, collection);
|
|
25918
|
+
responder(collection);
|
|
25919
|
+
};
|
|
25920
|
+
const onFetch = () => {
|
|
25921
|
+
var _a, _b, _c, _d, _e;
|
|
25922
|
+
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
25923
|
+
const messages = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
25924
|
+
if (messages.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
|
|
25925
|
+
return;
|
|
25926
|
+
const query = createQuery(queryMessages, Object.assign(Object.assign({}, queryParams), { page: (_e = (_d = collection === null || collection === void 0 ? void 0 : collection.params) === null || _d === void 0 ? void 0 : _d.page) !== null && _e !== void 0 ? _e : { limit } }));
|
|
25927
|
+
runQuery(query, ({ data: result, error, loading, prevPage: page }) => {
|
|
25928
|
+
const data = {
|
|
25929
|
+
loading,
|
|
25930
|
+
error,
|
|
25931
|
+
params: { page },
|
|
25932
|
+
data: messages,
|
|
25933
|
+
};
|
|
25934
|
+
if (result) {
|
|
25935
|
+
data.data = [...new Set([...messages, ...result.map(getResolver('message'))])];
|
|
25936
|
+
}
|
|
25937
|
+
pushToCache(cacheKey, data);
|
|
25938
|
+
responder(data);
|
|
25939
|
+
}, queryOptions(policy));
|
|
25940
|
+
};
|
|
25941
|
+
disposers.push(onMessageFetched(message => realtimeRouter(message, 'onFetch')), onMessageCreated(message => realtimeRouter(message, 'onCreate')), onMessageDeleted(message => realtimeRouter(message, 'onDelete')), onMessageUpdated(message => realtimeRouter(message, 'onUpdate')));
|
|
25942
|
+
onFetch();
|
|
25943
|
+
return () => {
|
|
25944
|
+
log(`liveMessages(tmpid: ${timestamp}) > dispose`);
|
|
25945
|
+
disposers.forEach(fn => fn());
|
|
25946
|
+
};
|
|
25947
|
+
};
|
|
25948
|
+
|
|
24774
25949
|
/**
|
|
24775
25950
|
* ```js
|
|
24776
25951
|
* import { observeMessage } from '@amityco/ts-sdk'
|
|
@@ -24793,6 +25968,7 @@ const observeMessage = (messageId, callback, policy = 'cache_then_server') => {
|
|
|
24793
25968
|
const { log } = getActiveClient();
|
|
24794
25969
|
const timestamp = Date.now();
|
|
24795
25970
|
log(`observeMessage(tmpid: ${timestamp}) > listen`);
|
|
25971
|
+
console.log('observeMessage will be deprecated on 15th November 2022, please use liveMessage instead.');
|
|
24796
25972
|
// wrapper function to make sure
|
|
24797
25973
|
const router = (result, action) => {
|
|
24798
25974
|
var _a, _b, _c;
|
|
@@ -24826,7 +26002,6 @@ const observeMessage = (messageId, callback, policy = 'cache_then_server') => {
|
|
|
24826
26002
|
*
|
|
24827
26003
|
* Observe all mutations on a list of {@link Amity.Message} for a given {@link Amity.Channel} object
|
|
24828
26004
|
*
|
|
24829
|
-
* @param client the client to observe the message with
|
|
24830
26005
|
* @param channelId the ID of the channel where to observe the messages
|
|
24831
26006
|
* @param callback the function to call when new data are available
|
|
24832
26007
|
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
@@ -24857,16 +26032,17 @@ const observeMessages = (channelId, callback) => {
|
|
|
24857
26032
|
const createCommunityEventSubscriber = (event, callback) => {
|
|
24858
26033
|
const client = getActiveClient();
|
|
24859
26034
|
const filter = (payload) => {
|
|
26035
|
+
const unpackedPayload = unpackCommunityPayload(payload);
|
|
24860
26036
|
if (!client.cache) {
|
|
24861
26037
|
// TODO: here we are missing specific properties here!
|
|
24862
|
-
callback(
|
|
26038
|
+
callback(unpackedPayload.communities[0]);
|
|
24863
26039
|
}
|
|
24864
26040
|
else {
|
|
24865
|
-
ingestInCache(
|
|
26041
|
+
ingestInCache(unpackedPayload);
|
|
24866
26042
|
const community = pullFromCache([
|
|
24867
26043
|
'community',
|
|
24868
26044
|
'get',
|
|
24869
|
-
|
|
26045
|
+
unpackedPayload.communities[0].communityId,
|
|
24870
26046
|
]);
|
|
24871
26047
|
callback(community.data);
|
|
24872
26048
|
}
|
|
@@ -24902,21 +26078,23 @@ function getEventRelatedMember(event, payload) {
|
|
|
24902
26078
|
const createCommunityMemberEventSubscriber = (event, callback) => {
|
|
24903
26079
|
const client = getActiveClient();
|
|
24904
26080
|
const filter = (payload) => {
|
|
26081
|
+
const communityPayload = unpackCommunityPayload(payload);
|
|
26082
|
+
const preparedPayload = prepareMembershipPayload(communityPayload, 'communityUsers');
|
|
24905
26083
|
if (!client.cache) {
|
|
24906
26084
|
// TODO: here we are missing specific properties here!
|
|
24907
|
-
callback(
|
|
26085
|
+
callback(preparedPayload.communities[0], getEventRelatedMember(event, preparedPayload));
|
|
24908
26086
|
}
|
|
24909
26087
|
else {
|
|
24910
|
-
ingestInCache(
|
|
26088
|
+
ingestInCache(preparedPayload);
|
|
24911
26089
|
const community = pullFromCache([
|
|
24912
26090
|
'community',
|
|
24913
26091
|
'get',
|
|
24914
|
-
|
|
26092
|
+
preparedPayload.communities[0].communityId,
|
|
24915
26093
|
]);
|
|
24916
26094
|
const member = pullFromCache([
|
|
24917
26095
|
'communityUsers',
|
|
24918
26096
|
'get',
|
|
24919
|
-
getResolver('communityUsers')(getEventRelatedMember(event,
|
|
26097
|
+
getResolver('communityUsers')(getEventRelatedMember(event, preparedPayload)),
|
|
24920
26098
|
]);
|
|
24921
26099
|
callback(community.data, member.data);
|
|
24922
26100
|
}
|
|
@@ -25341,9 +26519,9 @@ const queryFollows = async (key, query) => {
|
|
|
25341
26519
|
if (client.cache) {
|
|
25342
26520
|
ingestInCache(payload, { cachedAt });
|
|
25343
26521
|
const cacheKey = [
|
|
25344
|
-
|
|
26522
|
+
'follow',
|
|
25345
26523
|
'query',
|
|
25346
|
-
Object.assign(Object.assign({}, params), { userId, options: Object.assign({}, page) }),
|
|
26524
|
+
Object.assign(Object.assign({}, params), { userId, options: Object.assign({}, page), type: key }),
|
|
25347
26525
|
];
|
|
25348
26526
|
pushToCache(cacheKey, { follows: follows.map(getResolver('follow')), paging });
|
|
25349
26527
|
}
|
|
@@ -25358,7 +26536,11 @@ queryFollows.locally = (key, query) => {
|
|
|
25358
26536
|
if (!client.cache)
|
|
25359
26537
|
return;
|
|
25360
26538
|
const { page } = query, params = __rest(query, ["page"]);
|
|
25361
|
-
const queryKey = [
|
|
26539
|
+
const queryKey = [
|
|
26540
|
+
'follow',
|
|
26541
|
+
'query',
|
|
26542
|
+
Object.assign(Object.assign({}, params), { options: Object.assign({}, page), type: key }),
|
|
26543
|
+
];
|
|
25362
26544
|
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
25363
26545
|
if (!(data === null || data === void 0 ? void 0 : data.follows.length)) {
|
|
25364
26546
|
return;
|
|
@@ -25904,6 +27086,186 @@ const observeFollowings = (userId, callback) => {
|
|
|
25904
27086
|
};
|
|
25905
27087
|
};
|
|
25906
27088
|
|
|
27089
|
+
/**
|
|
27090
|
+
* ```js
|
|
27091
|
+
* import { liveFollowers } from '@amityco/ts-sdk'
|
|
27092
|
+
*
|
|
27093
|
+
* let followers = []
|
|
27094
|
+
* const unsub = liveFollowers({
|
|
27095
|
+
* userId: Amity.User['userId'];
|
|
27096
|
+
* }, response => merge(followers, response.data))
|
|
27097
|
+
* ```
|
|
27098
|
+
*
|
|
27099
|
+
* Observe all mutations on a list of {@link Amity.FollowStatus} followers for a given userId
|
|
27100
|
+
*
|
|
27101
|
+
* @param userId the user
|
|
27102
|
+
* @param callback the function to call when new data are available
|
|
27103
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
27104
|
+
*
|
|
27105
|
+
* @category Followers Live Collection
|
|
27106
|
+
*/
|
|
27107
|
+
const liveFollowers = (params, callback, config) => {
|
|
27108
|
+
const { log, cache } = getActiveClient();
|
|
27109
|
+
if (!cache) {
|
|
27110
|
+
console.log('For using Live Collection feature you need to enable Cache!');
|
|
27111
|
+
}
|
|
27112
|
+
const timestamp = Date.now();
|
|
27113
|
+
log(`liveFollowers(tmpid: ${timestamp}) > listen`);
|
|
27114
|
+
const { limit: queryLimit } = params, queryParams = __rest(params, ["limit"]);
|
|
27115
|
+
const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
|
|
27116
|
+
const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
|
|
27117
|
+
const disposers = [];
|
|
27118
|
+
const cacheKey = ['follow', 'collection', { userId: params.userId, type: 'follower' }];
|
|
27119
|
+
const responder = (data) => {
|
|
27120
|
+
var _a, _b;
|
|
27121
|
+
let followers = (_a = data.data
|
|
27122
|
+
.map(key => pullFromCache(['follow', 'get', key]))
|
|
27123
|
+
.filter(Boolean)
|
|
27124
|
+
.map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
|
|
27125
|
+
if (params.status && params.status !== 'all') {
|
|
27126
|
+
followers = filterByPropEquality(followers, 'status', params.status);
|
|
27127
|
+
}
|
|
27128
|
+
callback({
|
|
27129
|
+
onNextPage: onFetch,
|
|
27130
|
+
data: followers,
|
|
27131
|
+
hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
|
|
27132
|
+
loading: data.loading,
|
|
27133
|
+
error: data.error,
|
|
27134
|
+
});
|
|
27135
|
+
};
|
|
27136
|
+
const realtimeRouter = (followStatus, action) => {
|
|
27137
|
+
var _a;
|
|
27138
|
+
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27139
|
+
if (params.userId !== followStatus.to || !collection)
|
|
27140
|
+
return;
|
|
27141
|
+
if (['onDeclined', 'onCanceled', 'onUnfollowed', 'onDeleted'].includes(action)) {
|
|
27142
|
+
collection.data = collection.data.filter(p => p !== getResolver('follow')(followStatus));
|
|
27143
|
+
}
|
|
27144
|
+
else if (['onRequested', 'onAccepted', 'onFollowed'].includes(action)) {
|
|
27145
|
+
collection.data = [...new Set([getResolver('follow')(followStatus), ...collection.data])];
|
|
27146
|
+
}
|
|
27147
|
+
pushToCache(cacheKey, collection);
|
|
27148
|
+
responder(collection);
|
|
27149
|
+
};
|
|
27150
|
+
const onFetch = () => {
|
|
27151
|
+
var _a, _b, _c, _d, _e;
|
|
27152
|
+
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27153
|
+
const followers = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
27154
|
+
if (followers.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
|
|
27155
|
+
return;
|
|
27156
|
+
const query = createQuery(queryFollowers, Object.assign(Object.assign({}, queryParams), { page: (_e = (_d = collection === null || collection === void 0 ? void 0 : collection.params) === null || _d === void 0 ? void 0 : _d.page) !== null && _e !== void 0 ? _e : { limit } }));
|
|
27157
|
+
runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
|
|
27158
|
+
const data = {
|
|
27159
|
+
loading,
|
|
27160
|
+
error,
|
|
27161
|
+
params: { page },
|
|
27162
|
+
data: followers,
|
|
27163
|
+
};
|
|
27164
|
+
if (result) {
|
|
27165
|
+
data.data = [...new Set([...followers, ...result.map(getResolver('follow'))])];
|
|
27166
|
+
}
|
|
27167
|
+
pushToCache(cacheKey, data);
|
|
27168
|
+
responder(data);
|
|
27169
|
+
}, queryOptions(policy));
|
|
27170
|
+
};
|
|
27171
|
+
disposers.push(onFollowerRequested(followStatus => realtimeRouter(followStatus, 'onRequested')), onFollowRequestAccepted(followStatus => realtimeRouter(followStatus, 'onAccepted')), onFollowRequestDeclined(followStatus => realtimeRouter(followStatus, 'onDeclined')), onFollowRequestCanceled(followStatus => realtimeRouter(followStatus, 'onCanceled')), onUserFollowed(followStatus => realtimeRouter(followStatus, 'onFollowed')), onUserUnfollowed(followStatus => realtimeRouter(followStatus, 'onUnfollowed')), onFollowerDeleted(followStatus => realtimeRouter(followStatus, 'onDeleted')));
|
|
27172
|
+
onFetch();
|
|
27173
|
+
return () => {
|
|
27174
|
+
log(`liveFollowers(tmpid: ${timestamp}) > dispose`);
|
|
27175
|
+
disposers.forEach(fn => fn());
|
|
27176
|
+
};
|
|
27177
|
+
};
|
|
27178
|
+
|
|
27179
|
+
/**
|
|
27180
|
+
* ```js
|
|
27181
|
+
* import { liveFollowings } from '@amityco/ts-sdk'
|
|
27182
|
+
*
|
|
27183
|
+
* let followings = []
|
|
27184
|
+
* const unsub = liveFollowings({
|
|
27185
|
+
* userId: Amity.User['userId'];
|
|
27186
|
+
* }, response => merge(followings, response.data))
|
|
27187
|
+
* ```
|
|
27188
|
+
*
|
|
27189
|
+
* Observe all mutations on a list of {@link Amity.FollowStatus} followings for a given userId
|
|
27190
|
+
*
|
|
27191
|
+
* @param userId the user
|
|
27192
|
+
* @param callback the function to call when new data are available
|
|
27193
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
27194
|
+
*
|
|
27195
|
+
* @category Followings Live Collection
|
|
27196
|
+
*/
|
|
27197
|
+
const liveFollowings = (params, callback, config) => {
|
|
27198
|
+
const { log, cache } = getActiveClient();
|
|
27199
|
+
if (!cache) {
|
|
27200
|
+
console.log('For using Live Collection feature you need to enable Cache!');
|
|
27201
|
+
}
|
|
27202
|
+
const timestamp = Date.now();
|
|
27203
|
+
log(`liveFollowings(tmpid: ${timestamp}) > listen`);
|
|
27204
|
+
const { limit: queryLimit } = params, queryParams = __rest(params, ["limit"]);
|
|
27205
|
+
const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
|
|
27206
|
+
const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
|
|
27207
|
+
const disposers = [];
|
|
27208
|
+
const cacheKey = ['follow', 'collection', { userId: params.userId, type: 'following' }];
|
|
27209
|
+
const responder = (data) => {
|
|
27210
|
+
var _a, _b;
|
|
27211
|
+
let followings = (_a = data.data
|
|
27212
|
+
.map(key => pullFromCache(['follow', 'get', key]))
|
|
27213
|
+
.filter(Boolean)
|
|
27214
|
+
.map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
|
|
27215
|
+
if (params.status && params.status !== 'all') {
|
|
27216
|
+
followings = filterByPropEquality(followings, 'status', params.status);
|
|
27217
|
+
}
|
|
27218
|
+
callback({
|
|
27219
|
+
onNextPage: onFetch,
|
|
27220
|
+
data: followings,
|
|
27221
|
+
hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
|
|
27222
|
+
loading: data.loading,
|
|
27223
|
+
error: data.error,
|
|
27224
|
+
});
|
|
27225
|
+
};
|
|
27226
|
+
const realtimeRouter = (followStatus, action) => {
|
|
27227
|
+
var _a;
|
|
27228
|
+
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27229
|
+
if (params.userId !== followStatus.from || !collection)
|
|
27230
|
+
return;
|
|
27231
|
+
if (['onDeclined', 'onCanceled', 'onUnfollowed', 'onDeleted'].includes(action)) {
|
|
27232
|
+
collection.data = collection.data.filter(p => p !== getResolver('follow')(followStatus));
|
|
27233
|
+
}
|
|
27234
|
+
else if (['onRequested', 'onAccepted', 'onFollowed'].includes(action)) {
|
|
27235
|
+
collection.data = [...new Set([getResolver('follow')(followStatus), ...collection.data])];
|
|
27236
|
+
}
|
|
27237
|
+
pushToCache(cacheKey, collection);
|
|
27238
|
+
responder(collection);
|
|
27239
|
+
};
|
|
27240
|
+
const onFetch = () => {
|
|
27241
|
+
var _a, _b, _c, _d, _e;
|
|
27242
|
+
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27243
|
+
const followings = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
27244
|
+
if (followings.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
|
|
27245
|
+
return;
|
|
27246
|
+
const query = createQuery(queryFollowings, Object.assign(Object.assign({}, queryParams), { page: (_e = (_d = collection === null || collection === void 0 ? void 0 : collection.params) === null || _d === void 0 ? void 0 : _d.page) !== null && _e !== void 0 ? _e : { limit } }));
|
|
27247
|
+
runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
|
|
27248
|
+
const data = {
|
|
27249
|
+
loading,
|
|
27250
|
+
error,
|
|
27251
|
+
params: { page },
|
|
27252
|
+
data: followings,
|
|
27253
|
+
};
|
|
27254
|
+
if (result) {
|
|
27255
|
+
data.data = [...new Set([...followings, ...result.map(getResolver('follow'))])];
|
|
27256
|
+
}
|
|
27257
|
+
pushToCache(cacheKey, data);
|
|
27258
|
+
responder(data);
|
|
27259
|
+
}, queryOptions(policy));
|
|
27260
|
+
};
|
|
27261
|
+
disposers.push(onFollowerRequested(followStatus => realtimeRouter(followStatus, 'onRequested')), onFollowRequestAccepted(followStatus => realtimeRouter(followStatus, 'onAccepted')), onFollowRequestDeclined(followStatus => realtimeRouter(followStatus, 'onDeclined')), onFollowRequestCanceled(followStatus => realtimeRouter(followStatus, 'onCanceled')), onUserFollowed(followStatus => realtimeRouter(followStatus, 'onFollowed')), onUserUnfollowed(followStatus => realtimeRouter(followStatus, 'onUnfollowed')), onFollowerDeleted(followStatus => realtimeRouter(followStatus, 'onDeleted')));
|
|
27262
|
+
onFetch();
|
|
27263
|
+
return () => {
|
|
27264
|
+
log(`liveFollowings(tmpid: ${timestamp}) > dispose`);
|
|
27265
|
+
disposers.forEach(fn => fn());
|
|
27266
|
+
};
|
|
27267
|
+
};
|
|
27268
|
+
|
|
25907
27269
|
/**
|
|
25908
27270
|
* ```js
|
|
25909
27271
|
* import { observePosts } from '@amityco/ts-sdk'
|
|
@@ -26012,7 +27374,7 @@ const observePost = (postId, callback, policy = 'cache_then_server') => {
|
|
|
26012
27374
|
const livePosts = (params, callback, config) => {
|
|
26013
27375
|
const { log, cache } = getActiveClient();
|
|
26014
27376
|
if (!cache) {
|
|
26015
|
-
console.log(
|
|
27377
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
26016
27378
|
}
|
|
26017
27379
|
const timestamp = Date.now();
|
|
26018
27380
|
log(`livePosts(tmpid: ${timestamp}) > listen`);
|
|
@@ -26851,7 +28213,17 @@ const createUserToken = async (apiKey, apiRegion, params) => {
|
|
|
26851
28213
|
};
|
|
26852
28214
|
|
|
26853
28215
|
exports.API_REGIONS = API_REGIONS;
|
|
28216
|
+
exports.CommunityPostSettingMaps = CommunityPostSettingMaps;
|
|
28217
|
+
exports.CommunityPostSettings = CommunityPostSettings;
|
|
28218
|
+
exports.ContentFeedType = ContentFeedType;
|
|
28219
|
+
exports.DefaultCommunityPostSetting = DefaultCommunityPostSetting;
|
|
28220
|
+
exports.FileType = FileType;
|
|
28221
|
+
exports.MessageContentType = MessageContentType;
|
|
28222
|
+
exports.PostContentType = PostContentType;
|
|
26854
28223
|
exports.VERSION = VERSION$1;
|
|
28224
|
+
exports.VideoResolution = VideoResolution;
|
|
28225
|
+
exports.VideoSize = VideoSize;
|
|
28226
|
+
exports.VideoTranscodingStatus = VideoTranscodingStatus;
|
|
26855
28227
|
exports.acceptFollower = acceptFollower;
|
|
26856
28228
|
exports.addChannelMembers = addChannelMembers;
|
|
26857
28229
|
exports.addChannelMembersRole = addChannelMembersRole;
|
|
@@ -26894,7 +28266,9 @@ exports.disposeStream = disposeStream;
|
|
|
26894
28266
|
exports.dropFromCache = dropFromCache;
|
|
26895
28267
|
exports.enableCache = enableCache;
|
|
26896
28268
|
exports.fileUrlWithSize = fileUrlWithSize;
|
|
28269
|
+
exports.filterByChannelMembership = filterByChannelMembership;
|
|
26897
28270
|
exports.filterByPropEquality = filterByPropEquality;
|
|
28271
|
+
exports.filterByPropInclusion = filterByPropInclusion;
|
|
26898
28272
|
exports.follow = follow;
|
|
26899
28273
|
exports.getActiveClient = getActiveClient;
|
|
26900
28274
|
exports.getCategory = getCategory;
|
|
@@ -26906,6 +28280,7 @@ exports.getComments = getComments;
|
|
|
26906
28280
|
exports.getCommunities = getCommunities;
|
|
26907
28281
|
exports.getCommunity = getCommunity;
|
|
26908
28282
|
exports.getCommunityTopic = getCommunityTopic;
|
|
28283
|
+
exports.getFeedSettings = getFeedSettings;
|
|
26909
28284
|
exports.getFile = getFile;
|
|
26910
28285
|
exports.getFollowInfo = getFollowInfo;
|
|
26911
28286
|
exports.getMessage = getMessage;
|
|
@@ -26940,11 +28315,19 @@ exports.joinChannel = joinChannel;
|
|
|
26940
28315
|
exports.joinCommunity = joinCommunity;
|
|
26941
28316
|
exports.leaveChannel = leaveChannel;
|
|
26942
28317
|
exports.leaveCommunity = leaveCommunity;
|
|
28318
|
+
exports.liveChannelMembers = liveChannelMembers;
|
|
28319
|
+
exports.liveChannels = liveChannels;
|
|
26943
28320
|
exports.liveComments = liveComments;
|
|
28321
|
+
exports.liveFollowers = liveFollowers;
|
|
28322
|
+
exports.liveFollowings = liveFollowings;
|
|
28323
|
+
exports.liveMessage = liveMessage;
|
|
28324
|
+
exports.liveMessages = liveMessages;
|
|
26944
28325
|
exports.livePosts = livePosts;
|
|
26945
28326
|
exports.liveReactions = liveReactions;
|
|
28327
|
+
exports.liveUser = liveUser;
|
|
26946
28328
|
exports.mergeInCache = mergeInCache;
|
|
26947
28329
|
exports.observeChannel = observeChannel;
|
|
28330
|
+
exports.observeChannels = observeChannels;
|
|
26948
28331
|
exports.observeComment = observeComment;
|
|
26949
28332
|
exports.observeComments = observeComments;
|
|
26950
28333
|
exports.observeCommunity = observeCommunity;
|
|
@@ -26958,11 +28341,15 @@ exports.observePoll = observePoll;
|
|
|
26958
28341
|
exports.observePost = observePost;
|
|
26959
28342
|
exports.observePosts = observePosts;
|
|
26960
28343
|
exports.observeUser = observeUser;
|
|
28344
|
+
exports.onChannelCreated = onChannelCreated;
|
|
26961
28345
|
exports.onChannelDeleted = onChannelDeleted;
|
|
26962
28346
|
exports.onChannelJoined = onChannelJoined;
|
|
26963
28347
|
exports.onChannelLeft = onChannelLeft;
|
|
26964
28348
|
exports.onChannelMemberAdded = onChannelMemberAdded;
|
|
28349
|
+
exports.onChannelMemberBanned = onChannelMemberBanned;
|
|
28350
|
+
exports.onChannelMemberRead = onChannelMemberRead;
|
|
26965
28351
|
exports.onChannelMemberRemoved = onChannelMemberRemoved;
|
|
28352
|
+
exports.onChannelMemberUnbanned = onChannelMemberUnbanned;
|
|
26966
28353
|
exports.onChannelUpdated = onChannelUpdated;
|
|
26967
28354
|
exports.onClientBanned = onClientBanned;
|
|
26968
28355
|
exports.onClientDisconnected = onClientDisconnected;
|
|
@@ -26991,6 +28378,7 @@ exports.onFollowerDeleted = onFollowerDeleted;
|
|
|
26991
28378
|
exports.onFollowerRequested = onFollowerRequested;
|
|
26992
28379
|
exports.onMessageCreated = onMessageCreated;
|
|
26993
28380
|
exports.onMessageDeleted = onMessageDeleted;
|
|
28381
|
+
exports.onMessageFetched = onMessageFetched;
|
|
26994
28382
|
exports.onMessageUpdated = onMessageUpdated;
|
|
26995
28383
|
exports.onPollDeleted = onPollDeleted;
|
|
26996
28384
|
exports.onPollUpdated = onPollUpdated;
|
|
@@ -27011,6 +28399,7 @@ exports.onStreamRecorded = onStreamRecorded;
|
|
|
27011
28399
|
exports.onStreamStarted = onStreamStarted;
|
|
27012
28400
|
exports.onStreamStopped = onStreamStopped;
|
|
27013
28401
|
exports.onUserDeleted = onUserDeleted;
|
|
28402
|
+
exports.onUserFetched = onUserFetched;
|
|
27014
28403
|
exports.onUserFlagCleared = onUserFlagCleared;
|
|
27015
28404
|
exports.onUserFlagged = onUserFlagged;
|
|
27016
28405
|
exports.onUserFollowed = onUserFollowed;
|
|
@@ -27049,6 +28438,8 @@ exports.sortByFirstCreated = sortByFirstCreated;
|
|
|
27049
28438
|
exports.sortByLastActivity = sortByLastActivity;
|
|
27050
28439
|
exports.sortByLastCreated = sortByLastCreated;
|
|
27051
28440
|
exports.sortBySegmentNumber = sortBySegmentNumber;
|
|
28441
|
+
exports.startReading = startReading;
|
|
28442
|
+
exports.stopReading = stopReading;
|
|
27052
28443
|
exports.subscribeTopic = subscribeTopic;
|
|
27053
28444
|
exports.toPage = toPage;
|
|
27054
28445
|
exports.toPageRaw = toPageRaw;
|