Add room navigation functions to exposed library

Merge pull request #32 from noordstar/4-lib-improvement
pull/33/head
BramvdnHeuvel 2024-07-15 16:01:52 +02:00 committed by GitHub
commit 899088d63c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 41 additions and 4 deletions

View File

@ -1,7 +1,7 @@
module Internal.Values.Vault exposing module Internal.Values.Vault exposing
( Vault, init ( Vault, init
, VaultUpdate(..), update , VaultUpdate(..), update
, fromRoomId, mapRoom, updateRoom , rooms, fromRoomId, mapRoom, updateRoom
, getAccountData, setAccountData , 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. Rooms are environments where people can have a conversation with each other.
@docs fromRoomId, mapRoom, updateRoom @docs rooms, fromRoomId, mapRoom, updateRoom
## Account data ## Account data
@ -133,6 +133,13 @@ mapRoom roomId f vault =
{ vault | rooms = Hashdict.map roomId f vault.rooms } { 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. {-| Set a piece of account data as information in the global vault data.
-} -}
setAccountData : String -> Json.Value -> Vault -> Vault setAccountData : String -> Json.Value -> Vault -> Vault

View File

@ -1,6 +1,7 @@
module Matrix exposing module Matrix exposing
( Vault, fromUserId, fromUsername ( Vault, fromUserId, fromUsername
, VaultUpdate, update, sync, logs , VaultUpdate, update, sync, logs
, rooms, fromRoomId
, addAccessToken, sendMessageEvent , addAccessToken, sendMessageEvent
) )
@ -27,6 +28,11 @@ support a monolithic public registry. (:
@docs VaultUpdate, update, sync, logs @docs VaultUpdate, update, sync, logs
## Exploring the Vault
@docs rooms, fromRoomId
## Debugging ## Debugging
@docs addAccessToken, sendMessageEvent @docs addAccessToken, sendMessageEvent
@ -66,6 +72,14 @@ addAccessToken token (Vault 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. {-| Use a fully-fledged Matrix ID to connect.
case Matrix.fromUserId "@alice:example.org" of case Matrix.fromUserId "@alice:example.org" of
@ -112,6 +126,14 @@ fromUsername { username, host, port_ } =
|> Vault |> 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
{-| The VaultUpdate is a complex type that helps update the Vault. However, {-| The VaultUpdate is a complex type that helps update the Vault. However,
it also contains a human output! it also contains a human output!

View File

@ -1,5 +1,5 @@
module Matrix.Room exposing module Matrix.Room exposing
( Room, mostRecentEvents ( Room, mostRecentEvents, roomId
, getAccountData , 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 other platforms, the term used in Matrix is a "room". A room is a conversation
where a group of users talk to each other. 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 This module exposes various functions that help you inspect various aspects of
a room. a room.
@ -56,6 +56,14 @@ getAccountData key (Room room) =
Envelope.extract (Internal.getAccountData key) 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. {-| Get a list of the most recent events sent in the room.
-} -}
mostRecentEvents : Room -> List Types.Event mostRecentEvents : Room -> List Types.Event