study unsync flag - fixes #2865

This commit is contained in:
Thibault Duplessis 2017-03-29 12:25:09 +02:00
parent 923321501b
commit 67eae924ee
4 changed files with 20 additions and 13 deletions

View file

@ -16,7 +16,8 @@ case class AnaDrop(
variant: Variant,
fen: String,
path: String,
chapterId: Option[String]
chapterId: Option[String],
unsync: Boolean
) {
def branch: Valid[Branch] =
@ -63,6 +64,7 @@ object AnaDrop {
variant = variant,
fen = fen,
path = path,
chapterId = chapterId
chapterId = d str "ch",
unsync = ~(d boolean "unsync")
)
}

View file

@ -16,7 +16,8 @@ case class AnaMove(
fen: String,
path: String,
chapterId: Option[String],
promotion: Option[chess.PromotableRole]
promotion: Option[chess.PromotableRole],
unsync: Boolean
) {
def branch: Valid[Branch] =
@ -56,15 +57,14 @@ object AnaMove {
variant = chess.variant.Variant orDefault ~d.str("variant")
fen d str "fen"
path d str "path"
chapterId = d str "ch"
prom = d str "promotion" flatMap chess.Role.promotable
} yield AnaMove(
orig = orig,
dest = dest,
variant = variant,
fen = fen,
path = path,
chapterId = chapterId,
promotion = prom
chapterId = d str "ch",
promotion = d str "promotion" flatMap chess.Role.promotable,
unsync = ~(d boolean "unsync")
)
}

View file

@ -14,7 +14,7 @@ import lila.hub.actorApi.map._
import lila.socket.actorApi.{ Connected => _, _ }
import lila.socket.Socket.makeMessage
import lila.socket.Socket.Uid
import lila.socket.{ Handler, AnaMove, AnaDests, AnaDrop }
import lila.socket.{ Handler, AnaMove, AnaDrop }
import lila.tree.Node.{ Shape, Shapes, Comment }
import lila.user.User
import makeTimeout.short
@ -61,6 +61,7 @@ private[study] final class SocketHandler(
for {
userId <- member.userId
chapterId <- anaMove.chapterId
if !anaMove.unsync
} api.addNode(
userId,
studyId,
@ -83,6 +84,7 @@ private[study] final class SocketHandler(
for {
userId <- member.userId
chapterId <- anaDrop.chapterId
if !anaDrop.unsync
} api.addNode(
userId,
studyId,

View file

@ -31,9 +31,12 @@ module.exports = function(send, ctrl) {
var currentChapterId = function() {
if (ctrl.study) return ctrl.study.currentChapter().id;
};
var addChapterId = function(req) {
var addStudyData = function(req, addUnsync) {
var c = currentChapterId();
if (c) req.ch = c;
if (c) {
req.ch = c;
if (addUnsync && ctrl.study.members.canContribute() && ctrl.study.vm.behind !== false) req.unsync = true;
}
};
var handlers = {
@ -87,7 +90,7 @@ module.exports = function(send, ctrl) {
this.sendAnaMove = function(req) {
clearTimeout(anaMoveTimeout);
withoutStandardVariant(req);
addChapterId(req);
addStudyData(req, true);
this.send('anaMove', req);
anaMoveTimeout = setTimeout(this.sendAnaMove.bind(this, req), 3000);
}.bind(this);
@ -95,7 +98,7 @@ module.exports = function(send, ctrl) {
this.sendAnaDrop = function(req) {
clearTimeout(anaMoveTimeout);
withoutStandardVariant(req);
addChapterId(req);
addStudyData(req, true);
this.send('anaDrop', req);
anaMoveTimeout = setTimeout(this.sendAnaDrop.bind(this, req), 3000);
}.bind(this);
@ -107,7 +110,7 @@ module.exports = function(send, ctrl) {
}, 300);
else {
withoutStandardVariant(req);
addChapterId(req);
addStudyData(req);
this.send('anaDests', req);
anaDestsTimeout = setTimeout(function() {
console.log(req, 'resendAnaDests');