Fix request
This commit is contained in:
parent
5032589410
commit
c7f7bef3cc
3 changed files with 28 additions and 23 deletions
|
@ -985,8 +985,6 @@ class TelegramSettings(private val app: TelegramApplication) {
|
||||||
var hasSharingError = false
|
var hasSharingError = false
|
||||||
var additionalActiveTime = ADDITIONAL_ACTIVE_TIME_VALUES_SEC[0]
|
var additionalActiveTime = ADDITIONAL_ACTIVE_TIME_VALUES_SEC[0]
|
||||||
|
|
||||||
fun getPendingTdLib() = pendingTdLibText + pendingTdLibMap
|
|
||||||
|
|
||||||
fun getNextAdditionalActiveTime(): Long {
|
fun getNextAdditionalActiveTime(): Long {
|
||||||
var index = ADDITIONAL_ACTIVE_TIME_VALUES_SEC.indexOf(additionalActiveTime)
|
var index = ADDITIONAL_ACTIVE_TIME_VALUES_SEC.indexOf(additionalActiveTime)
|
||||||
return if (ADDITIONAL_ACTIVE_TIME_VALUES_SEC.lastIndex > index) {
|
return if (ADDITIONAL_ACTIVE_TIME_VALUES_SEC.lastIndex > index) {
|
||||||
|
|
|
@ -48,6 +48,14 @@ class LocationMessages(val app: TelegramApplication) {
|
||||||
return bufferedMessages.filter { it.chatId == chatId }.sortedBy { it.time }
|
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> {
|
fun getIngoingMessages(currentUserId: Int, start: Long, end: Long): List<LocationMessage> {
|
||||||
return dbHelper.getIngoingMessages(currentUserId, start, end)
|
return dbHelper.getIngoingMessages(currentUserId, start, end)
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,7 +98,7 @@ class ShareLocationHelper(private val app: TelegramApplication) {
|
||||||
var bufferedMessagesFull = false
|
var bufferedMessagesFull = false
|
||||||
app.settings.getChatsShareInfo().forEach { (chatId, shareInfo) ->
|
app.settings.getChatsShareInfo().forEach { (chatId, shareInfo) ->
|
||||||
checkAndSendBufferMessagesToChat(chatId)
|
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
|
bufferedMessagesFull = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,28 +110,27 @@ class ShareLocationHelper(private val app: TelegramApplication) {
|
||||||
fun checkAndSendBufferMessagesToChat(chatId: Long) {
|
fun checkAndSendBufferMessagesToChat(chatId: Long) {
|
||||||
val shareInfo = app.settings.getChatsShareInfo()[chatId]
|
val shareInfo = app.settings.getChatsShareInfo()[chatId]
|
||||||
if (shareInfo != null) {
|
if (shareInfo != null) {
|
||||||
app.locationMessages.getBufferedMessagesForChat(chatId).take(MAX_MESSAGES_IN_TDLIB_PER_CHAT).forEach {
|
app.locationMessages.getBufferedTextMessagesForChat(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 (shareInfo.pendingTdLibText < MAX_MESSAGES_IN_TDLIB_PER_CHAT) {
|
if (it.deviceName.isEmpty()) {
|
||||||
if (it.deviceName.isEmpty()) {
|
if (!shareInfo.pendingTextMessage && shareInfo.currentTextMessageId != -1L) {
|
||||||
if (!shareInfo.pendingTextMessage && shareInfo.currentTextMessageId != -1L) {
|
app.telegramHelper.editTextLocation(shareInfo, it)
|
||||||
app.telegramHelper.editTextLocation(shareInfo, it)
|
app.locationMessages.removeBufferedMessage(it)
|
||||||
app.locationMessages.removeBufferedMessage(it)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sendLocationToBot(it, shareInfo, SHARE_TYPE_TEXT)
|
|
||||||
}
|
}
|
||||||
|
} 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()) {
|
app.locationMessages.getBufferedMapMessagesForChat(chatId).take(MAX_MESSAGES_IN_TDLIB_PER_CHAT).forEach {
|
||||||
if (!shareInfo.pendingMapMessage && shareInfo.currentMapMessageId != -1L) {
|
if (shareInfo.pendingTdLibMap < MAX_MESSAGES_IN_TDLIB_PER_CHAT) {
|
||||||
app.telegramHelper.editMapLocation(shareInfo, it)
|
if (it.deviceName.isEmpty()) {
|
||||||
app.locationMessages.removeBufferedMessage(it)
|
if (!shareInfo.pendingMapMessage && shareInfo.currentMapMessageId != -1L) {
|
||||||
}
|
app.telegramHelper.editMapLocation(shareInfo, it)
|
||||||
} else {
|
app.locationMessages.removeBufferedMessage(it)
|
||||||
sendLocationToBot(it, shareInfo, SHARE_TYPE_MAP)
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
sendLocationToBot(it, shareInfo, SHARE_TYPE_MAP)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -191,7 +190,7 @@ class ShareLocationHelper(private val app: TelegramApplication) {
|
||||||
var bufferedMessagesFull = false
|
var bufferedMessagesFull = false
|
||||||
|
|
||||||
chatsShareInfo.values.forEach { shareInfo ->
|
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
|
bufferedMessagesFull = true
|
||||||
}
|
}
|
||||||
when (app.settings.shareTypeValue) {
|
when (app.settings.shareTypeValue) {
|
||||||
|
|
Loading…
Reference in a new issue