toFeedPost method

Map<String, dynamic> toFeedPost()

Convierte este BlogEntry a un Post para mostrarlo en el feed/timeline. El caption del Post incluirá un preview del contenido. El referenceId apunta al BlogEntry original.

Implementation

Map<String, dynamic> toFeedPost() {
  // Crear un preview del contenido (sin marcadores de formato)
  String preview = content
      .replaceAll(RegExp(r'\*\*([^*]+)\*\*'), r'\1')  // Remove **bold**
      .replaceAll(RegExp(r'\*([^*]+)\*'), r'\1')      // Remove *italic*
      .replaceAll(RegExp(r'~~([^~]+)~~'), r'\1')      // Remove ~~strike~~
      .replaceAll(RegExp(r'^#+\s*', multiLine: true), '') // Remove # headers
      .replaceAll(RegExp(r'\n+'), ' ')                // Replace newlines with spaces
      .trim();

  // Limitar el preview a ~150 caracteres
  if (preview.length > 150) {
    preview = '${preview.substring(0, 147)}...';
  }

  // El caption será: Título + preview (o solo preview si no hay título)
  final caption = title.isNotEmpty
      ? '$title\n\n$preview'
      : preview;

  return {
    'ownerId': ownerId,
    'profileName': profileName,
    'profileImgUrl': profileImgUrl,
    'caption': caption,
    'type': 'blogEntry',
    'mediaUrl': '',
    'thumbnailUrl': thumbnailUrl,
    'externalUrl': '',
    'createdTime': createdTime,
    'modifiedTime': modifiedTime,
    'position': null,
    'location': location,
    'likedProfiles': <String>[],
    'sharedProfiles': <String>[],
    'savedByProfiles': savedByProfiles,
    'mentionedProfiles': <String>[],
    'commentIds': <String>[],
    'hashtags': hashtags,
    'isCommentEnabled': isCommentEnabled,
    'isPrivate': false,
    'isDraft': false,
    'isHidden': isHidden,
    'verificationLevel': verificationLevel?.name,
    'mediaOwner': '',
    'referenceId': id,  // Referencia al BlogEntry original
    'lastInteraction': DateTime.now().millisecondsSinceEpoch,
    'aspectRatio': 1,
    'textStyleId': '',
  };
}