Resend map, after map editing error
This commit is contained in:
parent
17b7386514
commit
924d15616d
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.notifications.TelegramNotification.NotificationType
|
||||
import net.osmand.telegram.utils.AndroidUtils
|
||||
import net.osmand.telegram.utils.OsmandLocationUtils
|
||||
import org.drinkless.td.libcore.telegram.TdApi
|
||||
import java.util.*
|
||||
|
||||
|
@ -377,7 +376,10 @@ class TelegramService : Service(), LocationListener, TelegramIncomingMessagesLis
|
|||
Log.d(PlatformUtil.TAG, "Send live location error: $code - $message")
|
||||
when (messageType) {
|
||||
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() {
|
||||
shareChatsInfo.forEach { (_, shareInfo) ->
|
||||
prepareForSharingNewMessages(shareInfo)
|
||||
shareInfo.resetMessagesInfo()
|
||||
}
|
||||
}
|
||||
|
||||
fun prepareForSharingNewMessages(chatsIds: List<Long>) {
|
||||
chatsIds.forEach {
|
||||
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 getChatsShareInfo() = shareChatsInfo
|
||||
|
@ -1497,6 +1488,27 @@ class TelegramSettings(private val app: TelegramApplication) {
|
|||
|
||||
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 {
|
||||
|
||||
internal const val CHAT_ID_KEY = "chatId"
|
||||
|
|
|
@ -138,7 +138,7 @@ class ShareLocationHelper(private val app: TelegramApplication) {
|
|||
}
|
||||
}
|
||||
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 {
|
||||
if (!shareInfo.isPendingTextMessagesLimitReached()) {
|
||||
if (it.deviceName.isEmpty()) {
|
||||
if (!shareInfo.pendingTextMessage && shareInfo.currentTextMessageId != -1L) {
|
||||
if (!shareInfo.pendingTextMessage && shareInfo.isTextMessageIdPresent()) {
|
||||
val content = OsmandLocationUtils.getTextMessageContent(shareInfo.updateTextMessageId, it, app)
|
||||
app.telegramHelper.editTextLocation(shareInfo, content)
|
||||
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 {
|
||||
if (!shareInfo.isPendingMapMessagesLimitReached()) {
|
||||
if (it.deviceName.isEmpty()) {
|
||||
if (!shareInfo.pendingMapMessage && shareInfo.currentMapMessageId != -1L) {
|
||||
if (!shareInfo.pendingMapMessage) {
|
||||
if (shareInfo.isMapMessageIdPresent()) {
|
||||
app.telegramHelper.editMapLocation(shareInfo, it)
|
||||
} else {
|
||||
app.telegramHelper.sendNewMapLocation(shareInfo, it)
|
||||
}
|
||||
app.locationMessages.removeBufferedMessage(it)
|
||||
}
|
||||
} else {
|
||||
|
@ -279,7 +283,7 @@ class ShareLocationHelper(private val app: TelegramApplication) {
|
|||
}
|
||||
}
|
||||
if (pendingMessagesLimitReached) {
|
||||
checkNetworkType()
|
||||
updateNetworkType()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -347,7 +351,7 @@ class ShareLocationHelper(private val app: TelegramApplication) {
|
|||
}
|
||||
}
|
||||
|
||||
fun checkNetworkType(){
|
||||
fun updateNetworkType(){
|
||||
if (app.isInternetConnectionAvailable) {
|
||||
val networkType = when {
|
||||
app.isWifiConnected -> TdApi.NetworkTypeWiFi()
|
||||
|
|
|
@ -840,7 +840,7 @@ class TelegramHelper private constructor() {
|
|||
}
|
||||
|
||||
fun stopSendingLiveLocationToChat(shareInfo: ShareChatInfo) {
|
||||
if (shareInfo.currentMapMessageId != -1L && shareInfo.chatId != -1L) {
|
||||
if (!shareInfo.isMapMessageIdPresent() && shareInfo.chatId != -1L) {
|
||||
shareInfo.lastSendMapMessageTime = (System.currentTimeMillis() / 1000).toInt()
|
||||
client?.send(
|
||||
TdApi.EditMessageLiveLocation(shareInfo.chatId, shareInfo.currentMapMessageId, null, null)) { obj ->
|
||||
|
|
|
@ -15,7 +15,6 @@ import android.widget.TextView
|
|||
import androidx.appcompat.widget.ListPopupWindow
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import net.osmand.Location
|
||||
import net.osmand.data.LatLon
|
||||
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 {
|
||||
setOnRefreshListener {
|
||||
app.shareLocationHelper.checkNetworkType()
|
||||
app.shareLocationHelper.updateNetworkType()
|
||||
app.telegramHelper.scanChatsHistory()
|
||||
updateList()
|
||||
isRefreshing = false
|
||||
|
|
|
@ -72,7 +72,7 @@ class SharingStatusBottomSheet : DialogFragment() {
|
|||
if (sharingStatusType.canResendLocation) {
|
||||
if (i == 0) {
|
||||
setOnClickListener {
|
||||
app.shareLocationHelper.checkNetworkType()
|
||||
app.shareLocationHelper.updateNetworkType()
|
||||
app.settings.prepareForSharingNewMessages(sharingStatus.chatsIds)
|
||||
app.shareLocationHelper.checkAndSendBufferMessages()
|
||||
app.forceUpdateMyLocation()
|
||||
|
|
Loading…
Reference in a new issue