Skip to content

Commit

Permalink
fix: hide content from summary if cw is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
poppingmoon committed Nov 9, 2024
1 parent ce157c6 commit e357037
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions lib/view/widget/note_summary.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:misskey_dart/misskey_dart.dart';

import '../../i18n/strings.g.dart';
import '../../model/account.dart';
Expand All @@ -19,6 +20,32 @@ class NoteSummary extends ConsumerWidget {
final String noteId;
final void Function()? onTap;

String getNoteSummary(
BuildContext context,
Note note, {
bool detailed = true,
}) {
return [
if (note.cw case final cw?)
cw
else if (note.text case final text?)
text.replaceAll('\n', ' '),
if (note.fileIds.isNotEmpty)
'(${t.misskey.withNFiles(n: note.fileIds.length)})',
if (note.poll != null) '(${t.misskey.poll})',
if (note.replyId != null)
if (note.reply case final reply? when detailed)
'RE: ${getNoteSummary(context, reply, detailed: false)}'
else
'RE: ...',
if (note.renoteId != null)
if (note.renote case final renote? when detailed)
'RE: ${getNoteSummary(context, renote, detailed: false)}'
else
'RE: ...',
].join(' ');
}

@override
Widget build(BuildContext context, WidgetRef ref) {
final note = ref.watch(noteProvider(account, noteId));
Expand All @@ -32,13 +59,7 @@ class NoteSummary extends ConsumerWidget {
onTap: onTap,
child: Mfm(
account: account,
text: [
if (note.text != null) note.text!.replaceAll('\n', ' '),
if (note.fileIds.isNotEmpty)
'(${t.misskey.withNFiles(n: note.fileIds.length)})',
if (note.poll != null) '(${t.misskey.poll})',
if (note.replyId != null) 'RE: ...',
].join(' '),
text: getNoteSummary(context, note),
simple: true,
emojis: note.emojis,
author: note.user,
Expand Down

0 comments on commit e357037

Please sign in to comment.