diff --git a/src/app/chat/views/communities.nim b/src/app/chat/views/communities.nim index d7670ab3e1..86c2fe6051 100644 --- a/src/app/chat/views/communities.nim +++ b/src/app/chat/views/communities.nim @@ -273,18 +273,21 @@ QtObject: error "Error inviting to the community", msg = e.msg result = fmt"Error inviting to the community: {e.msg}" - proc inviteUsersToCommunity*(self: CommunitiesView, pubKeysJSON: string): string {.slot.} = + proc inviteUsersToCommunityById*(self: CommunitiesView, communityId: string, pubKeysJSON: string): string {.slot.} = try: let pubKeysParsed = pubKeysJSON.parseJson var pubKeys: seq[string] = @[] for pubKey in pubKeysParsed: pubKeys.add(pubKey.getStr) - self.status.chat.inviteUsersToCommunity(self.activeCommunity.id(), pubKeys) + self.status.chat.inviteUsersToCommunity(communityId, pubKeys) except Exception as e: error "Error inviting to the community", msg = e.msg result = fmt"Error inviting to the community: {e.msg}" + proc inviteUsersToCommunity*(self: CommunitiesView, pubKeysJSON: string): string {.slot.} = + self.inviteUsersToCommunityById(self.activeCommunity.id(), pubKeysJSON) + proc exportComumnity*(self: CommunitiesView): string {.slot.} = try: result = self.status.chat.exportCommunity(self.activeCommunity.communityItem.id) diff --git a/ui/app/AppLayouts/Chat/ChatLayout.qml b/ui/app/AppLayouts/Chat/ChatLayout.qml index 0564db7387..40dafc3469 100644 --- a/ui/app/AppLayouts/Chat/ChatLayout.qml +++ b/ui/app/AppLayouts/Chat/ChatLayout.qml @@ -27,36 +27,6 @@ SplitView { chatColumn.onActivated() } - function openPopup(popupComponent, params = {}) { - const popup = popupComponent.createObject(chatView, params); - popup.open() - return popup - } - - function getContactListObject(dataModel) { - const nbContacts = profileModel.contacts.list.rowCount() - const contacts = [] - let contact - for (let i = 0; i < nbContacts; i++) { - contact = { - name: profileModel.contacts.list.rowData(i, "name"), - localNickname: profileModel.contacts.list.rowData(i, "localNickname"), - pubKey: profileModel.contacts.list.rowData(i, "pubKey"), - address: profileModel.contacts.list.rowData(i, "address"), - identicon: profileModel.contacts.list.rowData(i, "identicon"), - thumbnailImage: profileModel.contacts.list.rowData(i, "thumbnailImage"), - isUser: false, - isContact: profileModel.contacts.list.rowData(i, "isContact") !== "false" - } - - contacts.push(contact) - if (dataModel) { - dataModel.append(contact); - } - } - return contacts - } - Connections { target: appMain onSettingsLoaded: { diff --git a/ui/app/AppLayouts/Chat/CommunityComponents/CommunityButton.qml b/ui/app/AppLayouts/Chat/CommunityComponents/CommunityButton.qml index b8943a7570..89ecc53530 100644 --- a/ui/app/AppLayouts/Chat/CommunityComponents/CommunityButton.qml +++ b/ui/app/AppLayouts/Chat/CommunityComponents/CommunityButton.qml @@ -58,4 +58,18 @@ StatusIconTabButton { text: unviewedMessagesCount > 99 ? "99+" : unviewedMessagesCount } } + + MouseArea { + anchors.fill: parent + cursorShape: Qt.PointingHandCursor + acceptedButtons: Qt.LeftButton | Qt.RightButton + onClicked: function (mouse) { + if (mouse.button === Qt.RightButton) { + commnunityMenu.communityId = communityButton.communityId + commnunityMenu.popup() + return + } + communityButton.clicked() + } + } } diff --git a/ui/app/AppLayouts/Chat/CommunityComponents/CommunityList.qml b/ui/app/AppLayouts/Chat/CommunityComponents/CommunityList.qml index 813fb11de6..d00a7d27cc 100644 --- a/ui/app/AppLayouts/Chat/CommunityComponents/CommunityList.qml +++ b/ui/app/AppLayouts/Chat/CommunityComponents/CommunityList.qml @@ -23,4 +23,50 @@ ListView { iconColor: model.communityColor useLetterIdenticon: model.thumbnailImage === "" } + + PopupMenu { + property string communityId + + onAboutToShow: { + chatsModel.communities.setObservedCommunity(commnunityMenu.communityId) + } + + id: commnunityMenu + Action { + text: qsTr("Invite People") + enabled: chatsModel.communities.observedCommunity.canManageUsers + icon.source: "../../../img/export.svg" + icon.width: 20 + icon.height: 20 + onTriggered: openPopup(inviteFriendsToCommunityPopup, {communityId: commnunityMenu.communityId}) + } + Action { + text: qsTr("View Community") + icon.source: "../../../img/group.svg" + icon.width: 20 + icon.height: 20 + onTriggered: openPopup(communityMembersPopup, {community: chatsModel.communities.observedCommunity}) + } + Separator { + height: 10 + } + Action { + text: qsTr("Edit Community") + // TODO reenable this option once the edit feature is done + enabled: false//chatsModel.communities.observedCommunity.admin + icon.source: "../../../img/edit.svg" + icon.width: 20 + icon.height: 20 + onTriggered: openPopup(editCommunityPopup, {community: chatsModel.communities.observedCommunity}) + } + Action { + text: qsTr("Leave Community") + icon.source: "../../../img/edit.svg" + icon.width: 20 + icon.height: 20 + onTriggered: { + chatsModel.communities.leaveCommunity(commnunityMenu.communityId) + } + } + } } diff --git a/ui/app/AppLayouts/Chat/CommunityComponents/CommunityMembersPopup.qml b/ui/app/AppLayouts/Chat/CommunityComponents/CommunityMembersPopup.qml index 7f2abe4488..1f5b950f5e 100644 --- a/ui/app/AppLayouts/Chat/CommunityComponents/CommunityMembersPopup.qml +++ b/ui/app/AppLayouts/Chat/CommunityComponents/CommunityMembersPopup.qml @@ -9,7 +9,7 @@ import "../components" ModalPopup { id: popup - property QtObject community: chatsModel.communities.activeCommunity + property QtObject community: chatsModel.communities.activeCommunity header: Item { height: childrenRect.height @@ -54,15 +54,7 @@ ModalPopup { label: qsTrId("invite-people") width: parent.width iconName: "invite" - onClicked: openPopup(inviteFriendsPopup) - Component { - id: inviteFriendsPopup - InviteFriendsToCommunityPopup { - onClosed: { - destroy() - } - } - } + onClicked: openPopup(inviteFriendsToCommunityPopup) } Separator { diff --git a/ui/app/AppLayouts/Chat/CommunityComponents/CommunityProfilePopupMembersList.qml b/ui/app/AppLayouts/Chat/CommunityComponents/CommunityProfilePopupMembersList.qml index f315d6f19b..b8c41e9be3 100644 --- a/ui/app/AppLayouts/Chat/CommunityComponents/CommunityProfilePopupMembersList.qml +++ b/ui/app/AppLayouts/Chat/CommunityComponents/CommunityProfilePopupMembersList.qml @@ -11,7 +11,7 @@ Item { property string headerTitle: "" property string headerDescription: "" property string headerImageSource: "" - height: childrenRect.height + height: 300 CommunityPopupButton { id: inviteBtn @@ -19,15 +19,7 @@ Item { label: qsTrId("invite-people") width: parent.width iconName: "invite" - onClicked: openPopup(inviteFriendsPopup) - Component { - id: inviteFriendsPopup - InviteFriendsToCommunityPopup { - onClosed: { - destroy() - } - } - } + onClicked: openPopup(inviteFriendsToCommunityPopup) } Separator { @@ -40,7 +32,6 @@ Item { anchors.rightMargin: -Style.current.padding } - StatusSettingsLineButton { id: membershipRequestsBtn text: qsTr("Membership requests") diff --git a/ui/app/AppLayouts/Chat/CommunityComponents/CommunityProfilePopupOverview.qml b/ui/app/AppLayouts/Chat/CommunityComponents/CommunityProfilePopupOverview.qml index e7f8f8151d..265ae459d0 100644 --- a/ui/app/AppLayouts/Chat/CommunityComponents/CommunityProfilePopupOverview.qml +++ b/ui/app/AppLayouts/Chat/CommunityComponents/CommunityProfilePopupOverview.qml @@ -71,14 +71,8 @@ Item { label: qsTr("Members") iconName: "members" txtColor: Style.current.textColor - //onClicked: openPopup(communityMembersPopup) onClicked: stack.push(membersList) - Component { - id: communityMembersPopup - CommunityMembersPopup {} - } - Item { property int nbRequests: chatsModel.communities.activeCommunity.communityMembershipRequests.nbRequests @@ -213,13 +207,6 @@ Item { label: qsTrId("edit-community") iconName: "edit" onClicked: openPopup(editCommunityPopup) - - Component { - id: editCommunityPopup - CreateCommunityPopup { - isEdit: true - } - } } } diff --git a/ui/app/AppLayouts/Chat/CommunityComponents/CommunityWelcomeBanner.qml b/ui/app/AppLayouts/Chat/CommunityComponents/CommunityWelcomeBanner.qml index d246760b2d..7d564ad4f1 100644 --- a/ui/app/AppLayouts/Chat/CommunityComponents/CommunityWelcomeBanner.qml +++ b/ui/app/AppLayouts/Chat/CommunityComponents/CommunityWelcomeBanner.qml @@ -17,15 +17,6 @@ Rectangle { radius: 16 color: Style.current.transparent - Component { - id: inviteFriendsPopup - InviteFriendsToCommunityPopup { - onClosed: { - destroy() - } - } - } - SVGImage { anchors.top: parent.top anchors.topMargin: -6 @@ -75,9 +66,7 @@ Rectangle { anchors.horizontalCenter: parent.horizontalCenter anchors.bottom: manageBtn.top anchors.bottomMargin: Style.current.halfPadding - onClicked: { - openPopup(inviteFriendsPopup) - } + onClicked: openPopup(inviteFriendsToCommunityPopup) } StatusButton { diff --git a/ui/app/AppLayouts/Chat/CommunityComponents/InviteFriendsToCommunityPopup.qml b/ui/app/AppLayouts/Chat/CommunityComponents/InviteFriendsToCommunityPopup.qml index c23faec4b7..3c595c2908 100644 --- a/ui/app/AppLayouts/Chat/CommunityComponents/InviteFriendsToCommunityPopup.qml +++ b/ui/app/AppLayouts/Chat/CommunityComponents/InviteFriendsToCommunityPopup.qml @@ -20,7 +20,7 @@ ModalPopup { inviteBtn.enabled = false contactList.membersData.clear(); // TODO remove friends that are already members - chatView.getContactListObject(contactList.membersData) + getContactListObject(contactList.membersData) noContactsRect.visible = !profileModel.contacts.list.hasAddedContacts(); contactList.visible = !noContactsRect.visible; } @@ -114,7 +114,7 @@ ModalPopup { //% "Invite" text: qsTrId("invite-button") onClicked : { - const error = chatsModel.communities.inviteUsersToCommunity(JSON.stringify(popup.pubKeys)) + const error = chatsModel.communities.inviteUsersToCommunityById(popup.communityId, JSON.stringify(popup.pubKeys)) // TODO show error to user also should we show success? if (error) { console.error('Error inviting', error) diff --git a/ui/app/AppLayouts/Chat/components/GroupChatPopup.qml b/ui/app/AppLayouts/Chat/components/GroupChatPopup.qml index 96b89650ab..cde62ddfe9 100644 --- a/ui/app/AppLayouts/Chat/components/GroupChatPopup.qml +++ b/ui/app/AppLayouts/Chat/components/GroupChatPopup.qml @@ -25,7 +25,7 @@ ModalPopup { contactList.membersData.clear(); - chatView.getContactListObject(contactList.membersData) + getContactListObject(contactList.membersData) contactList.membersData.append({ //% "(You)" diff --git a/ui/app/AppLayouts/Chat/components/GroupInfoPopup.qml b/ui/app/AppLayouts/Chat/components/GroupInfoPopup.qml index acd5db171b..0aa1e78c69 100644 --- a/ui/app/AppLayouts/Chat/components/GroupInfoPopup.qml +++ b/ui/app/AppLayouts/Chat/components/GroupInfoPopup.qml @@ -22,7 +22,7 @@ ModalPopup { currMemberCount = memberCount; contactList.membersData.clear(); - const contacts = chatView.getContactListObject() + const contacts = getContactListObject() contacts.forEach(function (contact) { if(popup.channel.contains(contact.pubKey) || diff --git a/ui/app/AppLayouts/Chat/components/NoFriendsRectangle.qml b/ui/app/AppLayouts/Chat/components/NoFriendsRectangle.qml index 289429205d..1e5d7f5808 100644 --- a/ui/app/AppLayouts/Chat/components/NoFriendsRectangle.qml +++ b/ui/app/AppLayouts/Chat/components/NoFriendsRectangle.qml @@ -11,7 +11,7 @@ Item { StyledText { id: noContacts text: noContactsRect.text - color: Style.current.darkGrey + color: Style.current.secondaryText anchors.top: parent.top anchors.topMargin: Style.current.padding anchors.left: parent.left diff --git a/ui/app/AppMain.qml b/ui/app/AppMain.qml index 9d57c2428e..f829d3c440 100644 --- a/ui/app/AppMain.qml +++ b/ui/app/AppMain.qml @@ -49,6 +49,30 @@ RowLayout { return popup } + function getContactListObject(dataModel) { + const nbContacts = profileModel.contacts.list.rowCount() + const contacts = [] + let contact + for (let i = 0; i < nbContacts; i++) { + contact = { + name: profileModel.contacts.list.rowData(i, "name"), + localNickname: profileModel.contacts.list.rowData(i, "localNickname"), + pubKey: profileModel.contacts.list.rowData(i, "pubKey"), + address: profileModel.contacts.list.rowData(i, "address"), + identicon: profileModel.contacts.list.rowData(i, "identicon"), + thumbnailImage: profileModel.contacts.list.rowData(i, "thumbnailImage"), + isUser: false, + isContact: profileModel.contacts.list.rowData(i, "isContact") !== "false" + } + + contacts.push(contact) + if (dataModel) { + dataModel.append(contact); + } + } + return contacts + } + function getUserNickname(pubKey) { // Get contact nickname const contactList = profileModel.contacts.list @@ -226,6 +250,31 @@ RowLayout { } } + Component { + id: inviteFriendsToCommunityPopup + InviteFriendsToCommunityPopup { + onClosed: { + destroy() + } + } + } + + Component { + id: communityMembersPopup + CommunityMembersPopup { + onClosed: { + destroy() + } + } + } + + Component { + id: editCommunityPopup + CreateCommunityPopup { + isEdit: true + } + } + ToastMessage { id: toastMessage } diff --git a/ui/app/img/export.svg b/ui/app/img/export.svg new file mode 100644 index 0000000000..fd21425899 --- /dev/null +++ b/ui/app/img/export.svg @@ -0,0 +1,4 @@ + + + +