1
0
mirror of https://github.com/fabianonline/telegram_backup.git synced 2024-11-23 01:06:17 +00:00

Only run the code in TelegramUpdateHandler if user and db are set.

This commit is contained in:
Fabian Schlenz 2016-07-07 06:24:07 +02:00
parent 2bee99518b
commit 5253145024

View File

@ -31,6 +31,7 @@ class TelegramUpdateHandler implements UpdateCallback {
public void setUser(UserManager user) { this.user = user; this.db = new Database(user, false);} public void setUser(UserManager user) { this.user = user; this.db = new Database(user, false);}
public void onUpdates(TelegramClient c, TLUpdates u) { public void onUpdates(TelegramClient c, TLUpdates u) {
if (db==null) return;
System.out.println("onUpdates - " + u.getUpdates().size() + " Updates, " + u.getUsers().size() + " Users, " + u.getChats().size() + " Chats"); System.out.println("onUpdates - " + u.getUpdates().size() + " Updates, " + u.getUsers().size() + " Users, " + u.getChats().size() + " Chats");
for(TLAbsUpdate update : u.getUpdates()) { for(TLAbsUpdate update : u.getUpdates()) {
processUpdate(update, c); processUpdate(update, c);
@ -41,6 +42,7 @@ class TelegramUpdateHandler implements UpdateCallback {
} }
public void onUpdatesCombined(TelegramClient c, TLUpdatesCombined u) { public void onUpdatesCombined(TelegramClient c, TLUpdatesCombined u) {
if (db==null) return;
System.out.println("onUpdatesCombined"); System.out.println("onUpdatesCombined");
for(TLAbsUpdate update : u.getUpdates()) { for(TLAbsUpdate update : u.getUpdates()) {
processUpdate(update, c); processUpdate(update, c);
@ -50,12 +52,14 @@ class TelegramUpdateHandler implements UpdateCallback {
} }
public void onUpdateShort(TelegramClient c, TLUpdateShort u) { public void onUpdateShort(TelegramClient c, TLUpdateShort u) {
if (db==null) return;
System.out.println("onUpdateShort"); System.out.println("onUpdateShort");
processUpdate(u.getUpdate(), c); processUpdate(u.getUpdate(), c);
System.out.println(" " + u.getUpdate().getClass().getName()); System.out.println(" " + u.getUpdate().getClass().getName());
} }
public void onShortChatMessage(TelegramClient c, TLUpdateShortChatMessage m) { public void onShortChatMessage(TelegramClient c, TLUpdateShortChatMessage m) {
if (db==null) return;
System.out.println("onShortChatMessage - " + m.getMessage()); System.out.println("onShortChatMessage - " + m.getMessage());
TLMessage msg = new TLMessage( TLMessage msg = new TLMessage(
m.getUnread(), m.getUnread(),
@ -81,6 +85,7 @@ class TelegramUpdateHandler implements UpdateCallback {
} }
public void onShortMessage(TelegramClient c, TLUpdateShortMessage m) { public void onShortMessage(TelegramClient c, TLUpdateShortMessage m) {
if (db==null) return;
System.out.println("onShortMessage - " + m.getOut() + " - " + m.getUserId() + " - " + m.getMessage()); System.out.println("onShortMessage - " + m.getOut() + " - " + m.getUserId() + " - " + m.getMessage());
int from_id, to_id; int from_id, to_id;
if (m.getOut()==true) { if (m.getOut()==true) {
@ -113,8 +118,8 @@ class TelegramUpdateHandler implements UpdateCallback {
db.saveMessages(vector); db.saveMessages(vector);
} }
public void onShortSentMessage(TelegramClient c, TLUpdateShortSentMessage m) { System.out.println("onShortSentMessage"); } public void onShortSentMessage(TelegramClient c, TLUpdateShortSentMessage m) { if (db==null) return; System.out.println("onShortSentMessage"); }
public void onUpdateTooLong(TelegramClient c) { System.out.println("onUpdateTooLong"); } public void onUpdateTooLong(TelegramClient c) { if (db==null) return; System.out.println("onUpdateTooLong"); }
private void processUpdate(TLAbsUpdate update, TelegramClient client) { private void processUpdate(TLAbsUpdate update, TelegramClient client) {
if (update instanceof TLUpdateNewMessage) { if (update instanceof TLUpdateNewMessage) {