[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:07:44 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-common-internals.git;a=commitdiff;h=99fdc69
The following commit has been merged in the master branch:
commit 99fdc69f95ecda47cefe1053894d9c46a86620c6
Author: Leon Handreke <leonh at ndreke.de>
Date: Thu Oct 17 23:12:08 2013 +0100
Handle message delivery reports in MessagesModel
Handle message delivery reports and update original message object with
the the new status and possibly an error message.
Introduce a new internal MessagePrivate class to hold extra properties
for MessagesModel to avoid having to extend KTp::Message.
REVIEW: 113222
---
KTp/Declarative/messages-model.cpp | 109 ++++++++++++++++++++++++++++++-------
KTp/Declarative/messages-model.h | 12 +++-
2 files changed, 99 insertions(+), 22 deletions(-)
diff --git a/KTp/Declarative/messages-model.cpp b/KTp/Declarative/messages-model.cpp
index 9cf1606..601c418 100644
--- a/KTp/Declarative/messages-model.cpp
+++ b/KTp/Declarative/messages-model.cpp
@@ -28,13 +28,32 @@
#include <TelepathyQt/Account>
#include "KTp/message-processor.h"
+#include "KTp/message.h"
+
+class MessagePrivate
+{
+ public:
+ MessagePrivate(const KTp::Message &message);
+
+ KTp::Message message;
+ MessagesModel::DeliveryStatus deliveryStatus;
+ QDateTime deliveryReportReceiveTime;
+};
+
+MessagePrivate::MessagePrivate(const KTp::Message &message) :
+ message(message),
+ deliveryStatus(MessagesModel::DeliveryStatusUnknown)
+{
+}
class MessagesModel::MessagesModelPrivate
{
public:
Tp::TextChannelPtr textChannel;
Tp::AccountPtr account;
- QList<KTp::Message> messages;
+ QList<MessagePrivate> messages;
+ // For fast lookup of original messages upon receipt of a message delivery report.
+ QHash<QString /*messageToken*/, QPersistentModelIndex> messagesByMessageToken;
bool visible;
};
@@ -51,6 +70,8 @@ MessagesModel::MessagesModel(const Tp::AccountPtr &account, QObject *parent) :
roles[SenderIdRole] = "senderId";
roles[SenderAliasRole] = "senderAlias";
roles[SenderAvatarRole] = "senderAvatar";
+ roles[DeliveryStatusRole] = "deliveryStatus";
+ roles[DeliveryReportReceiveTimeRole] = "deliveryReportReceiveTime";
setRoleNames(roles);
d->account = account;
@@ -102,10 +123,10 @@ void MessagesModel::setTextChannel(const Tp::TextChannelPtr &channel)
QList<Tp::ReceivedMessage> messageQueue = channel->messageQueue();
Q_FOREACH(const Tp::ReceivedMessage &message, messageQueue) {
bool messageAlreadyInModel = false;
- Q_FOREACH(const KTp::Message ¤t, d->messages) {
+ Q_FOREACH(const MessagePrivate ¤t, d->messages) {
//FIXME: docs say messageToken can return an empty string. What to do if that happens?
//Tp::Message has an == operator. maybe I can use that?
- if (current.token() == message.messageToken()) {
+ if (current.message.token() == message.messageToken()) {
messageAlreadyInModel = true;
break;
}
@@ -124,18 +145,51 @@ void MessagesModel::onMessageReceived(const Tp::ReceivedMessage &message)
kDebug() << "messageType = " << message.messageType();
kDebug() << "messageToken =" << message.messageToken();
- //delivery reports do not contain message text, everything else does.
- //simply ack these straight away
+ if (message.isDeliveryReport()) {
+ d->textChannel->acknowledge(QList<Tp::ReceivedMessage>() << message);
+
+ Tp::ReceivedMessage::DeliveryDetails deliveryDetails = message.deliveryDetails();
+ if(!deliveryDetails.hasOriginalToken()) {
+ kDebug() << "Delivery report without original message token received.";
+ // Matching the delivery report to the original message is impossible without the token.
+ return;
+ }
+ kDebug() << "originalMessageToken =" << deliveryDetails.originalToken();
- //TODO search through d->messages() for messages with identical messageToken and update sending state as appropriate
+ QPersistentModelIndex originalMessageIndex = d->messagesByMessageToken.value(
+ deliveryDetails.originalToken());
+ if (!originalMessageIndex.isValid() || originalMessageIndex.row() >= d->messages.count()) {
+ // The original message for this delivery report was not found.
+ return;
+ }
- if (message.messageType() == Tp::ChannelTextMessageTypeDeliveryReport) {
- d->textChannel->acknowledge(QList<Tp::ReceivedMessage>() << message);
+ MessagePrivate &originalMessage = d->messages[originalMessageIndex.row()];
+ kDebug() << "Got delivery status" << deliveryDetails.status()
+ << "for message with text" << originalMessage.message.mainMessagePart();
+ originalMessage.deliveryReportReceiveTime = message.received();
+ switch(deliveryDetails.status()) {
+ case Tp::DeliveryStatusPermanentlyFailed:
+ case Tp::DeliveryStatusTemporarilyFailed:
+ originalMessage.deliveryStatus = DeliveryStatusFailed;
+ if (deliveryDetails.hasDebugMessage()) {
+ kDebug() << "Delivery failure debug message:" << deliveryDetails.debugMessage();
+ }
+ break;
+ case Tp::DeliveryStatusDelivered:
+ originalMessage.deliveryStatus = DeliveryStatusDelivered;
+ break;
+ case Tp::DeliveryStatusRead:
+ originalMessage.deliveryStatus = DeliveryStatusRead;
+ break;
+ default:
+ originalMessage.deliveryStatus = DeliveryStatusUnknown;
+ break;
+ }
+ Q_EMIT dataChanged(originalMessageIndex, originalMessageIndex);
} else {
int length = rowCount();
beginInsertRows(QModelIndex(), length, length);
-
d->messages.append(KTp::MessageProcessor::instance()->processIncomingMessage(
message, d->account, d->textChannel));
@@ -152,14 +206,21 @@ void MessagesModel::onMessageReceived(const Tp::ReceivedMessage &message)
void MessagesModel::onMessageSent(const Tp::Message &message, Tp::MessageSendingFlags flags, const QString &messageToken)
{
Q_UNUSED(flags);
- Q_UNUSED(messageToken);
int length = rowCount();
beginInsertRows(QModelIndex(), length, length);
kDebug() << "text =" << message.text();
- d->messages.append(KTp::MessageProcessor::instance()->processIncomingMessage(
- message, d->account, d->textChannel));
+ const KTp::Message &newMessage = KTp::MessageProcessor::instance()->processIncomingMessage(
+ message, d->account, d->textChannel);
+ d->messages.append(newMessage);
+
+ if (!messageToken.isEmpty()) {
+ // Insert the message into the lookup table for delivery reports.
+ const QPersistentModelIndex &modelIndex(createIndex(length, 0));
+ d->messagesByMessageToken.insert(messageToken, modelIndex);
+ }
+
endInsertRows();
}
@@ -173,17 +234,17 @@ QVariant MessagesModel::data(const QModelIndex &index, int role) const
QVariant result;
if (index.isValid()) {
- const KTp::Message message = d->messages[index.row()];
+ const MessagePrivate m = d->messages[index.row()];
switch (role) {
case TextRole:
- result = message.finalizedMessage();
+ result = m.message.finalizedMessage();
break;
case TypeRole:
- if (message.type() == Tp::ChannelTextMessageTypeAction) {
+ if (m.message.type() == Tp::ChannelTextMessageTypeAction) {
result = MessageTypeAction;
} else {
- if (message .direction() == KTp::Message::LocalToRemote) {
+ if (m.message.direction() == KTp::Message::LocalToRemote) {
result = MessageTypeOutgoing;
} else {
result = MessageTypeIncoming;
@@ -191,19 +252,25 @@ QVariant MessagesModel::data(const QModelIndex &index, int role) const
}
break;
case TimeRole:
- result = message.time();
+ result = m.message.time();
break;
case SenderIdRole:
- result = message.senderId();
+ result = m.message.senderId();
break;
case SenderAliasRole:
- result = message.senderAlias();
+ result = m.message.senderAlias();
break;
case SenderAvatarRole:
- if (message.sender()) {
- result = QVariant::fromValue(message.sender()->avatarPixmap());
+ if (m.message.sender()) {
+ result = QVariant::fromValue(m.message.sender()->avatarPixmap());
}
break;
+ case DeliveryStatusRole:
+ result = m.deliveryStatus;
+ break;
+ case DeliveryReportReceiveTimeRole:
+ result = m.deliveryReportReceiveTime;
+ break;
};
} else {
kError() << "Attempting to access data at invalid index (" << index << ")";
diff --git a/KTp/Declarative/messages-model.h b/KTp/Declarative/messages-model.h
index a0f1565..24d2cb8 100644
--- a/KTp/Declarative/messages-model.h
+++ b/KTp/Declarative/messages-model.h
@@ -29,6 +29,7 @@ class MessagesModel : public QAbstractListModel
{
Q_OBJECT
Q_ENUMS(MessageType)
+ Q_ENUMS(DeliveryStatus)
Q_PROPERTY(bool visibleToUser READ isVisibleToUser WRITE setVisibleToUser NOTIFY visibleToUserChanged)
Q_PROPERTY(int unreadCount READ unreadCount NOTIFY unreadCountChanged)
Q_PROPERTY(bool shouldStartOpened READ shouldStartOpened CONSTANT)
@@ -43,7 +44,9 @@ class MessagesModel : public QAbstractListModel
TimeRole, //QDateTime
SenderIdRole, //string
SenderAliasRole, //string
- SenderAvatarRole //pixmap
+ SenderAvatarRole, //pixmap
+ DeliveryStatusRole, //MessagesModel::DeliveryStatus
+ DeliveryReportReceiveTimeRole //QDateTime
};
enum MessageType {
@@ -53,6 +56,13 @@ class MessagesModel : public QAbstractListModel
MessageTypeNotice
};
+ enum DeliveryStatus {
+ DeliveryStatusUnknown,
+ DeliveryStatusDelivered,
+ DeliveryStatusRead, // implies DeliveryStatusDelivered
+ DeliveryStatusFailed
+ };
+
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
--
ktp-common-internals packaging
More information about the pkg-kde-commits
mailing list