From 92e0f66d43b97a696bb4ec98f2a23bb821b661d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20R=C3=A1=C5=BE?= Date: Tue, 17 Nov 2026 23:28:31 +0100 Subject: [PATCH] fix(chat): keep the header to the info button Collapsing the chat menu into one action promoted "jump to date" to its own icon in the app bar, where it reads as clutter next to the title. It belongs with the conversation's other actions, so it moves to the chat info page as a tile beside the search, and the header is back to the single info button. Both now hand a timestamp back to the chat page, which jumps to it: a picked day lands on its first message, a search hit on the message itself. --- lib/pages/chat_info_page.dart | 21 +++++++++++++++++ lib/pages/chat_page.dart | 44 +++++++++++------------------------ 2 files changed, 34 insertions(+), 31 deletions(-) diff --git a/lib/pages/chat_info_page.dart b/lib/pages/chat_info_page.dart index 13a8f48..a18c31c 100644 --- a/lib/pages/chat_info_page.dart +++ b/lib/pages/chat_info_page.dart @@ -99,6 +99,21 @@ class _ChatInfoPageState extends State { ); } + /// Pick a day and hand it back to the chat page, which jumps to the first + /// message of that day (or the first one after it). + Future _jumpToDate() async { + final now = DateTime.now(); + final picked = await showDatePicker( + context: context, + initialDate: now, + firstDate: DateTime(now.year - 10), + lastDate: now, + ); + if (picked != null && mounted) { + Navigator.pop(context, picked); + } + } + /// Search this conversation. A picked hit is handed back to the chat page, /// which jumps to it. Future _openSearch() async { @@ -133,6 +148,12 @@ class _ChatInfoPageState extends State { label: 'searchInChat'.tr(), onPressed: _openSearch, ), + // Jump to a day + SettingsTile( + icon: Icons.event, + label: 'jumpToDate'.tr(), + onPressed: _jumpToDate, + ), // Chat theme SettingsTile( icon: Icons.palette, diff --git a/lib/pages/chat_page.dart b/lib/pages/chat_page.dart index 8e96389..f759370 100644 --- a/lib/pages/chat_page.dart +++ b/lib/pages/chat_page.dart @@ -377,47 +377,34 @@ class _ChatPageState extends State { } Future _openChatInfo() async { - // The info page hands back a timestamp when a search hit was picked there. - final jumpTo = await Navigator.of(context) + // The info page hands back a timestamp when a search hit or a date was + // picked there. + final target = await Navigator.of(context) .push(stepRoute(ChatInfoPage(widget.user.id))); // The theme (and possibly the user) may have changed while it was open. await _loadChatTheme(); await _loadMessages(); - if (jumpTo != null && mounted) { - await _jumpToMessage(jumpTo); + if (target != null && mounted) { + await _jumpTo(target); } } - /// Jump to the first message of a picked day (or the first one after it). - Future _jumpToDate() async { + /// Jumps to [target], or to the first message after it: a search hit is an + /// exact instant, a picked day is midnight. + Future _jumpTo(DateTime target) async { if (_messages.isEmpty) { return; } - final oldest = _messages.first.sentAt.toLocal(); - final firstDay = DateTime(oldest.year, oldest.month, oldest.day); - final now = DateTime.now(); - final picked = await showDatePicker( - context: context, - initialDate: now, - firstDate: firstDay.isBefore(DateTime(2000)) ? DateTime(2000) : firstDay, - lastDate: now, - ); - if (picked == null || !mounted) { - return; - } - DateTime? target; - for (final message in _messages) { - if (!message.sentAt.isBefore(picked)) { - target = message.sentAt; - break; - } + var index = _messages.indexWhere((message) => message.sentAt == target); + if (index < 0) { + index = _messages.indexWhere((message) => message.sentAt.isAfter(target)); } - if (target == null) { + if (index < 0) { await Fluttertoast.showToast( msg: 'noMessagesOnDate'.tr(), backgroundColor: Colors.orange); return; } - await _jumpToMessage(target); + await _jumpToMessage(_messages[index].sentAt); } // --------------------------------------------------------------------------- @@ -1368,11 +1355,6 @@ class _ChatPageState extends State { ), // Action buttons actions: [ - IconButton( - icon: const Icon(Icons.event), - tooltip: 'jumpToDate'.tr(), - onPressed: _jumpToDate, - ), IconButton( icon: const Icon(Icons.info), tooltip: 'infoButton'.tr(),