2024-05-17 05:12:11 -04:00
|
|
|
import { pick } from '@peertube/peertube-core-utils'
|
2024-03-29 09:25:03 -04:00
|
|
|
import {
|
|
|
|
ActivityTagObject,
|
|
|
|
ActivityTombstoneObject,
|
|
|
|
UserRight,
|
|
|
|
VideoComment,
|
|
|
|
VideoCommentForAdminOrUser,
|
|
|
|
VideoCommentObject
|
|
|
|
} from '@peertube/peertube-models'
|
2024-05-17 05:12:11 -04:00
|
|
|
import { extractMentions } from '@server/helpers/mentions.js'
|
2024-03-29 09:25:03 -04:00
|
|
|
import { getLocalApproveReplyActivityPubUrl } from '@server/lib/activitypub/url.js'
|
2024-05-17 05:12:11 -04:00
|
|
|
import { getServerActor } from '@server/models/application/application.js'
|
|
|
|
import { MAccount, MAccountId, MUserAccountId } from '@server/types/models/index.js'
|
2024-02-22 04:12:04 -05:00
|
|
|
import { Op, Order, QueryTypes, Sequelize, Transaction } from 'sequelize'
|
2020-07-07 04:57:04 -04:00
|
|
|
import {
|
|
|
|
AllowNull,
|
2024-03-29 09:25:03 -04:00
|
|
|
BelongsTo, Column,
|
2020-07-07 04:57:04 -04:00
|
|
|
CreatedAt,
|
|
|
|
DataType,
|
|
|
|
ForeignKey,
|
|
|
|
HasMany,
|
2024-02-22 04:12:04 -05:00
|
|
|
Is, Scopes,
|
2020-07-07 04:57:04 -04:00
|
|
|
Table,
|
|
|
|
UpdatedAt
|
|
|
|
} from 'sequelize-typescript'
|
2023-07-31 08:34:36 -04:00
|
|
|
import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc.js'
|
2024-02-28 10:22:51 -05:00
|
|
|
import { CONSTRAINTS_FIELDS, USER_EXPORT_MAX_ITEMS } from '../../initializers/constants.js'
|
2019-08-15 05:53:26 -04:00
|
|
|
import {
|
|
|
|
MComment,
|
2019-08-21 08:31:57 -04:00
|
|
|
MCommentAP,
|
2024-03-29 09:25:03 -04:00
|
|
|
MCommentAdminOrUserFormattable,
|
2024-02-12 04:47:52 -05:00
|
|
|
MCommentExport,
|
2019-08-20 13:05:31 -04:00
|
|
|
MCommentFormattable,
|
2019-08-15 05:53:26 -04:00
|
|
|
MCommentId,
|
|
|
|
MCommentOwner,
|
2024-03-29 09:25:03 -04:00
|
|
|
MCommentOwnerReplyVideoImmutable, MCommentOwnerVideoFeed,
|
2020-05-22 11:06:26 -04:00
|
|
|
MCommentOwnerVideoReply,
|
2024-03-29 09:25:03 -04:00
|
|
|
MVideo,
|
2020-05-22 11:06:26 -04:00
|
|
|
MVideoImmutable
|
2023-07-31 08:34:36 -04:00
|
|
|
} from '../../types/models/video/index.js'
|
|
|
|
import { VideoCommentAbuseModel } from '../abuse/video-comment-abuse.js'
|
|
|
|
import { AccountModel } from '../account/account.js'
|
|
|
|
import { ActorModel } from '../actor/actor.js'
|
2024-03-29 09:25:03 -04:00
|
|
|
import { CommentAutomaticTagModel } from '../automatic-tag/comment-automatic-tag.js'
|
2024-02-22 04:12:04 -05:00
|
|
|
import { SequelizeModel, buildLocalAccountIdsIn, buildSQLAttributes, throwIfNotValid } from '../shared/index.js'
|
2023-07-31 08:34:36 -04:00
|
|
|
import { ListVideoCommentsOptions, VideoCommentListQueryBuilder } from './sql/comment/video-comment-list-query-builder.js'
|
|
|
|
import { VideoChannelModel } from './video-channel.js'
|
|
|
|
import { VideoModel } from './video.js'
|
2017-12-22 03:14:50 -05:00
|
|
|
|
2020-07-27 10:26:25 -04:00
|
|
|
export enum ScopeNames {
|
2017-12-27 04:39:31 -05:00
|
|
|
WITH_ACCOUNT = 'WITH_ACCOUNT',
|
2017-12-27 10:11:53 -05:00
|
|
|
WITH_IN_REPLY_TO = 'WITH_IN_REPLY_TO',
|
2023-01-05 09:31:51 -05:00
|
|
|
WITH_VIDEO = 'WITH_VIDEO'
|
2017-12-22 04:50:07 -05:00
|
|
|
}
|
|
|
|
|
2019-04-23 03:50:57 -04:00
|
|
|
@Scopes(() => ({
|
2017-12-22 06:10:40 -05:00
|
|
|
[ScopeNames.WITH_ACCOUNT]: {
|
2017-12-22 04:50:07 -05:00
|
|
|
include: [
|
2017-12-27 10:11:53 -05:00
|
|
|
{
|
2019-08-15 05:53:26 -04:00
|
|
|
model: AccountModel
|
2017-12-27 10:11:53 -05:00
|
|
|
}
|
2019-04-23 03:50:57 -04:00
|
|
|
]
|
2017-12-27 04:39:31 -05:00
|
|
|
},
|
|
|
|
[ScopeNames.WITH_IN_REPLY_TO]: {
|
|
|
|
include: [
|
|
|
|
{
|
2019-04-23 03:50:57 -04:00
|
|
|
model: VideoCommentModel,
|
2017-12-28 05:16:08 -05:00
|
|
|
as: 'InReplyToVideoComment'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
[ScopeNames.WITH_VIDEO]: {
|
|
|
|
include: [
|
|
|
|
{
|
2019-04-23 03:50:57 -04:00
|
|
|
model: VideoModel,
|
2018-01-04 05:19:16 -05:00
|
|
|
required: true,
|
|
|
|
include: [
|
|
|
|
{
|
2023-10-31 05:02:19 -04:00
|
|
|
model: VideoChannelModel.unscoped(),
|
|
|
|
attributes: [ 'id', 'accountId' ],
|
2018-01-04 05:19:16 -05:00
|
|
|
required: true,
|
|
|
|
include: [
|
|
|
|
{
|
2023-10-31 05:02:19 -04:00
|
|
|
attributes: [ 'id', 'url' ],
|
|
|
|
model: ActorModel.unscoped(),
|
2019-08-15 05:53:26 -04:00
|
|
|
required: true
|
2023-10-31 05:02:19 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
attributes: [ 'id' ],
|
|
|
|
model: AccountModel.unscoped(),
|
|
|
|
required: true,
|
|
|
|
include: [
|
|
|
|
{
|
|
|
|
attributes: [ 'id', 'url' ],
|
|
|
|
model: ActorModel.unscoped(),
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
]
|
2018-01-04 05:19:16 -05:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
2017-12-27 04:39:31 -05:00
|
|
|
}
|
2019-04-23 03:50:57 -04:00
|
|
|
]
|
2017-12-22 04:50:07 -05:00
|
|
|
}
|
2019-04-23 03:50:57 -04:00
|
|
|
}))
|
2017-12-22 03:14:50 -05:00
|
|
|
@Table({
|
|
|
|
tableName: 'videoComment',
|
|
|
|
indexes: [
|
|
|
|
{
|
|
|
|
fields: [ 'videoId' ]
|
2017-12-22 04:50:07 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
fields: [ 'videoId', 'originCommentId' ]
|
2018-01-26 08:14:43 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
fields: [ 'url' ],
|
|
|
|
unique: true
|
2018-07-23 14:13:30 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
fields: [ 'accountId' ]
|
2020-06-05 04:42:36 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
fields: [
|
|
|
|
{ name: 'createdAt', order: 'DESC' }
|
|
|
|
]
|
2017-12-22 03:14:50 -05:00
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
2024-02-22 04:12:04 -05:00
|
|
|
export class VideoCommentModel extends SequelizeModel<VideoCommentModel> {
|
2017-12-22 03:14:50 -05:00
|
|
|
@CreatedAt
|
|
|
|
createdAt: Date
|
|
|
|
|
|
|
|
@UpdatedAt
|
|
|
|
updatedAt: Date
|
|
|
|
|
2019-11-15 13:05:08 -05:00
|
|
|
@AllowNull(true)
|
|
|
|
@Column(DataType.DATE)
|
|
|
|
deletedAt: Date
|
|
|
|
|
2017-12-22 03:14:50 -05:00
|
|
|
@AllowNull(false)
|
|
|
|
@Is('VideoCommentUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'url'))
|
|
|
|
@Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEOS.URL.max))
|
|
|
|
url: string
|
|
|
|
|
|
|
|
@AllowNull(false)
|
|
|
|
@Column(DataType.TEXT)
|
|
|
|
text: string
|
|
|
|
|
2024-03-29 09:25:03 -04:00
|
|
|
@AllowNull(false)
|
|
|
|
@Column
|
|
|
|
heldForReview: boolean
|
|
|
|
|
|
|
|
@AllowNull(true)
|
|
|
|
@Column
|
|
|
|
replyApproval: string
|
|
|
|
|
2017-12-22 03:14:50 -05:00
|
|
|
@ForeignKey(() => VideoCommentModel)
|
|
|
|
@Column
|
|
|
|
originCommentId: number
|
|
|
|
|
|
|
|
@BelongsTo(() => VideoCommentModel, {
|
|
|
|
foreignKey: {
|
2017-12-28 05:45:10 -05:00
|
|
|
name: 'originCommentId',
|
2017-12-22 03:14:50 -05:00
|
|
|
allowNull: true
|
|
|
|
},
|
2017-12-28 05:45:10 -05:00
|
|
|
as: 'OriginVideoComment',
|
2017-12-22 03:14:50 -05:00
|
|
|
onDelete: 'CASCADE'
|
|
|
|
})
|
2023-07-31 08:34:36 -04:00
|
|
|
OriginVideoComment: Awaited<VideoCommentModel>
|
2017-12-22 03:14:50 -05:00
|
|
|
|
|
|
|
@ForeignKey(() => VideoCommentModel)
|
|
|
|
@Column
|
|
|
|
inReplyToCommentId: number
|
|
|
|
|
|
|
|
@BelongsTo(() => VideoCommentModel, {
|
|
|
|
foreignKey: {
|
2017-12-28 05:45:10 -05:00
|
|
|
name: 'inReplyToCommentId',
|
2017-12-22 03:14:50 -05:00
|
|
|
allowNull: true
|
|
|
|
},
|
2017-12-28 05:16:08 -05:00
|
|
|
as: 'InReplyToVideoComment',
|
2017-12-22 03:14:50 -05:00
|
|
|
onDelete: 'CASCADE'
|
|
|
|
})
|
2023-07-31 08:34:36 -04:00
|
|
|
InReplyToVideoComment: Awaited<VideoCommentModel> | null
|
2017-12-22 03:14:50 -05:00
|
|
|
|
|
|
|
@ForeignKey(() => VideoModel)
|
|
|
|
@Column
|
|
|
|
videoId: number
|
|
|
|
|
|
|
|
@BelongsTo(() => VideoModel, {
|
|
|
|
foreignKey: {
|
|
|
|
allowNull: false
|
|
|
|
},
|
|
|
|
onDelete: 'CASCADE'
|
|
|
|
})
|
2023-07-31 08:34:36 -04:00
|
|
|
Video: Awaited<VideoModel>
|
2017-12-22 03:14:50 -05:00
|
|
|
|
2017-12-22 06:10:40 -05:00
|
|
|
@ForeignKey(() => AccountModel)
|
2017-12-22 03:14:50 -05:00
|
|
|
@Column
|
2017-12-22 06:10:40 -05:00
|
|
|
accountId: number
|
2017-12-22 03:14:50 -05:00
|
|
|
|
2017-12-22 06:10:40 -05:00
|
|
|
@BelongsTo(() => AccountModel, {
|
2017-12-22 03:14:50 -05:00
|
|
|
foreignKey: {
|
2019-11-15 13:05:08 -05:00
|
|
|
allowNull: true
|
2017-12-22 03:14:50 -05:00
|
|
|
},
|
|
|
|
onDelete: 'CASCADE'
|
|
|
|
})
|
2023-07-31 08:34:36 -04:00
|
|
|
Account: Awaited<AccountModel>
|
2017-12-22 03:14:50 -05:00
|
|
|
|
2020-07-07 04:57:04 -04:00
|
|
|
@HasMany(() => VideoCommentAbuseModel, {
|
|
|
|
foreignKey: {
|
2020-07-08 09:51:46 -04:00
|
|
|
name: 'videoCommentId',
|
2020-07-07 04:57:04 -04:00
|
|
|
allowNull: true
|
|
|
|
},
|
|
|
|
onDelete: 'set null'
|
|
|
|
})
|
2023-07-31 08:34:36 -04:00
|
|
|
CommentAbuses: Awaited<VideoCommentAbuseModel>[]
|
2020-07-07 04:57:04 -04:00
|
|
|
|
2024-03-29 09:25:03 -04:00
|
|
|
@HasMany(() => CommentAutomaticTagModel, {
|
|
|
|
foreignKey: 'commentId',
|
|
|
|
onDelete: 'CASCADE'
|
|
|
|
})
|
|
|
|
CommentAutomaticTags: Awaited<CommentAutomaticTagModel>[]
|
|
|
|
|
2023-01-09 04:29:23 -05:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
static getSQLAttributes (tableName: string, aliasPrefix = '') {
|
|
|
|
return buildSQLAttributes({
|
|
|
|
model: this,
|
|
|
|
tableName,
|
|
|
|
aliasPrefix
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2024-02-22 04:12:04 -05:00
|
|
|
static loadById (id: number, transaction?: Transaction): Promise<MComment> {
|
|
|
|
const query = {
|
2017-12-22 04:50:07 -05:00
|
|
|
where: {
|
|
|
|
id
|
2024-02-22 04:12:04 -05:00
|
|
|
},
|
|
|
|
transaction
|
2017-12-22 04:50:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return VideoCommentModel.findOne(query)
|
|
|
|
}
|
|
|
|
|
2024-02-22 04:12:04 -05:00
|
|
|
static loadByIdAndPopulateVideoAndAccountAndReply (id: number, transaction?: Transaction): Promise<MCommentOwnerVideoReply> {
|
|
|
|
const query = {
|
2017-12-28 05:16:08 -05:00
|
|
|
where: {
|
|
|
|
id
|
2024-02-22 04:12:04 -05:00
|
|
|
},
|
|
|
|
transaction
|
2017-12-28 05:16:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return VideoCommentModel
|
|
|
|
.scope([ ScopeNames.WITH_VIDEO, ScopeNames.WITH_ACCOUNT, ScopeNames.WITH_IN_REPLY_TO ])
|
|
|
|
.findOne(query)
|
|
|
|
}
|
|
|
|
|
2024-03-29 09:25:03 -04:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
static loadByUrlAndPopulateAccountAndVideoAndReply (url: string, transaction?: Transaction): Promise<MCommentOwnerVideoReply> {
|
2024-02-22 04:12:04 -05:00
|
|
|
const query = {
|
2017-12-22 03:14:50 -05:00
|
|
|
where: {
|
|
|
|
url
|
2024-02-22 04:12:04 -05:00
|
|
|
},
|
|
|
|
transaction
|
2017-12-22 03:14:50 -05:00
|
|
|
}
|
|
|
|
|
2024-03-29 09:25:03 -04:00
|
|
|
return VideoCommentModel.scope([ ScopeNames.WITH_ACCOUNT, ScopeNames.WITH_VIDEO, ScopeNames.WITH_IN_REPLY_TO ]).findOne(query)
|
2017-12-22 03:14:50 -05:00
|
|
|
}
|
2017-12-22 04:50:07 -05:00
|
|
|
|
2024-03-29 09:25:03 -04:00
|
|
|
static loadByUrlAndPopulateReplyAndVideoImmutableAndAccount (
|
|
|
|
url: string,
|
|
|
|
transaction?: Transaction
|
|
|
|
): Promise<MCommentOwnerReplyVideoImmutable> {
|
2024-02-22 04:12:04 -05:00
|
|
|
const query = {
|
2018-01-04 05:19:16 -05:00
|
|
|
where: {
|
|
|
|
url
|
2019-08-06 11:19:53 -04:00
|
|
|
},
|
|
|
|
include: [
|
|
|
|
{
|
2024-03-29 09:25:03 -04:00
|
|
|
attributes: [ 'id', 'uuid', 'url', 'remote' ],
|
2019-08-06 11:19:53 -04:00
|
|
|
model: VideoModel.unscoped()
|
|
|
|
}
|
2024-02-22 04:12:04 -05:00
|
|
|
],
|
|
|
|
transaction
|
2018-01-04 05:19:16 -05:00
|
|
|
}
|
|
|
|
|
2019-08-06 11:19:53 -04:00
|
|
|
return VideoCommentModel.scope([ ScopeNames.WITH_IN_REPLY_TO, ScopeNames.WITH_ACCOUNT ]).findOne(query)
|
2018-01-04 05:19:16 -05:00
|
|
|
}
|
|
|
|
|
2024-03-29 09:25:03 -04:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2020-11-13 10:38:23 -05:00
|
|
|
static listCommentsForApi (parameters: {
|
|
|
|
start: number
|
|
|
|
count: number
|
|
|
|
sort: string
|
|
|
|
|
2024-03-29 09:25:03 -04:00
|
|
|
autoTagOfAccountId: number
|
|
|
|
|
|
|
|
videoAccountOwnerId?: number
|
|
|
|
videoChannelOwnerId?: number
|
|
|
|
|
2022-08-12 05:05:11 -04:00
|
|
|
onLocalVideo?: boolean
|
2020-11-13 10:38:23 -05:00
|
|
|
isLocal?: boolean
|
2024-03-29 09:25:03 -04:00
|
|
|
|
2020-11-13 10:38:23 -05:00
|
|
|
search?: string
|
|
|
|
searchAccount?: string
|
|
|
|
searchVideo?: string
|
2024-03-29 09:25:03 -04:00
|
|
|
|
|
|
|
heldForReview: boolean
|
|
|
|
|
|
|
|
videoId?: number
|
|
|
|
videoChannelId?: number
|
|
|
|
autoTagOneOf?: string[]
|
2020-11-13 10:38:23 -05:00
|
|
|
}) {
|
2023-01-05 09:31:51 -05:00
|
|
|
const queryOptions: ListVideoCommentsOptions = {
|
2024-03-29 09:25:03 -04:00
|
|
|
...pick(parameters, [
|
|
|
|
'start',
|
|
|
|
'count',
|
|
|
|
'sort',
|
|
|
|
'isLocal',
|
|
|
|
'search',
|
|
|
|
'searchVideo',
|
|
|
|
'searchAccount',
|
|
|
|
'onLocalVideo',
|
|
|
|
'videoId',
|
|
|
|
'videoChannelId',
|
|
|
|
'autoTagOneOf',
|
|
|
|
'autoTagOfAccountId',
|
|
|
|
'videoAccountOwnerId',
|
|
|
|
'videoChannelOwnerId',
|
|
|
|
'heldForReview'
|
|
|
|
]),
|
2020-11-13 10:38:23 -05:00
|
|
|
|
2023-01-05 09:31:51 -05:00
|
|
|
selectType: 'api',
|
|
|
|
notDeleted: true
|
2020-11-16 05:55:17 -05:00
|
|
|
}
|
2020-11-13 10:38:23 -05:00
|
|
|
|
2022-02-28 02:34:43 -05:00
|
|
|
return Promise.all([
|
2024-03-29 09:25:03 -04:00
|
|
|
new VideoCommentListQueryBuilder(VideoCommentModel.sequelize, queryOptions).listComments<MCommentAdminOrUserFormattable>(),
|
2023-01-05 09:31:51 -05:00
|
|
|
new VideoCommentListQueryBuilder(VideoCommentModel.sequelize, queryOptions).countComments()
|
|
|
|
]).then(([ rows, count ]) => {
|
|
|
|
return { total: count, data: rows }
|
|
|
|
})
|
2020-11-13 10:38:23 -05:00
|
|
|
}
|
|
|
|
|
2019-07-18 08:28:37 -04:00
|
|
|
static async listThreadsForApi (parameters: {
|
2024-03-29 09:25:03 -04:00
|
|
|
video: MVideo
|
2020-01-31 10:56:52 -05:00
|
|
|
start: number
|
|
|
|
count: number
|
|
|
|
sort: string
|
2019-08-15 05:53:26 -04:00
|
|
|
user?: MUserAccountId
|
2019-07-18 08:28:37 -04:00
|
|
|
}) {
|
2024-03-29 09:25:03 -04:00
|
|
|
const { video, user } = parameters
|
2019-07-18 08:28:37 -04:00
|
|
|
|
2024-03-29 09:25:03 -04:00
|
|
|
const { blockerAccountIds, canSeeHeldForReview } = await VideoCommentModel.buildBlockerAccountIdsAndCanSeeHeldForReview({ user, video })
|
2018-10-12 09:26:04 -04:00
|
|
|
|
2023-01-05 09:31:51 -05:00
|
|
|
const commonOptions: ListVideoCommentsOptions = {
|
|
|
|
selectType: 'api',
|
2024-03-29 09:25:03 -04:00
|
|
|
videoId: video.id,
|
|
|
|
blockerAccountIds,
|
|
|
|
|
|
|
|
heldForReview: canSeeHeldForReview
|
|
|
|
? undefined // Display all comments for video owner or moderator
|
|
|
|
: false,
|
|
|
|
heldForReviewAccountIdException: user?.Account?.id
|
2021-02-19 03:50:13 -05:00
|
|
|
}
|
|
|
|
|
2023-01-05 09:31:51 -05:00
|
|
|
const listOptions: ListVideoCommentsOptions = {
|
|
|
|
...commonOptions,
|
|
|
|
...pick(parameters, [ 'sort', 'start', 'count' ]),
|
|
|
|
|
|
|
|
isThread: true,
|
|
|
|
includeReplyCounters: true
|
2017-12-22 04:50:07 -05:00
|
|
|
}
|
|
|
|
|
2023-01-05 09:31:51 -05:00
|
|
|
const countOptions: ListVideoCommentsOptions = {
|
|
|
|
...commonOptions,
|
2018-10-12 09:26:04 -04:00
|
|
|
|
2023-01-05 09:31:51 -05:00
|
|
|
isThread: true
|
|
|
|
}
|
2022-02-28 02:34:43 -05:00
|
|
|
|
2023-01-05 09:31:51 -05:00
|
|
|
const notDeletedCountOptions: ListVideoCommentsOptions = {
|
|
|
|
...commonOptions,
|
|
|
|
|
|
|
|
notDeleted: true
|
2021-02-19 03:50:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return Promise.all([
|
2024-03-29 09:25:03 -04:00
|
|
|
new VideoCommentListQueryBuilder(VideoCommentModel.sequelize, listOptions).listComments<MCommentAdminOrUserFormattable>(),
|
2023-01-05 09:31:51 -05:00
|
|
|
new VideoCommentListQueryBuilder(VideoCommentModel.sequelize, countOptions).countComments(),
|
|
|
|
new VideoCommentListQueryBuilder(VideoCommentModel.sequelize, notDeletedCountOptions).countComments()
|
2022-02-28 02:34:43 -05:00
|
|
|
]).then(([ rows, count, totalNotDeletedComments ]) => {
|
2021-02-19 03:50:13 -05:00
|
|
|
return { total: count, data: rows, totalNotDeletedComments }
|
|
|
|
})
|
2017-12-22 04:50:07 -05:00
|
|
|
}
|
|
|
|
|
2019-07-18 08:28:37 -04:00
|
|
|
static async listThreadCommentsForApi (parameters: {
|
2024-03-29 09:25:03 -04:00
|
|
|
video: MVideo
|
2020-01-31 10:56:52 -05:00
|
|
|
threadId: number
|
2019-08-15 05:53:26 -04:00
|
|
|
user?: MUserAccountId
|
2019-07-18 08:28:37 -04:00
|
|
|
}) {
|
2024-03-29 09:25:03 -04:00
|
|
|
const { user, video, threadId } = parameters
|
2019-07-18 08:28:37 -04:00
|
|
|
|
2024-03-29 09:25:03 -04:00
|
|
|
const { blockerAccountIds, canSeeHeldForReview } = await VideoCommentModel.buildBlockerAccountIdsAndCanSeeHeldForReview({ user, video })
|
2018-10-12 09:26:04 -04:00
|
|
|
|
2023-01-05 09:31:51 -05:00
|
|
|
const queryOptions: ListVideoCommentsOptions = {
|
2024-03-29 09:25:03 -04:00
|
|
|
threadId,
|
2017-12-22 04:50:07 -05:00
|
|
|
|
2024-03-29 09:25:03 -04:00
|
|
|
videoId: video.id,
|
2023-01-05 09:31:51 -05:00
|
|
|
selectType: 'api',
|
|
|
|
sort: 'createdAt',
|
|
|
|
|
|
|
|
blockerAccountIds,
|
2024-03-29 09:25:03 -04:00
|
|
|
includeReplyCounters: true,
|
|
|
|
|
|
|
|
heldForReview: canSeeHeldForReview
|
|
|
|
? undefined // Display all comments for video owner or moderator
|
|
|
|
: false,
|
|
|
|
heldForReviewAccountIdException: user?.Account?.id
|
2023-01-05 09:31:51 -05:00
|
|
|
}
|
2018-10-12 09:26:04 -04:00
|
|
|
|
2022-02-28 02:34:43 -05:00
|
|
|
return Promise.all([
|
2024-03-29 09:25:03 -04:00
|
|
|
new VideoCommentListQueryBuilder(VideoCommentModel.sequelize, queryOptions).listComments<MCommentAdminOrUserFormattable>(),
|
2023-01-05 09:31:51 -05:00
|
|
|
new VideoCommentListQueryBuilder(VideoCommentModel.sequelize, queryOptions).countComments()
|
|
|
|
]).then(([ rows, count ]) => {
|
|
|
|
return { total: count, data: rows }
|
|
|
|
})
|
2017-12-22 04:50:07 -05:00
|
|
|
}
|
|
|
|
|
2024-03-29 09:25:03 -04:00
|
|
|
static listThreadParentComments (options: {
|
|
|
|
comment: MCommentId
|
|
|
|
transaction?: Transaction
|
|
|
|
order?: 'ASC' | 'DESC'
|
|
|
|
}): Promise<MCommentOwner[]> {
|
|
|
|
const { comment, transaction, order = 'ASC' } = options
|
|
|
|
|
2018-01-05 05:19:25 -05:00
|
|
|
const query = {
|
2019-04-18 05:28:17 -04:00
|
|
|
order: [ [ 'createdAt', order ] ] as Order,
|
2018-01-05 05:19:25 -05:00
|
|
|
where: {
|
|
|
|
id: {
|
2020-01-31 10:56:52 -05:00
|
|
|
[Op.in]: Sequelize.literal('(' +
|
2018-03-21 06:17:01 -04:00
|
|
|
'WITH RECURSIVE children (id, "inReplyToCommentId") AS ( ' +
|
2019-01-04 02:56:20 -05:00
|
|
|
`SELECT id, "inReplyToCommentId" FROM "videoComment" WHERE id = ${comment.id} ` +
|
|
|
|
'UNION ' +
|
|
|
|
'SELECT "parent"."id", "parent"."inReplyToCommentId" FROM "videoComment" "parent" ' +
|
|
|
|
'INNER JOIN "children" ON "children"."inReplyToCommentId" = "parent"."id"' +
|
|
|
|
') ' +
|
2018-03-21 06:17:01 -04:00
|
|
|
'SELECT id FROM children' +
|
|
|
|
')'),
|
2020-01-31 10:56:52 -05:00
|
|
|
[Op.ne]: comment.id
|
2018-01-05 05:19:25 -05:00
|
|
|
}
|
|
|
|
},
|
2024-03-29 09:25:03 -04:00
|
|
|
transaction
|
2018-01-05 05:19:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return VideoCommentModel
|
|
|
|
.scope([ ScopeNames.WITH_ACCOUNT ])
|
|
|
|
.findAll(query)
|
|
|
|
}
|
|
|
|
|
2023-01-05 09:31:51 -05:00
|
|
|
static async listAndCountByVideoForAP (parameters: {
|
|
|
|
video: MVideoImmutable
|
|
|
|
start: number
|
|
|
|
count: number
|
|
|
|
}) {
|
|
|
|
const { video } = parameters
|
|
|
|
|
|
|
|
const blockerAccountIds = await VideoCommentModel.buildBlockerAccountIds({ user: null })
|
|
|
|
|
|
|
|
const queryOptions: ListVideoCommentsOptions = {
|
|
|
|
...pick(parameters, [ 'start', 'count' ]),
|
|
|
|
|
|
|
|
selectType: 'comment-only',
|
2020-05-22 11:06:26 -04:00
|
|
|
videoId: video.id,
|
2023-01-05 09:31:51 -05:00
|
|
|
sort: 'createdAt',
|
2020-05-22 11:06:26 -04:00
|
|
|
|
2024-03-29 09:25:03 -04:00
|
|
|
heldForReview: false,
|
|
|
|
|
2023-01-05 09:31:51 -05:00
|
|
|
blockerAccountIds
|
2018-05-25 10:21:16 -04:00
|
|
|
}
|
|
|
|
|
2022-02-28 02:34:43 -05:00
|
|
|
return Promise.all([
|
2023-01-05 09:31:51 -05:00
|
|
|
new VideoCommentListQueryBuilder(VideoCommentModel.sequelize, queryOptions).listComments<MComment>(),
|
|
|
|
new VideoCommentListQueryBuilder(VideoCommentModel.sequelize, queryOptions).countComments()
|
|
|
|
]).then(([ rows, count ]) => {
|
|
|
|
return { total: count, data: rows }
|
|
|
|
})
|
2018-05-25 10:21:16 -04:00
|
|
|
}
|
|
|
|
|
2020-06-27 07:12:30 -04:00
|
|
|
static async listForFeed (parameters: {
|
|
|
|
start: number
|
|
|
|
count: number
|
|
|
|
videoId?: number
|
2024-03-29 09:25:03 -04:00
|
|
|
videoAccountOwnerId?: number
|
|
|
|
videoChannelOwnerId?: number
|
2023-01-05 09:31:51 -05:00
|
|
|
}) {
|
|
|
|
const blockerAccountIds = await VideoCommentModel.buildBlockerAccountIds({ user: null })
|
2020-06-27 07:12:30 -04:00
|
|
|
|
2023-01-05 09:31:51 -05:00
|
|
|
const queryOptions: ListVideoCommentsOptions = {
|
2024-03-29 09:25:03 -04:00
|
|
|
...pick(parameters, [ 'start', 'count', 'videoAccountOwnerId', 'videoId', 'videoChannelOwnerId' ]),
|
2020-08-20 02:52:16 -04:00
|
|
|
|
2023-01-05 09:31:51 -05:00
|
|
|
selectType: 'feed',
|
2020-08-20 02:52:16 -04:00
|
|
|
|
2023-01-05 09:31:51 -05:00
|
|
|
sort: '-createdAt',
|
|
|
|
onPublicVideo: true,
|
2024-03-29 09:25:03 -04:00
|
|
|
|
2023-01-05 09:31:51 -05:00
|
|
|
notDeleted: true,
|
2024-03-29 09:25:03 -04:00
|
|
|
heldForReview: false,
|
2020-05-06 08:12:12 -04:00
|
|
|
|
2023-01-05 09:31:51 -05:00
|
|
|
blockerAccountIds
|
2018-06-08 14:34:37 -04:00
|
|
|
}
|
|
|
|
|
2023-01-05 09:31:51 -05:00
|
|
|
return new VideoCommentListQueryBuilder(VideoCommentModel.sequelize, queryOptions).listComments<MCommentOwnerVideoFeed>()
|
2018-06-08 14:34:37 -04:00
|
|
|
}
|
|
|
|
|
2020-05-14 10:56:15 -04:00
|
|
|
static listForBulkDelete (ofAccount: MAccount, filter: { onVideosOfAccount?: MAccountId } = {}) {
|
2023-01-05 09:31:51 -05:00
|
|
|
const queryOptions: ListVideoCommentsOptions = {
|
|
|
|
selectType: 'comment-only',
|
2020-05-14 10:56:15 -04:00
|
|
|
|
2023-01-05 09:31:51 -05:00
|
|
|
accountId: ofAccount.id,
|
|
|
|
videoAccountOwnerId: filter.onVideosOfAccount?.id,
|
|
|
|
|
2024-03-29 09:25:03 -04:00
|
|
|
heldForReview: undefined,
|
|
|
|
|
2023-01-05 09:31:51 -05:00
|
|
|
notDeleted: true,
|
|
|
|
count: 5000
|
2020-05-14 10:56:15 -04:00
|
|
|
}
|
|
|
|
|
2023-01-05 09:31:51 -05:00
|
|
|
return new VideoCommentListQueryBuilder(VideoCommentModel.sequelize, queryOptions).listComments<MComment>()
|
2020-05-14 10:56:15 -04:00
|
|
|
}
|
|
|
|
|
2024-02-12 04:47:52 -05:00
|
|
|
static listForExport (ofAccountId: number): Promise<MCommentExport[]> {
|
2024-02-28 10:22:51 -05:00
|
|
|
return VideoCommentModel.findAll({
|
2024-03-29 09:25:03 -04:00
|
|
|
attributes: [ 'id', 'url', 'text', 'createdAt' ],
|
2024-02-12 04:47:52 -05:00
|
|
|
where: {
|
|
|
|
accountId: ofAccountId,
|
|
|
|
deletedAt: null
|
|
|
|
},
|
|
|
|
include: [
|
|
|
|
{
|
2024-03-29 09:25:03 -04:00
|
|
|
attributes: [ 'id', 'uuid', 'url' ],
|
2024-02-12 04:47:52 -05:00
|
|
|
required: true,
|
|
|
|
model: VideoModel.unscoped()
|
|
|
|
},
|
|
|
|
{
|
|
|
|
attributes: [ 'url' ],
|
|
|
|
required: false,
|
|
|
|
model: VideoCommentModel,
|
|
|
|
as: 'InReplyToVideoComment'
|
|
|
|
}
|
2024-02-28 10:22:51 -05:00
|
|
|
],
|
|
|
|
limit: USER_EXPORT_MAX_ITEMS
|
|
|
|
})
|
2024-02-12 04:47:52 -05:00
|
|
|
}
|
|
|
|
|
2024-03-29 09:25:03 -04:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2018-02-28 12:04:46 -05:00
|
|
|
static async getStats () {
|
2024-05-17 05:12:11 -04:00
|
|
|
const where = {
|
2024-03-29 09:25:03 -04:00
|
|
|
deletedAt: null,
|
|
|
|
heldForReview: false
|
2024-05-17 05:12:11 -04:00
|
|
|
}
|
|
|
|
|
2018-02-28 12:04:46 -05:00
|
|
|
const totalLocalVideoComments = await VideoCommentModel.count({
|
2024-05-17 05:12:11 -04:00
|
|
|
where,
|
2018-02-28 12:04:46 -05:00
|
|
|
include: [
|
|
|
|
{
|
2022-06-17 10:16:28 -04:00
|
|
|
model: AccountModel.unscoped(),
|
2018-02-28 12:04:46 -05:00
|
|
|
required: true,
|
|
|
|
include: [
|
|
|
|
{
|
2022-06-17 10:16:28 -04:00
|
|
|
model: ActorModel.unscoped(),
|
2018-02-28 12:04:46 -05:00
|
|
|
required: true,
|
|
|
|
where: {
|
|
|
|
serverId: null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
2024-05-17 05:12:11 -04:00
|
|
|
const totalVideoComments = await VideoCommentModel.count({ where })
|
2018-02-28 12:04:46 -05:00
|
|
|
|
|
|
|
return {
|
|
|
|
totalLocalVideoComments,
|
|
|
|
totalVideoComments
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-29 09:25:03 -04:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2021-02-26 10:26:27 -05:00
|
|
|
static listRemoteCommentUrlsOfLocalVideos () {
|
|
|
|
const query = `SELECT "videoComment".url FROM "videoComment" ` +
|
|
|
|
`INNER JOIN account ON account.id = "videoComment"."accountId" ` +
|
|
|
|
`INNER JOIN actor ON actor.id = "account"."actorId" AND actor."serverId" IS NOT NULL ` +
|
|
|
|
`INNER JOIN video ON video.id = "videoComment"."videoId" AND video.remote IS FALSE`
|
|
|
|
|
|
|
|
return VideoCommentModel.sequelize.query<{ url: string }>(query, {
|
|
|
|
type: QueryTypes.SELECT,
|
|
|
|
raw: true
|
|
|
|
}).then(rows => rows.map(r => r.url))
|
|
|
|
}
|
|
|
|
|
2019-03-19 11:23:02 -04:00
|
|
|
static cleanOldCommentsOf (videoId: number, beforeUpdatedAt: Date) {
|
|
|
|
const query = {
|
|
|
|
where: {
|
|
|
|
updatedAt: {
|
2019-04-18 05:28:17 -04:00
|
|
|
[Op.lt]: beforeUpdatedAt
|
2019-03-19 11:23:02 -04:00
|
|
|
},
|
2019-08-06 11:19:53 -04:00
|
|
|
videoId,
|
|
|
|
accountId: {
|
|
|
|
[Op.notIn]: buildLocalAccountIdsIn()
|
2020-05-14 10:56:15 -04:00
|
|
|
},
|
|
|
|
// Do not delete Tombstones
|
|
|
|
deletedAt: null
|
2019-08-06 11:19:53 -04:00
|
|
|
}
|
2019-03-19 11:23:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return VideoCommentModel.destroy(query)
|
|
|
|
}
|
|
|
|
|
2024-03-29 09:25:03 -04:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2018-12-26 04:36:24 -05:00
|
|
|
getCommentStaticPath () {
|
|
|
|
return this.Video.getWatchStaticPath() + ';threadId=' + this.getThreadId()
|
|
|
|
}
|
|
|
|
|
2024-03-29 09:25:03 -04:00
|
|
|
getCommentUserReviewPath () {
|
|
|
|
return '/my-account/videos/comments?search=heldForReview:true'
|
|
|
|
}
|
|
|
|
|
2018-01-05 05:19:25 -05:00
|
|
|
getThreadId (): number {
|
|
|
|
return this.originCommentId || this.id
|
|
|
|
}
|
|
|
|
|
2018-01-04 05:19:16 -05:00
|
|
|
isOwned () {
|
2023-01-05 09:31:51 -05:00
|
|
|
if (!this.Account) return false
|
2019-11-15 13:05:08 -05:00
|
|
|
|
2018-01-04 05:19:16 -05:00
|
|
|
return this.Account.isOwned()
|
|
|
|
}
|
|
|
|
|
2021-06-15 03:17:19 -04:00
|
|
|
markAsDeleted () {
|
|
|
|
this.text = ''
|
|
|
|
this.deletedAt = new Date()
|
|
|
|
this.accountId = null
|
|
|
|
}
|
|
|
|
|
2019-11-15 13:05:08 -05:00
|
|
|
isDeleted () {
|
2020-01-31 10:56:52 -05:00
|
|
|
return this.deletedAt !== null
|
2019-11-15 13:05:08 -05:00
|
|
|
}
|
|
|
|
|
2019-01-04 02:56:20 -05:00
|
|
|
extractMentions () {
|
2023-07-31 08:34:36 -04:00
|
|
|
return extractMentions(this.text, this.isOwned())
|
2019-01-04 02:56:20 -05:00
|
|
|
}
|
|
|
|
|
2019-08-20 13:05:31 -04:00
|
|
|
toFormattedJSON (this: MCommentFormattable) {
|
2017-12-22 04:50:07 -05:00
|
|
|
return {
|
|
|
|
id: this.id,
|
|
|
|
url: this.url,
|
|
|
|
text: this.text,
|
2020-11-13 10:38:23 -05:00
|
|
|
|
2020-07-09 05:58:46 -04:00
|
|
|
threadId: this.getThreadId(),
|
2017-12-27 14:03:37 -05:00
|
|
|
inReplyToCommentId: this.inReplyToCommentId || null,
|
2017-12-22 04:50:07 -05:00
|
|
|
videoId: this.videoId,
|
2020-11-13 10:38:23 -05:00
|
|
|
|
2017-12-22 04:50:07 -05:00
|
|
|
createdAt: this.createdAt,
|
2017-12-22 06:10:40 -05:00
|
|
|
updatedAt: this.updatedAt,
|
2019-11-15 13:05:08 -05:00
|
|
|
deletedAt: this.deletedAt,
|
2020-11-13 10:38:23 -05:00
|
|
|
|
2024-03-29 09:25:03 -04:00
|
|
|
heldForReview: this.heldForReview,
|
|
|
|
|
2019-11-15 13:05:08 -05:00
|
|
|
isDeleted: this.isDeleted(),
|
2020-11-13 10:38:23 -05:00
|
|
|
|
2019-12-28 05:27:31 -05:00
|
|
|
totalRepliesFromVideoAuthor: this.get('totalRepliesFromVideoAuthor') || 0,
|
2017-12-27 10:11:53 -05:00
|
|
|
totalReplies: this.get('totalReplies') || 0,
|
2020-11-13 10:38:23 -05:00
|
|
|
|
|
|
|
account: this.Account
|
|
|
|
? this.Account.toFormattedJSON()
|
|
|
|
: null
|
2017-12-22 04:50:07 -05:00
|
|
|
} as VideoComment
|
|
|
|
}
|
2017-12-27 04:39:31 -05:00
|
|
|
|
2024-03-29 09:25:03 -04:00
|
|
|
toFormattedForAdminOrUserJSON (this: MCommentAdminOrUserFormattable) {
|
2020-11-13 10:38:23 -05:00
|
|
|
return {
|
|
|
|
id: this.id,
|
|
|
|
url: this.url,
|
|
|
|
text: this.text,
|
|
|
|
|
|
|
|
threadId: this.getThreadId(),
|
|
|
|
inReplyToCommentId: this.inReplyToCommentId || null,
|
|
|
|
videoId: this.videoId,
|
|
|
|
|
|
|
|
createdAt: this.createdAt,
|
|
|
|
updatedAt: this.updatedAt,
|
|
|
|
|
2024-03-29 09:25:03 -04:00
|
|
|
heldForReview: this.heldForReview,
|
|
|
|
automaticTags: (this.CommentAutomaticTags || []).map(m => m.AutomaticTag.name),
|
|
|
|
|
2020-11-13 10:38:23 -05:00
|
|
|
video: {
|
|
|
|
id: this.Video.id,
|
|
|
|
uuid: this.Video.uuid,
|
|
|
|
name: this.Video.name
|
|
|
|
},
|
|
|
|
|
|
|
|
account: this.Account
|
|
|
|
? this.Account.toFormattedJSON()
|
|
|
|
: null
|
2024-03-29 09:25:03 -04:00
|
|
|
} as VideoCommentForAdminOrUser
|
2020-11-13 10:38:23 -05:00
|
|
|
}
|
|
|
|
|
2019-11-15 13:05:08 -05:00
|
|
|
toActivityPubObject (this: MCommentAP, threadParentComments: MCommentOwner[]): VideoCommentObject | ActivityTombstoneObject {
|
2024-03-29 09:25:03 -04:00
|
|
|
const inReplyTo = this.inReplyToCommentId === null
|
|
|
|
? this.Video.url // New thread, so we reply to the video
|
|
|
|
: this.InReplyToVideoComment.url
|
2019-12-03 15:48:31 -05:00
|
|
|
|
2019-11-15 13:05:08 -05:00
|
|
|
if (this.isDeleted()) {
|
|
|
|
return {
|
|
|
|
id: this.url,
|
|
|
|
type: 'Tombstone',
|
|
|
|
formerType: 'Note',
|
2019-12-03 15:48:31 -05:00
|
|
|
inReplyTo,
|
2019-11-15 13:05:08 -05:00
|
|
|
published: this.createdAt.toISOString(),
|
|
|
|
updated: this.updatedAt.toISOString(),
|
|
|
|
deleted: this.deletedAt.toISOString()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-05 05:19:25 -05:00
|
|
|
const tag: ActivityTagObject[] = []
|
|
|
|
for (const parentComment of threadParentComments) {
|
2019-12-03 15:48:31 -05:00
|
|
|
if (!parentComment.Account) continue
|
|
|
|
|
2018-01-05 05:19:25 -05:00
|
|
|
const actor = parentComment.Account.Actor
|
|
|
|
|
|
|
|
tag.push({
|
|
|
|
type: 'Mention',
|
|
|
|
href: actor.url,
|
|
|
|
name: `@${actor.preferredUsername}@${actor.getHost()}`
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-03-29 09:25:03 -04:00
|
|
|
let replyApproval = this.replyApproval
|
|
|
|
if (this.Video.isOwned() && !this.heldForReview) {
|
|
|
|
replyApproval = getLocalApproveReplyActivityPubUrl(this.Video, this)
|
|
|
|
}
|
|
|
|
|
2017-12-27 04:39:31 -05:00
|
|
|
return {
|
|
|
|
type: 'Note' as 'Note',
|
|
|
|
id: this.url,
|
2022-01-13 08:12:29 -05:00
|
|
|
|
2017-12-27 04:39:31 -05:00
|
|
|
content: this.text,
|
2022-01-13 08:12:29 -05:00
|
|
|
mediaType: 'text/markdown',
|
|
|
|
|
2017-12-27 04:39:31 -05:00
|
|
|
inReplyTo,
|
2017-12-28 05:16:08 -05:00
|
|
|
updated: this.updatedAt.toISOString(),
|
2017-12-27 04:39:31 -05:00
|
|
|
published: this.createdAt.toISOString(),
|
2017-12-28 05:16:08 -05:00
|
|
|
url: this.url,
|
2018-01-05 05:19:25 -05:00
|
|
|
attributedTo: this.Account.Actor.url,
|
2024-03-29 09:25:03 -04:00
|
|
|
replyApproval,
|
2018-01-05 05:19:25 -05:00
|
|
|
tag
|
2017-12-27 04:39:31 -05:00
|
|
|
}
|
|
|
|
}
|
2020-05-22 11:06:26 -04:00
|
|
|
|
|
|
|
private static async buildBlockerAccountIds (options: {
|
2023-01-05 09:31:51 -05:00
|
|
|
user: MUserAccountId
|
|
|
|
}): Promise<number[]> {
|
|
|
|
const { user } = options
|
2020-05-22 11:06:26 -04:00
|
|
|
|
|
|
|
const serverActor = await getServerActor()
|
|
|
|
const blockerAccountIds = [ serverActor.Account.id ]
|
|
|
|
|
|
|
|
if (user) blockerAccountIds.push(user.Account.id)
|
|
|
|
|
|
|
|
return blockerAccountIds
|
|
|
|
}
|
2024-03-29 09:25:03 -04:00
|
|
|
|
|
|
|
private static buildBlockerAccountIdsAndCanSeeHeldForReview (options: {
|
|
|
|
video: MVideo
|
|
|
|
user: MUserAccountId
|
|
|
|
}) {
|
|
|
|
const { video, user } = options
|
|
|
|
const blockerAccountIdsPromise = this.buildBlockerAccountIds(options)
|
|
|
|
|
|
|
|
let canSeeHeldForReviewPromise: Promise<boolean>
|
|
|
|
if (user) {
|
|
|
|
if (user.hasRight(UserRight.SEE_ALL_COMMENTS)) {
|
|
|
|
canSeeHeldForReviewPromise = Promise.resolve(true)
|
|
|
|
} else {
|
|
|
|
canSeeHeldForReviewPromise = VideoChannelModel.loadAndPopulateAccount(video.channelId)
|
|
|
|
.then(c => c.accountId === user.Account.id)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
canSeeHeldForReviewPromise = Promise.resolve(false)
|
|
|
|
}
|
|
|
|
|
|
|
|
return Promise.all([ blockerAccountIdsPromise, canSeeHeldForReviewPromise ])
|
|
|
|
.then(([ blockerAccountIds, canSeeHeldForReview ]) => ({ blockerAccountIds, canSeeHeldForReview }))
|
|
|
|
}
|
2017-12-22 03:14:50 -05:00
|
|
|
}
|