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:
Jonathan Rainville 2021-11-15 10:15:21 -05:00 committed by Sale Djenic
parent 80b94d6519
commit cb7865bd9e
8 changed files with 31 additions and 17 deletions

View File

@ -1,6 +1,7 @@
import ./controller_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/dto/contacts
import ../../../../../app_service/service/accounts/service as accounts_service
@ -19,6 +20,9 @@ type
contactsService: contacts_service.Service
accountsService: accounts_service.ServiceInterface
# forward declaration:
method getContacts*[T](self: Controller[T], useCache: bool = true): seq[ContactsDto]
proc newController*[T](delegate: io_interface.AccessInterface,
events: EventEmitter,
contactsService: contacts_service.Service,
@ -91,8 +95,8 @@ method init*[T](self: Controller[T]) =
# let contactDto = self.contactsService.getContactById(args.id)
# self.delegate.onContactUpdated(contactDto)
method getContacts*[T](self: Controller[T]): seq[ContactsDto] =
return self.contactsService.getContacts()
method getContacts*[T](self: Controller[T], useCache: bool = true): seq[ContactsDto] =
return self.contactsService.getContacts(useCache)
method getContact*[T](self: Controller[T], id: string): ContactsDto =
return self.contactsService.getContactById(id)

View File

@ -12,7 +12,7 @@ method delete*(self: AccessInterface) {.base.} =
method init*(self: AccessInterface) {.base.} =
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")
method getContact*(self: AccessInterface, id: string): ContactDto.ContactsDto {.base.} =

View File

@ -132,7 +132,7 @@ QtObject:
self.endRemoveRows()
self.countChanged()
proc hasAddedContacts(self: ContactList): bool {.slot.} =
proc hasAddedContacts(self: ContactList): bool {.slot.} =
for c in self.contacts:
if(c.isContact()): return true
return false

View File

@ -42,6 +42,9 @@ method setContactList*[T](self: Module[T], contacts: seq[ContactsDto]) =
method updateContactList*[T](self: Module[T], contacts: seq[ContactsDto]) =
self.view.model().updateContactList(contacts)
method updateContactList*[T](self: Module[T], contacts: seq[ContactsDto]) =
self.view.updateContactList(contacts)
method load*[T](self: Module[T]) =
self.controller.init()
let contacts = self.controller.getContacts()

View File

@ -36,6 +36,9 @@ QtObject:
proc model*(self: View): Model =
return self.model
proc updateContactList*(self: View, contacts: seq[ContactsDto]) =
self.model.updateContactList(contacts)
proc modelChanged*(self: View) {.signal.}
proc getModel*(self: View): QVariant {.slot.} =

View File

@ -26,6 +26,10 @@ type
ContactAddedArgs* = ref object of Args
contact*: ContactsDto
type
ContactArgs* = ref object of Args
contact*: ContactsDto
ContactUpdatedArgs* = ref object of Args
id*: string
@ -38,6 +42,7 @@ const SIGNAL_CONTACT_UNBLOCKED* = "new-contactUnblocked"
const SIGNAL_CONTACT_REMOVED* = "new-contactRemoved"
const SIGNAL_CONTACT_NICKNAME_CHANGED* = "new-contactNicknameChanged"
QtObject:
type Service* = ref object of QObject
threadpool: ThreadPool
@ -71,7 +76,9 @@ QtObject:
proc init*(self: Service) =
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)
proc fetchContact(self: Service, id: string): ContactsDto =

View File

@ -91,7 +91,7 @@ StatusAppThreePanelLayout {
userList: chatColumn.userList
messageContextMenu: quickActionMessageOptionsMenu
profilePubKey: userProfile.pubKey
contactsList: root.rootStore.profileModelInst.contacts.list
contactsList: root.rootStore.allContacts
isOnline: root.rootStore.chatsModelInst.isOnline
}
}
@ -144,10 +144,9 @@ StatusAppThreePanelLayout {
//% "Are you sure you want to remove this contact?"
confirmationText: qsTrId("are-you-sure-you-want-to-remove-this-contact-")
onConfirmButtonClicked: {
// Not Refactored
// if (root.rootStore.profileModelInst.contacts.isAdded(chatColumn.contactToRemove)) {
// root.rootStore.profileModelInst.contacts.removeContact(chatColumn.contactToRemove)
// }
if (root.rootStore.contactsModuleInst.model.isAdded(chatColumn.contactToRemove)) {
root.rootStore.contactsModuleInst.model.removeContact(chatColumn.contactToRemove)
}
removeContactConfirmationDialog.parentPopup.close();
removeContactConfirmationDialog.close();
}

View File

@ -34,7 +34,7 @@ Item {
property string contactToRemove: ""
property string activeChatId: root.rootStore.chatsModelInst.channelView.activeChannel.id
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 string currentNotificationChatId
property string currentNotificationCommunityId
@ -152,7 +152,7 @@ Item {
chatInfoButton.subTitle: {
switch (root.rootStore.chatsModelInst.channelView.activeChannel.chatType) {
case Constants.chatTypeOneToOne:
return (root.isContact ?
return (root.rootStore.contactsModuleInst.model.isAdded(topBar.chatId) ?
//% "Contact"
qsTrId("chat-is-a-contact") :
//% "Not a contact"
@ -402,10 +402,8 @@ Item {
Layout.bottomMargin: Style.current.bigPadding
isContact: root.isContact
visible: root.rootStore.chatsModelInst.channelView.activeChannel.chatType === Constants.chatTypeOneToOne
&& (!root.isContact /*|| !contactRequestReceived*/)
onAddContactClicked: {
root.rootStore.addContact(activeChatId);
}
&& (!isContact /*|| !contactRequestReceived*/)
onAddContactClicked: root.rootStore.contactsModuleInst.addContact(activeChatId)
}
}