Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions lib/Push.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Push {
*/
protected array $userStatuses = [];
/**
* @psalm-var array<string, list<array{id: int, uid: string, token: int, endpoint: string, ua_public: string, auth: string, appTypes: string, activated: bool, activation_token: string}>>
* @psalm-var array<string, list<array{id: int, uid: string, token: int, endpoint: string, ua_public: string, auth: string, app_types: string, activated: bool, activation_token: string}>>
*/
protected array $userWebPushDevices = [];
/**
Expand Down Expand Up @@ -175,23 +175,20 @@ public function flushPayloads(): void {
}

/**
* @param array $devices
* @psalm-param $devices list<array{id: int, uid: string, token: int, endpoint: string, ua_public: string, auth: string, appTypes: string, activated: bool, activation_token: string}>
* @param string $app
* @return array
* @psalm-return list<array{id: int, uid: string, token: int, endpoint: string, ua_public: string, auth: string, appTypes: string, activated: bool, activation_token: string}>
* @psalm-param list<array{id: int, uid: string, token: int, endpoint: string, ua_public: string, auth: string, app_types: string, activated: bool, activation_token: string}> $devices
* @psalm-return list<array{id: int, uid: string, token: int, endpoint: string, ua_public: string, auth: string, app_types: string, activated: bool, activation_token: string}>
*/
public function filterWebPushDeviceList(array $devices, string $app): array {
// Consider all 3 options as 'talk'
if (\in_array($app, ['spreed', 'talk', 'admin_notification_talk'], true)) {
$app = 'talk';
}

return array_filter($devices, function ($device) use ($app) {
return array_values(array_filter($devices, function ($device) use ($app) {
$appTypes = explode(',', $device['app_types']);
return $device['activated'] && (\in_array($app, $appTypes)
|| (\in_array('all', $appTypes) && !\in_array('-' . $app, $appTypes)));
});
}));
}


Expand Down Expand Up @@ -299,6 +296,9 @@ public function pushToDevice(int $id, INotification $notification, ?OutputInterf
$this->proxyPushToDevice($id, $user, $proxyDevices, $notification, $output);
}

/**
* @param list<array{id: int, uid: string, token: int, endpoint: string, ua_public: string, auth: string, app_types: string, activated: bool, activation_token: string}> $devices
*/
public function webPushToDevice(int $id, IUser $user, array $devices, INotification $notification, ?OutputInterface $output = null): void {
if (empty($devices)) {
$this->printInfo('<comment>No web push devices found for user</comment>');
Expand Down Expand Up @@ -1042,7 +1042,7 @@ protected function getProxyDevicesForUsers(array $userIds): array {

/**
* @param string $uid
* @return list<array{id: int, uid: string, token: int, endpoint: string, ua_public: string, auth: string, appTypes: string, activated: bool, activation_token: string}>
* @return list<array{id: int, uid: string, token: int, endpoint: string, ua_public: string, auth: string, app_types: string, activated: bool, activation_token: string}>
*/
protected function getWebPushDevicesForUser(string $uid): array {
$query = $this->db->getQueryBuilder();
Expand All @@ -1051,6 +1051,7 @@ protected function getWebPushDevicesForUser(string $uid): array {
->where($query->expr()->eq('uid', $query->createNamedParameter($uid)));

$result = $query->executeQuery();
/** @var list<array{id: int, uid: string, token: int, endpoint: string, ua_public: string, auth: string, app_types: string, activated: bool, activation_token: string}> $devices */
$devices = $result->fetchAll();
$result->closeCursor();

Expand All @@ -1059,7 +1060,7 @@ protected function getWebPushDevicesForUser(string $uid): array {

/**
* @param string[] $userIds
* @return array<string, list<array{id: int, uid: string, token: int, endpoint: string, ua_public: string, auth: string, appTypes: string, activated: bool, activation_token: string}>>
* @return array<string, list<array{id: int, uid: string, token: int, endpoint: string, ua_public: string, auth: string, app_types: string, activated: bool, activation_token: string}>>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically I started here fixing the name as per database schema and then from there followed all paths

*/
protected function getWebPushDevicesForUsers(array $userIds): array {
$query = $this->db->getQueryBuilder();
Expand All @@ -1070,6 +1071,7 @@ protected function getWebPushDevicesForUsers(array $userIds): array {
$devices = [];
$result = $query->executeQuery();
while ($row = $result->fetch()) {
/** @psalm-var array{id: int, uid: string, token: int, endpoint: string, ua_public: string, auth: string, app_types: string, activated: bool, activation_token: string} $row */
if (!isset($devices[$row['uid']])) {
$devices[$row['uid']] = [];
}
Expand Down
2 changes: 1 addition & 1 deletion lib/WebPushClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function notify(string $endpoint, string $uaPublicKey, string $auth, stri
// the callback could be defined by the caller
// For the moment, it is used during registration only - no need to catch 404 &co
// as the registration isn't activated
$callback = function ($r) {
$callback = function ($r): void {
};
$c->flushPooled($callback);
}
Expand Down
12 changes: 1 addition & 11 deletions tests/psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="6.15.0@204d06619833a297b402cbc66be7f2df74437db4">
<files psalm-version="6.15.1@28dc127af1b5aecd52314f6f645bafc10d0e11f9">
<file src="lib/Controller/PushController.php">
<UndefinedClass>
<code><![CDATA[$this->identityProof]]></code>
Expand All @@ -21,26 +21,16 @@
</file>
<file src="lib/Push.php">
<LessSpecificReturnStatement>
<code><![CDATA[$devices]]></code>
<code><![CDATA[$devices]]></code>
<code><![CDATA[$devices]]></code>
<code><![CDATA[$devices]]></code>
<code><![CDATA[$otherDevices]]></code>
<code><![CDATA[$otherDevices]]></code>
<code><![CDATA[$talkDevices]]></code>
<code><![CDATA[array_filter($devices, function ($device) use ($app) {
$appTypes = explode(',', $device['app_types']);
return $device['activated'] && (\in_array($app, $appTypes)
|| (\in_array('all', $appTypes) && !\in_array('-' . $app, $appTypes)));
})]]></code>
</LessSpecificReturnStatement>
<MoreSpecificReturnType>
<code><![CDATA[array<string, list<array{id: int, uid: string, token: int, deviceidentifier: string, devicepublickey: string, devicepublickeyhash: string, pushtokenhash: string, proxyserver: string, apptype: string}>>]]></code>
<code><![CDATA[array<string, list<array{id: int, uid: string, token: int, endpoint: string, ua_public: string, auth: string, appTypes: string, activated: bool, activation_token: string}>>]]></code>
<code><![CDATA[list<array{id: int, uid: string, token: int, deviceidentifier: string, devicepublickey: string, devicepublickeyhash: string, pushtokenhash: string, proxyserver: string, apptype: string}>]]></code>
<code><![CDATA[list<array{id: int, uid: string, token: int, deviceidentifier: string, devicepublickey: string, devicepublickeyhash: string, pushtokenhash: string, proxyserver: string, apptype: string}>]]></code>
<code><![CDATA[list<array{id: int, uid: string, token: int, endpoint: string, ua_public: string, auth: string, appTypes: string, activated: bool, activation_token: string}>]]></code>
<code><![CDATA[list<array{id: int, uid: string, token: int, endpoint: string, ua_public: string, auth: string, appTypes: string, activated: bool, activation_token: string}>]]></code>
</MoreSpecificReturnType>
<UndefinedClass>
<code><![CDATA[$e]]></code>
Expand Down