forked from Nexus/nexus
add support for sending media
Still needs camera support.
This commit is contained in:
parent
a8285548e8
commit
c4f63d18b5
13 changed files with 303 additions and 122 deletions
41
lib/controllers/attachment.dart
Normal file
41
lib/controllers/attachment.dart
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import "package:file_selector/file_selector.dart";
|
||||
import "package:flutter_riverpod/flutter_riverpod.dart";
|
||||
import "package:nexus/controllers/client.dart";
|
||||
import "package:nexus/controllers/rooms.dart";
|
||||
import "package:nexus/models/content/content.dart";
|
||||
import "package:nexus/models/content/message.dart";
|
||||
import "package:path/path.dart";
|
||||
|
||||
class AttachmentController extends Notifier<(String, MessageContent?)?> {
|
||||
final String roomId;
|
||||
AttachmentController(this.roomId);
|
||||
|
||||
@override
|
||||
Null build() => null;
|
||||
|
||||
Future<void> add(XFile file) async {
|
||||
final filename = basename(file.path);
|
||||
state = (filename, null);
|
||||
|
||||
final room = ref.watch(
|
||||
RoomsController.provider.select((value) => value[roomId]),
|
||||
);
|
||||
|
||||
final content = await ref
|
||||
.watch(ClientController.provider.notifier)
|
||||
.uploadMedia(
|
||||
.new(
|
||||
path: file.path,
|
||||
encrypted:
|
||||
room?.state[EventType.encryption.name]?.isNotEmpty == true,
|
||||
),
|
||||
);
|
||||
|
||||
state = (filename, content);
|
||||
}
|
||||
|
||||
static final provider = NotifierProvider.family
|
||||
.autoDispose<AttachmentController, (String, MessageContent?)?, String>(
|
||||
AttachmentController.new,
|
||||
);
|
||||
}
|
||||
Loading…
Reference in a new issue