mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
Allow searching in LogsPopup
This commit is contained in:
parent
9ee286f60f
commit
a268abfd4c
|
@ -222,6 +222,7 @@ SOURCES += \
|
|||
|
||||
HEADERS += \
|
||||
src/Application.hpp \
|
||||
src/ForwardDecl.hpp \
|
||||
src/autogenerated/ResourcesAutogen.hpp \
|
||||
src/BrowserExtension.hpp \
|
||||
src/common/Aliases.hpp \
|
||||
|
|
10
src/ForwardDecl.hpp
Normal file
10
src/ForwardDecl.hpp
Normal file
|
@ -0,0 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
namespace chatterino {
|
||||
class Channel;
|
||||
class ChannelView;
|
||||
using ChannelPtr = std::shared_ptr<Channel>;
|
||||
|
||||
struct Message;
|
||||
using MessagePtr = std::shared_ptr<const Message>;
|
||||
} // namespace chatterino
|
|
@ -1,3 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
# include <fmt/format.h>
|
||||
# include <irccommand.h>
|
||||
|
|
|
@ -22,7 +22,7 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
std::size_t size()
|
||||
std::size_t size() const
|
||||
{
|
||||
return this->length_;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "common/Channel.hpp"
|
||||
#include "common/NetworkRequest.hpp"
|
||||
#include "debug/Log.hpp"
|
||||
#include "messages/Message.hpp"
|
||||
#include "providers/twitch/PartialTwitchUser.hpp"
|
||||
#include "providers/twitch/TwitchChannel.hpp"
|
||||
#include "providers/twitch/TwitchMessageBuilder.hpp"
|
||||
|
@ -20,34 +21,30 @@ namespace chatterino {
|
|||
LogsPopup::LogsPopup()
|
||||
: channel_(Channel::getEmpty())
|
||||
{
|
||||
this->initLayout();
|
||||
this->resize(400, 600);
|
||||
}
|
||||
|
||||
void LogsPopup::initLayout()
|
||||
{
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
layout->setMargin(0);
|
||||
|
||||
this->channelView_ = new ChannelView(this);
|
||||
layout->addWidget(this->channelView_);
|
||||
|
||||
this->setLayout(layout);
|
||||
}
|
||||
|
||||
void LogsPopup::setChannelName(QString channelName)
|
||||
{
|
||||
this->channelName_ = channelName;
|
||||
}
|
||||
|
||||
void LogsPopup::setChannel(std::shared_ptr<Channel> channel)
|
||||
void LogsPopup::setChannel(const ChannelPtr &channel)
|
||||
{
|
||||
this->channel_ = channel;
|
||||
this->updateWindowTitle();
|
||||
}
|
||||
|
||||
void LogsPopup::setTargetUserName(QString userName)
|
||||
void LogsPopup::setChannelName(const QString &channelName)
|
||||
{
|
||||
this->channelName_ = channelName;
|
||||
this->updateWindowTitle();
|
||||
}
|
||||
|
||||
void LogsPopup::setTargetUserName(const QString &userName)
|
||||
{
|
||||
this->userName_ = userName;
|
||||
this->updateWindowTitle();
|
||||
}
|
||||
|
||||
void LogsPopup::updateWindowTitle()
|
||||
{
|
||||
this->setWindowTitle(this->userName_ + "'s logs in #" + this->channelName_);
|
||||
}
|
||||
|
||||
void LogsPopup::getLogs()
|
||||
|
@ -60,8 +57,6 @@ void LogsPopup::getLogs()
|
|||
this->channelName_ = twitchChannel->getName();
|
||||
this->getLogviewerLogs(twitchChannel->roomId());
|
||||
|
||||
this->setWindowTitle(this->userName_ + "'s logs in #" +
|
||||
this->channelName_);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -83,7 +78,7 @@ void LogsPopup::setMessages(std::vector<MessagePtr> &messages)
|
|||
ChannelPtr logsChannel(new Channel("logs", Channel::Type::Misc));
|
||||
|
||||
logsChannel->addMessagesAtStart(messages);
|
||||
this->channelView_->setChannel(logsChannel);
|
||||
SearchPopup::setChannel(logsChannel);
|
||||
}
|
||||
|
||||
void LogsPopup::getLogviewerLogs(const QString &roomID)
|
||||
|
@ -121,6 +116,8 @@ void LogsPopup::getLogviewerLogs(const QString &roomID)
|
|||
static_cast<Communi::IrcPrivateMessage *>(ircMessage);
|
||||
TwitchMessageBuilder builder(this->channel_.get(), privMsg,
|
||||
args);
|
||||
builder.message().searchText = message;
|
||||
|
||||
messages.push_back(builder.build());
|
||||
}
|
||||
|
||||
|
@ -165,6 +162,7 @@ void LogsPopup::getOverrustleLogs()
|
|||
for (auto i : dataMessages)
|
||||
{
|
||||
QJsonObject singleMessage = i.toObject();
|
||||
auto text = singleMessage.value("text").toString();
|
||||
QTime timeStamp =
|
||||
QDateTime::fromSecsSinceEpoch(
|
||||
singleMessage.value("timestamp").toInt())
|
||||
|
@ -175,9 +173,9 @@ void LogsPopup::getOverrustleLogs()
|
|||
builder.emplace<TextElement>(this->userName_,
|
||||
MessageElementFlag::Username,
|
||||
MessageColor::System);
|
||||
builder.emplace<TextElement>(
|
||||
singleMessage.value("text").toString(),
|
||||
MessageElementFlag::Text, MessageColor::Text);
|
||||
builder.emplace<TextElement>(text, MessageElementFlag::Text,
|
||||
MessageColor::Text);
|
||||
builder.message().searchText = text;
|
||||
messages.push_back(builder.release());
|
||||
}
|
||||
}
|
||||
|
@ -191,4 +189,5 @@ void LogsPopup::getOverrustleLogs()
|
|||
})
|
||||
.execute();
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -1,37 +1,29 @@
|
|||
#pragma once
|
||||
|
||||
#include "widgets/BaseWindow.hpp"
|
||||
#include "widgets/helper/SearchPopup.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class Channel;
|
||||
class ChannelView;
|
||||
|
||||
class Channel;
|
||||
using ChannelPtr = std::shared_ptr<Channel>;
|
||||
|
||||
struct Message;
|
||||
using MessagePtr = std::shared_ptr<const Message>;
|
||||
|
||||
class LogsPopup : public BaseWindow
|
||||
class LogsPopup : public SearchPopup
|
||||
{
|
||||
public:
|
||||
LogsPopup();
|
||||
|
||||
void setChannelName(QString channelName);
|
||||
void setChannel(std::shared_ptr<Channel> channel);
|
||||
void setTargetUserName(QString userName);
|
||||
void setChannel(const ChannelPtr &channel) override;
|
||||
void setChannelName(const QString &channelName);
|
||||
void setTargetUserName(const QString &userName);
|
||||
|
||||
void getLogs();
|
||||
|
||||
protected:
|
||||
void updateWindowTitle() override;
|
||||
|
||||
private:
|
||||
ChannelView *channelView_ = nullptr;
|
||||
ChannelPtr channel_;
|
||||
|
||||
QString userName_;
|
||||
QString channelName_;
|
||||
|
||||
void initLayout();
|
||||
void setMessages(std::vector<MessagePtr> &messages);
|
||||
void getOverrustleLogs();
|
||||
void getLogviewerLogs(const QString &roomID);
|
||||
|
|
|
@ -10,6 +10,26 @@
|
|||
#include "widgets/helper/ChannelView.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
namespace {
|
||||
ChannelPtr filter(const QString &text, const QString &channelName,
|
||||
const LimitedQueueSnapshot<MessagePtr> &snapshot)
|
||||
{
|
||||
ChannelPtr channel(new Channel(channelName, Channel::Type::None));
|
||||
|
||||
for (size_t i = 0; i < snapshot.size(); i++)
|
||||
{
|
||||
MessagePtr message = snapshot[i];
|
||||
|
||||
if (text.isEmpty() ||
|
||||
message->searchText.indexOf(text, 0, Qt::CaseInsensitive) != -1)
|
||||
{
|
||||
channel->addMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
return channel;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
SearchPopup::SearchPopup()
|
||||
{
|
||||
|
@ -17,13 +37,24 @@ SearchPopup::SearchPopup()
|
|||
this->resize(400, 600);
|
||||
}
|
||||
|
||||
void SearchPopup::setChannel(ChannelPtr channel)
|
||||
void SearchPopup::setChannel(const ChannelPtr &channel)
|
||||
{
|
||||
this->channelName_ = channel->getName();
|
||||
this->snapshot_ = channel->getMessageSnapshot();
|
||||
this->performSearch();
|
||||
this->search();
|
||||
|
||||
this->setWindowTitle("Searching in " + channel->getName() + "s history");
|
||||
this->updateWindowTitle();
|
||||
}
|
||||
|
||||
void SearchPopup::updateWindowTitle()
|
||||
{
|
||||
this->setWindowTitle("Searching in " + this->channelName_ + "s history");
|
||||
}
|
||||
|
||||
void SearchPopup::search()
|
||||
{
|
||||
this->channelView_->setChannel(filter(this->searchInput_->text(),
|
||||
this->channelName_, this->snapshot_));
|
||||
}
|
||||
|
||||
void SearchPopup::keyPressEvent(QKeyEvent *e)
|
||||
|
@ -43,18 +74,20 @@ void SearchPopup::initLayout()
|
|||
{
|
||||
QVBoxLayout *layout1 = new QVBoxLayout(this);
|
||||
layout1->setMargin(0);
|
||||
layout1->setSpacing(0);
|
||||
|
||||
// HBOX
|
||||
{
|
||||
QHBoxLayout *layout2 = new QHBoxLayout(this);
|
||||
layout2->setMargin(6);
|
||||
layout2->setMargin(8);
|
||||
layout2->setSpacing(8);
|
||||
|
||||
// SEARCH INPUT
|
||||
{
|
||||
this->searchInput_ = new QLineEdit(this);
|
||||
layout2->addWidget(this->searchInput_);
|
||||
QObject::connect(this->searchInput_, &QLineEdit::returnPressed,
|
||||
[this] { this->performSearch(); });
|
||||
[this] { this->search(); });
|
||||
}
|
||||
|
||||
// SEARCH BUTTON
|
||||
|
@ -63,7 +96,7 @@ void SearchPopup::initLayout()
|
|||
searchButton->setText("Search");
|
||||
layout2->addWidget(searchButton);
|
||||
QObject::connect(searchButton, &QPushButton::clicked,
|
||||
[this] { this->performSearch(); });
|
||||
[this] { this->search(); });
|
||||
}
|
||||
|
||||
layout1->addLayout(layout2);
|
||||
|
@ -80,25 +113,4 @@ void SearchPopup::initLayout()
|
|||
}
|
||||
}
|
||||
|
||||
void SearchPopup::performSearch()
|
||||
{
|
||||
QString text = searchInput_->text();
|
||||
|
||||
ChannelPtr channel(new Channel(this->channelName_, Channel::Type::None));
|
||||
|
||||
for (size_t i = 0; i < this->snapshot_.size(); i++)
|
||||
{
|
||||
MessagePtr message = this->snapshot_[i];
|
||||
|
||||
if (text.isEmpty() ||
|
||||
message->searchText.indexOf(this->searchInput_->text(), 0,
|
||||
Qt::CaseInsensitive) != -1)
|
||||
{
|
||||
channel->addMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
this->channelView_->setChannel(channel);
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "ForwardDecl.hpp"
|
||||
#include "messages/LimitedQueueSnapshot.hpp"
|
||||
#include "widgets/BaseWindow.hpp"
|
||||
|
||||
|
@ -9,30 +10,26 @@ class QLineEdit;
|
|||
|
||||
namespace chatterino {
|
||||
|
||||
class Channel;
|
||||
class ChannelView;
|
||||
|
||||
struct Message;
|
||||
using MessagePtr = std::shared_ptr<const Message>;
|
||||
|
||||
class SearchPopup : public BaseWindow
|
||||
{
|
||||
public:
|
||||
SearchPopup();
|
||||
|
||||
void setChannel(std::shared_ptr<Channel> channel);
|
||||
virtual void setChannel(const ChannelPtr &channel);
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent *e) override;
|
||||
|
||||
virtual void updateWindowTitle();
|
||||
|
||||
private:
|
||||
void initLayout();
|
||||
void performSearch();
|
||||
void search();
|
||||
|
||||
LimitedQueueSnapshot<MessagePtr> snapshot_;
|
||||
QLineEdit *searchInput_;
|
||||
ChannelView *channelView_;
|
||||
QString channelName_;
|
||||
QLineEdit *searchInput_{};
|
||||
ChannelView *channelView_{};
|
||||
QString channelName_{};
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
|
Loading…
Reference in a new issue