ZaStoGram_desktop/Telegram/SourceFiles/gram/api/gram_api_request.cpp
John Preston 817f002d42 Shrink td_gram to its Telegram-native residue
Task: 2026/08/24/shrink-td-gram-to-telegram-native-residue
2026-10-08 22:23:53 +04:00

38 lines
983 B
C++

/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "gram/api/gram_api_request.h"
#include <QtCore/QJsonDocument>
#include <QtCore/QJsonObject>
#include <QtCore/QJsonValue>
#include <QtCore/QUrl>
namespace Gram {
std::optional<ApiError> ParseApiError(const QByteArray &json) {
const auto document = QJsonDocument::fromJson(json);
if (document.isNull() || !document.isObject()) {
return std::nullopt;
}
const auto object = document.object();
const auto error = object.value(u"error"_q);
if (!error.isString()) {
return std::nullopt;
}
return ApiError{ 0, error.toString() };
}
} // namespace Gram
namespace Gram::ApiDetails {
QString PercentEncoded(const QString &value) {
return QString::fromLatin1(QUrl::toPercentEncoding(value));
}
} // namespace Gram::ApiDetails