Sending locations seems to work as well...

This commit is contained in:
Sebastian Wolf 2021-01-03 01:22:30 +01:00
parent 7c615b5cff
commit 2b634471dc
No known key found for this signature in database
GPG key ID: CEA9522B5F38A90A
17 changed files with 220 additions and 5 deletions

View file

@ -16,7 +16,7 @@ CONFIG += sailfishapp sailfishapp_i18n
PKGCONFIG += nemonotifications-qt5 zlib
QT += core dbus sql multimedia
QT += core dbus sql multimedia positioning
DEFINES += QT_STATICPLUGIN

View file

@ -212,8 +212,11 @@ Page {
attachmentPreviewRow.isVideo = false;
attachmentPreviewRow.isDocument = false;
attachmentPreviewRow.isVoiceNote = false;
attachmentPreviewRow.isLocation = false;
attachmentPreviewRow.fileProperties = {};
attachmentPreviewRow.locationData = {};
attachmentPreviewRow.attachmentDescription = "";
fernschreiberUtils.stopGeoLocationUpdates();
}
function controlSendButton() {
@ -221,7 +224,8 @@ Page {
|| attachmentPreviewRow.isPicture
|| attachmentPreviewRow.isDocument
|| attachmentPreviewRow.isVideo
|| attachmentPreviewRow.isVoiceNote) {
|| attachmentPreviewRow.isVoiceNote
|| attachmentPreviewRow.isLocation) {
newMessageSendButton.enabled = true;
} else {
newMessageSendButton.enabled = false;
@ -245,6 +249,9 @@ Page {
if (attachmentPreviewRow.isVoiceNote) {
tdLibWrapper.sendVoiceNoteMessage(chatInformation.id, fernschreiberUtils.voiceNotePath(), newMessageTextField.text, newMessageColumn.replyToMessageId);
}
if (attachmentPreviewRow.isLocation) {
tdLibWrapper.sendLocationMessage(chatInformation.id, attachmentPreviewRow.locationData.latitude, attachmentPreviewRow.locationData.longitude, attachmentPreviewRow.locationData.horizontalAccuracy, newMessageColumn.replyToMessageId);
}
clearAttachmentPreviewRow();
} else {
tdLibWrapper.sendTextMessage(chatInformation.id, newMessageTextField.text, newMessageColumn.replyToMessageId);
@ -257,6 +264,7 @@ Page {
controlSendButton();
newMessageInReplyToRow.inReplyToMessage = null;
newMessageColumn.editMessageId = "0";
fernschreiberUtils.stopGeoLocationUpdates();
}
function getWordBoundaries(text, cursorPosition) {
@ -386,6 +394,7 @@ Page {
if (chatPage.canSendMessages) {
tdLibWrapper.setChatDraftMessage(chatInformation.id, 0, newMessageColumn.replyToMessageId, newMessageTextField.text);
}
fernschreiberUtils.stopGeoLocationUpdates();
tdLibWrapper.closeChat(chatInformation.id);
}
@ -1201,7 +1210,6 @@ Page {
id: attachmentOptionsFlickable
property bool isNeeded: false
width: parent.width
height: isNeeded ? attachmentOptionsRow.height : 0
Behavior on height { SmoothedAnimation { duration: 200 } }
@ -1305,6 +1313,22 @@ Page {
attachmentOptionsFlickable.isNeeded = false;
}
}
IconButton {
visible: fernschreiberUtils.supportsGeoLocation() && newMessageTextField.text === ""
icon.source: "image://theme/icon-m-location"
icon.sourceSize {
width: Theme.iconSizeMedium
height: Theme.iconSizeMedium
}
onClicked: {
fernschreiberUtils.startGeoLocationUpdates();
attachmentOptionsFlickable.isNeeded = false;
attachmentPreviewRow.isLocation = true;
attachmentPreviewRow.attachmentDescription = qsTr("Location: Obtaining position...");
attachmentPreviewRow.visible = true;
controlSendButton();
}
}
}
}
@ -1322,9 +1346,21 @@ Page {
property bool isVideo: false;
property bool isDocument: false;
property bool isVoiceNote: false;
property bool isLocation: false;
property var locationData: ({});
property var fileProperties:({});
property string attachmentDescription: "";
Connections {
target: fernschreiberUtils
onNewPositionInformation: {
attachmentPreviewRow.locationData = positionInformation;
if (attachmentPreviewRow.isLocation) {
attachmentPreviewRow.attachmentDescription = qsTr("Location (%1/%2)").arg(attachmentPreviewRow.locationData.latitude).arg(attachmentPreviewRow.locationData.longitude);
}
}
}
IconButton {
id: removeAttachmentsIconButton
icon.source: "image://theme/icon-m-clear"
@ -1350,13 +1386,13 @@ Page {
Label {
id: attachmentPreviewText
font.pixelSize: Theme.fontSizeSmall
text: attachmentPreviewRow.isVoiceNote ? attachmentPreviewRow.attachmentDescription : ( typeof attachmentPreviewRow.fileProperties !== "undefined" ? attachmentPreviewRow.fileProperties.fileName || "" : "" );
text: ( attachmentPreviewRow.isVoiceNote || attachmentPreviewRow.isLocation ) ? attachmentPreviewRow.attachmentDescription : ( typeof attachmentPreviewRow.fileProperties !== "undefined" ? attachmentPreviewRow.fileProperties.fileName || "" : "" );
anchors.verticalCenter: parent.verticalCenter
maximumLineCount: 1
truncationMode: TruncationMode.Fade
color: Theme.secondaryColor
visible: attachmentPreviewRow.isDocument || attachmentPreviewRow.isVoiceNote
visible: attachmentPreviewRow.isDocument || attachmentPreviewRow.isVoiceNote || attachmentPreviewRow.isLocation
}
}
@ -1558,6 +1594,7 @@ Page {
labelVisible: false
textLeftMargin: 0
textTopMargin: 0
enabled: !attachmentPreviewRow.isLocation
EnterKey.onClicked: {
if (appSettings.sendByEnter) {
sendMessage();

View file

@ -25,6 +25,8 @@
#include <QDir>
#include <QFile>
#include <QUrl>
#include <QGeoCoordinate>
#include <QGeoLocation>
#define DEBUG_MODULE FernschreiberUtils
#include "debuglog.h"
@ -53,6 +55,14 @@ FernschreiberUtils::FernschreiberUtils(QObject *parent) : QObject(parent)
connect(&audioRecorder, SIGNAL(durationChanged(qlonglong)), this, SIGNAL(voiceNoteDurationChanged(qlonglong)));
connect(&audioRecorder, SIGNAL(statusChanged(QMediaRecorder::Status)), this, SLOT(handleAudioRecorderStatusChanged(QMediaRecorder::Status)));
this->geoPositionInfoSource = QGeoPositionInfoSource::createDefaultSource(this);
if (this->geoPositionInfoSource) {
LOG("Geolocation successfully initialized...");
this->geoPositionInfoSource->setUpdateInterval(5000);
connect(geoPositionInfoSource, SIGNAL(positionUpdated(QGeoPositionInfo)), this, SLOT(handleGeoPositionUpdated(QGeoPositionInfo)));
} else {
LOG("Unable to initialize geolocation!");
}
}
FernschreiberUtils::~FernschreiberUtils()
@ -205,6 +215,25 @@ FernschreiberUtils::VoiceNoteRecordingState FernschreiberUtils::getVoiceNoteReco
return this->voiceNoteRecordingState;
}
void FernschreiberUtils::startGeoLocationUpdates()
{
if (this->geoPositionInfoSource) {
this->geoPositionInfoSource->startUpdates();
}
}
void FernschreiberUtils::stopGeoLocationUpdates()
{
if (this->geoPositionInfoSource) {
this->geoPositionInfoSource->stopUpdates();
}
}
bool FernschreiberUtils::supportsGeoLocation()
{
return this->geoPositionInfoSource;
}
void FernschreiberUtils::handleAudioRecorderStatusChanged(QMediaRecorder::Status status)
{
LOG("Audio recorder status changed:" << status);
@ -231,8 +260,33 @@ void FernschreiberUtils::handleAudioRecorderStatusChanged(QMediaRecorder::Status
emit voiceNoteRecordingStateChanged(this->voiceNoteRecordingState);
}
void FernschreiberUtils::handleGeoPositionUpdated(const QGeoPositionInfo &info)
{
LOG("Geo position was updated");
QVariantMap positionInformation;
if (info.hasAttribute(QGeoPositionInfo::HorizontalAccuracy)) {
positionInformation.insert("horizontalAccuracy", info.attribute(QGeoPositionInfo::HorizontalAccuracy));
} else {
positionInformation.insert("horizontalAccuracy", 0);
}
if (info.hasAttribute(QGeoPositionInfo::VerticalAccuracy)) {
positionInformation.insert("verticalAccuracy", info.attribute(QGeoPositionInfo::VerticalAccuracy));
} else {
positionInformation.insert("verticalAccuracy", 0);
}
QGeoCoordinate geoCoordinate = info.coordinate();
positionInformation.insert("latitude", geoCoordinate.latitude());
positionInformation.insert("longitude", geoCoordinate.longitude());
emit newPositionInformation(positionInformation);
}
void FernschreiberUtils::cleanUp()
{
if (this->geoPositionInfoSource) {
this->geoPositionInfoSource->stopUpdates();
}
QString voiceNotePath = this->voiceNotePath();
if (QFile::exists(voiceNotePath)) {
LOG("Removing old temporary file...");

View file

@ -22,6 +22,8 @@
#include <QObject>
#include <QAudioRecorder>
#include <QGeoPositionInfo>
#include <QGeoPositionInfoSource>
#include "tdlibwrapper.h"
class FernschreiberUtils : public QObject
@ -47,18 +49,25 @@ public:
Q_INVOKABLE void stopRecordingVoiceNote();
Q_INVOKABLE QString voiceNotePath();
Q_INVOKABLE VoiceNoteRecordingState getVoiceNoteRecordingState();
Q_INVOKABLE void startGeoLocationUpdates();
Q_INVOKABLE void stopGeoLocationUpdates();
Q_INVOKABLE bool supportsGeoLocation();
signals:
void voiceNoteDurationChanged(qlonglong duration);
void voiceNoteRecordingStateChanged(VoiceNoteRecordingState state);
void newPositionInformation(const QVariantMap &positionInformation);
private slots:
void handleAudioRecorderStatusChanged(QMediaRecorder::Status status);
void handleGeoPositionUpdated(const QGeoPositionInfo &info);
private:
QAudioRecorder audioRecorder;
VoiceNoteRecordingState voiceNoteRecordingState;
QGeoPositionInfoSource *geoPositionInfoSource;
void cleanUp();
};

View file

@ -497,6 +497,32 @@ void TDLibWrapper::sendVoiceNoteMessage(const QString &chatId, const QString &fi
this->sendRequest(requestObject);
}
void TDLibWrapper::sendLocationMessage(const QString &chatId, double latitude, double longitude, double horizontalAccuracy, const QString &replyToMessageId)
{
LOG("Sending location message" << chatId << latitude << longitude << horizontalAccuracy << replyToMessageId);
QVariantMap requestObject;
requestObject.insert(_TYPE, "sendMessage");
requestObject.insert(CHAT_ID, chatId);
if (replyToMessageId != "0") {
requestObject.insert("reply_to_message_id", replyToMessageId);
}
QVariantMap inputMessageContent;
inputMessageContent.insert(_TYPE, "inputMessageLocation");
QVariantMap location;
location.insert("latitude", latitude);
location.insert("longitude", longitude);
location.insert("horizontal_accuracy", horizontalAccuracy);
location.insert(_TYPE, "location");
inputMessageContent.insert("location", location);
inputMessageContent.insert("live_period", 0);
inputMessageContent.insert("heading", 0);
inputMessageContent.insert("proximity_alert_radius", 0);
requestObject.insert("input_message_content", inputMessageContent);
this->sendRequest(requestObject);
}
void TDLibWrapper::sendStickerMessage(const QString &chatId, const QString &fileId, const QString &replyToMessageId)
{
LOG("Sending sticker message" << chatId << fileId << replyToMessageId);

View file

@ -140,6 +140,7 @@ public:
Q_INVOKABLE void sendVideoMessage(const QString &chatId, const QString &filePath, const QString &message, const QString &replyToMessageId = "0");
Q_INVOKABLE void sendDocumentMessage(const QString &chatId, const QString &filePath, const QString &message, const QString &replyToMessageId = "0");
Q_INVOKABLE void sendVoiceNoteMessage(const QString &chatId, const QString &filePath, const QString &message, const QString &replyToMessageId = "0");
Q_INVOKABLE void sendLocationMessage(const QString &chatId, double latitude, double longitude, double horizontalAccuracy, const QString &replyToMessageId = "0");
Q_INVOKABLE void sendStickerMessage(const QString &chatId, const QString &fileId, const QString &replyToMessageId = "0");
Q_INVOKABLE void sendPollMessage(const QString &chatId, const QString &question, const QVariantList &options, bool anonymous, int correctOption, bool multiple, const QString &replyToMessageId = "0");
Q_INVOKABLE void forwardMessages(const QString &chatId, const QString &fromChatId, const QVariantList &messageIds, bool sendCopy, bool removeCaption);

View file

@ -411,6 +411,14 @@
<source>Search in chat...</source>
<translation>Im Chat suchen...</translation>
</message>
<message>
<source>Location: Obtaining position...</source>
<translation>Standort: Erlange Position...</translation>
</message>
<message>
<source>Location (%1/%2)</source>
<translation>Standort (%1/%2)</translation>
</message>
</context>
<context>
<name>ChatSelectionPage</name>

View file

@ -411,6 +411,14 @@
<source>Search in chat...</source>
<translation>Search in chat...</translation>
</message>
<message>
<source>Location: Obtaining position...</source>
<translation>Location: Obtaining position...</translation>
</message>
<message>
<source>Location (%1/%2)</source>
<translation>Location (%1/%2)</translation>
</message>
</context>
<context>
<name>ChatSelectionPage</name>

View file

@ -401,6 +401,14 @@
<source>Search in chat...</source>
<translation>Buscar</translation>
</message>
<message>
<source>Location: Obtaining position...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Location (%1/%2)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ChatSelectionPage</name>

View file

@ -411,6 +411,14 @@
<source>Search in chat...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Location: Obtaining position...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Location (%1/%2)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ChatSelectionPage</name>

View file

@ -401,6 +401,14 @@
<source>Search in chat...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Location: Obtaining position...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Location (%1/%2)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ChatSelectionPage</name>

View file

@ -411,6 +411,14 @@
<source>Search in chat...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Location: Obtaining position...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Location (%1/%2)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ChatSelectionPage</name>

View file

@ -421,6 +421,14 @@
<source>Search in chat...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Location: Obtaining position...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Location (%1/%2)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ChatSelectionPage</name>

View file

@ -421,6 +421,14 @@
<source>Search in chat...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Location: Obtaining position...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Location (%1/%2)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ChatSelectionPage</name>

View file

@ -411,6 +411,14 @@
<source>Search in chat...</source>
<translation>Sök i chatten...</translation>
</message>
<message>
<source>Location: Obtaining position...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Location (%1/%2)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ChatSelectionPage</name>

View file

@ -401,6 +401,14 @@
<source>Search in chat...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Location: Obtaining position...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Location (%1/%2)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ChatSelectionPage</name>

View file

@ -411,6 +411,14 @@
<source>Search in chat...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Location: Obtaining position...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Location (%1/%2)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ChatSelectionPage</name>