Skip to content

Commit bed736f

Browse files
the-nexi23rd
authored andcommitted
Added hidden accounts and stealth mode.
1 parent 03bf8ae commit bed736f

18 files changed

Lines changed: 823 additions & 105 deletions

TMessagesProj/src/main/java/org/telegram/messenger/ContactsController.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import androidx.collection.LongSparseArray;
3333

3434
import org.telegram.PhoneFormat.PhoneFormat;
35+
import org.telegram.messenger.forkgram.HiddenAccountHelper;
3536
import org.telegram.tgnet.ConnectionsManager;
3637
import org.telegram.tgnet.TLObject;
3738
import org.telegram.tgnet.TLRPC;
@@ -397,7 +398,7 @@ public void checkAppAccount() {
397398
boolean found = false;
398399
for (int b = 0; b < UserConfig.MAX_ACCOUNT_COUNT; b++) {
399400
TLRPC.User user = UserConfig.getInstance(b).getCurrentUser();
400-
if (user != null) {
401+
if (user != null && HiddenAccountHelper.isVisibleActivatedAccount(b)) {
401402
if (acc.name.equals("" + user.id)) {
402403
if (b == currentAccount) {
403404
systemAccount = acc;
@@ -419,7 +420,7 @@ public void checkAppAccount() {
419420
} catch (Throwable ignore) {
420421

421422
}
422-
if (getUserConfig().isClientActivated()) {
423+
if (HiddenAccountHelper.isVisibleActivatedAccount(currentAccount)) {
423424
readContacts();
424425
if (systemAccount == null) {
425426
try {
@@ -443,7 +444,7 @@ public void deleteUnknownAppAccounts() {
443444
boolean found = false;
444445
for (int b = 0; b < UserConfig.MAX_ACCOUNT_COUNT; b++) {
445446
TLRPC.User user = UserConfig.getInstance(b).getCurrentUser();
446-
if (user != null) {
447+
if (user != null && HiddenAccountHelper.isVisibleActivatedAccount(b)) {
447448
if (acc.name.equals("" + user.id)) {
448449
found = true;
449450
break;
@@ -530,11 +531,13 @@ public void deleteAllContacts(final Runnable runnable) {
530531
} catch (Throwable ignore) {
531532

532533
}
533-
try {
534-
systemAccount = new Account("" + getUserConfig().getClientUserId(), "org.telegram.messenger");
535-
am.addAccountExplicitly(systemAccount, "", null);
536-
} catch (Exception ignore) {
534+
if (HiddenAccountHelper.isVisibleActivatedAccount(currentAccount)) {
535+
try {
536+
systemAccount = new Account("" + getUserConfig().getClientUserId(), "org.telegram.messenger");
537+
am.addAccountExplicitly(systemAccount, "", null);
538+
} catch (Exception ignore) {
537539

540+
}
538541
}
539542
getMessagesStorage().putCachedPhoneBook(new HashMap<>(), false, true);
540543
getMessagesStorage().putContacts(new ArrayList<>(), true);

TMessagesProj/src/main/java/org/telegram/messenger/NotificationsController.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666

6767
import com.google.common.collect.Lists;
6868

69+
import org.telegram.messenger.forkgram.HiddenAccountHelper;
6970
import org.telegram.messenger.support.LongSparseIntArray;
7071
import org.telegram.messenger.utils.tlutils.TlUtils;
7172
import org.telegram.messenger.voip.VoIPGroupNotification;
@@ -1719,7 +1720,7 @@ public void processLoadedUnreadMessages(LongSparseArray<Integer> dialogs, ArrayL
17191720
private int getTotalAllUnreadCount() {
17201721
int count = 0;
17211722
for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) {
1722-
if (!UserConfig.getInstance(a).isClientActivated() || !SharedConfig.showNotificationsForAllAccounts && UserConfig.selectedAccount != a) {
1723+
if (!UserConfig.getInstance(a).isClientActivated() || HiddenAccountHelper.isAccountHidden(a) || !SharedConfig.showNotificationsForAllAccounts && UserConfig.selectedAccount != a) {
17231724
continue;
17241725
}
17251726
NotificationsController controller = getInstance(a);
@@ -4063,7 +4064,7 @@ private String validateChannelId(long dialogId, long topicId, String name, long[
40634064
}
40644065

40654066
private void showOrUpdateNotification(boolean notifyAboutLast) {
4066-
if (!getUserConfig().isClientActivated() || pushMessages.isEmpty() && storyPushMessages.isEmpty() || !SharedConfig.showNotificationsForAllAccounts && currentAccount != UserConfig.selectedAccount) {
4067+
if (!getUserConfig().isClientActivated() || HiddenAccountHelper.isAccountHidden(currentAccount) || pushMessages.isEmpty() && storyPushMessages.isEmpty() || !SharedConfig.showNotificationsForAllAccounts && currentAccount != UserConfig.selectedAccount) {
40674068
dismissNotification();
40684069
return;
40694070
}
@@ -4232,7 +4233,7 @@ private void showOrUpdateNotification(boolean notifyAboutLast) {
42324233

42334234
String detailText;
42344235
if (allowSummary) {
4235-
if (UserConfig.getActivatedAccountsCount() > 1) {
4236+
if (UserConfig.getVisibleAccountsCount() > 1) {
42364237
if (pushDialogs.size() == 1) {
42374238
detailText = UserObject.getFirstName(getUserConfig().getCurrentUser());
42384239
} else {

TMessagesProj/src/main/java/org/telegram/messenger/UserConfig.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.telegram.tgnet.SerializedData;
1919
import org.telegram.tgnet.TLRPC;
2020
import org.telegram.tgnet.tl.TL_account;
21+
import org.telegram.messenger.forkgram.HiddenAccountHelper;
2122

2223
import java.io.File;
2324
import java.util.Arrays;
@@ -109,6 +110,10 @@ public static int getActivatedAccountsCount() {
109110
return count;
110111
}
111112

113+
public static int getVisibleAccountsCount() {
114+
return HiddenAccountHelper.getVisibleAccountsCount();
115+
}
116+
112117
public UserConfig(int instance) {
113118
super(instance);
114119
}
@@ -473,6 +478,7 @@ public void updateSaveGalleryExceptions(int type, LongSparseArray<SaveToGalleryS
473478
public void clearConfig() {
474479
loadConfig();
475480
getPreferences().edit().clear().apply();
481+
HiddenAccountHelper.clearAccount(currentAccount);
476482

477483
sharingMyLocationUntil = 0;
478484
lastMyLocationShareTime = 0;

0 commit comments

Comments
 (0)