aboutsummaryrefslogtreecommitdiff
path: root/libdino/src/entity
diff options
context:
space:
mode:
Diffstat (limited to 'libdino/src/entity')
-rw-r--r--libdino/src/entity/account.vala1
-rw-r--r--libdino/src/entity/conversation.vala14
-rw-r--r--libdino/src/entity/file_transfer.vala7
-rw-r--r--libdino/src/entity/jid.vala89
-rw-r--r--libdino/src/entity/message.vala21
5 files changed, 25 insertions, 107 deletions
diff --git a/libdino/src/entity/account.vala b/libdino/src/entity/account.vala
index f0628ca4..111fbf08 100644
--- a/libdino/src/entity/account.vala
+++ b/libdino/src/entity/account.vala
@@ -1,4 +1,5 @@
using Gee;
+using Xmpp;
namespace Dino.Entities {
diff --git a/libdino/src/entity/conversation.vala b/libdino/src/entity/conversation.vala
index 83c5ac22..fe9cf9ad 100644
--- a/libdino/src/entity/conversation.vala
+++ b/libdino/src/entity/conversation.vala
@@ -1,3 +1,5 @@
+using Xmpp;
+
namespace Dino.Entities {
public class Conversation : Object {
@@ -11,6 +13,7 @@ public class Conversation : Object {
}
public int id { get; set; }
+ public Type type_ { get; set; }
public Account account { get; private set; }
public Jid counterpart { get; private set; }
public bool active { get; set; default = false; }
@@ -25,7 +28,6 @@ public class Conversation : Object {
}
}
public Encryption encryption { get; set; default = Encryption.NONE; }
- public Type type_ { get; set; }
public Message? read_up_to { get; set; }
public enum NotifySetting { DEFAULT, ON, OFF, HIGHLIGHT }
@@ -48,14 +50,14 @@ public class Conversation : Object {
this.db = db;
id = row[db.conversation.id];
+ type_ = (Conversation.Type) row[db.conversation.type_];
account = db.get_account_by_id(row[db.conversation.account_id]);
string? resource = row[db.conversation.resource];
- string jid = db.get_jid_by_id(row[db.conversation.jid_id]);
- counterpart = resource != null ? new Jid.with_resource(jid, resource) : new Jid(jid);
+ counterpart = Jid.parse(db.get_jid_by_id(row[db.conversation.jid_id]));
+ if (type_ == Conversation.Type.GROUPCHAT_PM) counterpart = counterpart.with_resource(resource);
active = row[db.conversation.active];
int64? last_active = row[db.conversation.last_active];
if (last_active != null) this.last_active = new DateTime.from_unix_utc(last_active);
- type_ = (Conversation.Type) row[db.conversation.type_];
encryption = (Encryption) row[db.conversation.encryption];
int? read_up_to = row[db.conversation.read_up_to];
if (read_up_to != null) this.read_up_to = db.get_message_by_id(read_up_to);
@@ -95,10 +97,10 @@ public class Conversation : Object {
}
public NotifySetting get_notification_default_setting(StreamInteractor stream_interactor) {
- Xmpp.Core.XmppStream? stream = stream_interactor.get_stream(account);
+ Xmpp.XmppStream? stream = stream_interactor.get_stream(account);
if (!Application.get_default().settings.notifications) return NotifySetting.OFF;
if (type_ == Type.GROUPCHAT) {
- bool members_only = stream.get_flag(Xmpp.Xep.Muc.Flag.IDENTITY).has_room_feature(counterpart.bare_jid.to_string(), Xmpp.Xep.Muc.Feature.MEMBERS_ONLY);
+ bool members_only = stream.get_flag(Xmpp.Xep.Muc.Flag.IDENTITY).has_room_feature(counterpart.bare_jid, Xmpp.Xep.Muc.Feature.MEMBERS_ONLY);
return members_only ? NotifySetting.ON : NotifySetting.HIGHLIGHT;
}
return NotifySetting.ON;
diff --git a/libdino/src/entity/file_transfer.vala b/libdino/src/entity/file_transfer.vala
index 120d3b38..22474396 100644
--- a/libdino/src/entity/file_transfer.vala
+++ b/libdino/src/entity/file_transfer.vala
@@ -1,3 +1,5 @@
+using Xmpp;
+
namespace Dino.Entities {
public class FileTransfer : Object {
@@ -48,11 +50,12 @@ public class FileTransfer : Object {
string counterpart_jid = db.get_jid_by_id(row[db.file_transfer.counterpart_id]);
string counterpart_resource = row[db.file_transfer.counterpart_resource];
- counterpart = counterpart_resource != null ? new Jid.with_resource(counterpart_jid, counterpart_resource) : new Jid(counterpart_jid);
+ counterpart = Jid.parse(counterpart_jid);
+ if (counterpart_resource != null) counterpart = counterpart.with_resource(counterpart_resource);
string our_resource = row[db.file_transfer.our_resource];
if (our_resource != null) {
- ourpart = new Jid.with_resource(account.bare_jid.to_string(), our_resource);
+ ourpart = account.bare_jid.with_resource(our_resource);
} else {
ourpart = account.bare_jid;
}
diff --git a/libdino/src/entity/jid.vala b/libdino/src/entity/jid.vala
deleted file mode 100644
index 42218fb2..00000000
--- a/libdino/src/entity/jid.vala
+++ /dev/null
@@ -1,89 +0,0 @@
-public class Dino.Entities.Jid : Object {
- public string? localpart { get; set; }
- public string domainpart { get; set; }
- public string? resourcepart { get; set; }
-
- public Jid bare_jid {
- owned get { return localpart != null ? new Jid(@"$localpart@$domainpart") : new Jid(domainpart); }
- }
-
- private string jid { get; private set; }
-
- public Jid(string jid) {
- Jid? parsed = Jid.parse(jid);
- string? localpart = parsed != null ? parsed.localpart : null;
- string domainpart = parsed != null ? parsed.domainpart : jid;
- string? resourcepart = parsed != null ? parsed.resourcepart : null;
- this.components(localpart, domainpart, resourcepart);
- }
-
- public Jid.with_resource(string bare_jid, string resource) {
- Jid? parsed = Jid.parse(bare_jid);
- this.components(parsed.localpart, parsed.domainpart, resource);
- }
-
- public Jid.components(string? localpart, string domainpart, string? resourcepart) {
- string jid = domainpart;
- if (localpart != null) {
- jid = @"$localpart@$jid";
- }
- if (resourcepart != null) {
- jid = @"$jid/$resourcepart";
- }
- this.jid = jid;
- this.localpart = localpart;
- this.domainpart = domainpart;
- this.resourcepart = resourcepart;
- }
-
- public static Jid? parse(string jid) {
- int slash_index = jid.index_of("/");
- string resourcepart = slash_index == -1 ? null : jid.slice(slash_index + 1, jid.length);
- string bare_jid = slash_index == -1 ? jid : jid.slice(0, slash_index);
- int at_index = bare_jid.index_of("@");
- string localpart = at_index == -1 ? null : bare_jid.slice(0, at_index);
- string domainpart = at_index == -1 ? bare_jid : bare_jid.slice(at_index + 1, bare_jid.length);
-
- if (domainpart == "") return null;
- if (slash_index != -1 && resourcepart == "") return null;
- if (at_index != -1 && localpart == "") return null;
-
- return new Jid.components(localpart, domainpart, resourcepart);
- }
-
- public bool is_bare() {
- return localpart != null && resourcepart == null;
- }
-
- public bool is_full() {
- return localpart != null && resourcepart != null;
- }
-
- public string to_string() {
- return jid;
- }
-
- public bool equals_bare(Jid? jid) {
- return jid != null && equals_bare_func(this, jid);
- }
-
- public bool equals(Jid? jid) {
- return jid != null && equals_func(this, jid);
- }
-
- public static new bool equals_bare_func(Jid jid1, Jid jid2) {
- return jid1.bare_jid.to_string() == jid2.bare_jid.to_string();
- }
-
- public static bool equals_func(Jid jid1, Jid jid2) {
- return jid1.to_string() == jid2.to_string();
- }
-
- public static new uint hash_bare_func(Jid jid) {
- return jid.bare_jid.to_string().hash();
- }
-
- public static new uint hash_func(Jid jid) {
- return jid.to_string().hash();
- }
-}
diff --git a/libdino/src/entity/message.vala b/libdino/src/entity/message.vala
index 27bd08d8..6e34e458 100644
--- a/libdino/src/entity/message.vala
+++ b/libdino/src/entity/message.vala
@@ -1,4 +1,5 @@
using Gee;
+using Xmpp;
namespace Dino.Entities {
@@ -51,7 +52,7 @@ public class Message : Object {
marked_ = value;
}
}
- public Xmpp.Message.Stanza stanza { get; set; }
+ public Xmpp.MessageStanza stanza { get; set; }
private Database? db;
@@ -67,15 +68,15 @@ public class Message : Object {
stanza_id = row[db.message.stanza_id];
type_ = (Message.Type) row[db.message.type_];
- string counterpart_jid = db.get_jid_by_id(row[db.message.counterpart_id]);
+ counterpart = Jid.parse(db.get_jid_by_id(row[db.message.counterpart_id]));
string counterpart_resource = row[db.message.counterpart_resource];
- counterpart = counterpart_resource != null ? new Jid.with_resource(counterpart_jid, counterpart_resource) : new Jid(counterpart_jid);
+ if (counterpart_resource != null) counterpart = counterpart.with_resource(counterpart_resource);
string our_resource = row[db.message.our_resource];
if (type_ == Type.GROUPCHAT && our_resource != null) {
- ourpart = new Jid.with_resource(counterpart_jid, our_resource);
+ ourpart = counterpart.with_resource(our_resource);
} else if (our_resource != null) {
- ourpart = new Jid.with_resource(account.bare_jid.to_string(), our_resource);
+ ourpart = account.bare_jid.with_resource(our_resource);
} else {
ourpart = account.bare_jid;
}
@@ -121,9 +122,9 @@ public class Message : Object {
public void set_type_string(string type) {
switch (type) {
- case Xmpp.Message.Stanza.TYPE_CHAT:
+ case Xmpp.MessageStanza.TYPE_CHAT:
type_ = Type.CHAT; break;
- case Xmpp.Message.Stanza.TYPE_GROUPCHAT:
+ case Xmpp.MessageStanza.TYPE_GROUPCHAT:
type_ = Type.GROUPCHAT; break;
}
}
@@ -131,11 +132,11 @@ public class Message : Object {
public new string get_type_string() {
switch (type_) {
case Type.CHAT:
- return Xmpp.Message.Stanza.TYPE_CHAT;
+ return Xmpp.MessageStanza.TYPE_CHAT;
case Type.GROUPCHAT:
- return Xmpp.Message.Stanza.TYPE_GROUPCHAT;
+ return Xmpp.MessageStanza.TYPE_GROUPCHAT;
default:
- return Xmpp.Message.Stanza.TYPE_NORMAL;
+ return Xmpp.MessageStanza.TYPE_NORMAL;
}
}