2017-05-07 08:31:51 -04:00
|
|
|
module Subscription exposing (subscriptions)
|
|
|
|
|
|
|
|
import Autocomplete
|
|
|
|
import Mastodon.WebSocket
|
2017-05-11 04:55:15 -04:00
|
|
|
import Ports
|
2017-05-07 08:31:51 -04:00
|
|
|
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 =
|
2017-05-10 03:13:25 -04:00
|
|
|
Time.every Time.second Tick
|
2017-05-07 08:31:51 -04:00
|
|
|
|
|
|
|
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
|
2017-05-11 04:55:15 -04:00
|
|
|
|
|
|
|
uploadSuccessSub =
|
|
|
|
Ports.uploadSuccess (DraftEvent << UploadResult)
|
|
|
|
|
|
|
|
uploadErrorSub =
|
|
|
|
Ports.uploadError (DraftEvent << UploadError)
|
2017-05-07 08:31:51 -04:00
|
|
|
in
|
2017-05-11 04:55:15 -04:00
|
|
|
Sub.batch
|
|
|
|
[ timeSub
|
|
|
|
, userWsSub
|
|
|
|
, otherWsSub
|
|
|
|
, autoCompleteSub
|
|
|
|
, uploadSuccessSub
|
|
|
|
, uploadErrorSub
|
|
|
|
]
|