diff --git a/api/v1/database/mastodon/accounts/search/mod.php b/api/v1/database/mastodon/accounts/search/mod.php index eff36ed..0392576 100644 --- a/api/v1/database/mastodon/accounts/search/mod.php +++ b/api/v1/database/mastodon/accounts/search/mod.php @@ -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 = []; diff --git a/api/v1/http/mastodon/accounts/silence/mod.php b/api/v1/http/mastodon/accounts/silence/mod.php index 8ce06ab..f94e592 100644 --- a/api/v1/http/mastodon/accounts/silence/mod.php +++ b/api/v1/http/mastodon/accounts/silence/mod.php @@ -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); }; $_(); diff --git a/api/v1/http/mastodon/accounts/suspend/mod.php b/api/v1/http/mastodon/accounts/suspend/mod.php index 39ecf3a..7cadda8 100644 --- a/api/v1/http/mastodon/accounts/suspend/mod.php +++ b/api/v1/http/mastodon/accounts/suspend/mod.php @@ -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); }; $_(); diff --git a/css/base.php b/css/base.php index ba486ed..8f20f4d 100644 --- a/css/base.php +++ b/css/base.php @@ -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; } diff --git a/js/templates/instance/filter-users.html b/js/templates/instance/filter-users.html index b0f7039..a7c0543 100644 --- a/js/templates/instance/filter-users.html +++ b/js/templates/instance/filter-users.html @@ -154,8 +154,8 @@
-
-
+
+
{name} @@ -168,16 +168,26 @@
-
{mastodon:fields}
+
{mastodon:fields}
{note}
- - + +
diff --git a/views/instance.php b/views/instance.php index d0da2e6..142c006 100644 --- a/views/instance.php +++ b/views/instance.php @@ -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 = '';