2022-07-31 12:45:25 +02:00
|
|
|
#pragma once
|
|
|
|
|
2023-06-17 17:41:52 +02:00
|
|
|
#include <boost/signals2.hpp>
|
2022-07-31 12:45:25 +02:00
|
|
|
#include <QString>
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
struct Message;
|
|
|
|
|
|
|
|
class MessageThread
|
|
|
|
{
|
|
|
|
public:
|
2023-06-17 17:41:52 +02:00
|
|
|
enum class Subscription : uint8_t {
|
|
|
|
None,
|
|
|
|
Subscribed,
|
|
|
|
Unsubscribed,
|
|
|
|
};
|
|
|
|
|
2022-07-31 12:45:25 +02:00
|
|
|
MessageThread(std::shared_ptr<const Message> rootMessage);
|
|
|
|
~MessageThread();
|
|
|
|
|
|
|
|
void addToThread(const std::shared_ptr<const Message> &message);
|
|
|
|
void addToThread(const std::weak_ptr<const Message> &message);
|
|
|
|
|
|
|
|
/// Returns the number of live reply references
|
|
|
|
size_t liveCount() const;
|
|
|
|
|
|
|
|
/// Returns the number of live reply references
|
|
|
|
size_t liveCount(const std::shared_ptr<const Message> &exclude) const;
|
|
|
|
|
2023-06-17 17:41:52 +02:00
|
|
|
bool subscribed() const
|
|
|
|
{
|
|
|
|
return this->subscription_ == Subscription::Subscribed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns true if and only if the user manually unsubscribed from the thread
|
|
|
|
/// @see #markUnsubscribed()
|
|
|
|
bool unsubscribed() const
|
|
|
|
{
|
|
|
|
return this->subscription_ == Subscription::Unsubscribed;
|
|
|
|
}
|
2022-10-08 16:25:32 +02:00
|
|
|
|
2023-06-17 17:41:52 +02:00
|
|
|
/// Subscribe to this thread.
|
|
|
|
void markSubscribed();
|
|
|
|
/// Unsubscribe from this thread.
|
|
|
|
void markUnsubscribed();
|
2022-10-08 16:25:32 +02:00
|
|
|
|
2022-07-31 12:45:25 +02:00
|
|
|
const QString &rootId() const
|
|
|
|
{
|
|
|
|
return rootMessageId_;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::shared_ptr<const Message> &root() const
|
|
|
|
{
|
|
|
|
return rootMessage_;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<std::weak_ptr<const Message>> &replies() const
|
|
|
|
{
|
|
|
|
return replies_;
|
|
|
|
}
|
|
|
|
|
2023-06-17 17:41:52 +02:00
|
|
|
boost::signals2::signal<void()> subscriptionUpdated;
|
|
|
|
|
2022-07-31 12:45:25 +02:00
|
|
|
private:
|
|
|
|
const QString rootMessageId_;
|
|
|
|
const std::shared_ptr<const Message> rootMessage_;
|
|
|
|
std::vector<std::weak_ptr<const Message>> replies_;
|
2023-06-17 17:41:52 +02:00
|
|
|
|
|
|
|
Subscription subscription_ = Subscription::None;
|
2022-07-31 12:45:25 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace chatterino
|