From 2b83e69c1f9a98c4400a7b25045f8735567dad28 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Sun, 6 Jun 2021 10:00:52 +0200 Subject: [PATCH] refactor: active room ID now only in defined in the path --- lib/pages/chat.dart | 1 - lib/pages/views/chat_view.dart | 1 - lib/utils/background_push.dart | 6 ++++-- lib/utils/matrix_sdk_extensions.dart/fluffy_client.dart | 3 --- lib/widgets/matrix.dart | 5 ++++- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/pages/chat.dart b/lib/pages/chat.dart index d2279646..54d88177 100644 --- a/lib/pages/chat.dart +++ b/lib/pages/chat.dart @@ -204,7 +204,6 @@ class ChatController extends State { void dispose() { timeline?.cancelSubscriptions(); timeline = null; - matrix.client.activeRoomId = ''; super.dispose(); } diff --git a/lib/pages/views/chat_view.dart b/lib/pages/views/chat_view.dart index d5c71cf8..49153f79 100644 --- a/lib/pages/views/chat_view.dart +++ b/lib/pages/views/chat_view.dart @@ -47,7 +47,6 @@ class ChatView extends StatelessWidget { ), ); } - controller.matrix.client.activeRoomId = controller.roomId; if (controller.room.membership == Membership.invite) { showFutureLoadingDialog( diff --git a/lib/utils/background_push.dart b/lib/utils/background_push.dart index c80cee66..a839cfc8 100644 --- a/lib/utils/background_push.dart +++ b/lib/utils/background_push.dart @@ -586,8 +586,10 @@ class BackgroundPush { await room.postLoad(); final event = await client.database.getEventById(client.id, eventId, room); - if (((client.activeRoomId?.isNotEmpty ?? false) && - client.activeRoomId == room.id && + final activeRoomId = router.currentState.pathParameters['roomid']; + + if (((activeRoomId?.isNotEmpty ?? false) && + activeRoomId == room.id && client.syncPresence == null) || (event != null && room.notificationCount == 0)) { return; diff --git a/lib/utils/matrix_sdk_extensions.dart/fluffy_client.dart b/lib/utils/matrix_sdk_extensions.dart/fluffy_client.dart index 337e3bef..50e6c7ce 100644 --- a/lib/utils/matrix_sdk_extensions.dart/fluffy_client.dart +++ b/lib/utils/matrix_sdk_extensions.dart/fluffy_client.dart @@ -7,9 +7,6 @@ import '../famedlysdk_store.dart'; class FluffyClient extends Client { static FluffyClient _instance; - /// The ID of the currently active room, if there is one. May be null or emtpy - String activeRoomId; - factory FluffyClient({testMode = false}) { _instance ??= FluffyClient._internal(testMode: testMode); return _instance; diff --git a/lib/widgets/matrix.dart b/lib/widgets/matrix.dart index e0d16af1..7df092cd 100644 --- a/lib/widgets/matrix.dart +++ b/lib/widgets/matrix.dart @@ -204,9 +204,12 @@ class MatrixState extends State with WidgetsBindingObserver { bool webHasFocus = true; + String get activeRoomId => + VRouter.of(navigatorContext).pathParameters['roomid']; + void _showLocalNotification(EventUpdate eventUpdate) async { final roomId = eventUpdate.roomID; - if (webHasFocus && client.activeRoomId == roomId) return; + if (webHasFocus && activeRoomId == roomId) return; final room = client.getRoomById(roomId); if (room.notificationCount == 0) return; final event = Event.fromJson(eventUpdate.content, room);