Merge pull request #10156 from osmandapp/ResendMap
Resend map, after map editing error
This commit is contained in:
commit
126a112fff
6 changed files with 40 additions and 23 deletions
|
@ -18,7 +18,6 @@ import net.osmand.telegram.helpers.TelegramHelper
|
||||||
import net.osmand.telegram.helpers.TelegramHelper.*
|
import net.osmand.telegram.helpers.TelegramHelper.*
|
||||||
import net.osmand.telegram.notifications.TelegramNotification.NotificationType
|
import net.osmand.telegram.notifications.TelegramNotification.NotificationType
|
||||||
import net.osmand.telegram.utils.AndroidUtils
|
import net.osmand.telegram.utils.AndroidUtils
|
||||||
import net.osmand.telegram.utils.OsmandLocationUtils
|
|
||||||
import org.drinkless.td.libcore.telegram.TdApi
|
import org.drinkless.td.libcore.telegram.TdApi
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
@ -377,7 +376,10 @@ class TelegramService : Service(), LocationListener, TelegramIncomingMessagesLis
|
||||||
Log.d(PlatformUtil.TAG, "Send live location error: $code - $message")
|
Log.d(PlatformUtil.TAG, "Send live location error: $code - $message")
|
||||||
when (messageType) {
|
when (messageType) {
|
||||||
TelegramHelper.MESSAGE_TYPE_TEXT -> shareInfo.pendingTdLibText--
|
TelegramHelper.MESSAGE_TYPE_TEXT -> shareInfo.pendingTdLibText--
|
||||||
TelegramHelper.MESSAGE_TYPE_MAP -> shareInfo.pendingTdLibMap--
|
TelegramHelper.MESSAGE_TYPE_MAP -> {
|
||||||
|
shareInfo.pendingTdLibMap--
|
||||||
|
shareInfo.currentMapMessageId = -1L
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -304,27 +304,18 @@ class TelegramSettings(private val app: TelegramApplication) {
|
||||||
|
|
||||||
fun prepareForSharingNewMessages() {
|
fun prepareForSharingNewMessages() {
|
||||||
shareChatsInfo.forEach { (_, shareInfo) ->
|
shareChatsInfo.forEach { (_, shareInfo) ->
|
||||||
prepareForSharingNewMessages(shareInfo)
|
shareInfo.resetMessagesInfo()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun prepareForSharingNewMessages(chatsIds: List<Long>) {
|
fun prepareForSharingNewMessages(chatsIds: List<Long>) {
|
||||||
chatsIds.forEach {
|
chatsIds.forEach {
|
||||||
shareChatsInfo[it]?.also { shareInfo ->
|
shareChatsInfo[it]?.also { shareInfo ->
|
||||||
prepareForSharingNewMessages(shareInfo)
|
shareInfo.resetMessagesInfo()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun prepareForSharingNewMessages(shareInfo: ShareChatInfo) {
|
|
||||||
shareInfo.pendingTdLibText = 0
|
|
||||||
shareInfo.pendingTdLibMap = 0
|
|
||||||
shareInfo.currentTextMessageId = -1L
|
|
||||||
shareInfo.currentMapMessageId = -1L
|
|
||||||
shareInfo.pendingTextMessage = false
|
|
||||||
shareInfo.pendingMapMessage = false
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getChatLivePeriod(chatId: Long) = shareChatsInfo[chatId]?.livePeriod
|
fun getChatLivePeriod(chatId: Long) = shareChatsInfo[chatId]?.livePeriod
|
||||||
|
|
||||||
fun getChatsShareInfo() = shareChatsInfo
|
fun getChatsShareInfo() = shareChatsInfo
|
||||||
|
@ -1497,6 +1488,27 @@ class TelegramSettings(private val app: TelegramApplication) {
|
||||||
|
|
||||||
fun isPendingMapMessagesLimitReached() = pendingTdLibMap >= MAX_MESSAGES_IN_TDLIB_PER_CHAT
|
fun isPendingMapMessagesLimitReached() = pendingTdLibMap >= MAX_MESSAGES_IN_TDLIB_PER_CHAT
|
||||||
|
|
||||||
|
fun resetMessagesInfo() {
|
||||||
|
resetTextMessageInfo()
|
||||||
|
resetMapMessageInfo()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun resetTextMessageInfo() {
|
||||||
|
pendingTdLibText = 0
|
||||||
|
currentTextMessageId = -1L
|
||||||
|
pendingTextMessage = false
|
||||||
|
}
|
||||||
|
|
||||||
|
fun resetMapMessageInfo() {
|
||||||
|
pendingTdLibMap = 0
|
||||||
|
currentMapMessageId = -1L
|
||||||
|
pendingMapMessage = false
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isTextMessageIdPresent() = currentTextMessageId != -1L
|
||||||
|
|
||||||
|
fun isMapMessageIdPresent() = currentMapMessageId != -1L
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
internal const val CHAT_ID_KEY = "chatId"
|
internal const val CHAT_ID_KEY = "chatId"
|
||||||
|
|
|
@ -138,7 +138,7 @@ class ShareLocationHelper(private val app: TelegramApplication) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pendingMessagesLimitReached && checkNetworkTypeAllowed) {
|
if (pendingMessagesLimitReached && checkNetworkTypeAllowed) {
|
||||||
checkNetworkType()
|
updateNetworkType()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,7 +167,7 @@ class ShareLocationHelper(private val app: TelegramApplication) {
|
||||||
app.locationMessages.getBufferedTextMessagesForChat(chatId).take(MAX_MESSAGES_IN_TDLIB_PER_CHAT).forEach {
|
app.locationMessages.getBufferedTextMessagesForChat(chatId).take(MAX_MESSAGES_IN_TDLIB_PER_CHAT).forEach {
|
||||||
if (!shareInfo.isPendingTextMessagesLimitReached()) {
|
if (!shareInfo.isPendingTextMessagesLimitReached()) {
|
||||||
if (it.deviceName.isEmpty()) {
|
if (it.deviceName.isEmpty()) {
|
||||||
if (!shareInfo.pendingTextMessage && shareInfo.currentTextMessageId != -1L) {
|
if (!shareInfo.pendingTextMessage && shareInfo.isTextMessageIdPresent()) {
|
||||||
val content = OsmandLocationUtils.getTextMessageContent(shareInfo.updateTextMessageId, it, app)
|
val content = OsmandLocationUtils.getTextMessageContent(shareInfo.updateTextMessageId, it, app)
|
||||||
app.telegramHelper.editTextLocation(shareInfo, content)
|
app.telegramHelper.editTextLocation(shareInfo, content)
|
||||||
app.locationMessages.removeBufferedMessage(it)
|
app.locationMessages.removeBufferedMessage(it)
|
||||||
|
@ -180,8 +180,12 @@ class ShareLocationHelper(private val app: TelegramApplication) {
|
||||||
app.locationMessages.getBufferedMapMessagesForChat(chatId).take(MAX_MESSAGES_IN_TDLIB_PER_CHAT).forEach {
|
app.locationMessages.getBufferedMapMessagesForChat(chatId).take(MAX_MESSAGES_IN_TDLIB_PER_CHAT).forEach {
|
||||||
if (!shareInfo.isPendingMapMessagesLimitReached()) {
|
if (!shareInfo.isPendingMapMessagesLimitReached()) {
|
||||||
if (it.deviceName.isEmpty()) {
|
if (it.deviceName.isEmpty()) {
|
||||||
if (!shareInfo.pendingMapMessage && shareInfo.currentMapMessageId != -1L) {
|
if (!shareInfo.pendingMapMessage) {
|
||||||
app.telegramHelper.editMapLocation(shareInfo, it)
|
if (shareInfo.isMapMessageIdPresent()) {
|
||||||
|
app.telegramHelper.editMapLocation(shareInfo, it)
|
||||||
|
} else {
|
||||||
|
app.telegramHelper.sendNewMapLocation(shareInfo, it)
|
||||||
|
}
|
||||||
app.locationMessages.removeBufferedMessage(it)
|
app.locationMessages.removeBufferedMessage(it)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -279,7 +283,7 @@ class ShareLocationHelper(private val app: TelegramApplication) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pendingMessagesLimitReached) {
|
if (pendingMessagesLimitReached) {
|
||||||
checkNetworkType()
|
updateNetworkType()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -347,7 +351,7 @@ class ShareLocationHelper(private val app: TelegramApplication) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun checkNetworkType(){
|
fun updateNetworkType(){
|
||||||
if (app.isInternetConnectionAvailable) {
|
if (app.isInternetConnectionAvailable) {
|
||||||
val networkType = when {
|
val networkType = when {
|
||||||
app.isWifiConnected -> TdApi.NetworkTypeWiFi()
|
app.isWifiConnected -> TdApi.NetworkTypeWiFi()
|
||||||
|
|
|
@ -840,7 +840,7 @@ class TelegramHelper private constructor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun stopSendingLiveLocationToChat(shareInfo: ShareChatInfo) {
|
fun stopSendingLiveLocationToChat(shareInfo: ShareChatInfo) {
|
||||||
if (shareInfo.currentMapMessageId != -1L && shareInfo.chatId != -1L) {
|
if (!shareInfo.isMapMessageIdPresent() && shareInfo.chatId != -1L) {
|
||||||
shareInfo.lastSendMapMessageTime = (System.currentTimeMillis() / 1000).toInt()
|
shareInfo.lastSendMapMessageTime = (System.currentTimeMillis() / 1000).toInt()
|
||||||
client?.send(
|
client?.send(
|
||||||
TdApi.EditMessageLiveLocation(shareInfo.chatId, shareInfo.currentMapMessageId, null, null)) { obj ->
|
TdApi.EditMessageLiveLocation(shareInfo.chatId, shareInfo.currentMapMessageId, null, null)) { obj ->
|
||||||
|
|
|
@ -15,7 +15,6 @@ import android.widget.TextView
|
||||||
import androidx.appcompat.widget.ListPopupWindow
|
import androidx.appcompat.widget.ListPopupWindow
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
|
||||||
import net.osmand.Location
|
import net.osmand.Location
|
||||||
import net.osmand.data.LatLon
|
import net.osmand.data.LatLon
|
||||||
import net.osmand.telegram.R
|
import net.osmand.telegram.R
|
||||||
|
@ -99,7 +98,7 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
|
|
||||||
mainView.findViewById<androidx.swiperefreshlayout.widget.SwipeRefreshLayout>(R.id.swipe_refresh).apply {
|
mainView.findViewById<androidx.swiperefreshlayout.widget.SwipeRefreshLayout>(R.id.swipe_refresh).apply {
|
||||||
setOnRefreshListener {
|
setOnRefreshListener {
|
||||||
app.shareLocationHelper.checkNetworkType()
|
app.shareLocationHelper.updateNetworkType()
|
||||||
app.telegramHelper.scanChatsHistory()
|
app.telegramHelper.scanChatsHistory()
|
||||||
updateList()
|
updateList()
|
||||||
isRefreshing = false
|
isRefreshing = false
|
||||||
|
|
|
@ -72,7 +72,7 @@ class SharingStatusBottomSheet : DialogFragment() {
|
||||||
if (sharingStatusType.canResendLocation) {
|
if (sharingStatusType.canResendLocation) {
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
setOnClickListener {
|
setOnClickListener {
|
||||||
app.shareLocationHelper.checkNetworkType()
|
app.shareLocationHelper.updateNetworkType()
|
||||||
app.settings.prepareForSharingNewMessages(sharingStatus.chatsIds)
|
app.settings.prepareForSharingNewMessages(sharingStatus.chatsIds)
|
||||||
app.shareLocationHelper.checkAndSendBufferMessages()
|
app.shareLocationHelper.checkAndSendBufferMessages()
|
||||||
app.forceUpdateMyLocation()
|
app.forceUpdateMyLocation()
|
||||||
|
|
Loading…
Reference in a new issue