Fix abuse message exception when target is removed

This commit is contained in:
Chocobozzz 2024-08-16 10:59:07 +02:00
parent 9a6e68d505
commit c0b2bc9a08
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
5 changed files with 13 additions and 10 deletions

View File

@ -125,10 +125,13 @@ export function getLocalApproveReplyActivityPubUrl (video: MVideoUUID, comment:
// ---------------------------------------------------------------------------
export function getAbuseTargetUrl (abuse: MAbuseFull) {
// Try to fetch target URL
// If it doesn't exist anymore use abuse URL
export function getAbuseIdentifier (abuse: MAbuseFull) {
return abuse.VideoAbuse?.Video?.url ||
abuse.VideoCommentAbuse?.VideoComment?.url ||
abuse.FlaggedAccount.Actor.url
abuse.FlaggedAccount?.Actor?.url ||
abuse.id + ''
}
// ---------------------------------------------------------------------------

View File

@ -1,6 +1,6 @@
import { logger } from '@server/helpers/logger.js'
import { WEBSERVER } from '@server/initializers/constants.js'
import { getAbuseTargetUrl } from '@server/lib/activitypub/url.js'
import { getAbuseIdentifier } 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'
@ -19,7 +19,7 @@ export class AbuseStateChangeForReporter extends AbstractNotification <MAbuseFul
}
log () {
logger.info('Notifying reporter of abuse % of state change.', getAbuseTargetUrl(this.abuse))
logger.info('Notifying reporter of abuse % of state change.', getAbuseIdentifier(this.abuse))
}
getSetting (user: MUserWithNotificationSetting) {

View File

@ -1,6 +1,6 @@
import { logger } from '@server/helpers/logger.js'
import { WEBSERVER } from '@server/initializers/constants.js'
import { getAbuseTargetUrl } from '@server/lib/activitypub/url.js'
import { getAbuseIdentifier } 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'
@ -17,7 +17,7 @@ export class NewAbuseForModerators extends AbstractNotification <NewAbusePayload
}
log () {
logger.info('Notifying %s user/moderators of new abuse %s.', this.moderators.length, getAbuseTargetUrl(this.payload.abuseInstance))
logger.info('Notifying %s user/moderators of new abuse %s.', this.moderators.length, getAbuseIdentifier(this.payload.abuseInstance))
}
getSetting (user: MUserWithNotificationSetting) {

View File

@ -1,5 +1,5 @@
import { logger } from '@server/helpers/logger.js'
import { getAbuseTargetUrl } from '@server/lib/activitypub/url.js'
import { getAbuseIdentifier } 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'
@ -19,7 +19,7 @@ export class NewAbuseMessageForModerators extends AbstractNewAbuseMessage {
}
log () {
logger.info('Notifying moderators of new abuse message on %s.', getAbuseTargetUrl(this.abuse))
logger.info('Notifying moderators of new abuse message on %s.', getAbuseIdentifier(this.abuse))
}
getTargetUsers () {

View File

@ -1,5 +1,5 @@
import { logger } from '@server/helpers/logger.js'
import { getAbuseTargetUrl } from '@server/lib/activitypub/url.js'
import { getAbuseIdentifier } 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'
@ -21,7 +21,7 @@ export class NewAbuseMessageForReporter extends AbstractNewAbuseMessage {
}
log () {
logger.info('Notifying reporter of new abuse message on %s.', getAbuseTargetUrl(this.abuse))
logger.info('Notifying reporter of new abuse message on %s.', getAbuseIdentifier(this.abuse))
}
getTargetUsers () {