[Telepathy-commits] [telepathy-qt4/master] ContactManager: don't second-guess the connection manager

Simon McVittie simon.mcvittie at collabora.co.uk
Thu Mar 5 09:00:37 PST 2009


Although we have flags to indicate which actions are likely to work, their
interactions are complex, so we should only reject attempts to take action
if the channel doesn't exist at all. In all other cases we should attempt
the D-Bus call, even if we expect it to fail, so the connection manager
can return an appropriate error.
---
 TelepathyQt4/Client/contact-manager.cpp |   35 ++++++++----------------------
 1 files changed, 10 insertions(+), 25 deletions(-)

diff --git a/TelepathyQt4/Client/contact-manager.cpp b/TelepathyQt4/Client/contact-manager.cpp
index 6cf7918..63c5351 100644
--- a/TelepathyQt4/Client/contact-manager.cpp
+++ b/TelepathyQt4/Client/contact-manager.cpp
@@ -203,14 +203,11 @@ bool ContactManager::canRequestContactsPresenceSubscription() const
 PendingOperation *ContactManager::requestContactsPresenceSubscription(
         const QList<QSharedPointer<Contact> > &contacts, const QString &message)
 {
-    if (!canRequestContactsPresenceSubscription()) {
-        warning() << "Contact subscription requested, "
-            "but unable to add contacts";
+    if (!mPriv->subscribeChannel) {
         return new PendingFailure(this, TELEPATHY_ERROR_NOT_IMPLEMENTED,
-                "Cannot request contacts presence subscription");
+                "Cannot subscribe to contacts' presence on this protocol");
     }
 
-    Q_ASSERT(mPriv->subscribeChannel);
     return mPriv->subscribeChannel->groupAddContacts(contacts, message);
 }
 
@@ -233,14 +230,11 @@ bool ContactManager::canRemoveContactsPresenceSubscription() const
 PendingOperation *ContactManager::removeContactsPresenceSubscription(
         const QList<QSharedPointer<Contact> > &contacts, const QString &message)
 {
-    if (!canRemoveContactsPresenceSubscription()) {
-        warning() << "Contact subscription removal requested, "
-            "but unable to remove contacts";
+    if (!mPriv->subscribeChannel) {
         return new PendingFailure(this, TELEPATHY_ERROR_NOT_IMPLEMENTED,
-                "Cannot remove contacts presence subscription");
+                "Cannot subscribe to contacts' presence on this protocol");
     }
 
-    Q_ASSERT(mPriv->subscribeChannel);
     return mPriv->subscribeChannel->groupRemoveContacts(contacts, message);
 }
 
@@ -266,14 +260,11 @@ bool ContactManager::canAuthorizeContactsPresencePublication() const
 PendingOperation *ContactManager::authorizeContactsPresencePublication(
         const QList<QSharedPointer<Contact> > &contacts, const QString &message)
 {
-    if (!canAuthorizeContactsPresencePublication()) {
-        warning() << "Contact publication authorization requested, "
-            "but unable to authorize contacts";
+    if (!mPriv->publishChannel) {
         return new PendingFailure(this, TELEPATHY_ERROR_NOT_IMPLEMENTED,
-                "Cannot authorize contacts presence publication");
+                "Cannot control publication of presence on this protocol");
     }
 
-    Q_ASSERT(mPriv->publishChannel);
     return mPriv->publishChannel->groupAddContacts(contacts, message);
 }
 
@@ -300,14 +291,11 @@ bool ContactManager::canRemoveContactsPresencePublication() const
 PendingOperation *ContactManager::removeContactsPresencePublication(
         const QList<QSharedPointer<Contact> > &contacts, const QString &message)
 {
-    if (!canRemoveContactsPresencePublication()) {
-        warning() << "Contact publication remove requested, "
-            "but unable to remove contacts";
+    if (!mPriv->publishChannel) {
         return new PendingFailure(this, TELEPATHY_ERROR_NOT_IMPLEMENTED,
-                "Cannot remove contacts presence publication");
+                "Cannot control publication of presence on this protocol");
     }
 
-    Q_ASSERT(mPriv->publishChannel);
     return mPriv->publishChannel->groupRemoveContacts(contacts, message);
 }
 
@@ -331,14 +319,11 @@ bool ContactManager::canBlockContacts() const
 PendingOperation *ContactManager::blockContacts(
         const QList<QSharedPointer<Contact> > &contacts, bool value)
 {
-    if (!canBlockContacts()) {
-        warning() << "Contact blocking requested, "
-            "but unable to block contacts";
+    if (!mPriv->denyChannel) {
         return new PendingFailure(this, TELEPATHY_ERROR_NOT_IMPLEMENTED,
-                "Cannot block contacts");
+                "Cannot block contacts on this protocol");
     }
 
-    Q_ASSERT(mPriv->denyChannel);
     if (value) {
         return mPriv->denyChannel->groupAddContacts(contacts);
     }
-- 
1.5.6.5




More information about the telepathy-commits mailing list