Skip to content

Commit

Permalink
feat(communities): Add ban state for spectated community
Browse files Browse the repository at this point in the history
Fixes: #8761
  • Loading branch information
borismelnik authored and jrainville committed Jan 9, 2023
1 parent 0675d6a commit 9b8a86a
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 23 deletions.
7 changes: 7 additions & 0 deletions src/app/modules/shared_models/active_section.nim
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ QtObject:
read = bannedMembers
notify = bannedMembersChanged

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

QtProperty[bool] amIBanned:
read = amIBanned
notify = bannedMembersChanged

proc pendingMemberRequests(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
4 changes: 4 additions & 0 deletions src/app/modules/shared_models/section_item.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import strformat
import ./member_model, ./member_item
import ../main/communities/models/[pending_request_item, pending_request_model]
import ../../global/global_singleton

import ../../../app_service/common/types

Expand Down Expand Up @@ -280,6 +281,9 @@ proc updateMember*(
proc bannedMembers*(self: SectionItem): member_model.Model {.inline.} =
self.bannedMembersModel

proc amIBanned*(self: SectionItem): bool {.inline.} =
self.bannedMembersModel.isContactWithIdAdded(singletonInstance.userProfile.getPubKey())

proc pendingMemberRequests*(self: SectionItem): member_model.Model {.inline.} =
self.pendingMemberRequestsModel

Expand Down
19 changes: 2 additions & 17 deletions src/app/modules/shared_models/section_model.nim
Original file line number Diff line number Diff line change
Expand Up @@ -239,23 +239,7 @@ QtObject:

self.items[index].muted = muted
let dataIndex = self.createIndex(index, 0, nil)
self.dataChanged(dataIndex, dataIndex, @[
ModelRole.Name.int,
ModelRole.Description.int,
ModelRole.Image.int,
ModelRole.Icon.int,
ModelRole.Color.int,
ModelRole.HasNotification.int,
ModelRole.NotificationsCount.int,
ModelRole.IsMember.int,
ModelRole.CanJoin.int,
ModelRole.Joined.int,
ModelRole.Muted.int,
ModelRole.MembersModel.int,
ModelRole.PendingRequestsToJoinModel.int,
ModelRole.HistoryArchiveSupportEnabled.int,
ModelRole.BannedMembersModel.int
])
self.dataChanged(dataIndex, dataIndex, @[ModelRole.Muted.int])


proc editItem*(self: SectionModel, item: SectionItem) =
Expand Down Expand Up @@ -405,6 +389,7 @@ QtObject:
"canManageUsers": item.canManageUsers,
"canRequestAccess": item.canRequestAccess,
"isMember": item.isMember,
"amIBanned": item.amIBanned,
"access": item.access,
"ensOnly": item.ensOnly,
"nbMembers": item.members.getCount(),
Expand Down
4 changes: 2 additions & 2 deletions ui/app/AppLayouts/Chat/views/ChatContentView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ ColumnLayout {
anchors.fill: parent
anchors.margins: Style.current.smallPadding

enabled: root.activeSectionData.joined
enabled: root.activeSectionData.joined && !root.activeSectionData.amIBanned

store: root.rootStore
usersStore: root.usersStore
Expand All @@ -199,7 +199,7 @@ ColumnLayout {
}

Binding on chatInputPlaceholder {
when: !root.activeSectionData.joined
when: !root.activeSectionData.joined || root.activeSectionData.amIBanned
value: qsTr("You need to join this community to send messages")
}

Expand Down
2 changes: 1 addition & 1 deletion ui/app/AppLayouts/Chat/views/ChatMessagesView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Item {

readonly property real scrollY: chatLogView.visibleArea.yPosition * chatLogView.contentHeight
readonly property bool isMostRecentMessageInViewport: chatLogView.visibleArea.yPosition >= 0.999 - chatLogView.visibleArea.heightRatio
readonly property var chatDetails: chatContentModule.chatDetails
readonly property var chatDetails: chatContentModule.chatDetails || null

function markAllMessagesReadIfMostRecentMessageIsInViewport() {
if (!isMostRecentMessageInViewport) {
Expand Down
5 changes: 4 additions & 1 deletion ui/app/AppLayouts/Chat/views/CommunityColumnView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,14 @@ Item {
anchors.topMargin: 8
anchors.bottomMargin: Style.current.halfPadding
anchors.horizontalCenter: parent.horizontalCenter
enabled: !root.communityData.amIBanned

visible: !communityData.joined
visible: !communityData.joined || root.communityData.amIBanned

text: {
if (root.communityData.amIBanned) return qsTr("You were banned from community")
if (invitationPending) return qsTr("Membership request pending...")

return root.communityData.access === Constants.communityChatOnRequestAccess ?
qsTr("Request to join") : qsTr("Join Community")
}
Expand Down
5 changes: 3 additions & 2 deletions ui/app/mainui/AppMain.qml
Original file line number Diff line number Diff line change
Expand Up @@ -1375,8 +1375,9 @@ Item {
Connections {
target: appMain.rootStore.mainModuleInst
function onActiveSectionChanged() {
if (!!appMain.rootStore.mainModuleInst.getCommunitySectionModule())
rootDropAreaPanel.activeChatType = appMain.rootStore.mainModuleInst.getCommunitySectionModule().activeItem.type
let communitySectionModule = appMain.rootStore.mainModuleInst.getCommunitySectionModule()
if (communitySectionModule)
rootDropAreaPanel.activeChatType = communitySectionModule.activeItem.type
}
}

Expand Down

0 comments on commit 9b8a86a

Please sign in to comment.