Skip to content
Open

WIP #558

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
"settings": "Settings",
"signInAndUp": "Sign In & Sing Up",
"signOut": "Sing out",
"share": "Share",
"startedOn": "Started on {date} at {hour}",
"@startedOn": {
"placeholders": {
Expand Down
1 change: 1 addition & 0 deletions lib/l10n/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
"score": "Score",
"search": "Rechercher",
"settings": "Param猫tres",
"share": "Partager",
"signInAndUp": "Connexion & Inscription",
"signOut": "D茅connexion",
"startedOn": "Commenc茅e le {date} 脿 {hour}",
Expand Down
26 changes: 26 additions & 0 deletions lib/models/player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Player extends CargPlayerObject with ChangeNotifier {
late String _profilePicture;
late bool _selected;
late bool _useGravatarProfilePicture;
late List<dynamic> _sharedWith;
static const String defaultProfilePicture =
'https://firebasestorage.googleapis.com/v0/b/carg-d3732.appspot.com/o/carg_logo.png?alt=media&token=861511da-db26-4216-8ee6-29b20c0a6852';

Expand All @@ -34,6 +35,27 @@ class Player extends CargPlayerObject with ChangeNotifier {
_gravatarProfilePicture = 'https://gravatar.com/avatar/$emailHash?s=200';
}

void sharePlayer(Player? player) {
if (player != null && player.linkedUserId != null) {
if (!sharedWith.contains(player.linkedUserId)) {
player.selected = true;
sharedWith.add(player.linkedUserId!);
notifyListeners();
} else if (sharedWith.contains(player.linkedUserId)) {
player.selected = false;
sharedWith.remove(player.linkedUserId!);
notifyListeners();
}
}
}

List<dynamic> get sharedWith => _sharedWith;

set sharedWith(List<dynamic> value) {
_sharedWith = value;
notifyListeners();
}

bool get useGravatarProfilePicture => _useGravatarProfilePicture;

set useGravatarProfilePicture(bool value) {
Expand Down Expand Up @@ -74,6 +96,7 @@ class Player extends CargPlayerObject with ChangeNotifier {
this.firstName,
this.lastName,
this.ownedBy,
sharedWith,
userName,
profilePicture,
this.linkedUserId,
Expand All @@ -89,6 +112,7 @@ class Player extends CargPlayerObject with ChangeNotifier {
_profilePicture = profilePicture ?? defaultProfilePicture;
_userName = userName ?? '';
_selected = false;
_sharedWith = sharedWith ?? [];
_useGravatarProfilePicture = useGravatarProfilePicture ?? false;
_gravatarProfilePicture = gravatarProfilePicture;
}
Expand All @@ -113,6 +137,7 @@ class Player extends CargPlayerObject with ChangeNotifier {
linkedUserId: json?['linked_user_id'],
profilePicture: json?['profile_picture'],
ownedBy: json?['owned_by'],
sharedWith: json?['shared_with'],
useGravatarProfilePicture:
json?['use_gravatar_profile_picture'] ?? false,
gravatarProfilePicture: json?['gravatar_profile_picture'],
Expand All @@ -133,6 +158,7 @@ class Player extends CargPlayerObject with ChangeNotifier {
'use_gravatar_profile_picture': useGravatarProfilePicture,
'linked_user_id': linkedUserId,
'owned_by': ownedBy,
'shared_with': sharedWith,
'owned': owned,
'testing': testing,
'admin': admin
Expand Down
28 changes: 28 additions & 0 deletions lib/services/impl/player_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,32 @@ class PlayerService extends AbstractPlayerService {
throw ServiceException('Error during the index search : ${e.toString()}');
}
}

@override
Future<void> sharePlayer({Player? player, List<String>? users}) async {
if (player == null || users == null) {
throw ServiceException('Please provide a player and an user list');
}
try {
player.sharedWith?.addAll(users);
await playerRepository.update(player);
} on RepositoryException catch (e) {
throw throw ServiceException(
'Impossible to modify the player ${player.id} : ${e.message}');
}
}

@override
Future<void> unSharePlayer({Player? player}) async {
if (player == null) {
throw ServiceException('Please provide a player and an user list');
}
try {
player.sharedWith?.clear();
await playerRepository.update(player);
} on RepositoryException catch (e) {
throw throw ServiceException(
'Impossible to modify the player ${player.id} : ${e.message}');
}
}
}
8 changes: 8 additions & 0 deletions lib/services/player/abstract_player_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,12 @@ abstract class AbstractPlayerService extends BaseAbstractService<Player> {
/// Return the player or null if not found
Future<List<Player>> searchPlayers(
{String query = '', Player? currentPlayer, bool? myPlayers});

/// Share a player with other users
Future<void> sharePlayer(
{Player? player, List<String>? users});

/// Remove all users with you shared the player
Future<void> unSharePlayer(
{Player? player});
}
Loading