status-desktop/ui/app/AppLayouts/Chat/popups/PinnedMessagesPopup.qml

221 lines
7.3 KiB
QML
Raw Normal View History

import QtQuick 2.13
import QtQuick.Controls 2.3
import utils 1.0
import shared 1.0
import shared.views 1.0
import shared.panels 1.0
import shared.popups 1.0
import shared.views.chat 1.0
import "../controls"
import "../panels"
//TODO remove or make view?
import "../views"
import StatusQ.Controls 0.1 as StatusQControls
// TODO: replace with StatusMOdal
ModalPopup {
id: popup
property var store
property var messageStore
property var pinnedMessagesModel //this doesn't belong to the messageStore, it is a part of the ChatContentStore, but we didn't introduce it yet.
property string messageToPin
property string messageToUnpin
property var emojiReactionsModel
header: Item {
height: childrenRect.height
width: parent.width
StyledText {
id: title
2021-07-30 16:02:22 +00:00
//% "Pin limit reached"
text: !!popup.messageToPin ? qsTrId("pin-limit-reached") :
//% "Pinned messages"
qsTrId("pinned-messages")
anchors.top: parent.top
anchors.left: parent.left
font.bold: true
font.pixelSize: 17
}
StyledText {
2021-05-25 19:38:18 +00:00
property int nbMessages: pinnedMessageListView.count
id: nbPinnedMessages
text: {
if (!!popup.messageToPin) {
2021-07-30 16:02:22 +00:00
//% "Unpin a previous message first"
return qsTrId("unpin-a-previous-message-first")
}
//% "%1 messages"
return nbMessages > 1 ? qsTrId("-1-messages").arg(nbMessages) :
//% "%1 message"
qsTrId("-1-message").arg(nbMessages)
}
anchors.left: parent.left
anchors.top: title.bottom
anchors.topMargin: 2
font.pixelSize: 15
color: Style.current.secondaryText
}
Separator {
anchors.top: nbPinnedMessages.bottom
anchors.topMargin: Style.current.padding
anchors.left: parent.left
anchors.leftMargin: -Style.current.padding
anchors.right: parent.right
anchors.rightMargin: -Style.current.padding
}
}
2021-05-25 19:38:18 +00:00
Item {
anchors.fill: parent
2021-05-25 19:38:18 +00:00
StyledText {
visible: pinnedMessageListView.count === 0
//% "Pinned messages will appear here."
text: qsTrId("pinned-messages-will-appear-here-")
2021-05-25 19:38:18 +00:00
anchors.centerIn: parent
color: Style.current.secondaryText
}
ButtonGroup {
id: pinButtonGroup
}
2021-05-25 19:38:18 +00:00
ListView {
id: pinnedMessageListView
model: popup.pinnedMessagesModel
2021-05-25 19:38:18 +00:00
height: parent.height
anchors.left: parent.left
anchors.leftMargin: -Style.current.padding
anchors.right: parent.right
anchors.rightMargin: -Style.current.padding
topMargin: Style.current.halfPadding
anchors.top: parent.top
anchors.topMargin: -Style.current.halfPadding
clip: true
delegate: Item {
id: messageDelegate
property var listView: ListView.view
width: parent.width
height: messageItem.height
MessageView {
id: messageItem
messageStore: popup.messageStore
messageContextMenu: msgContextMenu
messageId: model.id
responseToMessageWithId: model.responseToMessageWithId
senderId: model.senderId
senderDisplayName: model.senderDisplayName
senderLocalName: model.senderLocalName
senderIcon: model.senderIcon
isSenderIconIdenticon: model.isSenderIconIdenticon
amISender: model.amISender
message: model.messageText
messageImage: model.messageImage
messageTimestamp: model.timestamp
messageOutgoingStatus: model.outgoingStatus
messageContentType: model.contentType
pinnedMessage: model.pinned
messagePinnedBy: model.pinnedBy
reactionsModel: model.reactions
2022-01-25 12:56:53 +00:00
linkUrls: model.links
isInPinnedPopup: true
// This is possible since we have all data loaded before we load qml.
// When we fetch messages to fulfill a gap we have to set them at once.
prevMessageIndex: index - 1
prevMessageAsJsonObj: popup.messageStore? popup.messageStore.getMessageByIndexAsJson(index - 1) : {}
nextMessageIndex: index + 1
nextMessageAsJsonObj: popup.messageStore? popup.messageStore.getMessageByIndexAsJson(index + 1) : {}
// Additional params
forceHoverHandler: !popup.messageToPin
}
MouseArea {
anchors.fill: parent
enabled: !!popup.messageToPin
cursorShape: Qt.PointingHandCursor
z: 55
onClicked: radio.toggle()
}
StatusQControls.StatusRadioButton {
id: radio
visible: !!popup.messageToPin
anchors.right: parent.right
anchors.rightMargin: 18
anchors.verticalCenter: parent.verticalCenter
ButtonGroup.group: pinButtonGroup
function toggle() {
radio.checked = !radio.checked
if (radio.checked) {
popup.messageToUnpin = model.id
}
}
}
2021-05-25 19:38:18 +00:00
}
}
MessageContextMenuView {
id: msgContextMenu
reactionModel: popup.emojiReactionsModel
store: popup.store
pinnedPopup: true
pinnedMessage: true
onShouldCloseParentPopup: {
popup.close()
}
onPinMessage: {
popup.messageStore.pinMessage(messageId)
}
onUnpinMessage: {
popup.messageStore.unpinMessage(messageId)
}
onToggleReaction: {
popup.messageStore.toggleReaction(messageId, emojiId)
}
onOpenProfileClicked: {
Global.openProfilePopup(publicKey)
}
}
}
2021-05-25 19:38:18 +00:00
footer: Item {
width: parent.width
height: btnUnpin.height
StatusQControls.StatusButton {
id: btnUnpin
visible: !!popup.messageToPin
enabled: !!popup.messageToUnpin
2021-07-30 16:02:22 +00:00
//% "Unpin"
text: qsTrId("unpin")
type: StatusQControls.StatusBaseButton.Type.Danger
anchors.right: parent.right
onClicked: {
popup.messageStore.unpinMessage(popup.messageToUnpin)
popup.messageToUnpin = ""
popup.messageStore.pinMessage(popup.messageToPin)
popup.messageToPin = ""
popup.close()
}
}
}
}