aboutsummaryrefslogtreecommitdiff
path: root/libdino/src
diff options
context:
space:
mode:
Diffstat (limited to 'libdino/src')
-rw-r--r--libdino/src/service/message_processor.vala47
1 files changed, 29 insertions, 18 deletions
diff --git a/libdino/src/service/message_processor.vala b/libdino/src/service/message_processor.vala
index d8a25da1..697eae4c 100644
--- a/libdino/src/service/message_processor.vala
+++ b/libdino/src/service/message_processor.vala
@@ -35,6 +35,7 @@ public class MessageProcessor : StreamInteractionModule, Object {
received_pipeline.connect(new DeduplicateMessageListener(db));
received_pipeline.connect(new StoreMessageListener(stream_interactor));
received_pipeline.connect(new MamMessageListener(stream_interactor));
+ received_pipeline.connect(new SlackMessageListener());
}
public Entities.Message send_text(string text, Conversation conversation) {
@@ -73,7 +74,6 @@ public class MessageProcessor : StreamInteractionModule, Object {
if (message_stanza.body == null) return;
Entities.Message message = yield create_in_message(account, message_stanza);
- if (message == null) return;
Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation_for_message(message);
if (conversation != null) {
@@ -101,23 +101,6 @@ public class MessageProcessor : StreamInteractionModule, Object {
new_message.ourpart = new_message.direction == Entities.Message.DIRECTION_SENT ? message.from : message.to;
new_message.stanza = message;
- // Slack non-standard behavior
- if (account.domainpart.index_of("xmpp.slack.com") == account.domainpart.length - 14) {
- if (new_message.counterpart.equals_bare(account.bare_jid)) {
- // Ignore messages from us, because we neither know which conversation they belong to, nor can match
- // them to one of our send messages because of timestamp mismatches.
- return null;
- }
- if (new_message.direction == Entities.Message.DIRECTION_RECEIVED && message.type_ == "chat" && new_message.body.index_of("["+account.localpart+"] ") == 0) {
- // That is the best thing we can do, although allowing for attacks.
- new_message.direction = Entities.Message.DIRECTION_SENT;
- new_message.body = new_message.body.substring(account.localpart.length + 3);
- }
- if (message.stanza.get_attribute("ts") != null) {
- new_message.time = new DateTime.from_unix_utc((int64) double.parse(message.stanza.get_attribute("ts")));
- }
- }
-
Xep.MessageArchiveManagement.MessageFlag? mam_message_flag = Xep.MessageArchiveManagement.MessageFlag.get_flag(message);
if (mam_message_flag != null) new_message.local_time = mam_message_flag.server_time;
if (new_message.local_time == null || new_message.local_time.compare(new DateTime.now_utc()) > 0) new_message.local_time = new DateTime.now_utc();
@@ -229,6 +212,34 @@ public class MessageProcessor : StreamInteractionModule, Object {
}
}
+ private class SlackMessageListener : MessageListener {
+
+ public string[] after_actions_const = new string[]{ "DEDUPLICATE" };
+ public override string action_group { get { return "SLACK"; } }
+ public override string[] after_actions { get { return after_actions_const; } }
+
+ public override async bool run(Entities.Message message, Xmpp.MessageStanza stanza, Conversation conversation) {
+ // Slack non-standard behavior
+ Account account = conversation.account;
+ if (account.domainpart.index_of("xmpp.slack.com") == account.domainpart.length - 14) {
+ if (message.counterpart.equals_bare(account.bare_jid)) {
+ // Ignore messages from us, because we neither know which conversation they belong to, nor can match
+ // them to one of our send messages because of timestamp mismatches.
+ return true;
+ }
+ if (message.direction == Entities.Message.DIRECTION_RECEIVED && stanza.type_ == "chat" && message.body.index_of("["+account.localpart+"] ") == 0) {
+ // That is the best thing we can do, although allowing for attacks.
+ message.direction = Entities.Message.DIRECTION_SENT;
+ message.body = message.body.substring(account.localpart.length + 3);
+ }
+ if (stanza.stanza.get_attribute("ts") != null) {
+ message.time = new DateTime.from_unix_utc((int64) double.parse(stanza.stanza.get_attribute("ts")));
+ }
+ }
+ return false;
+ }
+ }
+
public Entities.Message create_out_message(string text, Conversation conversation) {
Entities.Message message = new Entities.Message(text);
message.type_ = Util.get_message_type_for_conversation(conversation);