feat: encrypt communities

This commit is contained in:
Richard Ramos 2022-10-07 12:33:23 -04:00 committed by Iuri Matias
parent 5d0d3e7135
commit 3b3b737956
20 changed files with 116 additions and 36 deletions

View File

@ -102,7 +102,8 @@ proc createCommunity*(
aX: int, aY: int, bX: int, bY: int,
historyArchiveSupportEnabled: bool,
pinMessageAllMembersEnabled: bool,
bannerJsonStr: string) =
bannerJsonStr: string,
encrypted: bool) =
self.communityService.createCommunity(
name,
description,
@ -115,7 +116,8 @@ proc createCommunity*(
aX, aY, bX, bY,
historyArchiveSupportEnabled,
pinMessageAllMembersEnabled,
bannerJsonStr)
bannerJsonStr,
encrypted)
proc requestImportDiscordCommunity*(
self: Controller,
@ -131,7 +133,8 @@ proc requestImportDiscordCommunity*(
historyArchiveSupportEnabled: bool,
pinMessageAllMembersEnabled: bool,
filesToImport: seq[string],
fromTimestamp: int) =
fromTimestamp: int,
encrypted: bool) =
self.communityService.requestImportDiscordCommunity(
name,
description,
@ -145,7 +148,8 @@ proc requestImportDiscordCommunity*(
historyArchiveSupportEnabled,
pinMessageAllMembersEnabled,
filesToImport,
fromTimestamp)
fromTimestamp,
encrypted)
proc reorderCommunityChat*(
self: Controller,

View File

@ -34,12 +34,14 @@ 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) {.base.} =
historyArchiveSupportEnabled: bool, pinMessageAllMembersEnabled: bool, bannerJsonStr: string,
encrypted: bool) {.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) {.base.} =
historyArchiveSupportEnabled: bool, pinMessageAllMembersEnabled: bool, filesToImport: seq[string],
fromTimestamp: int, encrypted: bool) {.base.} =
raise newException(ValueError, "No implementation available")
method deleteCommunityCategory*(self: AccessInterface, communityId: string, categoryId: string) {.base.} =

View File

@ -134,6 +134,7 @@ method getCommunityItem(self: Module, c: CommunityDto): SectionItem =
result = self.createMemberItem(requestDto.publicKey, requestDto.id)),
declinedMemberRequests = c.declinedRequestsToJoin.map(proc(requestDto: CommunityMembershipRequestDto): MemberItem =
result = self.createMemberItem(requestDto.publicKey, requestDto.id)),
encrypted = c.encrypted,
)
method getCuratedCommunityItem(self: Module, c: CuratedCommunity): CuratedCommunityItem =
@ -232,9 +233,11 @@ method createCommunity*(self: Module, name: string,
aX: int, aY: int, bX: int, bY: int,
historyArchiveSupportEnabled: bool,
pinMessageAllMembersEnabled: bool,
bannerJsonStr: string) =
bannerJsonStr: string,
encrypted: bool) =
self.controller.createCommunity(name, description, introMessage, outroMessage, access, color, tags,
imagePath, aX, aY, bX, bY, historyArchiveSupportEnabled, pinMessageAllMembersEnabled, bannerJsonStr)
imagePath, aX, aY, bX, bY, historyArchiveSupportEnabled, pinMessageAllMembersEnabled,
bannerJsonStr, encrypted)
method deleteCommunityCategory*(self: Module, communityId: string, categoryId: string) =
self.controller.deleteCommunityCategory(communityId, categoryId)
@ -304,8 +307,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) =
self.controller.requestImportDiscordCommunity(name, description, introMessage, outroMessage, access, color, tags, imagePath, aX, aY, bX, bY, historyArchiveSupportEnabled, pinMessageAllMembersEnabled, filesToImport, fromTimestamp)
historyArchiveSupportEnabled: bool, pinMessageAllMembersEnabled: bool, filesToImport: seq[string],
fromTimestamp: int, encrypted: bool) =
self.controller.requestImportDiscordCommunity(name, description, introMessage, outroMessage, access, color, tags, imagePath, aX, aY, bX, bY, historyArchiveSupportEnabled, pinMessageAllMembersEnabled, filesToImport, fromTimestamp, encrypted)
method getDiscordImportTaskItem(self: Module, t: DiscordImportTaskProgress): DiscordImportTaskItem =
return initDiscordImportTaskItem(

View File

@ -327,9 +327,11 @@ QtObject:
imagePath: string,
aX: int, aY: int, bX: int, bY: int,
historyArchiveSupportEnabled: bool,
pinMessageAllMembersEnabled: bool, bannerJsonStr: string) {.slot.} =
pinMessageAllMembersEnabled: bool, bannerJsonStr: string,
encrypted: bool) {.slot.} =
self.delegate.createCommunity(name, description, introMessage, outroMessage, access, color, tags,
imagePath, aX, aY, bX, bY, historyArchiveSupportEnabled, pinMessageAllMembersEnabled, bannerJsonStr)
imagePath, aX, aY, bX, bY, historyArchiveSupportEnabled, pinMessageAllMembersEnabled,
bannerJsonStr, encrypted)
proc clearFileList*(self: View) {.slot.} =
self.discordFileListModel.clearItems()
@ -361,7 +363,7 @@ QtObject:
aX: int, aY: int, bX: int, bY: int,
historyArchiveSupportEnabled: bool,
pinMessageAllMembersEnabled: bool,
fromTimestamp: int) {.slot.} =
fromTimestamp: int, encrypted: bool) {.slot.} =
let selectedItems = self.discordChannelsModel.getSelectedItems()
var filesToImport: seq[string] = @[]
@ -371,7 +373,8 @@ QtObject:
self.resetDiscordImport(false)
self.setDiscordImportInProgress(true)
self.delegate.requestImportDiscordCommunity(name, description, introMessage, outroMessage, access, color, tags,
imagePath, aX, aY, bX, bY, historyArchiveSupportEnabled, pinMessageAllMembersEnabled, filesToImport, fromTimestamp)
imagePath, aX, aY, bX, bY, historyArchiveSupportEnabled, pinMessageAllMembersEnabled,
filesToImport, fromTimestamp, encrypted)
proc deleteCommunityCategory*(self: View, communityId: string, categoryId: string): string {.slot.} =
self.delegate.deleteCommunityCategory(communityId, categoryId)

View File

@ -317,7 +317,8 @@ proc createChannelGroupItem[T](self: Module[T], c: ChannelGroupDto): SectionItem
isVerified = contactDetails.details.isContactVerified(),
requestToJoinId = requestDto.id
)
) else: @[]
) else: @[],
c.encrypted
)

View File

@ -170,6 +170,12 @@ QtObject:
QtProperty[bool] pinMessageAllMembersEnabled:
read = pinMessageAllMembersEnabled
proc encrypted(self: ActiveSection): bool {.slot.} =
return self.item.encrypted
QtProperty[bool] encrypted:
read = encrypted
proc members(self: ActiveSection): QVariant {.slot.} =
if (self.item.id == ""):
# FIXME (Jo) I don't know why but the Item is sometimes empty and doing anything here crashes the app

View File

@ -48,6 +48,7 @@ type
bannedMembersModel: member_model.Model
pendingMemberRequestsModel: member_model.Model
declinedMemberRequestsModel: member_model.Model
encrypted: bool
proc initItem*(
id: string,
@ -82,6 +83,7 @@ proc initItem*(
bannedMembers: seq[MemberItem] = @[],
pendingMemberRequests: seq[MemberItem] = @[],
declinedMemberRequests: seq[MemberItem] = @[],
encrypted: bool = false,
): SectionItem =
result.id = id
result.sectionType = sectionType
@ -120,6 +122,7 @@ proc initItem*(
result.pendingMemberRequestsModel.setItems(pendingMemberRequests)
result.declinedMemberRequestsModel = newModel()
result.declinedMemberRequestsModel.setItems(declinedMemberRequests)
result.encrypted = encrypted
proc isEmpty*(self: SectionItem): bool =
return self.id.len == 0
@ -157,6 +160,7 @@ proc `$`*(self: SectionItem): string =
bannedMembers:{self.bannedMembersModel},
pendingMemberRequests:{self.pendingMemberRequestsModel},
declinedMemberRequests:{self.declinedMemberRequestsModel},
encrypted:{self.encrypted},
]"""
proc id*(self: SectionItem): string {.inline.} =
@ -290,3 +294,6 @@ proc historyArchiveSupportEnabled*(self: SectionItem): bool {.inline.} =
proc pinMessageAllMembersEnabled*(self: SectionItem): bool {.inline.} =
self.pinMessageAllMembersEnabled
proc encrypted*(self: SectionItem): bool {.inline.} =
self.encrypted

View File

@ -36,6 +36,7 @@ type
HistoryArchiveSupportEnabled
PinMessageAllMembersEnabled
BannedMembersModel
Encrypted
QtObject:
type
@ -103,6 +104,7 @@ QtObject:
ModelRole.HistoryArchiveSupportEnabled.int:"historyArchiveSupportEnabled",
ModelRole.PinMessageAllMembersEnabled.int:"pinMessageAllMembersEnabled",
ModelRole.BannedMembersModel.int:"bannedMembers",
ModelRole.Encrypted.int:"encrypted",
}.toTable
method data(self: SectionModel, index: QModelIndex, role: int): QVariant =
@ -176,6 +178,8 @@ QtObject:
result = newQVariant(item.pinMessageAllMembersEnabled)
of ModelRole.BannedMembersModel:
result = newQVariant(item.bannedMembers)
of ModelRole.Encrypted:
result = newQVariant(item.encrypted)
proc isItemExist(self: SectionModel, id: string): bool =
for it in self.items:
@ -282,7 +286,8 @@ QtObject:
ModelRole.PendingRequestsToJoinModel.int,
ModelRole.HistoryArchiveSupportEnabled.int,
ModelRole.PinMessageAllMembersEnabled.int,
ModelRole.BannedMembersModel.int
ModelRole.BannedMembersModel.int,
ModelRole.Encrypted.int,
])
proc getNthEnabledItem*(self: SectionModel, nth: int): SectionItem =
@ -402,6 +407,7 @@ QtObject:
"isMember": item.isMember,
"access": item.access,
"ensOnly": item.ensOnly,
"nbMembers": item.members.getCount()
"nbMembers": item.members.getCount(),
"encrypted": item.encrypted,
}
return $jsonObj

View File

@ -103,6 +103,7 @@ type ChannelGroupDto* = object
historyArchiveSupportEnabled*: bool
pinMessageAllMembersEnabled*: bool
bannedMembersIds*: seq[string]
encrypted*: bool
type ClearedHistoryDto* = object
chatId*: string
@ -259,6 +260,7 @@ proc toChannelGroupDto*(jsonObj: JsonNode): ChannelGroupDto =
discard jsonObj.getProp("description", result.description)
discard jsonObj.getProp("introMessage", result.introMessage)
discard jsonObj.getProp("outroMessage", result.outroMessage)
discard jsonObj.getProp("encrypted", result.encrypted)
result.channelGroupType = ChannelGroupType.Unknown
var channelGroupTypeString: string

View File

@ -71,6 +71,7 @@ type CommunityDto* = object
adminSettings*: CommunityAdminSettingsDto
bannedMembersIds*: seq[string]
declinedRequestsToJoin*: seq[CommunityMembershipRequestDto]
encrypted*: bool
type CuratedCommunity* = object
available*: bool
@ -155,6 +156,7 @@ proc toCommunityDto*(jsonObj: JsonNode): CommunityDto =
discard jsonObj.getProp("description", result.description)
discard jsonObj.getProp("introMessage", result.introMessage)
discard jsonObj.getProp("outroMessage", result.outroMessage)
discard jsonObj.getProp("encrypted", result.encrypted)
var chatsObj: JsonNode
if(jsonObj.getProp("chats", chatsObj)):
@ -268,7 +270,8 @@ proc toChannelGroupDto*(communityDto: CommunityDto): ChannelGroupDto =
canManageUsers: communityDto.canManageUsers,
muted: communityDto.muted,
historyArchiveSupportEnabled: communityDto.settings.historyArchiveSupportEnabled,
bannedMembersIds: communityDto.bannedMembersIds
bannedMembersIds: communityDto.bannedMembersIds,
encrypted: communityDto.encrypted,
)
proc parseCommunitiesSettings*(response: RpcResponse[JsonNode]): seq[CommunitySettingsDto] =

View File

@ -702,7 +702,8 @@ QtObject:
historyArchiveSupportEnabled: bool,
pinMessageAllMembersEnabled: bool,
filesToImport: seq[string],
fromTimestamp: int) =
fromTimestamp: int,
encrypted: bool) =
try:
var image = singletonInstance.utils.formatImagePath(imageUrl)
var tagsString = tags
@ -722,7 +723,8 @@ QtObject:
historyArchiveSupportEnabled,
pinMessageAllMembersEnabled,
filesToImport,
fromTimestamp)
fromTimestamp,
encrypted)
if response.error != nil:
let error = Json.decode($response.error, RpcError)
@ -744,7 +746,8 @@ QtObject:
aX: int, aY: int, bX: int, bY: int,
historyArchiveSupportEnabled: bool,
pinMessageAllMembersEnabled: bool,
bannerJsonStr: string) =
bannerJsonStr: string,
encrypted: bool) =
try:
var image = singletonInstance.utils.formatImagePath(imageUrl)
var tagsString = tags
@ -763,7 +766,8 @@ QtObject:
aX, aY, bX, bY,
historyArchiveSupportEnabled,
pinMessageAllMembersEnabled,
bannerJsonStr)
bannerJsonStr,
encrypted)
if response.error != nil:
let error = Json.decode($response.error, RpcError)

View File

@ -61,7 +61,8 @@ proc createCommunity*(
aX: int, aY: int, bX: int, bY: int,
historyArchiveSupportEnabled: bool,
pinMessageAllMembersEnabled: bool,
bannerJsonStr: string
bannerJsonStr: string,
encrypted: bool
): RpcResponse[JsonNode] {.raises: [Exception].} =
let bannerImage = newCroppedImage(bannerJsonStr)
result = callPrivateRPC("createCommunity".prefix, %*[{
@ -81,7 +82,8 @@ proc createCommunity*(
"imageBy": bY,
"historyArchiveSupportEnabled": historyArchiveSupportEnabled,
"pinMessageAllMembersEnabled": pinMessageAllMembersEnabled,
"banner": bannerImage
"banner": bannerImage,
"encrypted": encrypted
}])
proc editCommunity*(
@ -136,7 +138,8 @@ proc requestImportDiscordCommunity*(
historyArchiveSupportEnabled: bool,
pinMessageAllMembersEnabled: bool,
filesToImport: seq[string],
fromTimestamp: int
fromTimestamp: int,
encrypted: bool,
): RpcResponse[JsonNode] {.raises: [Exception].} =
result = callPrivateRPC("requestImportDiscordCommunity".prefix, %*[{
# TODO this will need to be renamed membership (small m)
@ -156,7 +159,8 @@ proc requestImportDiscordCommunity*(
"historyArchiveSupportEnabled": historyArchiveSupportEnabled,
"pinMessageAllMembersEnabled": pinMessageAllMembersEnabled,
"from": fromTimestamp,
"filesToImport": filesToImport
"filesToImport": filesToImport,
"encrypted": encrypted,
}])
proc requestCancelDiscordCommunityImport*(communityId: string): RpcResponse[JsonNode] {.raises: [Exception].} =

View File

@ -14,6 +14,9 @@ ColumnLayout {
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
@ -74,4 +77,24 @@ ColumnLayout {
id: pinMessagesToggle
}
}
RowLayout {
Layout.fillWidth: true
Layout.preferredHeight: d.optionHeight
visible: requestToJoinToggle.checked
StatusBaseText {
Layout.fillWidth: true
text: qsTr("Encrypted")
TapHandler {
enabled: !encryptReadOnly
onTapped: encryptedToggle.toggle()
}
}
StatusCheckBox {
id: encryptedToggle
enabled: !encryptReadOnly
}
}
}

View File

@ -29,6 +29,7 @@ StackLayout {
property bool archiveSupportEnabled
property bool requestToJoinEnabled
property bool pinMessagesEnabled
property bool encrypted
property bool archiveSupportOptionVisible: false
property bool editable: false
@ -186,6 +187,8 @@ StackLayout {
archiveSupportEnabled: root.archiveSupportEnabled
requestToJoinEnabled: root.requestToJoinEnabled
pinMessagesEnabled: root.pinMessagesEnabled
encrypted: root.encrypted
encryptReadOnly: true
}
bottomReservedSpace: editCommunityPage.settingsDirtyToastMessageImplicitSize

View File

@ -243,7 +243,8 @@ QtObject {
options: {
historyArchiveSupportEnabled: false,
checkedMembership: false,
pinMessagesAllowedForMembers: false
pinMessagesAllowedForMembers: false,
encrypted: false
},
bannerJsonStr: ""
}) {
@ -251,7 +252,8 @@ QtObject {
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, args.bannerJsonStr);
args.options.historyArchiveSupportEnabled, args.options.pinMessagesAllowedForMembers,
args.bannerJsonStr, args.options.encrypted);
}
function importCommunity(communityKey) {

View File

@ -178,6 +178,7 @@ 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
onCurrentIndexChanged: {

View File

@ -492,7 +492,8 @@ StatusStackModal {
options: {
historyArchiveSupportEnabled: options.archiveSupportEnabled,
checkedMembership: options.requestToJoinEnabled ? Constants.communityChatOnRequestAccess : Constants.communityChatPublicAccess,
pinMessagesAllowedForMembers: options.pinMessagesEnabled
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})
}

View File

@ -69,7 +69,8 @@ QtObject {
options: {
historyArchiveSupportEnabled: false,
checkedMembership: false,
pinMessagesAllowedForMembers: false
pinMessagesAllowedForMembers: false,
encrypted: false,
},
bannerJsonStr: ""
}) {
@ -77,7 +78,8 @@ QtObject {
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, args.bannerJsonStr);
args.options.historyArchiveSupportEnabled, args.options.pinMessagesAllowedForMembers,
args.bannerJsonStr, args.options.encrypted);
}
function importCommunity(communityKey) {
@ -141,13 +143,14 @@ QtObject {
options: {
historyArchiveSupportEnabled: false,
checkedMembership: false,
pinMessagesAllowedForMembers: 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.historyArchiveSupportEnabled, args.options.pinMessagesAllowedForMembers, from, args.options.encrypted);
}
}

View File

@ -109,11 +109,12 @@ QtObject {
function createCommunity(communityName, communityDescription, checkedMembership, communityColor, communityTags,
communityImage, imageCropperModalaX, imageCropperModalaY, imageCropperModalbX, imageCropperModalbY,
historyArchiveSupportEnabled, pinMessagesAllowedForMembers, bannerJsonStr) {
historyArchiveSupportEnabled, pinMessagesAllowedForMembers, bannerJsonStr, encrypted) {
communitiesModuleInst.createCommunity(communityName, communityDescription, checkedMembership, communityColor,
communityTags, communityImage, imageCropperModalaX, imageCropperModalaY,
imageCropperModalbX, imageCropperModalbY,
historyArchiveSupportEnabled, pinMessagesAllowedForMembers, bannerJsonStr);
historyArchiveSupportEnabled, pinMessagesAllowedForMembers,
bannerJsonStr, encrypted);
}
function communityHasMember(communityId, pubKey)

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit a69a59c6014566344c1c102099baa192dd6e0a7c
Subproject commit 7eb66d09e7ff1ad3bac24d7049681f7fbb6b7905