Bug fixes

This commit is contained in:
DrKLO 2014-08-02 00:31:15 +01:00
parent f7e0225f48
commit dbef14dfeb
5 changed files with 87 additions and 52 deletions

View file

@ -83,7 +83,7 @@ android {
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 297
versionCode 299
versionName "1.7.0"
}
}

View file

@ -708,6 +708,23 @@ public class MessagesController implements NotificationCenter.NotificationCenter
public void run(TLObject response, TLRPC.TL_error error) {
if (error == null) {
final TLRPC.messages_Messages res = (TLRPC.messages_Messages) response;
MessagesStorage.getInstance().putUsersAndChats(res.users, res.chats, true, true);
Utilities.RunOnUIThread(new Runnable() {
@Override
public void run() {
for (TLRPC.User user : res.users) {
users.put(user.id, user);
if (user.id == UserConfig.getClientUserId()) {
UserConfig.setCurrentUser(user);
}
}
for (TLRPC.Chat chat : res.chats) {
chats.put(chat.id, chat);
}
}
});
if (res instanceof TLRPC.TL_messages_messagesSlice) {
processLoadedMediaCount(res.count, uid, classGuid, false);
} else {
@ -1110,10 +1127,10 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
}
public void loadMessages(final long dialog_id, final int offset, final int count, final int max_id, boolean fromCache, int midDate, final int classGuid, boolean from_unread, boolean forward) {
public void loadMessages(final long dialog_id, final int count, final int max_id, boolean fromCache, int midDate, final int classGuid, boolean from_unread, boolean forward) {
int lower_part = (int)dialog_id;
if (fromCache || lower_part == 0) {
MessagesStorage.getInstance().getMessages(dialog_id, offset, count, max_id, midDate, classGuid, from_unread, forward);
MessagesStorage.getInstance().getMessages(dialog_id, count, max_id, midDate, classGuid, from_unread, forward);
} else {
TLRPC.TL_messages_getHistory req = new TLRPC.TL_messages_getHistory();
if (lower_part < 0) {
@ -1130,7 +1147,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
req.peer.user_id = user.id;
}
}
req.offset = offset;
req.offset = 0;
req.limit = count;
req.max_id = max_id;
long reqId = ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
@ -1138,7 +1155,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
public void run(TLObject response, TLRPC.TL_error error) {
if (error == null) {
final TLRPC.messages_Messages res = (TLRPC.messages_Messages) response;
processLoadedMessages(res, dialog_id, offset, count, max_id, false, classGuid, 0, 0, 0, 0, false);
processLoadedMessages(res, dialog_id, count, max_id, false, classGuid, 0, 0, 0, 0, false);
}
}
});
@ -1146,7 +1163,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
}
public void processLoadedMessages(final TLRPC.messages_Messages messagesRes, final long dialog_id, final int offset, final int count, final int max_id, final boolean isCache, final int classGuid, final int first_unread, final int last_unread, final int unread_count, final int last_date, final boolean isForward) {
public void processLoadedMessages(final TLRPC.messages_Messages messagesRes, final long dialog_id, final int count, final int max_id, final boolean isCache, final int classGuid, final int first_unread, final int last_unread, final int unread_count, final int last_date, final boolean isForward) {
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public void run() {
@ -1158,7 +1175,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
Utilities.RunOnUIThread(new Runnable() {
@Override
public void run() {
loadMessages(dialog_id, offset, count, max_id, false, 0, classGuid, false, false);
loadMessages(dialog_id, count, max_id, false, 0, classGuid, false, false);
}
});
return;
@ -1196,7 +1213,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
chats.put(c.id, c);
}
}
NotificationCenter.getInstance().postNotificationName(messagesDidLoaded, dialog_id, offset, count, objects, isCache, first_unread, last_unread, unread_count, last_date, isForward);
NotificationCenter.getInstance().postNotificationName(messagesDidLoaded, dialog_id, count, objects, isCache, first_unread, last_unread, unread_count, last_date, isForward);
}
});
}
@ -4618,17 +4635,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
boolean isEncryptedChat = ((int)uid) == 0;
MessagesStorage.getInstance().storageQueue.postRunnable(new Runnable() {
@Override
public void run() {
Utilities.RunOnUIThread(new Runnable() {
@Override
public void run() {
NotificationCenter.getInstance().postNotificationName(didReceivedNewMessages, uid, messages);
}
});
}
});
NotificationCenter.getInstance().postNotificationName(didReceivedNewMessages, uid, messages);
for (MessageObject message : messages) {
if (lastMessage == null || (!isEncryptedChat && message.messageOwner.id > lastMessage.messageOwner.id || isEncryptedChat && message.messageOwner.id < lastMessage.messageOwner.id) || message.messageOwner.date > lastMessage.messageOwner.date) {

View file

@ -217,7 +217,6 @@ public class MessagesStorage {
cacheFile.delete();
cacheFile = null;
}
storageQueue.cleanupQueue();
openDatabase();
if (isLogin) {
Utilities.stageQueue.postRunnable(new Runnable() {
@ -1320,14 +1319,14 @@ public class MessagesStorage {
});
}
public void getMessages(final long dialog_id, final int offset, final int count, final int max_id, final int minDate, final int classGuid, final boolean from_unread, final boolean forward) {
public void getMessages(final long dialog_id, final int count, final int max_id, final int minDate, final int classGuid, final boolean from_unread, final boolean forward) {
storageQueue.postRunnable(new Runnable() {
@Override
public void run() {
TLRPC.TL_messages_messages res = new TLRPC.TL_messages_messages();
int count_unread = 0;
int count_query = count;
int offset_query = offset;
int offset_query = 0;
int min_unread_id = 0;
int max_unread_id = 0;
int max_unread_date = 0;
@ -1486,7 +1485,7 @@ public class MessagesStorage {
res.users.clear();
FileLog.e("tmessages", e);
} finally {
MessagesController.getInstance().processLoadedMessages(res, dialog_id, offset, count_query, max_id, true, classGuid, min_unread_id, max_unread_id, count_unread, max_unread_date, forward);
MessagesController.getInstance().processLoadedMessages(res, dialog_id, count_query, max_id, true, classGuid, min_unread_id, max_unread_id, count_unread, max_unread_date, forward);
}
}
});

View file

@ -17,10 +17,10 @@ import org.telegram.android.AndroidUtilities;
import org.telegram.ui.ApplicationLoader;
import java.io.RandomAccessFile;
import java.net.URL;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
@ -82,6 +82,12 @@ public class FileLoadOperation {
httpConnection.setReadTimeout(5000);
httpConnection.connect();
httpConnectionStream = httpConnection.getInputStream();
/*String ALLOWED_URI_CHARS = "@#&=*+-_.,:!?()/~'%";
String str = Uri.encode(url, ALLOWED_URI_CHARS);
HttpClient httpclient = new DefaultHttpClient();
HttpGet request = new HttpGet(str);
httpConnectionStream = httpclient.execute(request).getEntity().getContent();*/
} catch (Exception e) {
FileLog.e("tmessages", e);
cleanup();

View file

@ -143,14 +143,15 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
private boolean endReached = false;
private boolean loading = false;
private boolean cacheEndReaced = false;
private boolean firstLoading = true;
private int minDate = 0;
private int progressTag = 0;
boolean first = true;
private boolean first = true;
private int unread_to_load = 0;
private int first_unread_id = 0;
private int last_unread_id = 0;
private boolean unread_end_reached = false;
private boolean unread_end_reached = true;
private boolean loadingForward = false;
private MessageObject unreadMessageObject = null;
@ -338,7 +339,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
super.onFragmentCreate();
loading = true;
MessagesController.getInstance().loadMessages(dialog_id, 0, 30, 0, true, 0, classGuid, true, false);
MessagesController.getInstance().loadMessages(dialog_id, 30, 0, true, 0, classGuid, true, false);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
if (currentChat != null) {
@ -733,16 +734,16 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
if (firstVisibleItem <= 4) {
if (!endReached && !loading) {
if (messagesByDays.size() != 0) {
MessagesController.getInstance().loadMessages(dialog_id, 0, 20, maxMessageId, !cacheEndReaced, minDate, classGuid, false, false);
MessagesController.getInstance().loadMessages(dialog_id, 20, maxMessageId, !cacheEndReaced, minDate, classGuid, false, false);
} else {
MessagesController.getInstance().loadMessages(dialog_id, 0, 20, 0, !cacheEndReaced, minDate, classGuid, false, false);
MessagesController.getInstance().loadMessages(dialog_id, 20, 0, !cacheEndReaced, minDate, classGuid, false, false);
}
loading = true;
}
}
if (firstVisibleItem + visibleItemCount >= totalItemCount - 6) {
if (!unread_end_reached && !loadingForward) {
MessagesController.getInstance().loadMessages(dialog_id, 0, 20, minMessageId, true, maxDate, classGuid, false, true);
MessagesController.getInstance().loadMessages(dialog_id, 20, minMessageId, true, maxDate, classGuid, false, true);
loadingForward = true;
}
}
@ -865,9 +866,9 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
maxDate = Integer.MIN_VALUE;
minDate = 0;
unread_end_reached = true;
MessagesController.getInstance().loadMessages(dialog_id, 0, 30, 0, true, 0, classGuid, true, false);
loading = true;
chatAdapter.notifyDataSetChanged();
MessagesController.getInstance().loadMessages(dialog_id, 30, 0, true, 0, classGuid, true, false);
}
}
@ -1479,6 +1480,8 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
if (tempPath != null) {
File temp = new File(tempPath);
originalPath += temp.length() + "_" + temp.lastModified();
} else {
originalPath = null;
}
TLRPC.TL_photo photo = (TLRPC.TL_photo)MessagesStorage.getInstance().getSentFile(originalPath, currentEncryptedChat == null ? 0 : 3);
if (photo == null && uri != null) {
@ -1696,24 +1699,42 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
if (id == MessagesController.messagesDidLoaded) {
long did = (Long)args[0];
if (did == dialog_id) {
int offset = (Integer)args[1];
int count = (Integer)args[2];
boolean isCache = (Boolean)args[4];
int fnid = (Integer)args[5];
int last_unread_date = (Integer)args[8];
boolean forwardLoad = (Boolean)args[9];
int count = (Integer)args[1];
boolean isCache = (Boolean)args[3];
int fnid = (Integer)args[4];
int last_unread_date = (Integer)args[7];
boolean forwardLoad = (Boolean)args[8];
boolean wasUnread = false;
boolean positionToUnread = false;
if (fnid != 0) {
first_unread_id = (Integer)args[5];
last_unread_id = (Integer)args[6];
unread_to_load = (Integer)args[7];
first_unread_id = fnid;
last_unread_id = (Integer)args[5];
unread_to_load = (Integer)args[6];
positionToUnread = true;
}
ArrayList<MessageObject> messArr = (ArrayList<MessageObject>)args[3];
ArrayList<MessageObject> messArr = (ArrayList<MessageObject>)args[2];
int newRowsCount = 0;
unread_end_reached = last_unread_id == 0;
if (firstLoading) {
if (!unread_end_reached) {
messages.clear();
messagesByDays.clear();
messagesDict.clear();
if (currentEncryptedChat == null) {
maxMessageId = Integer.MAX_VALUE;
minMessageId = Integer.MIN_VALUE;
} else {
maxMessageId = Integer.MIN_VALUE;
minMessageId = Integer.MAX_VALUE;
}
maxDate = Integer.MIN_VALUE;
minDate = 0;
}
firstLoading = false;
}
for (int a = 0; a < messArr.size(); a++) {
MessageObject obj = messArr.get(a);
if (messagesDict.containsKey(obj.messageOwner.id)) {
@ -2042,15 +2063,17 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
lastVisible++;
}
if (lastVisible == oldCount) {
if (paused) {
scrollToTopOnResume = true;
} else {
chatListView.post(new Runnable() {
@Override
public void run() {
chatListView.setSelectionFromTop(messages.size() - 1, -100000 - chatListView.getPaddingTop());
}
});
if (!firstLoading) {
if (paused) {
scrollToTopOnResume = true;
} else {
chatListView.post(new Runnable() {
@Override
public void run() {
chatListView.setSelectionFromTop(messages.size() - 1, -100000 - chatListView.getPaddingTop());
}
});
}
}
} else {
showPagedownButton(true, true);
@ -2122,7 +2145,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
}
maxDate = Integer.MIN_VALUE;
minDate = 0;
MessagesController.getInstance().loadMessages(dialog_id, 0, 30, 0, !cacheEndReaced, minDate, classGuid, false, false);
MessagesController.getInstance().loadMessages(dialog_id, 30, 0, !cacheEndReaced, minDate, classGuid, false, false);
loading = true;
}
}
@ -2970,8 +2993,8 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
} else if (lower_part < 0) {
args.putInt("chat_id", -lower_part);
}
forwardSelectedMessages(did, param);
presentFragment(new ChatActivity(args), true);
forwardSelectedMessages(did, param);
removeSelfFromStack();
} else {
activity.finishFragment();