Merge pull request #4312: FIX(tts): OmitScope/OmitAuthor no longer reads HTML-formatted message

The new features "Omit Message Scope" and "Omit Message Author" were
somewhat broken.
The problems are adressed by transforming the message from HTML to
plaintext and creating a new TTS string that either contains no prefix
or just the scope or the author.

Fixes #4309
This commit is contained in:
Robert Adam 2020-06-26 07:29:15 +02:00 committed by GitHub
commit 79bbc1bf8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 30 deletions

View File

@ -35,6 +35,7 @@
#include "Utils.h"
#include "ChannelListener.h"
#include "TalkingUI.h"
#include <QTextDocumentFragment>
// We define a global macro called 'g'. This can lead to issues when included code uses 'g' as a type or parameter name (like protobuf 3.7 does). As such, for now, we have to make this our last include.
#include "Global.h"
@ -877,7 +878,6 @@ void MainWindow::msgChannelRemove(const MumbleProto::ChannelRemove &msg) {
void MainWindow::msgTextMessage(const MumbleProto::TextMessage &msg) {
ACTOR_INIT;
QString target;
QString overrideTTS = QString();
// Silently drop the message if this user is set to "ignore"
if (pSrc && pSrc->bLocalIgnore)
@ -888,30 +888,34 @@ void MainWindow::msgTextMessage(const MumbleProto::TextMessage &msg) {
bool privateMessage = false;
if (msg.tree_id_size() > 0) {
target += tr("(Tree) ");
target += tr("Tree");
} else if (msg.channel_id_size() > 0) {
target += tr("(Channel) ");
target += tr("Channel");
} else if (msg.session_size() > 0) {
target += tr("(Private) ");
target += tr("Private");
privateMessage = true;
}
// If NoScope or NoAuthor is selected generate a new string to pass to TTS
if (g.s.bTTSNoScope || g.s.bTTSNoAuthor) {
if (g.s.bTTSNoScope && g.s.bTTSNoAuthor) {
overrideTTS += tr("%2%1: %3").arg(QString()).arg(QString()).arg(u8(msg.message()));
} else if (g.s.bTTSNoAuthor) {
overrideTTS += tr("%2%1: %3").arg(QString()).arg(target).arg(u8(msg.message()));
} else if (g.s.bTTSNoScope) {
overrideTTS += tr("%2%1: %3").arg(name).arg(QString()).arg(u8(msg.message()));
const QString overrideTTS = [&]() {
if (!g.s.bTTSNoScope && !g.s.bTTSNoAuthor) {
return QString();
}
}
const QString plainMessage = QTextDocumentFragment::fromHtml(u8(msg.message())).toPlainText();
if (g.s.bTTSNoScope && g.s.bTTSNoAuthor) {
return plainMessage;
}
const QString prefixTTS = g.s.bTTSNoScope ? plainName : target;
return tr("%1: %2").arg(prefixTTS).arg(plainMessage);
}();
const QString prefixMessage = target.isEmpty() ? name : tr("(%1) %2").arg(target).arg(name);
g.l->log(privateMessage ? Log::PrivateTextMessage : Log::TextMessage,
tr("%2%1: %3").arg(name).arg(target).arg(u8(msg.message())),
tr("%1: %2").arg(prefixMessage).arg(u8(msg.message())),
tr("Message from %1").arg(plainName),
false,
overrideTTS.isNull() ? QString() : overrideTTS,
overrideTTS,
pSrc ? pSrc->bLocalIgnoreTTS : false);
}

View File

@ -5454,22 +5454,6 @@ Otherwise abort and check your certificate and username.</source>
<comment>message from</comment>
<translation type="unfinished"></translation>
</message>
<message>
<source>(Tree) </source>
<translation type="unfinished"></translation>
</message>
<message>
<source>(Channel) </source>
<translation type="unfinished"></translation>
</message>
<message>
<source>(Private) </source>
<translation type="unfinished"></translation>
</message>
<message>
<source>%2%1: %3</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Failed to load Opus, it will not be available for audio encoding/decoding.</source>
<translation type="unfinished"></translation>
@ -6050,6 +6034,26 @@ Valid options are:
<source>Silently disables Text-To-Speech for all text messages from the user.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Tree</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Channel</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Private</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>%1: %2</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>(%1) %2</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Manual</name>