From 1122ab85d16211888e90700ad7546e5ed8343cc7 Mon Sep 17 00:00:00 2001 From: DrKLO Date: Sun, 13 Jul 2014 03:02:21 +0400 Subject: [PATCH] Bug fixes --- .../telegram/android/MessagesController.java | 27 ++++----- .../android/NotificationsController.java | 9 ++- .../java/org/telegram/ui/ChatActivity.java | 59 ++++++++++--------- 3 files changed, 50 insertions(+), 45 deletions(-) diff --git a/TMessagesProj/src/main/java/org/telegram/android/MessagesController.java b/TMessagesProj/src/main/java/org/telegram/android/MessagesController.java index fe5948a99..117ac6022 100644 --- a/TMessagesProj/src/main/java/org/telegram/android/MessagesController.java +++ b/TMessagesProj/src/main/java/org/telegram/android/MessagesController.java @@ -1548,13 +1548,13 @@ 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); } }); } }); - HashMap dialogsToUpdate = new HashMap(); - dialogsToUpdate.put(dialog_id, 0); - NotificationsController.getInstance().processDialogsUpdateRead(dialogsToUpdate, true); } if (req.max_id != Integer.MAX_VALUE) { ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() { @@ -1634,15 +1634,14 @@ 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); } }); } }); - HashMap dialogsToUpdate = new HashMap(); - dialogsToUpdate.put(dialog_id, 0); - NotificationsController.getInstance().processDialogsUpdateRead(dialogsToUpdate, true); - if (chat.ttl > 0 && was) { int serverTime = Math.max(ConnectionsManager.getInstance().getCurrentTime(), max_date); MessagesStorage.getInstance().createTaskForDate(chat.id, serverTime, serverTime, 0); @@ -2488,15 +2487,15 @@ public class MessagesController implements NotificationCenter.NotificationCenter public void run(TLObject response, TLRPC.TL_error error) { if (newMsgObj != null) { if (error == null) { - TLRPC.messages_SentEncryptedMessage res = (TLRPC.messages_SentEncryptedMessage) response; + final TLRPC.messages_SentEncryptedMessage res = (TLRPC.messages_SentEncryptedMessage) response; newMsgObj.messageOwner.date = res.date; if (res.file instanceof TLRPC.TL_encryptedFile) { processSentMessage(newMsgObj.messageOwner, null, res.file, req, originalPath); } - MessagesStorage.getInstance().updateMessageStateAndId(newMsgObj.messageOwner.random_id, newMsgObj.messageOwner.id, newMsgObj.messageOwner.id, res.date, true); MessagesStorage.getInstance().storageQueue.postRunnable(new Runnable() { @Override public void run() { + MessagesStorage.getInstance().updateMessageStateAndId(newMsgObj.messageOwner.random_id, newMsgObj.messageOwner.id, newMsgObj.messageOwner.id, res.date, false); Utilities.RunOnUIThread(new Runnable() { @Override public void run() { @@ -2528,7 +2527,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter public void run(TLObject response, TLRPC.TL_error error) { if (error == null) { final int oldId = newMsgObj.messageOwner.id; - ArrayList sentMessages = new ArrayList(); + final ArrayList sentMessages = new ArrayList(); if (response instanceof TLRPC.TL_messages_sentMessage) { TLRPC.TL_messages_sentMessage res = (TLRPC.TL_messages_sentMessage) response; @@ -2603,19 +2602,17 @@ public class MessagesController implements NotificationCenter.NotificationCenter } } } - MessagesStorage.getInstance().updateMessageStateAndId(newMsgObj.messageOwner.random_id, oldId, newMsgObj.messageOwner.id, 0, true); - if (!sentMessages.isEmpty()) { - MessagesStorage.getInstance().putMessages(sentMessages, true, true); - } MessagesStorage.getInstance().storageQueue.postRunnable(new Runnable() { @Override public void run() { + MessagesStorage.getInstance().updateMessageStateAndId(newMsgObj.messageOwner.random_id, oldId, newMsgObj.messageOwner.id, 0, false); + MessagesStorage.getInstance().putMessages(sentMessages, true, false); Utilities.RunOnUIThread(new Runnable() { @Override public void run() { newMsgObj.messageOwner.send_state = MESSAGE_SEND_STATE_SENT; NotificationCenter.getInstance().postNotificationName(messageReceivedByServer, oldId, newMsgObj.messageOwner.id, newMsgObj); - sendingMessages.remove(oldId); //TODO CHECK THIS!!! + sendingMessages.remove(oldId); } }); } diff --git a/TMessagesProj/src/main/java/org/telegram/android/NotificationsController.java b/TMessagesProj/src/main/java/org/telegram/android/NotificationsController.java index 8339743a8..66a446a45 100644 --- a/TMessagesProj/src/main/java/org/telegram/android/NotificationsController.java +++ b/TMessagesProj/src/main/java/org/telegram/android/NotificationsController.java @@ -475,7 +475,7 @@ public class NotificationsController { if (messageObjects.isEmpty()) { return; } - notifyCheck = isLast; + boolean added = false; int oldCount = popupMessages.size(); HashMap settingsCache = new HashMap(); @@ -487,9 +487,10 @@ public class NotificationsController { continue; } long dialog_id = messageObject.getDialogId(); - if (dialog_id == openned_dialog_id) { + if (dialog_id == openned_dialog_id && ApplicationLoader.isScreenOn) { continue; } + added = true; Boolean value = settingsCache.get(dialog_id); boolean isChat = (int)dialog_id < 0; @@ -508,6 +509,10 @@ public class NotificationsController { } } + if (added) { + notifyCheck = isLast; + } + if (!popupMessages.isEmpty() && oldCount != popupMessages.size()) { if (ApplicationLoader.mainInterfacePaused || !ApplicationLoader.isScreenOn) { MessageObject messageObject = messageObjects.get(0); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java index d6737a91d..2232f493f 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java @@ -2860,38 +2860,40 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not } } + private void forwardSelectedMessages(long did, boolean fromMyName) { + if (forwaringMessage != null) { + if (forwaringMessage.messageOwner.id > 0) { + if (!fromMyName) { + MessagesController.getInstance().sendMessage(forwaringMessage, did); + } else { + processForwardFromMe(forwaringMessage, did); + } + } + forwaringMessage = null; + } else { + ArrayList ids = new ArrayList(selectedMessagesIds.keySet()); + Collections.sort(ids); + for (Integer id : ids) { + if (id > 0) { + if (!fromMyName) { + MessagesController.getInstance().sendMessage(selectedMessagesIds.get(id), did); + } else { + processForwardFromMe(selectedMessagesIds.get(id), did); + } + } + } + selectedMessagesCanCopyIds.clear(); + selectedMessagesIds.clear(); + } + } + @Override public void didSelectDialog(MessagesActivity activity, long did, boolean param) { if (dialog_id != 0 && (forwaringMessage != null || !selectedMessagesIds.isEmpty())) { - if (forwaringMessage != null) { - if (forwaringMessage.messageOwner.id > 0) { - if (!param) { - MessagesController.getInstance().sendMessage(forwaringMessage, did); - } else { - processForwardFromMe(forwaringMessage, did); - } - } - forwaringMessage = null; - } else { - ArrayList ids = new ArrayList(selectedMessagesIds.keySet()); - Collections.sort(ids); - for (Integer id : ids) { - if (id > 0) { - if (!param) { - MessagesController.getInstance().sendMessage(selectedMessagesIds.get(id), did); - } else { - processForwardFromMe(selectedMessagesIds.get(id), did); - } - } - } - selectedMessagesCanCopyIds.clear(); - selectedMessagesIds.clear(); - } + if (did != dialog_id) { int lower_part = (int)did; if (lower_part != 0) { - activity.removeSelfFromStack(); - Bundle args = new Bundle(); args.putBoolean("scrollToTopOnResume", scrollToTopOnResume); if (lower_part > 0) { @@ -2899,14 +2901,15 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not } else if (lower_part < 0) { args.putInt("chat_id", -lower_part); } - presentFragment(new ChatActivity(args)); - + presentFragment(new ChatActivity(args), true); removeSelfFromStack(); + forwardSelectedMessages(did, param); } else { activity.finishFragment(); } } else { activity.finishFragment(); + forwardSelectedMessages(did, param); chatListView.setSelectionFromTop(messages.size() - 1, -100000 - chatListView.getPaddingTop()); scrollToTopOnResume = true; }