From 30f208d9fbe146051facc1c314f2abad8431bb56 Mon Sep 17 00:00:00 2001 From: "Sebastian J. Wolf" Date: Sun, 27 Sep 2020 23:24:22 +0200 Subject: [PATCH] Initial steps to upload videos and documents --- qml/pages/ChatPage.qml | 73 +++++++++++++++++++++++++++++++++++++++--- src/tdlibwrapper.cpp | 48 +++++++++++++++++++++++++++ src/tdlibwrapper.h | 2 ++ 3 files changed, 119 insertions(+), 4 deletions(-) diff --git a/qml/pages/ChatPage.qml b/qml/pages/ChatPage.qml index 41691f5..d898247 100644 --- a/qml/pages/ChatPage.qml +++ b/qml/pages/ChatPage.qml @@ -21,6 +21,7 @@ import QtGraphicalEffects 1.0 import QtMultimedia 5.0 import Sailfish.Silica 1.0 import Sailfish.Pickers 1.0 +import Nemo.Thumbnailer 1.0 import WerkWolf.Fernschreiber 1.0 import "../components" import "../js/twemoji.js" as Emoji @@ -130,6 +131,8 @@ Page { function clearAttachmentPreviewRow() { attachmentPreviewRow.visible = false; attachmentPreviewRow.isPicture = false; + attachmentPreviewRow.isVideo = false; + attachmentPreviewRow.isDocument = false; attachmentPreviewRow.filePath = ""; } @@ -141,6 +144,12 @@ Page { if (attachmentPreviewRow.isPicture) { tdLibWrapper.sendPhotoMessage(chatInformation.id, attachmentPreviewRow.filePath, newMessageTextField.text, newMessageColumn.replyToMessageId); } + if (attachmentPreviewRow.isVideo) { + tdLibWrapper.sendVideoMessage(chatInformation.id, attachmentPreviewRow.filePath, newMessageTextField.text, newMessageColumn.replyToMessageId); + } + if (attachmentPreviewRow.isDocument) { + tdLibWrapper.sendDocumentMessage(chatInformation.id, attachmentPreviewRow.filePath, newMessageTextField.text, newMessageColumn.replyToMessageId); + } clearAttachmentPreviewRow(); } else { tdLibWrapper.sendTextMessage(chatInformation.id, newMessageTextField.text, newMessageColumn.replyToMessageId); @@ -834,6 +843,32 @@ Page { } } + Component { + id: videoPickerPage + VideoPickerPage { + onSelectedContentPropertiesChanged: { + attachmentOptionsRow.visible = false; + console.log("Selected video: " + selectedContentProperties.filePath ); + attachmentPreviewRow.filePath = selectedContentProperties.filePath; + attachmentPreviewRow.isVideo = true; + attachmentPreviewRow.visible = true; + } + } + } + + Component { + id: documentPickerPage + DocumentPickerPage { + onSelectedContentPropertiesChanged: { + attachmentOptionsRow.visible = false; + console.log("Selected document: " + selectedContentProperties.filePath ); + attachmentPreviewRow.filePath = selectedContentProperties.filePath; + attachmentPreviewRow.isDocument = true; + attachmentPreviewRow.visible = true; + } + } + } + InReplyToRow { onInReplyToMessageChanged: { if (inReplyToMessage) { @@ -855,6 +890,21 @@ Page { id: attachmentOptionsRow visible: false anchors.right: parent.right + spacing: Theme.paddingMedium + IconButton { + id: documentAttachmentButton + icon.source: "image://theme/icon-m-document" + onClicked: { + pageStack.push(documentPickerPage); + } + } + IconButton { + id: videoAttachmentButton + icon.source: "image://theme/icon-m-video" + onClicked: { + pageStack.push(videoPickerPage); + } + } IconButton { id: imageAttachmentButton icon.source: "image://theme/icon-m-image" @@ -871,19 +921,34 @@ Page { anchors.right: parent.right property bool isPicture: false; + property bool isVideo: false; + property bool isDocument: false; property string filePath: ""; - Image { + Thumbnail { id: attachmentPreviewImage width: Theme.itemSizeMedium height: Theme.itemSizeMedium + sourceSize.width: width + sourceSize.height: height - fillMode: Image.PreserveAspectCrop - autoTransform: true - asynchronous: true + fillMode: Thumbnail.PreserveAspectCrop source: attachmentPreviewRow.filePath + visible: attachmentPreviewRow.isPicture || attachmentPreviewRow.isVideo + } + + Text { + width: parent.width - Theme.paddingMedium - removeAttachmentsIconButton.width + + id: attachmentPreviewText + font.pixelSize: Theme.fontSizeSmall + text: attachmentPreviewRow.filePath; + maximumLineCount: 1 + elide: Text.ElideRight + color: Theme.secondaryColor visible: attachmentPreviewRow.isPicture } + IconButton { id: removeAttachmentsIconButton icon.source: "image://theme/icon-m-clear" diff --git a/src/tdlibwrapper.cpp b/src/tdlibwrapper.cpp index 1d094a1..80efde8 100644 --- a/src/tdlibwrapper.cpp +++ b/src/tdlibwrapper.cpp @@ -252,6 +252,54 @@ void TDLibWrapper::sendPhotoMessage(const QString &chatId, const QString &filePa this->sendRequest(requestObject); } +void TDLibWrapper::sendVideoMessage(const QString &chatId, const QString &filePath, const QString &message, const QString &replyToMessageId) +{ + qDebug() << "[TDLibWrapper] Sending video 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", "inputMessageVideo"); + QVariantMap formattedText; + formattedText.insert("text", message); + formattedText.insert("@type", "formattedText"); + inputMessageContent.insert("caption", formattedText); + QVariantMap videoInputFile; + videoInputFile.insert("@type", "inputFileLocal"); + videoInputFile.insert("path", filePath); + inputMessageContent.insert("video", videoInputFile); + + requestObject.insert("input_message_content", inputMessageContent); + this->sendRequest(requestObject); +} + +void TDLibWrapper::sendDocumentMessage(const QString &chatId, const QString &filePath, const QString &message, const QString &replyToMessageId) +{ + qDebug() << "[TDLibWrapper] Sending document 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", "inputMessageDocument"); + 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("document", documentInputFile); + + requestObject.insert("input_message_content", inputMessageContent); + this->sendRequest(requestObject); +} + void TDLibWrapper::getMessage(const QString &chatId, const QString &messageId) { qDebug() << "[TDLibWrapper] Retrieving message " << chatId << messageId; diff --git a/src/tdlibwrapper.h b/src/tdlibwrapper.h index 4c627f3..bb4c233 100644 --- a/src/tdlibwrapper.h +++ b/src/tdlibwrapper.h @@ -92,6 +92,8 @@ public: Q_INVOKABLE void viewMessage(const QString &chatId, const QString &messageId); Q_INVOKABLE void sendTextMessage(const QString &chatId, 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 sendDocumentMessage(const QString &chatId, const QString &filePath, const QString &message, const QString &replyToMessageId = "0"); Q_INVOKABLE void getMessage(const QString &chatId, const QString &messageId); Q_INVOKABLE void setOptionInteger(const QString &optionName, const int &optionValue); Q_INVOKABLE void setChatNotificationSettings(const QString &chatId, const QVariantMap ¬ificationSettings);