2021-12-09 12:53:40 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
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
|
2022-03-07 14:56:05 +00:00
|
|
|
property var emojiPopup
|
2022-11-14 20:21:00 +00:00
|
|
|
property var stickersPopup
|
2022-02-15 21:00:05 +00:00
|
|
|
property alias textInputField: chatInput
|
2022-02-08 12:08:02 +00:00
|
|
|
property UsersStore usersStore: UsersStore {}
|
|
|
|
|
|
|
|
onChatContentModuleChanged: {
|
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
|
|
|
|
|
2022-09-22 07:13:03 +00:00
|
|
|
// FIXME: this should be section data related only to that view, not the active one
|
|
|
|
readonly property var activeSectionData: rootStore.mainModuleInst ? rootStore.mainModuleInst.activeSection || {} : {}
|
|
|
|
|
2022-01-27 17:14:21 +00:00
|
|
|
// NOTE: Used this property change as it is the current way used for displaying new channel/chat data of content view.
|
|
|
|
// If in the future content is loaded dynamically, input focus should be activated when loaded / created content view.
|
|
|
|
onHeightChanged: {
|
2022-05-10 16:04:25 +00:00
|
|
|
if(root.height > 0) {
|
2022-01-27 17:14:21 +00:00
|
|
|
chatInput.forceInputActiveFocus()
|
|
|
|
}
|
2022-07-21 06:42:32 +00:00
|
|
|
}
|
2022-05-13 17:11:02 +00:00
|
|
|
|
2022-02-04 10:21:05 +00:00
|
|
|
StatusBanner {
|
2021-12-09 12:53:40 +00:00
|
|
|
Layout.fillWidth: true
|
2022-05-10 16:04:25 +00:00
|
|
|
visible: root.isBlocked
|
2022-02-04 10:21:05 +00:00
|
|
|
type: StatusBanner.Type.Danger
|
|
|
|
statusText: qsTr("Blocked")
|
2021-12-09 12:53:40 +00:00
|
|
|
}
|
|
|
|
|
2022-01-20 12:15:36 +00:00
|
|
|
MessageStore {
|
2021-12-14 14:19:55 +00:00
|
|
|
id: 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
|
|
|
}
|
|
|
|
|
|
|
|
MessageContextMenuView {
|
|
|
|
id: contextmenu
|
2022-05-10 16:04:25 +00:00
|
|
|
store: root.rootStore
|
|
|
|
reactionModel: root.rootStore.emojiReactionsModel
|
2021-12-14 14:19:55 +00:00
|
|
|
onPinMessage: {
|
|
|
|
messageStore.pinMessage(messageId)
|
|
|
|
}
|
|
|
|
|
|
|
|
onUnpinMessage: {
|
|
|
|
messageStore.unpinMessage(messageId)
|
|
|
|
}
|
2021-12-17 12:53:10 +00:00
|
|
|
|
|
|
|
onPinnedMessagesLimitReached: {
|
2022-01-11 23:16:17 +00:00
|
|
|
if(!chatContentModule) {
|
2022-09-12 16:35:20 +00:00
|
|
|
console.warn("error on open pinned messages limit reached from message context menu - chat content module is not set")
|
2022-01-11 23:16:17 +00:00
|
|
|
return
|
|
|
|
}
|
2022-05-10 16:04:25 +00:00
|
|
|
Global.openPopup(Global.pinnedMessagesPopup, {
|
2022-01-19 15:59:08 +00:00
|
|
|
store: rootStore,
|
2022-01-12 12:55:26 +00:00
|
|
|
messageStore: messageStore,
|
|
|
|
pinnedMessagesModel: chatContentModule.pinnedMessagesModel,
|
|
|
|
messageToPin: messageId
|
|
|
|
})
|
2021-12-17 12:53:10 +00:00
|
|
|
}
|
2021-12-20 14:21:35 +00:00
|
|
|
|
|
|
|
onToggleReaction: {
|
|
|
|
messageStore.toggleReaction(messageId, emojiId)
|
|
|
|
}
|
2022-01-05 15:50:03 +00:00
|
|
|
|
|
|
|
onOpenProfileClicked: {
|
2022-09-27 21:26:26 +00:00
|
|
|
Global.openProfilePopup(publicKey, null)
|
2022-01-05 15:50:03 +00:00
|
|
|
}
|
2022-01-13 15:14:34 +00:00
|
|
|
|
|
|
|
onDeleteMessage: {
|
|
|
|
messageStore.deleteMessage(messageId)
|
|
|
|
}
|
2022-01-17 18:46:46 +00:00
|
|
|
|
|
|
|
onEditClicked: messageStore.setEditModeOn(messageId)
|
2022-01-26 19:54:33 +00:00
|
|
|
|
|
|
|
onCreateOneToOneChat: {
|
|
|
|
Global.changeAppSectionBySectionType(Constants.appSection.chat)
|
2022-02-15 21:00:05 +00:00
|
|
|
root.rootStore.chatCommunitySectionModule.createOneToOneChat("", chatId, ensName)
|
2022-01-26 19:54:33 +00:00
|
|
|
}
|
2022-04-12 15:15:14 +00:00
|
|
|
onShowReplyArea: {
|
|
|
|
let obj = messageStore.getMessageByIdAsJson(messageId)
|
|
|
|
if (!obj) {
|
|
|
|
return
|
|
|
|
}
|
2022-07-21 06:42:32 +00:00
|
|
|
chatInput.showReplyArea(messageId, obj.senderDisplayName, obj.messageText, obj.contentType, obj.messageImage, obj.sticker)
|
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
|
|
|
|
|
|
|
|
ChatMessagesView {
|
|
|
|
id: chatMessages
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
2022-07-05 10:12:27 +00:00
|
|
|
chatContentModule: root.chatContentModule
|
|
|
|
rootStore: root.rootStore
|
2022-05-10 16:04:25 +00:00
|
|
|
contactsStore: root.contactsStore
|
2022-07-05 10:12:27 +00:00
|
|
|
messageContextMenu: contextmenu
|
2021-12-14 14:19:55 +00:00
|
|
|
messageStore: messageStore
|
2022-05-10 16:04:25 +00:00
|
|
|
emojiPopup: root.emojiPopup
|
2022-11-14 20:21:00 +00:00
|
|
|
stickersPopup: root.stickersPopup
|
2022-05-10 16:04:25 +00:00
|
|
|
usersStore: root.usersStore
|
|
|
|
stickersLoaded: root.stickersLoaded
|
|
|
|
isChatBlocked: root.isBlocked
|
2022-07-05 10:12:27 +00:00
|
|
|
channelEmoji: !chatContentModule ? "" : (chatContentModule.chatDetails.emoji || "")
|
2022-05-10 16:04:25 +00:00
|
|
|
isActiveChannel: root.isActiveChannel
|
2022-01-12 12:55:26 +00:00
|
|
|
onShowReplyArea: {
|
|
|
|
let obj = messageStore.getMessageByIdAsJson(messageId)
|
|
|
|
if (!obj) {
|
|
|
|
return
|
|
|
|
}
|
2022-07-21 06:42:32 +00:00
|
|
|
chatInput.showReplyArea(messageId, obj.senderDisplayName, obj.messageText, obj.contentType, obj.messageImage, obj.sticker)
|
2022-02-14 23:27:23 +00:00
|
|
|
}
|
|
|
|
onOpenStickerPackPopup: {
|
|
|
|
root.openStickerPackPopup(stickerPackId);
|
2022-01-12 12:55:26 +00:00
|
|
|
}
|
2023-01-05 03:14:12 +00:00
|
|
|
onEditModeChanged: if (!editModeOn) chatInput.forceInputActiveFocus()
|
2021-12-09 12:53:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: inputArea
|
|
|
|
Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom
|
|
|
|
Layout.fillWidth: true
|
2022-07-05 10:12:27 +00:00
|
|
|
Layout.preferredHeight: chatInput.implicitHeight
|
|
|
|
+ chatInput.anchors.topMargin
|
|
|
|
+ chatInput.anchors.bottomMargin
|
2021-12-09 12:53:40 +00:00
|
|
|
|
|
|
|
StatusChatInput {
|
|
|
|
id: chatInput
|
2022-07-05 10:12:27 +00:00
|
|
|
|
|
|
|
anchors.fill: parent
|
|
|
|
anchors.margins: Style.current.smallPadding
|
|
|
|
|
2022-12-18 20:29:18 +00:00
|
|
|
enabled: root.activeSectionData.joined && !root.activeSectionData.amIBanned
|
2022-09-22 07:13:03 +00:00
|
|
|
|
2022-05-10 16:04:25 +00:00
|
|
|
store: root.rootStore
|
|
|
|
usersStore: root.usersStore
|
2022-02-08 12:08:02 +00:00
|
|
|
|
2022-02-01 13:10:24 +00:00
|
|
|
messageContextMenu: contextmenu
|
2022-05-10 16:04:25 +00:00
|
|
|
emojiPopup: root.emojiPopup
|
2022-11-14 20:21:00 +00:00
|
|
|
stickersPopup: root.stickersPopup
|
2022-05-10 16:04:25 +00:00
|
|
|
isContactBlocked: root.isBlocked
|
|
|
|
isActiveChannel: root.isActiveChannel
|
2021-12-09 12:53:40 +00:00
|
|
|
anchors.bottom: parent.bottom
|
2022-01-11 23:16:17 +00:00
|
|
|
chatType: chatContentModule? chatContentModule.chatDetails.type : Constants.chatType.unknown
|
2022-12-19 14:55:44 +00:00
|
|
|
suggestions.suggestionFilter.addSystemSuggestions: chatType == Constants.chatType.communityChat
|
2022-07-15 10:32:26 +00:00
|
|
|
|
|
|
|
Binding on chatInputPlaceholder {
|
|
|
|
when: root.isBlocked
|
|
|
|
value: qsTr("This user has been blocked.")
|
|
|
|
}
|
|
|
|
|
2022-09-22 07:13:03 +00:00
|
|
|
Binding on chatInputPlaceholder {
|
2022-12-18 20:29:18 +00:00
|
|
|
when: !root.activeSectionData.joined || root.activeSectionData.amIBanned
|
2022-09-22 07:13:03 +00:00
|
|
|
value: qsTr("You need to join this community to send messages")
|
|
|
|
}
|
|
|
|
|
2021-12-09 12:53:40 +00:00
|
|
|
onSendTransactionCommandButtonClicked: {
|
2022-01-11 23:16:17 +00:00
|
|
|
if(!chatContentModule) {
|
|
|
|
console.debug("error on sending transaction command - chat content module is not set")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-12-01 10:24:25 +00:00
|
|
|
if (Utils.isEnsVerified(chatContentModule.getMyChatId())) {
|
2022-05-10 16:04:25 +00:00
|
|
|
Global.openPopup(root.sendTransactionWithEnsModal)
|
2021-12-23 20:46:58 +00:00
|
|
|
} else {
|
2022-05-10 16:04:25 +00:00
|
|
|
Global.openPopup(root.sendTransactionNoEnsModal)
|
2021-12-23 20:46:58 +00:00
|
|
|
}
|
2021-12-09 12:53:40 +00:00
|
|
|
}
|
|
|
|
onReceiveTransactionCommandButtonClicked: {
|
2022-05-10 16:04:25 +00:00
|
|
|
Global.openPopup(root.receiveTransactionModal)
|
2021-12-09 12:53:40 +00:00
|
|
|
}
|
|
|
|
onStickerSelected: {
|
2022-05-10 16:04:25 +00:00
|
|
|
root.rootStore.sendSticker(chatContentModule.getMyChatId(),
|
2022-01-12 12:55:26 +00:00
|
|
|
hashId,
|
2022-05-19 17:32:40 +00:00
|
|
|
chatInput.isReply ? chatInput.replyMessageId : "",
|
2022-08-10 19:18:20 +00:00
|
|
|
packId,
|
|
|
|
url)
|
2021-12-09 12:53:40 +00:00
|
|
|
}
|
2022-01-11 23:16:17 +00:00
|
|
|
|
2022-02-15 21:00:05 +00:00
|
|
|
|
|
|
|
onSendMessage: {
|
2022-03-22 08:29:58 +00:00
|
|
|
if (!chatContentModule) {
|
|
|
|
console.debug("error on sending message - chat content module is not set")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-05-10 16:04:25 +00:00
|
|
|
if(root.rootStore.sendMessage(event,
|
2022-09-20 15:26:54 +00:00
|
|
|
chatInput.getTextWithPublicKeys(),
|
|
|
|
chatInput.isReply? chatInput.replyMessageId : "",
|
2022-11-25 14:08:12 +00:00
|
|
|
chatInput.fileUrlsAndSources
|
2022-09-20 15:26:54 +00:00
|
|
|
))
|
2022-03-22 08:29:58 +00:00
|
|
|
{
|
2022-05-10 16:04:25 +00:00
|
|
|
Global.sendMessageSound.stop();
|
|
|
|
Qt.callLater(Global.sendMessageSound.play);
|
2022-03-22 08:29:58 +00:00
|
|
|
|
|
|
|
chatInput.textInput.clear();
|
|
|
|
chatInput.textInput.textFormat = TextEdit.PlainText;
|
|
|
|
chatInput.textInput.textFormat = TextEdit.RichText;
|
2021-12-22 14:55:13 +00:00
|
|
|
}
|
2021-12-09 12:53:40 +00:00
|
|
|
}
|
2022-02-24 12:15:02 +00:00
|
|
|
|
|
|
|
onUnblockChat: {
|
|
|
|
chatContentModule.unblockChat()
|
|
|
|
}
|
2022-12-21 12:52:52 +00:00
|
|
|
onKeyUpPress: messageStore.setEditModeOnLastMessage(root.rootStore.userProfileInst.pubKey)
|
2021-12-09 12:53:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|