Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

1.3 KB
Raw Blame
import { UserNotificationSettingValue, UserNotificationType_Type } from '@peertube/peertube-models'
import { UserModel } from '@server/models/user/user.js'
import { MUserWithNotificationSetting } from '@server/types/models/index.js'
import { MChangeOwnershipFull } from '@server/types/models/video/change-ownership.js'
import { AbstractNotification } from '../common/abstract-notification.js'
import { buildChangeOwnershipNotification } from './change-ownership-utils.js'

export abstract class AbstractVideoChangeOwnershipResponse extends AbstractNotification<MChangeOwnershipFull> {
  protected users: MUserWithNotificationSetting[] = []

  async prepare () {
    this.users = await UserModel.listOwnerAndAcceptedCollaboratorsOfChannel(this.payload.Video.channelId)
  }

  isDisabled () {
    return false
  }

  getSetting (_user: MUserWithNotificationSetting) {
    return UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
  }

  getTargetUsers () {
    return this.users.filter(user => user.id !== this.payload.NextOwner.userId)
  }

  createNotification (user: MUserWithNotificationSetting) {
    return buildChangeOwnershipNotification({
      user,
      payload: this.payload,
      notificationType: this.getNotificationType()
    })
  }

  protected abstract getNotificationType (): UserNotificationType_Type
}