Browse Source

fix(neon): Fix user status heartbeat

Signed-off-by: jld3103 <jld3103yt@gmail.com>
pull/589/head
jld3103 1 year ago
parent
commit
0cb48a8892
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 22
      packages/neon/neon/lib/src/blocs/user_statuses.dart

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

@ -61,21 +61,31 @@ class UserStatusesBloc extends InteractiveBloc implements UserStatusesBlocEvents
_updateStatus(username, Result.loading());
UserStatusPublic? data;
if (_account.username == username) {
final isAway =
_platform.canUseWindowManager && (!(await windowManager.isFocused()) || !(await windowManager.isVisible()));
final response = await _account.client.userStatus.heartbeat.heartbeat(
status: isAway ? 'away' : 'online',
);
data = response.ocs.data.public;
} else {
try {
final response = await _account.client.userStatus.heartbeat.heartbeat(
status: isAway ? 'away' : 'online',
);
data = response.ocs.data.public;
} 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) {
rethrow;
}
}
}
if (data == null) {
final response = await _account.client.userStatus.statuses.find(userId: username);
data = response.ocs.data;
}
_updateStatus(username, Result.success(data));
} catch (e, s) {
if (e is DynamiteApiException && (e.statusCode == 404 || e.statusCode == 204)) {
if (e is DynamiteApiException && e.statusCode == 404) {
_updateStatus(username, Result.success(null));
return;
}

Loading…
Cancel
Save