Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into chatterino7
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerixyz committed Sep 14, 2024
2 parents e706aae + 694cc2d commit 218a486
Show file tree
Hide file tree
Showing 30 changed files with 628 additions and 110 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unversioned

- Major: Add option to show pronouns in user card. (#5442, #5583)
- Major: Release plugins alpha. (#5288)
- Major: Improve high-DPI support on Windows. (#4868, #5391)
- Minor: Removed the Ctrl+Shift+L hotkey for toggling the "live only" tab visibility state. (#5530)
Expand All @@ -23,7 +24,7 @@
- Minor: Improve appearance of reply button. (#5491)
- Minor: Introduce HTTP API for plugins. (#5383, #5492, #5494)
- Minor: Support more Firefox variants for incognito link opening. (#5503)
- Minor: Replying to a message will now display the message being replied to. (#4350, #5519)
- Minor: Replying to a message will now display the message being replied to. (#4350, #5519, #5586)
- Minor: Links can now have prefixes and suffixes such as parentheses. (#5486, #5515)
- Minor: Added support for scrolling in splits with touchscreen panning gestures. (#5524)
- Minor: Removed experimental IRC support. (#5547)
Expand All @@ -47,6 +48,7 @@
- Bugfix: Fixed tab visibility being controllable in the emote popup. (#5530)
- Bugfix: Fixed account switch not being saved if no other settings were changed. (#5558)
- Bugfix: Fixed some tooltips not being readable. (#5578)
- Bugfix: Fixed log files being locked longer than needed. (#5592)
- Dev: Update Windows build from Qt 6.5.0 to Qt 6.7.1. (#5420)
- Dev: Update vcpkg build Qt from 6.5.0 to 6.7.0, boost from 1.83.0 to 1.85.0, openssl from 3.1.3 to 3.3.0. (#5422)
- Dev: Unsingletonize `ISoundController`. (#5462)
Expand Down Expand Up @@ -84,6 +86,7 @@
- Dev: Refactored `MessageBuilder` to be a single class. (#5548)
- Dev: Recent changes are now shown in the nightly release description. (#5553, #5554)
- Dev: The timer for `StreamerMode` is now destroyed on the correct thread. (#5571)
- Dev: Cleanup some parts of the `magic_enum` adaptation for Qt. (#5587)

## 2.5.1

Expand Down
7 changes: 7 additions & 0 deletions mocks/include/mocks/EmptyApplication.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,13 @@ class EmptyApplication : public IApplication
return nullptr;
}

pronouns::Pronouns *getPronouns() override
{
assert(false && "EmptyApplication::getPronouns was called without "
"being initialized");
return nullptr;
}

QTemporaryDir settingsDir;
Paths paths_;
Args args_;
Expand Down
10 changes: 10 additions & 0 deletions mocks/include/mocks/Logging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class Logging : public ILogging
(const QString &channelName, MessagePtr message,
const QString &platformName, const QString &streamID),
(override));

MOCK_METHOD(void, closeChannel,
(const QString &channelName, const QString &platformName),
(override));
};

class EmptyLogging : public ILogging
Expand All @@ -32,6 +36,12 @@ class EmptyLogging : public ILogging
{
//
}

void closeChannel(const QString &channelName,
const QString &platformName) override
{
//
}
};

} // namespace chatterino::mock
18 changes: 17 additions & 1 deletion src/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "providers/bttv/BttvEmotes.hpp"
#include "providers/ffz/FfzEmotes.hpp"
#include "providers/links/LinkResolver.hpp"
#include "providers/pronouns/Pronouns.hpp"
#include "providers/seventv/SeventvAPI.hpp"
#include "providers/seventv/SeventvEmotes.hpp"
#include "providers/twitch/TwitchBadges.hpp"
Expand Down Expand Up @@ -151,6 +152,7 @@ Application::Application(Settings &_settings, const Paths &paths,
, args_(_args)
, themes(new Theme(paths))
, fonts(new Fonts(_settings))
, logging(new Logging(_settings))
, emotes(new Emotes)
, accounts(new AccountController)
, hotkeys(new HotkeyController)
Expand Down Expand Up @@ -179,10 +181,10 @@ Application::Application(Settings &_settings, const Paths &paths,
, ffzEmotes(new FfzEmotes)
, seventvEmotes(new SeventvEmotes)
, seventvEventAPI(makeSeventvEventAPI(_settings))
, logging(new Logging(_settings))
, linkResolver(new LinkResolver)
, streamerMode(new StreamerMode)
, twitchUsers(new TwitchUsers)
, pronouns(new pronouns::Pronouns)
#ifdef CHATTERINO_HAVE_PLUGINS
, plugins(new PluginController(paths))
#endif
Expand Down Expand Up @@ -542,6 +544,7 @@ PubSub *Application::getTwitchPubSub()
ILogging *Application::getChatLogger()
{
assertInGuiThread();
assert(this->logging);

return this->logging.get();
}
Expand Down Expand Up @@ -620,6 +623,14 @@ SeventvEventAPI *Application::getSeventvEventAPI()
return this->seventvEventAPI.get();
}

pronouns::Pronouns *Application::getPronouns()
{
// pronouns::Pronouns handles its own locks, so we don't need to assert that this is called in the GUI thread
assert(this->pronouns);

return this->pronouns.get();
}

void Application::save()
{
this->commands->save();
Expand Down Expand Up @@ -779,4 +790,9 @@ IApplication *getApp()
return INSTANCE;
}

IApplication *tryGetApp()
{
return INSTANCE;
}

} // namespace chatterino
11 changes: 10 additions & 1 deletion src/Application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class SeventvEventAPI;
class ILinkResolver;
class IStreamerMode;
class ITwitchUsers;
namespace pronouns {
class Pronouns;
} // namespace pronouns

class IApplication
{
Expand Down Expand Up @@ -110,6 +113,7 @@ class IApplication
virtual ILinkResolver *getLinkResolver() = 0;
virtual IStreamerMode *getStreamerMode() = 0;
virtual ITwitchUsers *getTwitchUsers() = 0;
virtual pronouns::Pronouns *getPronouns() = 0;
};

class Application : public IApplication
Expand Down Expand Up @@ -145,6 +149,7 @@ class Application : public IApplication
private:
std::unique_ptr<Theme> themes;
std::unique_ptr<Fonts> fonts;
const std::unique_ptr<Logging> logging;
std::unique_ptr<Emotes> emotes;
std::unique_ptr<AccountController> accounts;
std::unique_ptr<HotkeyController> hotkeys;
Expand Down Expand Up @@ -172,10 +177,10 @@ class Application : public IApplication
std::unique_ptr<FfzEmotes> ffzEmotes;
std::unique_ptr<SeventvEmotes> seventvEmotes;
std::unique_ptr<SeventvEventAPI> seventvEventAPI;
const std::unique_ptr<Logging> logging;
std::unique_ptr<ILinkResolver> linkResolver;
std::unique_ptr<IStreamerMode> streamerMode;
std::unique_ptr<ITwitchUsers> twitchUsers;
std::unique_ptr<pronouns::Pronouns> pronouns;
#ifdef CHATTERINO_HAVE_PLUGINS
std::unique_ptr<PluginController> plugins;
#endif
Expand Down Expand Up @@ -225,6 +230,7 @@ class Application : public IApplication
FfzEmotes *getFfzEmotes() override;
SeventvEmotes *getSeventvEmotes() override;
SeventvEventAPI *getSeventvEventAPI() override;
pronouns::Pronouns *getPronouns() override;

ILinkResolver *getLinkResolver() override;
IStreamerMode *getStreamerMode() override;
Expand All @@ -243,4 +249,7 @@ class Application : public IApplication

IApplication *getApp();

/// Might return `nullptr` if the app is being destroyed
IApplication *tryGetApp();

} // namespace chatterino
7 changes: 7 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,13 @@ set(SOURCE_FILES
providers/liveupdates/BasicPubSubManager.hpp
providers/liveupdates/BasicPubSubWebsocket.hpp

providers/pronouns/Pronouns.cpp
providers/pronouns/Pronouns.hpp
providers/pronouns/UserPronouns.cpp
providers/pronouns/UserPronouns.hpp
providers/pronouns/alejo/PronounsAlejoApi.cpp
providers/pronouns/alejo/PronounsAlejoApi.hpp

providers/recentmessages/Api.cpp
providers/recentmessages/Api.hpp
providers/recentmessages/Impl.cpp
Expand Down
5 changes: 5 additions & 0 deletions src/common/Channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ Channel::Channel(const QString &name, Type type)

Channel::~Channel()
{
auto *app = tryGetApp();
if (app)
{
app->getChatLogger()->closeChannel(this->name_, this->platform_);
}
this->destroyed.invoke();
}

Expand Down
1 change: 1 addition & 0 deletions src/common/QLogging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Q_LOGGING_CATEGORY(chatterinoNotification, "chatterino.notification",
logThreshold);
Q_LOGGING_CATEGORY(chatterinoImageuploader, "chatterino.imageuploader",
logThreshold);
Q_LOGGING_CATEGORY(chatterinoPronouns, "chatterino.pronouns", logThreshold);
Q_LOGGING_CATEGORY(chatterinoPubSub, "chatterino.pubsub", logThreshold);
Q_LOGGING_CATEGORY(chatterinoRecentMessages, "chatterino.recentmessages",
logThreshold);
Expand Down
1 change: 1 addition & 0 deletions src/common/QLogging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Q_DECLARE_LOGGING_CATEGORY(chatterinoMessage);
Q_DECLARE_LOGGING_CATEGORY(chatterinoNativeMessage);
Q_DECLARE_LOGGING_CATEGORY(chatterinoNetwork);
Q_DECLARE_LOGGING_CATEGORY(chatterinoNotification);
Q_DECLARE_LOGGING_CATEGORY(chatterinoPronouns);
Q_DECLARE_LOGGING_CATEGORY(chatterinoPubSub);
Q_DECLARE_LOGGING_CATEGORY(chatterinoRecentMessages);
Q_DECLARE_LOGGING_CATEGORY(chatterinoSettings);
Expand Down
66 changes: 66 additions & 0 deletions src/providers/pronouns/Pronouns.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include "providers/pronouns/Pronouns.hpp"

#include "Application.hpp"
#include "common/QLogging.hpp"
#include "providers/pronouns/alejo/PronounsAlejoApi.hpp"
#include "providers/pronouns/UserPronouns.hpp"

#include <mutex>
#include <unordered_map>

namespace {

// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
const auto &LOG = chatterinoPronouns;

} // namespace

namespace chatterino::pronouns {

void Pronouns::getUserPronoun(
const QString &username,
const std::function<void(UserPronouns)> &callbackSuccess,
const std::function<void()> &callbackFail)
{
// Only fetch pronouns if we haven't fetched before.
auto cachedPronoun = this->getCachedUserPronoun(username);
if (cachedPronoun.has_value())
{
callbackSuccess(*cachedPronoun);
return;
}

this->alejoApi.fetch(username, [this, callbackSuccess, callbackFail,
username](const auto &oUserPronoun) {
if (!oUserPronoun.has_value())
{
callbackFail();
return;
}

const auto &userPronoun = *oUserPronoun;

qCDebug(LOG) << "Caching pronoun" << userPronoun.format() << "for user"
<< username;
{
std::unique_lock lock(this->mutex);
this->saved[username] = userPronoun;
}

callbackSuccess(userPronoun);
});
}

std::optional<UserPronouns> Pronouns::getCachedUserPronoun(
const QString &username)
{
std::shared_lock lock(this->mutex);
auto it = this->saved.find(username);
if (it != this->saved.end())
{
return {it->second};
}
return {};
}

} // namespace chatterino::pronouns
32 changes: 32 additions & 0 deletions src/providers/pronouns/Pronouns.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once

#include "providers/pronouns/alejo/PronounsAlejoApi.hpp"
#include "providers/pronouns/UserPronouns.hpp"

#include <functional>
#include <optional>
#include <shared_mutex>
#include <unordered_map>

namespace chatterino::pronouns {

class Pronouns
{
public:
void getUserPronoun(
const QString &username,
const std::function<void(UserPronouns)> &callbackSuccess,
const std::function<void()> &callbackFail);

private:
// Retrieve cached pronouns for user.
std::optional<UserPronouns> getCachedUserPronoun(const QString &username);

// mutex for editing the saved map.
std::shared_mutex mutex;
// Login name -> Pronouns
std::unordered_map<QString, UserPronouns> saved;
AlejoApi alejoApi;
};

} // namespace chatterino::pronouns
24 changes: 24 additions & 0 deletions src/providers/pronouns/UserPronouns.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "providers/pronouns/UserPronouns.hpp"

#include <QString>

#include <optional>

namespace chatterino::pronouns {

UserPronouns::UserPronouns(QString pronouns)
: representation{!pronouns.isEmpty() ? std::move(pronouns) : QString()}
{
}

bool UserPronouns::isUnspecified() const
{
return this->representation.isEmpty();
}

UserPronouns::operator bool() const
{
return !isUnspecified();
}

} // namespace chatterino::pronouns
31 changes: 31 additions & 0 deletions src/providers/pronouns/UserPronouns.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include <QString>

namespace chatterino::pronouns {

class UserPronouns
{
public:
UserPronouns() = default;
UserPronouns(QString pronouns);

QString format() const
{
if (isUnspecified())
{
return "unspecified";
}
return this->representation;
}

bool isUnspecified() const;

/// True, iff the pronouns are not unspecified.
operator bool() const;

private:
QString representation;
};

} // namespace chatterino::pronouns
Loading

0 comments on commit 218a486

Please sign in to comment.