From 0f7a4c6bcff121fad76dba193fe9b21670c9e2ff Mon Sep 17 00:00:00 2001 From: Ryan Fox Date: Tue, 12 Jan 2021 00:12:13 +0000 Subject: [PATCH] Update search functionality APIv1 search is deprecated and doesn't work anymore. --- public/style.css | 4 ++++ src/Mastodon/ApiUrl.elm | 6 +++++- src/Mastodon/Decoder.elm | 20 +++++++++++++++++++- src/Mastodon/Model.elm | 18 +++++++++++++++++- src/View/Common.elm | 23 +++++++++++++++++++++++ src/View/Notification.elm | 13 +------------ src/View/Search.elm | 4 ++-- 7 files changed, 71 insertions(+), 17 deletions(-) diff --git a/public/style.css b/public/style.css index 498c9ee..cd87ab5 100644 --- a/public/style.css +++ b/public/style.css @@ -116,6 +116,10 @@ li.load-more { clear: both; } +.list-group-item.status { + min-height: 70px; +} + .current-user { min-height: 55px; } diff --git a/src/Mastodon/ApiUrl.elm b/src/Mastodon/ApiUrl.elm index 6728c75..a97d8b4 100644 --- a/src/Mastodon/ApiUrl.elm +++ b/src/Mastodon/ApiUrl.elm @@ -42,6 +42,10 @@ apiPrefix : String apiPrefix = "/api/v1" +api2Prefix : String +api2Prefix = + "/api/v2" + apps : String apps = @@ -105,7 +109,7 @@ userAccount = search : String search = - apiPrefix ++ "/search" + api2Prefix ++ "/search" searchAccount : String diff --git a/src/Mastodon/Decoder.elm b/src/Mastodon/Decoder.elm index d99da23..bea2b97 100644 --- a/src/Mastodon/Decoder.elm +++ b/src/Mastodon/Decoder.elm @@ -15,6 +15,8 @@ module Mastodon.Decoder , tagDecoder , reblogDecoder , relationshipDecoder + , hashtagHistoryDecoder + , hashtagDecoder , searchResultsDecoder , statusDecoder , webSocketEventDecoder @@ -189,12 +191,28 @@ reblogDecoder = Decode.map Reblog (Decode.lazy (\_ -> statusDecoder)) +hashtagHistoryDecoder : Decode.Decoder HashtagHistory +hashtagHistoryDecoder = + Pipe.decode HashtagHistory + |> Pipe.required "day" Decode.string + |> Pipe.required "uses" Decode.string + |> Pipe.required "accounts" Decode.string + + +hashtagDecoder : Decode.Decoder Hashtag +hashtagDecoder = + Pipe.decode Hashtag + |> Pipe.required "name" Decode.string + |> Pipe.required "url" Decode.string + |> Pipe.required "history" (Decode.list hashtagHistoryDecoder) + + searchResultsDecoder : Decode.Decoder SearchResults searchResultsDecoder = Pipe.decode SearchResults |> Pipe.required "accounts" (Decode.list accountDecoder) |> Pipe.required "statuses" (Decode.list statusDecoder) - |> Pipe.required "hashtags" (Decode.list Decode.string) + |> Pipe.required "hashtags" (Decode.list hashtagDecoder) idDecoder : Decode.Decoder String diff --git a/src/Mastodon/Model.elm b/src/Mastodon/Model.elm index 9b055bf..0d38a32 100644 --- a/src/Mastodon/Model.elm +++ b/src/Mastodon/Model.elm @@ -11,6 +11,8 @@ module Mastodon.Model , Emoji , Error(..) , Field + , HashtagHistory + , Hashtag , Mention , Notification , NotificationAggregate @@ -206,10 +208,24 @@ type alias Relationship = } +type alias HashtagHistory = + { day : String + , uses : String + , accounts : String + } + + +type alias Hashtag = + { name : String + , url : String + , history : List HashtagHistory + } + + type alias SearchResults = { accounts : List Account , statuses : List Status - , hashtags : List String + , hashtags : List Hashtag } diff --git a/src/View/Common.elm b/src/View/Common.elm index 02b5daa..0a59384 100644 --- a/src/View/Common.elm +++ b/src/View/Common.elm @@ -4,6 +4,7 @@ module View.Common , accountAvatarLink , accountLink , accountLinkSmall + , accountLinkLarge , appLink , closeablePanelheading , icon @@ -67,6 +68,28 @@ accountLinkSmall external account = ] +accountLinkLarge : Bool -> Account -> Html Msg +accountLinkLarge external account = + let + accountHref = + if external then + target "_blank" + else + href <| "#account/" ++ account.id + in + a + [ href <| "#account/" ++ account.id + ] + [ text <| + if account.display_name == "" then + account.username + else + account.display_name + , br [] [] + , span [ class "acct" ] [ text <| "@" ++ account.acct ] + ] + + accountAvatarLink : Bool -> Account -> Html Msg accountAvatarLink external account = let diff --git a/src/View/Notification.elm b/src/View/Notification.elm index 63a19f3..dda4b3e 100644 --- a/src/View/Notification.elm +++ b/src/View/Notification.elm @@ -112,18 +112,7 @@ notificationFollowView currentUser { accounts } = div [ class "status follow-profile" ] [ Common.accountAvatarLink False account , div [ class "username" ] - [ - a - [ href <| "#account/" ++ account.id - ] - [ text <| - if account.display_name == "" then - account.username - else - account.display_name - , br [] [] - , span [ class "acct" ] [ text <| "@" ++ account.acct ] - ] + [ Common.accountLinkLarge False account , span [ class "btn-sm follow-profile-date" ] [ Common.icon "time", text <| Common.formatDate created_at ] ] diff --git a/src/View/Search.elm b/src/View/Search.elm index 6a33ab8..4fd8b6a 100644 --- a/src/View/Search.elm +++ b/src/View/Search.elm @@ -16,7 +16,7 @@ accountListView accounts = profileView account = li [ class "list-group-item status follow-profile" ] [ Common.accountAvatarLink False account - , div [ class "username" ] [ Common.accountLink False account ] + , div [ class "username" ] [ Common.accountLinkLarge False account ] , formatContent account.note [] |> div [ class "status-text" @@ -47,7 +47,7 @@ searchResultsView results = hashtags -> hashtags - |> List.map (\h -> a [ class "list-group-item", href <| "#hashtag/" ++ h ] [ text <| "#" ++ h ]) + |> List.map (\h -> a [ class "list-group-item", href <| "#hashtag/" ++ h.name ] [ text <| "#" ++ h.name ]) |> div [ class "list-group" ] in div [ class "timeline" ]