1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-05 02:39:33 +02:00

Add notification on new instance follower (server side)

This commit is contained in:
Chocobozzz 2019-04-08 17:26:01 +02:00
parent 0dc6477758
commit 883993c81e
No known key found for this signature in database
GPG key ID: 583A612D890159BE
19 changed files with 212 additions and 21 deletions

View file

@ -24,14 +24,16 @@ export {
// ---------------------------------------------------------------------------
async function processFollow (actor: ActorModel, targetActorURL: string) {
const { actorFollow, created } = await sequelizeTypescript.transaction(async t => {
const { actorFollow, created, isFollowingInstance } = await sequelizeTypescript.transaction(async t => {
const targetActor = await ActorModel.loadByUrlAndPopulateAccountAndChannel(targetActorURL, t)
if (!targetActor) throw new Error('Unknown actor')
if (targetActor.isOwned() === false) throw new Error('This is not a local actor.')
const serverActor = await getServerActor()
if (targetActor.id === serverActor.id && CONFIG.FOLLOWERS.INSTANCE.ENABLED === false) {
const isFollowingInstance = targetActor.id === serverActor.id
if (isFollowingInstance && CONFIG.FOLLOWERS.INSTANCE.ENABLED === false) {
logger.info('Rejecting %s because instance followers are disabled.', targetActor.url)
return sendReject(actor, targetActor)
@ -50,9 +52,6 @@ async function processFollow (actor: ActorModel, targetActorURL: string) {
transaction: t
})
actorFollow.ActorFollower = actor
actorFollow.ActorFollowing = targetActor
if (actorFollow.state !== 'accepted' && CONFIG.FOLLOWERS.INSTANCE.MANUAL_APPROVAL === false) {
actorFollow.state = 'accepted'
await actorFollow.save({ transaction: t })
@ -64,10 +63,16 @@ async function processFollow (actor: ActorModel, targetActorURL: string) {
// Target sends to actor he accepted the follow request
if (actorFollow.state === 'accepted') await sendAccept(actorFollow)
return { actorFollow, created }
return { actorFollow, created, isFollowingInstance }
})
if (created) Notifier.Instance.notifyOfNewFollow(actorFollow)
// Rejected
if (!actorFollow) return
if (created) {
if (isFollowingInstance) Notifier.Instance.notifyOfNewInstanceFollow(actorFollow)
else Notifier.Instance.notifyOfNewUserFollow(actorFollow)
}
logger.info('Actor %s is followed by actor %s.', targetActorURL, actor.url)
}