Skip to content

Commit

Permalink
Bus: move StreamStart to safer API
Browse files Browse the repository at this point in the history
  • Loading branch information
kraktus committed Jul 9, 2024
1 parent 4400c72 commit 8835513
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
6 changes: 4 additions & 2 deletions modules/activity/src/main/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.softwaremill.tagging.*

import lila.core.config.*
import lila.core.round.CorresMoveEvent
import lila.core.misc.streamer.StreamStart
import lila.common.Bus
import lila.core.forum.BusForum

Expand Down Expand Up @@ -61,7 +62,6 @@ final class Env(
"plan",
"relation",
"startStudy",
"streamStart",
"swissFinish"
):
case lila.core.ublog.UblogPost.Create(post) => write.ublogPost(post)
Expand All @@ -75,8 +75,10 @@ final class Env(
scheduler.scheduleOnce(5 minutes) { write.study(id) }
case lila.core.team.TeamCreate(t) => write.team(t.id, t.userId)
case lila.core.team.JoinTeam(id, userId) => write.team(id, userId)
case lila.core.misc.streamer.StreamStart(userId, _) => write.streamStart(userId)
case lila.core.swiss.SwissFinish(swissId, ranking) => write.swiss(swissId, ranking)

Bus.sub[StreamStart]:
case StreamStart(userId, _) => write.streamStart(userId)

Bus.sub[BusForum]:
case BusForum.CreatePost(post) => write.forumPost(post)
3 changes: 3 additions & 0 deletions modules/core/src/main/misc.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import lila.core.id.GameId

package streamer:
case class StreamStart(userId: UserId, streamerName: String)
object StreamStart:
given bus.WithChannel[StreamStart] = bus.WithChannel[StreamStart]("streamStart")

case class StreamersOnline(streamers: Iterable[(UserId, String)])

package map:
Expand Down
16 changes: 7 additions & 9 deletions modules/notify/src/main/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,17 @@ final class Env(
val getAllows = GetNotifyAllows(api.prefs.allows)

// api actor
Bus.subscribeFuns(
"notify" -> {
case lila.core.notify.NotifiedBatch(userIds) => api.markAllRead(userIds)
case lila.core.game.CorresAlarmEvent(userId, pov, opponent) =>
api.notifyOne(userId, CorresAlarm(pov.game.id, opponent))
},
"streamStart" -> { case lila.core.misc.streamer.StreamStart(userId, streamerName) =>
Bus.subscribeFun("notify"):
case lila.core.notify.NotifiedBatch(userIds) => api.markAllRead(userIds)
case lila.core.game.CorresAlarmEvent(userId, pov, opponent) =>
api.notifyOne(userId, CorresAlarm(pov.game.id, opponent))

Bus.sub[lila.core.misc.streamer.StreamStart]:
case lila.core.misc.streamer.StreamStart(userId, streamerName) =>
subsRepo
.subscribersOnlineSince(userId, 7)
.map: subs =>
api.notifyMany(subs, StreamStart(userId, streamerName))
}
)

lazy val cli = wire[NotifyCli]

Expand Down
5 changes: 1 addition & 4 deletions modules/streamer/src/main/Streaming.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,7 @@ final private class Streaming(
.foreach { s =>
import s.streamer.userId
if streamStartOnceEvery(userId) then
Bus.publish(
lila.core.misc.streamer.StreamStart(userId, s.streamer.name.value),
"streamStart"
)
Bus.pub(lila.core.misc.streamer.StreamStart(userId, s.streamer.name.value))
}
liveStreams = newStreams
streamers.foreach { streamer =>
Expand Down

0 comments on commit 8835513

Please sign in to comment.