made fillLatestMessages into a free standing function

This commit is contained in:
TranRed 2019-08-25 15:09:30 +02:00
parent 288ea5036b
commit 23c2fa8ee5
2 changed files with 28 additions and 24 deletions

View file

@ -40,6 +40,32 @@ int calculateTimeoutDuration(TimeoutButton timeout)
return timeout.second * durations[timeout.first];
}
chatterino::ChannelPtr filterMessages(const QString &userName,
chatterino::ChannelPtr channel)
{
chatterino::LimitedQueueSnapshot<chatterino::MessagePtr> snapshot =
channel->getMessageSnapshot();
chatterino::ChannelPtr channelPtr(new chatterino::Channel(
channel->getName(), chatterino::Channel::Type::None));
for (size_t i = 0; i < snapshot.size(); i++)
{
chatterino::MessagePtr message = snapshot[i];
bool isSelectedUser =
message->loginName.compare(userName, Qt::CaseInsensitive) == 0;
if (isSelectedUser &&
!message->flags.has(chatterino::MessageFlag::Whisper))
{
channelPtr->addMessage(message);
}
}
return channelPtr;
}
} // namespace
namespace chatterino {
@ -363,7 +389,8 @@ void UserInfoPopup::setData(const QString &name, const ChannelPtr &channel)
this->userStateChanged_.invoke();
this->fillLatestMessages();
this->latestMessages_->setChannel(
filterMessages(this->userName_, this->channel_));
}
void UserInfoPopup::updateUserData()
@ -554,26 +581,4 @@ void UserInfoPopup::TimeoutWidget::paintEvent(QPaintEvent *)
// / 2);
}
void UserInfoPopup::fillLatestMessages()
{
LimitedQueueSnapshot<MessagePtr> snapshot =
this->channel_->getMessageSnapshot();
ChannelPtr channelPtr(
new Channel(this->channel_->getName(), Channel::Type::None));
for (size_t i = 0; i < snapshot.size(); i++)
{
MessagePtr message = snapshot[i];
bool isSelectedUser = message->loginName.compare(
this->userName_, Qt::CaseInsensitive) == 0;
if (isSelectedUser && !message->flags.has(MessageFlag::Whisper))
{
channelPtr->addMessage(message);
}
}
this->latestMessages_->setChannel(channelPtr);
}
} // namespace chatterino

View file

@ -28,7 +28,6 @@ protected:
private:
void installEvents();
void updateUserData();
void fillLatestMessages();
void loadAvatar(const QUrl &url);
bool isMod_;