useloggedinaction now handles non-specific instanceUrl

This commit is contained in:
shilangyu 2020-09-22 23:17:42 +02:00
parent 72ef4a6d26
commit b37277c072
1 changed files with 8 additions and 4 deletions

View File

@ -6,17 +6,21 @@ import '../pages/settings.dart';
import '../util/goto.dart';
import 'stores.dart';
/// If user has an account for the given instance the passed wrapper will call
/// the passed action with a Jwt token. Otherwise the action is ignored and a
/// Snackbar is rendered. If [any] is set to true, this check is performed for
/// all instances and if any of them have an account, the wrapped action will be
/// called with a null token.
Function(
Function(Jwt token) action, [
String message,
]) useLoggedInAction(
String instanceUrl,
) {
]) useLoggedInAction(String instanceUrl, {bool any = false}) {
final context = useContext();
final store = useAccountsStore();
return (Function(Jwt token) action, [message]) {
if (store.isAnonymousFor(instanceUrl)) {
if (any && store.hasNoAccount ||
!any && store.isAnonymousFor(instanceUrl)) {
return () {
Scaffold.of(context).showSnackBar(SnackBar(
content: Text(message ?? 'you have to be logged in to do that'),