feat: introduce communities settings and history archive support UI

control
This commit is contained in:
Pascal Precht 2022-04-08 12:46:38 +02:00 committed by r4bbit.eth
parent 1d934c7b26
commit 8d4aa7dd56
18 changed files with 145 additions and 38 deletions

View File

@ -381,7 +381,8 @@ proc editCommunity*(
ensOnly: bool,
color: string,
imageUrl: string,
aX: int, aY: int, bX: int, bY: int) =
aX: int, aY: int, bX: int, bY: int,
historyArchiveSupportEnabled: bool) =
self.communityService.editCommunity(
self.sectionId,
name,
@ -390,7 +391,8 @@ proc editCommunity*(
ensOnly,
color,
imageUrl,
aX, aY, bX, bY)
aX, aY, bX, bY,
historyArchiveSupportEnabled)
proc exportCommunity*(self: Controller): string =
self.communityService.exportCommunity(self.sectionId)

View File

@ -241,7 +241,7 @@ method removeUserFromCommunity*(self: AccessInterface, pubKey: string) {.base.}
method banUserFromCommunity*(self: AccessInterface, pubKey: string) {.base.} =
raise newException(ValueError, "No implementation available")
method editCommunity*(self: AccessInterface, name: string, description: string, access: int, ensOnly: bool, color: string, imagePath: string, aX: int, aY: int, bX: int, bY: int) {.base.} =
method editCommunity*(self: AccessInterface, name: string, description: string, access: int, ensOnly: bool, color: string, imagePath: string, aX: int, aY: int, bX: int, bY: int, historyArchiveSupportEnabled: bool) {.base.} =
raise newException(ValueError, "No implementation available")
method exportCommunity*(self: AccessInterface): string {.base.} =

View File

@ -730,8 +730,8 @@ method banUserFromCommunity*(self: Module, pubKey: string) =
method editCommunity*(self: Module, name: string, description: string,
access: int, ensOnly: bool, color: string,
imagePath: string,
aX: int, aY: int, bX: int, bY: int) =
self.controller.editCommunity(name, description, access, ensOnly, color, imagePath, aX, aY, bX, bY)
aX: int, aY: int, bX: int, bY: int, historyArchiveSupportEnabled: bool) =
self.controller.editCommunity(name, description, access, ensOnly, color, imagePath, aX, aY, bX, bY, historyArchiveSupportEnabled)
method exportCommunity*(self: Module): string =
self.controller.exportCommunity()

View File

@ -244,8 +244,8 @@ QtObject:
proc banUserFromCommunity*(self: View, pubKey: string) {.slot.} =
self.delegate.banUserFromCommunity(pubKey)
proc editCommunity*(self: View, name: string, description: string, access: int, ensOnly: bool, color: string, imagePath: string, aX: int, aY: int, bX: int, bY: int) {.slot.} =
self.delegate.editCommunity(name, description, access, ensOnly, color, imagePath, aX, aY, bX, bY)
proc editCommunity*(self: View, name: string, description: string, access: int, ensOnly: bool, color: string, imagePath: string, aX: int, aY: int, bX: int, bY: int, historyArchiveSupportEnabled: bool) {.slot.} =
self.delegate.editCommunity(name, description, access, ensOnly, color, imagePath, aX, aY, bX, bY, historyArchiveSupportEnabled)
proc exportCommunity*(self: View): string {.slot.} =
self.delegate.exportCommunity()

View File

@ -70,7 +70,8 @@ proc createCommunity*(
ensOnly: bool,
color: string,
imageUrl: string,
aX: int, aY: int, bX: int, bY: int) =
aX: int, aY: int, bX: int, bY: int,
historyArchiveSupportEnabled: bool) =
self.communityService.createCommunity(
name,
description,
@ -78,7 +79,8 @@ proc createCommunity*(
ensOnly,
color,
imageUrl,
aX, aY, bX, bY)
aX, aY, bX, bY,
historyArchiveSupportEnabled)
proc reorderCommunityChat*(
self: Controller,

View File

@ -22,7 +22,7 @@ method getCommunityItem*(self: AccessInterface, community: CommunityDto): Sectio
method joinCommunity*(self: AccessInterface, communityId: string): string {.base.} =
raise newException(ValueError, "No implementation available")
method createCommunity*(self: AccessInterface, name: string, description: string, access: int, ensOnly: bool, color: string, imagePath: string, aX: int, aY: int, bX: int, bY: int) {.base.} =
method createCommunity*(self: AccessInterface, name: string, description: string, access: int, ensOnly: bool, color: string, imagePath: string, aX: int, aY: int, bX: int, bY: int, historyArchiveSupportEnabled: bool) {.base.} =
raise newException(ValueError, "No implementation available")
method deleteCommunityCategory*(self: AccessInterface, communityId: string, categoryId: string) {.base.} =

View File

@ -99,7 +99,8 @@ method getCommunityItem(self: Module, c: CommunityDto): SectionItem =
OnlineStatus.Offline, # TODO get the actual status?
contactDetails.icon,
contactDetails.details.added,
))
)),
historyArchiveSupportEnabled = c.settings.historyArchiveSupportEnabled
)
method setAllCommunities*(self: Module, communities: seq[CommunityDto]) =
@ -147,8 +148,9 @@ method communityCategoryDeleted*(self: Module) =
method createCommunity*(self: Module, name: string, description: string,
access: int, ensOnly: bool, color: string,
imagePath: string,
aX: int, aY: int, bX: int, bY: int) =
self.controller.createCommunity(name, description, access, ensOnly, color, imagePath, aX, aY, bX, bY)
aX: int, aY: int, bX: int, bY: int,
historyArchiveSupportEnabled: bool) =
self.controller.createCommunity(name, description, access, ensOnly, color, imagePath, aX, aY, bX, bY, historyArchiveSupportEnabled)
method deleteCommunityCategory*(self: Module, communityId: string, categoryId: string) =
self.controller.deleteCommunityCategory(communityId, categoryId)

View File

@ -68,8 +68,9 @@ QtObject:
proc createCommunity*(self: View, name: string, description: string,
access: int, ensOnly: bool, color: string,
imagePath: string,
aX: int, aY: int, bX: int, bY: int) {.slot.} =
self.delegate.createCommunity(name, description, access, ensOnly, color, imagePath, aX, aY, bX, bY)
aX: int, aY: int, bX: int, bY: int,
historyArchiveSupportEnabled: bool) {.slot.} =
self.delegate.createCommunity(name, description, access, ensOnly, color, imagePath, aX, aY, bX, bY, historyArchiveSupportEnabled)
proc deleteCommunityCategory*(self: View, communityId: string, categoryId: string): string {.slot.} =
self.delegate.deleteCommunityCategory(communityId, categoryId)

View File

@ -226,9 +226,12 @@ proc createChannelGroupItem[T](self: Module[T], c: ChannelGroupDto): SectionItem
x.communityId,
x.state,
x.our
)) else: @[]
)) else: @[],
communityDetails.settings.historyArchiveSupportEnabled
)
method load*[T](
self: Module[T],
events: EventEmitter,

View File

@ -17,11 +17,13 @@ QtObject:
proc membersChanged*(self: ActiveSection) {.signal.}
proc pendingRequestsToJoinChanged*(self: ActiveSection) {.signal.}
proc historyArchiveSupportEnabledChanged*(self: ActiveSection) {.signal.}
proc setActiveSectionData*(self: ActiveSection, item: SectionItem) =
self.item = item
self.membersChanged()
self.pendingRequestsToJoinChanged()
self.historyArchiveSupportEnabledChanged()
proc getId*(self: ActiveSection): string {.slot.} =
return self.item.id
@ -125,6 +127,12 @@ QtObject:
QtProperty[bool] ensOnly:
read = ensOnly
proc historyArchiveSupportEnabled(self: ActiveSection): bool {.slot.} =
return self.item.historyArchiveSupportEnabled
QtProperty[bool] historyArchiveSupportEnabled:
read = historyArchiveSupportEnabled
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

@ -34,6 +34,7 @@ type
ensOnly: bool
membersModel: user_model.Model
pendingRequestsToJoinModel: PendingRequestModel
historyArchiveSupportEnabled: bool
proc initItem*(
id: string,
@ -56,7 +57,8 @@ proc initItem*(
access: int = 0,
ensOnly = false,
members: seq[user_item.Item] = @[],
pendingRequestsToJoin: seq[PendingRequestItem] = @[]
pendingRequestsToJoin: seq[PendingRequestItem] = @[],
historyArchiveSupportEnabled = false
): SectionItem =
result.id = id
result.sectionType = sectionType
@ -81,6 +83,7 @@ proc initItem*(
result.membersModel.setItems(members)
result.pendingRequestsToJoinModel = newPendingRequestModel()
result.pendingRequestsToJoinModel.setItems(pendingRequestsToJoin)
result.historyArchiveSupportEnabled = historyArchiveSupportEnabled
proc isEmpty*(self: SectionItem): bool =
return self.id.len == 0
@ -107,6 +110,7 @@ proc `$`*(self: SectionItem): string =
access:{self.access},
ensOnly:{self.ensOnly},
members:{self.membersModel},
historyArchiveSupportEnabled:{self.historyArchiveSupportEnabled},
]"""
proc id*(self: SectionItem): string {.inline.} =
@ -196,3 +200,6 @@ proc updateMember*(
proc pendingRequestsToJoin*(self: SectionItem): PendingRequestModel {.inline.} =
self.pendingRequestsToJoinModel
proc historyArchiveSupportEnabled*(self: SectionItem): bool {.inline.} =
self.historyArchiveSupportEnabled

View File

@ -27,6 +27,7 @@ type
EnsOnly
MembersModel
PendingRequestsToJoinModel
HistoryArchiveSupportEnabled
QtObject:
type
@ -85,6 +86,7 @@ QtObject:
ModelRole.EnsOnly.int:"ensOnly",
ModelRole.MembersModel.int:"members",
ModelRole.PendingRequestsToJoinModel.int:"pendingRequestsToJoin",
ModelRole.HistoryArchiveSupportEnabled.int:"historyArchiveSupportEnabled",
}.toTable
method data(self: SectionModel, index: QModelIndex, role: int): QVariant =
@ -140,6 +142,8 @@ QtObject:
result = newQVariant(item.members)
of ModelRole.PendingRequestsToJoinModel:
result = newQVariant(item.pendingRequestsToJoin)
of ModelRole.HistoryArchiveSupportEnabled:
result = newQVariant(item.historyArchiveSupportEnabled)
proc isItemExist(self: SectionModel, id: string): bool =
for it in self.items:
@ -211,7 +215,8 @@ QtObject:
ModelRole.CanJoin.int,
ModelRole.Joined.int,
ModelRole.MembersModel.int,
ModelRole.PendingRequestsToJoinModel.int
ModelRole.PendingRequestsToJoinModel.int,
ModelRole.HistoryArchiveSupportEnabled.int
])
proc getItemById*(self: SectionModel, id: string): SectionItem =

View File

@ -87,6 +87,7 @@ type ChannelGroupDto* = object
canManageUsers*: bool
color*: string
muted*: bool
historyArchiveSupportEnabled*: bool
proc `$`*(self: ChatDto): string =
result = fmt"""ChatDto(

View File

@ -35,6 +35,10 @@ type CommunityMembershipRequestDto* = object
state*: int
our*: string
type CommunitySettingsDto* = object
id*: string
historyArchiveSupportEnabled*: bool
type CommunityDto* = object
id*: string
admin*: bool
@ -56,6 +60,7 @@ type CommunityDto* = object
isMember*: bool
muted*: bool
pendingRequestsToJoin*: seq[CommunityMembershipRequestDto]
settings*: CommunitySettingsDto
proc toCommunityDto*(jsonObj: JsonNode): CommunityDto =
result = CommunityDto()
@ -107,6 +112,11 @@ proc toCommunityMembershipRequestDto*(jsonObj: JsonNode): CommunityMembershipReq
discard jsonObj.getProp("communityId", result.communityId)
discard jsonObj.getProp("our", result.our)
proc toCommunitySettingsDto*(jsonObj: JsonNode): CommunitySettingsDto =
result = CommunitySettingsDto()
discard jsonObj.getProp("communityId", result.id)
discard jsonObj.getProp("historyArchiveSupportEnabled", result.historyArchiveSupportEnabled)
proc parseCommunities*(response: RpcResponse[JsonNode]): seq[CommunityDto] =
result = map(response.result.getElems(),
proc(x: JsonNode): CommunityDto = x.toCommunityDto())
@ -138,5 +148,10 @@ proc toChannelGroupDto*(communityDto: CommunityDto): ChannelGroupDto =
admin: m.roles.contains(CommunityMemberRoles.ManagerUsers.int)
)),
canManageUsers: communityDto.canManageUsers,
muted: communityDto.muted
)
muted: communityDto.muted,
historyArchiveSupportEnabled: communityDto.settings.historyArchiveSupportEnabled
)
proc parseCommunitiesSettings*(response: RpcResponse[JsonNode]): seq[CommunitySettingsDto] =
result = map(response.result.getElems(),
proc(x: JsonNode): CommunitySettingsDto = x.toCommunitySettingsDto())

View File

@ -97,6 +97,7 @@ QtObject:
# Forward declaration
proc loadAllCommunities(self: Service): seq[CommunityDto]
proc loadJoinedComunities(self: Service): seq[CommunityDto]
proc loadCommunitiesSettings(self: Service): seq[CommunitySettingsDto]
proc loadMyPendingRequestsToJoin*(self: Service)
proc handleCommunityUpdates(self: Service, communities: seq[CommunityDto], updatedChats: seq[ChatDto])
proc pendingRequestsToJoinForCommunity*(self: Service, communityId: string): seq[CommunityMembershipRequestDto]
@ -295,6 +296,13 @@ QtObject:
for community in allCommunities:
self.allCommunities[community.id] = community
let communitiesSettings = self.loadCommunitiesSettings()
for settings in communitiesSettings:
if self.allCommunities.hasKey(settings.id):
self.allCommunities[settings.id].settings = settings
if self.joinedCommunities.hasKey(settings.id):
self.joinedCommunities[settings.id].settings = settings
self.loadMyPendingRequestsToJoin()
except Exception as e:
@ -310,6 +318,10 @@ QtObject:
let response = status_go.getJoinedComunities()
return parseCommunities(response)
proc loadCommunitiesSettings(self: Service): seq[CommunitySettingsDto] =
let response = status_go.getCommunitiesSettings()
return parseCommunitiesSettings(response)
proc getJoinedCommunities*(self: Service): seq[CommunityDto] =
return toSeq(self.joinedCommunities.values)
@ -412,8 +424,10 @@ QtObject:
error "error: ", procName="joinCommunity", errDesription = "result is nil"
return
let updatedCommunity = response.result["communities"][0].toCommunityDto()
var updatedCommunity = response.result["communities"][0].toCommunityDto()
let communitySettings = response.result["communitiesSettings"][0].toCommunitySettingsDto()
updatedCommunity.settings = communitySettings
self.allCommunities[communityId] = updatedCommunity
self.joinedCommunities[communityId] = updatedCommunity
@ -502,7 +516,8 @@ QtObject:
ensOnly: bool,
color: string,
imageUrl: string,
aX: int, aY: int, bX: int, bY: int) =
aX: int, aY: int, bX: int, bY: int,
historyArchiveSupportEnabled: bool) =
try:
var image = singletonInstance.utils.formatImagePath(imageUrl)
let response = status_go.createCommunity(
@ -512,16 +527,20 @@ QtObject:
ensOnly,
color,
image,
aX, aY, bX, bY)
aX, aY, bX, bY,
historyArchiveSupportEnabled)
if response.error != nil:
let error = Json.decode($response.error, RpcError)
raise newException(RpcException, "Error creating community: " & error.message)
if response.result != nil and response.result.kind != JNull:
let community = response.result["communities"][0].toCommunityDto()
var community = response.result["communities"][0].toCommunityDto()
let communitySettings = response.result["communitiesSettings"][0].toCommunitySettingsDto()
# add this to the joinedCommunities list
community.settings = communitySettings
# add this to the joinedCommunities list and communitiesSettings
self.joinedCommunities[community.id] = community
self.events.emit(SIGNAL_COMMUNITY_CREATED, CommunityArgs(community: community))
@ -537,7 +556,8 @@ QtObject:
ensOnly: bool,
color: string,
imageUrl: string,
aX: int, aY: int, bX: int, bY: int) =
aX: int, aY: int, bX: int, bY: int,
historyArchiveSupportEnabled: bool) =
try:
var image = singletonInstance.utils.formatImagePath(imageUrl)
let response = status_go.editCommunity(
@ -548,7 +568,8 @@ QtObject:
ensOnly,
color,
image,
aX, aY, bX, bY)
aX, aY, bX, bY,
historyArchiveSupportEnabled)
if response.error != nil:
let error = Json.decode($response.error, RpcError)
@ -556,9 +577,10 @@ QtObject:
if response.result != nil and response.result.kind != JNull:
var community = response.result["communities"][0].toCommunityDto()
var communitySettings = response.result["communitiesSettings"][0].toCommunitySettingsDto()
community.settings = communitySettings
self.saveUpdatedJoinedCommunity(community)
self.events.emit(SIGNAL_COMMUNITY_EDITED, CommunityArgs(community: community))
except Exception as e:
error "Error editing community", msg = e.msg
@ -840,11 +862,21 @@ QtObject:
if(communityJArr.len == 0):
raise newException(RpcException, fmt"`communities` array is empty in the response for community id: {communityKey}")
var communitiesSettingsJArr: JsonNode
if(not response.result.getProp("communitiesSettings", communitiesSettingsJArr)):
raise newException(RpcException, fmt"there is no `communitiesSettings` key in the response for community id: {communityKey}")
if(communitiesSettingsJArr.len == 0):
raise newException(RpcException, fmt"`communitiesSettings` array is empty in the response for community id: {communityKey}")
var chatsJArr: JsonNode
if(not response.result.getProp("chats", chatsJArr)):
raise newException(RpcException, fmt"there is no `chats` key in the response for community id: {communityKey}")
let communityDto = communityJArr[0].toCommunityDto()
var communityDto = communityJArr[0].toCommunityDto()
let communitySettingsDto = communitiesSettingsJArr[0].toCommunitySettingsDto()
communityDto.settings = communitySettingsDto
self.joinedCommunities[communityDto.id] = communityDto
for chatObj in chatsJArr:
@ -955,4 +987,4 @@ QtObject:
for communityRequest in self.myCommunityRequests:
if (communityRequest.communityId == communityId):
return true
return false
return false

View File

@ -36,7 +36,8 @@ proc createCommunity*(
ensOnly: bool,
color: string,
imageUrl: string,
aX: int, aY: int, bX: int, bY: int
aX: int, aY: int, bX: int, bY: int,
historyArchiveSupportEnabled: bool
): RpcResponse[JsonNode] {.raises: [Exception].} =
result = callPrivateRPC("createCommunity".prefix, %*[{
# TODO this will need to be renamed membership (small m)
@ -49,7 +50,8 @@ proc createCommunity*(
"imageAx": aX,
"imageAy": aY,
"imageBx": bX,
"imageBy": bY
"imageBy": bY,
"historyArchiveSupportEnabled": historyArchiveSupportEnabled,
}])
proc editCommunity*(
@ -63,7 +65,8 @@ proc editCommunity*(
aX: int,
aY: int,
bX: int,
bY: int
bY: int,
historyArchiveSupportEnabled: bool
): RpcResponse[JsonNode] {.raises: [Exception].} =
result = callPrivateRPC("editCommunity".prefix, %*[{
# TODO this will need to be renamed membership (small m)
@ -77,7 +80,8 @@ proc editCommunity*(
"imageAx": aX,
"imageAy": aY,
"imageBx": bX,
"imageBy": bY
"imageBy": bY,
"historyArchiveSupportEnabled": historyArchiveSupportEnabled
}])
proc createCommunityChannel*(
@ -230,3 +234,6 @@ proc inviteUsersToCommunity*(communityId: string, pubKeys: seq[string]): RpcResp
"communityId": communityId,
"users": pubKeys
}])
proc getCommunitiesSettings*(): RpcResponse[JsonNode] {.raises: [Exception].} =
return callPrivateRPC("getCommunitiesSettings".prefix, %*[])

View File

@ -66,6 +66,7 @@ StatusModal {
property alias communityColor: colorDialog
property alias communityImage: addImageButton
property alias imageCropperModal: imageCropperModal
property alias historyArchiveSupportToggle: historyArchiveSupportToggle
contentHeight: content.height
bottomPadding: 8
@ -338,6 +339,25 @@ StatusModal {
anchors.leftMargin: 16
}
StatusListItem {
anchors.horizontalCenter: parent.horizontalCenter
visible: popup.store.isCommunityHistoryArchiveSupportEnabled
//% "Membership requirement"
title: qsTrId("History Archive Support")
sensor.onClicked: {
if (popup.store.isCommunityHistoryArchiveSupportEnabled) {
historyArchiveSupportToggle.checked = !historyArchiveSupportToggle.checked
}
}
components: [
StatusSwitch {
id: historyArchiveSupportToggle
enabled: popup.store.isCommunityHistoryArchiveSupportEnabled
checked: isEdit ? community.historyArchiveSupportEnabled : false
}
]
}
// Feature commented temporarily
/*
StatusSettingsLineButton {
@ -426,7 +446,8 @@ StatusModal {
popup.contentItem.imageCropperModal.aX,
popup.contentItem.imageCropperModal.aY,
popup.contentItem.imageCropperModal.bX,
popup.contentItem.imageCropperModal.bY
popup.contentItem.imageCropperModal.bY,
popup.contentItem.historyArchiveSupportToggle.checked
)
} else {
error = popup.store.createCommunity(
@ -439,7 +460,8 @@ StatusModal {
popup.contentItem.imageCropperModal.aX,
popup.contentItem.imageCropperModal.aY,
popup.contentItem.imageCropperModal.bX,
popup.contentItem.imageCropperModal.bY
popup.contentItem.imageCropperModal.bY,
popup.contentItem.historyArchiveSupportToggle.checked
)
}

View File

@ -210,8 +210,8 @@ QtObject {
// Not Refactored Yet
property var activeCommunityChatsModel: "" //chatsModelInst.communities.activeCommunity.chats
function createCommunity(communityName, communityDescription, checkedMembership, ensOnlySwitchChecked, communityColor, communityImage, imageCropperModalaX, imageCropperModalaY, imageCropperModalbX, imageCropperModalbY) {
communitiesModuleInst.createCommunity(communityName, communityDescription, checkedMembership, ensOnlySwitchChecked, communityColor, communityImage, imageCropperModalaX, imageCropperModalaY, imageCropperModalbX, imageCropperModalbY);
function createCommunity(communityName, communityDescription, checkedMembership, ensOnlySwitchChecked, communityColor, communityImage, imageCropperModalaX, imageCropperModalaY, imageCropperModalbX, imageCropperModalbY, historyArchiveSupportEnabled) {
communitiesModuleInst.createCommunity(communityName, communityDescription, checkedMembership, ensOnlySwitchChecked, communityColor, communityImage, imageCropperModalaX, imageCropperModalaY, imageCropperModalbX, imageCropperModalbY, historyArchiveSupportEnabled);
}
function importCommunity(communityKey) {