mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
fix: empty username causes mention on ever message
This fixes #2119 and additionally introduces the possibility to mention users by their public key.
This commit is contained in:
parent
74377430ce
commit
db802822f3
|
@ -31,6 +31,17 @@ void MessageProcessor::SharedParams::onUserNameSet(const QString& username)
|
||||||
QRegularExpression::CaseInsensitiveOption);
|
QRegularExpression::CaseInsensitiveOption);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the public key on which a message should be highlighted
|
||||||
|
* @param pk ToxPk in its hex string form
|
||||||
|
*/
|
||||||
|
void MessageProcessor::SharedParams::setPublicKey(const QString& pk)
|
||||||
|
{
|
||||||
|
// no sanitization needed, we expect a ToxPk in its string form
|
||||||
|
pubKeyMention = QRegularExpression("\\b" + pk + "\\b",
|
||||||
|
QRegularExpression::CaseInsensitiveOption);
|
||||||
|
}
|
||||||
|
|
||||||
MessageProcessor::MessageProcessor(const MessageProcessor::SharedParams& sharedParams)
|
MessageProcessor::MessageProcessor(const MessageProcessor::SharedParams& sharedParams)
|
||||||
: sharedParams(sharedParams)
|
: sharedParams(sharedParams)
|
||||||
{}
|
{}
|
||||||
|
@ -73,8 +84,9 @@ Message MessageProcessor::processIncomingMessage(bool isAction, QString const& m
|
||||||
if (detectingMentions) {
|
if (detectingMentions) {
|
||||||
auto nameMention = sharedParams.GetNameMention();
|
auto nameMention = sharedParams.GetNameMention();
|
||||||
auto sanitizedNameMention = sharedParams.GetSanitizedNameMention();
|
auto sanitizedNameMention = sharedParams.GetSanitizedNameMention();
|
||||||
|
auto pubKeyMention = sharedParams.GetPublicKeyMention();
|
||||||
|
|
||||||
for (auto const& mention : {nameMention, sanitizedNameMention}) {
|
for (auto const& mention : {nameMention, sanitizedNameMention, pubKeyMention}) {
|
||||||
auto matchIt = mention.globalMatch(ret.content);
|
auto matchIt = mention.globalMatch(ret.content);
|
||||||
if (!matchIt.hasNext()) {
|
if (!matchIt.hasNext()) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -85,6 +97,11 @@ Message MessageProcessor::processIncomingMessage(bool isAction, QString const& m
|
||||||
auto pos = static_cast<size_t>(match.capturedStart());
|
auto pos = static_cast<size_t>(match.capturedStart());
|
||||||
auto length = static_cast<size_t>(match.capturedLength());
|
auto length = static_cast<size_t>(match.capturedLength());
|
||||||
|
|
||||||
|
// skip matches on empty usernames
|
||||||
|
if (length == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
ret.metadata.push_back({MessageMetadataType::selfMention, pos, pos + length});
|
ret.metadata.push_back({MessageMetadataType::selfMention, pos, pos + length});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,11 +75,17 @@ public:
|
||||||
{
|
{
|
||||||
return sanitizedNameMention;
|
return sanitizedNameMention;
|
||||||
}
|
}
|
||||||
|
QRegularExpression GetPublicKeyMention() const
|
||||||
|
{
|
||||||
|
return pubKeyMention;
|
||||||
|
}
|
||||||
void onUserNameSet(const QString& username);
|
void onUserNameSet(const QString& username);
|
||||||
|
void setPublicKey(const QString& pk);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QRegularExpression nameMention;
|
QRegularExpression nameMention;
|
||||||
QRegularExpression sanitizedNameMention;
|
QRegularExpression sanitizedNameMention;
|
||||||
|
QRegularExpression pubKeyMention;
|
||||||
};
|
};
|
||||||
|
|
||||||
MessageProcessor(const SharedParams& sharedParams);
|
MessageProcessor(const SharedParams& sharedParams);
|
||||||
|
|
|
@ -691,6 +691,8 @@ void Widget::onCoreChanged(Core& core)
|
||||||
connect(this, &Widget::statusSet, &core, &Core::setStatus);
|
connect(this, &Widget::statusSet, &core, &Core::setStatus);
|
||||||
connect(this, &Widget::friendRequested, &core, &Core::requestFriendship);
|
connect(this, &Widget::friendRequested, &core, &Core::requestFriendship);
|
||||||
connect(this, &Widget::friendRequestAccepted, &core, &Core::acceptFriendRequest);
|
connect(this, &Widget::friendRequestAccepted, &core, &Core::acceptFriendRequest);
|
||||||
|
|
||||||
|
sharedMessageProcessorParams.setPublicKey(core.getSelfPublicKey().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::onConnected()
|
void Widget::onConnected()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user