diff --git a/lib/state_notifier/note_create_page/note_create_state_notifier.dart b/lib/state_notifier/note_create_page/note_create_state_notifier.dart index 07a888918..529421e97 100644 --- a/lib/state_notifier/note_create_page/note_create_state_notifier.dart +++ b/lib/state_notifier/note_create_page/note_create_state_notifier.dart @@ -246,50 +246,13 @@ class NoteCreateNotifier extends StateNotifier { throw SpecifiedException("投票期間を入れてや"); } + if (state.files.length > 16) { + throw SpecifiedException("ファイルは16個以下にしてください"); + } + try { state = state.copyWith(isNoteSending: NoteSendStatus.sending); - final fileIds = []; - - for (final file in state.files) { - switch (file) { - case PostFile(): - Uint8List contents = await file.file.readAsBytes(); - if (["image/jpeg", "image/tiff"].contains(file.type)) { - try { - contents = - await FlutterImageCompress.compressWithList(contents); - } catch (e) { - debugPrint("failed to compress file"); - } - } - final response = await misskey.drive.files.createAsBinary( - DriveFilesCreateRequest( - force: true, - name: file.fileName, - isSensitive: file.isNsfw, - comment: file.caption, - ), - contents, - ); - fileIds.add(response.id); - case AlreadyPostedFile(): - if (file.isEdited) { - await misskey.drive.files.update( - DriveFilesUpdateRequest( - fileId: file.file.id, - name: file.fileName, - isSensitive: file.isNsfw, - comment: file.caption, - ), - ); - } - fileIds.add(file.file.id); - } - } - - if (!mounted) return; - final nodes = const MfmParser().parse(state.text); final userList = []; @@ -312,6 +275,45 @@ class NoteCreateNotifier extends StateNotifier { throw SpecifiedException("連合オフやのによそのサーバーの人がメンションに含まれてるで"); } + final fileIds = await Future.wait( + state.files.map((file) async { + switch (file) { + case PostFile(): + Uint8List contents = await file.file.readAsBytes(); + if (["image/jpeg", "image/tiff"].contains(file.type)) { + try { + contents = + await FlutterImageCompress.compressWithList(contents); + } catch (e) { + debugPrint("failed to compress file"); + } + } + final response = await misskey.drive.files.createAsBinary( + DriveFilesCreateRequest( + force: true, + name: file.fileName, + isSensitive: file.isNsfw, + comment: file.caption, + ), + contents, + ); + return response.id; + case AlreadyPostedFile(): + if (file.isEdited) { + await misskey.drive.files.update( + DriveFilesUpdateRequest( + fileId: file.file.id, + name: file.fileName, + isSensitive: file.isNsfw, + comment: file.caption, + ), + ); + } + return file.file.id; + } + }), + ); + final mentionTargetUsers = [ for (final user in userList) await misskey.users.showByName(UsersShowByUserNameRequest(