@@ -38,14 +38,52 @@ public function __construct(
3838 ) {
3939 }
4040
41+ /**
42+ * Check if the event should be processed (not excluded and has valid target)
43+ *
44+ * @param IEvent $event
45+ * @return bool
46+ */
47+ private function shouldSend (IEvent $ event ): bool {
48+ return $ event ->getAffectedUser () !== '' && !$ this ->isExcludedAuthor ($ event );
49+ }
50+
51+ /**
52+ * Check if the event's author is excluded from activity logging
53+ *
54+ * @param IEvent $event
55+ * @return bool
56+ */
57+ private function isExcludedAuthor (IEvent $ event ): bool {
58+ $ excludedUsers = $ this ->config ->getSystemValue ('activity_log_exclude_users ' , []);
59+ if (empty ($ excludedUsers )) {
60+ return false ;
61+ }
62+ $ author = $ event ->getAuthor ();
63+ if ($ author === null || $ author === '' ) {
64+ return false ;
65+ }
66+ if (!isset ($ excludedUsers [$ author ])) {
67+ return false ;
68+ }
69+ $ rule = $ excludedUsers [$ author ];
70+ if ($ rule === 'all ' ) {
71+ return true ;
72+ }
73+ if (is_array ($ rule )) {
74+ return in_array ($ event ->getType (), $ rule , true );
75+ }
76+ return false ;
77+ }
78+
4179 /**
4280 * Send an event into the activity stream
4381 *
4482 * @param IEvent $event
4583 * @return int
4684 */
4785 public function send (IEvent $ event ): int {
48- if ($ event -> getAffectedUser () === '' ) {
86+ if (! $ this -> shouldSend ( $ event ) ) {
4987 return 0 ;
5088 }
5189
@@ -103,6 +141,10 @@ public function send(IEvent $event): int {
103141 * @throws Exception
104142 */
105143 public function bulkSend (IEvent $ event , array $ affectedUsers ): array {
144+ if ($ this ->isExcludedAuthor ($ event )) {
145+ return [];
146+ }
147+
106148 $ this ->connection ->beginTransaction ();
107149
108150 $ activityIds = [];
@@ -169,8 +211,7 @@ public function bulkSend(IEvent $event, array $affectedUsers): array {
169211 * @return bool
170212 */
171213 public function storeMail (IEvent $ event , int $ latestSendTime ): bool {
172- $ affectedUser = $ event ->getAffectedUser ();
173- if ($ affectedUser === '' ) {
214+ if (!$ this ->shouldSend ($ event )) {
174215 return false ;
175216 }
176217
0 commit comments