[SCM] ktp-common-internals packaging branch, master, updated. debian/15.12.1-2-1839-gf0635e9

Maximiliano Curia maxy at moszumanska.debian.org
Mon May 9 09:06:52 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-common-internals.git;a=commitdiff;h=0daa877

The following commit has been merged in the master branch:
commit 0daa8771d0616504f91a9b10bf01dc8075bc3091
Author: David Edmundson <kde at davidedmundson.co.uk>
Date:   Thu May 23 13:57:28 2013 +0100

    Store last message sent/received in channel watcher proxy
    
    REVIEW: 110613
---
 KTp/Models/text-channel-watcher-proxy-model.cpp | 58 +++++++++++++++++++++++--
 KTp/types.h                                     |  2 +
 2 files changed, 57 insertions(+), 3 deletions(-)

diff --git a/KTp/Models/text-channel-watcher-proxy-model.cpp b/KTp/Models/text-channel-watcher-proxy-model.cpp
index 0cf0956..b728284 100644
--- a/KTp/Models/text-channel-watcher-proxy-model.cpp
+++ b/KTp/Models/text-channel-watcher-proxy-model.cpp
@@ -26,6 +26,7 @@
 
 #include <KTp/types.h>
 #include <KTp/contact.h>
+#include <KTp/message.h>
 
 
 inline Tp::ChannelClassSpecList channelClasses() {
@@ -38,13 +39,20 @@ class ChannelWatcher : public QObject, public Tp::RefCounted
 public:
     ChannelWatcher(const QPersistentModelIndex &index, const Tp::TextChannelPtr &channel, QObject *parent=0);
     int unreadMessageCount() const;
+    QString lastMessage() const;
+    KTp::Message::MessageDirection lastMessageDirection() const;
     QPersistentModelIndex modelIndex() const;
 Q_SIGNALS:
     void messagesChanged();
     void invalidated();
+private Q_SLOTS:
+    void onMessageReceived(const Tp::ReceivedMessage &message);
+    void onMessageSent(const Tp::Message &message);
 private:
     QPersistentModelIndex m_index;
     Tp::TextChannelPtr m_channel;
+    QString m_lastMessage;
+    KTp::Message::MessageDirection m_lastMessageDirection;
 };
 
 typedef Tp::SharedPtr<ChannelWatcher> ChannelWatcherPtr;
@@ -52,12 +60,15 @@ typedef Tp::SharedPtr<ChannelWatcher> ChannelWatcherPtr;
 ChannelWatcher::ChannelWatcher(const QPersistentModelIndex &index, const Tp::TextChannelPtr &channel, QObject *parent):
     QObject(parent),
     m_index(index),
-    m_channel(channel)
+    m_channel(channel),
+    m_lastMessageDirection(KTp::Message::LocalToRemote)
 {
     connect(channel.data(), SIGNAL(pendingMessageRemoved(Tp::ReceivedMessage)), SIGNAL(messagesChanged()));
-    connect(channel.data(), SIGNAL(messageReceived(Tp::ReceivedMessage)), SIGNAL(messagesChanged()));
     connect(channel.data(), SIGNAL(invalidated(Tp::DBusProxy*,QString,QString)), SIGNAL(invalidated()));
 
+    connect(channel.data(), SIGNAL(messageReceived(Tp::ReceivedMessage)), SLOT(onMessageReceived(Tp::ReceivedMessage)));
+    connect(channel.data(), SIGNAL(messageSent(Tp::Message,Tp::MessageSendingFlags,QString)), SLOT(onMessageSent(Tp::Message)));
+
     //trigger an update to the contact straight away
     QTimer::singleShot(0, this, SIGNAL(messagesChanged()));
 }
@@ -72,8 +83,31 @@ int ChannelWatcher::unreadMessageCount() const
     return m_channel->messageQueue().size();
 }
 
+QString ChannelWatcher::lastMessage() const
+{
+    return m_lastMessage;
+}
+
+KTp::Message::MessageDirection ChannelWatcher::lastMessageDirection() const
+{
+    return m_lastMessageDirection;
+}
 
+void ChannelWatcher::onMessageReceived(const Tp::ReceivedMessage &message)
+{
+    if (!message.isDeliveryReport()) {
+        m_lastMessage = message.text();
+        m_lastMessageDirection = KTp::Message::RemoteToLocal;
+        Q_EMIT messagesChanged();
+    }
+}
 
+void ChannelWatcher::onMessageSent(const Tp::Message &message)
+{
+    m_lastMessage = message.text();
+    m_lastMessageDirection - KTp::Message::LocalToRemote;
+    Q_EMIT messagesChanged();
+}
 
 namespace KTp {
 
@@ -140,7 +174,7 @@ void KTp::TextChannelWatcherProxyModel::observeChannels(const Tp::MethodInvocati
 
 QVariant KTp::TextChannelWatcherProxyModel::data(const QModelIndex &proxyIndex, int role) const
 {
-    QModelIndex sourceIndex = mapToSource(proxyIndex);
+    const QModelIndex sourceIndex = mapToSource(proxyIndex);
     if (role == KTp::ContactHasTextChannelRole) {
         KTp::ContactPtr contact = sourceIndex.data(KTp::ContactRole).value<KTp::ContactPtr>();
         if (contact) {
@@ -160,6 +194,24 @@ QVariant KTp::TextChannelWatcherProxyModel::data(const QModelIndex &proxyIndex,
         }
         return 0;
     }
+    if (role == KTp::ContactLastMessageRole) {
+        KTp::ContactPtr contact = sourceIndex.data(KTp::ContactRole).value<KTp::ContactPtr>();
+        if (contact) {
+            if (d->currentChannels.contains(contact)) {
+                return d->currentChannels[contact]->lastMessage();
+            }
+        }
+        return QString();
+    }
+    if (role == KTp::ContactLastMessageDirectionRole) {
+        KTp::ContactPtr contact = sourceIndex.data(KTp::ContactRole).value<KTp::ContactPtr>();
+        if (contact) {
+            if (d->currentChannels.contains(contact)) {
+                return d->currentChannels[contact]->lastMessageDirection();
+            }
+        }
+        return KTp::Message::LocalToRemote;
+    }
 
     return sourceIndex.data(role);
 }
diff --git a/KTp/types.h b/KTp/types.h
index 82ccbb6..5f56b54 100644
--- a/KTp/types.h
+++ b/KTp/types.h
@@ -65,6 +65,8 @@ namespace KTp
 
         ContactHasTextChannelRole, ///< bool, returns true if a text channel is active for this contact
         ContactUnreadMessageCountRole, ///< int. the number of unread messages in active channels with this contact
+        ContactLastMessageRole, ///string, the last message to/from this contact in an active chat
+        ContactLastMessageDirectionRole, //enum KTp::Message::MessageDirection direction of last message
 
         ContactCanTextChatRole, ///< bool. You and contact can both text chat
         ContactCanFileTransferRole, ///< bool. You and contact can both file transfer

-- 
ktp-common-internals packaging



More information about the pkg-kde-commits mailing list