Skip to content

Commit

Permalink
Merge branch 'master' into test-refactor/emoji-rfc
Browse files Browse the repository at this point in the history
  • Loading branch information
Mm2PL authored Sep 28, 2024
2 parents 5ae1fbe + e149be3 commit d5ab142
Show file tree
Hide file tree
Showing 21 changed files with 583 additions and 80 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
- Bugfix: Fixed account switch not being saved if no other settings were changed. (#5558)
- Bugfix: Fixed some tooltips not being readable. (#5578)
- Bugfix: Fixed log files being locked longer than needed. (#5592)
- Bugfix: Fixed global badges not showing in anonymous mode. (#5599)
- Bugfix: Fixed grammar in the user highlight page. (#5602)
- Dev: Update Windows build from Qt 6.5.0 to Qt 6.7.1. (#5420)
- Dev: Update vcpkg build Qt from 6.5.0 to 6.7.0, boost from 1.83.0 to 1.85.0, openssl from 3.1.3 to 3.3.0. (#5422)
- Dev: Unsingletonize `ISoundController`. (#5462)
Expand Down Expand Up @@ -89,6 +91,7 @@
- Dev: Cleanup some parts of the `magic_enum` adaptation for Qt. (#5587)
- Dev: Refactored `static`s in headers to only be present once in the final app. (#5588)
- Dev: Refactored legacy Unicode zero-width-joiner replacement. (#5594)
- Dev: The JSON output when copying a message (<kbd>SHIFT</kbd> + right-click) is now more extensive. (#5600)

## 2.5.1

Expand Down
2 changes: 1 addition & 1 deletion resources/twitch-badges.json

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions scripts/update-badges.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import sys
import json
from pathlib import Path


def trim_version(version):
base_url = version["image_url_1x"].removesuffix("1")
assert version["image_url_2x"] == base_url + "2"
assert version["image_url_4x"] == base_url + "3"
v = {
"id": version["id"],
"title": version["title"],
"image": base_url,
}
if version["click_url"]:
v["url"] = version["click_url"]
return v


raw = sys.stdin.read()
assert len(raw) > 0, "Response from Helix' chat/badges/global needs to be piped"
base = json.loads(raw)["data"]
out = {set["set_id"]: [trim_version(v) for v in set["versions"]] for set in base}

with open(
Path(__file__).parent.parent / "resources" / "twitch-badges.json", mode="w"
) as f:
f.write(json.dumps(out, separators=(",", ":")))
37 changes: 37 additions & 0 deletions src/messages/Emote.cpp
Original file line number Diff line number Diff line change
@@ -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) ==
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/messages/Emote.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <optional>
#include <unordered_map>

class QJsonObject;

namespace chatterino {

struct Emote {
Expand All @@ -30,6 +32,8 @@ struct Emote {
{
return name.string;
}

QJsonObject toJson() const;
};

bool operator==(const Emote &a, const Emote &b);
Expand Down
20 changes: 20 additions & 0 deletions src/messages/ImageSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "messages/Image.hpp"
#include "singletons/Settings.hpp"

#include <QJsonObject>

namespace chatterino {

ImageSet::ImageSet()
Expand Down Expand Up @@ -135,4 +137,22 @@ bool ImageSet::operator!=(const ImageSet &other) const
return !this->operator==(other);
}

QJsonObject ImageSet::toJson() const
{
QJsonObject obj;
if (!this->imageX1_->isEmpty())
{
obj[u"1x"] = this->imageX1_->url().string;
}
if (!this->imageX2_->isEmpty())
{
obj[u"2x"] = this->imageX2_->url().string;
}
if (!this->imageX3_->isEmpty())
{
obj[u"3x"] = this->imageX3_->url().string;
}
return obj;
}

} // namespace chatterino
4 changes: 4 additions & 0 deletions src/messages/ImageSet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include <memory>

class QJsonObject;

namespace chatterino {

class Image;
Expand Down Expand Up @@ -34,6 +36,8 @@ class ImageSet
bool operator==(const ImageSet &other) const;
bool operator!=(const ImageSet &other) const;

QJsonObject toJson() const;

private:
ImagePtr imageX1_;
ImagePtr imageX2_;
Expand Down
78 changes: 78 additions & 0 deletions src/messages/Message.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
#include "messages/Message.hpp"

#include "Application.hpp"
#include "common/Literals.hpp"
#include "messages/MessageThread.hpp"
#include "providers/colors/ColorProvider.hpp"
#include "providers/twitch/TwitchBadge.hpp"
#include "singletons/Settings.hpp"
#include "util/DebugCount.hpp"
#include "util/QMagicEnum.hpp"
#include "widgets/helper/ScrollbarHighlight.hpp"

#include <QJsonArray>
#include <QJsonObject>
#include <QJsonValue>

namespace chatterino {

using namespace literals;

Message::Message()
: parseTime(QTime::currentTime())
{
Expand Down Expand Up @@ -80,4 +90,72 @@ ScrollbarHighlight Message::getScrollBarHighlight() const
return {};
}

QJsonObject Message::toJson() const
{
QJsonObject msg{
{"flags"_L1, qmagicenum::enumFlagsName(this->flags.value())},
{"id"_L1, this->id},
{"searchText"_L1, this->searchText},
{"messageText"_L1, this->messageText},
{"loginName"_L1, this->loginName},
{"displayName"_L1, this->displayName},
{"localizedName"_L1, this->localizedName},
{"timeoutUser"_L1, this->timeoutUser},
{"channelName"_L1, this->channelName},
{"usernameColor"_L1, this->usernameColor.name(QColor::HexArgb)},
{"count"_L1, static_cast<qint64>(this->count)},
{"serverReceivedTime"_L1,
this->serverReceivedTime.toString(Qt::ISODate)},
};

QJsonArray badges;
for (const auto &badge : this->badges)
{
badges.append(badge.key_);
}
msg["badges"_L1] = badges;

QJsonObject badgeInfos;
for (const auto &[key, value] : this->badgeInfos)
{
badgeInfos.insert(key, value);
}
msg["badgeInfos"_L1] = badgeInfos;

if (this->highlightColor)
{
msg["highlightColor"_L1] = this->highlightColor->name(QColor::HexArgb);
}

if (this->replyThread)
{
msg["replyThread"_L1] = this->replyThread->toJson();
}

if (this->replyParent)
{
msg["replyParent"_L1] = this->replyParent->id;
}

if (this->reward)
{
msg["reward"_L1] = this->reward->toJson();
}

// XXX: figure out if we can add this in tests
if (!getApp()->isTest())
{
msg["parseTime"_L1] = this->parseTime.toString(Qt::ISODate);
}

QJsonArray elements;
for (const auto &element : this->elements)
{
elements.append(element->toJson());
}
msg["elements"_L1] = elements;

return msg;
}

} // namespace chatterino
4 changes: 4 additions & 0 deletions src/messages/Message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <unordered_map>
#include <vector>

class QJsonObject;

namespace chatterino {
class MessageElement;
class MessageThread;
Expand Down Expand Up @@ -62,6 +64,8 @@ struct Message {
ScrollbarHighlight getScrollBarHighlight() const;

std::shared_ptr<ChannelPointReward> reward = nullptr;

QJsonObject toJson() const;
};

} // namespace chatterino
17 changes: 17 additions & 0 deletions src/messages/MessageColor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,21 @@ const QColor &MessageColor::getColor(Theme &themeManager) const
return _default;
}

QString MessageColor::toString() const
{
switch (this->type_)
{
case Type::Custom:
return this->customColor_.name(QColor::HexArgb);
case Type::Text:
return QStringLiteral("Text");
case Type::System:
return QStringLiteral("System");
case Type::Link:
return QStringLiteral("Link");
default:
return {};
}
}

} // namespace chatterino
3 changes: 3 additions & 0 deletions src/messages/MessageColor.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <QColor>
#include <QString>

namespace chatterino {
class Theme;
Expand All @@ -13,6 +14,8 @@ struct MessageColor {

const QColor &getColor(Theme &themeManager) const;

QString toString() const;

private:
Type type_;
QColor customColor_;
Expand Down
Loading

0 comments on commit d5ab142

Please sign in to comment.