Skip to content
This repository has been archived by the owner on May 22, 2023. It is now read-only.

Commit

Permalink
Don't remove old bosses in frontend (#56)
Browse files Browse the repository at this point in the history
The attempt at keeping high level bosses in #48 was backend only, I
forgot to update the frontend code.


Closes #46 (again)
  • Loading branch information
walfie authored Sep 16, 2016
1 parent 2f43425 commit 3f6dd3c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ import walfie.gbf.raidfinder.protocol._
object Application {
@JSExport
def init(url: String): Unit = {
val bossTtl = Duration.hours(6)

val maxReconnectInterval = Duration.seconds(10)

val websocket = new BinaryProtobufWebSocketClient(url, maxReconnectInterval)

val client = new WebSocketRaidFinderClient(
websocket, dom.window.localStorage, bossTtl, SystemClock
websocket, dom.window.localStorage, SystemClock
)

Moment.defineLocale("en-short", MomentShortLocale)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ trait RaidFinderClient {
}

class WebSocketRaidFinderClient(
websocket: WebSocketClient, storage: Storage, raidBossTtl: Duration, clock: Clock
websocket: WebSocketClient, storage: Storage, clock: Clock
) extends RaidFinderClient with WebSocketSubscriber {
import RaidFinderClient._

Expand Down Expand Up @@ -205,42 +205,27 @@ class WebSocketRaidFinderClient(
private def handleRaidBossesResponse(
raidBosses: Seq[RaidBoss]
): Unit = {
var shouldUpdateState = false // Sorry about the var

raidBosses.foreach { raidBoss =>
val bossName = raidBoss.name
val expired = isExpired(raidBoss)

allBossesMap.get(bossName) match {
case None if expired => // Do nothing
case None => // Add to our list of known bosses
val newColumn = RaidBossColumn(
raidBoss = Var(raidBoss),
raidTweets = Vars.empty,
isSubscribed = Var(false)
)
allBossesMap = allBossesMap.updated(bossName, newColumn)
shouldUpdateState = true

case Some(column) if expired => // Remove from allBosses list
allBossesMap = allBossesMap - bossName
shouldUpdateState = true
state.allBosses.get := allBossesMap.values.toArray.sortBy { column =>
val boss = column.raidBoss.get
(boss.level, boss.name)
}

case Some(column) => // Update existing raid boss data
column.raidBoss := raidBoss
}
}

if (shouldUpdateState) {
state.allBosses.get := allBossesMap.values.toArray.sortBy { column =>
val boss = column.raidBoss.get
(boss.level, boss.name)
}
}
}

private def isExpired(raidBoss: RaidBoss): Boolean = {
val minDate = clock.now().getTime - raidBossTtl.milliseconds
raidBoss.lastSeen.getTime < minDate
}

private def refollowBosses(): Unit = {
Expand Down

0 comments on commit 3f6dd3c

Please sign in to comment.