parent
e195053669
commit
31ab5a7962
|
@ -212,6 +212,9 @@ method getContacts*(self: Controller): seq[ContactsDto] =
|
|||
method getContact*(self: Controller, id: string): ContactsDto =
|
||||
return self.contactService.getContactById(id)
|
||||
|
||||
method getContactDetails*(self: Controller, id: string): ContactDetails =
|
||||
return self.contactService.getContactDetails(id)
|
||||
|
||||
method getContactNameAndImage*(self: Controller, contactId: string):
|
||||
tuple[name: string, image: string, isIdenticon: bool] =
|
||||
return self.contactService.getContactNameAndImage(contactId)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import ../../../../app_service/service/contacts/dto/[contacts]
|
||||
import ../../../../app_service/service/contacts/dto/[contacts, contact_details]
|
||||
import ../../../../app_service/service/chat/dto/[chat]
|
||||
import ../../../../app_service/service/community/dto/[community]
|
||||
|
||||
|
@ -76,6 +76,9 @@ method getContacts*(self: AccessInterface): seq[ContactsDto] {.base.} =
|
|||
method getContact*(self: AccessInterface, id: string): ContactsDto {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method getContactDetails*(self: AccessInterface, id: string): ContactDetails {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method getContactNameAndImage*(self: AccessInterface, contactId: string):
|
||||
tuple[name: string, image: string, isIdenticon: bool] {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
|
|
@ -189,11 +189,17 @@ proc buildCommunityUI(self: Module, events: EventEmitter,
|
|||
self.setActiveItemSubItem(selectedItemId, selectedSubItemId)
|
||||
|
||||
proc createItemFromPublicKey(self: Module, publicKey: string): contacts_item.Item =
|
||||
let contact = self.controller.getContact(publicKey)
|
||||
let (name, image, isIdenticon) = self.controller.getContactNameAndImage(contact.id)
|
||||
let contactDetails = self.controller.getContactDetails(publicKey)
|
||||
|
||||
return contacts_item.initItem(contact.id, name, image, isIdenticon, contact.isContact(), contact.isBlocked(),
|
||||
contact.requestReceived())
|
||||
return contacts_item.initItem(
|
||||
contactDetails.details.id,
|
||||
contactDetails.displayName,
|
||||
contactDetails.icon,
|
||||
contactDetails.isIdenticon,
|
||||
contactDetails.details.isContact(),
|
||||
contactDetails.details.isBlocked(),
|
||||
contactDetails.details.requestReceived()
|
||||
)
|
||||
|
||||
proc initContactRequestsModel(self: Module) =
|
||||
var contactsWhoAddedMe: seq[contacts_item.Item]
|
||||
|
@ -385,6 +391,7 @@ method getCurrentFleet*(self: Module): string =
|
|||
|
||||
method acceptContactRequest*(self: Module, publicKey: string) =
|
||||
self.controller.addContact(publicKey)
|
||||
self.createOneToOneChat(publicKey, ensName = "")
|
||||
|
||||
method onContactAccepted*(self: Module, publicKey: string) =
|
||||
self.view.contactRequestsModel().removeItemWithPubKey(publicKey)
|
||||
|
@ -412,6 +419,14 @@ method onContactBlocked*(self: Module, publicKey: string) =
|
|||
self.view.contactRequestsModel().removeItemWithPubKey(publicKey)
|
||||
|
||||
method onContactDetailsUpdated*(self: Module, publicKey: string) =
|
||||
let contact = self.controller.getContact(publicKey)
|
||||
if (contact.requestReceived() and
|
||||
not contact.isContact()and
|
||||
not contact.isBlocked() and
|
||||
not self.view.contactRequestsModel().containsItemWithPubKey(publicKey)):
|
||||
let item = self.createItemFromPublicKey(publicKey)
|
||||
self.view.contactRequestsModel().addItem(item)
|
||||
|
||||
let (chatName, chatImage, isIdenticon) = self.controller.getOneToOneChatNameAndImage(publicKey)
|
||||
self.view.chatsModel().updateItemDetails(publicKey, chatName, chatImage, isIdenticon)
|
||||
|
||||
|
|
|
@ -71,6 +71,12 @@ QtObject:
|
|||
of ModelRole.RequestReceived:
|
||||
result = newQVariant(item.requestReceived)
|
||||
|
||||
proc findIndexByPubKey(self: Model, pubKey: string): int =
|
||||
for i in 0 ..< self.items.len:
|
||||
if(self.items[i].pubKey == pubKey):
|
||||
return i
|
||||
return -1
|
||||
|
||||
proc addItems*(self: Model, items: seq[Item]) =
|
||||
if(items.len == 0):
|
||||
return
|
||||
|
@ -94,11 +100,6 @@ QtObject:
|
|||
self.endInsertRows()
|
||||
self.countChanged()
|
||||
|
||||
proc findIndexByPubKey(self: Model, pubKey: string): int =
|
||||
for i in 0 ..< self.items.len:
|
||||
if(self.items[i].pubKey == pubKey):
|
||||
return i
|
||||
return -1
|
||||
|
||||
proc containsItemWithPubKey*(self: Model, pubKey: string): bool =
|
||||
return self.findIndexByPubKey(pubKey) != -1
|
||||
|
|
Loading…
Reference in New Issue