1414use phpbb \config \config ;
1515use phpbb \controller \helper ;
1616use phpbb \db \driver \driver_interface ;
17- use phpbb \language \language ;
1817use phpbb \log \log_interface ;
1918use phpbb \notification \method \messenger_base ;
2019use phpbb \notification \type \type_interface ;
@@ -36,9 +35,6 @@ class webpush extends messenger_base implements extended_method_interface
3635 /** @var driver_interface */
3736 protected $ db ;
3837
39- /** @var language */
40- protected $ language ;
41-
4238 /** @var log_interface */
4339 protected $ log ;
4440
@@ -65,7 +61,6 @@ class webpush extends messenger_base implements extended_method_interface
6561 *
6662 * @param config $config
6763 * @param driver_interface $db
68- * @param language $language
6964 * @param log_interface $log
7065 * @param user_loader $user_loader
7166 * @param user $user
@@ -75,14 +70,13 @@ class webpush extends messenger_base implements extended_method_interface
7570 * @param string $notification_webpush_table
7671 * @param string $push_subscriptions_table
7772 */
78- public function __construct (config $ config , driver_interface $ db , language $ language , log_interface $ log , user_loader $ user_loader , user $ user , path_helper $ path_helper ,
73+ public function __construct (config $ config , driver_interface $ db , log_interface $ log , user_loader $ user_loader , user $ user , path_helper $ path_helper ,
7974 string $ phpbb_root_path , string $ php_ext , string $ notification_webpush_table , string $ push_subscriptions_table )
8075 {
8176 parent ::__construct ($ user_loader , $ phpbb_root_path , $ php_ext );
8277
8378 $ this ->config = $ config ;
8479 $ this ->db = $ db ;
85- $ this ->language = $ language ;
8680 $ this ->log = $ log ;
8781 $ this ->user = $ user ;
8882 $ this ->path_helper = $ path_helper ;
@@ -145,21 +139,10 @@ public function notify()
145139 {
146140 $ insert_buffer = new \phpbb \db \sql_insert_buffer ($ this ->db , $ this ->notification_webpush_table );
147141
148- // Load all users data we want to notify
149- $ notify_users = $ this ->load_recipients_data ();
150-
151142 /** @var type_interface $notification */
152143 foreach ($ this ->queue as $ notification )
153144 {
154145 $ data = $ notification ->get_insert_array ();
155-
156- // Change notification language if needed only
157- $ recipient_data = $ this ->user_loader ->get_user ($ notification ->user_id );
158- if ($ this ->language ->get_used_language () !== $ recipient_data ['user_lang ' ])
159- {
160- $ this ->language ->set_user_language ($ recipient_data ['user_lang ' ], true );
161- }
162-
163146 $ data += [
164147 'push_data ' => json_encode ([
165148 'heading ' => $ this ->config ['sitename ' ],
@@ -178,30 +161,41 @@ public function notify()
178161
179162 $ insert_buffer ->flush ();
180163
181- // Restore current user's language if needed only
182- if ($ this ->language ->get_used_language () !== $ this ->user ->data ['user_lang ' ])
183- {
184- $ this ->language ->set_user_language ($ this ->user ->data ['user_lang ' ], true );
185- }
186-
187- $ this ->notify_using_webpush ($ notify_users );
164+ $ this ->notify_using_webpush ();
188165
189166 return false ;
190167 }
191168
192169 /**
193170 * Notify using Web Push
194171 *
195- * @param array $notify_users Array of user ids to notify
196172 * @return void
197173 */
198- protected function notify_using_webpush ($ notify_users = [] ): void
174+ protected function notify_using_webpush (): void
199175 {
200176 if (empty ($ this ->queue ))
201177 {
202178 return ;
203179 }
204180
181+ // Load all users we want to notify
182+ $ user_ids = [];
183+ foreach ($ this ->queue as $ notification )
184+ {
185+ $ user_ids [] = $ notification ->user_id ;
186+ }
187+
188+ // Do not send push notifications to banned users
189+ if (!function_exists ('phpbb_get_banned_user_ids ' ))
190+ {
191+ include ($ this ->phpbb_root_path . 'includes/functions_user. ' . $ this ->php_ext );
192+ }
193+ $ banned_users = phpbb_get_banned_user_ids ($ user_ids );
194+
195+ // Load all the users we need
196+ $ notify_users = array_diff ($ user_ids , $ banned_users );
197+ $ this ->user_loader ->load_users ($ notify_users , array (USER_IGNORE ));
198+
205199 // Get subscriptions for users
206200 $ user_subscription_map = $ this ->get_user_subscription_map ($ notify_users );
207201
@@ -523,31 +517,4 @@ protected function set_endpoint_padding(\Minishlink\WebPush\WebPush $web_push, s
523517 }
524518 }
525519 }
526-
527- /**
528- * Load all users data to send notifications
529- *
530- * @return array Array of user ids to notify
531- */
532- protected function load_recipients_data (): array
533- {
534- $ notify_users = $ user_ids = [];
535- foreach ($ this ->queue as $ notification )
536- {
537- $ user_ids [] = $ notification ->user_id ;
538- }
539-
540- // Do not send push notifications to banned users
541- if (!function_exists ('phpbb_get_banned_user_ids ' ))
542- {
543- include ($ this ->phpbb_root_path . 'includes/functions_user. ' . $ this ->php_ext );
544- }
545- $ banned_users = phpbb_get_banned_user_ids ($ user_ids );
546-
547- // Load all the users we need
548- $ notify_users = array_diff ($ user_ids , $ banned_users );
549- $ this ->user_loader ->load_users ($ notify_users , [USER_IGNORE ]);
550-
551- return $ notify_users ;
552- }
553520}
0 commit comments