only propagate staff forum events to staff members

This commit is contained in:
Thibault Duplessis 2013-06-02 20:15:01 +02:00
parent abc2de6c3c
commit 4099f1eec3
5 changed files with 14 additions and 3 deletions

View file

@ -42,7 +42,9 @@ final class PostApi(
(indexer ! InsertPost(post)) >>
(env.recent.invalidate inject post) >>-
((ctx.userId ifFalse post.troll) ?? { userId
timeline ! Propagate(ForumPost(userId, topic.name, post.id)).toFriendsOf(userId)
timeline ! Propagate(ForumPost(userId, topic.name, post.id)).|>(prop
post.isStaff.fold(prop.toStaffFriendsOf(userId), prop.toFriendsOf(userId))
)
}) inject post
}

View file

@ -56,7 +56,9 @@ private[forum] final class TopicApi(
(indexer ! InsertPost(post)) >>
env.recent.invalidate >>-
((ctx.userId ifFalse post.troll) ?? { userId
timeline ! Propagate(ForumPost(userId, topic.name, post.id)).toFriendsOf(userId)
timeline ! Propagate(ForumPost(userId, topic.name, post.id)).|>(prop
post.isStaff.fold(prop.toStaffFriendsOf(userId), prop.toFriendsOf(userId))
)
}) inject topic
}

View file

@ -67,6 +67,7 @@ package timeline {
sealed trait Propagation
case class Users(users: List[String]) extends Propagation
case class Friends(user: String) extends Propagation
case class StaffFriends(user: String) extends Propagation
}
import propagation._
@ -74,6 +75,7 @@ package timeline {
case class Propagate(data: Atom, propagations: List[Propagation] = Nil) {
def toUsers(ids: List[String]) = copy(propagations = Users(ids) :: propagations)
def toFriendsOf(id: String) = copy(propagations = Friends(id) :: propagations)
def toStaffFriendsOf(id: String) = copy(propagations = StaffFriends(id) :: propagations)
}
}

View file

@ -11,6 +11,8 @@ import lila.db.api._
import lila.hub.actorApi.timeline.propagation._
import lila.hub.actorApi.timeline.{ Propagate, Atom, ReloadTimeline }
import lila.hub.ActorLazyRef
import lila.security.Granter
import lila.user.UserRepo
import makeTimeout.short
import tube.entryTube
@ -33,6 +35,9 @@ private[timeline] final class Push(
(propagations map {
case Users(ids) fuccess(ids)
case Friends(id) getFriendIds(id) map (_.toList)
case StaffFriends(id) getFriendIds(id) flatMap UserRepo.byIds map {
_ filter Granter(_.StaffForum) map (_.id)
}
}).sequence map (_.flatten.distinct)
private def makeEntry(users: List[String], data: Atom): Fu[Entry] =

View file

@ -55,7 +55,7 @@ object ApplicationBuild extends Build {
libraryDependencies ++= provided(play.api, scalastic)
)
lazy val timeline = project("timeline", Seq(common, db, game, user, hub, relation)).settings(
lazy val timeline = project("timeline", Seq(common, db, game, user, hub, security, relation)).settings(
libraryDependencies ++= provided(
play.api, play.test, reactivemongo, playReactivemongo)
)