refactor: move contact requests to new architecture
Fixes #4061 Most of the contact request code was already moved, but it wasn't hooked to the QML yet and also there were missing events and some code to improve.
This commit is contained in:
parent
80b94d6519
commit
cb7865bd9e
|
@ -1,6 +1,7 @@
|
||||||
import ./controller_interface
|
import ./controller_interface
|
||||||
import io_interface
|
import io_interface
|
||||||
#import ../../../../core/signals/types
|
|
||||||
|
import ../../../../core/signals/types
|
||||||
import ../../../../../app_service/service/contacts/service as contacts_service
|
import ../../../../../app_service/service/contacts/service as contacts_service
|
||||||
import ../../../../../app_service/service/contacts/dto/contacts
|
import ../../../../../app_service/service/contacts/dto/contacts
|
||||||
import ../../../../../app_service/service/accounts/service as accounts_service
|
import ../../../../../app_service/service/accounts/service as accounts_service
|
||||||
|
@ -19,6 +20,9 @@ type
|
||||||
contactsService: contacts_service.Service
|
contactsService: contacts_service.Service
|
||||||
accountsService: accounts_service.ServiceInterface
|
accountsService: accounts_service.ServiceInterface
|
||||||
|
|
||||||
|
# forward declaration:
|
||||||
|
method getContacts*[T](self: Controller[T], useCache: bool = true): seq[ContactsDto]
|
||||||
|
|
||||||
proc newController*[T](delegate: io_interface.AccessInterface,
|
proc newController*[T](delegate: io_interface.AccessInterface,
|
||||||
events: EventEmitter,
|
events: EventEmitter,
|
||||||
contactsService: contacts_service.Service,
|
contactsService: contacts_service.Service,
|
||||||
|
@ -91,8 +95,8 @@ method init*[T](self: Controller[T]) =
|
||||||
# let contactDto = self.contactsService.getContactById(args.id)
|
# let contactDto = self.contactsService.getContactById(args.id)
|
||||||
# self.delegate.onContactUpdated(contactDto)
|
# self.delegate.onContactUpdated(contactDto)
|
||||||
|
|
||||||
method getContacts*[T](self: Controller[T]): seq[ContactsDto] =
|
method getContacts*[T](self: Controller[T], useCache: bool = true): seq[ContactsDto] =
|
||||||
return self.contactsService.getContacts()
|
return self.contactsService.getContacts(useCache)
|
||||||
|
|
||||||
method getContact*[T](self: Controller[T], id: string): ContactsDto =
|
method getContact*[T](self: Controller[T], id: string): ContactsDto =
|
||||||
return self.contactsService.getContactById(id)
|
return self.contactsService.getContactById(id)
|
||||||
|
|
|
@ -12,7 +12,7 @@ method delete*(self: AccessInterface) {.base.} =
|
||||||
method init*(self: AccessInterface) {.base.} =
|
method init*(self: AccessInterface) {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
method getContacts*(self: AccessInterface): seq[ContactDto.ContactsDto] {.base.} =
|
method getContacts*(self: AccessInterface, useCache: bool = true): seq[ContactDto.ContactsDto] {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
method getContact*(self: AccessInterface, id: string): ContactDto.ContactsDto {.base.} =
|
method getContact*(self: AccessInterface, id: string): ContactDto.ContactsDto {.base.} =
|
||||||
|
|
|
@ -42,6 +42,9 @@ method setContactList*[T](self: Module[T], contacts: seq[ContactsDto]) =
|
||||||
method updateContactList*[T](self: Module[T], contacts: seq[ContactsDto]) =
|
method updateContactList*[T](self: Module[T], contacts: seq[ContactsDto]) =
|
||||||
self.view.model().updateContactList(contacts)
|
self.view.model().updateContactList(contacts)
|
||||||
|
|
||||||
|
method updateContactList*[T](self: Module[T], contacts: seq[ContactsDto]) =
|
||||||
|
self.view.updateContactList(contacts)
|
||||||
|
|
||||||
method load*[T](self: Module[T]) =
|
method load*[T](self: Module[T]) =
|
||||||
self.controller.init()
|
self.controller.init()
|
||||||
let contacts = self.controller.getContacts()
|
let contacts = self.controller.getContacts()
|
||||||
|
|
|
@ -36,6 +36,9 @@ QtObject:
|
||||||
proc model*(self: View): Model =
|
proc model*(self: View): Model =
|
||||||
return self.model
|
return self.model
|
||||||
|
|
||||||
|
proc updateContactList*(self: View, contacts: seq[ContactsDto]) =
|
||||||
|
self.model.updateContactList(contacts)
|
||||||
|
|
||||||
proc modelChanged*(self: View) {.signal.}
|
proc modelChanged*(self: View) {.signal.}
|
||||||
|
|
||||||
proc getModel*(self: View): QVariant {.slot.} =
|
proc getModel*(self: View): QVariant {.slot.} =
|
||||||
|
|
|
@ -26,6 +26,10 @@ type
|
||||||
ContactAddedArgs* = ref object of Args
|
ContactAddedArgs* = ref object of Args
|
||||||
contact*: ContactsDto
|
contact*: ContactsDto
|
||||||
|
|
||||||
|
type
|
||||||
|
ContactArgs* = ref object of Args
|
||||||
|
contact*: ContactsDto
|
||||||
|
|
||||||
ContactUpdatedArgs* = ref object of Args
|
ContactUpdatedArgs* = ref object of Args
|
||||||
id*: string
|
id*: string
|
||||||
|
|
||||||
|
@ -38,6 +42,7 @@ const SIGNAL_CONTACT_UNBLOCKED* = "new-contactUnblocked"
|
||||||
const SIGNAL_CONTACT_REMOVED* = "new-contactRemoved"
|
const SIGNAL_CONTACT_REMOVED* = "new-contactRemoved"
|
||||||
const SIGNAL_CONTACT_NICKNAME_CHANGED* = "new-contactNicknameChanged"
|
const SIGNAL_CONTACT_NICKNAME_CHANGED* = "new-contactNicknameChanged"
|
||||||
|
|
||||||
|
|
||||||
QtObject:
|
QtObject:
|
||||||
type Service* = ref object of QObject
|
type Service* = ref object of QObject
|
||||||
threadpool: ThreadPool
|
threadpool: ThreadPool
|
||||||
|
@ -71,7 +76,9 @@ QtObject:
|
||||||
proc init*(self: Service) =
|
proc init*(self: Service) =
|
||||||
self.fetchContacts()
|
self.fetchContacts()
|
||||||
|
|
||||||
proc getContacts*(self: Service): seq[ContactsDto] =
|
proc getContacts*(self: Service, useCache: bool = true): seq[ContactsDto] =
|
||||||
|
if (not useCache):
|
||||||
|
self.fetchContacts()
|
||||||
return toSeq(self.contacts.values)
|
return toSeq(self.contacts.values)
|
||||||
|
|
||||||
proc fetchContact(self: Service, id: string): ContactsDto =
|
proc fetchContact(self: Service, id: string): ContactsDto =
|
||||||
|
|
|
@ -91,7 +91,7 @@ StatusAppThreePanelLayout {
|
||||||
userList: chatColumn.userList
|
userList: chatColumn.userList
|
||||||
messageContextMenu: quickActionMessageOptionsMenu
|
messageContextMenu: quickActionMessageOptionsMenu
|
||||||
profilePubKey: userProfile.pubKey
|
profilePubKey: userProfile.pubKey
|
||||||
contactsList: root.rootStore.profileModelInst.contacts.list
|
contactsList: root.rootStore.allContacts
|
||||||
isOnline: root.rootStore.chatsModelInst.isOnline
|
isOnline: root.rootStore.chatsModelInst.isOnline
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -144,10 +144,9 @@ StatusAppThreePanelLayout {
|
||||||
//% "Are you sure you want to remove this contact?"
|
//% "Are you sure you want to remove this contact?"
|
||||||
confirmationText: qsTrId("are-you-sure-you-want-to-remove-this-contact-")
|
confirmationText: qsTrId("are-you-sure-you-want-to-remove-this-contact-")
|
||||||
onConfirmButtonClicked: {
|
onConfirmButtonClicked: {
|
||||||
// Not Refactored
|
if (root.rootStore.contactsModuleInst.model.isAdded(chatColumn.contactToRemove)) {
|
||||||
// if (root.rootStore.profileModelInst.contacts.isAdded(chatColumn.contactToRemove)) {
|
root.rootStore.contactsModuleInst.model.removeContact(chatColumn.contactToRemove)
|
||||||
// root.rootStore.profileModelInst.contacts.removeContact(chatColumn.contactToRemove)
|
}
|
||||||
// }
|
|
||||||
removeContactConfirmationDialog.parentPopup.close();
|
removeContactConfirmationDialog.parentPopup.close();
|
||||||
removeContactConfirmationDialog.close();
|
removeContactConfirmationDialog.close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ Item {
|
||||||
property string contactToRemove: ""
|
property string contactToRemove: ""
|
||||||
property string activeChatId: root.rootStore.chatsModelInst.channelView.activeChannel.id
|
property string activeChatId: root.rootStore.chatsModelInst.channelView.activeChannel.id
|
||||||
property bool isBlocked: root.rootStore.contactsModuleInst.model.isContactBlocked(activeChatId)
|
property bool isBlocked: root.rootStore.contactsModuleInst.model.isContactBlocked(activeChatId)
|
||||||
property bool isContact: root.rootStore.isContactAdded(activeChatId)
|
property bool isContact: root.rootStore.contactsModuleInst.model.isAdded(activeChatId)
|
||||||
// property bool contactRequestReceived: root.rootStore.contactsModuleInst.model.contactRequestReceived(activeChatId)
|
// property bool contactRequestReceived: root.rootStore.contactsModuleInst.model.contactRequestReceived(activeChatId)
|
||||||
property string currentNotificationChatId
|
property string currentNotificationChatId
|
||||||
property string currentNotificationCommunityId
|
property string currentNotificationCommunityId
|
||||||
|
@ -152,7 +152,7 @@ Item {
|
||||||
chatInfoButton.subTitle: {
|
chatInfoButton.subTitle: {
|
||||||
switch (root.rootStore.chatsModelInst.channelView.activeChannel.chatType) {
|
switch (root.rootStore.chatsModelInst.channelView.activeChannel.chatType) {
|
||||||
case Constants.chatTypeOneToOne:
|
case Constants.chatTypeOneToOne:
|
||||||
return (root.isContact ?
|
return (root.rootStore.contactsModuleInst.model.isAdded(topBar.chatId) ?
|
||||||
//% "Contact"
|
//% "Contact"
|
||||||
qsTrId("chat-is-a-contact") :
|
qsTrId("chat-is-a-contact") :
|
||||||
//% "Not a contact"
|
//% "Not a contact"
|
||||||
|
@ -402,10 +402,8 @@ Item {
|
||||||
Layout.bottomMargin: Style.current.bigPadding
|
Layout.bottomMargin: Style.current.bigPadding
|
||||||
isContact: root.isContact
|
isContact: root.isContact
|
||||||
visible: root.rootStore.chatsModelInst.channelView.activeChannel.chatType === Constants.chatTypeOneToOne
|
visible: root.rootStore.chatsModelInst.channelView.activeChannel.chatType === Constants.chatTypeOneToOne
|
||||||
&& (!root.isContact /*|| !contactRequestReceived*/)
|
&& (!isContact /*|| !contactRequestReceived*/)
|
||||||
onAddContactClicked: {
|
onAddContactClicked: root.rootStore.contactsModuleInst.addContact(activeChatId)
|
||||||
root.rootStore.addContact(activeChatId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue