use of org.telegram.tgnet.SerializedData in project Telegram-FOSS by Telegram-FOSS-Team.
the class AlertsCreator method performAskAQuestion.
private static void performAskAQuestion(BaseFragment fragment) {
int currentAccount = fragment.getCurrentAccount();
final SharedPreferences preferences = MessagesController.getMainSettings(currentAccount);
long uid = AndroidUtilities.getPrefIntOrLong(preferences, "support_id2", 0);
TLRPC.User supportUser = null;
if (uid != 0) {
supportUser = MessagesController.getInstance(currentAccount).getUser(uid);
if (supportUser == null) {
String userString = preferences.getString("support_user", null);
if (userString != null) {
try {
byte[] datacentersBytes = Base64.decode(userString, Base64.DEFAULT);
if (datacentersBytes != null) {
SerializedData data = new SerializedData(datacentersBytes);
supportUser = TLRPC.User.TLdeserialize(data, data.readInt32(false), false);
if (supportUser != null && supportUser.id == 333000) {
supportUser = null;
}
data.cleanup();
}
} catch (Exception e) {
FileLog.e(e);
supportUser = null;
}
}
}
}
if (supportUser == null) {
final AlertDialog progressDialog = new AlertDialog(fragment.getParentActivity(), 3);
progressDialog.setCanCacnel(false);
progressDialog.show();
TLRPC.TL_help_getSupport req = new TLRPC.TL_help_getSupport();
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
if (error == null) {
final TLRPC.TL_help_support res = (TLRPC.TL_help_support) response;
AndroidUtilities.runOnUIThread(() -> {
SharedPreferences.Editor editor = preferences.edit();
editor.putLong("support_id2", res.user.id);
SerializedData data = new SerializedData();
res.user.serializeToStream(data);
editor.putString("support_user", Base64.encodeToString(data.toByteArray(), Base64.DEFAULT));
editor.commit();
data.cleanup();
try {
progressDialog.dismiss();
} catch (Exception e) {
FileLog.e(e);
}
ArrayList<TLRPC.User> users = new ArrayList<>();
users.add(res.user);
MessagesStorage.getInstance(currentAccount).putUsersAndChats(users, null, true, true);
MessagesController.getInstance(currentAccount).putUser(res.user, false);
Bundle args = new Bundle();
args.putLong("user_id", res.user.id);
fragment.presentFragment(new ChatActivity(args));
});
} else {
AndroidUtilities.runOnUIThread(() -> {
try {
progressDialog.dismiss();
} catch (Exception e) {
FileLog.e(e);
}
});
}
});
} else {
MessagesController.getInstance(currentAccount).putUser(supportUser, true);
Bundle args = new Bundle();
args.putLong("user_id", supportUser.id);
fragment.presentFragment(new ChatActivity(args));
}
}
use of org.telegram.tgnet.SerializedData in project Telegram-FOSS by Telegram-FOSS-Team.
the class Theme method generateEmojiPreviewThemes.
private static void generateEmojiPreviewThemes(final ArrayList<TLRPC.TL_theme> emojiPreviewThemes, int currentAccount) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("emojithemes_config", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("count", emojiPreviewThemes.size());
for (int i = 0; i < emojiPreviewThemes.size(); ++i) {
TLRPC.TL_theme tlChatTheme = emojiPreviewThemes.get(i);
SerializedData data = new SerializedData(tlChatTheme.getObjectSize());
tlChatTheme.serializeToStream(data);
editor.putString("theme_" + i, Utilities.bytesToHex(data.toByteArray()));
}
editor.apply();
if (!emojiPreviewThemes.isEmpty()) {
final ArrayList<ChatThemeBottomSheet.ChatThemeItem> previewItems = new ArrayList<>();
previewItems.add(new ChatThemeBottomSheet.ChatThemeItem(EmojiThemes.createHomePreviewTheme()));
for (int i = 0; i < emojiPreviewThemes.size(); i++) {
TLRPC.TL_theme theme = emojiPreviewThemes.get(i);
EmojiThemes chatTheme = EmojiThemes.createPreviewFullTheme(theme);
ChatThemeBottomSheet.ChatThemeItem item = new ChatThemeBottomSheet.ChatThemeItem(chatTheme);
if (chatTheme.items.size() >= 4) {
previewItems.add(item);
}
}
ChatThemeController.chatThemeQueue.postRunnable(new Runnable() {
@Override
public void run() {
for (int i = 0; i < previewItems.size(); i++) {
previewItems.get(i).chatTheme.loadPreviewColors(currentAccount);
}
AndroidUtilities.runOnUIThread(() -> {
defaultEmojiThemes.clear();
defaultEmojiThemes.addAll(previewItems);
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.emojiPreviewThemesChanged);
});
}
});
} else {
defaultEmojiThemes.clear();
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.emojiPreviewThemesChanged);
}
}
use of org.telegram.tgnet.SerializedData in project Telegram-FOSS by Telegram-FOSS-Team.
the class MessagesController method loadAppConfig.
private void loadAppConfig() {
if (loadingAppConfig) {
return;
}
loadingAppConfig = true;
TLRPC.TL_help_getAppConfig req = new TLRPC.TL_help_getAppConfig();
getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
if (response instanceof TLRPC.TL_jsonObject) {
SharedPreferences.Editor editor = mainPreferences.edit();
boolean changed = false;
boolean keelAliveChanged = false;
TLRPC.TL_jsonObject object = (TLRPC.TL_jsonObject) response;
for (int a = 0, N = object.value.size(); a < N; a++) {
TLRPC.TL_jsonObjectValue value = object.value.get(a);
switch(value.key) {
case "emojies_animated_zoom":
{
if (value.value instanceof TLRPC.TL_jsonNumber) {
TLRPC.TL_jsonNumber number = (TLRPC.TL_jsonNumber) value.value;
if (animatedEmojisZoom != number.value) {
animatedEmojisZoom = (float) number.value;
editor.putFloat("animatedEmojisZoom", animatedEmojisZoom);
changed = true;
}
}
break;
}
case "dialog_filters_enabled":
{
if (value.value instanceof TLRPC.TL_jsonBool) {
TLRPC.TL_jsonBool bool = (TLRPC.TL_jsonBool) value.value;
if (bool.value != filtersEnabled) {
filtersEnabled = bool.value;
editor.putBoolean("filtersEnabled", filtersEnabled);
changed = true;
}
}
break;
}
case "dialog_filters_tooltip":
{
if (value.value instanceof TLRPC.TL_jsonBool) {
TLRPC.TL_jsonBool bool = (TLRPC.TL_jsonBool) value.value;
if (bool.value != showFiltersTooltip) {
showFiltersTooltip = bool.value;
editor.putBoolean("showFiltersTooltip", showFiltersTooltip);
changed = true;
getNotificationCenter().postNotificationName(NotificationCenter.filterSettingsUpdated);
}
}
break;
}
case "youtube_pip":
{
if (value.value instanceof TLRPC.TL_jsonString) {
TLRPC.TL_jsonString string = (TLRPC.TL_jsonString) value.value;
if (!string.value.equals(youtubePipType)) {
youtubePipType = string.value;
editor.putString("youtubePipType", youtubePipType);
changed = true;
}
}
break;
}
case "background_connection":
{
if (value.value instanceof TLRPC.TL_jsonBool) {
TLRPC.TL_jsonBool bool = (TLRPC.TL_jsonBool) value.value;
if (bool.value != backgroundConnection) {
backgroundConnection = bool.value;
editor.putBoolean("backgroundConnection", backgroundConnection);
changed = true;
keelAliveChanged = true;
}
}
break;
}
case "keep_alive_service":
{
if (value.value instanceof TLRPC.TL_jsonBool) {
TLRPC.TL_jsonBool bool = (TLRPC.TL_jsonBool) value.value;
if (bool.value != keepAliveService) {
keepAliveService = bool.value;
editor.putBoolean("keepAliveService", keepAliveService);
changed = true;
keelAliveChanged = true;
}
}
break;
}
case "qr_login_camera":
{
if (value.value instanceof TLRPC.TL_jsonBool) {
TLRPC.TL_jsonBool bool = (TLRPC.TL_jsonBool) value.value;
if (bool.value != qrLoginCamera) {
qrLoginCamera = bool.value;
editor.putBoolean("qrLoginCamera", qrLoginCamera);
changed = true;
}
}
break;
}
case "save_gifs_with_stickers":
{
if (value.value instanceof TLRPC.TL_jsonBool) {
TLRPC.TL_jsonBool bool = (TLRPC.TL_jsonBool) value.value;
if (bool.value != saveGifsWithStickers) {
saveGifsWithStickers = bool.value;
editor.putBoolean("saveGifsWithStickers", saveGifsWithStickers);
changed = true;
}
}
break;
}
case "url_auth_domains":
{
HashSet<String> newDomains = new HashSet<>();
if (value.value instanceof TLRPC.TL_jsonArray) {
TLRPC.TL_jsonArray array = (TLRPC.TL_jsonArray) value.value;
for (int b = 0, N2 = array.value.size(); b < N2; b++) {
TLRPC.JSONValue val = array.value.get(b);
if (val instanceof TLRPC.TL_jsonString) {
TLRPC.TL_jsonString string = (TLRPC.TL_jsonString) val;
newDomains.add(string.value);
}
}
}
if (!authDomains.equals(newDomains)) {
authDomains = newDomains;
editor.putStringSet("authDomains", authDomains);
changed = true;
}
break;
}
case "autologin_domains":
{
HashSet<String> newDomains = new HashSet<>();
if (value.value instanceof TLRPC.TL_jsonArray) {
TLRPC.TL_jsonArray array = (TLRPC.TL_jsonArray) value.value;
for (int b = 0, N2 = array.value.size(); b < N2; b++) {
TLRPC.JSONValue val = array.value.get(b);
if (val instanceof TLRPC.TL_jsonString) {
TLRPC.TL_jsonString string = (TLRPC.TL_jsonString) val;
newDomains.add(string.value);
}
}
}
if (!autologinDomains.equals(newDomains)) {
autologinDomains = newDomains;
editor.putStringSet("autologinDomains", autologinDomains);
changed = true;
}
break;
}
case "autologin_token":
{
if (value.value instanceof TLRPC.TL_jsonString) {
TLRPC.TL_jsonString string = (TLRPC.TL_jsonString) value.value;
if (!string.value.equals(autologinToken)) {
autologinToken = string.value;
editor.putString("autologinToken", autologinToken);
changed = true;
}
}
break;
}
case "emojies_send_dice":
{
HashSet<String> newEmojies = new HashSet<>();
if (value.value instanceof TLRPC.TL_jsonArray) {
TLRPC.TL_jsonArray array = (TLRPC.TL_jsonArray) value.value;
for (int b = 0, N2 = array.value.size(); b < N2; b++) {
TLRPC.JSONValue val = array.value.get(b);
if (val instanceof TLRPC.TL_jsonString) {
TLRPC.TL_jsonString string = (TLRPC.TL_jsonString) val;
newEmojies.add(string.value.replace("\uFE0F", ""));
}
}
}
if (!diceEmojies.equals(newEmojies)) {
diceEmojies = newEmojies;
editor.putStringSet("diceEmojies", diceEmojies);
changed = true;
}
break;
}
case "gif_search_emojies":
{
ArrayList<String> newEmojies = new ArrayList<>();
if (value.value instanceof TLRPC.TL_jsonArray) {
TLRPC.TL_jsonArray array = (TLRPC.TL_jsonArray) value.value;
for (int b = 0, N2 = array.value.size(); b < N2; b++) {
TLRPC.JSONValue val = array.value.get(b);
if (val instanceof TLRPC.TL_jsonString) {
TLRPC.TL_jsonString string = (TLRPC.TL_jsonString) val;
newEmojies.add(string.value.replace("\uFE0F", ""));
}
}
}
if (!gifSearchEmojies.equals(newEmojies)) {
gifSearchEmojies = newEmojies;
SerializedData serializedData = new SerializedData();
serializedData.writeInt32(gifSearchEmojies.size());
for (int b = 0, N2 = gifSearchEmojies.size(); b < N2; b++) {
serializedData.writeString(gifSearchEmojies.get(b));
}
editor.putString("gifSearchEmojies", Base64.encodeToString(serializedData.toByteArray(), Base64.DEFAULT));
serializedData.cleanup();
changed = true;
}
break;
}
case "emojies_send_dice_success":
{
try {
HashMap<String, DiceFrameSuccess> newEmojies = new HashMap<>();
if (value.value instanceof TLRPC.TL_jsonObject) {
TLRPC.TL_jsonObject jsonObject = (TLRPC.TL_jsonObject) value.value;
for (int b = 0, N2 = jsonObject.value.size(); b < N2; b++) {
TLRPC.TL_jsonObjectValue val = jsonObject.value.get(b);
if (val.value instanceof TLRPC.TL_jsonObject) {
TLRPC.TL_jsonObject jsonObject2 = (TLRPC.TL_jsonObject) val.value;
int n = Integer.MAX_VALUE;
int f = Integer.MAX_VALUE;
for (int c = 0, N3 = jsonObject2.value.size(); c < N3; c++) {
TLRPC.TL_jsonObjectValue val2 = jsonObject2.value.get(c);
if (val2.value instanceof TLRPC.TL_jsonNumber) {
if ("value".equals(val2.key)) {
n = (int) ((TLRPC.TL_jsonNumber) val2.value).value;
} else if ("frame_start".equals(val2.key)) {
f = (int) ((TLRPC.TL_jsonNumber) val2.value).value;
}
}
}
if (f != Integer.MAX_VALUE && n != Integer.MAX_VALUE) {
newEmojies.put(val.key.replace("\uFE0F", ""), new DiceFrameSuccess(f, n));
}
}
}
}
if (!diceSuccess.equals(newEmojies)) {
diceSuccess = newEmojies;
SerializedData serializedData = new SerializedData();
serializedData.writeInt32(diceSuccess.size());
for (HashMap.Entry<String, DiceFrameSuccess> entry : diceSuccess.entrySet()) {
serializedData.writeString(entry.getKey());
DiceFrameSuccess frameSuccess = entry.getValue();
serializedData.writeInt32(frameSuccess.frame);
serializedData.writeInt32(frameSuccess.num);
}
editor.putString("diceSuccess", Base64.encodeToString(serializedData.toByteArray(), Base64.DEFAULT));
serializedData.cleanup();
changed = true;
}
} catch (Exception e) {
FileLog.e(e);
}
break;
}
case "autoarchive_setting_available":
{
if (value.value instanceof TLRPC.TL_jsonBool) {
TLRPC.TL_jsonBool bool = (TLRPC.TL_jsonBool) value.value;
if (bool.value != autoarchiveAvailable) {
autoarchiveAvailable = bool.value;
editor.putBoolean("autoarchiveAvailable", autoarchiveAvailable);
changed = true;
}
}
break;
}
case "groupcall_video_participants_max":
{
if (value.value instanceof TLRPC.TL_jsonNumber) {
TLRPC.TL_jsonNumber number = (TLRPC.TL_jsonNumber) value.value;
if (number.value != groipCallVideoMaxParticipants) {
groipCallVideoMaxParticipants = (int) number.value;
editor.putInt("groipCallVideoMaxParticipants", groipCallVideoMaxParticipants);
changed = true;
}
}
break;
}
case "chat_read_mark_size_threshold":
{
if (value.value instanceof TLRPC.TL_jsonNumber) {
TLRPC.TL_jsonNumber number = (TLRPC.TL_jsonNumber) value.value;
if (number.value != chatReadMarkSizeThreshold) {
chatReadMarkSizeThreshold = (int) number.value;
editor.putInt("chatReadMarkSizeThreshold", chatReadMarkSizeThreshold);
changed = true;
}
}
break;
}
case "chat_read_mark_expire_period":
{
if (value.value instanceof TLRPC.TL_jsonNumber) {
TLRPC.TL_jsonNumber number = (TLRPC.TL_jsonNumber) value.value;
if (number.value != chatReadMarkExpirePeriod) {
chatReadMarkExpirePeriod = (int) number.value;
editor.putInt("chatReadMarkExpirePeriod", chatReadMarkExpirePeriod);
changed = true;
}
}
break;
}
case "inapp_update_check_delay":
{
if (value.value instanceof TLRPC.TL_jsonNumber) {
TLRPC.TL_jsonNumber number = (TLRPC.TL_jsonNumber) value.value;
if (number.value != updateCheckDelay) {
updateCheckDelay = (int) number.value;
editor.putInt("updateCheckDelay", updateCheckDelay);
changed = true;
}
} else if (value.value instanceof TLRPC.TL_jsonString) {
TLRPC.TL_jsonString number = (TLRPC.TL_jsonString) value.value;
int delay = Utilities.parseInt(number.value);
if (delay != updateCheckDelay) {
updateCheckDelay = delay;
editor.putInt("updateCheckDelay", updateCheckDelay);
changed = true;
}
}
break;
}
case "round_video_encoding":
{
if (value.value instanceof TLRPC.TL_jsonObject) {
TLRPC.TL_jsonObject jsonObject = (TLRPC.TL_jsonObject) value.value;
for (int b = 0, N2 = jsonObject.value.size(); b < N2; b++) {
TLRPC.TL_jsonObjectValue value2 = jsonObject.value.get(b);
switch(value2.key) {
case "diameter":
{
if (value2.value instanceof TLRPC.TL_jsonNumber) {
TLRPC.TL_jsonNumber number = (TLRPC.TL_jsonNumber) value2.value;
if (number.value != roundVideoSize) {
roundVideoSize = (int) number.value;
editor.putInt("roundVideoSize", roundVideoSize);
changed = true;
}
}
break;
}
case "video_bitrate":
{
if (value2.value instanceof TLRPC.TL_jsonNumber) {
TLRPC.TL_jsonNumber number = (TLRPC.TL_jsonNumber) value2.value;
if (number.value != roundVideoBitrate) {
roundVideoBitrate = (int) number.value;
editor.putInt("roundVideoBitrate", roundVideoBitrate);
changed = true;
}
}
break;
}
case "audio_bitrate":
{
if (value2.value instanceof TLRPC.TL_jsonNumber) {
TLRPC.TL_jsonNumber number = (TLRPC.TL_jsonNumber) value2.value;
if (number.value != roundAudioBitrate) {
roundAudioBitrate = (int) number.value;
editor.putInt("roundAudioBitrate", roundAudioBitrate);
changed = true;
}
}
break;
}
}
}
}
break;
}
case "stickers_emoji_suggest_only_api":
{
if (value.value instanceof TLRPC.TL_jsonBool) {
TLRPC.TL_jsonBool bool = (TLRPC.TL_jsonBool) value.value;
if (bool.value != suggestStickersApiOnly) {
suggestStickersApiOnly = bool.value;
editor.putBoolean("suggestStickersApiOnly", suggestStickersApiOnly);
changed = true;
}
}
break;
}
case "export_regex":
{
HashSet<String> newExport = new HashSet<>();
if (value.value instanceof TLRPC.TL_jsonArray) {
TLRPC.TL_jsonArray array = (TLRPC.TL_jsonArray) value.value;
for (int b = 0, N2 = array.value.size(); b < N2; b++) {
TLRPC.JSONValue val = array.value.get(b);
if (val instanceof TLRPC.TL_jsonString) {
TLRPC.TL_jsonString string = (TLRPC.TL_jsonString) val;
newExport.add(string.value);
}
}
}
if (!exportUri.equals(newExport)) {
exportUri = newExport;
editor.putStringSet("exportUri2", exportUri);
changed = true;
}
break;
}
case "export_group_urls":
{
HashSet<String> newExport = new HashSet<>();
if (value.value instanceof TLRPC.TL_jsonArray) {
TLRPC.TL_jsonArray array = (TLRPC.TL_jsonArray) value.value;
for (int b = 0, N2 = array.value.size(); b < N2; b++) {
TLRPC.JSONValue val = array.value.get(b);
if (val instanceof TLRPC.TL_jsonString) {
TLRPC.TL_jsonString string = (TLRPC.TL_jsonString) val;
newExport.add(string.value);
}
}
}
if (!exportGroupUri.equals(newExport)) {
exportGroupUri = newExport;
editor.putStringSet("exportGroupUri", exportGroupUri);
changed = true;
}
break;
}
case "export_private_urls":
{
HashSet<String> newExport = new HashSet<>();
if (value.value instanceof TLRPC.TL_jsonArray) {
TLRPC.TL_jsonArray array = (TLRPC.TL_jsonArray) value.value;
for (int b = 0, N2 = array.value.size(); b < N2; b++) {
TLRPC.JSONValue val = array.value.get(b);
if (val instanceof TLRPC.TL_jsonString) {
TLRPC.TL_jsonString string = (TLRPC.TL_jsonString) val;
newExport.add(string.value);
}
}
}
if (!exportPrivateUri.equals(newExport)) {
exportPrivateUri = newExport;
editor.putStringSet("exportPrivateUri", exportPrivateUri);
changed = true;
}
break;
}
case "pending_suggestions":
{
HashSet<String> newSuggestions = new HashSet<>();
if (value.value instanceof TLRPC.TL_jsonArray) {
TLRPC.TL_jsonArray array = (TLRPC.TL_jsonArray) value.value;
for (int b = 0, N2 = array.value.size(); b < N2; b++) {
TLRPC.JSONValue val = array.value.get(b);
if (val instanceof TLRPC.TL_jsonString) {
TLRPC.TL_jsonString string = (TLRPC.TL_jsonString) val;
newSuggestions.add(string.value);
}
}
}
if (!pendingSuggestions.equals(newSuggestions)) {
pendingSuggestions = newSuggestions;
editor.putStringSet("pendingSuggestions", pendingSuggestions);
getNotificationCenter().postNotificationName(NotificationCenter.newSuggestionsAvailable);
changed = true;
}
break;
}
case "emojies_sounds":
{
try {
HashMap<String, EmojiSound> newEmojies = new HashMap<>();
if (value.value instanceof TLRPC.TL_jsonObject) {
TLRPC.TL_jsonObject jsonObject = (TLRPC.TL_jsonObject) value.value;
for (int b = 0, N2 = jsonObject.value.size(); b < N2; b++) {
TLRPC.TL_jsonObjectValue val = jsonObject.value.get(b);
if (val.value instanceof TLRPC.TL_jsonObject) {
TLRPC.TL_jsonObject jsonObject2 = (TLRPC.TL_jsonObject) val.value;
long i = 0;
long ah = 0;
String fr = null;
for (int c = 0, N3 = jsonObject2.value.size(); c < N3; c++) {
TLRPC.TL_jsonObjectValue val2 = jsonObject2.value.get(c);
if (val2.value instanceof TLRPC.TL_jsonString) {
if ("id".equals(val2.key)) {
i = Utilities.parseLong(((TLRPC.TL_jsonString) val2.value).value);
} else if ("access_hash".equals(val2.key)) {
ah = Utilities.parseLong(((TLRPC.TL_jsonString) val2.value).value);
} else if ("file_reference_base64".equals(val2.key)) {
fr = ((TLRPC.TL_jsonString) val2.value).value;
}
}
}
if (i != 0 && ah != 0 && fr != null) {
newEmojies.put(val.key.replace("\uFE0F", ""), new EmojiSound(i, ah, fr));
}
}
}
}
if (!emojiSounds.equals(newEmojies)) {
emojiSounds = newEmojies;
SerializedData serializedData = new SerializedData();
serializedData.writeInt32(emojiSounds.size());
for (HashMap.Entry<String, EmojiSound> entry : emojiSounds.entrySet()) {
serializedData.writeString(entry.getKey());
EmojiSound emojiSound = entry.getValue();
serializedData.writeInt64(emojiSound.id);
serializedData.writeInt64(emojiSound.accessHash);
serializedData.writeByteArray(emojiSound.fileReference);
}
editor.putString("emojiSounds", Base64.encodeToString(serializedData.toByteArray(), Base64.DEFAULT));
serializedData.cleanup();
changed = true;
}
} catch (Exception e) {
FileLog.e(e);
}
break;
}
}
}
if (changed) {
editor.commit();
}
if (keelAliveChanged) {
ApplicationLoader.startPushService();
ConnectionsManager connectionsManager = getConnectionsManager();
connectionsManager.setPushConnectionEnabled(connectionsManager.isPushConnectionEnabled());
}
}
loadingAppConfig = false;
}));
}
use of org.telegram.tgnet.SerializedData in project Telegram-FOSS by Telegram-FOSS-Team.
the class MessagesController method performLogout.
public void performLogout(int type) {
if (type == 1) {
unregistedPush();
TLRPC.TL_auth_logOut req = new TLRPC.TL_auth_logOut();
getConnectionsManager().sendRequest(req, (response, error) -> {
getConnectionsManager().cleanup(false);
AndroidUtilities.runOnUIThread(() -> {
if (response instanceof TLRPC.TL_auth_loggedOut) {
TLRPC.TL_auth_loggedOut res = (TLRPC.TL_auth_loggedOut) response;
if (((TLRPC.TL_auth_loggedOut) response).future_auth_token != null) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("saved_tokens", Context.MODE_PRIVATE);
int count = preferences.getInt("count", 0);
SerializedData data = new SerializedData(response.getObjectSize());
res.serializeToStream(data);
preferences.edit().putString("log_out_token_" + count, Utilities.bytesToHex(data.toByteArray())).putInt("count", count + 1).apply();
}
}
});
});
} else {
getConnectionsManager().cleanup(type == 2);
}
getUserConfig().clearConfig();
boolean shouldHandle = true;
ArrayList<NotificationCenter.NotificationCenterDelegate> observers = getNotificationCenter().getObservers(NotificationCenter.appDidLogout);
if (observers != null) {
for (int a = 0, N = observers.size(); a < N; a++) {
if (observers.get(a) instanceof LaunchActivity) {
shouldHandle = false;
break;
}
}
}
if (shouldHandle) {
if (UserConfig.selectedAccount == currentAccount) {
int account = -1;
for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) {
if (UserConfig.getInstance(a).isClientActivated()) {
account = a;
break;
}
}
if (account != -1) {
UserConfig.selectedAccount = account;
UserConfig.getInstance(0).saveConfig(false);
LaunchActivity.clearFragments();
}
}
}
getNotificationCenter().postNotificationName(NotificationCenter.appDidLogout);
getMessagesStorage().cleanup(false);
cleanup();
getContactsController().deleteUnknownAppAccounts();
}
use of org.telegram.tgnet.SerializedData in project Telegram-FOSS by Telegram-FOSS-Team.
the class MessagesController method saveLogOutTokens.
public static void saveLogOutTokens(ArrayList<TLRPC.TL_auth_loggedOut> tokens) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("saved_tokens", Context.MODE_PRIVATE);
ArrayList<TLRPC.TL_auth_loggedOut> activeTokens = new ArrayList<>();
preferences.edit().clear().apply();
int date = (int) (System.currentTimeMillis() / 1000L);
for (int i = 0; i < Math.min(20, tokens.size()); i++) {
activeTokens.add(tokens.get(i));
}
if (activeTokens.size() > 0) {
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("count", activeTokens.size());
for (int i = 0; i < activeTokens.size(); i++) {
SerializedData data = new SerializedData(activeTokens.get(i).getObjectSize());
activeTokens.get(i).serializeToStream(data);
editor.putString("log_out_token_" + i, Utilities.bytesToHex(data.toByteArray()));
}
editor.apply();
}
}
Aggregations