|
11 | 11 | use OCP\Activity\Exceptions\FilterNotFoundException; |
12 | 12 | use OCP\Activity\Exceptions\IncompleteActivityException; |
13 | 13 | use OCP\Activity\Exceptions\SettingNotFoundException; |
| 14 | +use OCP\Activity\IBulkConsumer; |
14 | 15 | use OCP\Activity\IConsumer; |
15 | 16 | use OCP\Activity\IEvent; |
16 | 17 | use OCP\Activity\IFilter; |
17 | 18 | use OCP\Activity\IManager; |
18 | 19 | use OCP\Activity\IProvider; |
19 | 20 | use OCP\Activity\ISetting; |
| 21 | +use OCP\AppFramework\Utility\ITimeFactory; |
20 | 22 | use OCP\IConfig; |
21 | 23 | use OCP\IL10N; |
22 | 24 | use OCP\IRequest; |
@@ -46,6 +48,7 @@ public function __construct( |
46 | 48 | protected IValidator $validator, |
47 | 49 | protected IRichTextFormatter $richTextFormatter, |
48 | 50 | protected IL10N $l10n, |
| 51 | + protected ITimeFactory $timeFactory, |
49 | 52 | ) { |
50 | 53 | } |
51 | 54 |
|
@@ -96,25 +99,57 @@ public function generateEvent(): IEvent { |
96 | 99 | * {@inheritDoc} |
97 | 100 | */ |
98 | 101 | public function publish(IEvent $event): void { |
| 102 | + if ($event->getAuthor() === '' && $this->session->getUser() instanceof IUser) { |
| 103 | + $event->setAuthor($this->session->getUser()->getUID()); |
| 104 | + } |
| 105 | + |
| 106 | + if (!$event->getTimestamp()) { |
| 107 | + $event->setTimestamp($this->timeFactory->getTime()); |
| 108 | + } |
| 109 | + |
| 110 | + if ($event->getAffectedUser() === '' || !$event->isValid()) { |
| 111 | + throw new IncompleteActivityException('The given event is invalid'); |
| 112 | + } |
| 113 | + |
| 114 | + foreach ($this->getConsumers() as $c) { |
| 115 | + $c->receive($event); |
| 116 | + } |
| 117 | + } |
| 118 | + |
| 119 | + /** |
| 120 | + * {@inheritDoc} |
| 121 | + */ |
| 122 | + public function bulkPublish(IEvent $event, array $affectedUserIds, ISetting $setting): void { |
| 123 | + if (empty($affectedUserIds)) { |
| 124 | + throw new IncompleteActivityException('The given event is invalid'); |
| 125 | + } |
| 126 | + |
99 | 127 | if ($event->getAuthor() === '') { |
100 | 128 | if ($this->session->getUser() instanceof IUser) { |
101 | 129 | $event->setAuthor($this->session->getUser()->getUID()); |
102 | 130 | } |
103 | 131 | } |
104 | 132 |
|
105 | 133 | if (!$event->getTimestamp()) { |
106 | | - $event->setTimestamp(time()); |
| 134 | + $event->setTimestamp($this->timeFactory->getTime()); |
107 | 135 | } |
108 | 136 |
|
109 | 137 | if (!$event->isValid()) { |
110 | 138 | throw new IncompleteActivityException('The given event is invalid'); |
111 | 139 | } |
112 | 140 |
|
113 | 141 | foreach ($this->getConsumers() as $c) { |
114 | | - $c->receive($event); |
| 142 | + if ($c instanceof IBulkConsumer) { |
| 143 | + $c->bulkReceive($event, $affectedUserIds, $setting); |
| 144 | + } |
| 145 | + foreach ($affectedUserIds as $affectedUserId) { |
| 146 | + $event->setAffectedUser($affectedUserId); |
| 147 | + $c->receive($event); |
| 148 | + } |
115 | 149 | } |
116 | 150 | } |
117 | 151 |
|
| 152 | + |
118 | 153 | /** |
119 | 154 | * In order to improve lazy loading a closure can be registered which will be called in case |
120 | 155 | * activity consumers are actually requested |
|
0 commit comments