Commit b2ad802b authored by DrKLO's avatar DrKLO

Update secret chats layer

parent a54300fb
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
package org.telegram.android; package org.telegram.android;
import android.app.Activity; import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context; import android.content.Context;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.content.res.Configuration; import android.content.res.Configuration;
...@@ -34,8 +33,6 @@ import java.util.Locale; ...@@ -34,8 +33,6 @@ import java.util.Locale;
public class AndroidUtilities { public class AndroidUtilities {
public static ProgressDialog progressDialog;
private static final Hashtable<String, Typeface> typefaceCache = new Hashtable<String, Typeface>(); private static final Hashtable<String, Typeface> typefaceCache = new Hashtable<String, Typeface>();
private static int prevOrientation = -10; private static int prevOrientation = -10;
private static boolean waitingForSms = false; private static boolean waitingForSms = false;
...@@ -266,6 +263,22 @@ public class AndroidUtilities { ...@@ -266,6 +263,22 @@ public class AndroidUtilities {
return 0x0000000100000000L | ((long)id & 0x00000000FFFFFFFFL); 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) { public static void RunOnUIThread(Runnable runnable) {
RunOnUIThread(runnable, 0); RunOnUIThread(runnable, 0);
} }
...@@ -375,32 +388,4 @@ public class AndroidUtilities { ...@@ -375,32 +388,4 @@ public class AndroidUtilities {
} }
return photoSize; 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 { ...@@ -616,7 +616,7 @@ public class MessageObject {
} }
public boolean isSecretMedia() { 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) { public static void setIsUnread(TLRPC.Message message, boolean unread) {
......
...@@ -71,6 +71,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter ...@@ -71,6 +71,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
private boolean gettingNewDeleteTask = false; private boolean gettingNewDeleteTask = false;
private int currentDeletingTaskTime = 0; private int currentDeletingTaskTime = 0;
private ArrayList<Integer> currentDeletingTaskMids = null; private ArrayList<Integer> currentDeletingTaskMids = null;
private Runnable currentDeleteTaskRunnable = null;
public int totalDialogsCount = 0; public int totalDialogsCount = 0;
public boolean loadingDialogs = false; public boolean loadingDialogs = false;
...@@ -336,6 +337,12 @@ public class MessagesController implements NotificationCenter.NotificationCenter ...@@ -336,6 +337,12 @@ public class MessagesController implements NotificationCenter.NotificationCenter
startingSecretChat = false; startingSecretChat = false;
statusRequest = 0; statusRequest = 0;
statusSettingState = 0; statusSettingState = 0;
if (currentDeleteTaskRunnable != null) {
Utilities.stageQueue.cancelRunnable(currentDeleteTaskRunnable);
currentDeleteTaskRunnable = null;
}
addSupportUser(); addSupportUser();
} }
...@@ -530,11 +537,15 @@ public class MessagesController implements NotificationCenter.NotificationCenter ...@@ -530,11 +537,15 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}); });
} }
private void checkDeletingTask() { private boolean checkDeletingTask(boolean runnable) {
int currentServerTime = ConnectionsManager.getInstance().getCurrentTime(); int currentServerTime = ConnectionsManager.getInstance().getCurrentTime();
if (currentDeletingTaskMids != null && currentDeletingTaskTime != 0 && currentDeletingTaskTime <= currentServerTime) { if (currentDeletingTaskMids != null && (runnable || currentDeletingTaskTime != 0 && currentDeletingTaskTime <= currentServerTime)) {
currentDeletingTaskTime = 0; currentDeletingTaskTime = 0;
if (currentDeleteTaskRunnable != null && !runnable) {
Utilities.stageQueue.cancelRunnable(currentDeleteTaskRunnable);
}
currentDeleteTaskRunnable = null;
AndroidUtilities.RunOnUIThread(new Runnable() { AndroidUtilities.RunOnUIThread(new Runnable() {
@Override @Override
public void run() { public void run() {
...@@ -550,7 +561,9 @@ public class MessagesController implements NotificationCenter.NotificationCenter ...@@ -550,7 +561,9 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}); });
} }
}); });
return true;
} }
return false;
} }
public void processLoadedDeleteTask(final int taskTime, final ArrayList<Integer> messages) { public void processLoadedDeleteTask(final int taskTime, final ArrayList<Integer> messages) {
...@@ -562,7 +575,21 @@ public class MessagesController implements NotificationCenter.NotificationCenter ...@@ -562,7 +575,21 @@ public class MessagesController implements NotificationCenter.NotificationCenter
currentDeletingTaskTime = taskTime; currentDeletingTaskTime = taskTime;
currentDeletingTaskMids = messages; 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 { } else {
currentDeletingTaskTime = 0; currentDeletingTaskTime = 0;
currentDeletingTaskMids = null; currentDeletingTaskMids = null;
...@@ -1069,7 +1096,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter ...@@ -1069,7 +1096,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
public void updateTimerProc() { public void updateTimerProc() {
long currentTime = System.currentTimeMillis(); long currentTime = System.currentTimeMillis();
checkDeletingTask(); checkDeletingTask(false);
if (UserConfig.isClientActivated()) { if (UserConfig.isClientActivated()) {
if (ConnectionsManager.getInstance().getPauseTime() == 0 && ApplicationLoader.isScreenOn && !ApplicationLoader.mainInterfacePaused) { if (ConnectionsManager.getInstance().getPauseTime() == 0 && ApplicationLoader.isScreenOn && !ApplicationLoader.mainInterfacePaused) {
...@@ -3499,7 +3526,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter ...@@ -3499,7 +3526,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
} }
public TLRPC.Message decryptMessage(TLRPC.EncryptedMessage message) { 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) { if (chat == null) {
return null; return null;
} }
...@@ -3522,9 +3549,18 @@ public class MessagesController implements NotificationCenter.NotificationCenter ...@@ -3522,9 +3549,18 @@ public class MessagesController implements NotificationCenter.NotificationCenter
from_id = chat.participant_id; from_id = chat.participant_id;
} }
if (object instanceof TLRPC.TL_decryptedMessageLayer) {
object = ((TLRPC.TL_decryptedMessageLayer) object).message;
}
if (object instanceof TLRPC.TL_decryptedMessage) { if (object instanceof TLRPC.TL_decryptedMessage) {
TLRPC.TL_decryptedMessage decryptedMessage = (TLRPC.TL_decryptedMessage)object; 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.message = decryptedMessage.message;
newMessage.date = message.date; newMessage.date = message.date;
newMessage.local_id = newMessage.id = UserConfig.getNewMessageId(); newMessage.local_id = newMessage.id = UserConfig.getNewMessageId();
...@@ -3666,7 +3702,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter ...@@ -3666,7 +3702,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
} }
return newMessage; return newMessage;
} else if (object instanceof TLRPC.TL_decryptedMessageService) { } 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) { if (serviceMessage.action instanceof TLRPC.TL_decryptedMessageActionSetMessageTTL || serviceMessage.action instanceof TLRPC.TL_decryptedMessageActionScreenshotMessages) {
TLRPC.TL_messageService newMessage = new TLRPC.TL_messageService(); TLRPC.TL_messageService newMessage = new TLRPC.TL_messageService();
if (serviceMessage.action instanceof TLRPC.TL_decryptedMessageActionSetMessageTTL) { if (serviceMessage.action instanceof TLRPC.TL_decryptedMessageActionSetMessageTTL) {
...@@ -3727,6 +3763,19 @@ public class MessagesController implements NotificationCenter.NotificationCenter ...@@ -3727,6 +3763,19 @@ public class MessagesController implements NotificationCenter.NotificationCenter
if (!serviceMessage.action.random_ids.isEmpty()) { if (!serviceMessage.action.random_ids.isEmpty()) {
MessagesStorage.getInstance().createTaskForSecretChat(chat.id, 0, message.date, 1, serviceMessage.action.random_ids); 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 { } else {
return null; return null;
} }
......
...@@ -63,7 +63,7 @@ public class DispatchQueue extends Thread { ...@@ -63,7 +63,7 @@ public class DispatchQueue extends Thread {
postRunnable(runnable, 0); postRunnable(runnable, 0);
} }
public void postRunnable(Runnable runnable, int delay) { public void postRunnable(Runnable runnable, long delay) {
if (handler == null) { if (handler == null) {
synchronized (handlerSyncObject) { synchronized (handlerSyncObject) {
if (handler == null) { if (handler == null) {
......
...@@ -2557,8 +2557,6 @@ public class TLRPC { ...@@ -2557,8 +2557,6 @@ public class TLRPC {
public static class DecryptedMessage extends TLObject { public static class DecryptedMessage extends TLObject {
public long random_id; public long random_id;
public byte[] random_bytes; public byte[] random_bytes;
public int in_seq_no;
public int out_seq_no;
public DecryptedMessageAction action; public DecryptedMessageAction action;
public int ttl; public int ttl;
public String message; public String message;
...@@ -2566,36 +2564,27 @@ public class TLRPC { ...@@ -2566,36 +2564,27 @@ public class TLRPC {
} }
public static class TL_decryptedMessageService extends DecryptedMessage { public static class TL_decryptedMessageService extends DecryptedMessage {
public static int constructor = 0xda431693; public static int constructor = 0x73164160;
public void readParams(AbsSerializedData stream) { public void readParams(AbsSerializedData stream) {
random_id = stream.readInt64(); 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()); action = (DecryptedMessageAction)TLClassStore.Instance().TLdeserialize(stream, stream.readInt32());
} }
public void serializeToStream(AbsSerializedData stream) { public void serializeToStream(AbsSerializedData stream) {
stream.writeInt32(constructor); stream.writeInt32(constructor);
stream.writeInt64(random_id); stream.writeInt64(random_id);
stream.writeByteArray(random_bytes);
stream.writeInt32(in_seq_no);
stream.writeInt32(out_seq_no);
action.serializeToStream(stream); action.serializeToStream(stream);
} }
} }
public static class TL_decryptedMessage extends DecryptedMessage { public static class TL_decryptedMessage extends DecryptedMessage {
public static int constructor = 0x4e748938; public static int constructor = 0x204d3878;
public void readParams(AbsSerializedData stream) { public void readParams(AbsSerializedData stream) {
random_id = stream.readInt64(); random_id = stream.readInt64();
random_bytes = stream.readByteArray();
in_seq_no = stream.readInt32();
out_seq_no = stream.readInt32();
ttl = stream.readInt32(); ttl = stream.readInt32();
message = stream.readString(); message = stream.readString();
media = (DecryptedMessageMedia)TLClassStore.Instance().TLdeserialize(stream, stream.readInt32()); media = (DecryptedMessageMedia)TLClassStore.Instance().TLdeserialize(stream, stream.readInt32());
...@@ -2604,9 +2593,6 @@ public class TLRPC { ...@@ -2604,9 +2593,6 @@ public class TLRPC {
public void serializeToStream(AbsSerializedData stream) { public void serializeToStream(AbsSerializedData stream) {
stream.writeInt32(constructor); stream.writeInt32(constructor);
stream.writeInt64(random_id); stream.writeInt64(random_id);
stream.writeByteArray(random_bytes);
stream.writeInt32(in_seq_no);
stream.writeInt32(out_seq_no);
stream.writeInt32(ttl); stream.writeInt32(ttl);
stream.writeString(message); stream.writeString(message);
media.serializeToStream(stream); media.serializeToStream(stream);
...@@ -6281,19 +6267,28 @@ public class TLRPC { ...@@ -6281,19 +6267,28 @@ public class TLRPC {
} }
public static class TL_decryptedMessageLayer extends TLObject { 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 layer;
public int in_seq_no;
public int out_seq_no;
public DecryptedMessage message; public DecryptedMessage message;
public void readParams(AbsSerializedData stream) { public void readParams(AbsSerializedData stream) {
random_bytes = stream.readByteArray();
layer = stream.readInt32(); layer = stream.readInt32();
in_seq_no = stream.readInt32();
out_seq_no = stream.readInt32();
message = (DecryptedMessage)TLClassStore.Instance().TLdeserialize(stream, stream.readInt32()); message = (DecryptedMessage)TLClassStore.Instance().TLdeserialize(stream, stream.readInt32());
} }
public void serializeToStream(AbsSerializedData stream) { public void serializeToStream(AbsSerializedData stream) {
stream.writeInt32(constructor); stream.writeInt32(constructor);
stream.writeByteArray(random_bytes);
stream.writeInt32(layer); stream.writeInt32(layer);
stream.writeInt32(in_seq_no);
stream.writeInt32(out_seq_no);
message.serializeToStream(stream); message.serializeToStream(stream);
} }
} }
...@@ -8781,6 +8776,7 @@ public class TLRPC { ...@@ -8781,6 +8776,7 @@ public class TLRPC {
public long dialog_id; public long dialog_id;
public int ttl; public int ttl;
public int destroyTime; public int destroyTime;
public int layer;
public VideoEditedInfo videoEditedInfo = null; public VideoEditedInfo videoEditedInfo = null;
} }
...@@ -9663,24 +9659,6 @@ public class TLRPC { ...@@ -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 class TL_encryptedChat_old extends TL_encryptedChat {
public static int constructor = 0x6601d14f; public static int constructor = 0x6601d14f;
......
...@@ -26,7 +26,6 @@ import org.telegram.android.AndroidUtilities; ...@@ -26,7 +26,6 @@ import org.telegram.android.AndroidUtilities;
import org.telegram.messenger.FileLog; import org.telegram.messenger.FileLog;
import org.telegram.android.LocaleController; import org.telegram.android.LocaleController;
import org.telegram.messenger.R; import org.telegram.messenger.R;
import org.telegram.messenger.Utilities;
import org.telegram.ui.Views.ActionBar.ActionBarLayer; import org.telegram.ui.Views.ActionBar.ActionBarLayer;
import org.telegram.ui.Views.ActionBar.ActionBarMenu; import org.telegram.ui.Views.ActionBar.ActionBarMenu;
import org.telegram.ui.Views.ActionBar.BaseFragment; import org.telegram.ui.Views.ActionBar.BaseFragment;
...@@ -55,7 +54,13 @@ public class LoginActivity extends BaseFragment implements SlideView.SlideViewDe ...@@ -55,7 +54,13 @@ public class LoginActivity extends BaseFragment implements SlideView.SlideViewDe
v.onDestroyActivity(); v.onDestroyActivity();
} }
} }
Utilities.HideProgressDialog(getParentActivity()); if (progressDialog != null) {
try {
progressDialog.dismiss();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
} }
@Override @Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment