Init commit

This commit is contained in:
ShreejitPanchal
2026-05-19 19:56:02 +08:00
commit 6601501eff
4047 changed files with 2185372 additions and 0 deletions

View File

@@ -0,0 +1,68 @@
import { UserNotificationSettingValue, UserNotificationType } from '@peertube/peertube-models'
import { t } from '@server/helpers/i18n.js'
import { logger } from '@server/helpers/logger.js'
import { UserModel } from '@server/models/user/user.js'
import { MUserDefault, MUserWithNotificationSetting } from '@server/types/models/index.js'
import { AbstractNotification } from '../common/abstract-notification.js'
import { buildCollaborateToChannelNotification, NotificationCollaboratePayload } from './collaborate-to-channel-utils.js'
export class AcceptedToCollaborateToChannel extends AbstractNotification<NotificationCollaboratePayload> {
private user: MUserDefault
async prepare () {
this.user = await UserModel.loadByAccountId(this.payload.channel.accountId)
}
log () {
logger.info(
`Notifying user ${this.user.username} of accepted invitation to collaborate on channel ${this.payload.channel.Actor.getIdentifier()}`
)
}
isDisabled () {
return false
}
getSetting (_user: MUserWithNotificationSetting) {
// Always notify
return UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
}
getTargetUsers () {
return [ this.user ]
}
createNotification (user: MUserWithNotificationSetting) {
return buildCollaborateToChannelNotification({
user,
payload: this.payload,
notificationType: UserNotificationType.ACCEPTED_TO_COLLABORATE_TO_CHANNEL
})
}
// ---------------------------------------------------------------------------
createEmail (user: MUserWithNotificationSetting) {
const userLanguage = user.getLanguage()
const to = { email: user.email, language: userLanguage }
const { channel, collaborator } = this.payload
const text = t('{collaboratorName} accepted your invitation to become a collaborator of {channelName}', userLanguage, {
collaboratorName: collaborator.Account.getDisplayName(),
channelName: channel.getDisplayName()
})
return {
to,
subject: text,
text,
locals: {
action: {
text: t('Manage your channel', userLanguage),
url: channel.getClientManageUrl()
}
}
}
}
}

View File

@@ -0,0 +1,31 @@
import { UserNotificationType_Type } from '@peertube/peertube-models'
import { UserNotificationModel } from '@server/models/user/user-notification.js'
import { MChannelAccountDefault, MChannelCollaboratorAccount } from '@server/types/models/index.js'
import { MUserId, UserNotificationModelForApi } from '@server/types/models/user/index.js'
export type NotificationCollaboratePayload = {
collaborator: MChannelCollaboratorAccount
channel: MChannelAccountDefault
}
export function buildCollaborateToChannelNotification (options: {
user: MUserId
payload: NotificationCollaboratePayload
notificationType: UserNotificationType_Type
}): UserNotificationModelForApi {
const { user, payload, notificationType } = options
const notification = UserNotificationModel.build<UserNotificationModelForApi>({
type: notificationType,
userId: user.id,
channelCollaboratorId: payload.collaborator.id
})
notification.VideoChannelCollaborator = Object.assign(payload.collaborator, {
Account: payload.collaborator.Account,
Channel: payload.channel
})
return notification
}

View File

@@ -0,0 +1,76 @@
import { UserNotificationSettingValue, UserNotificationType } from '@peertube/peertube-models'
import { t } from '@server/helpers/i18n.js'
import { logger } from '@server/helpers/logger.js'
import { WEBSERVER } from '@server/initializers/constants.js'
import { AccountBlocklistModel } from '@server/models/account/account-blocklist.js'
import { UserModel } from '@server/models/user/user.js'
import { MUserDefault, MUserWithNotificationSetting } from '@server/types/models/index.js'
import { AbstractNotification } from '../common/abstract-notification.js'
import { buildCollaborateToChannelNotification, NotificationCollaboratePayload } from './collaborate-to-channel-utils.js'
export class InvitedToCollaborateToChannel extends AbstractNotification<NotificationCollaboratePayload> {
private user: MUserDefault
private channelAccountMuted = false
async prepare () {
this.user = await UserModel.loadByAccountId(this.payload.collaborator.accountId)
const hash = await AccountBlocklistModel.isAccountMutedByAccounts([ this.user.Account.id ], this.payload.channel.accountId)
this.channelAccountMuted = hash[this.user.Account.id] === true
}
log () {
logger.info(
`Notifying user ${this.user.username} of invitation to collaborate on channel ${this.payload.channel.Actor.getIdentifier()}`
)
}
isDisabled () {
return false
}
getSetting (_user: MUserWithNotificationSetting) {
if (this.channelAccountMuted) return UserNotificationSettingValue.NONE
// Always notify
return UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
}
getTargetUsers () {
return [ this.user ]
}
createNotification (user: MUserWithNotificationSetting) {
return buildCollaborateToChannelNotification({
user,
payload: this.payload,
notificationType: UserNotificationType.INVITED_TO_COLLABORATE_TO_CHANNEL
})
}
// ---------------------------------------------------------------------------
createEmail (user: MUserWithNotificationSetting) {
const userLanguage = user.getLanguage()
const to = { email: user.email, language: userLanguage }
const { channel } = this.payload
const text = t('{channelOwner} invited you to become a collaborator of channel {channelName}', userLanguage, {
channelOwner: channel.Account.getDisplayName(),
channelName: channel.getDisplayName()
})
return {
to,
subject: text,
text,
locals: {
action: {
text: t('Review the invitation', userLanguage),
url: WEBSERVER.URL + '/my-account/notifications'
}
}
}
}
}

View File

@@ -0,0 +1,68 @@
import { UserNotificationSettingValue, UserNotificationType } from '@peertube/peertube-models'
import { t } from '@server/helpers/i18n.js'
import { logger } from '@server/helpers/logger.js'
import { UserModel } from '@server/models/user/user.js'
import { MUserDefault, MUserWithNotificationSetting } from '@server/types/models/index.js'
import { AbstractNotification } from '../common/abstract-notification.js'
import { buildCollaborateToChannelNotification, NotificationCollaboratePayload } from './collaborate-to-channel-utils.js'
export class RefusedToCollaborateToChannel extends AbstractNotification<NotificationCollaboratePayload> {
private user: MUserDefault
async prepare () {
this.user = await UserModel.loadByAccountId(this.payload.channel.accountId)
}
log () {
logger.info(
`Notifying user ${this.user.username} of refused invitation to collaborate on channel ${this.payload.channel.Actor.getIdentifier()}`
)
}
isDisabled () {
return false
}
getSetting (_user: MUserWithNotificationSetting) {
// Always notify
return UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
}
getTargetUsers () {
return [ this.user ]
}
createNotification (user: MUserWithNotificationSetting) {
return buildCollaborateToChannelNotification({
user,
payload: this.payload,
notificationType: UserNotificationType.REFUSED_TO_COLLABORATE_TO_CHANNEL
})
}
// ---------------------------------------------------------------------------
createEmail (user: MUserWithNotificationSetting) {
const userLanguage = user.getLanguage()
const to = { email: user.email, language: userLanguage }
const { channel, collaborator } = this.payload
const text = t('{collaboratorName} refused your invitation to become a collaborator of {channelName}', userLanguage, {
collaboratorName: collaborator.Account.getDisplayName(),
channelName: channel.getDisplayName()
})
return {
to,
subject: text,
text,
locals: {
action: {
text: t('Manage your channel', userLanguage),
url: channel.getClientManageUrl()
}
}
}
}
}