generated from Nodarx/template
feat: entity patch #30
@@ -91,6 +91,7 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
self::CAPABILITY_ENTITY_FETCH => true,
|
||||
self::CAPABILITY_ENTITY_CREATE => false,
|
||||
self::CAPABILITY_ENTITY_MODIFY => false,
|
||||
self::CAPABILITY_ENTITY_PATCH => true,
|
||||
self::CAPABILITY_ENTITY_DELETE => true,
|
||||
self::CAPABILITY_ENTITY_MOVE => true,
|
||||
self::CAPABILITY_ENTITY_COPY => false,
|
||||
@@ -631,8 +632,18 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
|
||||
foreach ($targets as $targetCollection => $targetIdentifiers) {
|
||||
$uids = array_keys($targetIdentifiers);
|
||||
$flagsAdd = [];
|
||||
$flagsRemove = [];
|
||||
|
||||
$mutations = $this->mailService->entityPatch($targetCollection, $properties, ...$uids);
|
||||
foreach ($properties->getFlags() as $flag => $value) {
|
||||
if ($value === true) {
|
||||
$flagsAdd[] = $flag;
|
||||
} elseif ($value === false) {
|
||||
$flagsRemove[] = $flag;
|
||||
}
|
||||
}
|
||||
|
||||
$mutations = $this->mailService->entityPatch($targetCollection, $flagsAdd, $flagsRemove, ...$uids);
|
||||
|
||||
foreach ($uids as $uid) {
|
||||
$list[(string)$targetIdentifiers[$uid]] = ['disposition' => 'patched'];
|
||||
|
||||
@@ -353,6 +353,9 @@ class RemoteMailService
|
||||
|
||||
$this->client->perform(new SelectCommand($collection, false));
|
||||
|
||||
$flagsToAdd = $this->normalizeFlags($flagsToAdd);
|
||||
$flagsToRemove = $this->normalizeFlags($flagsToRemove);
|
||||
|
||||
if (!empty($flagsToAdd)) {
|
||||
$this->client->perform(new StoreCommand(
|
||||
FetchTarget::uid(SequenceSet::items(...array_values($uids))),
|
||||
@@ -869,4 +872,23 @@ class RemoteMailService
|
||||
|
||||
return CollectionRoles::None->value;
|
||||
}
|
||||
|
||||
private function normalizeFlags(array $flags): array
|
||||
{
|
||||
$map = [
|
||||
'read' => '\\Seen',
|
||||
'answered' => '\\Answered',
|
||||
'flagged' => '\\Flagged',
|
||||
'deleted' => '\\Deleted',
|
||||
'draft' => '\\Draft',
|
||||
];
|
||||
$normalized = [];
|
||||
foreach ($flags as $flag) {
|
||||
$flag = strtolower(trim($flag));
|
||||
if (isset($map[$flag])) {
|
||||
$normalized[] = $map[$flag];
|
||||
}
|
||||
}
|
||||
return $normalized;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user