aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--context.cpp24
-rw-r--r--context.h3
-rw-r--r--message.cpp7
-rw-r--r--message.h7
-rw-r--r--qml/ComposePane.qml15
-rw-r--r--qml/Message.qml5
6 files changed, 59 insertions, 2 deletions
diff --git a/context.cpp b/context.cpp
index e7742f6..a92c0c2 100644
--- a/context.cpp
+++ b/context.cpp
@@ -189,6 +189,23 @@ Context::sendTextMessage(uint32_t chatId, QString textToSend)
return dc_send_text_msg(m_context, chatId, utf8Text.constData());
}
+void
+Context::setDraft(uint32_t chatId, DcMessage *message)
+{
+ dc_set_draft(m_context, chatId, message->m_message);
+}
+
+DcMessage *
+Context::getDraft(uint32_t chatId)
+{
+ dc_msg_t *draft = dc_get_draft(m_context, chatId);
+ if (draft) {
+ return new DcMessage{draft};
+ } else {
+ return NULL;
+ }
+}
+
bool
Context::setChatMuteDuration(uint32_t chatId, int64_t duration)
{
@@ -200,3 +217,10 @@ Context::decideOnContactRequest(uint32_t msgId, int decision)
{
return dc_decide_on_contact_request(m_context, msgId, decision);
}
+
+DcMessage *
+Context::newMessage(int viewtype)
+{
+ dc_msg_t *message = dc_msg_new(m_context, viewtype);
+ return new DcMessage{message};
+}
diff --git a/context.h b/context.h
index df3fbfb..2d31f71 100644
--- a/context.h
+++ b/context.h
@@ -39,6 +39,8 @@ public:
Q_INVOKABLE DcMessage *getMessage(uint32_t msgId);
Q_INVOKABLE DcContact *getContact(uint32_t contactId);
Q_INVOKABLE uint32_t sendTextMessage(uint32_t chatId, QString textToSend);
+ Q_INVOKABLE void setDraft(uint32_t chatId, DcMessage *message);
+ Q_INVOKABLE DcMessage *getDraft(uint32_t chatId);
QString getBlobdir();
Q_INVOKABLE bool setConfig(QString key, QString value);
Q_INVOKABLE QString getConfig(QString key);
@@ -46,6 +48,7 @@ public:
Q_INVOKABLE QString getMessageInfo(uint32_t msgId);
Q_INVOKABLE QString getMessageHtml(uint32_t msgId);
Q_INVOKABLE uint32_t decideOnContactRequest(uint32_t msgId, int decision);
+ Q_INVOKABLE DcMessage *newMessage(int viewtype);
private:
dc_context_t *m_context{nullptr};
diff --git a/message.cpp b/message.cpp
index cf29dae..90723d9 100644
--- a/message.cpp
+++ b/message.cpp
@@ -46,6 +46,13 @@ DcMessage::getState()
return dc_msg_get_state(m_message);
}
+void
+DcMessage::setText(QString text)
+{
+ QByteArray utf8Text = text.toUtf8();
+ return dc_msg_set_text(m_message, utf8Text.constData());
+}
+
QString
DcMessage::getText()
{
diff --git a/message.h b/message.h
index 8f7ec9c..2ce81e2 100644
--- a/message.h
+++ b/message.h
@@ -4,6 +4,8 @@
#include <deltachat.h>
+class Context;
+
class DcMessage : public QObject {
Q_OBJECT
Q_PROPERTY(uint32_t id READ getId CONSTANT)
@@ -11,7 +13,7 @@ class DcMessage : public QObject {
Q_PROPERTY(uint32_t chatId READ getChatId CONSTANT)
Q_PROPERTY(int viewtype READ getViewtype CONSTANT)
Q_PROPERTY(int state READ getState CONSTANT)
- Q_PROPERTY(QString text READ getText CONSTANT)
+ Q_PROPERTY(QString text READ getText WRITE setText)
Q_PROPERTY(QString subject READ getSubject CONSTANT)
Q_PROPERTY(QString file READ getFile CONSTANT)
Q_PROPERTY(QString filename READ getFilename CONSTANT)
@@ -23,6 +25,8 @@ class DcMessage : public QObject {
Q_PROPERTY(bool hasHtml READ hasHtml CONSTANT)
dc_msg_t *m_message{nullptr};
+
+ friend class Context;
public:
explicit DcMessage(QObject *parent = nullptr);
explicit DcMessage(dc_msg_t *msg);
@@ -36,6 +40,7 @@ public:
//Q_INVOKABLE int64_t getTimestamp();
//Q_INVOKABLE int64_t getReceivedTimestamp();
//Q_INVOKABLE int64_t getSortTimestamp();
+ Q_INVOKABLE void setText(QString);
Q_INVOKABLE QString getText();
Q_INVOKABLE QString getSubject();
QString getFile();
diff --git a/qml/ComposePane.qml b/qml/ComposePane.qml
index 54480d5..44cbd7c 100644
--- a/qml/ComposePane.qml
+++ b/qml/ComposePane.qml
@@ -20,6 +20,21 @@ Pane {
placeholderText: qsTr("Message")
wrapMode: TextArea.Wrap
selectByMouse: true
+
+ Component.onCompleted: {
+ let draft = context.getDraft(chatId)
+ if (draft) {
+ messageField.text = draft.text
+ }
+ }
+
+ Connections {
+ function onEditingFinished() {
+ var msg = context.newMessage(10)
+ msg.setText(messageField.text)
+ context.setDraft(chatId, msg)
+ }
+ }
}
Button {
diff --git a/qml/Message.qml b/qml/Message.qml
index fdd895a..68b2979 100644
--- a/qml/Message.qml
+++ b/qml/Message.qml
@@ -161,13 +161,16 @@ RowLayout {
// Message
TextEdit {
Layout.maximumWidth: messageObject.width > 30 ? messageObject.width - 30 : messageObject.width
- text: messageObject.message.text
textFormat: Text.PlainText
selectByMouse: true
readOnly: true
color: "black"
wrapMode: Text.Wrap
font.pixelSize: 14
+
+ Component.onCompleted: {
+ text = messageObject.message.text
+ }
}
Row {
HtmlViewSheet {