Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: restore latest filter on app start #477

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/config/app_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import 'dart:ui';

import 'package:matrix/matrix.dart';

import '../pages/chat_list/chat_list.dart';

abstract class AppConfig {
static String _applicationName = 'FluffyChat';
static String get applicationName => _applicationName;
Expand Down Expand Up @@ -43,6 +45,7 @@ abstract class AppConfig {
static bool hideUnknownEvents = true;
static bool hideUnimportantStateEvents = true;
static bool separateChatTypes = false;
static ActiveFilter startFilter = ActiveFilter.allChats;
static bool autoplayImages = true;
static bool sendTypingNotifications = true;
static bool sendOnEnter = false;
Expand Down
1 change: 1 addition & 0 deletions lib/config/setting_keys.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ abstract class SettingKeys {
static const String hideUnimportantStateEvents =
'chat.fluffy.hideUnimportantStateEvents';
static const String separateChatTypes = 'chat.fluffy.separateChatTypes';
static const String startFilter = 'chat.fluffy.startFilter';
static const String sentry = 'sentry';
static const String theme = 'theme';
static const String amoledEnabled = 'amoled_enabled';
Expand Down
10 changes: 7 additions & 3 deletions lib/pages/chat_list/chat_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import 'package:fluffychat/utils/matrix_sdk_extensions/client_stories_extension.
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
import 'package:fluffychat/utils/platform_infos.dart';
import '../../../utils/account_bundles.dart';
import '../../config/setting_keys.dart';
import '../../utils/matrix_sdk_extensions/matrix_file_extension.dart';
import '../../utils/url_launcher.dart';
import '../../utils/voip/callkeep_manager.dart';
Expand Down Expand Up @@ -130,11 +131,14 @@ class ChatListController extends State<ChatList>
setState(() {
activeFilter = getActiveFilterByDestination(i);
});
AppConfig.startFilter = activeFilter;
Matrix.of(context).store.setString(
SettingKeys.startFilter,
activeFilter.name,
);
}

ActiveFilter activeFilter = AppConfig.separateChatTypes
? ActiveFilter.messages
: ActiveFilter.allChats;
ActiveFilter activeFilter = AppConfig.startFilter;

bool Function(Room) getRoomFilterByActiveFilter(ActiveFilter activeFilter) {
switch (activeFilter) {
Expand Down
12 changes: 11 additions & 1 deletion lib/pages/settings_chat/settings_chat_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:go_router/go_router.dart';

import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/config/setting_keys.dart';
import 'package:fluffychat/pages/chat_list/chat_list.dart';
import 'package:fluffychat/utils/platform_infos.dart';
import 'package:fluffychat/utils/voip/callkeep_manager.dart';
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
Expand Down Expand Up @@ -98,7 +99,16 @@ class SettingsChatView extends StatelessWidget {
),
SettingsSwitchListTile.adaptive(
title: L10n.of(context)!.separateChatTypes,
onChanged: (b) => AppConfig.separateChatTypes = b,
onChanged: (b) {
AppConfig.separateChatTypes = b;
// the filter on the app start must be one of the visible filters
AppConfig.startFilter =
b ? ActiveFilter.messages : ActiveFilter.allChats;
Matrix.of(context).store.setString(
SettingKeys.startFilter,
AppConfig.startFilter.name,
);
},
storeKey: SettingKeys.separateChatTypes,
defaultValue: AppConfig.separateChatTypes,
),
Expand Down
5 changes: 5 additions & 0 deletions lib/widgets/matrix.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import 'package:fluffychat/utils/voip_plugin.dart';
import 'package:fluffychat/widgets/fluffy_chat_app.dart';
import '../config/app_config.dart';
import '../config/setting_keys.dart';
import '../pages/chat_list/chat_list.dart';
import '../pages/key_verification/key_verification_dialog.dart';
import '../utils/account_bundles.dart';
import '../utils/background_push.dart';
Expand Down Expand Up @@ -447,6 +448,10 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
store.getBool(SettingKeys.separateChatTypes) ??
AppConfig.separateChatTypes;

AppConfig.startFilter = ActiveFilter.values.byName(
store.getString(SettingKeys.startFilter) ?? AppConfig.startFilter.name,
);

AppConfig.autoplayImages =
store.getBool(SettingKeys.autoplayImages) ?? AppConfig.autoplayImages;

Expand Down
Loading