Browse Source

feat(neon,nextcloud): adapt to inheritance

Signed-off-by: Nikolas Rimikis <leptopoda@users.noreply.github.com>
pull/704/head
Nikolas Rimikis 1 year ago
parent
commit
483b0e975a
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 15
      packages/neon/neon/lib/src/blocs/user_statuses.dart
  2. 4
      packages/neon/neon/lib/src/widgets/user_avatar.dart
  3. 96
      packages/nextcloud/test/user_status_test.dart

15
packages/neon/neon/lib/src/blocs/user_statuses.dart

@ -16,7 +16,7 @@ abstract class UserStatusesBlocEvents {
}
abstract class UserStatusesBlocStates {
BehaviorSubject<Map<String, Result<UserStatusPublic?>>> get statuses;
BehaviorSubject<Map<String, Result<UserStatusPublicInterface?>>> get statuses;
}
@internal
@ -39,8 +39,8 @@ class UserStatusesBloc extends InteractiveBloc implements UserStatusesBlocEvents
}
@override
BehaviorSubject<Map<String, Result<UserStatusPublic?>>> statuses =
BehaviorSubject<Map<String, Result<UserStatusPublic?>>>();
BehaviorSubject<Map<String, Result<UserStatusPublicInterface?>>> statuses =
BehaviorSubject<Map<String, Result<UserStatusPublicInterface?>>>();
@override
Future refresh() async {
@ -58,7 +58,7 @@ class UserStatusesBloc extends InteractiveBloc implements UserStatusesBlocEvents
try {
_updateStatus(username, Result.loading());
UserStatusPublic? data;
UserStatusPublicInterface? data;
if (_account.username == username) {
var isAway = false;
@ -71,7 +71,7 @@ class UserStatusesBloc extends InteractiveBloc implements UserStatusesBlocEvents
final response = await _account.client.userStatus.heartbeat.heartbeat(
status: isAway ? 'away' : 'online',
);
data = response.ocs.data.public;
data = response.ocs.data;
} catch (e) {
// 204 is returned if the heartbeat failed because the current status is different. Ignore this and fetch the normal status
if (e is! DynamiteApiException || e.statusCode != 204) {
@ -97,9 +97,10 @@ class UserStatusesBloc extends InteractiveBloc implements UserStatusesBlocEvents
}
}
Map<String, Result<UserStatusPublic?>> get _statuses => statuses.valueOrNull ?? <String, Result<UserStatusPublic?>>{};
Map<String, Result<UserStatusPublicInterface?>> get _statuses =>
statuses.valueOrNull ?? <String, Result<UserStatusPublicInterface?>>{};
void _updateStatus(final String username, final Result<UserStatusPublic?> result) {
void _updateStatus(final String username, final Result<UserStatusPublicInterface?> result) {
statuses.add({
..._statuses,
username: result,

4
packages/neon/neon/lib/src/widgets/user_avatar.dart

@ -85,7 +85,7 @@ class _UserAvatarState extends State<NeonUserAvatar> {
),
),
if (widget.showStatus) ...[
ResultBuilder<UserStatusPublic?>(
ResultBuilder<UserStatusPublicInterface?>(
stream: _userStatusBloc.statuses.mapNotNull((final statuses) => statuses[widget.username]),
builder: _userStatusIconBuilder,
),
@ -95,7 +95,7 @@ class _UserAvatarState extends State<NeonUserAvatar> {
},
);
Widget _userStatusIconBuilder(final BuildContext context, final Result<UserStatusPublic?> result) {
Widget _userStatusIconBuilder(final BuildContext context, final Result<UserStatusPublicInterface?> result) {
final hasEmoji = result.data?.icon != null;
final scaledSize = size / (hasEmoji ? 2 : 2.5);

96
packages/nextcloud/test/user_status_test.dart

@ -52,14 +52,14 @@ void main() {
test('Set status', () async {
final response = await client.userStatus.userStatus.setStatus(statusType: 'online');
expect(response.ocs.data.public.userId, 'user1');
expect(response.ocs.data.public.message, null);
expect(response.ocs.data.private1.messageId, null);
expect(response.ocs.data.private1.messageIsPredefined, false);
expect(response.ocs.data.public.icon, null);
expect(response.ocs.data.public.clearAt, null);
expect(response.ocs.data.public.status, 'online');
expect(response.ocs.data.private1.statusIsUserDefined, true);
expect(response.ocs.data.userId, 'user1');
expect(response.ocs.data.message, null);
expect(response.ocs.data.messageId, null);
expect(response.ocs.data.messageIsPredefined, false);
expect(response.ocs.data.icon, null);
expect(response.ocs.data.clearAt, null);
expect(response.ocs.data.status, 'online');
expect(response.ocs.data.statusIsUserDefined, true);
});
test('Get status', () async {
@ -68,14 +68,14 @@ void main() {
await client.userStatus.userStatus.setStatus(statusType: 'online');
final response = await client.userStatus.userStatus.getStatus();
expect(response.ocs.data.public.userId, 'user1');
expect(response.ocs.data.public.message, null);
expect(response.ocs.data.private1.messageId, null);
expect(response.ocs.data.private1.messageIsPredefined, false);
expect(response.ocs.data.public.icon, null);
expect(response.ocs.data.public.clearAt, null);
expect(response.ocs.data.public.status, 'online');
expect(response.ocs.data.private1.statusIsUserDefined, true);
expect(response.ocs.data.userId, 'user1');
expect(response.ocs.data.message, null);
expect(response.ocs.data.messageId, null);
expect(response.ocs.data.messageIsPredefined, false);
expect(response.ocs.data.icon, null);
expect(response.ocs.data.clearAt, null);
expect(response.ocs.data.status, 'online');
expect(response.ocs.data.statusIsUserDefined, true);
});
test('Find all statuses', () async {
@ -111,14 +111,14 @@ void main() {
messageId: 'meeting',
clearAt: clearAt,
);
expect(response.ocs.data.public.userId, 'user1');
expect(response.ocs.data.public.message, null);
expect(response.ocs.data.private1.messageId, 'meeting');
expect(response.ocs.data.private1.messageIsPredefined, true);
expect(response.ocs.data.public.icon, null);
expect(response.ocs.data.public.clearAt, clearAt);
expect(response.ocs.data.public.status, 'offline');
expect(response.ocs.data.private1.statusIsUserDefined, false);
expect(response.ocs.data.userId, 'user1');
expect(response.ocs.data.message, null);
expect(response.ocs.data.messageId, 'meeting');
expect(response.ocs.data.messageIsPredefined, true);
expect(response.ocs.data.icon, null);
expect(response.ocs.data.clearAt, clearAt);
expect(response.ocs.data.status, 'offline');
expect(response.ocs.data.statusIsUserDefined, false);
});
test('Set custom message', () async {
@ -128,14 +128,14 @@ void main() {
message: 'bla',
clearAt: clearAt,
);
expect(response.ocs.data.public.userId, 'user1');
expect(response.ocs.data.public.message, 'bla');
expect(response.ocs.data.private1.messageId, null);
expect(response.ocs.data.private1.messageIsPredefined, false);
expect(response.ocs.data.public.icon, '😀');
expect(response.ocs.data.public.clearAt, clearAt);
expect(response.ocs.data.public.status, 'offline');
expect(response.ocs.data.private1.statusIsUserDefined, false);
expect(response.ocs.data.userId, 'user1');
expect(response.ocs.data.message, 'bla');
expect(response.ocs.data.messageId, null);
expect(response.ocs.data.messageIsPredefined, false);
expect(response.ocs.data.icon, '😀');
expect(response.ocs.data.clearAt, clearAt);
expect(response.ocs.data.status, 'offline');
expect(response.ocs.data.statusIsUserDefined, false);
});
test('Clear message', () async {
@ -148,26 +148,26 @@ void main() {
await client.userStatus.userStatus.clearMessage();
final response = await client.userStatus.userStatus.getStatus();
expect(response.ocs.data.public.userId, 'user1');
expect(response.ocs.data.public.message, null);
expect(response.ocs.data.private1.messageId, null);
expect(response.ocs.data.private1.messageIsPredefined, false);
expect(response.ocs.data.public.icon, null);
expect(response.ocs.data.public.clearAt, null);
expect(response.ocs.data.public.status, 'offline');
expect(response.ocs.data.private1.statusIsUserDefined, false);
expect(response.ocs.data.userId, 'user1');
expect(response.ocs.data.message, null);
expect(response.ocs.data.messageId, null);
expect(response.ocs.data.messageIsPredefined, false);
expect(response.ocs.data.icon, null);
expect(response.ocs.data.clearAt, null);
expect(response.ocs.data.status, 'offline');
expect(response.ocs.data.statusIsUserDefined, false);
});
test('Heartbeat', () async {
final response = await client.userStatus.heartbeat.heartbeat(status: 'online');
expect(response.ocs.data.public.userId, 'user1');
expect(response.ocs.data.public.message, null);
expect(response.ocs.data.private1.messageId, null);
expect(response.ocs.data.private1.messageIsPredefined, false);
expect(response.ocs.data.public.icon, null);
expect(response.ocs.data.public.clearAt, null);
expect(response.ocs.data.public.status, 'online');
expect(response.ocs.data.private1.statusIsUserDefined, false);
expect(response.ocs.data.userId, 'user1');
expect(response.ocs.data.message, null);
expect(response.ocs.data.messageId, null);
expect(response.ocs.data.messageIsPredefined, false);
expect(response.ocs.data.icon, null);
expect(response.ocs.data.clearAt, null);
expect(response.ocs.data.status, 'online');
expect(response.ocs.data.statusIsUserDefined, false);
});
},
retry: retryCount,

Loading…
Cancel
Save