1
0
mirror of https://github.com/fabianonline/telegram_backup.git synced 2024-11-22 16:56:16 +00:00

DownloadManager now looks at all dialogs, not just the last 100.

This commit is contained in:
Fabian Schlenz 2018-04-12 06:46:42 +02:00
parent c5f901f4a2
commit 96d5b5c77b

View File

@ -28,6 +28,7 @@ import com.github.badoualy.telegram.tl.core.TLIntVector
import com.github.badoualy.telegram.tl.core.TLObject import com.github.badoualy.telegram.tl.core.TLObject
import com.github.badoualy.telegram.tl.api.messages.TLAbsMessages import com.github.badoualy.telegram.tl.api.messages.TLAbsMessages
import com.github.badoualy.telegram.tl.api.messages.TLAbsDialogs import com.github.badoualy.telegram.tl.api.messages.TLAbsDialogs
import com.github.badoualy.telegram.tl.api.messages.TLDialogsSlice
import com.github.badoualy.telegram.tl.api.* import com.github.badoualy.telegram.tl.api.*
import com.github.badoualy.telegram.tl.api.upload.TLFile import com.github.badoualy.telegram.tl.api.upload.TLFile
import com.github.badoualy.telegram.tl.exception.RpcErrorException import com.github.badoualy.telegram.tl.exception.RpcErrorException
@ -283,9 +284,24 @@ class DownloadManager(val client: TelegramClient, val prog: DownloadProgressInte
fun getChats(): ChatList { fun getChats(): ChatList {
val cl = ChatList() val cl = ChatList()
logger.trace("Calling messagesGetDialogs") logger.debug("Getting list of chats...")
val dialogs = client.messagesGetDialogs(0, 0, TLInputPeerEmpty(), 100) val limit = 100
logger.trace("Got {} dialogs back", dialogs.getDialogs().size) var offset = 0
while (true) {
var temp: TLAbsDialogs? = null
logger.trace("Calling messagesGetDialogs with offset {}", offset)
Utils.obeyFloodWait {
temp = client.messagesGetDialogs(offset, 0, TLInputPeerEmpty(), limit)
}
val dialogs = temp!!
val last_message = dialogs.messages.filter{ it is TLMessage || it is TLMessageService }.last()
offset = when(last_message) {
is TLMessage -> last_message.date
is TLMessageService -> last_message.date
else -> throw RuntimeException("Unexpected last_message type ${last_message.javaClass}")
}
logger.trace("Got {} dialogs back", dialogs.dialogs.size)
logger.trace("New offset will be {}", offset)
// Add dialogs // Add dialogs
cl.dialogs.addAll(dialogs.getDialogs().filter{it.getPeer() !is TLPeerChannel}) cl.dialogs.addAll(dialogs.getDialogs().filter{it.getPeer() !is TLPeerChannel})
@ -311,6 +327,14 @@ class DownloadManager(val client: TelegramClient, val prog: DownloadProgressInte
cl.channels.add(channel) cl.channels.add(channel)
} }
} }
if (dialogs.dialogs.size < limit) {
logger.debug("Got only ${dialogs.dialogs.size} back instead of ${limit}. Stopping the loop.")
logger.debug("Got ${cl.dialogs.size} groups, ${cl.channels.size} channels and ${cl.supergroups.size} supergroups.")
break;
}
}
return cl return cl
} }