4
1
mirror of https://github.com/QuasarApp/qTbot.git synced 2025-05-04 01:09:38 +00:00

fix crash on distructor

This commit is contained in:
Andrei Yankovich 2023-10-28 21:33:59 +02:00
parent 4d3ac752a7
commit 99f415ee86
5 changed files with 148 additions and 4 deletions

@ -61,9 +61,16 @@ IBot::sendRequest(const QSharedPointer<iRequest> &rquest) {
QSharedPointer<QHttpMultiPart> httpData;
switch (rquest->method()) {
case iRequest::Get:
networkReplay.reset(_manager->get(QNetworkRequest(url)));
case iRequest::Get: {
auto reply = _manager->get(QNetworkRequest(url));
// we control replay object wia shared pointers.
reply->setParent(nullptr);
networkReplay.reset(reply);
break;
}
case iRequest::Post:
// req.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
// reply = m_nam.post(req, params.toByteArray());
@ -74,7 +81,12 @@ IBot::sendRequest(const QSharedPointer<iRequest> &rquest) {
httpData = rquest->argsToMultipartFormData();
if (httpData) {
networkReplay.reset(_manager->post(netRequest, httpData.data()));
auto reply = _manager->post(netRequest, httpData.data());
// we control replay object wia shared pointers.
reply->setParent(nullptr);
networkReplay.reset(reply);
} else {
return nullptr;
}
@ -124,7 +136,7 @@ void IBot::handleIncomeNewUpdate(const QSharedPointer<iUpdate> & message) {
}
void IBot::doRemoveFinishedRequests() {
for (auto address: qAsConst(_toRemove)) {
for (auto address: std::as_const(_toRemove)) {
_replayStorage.remove(address);
}

@ -0,0 +1,48 @@
//#
//# Copyright (C) 2023-2023 QuasarApp.
//# Distributed under the GPLv3 software license, see the accompanying
//# Everyone is permitted to copy and distribute verbatim copies
//# of this license document, but changing it is not allowed.
//#
#include "telegramcontact.h"
namespace qTbot {
TelegramContact::TelegramContact()
{
}
TelegramContact::TelegramContact(const QJsonObject &jsonObject): IJsonBasedObject(jsonObject) {
}
unsigned long long TelegramContact::userIdInt() const {
return rawJson()["user_id"].toInteger();
}
QVariant TelegramContact::userId() const {
return rawJson()["user_id"];
}
QString TelegramContact::firstName() const {
return rawJson()["first_name"].toString();
}
QString TelegramContact::lastName() const {
return rawJson()["last_name"].toString();
}
QString TelegramContact::username() const {
return rawJson()["username"].toString();
}
QString TelegramContact::phone() const {
return rawJson()["phone_number"].toString();
}
QString TelegramContact::languageCode() const {
return rawJson()["language_code"].toString();
}
}

@ -0,0 +1,68 @@
//#
//# Copyright (C) 2023-2023 QuasarApp.
//# Distributed under the GPLv3 software license, see the accompanying
//# Everyone is permitted to copy and distribute verbatim copies
//# of this license document, but changing it is not allowed.
//#
#ifndef TELEGRAMCONTACT_H
#define TELEGRAMCONTACT_H
#include <qTbot/ijsonbasedobject.h>
namespace qTbot {
/**
* @brief The telegramcontact class contains information about user contact.
*/
class QTBOT_EXPORT TelegramContact: public IJsonBasedObject
{
public:
TelegramContact();
TelegramContact(const QJsonObject &jsonObject);
/**
* @brief userId This is id of usercontact
* @return id of user
*/
unsigned long long userIdInt() const;
/**
* @brief userId This is id of usercontact
* @return id of user
*/
QVariant userId() const;
/**
* @brief chatFirstName returns the first participant's first name in the chat.
* @return The first participant's first name in the chat.
*/
QString firstName() const;
/**
* @brief chatLastName returns the first participant's last name in the chat.
* @return The first participant's last name in the chat.
*/
QString lastName() const;
/**
* @brief chatUsername returns the first participant's username in the chat.
* @return The first participant's username in the chat.
*/
QString username() const;
/**
* @brief chatUsername returns the first participant's username in the chat.
* @return The first participant's username in the chat.
*/
QString phone() const;
/**
* @brief languageCode returns the sender's language code.
* @return The sender's language code.
*/
QString languageCode() const;
};
}
#endif // TELEGRAMCONTACT_H

@ -163,6 +163,10 @@ QSharedPointer<TelegramAudio> TelegramMsg::audio() const {
return QSharedPointer<TelegramAudio>::create(rawJson()[Audio].toObject());
}
QSharedPointer<TelegramContact> TelegramMsg::contact() const {
return QSharedPointer<TelegramContact>::create(rawJson()[Contact].toObject());
}
unsigned long long TelegramMsg::updateId() const {
return 0;
}

@ -9,6 +9,7 @@
#define TELEGRAMMSG_H
#include "imessage.h"
#include "qTbot/messages/telegramcontact.h"
#include "telegramaudio.h"
#include "telegramdocument.h"
#include "qTbot/messages/telegramimage.h"
@ -60,6 +61,11 @@ public:
*/
const Type Document = "document";
/**
* @brief Contact This is type of the files.
*/
const Type Contact = "contact";
/**
* @brief Audio This is type of Audio files.
*/
@ -200,6 +206,12 @@ public:
*/
QSharedPointer<TelegramAudio> audio() const;
/**
* @brief contact return contact
* @return contact information
*/
QSharedPointer<TelegramContact> contact() const;
unsigned long long updateId() const override;
};