chore(eventsub): add operator== and indicator for shared chat (#5974)
This commit is contained in:
@@ -389,11 +389,11 @@ struct Event {
|
||||
String broadcasterUserName;
|
||||
|
||||
/// For Shared Chat events, the user ID (e.g. 117166826) of the user who's channel the event took place in
|
||||
std::optional<std::string> sourceBroadcasterUserID;
|
||||
std::optional<String> sourceBroadcasterUserID;
|
||||
/// For Shared Chat events, the user Login (e.g. testaccount_420) of the user who's channel the event took place in
|
||||
std::optional<std::string> sourceBroadcasterUserLogin;
|
||||
std::optional<String> sourceBroadcasterUserLogin;
|
||||
/// For Shared Chat events, the user Name (e.g. 테스트계정420) of the user who's channel the event took place in
|
||||
std::optional<std::string> sourceBroadcasterUserName;
|
||||
std::optional<String> sourceBroadcasterUserName;
|
||||
|
||||
/// User ID (e.g. 117166826) of the user who took the action
|
||||
String moderatorUserID;
|
||||
@@ -439,6 +439,8 @@ struct Event {
|
||||
SharedChatDelete, //
|
||||
std::string>
|
||||
action;
|
||||
|
||||
bool isFromSharedChat() const noexcept;
|
||||
};
|
||||
|
||||
struct Payload {
|
||||
|
||||
@@ -152,6 +152,24 @@ struct String {
|
||||
return (this->flags & (ALLOC_BIT | QT_BIT)) == 0;
|
||||
}
|
||||
|
||||
// note: because we're using C++ 20, the reversed operator
|
||||
// (e.g. QAnyStringView == String) is automatically "synthesized".
|
||||
bool operator==(const QAnyStringView &other) const noexcept
|
||||
{
|
||||
return this->view() == other;
|
||||
}
|
||||
|
||||
bool operator==(const String &other) const noexcept
|
||||
{
|
||||
return this->view() == other.view();
|
||||
}
|
||||
|
||||
template <typename = void> // weak overload
|
||||
bool operator==(const std::string_view &other) const noexcept
|
||||
{
|
||||
return this->view() == other;
|
||||
}
|
||||
|
||||
private:
|
||||
static constexpr size_t QT_BIT = 1ULL << (sizeof(size_t) * 8 - 1);
|
||||
static constexpr size_t ALLOC_BIT = 1ULL << (sizeof(size_t) * 8 - 2);
|
||||
|
||||
@@ -28,6 +28,7 @@ set(SOURCE_FILES
|
||||
|
||||
# Subscription types (only additional functions)
|
||||
payloads/channel-ban-v1.cpp
|
||||
payloads/channel-moderate-v2.cpp
|
||||
# Add your new subscription type source file above this line
|
||||
|
||||
${eventsub_generated_sources}
|
||||
|
||||
@@ -1215,14 +1215,16 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
|
||||
return broadcasterUserName.error();
|
||||
}
|
||||
|
||||
std::optional<std::string> sourceBroadcasterUserID = std::nullopt;
|
||||
std::optional<chatterino::eventsub::lib::String> sourceBroadcasterUserID =
|
||||
std::nullopt;
|
||||
const auto *jvsourceBroadcasterUserID =
|
||||
root.if_contains("source_broadcaster_user_id");
|
||||
if (jvsourceBroadcasterUserID != nullptr &&
|
||||
!jvsourceBroadcasterUserID->is_null())
|
||||
{
|
||||
auto tsourceBroadcasterUserID =
|
||||
boost::json::try_value_to<std::string>(*jvsourceBroadcasterUserID);
|
||||
boost::json::try_value_to<chatterino::eventsub::lib::String>(
|
||||
*jvsourceBroadcasterUserID);
|
||||
|
||||
if (tsourceBroadcasterUserID.has_error())
|
||||
{
|
||||
@@ -1231,14 +1233,15 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
|
||||
sourceBroadcasterUserID = std::move(tsourceBroadcasterUserID.value());
|
||||
}
|
||||
|
||||
std::optional<std::string> sourceBroadcasterUserLogin = std::nullopt;
|
||||
std::optional<chatterino::eventsub::lib::String>
|
||||
sourceBroadcasterUserLogin = std::nullopt;
|
||||
const auto *jvsourceBroadcasterUserLogin =
|
||||
root.if_contains("source_broadcaster_user_login");
|
||||
if (jvsourceBroadcasterUserLogin != nullptr &&
|
||||
!jvsourceBroadcasterUserLogin->is_null())
|
||||
{
|
||||
auto tsourceBroadcasterUserLogin =
|
||||
boost::json::try_value_to<std::string>(
|
||||
boost::json::try_value_to<chatterino::eventsub::lib::String>(
|
||||
*jvsourceBroadcasterUserLogin);
|
||||
|
||||
if (tsourceBroadcasterUserLogin.has_error())
|
||||
@@ -1249,14 +1252,15 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
|
||||
std::move(tsourceBroadcasterUserLogin.value());
|
||||
}
|
||||
|
||||
std::optional<std::string> sourceBroadcasterUserName = std::nullopt;
|
||||
std::optional<chatterino::eventsub::lib::String> sourceBroadcasterUserName =
|
||||
std::nullopt;
|
||||
const auto *jvsourceBroadcasterUserName =
|
||||
root.if_contains("source_broadcaster_user_name");
|
||||
if (jvsourceBroadcasterUserName != nullptr &&
|
||||
!jvsourceBroadcasterUserName->is_null())
|
||||
{
|
||||
auto tsourceBroadcasterUserName =
|
||||
boost::json::try_value_to<std::string>(
|
||||
boost::json::try_value_to<chatterino::eventsub::lib::String>(
|
||||
*jvsourceBroadcasterUserName);
|
||||
|
||||
if (tsourceBroadcasterUserName.has_error())
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
#include "twitch-eventsub-ws/payloads/channel-moderate-v2.hpp"
|
||||
|
||||
namespace chatterino::eventsub::lib::payload::channel_moderate::v2 {
|
||||
|
||||
bool Event::isFromSharedChat() const noexcept
|
||||
{
|
||||
return this->sourceBroadcasterUserID && this->sourceBroadcasterUserLogin &&
|
||||
this->sourceBroadcasterUserName &&
|
||||
*this->sourceBroadcasterUserID != this->broadcasterUserID;
|
||||
}
|
||||
} // namespace chatterino::eventsub::lib::payload::channel_moderate::v2
|
||||
@@ -515,3 +515,55 @@ TEST(String, QtLifetime)
|
||||
}
|
||||
ASSERT_TRUE(qt.isDetached());
|
||||
}
|
||||
|
||||
TEST(String, Equals)
|
||||
{
|
||||
String empty;
|
||||
|
||||
// This is using ASSERT_TRUE instead of ASSERT_EQ to be able to view/go to
|
||||
// the chosen operator== in editors (with clangd for example).
|
||||
ASSERT_TRUE(empty == empty);
|
||||
ASSERT_TRUE(empty == "");
|
||||
ASSERT_TRUE(empty == u"");
|
||||
ASSERT_TRUE(empty == std::string_view{});
|
||||
ASSERT_TRUE(empty == QAnyStringView());
|
||||
ASSERT_TRUE(empty == String());
|
||||
ASSERT_TRUE("" == empty);
|
||||
ASSERT_TRUE(u"" == empty);
|
||||
|
||||
String longestSso(LONGEST_SSO);
|
||||
String longestSsoQt(LONGEST_SSO);
|
||||
ASSERT_EQ(longestSsoQt.qt(), LONGEST_SSO);
|
||||
|
||||
ASSERT_TRUE(longestSso == longestSso);
|
||||
ASSERT_TRUE(longestSsoQt == longestSsoQt);
|
||||
ASSERT_TRUE(longestSso == longestSsoQt);
|
||||
ASSERT_TRUE(longestSso == LONGEST_SSO);
|
||||
ASSERT_TRUE(longestSsoQt == LONGEST_SSO);
|
||||
ASSERT_TRUE(longestSso == String(LONGEST_SSO));
|
||||
ASSERT_TRUE(longestSsoQt == String(LONGEST_SSO));
|
||||
|
||||
String tooLong(TOO_LONG);
|
||||
String tooLongQt(TOO_LONG);
|
||||
ASSERT_EQ(tooLongQt.qt(), TOO_LONG);
|
||||
|
||||
ASSERT_TRUE(tooLong == tooLong);
|
||||
ASSERT_TRUE(tooLongQt == tooLongQt);
|
||||
ASSERT_TRUE(tooLong == tooLongQt);
|
||||
ASSERT_TRUE(tooLong == TOO_LONG);
|
||||
ASSERT_TRUE(tooLongQt == TOO_LONG);
|
||||
ASSERT_TRUE(tooLong == String(TOO_LONG));
|
||||
ASSERT_TRUE(tooLongQt == String(TOO_LONG));
|
||||
|
||||
String reallyLong(REALLY_LONG);
|
||||
String reallyLongQt(REALLY_LONG);
|
||||
ASSERT_EQ(reallyLongQt.qt(), REALLY_LONG);
|
||||
|
||||
ASSERT_TRUE(reallyLong == reallyLong);
|
||||
ASSERT_TRUE(reallyLongQt == reallyLongQt);
|
||||
ASSERT_TRUE(reallyLong == reallyLongQt);
|
||||
ASSERT_TRUE(reallyLong == REALLY_LONG);
|
||||
ASSERT_TRUE(reallyLongQt == REALLY_LONG);
|
||||
ASSERT_TRUE(reallyLong == String(REALLY_LONG));
|
||||
ASSERT_TRUE(reallyLongQt == String(REALLY_LONG));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user