mirror of
https://codeberg.org/shroff/phylum.git
synced 2026-01-05 19:21:23 -06:00
[client] Rename LoggedInUser => AccountUser
This commit is contained in:
@@ -8,14 +8,14 @@ part 'permissions.dart';
|
||||
|
||||
const _persistKeyUser = 'user';
|
||||
|
||||
class LoggedInUser {
|
||||
class AccountUser {
|
||||
final int id;
|
||||
final String email;
|
||||
final String name;
|
||||
final String home;
|
||||
final int permissions;
|
||||
|
||||
LoggedInUser({
|
||||
AccountUser({
|
||||
required this.id,
|
||||
required this.email,
|
||||
required this.name,
|
||||
@@ -28,7 +28,7 @@ class LoggedInUser {
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
if (other is! LoggedInUser) return false;
|
||||
if (other is! AccountUser) return false;
|
||||
|
||||
return id == other.id &&
|
||||
email == other.email &&
|
||||
@@ -48,8 +48,8 @@ class LoggedInUser {
|
||||
"permissions": permissions,
|
||||
};
|
||||
|
||||
factory LoggedInUser.fromJson(Map<String, dynamic> map) {
|
||||
return LoggedInUser(
|
||||
factory AccountUser.fromJson(Map<String, dynamic> map) {
|
||||
return AccountUser(
|
||||
id: map['id'],
|
||||
email: map['email'],
|
||||
name: map['name'],
|
||||
@@ -64,30 +64,30 @@ class LoggedInUser {
|
||||
}
|
||||
}
|
||||
|
||||
class LoggedInUserNotifier extends StateNotifier<LoggedInUser> {
|
||||
class AccountUserNotifier extends StateNotifier<AccountUser> {
|
||||
final PhylumAccount _account;
|
||||
|
||||
LoggedInUser get user => state;
|
||||
set user(LoggedInUser value) => state = value;
|
||||
AccountUser get user => state;
|
||||
set user(AccountUser value) => state = value;
|
||||
|
||||
LoggedInUserNotifier._(this._account, super.state) {
|
||||
AccountUserNotifier._(this._account, super.state) {
|
||||
stream.listen((user) {
|
||||
_account.persist(_persistKeyUser, jsonEncode(user.toJson()));
|
||||
});
|
||||
}
|
||||
|
||||
factory LoggedInUserNotifier.fromUser(PhylumAccount account, LoggedInUser user) {
|
||||
factory AccountUserNotifier.fromUser(PhylumAccount account, AccountUser user) {
|
||||
account.persist(_persistKeyUser, jsonEncode(user.toJson()));
|
||||
return LoggedInUserNotifier._(account, user);
|
||||
return AccountUserNotifier._(account, user);
|
||||
}
|
||||
|
||||
factory LoggedInUserNotifier.fromAccount(PhylumAccount account) {
|
||||
final user = LoggedInUser.fromJson(jsonDecode(account.getPersisted(_persistKeyUser)));
|
||||
return LoggedInUserNotifier._(account, user);
|
||||
factory AccountUserNotifier.fromAccount(PhylumAccount account) {
|
||||
final user = AccountUser.fromJson(jsonDecode(account.getPersisted(_persistKeyUser)));
|
||||
return AccountUserNotifier._(account, user);
|
||||
}
|
||||
|
||||
@override
|
||||
bool updateShouldNotify(LoggedInUser old, LoggedInUser current) {
|
||||
bool updateShouldNotify(AccountUser old, AccountUser current) {
|
||||
return old != current;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import 'package:phylum/libphylum/db/db.dart';
|
||||
import 'package:phylum/libphylum/logged_in_user.dart';
|
||||
import 'package:phylum/libphylum/account_user.dart';
|
||||
|
||||
Bookmark parseBookmark(Map<String, dynamic> data) {
|
||||
return Bookmark(
|
||||
@@ -35,8 +35,8 @@ User parseUser(Map data) {
|
||||
);
|
||||
}
|
||||
|
||||
LoggedInUser parseLoggedInUser(Map data) {
|
||||
return LoggedInUser(
|
||||
AccountUser parseAccountUser(Map data) {
|
||||
return AccountUser(
|
||||
id: data['id'],
|
||||
email: data['email'],
|
||||
name: data['name'],
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
part of 'logged_in_user.dart';
|
||||
part of 'account_user.dart';
|
||||
|
||||
typedef UserPermission = int;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import 'dart:async';
|
||||
|
||||
import 'package:offtheline/offtheline.dart';
|
||||
import 'package:phylum/libphylum/db/db.dart';
|
||||
import 'package:phylum/libphylum/logged_in_user.dart';
|
||||
import 'package:phylum/libphylum/account_user.dart';
|
||||
import 'package:phylum/libphylum/repositories/bookmark_repository.dart';
|
||||
import 'package:phylum/libphylum/repositories/publink_repository.dart';
|
||||
import 'package:phylum/libphylum/repositories/resource_repository.dart';
|
||||
@@ -40,7 +40,7 @@ class PhylumAccount extends Account<PhylumAccount> {
|
||||
@override
|
||||
Dispatcher dispatcher = HttpClientDispatcher();
|
||||
|
||||
LoggedInUser? _initialLoggedInUser;
|
||||
AccountUser? _initialUser;
|
||||
|
||||
String? _accessToken;
|
||||
set accessToken(String value) {
|
||||
@@ -49,10 +49,10 @@ class PhylumAccount extends Account<PhylumAccount> {
|
||||
apiClient.setHeader('Authorization', 'bearer $value');
|
||||
}
|
||||
|
||||
late LoggedInUserNotifier _userNotifier;
|
||||
StateNotifier<LoggedInUser> get userNotifier => _userNotifier;
|
||||
LoggedInUser get user => _userNotifier.user;
|
||||
set user(LoggedInUser value) {
|
||||
late AccountUserNotifier _userNotifier;
|
||||
StateNotifier<AccountUser> get userNotifier => _userNotifier;
|
||||
AccountUser get user => _userNotifier.user;
|
||||
set user(AccountUser value) {
|
||||
_userNotifier.user = value;
|
||||
}
|
||||
|
||||
@@ -61,15 +61,15 @@ class PhylumAccount extends Account<PhylumAccount> {
|
||||
persist(_persistKeyBootstrapUntil, value);
|
||||
}
|
||||
|
||||
PhylumAccount._create({required super.serverUrl, required String accessToken, required LoggedInUser user})
|
||||
PhylumAccount._create({required super.serverUrl, required String accessToken, required AccountUser user})
|
||||
: _accessToken = accessToken,
|
||||
_initialLoggedInUser = user,
|
||||
_initialUser = user,
|
||||
super.create();
|
||||
|
||||
PhylumAccount.restore({required super.id}) : super.restore();
|
||||
|
||||
static Future<PhylumAccount> create(
|
||||
{required Uri serverUrl, required String accessToken, required LoggedInUser user}) async {
|
||||
{required Uri serverUrl, required String accessToken, required AccountUser user}) async {
|
||||
final account = PhylumAccount._create(serverUrl: serverUrl, accessToken: accessToken, user: user);
|
||||
await account.setup();
|
||||
return account;
|
||||
@@ -88,10 +88,10 @@ class PhylumAccount extends Account<PhylumAccount> {
|
||||
}
|
||||
apiClient.setHeader('Authorization', 'bearer $_accessToken');
|
||||
|
||||
if (_initialLoggedInUser != null) {
|
||||
_userNotifier = LoggedInUserNotifier.fromUser(this, _initialLoggedInUser!);
|
||||
if (_initialUser != null) {
|
||||
_userNotifier = AccountUserNotifier.fromUser(this, _initialUser!);
|
||||
} else {
|
||||
_userNotifier = LoggedInUserNotifier.fromAccount(this);
|
||||
_userNotifier = AccountUserNotifier.fromAccount(this);
|
||||
}
|
||||
|
||||
final dispatcherOverride = const String.fromEnvironment('dispatcher');
|
||||
|
||||
@@ -2,7 +2,7 @@ part of 'responses.dart';
|
||||
|
||||
class BootstrapLoginResponse extends PhylumApiSuccessResponse {
|
||||
final String? accessToken;
|
||||
final LoggedInUser user;
|
||||
final AccountUser user;
|
||||
final Iterable<Bookmark> bookmarks;
|
||||
final Iterable<User> users;
|
||||
final bool clear;
|
||||
@@ -22,7 +22,7 @@ class BootstrapLoginResponse extends PhylumApiSuccessResponse {
|
||||
final users = (data["users"] as List).cast<Map>().map((u) => parseUser(u.cast<String, dynamic>()));
|
||||
return BootstrapLoginResponse._(
|
||||
accessToken: data['access_token'],
|
||||
user: parseLoggedInUser(data['user']),
|
||||
user: parseAccountUser(data['user']),
|
||||
bookmarks: bookmarks,
|
||||
users: users,
|
||||
until: data['until'],
|
||||
|
||||
@@ -4,7 +4,7 @@ import 'package:drift/drift.dart';
|
||||
import 'package:http/http.dart';
|
||||
import 'package:offtheline/offtheline.dart';
|
||||
import 'package:phylum/libphylum/db/db.dart';
|
||||
import 'package:phylum/libphylum/logged_in_user.dart';
|
||||
import 'package:phylum/libphylum/account_user.dart';
|
||||
import 'package:phylum/libphylum/parsers/parsers.dart';
|
||||
import 'package:phylum/libphylum/phylum_account.dart';
|
||||
import 'package:phylum/util/permissions.dart';
|
||||
|
||||
@@ -4,7 +4,7 @@ import 'package:drift/drift.dart' show TableOrViewStatements;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:phylum/libphylum/actions/action_resource_share.dart';
|
||||
import 'package:phylum/libphylum/db/resource_helpers.dart';
|
||||
import 'package:phylum/libphylum/logged_in_user.dart';
|
||||
import 'package:phylum/libphylum/account_user.dart';
|
||||
import 'package:phylum/libphylum/phylum_account.dart';
|
||||
import 'package:phylum/ui/common/dialogs/new_user_details_dialog.dart';
|
||||
import 'package:phylum/util/dialogs.dart';
|
||||
|
||||
Reference in New Issue
Block a user