don't publish timeline entries when liking own study

keyboard-move-autocomplete
Thibault Duplessis 2017-02-08 11:33:37 +01:00
parent 7ac63a5ccd
commit 0c8dc112dc
2 changed files with 4 additions and 5 deletions

View File

@ -409,9 +409,10 @@ 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.value, name)) toFollowersOf userId)
if (v) studyRepo byId studyId foreach {
_ foreach { study =>
if (userId != study.ownerId)
timeline ! (Propagate(StudyLike(userId, study.id.value, study.name.value)) toFollowersOf userId)
}
}
}

View File

@ -27,8 +27,6 @@ final class StudyRepo(private[study] val coll: Coll) {
implicit cp: CursorProducer[Study]) =
coll.find(selector).cursor[Study](readPreference)
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)