Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add setting for showing pronouns in user info popup #5442

Merged

Conversation

franzitrone
Copy link
Contributor

Common pronoun providers like alejo.io and pronoundb.org have respective browser extensions for twitch, but so far Chatterino does not support these providers.

I have now implemented a provider that fetches pronouns from APIs.
image

Pronoun providers can be configured in code, where, if multiple are configured the latter ones serve as a fallback for the former ones.

Right now, pronoundb.org and pronouns.alejo.io are implemented.

Pronouns are fetched when a message from a new user arrives and is cached application wide per session (as opposed to cache per tab). Pronouns are not added to the first message from a user. In the future, pronouns could be added to previous messages too.

For future-proofing, it is possible to fetch pronouns for multiple users at once, but right now, pronouns are fetched per-message if required.

@pajlada pajlada self-assigned this Jun 6, 2024
@pajlada
Copy link
Member

pajlada commented Jun 6, 2024

Some comments before I make a proper review:
Have you reached out to the API owners regarding adding this feature?
Do those API owners have some sort of privacy policy regarding data they store, and for the requests we make from Chatterino?
I'm not super fond of a request being spun off as soon as a message comes in, would it be super bad if it instead runs on a timer & bulk fetches data every ~30 seconds or so?

Copy link
Contributor

@github-actions github-actions bot left a comment

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

There were too many comments to post at once. Showing the first 25 out of 56. Check the log or trigger a new build to see more.

@franzitrone
Copy link
Contributor Author

Some comments before I make a proper review: Have you reached out to the API owners regarding adding this feature? Do those API owners have some sort of privacy policy regarding data they store, and for the requests we make from Chatterino? I'm not super fond of a request being spun off as soon as a message comes in, would it be super bad if it instead runs on a timer & bulk fetches data every ~30 seconds or so?

I think it should be easily possible to fetch on a timer, although I'm not familiar enough with the code base to know how or where timers are usually registered and run. Could you give me a pointer to where timers are usually placed? There was a "recent chatters" variable somewhere iirc, we could use this to occasionally on timer fetch pronouns for those.

Alejo.io unfortunately, to my understanding, has no documentation for the API at all, PronounDB has a documentation at https://pronoundb.org/wiki/api-docs and mentions setting a User-Agent (which should be set, as NetworkRequest is used). It does also provide a contact email, I'm probably going to ask there on what's the preferred way.

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 25 out of 56. Check the log or trigger a new build to see more.

I just realized I read and then completely skipped the entire clang-tidy part in the contribution guide to "do it later"... Whoops, I shall run it again locally and make the changes.

It also seems some things are broken on windows build (I think it's some std::size_t thing). I'll see if I can fix that, although I don't have Windows on any machine here.

@franzitrone franzitrone changed the title feat: Fetch and show pronouns for chatters. Draft: feat: Fetch and show pronouns for chatters. Jun 6, 2024
@franzitrone franzitrone marked this pull request as draft June 6, 2024 17:11
@franzitrone franzitrone changed the title Draft: feat: Fetch and show pronouns for chatters. feat: Fetch and show pronouns for chatters. Jun 6, 2024
@pajlada
Copy link
Member

pajlada commented Jun 6, 2024

Any sort of nitpicks or windows/macos/linux-specific things you can't fix can be easily fixed by any of our other contributors as part of the review process - we don't 100% listen to clang-tidy, so you can make a judgement call whether you care to listen to it

For the timer thing, I can bring up some example when I do my review of this PR in the weekend.
Generally, my opinion of the feature is that it should be opt-in as a user of Chatterino to use the API, and generally we shouldn't modify old messages unless very necessary.

@franzitrone
Copy link
Contributor Author

Any sort of nitpicks or windows/macos/linux-specific things you can't fix can be easily fixed by any of our other contributors as part of the review process - we don't 100% listen to clang-tidy, so you can make a judgement call whether you care to listen to it

Alright that sounds good! I'll go through the code again later or tomorrow.

For the timer thing, I can bring up some example when I do my review of this PR in the weekend.

Sounds good! When will you be reviewing? I might force-push new changes to my branch, but if needed I can just create a new branch and work on that.

Generally, my opinion of the feature is that it should be opt-in as a user of Chatterino to use the API, and generally we shouldn't modify old messages unless very necessary.

I've already created a checkbox in the settings menu to opt-out, I'll default it to disable then, which should also disable fetching.

@pajlada
Copy link
Member

pajlada commented Jun 6, 2024

I should be able to get a full review in on Saturday on Sunday on my stream, can delay to Sunday (or to whenever) if you want more time before I take a look

We Squash & Merge here, so you don't have to keep commits clean, I just prefer no force pushes after I've started reviewing

@Nerixyz
Copy link
Contributor

Nerixyz commented Jun 6, 2024

To fix compilation on Windows, you need to add an l, because long and unsigned long are four bytes (reference):

diff --git a/src/providers/pronouns/pronoundb/PronounsPronounDbApi.cpp b/src/providers/pronouns/pronoundb/PronounsPronounDbApi.cpp
index ca39f70f..728aed67 100644
--- a/src/providers/pronouns/pronoundb/PronounsPronounDbApi.cpp
+++ b/src/providers/pronouns/pronoundb/PronounsPronounDbApi.cpp
@@ -111,7 +111,7 @@ void PronounsPronounDbApi::fetch(std::vector<PronounUser> allUsers, IPronounsApi
   auto request = std::make_shared<IPronounsApi::RequestT>(allUsers.size(), std::move(onDone));
 
   for (std::size_t i {0}; i < allUsers.size(); i += 50) {
-    auto end = static_cast<std::size_t>(std::min(allUsers.size() - i, 50ul));
+    auto end = std::min(allUsers.size() - i, 50ull);
     auto users = std::vector<PronounUser>(allUsers.begin() + i, allUsers.begin() + i + end);
 
     NetworkRequest(PronounsPronounDbApi::makeRequest(users))

Just some general comments:

  • Please use clang-format to format your code (tip: turn on format-on-save in your editor).
  • The posted clang-tidy suggestions are valid (maybe the enum size one is debatable). You can use clang-tidy through clangd in your editor.
  • For documentation comments, use triple slash comments (/// - technically you could also use /** */, but it wastes two lines per comment).
  • Use QString over std::string, because we use it everywhere, and it's reference counted (but it doesn't have SSO sadly)
  • Although we mostly use one top-level namespace, I feel like a separate namespace for pronouns could be nice (so something like chatterino::PronounsPronounDbApi could become chatterino::pronouns::DbApi)
  • Currently, Chatterino makes one request to the DB per user, which could spam the provider quite a bit in fast chats. Maybe we could batch some requests (maybe at most one request per two seconds?).

@pajlada
Copy link
Member

pajlada commented Jun 6, 2024

For documentation comments, use triple slash comments (/// - technically you could also use /** */, but it wastes two lines per comment).

Although we mostly use one top-level namespace, I feel like a separate namespace for pronouns could be nice (so something like chatterino::PronounsPronounDbApi could become chatterino::pronouns::DbApi)

You can (and probably should) leave these changes until the implementation has been reviewed

Currently, Chatterino makes one request to the DB per user, which could spam the provider quite a bit in fast chats. Maybe we could batch some requests (maybe at most one request per two seconds?).

this is the same as i mentioned above

@franzitrone franzitrone force-pushed the mr/chatterino2/add-pronoun-provider branch 2 times, most recently from 488b6a7 to d72b09c Compare June 6, 2024 21:16
@franzitrone
Copy link
Contributor Author

I just noticed both of you had commented since I last checked (and before I pushed)!

@Nerixyz will do!

The latest version now queues users for fetching when messages arrive and are regularly dequeued and fetched in a batch. I don't think the alejo.io API supports batch requests and the (open-source) browser extension fetches per message too, but I still added a limit to avoid completely flooding it.

Copy link
Contributor

@github-actions github-actions bot left a comment

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

There were too many comments to post at once. Showing the first 25 out of 55. Check the log or trigger a new build to see more.


namespace chatterino {

class IPronounsApi
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: destructor of 'IPronounsApi' is public and non-virtual [cppcoreguidelines-virtual-class-destructor]

class IPronounsApi
      ^
Additional context

src/providers/pronouns/IPronounsApi.hpp:13: make it public and virtual

class IPronounsApi
      ^

using RequestT = PronounsApiRequest<ResultT>;

// Fetch pronouns from the API.
virtual void fetch(std::vector<PronounUser> users,
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: the parameter 'users' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]

    virtual void fetch(std::vector<PronounUser> users,
                                                ^


// Fetch pronouns from the API.
virtual void fetch(std::vector<PronounUser> users,
RequestT::CallbackT &&onDone){};
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: rvalue reference parameter 'onDone' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]

                       RequestT::CallbackT &&onDone){};
                                             ^

namespace chatterino {

PronounUser::PronounUser()
: id{}
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: initializer for member 'id' is redundant [readability-redundant-member-init]

Suggested change
: id{}
:


PronounUser::PronounUser()
: id{}
, username{}
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: initializer for member 'username' is redundant [readability-redundant-member-init]

Suggested change
, username{}
,

}
UserPronouns::UserPronouns(std::string pronouns)
{
if (pronouns.length() == 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: the 'empty' method should be used to check for emptiness instead of 'length' [readability-container-size-empty]

Suggested change
if (pronouns.length() == 0)
if (pronouns.empty())
Additional context

/usr/include/c++/13/bits/basic_string.h:1219: method 'basic_string'::empty() defined here

      empty() const _GLIBCXX_NOEXCEPT
      ^

UserPronouns();
UserPronouns(std::string);

inline std::string format() const
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: function 'format' has inline specifier but is implicitly inlined [readability-redundant-inline-specifier]

Suggested change
inline std::string format() const
std::string format() const

/*static*/ std::optional<std::unordered_map<std::string, std::string>>
PronounsAlejoApi::pronounsFromId = {};

/*static*/ UserPronouns PronounsAlejoApi::parse(QJsonObject object)
Copy link
Contributor

Choose a reason for hiding this comment

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

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

Suggested change
/*static*/ UserPronouns PronounsAlejoApi::parse(QJsonObject object)
/*static*/ static UserPronouns PronounsAlejoApi::parse(QJsonObject object)

/*static*/ std::optional<std::unordered_map<std::string, std::string>>
PronounsAlejoApi::pronounsFromId = {};

/*static*/ UserPronouns PronounsAlejoApi::parse(QJsonObject object)
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: out-of-line definition of 'parse' does not match any declaration in 'chatterino::PronounsAlejoApi' [clang-diagnostic-error]

/*static*/ UserPronouns PronounsAlejoApi::parse(QJsonObject object)
                                          ^

@Felanbird
Copy link
Collaborator

I don't think the alejo.io API supports batch requests and the (open-source) browser extension fetches per message too, but I still added a limit to avoid completely flooding it.

My main issue I outlined in #3346 was that alejo almost certainly can't keep up with the amount of requests we'd send, that 2 different implementations would return a different subset of users with pronouns, and it falls to blaming Chatterino if this feature we add works very sporadically (e.g. user reaction to bttv live emote updates)

pronounsdb does look like it could better handle the brunt of our requests in comparison though

@franzitrone
Copy link
Contributor Author

I don't think the alejo.io API supports batch requests and the (open-source) browser extension fetches per message too, but I still added a limit to avoid completely flooding it.

My main issue I outlined in #3346 was that alejo almost certainly can't keep up with the amount of requests we'd send, that 2 different implementations would return a different subset of users with pronouns, and it falls to blaming Chatterino if this feature we add works very sporadically (e.g. user reaction to bttv live emote updates)

pronounsdb does look like it could better handle the brunt of our requests in comparison though

PronounDB really does seem to handle it better, but it is unfortunately less widely used at least in the channels I've been lurking in. I'm wondering how alejo.io is working in the first place, as it seems that the browser extension is working in a flooding way too. If this is the intended way, and the way it is already implemented in its own browser extension, I don't see what sets apart Chatterino from just using a browser with the extension enabled (and then flooding the server in very lively channels).

@Felanbird
Copy link
Collaborator

I don't see what sets apart Chatterino from just using a browser with the extension enabled

Browser chat is 1 channel and Chatterino is up to 100

@franzitrone
Copy link
Contributor Author

I don't see what sets apart Chatterino from just using a browser with the extension enabled

Browser chat is 1 channel and Chatterino is up to 100

True. I suppose only queuing new users on message in the active tab leads to the aforementioned weird sporadic behaviour?

@iProdigy
Copy link
Contributor

iProdigy commented Jun 6, 2024

My recommendation is to only display the pronouns in the usercard - this minimizes http requests and avoids implementation complexity (of batching requests or caching thousands of pronouns)

I understand that the usercard approach reduces the convenience factor for this feature, but the technical challenges (in my opinion) puts us in a situation where we need to apply more pressure on Twitch to natively support pronouns (to display it inline with each chat message). Similar to the no-video and no-audio badges, there should be he,she,they badges natively selectable on Twitch, which would be very easy for us to support in a scalable manner

@Felanbird
Copy link
Collaborator

there should be he,she,they badges natively selectable on Twitch, which would be very easy for us to support in a scalable manner

not even just a badge, pronouns sent in the tags would be fine too (don't care about people who hate tags, they work)

@franzitrone franzitrone closed this Jun 7, 2024
@franzitrone franzitrone reopened this Jun 7, 2024
Copy link
Contributor

@github-actions github-actions bot left a comment

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

There were too many comments to post at once. Showing the first 25 out of 53. Check the log or trigger a new build to see more.


namespace chatterino {

class IPronounsApi
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: destructor of 'IPronounsApi' is public and non-virtual [cppcoreguidelines-virtual-class-destructor]

class IPronounsApi
      ^
Additional context

src/providers/pronouns/IPronounsApi.hpp:13: make it public and virtual

class IPronounsApi
      ^

using RequestT = PronounsApiRequest<ResultT>;

// Fetch pronouns from the API.
virtual void fetch(std::vector<PronounUser> users,
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: the parameter 'users' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]

    virtual void fetch(std::vector<PronounUser> users,
                                                ^


// Fetch pronouns from the API.
virtual void fetch(std::vector<PronounUser> users,
RequestT::CallbackT &&onDone){};
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: rvalue reference parameter 'onDone' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]

                       RequestT::CallbackT &&onDone){};
                                             ^

namespace chatterino {

PronounUser::PronounUser()
: id{}
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: initializer for member 'id' is redundant [readability-redundant-member-init]

Suggested change
: id{}
:


PronounUser::PronounUser()
: id{}
, username{}
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: initializer for member 'username' is redundant [readability-redundant-member-init]

Suggested change
, username{}
,

UserPronouns();
UserPronouns(std::string);

inline std::string format() const
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: function 'format' has inline specifier but is implicitly inlined [readability-redundant-inline-specifier]

Suggested change
inline std::string format() const
std::string format() const

/*static*/ std::optional<std::unordered_map<std::string, std::string>>
PronounsAlejoApi::pronounsFromId = {};

/*static*/ UserPronouns PronounsAlejoApi::parse(QJsonObject object)
Copy link
Contributor

Choose a reason for hiding this comment

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

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

Suggested change
/*static*/ UserPronouns PronounsAlejoApi::parse(QJsonObject object)
/*static*/ static UserPronouns PronounsAlejoApi::parse(QJsonObject object)

else
{
return {};
}
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: do not use 'else' after 'return' [llvm-else-after-return]

Suggested change
}
return {};

NetworkRequest(PronounsAlejoApi::API_URL + PronounsAlejoApi::API_USERS +
"/" + user.username)
.concurrent()
.onSuccess([request, user](auto result) {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no viable conversion from '(lambda at /github/workspace/src/providers/pronouns/alejo/PronounsAlejoApi.cpp:134:24)' to 'NetworkSuccessCallback' (aka 'function<void (NetworkResult)>') [clang-diagnostic-error]

            .onSuccess([request, user](auto result) {
                       ^
Additional context

/usr/include/c++/13/bits/std_function.h:374: candidate constructor not viable: no known conversion from '(lambda at /github/workspace/src/providers/pronouns/alejo/PronounsAlejoApi.cpp:134:24)' to 'nullptr_t' (aka 'std::nullptr_t') for 1st argument

      function(nullptr_t) noexcept
      ^

/usr/include/c++/13/bits/std_function.h:385: candidate constructor not viable: no known conversion from '(lambda at /github/workspace/src/providers/pronouns/alejo/PronounsAlejoApi.cpp:134:24)' to 'const function<void (NetworkResult)> &' for 1st argument

      function(const function& __x)
      ^

/usr/include/c++/13/bits/std_function.h:403: candidate constructor not viable: no known conversion from '(lambda at /github/workspace/src/providers/pronouns/alejo/PronounsAlejoApi.cpp:134:24)' to 'function<void (NetworkResult)> &&' for 1st argument

      function(function&& __x) noexcept
      ^

/usr/include/c++/13/bits/std_function.h:434: candidate template ignored: requirement '_Callable<(lambda at /github/workspace/src/providers/pronouns/alejo/PronounsAlejoApi.cpp:134:24), (lambda at /github/workspace/src/providers/pronouns/alejo/PronounsAlejoApi.cpp:134:24), std::__invoke_result<(lambda at /github/workspace/src/providers/pronouns/alejo/PronounsAlejoApi.cpp:134:24) &, chatterino::NetworkResult>>::value' was not satisfied [with _Functor = (lambda at /github/workspace/src/providers/pronouns/alejo/PronounsAlejoApi.cpp:134:24)]

	function(_Functor&& __f)
 ^

src/common/network/NetworkRequest.hpp:46: passing argument to parameter 'cb' here

    NetworkRequest onSuccess(NetworkSuccessCallback cb) &&;
                                                    ^

@franzitrone
Copy link
Contributor Author

I don't think I'll be able to update the PR this weekend, but I've installed the clang LS extension and I starting working through the suggestions yesterday.

The owner of PronounDB also replied yesterday I'll read it carefully tomorrow or so and share her comments.

Apologies for accidentally closing the PR yesterday, I was scrolling through the comments and somehow clicked "Close" 😒

@pajlada
Copy link
Member

pajlada commented Jun 8, 2024

Alright, I'll wait with reviewing the PR until you've had a chance to look at it further then. Poke me!

@treuks
Copy link
Contributor

treuks commented Jun 12, 2024

My recommendation is to only display the pronouns in the usercard - this minimizes http requests and avoids implementation complexity (of batching requests or caching thousands of pronouns)

There are certain pronoundb plugins for Discord, which show pronouns for a user. They show the pronouns inline with the messages, but only after you click on their profile, like so:

User message before you open the profile:
image

User message after you open the profile:
image

In my opinion this is a fairly decent approach to this sort of situation, we could do it like so:

Before:
image 1

Open user card:
Frame 1(12)

After:
image 4

I feel like this could be a decent middleground between only showing it in the usercard and making requests for like every user. thoughts?

@pajlada
Copy link
Member

pajlada commented Jun 12, 2024

I would be fine with that compromise @treuks

@iProdigy
Copy link
Contributor

compromise is good; i'm not a maintainer but could be easier to review if 2 separate prs

@franzitrone
Copy link
Contributor Author

Awesome! I'll try to merge and remove the draft tag.

@franzitrone franzitrone changed the title feat: Fetch and show pronouns for chatters. Fetch and show pronouns for chatters. Aug 29, 2024
@franzitrone franzitrone marked this pull request as ready for review August 29, 2024 15:04
Copy link
Contributor

@github-actions github-actions bot left a comment

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

@@ -124,6 +129,7 @@ class MockApplication : public mock::BaseApplication
FfzEmotes ffzEmotes;
SeventvEmotes seventvEmotes;
DisabledStreamerMode streamerMode;
Pronouns pronouns;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: field has incomplete type 'chatterino::pronouns::Pronouns' [clang-diagnostic-error]

    Pronouns pronouns;
             ^
Additional context

src/Application.hpp:56: forward declaration of 'chatterino::pronouns::Pronouns'

    class Pronouns;
          ^

@@ -124,6 +129,7 @@
FfzEmotes ffzEmotes;
SeventvEmotes seventvEmotes;
DisabledStreamerMode streamerMode;
Pronouns pronouns;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: unknown type name 'Pronouns'; did you mean 'chatterino::pronouns::Pronouns'? [clang-diagnostic-error]

Suggested change
Pronouns pronouns;
chatterino::pronouns::Pronouns pronouns;
Additional context

src/Application.hpp:56: 'chatterino::pronouns::Pronouns' declared here

    class Pronouns;
          ^

AccountController accounts;
mock::MockTwitchIrcServer twitch;
Emotes emotes;
BttvEmotes bttvEmotes;
FfzEmotes ffzEmotes;
SeventvEmotes seventvEmotes;
Pronouns pronouns;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: field has incomplete type 'chatterino::pronouns::Pronouns' [clang-diagnostic-error]

    Pronouns pronouns;
             ^
Additional context

src/Application.hpp:56: forward declaration of 'chatterino::pronouns::Pronouns'

    class Pronouns;
          ^

AccountController accounts;
mock::MockTwitchIrcServer twitch;
Emotes emotes;
BttvEmotes bttvEmotes;
FfzEmotes ffzEmotes;
SeventvEmotes seventvEmotes;
Pronouns pronouns;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: unknown type name 'Pronouns'; did you mean 'chatterino::pronouns::Pronouns'? [clang-diagnostic-error]

Suggested change
Pronouns pronouns;
chatterino::pronouns::Pronouns pronouns;
Additional context

src/Application.hpp:56: 'chatterino::pronouns::Pronouns' declared here

    class Pronouns;
          ^

@@ -91,6 +91,20 @@ class MockApplication : public mock::BaseApplication
return &this->seventvEmotes;
}

<<<<<<< HEAD:tests/src/TwitchMessageBuilder.cpp
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: version control conflict marker in file [clang-diagnostic-error]

<<<<<<< HEAD:tests/src/TwitchMessageBuilder.cpp
^

@@ -102,6 +116,7 @@
BttvEmotes bttvEmotes;
FfzEmotes ffzEmotes;
SeventvEmotes seventvEmotes;
Pronouns::Pronouns pronouns;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: field has incomplete type 'pronouns::Pronouns' [clang-diagnostic-error]

    Pronouns::Pronouns pronouns;
                       ^
Additional context

src/Application.hpp:56: forward declaration of 'chatterino::pronouns::Pronouns'

    class Pronouns;
          ^

@@ -102,6 +116,7 @@
BttvEmotes bttvEmotes;
FfzEmotes ffzEmotes;
SeventvEmotes seventvEmotes;
Pronouns::Pronouns pronouns;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: use of undeclared identifier 'Pronouns'; did you mean 'pronouns'? [clang-diagnostic-error]

Suggested change
Pronouns::Pronouns pronouns;
pronouns::Pronouns pronouns;
Additional context

src/Application.hpp:55: 'pronouns' declared here

namespace pronouns {
          ^

qCDebug(chatterinoPronouns) << "Fetching available pronouns for alejo.io";
NetworkRequest(AlejoApi::API_URL + AlejoApi::API_PRONOUNS)
.concurrent()
.cache()
Copy link
Collaborator

Choose a reason for hiding this comment

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

How well or not well does this handle caching?
From my cursory glance at the caching system, I can see a scenario where:

  • the data gets loaded and saved to cache
  • a user adds themselves to the database
  • this gets loaded from cache but still has the old data.

Even restarting Chatterino probably wouldn't help because the cached data will still be in cache and it will just be reloaded.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is only for the pronouns (i.e. some-pronoun-id → "they/them") not for the users, thus it's not frequently updated. But I agree that it should be removed, because we don't have any way of invalidating this.

@franzitrone
Copy link
Contributor Author

How can I run the benchmarks, tests, etc. on my machine? I'm getting Unknown CMake command "add_sanitizers".

In any case, I've pushed some changes that should hopefully fix the build errors.

@Nerixyz
Copy link
Contributor

Nerixyz commented Aug 29, 2024

I'm getting Unknown CMake command "add_sanitizers".

Are you sure you properly checked out all submodules (git submodule update --init --recursive)?

@franzitrone
Copy link
Contributor Author

franzitrone commented Aug 29, 2024

I'm getting Unknown CMake command "add_sanitizers".

Are you sure you properly checked out all submodules (git submodule update --init --recursive)?

I didn't, that was definitely it.

Copy link
Contributor

@github-actions github-actions bot left a comment

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

AccountController accounts;
mock::MockTwitchIrcServer twitch;
Emotes emotes;
BttvEmotes bttvEmotes;
FfzEmotes ffzEmotes;
SeventvEmotes seventvEmotes;
pronouns::Pronouns pronouns;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: field has incomplete type 'pronouns::Pronouns' [clang-diagnostic-error]

    pronouns::Pronouns pronouns;
                       ^
Additional context

src/Application.hpp:56: forward declaration of 'chatterino::pronouns::Pronouns'

    class Pronouns;
          ^

@@ -102,6 +108,7 @@ class MockApplication : public mock::BaseApplication
BttvEmotes bttvEmotes;
FfzEmotes ffzEmotes;
SeventvEmotes seventvEmotes;
pronouns::Pronouns pronouns;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: field has incomplete type 'pronouns::Pronouns' [clang-diagnostic-error]

    pronouns::Pronouns pronouns;
                       ^
Additional context

src/Application.hpp:56: forward declaration of 'chatterino::pronouns::Pronouns'

    class Pronouns;
          ^

@pajlada
Copy link
Member

pajlada commented Aug 31, 2024

@DeltaTimo Could you ensure this option is enabled?
image

If it already is, could you uncheck & check it?

@franzitrone
Copy link
Contributor Author

franzitrone commented Sep 1, 2024

@DeltaTimo Could you ensure this option is enabled? image

If it already is, could you uncheck & check it?

Yes, sure, I'll do in a sec!

Edit: done!

@pajlada
Copy link
Member

pajlada commented Sep 1, 2024

Seems like I still can't push things, weird

Here's a patch you can apply which will make it build

diff --git a/benchmarks/src/RecentMessages.cpp b/benchmarks/src/RecentMessages.cpp
index fd3461a7d..994c88858 100644
--- a/benchmarks/src/RecentMessages.cpp
+++ b/benchmarks/src/RecentMessages.cpp
@@ -11,6 +11,7 @@
 #include "providers/chatterino/ChatterinoBadges.hpp"
 #include "providers/ffz/FfzBadges.hpp"
 #include "providers/ffz/FfzEmotes.hpp"
+#include "providers/pronouns/Pronouns.hpp"
 #include "providers/recentmessages/Impl.hpp"
 #include "providers/seventv/SeventvBadges.hpp"
 #include "providers/seventv/SeventvEmotes.hpp"
diff --git a/src/Application.cpp b/src/Application.cpp
index 7f805fa1d..24dd346fd 100644
--- a/src/Application.cpp
+++ b/src/Application.cpp
@@ -187,36 +187,6 @@ Application::Application(Settings &_settings, const Paths &paths,
 
 Application::~Application()
 {
-#ifdef CHATTERINO_HAVE_PLUGINS
-    this->plugins.reset();
-#endif
-    this->twitchPubSub.reset();
-    this->twitchBadges.reset();
-    this->twitchLiveController.reset();
-    this->chatterinoBadges.reset();
-    this->bttvEmotes.reset();
-    this->ffzEmotes.reset();
-    this->seventvEmotes.reset();
-    this->notifications.reset();
-    this->commands.reset();
-    // If a crash happens after crashHandler has been reset, we'll assert
-    // This isn't super different from before, where if the app is already killed, the getApp() portion of it is already dead
-    this->crashHandler.reset();
-    this->seventvAPI.reset();
-    this->highlights.reset();
-    this->seventvBadges.reset();
-    this->ffzBadges.reset();
-    // this->twitch.reset();
-    this->imageUploader.reset();
-    this->hotkeys.reset();
-    this->fonts.reset();
-    this->sound.reset();
-    this->userData.reset();
-    this->toasts.reset();
-    this->accounts.reset();
-    this->emotes.reset();
-    this->themes.reset();
-    this->pronouns.reset();
     // we do this early to ensure getApp isn't used in any dtors
     INSTANCE = nullptr;
 }
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 5ed9e2457..8aec2c5bb 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -348,12 +348,12 @@ set(SOURCE_FILES
         providers/liveupdates/BasicPubSubManager.hpp
         providers/liveupdates/BasicPubSubWebsocket.hpp
 
-        providers/pronouns/Pronouns.hpp
         providers/pronouns/Pronouns.cpp
-        providers/pronouns/UserPronouns.hpp
+        providers/pronouns/Pronouns.hpp
         providers/pronouns/UserPronouns.cpp
-        providers/pronouns/alejo/PronounsAlejoApi.hpp
+        providers/pronouns/UserPronouns.hpp
         providers/pronouns/alejo/PronounsAlejoApi.cpp
+        providers/pronouns/alejo/PronounsAlejoApi.hpp
 
         providers/recentmessages/Api.cpp
         providers/recentmessages/Api.hpp
diff --git a/src/providers/pronouns/alejo/PronounsAlejoApi.cpp b/src/providers/pronouns/alejo/PronounsAlejoApi.cpp
index 0d2cfe834..31e606016 100644
--- a/src/providers/pronouns/alejo/PronounsAlejoApi.cpp
+++ b/src/providers/pronouns/alejo/PronounsAlejoApi.cpp
@@ -114,7 +114,7 @@ void AlejoApi::fetch(const QString &username,
                 return;
             }
             qCWarning(chatterinoPronouns)
-                << "alejo.io returned " << status
+                << "alejo.io returned " << status.value_or(-1)
                 << " when fetching pronouns for " << username;
             onDone({});
         })
diff --git a/tests/src/InputCompletion.cpp b/tests/src/InputCompletion.cpp
index cbf4fcc65..460fb1526 100644
--- a/tests/src/InputCompletion.cpp
+++ b/tests/src/InputCompletion.cpp
@@ -69,18 +69,12 @@ public:
         return &this->seventvEmotes;
     }
 
-    pronouns::Pronouns *getPronouns() override
-    {
-        return &this->pronouns;
-    }
-
     AccountController accounts;
     mock::MockTwitchIrcServer twitch;
     Emotes emotes;
     BttvEmotes bttvEmotes;
     FfzEmotes ffzEmotes;
     SeventvEmotes seventvEmotes;
-    pronouns::Pronouns pronouns;
 };
 
 }  // namespace
diff --git a/tests/src/MessageBuilder.cpp b/tests/src/MessageBuilder.cpp
index c2a68d16a..39f01f196 100644
--- a/tests/src/MessageBuilder.cpp
+++ b/tests/src/MessageBuilder.cpp
@@ -91,12 +91,6 @@ public:
         return &this->seventvEmotes;
     }
 
-    pronouns::Pronouns *getPronouns() override
-    {
-        return &this->pronouns;
-    }
-
-    Settings settings;
     AccountController accounts;
     Emotes emotes;
     mock::UserDataController userData;
@@ -108,7 +102,6 @@ public:
     BttvEmotes bttvEmotes;
     FfzEmotes ffzEmotes;
     SeventvEmotes seventvEmotes;
-    pronouns::Pronouns pronouns;
 };
 
 }  // namespace

@Felanbird
Copy link
Collaborator

Seems like I still can't push things, weird

probably because this branch is on a chatterino7 fork, not chatterino2

@franzitrone
Copy link
Contributor Author

Seems like I still can't push things, weird

probably because this branch is on a chatterino7 fork, not chatterino2

Oh yeah that's possible. I just applied the patch and pushed, thanks!

Copy link
Contributor

@github-actions github-actions bot left a comment

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

Copy link
Contributor

@github-actions github-actions bot left a comment

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

}

void AlejoApi::fetch(const QString &username,
std::function<void(std::optional<UserPronouns>)> onDone)
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: the parameter 'onDone' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]

src/providers/pronouns/alejo/PronounsAlejoApi.hpp:21:

-                std::function<void(std::optional<UserPronouns>)> onDone);
+                const std::function<void(std::optional<UserPronouns>)>& onDone);
Suggested change
std::function<void(std::optional<UserPronouns>)> onDone)
const std::function<void(std::optional<UserPronouns>)>& onDone)

Copy link
Member

@pajlada pajlada left a comment

Choose a reason for hiding this comment

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

Some nitpicking, will take another round of checks once these things have been done.

Functionally, the PR works almost as I'd expect. Thanks for taking the time to look into this, and I look forward to merge this in

qCDebug(chatterinoPronouns)
<< "Fetching pronouns from alejo.io for " << username;

alejoApi.fetch(username, [this, callbackSuccess, callbackFail,
Copy link
Member

Choose a reason for hiding this comment

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

Just confirming this is correct, and that you can ignore this. I will fix this in a follow-up PR

}

qCDebug(chatterinoPronouns) << "Fetching available pronouns for alejo.io";
NetworkRequest(AlejoApi::API_URL + AlejoApi::API_PRONOUNS)
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer if this network request is only made if the pronoun setting is enabled.
For reference, check out the BttvEmotes ctor.
If you want the request to be made in the constructor, which I think is fine for a network request this small, leave the autoInvoke param out (or set to true, its default value)

Copy link
Member

@pajlada pajlada left a comment

Choose a reason for hiding this comment

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

Since this is functionally mostly good, I will merge this in and follow-up with another PR cleaning some things up

@pajlada pajlada changed the title Fetch and show pronouns for chatters. feat: add setting for showing pronouns in user info popup Sep 8, 2024
@pajlada pajlada merged commit 9375bce into Chatterino:master Sep 8, 2024
18 checks passed
@pajlada
Copy link
Member

pajlada commented Sep 8, 2024

Thank you! As a first-time contributor, you are now eligible to be listed in the About page in Chatterino.

If you want this, you can open a new PR where you modify the resources/contributors.txt file and add yourself to the list. Read the comments at the top for instructions.

@iProdigy iProdigy mentioned this pull request Oct 15, 2024
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.

9 participants