Verified Commit ee372c17 authored by Chocobozzz's avatar Chocobozzz
Browse files

Add ability to expose the mute list

parent 894cc2f1
......@@ -2,9 +2,18 @@
Auto mute accounts or instances based on public blocklists.
## Mute lists
**Add your public list here**
## Settings
![settings screen](https://lutim.cpy.re/qaFui9N1.png)
You can choose to expose your mute list that will be available on `https://example.com/plugins/plugins/auto-mute/router/api/v1/mute-list`.
Other instances can follow your mute list, but muting removal is not supported yet. For example, if you subscribe to the mute list of `example.com`:
* `example.com` mutes `account1`
* Your instance automatically mutes `account1`
* `example.com` unmutes `account1`
* You instance **will not** unmute `account1`
## Blocklist URL format
......
......@@ -13,9 +13,10 @@ async function register ({
settingsManager,
storageManager,
peertubeHelpers,
registerSetting
registerSetting,
getRouter
}) {
const { logger } = peertubeHelpers
const { logger, database, server } = peertubeHelpers
registerSetting({
name: 'blocklist-urls',
......@@ -32,6 +33,14 @@ async function register ({
default: 3600 // 1 Hour
})
registerSetting({
name: 'expose-mute-list',
label: 'Publicly expose my mute list',
type: 'input-checkbox',
private: true,
default: false
})
const serverActor = await peertubeHelpers.server.getServerActor()
store.serverAccountId = serverActor.Account.id
......@@ -43,6 +52,44 @@ async function register ({
load(peertubeHelpers, storageManager, settings['blocklist-urls'], settings['check-seconds-interval'])
.catch(err => logger.error('Cannot load auto mute plugin.', { err }))
})
const router = getRouter()
router.get('/api/v1/mute-list', async (req, res) => {
try {
const setting = await settingsManager.getSetting('expose-mute-list')
if (setting !== true) return res.sendStatus(403)
const serverActor = await server.getServerActor()
const serverAccountId = serverActor.Account.id
const [ serverMutes, accountMutes ] = await Promise.all([
database.query(
'SELECT "server"."host", "serverBlocklist"."updatedAt" FROM "serverBlocklist" ' +
'INNER JOIN server ON server.id = "serverBlocklist"."targetServerId" WHERE "serverBlocklist"."accountId" = ' + serverAccountId,
{ type: 'SELECT' }
),
database.query(
'SELECT "actor"."preferredUsername", "server"."host", "accountBlocklist"."updatedAt" FROM "accountBlocklist" ' +
'INNER JOIN account ON account.id = "accountBlocklist"."targetAccountId" ' +
'INNER JOIN actor ON actor.id = account."actorId" ' +
'INNER JOIN server ON server.id = actor."serverId" WHERE "accountBlocklist"."accountId" = ' + serverAccountId,
{ type: 'SELECT' }
)
])
let result = serverMutes.map(m => ({ value: m.host, updatedAt: m.updatedAt }))
result = result.concat(accountMutes.map(m => ({ value: `${m.preferredUsername}@${m.host}`, updatedAt: m.updatedAt })))
return res.json({
data: result
})
} catch (err) {
logger.error('Error in mute list endpoint.', { err })
res.sendStatus(500)
}
})
}
async function unregister () {
......
{
"name": "peertube-plugin-auto-mute",
"version": "0.0.3",
"version": "0.0.4",
"description": "Auto mute plugin for PeerTube",
"engine": {
"peertube": ">=2.2.0"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment