Files
buzz/mobile/lib/features/channels/local_message_send_animation_provider.dart
klopez4212 aeb741fd31 Polish mobile channel navigation and message sends (#6488)
## Summary
- align iOS back controls and affected titles across channel details,
settings, and pairing
- make channel star and mute actions reflect their state immediately
- animate locally sent channel, thread, and DM messages from behind the
composer with a 300ms ease-out

## Testing
- `just mobile-check`
- full mobile test suite (1,573 tests)

---------

Signed-off-by: kenny lopez <klopez4212@gmail.com>
Signed-off-by: Kenny Lopez <klopez4212@gmail.com>
Co-authored-by: Princess Donut <b238ea756dee4d98afa5883fc7f1de61eeabe65bf700e3a5a5a80db5e42e2c2b@buzz.block.builderlab.xyz>
2026-08-21 19:13:16 +01:00

52 lines
1.7 KiB
Dart

import 'package:hooks_riverpod/hooks_riverpod.dart';
const _localMessageSendAnimationClaimWindow = Duration(seconds: 1);
/// Recently signed local messages that may play the send entrance animation.
///
/// The short claim window prevents a message first rendered much later (for
/// example after opening its channel) from looking newly sent.
class LocalMessageSendAnimationNotifier
extends Notifier<Map<String, DateTime>> {
/// The channel whose outgoing messages are tracked by this notifier.
final String channelId;
/// Creates animation state scoped to [channelId].
LocalMessageSendAnimationNotifier(this.channelId);
@override
Map<String, DateTime> build() => const {};
/// Marks [eventId] as a newly signed local message eligible for animation.
void mark(String eventId) {
final now = DateTime.now();
state = {
for (final entry in state.entries)
if (now.difference(entry.value) <=
_localMessageSendAnimationClaimWindow)
entry.key: entry.value,
eventId: now,
};
}
}
/// Whether [eventId] was marked recently enough to animate as a local send.
bool isRecentLocalMessageSendAnimation(
Map<String, DateTime> animations,
String eventId, {
DateTime? now,
}) {
final markedAt = animations[eventId];
if (markedAt == null) return false;
return (now ?? DateTime.now()).difference(markedAt) <=
_localMessageSendAnimationClaimWindow;
}
/// Recent local-send animation claims keyed by channel and event ID.
final localMessageSendAnimationProvider =
NotifierProvider.family<
LocalMessageSendAnimationNotifier,
Map<String, DateTime>,
String
>(LocalMessageSendAnimationNotifier.new);