Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Hide members count from community cards when the community is en… #14538

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/app/modules/main/communities/models/curated_community_item.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type
featured: bool
permissionModel: TokenPermissionsModel
amIBanned: bool
joined: bool
encrypted: bool

proc initCuratedCommunityItem*(
id: string,
Expand All @@ -30,7 +32,9 @@ proc initCuratedCommunityItem*(
activeMembers: int,
featured: bool,
tokenPermissionsItems: seq[TokenPermissionItem],
amIBanned: bool
amIBanned: bool,
joined: bool,
encrypted: bool
): CuratedCommunityItem =
result.id = id
result.name = name
Expand All @@ -47,6 +51,8 @@ proc initCuratedCommunityItem*(
if tokenPermissionsItems.len > 0:
result.permissionModel.setItems(tokenPermissionsItems)
result.amIBanned = amIBanned
result.joined = joined
result.encrypted = encrypted

proc `$`*(self: CuratedCommunityItem): string =
result = fmt"""CuratedCommunityItem(
Expand All @@ -60,6 +66,8 @@ proc `$`*(self: CuratedCommunityItem): string =
activeMembers: {self.activeMembers}
featured: {self.featured}
amIBanned: {self.amIBanned}
joined: {self.joined}
encrypted: {self.encrypted}
]"""

proc getId*(self: CuratedCommunityItem): string =
Expand Down Expand Up @@ -102,4 +110,10 @@ proc setPermissionModelItems*(self: CuratedCommunityItem, items: seq[TokenPermis
self.permissionModel.setItems(items)

proc getAmIBanned*(self: CuratedCommunityItem): bool =
return self.amIBanned
return self.amIBanned

proc getJoined*(self: CuratedCommunityItem): bool =
return self.joined

proc getEncrypted*(self: CuratedCommunityItem): bool =
return self.encrypted
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can omit the return keyword

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's more or less inline with the style used in each file. Here is return self.x, in src/app_service/service/message/dto/status_community_link_preview.nim is something like result = self.x

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type
Tags
Permissions
AmIBanned
Joined
Encrypted

QtObject:
type CuratedCommunityModel* = ref object of QAbstractListModel
Expand Down Expand Up @@ -67,6 +69,8 @@ QtObject:
ModelRole.Tags.int:"tags",
ModelRole.Permissions.int:"permissionsModel",
ModelRole.AmIBanned.int:"amIBanned",
ModelRole.Joined.int:"joined",
ModelRole.Encrypted.int:"encrypted"
}.toTable

method data(self: CuratedCommunityModel, index: QModelIndex, role: int): QVariant =
Expand Down Expand Up @@ -106,6 +110,10 @@ QtObject:
result = newQVariant(item.getFeatured())
of ModelRole.AmIBanned:
result = newQVariant(item.getAmIBanned())
of ModelRole.Joined:
result = newQVariant(item.getJoined())
of ModelRole.Encrypted:
result = newQVariant(item.getEncrypted())

proc findIndexById(self: CuratedCommunityModel, id: string): int =
for i in 0 ..< self.items.len:
Expand Down
4 changes: 3 additions & 1 deletion src/app/modules/main/communities/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,9 @@ proc getCuratedCommunityItem(self: Module, community: CommunityDto): CuratedComm
int(community.activeMembersCount),
community.featuredInDirectory,
tokenPermissionsItems,
amIbanned
amIbanned,
community.joined,
community.encrypted,
)

proc getDiscordCategoryItem(self: Module, c: DiscordCategoryDto): DiscordCategoryItem =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ QtObject:
color: string
icon: LinkPreviewThumbnail
banner: LinkPreviewThumbnail
encrypted: bool
joined: bool

proc setup*(self: StatusCommunityLinkPreview) =
self.QObject.setup()
Expand Down Expand Up @@ -74,6 +76,22 @@ QtObject:
proc getBanner*(self: StatusCommunityLinkPreview): LinkPreviewThumbnail =
result = self.banner

proc getEncrypted*(self: StatusCommunityLinkPreview): bool {.slot.} =
result = self.encrypted
proc encryptedChanged*(self: StatusCommunityLinkPreview) {.signal.}

QtProperty[bool] encrypted:
read = getEncrypted
notify = encryptedChanged

proc getJoined*(self: StatusCommunityLinkPreview): bool {.slot.} =
result = self.joined
proc joinedChanged*(self: StatusCommunityLinkPreview) {.signal.}

QtProperty[bool] joined:
read = getJoined
notify = joinedChanged

proc toStatusCommunityLinkPreview*(jsonObj: JsonNode): StatusCommunityLinkPreview =
new(result, delete)
result.setup()
Expand Down Expand Up @@ -108,7 +126,9 @@ QtObject:
activeMembersCount: {self.activeMembersCount},
color: {self.color},
icon: {self.icon},
banner: {self.banner}
banner: {self.banner},
encrypted: {self.encrypted},
joined: {self.joined}
)"""

proc `%`*(self: StatusCommunityLinkPreview): JsonNode =
Expand All @@ -120,7 +140,9 @@ QtObject:
"activeMembersCount": self.activeMembersCount,
"color": self.color,
"icon": self.icon,
"banner": self.banner
"banner": self.banner,
"encrypted": self.encrypted,
"joined": self.joined
}

proc empty*(self: StatusCommunityLinkPreview): bool =
Expand Down Expand Up @@ -155,4 +177,12 @@ QtObject:
self.icon.update(0, 0, "", community.images.thumbnail)
self.banner.update(0, 0, "", community.images.banner)

if self.encrypted != community.encrypted:
self.encrypted = community.encrypted
self.encryptedChanged()

if self.joined != community.joined:
self.joined = community.joined
self.joinedChanged()

return true
2 changes: 1 addition & 1 deletion ui/StatusQ/src/StatusQ/Components/StatusCommunityCard.qml
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ Rectangle {
// Bottom Row extra info component
Loader {
id: bottomRowLoader
Layout.fillWidth: (!!item && item.width===0)
Layout.fillWidth: true
Layout.preferredHeight: 24
active: ((root.categories.count > 0) || !!root.bottomRowComponent)
sourceComponent: tagsListComponent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ StatusScrollView {
activeUsers: model.activeMembers
popularity: model.popularity
categories: tagsJson.model
memberCountVisible: model.joined || !model.encrypted


// Community restrictions
Expand Down
2 changes: 1 addition & 1 deletion ui/imports/shared/controls/chat/LinkPreviewCard.qml
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ CalloutCard {
PropertyChanges { target: title; text: root.communityData.name }
PropertyChanges { target: description; text: root.communityData.description }
PropertyChanges { target: d; bannerImageSource: root.communityData.banner }
PropertyChanges { target: footerLoader; active: true; visible: true; sourceComponent: communityFooterComponent }
PropertyChanges { target: footerLoader; active: true; visible: !root.communityData.encrypted || root.communityData.joined; sourceComponent: communityFooterComponent }
},
State {
name: "channel"
Expand Down
2 changes: 2 additions & 0 deletions ui/imports/shared/controls/chat/private/CommunityData.qml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ QtObject {
property string color
property int membersCount
property int activeMembersCount // -1 when not available. >= 0 otherwise.
property bool encrypted
property bool joined
readonly property bool activeMembersCountAvailable: activeMembersCount >= 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ LinkPreviewCard {
membersCount: statusCommunityPreview ? statusCommunityPreview.membersCount : 0
activeMembersCount: statusCommunityPreview && isLocalData ? statusCommunityPreview.activeMembersCount : -1
color: statusCommunityPreview ? statusCommunityPreview.color : ""
encrypted: statusCommunityPreview ? statusCommunityPreview.encrypted : false
joined: statusCommunityPreview ? statusCommunityPreview.joined : false
}
channelData {
name: statusCommunityChannelPreview ? statusCommunityChannelPreview.displayName : ""
Expand Down