summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThanos Doukoudakis <thanos.doukoudakis@isode.com>2017-05-17 13:15:07 (GMT)
committerThanos Doukoudakis <thanos.doukoudakis@isode.com>2018-05-14 09:55:30 (GMT)
commitb7849f50877dffd2755445a986d856340eed59c2 (patch)
treea76adbbc613525bec214995c176e6f0e37d8b5a0 /Swift/QtUI
parent4663da31954d989f8535b94c4a78a0f4515542a4 (diff)
downloadswift-b7849f50877dffd2755445a986d856340eed59c2.zip
swift-b7849f50877dffd2755445a986d856340eed59c2.tar.bz2
Allow resending messages without 198 acks
This patch will allow to resend messages that have not been successfully delivered to the server. It requires that the server will have stream management enabled as described in XEP-198. Test-Information: Tested the changes on Windows and Linux. Modified the code to force messages to fail, and then tested the resend functionality. Added ChatControllerTest, with unit Tests for the resend case. The rest of unit test pass. Change-Id: Id095528247b25a47e34c5632b8469ebd4c97149b
Diffstat (limited to 'Swift/QtUI')
-rw-r--r--Swift/QtUI/QtChatWindow.cpp7
-rw-r--r--Swift/QtUI/QtChatWindow.h1
-rw-r--r--Swift/QtUI/QtWebKitChatView.cpp25
-rw-r--r--Swift/QtUI/QtWebKitChatView.h3
4 files changed, 35 insertions, 1 deletions
diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp
index cbdab48..7c0a9d8 100644
--- a/Swift/QtUI/QtChatWindow.cpp
+++ b/Swift/QtUI/QtChatWindow.cpp
@@ -1054,4 +1054,11 @@ void QtChatWindow::handleFocusTimerTick() {
focusTimer_.reset();
}
+void QtChatWindow::resendMessage(const std::string& id) {
+ if (!isOnline_ || (blockingState_ == IsBlocked)) {
+ return;
+ }
+ onResendMessageRequest(id);
+}
+
}
diff --git a/Swift/QtUI/QtChatWindow.h b/Swift/QtUI/QtChatWindow.h
index 1269165..8cc3283 100644
--- a/Swift/QtUI/QtChatWindow.h
+++ b/Swift/QtUI/QtChatWindow.h
@@ -94,6 +94,7 @@ namespace Swift {
void replaceMessage(const ChatMessage& message, const std::string& id, const boost::posix_time::ptime& time);
void replaceWithAction(const ChatMessage& message, const std::string& id, const boost::posix_time::ptime& time);
+ void resendMessage(const std::string& id);
// File transfer related stuff
std::string addFileTransfer(const std::string& senderName, const std::string& avatarPath, bool senderIsSelf, const std::string& filename, const boost::uintmax_t sizeInBytes, const std::string& description);
void setFileTransferProgress(std::string id, const int percentageDone);
diff --git a/Swift/QtUI/QtWebKitChatView.cpp b/Swift/QtUI/QtWebKitChatView.cpp
index 92f0a2c..8ced8fc 100644
--- a/Swift/QtUI/QtWebKitChatView.cpp
+++ b/Swift/QtUI/QtWebKitChatView.cpp
@@ -53,6 +53,9 @@ const QString QtWebKitChatView::ButtonFileTransferSendRequest = QString("filetra
const QString QtWebKitChatView::ButtonFileTransferAcceptRequest = QString("filetransfer-acceptrequest");
const QString QtWebKitChatView::ButtonFileTransferOpenFile = QString("filetransfer-openfile");
const QString QtWebKitChatView::ButtonMUCInvite = QString("mucinvite");
+const QString QtWebKitChatView::ButtonResendMessage = QString("resend-message");
+const QString QtWebKitChatView::ButtonResendPopup = QString("popup-resend");
+
namespace {
const double minimalFontScaling = 0.7;
@@ -606,6 +609,10 @@ QString QtWebKitChatView::buildChatWindowButton(const QString& name, const QStri
return html;
}
+QString QtWebKitChatView::buildChatWindowPopupImageButton(const QString& title, const QString& path, const QString& arg1, const QString& arg2, const QString& arg3, const QString& arg4, const QString& arg5) {
+ return QString("<div class=\"popup\" onclick='chatwindow.buttonClicked(\"%3\", \"%5\", \"6\", \"7\", \"8\", \"9\")' \"><img src='%1' title='%2'/><span class=\"popuptext\" id=\"resendPopup\" ><div class=\"resendButton\" onclick='chatwindow.buttonClicked(\"%4\", \"%5\", \"6\", \"7\", \"8\", \"9\")'>Resend</div></span></div>").arg(path).arg(title).arg(QtWebKitChatView::ButtonResendPopup).arg(QtWebKitChatView::ButtonResendMessage).arg(encodeButtonArgument(arg1)).arg(encodeButtonArgument(arg2)).arg(encodeButtonArgument(arg3)).arg(encodeButtonArgument(arg4)).arg(encodeButtonArgument(arg5));
+}
+
void QtWebKitChatView::resizeEvent(QResizeEvent* event) {
// This code ensures that if the user is scrolled all to the bottom of a chat view,
// the view stays scrolled to the bottom if the view is resized or if the message
@@ -807,6 +814,20 @@ void QtWebKitChatView::handleHTMLButtonClicked(QString id, QString encodedArgume
eventStream_->send(std::make_shared<JoinMUCUIEvent>(Q2PSTRING(roomJID), Q2PSTRING(password), boost::optional<std::string>(), false, false, isImpromptu.contains("true"), isContinuation.contains("true")));
setMUCInvitationJoined(elementID);
}
+ else if (id.startsWith(ButtonResendPopup)) {
+ QString chatID = arg1;
+ QWebElement message = document_.findFirst("#" + arg1);
+ if (!message.isNull()) {
+ QWebElement popuptext = message.findFirst("span#resendPopup.popuptext");
+ if (!popuptext.isNull()) {
+ popuptext.toggleClass("show");
+ }
+ }
+ }
+ else if (id.startsWith(ButtonResendMessage)) {
+ QString chatID = arg1;
+ window_->resendMessage(Q2PSTRING(chatID));
+ }
else {
SWIFT_LOG(debug) << "Unknown HTML button! ( " << Q2PSTRING(id) << " )" << std::endl;
}
@@ -964,7 +985,9 @@ void QtWebKitChatView::setAckState(std::string const& id, ChatWindow::AckState s
xml = "";
displayReceiptInfo(P2QSTRING(id), true);
break;
- case ChatWindow::Failed: xml = "<img src='qrc:/icons/error.png' title='" + tr("This message may not have been transmitted.") + "'/>"; break;
+ case ChatWindow::Failed:
+ xml = buildChatWindowPopupImageButton(tr("This message may not have been sent. Click to resend."), "qrc:/icons/error.png", P2QSTRING(id));
+ break;
}
setAckXML(P2QSTRING(id), xml);
}
diff --git a/Swift/QtUI/QtWebKitChatView.h b/Swift/QtUI/QtWebKitChatView.h
index a2eafe6..f0b4459 100644
--- a/Swift/QtUI/QtWebKitChatView.h
+++ b/Swift/QtUI/QtWebKitChatView.h
@@ -42,6 +42,8 @@ namespace Swift {
static const QString ButtonFileTransferAcceptRequest;
static const QString ButtonFileTransferOpenFile;
static const QString ButtonMUCInvite;
+ static const QString ButtonResendMessage;
+ static const QString ButtonResendPopup;
public:
QtWebKitChatView(QtChatWindow* window, UIEventStream* eventStream, QtChatTheme* theme, QWidget* parent, SettingsProvider* settings, bool disableAutoScroll = false);
~QtWebKitChatView() override;
@@ -157,6 +159,7 @@ namespace Swift {
QString getHighlightSpanStart(const HighlightAction& highlight);
QString chatMessageToHTML(const ChatWindow::ChatMessage& message);
static QString buildChatWindowButton(const QString& name, const QString& id, const QString& arg1 = QString(), const QString& arg2 = QString(), const QString& arg3 = QString(), const QString& arg4 = QString(), const QString& arg5 = QString());
+ static QString buildChatWindowPopupImageButton(const QString& title, const QString& path, const QString& arg1 = QString(), const QString& arg2 = QString(), const QString& arg3 = QString(), const QString& arg4 = QString(), const QString& arg5 = QString());
protected:
void resizeEvent(QResizeEvent* event) override;