mirror of
https://github.com/fabianonline/telegram_backup.git
synced 2024-11-22 08:46:15 +00:00
DownloadManager now looks at all dialogs, not just the last 100.
This commit is contained in:
parent
c5f901f4a2
commit
96d5b5c77b
@ -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.api.messages.TLAbsMessages
|
||||
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.upload.TLFile
|
||||
import com.github.badoualy.telegram.tl.exception.RpcErrorException
|
||||
@ -283,9 +284,24 @@ class DownloadManager(val client: TelegramClient, val prog: DownloadProgressInte
|
||||
|
||||
fun getChats(): ChatList {
|
||||
val cl = ChatList()
|
||||
logger.trace("Calling messagesGetDialogs")
|
||||
val dialogs = client.messagesGetDialogs(0, 0, TLInputPeerEmpty(), 100)
|
||||
logger.trace("Got {} dialogs back", dialogs.getDialogs().size)
|
||||
logger.debug("Getting list of chats...")
|
||||
val limit = 100
|
||||
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
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user