aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala/src/module/xep/0280_message_carbons.vala
diff options
context:
space:
mode:
authorMarvin W <git@larma.de>2018-01-12 21:03:09 +0100
committerfiaxh <git@mx.ax.lt>2018-01-28 00:38:47 +0100
commit782ae4c049e2b6fab13d7453cbb0e74610e7d200 (patch)
tree1b4cd0a1689cee0c2e2cac2ae9a5fb8ebbe63621 /xmpp-vala/src/module/xep/0280_message_carbons.vala
parentd46d071e57e599e8cfb1780597cbecb36881c4d8 (diff)
downloaddino-782ae4c049e2b6fab13d7453cbb0e74610e7d200.tar.gz
dino-782ae4c049e2b6fab13d7453cbb0e74610e7d200.zip
Move Jid class to xmpp-vala, partially refactor namespace
Diffstat (limited to 'xmpp-vala/src/module/xep/0280_message_carbons.vala')
-rw-r--r--xmpp-vala/src/module/xep/0280_message_carbons.vala96
1 files changed, 53 insertions, 43 deletions
diff --git a/xmpp-vala/src/module/xep/0280_message_carbons.vala b/xmpp-vala/src/module/xep/0280_message_carbons.vala
index 8dc4e00c..9e85a607 100644
--- a/xmpp-vala/src/module/xep/0280_message_carbons.vala
+++ b/xmpp-vala/src/module/xep/0280_message_carbons.vala
@@ -1,56 +1,60 @@
-using Xmpp.Core;
-
namespace Xmpp.Xep.MessageCarbons {
- private const string NS_URI = "urn:xmpp:carbons:2";
- public class Module : XmppStreamModule {
- public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0280_message_carbons_module");
+private const string NS_URI = "urn:xmpp:carbons:2";
- private ReceivedPipelineListener received_pipeline_listener = new ReceivedPipelineListener();
+public class Module : XmppStreamModule {
+ public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0280_message_carbons_module");
- public void enable(XmppStream stream) {
- Iq.Stanza iq = new Iq.Stanza.set(new StanzaNode.build("enable", NS_URI).add_self_xmlns());
- stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq);
- }
+ private ReceivedPipelineListener received_pipeline_listener = new ReceivedPipelineListener();
- public void disable(XmppStream stream) {
- Iq.Stanza iq = new Iq.Stanza.set(new StanzaNode.build("disable", NS_URI).add_self_xmlns());
- stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq);
- }
+ public void enable(XmppStream stream) {
+ Iq.Stanza iq = new Iq.Stanza.set(new StanzaNode.build("enable", NS_URI).add_self_xmlns());
+ stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq);
+ }
- public override void attach(XmppStream stream) {
- stream.stream_negotiated.connect(enable);
- stream.get_module(Message.Module.IDENTITY).received_pipeline.connect(received_pipeline_listener);
- stream.get_module(ServiceDiscovery.Module.IDENTITY).add_feature(stream, NS_URI);
- }
+ public void disable(XmppStream stream) {
+ Iq.Stanza iq = new Iq.Stanza.set(new StanzaNode.build("disable", NS_URI).add_self_xmlns());
+ stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq);
+ }
- public override void detach(XmppStream stream) {
- stream.stream_negotiated.disconnect(enable);
- stream.get_module(Message.Module.IDENTITY).received_pipeline.disconnect(received_pipeline_listener);
- }
+ public override void attach(XmppStream stream) {
+ stream.stream_negotiated.connect(enable);
+ stream.get_module(MessageModule.IDENTITY).received_pipeline.connect(received_pipeline_listener);
+ stream.get_module(ServiceDiscovery.Module.IDENTITY).add_feature(stream, NS_URI);
+ }
- public override string get_ns() { return NS_URI; }
- public override string get_id() { return IDENTITY.id; }
+ public override void detach(XmppStream stream) {
+ stream.stream_negotiated.disconnect(enable);
+ stream.get_module(MessageModule.IDENTITY).received_pipeline.disconnect(received_pipeline_listener);
}
-public class ReceivedPipelineListener : StanzaListener<Message.Stanza> {
+ public override string get_ns() {
+ return NS_URI;
+ }
+
+ public override string get_id() {
+ return IDENTITY.id;
+ }
+}
+
+public class ReceivedPipelineListener : StanzaListener<MessageStanza> {
private const string[] after_actions_const = {"EXTRACT_MESSAGE_1"};
public override string action_group { get { return "EXTRACT_MESSAGE_2"; } }
public override string[] after_actions { get { return after_actions_const; } }
- public override async void run(Core.XmppStream stream, Message.Stanza message) {
+ public override async void run(XmppStream stream, MessageStanza message) {
StanzaNode? received_node = message.stanza.get_subnode("received", NS_URI);
StanzaNode? sent_node = received_node == null ? message.stanza.get_subnode("sent", NS_URI) : null;
StanzaNode? carbons_node = received_node != null ? received_node : sent_node;
if (carbons_node != null) {
StanzaNode? forwarded_node = carbons_node.get_subnode("forwarded", "urn:xmpp:forward:0");
if (forwarded_node != null) {
- StanzaNode? message_node = forwarded_node.get_subnode("message", Message.NS_URI);
- string? from_attribute = message_node.get_attribute("from", Message.NS_URI);
+ StanzaNode? message_node = forwarded_node.get_subnode("message", Xmpp.NS_URI);
+ string? from_attribute = message_node.get_attribute("from", Xmpp.NS_URI);
// Any forwarded copies received by a Carbons-enabled client MUST be from that user's bare JID; any copies that do not meet this requirement MUST be ignored.
- if (from_attribute != null && from_attribute == get_bare_jid(stream.get_flag(Bind.Flag.IDENTITY).my_jid)) {
+ if (from_attribute != null && from_attribute == stream.get_flag(Bind.Flag.IDENTITY).my_jid.bare_jid.to_string()) {
if (received_node != null) {
message.add_flag(new MessageFlag(MessageFlag.TYPE_RECEIVED));
} else if (sent_node != null) {
@@ -66,22 +70,28 @@ public class ReceivedPipelineListener : StanzaListener<Message.Stanza> {
}
}
- public class MessageFlag : Message.MessageFlag {
- public const string ID = "message_carbons";
+public class MessageFlag : Xmpp.MessageFlag {
+ public const string ID = "message_carbons";
- public const string TYPE_RECEIVED = "received";
- public const string TYPE_SENT = "sent";
- private string type_;
+ public const string TYPE_RECEIVED = "received";
+ public const string TYPE_SENT = "sent";
+ private string type_;
- public MessageFlag(string type) {
- this.type_ = type;
- }
+ public MessageFlag(string type) {
+ this.type_ = type;
+ }
- public static MessageFlag? get_flag(Message.Stanza message) {
- return (MessageFlag) message.get_flag(NS_URI, ID);
- }
+ public static MessageFlag? get_flag(MessageStanza message) {
+ return (MessageFlag) message.get_flag(NS_URI, ID);
+ }
+
+ public override string get_ns() {
+ return NS_URI;
+ }
- public override string get_ns() { return NS_URI; }
- public override string get_id() { return ID; }
+ public override string get_id() {
+ return ID;
}
}
+
+}