Compare commits
3 Commits
9765b200b9
...
8b3c45ab29
Author | SHA1 | Date | |
---|---|---|---|
8b3c45ab29 | |||
adb415700a | |||
1e4b44a78b |
@ -112,13 +112,14 @@ class PostEditorController extends GetxController {
|
||||
Future<void> editAttachment(BuildContext context) {
|
||||
return showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
builder: (context) => AttachmentEditorPopup(
|
||||
usage: 'i.attachment',
|
||||
current: attachments,
|
||||
onUpdate: (value) {
|
||||
attachments.value = value;
|
||||
attachments.refresh();
|
||||
initialAttachments: attachments,
|
||||
onAdd: (value) {
|
||||
attachments.add(value);
|
||||
},
|
||||
onRemove: (value) {
|
||||
attachments.remove(value);
|
||||
},
|
||||
),
|
||||
);
|
||||
@ -164,6 +165,8 @@ class PostEditorController extends GetxController {
|
||||
visibleUsers.clear();
|
||||
invisibleUsers.clear();
|
||||
visibility.value = 0;
|
||||
publishedAt.value = null;
|
||||
publishedUntil.value = null;
|
||||
isDraft.value = false;
|
||||
isRestoreFromLocal.value = false;
|
||||
lastSaveTime.value = null;
|
||||
|
@ -10,6 +10,7 @@ import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
import 'package:solian/bootstrapper.dart';
|
||||
import 'package:solian/firebase_options.dart';
|
||||
import 'package:solian/platform.dart';
|
||||
import 'package:solian/providers/attachment_uploader.dart';
|
||||
import 'package:solian/providers/theme_switcher.dart';
|
||||
import 'package:solian/providers/websocket.dart';
|
||||
import 'package:solian/providers/auth.dart';
|
||||
@ -125,5 +126,6 @@ class SolianApp extends StatelessWidget {
|
||||
Get.lazyPut(() => ChannelProvider());
|
||||
Get.lazyPut(() => RealmProvider());
|
||||
Get.lazyPut(() => ChatCallProvider());
|
||||
Get.lazyPut(() => AttachmentUploaderController());
|
||||
}
|
||||
}
|
||||
|
165
lib/providers/attachment_uploader.dart
Normal file
165
lib/providers/attachment_uploader.dart
Normal file
@ -0,0 +1,165 @@
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:get/get.dart';
|
||||
import 'package:solian/models/attachment.dart';
|
||||
import 'package:solian/providers/content/attachment.dart';
|
||||
|
||||
class AttachmentUploadTask {
|
||||
File file;
|
||||
String usage;
|
||||
Map<String, dynamic>? metadata;
|
||||
|
||||
double progress = 0;
|
||||
bool isUploading = false;
|
||||
bool isCompleted = false;
|
||||
|
||||
AttachmentUploadTask({
|
||||
required this.file,
|
||||
required this.usage,
|
||||
this.metadata,
|
||||
});
|
||||
}
|
||||
|
||||
class AttachmentUploaderController extends GetxController {
|
||||
RxBool isUploading = false.obs;
|
||||
RxDouble progressOfUpload = 0.0.obs;
|
||||
RxList<AttachmentUploadTask> queueOfUpload = RxList.empty(growable: true);
|
||||
|
||||
void enqueueTask(AttachmentUploadTask task) {
|
||||
if (isUploading.value) throw Exception('uploading blocked');
|
||||
queueOfUpload.add(task);
|
||||
}
|
||||
|
||||
void dequeueTask(AttachmentUploadTask task) {
|
||||
if (isUploading.value) throw Exception('uploading blocked');
|
||||
queueOfUpload.remove(task);
|
||||
}
|
||||
|
||||
Future<Attachment> performSingleTask(int queueIndex) async {
|
||||
isUploading.value = true;
|
||||
progressOfUpload.value = 0;
|
||||
|
||||
queueOfUpload[queueIndex].isUploading = true;
|
||||
queueOfUpload.refresh();
|
||||
|
||||
final task = queueOfUpload[queueIndex];
|
||||
final result = await _rawUploadAttachment(
|
||||
await task.file.readAsBytes(),
|
||||
task.file.path,
|
||||
task.usage,
|
||||
null,
|
||||
onProgress: (value) {
|
||||
queueOfUpload[queueIndex].progress = value;
|
||||
queueOfUpload.refresh();
|
||||
progressOfUpload.value = value;
|
||||
},
|
||||
);
|
||||
|
||||
queueOfUpload.removeAt(queueIndex);
|
||||
queueOfUpload.refresh();
|
||||
|
||||
isUploading.value = false;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<void> performUploadQueue({
|
||||
required Function(Attachment item) onData,
|
||||
}) async {
|
||||
isUploading.value = true;
|
||||
progressOfUpload.value = 0;
|
||||
|
||||
for (var idx = 0; idx < queueOfUpload.length; idx++) {
|
||||
queueOfUpload[idx].isUploading = true;
|
||||
queueOfUpload.refresh();
|
||||
|
||||
final task = queueOfUpload[idx];
|
||||
final result = await _rawUploadAttachment(
|
||||
await task.file.readAsBytes(),
|
||||
task.file.path,
|
||||
task.usage,
|
||||
null,
|
||||
onProgress: (value) {
|
||||
queueOfUpload[idx].progress = value;
|
||||
queueOfUpload.refresh();
|
||||
progressOfUpload.value = (idx + value) / queueOfUpload.length;
|
||||
},
|
||||
);
|
||||
progressOfUpload.value = (idx + 1) / queueOfUpload.length;
|
||||
onData(result);
|
||||
|
||||
queueOfUpload[idx].isUploading = false;
|
||||
queueOfUpload[idx].isCompleted = false;
|
||||
queueOfUpload.refresh();
|
||||
}
|
||||
|
||||
queueOfUpload.clear();
|
||||
queueOfUpload.refresh();
|
||||
isUploading.value = false;
|
||||
}
|
||||
|
||||
Future<void> uploadAttachmentWithCallback(
|
||||
Uint8List data,
|
||||
String path,
|
||||
String usage,
|
||||
Map<String, dynamic>? metadata,
|
||||
Function(Attachment) callback,
|
||||
) async {
|
||||
if (isUploading.value) throw Exception('uploading blocked');
|
||||
|
||||
isUploading.value = true;
|
||||
final result = await _rawUploadAttachment(
|
||||
data,
|
||||
path,
|
||||
usage,
|
||||
metadata,
|
||||
onProgress: (progress) {
|
||||
progressOfUpload.value = progress;
|
||||
},
|
||||
);
|
||||
isUploading.value = false;
|
||||
callback(result);
|
||||
}
|
||||
|
||||
Future<Attachment> uploadAttachment(
|
||||
Uint8List data,
|
||||
String path,
|
||||
String usage,
|
||||
Map<String, dynamic>? metadata,
|
||||
) async {
|
||||
if (isUploading.value) throw Exception('uploading blocked');
|
||||
|
||||
isUploading.value = true;
|
||||
final result = await _rawUploadAttachment(
|
||||
data,
|
||||
path,
|
||||
usage,
|
||||
metadata,
|
||||
onProgress: (progress) {
|
||||
progressOfUpload.value = progress;
|
||||
},
|
||||
);
|
||||
isUploading.value = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<Attachment> _rawUploadAttachment(
|
||||
Uint8List data, String path, String usage, Map<String, dynamic>? metadata,
|
||||
{Function(double)? onProgress}) async {
|
||||
final AttachmentProvider provider = Get.find();
|
||||
try {
|
||||
final resp = await provider.createAttachment(
|
||||
data,
|
||||
path,
|
||||
usage,
|
||||
metadata,
|
||||
onProgress: onProgress,
|
||||
);
|
||||
var result = Attachment.fromJson(resp.body);
|
||||
return result;
|
||||
} catch (err) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
}
|
@ -38,11 +38,8 @@ class AttachmentProvider extends GetConnect {
|
||||
}
|
||||
|
||||
Future<Response> createAttachment(
|
||||
Uint8List data,
|
||||
String path,
|
||||
String usage,
|
||||
Map<String, dynamic>? metadata,
|
||||
) async {
|
||||
Uint8List data, String path, String usage, Map<String, dynamic>? metadata,
|
||||
{Function(double)? onProgress}) async {
|
||||
final AuthProvider auth = Get.find();
|
||||
if (auth.isAuthorized.isFalse) throw Exception('unauthorized');
|
||||
|
||||
@ -71,7 +68,13 @@ class AttachmentProvider extends GetConnect {
|
||||
if (mimetypeOverride != null) 'mimetype': mimetypeOverride,
|
||||
'metadata': jsonEncode(metadata),
|
||||
});
|
||||
final resp = await client.post('/attachments', payload);
|
||||
final resp = await client.post(
|
||||
'/attachments',
|
||||
payload,
|
||||
uploadProgress: (progress) {
|
||||
if (onProgress != null) onProgress(progress);
|
||||
},
|
||||
);
|
||||
if (resp.statusCode != 200) {
|
||||
throw Exception(resp.bodyString);
|
||||
}
|
||||
|
@ -157,6 +157,11 @@ const i18nEnglish = {
|
||||
'reactCompleted': 'Your reaction has been added',
|
||||
'reactUncompleted': 'Your reaction has been removed',
|
||||
'attachmentUploadBy': 'Upload by',
|
||||
'attachmentAutoUpload': 'Auto Upload',
|
||||
'attachmentUploadQueue': 'Upload Queue',
|
||||
'attachmentUploadQueueStart': 'Start All',
|
||||
'attachmentAttached': 'Exists Files',
|
||||
'attachmentUploadBlocked': 'Upload blocked, there is currently a task in progress...',
|
||||
'attachmentAdd': 'Attach attachments',
|
||||
'attachmentAddGalleryPhoto': 'Gallery photo',
|
||||
'attachmentAddGalleryVideo': 'Gallery video',
|
||||
|
@ -146,6 +146,11 @@ const i18nSimplifiedChinese = {
|
||||
'reactCompleted': '你的反应已被添加',
|
||||
'reactUncompleted': '你的反应已被移除',
|
||||
'attachmentUploadBy': '由上传',
|
||||
'attachmentAutoUpload': '自动上传',
|
||||
'attachmentUploadQueue': '上传队列',
|
||||
'attachmentUploadQueueStart': '整队上传',
|
||||
'attachmentAttached': '已附附件',
|
||||
'attachmentUploadBlocked': '上传受阻,当前已有任务进行中……',
|
||||
'attachmentAdd': '附加附件',
|
||||
'attachmentAddGalleryPhoto': '相册照片',
|
||||
'attachmentAddGalleryVideo': '相册视频',
|
||||
|
132
lib/widgets/attachments/attachment_attr_editor.dart
Normal file
132
lib/widgets/attachments/attachment_attr_editor.dart
Normal file
@ -0,0 +1,132 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_animate/flutter_animate.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:solian/exts.dart';
|
||||
import 'package:solian/models/attachment.dart';
|
||||
import 'package:solian/providers/content/attachment.dart';
|
||||
|
||||
class AttachmentAttrEditorDialog extends StatefulWidget {
|
||||
final Attachment item;
|
||||
final Function(Attachment item) onUpdate;
|
||||
|
||||
const AttachmentAttrEditorDialog({
|
||||
super.key,
|
||||
required this.item,
|
||||
required this.onUpdate,
|
||||
});
|
||||
|
||||
@override
|
||||
State<AttachmentAttrEditorDialog> createState() => _AttachmentAttrEditorDialogState();
|
||||
}
|
||||
|
||||
class _AttachmentAttrEditorDialogState extends State<AttachmentAttrEditorDialog> {
|
||||
final _altController = TextEditingController();
|
||||
|
||||
bool _isBusy = false;
|
||||
bool _isMature = false;
|
||||
|
||||
Future<Attachment?> _updateAttachment() async {
|
||||
final AttachmentProvider provider = Get.find();
|
||||
|
||||
setState(() => _isBusy = true);
|
||||
try {
|
||||
final resp = await provider.updateAttachment(
|
||||
widget.item.id,
|
||||
_altController.value.text,
|
||||
widget.item.usage,
|
||||
isMature: _isMature,
|
||||
);
|
||||
|
||||
Get.find<AttachmentProvider>().clearCache(id: widget.item.id);
|
||||
|
||||
setState(() => _isBusy = false);
|
||||
return Attachment.fromJson(resp.body);
|
||||
} catch (e) {
|
||||
context.showErrorDialog(e);
|
||||
setState(() => _isBusy = false);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
void syncWidget() {
|
||||
_isMature = widget.item.isMature;
|
||||
_altController.text = widget.item.alt;
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
syncWidget();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text('attachmentSetting'.tr),
|
||||
content: Container(
|
||||
constraints: const BoxConstraints(minWidth: 400),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (_isBusy)
|
||||
ClipRRect(
|
||||
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
||||
child: const LinearProgressIndicator().animate().scaleX(),
|
||||
),
|
||||
const SizedBox(height: 18),
|
||||
TextField(
|
||||
controller: _altController,
|
||||
decoration: InputDecoration(
|
||||
isDense: true,
|
||||
prefixIcon: const Icon(Icons.image_not_supported),
|
||||
border: const OutlineInputBorder(),
|
||||
labelText: 'attachmentAlt'.tr,
|
||||
),
|
||||
onTapOutside: (_) =>
|
||||
FocusManager.instance.primaryFocus?.unfocus(),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
CheckboxListTile(
|
||||
contentPadding: const EdgeInsets.only(left: 4, right: 18),
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(10))),
|
||||
title: Text('matureContent'.tr),
|
||||
secondary: const Icon(Icons.visibility_off),
|
||||
value: _isMature,
|
||||
onChanged: (newValue) {
|
||||
setState(() => _isMature = newValue ?? false);
|
||||
},
|
||||
controlAffinity: ListTileControlAffinity.leading,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actionsAlignment: MainAxisAlignment.spaceBetween,
|
||||
actions: <Widget>[
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
TextButton(
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor:
|
||||
Theme.of(context).colorScheme.onSurfaceVariant),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: Text('cancel'.tr),
|
||||
),
|
||||
TextButton(
|
||||
child: Text('apply'.tr),
|
||||
onPressed: () {
|
||||
_updateAttachment().then((value) {
|
||||
if (value != null) {
|
||||
widget.onUpdate(value);
|
||||
Navigator.pop(context);
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -16,19 +16,18 @@ import 'package:solian/widgets/attachments/attachment_item.dart';
|
||||
import 'package:url_launcher/url_launcher_string.dart';
|
||||
import 'package:path/path.dart' show extension;
|
||||
|
||||
class AttachmentListFullScreen extends StatefulWidget {
|
||||
class AttachmentFullScreen extends StatefulWidget {
|
||||
final String parentId;
|
||||
final Attachment item;
|
||||
|
||||
const AttachmentListFullScreen(
|
||||
const AttachmentFullScreen(
|
||||
{super.key, required this.parentId, required this.item});
|
||||
|
||||
@override
|
||||
State<AttachmentListFullScreen> createState() =>
|
||||
_AttachmentListFullScreenState();
|
||||
State<AttachmentFullScreen> createState() => _AttachmentFullScreenState();
|
||||
}
|
||||
|
||||
class _AttachmentListFullScreenState extends State<AttachmentListFullScreen> {
|
||||
class _AttachmentFullScreenState extends State<AttachmentFullScreen> {
|
||||
bool _showDetails = true;
|
||||
|
||||
bool _isDownloading = false;
|
||||
@ -83,7 +82,7 @@ class _AttachmentListFullScreenState extends State<AttachmentListFullScreen> {
|
||||
setState(() => _isDownloading = true);
|
||||
|
||||
var extName = extension(widget.item.name);
|
||||
if(extName.isEmpty) extName = '.png';
|
||||
if (extName.isEmpty) extName = '.png';
|
||||
final imagePath =
|
||||
'${Directory.systemTemp.path}/${widget.item.uuid}$extName';
|
||||
await Dio().download(
|
@ -9,7 +9,7 @@ import 'package:get/get.dart';
|
||||
import 'package:solian/models/attachment.dart';
|
||||
import 'package:solian/widgets/attachments/attachment_item.dart';
|
||||
import 'package:solian/providers/content/attachment.dart';
|
||||
import 'package:solian/widgets/attachments/attachment_list_fullscreen.dart';
|
||||
import 'package:solian/widgets/attachments/attachment_fullscreen.dart';
|
||||
|
||||
class AttachmentList extends StatefulWidget {
|
||||
final String parentId;
|
||||
@ -320,7 +320,7 @@ class AttachmentListEntry extends StatelessWidget {
|
||||
onReveal(true);
|
||||
} else if (['image'].contains(item!.mimetype.split('/').first)) {
|
||||
context.pushTransparentRoute(
|
||||
AttachmentListFullScreen(
|
||||
AttachmentFullScreen(
|
||||
parentId: parentId,
|
||||
item: item!,
|
||||
),
|
||||
|
@ -112,7 +112,9 @@ class ChatEvent extends StatelessWidget {
|
||||
case 'messages.edit':
|
||||
return ChatEventMessageActionLog(
|
||||
icon: const Icon(Icons.edit_note, size: 16),
|
||||
text: 'messageEditDesc'.trParams({'id': '#${item.id}'}),
|
||||
text: 'messageEditDesc'.trParams({
|
||||
'id': '#${item.body['related_event']}',
|
||||
}),
|
||||
isMerged: isMerged,
|
||||
isHasMerged: isHasMerged,
|
||||
isQuote: isQuote,
|
||||
@ -120,7 +122,9 @@ class ChatEvent extends StatelessWidget {
|
||||
case 'messages.delete':
|
||||
return ChatEventMessageActionLog(
|
||||
icon: const Icon(Icons.cancel_schedule_send, size: 16),
|
||||
text: 'messageDeleteDesc'.trParams({'id': '#${item.id}'}),
|
||||
text: 'messageDeleteDesc'.trParams({
|
||||
'id': '#${item.body['related_event']}',
|
||||
}),
|
||||
isMerged: isMerged,
|
||||
isHasMerged: isHasMerged,
|
||||
isQuote: isQuote,
|
||||
|
@ -38,7 +38,7 @@ class _ChatMessageInputState extends State<ChatMessageInput> {
|
||||
final TextEditingController _textController = TextEditingController();
|
||||
final FocusNode _focusNode = FocusNode();
|
||||
|
||||
List<int> _attachments = List.empty(growable: true);
|
||||
final List<int> _attachments = List.empty(growable: true);
|
||||
|
||||
Event? _editTo;
|
||||
Event? _replyTo;
|
||||
@ -46,11 +46,19 @@ class _ChatMessageInputState extends State<ChatMessageInput> {
|
||||
void _editAttachments() {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
builder: (context) => AttachmentEditorPopup(
|
||||
usage: 'm.attachment',
|
||||
current: _attachments,
|
||||
onUpdate: (value) => _attachments = value,
|
||||
initialAttachments: _attachments,
|
||||
onAdd: (value) {
|
||||
setState(() {
|
||||
_attachments.add(value);
|
||||
});
|
||||
},
|
||||
onRemove: (value) {
|
||||
setState(() {
|
||||
_attachments.remove(value);
|
||||
});
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user