Sending voice notes seems to work...

This commit is contained in:
Sebastian Wolf 2021-01-02 17:22:09 +01:00
parent d38f56b9fe
commit 5213084fb1
No known key found for this signature in database
GPG key ID: CEA9522B5F38A90A
17 changed files with 218 additions and 67 deletions

View file

@ -29,14 +29,15 @@ Item {
property int recordingState: fernschreiberUtils.getVoiceNoteRecordingState(); property int recordingState: fernschreiberUtils.getVoiceNoteRecordingState();
property int recordingDuration: 0; property int recordingDuration: 0;
property bool recordingDone: false;
function handleRecordingState() { function handleRecordingState() {
switch (recordingState) { switch (recordingState) {
case FernschreiberUtilities.Unavailable: case FernschreiberUtilities.Unavailable:
recordingStateLabel.text = qsTr("Unavailable"); recordingStateLabel.text = qsTr("Unavailable");
break; break;
case FernschreiberUtilities.Stopped: case FernschreiberUtilities.Ready:
recordingStateLabel.text = qsTr("Stopped"); recordingStateLabel.text = qsTr("Ready");
break; break;
case FernschreiberUtilities.Starting: case FernschreiberUtilities.Starting:
recordingStateLabel.text = qsTr("Starting"); recordingStateLabel.text = qsTr("Starting");
@ -167,6 +168,7 @@ Item {
onClicked: { onClicked: {
recordButton.visible = true; recordButton.visible = true;
fernschreiberUtils.stopRecordingVoiceNote(); fernschreiberUtils.stopRecordingVoiceNote();
recordingDone = true;
} }
} }
} }
@ -194,6 +196,22 @@ Item {
} }
} }
Button {
visible: recordingDone
anchors {
horizontalCenter: parent.horizontalCenter
}
text: qsTr("Use recording")
onClicked: {
attachmentOptionsRow.isNeeded = false;
attachmentPreviewRow.isVoiceNote = true;
attachmentPreviewRow.attachmentDescription = qsTr("Voice Note (%1)").arg(recordingDurationLabel.text);
attachmentPreviewRow.visible = true;
controlSendButton();
voiceNoteOverlayLoader.active = false;
}
}
} }
} }

View file

@ -211,14 +211,17 @@ Page {
attachmentPreviewRow.isPicture = false; attachmentPreviewRow.isPicture = false;
attachmentPreviewRow.isVideo = false; attachmentPreviewRow.isVideo = false;
attachmentPreviewRow.isDocument = false; attachmentPreviewRow.isDocument = false;
attachmentPreviewRow.isVoiceNote = false;
attachmentPreviewRow.fileProperties = {}; attachmentPreviewRow.fileProperties = {};
attachmentPreviewRow.attachmentDescription = "";
} }
function controlSendButton() { function controlSendButton() {
if (newMessageTextField.text.length !== 0 if (newMessageTextField.text.length !== 0
|| attachmentPreviewRow.isPicture || attachmentPreviewRow.isPicture
|| attachmentPreviewRow.isDocument || attachmentPreviewRow.isDocument
|| attachmentPreviewRow.isVideo) { || attachmentPreviewRow.isVideo
|| attachmentPreviewRow.isVoiceNote) {
newMessageSendButton.enabled = true; newMessageSendButton.enabled = true;
} else { } else {
newMessageSendButton.enabled = false; newMessageSendButton.enabled = false;
@ -239,6 +242,9 @@ Page {
if (attachmentPreviewRow.isDocument) { if (attachmentPreviewRow.isDocument) {
tdLibWrapper.sendDocumentMessage(chatInformation.id, attachmentPreviewRow.fileProperties.filePath, newMessageTextField.text, newMessageColumn.replyToMessageId); tdLibWrapper.sendDocumentMessage(chatInformation.id, attachmentPreviewRow.fileProperties.filePath, newMessageTextField.text, newMessageColumn.replyToMessageId);
} }
if (attachmentPreviewRow.isVoiceNote) {
tdLibWrapper.sendVoiceNoteMessage(chatInformation.id, fernschreiberUtils.voiceNotePath(), newMessageTextField.text, newMessageColumn.replyToMessageId);
}
clearAttachmentPreviewRow(); clearAttachmentPreviewRow();
} else { } else {
tdLibWrapper.sendTextMessage(chatInformation.id, newMessageTextField.text, newMessageColumn.replyToMessageId); tdLibWrapper.sendTextMessage(chatInformation.id, newMessageTextField.text, newMessageColumn.replyToMessageId);
@ -1300,7 +1306,9 @@ Page {
property bool isPicture: false; property bool isPicture: false;
property bool isVideo: false; property bool isVideo: false;
property bool isDocument: false; property bool isDocument: false;
property bool isVoiceNote: false;
property var fileProperties:({}); property var fileProperties:({});
property string attachmentDescription: "";
IconButton { IconButton {
id: removeAttachmentsIconButton id: removeAttachmentsIconButton
@ -1327,13 +1335,13 @@ Page {
Label { Label {
id: attachmentPreviewText id: attachmentPreviewText
font.pixelSize: Theme.fontSizeSmall font.pixelSize: Theme.fontSizeSmall
text: typeof attachmentPreviewRow.fileProperties !== "undefined" ? attachmentPreviewRow.fileProperties.fileName || "" : ""; text: attachmentPreviewRow.isVoiceNote ? attachmentPreviewRow.attachmentDescription : ( typeof attachmentPreviewRow.fileProperties !== "undefined" ? attachmentPreviewRow.fileProperties.fileName || "" : "" );
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
maximumLineCount: 1 maximumLineCount: 1
truncationMode: TruncationMode.Fade truncationMode: TruncationMode.Fade
color: Theme.secondaryColor color: Theme.secondaryColor
visible: attachmentPreviewRow.isDocument visible: attachmentPreviewRow.isDocument || attachmentPreviewRow.isVoiceNote
} }
} }

View file

@ -55,6 +55,11 @@ FernschreiberUtils::FernschreiberUtils(QObject *parent) : QObject(parent)
} }
FernschreiberUtils::~FernschreiberUtils()
{
this->cleanUp();
}
QString FernschreiberUtils::getMessageShortText(TDLibWrapper *tdLibWrapper, const QVariantMap &messageContent, const bool isChannel, const qlonglong currentUserId, const QVariantMap &messageSender) QString FernschreiberUtils::getMessageShortText(TDLibWrapper *tdLibWrapper, const QVariantMap &messageContent, const bool isChannel, const qlonglong currentUserId, const QVariantMap &messageSender)
{ {
if (messageContent.isEmpty()) { if (messageContent.isEmpty()) {
@ -179,12 +184,7 @@ QString FernschreiberUtils::getUserName(const QVariantMap &userInformation)
void FernschreiberUtils::startRecordingVoiceNote() void FernschreiberUtils::startRecordingVoiceNote()
{ {
LOG("Start recording voice note..."); LOG("Start recording voice note...");
QString voiceNotePath = this->voiceNotePath(); this->cleanUp();
LOG("Using temporary file at " << voiceNotePath);
if (QFile::exists(voiceNotePath)) {
LOG("Removing old temporary file...");
QFile::remove(voiceNotePath);
}
this->audioRecorder.setVolume(1); this->audioRecorder.setVolume(1);
this->audioRecorder.record(); this->audioRecorder.record();
} }
@ -216,7 +216,7 @@ void FernschreiberUtils::handleAudioRecorderStatusChanged(QMediaRecorder::Status
break; break;
case QMediaRecorder::LoadedStatus: case QMediaRecorder::LoadedStatus:
case QMediaRecorder::PausedStatus: case QMediaRecorder::PausedStatus:
this->voiceNoteRecordingState = VoiceNoteRecordingState::Stopped; this->voiceNoteRecordingState = VoiceNoteRecordingState::Ready;
break; break;
case QMediaRecorder::StartingStatus: case QMediaRecorder::StartingStatus:
this->voiceNoteRecordingState = VoiceNoteRecordingState::Starting; this->voiceNoteRecordingState = VoiceNoteRecordingState::Starting;
@ -230,3 +230,12 @@ void FernschreiberUtils::handleAudioRecorderStatusChanged(QMediaRecorder::Status
} }
emit voiceNoteRecordingStateChanged(this->voiceNoteRecordingState); emit voiceNoteRecordingStateChanged(this->voiceNoteRecordingState);
} }
void FernschreiberUtils::cleanUp()
{
QString voiceNotePath = this->voiceNotePath();
if (QFile::exists(voiceNotePath)) {
LOG("Removing old temporary file...");
QFile::remove(voiceNotePath);
}
}

View file

@ -29,10 +29,11 @@ class FernschreiberUtils : public QObject
Q_OBJECT Q_OBJECT
public: public:
explicit FernschreiberUtils(QObject *parent = nullptr); explicit FernschreiberUtils(QObject *parent = nullptr);
~FernschreiberUtils();
enum VoiceNoteRecordingState { enum VoiceNoteRecordingState {
Unavailable, Unavailable,
Stopped, Ready,
Starting, Starting,
Recording, Recording,
Stopping Stopping
@ -58,6 +59,8 @@ private:
QAudioRecorder audioRecorder; QAudioRecorder audioRecorder;
VoiceNoteRecordingState voiceNoteRecordingState; VoiceNoteRecordingState voiceNoteRecordingState;
void cleanUp();
}; };
#endif // FERNSCHREIBERUTILS_H #endif // FERNSCHREIBERUTILS_H

View file

@ -473,6 +473,30 @@ void TDLibWrapper::sendDocumentMessage(const QString &chatId, const QString &fil
this->sendRequest(requestObject); this->sendRequest(requestObject);
} }
void TDLibWrapper::sendVoiceNoteMessage(const QString &chatId, const QString &filePath, const QString &message, const QString &replyToMessageId)
{
LOG("Sending voice note message" << chatId << filePath << message << 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, "inputMessageVoiceNote");
QVariantMap formattedText;
formattedText.insert("text", message);
formattedText.insert(_TYPE, "formattedText");
inputMessageContent.insert("caption", formattedText);
QVariantMap documentInputFile;
documentInputFile.insert(_TYPE, "inputFileLocal");
documentInputFile.insert("path", filePath);
inputMessageContent.insert("voice_note", documentInputFile);
requestObject.insert("input_message_content", inputMessageContent);
this->sendRequest(requestObject);
}
void TDLibWrapper::sendStickerMessage(const QString &chatId, const QString &fileId, const QString &replyToMessageId) void TDLibWrapper::sendStickerMessage(const QString &chatId, const QString &fileId, const QString &replyToMessageId)
{ {
LOG("Sending sticker message" << chatId << fileId << replyToMessageId); LOG("Sending sticker message" << chatId << fileId << replyToMessageId);

View file

@ -139,6 +139,7 @@ public:
Q_INVOKABLE void sendPhotoMessage(const QString &chatId, const QString &filePath, const QString &message, const QString &replyToMessageId = "0"); Q_INVOKABLE void sendPhotoMessage(const QString &chatId, const QString &filePath, const QString &message, const QString &replyToMessageId = "0");
Q_INVOKABLE void sendVideoMessage(const QString &chatId, const QString &filePath, const QString &message, const QString &replyToMessageId = "0"); 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 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 sendStickerMessage(const QString &chatId, const QString &fileId, 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 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); Q_INVOKABLE void forwardMessages(const QString &chatId, const QString &fromChatId, const QVariantList &messageIds, bool sendCopy, bool removeCaption);

View file

@ -1436,31 +1436,39 @@
<name>VoiceNoteOverlay</name> <name>VoiceNoteOverlay</name>
<message> <message>
<source>Record a Voice Note</source> <source>Record a Voice Note</source>
<translation type="unfinished"></translation> <translation>Eine Sprachnachricht aufzeichnen</translation>
</message> </message>
<message> <message>
<source>Press the button to start recording</source> <source>Press the button to start recording</source>
<translation type="unfinished"></translation> <translation>Drücken Sie den Knopf, um die Aufzeichnung zu starten</translation>
</message> </message>
<message> <message>
<source>Unavailable</source> <source>Unavailable</source>
<translation type="unfinished"></translation> <translation>Nicht verfügbar</translation>
</message> </message>
<message> <message>
<source>Stopped</source> <source>Ready</source>
<translation type="unfinished"></translation> <translation>Bereit</translation>
</message> </message>
<message> <message>
<source>Starting</source> <source>Starting</source>
<translation type="unfinished"></translation> <translation>Startet</translation>
</message> </message>
<message> <message>
<source>Recording</source> <source>Recording</source>
<translation type="unfinished"></translation> <translation>Zeichnet auf</translation>
</message> </message>
<message> <message>
<source>Stopping</source> <source>Stopping</source>
<translation type="unfinished"></translation> <translation>Stoppt</translation>
</message>
<message>
<source>Use recording</source>
<translation>Aufzeichnung verwenden</translation>
</message>
<message>
<source>Voice Note (%1)</source>
<translation>Sprachnachricht (%1)</translation>
</message> </message>
</context> </context>
<context> <context>

View file

@ -1436,31 +1436,39 @@
<name>VoiceNoteOverlay</name> <name>VoiceNoteOverlay</name>
<message> <message>
<source>Record a Voice Note</source> <source>Record a Voice Note</source>
<translation type="unfinished"></translation> <translation>Record a Voice Note</translation>
</message> </message>
<message> <message>
<source>Press the button to start recording</source> <source>Press the button to start recording</source>
<translation type="unfinished"></translation> <translation>Press the button to start recording</translation>
</message> </message>
<message> <message>
<source>Unavailable</source> <source>Unavailable</source>
<translation type="unfinished"></translation> <translation>Unavailable</translation>
</message>
<message>
<source>Stopped</source>
<translation type="unfinished"></translation>
</message> </message>
<message> <message>
<source>Starting</source> <source>Starting</source>
<translation type="unfinished"></translation> <translation>Starting</translation>
</message> </message>
<message> <message>
<source>Recording</source> <source>Recording</source>
<translation type="unfinished"></translation> <translation>Recording</translation>
</message> </message>
<message> <message>
<source>Stopping</source> <source>Stopping</source>
<translation type="unfinished"></translation> <translation>Stopping</translation>
</message>
<message>
<source>Use recording</source>
<translation>Use recording</translation>
</message>
<message>
<source>Voice Note (%1)</source>
<translation>Voice Note (%1)</translation>
</message>
<message>
<source>Ready</source>
<translation>Ready</translation>
</message> </message>
</context> </context>
<context> <context>

View file

@ -1425,10 +1425,6 @@
<source>Unavailable</source> <source>Unavailable</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Stopped</source>
<translation type="unfinished"></translation>
</message>
<message> <message>
<source>Starting</source> <source>Starting</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
@ -1441,6 +1437,18 @@
<source>Stopping</source> <source>Stopping</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Use recording</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Voice Note (%1)</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ready</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>WebPagePreview</name> <name>WebPagePreview</name>

View file

@ -1447,10 +1447,6 @@
<source>Unavailable</source> <source>Unavailable</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Stopped</source>
<translation type="unfinished"></translation>
</message>
<message> <message>
<source>Starting</source> <source>Starting</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
@ -1463,6 +1459,18 @@
<source>Stopping</source> <source>Stopping</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Use recording</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Voice Note (%1)</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ready</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>WebPagePreview</name> <name>WebPagePreview</name>

View file

@ -1425,10 +1425,6 @@
<source>Unavailable</source> <source>Unavailable</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Stopped</source>
<translation type="unfinished"></translation>
</message>
<message> <message>
<source>Starting</source> <source>Starting</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
@ -1441,6 +1437,18 @@
<source>Stopping</source> <source>Stopping</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Use recording</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Voice Note (%1)</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ready</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>WebPagePreview</name> <name>WebPagePreview</name>

View file

@ -1446,10 +1446,6 @@
<source>Unavailable</source> <source>Unavailable</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Stopped</source>
<translation type="unfinished"></translation>
</message>
<message> <message>
<source>Starting</source> <source>Starting</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
@ -1462,6 +1458,18 @@
<source>Stopping</source> <source>Stopping</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Use recording</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Voice Note (%1)</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ready</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>WebPagePreview</name> <name>WebPagePreview</name>

View file

@ -1467,10 +1467,6 @@
<source>Unavailable</source> <source>Unavailable</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Stopped</source>
<translation type="unfinished"></translation>
</message>
<message> <message>
<source>Starting</source> <source>Starting</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
@ -1483,6 +1479,18 @@
<source>Stopping</source> <source>Stopping</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Use recording</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Voice Note (%1)</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ready</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>WebPagePreview</name> <name>WebPagePreview</name>

View file

@ -1467,10 +1467,6 @@
<source>Unavailable</source> <source>Unavailable</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Stopped</source>
<translation type="unfinished"></translation>
</message>
<message> <message>
<source>Starting</source> <source>Starting</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
@ -1483,6 +1479,18 @@
<source>Stopping</source> <source>Stopping</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Use recording</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Voice Note (%1)</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ready</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>WebPagePreview</name> <name>WebPagePreview</name>

View file

@ -1446,10 +1446,6 @@
<source>Unavailable</source> <source>Unavailable</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Stopped</source>
<translation type="unfinished"></translation>
</message>
<message> <message>
<source>Starting</source> <source>Starting</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
@ -1462,6 +1458,18 @@
<source>Stopping</source> <source>Stopping</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Use recording</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Voice Note (%1)</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ready</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>WebPagePreview</name> <name>WebPagePreview</name>

View file

@ -1425,10 +1425,6 @@
<source>Unavailable</source> <source>Unavailable</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Stopped</source>
<translation type="unfinished"></translation>
</message>
<message> <message>
<source>Starting</source> <source>Starting</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
@ -1441,6 +1437,18 @@
<source>Stopping</source> <source>Stopping</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Use recording</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Voice Note (%1)</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ready</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>WebPagePreview</name> <name>WebPagePreview</name>

View file

@ -1446,10 +1446,6 @@
<source>Unavailable</source> <source>Unavailable</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Stopped</source>
<translation type="unfinished"></translation>
</message>
<message> <message>
<source>Starting</source> <source>Starting</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
@ -1462,6 +1458,18 @@
<source>Stopping</source> <source>Stopping</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Use recording</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Voice Note (%1)</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ready</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>WebPagePreview</name> <name>WebPagePreview</name>