From 7ad9b9846c44d198a736183fb186c2039f5236b5 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 12 Oct 2018 15:26:04 +0200 Subject: Add ability for users to block an account/instance on server side --- server/lib/blocklist.ts | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 server/lib/blocklist.ts (limited to 'server/lib/blocklist.ts') diff --git a/server/lib/blocklist.ts b/server/lib/blocklist.ts new file mode 100644 index 000000000..394c24537 --- /dev/null +++ b/server/lib/blocklist.ts @@ -0,0 +1,40 @@ +import { sequelizeTypescript } from '../initializers' +import { AccountBlocklistModel } from '../models/account/account-blocklist' +import { ServerBlocklistModel } from '../models/server/server-blocklist' + +function addAccountInBlocklist (byAccountId: number, targetAccountId: number) { + return sequelizeTypescript.transaction(async t => { + return AccountBlocklistModel.create({ + accountId: byAccountId, + targetAccountId: targetAccountId + }, { transaction: t }) + }) +} + +function addServerInBlocklist (byAccountId: number, targetServerId: number) { + return sequelizeTypescript.transaction(async t => { + return ServerBlocklistModel.create({ + accountId: byAccountId, + targetServerId + }, { transaction: t }) + }) +} + +function removeAccountFromBlocklist (accountBlock: AccountBlocklistModel) { + return sequelizeTypescript.transaction(async t => { + return accountBlock.destroy({ transaction: t }) + }) +} + +function removeServerFromBlocklist (serverBlock: ServerBlocklistModel) { + return sequelizeTypescript.transaction(async t => { + return serverBlock.destroy({ transaction: t }) + }) +} + +export { + addAccountInBlocklist, + addServerInBlocklist, + removeAccountFromBlocklist, + removeServerFromBlocklist +} -- cgit v1.2.3 From af5767ffae41b2d5604e41ba9a7225c623dd6735 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 12 Oct 2018 17:26:40 +0200 Subject: Add user/instance block by users in the client --- server/lib/blocklist.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'server/lib/blocklist.ts') diff --git a/server/lib/blocklist.ts b/server/lib/blocklist.ts index 394c24537..1633e500c 100644 --- a/server/lib/blocklist.ts +++ b/server/lib/blocklist.ts @@ -4,7 +4,7 @@ import { ServerBlocklistModel } from '../models/server/server-blocklist' function addAccountInBlocklist (byAccountId: number, targetAccountId: number) { return sequelizeTypescript.transaction(async t => { - return AccountBlocklistModel.create({ + return AccountBlocklistModel.upsert({ accountId: byAccountId, targetAccountId: targetAccountId }, { transaction: t }) @@ -13,7 +13,7 @@ function addAccountInBlocklist (byAccountId: number, targetAccountId: number) { function addServerInBlocklist (byAccountId: number, targetServerId: number) { return sequelizeTypescript.transaction(async t => { - return ServerBlocklistModel.create({ + return ServerBlocklistModel.upsert({ accountId: byAccountId, targetServerId }, { transaction: t }) -- cgit v1.2.3