From f759ce5a6532b9cfe579f5e189d68deff254118a Mon Sep 17 00:00:00 2001 From: DrKLO Date: Fri, 20 Mar 2015 02:03:19 +0300 Subject: [PATCH] Bug fixes --- TMessagesProj/build.gradle | 2 +- .../telegram/android/MessagesController.java | 10 +- .../telegram/android/SendMessagesHelper.java | 110 ++++++++++-------- .../java/org/telegram/ui/ChatActivity.java | 8 +- 4 files changed, 73 insertions(+), 57 deletions(-) diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle index 5c9a86a30..a20711531 100644 --- a/TMessagesProj/build.gradle +++ b/TMessagesProj/build.gradle @@ -82,7 +82,7 @@ android { defaultConfig { minSdkVersion 8 targetSdkVersion 22 - versionCode 468 + versionCode 469 versionName "2.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 e58779679..db5a3fa06 100644 --- a/TMessagesProj/src/main/java/org/telegram/android/MessagesController.java +++ b/TMessagesProj/src/main/java/org/telegram/android/MessagesController.java @@ -687,17 +687,21 @@ public class MessagesController implements NotificationCenter.NotificationCenter } protected void processNewDifferenceParams(int seq, int pts, int date, int pts_count) { + FileLog.e("tmessages", "processNewDifferenceParams seq = " + seq + " pts = " + pts + " date = " + date + " pts_count = " + pts_count); if (pts != -1) { if (MessagesStorage.lastPtsValue + pts_count == pts) { + FileLog.e("tmessages", "APPLY PTS"); MessagesStorage.lastPtsValue = pts; MessagesStorage.getInstance().saveDiffParams(MessagesStorage.lastSeqValue, MessagesStorage.lastPtsValue, MessagesStorage.lastDateValue, MessagesStorage.lastQtsValue); - } else if (MessagesStorage.lastPtsValue == pts) { + } else if (MessagesStorage.lastPtsValue != pts) { if (gettingDifference || updatesStartWaitTimePts == 0 || updatesStartWaitTimePts != 0 && updatesStartWaitTimePts + 1500 > System.currentTimeMillis()) { + FileLog.e("tmessages", "ADD UPDATE TO QUEUE pts = " + pts + " pts_count = " + pts_count); if (updatesStartWaitTimePts == 0) { updatesStartWaitTimePts = System.currentTimeMillis(); } UserActionUpdatesPts updates = new UserActionUpdatesPts(); - updates.seq = seq; + updates.pts = pts; + updates.pts_count = pts_count; updatesQueuePts.add(updates); } else { getDifference(); @@ -706,6 +710,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter } if (seq != -1) { if (MessagesStorage.lastSeqValue + 1 == seq) { + FileLog.e("tmessages", "APPLY SEQ"); MessagesStorage.lastSeqValue = seq; if (date != -1) { MessagesStorage.lastDateValue = date; @@ -713,6 +718,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter MessagesStorage.getInstance().saveDiffParams(MessagesStorage.lastSeqValue, MessagesStorage.lastPtsValue, MessagesStorage.lastDateValue, MessagesStorage.lastQtsValue); } else if (MessagesStorage.lastSeqValue != seq) { if (gettingDifference || updatesStartWaitTimeSeq == 0 || updatesStartWaitTimeSeq != 0 && updatesStartWaitTimeSeq + 1500 > System.currentTimeMillis()) { + FileLog.e("tmessages", "ADD UPDATE TO QUEUE seq = " + seq); if (updatesStartWaitTimeSeq == 0) { updatesStartWaitTimeSeq = System.currentTimeMillis(); } diff --git a/TMessagesProj/src/main/java/org/telegram/android/SendMessagesHelper.java b/TMessagesProj/src/main/java/org/telegram/android/SendMessagesHelper.java index ada7a6ac3..818c25042 100644 --- a/TMessagesProj/src/main/java/org/telegram/android/SendMessagesHelper.java +++ b/TMessagesProj/src/main/java/org/telegram/android/SendMessagesHelper.java @@ -514,11 +514,12 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter ArrayList arr = new ArrayList<>(); ArrayList randomIds = new ArrayList<>(); ArrayList ids = new ArrayList<>(); + HashMap messagesByRandomIds = new HashMap<>(); for (int a = 0; a < messages.size(); a++) { MessageObject msgObj = messages.get(a); - TLRPC.Message newMsg = new TLRPC.TL_message(); + final TLRPC.Message newMsg = new TLRPC.TL_message(); newMsg.flags |= TLRPC.MESSAGE_FLAG_FWD; if (msgObj.isForwarded()) { newMsg.fwd_from_id = msgObj.messageOwner.fwd_from_id; @@ -541,6 +542,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter newMsg.random_id = getNextRandomId(); } randomIds.add(newMsg.random_id); + messagesByRandomIds.put(newMsg.random_id, newMsg); ids.add(newMsg.fwd_msg_id); newMsg.date = ConnectionsManager.getInstance().getCurrentTime(); newMsg.flags |= TLRPC.MESSAGE_FLAG_UNREAD; @@ -553,7 +555,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter putToSendingMessages(newMsg); - if (a % 100 == 0 || a == messages.size() - 1) { + if (arr.size() == 100 || a == messages.size() - 1) { MessagesStorage.getInstance().putMessages(arr, false, true, false, 0); MessagesController.getInstance().updateInterfaceWithMessages(peer, objArr); NotificationCenter.getInstance().postNotificationName(NotificationCenter.dialogsNeedReload); @@ -564,70 +566,78 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter req.random_id = randomIds; req.id = ids; - /*ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() { + final ArrayList newMsgObjArr = arr; + ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() { @Override public void run(TLObject response, TLRPC.TL_error error) { if (error == null) { - final int oldId = newMsgObj.id; - final ArrayList sentMessages = new ArrayList<>(); - final String attachPath = newMsgObj.attachPath; - - if (response instanceof TLRPC.messages_StatedMessages) { - TLRPC.messages_StatedMessages res = (TLRPC.messages_StatedMessages) response; - if (!res.messages.isEmpty()) { - sentMessages.addAll(res.messages); - TLRPC.Message message = res.messages.get(0); - newMsgObj.id = message.id; - processSentMessage(newMsgObj, message, originalPath); - } - if (res instanceof TLRPC.TL_messages_statedMessages) { - MessagesController.getInstance().processNewDifferenceParams(-1, res.pts, -1, res.pts_count); - } else if (res instanceof TLRPC.TL_messages_statedMessagesLinks) { - MessagesController.getInstance().processNewDifferenceParams(res.seq, res.pts, -1, res.pts_count); - } + final TLRPC.messages_StatedMessages res = (TLRPC.messages_StatedMessages) response; + if (newMsgObjArr.size() != res.messages.size()) { + MessagesController.getInstance().getDifference(); + return; } - MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() { - @Override - public void run() { - MessagesStorage.getInstance().updateMessageStateAndId(newMsgObj.random_id, oldId, newMsgObj.id, 0, false); - MessagesStorage.getInstance().putMessages(sentMessages, true, false, false, 0); - AndroidUtilities.runOnUIThread(new Runnable() { - @Override - public void run() { - newMsgObj.send_state = MessageObject.MESSAGE_SEND_STATE_SENT; - NotificationCenter.getInstance().postNotificationName(NotificationCenter.messageReceivedByServer, oldId, newMsgObj.id, newMsgObj); - processSentMessage(oldId); - removeFromSendingMessages(oldId); + if (res instanceof TLRPC.TL_messages_statedMessages) { + MessagesController.getInstance().processNewDifferenceParams(-1, res.pts, -1, res.pts_count); + } else if (res instanceof TLRPC.TL_messages_statedMessagesLinks) { + MessagesController.getInstance().processNewDifferenceParams(res.seq, res.pts, -1, res.pts_count); + } + for (int a = 0; a < res.messages.size(); a++) { + TLRPC.Message message = res.messages.get(a); + final TLRPC.Message newMsgObj = newMsgObjArr.get(a); + if (newMsgObj == null) { + continue; + } + final int oldId = newMsgObj.id; + final ArrayList sentMessages = new ArrayList<>(); + sentMessages.add(message); + newMsgObj.id = message.id; + processSentMessage(newMsgObj, message, null); + MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() { + @Override + public void run() { + MessagesStorage.getInstance().updateMessageStateAndId(newMsgObj.random_id, oldId, newMsgObj.id, 0, false); + MessagesStorage.getInstance().putMessages(sentMessages, true, false, false, 0); + AndroidUtilities.runOnUIThread(new Runnable() { + @Override + public void run() { + newMsgObj.send_state = MessageObject.MESSAGE_SEND_STATE_SENT; + NotificationCenter.getInstance().postNotificationName(NotificationCenter.messageReceivedByServer, oldId, newMsgObj.id, newMsgObj); + processSentMessage(oldId); + removeFromSendingMessages(oldId); + } + }); + if (newMsgObj.media instanceof TLRPC.TL_messageMediaVideo) { + stopVideoService(newMsgObj.attachPath); } - }); - if (newMsgObj.media instanceof TLRPC.TL_messageMediaVideo) { - stopVideoService(attachPath); } - } - }); + }); + } } else { - MessagesStorage.getInstance().markMessageAsSendError(newMsgObj.id); - AndroidUtilities.runOnUIThread(new Runnable() { - @Override - public void run() { - newMsgObj.send_state = MessageObject.MESSAGE_SEND_STATE_SEND_ERROR; - NotificationCenter.getInstance().postNotificationName(NotificationCenter.messageSendError, newMsgObj.id); - processSentMessage(newMsgObj.id); - if (newMsgObj.media instanceof TLRPC.TL_messageMediaVideo) { - stopVideoService(newMsgObj.attachPath); + for (final TLRPC.Message newMsgObj : newMsgObjArr) { + MessagesStorage.getInstance().markMessageAsSendError(newMsgObj.id); + AndroidUtilities.runOnUIThread(new Runnable() { + @Override + public void run() { + newMsgObj.send_state = MessageObject.MESSAGE_SEND_STATE_SEND_ERROR; + NotificationCenter.getInstance().postNotificationName(NotificationCenter.messageSendError, newMsgObj.id); + processSentMessage(newMsgObj.id); + if (newMsgObj.media instanceof TLRPC.TL_messageMediaVideo) { + stopVideoService(newMsgObj.attachPath); + } + removeFromSendingMessages(newMsgObj.id); } - removeFromSendingMessages(newMsgObj.id); - } - }); + }); + } } } }, null, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassCanCompress, ConnectionsManager.DEFAULT_DATACENTER_ID); - */ + if (a != messages.size() - 1) { objArr = new ArrayList<>(); arr = new ArrayList<>(); randomIds = new ArrayList<>(); ids = new ArrayList<>(); + messagesByRandomIds = new HashMap<>(); } } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java index 1a56c3936..fdb89193d 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java @@ -1895,10 +1895,10 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not if (arrayList == null || arrayList.isEmpty()) { return; } - for (MessageObject object : arrayList) { - if (!fromMyName) { - SendMessagesHelper.getInstance().sendMessage(object, dialog_id); - } else { + if (!fromMyName) { + SendMessagesHelper.getInstance().sendMessage(arrayList, dialog_id); + } else { + for (MessageObject object : arrayList) { SendMessagesHelper.getInstance().processForwardFromMyName(object, dialog_id); } }