Bug fixes

This commit is contained in:
DrKLO 2014-10-23 19:30:35 +04:00
parent d03fa95568
commit abf8f6f619
17 changed files with 368 additions and 629 deletions

View file

@ -1,21 +1,30 @@
## Telegram messenger for Android
[Telegram](http://telegram.org) is a messaging app with a focus on speed and security. Its superfast, simple and free.
This repo contains the official source code for [Telegram App for Android](https://play.google.com/store/apps/details?id=org.telegram.messenger).
This repo contains official [Telegram App for Android](https://play.google.com/store/apps/details?id=org.telegram.messenger) source code.
##Creating your Telegram Application
We welcome all developers to use our API and source code to create applications on our platform.
There are several things we require from **all developers** for the moment.
1. [**Obtain your own api_id**](https://core.telegram.org/api/obtaining_api_id) for your application.
2. Please **do not** use the name Telegram for your app — or make sure your users understand that it is unofficial.
3. Kindly **do not** use our standard logo (white paper plane in a blue circle) as your app's logo.
3. Please study our [**security guidelines**](https://core.telegram.org/mtproto/security_guidelines) and take good care of your users' data and privacy.
4. Please remember to publish **your** code too in order to comply with the licences.
### API, Protocol documentation
Documentation for Telegram API is available here: http://core.telegram.org/api
Telegram API manuals: http://core.telegram.org/api
Documentation for MTproto protocol is available here: http://core.telegram.org/mtproto
MTproto protocol manuals: http://core.telegram.org/mtproto
### Usage
**Beware of using dev branch and uploading it to any markets, in most cases it will work as you expecting**
First of all your should take a look to **src/main/java/org/telegram/messenger/BuildVars.java** and fill it with correct values.
**Beware of using the dev branch and uploading it to any markets, in many cases it not will work as expected**.
First of all, take a look at **src/main/java/org/telegram/messenger/BuildVars.java** and fill it with correct values.
Import the root folder into your IDE (tested on Android Studio), then run project.
### Localization

View file

@ -25,7 +25,7 @@ dependencies {
android {
compileSdkVersion 21
buildToolsVersion '21.0.1'
buildToolsVersion '21.0.2'
signingConfigs {
debug {
@ -80,7 +80,7 @@ android {
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 372
versionCode 374
versionName "1.9.6"
}
}

View file

@ -218,7 +218,7 @@ public class AndroidUtilities {
}
public static File getCacheDir() {
if (Environment.getExternalStorageState().startsWith(Environment.MEDIA_MOUNTED)) {
if (Environment.getExternalStorageState() == null || Environment.getExternalStorageState().startsWith(Environment.MEDIA_MOUNTED)) {
try {
File file = ApplicationLoader.applicationContext.getExternalCacheDir();
if (file != null) {

View file

@ -1711,7 +1711,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
public void markMessageAsRead(final long dialog_id, final long random_id, int ttl) {
if (random_id == 0 || dialog_id == 0) {
if (random_id == 0 || dialog_id == 0 || ttl <= 0) {
return;
}
int lower_part = (int)dialog_id;
@ -1726,10 +1726,8 @@ public class MessagesController implements NotificationCenter.NotificationCenter
ArrayList<Long> random_ids = new ArrayList<Long>();
random_ids.add(random_id);
SendMessagesHelper.getInstance().sendMessagesReadMessage(chat, random_ids, null);
if (ttl > 0) {
int time = ConnectionsManager.getInstance().getCurrentTime();
MessagesStorage.getInstance().createTaskForSecretChat(chat.id, time, time, 0, random_ids);
}
int time = ConnectionsManager.getInstance().getCurrentTime();
MessagesStorage.getInstance().createTaskForSecretChat(chat.id, time, time, 0, random_ids);
}
public void markDialogAsRead(final long dialog_id, final int max_id, final int max_positive_id, final int offset, final int max_date, final boolean was, final boolean popup) {

View file

@ -499,58 +499,15 @@ public class MessagesStorage {
cursor.dispose();
if (!encryptedChatIds.isEmpty()) {
String stringToLoad = TextUtils.join(",", encryptedChatIds);
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, user, g, authkey, ttl, layer, seq_in, seq_out FROM enc_chats WHERE uid IN(%s)", stringToLoad));
while (cursor.next()) {
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.EncryptedChat chat = (TLRPC.EncryptedChat)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
encryptedChats.add(chat);
chat.user_id = cursor.intValue(1);
if (!userIds.contains(chat.user_id)) {
userIds.add(chat.user_id);
}
chat.a_or_b = cursor.byteArrayValue(2);
chat.auth_key = cursor.byteArrayValue(3);
chat.ttl = cursor.intValue(4);
chat.layer = cursor.intValue(5);
chat.seq_in = cursor.intValue(6);
chat.seq_out = cursor.intValue(7);
}
buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
getEncryptedChatsInternal(TextUtils.join(",", encryptedChatIds), encryptedChats, userIds);
}
if (!userIds.isEmpty()) {
String stringToLoad = TextUtils.join(",", userIds);
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, status FROM users WHERE uid IN(%s)", stringToLoad));
while (cursor.next()) {
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.User user = (TLRPC.User) TLClassStore.Instance().TLdeserialize(data, data.readInt32());
if (user.status != null) {
user.status.expires = cursor.intValue(1);
}
users.add(user);
}
buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
getUsersInternal(TextUtils.join(",", userIds), users);
}
if (!chatIds.isEmpty()) {
String stringToLoad = TextUtils.join(",", chatIds);
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data FROM chats WHERE uid IN(%s)", stringToLoad));
while (cursor.next()) {
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.Chat chat = (TLRPC.Chat) TLClassStore.Instance().TLdeserialize(data, data.readInt32());
chats.add(chat);
}
buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
getChatsInternal(TextUtils.join(",", chatIds), chats);
}
}
Collections.reverse(messages);
@ -639,19 +596,7 @@ public class MessagesStorage {
cursor.dispose();
if (usersToLoad.length() != 0) {
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, status FROM users WHERE uid IN(%s)", usersToLoad.toString()));
while (cursor.next()) {
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.User user = (TLRPC.User)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
users.add(user);
if (user.status != null) {
user.status.expires = cursor.intValue(1);
}
}
buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
getUsersInternal(usersToLoad.toString(), users);
}
MessagesController.getInstance().processLoadedBlockedUsers(ids, users, true);
@ -872,8 +817,12 @@ public class MessagesStorage {
cursor = database.queryFinalized(String.format(Locale.US, "SELECT m.mid, m.ttl FROM messages as m INNER JOIN randoms as r ON m.mid = r.mid WHERE r.random_id IN (%s)", ids));
}
while (cursor.next()) {
int ttl = cursor.intValue(1);
if (ttl <= 0) {
continue;
}
int mid = cursor.intValue(0);
int date = Math.min(readTime, time) + cursor.intValue(1);
int date = Math.min(readTime, time) + ttl;
minDate = Math.min(minDate, date);
ArrayList<Integer> arr = messages.get(date);
if (arr == null) {
@ -1126,19 +1075,7 @@ public class MessagesStorage {
}
}
if (usersToLoad.length() != 0) {
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, status FROM users WHERE uid IN(%s)", usersToLoad.toString()));
while (cursor.next()) {
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.User user = (TLRPC.User)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
loadedUsers.add(user);
if (user.status != null) {
user.status.expires = cursor.intValue(1);
}
}
buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
getUsersInternal(usersToLoad.toString(), loadedUsers);
}
if (modified) {
updateChatInfo(chat_id, info, false);
@ -1225,7 +1162,18 @@ public class MessagesStorage {
SQLiteCursor cursor = database.queryFinalized("SELECT u.data, u.status, u.name FROM users as u INNER JOIN contacts as c ON u.uid = c.uid");
while (cursor.next()) {
String name = cursor.stringValue(2);
String username = null;
int usernamePos = name.lastIndexOf(";;;");
if (usernamePos != -1) {
username = name.substring(usernamePos + 3);
}
int found = 0;
if (name.startsWith(q) || name.contains(" " + q)) {
found = 1;
} else if (username != null && username.startsWith(q)) {
found = 2;
}
if (found != 0) {
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.User user = (TLRPC.User)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
@ -1233,7 +1181,11 @@ public class MessagesStorage {
if (user.status != null) {
user.status.expires = cursor.intValue(1);
}
resultArrayNames.add(Utilities.generateSearchName(user.first_name, user.last_name, q));
if (found == 1) {
resultArrayNames.add(Utilities.generateSearchName(user.first_name, user.last_name, q));
} else {
resultArrayNames.add(Utilities.generateSearchName("@" + user.username, null, "@" + q));
}
resultArray.add(user);
}
}
@ -1246,7 +1198,20 @@ public class MessagesStorage {
cursor = database.queryFinalized("SELECT q.data, u.name, q.user, q.g, q.authkey, q.ttl, u.data, u.status, q.layer, q.seq_in, q.seq_out FROM enc_chats as q INNER JOIN dialogs as d ON (q.uid << 32) = d.did INNER JOIN users as u ON q.user = u.uid");
while (cursor.next()) {
String name = cursor.stringValue(1);
String username = null;
int usernamePos = name.lastIndexOf(";;;");
if (usernamePos != -1) {
username = name.substring(usernamePos + 2);
}
int found = 0;
if (name.startsWith(q) || name.contains(" " + q)) {
found = 1;
} else if (username != null && username.startsWith(q)) {
found = 2;
}
if (found != 0) {
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
ByteBufferDesc data2 = buffersStorage.getFreeBuffer(cursor.byteArrayLength(6));
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0 && cursor.byteBufferValue(6, data2.buffer) != 0) {
@ -1263,7 +1228,11 @@ public class MessagesStorage {
if (user.status != null) {
user.status.expires = cursor.intValue(7);
}
resultArrayNames.add(Html.fromHtml("<font color=\"#00a60e\">" + ContactsController.formatName(user.first_name, user.last_name) + "</font>"));
if (found == 1) {
resultArrayNames.add(Html.fromHtml("<font color=\"#00a60e\">" + ContactsController.formatName(user.first_name, user.last_name) + "</font>"));
} else {
resultArrayNames.add(Utilities.generateSearchName("@" + user.username, null, "@" + q));
}
resultArray.add(chat);
encUsers.add(user);
}
@ -1473,19 +1442,7 @@ public class MessagesStorage {
cursor.dispose();
if (uids.length() != 0) {
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, status FROM users WHERE uid IN(%s)", uids.toString()));
while (cursor.next()) {
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.User user = (TLRPC.User)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
users.add(user);
if (user.status != null) {
user.status.expires = cursor.intValue(1);
}
}
buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
getUsersInternal(uids.toString(), users);
}
} catch (Exception e) {
contacts.clear();
@ -1597,20 +1554,7 @@ public class MessagesStorage {
}
}
if (usersToLoad.length() != 0) {
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, status FROM users WHERE uid IN(%s)", usersToLoad.toString()));
while (cursor.next()) {
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.User user = (TLRPC.User)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
loadedUsers.add(user.id);
if (user.status != null) {
user.status.expires = cursor.intValue(1);
}
res.users.add(user);
}
buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
getUsersInternal(usersToLoad.toString(), res.users);
}
} catch (Exception e) {
res.messages.clear();
@ -1737,45 +1681,11 @@ public class MessagesStorage {
if (!encryptedChatIds.isEmpty()) {
String stringToLoad = TextUtils.join(",", encryptedChatIds);
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, user, g, authkey, ttl, layer, seq_in, seq_out FROM enc_chats WHERE uid IN(%s)", stringToLoad));
while (cursor.next()) {
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.EncryptedChat chat = (TLRPC.EncryptedChat)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
encryptedChats.add(chat);
chat.user_id = cursor.intValue(1);
if (!userIds.contains(chat.user_id)) {
userIds.add(chat.user_id);
}
chat.a_or_b = cursor.byteArrayValue(2);
chat.auth_key = cursor.byteArrayValue(3);
chat.ttl = cursor.intValue(4);
chat.layer = cursor.intValue(5);
chat.seq_in = cursor.intValue(6);
chat.seq_out = cursor.intValue(7);
}
buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
getEncryptedChatsInternal(TextUtils.join(",", encryptedChatIds), encryptedChats, userIds);
}
if (!userIds.isEmpty()) {
String stringToLoad = TextUtils.join(",", userIds);
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, status FROM users WHERE uid IN(%s)", stringToLoad));
while (cursor.next()) {
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.User user = (TLRPC.User) TLClassStore.Instance().TLdeserialize(data, data.readInt32());
if (user.status != null) {
user.status.expires = cursor.intValue(1);
}
users.add(user);
}
buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
getUsersInternal(TextUtils.join(",", userIds), users);
}
if (!chatIds.isEmpty() || !broadcastIds.isEmpty()) {
@ -1792,16 +1702,7 @@ public class MessagesStorage {
}
stringToLoad.append(-cid);
}
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data FROM chats WHERE uid IN(%s)", stringToLoad.toString()));
while (cursor.next()) {
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.Chat chat = (TLRPC.Chat) TLClassStore.Instance().TLdeserialize(data, data.readInt32());
chats.add(chat);
}
buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
getChatsInternal(stringToLoad.toString(), chats);
}
SendMessagesHelper.getInstance().processUnsentMessages(messages, users, chats, encryptedChats);
@ -2017,20 +1918,7 @@ public class MessagesStorage {
}
}
if (usersToLoad.length() != 0) {
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, status FROM users WHERE uid IN(%s)", usersToLoad.toString()));
while (cursor.next()) {
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.User user = (TLRPC.User)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
loadedUsers.add(user.id);
if (user.status != null) {
user.status.expires = cursor.intValue(1);
}
res.users.add(user);
}
buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
getUsersInternal(usersToLoad.toString(), res.users);
}
} catch (Exception e) {
res.messages.clear();
@ -2270,42 +2158,15 @@ public class MessagesStorage {
@Override
public void run() {
try {
int userToLoad = 0;
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, user, g, authkey, ttl, layer, seq_in, seq_out FROM enc_chats WHERE uid = %d", chat_id));
if (cursor.next()) {
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.EncryptedChat chat = (TLRPC.EncryptedChat)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
result.add(chat);
chat.user_id = cursor.intValue(1);
userToLoad = chat.user_id;
chat.a_or_b = cursor.byteArrayValue(2);
chat.auth_key = cursor.byteArrayValue(3);
chat.ttl = cursor.intValue(4);
chat.layer = cursor.intValue(5);
chat.seq_in = cursor.intValue(6);
chat.seq_out = cursor.intValue(7);
}
buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
if (userToLoad != 0) {
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, status FROM users WHERE uid = %d", userToLoad));
if (cursor.next()) {
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.User user = (TLRPC.User)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
if (user.status != null) {
user.status.expires = cursor.intValue(1);
}
result.add(user);
}
buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
if (result.size() != 2) {
result.clear();
ArrayList<Integer> usersToLoad = new ArrayList<Integer>();
ArrayList<TLRPC.EncryptedChat> encryptedChats = new ArrayList<TLRPC.EncryptedChat>();
getEncryptedChatsInternal("" + chat_id, encryptedChats, usersToLoad);
if (!encryptedChats.isEmpty() && !usersToLoad.isEmpty()) {
ArrayList<TLRPC.User> users = new ArrayList<TLRPC.User>();
getUsersInternal(TextUtils.join(",", usersToLoad), users);
if (!users.isEmpty()) {
result.add(encryptedChats.get(0));
result.add(users.get(0));
}
}
} catch (Exception e) {
@ -2333,12 +2194,7 @@ public class MessagesStorage {
chat.serializeToStream(data);
state.bindInteger(1, chat.id);
state.bindInteger(2, user.id);
if (user.first_name != null && user.last_name != null) {
String name = (user.first_name + " " + user.last_name).toLowerCase();
state.bindString(3, name);
} else {
state.bindString(3, "");
}
state.bindString(3, formatUserSearchName(user));
state.bindByteBuffer(4, data.buffer);
if (chat.a_or_b != null) {
data2.writeRaw(chat.a_or_b);
@ -2374,54 +2230,157 @@ public class MessagesStorage {
});
}
private String formatUserSearchName(TLRPC.User user) {
StringBuilder str = new StringBuilder("");
if (user.first_name != null && user.first_name.length() > 0) {
str.append(user.first_name);
}
if (user.last_name != null && user.last_name.length() > 0) {
if (str.length() > 0) {
str.append(" ");
}
str.append(user.last_name);
}
str.append(";;;");
if (user.username != null && user.username.length() > 0) {
str.append(user.username);
}
return str.toString().toLowerCase();
}
private void putUsersInternal(ArrayList<TLRPC.User> users) throws Exception {
if (users == null || users.isEmpty()) {
return;
}
SQLitePreparedStatement state = database.executeFast("REPLACE INTO users VALUES(?, ?, ?, ?)");
for (TLRPC.User user : users) {
state.requery();
ByteBufferDesc data = buffersStorage.getFreeBuffer(user.getObjectSize());
user.serializeToStream(data);
state.bindInteger(1, user.id);
state.bindString(2, formatUserSearchName(user));
if (user.status != null) {
state.bindInteger(3, user.status.expires);
} else {
state.bindInteger(3, 0);
}
state.bindByteBuffer(4, data.buffer);
state.step();
buffersStorage.reuseFreeBuffer(data);
}
state.dispose();
}
private void putChatsInternal(ArrayList<TLRPC.Chat> chats) throws Exception {
if (chats == null || chats.isEmpty()) {
return;
}
SQLitePreparedStatement state = database.executeFast("REPLACE INTO chats VALUES(?, ?, ?)");
for (TLRPC.Chat chat : chats) {
state.requery();
ByteBufferDesc data = buffersStorage.getFreeBuffer(chat.getObjectSize());
chat.serializeToStream(data);
state.bindInteger(1, chat.id);
if (chat.title != null) {
String name = chat.title.toLowerCase();
state.bindString(2, name);
} else {
state.bindString(2, "");
}
state.bindByteBuffer(3, data.buffer);
state.step();
buffersStorage.reuseFreeBuffer(data);
}
state.dispose();
}
private void getUsersInternal(String usersToLoad, ArrayList<TLRPC.User> result) throws Exception {
if (usersToLoad == null || usersToLoad.length() == 0 || result == null) {
return;
}
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, status FROM users WHERE uid IN(%s)", usersToLoad));
while (cursor.next()) {
try {
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.User user = (TLRPC.User)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
if (user != null) {
if (user.status != null) {
user.status.expires = cursor.intValue(1);
}
result.add(user);
}
}
buffersStorage.reuseFreeBuffer(data);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
cursor.dispose();
}
private void getChatsInternal(String chatsToLoad, ArrayList<TLRPC.Chat> result) throws Exception {
if (chatsToLoad == null || chatsToLoad.length() == 0 || result == null) {
return;
}
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT data FROM chats WHERE uid IN(%s)", chatsToLoad));
while (cursor.next()) {
try {
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.Chat chat = (TLRPC.Chat)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
if (chat != null) {
result.add(chat);
}
}
buffersStorage.reuseFreeBuffer(data);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
cursor.dispose();
}
private void getEncryptedChatsInternal(String chatsToLoad, ArrayList<TLRPC.EncryptedChat> result, ArrayList<Integer> usersToLoad) throws Exception {
if (chatsToLoad == null || chatsToLoad.length() == 0 || result == null) {
return;
}
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, user, g, authkey, ttl, layer, seq_in, seq_out FROM enc_chats WHERE uid IN(%s)", chatsToLoad));
while (cursor.next()) {
try {
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.EncryptedChat chat = (TLRPC.EncryptedChat)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
if (chat != null) {
chat.user_id = cursor.intValue(1);
if (usersToLoad != null && !usersToLoad.contains(chat.user_id)) {
usersToLoad.add(chat.user_id);
}
chat.a_or_b = cursor.byteArrayValue(2);
chat.auth_key = cursor.byteArrayValue(3);
chat.ttl = cursor.intValue(4);
chat.layer = cursor.intValue(5);
chat.seq_in = cursor.intValue(6);
chat.seq_out = cursor.intValue(7);
result.add(chat);
}
}
buffersStorage.reuseFreeBuffer(data);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
cursor.dispose();
}
private void putUsersAndChatsInternal(final ArrayList<TLRPC.User> users, final ArrayList<TLRPC.Chat> chats, final boolean withTransaction) {
try {
if (withTransaction) {
database.beginTransaction();
}
if (users != null && !users.isEmpty()) {
SQLitePreparedStatement state = database.executeFast("REPLACE INTO users VALUES(?, ?, ?, ?)");
for (TLRPC.User user : users) {
state.requery();
ByteBufferDesc data = buffersStorage.getFreeBuffer(user.getObjectSize());
user.serializeToStream(data);
state.bindInteger(1, user.id);
if (user.first_name != null && user.last_name != null) {
String name = (user.first_name + " " + user.last_name).toLowerCase();
state.bindString(2, name);
} else {
state.bindString(2, "");
}
if (user.status != null) {
state.bindInteger(3, user.status.expires);
} else {
state.bindInteger(3, 0);
}
state.bindByteBuffer(4, data.buffer);
state.step();
buffersStorage.reuseFreeBuffer(data);
}
state.dispose();
}
if (chats != null && !chats.isEmpty()) {
SQLitePreparedStatement state = database.executeFast("REPLACE INTO chats VALUES(?, ?, ?)");
for (TLRPC.Chat chat : chats) {
state.requery();
ByteBufferDesc data = buffersStorage.getFreeBuffer(chat.getObjectSize());
chat.serializeToStream(data);
state.bindInteger(1, chat.id);
if (chat.title != null) {
String name = chat.title.toLowerCase();
state.bindString(2, name);
} else {
state.bindString(2, "");
}
state.bindByteBuffer(3, data.buffer);
state.step();
buffersStorage.reuseFreeBuffer(data);
}
state.dispose();
}
putUsersInternal(users);
putChatsInternal(chats);
if (withTransaction) {
database.commitTransaction();
}
@ -2999,16 +2958,10 @@ public class MessagesStorage {
usersDict.put(user.id, user);
}
ArrayList<TLRPC.User> loadedUsers = new ArrayList<TLRPC.User>();
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, status FROM users WHERE uid IN(%s)", ids.toString()));
while (cursor.next()) {
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.User user = (TLRPC.User)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
loadedUsers.add(user);
if (user.status != null) {
user.status.expires = cursor.intValue(1);
}
TLRPC.User updateUser = usersDict.get(user.id);
getUsersInternal(ids.toString(), loadedUsers);
for (TLRPC.User user : loadedUsers) {
TLRPC.User updateUser = usersDict.get(user.id);
if (updateUser != null) {
if (updateUser.first_name != null && updateUser.last_name != null) {
user.first_name = updateUser.first_name;
user.last_name = updateUser.last_name;
@ -3017,35 +2970,13 @@ public class MessagesStorage {
user.photo = updateUser.photo;
}
}
buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
if (!loadedUsers.isEmpty()) {
if (withTransaction) {
database.beginTransaction();
}
SQLitePreparedStatement state = database.executeFast("REPLACE INTO users VALUES(?, ?, ?, ?)");
for (TLRPC.User user : loadedUsers) {
state.requery();
ByteBufferDesc data = buffersStorage.getFreeBuffer(user.getObjectSize());
user.serializeToStream(data);
state.bindInteger(1, user.id);
if (user.first_name != null && user.last_name != null) {
String name = (user.first_name + " " + user.last_name).toLowerCase();
state.bindString(2, name);
} else {
state.bindString(2, "");
}
if (user.status != null) {
state.bindInteger(3, user.status.expires);
} else {
state.bindInteger(3, 0);
}
state.bindByteBuffer(4, data.buffer);
state.step();
buffersStorage.reuseFreeBuffer(data);
}
state.dispose();
putUsersInternal(loadedUsers);
if (withTransaction) {
database.commitTransaction();
}
@ -3308,58 +3239,15 @@ public class MessagesStorage {
cursor.dispose();
if (!encryptedToLoad.isEmpty()) {
String toLoad = TextUtils.join(",", encryptedToLoad);
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, user, g, authkey, ttl, layer, seq_in, seq_out FROM enc_chats WHERE uid IN(%s)", toLoad));
while (cursor.next()) {
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.EncryptedChat chat = (TLRPC.EncryptedChat)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
encryptedChats.add(chat);
chat.user_id = cursor.intValue(1);
if (!usersToLoad.contains(chat.user_id)) {
usersToLoad.add(chat.user_id);
}
chat.a_or_b = cursor.byteArrayValue(2);
chat.auth_key = cursor.byteArrayValue(3);
chat.ttl = cursor.intValue(4);
chat.layer = cursor.intValue(5);
chat.seq_in = cursor.intValue(6);
chat.seq_out = cursor.intValue(7);
}
buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
getEncryptedChatsInternal(TextUtils.join(",", encryptedToLoad), encryptedChats, usersToLoad);
}
if (!chatsToLoad.isEmpty()) {
String toLoad = TextUtils.join(",", chatsToLoad);
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data FROM chats WHERE uid IN(%s)", toLoad));
while (cursor.next()) {
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.Chat chat = (TLRPC.Chat)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
dialogs.chats.add(chat);
}
buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
getChatsInternal(TextUtils.join(",", chatsToLoad), dialogs.chats);
}
if (!usersToLoad.isEmpty()) {
String toLoad = TextUtils.join(",", usersToLoad);
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, status FROM users WHERE uid IN(%s)", toLoad));
while (cursor.next()) {
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.User user = (TLRPC.User)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
if (user.status != null) {
user.status.expires = cursor.intValue(1);
}
dialogs.users.add(user);
}
buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
getUsersInternal(TextUtils.join(",", usersToLoad), dialogs.users);
}
if (!dialogs.dialogs.isEmpty() || !encryptedChats.isEmpty()) {
@ -3442,49 +3330,8 @@ public class MessagesStorage {
state.dispose();
state2.dispose();
}
if (!messages.users.isEmpty()) {
SQLitePreparedStatement state = database.executeFast("REPLACE INTO users VALUES(?, ?, ?, ?)");
for (TLRPC.User user : messages.users) {
state.requery();
ByteBufferDesc data = buffersStorage.getFreeBuffer(user.getObjectSize());
user.serializeToStream(data);
state.bindInteger(1, user.id);
if (user.first_name != null && user.last_name != null) {
String name = (user.first_name + " " + user.last_name).toLowerCase();
state.bindString(2, name);
} else {
state.bindString(2, "");
}
if (user.status != null) {
state.bindInteger(3, user.status.expires);
} else {
state.bindInteger(3, 0);
}
state.bindByteBuffer(4, data.buffer);
state.step();
buffersStorage.reuseFreeBuffer(data);
}
state.dispose();
}
if (!messages.chats.isEmpty()) {
SQLitePreparedStatement state = database.executeFast("REPLACE INTO chats VALUES(?, ?, ?)");
for (TLRPC.Chat chat : messages.chats) {
state.requery();
ByteBufferDesc data = buffersStorage.getFreeBuffer(chat.getObjectSize());
chat.serializeToStream(data);
state.bindInteger(1, chat.id);
if (chat.title != null) {
String name = chat.title.toLowerCase();
state.bindString(2, name);
} else {
state.bindString(2, "");
}
state.bindByteBuffer(3, data.buffer);
state.step();
buffersStorage.reuseFreeBuffer(data);
}
state.dispose();
}
putUsersInternal(messages.users);
putChatsInternal(messages.chats);
database.commitTransaction();
} catch (Exception e) {
@ -3567,76 +3414,15 @@ public class MessagesStorage {
cursor.dispose();
if (!encryptedToLoad.isEmpty()) {
String toLoad = TextUtils.join(",", encryptedToLoad);
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, user, g, authkey, ttl, layer, seq_in, seq_out FROM enc_chats WHERE uid IN(%s)", toLoad));
while (cursor.next()) {
try {
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.EncryptedChat chat = (TLRPC.EncryptedChat)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
if (chat != null) {
encryptedChats.add(chat);
chat.user_id = cursor.intValue(1);
if (!usersToLoad.contains(chat.user_id)) {
usersToLoad.add(chat.user_id);
}
chat.a_or_b = cursor.byteArrayValue(2);
chat.auth_key = cursor.byteArrayValue(3);
chat.ttl = cursor.intValue(4);
chat.layer = cursor.intValue(5);
chat.seq_in = cursor.intValue(6);
chat.seq_out = cursor.intValue(7);
}
}
buffersStorage.reuseFreeBuffer(data);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
cursor.dispose();
getEncryptedChatsInternal(TextUtils.join(",", encryptedToLoad), encryptedChats, usersToLoad);
}
if (!chatsToLoad.isEmpty()) {
String toLoad = TextUtils.join(",", chatsToLoad);
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data FROM chats WHERE uid IN(%s)", toLoad));
while (cursor.next()) {
try {
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.Chat chat = (TLRPC.Chat)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
if (chat != null) {
dialogs.chats.add(chat);
}
}
buffersStorage.reuseFreeBuffer(data);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
cursor.dispose();
getChatsInternal(TextUtils.join(",", chatsToLoad), dialogs.chats);
}
if (!usersToLoad.isEmpty()) {
String toLoad = TextUtils.join(",", usersToLoad);
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, status FROM users WHERE uid IN(%s)", toLoad));
while (cursor.next()) {
try {
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.User user = (TLRPC.User)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
if (user != null) {
if (user.status != null) {
user.status.expires = cursor.intValue(1);
}
dialogs.users.add(user);
}
}
buffersStorage.reuseFreeBuffer(data);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
cursor.dispose();
getUsersInternal(TextUtils.join(",", usersToLoad), dialogs.users);
}
MessagesController.getInstance().processLoadedDialogs(dialogs, encryptedChats, offset, serverOffset, count, true, false);
} catch (Exception e) {
@ -3725,50 +3511,8 @@ public class MessagesStorage {
state4.dispose();
}
if (!dialogs.users.isEmpty()) {
SQLitePreparedStatement state = database.executeFast("REPLACE INTO users VALUES(?, ?, ?, ?)");
for (TLRPC.User user : dialogs.users) {
state.requery();
ByteBufferDesc data = buffersStorage.getFreeBuffer(user.getObjectSize());
user.serializeToStream(data);
state.bindInteger(1, user.id);
if (user.first_name != null && user.last_name != null) {
String name = (user.first_name + " " + user.last_name).toLowerCase();
state.bindString(2, name);
} else {
state.bindString(2, "");
}
if (user.status != null) {
state.bindInteger(3, user.status.expires);
} else {
state.bindInteger(3, 0);
}
state.bindByteBuffer(4, data.buffer);
state.step();
buffersStorage.reuseFreeBuffer(data);
}
state.dispose();
}
if (!dialogs.chats.isEmpty()) {
SQLitePreparedStatement state = database.executeFast("REPLACE INTO chats VALUES(?, ?, ?)");
for (TLRPC.Chat chat : dialogs.chats) {
state.requery();
ByteBufferDesc data = buffersStorage.getFreeBuffer(chat.getObjectSize());
chat.serializeToStream(data);
state.bindInteger(1, chat.id);
if (chat.title != null) {
String name = chat.title.toLowerCase();
state.bindString(2, name);
} else {
state.bindString(2, "");
}
state.bindByteBuffer(3, data.buffer);
state.step();
buffersStorage.reuseFreeBuffer(data);
}
state.dispose();
}
putUsersInternal(dialogs.users);
putChatsInternal(dialogs.chats);
database.commitTransaction();
@ -3783,56 +3527,23 @@ public class MessagesStorage {
public TLRPC.User getUser(final int user_id) {
TLRPC.User user = null;
try {
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, status FROM users WHERE uid = %d", user_id));
if (cursor.next()) {
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
user = (TLRPC.User) TLClassStore.Instance().TLdeserialize(data, data.readInt32());
if (user != null) {
if (user.status != null) {
user.status.expires = cursor.intValue(1);
}
}
}
buffersStorage.reuseFreeBuffer(data);
ArrayList<TLRPC.User> users = new ArrayList<TLRPC.User>();
getUsersInternal("" + user_id, users);
if (!users.isEmpty()) {
user = users.get(0);
}
cursor.dispose();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
return user;
}
public ArrayList<TLRPC.User> getUsers(final ArrayList<Integer> uids, final boolean[] error) {
public ArrayList<TLRPC.User> getUsers(final ArrayList<Integer> uids) {
ArrayList<TLRPC.User> users = new ArrayList<TLRPC.User>();
try {
String uidsStr = TextUtils.join(",", uids);
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, status FROM users WHERE uid IN (%s)", uidsStr));
while (cursor.next()) {
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.User user = (TLRPC.User) TLClassStore.Instance().TLdeserialize(data, data.readInt32());
if (user != null) {
if (user.status != null) {
user.status.expires = cursor.intValue(1);
}
users.add(user);
} else {
error[0] = true;
buffersStorage.reuseFreeBuffer(data);
break;
}
} else {
error[0] = true;
buffersStorage.reuseFreeBuffer(data);
break;
}
buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
getUsersInternal(TextUtils.join(",", uids), users);
} catch (Exception e) {
error[0] = true;
users.clear();
FileLog.e("tmessages", e);
}
return users;
@ -3841,15 +3552,11 @@ public class MessagesStorage {
public TLRPC.Chat getChat(final int chat_id) {
TLRPC.Chat chat = null;
try {
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT data FROM chats WHERE uid = %d", chat_id));
if (cursor.next()) {
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
chat = (TLRPC.Chat) TLClassStore.Instance().TLdeserialize(data, data.readInt32());
}
buffersStorage.reuseFreeBuffer(data);
ArrayList<TLRPC.Chat> chats = new ArrayList<TLRPC.Chat>();
getChatsInternal("" + chat_id, chats);
if (!chats.isEmpty()) {
chat = chats.get(0);
}
cursor.dispose();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
@ -3859,24 +3566,11 @@ public class MessagesStorage {
public TLRPC.EncryptedChat getEncryptedChat(final int chat_id) {
TLRPC.EncryptedChat chat = null;
try {
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, user, g, authkey, ttl, layer, seq_in, seq_out FROM enc_chats WHERE uid = %d", chat_id));
if (cursor.next()) {
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
chat = (TLRPC.EncryptedChat) TLClassStore.Instance().TLdeserialize(data, data.readInt32());
if (chat != null) {
chat.user_id = cursor.intValue(1);
chat.a_or_b = cursor.byteArrayValue(2);
chat.auth_key = cursor.byteArrayValue(3);
chat.ttl = cursor.intValue(4);
chat.layer = cursor.intValue(5);
chat.seq_in = cursor.intValue(6);
chat.seq_out = cursor.intValue(7);
}
}
buffersStorage.reuseFreeBuffer(data);
ArrayList<TLRPC.EncryptedChat> encryptedChats = new ArrayList<TLRPC.EncryptedChat>();
getEncryptedChatsInternal("" + chat_id, encryptedChats, null);
if (!encryptedChats.isEmpty()) {
chat = encryptedChats.get(0);
}
cursor.dispose();
} catch (Exception e) {
FileLog.e("tmessages", e);
}

View file

@ -626,10 +626,12 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
newMsg.to_id.user_id = encryptedChat.participant_id;
}
newMsg.ttl = encryptedChat.ttl;
if (newMsg.media instanceof TLRPC.TL_messageMediaAudio) {
newMsg.ttl = Math.max(encryptedChat.ttl, newMsg.media.audio.duration + 1);
} else if (newMsg.media instanceof TLRPC.TL_messageMediaVideo) {
newMsg.ttl = Math.max(encryptedChat.ttl, newMsg.media.video.duration + 1);
if (newMsg.ttl != 0) {
if (newMsg.media instanceof TLRPC.TL_messageMediaAudio) {
newMsg.ttl = Math.max(encryptedChat.ttl, newMsg.media.audio.duration + 1);
} else if (newMsg.media instanceof TLRPC.TL_messageMediaVideo) {
newMsg.ttl = Math.max(encryptedChat.ttl, newMsg.media.video.duration + 1);
}
}
}

View file

@ -99,12 +99,25 @@ public class ContactsActivitySearchAdapter extends BaseContactsSearchAdapter {
for (TLRPC.TL_contact contact : contactsCopy) {
TLRPC.User user = MessagesController.getInstance().getUser(contact.user_id);
if (user.id == UserConfig.getClientUserId()) {
continue;
}
String name = ContactsController.formatName(user.first_name, user.last_name).toLowerCase();
int found = 0;
if (name.startsWith(q) || name.contains(" " + q)) {
if (user.id == UserConfig.getClientUserId()) {
continue;
found = 1;
} else if (user.username != null && user.username.startsWith(q)) {
found = 2;
}
if (found != 0) {
if (found == 1) {
resultArrayNames.add(Utilities.generateSearchName(user.first_name, user.last_name, q));
} else {
resultArrayNames.add(Utilities.generateSearchName("@" + user.username, null, "@" + q));
}
resultArrayNames.add(Utilities.generateSearchName(user.first_name, user.last_name, q));
resultArray.add(user);
}
}
@ -197,7 +210,16 @@ public class ContactsActivitySearchAdapter extends BaseContactsSearchAdapter {
TLRPC.User user = getItem(i);
if (user != null) {
CharSequence username = null;
if (i > searchResult.size() && user.username != null) {
CharSequence name = null;
if (i < searchResult.size()) {
name = searchResultNames.get(i);
if (name != null && user != null && user.username != null && user.username.length() > 0) {
if (name.toString().startsWith("@" + user.username)) {
username = name;
name = null;
}
}
} else if (i > searchResult.size() && user.username != null) {
try {
username = Html.fromHtml(String.format("<font color=\"#357aa8\">@%s</font>%s", user.username.substring(0, lastFoundUsername.length()), user.username.substring(lastFoundUsername.length())));
} catch (Exception e) {
@ -206,7 +228,7 @@ public class ContactsActivitySearchAdapter extends BaseContactsSearchAdapter {
}
}
((ChatOrUserCell) view).setData(user, null, null, i < searchResult.size() ? searchResultNames.get(i) : null, username);
((ChatOrUserCell) view).setData(user, null, null, name, username);
if (ignoreUsers != null) {
if (ignoreUsers.containsKey(user.id)) {

View file

@ -1040,7 +1040,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
}
private boolean sendSecretMessageRead(MessageObject messageObject) {
if (messageObject == null || messageObject.isOut() || !messageObject.isSecretMedia() || messageObject.messageOwner.destroyTime != 0) {
if (messageObject == null || messageObject.isOut() || !messageObject.isSecretMedia() || messageObject.messageOwner.destroyTime != 0 || messageObject.messageOwner.ttl <= 0) {
return false;
}
MessagesController.getInstance().markMessageAsRead(dialog_id, messageObject.messageOwner.random_id, messageObject.messageOwner.ttl);

View file

@ -477,7 +477,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
args.putBoolean("destroyAfterSelect", true);
args.putBoolean("usersAsSections", true);
args.putBoolean("returnAsResult", true);
args.putBoolean("allowUsernameSearch", false);
//args.putBoolean("allowUsernameSearch", false);
if (chat_id > 0) {
args.putString("selectAlertString", LocaleController.getString("AddToTheGroup", R.string.AddToTheGroup));
}

View file

@ -82,11 +82,10 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
if (!usersToLoad.isEmpty()) {
final Semaphore semaphore = new Semaphore(0);
final ArrayList<TLRPC.User> users = new ArrayList<TLRPC.User>();
final boolean[] error = new boolean[1];
MessagesStorage.getInstance().storageQueue.postRunnable(new Runnable() {
@Override
public void run() {
users.addAll(MessagesStorage.getInstance().getUsers(usersToLoad, error));
users.addAll(MessagesStorage.getInstance().getUsers(usersToLoad));
semaphore.release();
}
});
@ -95,7 +94,7 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
} catch (Exception e) {
FileLog.e("tmessages", e);
}
if (error[0]) {
if (usersToLoad.size() != users.size()) {
return false;
}
if (!users.isEmpty()) {

View file

@ -775,17 +775,19 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
if (searching && searchWas) {
if (i == searchResult.size()) {
if (view == null) {
view = new SettingsSectionLayout(mContext);
((SettingsSectionLayout) view).setText(LocaleController.getString("GlobalSearch", R.string.GlobalSearch));
view.setPadding(AndroidUtilities.dp(11), 0, AndroidUtilities.dp(11), 0);
}
} else {
if (view == null) {
view = new ChatOrUserCell(mContext);
}
int type = getItemViewType(i);
if (type == 3) {
if (view == null) {
view = new SettingsSectionLayout(mContext);
((SettingsSectionLayout) view).setText(LocaleController.getString("GlobalSearch", R.string.GlobalSearch));
view.setPadding(AndroidUtilities.dp(11), 0, AndroidUtilities.dp(11), 0);
}
} else if (type == 2) {
if (view == null) {
view = new ChatOrUserCell(mContext);
}
if (searching && searchWas) {
TLRPC.User user = null;
TLRPC.Chat chat = null;
TLRPC.EncryptedChat encryptedChat = null;
@ -795,7 +797,7 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
if (obj instanceof TLRPC.User) {
user = MessagesController.getInstance().getUser(((TLRPC.User) obj).id);
if (user == null) {
user = (TLRPC.User)obj;
user = (TLRPC.User) obj;
}
} else if (obj instanceof TLRPC.Chat) {
chat = MessagesController.getInstance().getChat(((TLRPC.Chat) obj).id);
@ -805,7 +807,16 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
}
CharSequence username = null;
if (i > searchResult.size() && user != null && user.username != null) {
CharSequence name = null;
if (i < searchResult.size()) {
name = searchResultNames.get(i);
if (name != null && user != null && user.username != null && user.username.length() > 0) {
if (name.toString().startsWith("@" + user.username)) {
username = name;
name = null;
}
}
} else if (i > searchResult.size() && user != null && user.username != null) {
try {
username = Html.fromHtml(String.format("<font color=\"#357aa8\">@%s</font>%s", user.username.substring(0, lastFoundUsername.length()), user.username.substring(lastFoundUsername.length())));
} catch (Exception e) {
@ -814,36 +825,31 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
}
}
((ChatOrUserCell) view).setData(user, chat, encryptedChat, i < searchResult.size() ? searchResultNames.get(i) : null, username);
((ChatOrUserCell) view).setData(user, chat, encryptedChat, name, username);
}
return view;
}
int type = getItemViewType(i);
if (type == 1) {
} else if (type == 1) {
if (view == null) {
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = li.inflate(R.layout.loading_more_layout, viewGroup, false);
}
return view;
}
if (view == null) {
view = new DialogCell(mContext);
}
((DialogCell) view).useSeparator = (i != getCount() - 1);
if (serverOnly) {
((DialogCell)view).setDialog(MessagesController.getInstance().dialogsServerOnly.get(i));
} else {
TLRPC.TL_dialog dialog = MessagesController.getInstance().dialogs.get(i);
if (AndroidUtilities.isTablet()) {
if (dialog.id == openedDialogId) {
view.setBackgroundColor(0x0f000000);
} else {
view.setBackgroundColor(0);
}
} else if (type == 0) {
if (view == null) {
view = new DialogCell(mContext);
}
((DialogCell) view).useSeparator = (i != getCount() - 1);
if (serverOnly) {
((DialogCell) view).setDialog(MessagesController.getInstance().dialogsServerOnly.get(i));
} else {
TLRPC.TL_dialog dialog = MessagesController.getInstance().dialogs.get(i);
if (AndroidUtilities.isTablet()) {
if (dialog.id == openedDialogId) {
view.setBackgroundColor(0x0f000000);
} else {
view.setBackgroundColor(0);
}
}
((DialogCell) view).setDialog(dialog);
}
((DialogCell)view).setDialog(dialog);
}
return view;

View file

@ -1173,6 +1173,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
menuItem.hideSubItem(gallery_menu_save);
shareButton.setVisibility(View.GONE);
} else {
menuItem.showSubItem(gallery_menu_save);
shareButton.setVisibility(View.VISIBLE);
}
setImageIndex(0, true);
@ -1215,6 +1216,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
menuItem.hideSubItem(gallery_menu_save);
shareButton.setVisibility(View.GONE);
} else {
menuItem.showSubItem(gallery_menu_save);
shareButton.setVisibility(View.VISIBLE);
}
opennedFromMedia = true;

View file

@ -194,6 +194,9 @@ public class SettingsChangeUsernameActivity extends BaseFragment {
}
private void showErrorAlert(String error) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
if (error.equals("USERNAME_INVALID")) {

View file

@ -457,11 +457,17 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur
}
private void onPlayComplete() {
playButton.setImageResource(R.drawable.video_play);
videoSeekBarView.setProgress(videoTimelineView.getLeftProgress());
if (playButton != null) {
playButton.setImageResource(R.drawable.video_play);
}
if (videoSeekBarView != null && videoTimelineView != null) {
videoSeekBarView.setProgress(videoTimelineView.getLeftProgress());
}
try {
if (videoPlayer != null) {
videoPlayer.seekTo((int) (videoTimelineView.getLeftProgress() * videoDuration));
if (videoTimelineView != null) {
videoPlayer.seekTo((int) (videoTimelineView.getLeftProgress() * videoDuration));
}
}
} catch (Exception e) {
FileLog.e("tmessages", e);

View file

@ -597,24 +597,22 @@ public class ChatActivityEnterView implements NotificationCenter.NotificationCen
messsageEditText.dispatchKeyEvent(new KeyEvent(0, 67));
}
public void onEmojiSelected(String paramAnonymousString) {
public void onEmojiSelected(String symbol) {
int i = messsageEditText.getSelectionEnd();
CharSequence localCharSequence = Emoji.replaceEmoji(paramAnonymousString, messsageEditText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20));
messsageEditText.setText(messsageEditText.getText().insert(i, localCharSequence));
int j = i + localCharSequence.length();
messsageEditText.setSelection(j, j);
if (i < 0) {
i = 0;
}
try {
CharSequence localCharSequence = Emoji.replaceEmoji(symbol, messsageEditText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20));
messsageEditText.setText(messsageEditText.getText().insert(i, localCharSequence));
int j = i + localCharSequence.length();
messsageEditText.setSelection(j, j);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
});
emojiPopup = new PopupWindow(emojiView);
/*try {
Method method = emojiPopup.getClass().getMethod("setWindowLayoutType", int.class);
if (method != null) {
method.invoke(emojiPopup, WindowManager.LayoutParams.LAST_SUB_WINDOW);
}
} catch (Exception e) {
//don't promt
}*/
}
public void setDelegate(ChatActivityEnterViewDelegate delegate) {

View file

@ -20,12 +20,12 @@
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:interpolator="@anim/decelerate_cubic"
android:duration="220"/>
android:duration="150"/>
<scale
android:fromXScale=".8" android:toXScale="1.0"
android:fromYScale=".8" android:toYScale="1.0"
android:pivotX="50%p" android:pivotY="50%p"
android:interpolator="@anim/decelerate_cubic"
android:duration="220"/>
android:duration="150"/>
</set>

View file

@ -20,7 +20,7 @@
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:interpolator="@anim/decelerate_cubic"
android:duration="220"/>
android:duration="150"/>
<scale
android:fromXScale="1.0"
@ -30,5 +30,5 @@
android:pivotX="50%p"
android:pivotY="50%p"
android:interpolator="@anim/decelerate_cubic"
android:duration="220"/>
android:duration="150"/>
</set>