aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorfiaxh <git@mx.ax.lt>2017-12-11 18:39:55 +0100
committerfiaxh <git@mx.ax.lt>2017-12-13 21:11:33 +0100
commitf25fadde2d6c9492b9cafe2cddbcc7b966942e47 (patch)
tree84b25287be10372933e2ea4f708231e9ec5e142a /plugins
parentfc0d7feb5aef16e0024cfeb73286038998e926d2 (diff)
downloaddino-f25fadde2d6c9492b9cafe2cddbcc7b966942e47.tar.gz
dino-f25fadde2d6c9492b9cafe2cddbcc7b966942e47.zip
Fallback display for all file types
Diffstat (limited to 'plugins')
-rw-r--r--plugins/http-files/src/file_provider.vala25
1 files changed, 19 insertions, 6 deletions
diff --git a/plugins/http-files/src/file_provider.vala b/plugins/http-files/src/file_provider.vala
index aa8a6357..21d833eb 100644
--- a/plugins/http-files/src/file_provider.vala
+++ b/plugins/http-files/src/file_provider.vala
@@ -17,25 +17,38 @@ public class FileProvider : Dino.FileProvider, Object {
public FileProvider(StreamInteractor stream_interactor, Dino.Database dino_db) {
this.stream_interactor = stream_interactor;
this.url_regex = new Regex("""^(?i)\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))$""");
- this.file_ext_regex = new Regex("""\.(png|jpg|jpeg|svg|gif|pgp)""");
+ this.file_ext_regex = new Regex("""\.(png|jpg|jpeg|svg|gif|pgp)$""");
- stream_interactor.get_module(MessageProcessor.IDENTITY).message_received.connect(check_message);
- stream_interactor.get_module(MessageProcessor.IDENTITY).message_sent.connect(check_message);
+ stream_interactor.get_module(MessageProcessor.IDENTITY).message_received.connect(check_in_message);
+ stream_interactor.get_module(MessageProcessor.IDENTITY).message_sent.connect(check_out_message);
stream_interactor.get_module(Manager.IDENTITY).uploaded.connect((file_transfer, url) => {
file_transfer.info = url;
ignore_once.add(url);
});
}
- public void check_message(Message message, Conversation conversation) {
- if (ignore_once.remove(message.body)) return;
+ private void check_in_message(Message message, Conversation conversation) {
+ if (!url_regex.match(message.body)) return;
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;
+
+ string? oob_url = Xmpp.Xep.OutOfBandData.get_url_from_message(message.stanza);
+ if ((oob_url != null && oob_url == message.body) || file_ext_regex.match(message.body)) {
+ download_url(message, conversation);
+ }
+ }
+
+ public void check_out_message(Message message, Conversation conversation) {
+ if (ignore_once.remove(message.body)) return;
if (message.body.length < 5) return;
if (!url_regex.match(message.body)) return;
if (!file_ext_regex.match(message.body)) return;
+ download_url(message, conversation);
+ }
+
+ private void download_url(Message message, Conversation conversation) {
var session = new Soup.Session();
var head_message = new Soup.Message("HEAD", message.body);
if (head_message != null) {
@@ -47,7 +60,7 @@ public class FileProvider : Dino.FileProvider, Object {
if (name == "Content-Type") content_type = val;
if (name == "Content-Length") content_length = val;
});
- if (/*content_type != null && content_type.has_prefix("image") &&*/ content_length != null && int.parse(content_length) < 5000000) {
+ if (content_length != null && int.parse(content_length) < 5000000) {
FileTransfer file_transfer = new FileTransfer();
Soup.Request request = session.request(message.body);
request.send_async.begin(null, (obj, res) => {