-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from davewoloszyn/MDL-79460
MDL-79460: Add support for powerlevels and route for sync
- Loading branch information
Showing
6 changed files
with
276 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace App\Service; | ||
|
||
use App\Service\Filter\RoomFilter; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
|
||
class Filter | ||
{ | ||
private array $roomIds = []; | ||
private RoomFilter $roomFilter; | ||
|
||
public static function fromRequest(Request $request): static | ||
{ | ||
$filter = new static(); | ||
|
||
$filterData = $request->query->get('filter'); | ||
if (!$filterData) { | ||
return $filter; | ||
} | ||
|
||
// Filter the event data according to the API: | ||
// https://spec.matrix.org/v1.1/client-server-api/#filtering | ||
// Filters are made up of different filter types. | ||
// Detailed here: https://spec.matrix.org/v1.1/client-server-api/#post_matrixclientv3useruseridfilter | ||
$filterData = json_decode($request->query->get('filter')); | ||
|
||
if (property_exists($filterData, 'room')) { | ||
$filter->setRoomFilter(RoomFilter::fromObject($filterData->room)); | ||
} | ||
|
||
return $filter; | ||
} | ||
|
||
public function setRoomFilter(RoomFilter $roomFilter): static | ||
{ | ||
$this->roomFilter = $roomFilter; | ||
return $this; | ||
} | ||
|
||
public function getRequestedRoomIds(): array | ||
{ | ||
return $this->roomIds; | ||
} | ||
|
||
public function getRoomFilter(): RoomFilter | ||
{ | ||
if (empty($this->roomFilter)) { | ||
$this->roomFilter = new RoomFilter(); | ||
} | ||
|
||
return $this->roomFilter; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace App\Service\Filter; | ||
|
||
class RoomFilter | ||
{ | ||
private array $roomIds = []; | ||
private StateFilter $roomStateFilter; | ||
|
||
public static function fromObject(\stdClass $filterData): static | ||
{ | ||
$filter = new static(); | ||
|
||
// Check for a list of rooms. | ||
if (property_exists($filterData, 'rooms')) { | ||
$rooms = (array) $filterData->rooms; | ||
$filter->setRoomIds($rooms); | ||
} | ||
|
||
// Check for a room state filter. | ||
if (property_exists($filterData, 'state')) { | ||
$filter->setRoomState(StateFilter::fromObject($filterData->state)); | ||
} | ||
|
||
return $filter; | ||
} | ||
|
||
public function setRoomIds(array $ids): static | ||
{ | ||
$this->roomIds = $ids; | ||
return $this; | ||
} | ||
|
||
public function setRoomState(StateFilter $state): static | ||
{ | ||
$this->roomStateFilter = $state; | ||
return $this; | ||
} | ||
|
||
public function getRoomIds(): array | ||
{ | ||
return $this->roomIds; | ||
} | ||
|
||
public function getRoomState(): StateFilter | ||
{ | ||
return $this->roomStateFilter; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace App\Service\Filter; | ||
|
||
class StateFilter | ||
{ | ||
private array $types = []; | ||
|
||
public static function fromObject(\stdClass $filterData): static | ||
{ | ||
$filter = new static(); | ||
|
||
// We currently only support types. | ||
if (property_exists($filterData, 'types')) { | ||
$types = (array) $filterData->types; | ||
$filter->setTypes($types); | ||
} | ||
|
||
return $filter; | ||
} | ||
|
||
public function setTypes(array $types): static | ||
{ | ||
$this->types = $types; | ||
return $this; | ||
} | ||
|
||
public function getTypes(): array | ||
{ | ||
return $this->types; | ||
} | ||
} |