Dev setting: disableStatusUpdate

(cherry picked from commit e4c8827008)
This commit is contained in:
世界 2020-07-02 03:28:34 +00:00
parent 2b22dbdb25
commit 3bb2a89c03
No known key found for this signature in database
GPG Key ID: CD109927C34A63C4
7 changed files with 146 additions and 28 deletions

View File

@ -58,6 +58,7 @@ import java.util.concurrent.CountDownLatch;
import tw.nekomimi.nekogram.ExternalGcm;
import tw.nekomimi.nekogram.InternalFilters;
import tw.nekomimi.nekogram.NekoConfig;
import tw.nekomimi.nekogram.NekoXConfig;
import tw.nekomimi.nekogram.utils.AlertUtil;
import tw.nekomimi.nekogram.utils.ThreadUtil;
import tw.nekomimi.nekogram.utils.UIUtil;
@ -230,6 +231,11 @@ public class MessagesController extends BaseController implements NotificationCe
private int statusRequest;
private int statusSettingState;
private boolean offlineSent;
public boolean isOnline() {
return !offlineSent;
}
private String uploadingAvatar;
private HashMap<String, Object> uploadingThemes = new HashMap<>();
@ -4362,6 +4368,30 @@ public class MessagesController extends BaseController implements NotificationCe
});
}
public void updateStatus(boolean online) {
statusSettingState = online ? 2 : 1;
if (statusRequest != 0) {
getConnectionsManager().cancelRequest(statusRequest, true);
}
offlineSent = !online;
AndroidUtilities.runOnUIThread(() -> NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.updateUserStatus, (Object) null));
TLRPC.TL_account_updateStatus req = new TLRPC.TL_account_updateStatus();
req.offline = !online;
statusRequest = getConnectionsManager().sendRequest(req, (response, error) -> {
if (error == null) {
lastStatusUpdateTime = System.currentTimeMillis();
statusSettingState = 0;
} else {
AlertUtil.showToast(error);
}
statusRequest = 0;
});
}
public void updateTimerProc() {
long currentTime = System.currentTimeMillis();
@ -4379,20 +4409,25 @@ public class MessagesController extends BaseController implements NotificationCe
getConnectionsManager().cancelRequest(statusRequest, true);
}
TLRPC.TL_account_updateStatus req = new TLRPC.TL_account_updateStatus();
req.offline = false;
statusRequest = getConnectionsManager().sendRequest(req, (response, error) -> {
if (error == null) {
lastStatusUpdateTime = System.currentTimeMillis();
offlineSent = false;
statusSettingState = 0;
} else {
if (lastStatusUpdateTime != 0) {
lastStatusUpdateTime += 5000;
if (NekoXConfig.disableStatusUpdate) {
lastStatusUpdateTime = System.currentTimeMillis();
statusSettingState = 0;
} else {
TLRPC.TL_account_updateStatus req = new TLRPC.TL_account_updateStatus();
req.offline = false;
statusRequest = getConnectionsManager().sendRequest(req, (response, error) -> {
if (error == null) {
lastStatusUpdateTime = System.currentTimeMillis();
offlineSent = false;
statusSettingState = 0;
} else {
if (lastStatusUpdateTime != 0) {
lastStatusUpdateTime += 5000;
}
}
}
statusRequest = 0;
});
statusRequest = 0;
});
}
}
}
} else if (statusSettingState != 2 && !offlineSent && Math.abs(System.currentTimeMillis() - getConnectionsManager().getPauseTime()) >= 2000) {
@ -4400,18 +4435,22 @@ public class MessagesController extends BaseController implements NotificationCe
if (statusRequest != 0) {
getConnectionsManager().cancelRequest(statusRequest, true);
}
TLRPC.TL_account_updateStatus req = new TLRPC.TL_account_updateStatus();
req.offline = true;
statusRequest = getConnectionsManager().sendRequest(req, (response, error) -> {
if (error == null) {
offlineSent = true;
} else {
if (lastStatusUpdateTime != 0) {
lastStatusUpdateTime += 5000;
}
}
if (NekoXConfig.disableStatusUpdate) {
statusRequest = 0;
});
} else {
TLRPC.TL_account_updateStatus req = new TLRPC.TL_account_updateStatus();
req.offline = true;
statusRequest = getConnectionsManager().sendRequest(req, (response, error) -> {
if (error == null) {
offlineSent = true;
} else {
if (lastStatusUpdateTime != 0) {
lastStatusUpdateTime += 5000;
}
}
statusRequest = 0;
});
}
}
if (updatesQueueChannels.size() != 0) {
@ -11447,8 +11486,15 @@ public class MessagesController extends BaseController implements NotificationCe
toDbUser.status = update.status;
dbUsersStatus.add(toDbUser);
if (update.user_id == getUserConfig().getClientUserId()) {
boolean offline = !(update.status instanceof TLRPC.TL_userStatusOnline);
getNotificationsController().setLastOnlineFromOtherDevice(update.status.expires);
if (NekoXConfig.keepOnlineStatus && offline != offlineSent) {
getMessagesController().updateStatus(offline);
} else {
offlineSent = offline;
}
}
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.updateUserStatus, update);
} else if (baseUpdate instanceof TLRPC.TL_updateUserName) {
TLRPC.TL_updateUserName update = (TLRPC.TL_updateUserName) baseUpdate;
final TLRPC.User currentUser = getUser(update.user_id);

View File

@ -190,6 +190,10 @@ public class NotificationCenter {
public static final int messagePlayingSpeedChanged = totalEvents++;
public static final int screenStateChanged = totalEvents++;
// custom
public static final int updateUserStatus = totalEvents++;
private SparseArray<ArrayList<NotificationCenterDelegate>> observers = new SparseArray<>();
private SparseArray<ArrayList<NotificationCenterDelegate>> removeAfterBroadcast = new SparseArray<>();
private SparseArray<ArrayList<NotificationCenterDelegate>> addAfterBroadcast = new SparseArray<>();

View File

@ -19,12 +19,14 @@ import androidx.recyclerview.widget.RecyclerView;
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.LocaleController;
import org.telegram.messenger.MessagesController;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.messenger.SharedConfig;
import org.telegram.messenger.UserConfig;
import org.telegram.tgnet.TLRPC;
import org.telegram.ui.ActionBar.Theme;
import org.telegram.ui.Cells.DividerCell;
import org.telegram.ui.Cells.DrawerActionCell;
@ -40,8 +42,10 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Locale;
import cn.hutool.core.util.StrUtil;
import kotlin.jvm.functions.Function0;
import tw.nekomimi.nekogram.NekoConfig;
import tw.nekomimi.nekogram.NekoXConfig;
public class DrawerLayoutAdapter extends RecyclerListView.SelectionAdapter implements NotificationCenter.NotificationCenterDelegate {
@ -102,8 +106,17 @@ public class DrawerLayoutAdapter extends RecyclerListView.SelectionAdapter imple
return accountsShown;
}
@Override public void didReceivedNotification(int id, int account, Object... args) {
resetItems();
@Override
public void didReceivedNotification(int id, int account, Object... args) {
if (id == NotificationCenter.updateUserStatus) {
if (args[0] != null) {
TLRPC.TL_updateUserStatus update = (TLRPC.TL_updateUserStatus) args[0];
int selectedUserId = UserConfig.getInstance(UserConfig.selectedAccount).getClientUserId();
if (update.user_id != selectedUserId) {
return;
}
}
}
notifyDataSetChanged();
}
@ -262,8 +275,20 @@ public class DrawerLayoutAdapter extends RecyclerListView.SelectionAdapter imple
return true;
}));
}
if (NekoXConfig.disableStatusUpdate && !UserConfig.getInstance(UserConfig.selectedAccount).isBot) {
boolean online = MessagesController.getInstance(UserConfig.selectedAccount).isOnline();
String message = online ? StrUtil.upperFirst(LocaleController.getString("Online", R.string.Online)) : LocaleController.getString("VoipOfflineTitle",R.string.VoipOfflineTitle);
if (NekoXConfig.keepOnlineStatus) {
message += " (" + LocaleController.getString("Locked",R.string.Locked) + ")";
}
items.add(new CheckItem(14, message, R.drawable.baseline_visibility_24, () -> online, () -> {
MessagesController controller = MessagesController.getInstance(UserConfig.selectedAccount);
controller.updateStatus(!online);
return true;
}));
}
items.add(null); // divider
items.add(new CheckItem(12,LocaleController.getString("DarkMode",R.string.NightMode),R.drawable.baseline_brightness_2_24,() -> Theme.getActiveTheme().isDark(),null));
items.add(new CheckItem(12, LocaleController.getString("DarkMode", R.string.NightMode), R.drawable.baseline_brightness_2_24, () -> Theme.getActiveTheme().isDark(), null));
}
public int getId(int position) {
@ -311,7 +336,7 @@ public class DrawerLayoutAdapter extends RecyclerListView.SelectionAdapter imple
public Function0<Boolean> isChecked;
public Function0<Boolean> doSwitch;
public CheckItem(int id, String text, int icon, Function0<Boolean> isChecked,@Nullable Function0<Boolean> doSwitch) {
public CheckItem(int id, String text, int icon, Function0<Boolean> isChecked, @Nullable Function0<Boolean> doSwitch) {
super(id, text, icon);
this.isChecked = isChecked;
this.doSwitch = doSwitch;

View File

@ -598,6 +598,9 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
} else if (id == 13) {
presentFragment(new ProxyListActivity());
drawerLayoutContainer.closeDrawer(false);
} else if (id == 14) {
NekoXConfig.toggleKeepOnlineStatus();;
drawerLayoutAdapter.notifyDataSetChanged();
}
} else {
int id = drawerLayoutAdapter.getId(position);
@ -678,7 +681,9 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.didSetNewWallpapper);
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.notificationsCountUpdated);
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.screenStateChanged);
NotificationCenter.getGlobalInstance().addObserver(drawerLayoutAdapter, NotificationCenter.proxySettingsChanged);
NotificationCenter.getGlobalInstance().addObserver(drawerLayoutAdapter, NotificationCenter.updateUserStatus);
if (actionBarLayout.fragmentsStack.isEmpty()) {
if (!UserConfig.getInstance(currentAccount).isClientActivated()) {
@ -898,6 +903,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
PrivacyUtil.postCheckAll(this, account);
}
updateCurrentConnectionState(currentAccount);
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.updateUserStatus, (Object) null);
}
private void switchToAvailableAccountOrLogout() {
@ -2861,6 +2867,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.notificationsCountUpdated);
NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.screenStateChanged);
NotificationCenter.getGlobalInstance().removeObserver(drawerLayoutAdapter, NotificationCenter.proxySettingsChanged);
NotificationCenter.getGlobalInstance().removeObserver(drawerLayoutAdapter, NotificationCenter.updateUserStatus);
}

View File

@ -4,6 +4,7 @@ import android.content.SharedPreferences;
import org.telegram.messenger.BuildConfig;
import org.telegram.messenger.BuildVars;
import org.telegram.messenger.NotificationCenter;
import tw.nekomimi.nekogram.database.NitritesKt;
@ -19,6 +20,10 @@ public class NekoXConfig {
public static boolean disableFlagSecure = preferences.getBoolean("disable_flag_secure", false);
public static boolean disableScreenshotDetection = preferences.getBoolean("disable_screenshot_detection", false);
public static boolean disableStatusUpdate = preferences.getBoolean("disable_status_update", false);
public static boolean keepOnlineStatus = preferences.getBoolean("keepOnlineStatus", false);
public static void toggleDeveloperMode() {
preferences.edit().putBoolean("developer_mode", developerMode = !developerMode).apply();
@ -28,8 +33,10 @@ public class NekoXConfig {
preferences.edit()
.putBoolean("disable_flag_secure", disableFlagSecure = false)
.putBoolean("disable_screenshot_detection", disableScreenshotDetection = false)
.putBoolean("disable_status_update", disableStatusUpdate = false)
.apply();
}
}
@ -115,4 +122,21 @@ public class NekoXConfig {
}
public static void toggleDisableStatusUpdate() {
preferences.edit().putBoolean("disable_status_update", disableStatusUpdate = !disableStatusUpdate).apply();
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.updateUserStatus, (Object) null);
}
public static void toggleKeepOnlineStatus() {
preferences.edit().putBoolean("keepOnlineStatus", keepOnlineStatus = !keepOnlineStatus).apply();
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.updateUserStatus, (Object) null);
}
}

View File

@ -51,6 +51,7 @@ public class NekoXSettingActivity extends BaseFragment {
private int enableRow;
private int disableFlagSecureRow;
private int disableScreenshotDetectionRow;
private int disableStatusUpdateRow;
private int fetchAndExportLangRow;
private int checkUpdateRepoForceRow;
@ -119,6 +120,11 @@ public class NekoXSettingActivity extends BaseFragment {
if (view instanceof TextCheckCell) {
((TextCheckCell) view).setChecked(NekoXConfig.disableScreenshotDetection);
}
} else if (position == disableStatusUpdateRow) {
NekoXConfig.toggleDisableStatusUpdate();
if (view instanceof TextCheckCell) {
((TextCheckCell) view).setChecked(NekoXConfig.disableStatusUpdate);
}
}
});
@ -143,6 +149,7 @@ public class NekoXSettingActivity extends BaseFragment {
disableFlagSecureRow = rowCount++;
disableScreenshotDetectionRow = rowCount++;
disableStatusUpdateRow = rowCount++;
fetchAndExportLangRow = rowCount++;
checkUpdateRepoForceRow = rowCount++;
@ -282,6 +289,9 @@ public class NekoXSettingActivity extends BaseFragment {
textCell.setTextAndCheck("Disable Flag Secure", NekoXConfig.disableFlagSecure, true);
} else if (position == disableScreenshotDetectionRow) {
textCell.setTextAndCheck("Disable Screenshot Detection", NekoXConfig.disableScreenshotDetection, false);
} else if (position == disableStatusUpdateRow) {
textCell.setTextAndCheck("Disable Status Update", NekoXConfig.disableStatusUpdate, false);
}
}
break;

View File

@ -3,6 +3,8 @@
<string name="NekoX" translatable="false">Nekogram X</string>
<string name="Locked">Locked</string>
<string name="CustomApi">Custom API</string>
<string name="UseCustomApiNotice">Log in using the custom api, if you are unable to register or log in, this may help.\n\nNote: fcm will not work if you are using the release version.</string>
<string name="CustomApiNo">Don\'t use custom API</string>