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
412f145581
commit
641fba3553
|
@ -31,6 +31,17 @@ void MessageProcessor::SharedParams::onUserNameSet(const QString& username)
|
|||
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)
|
||||
: sharedParams(sharedParams)
|
||||
{}
|
||||
|
@ -73,8 +84,9 @@ Message MessageProcessor::processIncomingMessage(bool isAction, QString const& m
|
|||
if (detectingMentions) {
|
||||
auto nameMention = sharedParams.GetNameMention();
|
||||
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);
|
||||
if (!matchIt.hasNext()) {
|
||||
continue;
|
||||
|
@ -85,6 +97,11 @@ Message MessageProcessor::processIncomingMessage(bool isAction, QString const& m
|
|||
auto pos = static_cast<size_t>(match.capturedStart());
|
||||
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});
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -75,11 +75,17 @@ public:
|
|||
{
|
||||
return sanitizedNameMention;
|
||||
}
|
||||
QRegularExpression GetPublicKeyMention() const
|
||||
{
|
||||
return pubKeyMention;
|
||||
}
|
||||
void onUserNameSet(const QString& username);
|
||||
void setPublicKey(const QString& pk);
|
||||
|
||||
private:
|
||||
QRegularExpression nameMention;
|
||||
QRegularExpression sanitizedNameMention;
|
||||
QRegularExpression pubKeyMention;
|
||||
};
|
||||
|
||||
MessageProcessor(const SharedParams& sharedParams);
|
||||
|
|
|
@ -691,6 +691,8 @@ void Widget::onCoreChanged(Core& core)
|
|||
connect(this, &Widget::statusSet, &core, &Core::setStatus);
|
||||
connect(this, &Widget::friendRequested, &core, &Core::requestFriendship);
|
||||
connect(this, &Widget::friendRequestAccepted, &core, &Core::acceptFriendRequest);
|
||||
|
||||
sharedMessageProcessorParams.setPublicKey(core.getSelfPublicKey().toString());
|
||||
}
|
||||
|
||||
void Widget::onConnected()
|
||||
|
|
Loading…
Reference in New Issue
Block a user