service: Implement setting the subscription state of a contact
This commit is contained in:
@@ -18,6 +18,7 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
||||
on<ProfilePageRequestedEvent>(_onProfileRequested);
|
||||
on<ConversationUpdatedEvent>(_onConversationUpdated);
|
||||
on<AvatarSetEvent>(_onAvatarSet);
|
||||
on<SetSubscriptionStateEvent>(_onSetSubscriptionState);
|
||||
}
|
||||
|
||||
Future<void> _onProfileRequested(ProfilePageRequestedEvent event, Emitter<ProfileState> emit) async {
|
||||
@@ -71,4 +72,13 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
||||
awaitable: false
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _onSetSubscriptionState(SetSubscriptionStateEvent event, Emitter<ProfileState> emit) async {
|
||||
// TODO: Maybe already emit the state change to have it instant and debounce it until
|
||||
// everything else is done
|
||||
GetIt.I.get<BackgroundServiceDataSender>().sendData(
|
||||
SetShareOnlineStatusCommand(jid: event.jid, share: event.shareStatus),
|
||||
awaitable: false
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,3 +35,11 @@ class AvatarSetEvent extends ProfileEvent {
|
||||
|
||||
AvatarSetEvent(this.path, this.hash);
|
||||
}
|
||||
|
||||
/// Triggered by the UI when the subscription state should be set
|
||||
class SetSubscriptionStateEvent extends ProfileEvent {
|
||||
final String jid;
|
||||
final bool shareStatus;
|
||||
|
||||
SetSubscriptionStateEvent(this.jid, this.shareStatus);
|
||||
}
|
||||
|
||||
@@ -50,14 +50,13 @@ class ProfilePage extends StatelessWidget {
|
||||
padding: const EdgeInsets.symmetric(horizontal: 32.0).add(EdgeInsets.only(top: 8.0)),
|
||||
child: SettingsTile.switchTile(
|
||||
title: "Share online status",
|
||||
// TODO: This
|
||||
// TODO: Requires that we also store the subscription state in the
|
||||
// database.
|
||||
switchValue: state.conversation!.subscription == "to" || state.conversation!.subscription == "both",
|
||||
onToggle: (value) {
|
||||
GetIt.I.get<BackgroundServiceDataSender>().sendData(
|
||||
SetShareOnlineStatusCommand(jid: state.conversation!.jid, share: value),
|
||||
awaitable: false
|
||||
context.read<ProfileBloc>().add(
|
||||
SetSubscriptionStateEvent(
|
||||
state.conversation!.jid,
|
||||
value
|
||||
)
|
||||
);
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user