Enable image attachments :)

This commit is contained in:
Sebastian J. Wolf 2020-09-27 13:49:06 +02:00
parent a5c2b34a86
commit ad1cec1dfb
4 changed files with 113 additions and 14 deletions

View file

@ -42,7 +42,6 @@ DISTFILES += qml/harbour-fernschreiber.qml \
qml/pages/SettingsPage.qml \ qml/pages/SettingsPage.qml \
qml/pages/VideoPage.qml \ qml/pages/VideoPage.qml \
rpm/harbour-fernschreiber.changes.in \ rpm/harbour-fernschreiber.changes.in \
rpm/harbour-fernschreiber.changes.run.in \
rpm/harbour-fernschreiber.spec \ rpm/harbour-fernschreiber.spec \
rpm/harbour-fernschreiber.yaml \ rpm/harbour-fernschreiber.yaml \
translations/*.ts \ translations/*.ts \
@ -57,7 +56,7 @@ TRANSLATIONS += translations/harbour-fernschreiber-de.ts \
translations/harbour-fernschreiber-zh_CN.ts translations/harbour-fernschreiber-zh_CN.ts
# Use armv7hl for most devices and i486 for emulator and Jolla Tablet. Can most certainly be automated... ;) # Use armv7hl for most devices and i486 for emulator and Jolla Tablet. Can most certainly be automated... ;)
TARGET_ARCHITECTURE = i486 TARGET_ARCHITECTURE = armv7hl
INCLUDEPATH += $$PWD/tdlib/include INCLUDEPATH += $$PWD/tdlib/include
DEPENDPATH += $$PWD/tdlib/include DEPENDPATH += $$PWD/tdlib/include

View file

@ -20,6 +20,7 @@ import QtQuick 2.5
import QtGraphicalEffects 1.0 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 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
@ -126,6 +127,27 @@ Page {
return Functions.getDateTimeElapsed(message.date) + messageStatusSuffix; return Functions.getDateTimeElapsed(message.date) + messageStatusSuffix;
} }
function clearAttachmentPreviewRow() {
attachmentPreviewRow.visible = false;
attachmentPreviewRow.isPicture = false;
attachmentPreviewRow.filePath = "";
}
function sendMessage() {
if (newMessageColumn.editMessageId !== "0") {
tdLibWrapper.editMessageText(chatInformation.id, newMessageColumn.editMessageId, newMessageTextField.text);
} else {
if (attachmentPreviewRow.visible) {
if (attachmentPreviewRow.isPicture) {
tdLibWrapper.sendPhotoMessage(chatInformation.id, attachmentPreviewRow.filePath, newMessageTextField.text, newMessageColumn.replyToMessageId);
}
clearAttachmentPreviewRow();
} else {
tdLibWrapper.sendTextMessage(chatInformation.id, newMessageTextField.text, newMessageColumn.replyToMessageId);
}
}
}
Component.onCompleted: { Component.onCompleted: {
initializePage(); initializePage();
} }
@ -799,6 +821,19 @@ Page {
property string replyToMessageId: "0"; property string replyToMessageId: "0";
property string editMessageId: "0"; property string editMessageId: "0";
Component {
id: imagePickerPage
ImagePickerPage {
onSelectedContentPropertiesChanged: {
attachmentOptionsRow.visible = false;
console.log("Selected photo: " + selectedContentProperties.filePath );
attachmentPreviewRow.filePath = selectedContentProperties.filePath;
attachmentPreviewRow.isPicture = true;
attachmentPreviewRow.visible = true;
}
}
}
InReplyToRow { InReplyToRow {
onInReplyToMessageChanged: { onInReplyToMessageChanged: {
if (inReplyToMessage) { if (inReplyToMessage) {
@ -816,6 +851,48 @@ Page {
visible: false visible: false
} }
Row {
id: attachmentOptionsRow
visible: false
anchors.right: parent.right
IconButton {
id: imageAttachmentButton
icon.source: "image://theme/icon-m-image"
onClicked: {
pageStack.push(imagePickerPage);
}
}
}
Row {
id: attachmentPreviewRow
visible: false
spacing: Theme.paddingMedium
anchors.right: parent.right
property bool isPicture: false;
property string filePath: "";
Image {
id: attachmentPreviewImage
width: Theme.itemSizeMedium
height: Theme.itemSizeMedium
fillMode: Image.PreserveAspectCrop
autoTransform: true
asynchronous: true
source: attachmentPreviewRow.filePath
visible: attachmentPreviewRow.isPicture
}
IconButton {
id: removeAttachmentsIconButton
icon.source: "image://theme/icon-m-clear"
onClicked: {
clearAttachmentPreviewRow();
}
}
}
Text { Text {
width: parent.width width: parent.width
@ -854,11 +931,7 @@ Page {
} }
EnterKey.onClicked: { EnterKey.onClicked: {
if (tdLibWrapper.getSendByEnter()) { if (tdLibWrapper.getSendByEnter()) {
if (newMessageColumn.editMessageId !== "0") { sendMessage();
tdLibWrapper.editMessageText(chatInformation.id, newMessageColumn.editMessageId, newMessageTextField.text);
} else {
tdLibWrapper.sendTextMessage(chatInformation.id, newMessageTextField.text, newMessageColumn.replyToMessageId);
}
newMessageTextField.text = ""; newMessageTextField.text = "";
newMessageTextField.focus = false; newMessageTextField.focus = false;
} }
@ -888,11 +961,17 @@ Page {
IconButton { IconButton {
id: attachmentIconButton id: attachmentIconButton
icon.source: "image://theme/icon-m-attach" icon.source: attachmentOptionsRow.visible ? "image://theme/icon-m-attach?" + Theme.highlightColor : "image://theme/icon-m-attach?" + Theme.primaryColor
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.bottomMargin: Theme.paddingSmall anchors.bottomMargin: Theme.paddingSmall
enabled: !attachmentPreviewRow.visible
onClicked: { onClicked: {
if (attachmentOptionsRow.visible) {
attachmentOptionsRow.visible = false;
} else {
attachmentOptionsRow.visible = true;
}
} }
} }
@ -903,11 +982,7 @@ Page {
anchors.bottomMargin: Theme.paddingSmall anchors.bottomMargin: Theme.paddingSmall
enabled: false enabled: false
onClicked: { onClicked: {
if (newMessageColumn.editMessageId !== "0") { sendMessage();
tdLibWrapper.editMessageText(chatInformation.id, newMessageColumn.editMessageId, newMessageTextField.text);
} else {
tdLibWrapper.sendTextMessage(chatInformation.id, newMessageTextField.text, newMessageColumn.replyToMessageId);
}
newMessageTextField.text = ""; newMessageTextField.text = "";
newMessageTextField.focus = false; newMessageTextField.focus = false;
} }

View file

@ -228,6 +228,30 @@ void TDLibWrapper::sendTextMessage(const QString &chatId, const QString &message
this->sendRequest(requestObject); this->sendRequest(requestObject);
} }
void TDLibWrapper::sendPhotoMessage(const QString &chatId, const QString &filePath, const QString &message, const QString &replyToMessageId)
{
qDebug() << "[TDLibWrapper] Sending photo 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", "inputMessagePhoto");
QVariantMap formattedText;
formattedText.insert("text", message);
formattedText.insert("@type", "formattedText");
inputMessageContent.insert("caption", formattedText);
QVariantMap photoInputFile;
photoInputFile.insert("@type", "inputFileLocal");
photoInputFile.insert("path", filePath);
inputMessageContent.insert("photo", photoInputFile);
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

@ -91,6 +91,7 @@ public:
Q_INVOKABLE void getChatHistory(const QString &chatId, const qlonglong &fromMessageId = 0, const int &offset = 0, const int &limit = 50, const bool &onlyLocal = false); Q_INVOKABLE void getChatHistory(const QString &chatId, const qlonglong &fromMessageId = 0, const int &offset = 0, const int &limit = 50, const bool &onlyLocal = false);
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 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);