Skip to content
Draft
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
47 changes: 44 additions & 3 deletions lib/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,52 @@
) {
}

/**
* Check if the event should be processed (not excluded and has valid target)
*
* @param IEvent $event
* @return bool
*/
private function shouldSend(IEvent $event): bool {
return $event->getAffectedUser() !== '' && !$this->isExcludedAuthor($event);
}

/**
* Check if the event's author is excluded from activity logging
*
* @param IEvent $event
* @return bool
*/
private function isExcludedAuthor(IEvent $event): bool {
$excludedUsers = $this->config->getSystemValue('activity_log_exclude_users', []);
if (empty($excludedUsers)) {
return false;
}
$author = $event->getAuthor();
if ($author === null || $author === '') {

Check failure on line 63 in lib/Data.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

TypeDoesNotContainNull

lib/Data.php:63:7: TypeDoesNotContainNull: Type string for $author is never null (see https://psalm.dev/090)

Check failure on line 63 in lib/Data.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

TypeDoesNotContainNull

lib/Data.php:63:7: TypeDoesNotContainNull: string does not contain null (see https://psalm.dev/090)
return false;
}
if (!isset($excludedUsers[$author])) {
return false;
}
$rule = $excludedUsers[$author];
if ($rule === 'all') {
return true;
}
if (is_array($rule)) {
return in_array($event->getType(), $rule, true);
}
return false;
}

/**
* Send an event into the activity stream
*
* @param IEvent $event
* @return int
*/
public function send(IEvent $event): int {
if ($event->getAffectedUser() === '') {
if (!$this->shouldSend($event)) {
return 0;
}

Expand Down Expand Up @@ -103,6 +141,10 @@
* @throws Exception
*/
public function bulkSend(IEvent $event, array $affectedUsers): array {
if ($this->isExcludedAuthor($event)) {
return [];
}

$this->connection->beginTransaction();

$activityIds = [];
Expand Down Expand Up @@ -169,8 +211,7 @@
* @return bool
*/
public function storeMail(IEvent $event, int $latestSendTime): bool {
$affectedUser = $event->getAffectedUser();
if ($affectedUser === '') {
if (!$this->shouldSend($event)) {
return false;
}

Expand All @@ -194,7 +235,7 @@
'amq_appid' => $event->getApp(),
'amq_subject' => $event->getSubject(),
'amq_subjectparams' => json_encode($event->getSubjectParameters()),
'amq_affecteduser' => $affectedUser,

Check failure on line 238 in lib/Data.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedVariable

lib/Data.php:238:26: UndefinedVariable: Cannot find referenced variable $affectedUser (see https://psalm.dev/024)
'amq_timestamp' => $event->getTimestamp(),
'amq_type' => $event->getType(),
'amq_latest_send' => $latestSendTime,
Expand Down
Loading