Compare commits
7 Commits
0a5d9549b0
...
edb869035a
Author | SHA1 | Date |
---|---|---|
BramvdnHeuvel | edb869035a | |
BramvdnHeuvel | c473d60161 | |
BramvdnHeuvel | 41ec76822f | |
Bram | 1eb07377fd | |
Bram | 39f8021a8f | |
Bram | f714438dd4 | |
Bram | a514497406 |
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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."
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue