2024-10-15 19:26:12 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Controls 2.15
|
|
|
|
import QtQuick.Layouts 1.15
|
|
|
|
import QtQml.Models 2.15
|
2021-10-06 09:16:39 +00:00
|
|
|
|
2022-07-14 11:03:36 +00:00
|
|
|
import StatusQ.Core 0.1
|
2024-10-15 19:26:12 +00:00
|
|
|
import StatusQ.Core.Theme 0.1
|
2022-07-14 11:03:36 +00:00
|
|
|
|
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-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-08-18 14:41:02 +00:00
|
|
|
implicitHeight: (title.height + contactsList.height)
|
2022-03-24 20:55:22 +00:00
|
|
|
|
2021-12-31 12:29:51 +00:00
|
|
|
property var contactsModel
|
2022-08-18 14:41:02 +00:00
|
|
|
|
2022-03-24 20:55:22 +00:00
|
|
|
property int panelUsage: Constants.contactsPanelUsage.unknownPosition
|
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 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
|
|
|
|
|
|
|
StyledText {
|
|
|
|
id: title
|
2022-08-18 14:41:02 +00:00
|
|
|
height: visible ? contentHeight : 0
|
2022-03-24 20:55:22 +00:00
|
|
|
anchors.left: parent.left
|
2024-10-15 19:26:12 +00:00
|
|
|
anchors.leftMargin: Theme.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
|
2024-10-15 19:26:12 +00:00
|
|
|
color: Theme.palette.secondaryText
|
2022-03-24 20:55:22 +00:00
|
|
|
}
|
|
|
|
|
2022-07-14 11:03:36 +00:00
|
|
|
StatusListView {
|
2022-03-24 20:55:22 +00:00
|
|
|
id: contactsList
|
2022-10-26 20:00:40 +00:00
|
|
|
objectName: "ContactListPanel_ListView"
|
2022-03-24 20:55:22 +00:00
|
|
|
anchors.top: title.bottom
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.right: parent.right
|
2022-08-18 14:41:02 +00:00
|
|
|
onCountChanged: {
|
|
|
|
height = (count*64);
|
|
|
|
}
|
2022-06-03 15:32:03 +00:00
|
|
|
interactive: false
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
2023-08-01 12:29:36 +00:00
|
|
|
|
|
|
|
sorters: [
|
|
|
|
StringSorter {
|
|
|
|
roleName: "preferredDisplayName"
|
|
|
|
caseSensitivity: Qt.CaseInsensitive
|
|
|
|
}
|
|
|
|
]
|
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
|
2023-04-19 16:48:57 +00:00
|
|
|
|
2022-07-27 18:32:47 +00:00
|
|
|
width: ListView.view.width
|
2023-08-01 12:29:36 +00:00
|
|
|
name: model.preferredDisplayName
|
2022-07-26 13:05:19 +00:00
|
|
|
iconSource: model.icon
|
2022-03-24 20:55:22 +00:00
|
|
|
|
2024-10-25 13:00:32 +00:00
|
|
|
subTitle: model.ensVerified ? "" : Utils.getElidedCompressedPk(model.pubKey)
|
|
|
|
pubKeyColor: Utils.colorForPubkey(model.pubKey)
|
|
|
|
colorHash: Utils.getColorHashAsJson(model.pubKey, model.ensVerified)
|
|
|
|
|
2024-10-25 15:30:48 +00:00
|
|
|
showSendMessageButton: model.isContact && !model.isBlocked
|
2022-03-24 20:55:22 +00:00
|
|
|
showRejectContactRequestButton: {
|
2024-10-25 15:30:48 +00:00
|
|
|
if (root.panelUsage === Constants.contactsPanelUsage.receivedContactRequest
|
|
|
|
&& !model.verificationRequestStatus)
|
2022-03-24 20:55:22 +00:00
|
|
|
return true
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
showAcceptContactRequestButton: {
|
2024-10-25 15:30:48 +00:00
|
|
|
if (root.panelUsage === Constants.contactsPanelUsage.receivedContactRequest
|
|
|
|
&& !model.verificationRequestStatus)
|
2022-03-24 20:55:22 +00:00
|
|
|
return true
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
showRemoveRejectionButton: {
|
2024-10-25 15:30:48 +00:00
|
|
|
if (root.panelUsage === Constants.contactsPanelUsage.rejectedReceivedContactRequest)
|
2022-03-24 20:55:22 +00:00
|
|
|
return true
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
contactText: {
|
2024-10-25 15:30:48 +00:00
|
|
|
if (root.panelUsage === Constants.contactsPanelUsage.sentContactRequest)
|
2022-03-24 20:55:22 +00:00
|
|
|
return qsTr("Contact Request Sent")
|
2024-10-25 15:30:48 +00:00
|
|
|
|
|
|
|
if (root.panelUsage === Constants.contactsPanelUsage.rejectedSentContactRequest)
|
2022-03-24 20:55:22 +00:00
|
|
|
return qsTr("Contact Request Rejected")
|
|
|
|
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2024-10-25 15:30:48 +00:00
|
|
|
|
|
|
|
onContextMenuRequested: root.openContactContextMenu(
|
|
|
|
model.pubKey, model.preferredDisplayName, model.icon)
|
|
|
|
onSendMessageRequested: root.sendMessageActionTriggered(model.pubKey)
|
|
|
|
onAcceptContactRequested: root.contactRequestAccepted(model.pubKey)
|
|
|
|
onRejectRequestRequested: root.contactRequestRejected(model.pubKey)
|
|
|
|
onRemoveRejectionRequested: root.rejectionRemoved(model.pubKey)
|
|
|
|
onShowVerificationRequestRequested: root.showVerificationRequest(model.pubKey)
|
2021-10-06 09:16:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|