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.
76 lines
1.7 KiB
76 lines
1.7 KiB
2 years ago
|
part of '../neon_spreed.dart';
|
||
|
|
||
|
abstract class SpreedBlocEvents {
|
||
|
void createRoom(
|
||
|
final spreed.RoomType type,
|
||
|
final String? roomName,
|
||
|
final core.AutocompleteResult? invite,
|
||
|
);
|
||
|
}
|
||
|
|
||
|
abstract class SpreedBlocStates {
|
||
|
BehaviorSubject<Result<List<spreed.Room>>> get rooms;
|
||
|
|
||
|
BehaviorSubject<int> get unreadCounter;
|
||
|
}
|
||
|
|
||
|
class SpreedBloc extends InteractiveBloc implements SpreedBlocEvents, SpreedBlocStates {
|
||
|
SpreedBloc(
|
||
|
this.options,
|
||
|
this.account,
|
||
|
) {
|
||
|
rooms.listen((final result) {
|
||
|
if (result.hasData) {
|
||
|
unreadCounter.add(
|
||
|
[0, ...result.requireData.map((final room) => room.unreadMessages)].reduce((final a, final b) => a + b),
|
||
|
);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
unawaited(refresh());
|
||
|
}
|
||
|
|
||
|
final SpreedAppSpecificOptions options;
|
||
|
final Account account;
|
||
|
|
||
|
@override
|
||
|
void dispose() {
|
||
|
unawaited(rooms.close());
|
||
|
unawaited(unreadCounter.close());
|
||
|
super.dispose();
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
BehaviorSubject<Result<List<spreed.Room>>> rooms = BehaviorSubject();
|
||
|
|
||
|
@override
|
||
|
BehaviorSubject<int> unreadCounter = BehaviorSubject();
|
||
|
|
||
|
@override
|
||
|
Future<void> refresh() async {
|
||
|
await RequestManager.instance.wrapNextcloud(
|
||
|
account.id,
|
||
|
'spreed-rooms',
|
||
|
rooms,
|
||
|
account.client.spreed.room.getRoomsRaw(),
|
||
|
(final response) => response.body.ocs.data.toList(),
|
||
|
);
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
void createRoom(
|
||
|
final spreed.RoomType type,
|
||
|
final String? roomName,
|
||
|
final core.AutocompleteResult? invite,
|
||
|
) {
|
||
|
wrapAction(
|
||
|
() async => account.client.spreed.room.createRoom(
|
||
|
roomType: type.value,
|
||
|
roomName: roomName ?? '',
|
||
|
invite: invite?.id ?? '',
|
||
|
source: invite?.source ?? '',
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
}
|