Fix request

This commit is contained in:
Chumva 2019-02-14 18:00:32 +02:00
parent 5032589410
commit c7f7bef3cc
3 changed files with 28 additions and 23 deletions

View file

@ -985,8 +985,6 @@ class TelegramSettings(private val app: TelegramApplication) {
var hasSharingError = false
var additionalActiveTime = ADDITIONAL_ACTIVE_TIME_VALUES_SEC[0]
fun getPendingTdLib() = pendingTdLibText + pendingTdLibMap
fun getNextAdditionalActiveTime(): Long {
var index = ADDITIONAL_ACTIVE_TIME_VALUES_SEC.indexOf(additionalActiveTime)
return if (ADDITIONAL_ACTIVE_TIME_VALUES_SEC.lastIndex > index) {

View file

@ -48,6 +48,14 @@ class LocationMessages(val app: TelegramApplication) {
return bufferedMessages.filter { it.chatId == chatId }.sortedBy { it.time }
}
fun getBufferedTextMessagesForChat(chatId: Long): List<BufferMessage> {
return bufferedMessages.filter { it.chatId == chatId && it.type == TYPE_TEXT }.sortedBy { it.time }
}
fun getBufferedMapMessagesForChat(chatId: Long): List<BufferMessage> {
return bufferedMessages.filter { it.chatId == chatId && it.type == TYPE_MAP }.sortedBy { it.time }
}
fun getIngoingMessages(currentUserId: Int, start: Long, end: Long): List<LocationMessage> {
return dbHelper.getIngoingMessages(currentUserId, start, end)
}

View file

@ -98,7 +98,7 @@ class ShareLocationHelper(private val app: TelegramApplication) {
var bufferedMessagesFull = false
app.settings.getChatsShareInfo().forEach { (chatId, shareInfo) ->
checkAndSendBufferMessagesToChat(chatId)
if (shareInfo.getPendingTdLib() > MAX_MESSAGES_IN_TDLIB_PER_CHAT) {
if (shareInfo.pendingTdLibText >= MAX_MESSAGES_IN_TDLIB_PER_CHAT || shareInfo.pendingTdLibMap >= MAX_MESSAGES_IN_TDLIB_PER_CHAT) {
bufferedMessagesFull = true
}
}
@ -110,28 +110,27 @@ class ShareLocationHelper(private val app: TelegramApplication) {
fun checkAndSendBufferMessagesToChat(chatId: Long) {
val shareInfo = app.settings.getChatsShareInfo()[chatId]
if (shareInfo != null) {
app.locationMessages.getBufferedMessagesForChat(chatId).take(MAX_MESSAGES_IN_TDLIB_PER_CHAT).forEach {
if (it.type == LocationMessages.TYPE_TEXT) {
if (shareInfo.pendingTdLibText < MAX_MESSAGES_IN_TDLIB_PER_CHAT) {
if (it.deviceName.isEmpty()) {
if (!shareInfo.pendingTextMessage && shareInfo.currentTextMessageId != -1L) {
app.telegramHelper.editTextLocation(shareInfo, it)
app.locationMessages.removeBufferedMessage(it)
}
} else {
sendLocationToBot(it, shareInfo, SHARE_TYPE_TEXT)
app.locationMessages.getBufferedTextMessagesForChat(chatId).take(MAX_MESSAGES_IN_TDLIB_PER_CHAT).forEach {
if (shareInfo.pendingTdLibText < MAX_MESSAGES_IN_TDLIB_PER_CHAT) {
if (it.deviceName.isEmpty()) {
if (!shareInfo.pendingTextMessage && shareInfo.currentTextMessageId != -1L) {
app.telegramHelper.editTextLocation(shareInfo, it)
app.locationMessages.removeBufferedMessage(it)
}
} else {
sendLocationToBot(it, shareInfo, SHARE_TYPE_TEXT)
}
} else if (it.type == LocationMessages.TYPE_MAP) {
if (shareInfo.pendingTdLibMap < MAX_MESSAGES_IN_TDLIB_PER_CHAT) {
if (it.deviceName.isEmpty()) {
if (!shareInfo.pendingMapMessage && shareInfo.currentMapMessageId != -1L) {
app.telegramHelper.editMapLocation(shareInfo, it)
app.locationMessages.removeBufferedMessage(it)
}
} else {
sendLocationToBot(it, shareInfo, SHARE_TYPE_MAP)
}
}
app.locationMessages.getBufferedMapMessagesForChat(chatId).take(MAX_MESSAGES_IN_TDLIB_PER_CHAT).forEach {
if (shareInfo.pendingTdLibMap < MAX_MESSAGES_IN_TDLIB_PER_CHAT) {
if (it.deviceName.isEmpty()) {
if (!shareInfo.pendingMapMessage && shareInfo.currentMapMessageId != -1L) {
app.telegramHelper.editMapLocation(shareInfo, it)
app.locationMessages.removeBufferedMessage(it)
}
} else {
sendLocationToBot(it, shareInfo, SHARE_TYPE_MAP)
}
}
}
@ -191,7 +190,7 @@ class ShareLocationHelper(private val app: TelegramApplication) {
var bufferedMessagesFull = false
chatsShareInfo.values.forEach { shareInfo ->
if (shareInfo.getPendingTdLib() >= MAX_MESSAGES_IN_TDLIB_PER_CHAT || app.locationMessages.getBufferedMessagesCountForChat(shareInfo.chatId) >= 10) {
if (shareInfo.pendingTdLibText >= MAX_MESSAGES_IN_TDLIB_PER_CHAT || shareInfo.pendingTdLibMap >= MAX_MESSAGES_IN_TDLIB_PER_CHAT || app.locationMessages.getBufferedMessagesCountForChat(shareInfo.chatId) >= MAX_MESSAGES_IN_TDLIB_PER_CHAT) {
bufferedMessagesFull = true
}
when (app.settings.shareTypeValue) {