2023-06-17 17:41:52 +02:00
|
|
|
#include "messages/MessageThread.hpp"
|
2022-07-31 12:45:25 +02:00
|
|
|
|
|
|
|
#include "messages/Message.hpp"
|
|
|
|
#include "util/DebugCount.hpp"
|
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
|
|
|
|
MessageThread::MessageThread(std::shared_ptr<const Message> rootMessage)
|
|
|
|
: rootMessageId_(rootMessage->id)
|
|
|
|
, rootMessage_(std::move(rootMessage))
|
|
|
|
{
|
|
|
|
DebugCount::increase("message threads");
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageThread::~MessageThread()
|
|
|
|
{
|
|
|
|
DebugCount::decrease("message threads");
|
|
|
|
}
|
|
|
|
|
|
|
|
void MessageThread::addToThread(const std::shared_ptr<const Message> &message)
|
|
|
|
{
|
|
|
|
this->replies_.emplace_back(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MessageThread::addToThread(const std::weak_ptr<const Message> &message)
|
|
|
|
{
|
|
|
|
this->replies_.push_back(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t MessageThread::liveCount() const
|
|
|
|
{
|
|
|
|
size_t count = 0;
|
|
|
|
for (auto reply : this->replies_)
|
|
|
|
{
|
|
|
|
if (!reply.expired())
|
|
|
|
{
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t MessageThread::liveCount(
|
|
|
|
const std::shared_ptr<const Message> &exclude) const
|
|
|
|
{
|
|
|
|
size_t count = 0;
|
|
|
|
for (auto reply : this->replies_)
|
|
|
|
{
|
|
|
|
if (!reply.expired() && reply.lock() != exclude)
|
|
|
|
{
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2023-06-17 17:41:52 +02:00
|
|
|
void MessageThread::markSubscribed()
|
2022-10-08 16:25:32 +02:00
|
|
|
{
|
2023-06-17 17:41:52 +02:00
|
|
|
if (this->subscription_ == Subscription::Subscribed)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->subscription_ = Subscription::Subscribed;
|
|
|
|
this->subscriptionUpdated();
|
2022-10-08 16:25:32 +02:00
|
|
|
}
|
|
|
|
|
2023-06-17 17:41:52 +02:00
|
|
|
void MessageThread::markUnsubscribed()
|
2022-10-08 16:25:32 +02:00
|
|
|
{
|
2023-06-17 17:41:52 +02:00
|
|
|
if (this->subscription_ == Subscription::Unsubscribed)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->subscription_ = Subscription::Unsubscribed;
|
|
|
|
this->subscriptionUpdated();
|
2022-10-08 16:25:32 +02:00
|
|
|
}
|
|
|
|
|
2022-07-31 12:45:25 +02:00
|
|
|
} // namespace chatterino
|