From bfc9e43eb4ff879b263f798f8d86fefa0c16a5aa Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sat, 9 Mar 2019 17:56:11 +0300 Subject: [PATCH] Added a handler for "MESSAGE_EMPTY" error to delete a local message. - Added a determination of the zero-width-space as the space. - Fixes #3145. --- Telegram/SourceFiles/apiwrap.cpp | 6 +++++- Telegram/SourceFiles/ui/text/text.h | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 5d3eb86d4b..34e813cda3 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -4628,7 +4628,11 @@ void ApiWrap::sendMessage(MessageToSend &&message) { applyUpdates(result, randomId); history->clearSentDraftText(QString()); }).fail([=](const RPCError &error) { - sendMessageFail(error); + if (error.type() == qstr("MESSAGE_EMPTY")) { + lastMessage->destroy(); + } else { + sendMessageFail(error); + } history->clearSentDraftText(QString()); }).afterRequest(history->sendRequestId ).send(); diff --git a/Telegram/SourceFiles/ui/text/text.h b/Telegram/SourceFiles/ui/text/text.h index d6c4a08169..d3af7fab99 100644 --- a/Telegram/SourceFiles/ui/text/text.h +++ b/Telegram/SourceFiles/ui/text/text.h @@ -261,7 +261,7 @@ QString textcmdStopSemibold(); const QChar *textSkipCommand(const QChar *from, const QChar *end, bool canLink = true); inline bool chIsSpace(QChar ch, bool rich = false) { - return ch.isSpace() || (ch < 32 && !(rich && ch == TextCommand)) || (ch == QChar::ParagraphSeparator) || (ch == QChar::LineSeparator) || (ch == QChar::ObjectReplacementCharacter) || (ch == QChar::CarriageReturn) || (ch == QChar::Tabulation); + return ch.isSpace() || (ch < 32 && !(rich && ch == TextCommand)) || (ch == QChar::ParagraphSeparator) || (ch == QChar::LineSeparator) || (ch == QChar::ObjectReplacementCharacter) || (ch == QChar::CarriageReturn) || (ch == QChar::Tabulation) || (ch == QChar(8203)/*Zero width space.*/); } inline bool chIsDiac(QChar ch) { // diac and variation selectors return (ch.category() == QChar::Mark_NonSpacing) || (ch == 1652) || (ch >= 64606 && ch <= 64611);