[SMS App] Basic plain-text MMS support

## Summary

Desktop companion to https://invent.kde.org/kde/kdeconnect-android/merge_requests/78

Give desktop SMS app a basic understanding of the MMSes coming from Android:
- Show a fake body if we get an attachment we can't display (for now, any attachment)
- Display a fake contact header for multi-target messages since Android does not yet export multi-target address information
- Disable attempting to reply to multi-target messages

BUG: 398889

## Test Plan
### Before:
MMS messages were silently dropped, meaning:
 - Group MMS conversations were not visible
 - Single-target conversations with the most-recent message an MMS were not visible

### After:
 - Install https://invent.kde.org/kde/kdeconnect-android/merge_requests/78
 - Multi-target conversations are displayed (kind of ugly, since they have no contact information
 - Single-target conversations which end with an MMS are displayed
 - Plain-text MMS is displayed nicely
 - MMS attachments don't show
   - MMS which are only an attachment with no body are displayed with a dummy body
This commit is contained in:
Simon Redman 2019-07-19 15:29:28 +00:00
parent 875eba8e07
commit ee9547ed89
7 changed files with 30 additions and 5 deletions

View file

@ -47,6 +47,7 @@ public:
*/
enum Events {
EventTextMessage = 0x1, // This message has a body field which contains pure, human-readable text
EventMultiTarget = 0x2, // This is a multitarget (group) message which has an "addresses" field which is a list of participants in the group
};
/**
@ -77,6 +78,7 @@ public:
QVariantMap toVariant() const;
bool containsTextBody() const { return (eventField() & ConversationMessage::EventTextMessage); }
bool isMultitarget() const { return (eventField() & ConversationMessage::EventMultiTarget); }
protected:
/**

View file

@ -107,8 +107,8 @@ bool SmsPlugin::handleBatchMessages(const NetworkPacket& np)
ConversationMessage message(body.toMap());
if (message.containsTextBody()) {
forwardToTelepathy(message);
messagesList.append(message);
}
messagesList.append(message);
}
m_conversationInterface->addMessages(messagesList);

View file

@ -23,6 +23,9 @@
#include <QString>
#include <QLoggingCategory>
#include <KLocalizedString>
#include "interfaces/conversationmessage.h"
#include "interfaces/dbusinterfaces.h"
#include "smshelper.h"
@ -42,6 +45,7 @@ ConversationListModel::ConversationListModel(QObject* parent)
roles.insert(AddressRole, "address");
roles.insert(PersonUriRole, "personUri");
roles.insert(ConversationIdRole, "conversationId");
roles.insert(MultitargetRole, "isMultitarget");
roles.insert(DateRole, "date");
setItemRoleNames(roles);
@ -159,6 +163,14 @@ void ConversationListModel::createRowFromMessage(const QVariantMap& msg)
item->setData(message.threadID(), ConversationIdRole);
}
// TODO: Upgrade to support other kinds of media
// Get the body that we should display
QString displayBody = message.containsTextBody() ? message.body() : i18n("(Unsupported Message Type)");
// TODO: Upgrade with multitarget support
if (message.isMultitarget()) {
item->setText(i18n("(Multitarget Message)"));
}
// Update the message if the data is newer
// This will be true if a conversation receives a new message, but false when the user
// does something to trigger past conversation history loading
@ -168,8 +180,9 @@ void ConversationListModel::createRowFromMessage(const QVariantMap& msg)
// If there was no old data or incoming data is newer, update the record
item->setData(message.address(), AddressRole);
item->setData(message.type() == ConversationMessage::MessageTypeSent, FromMeRole);
item->setData(message.body(), Qt::ToolTipRole);
item->setData(displayBody, Qt::ToolTipRole);
item->setData(message.date(), DateRole);
item->setData(message.isMultitarget(), MultitargetRole);
}
if (toadd)

View file

@ -83,6 +83,7 @@ public:
AddressRole,
ConversationIdRole,
DateRole,
MultitargetRole, // Indicate that this conversation is multitarget
};
Q_ENUM(Roles)

View file

@ -21,6 +21,9 @@
#include "conversationmodel.h"
#include <QLoggingCategory>
#include <KLocalizedString>
#include "interfaces/conversationmessage.h"
Q_LOGGING_CATEGORY(KDECONNECT_SMS_CONVERSATION_MODEL, "kdeconnect.sms.conversation")
@ -110,8 +113,12 @@ void ConversationModel::createRowFromMessage(const QVariantMap& msg, int pos)
return;
}
// TODO: Upgrade to support other kinds of media
// Get the body that we should display
QString displayBody = message.containsTextBody() ? message.body() : i18n("(Unsupported Message Type)");
auto item = new QStandardItem;
item->setText(message.body());
item->setText(displayBody);
item->setData(message.type() == ConversationMessage::MessageTypeSent, FromMeRole);
item->setData(message.date(), DateRole);
insertRow(pos, item);

View file

@ -40,6 +40,7 @@ Kirigami.ScrollablePage
property string deviceId
// property QtObject device
property string conversationId
property bool isMultitarget
property string initialMessage
property string phoneNumber
@ -127,7 +128,7 @@ Kirigami.ScrollablePage
footer: Pane {
id: sendingArea
enabled: page.deviceConnected
enabled: page.deviceConnected && !page.isMultitarget
layer.enabled: sendingArea.enabled
layer.effect: DropShadow {
verticalOffset: 1
@ -148,7 +149,7 @@ Kirigami.ScrollablePage
TextArea {
id: messageField
Layout.fillWidth: true
placeholderText: i18n("Compose message")
placeholderText: page.isMultitarget ? i18n("Replying to multitarget messages is not supported") : i18n("Compose message")
wrapMode: TextArea.Wrap
topPadding: Kirigami.Units.gridUnit * 0.5
bottomPadding: topPadding

View file

@ -149,6 +149,7 @@ Kirigami.ScrollablePage
personUri: model.personUri,
phoneNumber: address,
conversationId: model.conversationId,
isMultitarget: isMultitarget,
initialMessage: page.initialMessage,
device: device})
initialMessage = ""