Skip to content

Commit

Permalink
fix(CommunitySettings): Process statuses for members model
Browse files Browse the repository at this point in the history
Closes: #6132
  • Loading branch information
borismelnik committed Jul 6, 2022
1 parent 1e7c648 commit 16e269d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/app/modules/main/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ proc init*(self: Controller) =
var args = ContactArgs(e)
self.delegate.contactUpdated(args.contactId)

self.events.on(SIGNAL_CONTACTS_STATUS_UPDATED) do(e: Args):
let args = ContactsStatusUpdatedArgs(e)
self.delegate.contactsStatusUpdated(args.statusUpdates)

self.events.on(SIGNAL_CONTACT_NICKNAME_CHANGED) do(e: Args):
var args = ContactArgs(e)
self.delegate.contactUpdated(args.contactId)
Expand Down Expand Up @@ -302,6 +306,9 @@ proc getContactNameAndImage*(self: Controller, contactId: string):
proc getContactDetails*(self: Controller, contactId: string): ContactDetails =
return self.contactsService.getContactDetails(contactId)

proc getStatusForContact*(self: Controller, contactId: string): StatusUpdateDto =
return self.contactsService.getStatusForContactWithId(contactId)

proc resolveENS*(self: Controller, ensName: string, uuid: string = "", reason: string = "") =
self.contactsService.resolveENS(ensName, uuid, reason)

Expand Down
3 changes: 3 additions & 0 deletions src/app/modules/main/io_interface.nim
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ method communityLeft*(self: AccessInterface, communityId: string) {.base.} =
method resolvedENS*(self: AccessInterface, publicKey: string, address: string, uuid: string, reason: string) {.base.} =
raise newException(ValueError, "No implementation available")

method contactsStatusUpdated*(self: AccessInterface, statusUpdates: seq[StatusUpdateDto]) {.base.} =
raise newException(ValueError, "No implementation available")

method contactUpdated*(self: AccessInterface, publicKey: string) {.base.} =
raise newException(ValueError, "No implementation available")

Expand Down
9 changes: 8 additions & 1 deletion src/app/modules/main/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import NimQml, tables, json, sugar, sequtils, strformat, marshal, times
import io_interface, view, controller, chat_search_item, chat_search_model
import ephemeral_notification_item, ephemeral_notification_model
import ./communities/models/[pending_request_item, pending_request_model]
import ../shared_models/[member_item, member_model, section_item, section_model, active_section]
import ../shared_models/[user_item, member_item, member_model, section_item, section_model, active_section]
import ../../global/app_sections_config as conf
import ../../global/app_signals
import ../../global/global_singleton
Expand Down Expand Up @@ -227,6 +227,8 @@ proc createChannelGroupItem[T](self: Module[T], c: ChannelGroupDto): SectionItem
c.muted,
c.members.map(proc(member: ChatMember): MemberItem =
let contactDetails = self.controller.getContactDetails(member.id)
let statusUpdateDto = self.controller.getStatusForContact(member.id)
let status = statusUpdateDto.statusType.int
result = initMemberItem(
pubKey = member.id,
displayName = contactDetails.displayName,
Expand Down Expand Up @@ -731,6 +733,11 @@ method resolvedENS*[T](self: Module[T], publicKey: string, address: string, uuid
else:
self.view.emitResolvedENSSignal(publicKey, address, uuid)

method contactsStatusUpdated*[T](self: Module[T], statusUpdates: seq[StatusUpdateDto]) =
for s in statusUpdates:
let status = OnlineStatus(s.statusType.int)
self.view.activeSection().setOnlineStatusForMember(s.publicKey, status)

method contactUpdated*[T](self: Module[T], publicKey: string) =
let contactDetails = self.controller.getContactDetails(publicKey)
self.view.activeSection().updateMember(
Expand Down
6 changes: 5 additions & 1 deletion src/app/modules/shared_models/active_section.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import NimQml
import section_item
import section_item, user_item
import ../../../app_service/service/contacts/dto/contacts

QtObject:
Expand Down Expand Up @@ -175,6 +175,10 @@ QtObject:
proc hasMember(self: ActiveSection, pubkey: string): bool {.slot.} =
return self.item.hasMember(pubkey)

proc setOnlineStatusForMember*(self: ActiveSection, pubKey: string,
onlineStatus: OnlineStatus) =
self.item.setOnlineStatusForMember(pubKey, onlineStatus)

proc updateMember*(
self: ActiveSection,
pubkey: string,
Expand Down
4 changes: 4 additions & 0 deletions src/app/modules/shared_models/section_item.nim
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ proc members*(self: SectionItem): member_model.Model {.inline.} =
proc hasMember*(self: SectionItem, pubkey: string): bool =
self.membersModel.isContactWithIdAdded(pubkey)

proc setOnlineStatusForMember*(self: SectionItem, pubKey: string,
onlineStatus: OnlineStatus) =
self.membersModel.setOnlineStatus(pubkey, onlineStatus)

proc updateMember*(
self: SectionItem,
pubkey: string,
Expand Down

0 comments on commit 16e269d

Please sign in to comment.