feat: Option to hide redacted and unknown events

This commit is contained in:
Sorunome 2020-11-07 12:00:41 +01:00
commit d500476fbc
16 changed files with 118 additions and 38 deletions

View file

@ -6,6 +6,7 @@ import 'package:path_provider/path_provider.dart';
import 'dart:async';
import 'dart:core';
import './database/shared.dart';
import '../config/setting_keys.dart';
import 'package:random_string/random_string.dart';
Future<Database> getDatabase(Client client) async {
@ -16,7 +17,7 @@ Future<Database> getDatabase(Client client) async {
try {
if (_db != null) return _db;
final store = Store();
var password = await store.getItem('database-password');
var password = await store.getItem(SettingKeys.databasePassword);
var newPassword = false;
if (password == null || password.isEmpty) {
newPassword = true;
@ -28,7 +29,7 @@ Future<Database> getDatabase(Client client) async {
password: password,
);
if (newPassword) {
await store.setItem('database-password', password);
await store.setItem(SettingKeys.databasePassword, password);
}
return _db;
} finally {
@ -74,6 +75,15 @@ class Store {
}
}
Future<bool> getItemBool(String key, [bool defaultValue]) async {
final value = await getItem(key);
if (value == null) {
return defaultValue ?? false;
}
// we also check for '1' for legacy reasons, some booleans were stored that way
return value == '1' || value.toLowerCase() == 'true';
}
Future<void> setItem(String key, String value) async {
if (!PlatformInfos.isMobile) {
await _setupLocalStorage();

View file

@ -15,6 +15,7 @@ import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:path_provider/path_provider.dart';
import '../components/matrix.dart';
import '../config/setting_keys.dart';
import 'famedlysdk_store.dart';
import 'matrix_locals.dart';
@ -42,8 +43,7 @@ abstract class FirebaseController {
token = null;
}
if (token?.isEmpty ?? true) {
final storeItem =
await matrix.store.getItem('chat.fluffy.show_no_google');
final storeItem = await matrix.store.getItem(SettingKeys.showNoGoogle);
final configOptionMissing = storeItem == null || storeItem.isEmpty;
if (configOptionMissing || (!configOptionMissing && storeItem == '1')) {
BotToast.showText(
@ -51,7 +51,7 @@ abstract class FirebaseController {
duration: Duration(seconds: 15),
);
if (configOptionMissing) {
await matrix.store.setItem('chat.fluffy.show_no_google', '0');
await matrix.store.setItem(SettingKeys.showNoGoogle, '0');
}
}
return;

View file

@ -7,6 +7,7 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:sentry/sentry.dart';
import 'famedlysdk_store.dart';
import '../config/setting_keys.dart';
abstract class SentryController {
static Future<void> toggleSentryAction(BuildContext context) async {
@ -17,14 +18,14 @@ abstract class SentryController {
cancelText: L10n.of(context).no,
);
final storage = Store();
await storage.setItem('sentry', enableSentry.toString());
await storage.setItem(SettingKeys.sentry, enableSentry.toString());
BotToast.showText(text: L10n.of(context).changesHaveBeenSaved);
return;
}
static Future<bool> getSentryStatus() async {
final storage = Store();
return await storage.getItem('sentry') == 'true';
return await storage.getItemBool(SettingKeys.sentry);
}
static final sentry = SentryClient(dsn: AppConfig.sentryDsn);