Commit 03d6596b authored by Andreas Traczyk's avatar Andreas Traczyk Committed by Ming Rui Zhang

messaging: save/restore draft messages

Change-Id: I6609cccdcc5e6ab4c86cad112d4a7c22900d2bfb
parent dca8787e
...@@ -976,18 +976,30 @@ CallWidget::setupChatView(const lrc::api::conversation::Info& convInfo) ...@@ -976,18 +976,30 @@ CallWidget::setupChatView(const lrc::api::conversation::Info& convInfo)
ui->sendContactRequestButton->setVisible(shouldShowSendContactRequestBtn); ui->sendContactRequestButton->setVisible(shouldShowSendContactRequestBtn);
ui->messageView->setMessagesVisibility(false); ui->messageView->setMessagesVisibility(false);
Utils::oneShotConnect(ui->messageView, &MessageWebView::messagesCleared, Utils::oneShotConnect(ui->messageView, &MessageWebView::sendMessageContentSaved,
[this, convInfo] { [this, &convInfo, &accountInfo, lastConvUid = lastConvUid_](const QString& content) {
auto convModel = LRCInstance::getCurrentConversationModel(); if (!lastConvUid.empty()) {
ui->messageView->printHistory(*convModel, convInfo.interactions); LRCInstance::setContentDraft(
Utils::oneShotConnect(ui->messageView, &MessageWebView::messagesLoaded, lastConvUid.c_str(), accountInfo.id.c_str(), content);
[this] { }
ui->messageView->setMessagesVisibility(true); Utils::oneShotConnect(ui->messageView, &MessageWebView::messagesCleared,
[this, &convInfo] {
auto convModel = LRCInstance::getCurrentConversationModel();
ui->messageView->printHistory(*convModel, convInfo.interactions);
Utils::oneShotConnect(ui->messageView, &MessageWebView::messagesLoaded,
[this] {
ui->messageView->setMessagesVisibility(true);
});
setConversationProfileData(convInfo);
}); });
setConversationProfileData(convInfo); ui->messageView->setInvitation(false);
ui->messageView->clear();
auto restoredContent = LRCInstance::getContentDraft(
convInfo.uid.c_str(), accountInfo.id.c_str());
ui->messageView->setSendMessageContent(restoredContent);
ui->smartList->update();
}); });
ui->messageView->setInvitation(false); ui->messageView->requestSendMessageContent();
ui->messageView->clear();
} }
void void
......
...@@ -272,6 +272,32 @@ ConversationItemDelegate::paintConversationItem(QPainter* painter, ...@@ -272,6 +272,32 @@ ConversationItemDelegate::paintConversationItem(QPainter* painter,
} }
// bottom-right: last interaction snippet or call state (if in call) // bottom-right: last interaction snippet or call state (if in call)
auto draft = index.data(static_cast<int>(SmartListModel::Role::Draft)).value<QString>();
if (!draft.isEmpty()) {
painter->save();
uint cp = 0x270F;
auto emojiString = QString::fromUcs4(&cp, 1);
QFont emojiMsgFont(QStringLiteral("Segoe UI Emoji"));
emojiMsgFont.setPointSize(scalingRatio > 1.0 ? fontSize_ - 2 : fontSize_);
QString text{ tr("Draft") };
int widthText{ QFontMetrics(font).width(text) };
int widthEmoji{ QFontMetrics(emojiMsgFont).width(emojiString) };
int margin { 4 };
painter->setFont(font);
painter->setPen(QColor(207, 83, 0));
painter->drawText(rectInfo2, Qt::AlignVCenter | Qt::AlignRight, text);
rectInfo2.moveTop(rectInfo2.top() - 2);
painter->setOpacity(0.7);
painter->setFont(emojiMsgFont);
painter->drawText(rectInfo2.right() - widthText - widthEmoji - margin, rectInfo2.y(),
widthEmoji, rectInfo2.height(), Qt::AlignVCenter, emojiString);
painter->restore();
return;
}
if (index.data(static_cast<int>(SmartListModel::Role::InCall)).value<bool>()) { if (index.data(static_cast<int>(SmartListModel::Role::InCall)).value<bool>()) {
QString callStateStr = index.data(static_cast<int>(SmartListModel::Role::CallStateStr)).value<QString>(); QString callStateStr = index.data(static_cast<int>(SmartListModel::Role::CallStateStr)).value<QString>();
if (!callStateStr.isNull()) { if (!callStateStr.isNull()) {
......
...@@ -338,6 +338,22 @@ public: ...@@ -338,6 +338,22 @@ public:
f(); f();
} }
} }
static QString getContentDraft(const QString& convUid,
const QString& accountId)
{
auto draftKey = accountId + "_" + convUid;
return instance().contentDrafts_[draftKey];
}
static void setContentDraft(const QString& convUid,
const QString& accountId,
const QString& content)
{
auto draftKey = accountId + "_" + convUid;
instance().contentDrafts_[draftKey] = content;
}
signals: signals:
void accountListChanged(); void accountListChanged();
...@@ -355,4 +371,5 @@ private: ...@@ -355,4 +371,5 @@ private:
AccountListModel accountListModel_; AccountListModel accountListModel_;
std::string selectedAccountId_; std::string selectedAccountId_;
std::string selectedConvUid_; std::string selectedConvUid_;
MapStringString contentDrafts_;
}; };
...@@ -457,6 +457,21 @@ MessageWebView::displayNavbar(bool display) ...@@ -457,6 +457,21 @@ MessageWebView::displayNavbar(bool display)
page()->runJavaScript(s, QWebEngineScript::MainWorld); page()->runJavaScript(s, QWebEngineScript::MainWorld);
} }
void
MessageWebView::requestSendMessageContent()
{
QString s = QString::fromLatin1("requestSendMessageContent();");
page()->runJavaScript(s, QWebEngineScript::MainWorld);
}
void
MessageWebView::setSendMessageContent(const QString& content)
{
QString s = QString::fromLatin1("setSendMessageContent(`%1`);")
.arg(content);
page()->runJavaScript(s, QWebEngineScript::MainWorld);
}
// JS bridging incoming // JS bridging incoming
Q_INVOKABLE int Q_INVOKABLE int
PrivateBridging::log(const QString& arg) PrivateBridging::log(const QString& arg)
...@@ -715,7 +730,7 @@ PrivateBridging::emitPasteKeyDetected() ...@@ -715,7 +730,7 @@ PrivateBridging::emitPasteKeyDetected()
return 0; return 0;
} }
int Q_INVOKABLE int
PrivateBridging::openAudioRecorder(int spikePosX, int spikePosY) PrivateBridging::openAudioRecorder(int spikePosX, int spikePosY)
{ {
//call the open audio recorder function in messageweview //call the open audio recorder function in messageweview
...@@ -729,7 +744,7 @@ PrivateBridging::openAudioRecorder(int spikePosX, int spikePosY) ...@@ -729,7 +744,7 @@ PrivateBridging::openAudioRecorder(int spikePosX, int spikePosY)
return 0; return 0;
} }
int Q_INVOKABLE int
PrivateBridging::openVideoRecorder(int spikePosX, int spikePosY) PrivateBridging::openVideoRecorder(int spikePosX, int spikePosY)
{ {
//call the open video recorder function in messageweview //call the open video recorder function in messageweview
...@@ -741,4 +756,18 @@ PrivateBridging::openVideoRecorder(int spikePosX, int spikePosY) ...@@ -741,4 +756,18 @@ PrivateBridging::openVideoRecorder(int spikePosX, int spikePosY)
qDebug() << "JS bridging - exception during openVideoRecorder!"; qDebug() << "JS bridging - exception during openVideoRecorder!";
} }
return 0; return 0;
}
Q_INVOKABLE int
PrivateBridging::saveSendMessageContent(const QString& arg)
{
try {
if (auto messageView = qobject_cast<MessageWebView*>(this->parent())) {
emit messageView->sendMessageContentSaved(arg);
}
} catch (...) {
qDebug() << "JS bridging - exception during saveSendMessageContent!";
}
return 0;
} }
\ No newline at end of file
...@@ -53,6 +53,7 @@ public: ...@@ -53,6 +53,7 @@ public:
Q_INVOKABLE int emitPasteKeyDetected(); Q_INVOKABLE int emitPasteKeyDetected();
Q_INVOKABLE int openAudioRecorder(int spikePosX,int spikePosY); Q_INVOKABLE int openAudioRecorder(int spikePosX,int spikePosY);
Q_INVOKABLE int openVideoRecorder(int spikePosX,int spikePosY); Q_INVOKABLE int openVideoRecorder(int spikePosX,int spikePosY);
Q_INVOKABLE int saveSendMessageContent(const QString& arg);
}; };
class MessageWebView : public QWebEngineView class MessageWebView : public QWebEngineView
...@@ -97,6 +98,8 @@ public: ...@@ -97,6 +98,8 @@ public:
void updateChatviewFrame(bool accountEnabled, bool isBanned, bool isTemporary, void updateChatviewFrame(bool accountEnabled, bool isBanned, bool isTemporary,
const QString& alias, const QString& bestId); const QString& alias, const QString& bestId);
void displayNavbar(bool display); void displayNavbar(bool display);
void requestSendMessageContent();
void setSendMessageContent(const QString& content);
protected: protected:
...@@ -114,6 +117,7 @@ signals: ...@@ -114,6 +117,7 @@ signals:
void textSelectedReady(); void textSelectedReady();
void pasteKeyDetected(); void pasteKeyDetected();
void invitationAccepted(); void invitationAccepted();
void sendMessageContentSaved(const QString& content);
private slots: private slots:
void slotLoadFinished(); void slotLoadFinished();
......
...@@ -239,6 +239,8 @@ SmartListModel::getConversationItemData(const conversation::Info& item, ...@@ -239,6 +239,8 @@ SmartListModel::getConversationItemData(const conversation::Info& item,
} }
case Role::SectionName: case Role::SectionName:
return QVariant(QString()); return QVariant(QString());
case Role::Draft:
return LRCInstance::getContentDraft(item.uid.c_str(), accountInfo.id.c_str());
} }
return QVariant(); return QVariant();
} }
......
...@@ -58,7 +58,8 @@ public: ...@@ -58,7 +58,8 @@ public:
InCall, InCall,
CallStateStr, CallStateStr,
SectionName, SectionName,
AccountId AccountId,
Draft
}; };
explicit SmartListModel(const std::string& accId, explicit SmartListModel(const std::string& accId,
......
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