Merge origin/dev into feat/group-editor-members-first

This commit is contained in:
zjs81 committed 2026-11-21 02:54:12 -07:00
commit 5e4e9bfce5
67 files changed
+5651 -1056

No files matched your search

+61 -62
View File
@@ -53,6 +53,7 @@ import '../widgets/empty_state.dart';
import '../widgets/filter_rule_dialog.dart';
import '../widgets/filtered_message_ghost.dart';
import '../widgets/chat_composer.dart';
import '../widgets/chat_compression_selector.dart';
import '../widgets/chat_send_pipeline.dart';
import '../widgets/chat_zoom_wrapper.dart';
import '../widgets/message_bubble_frame.dart';
@@ -843,12 +844,17 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
? _buildSearchResults(_loadSearchEntries)
: SafeArea(
top: false,
// The composer panel pads the bottom inset itself, so the
// background runs behind it to the screen edge.
bottom: false,
child: Column(
children: [
_buildCompressionSelector(),
Expanded(
child: ChatBackdrop(
key: _messageAreaKey,
contentKey: _messageAreaKey,
chatKey: ChatBackgroundService.channelKey(widget.channel),
footer: _buildInputBar(),
child: Consumer<MeshCoreConnector>(
builder: (context, connector, child) {
final messages = connector.getChannelMessages(
@@ -1064,7 +1070,6 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
),
),
),
_buildInputBar(),
],
),
),
@@ -2633,47 +2638,23 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
);
}
Widget _buildReplyBanner(double textScale) {
Widget _buildComposerReplyQuote(double textScale) {
final message = _replyingToMessage!;
final scheme = Theme.of(context).colorScheme;
final replyRegion = message.region;
return Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
decoration: BoxDecoration(
color: scheme.surfaceContainerHigh,
border: Border(
bottom: BorderSide(color: scheme.outlineVariant, width: 1),
),
return ChatComposerQuote(
title: context.l10n.chat_replyingTo(message.senderName),
content: _buildReplyContent(
message.text,
textScale,
color: scheme.onSurfaceVariant,
maxLines: 1,
gifSize: 48,
),
child: Row(
children: [
Icon(Icons.reply, size: 18, color: scheme.primary),
const SizedBox(width: 8),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
context.l10n.chat_replyingTo(message.senderName),
style: MeshTheme.mono(
fontSize: 12 * textScale,
fontWeight: FontWeight.w700,
color: scheme.primary,
),
),
_buildReplyContent(
message.text,
textScale,
color: scheme.onSurfaceVariant,
maxLines: 1,
gifSize: 48,
),
],
),
),
if (replyRegion?.isNotEmpty ?? false)
InkWell(
onDismiss: _cancelReply,
dismissTooltip: context.l10n.chat_cancelReply,
trailing: (replyRegion?.isNotEmpty ?? false)
? InkWell(
borderRadius: BorderRadius.circular(MeshRadii.xs),
onTap: () => setState(() => _useReplyRegion = !_useReplyRegion),
child: Container(
@@ -2691,6 +2672,8 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
),
child: Text(
context.l10n.channels_regionSetTo(replyRegion!),
maxLines: 1,
overflow: TextOverflow.ellipsis,
style:
MeshTheme.mono(
fontSize: 12 * textScale,
@@ -2704,17 +2687,8 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
),
),
),
),
const SizedBox(width: 4),
IconButton(
icon: const Icon(Icons.close, size: 18),
tooltip: context.l10n.chat_cancelReply,
onPressed: _cancelReply,
color: scheme.onSurfaceVariant,
constraints: const BoxConstraints(minWidth: 44, minHeight: 44),
),
],
),
)
: null,
);
}
@@ -2753,6 +2727,32 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
static String _replyPrefix(ChannelMessage replyTo) =>
'@[${replyTo.senderName}] ';
/// Compression is stored on this phone under the channel's storage ID, so
/// it can change while the radio is offline, but not before the slot has
/// one.
Widget _buildCompressionSelector() {
final slot = widget.channel.index;
return Consumer2<MeshCoreConnector, AppSettingsService>(
builder: (context, connector, settingsService, _) {
final hasStorageId = connector.channelIdForSlot(slot) != null;
return ChatCompressionSelector(
mode: connector.channelCompressionMode(slot),
enabled: hasStorageId,
disabledReason: hasStorageId
? null
: context.l10n.chatCompression_noStorageId,
profiles: settingsService.settings.cyr2latProfiles,
profileId: connector.getChannelCyr2LatProfileId(slot),
defaultProfileId: settingsService.settings.selectedCyr2latProfileId,
onModeChanged: (mode) =>
connector.setChannelCompressionMode(slot, mode),
onProfileChanged: (id) =>
connector.setChannelCyr2LatProfileId(slot, id),
);
},
);
}
Widget _buildInputBar() {
// Only the fields the composer depends on, so unrelated connector
// notifications (adverts, other chats, radio stats) don't rebuild it.
@@ -2790,18 +2790,17 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
: null,
onSend: _sendMessage,
sendTooltip: context.l10n.chat_sendMessage,
header: [
if (replyTo != null)
Builder(
builder: (context) {
final textScale = context.select<ChatTextScaleService, double>(
(service) => service.scale,
);
return _buildReplyBanner(textScale);
},
),
if (_imageSendTotal > 0) _buildImageSendProgress(scheme),
],
header: [if (_imageSendTotal > 0) _buildImageSendProgress(scheme)],
replyPreview: replyTo == null
? null
: Builder(
builder: (context) {
final textScale = context.select<ChatTextScaleService, double>(
(service) => service.scale,
);
return _buildComposerReplyQuote(textScale);
},
),
actionsBuilder: () {
final connector = context.read<MeshCoreConnector>();
return [
+22 -74
View File
@@ -783,13 +783,14 @@ class _ChannelsScreenState extends State<ChannelsScreen> {
break;
case ChannelSortOption.latestMessages:
// Filtered messages don't bump a channel, matching the preview.
// Ordered by local arrival time: sender clocks can be far off.
// Looked up once per channel: the lookup can scan back through
// filtered messages, and the comparator runs O(n log n) times.
final epoch = DateTime(1970);
final latest = <Channel, DateTime>{
for (final channel in filtered)
channel:
connector.latestVisibleChannelMessage(channel)?.timestamp ??
connector.latestVisibleChannelMessage(channel)?.receivedAt ??
epoch,
};
filtered.sort((a, b) {
@@ -1951,16 +1952,11 @@ void showEditChannelSheet(
context,
listen: false,
);
bool smazEnabled = connector.isChannelSmazEnabled(channel.index);
bool cyr2latEnabled = connector.isChannelCyr2LatEnabled(channel.index);
final initialUrlImagesEnabled = connector.isChannelUrlImagesEnabled(
channel.index,
);
bool urlImagesEnabled = initialUrlImagesEnabled;
final loadLinkImages = appSettingsService.settings.loadLinkImages;
String? selectedCyr2LatProfileId = connector.getChannelCyr2LatProfileId(
channel.index,
);
showMeshSheet(
context,
@@ -2018,62 +2014,6 @@ void showEditChannelSheet(
),
),
const SizedBox(height: 16),
SwitchListTile(
contentPadding: EdgeInsets.zero,
title: Text(sheetContext.l10n.channels_smazCompression),
value: smazEnabled,
onChanged: (value) => setSheetState(() {
smazEnabled = value;
if (smazEnabled) {
cyr2latEnabled = false;
}
}),
),
SwitchListTile(
contentPadding: EdgeInsets.zero,
title: Text(
sheetContext.l10n.channels_cyr2latCompression,
),
subtitle: Text(
sheetContext.l10n.channels_cyr2latCompressionDscr,
),
value: cyr2latEnabled,
onChanged: (value) => setSheetState(() {
cyr2latEnabled = value;
if (cyr2latEnabled) {
smazEnabled = false;
}
}),
),
if (cyr2latEnabled) ...[
Padding(
padding: const EdgeInsets.fromLTRB(0, 8, 0, 8),
child: DropdownButtonFormField<String>(
isExpanded: true,
initialValue: selectedCyr2LatProfileId,
decoration: InputDecoration(
labelText: sheetContext
.l10n
.channels_cyr2latSettingsSubheading,
border: const OutlineInputBorder(),
),
items: appSettingsService.settings.cyr2latProfiles
.map((profile) {
return DropdownMenuItem(
value: profile.id,
child: Text(
profile.name,
overflow: TextOverflow.ellipsis,
),
);
})
.toList(),
onChanged: (value) => setSheetState(() {
selectedCyr2LatProfileId = value;
}),
),
),
],
SwitchListTile(
contentPadding: EdgeInsets.zero,
title: Text(sheetContext.l10n.urlImage_enable),
@@ -2135,30 +2075,38 @@ void showEditChannelSheet(
}
Navigator.pop(sheetContext);
// A new PSK gives the channel a new storage ID;
// its compression settings move with it.
final previousId = connector.channelIdForSlot(
channel.index,
);
final compression = connector
.channelCompressionMode(channel.index);
final cyr2LatProfileId = connector
.getChannelCyr2LatProfileId(channel.index);
try {
await connector.setChannel(
channel.index,
name,
psk,
);
await connector.setChannelSmazEnabled(
channel.index,
smazEnabled,
);
await connector.setChannelCyr2LatEnabled(
channel.index,
cyr2latEnabled,
);
if (connector.channelIdForSlot(channel.index) !=
previousId) {
await connector.setChannelCompressionMode(
channel.index,
compression,
);
await connector.setChannelCyr2LatProfileId(
channel.index,
cyr2LatProfileId,
);
}
if (urlImagesEnabled != initialUrlImagesEnabled) {
await connector.setChannelUrlImagesEnabled(
channel.index,
urlImagesEnabled,
);
}
await connector.setChannelCyr2LatProfileId(
channel.index,
selectedCyr2LatProfileId,
);
if (!context.mounted) return;
showDismissibleSnackBar(
context,
+27 -97
View File
@@ -37,6 +37,7 @@ import '../services/chat_text_scale_service.dart';
import '../services/path_history_service.dart';
import '../services/translation_service.dart';
import '../widgets/chat_composer.dart';
import '../widgets/chat_compression_selector.dart';
import '../widgets/chat_send_pipeline.dart';
import '../widgets/chat_zoom_wrapper.dart';
import '../widgets/message_bubble_frame.dart';
@@ -622,12 +623,14 @@ class _ChatScreenState extends State<ChatScreen> {
);
return Column(
children: [
_buildCompressionSelector(connector),
Expanded(
child: ChatBackdrop(
key: _messageAreaKey,
contentKey: _messageAreaKey,
chatKey: ChatBackgroundService.contactKey(
widget.contact,
),
footer: _buildInputBar(connector),
child: Stack(
children: [
messages.isEmpty
@@ -640,7 +643,6 @@ class _ChatScreenState extends State<ChatScreen> {
),
),
),
_buildInputBar(connector),
],
);
},
@@ -648,6 +650,27 @@ class _ChatScreenState extends State<ChatScreen> {
);
}
/// Compression is stored on this phone per contact, so it can change
/// while the radio is offline.
Widget _buildCompressionSelector(MeshCoreConnector connector) {
final keyHex = widget.contact.publicKeyHex;
return Consumer<AppSettingsService>(
builder: (context, settingsService, _) {
return ChatCompressionSelector(
mode: connector.contactCompressionMode(keyHex),
enabled: true,
profiles: settingsService.settings.cyr2latProfiles,
profileId: connector.getContactCyr2LatProfileId(keyHex),
defaultProfileId: settingsService.settings.selectedCyr2latProfileId,
onModeChanged: (mode) =>
connector.setContactCompressionMode(keyHex, mode),
onProfileChanged: (id) =>
connector.setContactCyr2LatProfileId(keyHex, id),
);
},
);
}
Widget _buildEmptyState() {
if (_showBookmarkedOnly) return _buildBookmarkEmptyState();
return EmptyState(
@@ -1109,19 +1132,9 @@ class _ChatScreenState extends State<ChatScreen> {
void _showContactSettings(BuildContext context) {
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
final appSettingsService = Provider.of<AppSettingsService>(
context,
listen: false,
);
connector.ensureContactSmazSettingLoaded(widget.contact.publicKeyHex);
connector.ensureContactCyr2LatSettingLoaded(widget.contact.publicKeyHex);
// The live contact carries the current telemetry flags; widget.contact
// is the snapshot this screen was opened with.
final contact = _resolveContact(connector);
bool smazEnabled = connector.isContactSmazEnabled(contact.publicKeyHex);
bool cyr2latEnabled = connector.isContactCyr2LatEnabled(
contact.publicKeyHex,
);
bool urlImagesEnabled = connector.isContactUrlImagesEnabled(
contact.publicKeyHex,
);
@@ -1129,14 +1142,11 @@ class _ChatScreenState extends State<ChatScreen> {
.read<AppSettingsService>()
.settings
.loadLinkImages;
String? selectedCyr2LatProfileId = connector.getContactCyr2LatProfileId(
contact.publicKeyHex,
);
bool teleBaseEnabled = contact.teleBaseEnabled;
bool teleLocEnabled = contact.teleLocEnabled;
bool teleEnvEnabled = contact.teleEnvEnabled;
// Each toggle is committed immediately, like the compression switches,
// so dismissing the dialog by tapping outside keeps the change. All three
// Each toggle is committed immediately, like the link-image switch, so
// dismissing the dialog by tapping outside keeps the change. All three
// flags are sent every time so overlapping writes can't undo each other.
void commitTelemetryFlags() {
connector.setContactFlags(
@@ -1164,86 +1174,6 @@ class _ChatScreenState extends State<ChatScreen> {
),
const Divider(height: 8),
],
SwitchListTile(
contentPadding: EdgeInsets.zero,
title: Text(context.l10n.channels_smazCompression),
subtitle: Text(context.l10n.chat_compressOutgoingMessages),
value: smazEnabled,
onChanged: (value) {
connector.setContactSmazEnabled(
contact.publicKeyHex,
value,
);
connector.setContactCyr2LatEnabled(
contact.publicKeyHex,
false,
);
setDialogState(() {
smazEnabled = value;
if (smazEnabled) {
cyr2latEnabled = false;
}
});
},
),
const Divider(height: 8),
SwitchListTile(
contentPadding: EdgeInsets.zero,
title: Text(context.l10n.channels_cyr2latCompression),
subtitle: Text(context.l10n.channels_cyr2latCompressionDscr),
value: cyr2latEnabled,
onChanged: (value) {
connector.setContactCyr2LatEnabled(
contact.publicKeyHex,
value,
);
connector.setContactSmazEnabled(
contact.publicKeyHex,
false,
);
setDialogState(() {
cyr2latEnabled = value;
if (cyr2latEnabled) {
smazEnabled = false;
}
});
},
),
if (cyr2latEnabled) ...[
Padding(
padding: const EdgeInsets.fromLTRB(0, 8, 0, 8),
child: DropdownButtonFormField<String>(
isExpanded: true,
initialValue: selectedCyr2LatProfileId,
decoration: InputDecoration(
labelText:
context.l10n.channels_cyr2latSettingsSubheading,
border: const OutlineInputBorder(),
),
items: appSettingsService.settings.cyr2latProfiles.map((
profile,
) {
return DropdownMenuItem(
value: profile.id,
child: Text(
profile.name,
overflow: TextOverflow.ellipsis,
),
);
}).toList(),
onChanged: (value) {
connector.setContactCyr2LatProfileId(
contact.publicKeyHex,
value,
);
setDialogState(() {
selectedCyr2LatProfileId = value;
});
},
),
),
],
const Divider(height: 8),
SwitchListTile(
contentPadding: EdgeInsets.zero,
title: Text(context.l10n.urlImage_enable),
+77 -27
View File
@@ -81,6 +81,8 @@ class _ContactsScreenState extends State<ContactsScreen> {
final List<_PendingContactOperation> _pendingOperations = [];
final DerivedListCache<Contact> _filteredCache = DerivedListCache<Contact>();
final Map<String, _ContactTileEntrance> _rowCache = {};
MeshCoreConnector? _rowCacheConnector;
StreamSubscription<Uint8List>? _frameSubscription;
@@ -1099,21 +1101,12 @@ class _ContactsScreenState extends State<ContactsScreen> {
itemBuilder: (context, row) {
if (row == 0) return discoveredTile;
final index = row - 1;
final contact = filteredAndSorted[index];
final unreadCount = connector.getUnreadCountForContact(
contact,
);
return _ContactTileEntrance(
index: index,
contact: contact,
pathHashByteWidth: connector.pathHashByteWidth,
lastSeen: resolveContactLastSeen(contact),
unreadCount: unreadCount,
isFavorite: contact.isFavorite,
onTap: () => _openChat(context, contact),
onLongPress: () =>
_showContactOptions(context, connector, contact),
onManage: _manageAction(context, contact),
return _contactRow(
context,
connector,
filteredAndSorted[index],
index,
filteredAndSorted.length,
);
},
),
@@ -1123,6 +1116,54 @@ class _ContactsScreenState extends State<ContactsScreen> {
);
}
/// Returns the row built last time for [contact] when nothing it shows has
/// changed. The connector notifies up to 20 times a second on a busy mesh
/// and each notify rebuilds this screen; handing the list the same widget
/// instance lets Flutter skip rebuilding those rows.
_ContactTileEntrance _contactRow(
BuildContext context,
MeshCoreConnector connector,
Contact contact,
int index,
int rowCount,
) {
if (!identical(_rowCacheConnector, connector)) {
_rowCache.clear();
_rowCacheConnector = connector;
}
final unreadCount = connector.getUnreadCountForContact(contact);
final pathHashByteWidth = connector.pathHashByteWidth;
// Relative ("5 mins ago"), so it can change while the contact does not.
final lastSeenLabel = formatContactLastSeen(
context.l10n,
resolveContactLastSeen(contact),
);
final cached = _rowCache[contact.publicKeyHex];
if (cached != null &&
identical(cached.contact, contact) &&
cached.index == index &&
cached.unreadCount == unreadCount &&
cached.pathHashByteWidth == pathHashByteWidth &&
cached.lastSeenLabel == lastSeenLabel) {
return cached;
}
// Drop rows of contacts that left the list now and then.
if (_rowCache.length > rowCount + 100) _rowCache.clear();
return _rowCache[contact.publicKeyHex] = _ContactTileEntrance(
index: index,
contact: contact,
pathHashByteWidth: pathHashByteWidth,
lastSeenLabel: lastSeenLabel,
unreadCount: unreadCount,
isFavorite: contact.isFavorite,
// The State's context: rows outlive the list's item context while the
// list is swapped for an empty state.
onTap: () => _openChat(this.context, contact),
onLongPress: () => _showContactOptions(this.context, connector, contact),
onManage: _manageAction(this.context, contact),
);
}
List<Contact> _filterAndSortContacts(
List<Contact> contacts,
MeshCoreConnector connector,
@@ -1156,7 +1197,8 @@ class _ContactsScreenState extends State<ContactsScreen> {
DateTime _lastMessageTime(MeshCoreConnector connector, Contact contact) {
final messages = connector.getMessages(contact);
return messages.isEmpty ? DateTime(1970) : messages.last.timestamp;
// Local arrival time: sender clocks can be far off.
return messages.isEmpty ? DateTime(1970) : messages.last.receivedAt;
}
List<Contact> _computeFilteredContacts(
@@ -1204,16 +1246,24 @@ class _ContactsScreenState extends State<ContactsScreen> {
switch (viewState.contactsSortOption) {
case ContactSortOption.lastSeen:
filtered.sort(
(a, b) =>
resolveContactLastSeen(b).compareTo(resolveContactLastSeen(a)),
);
final lastSeenAt = {
for (final c in filtered)
c: resolveContactLastSeen(
c,
addedAt: connector.contactAddedAt(c.publicKeyHex),
),
};
filtered.sort((a, b) => lastSeenAt[b]!.compareTo(lastSeenAt[a]!));
break;
case ContactSortOption.recentMessages:
final lastMessageAt = {
for (final c in filtered) c: _lastMessageTime(connector, c),
};
filtered.sort((a, b) => lastMessageAt[b]!.compareTo(lastMessageAt[a]!));
filtered.sort((a, b) {
final timeCompare = lastMessageAt[b]!.compareTo(lastMessageAt[a]!);
if (timeCompare != 0) return timeCompare;
return a.name.toLowerCase().compareTo(b.name.toLowerCase());
});
break;
case ContactSortOption.name:
filtered.sort(
@@ -1737,7 +1787,7 @@ void confirmRemoveContact(
class _ContactTile extends StatelessWidget {
final Contact contact;
final int pathHashByteWidth;
final DateTime lastSeen;
final String lastSeenLabel;
final int unreadCount;
final bool isFavorite;
final VoidCallback onTap;
@@ -1747,7 +1797,7 @@ class _ContactTile extends StatelessWidget {
const _ContactTile({
required this.contact,
required this.pathHashByteWidth,
required this.lastSeen,
required this.lastSeenLabel,
required this.unreadCount,
required this.isFavorite,
required this.onTap,
@@ -1879,7 +1929,7 @@ class _ContactTile extends StatelessWidget {
],
),
Text(
formatContactLastSeen(context.l10n, lastSeen),
lastSeenLabel,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: MeshTheme.mono(
@@ -1956,7 +2006,7 @@ class _ContactTileEntrance extends StatelessWidget {
final int index;
final Contact contact;
final int pathHashByteWidth;
final DateTime lastSeen;
final String lastSeenLabel;
final int unreadCount;
final bool isFavorite;
final VoidCallback onTap;
@@ -1967,7 +2017,7 @@ class _ContactTileEntrance extends StatelessWidget {
required this.index,
required this.contact,
required this.pathHashByteWidth,
required this.lastSeen,
required this.lastSeenLabel,
required this.unreadCount,
required this.isFavorite,
required this.onTap,
@@ -1982,7 +2032,7 @@ class _ContactTileEntrance extends StatelessWidget {
child: _ContactTile(
contact: contact,
pathHashByteWidth: pathHashByteWidth,
lastSeen: lastSeen,
lastSeenLabel: lastSeenLabel,
unreadCount: unreadCount,
isFavorite: isFavorite,
onTap: onTap,