feat: add remote sync state
Signed-off-by: Sebastian <krupinski01@gmail.com>
This commit is contained in:
@@ -46,6 +46,11 @@ class CompositionManager {
|
||||
'sender' => $sender,
|
||||
'message' => $message,
|
||||
'attachments' => [],
|
||||
'remote' => [
|
||||
'status' => 'dirty',
|
||||
'entity' => null,
|
||||
'error' => null,
|
||||
],
|
||||
];
|
||||
|
||||
// Construct the snapshot mutation that will run while the composition is locked.
|
||||
@@ -111,7 +116,9 @@ class CompositionManager {
|
||||
$saveComposition,
|
||||
) ?? $snapshot;
|
||||
|
||||
return $snapshot;
|
||||
$response = $snapshot;
|
||||
unset($response['remote']);
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function patch(string $tenantId, string $userId, string $identifier, array $data): array {
|
||||
@@ -140,6 +147,7 @@ class CompositionManager {
|
||||
$composed['revision'] = $data['revision'];
|
||||
$composed['sender'] = $data['sender'] ?? [];
|
||||
$composed['message'] = $data['message'] ?? [];
|
||||
$composed = $this->markRemoteDirty($composed);
|
||||
$result = [
|
||||
'identifier' => $identifier,
|
||||
'disposition' => 'patched',
|
||||
@@ -175,7 +183,7 @@ class CompositionManager {
|
||||
|
||||
$composed['sender'] = $sender;
|
||||
$composed['message'] = $message;
|
||||
return $composed;
|
||||
return $this->markRemoteDirty($composed);
|
||||
};
|
||||
|
||||
// Execute the mutation and atomically persist the snapshot it returns.
|
||||
@@ -367,6 +375,12 @@ class CompositionManager {
|
||||
$failed = $this->attachmentAddFromDocuments($tenantId, $userId, $composition, $documents, $composed);
|
||||
}
|
||||
|
||||
$deviceAttachmentsChanged = $uploads !== [];
|
||||
$documentAttachmentsChanged = count($failed) < count($documents);
|
||||
if ($deviceAttachmentsChanged || $documentAttachmentsChanged) {
|
||||
$composed = $this->markRemoteDirty($composed);
|
||||
}
|
||||
|
||||
return $composed;
|
||||
};
|
||||
|
||||
@@ -551,6 +565,7 @@ class CompositionManager {
|
||||
}
|
||||
|
||||
unset($composed['attachments'][$identifier]);
|
||||
$composed = $this->markRemoteDirty($composed);
|
||||
$result['disposition'] = 'removed';
|
||||
return $composed;
|
||||
};
|
||||
@@ -566,6 +581,19 @@ class CompositionManager {
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function markRemoteDirty(array $composed): array {
|
||||
$remote = isset($composed['remote']) && is_array($composed['remote'])
|
||||
? $composed['remote']
|
||||
: [];
|
||||
|
||||
$remote['status'] = 'dirty';
|
||||
$remote['entity'] ??= null;
|
||||
$remote['error'] = null;
|
||||
$composed['remote'] = $remote;
|
||||
|
||||
return $composed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int,array|string> $entries
|
||||
* @return array<int,Address>
|
||||
|
||||
Reference in New Issue
Block a user