fix(plugins): Implement __eq for Channel (#6456)
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
- Bugfix: Fixed zero-width global BTTV emotes not showing in the `:~` completions. (#6440)
|
- Bugfix: Fixed zero-width global BTTV emotes not showing in the `:~` completions. (#6440)
|
||||||
- Bugfix: Fixed an issue where the update button would be unclickable on macOS and Linux. (#6447, #6453)
|
- Bugfix: Fixed an issue where the update button would be unclickable on macOS and Linux. (#6447, #6453)
|
||||||
- Bugfix: Fixed flickering tooltips on Wayland when the mouse cursor is over them. (#6451)
|
- Bugfix: Fixed flickering tooltips on Wayland when the mouse cursor is over them. (#6451)
|
||||||
|
- Bugfix: Fixed `c2.Channel` comparing `false` to the same channel. (#6456)
|
||||||
- Bugfix: Fixed an issue where the moderation icon was missing from the Moderation tab. (#6457)
|
- Bugfix: Fixed an issue where the moderation icon was missing from the Moderation tab. (#6457)
|
||||||
- Dev: Added documentation for WebSockets to `wip-plugins.md`. (#6432)
|
- Dev: Added documentation for WebSockets to `wip-plugins.md`. (#6432)
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
# include "controllers/plugins/SolTypes.hpp"
|
# include "controllers/plugins/SolTypes.hpp"
|
||||||
# include "providers/twitch/TwitchChannel.hpp"
|
# include "providers/twitch/TwitchChannel.hpp"
|
||||||
# include "providers/twitch/TwitchIrcServer.hpp"
|
# include "providers/twitch/TwitchIrcServer.hpp"
|
||||||
|
# include "util/WeakPtrHelpers.hpp"
|
||||||
|
|
||||||
# include <sol/sol.hpp>
|
# include <sol/sol.hpp>
|
||||||
|
|
||||||
@@ -159,6 +160,11 @@ QString ChannelRef::to_string()
|
|||||||
return QStringView(u"<c2.Channel %1>").arg(chan->getName());
|
return QStringView(u"<c2.Channel %1>").arg(chan->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ChannelRef::operator==(const ChannelRef &other) const noexcept
|
||||||
|
{
|
||||||
|
return weakOwnerEquals(this->weak, other.weak);
|
||||||
|
}
|
||||||
|
|
||||||
std::optional<ChannelRef> ChannelRef::get_by_name(const QString &name)
|
std::optional<ChannelRef> ChannelRef::get_by_name(const QString &name)
|
||||||
{
|
{
|
||||||
auto chan = getApp()->getTwitch()->getChannelOrEmpty(name);
|
auto chan = getApp()->getTwitch()->getChannelOrEmpty(name);
|
||||||
|
|||||||
@@ -155,6 +155,8 @@ public:
|
|||||||
*/
|
*/
|
||||||
QString to_string();
|
QString to_string();
|
||||||
|
|
||||||
|
bool operator==(const ChannelRef &other) const noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static functions
|
* Static functions
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace chatterino {
|
||||||
|
|
||||||
|
/// Check if the owner of two weak pointers is equal.
|
||||||
|
///
|
||||||
|
/// Like `std::weak_ptr::owner_before`, this compares the control blocks,
|
||||||
|
/// not the objects themselves.
|
||||||
|
/// Equivalent to the C++ 26 `std::weak_ptr::owner_equal`.
|
||||||
|
template <typename T>
|
||||||
|
bool weakOwnerEquals(const std::weak_ptr<T> &a,
|
||||||
|
const std::weak_ptr<T> &b) noexcept
|
||||||
|
{
|
||||||
|
return !a.owner_before(b) && !b.owner_before(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace chatterino
|
||||||
@@ -309,6 +309,15 @@ TEST_F(PluginTest, testChannel)
|
|||||||
lua->script(R"lua( return chn:is_twitch_channel() )lua").get<bool>(0),
|
lua->script(R"lua( return chn:is_twitch_channel() )lua").get<bool>(0),
|
||||||
true);
|
true);
|
||||||
|
|
||||||
|
ASSERT_TRUE(lua->script(R"lua(
|
||||||
|
assert(c2.Channel.by_name("mm2pl") == c2.Channel.by_name("mm2pl"))
|
||||||
|
assert(not c2.Channel.by_name("mm2pl") ~= c2.Channel.by_name("mm2pl"))
|
||||||
|
assert(c2.Channel.by_name("mm2pl") ~= c2.Channel.by_name("twitchdev"))
|
||||||
|
assert(c2.Channel.by_name("twitchdev") == c2.Channel.by_name("twitchdev"))
|
||||||
|
assert(c2.Channel.by_name("twitchdev") == c2.Channel.by_name("other")) -- empty channel
|
||||||
|
)lua")
|
||||||
|
.valid());
|
||||||
|
|
||||||
// this is not a TwitchChannel
|
// this is not a TwitchChannel
|
||||||
const auto *shouldThrow1 = R"lua(
|
const auto *shouldThrow1 = R"lua(
|
||||||
return chn:is_broadcaster()
|
return chn:is_broadcaster()
|
||||||
|
|||||||
Reference in New Issue
Block a user