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),
|
BoldUsername = (1 << 27),
|
||||||
NonBoldUsername = (1 << 28),
|
NonBoldUsername = (1 << 28),
|
||||||
|
|
||||||
|
// for links
|
||||||
|
LowercaseLink = (1 << 29),
|
||||||
|
OriginalLink = (1 << 30),
|
||||||
|
|
||||||
Default = Timestamp | Badges | Username | BitsStatic | FfzEmoteImage | BttvEmoteImage |
|
Default = Timestamp | Badges | Username | BitsStatic | FfzEmoteImage | BttvEmoteImage |
|
||||||
TwitchEmoteImage | BitsAmount | Text | AlwaysShow,
|
TwitchEmoteImage | BitsAmount | Text | AlwaysShow,
|
||||||
};
|
};
|
||||||
|
|
|
@ -220,35 +220,34 @@ MessagePtr TwitchMessageBuilder::build()
|
||||||
Link link;
|
Link link;
|
||||||
|
|
||||||
if (linkString.isEmpty()) {
|
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 {
|
} else {
|
||||||
if (app->settings->lowercaseLink) {
|
static QRegularExpression domainRegex(
|
||||||
QRegularExpression httpRegex("\\bhttps?://",
|
R"(^(?:(?:ftp|http)s?:\/\/)?([^\/:]+)(?:\/.*)?$)",
|
||||||
QRegularExpression::CaseInsensitiveOption);
|
QRegularExpression::CaseInsensitiveOption);
|
||||||
QRegularExpression ftpRegex("\\bftps?://",
|
|
||||||
QRegularExpression::CaseInsensitiveOption);
|
|
||||||
QRegularExpression getDomain("\\/\\/([^\\/]*)");
|
|
||||||
QString tempString = string;
|
|
||||||
|
|
||||||
if (!string.contains(httpRegex)) {
|
QString lowercaseLinkString;
|
||||||
if (!string.contains(ftpRegex)) {
|
auto match = domainRegex.match(string);
|
||||||
tempString.insert(0, "http://");
|
if (match.isValid()) {
|
||||||
}
|
lowercaseLinkString = string.mid(0, match.capturedStart(1)) +
|
||||||
}
|
match.captured(1).toLower() +
|
||||||
QString domain = getDomain.match(tempString).captured(1);
|
string.mid(match.capturedEnd(1));
|
||||||
string.replace(domain, domain.toLower());
|
} else {
|
||||||
|
lowercaseLinkString = string;
|
||||||
}
|
}
|
||||||
link = Link(Link::Url, linkString);
|
link = Link(Link::Url, linkString);
|
||||||
|
|
||||||
textColor = MessageColor(MessageColor::Link);
|
textColor = MessageColor(MessageColor::Link);
|
||||||
}
|
this->emplace<TextElement>(lowercaseLinkString, TextElement::LowercaseLink,
|
||||||
if (string.startsWith('@')) {
|
textColor)
|
||||||
this->emplace<TextElement>(string, TextElement::BoldUsername, textColor,
|
|
||||||
FontStyle::ChatMediumBold) //
|
|
||||||
->setLink(link);
|
->setLink(link);
|
||||||
this->emplace<TextElement>(string, TextElement::NonBoldUsername, textColor) //
|
this->emplace<TextElement>(string, TextElement::OriginalLink, textColor)
|
||||||
->setLink(link);
|
|
||||||
} else {
|
|
||||||
this->emplace<TextElement>(string, TextElement::Text, textColor) //
|
|
||||||
->setLink(link);
|
->setLink(link);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,7 @@ public:
|
||||||
|
|
||||||
/// Links
|
/// Links
|
||||||
BoolSetting linksDoubleClickOnly = {"/links/doubleClickToOpen", false};
|
BoolSetting linksDoubleClickOnly = {"/links/doubleClickToOpen", false};
|
||||||
BoolSetting lowercaseLink = {"/links/linkLowercase", true};
|
BoolSetting enableLowercaseLink = {"/links/linkLowercase", true};
|
||||||
|
|
||||||
/// Ingored Users
|
/// Ingored Users
|
||||||
BoolSetting enableTwitchIgnoredUsers = {"/ignore/enableTwitchIgnoredUsers", true};
|
BoolSetting enableTwitchIgnoredUsers = {"/ignore/enableTwitchIgnoredUsers", true};
|
||||||
|
|
|
@ -68,6 +68,7 @@ WindowManager::WindowManager()
|
||||||
this->wordFlagsListener_.addSetting(settings->enableFfzEmotes);
|
this->wordFlagsListener_.addSetting(settings->enableFfzEmotes);
|
||||||
this->wordFlagsListener_.addSetting(settings->enableTwitchEmotes);
|
this->wordFlagsListener_.addSetting(settings->enableTwitchEmotes);
|
||||||
this->wordFlagsListener_.addSetting(settings->enableUsernameBold);
|
this->wordFlagsListener_.addSetting(settings->enableUsernameBold);
|
||||||
|
this->wordFlagsListener_.addSetting(settings->enableLowercaseLink);
|
||||||
this->wordFlagsListener_.cb = [this](auto) {
|
this->wordFlagsListener_.cb = [this](auto) {
|
||||||
this->updateWordTypeMask(); //
|
this->updateWordTypeMask(); //
|
||||||
};
|
};
|
||||||
|
@ -111,6 +112,7 @@ void WindowManager::updateWordTypeMask()
|
||||||
flags |= MEF::AlwaysShow;
|
flags |= MEF::AlwaysShow;
|
||||||
flags |= MEF::Collapsed;
|
flags |= MEF::Collapsed;
|
||||||
flags |= settings->enableUsernameBold ? MEF::BoldUsername : MEF::NonBoldUsername;
|
flags |= settings->enableUsernameBold ? MEF::BoldUsername : MEF::NonBoldUsername;
|
||||||
|
flags |= settings->enableLowercaseLink ? MEF::LowercaseLink : MEF::OriginalLink;
|
||||||
|
|
||||||
// update flags
|
// update flags
|
||||||
MessageElement::Flags newFlags = static_cast<MessageElement::Flags>(flags);
|
MessageElement::Flags newFlags = static_cast<MessageElement::Flags>(flags);
|
||||||
|
|
|
@ -141,7 +141,7 @@ void LookPage::addMessageTab(LayoutCreator<QVBoxLayout> layout)
|
||||||
layout.emplace<Line>(false);
|
layout.emplace<Line>(false);
|
||||||
|
|
||||||
// lowercase links
|
// lowercase links
|
||||||
layout.append(this->createCheckBox("Lowercase domains", getSettings()->lowercaseLink));
|
layout.append(this->createCheckBox("Lowercase domains", getSettings()->enableLowercaseLink));
|
||||||
// bold usernames
|
// bold usernames
|
||||||
layout.append(this->createCheckBox("Bold @usernames", getSettings()->enableUsernameBold));
|
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 TextElement("This is a preview message", MessageElement::Text));
|
||||||
message->addElement(new EmoteElement(EmoteData(getApp()->resources->pajaDank),
|
message->addElement(new EmoteElement(EmoteData(getApp()->resources->pajaDank),
|
||||||
MessageElement::Flags::AlwaysShow));
|
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);
|
channel->addMessage(message);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
@ -300,7 +302,10 @@ ChannelPtr LookPage::createPreviewChannel()
|
||||||
message->addElement(
|
message->addElement(
|
||||||
new EmoteElement(EmoteData(getApp()->resources->ppHop), MessageElement::BttvEmote));
|
new EmoteElement(EmoteData(getApp()->resources->ppHop), MessageElement::BttvEmote));
|
||||||
message->addElement(
|
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")));
|
->setLink(Link(Link::Url, "https://www.fourtf.com")));
|
||||||
channel->addMessage(message);
|
channel->addMessage(message);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue