Skip to content

Commit

Permalink
Merge pull request #668 from 4ster1sk/fix/issue-646
Browse files Browse the repository at this point in the history
リノート解除時もとのノートを削除しないように
  • Loading branch information
shiosyakeyakini-info authored Nov 10, 2024
2 parents b7ab5f7 + 40b1caf commit 5c50a84
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 20 deletions.
53 changes: 35 additions & 18 deletions lib/view/note_modal_sheet/note_modal_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,18 @@ class NoteModalSheetNotifier extends _$NoteModalSheetNotifier {
}

Future<void> unRenote() async {
if (note.renoteId == null) return;
state = state.copyWith(delete: const AsyncLoading());
state = state.copyWith(
delete: await ref.read(dialogStateNotifierProvider.notifier).guard(
() async => await ref
.read(misskeyPostContextProvider)
.notes
.delete(NotesDeleteRequest(noteId: note.id)),
),
() async {
await ref
.read(misskeyPostContextProvider)
.notes
.delete(NotesDeleteRequest(noteId: note.id));
ref.read(notesWithProvider).delete(note.id);
},
),
);
}

Expand Down Expand Up @@ -224,9 +228,12 @@ class NoteModalSheet extends ConsumerWidget implements AutoRouteWrapper {
@override
Widget build(BuildContext context, WidgetRef ref) {
final accounts = ref.watch(accountRepositoryProvider);
final notifierProvider = noteModalSheetNotifierProvider(targetNote);
final targetNoteNotifierProvider =
noteModalSheetNotifierProvider(targetNote);
final baseNoteNotiferProvider = noteModalSheetNotifierProvider(baseNote);

ref.listen(notifierProvider.select((value) => value.user), (_, next) async {
ref.listen(targetNoteNotifierProvider.select((value) => value.user),
(_, next) async {
switch (next) {
case AsyncData<UserDetailed>(:final value):
await context.pushRoute(
Expand All @@ -240,10 +247,11 @@ class NoteModalSheet extends ConsumerWidget implements AutoRouteWrapper {
case AsyncError<UserDetailed>():
}
});
final noteStatus =
ref.watch(notifierProvider.select((value) => value.noteState));
final noteStatus = ref
.watch(targetNoteNotifierProvider.select((value) => value.noteState));

if (ref.read(notifierProvider).isLoading) {
if (ref.watch(targetNoteNotifierProvider).isLoading ||
ref.watch(baseNoteNotiferProvider).isLoading) {
return const Center(
child: SizedBox(
width: 100,
Expand Down Expand Up @@ -317,7 +325,8 @@ class NoteModalSheet extends ConsumerWidget implements AutoRouteWrapper {
leading: const Icon(Icons.person),
title: Text(S.of(context).user),
trailing: const Icon(Icons.keyboard_arrow_right),
onTap: () async => ref.read(notifierProvider.notifier).user(),
onTap: () async =>
ref.read(targetNoteNotifierProvider.notifier).user(),
),
ListTile(
leading: const Icon(Icons.open_in_browser),
Expand All @@ -339,7 +348,7 @@ class NoteModalSheet extends ConsumerWidget implements AutoRouteWrapper {
onTap: () async {
final uri = targetNote.url ?? targetNote.uri;
if (uri == null) return;
launchUrl(uri, mode: LaunchMode.externalApplication);
await launchUrl(uri, mode: LaunchMode.externalApplication);
if (!context.mounted) return;
Navigator.of(context).pop();
},
Expand All @@ -363,11 +372,12 @@ class NoteModalSheet extends ConsumerWidget implements AutoRouteWrapper {
onTap: () {
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
Future(() async {
if (!context.mounted) return;
final box = context.findRenderObject() as RenderBox?;
if (box == null) return;
final boundary = noteBoundaryKey.currentContext!
.findRenderObject()! as RenderRepaintBoundary;
await ref.read(notifierProvider.notifier).copyAsImage(
await ref.read(targetNoteNotifierProvider.notifier).copyAsImage(
box,
boundary,
View.of(context).devicePixelRatio,
Expand All @@ -386,7 +396,9 @@ class NoteModalSheet extends ConsumerWidget implements AutoRouteWrapper {
AsyncData(:final value) => ListTile(
leading: const Icon(Icons.star_rounded),
onTap: () async {
await ref.read(notifierProvider.notifier).favorite();
await ref
.read(targetNoteNotifierProvider.notifier)
.favorite();
if (!context.mounted) return;
Navigator.of(context).pop();
},
Expand Down Expand Up @@ -448,7 +460,7 @@ class NoteModalSheet extends ConsumerWidget implements AutoRouteWrapper {
leading: const Icon(Icons.delete),
title: Text(S.of(context).delete),
onTap: () async {
await ref.read(notifierProvider.notifier).delete();
await ref.read(targetNoteNotifierProvider.notifier).delete();
if (!context.mounted) return;
Navigator.of(context).pop();
},
Expand All @@ -457,8 +469,9 @@ class NoteModalSheet extends ConsumerWidget implements AutoRouteWrapper {
leading: const Icon(Icons.edit_outlined),
title: Text(S.of(context).deletedRecreate),
onTap: () async {
final result =
await ref.read(notifierProvider.notifier).deleteRecreate();
final result = await ref
.read(targetNoteNotifierProvider.notifier)
.deleteRecreate();
if (!result || !context.mounted) return;
Navigator.of(context).pop();
await context.pushRoute(
Expand All @@ -482,7 +495,11 @@ class NoteModalSheet extends ConsumerWidget implements AutoRouteWrapper {
ListTile(
leading: const Icon(Icons.delete),
title: Text(S.of(context).deleteRenote),
onTap: () async => ref.read(notifierProvider.notifier).unRenote(),
onTap: () async {
await ref.read(baseNoteNotiferProvider.notifier).unRenote();
if (!context.mounted) return;
Navigator.of(context).pop();
},
),
],
if (accountContext.isSame && baseNote.user.host != null ||
Expand Down
9 changes: 7 additions & 2 deletions test/view/common/misskey_notes/note_modal_sheet_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,13 @@ void main() {
);
when(misskey.notes).thenReturn(misskeyNotes);
when(misskeyNotes.featured(any)).thenAnswer(
(e) async =>
[TestData.note1.copyWith(text: null, renote: TestData.note2)],
(e) async => [
TestData.note1.copyWith(
text: null,
renoteId: TestData.note2.id,
renote: TestData.note2,
)
],
);
await tester.pumpWidget(
ProviderScope(
Expand Down

0 comments on commit 5c50a84

Please sign in to comment.