mirror of
https://github.com/dz0ny/meshcore-sar.git
synced 2026-08-11 16:30:28 +00:00
Hide last seen and tweak channels
This commit is contained in:
@@ -240,6 +240,5 @@ extension ContactLocalization on Contact {
|
|||||||
return '$routeHopCount hop${routeHopCount == 1 ? '' : 's'} via $routeHashSize-byte hashes';
|
return '$routeHopCount hop${routeHopCount == 1 ? '' : 's'} via $routeHashSize-byte hashes';
|
||||||
}
|
}
|
||||||
|
|
||||||
bool get routeSupportsLegacyRawTransport =>
|
bool get routeSupportsLegacyRawTransport => routeHasPath;
|
||||||
routeHasPath && routeSignedPathLen >= 0;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1974,14 +1974,13 @@ class AppProvider with ChangeNotifier {
|
|||||||
if (requester == null ||
|
if (requester == null ||
|
||||||
!requester.routeHasPath ||
|
!requester.routeHasPath ||
|
||||||
requester.routeHopCount > _maxDirectPayloadHops ||
|
requester.routeHopCount > _maxDirectPayloadHops ||
|
||||||
!requester.routeSupportsLegacyRawTransport ||
|
|
||||||
requester.outPath.isEmpty) {
|
requester.outPath.isEmpty) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
unawaited(
|
unawaited(
|
||||||
connectionProvider.sendRawVoicePacket(
|
connectionProvider.sendRawVoicePacket(
|
||||||
contactPath: requester.outPath,
|
contactPath: requester.outPath,
|
||||||
contactPathLen: requester.routeSignedPathLen,
|
contactPathLen: requester.routeEncodedPathLen,
|
||||||
payload: availability.encodeBinary(),
|
payload: availability.encodeBinary(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -2051,7 +2050,7 @@ class AppProvider with ChangeNotifier {
|
|||||||
for (final peer in peers) {
|
for (final peer in peers) {
|
||||||
await connectionProvider.sendRawVoicePacket(
|
await connectionProvider.sendRawVoicePacket(
|
||||||
contactPath: peer.outPath,
|
contactPath: peer.outPath,
|
||||||
contactPathLen: peer.routeSignedPathLen,
|
contactPathLen: peer.routeEncodedPathLen,
|
||||||
payload: request.encodeBinary(),
|
payload: request.encodeBinary(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -2074,7 +2073,6 @@ class AppProvider with ChangeNotifier {
|
|||||||
if (responder == null ||
|
if (responder == null ||
|
||||||
!responder.routeHasPath ||
|
!responder.routeHasPath ||
|
||||||
responder.routeHopCount > _maxDirectPayloadHops ||
|
responder.routeHopCount > _maxDirectPayloadHops ||
|
||||||
!responder.routeSupportsLegacyRawTransport ||
|
|
||||||
responder.outPath.isEmpty) {
|
responder.outPath.isEmpty) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -2166,7 +2164,7 @@ class AppProvider with ChangeNotifier {
|
|||||||
|
|
||||||
await connectionProvider.sendRawVoicePacket(
|
await connectionProvider.sendRawVoicePacket(
|
||||||
contactPath: target.outPath,
|
contactPath: target.outPath,
|
||||||
contactPathLen: target.routeSignedPathLen,
|
contactPathLen: target.routeEncodedPathLen,
|
||||||
payload: payload,
|
payload: payload,
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
@@ -2407,9 +2405,6 @@ class AppProvider with ChangeNotifier {
|
|||||||
if (!target.routeHasPath || target.routeHopCount > _maxDirectPayloadHops) {
|
if (!target.routeHasPath || target.routeHopCount > _maxDirectPayloadHops) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!target.routeSupportsLegacyRawTransport) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (target.outPath.isEmpty) {
|
if (target.outPath.isEmpty) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -2442,7 +2437,7 @@ class AppProvider with ChangeNotifier {
|
|||||||
);
|
);
|
||||||
await connectionProvider.sendRawVoicePacket(
|
await connectionProvider.sendRawVoicePacket(
|
||||||
contactPath: target.outPath,
|
contactPath: target.outPath,
|
||||||
contactPathLen: target.routeSignedPathLen,
|
contactPathLen: target.routeEncodedPathLen,
|
||||||
payload: RawRouteProbeRequest(
|
payload: RawRouteProbeRequest(
|
||||||
nonce: nonce,
|
nonce: nonce,
|
||||||
requesterKey6: requesterKey6,
|
requesterKey6: requesterKey6,
|
||||||
@@ -2470,7 +2465,7 @@ class AppProvider with ChangeNotifier {
|
|||||||
if (target.publicKeyHex.isNotEmpty) {
|
if (target.publicKeyHex.isNotEmpty) {
|
||||||
return 'pk:${target.publicKeyHex}';
|
return 'pk:${target.publicKeyHex}';
|
||||||
}
|
}
|
||||||
return 'name:${target.advName}:${target.routeSignedPathLen}:${target.outPath.map((b) => b.toRadixString(16).padLeft(2, '0')).join()}';
|
return 'name:${target.advName}:${target.routeEncodedPathLen}:${target.outPath.map((b) => b.toRadixString(16).padLeft(2, '0')).join()}';
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handleRawRouteProbeRequest(RawRouteProbeRequest request) {
|
void _handleRawRouteProbeRequest(RawRouteProbeRequest request) {
|
||||||
@@ -2488,9 +2483,6 @@ class AppProvider with ChangeNotifier {
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!requester.routeSupportsLegacyRawTransport) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (requester.outPath.isEmpty) {
|
if (requester.outPath.isEmpty) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -2500,7 +2492,7 @@ class AppProvider with ChangeNotifier {
|
|||||||
unawaited(
|
unawaited(
|
||||||
connectionProvider.sendRawVoicePacket(
|
connectionProvider.sendRawVoicePacket(
|
||||||
contactPath: requester.outPath,
|
contactPath: requester.outPath,
|
||||||
contactPathLen: requester.routeSignedPathLen,
|
contactPathLen: requester.routeEncodedPathLen,
|
||||||
payload: RawRouteProbeAck(nonce: request.nonce).encodeBinary(),
|
payload: RawRouteProbeAck(nonce: request.nonce).encodeBinary(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -38,12 +38,6 @@ Future<bool> serveCachedSessionFragments<T>({
|
|||||||
);
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!requester.routeSupportsLegacyRawTransport) {
|
|
||||||
debugPrint(
|
|
||||||
'⚠️ [$providerLabel] ${requester.advName} route uses unsupported 3-byte raw transport on current client',
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (requester.outPath.isEmpty) {
|
if (requester.outPath.isEmpty) {
|
||||||
debugPrint(
|
debugPrint(
|
||||||
'⚠️ [$providerLabel] ${requester.advName} has empty outPath payload',
|
'⚠️ [$providerLabel] ${requester.advName} has empty outPath payload',
|
||||||
@@ -64,7 +58,7 @@ Future<bool> serveCachedSessionFragments<T>({
|
|||||||
try {
|
try {
|
||||||
await sendRawPacket(
|
await sendRawPacket(
|
||||||
contactPath: requester.outPath,
|
contactPath: requester.outPath,
|
||||||
contactPathLen: requester.routeSignedPathLen,
|
contactPathLen: requester.routeEncodedPathLen,
|
||||||
payload: encodeBinary(fragment),
|
payload: encodeBinary(fragment),
|
||||||
);
|
);
|
||||||
servedCount++;
|
servedCount++;
|
||||||
|
|||||||
@@ -7,7 +7,10 @@ import '../models/contact.dart';
|
|||||||
import '../providers/contacts_provider.dart';
|
import '../providers/contacts_provider.dart';
|
||||||
import '../providers/app_provider.dart';
|
import '../providers/app_provider.dart';
|
||||||
import '../providers/connection_provider.dart';
|
import '../providers/connection_provider.dart';
|
||||||
|
import '../providers/messages_provider.dart';
|
||||||
import '../utils/contact_grouping.dart';
|
import '../utils/contact_grouping.dart';
|
||||||
|
import '../utils/avatar_label_helper.dart';
|
||||||
|
import '../widgets/common/contact_avatar.dart';
|
||||||
import '../widgets/contacts/contact_tile.dart';
|
import '../widgets/contacts/contact_tile.dart';
|
||||||
import '../widgets/contacts/add_channel_dialog.dart';
|
import '../widgets/contacts/add_channel_dialog.dart';
|
||||||
|
|
||||||
@@ -28,7 +31,11 @@ class ContactsTab extends StatefulWidget {
|
|||||||
class _ContactsTabState extends State<ContactsTab> {
|
class _ContactsTabState extends State<ContactsTab> {
|
||||||
Position? _currentPosition;
|
Position? _currentPosition;
|
||||||
final Set<String> _resolvingAdvertKeys = <String>{};
|
final Set<String> _resolvingAdvertKeys = <String>{};
|
||||||
ContactSortMode _sortMode = ContactSortMode.lastSeen;
|
final Map<ContactSection, ContactSortMode> _sortModes = {
|
||||||
|
ContactSection.teamMembers: ContactSortMode.lastSeen,
|
||||||
|
ContactSection.repeaters: ContactSortMode.lastSeen,
|
||||||
|
ContactSection.rooms: ContactSortMode.lastSeen,
|
||||||
|
};
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -127,11 +134,20 @@ class _ContactsTabState extends State<ContactsTab> {
|
|||||||
return l10n.daysAgo(diff.inDays);
|
return l10n.daysAgo(diff.inDays);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Contact> _sortContacts(List<Contact> contacts) {
|
List<Contact> _sortContacts(List<Contact> contacts, ContactSection section) {
|
||||||
final sorted = List<Contact>.from(contacts);
|
final sorted = List<Contact>.from(contacts);
|
||||||
|
if (section == ContactSection.channels) {
|
||||||
|
sorted.sort(
|
||||||
|
(a, b) =>
|
||||||
|
a.displayName.toLowerCase().compareTo(b.displayName.toLowerCase()),
|
||||||
|
);
|
||||||
|
return sorted;
|
||||||
|
}
|
||||||
|
|
||||||
|
final sortMode = _sortModes[section] ?? ContactSortMode.lastSeen;
|
||||||
|
|
||||||
sorted.sort((a, b) {
|
sorted.sort((a, b) {
|
||||||
if (_sortMode == ContactSortMode.distance) {
|
if (sortMode == ContactSortMode.distance) {
|
||||||
final distanceA = _distanceFromCurrentPosition(a);
|
final distanceA = _distanceFromCurrentPosition(a);
|
||||||
final distanceB = _distanceFromCurrentPosition(b);
|
final distanceB = _distanceFromCurrentPosition(b);
|
||||||
|
|
||||||
@@ -212,10 +228,23 @@ class _ContactsTabState extends State<ContactsTab> {
|
|||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: Consumer<ContactsProvider>(
|
body: Consumer<ContactsProvider>(
|
||||||
builder: (context, contactsProvider, child) {
|
builder: (context, contactsProvider, child) {
|
||||||
final chatContacts = _sortContacts(contactsProvider.chatContacts);
|
final messagesProvider = context.watch<MessagesProvider>();
|
||||||
final repeaters = _sortContacts(contactsProvider.repeaters);
|
final chatContacts = _sortContacts(
|
||||||
final rooms = _sortContacts(contactsProvider.rooms);
|
contactsProvider.chatContacts,
|
||||||
final channels = _sortContacts(contactsProvider.channels);
|
ContactSection.teamMembers,
|
||||||
|
);
|
||||||
|
final repeaters = _sortContacts(
|
||||||
|
contactsProvider.repeaters,
|
||||||
|
ContactSection.repeaters,
|
||||||
|
);
|
||||||
|
final rooms = _sortContacts(
|
||||||
|
contactsProvider.rooms,
|
||||||
|
ContactSection.rooms,
|
||||||
|
);
|
||||||
|
final channels = _sortContacts(
|
||||||
|
contactsProvider.channels,
|
||||||
|
ContactSection.channels,
|
||||||
|
);
|
||||||
final pendingAdverts = contactsProvider.pendingAdverts;
|
final pendingAdverts = contactsProvider.pendingAdverts;
|
||||||
|
|
||||||
// Check if there are any displayable contacts
|
// Check if there are any displayable contacts
|
||||||
@@ -257,17 +286,6 @@ class _ContactsTabState extends State<ContactsTab> {
|
|||||||
child: ListView(
|
child: ListView(
|
||||||
padding: const EdgeInsets.all(8),
|
padding: const EdgeInsets.all(8),
|
||||||
children: [
|
children: [
|
||||||
_SortModeSwitcher(
|
|
||||||
sortMode: _sortMode,
|
|
||||||
lastSeenLabel: l10n.lastSeen,
|
|
||||||
distanceLabel: l10n.distance,
|
|
||||||
onChanged: (sortMode) {
|
|
||||||
setState(() {
|
|
||||||
_sortMode = sortMode;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
|
|
||||||
// Pending adverts (public key only; quick resolve)
|
// Pending adverts (public key only; quick resolve)
|
||||||
if (pendingAdverts.isNotEmpty) ...[
|
if (pendingAdverts.isNotEmpty) ...[
|
||||||
_SectionHeader(
|
_SectionHeader(
|
||||||
@@ -295,6 +313,10 @@ class _ContactsTabState extends State<ContactsTab> {
|
|||||||
title: l10n.teamMembers,
|
title: l10n.teamMembers,
|
||||||
count: chatContacts.length,
|
count: chatContacts.length,
|
||||||
icon: Icons.people,
|
icon: Icons.people,
|
||||||
|
trailing: _buildSortMenu(
|
||||||
|
context,
|
||||||
|
ContactSection.teamMembers,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
..._buildContactSectionItems(chatContacts),
|
..._buildContactSectionItems(chatContacts),
|
||||||
const Divider(height: 32),
|
const Divider(height: 32),
|
||||||
@@ -306,6 +328,7 @@ class _ContactsTabState extends State<ContactsTab> {
|
|||||||
title: l10n.repeaters,
|
title: l10n.repeaters,
|
||||||
count: repeaters.length,
|
count: repeaters.length,
|
||||||
icon: Icons.router,
|
icon: Icons.router,
|
||||||
|
trailing: _buildSortMenu(context, ContactSection.repeaters),
|
||||||
),
|
),
|
||||||
..._buildContactSectionItems(repeaters),
|
..._buildContactSectionItems(repeaters),
|
||||||
const Divider(height: 32),
|
const Divider(height: 32),
|
||||||
@@ -317,6 +340,7 @@ class _ContactsTabState extends State<ContactsTab> {
|
|||||||
title: l10n.rooms,
|
title: l10n.rooms,
|
||||||
count: rooms.length,
|
count: rooms.length,
|
||||||
icon: Icons.tag,
|
icon: Icons.tag,
|
||||||
|
trailing: _buildSortMenu(context, ContactSection.rooms),
|
||||||
),
|
),
|
||||||
..._buildContactSectionItems(rooms),
|
..._buildContactSectionItems(rooms),
|
||||||
const Divider(height: 32),
|
const Divider(height: 32),
|
||||||
@@ -329,7 +353,14 @@ class _ContactsTabState extends State<ContactsTab> {
|
|||||||
icon: Icons.broadcast_on_personal,
|
icon: Icons.broadcast_on_personal,
|
||||||
),
|
),
|
||||||
if (channels.isNotEmpty) ...[
|
if (channels.isNotEmpty) ...[
|
||||||
..._buildContactSectionItems(channels),
|
...channels.map(
|
||||||
|
(channel) => _ChannelActivityCard(
|
||||||
|
channel: channel,
|
||||||
|
messagesProvider: messagesProvider,
|
||||||
|
contactsProvider: contactsProvider,
|
||||||
|
onNavigateToMessages: widget.onNavigateToMessages,
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
|
|
||||||
// Add Channel Button (visible in both simple and advanced mode, only show when connected)
|
// Add Channel Button (visible in both simple and advanced mode, only show when connected)
|
||||||
@@ -385,10 +416,70 @@ class _ContactsTabState extends State<ContactsTab> {
|
|||||||
);
|
);
|
||||||
}).toList();
|
}).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _buildSortMenu(BuildContext context, ContactSection section) {
|
||||||
|
final l10n = AppLocalizations.of(context)!;
|
||||||
|
final selectedMode = _sortModes[section] ?? ContactSortMode.lastSeen;
|
||||||
|
final colorScheme = Theme.of(context).colorScheme;
|
||||||
|
|
||||||
|
return PopupMenuButton<ContactSortMode>(
|
||||||
|
tooltip: 'Sort',
|
||||||
|
initialValue: selectedMode,
|
||||||
|
onSelected: (sortMode) {
|
||||||
|
setState(() {
|
||||||
|
_sortModes[section] = sortMode;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
itemBuilder: (context) => [
|
||||||
|
PopupMenuItem<ContactSortMode>(
|
||||||
|
value: ContactSortMode.lastSeen,
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Icon(
|
||||||
|
Icons.schedule,
|
||||||
|
size: 18,
|
||||||
|
color: selectedMode == ContactSortMode.lastSeen
|
||||||
|
? colorScheme.primary
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Text(l10n.lastSeen),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
PopupMenuItem<ContactSortMode>(
|
||||||
|
value: ContactSortMode.distance,
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Icon(
|
||||||
|
Icons.near_me,
|
||||||
|
size: 18,
|
||||||
|
color: selectedMode == ContactSortMode.distance
|
||||||
|
? colorScheme.primary
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Text(l10n.distance),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(4),
|
||||||
|
child: Icon(
|
||||||
|
Icons.more_horiz,
|
||||||
|
size: 18,
|
||||||
|
color: colorScheme.onSurfaceVariant,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ContactSortMode { lastSeen, distance }
|
enum ContactSortMode { lastSeen, distance }
|
||||||
|
|
||||||
|
enum ContactSection { teamMembers, repeaters, rooms, channels }
|
||||||
|
|
||||||
class _PendingAdvertTile extends StatelessWidget {
|
class _PendingAdvertTile extends StatelessWidget {
|
||||||
final PendingAdvert advert;
|
final PendingAdvert advert;
|
||||||
final String subtitle;
|
final String subtitle;
|
||||||
@@ -433,11 +524,13 @@ class _SectionHeader extends StatelessWidget {
|
|||||||
final String title;
|
final String title;
|
||||||
final int count;
|
final int count;
|
||||||
final IconData icon;
|
final IconData icon;
|
||||||
|
final Widget? trailing;
|
||||||
|
|
||||||
const _SectionHeader({
|
const _SectionHeader({
|
||||||
required this.title,
|
required this.title,
|
||||||
required this.count,
|
required this.count,
|
||||||
required this.icon,
|
required this.icon,
|
||||||
|
this.trailing,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -466,6 +559,7 @@ class _SectionHeader extends StatelessWidget {
|
|||||||
style: Theme.of(context).textTheme.labelSmall,
|
style: Theme.of(context).textTheme.labelSmall,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
if (trailing != null) ...[const Spacer(), trailing!],
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -504,31 +598,30 @@ class _InferredContactGroupCard extends StatelessWidget {
|
|||||||
color: colorScheme.outlineVariant.withValues(alpha: 0.35),
|
color: colorScheme.outlineVariant.withValues(alpha: 0.35),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: Padding(
|
child: Theme(
|
||||||
padding: const EdgeInsets.fromLTRB(12, 12, 12, 8),
|
data: Theme.of(context).copyWith(dividerColor: Colors.transparent),
|
||||||
child: Column(
|
child: ExpansionTile(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
tilePadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 2),
|
||||||
children: [
|
childrenPadding: const EdgeInsets.fromLTRB(12, 0, 12, 8),
|
||||||
Row(
|
initiallyExpanded: true,
|
||||||
children: [
|
leading: Icon(
|
||||||
Icon(
|
|
||||||
Icons.folder_copy_outlined,
|
Icons.folder_copy_outlined,
|
||||||
size: 18,
|
size: 18,
|
||||||
color: colorScheme.primary,
|
color: colorScheme.primary,
|
||||||
),
|
),
|
||||||
const SizedBox(width: 8),
|
title: Row(
|
||||||
Text(
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
label,
|
label,
|
||||||
style: Theme.of(
|
style: Theme.of(
|
||||||
context,
|
context,
|
||||||
).textTheme.titleSmall?.copyWith(fontWeight: FontWeight.w800),
|
).textTheme.titleSmall?.copyWith(fontWeight: FontWeight.w800),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
Container(
|
Container(
|
||||||
padding: const EdgeInsets.symmetric(
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
|
||||||
horizontal: 8,
|
|
||||||
vertical: 2,
|
|
||||||
),
|
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: colorScheme.primaryContainer,
|
color: colorScheme.primaryContainer,
|
||||||
borderRadius: BorderRadius.circular(999),
|
borderRadius: BorderRadius.circular(999),
|
||||||
@@ -540,7 +633,7 @@ class _InferredContactGroupCard extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: 10),
|
children: [
|
||||||
...contacts.map(
|
...contacts.map(
|
||||||
(contact) => ContactTile(
|
(contact) => ContactTile(
|
||||||
contact: contact,
|
contact: contact,
|
||||||
@@ -558,48 +651,268 @@ class _InferredContactGroupCard extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _SortModeSwitcher extends StatelessWidget {
|
class _ChannelActivityCard extends StatelessWidget {
|
||||||
final ContactSortMode sortMode;
|
final Contact channel;
|
||||||
final String lastSeenLabel;
|
final MessagesProvider messagesProvider;
|
||||||
final String distanceLabel;
|
final ContactsProvider contactsProvider;
|
||||||
final ValueChanged<ContactSortMode> onChanged;
|
final VoidCallback? onNavigateToMessages;
|
||||||
|
|
||||||
const _SortModeSwitcher({
|
const _ChannelActivityCard({
|
||||||
required this.sortMode,
|
required this.channel,
|
||||||
required this.lastSeenLabel,
|
required this.messagesProvider,
|
||||||
required this.distanceLabel,
|
required this.contactsProvider,
|
||||||
required this.onChanged,
|
required this.onNavigateToMessages,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Padding(
|
final colorScheme = Theme.of(context).colorScheme;
|
||||||
padding: const EdgeInsets.only(bottom: 12),
|
final channelIdx = channel.publicKey.length > 1 ? channel.publicKey[1] : 0;
|
||||||
child: Align(
|
final channelMessages = messagesProvider.getMessagesForChannel(channelIdx)
|
||||||
alignment: Alignment.centerLeft,
|
..sort((a, b) => b.sentAt.compareTo(a.sentAt));
|
||||||
child: SegmentedButton<ContactSortMode>(
|
final participantNames = <String>[];
|
||||||
segments: [
|
for (final message in channelMessages) {
|
||||||
ButtonSegment<ContactSortMode>(
|
final senderName = message.senderName?.trim();
|
||||||
value: ContactSortMode.lastSeen,
|
if (senderName == null || senderName.isEmpty) continue;
|
||||||
label: Text(lastSeenLabel),
|
if (!participantNames.contains(senderName)) {
|
||||||
icon: const Icon(Icons.schedule),
|
participantNames.add(senderName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Container(
|
||||||
|
margin: const EdgeInsets.only(bottom: 10),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
borderRadius: BorderRadius.circular(18),
|
||||||
|
gradient: LinearGradient(
|
||||||
|
begin: Alignment.topLeft,
|
||||||
|
end: Alignment.bottomRight,
|
||||||
|
colors: [
|
||||||
|
colorScheme.surfaceContainerLow,
|
||||||
|
colorScheme.tertiaryContainer.withValues(alpha: 0.45),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
ButtonSegment<ContactSortMode>(
|
border: Border.all(
|
||||||
value: ContactSortMode.distance,
|
color: colorScheme.outlineVariant.withValues(alpha: 0.35),
|
||||||
label: Text(distanceLabel),
|
),
|
||||||
icon: const Icon(Icons.near_me),
|
),
|
||||||
|
child: Material(
|
||||||
|
color: Colors.transparent,
|
||||||
|
child: InkWell(
|
||||||
|
borderRadius: BorderRadius.circular(18),
|
||||||
|
onTap: () async {
|
||||||
|
messagesProvider.navigateToDestination(
|
||||||
|
'channel',
|
||||||
|
recipientPublicKeyHex: channel.publicKeyHex,
|
||||||
|
);
|
||||||
|
onNavigateToMessages?.call();
|
||||||
|
},
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(14),
|
||||||
|
child: Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
ContactAvatar(contact: channel, radius: 24),
|
||||||
|
const SizedBox(width: 12),
|
||||||
|
Expanded(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
channel.displayName,
|
||||||
|
maxLines: 1,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
style: Theme.of(context).textTheme.titleMedium
|
||||||
|
?.copyWith(fontWeight: FontWeight.w800),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
if (participantNames.isNotEmpty)
|
||||||
|
_ExpandableParticipantStack(
|
||||||
|
names: participantNames,
|
||||||
|
contactForName: _findParticipantContact,
|
||||||
|
)
|
||||||
|
else
|
||||||
|
Text(
|
||||||
|
'No recent chatters',
|
||||||
|
style: Theme.of(context).textTheme.bodySmall
|
||||||
|
?.copyWith(color: colorScheme.onSurfaceVariant),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
Wrap(
|
||||||
|
spacing: 8,
|
||||||
|
runSpacing: 8,
|
||||||
|
children: [
|
||||||
|
_MetricChip(
|
||||||
|
icon: Icons.forum_outlined,
|
||||||
|
label: '${channelMessages.length}',
|
||||||
|
helper: 'messages',
|
||||||
|
),
|
||||||
|
_MetricChip(
|
||||||
|
icon: Icons.group_outlined,
|
||||||
|
label: '${participantNames.length}',
|
||||||
|
helper: 'active',
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
selected: {sortMode},
|
),
|
||||||
onSelectionChanged: (selection) {
|
],
|
||||||
final selected = selection.isEmpty ? null : selection.first;
|
),
|
||||||
if (selected != null) {
|
),
|
||||||
onChanged(selected);
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
},
|
|
||||||
showSelectedIcon: false,
|
Contact? _findParticipantContact(String name) {
|
||||||
|
for (final contact in contactsProvider.contacts) {
|
||||||
|
if (!contact.isChannel && contact.advName == name) {
|
||||||
|
return contact;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ExpandableParticipantStack extends StatefulWidget {
|
||||||
|
final List<String> names;
|
||||||
|
final Contact? Function(String name) contactForName;
|
||||||
|
|
||||||
|
const _ExpandableParticipantStack({
|
||||||
|
required this.names,
|
||||||
|
required this.contactForName,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<_ExpandableParticipantStack> createState() =>
|
||||||
|
_ExpandableParticipantStackState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ExpandableParticipantStackState
|
||||||
|
extends State<_ExpandableParticipantStack> {
|
||||||
|
bool _expanded = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final visibleNames = _expanded
|
||||||
|
? widget.names
|
||||||
|
: widget.names.take(4).toList();
|
||||||
|
final spacing = _expanded ? 24.0 : 18.0;
|
||||||
|
const avatarSize = 28.0;
|
||||||
|
final width = avatarSize + (visibleNames.length - 1) * spacing;
|
||||||
|
|
||||||
|
return GestureDetector(
|
||||||
|
onTap: widget.names.length > 4
|
||||||
|
? () {
|
||||||
|
setState(() {
|
||||||
|
_expanded = !_expanded;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
child: AnimatedContainer(
|
||||||
|
duration: const Duration(milliseconds: 180),
|
||||||
|
curve: Curves.easeOut,
|
||||||
|
width: width,
|
||||||
|
height: avatarSize,
|
||||||
|
child: Stack(
|
||||||
|
clipBehavior: Clip.none,
|
||||||
|
children: [
|
||||||
|
for (var i = 0; i < visibleNames.length; i++)
|
||||||
|
Positioned(
|
||||||
|
left: i * spacing,
|
||||||
|
child: _ParticipantAvatar(
|
||||||
|
name: visibleNames[i],
|
||||||
|
contact: widget.contactForName(visibleNames[i]),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _ParticipantAvatar extends StatelessWidget {
|
||||||
|
final String name;
|
||||||
|
final Contact? contact;
|
||||||
|
|
||||||
|
const _ParticipantAvatar({required this.name, required this.contact});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
if (contact != null) {
|
||||||
|
return Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
border: Border.all(
|
||||||
|
color: Theme.of(context).colorScheme.surface,
|
||||||
|
width: 2,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: ContactAvatar(contact: contact!, radius: 14),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
final colorScheme = Theme.of(context).colorScheme;
|
||||||
|
return Container(
|
||||||
|
width: 28,
|
||||||
|
height: 28,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: colorScheme.tertiaryContainer,
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
border: Border.all(color: colorScheme.surface, width: 2),
|
||||||
|
),
|
||||||
|
alignment: Alignment.center,
|
||||||
|
child: Text(
|
||||||
|
AvatarLabelHelper.buildLabel(name),
|
||||||
|
style: Theme.of(context).textTheme.labelSmall?.copyWith(
|
||||||
|
fontWeight: FontWeight.w700,
|
||||||
|
color: colorScheme.onTertiaryContainer,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _MetricChip extends StatelessWidget {
|
||||||
|
final IconData icon;
|
||||||
|
final String label;
|
||||||
|
final String helper;
|
||||||
|
|
||||||
|
const _MetricChip({
|
||||||
|
required this.icon,
|
||||||
|
required this.label,
|
||||||
|
required this.helper,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final colorScheme = Theme.of(context).colorScheme;
|
||||||
|
return Container(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 5),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: colorScheme.surface.withValues(alpha: 0.72),
|
||||||
|
borderRadius: BorderRadius.circular(999),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Icon(icon, size: 14, color: colorScheme.onSurfaceVariant),
|
||||||
|
const SizedBox(width: 5),
|
||||||
|
Text(
|
||||||
|
label,
|
||||||
|
style: Theme.of(
|
||||||
|
context,
|
||||||
|
).textTheme.labelMedium?.copyWith(fontWeight: FontWeight.w700),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 4),
|
||||||
|
Text(
|
||||||
|
helper,
|
||||||
|
style: Theme.of(context).textTheme.labelSmall?.copyWith(
|
||||||
|
color: colorScheme.onSurfaceVariant,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -403,15 +403,6 @@ class _ImageMessageBubbleState extends State<ImageMessageBubble> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sender.routeSupportsLegacyRawTransport) {
|
|
||||||
_clearRequestState();
|
|
||||||
await _showBlockingAlert(
|
|
||||||
'Cannot fetch image',
|
|
||||||
'Sender route uses 3-byte hashes. Raw media fetch is not supported in this client yet.',
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sender.routeHopCount >= 2) {
|
if (sender.routeHopCount >= 2) {
|
||||||
_showToast(
|
_showToast(
|
||||||
'Image fetch over ${sender.routeHopCount} hops may take a while.',
|
'Image fetch over ${sender.routeHopCount} hops may take a while.',
|
||||||
@@ -462,7 +453,7 @@ class _ImageMessageBubbleState extends State<ImageMessageBubble> {
|
|||||||
);
|
);
|
||||||
await conn.sendRawVoicePacket(
|
await conn.sendRawVoicePacket(
|
||||||
contactPath: sender.outPath,
|
contactPath: sender.outPath,
|
||||||
contactPathLen: sender.routeSignedPathLen,
|
contactPathLen: sender.routeEncodedPathLen,
|
||||||
payload: payload,
|
payload: payload,
|
||||||
);
|
);
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
|
|||||||
@@ -366,15 +366,6 @@ class _VoiceMessageBubbleState extends State<VoiceMessageBubble> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sender.routeSupportsLegacyRawTransport) {
|
|
||||||
_clearRequestState();
|
|
||||||
await _showBlockingAlert(
|
|
||||||
'Cannot fetch voice',
|
|
||||||
'Sender route uses 3-byte hashes. Raw media fetch is not supported in this client yet.',
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sender.routeHopCount >= 2) {
|
if (sender.routeHopCount >= 2) {
|
||||||
_showToast(
|
_showToast(
|
||||||
'Voice fetch over ${sender.routeHopCount} hops may take a while.',
|
'Voice fetch over ${sender.routeHopCount} hops may take a while.',
|
||||||
@@ -415,10 +406,7 @@ class _VoiceMessageBubbleState extends State<VoiceMessageBubble> {
|
|||||||
missingIndices: missing,
|
missingIndices: missing,
|
||||||
requesterKey6: requesterKey6,
|
requesterKey6: requesterKey6,
|
||||||
)
|
)
|
||||||
: VoiceFetchRequest(
|
: VoiceFetchRequest(sessionId: sessionId, requesterKey6: requesterKey6);
|
||||||
sessionId: sessionId,
|
|
||||||
requesterKey6: requesterKey6,
|
|
||||||
);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
debugPrint(
|
debugPrint(
|
||||||
@@ -426,7 +414,7 @@ class _VoiceMessageBubbleState extends State<VoiceMessageBubble> {
|
|||||||
);
|
);
|
||||||
await connectionProvider.sendRawVoicePacket(
|
await connectionProvider.sendRawVoicePacket(
|
||||||
contactPath: sender.outPath,
|
contactPath: sender.outPath,
|
||||||
contactPathLen: sender.routeSignedPathLen,
|
contactPathLen: sender.routeEncodedPathLen,
|
||||||
payload: request.encodeBinary(),
|
payload: request.encodeBinary(),
|
||||||
);
|
);
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
|
|||||||
@@ -796,7 +796,7 @@ packages:
|
|||||||
description:
|
description:
|
||||||
path: "."
|
path: "."
|
||||||
ref: main
|
ref: main
|
||||||
resolved-ref: "84b133069cbf9ce8e261ed13ac3051388f355878"
|
resolved-ref: bd3744ee21376b81be5f852cd0c1a82c0df40460
|
||||||
url: "https://github.com/dz0ny/meshcore_client.git"
|
url: "https://github.com/dz0ny/meshcore_client.git"
|
||||||
source: git
|
source: git
|
||||||
version: "0.1.0"
|
version: "0.1.0"
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ void main() {
|
|||||||
expect(contact.routeHashSize, 3);
|
expect(contact.routeHashSize, 3);
|
||||||
expect(contact.routeHopCount, 2);
|
expect(contact.routeHopCount, 2);
|
||||||
expect(contact.routeCanonicalText, 'AABBCC,DDEEFF');
|
expect(contact.routeCanonicalText, 'AABBCC,DDEEFF');
|
||||||
expect(contact.routeSupportsLegacyRawTransport, isFalse);
|
expect(contact.routeSupportsLegacyRawTransport, isTrue);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('treats -1 as unknown route', () {
|
test('treats -1 as unknown route', () {
|
||||||
|
|||||||
@@ -47,6 +47,63 @@ void main() {
|
|||||||
expect(ok, isFalse);
|
expect(ok, isFalse);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('returns false when requester has no learned path', () async {
|
||||||
|
final ok = await serveCachedSessionFragments<_Fragment>(
|
||||||
|
providerLabel: 'TestProvider',
|
||||||
|
sessionId: 'deadbeef',
|
||||||
|
requester: _buildContact(outPathLen: -1),
|
||||||
|
fragments: [
|
||||||
|
_Fragment(0, Uint8List.fromList([1])),
|
||||||
|
],
|
||||||
|
maxDirectPayloadHops: 3,
|
||||||
|
indexOf: (f) => f.index,
|
||||||
|
encodeBinary: (f) => f.payload,
|
||||||
|
sendRawPacket:
|
||||||
|
({
|
||||||
|
required contactPath,
|
||||||
|
required contactPathLen,
|
||||||
|
required payload,
|
||||||
|
}) async {},
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(ok, isFalse);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('returns false when requester path payload is empty', () async {
|
||||||
|
final requester = Contact(
|
||||||
|
publicKey: Uint8List.fromList(List<int>.generate(32, (i) => i)),
|
||||||
|
type: ContactType.chat,
|
||||||
|
flags: 0,
|
||||||
|
outPathLen: 1,
|
||||||
|
outPath: Uint8List(0),
|
||||||
|
advName: 'Requester',
|
||||||
|
lastAdvert: DateTime.now().millisecondsSinceEpoch ~/ 1000,
|
||||||
|
advLat: 0,
|
||||||
|
advLon: 0,
|
||||||
|
lastMod: DateTime.now().millisecondsSinceEpoch ~/ 1000,
|
||||||
|
);
|
||||||
|
|
||||||
|
final ok = await serveCachedSessionFragments<_Fragment>(
|
||||||
|
providerLabel: 'TestProvider',
|
||||||
|
sessionId: 'deadbeef',
|
||||||
|
requester: requester,
|
||||||
|
fragments: [
|
||||||
|
_Fragment(0, Uint8List.fromList([1])),
|
||||||
|
],
|
||||||
|
maxDirectPayloadHops: 3,
|
||||||
|
indexOf: (f) => f.index,
|
||||||
|
encodeBinary: (f) => f.payload,
|
||||||
|
sendRawPacket:
|
||||||
|
({
|
||||||
|
required contactPath,
|
||||||
|
required contactPathLen,
|
||||||
|
required payload,
|
||||||
|
}) async {},
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(ok, isFalse);
|
||||||
|
});
|
||||||
|
|
||||||
test('sends only requested indices', () async {
|
test('sends only requested indices', () async {
|
||||||
final sent = <Uint8List>[];
|
final sent = <Uint8List>[];
|
||||||
final ok = await serveCachedSessionFragments<_Fragment>(
|
final ok = await serveCachedSessionFragments<_Fragment>(
|
||||||
|
|||||||
Reference in New Issue
Block a user