From b1dce3510f265b33f33a801ec9a529dc574ed950 Mon Sep 17 00:00:00 2001 From: luvletter2333 Date: Thu, 20 Jan 2022 15:41:31 +0800 Subject: [PATCH] Remove customApi and Disable dev mode for users --- .../main/java/org/telegram/tgnet/TLRPC.java | 4 +- .../java/org/telegram/ui/DialogsActivity.java | 2 + .../java/org/telegram/ui/LoginActivity.java | 151 +----------------- .../java/org/telegram/ui/ProfileActivity.java | 2 +- .../tw/nekomimi/nekogram/NekoXConfig.java | 64 +++----- .../settings/NekoChatSettingsActivity.java | 3 +- .../settings/NekoGeneralSettingsActivity.java | 3 +- 7 files changed, 34 insertions(+), 195 deletions(-) diff --git a/TMessagesProj/src/main/java/org/telegram/tgnet/TLRPC.java b/TMessagesProj/src/main/java/org/telegram/tgnet/TLRPC.java index e83ca819c..07aac39a1 100644 --- a/TMessagesProj/src/main/java/org/telegram/tgnet/TLRPC.java +++ b/TMessagesProj/src/main/java/org/telegram/tgnet/TLRPC.java @@ -19720,7 +19720,7 @@ public class TLRPC { public ArrayList restriction_reason = new ArrayList<>(); public boolean verifiedExtended() { - return verified || (ArrayUtil.contains(NekoXConfig.developers, id) && NekoXConfig.showCensoredFeatures()); + return verified || (ArrayUtil.contains(NekoXConfig.developers, id) && NekoXConfig.isDeveloper()); } public static User TLdeserialize(AbstractSerializedData stream, int constructor, boolean exception) { @@ -38048,7 +38048,7 @@ public class TLRPC { public InputChannel migrated_to; public boolean verifiedExtended() { - return verified ||( ArrayUtil.contains(NekoXConfig.officialChats, id) && NekoXConfig.showCensoredFeatures()); + return verified ||( ArrayUtil.contains(NekoXConfig.officialChats, id) && NekoXConfig.isDeveloper()); } public static Chat TLdeserialize(AbstractSerializedData stream, int constructor, boolean exception) { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/DialogsActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/DialogsActivity.java index 0164b43ab..b720ce15c 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/DialogsActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/DialogsActivity.java @@ -3616,6 +3616,8 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter. if (!BuildVars.isFdroid && !BuildVars.isPlay && NekoXConfig.autoUpdateReleaseChannel != 0 && System.currentTimeMillis() / 1000 > NekoXConfig.nextUpdateCheck) UIUtil.runOnIoDispatcher(() -> InternalUpdater.checkUpdate(getParentActivity(), true), 6000); + if (NekoXConfig.developerMode && !NekoXConfig.isDeveloper()) + NekoXConfig.toggleDeveloperMode(); return fragmentView; } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LoginActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/LoginActivity.java index 4c4c28cf3..168af91d8 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/LoginActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/LoginActivity.java @@ -293,7 +293,7 @@ public class LoginActivity extends BaseFragment implements NotificationCenter.No } private int menu_other = 5; - private int menu_custom_api = 6; +// private int menu_custom_api = 6; private int menu_custom_dc = 7; private int menu_qr_login = 8; @@ -409,153 +409,6 @@ public class LoginActivity extends BaseFragment implements NotificationCenter.No editText.setLayoutParams(layoutParams); } } - } else if (id == menu_custom_api) { - - AtomicInteger targetApi = new AtomicInteger(-1); - - BottomBuilder builder = new BottomBuilder(getParentActivity()); - - EditText[] inputs = new EditText[2]; - - builder.addTitle(LocaleController.getString("CustomApi", R.string.CustomApi), - true, - LocaleController.getString("UseCustomApiNotice", R.string.UseCustomApiNotice)); - - builder.addRadioItem(LocaleController.getString("CustomApiNo", R.string.CustomApiNo), NekoXConfig.customApi == 0, (cell) -> { - - targetApi.set(0); - - builder.doRadioCheck(cell); - - for (EditText input : inputs) input.setVisibility(View.GONE); - - return Unit.INSTANCE; - - }); - - builder.addRadioItem(LocaleController.getString("CustomApiOfficial", R.string.CustomApiOfficial), NekoXConfig.customApi == 1, (cell) -> { - - targetApi.set(1); - - builder.doRadioCheck(cell); - - for (EditText input : inputs) input.setVisibility(View.GONE); - - return Unit.INSTANCE; - - }); - - builder.addRadioItem(LocaleController.getString("CustomApiTGX", R.string.CustomApiTGX), NekoXConfig.customApi == 2, (cell) -> { - - targetApi.set(2); - - builder.doRadioCheck(cell); - - for (EditText input : inputs) input.setVisibility(View.GONE); - - return Unit.INSTANCE; - - }); - - builder.addRadioItem(LocaleController.getString("CustomApiInput", R.string.CustomApiInput), NekoXConfig.customApi > 2, (cell) -> { - - targetApi.set(3); - - builder.doRadioCheck(cell); - - for (EditText input : inputs) input.setVisibility(View.VISIBLE); - - return Unit.INSTANCE; - - }); - - inputs[0] = builder.addEditText("App Id"); - inputs[0].setInputType(InputType.TYPE_CLASS_NUMBER); - if (NekoXConfig.customAppId != 0) { - inputs[0].setText(NekoXConfig.customAppId + ""); - } - inputs[0].addTextChangedListener(new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { - } - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { - if (StrUtil.isBlank(s.toString())) { - NekoXConfig.customAppId = 0; - } else if (!NumberUtil.isInteger(s.toString())) { - inputs[0].setText("0"); - } else { - NekoXConfig.customAppId = NumberUtil.parseInt(s.toString()); - } - } - - @Override - public void afterTextChanged(Editable s) { - } - }); - - inputs[1] = builder.addEditText("App Hash"); - inputs[1].setFilters(new InputFilter[]{new InputFilter.LengthFilter(BuildVars.OFFICAL_APP_HASH.length())}); - if (StrUtil.isNotBlank(NekoXConfig.customAppHash)) { - inputs[1].setText(NekoXConfig.customAppHash); - } - inputs[1].addTextChangedListener(new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { - } - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { - NekoXConfig.customAppHash = s.toString(); - } - - @Override - public void afterTextChanged(Editable s) { - } - }); - - if (NekoXConfig.customApi <= 2) { - - for (EditText input : inputs) input.setVisibility(View.GONE); - - } - - builder.addCancelButton(); - - builder.addButton(LocaleController.getString("Set", R.string.Set), (it) -> { - - int target = targetApi.get(); - - if (target > 2) { - - if (NekoXConfig.customAppId == 0) { - - inputs[0].requestFocus(); - AndroidUtilities.showKeyboard(inputs[0]); - - return Unit.INSTANCE; - - } else if (StrUtil.isBlank(NekoXConfig.customAppHash)) { - - inputs[1].requestFocus(); - AndroidUtilities.showKeyboard(inputs[1]); - - return Unit.INSTANCE; - - } - - } - - NekoXConfig.customApi = target; - NekoXConfig.saveCustomApi(); - - return Unit.INSTANCE; - - }); - - builder.show(); - } else if (id == menu_custom_dc) { AtomicInteger targetDc = new AtomicInteger(-1); @@ -645,7 +498,7 @@ public class LoginActivity extends BaseFragment implements NotificationCenter.No otherItem.addSubItem(4, R.drawable.list_bot, LocaleController.getString("BotLogin", R.string.BotLogin)); otherItem.addSubItem(menu_qr_login, R.drawable.wallet_qr, LocaleController.getString("ImportLogin", R.string.ImportLogin)); - otherItem.addSubItem(menu_custom_api, R.drawable.baseline_vpn_key_24, LocaleController.getString("CustomApi", R.string.CustomApi)); +// otherItem.addSubItem(menu_custom_api, R.drawable.baseline_vpn_key_24, LocaleController.getString("CustomApi", R.string.CustomApi)); otherItem.addSubItem(menu_custom_dc, R.drawable.baseline_sync_24, LocaleController.getString("CustomBackend", R.string.CustomBackend)); actionBar.setAllowOverlayTitle(true); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java index 5c4f92310..dafb1a80a 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java @@ -3047,7 +3047,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. }); } - if (NekoXConfig.showCensoredFeatures()) { + if (NekoXConfig.isDeveloper()) { builder.addItem(LocaleController.getString("DeveloperSettings", R.string.DeveloperSettings), R.drawable.baseline_developer_mode_24, (it) -> { BottomBuilder devBuilder = new BottomBuilder(ProfileActivity.this.getParentActivity()); devBuilder.addTitle(LocaleController.getString("DevModeTitle", R.string.DevModeTitle), LocaleController.getString("DevModeNotice", R.string.DevModeNotice)); diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoXConfig.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoXConfig.java index a53fe7292..eda7ffe3e 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoXConfig.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoXConfig.java @@ -16,6 +16,7 @@ import org.telegram.messenger.FileLog; import org.telegram.messenger.LocaleController; import org.telegram.messenger.NotificationCenter; import org.telegram.messenger.R; +import org.telegram.messenger.SharedConfig; import org.telegram.messenger.UserConfig; import org.telegram.ui.ActionBar.Theme; @@ -83,9 +84,9 @@ public class NekoXConfig { public static String ignoredUpdateTag = preferences.getString("ignoredUpdateTag", ""); public static long nextUpdateCheck = preferences.getLong("nextUpdateCheckTimestamp", 0); - public static int customApi = preferences.getInt("custom_api", 0); - public static int customAppId = preferences.getInt("custom_app_id", 0); - public static String customAppHash = preferences.getString("custom_app_hash", ""); +// public static int customApi = preferences.getInt("custom_api", 0); +// public static int customAppId = preferences.getInt("custom_app_id", 0); +// public static String customAppHash = preferences.getString("custom_app_hash", ""); public static void toggleDeveloperMode() { preferences.edit().putBoolean("developer_mode", developerMode = !developerMode).apply(); @@ -106,38 +107,10 @@ public class NekoXConfig { preferences.edit().putBoolean("disable_screenshot_detection", disableScreenshotDetection = !disableScreenshotDetection).apply(); } + private static Boolean hasDeveloper = null; + public static int currentAppId() { - switch (customApi) { - case 0: - return BuildConfig.APP_ID; - case 1: - return BuildVars.OFFICAL_APP_ID; - case 2: - return BuildVars.TGX_APP_ID; - default: - return customAppId; - } - } - - public static String currentAppHash() { - switch (customApi) { - case 0: - return BuildConfig.APP_HASH; - case 1: - return BuildVars.OFFICAL_APP_HASH; - case 2: - return BuildVars.TGX_APP_HASH; - default: - return customAppHash; - } - } - - public static void saveCustomApi() { - preferences.edit() - .putInt("custom_api", customApi) - .putInt("custom_app_id", customAppId) - .putString("custom_app_hash", customAppHash) - .apply(); + return BuildConfig.APP_ID; } public static void toggleDisableStatusUpdate() { @@ -158,13 +131,26 @@ public class NekoXConfig { preferences.edit().putString("ignoredUpdateTag", ignoredUpdateTag = ignored).apply(); } - public static void setNextUpdateCheck(long timestamp) { - preferences.edit().putLong("nextUpdateCheckTimestamp", nextUpdateCheck = timestamp).apply(); + public static String currentAppHash() { + return BuildConfig.APP_HASH; } - public static boolean showCensoredFeatures() { - long myId = UserConfig.getInstance(UserConfig.selectedAccount).clientUserId; - return NekoXConfig.developerMode || NekoXConfig.customApi > 0 || ArrayUtil.contains(NekoXConfig.developers, myId); + public static void setNextUpdateCheck(long timestamp) { + preferences.edit().putLong("nextUpdateCheckTimestamp", nextUpdateCheck = timestamp).apply(); + } + + public static boolean isDeveloper() { + if (hasDeveloper != null) + return hasDeveloper; + hasDeveloper = false; + for (int acc : SharedConfig.activeAccounts) { + long myId = UserConfig.getInstance(acc).clientUserId; + if (ArrayUtil.contains(NekoXConfig.developers, myId)) { + hasDeveloper = true; + break; + } + } + return hasDeveloper; } public static String getOpenPGPAppName() { diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoChatSettingsActivity.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoChatSettingsActivity.java index d6c6b00e1..8f4be7a79 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoChatSettingsActivity.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoChatSettingsActivity.java @@ -62,7 +62,6 @@ import tw.nekomimi.nekogram.config.cell.ConfigCellTextInput; public class NekoChatSettingsActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate { private final CellGroup cellGroup = new CellGroup(this); - private final boolean showCensoredFeatures = NekoXConfig.showCensoredFeatures(); private final AbstractConfigCell header0 = cellGroup.appendCell(new ConfigCellHeader(LocaleController.getString("StickerSize"))); private final AbstractConfigCell stickerSizeRow = cellGroup.appendCell(new ConfigCellCustom(998, true)); @@ -169,7 +168,7 @@ public class NekoChatSettingsActivity extends BaseFragment implements Notificati }); // Before listAdapter - if (!showCensoredFeatures) { + if (!NekoXConfig.isDeveloper()) { cellGroup.rows.remove(disableChatActionRow); cellGroup.rows.remove(disableChoosingStickerRow); cellGroup.rows.remove(ignoreBlockedRow); diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoGeneralSettingsActivity.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoGeneralSettingsActivity.java index b5b3b94d8..c116bcfb0 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoGeneralSettingsActivity.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoGeneralSettingsActivity.java @@ -77,7 +77,6 @@ public class NekoGeneralSettingsActivity extends BaseFragment { private ListAdapter listAdapter; private ValueAnimator statusBarColorAnimator; private DrawerProfilePreviewCell profilePreviewCell; - private final boolean showCensoredFeatures = NekoXConfig.showCensoredFeatures(); private final CellGroup cellGroup = new CellGroup(this); @@ -712,7 +711,7 @@ public class NekoGeneralSettingsActivity extends BaseFragment { } private void setCanNotChange() { - if (!showCensoredFeatures) + if (!NekoXConfig.isDeveloper()) cellGroup.rows.remove(hideSponsoredMessageRow); boolean enabled;