Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into chatterino7
Browse files Browse the repository at this point in the history
Now we're on commit 0ba7c0f; Changes from upstream we've pulled:

- Minor: Added highlights for first messages (Chatterino#3267)
- Bugfix: Fixed second chatterino icon appearing in the dock when restarting on a crash in macOS. (Chatterino#3268)
  • Loading branch information
zneix committed Oct 2, 2021
2 parents c5173a6 + 0ba7c0f commit b00bee6
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Minor: Fixed `/streamlink` command not stripping leading @'s or #'s (#3215)
- Minor: Strip leading @ and trailing , from username in `/popout` command. (#3217)
- Minor: Added `flags.reward_message` filter variable (#3231)
- Minor: Added highlights for first messages (#3267)
- Bugfix: Fixed colored usernames sometimes not working. (#3170)
- Bugfix: Restored ability to send duplicate `/me` messages. (#3166)
- Bugfix: Notifications for moderators about other moderators deleting messages can now be disabled. (#3121)
Expand All @@ -27,6 +28,7 @@
- Bugfix: Fixed own IRC messages not having metadata and a link to a usercard. (#3203)
- Bugfix: Fixed some channels still not loading in rare cases. (#3219)
- Bugfix: Fixed a bug with usernames or emotes completing from the wrong position. (#3229)
- Bugfix: Fixed second chatterino icon appearing in the dock when restarting on a crash in macOS. (#3268)
- Dev: Renamed CMake's build option `USE_SYSTEM_QT5KEYCHAIN` to `USE_SYSTEM_QTKEYCHAIN`. (#3103)
- Dev: Add benchmarks that can be compiled with the `BUILD_BENCHMARKS` CMake flag. Off by default. (#3038)

Expand Down
25 changes: 25 additions & 0 deletions src/RunGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
# include <QBreakpadHandler.h>
#endif

#ifdef Q_OS_MAC
# include "corefoundation/CFBundle.h"
#endif

namespace chatterino {
namespace {
void installCustomPalette()
Expand Down Expand Up @@ -122,8 +126,29 @@ namespace {
std::chrono::steady_clock::now() - signalsInitTime > 30s)
{
QProcess proc;

#ifdef Q_OS_MAC
// On macOS, programs are bundled into ".app" Application bundles,
// when restarting chatterino that bundle should be opened with the "open"
// terminal command instead of directly starting the underlying executable,
// as those are 2 different things for the OS and i.e. do not use
// the same dock icon (resulting in a second chatterino icon on restarting)
CFURLRef appUrlRef = CFBundleCopyBundleURL(CFBundleGetMainBundle());
CFStringRef macPath =
CFURLCopyFileSystemPath(appUrlRef, kCFURLPOSIXPathStyle);
const char *pathPtr =
CFStringGetCStringPtr(macPath, CFStringGetSystemEncoding());

proc.setProgram("open");
proc.setArguments({pathPtr, "--args", "--crash-recovery"});

CFRelease(appUrlRef);
CFRelease(macPath);
#else
proc.setProgram(QApplication::applicationFilePath());
proc.setArguments({"--crash-recovery"});
#endif

proc.startDetached();
}

Expand Down
31 changes: 31 additions & 0 deletions src/controllers/highlights/HighlightModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,29 @@ void HighlightModel::afterInit()
setColorItem(redeemedRow[Column::Color], *RedeemedColor, false);

this->insertCustomRow(redeemedRow, 3);

std::vector<QStandardItem *> firstMessageRow = this->createRow();
setBoolItem(firstMessageRow[Column::Pattern],
getSettings()->enableFirstMessageHighlight.getValue(), true,
false);
firstMessageRow[Column::Pattern]->setData("First Messages",
Qt::DisplayRole);
firstMessageRow[Column::ShowInMentions]->setFlags({});
firstMessageRow[Column::FlashTaskbar]->setFlags({});
firstMessageRow[Column::PlaySound]->setFlags({});
firstMessageRow[Column::UseRegex]->setFlags({});
firstMessageRow[Column::CaseSensitive]->setFlags({});

QUrl FirstMessageSound =
QUrl(getSettings()->firstMessageHighlightSoundUrl.getValue());
setFilePathItem(firstMessageRow[Column::SoundPath], FirstMessageSound,
false);

auto FirstMessageColor =
ColorProvider::instance().color(ColorType::FirstMessageHighlight);
setColorItem(firstMessageRow[Column::Color], *FirstMessageColor, false);

this->insertCustomRow(firstMessageRow, 4);
}

void HighlightModel::customRowSetData(const std::vector<QStandardItem *> &row,
Expand Down Expand Up @@ -304,6 +327,14 @@ void HighlightModel::customRowSetData(const std::vector<QStandardItem *> &row,
.updateColor(ColorType::RedeemedHighlight,
QColor(colorName));
}
else if (rowIndex == 4)
{
getSettings()->firstMessageHighlightColor.setValue(
colorName);
const_cast<ColorProvider &>(ColorProvider::instance())
.updateColor(ColorType::FirstMessageHighlight,
QColor(colorName));
}
}
}
break;
Expand Down
2 changes: 2 additions & 0 deletions src/controllers/highlights/HighlightPhrase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace {
QColor HighlightPhrase::FALLBACK_HIGHLIGHT_COLOR = QColor(127, 63, 73, 127);
QColor HighlightPhrase::FALLBACK_REDEEMED_HIGHLIGHT_COLOR =
QColor(28, 126, 141, 60);
QColor HighlightPhrase::FALLBACK_FIRST_MESSAGE_HIGHLIGHT_COLOR =
QColor(72, 127, 63, 60);
QColor HighlightPhrase::FALLBACK_SUB_COLOR = QColor(196, 102, 255, 100);

bool HighlightPhrase::operator==(const HighlightPhrase &other) const
Expand Down
1 change: 1 addition & 0 deletions src/controllers/highlights/HighlightPhrase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class HighlightPhrase
static QColor FALLBACK_HIGHLIGHT_COLOR;
static QColor FALLBACK_REDEEMED_HIGHLIGHT_COLOR;
static QColor FALLBACK_SUB_COLOR;
static QColor FALLBACK_FIRST_MESSAGE_HIGHLIGHT_COLOR;

private:
QString pattern_;
Expand Down
6 changes: 6 additions & 0 deletions src/messages/Message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ SBHighlight Message::getScrollBarHighlight() const
ColorProvider::instance().color(ColorType::RedeemedHighlight),
SBHighlight::Default, true);
}
else if (this->flags.has(MessageFlag::FirstMessage))
{
return SBHighlight(
ColorProvider::instance().color(ColorType::FirstMessageHighlight),
SBHighlight::Default, true);
}
return SBHighlight();
}

Expand Down
1 change: 1 addition & 0 deletions src/messages/Message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ enum class MessageFlag : uint32_t {
RedeemedHighlight = (1 << 20),
RedeemedChannelPointReward = (1 << 21),
ShowInMentions = (1 << 22),
FirstMessage = (1 << 23),
};
using MessageFlags = FlagsEnum<MessageFlag>;

Expand Down
13 changes: 10 additions & 3 deletions src/messages/layouts/MessageLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,16 @@ void MessageLayout::updateBuffer(QPixmap *buffer, int /*messageIndex*/,
}
}();

if ((this->message_->flags.has(MessageFlag::Highlighted) ||
this->message_->flags.has(MessageFlag::HighlightedWhisper)) &&
!this->flags.has(MessageLayoutFlag::IgnoreHighlights))
if (this->message_->flags.has(MessageFlag::FirstMessage) &&
getSettings()->enableFirstMessageHighlight.getValue())
{
backgroundColor = blendColors(
backgroundColor,
*ColorProvider::instance().color(ColorType::FirstMessageHighlight));
}
else if ((this->message_->flags.has(MessageFlag::Highlighted) ||
this->message_->flags.has(MessageFlag::HighlightedWhisper)) &&
!this->flags.has(MessageLayoutFlag::IgnoreHighlights))
{
// Blend highlight color with usual background color
backgroundColor =
Expand Down
14 changes: 14 additions & 0 deletions src/providers/colors/ColorProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,20 @@ void ColorProvider::initTypeColorMap()
std::make_shared<QColor>(
HighlightPhrase::FALLBACK_REDEEMED_HIGHLIGHT_COLOR)});
}

customColor = getSettings()->firstMessageHighlightColor;
if (QColor(customColor).isValid())
{
this->typeColorMap_.insert({ColorType::FirstMessageHighlight,
std::make_shared<QColor>(customColor)});
}
else
{
this->typeColorMap_.insert(
{ColorType::FirstMessageHighlight,
std::make_shared<QColor>(
HighlightPhrase::FALLBACK_FIRST_MESSAGE_HIGHLIGHT_COLOR)});
}
}

void ColorProvider::initDefaultColors()
Expand Down
3 changes: 2 additions & 1 deletion src/providers/colors/ColorProvider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ enum class ColorType {
SelfHighlight,
Subscription,
Whisper,
RedeemedHighlight
RedeemedHighlight,
FirstMessageHighlight,
};

class ColorProvider
Expand Down
6 changes: 6 additions & 0 deletions src/providers/twitch/TwitchMessageBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ MessagePtr TwitchMessageBuilder::build()
this->message().flags.set(MessageFlag::RedeemedHighlight);
}

if (this->tags.contains("first-msg") &&
this->tags["first-msg"].toString() == "1")
{
this->message().flags.set(MessageFlag::FirstMessage);
}

// timestamp
this->emplace<TimestampElement>(
calculateMessageTimestamp(this->ircMessage));
Expand Down
7 changes: 7 additions & 0 deletions src/singletons/Settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,13 @@ class Settings : public ABSettings, public ConcurrentSettings
QStringSetting redeemedHighlightColor = {
"/highlighting/redeemedHighlightColor", ""};

BoolSetting enableFirstMessageHighlight = {
"/highlighting/firstMessageHighlight/highlighted", true};
QStringSetting firstMessageHighlightSoundUrl = {
"/highlighting/firstMessageHighlightSoundUrl", ""};
QStringSetting firstMessageHighlightColor = {
"/highlighting/firstMessageHighlightColor", ""};

BoolSetting enableSubHighlight = {
"/highlighting/subHighlight/subsHighlighted", true};
BoolSetting enableSubHighlightSound = {
Expand Down
3 changes: 3 additions & 0 deletions src/widgets/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ void Window::addDebugStuff()
miscMessages.emplace_back(R"(@badges=;color=#00AD2B;display-name=Iamme420\s;emotes=;id=d47a1e4b-a3c6-4b9e-9bf1-51b8f3dbc76e;mod=0;room-id=11148817;subscriber=0;tmi-sent-ts=1529670347537;turbo=0;user-id=56422869;user-type= :iamme420!iamme420@iamme420.tmi.twitch.tv PRIVMSG #pajlada :offline chat gachiBASS)");
miscMessages.emplace_back(R"(@badge-info=founder/47;badges=moderator/1,founder/0,premium/1;color=#00FF80;display-name=gempir;emotes=;flags=;id=d4514490-202e-43cb-b429-ef01a9d9c2fe;mod=1;room-id=11148817;subscriber=0;tmi-sent-ts=1575198233854;turbo=0;user-id=77829817;user-type=mod :gempir!gempir@gempir.tmi.twitch.tv PRIVMSG #pajlada :offline chat gachiBASS)");

// "first time chat" message
miscMessages.emplace_back(R"(@badge-info=;badges=glhf-pledge/1;client-nonce=5d2627b0cbe56fa05faf5420def4807d;color=#1E90FF;display-name=oldcoeur;emote-only=1;emotes=84608:0-7;first-msg=1;flags=;id=7412fea4-8683-4cc9-a506-4228127a5c2d;mod=0;room-id=11148817;subscriber=0;tmi-sent-ts=1623429859222;turbo=0;user-id=139147886;user-type= :oldcoeur!oldcoeur@oldcoeur.tmi.twitch.tv PRIVMSG #pajlada :cmonBruh)");

// various link tests
linkMessages.emplace_back(R"(@badge-info=subscriber/48;badges=broadcaster/1,subscriber/36,partner/1;color=#CC44FF;display-name=pajlada;emotes=;flags=;id=3c23cf3c-0864-4699-a76b-089350141147;mod=0;room-id=11148817;subscriber=1;tmi-sent-ts=1577628844607;turbo=0;user-id=11148817;user-type= :pajlada!pajlada@pajlada.tmi.twitch.tv PRIVMSG #pajlada : Links that should pass: )" + getValidLinks().join(' '));
linkMessages.emplace_back(R"(@badge-info=subscriber/48;badges=broadcaster/1,subscriber/36,partner/1;color=#CC44FF;display-name=pajlada;emotes=;flags=;id=3c23cf3c-0864-4699-a76b-089350141147;mod=0;room-id=11148817;subscriber=1;tmi-sent-ts=1577628844607;turbo=0;user-id=11148817;user-type= :pajlada!pajlada@pajlada.tmi.twitch.tv PRIVMSG #pajlada : Links that should NOT pass: )" + getInvalidLinks().join(' '));
Expand Down

0 comments on commit b00bee6

Please sign in to comment.