Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions assets/translations/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,21 @@
"selectedCount": "Vybráno: %d",
"moreActions": "Další akce",
"jumpToLatest": "Skočit na nejnovější",
"searchMessages": "Hledat zprávy",
"searchInChat": "Hledat v tomto chatu",
"searchHint": "Hledat v lokální historii",
"searchEmptyHint": "Napiš text nebo zvol filtr. Zprávy se hledají jen v tomto zařízení.",
"noSearchResults": "Nic nenalezeno",
"anyType": "Jakýkoli typ",
"textOnly": "Text",
"anyDate": "Kdykoli",
"anySender": "Kdokoli",
"jumpToDate": "Skočit na datum",
"noMessagesOnDate": "Žádné zprávy od toho dne",
"allChats": "Vše",
"unreadChats": "Nepřečtené",
"pinnedChats": "Připnuté",
"noChatsInFilter": "Tady nic není",
"chatPinned": "Chat připnut",
"chatUnpinned": "Chat odebrán z připnutých",
"noChatsToForward": "Zatím žádné chaty, vyhledej uživatele",
Expand Down
15 changes: 15 additions & 0 deletions assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,21 @@
"selectedCount": "%d selected",
"moreActions": "More actions",
"jumpToLatest": "Jump to latest",
"searchMessages": "Search messages",
"searchInChat": "Search in this chat",
"searchHint": "Search the local history",
"searchEmptyHint": "Type something, or pick a filter. Messages are searched on this device only.",
"noSearchResults": "Nothing found",
"anyType": "Any type",
"textOnly": "Text",
"anyDate": "Any date",
"anySender": "Anyone",
"jumpToDate": "Jump to date",
"noMessagesOnDate": "No messages from that day or later",
"allChats": "All",
"unreadChats": "Unread",
"pinnedChats": "Pinned",
"noChatsInFilter": "Nothing here",
"chatPinned": "Chat pinned",
"chatUnpinned": "Chat unpinned",
"noChatsToForward": "No chats yet, search for a user",
Expand Down
83 changes: 82 additions & 1 deletion lib/pages/chat_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ import '../widgets/attachment_confirm_sheet.dart';
import '../widgets/chat_bubble.dart';
import 'chat_info_page.dart';
import 'forward_page.dart';
import 'search_page.dart';

class ChatPage extends StatefulWidget {
const ChatPage(this.user, {super.key});
const ChatPage(this.user, {this.jumpTo, super.key});
final User user;

/// Opens the conversation at this message instead of the newest one.
final DateTime? jumpTo;

@override
State<ChatPage> createState() => _ChatPageState();
}
Expand Down Expand Up @@ -123,6 +127,10 @@ class _ChatPageState extends State<ChatPage> {
await _loadMessages();
// Then top the conversation up from the server archive
_loadHistory();
final jumpTo = widget.jumpTo;
if (jumpTo != null) {
await _jumpToMessage(jumpTo);
}
}

/// Keeps the newest message on screen when the keyboard opens.
Expand Down Expand Up @@ -383,6 +391,47 @@ class _ChatPageState extends State<ChatPage> {
await _loadMessages();
}

/// Search this conversation; the picked result is jumped to.
Future<void> _openSearch() async {
final picked = await Navigator.of(context)
.push<DateTime>(stepRoute(MessageSearchPage(peer: widget.user)));
if (picked != null && mounted) {
await _jumpToMessage(picked);
}
}

/// Jump to the first message of a picked day (or the first one after it).
Future<void> _jumpToDate() 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;
}
}
if (target == null) {
await Fluttertoast.showToast(
msg: 'noMessagesOnDate'.tr(), backgroundColor: Colors.orange);
return;
}
await _jumpToMessage(target);
}

// ---------------------------------------------------------------------------
// Reply and multi-select
// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -1331,6 +1380,38 @@ class _ChatPageState extends State<ChatPage> {
),
// Action buttons
actions: [
PopupMenuButton<String>(
tooltip: 'moreActions'.tr(),
onSelected: (value) {
if (value == 'search') {
_openSearch();
} else {
_jumpToDate();
}
},
itemBuilder: (context) => [
PopupMenuItem(
value: 'search',
child: Row(
children: [
const Icon(Icons.search),
const SizedBox(width: 12),
Text('searchInChat'.tr()),
],
),
),
PopupMenuItem(
value: 'jumpDate',
child: Row(
children: [
const Icon(Icons.event),
const SizedBox(width: 12),
Text('jumpToDate'.tr()),
],
),
),
],
),
IconButton(
icon: const Icon(Icons.info),
tooltip: 'infoButton'.tr(),
Expand Down
74 changes: 73 additions & 1 deletion lib/pages/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import '../utils/message_notifier.dart';
import '../utils/notification_service.dart';
import 'search_user_page.dart';
import 'settings_page.dart';
import 'search_page.dart';
import '../utils/dialog_utils.dart';
import '../widgets/invite_list_item.dart';
import 'package:whisper_openapi_client_dart/api.dart';
Expand All @@ -33,6 +34,12 @@ class HomePage extends StatefulWidget {
State<HomePage> createState() => _HomePageState();
}

/// Which rows the chat list shows.
///
/// The roadmap lists folders for unread and favourites; favourites arrive in F7
/// with contacts, so the pinned chats stand in for them.
enum _ChatFilter { all, unread, pinned }

class _HomePageState extends State<HomePage>
with SingleTickerProviderStateMixin {
final WebSocketManager _webSocketManager = WebSocketManager();
Expand All @@ -46,6 +53,9 @@ class _HomePageState extends State<HomePage>

/// Conversation ids pinned to the top of the list.
Set<String> _pinnedChats = {};

/// Which rows the list shows; folders without extra storage.
_ChatFilter _filter = _ChatFilter.all;
bool _firstLoad = true;
String? _pendingFid; // Store pending FID

Expand Down Expand Up @@ -333,6 +343,56 @@ class _HomePageState extends State<HomePage>
await _getServerInvites();
}

/// Chats that pass the current folder filter.
List<MapEntry<User, PrivateMessage>> get _visibleChats {
switch (_filter) {
case _ChatFilter.unread:
return _chatEntries
.where((chat) => (_unreadCounts[chat.key.id] ?? 0) > 0)
.toList();
case _ChatFilter.pinned:
return _chatEntries
.where((chat) => _pinnedChats.contains(chat.key.id))
.toList();
case _ChatFilter.all:
return _chatEntries;
}
}

String _filterLabel(_ChatFilter filter) {
switch (filter) {
case _ChatFilter.all:
return 'allChats'.tr();
case _ChatFilter.unread:
return 'unreadChats'.tr();
case _ChatFilter.pinned:
return 'pinnedChats'.tr();
}
}

/// Folder chips above the list: everything, unread, pinned.
Widget _filterChips() {
return SingleChildScrollView(
scrollDirection: Axis.horizontal,
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
child: Row(
children: [
for (final filter in _ChatFilter.values)
Padding(
padding: const EdgeInsets.only(right: 8),
child: ChoiceChip(
label: Text(_filterLabel(filter)),
selected: _filter == filter,
onSelected: (_) => setState(() {
_filter = filter;
}),
),
),
],
),
);
}

/// Get ListView with content
ListView _getContent(List<MapEntry<User, PrivateMessage>> chats) {
_firstLoad = false;
Expand Down Expand Up @@ -424,6 +484,15 @@ class _HomePageState extends State<HomePage>
title: Text('msgPage'.tr()),
// Action buttons
actions: [
// Search across every locally stored conversation
IconButton(
icon: const Icon(Icons.search),
tooltip: 'searchMessages'.tr(),
onPressed: () {
Navigator.of(context)
.push(stepRoute(const MessageSearchPage()));
},
),
// Settings
IconButton(
icon: const Icon(Icons.settings),
Expand Down Expand Up @@ -485,6 +554,7 @@ class _HomePageState extends State<HomePage>
Column(
children: [
SizedBox(height: 10),
_filterChips(),
// Messages and avatar list
Expanded(
child: _firstLoad
Expand All @@ -494,7 +564,9 @@ class _HomePageState extends State<HomePage>
child: CircularProgressIndicator(),
),
)
: _getContent(_chatEntries),
: _visibleChats.isEmpty
? Center(child: Text('noChatsInFilter'.tr()))
: _getContent(_visibleChats),
),
],
),
Expand Down
Loading
Loading