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 ../../../shared_models/[user_model, user_item]
import ../../../shared_models/[user_model]
import ./io_interface
import models/showcase_contact_generic_model
@ -72,12 +72,6 @@ QtObject:
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.} =
self.delegate.sendContactRequest(publicKey, message)

View File

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

View File

@ -30,8 +30,6 @@ QtObject {
property bool openCreateChat: false
property var contactsModel: root.contactsStore.myContactsModel
// Important:
// Each `ChatLayout` has its own chatCommunitySectionModule
// (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 {
usersModule: root.chatContentModule.usersModule
}
contactsModel: root.rootStore.contactsStore.myContactsModel
onConfirmed: 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 QtQml.Models 2.15
import StatusQ.Controls 0.1
import StatusQ 0.1
import StatusQ.Components 0.1
import StatusQ.Controls 0.1
import StatusQ.Core 0.1
import StatusQ.Core.Theme 0.1
@ -63,6 +64,7 @@ Page {
rootStore: root.rootStore
utilsStore: root.utilsStore
contactsModel: root.rootStore.contactsStore.myContactsModel
function createChat() {
if (model.count === 0) {
@ -178,7 +180,7 @@ Page {
StatusBaseText {
anchors.centerIn: parent
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
verticalAlignment: Text.AlignVCenter
wrapMode: Text.WordWrap

View File

@ -100,10 +100,10 @@ MembersSelectorBase {
return
}
const hasPendingContactRequest = root.rootStore.contactsStore.hasPendingContactRequest(contactDetails.publicKey)
const hasPendingContactRequest = contactDetails.contactRequestState === Constants.ContactRequestState.Sent
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
// OR it's our own chat key or a banned user
// Then open the contact's profile popup

View File

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

View File

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

View File

@ -1218,7 +1218,7 @@ Loader {
onRemoveTrustStatus: root.rootStore.contactsStore.removeTrustStatus(profileContextMenu.pubKey)
onRemoveContact: Global.removeContactRequested(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)
onRemoveTrustedMark: Global.openRemoveIDVerificationDialog(profileContextMenu.pubKey, null)