Initial steps to upload videos and documents

This commit is contained in:
Sebastian J. Wolf 2020-09-27 23:24:22 +02:00
parent c9810ea194
commit 30f208d9fb
3 changed files with 119 additions and 4 deletions

View file

@ -21,6 +21,7 @@ import QtGraphicalEffects 1.0
import QtMultimedia 5.0 import QtMultimedia 5.0
import Sailfish.Silica 1.0 import Sailfish.Silica 1.0
import Sailfish.Pickers 1.0 import Sailfish.Pickers 1.0
import Nemo.Thumbnailer 1.0
import WerkWolf.Fernschreiber 1.0 import WerkWolf.Fernschreiber 1.0
import "../components" import "../components"
import "../js/twemoji.js" as Emoji import "../js/twemoji.js" as Emoji
@ -130,6 +131,8 @@ Page {
function clearAttachmentPreviewRow() { function clearAttachmentPreviewRow() {
attachmentPreviewRow.visible = false; attachmentPreviewRow.visible = false;
attachmentPreviewRow.isPicture = false; attachmentPreviewRow.isPicture = false;
attachmentPreviewRow.isVideo = false;
attachmentPreviewRow.isDocument = false;
attachmentPreviewRow.filePath = ""; attachmentPreviewRow.filePath = "";
} }
@ -141,6 +144,12 @@ Page {
if (attachmentPreviewRow.isPicture) { if (attachmentPreviewRow.isPicture) {
tdLibWrapper.sendPhotoMessage(chatInformation.id, attachmentPreviewRow.filePath, newMessageTextField.text, newMessageColumn.replyToMessageId); 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(); clearAttachmentPreviewRow();
} else { } else {
tdLibWrapper.sendTextMessage(chatInformation.id, newMessageTextField.text, newMessageColumn.replyToMessageId); 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 { InReplyToRow {
onInReplyToMessageChanged: { onInReplyToMessageChanged: {
if (inReplyToMessage) { if (inReplyToMessage) {
@ -855,6 +890,21 @@ Page {
id: attachmentOptionsRow id: attachmentOptionsRow
visible: false visible: false
anchors.right: parent.right 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 { IconButton {
id: imageAttachmentButton id: imageAttachmentButton
icon.source: "image://theme/icon-m-image" icon.source: "image://theme/icon-m-image"
@ -871,19 +921,34 @@ Page {
anchors.right: parent.right anchors.right: parent.right
property bool isPicture: false; property bool isPicture: false;
property bool isVideo: false;
property bool isDocument: false;
property string filePath: ""; property string filePath: "";
Image { Thumbnail {
id: attachmentPreviewImage id: attachmentPreviewImage
width: Theme.itemSizeMedium width: Theme.itemSizeMedium
height: Theme.itemSizeMedium height: Theme.itemSizeMedium
sourceSize.width: width
sourceSize.height: height
fillMode: Image.PreserveAspectCrop fillMode: Thumbnail.PreserveAspectCrop
autoTransform: true
asynchronous: true
source: attachmentPreviewRow.filePath 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 visible: attachmentPreviewRow.isPicture
} }
IconButton { IconButton {
id: removeAttachmentsIconButton id: removeAttachmentsIconButton
icon.source: "image://theme/icon-m-clear" icon.source: "image://theme/icon-m-clear"

View file

@ -252,6 +252,54 @@ void TDLibWrapper::sendPhotoMessage(const QString &chatId, const QString &filePa
this->sendRequest(requestObject); 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) void TDLibWrapper::getMessage(const QString &chatId, const QString &messageId)
{ {
qDebug() << "[TDLibWrapper] Retrieving message " << chatId << messageId; qDebug() << "[TDLibWrapper] Retrieving message " << chatId << messageId;

View file

@ -92,6 +92,8 @@ public:
Q_INVOKABLE void viewMessage(const QString &chatId, const QString &messageId); 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 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 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 getMessage(const QString &chatId, const QString &messageId);
Q_INVOKABLE void setOptionInteger(const QString &optionName, const int &optionValue); Q_INVOKABLE void setOptionInteger(const QString &optionName, const int &optionValue);
Q_INVOKABLE void setChatNotificationSettings(const QString &chatId, const QVariantMap &notificationSettings); Q_INVOKABLE void setChatNotificationSettings(const QString &chatId, const QVariantMap &notificationSettings);