generated from Nodarx/template
feat: serve message fetches from the cache
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -139,6 +139,25 @@ class MessageProperties extends MessagePropertiesMutableAbstract {
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the (cut off) content of a body section with its full content and clear its incomplete mark.
|
||||
*
|
||||
* @return bool whether the section exists in the body
|
||||
*/
|
||||
public function completeSection(string $partId, string $content): bool
|
||||
{
|
||||
if (!isset($this->data[static::PROPERTY_BODY]) || !is_array($this->data[static::PROPERTY_BODY])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$found = self::replaceSectionContent($this->data[static::PROPERTY_BODY], $partId, $content);
|
||||
if ($found) {
|
||||
$this->incompleteSections = array_values(array_diff($this->incompleteSections, [$partId]));
|
||||
}
|
||||
|
||||
return $found;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialise the fields the meta store needs for list, filter and sort.
|
||||
*
|
||||
@@ -209,6 +228,23 @@ class MessageProperties extends MessagePropertiesMutableAbstract {
|
||||
return $this;
|
||||
}
|
||||
|
||||
private static function replaceSectionContent(array &$part, string $partId, string $content): bool
|
||||
{
|
||||
if ((string) ($part['partId'] ?? '') === $partId) {
|
||||
$part['content'] = $content;
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($part['subParts'] ?? [] as $index => $child) {
|
||||
if (is_array($child) && self::replaceSectionContent($child, $partId, $content)) {
|
||||
$part['subParts'][$index] = $child;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function cachePreview(int $length = 200): string
|
||||
{
|
||||
$text = $this->getBodyTextPlain();
|
||||
|
||||
Reference in New Issue
Block a user