Skip to content

Commit 1fb5c09

Browse files
committed
app: Keep IntGlobalSetting.lastVisitedAccountId up-to-date
1 parent be2faab commit 1fb5c09

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

lib/widgets/app.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import '../generated/l10n/zulip_localizations.dart';
88
import '../log.dart';
99
import '../model/actions.dart';
1010
import '../model/localizations.dart';
11+
import '../model/settings.dart';
1112
import '../model/store.dart';
1213
import '../notifications/open.dart';
1314
import 'about_zulip.dart';
@@ -254,6 +255,7 @@ class _ZulipAppState extends State<ZulipApp> with WidgetsBindingObserver {
254255
if (widget.navigatorObservers != null)
255256
...widget.navigatorObservers!,
256257
_PreventEmptyStack(),
258+
_UpdateLastVisitedAccount(GlobalStoreWidget.settingsOf(context)),
257259
],
258260
builder: (BuildContext context, Widget? child) {
259261
if (!ZulipApp.ready.value) {
@@ -305,6 +307,20 @@ class _PreventEmptyStack extends NavigatorObserver {
305307
}
306308
}
307309

310+
class _UpdateLastVisitedAccount extends NavigatorObserver {
311+
_UpdateLastVisitedAccount(this.globalSettings);
312+
313+
final GlobalSettingsStore globalSettings;
314+
315+
@override
316+
void didChangeTop(Route<void> topRoute, Route<void>? previousTopRoute) {
317+
final old = globalSettings.getInt(IntGlobalSetting.lastVisitedAccountId);
318+
if (topRoute case AccountPageRouteMixin(accountId: var new_) when new_ != old) {
319+
globalSettings.setInt(IntGlobalSetting.lastVisitedAccountId, new_);
320+
}
321+
}
322+
}
323+
308324
class ChooseAccountPage extends StatelessWidget {
309325
const ChooseAccountPage({super.key});
310326

0 commit comments

Comments
 (0)