MCommentOwnerVideoReply
} from '../../typings/models/video'
import { AccountModel } from '../account/account'
-import { ActorModel } from '../activitypub/actor'
+import { ActorModel, unusedActorAttributesForAPI } from '../activitypub/actor'
import { buildBlockedAccountSQL, buildLocalAccountIdsIn, getCommentSort, throwIfNotValid } from '../utils'
import { VideoModel } from './video'
import { VideoChannelModel } from './video-channel'
enum ScopeNames {
WITH_ACCOUNT = 'WITH_ACCOUNT',
+ WITH_ACCOUNT_FOR_API = 'WITH_ACCOUNT_FOR_API',
WITH_IN_REPLY_TO = 'WITH_IN_REPLY_TO',
WITH_VIDEO = 'WITH_VIDEO',
ATTRIBUTES_FOR_API = 'ATTRIBUTES_FOR_API'
}
]
},
+ [ScopeNames.WITH_ACCOUNT_FOR_API]: {
+ include: [
+ {
+ model: AccountModel.unscoped(),
+ include: [
+ {
+ attributes: {
+ exclude: unusedActorAttributesForAPI
+ },
+ model: ActorModel, // Default scope includes avatar and server
+ required: true
+ }
+ ]
+ }
+ ]
+ },
[ScopeNames.WITH_IN_REPLY_TO]: {
include: [
{
limit: count,
order: getCommentSort(sort),
where: {
- videoId,
- inReplyToCommentId: null,
- accountId: {
- [Op.notIn]: Sequelize.literal(
- '(' + buildBlockedAccountSQL(serverAccountId, userAccountId) + ')'
- )
- }
+ [Op.and]: [
+ {
+ videoId
+ },
+ {
+ inReplyToCommentId: null
+ },
+ {
+ [Op.or]: [
+ {
+ accountId: {
+ [Op.notIn]: Sequelize.literal(
+ '(' + buildBlockedAccountSQL(serverAccountId, userAccountId) + ')'
+ )
+ }
+ },
+ {
+ accountId: null
+ }
+ ]
+ }
+ ]
}
}
const scopes: (string | ScopeOptions)[] = [
- ScopeNames.WITH_ACCOUNT,
+ ScopeNames.WITH_ACCOUNT_FOR_API,
{
method: [ ScopeNames.ATTRIBUTES_FOR_API, serverAccountId, userAccountId ]
}
}
const scopes: any[] = [
- ScopeNames.WITH_ACCOUNT,
+ ScopeNames.WITH_ACCOUNT_FOR_API,
{
method: [ ScopeNames.ATTRIBUTES_FOR_API, serverAccountId, userAccountId ]
}
})
it('Should hide its comments', async function () {
- const resThreads = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 5, '-createdAt', servers[0].accessToken)
+ const resThreads = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 25, '-createdAt', servers[0].accessToken)
const threads: VideoComment[] = resThreads.body.data
expect(threads).to.have.lengthOf(1)
it('Should hide its comments', async function () {
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
- const resThreads = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 5, '-createdAt', token)
+ const resThreads = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 20, '-createdAt', token)
+
+ let threads: VideoComment[] = resThreads.body.data
+ threads = threads.filter(t => t.isDeleted === false)
- const threads: VideoComment[] = resThreads.body.data
expect(threads).to.have.lengthOf(1)
expect(threads[0].totalReplies).to.equal(0)