2015-11-26 21:05:59 -07:00
|
|
|
package lila.insight
|
|
|
|
|
|
|
|
import lila.pref.Pref
|
2015-12-08 10:20:15 -07:00
|
|
|
import lila.security.Granter
|
2015-11-26 21:05:59 -07:00
|
|
|
import lila.user.User
|
|
|
|
|
|
|
|
final class Share(
|
2019-12-03 12:15:15 -07:00
|
|
|
prefApi: lila.pref.PrefApi,
|
|
|
|
relationApi: lila.relation.RelationApi
|
2019-12-13 20:08:21 -07:00
|
|
|
)(implicit ec: scala.concurrent.ExecutionContext) {
|
2015-11-26 21:05:59 -07:00
|
|
|
|
2021-11-06 02:25:26 -06:00
|
|
|
def getPrefId(insighted: User) = prefApi.getPref(insighted.id, _.insightShare)
|
2015-11-28 09:04:10 -07:00
|
|
|
|
2015-12-08 10:20:15 -07:00
|
|
|
def grant(insighted: User, to: Option[User]): Fu[Boolean] =
|
2018-03-16 17:20:53 -06:00
|
|
|
if (to ?? Granter(_.SeeInsight)) fuTrue
|
2019-12-13 07:30:20 -07:00
|
|
|
else
|
2021-11-06 02:25:26 -06:00
|
|
|
getPrefId(insighted) flatMap {
|
|
|
|
case _ if to.contains(insighted) => fuTrue
|
|
|
|
case Pref.InsightShare.EVERYBODY => fuTrue
|
|
|
|
case Pref.InsightShare.FRIENDS =>
|
|
|
|
to ?? { t =>
|
|
|
|
relationApi.fetchAreFriends(insighted.id, t.id)
|
|
|
|
}
|
|
|
|
case Pref.InsightShare.NOBODY => fuFalse
|
2015-12-08 10:20:15 -07:00
|
|
|
}
|
2015-11-26 21:05:59 -07:00
|
|
|
}
|