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