mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-06 03:50:26 +02:00
server/server -> server/core
This commit is contained in:
parent
114327d4ce
commit
5a3d0650c9
838 changed files with 111 additions and 111 deletions
|
@ -0,0 +1,73 @@
|
|||
import { UserNotificationType } from '@peertube/peertube-models'
|
||||
import { WEBSERVER } from '@server/initializers/constants.js'
|
||||
import { AccountModel } from '@server/models/account/account.js'
|
||||
import { UserNotificationModel } from '@server/models/user/user-notification.js'
|
||||
import {
|
||||
MAbuseFull,
|
||||
MAbuseMessage,
|
||||
MAccountDefault,
|
||||
MUserWithNotificationSetting,
|
||||
UserNotificationModelForApi
|
||||
} from '@server/types/models/index.js'
|
||||
import { AbstractNotification } from '../common/abstract-notification.js'
|
||||
|
||||
type NewAbuseMessagePayload = {
|
||||
abuse: MAbuseFull
|
||||
message: MAbuseMessage
|
||||
}
|
||||
|
||||
export abstract class AbstractNewAbuseMessage extends AbstractNotification <NewAbuseMessagePayload> {
|
||||
protected messageAccount: MAccountDefault
|
||||
|
||||
async loadMessageAccount () {
|
||||
this.messageAccount = await AccountModel.load(this.message.accountId)
|
||||
}
|
||||
|
||||
getSetting (user: MUserWithNotificationSetting) {
|
||||
return user.NotificationSetting.abuseNewMessage
|
||||
}
|
||||
|
||||
createNotification (user: MUserWithNotificationSetting) {
|
||||
const notification = UserNotificationModel.build<UserNotificationModelForApi>({
|
||||
type: UserNotificationType.ABUSE_NEW_MESSAGE,
|
||||
userId: user.id,
|
||||
abuseId: this.abuse.id
|
||||
})
|
||||
notification.Abuse = this.abuse
|
||||
|
||||
return notification
|
||||
}
|
||||
|
||||
protected createEmailFor (to: string, target: 'moderator' | 'reporter') {
|
||||
const text = 'New message on report #' + this.abuse.id
|
||||
const abuseUrl = target === 'moderator'
|
||||
? WEBSERVER.URL + '/admin/moderation/abuses/list?search=%23' + this.abuse.id
|
||||
: WEBSERVER.URL + '/my-account/abuses?search=%23' + this.abuse.id
|
||||
|
||||
const action = {
|
||||
text: 'View report #' + this.abuse.id,
|
||||
url: abuseUrl
|
||||
}
|
||||
|
||||
return {
|
||||
template: 'abuse-new-message',
|
||||
to,
|
||||
subject: text,
|
||||
locals: {
|
||||
abuseId: this.abuse.id,
|
||||
abuseUrl: action.url,
|
||||
messageAccountName: this.messageAccount.getDisplayName(),
|
||||
messageText: this.message.message,
|
||||
action
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected get abuse () {
|
||||
return this.payload.abuse
|
||||
}
|
||||
|
||||
protected get message () {
|
||||
return this.payload.message
|
||||
}
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
import { logger } from '@server/helpers/logger.js'
|
||||
import { WEBSERVER } from '@server/initializers/constants.js'
|
||||
import { getAbuseTargetUrl } from '@server/lib/activitypub/url.js'
|
||||
import { UserModel } from '@server/models/user/user.js'
|
||||
import { UserNotificationModel } from '@server/models/user/user-notification.js'
|
||||
import { MAbuseFull, MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models/index.js'
|
||||
import { AbuseState, UserNotificationType } from '@peertube/peertube-models'
|
||||
import { AbstractNotification } from '../common/abstract-notification.js'
|
||||
|
||||
export class AbuseStateChangeForReporter extends AbstractNotification <MAbuseFull> {
|
||||
|
||||
private user: MUserDefault
|
||||
|
||||
async prepare () {
|
||||
const reporter = this.abuse.ReporterAccount
|
||||
if (reporter.isOwned() !== true) return
|
||||
|
||||
this.user = await UserModel.loadByAccountActorId(this.abuse.ReporterAccount.actorId)
|
||||
}
|
||||
|
||||
log () {
|
||||
logger.info('Notifying reporter of abuse % of state change.', getAbuseTargetUrl(this.abuse))
|
||||
}
|
||||
|
||||
getSetting (user: MUserWithNotificationSetting) {
|
||||
return user.NotificationSetting.abuseStateChange
|
||||
}
|
||||
|
||||
getTargetUsers () {
|
||||
if (!this.user) return []
|
||||
|
||||
return [ this.user ]
|
||||
}
|
||||
|
||||
createNotification (user: MUserWithNotificationSetting) {
|
||||
const notification = UserNotificationModel.build<UserNotificationModelForApi>({
|
||||
type: UserNotificationType.ABUSE_STATE_CHANGE,
|
||||
userId: user.id,
|
||||
abuseId: this.abuse.id
|
||||
})
|
||||
notification.Abuse = this.abuse
|
||||
|
||||
return notification
|
||||
}
|
||||
|
||||
createEmail (to: string) {
|
||||
const text = this.abuse.state === AbuseState.ACCEPTED
|
||||
? 'Report #' + this.abuse.id + ' has been accepted'
|
||||
: 'Report #' + this.abuse.id + ' has been rejected'
|
||||
|
||||
const abuseUrl = WEBSERVER.URL + '/my-account/abuses?search=%23' + this.abuse.id
|
||||
|
||||
const action = {
|
||||
text: 'View report #' + this.abuse.id,
|
||||
url: abuseUrl
|
||||
}
|
||||
|
||||
return {
|
||||
template: 'abuse-state-change',
|
||||
to,
|
||||
subject: text,
|
||||
locals: {
|
||||
action,
|
||||
abuseId: this.abuse.id,
|
||||
abuseUrl,
|
||||
isAccepted: this.abuse.state === AbuseState.ACCEPTED
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private get abuse () {
|
||||
return this.payload
|
||||
}
|
||||
}
|
4
server/core/lib/notifier/shared/abuse/index.ts
Normal file
4
server/core/lib/notifier/shared/abuse/index.ts
Normal file
|
@ -0,0 +1,4 @@
|
|||
export * from './abuse-state-change-for-reporter.js'
|
||||
export * from './new-abuse-for-moderators.js'
|
||||
export * from './new-abuse-message-for-reporter.js'
|
||||
export * from './new-abuse-message-for-moderators.js'
|
|
@ -0,0 +1,119 @@
|
|||
import { logger } from '@server/helpers/logger.js'
|
||||
import { WEBSERVER } from '@server/initializers/constants.js'
|
||||
import { getAbuseTargetUrl } from '@server/lib/activitypub/url.js'
|
||||
import { UserModel } from '@server/models/user/user.js'
|
||||
import { UserNotificationModel } from '@server/models/user/user-notification.js'
|
||||
import { MAbuseFull, MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models/index.js'
|
||||
import { UserAbuse, UserNotificationType, UserRight } from '@peertube/peertube-models'
|
||||
import { AbstractNotification } from '../common/abstract-notification.js'
|
||||
|
||||
export type NewAbusePayload = { abuse: UserAbuse, abuseInstance: MAbuseFull, reporter: string }
|
||||
|
||||
export class NewAbuseForModerators extends AbstractNotification <NewAbusePayload> {
|
||||
private moderators: MUserDefault[]
|
||||
|
||||
async prepare () {
|
||||
this.moderators = await UserModel.listWithRight(UserRight.MANAGE_ABUSES)
|
||||
}
|
||||
|
||||
log () {
|
||||
logger.info('Notifying %s user/moderators of new abuse %s.', this.moderators.length, getAbuseTargetUrl(this.payload.abuseInstance))
|
||||
}
|
||||
|
||||
getSetting (user: MUserWithNotificationSetting) {
|
||||
return user.NotificationSetting.abuseAsModerator
|
||||
}
|
||||
|
||||
getTargetUsers () {
|
||||
return this.moderators
|
||||
}
|
||||
|
||||
createNotification (user: MUserWithNotificationSetting) {
|
||||
const notification = UserNotificationModel.build<UserNotificationModelForApi>({
|
||||
type: UserNotificationType.NEW_ABUSE_FOR_MODERATORS,
|
||||
userId: user.id,
|
||||
abuseId: this.payload.abuseInstance.id
|
||||
})
|
||||
notification.Abuse = this.payload.abuseInstance
|
||||
|
||||
return notification
|
||||
}
|
||||
|
||||
createEmail (to: string) {
|
||||
const abuseInstance = this.payload.abuseInstance
|
||||
|
||||
if (abuseInstance.VideoAbuse) return this.createVideoAbuseEmail(to)
|
||||
if (abuseInstance.VideoCommentAbuse) return this.createCommentAbuseEmail(to)
|
||||
|
||||
return this.createAccountAbuseEmail(to)
|
||||
}
|
||||
|
||||
private createVideoAbuseEmail (to: string) {
|
||||
const video = this.payload.abuseInstance.VideoAbuse.Video
|
||||
const videoUrl = WEBSERVER.URL + video.getWatchStaticPath()
|
||||
|
||||
return {
|
||||
template: 'video-abuse-new',
|
||||
to,
|
||||
subject: `New video abuse report from ${this.payload.reporter}`,
|
||||
locals: {
|
||||
videoUrl,
|
||||
isLocal: video.remote === false,
|
||||
videoCreatedAt: new Date(video.createdAt).toLocaleString(),
|
||||
videoPublishedAt: new Date(video.publishedAt).toLocaleString(),
|
||||
videoName: video.name,
|
||||
reason: this.payload.abuse.reason,
|
||||
videoChannel: this.payload.abuse.video.channel,
|
||||
reporter: this.payload.reporter,
|
||||
action: this.buildEmailAction()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private createCommentAbuseEmail (to: string) {
|
||||
const comment = this.payload.abuseInstance.VideoCommentAbuse.VideoComment
|
||||
const commentUrl = WEBSERVER.URL + comment.Video.getWatchStaticPath() + ';threadId=' + comment.getThreadId()
|
||||
|
||||
return {
|
||||
template: 'video-comment-abuse-new',
|
||||
to,
|
||||
subject: `New comment abuse report from ${this.payload.reporter}`,
|
||||
locals: {
|
||||
commentUrl,
|
||||
videoName: comment.Video.name,
|
||||
isLocal: comment.isOwned(),
|
||||
commentCreatedAt: new Date(comment.createdAt).toLocaleString(),
|
||||
reason: this.payload.abuse.reason,
|
||||
flaggedAccount: this.payload.abuseInstance.FlaggedAccount.getDisplayName(),
|
||||
reporter: this.payload.reporter,
|
||||
action: this.buildEmailAction()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private createAccountAbuseEmail (to: string) {
|
||||
const account = this.payload.abuseInstance.FlaggedAccount
|
||||
const accountUrl = account.getClientUrl()
|
||||
|
||||
return {
|
||||
template: 'account-abuse-new',
|
||||
to,
|
||||
subject: `New account abuse report from ${this.payload.reporter}`,
|
||||
locals: {
|
||||
accountUrl,
|
||||
accountDisplayName: account.getDisplayName(),
|
||||
isLocal: account.isOwned(),
|
||||
reason: this.payload.abuse.reason,
|
||||
reporter: this.payload.reporter,
|
||||
action: this.buildEmailAction()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private buildEmailAction () {
|
||||
return {
|
||||
text: 'View report #' + this.payload.abuseInstance.id,
|
||||
url: WEBSERVER.URL + '/admin/moderation/abuses/list?search=%23' + this.payload.abuseInstance.id
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
import { logger } from '@server/helpers/logger.js'
|
||||
import { getAbuseTargetUrl } from '@server/lib/activitypub/url.js'
|
||||
import { UserModel } from '@server/models/user/user.js'
|
||||
import { MUserDefault } from '@server/types/models/index.js'
|
||||
import { UserRight } from '@peertube/peertube-models'
|
||||
import { AbstractNewAbuseMessage } from './abstract-new-abuse-message.js'
|
||||
|
||||
export class NewAbuseMessageForModerators extends AbstractNewAbuseMessage {
|
||||
private moderators: MUserDefault[]
|
||||
|
||||
async prepare () {
|
||||
this.moderators = await UserModel.listWithRight(UserRight.MANAGE_ABUSES)
|
||||
|
||||
// Don't notify my own message
|
||||
this.moderators = this.moderators.filter(m => m.Account.id !== this.message.accountId)
|
||||
if (this.moderators.length === 0) return
|
||||
|
||||
await this.loadMessageAccount()
|
||||
}
|
||||
|
||||
log () {
|
||||
logger.info('Notifying moderators of new abuse message on %s.', getAbuseTargetUrl(this.abuse))
|
||||
}
|
||||
|
||||
getTargetUsers () {
|
||||
return this.moderators
|
||||
}
|
||||
|
||||
createEmail (to: string) {
|
||||
return this.createEmailFor(to, 'moderator')
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
import { logger } from '@server/helpers/logger.js'
|
||||
import { getAbuseTargetUrl } from '@server/lib/activitypub/url.js'
|
||||
import { UserModel } from '@server/models/user/user.js'
|
||||
import { MUserDefault } from '@server/types/models/index.js'
|
||||
import { AbstractNewAbuseMessage } from './abstract-new-abuse-message.js'
|
||||
|
||||
export class NewAbuseMessageForReporter extends AbstractNewAbuseMessage {
|
||||
private reporter: MUserDefault
|
||||
|
||||
async prepare () {
|
||||
// Only notify our users
|
||||
if (this.abuse.ReporterAccount.isOwned() !== true) return
|
||||
|
||||
await this.loadMessageAccount()
|
||||
|
||||
const reporter = await UserModel.loadByAccountActorId(this.abuse.ReporterAccount.actorId)
|
||||
// Don't notify my own message
|
||||
if (reporter.Account.id === this.message.accountId) return
|
||||
|
||||
this.reporter = reporter
|
||||
}
|
||||
|
||||
log () {
|
||||
logger.info('Notifying reporter of new abuse message on %s.', getAbuseTargetUrl(this.abuse))
|
||||
}
|
||||
|
||||
getTargetUsers () {
|
||||
if (!this.reporter) return []
|
||||
|
||||
return [ this.reporter ]
|
||||
}
|
||||
|
||||
createEmail (to: string) {
|
||||
return this.createEmailFor(to, 'reporter')
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue