complete new announcements - closes 5577

pull/5645/head
Thibault Duplessis 2019-10-12 15:05:43 +02:00
parent 22d9adc725
commit 0cc7a714e9
2 changed files with 34 additions and 19 deletions

View File

@ -2,8 +2,8 @@ package lila.api
import org.joda.time.DateTime
import org.joda.time.format.ISODateTimeFormat
import scala.concurrent.duration._
import play.api.libs.json.Json
import scala.concurrent.duration._
import scala.util.Try
import lila.hub.actorApi.Announce
@ -12,7 +12,12 @@ object AnnounceStore {
private var current = none[Announce]
def get: Option[Announce] = current
def get: Option[Announce] = {
current foreach { c =>
if (c.date isBefore DateTime.now) current = none
}
current
}
def set(announce: Option[Announce]) = {
current = announce

View File

@ -119,18 +119,28 @@
}
});
lichess.announce = (d) => {
$('#announce').remove();
if (d.msg) $('body').append(
'<div id="announce" class="announce">' +
d.msg +
'<time class="timeago" datetime="' + d.date + '"></time>' +
'<div class="actions"><a class="close">X</a></div>' +
'</div>'
).find('#announce .close').click(function() { $('#announce').remove(); });
};
const announce = $('body').data('announce');
if (announce) lichess.announce(announce);
lichess.announce = (() => {
let timeout;
const kill = () => $('#announce').remove();
const set = (d) => {
if (!d) return;
kill();
if (timeout) clearTimeout(timeout);
if (d.msg) {
$('body').append(
'<div id="announce" class="announce">' +
d.msg +
'<time class="timeago" datetime="' + d.date + '"></time>' +
'<div class="actions"><a class="close">X</a></div>' +
'</div>'
).find('#announce .close').click(kill);
timeout = setTimeout(kill, new Date(d.date) - Date.now());
lichess.pubsub.emit('content_loaded');
}
};
set($('body').data('announce'));
return set;
})();
lichess.reverse = s => s.split('').reverse().join('');
lichess.readServerFen = t => atob(lichess.reverse(t));
@ -271,13 +281,13 @@
document.body.addEventListener('mouseover', lichess.powertip.mouseover);
function renderTimeago() {
lichess.raf(function() {
lichess.timeago.render([].slice.call(document.getElementsByClassName('timeago'), 0, 99));
});
lichess.raf(() =>
lichess.timeago.render([].slice.call(document.getElementsByClassName('timeago'), 0, 99))
);
}
function setTimeago(interval) {
renderTimeago();
setTimeout(function() { setTimeago(interval * 1.1); }, interval);
setTimeout(() => setTimeago(interval * 1.1), interval);
}
setTimeago(1200);
lichess.pubsub.on('content_loaded', renderTimeago);
@ -292,7 +302,7 @@
}
}, 300);
var initiatingHtml = '<div class="initiating">' + lichess.spinnerHtml + '</div>';
const initiatingHtml = '<div class="initiating">' + lichess.spinnerHtml + '</div>';
lichess.challengeApp = (function() {
var instance, booted;