elm-matrix-sdk-alpha/src/Matrix/RoomInvite.elm

136 lines
3.5 KiB
Elm
Raw Normal View History

module Matrix.RoomInvite exposing
( RoomInvite, accept, reject, acceptWithReason, rejectWithReason
2023-04-12 13:38:00 +00:00
, roomId, RoomInviteEvent, getAllEvents--, getEvent
2023-03-31 11:50:05 +00:00
, sender, stateKey, eventType, content
)
2023-03-15 14:32:02 +00:00
{-| Sometimes, your user will be invited to a new room!
This module offers you a few simple handles to deal with such invites -
you can accept them, reject them or inspect them for further information.
# Invitations
@docs RoomInvite, accept, reject, acceptWithReason, rejectWithReason
# Exploring invitations
Sometimes, you may want to display information about the room.
Be careful though, anyone can invite you to any room! This means that room invites
may contain offensive, shocking or other unwanted content that the user may not
want to see.
@docs roomId, RoomInviteEvent, getEvent, getAllEvents
2023-03-16 09:24:03 +00:00
Once you have the event you want, you can explore it with the following functions.
2023-03-31 11:50:05 +00:00
@docs sender, stateKey, eventType, content
2023-03-16 09:24:03 +00:00
2023-03-15 14:32:02 +00:00
-}
import Internal.Api.VaultUpdate exposing (VaultUpdate)
import Internal.Invite as Internal
import Internal.Tools.Exceptions as X
import Internal.Values.RoomInvite as IR
import Json.Encode as E
import Task exposing (Task)
{-| The `RoomInvite` type serves as an invite to a given room.
-}
type alias RoomInvite =
Internal.RoomInvite
{-| If you would like to join a room, you can accept the offer.
-}
accept : RoomInvite -> Task X.Error VaultUpdate
accept invite =
Internal.accept { invite = invite, reason = Nothing }
{-| If you don't want to join the room, you can reject the offer.
-}
reject : RoomInvite -> Task X.Error VaultUpdate
reject invite =
Internal.reject { invite = invite, reason = Nothing }
{-| If the Matrix server supports it, you can add a reason for accepting an invite.
-}
acceptWithReason : String -> RoomInvite -> Task X.Error VaultUpdate
acceptWithReason reason invite =
Internal.accept { invite = invite, reason = Just reason }
{-| If the Matrix server supports it, you can add a reason for rejecting an invite.
-}
rejectWithReason : String -> RoomInvite -> Task X.Error VaultUpdate
rejectWithReason reason invite =
Internal.reject { invite = invite, reason = Just reason }
{-| Get the room id of the invited room.
-}
roomId : RoomInvite -> String
roomId =
Internal.roomId
2023-03-15 14:32:02 +00:00
{-| The `RoomInviteEvent` type represents a stripped event that your user can see while they haven't joined the group yet.
The invite includes a bunch of these events to tell you what the room looks like, who may be part of it,
and other information that will give you a hint of what kind of room it is.
-}
type alias RoomInviteEvent =
IR.RoomInviteEvent
{-| Get the Matrix user that originally sent this event.
-}
sender : RoomInviteEvent -> String
sender =
IR.sender
{-| Get the content of the event.
-}
content : RoomInviteEvent -> E.Value
content =
IR.content
{-| Get the event's content type.
-}
2023-03-31 11:50:05 +00:00
eventType : RoomInviteEvent -> String
eventType =
IR.eventType
2023-03-15 14:32:02 +00:00
{-| Get the event's state key.
-}
stateKey : RoomInviteEvent -> String
stateKey =
IR.stateKey
-- -- TODO: Fix this
-- {-| Get a specific event with a specific event content type and state key, if it exists.
-- -}
-- getEvent : { eventType : String, stateKey : String } -> RoomInvite -> Maybe RoomInviteEvent
-- getEvent data invite =
-- invite
-- |> Internal.withoutCredentials
-- |> IR.getEvent data
2023-03-15 14:32:02 +00:00
{-| Instead of looking at just one event, get all events in a list.
-}
getAllEvents : RoomInvite -> List RoomInviteEvent
getAllEvents =
Internal.getAllEvents