Add invite sending
parent
dc39036162
commit
bd73b97e93
|
@ -2,6 +2,7 @@ module Internal.Api.All exposing (..)
|
|||
|
||||
import Hash
|
||||
import Internal.Api.GetEvent.Main as GetEvent
|
||||
import Internal.Api.Invite.Main as Invite
|
||||
import Internal.Api.JoinedMembers.Main as JoinedMembers
|
||||
import Internal.Api.PreApi.Main as PreApi
|
||||
import Internal.Api.PreApi.Objects.Versions as V
|
||||
|
@ -21,6 +22,7 @@ type CredUpdate
|
|||
= MultipleUpdates (List CredUpdate)
|
||||
-- Updates as a result of API calls
|
||||
| GetEvent GetEvent.EventInput GetEvent.EventOutput
|
||||
| InviteSent Invite.InviteInput Invite.InviteOutput
|
||||
| JoinedMembersToRoom JoinedMembers.JoinedMembersInput JoinedMembers.JoinedMembersOutput
|
||||
| MessageEventSent SendMessageEvent.SendMessageEventInput SendMessageEvent.SendMessageEventOutput
|
||||
| RedactedEvent Redact.RedactInput Redact.RedactOutput
|
||||
|
@ -72,6 +74,44 @@ getEvent data =
|
|||
(PreApi.accessToken data.baseUrl data.accessToken)
|
||||
(PreApi.versions data.baseUrl data.versions)
|
||||
|
||||
type alias InviteInput =
|
||||
{ accessToken : AccessToken
|
||||
, baseUrl : String
|
||||
, reason : Maybe String
|
||||
, roomId : String
|
||||
, userId : String
|
||||
, versions : Maybe V.Versions
|
||||
}
|
||||
|
||||
{-| Send an invite to join a room.
|
||||
-}
|
||||
invite : InviteInput -> Future CredUpdate
|
||||
invite data =
|
||||
VG.withInfo2
|
||||
(\accessToken versions ->
|
||||
let
|
||||
input : Invite.InviteInput
|
||||
input =
|
||||
{ accessToken = accessToken
|
||||
, baseUrl = data.baseUrl
|
||||
, reason = data.reason
|
||||
, roomId = data.roomId
|
||||
, userId = data.userId
|
||||
}
|
||||
in
|
||||
Invite.invite versions.versions input
|
||||
|> Task.map
|
||||
(\output ->
|
||||
MultipleUpdates
|
||||
[ InviteSent input output
|
||||
, UpdateAccessToken accessToken
|
||||
, UpdateVersions versions
|
||||
]
|
||||
)
|
||||
)
|
||||
(PreApi.accessToken data.baseUrl data.accessToken)
|
||||
(PreApi.versions data.baseUrl data.versions)
|
||||
|
||||
|
||||
type alias JoinedMembersInput =
|
||||
{ accessToken : AccessToken
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
module Internal.Api.Invite.Api exposing (..)
|
||||
|
||||
import Internal.Api.Request as R
|
||||
import Internal.Tools.Exceptions as X
|
||||
import Json.Decode as D
|
||||
import Task exposing (Task)
|
||||
|
||||
type alias InviteInputV1 =
|
||||
{ accessToken : String
|
||||
, baseUrl : String
|
||||
, roomId : String
|
||||
, userId : String
|
||||
}
|
||||
|
||||
type alias InviteInputV2 =
|
||||
{ accessToken : String
|
||||
, baseUrl : String
|
||||
, reason : Maybe String
|
||||
, roomId : String
|
||||
, userId : String
|
||||
}
|
||||
|
||||
type alias InviteOutputV1 = ()
|
||||
|
||||
inviteV1 : InviteInputV1 -> Task X.Error InviteOutputV1
|
||||
inviteV1 data =
|
||||
R.rawApiCall
|
||||
{ headers = R.WithAccessToken data.accessToken
|
||||
, method = "POST"
|
||||
, baseUrl = data.baseUrl
|
||||
, path = "/_matrix/client/r0/rooms/{roomId}/invite"
|
||||
, pathParams =
|
||||
[ ( "roomId", data.roomId )
|
||||
]
|
||||
, queryParams = []
|
||||
, bodyParams =
|
||||
[ R.RequiredString "user_id" data.userId
|
||||
]
|
||||
, timeout = Nothing
|
||||
, decoder = always (D.map (always ()) D.value)
|
||||
}
|
||||
|
||||
inviteV2 : InviteInputV2 -> Task X.Error InviteOutputV1
|
||||
inviteV2 data =
|
||||
R.rawApiCall
|
||||
{ headers = R.WithAccessToken data.accessToken
|
||||
, method = "POST"
|
||||
, baseUrl = data.baseUrl
|
||||
, path = "/_matrix/client/r0/rooms/{roomId}/invite"
|
||||
, pathParams =
|
||||
[ ( "roomId", data.roomId )
|
||||
]
|
||||
, queryParams = []
|
||||
, bodyParams =
|
||||
[ R.RequiredString "user_id" data.userId
|
||||
, R.OptionalString "reason" data.reason
|
||||
]
|
||||
, timeout = Nothing
|
||||
, decoder = always (D.map (always ()) D.value)
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
module Internal.Api.Invite.Main exposing (..)
|
||||
|
||||
import Internal.Api.Invite.Api as Api
|
||||
import Internal.Tools.Exceptions as X
|
||||
import Internal.Tools.VersionControl as VC
|
||||
import Task exposing (Task)
|
||||
|
||||
|
||||
invite : List String -> InviteInput -> Task X.Error InviteOutput
|
||||
invite versions =
|
||||
VC.withBottomLayer
|
||||
{ current = Api.inviteV1
|
||||
, 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 =
|
||||
(\data ->
|
||||
{ accessToken = data.accessToken
|
||||
, baseUrl = data.baseUrl
|
||||
, roomId = data.roomId
|
||||
, userId = data.userId
|
||||
}
|
||||
)
|
||||
, current = Api.inviteV2
|
||||
, 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 InviteInput =
|
||||
Api.InviteInputV2
|
||||
|
||||
type alias InviteOutput =
|
||||
Api.InviteOutputV1
|
|
@ -36,9 +36,29 @@ Note that **under development** doesn't always mean that it _will be_ supported.
|
|||
| r0.0.1 || ❌ | ✔️ |
|
||||
| r0.0.0 || ❌ | ✔️ |
|
||||
|
||||
## Changing room member status
|
||||
|
||||
| **Spec version** | | Inviting | Joining room id |
|
||||
| ---------------- | - | -------- | --------------- |
|
||||
| v1.6 || ⚠️ | ⚠️ |
|
||||
| v1.5 || ✔️ | ⚠️ |
|
||||
| v1.4 || ✔️ | ⚠️ |
|
||||
| v1.3 || ✔️ | ⚠️ |
|
||||
| v1.2 || ✔️ | ⚠️ |
|
||||
| v1.1 || ✔️ | ⚠️ |
|
||||
| r0.6.1 || ✔️ | ⚠️ |
|
||||
| r0.6.0 || ✔️ | ⚠️ |
|
||||
| r0.5.0 || ✔️ | ⚠️ |
|
||||
| r0.4.0 || ✔️ | ⚠️ |
|
||||
| r0.3.0 || ✔️ | ⚠️ |
|
||||
| r0.2.0 || ✔️ | ⚠️ |
|
||||
| r0.1.0 || ✔️ | ⚠️ |
|
||||
| r0.0.1 || ✔️ | ⚠️ |
|
||||
| r0.0.0 || ✔️ | ⚠️ |
|
||||
|
||||
## Getting events for a room
|
||||
|
||||
| **Spec version** | | Event | Joined members | Members | Curren state | State event | Event at timestamp |
|
||||
| **Spec version** | | Event | Joined members | Members | Current state | State event | Event at timestamp |
|
||||
| ---------------- | - | ----- | -------------- | ------- | ------------ | ----------- | ------------------ |
|
||||
| v1.6 || ⚠️ | ⚠️ | ⚠️ | ⚠️ | ⚠️ | ⚠️ |
|
||||
| v1.5 || ✔️ | ✔️ | ⚡ | ⚡ | ⚡ | ⛔ |
|
||||
|
|
|
@ -106,12 +106,20 @@ updateWith credUpdate ((Credentials ({ cred, context } as data)) as credentials)
|
|||
Nothing ->
|
||||
credentials
|
||||
|
||||
-- TODO
|
||||
Api.InviteSent _ _ ->
|
||||
credentials
|
||||
|
||||
Api.JoinedMembersToRoom _ _ ->
|
||||
credentials
|
||||
|
||||
-- TODO
|
||||
Api.MessageEventSent _ _ ->
|
||||
credentials
|
||||
|
||||
-- TODO
|
||||
Api.RedactedEvent _ _ ->
|
||||
credentials
|
||||
|
||||
-- TODO
|
||||
Api.StateEventSent _ _ ->
|
||||
|
|
|
@ -4,7 +4,7 @@ import Dict exposing (Dict)
|
|||
import Internal.Tools.Hashdict as Hashdict exposing (Hashdict)
|
||||
import Internal.Tools.SpecEnums exposing (SessionDescriptionType(..))
|
||||
import Internal.Values.Event exposing (BlindEvent, IEvent)
|
||||
import Internal.Values.StateManager exposing (StateManager)
|
||||
import Internal.Values.StateManager as StateManager exposing (StateManager)
|
||||
import Internal.Values.Timeline as Timeline exposing (Timeline)
|
||||
import Json.Encode as E
|
||||
|
||||
|
@ -51,6 +51,12 @@ getEventById : String -> IRoom -> Maybe IEvent
|
|||
getEventById eventId (IRoom room) =
|
||||
Hashdict.get eventId room.events
|
||||
|
||||
getStateEvent : { eventType : String, stateKey : String } -> IRoom -> Maybe IEvent
|
||||
getStateEvent data (IRoom room) =
|
||||
room.timeline
|
||||
|> Timeline.mostRecentState
|
||||
|> StateManager.getStateEvent data
|
||||
|
||||
|
||||
{-| Get the room's id.
|
||||
-}
|
||||
|
|
|
@ -18,8 +18,8 @@ addEvent event oldManager =
|
|||
oldManager
|
||||
|
||||
|
||||
getStateEvent : String -> String -> StateManager -> Maybe IEvent
|
||||
getStateEvent eventType stateKey =
|
||||
getStateEvent : { eventType : String, stateKey : String } -> StateManager -> Maybe IEvent
|
||||
getStateEvent { eventType, stateKey } =
|
||||
Dict.get ( eventType, stateKey )
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue