Refactor recent messages API (#4763)

This exposes internal functions for testing by splitting the implementation & internal API into separate files
This commit is contained in:
pajlada
2023-08-12 13:34:59 +02:00
committed by GitHub
parent 5ee9697dd2
commit 3e1e400e3e
9 changed files with 332 additions and 278 deletions
+35
View File
@@ -0,0 +1,35 @@
#pragma once
#include "common/Channel.hpp"
#include "messages/Message.hpp"
#include <IrcMessage>
#include <QJsonObject>
#include <QString>
#include <QUrl>
#include <memory>
#include <vector>
namespace chatterino::recentmessages::detail {
// convertClearchatToNotice takes a Communi::IrcMessage that is a CLEARCHAT
// command and converts it to a readable NOTICE message. This has
// historically been done in the Recent Messages API, but this functionality
// has been moved to Chatterino instead.
Communi::IrcMessage *convertClearchatToNotice(Communi::IrcMessage *message);
// Parse the IRC messages returned in JSON form into Communi messages
std::vector<Communi::IrcMessage *> parseRecentMessages(
const QJsonObject &jsonRoot);
// Build Communi messages retrieved from the recent messages API into
// proper chatterino messages.
std::vector<MessagePtr> buildRecentMessages(
std::vector<Communi::IrcMessage *> &messages, Channel *channel);
// Returns the URL to be used for querying the Recent Messages API for the
// given channel.
QUrl constructRecentMessagesUrl(const QString &name);
} // namespace chatterino::recentmessages::detail