mirror of
https://github.com/openvk/chandler.git
synced 2025-01-22 15:24:15 +03:00
Add ability to fetch history of events
This commit is contained in:
parent
f3106105b4
commit
3093be04a6
1 changed files with 38 additions and 1 deletions
|
@ -81,6 +81,43 @@ class SignalManager
|
||||||
exit("[]");
|
exit("[]");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets creation time of user's last event.
|
||||||
|
* If there is no events returns 1.
|
||||||
|
*
|
||||||
|
* @api
|
||||||
|
* @param int $for User ID
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
function tipFor(int $for): int
|
||||||
|
{
|
||||||
|
$statement = $this->connection->query("SELECT since FROM pool WHERE `for` = $for ORDER BY since DESC");
|
||||||
|
$result = $statement->fetch(\PDO::FETCH_LAZY);
|
||||||
|
if(!$result) return 1;
|
||||||
|
|
||||||
|
return $result->since;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets history of long pool events.
|
||||||
|
* If there is no events returns empty array.
|
||||||
|
*
|
||||||
|
* @api
|
||||||
|
* @param int $for User ID
|
||||||
|
* @param int|null $tip last sync time
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function getHistoryFor(int $for, ?int $tip = NULL, int $limit = 1000): array
|
||||||
|
{
|
||||||
|
$res = [];
|
||||||
|
$tip = $tip ?? $this->tipFor($for);
|
||||||
|
$query = $this->connection->query("SELECT * FROM pool WHERE `for` = $for AND `since` > $tip ORDER BY since DESC LIMIT $limit");
|
||||||
|
foreach($query as $event)
|
||||||
|
$res[] = unserialize(hex2bin($event["event"]));
|
||||||
|
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Triggers event for user and sends signal to DB and listeners.
|
* Triggers event for user and sends signal to DB and listeners.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue