Add ability to view my followers

This commit is contained in:
Chocobozzz
2021-10-19 09:44:43 +02:00
parent 9593a78ae1
commit 4beda9e12a
47 changed files with 799 additions and 248 deletions

View File

@@ -1,5 +1,6 @@
import express from 'express'
import { pickCommonVideoQuery } from '@server/helpers/query'
import { ActorFollowModel } from '@server/models/actor/actor-follow'
import { getServerActor } from '@server/models/application/application'
import { buildNSFWFilter, getCountVideos, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils'
import { getFormattedObjects } from '../../helpers/utils'
@@ -20,6 +21,7 @@ import {
} from '../../middlewares'
import {
accountNameWithHostGetValidator,
accountsFollowersSortValidator,
accountsSortValidator,
ensureAuthUserOwnsAccountValidator,
videoChannelsSortValidator,
@@ -93,6 +95,17 @@ accountsRouter.get('/:accountName/ratings',
asyncMiddleware(listAccountRatings)
)
accountsRouter.get('/:accountName/followers',
authenticate,
asyncMiddleware(accountNameWithHostGetValidator),
ensureAuthUserOwnsAccountValidator,
paginationValidator,
accountsFollowersSortValidator,
setDefaultSort,
setDefaultPagination,
asyncMiddleware(listAccountFollowers)
)
// ---------------------------------------------------------------------------
export {
@@ -127,7 +140,7 @@ async function listAccountChannels (req: express.Request, res: express.Response)
search: req.query.search
}
const resultList = await VideoChannelModel.listByAccount(options)
const resultList = await VideoChannelModel.listByAccountForAPI(options)
return res.json(getFormattedObjects(resultList.data, resultList.total))
}
@@ -195,3 +208,21 @@ async function listAccountRatings (req: express.Request, res: express.Response)
})
return res.json(getFormattedObjects(resultList.rows, resultList.count))
}
async function listAccountFollowers (req: express.Request, res: express.Response) {
const account = res.locals.account
const channels = await VideoChannelModel.listAllByAccount(account.id)
const actorIds = [ account.actorId ].concat(channels.map(c => c.actorId))
const resultList = await ActorFollowModel.listFollowersForApi({
actorIds,
start: req.query.start,
count: req.query.count,
sort: req.query.sort,
search: req.query.search,
state: 'accepted',
})
return res.json(getFormattedObjects(resultList.data, resultList.total))
}

View File

@@ -98,7 +98,7 @@ export {
async function listFollowing (req: express.Request, res: express.Response) {
const serverActor = await getServerActor()
const resultList = await ActorFollowModel.listFollowingForApi({
const resultList = await ActorFollowModel.listInstanceFollowingForApi({
id: serverActor.id,
start: req.query.start,
count: req.query.count,
@@ -114,7 +114,7 @@ async function listFollowing (req: express.Request, res: express.Response) {
async function listFollowers (req: express.Request, res: express.Response) {
const serverActor = await getServerActor()
const resultList = await ActorFollowModel.listFollowersForApi({
actorId: serverActor.id,
actorIds: [ serverActor.id ],
start: req.query.start,
count: req.query.count,
sort: req.query.sort,

View File

@@ -95,7 +95,7 @@ async function areSubscriptionsExist (req: express.Request, res: express.Respons
return { name, host, uri: u }
})
const results = await ActorFollowModel.listSubscribedIn(user.Account.Actor.id, handles)
const results = await ActorFollowModel.listSubscriptionsOf(user.Account.Actor.id, handles)
const existObject: { [id: string ]: boolean } = {}
for (const handle of handles) {

View File

@@ -1,6 +1,7 @@
import express from 'express'
import { pickCommonVideoQuery } from '@server/helpers/query'
import { Hooks } from '@server/lib/plugins/hooks'
import { ActorFollowModel } from '@server/models/actor/actor-follow'
import { getServerActor } from '@server/models/application/application'
import { MChannelBannerAccountDefault } from '@server/types/models'
import { ActorImageType, VideoChannelCreate, VideoChannelUpdate } from '../../../shared'
@@ -33,7 +34,13 @@ import {
videoChannelsUpdateValidator,
videoPlaylistsSortValidator
} from '../../middlewares'
import { videoChannelsListValidator, videoChannelsNameWithHostValidator, videosSortValidator } from '../../middlewares/validators'
import {
ensureAuthUserOwnsChannelValidator,
videoChannelsFollowersSortValidator,
videoChannelsListValidator,
videoChannelsNameWithHostValidator,
videosSortValidator
} from '../../middlewares/validators'
import { updateAvatarValidator, updateBannerValidator } from '../../middlewares/validators/actor-image'
import { commonVideoPlaylistFiltersValidator } from '../../middlewares/validators/videos/video-playlists'
import { AccountModel } from '../../models/account/account'
@@ -65,8 +72,8 @@ videoChannelRouter.post('/',
videoChannelRouter.post('/:nameWithHost/avatar/pick',
authenticate,
reqAvatarFile,
// Check the rights
asyncMiddleware(videoChannelsUpdateValidator),
asyncMiddleware(videoChannelsNameWithHostValidator),
ensureAuthUserOwnsChannelValidator,
updateAvatarValidator,
asyncMiddleware(updateVideoChannelAvatar)
)
@@ -74,29 +81,31 @@ videoChannelRouter.post('/:nameWithHost/avatar/pick',
videoChannelRouter.post('/:nameWithHost/banner/pick',
authenticate,
reqBannerFile,
// Check the rights
asyncMiddleware(videoChannelsUpdateValidator),
asyncMiddleware(videoChannelsNameWithHostValidator),
ensureAuthUserOwnsChannelValidator,
updateBannerValidator,
asyncMiddleware(updateVideoChannelBanner)
)
videoChannelRouter.delete('/:nameWithHost/avatar',
authenticate,
// Check the rights
asyncMiddleware(videoChannelsUpdateValidator),
asyncMiddleware(videoChannelsNameWithHostValidator),
ensureAuthUserOwnsChannelValidator,
asyncMiddleware(deleteVideoChannelAvatar)
)
videoChannelRouter.delete('/:nameWithHost/banner',
authenticate,
// Check the rights
asyncMiddleware(videoChannelsUpdateValidator),
asyncMiddleware(videoChannelsNameWithHostValidator),
ensureAuthUserOwnsChannelValidator,
asyncMiddleware(deleteVideoChannelBanner)
)
videoChannelRouter.put('/:nameWithHost',
authenticate,
asyncMiddleware(videoChannelsUpdateValidator),
asyncMiddleware(videoChannelsNameWithHostValidator),
ensureAuthUserOwnsChannelValidator,
videoChannelsUpdateValidator,
asyncRetryTransactionMiddleware(updateVideoChannel)
)
@@ -132,6 +141,17 @@ videoChannelRouter.get('/:nameWithHost/videos',
asyncMiddleware(listVideoChannelVideos)
)
videoChannelRouter.get('/:nameWithHost/followers',
authenticate,
asyncMiddleware(videoChannelsNameWithHostValidator),
ensureAuthUserOwnsChannelValidator,
paginationValidator,
videoChannelsFollowersSortValidator,
setDefaultSort,
setDefaultPagination,
asyncMiddleware(listVideoChannelFollowers)
)
// ---------------------------------------------------------------------------
export {
@@ -332,3 +352,18 @@ async function listVideoChannelVideos (req: express.Request, res: express.Respon
return res.json(getFormattedObjects(resultList.data, resultList.total))
}
async function listVideoChannelFollowers (req: express.Request, res: express.Response) {
const channel = res.locals.videoChannel
const resultList = await ActorFollowModel.listFollowersForApi({
actorIds: [ channel.actorId ],
start: req.query.start,
count: req.query.count,
sort: req.query.sort,
search: req.query.search,
state: 'accepted',
})
return res.json(getFormattedObjects(resultList.data, resultList.total))
}