1
0
mirror of https://github.com/fabianonline/telegram_backup.git synced 2024-12-25 22:35:35 +00:00

Added JSON-based models.

This commit is contained in:
Fabian Schlenz 2017-02-21 14:07:16 +01:00
parent 50ba11a86c
commit da72ae75f5
4 changed files with 47 additions and 3 deletions

View File

@ -35,6 +35,8 @@ import com.github.badoualy.telegram.tl.exception.RpcErrorException;
import com.github.badoualy.telegram.tl.api.request.TLRequestUploadGetFile;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.IOException;
import java.io.File;
@ -206,10 +208,18 @@ public class DownloadManager {
if (response.getMessages().size() != vector.size()) {
CommandLineController.show_error("Requested " + vector.size() + " messages, but got " + response.getMessages().size() + ". That is unexpected. Quitting.");
}
//ObjectMapper om = new ObjectMapper();
//String json = om.writerWithDefaultPrettyPrinter().writeValueAsString(response.getMessages().get(1));
Gson gson = Utils.getGson();
String json = gson.toJson(response.getMessages());
System.out.println(json);
//System.exit(1);
prog.onMessageDownloaded(response.getMessages().size());
db.saveMessages(response.getMessages(), Kotlogram.API_LAYER);
db.saveChats(response.getChats());
db.saveUsers(response.getUsers());
//db.saveMessages(response.getMessages(), Kotlogram.API_LAYER);
//db.saveChats(response.getChats());
//db.saveUsers(response.getUsers());
logger.trace("Sleeping");
try {
TimeUnit.MILLISECONDS.sleep(Config.DELAY_AFTER_GET_MESSAGES);

View File

@ -26,6 +26,8 @@ import org.apache.commons.io.IOUtils;
import de.fabianonline.telegram_backup.Version;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.badoualy.telegram.tl.core.TLBytes;
import java.lang.reflect.Type;
public class Utils {
public static final int VERSIONS_EQUAL = 0;
@ -174,4 +176,17 @@ public class Utils {
if (!CommandLineOptions.cmd_anonymize) return str;
return str.replaceAll("[0-9]", "1").replaceAll("[A-Z]", "A").replaceAll("[a-z]", "a") + " (ANONYMIZED)";
}
public static Gson getGson() {
return new GsonBuilder()
.registerTypeAdapter(TLBytes.class, new TLBytesSerializer())
.setPrettyPrinting()
.create();
}
}
class TLBytesSerializer implements JsonSerializer<TLBytes> {
public JsonElement serialize(TLBytes bytes, Type typeOfSrc, JsonSerializationContext ctx) {
return new JsonNull();
}
}

View File

@ -0,0 +1,15 @@
public class Message_c09be45f {
int flags;
boolean out;
boolean mentioned;
boolean mediaUnread;
boolean silent;
boolean post;
int fromId;
Peer toId;
String _constructor;
int date;
String message;
int id;
JsonElement media;
}

View File

@ -0,0 +1,4 @@
class Peer {
int userId;
String _constructor;
}