fix(plugins): Implement __eq for Channel (#6456)
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
# include "controllers/plugins/SolTypes.hpp"
|
||||
# include "providers/twitch/TwitchChannel.hpp"
|
||||
# include "providers/twitch/TwitchIrcServer.hpp"
|
||||
# include "util/WeakPtrHelpers.hpp"
|
||||
|
||||
# include <sol/sol.hpp>
|
||||
|
||||
@@ -159,6 +160,11 @@ QString ChannelRef::to_string()
|
||||
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)
|
||||
{
|
||||
auto chan = getApp()->getTwitch()->getChannelOrEmpty(name);
|
||||
|
||||
@@ -155,6 +155,8 @@ public:
|
||||
*/
|
||||
QString to_string();
|
||||
|
||||
bool operator==(const ChannelRef &other) const noexcept;
|
||||
|
||||
/**
|
||||
* 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
|
||||
Reference in New Issue
Block a user