// Version: 1.1.0 | Created: 2026-04-02 | Updated: 2026-04-10
// Shared utility for generating a last-message preview string from a Room.
// Used by both RoomsRepository and SyncPersistenceService to avoid duplication.

import 'package:matrix/matrix.dart';

/// Returns a human-readable preview of the room's last event, or null if there
/// is no suitable event to preview.
String? lastMessagePreview(Room room) {
  final lastEvent = room.lastEvent;
  if (lastEvent == null) return null;

  return switch (lastEvent.type) {
    EventTypes.Message => lastEvent.body,
    EventTypes.Encrypted => '\u{1F512} Encrypted — use Element to read',
    EventTypes.Sticker => 'Sticker',
    _ => null,
  };
}
