Add ability to expose the mute list

This commit is contained in:
Chocobozzz 2020-05-11 10:12:57 +02:00
parent 894cc2f1d4
commit ee372c178a
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
3 changed files with 60 additions and 4 deletions

View File

@ -2,9 +2,18 @@
Auto mute accounts or instances based on public blocklists. Auto mute accounts or instances based on public blocklists.
## Mute lists
**Add your public list here**
## Settings ## 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 ## Blocklist URL format

View File

@ -13,9 +13,10 @@ async function register ({
settingsManager, settingsManager,
storageManager, storageManager,
peertubeHelpers, peertubeHelpers,
registerSetting registerSetting,
getRouter
}) { }) {
const { logger } = peertubeHelpers const { logger, database, server } = peertubeHelpers
registerSetting({ registerSetting({
name: 'blocklist-urls', name: 'blocklist-urls',
@ -32,6 +33,14 @@ async function register ({
default: 3600 // 1 Hour 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() const serverActor = await peertubeHelpers.server.getServerActor()
store.serverAccountId = serverActor.Account.id store.serverAccountId = serverActor.Account.id
@ -43,6 +52,44 @@ async function register ({
load(peertubeHelpers, storageManager, settings['blocklist-urls'], settings['check-seconds-interval']) load(peertubeHelpers, storageManager, settings['blocklist-urls'], settings['check-seconds-interval'])
.catch(err => logger.error('Cannot load auto mute plugin.', { err })) .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 () { async function unregister () {

View File

@ -1,6 +1,6 @@
{ {
"name": "peertube-plugin-auto-mute", "name": "peertube-plugin-auto-mute",
"version": "0.0.3", "version": "0.0.4",
"description": "Auto mute plugin for PeerTube", "description": "Auto mute plugin for PeerTube",
"engine": { "engine": {
"peertube": ">=2.2.0" "peertube": ">=2.2.0"