aboutsummaryrefslogtreecommitdiff
path: root/plugins/http-files/src/manager.vala
diff options
context:
space:
mode:
authorfiaxh <git@mx.ax.lt>2017-08-02 17:29:55 +0200
committerfiaxh <git@mx.ax.lt>2017-08-03 15:59:04 +0200
commitea174ab632ced082eb0f1c51cea1bc9dc5c7c89e (patch)
tree8f83d1379a48e7aa49af5a5146d76a4c595f2363 /plugins/http-files/src/manager.vala
parentf83e1188c5dcf1981832f296203f94503b467e30 (diff)
downloaddino-ea174ab632ced082eb0f1c51cea1bc9dc5c7c89e.tar.gz
dino-ea174ab632ced082eb0f1c51cea1bc9dc5c7c89e.zip
Http file upload
Diffstat (limited to 'plugins/http-files/src/manager.vala')
-rw-r--r--plugins/http-files/src/manager.vala56
1 files changed, 56 insertions, 0 deletions
diff --git a/plugins/http-files/src/manager.vala b/plugins/http-files/src/manager.vala
new file mode 100644
index 00000000..5b804a00
--- /dev/null
+++ b/plugins/http-files/src/manager.vala
@@ -0,0 +1,56 @@
+using Dino.Entities;
+using Xmpp;
+using Gee;
+
+namespace Dino.Plugins.HttpFiles {
+
+public class Manager : StreamInteractionModule, Object {
+ public static ModuleIdentity<Manager> IDENTITY = new ModuleIdentity<Manager>("http_files");
+ public string id { get { return IDENTITY.id; } }
+
+ public signal void upload_available(Account account);
+
+ private StreamInteractor stream_interactor;
+ private HashMap<Account, int?> max_file_sizes = new HashMap<Account, int?>(Account.hash_func, Account.equals_func);
+
+ private Manager(StreamInteractor stream_interactor) {
+ this.stream_interactor = stream_interactor;
+
+ stream_interactor.stream_negotiated.connect(on_stream_negotiated);
+ }
+
+ public void send(Conversation conversation, string file_uri) {
+ Xmpp.Core.XmppStream? stream = stream_interactor.get_stream(conversation.account);
+ if (stream != null) {
+ stream_interactor.module_manager.get_module(conversation.account, UploadStreamModule.IDENTITY).upload(stream, file_uri,
+ (stream, url_down) => {
+ stream_interactor.get_module(MessageProcessor.IDENTITY).send_message(url_down, conversation);
+ },
+ () => {}
+ );
+
+ }
+ }
+
+ public bool is_upload_available(Account account) {
+ return max_file_sizes.has_key(account);
+ }
+
+ public int? get_max_file_size(Account account) {
+ return max_file_sizes[account];
+ }
+
+ private void on_stream_negotiated(Account account, Core.XmppStream stream) {
+ stream_interactor.module_manager.get_module(account, UploadStreamModule.IDENTITY).feature_available.connect((stream, max_file_size) => {
+ max_file_sizes[account] = max_file_size;
+ upload_available(account);
+ });
+ }
+
+ public static void start(StreamInteractor stream_interactor) {
+ Manager m = new Manager(stream_interactor);
+ stream_interactor.add_module(m);
+ }
+}
+
+}