mirror of
https://github.com/DrKLO/Telegram.git
synced 2024-12-22 14:35:03 +01:00
Update secret chats layer
This commit is contained in:
parent
a54300fb0a
commit
b2ad802ba5
8 changed files with 295 additions and 153 deletions
|
@ -9,7 +9,6 @@
|
|||
package org.telegram.android;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.res.Configuration;
|
||||
|
@ -34,8 +33,6 @@ import java.util.Locale;
|
|||
|
||||
public class AndroidUtilities {
|
||||
|
||||
public static ProgressDialog progressDialog;
|
||||
|
||||
private static final Hashtable<String, Typeface> typefaceCache = new Hashtable<String, Typeface>();
|
||||
private static int prevOrientation = -10;
|
||||
private static boolean waitingForSms = false;
|
||||
|
@ -266,6 +263,22 @@ public class AndroidUtilities {
|
|||
return 0x0000000100000000L | ((long)id & 0x00000000FFFFFFFFL);
|
||||
}
|
||||
|
||||
public static int getMyLayerVersion(int layer) {
|
||||
return layer & 0xffff;
|
||||
}
|
||||
|
||||
public static int getPeerLayerVersion(int layer) {
|
||||
return (layer >> 16) & 0xffff;
|
||||
}
|
||||
|
||||
public static int setMyLayerVersion(int layer, int version) {
|
||||
return layer & 0xffff0000 | version;
|
||||
}
|
||||
|
||||
public static int setPeerLayerVersion(int layer, int version) {
|
||||
return layer & 0x0000ffff | (version << 16);
|
||||
}
|
||||
|
||||
public static void RunOnUIThread(Runnable runnable) {
|
||||
RunOnUIThread(runnable, 0);
|
||||
}
|
||||
|
@ -375,32 +388,4 @@ public class AndroidUtilities {
|
|||
}
|
||||
return photoSize;
|
||||
}
|
||||
|
||||
public static void ShowProgressDialog(final Activity activity, final String message) {
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if(activity != null && !activity.isFinishing()) {
|
||||
progressDialog = new ProgressDialog(activity);
|
||||
if (message != null) {
|
||||
progressDialog.setMessage(message);
|
||||
}
|
||||
progressDialog.setCanceledOnTouchOutside(false);
|
||||
progressDialog.setCancelable(false);
|
||||
progressDialog.show();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void HideProgressDialog() {
|
||||
RunOnUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (progressDialog != null) {
|
||||
progressDialog.dismiss();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -616,7 +616,7 @@ public class MessageObject {
|
|||
}
|
||||
|
||||
public boolean isSecretMedia() {
|
||||
return messageOwner.media instanceof TLRPC.TL_messageMediaPhoto && messageOwner.ttl != 0 && messageOwner.ttl <= 60;
|
||||
return messageOwner instanceof TLRPC.TL_message_secret && messageOwner.media instanceof TLRPC.TL_messageMediaPhoto && messageOwner.ttl != 0 && messageOwner.ttl <= 60;
|
||||
}
|
||||
|
||||
public static void setIsUnread(TLRPC.Message message, boolean unread) {
|
||||
|
|
|
@ -71,6 +71,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
|
|||
private boolean gettingNewDeleteTask = false;
|
||||
private int currentDeletingTaskTime = 0;
|
||||
private ArrayList<Integer> currentDeletingTaskMids = null;
|
||||
private Runnable currentDeleteTaskRunnable = null;
|
||||
|
||||
public int totalDialogsCount = 0;
|
||||
public boolean loadingDialogs = false;
|
||||
|
@ -336,6 +337,12 @@ public class MessagesController implements NotificationCenter.NotificationCenter
|
|||
startingSecretChat = false;
|
||||
statusRequest = 0;
|
||||
statusSettingState = 0;
|
||||
|
||||
if (currentDeleteTaskRunnable != null) {
|
||||
Utilities.stageQueue.cancelRunnable(currentDeleteTaskRunnable);
|
||||
currentDeleteTaskRunnable = null;
|
||||
}
|
||||
|
||||
addSupportUser();
|
||||
}
|
||||
|
||||
|
@ -530,11 +537,15 @@ public class MessagesController implements NotificationCenter.NotificationCenter
|
|||
});
|
||||
}
|
||||
|
||||
private void checkDeletingTask() {
|
||||
private boolean checkDeletingTask(boolean runnable) {
|
||||
int currentServerTime = ConnectionsManager.getInstance().getCurrentTime();
|
||||
|
||||
if (currentDeletingTaskMids != null && currentDeletingTaskTime != 0 && currentDeletingTaskTime <= currentServerTime) {
|
||||
if (currentDeletingTaskMids != null && (runnable || currentDeletingTaskTime != 0 && currentDeletingTaskTime <= currentServerTime)) {
|
||||
currentDeletingTaskTime = 0;
|
||||
if (currentDeleteTaskRunnable != null && !runnable) {
|
||||
Utilities.stageQueue.cancelRunnable(currentDeleteTaskRunnable);
|
||||
}
|
||||
currentDeleteTaskRunnable = null;
|
||||
AndroidUtilities.RunOnUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -550,7 +561,9 @@ public class MessagesController implements NotificationCenter.NotificationCenter
|
|||
});
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void processLoadedDeleteTask(final int taskTime, final ArrayList<Integer> messages) {
|
||||
|
@ -562,7 +575,21 @@ public class MessagesController implements NotificationCenter.NotificationCenter
|
|||
currentDeletingTaskTime = taskTime;
|
||||
currentDeletingTaskMids = messages;
|
||||
|
||||
checkDeletingTask();
|
||||
if (currentDeleteTaskRunnable != null) {
|
||||
Utilities.stageQueue.cancelRunnable(currentDeleteTaskRunnable);
|
||||
currentDeleteTaskRunnable = null;
|
||||
}
|
||||
|
||||
if (!checkDeletingTask(false)) {
|
||||
currentDeleteTaskRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
checkDeletingTask(true);
|
||||
}
|
||||
};
|
||||
int currentServerTime = ConnectionsManager.getInstance().getCurrentTime();
|
||||
Utilities.stageQueue.postRunnable(currentDeleteTaskRunnable, (long)Math.abs(currentServerTime - currentDeletingTaskTime) * 1000);
|
||||
}
|
||||
} else {
|
||||
currentDeletingTaskTime = 0;
|
||||
currentDeletingTaskMids = null;
|
||||
|
@ -1069,7 +1096,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
|
|||
public void updateTimerProc() {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
|
||||
checkDeletingTask();
|
||||
checkDeletingTask(false);
|
||||
|
||||
if (UserConfig.isClientActivated()) {
|
||||
if (ConnectionsManager.getInstance().getPauseTime() == 0 && ApplicationLoader.isScreenOn && !ApplicationLoader.mainInterfacePaused) {
|
||||
|
@ -3499,7 +3526,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
|
|||
}
|
||||
|
||||
public TLRPC.Message decryptMessage(TLRPC.EncryptedMessage message) {
|
||||
TLRPC.EncryptedChat chat = getEncryptedChatDB(message.chat_id);
|
||||
final TLRPC.EncryptedChat chat = getEncryptedChatDB(message.chat_id);
|
||||
if (chat == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -3522,9 +3549,18 @@ public class MessagesController implements NotificationCenter.NotificationCenter
|
|||
from_id = chat.participant_id;
|
||||
}
|
||||
|
||||
if (object instanceof TLRPC.TL_decryptedMessageLayer) {
|
||||
object = ((TLRPC.TL_decryptedMessageLayer) object).message;
|
||||
}
|
||||
|
||||
if (object instanceof TLRPC.TL_decryptedMessage) {
|
||||
TLRPC.TL_decryptedMessage decryptedMessage = (TLRPC.TL_decryptedMessage)object;
|
||||
TLRPC.TL_message_secret newMessage = new TLRPC.TL_message_secret();
|
||||
TLRPC.TL_message newMessage = null;
|
||||
if (AndroidUtilities.getPeerLayerVersion(chat.layer) >= 17) {
|
||||
newMessage = new TLRPC.TL_message_secret();
|
||||
} else {
|
||||
newMessage = new TLRPC.TL_message();
|
||||
}
|
||||
newMessage.message = decryptedMessage.message;
|
||||
newMessage.date = message.date;
|
||||
newMessage.local_id = newMessage.id = UserConfig.getNewMessageId();
|
||||
|
@ -3666,7 +3702,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
|
|||
}
|
||||
return newMessage;
|
||||
} else if (object instanceof TLRPC.TL_decryptedMessageService) {
|
||||
TLRPC.TL_decryptedMessageService serviceMessage = (TLRPC.TL_decryptedMessageService)object;
|
||||
final TLRPC.TL_decryptedMessageService serviceMessage = (TLRPC.TL_decryptedMessageService)object;
|
||||
if (serviceMessage.action instanceof TLRPC.TL_decryptedMessageActionSetMessageTTL || serviceMessage.action instanceof TLRPC.TL_decryptedMessageActionScreenshotMessages) {
|
||||
TLRPC.TL_messageService newMessage = new TLRPC.TL_messageService();
|
||||
if (serviceMessage.action instanceof TLRPC.TL_decryptedMessageActionSetMessageTTL) {
|
||||
|
@ -3727,6 +3763,19 @@ public class MessagesController implements NotificationCenter.NotificationCenter
|
|||
if (!serviceMessage.action.random_ids.isEmpty()) {
|
||||
MessagesStorage.getInstance().createTaskForSecretChat(chat.id, 0, message.date, 1, serviceMessage.action.random_ids);
|
||||
}
|
||||
} else if (serviceMessage.action instanceof TLRPC.TL_decryptedMessageActionNotifyLayer) {
|
||||
AndroidUtilities.RunOnUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int currentPeerLayer = AndroidUtilities.getPeerLayerVersion(chat.layer);
|
||||
chat.layer = 0;
|
||||
chat.layer = AndroidUtilities.setPeerLayerVersion(chat.layer, serviceMessage.action.layer);
|
||||
MessagesStorage.getInstance().updateEncryptedChatLayer(chat);
|
||||
if (currentPeerLayer < 17) {
|
||||
SendMessagesHelper.getInstance().sendNotifyLayerMessage(chat);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ public class MessagesStorage {
|
|||
database.executeFast("CREATE TABLE users(uid INTEGER PRIMARY KEY, name TEXT, status INTEGER, data BLOB)").stepThis().dispose();
|
||||
database.executeFast("CREATE TABLE messages(mid INTEGER PRIMARY KEY, uid INTEGER, read_state INTEGER, send_state INTEGER, date INTEGER, data BLOB, out INTEGER, ttl INTEGER, media INTEGER)").stepThis().dispose();
|
||||
database.executeFast("CREATE TABLE chats(uid INTEGER PRIMARY KEY, name TEXT, data BLOB)").stepThis().dispose();
|
||||
database.executeFast("CREATE TABLE enc_chats(uid INTEGER PRIMARY KEY, user INTEGER, name TEXT, data BLOB, g BLOB, authkey BLOB, ttl INTEGER)").stepThis().dispose();
|
||||
database.executeFast("CREATE TABLE enc_chats(uid INTEGER PRIMARY KEY, user INTEGER, name TEXT, data BLOB, g BLOB, authkey BLOB, ttl INTEGER, layer INTEGER)").stepThis().dispose();
|
||||
database.executeFast("CREATE TABLE dialogs(did INTEGER PRIMARY KEY, date INTEGER, unread_count INTEGER, last_mid INTEGER)").stepThis().dispose();
|
||||
database.executeFast("CREATE TABLE chat_settings(uid INTEGER PRIMARY KEY, participants BLOB)").stepThis().dispose();
|
||||
database.executeFast("CREATE TABLE contacts(uid INTEGER PRIMARY KEY, mutual INTEGER)").stepThis().dispose();
|
||||
|
@ -136,7 +136,7 @@ public class MessagesStorage {
|
|||
database.executeFast("CREATE INDEX IF NOT EXISTS mid_out_idx_messages ON messages(mid, out);").stepThis().dispose();
|
||||
database.executeFast("CREATE INDEX IF NOT EXISTS task_idx_messages ON messages(uid, out, read_state, ttl, date, send_state);").stepThis().dispose();
|
||||
database.executeFast("CREATE INDEX IF NOT EXISTS send_state_idx_messages ON messages(mid, send_state, date) WHERE mid < 0 AND send_state = 1;").stepThis().dispose();
|
||||
database.executeFast("PRAGMA user_version = 6").stepThis().dispose();
|
||||
database.executeFast("PRAGMA user_version = 7").stepThis().dispose();
|
||||
} else {
|
||||
try {
|
||||
SQLiteCursor cursor = database.queryFinalized("SELECT seq, pts, date, qts, lsv, sg, pbytes FROM params WHERE id = 1");
|
||||
|
@ -168,7 +168,7 @@ public class MessagesStorage {
|
|||
}
|
||||
|
||||
int version = database.executeInt("PRAGMA user_version");
|
||||
if (version < 6) {
|
||||
if (version < 7) {
|
||||
updateDbToLastVersion(version);
|
||||
}
|
||||
}
|
||||
|
@ -291,7 +291,7 @@ public class MessagesStorage {
|
|||
}
|
||||
if (version == 6 && version < 7) {
|
||||
database.executeFast("ALTER TABLE enc_chats ADD COLUMN layer INTEGER default 0").stepThis().dispose();
|
||||
database.executeFast("PRAGMA user_version = 6").stepThis().dispose();
|
||||
database.executeFast("PRAGMA user_version = 7").stepThis().dispose();
|
||||
version = 7;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@ -491,7 +491,7 @@ public class MessagesStorage {
|
|||
|
||||
if (!encryptedChatIds.isEmpty()) {
|
||||
String stringToLoad = TextUtils.join(",", encryptedChatIds);
|
||||
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, user, g, authkey, ttl FROM enc_chats WHERE uid IN(%s)", stringToLoad));
|
||||
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, user, g, authkey, ttl, layer 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) {
|
||||
|
@ -504,6 +504,7 @@ public class MessagesStorage {
|
|||
chat.a_or_b = cursor.byteArrayValue(2);
|
||||
chat.auth_key = cursor.byteArrayValue(3);
|
||||
chat.ttl = cursor.intValue(4);
|
||||
chat.layer = cursor.intValue(5);
|
||||
}
|
||||
buffersStorage.reuseFreeBuffer(data);
|
||||
}
|
||||
|
@ -1231,7 +1232,7 @@ public class MessagesStorage {
|
|||
cursor.dispose();
|
||||
|
||||
if (needEncrypted) {
|
||||
cursor = database.queryFinalized("SELECT q.data, q.name, q.user, q.g, q.authkey, q.ttl, u.data, u.status 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 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);
|
||||
if (name.startsWith(q) || name.contains(" " + q)) {
|
||||
|
@ -1243,6 +1244,7 @@ public class MessagesStorage {
|
|||
chat.a_or_b = cursor.byteArrayValue(3);
|
||||
chat.auth_key = cursor.byteArrayValue(4);
|
||||
chat.ttl = cursor.intValue(5);
|
||||
chat.layer = cursor.intValue(8);
|
||||
|
||||
TLRPC.User user = (TLRPC.User)TLClassStore.Instance().TLdeserialize(data2, data2.readInt32());
|
||||
if (user.status != null) {
|
||||
|
@ -1718,7 +1720,7 @@ public class MessagesStorage {
|
|||
|
||||
if (!encryptedChatIds.isEmpty()) {
|
||||
String stringToLoad = TextUtils.join(",", encryptedChatIds);
|
||||
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, user, g, authkey, ttl FROM enc_chats WHERE uid IN(%s)", stringToLoad));
|
||||
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, user, g, authkey, ttl, layer 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) {
|
||||
|
@ -1731,6 +1733,7 @@ public class MessagesStorage {
|
|||
chat.a_or_b = cursor.byteArrayValue(2);
|
||||
chat.auth_key = cursor.byteArrayValue(3);
|
||||
chat.ttl = cursor.intValue(4);
|
||||
chat.layer = cursor.intValue(5);
|
||||
}
|
||||
buffersStorage.reuseFreeBuffer(data);
|
||||
}
|
||||
|
@ -2147,6 +2150,30 @@ public class MessagesStorage {
|
|||
});
|
||||
}
|
||||
|
||||
public void updateEncryptedChatLayer(final TLRPC.EncryptedChat chat) {
|
||||
if (chat == null) {
|
||||
return;
|
||||
}
|
||||
storageQueue.postRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SQLitePreparedStatement state = null;
|
||||
try {
|
||||
state = database.executeFast("UPDATE enc_chats SET layer = ? WHERE uid = ?");
|
||||
state.bindInteger(1, chat.layer);
|
||||
state.bindInteger(2, chat.id);
|
||||
state.step();
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
} finally {
|
||||
if (state != null) {
|
||||
state.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void updateEncryptedChat(final TLRPC.EncryptedChat chat) {
|
||||
if (chat == null) {
|
||||
return;
|
||||
|
@ -2156,7 +2183,7 @@ public class MessagesStorage {
|
|||
public void run() {
|
||||
SQLitePreparedStatement state = null;
|
||||
try {
|
||||
state = database.executeFast("UPDATE enc_chats SET data = ?, g = ?, authkey = ?, ttl = ? WHERE uid = ?");
|
||||
state = database.executeFast("UPDATE enc_chats SET data = ?, g = ?, authkey = ?, ttl = ?, layer = ? WHERE uid = ?");
|
||||
ByteBufferDesc data = buffersStorage.getFreeBuffer(chat.getObjectSize());
|
||||
ByteBufferDesc data2 = buffersStorage.getFreeBuffer(chat.a_or_b != null ? chat.a_or_b.length : 1);
|
||||
ByteBufferDesc data3 = buffersStorage.getFreeBuffer(chat.auth_key != null ? chat.auth_key.length : 1);
|
||||
|
@ -2172,6 +2199,7 @@ public class MessagesStorage {
|
|||
state.bindByteBuffer(3, data3.buffer);
|
||||
state.bindInteger(4, chat.ttl);
|
||||
state.bindInteger(5, chat.id);
|
||||
state.bindInteger(6, chat.layer);
|
||||
state.step();
|
||||
buffersStorage.reuseFreeBuffer(data);
|
||||
buffersStorage.reuseFreeBuffer(data2);
|
||||
|
@ -2196,7 +2224,7 @@ public class MessagesStorage {
|
|||
public void run() {
|
||||
try {
|
||||
int userToLoad = 0;
|
||||
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, user, g, authkey, ttl FROM enc_chats WHERE uid = %d", chat_id));
|
||||
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, user, g, authkey, ttl, layer 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) {
|
||||
|
@ -2207,6 +2235,7 @@ public class MessagesStorage {
|
|||
chat.a_or_b = cursor.byteArrayValue(2);
|
||||
chat.auth_key = cursor.byteArrayValue(3);
|
||||
chat.ttl = cursor.intValue(4);
|
||||
chat.layer = cursor.intValue(5);
|
||||
}
|
||||
buffersStorage.reuseFreeBuffer(data);
|
||||
}
|
||||
|
@ -2247,7 +2276,7 @@ public class MessagesStorage {
|
|||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
SQLitePreparedStatement state = database.executeFast("REPLACE INTO enc_chats VALUES(?, ?, ?, ?, ?, ?, ?)");
|
||||
SQLitePreparedStatement state = database.executeFast("REPLACE INTO enc_chats VALUES(?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
ByteBufferDesc data = buffersStorage.getFreeBuffer(chat.getObjectSize());
|
||||
ByteBufferDesc data2 = buffersStorage.getFreeBuffer(chat.a_or_b != null ? chat.a_or_b.length : 1);
|
||||
ByteBufferDesc data3 = buffersStorage.getFreeBuffer(chat.auth_key != null ? chat.auth_key.length : 1);
|
||||
|
@ -2271,6 +2300,7 @@ public class MessagesStorage {
|
|||
state.bindByteBuffer(5, data2.buffer);
|
||||
state.bindByteBuffer(6, data3.buffer);
|
||||
state.bindInteger(7, chat.ttl);
|
||||
state.bindInteger(8, chat.layer);
|
||||
state.step();
|
||||
state.dispose();
|
||||
buffersStorage.reuseFreeBuffer(data);
|
||||
|
@ -2441,7 +2471,7 @@ public class MessagesStorage {
|
|||
}
|
||||
|
||||
private int getMessageMediaType(TLRPC.Message message) {
|
||||
if (message.media instanceof TLRPC.TL_messageMediaPhoto && message.ttl != 0 && message.ttl <= 60) {
|
||||
if (message instanceof TLRPC.TL_message_secret && message.media instanceof TLRPC.TL_messageMediaPhoto && message.ttl != 0 && message.ttl <= 60) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
@ -2482,7 +2512,7 @@ public class MessagesStorage {
|
|||
messagesIdsMap.put(message.id, dialog_id);
|
||||
}
|
||||
|
||||
if (message.media instanceof TLRPC.TL_messageMediaVideo || message.media instanceof TLRPC.TL_messageMediaPhoto && (message.ttl == 0 || message.ttl > 60)) {
|
||||
if (getMessageMediaType(message) == 0) {
|
||||
if (messageMediaIds.length() > 0) {
|
||||
messageMediaIds.append(",");
|
||||
}
|
||||
|
@ -2566,7 +2596,7 @@ public class MessagesStorage {
|
|||
state3.step();
|
||||
}
|
||||
|
||||
if (message.media instanceof TLRPC.TL_messageMediaVideo || message.media instanceof TLRPC.TL_messageMediaPhoto && (message.ttl == 0 || message.ttl > 60)) {
|
||||
if (getMessageMediaType(message) == 0) {
|
||||
state2.requery();
|
||||
state2.bindInteger(1, messageId);
|
||||
state2.bindLong(2, dialog_id);
|
||||
|
@ -3128,7 +3158,7 @@ public class MessagesStorage {
|
|||
|
||||
if (!encryptedToLoad.isEmpty()) {
|
||||
String toLoad = TextUtils.join(",", encryptedToLoad);
|
||||
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, user, g, authkey, ttl FROM enc_chats WHERE uid IN(%s)", toLoad));
|
||||
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, user, g, authkey, ttl, layer 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) {
|
||||
|
@ -3141,6 +3171,7 @@ public class MessagesStorage {
|
|||
chat.a_or_b = cursor.byteArrayValue(2);
|
||||
chat.auth_key = cursor.byteArrayValue(3);
|
||||
chat.ttl = cursor.intValue(4);
|
||||
chat.layer = cursor.intValue(5);
|
||||
}
|
||||
buffersStorage.reuseFreeBuffer(data);
|
||||
}
|
||||
|
@ -3242,7 +3273,7 @@ public class MessagesStorage {
|
|||
state.bindByteBuffer(6, data.buffer);
|
||||
state.bindInteger(7, (MessageObject.isOut(message) ? 1 : 0));
|
||||
state.bindInteger(8, 0);
|
||||
state.bindInteger(9, getMessageMediaType(message));
|
||||
state.bindInteger(9, 0);
|
||||
state.step();
|
||||
|
||||
if (message.media instanceof TLRPC.TL_messageMediaVideo || message.media instanceof TLRPC.TL_messageMediaPhoto) {
|
||||
|
@ -3384,7 +3415,7 @@ public class MessagesStorage {
|
|||
|
||||
if (!encryptedToLoad.isEmpty()) {
|
||||
String toLoad = TextUtils.join(",", encryptedToLoad);
|
||||
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, user, g, authkey, ttl FROM enc_chats WHERE uid IN(%s)", toLoad));
|
||||
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, user, g, authkey, ttl, layer FROM enc_chats WHERE uid IN(%s)", toLoad));
|
||||
while (cursor.next()) {
|
||||
try {
|
||||
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
|
||||
|
@ -3399,6 +3430,7 @@ public class MessagesStorage {
|
|||
chat.a_or_b = cursor.byteArrayValue(2);
|
||||
chat.auth_key = cursor.byteArrayValue(3);
|
||||
chat.ttl = cursor.intValue(4);
|
||||
chat.layer = cursor.intValue(5);
|
||||
}
|
||||
}
|
||||
buffersStorage.reuseFreeBuffer(data);
|
||||
|
@ -3509,7 +3541,7 @@ public class MessagesStorage {
|
|||
state.bindByteBuffer(6, data.buffer);
|
||||
state.bindInteger(7, (MessageObject.isOut(message) ? 1 : 0));
|
||||
state.bindInteger(8, 0);
|
||||
state.bindInteger(9, getMessageMediaType(message));
|
||||
state.bindInteger(9, 0);
|
||||
state.step();
|
||||
|
||||
state2.bindLong(1, uid);
|
||||
|
@ -3672,7 +3704,7 @@ 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 FROM enc_chats WHERE uid = %d", chat_id));
|
||||
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, user, g, authkey, ttl, layer 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) {
|
||||
|
@ -3682,6 +3714,7 @@ public class MessagesStorage {
|
|||
chat.a_or_b = cursor.byteArrayValue(2);
|
||||
chat.auth_key = cursor.byteArrayValue(3);
|
||||
chat.ttl = cursor.intValue(4);
|
||||
chat.layer = cursor.intValue(5);
|
||||
}
|
||||
}
|
||||
buffersStorage.reuseFreeBuffer(data);
|
||||
|
|
|
@ -29,9 +29,12 @@ import java.util.HashMap;
|
|||
|
||||
public class SendMessagesHelper implements NotificationCenter.NotificationCenterDelegate {
|
||||
|
||||
public static final int CURRENT_SECRET_CHAT_LAYER = 17;
|
||||
|
||||
private TLRPC.ChatParticipants currentChatInfo = null;
|
||||
private HashMap<String, ArrayList<DelayedMessage>> delayedMessages = new HashMap<String, ArrayList<DelayedMessage>>();
|
||||
private HashMap<Integer, MessageObject> unsentMessages = new HashMap<Integer, MessageObject>();
|
||||
private ArrayList<Integer> sendingNotifyLayer = new ArrayList<Integer>();
|
||||
|
||||
private class DelayedMessage {
|
||||
public TLObject sendRequest;
|
||||
|
@ -70,6 +73,8 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
|
|||
|
||||
public void cleanUp() {
|
||||
delayedMessages.clear();
|
||||
sendingNotifyLayer.clear();
|
||||
unsentMessages.clear();
|
||||
currentChatInfo = null;
|
||||
}
|
||||
|
||||
|
@ -135,7 +140,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
|
|||
} else if (encryptedFile != null && message.sendEncryptedRequest != null) {
|
||||
message.sendEncryptedRequest.media.key = encryptedFile.key;
|
||||
message.sendEncryptedRequest.media.iv = encryptedFile.iv;
|
||||
performSendEncryptedRequest(message.sendEncryptedRequest, message.obj, message.encryptedChat, encryptedFile, message.originalPath);
|
||||
performSendEncryptedRequest(message.sendEncryptedRequest, message.obj, message.encryptedChat, encryptedFile, message.originalPath, null);
|
||||
arr.remove(a);
|
||||
a--;
|
||||
}
|
||||
|
@ -366,6 +371,12 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
|
|||
int type = -1;
|
||||
int lower_id = (int) peer;
|
||||
int high_id = (int) (peer >> 32);
|
||||
TLRPC.EncryptedChat encryptedChat = null;
|
||||
TLRPC.InputPeer sendToPeer = null;
|
||||
ArrayList<TLRPC.InputUser> sendToPeers = null;
|
||||
if (lower_id == 0) {
|
||||
encryptedChat = MessagesController.getInstance().getEncryptedChat(high_id);
|
||||
}
|
||||
|
||||
if (retry) {
|
||||
newMsg = msgObj.messageOwner;
|
||||
|
@ -412,19 +423,19 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
|
|||
}
|
||||
} else {
|
||||
if (message != null) {
|
||||
if (lower_id != 0) {
|
||||
newMsg = new TLRPC.TL_message();
|
||||
} else {
|
||||
if (encryptedChat != null && AndroidUtilities.getPeerLayerVersion(encryptedChat.layer) >= 17) {
|
||||
newMsg = new TLRPC.TL_message_secret();
|
||||
} else {
|
||||
newMsg = new TLRPC.TL_message();
|
||||
}
|
||||
newMsg.media = new TLRPC.TL_messageMediaEmpty();
|
||||
type = 0;
|
||||
newMsg.message = message;
|
||||
} else if (lat != null && lon != null) {
|
||||
if (lower_id != 0) {
|
||||
newMsg = new TLRPC.TL_message();
|
||||
} else {
|
||||
if (encryptedChat != null && AndroidUtilities.getPeerLayerVersion(encryptedChat.layer) >= 17) {
|
||||
newMsg = new TLRPC.TL_message_secret();
|
||||
} else {
|
||||
newMsg = new TLRPC.TL_message();
|
||||
}
|
||||
newMsg.media = new TLRPC.TL_messageMediaGeo();
|
||||
newMsg.media.geo = new TLRPC.TL_geoPoint();
|
||||
|
@ -433,10 +444,10 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
|
|||
newMsg.message = "";
|
||||
type = 1;
|
||||
} else if (photo != null) {
|
||||
if (lower_id != 0) {
|
||||
newMsg = new TLRPC.TL_message();
|
||||
} else {
|
||||
if (encryptedChat != null && AndroidUtilities.getPeerLayerVersion(encryptedChat.layer) >= 17) {
|
||||
newMsg = new TLRPC.TL_message_secret();
|
||||
} else {
|
||||
newMsg = new TLRPC.TL_message();
|
||||
}
|
||||
newMsg.media = new TLRPC.TL_messageMediaPhoto();
|
||||
newMsg.media.photo = photo;
|
||||
|
@ -445,10 +456,10 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
|
|||
TLRPC.FileLocation location1 = photo.sizes.get(photo.sizes.size() - 1).location;
|
||||
newMsg.attachPath = FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE) + "/" + location1.volume_id + "_" + location1.local_id + ".jpg";
|
||||
} else if (video != null) {
|
||||
if (lower_id != 0) {
|
||||
newMsg = new TLRPC.TL_message();
|
||||
} else {
|
||||
if (encryptedChat != null && AndroidUtilities.getPeerLayerVersion(encryptedChat.layer) >= 17) {
|
||||
newMsg = new TLRPC.TL_message_secret();
|
||||
} else {
|
||||
newMsg = new TLRPC.TL_message();
|
||||
}
|
||||
newMsg.media = new TLRPC.TL_messageMediaVideo();
|
||||
newMsg.media.video = video;
|
||||
|
@ -480,10 +491,10 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
|
|||
type = 4;
|
||||
}
|
||||
} else if (user != null) {
|
||||
if (lower_id != 0) {
|
||||
newMsg = new TLRPC.TL_message();
|
||||
} else {
|
||||
if (encryptedChat != null && AndroidUtilities.getPeerLayerVersion(encryptedChat.layer) >= 17) {
|
||||
newMsg = new TLRPC.TL_message_secret();
|
||||
} else {
|
||||
newMsg = new TLRPC.TL_message();
|
||||
}
|
||||
newMsg.media = new TLRPC.TL_messageMediaContact();
|
||||
newMsg.media.phone_number = user.phone;
|
||||
|
@ -493,10 +504,10 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
|
|||
newMsg.message = "";
|
||||
type = 6;
|
||||
} else if (document != null) {
|
||||
if (lower_id != 0) {
|
||||
newMsg = new TLRPC.TL_message();
|
||||
} else {
|
||||
if (encryptedChat != null && AndroidUtilities.getPeerLayerVersion(encryptedChat.layer) >= 17) {
|
||||
newMsg = new TLRPC.TL_message_secret();
|
||||
} else {
|
||||
newMsg = new TLRPC.TL_message();
|
||||
}
|
||||
newMsg.media = new TLRPC.TL_messageMediaDocument();
|
||||
newMsg.media.document = document;
|
||||
|
@ -504,10 +515,10 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
|
|||
newMsg.message = "-1";
|
||||
newMsg.attachPath = path;
|
||||
} else if (audio != null) {
|
||||
if (lower_id != 0) {
|
||||
newMsg = new TLRPC.TL_message();
|
||||
} else {
|
||||
if (encryptedChat != null && AndroidUtilities.getPeerLayerVersion(encryptedChat.layer) >= 17) {
|
||||
newMsg = new TLRPC.TL_message_secret();
|
||||
} else {
|
||||
newMsg = new TLRPC.TL_message();
|
||||
}
|
||||
newMsg.media = new TLRPC.TL_messageMediaAudio();
|
||||
newMsg.media.audio = audio;
|
||||
|
@ -526,9 +537,6 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
|
|||
newMsg.date = ConnectionsManager.getInstance().getCurrentTime();
|
||||
newMsg.flags |= TLRPC.MESSAGE_FLAG_UNREAD;
|
||||
newMsg.dialog_id = peer;
|
||||
TLRPC.EncryptedChat encryptedChat = null;
|
||||
TLRPC.InputPeer sendToPeer = null;
|
||||
ArrayList<TLRPC.InputUser> sendToPeers = null;
|
||||
if (lower_id != 0) {
|
||||
if (high_id == 1) {
|
||||
if (currentChatInfo == null) {
|
||||
|
@ -571,7 +579,6 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
|
|||
}
|
||||
}
|
||||
} else {
|
||||
encryptedChat = MessagesController.getInstance().getEncryptedChat(high_id);
|
||||
newMsg.to_id = new TLRPC.TL_peerUser();
|
||||
if (encryptedChat.participant_id == UserConfig.getClientUserId()) {
|
||||
newMsg.to_id.user_id = encryptedChat.admin_id;
|
||||
|
@ -581,7 +588,6 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
|
|||
newMsg.ttl = encryptedChat.ttl;
|
||||
}
|
||||
|
||||
|
||||
MessageObject newMsgObj = new MessageObject(newMsg, null, 2);
|
||||
newMsgObj.messageOwner.send_state = MessageObject.MESSAGE_SEND_STATE_SENDING;
|
||||
|
||||
|
@ -616,7 +622,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
|
|||
Utilities.random.nextBytes(reqSend.random_bytes);
|
||||
reqSend.message = message;
|
||||
reqSend.media = new TLRPC.TL_decryptedMessageMediaEmpty();
|
||||
performSendEncryptedRequest(reqSend, newMsgObj, encryptedChat, null, null);
|
||||
performSendEncryptedRequest(reqSend, newMsgObj, encryptedChat, null, null, null);
|
||||
}
|
||||
} else if (type >= 1 && type <= 3 || type >= 5 && type <= 8) {
|
||||
if (encryptedChat == null) {
|
||||
|
@ -771,7 +777,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
|
|||
reqSend.media = new TLRPC.TL_decryptedMessageMediaGeoPoint();
|
||||
reqSend.media.lat = lat;
|
||||
reqSend.media._long = lon;
|
||||
performSendEncryptedRequest(reqSend, newMsgObj, encryptedChat, null, null);
|
||||
performSendEncryptedRequest(reqSend, newMsgObj, encryptedChat, null, null, null);
|
||||
} else if (type == 2) {
|
||||
TLRPC.PhotoSize small = photo.sizes.get(0);
|
||||
TLRPC.PhotoSize big = photo.sizes.get(photo.sizes.size() - 1);
|
||||
|
@ -797,10 +803,14 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
|
|||
encryptedFile.access_hash = big.location.secret;
|
||||
reqSend.media.key = big.location.key;
|
||||
reqSend.media.iv = big.location.iv;
|
||||
performSendEncryptedRequest(reqSend, newMsgObj, encryptedChat, encryptedFile, null);
|
||||
performSendEncryptedRequest(reqSend, newMsgObj, encryptedChat, encryptedFile, null, null);
|
||||
}
|
||||
} else if (type == 3) {
|
||||
if (AndroidUtilities.getPeerLayerVersion(encryptedChat.layer) >= 17) {
|
||||
reqSend.media = new TLRPC.TL_decryptedMessageMediaVideo();
|
||||
} else {
|
||||
reqSend.media = new TLRPC.TL_decryptedMessageMediaVideo_old();
|
||||
}
|
||||
reqSend.media.duration = video.duration;
|
||||
reqSend.media.size = video.size;
|
||||
reqSend.media.w = video.w;
|
||||
|
@ -824,7 +834,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
|
|||
encryptedFile.access_hash = video.access_hash;
|
||||
reqSend.media.key = video.key;
|
||||
reqSend.media.iv = video.iv;
|
||||
performSendEncryptedRequest(reqSend, newMsgObj, encryptedChat, encryptedFile, null);
|
||||
performSendEncryptedRequest(reqSend, newMsgObj, encryptedChat, encryptedFile, null, null);
|
||||
}
|
||||
} else if (type == 6) {
|
||||
reqSend.media = new TLRPC.TL_decryptedMessageMediaContact();
|
||||
|
@ -832,7 +842,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
|
|||
reqSend.media.first_name = user.first_name;
|
||||
reqSend.media.last_name = user.last_name;
|
||||
reqSend.media.user_id = user.id;
|
||||
performSendEncryptedRequest(reqSend, newMsgObj, encryptedChat, null, null);
|
||||
performSendEncryptedRequest(reqSend, newMsgObj, encryptedChat, null, null, null);
|
||||
} else if (type == 7) {
|
||||
reqSend.media = new TLRPC.TL_decryptedMessageMediaDocument();
|
||||
reqSend.media.size = document.size;
|
||||
|
@ -862,10 +872,14 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
|
|||
encryptedFile.access_hash = document.access_hash;
|
||||
reqSend.media.key = document.key;
|
||||
reqSend.media.iv = document.iv;
|
||||
performSendEncryptedRequest(reqSend, newMsgObj, encryptedChat, encryptedFile, null);
|
||||
performSendEncryptedRequest(reqSend, newMsgObj, encryptedChat, encryptedFile, null, null);
|
||||
}
|
||||
} else if (type == 8) {
|
||||
if (AndroidUtilities.getPeerLayerVersion(encryptedChat.layer) >= 17) {
|
||||
reqSend.media = new TLRPC.TL_decryptedMessageMediaAudio();
|
||||
} else {
|
||||
reqSend.media = new TLRPC.TL_decryptedMessageMediaAudio_old();
|
||||
}
|
||||
reqSend.media.duration = audio.duration;
|
||||
reqSend.media.size = audio.size;
|
||||
reqSend.media.mime_type = "audio/ogg";
|
||||
|
@ -1102,14 +1116,28 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
|
|||
}), true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassCanCompress, ConnectionsManager.DEFAULT_DATACENTER_ID);
|
||||
}
|
||||
|
||||
private void performSendEncryptedRequest(final TLRPC.DecryptedMessage req, final MessageObject newMsgObj, final TLRPC.EncryptedChat chat, final TLRPC.InputEncryptedFile encryptedFile, final String originalPath) {
|
||||
private void performSendEncryptedRequest(final TLRPC.DecryptedMessage req, final MessageObject newMsgObj, final TLRPC.EncryptedChat chat, final TLRPC.InputEncryptedFile encryptedFile, final String originalPath, final Runnable callback) {
|
||||
if (req == null || chat.auth_key == null || chat instanceof TLRPC.TL_encryptedChatRequested || chat instanceof TLRPC.TL_encryptedChatWaiting) {
|
||||
return;
|
||||
}
|
||||
int len = req.getObjectSize();
|
||||
TLObject toEncryptObject = null;
|
||||
if (AndroidUtilities.getPeerLayerVersion(chat.layer) >= 17) {
|
||||
TLRPC.TL_decryptedMessageLayer layer = new TLRPC.TL_decryptedMessageLayer();
|
||||
layer.layer = CURRENT_SECRET_CHAT_LAYER;
|
||||
layer.in_seq_no = 0; //TODO
|
||||
layer.out_seq_no = 0;
|
||||
layer.message = req;
|
||||
layer.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
|
||||
Utilities.random.nextBytes(layer.random_bytes);
|
||||
toEncryptObject = layer;
|
||||
} else {
|
||||
toEncryptObject = req;
|
||||
}
|
||||
|
||||
int len = toEncryptObject.getObjectSize();
|
||||
ByteBufferDesc toEncrypt = BuffersStorage.getInstance().getFreeBuffer(4 + len);
|
||||
toEncrypt.writeInt32(len);
|
||||
req.serializeToStream(toEncrypt);
|
||||
toEncryptObject.serializeToStream(toEncrypt);
|
||||
|
||||
byte[] messageKeyFull = Utilities.computeSHA1(toEncrypt.buffer);
|
||||
byte[] messageKey = new byte[16];
|
||||
|
@ -1162,6 +1190,9 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
|
|||
ConnectionsManager.getInstance().performRpc(reqToSend, new RPCRequest.RPCRequestDelegate() {
|
||||
@Override
|
||||
public void run(TLObject response, TLRPC.TL_error error) {
|
||||
if (error == null && callback != null) {
|
||||
callback.run();
|
||||
}
|
||||
if (newMsgObj != null) {
|
||||
if (error == null) {
|
||||
final String attachPath = newMsgObj.messageOwner.attachPath;
|
||||
|
@ -1436,38 +1467,89 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
|
|||
if (!(encryptedChat instanceof TLRPC.TL_encryptedChat)) {
|
||||
return;
|
||||
}
|
||||
TLRPC.TL_decryptedMessageService_old reqSend = new TLRPC.TL_decryptedMessageService_old();
|
||||
reqSend.random_id = getNextRandomId();
|
||||
reqSend.random_bytes = new byte[Math.max(1, (int)Math.ceil(Utilities.random.nextDouble() * 16))];
|
||||
TLRPC.TL_decryptedMessageService reqSend = null;
|
||||
if (AndroidUtilities.getPeerLayerVersion(encryptedChat.layer) >= 17) {
|
||||
reqSend = new TLRPC.TL_decryptedMessageService();
|
||||
} else {
|
||||
reqSend = new TLRPC.TL_decryptedMessageService_old();
|
||||
reqSend.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
|
||||
Utilities.random.nextBytes(reqSend.random_bytes);
|
||||
}
|
||||
reqSend.random_id = getNextRandomId();
|
||||
reqSend.action = new TLRPC.TL_decryptedMessageActionReadMessages();
|
||||
reqSend.action.random_ids = random_ids;
|
||||
performSendEncryptedRequest(reqSend, null, encryptedChat, null, null);
|
||||
performSendEncryptedRequest(reqSend, null, encryptedChat, null, null, null);
|
||||
}
|
||||
|
||||
public void sendMessagesDeleteMessage(ArrayList<Long> random_ids, TLRPC.EncryptedChat encryptedChat) {
|
||||
if (!(encryptedChat instanceof TLRPC.TL_encryptedChat)) {
|
||||
return;
|
||||
}
|
||||
TLRPC.TL_decryptedMessageService_old reqSend = new TLRPC.TL_decryptedMessageService_old();
|
||||
reqSend.random_id = getNextRandomId();
|
||||
reqSend.random_bytes = new byte[Math.max(1, (int)Math.ceil(Utilities.random.nextDouble() * 16))];
|
||||
TLRPC.TL_decryptedMessageService reqSend = null;
|
||||
if (AndroidUtilities.getPeerLayerVersion(encryptedChat.layer) >= 17) {
|
||||
reqSend = new TLRPC.TL_decryptedMessageService();
|
||||
} else {
|
||||
reqSend = new TLRPC.TL_decryptedMessageService_old();
|
||||
reqSend.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
|
||||
Utilities.random.nextBytes(reqSend.random_bytes);
|
||||
}
|
||||
reqSend.random_id = getNextRandomId();
|
||||
reqSend.action = new TLRPC.TL_decryptedMessageActionDeleteMessages();
|
||||
reqSend.action.random_ids = random_ids;
|
||||
performSendEncryptedRequest(reqSend, null, encryptedChat, null, null);
|
||||
performSendEncryptedRequest(reqSend, null, encryptedChat, null, null, null);
|
||||
}
|
||||
|
||||
public void sendClearHistoryMessage(TLRPC.EncryptedChat encryptedChat) {
|
||||
if (!(encryptedChat instanceof TLRPC.TL_encryptedChat)) {
|
||||
return;
|
||||
}
|
||||
TLRPC.TL_decryptedMessageService_old reqSend = new TLRPC.TL_decryptedMessageService_old();
|
||||
reqSend.random_id = getNextRandomId();
|
||||
reqSend.random_bytes = new byte[Math.max(1, (int)Math.ceil(Utilities.random.nextDouble() * 16))];
|
||||
TLRPC.TL_decryptedMessageService reqSend = null;
|
||||
if (AndroidUtilities.getPeerLayerVersion(encryptedChat.layer) >= 17) {
|
||||
reqSend = new TLRPC.TL_decryptedMessageService();
|
||||
} else {
|
||||
reqSend = new TLRPC.TL_decryptedMessageService_old();
|
||||
reqSend.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
|
||||
Utilities.random.nextBytes(reqSend.random_bytes);
|
||||
}
|
||||
reqSend.random_id = getNextRandomId();
|
||||
reqSend.action = new TLRPC.TL_decryptedMessageActionFlushHistory();
|
||||
performSendEncryptedRequest(reqSend, null, encryptedChat, null, null);
|
||||
performSendEncryptedRequest(reqSend, null, encryptedChat, null, null, null);
|
||||
}
|
||||
|
||||
public void sendNotifyLayerMessage(final TLRPC.EncryptedChat encryptedChat) {
|
||||
if (!(encryptedChat instanceof TLRPC.TL_encryptedChat)) {
|
||||
return;
|
||||
}
|
||||
if (sendingNotifyLayer.contains(encryptedChat.id)) {
|
||||
return;
|
||||
}
|
||||
sendingNotifyLayer.add(encryptedChat.id);
|
||||
TLRPC.TL_decryptedMessageService reqSend = null;
|
||||
if (AndroidUtilities.getPeerLayerVersion(encryptedChat.layer) >= 17) {
|
||||
reqSend = new TLRPC.TL_decryptedMessageService();
|
||||
} else {
|
||||
reqSend = new TLRPC.TL_decryptedMessageService_old();
|
||||
reqSend.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
|
||||
Utilities.random.nextBytes(reqSend.random_bytes);
|
||||
}
|
||||
reqSend.random_id = getNextRandomId();
|
||||
reqSend.action = new TLRPC.TL_decryptedMessageActionNotifyLayer();
|
||||
reqSend.action.layer = CURRENT_SECRET_CHAT_LAYER;
|
||||
Runnable callback = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
AndroidUtilities.RunOnUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
TLRPC.EncryptedChat chat = MessagesController.getInstance().getEncryptedChat(encryptedChat.id);
|
||||
sendingNotifyLayer.remove(chat.id);
|
||||
chat.layer = AndroidUtilities.setMyLayerVersion(chat.layer, CURRENT_SECRET_CHAT_LAYER);
|
||||
MessagesStorage.getInstance().updateEncryptedChatLayer(chat);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
performSendEncryptedRequest(reqSend, null, encryptedChat, null, null, callback);
|
||||
}
|
||||
|
||||
public void sendTTLMessage(TLRPC.EncryptedChat encryptedChat) {
|
||||
|
@ -1502,13 +1584,18 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
|
|||
MessagesController.getInstance().updateInterfaceWithMessages(newMsg.dialog_id, objArr);
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.dialogsNeedReload);
|
||||
|
||||
TLRPC.TL_decryptedMessageService_old reqSend = new TLRPC.TL_decryptedMessageService_old();
|
||||
reqSend.random_id = newMsg.random_id;
|
||||
reqSend.random_bytes = new byte[Math.max(1, (int)Math.ceil(Utilities.random.nextDouble() * 16))];
|
||||
TLRPC.TL_decryptedMessageService reqSend = null;
|
||||
if (AndroidUtilities.getPeerLayerVersion(encryptedChat.layer) >= 17) {
|
||||
reqSend = new TLRPC.TL_decryptedMessageService();
|
||||
} else {
|
||||
reqSend = new TLRPC.TL_decryptedMessageService_old();
|
||||
reqSend.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
|
||||
Utilities.random.nextBytes(reqSend.random_bytes);
|
||||
}
|
||||
reqSend.random_id = newMsg.random_id;
|
||||
reqSend.action = new TLRPC.TL_decryptedMessageActionSetMessageTTL();
|
||||
reqSend.action.ttl_seconds = encryptedChat.ttl;
|
||||
performSendEncryptedRequest(reqSend, newMsgObj, encryptedChat, null, null);
|
||||
performSendEncryptedRequest(reqSend, newMsgObj, encryptedChat, null, null, null);
|
||||
}
|
||||
|
||||
public void sendScreenshotMessage(TLRPC.EncryptedChat encryptedChat, ArrayList<Long> random_ids) {
|
||||
|
@ -1548,12 +1635,17 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
|
|||
MessagesController.getInstance().updateInterfaceWithMessages(newMsg.dialog_id, objArr);
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.dialogsNeedReload);
|
||||
|
||||
TLRPC.TL_decryptedMessageService_old reqSend = new TLRPC.TL_decryptedMessageService_old();
|
||||
reqSend.random_id = newMsg.random_id;
|
||||
reqSend.random_bytes = new byte[Math.max(1, (int)Math.ceil(Utilities.random.nextDouble() * 16))];
|
||||
TLRPC.TL_decryptedMessageService reqSend = null;
|
||||
if (AndroidUtilities.getPeerLayerVersion(encryptedChat.layer) >= 17) {
|
||||
reqSend = new TLRPC.TL_decryptedMessageService();
|
||||
} else {
|
||||
reqSend = new TLRPC.TL_decryptedMessageService_old();
|
||||
reqSend.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
|
||||
Utilities.random.nextBytes(reqSend.random_bytes);
|
||||
}
|
||||
reqSend.random_id = newMsg.random_id;
|
||||
reqSend.action = action;
|
||||
performSendEncryptedRequest(reqSend, newMsgObj, encryptedChat, null, null);
|
||||
performSendEncryptedRequest(reqSend, newMsgObj, encryptedChat, null, null, null);
|
||||
}
|
||||
|
||||
private void putToDelayedMessages(String location, DelayedMessage message) {
|
||||
|
|
|
@ -63,7 +63,7 @@ public class DispatchQueue extends Thread {
|
|||
postRunnable(runnable, 0);
|
||||
}
|
||||
|
||||
public void postRunnable(Runnable runnable, int delay) {
|
||||
public void postRunnable(Runnable runnable, long delay) {
|
||||
if (handler == null) {
|
||||
synchronized (handlerSyncObject) {
|
||||
if (handler == null) {
|
||||
|
|
|
@ -2557,8 +2557,6 @@ public class TLRPC {
|
|||
public static class DecryptedMessage extends TLObject {
|
||||
public long random_id;
|
||||
public byte[] random_bytes;
|
||||
public int in_seq_no;
|
||||
public int out_seq_no;
|
||||
public DecryptedMessageAction action;
|
||||
public int ttl;
|
||||
public String message;
|
||||
|
@ -2566,36 +2564,27 @@ public class TLRPC {
|
|||
}
|
||||
|
||||
public static class TL_decryptedMessageService extends DecryptedMessage {
|
||||
public static int constructor = 0xda431693;
|
||||
public static int constructor = 0x73164160;
|
||||
|
||||
|
||||
public void readParams(AbsSerializedData stream) {
|
||||
random_id = stream.readInt64();
|
||||
random_bytes = stream.readByteArray();
|
||||
in_seq_no = stream.readInt32();
|
||||
out_seq_no = stream.readInt32();
|
||||
action = (DecryptedMessageAction)TLClassStore.Instance().TLdeserialize(stream, stream.readInt32());
|
||||
}
|
||||
|
||||
public void serializeToStream(AbsSerializedData stream) {
|
||||
stream.writeInt32(constructor);
|
||||
stream.writeInt64(random_id);
|
||||
stream.writeByteArray(random_bytes);
|
||||
stream.writeInt32(in_seq_no);
|
||||
stream.writeInt32(out_seq_no);
|
||||
action.serializeToStream(stream);
|
||||
}
|
||||
}
|
||||
|
||||
public static class TL_decryptedMessage extends DecryptedMessage {
|
||||
public static int constructor = 0x4e748938;
|
||||
public static int constructor = 0x204d3878;
|
||||
|
||||
|
||||
public void readParams(AbsSerializedData stream) {
|
||||
random_id = stream.readInt64();
|
||||
random_bytes = stream.readByteArray();
|
||||
in_seq_no = stream.readInt32();
|
||||
out_seq_no = stream.readInt32();
|
||||
ttl = stream.readInt32();
|
||||
message = stream.readString();
|
||||
media = (DecryptedMessageMedia)TLClassStore.Instance().TLdeserialize(stream, stream.readInt32());
|
||||
|
@ -2604,9 +2593,6 @@ public class TLRPC {
|
|||
public void serializeToStream(AbsSerializedData stream) {
|
||||
stream.writeInt32(constructor);
|
||||
stream.writeInt64(random_id);
|
||||
stream.writeByteArray(random_bytes);
|
||||
stream.writeInt32(in_seq_no);
|
||||
stream.writeInt32(out_seq_no);
|
||||
stream.writeInt32(ttl);
|
||||
stream.writeString(message);
|
||||
media.serializeToStream(stream);
|
||||
|
@ -6281,19 +6267,28 @@ public class TLRPC {
|
|||
}
|
||||
|
||||
public static class TL_decryptedMessageLayer extends TLObject {
|
||||
public static int constructor = 0x99a438cf;
|
||||
public static int constructor = 0x1be31789;
|
||||
|
||||
public byte[] random_bytes;
|
||||
public int layer;
|
||||
public int in_seq_no;
|
||||
public int out_seq_no;
|
||||
public DecryptedMessage message;
|
||||
|
||||
public void readParams(AbsSerializedData stream) {
|
||||
random_bytes = stream.readByteArray();
|
||||
layer = stream.readInt32();
|
||||
in_seq_no = stream.readInt32();
|
||||
out_seq_no = stream.readInt32();
|
||||
message = (DecryptedMessage)TLClassStore.Instance().TLdeserialize(stream, stream.readInt32());
|
||||
}
|
||||
|
||||
public void serializeToStream(AbsSerializedData stream) {
|
||||
stream.writeInt32(constructor);
|
||||
stream.writeByteArray(random_bytes);
|
||||
stream.writeInt32(layer);
|
||||
stream.writeInt32(in_seq_no);
|
||||
stream.writeInt32(out_seq_no);
|
||||
message.serializeToStream(stream);
|
||||
}
|
||||
}
|
||||
|
@ -8781,6 +8776,7 @@ public class TLRPC {
|
|||
public long dialog_id;
|
||||
public int ttl;
|
||||
public int destroyTime;
|
||||
public int layer;
|
||||
public VideoEditedInfo videoEditedInfo = null;
|
||||
}
|
||||
|
||||
|
@ -9663,24 +9659,6 @@ public class TLRPC {
|
|||
}
|
||||
}
|
||||
|
||||
public static class decryptedMessageLayer extends TLObject {
|
||||
public static int constructor = 0x99a438cf;
|
||||
|
||||
public int layer;
|
||||
public TLObject message;
|
||||
|
||||
public void readParams(AbsSerializedData stream) {
|
||||
layer = stream.readInt32();
|
||||
message = TLClassStore.Instance().TLdeserialize(stream, stream.readInt32());
|
||||
}
|
||||
|
||||
public void serializeToStream(AbsSerializedData stream) {
|
||||
stream.writeInt32(constructor);
|
||||
stream.writeInt32(layer);
|
||||
message.serializeToStream(stream);
|
||||
}
|
||||
}
|
||||
|
||||
public static class TL_encryptedChat_old extends TL_encryptedChat {
|
||||
public static int constructor = 0x6601d14f;
|
||||
|
||||
|
|
|
@ -26,7 +26,6 @@ import org.telegram.android.AndroidUtilities;
|
|||
import org.telegram.messenger.FileLog;
|
||||
import org.telegram.android.LocaleController;
|
||||
import org.telegram.messenger.R;
|
||||
import org.telegram.messenger.Utilities;
|
||||
import org.telegram.ui.Views.ActionBar.ActionBarLayer;
|
||||
import org.telegram.ui.Views.ActionBar.ActionBarMenu;
|
||||
import org.telegram.ui.Views.ActionBar.BaseFragment;
|
||||
|
@ -55,7 +54,13 @@ public class LoginActivity extends BaseFragment implements SlideView.SlideViewDe
|
|||
v.onDestroyActivity();
|
||||
}
|
||||
}
|
||||
Utilities.HideProgressDialog(getParentActivity());
|
||||
if (progressDialog != null) {
|
||||
try {
|
||||
progressDialog.dismiss();
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue