Skip to content

Commit

Permalink
Do not alert for unwatched stocks
Browse files Browse the repository at this point in the history
  • Loading branch information
premnirmal committed Oct 26, 2022
1 parent 1599f54 commit 4d5a44f
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class StocksProvider @Inject constructor(
synchronized(quoteMap) {
quotes.forEach { quoteMap[it.symbol] = it }
}
_portfolio.emit(quoteMap.values.toList())
_portfolio.emit(quoteMap.values.filter { tickerSet.contains(it.symbol) }.toList())
} catch (e: Exception) {
Timber.w(e)
}
Expand Down Expand Up @@ -195,7 +195,7 @@ class StocksProvider @Inject constructor(
exponentialBackoff.reset()
scheduleUpdate()
}
FetchResult.success(quoteMap.values.toList())
FetchResult.success(quoteMap.values.filter { tickerSet.contains(it.symbol) }.toList())
}
} catch(ex: CancellationException) {
if (allowScheduling) {
Expand Down Expand Up @@ -236,14 +236,14 @@ class StocksProvider @Inject constructor(
}
}
_tickers.tryEmit(tickerSet.toList())
_portfolio.tryEmit(quoteMap.values.toList())
_portfolio.tryEmit(quoteMap.values.filter { tickerSet.contains(it.symbol) }.toList())
coroutineScope.launch {
val result = fetchStockInternal(ticker, false)
if (result.wasSuccessful) {
val data = result.data
quoteMap[ticker] = data
storage.saveQuote(result.data)
_portfolio.emit(quoteMap.values.toList())
_portfolio.emit(quoteMap.values.filter { tickerSet.contains(it.symbol) }.toList())
}
}
return tickerSet
Expand Down Expand Up @@ -276,7 +276,7 @@ class StocksProvider @Inject constructor(
quote?.position = position
val id = storage.addHolding(holding)
holding.id = id
_portfolio.emit(quoteMap.values.toList())
_portfolio.emit(quoteMap.values.filter { tickerSet.contains(it.symbol) }.toList())
return holding
}

Expand All @@ -291,7 +291,7 @@ class StocksProvider @Inject constructor(
quote?.position = position
}
storage.removeHolding(ticker, holding)
_portfolio.emit(quoteMap.values.toList())
_portfolio.emit(quoteMap.values.filter { tickerSet.contains(it.symbol) }.toList())
}

fun addStocks(symbols: Collection<String>): Collection<String> {
Expand All @@ -306,7 +306,7 @@ class StocksProvider @Inject constructor(
}
}
_tickers.tryEmit(tickerSet.toList())
_portfolio.tryEmit(quoteMap.values.toList())
_portfolio.tryEmit(quoteMap.values.filter { tickerSet.contains(it.symbol) }.toList())
return this.tickerSet
}

Expand All @@ -318,7 +318,7 @@ class StocksProvider @Inject constructor(
}
storage.removeQuoteBySymbol(ticker)
_tickers.emit(tickerSet.toList())
_portfolio.emit(quoteMap.values.toList())
_portfolio.emit(quoteMap.values.filter { tickerSet.contains(it.symbol) }.toList())
return tickerSet
}

Expand All @@ -331,7 +331,7 @@ class StocksProvider @Inject constructor(
}
storage.removeQuotesBySymbol(symbols.toList())
_tickers.emit(tickerSet.toList())
_portfolio.emit(quoteMap.values.toList())
_portfolio.emit(quoteMap.values.filter { tickerSet.contains(it.symbol) }.toList())
saveTickers()
}

Expand Down

0 comments on commit 4d5a44f

Please sign in to comment.