Add event redaction
parent
69c273f8bf
commit
dc39036162
|
@ -5,6 +5,7 @@ import Internal.Api.GetEvent.Main as GetEvent
|
||||||
import Internal.Api.JoinedMembers.Main as JoinedMembers
|
import Internal.Api.JoinedMembers.Main as JoinedMembers
|
||||||
import Internal.Api.PreApi.Main as PreApi
|
import Internal.Api.PreApi.Main as PreApi
|
||||||
import Internal.Api.PreApi.Objects.Versions as V
|
import Internal.Api.PreApi.Objects.Versions as V
|
||||||
|
import Internal.Api.Redact.Main as Redact
|
||||||
import Internal.Api.SendMessageEvent.Main as SendMessageEvent
|
import Internal.Api.SendMessageEvent.Main as SendMessageEvent
|
||||||
import Internal.Api.SendStateKey.Main as SendStateKey
|
import Internal.Api.SendStateKey.Main as SendStateKey
|
||||||
import Internal.Api.Sync.Main as Sync
|
import Internal.Api.Sync.Main as Sync
|
||||||
|
@ -22,6 +23,7 @@ type CredUpdate
|
||||||
| GetEvent GetEvent.EventInput GetEvent.EventOutput
|
| GetEvent GetEvent.EventInput GetEvent.EventOutput
|
||||||
| JoinedMembersToRoom JoinedMembers.JoinedMembersInput JoinedMembers.JoinedMembersOutput
|
| JoinedMembersToRoom JoinedMembers.JoinedMembersInput JoinedMembers.JoinedMembersOutput
|
||||||
| MessageEventSent SendMessageEvent.SendMessageEventInput SendMessageEvent.SendMessageEventOutput
|
| MessageEventSent SendMessageEvent.SendMessageEventInput SendMessageEvent.SendMessageEventOutput
|
||||||
|
| RedactedEvent Redact.RedactInput Redact.RedactOutput
|
||||||
| StateEventSent SendStateKey.SendStateKeyInput SendStateKey.SendStateKeyOutput
|
| StateEventSent SendStateKey.SendStateKeyInput SendStateKey.SendStateKeyOutput
|
||||||
| SyncUpdate Sync.SyncInput Sync.SyncOutput
|
| SyncUpdate Sync.SyncInput Sync.SyncOutput
|
||||||
-- Updates as a result of getting data early
|
-- Updates as a result of getting data early
|
||||||
|
@ -107,6 +109,62 @@ joinedMembers data =
|
||||||
(PreApi.versions data.baseUrl data.versions)
|
(PreApi.versions data.baseUrl data.versions)
|
||||||
|
|
||||||
|
|
||||||
|
type alias RedactEventInput =
|
||||||
|
{ accessToken : AccessToken
|
||||||
|
, baseUrl : String
|
||||||
|
, eventId : String
|
||||||
|
, reason : Maybe String
|
||||||
|
, roomId : String
|
||||||
|
, versions : Maybe V.Versions
|
||||||
|
, extraTransactionNoise : String
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
{-| Redact an event from a Matrix room.
|
||||||
|
-}
|
||||||
|
redact : RedactEventInput -> Future CredUpdate
|
||||||
|
redact data =
|
||||||
|
VG.withInfo3
|
||||||
|
(\accessToken versions transactionId ->
|
||||||
|
let
|
||||||
|
input : Redact.RedactInput
|
||||||
|
input =
|
||||||
|
{ accessToken = accessToken
|
||||||
|
, baseUrl = data.baseUrl
|
||||||
|
, roomId = data.roomId
|
||||||
|
, eventId = data.eventId
|
||||||
|
, txnId = transactionId
|
||||||
|
, reason = data.reason
|
||||||
|
}
|
||||||
|
in
|
||||||
|
-- TODO: As an option, the API may get this event to see
|
||||||
|
-- what the event looks like now.
|
||||||
|
Redact.redact versions.versions input
|
||||||
|
|> Task.map
|
||||||
|
(\output ->
|
||||||
|
MultipleUpdates
|
||||||
|
[ RedactedEvent input output
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(PreApi.accessToken data.baseUrl data.accessToken)
|
||||||
|
(PreApi.versions data.baseUrl data.versions)
|
||||||
|
(PreApi.transactionId
|
||||||
|
(\timestamp ->
|
||||||
|
[ Hash.fromInt timestamp
|
||||||
|
, Hash.fromString data.baseUrl
|
||||||
|
, Hash.fromString data.eventId
|
||||||
|
, Hash.fromString data.roomId
|
||||||
|
, Hash.fromString (data.reason |> Maybe.withDefault "no-reason")
|
||||||
|
, Hash.fromString data.extraTransactionNoise
|
||||||
|
]
|
||||||
|
|> List.foldl Hash.dependent (Hash.fromInt 0)
|
||||||
|
|> Hash.toString
|
||||||
|
|> (++) "elm"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
type alias SendMessageEventInput =
|
type alias SendMessageEventInput =
|
||||||
{ accessToken : AccessToken
|
{ accessToken : AccessToken
|
||||||
, baseUrl : String
|
, baseUrl : String
|
||||||
|
|
|
@ -21,19 +21,20 @@ Note that **under development** doesn't always mean that it _will be_ supported.
|
||||||
| **Spec version** | | Syncing | Redaction |
|
| **Spec version** | | Syncing | Redaction |
|
||||||
| ---------------- | - | ------- | --------- |
|
| ---------------- | - | ------- | --------- |
|
||||||
| v1.6 || ⚠️ | ⚠️ |
|
| v1.6 || ⚠️ | ⚠️ |
|
||||||
| v1.5 || ✔️ | ⚡ |
|
| v1.5 || ✔️ | ✔️ |
|
||||||
| v1.4 || ✔️ | ⚡ |
|
| v1.4 || ✔️ | ✔️ |
|
||||||
| v1.3 || ✔️ | ⚡ |
|
| v1.3 || ✔️ | ✔️ |
|
||||||
| v1.2 || ✔️ | ⚡ |
|
| v1.2 || ✔️ | ✔️ |
|
||||||
| v1.1 || ⚠️ | ⚠️ |
|
| v1.1 || ❌ | ✔️ |
|
||||||
| r0.6.1 || ⚠️ | ⚠️ |
|
| r0.6.1 || ❌ | ✔️ |
|
||||||
| r0.6.0 || ⚠️ | ⚠️ |
|
| r0.6.0 || ❌ | ✔️ |
|
||||||
| r0.5.0 || ⚠️ | ⚠️ |
|
| r0.5.0 || ❌ | ✔️ |
|
||||||
| r0.4.0 || ⚠️ | ⚠️ |
|
| r0.4.0 || ❌ | ✔️ |
|
||||||
| r0.3.0 || ⚠️ | ⚠️ |
|
| r0.3.0 || ❌ | ✔️ |
|
||||||
| r0.2.0 || ⚠️ | ⚠️ |
|
| r0.2.0 || ❌ | ✔️ |
|
||||||
| r0.1.0 || ⚠️ | ⚠️ |
|
| r0.1.0 || ❌ | ✔️ |
|
||||||
| r0.0.1 || ⚠️ | ⚠️ |
|
| r0.0.1 || ❌ | ✔️ |
|
||||||
|
| r0.0.0 || ❌ | ✔️ |
|
||||||
|
|
||||||
## Getting events for a room
|
## Getting events for a room
|
||||||
|
|
||||||
|
@ -73,3 +74,4 @@ Note that **under development** doesn't always mean that it _will be_ supported.
|
||||||
| r0.2.0 || ✔️ | ✔️ |
|
| r0.2.0 || ✔️ | ✔️ |
|
||||||
| r0.1.0 || ✔️ | ✔️ |
|
| r0.1.0 || ✔️ | ✔️ |
|
||||||
| r0.0.1 || ✔️ | ✔️ |
|
| r0.0.1 || ✔️ | ✔️ |
|
||||||
|
| r0.0.0 || ✔️ | ✔️ |
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
module Internal.Api.Redact.Api exposing (..)
|
||||||
|
|
||||||
|
import Internal.Api.Redact.V1.SpecObjects as SO1
|
||||||
|
import Internal.Api.Request as R
|
||||||
|
import Internal.Tools.Exceptions as X
|
||||||
|
import Task exposing (Task)
|
||||||
|
|
||||||
|
|
||||||
|
type alias RedactInputV1 =
|
||||||
|
{ accessToken : String
|
||||||
|
, baseUrl : String
|
||||||
|
, roomId : String
|
||||||
|
, eventId : String
|
||||||
|
, txnId : String
|
||||||
|
, reason : Maybe String
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
type alias RedactOutputV1 =
|
||||||
|
SO1.Redaction
|
||||||
|
|
||||||
|
|
||||||
|
redactV1 : RedactInputV1 -> Task X.Error RedactOutputV1
|
||||||
|
redactV1 data =
|
||||||
|
R.rawApiCall
|
||||||
|
{ headers = R.WithAccessToken data.accessToken
|
||||||
|
, method = "PUT"
|
||||||
|
, baseUrl = data.baseUrl
|
||||||
|
, path = "/_matrix/client/r0/rooms/{roomId}/redact/{eventId}/{txnId}"
|
||||||
|
, pathParams =
|
||||||
|
[ ( "roomId", data.roomId )
|
||||||
|
, ( "eventId", data.eventId )
|
||||||
|
, ( "txnId", data.txnId )
|
||||||
|
]
|
||||||
|
, queryParams = []
|
||||||
|
, bodyParams =
|
||||||
|
[ R.OptionalString "reason" data.reason
|
||||||
|
]
|
||||||
|
, timeout = Nothing
|
||||||
|
, decoder = always SO1.redactionDecoder
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
redactV2 : RedactInputV1 -> Task X.Error RedactOutputV1
|
||||||
|
redactV2 data =
|
||||||
|
R.rawApiCall
|
||||||
|
{ headers = R.WithAccessToken data.accessToken
|
||||||
|
, method = "PUT"
|
||||||
|
, baseUrl = data.baseUrl
|
||||||
|
, path = "/_matrix/client/v3/rooms/{roomId}/redact/{eventId}/{txnId}"
|
||||||
|
, pathParams =
|
||||||
|
[ ( "roomId", data.roomId )
|
||||||
|
, ( "eventId", data.eventId )
|
||||||
|
, ( "txnId", data.txnId )
|
||||||
|
]
|
||||||
|
, queryParams = []
|
||||||
|
, bodyParams = []
|
||||||
|
, timeout = Nothing
|
||||||
|
, decoder = always SO1.redactionDecoder
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
module Internal.Api.Redact.Main exposing (..)
|
||||||
|
|
||||||
|
import Internal.Api.Redact.Api as Api
|
||||||
|
import Internal.Tools.Exceptions as X
|
||||||
|
import Internal.Tools.VersionControl as VC
|
||||||
|
import Task exposing (Task)
|
||||||
|
|
||||||
|
|
||||||
|
redact : List String -> RedactInput -> Task X.Error RedactOutput
|
||||||
|
redact versions =
|
||||||
|
VC.withBottomLayer
|
||||||
|
{ current = Api.redactV1
|
||||||
|
, version = "r0.0.0"
|
||||||
|
}
|
||||||
|
|> VC.sameForVersion "r0.0.1"
|
||||||
|
|> VC.sameForVersion "r0.1.0"
|
||||||
|
|> VC.sameForVersion "r0.2.0"
|
||||||
|
|> VC.sameForVersion "r0.3.0"
|
||||||
|
|> VC.sameForVersion "r0.4.0"
|
||||||
|
|> VC.sameForVersion "r0.5.0"
|
||||||
|
|> VC.sameForVersion "r0.6.0"
|
||||||
|
|> VC.sameForVersion "r0.6.1"
|
||||||
|
|> VC.addMiddleLayer
|
||||||
|
{ downcast = identity
|
||||||
|
, current = Api.redactV2
|
||||||
|
, upcast = identity
|
||||||
|
, version = "v1.1"
|
||||||
|
}
|
||||||
|
|> VC.sameForVersion "v1.2"
|
||||||
|
|> VC.sameForVersion "v1.3"
|
||||||
|
|> VC.sameForVersion "v1.4"
|
||||||
|
|> VC.sameForVersion "v1.5"
|
||||||
|
|> VC.mostRecentFromVersionList versions
|
||||||
|
|> Maybe.withDefault (always <| Task.fail X.UnsupportedSpecVersion)
|
||||||
|
|
||||||
|
|
||||||
|
type alias RedactInput =
|
||||||
|
Api.RedactInputV1
|
||||||
|
|
||||||
|
|
||||||
|
type alias RedactOutput =
|
||||||
|
Api.RedactOutputV1
|
|
@ -0,0 +1,38 @@
|
||||||
|
module Internal.Api.Redact.V1.SpecObjects exposing
|
||||||
|
( Redaction
|
||||||
|
, encodeRedaction
|
||||||
|
, redactionDecoder
|
||||||
|
)
|
||||||
|
|
||||||
|
{-| Automatically generated 'SpecObjects'
|
||||||
|
|
||||||
|
Last generated at Unix time 1678053256
|
||||||
|
|
||||||
|
-}
|
||||||
|
|
||||||
|
import Internal.Tools.EncodeExtra exposing (maybeObject)
|
||||||
|
import Json.Decode as D
|
||||||
|
import Json.Encode as E
|
||||||
|
|
||||||
|
|
||||||
|
{-| A confirmation containing the ID for the redaction event.
|
||||||
|
-}
|
||||||
|
type alias Redaction =
|
||||||
|
{ eventId : String
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
encodeRedaction : Redaction -> E.Value
|
||||||
|
encodeRedaction data =
|
||||||
|
maybeObject
|
||||||
|
[ ( "event_id", Just <| E.string data.eventId )
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
redactionDecoder : D.Decoder Redaction
|
||||||
|
redactionDecoder =
|
||||||
|
D.map
|
||||||
|
(\a ->
|
||||||
|
{ eventId = a }
|
||||||
|
)
|
||||||
|
(D.field "event_id" D.string)
|
|
@ -0,0 +1,9 @@
|
||||||
|
version: v1
|
||||||
|
name: SpecObjects
|
||||||
|
objects:
|
||||||
|
Redaction:
|
||||||
|
description: A confirmation containing the ID for the redaction event.
|
||||||
|
fields:
|
||||||
|
event_id:
|
||||||
|
type: string
|
||||||
|
required: true
|
Loading…
Reference in New Issue