Exclude the logged-in user from reply mentions

When posting a reply, exclude the current user from the automatically
populated list of mentions.
This commit is contained in:
St John Karp 2018-10-10 15:09:51 -07:00
parent 2bdea8f088
commit 157b9eed48
2 changed files with 23 additions and 2 deletions

View File

@ -39,10 +39,31 @@ class StatusController extends Controller
}
}
// Compile a list of accounts to include in the reply.
$reply_mentions = [];
if (session()->has('user'))
{
// Include the original poster, if not the current user.
if ($status['account']['acct'] !== session('user')->user['acct'])
{
array_push($reply_mentions, '@' . $status['account']['acct']);
}
// Include all mentions, excluding the current user.
foreach ($status['mentions'] as $mention)
{
if ($mention['acct'] !== session('user')->user['acct'])
{
array_push($reply_mentions, '@' . $mention['acct']);
}
}
}
$vars = [
'status' => $status,
'mastodon_domain' => explode('//', env('MASTODON_DOMAIN'))[1],
'logged_in' => session()->has('user')
'logged_in' => session()->has('user'),
'reply_mentions' => implode(' ', $reply_mentions)
];
return view('show_status', $vars);

View File

@ -28,7 +28,7 @@
placeholder="Spoiler/Warning"
value="{{ $status['spoiler_text'] }}"
/>
<textarea rows="4" name="status" placeholder="Reply" required autofocus>{{ '@' . $status['account']['acct'] }} @foreach ($status['mentions'] as $mention){{ '@' . $mention['acct'] }} @endforeach</textarea>
<textarea rows="4" name="status" placeholder="Reply" required autofocus>{{ $reply_mentions }} </textarea>
<select name="visibility">
<option value="public" @if ($status['visibility'] === 'public') selected @endif>Public</option>
<option value="unlisted" @if ($status['visibility'] === 'unlisted') selected @endif>Unlisted</option>