aboutsummaryrefslogtreecommitdiff
path: root/libdino/src/entity
diff options
context:
space:
mode:
authorfiaxh <git@mx.ax.lt>2017-03-24 22:57:05 +0100
committerfiaxh <git@mx.ax.lt>2017-03-31 01:21:35 +0200
commit7d2f995a097086be01426cc79c9c801dabaf9e3b (patch)
tree32b00adeaec82843a9f41fb3de17adc25e62fcc1 /libdino/src/entity
parent3733d24a9066bdd3e038d642a62cf642abd0b0bf (diff)
downloaddino-7d2f995a097086be01426cc79c9c801dabaf9e3b.tar.gz
dino-7d2f995a097086be01426cc79c9c801dabaf9e3b.zip
Fix conversation last_active
Diffstat (limited to 'libdino/src/entity')
-rw-r--r--libdino/src/entity/account.vala21
-rw-r--r--libdino/src/entity/conversation.vala19
-rw-r--r--libdino/src/entity/message.vala12
3 files changed, 35 insertions, 17 deletions
diff --git a/libdino/src/entity/account.vala b/libdino/src/entity/account.vala
index 3f1bfdb2..59a76c7d 100644
--- a/libdino/src/entity/account.vala
+++ b/libdino/src/entity/account.vala
@@ -71,13 +71,20 @@ public class Account : Object {
}
private void on_update(Object o, ParamSpec sp) {
- db.account.update().with(db.account.id, "=", id)
- .set(db.account.bare_jid, bare_jid.to_string())
- .set(db.account.resourcepart, resourcepart)
- .set(db.account.password, password)
- .set(db.account.alias, alias)
- .set(db.account.enabled, enabled)
- .perform();
+ var update = db.account.update().with(db.account.id, "=", id);
+ switch (sp.name) {
+ case "bare-jid":
+ update.set(db.account.bare_jid, bare_jid.to_string()); break;
+ case "resourcepart":
+ update.set(db.account.resourcepart, resourcepart); break;
+ case "password":
+ update.set(db.account.password, password); break;
+ case "alias":
+ update.set(db.account.alias, alias); break;
+ case "enabled":
+ update.set(db.account.enabled, enabled); break;
+ }
+ update.perform();
}
}
diff --git a/libdino/src/entity/conversation.vala b/libdino/src/entity/conversation.vala
index 376d1cef..55413785 100644
--- a/libdino/src/entity/conversation.vala
+++ b/libdino/src/entity/conversation.vala
@@ -13,7 +13,16 @@ public class Conversation : Object {
public Account account { get; private set; }
public Jid counterpart { get; private set; }
public bool active { get; set; default = false; }
- public DateTime? last_active { get; set; }
+ private DateTime? _last_active;
+ public DateTime? last_active {
+ get { return _last_active; }
+ set {
+ if (_last_active == null ||
+ (value != null && value.difference(_last_active) > 0)) {
+ _last_active = value;
+ }
+ }
+ }
public Encryption encryption { get; set; default = Encryption.NONE; }
public Type type_ { get; set; }
public Message read_up_to { get; set; }
@@ -34,7 +43,7 @@ public class Conversation : Object {
account = db.get_account_by_id(row[db.conversation.account_id]);
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);
+ if (last_active != null) this.last_active = new DateTime.from_unix_local(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];
@@ -76,15 +85,15 @@ public class Conversation : Object {
var update = db.conversation.update().with(db.conversation.jid_id, "=", db.get_jid_id(counterpart))
.with(db.conversation.account_id, "=", account.id);
switch (sp.name) {
- case "type_":
+ case "type-":
update.set(db.conversation.type_, type_); break;
case "encryption":
update.set(db.conversation.encryption, encryption); break;
- case "read_up_to":
+ case "read-up-to":
update.set(db.conversation.read_up_to, read_up_to.id); break;
case "active":
update.set(db.conversation.active, active); break;
- case "last_active":
+ case "last-active":
if (last_active != null) {
update.set(db.conversation.last_active, (long) last_active.to_unix());
} else {
diff --git a/libdino/src/entity/message.vala b/libdino/src/entity/message.vala
index e50a1fc2..b5686159 100644
--- a/libdino/src/entity/message.vala
+++ b/libdino/src/entity/message.vala
@@ -40,6 +40,7 @@ public class Message : Object {
public string? body { get; set; }
public string? stanza_id { get; set; }
public DateTime? time { get; set; }
+ /** UTC **/
public DateTime? local_time { get; set; }
public Encryption encryption { get; set; default = Encryption.NONE; }
public Marked marked { get; set; default = Marked.NONE; }
@@ -63,7 +64,8 @@ public class Message : Object {
counterpart = from_resource != null ? new Jid(from + "/" + from_resource) : new Jid(from);
direction = row[db.message.direction];
type_ = (Message.Type) row[db.message.type_];
- time = new DateTime.from_unix_utc(row[db.message.time]);
+ time = new DateTime.from_unix_local(row[db.message.time]);
+ local_time = new DateTime.from_unix_local(row[db.message.time]);
body = row[db.message.body];
account = db.get_account_by_id(row[db.message.account_id]); // TODO dont have to generate acc new
marked = (Message.Marked) row[db.message.marked];
@@ -141,7 +143,7 @@ public class Message : Object {
private void on_update(Object o, ParamSpec sp) {
Qlite.UpdateBuilder update_builder = db.message.update().with(db.message.id, "=", id);
switch (sp.name) {
- case "stanza_id":
+ case "stanza-id":
update_builder.set(db.message.stanza_id, stanza_id); break;
case "counterpart":
update_builder.set(db.message.counterpart_id, db.get_jid_id(counterpart));
@@ -150,11 +152,11 @@ public class Message : Object {
update_builder.set(db.message.our_resource, ourpart.resourcepart); break;
case "direction":
update_builder.set(db.message.direction, direction); break;
- case "type_":
+ case "type-":
update_builder.set(db.message.type_, type_); break;
case "time":
update_builder.set(db.message.time, (long) time.to_unix()); break;
- case "local_time":
+ case "local-time":
update_builder.set(db.message.local_time, (long) local_time.to_unix()); break;
case "body":
update_builder.set(db.message.body, body); break;
@@ -165,7 +167,7 @@ public class Message : Object {
}
update_builder.perform();
- if (sp.get_name() == "real_jid") {
+ if (sp.get_name() == "real-jid") {
db.real_jid.insert().or("REPLACE")
.value(db.real_jid.message_id, id)
.value(db.real_jid.real_jid, real_jid)