aboutsummaryrefslogtreecommitdiff
path: root/plugins/http-files
diff options
context:
space:
mode:
authorfiaxh <git@mx.ax.lt>2017-09-26 17:01:06 +0200
committerfiaxh <git@mx.ax.lt>2017-09-26 17:01:06 +0200
commit9d8e1e88ec61403659a8cc410d5c4414e3bd3a96 (patch)
tree40f1014b7511fd5951035cb706f06d4daa2a42f0 /plugins/http-files
parent54a25fd926070a977138cec94908c55806e22f4a (diff)
downloaddino-9d8e1e88ec61403659a8cc410d5c4414e3bd3a96.tar.gz
dino-9d8e1e88ec61403659a8cc410d5c4414e3bd3a96.zip
http-files: max-file-size handling
Diffstat (limited to 'plugins/http-files')
-rw-r--r--plugins/http-files/src/contact_titlebar_entry.vala4
-rw-r--r--plugins/http-files/src/file_provider.vala9
-rw-r--r--plugins/http-files/src/manager.vala4
-rw-r--r--plugins/http-files/src/upload_stream_module.vala10
4 files changed, 14 insertions, 13 deletions
diff --git a/plugins/http-files/src/contact_titlebar_entry.vala b/plugins/http-files/src/contact_titlebar_entry.vala
index 3fd8ee39..e5b82abe 100644
--- a/plugins/http-files/src/contact_titlebar_entry.vala
+++ b/plugins/http-files/src/contact_titlebar_entry.vala
@@ -38,8 +38,8 @@ public class ConversationTitlebarWidget : Button, Plugins.ConversationTitlebarWi
FileChooserNative chooser = new FileChooserNative (
"Select file", get_toplevel() as Window, FileChooserAction.OPEN,
"Select", "Cancel");
- int? max_file_size = stream_interactor.get_module(Manager.IDENTITY).get_max_file_size(conversation.account);
- if (max_file_size != null) {
+ long max_file_size = stream_interactor.get_module(Manager.IDENTITY).get_max_file_size(conversation.account);
+ if (max_file_size != -1) {
FileFilter filter = new FileFilter();
filter.add_custom(FileFilterFlags.URI, (filter_info) => {
File file = File.new_for_uri(filter_info.uri);
diff --git a/plugins/http-files/src/file_provider.vala b/plugins/http-files/src/file_provider.vala
index b4a69ddb..69ae9218 100644
--- a/plugins/http-files/src/file_provider.vala
+++ b/plugins/http-files/src/file_provider.vala
@@ -36,7 +36,8 @@ public class FileProvider : Plugins.FileProvider, Object {
public void check_message(Message message, Conversation conversation) {
if (ignore_once.remove(message.body)) return;
- bool in_roster = stream_interactor.get_module(RosterManager.IDENTITY).get_roster_item(conversation.account, conversation.counterpart) != null;
+ Jid relevant_jid = stream_interactor.get_module(MucManager.IDENTITY).get_real_jid(message.from, conversation.account) ?? conversation.counterpart;
+ bool in_roster = stream_interactor.get_module(RosterManager.IDENTITY).get_roster_item(conversation.account, relevant_jid) != null;
if (message.direction == Message.DIRECTION_RECEIVED && !in_roster) return;
if (message.body.length < 5) return;
if (!url_regex.match(message.body)) return;
@@ -57,11 +58,11 @@ public class FileProvider : Plugins.FileProvider, Object {
Soup.Request request = session.request (message.body);
FileTransfer file_transfer = new FileTransfer();
file_transfer.account = conversation.account;
- file_transfer.counterpart = conversation.counterpart;
+ file_transfer.counterpart = message.counterpart;
file_transfer.ourpart = message.ourpart;
file_transfer.encryption = Encryption.NONE;
- file_transfer.time = new DateTime.now_utc();
- file_transfer.local_time = new DateTime.now_utc();
+ file_transfer.time = message.time;
+ file_transfer.local_time = message.local_time;
file_transfer.direction = message.direction;
file_transfer.input_stream = request.send();
file_transfer.file_name = message.body.substring(message.body.last_index_of("/") + 1);
diff --git a/plugins/http-files/src/manager.vala b/plugins/http-files/src/manager.vala
index 14c190af..b1b7296c 100644
--- a/plugins/http-files/src/manager.vala
+++ b/plugins/http-files/src/manager.vala
@@ -13,7 +13,7 @@ public class Manager : StreamInteractionModule, Object {
public signal void uploaded(FileTransfer file_transfer, string url);
private StreamInteractor stream_interactor;
- private HashMap<Account, int?> max_file_sizes = new HashMap<Account, int?>(Account.hash_func, Account.equals_func);
+ private HashMap<Account, long> max_file_sizes = new HashMap<Account, long>(Account.hash_func, Account.equals_func);
private Manager(StreamInteractor stream_interactor) {
this.stream_interactor = stream_interactor;
@@ -60,7 +60,7 @@ public class Manager : StreamInteractionModule, Object {
}
}
- public int? get_max_file_size(Account account) {
+ public long get_max_file_size(Account account) {
lock (max_file_sizes) {
return max_file_sizes[account];
}
diff --git a/plugins/http-files/src/upload_stream_module.vala b/plugins/http-files/src/upload_stream_module.vala
index db2e655b..c4fa3d2f 100644
--- a/plugins/http-files/src/upload_stream_module.vala
+++ b/plugins/http-files/src/upload_stream_module.vala
@@ -10,7 +10,7 @@ private const string NS_URI_0 = "urn:xmpp:http:upload:0";
public class UploadStreamModule : XmppStreamModule {
public static Core.ModuleIdentity<UploadStreamModule> IDENTITY = new Core.ModuleIdentity<UploadStreamModule>(NS_URI, "0363_http_file_upload");
- public signal void feature_available(XmppStream stream, int? max_file_size);
+ public signal void feature_available(XmppStream stream, long max_file_size);
public delegate void OnUploadOk(XmppStream stream, string url_down);
public delegate void OnError(XmppStream stream, string error);
@@ -122,7 +122,7 @@ public class UploadStreamModule : XmppStreamModule {
}
if (ver_available || ver_0_available) {
- int? max_file_size = extract_max_file_size(info_result);
+ long max_file_size = extract_max_file_size(info_result);
if (ver_0_available) {
stream.add_flag(new Flag(jid, NS_URI_0));
} else if (ver_available) {
@@ -135,7 +135,7 @@ public class UploadStreamModule : XmppStreamModule {
return false;
}
- private int? extract_max_file_size(Xep.ServiceDiscovery.InfoResult info_result) {
+ private long extract_max_file_size(Xep.ServiceDiscovery.InfoResult info_result) {
string? max_file_size_str = null;
StanzaNode x_node = info_result.iq.stanza.get_deep_subnode("http://jabber.org/protocol/disco#info:query", "jabber:x:data:x");
Gee.List<StanzaNode> field_nodes = x_node.get_subnodes("field", "jabber:x:data");
@@ -147,8 +147,8 @@ public class UploadStreamModule : XmppStreamModule {
break;
}
}
- if (max_file_size_str != null) return int.parse(max_file_size_str);
- return null;
+ if (max_file_size_str != null) return long.parse(max_file_size_str);
+ return -1;
}
}