Improved feedback on silence/suspend actions

This commit is contained in:
Bofh 2022-12-13 13:15:19 +01:00
parent 739f23cc63
commit dcc159ea91
6 changed files with 72 additions and 10 deletions

View File

@ -32,7 +32,7 @@ $filtered_accounts_index = [];
$sql_all = '
SELECT
a.id, a.display_name, a.username, a.domain, a.fields,
a.id, a.display_name, a.username, a.domain, a.fields, a.silenced_at,
a.note, a.avatar_file_name, a.avatar_storage_schema_version,
(SELECT count(1) FROM statuses WHERE account_id = a.id) AS statuses
FROM accounts AS a
@ -198,6 +198,14 @@ if (isset($_GET['profile']) && trim($_GET['profile']) != '')
$config = instance_config('mastodon');
$filtered_accounts = array_unique($filtered_accounts);
$trusted_users = mod_php('api/v1/config/trusted_users/get');
$suspended_users = [];
$susp_file = 'suspended_accounts,'.$GLOBALS['ap_software'].','.$GLOBALS['ap_instance'];
if (filedb_exists('cache', $susp_file))
$suspended_users = unserialize(filedb_get('cache', $susp_file));
$silenced_users = [];
$sile_file = 'silenced_accounts,'.$GLOBALS['ap_software'].','.$GLOBALS['ap_instance'];
if (filedb_exists('cache', $sile_file))
$silenced_users = unserialize(filedb_get('cache', $sile_file));
$result_accounts = [];
foreach ($filtered_accounts as $id) {
@ -206,7 +214,8 @@ foreach ($filtered_accounts as $id) {
$acct_for_trusted = $account['username'].'@'.($account['domain'] === null ?
$GLOBALS['ap_instance'] : $account['domain']);
if (in_array($acct_for_trusted, $trusted_users))
if (in_array($acct_for_trusted, $trusted_users) ||
in_array($id, $suspended_users))
continue;
$following = $pg->fetch('SELECT count(1) FROM follows WHERE account_id = \''.$id.'\'');
@ -226,6 +235,10 @@ foreach ($filtered_accounts as $id) {
$newacc['statuses'] = intval($account['statuses']);
$newacc['following'] = intval($following['count']);
$newacc['followers'] = intval($followers['count']);
$newacc['silenced'] = $account['silenced_at'] !== null;
if (in_array($id, $silenced_users))
$newacc['silenced'] = true;
if ($account['avatar_storage_schema_version'] === 1) {
$c = 0;
$parts = [];

View File

@ -5,11 +5,22 @@ $_ = function() {
if (!valid_mastodon_account_id($id))
return apiresult(['error' => 'id parameter has incorrect format'], 400);
instance_config();
$output = instance_http_post('/api/v1/admin/accounts/'.$id.'/action',
['type' => 'silence' ]);
$silenced = [];
$sile_file = 'silenced_accounts,'.$GLOBALS['ap_software'].','.$GLOBALS['ap_instance'];
if (filedb_exists('cache', $sile_file))
$silenced = unserialize(filedb_get('cache', $sile_file));
$silenced []= $id;
$silenced = array_unique($silenced);
filedb_put('cache', $sile_file, serialize($silenced));
if (!isset($_SERVER['REQUEST_URI']))
sleep(2);
return apiresult($output);
};
$_();

View File

@ -5,6 +5,8 @@ $_ = function() {
if (!valid_mastodon_account_id($id))
return apiresult(['error' => 'id parameter has incorrect format'], 400);
instance_config();
$explain = 'Your account has been suspended';
if (isset($_POST['explain']))
$explain = trim($_POST['explain']);
@ -21,8 +23,17 @@ $_ = function() {
if ($is_remote_account)
instance_http_delete('/api/v1/admin/accounts/'.$id);
$suspended = [];
$susp_file = 'suspended_accounts,'.$GLOBALS['ap_software'].','.$GLOBALS['ap_instance'];
if (filedb_exists('cache', $susp_file))
$suspended = unserialize(filedb_get('cache', $susp_file));
$suspended []= $id;
$suspended = array_unique($suspended);
filedb_put('cache', $susp_file, serialize($suspended));
if (!isset($_SERVER['REQUEST_URI']))
sleep(3);
return apiresult($output);
};
$_();

View File

@ -75,6 +75,11 @@ body > .toast-container {
border: none !important;
box-shadow: none !important;
}
.disabled,
.silenced .disable-able {
filter: saturate(0);
opacity: 0.7;
}
.gray { color: gray }
.btn {
padding: 1em 3em;
@ -198,6 +203,11 @@ table.fields tr.verified td .fa.fa-check::before {
border: 1px solid #0000001a;
border-radius: .5em;
margin-top: .5em;
word-break: break-word;
}
.item.suspended .card {
background: #fff3f3 !important;
border: 2px solid red;
}

View File

@ -154,8 +154,8 @@
</div>
<div id="users-all"></div>
<div id="users-all-item" data-id="{id}">
<div class="card software {software}">
<div class="flex">
<div class="card software {software} {silencedClass}">
<div class="flex disable-able">
<img data-src="{avatar}"/>
<div class="w100" style="padding:0 1em">
<b style="font-size: 1.1em">{name}</b>
@ -168,16 +168,26 @@
</div>
</div>
</div>
<div class="only mastodon">{mastodon:fields}</div>
<div class="only mastodon disable-able">{mastodon:fields}</div>
<div class="note">{note}</div>
<div style="margin-top: 1em; text-align: right;">
<button onclick="if (window.view.instance.do.users.trust_user('{acct}'))
E.element('.item[data-id=&quot;{id}&quot;]').remove()"
class="btn mid green"><i class="fa fa-thumbs-up fa-fw"></i>Trust</button>
<button onclick="window.view.instance.do.users.silence('{id}')"
class="btn mid"><i class="fa fa-volume-mute fa-fw"></i>Silence</button>
<button onclick="window.view.instance.do.users.suspend('{id}')"
class="btn mid red"><i class="fa fa-ban fa-fw"></i>Suspend</button>
<button onclick="
if ('' === '{disabledClass}') {
if (window.view.instance.do.users.silence('{id}')) {
E.element('.item[data-id=&quot;{id}&quot;]').classList.add('silenced');
this.querySelector('span').innerText = 'Silenced';
this.setAttribute('disabled', 'true');
}
}"
class="btn mid disable-able" {disabledHTML}>
<i class="fa fa-volume-mute fa-fw"></i><span>{silencedText}</span></button>
<button onclick="if (window.view.instance.do.users.suspend('{id}')) {
E.element('.item[data-id=&quot;{id}&quot;]').classList.add('suspended');
this.querySelector('span'),innerText = 'Suspended'}"
class="btn mid red"><i class="fa fa-ban fa-fw"></i><span>Suspend</span></button>
</div>
</div>
</div>

View File

@ -34,12 +34,13 @@ window.view.instance = {
return true;
},
suspend: function(_id) {
if (!confirm('Are you sure you want to suspend this user?')) return;
if (!confirm('Are you sure you want to suspend this user?')) return false;
const hargs = get_hash_arguments();
http.get(`api/v1/http/mastodon/accounts/suspend?instance=${hargs.instance}&id=${_id}`,
{}, function(js) {
toast.info('User has been successfully suspended');
});
return true;
},
silence: function(_id) {
const hargs = get_hash_arguments();
@ -47,6 +48,7 @@ window.view.instance = {
{}, function(js) {
toast.info('User has been successfully silenced');
});
return true;
},
},
new_accounts: {
@ -201,6 +203,7 @@ window.view.instance = {
execute: function(page, items_per_page) {
const btn = E.elemid('btncollapse-filters-current');
if (btn.innerText.trim() === 'hide') btn.click();
window.scrollTo(0,0);
const data = window.view.instance.do.filter_users.get_current_filter();
delete data.id;
@ -234,6 +237,10 @@ window.view.instance = {
tpl = tpl.replaceAll('{statuses}', it.statuses);
tpl = tpl.replaceAll('{following}', it.following);
tpl = tpl.replaceAll('{followers}', it.followers);
tpl = tpl.replaceAll('{disabledClass}', it.silenced === true ? 'disabled' : '');
tpl = tpl.replaceAll('{silencedClass}', it.silenced === true ? 'silenced' : '');
tpl = tpl.replaceAll('{disabledHTML}', it.silenced === true ? 'disabled="true"' : '');
tpl = tpl.replaceAll('{silencedText}', it.silenced === true ? 'Silenced' : 'Silence');
if (hargs.software === 'mastodon') {
if (![null, undefined].includes(it.fields)) {
var _fields = '<table class="fields"><tbody>';