Skip to content

Commit

Permalink
Merge pull request #9 from QuasarApp/sendLocations
Browse files Browse the repository at this point in the history
added support of location data type
  • Loading branch information
EndrII authored Nov 4, 2023
2 parents a95391d + 94e93a2 commit ac3b39c
Show file tree
Hide file tree
Showing 11 changed files with 182 additions and 19 deletions.
5 changes: 1 addition & 4 deletions src/qTbot/qTbot.qrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
<RCC>
<qresource prefix="/">
<file>src/qTbotModule/qmldir</file>
<file>src/qTbotModule/qTbot.qml</file>
</qresource>
<qresource prefix="/"/>
<qresource prefix="/qTbotTr"/>
</RCC>
31 changes: 31 additions & 0 deletions src/qTbot/src/private/requests/telegramsendlocation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//#
//# 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 "telegramsendlocation.h"
namespace qTbot {

TelegramSendLocation::TelegramSendLocation(const QVariant &chatId,
const QString &text,
float latitude,
float longitude,
unsigned long long replyToMessageId
):
TelegramSingleRquest("sendLocation") {

addArg("chat_id", chatId);
if (text.size())
addArg("caption", text);

addArg("latitude", latitude);
addArg("longitude", longitude);

if (replyToMessageId) {
addArg("reply_to_message_id", replyToMessageId);
}
}

}
27 changes: 27 additions & 0 deletions src/qTbot/src/private/requests/telegramsendlocation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//#
//# 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 TELEGRAMSENDLOCATION_H
#define TELEGRAMSENDLOCATION_H

#include "requests/telegramsinglerquest.h"
namespace qTbot {

/**
* @brief The TelegramSendLocation class sents location data into chat
*/
class TelegramSendLocation: public TelegramSingleRquest
{
public:
TelegramSendLocation(const QVariant &chatId,
const QString &text,
float latitude,
float longitude,
unsigned long long replyToMessageId);
};
}
#endif // TELEGRAMSENDLOCATION_H
18 changes: 18 additions & 0 deletions src/qTbot/src/public/qTbot/itelegrambot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <requests/telegramsendmsg.h>
#include <requests/telegramdeletemessage.h>
#include <requests/telegrameditmessage.h>
#include <requests/telegramsendlocation.h>

#include <QNetworkReply>
#include <QSharedPointer>
Expand Down Expand Up @@ -432,6 +433,23 @@ bool ITelegramBot::sendFileById(const QString &fileID, const QVariant &chatId) {

}

bool ITelegramBot::sendLocation(const QVariant &chatId,
const QString &text,
float latitude,
float longitude,
unsigned long long replyToMessageId) {
if (!chatId.isValid() || chatId.isNull())
return false;

if (!(longitude && latitude)) {
return false;
}

auto&& request = QSharedPointer<TelegramSendLocation>::create(chatId, text, latitude, longitude, replyToMessageId);

return bool(sendRequest(request));
}

int ITelegramBot::getFileSizeByUniqueId(const QString &id) const {
if (auto && file = _filesMetaInfo.value(id)) {
return file->fileSize();
Expand Down
14 changes: 14 additions & 0 deletions src/qTbot/src/public/qTbot/itelegrambot.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,20 @@ class QTBOT_EXPORT ITelegramBot : public IBot
*/
bool sendFileById(const QString& fileID, const QVariant& chatId);

/**
* @brief sendLocation This method sents locatin to user.
* @param chatId This is distanation id chat.
* @param latitude
* @param longitude
* @param replyToMessageId The unique identifier of the message to reply to, skip if you want to sent new independet message.
* @return true if locations sent successful else false
*/
bool sendLocation(const QVariant& chatId,
const QString& text,
float latitude,
float longitude,
unsigned long long replyToMessageId = 0);

// to do

// * forwardMessage implementations
Expand Down
31 changes: 31 additions & 0 deletions src/qTbot/src/public/qTbot/messages/telegramlocation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//#
//# 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 "telegramlocation.h"

namespace qTbot {

TelegramLocation::TelegramLocation()
{

}

TelegramLocation::TelegramLocation(const QJsonObject &jsonObject):
IJsonBasedObject(jsonObject) {

}

double TelegramLocation::latitude() const {
return rawJson()["latitude"].toDouble();

}

double TelegramLocation::longitude() const {
return rawJson()["latitude"].toDouble();

}
}
43 changes: 43 additions & 0 deletions src/qTbot/src/public/qTbot/messages/telegramlocation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//#
//# 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 TELEGRAMLOCATION_H
#define TELEGRAMLOCATION_H

#include <qTbot/ijsonbasedobject.h>

namespace qTbot {

/**
* @brief The TelegramLocation class just simple struct with latitude and longitude
*/
class TelegramLocation: public IJsonBasedObject
{
public:
TelegramLocation();

/**
* @brief Constructs a location object from a JSON object.
* @param jsonObject The JSON object containing photo data.
*/
TelegramLocation(const QJsonObject &jsonObject);

/**
* @brief latitude is float value of latitude
* @return float value of latitude
*/
double latitude() const;

/**
* @brief longitude is float value of longitude
* @return float value of longitude
*/
double longitude() const;
};
}
#endif // TELEGRAMLOCATION_H
5 changes: 5 additions & 0 deletions src/qTbot/src/public/qTbot/messages/telegrammsg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//#

#include "telegrammsg.h"
#include "qTbot/messages/telegramlocation.h"
#include "qjsonarray.h"
namespace qTbot {

Expand Down Expand Up @@ -167,6 +168,10 @@ QSharedPointer<TelegramContact> TelegramMsg::contact() const {
return QSharedPointer<TelegramContact>::create(rawJson()[Contact].toObject());
}

QSharedPointer<TelegramLocation> TelegramMsg::location() const {
return QSharedPointer<TelegramLocation>::create(rawJson()[Location].toObject());
}

unsigned long long TelegramMsg::updateId() const {
return 0;
}
Expand Down
12 changes: 12 additions & 0 deletions src/qTbot/src/public/qTbot/messages/telegrammsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "qTbot/messages/telegramcontact.h"
#include "telegramaudio.h"
#include "telegramdocument.h"
#include "telegramlocation.h"
#include "qTbot/messages/telegramimage.h"

namespace qTbot {
Expand Down Expand Up @@ -66,6 +67,11 @@ class QTBOT_EXPORT TelegramMsg: public iMessage
*/
const Type Contact = "contact";

/**
* @brief Location This is type of location data.
*/
const Type Location = "location";

/**
* @brief Audio This is type of Audio files.
*/
Expand Down Expand Up @@ -213,6 +219,12 @@ class QTBOT_EXPORT TelegramMsg: public iMessage
QSharedPointer<TelegramContact> contact() const;

unsigned long long updateId() const override;

/**
* @brief location returns location object of message.
* @return location object.
*/
QSharedPointer<TelegramLocation> location() const;
};

}
Expand Down
12 changes: 0 additions & 12 deletions src/qTbot/src/qTbotModule/qTbot.qml

This file was deleted.

3 changes: 0 additions & 3 deletions src/qTbot/src/qTbotModule/qmldir

This file was deleted.

0 comments on commit ac3b39c

Please # to comment.