mirror of
https://github.com/Thumbscrew/PSMatrix.git
synced 2025-01-18 09:35:44 +00:00
add function for getting joined rooms
This commit is contained in:
parent
de4a048ab2
commit
c16d850676
@ -71,7 +71,8 @@ PowerShellVersion = '7.0'
|
||||
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
|
||||
FunctionsToExport = @(
|
||||
'New-MatrixAccessToken',
|
||||
'Remove-MatrixAccessToken'
|
||||
'Remove-MatrixAccessToken',
|
||||
'Get-MatrixJoinedRooms'
|
||||
)
|
||||
|
||||
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
|
||||
|
10
private/Get-MatrixAuthHeaders.ps1
Normal file
10
private/Get-MatrixAuthHeaders.ps1
Normal file
@ -0,0 +1,10 @@
|
||||
function Get-MatrixAuthHeaders {
|
||||
param(
|
||||
[Parameter(Mandatory)]
|
||||
[SecureString]$AccessToken
|
||||
)
|
||||
|
||||
return @{
|
||||
Authorization="Bearer " + ($AccessToken | ConvertFrom-SecureString -AsPlainText)
|
||||
}
|
||||
}
|
52
public/Get-MatrixJoinedRooms.ps1
Normal file
52
public/Get-MatrixJoinedRooms.ps1
Normal file
@ -0,0 +1,52 @@
|
||||
function Get-MatrixJoinedRooms {
|
||||
param(
|
||||
[Parameter(Mandatory)]
|
||||
[string]$ServerUrl,
|
||||
|
||||
[Parameter(Mandatory)]
|
||||
[SecureString]$AccessToken
|
||||
)
|
||||
|
||||
try {
|
||||
$url = New-MatrixUrl -ServerUrl $ServerUrl -ApiPath "_matrix/client/v3/joined_rooms"
|
||||
}
|
||||
catch {
|
||||
Write-Error $Error[0]
|
||||
return
|
||||
}
|
||||
|
||||
$headers = Get-MatrixAuthHeaders -AccessToken $AccessToken
|
||||
|
||||
$res = Invoke-RestMethod -Uri $url -Headers $headers
|
||||
$rooms = @()
|
||||
|
||||
foreach($roomId in $res.joined_rooms) {
|
||||
$roomAliasUrl = New-MatrixUrl -ServerUrl $ServerUrl -ApiPath "_matrix/client/v3/rooms/$roomId/state/m.room.canonical_alias"
|
||||
$mainAlias = $null
|
||||
$altAliases = @()
|
||||
|
||||
Write-Debug "Retrieving aliases for room ID $roomId via request $roomAliasUrl"
|
||||
|
||||
try {
|
||||
$aliasRes = Invoke-RestMethod -Uri $roomAliasUrl -Headers $headers
|
||||
$mainAlias = $aliasRes.alias
|
||||
$altAliases = $aliasRes.alt_aliases
|
||||
if($null -eq $altAliases) {
|
||||
$altAliases = @()
|
||||
}
|
||||
}
|
||||
catch {
|
||||
# Write-Warning $Error[0]
|
||||
}
|
||||
|
||||
$room = [PSCustomObject]@{
|
||||
RoomID = $roomId
|
||||
MainAlias = $mainAlias
|
||||
AltAliases = $altAliases
|
||||
}
|
||||
|
||||
$rooms += $room
|
||||
}
|
||||
|
||||
return $rooms
|
||||
}
|
Loading…
Reference in New Issue
Block a user