abstract study join/quit as study "door" with bool flag

This commit is contained in:
Thibault Duplessis 2017-02-14 14:14:45 +01:00
parent 57f3a3b5f3
commit 2aa21da9ee
3 changed files with 18 additions and 23 deletions

View file

@ -231,8 +231,7 @@ case class UnBlock(u1: String, u2: String)
}
package study {
case class StudyJoin(userId: String, studyId: String, contributor: Boolean, public: Boolean)
case class StudyQuit(userId: String, studyId: String, contributor: Boolean, public: Boolean)
case class StudyDoor(userId: String, studyId: String, contributor: Boolean, public: Boolean, enters: Boolean)
case class StudyBecamePrivate(studyId: String, contributors: Set[String])
case class StudyBecamePublic (studyId: String, contributors: Set[String])
case class StudyMemberGotWriteAccess(userId: String, studyId: String, public: Boolean)

View file

@ -71,15 +71,15 @@ private[relation] final class RelationActor(
onlinePlayings putAll usersPlaying
notifyFollowersGameStateChanged(usersPlaying, "following_playing")
case lila.hub.actorApi.study.StudyJoin(userId, studyId, contributor, public) =>
case lila.hub.actorApi.study.StudyDoor(userId, studyId, contributor, public, true) =>
onlineStudyingAll.put(userId, studyId)
if (contributor && public) {
val wasAlreadyInStudy = onlineStudying.get(userId).isDefined
onlineStudying.put(userId, studyId)
if (!wasAlreadyInStudy) notifyFollowersFriendInStudyStateChanged(userId, studyId, "following_joined_study")
}
case lila.hub.actorApi.study.StudyQuit(userId, studyId, contributor, public) =>
case lila.hub.actorApi.study.StudyDoor(userId, studyId, contributor, public, false) =>
onlineStudyingAll remove userId
if (contributor && public) {
onlineStudying remove userId

View file

@ -41,28 +41,24 @@ private final class Socket(
lilaBus.unsubscribe(self)
}
def sendStudyJoin(userId: User.ID) {
lightStudyCache.get(studyId) foreach { studyOption =>
studyOption foreach { study =>
val contributor = study.contributors.contains(userId)
context.system.lilaBus.publish(lila.hub.actorApi.study.StudyJoin(userId, studyId.value, contributor, study.isPublic), 'study)
def sendStudyDoor(enters: Boolean)(userId: User.ID) =
lightStudyCache.get(studyId) foreach {
_ foreach { study =>
lilaBus.publish(
lila.hub.actorApi.study.StudyDoor(
userId = userId,
studyId = studyId.value,
contributor = study contributors userId,
public = study.isPublic,
enters = enters),
'study)
}
}
}
def sendStudyQuit(userId: User.ID) {
lightStudyCache.get(studyId) foreach { studyOption =>
studyOption foreach { study =>
val contributor = study.contributors.contains(userId)
context.system.lilaBus.publish(lila.hub.actorApi.study.StudyQuit(userId, studyId.value, contributor, study.isPublic), 'study)
}
}
}
def receiveSpecific = ({
case SetPath(pos, uid) =>
uidToUserId(uid) foreach sendStudyJoin
uidToUserId(uid) foreach sendStudyDoor(true)
notifyVersion("path", Json.obj(
"p" -> pos,
"w" -> who(uid).map(whoWriter.writes)
@ -166,12 +162,12 @@ private final class Socket(
addMember(uid.value, member)
notifyCrowd
sender ! Socket.Connected(enumerator, member)
userId foreach sendStudyJoin
userId foreach sendStudyDoor(true)
case Quit(uid) =>
members get uid foreach { member =>
quit(uid)
member.userId foreach sendStudyQuit
member.userId foreach sendStudyDoor(false)
notifyCrowd
}