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

#354 対応 #357

Merged
merged 1 commit into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
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
10 changes: 7 additions & 3 deletions lib/providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ import 'package:misskey_dart/misskey_dart.dart';
final dioProvider = Provider((ref) => Dio());
final fileSystemProvider =
Provider<FileSystem>((ref) => const LocalFileSystem());
final misskeyProvider = Provider.family<Misskey, Account>(
(ref, account) => Misskey(token: account.token, host: account.host, socketConnectionTimeout: const Duration(seconds: 20)));
final misskeyProvider = Provider.family<Misskey, Account>((ref, account) =>
Misskey(
token: account.token,
host: account.host,
socketConnectionTimeout: const Duration(seconds: 20)));

final localTimeLineProvider =
ChangeNotifierProvider.family<TimelineRepository, TabSetting>(
Expand Down Expand Up @@ -194,5 +197,6 @@ final noteCreateProvider = StateNotifierProvider.family
ref.read(fileSystemProvider),
ref.read(dioProvider),
ref.read(misskeyProvider(account)),
ref.read(errorEventProvider.notifier)),
ref.read(errorEventProvider.notifier),
ref.read(notesProvider(account))),
);
18 changes: 12 additions & 6 deletions lib/router/app_router.gr.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 49 additions & 31 deletions lib/state_notifier/note_create_page/note_create_state_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:mfm_parser/mfm_parser.dart';
import 'package:miria/model/account.dart';
import 'package:miria/model/image_file.dart';
import 'package:miria/repository/note_repository.dart';
import 'package:miria/view/common/error_dialog_handler.dart';
import 'package:miria/view/dialogs/simple_message_dialog.dart';
import 'package:miria/view/note_create_page/drive_file_select_dialog.dart';
import 'package:miria/view/note_create_page/drive_modal_sheet.dart';
import 'package:miria/view/note_create_page/file_settings_dialog.dart';
import 'package:miria/view/note_create_page/note_create_page.dart';
import 'package:miria/view/user_select_dialog.dart';
import 'package:misskey_dart/misskey_dart.dart';

Expand Down Expand Up @@ -68,6 +70,8 @@ class NoteCreate with _$NoteCreate {
int? voteDuration,
@Default(VoteExpireDurationType.seconds)
VoteExpireDurationType voteDurationType,
NoteCreationMode? noteCreationMode,
String? noteId,
}) = _NoteCreate;
}

Expand All @@ -83,6 +87,7 @@ class NoteCreateNotifier extends StateNotifier<NoteCreate> {
FileSystem fileSystem;
Dio dio;
Misskey misskey;
NoteRepository noteRepository;
StateNotifier<(Object? error, BuildContext? context)> errorNotifier;

NoteCreateNotifier(
Expand All @@ -91,16 +96,18 @@ class NoteCreateNotifier extends StateNotifier<NoteCreate> {
this.dio,
this.misskey,
this.errorNotifier,
this.noteRepository,
);

/// 初期化する
Future<void> initialize(
CommunityChannel? channel,
String? initialText,
List<String>? initialMediaFiles,
Note? deletedNote,
Note? note,
Note? renote,
Note? reply,
NoteCreationMode? noteCreationMode,
) async {
var resultState = state;

Expand Down Expand Up @@ -148,9 +155,9 @@ class NoteCreateNotifier extends StateNotifier<NoteCreate> {
}

// 削除されたノートの反映
if (deletedNote != null) {
if (note != null) {
final files = <MisskeyPostFile>[];
for (final file in deletedNote.files) {
for (final file in note.files) {
if (file.type.startsWith("image")) {
final response = await dio.get(file.url,
options: Options(responseType: ResponseType.bytes));
Expand All @@ -172,33 +179,33 @@ class NoteCreateNotifier extends StateNotifier<NoteCreate> {
));
}
}
final deletedNoteChannel = deletedNote.channel;
final deletedNoteChannel = note.channel;

resultState = resultState.copyWith(
noteVisibility: deletedNote.visibility,
localOnly: deletedNote.localOnly,
noteVisibility: note.visibility,
localOnly: note.localOnly,
files: files,
channel: deletedNoteChannel != null
? NoteCreateChannel(
id: deletedNoteChannel.id, name: deletedNoteChannel.name)
: null,
cwText: deletedNote.cw ?? "",
isCw: deletedNote.cw?.isNotEmpty == true,
text: deletedNote.text ?? "",
reactionAcceptance: deletedNote.reactionAcceptance,
cwText: note.cw ?? "",
isCw: note.cw?.isNotEmpty == true,
text: note.text ?? "",
reactionAcceptance: note.reactionAcceptance,
replyTo: [
for (final userId in deletedNote.mentions)
for (final userId in note.mentions)
(await misskey.users.show(UsersShowRequest(userId: userId)))
.toUser()
],
isVote: deletedNote.poll != null,
isVoteMultiple: deletedNote.poll?.multiple ?? false,
isVote: note.poll != null,
isVoteMultiple: note.poll?.multiple ?? false,
voteExpireType: VoteExpireType.date,
voteContentCount:
deletedNote.poll?.choices.map((e) => e.text).length ?? 2,
voteContent:
deletedNote.poll?.choices.map((e) => e.text).toList() ?? [],
voteDate: deletedNote.poll?.expiresAt,
voteContentCount: note.poll?.choices.map((e) => e.text).length ?? 2,
voteContent: note.poll?.choices.map((e) => e.text).toList() ?? [],
voteDate: note.poll?.expiresAt,
noteCreationMode: noteCreationMode,
noteId: note.id,
);
state = resultState;
return;
Expand Down Expand Up @@ -390,19 +397,30 @@ class NoteCreateNotifier extends StateNotifier<NoteCreate> {
? voteDuration
: null);

await misskey.notes.create(NotesCreateRequest(
visibility: state.noteVisibility,
text: postText,
cw: state.isCw ? state.cwText : null,
localOnly: state.localOnly,
replyId: state.reply?.id,
renoteId: state.renote?.id,
channelId: state.channel?.id,
fileIds: fileIds.isEmpty ? null : fileIds,
visibleUserIds: visibleUserIds.toSet().toList(), //distinct list
reactionAcceptance: state.reactionAcceptance,
poll: state.isVote ? poll : null,
));
if (state.noteCreationMode == NoteCreationMode.update) {
await misskey.notes.update(NotesUpdateRequest(
noteId: state.noteId!,
text: postText ?? "",
cw: state.isCw ? state.cwText : null,
));
noteRepository.registerNote(noteRepository.notes[state.noteId!]!
.copyWith(
text: postText ?? "", cw: state.isCw ? state.cwText : null));
} else {
await misskey.notes.create(NotesCreateRequest(
visibility: state.noteVisibility,
text: postText,
cw: state.isCw ? state.cwText : null,
localOnly: state.localOnly,
replyId: state.reply?.id,
renoteId: state.renote?.id,
channelId: state.channel?.id,
fileIds: fileIds.isEmpty ? null : fileIds,
visibleUserIds: visibleUserIds.toSet().toList(), //distinct list
reactionAcceptance: state.reactionAcceptance,
poll: state.isVote ? poll : null,
));
}
if (!mounted) return;
state = state.copyWith(isNoteSending: NoteSendStatus.finished);
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ mixin _$NoteCreate {
int? get voteDuration => throw _privateConstructorUsedError;
VoteExpireDurationType get voteDurationType =>
throw _privateConstructorUsedError;
NoteCreationMode? get noteCreationMode => throw _privateConstructorUsedError;
String? get noteId => throw _privateConstructorUsedError;

@JsonKey(ignore: true)
$NoteCreateCopyWith<NoteCreate> get copyWith =>
Expand Down Expand Up @@ -74,7 +76,9 @@ abstract class $NoteCreateCopyWith<$Res> {
bool isVoteMultiple,
DateTime? voteDate,
int? voteDuration,
VoteExpireDurationType voteDurationType});
VoteExpireDurationType voteDurationType,
NoteCreationMode? noteCreationMode,
String? noteId});

$AccountCopyWith<$Res> get account;
$NoteCreateChannelCopyWith<$Res>? get channel;
Expand Down Expand Up @@ -117,6 +121,8 @@ class _$NoteCreateCopyWithImpl<$Res, $Val extends NoteCreate>
Object? voteDate = freezed,
Object? voteDuration = freezed,
Object? voteDurationType = null,
Object? noteCreationMode = freezed,
Object? noteId = freezed,
}) {
return _then(_value.copyWith(
account: null == account
Expand Down Expand Up @@ -207,6 +213,14 @@ class _$NoteCreateCopyWithImpl<$Res, $Val extends NoteCreate>
? _value.voteDurationType
: voteDurationType // ignore: cast_nullable_to_non_nullable
as VoteExpireDurationType,
noteCreationMode: freezed == noteCreationMode
? _value.noteCreationMode
: noteCreationMode // ignore: cast_nullable_to_non_nullable
as NoteCreationMode?,
noteId: freezed == noteId
? _value.noteId
: noteId // ignore: cast_nullable_to_non_nullable
as String?,
) as $Val);
}

Expand Down Expand Up @@ -285,7 +299,9 @@ abstract class _$$_NoteCreateCopyWith<$Res>
bool isVoteMultiple,
DateTime? voteDate,
int? voteDuration,
VoteExpireDurationType voteDurationType});
VoteExpireDurationType voteDurationType,
NoteCreationMode? noteCreationMode,
String? noteId});

@override
$AccountCopyWith<$Res> get account;
Expand Down Expand Up @@ -330,6 +346,8 @@ class __$$_NoteCreateCopyWithImpl<$Res>
Object? voteDate = freezed,
Object? voteDuration = freezed,
Object? voteDurationType = null,
Object? noteCreationMode = freezed,
Object? noteId = freezed,
}) {
return _then(_$_NoteCreate(
account: null == account
Expand Down Expand Up @@ -420,6 +438,14 @@ class __$$_NoteCreateCopyWithImpl<$Res>
? _value.voteDurationType
: voteDurationType // ignore: cast_nullable_to_non_nullable
as VoteExpireDurationType,
noteCreationMode: freezed == noteCreationMode
? _value.noteCreationMode
: noteCreationMode // ignore: cast_nullable_to_non_nullable
as NoteCreationMode?,
noteId: freezed == noteId
? _value.noteId
: noteId // ignore: cast_nullable_to_non_nullable
as String?,
));
}
}
Expand Down Expand Up @@ -449,7 +475,9 @@ class _$_NoteCreate implements _NoteCreate {
this.isVoteMultiple = false,
this.voteDate,
this.voteDuration,
this.voteDurationType = VoteExpireDurationType.seconds})
this.voteDurationType = VoteExpireDurationType.seconds,
this.noteCreationMode,
this.noteId})
: _replyTo = replyTo,
_files = files,
_voteContent = voteContent;
Expand Down Expand Up @@ -528,10 +556,14 @@ class _$_NoteCreate implements _NoteCreate {
@override
@JsonKey()
final VoteExpireDurationType voteDurationType;
@override
final NoteCreationMode? noteCreationMode;
@override
final String? noteId;

@override
String toString() {
return 'NoteCreate(account: $account, noteVisibility: $noteVisibility, localOnly: $localOnly, replyTo: $replyTo, files: $files, channel: $channel, reply: $reply, renote: $renote, reactionAcceptance: $reactionAcceptance, isCw: $isCw, cwText: $cwText, text: $text, isTextFocused: $isTextFocused, isNoteSending: $isNoteSending, isVote: $isVote, voteContent: $voteContent, voteContentCount: $voteContentCount, voteExpireType: $voteExpireType, isVoteMultiple: $isVoteMultiple, voteDate: $voteDate, voteDuration: $voteDuration, voteDurationType: $voteDurationType)';
return 'NoteCreate(account: $account, noteVisibility: $noteVisibility, localOnly: $localOnly, replyTo: $replyTo, files: $files, channel: $channel, reply: $reply, renote: $renote, reactionAcceptance: $reactionAcceptance, isCw: $isCw, cwText: $cwText, text: $text, isTextFocused: $isTextFocused, isNoteSending: $isNoteSending, isVote: $isVote, voteContent: $voteContent, voteContentCount: $voteContentCount, voteExpireType: $voteExpireType, isVoteMultiple: $isVoteMultiple, voteDate: $voteDate, voteDuration: $voteDuration, voteDurationType: $voteDurationType, noteCreationMode: $noteCreationMode, noteId: $noteId)';
}

@override
Expand Down Expand Up @@ -572,7 +604,10 @@ class _$_NoteCreate implements _NoteCreate {
(identical(other.voteDuration, voteDuration) ||
other.voteDuration == voteDuration) &&
(identical(other.voteDurationType, voteDurationType) ||
other.voteDurationType == voteDurationType));
other.voteDurationType == voteDurationType) &&
(identical(other.noteCreationMode, noteCreationMode) ||
other.noteCreationMode == noteCreationMode) &&
(identical(other.noteId, noteId) || other.noteId == noteId));
}

@override
Expand All @@ -599,7 +634,9 @@ class _$_NoteCreate implements _NoteCreate {
isVoteMultiple,
voteDate,
voteDuration,
voteDurationType
voteDurationType,
noteCreationMode,
noteId
]);

@JsonKey(ignore: true)
Expand Down Expand Up @@ -632,7 +669,9 @@ abstract class _NoteCreate implements NoteCreate {
final bool isVoteMultiple,
final DateTime? voteDate,
final int? voteDuration,
final VoteExpireDurationType voteDurationType}) = _$_NoteCreate;
final VoteExpireDurationType voteDurationType,
final NoteCreationMode? noteCreationMode,
final String? noteId}) = _$_NoteCreate;

@override
Account get account;
Expand Down Expand Up @@ -679,6 +718,10 @@ abstract class _NoteCreate implements NoteCreate {
@override
VoteExpireDurationType get voteDurationType;
@override
NoteCreationMode? get noteCreationMode;
@override
String? get noteId;
@override
@JsonKey(ignore: true)
_$$_NoteCreateCopyWith<_$_NoteCreate> get copyWith =>
throw _privateConstructorUsedError;
Expand Down
Loading