1af8d6f068
(only for user, server and theme) This was done, because localstore is somewhat inconsistent in terms of events on different platforms. Also storing user, server and theme using shared-preferences should fit into flutters ecosystem a little better
69 lines
1.8 KiB
Dart
69 lines
1.8 KiB
Dart
import 'package:shared_preferences/shared_preferences.dart';
|
|
import './resolve_url.dart';
|
|
|
|
class User {
|
|
const User(
|
|
{required this.username, required this.password, required this.server});
|
|
|
|
final String username;
|
|
final String password;
|
|
final OutbagServer server;
|
|
|
|
Future<void> toDisk() async {
|
|
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
|
|
await prefs.setString('username', username);
|
|
await prefs.setString('password', password);
|
|
await server.toDisk();
|
|
}
|
|
|
|
static Future<User> fromDisk() async {
|
|
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
|
|
final server = await OutbagServer.fromDisk();
|
|
|
|
return User(
|
|
username: prefs.getString('username')!,
|
|
password: prefs.getString('password')!,
|
|
server: server);
|
|
}
|
|
|
|
static Future<void> removeDisk() async {
|
|
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
|
|
await prefs.remove('username');
|
|
await prefs.remove('password');
|
|
await OutbagServer.removeDisk();
|
|
}
|
|
|
|
String get humanReadable {
|
|
return '$username@${server.tag}';
|
|
}
|
|
}
|
|
|
|
class AccountMeta {
|
|
final int permissions;
|
|
final String username;
|
|
final bool discoverable;
|
|
final int maxRoomCount;
|
|
final int maxRoomSize;
|
|
final int maxRoomMemberCount;
|
|
|
|
const AccountMeta(
|
|
{required this.permissions,
|
|
required this.username,
|
|
required this.maxRoomSize,
|
|
required this.maxRoomCount,
|
|
required this.maxRoomMemberCount,
|
|
required this.discoverable});
|
|
|
|
factory AccountMeta.fromJSON(dynamic json) {
|
|
return AccountMeta(
|
|
permissions: json['rights'],
|
|
username: json['name'],
|
|
maxRoomSize: json['maxRoomSize'],
|
|
maxRoomCount: json['maxRooms'],
|
|
maxRoomMemberCount: json['maxUsersPerRoom'],
|
|
discoverable: json['viewable'] == 1);
|
|
}
|
|
}
|