|
|
@ -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; |
|
|
|
} |
|
|
|
} |
|
|
|