Commit 35c53e24 authored by Martin Straka's avatar Martin Straka

Added reply on the message

parent cd00dbe6
......@@ -53,7 +53,7 @@ Component {
if (msgType == MessageType.TYPE_RECEIVED) {
str = qsTr("Received message")
}
return str + " " + msgId + "\n" + qsTr("Attachment operations")
return str + " " + msgId + "\n" + qsTr("Message operations")
}
Item {
anchors.left: parent.left
......@@ -80,10 +80,16 @@ Component {
image: "qrc:/ui/datovka-email-download.svg"
showNext: false
}
ListElement {
index: 4
name: qsTr("Reply")
image: "qrc:/ui/reply.svg"
showNext: false
}
ListElement {
index: 1
name: qsTr("Send attachments by email")
image: "qrc:/ui/reply.svg"
image: "qrc:/ui/attach-to-mail.svg"
showNext: false
}
ListElement {
......@@ -152,18 +158,33 @@ Component {
onClicked: {
if (index == 0) {
isds.doIsdsAction("downloadMessage", userName)
pageView.pop(StackView.Immediate)
} else if (index == 1) {
files.sendAttachmentsWithEmailFromDb(userName, msgId)
pageView.pop(StackView.Immediate)
} else if (index == 2) {
files.saveAttachmentsToDiskDb(userName, msgId)
pageView.pop(StackView.Immediate)
} else if (index == 3) {
if (files.deleteAttachmentsFromDb(userName, msgId)) {
if (attachmentModel != null) {
attachmentModel.clearAll()
}
}
pageView.pop(StackView.Immediate)
} else if (index == 4) {
// Allows reply only for received messages
if (msgType == MessageType.TYPE_RECEIVED) {
pageView.replace(pageSendMessage, {
"pageView": pageView,
"statusBar": statusBar,
"userName": userName,
"msgId": msgId,
"msgType": msgType,
"action": "reply"
}, StackView.Immediate)
}
}
pageView.pop(StackView.Immediate)
}
}
}
......
......@@ -65,9 +65,28 @@ Item {
"path": filePath, "img": fileIcon, "size": fileSize, "zfo": isZfo});
}
/* Set reply message data and add recipient to model */
function setReplyData(userName, msgId) {
headerBar.title = qsTr("Reply message %1").arg(msgId) + " (" + userName + ")"
// get some message envelope data and add recipient to recipient model
var msgEnvelope = messages.getReplyMsgDataAndSetRecipient(userName, msgId, recipBoxModel)
dmAnnotation.text = "Re: " + msgEnvelope.dmAnnotation
dmSenderRefNumber.text = msgEnvelope.dmRecipientRefNumber
dmSenderIdent.text = msgEnvelope.dmRecipientIdent
dmRecipientRefNumber.text = msgEnvelope.dmSenderRefNumber
dmRecipientIdent.text = msgEnvelope.dmSenderIdent
dmLegalTitleLaw.text = msgEnvelope.dmLegalTitleLaw
dmLegalTitleYear.text = msgEnvelope.dmLegalTitleYear
dmLegalTitleSect.text = msgEnvelope.dmLegalTitleSect
dmLegalTitlePar.text = msgEnvelope.dmLegalTitlePar
dmLegalTitlePoint.text = msgEnvelope.dmLegalTitlePoint
}
Component.onCompleted: {
if (action == "new") {
if (action === "new") {
headerBar.title = qsTr("Create message") + " (" + userName + ")"
} else if (action === "reply") {
setReplyData(userName, msgId)
}
actionButton.enabled = false
var boxEffectiveOVM = accounts.boxEffectiveOVM(userName)
......
......@@ -144,6 +144,50 @@ QString Messages::getMessageDetail(const QString &userName,
return msgDb->getMessageDetailDataFromDb(msgId);
}
MsgEnvelope *Messages::getReplyMsgDataAndSetRecipient(
const QString &userName, qint64 msgId, const QVariant &dbModelVariant)
{
qDebug("%s()", __func__);
MessageDb *msgDb = globMessageDbsPtr->accessMessageDb(
globSet.dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical("%s", "Cannot open message database.");
return new (std::nothrow) MsgEnvelope();
}
MsgEnvelope msg = msgDb->getMessageEnvelopeData(msgId);
// Add recipient to model
DataboxListModel *dbModel =
DataboxListModel::fromVariant(dbModelVariant);
if (dbModel != Q_NULLPTR) {
DataboxModelEntry dbEntry;
dbEntry.setDbID(msg.dbIDSender());
dbEntry.setDbName(msg.dmSender());
dbEntry.setDbAddress(msg.dmSenderAddress());
dbModel->addEntry(dbEntry);
}
// Return message envelope data into QML
return new (std::nothrow) MsgEnvelope(msg.dmID(), msg.dmAnnotation(),
msg.dbIDSender(), msg.dmSender(), msg.dmSenderAddress(),
msg.dmSenderType(), msg.dmSenderOrgUnit(), msg.dmSenderOrgUnitNum(),
msg.dmSenderRefNumber(), msg.dmSenderIdent(), msg.dbIDRecipient(),
msg.dmRecipient(), msg.dmRecipientAddress(),
msg.dmRecipientOrgUnit(), msg.dmRecipientOrgUnitNum(),
msg.dmAmbiguousRecipient(), msg.dmRecipientRefNumber(),
msg.dmRecipientIdent(), msg.dmLegalTitleLaw(),
msg.dmLegalTitleYear(), msg.dmLegalTitleSect(),
msg.dmLegalTitlePar(), msg.dmLegalTitlePoint(), msg.dmToHands(),
msg.dmPersonalDelivery(), msg.dmAllowSubstDelivery(),
msg.dmQTimestamp(), msg.dmDeliveryTime(), msg.dmAcceptanceTime(),
msg.dmMessageStatus(), msg.dmAttachmentSize(), msg.dmType(),
msg._dmMessageType(), msg._dmDownloadDate(), msg._dmCustomData(),
msg._dmAttachDownloaded(), msg._dmReadLocally());
}
void Messages::markMessageAsLocallyRead(const QVariant &msgModelVariant,
const QString &userName, qint64 msgId, bool isRead)
{
......
......@@ -26,6 +26,8 @@
#include <QObject>
#include "src/qml_interaction/message_envelope.h"
/*
* Class Messages provides interface between QML and message database.
* Class is initialised in the main function (main.cpp)
......@@ -86,6 +88,18 @@ public:
QString getMessageDetail(const QString &userName,
const QString &msgIdStr);
/*!
* @brief Get message envelope data to QML and set recipient into model.
*
* @param[in] userName User name identifying the account.
* @param[in] dmId Message identifier.
* @param[in,out] dbModelVariant QVariant holding recipient model to be set.
* @return Pointer to message envelope data object.
*/
Q_INVOKABLE
MsgEnvelope *getReplyMsgDataAndSetRecipient(const QString &userName,
qint64 msgId, const QVariant &dbModelVariant);
/*!
* @brief Set message in database as locally read.
*/
......
......@@ -337,6 +337,75 @@ int MessageDb::getMessageCount(enum MessageType messageType)
return 0;
}
MsgEnvelope MessageDb::getMessageEnvelopeData(qint64 dmId)
{
QSqlQuery query(m_db);
QString queryStr;
MsgEnvelope msgEnvel;
queryStr = "SELECT dmAnnotation, "
"dbIDSender, dmSender, dmSenderAddress, dmSenderType, "
"dmSenderOrgUnit, dmSenderOrgUnitNum, dmSenderRefNumber, "
"dmSenderIdent, dbIDRecipient, dmRecipient, dmRecipientAddress, "
"dmRecipientOrgUnit, dmRecipientOrgUnitNum, dmAmbiguousRecipient, "
"dmRecipientRefNumber, dmRecipientIdent, dmLegalTitleLaw, "
"dmLegalTitleYear, dmLegalTitleSect, dmLegalTitlePar, "
"dmLegalTitlePoint, dmToHands, dmPersonalDelivery, "
"dmAllowSubstDelivery, dmQTimestamp, dmDeliveryTime, "
"dmAcceptanceTime, dmMessageStatus, dmAttachmentSize, dmType, "
"_dmMessageType, _dmDownloadDate, _dmCustomData, "
"_dmAttachDownloaded, _dmReadLocally "
"FROM messages WHERE dmID = :dmID";
if (!query.prepare(queryStr)) {
return msgEnvel;
}
query.bindValue(":dmID", dmId);
if (query.exec() && query.isActive() &&
query.first() && query.isValid()) {
msgEnvel.setDmID(dmId);
msgEnvel.setDmAnnotation(query.value(0).toString());
msgEnvel.setDbIDSender(query.value(1).toString());
msgEnvel.setDmSender(query.value(2).toString());
msgEnvel.setDmSenderAddress(query.value(3).toString());
msgEnvel.setDmSenderType(query.value(4).toInt());
msgEnvel.setDmSenderOrgUnit(query.value(5).toString());
msgEnvel.setDmSenderOrgUnitNum(query.value(6).toString());
msgEnvel.setDmSenderRefNumber(query.value(7).toString());
msgEnvel.setDmSenderIdent(query.value(8).toString());
msgEnvel.setDbIDRecipient(query.value(9).toString());
msgEnvel.setDmRecipient(query.value(10).toString());
msgEnvel.setDmRecipientAddress(query.value(11).toString());
msgEnvel.setDmRecipientOrgUnit(query.value(12).toString());
msgEnvel.setDmRecipientOrgUnitNum(query.value(13).toString());
msgEnvel.setDmAmbiguousRecipient(query.value(14).toString());
msgEnvel.setDmRecipientRefNumber(query.value(15).toString());
msgEnvel.setDmRecipientIdent(query.value(16).toString());
msgEnvel.setDmLegalTitleLaw(query.value(17).toString());
msgEnvel.setDmLegalTitleYear(query.value(18).toString());
msgEnvel.setDmLegalTitleSect(query.value(19).toString());
msgEnvel.setDmLegalTitlePar(query.value(20).toString());
msgEnvel.setDmLegalTitlePoint(query.value(21).toString());
msgEnvel.setDmToHands(query.value(22).toString());
msgEnvel.setDmPersonalDelivery(query.value(23).toBool());
msgEnvel.setDmAllowSubstDelivery(query.value(24).toBool());
msgEnvel.setDmQTimestamp(query.value(25).toString());
msgEnvel.setDmDeliveryTime(query.value(26).toString());
msgEnvel.setDmAcceptanceTime(query.value(27).toString());
msgEnvel.setDmMessageStatus(query.value(28).toInt());
msgEnvel.setDmAttachmentSize(query.value(29).toInt());
msgEnvel.setDmType(query.value(30).toString());
msgEnvel._setDmMessageType(query.value(31).toInt());
msgEnvel._setDmDownloadDate(query.value(32).toString());
msgEnvel._setDmCustomData(query.value(33).toString());
msgEnvel._setDmAttachDownloaded(query.value(34).toBool());
msgEnvel._setDmReadLocally(query.value(35).toBool());
}
return msgEnvel;
}
bool MessageDb::getMessageDataForEmail(qint64 dmId, QString &body,
QString &subject)
{
......
......@@ -136,6 +136,14 @@ public:
*/
int getMessageCount(enum MessageType messageType);
/*!
* @brief Return message envelope data.
*
* @param[in] dmId Message identifier.
* @return Message envelope data structure.
*/
MsgEnvelope getMessageEnvelopeData(qint64 dmId);
/*!
* @brief Get list of messages from db - for QML.
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment