1
0
Fork 0
tooty/src/Subscription.elm

65 lines
1.8 KiB
Elm
Raw Normal View History

module Subscription exposing (subscriptions)
import Autocomplete
import Keyboard
import Mastodon.WebSocket
2017-05-11 08:55:15 +00:00
import Ports
import Time
import Types exposing (..)
subscriptions : Model -> Sub Msg
subscriptions { clients, currentView } =
let
timeSub =
2017-05-10 07:13:25 +00:00
Time.every Time.second Tick
userWsSub =
Mastodon.WebSocket.subscribeToWebSockets
(List.head clients)
Mastodon.WebSocket.UserStream
NewWebsocketUserMessage
|> Sub.map WebSocketEvent
otherWsSub =
if currentView == GlobalTimelineView then
Mastodon.WebSocket.subscribeToWebSockets
(List.head clients)
Mastodon.WebSocket.GlobalPublicStream
NewWebsocketGlobalMessage
|> Sub.map WebSocketEvent
else if currentView == LocalTimelineView then
Mastodon.WebSocket.subscribeToWebSockets
(List.head clients)
Mastodon.WebSocket.LocalPublicStream
NewWebsocketLocalMessage
|> Sub.map WebSocketEvent
else
Sub.none
autoCompleteSub =
Sub.map (DraftEvent << SetAutoState) Autocomplete.subscription
2017-05-11 08:55:15 +00:00
uploadSuccessSub =
Ports.uploadSuccess (DraftEvent << UploadResult)
uploadErrorSub =
Ports.uploadError (DraftEvent << UploadError)
keyDownsSub =
Keyboard.downs (KeyMsg KeyDown)
keyUpsSub =
Keyboard.ups (KeyMsg KeyUp)
in
2017-05-11 08:55:15 +00:00
Sub.batch
[ timeSub
, userWsSub
, otherWsSub
, autoCompleteSub
, uploadSuccessSub
, uploadErrorSub
, keyDownsSub
2017-07-17 14:14:35 +00:00
, keyUpsSub
2017-05-11 08:55:15 +00:00
]