diff options
author | Patiga <dev@patiga.eu> | 2022-06-28 12:11:17 +0200 |
---|---|---|
committer | fiaxh <git@lightrise.org> | 2024-11-14 10:20:12 -0600 |
commit | aaf4542e6208460c305db4be36b15dc832ddc95a (patch) | |
tree | ec7b60b0f0ea74e21403788e8345336bd0f3939b /plugins/http-files/src/file_sender.vala | |
parent | 909f569318835d11703c49fba7dbe49996759f38 (diff) | |
download | dino-aaf4542e6208460c305db4be36b15dc832ddc95a.tar.gz dino-aaf4542e6208460c305db4be36b15dc832ddc95a.zip |
Implement XEP-0447: Stateless file sharing
Diffstat (limited to 'plugins/http-files/src/file_sender.vala')
-rw-r--r-- | plugins/http-files/src/file_sender.vala | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/plugins/http-files/src/file_sender.vala b/plugins/http-files/src/file_sender.vala index a2f4769b..91b50944 100644 --- a/plugins/http-files/src/file_sender.vala +++ b/plugins/http-files/src/file_sender.vala @@ -45,11 +45,38 @@ public class HttpFileSender : FileSender, Object { yield upload(file_transfer, send_data, file_meta); - Entities.Message message = stream_interactor.get_module(MessageProcessor.IDENTITY).create_out_message(send_data.url_down, conversation); - file_transfer.info = message.id.to_string(); - - message.encryption = send_data.encrypt_message ? conversation.encryption : Encryption.NONE; - stream_interactor.get_module(MessageProcessor.IDENTITY).send_xmpp_message(message, conversation); + if (send_data.encrypt_message && conversation.encryption != Encryption.NONE) { + Entities.Message message = stream_interactor.get_module(MessageProcessor.IDENTITY).create_out_message(send_data.url_down, conversation); + file_transfer.info = message.id.to_string(); + + message.encryption = conversation.encryption; + stream_interactor.get_module(MessageProcessor.IDENTITY).send_xmpp_message(message, conversation); + } else { + // Use stateless file sharing for unencrypted file sharing + Xep.StatelessFileSharing.HttpSource source = new Xep.StatelessFileSharing.HttpSource(); + source.url = send_data.url_down; + file_transfer.sfs_sources.append(new FileTransfer.SerializedSfsSource.from_sfs_source(source) as Object); + this.db.sfs_sources.insert() + .value(db.sfs_sources.id, file_transfer.id) + .value(db.sfs_sources.type, source.type()) + .value(db.sfs_sources.data, source.serialize()) + .perform(); + XmppStream stream = stream_interactor.get_stream(conversation.account); + Xep.StatelessFileSharing.Module sfs_module = stream.get_module(Xep.StatelessFileSharing.Module.IDENTITY); + string message_type; + if (conversation.type_ == Conversation.Type.GROUPCHAT) { + message_type = MessageStanza.TYPE_GROUPCHAT; + } else { + message_type = MessageStanza.TYPE_CHAT; + } + MessageStanza sfs_message = new MessageStanza() { to=conversation.counterpart, type_=message_type }; + // TODO: is this the correct way of adding out-of-band-data? + sfs_message.body = source.url; + Xep.OutOfBandData.add_url_to_message(sfs_message, source.url); + // TODO: message hint correct? + Xep.MessageProcessingHints.set_message_hint(sfs_message, Xep.MessageProcessingHints.HINT_STORE); + sfs_module.send_stateless_file_transfer(stream, sfs_message, yield file_transfer.to_sfs_element()); + } } public async bool can_send(Conversation conversation, FileTransfer file_transfer) { |