From 51a23728694a3f1312cc9396fc093ca178457c3c Mon Sep 17 00:00:00 2001 From: fiaxh Date: Wed, 22 Apr 2020 15:44:12 +0200 Subject: Add file upload preview fixes #756 --- libdino/src/service/file_manager.vala | 12 ++++++++++-- libdino/src/service/jingle_file_transfers.vala | 11 +++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) (limited to 'libdino') diff --git a/libdino/src/service/file_manager.vala b/libdino/src/service/file_manager.vala index 20540e6e..00abe517 100644 --- a/libdino/src/service/file_manager.vala +++ b/libdino/src/service/file_manager.vala @@ -38,7 +38,15 @@ public class FileManager : StreamInteractionModule, Object { this.add_sender(new JingleFileSender(stream_interactor)); } - public async void send_file(string uri, Conversation conversation) { + public HashMap get_file_size_limits(Conversation conversation) { + HashMap ret = new HashMap(); + foreach (FileSender sender in file_senders) { + ret[sender.get_id()] = sender.get_file_size_limit(conversation); + } + return ret; + } + + public async void send_file(File file, Conversation conversation) { FileTransfer file_transfer = new FileTransfer(); file_transfer.account = conversation.account; file_transfer.counterpart = conversation.counterpart; @@ -53,7 +61,6 @@ public class FileManager : StreamInteractionModule, Object { file_transfer.encryption = conversation.encryption; try { - File file = File.new_for_path(uri); FileInfo file_info = file.query_info("*", FileQueryInfoFlags.NONE); file_transfer.file_name = file_info.get_display_name(); file_transfer.mime_type = file_info.get_content_type(); @@ -394,6 +401,7 @@ public interface FileSender : Object { public signal void upload_available(Account account); public abstract bool is_upload_available(Conversation conversation); + public abstract long get_file_size_limit(Conversation conversation); public abstract bool can_send(Conversation conversation, FileTransfer file_transfer); public abstract async FileSendData? prepare_send_file(Conversation conversation, FileTransfer file_transfer, FileMeta file_meta) throws FileSendError; public abstract async void send_file(Conversation conversation, FileTransfer file_transfer, FileSendData file_send_data, FileMeta file_meta) throws FileSendError; diff --git a/libdino/src/service/jingle_file_transfers.vala b/libdino/src/service/jingle_file_transfers.vala index 3a5fa95e..4c3646b3 100644 --- a/libdino/src/service/jingle_file_transfers.vala +++ b/libdino/src/service/jingle_file_transfers.vala @@ -164,7 +164,18 @@ public class JingleFileSender : FileSender, Object { return false; } + public long get_file_size_limit(Conversation conversation) { + if (can_send_(conversation)) { + return int.MAX; + } + return -1; + } + public bool can_send(Conversation conversation, FileTransfer file_transfer) { + return can_send_(conversation); + } + + private bool can_send_(Conversation conversation) { if (conversation.type_ != Conversation.Type.CHAT) return false; // No file specific restrictions apply to Jingle file transfers -- cgit v1.2.3-70-g09d2