Skip to content

Commit

Permalink
省略されたノートを一定の行まで表示する
Browse files Browse the repository at this point in the history
  • Loading branch information
poppingmoon committed Nov 23, 2023
1 parent 4b49524 commit 9b2b223
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 76 deletions.
6 changes: 6 additions & 0 deletions lib/view/common/misskey_notes/mfm_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class MfmText extends ConsumerStatefulWidget {
final List<InlineSpan> prefixSpan;
final Function(MisskeyEmojiData)? onEmojiTap;
final bool isEnableAnimatedMFM;
final TextOverflow? overflow;
final int? maxLines;

const MfmText({
super.key,
Expand All @@ -47,6 +49,8 @@ class MfmText extends ConsumerStatefulWidget {
this.prefixSpan = const [],
this.onEmojiTap,
this.isEnableAnimatedMFM = true,
this.overflow,
this.maxLines,
}) : assert(mfmText != null || mfmNode != null);

@override
Expand Down Expand Up @@ -165,6 +169,8 @@ class MfmTextState extends ConsumerState<MfmText> {
suffixSpan: widget.suffixSpan,
prefixSpan: widget.prefixSpan,
isUseAnimation: widget.isEnableAnimatedMFM,
overflow: widget.overflow,
maxLines: widget.maxLines,
);
}
}
Expand Down
134 changes: 59 additions & 75 deletions lib/view/common/misskey_notes/misskey_note.dart
Original file line number Diff line number Diff line change
Expand Up @@ -418,84 +418,68 @@ class MisskeyNoteState extends ConsumerState<MisskeyNote> {
],
if (displayNote.cw == null ||
displayNote.cw != null && isCwOpened) ...[
if (isReactionedRenote)
SimpleMfmText(
"${(displayNote.text ?? "").substring(0, min((displayNote.text ?? "").length, 50))}..."
.replaceAll("\n\n", "\n"),
isNyaize: displayNote.user.isCat,
emojis: displayNote.emojis,
suffixSpan: [
WidgetSpan(
child: InNoteButton(
onPressed: () {
ref
.read(notesProvider(
AccountScope.of(context)))
.updateNoteStatus(
widget.note.id,
(status) => status.copyWith(
isReactionedRenote: !status
.isReactionedRenote),
);
},
child: const Text("続きを表示"),
MfmText(
mfmNode: displayTextNodes,
host: displayNote.user.host,
emoji: displayNote.emojis,
isNyaize: displayNote.user.isCat,
isEnableAnimatedMFM: ref
.read(generalSettingsRepositoryProvider)
.settings
.enableAnimatedMFM,
onEmojiTap: (emojiData) async =>
await reactionControl(
ref,
context,
displayNote,
requestEmoji: emojiData,
),
overflow: TextOverflow.clip,
suffixSpan: [
if (!isEmptyRenote &&
displayNote.renoteId != null &&
(widget.recursive == 2 ||
widget.isForceUnvisibleRenote))
TextSpan(
text: " RN:...",
style: TextStyle(
color: Theme.of(context).primaryColor,
fontStyle: FontStyle.italic,
),
)
],
)
else ...[
if (isLongVisible)
MfmText(
mfmNode: displayTextNodes,
host: displayNote.user.host,
emoji: displayNote.emojis,
isNyaize: displayNote.user.isCat,
isEnableAnimatedMFM: ref
.read(generalSettingsRepositoryProvider)
.settings
.enableAnimatedMFM,
onEmojiTap: (emojiData) async =>
await reactionControl(
ref, context, displayNote,
requestEmoji: emojiData),
suffixSpan: [
if (!isEmptyRenote &&
displayNote.renoteId != null &&
(widget.recursive == 2 ||
widget.isForceUnvisibleRenote))
TextSpan(
text: " RN:...",
style: TextStyle(
color: Theme.of(context).primaryColor,
fontStyle: FontStyle.italic,
),
),
],
)
else
SimpleMfmText(
"${(displayNote.text ?? "").substring(0, min((displayNote.text ?? "").length, 150))}..."
.replaceAll("\n\n", "\n"),
emojis: displayNote.emojis,
isNyaize: displayNote.user.isCat,
suffixSpan: [
WidgetSpan(
child: InNoteButton(
onPressed: () {
ref
.read(notesProvider(
AccountScope.of(context)))
.updateNoteStatus(
widget.note.id,
(status) => status.copyWith(
isLongVisible: !status
.isLongVisible));
},
child: const Text("続きを表示"),
),
],
maxLines: isReactionedRenote
? 1
: isLongVisible
? null
: 10,
),
if (isReactionedRenote || !isLongVisible)
Center(
child: InNoteButton(
onPressed: () {
final repository = ref.read(
notesProvider(
AccountScope.of(context),
),
)
],
);
repository.updateNoteStatus(
widget.note.id,
(status) => isReactionedRenote
? status.copyWith(
isReactionedRenote:
!status.isReactionedRenote,
)
: status.copyWith(
isLongVisible:
!status.isLongVisible,
),
);
},
child: const Text("続きを表示"),
),
),
if (!isReactionedRenote) ...[
MisskeyFileView(
files: displayNote.files,
height: 200 *
Expand Down
5 changes: 4 additions & 1 deletion test/view/common/misskey_notes/misskey_notes_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,12 @@ System.out.println("@ai uneune");
note: TestData.note1.copyWith(text: longText),
));
await tester.pumpAndSettle();
expect(find.textContaining(longText, findRichText: true), findsNothing);
await tester.tap(find.text("続きを表示"));
await tester.pumpAndSettle();
expect(
find.text("続きを表示"),
findsNothing,
);
expect(
find.textContaining(longText, findRichText: true), findsOneWidget);
});
Expand Down

0 comments on commit 9b2b223

Please sign in to comment.