asnasd/lib/widgets/renderers/diffs/pinned_events_diff.dart
Henry-Hiles 6e6bcaaad1
support a lot more events to be rendered
Also adds show hidden events setting.

Fixes #178
2026-11-26 17:19:19 -05:00

57 lines
1.8 KiB
Dart

import "package:fast_immutable_collections/fast_immutable_collections.dart";
import "package:material_ui/material_ui.dart";
import "package:nexus/helpers/hooks/chat_scroll.dart";
import "package:nexus/helpers/extensions/success_scheme.dart";
import "package:nexus/widgets/renderers/related_event_line.dart";
/// A line for each message a pinned events event pinned, in green, and each one
/// it unpinned, in red and struck through.
class const PinnedEventsDiff(
final String roomId, {
required final IList<String> pinned,
required final IList<String> unpinned,
/// If set, tapping a message jumps to it.
final JumpToEvent? jumpToEvent,
super.key,
}) extends StatelessWidget {
static const maxShown = 5;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final style = theme.textTheme.labelMedium;
final changes = [
...pinned.map((eventId) => (eventId, unpinned: false)),
...unpinned.map((eventId) => (eventId, unpinned: true)),
];
return Column(
crossAxisAlignment: .start,
spacing: 2,
children: [
...changes.take(maxShown).map((change) {
final color = change.unpinned
? theme.colorScheme.error
: theme.successScheme.primary;
final decoration = change.unpinned
? TextDecoration.lineThrough
: null;
return RelatedEventLine(
roomId,
change.$1,
color: color,
decoration: decoration,
jumpToEvent: jumpToEvent,
);
}),
if (changes.length > maxShown)
Text(
"+${changes.length - maxShown} more",
style: style?.copyWith(color: theme.colorScheme.onSurfaceVariant),
),
],
);
}
}