Fix online status not being restored properly

Closes #11
This commit is contained in:
Nutcake 2023-10-21 12:39:09 +02:00
parent c5c4d446f3
commit 9f08e6ce62
3 changed files with 10 additions and 4 deletions

View file

@ -6,6 +6,7 @@ import 'package:recon/apis/session_api.dart';
import 'package:recon/apis/user_api.dart'; import 'package:recon/apis/user_api.dart';
import 'package:recon/clients/api_client.dart'; import 'package:recon/clients/api_client.dart';
import 'package:recon/clients/notification_client.dart'; import 'package:recon/clients/notification_client.dart';
import 'package:recon/clients/settings_client.dart';
import 'package:recon/crypto_helper.dart'; import 'package:recon/crypto_helper.dart';
import 'package:recon/hub_manager.dart'; import 'package:recon/hub_manager.dart';
import 'package:recon/models/hub_events.dart'; import 'package:recon/models/hub_events.dart';
@ -37,6 +38,7 @@ class MessagingClient extends ChangeNotifier {
final HubManager _hubManager = HubManager(); final HubManager _hubManager = HubManager();
final Map<String, Session> _sessionMap = {}; final Map<String, Session> _sessionMap = {};
final Set<String> _knownSessionKeys = {}; final Set<String> _knownSessionKeys = {};
final SettingsClient _settingsClient;
Friend? selectedFriend; Friend? selectedFriend;
Timer? _statusHeartbeat; Timer? _statusHeartbeat;
@ -47,9 +49,11 @@ class MessagingClient extends ChangeNotifier {
UserStatus get userStatus => _userStatus; UserStatus get userStatus => _userStatus;
MessagingClient({required ApiClient apiClient, required NotificationClient notificationClient}) MessagingClient({required ApiClient apiClient, required NotificationClient notificationClient, required SettingsClient settingsClient})
: _apiClient = apiClient, : _apiClient = apiClient,
_notificationClient = notificationClient { _notificationClient = notificationClient,
_settingsClient = settingsClient
{
debugPrint("mClient created: $hashCode"); debugPrint("mClient created: $hashCode");
Hive.openBox(_messageBoxKey).then((box) async { Hive.openBox(_messageBoxKey).then((box) async {
await box.delete(_lastUpdateKey); await box.delete(_lastUpdateKey);
@ -276,7 +280,8 @@ class MessagingClient extends ChangeNotifier {
await _refreshUnreads(); await _refreshUnreads();
_unreadSafeguard = Timer.periodic(_unreadSafeguardDuration, (timer) => _refreshUnreads()); _unreadSafeguard = Timer.periodic(_unreadSafeguardDuration, (timer) => _refreshUnreads());
_hubManager.send("RequestStatus", arguments: [null, false]); _hubManager.send("RequestStatus", arguments: [null, false]);
await setOnlineStatus(OnlineStatus.online); final lastOnline = OnlineStatus.values.elementAtOrNull(_settingsClient.currentSettings.lastOnlineStatus.valueOrDefault);
await setOnlineStatus(lastOnline ?? OnlineStatus.online);
_statusHeartbeat = Timer.periodic(_statusHeartbeatDuration, (timer) { _statusHeartbeat = Timer.periodic(_statusHeartbeatDuration, (timer) {
setOnlineStatus(_userStatus.onlineStatus); setOnlineStatus(_userStatus.onlineStatus);
}); });

View file

@ -164,6 +164,7 @@ class _ReConState extends State<ReCon> {
ChangeNotifierProvider( ChangeNotifierProvider(
create: (context) => MessagingClient( create: (context) => MessagingClient(
apiClient: clientHolder.apiClient, apiClient: clientHolder.apiClient,
settingsClient: clientHolder.settingsClient,
notificationClient: clientHolder.notificationClient, notificationClient: clientHolder.notificationClient,
), ),
), ),

View file

@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts # In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix. # of the product and file versions while build-number is used as the build suffix.
version: 0.9.2-beta+1 version: 0.9.3-beta+1
environment: environment:
sdk: '>=3.0.1' sdk: '>=3.0.1'