Bug fixes

This commit is contained in:
DrKLO 2015-03-20 02:03:19 +03:00
parent a484ab0d7f
commit f759ce5a65
4 changed files with 73 additions and 57 deletions

View File

@ -82,7 +82,7 @@ android {
defaultConfig { defaultConfig {
minSdkVersion 8 minSdkVersion 8
targetSdkVersion 22 targetSdkVersion 22
versionCode 468 versionCode 469
versionName "2.6.0" versionName "2.6.0"
} }
} }

View File

@ -687,17 +687,21 @@ public class MessagesController implements NotificationCenter.NotificationCenter
} }
protected void processNewDifferenceParams(int seq, int pts, int date, int pts_count) { 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 (pts != -1) {
if (MessagesStorage.lastPtsValue + pts_count == pts) { if (MessagesStorage.lastPtsValue + pts_count == pts) {
FileLog.e("tmessages", "APPLY PTS");
MessagesStorage.lastPtsValue = pts; MessagesStorage.lastPtsValue = pts;
MessagesStorage.getInstance().saveDiffParams(MessagesStorage.lastSeqValue, MessagesStorage.lastPtsValue, MessagesStorage.lastDateValue, MessagesStorage.lastQtsValue); 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()) { 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) { if (updatesStartWaitTimePts == 0) {
updatesStartWaitTimePts = System.currentTimeMillis(); updatesStartWaitTimePts = System.currentTimeMillis();
} }
UserActionUpdatesPts updates = new UserActionUpdatesPts(); UserActionUpdatesPts updates = new UserActionUpdatesPts();
updates.seq = seq; updates.pts = pts;
updates.pts_count = pts_count;
updatesQueuePts.add(updates); updatesQueuePts.add(updates);
} else { } else {
getDifference(); getDifference();
@ -706,6 +710,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
} }
if (seq != -1) { if (seq != -1) {
if (MessagesStorage.lastSeqValue + 1 == seq) { if (MessagesStorage.lastSeqValue + 1 == seq) {
FileLog.e("tmessages", "APPLY SEQ");
MessagesStorage.lastSeqValue = seq; MessagesStorage.lastSeqValue = seq;
if (date != -1) { if (date != -1) {
MessagesStorage.lastDateValue = date; MessagesStorage.lastDateValue = date;
@ -713,6 +718,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
MessagesStorage.getInstance().saveDiffParams(MessagesStorage.lastSeqValue, MessagesStorage.lastPtsValue, MessagesStorage.lastDateValue, MessagesStorage.lastQtsValue); MessagesStorage.getInstance().saveDiffParams(MessagesStorage.lastSeqValue, MessagesStorage.lastPtsValue, MessagesStorage.lastDateValue, MessagesStorage.lastQtsValue);
} else if (MessagesStorage.lastSeqValue != seq) { } else if (MessagesStorage.lastSeqValue != seq) {
if (gettingDifference || updatesStartWaitTimeSeq == 0 || updatesStartWaitTimeSeq != 0 && updatesStartWaitTimeSeq + 1500 > System.currentTimeMillis()) { if (gettingDifference || updatesStartWaitTimeSeq == 0 || updatesStartWaitTimeSeq != 0 && updatesStartWaitTimeSeq + 1500 > System.currentTimeMillis()) {
FileLog.e("tmessages", "ADD UPDATE TO QUEUE seq = " + seq);
if (updatesStartWaitTimeSeq == 0) { if (updatesStartWaitTimeSeq == 0) {
updatesStartWaitTimeSeq = System.currentTimeMillis(); updatesStartWaitTimeSeq = System.currentTimeMillis();
} }

View File

@ -514,11 +514,12 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
ArrayList<TLRPC.Message> arr = new ArrayList<>(); ArrayList<TLRPC.Message> arr = new ArrayList<>();
ArrayList<Long> randomIds = new ArrayList<>(); ArrayList<Long> randomIds = new ArrayList<>();
ArrayList<Integer> ids = new ArrayList<>(); ArrayList<Integer> ids = new ArrayList<>();
HashMap<Long, TLRPC.Message> messagesByRandomIds = new HashMap<>();
for (int a = 0; a < messages.size(); a++) { for (int a = 0; a < messages.size(); a++) {
MessageObject msgObj = messages.get(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; newMsg.flags |= TLRPC.MESSAGE_FLAG_FWD;
if (msgObj.isForwarded()) { if (msgObj.isForwarded()) {
newMsg.fwd_from_id = msgObj.messageOwner.fwd_from_id; newMsg.fwd_from_id = msgObj.messageOwner.fwd_from_id;
@ -541,6 +542,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
newMsg.random_id = getNextRandomId(); newMsg.random_id = getNextRandomId();
} }
randomIds.add(newMsg.random_id); randomIds.add(newMsg.random_id);
messagesByRandomIds.put(newMsg.random_id, newMsg);
ids.add(newMsg.fwd_msg_id); ids.add(newMsg.fwd_msg_id);
newMsg.date = ConnectionsManager.getInstance().getCurrentTime(); newMsg.date = ConnectionsManager.getInstance().getCurrentTime();
newMsg.flags |= TLRPC.MESSAGE_FLAG_UNREAD; newMsg.flags |= TLRPC.MESSAGE_FLAG_UNREAD;
@ -553,7 +555,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
putToSendingMessages(newMsg); 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); MessagesStorage.getInstance().putMessages(arr, false, true, false, 0);
MessagesController.getInstance().updateInterfaceWithMessages(peer, objArr); MessagesController.getInstance().updateInterfaceWithMessages(peer, objArr);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.dialogsNeedReload); NotificationCenter.getInstance().postNotificationName(NotificationCenter.dialogsNeedReload);
@ -564,70 +566,78 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
req.random_id = randomIds; req.random_id = randomIds;
req.id = ids; req.id = ids;
/*ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() { final ArrayList<TLRPC.Message> newMsgObjArr = arr;
ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
@Override @Override
public void run(TLObject response, TLRPC.TL_error error) { public void run(TLObject response, TLRPC.TL_error error) {
if (error == null) { if (error == null) {
final int oldId = newMsgObj.id; final TLRPC.messages_StatedMessages res = (TLRPC.messages_StatedMessages) response;
final ArrayList<TLRPC.Message> sentMessages = new ArrayList<>(); if (newMsgObjArr.size() != res.messages.size()) {
final String attachPath = newMsgObj.attachPath; MessagesController.getInstance().getDifference();
return;
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);
}
} }
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() { if (res instanceof TLRPC.TL_messages_statedMessages) {
@Override MessagesController.getInstance().processNewDifferenceParams(-1, res.pts, -1, res.pts_count);
public void run() { } else if (res instanceof TLRPC.TL_messages_statedMessagesLinks) {
MessagesStorage.getInstance().updateMessageStateAndId(newMsgObj.random_id, oldId, newMsgObj.id, 0, false); MessagesController.getInstance().processNewDifferenceParams(res.seq, res.pts, -1, res.pts_count);
MessagesStorage.getInstance().putMessages(sentMessages, true, false, false, 0); }
AndroidUtilities.runOnUIThread(new Runnable() { for (int a = 0; a < res.messages.size(); a++) {
@Override TLRPC.Message message = res.messages.get(a);
public void run() { final TLRPC.Message newMsgObj = newMsgObjArr.get(a);
newMsgObj.send_state = MessageObject.MESSAGE_SEND_STATE_SENT; if (newMsgObj == null) {
NotificationCenter.getInstance().postNotificationName(NotificationCenter.messageReceivedByServer, oldId, newMsgObj.id, newMsgObj); continue;
processSentMessage(oldId); }
removeFromSendingMessages(oldId); final int oldId = newMsgObj.id;
final ArrayList<TLRPC.Message> 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 { } else {
MessagesStorage.getInstance().markMessageAsSendError(newMsgObj.id); for (final TLRPC.Message newMsgObj : newMsgObjArr) {
AndroidUtilities.runOnUIThread(new Runnable() { MessagesStorage.getInstance().markMessageAsSendError(newMsgObj.id);
@Override AndroidUtilities.runOnUIThread(new Runnable() {
public void run() { @Override
newMsgObj.send_state = MessageObject.MESSAGE_SEND_STATE_SEND_ERROR; public void run() {
NotificationCenter.getInstance().postNotificationName(NotificationCenter.messageSendError, newMsgObj.id); newMsgObj.send_state = MessageObject.MESSAGE_SEND_STATE_SEND_ERROR;
processSentMessage(newMsgObj.id); NotificationCenter.getInstance().postNotificationName(NotificationCenter.messageSendError, newMsgObj.id);
if (newMsgObj.media instanceof TLRPC.TL_messageMediaVideo) { processSentMessage(newMsgObj.id);
stopVideoService(newMsgObj.attachPath); 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); }, null, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassCanCompress, ConnectionsManager.DEFAULT_DATACENTER_ID);
*/
if (a != messages.size() - 1) { if (a != messages.size() - 1) {
objArr = new ArrayList<>(); objArr = new ArrayList<>();
arr = new ArrayList<>(); arr = new ArrayList<>();
randomIds = new ArrayList<>(); randomIds = new ArrayList<>();
ids = new ArrayList<>(); ids = new ArrayList<>();
messagesByRandomIds = new HashMap<>();
} }
} }
} }

View File

@ -1895,10 +1895,10 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
if (arrayList == null || arrayList.isEmpty()) { if (arrayList == null || arrayList.isEmpty()) {
return; return;
} }
for (MessageObject object : arrayList) { if (!fromMyName) {
if (!fromMyName) { SendMessagesHelper.getInstance().sendMessage(arrayList, dialog_id);
SendMessagesHelper.getInstance().sendMessage(object, dialog_id); } else {
} else { for (MessageObject object : arrayList) {
SendMessagesHelper.getInstance().processForwardFromMyName(object, dialog_id); SendMessagesHelper.getInstance().processForwardFromMyName(object, dialog_id);
} }
} }