aboutsummaryrefslogtreecommitdiff
path: root/libdino
diff options
context:
space:
mode:
Diffstat (limited to 'libdino')
-rw-r--r--libdino/src/service/entity_info.vala20
-rw-r--r--libdino/src/service/muc_manager.vala65
2 files changed, 61 insertions, 24 deletions
diff --git a/libdino/src/service/entity_info.vala b/libdino/src/service/entity_info.vala
index b80d4b59..d7d0bc9e 100644
--- a/libdino/src/service/entity_info.vala
+++ b/libdino/src/service/entity_info.vala
@@ -32,12 +32,13 @@ public class EntityInfo : StreamInteractionModule, Object {
this.entity_capabilities_storage = new EntityCapabilitiesStorage(db);
stream_interactor.account_added.connect(on_account_added);
- stream_interactor.stream_negotiated.connect((account, stream) => {
- var cache = new CapsCacheImpl(account, this);
- stream.get_module(ServiceDiscovery.Module.IDENTITY).cache = cache;
-
- string? hash = EntityCapabilities.get_server_caps_hash(stream);
- entity_caps_hashes[account.bare_jid.domain_jid] = hash;
+ stream_interactor.connection_manager.stream_opened.connect((account, stream) => {
+ stream.received_features_node.connect(() => {
+ string? hash = EntityCapabilities.get_server_caps_hash(stream);
+ if (hash != null) {
+ entity_caps_hashes[account.bare_jid.domain_jid] = hash;
+ }
+ });
});
stream_interactor.module_manager.initialize_account_modules.connect(initialize_modules);
@@ -169,14 +170,14 @@ public class EntityInfo : StreamInteractionModule, Object {
return identities;
}
+ identities = new HashSet<Identity>(Identity.hash_func, Identity.equals_func);
var qry = db.entity_identity.select().with(db.entity_identity.entity, "=", entity);
foreach (Row row in qry) {
- if (identities == null) identities = new HashSet<Identity>(Identity.hash_func, Identity.equals_func);
var identity = new Identity(row[db.entity_identity.category], row[db.entity_identity.type], row[db.entity_identity.entity_name]);
identities.add(identity);
}
- if (entity_identity.size == 0) {
+ if (identities.size == 0) {
return null;
}
entity_identity[entity] = identities;
@@ -202,6 +203,9 @@ public class EntityInfo : StreamInteractionModule, Object {
}
private void on_account_added(Account account) {
+ var cache = new CapsCacheImpl(account, this);
+ stream_interactor.module_manager.get_module(account, ServiceDiscovery.Module.IDENTITY).cache = cache;
+
stream_interactor.module_manager.get_module(account, Presence.Module.IDENTITY).received_available.connect((stream, presence) => on_received_available_presence(account, presence));
}
diff --git a/libdino/src/service/muc_manager.vala b/libdino/src/service/muc_manager.vala
index a508f819..5d0b05b9 100644
--- a/libdino/src/service/muc_manager.vala
+++ b/libdino/src/service/muc_manager.vala
@@ -386,21 +386,6 @@ public class MucManager : StreamInteractionModule, Object {
private_room_occupant_updated(account, room, occupant);
}
});
-
- bookmarks_provider[account] = stream_interactor.module_manager.get_module(account, Xep.Bookmarks.Module.IDENTITY);
-
- bookmarks_provider[account].received_conferences.connect( (stream, conferences) => {
- sync_autojoin_active(account, conferences);
- bookmarks_updated(account, conferences);
- });
- bookmarks_provider[account].conference_added.connect( (stream, conference) => {
- // TODO join (for Bookmarks2)
- conference_added(account, conference);
- });
- bookmarks_provider[account].conference_removed.connect( (stream, jid) => {
- // TODO part (for Bookmarks2)
- conference_removed(account, jid);
- });
}
private async void search_default_muc_server(Account account) {
@@ -434,7 +419,7 @@ public class MucManager : StreamInteractionModule, Object {
}
private async void on_stream_negotiated(Account account, XmppStream stream) {
- if (bookmarks_provider[account] == null) return;
+ yield initialize_bookmarks_provider(account);
Set<Conference>? conferences = yield bookmarks_provider[account].get_conferences(stream);
@@ -449,6 +434,31 @@ public class MucManager : StreamInteractionModule, Object {
}
}
+ private async void initialize_bookmarks_provider(Account account) {
+ if (bookmarks_provider.has_key(account)) return;
+
+ // Use PEP native bookmarks (urn:xmpp:bookmarks:1) if conversion is available, legacy bookmarks (storage:bookmarks) otherwise.
+ bool has_feature = yield stream_interactor.get_module(EntityInfo.IDENTITY).has_feature(account, account.bare_jid, Xep.Bookmarks2.NS_URI_COMPAT);
+ if (has_feature) {
+ debug("[%s] Using PEP native bookmarks (urn:xmpp:bookmarks:1)", account.bare_jid.to_string());
+ bookmarks_provider[account] = stream_interactor.module_manager.get_module(account, Xep.Bookmarks2.Module.IDENTITY);
+ } else {
+ debug("[%s] Using legacy bookmarks (storage:bookmarks)", account.bare_jid.to_string());
+ bookmarks_provider[account] = stream_interactor.module_manager.get_module(account, Xep.Bookmarks.Module.IDENTITY);
+ }
+
+ bookmarks_provider[account].received_conferences.connect( (stream, conferences) => {
+ sync_autojoin_active(account, conferences);
+ bookmarks_updated(account, conferences);
+ });
+ bookmarks_provider[account].conference_added.connect( (stream, conference) => {
+ on_conference_added(account, conference);
+ });
+ bookmarks_provider[account].conference_removed.connect( (stream, jid) => {
+ on_conference_removed(account, jid);
+ });
+ }
+
private void on_invite_received(Account account, Jid room_jid, Jid from_jid, string? password, string? reason) {
if (!invites.has_key(account)) {
invites[account] = new LinkedList<Jid>(Jid.equals_func);
@@ -544,6 +554,29 @@ public class MucManager : StreamInteractionModule, Object {
});
}
+ private void on_conference_added(Account account, Xmpp.Conference conference) {
+ Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation(conference.jid, account, Conversation.Type.GROUPCHAT);
+ if (conversation != null) {
+ if (!conversation.active && conference.autojoin) {
+ join.begin(account, conference.jid, conference.nick, conference.password);
+ } else if (conversation.active && !conference.autojoin) {
+ part(account, conference.jid);
+ }
+ }
+ if (conference.autojoin) {
+ join.begin(account, conference.jid, conference.nick, conference.password);
+ }
+ conference_added(account, conference);
+ }
+
+ private void on_conference_removed(Account account, Jid jid) {
+ Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation(jid, account, Conversation.Type.GROUPCHAT);
+ if (conversation != null && conversation.active) {
+ part(account, jid);
+ }
+ conference_removed(account, jid);
+ }
+
private void self_ping(Account account) {
XmppStream? stream = stream_interactor.get_stream(account);
if (stream == null) return;