Skip to content

Commit

Permalink
リアクション後にnotes/showを呼ばない
Browse files Browse the repository at this point in the history
  • Loading branch information
poppingmoon committed Nov 3, 2023
1 parent bf9cab0 commit 7680029
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 41 deletions.
1 change: 0 additions & 1 deletion lib/const.dart

This file was deleted.

25 changes: 25 additions & 0 deletions lib/repository/note_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,17 @@ class NoteRepository extends ChangeNotifier {
);
}

void addMyReaction(String noteId, String reaction) {
addReaction(
noteId,
TimelineReacted(
reaction: reaction,
emoji: null,
userId: account.i.id,
),
);
}

void removeReaction(String noteId, TimelineReacted reaction) {
final registeredNote = _notes[noteId];
if (registeredNote == null) return;
Expand Down Expand Up @@ -155,6 +166,20 @@ class NoteRepository extends ChangeNotifier {
);
}

void removeMyReaction(String noteId) {
final myReaction = _notes[noteId]?.myReaction;
if (myReaction == null) return;

removeReaction(
noteId,
TimelineReacted(
reaction: myReaction,
emoji: null,
userId: account.i.id,
),
);
}

void addVote(String noteId, TimelineVoted vote) {
final registeredNote = _notes[noteId];
if (registeredNote == null) return;
Expand Down
44 changes: 22 additions & 22 deletions lib/view/common/misskey_notes/misskey_note.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:collection/collection.dart';
import 'package:dotted_border/dotted_border.dart';
import 'package:flutter/material.dart';
import 'package:mfm_parser/mfm_parser.dart' as parser;
import 'package:miria/const.dart';
import 'package:miria/extensions/date_time_extension.dart';
import 'package:miria/extensions/note_visibility_extension.dart';
import 'package:miria/extensions/user_extension.dart';
Expand Down Expand Up @@ -783,11 +782,7 @@ class MisskeyNoteState extends ConsumerState<MisskeyNote> {
.notes
.reactions
.delete(NotesReactionsDeleteRequest(noteId: displayNote.id));
if (account.host == "misskey.io") {
await Future.delayed(
const Duration(milliseconds: misskeyIOReactionDelay));
}
await ref.read(notesProvider(account)).refresh(displayNote.id);
ref.read(notesProvider(account)).removeMyReaction(displayNote.id);
return;
}
final misskey = ref.read(misskeyProvider(account));
Expand All @@ -797,27 +792,32 @@ class MisskeyNoteState extends ConsumerState<MisskeyNote> {
selectedEmoji = const UnicodeEmojiData(char: '❤️');
} else if (requestEmoji == null) {
selectedEmoji = await showDialog<MisskeyEmojiData?>(
context: context,
builder: (context) => ReactionPickerDialog(
account: account,
isAcceptSensitive: displayNote.reactionAcceptance !=
ReactionAcceptance.nonSensitiveOnly &&
displayNote.reactionAcceptance !=
ReactionAcceptance
.nonSensitiveOnlyForLocalLikeOnlyForRemote,
));
context: context,
builder: (context) => ReactionPickerDialog(
account: account,
isAcceptSensitive: displayNote.reactionAcceptance !=
ReactionAcceptance.nonSensitiveOnly &&
displayNote.reactionAcceptance !=
ReactionAcceptance.nonSensitiveOnlyForLocalLikeOnlyForRemote,
),
);
} else {
selectedEmoji = requestEmoji;
}

if (selectedEmoji == null) return;
await misskey.notes.reactions.create(NotesReactionsCreateRequest(
noteId: displayNote.id, reaction: ":${selectedEmoji.baseName}:"));
if (account.host == "misskey.io") {
await Future.delayed(
const Duration(milliseconds: misskeyIOReactionDelay));
}
await note.refresh(displayNote.id);
final reactionString = switch (selectedEmoji) {
UnicodeEmojiData(:final char) => char,
CustomEmojiData(:final baseName) => ":$baseName@.:",
NotEmojiData(:final name) => name,
};
await misskey.notes.reactions.create(
NotesReactionsCreateRequest(
noteId: displayNote.id,
reaction: reactionString,
),
);
note.addMyReaction(displayNote.id, reactionString);
}
}

Expand Down
28 changes: 10 additions & 18 deletions lib/view/common/misskey_notes/reaction_button.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:miria/const.dart';
import 'package:miria/model/account.dart';
import 'package:miria/model/misskey_emoji_data.dart';
import 'package:miria/providers.dart';
Expand Down Expand Up @@ -81,12 +80,7 @@ class ReactionButtonState extends ConsumerState<ReactionButton> {
.notes
.reactions
.delete(NotesReactionsDeleteRequest(noteId: widget.noteId));
if (account.host == "misskey.io") {
await Future.delayed(
const Duration(milliseconds: misskeyIOReactionDelay));
}

await ref.read(notesProvider(account)).refresh(widget.noteId);
ref.read(notesProvider(account)).removeMyReaction(widget.noteId);

return;
}
Expand All @@ -102,23 +96,21 @@ class ReactionButtonState extends ConsumerState<ReactionButton> {
break;
case CustomEmojiData():
if (!emojiData.isCurrentServer) return;
reactionString = ":${emojiData.baseName}:";
reactionString = ":${emojiData.baseName}@.:";
break;
case NotEmojiData():
return;
}

await ref.read(misskeyProvider(account)).notes.reactions.create(
NotesReactionsCreateRequest(
noteId: widget.noteId, reaction: reactionString));

// misskey.ioはただちにリアクションを反映してくれない
if (account.host == "misskey.io") {
await Future.delayed(
const Duration(milliseconds: misskeyIOReactionDelay));
}

await ref.read(notesProvider(account)).refresh(widget.noteId);
NotesReactionsCreateRequest(
noteId: widget.noteId,
reaction: reactionString,
),
);
ref
.read(notesProvider(account))
.addMyReaction(widget.noteId, reactionString);
},
onLongPress: () {
showDialog(
Expand Down

0 comments on commit 7680029

Please sign in to comment.