mirror of
https://github.com/fabianonline/telegram_backup.git
synced 2024-11-22 08:46:15 +00:00
More JSON stuff. Still work in progress.
This commit is contained in:
parent
ef03deb31e
commit
f250f40e5e
@ -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(),
|
||||
|
@ -1,16 +1,16 @@
|
||||
/* Telegram_Backup
|
||||
* Copyright (C) 2016 Fabian Schlenz
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
@ -29,15 +29,16 @@ 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;
|
||||
private Database db = null;
|
||||
public boolean debug = false;
|
||||
private Gson gson = Utils.getGson();
|
||||
|
||||
|
||||
public void activate() { this.user = UserManager.getInstance(); this.db = Database.getInstance();}
|
||||
|
||||
|
||||
public void onUpdates(TelegramClient c, TLUpdates u) {
|
||||
if (db==null) return;
|
||||
if (debug) System.out.println("onUpdates - " + u.getUpdates().size() + " Updates, " + u.getUsers().size() + " Users, " + u.getChats().size() + " Chats");
|
||||
@ -48,7 +49,7 @@ class TelegramUpdateHandler implements UpdateCallback {
|
||||
db.saveUsers(u.getUsers(), gson);
|
||||
db.saveChats(u.getChats(), gson);
|
||||
}
|
||||
|
||||
|
||||
public void onUpdatesCombined(TelegramClient c, TLUpdatesCombined u) {
|
||||
if (db==null) return;
|
||||
if (debug) System.out.println("onUpdatesCombined");
|
||||
@ -58,14 +59,14 @@ class TelegramUpdateHandler implements UpdateCallback {
|
||||
db.saveUsers(u.getUsers(), gson);
|
||||
db.saveChats(u.getChats(), gson);
|
||||
}
|
||||
|
||||
|
||||
public void onUpdateShort(TelegramClient c, TLUpdateShort u) {
|
||||
if (db==null) return;
|
||||
if (debug) System.out.println("onUpdateShort");
|
||||
processUpdate(u.getUpdate(), c);
|
||||
if (debug) System.out.println(" " + u.getUpdate().getClass().getName());
|
||||
}
|
||||
|
||||
|
||||
public void onShortChatMessage(TelegramClient c, TLUpdateShortChatMessage m) {
|
||||
if (db==null) return;
|
||||
if (debug) System.out.println("onShortChatMessage - " + m.getMessage());
|
||||
@ -93,7 +94,7 @@ class TelegramUpdateHandler implements UpdateCallback {
|
||||
db.saveMessages(vector, Kotlogram.API_LAYER, gson);
|
||||
System.out.print('.');
|
||||
}
|
||||
|
||||
|
||||
public void onShortMessage(TelegramClient c, TLUpdateShortMessage m) {
|
||||
if (db==null) return;
|
||||
if (debug) System.out.println("onShortMessage - " + m.getOut() + " - " + m.getUserId() + " - " + m.getMessage());
|
||||
@ -129,27 +130,24 @@ class TelegramUpdateHandler implements UpdateCallback {
|
||||
db.saveMessages(vector, Kotlogram.API_LAYER, gson);
|
||||
System.out.print('.');
|
||||
}
|
||||
|
||||
|
||||
public void onShortSentMessage(TelegramClient c, TLUpdateShortSentMessage m) { if (db==null) return; System.out.println("onShortSentMessage"); }
|
||||
public void onUpdateTooLong(TelegramClient c) { if (db==null) return; System.out.println("onUpdateTooLong"); }
|
||||
|
||||
|
||||
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);
|
||||
if (fm != null && !fm.isEmpty() && !fm.isDownloaded()) {
|
||||
try {
|
||||
fm.download();
|
||||
} 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();
|
||||
}
|
||||
AbstractMediaFileManager fm = FileManagerFactory.getFileManager(msg);
|
||||
if (fm != null && !fm.isEmpty() && !fm.isDownloaded()) {
|
||||
try {
|
||||
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 {
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user