mirror of https://git.stjo.hn/planiverse
Implement follow/unfollow accounts
Implemented basic follow/unfollow functionality. Probably needs some styling, definitely needs other controls.
This commit is contained in:
parent
d6b3c8eae1
commit
c0e7838308
|
@ -16,11 +16,55 @@ class AccountController extends Controller
|
||||||
->token($user->token)
|
->token($user->token)
|
||||||
->get('/accounts/' . $account_id);
|
->get('/accounts/' . $account_id);
|
||||||
|
|
||||||
|
if (session()->has('relationship'))
|
||||||
|
{
|
||||||
|
// The user is coming here after peforming an action on an account,
|
||||||
|
// in which case we don't need to re-query the relationship.
|
||||||
|
|
||||||
|
$relationship = session('relationship');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// If the relationship hasn't been returned from performing an action,
|
||||||
|
// we need to query for it.
|
||||||
|
|
||||||
|
$relationships = Mastodon::domain(env('MASTODON_DOMAIN'))
|
||||||
|
->token($user->token)
|
||||||
|
->get('/accounts/relationships', ['id' => $account_id]);
|
||||||
|
|
||||||
|
$relationship = $relationships[0];
|
||||||
|
}
|
||||||
|
|
||||||
$vars = [
|
$vars = [
|
||||||
'account' => $account,
|
'account' => $account,
|
||||||
'mastodon_domain' => explode('//', env('MASTODON_DOMAIN'))[1]
|
'mastodon_domain' => explode('//', env('MASTODON_DOMAIN'))[1],
|
||||||
|
'relationship' => $relationship
|
||||||
];
|
];
|
||||||
|
|
||||||
return view('account', $vars);
|
return view('account', $vars);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function follow_account(Request $request, string $account_id)
|
||||||
|
{
|
||||||
|
$user = session('user');
|
||||||
|
|
||||||
|
$relationship = Mastodon::domain(env('MASTODON_DOMAIN'))
|
||||||
|
->token($user->token)
|
||||||
|
->post('/accounts/' . $account_id . '/follow');
|
||||||
|
|
||||||
|
return redirect()->route('account', ['account_id' => $account_id])
|
||||||
|
->with('relationship', $relationship);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function unfollow_account(Request $request, string $account_id)
|
||||||
|
{
|
||||||
|
$user = session('user');
|
||||||
|
|
||||||
|
$relationship = Mastodon::domain(env('MASTODON_DOMAIN'))
|
||||||
|
->token($user->token)
|
||||||
|
->post('/accounts/' . $account_id . '/unfollow');
|
||||||
|
|
||||||
|
return redirect()->route('account', ['account_id' => $account_id])
|
||||||
|
->with('relationship', $relationship);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,17 @@
|
||||||
</a>
|
</a>
|
||||||
</span>
|
</span>
|
||||||
{!! $account['note'] !!}
|
{!! $account['note'] !!}
|
||||||
|
<div>
|
||||||
|
@if ($relationship['following'])
|
||||||
|
<a href="{{ route('unfollow', ['account_id' => $account['id']]) }}">
|
||||||
|
Unfollow
|
||||||
|
</a>
|
||||||
|
@else
|
||||||
|
<a href="{{ route('follow', ['account_id' => $account['id']]) }}">
|
||||||
|
Follow
|
||||||
|
</a>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -63,6 +63,14 @@ Route::get('/account/{account_id}', 'AccountController@view_account')
|
||||||
->name('account')
|
->name('account')
|
||||||
->middleware('authorize');
|
->middleware('authorize');
|
||||||
|
|
||||||
|
Route::get('/account/{account_id}/follow', 'AccountController@follow_account')
|
||||||
|
->name('follow')
|
||||||
|
->middleware('authorize');
|
||||||
|
|
||||||
|
Route::get('/account/{account_id}/unfollow', 'AccountController@unfollow_account')
|
||||||
|
->name('unfollow')
|
||||||
|
->middleware('authorize');
|
||||||
|
|
||||||
Route::get('/login', 'LoginController@login')
|
Route::get('/login', 'LoginController@login')
|
||||||
->name('login');
|
->name('login');
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue