A framework for building convergent cross-platform Nextcloud clients using Flutter.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.4 KiB

import 'dart:async';
import 'package:neon/src/models/account.dart';
import 'package:neon/src/neon.dart';
2 years ago
import 'package:nextcloud/nextcloud.dart';
import 'package:rx_bloc/rx_bloc.dart';
import 'package:rxdart/rxdart.dart';
part 'user_details.rxb.g.dart';
abstract class UserDetailsBlocEvents {
void refresh();
}
2 years ago
abstract class UserDetailsBlocStates {
BehaviorSubject<Result<ProvisioningApiUserDetails>> get userDetails;
}
@RxBloc()
class UserDetailsBloc extends $UserDetailsBloc {
UserDetailsBloc(
this._requestManager,
this._client,
) {
_$refreshEvent.listen((final _) => _loadUserDetails());
2 years ago
_loadUserDetails();
}
void _loadUserDetails() {
_requestManager
.wrapNextcloud<ProvisioningApiUserDetails, ProvisioningApiUser>(
2 years ago
_client.id,
'user-details',
() async => _client.provisioningApi.getCurrentUser(),
(final response) => response.ocs.data,
previousData: _userDetailsSubject.valueOrNull?.data,
2 years ago
)
.listen(_userDetailsSubject.add);
}
final RequestManager _requestManager;
final NextcloudClient _client;
final _userDetailsSubject = BehaviorSubject<Result<ProvisioningApiUserDetails>>();
@override
void dispose() {
unawaited(_userDetailsSubject.close());
2 years ago
super.dispose();
}
@override
BehaviorSubject<Result<ProvisioningApiUserDetails>> _mapToUserDetailsState() => _userDetailsSubject;
}