@ -11,6 +11,7 @@ param (
[ securestring ]
[ securestring ]
$AccessToken
$AccessToken
)
)
$ErrorActionPreference = 'Stop'
$account_data_type_prefix = 'de.lubiland.pingposh.'
$account_data_type_prefix = 'de.lubiland.pingposh.'
$account_data_types = @ {
$account_data_types = @ {
@ -180,7 +181,7 @@ function Join-Pong {
FormattedBody = $formatted_body
FormattedBody = $formatted_body
}
}
}
}
function Open- Event {
function Open- Join Event {
param (
param (
[ Parameter ( Mandatory = $true ) ]
[ Parameter ( Mandatory = $true ) ]
$Event ,
$Event ,
@ -201,6 +202,31 @@ function Open-Event {
Send-Pong -RoomId $RoomId @bodies -OriginHomeServer $origin_homeserver -Duration $difference . TotalMilliseconds -PingEventId $Event . event_id
Send-Pong -RoomId $RoomId @bodies -OriginHomeServer $origin_homeserver -Duration $difference . TotalMilliseconds -PingEventId $Event . event_id
}
}
}
}
function Join-MatrixRoom {
param (
[ Parameter ( Mandatory = $true ) ]
$RoomId
)
$uri = '{0}/_matrix/client/r0/rooms/{1}/join' -f $HomeServer , $RoomId
$header_splat = @ {
Authentication = 'Bearer'
Token = $AccessToken
ContentType = 'application/json'
}
$http_splat = @ {
Uri = $uri
Method = 'Post'
}
$response = Invoke-RestMethod @header_splat @http_splat
if ( $response . room_id ) {
Write-Host ( 'Joined room {0}' -f $RoomId )
} else {
Write-Error ( 'Error joining room {0}: {1}' -f $RoomId , $response . error )
}
}
function Get-MatrixAccountData {
function Get-MatrixAccountData {
param (
param (
[ Parameter ( Mandatory = $true ) ]
[ Parameter ( Mandatory = $true ) ]
@ -298,7 +324,16 @@ function Invoke-MatrixSync {
foreach ( $room_id in $room_ids ) {
foreach ( $room_id in $room_ids ) {
$events = $response . rooms . join . $room_id . timeline . events
$events = $response . rooms . join . $room_id . timeline . events
foreach ( $event in $events ) {
foreach ( $event in $events ) {
Open-Event -Event $event -RoomId $room_id
Open-JoinEvent -Event $event -RoomId $room_id
}
}
#.PSObject.Properties because the rooms under .invite are [NoteProperty]
$room_ids = $response . rooms . invite . PSObject . Properties . Name
foreach ( $room_id in $room_ids ) {
$invites = $response . rooms . invite . $room_id . invite_state . events | Where-Object { $_ . content . join_rule -eq 'invite' }
foreach ( $invite in $invites ) {
Join-MatrixRoom -RoomId $room_id
}
}
}
}
@ -332,12 +367,13 @@ function Get-MatrixFilterId {
function Get-FilterId {
function Get-FilterId {
$filter = @ {
$filter = @ {
event_fields = @ (
event_fields = @ (
#all fields used in Open- Event
#all fields used in Open- Join Event
'event_id'
'event_id'
'sender'
'sender'
'origin_server_ts'
'origin_server_ts'
'content.msgtype'
'content.msgtype'
'content.body'
'content.body'
#'content.membership' #invites only
)
)
presence = @ {
presence = @ {
#we don't use presence information
#we don't use presence information
@ -353,8 +389,11 @@ function Get-FilterId {
types = @ ( 'invalid' )
types = @ ( 'invalid' )
}
}
state = @ {
state = @ {
#we don't use room state
types = @ (
types = @ ( 'invalid' )
#to receive invites
'm.room.member'
)
lazy_load_members = $true
}
}
timeline = @ {
timeline = @ {
#exclude ourself
#exclude ourself