Add invite function

4-transfer-api
Bram 2024-07-22 12:58:52 +02:00
parent 41bee45693
commit a2582f36f9
7 changed files with 62 additions and 12 deletions

View File

@ -1,4 +1,4 @@
module Internal.Api.Invite.Api exposing (InviteInput, Phantom, invite)
module Internal.Api.InviteUser.Api exposing (InviteInput, Phantom, inviteUser)
{-|
@ -14,7 +14,7 @@ room.
If the user was invited to the room, the homeserver will append a m.room.member
event to the room.
@docs InviteInput, Phantom, invite
@docs InviteInput, Phantom, inviteUser
-}
@ -31,8 +31,8 @@ import Internal.Values.Vault as V
{-| Invite a user to a room.
-}
invite : InviteInput -> A.TaskChain (Phantom ph1) (Phantom ph1)
invite =
inviteUser : InviteInput -> A.TaskChain (Phantom ph1) (Phantom ph1)
inviteUser =
A.startWithVersion "r0.0.0" inviteV1
|> A.sameForVersion "r0.0.1"
|> A.sameForVersion "r0.1.0"

View File

@ -1,6 +1,6 @@
module Internal.Api.Main exposing
( Msg
, sendMessageEvent, sendStateEvent, setAccountData, setRoomAccountData, sync
, inviteUser, sendMessageEvent, sendStateEvent, setAccountData, setRoomAccountData, sync
)
{-|
@ -18,7 +18,7 @@ This module is used as reference for getting
## Actions
@docs sendMessageEvent, sendStateEvent, setAccountData, setRoomAccountData, sync
@docs inviteUser, sendMessageEvent, sendStateEvent, setAccountData, setRoomAccountData, sync
-}
@ -28,6 +28,7 @@ import Internal.Values.Context as Context
import Internal.Values.Envelope as E
import Internal.Values.User as User
import Internal.Values.Vault as V
import Internal.Values.User exposing (User)
{-| Update message type that is being returned.
@ -35,6 +36,28 @@ import Internal.Values.Vault as V
type alias Msg =
Backpack
{-| Invite a user to a room.
-}
inviteUser :
E.Envelope a
->
{ reason : Maybe String
, roomId : String
, toMsg : Msg -> msg
, user : User
}
-> Cmd msg
inviteUser env data =
ITask.run
data.toMsg
(ITask.inviteUser
{ reason = data.reason
, roomId = data.roomId
, user = data.user
}
)
(Context.apiFormat env.context)
{-| Send a message event.
-}

View File

@ -12,7 +12,6 @@ This module sends state events to Matrix rooms.
-}
import Internal.Api.Api as A
import Internal.Api.Invite.Api exposing (Phantom)
import Internal.Api.Request as R
import Internal.Config.Log exposing (log)
import Internal.Config.Text as Text

View File

@ -12,7 +12,6 @@ This module allows the developer to set global account data.
-}
import Internal.Api.Api as A
import Internal.Api.Invite.Api exposing (Phantom)
import Internal.Api.Request as R
import Internal.Config.Log exposing (log)
import Internal.Config.Text as Text

View File

@ -12,7 +12,6 @@ This module allows the developer to set account data to a Matrix room.
-}
import Internal.Api.Api as A
import Internal.Api.Invite.Api exposing (Phantom)
import Internal.Api.Request as R
import Internal.Config.Log exposing (log)
import Internal.Config.Text as Text

View File

@ -1,6 +1,6 @@
module Internal.Api.Task exposing
( Task, run, Backpack
, sendMessageEvent, sendStateEvent, setAccountData, setRoomAccountData, sync
, inviteUser, sendMessageEvent, sendStateEvent, setAccountData, setRoomAccountData, sync
)
{-|
@ -23,12 +23,13 @@ up-to-date.
## Tasks
@docs sendMessageEvent, sendStateEvent, setAccountData, setRoomAccountData, sync
@docs inviteUser, sendMessageEvent, sendStateEvent, setAccountData, setRoomAccountData, sync
-}
import Internal.Api.BaseUrl.Api
import Internal.Api.Chain as C
import Internal.Api.InviteUser.Api
import Internal.Api.LoginWithUsernameAndPassword.Api
import Internal.Api.Now.Api
import Internal.Api.Request as Request
@ -46,6 +47,7 @@ import Internal.Values.Envelope as E exposing (EnvelopeUpdate(..))
import Internal.Values.Room exposing (RoomUpdate(..))
import Internal.Values.Vault exposing (VaultUpdate(..))
import Task
import Internal.Values.User exposing (User)
{-| A Backpack is the ultimate message type that gets sent back by the Elm
@ -207,6 +209,15 @@ finishTask uftask =
)
{-| Invite a user to a room.
-}
inviteUser : { reason : Maybe String, roomId : String, user : User } -> Task
inviteUser input =
makeVBA
|> C.andThen (Internal.Api.InviteUser.Api.inviteUser input)
|> finishTask
{-| Establish a Task Chain context where the base URL and supported list of
versions are known.
-}

View File

@ -44,7 +44,7 @@ room. These events are JSON objects that can be shaped in any way or form that
you like. To help other users with decoding your JSON objects, you pass an
`eventType` string which helps them figure out the nature of your JSON object.
@docs sendMessageEvent, sendStateEvent
@docs inviteUser, sendMessageEvent, sendStateEvent
-}
@ -68,6 +68,25 @@ getAccountData key (Room room) =
Envelope.extract (Internal.getAccountData key) room
{-| Invite a user to a room.
-}
invite :
{ reason : Maybe String
, room : Room
, toMsg : Types.VaultUpdate -> msg
, user : Types.User
}
-> Cmd msg
invite data =
case (data.room, data.user) of
(Room room, Types.User user) ->
Api.inviteUser room
{ reason = data.reason
, roomId = roomId data.room
, toMsg = Types.VaultUpdate >> data.toMsg
, user = user.content
}
{-| Get a room's room id. This is an opaque string that distinguishes rooms from
each other.
-}