aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmake/FindGPGME.cmake8
-rw-r--r--libdino/src/entity/conversation.vala26
-rw-r--r--libdino/src/entity/message.vala4
-rw-r--r--libdino/src/service/avatar_manager.vala16
-rw-r--r--libdino/src/service/database.vala57
5 files changed, 82 insertions, 29 deletions
diff --git a/cmake/FindGPGME.cmake b/cmake/FindGPGME.cmake
index 90f734fe..02fa7593 100644
--- a/cmake/FindGPGME.cmake
+++ b/cmake/FindGPGME.cmake
@@ -20,14 +20,14 @@ if(GPGME_CONFIG_EXECUTABLE)
OUTPUT_VARIABLE GPGME_LDFLAGS
OUTPUT_STRIP_TRAILING_WHITESPACE)
- string(REGEX REPLACE "^(.* |)-l([^ ]*)$( .*|)" "\\2" GPGME_LIBRARY "${GPGME_LDFLAGS}")
- string(REGEX REPLACE "^(.* |)-L([^ ]*)$( .*|)" "\\2" GPGME_LIBRARY_DIRS "${GPGME_LDFLAGS}")
+ string(REGEX REPLACE "^(.* |)-l([^ ]*gpgme[^ ]*)( .*|)$" "\\2" GPGME_LIBRARY "${GPGME_LDFLAGS}")
+ string(REGEX REPLACE "^(.* |)-L([^ ]*)( .*|)$" "\\2" GPGME_LIBRARY_DIRS "${GPGME_LDFLAGS}")
find_library(LIB_NAME_GPGME ${GPGME_LIBRARY} HINTS ${GPGME_LIBRARY_DIRS})
set(GPGME_LIBRARY ${LIB_NAME_GPGME})
if(NOT TARGET gpgme)
- add_library(gpgme SHARED IMPORTED)
- set_property(TARGET gpgme PROPERTY IMPORTED_LOCATION "${GPGME_LIBRARY}")
+ add_library(gpgme INTERFACE IMPORTED)
+ set_property(TARGET gpgme PROPERTY INTERFACE_LINK_LIBRARIES "${GPGME_LDFLAGS}")
set_property(TARGET gpgme PROPERTY INTERFACE_COMPILE_OPTIONS "${GPGME_CFLAGS}")
endif(NOT TARGET gpgme)
endif(GPGME_CONFIG_EXECUTABLE)
diff --git a/libdino/src/entity/conversation.vala b/libdino/src/entity/conversation.vala
index fd226b3e..376d1cef 100644
--- a/libdino/src/entity/conversation.vala
+++ b/libdino/src/entity/conversation.vala
@@ -74,15 +74,23 @@ public class Conversation : Object {
private void on_update(Object o, ParamSpec sp) {
var update = db.conversation.update().with(db.conversation.jid_id, "=", db.get_jid_id(counterpart))
- .with(db.conversation.account_id, "=", account.id)
- .set(db.conversation.type_, type_)
- .set(db.conversation.encryption, encryption)
- //.set(conversation.read_up_to, changed_conversation.read_up_to)
- .set(db.conversation.active, active);
- if (last_active != null) {
- update.set(db.conversation.last_active, (long) last_active.to_unix());
- } else {
- update.set_null(db.conversation.last_active);
+ .with(db.conversation.account_id, "=", account.id);
+ switch (sp.name) {
+ case "type_":
+ update.set(db.conversation.type_, type_); break;
+ 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;
+ case "active":
+ update.set(db.conversation.active, active); break;
+ case "last_active":
+ if (last_active != null) {
+ update.set(db.conversation.last_active, (long) last_active.to_unix());
+ } else {
+ update.set_null(db.conversation.last_active);
+ }
+ break;
}
update.perform();
}
diff --git a/libdino/src/entity/message.vala b/libdino/src/entity/message.vala
index 602c74b6..e50a1fc2 100644
--- a/libdino/src/entity/message.vala
+++ b/libdino/src/entity/message.vala
@@ -140,7 +140,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.get_name()) {
+ switch (sp.name) {
case "stanza_id":
update_builder.set(db.message.stanza_id, stanza_id); break;
case "counterpart":
@@ -166,7 +166,7 @@ public class Message : Object {
update_builder.perform();
if (sp.get_name() == "real_jid") {
- db.real_jid.insert()
+ db.real_jid.insert().or("REPLACE")
.value(db.real_jid.message_id, id)
.value(db.real_jid.real_jid, real_jid)
.perform();
diff --git a/libdino/src/service/avatar_manager.vala b/libdino/src/service/avatar_manager.vala
index 1c0a3b51..de3d86fb 100644
--- a/libdino/src/service/avatar_manager.vala
+++ b/libdino/src/service/avatar_manager.vala
@@ -22,6 +22,7 @@ public class AvatarManager : StreamInteractionModule, Object {
private HashMap<Jid, string> user_avatars = new HashMap<Jid, string>(Jid.hash_func, Jid.equals_func);
private HashMap<Jid, string> vcard_avatars = new HashMap<Jid, string>(Jid.hash_func, Jid.equals_func);
private AvatarStorage avatar_storage = new AvatarStorage(get_storage_dir());
+ private HashMap<string, Pixbuf> cached_pixbuf = new HashMap<string, Pixbuf>();
private const int MAX_PIXEL = 192;
public static void start(StreamInteractor stream_interactor, Database db) {
@@ -45,6 +46,17 @@ public class AvatarManager : StreamInteractionModule, Object {
modules.add(new Xep.VCard.Module(avatar_storage));
}
+ private Pixbuf? get_avatar_by_hash(string hash) {
+ if (cached_pixbuf.has_key(hash)) {
+ return cached_pixbuf[hash];
+ }
+ Pixbuf? image = avatar_storage.get_image(hash);
+ if (image != null) {
+ cached_pixbuf[hash] = image;
+ }
+ return image;
+ }
+
public Pixbuf? get_avatar(Account account, Jid jid) {
Jid jid_ = jid;
if (!stream_interactor.get_module(MucManager.IDENTITY).is_groupchat_occupant(jid, account)) {
@@ -52,11 +64,11 @@ public class AvatarManager : StreamInteractionModule, Object {
}
string? user_avatars_id = user_avatars[jid_];
if (user_avatars_id != null) {
- return avatar_storage.get_image(user_avatars_id);
+ return get_avatar_by_hash(user_avatars_id);
}
string? vcard_avatars_id = vcard_avatars[jid_];
if (vcard_avatars_id != null) {
- return avatar_storage.get_image(vcard_avatars_id);
+ return get_avatar_by_hash(vcard_avatars_id);
}
return null;
}
diff --git a/libdino/src/service/database.vala b/libdino/src/service/database.vala
index 202a0930..4115bcfa 100644
--- a/libdino/src/service/database.vala
+++ b/libdino/src/service/database.vala
@@ -120,6 +120,10 @@ public class Database : Qlite.Database {
public AvatarTable avatar { get; private set; }
public EntityFeatureTable entity_feature { 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>();
+ public Map<int, Account> account_table_cache = new HashMap<int, Account>();
+
public Database(string fileName) throws DatabaseError {
base(fileName, VERSION);
account = new AccountTable(this);
@@ -141,21 +145,26 @@ public class Database : Qlite.Database {
foreach(Row row in account.select()) {
Account account = new Account.from_row(this, row);
ret.add(account);
+ account_table_cache[account.id] = account;
}
return ret;
}
public Account? get_account_by_id(int id) {
- Row? row = account.row_with(account.id, id).inner;
- if (row != null) {
- return new Account.from_row(this, row);
+ if (account_table_cache.has_key(id)) {
+ return account_table_cache[id];
+ } else {
+ Row? row = account.row_with(account.id, id).inner;
+ if (row != null) {
+ Account a = new Account.from_row(this, row);
+ account_table_cache[a.id] = a;
+ return a;
+ }
+ return null;
}
- return null;
}
public Gee.List<Message> get_messages(Jid jid, Account account, int count, Message? before) {
- string jid_id = get_jid_id(jid).to_string();
-
QueryBuilder select = message.select()
.with(message.counterpart_id, "=", get_jid_id(jid))
.with(message.account_id, "=", account.id)
@@ -181,10 +190,9 @@ public class Database : Qlite.Database {
}
public bool contains_message(Message query_message, Account account) {
- int jid_id = get_jid_id(query_message.counterpart);
QueryBuilder builder = message.select()
.with(message.account_id, "=", account.id)
- .with(message.counterpart_id, "=", jid_id)
+ .with(message.counterpart_id, "=", get_jid_id(query_message.counterpart))
.with(message.counterpart_resource, "=", query_message.counterpart.resourcepart)
.with(message.body, "=", query_message.body)
.with(message.time, "<", (long) query_message.time.add_minutes(1).to_unix())
@@ -255,16 +263,41 @@ public class Database : Qlite.Database {
public int get_jid_id(Jid jid_obj) {
- Row? row = jid.row_with(jid.bare_jid, jid_obj.bare_jid.to_string()).inner;
- return row != null ? row[jid.id] : add_jid(jid_obj);
+ string bare_jid = jid_obj.bare_jid.to_string();
+ if (jid_table_reverse.has_key(bare_jid)) {
+ return jid_table_reverse[bare_jid];
+ } else {
+ Row? row = jid.row_with(jid.bare_jid, jid_obj.bare_jid.to_string()).inner;
+ if (row != null) {
+ int id = row[jid.id];
+ jid_table_cache[id] = bare_jid;
+ jid_table_reverse[bare_jid] = id;
+ return id;
+ } else {
+ return add_jid(jid_obj);
+ }
+ }
}
public string? get_jid_by_id(int id) {
- return jid.select({jid.bare_jid}).with(jid.id, "=", id)[jid.bare_jid];
+ if (jid_table_cache.has_key(id)) {
+ return jid_table_cache[id];
+ } else {
+ string? bare_jid = jid.select({jid.bare_jid}).with(jid.id, "=", id)[jid.bare_jid];
+ if (bare_jid != null) {
+ jid_table_cache[id] = bare_jid;
+ jid_table_reverse[bare_jid] = id;
+ }
+ return bare_jid;
+ }
}
private int add_jid(Jid jid_obj) {
- return (int) jid.insert().value(jid.bare_jid, jid_obj.bare_jid.to_string()).perform();
+ string bare_jid = jid_obj.bare_jid.to_string();
+ int id = (int) jid.insert().value(jid.bare_jid, bare_jid).perform();
+ jid_table_cache[id] = bare_jid;
+ jid_table_reverse[bare_jid] = id;
+ return id;
}
}