aboutsummaryrefslogtreecommitdiff
path: root/libdino
diff options
context:
space:
mode:
Diffstat (limited to 'libdino')
-rw-r--r--libdino/meson.build1
-rw-r--r--libdino/src/application.vala2
-rw-r--r--libdino/src/entity/account.vala6
-rw-r--r--libdino/src/entity/message.vala2
-rw-r--r--libdino/src/service/call_state.vala2
-rw-r--r--libdino/src/service/calls.vala2
-rw-r--r--libdino/src/service/database.vala2
-rw-r--r--libdino/src/service/history_sync.vala2
-rw-r--r--libdino/src/service/reactions.vala2
-rw-r--r--libdino/src/service/roster_manager.vala2
-rw-r--r--libdino/src/service/search_processor.vala12
-rw-r--r--libdino/src/util/weak_map.vala119
-rw-r--r--libdino/tests/jid.vala2
13 files changed, 18 insertions, 138 deletions
diff --git a/libdino/meson.build b/libdino/meson.build
index 73b1c512..f83878e4 100644
--- a/libdino/meson.build
+++ b/libdino/meson.build
@@ -81,7 +81,6 @@ sources = files(
'src/util/limit_input_stream.vala',
'src/util/send_message.vala',
'src/util/util.vala',
- 'src/util/weak_map.vala',
'src/util/weak_timeout.vala',
)
sources += [version_vala]
diff --git a/libdino/src/application.vala b/libdino/src/application.vala
index 19650495..8571120e 100644
--- a/libdino/src/application.vala
+++ b/libdino/src/application.vala
@@ -94,7 +94,7 @@ public interface Application : GLib.Application {
}
jid = Uri.unescape_string(jid);
try {
- jid = new Xmpp.Jid(jid).to_string();
+ jid = Xmpp.Jid.from_string(jid).to_string();
} catch (Xmpp.InvalidJidError e) {
warning("Received invalid jid in xmpp:-URI: %s", e.message);
}
diff --git a/libdino/src/entity/account.vala b/libdino/src/entity/account.vala
index e7729fa0..a108af22 100644
--- a/libdino/src/entity/account.vala
+++ b/libdino/src/entity/account.vala
@@ -10,7 +10,7 @@ public class Account : Object {
public string domainpart { get { return full_jid.domainpart; } }
public string resourcepart {
get { return full_jid.resourcepart; }
- private set { full_jid.resourcepart = value; }
+ private set { full_jid = full_jid.with_resource(value); }
}
public Jid bare_jid { owned get { return full_jid.bare_jid; } }
public Jid full_jid { get; private set; }
@@ -37,7 +37,7 @@ public class Account : Object {
public Account.from_row(Database db, Qlite.Row row) throws InvalidJidError {
this.db = db;
id = row[db.account.id];
- full_jid = new Jid(row[db.account.bare_jid]).with_resource(row[db.account.resourcepart]);
+ full_jid = Jid.from_string(row[db.account.bare_jid]).with_resource(row[db.account.resourcepart]);
password = row[db.account.password];
alias = row[db.account.alias];
enabled = row[db.account.enabled];
@@ -82,7 +82,7 @@ public class Account : Object {
}
public static bool equals_func(Account acc1, Account acc2) {
- return acc1.bare_jid.to_string() == acc2.bare_jid.to_string();
+ return acc1.bare_jid.equals(acc2.bare_jid);
}
public static uint hash_func(Account acc) {
diff --git a/libdino/src/entity/message.vala b/libdino/src/entity/message.vala
index ace59572..16e7ae3f 100644
--- a/libdino/src/entity/message.vala
+++ b/libdino/src/entity/message.vala
@@ -109,7 +109,7 @@ public class Message : Object {
encryption = (Encryption) row[db.message.encryption];
string? real_jid_str = row[db.real_jid.real_jid];
- if (real_jid_str != null) real_jid = new Jid(real_jid_str);
+ if (real_jid_str != null) real_jid = Jid.from_string(real_jid_str);
occupant_db_id = row[db.message_occupant_id.occupant_id];
diff --git a/libdino/src/service/call_state.vala b/libdino/src/service/call_state.vala
index a87aee0a..3caf5071 100644
--- a/libdino/src/service/call_state.vala
+++ b/libdino/src/service/call_state.vala
@@ -354,7 +354,7 @@ public class Dino.CallState : Object {
}
if (cim_call_id == null) cim_call_id = Xmpp.random_uuid();
- muc_jid = new Jid("%08x@".printf(Random.next_int()) + muc_jid.to_string()); // TODO longer?
+ muc_jid = Jid.from_string("%08x@".printf(Random.next_int()) + muc_jid.to_string()); // TODO longer?
debug("[%s] Converting call to groupcall %s", call.account.bare_jid.to_string(), muc_jid.to_string());
yield join_group_call(muc_jid);
diff --git a/libdino/src/service/calls.vala b/libdino/src/service/calls.vala
index a2d25655..e0e37ffd 100644
--- a/libdino/src/service/calls.vala
+++ b/libdino/src/service/calls.vala
@@ -425,7 +425,7 @@ namespace Dino {
string? room_jid_str = join_method_node.get_attribute("room");
if (room_jid_str == null) return;
- Jid room_jid = new Jid(room_jid_str);
+ Jid room_jid = Jid.from_string(room_jid_str);
call_state = create_recv_muji_call(account, call_id, from_jid, room_jid, message_stanza.type_);
multiparty = true;
diff --git a/libdino/src/service/database.vala b/libdino/src/service/database.vala
index 7a5b940a..847d87f6 100644
--- a/libdino/src/service/database.vala
+++ b/libdino/src/service/database.vala
@@ -833,7 +833,7 @@ public class Database : Qlite.Database {
} else {
string? bare_jid = jid.select({jid.bare_jid}).with(jid.id, "=", id)[jid.bare_jid];
if (bare_jid != null) {
- Jid jid_parsed = new Jid(bare_jid);
+ Jid jid_parsed = Jid.from_string(bare_jid);
jid_table_cache[id] = jid_parsed;
// Only store fully normalized Jids for reverse lookup
diff --git a/libdino/src/service/history_sync.vala b/libdino/src/service/history_sync.vala
index 190284e0..9bd3f54f 100644
--- a/libdino/src/service/history_sync.vala
+++ b/libdino/src/service/history_sync.vala
@@ -505,7 +505,7 @@ public class Dino.HistorySync {
foreach (Row row in db.mam_catchup.select().with(db.mam_catchup.account_id, "=", account.id)) {
var mam_range = new MamRange();
mam_range.id = row[db.mam_catchup.id];
- mam_range.server_jid = new Jid(row[db.mam_catchup.server_jid]);
+ mam_range.server_jid = Jid.from_string(row[db.mam_catchup.server_jid]);
mam_range.from_time = row[db.mam_catchup.from_time];
mam_range.from_id = row[db.mam_catchup.from_id];
mam_range.from_end = row[db.mam_catchup.from_end];
diff --git a/libdino/src/service/reactions.vala b/libdino/src/service/reactions.vala
index f6050d28..16849c68 100644
--- a/libdino/src/service/reactions.vala
+++ b/libdino/src/service/reactions.vala
@@ -210,7 +210,7 @@ public class Dino.Reactions : StreamInteractionModule, Object {
Jid jid = null;
if (!db.jid.bare_jid.is_null(row)) {
- jid = new Jid(row[db.jid.bare_jid]);
+ jid = Jid.from_string(row[db.jid.bare_jid]);
} else if (!db.occupantid.occupant_id.is_null(row)) {
if (row[db.occupantid.occupant_id] == own_occupant_id) {
jid = account.bare_jid;
diff --git a/libdino/src/service/roster_manager.vala b/libdino/src/service/roster_manager.vala
index 7cd844da..c9bafb24 100644
--- a/libdino/src/service/roster_manager.vala
+++ b/libdino/src/service/roster_manager.vala
@@ -93,7 +93,7 @@ public class RosterStoreImpl : Roster.Storage, Object {
foreach (Qlite.Row row in db.roster.select().with(db.roster.account_id, "=", account.id)) {
try {
Roster.Item item = new Roster.Item();
- item.jid = new Jid(row[db.roster.jid]);
+ item.jid = Jid.from_string(row[db.roster.jid]);
item.name = row[db.roster.handle];
item.subscription = row[db.roster.subscription];
items[item.jid] = item;
diff --git a/libdino/src/service/search_processor.vala b/libdino/src/service/search_processor.vala
index 6e7d4993..2b5ebe49 100644
--- a/libdino/src/service/search_processor.vala
+++ b/libdino/src/service/search_processor.vala
@@ -134,9 +134,9 @@ public class SearchProcessor : StreamInteractionModule, Object {
foreach(Row chat in chats) {
try {
if (suggestions.size == 0) {
- suggestions.add(new SearchSuggestion(new Conversation.from_row(db, chat), new Jid(chat[db.jid.bare_jid]), "from:"+chat[db.jid.bare_jid], after_prev_space, next_space));
+ suggestions.add(new SearchSuggestion(new Conversation.from_row(db, chat), Jid.from_string(chat[db.jid.bare_jid]), "from:"+chat[db.jid.bare_jid], after_prev_space, next_space));
}
- suggestions.add(new SearchSuggestion(new Conversation.from_row(db, chat), new Jid(chat[db.account.bare_jid]), "from:"+chat[db.account.bare_jid], after_prev_space, next_space));
+ suggestions.add(new SearchSuggestion(new Conversation.from_row(db, chat), Jid.from_string(chat[db.account.bare_jid]), "from:"+chat[db.account.bare_jid], after_prev_space, next_space));
} catch (InvalidJidError e) {
warning("Ignoring search suggestion with invalid Jid: %s", e.message);
}
@@ -160,7 +160,7 @@ public class SearchProcessor : StreamInteractionModule, Object {
.limit(5);
foreach(Row msg in msgs) {
try {
- suggestions.add(new SearchSuggestion(new Conversation.from_row(db, msg), new Jid(current_in).with_resource(msg[db.message.counterpart_resource]), "from:"+msg[db.message.counterpart_resource], after_prev_space, next_space));
+ suggestions.add(new SearchSuggestion(new Conversation.from_row(db, msg), Jid.from_string(current_in).with_resource(msg[db.message.counterpart_resource]), "from:"+msg[db.message.counterpart_resource], after_prev_space, next_space));
} catch (InvalidJidError e) {
warning("Ignoring search suggestion with invalid Jid: %s", e.message);
}
@@ -190,7 +190,7 @@ public class SearchProcessor : StreamInteractionModule, Object {
.limit(limit);
foreach(Row chat in chats) {
try {
- suggestions.add(new SearchSuggestion(new Conversation.from_row(db, chat), new Jid(chat[db.jid.bare_jid]), "with:"+chat[db.jid.bare_jid], after_prev_space, next_space) { order = chat[db.conversation.last_active]});
+ suggestions.add(new SearchSuggestion(new Conversation.from_row(db, chat), Jid.from_string(chat[db.jid.bare_jid]), "with:"+chat[db.jid.bare_jid], after_prev_space, next_space) { order = chat[db.conversation.last_active]});
} catch (InvalidJidError e) {
warning("Ignoring search suggestion with invalid Jid: %s", e.message);
}
@@ -208,7 +208,7 @@ public class SearchProcessor : StreamInteractionModule, Object {
.limit(limit - suggestions.size);
foreach(Row chat in chats) {
try {
- suggestions.add(new SearchSuggestion(new Conversation.from_row(db, chat), new Jid(chat[db.jid.bare_jid]).with_resource(chat[db.conversation.resource]), "with:"+chat[db.jid.bare_jid]+"/"+chat[db.conversation.resource], after_prev_space, next_space) { order = chat[db.conversation.last_active]});
+ suggestions.add(new SearchSuggestion(new Conversation.from_row(db, chat), Jid.from_string(chat[db.jid.bare_jid]).with_resource(chat[db.conversation.resource]), "with:"+chat[db.jid.bare_jid]+"/"+chat[db.conversation.resource], after_prev_space, next_space) { order = chat[db.conversation.last_active]});
} catch (InvalidJidError e) {
warning("Ignoring search suggestion with invalid Jid: %s", e.message);
}
@@ -235,7 +235,7 @@ public class SearchProcessor : StreamInteractionModule, Object {
.limit(limit);
foreach(Row chat in groupchats) {
try {
- suggestions.add(new SearchSuggestion(new Conversation.from_row(db, chat), new Jid(chat[db.jid.bare_jid]), "in:"+chat[db.jid.bare_jid], after_prev_space, next_space));
+ suggestions.add(new SearchSuggestion(new Conversation.from_row(db, chat), Jid.from_string(chat[db.jid.bare_jid]), "in:"+chat[db.jid.bare_jid], after_prev_space, next_space));
} catch (InvalidJidError e) {
warning("Ignoring search suggestion with invalid Jid: %s", e.message);
}
diff --git a/libdino/src/util/weak_map.vala b/libdino/src/util/weak_map.vala
deleted file mode 100644
index a7f4bc44..00000000
--- a/libdino/src/util/weak_map.vala
+++ /dev/null
@@ -1,119 +0,0 @@
-using Gee;
-
-public class WeakMap<K, V> : Gee.AbstractMap<K, V> {
-
- private HashMap<K, weak V> hash_map;
- private HashMap<K, WeakNotifyWrapper> notify_map;
-
- public HashDataFunc<K>? key_hash_func = null;
- public EqualDataFunc<K>? key_equal_func = null;
- public EqualDataFunc<V>? value_equal_func = null;
-
- public WeakMap(owned HashDataFunc<K>? key_hash_func = null, owned EqualDataFunc<K>? key_equal_func = null, owned EqualDataFunc<V>? value_equal_func = null) {
- if (!typeof(V).is_object()) {
- error("WeakMap only takes values that are Objects");
- }
-
- this.key_hash_func = (owned)key_hash_func;
- this.key_equal_func = (owned)key_equal_func;
- this.value_equal_func = (owned)value_equal_func;
-
- if (this.key_equal_func == null || this.key_equal_func == null || this.value_equal_func == null) {
- hash_map = new HashMap<K, weak V>();
- notify_map = new HashMap<K, WeakNotifyWrapper>();
- } else {
- hash_map = new HashMap<K, weak V>((v) => { return this.key_hash_func != null ? this.key_hash_func(v) : 0; },
- (a, b) => { return this.key_equal_func != null ? this.key_equal_func(a, b) : a == b; },
- (a, b) => { return this.value_equal_func != null ? this.value_equal_func(a, b) : a == b; });
- notify_map = new HashMap<K, WeakNotifyWrapper>((v) => { return this.key_hash_func != null ? this.key_hash_func(v) : 0; },
- (a, b) => { return this.key_equal_func != null ? this.key_equal_func(a, b) : a == b; });
- }
- }
-
- public override void clear() {
- foreach (K key in notify_map.keys) {
- Object o = (Object) hash_map[key];
- o.weak_unref(notify_map[key].func);
- }
- hash_map.clear();
- notify_map.clear();
- }
-
- public override V @get(K key) {
- if (!hash_map.has_key(key)) return null;
-
- var v = hash_map[key];
-
- return (owned) v;
- }
-
- public override bool has(K key, V value) {
- return has_key(key) && (this.value_equal_func != null ? this.value_equal_func(hash_map[key], value) : hash_map[key] == value);
- }
-
- public override bool has_key(K key) {
- return hash_map.has_key(key);
- }
-
- public override Gee.MapIterator<K,V> map_iterator() {
- assert_not_reached();
- }
-
- public override void @set(K key, V value) {
- assert(value != null);
-
- unset(key);
-
- Object v_obj = (Object) value;
- var notify_wrap = new WeakNotifyWrapper((obj) => {
- hash_map.unset(key);
- notify_map.unset(key);
- });
- notify_map[key] = notify_wrap;
- v_obj.weak_ref(notify_wrap.func);
-
- hash_map[key] = value;
- }
-
- public override bool unset(K key, out V value = null) {
- if (!hash_map.has_key(key)) {
- value = null;
- return false;
- }
-
- Object v_obj = (Object) hash_map[key];
- v_obj.weak_unref(notify_map[key].func);
- notify_map.unset(key);
- return hash_map.unset(key, out value);
- }
- public override Gee.Set<Gee.Map.Entry<K,V>> entries { owned get; }
-
- public override Gee.Set<K> keys {
- owned get { return hash_map.keys; }
- }
-
- public override bool read_only { get { assert_not_reached(); } }
-
- public override int size { get { return hash_map.size; } }
-
- public override Gee.Collection<V> values {
- owned get {
- assert_not_reached();
- }
- }
-
- public override void dispose() {
- foreach (K key in notify_map.keys) {
- Object o = (Object) hash_map[key];
- o.weak_unref(notify_map[key].func);
- }
- }
-}
-
-internal class WeakNotifyWrapper {
- public WeakNotify func;
-
- public WeakNotifyWrapper(owned WeakNotify func) {
- this.func = (owned) func;
- }
-} \ No newline at end of file
diff --git a/libdino/tests/jid.vala b/libdino/tests/jid.vala
index 08ec5c3a..072d41a5 100644
--- a/libdino/tests/jid.vala
+++ b/libdino/tests/jid.vala
@@ -12,7 +12,7 @@ class JidTest : Gee.TestCase {
}
private void test_parse() {
- Jid jid = new Jid("user@example.com/res");
+ Jid jid = Jid.from_string("user@example.com/res");
fail_if(jid.localpart != "user");
fail_if(jid.domainpart != "example.com");
fail_if(jid.resourcepart != "res");