From 2f3cf0d2ff65a6ed4af69ec978b81a34aabd7c6a Mon Sep 17 00:00:00 2001 From: Jussi Kukkonen Date: Thu, 1 Sep 2011 22:53:55 +0300 Subject: [PATCH] mail notification: ensure google notification setting is correct Google XMPP server has an (extension) setting that can be used to enable mail notifications, see https://code.google.com/apis/talk/jep_extensions/usersettings.html https://bugs.freedesktop.org/show_bug.cgi?id=40565 --- src/conn-mail-notif.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ src/namespaces.h | 1 + 2 files changed, 60 insertions(+), 0 deletions(-) diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index 88aac0d..033249a 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -72,6 +72,7 @@ struct _GabbleConnectionMailNotificationPrivate guint poll_timeout_id; guint poll_count; GList *inbox_url_requests; /* list of DBusGMethodInvocation */ + gboolean google_settings_set; }; @@ -463,6 +464,24 @@ store_unread_mails (GabbleConnection *conn, g_ptr_array_free (mails_removed, TRUE); } +static void +set_settings_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + GError *error = NULL; + WockyPorter *porter = WOCKY_PORTER (source_object); + WockyStanza *reply = wocky_porter_send_iq_finish (porter, res, &error); + + if (reply == NULL || + wocky_stanza_extract_errors (reply, NULL, &error, NULL, NULL)) + { + DEBUG ("Failed to set google user settings: %s", error->message); + g_error_free (error); + } + + tp_clear_object (&reply); +} static void query_unread_mails_cb (GObject *source_object, @@ -579,6 +598,44 @@ new_mail_handler (WockyPorter *porter, return TRUE; } +/* Make sure google knows we want mail notifications. According to + * Google clients should set 'mailnotifications' to true when needed + * but never to false, for compatibility reasons: + * https://code.google.com/apis/talk/jep_extensions/usersettings.html#3 */ +static void +ensure_google_settings (GabbleConnection *self) +{ + TpBaseConnection *base_conn = TP_BASE_CONNECTION (self); + WockyStanza *query; + WockyPorter *porter; + + if (self->mail_priv->google_settings_set) + return; + + if (!(self->features & GABBLE_CONNECTION_FEATURES_GOOGLE_MAIL_NOTIFY)) + return; + + if (base_conn->status != TP_CONNECTION_STATUS_CONNECTED) + return; + + + porter = wocky_session_get_porter (self->session); + query = wocky_stanza_build (WOCKY_STANZA_TYPE_IQ, + WOCKY_STANZA_SUB_TYPE_SET, NULL, NULL, + '@', "id", "user-setting-3", + '(', "usersetting", + ':', NS_GOOGLE_SETTING, + '(', "mailnotifications", + '@', "value", "true", + ')', + ')', + NULL); + wocky_porter_send_iq_async (porter, query, NULL, + set_settings_cb, self); + self->mail_priv->google_settings_set = TRUE; + + g_object_unref (query); +} static void connection_status_changed (GabbleConnection *conn, @@ -606,6 +663,7 @@ connection_status_changed (GabbleConnection *conn, { DEBUG ("Someone is already interested in MailNotification"); update_unread_mails (conn); + ensure_google_settings (conn); } } } @@ -620,6 +678,7 @@ mail_clients_interested_cb (GabbleConnection *self, self->mail_priv->interested = TRUE; update_unread_mails (self); + ensure_google_settings (self); } /* called on transition from 1 to 0 interested clients */ diff --git a/src/namespaces.h b/src/namespaces.h index d39853d..bacbb2a 100644 --- a/src/namespaces.h +++ b/src/namespaces.h @@ -118,6 +118,7 @@ #define NS_VERSION "jabber:iq:version" #define NS_GEOLOC "http://jabber.org/protocol/geoloc" #define NS_GOOGLE_MAIL_NOTIFY "google:mail:notify" +#define NS_GOOGLE_SETTING "google:setting" #define NS_TEMPPRES "urn:xmpp:temppres:0" #define NS_GOOGLE_SHARED_STATUS "google:shared-status" -- 1.7.6