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

Committing current state.

This commit is contained in:
Fabian Schlenz 2017-11-24 11:29:26 +01:00
parent f250f40e5e
commit ae95481e54
3 changed files with 11 additions and 5 deletions

View File

@ -47,6 +47,7 @@ import java.text.SimpleDateFormat;
import de.fabianonline.telegram_backup.mediafilemanager.AbstractMediaFileManager;
import de.fabianonline.telegram_backup.mediafilemanager.FileManagerFactory;
import de.fabianonline.telegram_backup.models.Message;
public class Database {
private Connection conn;
@ -396,12 +397,12 @@ public class Database {
}
}
public LinkedList<TLMessage> getMessagesWithMedia() {
public LinkedList<Message> getMessagesWithMedia() {
try {
LinkedList<TLMessage> list = new LinkedList<TLMessage>();
ResultSet rs = stmt.executeQuery("SELECT data FROM messages WHERE has_media=1");
LinkedList<Message> list = new LinkedList<Message>();
ResultSet rs = stmt.executeQuery("SELECT json FROM messages WHERE has_media=1");
while (rs.next()) {
list.add(bytesToTLMessage(rs.getBytes(1)));
list.add(new Message(rs.getString(1)));
}
rs.close();
return list;

View File

@ -137,7 +137,7 @@ class TelegramUpdateHandler implements UpdateCallback {
private void processUpdate(TLAbsUpdate update, TelegramClient client) {
if (update instanceof TLUpdateNewMessage) {
TLAbsMessage abs_msg = ((TLUpdateNewMessage)update).getMessage();
Message msg = new Message(abs_msg);
Message msg = Message.fromObject(abs_msg);
msg.save();
System.out.print('.');
AbstractMediaFileManager fm = FileManagerFactory.getFileManager(msg);

View File

@ -1,6 +1,7 @@
package de.fabianonline.telegram_backup.models;
import de.fabianonline.telegram_backup.Database;
import de.fabianonline.telegram_backup.Utils;
import com.google.gson.JsonParser;
import com.google.gson.JsonObject;
@ -14,6 +15,10 @@ public class Message {
public Message(String json) {
this.json = new JsonParser().parse(json).getAsJsonObject();
}
public static Message fromObject(TLAbsMessage msg) {
return new Message(Utils.getGson().fromObject(msg));
}
public static Message get(int id) {
String json = Database.getInstance().queryString("SELECT json FROM " + tableName + " WHERE id=" + id);