Attempt to fix wrong unread count in notification

This commit is contained in:
DrKLO 2014-07-12 14:23:36 +04:00
parent 780ca63d8d
commit 9667a246b3
3 changed files with 27 additions and 35 deletions

View File

@ -83,7 +83,7 @@ android {
defaultConfig { defaultConfig {
minSdkVersion 8 minSdkVersion 8
targetSdkVersion 19 targetSdkVersion 19
versionCode 275 versionCode 276
versionName "1.6.0" versionName "1.6.0"
} }
} }

View File

@ -1535,8 +1535,27 @@ public class MessagesController implements NotificationCenter.NotificationCenter
req.max_id = max_positive_id; req.max_id = max_positive_id;
req.offset = offset; req.offset = offset;
if (offset == 0) { if (offset == 0) {
HashMap<Long, Integer> dialogsToUpdate = new HashMap<Long, Integer>();
dialogsToUpdate.put(dialog_id, 0);
NotificationsController.getInstance().processDialogsUpdateRead(dialogsToUpdate, true);
NotificationsController.getInstance().processReadMessages(null, dialog_id, 0, max_id); NotificationsController.getInstance().processReadMessages(null, dialog_id, 0, max_id);
MessagesStorage.getInstance().processPendingRead(dialog_id, max_positive_id, max_date, false); 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) { if (req.max_id != Integer.MAX_VALUE) {
ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() { 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<Long, Integer> dialogsToUpdate = new HashMap<Long, Integer>();
dialogsToUpdate.put(dialog_id, 0);
NotificationsController.getInstance().processDialogsUpdateRead(dialogsToUpdate, true);
}
}
});
}
});
if (offset == 0) { if (offset == 0) {
TLRPC.TL_messages_receivedMessages req2 = new TLRPC.TL_messages_receivedMessages(); TLRPC.TL_messages_receivedMessages req2 = new TLRPC.TL_messages_receivedMessages();
req2.max_id = max_positive_id; 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); MessagesStorage.getInstance().processPendingRead(dialog_id, max_id, max_date, false);
HashMap<Long, Integer> dialogsToUpdate = new HashMap<Long, Integer>();
dialogsToUpdate.put(dialog_id, 0);
NotificationsController.getInstance().processDialogsUpdateRead(dialogsToUpdate, true);
MessagesStorage.getInstance().storageQueue.postRunnable(new Runnable() { MessagesStorage.getInstance().storageQueue.postRunnable(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -1636,9 +1639,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter
dialog.unread_count = 0; dialog.unread_count = 0;
NotificationCenter.getInstance().postNotificationName(dialogsNeedReload); NotificationCenter.getInstance().postNotificationName(dialogsNeedReload);
} }
HashMap<Long, Integer> dialogsToUpdate = new HashMap<Long, Integer>();
dialogsToUpdate.put(dialog_id, 0);
NotificationsController.getInstance().processDialogsUpdateRead(dialogsToUpdate, true);
} }
}); });
} }
@ -2616,7 +2616,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
public void run() { public void run() {
newMsgObj.messageOwner.send_state = MESSAGE_SEND_STATE_SENT; newMsgObj.messageOwner.send_state = MESSAGE_SEND_STATE_SENT;
NotificationCenter.getInstance().postNotificationName(messageReceivedByServer, oldId, newMsgObj.messageOwner.id, newMsgObj); 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); NotificationCenter.getInstance().postNotificationName(dialogsNeedReload);
if (!pushMessages.isEmpty()) { if (!pushMessages.isEmpty()) {
NotificationsController.getInstance().processNewMessages(pushMessages, !(res instanceof TLRPC.TL_updates_differenceSlice)); 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()) { if (!obj.isFromMe() && obj.isUnread()) {
NotificationsController.getInstance().processNewMessages(objArr, true); NotificationsController.getInstance().processNewMessages(objArr, true);
NotificationsController.getInstance().processReadMessages(null, 0, 0, 0);
} }
updateInterfaceWithMessages(-updates.chat_id, objArr); updateInterfaceWithMessages(-updates.chat_id, objArr);
NotificationCenter.getInstance().postNotificationName(dialogsNeedReload); NotificationCenter.getInstance().postNotificationName(dialogsNeedReload);
@ -3591,7 +3587,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter
} }
if (!obj.isFromMe() && obj.isUnread()) { if (!obj.isFromMe() && obj.isUnread()) {
NotificationsController.getInstance().processNewMessages(objArr, true); NotificationsController.getInstance().processNewMessages(objArr, true);
NotificationsController.getInstance().processReadMessages(null, 0, 0, 0);
} }
updateInterfaceWithMessages(updates.from_id, objArr); updateInterfaceWithMessages(updates.from_id, objArr);
NotificationCenter.getInstance().postNotificationName(dialogsNeedReload); 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); NotificationsController.getInstance().processReadMessages(markAsReadMessages, 0, 0, 0);
} }
if (!deletedMessages.isEmpty()) { if (!deletedMessages.isEmpty()) {

View File

@ -789,7 +789,7 @@ public class MessagesStorage {
//database.executeFast("DELETE FROM pending_read WHERE uid = " + dialog_id).stepThis().dispose(); //database.executeFast("DELETE FROM pending_read WHERE uid = " + dialog_id).stepThis().dispose();
} else { } else {
database.beginTransaction(); database.beginTransaction();
SQLitePreparedStatement state;/*) = database.executeFast("REPLACE INTO pending_read VALUES(?, ?)"); SQLitePreparedStatement state;/* = database.executeFast("REPLACE INTO pending_read VALUES(?, ?)");
state.requery(); state.requery();
state.bindLong(1, dialog_id); state.bindLong(1, dialog_id);
state.bindInteger(2, max_id); state.bindInteger(2, max_id);
@ -1801,9 +1801,6 @@ public class MessagesStorage {
} }
private void putMessagesInternal(final ArrayList<TLRPC.Message> messages, final boolean withTransaction) { private void putMessagesInternal(final ArrayList<TLRPC.Message> messages, final boolean withTransaction) {
if (Thread.currentThread().getId() != storageQueue.getId()) {
throw new RuntimeException("wrong db thread");
}
try { try {
if (withTransaction) { if (withTransaction) {
database.beginTransaction(); database.beginTransaction();