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:
apa420 2018-08-06 16:40:12 +02:00 committed by fourtf
parent 5b64e9573b
commit 7e3292e900
5 changed files with 37 additions and 27 deletions

View file

@ -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,
}; };

View file

@ -220,35 +220,34 @@ MessagePtr TwitchMessageBuilder::build()
Link link; Link link;
if (linkString.isEmpty()) { if (linkString.isEmpty()) {
link = Link();
} else {
if (app->settings->lowercaseLink) {
QRegularExpression httpRegex("\\bhttps?://",
QRegularExpression::CaseInsensitiveOption);
QRegularExpression ftpRegex("\\bftps?://",
QRegularExpression::CaseInsensitiveOption);
QRegularExpression getDomain("\\/\\/([^\\/]*)");
QString tempString = string;
if (!string.contains(httpRegex)) {
if (!string.contains(ftpRegex)) {
tempString.insert(0, "http://");
}
}
QString domain = getDomain.match(tempString).captured(1);
string.replace(domain, domain.toLower());
}
link = Link(Link::Url, linkString);
textColor = MessageColor(MessageColor::Link);
}
if (string.startsWith('@')) { if (string.startsWith('@')) {
this->emplace<TextElement>(string, TextElement::BoldUsername, textColor, this->emplace<TextElement>(string, TextElement::BoldUsername, textColor,
FontStyle::ChatMediumBold) // FontStyle::ChatMediumBold);
->setLink(link); this->emplace<TextElement>(string, TextElement::NonBoldUsername, textColor);
this->emplace<TextElement>(string, TextElement::NonBoldUsername, textColor) //
->setLink(link);
} else { } else {
this->emplace<TextElement>(string, TextElement::Text, textColor) // this->emplace<TextElement>(string, TextElement::Text, textColor);
}
} else {
static QRegularExpression domainRegex(
R"(^(?:(?:ftp|http)s?:\/\/)?([^\/:]+)(?:\/.*)?$)",
QRegularExpression::CaseInsensitiveOption);
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);
this->emplace<TextElement>(lowercaseLinkString, TextElement::LowercaseLink,
textColor)
->setLink(link);
this->emplace<TextElement>(string, TextElement::OriginalLink, textColor)
->setLink(link); ->setLink(link);
} }

View file

@ -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};

View file

@ -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);

View file

@ -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);
} }