feat: Add "Copy message as JSON" option when shift-right-clicking a message (#5150)

This commit is contained in:
pajlada 2024-02-03 13:03:31 +01:00 committed by GitHub
parent 0393146187
commit 7fdb3841db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 33 additions and 0 deletions

View file

@ -113,6 +113,7 @@
- Dev: `Details` file properties tab is now populated on Windows. (#4912)
- Dev: Removed `Outcome` from network requests. (#4959)
- Dev: Added Tests for Windows and MacOS in CI. (#4970, #5032)
- Dev: Added "Copy message as JSON" option when shift-right-clicking a message. (#5150)
- Dev: Move `clang-tidy` checker to its own CI job. (#4996)
- Dev: Refactored the Image Uploader feature. (#4971)
- Dev: Refactored the SplitOverlay code. (#5082)

View file

@ -3,6 +3,7 @@
#include "common/FlagsEnum.hpp"
#include "util/QStringHash.hpp"
#include <magic_enum/magic_enum.hpp>
#include <QColor>
#include <QTime>
@ -107,3 +108,8 @@ struct Message {
};
} // namespace chatterino
template <>
struct magic_enum::customize::enum_range<chatterino::MessageFlag> {
static constexpr bool is_flags = true;
};

View file

@ -45,6 +45,7 @@
#include "widgets/TooltipWidget.hpp"
#include "widgets/Window.hpp"
#include <magic_enum/magic_enum_flags.hpp>
#include <QClipboard>
#include <QColor>
#include <QDate>
@ -52,6 +53,7 @@
#include <QDesktopServices>
#include <QEasingCurve>
#include <QGraphicsBlurEffect>
#include <QJsonDocument>
#include <QMessageBox>
#include <QPainter>
#include <QScreen>
@ -244,6 +246,30 @@ void addHiddenContextMenuItems(QMenu *menu,
crossPlatformCopy(messageID);
});
}
const auto *message = layout->getMessage();
if (message != nullptr)
{
QJsonDocument jsonDocument;
QJsonObject jsonObject;
jsonObject["id"] = message->id;
jsonObject["searchText"] = message->searchText;
jsonObject["messageText"] = message->messageText;
jsonObject["flags"] = QString::fromStdString(
magic_enum::enum_flags_name(message->flags.value()));
jsonDocument.setObject(jsonObject);
auto jsonString =
jsonDocument.toJson(QJsonDocument::JsonFormat::Indented);
menu->addAction("Copy message &JSON", [jsonString] {
crossPlatformCopy(jsonString);
});
}
}
// Current function: https://www.desmos.com/calculator/vdyamchjwh