Skip to content

chore: refactor TwitchIrcServer - #5421

Merged
pajlada merged 23 commits into
masterfrom
chore/refactor-twitchircserver
Jun 1, 2024
Merged

pajlada merged 23 commits into
masterfrom
chore/refactor-twitchircserver

Conversation

@pajlada

@pajlada pajlada commented May 25, 2024 •

Copy link
Copy Markdown
Member

This PR aims to remove all direct uses of getApp()->twitch, ensuring we can add tests for anything adjacent to TwitchIrcServer

The class and its inheritance is ugly, so this refactor PR is also pretty ugly. To achieve the goal of this PR without making too many changes, I've added getTwitchAbstract() alongside getTwitch() which returns the IAbstractIrcServer of the TwitchIrcServer.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

Comment thread src/Application.hpp Outdated
pajlada added 22 commits June 1, 2024 14:11
we currently don't uninitialize it (meaning we don't change anything yet)
This will be used, in the interim, for non-overloaded-TwitchIrcServer
functions (e.g. getOrAddChannel), to allow for full mocking.

This is not the intended final state of these classes, but will make it
easier to move functionality out of things when that step is taken.
@pajlada
pajlada force-pushed the chore/refactor-twitchircserver branch from 2cbaaec to c3f99c7 Compare June 1, 2024 12:11
@pajlada pajlada changed the title chore: refactor TwitchIrcServer (unsingletonize/interfaceizes) chore: refactor TwitchIrcServer Jun 1, 2024
@pajlada
pajlada marked this pull request as ready for review June 1, 2024 12:31
@pajlada

pajlada commented Jun 1, 2024

Copy link
Copy Markdown
Member Author

image

Small testing shows everything works as expected - I've done a full self-review, ensuring I haven't c-v-pasted anything incorrectly.

@pajlada
pajlada enabled auto-merge (squash) June 1, 2024 12:36

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

return nullptr;
}

IAbstractIrcServer *getTwitchAbstract() override

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: method 'getTwitchAbstract' can be made static [readability-convert-member-functions-to-static]

Suggested change
IAbstractIrcServer *getTwitchAbstract() override
static IAbstractIrcServer *getTwitchAbstract() override


IAbstractIrcServer *getTwitchAbstract() override
{
assert(false && "EmptyApplication::getTwitchAbstract was called "

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: implicit conversion 'const char *' -> 'bool' [readability-implicit-bool-conversion]

        assert(false && "EmptyApplication::getTwitchAbstract was called "
                        ^

this fix will not be applied because it overlaps with another fix

IAbstractIrcServer *getTwitchAbstract() override
{
assert(false && "EmptyApplication::getTwitchAbstract was called "
"without being initialized");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: redundant boolean literal supplied to boolean operator [readability-simplify-boolean-expr]

Suggested change
"without being initialized");
assert(false);

@@ -2,8 +2,13 @@

#include "mocks/Channel.hpp"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: 'mocks/Channel.hpp' file not found [clang-diagnostic-error]

#include "mocks/Channel.hpp"
         ^

#include "mocks/Channel.hpp"
#include "providers/bttv/BttvEmotes.hpp"
#include "providers/bttv/BttvLiveUpdates.hpp"
#include "providers/ffz/FfzEmotes.hpp"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: included header BttvLiveUpdates.hpp is not used directly [misc-include-cleaner]

Suggested change
#include "providers/ffz/FfzEmotes.hpp"
#include "providers/ffz/FfzEmotes.hpp"

virtual void forEachChannel(std::function<void(ChannelPtr)> func) = 0;
};

class AbstractIrcServer : public IAbstractIrcServer, public QObject

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "QObject" is directly included [misc-include-cleaner]

src/providers/irc/AbstractIrcServer.hpp:9:

+ #include <qobject.h>


void addMessage(Communi::IrcMessage *message, const ChannelPtr &chan,
const QString &originalContent, TwitchIrcServer &server,
const QString &originalContent, ITwitchIrcServer &server,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "QString" is directly included [misc-include-cleaner]

src/providers/twitch/IrcMessageHandler.hpp:5:

+ #include <qobject.h>

sent = true;
}

std::unique_ptr<BttvLiveUpdates> &TwitchIrcServer::getBTTVLiveUpdates()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "std::unique_ptr" is directly included [misc-include-cleaner]

std::unique_ptr<BttvLiveUpdates> &TwitchIrcServer::getBTTVLiveUpdates()
     ^

virtual ~ITwitchIrcServer() = default;

virtual void forEachChannelAndSpecialChannels(
std::function<void(ChannelPtr)> func) = 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "std::function" is directly included [misc-include-cleaner]

src/providers/twitch/TwitchIrcServer.hpp:10:

- #include <memory>
+ #include <functional>
+ #include <memory>

std::function<void(ChannelPtr)> func) = 0;

virtual std::shared_ptr<Channel> getChannelOrEmptyByID(
const QString &channelID) = 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "QString" is directly included [misc-include-cleaner]

src/providers/twitch/TwitchIrcServer.hpp:8:

+ #include <qhashfunctions.h>

@pajlada
pajlada merged commit b6dc5d9 into master Jun 1, 2024
@pajlada
pajlada deleted the chore/refactor-twitchircserver branch June 1, 2024 12:56
babicekmarek pushed a commit to babicekmarek/streamally-chatterino that referenced this pull request Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant