Skip to content

Commit

Permalink
feat(CommunitySettings): add checkbox to allow members to pin messages
Browse files Browse the repository at this point in the history
This adds a checkbox to configure whether or not community members are
allowed to pin any message of a community channel, based on the newly
introduced `CommunityAdminSettings` that are introduced in status-im/status-go#2668

Closes #5662
  • Loading branch information
0x-r4bbit committed May 19, 2022
1 parent ad584f3 commit 8c496e0
Show file tree
Hide file tree
Showing 25 changed files with 118 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ method getChatColor*(self: AccessInterface): string {.base.} =
method amIChatAdmin*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")

method pinMessageAllowedForMembers*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")

method getNumberOfPinnedMessages*(self: AccessInterface): int {.base.} =
raise newException(ValueError, "No implementation available")

Expand Down Expand Up @@ -122,4 +125,4 @@ method leaveChat*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

method didIJoinedChat*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")
raise newException(ValueError, "No implementation available")
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,12 @@ method amIChatAdmin*(self: Module): bool =
let communityDto = self.controller.getCommunityDetails()
return communityDto.admin

method pinMessageAllowedForMembers*(self: Module): bool =
if(self.controller.belongsToCommunity()):
let communityDto = self.controller.getCommunityDetails()
return communityDto.adminSettings.pinMessageAllMembersEnabled
return false

method getNumberOfPinnedMessages*(self: Module): int =
return self.controller.getNumOfPinnedMessages()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ QtObject:
proc amIChatAdmin*(self: View): bool {.slot.} =
return self.delegate.amIChatAdmin()

proc pinMessageAllowedForMembers*(self: View): bool {.slot.} =
return self.delegate.pinMessageAllowedForMembers()

proc getNumberOfPinnedMessages*(self: View): int {.slot.} =
return self.delegate.getNumberOfPinnedMessages()

Expand Down Expand Up @@ -165,4 +168,4 @@ QtObject:

proc refreshAMessageUserRespondedTo(self: View, msgId: string) {.signal.}
proc emitRefreshAMessageUserRespondedToSignal*(self: View, msgId: string) =
self.refreshAMessageUserRespondedTo(msgId)
self.refreshAMessageUserRespondedTo(msgId)
6 changes: 4 additions & 2 deletions src/app/modules/main/chat_section/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,8 @@ proc editCommunity*(
color: string,
imageUrl: string,
aX: int, aY: int, bX: int, bY: int,
historyArchiveSupportEnabled: bool) =
historyArchiveSupportEnabled: bool,
pinMessageAllMembersEnabled: bool) =
self.communityService.editCommunity(
self.sectionId,
name,
Expand All @@ -388,7 +389,8 @@ proc editCommunity*(
color,
imageUrl,
aX, aY, bX, bY,
historyArchiveSupportEnabled)
historyArchiveSupportEnabled,
pinMessageAllMembersEnabled)

proc exportCommunity*(self: Controller): string =
self.communityService.exportCommunity(self.sectionId)
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 @@ -243,7 +243,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, color: string, imagePath: string, aX: int, aY: int, bX: int, bY: int, historyArchiveSupportEnabled: bool) {.base.} =
method editCommunity*(self: AccessInterface, name: string, description: string, access: int, color: string, imagePath: string, aX: int, aY: int, bX: int, bY: int, historyArchiveSupportEnabled: bool, pinMessageAllMembersEnabled: bool) {.base.} =
raise newException(ValueError, "No implementation available")

method exportCommunity*(self: AccessInterface): string {.base.} =
Expand Down
5 changes: 3 additions & 2 deletions src/app/modules/main/chat_section/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -726,8 +726,9 @@ method banUserFromCommunity*(self: Module, pubKey: string) =
method editCommunity*(self: Module, name: string, description: string,
access: int, color: string,
imagePath: string,
aX: int, aY: int, bX: int, bY: int, historyArchiveSupportEnabled: bool) =
self.controller.editCommunity(name, description, access, color, imagePath, aX, aY, bX, bY, historyArchiveSupportEnabled)
aX: int, aY: int, bX: int, bY: int, historyArchiveSupportEnabled: bool,
pinMessageAllMembersEnabled: bool) =
self.controller.editCommunity(name, description, access, color, imagePath, aX, aY, bX, bY, historyArchiveSupportEnabled, pinMessageAllMembersEnabled)

method exportCommunity*(self: Module): string =
self.controller.exportCommunity()
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 @@ -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, color: string, imagePath: string, aX: int, aY: int, bX: int, bY: int, historyArchiveSupportEnabled: bool) {.slot.} =
self.delegate.editCommunity(name, description, access, color, imagePath, aX, aY, bX, bY, historyArchiveSupportEnabled)
proc editCommunity*(self: View, name: string, description: string, access: int, color: string, imagePath: string, aX: int, aY: int, bX: int, bY: int, historyArchiveSupportEnabled: bool, pinMessageAllMembersEnabled: bool) {.slot.} =
self.delegate.editCommunity(name, description, access, color, imagePath, aX, aY, bX, bY, historyArchiveSupportEnabled, pinMessageAllMembersEnabled)

proc exportCommunity*(self: View): string {.slot.} =
self.delegate.exportCommunity()
Expand Down
6 changes: 4 additions & 2 deletions src/app/modules/main/communities/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,17 @@ proc createCommunity*(
color: string,
imageUrl: string,
aX: int, aY: int, bX: int, bY: int,
historyArchiveSupportEnabled: bool) =
historyArchiveSupportEnabled: bool,
pinMessageAllMembersEnabled: bool) =
self.communityService.createCommunity(
name,
description,
access,
color,
imageUrl,
aX, aY, bX, bY,
historyArchiveSupportEnabled)
historyArchiveSupportEnabled,
pinMessageAllMembersEnabled)

proc reorderCommunityChat*(
self: Controller,
Expand Down
2 changes: 1 addition & 1 deletion src/app/modules/main/communities/io_interface.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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, color: string, imagePath: string, aX: int, aY: int, bX: int, bY: int, historyArchiveSupportEnabled: bool) {.base.} =
method createCommunity*(self: AccessInterface, name: string, description: string, access: int, color: string, imagePath: string, aX: int, aY: int, bX: int, bY: int, historyArchiveSupportEnabled: bool, pinMessageAllMembersEnabled: bool) {.base.} =
raise newException(ValueError, "No implementation available")

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

method deleteCommunityCategory*(self: Module, communityId: string, categoryId: string) =
self.controller.deleteCommunityCategory(communityId, categoryId)
Expand Down
5 changes: 3 additions & 2 deletions src/app/modules/main/communities/view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ QtObject:
access: int, color: string,
imagePath: string,
aX: int, aY: int, bX: int, bY: int,
historyArchiveSupportEnabled: bool) {.slot.} =
self.delegate.createCommunity(name, description, access, color, imagePath, aX, aY, bX, bY, historyArchiveSupportEnabled)
historyArchiveSupportEnabled: bool,
pinMessageAllMembersEnabled: bool) {.slot.} =
self.delegate.createCommunity(name, description, access, color, imagePath, aX, aY, bX, bY, historyArchiveSupportEnabled, pinMessageAllMembersEnabled)

proc deleteCommunityCategory*(self: View, communityId: string, categoryId: string): string {.slot.} =
self.delegate.deleteCommunityCategory(communityId, categoryId)
Expand Down
3 changes: 2 additions & 1 deletion src/app/modules/main/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ proc createChannelGroupItem[T](self: Module[T], c: ChannelGroupDto): SectionItem
x.state,
x.our
)) else: @[],
communityDetails.settings.historyArchiveSupportEnabled
communityDetails.settings.historyArchiveSupportEnabled,
communityDetails.adminSettings.pinMessageAllMembersEnabled
)


Expand Down
6 changes: 6 additions & 0 deletions src/app/modules/shared_models/active_section.nim
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ QtObject:
QtProperty[bool] historyArchiveSupportEnabled:
read = historyArchiveSupportEnabled

proc pinMessageAllMembersEnabled(self: ActiveSection): bool {.slot.} =
return self.item.pinMessageAllMembersEnabled

QtProperty[bool] pinMessageAllMembersEnabled:
read = pinMessageAllMembersEnabled

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
Expand Down
9 changes: 8 additions & 1 deletion src/app/modules/shared_models/section_item.nim
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type
membersModel: user_model.Model
pendingRequestsToJoinModel: PendingRequestModel
historyArchiveSupportEnabled: bool
pinMessageAllMembersEnabled: bool

proc initItem*(
id: string,
Expand All @@ -58,7 +59,8 @@ proc initItem*(
ensOnly = false,
members: seq[user_item.Item] = @[],
pendingRequestsToJoin: seq[PendingRequestItem] = @[],
historyArchiveSupportEnabled = false
historyArchiveSupportEnabled = false,
pinMessageAllMembersEnabled = false
): SectionItem =
result.id = id
result.sectionType = sectionType
Expand All @@ -84,6 +86,7 @@ proc initItem*(
result.pendingRequestsToJoinModel = newPendingRequestModel()
result.pendingRequestsToJoinModel.setItems(pendingRequestsToJoin)
result.historyArchiveSupportEnabled = historyArchiveSupportEnabled
result.pinMessageAllMembersEnabled = pinMessageAllMembersEnabled

proc isEmpty*(self: SectionItem): bool =
return self.id.len == 0
Expand Down Expand Up @@ -111,6 +114,7 @@ proc `$`*(self: SectionItem): string =
ensOnly:{self.ensOnly},
members:{self.membersModel},
historyArchiveSupportEnabled:{self.historyArchiveSupportEnabled},
pinMessageAllMembersEnabled:{self.pinMessageAllMembersEnabled},
]"""

proc id*(self: SectionItem): string {.inline.} =
Expand Down Expand Up @@ -203,3 +207,6 @@ proc pendingRequestsToJoin*(self: SectionItem): PendingRequestModel {.inline.} =

proc historyArchiveSupportEnabled*(self: SectionItem): bool {.inline.} =
self.historyArchiveSupportEnabled

proc pinMessageAllMembersEnabled*(self: SectionItem): bool {.inline.} =
self.pinMessageAllMembersEnabled
9 changes: 7 additions & 2 deletions src/app/modules/shared_models/section_model.nim
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type
MembersModel
PendingRequestsToJoinModel
HistoryArchiveSupportEnabled
PinMessageAllMembersEnabled

QtObject:
type
Expand Down Expand Up @@ -87,6 +88,7 @@ QtObject:
ModelRole.MembersModel.int:"members",
ModelRole.PendingRequestsToJoinModel.int:"pendingRequestsToJoin",
ModelRole.HistoryArchiveSupportEnabled.int:"historyArchiveSupportEnabled",
ModelRole.PinMessageAllMembersEnabled.int:"pinMessageAllMembersEnabled",
}.toTable

method data(self: SectionModel, index: QModelIndex, role: int): QVariant =
Expand Down Expand Up @@ -144,6 +146,8 @@ QtObject:
result = newQVariant(item.pendingRequestsToJoin)
of ModelRole.HistoryArchiveSupportEnabled:
result = newQVariant(item.historyArchiveSupportEnabled)
of ModelRole.PinMessageAllMembersEnabled:
result = newQVariant(item.pinMessageAllMembersEnabled)

proc isItemExist(self: SectionModel, id: string): bool =
for it in self.items:
Expand Down Expand Up @@ -216,7 +220,8 @@ QtObject:
ModelRole.Joined.int,
ModelRole.MembersModel.int,
ModelRole.PendingRequestsToJoinModel.int,
ModelRole.HistoryArchiveSupportEnabled.int
ModelRole.HistoryArchiveSupportEnabled.int,
ModelRole.PinMessageAllMembersEnabled.int
])

proc getItemById*(self: SectionModel, id: string): SectionItem =
Expand Down Expand Up @@ -313,4 +318,4 @@ QtObject:
"ensOnly": item.ensOnly,
"nbMembers": item.members.getCount()
}
return $jsonObj
return $jsonObj
1 change: 1 addition & 0 deletions src/app_service/service/chat/dto/chat.nim
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ type ChannelGroupDto* = object
color*: string
muted*: bool
historyArchiveSupportEnabled*: bool
pinMessageAllMembersEnabled*: bool

proc `$`*(self: ChatDto): string =
result = fmt"""ChatDto(
Expand Down
12 changes: 12 additions & 0 deletions src/app_service/service/community/dto/community.nim
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ type CommunitySettingsDto* = object
id*: string
historyArchiveSupportEnabled*: bool

type CommunityAdminSettingsDto* = object
pinMessageAllMembersEnabled*: bool

type CommunityDto* = object
id*: string
admin*: bool
Expand All @@ -61,6 +64,11 @@ type CommunityDto* = object
muted*: bool
pendingRequestsToJoin*: seq[CommunityMembershipRequestDto]
settings*: CommunitySettingsDto
adminSettings*: CommunityAdminSettingsDto

proc toCommunityAdminSettingsDto*(jsonObj: JsonNode): CommunityAdminSettingsDto =
result = CommunityAdminSettingsDto()
discard jsonObj.getProp("pinMessageAllMembersEnabled", result.pinMessageAllMembersEnabled)

proc toCommunityDto*(jsonObj: JsonNode): CommunityDto =
result = CommunityDto()
Expand Down Expand Up @@ -90,6 +98,10 @@ proc toCommunityDto*(jsonObj: JsonNode): CommunityDto =
if(jsonObj.getProp("permissions", permissionObj)):
result.permissions = toPermission(permissionObj)

var adminSettingsObj: JsonNode
if(jsonObj.getProp("adminSettings", adminSettingsObj)):
result.adminSettings = toCommunityAdminSettingsDto(adminSettingsObj)

var membersObj: JsonNode
if(jsonObj.getProp("members", membersObj) and membersObj.kind == JObject):
for memberId, memberObj in membersObj:
Expand Down
12 changes: 8 additions & 4 deletions src/app_service/service/community/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,8 @@ QtObject:
color: string,
imageUrl: string,
aX: int, aY: int, bX: int, bY: int,
historyArchiveSupportEnabled: bool) =
historyArchiveSupportEnabled: bool,
pinMessageAllMembersEnabled: bool) =
try:
var image = singletonInstance.utils.formatImagePath(imageUrl)
let response = status_go.createCommunity(
Expand All @@ -542,7 +543,8 @@ QtObject:
color,
image,
aX, aY, bX, bY,
historyArchiveSupportEnabled)
historyArchiveSupportEnabled,
pinMessageAllMembersEnabled)

if response.error != nil:
let error = Json.decode($response.error, RpcError)
Expand Down Expand Up @@ -570,7 +572,8 @@ QtObject:
color: string,
imageUrl: string,
aX: int, aY: int, bX: int, bY: int,
historyArchiveSupportEnabled: bool) =
historyArchiveSupportEnabled: bool,
pinMessageAllMembersEnabled: bool) =
try:
var image = singletonInstance.utils.formatImagePath(imageUrl)
let response = status_go.editCommunity(
Expand All @@ -581,7 +584,8 @@ QtObject:
color,
image,
aX, aY, bX, bY,
historyArchiveSupportEnabled)
historyArchiveSupportEnabled,
pinMessageAllMembersEnabled)

if response.error != nil:
let error = Json.decode($response.error, RpcError)
Expand Down
10 changes: 7 additions & 3 deletions src/backend/communities.nim
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ proc createCommunity*(
color: string,
imageUrl: string,
aX: int, aY: int, bX: int, bY: int,
historyArchiveSupportEnabled: bool
historyArchiveSupportEnabled: bool,
pinMessageAllMembersEnabled: bool
): RpcResponse[JsonNode] {.raises: [Exception].} =
result = callPrivateRPC("createCommunity".prefix, %*[{
# TODO this will need to be renamed membership (small m)
Expand All @@ -51,6 +52,7 @@ proc createCommunity*(
"imageBx": bX,
"imageBy": bY,
"historyArchiveSupportEnabled": historyArchiveSupportEnabled,
"pinMessageAllMembersEnabled": pinMessageAllMembersEnabled
}])

proc editCommunity*(
Expand All @@ -64,7 +66,8 @@ proc editCommunity*(
aY: int,
bX: int,
bY: int,
historyArchiveSupportEnabled: bool
historyArchiveSupportEnabled: bool,
pinMessageAllMembersEnabled: bool
): RpcResponse[JsonNode] {.raises: [Exception].} =
result = callPrivateRPC("editCommunity".prefix, %*[{
# TODO this will need to be renamed membership (small m)
Expand All @@ -79,7 +82,8 @@ proc editCommunity*(
"imageAy": aY,
"imageBx": bX,
"imageBy": bY,
"historyArchiveSupportEnabled": historyArchiveSupportEnabled
"historyArchiveSupportEnabled": historyArchiveSupportEnabled,
"pinMessageAllMembersEnabled": pinMessageAllMembersEnabled
}])

proc createCommunityChannel*(
Expand Down
Loading

0 comments on commit 8c496e0

Please sign in to comment.