2017-05-07 08:31:51 -04:00
|
|
|
module Subscription exposing (subscriptions)
|
|
|
|
|
|
|
|
import Autocomplete
|
|
|
|
import Mastodon.WebSocket
|
|
|
|
import Time
|
|
|
|
import Types exposing (..)
|
|
|
|
|
|
|
|
|
|
|
|
subscriptions : Model -> Sub Msg
|
2017-05-09 12:43:12 -04:00
|
|
|
subscriptions { clients, currentView } =
|
2017-05-07 08:31:51 -04:00
|
|
|
let
|
|
|
|
timeSub =
|
|
|
|
Time.every Time.millisecond Tick
|
|
|
|
|
|
|
|
userWsSub =
|
|
|
|
Mastodon.WebSocket.subscribeToWebSockets
|
2017-05-09 12:43:12 -04:00
|
|
|
(List.head clients)
|
2017-05-07 08:31:51 -04:00
|
|
|
Mastodon.WebSocket.UserStream
|
|
|
|
NewWebsocketUserMessage
|
|
|
|
|> Sub.map WebSocketEvent
|
|
|
|
|
|
|
|
otherWsSub =
|
|
|
|
if currentView == GlobalTimelineView then
|
|
|
|
Mastodon.WebSocket.subscribeToWebSockets
|
2017-05-09 12:43:12 -04:00
|
|
|
(List.head clients)
|
2017-05-07 08:31:51 -04:00
|
|
|
Mastodon.WebSocket.GlobalPublicStream
|
|
|
|
NewWebsocketGlobalMessage
|
|
|
|
|> Sub.map WebSocketEvent
|
|
|
|
else if currentView == LocalTimelineView then
|
|
|
|
Mastodon.WebSocket.subscribeToWebSockets
|
2017-05-09 12:43:12 -04:00
|
|
|
(List.head clients)
|
2017-05-07 08:31:51 -04:00
|
|
|
Mastodon.WebSocket.LocalPublicStream
|
|
|
|
NewWebsocketLocalMessage
|
|
|
|
|> Sub.map WebSocketEvent
|
|
|
|
else
|
|
|
|
Sub.none
|
|
|
|
|
|
|
|
autoCompleteSub =
|
|
|
|
Sub.map (DraftEvent << SetAutoState) Autocomplete.subscription
|
|
|
|
in
|
|
|
|
[ timeSub, userWsSub, otherWsSub, autoCompleteSub ]
|
|
|
|
|> Sub.batch
|