From 9667a246b3c2da917a033b565716fabad025c256 Mon Sep 17 00:00:00 2001 From: DrKLO Date: Sat, 12 Jul 2014 14:23:36 +0400 Subject: [PATCH] Attempt to fix wrong unread count in notification --- TMessagesProj/build.gradle | 2 +- .../telegram/android/MessagesController.java | 55 +++++++++---------- .../org/telegram/android/MessagesStorage.java | 5 +- 3 files changed, 27 insertions(+), 35 deletions(-) diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle index ec66a3382..595d4967a 100644 --- a/TMessagesProj/build.gradle +++ b/TMessagesProj/build.gradle @@ -83,7 +83,7 @@ android { defaultConfig { minSdkVersion 8 targetSdkVersion 19 - versionCode 275 + versionCode 276 versionName "1.6.0" } } diff --git a/TMessagesProj/src/main/java/org/telegram/android/MessagesController.java b/TMessagesProj/src/main/java/org/telegram/android/MessagesController.java index 3b2b52428..8b9aa308e 100644 --- a/TMessagesProj/src/main/java/org/telegram/android/MessagesController.java +++ b/TMessagesProj/src/main/java/org/telegram/android/MessagesController.java @@ -1535,8 +1535,27 @@ public class MessagesController implements NotificationCenter.NotificationCenter req.max_id = max_positive_id; req.offset = offset; if (offset == 0) { + HashMap dialogsToUpdate = new HashMap(); + dialogsToUpdate.put(dialog_id, 0); + NotificationsController.getInstance().processDialogsUpdateRead(dialogsToUpdate, true); + NotificationsController.getInstance().processReadMessages(null, dialog_id, 0, max_id); MessagesStorage.getInstance().processPendingRead(dialog_id, max_positive_id, max_date, false); + MessagesStorage.getInstance().storageQueue.postRunnable(new Runnable() { + @Override + public void run() { + Utilities.RunOnUIThread(new Runnable() { + @Override + public void run() { + TLRPC.TL_dialog dialog = dialogs_dict.get(dialog_id); + if (dialog != null) { + dialog.unread_count = 0; + NotificationCenter.getInstance().postNotificationName(dialogsNeedReload); + } + } + }); + } + }); } if (req.max_id != Integer.MAX_VALUE) { ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() { @@ -1572,26 +1591,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter }); } - MessagesStorage.getInstance().storageQueue.postRunnable(new Runnable() { - @Override - public void run() { - Utilities.RunOnUIThread(new Runnable() { - @Override - public void run() { - if (offset == 0) { - TLRPC.TL_dialog dialog = dialogs_dict.get(dialog_id); - if (dialog != null) { - dialog.unread_count = 0; - NotificationCenter.getInstance().postNotificationName(dialogsNeedReload); - } - HashMap dialogsToUpdate = new HashMap(); - dialogsToUpdate.put(dialog_id, 0); - NotificationsController.getInstance().processDialogsUpdateRead(dialogsToUpdate, true); - } - } - }); - } - }); if (offset == 0) { TLRPC.TL_messages_receivedMessages req2 = new TLRPC.TL_messages_receivedMessages(); req2.max_id = max_positive_id; @@ -1625,6 +1624,10 @@ public class MessagesController implements NotificationCenter.NotificationCenter } MessagesStorage.getInstance().processPendingRead(dialog_id, max_id, max_date, false); + HashMap dialogsToUpdate = new HashMap(); + dialogsToUpdate.put(dialog_id, 0); + NotificationsController.getInstance().processDialogsUpdateRead(dialogsToUpdate, true); + MessagesStorage.getInstance().storageQueue.postRunnable(new Runnable() { @Override public void run() { @@ -1636,9 +1639,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter dialog.unread_count = 0; NotificationCenter.getInstance().postNotificationName(dialogsNeedReload); } - HashMap dialogsToUpdate = new HashMap(); - dialogsToUpdate.put(dialog_id, 0); - NotificationsController.getInstance().processDialogsUpdateRead(dialogsToUpdate, true); } }); } @@ -2616,7 +2616,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter public void run() { newMsgObj.messageOwner.send_state = MESSAGE_SEND_STATE_SENT; NotificationCenter.getInstance().postNotificationName(messageReceivedByServer, oldId, newMsgObj.messageOwner.id, newMsgObj); - sendingMessages.remove(oldId); + sendingMessages.remove(oldId); //TODO CHECK THIS!!! } }); } @@ -3430,9 +3430,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter NotificationCenter.getInstance().postNotificationName(dialogsNeedReload); if (!pushMessages.isEmpty()) { NotificationsController.getInstance().processNewMessages(pushMessages, !(res instanceof TLRPC.TL_updates_differenceSlice)); - if (res.other_updates == null || res.other_updates.isEmpty()) { - NotificationsController.getInstance().processReadMessages(null, 0, 0, 0); - } } } }); @@ -3535,7 +3532,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter } if (!obj.isFromMe() && obj.isUnread()) { NotificationsController.getInstance().processNewMessages(objArr, true); - NotificationsController.getInstance().processReadMessages(null, 0, 0, 0); } updateInterfaceWithMessages(-updates.chat_id, objArr); NotificationCenter.getInstance().postNotificationName(dialogsNeedReload); @@ -3591,7 +3587,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter } if (!obj.isFromMe() && obj.isUnread()) { NotificationsController.getInstance().processNewMessages(objArr, true); - NotificationsController.getInstance().processReadMessages(null, 0, 0, 0); } updateInterfaceWithMessages(updates.from_id, objArr); NotificationCenter.getInstance().postNotificationName(dialogsNeedReload); @@ -4181,7 +4176,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter } } } - if (!markAsReadMessages.isEmpty() || !messages.isEmpty()) { + if (!markAsReadMessages.isEmpty()) { NotificationsController.getInstance().processReadMessages(markAsReadMessages, 0, 0, 0); } if (!deletedMessages.isEmpty()) { diff --git a/TMessagesProj/src/main/java/org/telegram/android/MessagesStorage.java b/TMessagesProj/src/main/java/org/telegram/android/MessagesStorage.java index da1be2154..a98c54c06 100644 --- a/TMessagesProj/src/main/java/org/telegram/android/MessagesStorage.java +++ b/TMessagesProj/src/main/java/org/telegram/android/MessagesStorage.java @@ -789,7 +789,7 @@ public class MessagesStorage { //database.executeFast("DELETE FROM pending_read WHERE uid = " + dialog_id).stepThis().dispose(); } else { database.beginTransaction(); - SQLitePreparedStatement state;/*) = database.executeFast("REPLACE INTO pending_read VALUES(?, ?)"); + SQLitePreparedStatement state;/* = database.executeFast("REPLACE INTO pending_read VALUES(?, ?)"); state.requery(); state.bindLong(1, dialog_id); state.bindInteger(2, max_id); @@ -1801,9 +1801,6 @@ public class MessagesStorage { } private void putMessagesInternal(final ArrayList messages, final boolean withTransaction) { - if (Thread.currentThread().getId() != storageQueue.getId()) { - throw new RuntimeException("wrong db thread"); - } try { if (withTransaction) { database.beginTransaction();