fix(watch): finalise correctif sync workoutHistory/exercise et distance live montre (#157)

This commit is contained in:
2026-07-29 11:22:17 +02:00
parent 6f913e4e8d
commit 30c6259748
28 changed files with 1658 additions and 248 deletions

View File

@ -765,7 +765,7 @@ abstract interface class RemoteShareApi {
});
Future<List<ShareInboxItem>> fetchInbox(String token);
Future<RemoteSyncedItem> acceptShare(String shareId, String token);
Future<List<RemoteSyncedItem>> acceptShare(String shareId, String token);
Future<void> declineShare(String shareId, String token);
Future<void> revokeShare(String shareId, String token);
}

View File

@ -632,15 +632,15 @@ final class ShareUseCases {
return;
}
try {
if (cachedItem?.resourceType == ShareResourceType.pack) {
await remoteShareApi.acceptShare(shareId, token);
await _importSharedPayload(cachedItem!);
final createdResources = await remoteShareApi.acceptShare(shareId, token);
final cachedPackItem = cachedItem;
if (cachedPackItem != null &&
cachedPackItem.resourceType == ShareResourceType.pack) {
await _importSharedPayload(cachedPackItem);
} else {
final createdResource = await remoteShareApi.acceptShare(
shareId,
token,
);
await localChanges.applyRemoteItem(createdResource);
for (final createdResource in createdResources) {
await localChanges.applyRemoteItem(createdResource);
}
}
await inboxRepository.markStatus(
shareId,
@ -794,11 +794,13 @@ final class ShareUseCases {
if (item?.resourceType == ShareResourceType.pack) {
await remoteShareApi.acceptShare(action.shareId!, token);
} else {
final created = await remoteShareApi.acceptShare(
final createdResources = await remoteShareApi.acceptShare(
action.shareId!,
token,
);
await localChanges.applyRemoteItem(created);
for (final createdResource in createdResources) {
await localChanges.applyRemoteItem(createdResource);
}
}
await inboxRepository.markStatus(
action.shareId!,
@ -3505,6 +3507,7 @@ bool _hasSameWatchCommandRevisionState(
left.deviceSessionId == right.deviceSessionId &&
left.phase == right.phase &&
left.phoneReachable == right.phoneReachable &&
left.expiresAtEpochMs == right.expiresAtEpochMs &&
left.seriesIndex == right.seriesIndex &&
left.seriesTotal == right.seriesTotal &&
left.exerciseName == right.exerciseName &&
@ -3533,6 +3536,7 @@ bool _hasSameWatchCommandRevisionState(
left.canDecrementScore == right.canDecrementScore &&
left.manualScoreTargetValue == right.manualScoreTargetValue &&
left.manualScoreTargetLabel == right.manualScoreTargetLabel &&
left.manualScoreRepsTargetValue == right.manualScoreRepsTargetValue &&
left.manualScoreScope == right.manualScoreScope;
}
@ -4055,6 +4059,7 @@ final class WatchSessionProjectionProjector {
deviceSessionId: '',
revision: revision,
projectedAtEpochMs: _epochMs(now),
expiresAtEpochMs: _watchProjectionExpiresAtEpochMs(now),
phase: WatchSessionPhase.noActiveSession,
phoneReachable: true,
seriesIndex: 0,
@ -4075,6 +4080,7 @@ final class WatchSessionProjectionProjector {
deviceSessionId: session.metadata.id,
revision: revision,
projectedAtEpochMs: _epochMs(now),
expiresAtEpochMs: _watchProjectionExpiresAtEpochMs(now),
phase: WatchSessionPhase.noActiveSession,
phoneReachable: true,
seriesIndex: session.currentSetIndex + 1,
@ -4150,6 +4156,7 @@ final class WatchSessionProjectionProjector {
deviceSessionId: session.metadata.id,
revision: revision,
projectedAtEpochMs: projectedAtEpochMs,
expiresAtEpochMs: _watchProjectionExpiresAtEpochMs(now),
phase: phase,
phoneReachable: true,
seriesIndex: session.currentSetIndex + 1,
@ -4202,6 +4209,7 @@ final class WatchSessionProjectionProjector {
canDecrementScore: (manualScoreProjection?.value ?? 0) > 0,
manualScoreTargetValue: manualScoreProjection?.targetValue,
manualScoreTargetLabel: manualScoreProjection?.targetLabel,
manualScoreRepsTargetValue: manualScoreProjection?.repsTargetValue,
manualScoreScope: manualScoreProjection?.scope,
);
}
@ -4274,12 +4282,14 @@ final class _WatchManualScoreProjectionData {
required this.value,
this.targetValue,
this.targetLabel,
this.repsTargetValue,
});
final WatchManualScoreScope scope;
final double value;
final double? targetValue;
final String? targetLabel;
final int? repsTargetValue;
}
_WatchManualScoreProjectionData? _watchManualScoreProjection({
@ -4304,6 +4314,9 @@ _WatchManualScoreProjectionData? _watchManualScoreProjection({
value: result?.actualScore ?? 0,
targetValue: step.defaultTargetScore,
targetLabel: step.defaultTargetScore == null ? null : 'Cible',
repsTargetValue: step.type == ExerciseStepType.reps
? step.defaultTargetValue
: null,
);
}
if (snapshot.scoreEnabled &&
@ -4612,6 +4625,13 @@ String? _betweenSetsNextExerciseName(
int _epochMs(DateTime value) => value.toUtc().millisecondsSinceEpoch;
int _watchProjectionExpiresAtEpochMs(DateTime projectedAt) {
return projectedAt
.toUtc()
.add(const Duration(seconds: 12))
.millisecondsSinceEpoch;
}
final class ActiveExerciseStepUseCases {
const ActiveExerciseStepUseCases({
required this.sessionRepository,