Add oob tag to http-upload messages

fixes #166
This commit is contained in:
fiaxh 2017-10-22 17:24:16 +02:00
parent 128a015d45
commit 749edd21b9
5 changed files with 34 additions and 13 deletions

View file

@ -11,7 +11,7 @@ public class MessageProcessor : StreamInteractionModule, Object {
public signal void pre_message_received(Entities.Message message, Xmpp.Message.Stanza message_stanza, Conversation conversation);
public signal void message_received(Entities.Message message, Conversation conversation);
public signal void out_message_created(Entities.Message message, Conversation conversation);
public signal void build_message_stanza(Entities.Message message, Xmpp.Message.Stanza message_stanza, Conversation conversation);
public signal void pre_message_send(Entities.Message message, Xmpp.Message.Stanza message_stanza, Conversation conversation);
public signal void message_sent(Entities.Message message, Conversation conversation);
@ -175,8 +175,6 @@ public class MessageProcessor : StreamInteractionModule, Object {
}
message.marked = Entities.Message.Marked.UNSENT;
message.encryption = conversation.encryption;
out_message_created(message, conversation);
return message;
}
@ -193,6 +191,7 @@ public class MessageProcessor : StreamInteractionModule, Object {
} else {
new_message.type_ = Xmpp.Message.Stanza.TYPE_CHAT;
}
build_message_stanza(message, new_message, conversation);
pre_message_send(message, new_message, conversation);
if (message.marked == Entities.Message.Marked.UNSENT || message.marked == Entities.Message.Marked.WONTSEND) return;
if (delayed) {

View file

@ -12,12 +12,21 @@ public class Manager : StreamInteractionModule, FileSender, Object {
public signal void uploaded(FileTransfer file_transfer, string url);
private StreamInteractor stream_interactor;
private Database db;
private HashMap<Account, long> max_file_sizes = new HashMap<Account, long>(Account.hash_func, Account.equals_func);
private Manager(StreamInteractor stream_interactor) {
public static void start(StreamInteractor stream_interactor, Database db) {
Manager m = new Manager(stream_interactor, db);
stream_interactor.add_module(m);
}
private Manager(StreamInteractor stream_interactor, Database db) {
this.stream_interactor = stream_interactor;
this.db = db;
stream_interactor.get_module(FileManager.IDENTITY).add_sender(this);
stream_interactor.stream_negotiated.connect(on_stream_negotiated);
stream_interactor.get_module(MessageProcessor.IDENTITY).build_message_stanza.connect(check_add_oob);
}
public void send_file(Conversation conversation, FileTransfer file_transfer) {
@ -60,9 +69,10 @@ public class Manager : StreamInteractionModule, FileSender, Object {
});
}
public static void start(StreamInteractor stream_interactor) {
Manager m = new Manager(stream_interactor);
stream_interactor.add_module(m);
private void check_add_oob(Entities.Message message, Xmpp.Message.Stanza message_stanza, Conversation conversation) {
if (message_is_file(db, message)) {
Xep.OutOfBandData.add_url_to_message(message_stanza, message_stanza.body);
}
}
}
@ -77,20 +87,20 @@ public class FileMessageFilterDisplay : Plugins.MessageDisplayProvider, Object {
}
public bool can_display(Entities.Message? message) {
return message_is_file(message);
return message_is_file(db, message);
}
public Plugins.MetaConversationItem? get_item(Entities.Message message, Conversation conversation) {
return null;
}
}
private bool message_is_file(Entities.Message message) {
private bool message_is_file(Database db, Entities.Message message) {
Qlite.QueryBuilder builder = db.file_transfer.select()
.with(db.file_transfer.info, "=", message.body)
.with(db.file_transfer.account_id, "=", message.account.id)
.with(db.file_transfer.counterpart_id, "=", db.get_jid_id(message.counterpart));
return builder.count() > 0;
}
}
}

View file

@ -11,7 +11,7 @@ public class Plugin : RootInterface, Object {
public void registered(Dino.Application app) {
try {
this.app = app;
Manager.start(this.app.stream_interactor);
Manager.start(this.app.stream_interactor, app.db);
file_provider = new FileProvider(app.stream_interactor, app.db);

View file

@ -51,6 +51,7 @@ SOURCES
"src/module/xep/0049_private_xml_storage.vala"
"src/module/xep/0054_vcard/module.vala"
"src/module/xep/0060_pubsub.vala"
"src/module/xep/0066_out_of_band_data.vala"
"src/module/xep/0082_date_time_profiles.vala"
"src/module/xep/0084_user_avatars.vala"
"src/module/xep/0085_chat_state_notifications.vala"

View file

@ -0,0 +1,11 @@
using Xmpp.Core;
namespace Xmpp.Xep.OutOfBandData {
public const string NS_URI = "jabber:x:oob";
public static void add_url_to_message(Message.Stanza message, string url, string? desc = null) {
message.stanza.put_node(new StanzaNode.build("x", NS_URI).add_self_xmlns().put_node(new StanzaNode.build("url", NS_URI).put_node(new StanzaNode.text(url))));
}
}