aboutsummaryrefslogtreecommitdiff
path: root/libdino/src/service
diff options
context:
space:
mode:
authorMarvin W <git@larma.de>2017-03-12 13:19:04 +0100
committerMarvin W <git@larma.de>2017-03-12 14:09:32 +0100
commite8f11178ecc1a333976ba713f532fcae11931b16 (patch)
tree71ef4de63e27203780f3d5bfaa1662d97faaca16 /libdino/src/service
parenta9ea0e9f87e71c60bc570066525d3e3634fbdcc0 (diff)
downloaddino-e8f11178ecc1a333976ba713f532fcae11931b16.tar.gz
dino-e8f11178ecc1a333976ba713f532fcae11931b16.zip
Move storage into user directory and fix plugin search path
Diffstat (limited to 'libdino/src/service')
-rw-r--r--libdino/src/service/avatar_manager.vala12
-rw-r--r--libdino/src/service/avatar_storage.vala17
-rw-r--r--libdino/src/service/message_manager.vala2
-rw-r--r--libdino/src/service/module_manager.vala3
4 files changed, 23 insertions, 11 deletions
diff --git a/libdino/src/service/avatar_manager.vala b/libdino/src/service/avatar_manager.vala
index 69e5580e..032bd576 100644
--- a/libdino/src/service/avatar_manager.vala
+++ b/libdino/src/service/avatar_manager.vala
@@ -20,7 +20,7 @@ public class AvatarManager : StreamInteractionModule, Object {
private Database db;
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("./"); // TODO ihh
+ private AvatarStorage avatar_storage = new AvatarStorage(get_storage_dir());
private const int MAX_PIXEL = 192;
public static void start(StreamInteractor stream_interactor, Database db) {
@@ -28,10 +28,20 @@ public class AvatarManager : StreamInteractionModule, Object {
stream_interactor.add_module(m);
}
+ public static string get_storage_dir() {
+ return Path.build_filename(Application.get_storage_dir(), "avatars");
+ }
+
private AvatarManager(StreamInteractor stream_interactor, Database db) {
this.stream_interactor = stream_interactor;
this.db = db;
stream_interactor.account_added.connect(on_account_added);
+ stream_interactor.module_manager.initialize_account_modules.connect(initialize_avatar_modules);
+ }
+
+ private void initialize_avatar_modules(Account account, ArrayList<Core.XmppStreamModule> modules) {
+ modules.add(new Xep.UserAvatars.Module(avatar_storage));
+ modules.add(new Xep.VCard.Module(avatar_storage));
}
public Pixbuf? get_avatar(Account account, Jid jid) {
diff --git a/libdino/src/service/avatar_storage.vala b/libdino/src/service/avatar_storage.vala
index a9a8fb86..46b43d99 100644
--- a/libdino/src/service/avatar_storage.vala
+++ b/libdino/src/service/avatar_storage.vala
@@ -9,23 +9,28 @@ public class AvatarStorage : Xep.PixbufStorage, Object {
public AvatarStorage(string folder) {
this.folder = folder;
+ DirUtils.create_with_parents(folder, 0700);
}
public void store(string id, uint8[] data) {
- File file = File.new_for_path(id);
- if (file.query_exists()) file.delete(); //TODO y?
- DataOutputStream fos = new DataOutputStream(file.create(FileCreateFlags.REPLACE_DESTINATION));
- fos.write(data);
+ File file = File.new_for_path(Path.build_filename(folder, id));
+ try {
+ if (file.query_exists()) file.delete(); //TODO y?
+ DataOutputStream fos = new DataOutputStream(file.create(FileCreateFlags.REPLACE_DESTINATION));
+ fos.write(data);
+ } catch (Error e) {
+ // Ignore: we failed in storing, so we refuse to display later...
+ }
}
public bool has_image(string id) {
- File file = File.new_for_path(folder + id);
+ File file = File.new_for_path(Path.build_filename(folder, id));
return file.query_exists();
}
public Pixbuf? get_image(string id) {
try {
- return new Pixbuf.from_file(folder + id);
+ return new Pixbuf.from_file(Path.build_filename(folder, id));
} catch (Error e) {
return null;
}
diff --git a/libdino/src/service/message_manager.vala b/libdino/src/service/message_manager.vala
index 11435262..b24aa12d 100644
--- a/libdino/src/service/message_manager.vala
+++ b/libdino/src/service/message_manager.vala
@@ -170,7 +170,7 @@ public class MessageManager : StreamInteractionModule, Object {
pre_message_send(message, new_message, conversation);
if (message.marked == Entities.Message.Marked.UNSENT || message.marked == Entities.Message.Marked.WONTSEND) return;
if (delayed) {
- stream.get_module(Xmpp.Xep.DelayedDelivery.Module.IDENTITY).set_message_delay(new_message, message.time);
+ Xmpp.Xep.DelayedDelivery.Module.set_message_delay(new_message, message.time);
}
stream.get_module(Xmpp.Message.Module.IDENTITY).send_message(stream, new_message);
message.stanza_id = new_message.id;
diff --git a/libdino/src/service/module_manager.vala b/libdino/src/service/module_manager.vala
index 896fb1e4..ab268876 100644
--- a/libdino/src/service/module_manager.vala
+++ b/libdino/src/service/module_manager.vala
@@ -8,7 +8,6 @@ namespace Dino {
public class ModuleManager {
private HashMap<Account, ArrayList<Core.XmppStreamModule>> module_map = new HashMap<Account, ArrayList<Core.XmppStreamModule>>();
- private AvatarStorage avatar_storage = new AvatarStorage("./");
private EntityCapabilitiesStorage entity_capabilities_storage;
public signal void initialize_account_modules(Account account, ArrayList<Core.XmppStreamModule> modules);
@@ -65,8 +64,6 @@ public class ModuleManager {
module_map[account].add(new Xep.Muc.Module());
module_map[account].add(new Xep.Pubsub.Module());
module_map[account].add(new Xep.EntityCapabilities.Module(entity_capabilities_storage));
- module_map[account].add(new Xep.UserAvatars.Module(avatar_storage));
- module_map[account].add(new Xep.VCard.Module(avatar_storage));
module_map[account].add(new Xep.MessageDeliveryReceipts.Module());
module_map[account].add(new Xep.ChatStateNotifications.Module());
module_map[account].add(new Xep.ChatMarkers.Module());