treewide sweepfixes

This commit is contained in:
Henry Hiles 2026-10-14 17:01:39 -04:00
commit 012ecd9249
Signed by: Henry-Hiles
SSH key fingerprint: SHA256:VKQUdS31Q90KvX7EkKMHMBpUspcmItAh86a+v7PGiIs
41 changed files with 270 additions and 386 deletions

View file

@ -11,6 +11,7 @@ import "package:fluttertagger/fluttertagger.dart";
import "package:hooks_riverpod/hooks_riverpod.dart";
import "package:nexus/controllers/attachment.dart";
import "package:nexus/controllers/image_picker.dart";
import "package:image_picker/image_picker.dart";
import "package:nexus/controllers/power_level.dart";
import "package:nexus/models/content/message.dart";
import "package:nexus/models/relation_type.dart";
@ -89,6 +90,14 @@ class const Composer(
final attachment = ref.watch(AttachmentController.provider(roomId));
Future<void> attach(Future<XFile?> pick) async {
if (await pick case final file?) {
await ref
.read(AttachmentController.provider(roomId).notifier)
.add(file);
}
}
void send() {
if (controller.value.text.isEmpty && attachment == null ||
attachment != null && attachment.$2 == null) {
@ -173,53 +182,33 @@ class const Composer(
tooltip: "Add media",
enabled: attachment == null,
itemBuilder: (context) => [
if (Platform.isAndroid || Platform.isIOS)
for (final (source, title, icon) in [
if (Platform.isAndroid || Platform.isIOS)
(
ImageSource.camera,
"Camera",
Icons.add_a_photo,
),
(
ImageSource.gallery,
"Gallery",
Icons.add_photo_alternate,
),
])
PopupMenuItem(
child: ListTile(
title: Text("Camera"),
leading: Icon(Icons.add_a_photo),
title: Text(title),
leading: Icon(icon),
),
onTap: () async => ref
.read(
AttachmentController.provider(roomId)
.notifier,
)
.add(
(await ref
.watch(
ImagePickerController.provider,
)
.pickImage(source: .camera))!,
)
.onError(showError),
onTap: () => attach(
ref
.read(ImagePickerController.provider)
.pickImage(source: source),
).onError(showError),
),
PopupMenuItem(
child: ListTile(
title: Text("Gallery"),
leading: Icon(Icons.add_photo_alternate),
),
onTap: () async => ref
.read(
AttachmentController.provider(roomId)
.notifier,
)
.add(
(await ref
.watch(
ImagePickerController.provider,
)
.pickImage(source: .gallery))!,
)
.onError(showError),
),
PopupMenuItem(
onTap: () async => ref
.watch(
AttachmentController.provider(roomId)
.notifier,
)
.add((await openFile())!)
.onError(showError),
onTap: () =>
attach(openFile()).onError(showError),
child: ListTile(
title: Text("Files"),
leading: Icon(Icons.attachment),

View file

@ -26,7 +26,7 @@ class const EmojiPicker({
if (!isFreeText) {
await ref
.watch(RecentEmojiController.provider.notifier)
.read(RecentEmojiController.provider.notifier)
.add(emoji)
.onError(showError);
}

View file

@ -149,6 +149,6 @@ class const Html(
.nonNulls,
),
},
onTapUrl: (url) => ref.watch(LaunchHelper.provider).launchUrl(.parse(url)),
onTapUrl: (url) => ref.read(LaunchHelper.provider).launchUrl(.parse(url)),
);
}

View file

@ -16,7 +16,7 @@ final class const LinkifiedText(
style: style,
options: .new(humanize: false),
onOpen: (link) =>
ref.watch(LaunchHelper.provider).launchUrl(.parse(link.url)),
ref.read(LaunchHelper.provider).launchUrl(.parse(link.url)),
linkStyle: .new(color: Theme.of(context).colorScheme.primary),
overflow: maxLines == null ? null : .ellipsis,
);

View file

@ -79,9 +79,11 @@ class const MemberList(final String roomId, {super.key})
)
: Expanded(
child: CustomScrollView(
slivers: [
for (final MapEntry(key: powerLevel, value: members)
in value) ...[
slivers: value.expand((group) {
final MapEntry(key: powerLevel, value: members) =
group;
return [
SliverToBoxAdapter(
child: Padding(
padding: .symmetric(horizontal: 16),
@ -151,8 +153,8 @@ class const MemberList(final String roomId, {super.key})
}
},
),
],
],
];
}).toList(),
),
),
AsyncLoading _ => Loading(),

View file

@ -18,7 +18,7 @@ class const SelectServerPage({super.key}) extends HookConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) {
final theme = Theme.of(context);
final launch = ref.watch(LaunchHelper.provider).launchUrl;
final launch = ref.read(LaunchHelper.provider).launchUrl;
final isLoading = useState(false);
final homeserverUrl = useTextEditingController();
@ -52,7 +52,7 @@ class const SelectServerPage({super.key}) extends HookConsumerWidget {
AuthUrlController.provider(url).future,
);
await ref.watch(LaunchHelper.provider).launchUrl(codeResponse.url);
await ref.read(LaunchHelper.provider).launchUrl(codeResponse.url);
AppLinks().uriLinkStream.listen((encodedUri) async {
final state = encodedUri.queryParameters["state"];
@ -64,7 +64,7 @@ class const SelectServerPage({super.key}) extends HookConsumerWidget {
if (code != null) {
await ref
.watch(ClientController.provider.notifier)
.read(ClientController.provider.notifier)
.exchangeToken(
.new(
homeserverUrl: url,
@ -74,7 +74,7 @@ class const SelectServerPage({super.key}) extends HookConsumerWidget {
path: "/",
),
code: code,
clientId: await ref.watch(
clientId: await ref.read(
ClientIdController.provider(url).future,
),
),

View file

@ -30,7 +30,7 @@ class const SettingsPage({super.key}) extends ConsumerWidget {
barHintText: "Search...",
isFullScreen: categoriesArePages,
suggestionsBuilder: (suggestionsContext, controller) async {
final categories = await ref.watch(
final categories = await ref.read(
SettingsSectionsController.provider.future,
);
final query = controller.text.toLowerCase();

View file

@ -23,7 +23,7 @@ class const VerifyPage({super.key}) extends HookConsumerWidget {
}
inputError.value = await ref
.watch(ClientController.provider.notifier)
.read(ClientController.provider.notifier)
.verify(passphraseController.text);
} finally {
isLoading.value = false;

View file

@ -27,7 +27,7 @@ class const AudioPlayer(
player.platform?.state = player.platform!.state.copyWith(buffering: true);
scheduleMicrotask(() async {
final video = await ref
.watch(ClientController.provider.notifier)
.read(ClientController.provider.notifier)
.downloadMedia(.new(mxc: uri, encrypted: encrypted));
await player.open(Media(video.path), play: false);

View file

@ -25,7 +25,7 @@ class const VideoPlayer(
player.platform?.state = player.platform!.state.copyWith(buffering: true);
scheduleMicrotask(() async {
final video = await ref
.watch(ClientController.provider.notifier)
.read(ClientController.provider.notifier)
.downloadMedia(.new(mxc: uri, encrypted: encrypted));
await player.open(Media(video.path), play: false);
});

View file

@ -81,6 +81,15 @@ class const EventRenderer(
event.sender == previousEvent?.sender &&
event.pmp?.id == previousEvent?.pmp?.id;
GenericEventRenderer generic(IconData icon, String text) =>
.new(icon, maxLines: maxLines, [
WidgetSpan(
alignment: .middle,
child: MessageDisplayname(event, shouldWrap: maxLines == null),
),
TextSpan(text: text),
]);
final child = event.redactedBy != null || event.relationType == "m.replace"
? null
: switch (event.content) {
@ -122,169 +131,67 @@ class const EventRenderer(
_ => MembershipRenderer(event, maxLines: maxLines),
},
AvatarContent() => GenericEventRenderer(
AvatarContent() => generic(
Icons.interests,
maxLines: maxLines,
[
WidgetSpan(
alignment: .middle,
child: MessageDisplayname(
event,
shouldWrap: maxLines == null,
),
),
TextSpan(text: "changed the room avatar"),
],
"changed the room avatar",
),
CreateContent() => GenericEventRenderer(
Icons.add,
maxLines: maxLines,
[
WidgetSpan(
alignment: .middle,
child: MessageDisplayname(
event,
shouldWrap: maxLines == null,
),
),
TextSpan(text: "created the room"),
],
),
PowerLevelsContent() => GenericEventRenderer(
CreateContent() => generic(Icons.add, "created the room"),
PowerLevelsContent() => generic(
Icons.power,
maxLines: maxLines,
[
WidgetSpan(
alignment: .middle,
child: MessageDisplayname(
event,
shouldWrap: maxLines == null,
),
),
TextSpan(text: "changed the room's power levels"),
],
"changed the room's power levels",
),
JoinRulesContent() => GenericEventRenderer(
JoinRulesContent() => generic(
Icons.rule,
maxLines: maxLines,
[
WidgetSpan(
alignment: .middle,
child: MessageDisplayname(
event,
shouldWrap: maxLines == null,
),
),
TextSpan(text: "changed the room's join rules"),
],
"changed the room's join rules",
),
TopicContent() => GenericEventRenderer(
TopicContent() => generic(
Icons.description,
maxLines: maxLines,
[
WidgetSpan(
alignment: .middle,
child: MessageDisplayname(
event,
shouldWrap: maxLines == null,
),
),
TextSpan(text: "updated the room topic"),
],
"updated the room topic",
),
HistoryVisibilityContent(:final historyVisibility) =>
GenericEventRenderer(Icons.history, maxLines: maxLines, [
WidgetSpan(
alignment: .middle,
child: MessageDisplayname(
event,
shouldWrap: maxLines == null,
),
),
TextSpan(
text:
"changed the room's history visibility to ${switch (historyVisibility) {
.invited => "since invited",
.joined => "since joined",
.shared => "all history visible (shared)",
.worldReadable => "all history visible (world readable)",
}}",
),
]),
PinnedEventsContent() => GenericEventRenderer(
HistoryVisibilityContent(:final historyVisibility) => generic(
Icons.history,
"changed the room's history visibility to ${switch (historyVisibility) {
.invited => "since invited",
.joined => "since joined",
.shared => "all history visible (shared)",
.worldReadable => "all history visible (world readable)",
}}",
),
PinnedEventsContent() => generic(
Icons.push_pin,
maxLines: maxLines,
[
WidgetSpan(
alignment: .middle,
child: MessageDisplayname(
event,
shouldWrap: maxLines == null,
),
),
TextSpan(text: "pinned/unpinned some events"),
],
"pinned/unpinned some events",
),
ServerACLContent() => GenericEventRenderer(
ServerACLContent() => generic(
Icons.list,
maxLines: maxLines,
[
WidgetSpan(
alignment: .middle,
child: MessageDisplayname(
event,
shouldWrap: maxLines == null,
),
),
TextSpan(text: "updated the server ban list"),
],
"updated the server ban list",
),
CanonicalAliasContent(:final alias, :final altAliases) => generic(
Icons.numbers,
switch ([
if (event.previousContent case CanonicalAliasContent(
alias: final prevAlias,
altAliases: final prevAltAliases,
)) ...[
if (prevAlias != alias)
if (alias == null)
"removed the room's canonical alias"
else
"changed the room's canonical alias to $alias",
CanonicalAliasContent(:final alias, :final altAliases) =>
GenericEventRenderer(Icons.numbers, maxLines: maxLines, [
WidgetSpan(
alignment: .middle,
child: MessageDisplayname(
event,
shouldWrap: maxLines == null,
),
),
TextSpan(
text: switch ([
if (event.previousContent case CanonicalAliasContent(
alias: final prevAlias,
altAliases: final prevAltAliases,
)) ...[
if (prevAlias != alias)
if (alias == null)
"removed the room's canonical alias"
else
"changed the room's canonical alias to $alias",
if (prevAltAliases
.remove(alias ?? "")
.remove(prevAlias ?? "") !=
altAliases
.remove(alias ?? "")
.remove(prevAlias ?? ""))
"changed the room's aliases",
] else ...[
if (alias != null) "set the room's canonical alias",
if (altAliases.isNotEmpty) "set the room's aliases",
],
]) {
[] => "did something related to room aliases",
List prev => prev.join(" and "),
},
),
]),
if (prevAltAliases
.remove(alias ?? "")
.remove(prevAlias ?? "") !=
altAliases.remove(alias ?? "").remove(prevAlias ?? ""))
"changed the room's aliases",
] else ...[
if (alias != null) "set the room's canonical alias",
if (altAliases.isNotEmpty) "set the room's aliases",
],
]) {
[] => "did something related to room aliases",
List prev => prev.join(" and "),
},
),
_ => null,
};

View file

@ -1,3 +1,4 @@
import "package:collection/collection.dart";
import "package:material_ui/material_ui.dart";
class const GenericEventRenderer(
@ -17,12 +18,14 @@ class const GenericEventRenderer(
Flexible(
child: Text.rich(
TextSpan(
children: [
for (final (index, child) in children.indexed) ...[
if (index > 0) TextSpan(text: " "),
child,
],
],
children: children
.expandIndexed(
(index, child) => [
if (index > 0) TextSpan(text: " "),
child,
],
)
.toList(),
),
maxLines: maxLines ?? 999,
overflow: .ellipsis,

View file

@ -271,8 +271,7 @@ final class const RoomChat({
),
),
if (memberListOpened == true && showMembersByDefault)
MemberList(roomId),
if (memberListOpened && showMembersByDefault) MemberList(roomId),
],
),
),

View file

@ -4,6 +4,7 @@ import "package:hooks_riverpod/hooks_riverpod.dart";
import "package:material_ui/material_ui.dart";
import "package:navigation_rail_m3e/navigation_rail_m3e.dart";
import "package:nexus/helpers/extensions/get_all_child_rooms.dart";
import "package:nexus/helpers/extensions/room_destinations.dart";
import "package:nexus/models/nav_page.dart";
import "package:nexus/widgets/avatar_or_hash.dart";
import "package:nexus/widgets/divider_widget.dart";
@ -13,32 +14,11 @@ import "package:nexus/widgets/join_dialog.dart";
import "package:nexus/widgets/room_menu_button.dart";
import "package:nexus/controllers/key.dart";
import "package:nexus/controllers/spaces.dart";
import "package:nexus/models/room.dart";
import "package:collection/collection.dart";
import "package:fast_immutable_collections/fast_immutable_collections.dart";
// Needed for navigation_rail_m3e (#65).
import "package:flutter/material.dart" as old_mat;
List<NavigationRailM3EDestination> roomDestinations(
IList<Room> rooms, {
required bool isDm,
}) => [
for (final room in rooms)
.new(
label: room.metadata?.name ?? "Unnamed Room",
badgeCount: switch (room.metadata?.unreadNotifications) {
0 || null => room.metadata?.unreadMessages == 0 ? null : 0,
int unread => unread,
},
icon: AvatarOrHash(
room.metadata?.avatar,
room.metadata?.name ?? "Unnamed Room",
fallback: isDm ? null : const Icon(Icons.numbers),
),
),
];
class const RoomList({super.key}) extends ConsumerWidget implements NavPage {
@override
String get title => "Rooms";
@ -265,13 +245,12 @@ class const RoomsPane({super.key}) extends ConsumerWidget {
header: selectedSpace.room == null
? null
: const DividerWidget(Text("Rooms")),
destinations: roomDestinations(
selectedSpace.children,
destinations: selectedSpace.children.toDestinations(
isDm: isDm,
),
),
for (final subSpace in selectedSpace.subSpaces)
.new(
...selectedSpace.subSpaces.map(
(subSpace) => NavigationRailM3ESection(
header: DividerWidget(
Row(
mainAxisSize: .min,
@ -293,11 +272,9 @@ class const RoomsPane({super.key}) extends ConsumerWidget {
],
),
),
destinations: roomDestinations(
subSpace.children,
isDm: isDm,
),
destinations: subSpace.children.toDestinations(isDm: isDm),
),
),
],
onDestinationSelected: (value) {
ref

View file

@ -33,7 +33,7 @@ final class const RoomMenuButton(
if (room != null) ...[
PopupMenuItem(
onTap: () async {
final vias = ref.watch(ViaController.provider(room!));
final vias = ref.read(ViaController.provider(room!));
await Clipboard.setData(
.new(
@ -126,8 +126,10 @@ final class const RoomMenuButton(
duration: Duration(days: 1),
),
);
await client.leaveRoom(room!);
snackbar.close();
await client
.leaveRoom(room!)
.onError(showError)
.whenComplete(snackbar.close);
},
child: Text("Leave"),
),

View file

@ -15,7 +15,7 @@ class const UrlPreview(final Uri link, {super.key}) extends ConsumerWidget {
data: (preview) => preview == null
? SizedBox.shrink()
: InkWell(
onTap: () => ref.watch(LaunchHelper.provider).launchUrl(link),
onTap: () => ref.read(LaunchHelper.provider).launchUrl(link),
child: Card(
margin: .symmetric(vertical: 4),
color: Theme.of(context)

View file

@ -26,6 +26,9 @@ final class const UserBottomSheet(
Widget build(BuildContext context, WidgetRef ref) {
final theme = Theme.of(context);
final textTheme = theme.textTheme;
final subtitleStyle = textTheme.titleSmall?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
);
final client = ref.read(ClientController.provider.notifier);
void showMembershipDialog(MembershipAction action) => showDialog(
@ -112,13 +115,7 @@ final class const UserBottomSheet(
style: textTheme.headlineLarge,
textAlign: .center,
),
SelectableText(
userId,
textAlign: .center,
style: textTheme.titleSmall?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
),
SelectableText(userId, textAlign: .center, style: subtitleStyle),
ref
.watch(ProfileController.provider(userId))
@ -151,9 +148,7 @@ final class const UserBottomSheet(
Text(
pronoun.summary,
textAlign: .center,
style: textTheme.titleSmall?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
style: subtitleStyle,
),
],
)
@ -172,9 +167,7 @@ final class const UserBottomSheet(
Text(
profileResponse.profile.timezone!,
textAlign: .center,
style: textTheme.titleSmall?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
style: subtitleStyle,
),
],
],
@ -212,7 +205,6 @@ final class const UserBottomSheet(
Padding(
padding: .only(top: 4),
child: Row(
mainAxisSize: MainAxisSize.max,
spacing: 8,
children: [
if (member.status == .join || member.status == .invite)