[ekiga] Jabber/XMPP: automatically ask to subscribe to a contact's presence if we just added it to the roste
- From: Julien Puydt <jpuydt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ekiga] Jabber/XMPP: automatically ask to subscribe to a contact's presence if we just added it to the roste
- Date: Sat, 27 Oct 2012 12:46:38 +0000 (UTC)
commit 68050abe8a6936e941b840c92095530e16d8ab67
Author: Julien Puydt <jpuydt free fr>
Date: Sat Oct 27 12:21:20 2012 +0200
Jabber/XMPP: automatically ask to subscribe to a contact's presence if we just added it to the roster
plugins/loudmouth/loudmouth-heap-roster.cpp | 29 +++++++++++++++++++++++++++
plugins/loudmouth/loudmouth-heap-roster.h | 9 ++++++++
2 files changed, 38 insertions(+), 0 deletions(-)
---
diff --git a/plugins/loudmouth/loudmouth-heap-roster.cpp b/plugins/loudmouth/loudmouth-heap-roster.cpp
index 4f0f18f..607aaf0 100644
--- a/plugins/loudmouth/loudmouth-heap-roster.cpp
+++ b/plugins/loudmouth/loudmouth-heap-roster.cpp
@@ -294,6 +294,34 @@ LM::HeapRoster::parse_roster (LmMessageNode* query)
PresentityPtr presentity(new Presentity (connection, node));
presentity->chat_requested.connect (boost::bind (&LM::HeapRoster::on_chat_requested, this, presentity));
add_presentity (presentity);
+ const gchar* subscription = lm_message_node_get_attribute (node, "subscription");
+ if (subscription != NULL && strcmp (subscription, "none") == 0) {
+
+ const gchar* ask = lm_message_node_get_attribute (node, "ask");
+ if (ask == NULL || (ask != NULL && strcmp (ask, "subscribe") != 0)) {
+
+ std::set<std::string>::iterator iter = items_added_by_me.find (presentity->get_jid ());
+ if (iter != items_added_by_me.end ()) {
+
+ /* if we're here then this is a new contact, we are not subscribed to it,
+ * and we did not ask to be subscribed to it and we added it recently:
+ * let's ask for subscription!
+ *
+ * Beware that the first three actions could have been done from another client,
+ * so that last condition is important so we don't start doing things
+ * in the back of the user!
+ */
+ items_added_by_me.erase (iter);
+ LmMessage* subscribe = lm_message_new (NULL, LM_MESSAGE_TYPE_PRESENCE);
+ lm_message_node_set_attributes (lm_message_get_node (subscribe),
+ "to", presentity->get_jid ().c_str (),
+ "type", "subscribe",
+ NULL);
+ lm_connection_send (connection, subscribe, NULL);
+ lm_message_unref (subscribe);
+ }
+ }
+ }
}
}
}
@@ -350,6 +378,7 @@ LM::HeapRoster::add_item_form_submitted (bool submitted,
g_free (escaped);
}
+ items_added_by_me.insert (jid);
lm_connection_send (connection, message, NULL);
lm_message_unref (message);
}
diff --git a/plugins/loudmouth/loudmouth-heap-roster.h b/plugins/loudmouth/loudmouth-heap-roster.h
index 7b01f88..f2ad46b 100644
--- a/plugins/loudmouth/loudmouth-heap-roster.h
+++ b/plugins/loudmouth/loudmouth-heap-roster.h
@@ -121,6 +121,15 @@ namespace LM
LmHandlerResult message_handler_muc (LmMessage* message);
const std::set<std::string> existing_groups () const;
+
+ /* when adding an item, we first ask to add it to the roster,
+ * then get notified that it was really added,
+ * and then we could ask to subscribe to it,
+ * *but* we don't want to do that if that was done from another client
+ * so when we ask to add it, we note it in that set, so when we get
+ * notified it was added, we can know we did that and act accordingly.
+ */
+ std::set<std::string> items_added_by_me;
};
typedef boost::shared_ptr<HeapRoster> HeapRosterPtr;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]