mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-04 10:19:35 +02:00
Add new follow, mention and user registered notifs
This commit is contained in:
parent
dc13348070
commit
f7cc67b455
25 changed files with 899 additions and 57 deletions
|
@ -5,6 +5,7 @@ import { sequelizeTypescript } from '../../../initializers'
|
|||
import { ActorModel } from '../../../models/activitypub/actor'
|
||||
import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
|
||||
import { sendAccept } from '../send'
|
||||
import { Notifier } from '../../notifier'
|
||||
|
||||
async function processFollowActivity (activity: ActivityFollow, byActor: ActorModel) {
|
||||
const activityObject = activity.object
|
||||
|
@ -21,13 +22,13 @@ export {
|
|||
// ---------------------------------------------------------------------------
|
||||
|
||||
async function processFollow (actor: ActorModel, targetActorURL: string) {
|
||||
await sequelizeTypescript.transaction(async t => {
|
||||
const { actorFollow, created } = 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 [ actorFollow ] = await ActorFollowModel.findOrCreate({
|
||||
const [ actorFollow, created ] = await ActorFollowModel.findOrCreate({
|
||||
where: {
|
||||
actorId: actor.id,
|
||||
targetActorId: targetActor.id
|
||||
|
@ -52,8 +53,12 @@ async function processFollow (actor: ActorModel, targetActorURL: string) {
|
|||
actorFollow.ActorFollowing = targetActor
|
||||
|
||||
// Target sends to actor he accepted the follow request
|
||||
return sendAccept(actorFollow)
|
||||
await sendAccept(actorFollow)
|
||||
|
||||
return { actorFollow, created }
|
||||
})
|
||||
|
||||
if (created) Notifier.Instance.notifyOfNewFollow(actorFollow)
|
||||
|
||||
logger.info('Actor %s is followed by actor %s.', targetActorURL, actor.url)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue