1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
<?php
namespace App\Controllers;
use App\Database;
use App\Errors\UnauthorizedError;
use App\Events\PresenceEvent;
use App\Models\User;
use App\Types\PresenceState;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
class SyncController
{
/**
* GET /_matrix/client/v3/sync
*
* @see https://spec.matrix.org/v1.15/client-server-api/#get_matrixclientv3sync
* @see https://spec.matrix.org/v1.15/client-server-api/#extensions-to-sync
*/
public function sync(Request $request): Response
{
$accessToken = str_replace("Bearer ", "", $request->headers->get("authorization") ?: "");
$user = User::fetchWithAccessToken($accessToken);
if (empty($user)) {
throw new UnauthorizedError();
}
$filter = $request->query->get("filter", "");
$syncFullState = $request->query->get("full_state", false);
$setPresence = PresenceState::tryFrom($request->query->get("set_presence") ?? "") ?? PresenceState::ONLINE;
$since = $request->query->get("since", "");
$timeout = $request->query->get("timeout", 0);
$rooms = Database::getInstance()->query(<<<SQL
select * from rooms
SQL)->fetchAll();
$joinedRooms = new \stdClass();
if (! empty($rooms)) {
$joinedRooms = [];
foreach ($rooms as $room) {
$joinedRooms[$room["id"]] = [
"account_data" => [
"events" => [],
],
"ephemeral" => [
"events" => [],
],
"state" => [
"events" => [],
],
"summary" => [
"m.heroes" => [],
"m.invited_member_count" => 0,
"m.joined_member_count" => 1,
],
"timeline" => [
"events" => [],
"limited" => false,
"prev_batch" => "",
],
"unread_notifications" => [
"highlight_count" => 1,
"notification_count" => 2,
],
"unread_thread_notifications" => new \stdClass(),
];
}
}
return new JsonResponse([
"account_data" => [
"events" => [
],
],
"device_lists" => [
"changed" => [],
"left" => [],
],
"device_one_time_keys_count" => [
"signed_curve25519" => 10,
],
"next_batch" => "next_batch_id",
"presence" => [
"events" => [
(new PresenceEvent(sender: $user->getId()))->toJsonEncodeable(),
],
],
"rooms" => [
"invite" => new \stdClass(),
"join" => $joinedRooms,
"knock" => new \stdClass(),
"leave" => new \stdClass(),
],
"to_device" => [
"events" => [],
],
]);
}
}
|