Mobile app (Android):
- Sign-in to any server, with authenticator codes. The server address and
token are kept in secure storage; a dropped connection never signs out.
- Workspaces, recent pages, spaces and a foldable page tree; search; the
inbox with mark-read.
- Pages open read-only in the shared editor from their saved content and
join the live document to edit (with the native toolbar). Page links in
the text open in the app (new "navigate" bridge message).
- Comments: threads, replies, resolve.
- "Save to Docwell" in the Android share sheet makes a page from shared
text, with web addresses as links.
- Offline reading: every answer the app reads is kept on the phone, and
used when the server can't be reached.
- Push through UnifiedPush (ntfy, NextPush, ...). The app uses the Android
connector directly; the umbrella package pulls in a native crypto build
for Linux that breaks `dart run` and tests.
Server:
- /me/devices registers a phone's UnifiedPush endpoint and Web Push keys
(new push_devices collection). Each notification is also pushed,
encrypted with RFC 8291 aes128gcm so the distributor can't read it; the
app drops messages that don't decrypt. Endpoints answering 404/410 are
forgotten. Endpoints follow the webhook address rules.
- /collab accepts the apps' own origins ("null" for the mobile editor page,
wails:// for the desktop app). Sign-in is a token in the first message,
not a cookie, so this opens no cross-site hijacking.
Tried on an Android 15 emulator: sign-in, browsing, reading, live editing,
sharing and offline reading. Not covered: push end to end (no distributor
on the emulator), iOS, and YouTube embeds, which refuse to play from the
app's local editor page (error 153).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
257 lines
8.0 KiB
Dart
257 lines
8.0 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 'widgets.dart';
|
|
|
|
/// A page's comment threads with their replies. People who may comment can
|
|
/// start a thread, reply and resolve.
|
|
class CommentsScreen extends StatefulWidget {
|
|
const CommentsScreen({
|
|
super.key,
|
|
required this.session,
|
|
required this.page,
|
|
this.highlight,
|
|
});
|
|
|
|
final AppSession session;
|
|
final Page page;
|
|
|
|
/// A comment to scroll to and mark (from a notification).
|
|
final String? highlight;
|
|
|
|
@override
|
|
State<CommentsScreen> createState() => _CommentsScreenState();
|
|
}
|
|
|
|
class _CommentsScreenState extends State<CommentsScreen> {
|
|
DocwellApi get _api => widget.session.api;
|
|
List<Comment>? _comments;
|
|
String? _error;
|
|
bool _showResolved = false;
|
|
final _text = TextEditingController();
|
|
Comment? _replyTo;
|
|
bool _busy = false;
|
|
|
|
bool get _canComment => widget.page.role.canComment && !widget.page.inTrash;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_load();
|
|
}
|
|
|
|
Future<void> _load() async {
|
|
try {
|
|
final list = await _api.comments(widget.page.id);
|
|
if (mounted) {
|
|
setState(() {
|
|
_comments = list;
|
|
_error = null;
|
|
});
|
|
}
|
|
} catch (e) {
|
|
if (mounted) setState(() => _error = describeError(e));
|
|
}
|
|
}
|
|
|
|
Future<void> _send() async {
|
|
final body = _text.text.trim();
|
|
if (body.isEmpty) return;
|
|
setState(() => _busy = true);
|
|
try {
|
|
await _api.addComment(widget.page.id, body, parent: _replyTo?.id ?? '');
|
|
_text.clear();
|
|
_replyTo = null;
|
|
await _load();
|
|
} catch (e) {
|
|
if (mounted) {
|
|
ScaffoldMessenger.of(
|
|
context,
|
|
).showSnackBar(SnackBar(content: Text(describeError(e))));
|
|
}
|
|
} finally {
|
|
if (mounted) setState(() => _busy = false);
|
|
}
|
|
}
|
|
|
|
Future<void> _resolve(Comment c) async {
|
|
try {
|
|
await _api.resolveComment(c.id, c.resolvedAt.isEmpty);
|
|
await _load();
|
|
} catch (e) {
|
|
if (mounted) {
|
|
ScaffoldMessenger.of(
|
|
context,
|
|
).showSnackBar(SnackBar(content: Text(describeError(e))));
|
|
}
|
|
}
|
|
}
|
|
|
|
Widget _comment(Comment c, {bool reply = false}) {
|
|
final marked = c.id == widget.highlight;
|
|
final theme = Theme.of(context);
|
|
return Container(
|
|
color: marked ? theme.colorScheme.secondaryContainer : null,
|
|
padding: EdgeInsets.fromLTRB(reply ? 40 : 16, 8, 16, 8),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
if (c.quote.isNotEmpty)
|
|
Container(
|
|
margin: const EdgeInsets.only(bottom: 6),
|
|
padding: const EdgeInsets.only(left: 8),
|
|
decoration: BoxDecoration(
|
|
border: Border(
|
|
left: BorderSide(color: theme.colorScheme.outline, width: 3),
|
|
),
|
|
),
|
|
child: Text(
|
|
c.quote,
|
|
maxLines: 3,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: theme.textTheme.bodySmall,
|
|
),
|
|
),
|
|
Text.rich(
|
|
TextSpan(
|
|
children: [
|
|
TextSpan(
|
|
text: c.author.name.isEmpty ? c.author.email : c.author.name,
|
|
style: const TextStyle(fontWeight: FontWeight.w600),
|
|
),
|
|
TextSpan(
|
|
text: ' ${shortDate(c.created)}',
|
|
style: theme.textTheme.bodySmall,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(height: 2),
|
|
Text(c.body),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final all = _comments;
|
|
final threads = (all ?? [])
|
|
.where(
|
|
(c) => c.parent.isEmpty && (_showResolved || c.resolvedAt.isEmpty),
|
|
)
|
|
.toList();
|
|
final resolved = (all ?? [])
|
|
.where((c) => c.parent.isEmpty && c.resolvedAt.isNotEmpty)
|
|
.length;
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('Comments'),
|
|
actions: [
|
|
if (resolved > 0)
|
|
TextButton(
|
|
onPressed: () => setState(() => _showResolved = !_showResolved),
|
|
child: Text(
|
|
_showResolved ? 'Hide resolved' : 'Resolved ($resolved)',
|
|
),
|
|
),
|
|
],
|
|
),
|
|
body: Column(
|
|
children: [
|
|
Expanded(
|
|
child: RefreshIndicator(
|
|
onRefresh: _load,
|
|
child: ListView(
|
|
children: [
|
|
if (_error != null)
|
|
ErrorTile(message: _error!, onRetry: _load)
|
|
else if (all == null)
|
|
const Padding(
|
|
padding: EdgeInsets.all(32),
|
|
child: Center(child: CircularProgressIndicator()),
|
|
)
|
|
else if (threads.isEmpty)
|
|
const ListTile(title: Text('No comments yet.')),
|
|
for (final t in threads)
|
|
Card(
|
|
margin: const EdgeInsets.fromLTRB(12, 8, 12, 0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
_comment(t),
|
|
for (final r in all!.where((c) => c.parent == t.id))
|
|
_comment(r, reply: true),
|
|
OverflowBar(
|
|
alignment: MainAxisAlignment.end,
|
|
children: [
|
|
if (t.canResolve)
|
|
TextButton(
|
|
onPressed: () => _resolve(t),
|
|
child: Text(
|
|
t.resolvedAt.isEmpty ? 'Resolve' : 'Reopen',
|
|
),
|
|
),
|
|
if (_canComment && t.resolvedAt.isEmpty)
|
|
TextButton(
|
|
onPressed: () => setState(() => _replyTo = t),
|
|
child: const Text('Reply'),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
if (_canComment)
|
|
SafeArea(
|
|
top: false,
|
|
child: Padding(
|
|
padding: const EdgeInsets.fromLTRB(12, 8, 8, 8),
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: TextField(
|
|
key: const Key('comment-text'),
|
|
controller: _text,
|
|
minLines: 1,
|
|
maxLines: 5,
|
|
decoration: InputDecoration(
|
|
hintText: _replyTo == null
|
|
? 'Comment on the page'
|
|
: 'Reply to ${_replyTo!.author.name}',
|
|
border: const OutlineInputBorder(),
|
|
isDense: true,
|
|
suffixIcon: _replyTo == null
|
|
? null
|
|
: IconButton(
|
|
tooltip: 'Cancel reply',
|
|
icon: const Icon(Icons.close),
|
|
onPressed: () =>
|
|
setState(() => _replyTo = null),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
IconButton(
|
|
key: const Key('comment-send'),
|
|
tooltip: 'Send',
|
|
icon: const Icon(Icons.send),
|
|
onPressed: _busy ? null : _send,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|