[Desktop] Allow SMS app to handle newly recieved messages

Summary:
Update sms app model to use new conversationUpdated signal

Filter incoming messages which belong to a different conversation than the one currently being viewed

See Android-side diff D15360 which adds support for sending live updates when a new message is sent or received

Test Plan:
This patch relies on D15360 for Android-side support
  - Positive case:
    - Open a conversation in the SMS app
    - Receive a new message into that conversation (text yourself?)
    - Verify that the new message appears at the bottom of the appropriate conversation
  - Negative case:
    - Open a conversation in the SMS app
    - Receive a new message into a different conversation (text yourself?)
    - Verify that the new message does *not* appear in the open conversation

Reviewers: #kde_connect, nicolasfella

Reviewed By: #kde_connect, nicolasfella

Subscribers: nicolasfella, kdeconnect

Tags: #kde_connect

Differential Revision: https://phabricator.kde.org/D15409
This commit is contained in:
Simon Redman 2018-09-16 16:20:22 -06:00
parent 64062b3cc9
commit 23d931cb10
4 changed files with 31 additions and 3 deletions

View file

@ -96,7 +96,7 @@ void ConversationsDbusInterface::addMessage(const ConversationMessage &message)
Q_EMIT conversationCreated(threadId); Q_EMIT conversationCreated(threadId);
} else } else
{ {
Q_EMIT conversationUpdated(threadId); Q_EMIT conversationUpdated(message.toVariant());
} }
} }

View file

@ -72,8 +72,8 @@ public Q_SLOTS:
Q_SIGNALS: Q_SIGNALS:
Q_SCRIPTABLE void conversationCreated(const QString& threadID); Q_SCRIPTABLE void conversationCreated(const QString& threadID);
Q_SCRIPTABLE void conversationRemoved(const QString& threadID); Q_SCRIPTABLE void conversationRemoved(const QString& threadID);
Q_SCRIPTABLE void conversationUpdated(const QString& threadID); Q_SCRIPTABLE void conversationUpdated(const QVariantMap& msg) const;
Q_SCRIPTABLE void conversationMessageReceived(const QVariantMap & msg, int pos) const; Q_SCRIPTABLE void conversationMessageReceived(const QVariantMap& msg, int pos) const;
private /*methods*/: private /*methods*/:
QString newId(); //Generates successive identifitiers to use as public ids QString newId(); //Generates successive identifitiers to use as public ids

View file

@ -67,6 +67,7 @@ void ConversationModel::setDeviceId(const QString& deviceId)
m_conversationsInterface = new DeviceConversationsDbusInterface(deviceId, this); m_conversationsInterface = new DeviceConversationsDbusInterface(deviceId, this);
connect(m_conversationsInterface, SIGNAL(conversationMessageReceived(QVariantMap, int)), this, SLOT(createRowFromMessage(QVariantMap, int))); connect(m_conversationsInterface, SIGNAL(conversationMessageReceived(QVariantMap, int)), this, SLOT(createRowFromMessage(QVariantMap, int)));
connect(m_conversationsInterface, SIGNAL(conversationUpdated(QVariantMap)), this, SLOT(handleConversationUpdate(QVariantMap)));
} }
void ConversationModel::sendReplyToConversation(const QString& message) void ConversationModel::sendReplyToConversation(const QString& message)
@ -78,9 +79,35 @@ void ConversationModel::sendReplyToConversation(const QString& message)
void ConversationModel::createRowFromMessage(const QVariantMap& msg, int pos) void ConversationModel::createRowFromMessage(const QVariantMap& msg, int pos)
{ {
const ConversationMessage message(msg); const ConversationMessage message(msg);
if (!(message.threadID() == m_threadId.toInt())) {
// Because of the asynchronous nature of the current implementation of this model, if the
// user clicks quickly between threads or for some other reason a message comes when we're
// not expecting it, we should not display it in the wrong place
qCDebug(KDECONNECT_SMS_CONVERSATION_MODEL)
<< "Got a message for a thread" << message.threadID()
<< "but we are currently viewing" << m_threadId
<< "Discarding.";
return;
}
auto item = new QStandardItem; auto item = new QStandardItem;
item->setText(message.body()); item->setText(message.body());
item->setData(message.type() == ConversationMessage::MessageTypeSent, FromMeRole); item->setData(message.type() == ConversationMessage::MessageTypeSent, FromMeRole);
item->setData(message.date(), DateRole); item->setData(message.date(), DateRole);
insertRow(pos, item); insertRow(pos, item);
} }
void ConversationModel::handleConversationUpdate(const QVariantMap& msg)
{
const ConversationMessage message(msg);
if (!(message.threadID() == m_threadId.toInt())) {
// If a conversation which we are not currently viewing was updated, discard the information
qCDebug(KDECONNECT_SMS_CONVERSATION_MODEL)
<< "Saw update for thread" << message.threadID()
<< "but we are currently viewing" << m_threadId;
return;
}
createRowFromMessage(msg, 0);
}

View file

@ -56,6 +56,7 @@ public:
private Q_SLOTS: private Q_SLOTS:
void createRowFromMessage(const QVariantMap &msg, int pos); void createRowFromMessage(const QVariantMap &msg, int pos);
void handleConversationUpdate(const QVariantMap &msg);
private: private:
DeviceConversationsDbusInterface* m_conversationsInterface; DeviceConversationsDbusInterface* m_conversationsInterface;