diff options
Diffstat (limited to 'src/Models')
| -rw-r--r-- | src/Models/RoomEvent.php | 2 | ||||
| -rw-r--r-- | src/Models/User.php | 27 |
2 files changed, 25 insertions, 4 deletions
diff --git a/src/Models/RoomEvent.php b/src/Models/RoomEvent.php index ce74cac..11d74b0 100644 --- a/src/Models/RoomEvent.php +++ b/src/Models/RoomEvent.php @@ -22,7 +22,7 @@ class RoomEvent { $rowUnsigned = json_decode($row["unsigned"], true); $unsigned = new UnsignedData( - age: $row["age"] ?? null, + age: $row["age"] ?? ((time() - new \DateTime($row["origin_server_timestamp"])->getTimestamp()) * 1000), membership: $row["membership"] ?? null, previousContent: $row["previous_content"] ?? null, redactedBecause: $row["redacted_because"] ?? null, diff --git a/src/Models/User.php b/src/Models/User.php index 4c016ad..a30bee0 100644 --- a/src/Models/User.php +++ b/src/Models/User.php @@ -12,6 +12,8 @@ use Symfony\Component\HttpFoundation\Response; class User implements ConnectsToDatabase { + private string $deviceId; + public function __construct( private string $id, private string $name, @@ -62,7 +64,7 @@ class User implements ConnectsToDatabase public static function fetchWithAccessToken(string $accessToken): ?self { $row = Database::getInstance()->query(<<<SQL - select users.* from users left join tokens on tokens.user_id = users.id where tokens.access_token=:access_token + select users.*, tokens.device_id from users left join tokens on tokens.user_id = users.id where tokens.access_token=:access_token SQL, [ "access_token" => $accessToken, ])->fetch(); @@ -71,7 +73,10 @@ class User implements ConnectsToDatabase return null; } - return self::fromDatabase($row); + $user = self::fromDatabase($row); + $user->setDeviceId($row["device_id"]); + + return $user; } public static function new(string $id, string $name): self @@ -137,9 +142,25 @@ class User implements ConnectsToDatabase return $this->name; } + public function setDeviceId(string $id): void + { + $this->deviceId = $id; + } + + public function getDeviceId(): string + { + return $this->deviceId; + } + public function fetchDevice(string $id): ?Device { - return Device::fetch($id, $this->id); + $device = Device::fetch($id, $this->id); + + if ($device) { + $this->setDeviceId($device->getId()); + } + + return $device; } /** |
