2023-02-08 14:45:54 +00:00
|
|
|
import QtQuick 2.14
|
2021-08-06 15:31:42 +00:00
|
|
|
import Qt.labs.platform 1.1
|
2023-02-08 14:45:54 +00:00
|
|
|
import QtQuick.Controls 2.14
|
|
|
|
import QtQuick.Layouts 1.14
|
2021-04-28 15:30:41 +00:00
|
|
|
import QtGraphicalEffects 1.0
|
2023-02-08 14:45:54 +00:00
|
|
|
import QtQml 2.14
|
2021-12-09 12:53:40 +00:00
|
|
|
import Qt.labs.qmlmodels 1.0
|
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
|
|
|
|
2022-02-28 20:14:04 +00:00
|
|
|
property bool isSectionActive: mainModule.activeSection.id === parentModule.getMySectionId()
|
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-01-27 15:24:00 +00:00
|
|
|
property var contactDetails: activeChatType === Constants.chatType.oneToOne && Utils.getContactDetailsAsJson(root.activeChatId, false)
|
|
|
|
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 = "";
|
|
|
|
}
|
|
|
|
|
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-01-27 15:24:00 +00:00
|
|
|
delegate: Loader {
|
|
|
|
id: chatLoader
|
2023-02-08 14:45:54 +00:00
|
|
|
|
|
|
|
// Channels/chats are not loaded by default and only load when first put active
|
|
|
|
active: false
|
2023-01-27 15:24:00 +00:00
|
|
|
width: parent.width
|
|
|
|
height: parent.height
|
2023-02-08 14:45:54 +00:00
|
|
|
visible: model.active
|
|
|
|
|
|
|
|
// Removing the binding in order not to unload the content:
|
|
|
|
// It is done for keeping:
|
|
|
|
// - the last channel/chat scroll position
|
|
|
|
// - the last typed but not sent text
|
|
|
|
Binding on active {
|
|
|
|
when: !chatLoader.active
|
|
|
|
restoreMode: Binding.RestoreNone
|
|
|
|
value: model.itemId && root.isSectionActive && (model.itemId === root.activeChatId || model.itemId === root.activeSubItemId)
|
|
|
|
}
|
2023-01-27 15:24:00 +00:00
|
|
|
|
|
|
|
sourceComponent: ChatContentView {
|
|
|
|
visible: !root.rootStore.openCreateChat && isActiveChannel
|
|
|
|
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: chatLoader.visible
|
|
|
|
onOpenStickerPackPopup: {
|
|
|
|
root.openStickerPackPopup(stickerPackId)
|
2022-03-04 16:05:46 +00:00
|
|
|
}
|
2023-01-27 15:24:00 +00:00
|
|
|
onOpenAppSearch: {
|
|
|
|
root.openAppSearch();
|
|
|
|
}
|
|
|
|
Component.onCompleted: {
|
|
|
|
parentModule.prepareChatContentModuleForChatId(model.itemId)
|
|
|
|
chatContentModule = parentModule.getChatContentModule()
|
|
|
|
chatSectionModule = root.parentModule
|
|
|
|
root.checkForCreateChatOptions(model.itemId)
|
2021-07-16 15:02:47 +00:00
|
|
|
}
|
2021-09-21 12:26:32 +00:00
|
|
|
}
|
2021-12-09 12:53:40 +00:00
|
|
|
}
|
|
|
|
}
|
2021-08-09 11:11:04 +00:00
|
|
|
|
2021-12-09 12:53:40 +00:00
|
|
|
ChatRequestMessagePanel {
|
2023-01-06 15:43:54 +00:00
|
|
|
anchors.fill: parent
|
|
|
|
anchors.bottomMargin: Style.current.bigPadding
|
2022-07-06 16:51:56 +00:00
|
|
|
isUserAdded: root.isUserAdded
|
|
|
|
visible: root.activeChatType === Constants.chatType.oneToOne && !root.isUserAdded
|
2021-12-09 12:53:40 +00:00
|
|
|
onAddContactClicked: {
|
2021-12-16 20:02:58 +00:00
|
|
|
root.rootStore.addContact(root.activeChatId);
|
2021-07-16 15:02:47 +00:00
|
|
|
}
|
2021-12-01 16:47:57 +00:00
|
|
|
}
|
2021-05-18 17:17: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
|
|
|
}
|
2021-07-16 15:02:47 +00:00
|
|
|
|
2021-12-13 14:24:21 +00: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 11:26:30 +00:00
|
|
|
// qsTr("Could not buy Stickerpack")
|
2021-12-13 14:24:21 +00:00
|
|
|
// :
|
2022-04-04 11:26:30 +00:00
|
|
|
// qsTr("Stickerpack bought successfully");
|
2021-12-13 14:24:21 +00: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 20:34:26 +00:00
|
|
|
}
|