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

More JSON stuff. Still work in progress.

This commit is contained in:
Fabian Schlenz 2017-02-26 13:18:14 +01:00
parent ef03deb31e
commit f250f40e5e
5 changed files with 28 additions and 26 deletions

View File

@ -22,6 +22,7 @@ import de.fabianonline.telegram_backup.StickerConverter;
import de.fabianonline.telegram_backup.DownloadProgressInterface;
import de.fabianonline.telegram_backup.mediafilemanager.FileManagerFactory;
import de.fabianonline.telegram_backup.mediafilemanager.AbstractMediaFileManager;
import de.fabianonline.telegram_backup.models.Message;
import com.github.badoualy.telegram.api.TelegramClient;
import com.github.badoualy.telegram.api.Kotlogram;
@ -263,10 +264,10 @@ public class DownloadManager {
downloadMessages(ids);
}
LinkedList<TLMessage> messages = this.db.getMessagesWithMedia();
LinkedList<Message> messages = this.db.getMessagesWithMedia();
logger.debug("Database returned {} messages with media", messages.size());
prog.onMediaDownloadStart(messages.size());
for (TLMessage msg : messages) {
for (Message msg : messages) {
AbstractMediaFileManager m = FileManagerFactory.getFileManager(msg);
logger.trace("message {}, {}, {}, {}, {}",
msg.getId(),

View File

@ -29,6 +29,7 @@ import de.fabianonline.telegram_backup.Utils;
import de.fabianonline.telegram_backup.UserManager;
import de.fabianonline.telegram_backup.mediafilemanager.AbstractMediaFileManager;
import de.fabianonline.telegram_backup.mediafilemanager.FileManagerFactory;
import de.fabianonline.telegram_backup.models.Message;
class TelegramUpdateHandler implements UpdateCallback {
private UserManager user = null;
@ -136,22 +137,19 @@ class TelegramUpdateHandler implements UpdateCallback {
private void processUpdate(TLAbsUpdate update, TelegramClient client) {
if (update instanceof TLUpdateNewMessage) {
TLAbsMessage abs_msg = ((TLUpdateNewMessage)update).getMessage();
TLVector<TLAbsMessage> vector = new TLVector<TLAbsMessage>(TLAbsMessage.class);
vector.add(abs_msg);
db.saveMessages(vector, Kotlogram.API_LAYER, gson);
Message msg = new Message(abs_msg);
msg.save();
System.out.print('.');
if (abs_msg instanceof TLMessage) {
AbstractMediaFileManager fm = FileManagerFactory.getFileManager((TLMessage)abs_msg, user, client);
AbstractMediaFileManager fm = FileManagerFactory.getFileManager(msg);
if (fm != null && !fm.isEmpty() && !fm.isDownloaded()) {
try {
fm.download();
fm.download(client);
} catch (Exception e) {
System.out.println("We got an exception while downloading media, but we're going to ignore it.");
System.out.println("Here it is anyway:");
e.printStackTrace();
}
}
}
} else {
// ignore everything else...
}

View File

@ -27,6 +27,7 @@ import de.fabianonline.telegram_backup.models.Message;
import com.google.gson.JsonObject;
import com.github.badoualy.telegram.api.TelegramClient;
import com.github.badoualy.telegram.tl.exception.RpcErrorException;
import java.io.IOException;
import java.io.File;

View File

@ -27,6 +27,7 @@ import com.google.gson.JsonObject;
import com.google.gson.JsonElement;
import com.github.badoualy.telegram.api.TelegramClient;
import com.github.badoualy.telegram.tl.exception.RpcErrorException;
import java.io.IOException;
import java.io.File;

View File

@ -27,6 +27,7 @@ import com.google.gson.JsonObject;
import com.google.gson.JsonElement;
import com.github.badoualy.telegram.api.TelegramClient;
import com.github.badoualy.telegram.tl.exception.RpcErrorException;
import java.io.IOException;
import java.io.File;