aboutsummaryrefslogtreecommitdiff
path: root/libdino/src/entity/message.vala
diff options
context:
space:
mode:
authorMarvin W <git@larma.de>2017-03-10 19:34:56 +0100
committerMarvin W <git@larma.de>2017-03-10 19:50:34 +0100
commit29ca70a6d534e1cd79963718c793ae740318cff1 (patch)
tree295bc0a88b9f31f103bc970fbdcd2d940d6c83e2 /libdino/src/entity/message.vala
parentcf51e1dee22273366700c41a185c4bea343dddfe (diff)
downloaddino-29ca70a6d534e1cd79963718c793ae740318cff1.tar.gz
dino-29ca70a6d534e1cd79963718c793ae740318cff1.zip
Initial plugin system
Diffstat (limited to 'libdino/src/entity/message.vala')
-rw-r--r--libdino/src/entity/message.vala91
1 files changed, 91 insertions, 0 deletions
diff --git a/libdino/src/entity/message.vala b/libdino/src/entity/message.vala
new file mode 100644
index 00000000..65d05bdf
--- /dev/null
+++ b/libdino/src/entity/message.vala
@@ -0,0 +1,91 @@
+using Gee;
+
+using Xmpp;
+
+public class Dino.Entities.Message : Object {
+
+ public const bool DIRECTION_SENT = true;
+ public const bool DIRECTION_RECEIVED = false;
+
+ public enum Marked {
+ NONE,
+ RECEIVED,
+ READ,
+ ACKNOWLEDGED,
+ UNSENT,
+ WONTSEND
+ }
+
+ public enum Encryption {
+ NONE,
+ PGP
+ }
+
+ public enum Type {
+ ERROR,
+ CHAT,
+ GROUPCHAT,
+ HEADLINE,
+ NORMAL
+ }
+
+ public int? id { get; set; }
+ public Account account { get; set; }
+ public Jid? counterpart { get; set; }
+ public Jid? ourpart { get; set; }
+ public Jid? from {
+ get { return direction == DIRECTION_SENT ? account.bare_jid : counterpart; }
+ }
+ public Jid? to {
+ get { return direction == DIRECTION_SENT ? counterpart : account.bare_jid; }
+ }
+ public bool direction { get; set; }
+ public string? real_jid { get; set; }
+ public Type type_ { get; set; }
+ public string? body { get; set; }
+ public string? stanza_id { get; set; }
+ public DateTime? time { get; set; }
+ public DateTime? local_time { get; set; }
+ public Encryption encryption { get; set; default = Encryption.NONE; }
+ public Marked marked { get; set; default = Marked.NONE; }
+ public Xmpp.Message.Stanza stanza { get; set; }
+
+ public void set_type_string(string type) {
+ switch (type) {
+ case Xmpp.Message.Stanza.TYPE_CHAT:
+ type_ = Type.CHAT; break;
+ case Xmpp.Message.Stanza.TYPE_GROUPCHAT:
+ type_ = Type.GROUPCHAT; break;
+ default:
+ type_ = Type.NORMAL; break;
+ }
+ }
+
+ public new string get_type_string() {
+ switch (type_) {
+ case Type.CHAT:
+ return Xmpp.Message.Stanza.TYPE_CHAT;
+ case Type.GROUPCHAT:
+ return Xmpp.Message.Stanza.TYPE_GROUPCHAT;
+ default:
+ return Xmpp.Message.Stanza.TYPE_NORMAL;
+ }
+ }
+
+ public bool equals(Message? m) {
+ if (m == null) return false;
+ return equals_func(this, m);
+ }
+
+ public static bool equals_func(Message m1, Message m2) {
+ if (m1.stanza_id == m2.stanza_id &&
+ m1.body == m2.body) {
+ return true;
+ }
+ return false;
+ }
+
+ public static uint hash_func(Message message) {
+ return message.body.hash();
+ }
+}