2020-06-17 15:18:31 -04:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
|
|
|
import QtQuick.Layouts 1.13
|
2020-11-30 23:24:01 +02:00
|
|
|
import QtQuick.Dialogs 1.3
|
2021-10-28 00:27:49 +03:00
|
|
|
|
2022-07-14 14:03:36 +03:00
|
|
|
import StatusQ.Core 0.1
|
2022-09-19 10:40:02 +02:00
|
|
|
import StatusQ.Core.Theme 0.1
|
2022-07-14 14:03:36 +03:00
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
import StatusQ.Components 0.1
|
|
|
|
|
2021-10-28 00:27:49 +03:00
|
|
|
import utils 1.0
|
|
|
|
import shared 1.0
|
2021-10-28 23:23:30 +03:00
|
|
|
import shared.views 1.0
|
2021-10-28 00:27:49 +03:00
|
|
|
import shared.panels 1.0
|
|
|
|
import shared.popups 1.0
|
|
|
|
import shared.status 1.0
|
|
|
|
import shared.controls 1.0
|
2021-10-28 23:23:30 +03:00
|
|
|
import shared.views.chat 1.0
|
2021-09-28 18:04:06 +03:00
|
|
|
|
2021-10-01 18:58:36 +03:00
|
|
|
import "../controls"
|
|
|
|
|
2021-07-22 17:53:19 +03:00
|
|
|
Item {
|
2021-08-02 16:38:03 +03:00
|
|
|
id: root
|
2021-07-22 17:53:19 +03:00
|
|
|
|
2022-07-05 14:12:27 +04:00
|
|
|
property var chatContentModule
|
|
|
|
property var rootStore
|
2021-12-09 13:53:40 +01:00
|
|
|
property var messageStore
|
2022-02-08 13:08:02 +01:00
|
|
|
property var usersStore
|
2022-01-04 13:06:05 +01:00
|
|
|
property var contactsStore
|
2022-03-14 15:32:52 -04:00
|
|
|
property string channelEmoji
|
2021-10-22 01:39:53 +03:00
|
|
|
|
2022-04-13 12:59:16 +03:00
|
|
|
property var emojiPopup
|
2022-11-14 15:21:00 -05:00
|
|
|
property var stickersPopup
|
2022-04-13 12:59:16 +03:00
|
|
|
|
2021-12-08 23:20:43 +02:00
|
|
|
property bool stickersLoaded: false
|
2020-11-19 14:30:09 -04:00
|
|
|
property alias chatLogView: chatLogView
|
2022-02-24 13:15:02 +01:00
|
|
|
property bool isChatBlocked: false
|
2022-06-23 11:47:30 -04:00
|
|
|
property bool isActiveChannel: false
|
2021-07-08 11:20:03 -04:00
|
|
|
|
2022-07-05 14:12:27 +04:00
|
|
|
property var messageContextMenu
|
2021-08-05 17:05:47 -04:00
|
|
|
|
2021-12-08 23:20:43 +02:00
|
|
|
signal openStickerPackPopup(string stickerPackId)
|
2022-01-12 15:55:26 +03:00
|
|
|
signal showReplyArea(string messageId, string author)
|
2023-01-05 04:14:12 +01:00
|
|
|
signal editModeChanged(bool editModeOn)
|
2021-12-08 23:20:43 +02:00
|
|
|
|
2022-12-05 08:52:41 +01:00
|
|
|
QtObject {
|
|
|
|
id: d
|
|
|
|
|
|
|
|
readonly property real scrollY: chatLogView.visibleArea.yPosition * chatLogView.contentHeight
|
|
|
|
readonly property bool isMostRecentMessageInViewport: chatLogView.visibleArea.yPosition >= 0.999 - chatLogView.visibleArea.heightRatio
|
2022-12-18 23:29:18 +03:00
|
|
|
readonly property var chatDetails: chatContentModule.chatDetails || null
|
2022-12-05 08:52:41 +01:00
|
|
|
|
2023-01-18 09:58:24 +02:00
|
|
|
readonly property var loadMoreMessagesIfScrollBelowThreshold: Backpressure.oneInTime(root, 100, function() {
|
2023-01-10 13:40:01 +02:00
|
|
|
if(scrollY < 1000) messageStore.loadMoreMessages()
|
2022-12-20 11:58:50 +01:00
|
|
|
})
|
|
|
|
|
2022-12-05 08:52:41 +01:00
|
|
|
function markAllMessagesReadIfMostRecentMessageIsInViewport() {
|
2023-01-06 11:17:39 +02:00
|
|
|
if (!isMostRecentMessageInViewport || !chatLogView.visible) {
|
2022-12-05 08:52:41 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-12-26 11:25:16 -05:00
|
|
|
if (chatDetails && chatDetails.active && chatDetails.hasUnreadMessages && !messageStore.messageSearchOngoing) {
|
2022-12-05 08:52:41 +01:00
|
|
|
chatContentModule.markAllMessagesRead()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onIsMostRecentMessageInViewportChanged: markAllMessagesReadIfMostRecentMessageIsInViewport()
|
|
|
|
}
|
|
|
|
|
2022-01-27 12:28:27 +01:00
|
|
|
Connections {
|
|
|
|
target: root.messageStore.messageModule
|
|
|
|
|
2022-09-23 00:01:29 +02:00
|
|
|
function onMessageSuccessfullySent() {
|
2022-12-05 08:52:41 +01:00
|
|
|
chatLogView.positionViewAtBeginning()
|
2022-01-27 12:28:27 +01:00
|
|
|
}
|
|
|
|
|
2022-09-23 00:01:29 +02:00
|
|
|
function onSendingMessageFailed() {
|
|
|
|
sendingMsgFailedPopup.open()
|
2022-01-27 12:28:27 +01:00
|
|
|
}
|
|
|
|
|
2022-12-05 08:52:41 +01:00
|
|
|
function onScrollToMessage(messageIndex) {
|
|
|
|
chatLogView.positionViewAtIndex(messageIndex, ListView.Center)
|
|
|
|
chatLogView.itemAtIndex(messageIndex).startMessageFoundAnimation()
|
2022-01-27 13:44:33 +01:00
|
|
|
}
|
|
|
|
|
2022-12-05 08:52:41 +01:00
|
|
|
function onMessageSearchOngoingChanged() {
|
|
|
|
d.markAllMessagesReadIfMostRecentMessageIsInViewport()
|
2022-01-27 12:28:27 +01:00
|
|
|
}
|
2022-12-05 08:52:41 +01:00
|
|
|
}
|
2022-01-27 12:28:27 +01:00
|
|
|
|
2022-12-05 08:52:41 +01:00
|
|
|
Connections {
|
2022-12-20 17:23:49 +02:00
|
|
|
target: !!d.chatDetails ? d.chatDetails : null
|
2022-12-05 08:52:41 +01:00
|
|
|
|
|
|
|
function onActiveChanged() {
|
|
|
|
d.markAllMessagesReadIfMostRecentMessageIsInViewport()
|
2022-12-20 11:58:50 +01:00
|
|
|
d.loadMoreMessagesIfScrollBelowThreshold()
|
2022-12-05 08:52:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function onHasUnreadMessagesChanged() {
|
2023-01-06 11:17:39 +02:00
|
|
|
if (!d.chatDetails.hasUnreadMessages) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// HACK: we call `addNewMessagesMarker` later because messages model
|
|
|
|
// may not be yet propagated with unread messages when this signal is emitted
|
|
|
|
if (chatLogView.visible) {
|
|
|
|
if (!d.isMostRecentMessageInViewport) {
|
|
|
|
Qt.callLater(() => messageStore.addNewMessagesMarker())
|
|
|
|
}
|
|
|
|
} else {
|
2022-12-05 08:52:41 +01:00
|
|
|
Qt.callLater(() => messageStore.addNewMessagesMarker())
|
|
|
|
}
|
|
|
|
}
|
2022-01-27 12:28:27 +01:00
|
|
|
}
|
|
|
|
|
2022-12-20 11:58:50 +01:00
|
|
|
Connections {
|
|
|
|
target: root.rootStore
|
|
|
|
enabled: d.chatDetails && d.chatDetails.active
|
|
|
|
|
|
|
|
function onLoadingHistoryMessagesInProgressChanged() {
|
|
|
|
if(!root.rootStore.loadingHistoryMessagesInProgress) {
|
|
|
|
d.loadMoreMessagesIfScrollBelowThreshold()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-22 13:00:44 +01:00
|
|
|
Item {
|
|
|
|
id: loadingMessagesIndicator
|
2022-07-05 14:12:27 +04:00
|
|
|
visible: root.rootStore.loadingHistoryMessagesInProgress
|
2021-12-22 13:00:44 +01:00
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.left: parent.left
|
|
|
|
height: visible? 20 : 0
|
|
|
|
width: parent.width
|
|
|
|
|
|
|
|
Loader {
|
2022-07-05 14:12:27 +04:00
|
|
|
active: root.rootStore.loadingHistoryMessagesInProgress
|
2021-12-22 13:00:44 +01:00
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
sourceComponent: Component {
|
|
|
|
LoadingAnimation {
|
|
|
|
width: 18
|
|
|
|
height: 18
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-14 14:03:36 +03:00
|
|
|
StatusListView {
|
2021-08-02 16:38:03 +03:00
|
|
|
id: chatLogView
|
2022-07-20 14:14:50 +02:00
|
|
|
objectName: "chatLogView"
|
2021-12-22 13:00:44 +01:00
|
|
|
anchors.top: loadingMessagesIndicator.bottom
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.right: parent.right
|
2021-12-10 12:29:33 +01:00
|
|
|
spacing: 0
|
2021-08-02 16:38:03 +03:00
|
|
|
verticalLayoutDirection: ListView.BottomToTop
|
2023-02-03 15:05:32 +02:00
|
|
|
cacheBuffer: height * 2 // cache 2 screens worth of items
|
2020-09-24 11:05:17 -04:00
|
|
|
|
2022-07-05 14:12:27 +04:00
|
|
|
model: messageStore.messagesModel
|
|
|
|
|
|
|
|
onContentYChanged: {
|
2022-12-05 08:52:41 +01:00
|
|
|
scrollDownButton.visible = contentHeight - (d.scrollY + height) > 400
|
2022-12-20 11:58:50 +01:00
|
|
|
d.loadMoreMessagesIfScrollBelowThreshold()
|
2022-07-05 14:12:27 +04:00
|
|
|
}
|
|
|
|
|
2022-12-05 08:52:41 +01:00
|
|
|
onCountChanged: d.markAllMessagesReadIfMostRecentMessageIsInViewport()
|
|
|
|
|
2023-01-06 11:17:39 +02:00
|
|
|
onVisibleChanged: d.markAllMessagesReadIfMostRecentMessageIsInViewport()
|
|
|
|
|
2022-07-14 14:03:36 +03:00
|
|
|
ScrollBar.vertical: StatusScrollBar {
|
2021-12-22 13:00:44 +01:00
|
|
|
visible: chatLogView.visibleArea.heightRatio < 1
|
|
|
|
}
|
2021-12-09 13:53:40 +01:00
|
|
|
|
2021-12-22 13:00:44 +01:00
|
|
|
Button {
|
2022-07-05 14:12:27 +04:00
|
|
|
id: scrollDownButton
|
|
|
|
|
2021-12-22 13:00:44 +01:00
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.rightMargin: Style.current.padding
|
2022-12-05 08:52:41 +01:00
|
|
|
|
|
|
|
visible: false
|
|
|
|
height: 32
|
|
|
|
width: arrowImage.width + 2 * Style.current.halfPadding
|
|
|
|
|
2021-12-22 13:00:44 +01:00
|
|
|
background: Rectangle {
|
|
|
|
color: Style.current.buttonSecondaryColor
|
|
|
|
border.width: 0
|
|
|
|
radius: 16
|
|
|
|
}
|
2022-07-05 14:12:27 +04:00
|
|
|
|
2021-12-22 13:00:44 +01:00
|
|
|
onClicked: {
|
|
|
|
scrollDownButton.visible = false
|
2022-12-05 08:52:41 +01:00
|
|
|
chatLogView.positionViewAtBeginning()
|
2021-12-22 13:00:44 +01:00
|
|
|
}
|
2021-12-09 13:53:40 +01:00
|
|
|
|
2022-10-03 14:16:44 +02:00
|
|
|
StatusIcon {
|
2021-12-22 13:00:44 +01:00
|
|
|
id: arrowImage
|
2022-12-05 08:52:41 +01:00
|
|
|
anchors.centerIn: parent
|
2021-12-22 13:00:44 +01:00
|
|
|
width: 24
|
|
|
|
height: 24
|
2022-10-03 14:16:44 +02:00
|
|
|
icon: "arrow-down"
|
|
|
|
color: Style.current.pillButtonTextColor
|
2021-12-22 13:00:44 +01:00
|
|
|
}
|
2021-12-09 13:53:40 +01:00
|
|
|
|
2021-12-22 13:00:44 +01:00
|
|
|
MouseArea {
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
anchors.fill: parent
|
2023-01-06 16:43:54 +01:00
|
|
|
acceptedButtons: Qt.NoButton
|
2021-12-22 13:00:44 +01:00
|
|
|
}
|
|
|
|
}
|
2020-11-30 23:24:01 +02:00
|
|
|
|
2021-10-01 18:58:36 +03:00
|
|
|
delegate: MessageView {
|
2021-08-02 16:38:03 +03:00
|
|
|
id: msgDelegate
|
2022-07-05 14:12:27 +04:00
|
|
|
|
|
|
|
width: ListView.view.width
|
2022-09-30 17:15:22 +02:00
|
|
|
height: implicitHeight
|
2022-07-05 14:12:27 +04:00
|
|
|
|
2022-07-21 12:16:25 -04:00
|
|
|
objectName: "chatMessageViewDelegate"
|
2022-07-05 14:12:27 +04:00
|
|
|
rootStore: root.rootStore
|
2021-12-09 13:53:40 +01:00
|
|
|
messageStore: root.messageStore
|
2022-02-08 13:08:02 +01:00
|
|
|
usersStore: root.usersStore
|
2022-01-04 13:06:05 +01:00
|
|
|
contactsStore: root.contactsStore
|
2022-03-14 15:32:52 -04:00
|
|
|
channelEmoji: root.channelEmoji
|
2022-04-13 12:59:16 +03:00
|
|
|
emojiPopup: root.emojiPopup
|
2022-11-14 15:21:00 -05:00
|
|
|
stickersPopup: root.stickersPopup
|
2022-07-25 14:43:05 +02:00
|
|
|
chatLogView: ListView.view
|
2022-01-04 13:06:05 +01:00
|
|
|
|
2022-06-29 12:50:10 -04:00
|
|
|
isActiveChannel: root.isActiveChannel
|
2022-02-24 13:15:02 +01:00
|
|
|
isChatBlocked: root.isChatBlocked
|
2022-07-05 14:12:27 +04:00
|
|
|
messageContextMenu: root.messageContextMenu
|
2021-12-09 13:53:40 +01:00
|
|
|
|
|
|
|
messageId: model.id
|
2022-02-24 10:04:59 -05:00
|
|
|
communityId: model.communityId
|
2021-12-09 13:53:40 +01:00
|
|
|
responseToMessageWithId: model.responseToMessageWithId
|
|
|
|
senderId: model.senderId
|
|
|
|
senderDisplayName: model.senderDisplayName
|
2022-09-14 09:35:26 +02:00
|
|
|
senderOptionalName: model.senderOptionalName
|
|
|
|
senderIsEnsVerified: model.senderEnsVerified
|
2021-12-09 13:53:40 +01:00
|
|
|
senderIcon: model.senderIcon
|
2023-01-10 13:29:24 +02:00
|
|
|
senderColorHash: model.senderColorHash
|
2022-03-04 16:33:48 -05:00
|
|
|
senderIsAdded: model.senderIsAdded
|
2022-09-30 17:36:49 +03:00
|
|
|
senderTrustStatus: model.senderTrustStatus
|
2021-12-09 13:53:40 +01:00
|
|
|
amISender: model.amISender
|
2022-07-05 14:12:27 +04:00
|
|
|
messageText: model.messageText
|
2023-01-06 15:19:27 -05:00
|
|
|
unparsedText: model.unparsedText
|
2021-12-09 13:53:40 +01:00
|
|
|
messageImage: model.messageImage
|
|
|
|
messageTimestamp: model.timestamp
|
|
|
|
messageOutgoingStatus: model.outgoingStatus
|
2022-12-08 16:01:08 -05:00
|
|
|
resendError: model.resendError
|
2021-12-09 13:53:40 +01:00
|
|
|
messageContentType: model.contentType
|
|
|
|
pinnedMessage: model.pinned
|
2022-01-05 16:50:03 +01:00
|
|
|
messagePinnedBy: model.pinnedBy
|
2021-12-20 15:21:35 +01:00
|
|
|
reactionsModel: model.reactions
|
2022-01-13 14:25:38 -05:00
|
|
|
sticker: model.sticker
|
|
|
|
stickerPack: model.stickerPack
|
2022-01-17 19:46:46 +01:00
|
|
|
editModeOn: model.editMode
|
2023-01-05 04:14:12 +01:00
|
|
|
onEditModeOnChanged: root.editModeChanged(editModeOn)
|
2022-01-17 19:46:46 +01:00
|
|
|
isEdited: model.isEdited
|
2022-01-25 13:56:53 +01:00
|
|
|
linkUrls: model.links
|
2022-09-15 09:31:38 +02:00
|
|
|
messageAttachments: model.messageAttachments
|
2022-02-09 01:04:49 +01:00
|
|
|
transactionParams: model.transactionParameters
|
2022-12-19 15:55:44 +01:00
|
|
|
hasMention: model.mentioned
|
2023-01-12 14:23:26 -05:00
|
|
|
quotedMessageText: model.quotedMessageParsedText
|
|
|
|
quotedMessageFrom: model.quotedMessageFrom
|
|
|
|
quotedMessageContentType: model.quotedMessageContentType
|
2023-01-11 16:16:35 -05:00
|
|
|
quotedMessageDeleted: model.quotedMessageDeleted
|
2023-01-10 13:29:24 +02:00
|
|
|
quotedMessageAuthorDetailsName: model.quotedMessageAuthorName
|
|
|
|
quotedMessageAuthorDetailsDisplayName: model.quotedMessageAuthorDisplayName
|
|
|
|
quotedMessageAuthorDetailsThumbnailImage: model.quotedMessageAuthorThumbnailImage
|
|
|
|
quotedMessageAuthorDetailsEnsVerified: model.quotedMessageAuthorEnsVerified
|
|
|
|
quotedMessageAuthorDetailsIsContact: model.quotedMessageAuthorIsContact
|
|
|
|
quotedMessageAuthorDetailsColorHash: model.quotedMessageAuthorColorHash
|
|
|
|
|
2022-02-25 11:42:32 +01:00
|
|
|
gapFrom: model.gapFrom
|
|
|
|
gapTo: model.gapTo
|
|
|
|
|
2023-01-10 13:29:24 +02:00
|
|
|
// 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.
|
|
|
|
// Also one important thing here is that messages are set in descending order
|
|
|
|
// in terms of `timestamp` of a message, that means a message with the most
|
|
|
|
// recent time is added at index 0.
|
|
|
|
prevMessageIndex: prevMsgIndex
|
|
|
|
prevMessageTimestamp: prevMsgTimestamp
|
|
|
|
prevMessageSenderId: prevMsgSenderId
|
|
|
|
prevMessageContentType: prevMsgContentType
|
|
|
|
nextMessageIndex: nextMsgIndex
|
|
|
|
nextMessageTimestamp: nextMsgTimestamp
|
2022-07-05 14:12:27 +04:00
|
|
|
|
2021-12-08 23:20:43 +02:00
|
|
|
onOpenStickerPackPopup: {
|
|
|
|
root.openStickerPackPopup(stickerPackId);
|
|
|
|
}
|
2022-01-05 16:50:03 +01:00
|
|
|
|
2022-01-12 15:55:26 +03:00
|
|
|
onShowReplyArea: {
|
|
|
|
root.showReplyArea(messageId, author)
|
|
|
|
}
|
|
|
|
|
2022-07-05 14:12:27 +04:00
|
|
|
onImageClicked: Global.openImagePopup(image, messageContextMenu)
|
2022-01-18 22:02:47 +01:00
|
|
|
|
2022-01-05 16:50:03 +01:00
|
|
|
stickersLoaded: root.stickersLoaded
|
2022-01-17 19:46:46 +01:00
|
|
|
|
|
|
|
onVisibleChanged: {
|
|
|
|
if(!visible && model.editMode)
|
|
|
|
messageStore.setEditModeOff(model.id)
|
|
|
|
}
|
2021-08-02 16:38:03 +03:00
|
|
|
}
|
2021-06-30 14:46:26 -04:00
|
|
|
}
|
2021-12-10 17:11:18 +01:00
|
|
|
|
2021-12-22 13:00:44 +01:00
|
|
|
MessageDialog {
|
|
|
|
id: sendingMsgFailedPopup
|
|
|
|
standardButtons: StandardButton.Ok
|
2022-04-04 13:26:30 +02:00
|
|
|
text: qsTr("Failed to send message.")
|
2021-12-22 13:00:44 +01:00
|
|
|
icon: StandardIcon.Critical
|
|
|
|
}
|
2020-05-27 18:59:17 -04:00
|
|
|
}
|