Chat/RootStore: contactsModel property removed

This commit is contained in:
Michał Cieślak 2024-11-15 10:52:20 +01:00
parent a30e823c25
commit 6718491198
9 changed files with 36 additions and 37 deletions

View File

@ -1,6 +1,6 @@
import NimQml import NimQml
import ../../../shared_models/[user_model, user_item] import ../../../shared_models/[user_model]
import ./io_interface import ./io_interface
import models/showcase_contact_generic_model import models/showcase_contact_generic_model
@ -72,12 +72,6 @@ QtObject:
proc contactInfoRequestFinished(self: View, publicKey: string, ok: bool) {.signal.} proc contactInfoRequestFinished(self: View, publicKey: string, ok: bool) {.signal.}
proc hasPendingContactRequest*(self: View, publicKey: string): bool {.slot.} =
if not self.contactsModel.isContactWithIdAdded(publicKey):
return false
let userItem = self.contactsModel.getItemByPubKey(publicKey)
return userItem.contactRequest == ContactRequest.Sent
proc sendContactRequest*(self: View, publicKey: string, message: string) {.slot.} = proc sendContactRequest*(self: View, publicKey: string, message: string) {.slot.} =
self.delegate.sendContactRequest(publicKey, message) self.delegate.sendContactRequest(publicKey, message)

View File

@ -40,7 +40,11 @@ SplitView {
QtObject { QtObject {
function getContactDetailsAsJson() { function getContactDetailsAsJson() {
return JSON.stringify({ ensVerified: false }) return JSON.stringify({
ensVerified: false,
isCurrentUser: false,
contactRequestState: Constants.ContactRequestState.Mutual
})
} }
Component.onCompleted: { Component.onCompleted: {
@ -53,18 +57,18 @@ SplitView {
} }
} }
ChatStores.RootStore { ListModel {
id: rootStoreMock id: contacts
readonly property var contactsModel: ListModel { Component.onCompleted: {
id: contactsModel for(let i=0; i < 20; i++) {
append(usersModelEditor.getNewUser(i))
Component.onCompleted: {
for(let i=0; i < 20; i++) {
append(usersModelEditor.getNewUser(i))
}
} }
} }
}
ChatStores.RootStore {
id: rootStoreMock
readonly property var contactsStore: QtObject { readonly property var contactsStore: QtObject {
readonly property var mainModuleInst: null readonly property var mainModuleInst: null
@ -187,6 +191,8 @@ SplitView {
return true return true
} }
} }
contactsModel: contacts
} }
} }
} }
@ -205,6 +211,8 @@ SplitView {
sourceComponent: MembersEditSelectorView { sourceComponent: MembersEditSelectorView {
rootStore: rootStoreMock rootStore: rootStoreMock
usersStore: usersStoreMock usersStore: usersStoreMock
contactsModel: contacts
} }
} }
} }
@ -241,11 +249,11 @@ SplitView {
UsersModelEditor { UsersModelEditor {
id: usersModelEditor id: usersModelEditor
anchors.fill: parent anchors.fill: parent
model: contactsModel model: contacts
onRemoveClicked: contactsModel.remove(index, 1) onRemoveClicked: contacts.remove(index, 1)
onRemoveAllClicked: contactsModel.clear() onRemoveAllClicked: contacts.clear()
onAddClicked: contactsModel.append(usersModelEditor.getNewUser(contactsModel.count)) onAddClicked: contacts.append(usersModelEditor.getNewUser(contacts.count))
} }
} }
} }

View File

@ -30,8 +30,6 @@ QtObject {
property bool openCreateChat: false property bool openCreateChat: false
property var contactsModel: root.contactsStore.myContactsModel
// Important: // Important:
// Each `ChatLayout` has its own chatCommunitySectionModule // Each `ChatLayout` has its own chatCommunitySectionModule
// (on the backend chat and community sections share the same module since they are actually the same) // (on the backend chat and community sections share the same module since they are actually the same)

View File

@ -346,6 +346,7 @@ Item {
usersStore: UsersStore { usersStore: UsersStore {
usersModule: root.chatContentModule.usersModule usersModule: root.chatContentModule.usersModule
} }
contactsModel: root.rootStore.contactsStore.myContactsModel
onConfirmed: root.state = d.stateInfoButtonContent onConfirmed: root.state = d.stateInfoButtonContent
onRejected: root.state = d.stateInfoButtonContent onRejected: root.state = d.stateInfoButtonContent

View File

@ -3,8 +3,9 @@ import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15 import QtQuick.Layouts 1.15
import QtQml.Models 2.15 import QtQml.Models 2.15
import StatusQ.Controls 0.1 import StatusQ 0.1
import StatusQ.Components 0.1 import StatusQ.Components 0.1
import StatusQ.Controls 0.1
import StatusQ.Core 0.1 import StatusQ.Core 0.1
import StatusQ.Core.Theme 0.1 import StatusQ.Core.Theme 0.1
@ -63,6 +64,7 @@ Page {
rootStore: root.rootStore rootStore: root.rootStore
utilsStore: root.utilsStore utilsStore: root.utilsStore
contactsModel: root.rootStore.contactsStore.myContactsModel
function createChat() { function createChat() {
if (model.count === 0) { if (model.count === 0) {
@ -178,7 +180,7 @@ Page {
StatusBaseText { StatusBaseText {
anchors.centerIn: parent anchors.centerIn: parent
width: Math.min(553, parent.width - 2 * Theme.padding) width: Math.min(553, parent.width - 2 * Theme.padding)
visible: root.rootStore.contactsModel.count === 0 visible: root.rootStore.contactsStore.myContactsModel.ModelCount.empty
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
wrapMode: Text.WordWrap wrapMode: Text.WordWrap

View File

@ -100,10 +100,10 @@ MembersSelectorBase {
return return
} }
const hasPendingContactRequest = root.rootStore.contactsStore.hasPendingContactRequest(contactDetails.publicKey) const hasPendingContactRequest = contactDetails.contactRequestState === Constants.ContactRequestState.Sent
if ((root.model.count === 0 && hasPendingContactRequest) || if ((root.model.count === 0 && hasPendingContactRequest) ||
contactDetails.publicKey === root.rootStore.contactsStore.myPublicKey || contactDetails.isBlocked) { contactDetails.isCurrentUser || contactDetails.isBlocked) {
// List is empty and we have a contact request // List is empty and we have a contact request
// OR it's our own chat key or a banned user // OR it's our own chat key or a banned user
// Then open the contact's profile popup // Then open the contact's profile popup

View File

@ -19,6 +19,8 @@ InlineSelectorPanel {
property ChatStores.RootStore rootStore property ChatStores.RootStore rootStore
property alias contactsModel: suggestionsModel.sourceModel
readonly property int membersLimit: 20 // see: https://github.com/status-im/status-mobile/issues/13066 readonly property int membersLimit: 20 // see: https://github.com/status-im/status-mobile/issues/13066
property bool limitReached: model.count >= membersLimit property bool limitReached: model.count >= membersLimit
@ -29,9 +31,7 @@ InlineSelectorPanel {
warningLabel.visible: limitReached warningLabel.visible: limitReached
suggestionsModel: SortFilterProxyModel { suggestionsModel: SortFilterProxyModel {
id: _suggestionsModel id: suggestionsModel
sourceModel: root.rootStore.contactsModel
function searchPredicate(displayName, localNickname, nameAlias) { function searchPredicate(displayName, localNickname, nameAlias) {
return displayName.toLowerCase().includes(root.edit.text.toLowerCase()) || return displayName.toLowerCase().includes(root.edit.text.toLowerCase()) ||
@ -52,14 +52,14 @@ InlineSelectorPanel {
enabled: root.edit.text !== "" && root.pastedChatKey == "" enabled: root.edit.text !== "" && root.pastedChatKey == ""
expression: { expression: {
root.edit.text // ensure expression is reevaluated when edit.text changes root.edit.text // ensure expression is reevaluated when edit.text changes
return _suggestionsModel.searchPredicate(model.displayName, model.localNickname, model.alias) return suggestionsModel.searchPredicate(model.displayName, model.localNickname, model.alias)
} }
expectedRoles: ["displayName", "localNickname", "alias"] expectedRoles: ["displayName", "localNickname", "alias"]
}, },
FastExpressionFilter { FastExpressionFilter {
expression: { expression: {
root.model.count // ensure expression is reevaluated when members model changes root.model.count // ensure expression is reevaluated when members model changes
return _suggestionsModel.notAMemberPredicate(model.pubKey) return suggestionsModel.notAMemberPredicate(model.pubKey)
} }
expectedRoles: ["pubKey"] expectedRoles: ["pubKey"]
}, },

View File

@ -56,10 +56,6 @@ QtObject {
return root.globalUtilsInst.generateAlias(pubKey) return root.globalUtilsInst.generateAlias(pubKey)
} }
function hasPendingContactRequest(pubKey) {
return root.contactsModule.hasPendingContactRequest(pubKey)
}
function joinPrivateChat(pubKey) { function joinPrivateChat(pubKey) {
Global.changeAppSectionBySectionType(Constants.appSection.chat) Global.changeAppSectionBySectionType(Constants.appSection.chat)
root.contactsModule.switchToOrCreateOneToOneChat(pubKey) root.contactsModule.switchToOrCreateOneToOneChat(pubKey)

View File

@ -1218,7 +1218,7 @@ Loader {
onRemoveTrustStatus: root.rootStore.contactsStore.removeTrustStatus(profileContextMenu.pubKey) onRemoveTrustStatus: root.rootStore.contactsStore.removeTrustStatus(profileContextMenu.pubKey)
onRemoveContact: Global.removeContactRequested(profileContextMenu.pubKey) onRemoveContact: Global.removeContactRequested(profileContextMenu.pubKey)
onBlockContact: Global.blockContactRequested(profileContextMenu.pubKey) onBlockContact: Global.blockContactRequested(profileContextMenu.pubKey)
onRemoveFromGroup: root.store.removeMemberFromGroupChat(profileContextMenu.pubKey) onRemoveFromGroup: root.rootStore.removeMemberFromGroupChat(profileContextMenu.pubKey)
onMarkAsTrusted: Global.openMarkAsIDVerifiedPopup(profileContextMenu.pubKey, null) onMarkAsTrusted: Global.openMarkAsIDVerifiedPopup(profileContextMenu.pubKey, null)
onRemoveTrustedMark: Global.openRemoveIDVerificationDialog(profileContextMenu.pubKey, null) onRemoveTrustedMark: Global.openRemoveIDVerificationDialog(profileContextMenu.pubKey, null)