Skip to content

Commit

Permalink
feat(desktop): New invite to community popup with message
Browse files Browse the repository at this point in the history
  • Loading branch information
MishkaRogachev committed Aug 12, 2022
1 parent 0418979 commit e67d649
Show file tree
Hide file tree
Showing 25 changed files with 287 additions and 137 deletions.
4 changes: 2 additions & 2 deletions src/app/modules/main/chat_section/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,8 @@ method unmuteCategory*(self: Controller, categoryId: string) =
proc setCommunityMuted*(self: Controller, muted: bool) =
self.communityService.setCommunityMuted(self.sectionId, muted)

proc inviteUsersToCommunity*(self: Controller, pubKeys: string): string =
result = self.communityService.inviteUsersToCommunityById(self.sectionId, pubKeys)
proc inviteUsersToCommunity*(self: Controller, pubKeys: string, inviteMessage: string): string =
result = self.communityService.inviteUsersToCommunityById(self.sectionId, pubKeys, inviteMessage)

proc reorderCommunityCategories*(self: Controller, categoryId: string, position: int) =
self.communityService.reorderCommunityCategories(self.sectionId, categoryId, position)
Expand Down
2 changes: 1 addition & 1 deletion src/app/modules/main/chat_section/io_interface.nim
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ method exportCommunity*(self: AccessInterface): string {.base.} =
method setCommunityMuted*(self: AccessInterface, muted: bool) {.base.} =
raise newException(ValueError, "No implementation available")

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

method createCommunityCategory*(self: AccessInterface, name: string, channels: seq[string]) {.base.} =
Expand Down
4 changes: 2 additions & 2 deletions src/app/modules/main/chat_section/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -792,8 +792,8 @@ method exportCommunity*(self: Module): string =
method setCommunityMuted*(self: Module, muted: bool) =
self.controller.setCommunityMuted(muted)

method inviteUsersToCommunity*(self: Module, pubKeysJSON: string): string =
result = self.controller.inviteUsersToCommunity(pubKeysJSON)
method inviteUsersToCommunity*(self: Module, pubKeysJSON: string, inviteMessage: string): string =
result = self.controller.inviteUsersToCommunity(pubKeysJSON, inviteMessage)

method prepareEditCategoryModel*(self: Module, categoryId: string) =
self.view.editCategoryChannelsModel().clearItems()
Expand Down
4 changes: 2 additions & 2 deletions src/app/modules/main/chat_section/view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ QtObject:
proc setCommunityMuted*(self: View, muted: bool) {.slot.} =
self.delegate.setCommunityMuted(muted)

proc inviteUsersToCommunity*(self: View, pubKeysJSON: string): string {.slot.} =
result = self.delegate.inviteUsersToCommunity(pubKeysJSON)
proc inviteUsersToCommunity*(self: View, pubKeysJSON: string, inviteMessage: string): string {.slot.} =
result = self.delegate.inviteUsersToCommunity(pubKeysJSON, inviteMessage)

proc createCommunityCategory*(self: View, name: string, channels: string) {.slot.} =
let channelsSeq = map(parseJson(channels).getElems(), proc(x:JsonNode):string = x.getStr())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ proc newController*(delegate: io_interface.AccessInterface,
proc delete*(self: Controller) =
discard

proc inviteUsersToCommunity*(self: Controller, communityID: string, pubKeys: string): string =
result = self.communityService.inviteUsersToCommunityById(communityID, pubKeys)
proc inviteUsersToCommunity*(self: Controller, communityID: string, pubKeys: string, inviteMessage: string): string =
result = self.communityService.inviteUsersToCommunityById(communityID, pubKeys, inviteMessage)

proc leaveCommunity*(self: Controller, communityID: string) =
self.communityService.leaveCommunity(communityID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ method getModuleAsVariant*(self: AccessInterface): QVariant {.base.} =
method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

method inviteUsersToCommunity*(self: AccessInterface, communityID: string, pubKeysJSON: string): string {.base.} =
method inviteUsersToCommunity*(self: AccessInterface, communityID: string, pubKeysJSON: string, inviteMessage: string): string {.base.} =
raise newException(ValueError, "No implementation available")

method leaveCommunity*(self: AccessInterface, communityID: string) {.base.} =
Expand Down
4 changes: 2 additions & 2 deletions src/app/modules/main/profile_section/communities/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ method viewDidLoad*(self: Module) =
method getModuleAsVariant*(self: Module): QVariant =
return self.viewVariant

method inviteUsersToCommunity*(self: Module, communityID: string, pubKeysJSON: string): string =
result = self.controller.inviteUsersToCommunity(communityID, pubKeysJSON)
method inviteUsersToCommunity*(self: Module, communityID: string, pubKeysJSON: string, inviteMessage: string): string =
result = self.controller.inviteUsersToCommunity(communityID, pubKeysJSON, inviteMessage)

method leaveCommunity*(self: Module, communityID: string) =
self.controller.leaveCommunity(communityID)
Expand Down
4 changes: 2 additions & 2 deletions src/app/modules/main/profile_section/communities/view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ QtObject:
proc load*(self: View) =
self.delegate.viewDidLoad()

method inviteUsersToCommunity*(self: View, communityID: string, pubKeysJSON: string): string {.slot.} =
result = self.delegate.inviteUsersToCommunity(communityID, pubKeysJSON)
method inviteUsersToCommunity*(self: View, communityID: string, pubKeysJSON: string, inviteMessage: string): string {.slot.} =
result = self.delegate.inviteUsersToCommunity(communityID, pubKeysJSON, inviteMessage)

method leaveCommunity*(self: View, communityID: string) {.slot.} =
self.delegate.leaveCommunity(communityID)
Expand Down
4 changes: 2 additions & 2 deletions src/app_service/service/community/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1069,15 +1069,15 @@ QtObject:
except Exception as e:
error "Error declining request to join community", msg = e.msg

proc inviteUsersToCommunityById*(self: Service, communityId: string, pubKeysJson: string): string =
proc inviteUsersToCommunityById*(self: Service, communityId: string, pubKeysJson: string, inviteMessage: string): string =
try:
let pubKeysParsed = pubKeysJson.parseJson
var pubKeys: seq[string] = @[]
for pubKey in pubKeysParsed:
pubKeys.add(pubKey.getStr)
# We no longer send invites, but merely share the community so
# users can request access (with automatic acception)
let response = status_go.shareCommunityToUsers(communityId, pubKeys)
let response = status_go.shareCommunityToUsers(communityId, pubKeys, inviteMessage)
discard self.chatService.processMessageUpdateAfterSend(response)
except Exception as e:
error "Error sharing community", msg = e.msg
Expand Down
5 changes: 3 additions & 2 deletions src/backend/communities.nim
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,11 @@ proc inviteUsersToCommunity*(communityId: string, pubKeys: seq[string]): RpcResp
"users": pubKeys
}])

proc shareCommunityToUsers*(communityId: string, pubKeys: seq[string]): RpcResponse[JsonNode] {.raises: [Exception].} =
proc shareCommunityToUsers*(communityId: string, pubKeys: seq[string], inviteMessage: string): RpcResponse[JsonNode] {.raises: [Exception].} =
return callPrivateRPC("shareCommunity".prefix, %*[{
"communityId": communityId,
"users": pubKeys
"users": pubKeys,
"inviteMessage": inviteMessage
}])

proc getCommunitiesSettings*(): RpcResponse[JsonNode] {.raises: [Exception].} =
Expand Down
2 changes: 0 additions & 2 deletions ui/app/AppLayouts/Chat/controls/Contact.qml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ Rectangle {

visible: isVisible && (isContact || isUser)
height: visible ? 64 : 0
anchors.right: parent.right
anchors.left: parent.left
border.width: 0
radius: Style.current.radius
color: isHovered ? Style.current.backgroundHover : Style.current.transparent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,62 +1,86 @@
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Dialogs 1.3
import QtQuick.Layouts 1.13
import QtGraphicalEffects 1.13
import QtQuick 2.14
import QtQuick.Layouts 1.4

import StatusQ.Components 0.1
import StatusQ.Controls 0.1
import StatusQ.Popups 0.1

import utils 1.0
import shared.controls 1.0
import shared 1.0
import shared.controls 1.0
import shared.panels 1.0
import shared.views 1.0
import shared.status 1.0
import StatusQ.Components 0.1
import StatusQ.Popups 0.1

Column {
ColumnLayout {
id: root

property string headerTitle: ""

property var rootStore
property var contactsStore
property var community
property alias contactListSearch: contactFieldAndList

StatusDescriptionListItem {
title: qsTr("Share community")
subTitle: `${Constants.communityLinkPrefix}${root.community && root.community.id.substring(0, 4)}...${root.community && root.community.id.substring(root.community.id.length -2)}`
tooltip.text: qsTr("Copied!")
icon.name: "copy"
iconButton.onClicked: {
let link = `${Constants.communityLinkPrefix}${root.community.id}`
root.rootStore.copyToClipboard(link)
tooltip.visible = !tooltip.visible
}
width: parent.width
}
property var pubKeys: ([])

StatusModalDivider {
bottomPadding: Style.current.padding
}
spacing: Style.current.padding

StyledText {
id: headline
text: qsTr("Contacts")
font.pixelSize: Style.current.primaryTextFontSize
color: Style.current.secondaryText
anchors.left: parent.left
anchors.leftMargin: Style.current.padding
}

ContactsListAndSearch {
id: contactFieldAndList
anchors.horizontalCenter: parent.horizontalCenter
width: parent.width - 32
StatusInput {
id: filterInput
placeholderText: qsTr("Search contacts")
input.icon.name: "search"
input.clearable: true
Layout.fillWidth: true
}

ExistingContacts {
id: existingContacts

contactsStore: root.contactsStore
community: root.community
showCheckbox: true
hideCommunityMembers: true
showSearch: false
rootStore: root.rootStore
showCheckbox: true
filterText: filterInput.text
pubKeys: root.pubKeys
onContactClicked: function (contact) {
if (!contact || typeof contact === "string") {
return
}
const index = root.pubKeys.indexOf(contact.pubKey)
const pubKeysCopy = Object.assign([], root.pubKeys)
if (index === -1) {
pubKeysCopy.push(contact.pubKey)
} else {
pubKeysCopy.splice(index, 1)
}
root.pubKeys = pubKeysCopy
}
Layout.rightMargin: -Style.current.padding
Layout.fillWidth: true
Layout.fillHeight: true
}

StatusModalDivider {
bottomPadding: Style.current.padding
Layout.fillWidth: true
}

StatusDescriptionListItem {
title: qsTr("Share community")
subTitle: `${Constants.communityLinkPrefix}${root.community && root.community.id.substring(0, 4)}...${root.community && root.community.id.substring(root.community.id.length -2)}`
tooltip.text: qsTr("Copied!")
icon.name: "copy"
iconButton.onClicked: {
let link = `${Constants.communityLinkPrefix}${root.community.id}`
root.rootStore.copyToClipboard(link)
tooltip.visible = !tooltip.visible
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import QtQuick 2.14
import QtQuick.Layouts 1.4

import StatusQ.Core 0.1
import StatusQ.Components 0.1
import StatusQ.Controls 0.1
import StatusQ.Popups 0.1

import utils 1.0
import shared 1.0
import shared.views 1.0
import shared.status 1.0

ColumnLayout {
id: root

property var pubKeys: ([])

property var rootStore
property var contactsStore

property alias inviteMessage: messageInput.text

spacing: Style.current.padding

QtObject {
id: d

readonly property int maxMsgLength: 140
readonly property int msgHeight: 108
}

StatusInput {
id: messageInput
label: qsTr("Invitation Message")
charLimit: d.maxMsgLength
placeholderText: qsTr("The message a contact will get with community invitation")
input.multiline: true
input.implicitHeight: d.msgHeight
input.verticalAlignment: TextEdit.AlignTop
Layout.minimumHeight: 150 // TODO: implicitHeight is not calculated well from input.implicitHeight
Layout.fillWidth: true
}

PickedContacts {
id: existingContacts
enabled: false
contactsStore: root.contactsStore
pubKeys: root.pubKeys
Layout.fillWidth: true
Layout.fillHeight: true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,6 @@ StatusModal {
community: root.community
contactsStore: root.contactsStore
rootStore: root.store

contactListSearch.chatKey.text: ""
contactListSearch.pubKey: ""
contactListSearch.pubKeys: []
contactListSearch.ensUsername: ""
contactListSearch.existingContacts.visible: root.hasAddedContacts
contactListSearch.noContactsRect.visible: !contactListSearch.existingContacts.visible
}
}
}
Expand All @@ -117,9 +110,9 @@ StatusModal {
text: qsTr("Invite")
visible: root.contentItem.depth > 2
height: !visible ? 0 : implicitHeight
enabled: root.contentItem.currentItem.contactListSearch !== undefined && root.contentItem.currentItem.contactListSearch.pubKeys.length > 0
enabled: root.contentItem.currentItem !== undefined && root.contentItem.currentItem.pubKeys.length > 0
onClicked: {
root.contentItem.currentItem.sendInvites(root.contentItem.currentItem.contactListSearch.pubKeys)
root.contentItem.currentItem.sendInvites(root.contentItem.currentItem.pubKeys, "") // NOTE: empty message
root.contentItem.pop()
}
}
Expand Down
Loading

0 comments on commit e67d649

Please sign in to comment.