From 01d8e3f33e717beadf9d7b419a609ebe5d79db3b Mon Sep 17 00:00:00 2001 From: Chumva Date: Fri, 13 Jul 2018 14:02:59 +0300 Subject: [PATCH 1/8] change chaiTitle to chatId --- .../net/osmand/telegram/TelegramService.kt | 4 +- .../net/osmand/telegram/TelegramSettings.kt | 65 +++++++++++-------- .../telegram/helpers/ShowLocationHelper.kt | 27 ++++---- .../osmand/telegram/helpers/TelegramHelper.kt | 63 ++++++++---------- .../telegram/helpers/TelegramUiHelper.kt | 9 ++- .../osmand/telegram/ui/LiveNowTabFragment.kt | 18 ++--- .../net/osmand/telegram/ui/MainActivity.kt | 18 ++--- .../telegram/ui/SetTimeDialogFragment.kt | 5 ++ 8 files changed, 112 insertions(+), 97 deletions(-) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/TelegramService.kt b/OsmAnd-telegram/src/net/osmand/telegram/TelegramService.kt index 1ef5c0a2d9..96cc14cb69 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/TelegramService.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/TelegramService.kt @@ -246,9 +246,9 @@ class TelegramService : Service(), LocationListener, TelegramIncomingMessagesLis } } - override fun onReceiveChatLocationMessages(chatTitle: String, vararg messages: TdApi.Message) { + override fun onReceiveChatLocationMessages(chatId: Long, vararg messages: TdApi.Message) { val app = app() - if (app.settings.isShowingChatOnMap(chatTitle)) { + if (app.settings.isShowingChatOnMap(chatId)) { ShowMessagesTask(app).executeOnExecutor(executor, *messages) } } diff --git a/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt b/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt index 14b7297a40..f0b8870252 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt @@ -16,18 +16,20 @@ private const val SEND_MY_LOCATION_INTERVAL_KEY = "send_my_location_interval" private const val SEND_MY_LOCATION_INTERVAL_DEFAULT = 5L * 1000 // 5 seconds private const val USER_LOCATION_EXPIRE_TIME_KEY = "user_location_expire_time" +private const val CHANGED_TO_CHAT_ID_KEY = "changed_to_chat_id" private const val USER_LOCATION_EXPIRE_TIME_DEFAULT = 15L * 60 * 1000 // 15 minutes class TelegramSettings(private val app: TelegramApplication) { - private var shareLocationChats: Set = emptySet() - private var showOnMapChats: Set = emptySet() + private var shareLocationChats: Set = emptySet() + private var showOnMapChats: Set = emptySet() var metricsConstants = MetricsConstants.KILOMETERS_AND_METERS var speedConstants = SpeedConstants.KILOMETERS_PER_HOUR var sendMyLocationInterval = SEND_MY_LOCATION_INTERVAL_DEFAULT var userLocationExpireTime = USER_LOCATION_EXPIRE_TIME_DEFAULT + var afterMovingChatTitleToChatId = false init { read() @@ -35,28 +37,28 @@ class TelegramSettings(private val app: TelegramApplication) { fun hasAnyChatToShareLocation() = shareLocationChats.isNotEmpty() - fun isSharingLocationToChat(chatTitle: String) = shareLocationChats.contains(chatTitle) + fun isSharingLocationToChat(id: Long) = shareLocationChats.contains(id) fun hasAnyChatToShowOnMap() = showOnMapChats.isNotEmpty() - fun isShowingChatOnMap(chatTitle: String) = showOnMapChats.contains(chatTitle) + fun isShowingChatOnMap(id: Long) = showOnMapChats.contains(id) - fun removeNonexistingChats(presentChatTitles: List) { + fun removeNonexistingChats(presentChatIds: List) { val shareLocationChats = shareLocationChats.toMutableList() - shareLocationChats.intersect(presentChatTitles) + shareLocationChats.intersect(presentChatIds) this.shareLocationChats = shareLocationChats.toHashSet() val showOnMapChats = showOnMapChats.toMutableList() - showOnMapChats.intersect(presentChatTitles) + showOnMapChats.intersect(presentChatIds) this.showOnMapChats = showOnMapChats.toHashSet() } - fun shareLocationToChat(chatTitle: String, share: Boolean) { + fun shareLocationToChat(id: Long, share: Boolean) { val shareLocationChats = shareLocationChats.toMutableList() if (share) { - shareLocationChats.add(chatTitle) + shareLocationChats.add(id) } else { - shareLocationChats.remove(chatTitle) + shareLocationChats.remove(id) } this.shareLocationChats = shareLocationChats.toHashSet() } @@ -65,12 +67,12 @@ class TelegramSettings(private val app: TelegramApplication) { this.shareLocationChats = emptySet() } - fun showChatOnMap(chatTitle: String, show: Boolean) { + fun showChatOnMap(id: Long, show: Boolean) { val showOnMapChats = showOnMapChats.toMutableList() if (show) { - showOnMapChats.add(chatTitle) + showOnMapChats.add(id) } else { - showOnMapChats.remove(chatTitle) + showOnMapChats.remove(id) } this.showOnMapChats = showOnMapChats.toHashSet() } @@ -87,20 +89,21 @@ class TelegramSettings(private val app: TelegramApplication) { val shareLocationChatsSet = mutableSetOf() val shareLocationChats = ArrayList(shareLocationChats) - for (chatTitle in shareLocationChats) { - shareLocationChatsSet.add(chatTitle) + for (chatId in shareLocationChats) { + shareLocationChatsSet.add(chatId.toString()) } edit.putStringSet(SHARE_LOCATION_CHATS_KEY, shareLocationChatsSet) val showOnMapChatsSet = mutableSetOf() val showOnMapChats = ArrayList(showOnMapChats) - for (chatTitle in showOnMapChats) { - showOnMapChatsSet.add(chatTitle) + for (chatId in showOnMapChats) { + showOnMapChatsSet.add(chatId.toString()) } edit.putStringSet(SHOW_ON_MAP_CHATS_KEY, showOnMapChatsSet) edit.putString(METRICS_CONSTANTS_KEY, metricsConstants.name) edit.putString(SPEED_CONSTANTS_KEY, speedConstants.name) + edit.putBoolean(CHANGED_TO_CHAT_ID_KEY, afterMovingChatTitleToChatId) edit.putLong(SEND_MY_LOCATION_INTERVAL_KEY, sendMyLocationInterval) @@ -109,18 +112,28 @@ class TelegramSettings(private val app: TelegramApplication) { fun read() { val prefs = app.getSharedPreferences(SETTINGS_NAME, Context.MODE_PRIVATE) + afterMovingChatTitleToChatId = + prefs.getBoolean(CHANGED_TO_CHAT_ID_KEY, false) - val shareLocationChats = mutableSetOf() + val shareLocationChats = mutableSetOf() val shareLocationChatsSet = prefs.getStringSet(SHARE_LOCATION_CHATS_KEY, mutableSetOf()) - for (chatTitle in shareLocationChatsSet) { - shareLocationChats.add(chatTitle) - } - this.shareLocationChats = shareLocationChats - - val showOnMapChats = mutableSetOf() + + val showOnMapChats = mutableSetOf() val showOnMapChatsSet = prefs.getStringSet(SHOW_ON_MAP_CHATS_KEY, mutableSetOf()) - for (chatTitle in showOnMapChatsSet) { - showOnMapChats.add(chatTitle) + + if (!afterMovingChatTitleToChatId) { + showOnMapChatsSet.clear() + shareLocationChatsSet.clear() + afterMovingChatTitleToChatId = true + } + + for (chatId in shareLocationChatsSet) { + shareLocationChats.add(chatId.toLong()) + } + this.shareLocationChats = shareLocationChats + + for (chatId in showOnMapChatsSet) { + showOnMapChats.add(chatId.toLong()) } this.showOnMapChats = showOnMapChats diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt index 4618099e0b..529c789056 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt @@ -53,11 +53,11 @@ class ShowLocationHelper(private val app: TelegramApplication) { execOsmandApi { val messages = telegramHelper.getMessages() for (message in messages) { - val chatTitle = telegramHelper.getChat(message.chatId)?.title + val chatId = message.chatId val date = Math.max(message.date, message.editDate) * 1000L val expired = System.currentTimeMillis() - date > app.settings.userLocationExpireTime - if (chatTitle != null && expired) { - removeMapPoint(chatTitle, message) + if (expired) { + removeMapPoint(chatId, message) } } } @@ -65,6 +65,7 @@ class ShowLocationHelper(private val app: TelegramApplication) { fun addLocationToMap(message: TdApi.Message) { execOsmandApi { + val chatId = message.chatId val chatTitle = telegramHelper.getChat(message.chatId)?.title val content = message.content if (chatTitle != null && content is TdApi.MessageLocation) { @@ -86,33 +87,33 @@ class ShowLocationHelper(private val app: TelegramApplication) { } setupMapLayer() val params = generatePhotoParams(photoPath) - osmandAidlHelper.addMapPoint(MAP_LAYER_ID, "${chatTitle}_${message.senderUserId}", userName, userName, + osmandAidlHelper.addMapPoint(MAP_LAYER_ID, "${chatId}_${message.senderUserId}", userName, userName, chatTitle, Color.RED, ALatLon(content.location.latitude, content.location.longitude), null, params) } else if (chatTitle != null && content is MessageOsmAndBotLocation && content.isValid()) { val name = content.name setupMapLayer() - osmandAidlHelper.addMapPoint(MAP_LAYER_ID, "${chatTitle}_$name", name, name, + osmandAidlHelper.addMapPoint(MAP_LAYER_ID, "${chatId}_$name", name, name, chatTitle, Color.RED, ALatLon(content.lat, content.lon), null, null) } } } - fun showChatMessages(chatTitle: String) { + fun showChatMessages(chatId: Long) { execOsmandApi { - val messages = telegramHelper.getChatMessages(chatTitle) + val messages = telegramHelper.getChatMessages(chatId) for (message in messages) { addLocationToMap(message) } } } - fun hideChatMessages(chatTitle: String) { + fun hideChatMessages(chatId: Long) { execOsmandApi { - val messages = telegramHelper.getChatMessages(chatTitle) + val messages = telegramHelper.getChatMessages(chatId) for (message in messages) { val user = telegramHelper.getUser(message.senderUserId) if (user != null) { - removeMapPoint(chatTitle, message) + removeMapPoint(chatId, message) } } } @@ -145,12 +146,12 @@ class ShowLocationHelper(private val app: TelegramApplication) { return mapOf(AMapPoint.POINT_IMAGE_URI_PARAM to photoUri.toString()) } - private fun removeMapPoint(chatTitle: String, message: TdApi.Message) { + private fun removeMapPoint(chatId: Long, message: TdApi.Message) { val content = message.content if (content is TdApi.MessageLocation) { - osmandAidlHelper.removeMapPoint(MAP_LAYER_ID, "${chatTitle}_${message.senderUserId}") + osmandAidlHelper.removeMapPoint(MAP_LAYER_ID, "${chatId}_${message.senderUserId}") } else if (content is MessageOsmAndBotLocation) { - osmandAidlHelper.removeMapPoint(MAP_LAYER_ID, "${chatTitle}_${content.name}") + osmandAidlHelper.removeMapPoint(MAP_LAYER_ID, "${chatId}_${content.name}") } } diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt index ad4151ed83..0c2ce748c1 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt @@ -49,7 +49,7 @@ class TelegramHelper private constructor() { private val secretChats = ConcurrentHashMap() private val chats = ConcurrentHashMap() - private val chatTitles = ConcurrentHashMap() + private val chatIds = TreeSet() private val chatList = TreeSet() private val chatLiveMessages = ConcurrentHashMap() @@ -98,7 +98,7 @@ class TelegramHelper private constructor() { } } - fun getChatTitles() = chatTitles.keys().toList() + fun getChatTitles() = chatIds.toList() fun getChat(id: Long) = chats[id] @@ -107,8 +107,8 @@ class TelegramHelper private constructor() { fun getUserMessage(user: TdApi.User) = usersLocationMessages.values.firstOrNull { it.senderUserId == user.id } - fun getChatMessages(chatTitle: String) = - usersLocationMessages.values.filter { chats[it.chatId]?.title == chatTitle } + fun getChatMessages(chatId: Long) = + usersLocationMessages.values.filter { chats[it.chatId]?.id == chatId } fun getMessages() = usersLocationMessages.values.toList() @@ -131,9 +131,9 @@ class TelegramHelper private constructor() { fun getSupergroupFullInfo(id: Int) = supergroupsFullInfo[id] private fun updateChatTitles() { - chatTitles.clear() + chatIds.clear() for (chatEntry in chats.entries) { - chatTitles[chatEntry.value.title] = chatEntry.key + chatIds.add(chatEntry.key) } } @@ -172,7 +172,7 @@ class TelegramHelper private constructor() { } interface TelegramIncomingMessagesListener { - fun onReceiveChatLocationMessages(chatTitle: String, vararg messages: TdApi.Message) + fun onReceiveChatLocationMessages(chatId: Long, vararg messages: TdApi.Message) fun updateLocationMessages() } @@ -372,11 +372,9 @@ class TelegramHelper private constructor() { } removeOldMessages(message.senderUserId, message.chatId) usersLocationMessages[message.id] = message - val chatTitle = chats[message.chatId]?.title - if (chatTitle != null) { + val chatId = message.chatId incomingMessagesListeners.forEach { - it.onReceiveChatLocationMessages(chatTitle, message) - } + it.onReceiveChatLocationMessages(chatId, message) } } } @@ -397,15 +395,15 @@ class TelegramHelper private constructor() { * @latitude Latitude of the location * @longitude Longitude of the location */ - fun sendLiveLocationMessage(chatTitles: List, livePeriod: Int, latitude: Double, longitude: Double): Boolean { + fun sendLiveLocationMessage(chatIds: List, livePeriod: Int, latitude: Double, longitude: Double): Boolean { if (!requestingActiveLiveLocationMessages && haveAuthorization) { if (needRefreshActiveLiveLocationMessages) { getActiveLiveLocationMessages { - sendLiveLocationImpl(chatTitles, livePeriod, latitude, longitude) + sendLiveLocationImpl(chatIds, livePeriod, latitude, longitude) } needRefreshActiveLiveLocationMessages = false } else { - sendLiveLocationImpl(chatTitles, livePeriod, latitude, longitude) + sendLiveLocationImpl(chatIds, livePeriod, latitude, longitude) } return true } @@ -440,7 +438,7 @@ class TelegramHelper private constructor() { } } - private fun sendLiveLocationImpl(chatTitles: List, livePeriod: Int, latitude: Double, longitude: Double) { + private fun sendLiveLocationImpl(chatIds: List, livePeriod: Int, latitude: Double, longitude: Double) { val lp = when { livePeriod < MIN_LOCATION_MESSAGE_LIVE_PERIOD_SEC -> MIN_LOCATION_MESSAGE_LIVE_PERIOD_SEC livePeriod > MAX_LOCATION_MESSAGE_LIVE_PERIOD_SEC -> MAX_LOCATION_MESSAGE_LIVE_PERIOD_SEC @@ -449,18 +447,15 @@ class TelegramHelper private constructor() { val location = TdApi.Location(latitude, longitude) val content = TdApi.InputMessageLocation(location, lp) - for (chatTitle in chatTitles) { - val chatId = this.chatTitles[chatTitle] - if (chatId != null) { - val msgId = chatLiveMessages[chatId] - if (msgId != null) { - if (msgId != 0L) { - client?.send(TdApi.EditMessageLiveLocation(chatId, msgId, null, location), liveLocationMessageUpdatesHandler) - } - } else { - chatLiveMessages[chatId] = 0L - client?.send(TdApi.SendMessage(chatId, 0, false, true, null, content), liveLocationMessageUpdatesHandler) + for (chatId in chatIds) { + val msgId = chatLiveMessages[chatId] + if (msgId != null) { + if (msgId != 0L) { + client?.send(TdApi.EditMessageLiveLocation(chatId, msgId, null, location), liveLocationMessageUpdatesHandler) } + } else { + chatLiveMessages[chatId] = 0L + client?.send(TdApi.SendMessage(chatId, 0, false, true, null, content), liveLocationMessageUpdatesHandler) } } } @@ -856,11 +851,9 @@ class TelegramHelper private constructor() { synchronized(message) { message.editDate = updateMessageEdited.editDate } - val chatTitle = chats[message.chatId]?.title - if (chatTitle != null) { - incomingMessagesListeners.forEach { - it.onReceiveChatLocationMessages(chatTitle, message) - } + val chatId = message.chatId + incomingMessagesListeners.forEach { + it.onReceiveChatLocationMessages(chatId, message) } } } @@ -880,11 +873,9 @@ class TelegramHelper private constructor() { newContent } } - val chatTitle = chats[message.chatId]?.title - if (chatTitle != null) { - incomingMessagesListeners.forEach { - it.onReceiveChatLocationMessages(chatTitle, message) - } + val chatId = message.chatId + incomingMessagesListeners.forEach { + it.onReceiveChatLocationMessages(chatId, message) } } } diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramUiHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramUiHelper.kt index 3fc146af37..1efc38db54 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramUiHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramUiHelper.kt @@ -41,6 +41,7 @@ object TelegramUiHelper { messages: List ): ChatItem { val res = ChatItem().apply { + chatId = chat.id chatTitle = chat.title photoPath = chat.photo?.small?.local?.path placeholderId = R.drawable.img_user_picture @@ -95,6 +96,7 @@ object TelegramUiHelper { ): LocationItem? { return if (content.isValid()) { LocationItem().apply { + chatId = chat.id chatTitle = chat.title name = content.name latLon = LatLon(content.lat, content.lon) @@ -113,6 +115,7 @@ object TelegramUiHelper { val user = helper.getUser(message.senderUserId) ?: return null val content = message.content as TdApi.MessageLocation return LocationItem().apply { + chatId = chat.id chatTitle = chat.title name = "${user.firstName} ${user.lastName}".trim() if (name.isEmpty()) { @@ -130,6 +133,8 @@ object TelegramUiHelper { abstract class ListItem { + var chatId: Long = 0 + internal set var chatTitle: String = "" internal set var latLon: LatLon? = null @@ -161,7 +166,7 @@ object TelegramUiHelper { override fun canBeOpenedOnMap() = latLon != null && !chatWithBot - override fun getMapPointId() = "${chatTitle}_$userId" + override fun getMapPointId() = "${chatId}_$userId" override fun getVisibleName() = chatTitle } @@ -175,7 +180,7 @@ object TelegramUiHelper { override fun getMapPointId(): String { val id = if (userId != 0) userId.toString() else name - return "${chatTitle}_$id" + return "${chatId}_$id" } override fun getVisibleName() = name diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/LiveNowTabFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/LiveNowTabFragment.kt index 22283871f2..7426342513 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/LiveNowTabFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/LiveNowTabFragment.kt @@ -119,7 +119,7 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage override fun onSendLiveLocationError(code: Int, message: String) {} - override fun onReceiveChatLocationMessages(chatTitle: String, vararg messages: TdApi.Message) { + override fun onReceiveChatLocationMessages(chatId: Long, vararg messages: TdApi.Message) { app.runInUIThread { updateList() } } @@ -273,12 +273,12 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage if (item is ChatItem && holder is ChatViewHolder) { val nextIsLocation = !lastItem && items[position + 1] is LocationItem - val chatTitle = item.chatTitle - val stateTextInd = if (settings.isShowingChatOnMap(chatTitle)) 1 else 0 + val chatId = item.chatId + val stateTextInd = if (settings.isShowingChatOnMap(chatId)) 1 else 0 holder.description?.text = getChatItemDescription(item) holder.imageButton?.visibility = View.GONE - holder.showOnMapRow?.setOnClickListener { showPopupMenu(holder, chatTitle) } + holder.showOnMapRow?.setOnClickListener { showPopupMenu(holder, chatId) } holder.showOnMapState?.text = menuList[stateTextInd] holder.bottomDivider?.visibility = if (nextIsLocation) View.VISIBLE else View.GONE } else if (item is LocationItem && holder is ContactViewHolder) { @@ -300,7 +300,7 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage } } - private fun showPopupMenu(holder: ChatViewHolder, chatTitle: String) { + private fun showPopupMenu(holder: ChatViewHolder, chatId: Long) { val ctx = holder.itemView.context val paint = Paint() @@ -319,7 +319,7 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage setOnItemClickListener { _, _, position, _ -> val allSelected = position == 1 - settings.showChatOnMap(chatTitle, allSelected) + settings.showChatOnMap(chatId, allSelected) if (settings.hasAnyChatToShowOnMap()) { if (osmandAidlHelper.isOsmandNotInstalled()) { if (allSelected) { @@ -327,16 +327,16 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage } } else { if (allSelected) { - app.showLocationHelper.showChatMessages(chatTitle) + app.showLocationHelper.showChatMessages(chatId) } else { - app.showLocationHelper.hideChatMessages(chatTitle) + app.showLocationHelper.hideChatMessages(chatId) } app.showLocationHelper.startShowingLocation() } } else { app.showLocationHelper.stopShowingLocation() if (!allSelected) { - app.showLocationHelper.hideChatMessages(chatTitle) + app.showLocationHelper.hideChatMessages(chatId) } } diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/MainActivity.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/MainActivity.kt index 1b0019ffbc..cb85f69138 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/MainActivity.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/MainActivity.kt @@ -451,8 +451,8 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene override fun onBindViewHolder(holder: ViewHolder, position: Int) { val chat = chats[position] - val chatTitle = chat.title - holder.groupName?.text = chatTitle + val chatId = chat.id + holder.groupName?.text = chat.title var drawable: Drawable? = null var bitmap: Bitmap? = null @@ -469,9 +469,9 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene holder.icon?.setImageDrawable(drawable) } holder.shareLocationSwitch?.setOnCheckedChangeListener(null) - holder.shareLocationSwitch?.isChecked = settings.isSharingLocationToChat(chatTitle) + holder.shareLocationSwitch?.isChecked = settings.isSharingLocationToChat(chatId) holder.shareLocationSwitch?.setOnCheckedChangeListener { view, isChecked -> - settings.shareLocationToChat(chatTitle, isChecked) + settings.shareLocationToChat(chatId, isChecked) if (settings.hasAnyChatToShareLocation()) { if (!AndroidUtils.isLocationPermissionAvailable(view.context)) { if (isChecked) { @@ -486,9 +486,9 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene } holder.showOnMapSwitch?.setOnCheckedChangeListener(null) - holder.showOnMapSwitch?.isChecked = settings.isShowingChatOnMap(chatTitle) + holder.showOnMapSwitch?.isChecked = settings.isShowingChatOnMap(chatId) holder.showOnMapSwitch?.setOnCheckedChangeListener { _, isChecked -> - settings.showChatOnMap(chatTitle, isChecked) + settings.showChatOnMap(chatId, isChecked) if (settings.hasAnyChatToShowOnMap()) { if (osmandAidlHelper.isOsmandNotInstalled()) { if (isChecked) { @@ -496,16 +496,16 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene } } else { if (isChecked) { - app.showLocationHelper.showChatMessages(chatTitle) + app.showLocationHelper.showChatMessages(chatId) } else { - app.showLocationHelper.hideChatMessages(chatTitle) + app.showLocationHelper.hideChatMessages(chatId) } app.showLocationHelper.startShowingLocation() } } else { app.showLocationHelper.stopShowingLocation() if (!isChecked) { - app.showLocationHelper.hideChatMessages(chatTitle) + app.showLocationHelper.hideChatMessages(chatId) } } } diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/SetTimeDialogFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/SetTimeDialogFragment.kt index c534b0c897..c22169b08b 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/SetTimeDialogFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/SetTimeDialogFragment.kt @@ -17,6 +17,7 @@ import net.osmand.telegram.TelegramApplication import net.osmand.telegram.helpers.ShareLocationHelper import net.osmand.telegram.helpers.TelegramUiHelper import net.osmand.telegram.ui.SetTimeDialogFragment.SetTimeListAdapter.ChatViewHolder +import net.osmand.telegram.utils.AndroidUtils import org.drinkless.td.libcore.telegram.TdApi import java.util.concurrent.TimeUnit @@ -77,6 +78,7 @@ class SetTimeDialogFragment : DialogFragment() { text = getString(R.string.shared_string_share) setOnClickListener { Toast.makeText(context, "Share", Toast.LENGTH_SHORT).show() + } } @@ -146,6 +148,9 @@ class SetTimeDialogFragment : DialogFragment() { if (seconds >= ShareLocationHelper.MIN_LOCATION_MESSAGE_LIVE_PERIOD_SEC) { if (id != null) { chatIdsToDuration[id] = seconds + app.settings.shareLocationToChat(id, true) + app.shareLocationHelper.startSharingLocation() + } else { chatIdsToDuration.keys.forEach { chatIdsToDuration[it] = seconds From ea524b45da254bce64afd4db25870d766159bb62 Mon Sep 17 00:00:00 2001 From: Chumva Date: Fri, 13 Jul 2018 14:08:19 +0300 Subject: [PATCH 2/8] remove treeSet --- .../osmand/telegram/helpers/TelegramHelper.kt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt index 0c2ce748c1..1a50b9b69f 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt @@ -49,7 +49,7 @@ class TelegramHelper private constructor() { private val secretChats = ConcurrentHashMap() private val chats = ConcurrentHashMap() - private val chatIds = TreeSet() + private val chatTitles = ConcurrentHashMap() private val chatList = TreeSet() private val chatLiveMessages = ConcurrentHashMap() @@ -98,7 +98,7 @@ class TelegramHelper private constructor() { } } - fun getChatTitles() = chatIds.toList() + fun getChatTitles() = chatTitles.toList() fun getChat(id: Long) = chats[id] @@ -130,10 +130,10 @@ class TelegramHelper private constructor() { fun getSupergroupFullInfo(id: Int) = supergroupsFullInfo[id] - private fun updateChatTitles() { - chatIds.clear() + private fun updateChatIds() { + chatTitles.clear() for (chatEntry in chats.entries) { - chatIds.add(chatEntry.key) + chatTitles[chatEntry.value.title] = chatEntry.key } } @@ -346,7 +346,7 @@ class TelegramHelper private constructor() { return } } - updateChatTitles() + updateChatIds() listener?.onTelegramChatsRead() } @@ -756,7 +756,7 @@ class TelegramHelper private constructor() { chat.order = 0 setChatOrder(chat, order) } - updateChatTitles() + updateChatIds() listener?.onTelegramChatsChanged() } TdApi.UpdateChatTitle.CONSTRUCTOR -> { @@ -766,7 +766,7 @@ class TelegramHelper private constructor() { synchronized(chat) { chat.title = updateChat.title } - updateChatTitles() + updateChatIds() listener?.onTelegramChatChanged(chat) } } From 5c91ad99763cf0c5197ccb8e4d9a704d4c7972a8 Mon Sep 17 00:00:00 2001 From: Chumva Date: Fri, 13 Jul 2018 14:09:24 +0300 Subject: [PATCH 3/8] remove unnecessary search --- .../src/net/osmand/telegram/helpers/TelegramHelper.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt index 1a50b9b69f..dd6e87577c 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt @@ -108,7 +108,7 @@ class TelegramHelper private constructor() { usersLocationMessages.values.firstOrNull { it.senderUserId == user.id } fun getChatMessages(chatId: Long) = - usersLocationMessages.values.filter { chats[it.chatId]?.id == chatId } + usersLocationMessages.values.filter { it.chatId == chatId } fun getMessages() = usersLocationMessages.values.toList() From cc24288a2d5b4d263dcef68f7dcbdb967994015b Mon Sep 17 00:00:00 2001 From: Chumva Date: Fri, 13 Jul 2018 14:11:32 +0300 Subject: [PATCH 4/8] fix tabs --- .../src/net/osmand/telegram/helpers/TelegramHelper.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt index dd6e87577c..748537acb9 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt @@ -105,7 +105,7 @@ class TelegramHelper private constructor() { fun getUser(id: Int) = users[id] fun getUserMessage(user: TdApi.User) = - usersLocationMessages.values.firstOrNull { it.senderUserId == user.id } + usersLocationMessages.values.firstOrNull { it.senderUserId == user.id } fun getChatMessages(chatId: Long) = usersLocationMessages.values.filter { it.chatId == chatId } @@ -133,7 +133,7 @@ class TelegramHelper private constructor() { private fun updateChatIds() { chatTitles.clear() for (chatEntry in chats.entries) { - chatTitles[chatEntry.value.title] = chatEntry.key + chatTitles[chatEntry.value.title] = chatEntry.key } } From 2b0b2b44478d538c6ff5c62d5820115a0b1b9739 Mon Sep 17 00:00:00 2001 From: Chumva Date: Fri, 13 Jul 2018 14:16:01 +0300 Subject: [PATCH 5/8] remove updateChatTitles --- .../net/osmand/telegram/helpers/TelegramHelper.kt | 13 +------------ .../src/net/osmand/telegram/ui/MainActivity.kt | 2 +- .../net/osmand/telegram/ui/SetTimeDialogFragment.kt | 5 ----- 3 files changed, 2 insertions(+), 18 deletions(-) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt index 748537acb9..d317289b6d 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt @@ -49,7 +49,6 @@ class TelegramHelper private constructor() { private val secretChats = ConcurrentHashMap() private val chats = ConcurrentHashMap() - private val chatTitles = ConcurrentHashMap() private val chatList = TreeSet() private val chatLiveMessages = ConcurrentHashMap() @@ -98,7 +97,7 @@ class TelegramHelper private constructor() { } } - fun getChatTitles() = chatTitles.toList() + fun getChatIds() = chats.keys().toList() fun getChat(id: Long) = chats[id] @@ -130,13 +129,6 @@ class TelegramHelper private constructor() { fun getSupergroupFullInfo(id: Int) = supergroupsFullInfo[id] - private fun updateChatIds() { - chatTitles.clear() - for (chatEntry in chats.entries) { - chatTitles[chatEntry.value.title] = chatEntry.key - } - } - private fun isChannel(chat: TdApi.Chat): Boolean { return chat.type is TdApi.ChatTypeSupergroup && (chat.type as TdApi.ChatTypeSupergroup).isChannel } @@ -346,7 +338,6 @@ class TelegramHelper private constructor() { return } } - updateChatIds() listener?.onTelegramChatsRead() } @@ -756,7 +747,6 @@ class TelegramHelper private constructor() { chat.order = 0 setChatOrder(chat, order) } - updateChatIds() listener?.onTelegramChatsChanged() } TdApi.UpdateChatTitle.CONSTRUCTOR -> { @@ -766,7 +756,6 @@ class TelegramHelper private constructor() { synchronized(chat) { chat.title = updateChat.title } - updateChatIds() listener?.onTelegramChatChanged(chat) } } diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/MainActivity.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/MainActivity.kt index cb85f69138..5b822397f3 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/MainActivity.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/MainActivity.kt @@ -258,7 +258,7 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene } private fun removeNonexistingChatsFromSettings() { - val presentChatTitles = telegramHelper.getChatTitles() + val presentChatTitles = telegramHelper.getChatIds() settings.removeNonexistingChats(presentChatTitles) } diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/SetTimeDialogFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/SetTimeDialogFragment.kt index c22169b08b..c534b0c897 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/SetTimeDialogFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/SetTimeDialogFragment.kt @@ -17,7 +17,6 @@ import net.osmand.telegram.TelegramApplication import net.osmand.telegram.helpers.ShareLocationHelper import net.osmand.telegram.helpers.TelegramUiHelper import net.osmand.telegram.ui.SetTimeDialogFragment.SetTimeListAdapter.ChatViewHolder -import net.osmand.telegram.utils.AndroidUtils import org.drinkless.td.libcore.telegram.TdApi import java.util.concurrent.TimeUnit @@ -78,7 +77,6 @@ class SetTimeDialogFragment : DialogFragment() { text = getString(R.string.shared_string_share) setOnClickListener { Toast.makeText(context, "Share", Toast.LENGTH_SHORT).show() - } } @@ -148,9 +146,6 @@ class SetTimeDialogFragment : DialogFragment() { if (seconds >= ShareLocationHelper.MIN_LOCATION_MESSAGE_LIVE_PERIOD_SEC) { if (id != null) { chatIdsToDuration[id] = seconds - app.settings.shareLocationToChat(id, true) - app.shareLocationHelper.startSharingLocation() - } else { chatIdsToDuration.keys.forEach { chatIdsToDuration[it] = seconds From 3c05c0e37e28c8fe1155a7584d9426b866267c2d Mon Sep 17 00:00:00 2001 From: Chumva Date: Fri, 13 Jul 2018 14:27:01 +0300 Subject: [PATCH 6/8] fix tabs in settings --- .../net/osmand/telegram/TelegramSettings.kt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt b/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt index f0b8870252..de5c63d26d 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt @@ -117,7 +117,7 @@ class TelegramSettings(private val app: TelegramApplication) { val shareLocationChats = mutableSetOf() val shareLocationChatsSet = prefs.getStringSet(SHARE_LOCATION_CHATS_KEY, mutableSetOf()) - + val showOnMapChats = mutableSetOf() val showOnMapChatsSet = prefs.getStringSet(SHOW_ON_MAP_CHATS_KEY, mutableSetOf()) @@ -126,22 +126,22 @@ class TelegramSettings(private val app: TelegramApplication) { shareLocationChatsSet.clear() afterMovingChatTitleToChatId = true } - - for (chatId in shareLocationChatsSet) { - shareLocationChats.add(chatId.toLong()) - } - this.shareLocationChats = shareLocationChats - for (chatId in showOnMapChatsSet) { + for (chatId in shareLocationChatsSet) { + shareLocationChats.add(chatId.toLong()) + } + this.shareLocationChats = shareLocationChats + + for (chatId in showOnMapChatsSet) { showOnMapChats.add(chatId.toLong()) } this.showOnMapChats = showOnMapChats metricsConstants = MetricsConstants.valueOf( - prefs.getString(METRICS_CONSTANTS_KEY, MetricsConstants.KILOMETERS_AND_METERS.name) + prefs.getString(METRICS_CONSTANTS_KEY, MetricsConstants.KILOMETERS_AND_METERS.name) ) speedConstants = SpeedConstants.valueOf( - prefs.getString(SPEED_CONSTANTS_KEY, SpeedConstants.KILOMETERS_PER_HOUR.name) + prefs.getString(SPEED_CONSTANTS_KEY, SpeedConstants.KILOMETERS_PER_HOUR.name) ) sendMyLocationInterval = From 2cde7dcb3f871dc4696a25871a707ddf3b95e1e5 Mon Sep 17 00:00:00 2001 From: Alex Sytnyk Date: Fri, 13 Jul 2018 14:32:11 +0300 Subject: [PATCH 7/8] Refactor TelegramSettings --- .../net/osmand/telegram/TelegramSettings.kt | 54 ++++++++++--------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt b/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt index de5c63d26d..af994637bd 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt @@ -16,9 +16,10 @@ private const val SEND_MY_LOCATION_INTERVAL_KEY = "send_my_location_interval" private const val SEND_MY_LOCATION_INTERVAL_DEFAULT = 5L * 1000 // 5 seconds private const val USER_LOCATION_EXPIRE_TIME_KEY = "user_location_expire_time" -private const val CHANGED_TO_CHAT_ID_KEY = "changed_to_chat_id" private const val USER_LOCATION_EXPIRE_TIME_DEFAULT = 15L * 60 * 1000 // 15 minutes +private const val TITLES_REPLACED_WITH_IDS = "changed_to_chat_id" + class TelegramSettings(private val app: TelegramApplication) { private var shareLocationChats: Set = emptySet() @@ -29,19 +30,19 @@ class TelegramSettings(private val app: TelegramApplication) { var sendMyLocationInterval = SEND_MY_LOCATION_INTERVAL_DEFAULT var userLocationExpireTime = USER_LOCATION_EXPIRE_TIME_DEFAULT - var afterMovingChatTitleToChatId = false init { + updatePrefs() read() } fun hasAnyChatToShareLocation() = shareLocationChats.isNotEmpty() - fun isSharingLocationToChat(id: Long) = shareLocationChats.contains(id) + fun isSharingLocationToChat(chatId: Long) = shareLocationChats.contains(chatId) fun hasAnyChatToShowOnMap() = showOnMapChats.isNotEmpty() - fun isShowingChatOnMap(id: Long) = showOnMapChats.contains(id) + fun isShowingChatOnMap(chatId: Long) = showOnMapChats.contains(chatId) fun removeNonexistingChats(presentChatIds: List) { val shareLocationChats = shareLocationChats.toMutableList() @@ -53,12 +54,12 @@ class TelegramSettings(private val app: TelegramApplication) { this.showOnMapChats = showOnMapChats.toHashSet() } - fun shareLocationToChat(id: Long, share: Boolean) { + fun shareLocationToChat(chatId: Long, share: Boolean) { val shareLocationChats = shareLocationChats.toMutableList() if (share) { - shareLocationChats.add(id) + shareLocationChats.add(chatId) } else { - shareLocationChats.remove(id) + shareLocationChats.remove(chatId) } this.shareLocationChats = shareLocationChats.toHashSet() } @@ -67,12 +68,12 @@ class TelegramSettings(private val app: TelegramApplication) { this.shareLocationChats = emptySet() } - fun showChatOnMap(id: Long, show: Boolean) { + fun showChatOnMap(chatId: Long, show: Boolean) { val showOnMapChats = showOnMapChats.toMutableList() if (show) { - showOnMapChats.add(id) + showOnMapChats.add(chatId) } else { - showOnMapChats.remove(id) + showOnMapChats.remove(chatId) } this.showOnMapChats = showOnMapChats.toHashSet() } @@ -103,7 +104,6 @@ class TelegramSettings(private val app: TelegramApplication) { edit.putString(METRICS_CONSTANTS_KEY, metricsConstants.name) edit.putString(SPEED_CONSTANTS_KEY, speedConstants.name) - edit.putBoolean(CHANGED_TO_CHAT_ID_KEY, afterMovingChatTitleToChatId) edit.putLong(SEND_MY_LOCATION_INTERVAL_KEY, sendMyLocationInterval) @@ -112,36 +112,26 @@ class TelegramSettings(private val app: TelegramApplication) { fun read() { val prefs = app.getSharedPreferences(SETTINGS_NAME, Context.MODE_PRIVATE) - afterMovingChatTitleToChatId = - prefs.getBoolean(CHANGED_TO_CHAT_ID_KEY, false) val shareLocationChats = mutableSetOf() val shareLocationChatsSet = prefs.getStringSet(SHARE_LOCATION_CHATS_KEY, mutableSetOf()) - - val showOnMapChats = mutableSetOf() - val showOnMapChatsSet = prefs.getStringSet(SHOW_ON_MAP_CHATS_KEY, mutableSetOf()) - - if (!afterMovingChatTitleToChatId) { - showOnMapChatsSet.clear() - shareLocationChatsSet.clear() - afterMovingChatTitleToChatId = true - } - for (chatId in shareLocationChatsSet) { shareLocationChats.add(chatId.toLong()) } this.shareLocationChats = shareLocationChats + val showOnMapChats = mutableSetOf() + val showOnMapChatsSet = prefs.getStringSet(SHOW_ON_MAP_CHATS_KEY, mutableSetOf()) for (chatId in showOnMapChatsSet) { showOnMapChats.add(chatId.toLong()) } this.showOnMapChats = showOnMapChats metricsConstants = MetricsConstants.valueOf( - prefs.getString(METRICS_CONSTANTS_KEY, MetricsConstants.KILOMETERS_AND_METERS.name) + prefs.getString(METRICS_CONSTANTS_KEY, MetricsConstants.KILOMETERS_AND_METERS.name) ) speedConstants = SpeedConstants.valueOf( - prefs.getString(SPEED_CONSTANTS_KEY, SpeedConstants.KILOMETERS_PER_HOUR.name) + prefs.getString(SPEED_CONSTANTS_KEY, SpeedConstants.KILOMETERS_PER_HOUR.name) ) sendMyLocationInterval = @@ -149,4 +139,18 @@ class TelegramSettings(private val app: TelegramApplication) { userLocationExpireTime = prefs.getLong(USER_LOCATION_EXPIRE_TIME_KEY, USER_LOCATION_EXPIRE_TIME_DEFAULT) } + + private fun updatePrefs() { + val prefs = app.getSharedPreferences(SETTINGS_NAME, Context.MODE_PRIVATE) + val idsInUse = prefs.getBoolean(TITLES_REPLACED_WITH_IDS, false) + if (!idsInUse) { + val edit = prefs.edit() + + edit.putStringSet(SHARE_LOCATION_CHATS_KEY, emptySet()) + edit.putStringSet(SHOW_ON_MAP_CHATS_KEY, emptySet()) + edit.putBoolean(TITLES_REPLACED_WITH_IDS, true) + + edit.apply() + } + } } From 951065e21cfcb181449fd0833720729c6a527ebc Mon Sep 17 00:00:00 2001 From: Alex Sytnyk Date: Fri, 13 Jul 2018 14:42:57 +0300 Subject: [PATCH 8/8] Fix small issues --- .../osmand/telegram/helpers/ShowLocationHelper.kt | 3 +-- .../net/osmand/telegram/helpers/TelegramHelper.kt | 15 ++++++--------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt index 529c789056..2676fc1aed 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt @@ -53,11 +53,10 @@ class ShowLocationHelper(private val app: TelegramApplication) { execOsmandApi { val messages = telegramHelper.getMessages() for (message in messages) { - val chatId = message.chatId val date = Math.max(message.date, message.editDate) * 1000L val expired = System.currentTimeMillis() - date > app.settings.userLocationExpireTime if (expired) { - removeMapPoint(chatId, message) + removeMapPoint(message.chatId, message) } } } diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt index d317289b6d..8e55b4ab56 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt @@ -104,10 +104,10 @@ class TelegramHelper private constructor() { fun getUser(id: Int) = users[id] fun getUserMessage(user: TdApi.User) = - usersLocationMessages.values.firstOrNull { it.senderUserId == user.id } + usersLocationMessages.values.firstOrNull { it.senderUserId == user.id } fun getChatMessages(chatId: Long) = - usersLocationMessages.values.filter { it.chatId == chatId } + usersLocationMessages.values.filter { it.chatId == chatId } fun getMessages() = usersLocationMessages.values.toList() @@ -363,9 +363,8 @@ class TelegramHelper private constructor() { } removeOldMessages(message.senderUserId, message.chatId) usersLocationMessages[message.id] = message - val chatId = message.chatId - incomingMessagesListeners.forEach { - it.onReceiveChatLocationMessages(chatId, message) + incomingMessagesListeners.forEach { + it.onReceiveChatLocationMessages(message.chatId, message) } } } @@ -840,9 +839,8 @@ class TelegramHelper private constructor() { synchronized(message) { message.editDate = updateMessageEdited.editDate } - val chatId = message.chatId incomingMessagesListeners.forEach { - it.onReceiveChatLocationMessages(chatId, message) + it.onReceiveChatLocationMessages(message.chatId, message) } } } @@ -862,9 +860,8 @@ class TelegramHelper private constructor() { newContent } } - val chatId = message.chatId incomingMessagesListeners.forEach { - it.onReceiveChatLocationMessages(chatId, message) + it.onReceiveChatLocationMessages(message.chatId, message) } } }