Commit 8ffab8fd authored by Thomas BOUTROUE's avatar Thomas BOUTROUE

Implement message editing (text or caption)

parent 07089458
......@@ -20,6 +20,10 @@ DelegateAbstractMessageContent {
fileItem: (animationItem ? animationItem.animation : null);
autoDownload: true;
}
DelegateFormattedText {
formattedTextItem: captionItem;
ExtraAnchors.horizontalFill: parent;
}
Item {
id: placeholder;
implicitWidth: (animationItem ? Math.min (animationItem.width, self.width) : 1);
......
......@@ -75,6 +75,10 @@ ApplicationWindow {
PageStackAction.Immediate);
}
}
onEditTextRequested: {
Helpers.currentMsgType = TD_ObjectType.MESSAGE_TEXT;
btnSendMsg.textBox.text = (formattedText ? formattedText.text : "");
}
}
ShaderEffectSource {
id: maskAvatarCircle;
......@@ -700,6 +704,7 @@ ApplicationWindow {
RectangleButton {
active: selectorMsgType.visible;
rounded: false;
enabled: (TD_Global.editingMessageId === "");
icon: {
switch (Helpers.currentMsgType) {
case TD_ObjectType.MESSAGE_TEXT: return "icon-m-text-input";
......@@ -811,25 +816,30 @@ ApplicationWindow {
textBox.focus = false;
var tmp = textBox.text.trim ();
/// SEND
switch (Helpers.currentMsgType) {
case TD_ObjectType.MESSAGE_TEXT:
TD_Global.sendMessageText (TD_Global.currentChat, tmp);
break;
case TD_ObjectType.MESSAGE_PHOTO:
TD_Global.sendMessagePhoto (TD_Global.currentChat, (TD_Global.selectedPhotosCount > 0), tmp);
break;
case TD_ObjectType.MESSAGE_VIDEO:
TD_Global.sendMessageVideo (TD_Global.currentChat, (TD_Global.selectedVideosCount > 0), tmp);
break;
case TD_ObjectType.MESSAGE_DOCUMENT:
TD_Global.sendMessageDocument (TD_Global.currentChat, currentDocument, tmp);
break;
case TD_ObjectType.MESSAGE_VOICE_NOTE:
TD_Global.sendMessageVoiceNote (TD_Global.currentChat, currentRecording);
break;
case TD_ObjectType.MESSAGE_STICKER:
TD_Global.sendMessageSticker (TD_Global.currentChat, currentSticker);
break;
if (TD_Global.editingMessageId !== "") {
TD_Global.sendMessageEdit (TD_Global.currentChat, tmp);
}
else {
switch (Helpers.currentMsgType) {
case TD_ObjectType.MESSAGE_TEXT:
TD_Global.sendMessageText (TD_Global.currentChat, tmp);
break;
case TD_ObjectType.MESSAGE_PHOTO:
TD_Global.sendMessagePhoto (TD_Global.currentChat, (TD_Global.selectedPhotosCount > 0), tmp);
break;
case TD_ObjectType.MESSAGE_VIDEO:
TD_Global.sendMessageVideo (TD_Global.currentChat, (TD_Global.selectedVideosCount > 0), tmp);
break;
case TD_ObjectType.MESSAGE_DOCUMENT:
TD_Global.sendMessageDocument (TD_Global.currentChat, currentDocument, tmp);
break;
case TD_ObjectType.MESSAGE_VOICE_NOTE:
TD_Global.sendMessageVoiceNote (TD_Global.currentChat, currentRecording);
break;
case TD_ObjectType.MESSAGE_STICKER:
TD_Global.sendMessageSticker (TD_Global.currentChat, currentSticker);
break;
}
}
/// RESET
TD_Global.unselectAllPhotos ();
......
......@@ -57,6 +57,14 @@ Page {
? replyingToMessageRefWatcher.messageItem
: null);
readonly property TD_MessageRefWatcher editingMessageRefWatcher : (currentChat && TD_Global.editingMessageId !== ""
? currentChat.getMessageRefById (TD_Global.editingMessageId)
: null);
readonly property TD_Message editingToMessageItem : (editingMessageRefWatcher
? editingMessageRefWatcher.messageItem
: null);
readonly property TD_MessageRefWatcher pinnedMessageRefWatcher : (currentChatSupergroupItem && currentChatSupergroupItem.pinnedMessageId
? currentChat.getMessageRefById (currentChatSupergroupItem.pinnedMessageId)
: null);
......@@ -218,12 +226,27 @@ Page {
}
}
MenuItem {
text: qsTr ("Edit [TODO]");
visible: delegateMsg.messageItem.canBeEdited;
enabled: false;
text: (textItem
? qsTr ("Edit text")
: (captionItem
? qsTr ("Edit caption")
: ""));
visible: (delegateMsg.messageItem.canBeEdited && (textItem || captionItem));
onClicked: {
// TODO
TD_Global.editingMessageId = delegateMsg.messageItem.id;
TD_Global.editFormattedText (textItem || captionItem);
}
readonly property TD_FormattedText textItem : (delegateMsg.messageItem &&
delegateMsg.messageItem.content &&
"text" in delegateMsg.messageItem.content
? delegateMsg.messageItem.content ["text"]
: null);
readonly property TD_FormattedText captionItem : (delegateMsg.messageItem &&
delegateMsg.messageItem.content &&
"caption" in delegateMsg.messageItem.content
? delegateMsg.messageItem.content ["caption"]
: null);
}
MenuItem {
text: qsTr ("Delete only for me");
......@@ -815,6 +838,51 @@ Page {
}
}
}
Item {
id: stripEdit;
visible: (editingToMessageItem !== null);
implicitHeight: (layoutEdit.height + layoutEdit.anchors.margins * 2);
ExtraAnchors.horizontalFill: parent;
Rectangle {
color: Helpers.panelColor;
anchors.fill: parent;
Rectangle {
color: Theme.rgba (Theme.secondaryHighlightColor, 0.15);
anchors.fill: parent;
}
}
RowContainer {
id: layoutEdit;
spacing: Theme.paddingMedium;
anchors {
margins: Theme.paddingMedium;
verticalCenter: parent.verticalCenter;
}
ExtraAnchors.horizontalFill: parent;
LabelFixed {
text: qsTr ("<b>Edit</b>: %1").arg (editingToMessageItem ? editingToMessageItem.preview (TD_Message.SHOW_TITLE | TD_Message.MULTILINE).replace (/\n/g, "<br>") : qsTr ("<i>deleted message</i>"));
color: Theme.secondaryHighlightColor;
elide: Text.ElideRight;
wrapMode: Text.WrapAtWordBoundaryOrAnywhere;
textFormat: Text.StyledText;
maximumLineCount: 3;
font.pixelSize: Theme.fontSizeSmall;
anchors.verticalCenter: parent.verticalCenter;
Container.horizontalStretch: 1;
}
RectangleButton {
icon: "icon-m-clear";
anchors.verticalCenter: parent.verticalCenter;
onClicked: {
TD_Global.editFormattedText (null);
TD_Global.editingMessageId = "";
}
}
}
}
Item {
Container.forcedHeight: footerChat.height;
ExtraAnchors.horizontalFill: parent;
......
......@@ -14,7 +14,7 @@ Name: harbour-telegrame
%{?qtc_builddir:%define _builddir %qtc_builddir}
Summary: A native Telegram client for Sailfish OS
Version: 0.9
Release: 13
Release: 15
Group: Qt/Qt
License: WTFPL
URL: http://gitlab.unique-conception.org/sailfish-app/telegra-me
......
Name: harbour-telegrame
Summary: A native Telegram client for Sailfish OS
Version: 0.9
Release: 13
Release: 15
Group: Qt/Qt
URL: http://gitlab.unique-conception.org/sailfish-app/telegra-me
......
......@@ -353,6 +353,7 @@ void QtTdLibGlobal::closeChat (QtTdLibChat * chatItem) {
chatItem->set_hasReachedFirst (false); // NOTE : reset start flag
chatItem->set_hasReachedLast (false); // NOTE : reset end flag
chatItem->set_isCurrentChat (false);
set_editingMessageId ("");
set_replyingToMessageId ("");
set_currentMessageContent (Q_NULLPTR);
set_currentChat (Q_NULLPTR);
......@@ -553,7 +554,6 @@ QJsonValue QtTdLibGlobal::createFormattedTextJson (const QString & text) {
}
void QtTdLibGlobal::sendMessageText (QtTdLibChat * chatItem, const QString & text) {
qWarning () << "sendMessageText" << chatItem << text;
if (chatItem != Q_NULLPTR && !text.isEmpty ()) {
send (QJsonObject {
{ "@type", "sendMessage" },
......@@ -574,6 +574,47 @@ void QtTdLibGlobal::sendMessageText (QtTdLibChat * chatItem, const QString & tex
set_replyingToMessageId ("");
}
void QtTdLibGlobal::sendMessageEdit (QtTdLibChat * chatItem, const QString & text) {
if (chatItem != Q_NULLPTR && !text.isEmpty ()) {
if (QtTdLibMessage * messageItem = { chatItem->getMessageItemById (m_editingMessageId) }) {
switch (messageItem->get_content ()->get_typeOf ()) {
case QtTdLibObjectType::MESSAGE_TEXT: {
send (QJsonObject {
{ "@type", "editMessageText" },
{ "chat_id" , chatItem->get_id_asJSON () },
{ "message_id", messageItem->get_id_asJSON () },
{ "reply_markup", QJsonValue::Null },
{ "input_message_content", QJsonObject {
{ "@type", "inputMessageText" },
{ "disable_web_page_preview", false },
{ "clear_draft", false },
{ "text", createFormattedTextJson (text) },
}
}
});
break;
}
case QtTdLibObjectType::MESSAGE_PHOTO:
case QtTdLibObjectType::MESSAGE_AUDIO:
case QtTdLibObjectType::MESSAGE_VIDEO:
case QtTdLibObjectType::MESSAGE_DOCUMENT:
case QtTdLibObjectType::MESSAGE_ANIMATION:
case QtTdLibObjectType::MESSAGE_VOICE_NOTE: {
send (QJsonObject {
{ "@type", "editMessageCaption" },
{ "chat_id" , chatItem->get_id_asJSON () },
{ "message_id", messageItem->get_id_asJSON () },
{ "reply_markup", QJsonValue::Null },
{ "caption", createFormattedTextJson (text) },
});
break;
}
}
}
}
set_editingMessageId (QString { });
}
void QtTdLibGlobal::sendMessagePhoto (QtTdLibChat * chatItem, const bool groupInAlbum, const QString & caption) {
if (chatItem != Q_NULLPTR && !m_selectedPhotosList.isEmpty ()) {
if (groupInAlbum) {
......@@ -794,6 +835,10 @@ void QtTdLibGlobal::removeRecording (const QString & path) {
QFile::remove (path);
}
void QtTdLibGlobal::editFormattedText (QtTdLibFormattedText * formattedText) {
emit editTextRequested (formattedText);
}
void QtTdLibGlobal::onFrame (const QJsonObject & json) {
switch (QtTdLibEnums::objectTypeEnumFromJson (json)) {
case QtTdLibObjectType::UPDATE_AUTHORIZATION_STATE: {
......
......@@ -45,6 +45,7 @@ class QtTdLibGlobal : public QObject {
QML_CONSTANT_PTR_PROPERTY (sortedContactsList, QSortFilterProxyModel)
QML_WRITABLE_VAR_PROPERTY (sendTextOnEnterKey, bool)
QML_WRITABLE_CSTREF_PROPERTY (replyingToMessageId, QString)
QML_WRITABLE_CSTREF_PROPERTY (editingMessageId, QString)
public:
explicit QtTdLibGlobal (QObject * parent = Q_NULLPTR);
......@@ -124,8 +125,13 @@ public:
Q_INVOKABLE QString stopRecordingAudio (void);
Q_INVOKABLE void removeRecording (const QString & path);
Q_INVOKABLE void editFormattedText (QtTdLibFormattedText * formattedText);
Q_INVOKABLE void sendMessageEdit (QtTdLibChat * chatItem, const QString & text);
signals:
void showChatRequested (QtTdLibChat * chatItem);
void editTextRequested (QtTdLibFormattedText * formattedText);
protected slots:
void onFrame (const QJsonObject & json);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment