@@ -48,181 +48,181 @@ |
||
48 | 48 | */ |
49 | 49 | class App { |
50 | 50 | |
51 | - /** @var string[] */ |
|
52 | - private static $nameSpaceCache = []; |
|
53 | - |
|
54 | - /** |
|
55 | - * Turns an app id into a namespace by either reading the appinfo.xml's |
|
56 | - * namespace tag or uppercasing the appid's first letter |
|
57 | - * @param string $appId the app id |
|
58 | - * @param string $topNamespace the namespace which should be prepended to |
|
59 | - * the transformed app id, defaults to OCA\ |
|
60 | - * @return string the starting namespace for the app |
|
61 | - */ |
|
62 | - public static function buildAppNamespace(string $appId, string $topNamespace='OCA\\'): string { |
|
63 | - // Hit the cache! |
|
64 | - if (isset(self::$nameSpaceCache[$appId])) { |
|
65 | - return $topNamespace . self::$nameSpaceCache[$appId]; |
|
66 | - } |
|
67 | - |
|
68 | - $appInfo = \OC_App::getAppInfo($appId); |
|
69 | - if (isset($appInfo['namespace'])) { |
|
70 | - self::$nameSpaceCache[$appId] = trim($appInfo['namespace']); |
|
71 | - } else { |
|
72 | - if ($appId !== 'spreed') { |
|
73 | - // if the tag is not found, fall back to uppercasing the first letter |
|
74 | - self::$nameSpaceCache[$appId] = ucfirst($appId); |
|
75 | - } else { |
|
76 | - // For the Talk app (appid spreed) the above fallback doesn't work. |
|
77 | - // This leads to a problem when trying to install it freshly, |
|
78 | - // because the apps namespace is already registered before the |
|
79 | - // app is downloaded from the appstore, because of the hackish |
|
80 | - // global route index.php/call/{token} which is registered via |
|
81 | - // the core/routes.php so it does not have the app namespace. |
|
82 | - // @ref https://github.com/nextcloud/server/pull/19433 |
|
83 | - self::$nameSpaceCache[$appId] = 'Talk'; |
|
84 | - } |
|
85 | - } |
|
86 | - |
|
87 | - return $topNamespace . self::$nameSpaceCache[$appId]; |
|
88 | - } |
|
89 | - |
|
90 | - public static function getAppIdForClass(string $className, string $topNamespace='OCA\\'): ?string { |
|
91 | - if (strpos($className, $topNamespace) !== 0) { |
|
92 | - return null; |
|
93 | - } |
|
94 | - |
|
95 | - foreach (self::$nameSpaceCache as $appId => $namespace) { |
|
96 | - if (strpos($className, $topNamespace . $namespace . '\\') === 0) { |
|
97 | - return $appId; |
|
98 | - } |
|
99 | - } |
|
100 | - |
|
101 | - return null; |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * Shortcut for calling a controller method and printing the result |
|
107 | - * @param string $controllerName the name of the controller under which it is |
|
108 | - * stored in the DI container |
|
109 | - * @param string $methodName the method that you want to call |
|
110 | - * @param DIContainer $container an instance of a pimple container. |
|
111 | - * @param array $urlParams list of URL parameters (optional) |
|
112 | - * @throws HintException |
|
113 | - */ |
|
114 | - public static function main(string $controllerName, string $methodName, DIContainer $container, array $urlParams = null) { |
|
115 | - if (!is_null($urlParams)) { |
|
116 | - $container->query(IRequest::class)->setUrlParameters($urlParams); |
|
117 | - } elseif (isset($container['urlParams']) && !is_null($container['urlParams'])) { |
|
118 | - $container->query(IRequest::class)->setUrlParameters($container['urlParams']); |
|
119 | - } |
|
120 | - $appName = $container['AppName']; |
|
121 | - |
|
122 | - // first try $controllerName then go for \OCA\AppName\Controller\$controllerName |
|
123 | - try { |
|
124 | - $controller = $container->query($controllerName); |
|
125 | - } catch (QueryException $e) { |
|
126 | - if (strpos($controllerName, '\\Controller\\') !== false) { |
|
127 | - // This is from a global registered app route that is not enabled. |
|
128 | - [/*OC(A)*/, $app, /* Controller/Name*/] = explode('\\', $controllerName, 3); |
|
129 | - throw new HintException('App ' . strtolower($app) . ' is not enabled'); |
|
130 | - } |
|
131 | - |
|
132 | - if ($appName === 'core') { |
|
133 | - $appNameSpace = 'OC\\Core'; |
|
134 | - } else { |
|
135 | - $appNameSpace = self::buildAppNamespace($appName); |
|
136 | - } |
|
137 | - $controllerName = $appNameSpace . '\\Controller\\' . $controllerName; |
|
138 | - $controller = $container->query($controllerName); |
|
139 | - } |
|
140 | - |
|
141 | - // initialize the dispatcher and run all the middleware before the controller |
|
142 | - /** @var Dispatcher $dispatcher */ |
|
143 | - $dispatcher = $container['Dispatcher']; |
|
144 | - |
|
145 | - list( |
|
146 | - $httpHeaders, |
|
147 | - $responseHeaders, |
|
148 | - $responseCookies, |
|
149 | - $output, |
|
150 | - $response |
|
151 | - ) = $dispatcher->dispatch($controller, $methodName); |
|
152 | - |
|
153 | - $io = $container[IOutput::class]; |
|
154 | - |
|
155 | - if (!is_null($httpHeaders)) { |
|
156 | - $io->setHeader($httpHeaders); |
|
157 | - } |
|
158 | - |
|
159 | - foreach ($responseHeaders as $name => $value) { |
|
160 | - $io->setHeader($name . ': ' . $value); |
|
161 | - } |
|
162 | - |
|
163 | - foreach ($responseCookies as $name => $value) { |
|
164 | - $expireDate = null; |
|
165 | - if ($value['expireDate'] instanceof \DateTime) { |
|
166 | - $expireDate = $value['expireDate']->getTimestamp(); |
|
167 | - } |
|
168 | - $sameSite = $value['sameSite'] ?? 'Lax'; |
|
169 | - |
|
170 | - $io->setCookie( |
|
171 | - $name, |
|
172 | - $value['value'], |
|
173 | - $expireDate, |
|
174 | - $container->getServer()->getWebRoot(), |
|
175 | - null, |
|
176 | - $container->getServer()->getRequest()->getServerProtocol() === 'https', |
|
177 | - true, |
|
178 | - $sameSite |
|
179 | - ); |
|
180 | - } |
|
181 | - |
|
182 | - /* |
|
51 | + /** @var string[] */ |
|
52 | + private static $nameSpaceCache = []; |
|
53 | + |
|
54 | + /** |
|
55 | + * Turns an app id into a namespace by either reading the appinfo.xml's |
|
56 | + * namespace tag or uppercasing the appid's first letter |
|
57 | + * @param string $appId the app id |
|
58 | + * @param string $topNamespace the namespace which should be prepended to |
|
59 | + * the transformed app id, defaults to OCA\ |
|
60 | + * @return string the starting namespace for the app |
|
61 | + */ |
|
62 | + public static function buildAppNamespace(string $appId, string $topNamespace='OCA\\'): string { |
|
63 | + // Hit the cache! |
|
64 | + if (isset(self::$nameSpaceCache[$appId])) { |
|
65 | + return $topNamespace . self::$nameSpaceCache[$appId]; |
|
66 | + } |
|
67 | + |
|
68 | + $appInfo = \OC_App::getAppInfo($appId); |
|
69 | + if (isset($appInfo['namespace'])) { |
|
70 | + self::$nameSpaceCache[$appId] = trim($appInfo['namespace']); |
|
71 | + } else { |
|
72 | + if ($appId !== 'spreed') { |
|
73 | + // if the tag is not found, fall back to uppercasing the first letter |
|
74 | + self::$nameSpaceCache[$appId] = ucfirst($appId); |
|
75 | + } else { |
|
76 | + // For the Talk app (appid spreed) the above fallback doesn't work. |
|
77 | + // This leads to a problem when trying to install it freshly, |
|
78 | + // because the apps namespace is already registered before the |
|
79 | + // app is downloaded from the appstore, because of the hackish |
|
80 | + // global route index.php/call/{token} which is registered via |
|
81 | + // the core/routes.php so it does not have the app namespace. |
|
82 | + // @ref https://github.com/nextcloud/server/pull/19433 |
|
83 | + self::$nameSpaceCache[$appId] = 'Talk'; |
|
84 | + } |
|
85 | + } |
|
86 | + |
|
87 | + return $topNamespace . self::$nameSpaceCache[$appId]; |
|
88 | + } |
|
89 | + |
|
90 | + public static function getAppIdForClass(string $className, string $topNamespace='OCA\\'): ?string { |
|
91 | + if (strpos($className, $topNamespace) !== 0) { |
|
92 | + return null; |
|
93 | + } |
|
94 | + |
|
95 | + foreach (self::$nameSpaceCache as $appId => $namespace) { |
|
96 | + if (strpos($className, $topNamespace . $namespace . '\\') === 0) { |
|
97 | + return $appId; |
|
98 | + } |
|
99 | + } |
|
100 | + |
|
101 | + return null; |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * Shortcut for calling a controller method and printing the result |
|
107 | + * @param string $controllerName the name of the controller under which it is |
|
108 | + * stored in the DI container |
|
109 | + * @param string $methodName the method that you want to call |
|
110 | + * @param DIContainer $container an instance of a pimple container. |
|
111 | + * @param array $urlParams list of URL parameters (optional) |
|
112 | + * @throws HintException |
|
113 | + */ |
|
114 | + public static function main(string $controllerName, string $methodName, DIContainer $container, array $urlParams = null) { |
|
115 | + if (!is_null($urlParams)) { |
|
116 | + $container->query(IRequest::class)->setUrlParameters($urlParams); |
|
117 | + } elseif (isset($container['urlParams']) && !is_null($container['urlParams'])) { |
|
118 | + $container->query(IRequest::class)->setUrlParameters($container['urlParams']); |
|
119 | + } |
|
120 | + $appName = $container['AppName']; |
|
121 | + |
|
122 | + // first try $controllerName then go for \OCA\AppName\Controller\$controllerName |
|
123 | + try { |
|
124 | + $controller = $container->query($controllerName); |
|
125 | + } catch (QueryException $e) { |
|
126 | + if (strpos($controllerName, '\\Controller\\') !== false) { |
|
127 | + // This is from a global registered app route that is not enabled. |
|
128 | + [/*OC(A)*/, $app, /* Controller/Name*/] = explode('\\', $controllerName, 3); |
|
129 | + throw new HintException('App ' . strtolower($app) . ' is not enabled'); |
|
130 | + } |
|
131 | + |
|
132 | + if ($appName === 'core') { |
|
133 | + $appNameSpace = 'OC\\Core'; |
|
134 | + } else { |
|
135 | + $appNameSpace = self::buildAppNamespace($appName); |
|
136 | + } |
|
137 | + $controllerName = $appNameSpace . '\\Controller\\' . $controllerName; |
|
138 | + $controller = $container->query($controllerName); |
|
139 | + } |
|
140 | + |
|
141 | + // initialize the dispatcher and run all the middleware before the controller |
|
142 | + /** @var Dispatcher $dispatcher */ |
|
143 | + $dispatcher = $container['Dispatcher']; |
|
144 | + |
|
145 | + list( |
|
146 | + $httpHeaders, |
|
147 | + $responseHeaders, |
|
148 | + $responseCookies, |
|
149 | + $output, |
|
150 | + $response |
|
151 | + ) = $dispatcher->dispatch($controller, $methodName); |
|
152 | + |
|
153 | + $io = $container[IOutput::class]; |
|
154 | + |
|
155 | + if (!is_null($httpHeaders)) { |
|
156 | + $io->setHeader($httpHeaders); |
|
157 | + } |
|
158 | + |
|
159 | + foreach ($responseHeaders as $name => $value) { |
|
160 | + $io->setHeader($name . ': ' . $value); |
|
161 | + } |
|
162 | + |
|
163 | + foreach ($responseCookies as $name => $value) { |
|
164 | + $expireDate = null; |
|
165 | + if ($value['expireDate'] instanceof \DateTime) { |
|
166 | + $expireDate = $value['expireDate']->getTimestamp(); |
|
167 | + } |
|
168 | + $sameSite = $value['sameSite'] ?? 'Lax'; |
|
169 | + |
|
170 | + $io->setCookie( |
|
171 | + $name, |
|
172 | + $value['value'], |
|
173 | + $expireDate, |
|
174 | + $container->getServer()->getWebRoot(), |
|
175 | + null, |
|
176 | + $container->getServer()->getRequest()->getServerProtocol() === 'https', |
|
177 | + true, |
|
178 | + $sameSite |
|
179 | + ); |
|
180 | + } |
|
181 | + |
|
182 | + /* |
|
183 | 183 | * Status 204 does not have a body and no Content Length |
184 | 184 | * Status 304 does not have a body and does not need a Content Length |
185 | 185 | * https://tools.ietf.org/html/rfc7230#section-3.3 |
186 | 186 | * https://tools.ietf.org/html/rfc7230#section-3.3.2 |
187 | 187 | */ |
188 | - $emptyResponse = false; |
|
189 | - if (preg_match('/^HTTP\/\d\.\d (\d{3}) .*$/', $httpHeaders, $matches)) { |
|
190 | - $status = (int)$matches[1]; |
|
191 | - if ($status === Http::STATUS_NO_CONTENT || $status === Http::STATUS_NOT_MODIFIED) { |
|
192 | - $emptyResponse = true; |
|
193 | - } |
|
194 | - } |
|
195 | - |
|
196 | - if (!$emptyResponse) { |
|
197 | - if ($response instanceof ICallbackResponse) { |
|
198 | - $response->callback($io); |
|
199 | - } elseif (!is_null($output)) { |
|
200 | - $io->setHeader('Content-Length: ' . strlen($output)); |
|
201 | - $io->setOutput($output); |
|
202 | - } |
|
203 | - } |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * Shortcut for calling a controller method and printing the result. |
|
208 | - * Similar to App:main except that no headers will be sent. |
|
209 | - * This should be used for example when registering sections via |
|
210 | - * \OC\AppFramework\Core\API::registerAdmin() |
|
211 | - * |
|
212 | - * @param string $controllerName the name of the controller under which it is |
|
213 | - * stored in the DI container |
|
214 | - * @param string $methodName the method that you want to call |
|
215 | - * @param array $urlParams an array with variables extracted from the routes |
|
216 | - * @param DIContainer $container an instance of a pimple container. |
|
217 | - */ |
|
218 | - public static function part(string $controllerName, string $methodName, array $urlParams, |
|
219 | - DIContainer $container) { |
|
220 | - $container['urlParams'] = $urlParams; |
|
221 | - $controller = $container[$controllerName]; |
|
222 | - |
|
223 | - $dispatcher = $container['Dispatcher']; |
|
224 | - |
|
225 | - list(, , $output) = $dispatcher->dispatch($controller, $methodName); |
|
226 | - return $output; |
|
227 | - } |
|
188 | + $emptyResponse = false; |
|
189 | + if (preg_match('/^HTTP\/\d\.\d (\d{3}) .*$/', $httpHeaders, $matches)) { |
|
190 | + $status = (int)$matches[1]; |
|
191 | + if ($status === Http::STATUS_NO_CONTENT || $status === Http::STATUS_NOT_MODIFIED) { |
|
192 | + $emptyResponse = true; |
|
193 | + } |
|
194 | + } |
|
195 | + |
|
196 | + if (!$emptyResponse) { |
|
197 | + if ($response instanceof ICallbackResponse) { |
|
198 | + $response->callback($io); |
|
199 | + } elseif (!is_null($output)) { |
|
200 | + $io->setHeader('Content-Length: ' . strlen($output)); |
|
201 | + $io->setOutput($output); |
|
202 | + } |
|
203 | + } |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * Shortcut for calling a controller method and printing the result. |
|
208 | + * Similar to App:main except that no headers will be sent. |
|
209 | + * This should be used for example when registering sections via |
|
210 | + * \OC\AppFramework\Core\API::registerAdmin() |
|
211 | + * |
|
212 | + * @param string $controllerName the name of the controller under which it is |
|
213 | + * stored in the DI container |
|
214 | + * @param string $methodName the method that you want to call |
|
215 | + * @param array $urlParams an array with variables extracted from the routes |
|
216 | + * @param DIContainer $container an instance of a pimple container. |
|
217 | + */ |
|
218 | + public static function part(string $controllerName, string $methodName, array $urlParams, |
|
219 | + DIContainer $container) { |
|
220 | + $container['urlParams'] = $urlParams; |
|
221 | + $controller = $container[$controllerName]; |
|
222 | + |
|
223 | + $dispatcher = $container['Dispatcher']; |
|
224 | + |
|
225 | + list(, , $output) = $dispatcher->dispatch($controller, $methodName); |
|
226 | + return $output; |
|
227 | + } |
|
228 | 228 | } |
@@ -59,10 +59,10 @@ discard block |
||
59 | 59 | * the transformed app id, defaults to OCA\ |
60 | 60 | * @return string the starting namespace for the app |
61 | 61 | */ |
62 | - public static function buildAppNamespace(string $appId, string $topNamespace='OCA\\'): string { |
|
62 | + public static function buildAppNamespace(string $appId, string $topNamespace = 'OCA\\'): string { |
|
63 | 63 | // Hit the cache! |
64 | 64 | if (isset(self::$nameSpaceCache[$appId])) { |
65 | - return $topNamespace . self::$nameSpaceCache[$appId]; |
|
65 | + return $topNamespace.self::$nameSpaceCache[$appId]; |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | $appInfo = \OC_App::getAppInfo($appId); |
@@ -84,16 +84,16 @@ discard block |
||
84 | 84 | } |
85 | 85 | } |
86 | 86 | |
87 | - return $topNamespace . self::$nameSpaceCache[$appId]; |
|
87 | + return $topNamespace.self::$nameSpaceCache[$appId]; |
|
88 | 88 | } |
89 | 89 | |
90 | - public static function getAppIdForClass(string $className, string $topNamespace='OCA\\'): ?string { |
|
90 | + public static function getAppIdForClass(string $className, string $topNamespace = 'OCA\\'): ?string { |
|
91 | 91 | if (strpos($className, $topNamespace) !== 0) { |
92 | 92 | return null; |
93 | 93 | } |
94 | 94 | |
95 | 95 | foreach (self::$nameSpaceCache as $appId => $namespace) { |
96 | - if (strpos($className, $topNamespace . $namespace . '\\') === 0) { |
|
96 | + if (strpos($className, $topNamespace.$namespace.'\\') === 0) { |
|
97 | 97 | return $appId; |
98 | 98 | } |
99 | 99 | } |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | if (strpos($controllerName, '\\Controller\\') !== false) { |
127 | 127 | // This is from a global registered app route that is not enabled. |
128 | 128 | [/*OC(A)*/, $app, /* Controller/Name*/] = explode('\\', $controllerName, 3); |
129 | - throw new HintException('App ' . strtolower($app) . ' is not enabled'); |
|
129 | + throw new HintException('App '.strtolower($app).' is not enabled'); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | if ($appName === 'core') { |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | } else { |
135 | 135 | $appNameSpace = self::buildAppNamespace($appName); |
136 | 136 | } |
137 | - $controllerName = $appNameSpace . '\\Controller\\' . $controllerName; |
|
137 | + $controllerName = $appNameSpace.'\\Controller\\'.$controllerName; |
|
138 | 138 | $controller = $container->query($controllerName); |
139 | 139 | } |
140 | 140 | |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | } |
158 | 158 | |
159 | 159 | foreach ($responseHeaders as $name => $value) { |
160 | - $io->setHeader($name . ': ' . $value); |
|
160 | + $io->setHeader($name.': '.$value); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | foreach ($responseCookies as $name => $value) { |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | */ |
188 | 188 | $emptyResponse = false; |
189 | 189 | if (preg_match('/^HTTP\/\d\.\d (\d{3}) .*$/', $httpHeaders, $matches)) { |
190 | - $status = (int)$matches[1]; |
|
190 | + $status = (int) $matches[1]; |
|
191 | 191 | if ($status === Http::STATUS_NO_CONTENT || $status === Http::STATUS_NOT_MODIFIED) { |
192 | 192 | $emptyResponse = true; |
193 | 193 | } |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | if ($response instanceof ICallbackResponse) { |
198 | 198 | $response->callback($io); |
199 | 199 | } elseif (!is_null($output)) { |
200 | - $io->setHeader('Content-Length: ' . strlen($output)); |
|
200 | + $io->setHeader('Content-Length: '.strlen($output)); |
|
201 | 201 | $io->setOutput($output); |
202 | 202 | } |
203 | 203 | } |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | |
223 | 223 | $dispatcher = $container['Dispatcher']; |
224 | 224 | |
225 | - list(, , $output) = $dispatcher->dispatch($controller, $methodName); |
|
225 | + list(,, $output) = $dispatcher->dispatch($controller, $methodName); |
|
226 | 226 | return $output; |
227 | 227 | } |
228 | 228 | } |
@@ -34,513 +34,513 @@ |
||
34 | 34 | |
35 | 35 | class Event implements IEvent { |
36 | 36 | |
37 | - /** @var string */ |
|
38 | - protected $app = ''; |
|
39 | - /** @var string */ |
|
40 | - protected $type = ''; |
|
41 | - /** @var string */ |
|
42 | - protected $affectedUser = ''; |
|
43 | - /** @var string */ |
|
44 | - protected $author = ''; |
|
45 | - /** @var int */ |
|
46 | - protected $timestamp = 0; |
|
47 | - /** @var string */ |
|
48 | - protected $subject = ''; |
|
49 | - /** @var array */ |
|
50 | - protected $subjectParameters = []; |
|
51 | - /** @var string */ |
|
52 | - protected $subjectParsed = ''; |
|
53 | - /** @var string */ |
|
54 | - protected $subjectRich = ''; |
|
55 | - /** @var array */ |
|
56 | - protected $subjectRichParameters = []; |
|
57 | - /** @var string */ |
|
58 | - protected $message = ''; |
|
59 | - /** @var array */ |
|
60 | - protected $messageParameters = []; |
|
61 | - /** @var string */ |
|
62 | - protected $messageParsed = ''; |
|
63 | - /** @var string */ |
|
64 | - protected $messageRich = ''; |
|
65 | - /** @var array */ |
|
66 | - protected $messageRichParameters = []; |
|
67 | - /** @var string */ |
|
68 | - protected $objectType = ''; |
|
69 | - /** @var int */ |
|
70 | - protected $objectId = 0; |
|
71 | - /** @var string */ |
|
72 | - protected $objectName = ''; |
|
73 | - /** @var string */ |
|
74 | - protected $link = ''; |
|
75 | - /** @var string */ |
|
76 | - protected $icon = ''; |
|
77 | - /** @var bool */ |
|
78 | - protected $generateNotification = true; |
|
79 | - |
|
80 | - /** @var IEvent|null */ |
|
81 | - protected $child; |
|
82 | - /** @var IValidator */ |
|
83 | - protected $richValidator; |
|
84 | - |
|
85 | - /** |
|
86 | - * @param IValidator $richValidator |
|
87 | - */ |
|
88 | - public function __construct(IValidator $richValidator) { |
|
89 | - $this->richValidator = $richValidator; |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Set the app of the activity |
|
94 | - * |
|
95 | - * @param string $app |
|
96 | - * @return IEvent |
|
97 | - * @throws \InvalidArgumentException if the app id is invalid |
|
98 | - * @since 8.2.0 |
|
99 | - */ |
|
100 | - public function setApp(string $app): IEvent { |
|
101 | - if ($app === '' || isset($app[32])) { |
|
102 | - throw new \InvalidArgumentException('The given app is invalid'); |
|
103 | - } |
|
104 | - $this->app = $app; |
|
105 | - return $this; |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * @return string |
|
110 | - */ |
|
111 | - public function getApp(): string { |
|
112 | - return $this->app; |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * Set the type of the activity |
|
117 | - * |
|
118 | - * @param string $type |
|
119 | - * @return IEvent |
|
120 | - * @throws \InvalidArgumentException if the type is invalid |
|
121 | - * @since 8.2.0 |
|
122 | - */ |
|
123 | - public function setType(string $type): IEvent { |
|
124 | - if ($type === '' || isset($type[255])) { |
|
125 | - throw new \InvalidArgumentException('The given type is invalid'); |
|
126 | - } |
|
127 | - $this->type = $type; |
|
128 | - return $this; |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * @return string |
|
133 | - */ |
|
134 | - public function getType(): string { |
|
135 | - return $this->type; |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * Set the affected user of the activity |
|
140 | - * |
|
141 | - * @param string $affectedUser |
|
142 | - * @return IEvent |
|
143 | - * @throws \InvalidArgumentException if the affected user is invalid |
|
144 | - * @since 8.2.0 |
|
145 | - */ |
|
146 | - public function setAffectedUser(string $affectedUser): IEvent { |
|
147 | - if ($affectedUser === '' || isset($affectedUser[64])) { |
|
148 | - throw new \InvalidArgumentException('The given affected user is invalid'); |
|
149 | - } |
|
150 | - $this->affectedUser = $affectedUser; |
|
151 | - return $this; |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * @return string |
|
156 | - */ |
|
157 | - public function getAffectedUser(): string { |
|
158 | - return $this->affectedUser; |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * Set the author of the activity |
|
163 | - * |
|
164 | - * @param string $author |
|
165 | - * @return IEvent |
|
166 | - * @throws \InvalidArgumentException if the author is invalid |
|
167 | - * @since 8.2.0 |
|
168 | - */ |
|
169 | - public function setAuthor(string $author): IEvent { |
|
170 | - if (isset($author[64])) { |
|
171 | - throw new \InvalidArgumentException('The given author user is invalid'); |
|
172 | - } |
|
173 | - $this->author = $author; |
|
174 | - return $this; |
|
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * @return string |
|
179 | - */ |
|
180 | - public function getAuthor(): string { |
|
181 | - return $this->author; |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * Set the timestamp of the activity |
|
186 | - * |
|
187 | - * @param int $timestamp |
|
188 | - * @return IEvent |
|
189 | - * @throws \InvalidArgumentException if the timestamp is invalid |
|
190 | - * @since 8.2.0 |
|
191 | - */ |
|
192 | - public function setTimestamp(int $timestamp): IEvent { |
|
193 | - $this->timestamp = $timestamp; |
|
194 | - return $this; |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * @return int |
|
199 | - */ |
|
200 | - public function getTimestamp(): int { |
|
201 | - return $this->timestamp; |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Set the subject of the activity |
|
206 | - * |
|
207 | - * @param string $subject |
|
208 | - * @param array $parameters |
|
209 | - * @return IEvent |
|
210 | - * @throws \InvalidArgumentException if the subject or parameters are invalid |
|
211 | - * @since 8.2.0 |
|
212 | - */ |
|
213 | - public function setSubject(string $subject, array $parameters = []): IEvent { |
|
214 | - if (isset($subject[255])) { |
|
215 | - throw new \InvalidArgumentException('The given subject is invalid'); |
|
216 | - } |
|
217 | - $this->subject = $subject; |
|
218 | - $this->subjectParameters = $parameters; |
|
219 | - return $this; |
|
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * @return string |
|
224 | - */ |
|
225 | - public function getSubject(): string { |
|
226 | - return $this->subject; |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * @return array |
|
231 | - */ |
|
232 | - public function getSubjectParameters(): array { |
|
233 | - return $this->subjectParameters; |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * @param string $subject |
|
238 | - * @return $this |
|
239 | - * @throws \InvalidArgumentException if the subject is invalid |
|
240 | - * @since 11.0.0 |
|
241 | - */ |
|
242 | - public function setParsedSubject(string $subject): IEvent { |
|
243 | - if ($subject === '') { |
|
244 | - throw new \InvalidArgumentException('The given parsed subject is invalid'); |
|
245 | - } |
|
246 | - $this->subjectParsed = $subject; |
|
247 | - return $this; |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * @return string |
|
252 | - * @since 11.0.0 |
|
253 | - */ |
|
254 | - public function getParsedSubject(): string { |
|
255 | - return $this->subjectParsed; |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * @param string $subject |
|
260 | - * @param array $parameters |
|
261 | - * @return $this |
|
262 | - * @throws \InvalidArgumentException if the subject or parameters are invalid |
|
263 | - * @since 11.0.0 |
|
264 | - */ |
|
265 | - public function setRichSubject(string $subject, array $parameters = []): IEvent { |
|
266 | - if ($subject === '') { |
|
267 | - throw new \InvalidArgumentException('The given parsed subject is invalid'); |
|
268 | - } |
|
269 | - $this->subjectRich = $subject; |
|
270 | - $this->subjectRichParameters = $parameters; |
|
271 | - |
|
272 | - return $this; |
|
273 | - } |
|
274 | - |
|
275 | - /** |
|
276 | - * @return string |
|
277 | - * @since 11.0.0 |
|
278 | - */ |
|
279 | - public function getRichSubject(): string { |
|
280 | - return $this->subjectRich; |
|
281 | - } |
|
282 | - |
|
283 | - /** |
|
284 | - * @return array[] |
|
285 | - * @since 11.0.0 |
|
286 | - */ |
|
287 | - public function getRichSubjectParameters(): array { |
|
288 | - return $this->subjectRichParameters; |
|
289 | - } |
|
290 | - |
|
291 | - /** |
|
292 | - * Set the message of the activity |
|
293 | - * |
|
294 | - * @param string $message |
|
295 | - * @param array $parameters |
|
296 | - * @return IEvent |
|
297 | - * @throws \InvalidArgumentException if the message or parameters are invalid |
|
298 | - * @since 8.2.0 |
|
299 | - */ |
|
300 | - public function setMessage(string $message, array $parameters = []): IEvent { |
|
301 | - if (isset($message[255])) { |
|
302 | - throw new \InvalidArgumentException('The given message is invalid'); |
|
303 | - } |
|
304 | - $this->message = $message; |
|
305 | - $this->messageParameters = $parameters; |
|
306 | - return $this; |
|
307 | - } |
|
308 | - |
|
309 | - /** |
|
310 | - * @return string |
|
311 | - */ |
|
312 | - public function getMessage(): string { |
|
313 | - return $this->message; |
|
314 | - } |
|
315 | - |
|
316 | - /** |
|
317 | - * @return array |
|
318 | - */ |
|
319 | - public function getMessageParameters(): array { |
|
320 | - return $this->messageParameters; |
|
321 | - } |
|
322 | - |
|
323 | - /** |
|
324 | - * @param string $message |
|
325 | - * @return $this |
|
326 | - * @throws \InvalidArgumentException if the message is invalid |
|
327 | - * @since 11.0.0 |
|
328 | - */ |
|
329 | - public function setParsedMessage(string $message): IEvent { |
|
330 | - $this->messageParsed = $message; |
|
331 | - return $this; |
|
332 | - } |
|
333 | - |
|
334 | - /** |
|
335 | - * @return string |
|
336 | - * @since 11.0.0 |
|
337 | - */ |
|
338 | - public function getParsedMessage(): string { |
|
339 | - return $this->messageParsed; |
|
340 | - } |
|
341 | - |
|
342 | - /** |
|
343 | - * @param string $message |
|
344 | - * @param array $parameters |
|
345 | - * @return $this |
|
346 | - * @throws \InvalidArgumentException if the subject or parameters are invalid |
|
347 | - * @since 11.0.0 |
|
348 | - */ |
|
349 | - public function setRichMessage(string $message, array $parameters = []): IEvent { |
|
350 | - $this->messageRich = $message; |
|
351 | - $this->messageRichParameters = $parameters; |
|
352 | - |
|
353 | - return $this; |
|
354 | - } |
|
355 | - |
|
356 | - /** |
|
357 | - * @return string |
|
358 | - * @since 11.0.0 |
|
359 | - */ |
|
360 | - public function getRichMessage(): string { |
|
361 | - return $this->messageRich; |
|
362 | - } |
|
363 | - |
|
364 | - /** |
|
365 | - * @return array[] |
|
366 | - * @since 11.0.0 |
|
367 | - */ |
|
368 | - public function getRichMessageParameters(): array { |
|
369 | - return $this->messageRichParameters; |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * Set the object of the activity |
|
374 | - * |
|
375 | - * @param string $objectType |
|
376 | - * @param int $objectId |
|
377 | - * @param string $objectName |
|
378 | - * @return IEvent |
|
379 | - * @throws \InvalidArgumentException if the object is invalid |
|
380 | - * @since 8.2.0 |
|
381 | - */ |
|
382 | - public function setObject(string $objectType, int $objectId, string $objectName = ''): IEvent { |
|
383 | - if (isset($objectType[255])) { |
|
384 | - throw new \InvalidArgumentException('The given object type is invalid'); |
|
385 | - } |
|
386 | - if (isset($objectName[4000])) { |
|
387 | - throw new \InvalidArgumentException('The given object name is invalid'); |
|
388 | - } |
|
389 | - $this->objectType = $objectType; |
|
390 | - $this->objectId = $objectId; |
|
391 | - $this->objectName = $objectName; |
|
392 | - return $this; |
|
393 | - } |
|
394 | - |
|
395 | - /** |
|
396 | - * @return string |
|
397 | - */ |
|
398 | - public function getObjectType(): string { |
|
399 | - return $this->objectType; |
|
400 | - } |
|
401 | - |
|
402 | - /** |
|
403 | - * @return int |
|
404 | - */ |
|
405 | - public function getObjectId(): int { |
|
406 | - return $this->objectId; |
|
407 | - } |
|
408 | - |
|
409 | - /** |
|
410 | - * @return string |
|
411 | - */ |
|
412 | - public function getObjectName(): string { |
|
413 | - return $this->objectName; |
|
414 | - } |
|
415 | - |
|
416 | - /** |
|
417 | - * Set the link of the activity |
|
418 | - * |
|
419 | - * @param string $link |
|
420 | - * @return IEvent |
|
421 | - * @throws \InvalidArgumentException if the link is invalid |
|
422 | - * @since 8.2.0 |
|
423 | - */ |
|
424 | - public function setLink(string $link): IEvent { |
|
425 | - if (isset($link[4000])) { |
|
426 | - throw new \InvalidArgumentException('The given link is invalid'); |
|
427 | - } |
|
428 | - $this->link = $link; |
|
429 | - return $this; |
|
430 | - } |
|
431 | - |
|
432 | - /** |
|
433 | - * @return string |
|
434 | - */ |
|
435 | - public function getLink(): string { |
|
436 | - return $this->link; |
|
437 | - } |
|
438 | - |
|
439 | - /** |
|
440 | - * @param string $icon |
|
441 | - * @return $this |
|
442 | - * @throws \InvalidArgumentException if the icon is invalid |
|
443 | - * @since 11.0.0 |
|
444 | - */ |
|
445 | - public function setIcon(string $icon): IEvent { |
|
446 | - if (isset($icon[4000])) { |
|
447 | - throw new \InvalidArgumentException('The given icon is invalid'); |
|
448 | - } |
|
449 | - $this->icon = $icon; |
|
450 | - return $this; |
|
451 | - } |
|
452 | - |
|
453 | - /** |
|
454 | - * @return string |
|
455 | - * @since 11.0.0 |
|
456 | - */ |
|
457 | - public function getIcon(): string { |
|
458 | - return $this->icon; |
|
459 | - } |
|
460 | - |
|
461 | - /** |
|
462 | - * @param IEvent $child |
|
463 | - * @return $this |
|
464 | - * @since 11.0.0 - Since 15.0.0 returns $this |
|
465 | - */ |
|
466 | - public function setChildEvent(IEvent $child): IEvent { |
|
467 | - $this->child = $child; |
|
468 | - return $this; |
|
469 | - } |
|
470 | - |
|
471 | - /** |
|
472 | - * @return IEvent|null |
|
473 | - * @since 11.0.0 |
|
474 | - */ |
|
475 | - public function getChildEvent() { |
|
476 | - return $this->child; |
|
477 | - } |
|
478 | - |
|
479 | - /** |
|
480 | - * @return bool |
|
481 | - * @since 8.2.0 |
|
482 | - */ |
|
483 | - public function isValid(): bool { |
|
484 | - return |
|
485 | - $this->isValidCommon() |
|
486 | - && |
|
487 | - $this->getSubject() !== '' |
|
488 | - ; |
|
489 | - } |
|
490 | - |
|
491 | - /** |
|
492 | - * @return bool |
|
493 | - * @since 8.2.0 |
|
494 | - */ |
|
495 | - public function isValidParsed(): bool { |
|
496 | - if ($this->getRichSubject() !== '' || !empty($this->getRichSubjectParameters())) { |
|
497 | - try { |
|
498 | - $this->richValidator->validate($this->getRichSubject(), $this->getRichSubjectParameters()); |
|
499 | - } catch (InvalidObjectExeption $e) { |
|
500 | - return false; |
|
501 | - } |
|
502 | - } |
|
503 | - |
|
504 | - if ($this->getRichMessage() !== '' || !empty($this->getRichMessageParameters())) { |
|
505 | - try { |
|
506 | - $this->richValidator->validate($this->getRichMessage(), $this->getRichMessageParameters()); |
|
507 | - } catch (InvalidObjectExeption $e) { |
|
508 | - return false; |
|
509 | - } |
|
510 | - } |
|
511 | - |
|
512 | - return |
|
513 | - $this->isValidCommon() |
|
514 | - && |
|
515 | - $this->getParsedSubject() !== '' |
|
516 | - ; |
|
517 | - } |
|
518 | - |
|
519 | - protected function isValidCommon(): bool { |
|
520 | - return |
|
521 | - $this->getApp() !== '' |
|
522 | - && |
|
523 | - $this->getType() !== '' |
|
524 | - && |
|
525 | - $this->getAffectedUser() !== '' |
|
526 | - && |
|
527 | - $this->getTimestamp() !== 0 |
|
528 | - /** |
|
529 | - * Disabled for BC with old activities |
|
530 | - * && |
|
531 | - * $this->getObjectType() !== '' |
|
532 | - * && |
|
533 | - * $this->getObjectId() !== 0 |
|
534 | - */ |
|
535 | - ; |
|
536 | - } |
|
537 | - |
|
538 | - public function setGenerateNotification(bool $generate): IEvent { |
|
539 | - $this->generateNotification = $generate; |
|
540 | - return $this; |
|
541 | - } |
|
542 | - |
|
543 | - public function getGenerateNotification(): bool { |
|
544 | - return $this->generateNotification; |
|
545 | - } |
|
37 | + /** @var string */ |
|
38 | + protected $app = ''; |
|
39 | + /** @var string */ |
|
40 | + protected $type = ''; |
|
41 | + /** @var string */ |
|
42 | + protected $affectedUser = ''; |
|
43 | + /** @var string */ |
|
44 | + protected $author = ''; |
|
45 | + /** @var int */ |
|
46 | + protected $timestamp = 0; |
|
47 | + /** @var string */ |
|
48 | + protected $subject = ''; |
|
49 | + /** @var array */ |
|
50 | + protected $subjectParameters = []; |
|
51 | + /** @var string */ |
|
52 | + protected $subjectParsed = ''; |
|
53 | + /** @var string */ |
|
54 | + protected $subjectRich = ''; |
|
55 | + /** @var array */ |
|
56 | + protected $subjectRichParameters = []; |
|
57 | + /** @var string */ |
|
58 | + protected $message = ''; |
|
59 | + /** @var array */ |
|
60 | + protected $messageParameters = []; |
|
61 | + /** @var string */ |
|
62 | + protected $messageParsed = ''; |
|
63 | + /** @var string */ |
|
64 | + protected $messageRich = ''; |
|
65 | + /** @var array */ |
|
66 | + protected $messageRichParameters = []; |
|
67 | + /** @var string */ |
|
68 | + protected $objectType = ''; |
|
69 | + /** @var int */ |
|
70 | + protected $objectId = 0; |
|
71 | + /** @var string */ |
|
72 | + protected $objectName = ''; |
|
73 | + /** @var string */ |
|
74 | + protected $link = ''; |
|
75 | + /** @var string */ |
|
76 | + protected $icon = ''; |
|
77 | + /** @var bool */ |
|
78 | + protected $generateNotification = true; |
|
79 | + |
|
80 | + /** @var IEvent|null */ |
|
81 | + protected $child; |
|
82 | + /** @var IValidator */ |
|
83 | + protected $richValidator; |
|
84 | + |
|
85 | + /** |
|
86 | + * @param IValidator $richValidator |
|
87 | + */ |
|
88 | + public function __construct(IValidator $richValidator) { |
|
89 | + $this->richValidator = $richValidator; |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Set the app of the activity |
|
94 | + * |
|
95 | + * @param string $app |
|
96 | + * @return IEvent |
|
97 | + * @throws \InvalidArgumentException if the app id is invalid |
|
98 | + * @since 8.2.0 |
|
99 | + */ |
|
100 | + public function setApp(string $app): IEvent { |
|
101 | + if ($app === '' || isset($app[32])) { |
|
102 | + throw new \InvalidArgumentException('The given app is invalid'); |
|
103 | + } |
|
104 | + $this->app = $app; |
|
105 | + return $this; |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * @return string |
|
110 | + */ |
|
111 | + public function getApp(): string { |
|
112 | + return $this->app; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * Set the type of the activity |
|
117 | + * |
|
118 | + * @param string $type |
|
119 | + * @return IEvent |
|
120 | + * @throws \InvalidArgumentException if the type is invalid |
|
121 | + * @since 8.2.0 |
|
122 | + */ |
|
123 | + public function setType(string $type): IEvent { |
|
124 | + if ($type === '' || isset($type[255])) { |
|
125 | + throw new \InvalidArgumentException('The given type is invalid'); |
|
126 | + } |
|
127 | + $this->type = $type; |
|
128 | + return $this; |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * @return string |
|
133 | + */ |
|
134 | + public function getType(): string { |
|
135 | + return $this->type; |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * Set the affected user of the activity |
|
140 | + * |
|
141 | + * @param string $affectedUser |
|
142 | + * @return IEvent |
|
143 | + * @throws \InvalidArgumentException if the affected user is invalid |
|
144 | + * @since 8.2.0 |
|
145 | + */ |
|
146 | + public function setAffectedUser(string $affectedUser): IEvent { |
|
147 | + if ($affectedUser === '' || isset($affectedUser[64])) { |
|
148 | + throw new \InvalidArgumentException('The given affected user is invalid'); |
|
149 | + } |
|
150 | + $this->affectedUser = $affectedUser; |
|
151 | + return $this; |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * @return string |
|
156 | + */ |
|
157 | + public function getAffectedUser(): string { |
|
158 | + return $this->affectedUser; |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * Set the author of the activity |
|
163 | + * |
|
164 | + * @param string $author |
|
165 | + * @return IEvent |
|
166 | + * @throws \InvalidArgumentException if the author is invalid |
|
167 | + * @since 8.2.0 |
|
168 | + */ |
|
169 | + public function setAuthor(string $author): IEvent { |
|
170 | + if (isset($author[64])) { |
|
171 | + throw new \InvalidArgumentException('The given author user is invalid'); |
|
172 | + } |
|
173 | + $this->author = $author; |
|
174 | + return $this; |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * @return string |
|
179 | + */ |
|
180 | + public function getAuthor(): string { |
|
181 | + return $this->author; |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * Set the timestamp of the activity |
|
186 | + * |
|
187 | + * @param int $timestamp |
|
188 | + * @return IEvent |
|
189 | + * @throws \InvalidArgumentException if the timestamp is invalid |
|
190 | + * @since 8.2.0 |
|
191 | + */ |
|
192 | + public function setTimestamp(int $timestamp): IEvent { |
|
193 | + $this->timestamp = $timestamp; |
|
194 | + return $this; |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * @return int |
|
199 | + */ |
|
200 | + public function getTimestamp(): int { |
|
201 | + return $this->timestamp; |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Set the subject of the activity |
|
206 | + * |
|
207 | + * @param string $subject |
|
208 | + * @param array $parameters |
|
209 | + * @return IEvent |
|
210 | + * @throws \InvalidArgumentException if the subject or parameters are invalid |
|
211 | + * @since 8.2.0 |
|
212 | + */ |
|
213 | + public function setSubject(string $subject, array $parameters = []): IEvent { |
|
214 | + if (isset($subject[255])) { |
|
215 | + throw new \InvalidArgumentException('The given subject is invalid'); |
|
216 | + } |
|
217 | + $this->subject = $subject; |
|
218 | + $this->subjectParameters = $parameters; |
|
219 | + return $this; |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * @return string |
|
224 | + */ |
|
225 | + public function getSubject(): string { |
|
226 | + return $this->subject; |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * @return array |
|
231 | + */ |
|
232 | + public function getSubjectParameters(): array { |
|
233 | + return $this->subjectParameters; |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * @param string $subject |
|
238 | + * @return $this |
|
239 | + * @throws \InvalidArgumentException if the subject is invalid |
|
240 | + * @since 11.0.0 |
|
241 | + */ |
|
242 | + public function setParsedSubject(string $subject): IEvent { |
|
243 | + if ($subject === '') { |
|
244 | + throw new \InvalidArgumentException('The given parsed subject is invalid'); |
|
245 | + } |
|
246 | + $this->subjectParsed = $subject; |
|
247 | + return $this; |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * @return string |
|
252 | + * @since 11.0.0 |
|
253 | + */ |
|
254 | + public function getParsedSubject(): string { |
|
255 | + return $this->subjectParsed; |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * @param string $subject |
|
260 | + * @param array $parameters |
|
261 | + * @return $this |
|
262 | + * @throws \InvalidArgumentException if the subject or parameters are invalid |
|
263 | + * @since 11.0.0 |
|
264 | + */ |
|
265 | + public function setRichSubject(string $subject, array $parameters = []): IEvent { |
|
266 | + if ($subject === '') { |
|
267 | + throw new \InvalidArgumentException('The given parsed subject is invalid'); |
|
268 | + } |
|
269 | + $this->subjectRich = $subject; |
|
270 | + $this->subjectRichParameters = $parameters; |
|
271 | + |
|
272 | + return $this; |
|
273 | + } |
|
274 | + |
|
275 | + /** |
|
276 | + * @return string |
|
277 | + * @since 11.0.0 |
|
278 | + */ |
|
279 | + public function getRichSubject(): string { |
|
280 | + return $this->subjectRich; |
|
281 | + } |
|
282 | + |
|
283 | + /** |
|
284 | + * @return array[] |
|
285 | + * @since 11.0.0 |
|
286 | + */ |
|
287 | + public function getRichSubjectParameters(): array { |
|
288 | + return $this->subjectRichParameters; |
|
289 | + } |
|
290 | + |
|
291 | + /** |
|
292 | + * Set the message of the activity |
|
293 | + * |
|
294 | + * @param string $message |
|
295 | + * @param array $parameters |
|
296 | + * @return IEvent |
|
297 | + * @throws \InvalidArgumentException if the message or parameters are invalid |
|
298 | + * @since 8.2.0 |
|
299 | + */ |
|
300 | + public function setMessage(string $message, array $parameters = []): IEvent { |
|
301 | + if (isset($message[255])) { |
|
302 | + throw new \InvalidArgumentException('The given message is invalid'); |
|
303 | + } |
|
304 | + $this->message = $message; |
|
305 | + $this->messageParameters = $parameters; |
|
306 | + return $this; |
|
307 | + } |
|
308 | + |
|
309 | + /** |
|
310 | + * @return string |
|
311 | + */ |
|
312 | + public function getMessage(): string { |
|
313 | + return $this->message; |
|
314 | + } |
|
315 | + |
|
316 | + /** |
|
317 | + * @return array |
|
318 | + */ |
|
319 | + public function getMessageParameters(): array { |
|
320 | + return $this->messageParameters; |
|
321 | + } |
|
322 | + |
|
323 | + /** |
|
324 | + * @param string $message |
|
325 | + * @return $this |
|
326 | + * @throws \InvalidArgumentException if the message is invalid |
|
327 | + * @since 11.0.0 |
|
328 | + */ |
|
329 | + public function setParsedMessage(string $message): IEvent { |
|
330 | + $this->messageParsed = $message; |
|
331 | + return $this; |
|
332 | + } |
|
333 | + |
|
334 | + /** |
|
335 | + * @return string |
|
336 | + * @since 11.0.0 |
|
337 | + */ |
|
338 | + public function getParsedMessage(): string { |
|
339 | + return $this->messageParsed; |
|
340 | + } |
|
341 | + |
|
342 | + /** |
|
343 | + * @param string $message |
|
344 | + * @param array $parameters |
|
345 | + * @return $this |
|
346 | + * @throws \InvalidArgumentException if the subject or parameters are invalid |
|
347 | + * @since 11.0.0 |
|
348 | + */ |
|
349 | + public function setRichMessage(string $message, array $parameters = []): IEvent { |
|
350 | + $this->messageRich = $message; |
|
351 | + $this->messageRichParameters = $parameters; |
|
352 | + |
|
353 | + return $this; |
|
354 | + } |
|
355 | + |
|
356 | + /** |
|
357 | + * @return string |
|
358 | + * @since 11.0.0 |
|
359 | + */ |
|
360 | + public function getRichMessage(): string { |
|
361 | + return $this->messageRich; |
|
362 | + } |
|
363 | + |
|
364 | + /** |
|
365 | + * @return array[] |
|
366 | + * @since 11.0.0 |
|
367 | + */ |
|
368 | + public function getRichMessageParameters(): array { |
|
369 | + return $this->messageRichParameters; |
|
370 | + } |
|
371 | + |
|
372 | + /** |
|
373 | + * Set the object of the activity |
|
374 | + * |
|
375 | + * @param string $objectType |
|
376 | + * @param int $objectId |
|
377 | + * @param string $objectName |
|
378 | + * @return IEvent |
|
379 | + * @throws \InvalidArgumentException if the object is invalid |
|
380 | + * @since 8.2.0 |
|
381 | + */ |
|
382 | + public function setObject(string $objectType, int $objectId, string $objectName = ''): IEvent { |
|
383 | + if (isset($objectType[255])) { |
|
384 | + throw new \InvalidArgumentException('The given object type is invalid'); |
|
385 | + } |
|
386 | + if (isset($objectName[4000])) { |
|
387 | + throw new \InvalidArgumentException('The given object name is invalid'); |
|
388 | + } |
|
389 | + $this->objectType = $objectType; |
|
390 | + $this->objectId = $objectId; |
|
391 | + $this->objectName = $objectName; |
|
392 | + return $this; |
|
393 | + } |
|
394 | + |
|
395 | + /** |
|
396 | + * @return string |
|
397 | + */ |
|
398 | + public function getObjectType(): string { |
|
399 | + return $this->objectType; |
|
400 | + } |
|
401 | + |
|
402 | + /** |
|
403 | + * @return int |
|
404 | + */ |
|
405 | + public function getObjectId(): int { |
|
406 | + return $this->objectId; |
|
407 | + } |
|
408 | + |
|
409 | + /** |
|
410 | + * @return string |
|
411 | + */ |
|
412 | + public function getObjectName(): string { |
|
413 | + return $this->objectName; |
|
414 | + } |
|
415 | + |
|
416 | + /** |
|
417 | + * Set the link of the activity |
|
418 | + * |
|
419 | + * @param string $link |
|
420 | + * @return IEvent |
|
421 | + * @throws \InvalidArgumentException if the link is invalid |
|
422 | + * @since 8.2.0 |
|
423 | + */ |
|
424 | + public function setLink(string $link): IEvent { |
|
425 | + if (isset($link[4000])) { |
|
426 | + throw new \InvalidArgumentException('The given link is invalid'); |
|
427 | + } |
|
428 | + $this->link = $link; |
|
429 | + return $this; |
|
430 | + } |
|
431 | + |
|
432 | + /** |
|
433 | + * @return string |
|
434 | + */ |
|
435 | + public function getLink(): string { |
|
436 | + return $this->link; |
|
437 | + } |
|
438 | + |
|
439 | + /** |
|
440 | + * @param string $icon |
|
441 | + * @return $this |
|
442 | + * @throws \InvalidArgumentException if the icon is invalid |
|
443 | + * @since 11.0.0 |
|
444 | + */ |
|
445 | + public function setIcon(string $icon): IEvent { |
|
446 | + if (isset($icon[4000])) { |
|
447 | + throw new \InvalidArgumentException('The given icon is invalid'); |
|
448 | + } |
|
449 | + $this->icon = $icon; |
|
450 | + return $this; |
|
451 | + } |
|
452 | + |
|
453 | + /** |
|
454 | + * @return string |
|
455 | + * @since 11.0.0 |
|
456 | + */ |
|
457 | + public function getIcon(): string { |
|
458 | + return $this->icon; |
|
459 | + } |
|
460 | + |
|
461 | + /** |
|
462 | + * @param IEvent $child |
|
463 | + * @return $this |
|
464 | + * @since 11.0.0 - Since 15.0.0 returns $this |
|
465 | + */ |
|
466 | + public function setChildEvent(IEvent $child): IEvent { |
|
467 | + $this->child = $child; |
|
468 | + return $this; |
|
469 | + } |
|
470 | + |
|
471 | + /** |
|
472 | + * @return IEvent|null |
|
473 | + * @since 11.0.0 |
|
474 | + */ |
|
475 | + public function getChildEvent() { |
|
476 | + return $this->child; |
|
477 | + } |
|
478 | + |
|
479 | + /** |
|
480 | + * @return bool |
|
481 | + * @since 8.2.0 |
|
482 | + */ |
|
483 | + public function isValid(): bool { |
|
484 | + return |
|
485 | + $this->isValidCommon() |
|
486 | + && |
|
487 | + $this->getSubject() !== '' |
|
488 | + ; |
|
489 | + } |
|
490 | + |
|
491 | + /** |
|
492 | + * @return bool |
|
493 | + * @since 8.2.0 |
|
494 | + */ |
|
495 | + public function isValidParsed(): bool { |
|
496 | + if ($this->getRichSubject() !== '' || !empty($this->getRichSubjectParameters())) { |
|
497 | + try { |
|
498 | + $this->richValidator->validate($this->getRichSubject(), $this->getRichSubjectParameters()); |
|
499 | + } catch (InvalidObjectExeption $e) { |
|
500 | + return false; |
|
501 | + } |
|
502 | + } |
|
503 | + |
|
504 | + if ($this->getRichMessage() !== '' || !empty($this->getRichMessageParameters())) { |
|
505 | + try { |
|
506 | + $this->richValidator->validate($this->getRichMessage(), $this->getRichMessageParameters()); |
|
507 | + } catch (InvalidObjectExeption $e) { |
|
508 | + return false; |
|
509 | + } |
|
510 | + } |
|
511 | + |
|
512 | + return |
|
513 | + $this->isValidCommon() |
|
514 | + && |
|
515 | + $this->getParsedSubject() !== '' |
|
516 | + ; |
|
517 | + } |
|
518 | + |
|
519 | + protected function isValidCommon(): bool { |
|
520 | + return |
|
521 | + $this->getApp() !== '' |
|
522 | + && |
|
523 | + $this->getType() !== '' |
|
524 | + && |
|
525 | + $this->getAffectedUser() !== '' |
|
526 | + && |
|
527 | + $this->getTimestamp() !== 0 |
|
528 | + /** |
|
529 | + * Disabled for BC with old activities |
|
530 | + * && |
|
531 | + * $this->getObjectType() !== '' |
|
532 | + * && |
|
533 | + * $this->getObjectId() !== 0 |
|
534 | + */ |
|
535 | + ; |
|
536 | + } |
|
537 | + |
|
538 | + public function setGenerateNotification(bool $generate): IEvent { |
|
539 | + $this->generateNotification = $generate; |
|
540 | + return $this; |
|
541 | + } |
|
542 | + |
|
543 | + public function getGenerateNotification(): bool { |
|
544 | + return $this->generateNotification; |
|
545 | + } |
|
546 | 546 | } |
@@ -31,29 +31,29 @@ |
||
31 | 31 | * class based one |
32 | 32 | */ |
33 | 33 | class ActivitySettingsAdapter extends ActivitySettings { |
34 | - private $oldSettings; |
|
34 | + private $oldSettings; |
|
35 | 35 | |
36 | - public function __construct(ISetting $oldSettings) { |
|
37 | - $this->oldSettings = $oldSettings; |
|
38 | - } |
|
36 | + public function __construct(ISetting $oldSettings) { |
|
37 | + $this->oldSettings = $oldSettings; |
|
38 | + } |
|
39 | 39 | |
40 | - public function getIdentifier() { |
|
41 | - return $this->oldSettings->getIdentifier(); |
|
42 | - } |
|
40 | + public function getIdentifier() { |
|
41 | + return $this->oldSettings->getIdentifier(); |
|
42 | + } |
|
43 | 43 | |
44 | - public function getName() { |
|
45 | - return $this->oldSettings->getName(); |
|
46 | - } |
|
44 | + public function getName() { |
|
45 | + return $this->oldSettings->getName(); |
|
46 | + } |
|
47 | 47 | |
48 | - public function getPriority() { |
|
49 | - return $this->oldSettings->getPriority(); |
|
50 | - } |
|
48 | + public function getPriority() { |
|
49 | + return $this->oldSettings->getPriority(); |
|
50 | + } |
|
51 | 51 | |
52 | - public function canChangeMail() { |
|
53 | - return $this->oldSettings->canChangeMail(); |
|
54 | - } |
|
52 | + public function canChangeMail() { |
|
53 | + return $this->oldSettings->canChangeMail(); |
|
54 | + } |
|
55 | 55 | |
56 | - public function isDefaultEnabledMail() { |
|
57 | - return $this->oldSettings->isDefaultEnabledMail(); |
|
58 | - } |
|
56 | + public function isDefaultEnabledMail() { |
|
57 | + return $this->oldSettings->isDefaultEnabledMail(); |
|
58 | + } |
|
59 | 59 | } |
@@ -42,352 +42,352 @@ |
||
42 | 42 | use OCP\RichObjectStrings\IValidator; |
43 | 43 | |
44 | 44 | class Manager implements IManager { |
45 | - /** @var IRequest */ |
|
46 | - protected $request; |
|
47 | - |
|
48 | - /** @var IUserSession */ |
|
49 | - protected $session; |
|
50 | - |
|
51 | - /** @var IConfig */ |
|
52 | - protected $config; |
|
53 | - |
|
54 | - /** @var IValidator */ |
|
55 | - protected $validator; |
|
56 | - |
|
57 | - /** @var string */ |
|
58 | - protected $formattingObjectType; |
|
59 | - |
|
60 | - /** @var int */ |
|
61 | - protected $formattingObjectId; |
|
62 | - |
|
63 | - /** @var bool */ |
|
64 | - protected $requirePNG = false; |
|
65 | - |
|
66 | - /** @var string */ |
|
67 | - protected $currentUserId; |
|
68 | - |
|
69 | - public function __construct(IRequest $request, |
|
70 | - IUserSession $session, |
|
71 | - IConfig $config, |
|
72 | - IValidator $validator) { |
|
73 | - $this->request = $request; |
|
74 | - $this->session = $session; |
|
75 | - $this->config = $config; |
|
76 | - $this->validator = $validator; |
|
77 | - } |
|
78 | - |
|
79 | - /** @var \Closure[] */ |
|
80 | - private $consumersClosures = []; |
|
81 | - |
|
82 | - /** @var IConsumer[] */ |
|
83 | - private $consumers = []; |
|
84 | - |
|
85 | - /** |
|
86 | - * @return \OCP\Activity\IConsumer[] |
|
87 | - */ |
|
88 | - protected function getConsumers(): array { |
|
89 | - if (!empty($this->consumers)) { |
|
90 | - return $this->consumers; |
|
91 | - } |
|
92 | - |
|
93 | - $this->consumers = []; |
|
94 | - foreach ($this->consumersClosures as $consumer) { |
|
95 | - $c = $consumer(); |
|
96 | - if ($c instanceof IConsumer) { |
|
97 | - $this->consumers[] = $c; |
|
98 | - } else { |
|
99 | - throw new \InvalidArgumentException('The given consumer does not implement the \OCP\Activity\IConsumer interface'); |
|
100 | - } |
|
101 | - } |
|
102 | - |
|
103 | - return $this->consumers; |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Generates a new IEvent object |
|
108 | - * |
|
109 | - * Make sure to call at least the following methods before sending it to the |
|
110 | - * app with via the publish() method: |
|
111 | - * - setApp() |
|
112 | - * - setType() |
|
113 | - * - setAffectedUser() |
|
114 | - * - setSubject() |
|
115 | - * |
|
116 | - * @return IEvent |
|
117 | - */ |
|
118 | - public function generateEvent(): IEvent { |
|
119 | - return new Event($this->validator); |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Publish an event to the activity consumers |
|
124 | - * |
|
125 | - * Make sure to call at least the following methods before sending an Event: |
|
126 | - * - setApp() |
|
127 | - * - setType() |
|
128 | - * - setAffectedUser() |
|
129 | - * - setSubject() |
|
130 | - * |
|
131 | - * @param IEvent $event |
|
132 | - * @throws \BadMethodCallException if required values have not been set |
|
133 | - */ |
|
134 | - public function publish(IEvent $event): void { |
|
135 | - if ($event->getAuthor() === '') { |
|
136 | - if ($this->session->getUser() instanceof IUser) { |
|
137 | - $event->setAuthor($this->session->getUser()->getUID()); |
|
138 | - } |
|
139 | - } |
|
140 | - |
|
141 | - if (!$event->getTimestamp()) { |
|
142 | - $event->setTimestamp(time()); |
|
143 | - } |
|
144 | - |
|
145 | - if (!$event->isValid()) { |
|
146 | - throw new \BadMethodCallException('The given event is invalid'); |
|
147 | - } |
|
148 | - |
|
149 | - foreach ($this->getConsumers() as $c) { |
|
150 | - $c->receive($event); |
|
151 | - } |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * In order to improve lazy loading a closure can be registered which will be called in case |
|
156 | - * activity consumers are actually requested |
|
157 | - * |
|
158 | - * $callable has to return an instance of OCA\Activity\IConsumer |
|
159 | - * |
|
160 | - * @param \Closure $callable |
|
161 | - */ |
|
162 | - public function registerConsumer(\Closure $callable): void { |
|
163 | - $this->consumersClosures[] = $callable; |
|
164 | - $this->consumers = []; |
|
165 | - } |
|
166 | - |
|
167 | - /** @var string[] */ |
|
168 | - protected $filterClasses = []; |
|
169 | - |
|
170 | - /** @var IFilter[] */ |
|
171 | - protected $filters = []; |
|
172 | - |
|
173 | - /** |
|
174 | - * @param string $filter Class must implement OCA\Activity\IFilter |
|
175 | - * @return void |
|
176 | - */ |
|
177 | - public function registerFilter(string $filter): void { |
|
178 | - $this->filterClasses[$filter] = false; |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * @return IFilter[] |
|
183 | - * @throws \InvalidArgumentException |
|
184 | - */ |
|
185 | - public function getFilters(): array { |
|
186 | - foreach ($this->filterClasses as $class => $false) { |
|
187 | - /** @var IFilter $filter */ |
|
188 | - $filter = \OC::$server->query($class); |
|
189 | - |
|
190 | - if (!$filter instanceof IFilter) { |
|
191 | - throw new \InvalidArgumentException('Invalid activity filter registered'); |
|
192 | - } |
|
193 | - |
|
194 | - $this->filters[$filter->getIdentifier()] = $filter; |
|
195 | - |
|
196 | - unset($this->filterClasses[$class]); |
|
197 | - } |
|
198 | - return $this->filters; |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * @param string $id |
|
203 | - * @return IFilter |
|
204 | - * @throws \InvalidArgumentException when the filter was not found |
|
205 | - * @since 11.0.0 |
|
206 | - */ |
|
207 | - public function getFilterById(string $id): IFilter { |
|
208 | - $filters = $this->getFilters(); |
|
209 | - |
|
210 | - if (isset($filters[$id])) { |
|
211 | - return $filters[$id]; |
|
212 | - } |
|
213 | - |
|
214 | - throw new \InvalidArgumentException('Requested filter does not exist'); |
|
215 | - } |
|
216 | - |
|
217 | - /** @var string[] */ |
|
218 | - protected $providerClasses = []; |
|
219 | - |
|
220 | - /** @var IProvider[] */ |
|
221 | - protected $providers = []; |
|
222 | - |
|
223 | - /** |
|
224 | - * @param string $provider Class must implement OCA\Activity\IProvider |
|
225 | - * @return void |
|
226 | - */ |
|
227 | - public function registerProvider(string $provider): void { |
|
228 | - $this->providerClasses[$provider] = false; |
|
229 | - } |
|
230 | - |
|
231 | - /** |
|
232 | - * @return IProvider[] |
|
233 | - * @throws \InvalidArgumentException |
|
234 | - */ |
|
235 | - public function getProviders(): array { |
|
236 | - foreach ($this->providerClasses as $class => $false) { |
|
237 | - /** @var IProvider $provider */ |
|
238 | - $provider = \OC::$server->query($class); |
|
239 | - |
|
240 | - if (!$provider instanceof IProvider) { |
|
241 | - throw new \InvalidArgumentException('Invalid activity provider registered'); |
|
242 | - } |
|
243 | - |
|
244 | - $this->providers[] = $provider; |
|
245 | - |
|
246 | - unset($this->providerClasses[$class]); |
|
247 | - } |
|
248 | - return $this->providers; |
|
249 | - } |
|
250 | - |
|
251 | - /** @var string[] */ |
|
252 | - protected $settingsClasses = []; |
|
253 | - |
|
254 | - /** @var ISetting[] */ |
|
255 | - protected $settings = []; |
|
256 | - |
|
257 | - /** |
|
258 | - * @param string $setting Class must implement OCA\Activity\ISetting |
|
259 | - * @return void |
|
260 | - */ |
|
261 | - public function registerSetting(string $setting): void { |
|
262 | - $this->settingsClasses[$setting] = false; |
|
263 | - } |
|
264 | - |
|
265 | - /** |
|
266 | - * @return ActivitySettings[] |
|
267 | - * @throws \InvalidArgumentException |
|
268 | - */ |
|
269 | - public function getSettings(): array { |
|
270 | - foreach ($this->settingsClasses as $class => $false) { |
|
271 | - /** @var ISetting $setting */ |
|
272 | - $setting = \OC::$server->query($class); |
|
273 | - |
|
274 | - if (!$setting instanceof ISetting) { |
|
275 | - if (!$setting instanceof ActivitySettings) { |
|
276 | - $setting = new ActivitySettingsAdapter($setting); |
|
277 | - } |
|
278 | - } else { |
|
279 | - throw new \InvalidArgumentException('Invalid activity filter registered'); |
|
280 | - } |
|
281 | - |
|
282 | - $this->settings[$setting->getIdentifier()] = $setting; |
|
283 | - |
|
284 | - unset($this->settingsClasses[$class]); |
|
285 | - } |
|
286 | - return $this->settings; |
|
287 | - } |
|
288 | - |
|
289 | - /** |
|
290 | - * @param string $id |
|
291 | - * @return ActivitySettings |
|
292 | - * @throws \InvalidArgumentException when the setting was not found |
|
293 | - * @since 11.0.0 |
|
294 | - */ |
|
295 | - public function getSettingById(string $id): ActivitySettings { |
|
296 | - $settings = $this->getSettings(); |
|
297 | - |
|
298 | - if (isset($settings[$id])) { |
|
299 | - return $settings[$id]; |
|
300 | - } |
|
301 | - |
|
302 | - throw new \InvalidArgumentException('Requested setting does not exist'); |
|
303 | - } |
|
304 | - |
|
305 | - |
|
306 | - /** |
|
307 | - * @param string $type |
|
308 | - * @param int $id |
|
309 | - */ |
|
310 | - public function setFormattingObject(string $type, int $id): void { |
|
311 | - $this->formattingObjectType = $type; |
|
312 | - $this->formattingObjectId = $id; |
|
313 | - } |
|
314 | - |
|
315 | - /** |
|
316 | - * @return bool |
|
317 | - */ |
|
318 | - public function isFormattingFilteredObject(): bool { |
|
319 | - return $this->formattingObjectType !== null && $this->formattingObjectId !== null |
|
320 | - && $this->formattingObjectType === $this->request->getParam('object_type') |
|
321 | - && $this->formattingObjectId === (int) $this->request->getParam('object_id'); |
|
322 | - } |
|
323 | - |
|
324 | - /** |
|
325 | - * @param bool $status Set to true, when parsing events should not use SVG icons |
|
326 | - */ |
|
327 | - public function setRequirePNG(bool $status): void { |
|
328 | - $this->requirePNG = $status; |
|
329 | - } |
|
330 | - |
|
331 | - /** |
|
332 | - * @return bool |
|
333 | - */ |
|
334 | - public function getRequirePNG(): bool { |
|
335 | - return $this->requirePNG; |
|
336 | - } |
|
337 | - |
|
338 | - /** |
|
339 | - * Set the user we need to use |
|
340 | - * |
|
341 | - * @param string|null $currentUserId |
|
342 | - * @throws \UnexpectedValueException If the user is invalid |
|
343 | - */ |
|
344 | - public function setCurrentUserId(string $currentUserId = null): void { |
|
345 | - if (!is_string($currentUserId) && $currentUserId !== null) { |
|
346 | - throw new \UnexpectedValueException('The given current user is invalid'); |
|
347 | - } |
|
348 | - $this->currentUserId = $currentUserId; |
|
349 | - } |
|
350 | - |
|
351 | - /** |
|
352 | - * Get the user we need to use |
|
353 | - * |
|
354 | - * Either the user is logged in, or we try to get it from the token |
|
355 | - * |
|
356 | - * @return string |
|
357 | - * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
358 | - */ |
|
359 | - public function getCurrentUserId(): string { |
|
360 | - if ($this->currentUserId !== null) { |
|
361 | - return $this->currentUserId; |
|
362 | - } |
|
363 | - |
|
364 | - if (!$this->session->isLoggedIn()) { |
|
365 | - return $this->getUserFromToken(); |
|
366 | - } |
|
367 | - |
|
368 | - return $this->session->getUser()->getUID(); |
|
369 | - } |
|
370 | - |
|
371 | - /** |
|
372 | - * Get the user for the token |
|
373 | - * |
|
374 | - * @return string |
|
375 | - * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
376 | - */ |
|
377 | - protected function getUserFromToken(): string { |
|
378 | - $token = (string) $this->request->getParam('token', ''); |
|
379 | - if (strlen($token) !== 30) { |
|
380 | - throw new \UnexpectedValueException('The token is invalid'); |
|
381 | - } |
|
382 | - |
|
383 | - $users = $this->config->getUsersForUserValue('activity', 'rsstoken', $token); |
|
384 | - |
|
385 | - if (count($users) !== 1) { |
|
386 | - // No unique user found |
|
387 | - throw new \UnexpectedValueException('The token is invalid'); |
|
388 | - } |
|
389 | - |
|
390 | - // Token found login as that user |
|
391 | - return array_shift($users); |
|
392 | - } |
|
45 | + /** @var IRequest */ |
|
46 | + protected $request; |
|
47 | + |
|
48 | + /** @var IUserSession */ |
|
49 | + protected $session; |
|
50 | + |
|
51 | + /** @var IConfig */ |
|
52 | + protected $config; |
|
53 | + |
|
54 | + /** @var IValidator */ |
|
55 | + protected $validator; |
|
56 | + |
|
57 | + /** @var string */ |
|
58 | + protected $formattingObjectType; |
|
59 | + |
|
60 | + /** @var int */ |
|
61 | + protected $formattingObjectId; |
|
62 | + |
|
63 | + /** @var bool */ |
|
64 | + protected $requirePNG = false; |
|
65 | + |
|
66 | + /** @var string */ |
|
67 | + protected $currentUserId; |
|
68 | + |
|
69 | + public function __construct(IRequest $request, |
|
70 | + IUserSession $session, |
|
71 | + IConfig $config, |
|
72 | + IValidator $validator) { |
|
73 | + $this->request = $request; |
|
74 | + $this->session = $session; |
|
75 | + $this->config = $config; |
|
76 | + $this->validator = $validator; |
|
77 | + } |
|
78 | + |
|
79 | + /** @var \Closure[] */ |
|
80 | + private $consumersClosures = []; |
|
81 | + |
|
82 | + /** @var IConsumer[] */ |
|
83 | + private $consumers = []; |
|
84 | + |
|
85 | + /** |
|
86 | + * @return \OCP\Activity\IConsumer[] |
|
87 | + */ |
|
88 | + protected function getConsumers(): array { |
|
89 | + if (!empty($this->consumers)) { |
|
90 | + return $this->consumers; |
|
91 | + } |
|
92 | + |
|
93 | + $this->consumers = []; |
|
94 | + foreach ($this->consumersClosures as $consumer) { |
|
95 | + $c = $consumer(); |
|
96 | + if ($c instanceof IConsumer) { |
|
97 | + $this->consumers[] = $c; |
|
98 | + } else { |
|
99 | + throw new \InvalidArgumentException('The given consumer does not implement the \OCP\Activity\IConsumer interface'); |
|
100 | + } |
|
101 | + } |
|
102 | + |
|
103 | + return $this->consumers; |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Generates a new IEvent object |
|
108 | + * |
|
109 | + * Make sure to call at least the following methods before sending it to the |
|
110 | + * app with via the publish() method: |
|
111 | + * - setApp() |
|
112 | + * - setType() |
|
113 | + * - setAffectedUser() |
|
114 | + * - setSubject() |
|
115 | + * |
|
116 | + * @return IEvent |
|
117 | + */ |
|
118 | + public function generateEvent(): IEvent { |
|
119 | + return new Event($this->validator); |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Publish an event to the activity consumers |
|
124 | + * |
|
125 | + * Make sure to call at least the following methods before sending an Event: |
|
126 | + * - setApp() |
|
127 | + * - setType() |
|
128 | + * - setAffectedUser() |
|
129 | + * - setSubject() |
|
130 | + * |
|
131 | + * @param IEvent $event |
|
132 | + * @throws \BadMethodCallException if required values have not been set |
|
133 | + */ |
|
134 | + public function publish(IEvent $event): void { |
|
135 | + if ($event->getAuthor() === '') { |
|
136 | + if ($this->session->getUser() instanceof IUser) { |
|
137 | + $event->setAuthor($this->session->getUser()->getUID()); |
|
138 | + } |
|
139 | + } |
|
140 | + |
|
141 | + if (!$event->getTimestamp()) { |
|
142 | + $event->setTimestamp(time()); |
|
143 | + } |
|
144 | + |
|
145 | + if (!$event->isValid()) { |
|
146 | + throw new \BadMethodCallException('The given event is invalid'); |
|
147 | + } |
|
148 | + |
|
149 | + foreach ($this->getConsumers() as $c) { |
|
150 | + $c->receive($event); |
|
151 | + } |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * In order to improve lazy loading a closure can be registered which will be called in case |
|
156 | + * activity consumers are actually requested |
|
157 | + * |
|
158 | + * $callable has to return an instance of OCA\Activity\IConsumer |
|
159 | + * |
|
160 | + * @param \Closure $callable |
|
161 | + */ |
|
162 | + public function registerConsumer(\Closure $callable): void { |
|
163 | + $this->consumersClosures[] = $callable; |
|
164 | + $this->consumers = []; |
|
165 | + } |
|
166 | + |
|
167 | + /** @var string[] */ |
|
168 | + protected $filterClasses = []; |
|
169 | + |
|
170 | + /** @var IFilter[] */ |
|
171 | + protected $filters = []; |
|
172 | + |
|
173 | + /** |
|
174 | + * @param string $filter Class must implement OCA\Activity\IFilter |
|
175 | + * @return void |
|
176 | + */ |
|
177 | + public function registerFilter(string $filter): void { |
|
178 | + $this->filterClasses[$filter] = false; |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * @return IFilter[] |
|
183 | + * @throws \InvalidArgumentException |
|
184 | + */ |
|
185 | + public function getFilters(): array { |
|
186 | + foreach ($this->filterClasses as $class => $false) { |
|
187 | + /** @var IFilter $filter */ |
|
188 | + $filter = \OC::$server->query($class); |
|
189 | + |
|
190 | + if (!$filter instanceof IFilter) { |
|
191 | + throw new \InvalidArgumentException('Invalid activity filter registered'); |
|
192 | + } |
|
193 | + |
|
194 | + $this->filters[$filter->getIdentifier()] = $filter; |
|
195 | + |
|
196 | + unset($this->filterClasses[$class]); |
|
197 | + } |
|
198 | + return $this->filters; |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * @param string $id |
|
203 | + * @return IFilter |
|
204 | + * @throws \InvalidArgumentException when the filter was not found |
|
205 | + * @since 11.0.0 |
|
206 | + */ |
|
207 | + public function getFilterById(string $id): IFilter { |
|
208 | + $filters = $this->getFilters(); |
|
209 | + |
|
210 | + if (isset($filters[$id])) { |
|
211 | + return $filters[$id]; |
|
212 | + } |
|
213 | + |
|
214 | + throw new \InvalidArgumentException('Requested filter does not exist'); |
|
215 | + } |
|
216 | + |
|
217 | + /** @var string[] */ |
|
218 | + protected $providerClasses = []; |
|
219 | + |
|
220 | + /** @var IProvider[] */ |
|
221 | + protected $providers = []; |
|
222 | + |
|
223 | + /** |
|
224 | + * @param string $provider Class must implement OCA\Activity\IProvider |
|
225 | + * @return void |
|
226 | + */ |
|
227 | + public function registerProvider(string $provider): void { |
|
228 | + $this->providerClasses[$provider] = false; |
|
229 | + } |
|
230 | + |
|
231 | + /** |
|
232 | + * @return IProvider[] |
|
233 | + * @throws \InvalidArgumentException |
|
234 | + */ |
|
235 | + public function getProviders(): array { |
|
236 | + foreach ($this->providerClasses as $class => $false) { |
|
237 | + /** @var IProvider $provider */ |
|
238 | + $provider = \OC::$server->query($class); |
|
239 | + |
|
240 | + if (!$provider instanceof IProvider) { |
|
241 | + throw new \InvalidArgumentException('Invalid activity provider registered'); |
|
242 | + } |
|
243 | + |
|
244 | + $this->providers[] = $provider; |
|
245 | + |
|
246 | + unset($this->providerClasses[$class]); |
|
247 | + } |
|
248 | + return $this->providers; |
|
249 | + } |
|
250 | + |
|
251 | + /** @var string[] */ |
|
252 | + protected $settingsClasses = []; |
|
253 | + |
|
254 | + /** @var ISetting[] */ |
|
255 | + protected $settings = []; |
|
256 | + |
|
257 | + /** |
|
258 | + * @param string $setting Class must implement OCA\Activity\ISetting |
|
259 | + * @return void |
|
260 | + */ |
|
261 | + public function registerSetting(string $setting): void { |
|
262 | + $this->settingsClasses[$setting] = false; |
|
263 | + } |
|
264 | + |
|
265 | + /** |
|
266 | + * @return ActivitySettings[] |
|
267 | + * @throws \InvalidArgumentException |
|
268 | + */ |
|
269 | + public function getSettings(): array { |
|
270 | + foreach ($this->settingsClasses as $class => $false) { |
|
271 | + /** @var ISetting $setting */ |
|
272 | + $setting = \OC::$server->query($class); |
|
273 | + |
|
274 | + if (!$setting instanceof ISetting) { |
|
275 | + if (!$setting instanceof ActivitySettings) { |
|
276 | + $setting = new ActivitySettingsAdapter($setting); |
|
277 | + } |
|
278 | + } else { |
|
279 | + throw new \InvalidArgumentException('Invalid activity filter registered'); |
|
280 | + } |
|
281 | + |
|
282 | + $this->settings[$setting->getIdentifier()] = $setting; |
|
283 | + |
|
284 | + unset($this->settingsClasses[$class]); |
|
285 | + } |
|
286 | + return $this->settings; |
|
287 | + } |
|
288 | + |
|
289 | + /** |
|
290 | + * @param string $id |
|
291 | + * @return ActivitySettings |
|
292 | + * @throws \InvalidArgumentException when the setting was not found |
|
293 | + * @since 11.0.0 |
|
294 | + */ |
|
295 | + public function getSettingById(string $id): ActivitySettings { |
|
296 | + $settings = $this->getSettings(); |
|
297 | + |
|
298 | + if (isset($settings[$id])) { |
|
299 | + return $settings[$id]; |
|
300 | + } |
|
301 | + |
|
302 | + throw new \InvalidArgumentException('Requested setting does not exist'); |
|
303 | + } |
|
304 | + |
|
305 | + |
|
306 | + /** |
|
307 | + * @param string $type |
|
308 | + * @param int $id |
|
309 | + */ |
|
310 | + public function setFormattingObject(string $type, int $id): void { |
|
311 | + $this->formattingObjectType = $type; |
|
312 | + $this->formattingObjectId = $id; |
|
313 | + } |
|
314 | + |
|
315 | + /** |
|
316 | + * @return bool |
|
317 | + */ |
|
318 | + public function isFormattingFilteredObject(): bool { |
|
319 | + return $this->formattingObjectType !== null && $this->formattingObjectId !== null |
|
320 | + && $this->formattingObjectType === $this->request->getParam('object_type') |
|
321 | + && $this->formattingObjectId === (int) $this->request->getParam('object_id'); |
|
322 | + } |
|
323 | + |
|
324 | + /** |
|
325 | + * @param bool $status Set to true, when parsing events should not use SVG icons |
|
326 | + */ |
|
327 | + public function setRequirePNG(bool $status): void { |
|
328 | + $this->requirePNG = $status; |
|
329 | + } |
|
330 | + |
|
331 | + /** |
|
332 | + * @return bool |
|
333 | + */ |
|
334 | + public function getRequirePNG(): bool { |
|
335 | + return $this->requirePNG; |
|
336 | + } |
|
337 | + |
|
338 | + /** |
|
339 | + * Set the user we need to use |
|
340 | + * |
|
341 | + * @param string|null $currentUserId |
|
342 | + * @throws \UnexpectedValueException If the user is invalid |
|
343 | + */ |
|
344 | + public function setCurrentUserId(string $currentUserId = null): void { |
|
345 | + if (!is_string($currentUserId) && $currentUserId !== null) { |
|
346 | + throw new \UnexpectedValueException('The given current user is invalid'); |
|
347 | + } |
|
348 | + $this->currentUserId = $currentUserId; |
|
349 | + } |
|
350 | + |
|
351 | + /** |
|
352 | + * Get the user we need to use |
|
353 | + * |
|
354 | + * Either the user is logged in, or we try to get it from the token |
|
355 | + * |
|
356 | + * @return string |
|
357 | + * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
358 | + */ |
|
359 | + public function getCurrentUserId(): string { |
|
360 | + if ($this->currentUserId !== null) { |
|
361 | + return $this->currentUserId; |
|
362 | + } |
|
363 | + |
|
364 | + if (!$this->session->isLoggedIn()) { |
|
365 | + return $this->getUserFromToken(); |
|
366 | + } |
|
367 | + |
|
368 | + return $this->session->getUser()->getUID(); |
|
369 | + } |
|
370 | + |
|
371 | + /** |
|
372 | + * Get the user for the token |
|
373 | + * |
|
374 | + * @return string |
|
375 | + * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
376 | + */ |
|
377 | + protected function getUserFromToken(): string { |
|
378 | + $token = (string) $this->request->getParam('token', ''); |
|
379 | + if (strlen($token) !== 30) { |
|
380 | + throw new \UnexpectedValueException('The token is invalid'); |
|
381 | + } |
|
382 | + |
|
383 | + $users = $this->config->getUsersForUserValue('activity', 'rsstoken', $token); |
|
384 | + |
|
385 | + if (count($users) !== 1) { |
|
386 | + // No unique user found |
|
387 | + throw new \UnexpectedValueException('The token is invalid'); |
|
388 | + } |
|
389 | + |
|
390 | + // Token found login as that user |
|
391 | + return array_shift($users); |
|
392 | + } |
|
393 | 393 | } |
@@ -32,13 +32,13 @@ |
||
32 | 32 | * @since 8.0.0 |
33 | 33 | */ |
34 | 34 | interface IExtension { |
35 | - public const METHOD_STREAM = 'stream'; |
|
36 | - public const METHOD_MAIL = 'email'; |
|
37 | - public const METHOD_NOTIFICATION = 'notification'; |
|
35 | + public const METHOD_STREAM = 'stream'; |
|
36 | + public const METHOD_MAIL = 'email'; |
|
37 | + public const METHOD_NOTIFICATION = 'notification'; |
|
38 | 38 | |
39 | - public const PRIORITY_VERYLOW = 10; |
|
40 | - public const PRIORITY_LOW = 20; |
|
41 | - public const PRIORITY_MEDIUM = 30; |
|
42 | - public const PRIORITY_HIGH = 40; |
|
43 | - public const PRIORITY_VERYHIGH = 50; |
|
39 | + public const PRIORITY_VERYLOW = 10; |
|
40 | + public const PRIORITY_LOW = 20; |
|
41 | + public const PRIORITY_MEDIUM = 30; |
|
42 | + public const PRIORITY_HIGH = 40; |
|
43 | + public const PRIORITY_VERYHIGH = 50; |
|
44 | 44 | } |
@@ -36,9 +36,9 @@ |
||
36 | 36 | public const METHOD_MAIL = 'email'; |
37 | 37 | public const METHOD_NOTIFICATION = 'notification'; |
38 | 38 | |
39 | - public const PRIORITY_VERYLOW = 10; |
|
40 | - public const PRIORITY_LOW = 20; |
|
41 | - public const PRIORITY_MEDIUM = 30; |
|
42 | - public const PRIORITY_HIGH = 40; |
|
43 | - public const PRIORITY_VERYHIGH = 50; |
|
39 | + public const PRIORITY_VERYLOW = 10; |
|
40 | + public const PRIORITY_LOW = 20; |
|
41 | + public const PRIORITY_MEDIUM = 30; |
|
42 | + public const PRIORITY_HIGH = 40; |
|
43 | + public const PRIORITY_VERYHIGH = 50; |
|
44 | 44 | } |
@@ -42,345 +42,345 @@ |
||
42 | 42 | * @since 8.2.0 |
43 | 43 | */ |
44 | 44 | interface IEvent { |
45 | - /** |
|
46 | - * Set the app of the activity |
|
47 | - * |
|
48 | - * @param string $app |
|
49 | - * @return IEvent |
|
50 | - * @throws \InvalidArgumentException if the app id is invalid |
|
51 | - * @since 8.2.0 |
|
52 | - */ |
|
53 | - public function setApp(string $app): self; |
|
54 | - |
|
55 | - /** |
|
56 | - * Set the type of the activity |
|
57 | - * |
|
58 | - * @param string $type |
|
59 | - * @return IEvent |
|
60 | - * @throws \InvalidArgumentException if the type is invalid |
|
61 | - * @since 8.2.0 |
|
62 | - */ |
|
63 | - public function setType(string $type): self; |
|
64 | - |
|
65 | - /** |
|
66 | - * Set the affected user of the activity |
|
67 | - * |
|
68 | - * @param string $user |
|
69 | - * @return IEvent |
|
70 | - * @throws \InvalidArgumentException if the affected user is invalid |
|
71 | - * @since 8.2.0 |
|
72 | - */ |
|
73 | - public function setAffectedUser(string $user): self; |
|
74 | - |
|
75 | - /** |
|
76 | - * Set the author of the activity |
|
77 | - * |
|
78 | - * @param string $author |
|
79 | - * @return IEvent |
|
80 | - * @throws \InvalidArgumentException if the author is invalid |
|
81 | - * @since 8.2.0 |
|
82 | - */ |
|
83 | - public function setAuthor(string $author): self; |
|
84 | - |
|
85 | - /** |
|
86 | - * Set the author of the activity |
|
87 | - * |
|
88 | - * @param int $timestamp |
|
89 | - * @return IEvent |
|
90 | - * @throws \InvalidArgumentException if the timestamp is invalid |
|
91 | - * @since 8.2.0 |
|
92 | - */ |
|
93 | - public function setTimestamp(int $timestamp): self; |
|
94 | - |
|
95 | - /** |
|
96 | - * Set the subject of the activity |
|
97 | - * |
|
98 | - * @param string $subject |
|
99 | - * @param array $parameters |
|
100 | - * @return IEvent |
|
101 | - * @throws \InvalidArgumentException if the subject or parameters are invalid |
|
102 | - * @since 8.2.0 |
|
103 | - */ |
|
104 | - public function setSubject(string $subject, array $parameters = []): self; |
|
105 | - |
|
106 | - /** |
|
107 | - * Set a parsed subject |
|
108 | - * |
|
109 | - * HTML is not allowed in the parsed subject and will be escaped |
|
110 | - * automatically by the clients. You can use the RichObjectString system |
|
111 | - * provided by the Nextcloud server to highlight important parameters via |
|
112 | - * the setRichSubject method, but make sure, that a plain text message is |
|
113 | - * always set via setParsedSubject, to support clients which can not handle |
|
114 | - * rich strings. |
|
115 | - * |
|
116 | - * See https://github.com/nextcloud/server/issues/1706 for more information. |
|
117 | - * |
|
118 | - * @param string $subject |
|
119 | - * @return $this |
|
120 | - * @throws \InvalidArgumentException if the subject is invalid |
|
121 | - * @since 11.0.0 |
|
122 | - */ |
|
123 | - public function setParsedSubject(string $subject): self; |
|
124 | - |
|
125 | - /** |
|
126 | - * @return string |
|
127 | - * @since 11.0.0 |
|
128 | - */ |
|
129 | - public function getParsedSubject(): string; |
|
130 | - |
|
131 | - /** |
|
132 | - * Set a RichObjectString subject |
|
133 | - * |
|
134 | - * HTML is not allowed in the rich subject and will be escaped automatically |
|
135 | - * by the clients, but you can use the RichObjectString system provided by |
|
136 | - * the Nextcloud server to highlight important parameters. |
|
137 | - * Also make sure, that a plain text subject is always set via |
|
138 | - * setParsedSubject, to support clients which can not handle rich strings. |
|
139 | - * |
|
140 | - * See https://github.com/nextcloud/server/issues/1706 for more information. |
|
141 | - * |
|
142 | - * @param string $subject |
|
143 | - * @param array $parameters |
|
144 | - * @return $this |
|
145 | - * @throws \InvalidArgumentException if the subject or parameters are invalid |
|
146 | - * @since 11.0.0 |
|
147 | - */ |
|
148 | - public function setRichSubject(string $subject, array $parameters = []): self; |
|
149 | - |
|
150 | - /** |
|
151 | - * @return string |
|
152 | - * @since 11.0.0 |
|
153 | - */ |
|
154 | - public function getRichSubject(): string; |
|
155 | - |
|
156 | - /** |
|
157 | - * @return array[] |
|
158 | - * @since 11.0.0 |
|
159 | - */ |
|
160 | - public function getRichSubjectParameters(): array; |
|
161 | - |
|
162 | - /** |
|
163 | - * Set the message of the activity |
|
164 | - * |
|
165 | - * @param string $message |
|
166 | - * @param array $parameters |
|
167 | - * @return IEvent |
|
168 | - * @throws \InvalidArgumentException if the message or parameters are invalid |
|
169 | - * @since 8.2.0 |
|
170 | - */ |
|
171 | - public function setMessage(string $message, array $parameters = []): self; |
|
172 | - |
|
173 | - /** |
|
174 | - * Set a parsed message |
|
175 | - * |
|
176 | - * HTML is not allowed in the parsed message and will be escaped |
|
177 | - * automatically by the clients. You can use the RichObjectString system |
|
178 | - * provided by the Nextcloud server to highlight important parameters via |
|
179 | - * the setRichMessage method, but make sure, that a plain text message is |
|
180 | - * always set via setParsedMessage, to support clients which can not handle |
|
181 | - * rich strings. |
|
182 | - * |
|
183 | - * See https://github.com/nextcloud/server/issues/1706 for more information. |
|
184 | - * |
|
185 | - * @param string $message |
|
186 | - * @return $this |
|
187 | - * @throws \InvalidArgumentException if the message is invalid |
|
188 | - * @since 11.0.0 |
|
189 | - */ |
|
190 | - public function setParsedMessage(string $message): self; |
|
191 | - |
|
192 | - /** |
|
193 | - * @return string |
|
194 | - * @since 11.0.0 |
|
195 | - */ |
|
196 | - public function getParsedMessage(): string; |
|
197 | - |
|
198 | - /** |
|
199 | - * Set a RichObjectString message |
|
200 | - * |
|
201 | - * HTML is not allowed in the rich message and will be escaped automatically |
|
202 | - * by the clients, but you can use the RichObjectString system provided by |
|
203 | - * the Nextcloud server to highlight important parameters. |
|
204 | - * Also make sure, that a plain text message is always set via |
|
205 | - * setParsedMessage, to support clients which can not handle rich strings. |
|
206 | - * |
|
207 | - * See https://github.com/nextcloud/server/issues/1706 for more information. |
|
208 | - * |
|
209 | - * @param string $message |
|
210 | - * @param array $parameters |
|
211 | - * @return $this |
|
212 | - * @throws \InvalidArgumentException if the message or parameters are invalid |
|
213 | - * @since 11.0.0 |
|
214 | - */ |
|
215 | - public function setRichMessage(string $message, array $parameters = []): self; |
|
216 | - |
|
217 | - /** |
|
218 | - * @return string |
|
219 | - * @since 11.0.0 |
|
220 | - */ |
|
221 | - public function getRichMessage(): string; |
|
222 | - |
|
223 | - /** |
|
224 | - * @return array[] |
|
225 | - * @since 11.0.0 |
|
226 | - */ |
|
227 | - public function getRichMessageParameters(): array; |
|
228 | - |
|
229 | - /** |
|
230 | - * Set the object of the activity |
|
231 | - * |
|
232 | - * @param string $objectType |
|
233 | - * @param int $objectId |
|
234 | - * @param string $objectName |
|
235 | - * @return IEvent |
|
236 | - * @throws \InvalidArgumentException if the object is invalid |
|
237 | - * @since 8.2.0 |
|
238 | - */ |
|
239 | - public function setObject(string $objectType, int $objectId, string $objectName = ''): self; |
|
240 | - |
|
241 | - /** |
|
242 | - * Set the link of the activity |
|
243 | - * |
|
244 | - * @param string $link |
|
245 | - * @return IEvent |
|
246 | - * @throws \InvalidArgumentException if the link is invalid |
|
247 | - * @since 8.2.0 |
|
248 | - */ |
|
249 | - public function setLink(string $link): self; |
|
250 | - |
|
251 | - /** |
|
252 | - * @return string |
|
253 | - * @since 8.2.0 |
|
254 | - */ |
|
255 | - public function getApp(): string; |
|
256 | - |
|
257 | - /** |
|
258 | - * @return string |
|
259 | - * @since 8.2.0 |
|
260 | - */ |
|
261 | - public function getType(): string; |
|
262 | - |
|
263 | - /** |
|
264 | - * @return string |
|
265 | - * @since 8.2.0 |
|
266 | - */ |
|
267 | - public function getAffectedUser(): string; |
|
268 | - |
|
269 | - /** |
|
270 | - * @return string |
|
271 | - * @since 8.2.0 |
|
272 | - */ |
|
273 | - public function getAuthor(): string; |
|
274 | - |
|
275 | - /** |
|
276 | - * @return int |
|
277 | - * @since 8.2.0 |
|
278 | - */ |
|
279 | - public function getTimestamp(): int; |
|
280 | - |
|
281 | - /** |
|
282 | - * @return string |
|
283 | - * @since 8.2.0 |
|
284 | - */ |
|
285 | - public function getSubject(): string; |
|
286 | - |
|
287 | - /** |
|
288 | - * @return array |
|
289 | - * @since 8.2.0 |
|
290 | - */ |
|
291 | - public function getSubjectParameters(): array; |
|
292 | - |
|
293 | - /** |
|
294 | - * @return string |
|
295 | - * @since 8.2.0 |
|
296 | - */ |
|
297 | - public function getMessage(): string; |
|
298 | - |
|
299 | - /** |
|
300 | - * @return array |
|
301 | - * @since 8.2.0 |
|
302 | - */ |
|
303 | - public function getMessageParameters(): array; |
|
304 | - |
|
305 | - /** |
|
306 | - * @return string |
|
307 | - * @since 8.2.0 |
|
308 | - */ |
|
309 | - public function getObjectType(): string; |
|
310 | - |
|
311 | - /** |
|
312 | - * @return int |
|
313 | - * @since 8.2.0 |
|
314 | - */ |
|
315 | - public function getObjectId(): int; |
|
316 | - |
|
317 | - /** |
|
318 | - * @return string |
|
319 | - * @since 8.2.0 |
|
320 | - */ |
|
321 | - public function getObjectName(): string; |
|
322 | - |
|
323 | - /** |
|
324 | - * @return string |
|
325 | - * @since 8.2.0 |
|
326 | - */ |
|
327 | - public function getLink(): string; |
|
328 | - |
|
329 | - /** |
|
330 | - * @param string $icon |
|
331 | - * @return $this |
|
332 | - * @throws \InvalidArgumentException if the icon is invalid |
|
333 | - * @since 11.0.0 |
|
334 | - */ |
|
335 | - public function setIcon(string $icon): self; |
|
336 | - |
|
337 | - /** |
|
338 | - * @return string |
|
339 | - * @since 11.0.0 |
|
340 | - */ |
|
341 | - public function getIcon(): string; |
|
342 | - |
|
343 | - /** |
|
344 | - * @param IEvent $child |
|
345 | - * @return $this |
|
346 | - * @since 11.0.0 - Since 15.0.0 returns $this |
|
347 | - */ |
|
348 | - public function setChildEvent(IEvent $child): self; |
|
349 | - |
|
350 | - /** |
|
351 | - * @return IEvent|null |
|
352 | - * @since 11.0.0 |
|
353 | - */ |
|
354 | - public function getChildEvent(); |
|
355 | - |
|
356 | - /** |
|
357 | - * @return bool |
|
358 | - * @since 11.0.0 |
|
359 | - */ |
|
360 | - public function isValid(): bool; |
|
361 | - |
|
362 | - /** |
|
363 | - * @return bool |
|
364 | - * @since 11.0.0 |
|
365 | - */ |
|
366 | - public function isValidParsed(): bool; |
|
367 | - |
|
368 | - /** |
|
369 | - * Set whether or not a notification should be automatically generated for this activity. |
|
370 | - * |
|
371 | - * Set this to `false` if the app already generates a notification for the event. |
|
372 | - * |
|
373 | - * @param bool $generate |
|
374 | - * @return IEvent |
|
375 | - * @since 20.0.0 |
|
376 | - */ |
|
377 | - public function setGenerateNotification(bool $generate): self; |
|
378 | - |
|
379 | - /** |
|
380 | - * whether or not a notification should be automatically generated for this activity. |
|
381 | - * |
|
382 | - * @return bool |
|
383 | - * @since 20.0.0 |
|
384 | - */ |
|
385 | - public function getGenerateNotification(): bool; |
|
45 | + /** |
|
46 | + * Set the app of the activity |
|
47 | + * |
|
48 | + * @param string $app |
|
49 | + * @return IEvent |
|
50 | + * @throws \InvalidArgumentException if the app id is invalid |
|
51 | + * @since 8.2.0 |
|
52 | + */ |
|
53 | + public function setApp(string $app): self; |
|
54 | + |
|
55 | + /** |
|
56 | + * Set the type of the activity |
|
57 | + * |
|
58 | + * @param string $type |
|
59 | + * @return IEvent |
|
60 | + * @throws \InvalidArgumentException if the type is invalid |
|
61 | + * @since 8.2.0 |
|
62 | + */ |
|
63 | + public function setType(string $type): self; |
|
64 | + |
|
65 | + /** |
|
66 | + * Set the affected user of the activity |
|
67 | + * |
|
68 | + * @param string $user |
|
69 | + * @return IEvent |
|
70 | + * @throws \InvalidArgumentException if the affected user is invalid |
|
71 | + * @since 8.2.0 |
|
72 | + */ |
|
73 | + public function setAffectedUser(string $user): self; |
|
74 | + |
|
75 | + /** |
|
76 | + * Set the author of the activity |
|
77 | + * |
|
78 | + * @param string $author |
|
79 | + * @return IEvent |
|
80 | + * @throws \InvalidArgumentException if the author is invalid |
|
81 | + * @since 8.2.0 |
|
82 | + */ |
|
83 | + public function setAuthor(string $author): self; |
|
84 | + |
|
85 | + /** |
|
86 | + * Set the author of the activity |
|
87 | + * |
|
88 | + * @param int $timestamp |
|
89 | + * @return IEvent |
|
90 | + * @throws \InvalidArgumentException if the timestamp is invalid |
|
91 | + * @since 8.2.0 |
|
92 | + */ |
|
93 | + public function setTimestamp(int $timestamp): self; |
|
94 | + |
|
95 | + /** |
|
96 | + * Set the subject of the activity |
|
97 | + * |
|
98 | + * @param string $subject |
|
99 | + * @param array $parameters |
|
100 | + * @return IEvent |
|
101 | + * @throws \InvalidArgumentException if the subject or parameters are invalid |
|
102 | + * @since 8.2.0 |
|
103 | + */ |
|
104 | + public function setSubject(string $subject, array $parameters = []): self; |
|
105 | + |
|
106 | + /** |
|
107 | + * Set a parsed subject |
|
108 | + * |
|
109 | + * HTML is not allowed in the parsed subject and will be escaped |
|
110 | + * automatically by the clients. You can use the RichObjectString system |
|
111 | + * provided by the Nextcloud server to highlight important parameters via |
|
112 | + * the setRichSubject method, but make sure, that a plain text message is |
|
113 | + * always set via setParsedSubject, to support clients which can not handle |
|
114 | + * rich strings. |
|
115 | + * |
|
116 | + * See https://github.com/nextcloud/server/issues/1706 for more information. |
|
117 | + * |
|
118 | + * @param string $subject |
|
119 | + * @return $this |
|
120 | + * @throws \InvalidArgumentException if the subject is invalid |
|
121 | + * @since 11.0.0 |
|
122 | + */ |
|
123 | + public function setParsedSubject(string $subject): self; |
|
124 | + |
|
125 | + /** |
|
126 | + * @return string |
|
127 | + * @since 11.0.0 |
|
128 | + */ |
|
129 | + public function getParsedSubject(): string; |
|
130 | + |
|
131 | + /** |
|
132 | + * Set a RichObjectString subject |
|
133 | + * |
|
134 | + * HTML is not allowed in the rich subject and will be escaped automatically |
|
135 | + * by the clients, but you can use the RichObjectString system provided by |
|
136 | + * the Nextcloud server to highlight important parameters. |
|
137 | + * Also make sure, that a plain text subject is always set via |
|
138 | + * setParsedSubject, to support clients which can not handle rich strings. |
|
139 | + * |
|
140 | + * See https://github.com/nextcloud/server/issues/1706 for more information. |
|
141 | + * |
|
142 | + * @param string $subject |
|
143 | + * @param array $parameters |
|
144 | + * @return $this |
|
145 | + * @throws \InvalidArgumentException if the subject or parameters are invalid |
|
146 | + * @since 11.0.0 |
|
147 | + */ |
|
148 | + public function setRichSubject(string $subject, array $parameters = []): self; |
|
149 | + |
|
150 | + /** |
|
151 | + * @return string |
|
152 | + * @since 11.0.0 |
|
153 | + */ |
|
154 | + public function getRichSubject(): string; |
|
155 | + |
|
156 | + /** |
|
157 | + * @return array[] |
|
158 | + * @since 11.0.0 |
|
159 | + */ |
|
160 | + public function getRichSubjectParameters(): array; |
|
161 | + |
|
162 | + /** |
|
163 | + * Set the message of the activity |
|
164 | + * |
|
165 | + * @param string $message |
|
166 | + * @param array $parameters |
|
167 | + * @return IEvent |
|
168 | + * @throws \InvalidArgumentException if the message or parameters are invalid |
|
169 | + * @since 8.2.0 |
|
170 | + */ |
|
171 | + public function setMessage(string $message, array $parameters = []): self; |
|
172 | + |
|
173 | + /** |
|
174 | + * Set a parsed message |
|
175 | + * |
|
176 | + * HTML is not allowed in the parsed message and will be escaped |
|
177 | + * automatically by the clients. You can use the RichObjectString system |
|
178 | + * provided by the Nextcloud server to highlight important parameters via |
|
179 | + * the setRichMessage method, but make sure, that a plain text message is |
|
180 | + * always set via setParsedMessage, to support clients which can not handle |
|
181 | + * rich strings. |
|
182 | + * |
|
183 | + * See https://github.com/nextcloud/server/issues/1706 for more information. |
|
184 | + * |
|
185 | + * @param string $message |
|
186 | + * @return $this |
|
187 | + * @throws \InvalidArgumentException if the message is invalid |
|
188 | + * @since 11.0.0 |
|
189 | + */ |
|
190 | + public function setParsedMessage(string $message): self; |
|
191 | + |
|
192 | + /** |
|
193 | + * @return string |
|
194 | + * @since 11.0.0 |
|
195 | + */ |
|
196 | + public function getParsedMessage(): string; |
|
197 | + |
|
198 | + /** |
|
199 | + * Set a RichObjectString message |
|
200 | + * |
|
201 | + * HTML is not allowed in the rich message and will be escaped automatically |
|
202 | + * by the clients, but you can use the RichObjectString system provided by |
|
203 | + * the Nextcloud server to highlight important parameters. |
|
204 | + * Also make sure, that a plain text message is always set via |
|
205 | + * setParsedMessage, to support clients which can not handle rich strings. |
|
206 | + * |
|
207 | + * See https://github.com/nextcloud/server/issues/1706 for more information. |
|
208 | + * |
|
209 | + * @param string $message |
|
210 | + * @param array $parameters |
|
211 | + * @return $this |
|
212 | + * @throws \InvalidArgumentException if the message or parameters are invalid |
|
213 | + * @since 11.0.0 |
|
214 | + */ |
|
215 | + public function setRichMessage(string $message, array $parameters = []): self; |
|
216 | + |
|
217 | + /** |
|
218 | + * @return string |
|
219 | + * @since 11.0.0 |
|
220 | + */ |
|
221 | + public function getRichMessage(): string; |
|
222 | + |
|
223 | + /** |
|
224 | + * @return array[] |
|
225 | + * @since 11.0.0 |
|
226 | + */ |
|
227 | + public function getRichMessageParameters(): array; |
|
228 | + |
|
229 | + /** |
|
230 | + * Set the object of the activity |
|
231 | + * |
|
232 | + * @param string $objectType |
|
233 | + * @param int $objectId |
|
234 | + * @param string $objectName |
|
235 | + * @return IEvent |
|
236 | + * @throws \InvalidArgumentException if the object is invalid |
|
237 | + * @since 8.2.0 |
|
238 | + */ |
|
239 | + public function setObject(string $objectType, int $objectId, string $objectName = ''): self; |
|
240 | + |
|
241 | + /** |
|
242 | + * Set the link of the activity |
|
243 | + * |
|
244 | + * @param string $link |
|
245 | + * @return IEvent |
|
246 | + * @throws \InvalidArgumentException if the link is invalid |
|
247 | + * @since 8.2.0 |
|
248 | + */ |
|
249 | + public function setLink(string $link): self; |
|
250 | + |
|
251 | + /** |
|
252 | + * @return string |
|
253 | + * @since 8.2.0 |
|
254 | + */ |
|
255 | + public function getApp(): string; |
|
256 | + |
|
257 | + /** |
|
258 | + * @return string |
|
259 | + * @since 8.2.0 |
|
260 | + */ |
|
261 | + public function getType(): string; |
|
262 | + |
|
263 | + /** |
|
264 | + * @return string |
|
265 | + * @since 8.2.0 |
|
266 | + */ |
|
267 | + public function getAffectedUser(): string; |
|
268 | + |
|
269 | + /** |
|
270 | + * @return string |
|
271 | + * @since 8.2.0 |
|
272 | + */ |
|
273 | + public function getAuthor(): string; |
|
274 | + |
|
275 | + /** |
|
276 | + * @return int |
|
277 | + * @since 8.2.0 |
|
278 | + */ |
|
279 | + public function getTimestamp(): int; |
|
280 | + |
|
281 | + /** |
|
282 | + * @return string |
|
283 | + * @since 8.2.0 |
|
284 | + */ |
|
285 | + public function getSubject(): string; |
|
286 | + |
|
287 | + /** |
|
288 | + * @return array |
|
289 | + * @since 8.2.0 |
|
290 | + */ |
|
291 | + public function getSubjectParameters(): array; |
|
292 | + |
|
293 | + /** |
|
294 | + * @return string |
|
295 | + * @since 8.2.0 |
|
296 | + */ |
|
297 | + public function getMessage(): string; |
|
298 | + |
|
299 | + /** |
|
300 | + * @return array |
|
301 | + * @since 8.2.0 |
|
302 | + */ |
|
303 | + public function getMessageParameters(): array; |
|
304 | + |
|
305 | + /** |
|
306 | + * @return string |
|
307 | + * @since 8.2.0 |
|
308 | + */ |
|
309 | + public function getObjectType(): string; |
|
310 | + |
|
311 | + /** |
|
312 | + * @return int |
|
313 | + * @since 8.2.0 |
|
314 | + */ |
|
315 | + public function getObjectId(): int; |
|
316 | + |
|
317 | + /** |
|
318 | + * @return string |
|
319 | + * @since 8.2.0 |
|
320 | + */ |
|
321 | + public function getObjectName(): string; |
|
322 | + |
|
323 | + /** |
|
324 | + * @return string |
|
325 | + * @since 8.2.0 |
|
326 | + */ |
|
327 | + public function getLink(): string; |
|
328 | + |
|
329 | + /** |
|
330 | + * @param string $icon |
|
331 | + * @return $this |
|
332 | + * @throws \InvalidArgumentException if the icon is invalid |
|
333 | + * @since 11.0.0 |
|
334 | + */ |
|
335 | + public function setIcon(string $icon): self; |
|
336 | + |
|
337 | + /** |
|
338 | + * @return string |
|
339 | + * @since 11.0.0 |
|
340 | + */ |
|
341 | + public function getIcon(): string; |
|
342 | + |
|
343 | + /** |
|
344 | + * @param IEvent $child |
|
345 | + * @return $this |
|
346 | + * @since 11.0.0 - Since 15.0.0 returns $this |
|
347 | + */ |
|
348 | + public function setChildEvent(IEvent $child): self; |
|
349 | + |
|
350 | + /** |
|
351 | + * @return IEvent|null |
|
352 | + * @since 11.0.0 |
|
353 | + */ |
|
354 | + public function getChildEvent(); |
|
355 | + |
|
356 | + /** |
|
357 | + * @return bool |
|
358 | + * @since 11.0.0 |
|
359 | + */ |
|
360 | + public function isValid(): bool; |
|
361 | + |
|
362 | + /** |
|
363 | + * @return bool |
|
364 | + * @since 11.0.0 |
|
365 | + */ |
|
366 | + public function isValidParsed(): bool; |
|
367 | + |
|
368 | + /** |
|
369 | + * Set whether or not a notification should be automatically generated for this activity. |
|
370 | + * |
|
371 | + * Set this to `false` if the app already generates a notification for the event. |
|
372 | + * |
|
373 | + * @param bool $generate |
|
374 | + * @return IEvent |
|
375 | + * @since 20.0.0 |
|
376 | + */ |
|
377 | + public function setGenerateNotification(bool $generate): self; |
|
378 | + |
|
379 | + /** |
|
380 | + * whether or not a notification should be automatically generated for this activity. |
|
381 | + * |
|
382 | + * @return bool |
|
383 | + * @since 20.0.0 |
|
384 | + */ |
|
385 | + public function getGenerateNotification(): bool; |
|
386 | 386 | } |
@@ -35,141 +35,141 @@ |
||
35 | 35 | * @since 6.0.0 |
36 | 36 | */ |
37 | 37 | interface IManager { |
38 | - /** |
|
39 | - * Generates a new IEvent object |
|
40 | - * |
|
41 | - * Make sure to call at least the following methods before sending it to the |
|
42 | - * app with via the publish() method: |
|
43 | - * - setApp() |
|
44 | - * - setType() |
|
45 | - * - setAffectedUser() |
|
46 | - * - setSubject() |
|
47 | - * |
|
48 | - * @return IEvent |
|
49 | - * @since 8.2.0 |
|
50 | - */ |
|
51 | - public function generateEvent(): IEvent; |
|
52 | - |
|
53 | - /** |
|
54 | - * Publish an event to the activity consumers |
|
55 | - * |
|
56 | - * Make sure to call at least the following methods before sending an Event: |
|
57 | - * - setApp() |
|
58 | - * - setType() |
|
59 | - * - setAffectedUser() |
|
60 | - * - setSubject() |
|
61 | - * |
|
62 | - * @param IEvent $event |
|
63 | - * @throws \BadMethodCallException if required values have not been set |
|
64 | - * @since 8.2.0 |
|
65 | - */ |
|
66 | - public function publish(IEvent $event): void; |
|
67 | - |
|
68 | - /** |
|
69 | - * In order to improve lazy loading a closure can be registered which will be called in case |
|
70 | - * activity consumers are actually requested |
|
71 | - * |
|
72 | - * $callable has to return an instance of \OCP\Activity\IConsumer |
|
73 | - * |
|
74 | - * @param \Closure $callable |
|
75 | - * @since 6.0.0 |
|
76 | - */ |
|
77 | - public function registerConsumer(\Closure $callable): void; |
|
78 | - |
|
79 | - /** |
|
80 | - * @param string $filter Class must implement OCA\Activity\IFilter |
|
81 | - * @since 11.0.0 |
|
82 | - */ |
|
83 | - public function registerFilter(string $filter): void; |
|
84 | - |
|
85 | - /** |
|
86 | - * @return IFilter[] |
|
87 | - * @since 11.0.0 |
|
88 | - */ |
|
89 | - public function getFilters(): array; |
|
90 | - |
|
91 | - /** |
|
92 | - * @param string $id |
|
93 | - * @return IFilter |
|
94 | - * @throws \InvalidArgumentException when the filter was not found |
|
95 | - * @since 11.0.0 |
|
96 | - */ |
|
97 | - public function getFilterById(string $id): IFilter; |
|
98 | - |
|
99 | - /** |
|
100 | - * @param string $setting Class must implement OCA\Activity\ISetting |
|
101 | - * @since 11.0.0 |
|
102 | - */ |
|
103 | - public function registerSetting(string $setting): void; |
|
104 | - |
|
105 | - /** |
|
106 | - * @return ActivitySettings[] |
|
107 | - * @since 11.0.0 |
|
108 | - */ |
|
109 | - public function getSettings(): array; |
|
110 | - |
|
111 | - /** |
|
112 | - * @param string $provider Class must implement OCA\Activity\IProvider |
|
113 | - * @since 11.0.0 |
|
114 | - */ |
|
115 | - public function registerProvider(string $provider): void; |
|
116 | - |
|
117 | - /** |
|
118 | - * @return IProvider[] |
|
119 | - * @since 11.0.0 |
|
120 | - */ |
|
121 | - public function getProviders(): array; |
|
122 | - |
|
123 | - /** |
|
124 | - * @param string $id |
|
125 | - * @return ActivitySettings |
|
126 | - * @throws \InvalidArgumentException when the setting was not found |
|
127 | - * @since 11.0.0 |
|
128 | - */ |
|
129 | - public function getSettingById(string $id): ActivitySettings; |
|
130 | - |
|
131 | - /** |
|
132 | - * @param string $type |
|
133 | - * @param int $id |
|
134 | - * @since 8.2.0 |
|
135 | - */ |
|
136 | - public function setFormattingObject(string $type, int $id): void; |
|
137 | - |
|
138 | - /** |
|
139 | - * @return bool |
|
140 | - * @since 8.2.0 |
|
141 | - */ |
|
142 | - public function isFormattingFilteredObject(): bool; |
|
143 | - |
|
144 | - /** |
|
145 | - * @param bool $status Set to true, when parsing events should not use SVG icons |
|
146 | - * @since 12.0.1 |
|
147 | - */ |
|
148 | - public function setRequirePNG(bool $status): void; |
|
149 | - |
|
150 | - /** |
|
151 | - * @return bool |
|
152 | - * @since 12.0.1 |
|
153 | - */ |
|
154 | - public function getRequirePNG(): bool; |
|
155 | - |
|
156 | - /** |
|
157 | - * Set the user we need to use |
|
158 | - * |
|
159 | - * @param string|null $currentUserId |
|
160 | - * @throws \UnexpectedValueException If the user is invalid |
|
161 | - * @since 9.0.1 |
|
162 | - */ |
|
163 | - public function setCurrentUserId(string $currentUserId = null): void; |
|
164 | - |
|
165 | - /** |
|
166 | - * Get the user we need to use |
|
167 | - * |
|
168 | - * Either the user is logged in, or we try to get it from the token |
|
169 | - * |
|
170 | - * @return string |
|
171 | - * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
172 | - * @since 8.1.0 |
|
173 | - */ |
|
174 | - public function getCurrentUserId(): string; |
|
38 | + /** |
|
39 | + * Generates a new IEvent object |
|
40 | + * |
|
41 | + * Make sure to call at least the following methods before sending it to the |
|
42 | + * app with via the publish() method: |
|
43 | + * - setApp() |
|
44 | + * - setType() |
|
45 | + * - setAffectedUser() |
|
46 | + * - setSubject() |
|
47 | + * |
|
48 | + * @return IEvent |
|
49 | + * @since 8.2.0 |
|
50 | + */ |
|
51 | + public function generateEvent(): IEvent; |
|
52 | + |
|
53 | + /** |
|
54 | + * Publish an event to the activity consumers |
|
55 | + * |
|
56 | + * Make sure to call at least the following methods before sending an Event: |
|
57 | + * - setApp() |
|
58 | + * - setType() |
|
59 | + * - setAffectedUser() |
|
60 | + * - setSubject() |
|
61 | + * |
|
62 | + * @param IEvent $event |
|
63 | + * @throws \BadMethodCallException if required values have not been set |
|
64 | + * @since 8.2.0 |
|
65 | + */ |
|
66 | + public function publish(IEvent $event): void; |
|
67 | + |
|
68 | + /** |
|
69 | + * In order to improve lazy loading a closure can be registered which will be called in case |
|
70 | + * activity consumers are actually requested |
|
71 | + * |
|
72 | + * $callable has to return an instance of \OCP\Activity\IConsumer |
|
73 | + * |
|
74 | + * @param \Closure $callable |
|
75 | + * @since 6.0.0 |
|
76 | + */ |
|
77 | + public function registerConsumer(\Closure $callable): void; |
|
78 | + |
|
79 | + /** |
|
80 | + * @param string $filter Class must implement OCA\Activity\IFilter |
|
81 | + * @since 11.0.0 |
|
82 | + */ |
|
83 | + public function registerFilter(string $filter): void; |
|
84 | + |
|
85 | + /** |
|
86 | + * @return IFilter[] |
|
87 | + * @since 11.0.0 |
|
88 | + */ |
|
89 | + public function getFilters(): array; |
|
90 | + |
|
91 | + /** |
|
92 | + * @param string $id |
|
93 | + * @return IFilter |
|
94 | + * @throws \InvalidArgumentException when the filter was not found |
|
95 | + * @since 11.0.0 |
|
96 | + */ |
|
97 | + public function getFilterById(string $id): IFilter; |
|
98 | + |
|
99 | + /** |
|
100 | + * @param string $setting Class must implement OCA\Activity\ISetting |
|
101 | + * @since 11.0.0 |
|
102 | + */ |
|
103 | + public function registerSetting(string $setting): void; |
|
104 | + |
|
105 | + /** |
|
106 | + * @return ActivitySettings[] |
|
107 | + * @since 11.0.0 |
|
108 | + */ |
|
109 | + public function getSettings(): array; |
|
110 | + |
|
111 | + /** |
|
112 | + * @param string $provider Class must implement OCA\Activity\IProvider |
|
113 | + * @since 11.0.0 |
|
114 | + */ |
|
115 | + public function registerProvider(string $provider): void; |
|
116 | + |
|
117 | + /** |
|
118 | + * @return IProvider[] |
|
119 | + * @since 11.0.0 |
|
120 | + */ |
|
121 | + public function getProviders(): array; |
|
122 | + |
|
123 | + /** |
|
124 | + * @param string $id |
|
125 | + * @return ActivitySettings |
|
126 | + * @throws \InvalidArgumentException when the setting was not found |
|
127 | + * @since 11.0.0 |
|
128 | + */ |
|
129 | + public function getSettingById(string $id): ActivitySettings; |
|
130 | + |
|
131 | + /** |
|
132 | + * @param string $type |
|
133 | + * @param int $id |
|
134 | + * @since 8.2.0 |
|
135 | + */ |
|
136 | + public function setFormattingObject(string $type, int $id): void; |
|
137 | + |
|
138 | + /** |
|
139 | + * @return bool |
|
140 | + * @since 8.2.0 |
|
141 | + */ |
|
142 | + public function isFormattingFilteredObject(): bool; |
|
143 | + |
|
144 | + /** |
|
145 | + * @param bool $status Set to true, when parsing events should not use SVG icons |
|
146 | + * @since 12.0.1 |
|
147 | + */ |
|
148 | + public function setRequirePNG(bool $status): void; |
|
149 | + |
|
150 | + /** |
|
151 | + * @return bool |
|
152 | + * @since 12.0.1 |
|
153 | + */ |
|
154 | + public function getRequirePNG(): bool; |
|
155 | + |
|
156 | + /** |
|
157 | + * Set the user we need to use |
|
158 | + * |
|
159 | + * @param string|null $currentUserId |
|
160 | + * @throws \UnexpectedValueException If the user is invalid |
|
161 | + * @since 9.0.1 |
|
162 | + */ |
|
163 | + public function setCurrentUserId(string $currentUserId = null): void; |
|
164 | + |
|
165 | + /** |
|
166 | + * Get the user we need to use |
|
167 | + * |
|
168 | + * Either the user is logged in, or we try to get it from the token |
|
169 | + * |
|
170 | + * @return string |
|
171 | + * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
172 | + * @since 8.1.0 |
|
173 | + */ |
|
174 | + public function getCurrentUserId(): string; |
|
175 | 175 | } |
@@ -27,75 +27,75 @@ |
||
27 | 27 | * @since 20.0.0 |
28 | 28 | */ |
29 | 29 | abstract class ActivitySettings implements ISetting { |
30 | - /** |
|
31 | - * @return string Lowercase a-z and underscore only identifier |
|
32 | - * @since 20.0.0 |
|
33 | - */ |
|
34 | - abstract public function getIdentifier(); |
|
30 | + /** |
|
31 | + * @return string Lowercase a-z and underscore only identifier |
|
32 | + * @since 20.0.0 |
|
33 | + */ |
|
34 | + abstract public function getIdentifier(); |
|
35 | 35 | |
36 | - /** |
|
37 | - * @return string A translated string |
|
38 | - * @since 20.0.0 |
|
39 | - */ |
|
40 | - abstract public function getName(); |
|
36 | + /** |
|
37 | + * @return string A translated string |
|
38 | + * @since 20.0.0 |
|
39 | + */ |
|
40 | + abstract public function getName(); |
|
41 | 41 | |
42 | - /** |
|
43 | - * @return int whether the filter should be rather on the top or bottom of |
|
44 | - * the admin section. The filters are arranged in ascending order of the |
|
45 | - * priority values. It is required to return a value between 0 and 100. |
|
46 | - * @since 20.0.0 |
|
47 | - */ |
|
48 | - abstract public function getPriority(); |
|
42 | + /** |
|
43 | + * @return int whether the filter should be rather on the top or bottom of |
|
44 | + * the admin section. The filters are arranged in ascending order of the |
|
45 | + * priority values. It is required to return a value between 0 and 100. |
|
46 | + * @since 20.0.0 |
|
47 | + */ |
|
48 | + abstract public function getPriority(); |
|
49 | 49 | |
50 | - /** |
|
51 | - * @return bool True when the option can be changed for the mail |
|
52 | - * @since 20.0.0 |
|
53 | - */ |
|
54 | - public function canChangeMail() { |
|
55 | - return true; |
|
56 | - } |
|
50 | + /** |
|
51 | + * @return bool True when the option can be changed for the mail |
|
52 | + * @since 20.0.0 |
|
53 | + */ |
|
54 | + public function canChangeMail() { |
|
55 | + return true; |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * @return bool True when the option can be changed for the notification |
|
60 | - * @since 20.0.0 |
|
61 | - */ |
|
62 | - public function canChangeNotification() { |
|
63 | - return true; |
|
64 | - } |
|
58 | + /** |
|
59 | + * @return bool True when the option can be changed for the notification |
|
60 | + * @since 20.0.0 |
|
61 | + */ |
|
62 | + public function canChangeNotification() { |
|
63 | + return true; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @return bool Whether or not an activity email should be send by default |
|
68 | - * @since 20.0.0 |
|
69 | - */ |
|
70 | - public function isDefaultEnabledMail() { |
|
71 | - return false; |
|
72 | - } |
|
66 | + /** |
|
67 | + * @return bool Whether or not an activity email should be send by default |
|
68 | + * @since 20.0.0 |
|
69 | + */ |
|
70 | + public function isDefaultEnabledMail() { |
|
71 | + return false; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @return bool Whether or not an activity notification should be send by default |
|
76 | - * @since 20.0.0 |
|
77 | - */ |
|
78 | - public function isDefaultEnabledNotification() { |
|
79 | - return $this->isDefaultEnabledMail() && !$this->canChangeMail(); |
|
80 | - } |
|
74 | + /** |
|
75 | + * @return bool Whether or not an activity notification should be send by default |
|
76 | + * @since 20.0.0 |
|
77 | + */ |
|
78 | + public function isDefaultEnabledNotification() { |
|
79 | + return $this->isDefaultEnabledMail() && !$this->canChangeMail(); |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * Left in for backwards compatibility |
|
84 | - * |
|
85 | - * @return bool |
|
86 | - * @since 20.0.0 |
|
87 | - */ |
|
88 | - public function canChangeStream() { |
|
89 | - return false; |
|
90 | - } |
|
82 | + /** |
|
83 | + * Left in for backwards compatibility |
|
84 | + * |
|
85 | + * @return bool |
|
86 | + * @since 20.0.0 |
|
87 | + */ |
|
88 | + public function canChangeStream() { |
|
89 | + return false; |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * Left in for backwards compatibility |
|
94 | - * |
|
95 | - * @return bool |
|
96 | - * @since 20.0.0 |
|
97 | - */ |
|
98 | - public function isDefaultEnabledStream() { |
|
99 | - return true; |
|
100 | - } |
|
92 | + /** |
|
93 | + * Left in for backwards compatibility |
|
94 | + * |
|
95 | + * @return bool |
|
96 | + * @since 20.0.0 |
|
97 | + */ |
|
98 | + public function isDefaultEnabledStream() { |
|
99 | + return true; |
|
100 | + } |
|
101 | 101 | } |