Skip to content

Commit 5c127f5

Browse files
committed
Added broadcast subscription list
1 parent 982c08a commit 5c127f5

File tree

7 files changed

+61
-6
lines changed

7 files changed

+61
-6
lines changed

app/controllers/RelayTour.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ final class RelayTour(env: Env, apiC: => Api) extends LilaController(env):
3939
.map:
4040
html.relay.tour.byOwner(_, owner)
4141

42+
def subscribed(page: Int) = Auth { ctx ?=> me ?=>
43+
Reasonable(page, config.Max(20)):
44+
env.relay.pager
45+
.subscribedBy(me.userId, page)
46+
.flatMap: pager =>
47+
Ok.pageAsync:
48+
html.relay.tour.subscribed(pager)
49+
}
50+
4251
private def page(key: String, menu: String) = Open:
4352
pageHit
4453
FoundPage(env.api.cmsRender(lila.cms.CmsPage.Key(key))): p =>

app/views/relay/tour.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,23 @@ object tour:
8484
)
8585
)
8686

87+
def subscribed(pager: Paginator[RelayTour | WithLastRound])(using PageContext) =
88+
views.html.base.layout(
89+
title = liveBroadcasts.txt(),
90+
moreCss = cssTag("relay.index"),
91+
moreJs = infiniteScrollTag
92+
):
93+
main(cls := "relay-index page-menu")(
94+
pageMenu("subscribed"),
95+
div(cls := "page-menu__content box box-pad")(
96+
boxTop:
97+
h1(liveBroadcasts())
98+
,
99+
standardFlash,
100+
renderPager(pager)
101+
)
102+
)
103+
87104
def showEmpty(t: RelayTour, owner: Option[LightUser], markup: Option[Html])(using PageContext) =
88105
views.html.base.layout(
89106
title = t.name,
@@ -134,6 +151,9 @@ object tour:
134151
" ",
135152
trans.broadcast.broadcasts()
136153
),
154+
a(href := routes.RelayTour.subscribed(), cls := menu.activeO("subscribed"))(
155+
trans.broadcast.subscribedBroadcasts()
156+
),
137157
a(href := routes.RelayTour.form, cls := menu.activeO("new"))(trans.broadcast.newBroadcast()),
138158
a(href := routes.RelayTour.calendar, cls := menu.activeO("calendar"))(trans.tournamentCalendar()),
139159
a(href := routes.RelayTour.help, cls := menu.activeO("help"))(trans.broadcast.aboutBroadcasts())

conf/routes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ POST /broadcast/new controllers.RelayTour.create
247247
GET /broadcast/calendar controllers.RelayTour.calendar
248248
GET /broadcast/help controllers.RelayTour.help
249249
GET /broadcast/by/:user controllers.RelayTour.by(user, page: Int ?= 1)
250+
GET /broadcast/subscribed controllers.RelayTour.subscribed(page: Int ?= 1)
250251
GET /broadcast/:ts/$anyId<\w{8}> controllers.RelayTour.show(ts, anyId)
251252
GET /api/broadcast/$tourId<\w{8}>.pgn controllers.RelayTour.pgn(tourId)
252253
GET /broadcast/$tourId<\w{8}>/edit controllers.RelayTour.edit(tourId)

modules/i18n/src/main/I18nKeys.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,6 +1584,7 @@ object I18nKeys:
15841584
val `myBroadcasts` = I18nKey("broadcast:myBroadcasts")
15851585
val `liveBroadcasts` = I18nKey("broadcast:liveBroadcasts")
15861586
val `newBroadcast` = I18nKey("broadcast:newBroadcast")
1587+
val `subscribedBroadcasts` = I18nKey("broadcast:subscribedBroadcasts")
15871588
val `aboutBroadcasts` = I18nKey("broadcast:aboutBroadcasts")
15881589
val `noRoundsYet` = I18nKey("broadcast:noRoundsYet")
15891590
val `howToUseLichessBroadcasts` = I18nKey("broadcast:howToUseLichessBroadcasts")

modules/relay/src/main/RelayPager.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,25 @@ final class RelayPager(tourRepo: RelayTourRepo, roundRepo: RelayRoundRepo, cache
3333
maxPerPage = maxPerPage
3434
)
3535

36+
def subscribedBy(userId: UserId, page: Int): Fu[Paginator[RelayTour | WithLastRound]] = Paginator(
37+
adapter = new:
38+
def nbResults: Fu[Int] = tourRepo.countBySubscriberId(userId)
39+
def slice(offset: Int, length: Int): Fu[List[WithLastRound]] =
40+
tourRepo.coll
41+
.aggregateList(length, _.sec): framework =>
42+
import framework.*
43+
Match(tourRepo.selectors.subscriberId(userId)) -> {
44+
List(Sort(Descending("createdAt"))) ::: aggregateRoundAndUnwind(framework) ::: List(
45+
Skip(offset),
46+
Limit(length)
47+
)
48+
}
49+
.map(readToursWithRound)
50+
,
51+
currentPage = page,
52+
maxPerPage = maxPerPage
53+
)
54+
3655
object inactive:
3756

3857
private def slice(offset: Int, length: Int): Fu[List[WithLastRound]] =

modules/relay/src/main/RelayTourRepo.scala

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ final private class RelayTourRepo(val coll: Coll)(using Executor):
2626
def isSubscribed(tid: RelayTour.Id, uid: UserId): Fu[Boolean] =
2727
coll.exists($doc($id(tid), "subscribers" -> uid))
2828

29+
def countBySubscriberId(uid: UserId): Fu[Int] =
30+
coll.countSel(selectors.subscriberId(uid))
31+
2932
def hasNotified(rt: RelayRound.WithTour): Fu[Boolean] =
3033
coll.exists($doc($id(rt.tour.id), "notified" -> rt.round.id))
3134

@@ -36,9 +39,10 @@ final private class RelayTourRepo(val coll: Coll)(using Executor):
3639
coll.delete.one($id(tour.id)).void
3740

3841
private[relay] object selectors:
39-
val official = $doc("tier" $exists true)
40-
val active = $doc("active" -> true)
41-
val inactive = $doc("active" -> false)
42-
def ownerId(u: UserId) = $doc("ownerId" -> u)
43-
val officialActive = official ++ active
44-
val officialInactive = official ++ inactive
42+
val official = $doc("tier" $exists true)
43+
val active = $doc("active" -> true)
44+
val inactive = $doc("active" -> false)
45+
def ownerId(u: UserId) = $doc("ownerId" -> u)
46+
def subscriberId(u: UserId) = $doc("subscribers" -> u)
47+
val officialActive = official ++ active
48+
val officialInactive = official ++ inactive

translation/source/broadcast.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
</plurals>
99
<string name="liveBroadcasts">Live tournament broadcasts</string>
1010
<string name="newBroadcast">New live broadcast</string>
11+
<string name="subscribedBroadcasts">Subscribed Broadcasts</string>
1112
<string name="aboutBroadcasts">About broadcasts</string>
1213
<string name="noRoundsYet">No rounds yet.</string>
1314
<string name="howToUseLichessBroadcasts">How to use Lichess Broadcasts.</string>

0 commit comments

Comments
 (0)