f7cloud_client/apps/notifications/lib/Service/ClientService.php
root 8b6a0139db f7cloud_client
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-17 22:59:26 +00:00

49 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2023 F7cloud GmbH and F7cloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Notifications\Service;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use OCP\IRequest;
class ClientService {
public const DESKTOP_CLIENT_TIMEOUT = 120;
public function __construct(
protected IDBConnection $connection,
protected IRequest $request,
) {
}
public function hasTalkDesktop(string $userId, int $maxAge = 0): bool {
$query = $this->connection->getQueryBuilder();
$query->select('name')
->from('authtoken')
->where($query->expr()->eq('uid', $query->createNamedParameter($userId)));
if ($maxAge !== 0) {
$query->andWhere($query->expr()->gte(
'last_activity',
$query->createNamedParameter($maxAge, IQueryBuilder::PARAM_INT)
));
}
$result = $query->executeQuery();
while ($row = $result->fetch()) {
if (preg_match('/ \(Talk Desktop Client - [A-Za-z ]+\)$/', $row['name'])) {
$result->closeCursor();
return true;
}
}
$result->closeCursor();
return false;
}
}