mirror of
https://github.com/Thumbscrew/PSMatrix.git
synced 2025-01-18 17:45:44 +00:00
add Remove-MatrixRoomMessage
(#4)
* fix debug url * fix `MatrixMessage` type * add `Remove-MatrixRoomMessage` * add `Get-Help` block
This commit is contained in:
parent
2075ddb626
commit
a9bc50465f
@ -77,7 +77,8 @@ FunctionsToExport = @(
|
|||||||
'Get-MatrixJoinedRooms',
|
'Get-MatrixJoinedRooms',
|
||||||
'Get-MatrixJoinedMembers',
|
'Get-MatrixJoinedMembers',
|
||||||
'Get-MatrixRoomId',
|
'Get-MatrixRoomId',
|
||||||
'Get-MatrixRoomMessages'
|
'Get-MatrixRoomMessages',
|
||||||
|
'Remove-MatrixRoomMessage'
|
||||||
)
|
)
|
||||||
|
|
||||||
# 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.
|
# 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.
|
||||||
|
@ -2,30 +2,22 @@
|
|||||||
<Type>
|
<Type>
|
||||||
<Name>MatrixMessage</Name>
|
<Name>MatrixMessage</Name>
|
||||||
<Members>
|
<Members>
|
||||||
<NoteProperty>
|
<MemberSet>
|
||||||
<Name>EventID</Name>
|
<Name>PSStandardMembers</Name>
|
||||||
<Value>EventID</Value>
|
<Members>
|
||||||
</NoteProperty>
|
<PropertySet>
|
||||||
<NoteProperty>
|
<Name>DefaultDisplayPropertySet</Name>
|
||||||
<Name>Sender</Name>
|
<ReferencedProperties>
|
||||||
<Value>Sender</Value>
|
<Name>EventID</Name>
|
||||||
</NoteProperty>
|
<Name>Sender</Name>
|
||||||
<NoteProperty>
|
<Name>Body</Name>
|
||||||
<Name>Body</Name>
|
<Name>Format</Name>
|
||||||
<Value>Body</Value>
|
<Name>FormattedBody</Name>
|
||||||
</NoteProperty>
|
<Name>MsgType</Name>
|
||||||
<NoteProperty>
|
</ReferencedProperties>
|
||||||
<Name>Format</Name>
|
</PropertySet>
|
||||||
<Value>Format</Value>
|
</Members>
|
||||||
</NoteProperty>
|
</MemberSet>
|
||||||
<NoteProperty>
|
|
||||||
<Name>FormattedBody</Name>
|
|
||||||
<Value>FormattedBody</Value>
|
|
||||||
</NoteProperty>
|
|
||||||
<NoteProperty>
|
|
||||||
<Name>MsgType</Name>
|
|
||||||
<Value>MsgType</Value>
|
|
||||||
</NoteProperty>
|
|
||||||
</Members>
|
</Members>
|
||||||
</Type>
|
</Type>
|
||||||
</Types>
|
</Types>
|
@ -16,7 +16,6 @@ function Get-MatrixRoomMessages {
|
|||||||
[int]$Limit = 50
|
[int]$Limit = 50
|
||||||
)
|
)
|
||||||
|
|
||||||
Write-Debug "URL: $url"
|
|
||||||
$headers = Get-MatrixAuthHeaders -AccessToken $AccessToken
|
$headers = Get-MatrixAuthHeaders -AccessToken $AccessToken
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -51,6 +50,8 @@ function Get-MatrixRoomMessages {
|
|||||||
+ "?filter=$filterId" `
|
+ "?filter=$filterId" `
|
||||||
+ "&full_state=true&set_presence=offline")
|
+ "&full_state=true&set_presence=offline")
|
||||||
|
|
||||||
|
Write-Debug "URL: $url"
|
||||||
|
|
||||||
$res = Invoke-RestMethod -Uri $url -Headers $headers
|
$res = Invoke-RestMethod -Uri $url -Headers $headers
|
||||||
} catch {
|
} catch {
|
||||||
Write-Error $_
|
Write-Error $_
|
||||||
|
64
public/Remove-MatrixRoomMessage.ps1
Normal file
64
public/Remove-MatrixRoomMessage.ps1
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
<#
|
||||||
|
.Synopsis
|
||||||
|
Redact a Matrix message in a given Room ID.
|
||||||
|
|
||||||
|
.Description
|
||||||
|
Redact a Matrix message in a given Room ID from _matrix/client/v3/rooms/{roomId}/redact/{eventId}/{txnId}. See https://spec.matrix.org/v1.2/client-server-api/#put_matrixclientv3roomsroomidredacteventidtxnid.
|
||||||
|
|
||||||
|
.Parameter ServerUrl
|
||||||
|
URL for the Matrix server to log into, for example "https://matrix.example.com".
|
||||||
|
|
||||||
|
.Parameter AccessToken
|
||||||
|
A SecureString containing the Matrix access token.
|
||||||
|
|
||||||
|
.Parameter RoomId
|
||||||
|
The Matrix room ID to redact the message from.
|
||||||
|
|
||||||
|
.Parameter Message
|
||||||
|
The MatrixMessage object that contains the Event ID to redact.
|
||||||
|
|
||||||
|
.Parameter Reason
|
||||||
|
The reason to provide for the redaction (optional).
|
||||||
|
|
||||||
|
.Example
|
||||||
|
Remove-MatrixRoomMessage -ServerUrl $server -AccessToken $token -RoomId "!ehXvUhWNASUkSLvAGP:matrix.org" -Message $message -Reason "Redacted by PSMatrix"
|
||||||
|
#>
|
||||||
|
function Remove-MatrixRoomMessage {
|
||||||
|
param (
|
||||||
|
[Parameter(Mandatory)]
|
||||||
|
[string]
|
||||||
|
$ServerUrl,
|
||||||
|
|
||||||
|
[Parameter(Mandatory)]
|
||||||
|
[SecureString]
|
||||||
|
$AccessToken,
|
||||||
|
|
||||||
|
[Parameter(Mandatory)]
|
||||||
|
[string]
|
||||||
|
$RoomId,
|
||||||
|
|
||||||
|
[Parameter(Mandatory)]
|
||||||
|
[MatrixMessage]
|
||||||
|
$Message,
|
||||||
|
|
||||||
|
[Parameter(Mandatory=$false)]
|
||||||
|
[string]
|
||||||
|
$Reason
|
||||||
|
)
|
||||||
|
|
||||||
|
$eventId = $Message.EventID
|
||||||
|
$txnId = New-Guid
|
||||||
|
$url = New-MatrixUrl -ServerUrl $ServerUrl -ApiPath "_matrix/client/v3/rooms/$RoomId/redact/$eventId/$txnId"
|
||||||
|
Write-Debug "URL: $url"
|
||||||
|
$method = "Put"
|
||||||
|
$headers = Get-MatrixAuthHeaders -AccessToken $AccessToken
|
||||||
|
$body = @{
|
||||||
|
reason = $Reason
|
||||||
|
} | ConvertTo-Json
|
||||||
|
|
||||||
|
try {
|
||||||
|
return Invoke-RestMethod -Uri $url -Method $method -Headers $headers -Body $body
|
||||||
|
} catch {
|
||||||
|
Write-Error $_
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user