Skip to content

Commit

Permalink
refactor: Fix a bunch of minor things (Chatterino#5094)
Browse files Browse the repository at this point in the history
  • Loading branch information
pajlada authored and devJimmyboy committed Feb 11, 2024
1 parent bacb168 commit ed2b8d0
Show file tree
Hide file tree
Showing 11 changed files with 188 additions and 131 deletions.
2 changes: 1 addition & 1 deletion src/messages/Emote.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct Emote {
ImageSet images;
Tooltip tooltip;
Url homePage;
bool zeroWidth;
bool zeroWidth{};
EmoteId id;
EmoteAuthor author;
/**
Expand Down
1 change: 1 addition & 0 deletions src/messages/SharedMessageBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class SharedMessageBuilder : public MessageBuilder

virtual Outcome tryAppendEmote(const EmoteName &name)
{
(void)name;
return Failure;
}

Expand Down
10 changes: 9 additions & 1 deletion src/providers/irc/AbstractIrcServer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class AbstractIrcServer : public QObject
enum ConnectionType { Read = 1, Write = 2, Both = 3 };

~AbstractIrcServer() override = default;
AbstractIrcServer(const AbstractIrcServer &) = delete;
AbstractIrcServer(AbstractIrcServer &&) = delete;
AbstractIrcServer &operator=(const AbstractIrcServer &) = delete;
AbstractIrcServer &operator=(AbstractIrcServer &&) = delete;

// initializeIrc must be called from the derived class
// this allows us to initialize the abstract IRC server based on the derived class's parameters
Expand Down Expand Up @@ -57,7 +61,11 @@ class AbstractIrcServer : public QObject
// initializeConnectionSignals is called on a connection once in its lifetime.
// it can be used to connect signals to your class
virtual void initializeConnectionSignals(IrcConnection *connection,
ConnectionType type){};
ConnectionType type)
{
(void)connection;
(void)type;
}

// initializeConnection is called every time before we try to connect to the IRC server
virtual void initializeConnection(IrcConnection *connection,
Expand Down
19 changes: 14 additions & 5 deletions src/providers/twitch/PubSubClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,29 @@ void PubSubClient::close(const std::string &reason,
});
}

bool PubSubClient::listen(PubSubListenMessage msg)
bool PubSubClient::listen(const PubSubListenMessage &msg)
{
int numRequestedListens = msg.topics.size();
auto numRequestedListens = msg.topics.size();

if (this->numListens_ + numRequestedListens > PubSubClient::MAX_LISTENS)
{
// This PubSubClient is already at its peak listens
return false;
}
this->numListens_ += numRequestedListens;
DebugCount::increase("PubSub topic pending listens", numRequestedListens);
DebugCount::increase("PubSub topic pending listens",
static_cast<int64_t>(numRequestedListens));

for (const auto &topic : msg.topics)
{
this->listeners_.emplace_back(Listener{topic, false, false, false});
this->listeners_.emplace_back(Listener{
TopicData{
topic,
false,
false,
},
false,
});
}

qCDebug(chatterinoPubSub)
Expand Down Expand Up @@ -127,7 +135,7 @@ PubSubClient::UnlistenPrefixResponse PubSubClient::unlistenPrefix(

this->numListens_ -= numRequestedUnlistens;
DebugCount::increase("PubSub topic pending unlistens",
numRequestedUnlistens);
static_cast<int64_t>(numRequestedUnlistens));

PubSubUnlistenMessage message(topics);

Expand Down Expand Up @@ -192,6 +200,7 @@ void PubSubClient::ping()

runAfter(this->heartbeatTimer_, this->clientOptions_.pingInterval_,
[self](auto timer) {
(void)timer;
if (!self->started_)
{
return;
Expand Down
2 changes: 1 addition & 1 deletion src/providers/twitch/PubSubClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class PubSubClient : public std::enable_shared_from_this<PubSubClient>
websocketpp::close::status::value code =
websocketpp::close::status::normal);

bool listen(PubSubListenMessage msg);
bool listen(const PubSubListenMessage &msg);
UnlistenPrefixResponse unlistenPrefix(const QString &prefix);

void handleListenResponse(const PubSubMessage &message);
Expand Down
79 changes: 45 additions & 34 deletions src/providers/twitch/TwitchChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ TwitchChannel::TwitchChannel(const QString &name)
, bttvEmotes_(std::make_shared<EmoteMap>())
, ffzEmotes_(std::make_shared<EmoteMap>())
, seventvEmotes_(std::make_shared<EmoteMap>())
, mod_(false)
{
qCDebug(chatterinoTwitch) << "[TwitchChannel" << name << "] Opened";

Expand Down Expand Up @@ -325,13 +324,15 @@ void TwitchChannel::refreshFFZChannelEmotes(bool manualRefresh)
[this, weak = weakOf<Channel>(this)](auto &&modBadge) {
if (auto shared = weak.lock())
{
this->ffzCustomModBadge_.set(std::move(modBadge));
this->ffzCustomModBadge_.set(
std::forward<decltype(modBadge)>(modBadge));
}
},
[this, weak = weakOf<Channel>(this)](auto &&vipBadge) {
if (auto shared = weak.lock())
{
this->ffzCustomVipBadge_.set(std::move(vipBadge));
this->ffzCustomVipBadge_.set(
std::forward<decltype(vipBadge)>(vipBadge));
}
},
manualRefresh);
Expand Down Expand Up @@ -781,12 +782,12 @@ void TwitchChannel::setRoomId(const QString &id)
SharedAccessGuard<const TwitchChannel::RoomModes>
TwitchChannel::accessRoomModes() const
{
return this->roomModes_.accessConst();
return this->roomModes.accessConst();
}

void TwitchChannel::setRoomModes(const RoomModes &_roomModes)
void TwitchChannel::setRoomModes(const RoomModes &newRoomModes)
{
this->roomModes_ = _roomModes;
this->roomModes = newRoomModes;

this->roomModesChanged.invoke();
}
Expand Down Expand Up @@ -1136,7 +1137,7 @@ const QString &TwitchChannel::popoutPlayerUrl()
return this->popoutPlayerUrl_;
}

int TwitchChannel::chatterCount()
int TwitchChannel::chatterCount() const
{
return this->chatterCount_;
}
Expand Down Expand Up @@ -1204,7 +1205,7 @@ void TwitchChannel::loadRecentMessages()
tc->loadingRecentMessages_.clear();

std::vector<MessagePtr> msgs;
for (MessagePtr msg : messages)
for (const auto &msg : messages)
{
const auto highlighted =
msg->flags.has(MessageFlag::Highlighted);
Expand Down Expand Up @@ -1354,7 +1355,10 @@ void TwitchChannel::refreshChatters()
}
},
// Refresh chatters should only be used when failing silently is an option
[](auto error, auto message) {});
[](auto error, auto message) {
(void)error;
(void)message;
});
}

void TwitchChannel::addReplyThread(const std::shared_ptr<MessageThread> &thread)
Expand Down Expand Up @@ -1432,14 +1436,15 @@ void TwitchChannel::refreshBadges()
for (const auto &version : badgeSet.versions)
{
auto emote = Emote{
EmoteName{},
ImageSet{
Image::fromUrl(version.imageURL1x, 1),
Image::fromUrl(version.imageURL2x, .5),
Image::fromUrl(version.imageURL4x, .25),
},
Tooltip{version.title},
version.clickURL,
.name = EmoteName{},
.images =
ImageSet{
Image::fromUrl(version.imageURL1x, 1),
Image::fromUrl(version.imageURL2x, .5),
Image::fromUrl(version.imageURL4x, .25),
},
.tooltip = Tooltip{version.title},
.homePage = version.clickURL,
};
(*badgeSets)[setID][version.id] =
std::make_shared<Emote>(emote);
Expand Down Expand Up @@ -1511,22 +1516,28 @@ void TwitchChannel::refreshCheerEmotes()
// Combine the prefix (e.g. BibleThump) with the tier (1, 100 etc.)
auto emoteTooltip =
set.prefix + tier.id + "<br>Twitch Cheer Emote";
cheerEmote.animatedEmote = std::make_shared<Emote>(
Emote{EmoteName{"cheer emote"},
ImageSet{
tier.darkAnimated.imageURL1x,
tier.darkAnimated.imageURL2x,
tier.darkAnimated.imageURL4x,
},
Tooltip{emoteTooltip}, Url{}});
cheerEmote.staticEmote = std::make_shared<Emote>(
Emote{EmoteName{"cheer emote"},
ImageSet{
tier.darkStatic.imageURL1x,
tier.darkStatic.imageURL2x,
tier.darkStatic.imageURL4x,
},
Tooltip{emoteTooltip}, Url{}});
cheerEmote.animatedEmote = std::make_shared<Emote>(Emote{
.name = EmoteName{"cheer emote"},
.images =
ImageSet{
tier.darkAnimated.imageURL1x,
tier.darkAnimated.imageURL2x,
tier.darkAnimated.imageURL4x,
},
.tooltip = Tooltip{emoteTooltip},
.homePage = Url{},
});
cheerEmote.staticEmote = std::make_shared<Emote>(Emote{
.name = EmoteName{"cheer emote"},
.images =
ImageSet{
tier.darkStatic.imageURL1x,
tier.darkStatic.imageURL2x,
tier.darkStatic.imageURL4x,
},
.tooltip = Tooltip{emoteTooltip},
.homePage = Url{},
});

cheerEmoteSet.cheerEmotes.emplace_back(
std::move(cheerEmote));
Expand Down Expand Up @@ -1763,7 +1774,7 @@ void TwitchChannel::updateSevenTVActivity()
});
}

void TwitchChannel::listenSevenTVCosmetics()
void TwitchChannel::listenSevenTVCosmetics() const
{
if (getApp()->twitch->seventvEventAPI)
{
Expand Down
13 changes: 9 additions & 4 deletions src/providers/twitch/TwitchChannel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ class TwitchChannel final : public Channel, public ChannelChatters
explicit TwitchChannel(const QString &channelName);
~TwitchChannel() override;

TwitchChannel(const TwitchChannel &) = delete;
TwitchChannel(TwitchChannel &&) = delete;
TwitchChannel &operator=(const TwitchChannel &) = delete;
TwitchChannel &operator=(TwitchChannel &&) = delete;

void initialize();

// Channel methods
Expand All @@ -130,7 +135,7 @@ class TwitchChannel final : public Channel, public ChannelChatters
const QString &subscriptionUrl();
const QString &channelUrl();
const QString &popoutPlayerUrl();
int chatterCount();
int chatterCount() const;
bool isLive() const override;
QString roomId() const;
SharedAccessGuard<const RoomModes> accessRoomModes() const;
Expand Down Expand Up @@ -305,7 +310,7 @@ class TwitchChannel final : public Channel, public ChannelChatters
* This is done at most once every 60s.
*/
void updateSevenTVActivity();
void listenSevenTVCosmetics();
void listenSevenTVCosmetics() const;

/**
* @brief Sets the live status of this Twitch channel
Expand All @@ -317,7 +322,7 @@ class TwitchChannel final : public Channel, public ChannelChatters
void setVIP(bool value);
void setStaff(bool value);
void setRoomId(const QString &id);
void setRoomModes(const RoomModes &roomModes_);
void setRoomModes(const RoomModes &newRoomModes);
void setDisplayName(const QString &name);
void setLocalizedName(const QString &name);

Expand Down Expand Up @@ -376,7 +381,7 @@ class TwitchChannel final : public Channel, public ChannelChatters
const QString popoutPlayerUrl_;
int chatterCount_{};
UniqueAccess<StreamStatus> streamStatus_;
UniqueAccess<RoomModes> roomModes_;
UniqueAccess<RoomModes> roomModes;
bool disconnected_{};
std::optional<std::chrono::time_point<std::chrono::system_clock>>
lastConnectedAt_{};
Expand Down
4 changes: 3 additions & 1 deletion src/widgets/settingspages/GeneralPageView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class ComboBox : public QComboBox

void wheelEvent(QWheelEvent *event) override
{
(void)event;
}
};

Expand Down Expand Up @@ -311,8 +312,9 @@ class GeneralPageView : public QWidget
bool filterElements(const QString &query);

protected:
void resizeEvent(QResizeEvent *ev) override
void resizeEvent(QResizeEvent *event) override
{
(void)event;
}

private:
Expand Down
8 changes: 8 additions & 0 deletions src/widgets/splits/Split.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -959,17 +959,23 @@ void Split::paintEvent(QPaintEvent *)

void Split::mouseMoveEvent(QMouseEvent *event)
{
(void)event;

this->handleModifiers(QGuiApplication::queryKeyboardModifiers());
}

void Split::keyPressEvent(QKeyEvent *event)
{
(void)event;

this->view_->unsetCursor();
this->handleModifiers(QGuiApplication::queryKeyboardModifiers());
}

void Split::keyReleaseEvent(QKeyEvent *event)
{
(void)event;

this->view_->unsetCursor();
this->handleModifiers(QGuiApplication::queryKeyboardModifiers());
}
Expand Down Expand Up @@ -1005,6 +1011,8 @@ void Split::enterEvent(QEvent * /*event*/)

void Split::leaveEvent(QEvent *event)
{
(void)event;

this->isMouseOver_ = false;

this->overlay_->hide();
Expand Down
Loading

0 comments on commit ed2b8d0

Please sign in to comment.