2026-09-26 22:45:38 +03:00
|
|
|
import "package:auto_route/auto_route.dart";
|
|
|
|
|
import "package:flutter/material.dart";
|
|
|
|
|
import "package:flutter_riverpod/flutter_riverpod.dart";
|
|
|
|
|
|
|
|
|
|
import "package:smol_mail/data/providers/providers.dart";
|
|
|
|
|
import "package:smol_mail/presentation/routes/app_router.gr.dart";
|
|
|
|
|
import "package:smol_mail/presentation/theme/app_colors.dart";
|
2026-09-28 23:49:39 +03:00
|
|
|
import "package:smol_mail/smol/ui.dart";
|
2026-09-26 22:45:38 +03:00
|
|
|
|
|
|
|
|
/// Contacts: the addresses bound to keys, with the trust badge and the number
|
|
|
|
|
/// of keys each has replaced — the §8 surface for noticing rotations.
|
|
|
|
|
@RoutePage()
|
|
|
|
|
class ContactsScreen extends ConsumerWidget {
|
|
|
|
|
const ContactsScreen({super.key});
|
|
|
|
|
|
2026-09-30 17:14:47 +03:00
|
|
|
void _import(BuildContext context) =>
|
|
|
|
|
AutoRouter.of(context).push(ImportContactDialogRoute());
|
2026-09-26 22:45:38 +03:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
|
final contacts = ref.watch(contactsProvider);
|
|
|
|
|
|
|
|
|
|
return Scaffold(
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
title: const Text("Contacts"),
|
|
|
|
|
actions: [
|
|
|
|
|
IconButton(
|
|
|
|
|
tooltip: "Import smol:// address",
|
2026-09-30 17:14:47 +03:00
|
|
|
onPressed: () => _import(context),
|
2026-09-26 22:45:38 +03:00
|
|
|
icon: const Icon(Icons.person_add),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
body: contacts.isEmpty
|
|
|
|
|
? Center(
|
|
|
|
|
child: Text(
|
|
|
|
|
"no contacts yet — import a smol:// address, or write to someone",
|
|
|
|
|
style: Theme.of(context).textTheme.labelSmall,
|
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
: ListView.builder(
|
|
|
|
|
itemCount: contacts.length,
|
|
|
|
|
itemBuilder: (ctx, i) {
|
|
|
|
|
final (address, contact) = contacts[i];
|
2026-09-27 11:07:11 +03:00
|
|
|
final accepted = ref.read(storeProvider).accepted(address);
|
2026-09-26 22:45:38 +03:00
|
|
|
return ListTile(
|
|
|
|
|
splashColor: Theme.of(context).extension<AppColors>()!.highlight,
|
|
|
|
|
onTap: () => AutoRouter.of(context)
|
|
|
|
|
.push(ContactDetailRoute(address: address)),
|
|
|
|
|
title: Text(address),
|
|
|
|
|
subtitle: Text(
|
|
|
|
|
fingerprint(contact.key),
|
|
|
|
|
style: Theme.of(context).textTheme.labelSmall,
|
|
|
|
|
),
|
|
|
|
|
trailing: Wrap(
|
|
|
|
|
spacing: 6,
|
2026-09-27 11:07:11 +03:00
|
|
|
crossAxisAlignment: WrapCrossAlignment.center,
|
2026-09-26 22:45:38 +03:00
|
|
|
children: [
|
|
|
|
|
_chip(context, contact.verified ? "verified" : "tofu",
|
|
|
|
|
ok: contact.verified),
|
|
|
|
|
if (contact.history.isNotEmpty)
|
|
|
|
|
_chip(context, "${contact.history.length} previous",
|
|
|
|
|
ok: false),
|
2026-09-27 11:07:11 +03:00
|
|
|
if (accepted != null && accepted.active)
|
|
|
|
|
_chip(context, "accepted", ok: true),
|
2026-09-26 22:45:38 +03:00
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget _chip(BuildContext context, String text, {required bool ok}) =>
|
|
|
|
|
Container(
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
border: Border.all(
|
|
|
|
|
color: ok
|
|
|
|
|
? Theme.of(context).primaryColor
|
|
|
|
|
: Theme.of(context).textTheme.labelSmall!.color!,
|
|
|
|
|
),
|
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
|
),
|
|
|
|
|
child: Text(
|
|
|
|
|
text,
|
|
|
|
|
style: Theme.of(context).textTheme.labelSmall!.copyWith(
|
|
|
|
|
color: ok
|
|
|
|
|
? Theme.of(context).primaryColor
|
|
|
|
|
: Theme.of(context).textTheme.labelSmall!.color,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|