1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
using Xmpp.Core;
namespace Xmpp.Xep.DelayedDelivery {
private const string NS_URI = "urn:xmpp:delay";
public class Module : XmppStreamModule {
public const string ID = "0203_delayed_delivery";
public static DateTime? get_send_time(Message.Stanza message) {
StanzaNode? delay_node = message.stanza.get_subnode("delay", NS_URI);
if (delay_node != null) {
string time = delay_node.get_attribute("stamp");
return new DateTime.utc(int.parse(time.substring(0, 4)),
int.parse(time.substring(5, 2)),
int.parse(time.substring(8, 2)),
int.parse(time.substring(11, 2)),
int.parse(time.substring(14, 2)),
int.parse(time.substring(17, 2)));
} else {
return null;
}
}
public override void attach(XmppStream stream) {
Message.Module.get_module(stream).pre_received_message.connect(on_pre_received_message);
}
public override void detach(XmppStream stream) { }
public static Module? get_module(XmppStream stream) {
return (Module?) stream.get_module(NS_URI, ID);
}
public static void require(XmppStream stream) {
if (get_module(stream) == null) stream.add_module(new Module());
}
public override string get_ns() { return NS_URI; }
public override string get_id() { return ID; }
private void on_pre_received_message(XmppStream stream, Message.Stanza message) {
StanzaNode? delay_node = message.stanza.get_subnode("delay", NS_URI);
if (delay_node != null) {
string time = delay_node.get_attribute("stamp");
DateTime datetime = new DateTime.utc(int.parse(time.substring(0, 4)),
int.parse(time.substring(5, 2)),
int.parse(time.substring(8, 2)),
int.parse(time.substring(11, 2)),
int.parse(time.substring(14, 2)),
int.parse(time.substring(17, 2)));
message.add_flag(new MessageFlag(datetime));
}
}
}
public class MessageFlag : Message.MessageFlag {
public const string ID = "delayed_delivery";
DateTime datetime;
public MessageFlag(DateTime datetime) {
this.datetime = datetime;
}
public static MessageFlag? get_flag(Message.Stanza message) { return (MessageFlag) message.get_flag(NS_URI, ID); }
public override string get_ns() { return NS_URI; }
public override string get_id() { return ID; }
}
}
|