rename chatLocLivePeriods
This commit is contained in:
parent
c7b8fb074d
commit
c2aca3c9fb
2 changed files with 8 additions and 9 deletions
|
@ -25,9 +25,10 @@ private const val TITLES_REPLACED_WITH_IDS = "changed_to_chat_id"
|
||||||
|
|
||||||
class TelegramSettings(private val app: TelegramApplication) {
|
class TelegramSettings(private val app: TelegramApplication) {
|
||||||
|
|
||||||
|
var chatLocLivePeriods = mutableMapOf<Long, Long>()
|
||||||
|
|
||||||
private var shareLocationChats: Set<Long> = emptySet()
|
private var shareLocationChats: Set<Long> = emptySet()
|
||||||
private var showOnMapChats: Set<Long> = emptySet()
|
private var showOnMapChats: Set<Long> = emptySet()
|
||||||
private var chatIdsToDuration = mutableMapOf<Long, Long>()
|
|
||||||
|
|
||||||
var metricsConstants = MetricsConstants.KILOMETERS_AND_METERS
|
var metricsConstants = MetricsConstants.KILOMETERS_AND_METERS
|
||||||
var speedConstants = SpeedConstants.KILOMETERS_PER_HOUR
|
var speedConstants = SpeedConstants.KILOMETERS_PER_HOUR
|
||||||
|
@ -57,7 +58,7 @@ class TelegramSettings(private val app: TelegramApplication) {
|
||||||
showOnMapChats.intersect(presentChatIds)
|
showOnMapChats.intersect(presentChatIds)
|
||||||
this.showOnMapChats = showOnMapChats.toHashSet()
|
this.showOnMapChats = showOnMapChats.toHashSet()
|
||||||
|
|
||||||
chatIdsToDuration = chatIdsToDuration.filter { (key, _) ->
|
chatLocLivePeriods = chatLocLivePeriods.filter { (key, _) ->
|
||||||
presentChatIds.contains(key)
|
presentChatIds.contains(key)
|
||||||
}.toMutableMap()
|
}.toMutableMap()
|
||||||
}
|
}
|
||||||
|
@ -70,20 +71,20 @@ class TelegramSettings(private val app: TelegramApplication) {
|
||||||
duration > TelegramHelper.MAX_LOCATION_MESSAGE_LIVE_PERIOD_SEC -> TelegramHelper.MAX_LOCATION_MESSAGE_LIVE_PERIOD_SEC.toLong()
|
duration > TelegramHelper.MAX_LOCATION_MESSAGE_LIVE_PERIOD_SEC -> TelegramHelper.MAX_LOCATION_MESSAGE_LIVE_PERIOD_SEC.toLong()
|
||||||
else -> duration
|
else -> duration
|
||||||
}
|
}
|
||||||
chatIdsToDuration[chatId] = lp
|
chatLocLivePeriods[chatId] = lp
|
||||||
shareLocationChats.add(chatId)
|
shareLocationChats.add(chatId)
|
||||||
} else {
|
} else {
|
||||||
shareLocationChats.remove(chatId)
|
shareLocationChats.remove(chatId)
|
||||||
chatIdsToDuration.remove(chatId)
|
chatLocLivePeriods.remove(chatId)
|
||||||
}
|
}
|
||||||
this.shareLocationChats = shareLocationChats.toHashSet()
|
this.shareLocationChats = shareLocationChats.toHashSet()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getChatExpireTime(chatId: Long) = chatIdsToDuration[chatId]
|
fun getChatExpireTime(chatId: Long) = chatLocLivePeriods[chatId]
|
||||||
|
|
||||||
fun stopSharingLocationToChats() {
|
fun stopSharingLocationToChats() {
|
||||||
this.shareLocationChats = emptySet()
|
this.shareLocationChats = emptySet()
|
||||||
this.chatIdsToDuration.clear()
|
this.chatLocLivePeriods.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showChatOnMap(chatId: Long, show: Boolean) {
|
fun showChatOnMap(chatId: Long, show: Boolean) {
|
||||||
|
@ -100,8 +101,6 @@ class TelegramSettings(private val app: TelegramApplication) {
|
||||||
|
|
||||||
fun getShowOnMapChats() = ArrayList(showOnMapChats)
|
fun getShowOnMapChats() = ArrayList(showOnMapChats)
|
||||||
|
|
||||||
fun getChatIdsToDuration() = chatIdsToDuration
|
|
||||||
|
|
||||||
fun getShowOnMapChatsCount() = showOnMapChats.size
|
fun getShowOnMapChatsCount() = showOnMapChats.size
|
||||||
|
|
||||||
fun save() {
|
fun save() {
|
||||||
|
|
|
@ -38,7 +38,7 @@ class ShareLocationHelper(private val app: TelegramApplication) {
|
||||||
lastLocation = location
|
lastLocation = location
|
||||||
|
|
||||||
if (location != null && app.isInternetConnectionAvailable) {
|
if (location != null && app.isInternetConnectionAvailable) {
|
||||||
val chatIdsToDuration = app.settings.getChatIdsToDuration()
|
val chatIdsToDuration = app.settings.chatLocLivePeriods
|
||||||
if (chatIdsToDuration.isNotEmpty()) {
|
if (chatIdsToDuration.isNotEmpty()) {
|
||||||
app.telegramHelper.sendLiveLocationMessage(chatIdsToDuration, location.latitude, location.longitude)
|
app.telegramHelper.sendLiveLocationMessage(chatIdsToDuration, location.latitude, location.longitude)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue