mirror of
https://github.com/status-im/status-desktop.git
synced 2025-02-21 19:18:53 +00:00
refactor(contacts-service): general improvement
- Signal's arguments updated - Sent payload optimized - Local nickname added to profile section contacts model - Rest updated accordingly to above changes
This commit is contained in:
parent
1e30872a96
commit
caf7fd2072
@ -20,9 +20,6 @@ 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,
|
||||
@ -37,28 +34,6 @@ method delete*[T](self: Controller[T]) =
|
||||
discard
|
||||
|
||||
method init*[T](self: Controller[T]) =
|
||||
# TODO change this event when chat is refactored
|
||||
# The goal would be to send the event with COntactsDto instead of Profile
|
||||
self.events.on(SignalType.Message.event) do(e: Args):
|
||||
let msgData = MessageSignal(e);
|
||||
if msgData.contacts.len > 0:
|
||||
var contacts: seq[ContactsDto] = @[]
|
||||
for contact in msgData.contacts:
|
||||
contacts.add(ContactsDto(
|
||||
id: contact.id,
|
||||
name: contact.username,
|
||||
ensVerified: contact.ensVerified,
|
||||
alias: contact.alias,
|
||||
identicon: contact.identicon,
|
||||
localNickname: contact.localNickname,
|
||||
# image: contact.identityImage,
|
||||
added: contact.added,
|
||||
blocked: contact.blocked,
|
||||
hasAddedUs: contact.hasAddedUs
|
||||
))
|
||||
|
||||
self.delegate.updateContactList(contacts)
|
||||
|
||||
self.events.on(SIGNAL_CONTACT_LOOKED_UP) do(e: Args):
|
||||
var args = ContactArgs(e)
|
||||
self.delegate.contactLookedUp(args.contactId)
|
||||
@ -83,20 +58,8 @@ method init*[T](self: Controller[T]) =
|
||||
var args = ContactNicknameUpdatedArgs(e)
|
||||
self.delegate.contactNicknameChanged(args.contactId, args.nickname)
|
||||
|
||||
self.events.on(SIGNAL_CONTACT_UPDATED) do(e: Args):
|
||||
# I left this as part it was.
|
||||
let contacts = self.getContacts()
|
||||
self.delegate.setContactList(contacts)
|
||||
|
||||
# Since we have the exact contact which has been updated, then we need to improve the way of updating the view
|
||||
# and instead setting the whole list for every change we should update only the appropriate item in the view.
|
||||
# Example:
|
||||
# let args = ContactUpdatedArgs(e)
|
||||
# let contactDto = self.contactsService.getContactById(args.id)
|
||||
# self.delegate.onContactUpdated(contactDto)
|
||||
|
||||
method getContacts*[T](self: Controller[T], useCache: bool = true): seq[ContactsDto] =
|
||||
return self.contactsService.getContacts(useCache)
|
||||
method getContacts*[T](self: Controller[T]): seq[ContactsDto] =
|
||||
return self.contactsService.getContacts()
|
||||
|
||||
method getContact*[T](self: Controller[T], id: string): ContactsDto =
|
||||
return self.contactsService.getContactById(id)
|
||||
@ -123,4 +86,4 @@ method changeContactNickname*[T](self: Controller[T], publicKey: string, nicknam
|
||||
self.contactsService.changeContactNickname(publicKey, nickname)
|
||||
|
||||
method lookupContact*[T](self: Controller[T], value: string) =
|
||||
self.contactsService.lookupContact(value)
|
||||
self.contactsService.lookupContact(value)
|
@ -12,7 +12,7 @@ method delete*(self: AccessInterface) {.base.} =
|
||||
method init*(self: AccessInterface) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method getContacts*(self: AccessInterface, useCache: bool = true): seq[ContactDto.ContactsDto] {.base.} =
|
||||
method getContacts*(self: AccessInterface): seq[ContactDto.ContactsDto] {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method getContact*(self: AccessInterface, id: string): ContactDto.ContactsDto {.base.} =
|
||||
|
@ -67,6 +67,12 @@ QtObject:
|
||||
self.blockedContacts.changeNicknameForContactWithId(id, nickname)
|
||||
self.contactRequests.changeNicknameForContactWithId(id, nickname)
|
||||
|
||||
proc changeNicknameForContactWithId*(self: Model, id: string, nickname: string) =
|
||||
self.contactList.changeNicknameForContactWithId(id, nickname)
|
||||
self.addedContacts.changeNicknameForContactWithId(id, nickname)
|
||||
self.blockedContacts.changeNicknameForContactWithId(id, nickname)
|
||||
self.contactRequests.changeNicknameForContactWithId(id, nickname)
|
||||
|
||||
proc updateContactList*(self: Model, contacts: seq[ContactsDto]) =
|
||||
for contact in contacts:
|
||||
var requestAlreadyAdded = false
|
||||
|
@ -140,7 +140,7 @@ QtObject:
|
||||
# There are much better ways of notifying qml about this change than sending this signal.
|
||||
# It also may has an impact to the app performances since it's handled on multiple places on the qml side.
|
||||
# Would be good to get rid of it durign refactor phase.
|
||||
proc contactChanged*(self: ContactList, pubkey: string, localNickname: string) {.signal.}
|
||||
proc contactChanged*(self: ContactList, pubkey: string) {.signal.}
|
||||
|
||||
proc updateContact*(self: ContactList, contact: ContactsDto) =
|
||||
var found = false
|
||||
@ -158,7 +158,7 @@ QtObject:
|
||||
self.addContactToList(contact)
|
||||
else:
|
||||
self.dataChanged(topLeft, bottomRight, @[ContactRoles.Name.int])
|
||||
self.contactChanged(contact.id, contact.localNickname)
|
||||
self.contactChanged(contact.id)
|
||||
|
||||
proc setNewData*(self: ContactList, contactList: seq[ContactsDto]) =
|
||||
self.beginResetModel()
|
||||
@ -176,5 +176,5 @@ QtObject:
|
||||
self.dataChanged(index, index, @[ContactRoles.LocalNickname.int])
|
||||
|
||||
# Wrote about it where this signal is defined, it's emitted from here just because of the qml part.
|
||||
self.contactChanged(self.contacts[i].id, nickname)
|
||||
return
|
||||
self.contactChanged(self.contacts[i].id)
|
||||
return
|
@ -1,6 +1,6 @@
|
||||
import NimQml, Tables
|
||||
|
||||
import ./io_interface, ./view, ./controller
|
||||
import io_interface, view, controller, model
|
||||
import ../../../../global/global_singleton
|
||||
|
||||
import ../../../../../app_service/service/contacts/service as contacts_service
|
||||
@ -42,9 +42,6 @@ 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()
|
||||
@ -103,4 +100,4 @@ method lookupContact*[T](self: Module[T], value: string) =
|
||||
self.controller.lookupContact(value)
|
||||
|
||||
method contactLookedUp*[T](self: Module[T], id: string) =
|
||||
self.view.contactLookedUp(id)
|
||||
self.view.contactLookedUp(id)
|
@ -36,9 +36,6 @@ 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.} =
|
||||
|
@ -26,13 +26,6 @@ type
|
||||
ContactAddedArgs* = ref object of Args
|
||||
contact*: ContactsDto
|
||||
|
||||
type
|
||||
ContactArgs* = ref object of Args
|
||||
contact*: ContactsDto
|
||||
|
||||
ContactUpdatedArgs* = ref object of Args
|
||||
id*: string
|
||||
|
||||
# Signals which may be emitted by this service:
|
||||
const SIGNAL_CONTACT_LOOKED_UP* = "SIGNAL_CONTACT_LOOKED_UP"
|
||||
# Remove new when old code is removed
|
||||
@ -76,9 +69,7 @@ QtObject:
|
||||
proc init*(self: Service) =
|
||||
self.fetchContacts()
|
||||
|
||||
proc getContacts*(self: Service, useCache: bool = true): seq[ContactsDto] =
|
||||
if (not useCache):
|
||||
self.fetchContacts()
|
||||
proc getContacts*(self: Service): seq[ContactsDto] =
|
||||
return toSeq(self.contacts.values)
|
||||
|
||||
proc fetchContact(self: Service, id: string): ContactsDto =
|
||||
|
Loading…
x
Reference in New Issue
Block a user