2017-04-29 12:05:06 -04:00
|
|
|
module Command
|
|
|
|
exposing
|
|
|
|
( initCommands
|
|
|
|
, navigateToAuthUrl
|
|
|
|
, registerApp
|
2017-05-09 12:43:12 -04:00
|
|
|
, saveClients
|
2017-04-29 12:05:06 -04:00
|
|
|
, saveRegistration
|
|
|
|
, loadNotifications
|
|
|
|
, loadUserAccount
|
|
|
|
, loadAccount
|
2017-04-29 16:48:55 -04:00
|
|
|
, loadAccountFollowers
|
|
|
|
, loadAccountFollowing
|
2021-01-12 01:08:43 -05:00
|
|
|
, loadAccountPins
|
2017-05-06 05:15:52 -04:00
|
|
|
, loadHomeTimeline
|
2017-05-05 11:26:49 -04:00
|
|
|
, loadLocalTimeline
|
|
|
|
, loadGlobalTimeline
|
|
|
|
, loadAccountTimeline
|
2021-01-11 23:20:35 -05:00
|
|
|
, loadAccountTimelineReplies
|
2017-05-13 09:55:46 -04:00
|
|
|
, loadFavoriteTimeline
|
2017-05-27 03:32:15 -04:00
|
|
|
, loadHashtagTimeline
|
2017-05-25 17:07:17 -04:00
|
|
|
, loadMutes
|
|
|
|
, loadBlocks
|
2017-05-05 11:26:49 -04:00
|
|
|
, loadNextTimeline
|
2017-04-29 16:48:55 -04:00
|
|
|
, loadRelationships
|
2017-04-29 12:05:06 -04:00
|
|
|
, loadThread
|
|
|
|
, loadTimelines
|
|
|
|
, postStatus
|
2017-05-01 16:10:34 -04:00
|
|
|
, updateDomStatus
|
2017-04-29 12:05:06 -04:00
|
|
|
, deleteStatus
|
|
|
|
, reblogStatus
|
|
|
|
, unreblogStatus
|
|
|
|
, favouriteStatus
|
|
|
|
, unfavouriteStatus
|
2017-04-29 16:48:55 -04:00
|
|
|
, follow
|
|
|
|
, unfollow
|
2017-05-25 17:07:17 -04:00
|
|
|
, mute
|
|
|
|
, unmute
|
|
|
|
, block
|
|
|
|
, unblock
|
2017-05-11 04:55:15 -04:00
|
|
|
, uploadMedia
|
2017-04-30 05:08:30 -04:00
|
|
|
, focusId
|
|
|
|
, scrollColumnToTop
|
|
|
|
, scrollColumnToBottom
|
2017-05-04 02:31:58 -04:00
|
|
|
, scrollToThreadStatus
|
2017-05-01 16:10:34 -04:00
|
|
|
, searchAccounts
|
2017-05-30 18:27:30 -04:00
|
|
|
, search
|
2017-06-02 08:11:50 -04:00
|
|
|
, notifyStatus
|
|
|
|
, notifyNotification
|
2021-01-10 22:12:21 -05:00
|
|
|
, clearDraft
|
2017-04-29 12:05:06 -04:00
|
|
|
)
|
|
|
|
|
2017-04-30 05:08:30 -04:00
|
|
|
import Dom
|
|
|
|
import Dom.Scroll
|
2017-04-29 12:05:06 -04:00
|
|
|
import Json.Encode as Encode
|
2017-05-05 11:26:49 -04:00
|
|
|
import Json.Decode as Decode
|
|
|
|
import HttpBuilder
|
|
|
|
import Mastodon.ApiUrl as ApiUrl
|
|
|
|
import Mastodon.Decoder exposing (..)
|
|
|
|
import Mastodon.Encoder exposing (..)
|
2017-11-29 08:06:08 -05:00
|
|
|
import Mastodon.Helper exposing (extractStatusId)
|
2017-05-05 11:26:49 -04:00
|
|
|
import Mastodon.Http exposing (..)
|
2017-04-29 12:05:06 -04:00
|
|
|
import Mastodon.Model exposing (..)
|
|
|
|
import Navigation
|
|
|
|
import Ports
|
2017-05-30 18:27:30 -04:00
|
|
|
import String.Extra exposing (replace)
|
2017-04-30 05:08:30 -04:00
|
|
|
import Task
|
2017-04-29 12:05:06 -04:00
|
|
|
import Types exposing (..)
|
2017-06-02 08:11:50 -04:00
|
|
|
import View.Formatter exposing (textContent)
|
2017-04-29 12:05:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
initCommands : Maybe AppRegistration -> Maybe Client -> Maybe String -> Cmd Msg
|
|
|
|
initCommands registration client authCode =
|
|
|
|
Cmd.batch <|
|
|
|
|
case authCode of
|
|
|
|
Just authCode ->
|
|
|
|
case registration of
|
|
|
|
Just registration ->
|
2017-05-09 12:43:12 -04:00
|
|
|
[ getAccessToken registration authCode
|
|
|
|
, Ports.deleteRegistration ""
|
|
|
|
]
|
2017-04-29 12:05:06 -04:00
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
[]
|
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
[ loadUserAccount client, loadTimelines client ]
|
|
|
|
|
|
|
|
|
2017-05-05 11:26:49 -04:00
|
|
|
getAccessToken : AppRegistration -> String -> Cmd Msg
|
|
|
|
getAccessToken registration authCode =
|
|
|
|
HttpBuilder.post (registration.server ++ ApiUrl.oauthToken)
|
|
|
|
|> HttpBuilder.withJsonBody (authorizationCodeEncoder registration authCode)
|
|
|
|
|> withBodyDecoder (accessTokenDecoder registration)
|
|
|
|
|> send (MastodonEvent << AccessToken)
|
|
|
|
|
|
|
|
|
2017-04-29 12:05:06 -04:00
|
|
|
navigateToAuthUrl : AppRegistration -> Cmd Msg
|
|
|
|
navigateToAuthUrl registration =
|
2017-05-05 11:26:49 -04:00
|
|
|
Navigation.load <| getAuthorizationUrl registration
|
2017-04-29 12:05:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
registerApp : Model -> Cmd Msg
|
|
|
|
registerApp { server, location } =
|
|
|
|
let
|
2017-05-05 11:26:49 -04:00
|
|
|
redirectUri =
|
2017-04-29 12:05:06 -04:00
|
|
|
location.origin ++ location.pathname
|
|
|
|
|
|
|
|
cleanServer =
|
|
|
|
if String.endsWith "/" server then
|
|
|
|
String.dropRight 1 server
|
|
|
|
else
|
|
|
|
server
|
2017-05-05 11:26:49 -04:00
|
|
|
|
|
|
|
clientName =
|
2017-04-29 12:05:06 -04:00
|
|
|
"tooty"
|
2017-05-05 11:26:49 -04:00
|
|
|
|
|
|
|
scope =
|
2017-04-29 12:05:06 -04:00
|
|
|
"read write follow"
|
2017-05-05 11:26:49 -04:00
|
|
|
|
|
|
|
website =
|
2021-01-11 14:36:50 -05:00
|
|
|
"https://git.sdf.org/flewkey/tooty"
|
2017-05-05 11:26:49 -04:00
|
|
|
in
|
|
|
|
HttpBuilder.post (cleanServer ++ ApiUrl.apps)
|
|
|
|
|> withBodyDecoder (appRegistrationDecoder cleanServer scope)
|
|
|
|
|> HttpBuilder.withJsonBody
|
|
|
|
(appRegistrationEncoder clientName redirectUri scope website)
|
|
|
|
|> send (MastodonEvent << AppRegistered)
|
2017-04-29 12:05:06 -04:00
|
|
|
|
|
|
|
|
2017-05-09 12:43:12 -04:00
|
|
|
saveClients : List Client -> Cmd Msg
|
|
|
|
saveClients clients =
|
|
|
|
clients
|
|
|
|
|> List.map clientEncoder
|
|
|
|
|> Encode.list
|
2017-04-29 12:05:06 -04:00
|
|
|
|> Encode.encode 0
|
2017-05-09 12:43:12 -04:00
|
|
|
|> Ports.saveClients
|
2017-04-29 12:05:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
saveRegistration : AppRegistration -> Cmd Msg
|
|
|
|
saveRegistration registration =
|
2017-05-05 11:26:49 -04:00
|
|
|
registrationEncoder registration
|
2017-04-29 12:05:06 -04:00
|
|
|
|> Encode.encode 0
|
|
|
|
|> Ports.saveRegistration
|
|
|
|
|
|
|
|
|
2017-05-05 17:35:54 -04:00
|
|
|
loadNotifications : Maybe Client -> Maybe String -> Cmd Msg
|
|
|
|
loadNotifications client url =
|
2017-04-29 12:05:06 -04:00
|
|
|
case client of
|
|
|
|
Just client ->
|
2017-05-05 17:35:54 -04:00
|
|
|
HttpBuilder.get (Maybe.withDefault ApiUrl.notifications url)
|
2017-05-05 11:26:49 -04:00
|
|
|
|> withClient client
|
|
|
|
|> withBodyDecoder (Decode.list notificationDecoder)
|
2017-05-05 17:55:30 -04:00
|
|
|
|> withQueryParams [ ( "limit", "30" ) ]
|
2017-05-05 17:35:54 -04:00
|
|
|
|> send (MastodonEvent << Notifications (url /= Nothing))
|
2017-04-29 12:05:06 -04:00
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
Cmd.none
|
|
|
|
|
|
|
|
|
|
|
|
loadUserAccount : Maybe Client -> Cmd Msg
|
|
|
|
loadUserAccount client =
|
|
|
|
case client of
|
|
|
|
Just client ->
|
2017-05-05 11:26:49 -04:00
|
|
|
HttpBuilder.get ApiUrl.userAccount
|
|
|
|
|> withClient client
|
|
|
|
|> withBodyDecoder accountDecoder
|
|
|
|
|> send (MastodonEvent << CurrentUser)
|
2017-04-29 12:05:06 -04:00
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
Cmd.none
|
|
|
|
|
|
|
|
|
2017-11-29 08:06:08 -05:00
|
|
|
loadAccount : Maybe Client -> String -> Cmd Msg
|
2017-04-29 12:05:06 -04:00
|
|
|
loadAccount client accountId =
|
|
|
|
case client of
|
|
|
|
Just client ->
|
2017-04-29 16:48:55 -04:00
|
|
|
Cmd.batch
|
2017-05-05 11:26:49 -04:00
|
|
|
[ HttpBuilder.get (ApiUrl.account accountId)
|
|
|
|
|> withClient client
|
|
|
|
|> withBodyDecoder accountDecoder
|
|
|
|
|> send (MastodonEvent << AccountReceived)
|
|
|
|
, requestRelationships client [ accountId ]
|
|
|
|
|> send (MastodonEvent << AccountRelationship)
|
2017-04-29 16:48:55 -04:00
|
|
|
]
|
2017-04-29 12:05:06 -04:00
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
Cmd.none
|
|
|
|
|
|
|
|
|
2021-01-12 01:08:43 -05:00
|
|
|
loadAccountPins : Maybe Client -> String -> Maybe String -> Cmd Msg
|
|
|
|
loadAccountPins client accountId url =
|
|
|
|
case client of
|
|
|
|
Just client ->
|
|
|
|
HttpBuilder.get (Maybe.withDefault (ApiUrl.accountTimeline accountId) url)
|
|
|
|
|> withClient client
|
|
|
|
|> withBodyDecoder (Decode.list statusDecoder)
|
|
|
|
|> withQueryParams [ ( "pinned", "true" ) ]
|
|
|
|
|> send (MastodonEvent << AccountPins (url /= Nothing))
|
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
Cmd.none
|
|
|
|
|
|
|
|
|
2017-11-29 08:06:08 -05:00
|
|
|
loadAccountFollowers : Maybe Client -> String -> Maybe String -> Cmd Msg
|
2017-05-08 06:22:20 -04:00
|
|
|
loadAccountFollowers client accountId url =
|
2017-04-29 16:48:55 -04:00
|
|
|
case client of
|
|
|
|
Just client ->
|
2017-05-08 06:22:20 -04:00
|
|
|
HttpBuilder.get (Maybe.withDefault (ApiUrl.followers accountId) url)
|
2017-05-05 11:26:49 -04:00
|
|
|
|> withClient client
|
|
|
|
|> withBodyDecoder (Decode.list accountDecoder)
|
2017-05-08 06:22:20 -04:00
|
|
|
|> send (MastodonEvent << AccountFollowers (url /= Nothing))
|
2017-04-29 16:48:55 -04:00
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
Cmd.none
|
|
|
|
|
|
|
|
|
2017-11-29 08:06:08 -05:00
|
|
|
loadAccountFollowing : Maybe Client -> String -> Maybe String -> Cmd Msg
|
2017-05-08 06:22:20 -04:00
|
|
|
loadAccountFollowing client accountId url =
|
2017-04-29 16:48:55 -04:00
|
|
|
case client of
|
|
|
|
Just client ->
|
2017-05-08 06:22:20 -04:00
|
|
|
HttpBuilder.get (Maybe.withDefault (ApiUrl.following accountId) url)
|
2017-05-05 11:26:49 -04:00
|
|
|
|> withClient client
|
|
|
|
|> withBodyDecoder (Decode.list accountDecoder)
|
2017-05-08 06:22:20 -04:00
|
|
|
|> send (MastodonEvent << AccountFollowing (url /= Nothing))
|
2017-04-29 16:48:55 -04:00
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
Cmd.none
|
|
|
|
|
|
|
|
|
2017-05-30 18:27:30 -04:00
|
|
|
search : Maybe Client -> String -> Cmd Msg
|
|
|
|
search client term =
|
|
|
|
case client of
|
|
|
|
Just client ->
|
|
|
|
let
|
|
|
|
cleanTerm =
|
|
|
|
term |> replace "#" ""
|
|
|
|
in
|
|
|
|
HttpBuilder.get ApiUrl.search
|
|
|
|
|> withClient client
|
|
|
|
|> withBodyDecoder searchResultsDecoder
|
|
|
|
|> withQueryParams [ ( "q", cleanTerm ), ( "resolve", "true" ) ]
|
|
|
|
|> send (MastodonEvent << SearchResultsReceived)
|
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
Cmd.none
|
|
|
|
|
|
|
|
|
2017-05-01 16:10:34 -04:00
|
|
|
searchAccounts : Maybe Client -> String -> Int -> Bool -> Cmd Msg
|
|
|
|
searchAccounts client query limit resolve =
|
|
|
|
if query == "" then
|
|
|
|
Cmd.none
|
|
|
|
else
|
|
|
|
case client of
|
|
|
|
Just client ->
|
2017-05-05 11:26:49 -04:00
|
|
|
let
|
|
|
|
qs =
|
|
|
|
[ ( "q", query )
|
|
|
|
, ( "limit", toString limit )
|
|
|
|
, ( "resolve"
|
|
|
|
, if resolve then
|
|
|
|
"true"
|
|
|
|
else
|
|
|
|
"false"
|
|
|
|
)
|
|
|
|
]
|
|
|
|
in
|
|
|
|
HttpBuilder.get ApiUrl.searchAccount
|
|
|
|
|> withClient client
|
|
|
|
|> withBodyDecoder (Decode.list accountDecoder)
|
|
|
|
|> withQueryParams qs
|
|
|
|
|> send (MastodonEvent << AutoSearch)
|
2017-05-01 16:10:34 -04:00
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
Cmd.none
|
|
|
|
|
|
|
|
|
2017-11-29 08:06:08 -05:00
|
|
|
requestRelationships : Client -> List String -> Request (List Relationship)
|
2017-05-05 11:26:49 -04:00
|
|
|
requestRelationships client ids =
|
|
|
|
HttpBuilder.get ApiUrl.relationships
|
|
|
|
|> withClient client
|
|
|
|
|> withBodyDecoder (Decode.list relationshipDecoder)
|
|
|
|
|> withQueryParams
|
2017-11-29 08:06:08 -05:00
|
|
|
(List.map (\id -> ( "id[]", id )) ids)
|
2017-05-05 11:26:49 -04:00
|
|
|
|
|
|
|
|
2017-11-29 08:06:08 -05:00
|
|
|
loadRelationships : Maybe Client -> List String -> Cmd Msg
|
2017-05-05 11:26:49 -04:00
|
|
|
loadRelationships client ids =
|
2017-05-05 17:47:25 -04:00
|
|
|
if List.length ids > 0 then
|
|
|
|
case client of
|
|
|
|
Just client ->
|
|
|
|
requestRelationships client ids
|
|
|
|
|> send (MastodonEvent << AccountRelationships)
|
2017-04-29 12:05:06 -04:00
|
|
|
|
2017-05-05 17:47:25 -04:00
|
|
|
Nothing ->
|
|
|
|
Cmd.none
|
|
|
|
else
|
|
|
|
Cmd.none
|
2017-04-29 12:05:06 -04:00
|
|
|
|
|
|
|
|
2017-11-29 08:06:08 -05:00
|
|
|
loadThread : Maybe Client -> StatusId -> Cmd Msg
|
2017-05-29 10:28:01 -04:00
|
|
|
loadThread client id =
|
2017-04-29 12:05:06 -04:00
|
|
|
case client of
|
|
|
|
Just client ->
|
2017-05-29 10:28:01 -04:00
|
|
|
Cmd.batch
|
|
|
|
[ HttpBuilder.get (ApiUrl.status id)
|
|
|
|
|> withClient client
|
|
|
|
|> withBodyDecoder statusDecoder
|
|
|
|
|> send (MastodonEvent << (ThreadStatusLoaded id))
|
|
|
|
, HttpBuilder.get (ApiUrl.context id)
|
|
|
|
|> withClient client
|
|
|
|
|> withBodyDecoder contextDecoder
|
|
|
|
|> send (MastodonEvent << (ThreadContextLoaded id))
|
|
|
|
]
|
2017-04-29 12:05:06 -04:00
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
Cmd.none
|
|
|
|
|
|
|
|
|
2017-05-06 05:15:52 -04:00
|
|
|
loadHomeTimeline : Maybe Client -> Maybe String -> Cmd Msg
|
|
|
|
loadHomeTimeline client url =
|
2017-04-29 12:05:06 -04:00
|
|
|
case client of
|
|
|
|
Just client ->
|
2017-05-05 11:26:49 -04:00
|
|
|
HttpBuilder.get (Maybe.withDefault ApiUrl.homeTimeline url)
|
|
|
|
|> withClient client
|
|
|
|
|> withBodyDecoder (Decode.list statusDecoder)
|
2017-05-05 17:55:30 -04:00
|
|
|
|> withQueryParams [ ( "limit", "60" ) ]
|
2017-05-06 05:15:52 -04:00
|
|
|
|> send (MastodonEvent << HomeTimeline (url /= Nothing))
|
2017-04-29 12:05:06 -04:00
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
Cmd.none
|
|
|
|
|
|
|
|
|
2017-05-05 11:26:49 -04:00
|
|
|
loadLocalTimeline : Maybe Client -> Maybe String -> Cmd Msg
|
|
|
|
loadLocalTimeline client url =
|
|
|
|
case client of
|
|
|
|
Just client ->
|
|
|
|
HttpBuilder.get (Maybe.withDefault ApiUrl.publicTimeline url)
|
|
|
|
|> withClient client
|
|
|
|
|> withBodyDecoder (Decode.list statusDecoder)
|
2017-05-05 17:55:30 -04:00
|
|
|
|> withQueryParams [ ( "local", "true" ), ( "limit", "60" ) ]
|
2017-05-05 11:26:49 -04:00
|
|
|
|> send (MastodonEvent << LocalTimeline (url /= Nothing))
|
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
Cmd.none
|
|
|
|
|
|
|
|
|
|
|
|
loadGlobalTimeline : Maybe Client -> Maybe String -> Cmd Msg
|
|
|
|
loadGlobalTimeline client url =
|
|
|
|
case client of
|
|
|
|
Just client ->
|
|
|
|
HttpBuilder.get (Maybe.withDefault ApiUrl.publicTimeline url)
|
|
|
|
|> withClient client
|
|
|
|
|> withBodyDecoder (Decode.list statusDecoder)
|
2017-05-05 17:55:30 -04:00
|
|
|
|> withQueryParams [ ( "limit", "60" ) ]
|
2017-05-05 11:26:49 -04:00
|
|
|
|> send (MastodonEvent << GlobalTimeline (url /= Nothing))
|
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
Cmd.none
|
|
|
|
|
|
|
|
|
2017-11-29 08:06:08 -05:00
|
|
|
loadAccountTimeline : Maybe Client -> String -> Maybe String -> Cmd Msg
|
2017-05-05 11:26:49 -04:00
|
|
|
loadAccountTimeline client accountId url =
|
|
|
|
case client of
|
|
|
|
Just client ->
|
|
|
|
HttpBuilder.get (Maybe.withDefault (ApiUrl.accountTimeline accountId) url)
|
|
|
|
|> withClient client
|
|
|
|
|> withBodyDecoder (Decode.list statusDecoder)
|
2021-01-11 23:20:35 -05:00
|
|
|
|> withQueryParams [ ( "limit", "60" )
|
|
|
|
, ( "exclude_replies", "true" )
|
|
|
|
]
|
|
|
|
|> send (MastodonEvent << AccountTimeline (url /= Nothing))
|
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
Cmd.none
|
|
|
|
|
|
|
|
|
|
|
|
loadAccountTimelineReplies : Maybe Client -> String -> Maybe String -> Cmd Msg
|
|
|
|
loadAccountTimelineReplies client accountId url =
|
|
|
|
case client of
|
|
|
|
Just client ->
|
|
|
|
HttpBuilder.get (Maybe.withDefault (ApiUrl.accountTimeline accountId) url)
|
|
|
|
|> withClient client
|
|
|
|
|> withBodyDecoder (Decode.list statusDecoder)
|
|
|
|
|> withQueryParams [ ( "limit", "60" )
|
|
|
|
, ( "exclude_replies", "false" )
|
|
|
|
]
|
2017-05-05 11:26:49 -04:00
|
|
|
|> send (MastodonEvent << AccountTimeline (url /= Nothing))
|
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
Cmd.none
|
|
|
|
|
|
|
|
|
2017-05-13 09:55:46 -04:00
|
|
|
loadFavoriteTimeline : Maybe Client -> Maybe String -> Cmd Msg
|
|
|
|
loadFavoriteTimeline client url =
|
|
|
|
case client of
|
|
|
|
Just client ->
|
|
|
|
HttpBuilder.get (Maybe.withDefault ApiUrl.favouriteTimeline url)
|
|
|
|
|> withClient client
|
|
|
|
|> withBodyDecoder (Decode.list statusDecoder)
|
|
|
|
|> withQueryParams [ ( "limit", "60" ) ]
|
|
|
|
|> send (MastodonEvent << FavoriteTimeline (url /= Nothing))
|
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
Cmd.none
|
|
|
|
|
|
|
|
|
2017-05-27 03:32:15 -04:00
|
|
|
loadHashtagTimeline : Maybe Client -> String -> Maybe String -> Cmd Msg
|
|
|
|
loadHashtagTimeline client hashtag url =
|
|
|
|
case client of
|
|
|
|
Just client ->
|
|
|
|
HttpBuilder.get (Maybe.withDefault (ApiUrl.hashtag hashtag) url)
|
|
|
|
|> withClient client
|
|
|
|
|> withBodyDecoder (Decode.list statusDecoder)
|
|
|
|
|> withQueryParams [ ( "limit", "60" ) ]
|
|
|
|
|> send (MastodonEvent << HashtagTimeline (url /= Nothing))
|
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
Cmd.none
|
|
|
|
|
|
|
|
|
2017-05-25 17:07:17 -04:00
|
|
|
loadMutes : Maybe Client -> Maybe String -> Cmd Msg
|
|
|
|
loadMutes client url =
|
|
|
|
case client of
|
|
|
|
Just client ->
|
|
|
|
HttpBuilder.get (Maybe.withDefault ApiUrl.mutes url)
|
|
|
|
|> withClient client
|
|
|
|
|> withBodyDecoder (Decode.list accountDecoder)
|
|
|
|
|> withQueryParams [ ( "limit", "60" ) ]
|
|
|
|
|> send (MastodonEvent << Mutes (url /= Nothing))
|
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
Cmd.none
|
|
|
|
|
|
|
|
|
|
|
|
loadBlocks : Maybe Client -> Maybe String -> Cmd Msg
|
|
|
|
loadBlocks client url =
|
|
|
|
case client of
|
|
|
|
Just client ->
|
|
|
|
HttpBuilder.get (Maybe.withDefault ApiUrl.blocks url)
|
|
|
|
|> withClient client
|
|
|
|
|> withBodyDecoder (Decode.list accountDecoder)
|
|
|
|
|> withQueryParams [ ( "limit", "60" ) ]
|
|
|
|
|> send (MastodonEvent << Blocks (url /= Nothing))
|
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
Cmd.none
|
|
|
|
|
|
|
|
|
2017-05-05 11:26:49 -04:00
|
|
|
loadTimelines : Maybe Client -> Cmd Msg
|
|
|
|
loadTimelines client =
|
|
|
|
Cmd.batch
|
2017-05-06 05:15:52 -04:00
|
|
|
[ loadHomeTimeline client Nothing
|
2017-05-05 11:26:49 -04:00
|
|
|
, loadLocalTimeline client Nothing
|
|
|
|
, loadGlobalTimeline client Nothing
|
2017-05-05 17:35:54 -04:00
|
|
|
, loadNotifications client Nothing
|
2017-05-05 11:26:49 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2017-05-29 10:28:01 -04:00
|
|
|
loadNextTimeline : Model -> String -> String -> Cmd Msg
|
|
|
|
loadNextTimeline { clients, currentView, accountInfo } id next =
|
|
|
|
let
|
|
|
|
client =
|
|
|
|
List.head clients
|
|
|
|
in
|
|
|
|
case id of
|
|
|
|
"notifications" ->
|
|
|
|
loadNotifications client (Just next)
|
2017-05-05 17:35:54 -04:00
|
|
|
|
2017-05-29 10:28:01 -04:00
|
|
|
"home-timeline" ->
|
|
|
|
loadHomeTimeline client (Just next)
|
2017-05-05 11:26:49 -04:00
|
|
|
|
2017-05-29 10:28:01 -04:00
|
|
|
"local-timeline" ->
|
|
|
|
loadLocalTimeline client (Just next)
|
2017-05-05 11:26:49 -04:00
|
|
|
|
2017-05-29 10:28:01 -04:00
|
|
|
"global-timeline" ->
|
|
|
|
loadGlobalTimeline client (Just next)
|
2017-05-05 11:26:49 -04:00
|
|
|
|
2017-05-29 10:28:01 -04:00
|
|
|
"favorite-timeline" ->
|
|
|
|
loadFavoriteTimeline client (Just next)
|
2017-05-13 09:55:46 -04:00
|
|
|
|
2017-05-29 10:28:01 -04:00
|
|
|
"hashtag-timeline" ->
|
|
|
|
case currentView of
|
|
|
|
HashtagView hashtag ->
|
|
|
|
loadHashtagTimeline client hashtag (Just next)
|
2017-05-27 03:32:15 -04:00
|
|
|
|
2017-05-29 10:28:01 -04:00
|
|
|
_ ->
|
|
|
|
Cmd.none
|
2017-05-27 03:32:15 -04:00
|
|
|
|
2017-05-29 10:28:01 -04:00
|
|
|
"account-timeline" ->
|
|
|
|
case accountInfo.account of
|
|
|
|
Just account ->
|
|
|
|
loadAccountTimeline client account.id (Just next)
|
2017-05-05 11:26:49 -04:00
|
|
|
|
2017-05-29 10:28:01 -04:00
|
|
|
_ ->
|
|
|
|
Cmd.none
|
2017-05-05 11:26:49 -04:00
|
|
|
|
2017-05-29 10:28:01 -04:00
|
|
|
"account-followers" ->
|
|
|
|
case accountInfo.account of
|
|
|
|
Just account ->
|
|
|
|
loadAccountFollowers client account.id (Just next)
|
2017-05-08 06:22:20 -04:00
|
|
|
|
2017-05-29 10:28:01 -04:00
|
|
|
_ ->
|
|
|
|
Cmd.none
|
2017-05-08 06:22:20 -04:00
|
|
|
|
2017-05-29 10:28:01 -04:00
|
|
|
"account-following" ->
|
|
|
|
case accountInfo.account of
|
|
|
|
Just account ->
|
|
|
|
loadAccountFollowing client account.id (Just next)
|
2017-05-08 06:22:20 -04:00
|
|
|
|
2017-05-29 10:28:01 -04:00
|
|
|
_ ->
|
|
|
|
Cmd.none
|
2017-05-08 06:22:20 -04:00
|
|
|
|
2017-05-29 10:28:01 -04:00
|
|
|
_ ->
|
|
|
|
Cmd.none
|
2017-05-05 11:26:49 -04:00
|
|
|
|
|
|
|
|
2017-04-29 12:05:06 -04:00
|
|
|
postStatus : Maybe Client -> StatusRequestBody -> Cmd Msg
|
|
|
|
postStatus client draft =
|
|
|
|
case client of
|
|
|
|
Just client ->
|
2017-05-05 11:26:49 -04:00
|
|
|
HttpBuilder.post ApiUrl.statuses
|
|
|
|
|> withClient client
|
|
|
|
|> HttpBuilder.withJsonBody (statusRequestBodyEncoder draft)
|
|
|
|
|> withBodyDecoder statusDecoder
|
|
|
|
|> send (MastodonEvent << StatusPosted)
|
2017-04-29 12:05:06 -04:00
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
Cmd.none
|
|
|
|
|
|
|
|
|
2017-05-01 16:10:34 -04:00
|
|
|
updateDomStatus : String -> Cmd Msg
|
|
|
|
updateDomStatus statusText =
|
|
|
|
Ports.setStatus { id = "status", status = statusText }
|
|
|
|
|
|
|
|
|
2017-11-29 08:06:08 -05:00
|
|
|
deleteStatus : Maybe Client -> StatusId -> Cmd Msg
|
2017-04-29 12:05:06 -04:00
|
|
|
deleteStatus client id =
|
|
|
|
case client of
|
|
|
|
Just client ->
|
2017-05-05 11:26:49 -04:00
|
|
|
HttpBuilder.delete (ApiUrl.status id)
|
|
|
|
|> withClient client
|
|
|
|
|> withBodyDecoder (Decode.succeed id)
|
|
|
|
|> send (MastodonEvent << StatusDeleted)
|
2017-04-29 12:05:06 -04:00
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
Cmd.none
|
|
|
|
|
|
|
|
|
2017-11-29 08:06:08 -05:00
|
|
|
reblogStatus : Maybe Client -> StatusId -> Cmd Msg
|
2017-04-29 12:05:06 -04:00
|
|
|
reblogStatus client statusId =
|
|
|
|
case client of
|
|
|
|
Just client ->
|
2017-05-05 11:26:49 -04:00
|
|
|
HttpBuilder.post (ApiUrl.reblog statusId)
|
|
|
|
|> withClient client
|
|
|
|
|> withBodyDecoder statusDecoder
|
|
|
|
|> send (MastodonEvent << Reblogged)
|
2017-04-29 12:05:06 -04:00
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
Cmd.none
|
|
|
|
|
|
|
|
|
2017-11-29 08:06:08 -05:00
|
|
|
unreblogStatus : Maybe Client -> StatusId -> Cmd Msg
|
2017-04-29 12:05:06 -04:00
|
|
|
unreblogStatus client statusId =
|
|
|
|
case client of
|
|
|
|
Just client ->
|
2017-05-05 11:26:49 -04:00
|
|
|
HttpBuilder.post (ApiUrl.unreblog statusId)
|
|
|
|
|> withClient client
|
|
|
|
|> withBodyDecoder statusDecoder
|
|
|
|
|> send (MastodonEvent << Unreblogged)
|
2017-04-29 12:05:06 -04:00
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
Cmd.none
|
|
|
|
|
|
|
|
|
2017-11-29 08:06:08 -05:00
|
|
|
favouriteStatus : Maybe Client -> StatusId -> Cmd Msg
|
2017-04-29 12:05:06 -04:00
|
|
|
favouriteStatus client statusId =
|
|
|
|
case client of
|
|
|
|
Just client ->
|
2017-05-05 11:26:49 -04:00
|
|
|
HttpBuilder.post (ApiUrl.favourite statusId)
|
|
|
|
|> withClient client
|
|
|
|
|> withBodyDecoder statusDecoder
|
|
|
|
|> send (MastodonEvent << FavoriteAdded)
|
2017-04-29 12:05:06 -04:00
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
Cmd.none
|
|
|
|
|
|
|
|
|
2017-11-29 08:06:08 -05:00
|
|
|
unfavouriteStatus : Maybe Client -> StatusId -> Cmd Msg
|
2017-04-29 12:05:06 -04:00
|
|
|
unfavouriteStatus client statusId =
|
|
|
|
case client of
|
|
|
|
Just client ->
|
2017-05-05 11:26:49 -04:00
|
|
|
HttpBuilder.post (ApiUrl.unfavourite statusId)
|
|
|
|
|> withClient client
|
|
|
|
|> withBodyDecoder statusDecoder
|
|
|
|
|> send (MastodonEvent << FavoriteRemoved)
|
2017-04-29 12:05:06 -04:00
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
Cmd.none
|
2017-04-29 16:48:55 -04:00
|
|
|
|
|
|
|
|
2017-05-25 04:25:43 -04:00
|
|
|
follow : Maybe Client -> Account -> Cmd Msg
|
|
|
|
follow client account =
|
2017-04-29 16:48:55 -04:00
|
|
|
case client of
|
|
|
|
Just client ->
|
2017-05-25 04:25:43 -04:00
|
|
|
HttpBuilder.post (ApiUrl.follow account.id)
|
2017-05-05 11:26:49 -04:00
|
|
|
|> withClient client
|
|
|
|
|> withBodyDecoder relationshipDecoder
|
2017-05-25 04:25:43 -04:00
|
|
|
|> send (MastodonEvent << (AccountFollowed account))
|
2017-04-29 16:48:55 -04:00
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
Cmd.none
|
|
|
|
|
|
|
|
|
2017-05-25 04:25:43 -04:00
|
|
|
unfollow : Maybe Client -> Account -> Cmd Msg
|
|
|
|
unfollow client account =
|
2017-04-29 16:48:55 -04:00
|
|
|
case client of
|
|
|
|
Just client ->
|
2017-05-25 04:25:43 -04:00
|
|
|
HttpBuilder.post (ApiUrl.unfollow account.id)
|
2017-05-05 11:26:49 -04:00
|
|
|
|> withClient client
|
|
|
|
|> withBodyDecoder relationshipDecoder
|
2017-05-25 04:25:43 -04:00
|
|
|
|> send (MastodonEvent << (AccountUnfollowed account))
|
2017-04-29 16:48:55 -04:00
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
Cmd.none
|
2017-04-30 05:08:30 -04:00
|
|
|
|
|
|
|
|
2017-05-25 17:07:17 -04:00
|
|
|
mute : Maybe Client -> Account -> Cmd Msg
|
|
|
|
mute client account =
|
|
|
|
case client of
|
|
|
|
Just client ->
|
|
|
|
HttpBuilder.post (ApiUrl.mute account.id)
|
|
|
|
|> withClient client
|
|
|
|
|> withBodyDecoder relationshipDecoder
|
|
|
|
|> send (MastodonEvent << (AccountMuted account))
|
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
Cmd.none
|
|
|
|
|
|
|
|
|
|
|
|
unmute : Maybe Client -> Account -> Cmd Msg
|
|
|
|
unmute client account =
|
|
|
|
case client of
|
|
|
|
Just client ->
|
|
|
|
HttpBuilder.post (ApiUrl.unmute account.id)
|
|
|
|
|> withClient client
|
|
|
|
|> withBodyDecoder relationshipDecoder
|
|
|
|
|> send (MastodonEvent << (AccountUnmuted account))
|
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
Cmd.none
|
|
|
|
|
|
|
|
|
|
|
|
block : Maybe Client -> Account -> Cmd Msg
|
|
|
|
block client account =
|
|
|
|
case client of
|
|
|
|
Just client ->
|
|
|
|
HttpBuilder.post (ApiUrl.block account.id)
|
|
|
|
|> withClient client
|
|
|
|
|> withBodyDecoder relationshipDecoder
|
|
|
|
|> send (MastodonEvent << (AccountBlocked account))
|
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
Cmd.none
|
|
|
|
|
|
|
|
|
|
|
|
unblock : Maybe Client -> Account -> Cmd Msg
|
|
|
|
unblock client account =
|
|
|
|
case client of
|
|
|
|
Just client ->
|
|
|
|
HttpBuilder.post (ApiUrl.unblock account.id)
|
|
|
|
|> withClient client
|
|
|
|
|> withBodyDecoder relationshipDecoder
|
|
|
|
|> send (MastodonEvent << (AccountUnblocked account))
|
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
Cmd.none
|
|
|
|
|
|
|
|
|
2017-05-11 04:55:15 -04:00
|
|
|
uploadMedia : Maybe Client -> String -> Cmd Msg
|
|
|
|
uploadMedia client fileInputId =
|
|
|
|
case client of
|
|
|
|
Just { server, token } ->
|
|
|
|
Ports.uploadMedia
|
|
|
|
{ id = fileInputId
|
|
|
|
, url = server ++ ApiUrl.uploadMedia
|
|
|
|
, token = token
|
|
|
|
}
|
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
Cmd.none
|
|
|
|
|
|
|
|
|
2017-04-30 05:08:30 -04:00
|
|
|
focusId : String -> Cmd Msg
|
|
|
|
focusId id =
|
|
|
|
Dom.focus id |> Task.attempt (always NoOp)
|
|
|
|
|
|
|
|
|
|
|
|
scrollColumnToTop : String -> Cmd Msg
|
|
|
|
scrollColumnToTop column =
|
|
|
|
Task.attempt (always NoOp) <| Dom.Scroll.toTop column
|
|
|
|
|
|
|
|
|
|
|
|
scrollColumnToBottom : String -> Cmd Msg
|
|
|
|
scrollColumnToBottom column =
|
|
|
|
Task.attempt (always NoOp) <| Dom.Scroll.toBottom column
|
2017-05-04 02:31:58 -04:00
|
|
|
|
|
|
|
|
|
|
|
scrollToThreadStatus : String -> Cmd Msg
|
|
|
|
scrollToThreadStatus cssId =
|
|
|
|
Ports.scrollIntoView <| "thread-status-" ++ cssId
|
2017-06-02 08:11:50 -04:00
|
|
|
|
|
|
|
|
|
|
|
notifyStatus : Status -> Cmd Msg
|
|
|
|
notifyStatus status =
|
|
|
|
Ports.notify
|
|
|
|
{ title = status.account.acct
|
|
|
|
, icon = status.account.avatar
|
|
|
|
, body = status.content |> textContent
|
2017-11-29 08:06:08 -05:00
|
|
|
, clickUrl = "#thread/" ++ extractStatusId status.id
|
2017-06-02 08:11:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
notifyNotification : Notification -> Cmd Msg
|
|
|
|
notifyNotification notification =
|
|
|
|
case notification.status of
|
|
|
|
Just status ->
|
|
|
|
case notification.type_ of
|
|
|
|
"reblog" ->
|
|
|
|
Ports.notify
|
|
|
|
{ title = notification.account.acct ++ " reboosted"
|
|
|
|
, icon = notification.account.avatar
|
|
|
|
, body = status.content |> textContent
|
2017-11-29 08:06:08 -05:00
|
|
|
, clickUrl = "#thread/" ++ extractStatusId status.id
|
2017-06-02 08:11:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
"favourite" ->
|
|
|
|
Ports.notify
|
|
|
|
{ title = notification.account.acct ++ " favorited"
|
|
|
|
, icon = notification.account.avatar
|
|
|
|
, body = status.content |> textContent
|
2017-11-29 08:06:08 -05:00
|
|
|
, clickUrl = "#thread/" ++ extractStatusId status.id
|
2017-06-02 08:11:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
"mention" ->
|
|
|
|
Ports.notify
|
|
|
|
{ title = notification.account.acct ++ " mentioned you"
|
|
|
|
, icon = notification.account.avatar
|
|
|
|
, body = status.content |> textContent
|
2017-11-29 08:06:08 -05:00
|
|
|
, clickUrl = "#thread/" ++ extractStatusId status.id
|
2017-06-02 08:11:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
_ ->
|
|
|
|
Cmd.none
|
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
case notification.type_ of
|
|
|
|
"follow" ->
|
|
|
|
Ports.notify
|
|
|
|
{ title = notification.account.acct ++ " follows you"
|
|
|
|
, icon = notification.account.avatar
|
|
|
|
, body = notification.account.note
|
2017-11-29 08:06:08 -05:00
|
|
|
, clickUrl = "#account/" ++ notification.account.id
|
2017-06-02 08:11:50 -04:00
|
|
|
}
|
|
|
|
|
2021-01-12 16:06:13 -05:00
|
|
|
"follow_request" ->
|
|
|
|
Ports.notify
|
|
|
|
{ title = notification.account.acct ++ " sent you a follow request"
|
|
|
|
, icon = notification.account.avatar
|
|
|
|
, body = notification.account.note
|
|
|
|
, clickUrl = "#account/" ++ notification.account.id
|
|
|
|
}
|
|
|
|
|
2017-06-02 08:11:50 -04:00
|
|
|
_ ->
|
|
|
|
Cmd.none
|
2021-01-10 22:12:21 -05:00
|
|
|
|
|
|
|
clearDraft : Cmd Msg
|
|
|
|
clearDraft =
|
|
|
|
Task.perform identity (Task.succeed (DraftEvent ClearDraft))
|