Compare commits
7 Commits
0a5d9549b0
...
edb869035a
Author | SHA1 | Date |
---|---|---|
|
edb869035a | |
|
c473d60161 | |
|
41ec76822f | |
|
1eb07377fd | |
|
39f8021a8f | |
|
f714438dd4 | |
|
a514497406 |
|
@ -104,9 +104,9 @@ syncV1 data =
|
||||||
, coder = V1.coderSyncResponse
|
, coder = V1.coderSyncResponse
|
||||||
, contextChange = always identity
|
, contextChange = always identity
|
||||||
, method = "GET"
|
, method = "GET"
|
||||||
, path = [ "_matrix", "client", "r0", "sync" ]
|
, path = [ "_matrix", "client", "v3", "sync" ]
|
||||||
, toUpdate =
|
, 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
|
, coder = V2.coderSyncResponse
|
||||||
, contextChange = always identity
|
, contextChange = always identity
|
||||||
, method = "GET"
|
, method = "GET"
|
||||||
, path = [ "_matrix", "client", "r0", "sync" ]
|
, path = [ "_matrix", "client", "v3", "sync" ]
|
||||||
, toUpdate =
|
, 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
|
, coder = V3.coderSyncResponse
|
||||||
, contextChange = always identity
|
, contextChange = always identity
|
||||||
, method = "GET"
|
, method = "GET"
|
||||||
, path = [ "_matrix", "client", "r0", "sync" ]
|
, path = [ "_matrix", "client", "v3", "sync" ]
|
||||||
, toUpdate =
|
, 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
|
, coder = V4.coderSyncResponse
|
||||||
, contextChange = always identity
|
, contextChange = always identity
|
||||||
, method = "GET"
|
, method = "GET"
|
||||||
, path = [ "_matrix", "client", "r0", "sync" ]
|
, path = [ "_matrix", "client", "v3", "sync" ]
|
||||||
, toUpdate =
|
, 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,16 +935,54 @@ updateTimeline { filter, nextBatch, roomId, since } timeline =
|
||||||
timeline.events
|
timeline.events
|
||||||
|> Maybe.map
|
|> Maybe.map
|
||||||
(\events ->
|
(\events ->
|
||||||
R.AddSync
|
let
|
||||||
{ events = List.map (toEvent roomId) events
|
limited : Bool
|
||||||
, filter = filter
|
limited =
|
||||||
, start =
|
Maybe.withDefault False timeline.limited
|
||||||
case timeline.prevBatch of
|
|
||||||
Just _ ->
|
|
||||||
timeline.prevBatch
|
|
||||||
|
|
||||||
Nothing ->
|
newEvents : List Event.Event
|
||||||
since
|
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
|
, end = nextBatch
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -683,16 +683,54 @@ updateJoinedRoom data room =
|
||||||
|
|
||||||
updateTimeline : { filter : Filter, nextBatch : String, roomId : String, since : Maybe String } -> Timeline -> R.RoomUpdate
|
updateTimeline : { filter : Filter, nextBatch : String, roomId : String, since : Maybe String } -> Timeline -> R.RoomUpdate
|
||||||
updateTimeline { filter, nextBatch, roomId, since } timeline =
|
updateTimeline { filter, nextBatch, roomId, since } timeline =
|
||||||
R.AddSync
|
let
|
||||||
{ events = List.map (toEvent roomId) timeline.events
|
limited : Bool
|
||||||
, filter = filter
|
limited =
|
||||||
, start =
|
Maybe.withDefault False timeline.limited
|
||||||
case timeline.prevBatch of
|
|
||||||
Just _ ->
|
|
||||||
timeline.prevBatch
|
|
||||||
|
|
||||||
Nothing ->
|
newEvents : List Event.Event
|
||||||
since
|
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
|
, end = nextBatch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -952,16 +952,54 @@ updateJoinedRoom data room =
|
||||||
|
|
||||||
updateTimeline : { filter : Filter, nextBatch : String, roomId : String, since : Maybe String } -> Timeline -> R.RoomUpdate
|
updateTimeline : { filter : Filter, nextBatch : String, roomId : String, since : Maybe String } -> Timeline -> R.RoomUpdate
|
||||||
updateTimeline { filter, nextBatch, roomId, since } timeline =
|
updateTimeline { filter, nextBatch, roomId, since } timeline =
|
||||||
R.AddSync
|
let
|
||||||
{ events = List.map (toEvent roomId) timeline.events
|
limited : Bool
|
||||||
, filter = filter
|
limited =
|
||||||
, start =
|
Maybe.withDefault False timeline.limited
|
||||||
case timeline.prevBatch of
|
|
||||||
Just _ ->
|
|
||||||
timeline.prevBatch
|
|
||||||
|
|
||||||
Nothing ->
|
newEvents : List Event.Event
|
||||||
since
|
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
|
, end = nextBatch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ coder =
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
(Json.field.required
|
(Json.field.required
|
||||||
{ fieldName = "eventType"
|
{ fieldName = "type"
|
||||||
, toField = .eventType
|
, toField = .eventType
|
||||||
, description =
|
, description =
|
||||||
[ "Event type, generally namespaced using the Java package naming convention."
|
[ "Event type, generally namespaced using the Java package naming convention."
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
module Matrix exposing
|
module Matrix exposing
|
||||||
( Vault, fromUserId, fromUsername
|
( Vault, fromUserId, fromUsername
|
||||||
, VaultUpdate, update, sync
|
, VaultUpdate, update, sync, logs
|
||||||
, addAccessToken, sendMessageEvent
|
, addAccessToken, sendMessageEvent
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ support a monolithic public registry. (:
|
||||||
|
|
||||||
## Keeping the Vault up-to-date
|
## Keeping the Vault up-to-date
|
||||||
|
|
||||||
@docs VaultUpdate, update, sync
|
@docs VaultUpdate, update, sync, logs
|
||||||
|
|
||||||
|
|
||||||
## Debugging
|
## Debugging
|
||||||
|
@ -112,6 +112,28 @@ fromUsername { username, host, port_ } =
|
||||||
|> Vault
|
|> 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.
|
{-| Send a message event to a room.
|
||||||
|
|
||||||
This function can be used in a scenario where the user does not want to sync
|
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
|
exists and the user is able to send a message to, and instead just sends the
|
||||||
request to the Matrix API.
|
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 :
|
sendMessageEvent :
|
||||||
{ content : E.Value
|
{ content : E.Value
|
||||||
|
|
Loading…
Reference in New Issue