Skip to content

Commit

Permalink
Merge branch 'master' into flipped-chapter-edit-orientation
Browse files Browse the repository at this point in the history
  • Loading branch information
johndoknjas committed Nov 8, 2024
2 parents 7069222 + 29b0acc commit 486b329
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 27 deletions.
17 changes: 9 additions & 8 deletions app/controllers/TeamApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,15 @@ final class TeamApi(env: Env, apiC: => Api) extends LilaController(env):
yield leads

def teamsOf(username: UserStr) = AnonOrScoped(): ctx ?=>
import env.team.jsonView.given
JsonOk:
for
ids <- api.joinedTeamIdsOfUserAsSeenBy(username)
teams <- api.teamsByIds(ids)
teams <- env.team.memberRepo.addPublicLeaderIds(teams)
_ <- env.user.lightUserApi.preloadMany(teams.flatMap(_.publicLeaders))
yield teams
Found(meOrFetch(username)): user =>
import env.team.jsonView.given
JsonOk:
for
ids <- api.joinedTeamIdsOfUserAsSeenBy(user)
teams <- api.teamsByIds(ids)
teams <- env.team.memberRepo.addPublicLeaderIds(teams)
_ <- env.user.lightUserApi.preloadMany(teams.flatMap(_.publicLeaders))
yield teams

def requests(teamId: TeamId) = Scoped(_.Team.Read) { ctx ?=> me ?=>
WithOwnedTeamEnabled(teamId, _.Request): team =>
Expand Down
2 changes: 1 addition & 1 deletion modules/team/src/main/Cached.scala
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ final class Cached(
nbReqs <- requestRepo.countPendingForTeams(leaderTeams)
yield nbReqs

private[team] val forumAccess = cacheApi[TeamId, Access](1_024, "team.forum.access"):
private[team] val forumAccess = cacheApi[TeamId, Access](256, "team.forum.access"):
_.expireAfterWrite(5 minutes).buildAsyncFuture(id => teamRepo.forumAccess(id).dmap(_ | Access.None))

val unsubs = cacheApi[TeamId, Int](512, "team.unsubs"):
Expand Down
14 changes: 7 additions & 7 deletions modules/team/src/main/Team.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ object Team:
v.key -> LightTeam(nameToId(name), name, none)
}.toMap

val maxLeaders = 10
val maxJoinCeiling = 50
val maxLeaders = Max(10)
val maxJoin = Max(50)
val verifiedMaxJoin = Max(150)

def maxJoin(u: User) =
if u.isVerified then maxJoinCeiling * 2
def maxJoin(u: User): Max =
if u.isVerified then verifiedMaxJoin
else
{
15 + daysBetween(u.createdAt, nowInstant) / 7
}.atMost(maxJoinCeiling)
maxJoin.map:
_.atMost(15 + daysBetween(u.createdAt, nowInstant) / 7)

case class IdsStr(value: String) extends AnyVal:

Expand Down
13 changes: 6 additions & 7 deletions modules/team/src/main/TeamApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,16 @@ final class TeamApi(
cached.teamIds(me).dmap(_.size)

def hasJoinedTooManyTeams(using me: Me) =
countTeamsOf(me).dmap(_ > Team.maxJoin(me))
countTeamsOf(me).dmap(Team.maxJoin(me) < _)

def hasTeams(me: User): Fu[Boolean] = cached.teamIds(me.id).map(_.value.nonEmpty)

def joinedTeamIdsOfUserAsSeenBy[U: UserIdOf](member: U)(using viewer: Option[Me]): Fu[List[TeamId]] =
def joinedTeamIdsOfUserAsSeenBy(of: User)(using viewer: Option[Me]): Fu[List[TeamId]] =
cached
.teamIdsList(member.id)
.map(_.take(lila.team.Team.maxJoinCeiling))
.flatMap { allIds =>
if viewer.exists(_.is(member)) || Granter.opt(_.UserModView) then fuccess(allIds)
.teamIdsList(of.id)
.map(_.take(Team.maxJoin(of).value))
.flatMap: allIds =>
if viewer.exists(_.is(of)) || Granter.opt(_.UserModView) then fuccess(allIds)
else
allIds.nonEmpty.so:
teamRepo.filterHideMembers(allIds).flatMap { hiddenIds =>
Expand All @@ -115,7 +115,6 @@ final class TeamApi(
!hiddenIds(id) || viewerTeamIds.contains(id)
}
}
}

def countCreatedRecently(me: User): Fu[Int] =
teamRepo.countCreatedSince(me.id, Period.ofWeeks(1))
Expand Down
4 changes: 2 additions & 2 deletions modules/team/src/main/TeamSecurity.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ final class TeamSecurity(memberRepo: TeamMemberRepo, userApi: lila.core.user.Use
"name" -> lila.common.Form.username.historicalField
.verifying(
s"No more than ${Team.maxLeaders} leaders, please",
_ => t.leaders.sizeIs < Team.maxLeaders
_ => t.leaders.sizeIs < Team.maxLeaders.value
)
.verifying(
"You can't make Lichess a leader",
Expand Down Expand Up @@ -103,7 +103,7 @@ final class TeamSecurity(memberRepo: TeamMemberRepo, userApi: lila.core.user.Use
)
.verifying(
s"No more than ${Team.maxLeaders} leaders, please",
_.sizeIs <= Team.maxLeaders
_.sizeIs <= Team.maxLeaders.value
)
.verifying(
"Duplicated leader name",
Expand Down
2 changes: 1 addition & 1 deletion modules/team/src/main/ui/TeamUi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ final class TeamUi(helpers: Helpers)(using Executor):
div(cls := "page-menu__content box")(
h1(cls := "box__top")(trt.myTeams()),
standardFlash.map(div(cls := "box__pad")(_)),
ctx.me.filter(me => teams.size > Team.maxJoin(me)).map { me =>
ctx.me.filter(me => Team.maxJoin(me) < teams.size).map { me =>
flashMessage("failure"):
s"You have joined ${teams.size} out of ${Team.maxJoin(me)} teams. Leave some teams before you can join others."
},
Expand Down
2 changes: 1 addition & 1 deletion ui/.build/src/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function monitor(pkgs: string[]): Promise<void> {
clearTimeout(tscTimeout);
tscTimeout = setTimeout(() => {
if (packageTimeout) return;
esbuild(tsc());
tsc().then(esbuild);
}, 2000);
};
const packageChange = async () => {
Expand Down

0 comments on commit 486b329

Please sign in to comment.