2021-10-06 09:16:39 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
|
|
|
import QtQuick.Layouts 1.13
|
2022-03-24 20:55:22 +00:00
|
|
|
import QtQml.Models 2.13
|
2021-10-06 09:16:39 +00:00
|
|
|
|
2022-07-14 11:03:36 +00:00
|
|
|
import StatusQ.Core 0.1
|
|
|
|
|
2021-10-06 09:16:39 +00:00
|
|
|
import utils 1.0
|
2021-10-27 21:27:49 +00:00
|
|
|
import shared 1.0
|
2021-12-21 20:52:17 +00:00
|
|
|
import shared.popups 1.0
|
2022-03-24 20:55:22 +00:00
|
|
|
import shared.panels 1.0
|
2021-10-06 09:16:39 +00:00
|
|
|
|
2022-07-14 11:03:36 +00:00
|
|
|
import "../../Chat/popups"
|
2021-10-06 09:16:39 +00:00
|
|
|
import "."
|
|
|
|
|
2022-08-16 11:07:02 +00:00
|
|
|
import SortFilterProxyModel 0.2
|
|
|
|
|
2022-03-24 20:55:22 +00:00
|
|
|
Item {
|
2022-08-16 11:11:12 +00:00
|
|
|
id: root
|
2022-03-24 20:55:22 +00:00
|
|
|
|
2022-07-06 19:27:04 +00:00
|
|
|
property var contactsStore
|
2021-12-31 12:29:51 +00:00
|
|
|
property var contactsModel
|
2022-03-24 20:55:22 +00:00
|
|
|
property int panelUsage: Constants.contactsPanelUsage.unknownPosition
|
2022-06-03 15:32:03 +00:00
|
|
|
property bool scrollbarOn: false
|
2022-07-22 14:25:58 +00:00
|
|
|
readonly property int contactsListHeight: ((contactsList.count * contactsList.itemAtIndex(0).implicitHeight)+title.height)
|
2021-12-31 12:29:51 +00:00
|
|
|
|
2022-03-24 20:55:22 +00:00
|
|
|
property string title: ""
|
2021-10-06 09:16:39 +00:00
|
|
|
property string searchString: ""
|
2022-05-23 11:45:29 +00:00
|
|
|
readonly property int count: contactsList.count
|
2022-03-24 20:55:22 +00:00
|
|
|
|
2022-07-06 19:27:04 +00:00
|
|
|
signal openContactContextMenu(string publicKey, string name, string icon)
|
2022-03-24 20:55:22 +00:00
|
|
|
signal contactClicked(string publicKey)
|
|
|
|
signal sendMessageActionTriggered(string publicKey)
|
2022-06-28 18:11:18 +00:00
|
|
|
signal showVerificationRequest(string publicKey)
|
2022-03-25 11:33:30 +00:00
|
|
|
signal contactRequestAccepted(string publicKey)
|
|
|
|
signal contactRequestRejected(string publicKey)
|
|
|
|
signal rejectionRemoved(string publicKey)
|
2022-03-24 20:55:22 +00:00
|
|
|
signal textClicked(string publicKey)
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
id: title
|
|
|
|
anchors.left: parent.left
|
2022-05-07 11:45:15 +00:00
|
|
|
anchors.leftMargin: Style.current.padding
|
2022-08-16 11:11:12 +00:00
|
|
|
visible: contactsList.count > 0 && root.title !== ""
|
|
|
|
text: root.title
|
2022-03-24 20:55:22 +00:00
|
|
|
font.weight: Font.Medium
|
|
|
|
font.pixelSize: 15
|
|
|
|
color: Style.current.secondaryText
|
|
|
|
}
|
|
|
|
|
2022-07-14 11:03:36 +00:00
|
|
|
StatusListView {
|
2022-03-24 20:55:22 +00:00
|
|
|
id: contactsList
|
|
|
|
anchors.top: title.bottom
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.bottom: parent.bottom
|
2022-06-03 15:32:03 +00:00
|
|
|
interactive: false
|
2022-08-16 11:11:12 +00:00
|
|
|
ScrollBar.vertical.policy: root.scrollbarOn ? ScrollBar.AlwaysOn : ScrollBar.AsNeeded
|
2022-08-16 11:07:02 +00:00
|
|
|
model: SortFilterProxyModel {
|
|
|
|
id: filteredModel
|
|
|
|
|
2022-08-16 11:11:12 +00:00
|
|
|
sourceModel: root.contactsModel
|
2022-08-16 11:07:02 +00:00
|
|
|
|
|
|
|
function panelUsagePredicate(isVerified) {
|
|
|
|
if (panelUsage === Constants.contactsPanelUsage.verifiedMutualContacts) return isVerified
|
|
|
|
if (panelUsage === Constants.contactsPanelUsage.mutualContacts) return !isVerified
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
function searchPredicate(name, pubkey) {
|
2022-08-17 06:44:02 +00:00
|
|
|
const lowerCaseSearchString = root.searchString.toLowerCase()
|
|
|
|
const compressedPubkey = Utils.getCompressedPk(pubkey)
|
2022-03-24 20:55:22 +00:00
|
|
|
|
2022-08-16 11:07:02 +00:00
|
|
|
return name.toLowerCase().includes(lowerCaseSearchString) ||
|
|
|
|
pubkey.toLowerCase().includes(lowerCaseSearchString) ||
|
|
|
|
compressedPubkey.toLowerCase().includes(lowerCaseSearchString)
|
|
|
|
}
|
|
|
|
|
|
|
|
filters: [
|
|
|
|
ExpressionFilter { expression: filteredModel.panelUsagePredicate(model.isVerified) },
|
|
|
|
ExpressionFilter {
|
2022-08-17 06:44:02 +00:00
|
|
|
enabled: root.searchString !== ""
|
2022-08-16 11:07:02 +00:00
|
|
|
expression: {
|
2022-08-16 11:11:12 +00:00
|
|
|
root.searchString // ensure expression is reevaluated when searchString changes
|
2022-08-17 06:44:02 +00:00
|
|
|
return filteredModel.searchPredicate(model.displayName, model.pubKey)
|
2022-08-16 11:07:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2022-03-24 20:55:22 +00:00
|
|
|
|
2022-08-16 11:07:02 +00:00
|
|
|
delegate: ContactPanel {
|
2022-03-24 20:55:22 +00:00
|
|
|
id: panelDelegate
|
2022-07-27 18:32:47 +00:00
|
|
|
width: ListView.view.width
|
2022-08-16 11:11:12 +00:00
|
|
|
contactsStore: root.contactsStore
|
2022-06-03 13:24:49 +00:00
|
|
|
name: model.displayName
|
2022-03-24 20:55:22 +00:00
|
|
|
publicKey: model.pubKey
|
2022-07-26 13:05:19 +00:00
|
|
|
iconSource: model.icon
|
2022-07-06 16:51:56 +00:00
|
|
|
isContact: model.isContact
|
2022-03-24 20:55:22 +00:00
|
|
|
isBlocked: model.isBlocked
|
2022-06-03 13:24:49 +00:00
|
|
|
isVerified: model.isVerified
|
|
|
|
isUntrustworthy: model.isUntrustworthy
|
2022-06-28 18:11:18 +00:00
|
|
|
verificationRequestStatus: model.incomingVerificationStatus
|
2022-03-24 20:55:22 +00:00
|
|
|
|
2022-07-27 18:31:41 +00:00
|
|
|
showSendMessageButton: isContact && !isBlocked
|
2022-07-06 19:27:04 +00:00
|
|
|
onOpenContactContextMenu: function (publicKey, name, icon) {
|
2022-08-16 11:11:12 +00:00
|
|
|
root.openContactContextMenu(publicKey, name, icon)
|
2022-07-06 19:27:04 +00:00
|
|
|
}
|
2022-03-24 20:55:22 +00:00
|
|
|
showRejectContactRequestButton: {
|
2022-08-16 11:11:12 +00:00
|
|
|
if (root.panelUsage === Constants.contactsPanelUsage.receivedContactRequest && !model.verificationRequestStatus) {
|
2022-03-24 20:55:22 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
showAcceptContactRequestButton: {
|
2022-08-16 11:11:12 +00:00
|
|
|
if (root.panelUsage === Constants.contactsPanelUsage.receivedContactRequest && !model.verificationRequestStatus) {
|
2022-03-24 20:55:22 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
showRemoveRejectionButton: {
|
2022-08-16 11:11:12 +00:00
|
|
|
if (root.panelUsage === Constants.contactsPanelUsage.rejectedReceivedContactRequest) {
|
2022-03-24 20:55:22 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
contactText: {
|
2022-08-16 11:11:12 +00:00
|
|
|
if (root.panelUsage === Constants.contactsPanelUsage.sentContactRequest) {
|
2022-03-24 20:55:22 +00:00
|
|
|
return qsTr("Contact Request Sent")
|
|
|
|
}
|
2022-08-16 11:11:12 +00:00
|
|
|
else if (root.panelUsage === Constants.contactsPanelUsage.rejectedSentContactRequest) {
|
2022-03-24 20:55:22 +00:00
|
|
|
return qsTr("Contact Request Rejected")
|
|
|
|
}
|
|
|
|
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
contactTextClickable: {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2022-08-16 11:11:12 +00:00
|
|
|
onClicked: root.contactClicked(model.pubKey)
|
|
|
|
onSendMessageActionTriggered: root.sendMessageActionTriggered(publicKey)
|
|
|
|
onContactRequestAccepted: root.contactRequestAccepted(publicKey)
|
|
|
|
onContactRequestRejected: root.contactRequestRejected(publicKey)
|
|
|
|
onRejectionRemoved: root.rejectionRemoved(publicKey)
|
|
|
|
onTextClicked: root.textClicked(publicKey)
|
|
|
|
onShowVerificationRequest: root.showVerificationRequest(publicKey)
|
2021-10-06 09:16:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|