diff --git a/src/app/modules/main/communities/models/curated_community_item.nim b/src/app/modules/main/communities/models/curated_community_item.nim index 0d9a20f167..b98986a694 100644 --- a/src/app/modules/main/communities/models/curated_community_item.nim +++ b/src/app/modules/main/communities/models/curated_community_item.nim @@ -12,6 +12,7 @@ type tags: string members: int activeMembers: int + featured: bool proc initCuratedCommunityItem*( id: string, @@ -23,7 +24,8 @@ proc initCuratedCommunityItem*( color: string, tags: string, members: int, - activeMembers: int + activeMembers: int, + featured: bool ): CuratedCommunityItem = result.id = id result.name = name @@ -35,6 +37,7 @@ proc initCuratedCommunityItem*( result.tags = tags result.members = members result.activeMembers = activeMembers + result.featured = featured proc `$`*(self: CuratedCommunityItem): string = result = fmt"""CuratedCommunityItem( @@ -46,6 +49,7 @@ proc `$`*(self: CuratedCommunityItem): string = tags: {self.tags}, members: {self.members} activeMembers: {self.activeMembers} + featured: {self.featured} ]""" proc getId*(self: CuratedCommunityItem): string = @@ -77,3 +81,6 @@ proc getColor*(self: CuratedCommunityItem): string = proc getTags*(self: CuratedCommunityItem): string = return self.tags + +proc getFeatured*(self: CuratedCommunityItem): bool = + return self.featured diff --git a/src/app/modules/main/communities/models/curated_community_model.nim b/src/app/modules/main/communities/models/curated_community_model.nim index bfc2d0960e..2f1bb31b40 100644 --- a/src/app/modules/main/communities/models/curated_community_model.nim +++ b/src/app/modules/main/communities/models/curated_community_model.nim @@ -61,7 +61,7 @@ QtObject: ModelRole.ActiveMembers.int:"activeMembers", ModelRole.Color.int:"color", ModelRole.Popularity.int:"popularity", - ModelRole.Tags.int:"tags" + ModelRole.Tags.int:"tags", }.toTable method data(self: CuratedCommunityModel, index: QModelIndex, role: int): QVariant = @@ -96,11 +96,7 @@ QtObject: of ModelRole.Tags: result = newQVariant(item.getTags()) of ModelRole.Featured: - # TODO: replace this with a real value - var featured = false - if index.row < 3: - featured = true - result = newQVariant(featured) + result = newQVariant(item.getFeatured()) proc findIndexById(self: CuratedCommunityModel, id: string): int = for i in 0 ..< self.items.len: diff --git a/src/app/modules/main/communities/module.nim b/src/app/modules/main/communities/module.nim index ce4dd985cb..3e4b1a0ed5 100644 --- a/src/app/modules/main/communities/module.nim +++ b/src/app/modules/main/communities/module.nim @@ -194,7 +194,8 @@ proc getCuratedCommunityItem(self: Module, c: CommunityDto): CuratedCommunityIte c.color, c.tags, len(c.members), - int(c.activeMembersCount)) + int(c.activeMembersCount), + c.featuredInDirectory) proc getDiscordCategoryItem(self: Module, c: DiscordCategoryDto): DiscordCategoryItem = return initDiscordCategoryItem( diff --git a/src/app_service/service/community/dto/community.nim b/src/app_service/service/community/dto/community.nim index 2cce20e5ac..ed71370fd7 100644 --- a/src/app_service/service/community/dto/community.nim +++ b/src/app_service/service/community/dto/community.nim @@ -1,5 +1,6 @@ {.used.} +import std/jsonutils import json, sequtils, sugar, tables, strutils, json_serialization import ../../../../backend/communities @@ -91,6 +92,7 @@ type CommunityDto* = object isMember*: bool muted*: bool listedInDirectory*: bool + featuredInDirectory*: bool pendingRequestsToJoin*: seq[CommunityMembershipRequestDto] settings*: CommunitySettingsDto adminSettings*: CommunityAdminSettingsDto @@ -355,7 +357,12 @@ proc parseCuratedCommunities*(response: JsonNode): seq[CommunityDto] = result = parseKnownCuratedCommunities(response["communities"]) if (response["unknownCommunities"].kind == JArray): result = concat(result, parseUnknownCuratedCommunities(response["unknownCommunities"])) - + if (response["contractFeaturedCommunities"].kind == JArray): + let featuredCommunityIDs = response["contractFeaturedCommunities"].to(seq[string]) + for i in 0.. id == communityID) + proc contains(arrayToSearch: seq[int], searched: int): bool = for element in arrayToSearch: if element == searched: