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 toDisk() async { final SharedPreferences prefs = await SharedPreferences.getInstance(); await prefs.setString('username', username); await prefs.setString('password', password); await server.toDisk(); } static Future 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 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); } }