[DeckShare] Extract the share-creation response handling into DeckShareUtils

This commit is contained in:
Lukas Brübach 2026-09-18 23:56:40 +02:00 committed by GitHub
parent 4b870fdf06
commit a5b2114296
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 45 additions and 35 deletions

View file

@ -4,6 +4,8 @@
#include <QGuiApplication>
#include <QTimeZone>
#include <libcockatrice/network/client/abstract/abstract_client.h>
#include <libcockatrice/protocol/pb/response.pb.h>
#include <libcockatrice/protocol/pb/response_deck_share_create.pb.h>
namespace DeckShareUtils
{
@ -25,4 +27,21 @@ QString formatShareExpiry(const QDateTime &expiry)
return expiry.toLocalTime().toString();
}
ShareResponse handleShareResponse(const AbstractClient *client, const Response &response)
{
const Response_DeckShareCreate &resp = response.GetExtension(Response_DeckShareCreate::ext);
const QString token = QString::fromStdString(resp.token());
const QString link = buildShareLink(client, token);
copyShareLinkToClipboard(link);
#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
const QDateTime expiry = QDateTime::fromSecsSinceEpoch(resp.expires_at(), QTimeZone::UTC);
#else
const QDateTime expiry = QDateTime::fromSecsSinceEpoch(resp.expires_at(), Qt::UTC);
#endif
return {link, expiry};
}
} // namespace DeckShareUtils