Bug fixes
This commit is contained in:
parent
d03fa95568
commit
abf8f6f619
21
README.md
21
README.md
@ -1,21 +1,30 @@
|
|||||||
## Telegram messenger for Android
|
## Telegram messenger for Android
|
||||||
|
|
||||||
[Telegram](http://telegram.org) is a messaging app with a focus on speed and security. It’s superfast, simple and free.
|
[Telegram](http://telegram.org) is a messaging app with a focus on speed and security. It’s 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
|
### 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
|
### Usage
|
||||||
|
|
||||||
**Beware of using dev branch and uploading it to any markets, in most cases it will work as you expecting**
|
**Beware of using the dev branch and uploading it to any markets, in many cases it not will work as expected**.
|
||||||
|
|
||||||
First of all your should take a look to **src/main/java/org/telegram/messenger/BuildVars.java** and fill it with correct values.
|
|
||||||
|
|
||||||
|
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.
|
Import the root folder into your IDE (tested on Android Studio), then run project.
|
||||||
|
|
||||||
### Localization
|
### Localization
|
||||||
|
@ -25,7 +25,7 @@ dependencies {
|
|||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 21
|
compileSdkVersion 21
|
||||||
buildToolsVersion '21.0.1'
|
buildToolsVersion '21.0.2'
|
||||||
|
|
||||||
signingConfigs {
|
signingConfigs {
|
||||||
debug {
|
debug {
|
||||||
@ -80,7 +80,7 @@ android {
|
|||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion 8
|
minSdkVersion 8
|
||||||
targetSdkVersion 19
|
targetSdkVersion 19
|
||||||
versionCode 372
|
versionCode 374
|
||||||
versionName "1.9.6"
|
versionName "1.9.6"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -218,7 +218,7 @@ public class AndroidUtilities {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static File getCacheDir() {
|
public static File getCacheDir() {
|
||||||
if (Environment.getExternalStorageState().startsWith(Environment.MEDIA_MOUNTED)) {
|
if (Environment.getExternalStorageState() == null || Environment.getExternalStorageState().startsWith(Environment.MEDIA_MOUNTED)) {
|
||||||
try {
|
try {
|
||||||
File file = ApplicationLoader.applicationContext.getExternalCacheDir();
|
File file = ApplicationLoader.applicationContext.getExternalCacheDir();
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
|
@ -1711,7 +1711,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void markMessageAsRead(final long dialog_id, final long random_id, int ttl) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
int lower_part = (int)dialog_id;
|
int lower_part = (int)dialog_id;
|
||||||
@ -1726,10 +1726,8 @@ public class MessagesController implements NotificationCenter.NotificationCenter
|
|||||||
ArrayList<Long> random_ids = new ArrayList<Long>();
|
ArrayList<Long> random_ids = new ArrayList<Long>();
|
||||||
random_ids.add(random_id);
|
random_ids.add(random_id);
|
||||||
SendMessagesHelper.getInstance().sendMessagesReadMessage(chat, random_ids, null);
|
SendMessagesHelper.getInstance().sendMessagesReadMessage(chat, random_ids, null);
|
||||||
if (ttl > 0) {
|
int time = ConnectionsManager.getInstance().getCurrentTime();
|
||||||
int time = ConnectionsManager.getInstance().getCurrentTime();
|
MessagesStorage.getInstance().createTaskForSecretChat(chat.id, time, time, 0, random_ids);
|
||||||
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) {
|
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) {
|
||||||
|
@ -499,58 +499,15 @@ public class MessagesStorage {
|
|||||||
cursor.dispose();
|
cursor.dispose();
|
||||||
|
|
||||||
if (!encryptedChatIds.isEmpty()) {
|
if (!encryptedChatIds.isEmpty()) {
|
||||||
String stringToLoad = TextUtils.join(",", encryptedChatIds);
|
getEncryptedChatsInternal(TextUtils.join(",", encryptedChatIds), encryptedChats, userIds);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!userIds.isEmpty()) {
|
if (!userIds.isEmpty()) {
|
||||||
String stringToLoad = TextUtils.join(",", userIds);
|
getUsersInternal(TextUtils.join(",", userIds), users);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!chatIds.isEmpty()) {
|
if (!chatIds.isEmpty()) {
|
||||||
String stringToLoad = TextUtils.join(",", chatIds);
|
getChatsInternal(TextUtils.join(",", chatIds), chats);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Collections.reverse(messages);
|
Collections.reverse(messages);
|
||||||
@ -639,19 +596,7 @@ public class MessagesStorage {
|
|||||||
cursor.dispose();
|
cursor.dispose();
|
||||||
|
|
||||||
if (usersToLoad.length() != 0) {
|
if (usersToLoad.length() != 0) {
|
||||||
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, status FROM users WHERE uid IN(%s)", usersToLoad.toString()));
|
getUsersInternal(usersToLoad.toString(), users);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MessagesController.getInstance().processLoadedBlockedUsers(ids, users, true);
|
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));
|
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()) {
|
while (cursor.next()) {
|
||||||
|
int ttl = cursor.intValue(1);
|
||||||
|
if (ttl <= 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
int mid = cursor.intValue(0);
|
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);
|
minDate = Math.min(minDate, date);
|
||||||
ArrayList<Integer> arr = messages.get(date);
|
ArrayList<Integer> arr = messages.get(date);
|
||||||
if (arr == null) {
|
if (arr == null) {
|
||||||
@ -1126,19 +1075,7 @@ public class MessagesStorage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (usersToLoad.length() != 0) {
|
if (usersToLoad.length() != 0) {
|
||||||
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, status FROM users WHERE uid IN(%s)", usersToLoad.toString()));
|
getUsersInternal(usersToLoad.toString(), loadedUsers);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
if (modified) {
|
if (modified) {
|
||||||
updateChatInfo(chat_id, info, false);
|
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");
|
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()) {
|
while (cursor.next()) {
|
||||||
String name = cursor.stringValue(2);
|
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)) {
|
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 data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
|
||||||
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
|
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
|
||||||
TLRPC.User user = (TLRPC.User)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
|
TLRPC.User user = (TLRPC.User)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
|
||||||
@ -1233,7 +1181,11 @@ public class MessagesStorage {
|
|||||||
if (user.status != null) {
|
if (user.status != null) {
|
||||||
user.status.expires = cursor.intValue(1);
|
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);
|
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");
|
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()) {
|
while (cursor.next()) {
|
||||||
String name = cursor.stringValue(1);
|
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)) {
|
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 data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
|
||||||
ByteBufferDesc data2 = buffersStorage.getFreeBuffer(cursor.byteArrayLength(6));
|
ByteBufferDesc data2 = buffersStorage.getFreeBuffer(cursor.byteArrayLength(6));
|
||||||
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0 && cursor.byteBufferValue(6, data2.buffer) != 0) {
|
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) {
|
if (user.status != null) {
|
||||||
user.status.expires = cursor.intValue(7);
|
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);
|
resultArray.add(chat);
|
||||||
encUsers.add(user);
|
encUsers.add(user);
|
||||||
}
|
}
|
||||||
@ -1473,19 +1442,7 @@ public class MessagesStorage {
|
|||||||
cursor.dispose();
|
cursor.dispose();
|
||||||
|
|
||||||
if (uids.length() != 0) {
|
if (uids.length() != 0) {
|
||||||
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, status FROM users WHERE uid IN(%s)", uids.toString()));
|
getUsersInternal(uids.toString(), users);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
contacts.clear();
|
contacts.clear();
|
||||||
@ -1597,20 +1554,7 @@ public class MessagesStorage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (usersToLoad.length() != 0) {
|
if (usersToLoad.length() != 0) {
|
||||||
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, status FROM users WHERE uid IN(%s)", usersToLoad.toString()));
|
getUsersInternal(usersToLoad.toString(), res.users);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
res.messages.clear();
|
res.messages.clear();
|
||||||
@ -1737,45 +1681,11 @@ public class MessagesStorage {
|
|||||||
|
|
||||||
|
|
||||||
if (!encryptedChatIds.isEmpty()) {
|
if (!encryptedChatIds.isEmpty()) {
|
||||||
String stringToLoad = TextUtils.join(",", encryptedChatIds);
|
getEncryptedChatsInternal(TextUtils.join(",", encryptedChatIds), encryptedChats, userIds);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!userIds.isEmpty()) {
|
if (!userIds.isEmpty()) {
|
||||||
String stringToLoad = TextUtils.join(",", userIds);
|
getUsersInternal(TextUtils.join(",", userIds), users);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!chatIds.isEmpty() || !broadcastIds.isEmpty()) {
|
if (!chatIds.isEmpty() || !broadcastIds.isEmpty()) {
|
||||||
@ -1792,16 +1702,7 @@ public class MessagesStorage {
|
|||||||
}
|
}
|
||||||
stringToLoad.append(-cid);
|
stringToLoad.append(-cid);
|
||||||
}
|
}
|
||||||
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data FROM chats WHERE uid IN(%s)", stringToLoad.toString()));
|
getChatsInternal(stringToLoad.toString(), chats);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SendMessagesHelper.getInstance().processUnsentMessages(messages, users, chats, encryptedChats);
|
SendMessagesHelper.getInstance().processUnsentMessages(messages, users, chats, encryptedChats);
|
||||||
@ -2017,20 +1918,7 @@ public class MessagesStorage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (usersToLoad.length() != 0) {
|
if (usersToLoad.length() != 0) {
|
||||||
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, status FROM users WHERE uid IN(%s)", usersToLoad.toString()));
|
getUsersInternal(usersToLoad.toString(), res.users);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
res.messages.clear();
|
res.messages.clear();
|
||||||
@ -2270,42 +2158,15 @@ public class MessagesStorage {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
int userToLoad = 0;
|
ArrayList<Integer> usersToLoad = new ArrayList<Integer>();
|
||||||
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));
|
ArrayList<TLRPC.EncryptedChat> encryptedChats = new ArrayList<TLRPC.EncryptedChat>();
|
||||||
if (cursor.next()) {
|
getEncryptedChatsInternal("" + chat_id, encryptedChats, usersToLoad);
|
||||||
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
|
if (!encryptedChats.isEmpty() && !usersToLoad.isEmpty()) {
|
||||||
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
|
ArrayList<TLRPC.User> users = new ArrayList<TLRPC.User>();
|
||||||
TLRPC.EncryptedChat chat = (TLRPC.EncryptedChat)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
|
getUsersInternal(TextUtils.join(",", usersToLoad), users);
|
||||||
result.add(chat);
|
if (!users.isEmpty()) {
|
||||||
chat.user_id = cursor.intValue(1);
|
result.add(encryptedChats.get(0));
|
||||||
userToLoad = chat.user_id;
|
result.add(users.get(0));
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -2333,12 +2194,7 @@ public class MessagesStorage {
|
|||||||
chat.serializeToStream(data);
|
chat.serializeToStream(data);
|
||||||
state.bindInteger(1, chat.id);
|
state.bindInteger(1, chat.id);
|
||||||
state.bindInteger(2, user.id);
|
state.bindInteger(2, user.id);
|
||||||
if (user.first_name != null && user.last_name != null) {
|
state.bindString(3, formatUserSearchName(user));
|
||||||
String name = (user.first_name + " " + user.last_name).toLowerCase();
|
|
||||||
state.bindString(3, name);
|
|
||||||
} else {
|
|
||||||
state.bindString(3, "");
|
|
||||||
}
|
|
||||||
state.bindByteBuffer(4, data.buffer);
|
state.bindByteBuffer(4, data.buffer);
|
||||||
if (chat.a_or_b != null) {
|
if (chat.a_or_b != null) {
|
||||||
data2.writeRaw(chat.a_or_b);
|
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) {
|
private void putUsersAndChatsInternal(final ArrayList<TLRPC.User> users, final ArrayList<TLRPC.Chat> chats, final boolean withTransaction) {
|
||||||
try {
|
try {
|
||||||
if (withTransaction) {
|
if (withTransaction) {
|
||||||
database.beginTransaction();
|
database.beginTransaction();
|
||||||
}
|
}
|
||||||
if (users != null && !users.isEmpty()) {
|
putUsersInternal(users);
|
||||||
SQLitePreparedStatement state = database.executeFast("REPLACE INTO users VALUES(?, ?, ?, ?)");
|
putChatsInternal(chats);
|
||||||
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();
|
|
||||||
}
|
|
||||||
if (withTransaction) {
|
if (withTransaction) {
|
||||||
database.commitTransaction();
|
database.commitTransaction();
|
||||||
}
|
}
|
||||||
@ -2999,16 +2958,10 @@ public class MessagesStorage {
|
|||||||
usersDict.put(user.id, user);
|
usersDict.put(user.id, user);
|
||||||
}
|
}
|
||||||
ArrayList<TLRPC.User> loadedUsers = new ArrayList<TLRPC.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()));
|
getUsersInternal(ids.toString(), loadedUsers);
|
||||||
while (cursor.next()) {
|
for (TLRPC.User user : loadedUsers) {
|
||||||
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
|
TLRPC.User updateUser = usersDict.get(user.id);
|
||||||
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
|
if (updateUser != null) {
|
||||||
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);
|
|
||||||
if (updateUser.first_name != null && updateUser.last_name != null) {
|
if (updateUser.first_name != null && updateUser.last_name != null) {
|
||||||
user.first_name = updateUser.first_name;
|
user.first_name = updateUser.first_name;
|
||||||
user.last_name = updateUser.last_name;
|
user.last_name = updateUser.last_name;
|
||||||
@ -3017,35 +2970,13 @@ public class MessagesStorage {
|
|||||||
user.photo = updateUser.photo;
|
user.photo = updateUser.photo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buffersStorage.reuseFreeBuffer(data);
|
|
||||||
}
|
}
|
||||||
cursor.dispose();
|
|
||||||
if (!loadedUsers.isEmpty()) {
|
if (!loadedUsers.isEmpty()) {
|
||||||
if (withTransaction) {
|
if (withTransaction) {
|
||||||
database.beginTransaction();
|
database.beginTransaction();
|
||||||
}
|
}
|
||||||
SQLitePreparedStatement state = database.executeFast("REPLACE INTO users VALUES(?, ?, ?, ?)");
|
putUsersInternal(loadedUsers);
|
||||||
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();
|
|
||||||
if (withTransaction) {
|
if (withTransaction) {
|
||||||
database.commitTransaction();
|
database.commitTransaction();
|
||||||
}
|
}
|
||||||
@ -3308,58 +3239,15 @@ public class MessagesStorage {
|
|||||||
cursor.dispose();
|
cursor.dispose();
|
||||||
|
|
||||||
if (!encryptedToLoad.isEmpty()) {
|
if (!encryptedToLoad.isEmpty()) {
|
||||||
String toLoad = TextUtils.join(",", encryptedToLoad);
|
getEncryptedChatsInternal(TextUtils.join(",", encryptedToLoad), encryptedChats, usersToLoad);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!chatsToLoad.isEmpty()) {
|
if (!chatsToLoad.isEmpty()) {
|
||||||
String toLoad = TextUtils.join(",", chatsToLoad);
|
getChatsInternal(TextUtils.join(",", chatsToLoad), dialogs.chats);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!usersToLoad.isEmpty()) {
|
if (!usersToLoad.isEmpty()) {
|
||||||
String toLoad = TextUtils.join(",", usersToLoad);
|
getUsersInternal(TextUtils.join(",", usersToLoad), dialogs.users);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dialogs.dialogs.isEmpty() || !encryptedChats.isEmpty()) {
|
if (!dialogs.dialogs.isEmpty() || !encryptedChats.isEmpty()) {
|
||||||
@ -3442,49 +3330,8 @@ public class MessagesStorage {
|
|||||||
state.dispose();
|
state.dispose();
|
||||||
state2.dispose();
|
state2.dispose();
|
||||||
}
|
}
|
||||||
if (!messages.users.isEmpty()) {
|
putUsersInternal(messages.users);
|
||||||
SQLitePreparedStatement state = database.executeFast("REPLACE INTO users VALUES(?, ?, ?, ?)");
|
putChatsInternal(messages.chats);
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
database.commitTransaction();
|
database.commitTransaction();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -3567,76 +3414,15 @@ public class MessagesStorage {
|
|||||||
cursor.dispose();
|
cursor.dispose();
|
||||||
|
|
||||||
if (!encryptedToLoad.isEmpty()) {
|
if (!encryptedToLoad.isEmpty()) {
|
||||||
String toLoad = TextUtils.join(",", encryptedToLoad);
|
getEncryptedChatsInternal(TextUtils.join(",", encryptedToLoad), encryptedChats, usersToLoad);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!chatsToLoad.isEmpty()) {
|
if (!chatsToLoad.isEmpty()) {
|
||||||
String toLoad = TextUtils.join(",", chatsToLoad);
|
getChatsInternal(TextUtils.join(",", chatsToLoad), dialogs.chats);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!usersToLoad.isEmpty()) {
|
if (!usersToLoad.isEmpty()) {
|
||||||
String toLoad = TextUtils.join(",", usersToLoad);
|
getUsersInternal(TextUtils.join(",", usersToLoad), dialogs.users);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
MessagesController.getInstance().processLoadedDialogs(dialogs, encryptedChats, offset, serverOffset, count, true, false);
|
MessagesController.getInstance().processLoadedDialogs(dialogs, encryptedChats, offset, serverOffset, count, true, false);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -3725,50 +3511,8 @@ public class MessagesStorage {
|
|||||||
state4.dispose();
|
state4.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dialogs.users.isEmpty()) {
|
putUsersInternal(dialogs.users);
|
||||||
SQLitePreparedStatement state = database.executeFast("REPLACE INTO users VALUES(?, ?, ?, ?)");
|
putChatsInternal(dialogs.chats);
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
database.commitTransaction();
|
database.commitTransaction();
|
||||||
|
|
||||||
@ -3783,56 +3527,23 @@ public class MessagesStorage {
|
|||||||
public TLRPC.User getUser(final int user_id) {
|
public TLRPC.User getUser(final int user_id) {
|
||||||
TLRPC.User user = null;
|
TLRPC.User user = null;
|
||||||
try {
|
try {
|
||||||
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, status FROM users WHERE uid = %d", user_id));
|
ArrayList<TLRPC.User> users = new ArrayList<TLRPC.User>();
|
||||||
if (cursor.next()) {
|
getUsersInternal("" + user_id, users);
|
||||||
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
|
if (!users.isEmpty()) {
|
||||||
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
|
user = users.get(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);
|
|
||||||
}
|
}
|
||||||
cursor.dispose();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
FileLog.e("tmessages", e);
|
FileLog.e("tmessages", e);
|
||||||
}
|
}
|
||||||
return user;
|
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>();
|
ArrayList<TLRPC.User> users = new ArrayList<TLRPC.User>();
|
||||||
try {
|
try {
|
||||||
String uidsStr = TextUtils.join(",", uids);
|
getUsersInternal(TextUtils.join(",", uids), users);
|
||||||
|
|
||||||
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();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
error[0] = true;
|
users.clear();
|
||||||
FileLog.e("tmessages", e);
|
FileLog.e("tmessages", e);
|
||||||
}
|
}
|
||||||
return users;
|
return users;
|
||||||
@ -3841,15 +3552,11 @@ public class MessagesStorage {
|
|||||||
public TLRPC.Chat getChat(final int chat_id) {
|
public TLRPC.Chat getChat(final int chat_id) {
|
||||||
TLRPC.Chat chat = null;
|
TLRPC.Chat chat = null;
|
||||||
try {
|
try {
|
||||||
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT data FROM chats WHERE uid = %d", chat_id));
|
ArrayList<TLRPC.Chat> chats = new ArrayList<TLRPC.Chat>();
|
||||||
if (cursor.next()) {
|
getChatsInternal("" + chat_id, chats);
|
||||||
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
|
if (!chats.isEmpty()) {
|
||||||
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
|
chat = chats.get(0);
|
||||||
chat = (TLRPC.Chat) TLClassStore.Instance().TLdeserialize(data, data.readInt32());
|
|
||||||
}
|
|
||||||
buffersStorage.reuseFreeBuffer(data);
|
|
||||||
}
|
}
|
||||||
cursor.dispose();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
FileLog.e("tmessages", e);
|
FileLog.e("tmessages", e);
|
||||||
}
|
}
|
||||||
@ -3859,24 +3566,11 @@ public class MessagesStorage {
|
|||||||
public TLRPC.EncryptedChat getEncryptedChat(final int chat_id) {
|
public TLRPC.EncryptedChat getEncryptedChat(final int chat_id) {
|
||||||
TLRPC.EncryptedChat chat = null;
|
TLRPC.EncryptedChat chat = null;
|
||||||
try {
|
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));
|
ArrayList<TLRPC.EncryptedChat> encryptedChats = new ArrayList<TLRPC.EncryptedChat>();
|
||||||
if (cursor.next()) {
|
getEncryptedChatsInternal("" + chat_id, encryptedChats, null);
|
||||||
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
|
if (!encryptedChats.isEmpty()) {
|
||||||
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
|
chat = encryptedChats.get(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);
|
|
||||||
}
|
}
|
||||||
cursor.dispose();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
FileLog.e("tmessages", e);
|
FileLog.e("tmessages", e);
|
||||||
}
|
}
|
||||||
|
@ -626,10 +626,12 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
|
|||||||
newMsg.to_id.user_id = encryptedChat.participant_id;
|
newMsg.to_id.user_id = encryptedChat.participant_id;
|
||||||
}
|
}
|
||||||
newMsg.ttl = encryptedChat.ttl;
|
newMsg.ttl = encryptedChat.ttl;
|
||||||
if (newMsg.media instanceof TLRPC.TL_messageMediaAudio) {
|
if (newMsg.ttl != 0) {
|
||||||
newMsg.ttl = Math.max(encryptedChat.ttl, newMsg.media.audio.duration + 1);
|
if (newMsg.media instanceof TLRPC.TL_messageMediaAudio) {
|
||||||
} else if (newMsg.media instanceof TLRPC.TL_messageMediaVideo) {
|
newMsg.ttl = Math.max(encryptedChat.ttl, newMsg.media.audio.duration + 1);
|
||||||
newMsg.ttl = Math.max(encryptedChat.ttl, newMsg.media.video.duration + 1);
|
} else if (newMsg.media instanceof TLRPC.TL_messageMediaVideo) {
|
||||||
|
newMsg.ttl = Math.max(encryptedChat.ttl, newMsg.media.video.duration + 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,12 +99,25 @@ public class ContactsActivitySearchAdapter extends BaseContactsSearchAdapter {
|
|||||||
|
|
||||||
for (TLRPC.TL_contact contact : contactsCopy) {
|
for (TLRPC.TL_contact contact : contactsCopy) {
|
||||||
TLRPC.User user = MessagesController.getInstance().getUser(contact.user_id);
|
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();
|
String name = ContactsController.formatName(user.first_name, user.last_name).toLowerCase();
|
||||||
|
|
||||||
|
int found = 0;
|
||||||
if (name.startsWith(q) || name.contains(" " + q)) {
|
if (name.startsWith(q) || name.contains(" " + q)) {
|
||||||
if (user.id == UserConfig.getClientUserId()) {
|
found = 1;
|
||||||
continue;
|
} 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);
|
resultArray.add(user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -197,7 +210,16 @@ public class ContactsActivitySearchAdapter extends BaseContactsSearchAdapter {
|
|||||||
TLRPC.User user = getItem(i);
|
TLRPC.User user = getItem(i);
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
CharSequence username = 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 {
|
try {
|
||||||
username = Html.fromHtml(String.format("<font color=\"#357aa8\">@%s</font>%s", user.username.substring(0, lastFoundUsername.length()), user.username.substring(lastFoundUsername.length())));
|
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) {
|
} 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 != null) {
|
||||||
if (ignoreUsers.containsKey(user.id)) {
|
if (ignoreUsers.containsKey(user.id)) {
|
||||||
|
@ -1040,7 +1040,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean sendSecretMessageRead(MessageObject messageObject) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
MessagesController.getInstance().markMessageAsRead(dialog_id, messageObject.messageOwner.random_id, messageObject.messageOwner.ttl);
|
MessagesController.getInstance().markMessageAsRead(dialog_id, messageObject.messageOwner.random_id, messageObject.messageOwner.ttl);
|
||||||
|
@ -477,7 +477,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
|
|||||||
args.putBoolean("destroyAfterSelect", true);
|
args.putBoolean("destroyAfterSelect", true);
|
||||||
args.putBoolean("usersAsSections", true);
|
args.putBoolean("usersAsSections", true);
|
||||||
args.putBoolean("returnAsResult", true);
|
args.putBoolean("returnAsResult", true);
|
||||||
args.putBoolean("allowUsernameSearch", false);
|
//args.putBoolean("allowUsernameSearch", false);
|
||||||
if (chat_id > 0) {
|
if (chat_id > 0) {
|
||||||
args.putString("selectAlertString", LocaleController.getString("AddToTheGroup", R.string.AddToTheGroup));
|
args.putString("selectAlertString", LocaleController.getString("AddToTheGroup", R.string.AddToTheGroup));
|
||||||
}
|
}
|
||||||
|
@ -82,11 +82,10 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
|
|||||||
if (!usersToLoad.isEmpty()) {
|
if (!usersToLoad.isEmpty()) {
|
||||||
final Semaphore semaphore = new Semaphore(0);
|
final Semaphore semaphore = new Semaphore(0);
|
||||||
final ArrayList<TLRPC.User> users = new ArrayList<TLRPC.User>();
|
final ArrayList<TLRPC.User> users = new ArrayList<TLRPC.User>();
|
||||||
final boolean[] error = new boolean[1];
|
|
||||||
MessagesStorage.getInstance().storageQueue.postRunnable(new Runnable() {
|
MessagesStorage.getInstance().storageQueue.postRunnable(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
users.addAll(MessagesStorage.getInstance().getUsers(usersToLoad, error));
|
users.addAll(MessagesStorage.getInstance().getUsers(usersToLoad));
|
||||||
semaphore.release();
|
semaphore.release();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -95,7 +94,7 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
FileLog.e("tmessages", e);
|
FileLog.e("tmessages", e);
|
||||||
}
|
}
|
||||||
if (error[0]) {
|
if (usersToLoad.size() != users.size()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!users.isEmpty()) {
|
if (!users.isEmpty()) {
|
||||||
|
@ -775,17 +775,19 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View getView(int i, View view, ViewGroup viewGroup) {
|
public View getView(int i, View view, ViewGroup viewGroup) {
|
||||||
if (searching && searchWas) {
|
int type = getItemViewType(i);
|
||||||
if (i == searchResult.size()) {
|
|
||||||
if (view == null) {
|
if (type == 3) {
|
||||||
view = new SettingsSectionLayout(mContext);
|
if (view == null) {
|
||||||
((SettingsSectionLayout) view).setText(LocaleController.getString("GlobalSearch", R.string.GlobalSearch));
|
view = new SettingsSectionLayout(mContext);
|
||||||
view.setPadding(AndroidUtilities.dp(11), 0, AndroidUtilities.dp(11), 0);
|
((SettingsSectionLayout) view).setText(LocaleController.getString("GlobalSearch", R.string.GlobalSearch));
|
||||||
}
|
view.setPadding(AndroidUtilities.dp(11), 0, AndroidUtilities.dp(11), 0);
|
||||||
} else {
|
}
|
||||||
if (view == null) {
|
} else if (type == 2) {
|
||||||
view = new ChatOrUserCell(mContext);
|
if (view == null) {
|
||||||
}
|
view = new ChatOrUserCell(mContext);
|
||||||
|
}
|
||||||
|
if (searching && searchWas) {
|
||||||
TLRPC.User user = null;
|
TLRPC.User user = null;
|
||||||
TLRPC.Chat chat = null;
|
TLRPC.Chat chat = null;
|
||||||
TLRPC.EncryptedChat encryptedChat = null;
|
TLRPC.EncryptedChat encryptedChat = null;
|
||||||
@ -795,7 +797,7 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
|
|||||||
if (obj instanceof TLRPC.User) {
|
if (obj instanceof TLRPC.User) {
|
||||||
user = MessagesController.getInstance().getUser(((TLRPC.User) obj).id);
|
user = MessagesController.getInstance().getUser(((TLRPC.User) obj).id);
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
user = (TLRPC.User)obj;
|
user = (TLRPC.User) obj;
|
||||||
}
|
}
|
||||||
} else if (obj instanceof TLRPC.Chat) {
|
} else if (obj instanceof TLRPC.Chat) {
|
||||||
chat = MessagesController.getInstance().getChat(((TLRPC.Chat) obj).id);
|
chat = MessagesController.getInstance().getChat(((TLRPC.Chat) obj).id);
|
||||||
@ -805,7 +807,16 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
|
|||||||
}
|
}
|
||||||
|
|
||||||
CharSequence username = null;
|
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 {
|
try {
|
||||||
username = Html.fromHtml(String.format("<font color=\"#357aa8\">@%s</font>%s", user.username.substring(0, lastFoundUsername.length()), user.username.substring(lastFoundUsername.length())));
|
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) {
|
} 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);
|
||||||
}
|
}
|
||||||
|
} else if (type == 1) {
|
||||||
return view;
|
|
||||||
}
|
|
||||||
int type = getItemViewType(i);
|
|
||||||
if (type == 1) {
|
|
||||||
if (view == null) {
|
if (view == null) {
|
||||||
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
view = li.inflate(R.layout.loading_more_layout, viewGroup, false);
|
view = li.inflate(R.layout.loading_more_layout, viewGroup, false);
|
||||||
}
|
}
|
||||||
return view;
|
} else if (type == 0) {
|
||||||
}
|
if (view == null) {
|
||||||
|
view = new DialogCell(mContext);
|
||||||
if (view == null) {
|
}
|
||||||
view = new DialogCell(mContext);
|
((DialogCell) view).useSeparator = (i != getCount() - 1);
|
||||||
}
|
if (serverOnly) {
|
||||||
((DialogCell) view).useSeparator = (i != getCount() - 1);
|
((DialogCell) view).setDialog(MessagesController.getInstance().dialogsServerOnly.get(i));
|
||||||
if (serverOnly) {
|
} else {
|
||||||
((DialogCell)view).setDialog(MessagesController.getInstance().dialogsServerOnly.get(i));
|
TLRPC.TL_dialog dialog = MessagesController.getInstance().dialogs.get(i);
|
||||||
} else {
|
if (AndroidUtilities.isTablet()) {
|
||||||
TLRPC.TL_dialog dialog = MessagesController.getInstance().dialogs.get(i);
|
if (dialog.id == openedDialogId) {
|
||||||
if (AndroidUtilities.isTablet()) {
|
view.setBackgroundColor(0x0f000000);
|
||||||
if (dialog.id == openedDialogId) {
|
} else {
|
||||||
view.setBackgroundColor(0x0f000000);
|
view.setBackgroundColor(0);
|
||||||
} else {
|
}
|
||||||
view.setBackgroundColor(0);
|
}
|
||||||
}
|
((DialogCell) view).setDialog(dialog);
|
||||||
}
|
}
|
||||||
((DialogCell)view).setDialog(dialog);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
|
@ -1173,6 +1173,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
|
|||||||
menuItem.hideSubItem(gallery_menu_save);
|
menuItem.hideSubItem(gallery_menu_save);
|
||||||
shareButton.setVisibility(View.GONE);
|
shareButton.setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
|
menuItem.showSubItem(gallery_menu_save);
|
||||||
shareButton.setVisibility(View.VISIBLE);
|
shareButton.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
setImageIndex(0, true);
|
setImageIndex(0, true);
|
||||||
@ -1215,6 +1216,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
|
|||||||
menuItem.hideSubItem(gallery_menu_save);
|
menuItem.hideSubItem(gallery_menu_save);
|
||||||
shareButton.setVisibility(View.GONE);
|
shareButton.setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
|
menuItem.showSubItem(gallery_menu_save);
|
||||||
shareButton.setVisibility(View.VISIBLE);
|
shareButton.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
opennedFromMedia = true;
|
opennedFromMedia = true;
|
||||||
|
@ -194,6 +194,9 @@ public class SettingsChangeUsernameActivity extends BaseFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void showErrorAlert(String error) {
|
private void showErrorAlert(String error) {
|
||||||
|
if (getParentActivity() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
||||||
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
||||||
if (error.equals("USERNAME_INVALID")) {
|
if (error.equals("USERNAME_INVALID")) {
|
||||||
|
@ -457,11 +457,17 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void onPlayComplete() {
|
private void onPlayComplete() {
|
||||||
playButton.setImageResource(R.drawable.video_play);
|
if (playButton != null) {
|
||||||
videoSeekBarView.setProgress(videoTimelineView.getLeftProgress());
|
playButton.setImageResource(R.drawable.video_play);
|
||||||
|
}
|
||||||
|
if (videoSeekBarView != null && videoTimelineView != null) {
|
||||||
|
videoSeekBarView.setProgress(videoTimelineView.getLeftProgress());
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
if (videoPlayer != null) {
|
if (videoPlayer != null) {
|
||||||
videoPlayer.seekTo((int) (videoTimelineView.getLeftProgress() * videoDuration));
|
if (videoTimelineView != null) {
|
||||||
|
videoPlayer.seekTo((int) (videoTimelineView.getLeftProgress() * videoDuration));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
FileLog.e("tmessages", e);
|
FileLog.e("tmessages", e);
|
||||||
|
@ -597,24 +597,22 @@ public class ChatActivityEnterView implements NotificationCenter.NotificationCen
|
|||||||
messsageEditText.dispatchKeyEvent(new KeyEvent(0, 67));
|
messsageEditText.dispatchKeyEvent(new KeyEvent(0, 67));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onEmojiSelected(String paramAnonymousString) {
|
public void onEmojiSelected(String symbol) {
|
||||||
int i = messsageEditText.getSelectionEnd();
|
int i = messsageEditText.getSelectionEnd();
|
||||||
CharSequence localCharSequence = Emoji.replaceEmoji(paramAnonymousString, messsageEditText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20));
|
if (i < 0) {
|
||||||
messsageEditText.setText(messsageEditText.getText().insert(i, localCharSequence));
|
i = 0;
|
||||||
int j = i + localCharSequence.length();
|
}
|
||||||
messsageEditText.setSelection(j, j);
|
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);
|
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) {
|
public void setDelegate(ChatActivityEnterViewDelegate delegate) {
|
||||||
|
@ -20,12 +20,12 @@
|
|||||||
android:fromAlpha="0.0"
|
android:fromAlpha="0.0"
|
||||||
android:toAlpha="1.0"
|
android:toAlpha="1.0"
|
||||||
android:interpolator="@anim/decelerate_cubic"
|
android:interpolator="@anim/decelerate_cubic"
|
||||||
android:duration="220"/>
|
android:duration="150"/>
|
||||||
|
|
||||||
<scale
|
<scale
|
||||||
android:fromXScale=".8" android:toXScale="1.0"
|
android:fromXScale=".8" android:toXScale="1.0"
|
||||||
android:fromYScale=".8" android:toYScale="1.0"
|
android:fromYScale=".8" android:toYScale="1.0"
|
||||||
android:pivotX="50%p" android:pivotY="50%p"
|
android:pivotX="50%p" android:pivotY="50%p"
|
||||||
android:interpolator="@anim/decelerate_cubic"
|
android:interpolator="@anim/decelerate_cubic"
|
||||||
android:duration="220"/>
|
android:duration="150"/>
|
||||||
</set>
|
</set>
|
@ -20,7 +20,7 @@
|
|||||||
android:fromAlpha="1.0"
|
android:fromAlpha="1.0"
|
||||||
android:toAlpha="0.0"
|
android:toAlpha="0.0"
|
||||||
android:interpolator="@anim/decelerate_cubic"
|
android:interpolator="@anim/decelerate_cubic"
|
||||||
android:duration="220"/>
|
android:duration="150"/>
|
||||||
|
|
||||||
<scale
|
<scale
|
||||||
android:fromXScale="1.0"
|
android:fromXScale="1.0"
|
||||||
@ -30,5 +30,5 @@
|
|||||||
android:pivotX="50%p"
|
android:pivotX="50%p"
|
||||||
android:pivotY="50%p"
|
android:pivotY="50%p"
|
||||||
android:interpolator="@anim/decelerate_cubic"
|
android:interpolator="@anim/decelerate_cubic"
|
||||||
android:duration="220"/>
|
android:duration="150"/>
|
||||||
</set>
|
</set>
|
Loading…
Reference in New Issue
Block a user