Init commit
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
import { UserNotificationType, UserRight } from '@peertube/peertube-models'
|
||||
import { t } from '@server/helpers/i18n.js'
|
||||
import { logger } from '@server/helpers/logger.js'
|
||||
import { instanceFollowingUrl } from '@server/lib/client-urls.js'
|
||||
import { UserNotificationModel } from '@server/models/user/user-notification.js'
|
||||
import { UserModel } from '@server/models/user/user.js'
|
||||
import { MActorFollowFull, MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models/index.js'
|
||||
import { AbstractNotification } from '../common/abstract-notification.js'
|
||||
|
||||
export class AutoFollowForInstance extends AbstractNotification<MActorFollowFull> {
|
||||
private admins: MUserDefault[]
|
||||
|
||||
async prepare () {
|
||||
this.admins = await UserModel.listWithRight(UserRight.MANAGE_SERVER_FOLLOW)
|
||||
}
|
||||
|
||||
log () {
|
||||
logger.info('Notifying %d administrators of auto instance following: %s.', this.admins.length, this.actorFollow.ActorFollowing.url)
|
||||
}
|
||||
|
||||
getSetting (user: MUserWithNotificationSetting) {
|
||||
return user.NotificationSetting.autoInstanceFollowing
|
||||
}
|
||||
|
||||
getTargetUsers () {
|
||||
return this.admins
|
||||
}
|
||||
|
||||
createNotification (user: MUserWithNotificationSetting) {
|
||||
const notification = UserNotificationModel.build<UserNotificationModelForApi>({
|
||||
type: UserNotificationType.AUTO_INSTANCE_FOLLOWING,
|
||||
userId: user.id,
|
||||
actorFollowId: this.actorFollow.id
|
||||
})
|
||||
notification.ActorFollow = this.actorFollow
|
||||
|
||||
return notification
|
||||
}
|
||||
|
||||
createEmail (user: MUserWithNotificationSetting) {
|
||||
const to = { email: user.email, language: user.getLanguage() }
|
||||
|
||||
const subscription = this.actorFollow.ActorFollowing
|
||||
|
||||
return {
|
||||
to,
|
||||
subject: t('Auto platform follow', to.language),
|
||||
text: t('Your platform automatically followed {identifier}', to.language, { identifier: subscription.getIdentifier() }),
|
||||
locals: {
|
||||
action: {
|
||||
text: t('View subscription', to.language),
|
||||
url: instanceFollowingUrl
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private get actorFollow () {
|
||||
return this.payload
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
import { UserNotificationType, UserRight } from '@peertube/peertube-models'
|
||||
import { t } from '@server/helpers/i18n.js'
|
||||
import { logger } from '@server/helpers/logger.js'
|
||||
import { CONFIG } from '@server/initializers/config.js'
|
||||
import { WEBSERVER } from '@server/initializers/constants.js'
|
||||
import { isBlockedByServerOrAccount } from '@server/lib/blocklist.js'
|
||||
import { UserNotificationModel } from '@server/models/user/user-notification.js'
|
||||
import { UserModel } from '@server/models/user/user.js'
|
||||
import { MActorFollowFull, MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models/index.js'
|
||||
import { AbstractNotification } from '../common/abstract-notification.js'
|
||||
|
||||
export class FollowForInstance extends AbstractNotification<MActorFollowFull> {
|
||||
private admins: MUserDefault[]
|
||||
|
||||
async prepare () {
|
||||
this.admins = await UserModel.listWithRight(UserRight.MANAGE_SERVER_FOLLOW)
|
||||
}
|
||||
|
||||
isDisabled () {
|
||||
const follower = Object.assign(this.actorFollow.ActorFollower.Account, { Actor: this.actorFollow.ActorFollower })
|
||||
|
||||
return isBlockedByServerOrAccount(follower)
|
||||
}
|
||||
|
||||
log () {
|
||||
logger.info('Notifying %d administrators of new instance follower: %s.', this.admins.length, this.actorFollow.ActorFollower.url)
|
||||
}
|
||||
|
||||
getSetting (user: MUserWithNotificationSetting) {
|
||||
return user.NotificationSetting.newInstanceFollower
|
||||
}
|
||||
|
||||
getTargetUsers () {
|
||||
return this.admins
|
||||
}
|
||||
|
||||
createNotification (user: MUserWithNotificationSetting) {
|
||||
const notification = UserNotificationModel.build<UserNotificationModelForApi>({
|
||||
type: UserNotificationType.NEW_INSTANCE_FOLLOWER,
|
||||
userId: user.id,
|
||||
actorFollowId: this.actorFollow.id
|
||||
})
|
||||
notification.ActorFollow = this.actorFollow
|
||||
|
||||
return notification
|
||||
}
|
||||
|
||||
createEmail (user: MUserWithNotificationSetting) {
|
||||
const to = { email: user.email, language: user.getLanguage() }
|
||||
const language = user.getLanguage()
|
||||
|
||||
const context = { instanceName: CONFIG.INSTANCE.NAME, handle: this.actorFollow.ActorFollower.getIdentifier() }
|
||||
|
||||
const text = this.actorFollow.state === 'pending'
|
||||
? t('{instanceName} has a new follower, {handle}, awaiting manual approval.', language, context)
|
||||
: t('{instanceName} has a new follower: {handle}.', language, context)
|
||||
|
||||
return {
|
||||
to,
|
||||
subject: t('New follower for {instanceName}', language, { instanceName: CONFIG.INSTANCE.NAME }),
|
||||
text,
|
||||
locals: {
|
||||
action: {
|
||||
text: t('Review followers', language),
|
||||
url: WEBSERVER.URL + '/admin/follows/followers-list'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private get actorFollow () {
|
||||
return this.payload
|
||||
}
|
||||
}
|
||||
91
server/core/lib/notifier/shared/follow/follow-for-user.ts
Normal file
91
server/core/lib/notifier/shared/follow/follow-for-user.ts
Normal file
@@ -0,0 +1,91 @@
|
||||
import { UserNotificationType } from '@peertube/peertube-models'
|
||||
import { t } from '@server/helpers/i18n.js'
|
||||
import { logger } from '@server/helpers/logger.js'
|
||||
import { isBlockedByServerOrAccount } from '@server/lib/blocklist.js'
|
||||
import { UserNotificationModel } from '@server/models/user/user-notification.js'
|
||||
import { UserModel } from '@server/models/user/user.js'
|
||||
import { MActorFollowFull, MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models/index.js'
|
||||
import { AbstractNotification } from '../common/abstract-notification.js'
|
||||
|
||||
export class FollowForUser extends AbstractNotification<MActorFollowFull> {
|
||||
private followType: 'account' | 'channel'
|
||||
private user: MUserDefault
|
||||
|
||||
async prepare () {
|
||||
// Account follows one of our account?
|
||||
this.followType = 'channel'
|
||||
this.user = await UserModel.loadByChannelActorId(this.actorFollow.ActorFollowing.id)
|
||||
|
||||
// Account follows one of our channel?
|
||||
if (!this.user) {
|
||||
this.user = await UserModel.loadByAccountActorId(this.actorFollow.ActorFollowing.id)
|
||||
this.followType = 'account'
|
||||
}
|
||||
}
|
||||
|
||||
async isDisabled () {
|
||||
if (this.payload.ActorFollowing.isLocal() === false) return true
|
||||
|
||||
const followerAccount = this.actorFollow.ActorFollower.Account
|
||||
const followerAccountWithActor = Object.assign(followerAccount, { Actor: this.actorFollow.ActorFollower })
|
||||
|
||||
return isBlockedByServerOrAccount(followerAccountWithActor, this.user.Account)
|
||||
}
|
||||
|
||||
log () {
|
||||
logger.info('Notifying user %s of new follower: %s.', this.user.username, this.actorFollow.ActorFollower.Account.getDisplayName())
|
||||
}
|
||||
|
||||
getSetting (user: MUserWithNotificationSetting) {
|
||||
return user.NotificationSetting.newFollow
|
||||
}
|
||||
|
||||
getTargetUsers () {
|
||||
if (!this.user) return []
|
||||
|
||||
return [ this.user ]
|
||||
}
|
||||
|
||||
createNotification (user: MUserWithNotificationSetting) {
|
||||
const notification = UserNotificationModel.build<UserNotificationModelForApi>({
|
||||
type: UserNotificationType.NEW_FOLLOW,
|
||||
userId: user.id,
|
||||
actorFollowId: this.actorFollow.id
|
||||
})
|
||||
notification.ActorFollow = this.actorFollow
|
||||
|
||||
return notification
|
||||
}
|
||||
|
||||
createEmail (user: MUserWithNotificationSetting) {
|
||||
const to = { email: user.email, language: user.getLanguage() }
|
||||
|
||||
const following = this.actorFollow.ActorFollowing
|
||||
const follower = this.actorFollow.ActorFollower
|
||||
|
||||
const followingAccountOrChannel = Object.assign(following.VideoChannel || following.Account, { Actor: following })
|
||||
const followerAccountOrChannel = Object.assign(follower.VideoChannel || follower.Account, { Actor: follower })
|
||||
const followingName = followingAccountOrChannel.getDisplayName()
|
||||
|
||||
return {
|
||||
template: 'follower-on-channel',
|
||||
to,
|
||||
|
||||
subject: this.followType === 'account'
|
||||
? t('New follower on your account {followingName}', to.language, { followingName })
|
||||
: t('New follower on your channel {followingName}', to.language, { followingName }),
|
||||
|
||||
locals: {
|
||||
followerName: follower.Account.getDisplayName(),
|
||||
followerUrl: followerAccountOrChannel.getClientUrl(),
|
||||
followingUrl: followingAccountOrChannel.getClientUrl(),
|
||||
followingName,
|
||||
accountFollowType: this.followType === 'account'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private get actorFollow () {
|
||||
return this.payload
|
||||
}
|
||||
}
|
||||
3
server/core/lib/notifier/shared/follow/index.ts
Normal file
3
server/core/lib/notifier/shared/follow/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from './auto-follow-for-instance.js'
|
||||
export * from './follow-for-instance.js'
|
||||
export * from './follow-for-user.js'
|
||||
Reference in New Issue
Block a user