- static async listThreadCommentsForApi (videoId: number, threadId: number, user?: UserModel) {
- const serverActor = await getServerActor()
- const serverAccountId = serverActor.Account.id
- const userAccountId = user ? user.Account.id : undefined
+ static async listThreadsForApi (parameters: {
+ videoId: number
+ isVideoOwned: boolean
+ start: number
+ count: number
+ sort: string
+ user?: MUserAccountId
+ }) {
+ const { videoId, isVideoOwned, start, count, sort, user } = parameters
+
+ const blockerAccountIds = await VideoCommentModel.buildBlockerAccountIds({ videoId, user, isVideoOwned })
+
+ const accountBlockedWhere = {
+ accountId: {
+ [Op.notIn]: Sequelize.literal(
+ '(' + buildBlockedAccountSQL(blockerAccountIds) + ')'
+ )
+ }
+ }
+
+ const queryList = {
+ offset: start,
+ limit: count,
+ order: getCommentSort(sort),
+ where: {
+ [Op.and]: [
+ {
+ videoId
+ },
+ {
+ inReplyToCommentId: null
+ },
+ {
+ [Op.or]: [
+ accountBlockedWhere,
+ {
+ accountId: null
+ }
+ ]
+ }
+ ]
+ }
+ }
+
+ const scopesList: (string | ScopeOptions)[] = [
+ ScopeNames.WITH_ACCOUNT_FOR_API,
+ {
+ method: [ ScopeNames.ATTRIBUTES_FOR_API, blockerAccountIds ]
+ }
+ ]
+
+ const queryCount = {
+ where: {
+ videoId,
+ deletedAt: null,
+ ...accountBlockedWhere
+ }
+ }
+
+ return Promise.all([
+ VideoCommentModel.scope(scopesList).findAndCountAll(queryList),
+ VideoCommentModel.count(queryCount)
+ ]).then(([ { rows, count }, totalNotDeletedComments ]) => {
+ return { total: count, data: rows, totalNotDeletedComments }
+ })
+ }
+
+ static async listThreadCommentsForApi (parameters: {
+ videoId: number
+ isVideoOwned: boolean
+ threadId: number
+ user?: MUserAccountId
+ }) {
+ const { videoId, threadId, user, isVideoOwned } = parameters
+
+ const blockerAccountIds = await VideoCommentModel.buildBlockerAccountIds({ videoId, user, isVideoOwned })