aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfiaxh <git@mx.ax.lt>2017-05-24 17:28:39 +0200
committerfiaxh <git@mx.ax.lt>2017-05-24 17:29:17 +0200
commit142257a544b36e60b738e55e5f9f096f1169c389 (patch)
tree0e02590f59615689b4c77dbe5b23e51fd04bb96f
parentbcb96909c9b53c2ca5287433f2fef103b0ddf317 (diff)
downloaddino-142257a544b36e60b738e55e5f9f096f1169c389.tar.gz
dino-142257a544b36e60b738e55e5f9f096f1169c389.zip
fixup bcb9690 (Roster versioning)
-rw-r--r--libdino/src/entity/account.vala5
-rw-r--r--libdino/src/service/database.vala21
-rw-r--r--libdino/src/service/roster_manager.vala20
-rw-r--r--main/src/ui/chat_input/view.vala4
-rw-r--r--xmpp-vala/src/module/xep/0199_ping.vala8
5 files changed, 20 insertions, 38 deletions
diff --git a/libdino/src/entity/account.vala b/libdino/src/entity/account.vala
index 59a76c7d..23544b46 100644
--- a/libdino/src/entity/account.vala
+++ b/libdino/src/entity/account.vala
@@ -15,6 +15,7 @@ public class Account : Object {
}
public string? alias { get; set; }
public bool enabled { get; set; default = false; }
+ public string? roster_version { get; set; }
private Database? db;
@@ -34,6 +35,7 @@ public class Account : Object {
password = row[db.account.password];
alias = row[db.account.alias];
enabled = row[db.account.enabled];
+ roster_version = row[db.account.roster_version];
notify.connect(on_update);
}
@@ -46,6 +48,7 @@ public class Account : Object {
.value(db.account.password, password)
.value(db.account.alias, alias)
.value(db.account.enabled, enabled)
+ .value(db.account.roster_version, roster_version)
.perform();
notify.connect(on_update);
@@ -83,6 +86,8 @@ public class Account : Object {
update.set(db.account.alias, alias); break;
case "enabled":
update.set(db.account.enabled, enabled); break;
+ case "roster-version":
+ update.set(db.account.roster_version, roster_version); break;
}
update.perform();
}
diff --git a/libdino/src/service/database.vala b/libdino/src/service/database.vala
index 2836751f..19ca0b06 100644
--- a/libdino/src/service/database.vala
+++ b/libdino/src/service/database.vala
@@ -6,7 +6,7 @@ using Dino.Entities;
namespace Dino {
public class Database : Qlite.Database {
- private const int VERSION = 1;
+ private const int VERSION = 2;
public class AccountTable : Table {
public Column<int> id = new Column.Integer("id") { primary_key = true, auto_increment = true };
@@ -15,10 +15,11 @@ public class Database : Qlite.Database {
public Column<string> password = new Column.Text("password");
public Column<string> alias = new Column.Text("alias");
public Column<bool> enabled = new Column.BoolInt("enabled");
+ public Column<string> roster_version = new Column.Text("roster_version") { min_version=2 };
internal AccountTable(Database db) {
base(db, "account");
- init({id, bare_jid, resourcepart, password, alias, enabled});
+ init({id, bare_jid, resourcepart, password, alias, enabled, roster_version});
}
}
@@ -128,18 +129,6 @@ public class Database : Qlite.Database {
}
}
- public class AccountKeyValueTable : Table {
- public Column<int> account_id = new Column.Integer("account_id");
- public Column<string> key = new Column.Text("key");
- public Column<string> value = new Column.Text("value");
-
- internal AccountKeyValueTable(Database db) {
- base(db, "account_key_value");
- init({account_id, key, value});
- unique({account_id, key}, "IGNORE");
- }
- }
-
public AccountTable account { get; private set; }
public JidTable jid { get; private set; }
public MessageTable message { get; private set; }
@@ -148,7 +137,6 @@ public class Database : Qlite.Database {
public AvatarTable avatar { get; private set; }
public EntityFeatureTable entity_feature { get; private set; }
public RosterTable roster { get; private set; }
- public AccountKeyValueTable account_key_value { get; private set; }
public Map<int, string> jid_table_cache = new HashMap<int, string>();
public Map<string, int> jid_table_reverse = new HashMap<string, int>();
@@ -164,8 +152,7 @@ public class Database : Qlite.Database {
avatar = new AvatarTable(this);
entity_feature = new EntityFeatureTable(this);
roster = new RosterTable(this);
- account_key_value = new AccountKeyValueTable(this);
- init({ account, jid, message, real_jid, conversation, avatar, entity_feature, roster, account_key_value });
+ init({ account, jid, message, real_jid, conversation, avatar, entity_feature, roster });
exec("PRAGMA synchronous=0");
}
diff --git a/libdino/src/service/roster_manager.vala b/libdino/src/service/roster_manager.vala
index 91da7579..e17c24e3 100644
--- a/libdino/src/service/roster_manager.vala
+++ b/libdino/src/service/roster_manager.vala
@@ -72,14 +72,12 @@ public class RosterStoreImpl : Roster.Storage, Object {
private Account account;
private Database db;
- private string version = "";
private HashMap<string, Roster.Item> items = new HashMap<string, Roster.Item>();
public class RosterStoreImpl(Account account, Database db) {
this.account = account;
this.db = db;
- version = db_get_roster_version() ?? "";
foreach (Qlite.Row row in db.roster.select().with(db.roster.account_id, "=", account.id)) {
Roster.Item item = new Roster.Item();
item.jid = row[db.roster.jid];
@@ -90,7 +88,7 @@ public class RosterStoreImpl : Roster.Storage, Object {
}
public string? get_roster_version() {
- return version;
+ return account.roster_version;
}
public Collection<Roster.Item> get_roster() {
@@ -102,11 +100,7 @@ public class RosterStoreImpl : Roster.Storage, Object {
}
public void set_roster_version(string version) {
- db.account_key_value.insert().or("REPLACE")
- .value(db.account_key_value.account_id, account.id)
- .value(db.account_key_value.key, "roster_version")
- .value(db.account_key_value.value, version)
- .perform();
+ account.roster_version = version;
}
public void set_roster(Collection<Roster.Item> items) {
@@ -130,15 +124,7 @@ public class RosterStoreImpl : Roster.Storage, Object {
items.unset(item.jid);
db.roster.delete()
.with(db.roster.account_id, "=", account.id)
- .with(db.roster.jid, "=", item.jid);
- }
-
- private string? db_get_roster_version() {
- Qlite.Row? row = db.account_key_value.select()
- .with(db.account_key_value.account_id, "=", account.id)
- .with(db.account_key_value.key, "=", "roster_version").iterator().get_next();
- if (row != null) return row[db.account_key_value.value];
- return null;
+ .with(db.roster.jid, "=", item.jid).perform();
}
}
diff --git a/main/src/ui/chat_input/view.vala b/main/src/ui/chat_input/view.vala
index 3c5baa41..0887de25 100644
--- a/main/src/ui/chat_input/view.vala
+++ b/main/src/ui/chat_input/view.vala
@@ -61,6 +61,10 @@ public class View : Box {
case "/nick":
stream_interactor.get_module(MucManager.IDENTITY).change_nick(conversation.account, conversation.counterpart, token[1]);
break;
+ case "/ping":
+ Xmpp.Core.XmppStream? stream = stream_interactor.get_stream(conversation.account);
+ stream.get_module(Xmpp.Xep.Ping.Module.IDENTITY).send_ping(stream, conversation.counterpart.to_string() + "/" + token[1], null);
+ break;
case "/topic":
stream_interactor.get_module(MucManager.IDENTITY).change_subject(conversation.account, conversation.counterpart, token[1]);
break;
diff --git a/xmpp-vala/src/module/xep/0199_ping.vala b/xmpp-vala/src/module/xep/0199_ping.vala
index 3b11bd73..6cb3b4ba 100644
--- a/xmpp-vala/src/module/xep/0199_ping.vala
+++ b/xmpp-vala/src/module/xep/0199_ping.vala
@@ -8,7 +8,7 @@ namespace Xmpp.Xep.Ping {
public class Module : XmppStreamModule {
public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0199_ping");
- public void send_ping(XmppStream stream, string jid, ResponseListener listener) {
+ public void send_ping(XmppStream stream, string jid, ResponseListener? listener) {
Iq.Stanza iq = new Iq.Stanza.get(new StanzaNode.build("ping", NS_URI).add_self_xmlns());
iq.to = jid;
stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, on_ping_response, listener);
@@ -35,9 +35,9 @@ namespace Xmpp.Xep.Ping {
public void on_iq_set(XmppStream stream, Iq.Stanza iq) { }
}
- private static void on_ping_response(XmppStream stream, Iq.Stanza iq, Object o) {
- ResponseListener listener = o as ResponseListener;
- listener.on_result(stream);
+ private static void on_ping_response(XmppStream stream, Iq.Stanza iq, Object? o) {
+ ResponseListener? listener = o as ResponseListener;
+ if (listener != null) listener.on_result(stream);
}
}