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

--limit-messages now also affects channels and supergroups.

This commit is contained in:
Fabian Schlenz 2018-04-12 05:56:30 +02:00
parent f434482cdf
commit e8c28b4e72

View File

@ -140,19 +140,22 @@ class DownloadManager(val client: TelegramClient, val prog: DownloadProgressInte
if (settings.download_channels) { if (settings.download_channels) {
println("Checking channels...") println("Checking channels...")
for (channel in chats.channels) { if (channel.download) downloadMessagesFromChannel(channel) } for (channel in chats.channels) { if (channel.download) downloadMessagesFromChannel(channel, limit) }
} }
if (settings.download_supergroups) { if (settings.download_supergroups) {
println("Checking supergroups...") println("Checking supergroups...")
for (supergroup in chats.supergroups) { if (supergroup.download) downloadMessagesFromChannel(supergroup) } for (supergroup in chats.supergroups) { if (supergroup.download) downloadMessagesFromChannel(supergroup, limit) }
} }
} }
private fun downloadMessagesFromChannel(channel: Channel) { private fun downloadMessagesFromChannel(channel: Channel, limit: Int?) {
val obj = channel.obj val obj = channel.obj
val max_known_id = db.getTopMessageIDForChannel(channel.id) var max_known_id = db.getTopMessageIDForChannel(channel.id)
if (obj.getTopMessage() > max_known_id) { if (obj.getTopMessage() > max_known_id) {
if (limit != null) {
max_known_id = Math.max(max_known_id, obj.getTopMessage() - limit)
}
val ids = makeIdList(max_known_id + 1, obj.getTopMessage()) val ids = makeIdList(max_known_id + 1, obj.getTopMessage())
var channel_name = channel.title var channel_name = channel.title