diff --git a/src/messages/messageelement.cpp b/src/messages/messageelement.cpp index 193ae3c4b..ca779a533 100644 --- a/src/messages/messageelement.cpp +++ b/src/messages/messageelement.cpp @@ -220,7 +220,10 @@ void TimestampElement::addToContainer(MessageLayoutContainer &container, TextElement *TimestampElement::formatTime(const QTime &time) { - QString format = time.toString(singletons::SettingManager::getInstance().timestampFormat); + static QLocale locale("en_US"); + + QString format = + locale.toString(time, singletons::SettingManager::getInstance().timestampFormat); return new TextElement(format, Flags::Timestamp, MessageColor::System, FontStyle::Medium); } diff --git a/src/singletons/helper/ircmessagehandler.cpp b/src/singletons/helper/ircmessagehandler.cpp index 12c8ef0e1..9d169a92b 100644 --- a/src/singletons/helper/ircmessagehandler.cpp +++ b/src/singletons/helper/ircmessagehandler.cpp @@ -123,7 +123,18 @@ void IrcMessageHandler::handleClearChatMessage(Communi::IrcMessage *message) void IrcMessageHandler::handleUserStateMessage(Communi::IrcMessage *message) { - // TODO: Implement + QVariant _mod = message->tag("mod"); + + if (_mod.isValid()) { + auto rawChannelName = message->parameters().at(0); + auto trimmedChannelName = rawChannelName.mid(1); + + auto c = this->channelManager.getTwitchChannel(trimmedChannelName); + twitch::TwitchChannel *tc = dynamic_cast(c.get()); + if (tc != nullptr) { + tc->setMod(_mod == "1"); + } + } } void IrcMessageHandler::handleWhisperMessage(Communi::IrcMessage *message) diff --git a/src/singletons/ircmanager.cpp b/src/singletons/ircmanager.cpp index f76d94ef6..8c426ca98 100644 --- a/src/singletons/ircmanager.cpp +++ b/src/singletons/ircmanager.cpp @@ -188,6 +188,8 @@ void IrcManager::beginConnecting() this->writeConnection->open(); this->readConnection->open(); + + this->connected(); } void IrcManager::disconnect() diff --git a/src/singletons/ircmanager.hpp b/src/singletons/ircmanager.hpp index 1fd701f43..8153d10be 100644 --- a/src/singletons/ircmanager.hpp +++ b/src/singletons/ircmanager.hpp @@ -50,6 +50,7 @@ public: pajlada::Signals::Signal onPrivateMessage; void privateMessageReceived(Communi::IrcPrivateMessage *message); + boost::signals2::signal connected; Communi::IrcConnection *getReadConnection(); diff --git a/src/twitch/twitchchannel.cpp b/src/twitch/twitchchannel.cpp index 90f68d08d..b5e36ac59 100644 --- a/src/twitch/twitchchannel.cpp +++ b/src/twitch/twitchchannel.cpp @@ -1,6 +1,7 @@ #include "twitchchannel.hpp" #include "debug/log.hpp" #include "singletons/emotemanager.hpp" +#include "singletons/ircmanager.hpp" #include "twitch/twitchmessagebuilder.hpp" #include "util/urlfetch.hpp" @@ -18,6 +19,7 @@ TwitchChannel::TwitchChannel(const QString &channelName) , channelURL("https://twitch.tv/" + name) , popoutPlayerURL("https://player.twitch.tv/?channel=" + name) , isLive(false) + , mod(false) { debug::Log("[TwitchChannel:{}] Opened", this->name); @@ -36,10 +38,15 @@ TwitchChannel::TwitchChannel(const QString &channelName) this->fetchMessages.connect([this] { this->fetchRecentMessages(); // }); + + this->connectedConnection = singletons::IrcManager::getInstance().connected.connect( + [this] { this->userStateChanged(); }); } TwitchChannel::~TwitchChannel() { + this->connectedConnection.disconnect(); + this->liveStatusTimer->stop(); this->liveStatusTimer->deleteLater(); } @@ -88,9 +95,24 @@ bool TwitchChannel::isMod() return this->mod; } +void TwitchChannel::setMod(bool value) +{ + if (this->mod != value) { + this->mod = value; + + this->userStateChanged(); + } +} + bool TwitchChannel::isBroadcaster() { - return this->name == singletons::AccountManager::getInstance().Twitch.getCurrent()->getUserId(); + QString xD = this->name; + QString xD2 = singletons::AccountManager::getInstance().Twitch.getCurrent()->getUserName(); + + qDebug() << xD << xD2; + + return this->name == + singletons::AccountManager::getInstance().Twitch.getCurrent()->getUserName(); } bool TwitchChannel::hasModRights() diff --git a/src/twitch/twitchchannel.hpp b/src/twitch/twitchchannel.hpp index 014aa031c..0aae27b37 100644 --- a/src/twitch/twitchchannel.hpp +++ b/src/twitch/twitchchannel.hpp @@ -23,6 +23,7 @@ public: void sendMessage(const QString &message) override; bool isMod(); + void setMod(bool value); bool isBroadcaster(); bool hasModRights(); @@ -38,7 +39,7 @@ public: boost::signals2::signal onlineStatusChanged; pajlada::Signals::NoArgBoltSignal fetchMessages; - pajlada::Signals::NoArgSignal userStateChanged; + boost::signals2::signal userStateChanged; QString roomID; bool isLive; @@ -53,6 +54,8 @@ private: void fetchRecentMessages(); + boost::signals2::connection connectedConnection; + bool mod; }; diff --git a/src/widgets/helper/splitheader.cpp b/src/widgets/helper/splitheader.cpp index 873b27982..9ef0463da 100644 --- a/src/widgets/helper/splitheader.cpp +++ b/src/widgets/helper/splitheader.cpp @@ -161,7 +161,16 @@ void SplitHeader::updateModerationModeIcon() ? resourceManager.moderationmode_enabled->getPixmap() : resourceManager.moderationmode_disabled->getPixmap()); - // this->moderationButton->setVisible(this->split->channel->hasModRights()); + bool modButtonVisible = false; + SharedChannel channel = this->split->getChannel(); + + twitch::TwitchChannel *tc = dynamic_cast(channel.get()); + + if (tc != nullptr && tc->hasModRights()) { + modButtonVisible = true; + } + + this->moderationButton->setVisible(modButtonVisible); } void SplitHeader::paintEvent(QPaintEvent *) diff --git a/src/widgets/helper/splitheader.hpp b/src/widgets/helper/splitheader.hpp index f72429941..900f151dc 100644 --- a/src/widgets/helper/splitheader.hpp +++ b/src/widgets/helper/splitheader.hpp @@ -13,6 +13,7 @@ #include #include #include +#include namespace chatterino { diff --git a/src/widgets/settingspages/appearancepage.cpp b/src/widgets/settingspages/appearancepage.cpp index 43d783d03..1725c9ef8 100644 --- a/src/widgets/settingspages/appearancepage.cpp +++ b/src/widgets/settingspages/appearancepage.cpp @@ -18,7 +18,9 @@ #define SCROLL_SMOOTH "Enable smooth scrolling" #define SCROLL_NEWMSG "Enable smooth scrolling for new messages" -#define TIMESTAMP_FORMATS "hh:mm a", "h:mm a", "HH:mm", "H:mm" +// clang-format off +#define TIMESTAMP_FORMATS "hh:mm a", "h:mm a", "hh:mm:ss a", "h:mm:ss a", "HH:mm", "H:mm", "HH:mm:ss", "H:mm:ss" +// clang-format on namespace chatterino { namespace widgets { @@ -55,7 +57,7 @@ AppearancePage::AppearancePage() messages.append(this->createCheckBox("Show timestamp", settings.showTimestamps)); auto tbox = messages.emplace(); { - tbox.emplace("timestamp format:"); + tbox.emplace("timestamp format (a = am/pm):"); tbox.append(this->createComboBox({TIMESTAMP_FORMATS}, settings.timestampFormat)); } messages.append(this->createCheckBox("Show badges", settings.showBadges)); diff --git a/src/widgets/settingspages/moderationpage.cpp b/src/widgets/settingspages/moderationpage.cpp index e2e7d2597..0ab611288 100644 --- a/src/widgets/settingspages/moderationpage.cpp +++ b/src/widgets/settingspages/moderationpage.cpp @@ -27,9 +27,7 @@ ModerationPage::ModerationPage() auto text = layout.emplace().getElement(); - settings.moderationActions.connect([=](const QString &str, auto) { - text->setPlainText(str); // - }); + text->setPlainText(settings.moderationActions); QObject::connect(text, &QTextEdit::textChanged, this, [this] { this->itemsChangedTimer.start(200); }); diff --git a/src/widgets/split.cpp b/src/widgets/split.cpp index 571701f6c..32eed9cc6 100644 --- a/src/widgets/split.cpp +++ b/src/widgets/split.cpp @@ -123,6 +123,8 @@ Split::Split(SplitContainer *parent, const std::string &_uuid) Split::~Split() { this->channelNameUpdated(""); + this->usermodeChangedConnection.disconnect(); + this->channelIDChangedConnection.disconnect(); } const std::string &Split::getUUID() const @@ -144,8 +146,19 @@ void Split::setChannel(SharedChannel _newChannel) { this->view.setChannel(_newChannel); + this->usermodeChangedConnection.disconnect(); + this->channel = _newChannel; + twitch::TwitchChannel *tc = dynamic_cast(_newChannel.get()); + + if (tc != nullptr) { + this->usermodeChangedConnection = + tc->userStateChanged.connect([this] { this->header.updateModerationModeIcon(); }); + } + + this->header.updateModerationModeIcon(); + this->channelChanged(); } diff --git a/src/widgets/split.hpp b/src/widgets/split.hpp index 6cab1c932..64100ab8b 100644 --- a/src/widgets/split.hpp +++ b/src/widgets/split.hpp @@ -44,7 +44,7 @@ class Split : public BaseWidget public: Split(SplitContainer *parent, const std::string &_uuid); - ~Split(); + virtual ~Split(); pajlada::Settings::Setting channelName; boost::signals2::signal channelChanged; @@ -94,6 +94,7 @@ private: bool moderationMode; boost::signals2::connection channelIDChangedConnection; + boost::signals2::connection usermodeChangedConnection; void setChannel(SharedChannel newChannel); void doOpenAccountPopupWidget(AccountPopupWidget *widget, QString user);