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
|
2021-08-16 09:11:43 +00:00
|
|
|
import QtQuick.Dialogs 1.0
|
2021-08-06 15:44:57 +00:00
|
|
|
|
|
|
|
import StatusQ.Popups 0.1
|
|
|
|
|
2020-08-03 17:17:03 +00:00
|
|
|
import "../../../../imports"
|
|
|
|
import "../../../../shared"
|
2020-09-22 14:45:09 +00:00
|
|
|
import "../../../../shared/status"
|
2020-08-03 17:17:03 +00:00
|
|
|
import "./"
|
|
|
|
|
2021-08-06 15:44:57 +00:00
|
|
|
StatusPopupMenu {
|
2021-07-16 15:02:47 +00:00
|
|
|
id: messageContextMenu
|
2021-08-06 15:44:57 +00:00
|
|
|
width: emojiContainer.visible ? emojiContainer.width : 176
|
2021-07-16 15:02:47 +00:00
|
|
|
|
2021-05-25 19:34:46 +00:00
|
|
|
property string messageId
|
2021-07-20 15:26:41 +00:00
|
|
|
property int contentType
|
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-08-16 12:35:24 +00:00
|
|
|
property bool pinnedPopup: false
|
2021-06-29 14:49:32 +00:00
|
|
|
property bool isText: false
|
|
|
|
property bool isCurrentUser: false
|
2021-08-16 09:11:43 +00:00
|
|
|
property bool isRightClickOnImage: 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-08-16 09:11:43 +00:00
|
|
|
property string imageSource: ""
|
2021-07-26 17:27:09 +00:00
|
|
|
property bool canPin: {
|
|
|
|
const nbPinnedMessages = chatsModel.messageView.pinnedMessagesList.count
|
|
|
|
return nbPinnedMessages < Constants.maxNumberOfPins
|
|
|
|
}
|
2021-06-29 14:49:32 +00:00
|
|
|
|
2021-08-16 12:35:24 +00:00
|
|
|
signal shouldCloseParentPopup
|
2021-07-22 07:47:15 +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-08-06 15:44:57 +00:00
|
|
|
/* // copy link feature not ready yet
|
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-08-06 15:44:57 +00:00
|
|
|
*/
|
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
|
2021-08-06 15:44:57 +00:00
|
|
|
spacing: Style.current.halfPadding
|
|
|
|
leftPadding: Style.current.halfPadding
|
|
|
|
rightPadding: Style.current.halfPadding
|
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
|
2021-08-06 15:44:57 +00:00
|
|
|
width: parent.width
|
2020-08-03 17:17:03 +00:00
|
|
|
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-07-22 17:08:37 +00:00
|
|
|
text: Utils.removeStatusEns(isCurrentUser ? profileModel.ens.preferredUsername || userName : userName)
|
2021-02-15 16:25:07 +00:00
|
|
|
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-08-06 15:44:57 +00:00
|
|
|
/* // copy link feature not ready yet
|
|
|
|
StatusMenuItem {
|
2021-02-23 10:18:09 +00:00
|
|
|
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()
|
|
|
|
}
|
2021-08-06 15:44:57 +00:00
|
|
|
icon.name: "link"
|
2021-02-23 10:18:09 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-08-06 15:44:57 +00:00
|
|
|
*/
|
2021-02-23 10:18:09 +00:00
|
|
|
|
2021-08-16 09:11:43 +00:00
|
|
|
StatusMenuItem {
|
|
|
|
id: copyImageAction
|
|
|
|
text: qsTr("Copy image")
|
|
|
|
onTriggered: {
|
|
|
|
chatsModel.copyImageToClipboard(imageSource ? imageSource : "")
|
|
|
|
messageContextMenu.close()
|
|
|
|
}
|
|
|
|
icon.name: "copy"
|
|
|
|
enabled: isRightClickOnImage
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusMenuItem {
|
|
|
|
id: downloadImageAction
|
|
|
|
text: qsTr("Download image")
|
|
|
|
onTriggered: {
|
|
|
|
fileDialog.open()
|
|
|
|
messageContextMenu.close()
|
|
|
|
}
|
|
|
|
icon.name: "download"
|
|
|
|
enabled: isRightClickOnImage
|
|
|
|
}
|
|
|
|
|
2021-08-06 15:44:57 +00:00
|
|
|
StatusMenuItem {
|
2020-08-03 17:17:03 +00:00
|
|
|
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()
|
|
|
|
}
|
2021-08-06 15:44:57 +00:00
|
|
|
icon.name: "profile"
|
|
|
|
enabled: isProfile
|
2020-08-03 17:17:03 +00:00
|
|
|
}
|
2021-06-29 14:49:32 +00:00
|
|
|
|
2021-08-06 15:44:57 +00:00
|
|
|
StatusMenuItem {
|
|
|
|
id: sendMessageOrReplyTo
|
2020-08-03 17:17:03 +00:00
|
|
|
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
|
|
|
}
|
2020-09-17 14:26:26 +00:00
|
|
|
messageContextMenu.close()
|
|
|
|
}
|
2021-08-06 15:44:57 +00:00
|
|
|
icon.name: "chat"
|
2021-08-16 09:11:43 +00:00
|
|
|
enabled: isProfile || (!hideEmojiPicker && !emojiOnly && !isProfile && !isRightClickOnImage)
|
2020-08-03 17:17:03 +00:00
|
|
|
}
|
2021-07-22 07:47:15 +00:00
|
|
|
|
2021-08-06 15:44:57 +00:00
|
|
|
StatusMenuItem {
|
|
|
|
id: editMessageAction
|
|
|
|
//% "Edit message"
|
|
|
|
text: qsTrId("edit-message")
|
|
|
|
onTriggered: {
|
|
|
|
onClickEdit();
|
|
|
|
}
|
|
|
|
icon.name: "edit"
|
2021-08-16 09:11:43 +00:00
|
|
|
enabled: isCurrentUser && !hideEmojiPicker && !emojiOnly && !isProfile && !isRightClickOnImage
|
2021-07-16 15:06:52 +00:00
|
|
|
}
|
|
|
|
|
2021-08-06 15:44:57 +00:00
|
|
|
StatusMenuItem {
|
|
|
|
id: pinAction
|
|
|
|
text: {
|
|
|
|
if (pinnedMessage) {
|
|
|
|
//% "Unpin"
|
|
|
|
return qsTrId("unpin")
|
|
|
|
}
|
|
|
|
//% "Pin"
|
|
|
|
return qsTrId("pin")
|
|
|
|
|
|
|
|
}
|
2021-07-22 07:47:15 +00:00
|
|
|
onTriggered: {
|
2021-08-06 15:44:57 +00:00
|
|
|
if (pinnedMessage) {
|
|
|
|
chatsModel.messageView.unPinMessage(messageId, chatsModel.channelView.activeChannel.id)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!canPin) {
|
|
|
|
// Open pin modal so that the user can unpin one
|
|
|
|
openPopup(pinnedMessagesPopupComponent, {messageToPin: messageId})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
chatsModel.messageView.pinMessage(messageId, chatsModel.channelView.activeChannel.id)
|
2021-07-22 07:47:15 +00:00
|
|
|
messageContextMenu.close()
|
|
|
|
}
|
2021-08-06 15:44:57 +00:00
|
|
|
icon.name: "pin"
|
|
|
|
enabled: {
|
2021-08-16 09:11:43 +00:00
|
|
|
if(isProfile || emojiOnly || isRightClickOnImage)
|
2021-08-06 15:44:57 +00:00
|
|
|
return false
|
|
|
|
|
|
|
|
switch (chatsModel.channelView.activeChannel.chatType) {
|
|
|
|
case Constants.chatTypePublic: return false
|
|
|
|
case Constants.chatTypeStatusUpdate: return false
|
|
|
|
case Constants.chatTypeOneToOne: return true
|
|
|
|
case Constants.chatTypePrivateGroupChat: return chatsModel.channelView.activeChannel.isAdmin(profileModel.profile.pubKey)
|
|
|
|
case Constants.chatTypeCommunity: return chatsModel.communities.activeCommunity.admin
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusMenuSeparator {
|
2021-08-18 12:37:13 +00:00
|
|
|
visible: deleteMessageAction.enabled && (viewProfileAction.visible
|
|
|
|
|| sendMessageOrReplyTo.visible || editMessageAction.visible || pinAction.visible)
|
2021-07-22 07:47:15 +00:00
|
|
|
}
|
2021-08-06 15:44:57 +00:00
|
|
|
|
|
|
|
StatusMenuItem {
|
2021-07-26 18:44:25 +00:00
|
|
|
id: deleteMessageAction
|
2021-08-16 09:11:43 +00:00
|
|
|
enabled: isCurrentUser && !isProfile && !emojiOnly && !pinnedPopup && !isRightClickOnImage &&
|
2021-07-20 15:26:41 +00:00
|
|
|
(contentType === Constants.messageType ||
|
|
|
|
contentType === Constants.stickerType ||
|
|
|
|
contentType === Constants.emojiType ||
|
|
|
|
contentType === Constants.imageType ||
|
|
|
|
contentType === Constants.audioType)
|
2021-07-30 16:02:22 +00:00
|
|
|
//% "Delete message"
|
|
|
|
text: qsTrId("delete-message")
|
2021-07-26 18:44:25 +00:00
|
|
|
onTriggered: {
|
|
|
|
if (!appSettings.showDeleteMessageWarning) {
|
|
|
|
return chatsModel.messageView.deleteMessage(messageId)
|
|
|
|
}
|
|
|
|
|
|
|
|
let confirmationDialog = openPopup(genericConfirmationDialog, {
|
2021-07-30 16:02:22 +00:00
|
|
|
//% "Confirm deleting this message"
|
|
|
|
title: qsTrId("confirm-deleting-this-message"),
|
|
|
|
//% "Are you sure you want to delete this message? Be aware that other clients are not guaranteed to delete the message as well."
|
|
|
|
confirmationText: qsTrId("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)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2021-08-06 15:44:57 +00:00
|
|
|
icon.name: "delete"
|
|
|
|
type: StatusMenuItem.Type.Danger
|
2021-07-26 18:44:25 +00:00
|
|
|
}
|
2021-08-16 12:35:24 +00:00
|
|
|
|
|
|
|
StatusMenuItem {
|
|
|
|
enabled: messageContextMenu.pinnedPopup
|
|
|
|
text: qsTr("Jump to")
|
|
|
|
onTriggered: {
|
|
|
|
positionAtMessage(messageContextMenu.messageId)
|
|
|
|
messageContextMenu.close()
|
|
|
|
messageContextMenu.shouldCloseParentPopup()
|
|
|
|
}
|
|
|
|
icon.name: "up"
|
|
|
|
}
|
2021-08-16 09:11:43 +00:00
|
|
|
|
|
|
|
FileDialog {
|
|
|
|
id: fileDialog
|
|
|
|
title: qsTr("Please choose a directory")
|
|
|
|
selectFolder: true
|
|
|
|
modality: Qt.NonModal
|
|
|
|
onAccepted: {
|
|
|
|
chatsModel.downloadImage(imageSource ? imageSource : "", fileDialog.fileUrls)
|
|
|
|
fileDialog.close()
|
|
|
|
}
|
|
|
|
onRejected: {
|
|
|
|
fileDialog.close()
|
|
|
|
}
|
|
|
|
}
|
2020-08-03 17:17:03 +00:00
|
|
|
}
|