aboutsummaryrefslogtreecommitdiff
path: root/libdino/src
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2023-09-24 19:54:04 +0200
committerfiaxh <git@lightrise.org>2023-09-24 19:54:04 +0200
commite2c34bf2235c9f85fc91de9c0f1b74858f4ef89e (patch)
treef5565f57a7cbea8a13748e8a1c613540bbb4d76c /libdino/src
parent9eafe4139d6b2c0cabe3c77a903d6ae931a26975 (diff)
downloaddino-e2c34bf2235c9f85fc91de9c0f1b74858f4ef89e.tar.gz
dino-e2c34bf2235c9f85fc91de9c0f1b74858f4ef89e.zip
Rewrite contact details dialog
Diffstat (limited to 'libdino/src')
-rw-r--r--libdino/src/application.vala1
-rw-r--r--libdino/src/service/contact_model.vala58
2 files changed, 59 insertions, 0 deletions
diff --git a/libdino/src/application.vala b/libdino/src/application.vala
index 5e58e364..727b6131 100644
--- a/libdino/src/application.vala
+++ b/libdino/src/application.vala
@@ -57,6 +57,7 @@ public interface Application : GLib.Application {
Reactions.start(stream_interactor, db);
Replies.start(stream_interactor, db);
FallbackBody.start(stream_interactor, db);
+ ContactModels.start(stream_interactor);
create_actions();
diff --git a/libdino/src/service/contact_model.vala b/libdino/src/service/contact_model.vala
new file mode 100644
index 00000000..312df4f7
--- /dev/null
+++ b/libdino/src/service/contact_model.vala
@@ -0,0 +1,58 @@
+using Xmpp;
+using Gee;
+using Qlite;
+
+using Dino.Entities;
+
+public class Dino.Model.ConversationDisplayName : Object {
+ public string display_name { get; set; }
+}
+
+namespace Dino {
+ public class ContactModels : StreamInteractionModule, Object {
+ public static ModuleIdentity<ContactModels> IDENTITY = new ModuleIdentity<ContactModels>("contact_models");
+ public string id { get { return IDENTITY.id; } }
+
+ private StreamInteractor stream_interactor;
+ private HashMap<Conversation, Model.ConversationDisplayName> conversation_models = new HashMap<Conversation, Model.ConversationDisplayName>(Conversation.hash_func, Conversation.equals_func);
+
+ public static void start(StreamInteractor stream_interactor) {
+ ContactModels m = new ContactModels(stream_interactor);
+ stream_interactor.add_module(m);
+ }
+
+ private ContactModels(StreamInteractor stream_interactor) {
+ this.stream_interactor = stream_interactor;
+
+ stream_interactor.get_module(MucManager.IDENTITY).room_info_updated.connect((account, jid) => {
+ check_update_models(account, jid, Conversation.Type.GROUPCHAT);
+ });
+ stream_interactor.get_module(MucManager.IDENTITY).private_room_occupant_updated.connect((account, room, occupant) => {
+ check_update_models(account, room, Conversation.Type.GROUPCHAT);
+ });
+ stream_interactor.get_module(MucManager.IDENTITY).subject_set.connect((account, jid, subject) => {
+ check_update_models(account, jid, Conversation.Type.GROUPCHAT);
+ });
+ stream_interactor.get_module(RosterManager.IDENTITY).updated_roster_item.connect((account, jid, roster_item) => {
+ check_update_models(account, jid, Conversation.Type.CHAT);
+ });
+ }
+
+ private void check_update_models(Account account, Jid jid, Conversation.Type conversation_ty) {
+ var conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation(jid, account, conversation_ty);
+ if (conversation == null) return;
+ var display_name_model = conversation_models[conversation];
+ if (display_name_model == null) return;
+ display_name_model.display_name = Dino.get_conversation_display_name(stream_interactor, conversation, "%s (%s)");
+ }
+
+ public Model.ConversationDisplayName get_display_name_model(Conversation conversation) {
+ if (conversation_models.has_key(conversation)) return conversation_models[conversation];
+
+ var model = new Model.ConversationDisplayName();
+ model.display_name = Dino.get_conversation_display_name(stream_interactor, conversation, "%s (%s)");
+ conversation_models[conversation] = model;
+ return model;
+ }
+ }
+} \ No newline at end of file