1616use OCA \Libresign \Events \SignedEvent ;
1717use OCA \Libresign \Events \SignRequestCanceledEvent ;
1818use OCA \Libresign \Service \IdentifyMethod \IIdentifyMethod ;
19+ use OCA \Libresign \Service \NotificationPreferenceResolver ;
1920use OCP \AppFramework \Utility \ITimeFactory ;
2021use OCP \EventDispatcher \Event ;
2122use OCP \EventDispatcher \IEventListener ;
@@ -34,6 +35,7 @@ public function __construct(
3435 private ITimeFactory $ timeFactory ,
3536 protected IURLGenerator $ url ,
3637 private SignRequestMapper $ signRequestMapper ,
38+ private NotificationPreferenceResolver $ notificationPreferenceResolver ,
3739 ) {
3840 }
3941
@@ -72,9 +74,10 @@ private function sendSignNotification(
7274 if ($ identifyMethod ->getEntity ()->isDeletedAccount ()) {
7375 return ;
7476 }
75- $ notificationDisabled = $ this ->isNotificationDisabledAtActivity (
77+ $ notificationDisabled = $ this ->notificationPreferenceResolver -> isInAppNotificationDisabled (
7678 $ identifyMethod ->getEntity ()->getIdentifierValue (),
7779 SendSignNotificationEvent::FILE_TO_SIGN ,
80+ true ,
7881 );
7982 if ($ notificationDisabled ) {
8083 return ;
@@ -117,9 +120,10 @@ private function sendSignedNotification(
117120 if ($ identifyMethod ->getEntity ()->isDeletedAccount ()) {
118121 return ;
119122 }
120- $ notificationDisabled = $ this ->isNotificationDisabledAtActivity (
123+ $ notificationDisabled = $ this ->notificationPreferenceResolver -> isInAppNotificationDisabled (
121124 $ libreSignFile ->getUserId (),
122125 SignedEvent::FILE_SIGNED ,
126+ true ,
123127 );
124128 if ($ notificationDisabled ) {
125129 return ;
@@ -169,9 +173,10 @@ private function sendCanceledNotification(
169173 if ($ identifyMethod ->getEntity ()->isDeletedAccount ()) {
170174 return ;
171175 }
172- $ notificationDisabled = $ this ->isNotificationDisabledAtActivity (
176+ $ notificationDisabled = $ this ->notificationPreferenceResolver -> isInAppNotificationDisabled (
173177 $ identifyMethod ->getEntity ()->getIdentifierValue (),
174178 SignRequestCanceledEvent::SIGN_REQUEST_CANCELED ,
179+ true ,
175180 );
176181 if ($ notificationDisabled ) {
177182 return ;
@@ -204,36 +209,6 @@ private function sendCanceledNotification(
204209 $ this ->notificationManager ->notify ($ notification );
205210 }
206211
207- private function isNotificationDisabledAtActivity (string $ userId , string $ type ): bool {
208- if (!class_exists (\OCA \Activity \UserSettings::class)) {
209- return false ;
210- }
211- $ activityUserSettings = \OCP \Server::get (\OCA \Activity \UserSettings::class);
212- if ($ activityUserSettings ) {
213- $ manager = \OCP \Server::get (\OCP \Activity \IManager::class);
214- try {
215- $ manager ->getSettingById ($ type );
216- } catch (\Exception ) {
217- return false ;
218- }
219-
220- $ adminSetting = $ activityUserSettings ->getAdminSetting ('notification ' , $ type );
221- if (!$ adminSetting ) {
222- return true ;
223- }
224-
225- $ notificationSetting = $ activityUserSettings ->getUserSetting (
226- $ userId ,
227- 'notification ' ,
228- $ type
229- );
230- if ($ notificationSetting === false ) {
231- return true ;
232- }
233- }
234- return false ;
235- }
236-
237212 /**
238213 * @psalm-return array{type: 'file', id: string, name: string, path: string, link: string}
239214 */
0 commit comments