2023-12-23 20:23:38 +00:00
|
|
|
// SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
|
|
#include "session.h"
|
|
|
|
|
2023-12-28 20:26:08 +00:00
|
|
|
#include "handler/poll.h"
|
|
|
|
|
2023-12-23 20:23:38 +00:00
|
|
|
Session::Session(unsigned int id, const std::string& access, const std::string& renew):
|
|
|
|
id(id),
|
|
|
|
access(access),
|
2023-12-28 20:26:08 +00:00
|
|
|
renew(renew),
|
|
|
|
polling(nullptr)
|
2023-12-23 20:23:38 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
std::string Session::getAccessToken() const {
|
|
|
|
return access;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Session::getRenewToken() const {
|
|
|
|
return renew;
|
|
|
|
}
|
2023-12-28 20:26:08 +00:00
|
|
|
|
|
|
|
void Session::accept(std::unique_ptr<Request> request) {
|
|
|
|
if (polling) {
|
|
|
|
Response& res = request->createResponse(Response::Status::ok);
|
|
|
|
nlohmann::json body = nlohmann::json::object();
|
|
|
|
body["result"] = Handler::Poll::Result::replace;
|
|
|
|
|
|
|
|
res.setBody(body);
|
|
|
|
res.send();
|
|
|
|
}
|
|
|
|
|
|
|
|
polling = std::move(request);
|
|
|
|
}
|