Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
5db8481
WIP on user full game list
ZTL-UwU Feb 24, 2024
7c94aae
Add bookmark button
ZTL-UwU Feb 24, 2024
8505629
Fix analysis
ZTL-UwU Feb 24, 2024
78ff233
Add pagination
ZTL-UwU Feb 25, 2024
dc9852a
Fix loading indicator behavior
ZTL-UwU Feb 25, 2024
326aabf
Merge branch 'main' into full-game-list
ZTL-UwU Apr 12, 2024
3ed4ffc
fix conflicts
ZTL-UwU Apr 12, 2024
3dd513c
remove gradle.properties proxy
ZTL-UwU Apr 12, 2024
024af03
fix analyze
ZTL-UwU Apr 12, 2024
1ff450d
use flutter_slidable
ZTL-UwU Apr 15, 2024
1887dbc
remove unnecessary import
ZTL-UwU Apr 15, 2024
bb11551
Merge branch 'main' into full-game-list
ZTL-UwU May 16, 2024
3b02bf2
Refactor game histroy
ZTL-UwU May 16, 2024
1e03c9b
Clear engine suggestion arrows after reaching checkmate or stalemate
timmcca-be May 27, 2024
03d12f5
Merge branch 'main' into full-game-list
ZTL-UwU May 28, 2024
4348ef8
Add side for game history & add comment for ExtendedGameListTile & fi…
ZTL-UwU May 28, 2024
78d936a
Merge pull request #724 from timmcca-be/m0-fix
veloce May 28, 2024
ad69b56
Replace getRecentGame with getUserGames
ZTL-UwU May 28, 2024
b66e02f
Add more missing context.mounted checks
veloce May 28, 2024
f339fc2
Fix format
veloce May 28, 2024
1f626f9
Add a doc comment
veloce May 28, 2024
3a45d3b
Improve LichessClient tests and types
veloce May 28, 2024
b9dd630
Use gameStorage when offline
ZTL-UwU May 28, 2024
854ce06
Remove duplicate method
veloce May 28, 2024
6a72d1c
Remove unused imports
ZTL-UwU May 28, 2024
0ab7560
Remove unused imports
ZTL-UwU May 28, 2024
5acb1a6
Remove comment
veloce May 28, 2024
10ed05e
Merge branch 'full-game-list' of https://github.com/ZTL-UwU/mobile in…
veloce May 28, 2024
bcbc2d5
Refactor recent game providers
veloce May 28, 2024
562b9ef
Show total number of games
veloce May 29, 2024
fb276e9
Retrict context menu analysis access to supported variants
veloce May 29, 2024
15ac0d5
Remove bookmark action for now, refactor
veloce May 29, 2024
5cb6b54
Use correct game count
veloce May 29, 2024
bd75349
Make max parameter mandatory
veloce May 29, 2024
cbe7b4d
Remove unused import
veloce May 29, 2024
b37150a
Only show more button if number of games > recent games
veloce May 29, 2024
7b6fb8f
Add missing trailing comma
veloce May 29, 2024
c3a082e
Tweak comment
veloce May 30, 2024
d29afcc
Comment out game count fields that we don't use for now
veloce May 30, 2024
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
16 changes: 1 addition & 15 deletions lib/src/model/account/account_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import 'package:lichess_mobile/src/model/common/http.dart';
import 'package:lichess_mobile/src/model/common/id.dart';
import 'package:lichess_mobile/src/model/common/perf.dart';
import 'package:lichess_mobile/src/model/common/speed.dart';
import 'package:lichess_mobile/src/model/game/archived_game.dart';
import 'package:lichess_mobile/src/model/game/game_repository.dart';
import 'package:lichess_mobile/src/model/user/user.dart';
import 'package:lichess_mobile/src/model/user/user_repository.dart';
import 'package:logging/logging.dart';
Expand Down Expand Up @@ -45,18 +43,6 @@ Future<IList<UserActivity>> accountActivity(AccountActivityRef ref) async {
);
}

@riverpod
Future<IList<LightArchivedGame>> accountRecentGames(
AccountRecentGamesRef ref,
) async {
final session = ref.watch(authSessionProvider);
if (session == null) return IList();
return ref.withClientCacheFor(
(client) => GameRepository(client).getRecentGames(session.user.id),
const Duration(hours: 1),
);
}

@riverpod
Future<IList<OngoingGame>> ongoingGames(OngoingGamesRef ref) async {
final session = ref.watch(authSessionProvider);
Expand All @@ -71,7 +57,7 @@ Future<IList<OngoingGame>> ongoingGames(OngoingGamesRef ref) async {
class AccountRepository {
AccountRepository(this.client);

final http.Client client;
final LichessClient client;
final Logger _log = Logger('AccountRepository');

Future<User> getProfile() {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/model/auth/auth_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ FlutterAppAuth appAuth(AppAuthRef ref) {

class AuthRepository {
AuthRepository(
http.Client client,
LichessClient client,
FlutterAppAuth appAuth,
) : _client = client,
_appAuth = appAuth;

final http.Client _client;
final LichessClient _client;
final Logger _log = Logger('AuthRepository');
final FlutterAppAuth _appAuth;

Expand Down
3 changes: 2 additions & 1 deletion lib/src/model/challenge/challenge_repository.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import 'package:http/http.dart' as http;
import 'package:lichess_mobile/src/model/common/http.dart';

import './challenge_request.dart';

class ChallengeRepository {
const ChallengeRepository(this.client);

final http.Client client;
final LichessClient client;

Future<void> challenge(String username, ChallengeRequest req) async {
final uri = Uri(path: '/api/challenge/$username');
Expand Down
5 changes: 4 additions & 1 deletion lib/src/model/common/eval.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ class ClientEval with _$ClientEval implements Eval {
}

IList<Move?> get bestMoves {
return pvs.map((e) => Move.fromUci(e.moves.first)).toIList();
return pvs
.where((e) => e.moves.isNotEmpty)
.map((e) => Move.fromUci(e.moves.first))
.toIList();
}

@override
Expand Down
36 changes: 12 additions & 24 deletions lib/src/model/common/http.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Client defaultClient(DefaultClientRef ref) {
///
/// Only one instance of this client is created and kept alive for the whole app.
@Riverpod(keepAlive: true)
Client lichessClient(LichessClientRef ref) {
LichessClient lichessClient(LichessClientRef ref) {
final client = LichessClient(
// Retry just once, after 500ms, on 429 Too Many Requests.
RetryClient(
Expand Down Expand Up @@ -178,8 +178,6 @@ class LichessClient implements Client {
final request = response.request!;
final method = request.method;
final url = request.url;
// TODD for now logging isn't much useful
// We could use improve it later to create an http logger in the app.
_logger.warning(
'$method $url responded with status ${response.statusCode} ${response.reasonPhrase}',
);
Expand Down Expand Up @@ -284,16 +282,16 @@ class LichessClient implements Client {

return Response.fromStream(await send(request));
}
}

/// Throws an error if [response] is not successful.
void _checkResponseSuccess(Uri url, Response response) {
if (response.statusCode < 400) return;
var message = 'Request to $url failed with status ${response.statusCode}';
if (response.reasonPhrase != null) {
message = '$message: ${response.reasonPhrase}';
}
throw ClientException('$message.', url);
/// Throws an error if [response] is not successful.
void _checkResponseSuccess(Uri url, Response response) {
if (response.statusCode < 400) return;
var message = 'Request to $url failed with status ${response.statusCode}';
if (response.reasonPhrase != null) {
message = '$message: ${response.reasonPhrase}';
}
throw ClientException('$message.', url);
}

extension ClientExtension on Client {
Expand Down Expand Up @@ -464,29 +462,19 @@ extension ClientExtension on Client {
);
}
}

/// Throws an error if [response] is not successful.
void _checkResponseSuccess(Uri url, Response response) {
if (response.statusCode < 400) return;
var message = 'Request to $url failed with status ${response.statusCode}';
if (response.reasonPhrase != null) {
message = '$message: ${response.reasonPhrase}';
}
throw ClientException('$message.', url);
}
}

extension ClientWidgetRefExtension on WidgetRef {
/// Runs [fn] with a [LichessClient].
Future<T> withClient<T>(Future<T> Function(Client) fn) async {
Future<T> withClient<T>(Future<T> Function(LichessClient) fn) async {
final client = read(lichessClientProvider);
return await fn(client);
}
}

extension ClientRefExtension on Ref {
/// Runs [fn] with a [LichessClient].
Future<T> withClient<T>(Future<T> Function(Client) fn) async {
Future<T> withClient<T>(Future<T> Function(LichessClient) fn) async {
final client = read(lichessClientProvider);
return await fn(client);
}
Expand All @@ -500,7 +488,7 @@ extension ClientAutoDisposeRefExtension<T> on AutoDisposeRef<T> {
/// If [fn] throws with a [SocketException], the provider is not kept alive, this
/// allows to retry the request later.
Future<U> withClientCacheFor<U>(
Future<U> Function(Client) fn,
Future<U> Function(LichessClient) fn,
Duration duration,
) async {
final link = keepAlive();
Expand Down
12 changes: 3 additions & 9 deletions lib/src/model/engine/uci_protocol.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ class UCIProtocol {
_stopRequested != true &&
parts.first == 'info') {
int depth = 0;
int? nodes;
int nodes = 0;
int multiPv = 1;
int? elapsedMs;
int elapsedMs = 0;
String? evalType;
bool isMate = false;
int? povEv;
Expand Down Expand Up @@ -130,16 +130,10 @@ class UCIProtocol {
}
}

// Sometimes we get #0. Let's just skip it.
if (isMate && povEv == 0) return;

// Track max pv index to determine when pv prints are done.
if (_expectedPvs < multiPv) _expectedPvs = multiPv;

if (depth < minDepth ||
nodes == null ||
elapsedMs == null ||
povEv == null) return;
if ((depth < minDepth && moves.isNotEmpty) || povEv == null) return;

final pivot = _work!.threatMode == true ? 0 : 1;
final ev = _work!.ply % 2 == pivot ? -povEv : povEv;
Expand Down
3 changes: 3 additions & 0 deletions lib/src/model/game/archived_game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ class ArchivedGame
: white;
}

/// A [LightArchivedGame] associated with a point of view of a player.
typedef LightArchivedGameWithPov = ({LightArchivedGame game, Side pov});

/// A lichess game exported from the API, with less data than [ArchivedGame].
///
/// This is commonly used to display a list of games.
Expand Down
Loading