1414use phpbb \config \config ;
1515use phpbb \controller \helper ;
1616use phpbb \db \driver \driver_interface ;
17+ use phpbb \language \language ;
1718use phpbb \log \log_interface ;
1819use phpbb \notification \method \messenger_base ;
1920use phpbb \notification \type \type_interface ;
@@ -36,6 +37,9 @@ class webpush extends messenger_base implements extended_method_interface
3637 /** @var driver_interface */
3738 protected $ db ;
3839
40+ /** @var language */
41+ protected $ language ;
42+
3943 /** @var log_interface */
4044 protected $ log ;
4145
@@ -62,6 +66,7 @@ class webpush extends messenger_base implements extended_method_interface
6266 *
6367 * @param config $config
6468 * @param driver_interface $db
69+ * @param language $language
6570 * @param log_interface $log
6671 * @param user_loader $user_loader
6772 * @param user $user
@@ -71,13 +76,14 @@ class webpush extends messenger_base implements extended_method_interface
7176 * @param string $notification_webpush_table
7277 * @param string $push_subscriptions_table
7378 */
74- public function __construct (config $ config , driver_interface $ db , log_interface $ log , user_loader $ user_loader , user $ user , path_helper $ path_helper ,
79+ public function __construct (config $ config , driver_interface $ db , language $ language , log_interface $ log , user_loader $ user_loader , user $ user , path_helper $ path_helper ,
7580 string $ phpbb_root_path , string $ php_ext , string $ notification_webpush_table , string $ push_subscriptions_table )
7681 {
7782 parent ::__construct ($ user_loader , $ phpbb_root_path , $ php_ext );
7883
7984 $ this ->config = $ config ;
8085 $ this ->db = $ db ;
86+ $ this ->language = $ language ;
8187 $ this ->log = $ log ;
8288 $ this ->user = $ user ;
8389 $ this ->path_helper = $ path_helper ;
@@ -144,6 +150,11 @@ public function notify()
144150 foreach ($ this ->queue as $ notification )
145151 {
146152 $ data = $ notification ->get_insert_array ();
153+
154+ // Choose receiving user's language
155+ $ user = $ this ->user_loader ->get_user ($ data ['user_id ' ]);
156+ $ this ->language ->set_user_language ($ user ['user_lang ' ], true );
157+
147158 $ data += [
148159 'push_data ' => json_encode ([
149160 'heading ' => $ this ->config ['sitename ' ],
@@ -162,6 +173,9 @@ public function notify()
162173
163174 $ insert_buffer ->flush ();
164175
176+ // Restore current user's language
177+ $ this ->language ->set_user_language ($ this ->user ->data ['user_lang ' ], true );
178+
165179 $ this ->notify_using_webpush ();
166180
167181 return false ;
0 commit comments