Compare commits

...

6 Commits

Author SHA1 Message Date
BramvdnHeuvel c473d60161
Merge branch 'develop' into 4-transfer-api 2024-07-13 09:58:40 +02:00
BramvdnHeuvel 41ec76822f
Add logs function to Matrix
Merge pull request #27 from noordstar/4-log-reader
2024-07-13 09:57:18 +02:00
Bram 1eb07377fd Fix StrippedEvent JSON coder 2024-07-13 09:39:14 +02:00
Bram 39f8021a8f Fix spec misconception
Apparently, the  field is also meant for other reasons than the cputime         unlimited
filesize        unlimited
datasize        unlimited
stacksize       8MB
coredumpsize    unlimited
resident        unlimited
maxproc         62741
descriptors     524288
memorylocked    8MB
addressspace    unlimited
maxfilelocks    unlimited
sigpending      62741
msgqueue        819200
nice            0
rt_priority     0
rt_time         unlimited field on the filter, despite the description suggesting otherwise.
2024-07-13 09:38:57 +02:00
Bram f714438dd4 Add logs function for better runtime documentation 2024-06-03 11:05:06 +02:00
Bram a514497406 Improve documentation of sendMessageEvent 2024-06-03 11:04:34 +02:00
6 changed files with 192 additions and 44 deletions

View File

@ -104,9 +104,9 @@ syncV1 data =
, coder = V1.coderSyncResponse
, contextChange = always identity
, method = "GET"
, path = [ "_matrix", "client", "r0", "sync" ]
, path = [ "_matrix", "client", "v3", "sync" ]
, toUpdate =
V1.updateSyncResponse { filter = Filter.pass, since = data.since }
Debug.log "Handling output v1" >> V1.updateSyncResponse { filter = Filter.pass, since = data.since } >> Debug.log "Received"
}
@ -126,9 +126,9 @@ syncV2 data =
, coder = V2.coderSyncResponse
, contextChange = always identity
, method = "GET"
, path = [ "_matrix", "client", "r0", "sync" ]
, path = [ "_matrix", "client", "v3", "sync" ]
, toUpdate =
V2.updateSyncResponse { filter = Filter.pass, since = data.since }
Debug.log "Handling output v2" >> V2.updateSyncResponse { filter = Filter.pass, since = data.since } >> Debug.log "Received"
}
@ -148,9 +148,9 @@ syncV3 data =
, coder = V3.coderSyncResponse
, contextChange = always identity
, method = "GET"
, path = [ "_matrix", "client", "r0", "sync" ]
, path = [ "_matrix", "client", "v3", "sync" ]
, toUpdate =
V3.updateSyncResponse { filter = Filter.pass, since = data.since }
Debug.log "Handling output v3" >> V3.updateSyncResponse { filter = Filter.pass, since = data.since } >> Debug.log "Received"
}
@ -170,7 +170,7 @@ syncV4 data =
, coder = V4.coderSyncResponse
, contextChange = always identity
, method = "GET"
, path = [ "_matrix", "client", "r0", "sync" ]
, path = [ "_matrix", "client", "v3", "sync" ]
, toUpdate =
V4.updateSyncResponse { filter = Filter.pass, since = data.since }
Debug.log "Handling output v4" >> V4.updateSyncResponse { filter = Filter.pass, since = data.since } >> Debug.log "Received"
}

View File

@ -935,18 +935,56 @@ updateTimeline { filter, nextBatch, roomId, since } timeline =
timeline.events
|> Maybe.map
(\events ->
R.AddSync
{ events = List.map (toEvent roomId) events
, filter = filter
, start =
case timeline.prevBatch of
Just _ ->
timeline.prevBatch
let
limited : Bool
limited =
Maybe.withDefault False timeline.limited
Nothing ->
since
, end = nextBatch
}
newEvents : List Event.Event
newEvents =
List.map (toEvent roomId) events
in
case ( limited, timeline.prevBatch ) of
( False, Just p ) ->
if timeline.prevBatch == since then
R.AddSync
{ events = newEvents
, filter = filter
, start = Just p
, end = nextBatch
}
else
R.More
[ R.AddSync
{ events = []
, filter = filter
, start = since
, end = p
}
, R.AddSync
{ events = newEvents
, filter = filter
, start = Just p
, end = nextBatch
}
]
( False, Nothing ) ->
R.AddSync
{ events = newEvents
, filter = filter
, start = since
, end = nextBatch
}
( True, _ ) ->
R.AddSync
{ events = newEvents
, filter = filter
, start = timeline.prevBatch
, end = nextBatch
}
)

View File

@ -683,18 +683,56 @@ updateJoinedRoom data room =
updateTimeline : { filter : Filter, nextBatch : String, roomId : String, since : Maybe String } -> Timeline -> R.RoomUpdate
updateTimeline { filter, nextBatch, roomId, since } timeline =
R.AddSync
{ events = List.map (toEvent roomId) timeline.events
, filter = filter
, start =
case timeline.prevBatch of
Just _ ->
timeline.prevBatch
let
limited : Bool
limited =
Maybe.withDefault False timeline.limited
Nothing ->
since
, end = nextBatch
}
newEvents : List Event.Event
newEvents =
List.map (toEvent roomId) timeline.events
in
case ( limited, timeline.prevBatch ) of
( False, Just p ) ->
if timeline.prevBatch == since then
R.AddSync
{ events = newEvents
, filter = filter
, start = Just p
, end = nextBatch
}
else
R.More
[ R.AddSync
{ events = []
, filter = filter
, start = since
, end = p
}
, R.AddSync
{ events = newEvents
, filter = filter
, start = Just p
, end = nextBatch
}
]
( False, Nothing ) ->
R.AddSync
{ events = newEvents
, filter = filter
, start = since
, end = nextBatch
}
( True, _ ) ->
R.AddSync
{ events = newEvents
, filter = filter
, start = timeline.prevBatch
, end = nextBatch
}
toEvent : String -> ClientEventWithoutRoomID -> Event.Event

View File

@ -952,18 +952,56 @@ updateJoinedRoom data room =
updateTimeline : { filter : Filter, nextBatch : String, roomId : String, since : Maybe String } -> Timeline -> R.RoomUpdate
updateTimeline { filter, nextBatch, roomId, since } timeline =
R.AddSync
{ events = List.map (toEvent roomId) timeline.events
, filter = filter
, start =
case timeline.prevBatch of
Just _ ->
timeline.prevBatch
let
limited : Bool
limited =
Maybe.withDefault False timeline.limited
Nothing ->
since
, end = nextBatch
}
newEvents : List Event.Event
newEvents =
List.map (toEvent roomId) timeline.events
in
case ( limited, timeline.prevBatch ) of
( False, Just p ) ->
if timeline.prevBatch == since then
R.AddSync
{ events = newEvents
, filter = filter
, start = Just p
, end = nextBatch
}
else
R.More
[ R.AddSync
{ events = []
, filter = filter
, start = since
, end = p
}
, R.AddSync
{ events = newEvents
, filter = filter
, start = Just p
, end = nextBatch
}
]
( False, Nothing ) ->
R.AddSync
{ events = newEvents
, filter = filter
, start = since
, end = nextBatch
}
( True, _ ) ->
R.AddSync
{ events = newEvents
, filter = filter
, start = timeline.prevBatch
, end = nextBatch
}
toEvent : String -> ClientEventWithoutRoomID -> Event.Event

View File

@ -36,7 +36,7 @@ coder =
}
)
(Json.field.required
{ fieldName = "eventType"
{ fieldName = "type"
, toField = .eventType
, description =
[ "Event type, generally namespaced using the Java package naming convention."

View File

@ -1,6 +1,6 @@
module Matrix exposing
( Vault, fromUserId, fromUsername
, VaultUpdate, update, sync
, VaultUpdate, update, sync, logs
, addAccessToken, sendMessageEvent
)
@ -24,7 +24,7 @@ support a monolithic public registry. (:
## Keeping the Vault up-to-date
@docs VaultUpdate, update, sync
@docs VaultUpdate, update, sync, logs
## Debugging
@ -112,6 +112,28 @@ fromUsername { username, host, port_ } =
|> Vault
{-| The VaultUpdate is a complex type that helps update the Vault. However,
it also contains a human output!
Using this function, you can get a human output that describes everything that
the VaultUpdate has to tell the Vault.
The `channel` field describes the context of the log, allowing you to filter
further. For example:
- `debug` is a comprehensive channel describing everything the Elm runtime has
executed.
- `warn` contains warnings that aren't breaking, but relevant.
- `securityWarn` warns about potential security issues or potential attacks.
- `error` has errors that were encountered.
- `caughtError` has errors that were dealt with successfully.
-}
logs : VaultUpdate -> List { channel : String, content : String }
logs (VaultUpdate vu) =
vu.logs
{-| Send a message event to a room.
This function can be used in a scenario where the user does not want to sync
@ -119,6 +141,18 @@ the client, or is unable to. This function doesn't check whether the given room
exists and the user is able to send a message to, and instead just sends the
request to the Matrix API.
The fields stand for the following:
- `content` is the JSON object that is sent to the Matrix room.
- `eventType` is the event type that is sent to the Matrix room.
- `roomId` is the Matrix room ID.
- `toMsg` is the `msg` type that is returned after the message has been sent.
- `transactionId` is a unique identifier that helps the Matrix server
distringuish messages. If you send the same message with the same transactionId,
the server promises to register it only once.
- `vault` is the Matrix Vault that contains all the latest and most relevant
information.
-}
sendMessageEvent :
{ content : E.Value