mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
added roommodes to the splitheader
This commit is contained in:
parent
48e94a1169
commit
59110ad4bd
|
@ -110,7 +110,7 @@ QString CommandController::execCommand(const QString &text, ChannelPtr channel,
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
} else if (commandName == "/uptime") {
|
} else if (commandName == "/uptime") {
|
||||||
const auto &streamStatus = twitchChannel->GetStreamStatus();
|
const auto &streamStatus = twitchChannel->getStreamStatus();
|
||||||
|
|
||||||
QString messageText =
|
QString messageText =
|
||||||
streamStatus.live ? streamStatus.uptime : "Channel is not live.";
|
streamStatus.live ? streamStatus.uptime : "Channel is not live.";
|
||||||
|
|
|
@ -27,34 +27,48 @@ IrcMessageHandler &IrcMessageHandler::getInstance()
|
||||||
void IrcMessageHandler::handleRoomStateMessage(Communi::IrcMessage *message)
|
void IrcMessageHandler::handleRoomStateMessage(Communi::IrcMessage *message)
|
||||||
{
|
{
|
||||||
const auto &tags = message->tags();
|
const auto &tags = message->tags();
|
||||||
auto iterator = tags.find("room-id");
|
auto app = getApp();
|
||||||
|
|
||||||
if (iterator != tags.end()) {
|
// get twitch channel
|
||||||
auto roomID = iterator.value().toString();
|
QString chanName;
|
||||||
|
if (!trimChannelName(message->parameter(0), chanName)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto chan = app->twitch.server->getChannelOrEmpty(chanName);
|
||||||
|
TwitchChannel *twitchChannel = dynamic_cast<twitch::TwitchChannel *>(chan.get());
|
||||||
|
|
||||||
QStringList words = QString(message->toData()).split("#");
|
if (twitchChannel) {
|
||||||
|
// room-id
|
||||||
|
decltype(tags.find("xD")) it;
|
||||||
|
|
||||||
// ensure the format is valid
|
if ((it = tags.find("room-id")) != tags.end()) {
|
||||||
if (words.length() < 2) {
|
auto roomID = it.value().toString();
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto app = getApp();
|
|
||||||
|
|
||||||
QString channelName = words.at(1);
|
|
||||||
|
|
||||||
auto channel = app->twitch.server->getChannelOrEmpty(channelName);
|
|
||||||
|
|
||||||
if (channel->isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (auto twitchChannel = dynamic_cast<twitch::TwitchChannel *>(channel.get())) {
|
|
||||||
// set the room id of the channel
|
|
||||||
twitchChannel->setRoomID(roomID);
|
twitchChannel->setRoomID(roomID);
|
||||||
|
|
||||||
|
app->resources->loadChannelData(roomID);
|
||||||
}
|
}
|
||||||
|
|
||||||
app->resources->loadChannelData(roomID);
|
// Room modes
|
||||||
|
TwitchChannel::RoomModes roomModes = twitchChannel->getRoomModes();
|
||||||
|
|
||||||
|
if ((it = tags.find("emote-only")) != tags.end()) {
|
||||||
|
roomModes.emoteOnly = it.value() == "1";
|
||||||
|
}
|
||||||
|
if ((it = tags.find("subs-only")) != tags.end()) {
|
||||||
|
roomModes.submode = it.value() == "1";
|
||||||
|
}
|
||||||
|
if ((it = tags.find("slow")) != tags.end()) {
|
||||||
|
roomModes.slowMode = it.value().toInt();
|
||||||
|
}
|
||||||
|
if ((it = tags.find("r9k")) != tags.end()) {
|
||||||
|
roomModes.r9k = it.value() == "1";
|
||||||
|
}
|
||||||
|
if ((it = tags.find("broadcaster-lang")) != tags.end()) {
|
||||||
|
roomModes.broadcasterLang = it.value().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
twitchChannel->setRoomModes(roomModes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +80,7 @@ void IrcMessageHandler::handleClearChatMessage(Communi::IrcMessage *message)
|
||||||
}
|
}
|
||||||
|
|
||||||
QString chanName;
|
QString chanName;
|
||||||
if (!TrimChannelName(message->parameter(0), chanName)) {
|
if (!trimChannelName(message->parameter(0), chanName)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +130,7 @@ void IrcMessageHandler::handleUserStateMessage(Communi::IrcMessage *message)
|
||||||
auto app = getApp();
|
auto app = getApp();
|
||||||
|
|
||||||
QString channelName;
|
QString channelName;
|
||||||
if (!TrimChannelName(message->parameter(0), channelName)) {
|
if (!trimChannelName(message->parameter(0), channelName)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,7 +217,8 @@ void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message)
|
||||||
// auto channel = app->twitch.server->getChannelOrEmpty(channelName);
|
// auto channel = app->twitch.server->getChannelOrEmpty(channelName);
|
||||||
|
|
||||||
// if (channel->isEmpty()) {
|
// if (channel->isEmpty()) {
|
||||||
// debug::Log("[IrcManager:handleNoticeMessage] Channel {} not found in channel manager",
|
// debug::Log("[IrcManager:handleNoticeMessage] Channel {} not found in channel
|
||||||
|
// manager",
|
||||||
// channelName);
|
// channelName);
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
|
|
|
@ -86,7 +86,7 @@ TwitchChannel::TwitchChannel(const QString &channelName, Communi::IrcConnection
|
||||||
};
|
};
|
||||||
|
|
||||||
auto doRefreshChatters = [=]() {
|
auto doRefreshChatters = [=]() {
|
||||||
const auto streamStatus = this->GetStreamStatus();
|
const auto streamStatus = this->getStreamStatus();
|
||||||
|
|
||||||
if (app->settings->onlyFetchChattersForSmallerStreamers) {
|
if (app->settings->onlyFetchChattersForSmallerStreamers) {
|
||||||
if (streamStatus.live && streamStatus.viewerCount > app->settings->smallStreamerLimit) {
|
if (streamStatus.live && streamStatus.viewerCount > app->settings->smallStreamerLimit) {
|
||||||
|
@ -213,6 +213,35 @@ void TwitchChannel::addRecentChatter(const std::shared_ptr<messages::Message> &m
|
||||||
this->completionModel.addUser(message->displayName);
|
this->completionModel.addUser(message->displayName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TwitchChannel::RoomModes TwitchChannel::getRoomModes()
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(this->roomModeMutex);
|
||||||
|
|
||||||
|
return this->roomModes;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TwitchChannel::setRoomModes(const RoomModes &_roomModes)
|
||||||
|
{
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(this->roomModeMutex);
|
||||||
|
this->roomModes = _roomModes;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->roomModesChanged.invoke();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TwitchChannel::isLive() const
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(this->streamStatusMutex);
|
||||||
|
return this->streamStatus.live;
|
||||||
|
}
|
||||||
|
|
||||||
|
TwitchChannel::StreamStatus TwitchChannel::getStreamStatus() const
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(this->streamStatusMutex);
|
||||||
|
return this->streamStatus;
|
||||||
|
}
|
||||||
|
|
||||||
void TwitchChannel::setLive(bool newLiveStatus)
|
void TwitchChannel::setLive(bool newLiveStatus)
|
||||||
{
|
{
|
||||||
bool gotNewLiveStatus = false;
|
bool gotNewLiveStatus = false;
|
||||||
|
|
|
@ -38,6 +38,15 @@ public:
|
||||||
bool broadcaster;
|
bool broadcaster;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct RoomModes {
|
||||||
|
bool submode = false;
|
||||||
|
bool r9k = false;
|
||||||
|
bool emoteOnly = false;
|
||||||
|
// int folowerOnly = 0;
|
||||||
|
int slowMode = 0;
|
||||||
|
QString broadcasterLang;
|
||||||
|
};
|
||||||
|
|
||||||
~TwitchChannel() final;
|
~TwitchChannel() final;
|
||||||
|
|
||||||
void reloadChannelEmotes();
|
void reloadChannelEmotes();
|
||||||
|
@ -66,25 +75,20 @@ public:
|
||||||
|
|
||||||
pajlada::Signals::NoArgBoltSignal fetchMessages;
|
pajlada::Signals::NoArgBoltSignal fetchMessages;
|
||||||
pajlada::Signals::NoArgSignal userStateChanged;
|
pajlada::Signals::NoArgSignal userStateChanged;
|
||||||
|
pajlada::Signals::NoArgSignal roomModesChanged;
|
||||||
|
|
||||||
QString roomID;
|
QString roomID;
|
||||||
|
RoomModes getRoomModes();
|
||||||
|
void setRoomModes(const RoomModes &roomModes);
|
||||||
|
|
||||||
StreamStatus GetStreamStatus() const
|
StreamStatus getStreamStatus() const;
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> lock(this->streamStatusMutex);
|
|
||||||
return this->streamStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct NameOptions {
|
struct NameOptions {
|
||||||
QString displayName;
|
QString displayName;
|
||||||
QString localizedName;
|
QString localizedName;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool IsLive() const
|
bool isLive() const;
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> lock(this->streamStatusMutex);
|
|
||||||
return this->streamStatus.live;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit TwitchChannel(const QString &channelName, Communi::IrcConnection *readConnection);
|
explicit TwitchChannel(const QString &channelName, Communi::IrcConnection *readConnection);
|
||||||
|
@ -103,6 +107,8 @@ private:
|
||||||
bool mod;
|
bool mod;
|
||||||
QByteArray messageSuffix;
|
QByteArray messageSuffix;
|
||||||
QString lastSentMessage;
|
QString lastSentMessage;
|
||||||
|
RoomModes roomModes;
|
||||||
|
std::mutex roomModeMutex;
|
||||||
|
|
||||||
Communi::IrcConnection *readConnection;
|
Communi::IrcConnection *readConnection;
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ namespace chatterino {
|
||||||
namespace providers {
|
namespace providers {
|
||||||
namespace twitch {
|
namespace twitch {
|
||||||
|
|
||||||
bool TrimChannelName(const QString &channelName, QString &outChannelName)
|
bool trimChannelName(const QString &channelName, QString &outChannelName)
|
||||||
{
|
{
|
||||||
if (channelName.length() < 3) {
|
if (channelName.length() < 3) {
|
||||||
debug::Log("channel name length below 3");
|
debug::Log("channel name length below 3");
|
||||||
|
|
|
@ -6,7 +6,7 @@ namespace chatterino {
|
||||||
namespace providers {
|
namespace providers {
|
||||||
namespace twitch {
|
namespace twitch {
|
||||||
|
|
||||||
bool TrimChannelName(const QString &channelName, QString &outChannelName);
|
bool trimChannelName(const QString &channelName, QString &outChannelName);
|
||||||
|
|
||||||
} // namespace twitch
|
} // namespace twitch
|
||||||
} // namespace providers
|
} // namespace providers
|
||||||
|
|
|
@ -78,7 +78,7 @@ std::shared_ptr<Channel> TwitchServer::createChannel(const QString &channelName)
|
||||||
void TwitchServer::privateMessageReceived(IrcPrivateMessage *message)
|
void TwitchServer::privateMessageReceived(IrcPrivateMessage *message)
|
||||||
{
|
{
|
||||||
QString channelName;
|
QString channelName;
|
||||||
if (!TrimChannelName(message->target(), channelName)) {
|
if (!trimChannelName(message->target(), channelName)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,6 @@ FontManager::FontData &FontManager::getOrCreateFontData(Type type, float scale)
|
||||||
if (it != map.end()) {
|
if (it != map.end()) {
|
||||||
// return if found
|
// return if found
|
||||||
|
|
||||||
qDebug() << it->second.font;
|
|
||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,16 @@ SplitHeader::SplitHeader(Split *_split)
|
||||||
|
|
||||||
layout->addStretch(1);
|
layout->addStretch(1);
|
||||||
|
|
||||||
|
// mode button
|
||||||
|
auto mode = layout.emplace<RippleEffectLabel>(this).assign(&this->modeButton);
|
||||||
|
|
||||||
|
mode->getLabel().setText("dank\nmemes");
|
||||||
|
|
||||||
|
// QObject::connect(mode.getElement(), &RippleEffectButton::clicked, this, [this]
|
||||||
|
// {
|
||||||
|
// //
|
||||||
|
// });
|
||||||
|
|
||||||
// moderation mode
|
// moderation mode
|
||||||
auto moderator = layout.emplace<RippleEffectButton>(this).assign(&this->moderationButton);
|
auto moderator = layout.emplace<RippleEffectButton>(this).assign(&this->moderationButton);
|
||||||
|
|
||||||
|
@ -167,7 +177,7 @@ void SplitHeader::updateChannelText()
|
||||||
TwitchChannel *twitchChannel = dynamic_cast<TwitchChannel *>(channel.get());
|
TwitchChannel *twitchChannel = dynamic_cast<TwitchChannel *>(channel.get());
|
||||||
|
|
||||||
if (twitchChannel != nullptr) {
|
if (twitchChannel != nullptr) {
|
||||||
const auto &streamStatus = twitchChannel->GetStreamStatus();
|
const auto &streamStatus = twitchChannel->getStreamStatus();
|
||||||
|
|
||||||
if (streamStatus.live) {
|
if (streamStatus.live) {
|
||||||
this->isLive = true;
|
this->isLive = true;
|
||||||
|
@ -216,6 +226,45 @@ void SplitHeader::updateModerationModeIcon()
|
||||||
this->moderationButton->setVisible(modButtonVisible);
|
this->moderationButton->setVisible(modButtonVisible);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SplitHeader::updateModes()
|
||||||
|
{
|
||||||
|
TwitchChannel *tc = dynamic_cast<TwitchChannel *>(this->split->getChannel().get());
|
||||||
|
if (tc == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
TwitchChannel::RoomModes roomModes = tc->getRoomModes();
|
||||||
|
|
||||||
|
QString text;
|
||||||
|
|
||||||
|
if (roomModes.r9k) {
|
||||||
|
text += "r9k, ";
|
||||||
|
}
|
||||||
|
if (roomModes.slowMode) {
|
||||||
|
text += QString("slow(%1), ").arg(QString::number(roomModes.slowMode));
|
||||||
|
}
|
||||||
|
if (roomModes.emoteOnly) {
|
||||||
|
text += "emote, ";
|
||||||
|
}
|
||||||
|
if (roomModes.submode) {
|
||||||
|
text += "sub, ";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (text.length() > 2) {
|
||||||
|
text = text.mid(0, text.size() - 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
qDebug() << text;
|
||||||
|
|
||||||
|
static QRegularExpression commaReplacement("^.+?, .+?,( ).+$");
|
||||||
|
QRegularExpressionMatch match = commaReplacement.match(text);
|
||||||
|
if (match.hasMatch()) {
|
||||||
|
text = text.mid(0, match.capturedStart(1)) + '\n' + text.mid(match.capturedEnd(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
this->modeButton->getLabel().setText(text);
|
||||||
|
}
|
||||||
|
|
||||||
void SplitHeader::paintEvent(QPaintEvent *)
|
void SplitHeader::paintEvent(QPaintEvent *)
|
||||||
{
|
{
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
|
|
|
@ -34,6 +34,7 @@ public:
|
||||||
// Update channel text from chat widget
|
// Update channel text from chat widget
|
||||||
void updateChannelText();
|
void updateChannelText();
|
||||||
void updateModerationModeIcon();
|
void updateModerationModeIcon();
|
||||||
|
void updateModes();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void scaleChangedEvent(float) override;
|
virtual void scaleChangedEvent(float) override;
|
||||||
|
@ -59,6 +60,7 @@ private:
|
||||||
RippleEffectButton *dropdownButton;
|
RippleEffectButton *dropdownButton;
|
||||||
// Label *titleLabel;
|
// Label *titleLabel;
|
||||||
SignalLabel *titleLabel;
|
SignalLabel *titleLabel;
|
||||||
|
RippleEffectLabel *modeButton;
|
||||||
RippleEffectButton *moderationButton;
|
RippleEffectButton *moderationButton;
|
||||||
|
|
||||||
QMenu dropdownMenu;
|
QMenu dropdownMenu;
|
||||||
|
|
|
@ -129,15 +129,10 @@ Split::Split(QWidget *parent)
|
||||||
this->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
this->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||||
|
|
||||||
this->managedConnect(modifierStatusChanged, [this](Qt::KeyboardModifiers status) {
|
this->managedConnect(modifierStatusChanged, [this](Qt::KeyboardModifiers status) {
|
||||||
|
|
||||||
qDebug() << "xD" << status;
|
|
||||||
|
|
||||||
if ((status == Qt::AltModifier || status == (Qt::AltModifier | Qt::ControlModifier)) &&
|
if ((status == Qt::AltModifier || status == (Qt::AltModifier | Qt::ControlModifier)) &&
|
||||||
this->isMouseOver) {
|
this->isMouseOver) {
|
||||||
qDebug() << "show";
|
|
||||||
this->overlay->show();
|
this->overlay->show();
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "hide";
|
|
||||||
this->overlay->hide();
|
this->overlay->hide();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -187,6 +182,7 @@ void Split::setChannel(IndirectChannel newChannel)
|
||||||
this->view.setChannel(newChannel.get());
|
this->view.setChannel(newChannel.get());
|
||||||
|
|
||||||
this->usermodeChangedConnection.disconnect();
|
this->usermodeChangedConnection.disconnect();
|
||||||
|
this->roomModeChangedConnection.disconnect();
|
||||||
this->indirectChannelChangedConnection.disconnect();
|
this->indirectChannelChangedConnection.disconnect();
|
||||||
|
|
||||||
TwitchChannel *tc = dynamic_cast<TwitchChannel *>(newChannel.get().get());
|
TwitchChannel *tc = dynamic_cast<TwitchChannel *>(newChannel.get().get());
|
||||||
|
@ -194,6 +190,9 @@ void Split::setChannel(IndirectChannel newChannel)
|
||||||
if (tc != nullptr) {
|
if (tc != nullptr) {
|
||||||
this->usermodeChangedConnection =
|
this->usermodeChangedConnection =
|
||||||
tc->userStateChanged.connect([this] { this->header.updateModerationModeIcon(); });
|
tc->userStateChanged.connect([this] { this->header.updateModerationModeIcon(); });
|
||||||
|
|
||||||
|
this->roomModeChangedConnection =
|
||||||
|
tc->roomModesChanged.connect([this] { this->header.updateModes(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
this->indirectChannelChangedConnection = newChannel.getChannelChanged().connect([this] { //
|
this->indirectChannelChangedConnection = newChannel.getChannelChanged().connect([this] { //
|
||||||
|
@ -202,6 +201,7 @@ void Split::setChannel(IndirectChannel newChannel)
|
||||||
|
|
||||||
this->header.updateModerationModeIcon();
|
this->header.updateModerationModeIcon();
|
||||||
this->header.updateChannelText();
|
this->header.updateChannelText();
|
||||||
|
this->header.updateModes();
|
||||||
|
|
||||||
this->channelChanged.invoke();
|
this->channelChanged.invoke();
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,6 +100,8 @@ private:
|
||||||
|
|
||||||
pajlada::Signals::Connection channelIDChangedConnection;
|
pajlada::Signals::Connection channelIDChangedConnection;
|
||||||
pajlada::Signals::Connection usermodeChangedConnection;
|
pajlada::Signals::Connection usermodeChangedConnection;
|
||||||
|
pajlada::Signals::Connection roomModeChangedConnection;
|
||||||
|
|
||||||
pajlada::Signals::Connection indirectChannelChangedConnection;
|
pajlada::Signals::Connection indirectChannelChangedConnection;
|
||||||
|
|
||||||
std::vector<pajlada::Signals::ScopedConnection> managedConnections;
|
std::vector<pajlada::Signals::ScopedConnection> managedConnections;
|
||||||
|
|
Loading…
Reference in a new issue