Files
buzz/mobile/lib/features/channels/thread_detail_helpers.dart
klopez4212 69107dc3bf Polish mobile message threads and composer (#5645)
## Summary

- refine mobile message metadata, search spacing, and Activity filter
semantics
- add channel-parity Latest navigation and stable tail following to
threads
- synchronize Android composer/keyboard geometry and keep Latest spacing
stable across IME transitions

## Validation

- `bin/just mobile-check`
- `bin/just mobile-test` (1,276 tests)
- Pixel 10 install/launch and channel/thread keyboard, Latest, tail, and
back-navigation review
- signed iPhone install/launch workflow

## Snapshots

See the review snapshots below.

---------

Signed-off-by: kenny lopez <klopez4212@gmail.com>
Signed-off-by: Kenny Lopez <klopez4212@gmail.com>
Signed-off-by: Princess Donut <b238ea756dee4d98afa5883fc7f1de61eeabe65bf700e3a5a5a80db5e42e2c2b@buzz.block.builderlab.xyz>
Co-authored-by: Fast Fizz <2df81cb51f05a9d5387ef24d7b9ecb8fcdfcd1c70ffabc67061c9596e1b5b1c4@buzz.block.builderlab.xyz>
Co-authored-by: Princess Donut <b238ea756dee4d98afa5883fc7f1de61eeabe65bf700e3a5a5a80db5e42e2c2b@buzz.block.builderlab.xyz>
2026-08-15 09:14:14 +01:00

114 lines
3.1 KiB
Dart

part of 'thread_detail_page.dart';
int _threadTailIndex(int replyCount) => replyCount;
void _resumeThreadTailFollow({
required bool Function() isVisible,
required ObjectRef<bool> userOptedOut,
required ObjectRef<bool> followsTail,
}) {
if (!isVisible()) return;
userOptedOut.value = false;
followsTail.value = true;
}
bool _isDeletedBy(Iterable<NostrEvent> events, String messageId) {
for (final event in events) {
if (event.kind != EventKind.deletion &&
event.kind != EventKind.nip29DeleteEvent) {
continue;
}
if (event.tags.any(
(tag) => tag.length >= 2 && tag[0] == 'e' && tag[1] == messageId,
)) {
return true;
}
}
return false;
}
/// Build a lightweight summary for a nested thread (reply that has its own
/// replies). Same logic as the top-level [ThreadSummary] but kept local to
/// avoid coupling.
ThreadSummary _buildNestedSummary(
String messageId,
List<TimelineMessage> children,
) {
final seen = <String>{};
final participants = <String>[];
for (var i = children.length - 1; i >= 0 && participants.length < 3; i--) {
final pk = children[i].pubkey.toLowerCase();
if (seen.add(pk)) participants.add(pk);
}
return ThreadSummary(
threadHeadId: messageId,
replyCount: children.length,
participantPubkeys: participants.reversed.toList(),
lastReplyAt: children.last.createdAt,
);
}
/// Serializes deferred tail work behind the latest user scroll intent.
class _ThreadTailIntent {
var _generation = 0;
var isDragging = false;
void detach() => _generation++;
void beginDrag() {
isDragging = true;
detach();
}
void endDrag() => isDragging = false;
void scheduleNextFrame({
required bool allowed,
required bool Function() revalidate,
required VoidCallback action,
}) {
if (!allowed) return;
final generation = ++_generation;
WidgetsBinding.instance.addPostFrameCallback((_) {
if (generation == _generation && revalidate()) action();
});
}
void schedule({
required bool allowed,
required bool Function() revalidate,
required VoidCallback action,
}) {
if (!allowed) return;
final generation = ++_generation;
WidgetsBinding.instance.addPostFrameCallback((_) {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (generation == _generation && revalidate()) action();
});
WidgetsBinding.instance.scheduleFrame();
});
}
}
/// Thread-scoped typing status with optional size animation.
class _ThreadTypingIndicator extends StatelessWidget {
final List<TypingEntry> entries;
final bool animated;
const _ThreadTypingIndicator({required this.entries, this.animated = true});
@override
Widget build(BuildContext context) {
final child = entries.isEmpty
? const SizedBox.shrink()
: ChannelTypingIndicator(entries: entries);
if (!animated || MediaQuery.disableAnimationsOf(context)) return child;
return AnimatedSize(
duration: const Duration(milliseconds: 180),
curve: Curves.easeOutCubic,
alignment: Alignment.bottomCenter,
child: child,
);
}
}