relay private beta

pull/3674/head
Thibault Duplessis 2017-10-06 19:08:32 -05:00
parent d29dd1135d
commit bc11863140
5 changed files with 29 additions and 34 deletions

View File

@ -18,13 +18,13 @@ object Relay extends LilaController {
}
}
def form = Auth { implicit ctx => me =>
def form = Secure(_.Beta) { implicit ctx => me =>
NoLame {
Ok(html.relay.create(env.forms.create)).fuccess
}
}
def create = AuthBody { implicit ctx => implicit me =>
def create = SecureBody(_.Beta) { implicit ctx => me =>
implicit val req = ctx.body
env.forms.create.bindFromRequest.fold(
err => BadRequest(html.relay.create(err)).fuccess,
@ -34,13 +34,13 @@ object Relay extends LilaController {
)
}
def edit(slug: String, id: String) = Auth { implicit ctx => implicit me =>
def edit(slug: String, id: String) = Auth { implicit ctx => me =>
OptionFuResult(env.api.byIdAndOwner(RelayModel.Id(id), me)) { relay =>
Ok(html.relay.edit(relay, env.forms.edit(relay))).fuccess
}
}
def update(slug: String, id: String) = AuthBody { implicit ctx => implicit me =>
def update(slug: String, id: String) = AuthBody { implicit ctx => me =>
OptionFuResult(env.api.byIdAndOwner(RelayModel.Id(id), me)) { relay =>
implicit val req = ctx.body
env.forms.edit(relay).bindFromRequest.fold(

View File

@ -25,6 +25,9 @@
<div>
<a href="@routes.Tv.index">Lichess TV</a>
<a href="@routes.Tv.games">@trans.currentGames()</a>
@if(isGranted(_.Beta)) {
<a href="@routes.Relay.index">Broadcasts</a>
}
<a href="@routes.Video.index">@trans.videoLibrary()</a>
</div>
</section>

View File

@ -1,18 +1,17 @@
@(sel: lila.relay.Relay.Selection)(implicit ctx: Context)
@sublist(relays: List[lila.relay.Relay.WithStudy]) = {
@if(relays.isEmpty) {
<div class="norelays">
<p>None yet.</p>
</div>
} else {
<div class="list">
@relays.map { r =>
<div class="relay">
@widget(r)
@sublist(name: String, relays: List[lila.relay.Relay.WithStudy]) = {
@if(relays.nonEmpty) {
<section>
<h2>@name</h2>
<div class="list">
@relays.map { r =>
<div class="relay">
@widget(r)
</div>
}
</div>
}
</div>
</section>
}
}
@ -23,17 +22,8 @@ moreCss = cssTag("relay-list.css")) {
<div class="top">
<h1>Live tournament broadcasts</h1>
</div>
<section>
<h2>Ongoing</h2>
@sublist(sel.started)
</section>
<section>
<h2>Upcoming</h2>
@sublist(sel.created)
</section>
<section>
<h2>Completed</h2>
@sublist(sel.closed)
</section>
@sublist("Ongoing", sel.started)
@sublist("Upcoming", sel.created)
@sublist("Completed", sel.closed)
</div>
}

View File

@ -65,11 +65,11 @@ private final class RelayFetch(
case Some(delay) => fuccess(delay)
case None => api.getNbViewers(r) map {
case 0 => 30
case nb => (11 - nb / 2) atLeast 2
case nb => (16 - nb) atLeast 5
}
}) map { seconds =>
sync.copy(nextAt = DateTime.now plusSeconds {
seconds atLeast { if (sync.log.isOk) 2 else 5 }
seconds atLeast { if (sync.log.isOk) 5 else 10 }
} some)
}
} flatMap { api.setSync(r.id, _) }

View File

@ -26,13 +26,15 @@ export default class RelayCtrl {
c.relay = this.convertDate(r);
if (!c.tags.find(t => t[0] === 'Result' && t[1] !== '*')) {
const delay = (Date.now() - r.lastMoveAt!) % 1000;
console.log(delay);
setTimeout(() => setInterval(this.redraw, 1000), delay);
console.log(delay, r.lastMoveAt);
setTimeout(() => {
this.clockInterval = setInterval(this.redraw, 1000);
}, delay);
}
}
}
convertDate = (r: StudyChapterRelay): StudyChapterRelay => {
private convertDate = (r: StudyChapterRelay): StudyChapterRelay => {
if (typeof r.secondsSinceLastMove !== 'undefined' && !r.lastMoveAt) {
r.lastMoveAt = Date.now() - r.secondsSinceLastMove * 1000;
}
@ -49,7 +51,7 @@ export default class RelayCtrl {
this.data.sync.log.push(event);
this.data.sync.log = this.data.sync.log.slice(-20);
this.cooldown = true;
setTimeout(() => { this.cooldown = false; this.redraw(); }, 3000);
setTimeout(() => { this.cooldown = false; this.redraw(); }, 4500);
this.redraw();
if (event.error) console.warn(`relay synchronisation error: ${event.error}`);
}