parent
e77dca0692
commit
75aa841ceb
@ -4,6 +4,7 @@ module Mastodon.ApiUrl
|
||||
, oauthAuthorize
|
||||
, oauthToken
|
||||
, account
|
||||
, accountTimeline
|
||||
, homeTimeline
|
||||
, publicTimeline
|
||||
, notifications
|
||||
@ -65,6 +66,11 @@ publicTimeline local =
|
||||
"/api/v1/timelines/public" ++ isLocal
|
||||
|
||||
|
||||
accountTimeline : Int -> String
|
||||
accountTimeline id =
|
||||
(account id) ++ "/statuses"
|
||||
|
||||
|
||||
notifications : String
|
||||
notifications =
|
||||
"/api/v1/notifications"
|
||||
|
@ -10,6 +10,7 @@ module Mastodon.Http
|
||||
, getAuthorizationUrl
|
||||
, getAccessToken
|
||||
, fetchAccount
|
||||
, fetchAccountTimeline
|
||||
, fetchLocalTimeline
|
||||
, fetchNotifications
|
||||
, fetchGlobalTimeline
|
||||
@ -21,6 +22,7 @@ module Mastodon.Http
|
||||
import Http
|
||||
import HttpBuilder
|
||||
import Json.Decode as Decode
|
||||
import Task
|
||||
import Mastodon.ApiUrl as ApiUrl
|
||||
import Mastodon.Decoder exposing (..)
|
||||
import Mastodon.Encoder exposing (..)
|
||||
@ -121,6 +123,11 @@ fetchGlobalTimeline client =
|
||||
fetch client (ApiUrl.publicTimeline (Nothing)) <| Decode.list statusDecoder
|
||||
|
||||
|
||||
fetchAccountTimeline : Client -> Int -> Request (List Status)
|
||||
fetchAccountTimeline client id =
|
||||
fetch client (ApiUrl.accountTimeline id) <| Decode.list statusDecoder
|
||||
|
||||
|
||||
fetchNotifications : Client -> Request (List Notification)
|
||||
fetchNotifications client =
|
||||
fetch client (ApiUrl.notifications) <| Decode.list notificationDecoder
|
||||
|
@ -47,7 +47,8 @@ type MastodonMsg
|
||||
| Reblogged (Result Mastodon.Model.Error Mastodon.Model.Status)
|
||||
| StatusPosted (Result Mastodon.Model.Error Mastodon.Model.Status)
|
||||
| Unreblogged (Result Mastodon.Model.Error Mastodon.Model.Status)
|
||||
| UserAccount (Result Mastodon.Model.Error Mastodon.Model.Account)
|
||||
| Account (Result Mastodon.Model.Error Mastodon.Model.Account)
|
||||
| AccountTimeline (Result Mastodon.Model.Error (List Mastodon.Model.Status))
|
||||
| UserTimeline (Result Mastodon.Model.Error (List Mastodon.Model.Status))
|
||||
|
||||
|
||||
@ -62,7 +63,7 @@ type Msg
|
||||
| ClearOpenedAccount
|
||||
| CloseThread
|
||||
| DraftEvent DraftMsg
|
||||
| LoadUserAccount Int
|
||||
| LoadAccount Int
|
||||
| MastodonEvent MastodonMsg
|
||||
| NoOp
|
||||
| OpenThread Mastodon.Model.Status
|
||||
@ -114,6 +115,7 @@ type alias Model =
|
||||
, userTimeline : List Mastodon.Model.Status
|
||||
, localTimeline : List Mastodon.Model.Status
|
||||
, globalTimeline : List Mastodon.Model.Status
|
||||
, accountTimeline : List Mastodon.Model.Status
|
||||
, notifications : List Mastodon.Model.NotificationAggregate
|
||||
, draft : Draft
|
||||
, errors : List String
|
||||
@ -156,6 +158,7 @@ init flags location =
|
||||
, userTimeline = []
|
||||
, localTimeline = []
|
||||
, globalTimeline = []
|
||||
, accountTimeline = []
|
||||
, notifications = []
|
||||
, draft = defaultDraft
|
||||
, errors = []
|
||||
@ -502,7 +505,7 @@ processMastodonEvent msg model =
|
||||
Err error ->
|
||||
{ model | errors = (errorText error) :: model.errors } ! []
|
||||
|
||||
UserAccount result ->
|
||||
Account result ->
|
||||
case result of
|
||||
Ok account ->
|
||||
{ model | currentView = AccountView account } ! []
|
||||
@ -514,6 +517,14 @@ processMastodonEvent msg model =
|
||||
}
|
||||
! []
|
||||
|
||||
AccountTimeline result ->
|
||||
case result of
|
||||
Ok statuses ->
|
||||
{ model | accountTimeline = statuses } ! []
|
||||
|
||||
Err error ->
|
||||
{ model | errors = (errorText error) :: model.errors } ! []
|
||||
|
||||
UserTimeline result ->
|
||||
case result of
|
||||
Ok userTimeline ->
|
||||
@ -723,17 +734,19 @@ update msg model =
|
||||
Nothing ->
|
||||
[]
|
||||
|
||||
LoadUserAccount accountId ->
|
||||
LoadAccount accountId ->
|
||||
{-
|
||||
@TODO
|
||||
When requesting a user profile, we should load a new "page"
|
||||
so that the URL in the browser matches the user displayed
|
||||
-}
|
||||
model
|
||||
{ model | currentView = preferredTimeline model }
|
||||
! case model.client of
|
||||
Just client ->
|
||||
[ Mastodon.Http.fetchAccount client accountId
|
||||
|> Mastodon.Http.send (MastodonEvent << UserAccount)
|
||||
|> Mastodon.Http.send (MastodonEvent << Account)
|
||||
, Mastodon.Http.fetchAccountTimeline client accountId
|
||||
|> Mastodon.Http.send (MastodonEvent << AccountTimeline)
|
||||
]
|
||||
|
||||
Nothing ->
|
||||
|
@ -70,7 +70,7 @@ accountLink : Mastodon.Model.Account -> Html Msg
|
||||
accountLink account =
|
||||
a
|
||||
[ href account.url
|
||||
, ViewHelper.onClickWithPreventAndStop (LoadUserAccount account.id)
|
||||
, ViewHelper.onClickWithPreventAndStop (LoadAccount account.id)
|
||||
]
|
||||
[ text <| "@" ++ account.username ]
|
||||
|
||||
@ -79,7 +79,7 @@ accountAvatarLink : Mastodon.Model.Account -> Html Msg
|
||||
accountAvatarLink account =
|
||||
a
|
||||
[ href account.url
|
||||
, ViewHelper.onClickWithPreventAndStop (LoadUserAccount account.id)
|
||||
, ViewHelper.onClickWithPreventAndStop (LoadAccount account.id)
|
||||
, title <| "@" ++ account.username
|
||||
]
|
||||
[ img [ class "avatar", src account.avatar ] [] ]
|
||||
@ -174,7 +174,7 @@ statusView context ({ account, content, media_attachments, reblog, mentions } as
|
||||
-- When clicking on a status, we should not let the browser
|
||||
-- redirect to a new page. That's why we're preventing the default
|
||||
-- behavior here
|
||||
, ViewHelper.onClickWithPreventAndStop (LoadUserAccount account.id)
|
||||
, ViewHelper.onClickWithPreventAndStop (LoadAccount account.id)
|
||||
]
|
||||
in
|
||||
case reblog of
|
||||
@ -611,7 +611,7 @@ homepageView model =
|
||||
|
||||
Model.AccountView account ->
|
||||
-- Todo: Load the user timeline
|
||||
accountTimelineView account [] "Account" "user"
|
||||
accountTimelineView account model.accountTimeline "Account" "user"
|
||||
|
||||
Model.ThreadView thread ->
|
||||
threadView thread
|
||||
|
@ -13,7 +13,7 @@ import HtmlParser
|
||||
import Json.Decode as Decode
|
||||
import String.Extra exposing (replace)
|
||||
import Mastodon.Model
|
||||
import Model exposing (Msg(LoadUserAccount))
|
||||
import Model exposing (Msg(LoadAccount))
|
||||
|
||||
|
||||
-- Custom Events
|
||||
@ -58,7 +58,7 @@ createLinkNode attrs children mentions =
|
||||
Just mention ->
|
||||
Html.node "a"
|
||||
((List.map toAttribute attrs)
|
||||
++ [ onClickWithPreventAndStop (LoadUserAccount mention.id) ]
|
||||
++ [ onClickWithPreventAndStop (LoadAccount mention.id) ]
|
||||
)
|
||||
(toVirtualDom mentions children)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user