feat: include more data when copying messages as JSON (#5600)

This commit is contained in:
nerix
2024-09-28 12:40:15 +02:00
committed by GitHub
parent edf18a7a0f
commit e149be3820
16 changed files with 504 additions and 33 deletions
+37
View File
@@ -1,9 +1,15 @@
#include "messages/Emote.hpp"
#include "common/Literals.hpp"
#include <QJsonObject>
#include <unordered_map>
namespace chatterino {
using namespace literals;
bool operator==(const Emote &a, const Emote &b)
{
return std::tie(a.homePage, a.name, a.tooltip, a.images) ==
@@ -15,6 +21,37 @@ bool operator!=(const Emote &a, const Emote &b)
return !(a == b);
}
QJsonObject Emote::toJson() const
{
QJsonObject obj{
{"name"_L1, this->name.string},
{"images"_L1, this->images.toJson()},
{"tooltip"_L1, this->tooltip.string},
};
if (!this->homePage.string.isEmpty())
{
obj["homePage"_L1] = this->homePage.string;
}
if (this->zeroWidth)
{
obj["zeroWidth"_L1] = this->zeroWidth;
}
if (!this->id.string.isEmpty())
{
obj["id"_L1] = this->id.string;
}
if (!this->author.string.isEmpty())
{
obj["author"_L1] = this->author.string;
}
if (this->baseName)
{
obj["baseName"_L1] = this->baseName->string;
}
return obj;
}
EmotePtr cachedOrMakeEmotePtr(Emote &&emote, const EmoteMap &cache)
{
// reuse old shared_ptr if nothing changed