From 9fc9f698d9928a9b4d8b23222505f991c33df585 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Mon, 10 Jan 2022 11:44:54 -0500 Subject: [PATCH] refactor(community): hook invite user and fix community context menu --- src/app/boot/app_controller.nim | 2 +- .../modules/main/communities/controller.nim | 8 +++- .../main/communities/controller_interface.nim | 2 +- src/app/modules/main/communities/module.nim | 20 ++++++---- .../module_access_interface.nim | 9 ++++- src/app/modules/main/communities/view.nim | 13 ++----- .../modules/shared_models/active_section.nim | 3 +- .../modules/shared_models/section_item.nim | 6 +++ .../service/community/dto/community.nim | 2 +- src/app_service/service/community/service.nim | 21 +++++++--- ui/app/AppLayouts/Chat/ChatLayout.qml | 2 + ...ommunityProfilePopupInviteFriendsPanel.qml | 28 ++++++------- .../CommunityProfilePopupOverviewPanel.qml | 4 +- .../CommunityWelcomeBannerPanel.qml | 4 +- .../InviteFriendsToCommunityPopup.qml | 9 ++++- .../Chat/views/CommunityColumnView.qml | 28 ++++++------- ui/app/AppLayouts/stores/RootStore.qml | 15 ++++++- ui/app/AppMain.qml | 39 +++++++++---------- .../shared/controls/ContactsListAndSearch.qml | 8 ++-- ui/imports/shared/views/ExistingContacts.qml | 8 +++- ui/imports/shared/views/SearchResults.qml | 10 +++-- 21 files changed, 150 insertions(+), 91 deletions(-) diff --git a/src/app/boot/app_controller.nim b/src/app/boot/app_controller.nim index 441df2d361..5681ded9bb 100644 --- a/src/app/boot/app_controller.nim +++ b/src/app/boot/app_controller.nim @@ -124,7 +124,7 @@ proc newAppController*(statusFoundation: StatusFoundation): AppController = result.networkService = network_service.newService() result.contactsService = contacts_service.newService(statusFoundation.status.events, statusFoundation.threadpool) result.chatService = chat_service.newService(statusFoundation.status.events, result.contactsService) - result.communityService = community_service.newService(statusFoundation.status.events) + result.communityService = community_service.newService(statusFoundation.status.events, result.chatService) result.messageService = message_service.newService(statusFoundation.status.events, statusFoundation.threadpool) result.activityCenterService = activity_center_service.newService(statusFoundation.status.events, statusFoundation.threadpool, result.chatService) diff --git a/src/app/modules/main/communities/controller.nim b/src/app/modules/main/communities/controller.nim index 0f009c3ea1..04d1691df9 100644 --- a/src/app/modules/main/communities/controller.nim +++ b/src/app/modules/main/communities/controller.nim @@ -31,6 +31,10 @@ method init*(self: Controller) = let communities = self.communityService.getAllCommunities() self.delegate.setAllCommunities(communities) + self.events.on(SIGNAL_COMMUNITY_CREATED) do(e:Args): + let args = CommunityArgs(e) + self.delegate.addCommunity(args.community) + self.events.on(SIGNAL_COMMUNITY_MY_REQUEST_ADDED) do(e:Args): let args = CommunityRequestArgs(e) # self.delegate.requestAdded() @@ -183,8 +187,8 @@ method acceptRequestToJoinCommunity*(self: Controller, communityId: string, requ method declineRequestToJoinCommunity*(self: Controller, communityId: string, requestId: string) = self.communityService.declineRequestToJoinCommunity(requestId) -# method inviteUsersToCommunityById*(self: Controller, communityId: string, pubKeys: string) = -# self.communityService.inviteUsersToCommunityById(communityId, pubKeys) +method inviteUsersToCommunityById*(self: Controller, communityId: string, pubKeys: string): string = + result = self.communityService.inviteUsersToCommunityById(communityId, pubKeys) method removeUserFromCommunity*(self: Controller, communityId: string, pubKeys: string) = self.communityService.removeUserFromCommunity(communityId, pubKeys) diff --git a/src/app/modules/main/communities/controller_interface.nim b/src/app/modules/main/communities/controller_interface.nim index ca2d7b7244..da7cd3b2e3 100644 --- a/src/app/modules/main/communities/controller_interface.nim +++ b/src/app/modules/main/communities/controller_interface.nim @@ -61,7 +61,7 @@ method acceptRequestToJoinCommunity*(self: AccessInterface, communityId: string, method declineRequestToJoinCommunity*(self: AccessInterface, communityId: string, requestId: string) {.base.} = raise newException(ValueError, "No implementation available") -method inviteUsersToCommunityById*(self: AccessInterface, communityId: string, pubKeys: string) {.base.} = +method inviteUsersToCommunityById*(self: AccessInterface, communityId: string, pubKeys: string): string {.base.} = raise newException(ValueError, "No implementation available") method removeUserFromCommunity*(self: AccessInterface, communityId: string, pubKeys: string) {.base.} = diff --git a/src/app/modules/main/communities/module.nim b/src/app/modules/main/communities/module.nim index c37f9df696..165852dde1 100644 --- a/src/app/modules/main/communities/module.nim +++ b/src/app/modules/main/communities/module.nim @@ -50,12 +50,10 @@ method isLoaded*(self: Module): bool = method viewDidLoad*(self: Module) = self.moduleLoaded = true - # FIXME this works one time, then restarting the app doesn member_item.initItem(x.id, x.roles))) - self.view.addItem(communityItem) + +method setAllCommunities*(self: Module, communities: seq[CommunityDto]) = + for community in communities: + self.view.addItem(self.getCommunityItem(community)) + +method addCommunity*(self: Module, community: CommunityDto) = + self.view.addItem(self.getCommunityItem(community)) method joinCommunity*(self: Module, communityId: string): string = self.controller.joinCommunity(communityId) @@ -154,8 +158,8 @@ method removeUserFromCommunity*(self: Module, communityId: string, categoryId: s method leaveCommunity*(self: Module, communityId: string) = self.controller.leaveCommunity(communityId) -method inviteUsersToCommunityById*(self: Module, communityId: string, pubKeysJSON: string) = - self.controller.inviteUsersToCommunityById(communityId, pubKeysJSON) +method inviteUsersToCommunityById*(self: Module, communityId: string, pubKeysJSON: string): string = + result = self.controller.inviteUsersToCommunityById(communityId, pubKeysJSON) method removeUserFromCommunity*(self: Module, communityId: string, pubKey: string) = self.controller.removeUserFromCommunity(communityId, pubKey) diff --git a/src/app/modules/main/communities/private_interfaces/module_access_interface.nim b/src/app/modules/main/communities/private_interfaces/module_access_interface.nim index 6ded83113a..3de776dc19 100644 --- a/src/app/modules/main/communities/private_interfaces/module_access_interface.nim +++ b/src/app/modules/main/communities/private_interfaces/module_access_interface.nim @@ -1,4 +1,5 @@ import ../../../../../app_service/service/community/service as community_service +import ../../../shared_models/section_item method delete*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") @@ -12,6 +13,12 @@ method isLoaded*(self: AccessInterface): bool {.base.} = method setAllCommunities*(self: AccessInterface, communities: seq[CommunityDto]) {.base.} = raise newException(ValueError, "No implementation available") +method getCommunityItem*(self: AccessInterface, community: CommunityDto): SectionItem {.base.} = + raise newException(ValueError, "No implementation available") + +method addCommunity*(self: AccessInterface, community: CommunityDto) {.base.} = + raise newException(ValueError, "No implementation available") + method joinCommunity*(self: AccessInterface, communityId: string): string {.base.} = raise newException(ValueError, "No implementation available") @@ -42,7 +49,7 @@ method reorderCommunityChannel*(self: AccessInterface, communityId: string, cate method leaveCommunity*(self: AccessInterface, communityId: string) {.base.} = raise newException(ValueError, "No implementation available") -method inviteUsersToCommunityById*(self: AccessInterface, communityId: string, pubKeysJSON: string) {.base.} = +method inviteUsersToCommunityById*(self: AccessInterface, communityId: string, pubKeysJSON: string): string {.base.} = raise newException(ValueError, "No implementation available") method removeUserFromCommunity*(self: AccessInterface, communityId: string, pubKey: string) {.base.} = diff --git a/src/app/modules/main/communities/view.nim b/src/app/modules/main/communities/view.nim index eb43d1c90b..e74e429113 100644 --- a/src/app/modules/main/communities/view.nim +++ b/src/app/modules/main/communities/view.nim @@ -12,13 +12,11 @@ QtObject: model: SectionModel modelVariant: QVariant observedItem: ActiveSection - observedItemVariant: QVariant proc delete*(self: View) = self.model.delete self.modelVariant.delete self.observedItem.delete - self.observedItemVariant.delete self.QObject.delete proc newView*(delegate: io_interface.AccessInterface): View = @@ -28,7 +26,6 @@ QtObject: result.model = newModel() result.modelVariant = newQVariant(result.model) result.observedItem = newActiveSection() - result.observedItemVariant = newQVariant(result.observedItem) proc load*(self: View) = self.delegate.viewDidLoad() @@ -45,7 +42,7 @@ QtObject: proc observedItemChanged*(self:View) {.signal.} proc getObservedItem(self: View): QVariant {.slot.} = - return self.observedItemVariant + return newQVariant(self.observedItem) QtProperty[QVariant] observedCommunity: read = getObservedItem @@ -56,6 +53,7 @@ QtObject: if (item.id == ""): return self.observedItem.setActiveSectionData(item) + self.observedItemChanged() proc joinCommunity*(self: View, communityId: string): string {.slot.} = result = self.delegate.joinCommunity(communityId) @@ -93,11 +91,8 @@ QtObject: proc leaveCommunity*(self: View, communityId: string) {.slot.} = self.delegate.leaveCommunity(communityId) - proc inviteUsersToCommunityById*(self: View, communityId: string, pubKeysJSON: string) {.slot.} = - self.delegate.inviteUsersToCommunityById(communityId, pubKeysJSON) - - proc inviteUsersToCommunity*(self: View, communityId: string, pubKeysJSON: string) {.slot.} = - self.inviteUsersToCommunityById(communityId, pubKeysJSON) + proc inviteUsersToCommunityById*(self: View, communityId: string, pubKeysJSON: string): string {.slot.} = + result = self.delegate.inviteUsersToCommunityById(communityId, pubKeysJSON) proc removeUserFromCommunity*(self: View, communityId: string, pubKey: string) {.slot.} = self.delegate.removeUserFromCommunity(communityId, pubKey) diff --git a/src/app/modules/shared_models/active_section.nim b/src/app/modules/shared_models/active_section.nim index d9955c0b23..467b4bbec4 100644 --- a/src/app/modules/shared_models/active_section.nim +++ b/src/app/modules/shared_models/active_section.nim @@ -126,4 +126,5 @@ QtObject: QtProperty[int] nbMembers: read = nbMembers - \ No newline at end of file + proc hasMember(self: ActiveSection, pubkey: string): bool {.slot.} = + return self.item.hasMember(pubkey) \ No newline at end of file diff --git a/src/app/modules/shared_models/section_item.nim b/src/app/modules/shared_models/section_item.nim index 54b230fd77..f6c86795c3 100644 --- a/src/app/modules/shared_models/section_item.nim +++ b/src/app/modules/shared_models/section_item.nim @@ -175,3 +175,9 @@ proc ensOnly*(self: SectionItem): bool {.inline.} = proc members*(self: SectionItem): seq[MemberItem] {.inline.} = self.members + +proc hasMember*(self: SectionItem, pubkey: string): bool = + for member in self.members: + if (member.id == pubkey): + return true + return false diff --git a/src/app_service/service/community/dto/community.nim b/src/app_service/service/community/dto/community.nim index 6c25c01f7c..5ad72f0292 100644 --- a/src/app_service/service/community/dto/community.nim +++ b/src/app_service/service/community/dto/community.nim @@ -141,7 +141,7 @@ proc toCommunityDto*(jsonObj: JsonNode): CommunityDto = result.permissions = toPermission(permissionObj) var membersObj: JsonNode - if(jsonObj.getProp("members", membersObj)): + if(jsonObj.getProp("members", membersObj) and membersObj.kind == JArray): for memberId, memberObj in membersObj: result.members.add(toMember(memberObj, memberId)) diff --git a/src/app_service/service/community/service.nim b/src/app_service/service/community/service.nim index e7bf9534cf..2c5c1fcbf5 100644 --- a/src/app_service/service/community/service.nim +++ b/src/app_service/service/community/service.nim @@ -4,6 +4,7 @@ import eventemitter import ./dto/community as community_dto export community_dto import ../../../app/global/global_singleton +import ../chat/service as chat_service import status/statusgo_backend_new/communities as status_go @@ -57,6 +58,7 @@ QtObject: type Service* = ref object of QObject events: EventEmitter + chatService: chat_service.Service joinedCommunities: Table[string, CommunityDto] # [community_id, CommunityDto] allCommunities: Table[string, CommunityDto] # [community_id, CommunityDto] myCommunityRequests*: seq[CommunityMembershipRequestDto] @@ -69,9 +71,10 @@ QtObject: proc delete*(self: Service) = discard - proc newService*(events: EventEmitter): Service = + proc newService*(events: EventEmitter, chatService: chat_service.Service): Service = result = Service() result.events = events + result.chatService = chatService result.joinedCommunities = initTable[string, CommunityDto]() result.allCommunities = initTable[string, CommunityDto]() result.myCommunityRequests = @[] @@ -486,11 +489,17 @@ QtObject: except Exception as e: error "Error exporting community", msg = e.msg - # proc inviteUsersToCommunityById*(self: Service, communityId: string, pubKeys: string) = - # try: - # discard status_go.inviteUsersToCommunityById(communityId, pubKeys) - # except Exception as e: - # error "Error exporting community", msg = e.msg + proc inviteUsersToCommunityById*(self: Service, communityId: string, pubKeysJson: string): string = + try: + let pubKeysParsed = pubKeysJson.parseJson + var pubKeys: seq[string] = @[] + for pubKey in pubKeysParsed: + pubKeys.add(pubKey.getStr) + let response = status_go.inviteUsersToCommunity(communityId, pubKeys) + discard self.chatService.processMessageUpdateAfterSend(response) + except Exception as e: + error "Error exporting community", msg = e.msg + result = "Error exporting community: " & e.msg proc removeUserFromCommunity*(self: Service, communityId: string, pubKeys: string) = try: diff --git a/ui/app/AppLayouts/Chat/ChatLayout.qml b/ui/app/AppLayouts/Chat/ChatLayout.qml index a7fc63ebaa..132884dec1 100644 --- a/ui/app/AppLayouts/Chat/ChatLayout.qml +++ b/ui/app/AppLayouts/Chat/ChatLayout.qml @@ -26,6 +26,7 @@ StatusAppThreePanelLayout { handle: SplitViewHandle { implicitWidth: 5 } property var contactsStore + property bool hasAddedContacts: root.contactsStore.myContactsModel.count > 0 // Not Refactored property var messageStore @@ -128,6 +129,7 @@ StatusAppThreePanelLayout { CommunityColumnView { communitySectionModule: root.rootStore.chatCommunitySectionModule store: root.rootStore + hasAddedContacts: root.hasAddedContacts pinnedMessagesPopupComponent: root.pinnedMessagesListPopupComponent } } diff --git a/ui/app/AppLayouts/Chat/panels/communities/CommunityProfilePopupInviteFriendsPanel.qml b/ui/app/AppLayouts/Chat/panels/communities/CommunityProfilePopupInviteFriendsPanel.qml index 92ab8b6438..7ba5ea1b6f 100644 --- a/ui/app/AppLayouts/Chat/panels/communities/CommunityProfilePopupInviteFriendsPanel.qml +++ b/ui/app/AppLayouts/Chat/panels/communities/CommunityProfilePopupInviteFriendsPanel.qml @@ -17,19 +17,20 @@ Column { property string headerTitle: "" + property var rootStore + property var contactsStore property var community property alias contactListSearch: contactFieldAndList function sendInvites(pubKeys) { - // Not Refactored Yet -// const error = chatsModel.communities.inviteUsersToCommunityById(root.community.id, JSON.stringify(pubKeys)) -// if (error) { -// console.error('Error inviting', error) -// contactFieldAndList.validationError = error -// return -// } -// //% "Invite successfully sent" -// contactFieldAndList.successMessage = qsTrId("invite-successfully-sent") + const error = root.rootStore.inviteUsersToCommunityById(root.community.id, JSON.stringify(pubKeys)) + if (error) { + console.error('Error inviting', error) + contactFieldAndList.validationError = error + return + } + //% "Invite successfully sent" + contactFieldAndList.successMessage = qsTrId("invite-successfully-sent") } StatusDescriptionListItem { @@ -40,10 +41,9 @@ Column { tooltip.text: qsTrId("copy-to-clipboard") icon.name: "copy" iconButton.onClicked: { - // Not Refactored Yet -// let link = `${Constants.communityLinkPrefix}${root.community.id}` -// chatsModel.copyToClipboard(link) -// tooltip.visible = !tooltip.visible + let link = `${Constants.communityLinkPrefix}${root.community.id}` + root.rootStore.copyToClipboard(link) + tooltip.visible = !tooltip.visible } width: parent.width } @@ -65,6 +65,8 @@ Column { id: contactFieldAndList anchors.horizontalCenter: parent.horizontalCenter width: parent.width - 32 + contactsStore: root.contactsStore + community: root.community showCheckbox: true hideCommunityMembers: true showSearch: false diff --git a/ui/app/AppLayouts/Chat/panels/communities/CommunityProfilePopupOverviewPanel.qml b/ui/app/AppLayouts/Chat/panels/communities/CommunityProfilePopupOverviewPanel.qml index 4cce233cae..4ac20c488b 100644 --- a/ui/app/AppLayouts/Chat/panels/communities/CommunityProfilePopupOverviewPanel.qml +++ b/ui/app/AppLayouts/Chat/panels/communities/CommunityProfilePopupOverviewPanel.qml @@ -114,7 +114,7 @@ Column { StatusListItem { anchors.horizontalCenter: parent.horizontalCenter - visible: root.community.isAdmin || root.community.admin + visible: root.community.amISectionAdmin //% "Edit community" title: qsTrId("edit-community") icon.name: "edit" @@ -124,7 +124,7 @@ Column { StatusListItem { anchors.horizontalCenter: parent.horizontalCenter - visible: root.community.isAdmin || root.community.admin + visible: root.community.amISectionAdmin //% "Transfer ownership" title: qsTrId("transfer-ownership") icon.name: "exchange" diff --git a/ui/app/AppLayouts/Chat/panels/communities/CommunityWelcomeBannerPanel.qml b/ui/app/AppLayouts/Chat/panels/communities/CommunityWelcomeBannerPanel.qml index e7fad71307..3d45ea5358 100644 --- a/ui/app/AppLayouts/Chat/panels/communities/CommunityWelcomeBannerPanel.qml +++ b/ui/app/AppLayouts/Chat/panels/communities/CommunityWelcomeBannerPanel.qml @@ -23,6 +23,7 @@ Rectangle { color: Style.current.transparent property var activeCommunity property var store + property bool hasAddedContacts MouseArea { anchors.fill: parent @@ -89,7 +90,8 @@ Rectangle { anchors.bottom: manageBtn.top anchors.bottomMargin: Style.current.halfPadding onClicked: Global.openPopup(inviteFriendsToCommunityPopup, { - community: root.activeCommunity + community: root.activeCommunity, + hasAddedContacts: root.hasAddedContacts }) } diff --git a/ui/app/AppLayouts/Chat/popups/community/InviteFriendsToCommunityPopup.qml b/ui/app/AppLayouts/Chat/popups/community/InviteFriendsToCommunityPopup.qml index 3723120107..150ba1147e 100644 --- a/ui/app/AppLayouts/Chat/popups/community/InviteFriendsToCommunityPopup.qml +++ b/ui/app/AppLayouts/Chat/popups/community/InviteFriendsToCommunityPopup.qml @@ -15,6 +15,8 @@ import "../../panels/communities" StatusModal { id: popup + property var rootStore + property var contactsStore property var community property bool hasAddedContacts @@ -35,9 +37,12 @@ StatusModal { contentItem: CommunityProfilePopupInviteFriendsPanel { id: contactFieldAndList + rootStore: popup.rootStore + contactsStore: popup.contactsStore + community: popup.community contactListSearch.onUserClicked: { - if (isContact) { - // those are just added to the list to by added by the bunch + if (isAddedContact) { + // those are just added to the list to be added by the bunch return } contactFieldAndList.sendInvites([pubKey]) diff --git a/ui/app/AppLayouts/Chat/views/CommunityColumnView.qml b/ui/app/AppLayouts/Chat/views/CommunityColumnView.qml index 5242f83d85..f9eadd23e8 100644 --- a/ui/app/AppLayouts/Chat/views/CommunityColumnView.qml +++ b/ui/app/AppLayouts/Chat/views/CommunityColumnView.qml @@ -26,6 +26,7 @@ Item { property var communitySectionModule property var store + property bool hasAddedContacts: false property var communityData: store.mainModuleInst ? store.mainModuleInst.activeSection || {} : {} // TODO unhardcode // Not Refactored Yet @@ -48,10 +49,10 @@ Item { chatInfoButton.icon.color: communityData.color menuButton.visible: communityData.amISectionAdmin && communityData.canManageUsers // TODO remove dynamic scoping of popup component - chatInfoButton.onClicked: Global.openPopup(communityProfilePopup, { - store: root.store, - community: communityData - }) + chatInfoButton.onClicked: Global.openPopup(communityProfilePopup, { + store: root.store, + community: communityData + }) popupMenu: StatusPopupMenu { StatusMenuItem { @@ -78,10 +79,10 @@ Item { text: qsTrId("invite-people") icon.name: "share-ios" enabled: communityData.canManageUsers - // Not Refactored Yet -// onTriggered: Global.openPopup(inviteFriendsToCommunityPopup, { -// community: root.store.chatsModelInst.communities.activeCommunity -// }) + onTriggered: Global.openPopup(inviteFriendsToCommunityPopup, { + community: communityData, + hasAddedContacts: root.hasAddedContacts + }) } } } @@ -198,11 +199,11 @@ Item { //% "Invite people" text: qsTrId("invite-people") icon.name: "share-ios" - // Not Refactored Yet - enabled: communityData.amISectionAdmin -// onTriggered: Global.openPopup(inviteFriendsToCommunityPopup, { -// community: root.store.chatsModelInst.communities.activeCommunity -// }) + enabled: communityData.canManageUsers + onTriggered: Global.openPopup(inviteFriendsToCommunityPopup, { + community: communityData, + hasAddedContacts: root.hasAddedContacts + }) } } @@ -350,6 +351,7 @@ Item { CommunityWelcomeBannerPanel { activeCommunity: communityData store: root.store + hasAddedContacts: root.hasAddedContacts } } } diff --git a/ui/app/AppLayouts/stores/RootStore.qml b/ui/app/AppLayouts/stores/RootStore.qml index 658282aa7d..e2cfd9ccd9 100644 --- a/ui/app/AppLayouts/stores/RootStore.qml +++ b/ui/app/AppLayouts/stores/RootStore.qml @@ -7,6 +7,7 @@ QtObject { property var mainModuleInst: mainModule property var aboutModuleInst: aboutModule property var communitiesModuleInst: communitiesModule + property var observedCommunity: communitiesModuleInst.observedCommunity property ProfileSectionStore profileSectionStore: ProfileSectionStore { } @@ -25,12 +26,19 @@ QtObject { // Not Refactored Yet // property var profileModelInst: profileModel + property var contactStore: profileSectionStore.contactsStore + property bool hasAddedContacts: contactStore.myContactsModel.count > 0 + property var assets: walletSectionAccountTokens.model // property MessageStore messageStore: MessageStore { } property real volume: !!localAccountSensitiveSettings ? localAccountSensitiveSettings.volume : 0.0 property bool notificationSoundsEnabled: !!localAccountSensitiveSettings ? localAccountSensitiveSettings.notificationSoundsEnabled : false + function setObservedCommunity(communityId) { + communitiesModuleInst.setObservedCommunity(communityId); + } + function setCommunityMuted(communityId, checked) { // Not Refactored Yet // chatsModelInst.communities.setCommunityMuted(communityId, checked); @@ -53,8 +61,11 @@ QtObject { communitiesModuleInst.editCommunity(communityId, communityName, communityDescription, checkedMembership, ensOnlySwitchChecked, communityColor, communityImage, imageCropperModalaX, imageCropperModalaY, imageCropperModalbX, imageCropperModalbY); } + function inviteUsersToCommunityById(communityId, pubkeysJson) { + communitiesModuleInst.inviteUsersToCommunityById(communityId, pubkeysJson); + } + function copyToClipboard(text) { - // Not Refactored Yet -// chatsModelInst.copyToClipboard(text); + globalUtils.copyToClipboard(text) } } diff --git a/ui/app/AppMain.qml b/ui/app/AppMain.qml index 2c8d54c883..e2e4307fe6 100644 --- a/ui/app/AppMain.qml +++ b/ui/app/AppMain.qml @@ -241,40 +241,39 @@ Item { id: communityContextMenu openHandler: function () { - // Not Refactored Yet -// chatsModel.communities.setObservedCommunity(model.id) + appMain.rootStore.setObservedCommunity(model.id) } StatusMenuItem { //% "Invite People" text: qsTrId("invite-people") icon.name: "share-ios" - // Not Refactored Yet -// enabled: chatsModel.communities.observedCommunity.canManageUsers -// onTriggered: Global.openPopup(inviteFriendsToCommunityPopup, { -// community: chatsModel.communities.observedCommunity -// }) + enabled: appMain.rootStore.observedCommunity.canManageUsers + onTriggered: Global.openPopup(inviteFriendsToCommunityPopup, { + community: appMain.rootStore.observedCommunity, + hasAddedContacts: appMain.rootStore.hasAddedContacts + }) } StatusMenuItem { //% "View Community" text: qsTrId("view-community") icon.name: "group-chat" - // Not Refactored Yet -// onTriggered: Global.openPopup(communityProfilePopup, { -// store: appMain.rootStore, -// community: chatsModel.communities.observedCommunity -// }) + onTriggered: Global.openPopup(communityProfilePopup, { + store: appMain.rootStore, + community: appMain.rootStore.observedCommunity + }) } StatusMenuItem { - // Not Refactored Yet -// enabled: chatsModel.communities.observedCommunity.admin + enabled: appMain.rootStore.observedCommunity.amISectionAdmin //% "Edit Community" text: qsTrId("edit-community") icon.name: "edit" - // Not Refactored Yet -// onTriggered: Global.openPopup(editCommunityPopup, {store: appMain.rootStore, community: chatsModel.communities.observedCommunity}) + onTriggered: Global.openPopup(editCommunityPopup, { + store: appMain.rootStore, + community: appMain.rootStore.observedCommunity + }) } StatusMenuSeparator {} @@ -425,7 +424,7 @@ Item { pinnedMessagesListPopupComponent: pinnedMessagesPopupComponent - contactsStore: appMain.rootStore.profileSectionStore.contactsStore + contactsStore: appMain.rootStore.contactStore rootStore.emojiReactionsModel: appMain.rootStore.emojiReactionsModel onProfileButtonClicked: { @@ -515,7 +514,7 @@ Item { pinnedMessagesListPopupComponent: pinnedMessagesPopupComponent - contactsStore: appMain.rootStore.profileSectionStore.contactsStore + contactsStore: appMain.rootStore.contactStore rootStore.emojiReactionsModel: appMain.rootStore.emojiReactionsModel onProfileButtonClicked: { @@ -617,8 +616,8 @@ Item { id: inviteFriendsToCommunityPopup InviteFriendsToCommunityPopup { anchors.centerIn: parent - // Not Refactored Yet -// hasAddedContacts: appMain.rootStore.allContacts.hasAddedContacts() + rootStore: appMain.rootStore + contactsStore: appMain.rootStore.contactStore onClosed: { destroy() } diff --git a/ui/imports/shared/controls/ContactsListAndSearch.qml b/ui/imports/shared/controls/ContactsListAndSearch.qml index 85c50640e8..27d2c8e435 100644 --- a/ui/imports/shared/controls/ContactsListAndSearch.qml +++ b/ui/imports/shared/controls/ContactsListAndSearch.qml @@ -18,6 +18,7 @@ Item { height: childrenRect.height + 24 property var contactsStore + property var community property string validationError: "" property string successMessage: "" @@ -31,7 +32,7 @@ Item { property bool showCheckbox: false property bool showContactList: true property bool showSearch: true - signal userClicked(string pubKey) + signal userClicked(string pubKey, bool isAddedContact) property var pubKeys: ([]) property bool hideCommunityMembers: false property bool addContactEnabled: true @@ -167,6 +168,7 @@ Item { id: existingContacts contactsStore: root.contactsStore + community: root.community visible: showContactList hideCommunityMembers: root.hideCommunityMembers @@ -195,7 +197,7 @@ Item { } root.pubKeys = pubKeysCopy - userClicked(contact.pubKey) + userClicked(contact.pubKey, contact.isContact) } expanded: !searchResults.loading && pubKey === "" && !searchResults.showProfileNotFoundMessage } @@ -213,7 +215,7 @@ Item { if (!validate()) { return } - userClicked(pubKey) + userClicked(pubKey, isAddedContact) } onAddToContactsButtonClicked: { root.contactsStore.addContact(pubKey) diff --git a/ui/imports/shared/views/ExistingContacts.qml b/ui/imports/shared/views/ExistingContacts.qml index 4519ac88eb..85753752a6 100644 --- a/ui/imports/shared/views/ExistingContacts.qml +++ b/ui/imports/shared/views/ExistingContacts.qml @@ -14,6 +14,7 @@ Item { anchors.right: parent.right property var contactsStore + property var community property string filterText: "" property bool expanded: true @@ -50,11 +51,14 @@ Item { name: model.name identicon: model.icon isIdenticon: model.isIdenticon - visible: model.isContact && !model.isBlocked && (root.filterText === "" || + isVisible: { + return model.isContact && !model.isBlocked && (root.filterText === "" || root.matchesAlias(model.name.toLowerCase(), root.filterText.toLowerCase()) || model.name.toLowerCase().includes(root.filterText.toLowerCase()) || model.pubKey.toLowerCase().includes(root.filterText.toLowerCase())) && - !root.hideCommunityMembers + (!root.hideCommunityMembers || + !root.community.hasMember(model.pubKey)) + } onContactClicked: function () { root.contactClicked(model) } diff --git a/ui/imports/shared/views/SearchResults.qml b/ui/imports/shared/views/SearchResults.qml index 4d6dc1e45b..66b246ebfd 100644 --- a/ui/imports/shared/views/SearchResults.qml +++ b/ui/imports/shared/views/SearchResults.qml @@ -29,9 +29,13 @@ Item { property bool resultClickable: true property bool addContactEnabled: true - property bool isAddedContact: root.pubKey != "" ? Utils.getContactDetailsAsJson(root.pubKey).isContact : false + property bool isAddedContact: root.isContactAdded() - signal resultClicked(string pubKey) + function isContactAdded() { + return root.pubKey != "" ? Utils.getContactDetailsAsJson(root.pubKey).isContact : false + } + + signal resultClicked(string pubKey, bool isAddedContact) signal addToContactsButtonClicked(string pubKey) function reset() { @@ -113,7 +117,7 @@ Item { onExited: foundContact.hovered = false onClicked: { if (root.resultClickable) { - root.resultClicked(root.pubKey) + root.resultClicked(root.pubKey, root.isAddedContact) } } }