2023-04-19 17:31:18 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQml 2.15
|
2021-12-09 12:53:40 +00:00
|
|
|
import Qt.labs.platform 1.1
|
|
|
|
import QtQuick.Controls 2.13
|
|
|
|
import QtQuick.Layouts 1.13
|
|
|
|
import QtGraphicalEffects 1.0
|
|
|
|
|
|
|
|
import StatusQ.Core.Theme 0.1
|
2022-03-07 14:56:05 +00:00
|
|
|
import StatusQ.Core.Utils 0.1 as StatusQUtils
|
2021-12-09 12:53:40 +00:00
|
|
|
import StatusQ.Components 0.1
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
|
|
|
|
import utils 1.0
|
|
|
|
import shared 1.0
|
|
|
|
import shared.popups 1.0
|
|
|
|
import shared.status 1.0
|
|
|
|
import shared.controls 1.0
|
|
|
|
import shared.views.chat 1.0
|
|
|
|
|
|
|
|
import "../helpers"
|
|
|
|
import "../controls"
|
|
|
|
import "../popups"
|
|
|
|
import "../panels"
|
|
|
|
import "../../Wallet"
|
|
|
|
import "../stores"
|
|
|
|
|
|
|
|
ColumnLayout {
|
2022-05-10 16:04:25 +00:00
|
|
|
id: root
|
2022-07-21 16:16:25 +00:00
|
|
|
objectName: "chatContentViewColumn"
|
2021-12-09 12:53:40 +00:00
|
|
|
spacing: 0
|
|
|
|
|
|
|
|
// Important:
|
|
|
|
// Each chat/channel has its own ChatContentModule
|
|
|
|
property var chatContentModule
|
2022-05-10 16:04:25 +00:00
|
|
|
property var chatSectionModule
|
2021-12-22 14:55:13 +00:00
|
|
|
property var rootStore
|
2022-01-04 12:06:05 +00:00
|
|
|
property var contactsStore
|
2022-02-28 20:14:04 +00:00
|
|
|
property bool isActiveChannel: false
|
2023-04-18 18:23:57 +00:00
|
|
|
property string chatId
|
2023-04-27 14:21:41 +00:00
|
|
|
property int chatType: Constants.chatType.unknown
|
2023-03-10 17:33:26 +00:00
|
|
|
|
2023-04-17 20:43:23 +00:00
|
|
|
readonly property alias chatMessagesLoader: chatMessagesLoader
|
|
|
|
|
2022-03-07 14:56:05 +00:00
|
|
|
property var emojiPopup
|
2022-11-14 20:21:00 +00:00
|
|
|
property var stickersPopup
|
2022-02-08 12:08:02 +00:00
|
|
|
property UsersStore usersStore: UsersStore {}
|
|
|
|
|
2023-04-19 17:31:18 +00:00
|
|
|
onChatContentModuleChanged: if (!!chatContentModule) {
|
2022-05-10 16:04:25 +00:00
|
|
|
root.usersStore.usersModule = root.chatContentModule.usersModule
|
2022-02-08 12:08:02 +00:00
|
|
|
}
|
|
|
|
|
2022-05-10 16:04:25 +00:00
|
|
|
signal openAppSearch()
|
2022-02-14 23:27:23 +00:00
|
|
|
signal openStickerPackPopup(string stickerPackId)
|
2021-12-09 12:53:40 +00:00
|
|
|
|
2021-12-23 20:46:58 +00:00
|
|
|
property Component sendTransactionNoEnsModal
|
|
|
|
property Component receiveTransactionModal
|
|
|
|
property Component sendTransactionWithEnsModal
|
|
|
|
|
2022-02-04 10:21:05 +00:00
|
|
|
property bool isBlocked: false
|
|
|
|
|
2022-01-05 15:50:03 +00:00
|
|
|
property bool stickersLoaded: false
|
|
|
|
|
2023-04-18 18:23:57 +00:00
|
|
|
QtObject {
|
|
|
|
id: d
|
|
|
|
|
|
|
|
property bool isUserAdded
|
|
|
|
|
|
|
|
function updateIsUserAdded() {
|
2023-04-27 14:21:41 +00:00
|
|
|
if (root.chatType !== Constants.chatType.oneToOne) {
|
2023-04-20 19:45:13 +00:00
|
|
|
return false
|
|
|
|
}
|
2023-04-18 18:23:57 +00:00
|
|
|
isUserAdded = Qt.binding(() => {isActiveChannel; return Utils.getContactDetailsAsJson(root.chatId, false).isAdded})
|
|
|
|
}
|
|
|
|
|
|
|
|
Component.onCompleted: updateIsUserAdded()
|
|
|
|
}
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
target: root.contactsStore.myContactsModel
|
|
|
|
|
|
|
|
function onItemChanged(pubKey) {
|
|
|
|
if (pubKey === root.chatId) {
|
|
|
|
d.updateIsUserAdded()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-06 15:43:54 +00:00
|
|
|
Loader {
|
2021-12-09 12:53:40 +00:00
|
|
|
Layout.fillWidth: true
|
2023-01-06 15:43:54 +00:00
|
|
|
active: root.isBlocked
|
|
|
|
visible: active
|
|
|
|
sourceComponent: StatusBanner {
|
|
|
|
type: StatusBanner.Type.Danger
|
|
|
|
statusText: qsTr("Blocked")
|
|
|
|
}
|
2021-12-09 12:53:40 +00:00
|
|
|
}
|
|
|
|
|
2023-04-17 20:43:23 +00:00
|
|
|
readonly property var messageStore: MessageStore {
|
2022-09-30 14:36:49 +00:00
|
|
|
messageModule: chatContentModule ? chatContentModule.messagesModule : null
|
2022-05-10 16:04:25 +00:00
|
|
|
chatSectionModule: root.rootStore.chatCommunitySectionModule
|
2021-12-14 14:19:55 +00:00
|
|
|
}
|
|
|
|
|
2023-04-19 17:31:18 +00:00
|
|
|
Loader {
|
|
|
|
id: contextMenuLoader
|
|
|
|
active: root.isActiveChannel
|
|
|
|
asynchronous: true
|
|
|
|
|
|
|
|
// FIXME: `MessageContextMenuView` is way too heavy
|
|
|
|
// see: https://github.com/status-im/status-desktop/pull/10343#issuecomment-1515103756
|
|
|
|
sourceComponent: MessageContextMenuView {
|
|
|
|
store: root.rootStore
|
|
|
|
reactionModel: root.rootStore.emojiReactionsModel
|
|
|
|
disabledForChat: chatType === Constants.chatType.oneToOne && !d.isUserAdded
|
|
|
|
|
|
|
|
onPinMessage: {
|
|
|
|
messageStore.pinMessage(messageId)
|
|
|
|
}
|
2021-12-14 14:19:55 +00:00
|
|
|
|
2023-04-19 17:31:18 +00:00
|
|
|
onUnpinMessage: {
|
|
|
|
messageStore.unpinMessage(messageId)
|
|
|
|
}
|
2021-12-17 12:53:10 +00:00
|
|
|
|
2023-04-19 17:31:18 +00:00
|
|
|
onPinnedMessagesLimitReached: {
|
|
|
|
if(!chatContentModule) {
|
|
|
|
console.warn("error on open pinned messages limit reached from message context menu - chat content module is not set")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
Global.openPinnedMessagesPopupRequested(rootStore, messageStore, chatContentModule.pinnedMessagesModel, messageId, root.chatId)
|
2022-01-11 23:16:17 +00:00
|
|
|
}
|
2021-12-20 14:21:35 +00:00
|
|
|
|
2023-04-19 17:31:18 +00:00
|
|
|
onToggleReaction: {
|
|
|
|
messageStore.toggleReaction(messageId, emojiId)
|
|
|
|
}
|
2022-01-05 15:50:03 +00:00
|
|
|
|
2023-04-19 17:31:18 +00:00
|
|
|
onOpenProfileClicked: {
|
|
|
|
Global.openProfilePopup(publicKey, null)
|
|
|
|
}
|
2022-01-13 15:14:34 +00:00
|
|
|
|
2023-04-19 17:31:18 +00:00
|
|
|
onDeleteMessage: {
|
|
|
|
messageStore.deleteMessage(messageId)
|
|
|
|
}
|
2022-01-17 18:46:46 +00:00
|
|
|
|
2023-04-19 17:31:18 +00:00
|
|
|
onEditClicked: messageStore.setEditModeOn(messageId)
|
2022-01-26 19:54:33 +00:00
|
|
|
|
2023-04-19 17:31:18 +00:00
|
|
|
onCreateOneToOneChat: {
|
|
|
|
Global.changeAppSectionBySectionType(Constants.appSection.chat)
|
|
|
|
root.rootStore.chatCommunitySectionModule.createOneToOneChat("", chatId, ensName)
|
|
|
|
}
|
|
|
|
onShowReplyArea: {
|
|
|
|
let obj = messageStore.getMessageByIdAsJson(messageId)
|
|
|
|
if (!obj) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (inputAreaLoader.item) {
|
2023-04-27 12:35:16 +00:00
|
|
|
inputAreaLoader.item.chatInput.showReplyArea(messageId, obj.senderDisplayName, obj.messageText, obj.contentType, obj.messageImage, obj.albumMessageImages, obj.albumImagesCount, obj.sticker)
|
2023-04-19 17:31:18 +00:00
|
|
|
}
|
2022-04-12 15:15:14 +00:00
|
|
|
}
|
|
|
|
}
|
2021-12-14 14:19:55 +00:00
|
|
|
}
|
|
|
|
|
2021-12-09 12:53:40 +00:00
|
|
|
ColumnLayout {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
|
|
|
clip: true
|
|
|
|
|
2023-04-17 20:43:23 +00:00
|
|
|
Loader {
|
|
|
|
id: chatMessagesLoader
|
2021-12-09 12:53:40 +00:00
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
2023-04-17 20:43:23 +00:00
|
|
|
|
|
|
|
sourceComponent: ChatMessagesView {
|
|
|
|
chatContentModule: root.chatContentModule
|
|
|
|
rootStore: root.rootStore
|
|
|
|
contactsStore: root.contactsStore
|
2023-04-19 17:31:18 +00:00
|
|
|
messageContextMenu: contextMenuLoader.item
|
2023-04-17 20:43:23 +00:00
|
|
|
messageStore: root.messageStore
|
|
|
|
emojiPopup: root.emojiPopup
|
|
|
|
stickersPopup: root.stickersPopup
|
|
|
|
usersStore: root.usersStore
|
|
|
|
stickersLoaded: root.stickersLoaded
|
2023-04-27 14:21:41 +00:00
|
|
|
isChatBlocked: root.isBlocked || (root.chatType === Constants.chatType.oneToOne && !d.isUserAdded)
|
2023-04-17 20:43:23 +00:00
|
|
|
channelEmoji: !chatContentModule ? "" : (chatContentModule.chatDetails.emoji || "")
|
|
|
|
isActiveChannel: root.isActiveChannel
|
|
|
|
onShowReplyArea: {
|
|
|
|
let obj = messageStore.getMessageByIdAsJson(messageId)
|
|
|
|
if (!obj) {
|
|
|
|
return
|
|
|
|
}
|
2023-04-19 17:31:18 +00:00
|
|
|
if (inputAreaLoader.item) {
|
2023-04-27 12:35:16 +00:00
|
|
|
inputAreaLoader.item.chatInput.showReplyArea(messageId, obj.senderDisplayName, obj.messageText, obj.contentType, obj.messageImage, obj.albumMessageImages, obj.albumImagesCount, obj.sticker)
|
2023-04-19 17:31:18 +00:00
|
|
|
}
|
2022-01-12 12:55:26 +00:00
|
|
|
}
|
2023-04-17 20:43:23 +00:00
|
|
|
onOpenStickerPackPopup: {
|
|
|
|
root.openStickerPackPopup(stickerPackId);
|
|
|
|
}
|
2023-04-19 17:31:18 +00:00
|
|
|
onEditModeChanged: if (!editModeOn && inputAreaLoader.item) inputAreaLoader.item.chatInput.forceInputActiveFocus()
|
2022-01-12 12:55:26 +00:00
|
|
|
}
|
2021-12-09 12:53:40 +00:00
|
|
|
}
|
|
|
|
|
2023-04-19 17:31:18 +00:00
|
|
|
Loader {
|
|
|
|
id: inputAreaLoader
|
|
|
|
|
2021-12-09 12:53:40 +00:00
|
|
|
Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom
|
|
|
|
Layout.fillWidth: true
|
2022-07-05 10:12:27 +00:00
|
|
|
|
2023-04-19 17:31:18 +00:00
|
|
|
active: root.isActiveChannel
|
|
|
|
asynchronous: true
|
2022-09-22 07:13:03 +00:00
|
|
|
|
2023-04-19 17:31:18 +00:00
|
|
|
property string preservedText
|
|
|
|
Binding on preservedText {
|
|
|
|
when: inputAreaLoader.item != null
|
|
|
|
value: inputAreaLoader.item ? inputAreaLoader.item.chatInput.textInput.text : inputAreaLoader.preservedText
|
|
|
|
restoreMode: Binding.RestoreNone
|
|
|
|
delayed: true
|
|
|
|
}
|
2022-07-15 10:32:26 +00:00
|
|
|
|
2023-04-19 17:31:18 +00:00
|
|
|
// FIXME: `StatusChatInput` is way too heavy
|
|
|
|
// see: https://github.com/status-im/status-desktop/pull/10343#issuecomment-1515103756
|
|
|
|
sourceComponent: Item {
|
|
|
|
id: inputArea
|
|
|
|
implicitHeight: chatInput.implicitHeight
|
|
|
|
+ chatInput.anchors.topMargin
|
|
|
|
+ chatInput.anchors.bottomMargin
|
|
|
|
|
|
|
|
readonly property alias chatInput: chatInput
|
|
|
|
|
|
|
|
StatusChatInput {
|
|
|
|
id: chatInput
|
|
|
|
|
|
|
|
anchors.fill: parent
|
|
|
|
anchors.margins: Style.current.smallPadding
|
|
|
|
|
|
|
|
enabled: root.rootStore.sectionDetails.joined && !root.rootStore.sectionDetails.amIBanned &&
|
|
|
|
!(chatType === Constants.chatType.oneToOne && !d.isUserAdded)
|
|
|
|
|
|
|
|
store: root.rootStore
|
|
|
|
usersStore: root.usersStore
|
|
|
|
|
|
|
|
textInput.text: inputAreaLoader.preservedText
|
|
|
|
messageContextMenu: contextMenuLoader.item
|
|
|
|
emojiPopup: root.emojiPopup
|
|
|
|
stickersPopup: root.stickersPopup
|
|
|
|
isContactBlocked: root.isBlocked
|
|
|
|
isActiveChannel: root.isActiveChannel
|
|
|
|
anchors.bottom: parent.bottom
|
2023-04-27 14:21:41 +00:00
|
|
|
chatType: root.chatType
|
|
|
|
suggestions.suggestionFilter.addSystemSuggestions: chatType === Constants.chatType.communityChat
|
2023-04-19 17:31:18 +00:00
|
|
|
|
|
|
|
Binding on chatInputPlaceholder {
|
|
|
|
when: root.isBlocked
|
|
|
|
value: qsTr("This user has been blocked.")
|
|
|
|
}
|
2022-09-22 07:13:03 +00:00
|
|
|
|
2023-04-19 17:31:18 +00:00
|
|
|
Binding on chatInputPlaceholder {
|
|
|
|
when: !root.rootStore.sectionDetails.joined || root.rootStore.sectionDetails.amIBanned
|
|
|
|
value: qsTr("You need to join this community to send messages")
|
2022-01-11 23:16:17 +00:00
|
|
|
}
|
|
|
|
|
2023-04-19 17:31:18 +00:00
|
|
|
onSendTransactionCommandButtonClicked: {
|
|
|
|
if(!chatContentModule) {
|
|
|
|
console.debug("error on sending transaction command - chat content module is not set")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Utils.isEnsVerified(chatContentModule.getMyChatId())) {
|
|
|
|
Global.openPopup(root.sendTransactionWithEnsModal)
|
|
|
|
} else {
|
|
|
|
Global.openPopup(root.sendTransactionNoEnsModal)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
onReceiveTransactionCommandButtonClicked: {
|
|
|
|
Global.openPopup(root.receiveTransactionModal)
|
|
|
|
}
|
|
|
|
onStickerSelected: {
|
|
|
|
root.rootStore.sendSticker(chatContentModule.getMyChatId(),
|
|
|
|
hashId,
|
|
|
|
chatInput.isReply ? chatInput.replyMessageId : "",
|
|
|
|
packId,
|
|
|
|
url)
|
2021-12-23 20:46:58 +00:00
|
|
|
}
|
2022-01-11 23:16:17 +00:00
|
|
|
|
2022-02-15 21:00:05 +00:00
|
|
|
|
2023-04-19 17:31:18 +00:00
|
|
|
onSendMessage: {
|
|
|
|
if (!chatContentModule) {
|
|
|
|
console.debug("error on sending message - chat content module is not set")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if(root.rootStore.sendMessage(chatContentModule.getMyChatId(),
|
|
|
|
event,
|
|
|
|
chatInput.getTextWithPublicKeys(),
|
|
|
|
chatInput.isReply? chatInput.replyMessageId : "",
|
|
|
|
chatInput.fileUrlsAndSources
|
|
|
|
))
|
|
|
|
{
|
|
|
|
Global.playSendMessageSound()
|
|
|
|
|
|
|
|
chatInput.textInput.clear();
|
|
|
|
chatInput.textInput.textFormat = TextEdit.PlainText;
|
|
|
|
chatInput.textInput.textFormat = TextEdit.RichText;
|
|
|
|
}
|
2022-03-22 08:29:58 +00:00
|
|
|
}
|
|
|
|
|
2023-04-19 17:31:18 +00:00
|
|
|
onUnblockChat: {
|
|
|
|
chatContentModule.unblockChat()
|
2021-12-22 14:55:13 +00:00
|
|
|
}
|
2023-04-19 17:31:18 +00:00
|
|
|
onKeyUpPress: messageStore.setEditModeOnLastMessage(root.rootStore.userProfileInst.pubKey)
|
2022-02-24 12:15:02 +00:00
|
|
|
|
2023-04-19 17:31:18 +00:00
|
|
|
Component.onCompleted: {
|
|
|
|
Qt.callLater(() => {
|
|
|
|
forceInputActiveFocus()
|
|
|
|
textInput.cursorPosition = textInput.length
|
|
|
|
})
|
|
|
|
}
|
2022-02-24 12:15:02 +00:00
|
|
|
}
|
2021-12-09 12:53:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|