2023-02-08 16:45:54 +02:00
|
|
|
import QtQuick 2.14
|
2021-08-06 17:31:42 +02:00
|
|
|
import Qt.labs.platform 1.1
|
2023-02-08 16:45:54 +02:00
|
|
|
import QtQuick.Controls 2.14
|
|
|
|
import QtQuick.Layouts 1.14
|
2021-04-28 11:30:41 -04:00
|
|
|
import QtGraphicalEffects 1.0
|
2023-02-08 16:45:54 +02:00
|
|
|
import QtQml 2.14
|
2021-12-09 13:53:40 +01:00
|
|
|
import Qt.labs.qmlmodels 1.0
|
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
|
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
|
|
|
|
2022-02-28 15:14:04 -05:00
|
|
|
property bool isSectionActive: mainModule.activeSection.id === parentModule.getMySectionId()
|
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) {
|
|
|
|
if(root.rootStore.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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (root.rootStore.createChatStartSendTransactionProcess) {
|
|
|
|
Global.openPopup(cmpReceiveTransaction);
|
|
|
|
}
|
|
|
|
else if (root.rootStore.createChatStickerHashId !== "" &&
|
2022-08-10 15:18:20 -04:00
|
|
|
root.rootStore.createChatStickerPackId !== "" &&
|
|
|
|
root.rootStore.createChatStickerUrl !== "") {
|
2022-03-22 09:29:58 +01:00
|
|
|
root.rootStore.sendSticker(chatId,
|
|
|
|
root.rootStore.createChatStickerHashId,
|
|
|
|
"",
|
2022-08-10 15:18:20 -04:00
|
|
|
root.rootStore.createChatStickerPackId,
|
|
|
|
root.rootStore.createChatStickerUrl);
|
2022-03-22 09:29:58 +01:00
|
|
|
}
|
|
|
|
else if (root.rootStore.createChatInitMessage !== "" ||
|
|
|
|
root.rootStore.createChatFileUrls.length > 0) {
|
|
|
|
|
2023-01-09 23:13:08 +02:00
|
|
|
root.rootStore.sendMessage(chatId,
|
|
|
|
Qt.Key_Enter,
|
2022-03-22 09:29:58 +01:00
|
|
|
root.rootStore.createChatInitMessage,
|
|
|
|
"",
|
|
|
|
root.rootStore.createChatFileUrls
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear.
|
|
|
|
root.rootStore.createChatInitMessage = "";
|
|
|
|
root.rootStore.createChatFileUrls = [];
|
|
|
|
root.rootStore.createChatStartSendTransactionProcess = false;
|
|
|
|
root.rootStore.createChatStartReceiveTransactionProcess = false;
|
|
|
|
root.rootStore.createChatStickerHashId = "";
|
|
|
|
root.rootStore.createChatStickerPackId = "";
|
|
|
|
}
|
|
|
|
|
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-20 15:45:13 -04:00
|
|
|
activeChatType: root.activeChatType
|
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
|
|
|
|
2021-12-09 13:53:40 +01:00
|
|
|
ChatRequestMessagePanel {
|
2023-01-06 16:43:54 +01:00
|
|
|
anchors.fill: parent
|
|
|
|
anchors.bottomMargin: Style.current.bigPadding
|
2022-07-06 12:51:56 -04:00
|
|
|
isUserAdded: root.isUserAdded
|
|
|
|
visible: root.activeChatType === Constants.chatType.oneToOne && !root.isUserAdded
|
2021-12-09 13:53:40 +01:00
|
|
|
onAddContactClicked: {
|
2021-12-16 15:02:58 -05:00
|
|
|
root.rootStore.addContact(root.activeChatId);
|
2021-07-16 18:02:47 +03:00
|
|
|
}
|
2021-12-01 17:47:57 +01:00
|
|
|
}
|
2021-05-18 13:17:04 -04: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
|
|
|
}
|
2021-07-16 18:02:47 +03:00
|
|
|
|
2021-12-13 15:24:21 +01:00
|
|
|
// Not Refactored Yet
|
|
|
|
// Connections {
|
|
|
|
// target: root.rootStore.chatsModelInst.stickers
|
|
|
|
// onTransactionWasSent: {
|
|
|
|
// //% "Transaction pending..."
|
|
|
|
// toastMessage.title = qsTr("Transaction pending...")
|
|
|
|
// toastMessage.source = Style.svg("loading")
|
|
|
|
// toastMessage.iconColor = Style.current.primary
|
|
|
|
// toastMessage.iconRotates = true
|
|
|
|
// toastMessage.link = `${walletModel.utilsView.etherscanLink}/${txResult}`
|
|
|
|
// toastMessage.open()
|
|
|
|
// }
|
|
|
|
// onTransactionCompleted: {
|
|
|
|
// toastMessage.title = !success ?
|
2022-04-04 13:26:30 +02:00
|
|
|
// qsTr("Could not buy Stickerpack")
|
2021-12-13 15:24:21 +01:00
|
|
|
// :
|
2022-04-04 13:26:30 +02:00
|
|
|
// qsTr("Stickerpack bought successfully");
|
2021-12-13 15:24:21 +01:00
|
|
|
// if (success) {
|
|
|
|
// toastMessage.source = Style.svg("check-circle")
|
|
|
|
// toastMessage.iconColor = Style.current.success
|
|
|
|
// } else {
|
|
|
|
// toastMessage.source = Style.svg("block-icon")
|
|
|
|
// toastMessage.iconColor = Style.current.danger
|
|
|
|
// }
|
|
|
|
|
|
|
|
// toastMessage.link = `${walletModel.utilsView.etherscanLink}/${txHash}`
|
|
|
|
// toastMessage.open()
|
|
|
|
// }
|
|
|
|
// }
|
2020-05-25 16:34:26 -04:00
|
|
|
}
|