Add ways to navigate through rooms

pull/32/head
Bram 2024-07-13 09:50:39 +02:00
parent a95fbbb856
commit 458ea59425
3 changed files with 41 additions and 4 deletions

View File

@ -1,7 +1,7 @@
module Internal.Values.Vault exposing
( Vault, init
, VaultUpdate(..), update
, fromRoomId, mapRoom, updateRoom
, rooms, fromRoomId, mapRoom, updateRoom
, getAccountData, setAccountData
)
@ -23,7 +23,7 @@ To update the Vault, one uses VaultUpdate types.
Rooms are environments where people can have a conversation with each other.
@docs fromRoomId, mapRoom, updateRoom
@docs rooms, fromRoomId, mapRoom, updateRoom
## Account data
@ -122,6 +122,13 @@ mapRoom roomId f vault =
{ vault | rooms = Hashdict.map roomId f vault.rooms }
{-| Get a list of all joined rooms present in the vault.
-}
rooms : Vault -> List Room
rooms vault =
Hashdict.values vault.rooms
{-| Set a piece of account data as information in the global vault data.
-}
setAccountData : String -> Json.Value -> Vault -> Vault

View File

@ -1,6 +1,7 @@
module Matrix exposing
( Vault, fromUserId, fromUsername
, VaultUpdate, update
, rooms, fromRoomId
, addAccessToken, sendMessageEvent
)
@ -27,6 +28,11 @@ support a monolithic public registry. (:
@docs VaultUpdate, update
## Exploring the Vault
@docs rooms, fromRoomId
## Debugging
@docs addAccessToken, sendMessageEvent
@ -66,6 +72,14 @@ addAccessToken token (Vault vault) =
|> Vault
{-| Get a room based on its room ID, if the user is a member of that room.
-}
fromRoomId : String -> Vault -> Maybe Types.Room
fromRoomId roomId (Vault vault) =
Envelope.mapMaybe (Internal.fromRoomId roomId) vault
|> Maybe.map Types.Room
{-| Use a fully-fledged Matrix ID to connect.
case Matrix.fromUserId "@alice:example.org" of
@ -112,6 +126,14 @@ fromUsername { username, host, port_ } =
|> Vault
{-| Get a list of all the rooms that the user has joined.
-}
rooms : Vault -> List Types.Room
rooms (Vault vault) =
Envelope.mapList Internal.rooms vault
|> List.map Types.Room
{-| Send a message event to a room.
This function can be used in a scenario where the user does not want to sync

View File

@ -1,5 +1,5 @@
module Matrix.Room exposing
( Room, mostRecentEvents
( Room, mostRecentEvents, roomId
, getAccountData
)
@ -12,7 +12,7 @@ What is usually called a chat, a channel, a conversation or a group chat on
other platforms, the term used in Matrix is a "room". A room is a conversation
where a group of users talk to each other.
@docs Room, mostRecentEvents
@docs Room, mostRecentEvents, roomId
This module exposes various functions that help you inspect various aspects of
a room.
@ -56,6 +56,14 @@ getAccountData key (Room room) =
Envelope.extract (Internal.getAccountData key) room
{-| Get a room's room id. This is an opaque string that distinguishes rooms from
each other.
-}
roomId : Room -> String
roomId (Room room) =
Envelope.extract .roomId room
{-| Get a list of the most recent events sent in the room.
-}
mostRecentEvents : Room -> List Types.Event