2023-02-08 16:45:54 +02:00
|
|
|
import QtQuick 2.14
|
|
|
|
import QtQuick.Controls 2.14
|
|
|
|
import QtQml 2.14
|
2021-07-06 11:42:51 +02:00
|
|
|
|
|
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
import StatusQ.Components 0.1
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
|
2021-09-28 18:04:06 +03:00
|
|
|
import utils 1.0
|
2021-10-28 00:27:49 +03:00
|
|
|
import shared 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
|
2020-05-25 16:34:26 -04:00
|
|
|
|
2021-10-01 18:58:36 +03:00
|
|
|
import "../helpers"
|
|
|
|
import "../controls"
|
|
|
|
import "../popups"
|
|
|
|
import "../panels"
|
|
|
|
import "../../Wallet"
|
2021-07-16 18:02:47 +03:00
|
|
|
|
|
|
|
Item {
|
2021-10-22 01:39:53 +03:00
|
|
|
id: root
|
2021-12-01 17:47:57 +01:00
|
|
|
|
|
|
|
// Important: we have parent module in this context only cause qml components
|
2021-12-09 13:53:40 +01:00
|
|
|
// don't follow struct we have on the backend.
|
2021-12-01 17:47:57 +01:00
|
|
|
property var parentModule
|
|
|
|
|
2021-10-01 18:58:36 +03:00
|
|
|
property var rootStore
|
2023-05-04 14:36:35 -04:00
|
|
|
property var createChatPropertiesStore
|
2022-01-04 13:06:05 +01:00
|
|
|
property var contactsStore
|
2022-03-07 09:56:05 -05:00
|
|
|
property var emojiPopup
|
2022-11-14 15:21:00 -05:00
|
|
|
property var stickersPopup
|
2022-01-04 13:06:05 +01:00
|
|
|
|
2021-12-16 15:02:58 -05:00
|
|
|
property string activeChatId: parentModule && parentModule.activeItem.id
|
2022-06-30 22:25:04 +03:00
|
|
|
property int chatsCount: parentModule && parentModule.model ? parentModule.model.count : 0
|
2023-01-27 10:24:00 -05:00
|
|
|
property int activeChatType: parentModule && parentModule.activeItem.type
|
2021-12-08 23:20:43 +02:00
|
|
|
property bool stickersLoaded: false
|
2023-03-15 13:30:18 +05:30
|
|
|
property var contactDetails: null
|
2023-01-27 10:24:00 -05:00
|
|
|
property bool isUserAdded: root.contactDetails && root.contactDetails.isAdded
|
2022-01-04 13:06:05 +01:00
|
|
|
|
2021-11-10 09:09:31 +01:00
|
|
|
signal openAppSearch()
|
2021-12-08 23:20:43 +02:00
|
|
|
signal openStickerPackPopup(string stickerPackId)
|
2021-11-10 09:09:31 +01:00
|
|
|
|
2020-09-29 11:06:57 +02:00
|
|
|
function requestAddressForTransaction(address, amount, tokenAddress, tokenDecimals = 18) {
|
2021-12-14 17:11:31 +01:00
|
|
|
amount = globalUtils.eth2Wei(amount.toString(), tokenDecimals)
|
2021-12-23 15:46:58 -05:00
|
|
|
|
|
|
|
parentModule.prepareChatContentModuleForChatId(activeChatId)
|
|
|
|
let chatContentModule = parentModule.getChatContentModule()
|
|
|
|
chatContentModule.inputAreaModule.requestAddress(address,
|
|
|
|
amount,
|
|
|
|
tokenAddress)
|
2020-07-20 13:04:33 -04:00
|
|
|
}
|
2020-09-29 11:06:57 +02:00
|
|
|
function requestTransaction(address, amount, tokenAddress, tokenDecimals = 18) {
|
2021-12-23 15:46:58 -05:00
|
|
|
amount = globalUtils.eth2Wei(amount.toString(), tokenDecimals)
|
|
|
|
|
|
|
|
|
|
|
|
parentModule.prepareChatContentModuleForChatId(activeChatId)
|
|
|
|
let chatContentModule = parentModule.getChatContentModule()
|
|
|
|
chatContentModule.inputAreaModule.request(address,
|
|
|
|
amount,
|
|
|
|
tokenAddress)
|
2020-07-20 13:04:33 -04:00
|
|
|
}
|
2020-09-29 11:06:57 +02:00
|
|
|
|
2022-03-22 09:29:58 +01:00
|
|
|
// This function is called once `1:1` or `group` chat is created.
|
|
|
|
function checkForCreateChatOptions(chatId) {
|
2023-05-04 14:36:35 -04:00
|
|
|
if(root.createChatPropertiesStore.createChatStartSendTransactionProcess) {
|
2022-12-01 11:24:25 +01:00
|
|
|
if (root.contactDetails.ensVerified) {
|
2022-03-22 09:29:58 +01:00
|
|
|
Global.openPopup(cmpSendTransactionWithEns);
|
|
|
|
} else {
|
|
|
|
Global.openPopup(cmpSendTransactionNoEns);
|
|
|
|
}
|
|
|
|
}
|
2023-05-04 14:36:35 -04:00
|
|
|
else if (root.createChatPropertiesStore.createChatStartSendTransactionProcess) {
|
2022-03-22 09:29:58 +01:00
|
|
|
Global.openPopup(cmpReceiveTransaction);
|
|
|
|
}
|
2023-05-04 14:36:35 -04:00
|
|
|
else if (root.createChatPropertiesStore.createChatStickerHashId !== "" &&
|
|
|
|
root.createChatPropertiesStore.createChatStickerPackId !== "" &&
|
|
|
|
root.createChatPropertiesStore.createChatStickerUrl !== "") {
|
2022-03-22 09:29:58 +01:00
|
|
|
root.rootStore.sendSticker(chatId,
|
2023-05-04 14:36:35 -04:00
|
|
|
root.createChatPropertiesStore.createChatStickerHashId,
|
2022-03-22 09:29:58 +01:00
|
|
|
"",
|
2023-05-04 14:36:35 -04:00
|
|
|
root.createChatPropertiesStore.createChatStickerPackId,
|
|
|
|
root.createChatPropertiesStore.createChatStickerUrl);
|
2022-03-22 09:29:58 +01:00
|
|
|
}
|
2023-05-04 14:36:35 -04:00
|
|
|
else if (root.createChatPropertiesStore.createChatInitMessage !== "" ||
|
|
|
|
root.createChatPropertiesStore.createChatFileUrls.length > 0) {
|
2022-03-22 09:29:58 +01:00
|
|
|
|
2023-01-09 23:13:08 +02:00
|
|
|
root.rootStore.sendMessage(chatId,
|
|
|
|
Qt.Key_Enter,
|
2023-05-04 14:36:35 -04:00
|
|
|
root.createChatPropertiesStore.createChatInitMessage,
|
2022-03-22 09:29:58 +01:00
|
|
|
"",
|
2023-05-04 14:36:35 -04:00
|
|
|
root.createChatPropertiesStore.createChatFileUrls
|
2022-03-22 09:29:58 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-05-04 14:36:35 -04:00
|
|
|
root.createChatPropertiesStore.resetProperties()
|
2022-03-22 09:29:58 +01:00
|
|
|
}
|
|
|
|
|
2023-03-15 13:30:18 +05:30
|
|
|
function updateContactDetails() {
|
|
|
|
contactDetails = activeChatType === Constants.chatType.oneToOne && Utils.getContactDetailsAsJson(root.activeChatId, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
onActiveChatIdChanged: root.updateContactDetails()
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
target: root.contactsStore.myContactsModel
|
|
|
|
|
|
|
|
function onItemChanged(pubKey) {
|
|
|
|
if (pubKey === root.activeChatId)
|
|
|
|
root.updateContactDetails()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-20 13:15:36 +01:00
|
|
|
EmptyChatPanel {
|
2022-01-25 16:22:35 +01:00
|
|
|
anchors.fill: parent
|
2022-06-30 22:25:04 +03:00
|
|
|
visible: root.activeChatId === "" || root.chatsCount == 0
|
2022-01-28 09:19:49 +01:00
|
|
|
rootStore: root.rootStore
|
2022-01-20 13:15:36 +01:00
|
|
|
onShareChatKeyClicked: Global.openProfilePopup(userProfile.pubKey);
|
|
|
|
}
|
2021-07-16 18:02:47 +03:00
|
|
|
|
2022-01-20 13:15:36 +01:00
|
|
|
// This is kind of a solution for applying backend refactored changes with the minimal qml changes.
|
|
|
|
// The best would be if we made qml to follow the struct we have on the backend side.
|
|
|
|
Repeater {
|
2022-03-03 15:01:11 -05:00
|
|
|
id: chatRepeater
|
2022-01-20 13:15:36 +01:00
|
|
|
model: parentModule && parentModule.model
|
2023-02-08 16:45:54 +02:00
|
|
|
|
2023-04-17 22:43:23 +02:00
|
|
|
ChatContentView {
|
2023-01-27 10:24:00 -05:00
|
|
|
width: parent.width
|
|
|
|
height: parent.height
|
2023-04-19 19:31:18 +02:00
|
|
|
visible: !root.rootStore.openCreateChat && isActiveChannel
|
2023-04-18 20:23:57 +02:00
|
|
|
chatId: model.itemId
|
2023-04-27 16:21:41 +02:00
|
|
|
chatType: model.type
|
2023-04-17 22:43:23 +02:00
|
|
|
chatMessagesLoader.active: model.loaderActive
|
|
|
|
rootStore: root.rootStore
|
|
|
|
contactsStore: root.contactsStore
|
|
|
|
emojiPopup: root.emojiPopup
|
|
|
|
stickersPopup: root.stickersPopup
|
|
|
|
sendTransactionNoEnsModal: cmpSendTransactionNoEns
|
|
|
|
receiveTransactionModal: cmpReceiveTransaction
|
|
|
|
sendTransactionWithEnsModal: cmpSendTransactionWithEns
|
|
|
|
stickersLoaded: root.stickersLoaded
|
|
|
|
isBlocked: model.blocked
|
|
|
|
isActiveChannel: model.active
|
|
|
|
onOpenStickerPackPopup: {
|
|
|
|
root.openStickerPackPopup(stickerPackId)
|
|
|
|
}
|
|
|
|
onOpenAppSearch: {
|
|
|
|
root.openAppSearch();
|
|
|
|
}
|
|
|
|
Component.onCompleted: {
|
|
|
|
parentModule.prepareChatContentModuleForChatId(model.itemId)
|
|
|
|
chatContentModule = parentModule.getChatContentModule()
|
|
|
|
chatSectionModule = root.parentModule
|
|
|
|
root.checkForCreateChatOptions(model.itemId)
|
2021-09-21 14:26:32 +02:00
|
|
|
}
|
2021-12-09 13:53:40 +01:00
|
|
|
}
|
|
|
|
}
|
2021-08-09 13:11:04 +02:00
|
|
|
|
2022-01-20 13:15:36 +01:00
|
|
|
Component {
|
|
|
|
id: cmpSendTransactionNoEns
|
|
|
|
ChatCommandModal {
|
|
|
|
id: sendTransactionNoEns
|
|
|
|
store: root.rootStore
|
|
|
|
contactsStore: root.contactsStore
|
|
|
|
onClosed: {
|
|
|
|
destroy()
|
|
|
|
}
|
|
|
|
sendChatCommand: root.requestAddressForTransaction
|
|
|
|
isRequested: false
|
2022-04-04 13:26:30 +02:00
|
|
|
commandTitle: qsTr("Send")
|
2022-01-20 13:15:36 +01:00
|
|
|
header.title: commandTitle
|
2022-04-04 13:26:30 +02:00
|
|
|
finalButtonLabel: qsTr("Request Address")
|
2022-01-20 13:15:36 +01:00
|
|
|
selectRecipient.selectedRecipient: {
|
|
|
|
parentModule.prepareChatContentModuleForChatId(activeChatId)
|
|
|
|
let chatContentModule = parentModule.getChatContentModule()
|
|
|
|
return {
|
|
|
|
address: Constants.zeroAddress, // Setting as zero address since we don't have the address yet
|
|
|
|
alias: chatContentModule.chatDetails.name, // Do we need the alias for real or name works?
|
2022-04-13 15:39:19 +02:00
|
|
|
pubKey: chatContentModule.chatDetails.id,
|
|
|
|
icon: chatContentModule.chatDetails.icon,
|
2022-01-20 13:15:36 +01:00
|
|
|
name: chatContentModule.chatDetails.name,
|
2022-02-09 01:04:49 +01:00
|
|
|
type: RecipientSelector.Type.Contact,
|
|
|
|
ensVerified: true
|
2021-05-18 13:17:04 -04:00
|
|
|
}
|
2021-07-16 18:02:47 +03:00
|
|
|
}
|
2022-01-20 13:15:36 +01:00
|
|
|
selectRecipient.selectedType: RecipientSelector.Type.Contact
|
|
|
|
selectRecipient.readOnly: true
|
2021-07-16 18:02:47 +03:00
|
|
|
}
|
2022-01-20 13:15:36 +01:00
|
|
|
}
|
2021-07-16 18:02:47 +03:00
|
|
|
|
2022-01-20 13:15:36 +01:00
|
|
|
Component {
|
|
|
|
id: cmpReceiveTransaction
|
|
|
|
ChatCommandModal {
|
|
|
|
id: receiveTransaction
|
|
|
|
store: root.rootStore
|
|
|
|
contactsStore: root.contactsStore
|
|
|
|
onClosed: {
|
|
|
|
destroy()
|
|
|
|
}
|
|
|
|
sendChatCommand: root.requestTransaction
|
|
|
|
isRequested: true
|
2022-04-04 13:26:30 +02:00
|
|
|
commandTitle: qsTr("Request")
|
2022-01-20 13:15:36 +01:00
|
|
|
header.title: commandTitle
|
2022-04-04 13:26:30 +02:00
|
|
|
finalButtonLabel: qsTr("Request")
|
2022-01-20 13:15:36 +01:00
|
|
|
selectRecipient.selectedRecipient: {
|
|
|
|
parentModule.prepareChatContentModuleForChatId(activeChatId)
|
|
|
|
let chatContentModule = parentModule.getChatContentModule()
|
|
|
|
return {
|
|
|
|
address: Constants.zeroAddress, // Setting as zero address since we don't have the address yet
|
|
|
|
alias: chatContentModule.chatDetails.name, // Do we need the alias for real or name works?
|
2022-04-13 15:39:19 +02:00
|
|
|
pubKey: chatContentModule.chatDetails.id,
|
|
|
|
icon: chatContentModule.chatDetails.icon,
|
2022-01-20 13:15:36 +01:00
|
|
|
name: chatContentModule.chatDetails.name,
|
|
|
|
type: RecipientSelector.Type.Contact
|
2021-05-18 13:17:04 -04:00
|
|
|
}
|
|
|
|
}
|
2022-01-20 13:15:36 +01:00
|
|
|
selectRecipient.selectedType: RecipientSelector.Type.Contact
|
|
|
|
selectRecipient.readOnly: true
|
2020-10-28 18:44:09 +11:00
|
|
|
}
|
2022-01-20 13:15:36 +01:00
|
|
|
}
|
2020-10-28 18:44:09 +11:00
|
|
|
|
2022-01-20 13:15:36 +01:00
|
|
|
Component {
|
|
|
|
id: cmpSendTransactionWithEns
|
|
|
|
SendModal {
|
|
|
|
id: sendTransactionWithEns
|
|
|
|
onClosed: {
|
|
|
|
destroy()
|
|
|
|
}
|
2022-03-18 15:47:51 +01:00
|
|
|
preSelectedRecipient: {
|
2022-01-20 13:15:36 +01:00
|
|
|
parentModule.prepareChatContentModuleForChatId(activeChatId)
|
|
|
|
let chatContentModule = parentModule.getChatContentModule()
|
|
|
|
|
|
|
|
return {
|
|
|
|
address: "",
|
|
|
|
alias: chatContentModule.chatDetails.name, // Do we need the alias for real or name works?
|
|
|
|
identicon: chatContentModule.chatDetails.icon,
|
|
|
|
name: chatContentModule.chatDetails.name,
|
|
|
|
type: RecipientSelector.Type.Contact,
|
|
|
|
ensVerified: true
|
2021-07-16 18:02:47 +03:00
|
|
|
}
|
2020-11-03 21:29:56 +11:00
|
|
|
}
|
|
|
|
}
|
2022-01-20 13:15:36 +01:00
|
|
|
}
|
2020-05-25 16:34:26 -04:00
|
|
|
}
|