timeline study likes - close #1950

pull/1955/head
Thibault Duplessis 2016-06-01 02:14:02 +02:00
parent 94b58e22ec
commit 478d8f3d04
5 changed files with 18 additions and 2 deletions

View File

@ -50,7 +50,10 @@ in @perf.name
}
}
case StudyCreate(userId, studyId, studyName) => {
@userIdLink(userId.some, withOnline = false) hosts <a href="@routes.Study.show(studyId)">a new study</a>
@userIdLink(userId.some, withOnline = false) hosts « <a href="@routes.Study.show(studyId)">@studyName</a> »
}
case StudyLike(userId, studyId, studyName) => {
@userIdLink(userId.some, withOnline = false) likes « <a href="@routes.Study.show(studyId)">@studyName</a> »
}
}
@momentFromNow(e.date)

View File

@ -104,6 +104,7 @@ case class GameEnd(playerId: String, opponent: Option[String], win: Option[Boole
case class SimulCreate(userId: String, simulId: String, simulName: String) extends Atom(s"simulCreate", true)
case class SimulJoin(userId: String, simulId: String, simulName: String) extends Atom(s"simulJoin", true)
case class StudyCreate(userId: String, studyId: String, studyName: String) extends Atom(s"studyCreate", true)
case class StudyLike(userId: String, studyId: String, studyName: String) extends Atom(s"studyLike", true)
object propagation {
sealed trait Propagation

View File

@ -7,7 +7,7 @@ import scala.concurrent.duration._
import chess.format.pgn.{ Glyphs, Glyph }
import chess.format.{ Forsyth, FEN }
import lila.hub.actorApi.map.Tell
import lila.hub.actorApi.timeline.{ Propagate, StudyCreate }
import lila.hub.actorApi.timeline.{ Propagate, StudyCreate, StudyLike }
import lila.hub.Sequencer
import lila.socket.Socket.Uid
import lila.socket.tree.Node.{ Shape, Shapes, Comment }
@ -335,6 +335,11 @@ final class StudyApi(
def like(studyId: Study.ID, userId: User.ID, v: Boolean, socket: ActorRef, uid: Uid): Funit =
studyRepo.like(studyId, userId, v) map { likes =>
sendTo(studyId, Socket.SetLiking(Study.Liking(likes, v), uid))
if (v) studyRepo.nameById(studyId) foreach {
_ ?? { name =>
timeline ! (Propagate(StudyLike(userId, studyId, name)) toFollowersOf userId)
}
}
}
private def reloadUid(study: Study, uid: Uid) =

View File

@ -18,6 +18,8 @@ final class StudyRepo(private[study] val coll: Coll) {
def byId(id: Study.ID) = coll.find($id(id), projection).uno[Study]
def nameById(id: Study.ID) = coll.primitiveOne[String]($id(id), "name")
def exists(id: Study.ID) = coll.exists($id(id))
private[study] def selectOwnerId(ownerId: User.ID) = $doc("ownerId" -> ownerId)

View File

@ -34,6 +34,7 @@ case class Entry(
case "simul-create" => simulCreateHandler.read(data)
case "simul-join" => simulJoinHandler.read(data)
case "study-create" => studyCreateHandler.read(data)
case "study-like" => studyLikeHandler.read(data)
case _ => sys error s"Unhandled atom type: $typ"
}) match {
case Success(atom) => Some(atom)
@ -68,6 +69,7 @@ object Entry {
case d: SimulCreate => "simul-create" -> toBson(d)
case d: SimulJoin => "simul-join" -> toBson(d)
case d: StudyCreate => "study-create" -> toBson(d)(studyCreateHandler)
case d: StudyLike => "study-like" -> toBson(d)(studyLikeHandler)
}
} match {
case (typ, bson) =>
@ -88,6 +90,7 @@ object Entry {
implicit val simulCreateHandler = Macros.handler[SimulCreate]
implicit val simulJoinHandler = Macros.handler[SimulJoin]
implicit val studyCreateHandler = Macros.handler[StudyCreate]
implicit val studyLikeHandler = Macros.handler[StudyLike]
}
object atomJsonWrite {
@ -104,6 +107,7 @@ object Entry {
implicit val simulCreateWrite = Json.writes[SimulCreate]
implicit val simulJoinWrite = Json.writes[SimulJoin]
implicit val studyCreateWrite = Json.writes[StudyCreate]
implicit val studyLikeWrite = Json.writes[StudyLike]
implicit val atomWrite = Writes[Atom] {
case d: Follow => followWrite writes d
case d: TeamJoin => teamJoinWrite writes d
@ -118,6 +122,7 @@ object Entry {
case d: SimulCreate => simulCreateWrite writes d
case d: SimulJoin => simulJoinWrite writes d
case d: StudyCreate => studyCreateWrite writes d
case d: StudyLike => studyLikeWrite writes d
}
}