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. 14
      packages/neon/neon/lib/src/blocs/user_statuses.dart

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

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

Loading…
Cancel
Save