2020-08-03 17:17:03 +00:00
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Controls 2.3
|
|
|
|
import QtQuick.Layouts 1.3
|
|
|
|
import QtQml.Models 2.3
|
|
|
|
import "../../../../imports"
|
|
|
|
import "../../../../shared"
|
2020-09-22 14:45:09 +00:00
|
|
|
import "../../../../shared/status"
|
2020-08-03 17:17:03 +00:00
|
|
|
import "./"
|
|
|
|
|
|
|
|
PopupMenu {
|
2021-07-16 15:02:47 +00:00
|
|
|
id: messageContextMenu
|
|
|
|
width: messageContextMenu.isProfile ? profileHeader.width : emojiContainer.width
|
2021-07-22 07:47:15 +00:00
|
|
|
closePolicy: Popup.CloseOnPressOutside | Popup.CloseOnEscape
|
2021-07-16 15:02:47 +00:00
|
|
|
|
2021-05-25 19:34:46 +00:00
|
|
|
property string messageId
|
2020-08-03 17:17:03 +00:00
|
|
|
property bool isProfile: false
|
2020-08-27 23:26:12 +00:00
|
|
|
property bool isSticker: false
|
2020-12-08 12:34:02 +00:00
|
|
|
property bool emojiOnly: false
|
2021-05-25 19:34:46 +00:00
|
|
|
property bool hideEmojiPicker: false
|
|
|
|
property bool pinnedMessage: false
|
2021-07-22 07:47:15 +00:00
|
|
|
property bool showJumpTo: false
|
2021-06-29 14:49:32 +00:00
|
|
|
property bool isText: false
|
|
|
|
property bool isCurrentUser: false
|
2021-02-23 10:18:09 +00:00
|
|
|
property string linkUrls: ""
|
2021-02-01 21:29:35 +00:00
|
|
|
property alias emojiContainer: emojiContainer
|
2020-10-02 13:02:56 +00:00
|
|
|
property var identicon: ""
|
|
|
|
property var userName: ""
|
|
|
|
property string nickname: ""
|
|
|
|
property var fromAuthor: ""
|
|
|
|
property var text: ""
|
2021-02-01 20:37:50 +00:00
|
|
|
property var emojiReactionsReactedByUser: []
|
2021-06-29 14:49:32 +00:00
|
|
|
property var onClickEdit: function(){}
|
2021-07-16 15:02:47 +00:00
|
|
|
property var reactionModel
|
2021-06-29 14:49:32 +00:00
|
|
|
|
2021-07-22 07:47:15 +00:00
|
|
|
signal closeParentPopup
|
|
|
|
|
2021-07-16 15:02:47 +00:00
|
|
|
subMenuIcons: [{
|
2021-02-23 10:18:09 +00:00
|
|
|
source: Qt.resolvedUrl("../../../../shared/img/copy-to-clipboard-icon"),
|
|
|
|
width: 16,
|
|
|
|
height: 16
|
2021-07-16 15:02:47 +00:00
|
|
|
}]
|
2020-10-02 13:02:56 +00:00
|
|
|
|
2021-02-01 20:37:50 +00:00
|
|
|
function show(userNameParam, fromAuthorParam, identiconParam, textParam, nicknameParam, emojiReactionsModel) {
|
2020-10-02 13:02:56 +00:00
|
|
|
userName = userNameParam || ""
|
|
|
|
nickname = nicknameParam || ""
|
|
|
|
fromAuthor = fromAuthorParam || ""
|
|
|
|
identicon = identiconParam || ""
|
|
|
|
text = textParam || ""
|
2021-02-01 20:37:50 +00:00
|
|
|
let newEmojiReactions = []
|
|
|
|
if (!!emojiReactionsModel) {
|
|
|
|
emojiReactionsModel.forEach(function (emojiReaction) {
|
|
|
|
newEmojiReactions[emojiReaction.emojiId] = emojiReaction.currentUserReacted
|
|
|
|
})
|
|
|
|
}
|
2021-07-16 15:02:47 +00:00
|
|
|
emojiReactionsReactedByUser = newEmojiReactions;
|
2021-02-01 20:37:50 +00:00
|
|
|
|
2021-02-23 10:18:09 +00:00
|
|
|
const numLinkUrls = messageContextMenu.linkUrls.split(" ").length
|
|
|
|
copyLinkMenu.enabled = numLinkUrls > 1
|
2021-03-17 12:41:24 +00:00
|
|
|
copyLinkAction.enabled = !!messageContextMenu.linkUrls && numLinkUrls === 1 && !emojiOnly && !messageContextMenu.isProfile
|
2021-07-22 07:47:15 +00:00
|
|
|
popup()
|
2020-10-02 13:02:56 +00:00
|
|
|
}
|
|
|
|
|
2020-08-03 17:17:03 +00:00
|
|
|
Item {
|
|
|
|
id: emojiContainer
|
|
|
|
width: emojiRow.width
|
|
|
|
height: visible ? emojiRow.height : 0
|
2021-07-16 15:02:47 +00:00
|
|
|
visible: !hideEmojiPicker && (messageContextMenu.emojiOnly || !messageContextMenu.isProfile)
|
2020-08-03 17:17:03 +00:00
|
|
|
Row {
|
|
|
|
id: emojiRow
|
|
|
|
spacing: Style.current.smallPadding
|
|
|
|
leftPadding: Style.current.smallPadding
|
|
|
|
rightPadding: Style.current.smallPadding
|
2020-12-08 12:34:02 +00:00
|
|
|
bottomPadding: messageContextMenu.emojiOnly ? 0 : Style.current.padding
|
2020-08-03 17:17:03 +00:00
|
|
|
|
|
|
|
Repeater {
|
|
|
|
model: reactionModel
|
|
|
|
delegate: EmojiReaction {
|
|
|
|
source: "../../../img/" + filename
|
|
|
|
emojiId: model.emojiId
|
2021-02-01 20:37:50 +00:00
|
|
|
reactedByUser: !!messageContextMenu.emojiReactionsReactedByUser[model.emojiId]
|
2020-08-12 17:58:19 +00:00
|
|
|
closeModal: function () {
|
|
|
|
messageContextMenu.close()
|
|
|
|
}
|
2020-08-03 17:17:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-16 15:02:47 +00:00
|
|
|
Item {
|
2020-08-03 17:17:03 +00:00
|
|
|
id: profileHeader
|
|
|
|
visible: messageContextMenu.isProfile
|
|
|
|
width: 200
|
|
|
|
height: visible ? profileImage.height + username.height + Style.current.padding : 0
|
2021-07-16 15:02:47 +00:00
|
|
|
Rectangle {
|
|
|
|
anchors.fill: parent
|
|
|
|
visible: mouseArea.containsMouse
|
|
|
|
color: Style.current.backgroundHover
|
|
|
|
}
|
2020-09-22 14:45:09 +00:00
|
|
|
StatusImageIdenticon {
|
2020-08-03 17:17:03 +00:00
|
|
|
id: profileImage
|
2020-10-02 13:02:56 +00:00
|
|
|
source: identicon
|
2020-08-03 17:17:03 +00:00
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.topMargin: 4
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
}
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
id: username
|
2021-02-15 16:25:07 +00:00
|
|
|
text: Utils.removeStatusEns(userName)
|
|
|
|
elide: Text.ElideRight
|
|
|
|
maximumLineCount: 3
|
2020-08-03 17:17:03 +00:00
|
|
|
horizontalAlignment: Text.AlignHCenter
|
2021-02-15 16:25:07 +00:00
|
|
|
wrapMode: Text.Wrap
|
2020-08-03 17:17:03 +00:00
|
|
|
anchors.top: profileImage.bottom
|
|
|
|
anchors.topMargin: 4
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.leftMargin: Style.current.smallPadding
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.rightMargin: Style.current.smallPadding
|
|
|
|
font.weight: Font.Medium
|
|
|
|
font.pixelSize: 15
|
|
|
|
}
|
|
|
|
|
|
|
|
MouseArea {
|
2021-07-16 15:02:47 +00:00
|
|
|
id: mouseArea
|
2020-08-03 17:17:03 +00:00
|
|
|
anchors.fill: parent
|
|
|
|
hoverEnabled: true
|
2021-07-16 15:02:47 +00:00
|
|
|
cursorShape: Qt.PointingHandCursor
|
2020-08-03 17:17:03 +00:00
|
|
|
onClicked: {
|
2020-10-02 13:02:56 +00:00
|
|
|
openProfilePopup(userName, fromAuthor, identicon);
|
2020-09-17 14:26:26 +00:00
|
|
|
messageContextMenu.close()
|
2020-08-03 17:17:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Separator {
|
|
|
|
anchors.bottom: viewProfileAction.top
|
2021-05-25 19:38:18 +00:00
|
|
|
visible: !messageContextMenu.emojiOnly && !messageContextMenu.hideEmojiPicker
|
2020-08-03 17:17:03 +00:00
|
|
|
}
|
|
|
|
|
2021-05-25 19:34:46 +00:00
|
|
|
Action {
|
|
|
|
id: pinAction
|
2021-07-16 20:22:50 +00:00
|
|
|
//% "Unpin"
|
|
|
|
text: pinnedMessage ? qsTrId("unpin") :
|
|
|
|
//% "Pin"
|
|
|
|
qsTrId("pin")
|
2021-05-25 19:34:46 +00:00
|
|
|
onTriggered: {
|
|
|
|
if (pinnedMessage) {
|
2021-06-21 19:35:32 +00:00
|
|
|
chatsModel.messageView.unPinMessage(messageId, chatsModel.channelView.activeChannel.id)
|
2021-05-25 19:34:46 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-06-21 19:35:32 +00:00
|
|
|
chatsModel.messageView.pinMessage(messageId, chatsModel.channelView.activeChannel.id)
|
2021-05-25 19:34:46 +00:00
|
|
|
messageContextMenu.close()
|
|
|
|
}
|
|
|
|
icon.source: "../../../img/pin"
|
|
|
|
icon.width: 16
|
|
|
|
icon.height: 16
|
2021-05-25 19:38:18 +00:00
|
|
|
enabled: {
|
2021-06-17 22:09:00 +00:00
|
|
|
switch (chatsModel.channelView.activeChannel.chatType) {
|
2021-05-25 19:38:18 +00:00
|
|
|
case Constants.chatTypePublic: return false
|
|
|
|
case Constants.chatTypeStatusUpdate: return false
|
|
|
|
case Constants.chatTypeOneToOne: return true
|
2021-06-17 22:09:00 +00:00
|
|
|
case Constants.chatTypePrivateGroupChat: return chatsModel.channelView.activeChannel.isAdmin(profileModel.profile.pubKey)
|
2021-05-25 19:38:18 +00:00
|
|
|
case Constants.chatTypeCommunity: return chatsModel.communities.activeCommunity.admin
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
2021-05-25 19:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Action {
|
|
|
|
id: copyAction
|
2021-06-17 07:06:38 +00:00
|
|
|
enabled: !emojiOnly
|
2021-07-16 20:22:50 +00:00
|
|
|
//% "Copy"
|
|
|
|
text: qsTrId("copy-to-clipboard")
|
2021-05-25 19:34:46 +00:00
|
|
|
onTriggered: {
|
|
|
|
chatsModel.copyToClipboard(messageContextMenu.text)
|
|
|
|
messageContextMenu.close()
|
|
|
|
}
|
|
|
|
icon.source: "../../../../shared/img/copy-to-clipboard-icon"
|
|
|
|
icon.width: 16
|
|
|
|
icon.height: 16
|
|
|
|
}
|
|
|
|
|
2021-02-23 10:18:09 +00:00
|
|
|
Action {
|
|
|
|
id: copyLinkAction
|
2021-07-16 20:22:50 +00:00
|
|
|
//% "Copy link"
|
|
|
|
text: qsTrId("copy-link")
|
2021-02-23 10:18:09 +00:00
|
|
|
onTriggered: {
|
|
|
|
chatsModel.copyToClipboard(linkUrls.split(" ")[0])
|
|
|
|
messageContextMenu.close()
|
|
|
|
}
|
|
|
|
icon.source: "../../../../shared/img/copy-to-clipboard-icon"
|
|
|
|
icon.width: 16
|
|
|
|
icon.height: 16
|
|
|
|
enabled: false
|
|
|
|
}
|
|
|
|
|
|
|
|
PopupMenu {
|
|
|
|
id: copyLinkMenu
|
2021-07-16 20:22:50 +00:00
|
|
|
//% "Copy link"
|
|
|
|
title: qsTrId("copy-link")
|
2021-04-07 17:36:30 +00:00
|
|
|
|
2021-02-23 10:18:09 +00:00
|
|
|
Repeater {
|
|
|
|
id: linksRepeater
|
|
|
|
model: messageContextMenu.linkUrls.split(" ")
|
|
|
|
delegate: MenuItem {
|
2021-04-07 17:36:30 +00:00
|
|
|
id: popupMenuItem
|
2021-02-23 10:18:09 +00:00
|
|
|
text: modelData
|
|
|
|
onTriggered: {
|
|
|
|
chatsModel.copyToClipboard(modelData)
|
|
|
|
messageContextMenu.close()
|
|
|
|
}
|
2021-04-07 17:36:30 +00:00
|
|
|
contentItem: StyledText {
|
|
|
|
text: popupMenuItem.text
|
|
|
|
font: popupMenuItem.font
|
|
|
|
color: Style.current.textColor
|
|
|
|
horizontalAlignment: Text.AlignLeft
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
elide: Text.ElideRight
|
|
|
|
}
|
|
|
|
background: Rectangle {
|
|
|
|
implicitWidth: 220
|
|
|
|
implicitHeight: 34
|
2021-04-09 13:46:37 +00:00
|
|
|
color: popupMenuItem.highlighted ? Style.current.backgroundHover: Style.current.transparent
|
2021-04-07 17:36:30 +00:00
|
|
|
}
|
2021-02-23 10:18:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-03 17:17:03 +00:00
|
|
|
Action {
|
|
|
|
id: viewProfileAction
|
2021-02-18 16:36:05 +00:00
|
|
|
//% "View Profile"
|
2020-08-03 17:17:03 +00:00
|
|
|
text: qsTrId("view-profile")
|
2020-09-17 14:26:26 +00:00
|
|
|
onTriggered: {
|
2021-01-13 07:42:32 +00:00
|
|
|
openProfilePopup(userName, fromAuthor, identicon, "", nickname);
|
2020-09-17 14:26:26 +00:00
|
|
|
messageContextMenu.close()
|
|
|
|
}
|
2020-08-03 17:17:03 +00:00
|
|
|
icon.source: "../../../img/profileActive.svg"
|
2020-08-14 12:08:09 +00:00
|
|
|
icon.width: 16
|
|
|
|
icon.height: 16
|
2021-03-17 12:41:24 +00:00
|
|
|
enabled: !emojiOnly && !copyLinkAction.enabled
|
2020-08-03 17:17:03 +00:00
|
|
|
}
|
2021-06-29 14:49:32 +00:00
|
|
|
|
|
|
|
Action {
|
|
|
|
id: editMessageAction
|
2021-07-16 20:22:50 +00:00
|
|
|
//% "Edit message"
|
|
|
|
text: qsTrId("edit-message")
|
2021-06-29 14:49:32 +00:00
|
|
|
onTriggered: {
|
|
|
|
onClickEdit();
|
|
|
|
}
|
2021-07-26 18:44:25 +00:00
|
|
|
icon.source: "../../../img/edit-message.svg"
|
2021-06-29 14:49:32 +00:00
|
|
|
icon.width: 16
|
|
|
|
icon.height: 16
|
|
|
|
enabled: isCurrentUser && isText
|
|
|
|
}
|
|
|
|
|
2020-08-03 17:17:03 +00:00
|
|
|
Action {
|
|
|
|
text: messageContextMenu.isProfile ?
|
2020-08-26 15:52:26 +00:00
|
|
|
//% "Send message"
|
|
|
|
qsTrId("send-message") :
|
2020-08-03 17:17:03 +00:00
|
|
|
//% "Reply to"
|
|
|
|
qsTrId("reply-to")
|
2020-09-17 14:26:26 +00:00
|
|
|
onTriggered: {
|
2020-12-10 11:41:28 +00:00
|
|
|
if (messageContextMenu.isProfile) {
|
|
|
|
appMain.changeAppSection(Constants.chat)
|
2021-06-17 22:09:00 +00:00
|
|
|
chatsModel.channelView.joinPrivateChat(fromAuthor, "")
|
2020-12-10 11:41:28 +00:00
|
|
|
} else {
|
2021-07-22 07:47:15 +00:00
|
|
|
showReplyArea()
|
2020-12-10 11:41:28 +00:00
|
|
|
}
|
2021-07-22 07:47:15 +00:00
|
|
|
messageContextMenu.closeParentPopup()
|
2020-09-17 14:26:26 +00:00
|
|
|
messageContextMenu.close()
|
|
|
|
}
|
2020-08-03 17:17:03 +00:00
|
|
|
icon.source: "../../../img/messageActive.svg"
|
2020-08-14 12:08:09 +00:00
|
|
|
icon.width: 16
|
|
|
|
icon.height: 16
|
2020-12-08 12:34:02 +00:00
|
|
|
enabled: !isSticker && !emojiOnly
|
2020-08-03 17:17:03 +00:00
|
|
|
}
|
2021-07-22 07:47:15 +00:00
|
|
|
|
2021-07-16 15:06:52 +00:00
|
|
|
Separator {
|
|
|
|
visible: deleteMessageAction.enabled
|
|
|
|
height: visible ? Style.current.halfPadding : 0
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:47:15 +00:00
|
|
|
Action {
|
|
|
|
text: qsTr("Jump to")
|
|
|
|
onTriggered: {
|
|
|
|
positionAtMessage(messageContextMenu.messageId)
|
|
|
|
messageContextMenu.closeParentPopup()
|
|
|
|
messageContextMenu.close()
|
|
|
|
}
|
|
|
|
icon.source: "../../../img/arrow-up.svg"
|
|
|
|
icon.width: 16
|
|
|
|
icon.height: 16
|
|
|
|
enabled: messageContextMenu.pinnedMessage && messageContextMenu.showJumpTo
|
|
|
|
}
|
2021-07-26 18:44:25 +00:00
|
|
|
|
|
|
|
Action {
|
|
|
|
id: deleteMessageAction
|
|
|
|
text: qsTr("Delete message")
|
|
|
|
onTriggered: {
|
|
|
|
if (!appSettings.showDeleteMessageWarning) {
|
|
|
|
return chatsModel.messageView.deleteMessage(messageId)
|
|
|
|
}
|
|
|
|
|
|
|
|
let confirmationDialog = openPopup(genericConfirmationDialog, {
|
|
|
|
title: qsTr("Confirm deleting this message"),
|
2021-07-16 15:06:52 +00:00
|
|
|
confirmationText: qsTr("Are you sure you want to delete this message? Be aware that other clients are not guaranteed to delete the message as well."),
|
2021-07-26 18:44:25 +00:00
|
|
|
height: 260,
|
|
|
|
"checkbox.visible": true,
|
|
|
|
executeConfirm: function () {
|
|
|
|
if (confirmationDialog.checkbox.checked) {
|
|
|
|
appSettings.showDeleteMessageWarning = false
|
|
|
|
}
|
|
|
|
|
|
|
|
confirmationDialog.close()
|
|
|
|
chatsModel.messageView.deleteMessage(messageId)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
icon.source: "../../../img/delete.svg"
|
2021-07-16 15:06:52 +00:00
|
|
|
icon.color: Style.current.danger
|
2021-07-26 18:44:25 +00:00
|
|
|
icon.width: 16
|
|
|
|
icon.height: 16
|
|
|
|
enabled: isCurrentUser
|
|
|
|
}
|
2020-08-03 17:17:03 +00:00
|
|
|
}
|