mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
20c974fdab
Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
61 lines
1.2 KiB
C++
61 lines
1.2 KiB
C++
#include "MessageThread.hpp"
|
|
|
|
#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;
|
|
}
|
|
|
|
} // namespace chatterino
|