aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/blocklist.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/blocklist.ts')
-rw-r--r--server/lib/blocklist.ts25
1 files changed, 23 insertions, 2 deletions
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 @@
1import { sequelizeTypescript } from '@server/initializers/database' 1import { sequelizeTypescript } from '@server/initializers/database'
2import { MAccountBlocklist, MServerBlocklist } from '@server/typings/models' 2import { getServerActor } from '@server/models/application/application'
3import { MAccountBlocklist, MAccountId, MAccountServer, MServerBlocklist } from '@server/typings/models'
3import { AccountBlocklistModel } from '../models/account/account-blocklist' 4import { AccountBlocklistModel } from '../models/account/account-blocklist'
4import { ServerBlocklistModel } from '../models/server/server-blocklist' 5import { ServerBlocklistModel } from '../models/server/server-blocklist'
5 6
@@ -33,9 +34,29 @@ function removeServerFromBlocklist (serverBlock: MServerBlocklist) {
33 }) 34 })
34} 35}
35 36
37async function isBlockedByServerOrAccount (targetAccount: MAccountServer, userAccount?: MAccountId) {
38 const serverAccountId = (await getServerActor()).Account.id
39 const sourceAccounts = [ serverAccountId ]
40
41 if (userAccount) sourceAccounts.push(userAccount.id)
42
43 const accountMutedHash = await AccountBlocklistModel.isAccountMutedByMulti(sourceAccounts, targetAccount.id)
44 if (accountMutedHash[serverAccountId] || (userAccount && accountMutedHash[userAccount.id])) {
45 return true
46 }
47
48 const instanceMutedHash = await ServerBlocklistModel.isServerMutedByMulti(sourceAccounts, targetAccount.Actor.serverId)
49 if (instanceMutedHash[serverAccountId] || (userAccount && instanceMutedHash[userAccount.id])) {
50 return true
51 }
52
53 return false
54}
55
36export { 56export {
37 addAccountInBlocklist, 57 addAccountInBlocklist,
38 addServerInBlocklist, 58 addServerInBlocklist,
39 removeAccountFromBlocklist, 59 removeAccountFromBlocklist,
40 removeServerFromBlocklist 60 removeServerFromBlocklist,
61 isBlockedByServerOrAccount
41} 62}