Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
87 changes: 44 additions & 43 deletions lib/private/Activity/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,60 +11,43 @@

use OCP\Activity\Exceptions\InvalidValueException;
use OCP\Activity\IEvent;
use OCP\IAppConfig;
use OCP\RichObjectStrings\InvalidObjectExeption;
use OCP\RichObjectStrings\IRichTextFormatter;
use OCP\RichObjectStrings\IValidator;
use Psr\Log\LoggerInterface;

class Event implements IEvent {
/** @var string */
protected $app = '';
/** @var string */
protected $type = '';
/** @var string */
protected $affectedUser = '';
/** @var string */
protected $author = '';
/** @var int */
protected $timestamp = 0;
/** @var string */
protected $subject = '';
/** @var array */
protected $subjectParameters = [];
/** @var string */
protected $subjectParsed = '';
/** @var string */
protected $subjectRich = '';
protected string $app = '';
protected string $type = '';
protected string $affectedUser = '';
protected string $author = '';
protected int $timestamp = 0;
protected string $subject = '';
protected array $subjectParameters = [];
protected string $subjectParsed = '';
protected string $subjectRich = '';
/** @var array<string, array<string, string>> */
protected $subjectRichParameters = [];
/** @var string */
protected $message = '';
/** @var array */
protected $messageParameters = [];
/** @var string */
protected $messageParsed = '';
/** @var string */
protected $messageRich = '';
protected array $subjectRichParameters = [];
protected string $message = '';
protected array $messageParameters = [];
protected string $messageParsed = '';
protected string $messageRich = '';
/** @var array<string, array<string, string>> */
protected $messageRichParameters = [];
/** @var string */
protected $objectType = '';
/** @var int */
protected $objectId = 0;
/** @var string */
protected $objectName = '';
/** @var string */
protected $link = '';
/** @var string */
protected $icon = '';
/** @var bool */
protected $generateNotification = true;

/** @var IEvent|null */
protected $child;
protected array $messageRichParameters = [];
protected string $objectType = '';
protected int $objectId = 0;
protected string $objectName = '';
protected string $link = '';
protected string $icon = '';
protected bool $generateNotification = true;
protected ?IEvent $child;

public function __construct(
protected IValidator $richValidator,
protected IRichTextFormatter $richTextFormatter,
protected LoggerInterface $logger,
protected IAppConfig $appConfig,
) {
}

Expand Down Expand Up @@ -165,6 +148,24 @@ public function setSubject(string $subject, array $parameters = []): IEvent {
if (isset($subject[255])) {
throw new InvalidValueException('subject');
}

$counter = $this->appConfig->getValueInt('activity', 'overly_long_activities', 0);
foreach ($parameters as $parameter) {
if (strlen($parameter) > 4000) {
$counter++;
$this->logger->error('Activity with over 4000 characters detected', [

]);
} elseif (strlen($parameter) > 2000) {
$counter++;
$this->logger->warning('Activity with over 2000 characters detected', ['app' => $this->getApp()]);
}
}

if ($counter !== 0) {
$this->appConfig->setValueInt('activity', 'overly_long_activities', $counter);
}

$this->subject = $subject;
$this->subjectParameters = $parameters;
return $this;
Expand Down
6 changes: 5 additions & 1 deletion lib/private/Activity/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
use OCP\Activity\IProvider;
use OCP\Activity\ISetting;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IRequest;
use OCP\IUser;
use OCP\IUserSession;
use OCP\RichObjectStrings\IRichTextFormatter;
use OCP\RichObjectStrings\IValidator;
use Psr\Log\LoggerInterface;

class Manager implements IManager {

Expand All @@ -49,6 +51,8 @@ public function __construct(
protected IRichTextFormatter $richTextFormatter,
protected IL10N $l10n,
protected ITimeFactory $timeFactory,
protected IAppConfig $appConfig,
protected LoggerInterface $logger,
) {
}

Expand Down Expand Up @@ -92,7 +96,7 @@ protected function getConsumers(): array {
* @return IEvent
*/
public function generateEvent(): IEvent {
return new Event($this->validator, $this->richTextFormatter);
return new Event($this->validator, $this->richTextFormatter, $this->logger, $this->appConfig);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion lib/private/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -633,13 +633,15 @@ public function __construct($webRoot, \OC\Config $config) {
$this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
$l10n = $this->get(IFactory::class)->get('lib');
return new \OC\Activity\Manager(
$c->getRequest(),
$c->get(IRequest::class),
$c->get(IUserSession::class),
$c->get(\OCP\IConfig::class),
$c->get(IValidator::class),
$c->get(IRichTextFormatter::class),
$l10n,
$c->get(ITimeFactory::class),
$c->get(IAppConfig::class),
$c->get(LoggerInterface::class),
);
});

Expand Down
Loading