wait one minute before timelining studies - closes #1944

pull/1955/head
Thibault Duplessis 2016-05-31 16:21:57 +02:00
parent 40658139fd
commit 79e9fd407d
2 changed files with 13 additions and 3 deletions

View File

@ -81,6 +81,7 @@ final class Env(
relationApi = lila.relation.Env.current.api
),
lightUser = getLightUser,
scheduler = system.scheduler,
chat = hub.actor.chat,
timeline = hub.actor.timeline,
socketHub = socketHub)

View File

@ -2,6 +2,7 @@ package lila.study
import akka.actor.{ ActorRef, ActorSelection }
import org.apache.commons.lang3.StringEscapeUtils.escapeHtml4
import scala.concurrent.duration._
import chess.format.pgn.{ Glyphs, Glyph }
import chess.format.{ Forsyth, FEN }
@ -20,6 +21,7 @@ final class StudyApi(
chapterMaker: ChapterMaker,
notifier: StudyNotifier,
lightUser: lila.common.LightUser.Getter,
scheduler: akka.actor.Scheduler,
chat: ActorSelection,
timeline: ActorSelection,
socketHub: ActorRef) {
@ -45,11 +47,18 @@ final class StudyApi(
def create(data: DataForm.Data, user: User): Fu[Study.WithChapter] =
studyMaker(data, user) flatMap { res =>
studyRepo.insert(res.study) >>
chapterRepo.insert(res.chapter) >>- {
if (res.study.isPublic) timeline ! (Propagate(StudyCreate(user.id, res.study.id, res.study.name)) toFollowersOf user.id)
} inject res
chapterRepo.insert(res.chapter) >>-
scheduleTimeline(res.study.id) inject res
}
private def scheduleTimeline(studyId: Study.ID) = scheduler.scheduleOnce(1 minute) {
byId(studyId) foreach {
_.filter(_.isPublic) foreach { study =>
timeline ! (Propagate(StudyCreate(study.ownerId, study.id, study.name)) toFollowersOf study.ownerId)
}
}
}
def talk(userId: User.ID, studyId: Study.ID, text: String, socket: ActorRef) = byId(studyId) foreach {
_ foreach { study =>
(study.members contains userId) ?? {