Notify of team join via notification menu rather than inbox.
This commit is contained in:
parent
b1bd3ad307
commit
fac30eb06f
|
@ -39,6 +39,11 @@ private object BSONHandlers {
|
|||
implicit val AnswerIdHandler = intAnyValHandler[AnswerId](_.value, AnswerId.apply)
|
||||
implicit val QaAnswerHandler = Macros.handler[QaAnswer]
|
||||
|
||||
import TeamJoined._
|
||||
implicit val TeamIdHandler = stringAnyValHandler[TeamId](_.value, TeamId.apply)
|
||||
implicit val TeamNameHandler = stringAnyValHandler[TeamName](_.value, TeamName.apply)
|
||||
implicit val TeamJoinedHandler = Macros.handler[TeamJoined]
|
||||
|
||||
implicit val NotificationContentHandler = new BSON[NotificationContent] {
|
||||
|
||||
private def writeNotificationType(notificationContent: NotificationContent) = {
|
||||
|
@ -47,6 +52,7 @@ private object BSONHandlers {
|
|||
case _: InvitedToStudy => "invitedStudy"
|
||||
case _: PrivateMessage => "privateMessage"
|
||||
case _: QaAnswer => "qaAnswer"
|
||||
case _: TeamJoined => "teamJoined"
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,6 +70,7 @@ private object BSONHandlers {
|
|||
$doc("type" -> writeNotificationType(notificationContent))
|
||||
case q: QaAnswer => QaAnswerHandler.write(q) ++
|
||||
$doc("type" -> writeNotificationType(notificationContent))
|
||||
case t: TeamJoined => TeamJoinedHandler.write(t) ++ $doc("type" -> writeNotificationType(notificationContent))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,6 +97,7 @@ private object BSONHandlers {
|
|||
case "invitedStudy" => readInvitedStudyNotification(reader)
|
||||
case "privateMessage" => PrivateMessageHandler read reader.doc
|
||||
case "qaAnswer" => QaAnswerHandler read reader.doc
|
||||
case "teamJoined" => TeamJoinedHandler read reader.doc
|
||||
}
|
||||
|
||||
def writes(writer: Writer, n: NotificationContent): dsl.Bdoc = {
|
||||
|
|
|
@ -30,6 +30,10 @@ final class JSONHandlers(
|
|||
"questionSlug" -> questionSlug.value,
|
||||
"answerId" -> answerId.value
|
||||
)
|
||||
case TeamJoined(teamId, teamName) => Json.obj(
|
||||
"teamId" -> teamId.value,
|
||||
"teamName" -> teamName.value
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,6 +45,7 @@ final class JSONHandlers(
|
|||
case _: InvitedToStudy => "invitedStudy"
|
||||
case _: PrivateMessage => "privateMessage"
|
||||
case _: QaAnswer => "qaAnswer"
|
||||
case _: TeamJoined => "teamJoined"
|
||||
}
|
||||
|
||||
Json.obj("content" -> writeBody(body),
|
||||
|
|
|
@ -82,3 +82,11 @@ object QaAnswer {
|
|||
case class QuestionSlug(value: String) extends AnyVal with StringValue
|
||||
case class AnswerId(value: Int) extends AnyVal
|
||||
}
|
||||
|
||||
case class TeamJoined(teamId: TeamJoined.TeamId, teamName: TeamJoined.TeamName) extends NotificationContent
|
||||
|
||||
object TeamJoined {
|
||||
case class TeamId(value: String) extends AnyVal with StringValue
|
||||
case class TeamName(value: String) extends AnyVal with StringValue
|
||||
|
||||
}
|
||||
|
|
|
@ -59,6 +59,7 @@ final class NotifyApi(
|
|||
case InvitedToStudy(invitedBy, _, studyId) => repo.hasRecentStudyInvitation(notification.notifies, studyId)
|
||||
case PrivateMessage(_, thread, _) => repo.hasRecentPrivateMessageFrom(notification.notifies, thread)
|
||||
case QaAnswer(_,_,questionId,_,_) => repo.hasRecentQaAnswer(notification.notifies, questionId)
|
||||
case _: TeamJoined => fuccess(false)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,8 +3,9 @@ package lila.team
|
|||
import com.typesafe.config.Config
|
||||
|
||||
import lila.common.PimpedConfig._
|
||||
import lila.notify.NotifyApi
|
||||
|
||||
final class Env(config: Config, hub: lila.hub.Env, db: lila.db.Env) {
|
||||
final class Env(config: Config, hub: lila.hub.Env, notifyApi: NotifyApi, db: lila.db.Env) {
|
||||
|
||||
private val settings = new {
|
||||
val CollectionTeam = config getString "collection.team"
|
||||
|
@ -42,7 +43,7 @@ final class Env(config: Config, hub: lila.hub.Env, db: lila.db.Env) {
|
|||
|
||||
private lazy val notifier = new Notifier(
|
||||
sender = NotifierSender,
|
||||
messenger = hub.actor.messenger,
|
||||
notifyApi = notifyApi,
|
||||
router = hub.actor.router)
|
||||
}
|
||||
|
||||
|
@ -51,5 +52,6 @@ object Env {
|
|||
lazy val current = "team" boot new Env(
|
||||
config = lila.common.PlayApp loadConfig "team",
|
||||
hub = lila.hub.Env.current,
|
||||
notifyApi = lila.notify.Env.current.api,
|
||||
db = lila.db.Env.current)
|
||||
}
|
||||
|
|
|
@ -1,31 +1,19 @@
|
|||
package lila.team
|
||||
|
||||
import akka.actor.ActorSelection
|
||||
import akka.pattern.ask
|
||||
|
||||
import lila.hub.actorApi.message.LichessThread
|
||||
import lila.hub.actorApi.router._
|
||||
import lila.notify.Notification.Notifies
|
||||
import lila.notify.TeamJoined.{TeamId, TeamName}
|
||||
import lila.notify.{Notification, TeamJoined, NotifyApi}
|
||||
|
||||
private[team] final class Notifier(
|
||||
sender: String,
|
||||
messenger: ActorSelection,
|
||||
notifyApi: NotifyApi,
|
||||
router: ActorSelection) {
|
||||
|
||||
import makeTimeout.large
|
||||
def acceptRequest(team: Team, request: Request) = {
|
||||
val notificationContent = TeamJoined(TeamId(team.id), TeamName(team.name))
|
||||
val notification = Notification(Notifies(request.user), notificationContent)
|
||||
|
||||
def acceptRequest(team: Team, request: Request) {
|
||||
teamUrl(team.id) foreach { url =>
|
||||
messenger ! LichessThread(
|
||||
from = sender,
|
||||
to = request.user,
|
||||
subject = """You have joined the team %s""".format(team.name),
|
||||
message = """Congratulation, your request to join the team was accepted!
|
||||
|
||||
Here is the team page: %s""" format url
|
||||
)
|
||||
notifyApi.addNotification(notification)
|
||||
}
|
||||
}
|
||||
|
||||
private def teamUrl(id: String) =
|
||||
router ? Abs(TeamShow(id)) mapTo manifest[String]
|
||||
}
|
||||
|
|
|
@ -277,7 +277,7 @@ object ApplicationBuild extends Build {
|
|||
play.api, RM)
|
||||
)
|
||||
|
||||
lazy val team = project("team", Seq(common, memo, db, user, forum, security, hub)).settings(
|
||||
lazy val team = project("team", Seq(common, memo, db, user, forum, security, hub, notifyModule)).settings(
|
||||
libraryDependencies ++= provided(
|
||||
play.api, RM)
|
||||
)
|
||||
|
|
|
@ -90,6 +90,16 @@ var handlers = {
|
|||
m('span', " answered your question « " + content.title + " ».")
|
||||
]);
|
||||
}
|
||||
},
|
||||
teamJoined: {
|
||||
html: function(notification) {
|
||||
var content = notification.content
|
||||
var url = "/team/" + content.teamId;
|
||||
|
||||
return genericNotification(notification, url, '&',
|
||||
m('span', " You have joined « " + content.teamName + " ».")
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue