Skip to content

Commit

Permalink
feat(@desktop/communities): Automaticaly encrypt closed communitites
Browse files Browse the repository at this point in the history
  • Loading branch information
mprakhov committed May 5, 2023
1 parent a674ec5 commit 60bd0d2
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 68 deletions.
12 changes: 4 additions & 8 deletions src/app/modules/main/communities/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ proc createCommunity*(
aX: int, aY: int, bX: int, bY: int,
historyArchiveSupportEnabled: bool,
pinMessageAllMembersEnabled: bool,
bannerJsonStr: string,
encrypted: bool) =
bannerJsonStr: string) =
self.communityService.createCommunity(
name,
description,
Expand All @@ -152,8 +151,7 @@ proc createCommunity*(
aX, aY, bX, bY,
historyArchiveSupportEnabled,
pinMessageAllMembersEnabled,
bannerJsonStr,
encrypted)
bannerJsonStr)

proc requestImportDiscordCommunity*(
self: Controller,
Expand All @@ -169,8 +167,7 @@ proc requestImportDiscordCommunity*(
historyArchiveSupportEnabled: bool,
pinMessageAllMembersEnabled: bool,
filesToImport: seq[string],
fromTimestamp: int,
encrypted: bool) =
fromTimestamp: int) =
self.communityService.requestImportDiscordCommunity(
name,
description,
Expand All @@ -184,8 +181,7 @@ proc requestImportDiscordCommunity*(
historyArchiveSupportEnabled,
pinMessageAllMembersEnabled,
filesToImport,
fromTimestamp,
encrypted)
fromTimestamp)

proc reorderCommunityChat*(
self: Controller,
Expand Down
5 changes: 2 additions & 3 deletions src/app/modules/main/communities/io_interface.nim
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,13 @@ method spectateCommunity*(self: AccessInterface, communityId: string): string {.

method createCommunity*(self: AccessInterface, name: string, description, introMessage, outroMessage: string, access: int,
color: string, tags: string, imagePath: string, aX: int, aY: int, bX: int, bY: int,
historyArchiveSupportEnabled: bool, pinMessageAllMembersEnabled: bool, bannerJsonStr: string,
encrypted: bool) {.base.} =
historyArchiveSupportEnabled: bool, pinMessageAllMembersEnabled: bool, bannerJsonStr: string) {.base.} =
raise newException(ValueError, "No implementation available")

method requestImportDiscordCommunity*(self: AccessInterface, name: string, description, introMessage, outroMessage: string, access: int,
color: string, tags: string, imagePath: string, aX: int, aY: int, bX: int, bY: int,
historyArchiveSupportEnabled: bool, pinMessageAllMembersEnabled: bool, filesToImport: seq[string],
fromTimestamp: int, encrypted: bool) {.base.} =
fromTimestamp: int) {.base.} =
raise newException(ValueError, "No implementation available")

method deleteCommunityCategory*(self: AccessInterface, communityId: string, categoryId: string) {.base.} =
Expand Down
9 changes: 4 additions & 5 deletions src/app/modules/main/communities/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,10 @@ method createCommunity*(self: Module, name: string,
aX: int, aY: int, bX: int, bY: int,
historyArchiveSupportEnabled: bool,
pinMessageAllMembersEnabled: bool,
bannerJsonStr: string,
encrypted: bool) =
bannerJsonStr: string) =
self.controller.createCommunity(name, description, introMessage, outroMessage, access, color, tags,
imagePath, aX, aY, bX, bY, historyArchiveSupportEnabled, pinMessageAllMembersEnabled,
bannerJsonStr, encrypted)
bannerJsonStr)

method deleteCommunityCategory*(self: Module, communityId: string, categoryId: string) =
self.controller.deleteCommunityCategory(communityId, categoryId)
Expand Down Expand Up @@ -339,9 +338,9 @@ method requestExtractDiscordChannelsAndCategories*(self: Module, filesToImport:
method requestImportDiscordCommunity*(self: Module, name: string, description, introMessage, outroMessage: string, access: int,
color: string, tags: string, imagePath: string, aX: int, aY: int, bX: int, bY: int,
historyArchiveSupportEnabled: bool, pinMessageAllMembersEnabled: bool, filesToImport: seq[string],
fromTimestamp: int, encrypted: bool) =
fromTimestamp: int) =
self.view.setDiscordImportHasCommunityImage(imagePath != "")
self.controller.requestImportDiscordCommunity(name, description, introMessage, outroMessage, access, color, tags, imagePath, aX, aY, bX, bY, historyArchiveSupportEnabled, pinMessageAllMembersEnabled, filesToImport, fromTimestamp, encrypted)
self.controller.requestImportDiscordCommunity(name, description, introMessage, outroMessage, access, color, tags, imagePath, aX, aY, bX, bY, historyArchiveSupportEnabled, pinMessageAllMembersEnabled, filesToImport, fromTimestamp)

proc getDiscordImportTaskItem(self: Module, t: DiscordImportTaskProgress): DiscordImportTaskItem =
return initDiscordImportTaskItem(
Expand Down
9 changes: 4 additions & 5 deletions src/app/modules/main/communities/view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -421,11 +421,10 @@ QtObject:
imagePath: string,
aX: int, aY: int, bX: int, bY: int,
historyArchiveSupportEnabled: bool,
pinMessageAllMembersEnabled: bool, bannerJsonStr: string,
encrypted: bool) {.slot.} =
pinMessageAllMembersEnabled: bool, bannerJsonStr: string) {.slot.} =
self.delegate.createCommunity(name, description, introMessage, outroMessage, access, color, tags,
imagePath, aX, aY, bX, bY, historyArchiveSupportEnabled, pinMessageAllMembersEnabled,
bannerJsonStr, encrypted)
bannerJsonStr)

proc clearFileList*(self: View) {.slot.} =
self.discordFileListModel.clearItems()
Expand Down Expand Up @@ -459,7 +458,7 @@ QtObject:
aX: int, aY: int, bX: int, bY: int,
historyArchiveSupportEnabled: bool,
pinMessageAllMembersEnabled: bool,
fromTimestamp: int, encrypted: bool) {.slot.} =
fromTimestamp: int) {.slot.} =
let selectedItems = self.discordChannelsModel.getSelectedItems()
var filesToImport: seq[string] = @[]

Expand All @@ -470,7 +469,7 @@ QtObject:
self.setDiscordImportInProgress(true)
self.delegate.requestImportDiscordCommunity(name, description, introMessage, outroMessage, access, color, tags,
imagePath, aX, aY, bX, bY, historyArchiveSupportEnabled, pinMessageAllMembersEnabled,
filesToImport, fromTimestamp, encrypted)
filesToImport, fromTimestamp)

proc deleteCommunityCategory*(self: View, communityId: string, categoryId: string): string {.slot.} =
self.delegate.deleteCommunityCategory(communityId, categoryId)
Expand Down
12 changes: 4 additions & 8 deletions src/app_service/service/community/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -911,8 +911,7 @@ QtObject:
historyArchiveSupportEnabled: bool,
pinMessageAllMembersEnabled: bool,
filesToImport: seq[string],
fromTimestamp: int,
encrypted: bool) =
fromTimestamp: int) =
try:
var image = singletonInstance.utils.formatImagePath(imageUrl)
var tagsString = tags
Expand All @@ -932,8 +931,7 @@ QtObject:
historyArchiveSupportEnabled,
pinMessageAllMembersEnabled,
filesToImport,
fromTimestamp,
encrypted)
fromTimestamp)

if response.error != nil:
let error = Json.decode($response.error, RpcError)
Expand All @@ -955,8 +953,7 @@ QtObject:
aX: int, aY: int, bX: int, bY: int,
historyArchiveSupportEnabled: bool,
pinMessageAllMembersEnabled: bool,
bannerJsonStr: string,
encrypted: bool) =
bannerJsonStr: string) =
try:
var bannerJson = bannerJsonStr.parseJson
bannerJson{"imagePath"} = newJString(singletonInstance.utils.formatImagePath(bannerJson["imagePath"].getStr))
Expand All @@ -976,8 +973,7 @@ QtObject:
aX, aY, bX, bY,
historyArchiveSupportEnabled,
pinMessageAllMembersEnabled,
$bannerJson,
encrypted)
$bannerJson)

if response.error != nil:
let error = Json.decode($response.error, RpcError)
Expand Down
12 changes: 4 additions & 8 deletions src/backend/communities.nim
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ proc createCommunity*(
aX: int, aY: int, bX: int, bY: int,
historyArchiveSupportEnabled: bool,
pinMessageAllMembersEnabled: bool,
bannerJsonStr: string,
encrypted: bool
bannerJsonStr: string
): RpcResponse[JsonNode] {.raises: [Exception].} =
let bannerImage = newCroppedImage(bannerJsonStr)
result = callPrivateRPC("createCommunity".prefix, %*[{
Expand All @@ -91,8 +90,7 @@ proc createCommunity*(
"imageBy": bY,
"historyArchiveSupportEnabled": historyArchiveSupportEnabled,
"pinMessageAllMembersEnabled": pinMessageAllMembersEnabled,
"banner": bannerImage,
"encrypted": encrypted
"banner": bannerImage
}])

proc editCommunity*(
Expand Down Expand Up @@ -131,7 +129,7 @@ proc editCommunity*(
"imageBy": bY,
"banner": bannerImage,
"historyArchiveSupportEnabled": historyArchiveSupportEnabled,
"pinMessageAllMembersEnabled": pinMessageAllMembersEnabled
"pinMessageAllMembersEnabled": pinMessageAllMembersEnabled,
}])

proc requestImportDiscordCommunity*(
Expand All @@ -148,7 +146,6 @@ proc requestImportDiscordCommunity*(
pinMessageAllMembersEnabled: bool,
filesToImport: seq[string],
fromTimestamp: int,
encrypted: bool,
): RpcResponse[JsonNode] {.raises: [Exception].} =
result = callPrivateRPC("requestImportDiscordCommunity".prefix, %*[{
# TODO this will need to be renamed membership (small m)
Expand All @@ -168,8 +165,7 @@ proc requestImportDiscordCommunity*(
"historyArchiveSupportEnabled": historyArchiveSupportEnabled,
"pinMessageAllMembersEnabled": pinMessageAllMembersEnabled,
"from": fromTimestamp,
"filesToImport": filesToImport,
"encrypted": encrypted,
"filesToImport": filesToImport
}])

proc createCommunityTokenPermission*(communityId: string, permissionType: int, tokenCriteria: string, isPrivate: bool): RpcResponse[JsonNode] {.raises: [Exception].} =
Expand Down
23 changes: 0 additions & 23 deletions ui/app/AppLayouts/Chat/controls/community/CommunityOptions.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ Column {
property alias archiveSupportEnabled: archiveSupportToggle.checked
property alias requestToJoinEnabled: requestToJoinToggle.checked
property alias pinMessagesEnabled: pinMessagesToggle.checked
property alias encrypted: encryptedToggle.checked

property bool encryptReadOnly: false

spacing: 0

Expand Down Expand Up @@ -76,24 +73,4 @@ Column {
id: pinMessagesToggle
}
}

RowLayout {
width: visible ? parent.width : 0
height: visible ? d.optionHeight : 0
visible: requestToJoinToggle.checked

StatusBaseText {
Layout.fillWidth: true
text: qsTr("Encrypted")
TapHandler {
enabled: !encryptReadOnly
onTapped: encryptedToggle.toggle()
}
}

StatusCheckBox {
id: encryptedToggle
enabled: !encryptReadOnly
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ StackLayout {
property bool archiveSupportEnabled
property bool requestToJoinEnabled
property bool pinMessagesEnabled
property bool encrypted
property string previousPageName: (currentIndex === 1) ? qsTr("Overview") : ""

property bool editable: false
Expand Down Expand Up @@ -188,8 +187,6 @@ StackLayout {
archiveSupportEnabled: root.archiveSupportEnabled
requestToJoinEnabled: root.requestToJoinEnabled
pinMessagesEnabled: root.pinMessagesEnabled
encrypted: root.encrypted
encryptReadOnly: true
}

bottomReservedSpace: editCommunityPage.settingsDirtyToastMessageImplicitSize
Expand Down
1 change: 0 additions & 1 deletion ui/app/AppLayouts/Chat/views/CommunitySettingsView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ StatusSectionLayout {
tags: root.rootStore.communityTags
selectedTags: root.filteredSelectedTags
archiveSupportEnabled: root.community.historyArchiveSupportEnabled
encrypted: root.community.encrypted
requestToJoinEnabled: root.community.access === Constants.communityChatOnRequestAccess
pinMessagesEnabled: root.community.pinMessageAllMembersEnabled
editable: root.community.amISectionAdmin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,6 @@ StatusStackModal {
historyArchiveSupportEnabled: options.archiveSupportEnabled,
checkedMembership: options.requestToJoinEnabled ? Constants.communityChatOnRequestAccess : Constants.communityChatPublicAccess,
pinMessagesAllowedForMembers: options.pinMessagesEnabled,
encrypted: options.requestToJoinEnabled && options.encrypted // Only communities with memberships can be encrypted
},
bannerJsonStr: JSON.stringify({imagePath: String(bannerPicker.source).replace("file://", ""), cropRect: bannerPicker.cropRect})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,13 @@ QtObject {
historyArchiveSupportEnabled: false,
checkedMembership: false,
pinMessagesAllowedForMembers: false,
encrypted: false
}
}, from = 0) {
return communitiesModuleInst.requestImportDiscordCommunity(
args.name, args.description, args.introMessage, args.outroMessage, args.options.checkedMembership,
args.color, args.tags,
args.image.src, args.image.AX, args.image.AY, args.image.BX, args.image.BY,
args.options.historyArchiveSupportEnabled, args.options.pinMessagesAllowedForMembers, from, args.options.encrypted);
args.options.historyArchiveSupportEnabled, args.options.pinMessagesAllowedForMembers, from);
}


Expand Down

0 comments on commit 60bd0d2

Please # to comment.