Add functionality to join rooms by their id
parent
27b3fc562e
commit
45142509d3
|
@ -0,0 +1,40 @@
|
||||||
|
module Internal.Api.JoinRoomById.Api exposing (..)
|
||||||
|
|
||||||
|
import Internal.Api.Request as R
|
||||||
|
import Internal.Tools.Context exposing (Context, VBA)
|
||||||
|
import Internal.Tools.Exceptions as X
|
||||||
|
import Json.Decode as D
|
||||||
|
import Task exposing (Task)
|
||||||
|
|
||||||
|
|
||||||
|
type alias JoinRoomByIdInputV1 =
|
||||||
|
{ roomId : String }
|
||||||
|
|
||||||
|
|
||||||
|
type alias JoinRoomByIdInputV2 =
|
||||||
|
{ roomId : String, reason : Maybe String }
|
||||||
|
|
||||||
|
|
||||||
|
type alias JoinRoomByIdOutputV1 =
|
||||||
|
{ roomId : String }
|
||||||
|
|
||||||
|
|
||||||
|
joinRoomByIdV1 : JoinRoomByIdInputV1 -> Context (VBA a) -> Task X.Error JoinRoomByIdOutputV1
|
||||||
|
joinRoomByIdV1 { roomId } =
|
||||||
|
R.callApi "POST" "/_matrix/client/r0/rooms/{roomId}/join"
|
||||||
|
>> R.withAttributes
|
||||||
|
[ R.accessToken
|
||||||
|
, R.replaceInUrl "roomId" roomId
|
||||||
|
]
|
||||||
|
>> R.toTask (D.map (\r -> { roomId = r }) (D.field "room_id" D.string))
|
||||||
|
|
||||||
|
|
||||||
|
joinRoomByIdV2 : JoinRoomByIdInputV2 -> Context (VBA a) -> Task X.Error JoinRoomByIdOutputV1
|
||||||
|
joinRoomByIdV2 { roomId, reason } =
|
||||||
|
R.callApi "POST" "/_matrix/client/v3/rooms/{roomId}/join"
|
||||||
|
>> R.withAttributes
|
||||||
|
[ R.accessToken
|
||||||
|
, R.replaceInUrl "roomId" roomId
|
||||||
|
, R.bodyOpString "reason" reason
|
||||||
|
]
|
||||||
|
>> R.toTask (D.map (\r -> { roomId = r }) (D.field "room_id" D.string))
|
|
@ -0,0 +1,45 @@
|
||||||
|
module Internal.Api.JoinRoomById.Main exposing (..)
|
||||||
|
|
||||||
|
import Internal.Api.JoinRoomById.Api as Api
|
||||||
|
import Internal.Tools.Context as Context exposing (Context, VBA)
|
||||||
|
import Internal.Tools.Exceptions as X
|
||||||
|
import Internal.Tools.VersionControl as VC
|
||||||
|
import Task exposing (Task)
|
||||||
|
|
||||||
|
|
||||||
|
joinRoomById : Context (VBA a) -> JoinRoomByIdInput -> Task X.Error JoinRoomByIdOutput
|
||||||
|
joinRoomById context input =
|
||||||
|
VC.withBottomLayer
|
||||||
|
{ current = Api.joinRoomByIdV1
|
||||||
|
, 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 -> { roomId = data.roomId }
|
||||||
|
, current = Api.joinRoomByIdV2
|
||||||
|
, upcast = identity
|
||||||
|
, version = "v1.1"
|
||||||
|
}
|
||||||
|
|> VC.sameForVersion "v1.2"
|
||||||
|
|> VC.sameForVersion "v1.3"
|
||||||
|
|> VC.sameForVersion "v1.4"
|
||||||
|
|> VC.sameForVersion "v1.5"
|
||||||
|
|> VC.mostRecentFromVersionList (Context.getVersions context)
|
||||||
|
|> Maybe.withDefault (always <| always <| Task.fail X.UnsupportedSpecVersion)
|
||||||
|
|> (|>) input
|
||||||
|
|> (|>) context
|
||||||
|
|
||||||
|
|
||||||
|
type alias JoinRoomByIdInput =
|
||||||
|
Api.JoinRoomByIdInputV2
|
||||||
|
|
||||||
|
|
||||||
|
type alias JoinRoomByIdOutput =
|
||||||
|
Api.JoinRoomByIdOutputV1
|
|
@ -41,20 +41,20 @@ Note that **under development** doesn't always mean that it _will be_ supported.
|
||||||
| **Spec version** | | Inviting | Joining room id |
|
| **Spec version** | | Inviting | Joining room id |
|
||||||
| ---------------- | - | -------- | --------------- |
|
| ---------------- | - | -------- | --------------- |
|
||||||
| 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 || ✔️ | ⚠️ |
|
| r0.0.0 || ✔️ | ✔️ |
|
||||||
|
|
||||||
## Getting events for a room
|
## Getting events for a room
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import Internal.Api.Chain as Chain
|
||||||
import Internal.Api.Credentials as Cred exposing (Credentials)
|
import Internal.Api.Credentials as Cred exposing (Credentials)
|
||||||
import Internal.Api.GetEvent.Main exposing (EventInput)
|
import Internal.Api.GetEvent.Main exposing (EventInput)
|
||||||
import Internal.Api.Invite.Main exposing (InviteInput)
|
import Internal.Api.Invite.Main exposing (InviteInput)
|
||||||
|
import Internal.Api.JoinRoomById.Main exposing (JoinRoomByIdInput)
|
||||||
import Internal.Api.JoinedMembers.Main exposing (JoinedMembersInput)
|
import Internal.Api.JoinedMembers.Main exposing (JoinedMembersInput)
|
||||||
import Internal.Api.SendStateKey.Main exposing (SendStateKeyInput)
|
import Internal.Api.SendStateKey.Main exposing (SendStateKeyInput)
|
||||||
import Internal.Api.Sync.Main exposing (SyncInput)
|
import Internal.Api.Sync.Main exposing (SyncInput)
|
||||||
|
@ -47,6 +48,13 @@ joinedMembers data cred =
|
||||||
|> C.toTask
|
|> C.toTask
|
||||||
|
|
||||||
|
|
||||||
|
joinRoomById : JoinRoomByIdInput -> Credentials -> FutureTask
|
||||||
|
joinRoomById data cred =
|
||||||
|
C.makeVBA cred
|
||||||
|
|> Chain.andThen (C.joinRoomById data)
|
||||||
|
|> C.toTask
|
||||||
|
|
||||||
|
|
||||||
type alias RedactInput =
|
type alias RedactInput =
|
||||||
{ eventId : String
|
{ eventId : String
|
||||||
, extraTransactionNoise : String
|
, extraTransactionNoise : String
|
||||||
|
|
|
@ -4,6 +4,7 @@ import Internal.Api.Chain as Chain exposing (IdemChain, TaskChain)
|
||||||
import Internal.Api.Credentials as Credentials exposing (Credentials)
|
import Internal.Api.Credentials as Credentials exposing (Credentials)
|
||||||
import Internal.Api.GetEvent.Main as GetEvent
|
import Internal.Api.GetEvent.Main as GetEvent
|
||||||
import Internal.Api.Invite.Main as Invite
|
import Internal.Api.Invite.Main as Invite
|
||||||
|
import Internal.Api.JoinRoomById.Main as JoinRoomById
|
||||||
import Internal.Api.JoinedMembers.Main as JoinedMembers
|
import Internal.Api.JoinedMembers.Main as JoinedMembers
|
||||||
import Internal.Api.LoginWithUsernameAndPassword.Main as LoginWithUsernameAndPassword
|
import Internal.Api.LoginWithUsernameAndPassword.Main as LoginWithUsernameAndPassword
|
||||||
import Internal.Api.Redact.Main as Redact
|
import Internal.Api.Redact.Main as Redact
|
||||||
|
@ -25,6 +26,7 @@ type VaultUpdate
|
||||||
| GetEvent GetEvent.EventInput GetEvent.EventOutput
|
| GetEvent GetEvent.EventInput GetEvent.EventOutput
|
||||||
| InviteSent Invite.InviteInput Invite.InviteOutput
|
| InviteSent Invite.InviteInput Invite.InviteOutput
|
||||||
| JoinedMembersToRoom JoinedMembers.JoinedMembersInput JoinedMembers.JoinedMembersOutput
|
| JoinedMembersToRoom JoinedMembers.JoinedMembersInput JoinedMembers.JoinedMembersOutput
|
||||||
|
| JoinedRoom JoinRoomById.JoinRoomByIdInput JoinRoomById.JoinRoomByIdOutput
|
||||||
| LoggedInWithUsernameAndPassword LoginWithUsernameAndPassword.LoginWithUsernameAndPasswordInput LoginWithUsernameAndPassword.LoginWithUsernameAndPasswordOutput
|
| LoggedInWithUsernameAndPassword LoginWithUsernameAndPassword.LoginWithUsernameAndPasswordInput LoginWithUsernameAndPassword.LoginWithUsernameAndPasswordOutput
|
||||||
| MessageEventSent SendMessageEvent.SendMessageEventInput SendMessageEvent.SendMessageEventOutput
|
| MessageEventSent SendMessageEvent.SendMessageEventInput SendMessageEvent.SendMessageEventOutput
|
||||||
| RedactedEvent Redact.RedactInput Redact.RedactOutput
|
| RedactedEvent Redact.RedactInput Redact.RedactOutput
|
||||||
|
@ -150,6 +152,19 @@ joinedMembers input =
|
||||||
input
|
input
|
||||||
|
|
||||||
|
|
||||||
|
joinRoomById : JoinRoomById.JoinRoomByIdInput -> IdemChain VaultUpdate (VBA a)
|
||||||
|
joinRoomById input =
|
||||||
|
toChain
|
||||||
|
(\output ->
|
||||||
|
Chain.TaskChainPiece
|
||||||
|
{ contextChange = identity
|
||||||
|
, messages = [ JoinedRoom input output ]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
JoinRoomById.joinRoomById
|
||||||
|
input
|
||||||
|
|
||||||
|
|
||||||
loginWithUsernameAndPassword : LoginWithUsernameAndPassword.LoginWithUsernameAndPasswordInput -> TaskChain VaultUpdate (VB a) (VBA a)
|
loginWithUsernameAndPassword : LoginWithUsernameAndPassword.LoginWithUsernameAndPasswordInput -> TaskChain VaultUpdate (VB a) (VBA a)
|
||||||
loginWithUsernameAndPassword input =
|
loginWithUsernameAndPassword input =
|
||||||
toChain
|
toChain
|
||||||
|
|
|
@ -111,9 +111,14 @@ updateWith vaultUpdate ((Vault ({ cred, context } as data)) as credentials) =
|
||||||
InviteSent _ _ ->
|
InviteSent _ _ ->
|
||||||
credentials
|
credentials
|
||||||
|
|
||||||
|
-- TODO
|
||||||
JoinedMembersToRoom _ _ ->
|
JoinedMembersToRoom _ _ ->
|
||||||
credentials
|
credentials
|
||||||
|
|
||||||
|
-- TODO
|
||||||
|
JoinedRoom _ _ ->
|
||||||
|
credentials
|
||||||
|
|
||||||
-- TODO
|
-- TODO
|
||||||
MessageEventSent _ _ ->
|
MessageEventSent _ _ ->
|
||||||
credentials
|
credentials
|
||||||
|
@ -126,7 +131,6 @@ updateWith vaultUpdate ((Vault ({ cred, context } as data)) as credentials) =
|
||||||
StateEventSent _ _ ->
|
StateEventSent _ _ ->
|
||||||
credentials
|
credentials
|
||||||
|
|
||||||
-- TODO
|
|
||||||
SyncUpdate input output ->
|
SyncUpdate input output ->
|
||||||
let
|
let
|
||||||
jRooms : List IRoom.IRoom
|
jRooms : List IRoom.IRoom
|
||||||
|
@ -186,7 +190,7 @@ updateWith vaultUpdate ((Vault ({ cred, context } as data)) as credentials) =
|
||||||
UpdateVersions versions ->
|
UpdateVersions versions ->
|
||||||
Vault { data | context = Credentials.addVersions versions context }
|
Vault { data | context = Credentials.addVersions versions context }
|
||||||
|
|
||||||
-- TODO: Save all info
|
-- TODO: Save ALL info
|
||||||
LoggedInWithUsernameAndPassword _ output ->
|
LoggedInWithUsernameAndPassword _ output ->
|
||||||
Vault { data | context = Credentials.addToken output.accessToken context }
|
Vault { data | context = Credentials.addToken output.accessToken context }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue