diff --git a/lib/controllers/client_controller.dart b/lib/controllers/client_controller.dart index dc964dd..4faf631 100644 --- a/lib/controllers/client_controller.dart +++ b/lib/controllers/client_controller.dart @@ -1,7 +1,8 @@ import "dart:convert"; import "dart:io"; import "package:flutter/foundation.dart"; -import "package:flutter_vodozemac/flutter_vodozemac.dart"; +import "package:vodozemac/vodozemac.dart" as voz; +import "package:flutter_vodozemac/flutter_vodozemac.dart" as voz_fl; import "package:matrix/matrix.dart"; import "package:flutter_riverpod/flutter_riverpod.dart"; import "package:nexus/controllers/secure_storage_controller.dart"; @@ -14,7 +15,7 @@ class ClientController extends AsyncNotifier { static const sessionBackupKey = "sessionBackup"; @override Future build() async { - await init(); + if (!voz.isInitialized()) await voz_fl.init(); final client = Client( "nexus", logLevel: kReleaseMode ? Level.warning : Level.verbose, @@ -45,6 +46,10 @@ class ClientController extends AsyncNotifier { ); } + ref.onDispose( + client.onRoomState.stream.listen((_) => ref.notifyListeners()).cancel, + ); + return client; } diff --git a/lib/pages/chat_page.dart b/lib/pages/chat_page.dart index ff1f99d..c60cc45 100644 --- a/lib/pages/chat_page.dart +++ b/lib/pages/chat_page.dart @@ -1,6 +1,6 @@ import "package:flutter/material.dart"; -import "package:nexus/widgets/chat/room_chat.dart"; -import "package:nexus/widgets/chat/sidebar.dart"; +import "package:nexus/widgets/chat_page/room_chat.dart"; +import "package:nexus/widgets/chat_page/sidebar.dart"; class ChatPage extends StatelessWidget { const ChatPage({super.key}); diff --git a/lib/widgets/chat/chat_box.dart b/lib/widgets/chat_page/chat_box.dart similarity index 100% rename from lib/widgets/chat/chat_box.dart rename to lib/widgets/chat_page/chat_box.dart diff --git a/lib/widgets/chat/code_block.dart b/lib/widgets/chat_page/code_block.dart similarity index 100% rename from lib/widgets/chat/code_block.dart rename to lib/widgets/chat_page/code_block.dart diff --git a/lib/widgets/chat/member_list.dart b/lib/widgets/chat_page/member_list.dart similarity index 100% rename from lib/widgets/chat/member_list.dart rename to lib/widgets/chat_page/member_list.dart diff --git a/lib/widgets/chat/room_appbar.dart b/lib/widgets/chat_page/room_appbar.dart similarity index 100% rename from lib/widgets/chat/room_appbar.dart rename to lib/widgets/chat_page/room_appbar.dart diff --git a/lib/widgets/chat/room_chat.dart b/lib/widgets/chat_page/room_chat.dart similarity index 97% rename from lib/widgets/chat/room_chat.dart rename to lib/widgets/chat_page/room_chat.dart index 36e1f3c..2f23655 100644 --- a/lib/widgets/chat/room_chat.dart +++ b/lib/widgets/chat_page/room_chat.dart @@ -14,12 +14,12 @@ import "package:nexus/controllers/current_room_controller.dart"; import "package:nexus/controllers/room_chat_controller.dart"; import "package:nexus/helpers/extension_helper.dart"; import "package:nexus/helpers/launch_helper.dart"; -import "package:nexus/widgets/chat/chat_box.dart"; -import "package:nexus/widgets/chat/code_block.dart"; -import "package:nexus/widgets/chat/member_list.dart"; -import "package:nexus/widgets/chat/room_appbar.dart"; -import "package:nexus/widgets/chat/spoiler_text.dart"; -import "package:nexus/widgets/chat/top_widget.dart"; +import "package:nexus/widgets/chat_page/chat_box.dart"; +import "package:nexus/widgets/chat_page/code_block.dart"; +import "package:nexus/widgets/chat_page/member_list.dart"; +import "package:nexus/widgets/chat_page/room_appbar.dart"; +import "package:nexus/widgets/chat_page/spoiler_text.dart"; +import "package:nexus/widgets/chat_page/top_widget.dart"; import "package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart"; class RoomChat extends HookConsumerWidget { diff --git a/lib/widgets/chat/sidebar.dart b/lib/widgets/chat_page/sidebar.dart similarity index 82% rename from lib/widgets/chat/sidebar.dart rename to lib/widgets/chat_page/sidebar.dart index 7df0860..e6e98e6 100644 --- a/lib/widgets/chat/sidebar.dart +++ b/lib/widgets/chat_page/sidebar.dart @@ -40,11 +40,22 @@ class Sidebar extends HookConsumerWidget { destinations: spaces .map( (space) => NavigationRailDestination( - icon: AvatarOrHash( - space.avatar, - fallback: space.icon, - space.title, - headers: space.client.headers, + icon: Badge( + smallSize: 8, + backgroundColor: Theme.of( + context, + ).colorScheme.primary, + isLabelVisible: + space.children.firstWhereOrNull( + (room) => room.roomData.hasNewMessages, + ) != + null, + child: AvatarOrHash( + space.avatar, + fallback: space.icon, + space.title, + headers: space.client.headers, + ), ), label: Text(space.title), padding: EdgeInsets.only(top: 4), @@ -73,18 +84,11 @@ class Sidebar extends HookConsumerWidget { return Scaffold( backgroundColor: Colors.transparent, appBar: AppBar( - leading: Badge( - isLabelVisible: - space.children.firstWhereOrNull( - (room) => room.roomData.isUnread, - ) != - null, - child: AvatarOrHash( - space.avatar, - fallback: space.icon, - space.title, - headers: space.client.headers, - ), + leading: AvatarOrHash( + space.avatar, + fallback: space.icon, + space.title, + headers: space.client.headers, ), title: Text( space.title, @@ -104,7 +108,7 @@ class Sidebar extends HookConsumerWidget { (room) => NavigationRailDestination( label: Text(room.title), icon: Badge( - isLabelVisible: room.roomData.isUnread, + isLabelVisible: room.roomData.hasNewMessages, child: AvatarOrHash( room.avatar, room.title, diff --git a/lib/widgets/chat/spoiler_text.dart b/lib/widgets/chat_page/spoiler_text.dart similarity index 100% rename from lib/widgets/chat/spoiler_text.dart rename to lib/widgets/chat_page/spoiler_text.dart diff --git a/lib/widgets/chat/top_widget.dart b/lib/widgets/chat_page/top_widget.dart similarity index 100% rename from lib/widgets/chat/top_widget.dart rename to lib/widgets/chat_page/top_widget.dart diff --git a/pubspec.lock b/pubspec.lock index 1e56f04..ac2c7b3 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1589,7 +1589,7 @@ packages: source: hosted version: "15.0.2" vodozemac: - dependency: transitive + dependency: "direct main" description: name: vodozemac sha256: "39144e20740807731871c9248d811ed5a037b21d0aa9ffcfa630954de74139d9" diff --git a/pubspec.yaml b/pubspec.yaml index 6fad88a..33601fd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -59,6 +59,7 @@ dependencies: flutter_svg: ^2.2.2 simple_secure_storage: ^0.3.6 json_annotation: ^4.9.0 + vodozemac: ^0.4.0 dev_dependencies: build_runner: ^2.4.11