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 ;
@@ -43,7 +44,7 @@ public function __construct(
4344
4445 #[\Override]
4546 public function handle (Event $ event ): void {
46- /** @var SendSignNotificationEvent|SignedEvent $event */
47+ /** @var SendSignNotificationEvent|SignedEvent|SignRequestCanceledEvent $event */
4748 match ($ event ::class) {
4849 SendSignNotificationEvent::class => $ this ->generateNewSignNotificationActivity (
4950 $ event ->getSignRequest (),
@@ -55,6 +56,11 @@ public function handle(Event $event): void {
5556 $ event ->getLibreSignFile (),
5657 $ event ->getIdentifyMethod (),
5758 ),
59+ SignRequestCanceledEvent::class => $ this ->generateCanceledActivity (
60+ $ event ->getSignRequest (),
61+ $ event ->getLibreSignFile (),
62+ $ event ->getIdentifyMethod (),
63+ ),
5864 };
5965 }
6066
@@ -167,6 +173,51 @@ protected function generateSignedEventActivity(
167173 }
168174 }
169175
176+ protected function generateCanceledActivity (
177+ SignRequest $ signRequest ,
178+ FileEntity $ libreSignFile ,
179+ IIdentifyMethod $ identifyMethod ,
180+ ): void {
181+ $ actor = $ this ->userSession ->getUser ();
182+ if (!$ actor instanceof IUser) {
183+ return ;
184+ }
185+ $ actorId = $ actor ->getUID ();
186+
187+ $ event = $ this ->activityManager ->generateEvent ();
188+ try {
189+ $ event
190+ ->setApp (Application::APP_ID )
191+ ->setType (SignRequestCanceledEvent::SIGN_REQUEST_CANCELED )
192+ ->setAuthor ($ actorId )
193+ ->setObject ('signRequest ' , $ signRequest ->getId ())
194+ ->setTimestamp ($ this ->timeFactory ->getTime ())
195+ ->setAffectedUser ($ identifyMethod ->getEntity ()->getIdentifierValue ())
196+ ->setGenerateNotification (false );
197+
198+ $ event ->setSubject ('sign_request_canceled ' , [
199+ 'from ' => $ this ->getUserParameter (
200+ $ actor ->getUID (),
201+ $ actor ->getDisplayName (),
202+ ),
203+ 'file ' => $ this ->getFileParameter ($ signRequest , $ libreSignFile ),
204+ 'signer ' => $ this ->getUserParameter (
205+ $ identifyMethod ->getEntity ()->getIdentifierValue (),
206+ $ signRequest ->getDisplayName (),
207+ ),
208+ 'signRequest ' => [
209+ 'type ' => 'sign-request ' ,
210+ 'id ' => (string )$ signRequest ->getId (),
211+ 'name ' => $ actor ->getDisplayName (),
212+ ],
213+ ]);
214+ $ this ->activityManager ->publish ($ event );
215+ } catch (UnknownActivityException $ e ) {
216+ $ this ->logger ->error ($ e ->getMessage (), ['exception ' => $ e ]);
217+ return ;
218+ }
219+ }
220+
170221 /**
171222 * @return array{type: 'file', id: string, name: string, path: string, link: string}
172223 */
0 commit comments