Fix UI allowing edits of foreign messages in some cases

This commit is contained in:
Nicolas Werner 2021-02-10 14:32:16 +01:00
parent 4a5b5f992d
commit a62276c289
6 changed files with 20 additions and 12 deletions

View file

@ -310,7 +310,7 @@ Rectangle {
ToolTip.text: qsTr("Emoji")
onClicked: emojiPopup.visible ? emojiPopup.close() : emojiPopup.show(emojiButton, function(emoji) {
messageInput.insert(messageInput.cursorPosition, emoji);
TimelineManager.focusMessageInput()
TimelineManager.focusMessageInput();
})
}

View file

@ -73,7 +73,9 @@ ListView {
Shortcut {
sequence: "Ctrl+E"
onActivated: chat.model.edit = chat.model.reply
onActivated: {
chat.model.edit = chat.model.reply;
}
}
Component {

View file

@ -26,12 +26,12 @@ Item {
acceptedButtons: Qt.AllButtons
onClicked: {
if (mouse.button === Qt.RightButton)
messageContextMenu.show(model.id, model.type, model.isEncrypted, row);
messageContextMenu.show(model.id, model.type, model.isEncrypted, model.isEditable, row);
else
mouse.accepted = false;
}
onPressAndHold: {
messageContextMenu.show(model.id, model.type, model.isEncrypted, row, mapToItem(timelineRoot, mouse.x, mouse.y));
messageContextMenu.show(model.id, model.type, model.isEncrypted, model.isEditable, row, mapToItem(timelineRoot, mouse.x, mouse.y));
}
}
@ -143,7 +143,7 @@ Item {
image: ":/icons/icons/ui/vertical-ellipsis.png"
ToolTip.visible: hovered
ToolTip.text: qsTr("Options")
onClicked: messageContextMenu.show(model.id, model.type, model.isEncrypted, optionsButton)
onClicked: messageContextMenu.show(model.id, model.type, model.isEncrypted, model.isEditable, optionsButton)
}
Label {

View file

@ -66,11 +66,13 @@ Page {
property string eventId
property int eventType
property bool isEncrypted
property bool isEditable
function show(eventId_, eventType_, isEncrypted_, showAt_, position) {
function show(eventId_, eventType_, isEncrypted_, isEditable_, showAt_, position) {
eventId = eventId_;
eventType = eventType_;
isEncrypted = isEncrypted_;
isEditable = isEditable_;
if (position)
popup(position, showAt_);
else
@ -92,6 +94,8 @@ Page {
}
MenuItem {
visible: messageContextMenu.isEditable
height: visible ? implicitHeight : 0
text: qsTr("Edit")
onClicked: TimelineManager.timeline.editAction(messageContextMenu.eventId)
}

View file

@ -14,6 +14,6 @@ ImageButton {
image: ":/icons/icons/ui/smile.png"
onClicked: emojiPicker.visible ? emojiPicker.close() : emojiPicker.show(emojiButton, function(emoji) {
TimelineManager.queueReactionMessage(event_id, emoji);
TimelineManager.focusMessageInput()
TimelineManager.focusMessageInput();
})
}

View file

@ -1537,11 +1537,11 @@ void
TimelineModel::setEdit(QString newEdit)
{
if (edit_ != newEdit) {
auto ev = events.get(newEdit.toStdString(), "");
if (ev && mtx::accessors::sender(*ev) == http::client()->user_id().to_string()) {
edit_ = newEdit;
emit editChanged(edit_);
auto ev = events.get(newEdit.toStdString(), "");
if (ev) {
setReply(QString::fromStdString(
mtx::accessors::relations(*ev).reply_to().value_or("")));
@ -1555,6 +1555,8 @@ TimelineModel::setEdit(QString newEdit)
input()->setText("");
}
} else {
edit_ = "";
emit editChanged(edit_);
input()->setText("");
}
}