// Version: 1.1.1 | Created: 2026-04-02 | Updated: 2026-07-03
// 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,
  };
}
