Skip to content

Commit aa7897e

Browse files
committed
Load users data earlier
1 parent 044f40a commit aa7897e

1 file changed

Lines changed: 33 additions & 20 deletions

File tree

notification/method/webpush.php

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ public function notify()
146146
{
147147
$insert_buffer = new \phpbb\db\sql_insert_buffer($this->db, $this->notification_webpush_table);
148148

149+
// Load all users we want to notify
150+
$notify_users = $this->load_receivers();
151+
149152
/** @var type_interface $notification */
150153
foreach ($this->queue as $notification)
151154
{
@@ -176,41 +179,24 @@ public function notify()
176179
// Restore current user's language
177180
$this->language->set_user_language($this->user->data['user_lang'], true);
178181

179-
$this->notify_using_webpush();
182+
$this->notify_using_webpush($notify_users);
180183

181184
return false;
182185
}
183186

184187
/**
185188
* Notify using Web Push
186189
*
190+
* @param array $notify_users Array of user ids to notify
187191
* @return void
188192
*/
189-
protected function notify_using_webpush(): void
193+
protected function notify_using_webpush($notify_users = []): void
190194
{
191195
if (empty($this->queue))
192196
{
193197
return;
194198
}
195199

196-
// Load all users we want to notify
197-
$user_ids = [];
198-
foreach ($this->queue as $notification)
199-
{
200-
$user_ids[] = $notification->user_id;
201-
}
202-
203-
// Do not send push notifications to banned users
204-
if (!function_exists('phpbb_get_banned_user_ids'))
205-
{
206-
include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext);
207-
}
208-
$banned_users = phpbb_get_banned_user_ids($user_ids);
209-
210-
// Load all the users we need
211-
$notify_users = array_diff($user_ids, $banned_users);
212-
$this->user_loader->load_users($notify_users, array(USER_IGNORE));
213-
214200
// Get subscriptions for users
215201
$user_subscription_map = $this->get_user_subscription_map($notify_users);
216202

@@ -532,4 +518,31 @@ protected function set_endpoint_padding(\Minishlink\WebPush\WebPush $web_push, s
532518
}
533519
}
534520
}
521+
522+
/**
523+
* Load all users data to send notifications
524+
*
525+
* @return array Array of user ids to notify
526+
*/
527+
protected function load_receivers(): array
528+
{
529+
$notify_users = $user_ids = [];
530+
foreach ($this->queue as $notification)
531+
{
532+
$user_ids[] = $notification->user_id;
533+
}
534+
535+
// Do not send push notifications to banned users
536+
if (!function_exists('phpbb_get_banned_user_ids'))
537+
{
538+
include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext);
539+
}
540+
$banned_users = phpbb_get_banned_user_ids($user_ids);
541+
542+
// Load all the users we need
543+
$notify_users = array_diff($user_ids, $banned_users);
544+
$this->user_loader->load_users($notify_users, [USER_IGNORE]);
545+
546+
return $notify_users;
547+
}
535548
}

0 commit comments

Comments
 (0)