Files
Docwell/Phone-App/lib/screens/notifications_screen.dart
T
tajniak81andClaude Opus 5.5 84043ba05b Add date mentions with reminders
- "@today", "@friday", "@2026-12-01" insert a date; "@remind friday"
  or the date's popover adds a reminder for the person who set it.
- docwell-server keeps a reminders row per person, date and time zone
  in step with each page and sends a "reminder" notification at 9:00
  on the day in that time zone (job notify.reminders). Dates already
  past when added do not notify.
- Exports write dates out; the web and phone inboxes show reminders.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 14:55:46 +01:00

133 lines
3.9 KiB
Dart

// SPDX-License-Identifier: AGPL-3.0-or-later
import 'package:flutter/material.dart' hide Notification, Page;
import '../api/docwell_api.dart';
import '../app.dart';
import 'page_screen.dart';
import 'widgets.dart';
String notificationText(Notification n) {
final who = n.actor == null
? 'Someone'
: (n.actor!.name.isEmpty ? n.actor!.email : n.actor!.name);
return switch (n.type) {
NotificationType.comment => '$who commented',
NotificationType.reply => '$who replied',
NotificationType.mention => '$who mentioned you',
NotificationType.share => '$who shared a page with you',
NotificationType.resolved => '$who resolved a thread',
NotificationType.reminder => 'Reminder',
};
}
/// The inbox: mentions, replies, comments, shares and reminders, newest first.
class NotificationsScreen extends StatefulWidget {
const NotificationsScreen({super.key, required this.session});
final AppSession session;
@override
State<NotificationsScreen> createState() => _NotificationsScreenState();
}
class _NotificationsScreenState extends State<NotificationsScreen> {
DocwellApi get _api => widget.session.api;
NotificationList? _list;
String? _error;
@override
void initState() {
super.initState();
_load();
}
Future<void> _load() async {
try {
final list = await _api.notifications();
if (mounted) {
setState(() {
_list = list;
_error = null;
});
}
} catch (e) {
if (mounted) setState(() => _error = describeError(e));
}
}
Future<void> _open(Notification n) async {
if (!n.read) await _api.markRead(ids: [n.id]).catchError((_) {});
final page = n.page;
if (page == null || !mounted) return;
await Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (_) => PageScreen(
session: widget.session,
pageId: page.id,
openComment: n.comment.isEmpty ? null : n.comment,
),
),
);
_load();
}
Future<void> _readAll() async {
await _api.markRead(all: true).catchError((_) {});
_load();
}
@override
Widget build(BuildContext context) {
final list = _list;
return Scaffold(
appBar: AppBar(
title: const Text('Inbox'),
actions: [
if ((list?.unread ?? 0) > 0)
TextButton(onPressed: _readAll, child: const Text('Mark all read')),
],
),
body: RefreshIndicator(
onRefresh: _load,
child: ListView(
children: [
if (_error != null)
ErrorTile(message: _error!, onRetry: _load)
else if (list == null)
const Padding(
padding: EdgeInsets.all(32),
child: Center(child: CircularProgressIndicator()),
)
else if (list.items.isEmpty)
const ListTile(title: Text("You're all caught up.")),
for (final n in list?.items ?? <Notification>[])
ListTile(
key: Key('notification-${n.id}'),
leading: Icon(
n.read
? Icons.notifications_none
: Icons.notifications_active,
color: n.read ? null : Theme.of(context).colorScheme.primary,
),
title: Text(
'${notificationText(n)} · ${(n.page?.title ?? '').isNotEmpty ? n.page!.title : 'Untitled'}',
style: TextStyle(fontWeight: n.read ? null : FontWeight.w600),
),
subtitle: Text(
[
n.excerpt,
shortDate(n.created),
].where((s) => s.isNotEmpty).join('\n'),
maxLines: 3,
overflow: TextOverflow.ellipsis,
),
onTap: () => _open(n),
),
],
),
),
);
}
}