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 recordingDuration: 0;
property bool recordingDone: false;
function handleRecordingState() {
switch (recordingState) {
case FernschreiberUtilities.Unavailable:
recordingStateLabel.text = qsTr("Unavailable");
break;
case FernschreiberUtilities.Stopped:
recordingStateLabel.text = qsTr("Stopped");
case FernschreiberUtilities.Ready:
recordingStateLabel.text = qsTr("Ready");
break;
case FernschreiberUtilities.Starting:
recordingStateLabel.text = qsTr("Starting");
@ -167,6 +168,7 @@ Item {
onClicked: {
recordButton.visible = true;
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.isVideo = false;
attachmentPreviewRow.isDocument = false;
attachmentPreviewRow.isVoiceNote = false;
attachmentPreviewRow.fileProperties = {};
attachmentPreviewRow.attachmentDescription = "";
}
function controlSendButton() {
if (newMessageTextField.text.length !== 0
|| attachmentPreviewRow.isPicture
|| attachmentPreviewRow.isDocument
|| attachmentPreviewRow.isVideo) {
|| attachmentPreviewRow.isVideo
|| attachmentPreviewRow.isVoiceNote) {
newMessageSendButton.enabled = true;
} else {
newMessageSendButton.enabled = false;
@ -239,6 +242,9 @@ Page {
if (attachmentPreviewRow.isDocument) {
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();
} else {
tdLibWrapper.sendTextMessage(chatInformation.id, newMessageTextField.text, newMessageColumn.replyToMessageId);
@ -1300,7 +1306,9 @@ Page {
property bool isPicture: false;
property bool isVideo: false;
property bool isDocument: false;
property bool isVoiceNote: false;
property var fileProperties:({});
property string attachmentDescription: "";
IconButton {
id: removeAttachmentsIconButton
@ -1327,13 +1335,13 @@ Page {
Label {
id: attachmentPreviewText
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
maximumLineCount: 1
truncationMode: TruncationMode.Fade
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)
{
if (messageContent.isEmpty()) {
@ -179,12 +184,7 @@ QString FernschreiberUtils::getUserName(const QVariantMap &userInformation)
void FernschreiberUtils::startRecordingVoiceNote()
{
LOG("Start recording voice note...");
QString voiceNotePath = this->voiceNotePath();
LOG("Using temporary file at " << voiceNotePath);
if (QFile::exists(voiceNotePath)) {
LOG("Removing old temporary file...");
QFile::remove(voiceNotePath);
}
this->cleanUp();
this->audioRecorder.setVolume(1);
this->audioRecorder.record();
}
@ -216,7 +216,7 @@ void FernschreiberUtils::handleAudioRecorderStatusChanged(QMediaRecorder::Status
break;
case QMediaRecorder::LoadedStatus:
case QMediaRecorder::PausedStatus:
this->voiceNoteRecordingState = VoiceNoteRecordingState::Stopped;
this->voiceNoteRecordingState = VoiceNoteRecordingState::Ready;
break;
case QMediaRecorder::StartingStatus:
this->voiceNoteRecordingState = VoiceNoteRecordingState::Starting;
@ -230,3 +230,12 @@ void FernschreiberUtils::handleAudioRecorderStatusChanged(QMediaRecorder::Status
}
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
public:
explicit FernschreiberUtils(QObject *parent = nullptr);
~FernschreiberUtils();
enum VoiceNoteRecordingState {
Unavailable,
Stopped,
Ready,
Starting,
Recording,
Stopping
@ -58,6 +59,8 @@ private:
QAudioRecorder audioRecorder;
VoiceNoteRecordingState voiceNoteRecordingState;
void cleanUp();
};
#endif // FERNSCHREIBERUTILS_H

View file

@ -473,6 +473,30 @@ void TDLibWrapper::sendDocumentMessage(const QString &chatId, const QString &fil
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)
{
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 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 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

@ -1436,31 +1436,39 @@
<name>VoiceNoteOverlay</name>
<message>
<source>Record a Voice Note</source>
<translation type="unfinished"></translation>
<translation>Eine Sprachnachricht aufzeichnen</translation>
</message>
<message>
<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>
<source>Unavailable</source>
<translation type="unfinished"></translation>
<translation>Nicht verfügbar</translation>
</message>
<message>
<source>Stopped</source>
<translation type="unfinished"></translation>
<source>Ready</source>
<translation>Bereit</translation>
</message>
<message>
<source>Starting</source>
<translation type="unfinished"></translation>
<translation>Startet</translation>
</message>
<message>
<source>Recording</source>
<translation type="unfinished"></translation>
<translation>Zeichnet auf</translation>
</message>
<message>
<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>
</context>
<context>

View file

@ -1436,31 +1436,39 @@
<name>VoiceNoteOverlay</name>
<message>
<source>Record a Voice Note</source>
<translation type="unfinished"></translation>
<translation>Record a Voice Note</translation>
</message>
<message>
<source>Press the button to start recording</source>
<translation type="unfinished"></translation>
<translation>Press the button to start recording</translation>
</message>
<message>
<source>Unavailable</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Stopped</source>
<translation type="unfinished"></translation>
<translation>Unavailable</translation>
</message>
<message>
<source>Starting</source>
<translation type="unfinished"></translation>
<translation>Starting</translation>
</message>
<message>
<source>Recording</source>
<translation type="unfinished"></translation>
<translation>Recording</translation>
</message>
<message>
<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>
</context>
<context>

View file

@ -1425,10 +1425,6 @@
<source>Unavailable</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Stopped</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Starting</source>
<translation type="unfinished"></translation>
@ -1441,6 +1437,18 @@
<source>Stopping</source>
<translation type="unfinished"></translation>
</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>
<name>WebPagePreview</name>

View file

@ -1447,10 +1447,6 @@
<source>Unavailable</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Stopped</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Starting</source>
<translation type="unfinished"></translation>
@ -1463,6 +1459,18 @@
<source>Stopping</source>
<translation type="unfinished"></translation>
</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>
<name>WebPagePreview</name>

View file

@ -1425,10 +1425,6 @@
<source>Unavailable</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Stopped</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Starting</source>
<translation type="unfinished"></translation>
@ -1441,6 +1437,18 @@
<source>Stopping</source>
<translation type="unfinished"></translation>
</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>
<name>WebPagePreview</name>

View file

@ -1446,10 +1446,6 @@
<source>Unavailable</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Stopped</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Starting</source>
<translation type="unfinished"></translation>
@ -1462,6 +1458,18 @@
<source>Stopping</source>
<translation type="unfinished"></translation>
</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>
<name>WebPagePreview</name>

View file

@ -1467,10 +1467,6 @@
<source>Unavailable</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Stopped</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Starting</source>
<translation type="unfinished"></translation>
@ -1483,6 +1479,18 @@
<source>Stopping</source>
<translation type="unfinished"></translation>
</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>
<name>WebPagePreview</name>

View file

@ -1467,10 +1467,6 @@
<source>Unavailable</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Stopped</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Starting</source>
<translation type="unfinished"></translation>
@ -1483,6 +1479,18 @@
<source>Stopping</source>
<translation type="unfinished"></translation>
</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>
<name>WebPagePreview</name>

View file

@ -1446,10 +1446,6 @@
<source>Unavailable</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Stopped</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Starting</source>
<translation type="unfinished"></translation>
@ -1462,6 +1458,18 @@
<source>Stopping</source>
<translation type="unfinished"></translation>
</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>
<name>WebPagePreview</name>

View file

@ -1425,10 +1425,6 @@
<source>Unavailable</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Stopped</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Starting</source>
<translation type="unfinished"></translation>
@ -1441,6 +1437,18 @@
<source>Stopping</source>
<translation type="unfinished"></translation>
</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>
<name>WebPagePreview</name>

View file

@ -1446,10 +1446,6 @@
<source>Unavailable</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Stopped</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Starting</source>
<translation type="unfinished"></translation>
@ -1462,6 +1458,18 @@
<source>Stopping</source>
<translation type="unfinished"></translation>
</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>
<name>WebPagePreview</name>