Don't show Reply menu item if the message can't be replied to

Also moved the handling of the Edit action to the chat page where
it's actually being handled.
This commit is contained in:
Slava Monich 2020-12-15 20:15:12 +02:00
parent f6d72d8ef1
commit aee027219a
2 changed files with 22 additions and 11 deletions

View file

@ -28,6 +28,7 @@ ListItem {
property var chatId
property var messageId
property var myMessage
property bool canReplyToMessage
readonly property var userInformation: tdLibWrapper.getUserInformation(myMessage.sender_user_id)
property QtObject precalculatedValues: ListView.view.precalculatedValues
readonly property color textColor: isOwnMessage ? Theme.highlightColor : Theme.primaryColor
@ -42,6 +43,9 @@ ListItem {
highlighted: (down || isSelected) && !menuOpen
openMenuOnPressAndHold: !messageListItem.precalculatedValues.pageIsSelecting
signal replyToMessage()
signal editMessage()
onClicked: {
if(messageListItem.precalculatedValues.pageIsSelecting) {
page.toggleMessageSelection(myMessage);
@ -88,20 +92,14 @@ ListItem {
}
MenuItem {
onClicked: {
newMessageInReplyToRow.inReplyToMessage = myMessage;
newMessageTextField.focus = true;
}
visible: messageListItem.canReplyToMessage
onClicked: messageListItem.replyToMessage()
text: qsTr("Reply to Message")
}
MenuItem {
onClicked: {
newMessageColumn.editMessageId = messageId;
newMessageTextField.text = Functions.getMessageText(myMessage, false, false, true);
newMessageTextField.focus = true;
}
text: qsTr("Edit Message")
visible: myMessage.can_be_edited
onClicked: messageListItem.editMessage()
text: qsTr("Edit Message")
}
MenuItem {
onClicked: {

View file

@ -58,6 +58,8 @@ Page {
)
property var selectedMessages: []
readonly property bool isSelecting: selectedMessages.length > 0
readonly property bool canSendMessages: hasSendPrivilege("can_send_messages")
states: [
State {
name: "selectMessages"
@ -77,6 +79,7 @@ Page {
}
]
function toggleMessageSelection(message) {
var selectionArray = selectedMessages;
var foundIndex = -1
@ -923,6 +926,16 @@ Page {
myMessage: model.display
messageId: model.message_id
extraContentComponentName: chatView.contentComponentNames[model.content_type]
canReplyToMessage: chatPage.canSendMessages
onReplyToMessage: {
newMessageInReplyToRow.inReplyToMessage = myMessage
newMessageTextField.focus = true
}
onEditMessage: {
newMessageColumn.editMessageId = messageId
newMessageTextField.text = Functions.getMessageText(myMessage, false, false, true)
newMessageTextField.focus = true
}
}
}
Component {
@ -1048,7 +1061,7 @@ Page {
height: isNeeded ? implicitHeight : 0
Behavior on height { SmoothedAnimation { duration: 200 } }
readonly property bool isNeeded: !chatPage.isSelecting && chatPage.hasSendPrivilege("can_send_messages")
readonly property bool isNeeded: !chatPage.isSelecting && chatPage.canSendMessages
property string replyToMessageId: "0";
property string editMessageId: "0";