aboutsummaryrefslogtreecommitdiff
path: root/libdino/src/entity
diff options
context:
space:
mode:
Diffstat (limited to 'libdino/src/entity')
-rw-r--r--libdino/src/entity/conversation.vala21
-rw-r--r--libdino/src/entity/jid.vala2
-rw-r--r--libdino/src/entity/message.vala11
3 files changed, 21 insertions, 13 deletions
diff --git a/libdino/src/entity/conversation.vala b/libdino/src/entity/conversation.vala
index 55413785..5a41c7fb 100644
--- a/libdino/src/entity/conversation.vala
+++ b/libdino/src/entity/conversation.vala
@@ -6,7 +6,8 @@ public class Conversation : Object {
public enum Type {
CHAT,
- GROUPCHAT
+ GROUPCHAT,
+ GROUPCHAT_PM
}
public int id { get; set; }
@@ -30,8 +31,8 @@ public class Conversation : Object {
private Database? db;
public Conversation(Jid jid, Account account, Type type) {
- this.counterpart = jid;
this.account = account;
+ this.counterpart = jid;
this.type_ = type;
}
@@ -39,8 +40,10 @@ public class Conversation : Object {
this.db = db;
id = row[db.conversation.id];
- counterpart = new Jid(db.get_jid_by_id(row[db.conversation.jid_id]));
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);
active = row[db.conversation.active];
int64? last_active = row[db.conversation.last_active];
if (last_active != null) this.last_active = new DateTime.from_unix_local(last_active);
@@ -55,12 +58,15 @@ public class Conversation : Object {
public void persist(Database db) {
this.db = db;
var insert = db.conversation.insert()
- .value(db.conversation.jid_id, db.get_jid_id(counterpart))
.value(db.conversation.account_id, account.id)
+ .value(db.conversation.jid_id, db.get_jid_id(counterpart))
.value(db.conversation.type_, type_)
.value(db.conversation.encryption, encryption)
//.value(conversation.read_up_to, new_conversation.read_up_to)
.value(db.conversation.active, active);
+ if (counterpart.is_full()) {
+ insert.value(db.conversation.resource, counterpart.resourcepart);
+ }
if (last_active != null) {
insert.value(db.conversation.last_active, (long) last_active.to_unix());
}
@@ -90,7 +96,12 @@ public class Conversation : Object {
case "encryption":
update.set(db.conversation.encryption, encryption); break;
case "read-up-to":
- update.set(db.conversation.read_up_to, read_up_to.id); break;
+ if (read_up_to != null) {
+ update.set(db.conversation.read_up_to, read_up_to.id);
+ } else {
+ update.set_null(db.conversation.read_up_to);
+ }
+ break;
case "active":
update.set(db.conversation.active, active); break;
case "last-active":
diff --git a/libdino/src/entity/jid.vala b/libdino/src/entity/jid.vala
index 96948ca4..edd3bc91 100644
--- a/libdino/src/entity/jid.vala
+++ b/libdino/src/entity/jid.vala
@@ -19,7 +19,7 @@ public class Dino.Entities.Jid : Object {
public Jid.with_resource(string bare_jid, string resource) {
Jid? parsed = Jid.parse(bare_jid);
- this.components(parsed.localpart, parsed.domainpart, resourcepart);
+ this.components(parsed.localpart, parsed.domainpart, resource);
}
public Jid.components(string? localpart, string domainpart, string? resourcepart) {
diff --git a/libdino/src/entity/message.vala b/libdino/src/entity/message.vala
index b5686159..4624aa87 100644
--- a/libdino/src/entity/message.vala
+++ b/libdino/src/entity/message.vala
@@ -20,8 +20,8 @@ public class Message : Object {
ERROR,
CHAT,
GROUPCHAT,
- HEADLINE,
- NORMAL
+ GROUPCHAT_PM,
+ UNKNOWN
}
public int? id { get; set; }
@@ -36,7 +36,7 @@ public class Message : Object {
}
public bool direction { get; set; }
public string? real_jid { get; set; }
- public Type type_ { get; set; }
+ public Type type_ { get; set; default = Type.UNKNOWN; }
public string? body { get; set; }
public string? stanza_id { get; set; }
public DateTime? time { get; set; }
@@ -48,10 +48,9 @@ public class Message : Object {
private Database? db;
- public Message(string? body, Type type) {
+ public Message(string? body) {
this.id = -1;
this.body = body;
- this.type_ = type;
}
public Message.from_row(Database db, Qlite.Row row) {
@@ -107,8 +106,6 @@ public class Message : Object {
type_ = Type.CHAT; break;
case Xmpp.Message.Stanza.TYPE_GROUPCHAT:
type_ = Type.GROUPCHAT; break;
- default:
- type_ = Type.NORMAL; break;
}
}