1414use OCA \Libresign \Db \SignRequestMapper ;
1515use OCA \Libresign \Events \SendSignNotificationEvent ;
1616use OCA \Libresign \Events \SignedEvent ;
17+ use OCA \Libresign \Events \SignRequestCanceledEvent ;
1718use OCA \Libresign \Service \AccountService ;
1819use OCA \Libresign \Service \IdentifyMethod \IIdentifyMethod ;
1920use OCP \Activity \Exceptions \UnknownActivityException ;
@@ -42,7 +43,7 @@ public function __construct(
4243 }
4344
4445 public function handle (Event $ event ): void {
45- /** @var SendSignNotificationEvent|SignedEvent $event */
46+ /** @var SendSignNotificationEvent|SignedEvent|SignRequestCanceledEvent $event */
4647 match ($ event ::class) {
4748 SendSignNotificationEvent::class => $ this ->generateNewSignNotificationActivity (
4849 $ event ->getSignRequest (),
@@ -54,6 +55,11 @@ public function handle(Event $event): void {
5455 $ event ->getLibreSignFile (),
5556 $ event ->getIdentifyMethod (),
5657 ),
58+ SignRequestCanceledEvent::class => $ this ->generateCanceledActivity (
59+ $ event ->getSignRequest (),
60+ $ event ->getLibreSignFile (),
61+ $ event ->getIdentifyMethod (),
62+ ),
5763 };
5864 }
5965
@@ -166,6 +172,51 @@ protected function generateSignedEventActivity(
166172 }
167173 }
168174
175+ protected function generateCanceledActivity (
176+ SignRequest $ signRequest ,
177+ FileEntity $ libreSignFile ,
178+ IIdentifyMethod $ identifyMethod ,
179+ ): void {
180+ $ actor = $ this ->userSession ->getUser ();
181+ if (!$ actor instanceof IUser) {
182+ return ;
183+ }
184+ $ actorId = $ actor ->getUID ();
185+
186+ $ event = $ this ->activityManager ->generateEvent ();
187+ try {
188+ $ event
189+ ->setApp (Application::APP_ID )
190+ ->setType (SignRequestCanceledEvent::SIGN_REQUEST_CANCELED )
191+ ->setAuthor ($ actorId )
192+ ->setObject ('signRequest ' , $ signRequest ->getId ())
193+ ->setTimestamp ($ this ->timeFactory ->getTime ())
194+ ->setAffectedUser ($ identifyMethod ->getEntity ()->getIdentifierValue ())
195+ ->setGenerateNotification (false );
196+
197+ $ event ->setSubject ('sign_request_canceled ' , [
198+ 'from ' => $ this ->getUserParameter (
199+ $ actor ->getUID (),
200+ $ actor ->getDisplayName (),
201+ ),
202+ 'file ' => $ this ->getFileParameter ($ signRequest , $ libreSignFile ),
203+ 'signer ' => $ this ->getUserParameter (
204+ $ identifyMethod ->getEntity ()->getIdentifierValue (),
205+ $ signRequest ->getDisplayName (),
206+ ),
207+ 'signRequest ' => [
208+ 'type ' => 'sign-request ' ,
209+ 'id ' => (string )$ signRequest ->getId (),
210+ 'name ' => $ actor ->getDisplayName (),
211+ ],
212+ ]);
213+ $ this ->activityManager ->publish ($ event );
214+ } catch (UnknownActivityException $ e ) {
215+ $ this ->logger ->error ($ e ->getMessage (), ['exception ' => $ e ]);
216+ return ;
217+ }
218+ }
219+
169220 /**
170221 * @return array{type: 'file', id: string, name: string, path: string, link: string}
171222 */
0 commit comments