From 696d83fd1377486dd03cc1bd02a21d9b6ddd9fcd Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 22 May 2020 17:06:26 +0200 Subject: Block comments from muted accounts/servers Add better control for users of comments displayed on their videos: * Do not forward comments from muted remote accounts/servers (muted by the current server or by the video owner) * Do not list threads and hide replies (with their children) of accounts/servers muted by the video owner * Hide from RSS comments of muted accounts/servers by video owners Use case: * Try to limit spam propagation in the federation * Add ability for users to automatically hide comments on their videos from undesirable accounts/servers (the comment section belongs to videomakers, so they choose what's posted there) --- server/lib/blocklist.ts | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'server/lib/blocklist.ts') diff --git a/server/lib/blocklist.ts b/server/lib/blocklist.ts index 842eecb5b..d282d091b 100644 --- a/server/lib/blocklist.ts +++ b/server/lib/blocklist.ts @@ -1,5 +1,6 @@ import { sequelizeTypescript } from '@server/initializers/database' -import { MAccountBlocklist, MServerBlocklist } from '@server/typings/models' +import { getServerActor } from '@server/models/application/application' +import { MAccountBlocklist, MAccountId, MAccountServer, MServerBlocklist } from '@server/typings/models' import { AccountBlocklistModel } from '../models/account/account-blocklist' import { ServerBlocklistModel } from '../models/server/server-blocklist' @@ -33,9 +34,29 @@ function removeServerFromBlocklist (serverBlock: MServerBlocklist) { }) } +async function isBlockedByServerOrAccount (targetAccount: MAccountServer, userAccount?: MAccountId) { + const serverAccountId = (await getServerActor()).Account.id + const sourceAccounts = [ serverAccountId ] + + if (userAccount) sourceAccounts.push(userAccount.id) + + const accountMutedHash = await AccountBlocklistModel.isAccountMutedByMulti(sourceAccounts, targetAccount.id) + if (accountMutedHash[serverAccountId] || (userAccount && accountMutedHash[userAccount.id])) { + return true + } + + const instanceMutedHash = await ServerBlocklistModel.isServerMutedByMulti(sourceAccounts, targetAccount.Actor.serverId) + if (instanceMutedHash[serverAccountId] || (userAccount && instanceMutedHash[userAccount.id])) { + return true + } + + return false +} + export { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, - removeServerFromBlocklist + removeServerFromBlocklist, + isBlockedByServerOrAccount } -- cgit v1.2.3