status-desktop/ui/app/AppLayouts/Chat/components/MessageContextMenu.qml

160 lines
5.0 KiB
QML
Raw Normal View History

import QtQuick 2.12
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
import QtQml.Models 2.3
import "../../../../imports"
import "../../../../shared"
import "../../../../shared/status"
import "./"
PopupMenu {
property bool isProfile: false
property bool isSticker: false
property bool emojiOnly: false
property alias emojiContainer: emojiContainer
id: messageContextMenu
width: messageContextMenu.isProfile ? profileHeader.width : emojiContainer.width
2020-10-02 13:02:56 +00:00
property var identicon: ""
property var userName: ""
property string nickname: ""
property var fromAuthor: ""
property var text: ""
property var emojiReactionsReactedByUser: []
2020-10-02 13:02:56 +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 || ""
let newEmojiReactions = []
if (!!emojiReactionsModel) {
emojiReactionsModel.forEach(function (emojiReaction) {
newEmojiReactions[emojiReaction.emojiId] = emojiReaction.currentUserReacted
})
}
emojiReactionsReactedByUser = newEmojiReactions
2020-10-02 13:02:56 +00:00
popup();
}
Item {
id: emojiContainer
visible: messageContextMenu.emojiOnly || !messageContextMenu.isProfile
width: emojiRow.width
height: visible ? emojiRow.height : 0
Row {
id: emojiRow
spacing: Style.current.smallPadding
leftPadding: Style.current.smallPadding
rightPadding: Style.current.smallPadding
bottomPadding: messageContextMenu.emojiOnly ? 0 : Style.current.padding
Repeater {
model: reactionModel
delegate: EmojiReaction {
source: "../../../img/" + filename
emojiId: model.emojiId
reactedByUser: !!messageContextMenu.emojiReactionsReactedByUser[model.emojiId]
closeModal: function () {
messageContextMenu.close()
}
}
}
}
}
Rectangle {
property bool hovered: false
id: profileHeader
visible: messageContextMenu.isProfile
width: 200
height: visible ? profileImage.height + username.height + Style.current.padding : 0
color: hovered ? Style.current.secondaryBackground : Style.current.transparent
StatusImageIdenticon {
id: profileImage
2020-10-02 13:02:56 +00:00
source: identicon
anchors.top: parent.top
anchors.topMargin: 4
anchors.horizontalCenter: parent.horizontalCenter
}
StyledText {
id: username
text: Utils.removeStatusEns(userName)
elide: Text.ElideRight
maximumLineCount: 3
horizontalAlignment: Text.AlignHCenter
wrapMode: Text.Wrap
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 {
cursorShape: Qt.PointingHandCursor
anchors.fill: parent
hoverEnabled: true
onEntered: {
profileHeader.hovered = true
}
onExited: {
profileHeader.hovered = false
}
onClicked: {
2020-10-02 13:02:56 +00:00
openProfilePopup(userName, fromAuthor, identicon);
2020-09-17 14:26:26 +00:00
messageContextMenu.close()
}
}
}
Separator {
anchors.bottom: viewProfileAction.top
visible: !messageContextMenu.emojiOnly
}
Action {
id: viewProfileAction
//% "View profile"
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()
}
icon.source: "../../../img/profileActive.svg"
2020-08-14 12:08:09 +00:00
icon.width: 16
icon.height: 16
enabled: !emojiOnly
}
Action {
text: messageContextMenu.isProfile ?
2020-08-26 15:52:26 +00:00
//% "Send message"
qsTrId("send-message") :
//% "Reply to"
qsTrId("reply-to")
2020-09-17 14:26:26 +00:00
onTriggered: {
if (messageContextMenu.isProfile) {
appMain.changeAppSection(Constants.chat)
chatsModel.joinChat(fromAuthor, Constants.chatTypeOneToOne)
} else {
showReplyArea()
}
2020-09-17 14:26:26 +00:00
messageContextMenu.close()
}
icon.source: "../../../img/messageActive.svg"
2020-08-14 12:08:09 +00:00
icon.width: 16
icon.height: 16
enabled: !isSticker && !emojiOnly
}
}