Merge origin/dev into cursor/routing-send-settings-ef15
This commit is contained in:
commit
4065d60a16
84 files changed
+7843
-1144
No files matched your search
@@ -5,15 +5,14 @@ import 'package:provider/provider.dart';
|
||||
import '../connector/meshcore_connector.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../models/app_settings.dart';
|
||||
import '../models/image_codec_support.dart';
|
||||
import '../services/app_settings_service.dart';
|
||||
import '../services/background_service.dart';
|
||||
import '../services/image_codec_service.dart';
|
||||
import '../services/map_tile_cache_service.dart';
|
||||
import '../services/notification_service.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../utils/platform_info.dart';
|
||||
import '../widgets/adaptive_app_bar_title.dart';
|
||||
import '../widgets/image_codec_models_section.dart';
|
||||
import '../widgets/cyr2lat_profile_dialog.dart';
|
||||
import '../widgets/language_picker_sheet.dart';
|
||||
import '../widgets/mesh_nav_tile.dart';
|
||||
@@ -460,6 +459,20 @@ class AppSettingsScreen extends StatelessWidget {
|
||||
value: settingsService.settings.regionOnHopsLine,
|
||||
onChanged: settingsService.setRegionOnHopsLine,
|
||||
),
|
||||
const Divider(height: 1, indent: 16),
|
||||
SwitchListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 4,
|
||||
),
|
||||
secondary: const Icon(Icons.compress, size: 24),
|
||||
title: Text(context.l10n.appSettings_showCompressionIndicator),
|
||||
subtitle: Text(
|
||||
context.l10n.appSettings_showCompressionIndicatorSubtitle,
|
||||
),
|
||||
value: settingsService.settings.showCompressionIndicator,
|
||||
onChanged: settingsService.setShowCompressionIndicator,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -769,7 +782,10 @@ class AppSettingsScreen extends StatelessWidget {
|
||||
onChanged: (value) =>
|
||||
settingsService.setImageProcessAutomatically(value),
|
||||
),
|
||||
_buildImageCodecModels(context),
|
||||
if (_imageCodecService(context) != null) ...[
|
||||
const Divider(height: 1, indent: 16),
|
||||
const ImageCodecModelsSection(),
|
||||
],
|
||||
],
|
||||
),
|
||||
],
|
||||
@@ -795,167 +811,6 @@ class AppSettingsScreen extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
/// Model registry for image messages: the download entry point, the
|
||||
/// downloaded weights, and — when the build simply cannot run the codec —
|
||||
/// [ImageCodecService.unavailableReason] instead of a dead download button.
|
||||
Widget _buildImageCodecModels(BuildContext context) {
|
||||
final ImageCodecService codec;
|
||||
try {
|
||||
codec = context.watch<ImageCodecService>();
|
||||
} on ProviderNotFoundException {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final textTheme = Theme.of(context).textTheme;
|
||||
final reason = codec.unavailableReason;
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 4, 16, 16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
context.l10n.imageMessages_modelSectionTitle,
|
||||
style: textTheme.titleSmall,
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
if (reason != null)
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: scheme.surfaceContainerLow,
|
||||
borderRadius: BorderRadius.circular(MeshRadii.md),
|
||||
border: Border.all(color: scheme.outlineVariant),
|
||||
),
|
||||
child: Text(
|
||||
reason,
|
||||
style: textTheme.bodyMedium?.copyWith(
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
for (final spec in imageCodecPresetModels)
|
||||
_buildImageCodecPreset(context, codec, spec),
|
||||
for (final model in codec.availableModels)
|
||||
ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
dense: true,
|
||||
leading: const Icon(Icons.check_circle_outline, size: 24),
|
||||
title: Text(model.name.isEmpty ? model.id : model.name),
|
||||
subtitle: Text(_formatModelBytes(context, model.fileSizeBytes)),
|
||||
trailing: IconButton(
|
||||
icon: const Icon(Icons.delete_outline, size: 24),
|
||||
tooltip: context.l10n.imageMessages_removeModel,
|
||||
onPressed: codec.isBusy || codec.isDownloading
|
||||
? null
|
||||
: () => codec.removeModel(model),
|
||||
),
|
||||
),
|
||||
if (codec.lastError != null) ...[
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
codec.lastError!,
|
||||
style: textTheme.bodyMedium?.copyWith(color: scheme.error),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildImageCodecPreset(
|
||||
BuildContext context,
|
||||
ImageCodecService codec,
|
||||
ImageCodecModelSpec spec,
|
||||
) {
|
||||
final textTheme = Theme.of(context).textTheme;
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final alreadyHave = spec.hasCompleteInstalledRecord(codec.availableModels);
|
||||
// downloadPresetModel throws StateError on a placeholder URL, deliberately,
|
||||
// so the button must not be offerable until the weights are published.
|
||||
final blocked = spec.urlsArePlaceholders;
|
||||
final busy = codec.isDownloading;
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 4),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
dense: true,
|
||||
leading: const Icon(Icons.download_outlined, size: 24),
|
||||
title: Text(spec.label),
|
||||
subtitle: Text(
|
||||
blocked
|
||||
? context.l10n.imageMessages_modelNotPublished
|
||||
: _formatModelBytes(context, spec.totalSizeBytes),
|
||||
),
|
||||
trailing: alreadyHave
|
||||
? Text(
|
||||
context.l10n.imageMessages_modelReady,
|
||||
style: textTheme.labelMedium?.copyWith(
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
)
|
||||
: busy
|
||||
? TextButton(
|
||||
onPressed: codec.cancelDownload,
|
||||
child: Text(context.l10n.imageMessages_cancelDownload),
|
||||
)
|
||||
: TextButton(
|
||||
onPressed: blocked
|
||||
? null
|
||||
: () => _downloadImageCodecModel(context, codec, spec),
|
||||
child: Text(context.l10n.imageMessages_downloadModel),
|
||||
),
|
||||
),
|
||||
if (busy)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: LinearProgressIndicator(value: codec.downloadProgress),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _downloadImageCodecModel(
|
||||
BuildContext context,
|
||||
ImageCodecService codec,
|
||||
ImageCodecModelSpec spec,
|
||||
) async {
|
||||
final messenger = ScaffoldMessenger.of(context);
|
||||
final l10n = context.l10n;
|
||||
try {
|
||||
await codec.downloadPresetModel(spec);
|
||||
} catch (error) {
|
||||
messenger.showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(l10n.imageMessages_downloadFailedWithError('$error')),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _formatModelBytes(BuildContext context, int bytes) {
|
||||
final l10n = context.l10n;
|
||||
if (bytes >= 1024 * 1024 * 1024) {
|
||||
return l10n.mapCache_sizeGigabytes(
|
||||
(bytes / (1024 * 1024 * 1024)).toStringAsFixed(2),
|
||||
);
|
||||
}
|
||||
if (bytes >= 1024 * 1024) {
|
||||
return l10n.mapCache_sizeMegabytes(
|
||||
(bytes / (1024 * 1024)).toStringAsFixed(0),
|
||||
);
|
||||
}
|
||||
if (bytes >= 1024) {
|
||||
return l10n.mapCache_sizeKilobytes((bytes / 1024).toStringAsFixed(0));
|
||||
}
|
||||
return l10n.mapCache_sizeBytes('$bytes');
|
||||
}
|
||||
|
||||
Widget _buildBatteryContent(
|
||||
BuildContext context,
|
||||
AppSettingsService settingsService,
|
||||
|
||||
@@ -22,6 +22,7 @@ import '../utils/platform_info.dart';
|
||||
import '../utils/share_origin.dart';
|
||||
import '../widgets/app_bar.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../widgets/model_download_list.dart';
|
||||
import '../widgets/sync_progress_overlay.dart';
|
||||
|
||||
class BackupRestoreScreen extends StatefulWidget {
|
||||
@@ -630,12 +631,6 @@ class _BackupRestoreScreenState extends State<BackupRestoreScreen> {
|
||||
required ImageCodecService imageCodecService,
|
||||
}) async {
|
||||
final l10n = context.l10n;
|
||||
final modelNames = [
|
||||
if (translationModel != null)
|
||||
translationModelFriendlyName(translationModel),
|
||||
if (imageCodecModel != null)
|
||||
imageCodecSpec?.label ?? imageCodecModel.name,
|
||||
];
|
||||
var starting = false;
|
||||
var cancelRequested = false;
|
||||
var translationDone = translationModel == null;
|
||||
@@ -658,16 +653,9 @@ class _BackupRestoreScreenState extends State<BackupRestoreScreen> {
|
||||
starting ||
|
||||
translationService.isDownloading ||
|
||||
imageCodecService.isDownloading;
|
||||
final currentProgress = currentModel == translationModel?.name
|
||||
? translationService.downloadProgress
|
||||
: currentModel == imageCodecModel?.name
|
||||
? imageCodecService.downloadProgress
|
||||
: null;
|
||||
final currentFile = currentModel == translationModel?.name
|
||||
? translationService.downloadFileName
|
||||
: currentModel == imageCodecModel?.name
|
||||
? imageCodecService.downloadFileName
|
||||
: null;
|
||||
final translationCurrent = currentModel == translationModel?.name;
|
||||
final imageCurrent = currentModel == imageCodecModel?.name;
|
||||
final failure = downloadError;
|
||||
|
||||
void requestDownloadCancel() {
|
||||
cancelRequested = true;
|
||||
@@ -682,31 +670,73 @@ class _BackupRestoreScreenState extends State<BackupRestoreScreen> {
|
||||
},
|
||||
child: AlertDialog(
|
||||
title: Text(l10n.backupRestore_missingModelsTitle),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
l10n.backupRestore_missingModelsMessage(
|
||||
modelNames.join('\n'),
|
||||
),
|
||||
),
|
||||
if (isDownloading) ...[
|
||||
const SizedBox(height: 16),
|
||||
Text(currentFile ?? currentModel ?? ''),
|
||||
const SizedBox(height: 8),
|
||||
LinearProgressIndicator(value: currentProgress),
|
||||
],
|
||||
if (downloadError != null) ...[
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(l10n.backupRestore_missingModelsMessage),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
l10n.backupRestore_failed(downloadError!),
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
ModelDownloadList(
|
||||
rowPadding: const EdgeInsets.symmetric(vertical: 4),
|
||||
items: [
|
||||
if (translationModel != null)
|
||||
_missingModelItem(
|
||||
id: 'translation-${translationModel.id}',
|
||||
name: translationModelFriendlyName(
|
||||
translationModel,
|
||||
),
|
||||
sizeBytes: translationModel.fileSizeBytes,
|
||||
done: translationDone,
|
||||
current: translationCurrent,
|
||||
downloading:
|
||||
translationService.isDownloading ||
|
||||
(starting && translationCurrent),
|
||||
progress: translationService.downloadProgress,
|
||||
downloadedBytes:
|
||||
translationService.downloadedBytes,
|
||||
totalBytes: translationService.downloadTotalBytes,
|
||||
detail:
|
||||
translationService.downloadFileName ==
|
||||
'Merging chunks...'
|
||||
? l10n.translation_mergingChunks
|
||||
: null,
|
||||
error: failure == null
|
||||
? null
|
||||
: l10n.backupRestore_failed(failure),
|
||||
),
|
||||
if (imageCodecModel != null)
|
||||
_missingModelItem(
|
||||
id: 'image-${imageCodecModel.id}',
|
||||
name:
|
||||
imageCodecSpec?.label ??
|
||||
imageCodecModelFriendlyName(imageCodecModel),
|
||||
sizeBytes:
|
||||
imageCodecSpec?.totalSizeBytes ??
|
||||
imageCodecModel.fileSizeBytes,
|
||||
done: imageCodecDone,
|
||||
current: imageCurrent,
|
||||
downloading:
|
||||
imageCodecService.isDownloading ||
|
||||
(starting && imageCurrent),
|
||||
progress: imageCodecService.downloadProgress,
|
||||
downloadedBytes:
|
||||
imageCodecService.downloadedBytes,
|
||||
totalBytes: imageCodecService.downloadTotalBytes,
|
||||
detail:
|
||||
imageCodecService.downloadFileName
|
||||
?.startsWith('Verifying ') ==
|
||||
true
|
||||
? l10n.modelDownload_verifying
|
||||
: null,
|
||||
error: failure == null
|
||||
? null
|
||||
: l10n.backupRestore_failed(failure),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
@@ -830,3 +860,40 @@ class _BackupRestoreScreenState extends State<BackupRestoreScreen> {
|
||||
showDismissibleSnackBar(context, content: Text(message));
|
||||
}
|
||||
}
|
||||
|
||||
ModelDownloadItem _missingModelItem({
|
||||
required String id,
|
||||
required String name,
|
||||
required int sizeBytes,
|
||||
required bool done,
|
||||
required bool current,
|
||||
required bool downloading,
|
||||
required double? progress,
|
||||
required int downloadedBytes,
|
||||
required int? totalBytes,
|
||||
required String? detail,
|
||||
required String? error,
|
||||
}) {
|
||||
final inProgress = downloading && current && !done;
|
||||
final failed = error != null && current && !inProgress && !done;
|
||||
return ModelDownloadItem(
|
||||
id: id,
|
||||
name: name,
|
||||
sizeBytes: sizeBytes > 0 ? sizeBytes : null,
|
||||
status: done
|
||||
? ModelDownloadStatus.ready
|
||||
: failed
|
||||
? ModelDownloadStatus.error
|
||||
: inProgress
|
||||
? ModelDownloadStatus.downloading
|
||||
: ModelDownloadStatus.notDownloaded,
|
||||
progress: inProgress ? progress : null,
|
||||
downloadedBytes: inProgress ? downloadedBytes : 0,
|
||||
totalBytes: inProgress ? totalBytes : null,
|
||||
detail: failed
|
||||
? error
|
||||
: inProgress
|
||||
? detail
|
||||
: null,
|
||||
);
|
||||
}
|
||||
@@ -99,12 +99,15 @@ class ChannelChatScreen extends StatefulWidget {
|
||||
State<ChannelChatScreen> createState() => _ChannelChatScreenState();
|
||||
}
|
||||
|
||||
class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
class _ChannelChatScreenState extends State<ChannelChatScreen>
|
||||
with WidgetsBindingObserver {
|
||||
final _holidayWatcher = HolidayTriggerWatcher();
|
||||
final _messageAreaKey = GlobalKey();
|
||||
final TextEditingController _textController = TextEditingController();
|
||||
final ChatScrollController _scrollController = ChatScrollController();
|
||||
final FocusNode _textFieldFocusNode = FocusNode();
|
||||
bool _focusLostWhileAway = false;
|
||||
bool _focusLostToRoute = false;
|
||||
ChannelMessage? _replyingToMessage;
|
||||
bool _useReplyRegion = false;
|
||||
final CommunityStore _communityStore = CommunityStore();
|
||||
@@ -135,6 +138,13 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
MeshCoreConnector? _connector;
|
||||
final ChatSendGuard _sendGuard = ChatSendGuard();
|
||||
bool _channelSkipNextBottomSnap = false;
|
||||
|
||||
/// Newest entry and selection size seen by the last bottom-snap check, so
|
||||
/// a rebuild that only changed the selection is not mistaken for a new
|
||||
/// message.
|
||||
String? _snapNewestEntryId;
|
||||
int _snapSelectionCount = 0;
|
||||
|
||||
String? _unreadDividerMessageId;
|
||||
_TranscriptLayout? _transcriptLayout;
|
||||
ReceivedImageStore? _watchedImageStore;
|
||||
@@ -173,6 +183,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
_textFieldFocusNode.addListener(_onTextFieldFocusChange);
|
||||
_scrollController.onScrollNearTop = _loadOlderMessages;
|
||||
_scrollController.showJumpToBottom.addListener(_clearDividerAtBottom);
|
||||
@@ -263,10 +274,28 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
if (state != AppLifecycleState.resumed) return;
|
||||
// The focus manager observes the lifecycle from app start, so its restore
|
||||
// is already queued and runs first. Clearing afterwards keeps a focus
|
||||
// that was not restored (the user clicked elsewhere) from swallowing the
|
||||
// next real tap on the composer.
|
||||
scheduleMicrotask(() => _focusLostWhileAway = false);
|
||||
}
|
||||
|
||||
void _onTextFieldFocusChange() {
|
||||
if (_textFieldFocusNode.hasFocus && mounted) {
|
||||
_scrollController.handleKeyboardOpen();
|
||||
if (!mounted) return;
|
||||
if (!_textFieldFocusNode.hasFocus) {
|
||||
final state = WidgetsBinding.instance.lifecycleState;
|
||||
_focusLostWhileAway = state != null && state != AppLifecycleState.resumed;
|
||||
_focusLostToRoute = !(ModalRoute.of(context)?.isCurrent ?? true);
|
||||
return;
|
||||
}
|
||||
final restored = _focusLostWhileAway || _focusLostToRoute;
|
||||
_focusLostWhileAway = false;
|
||||
_focusLostToRoute = false;
|
||||
if (!restored) _scrollController.handleKeyboardOpen();
|
||||
}
|
||||
|
||||
Future<void> _loadOlderMessages() async {
|
||||
@@ -347,6 +376,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
_route?.secondaryAnimation?.removeStatusListener(_onCoveringRouteStatus);
|
||||
_watchedImageStore?.removeListener(_onImageStoreChanged);
|
||||
_unregisterActive();
|
||||
@@ -929,12 +959,25 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
rowCount + (_isLoadingOlder ? 1 : 0);
|
||||
|
||||
// Auto-scroll to bottom if user is already at bottom
|
||||
final newestEntryId = layout.ids.first;
|
||||
final selectionCount = _selectedIds.length;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (!mounted) return;
|
||||
final newEntry =
|
||||
newestEntryId != _snapNewestEntryId;
|
||||
final selectionChanged =
|
||||
selectionCount != _snapSelectionCount;
|
||||
_snapNewestEntryId = newestEntryId;
|
||||
_snapSelectionCount = selectionCount;
|
||||
if (_channelSkipNextBottomSnap) {
|
||||
_channelSkipNextBottomSnap = false;
|
||||
return;
|
||||
}
|
||||
// Picking or clearing messages is not a new
|
||||
// message: keep the reading position.
|
||||
if (!newEntry && (_selecting || selectionChanged)) {
|
||||
return;
|
||||
}
|
||||
_scrollController.scrollToBottomIfAtBottom();
|
||||
});
|
||||
|
||||
@@ -1109,6 +1152,8 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
final publicIpfsGateway = settingsService.settings.publicIpfsGateway;
|
||||
final enableTracing = settingsService.settings.enableMessageTracing;
|
||||
final regionOnHopsLine = settingsService.settings.regionOnHopsLine;
|
||||
final showCompressionIndicator =
|
||||
settingsService.settings.showCompressionIndicator;
|
||||
final isOutgoing = message.isOutgoing;
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final gifId = GifHelper.parseGif(message.text);
|
||||
@@ -1423,8 +1468,10 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
bottom: 4,
|
||||
)
|
||||
: EdgeInsets.zero,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
child: Wrap(
|
||||
spacing: 4,
|
||||
runSpacing: 2,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
formatChatTime(context, message.timestamp),
|
||||
@@ -1433,20 +1480,23 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
color: metaColor,
|
||||
),
|
||||
),
|
||||
if (message.hasFutureTimestamp) ...[
|
||||
const SizedBox(width: 4),
|
||||
if (message.hasFutureTimestamp)
|
||||
FutureTimestampIndicator(size: 16 * textScale),
|
||||
],
|
||||
if (showCompressionIndicator &&
|
||||
message.isSmazCompressed)
|
||||
CompressionIndicator(
|
||||
size: 14 * textScale,
|
||||
color: metaColor,
|
||||
),
|
||||
if (enableTracing &&
|
||||
!isOutgoing &&
|
||||
message.repeatCount > 0) ...[
|
||||
const SizedBox(width: 6),
|
||||
const SizedBox(width: 2),
|
||||
Icon(
|
||||
Icons.repeat,
|
||||
size: 14 * textScale,
|
||||
color: metaColor,
|
||||
),
|
||||
const SizedBox(width: 2),
|
||||
Text(
|
||||
'${message.repeatCount}',
|
||||
style: MeshTheme.mono(
|
||||
@@ -1455,8 +1505,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
),
|
||||
),
|
||||
],
|
||||
if (isOutgoing) ...[
|
||||
const SizedBox(width: 4),
|
||||
if (isOutgoing)
|
||||
MessageStatusIcon(
|
||||
size: 16 * textScale,
|
||||
isAcked: false,
|
||||
@@ -1476,7 +1525,6 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
ChannelMessageStatus.failed,
|
||||
onColor: metaColor,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -20,6 +20,7 @@ import '../helpers/path_helper.dart';
|
||||
import '../helpers/reaction_helper.dart';
|
||||
import '../widgets/message_status_icon.dart';
|
||||
import '../widgets/empty_state.dart';
|
||||
import '../helpers/chat_scroll_anchor.dart';
|
||||
import '../helpers/chat_scroll_controller.dart';
|
||||
import '../helpers/gif_helper.dart';
|
||||
import '../helpers/ipfs_link_attach_flow.dart';
|
||||
@@ -90,12 +91,16 @@ class ChatScreen extends StatefulWidget {
|
||||
State<ChatScreen> createState() => _ChatScreenState();
|
||||
}
|
||||
|
||||
class _ChatScreenState extends State<ChatScreen> {
|
||||
class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
|
||||
final _holidayWatcher = HolidayTriggerWatcher();
|
||||
final _messageAreaKey = GlobalKey();
|
||||
final _textController = TextEditingController();
|
||||
final _scrollController = ChatScrollController();
|
||||
final _scrollAnchor = ChatScrollAnchor();
|
||||
({String id, bool bookmarksOnly})? _newestRow;
|
||||
final _textFieldFocusNode = FocusNode();
|
||||
bool _focusLostWhileAway = false;
|
||||
bool _focusLostToRoute = false;
|
||||
final GlobalKey _unreadScrollKey = GlobalKey();
|
||||
bool _isLoadingOlder = false;
|
||||
bool _showBookmarkedOnly = false;
|
||||
@@ -151,6 +156,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
_textFieldFocusNode.addListener(_onTextFieldFocusChange);
|
||||
_scrollController.onScrollNearTop = _loadOlderMessages;
|
||||
_scrollController.showJumpToBottom.addListener(_clearDividerAtBottom);
|
||||
@@ -218,10 +224,28 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
if (state != AppLifecycleState.resumed) return;
|
||||
// The focus manager observes the lifecycle from app start, so its restore
|
||||
// is already queued and runs first. Clearing afterwards keeps a focus
|
||||
// that was not restored (the user clicked elsewhere) from swallowing the
|
||||
// next real tap on the composer.
|
||||
scheduleMicrotask(() => _focusLostWhileAway = false);
|
||||
}
|
||||
|
||||
void _onTextFieldFocusChange() {
|
||||
if (_textFieldFocusNode.hasFocus && mounted) {
|
||||
_scrollController.handleKeyboardOpen();
|
||||
if (!mounted) return;
|
||||
if (!_textFieldFocusNode.hasFocus) {
|
||||
final state = WidgetsBinding.instance.lifecycleState;
|
||||
_focusLostWhileAway = state != null && state != AppLifecycleState.resumed;
|
||||
_focusLostToRoute = !(ModalRoute.of(context)?.isCurrent ?? true);
|
||||
return;
|
||||
}
|
||||
final restored = _focusLostWhileAway || _focusLostToRoute;
|
||||
_focusLostWhileAway = false;
|
||||
_focusLostToRoute = false;
|
||||
if (!restored) _scrollController.handleKeyboardOpen();
|
||||
}
|
||||
|
||||
Future<void> _loadOlderMessages() async {
|
||||
@@ -238,6 +262,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
_route?.secondaryAnimation?.removeStatusListener(_onCoveringRouteStatus);
|
||||
_unregisterActive();
|
||||
_scrollController.showJumpToBottom.removeListener(_clearDividerAtBottom);
|
||||
@@ -701,15 +726,41 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
final reversedMessages = visibleMessages.reversed.toList();
|
||||
final itemCount = reversedMessages.length + (_isLoadingOlder ? 1 : 0);
|
||||
|
||||
// A reader scrolled up keeps their place when messages arrive below, as
|
||||
// a room's backlog does in a burst right after login.
|
||||
final previous = _newestRow;
|
||||
final newest = (
|
||||
id: reversedMessages.first.messageId,
|
||||
bookmarksOnly: _showBookmarkedOnly,
|
||||
);
|
||||
_newestRow = newest;
|
||||
if (previous != null &&
|
||||
previous.bookmarksOnly == newest.bookmarksOnly &&
|
||||
previous.id != newest.id &&
|
||||
_pendingUnreadScrollTarget == null &&
|
||||
_scrollController.showJumpToBottom.value) {
|
||||
final inserted = reversedMessages.indexWhere(
|
||||
(m) => m.messageId == previous.id,
|
||||
);
|
||||
if (inserted > 0) _scrollAnchor.rowsInsertedBelow(inserted);
|
||||
}
|
||||
|
||||
// Auto-scroll to bottom if user is already at bottom
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (!mounted) return;
|
||||
if (_pendingUnreadScrollTarget != null) return;
|
||||
// Never take over a drag or fling: during a sync every update would
|
||||
// pull a reader who starts scrolling up back to the newest message.
|
||||
if (_scrollController.hasClients &&
|
||||
_scrollController.position.isScrollingNotifier.value) {
|
||||
return;
|
||||
}
|
||||
_scrollController.scrollToBottomIfAtBottom();
|
||||
});
|
||||
|
||||
return ChatZoomWrapper(
|
||||
child: ListView.builder(
|
||||
child: AnchoredChatListView.builder(
|
||||
scrollAnchor: _scrollAnchor,
|
||||
reverse: true, // List grows from bottom up
|
||||
controller: _scrollController,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 16),
|
||||
@@ -1584,6 +1635,8 @@ class _MessageBubble extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
final settingsService = context.watch<AppSettingsService>();
|
||||
final enableTracing = settingsService.settings.enableMessageTracing;
|
||||
final showCompressionIndicator =
|
||||
settingsService.settings.showCompressionIndicator;
|
||||
final isOutgoing = message.isOutgoing;
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final gifId = GifHelper.parseGif(message.text);
|
||||
@@ -1845,6 +1898,12 @@ class _MessageBubble extends StatelessWidget {
|
||||
FutureTimestampIndicator(
|
||||
size: 16 * textScale,
|
||||
),
|
||||
if (showCompressionIndicator &&
|
||||
message.isSmazCompressed)
|
||||
CompressionIndicator(
|
||||
size: 14 * textScale,
|
||||
color: metaColor,
|
||||
),
|
||||
if (isOutgoing) ...[
|
||||
const SizedBox(width: 2),
|
||||
MessageStatusIcon(
|
||||
|
||||
@@ -1243,34 +1243,38 @@ class _ContactsScreenState extends State<ContactsScreen> {
|
||||
}).toList();
|
||||
}
|
||||
|
||||
switch (viewState.contactsSortOption) {
|
||||
case ContactSortOption.lastSeen:
|
||||
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) {
|
||||
final timeCompare = lastMessageAt[b]!.compareTo(lastMessageAt[a]!);
|
||||
final lastSeenAt =
|
||||
viewState.contactsSortOption == ContactSortOption.lastSeen
|
||||
? {
|
||||
for (final c in filtered)
|
||||
c: resolveContactLastSeen(
|
||||
c,
|
||||
addedAt: connector.contactAddedAt(c.publicKeyHex),
|
||||
),
|
||||
}
|
||||
: null;
|
||||
final lastMessageAt =
|
||||
viewState.contactsSortOption == ContactSortOption.recentMessages
|
||||
? {for (final c in filtered) c: _lastMessageTime(connector, c)}
|
||||
: null;
|
||||
int tieBreak(Contact a, Contact b) {
|
||||
switch (viewState.contactsSortOption) {
|
||||
case ContactSortOption.lastSeen:
|
||||
return lastSeenAt![b]!.compareTo(lastSeenAt[a]!);
|
||||
case ContactSortOption.recentMessages:
|
||||
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(
|
||||
(a, b) => a.name.toLowerCase().compareTo(b.name.toLowerCase()),
|
||||
);
|
||||
break;
|
||||
case ContactSortOption.name:
|
||||
return a.name.toLowerCase().compareTo(b.name.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
filtered.sort(
|
||||
(a, b) =>
|
||||
compareContactQueryRank(a, b, viewState.contactsSearchText, tieBreak),
|
||||
);
|
||||
|
||||
return filtered;
|
||||
}
|
||||
|
||||
@@ -1459,11 +1463,14 @@ class _ContactsScreenState extends State<ContactsScreen> {
|
||||
builder: (builderContext, setDialogState) {
|
||||
final filteredContacts = filterQuery.isEmpty
|
||||
? sortedContacts
|
||||
: sortedContacts
|
||||
: (sortedContacts
|
||||
.where(
|
||||
(contact) => matchesContactQuery(contact, filterQuery),
|
||||
)
|
||||
.toList();
|
||||
.toList()
|
||||
..sort(
|
||||
(a, b) => compareContactQueryRank(a, b, filterQuery),
|
||||
));
|
||||
return AlertDialog(
|
||||
title: Text(
|
||||
isEditing
|
||||
|
||||
@@ -662,17 +662,32 @@ class _DiscoveryScreenState extends State<DiscoveryScreen> {
|
||||
return _matchesTypeFilter(contact);
|
||||
}).toList();
|
||||
|
||||
switch (sortOption) {
|
||||
case ContactSortOption.lastSeen:
|
||||
filtered.sort((a, b) => b.lastSeen.compareTo(a.lastSeen));
|
||||
break;
|
||||
case ContactSortOption.name:
|
||||
filtered.sort(
|
||||
(a, b) => a.name.toLowerCase().compareTo(b.name.toLowerCase()),
|
||||
);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
int tieBreak(Contact a, Contact b) {
|
||||
switch (sortOption) {
|
||||
case ContactSortOption.lastSeen:
|
||||
return b.lastSeen.compareTo(a.lastSeen);
|
||||
case ContactSortOption.name:
|
||||
return a.name.toLowerCase().compareTo(b.name.toLowerCase());
|
||||
default:
|
||||
return a.name.toLowerCase().compareTo(b.name.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
if (searchQuery.trim().isEmpty) {
|
||||
switch (sortOption) {
|
||||
case ContactSortOption.lastSeen:
|
||||
filtered.sort((a, b) => b.lastSeen.compareTo(a.lastSeen));
|
||||
case ContactSortOption.name:
|
||||
filtered.sort(
|
||||
(a, b) => a.name.toLowerCase().compareTo(b.name.toLowerCase()),
|
||||
);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
filtered.sort(
|
||||
(a, b) => compareContactQueryRank(a, b, searchQuery, tieBreak),
|
||||
);
|
||||
}
|
||||
|
||||
return filtered;
|
||||
|
||||
+30
-26
@@ -2292,13 +2292,14 @@ class _MapScreenState extends State<MapScreen> with WidgetsBindingObserver {
|
||||
) {
|
||||
final query = _searchQuery.trim().toLowerCase();
|
||||
final matches =
|
||||
allContacts.where((c) => matchesContactQuery(c, query)).toList()
|
||||
..sort((a, b) {
|
||||
allContacts.where((c) => matchesContactQuery(c, query)).toList()..sort(
|
||||
(a, b) => compareContactQueryRank(a, b, query, (a, b) {
|
||||
if (a.hasLocation != b.hasLocation) {
|
||||
return a.hasLocation ? -1 : 1;
|
||||
}
|
||||
return b.lastHeard.compareTo(a.lastHeard);
|
||||
});
|
||||
}),
|
||||
);
|
||||
final results = matches.take(8).toList();
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(top: 6),
|
||||
@@ -3464,6 +3465,15 @@ class _MapScreenState extends State<MapScreen> with WidgetsBindingObserver {
|
||||
contact.type != advTypeRoom,
|
||||
)
|
||||
.toList();
|
||||
final people = allContacts
|
||||
.where(
|
||||
(contact) =>
|
||||
query.isEmpty || matchesContactQuery(contact, query),
|
||||
)
|
||||
.toList();
|
||||
if (query.isNotEmpty) {
|
||||
people.sort((a, b) => compareContactQueryRank(a, b, query));
|
||||
}
|
||||
return SafeArea(
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
@@ -3499,29 +3509,23 @@ class _MapScreenState extends State<MapScreen> with WidgetsBindingObserver {
|
||||
},
|
||||
),
|
||||
),
|
||||
...allContacts
|
||||
.where(
|
||||
(contact) =>
|
||||
query.isEmpty ||
|
||||
matchesContactQuery(contact, query),
|
||||
)
|
||||
.map((contact) {
|
||||
return ListTile(
|
||||
leading: const Icon(Icons.person),
|
||||
title: Text(contact.name),
|
||||
onTap: () {
|
||||
Navigator.pop(sheetContext);
|
||||
if (!_markerFits(
|
||||
context,
|
||||
markerText,
|
||||
maxContactMessageBytes(),
|
||||
)) {
|
||||
return;
|
||||
}
|
||||
liveConnector.sendMessage(contact, markerText);
|
||||
},
|
||||
);
|
||||
}),
|
||||
...people.map((contact) {
|
||||
return ListTile(
|
||||
leading: const Icon(Icons.person),
|
||||
title: Text(contact.name),
|
||||
onTap: () {
|
||||
Navigator.pop(sheetContext);
|
||||
if (!_markerFits(
|
||||
context,
|
||||
markerText,
|
||||
maxContactMessageBytes(),
|
||||
)) {
|
||||
return;
|
||||
}
|
||||
liveConnector.sendMessage(contact, markerText);
|
||||
},
|
||||
);
|
||||
}),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 4),
|
||||
child: Text(
|
||||
|
||||
Reference in new issue
Block a user