Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: hide content from summary if cw is provided #468

Merged
merged 1 commit into from
Nov 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading