mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
Dynamic lowercase link setting - did request (#612)
* Added functionality of dynamic lowercase links * fixed fourtfs request, lajamerr has a better solution though * Fix matching and lowercasing of domain only. * Update TwitchMessageBuilder.cpp Added what fourtf asked in a good way NOTE: I removed a : from the regex since otherwise it would fuck up * fixed stuff and removed debugs * fixed stuff
This commit is contained in:
parent
5b64e9573b
commit
7e3292e900
|
@ -96,6 +96,10 @@ public:
|
|||
BoldUsername = (1 << 27),
|
||||
NonBoldUsername = (1 << 28),
|
||||
|
||||
// for links
|
||||
LowercaseLink = (1 << 29),
|
||||
OriginalLink = (1 << 30),
|
||||
|
||||
Default = Timestamp | Badges | Username | BitsStatic | FfzEmoteImage | BttvEmoteImage |
|
||||
TwitchEmoteImage | BitsAmount | Text | AlwaysShow,
|
||||
};
|
||||
|
|
|
@ -220,35 +220,34 @@ MessagePtr TwitchMessageBuilder::build()
|
|||
Link link;
|
||||
|
||||
if (linkString.isEmpty()) {
|
||||
link = Link();
|
||||
if (string.startsWith('@')) {
|
||||
this->emplace<TextElement>(string, TextElement::BoldUsername, textColor,
|
||||
FontStyle::ChatMediumBold);
|
||||
this->emplace<TextElement>(string, TextElement::NonBoldUsername, textColor);
|
||||
} else {
|
||||
this->emplace<TextElement>(string, TextElement::Text, textColor);
|
||||
}
|
||||
} else {
|
||||
if (app->settings->lowercaseLink) {
|
||||
QRegularExpression httpRegex("\\bhttps?://",
|
||||
QRegularExpression::CaseInsensitiveOption);
|
||||
QRegularExpression ftpRegex("\\bftps?://",
|
||||
QRegularExpression::CaseInsensitiveOption);
|
||||
QRegularExpression getDomain("\\/\\/([^\\/]*)");
|
||||
QString tempString = string;
|
||||
static QRegularExpression domainRegex(
|
||||
R"(^(?:(?:ftp|http)s?:\/\/)?([^\/:]+)(?:\/.*)?$)",
|
||||
QRegularExpression::CaseInsensitiveOption);
|
||||
|
||||
if (!string.contains(httpRegex)) {
|
||||
if (!string.contains(ftpRegex)) {
|
||||
tempString.insert(0, "http://");
|
||||
}
|
||||
}
|
||||
QString domain = getDomain.match(tempString).captured(1);
|
||||
string.replace(domain, domain.toLower());
|
||||
QString lowercaseLinkString;
|
||||
auto match = domainRegex.match(string);
|
||||
if (match.isValid()) {
|
||||
lowercaseLinkString = string.mid(0, match.capturedStart(1)) +
|
||||
match.captured(1).toLower() +
|
||||
string.mid(match.capturedEnd(1));
|
||||
} else {
|
||||
lowercaseLinkString = string;
|
||||
}
|
||||
link = Link(Link::Url, linkString);
|
||||
|
||||
textColor = MessageColor(MessageColor::Link);
|
||||
}
|
||||
if (string.startsWith('@')) {
|
||||
this->emplace<TextElement>(string, TextElement::BoldUsername, textColor,
|
||||
FontStyle::ChatMediumBold) //
|
||||
this->emplace<TextElement>(lowercaseLinkString, TextElement::LowercaseLink,
|
||||
textColor)
|
||||
->setLink(link);
|
||||
this->emplace<TextElement>(string, TextElement::NonBoldUsername, textColor) //
|
||||
->setLink(link);
|
||||
} else {
|
||||
this->emplace<TextElement>(string, TextElement::Text, textColor) //
|
||||
this->emplace<TextElement>(string, TextElement::OriginalLink, textColor)
|
||||
->setLink(link);
|
||||
}
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ public:
|
|||
|
||||
/// Links
|
||||
BoolSetting linksDoubleClickOnly = {"/links/doubleClickToOpen", false};
|
||||
BoolSetting lowercaseLink = {"/links/linkLowercase", true};
|
||||
BoolSetting enableLowercaseLink = {"/links/linkLowercase", true};
|
||||
|
||||
/// Ingored Users
|
||||
BoolSetting enableTwitchIgnoredUsers = {"/ignore/enableTwitchIgnoredUsers", true};
|
||||
|
|
|
@ -68,6 +68,7 @@ WindowManager::WindowManager()
|
|||
this->wordFlagsListener_.addSetting(settings->enableFfzEmotes);
|
||||
this->wordFlagsListener_.addSetting(settings->enableTwitchEmotes);
|
||||
this->wordFlagsListener_.addSetting(settings->enableUsernameBold);
|
||||
this->wordFlagsListener_.addSetting(settings->enableLowercaseLink);
|
||||
this->wordFlagsListener_.cb = [this](auto) {
|
||||
this->updateWordTypeMask(); //
|
||||
};
|
||||
|
@ -111,6 +112,7 @@ void WindowManager::updateWordTypeMask()
|
|||
flags |= MEF::AlwaysShow;
|
||||
flags |= MEF::Collapsed;
|
||||
flags |= settings->enableUsernameBold ? MEF::BoldUsername : MEF::NonBoldUsername;
|
||||
flags |= settings->enableLowercaseLink ? MEF::LowercaseLink : MEF::OriginalLink;
|
||||
|
||||
// update flags
|
||||
MessageElement::Flags newFlags = static_cast<MessageElement::Flags>(flags);
|
||||
|
|
|
@ -141,7 +141,7 @@ void LookPage::addMessageTab(LayoutCreator<QVBoxLayout> layout)
|
|||
layout.emplace<Line>(false);
|
||||
|
||||
// lowercase links
|
||||
layout.append(this->createCheckBox("Lowercase domains", getSettings()->lowercaseLink));
|
||||
layout.append(this->createCheckBox("Lowercase domains", getSettings()->enableLowercaseLink));
|
||||
// bold usernames
|
||||
layout.append(this->createCheckBox("Bold @usernames", getSettings()->enableUsernameBold));
|
||||
|
||||
|
@ -286,7 +286,9 @@ ChannelPtr LookPage::createPreviewChannel()
|
|||
message->addElement(new TextElement("This is a preview message", MessageElement::Text));
|
||||
message->addElement(new EmoteElement(EmoteData(getApp()->resources->pajaDank),
|
||||
MessageElement::Flags::AlwaysShow));
|
||||
// message->addElement(new)
|
||||
message->addElement(new TextElement("@fourtf", TextElement::BoldUsername,
|
||||
MessageColor::Text, FontStyle::ChatMediumBold));
|
||||
message->addElement(new TextElement("@fourtf", TextElement::NonBoldUsername));
|
||||
channel->addMessage(message);
|
||||
}
|
||||
{
|
||||
|
@ -300,7 +302,10 @@ ChannelPtr LookPage::createPreviewChannel()
|
|||
message->addElement(
|
||||
new EmoteElement(EmoteData(getApp()->resources->ppHop), MessageElement::BttvEmote));
|
||||
message->addElement(
|
||||
(new TextElement("www.fourtf.com", MessageElement::Text, MessageColor::Link))
|
||||
(new TextElement("www.fourtf.com", MessageElement::LowercaseLink, MessageColor::Link))
|
||||
->setLink(Link(Link::Url, "https://www.fourtf.com")));
|
||||
message->addElement(
|
||||
(new TextElement("wWw.FoUrTf.CoM", MessageElement::OriginalLink, MessageColor::Link))
|
||||
->setLink(Link(Link::Url, "https://www.fourtf.com")));
|
||||
channel->addMessage(message);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue