[telepathy-qt4/master] TextChannel: Added chatState method for retrieving contacts current chat state.

Andre Moreira Magalhaes (andrunko) andre.magalhaes at collabora.co.uk
Tue Nov 3 10:24:09 PST 2009


---
 TelepathyQt4/text-channel.cpp |   31 +++++++++++++++++++++++++++++++
 TelepathyQt4/text-channel.h   |    3 +++
 2 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/TelepathyQt4/text-channel.cpp b/TelepathyQt4/text-channel.cpp
index 6ac4d3f..e76c768 100644
--- a/TelepathyQt4/text-channel.cpp
+++ b/TelepathyQt4/text-channel.cpp
@@ -161,6 +161,7 @@ struct TELEPATHY_QT4_NO_EXPORT TextChannel::Private
         uint state;
     };
     QList<ChatStateEvent *> chatStateQueue;
+    QHash<ContactPtr, ChannelChatState> chatStates;
 
     QSet<uint> awaitingContacts;
 };
@@ -326,6 +327,10 @@ void TextChannel::Private::enableChatStateNotifications(
             SIGNAL(ChatStateChanged(uint, uint)),
             SLOT(onChatStateChanged(uint, uint)));
 
+    /* FIXME Download initial contacts chat state.
+     * See http://bugs.freedesktop.org/show_bug.cgi?id=24882
+     */
+
     self->readinessHelper->setIntrospectCompleted(FeatureChatState, true);
 }
 
@@ -459,6 +464,8 @@ void TextChannel::Private::processChatStateQueue()
             break;
         }
 
+        chatStates.insert(e->contact, (ChannelChatState) e->state);
+
         // if we reach here, the Contact object is ready
         emit parent->chatStateChanged(e->contact, (ChannelChatState) e->state);
 
@@ -780,6 +787,30 @@ QList<ReceivedMessage> TextChannel::messageQueue() const
     return mPriv->messages;
 }
 
+/**
+ * Return the contact \a contact current chat state.
+ *
+ * If hasChatStateInterface() returns false, this method will always return
+ * ChannelChatStateInactive.
+ *
+ * This method requires TextChannel::FeatureChatState to be enabled.
+ *
+ * \return A contact current chat state.
+ */
+ChannelChatState TextChannel::chatState(const ContactPtr &contact) const
+{
+    if (!isReady(FeatureChatState)) {
+        warning() << "TextChannel::chatState() used with "
+            "FeatureChatState not ready";
+        return ChannelChatStateInactive;
+    }
+
+    if (mPriv->chatStates.contains(contact)) {
+        return mPriv->chatStates.value(contact);
+    }
+    return ChannelChatStateInactive;
+}
+
 void TextChannel::onAcknowledgePendingMessagesReply(
         QDBusPendingCallWatcher *watcher)
 {
diff --git a/TelepathyQt4/text-channel.h b/TelepathyQt4/text-channel.h
index 03dcb04..b47ddab 100644
--- a/TelepathyQt4/text-channel.h
+++ b/TelepathyQt4/text-channel.h
@@ -88,6 +88,9 @@ public:
     // requires FeatureMessageQueue
     QList<ReceivedMessage> messageQueue() const;
 
+    // requires FeatureChatState
+    ChannelChatState chatState(const ContactPtr &contact) const;
+
 public Q_SLOTS:
     void acknowledge(const QList<ReceivedMessage> &messages);
 
-- 
1.5.6.5




More information about the telepathy-commits mailing list