Initial commit
Some checks failed
Main Deploy Workflow / deploy_web (push) Has been cancelled
Main Deploy Workflow / deploy_playstore_internal (push) Has been cancelled
Close stale issues and PRs / stale (push) Has been cancelled

This commit is contained in:
2026-09-11 15:59:56 -03:00
commit 0037b0b9cf
651 changed files with 199705 additions and 0 deletions

View File

@@ -0,0 +1,68 @@
// SPDX-FileCopyrightText: 2019-Present Christian Kußowski
// SPDX-FileCopyrightText: 2019-Present Contributors to FluffyChat
//
// SPDX-License-Identifier: AGPL-3.0-or-later
import 'package:matrix/matrix.dart';
extension ApplicationAccountConfigExtension on Client {
static const String accountDataKey = 'im.fluffychat.account_config';
ApplicationAccountConfig get applicationAccountConfig =>
ApplicationAccountConfig.fromJson(
accountData[accountDataKey]?.content ?? {},
);
Future<void> setApplicationAccountConfig(ApplicationAccountConfig config) =>
setAccountData(userID!, accountDataKey, config.toJson());
/// Only updates the specified values in ApplicationAccountConfig
Future<void> updateApplicationAccountConfig(ApplicationAccountConfig config) {
final currentConfig = applicationAccountConfig;
return setAccountData(
userID!,
accountDataKey,
ApplicationAccountConfig(
wallpaperUrl: config.wallpaperUrl ?? currentConfig.wallpaperUrl,
wallpaperOpacity:
config.wallpaperOpacity ?? currentConfig.wallpaperOpacity,
wallpaperBlur: config.wallpaperBlur ?? currentConfig.wallpaperBlur,
).toJson(),
);
}
}
class ApplicationAccountConfig {
final Uri? wallpaperUrl;
final double? wallpaperOpacity;
final double? wallpaperBlur;
const ApplicationAccountConfig({
this.wallpaperUrl,
this.wallpaperOpacity,
this.wallpaperBlur,
});
static double _sanitizedOpacity(double? opacity) {
if (opacity == null) return 1;
if (opacity > 1 || opacity < 0) return 1;
return opacity;
}
factory ApplicationAccountConfig.fromJson(Map<String, dynamic> json) =>
ApplicationAccountConfig(
wallpaperUrl: json['wallpaper_url'] is String
? Uri.tryParse(json['wallpaper_url'])
: null,
wallpaperOpacity: _sanitizedOpacity(
json.tryGet<double>('wallpaper_opacity'),
),
wallpaperBlur: json.tryGet<double>('wallpaper_blur'),
);
Map<String, dynamic> toJson() => {
'wallpaper_url': wallpaperUrl?.toString(),
'wallpaper_opacity': wallpaperOpacity,
'wallpaper_blur': wallpaperBlur,
};
}