diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt index d4c45e5a4b..16f4d732fb 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt @@ -20,12 +20,13 @@ import kotlin.collections.HashSet class TelegramHelper private constructor() { companion object { + const val OSMAND_BOT_USERNAME = "osmand_bot" + private val log = PlatformUtil.getLog(TelegramHelper::class.java) private const val CHATS_LIMIT = 100 private const val IGNORED_ERROR_CODE = 406 private const val UPDATE_LIVE_MESSAGES_INTERVAL_SEC = 30L private const val MESSAGE_ACTIVE_TIME_SEC = 24 * 60 * 60 // 24 hours - private const val OSMAND_BOT_USERNAME = "osmand_bot" // min and max values for the Telegram API const val MIN_LOCATION_MESSAGE_LIVE_PERIOD_SEC = 61 diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/LiveNowTabFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/LiveNowTabFragment.kt index b495ed96eb..aa14c0a4f5 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/LiveNowTabFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/LiveNowTabFragment.kt @@ -13,6 +13,7 @@ import android.widget.TextView import android.widget.Toast import net.osmand.telegram.R import net.osmand.telegram.TelegramApplication +import net.osmand.telegram.helpers.TelegramHelper import net.osmand.telegram.helpers.TelegramHelper.* import net.osmand.telegram.helpers.TelegramUiHelper import org.drinkless.td.libcore.telegram.TdApi @@ -103,14 +104,19 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage private fun updateList() { val res = mutableListOf() for ((id, messages) in telegramHelper.getMessagesByChatIds()) { - telegramHelper.getChat(id)?.let { chat -> + telegramHelper.getChat(id)?.also { chat -> res.add(chat) - if (chat.type is TdApi.ChatTypeBasicGroup || chat.type is TdApi.ChatTypeSupergroup) { + val type = chat.type + if (type is TdApi.ChatTypeBasicGroup || type is TdApi.ChatTypeSupergroup) { messages.forEach { message -> - telegramHelper.getUser(message.senderUserId)?.let { user -> - res.add(user) + if (message.content is MessageOsmAndBotLocation) { + res.add(message.content) + } else { + telegramHelper.getUser(message.senderUserId)?.also { res.add(it) } } } + } else if (type is TdApi.ChatTypePrivate && telegramHelper.getUser(type.userId)?.username == TelegramHelper.OSMAND_BOT_USERNAME) { + res.addAll(messages.filter { it.content is MessageOsmAndBotLocation }) } } } @@ -195,6 +201,11 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage holder.title?.text = "${item.firstName} ${item.lastName}" holder.description?.text = "User description" // FIXME holder.bottomShadow?.visibility = if (lastItem) View.VISIBLE else View.GONE + } else if (item is MessageOsmAndBotLocation && holder is ContactViewHolder) { + holder.icon?.setImageDrawable(app.uiUtils.getThemedIcon(R.drawable.ic_group)) + holder.title?.text = item.name + holder.description?.text = "Location from osmand_bot" // FIXME + holder.bottomShadow?.visibility = if (lastItem) View.VISIBLE else View.GONE } }