diff --git a/src/Vervis/Handler/Person.hs b/src/Vervis/Handler/Person.hs index 669b8c2..673453b 100644 --- a/src/Vervis/Handler/Person.hs +++ b/src/Vervis/Handler/Person.hs @@ -45,6 +45,7 @@ import Vervis.Model.Ident import Vervis.Secure import Vervis.Settings import Vervis.Widget (avatarW) +import Vervis.Widget.Sharer -- | Account verification email resend form getResendVerifyEmailR :: Handler Html @@ -145,3 +146,6 @@ getPerson shr sharer person = do } secure <- getSecure provideHtmlAndAP personAP $(widgetFile "person") + where + followButton = + followW (SharerFollowR shr) (return $ personFollowers person) diff --git a/src/Vervis/Handler/Project.hs b/src/Vervis/Handler/Project.hs index 186c85d..7176987 100644 --- a/src/Vervis/Handler/Project.hs +++ b/src/Vervis/Handler/Project.hs @@ -160,6 +160,10 @@ getProjectR shar proj = do } , AP.projectTeam = route2local $ ProjectTeamR shar proj } + followButton = + followW + (ProjectFollowR shar proj) + (return $ projectFollowers project) provideHtmlAndAP projectAP $(widgetFile "project/one") putProjectR :: ShrIdent -> PrjIdent -> Handler Html diff --git a/src/Vervis/Handler/Repo/Darcs.hs b/src/Vervis/Handler/Repo/Darcs.hs index e43e09a..7da4dba 100644 --- a/src/Vervis/Handler/Repo/Darcs.hs +++ b/src/Vervis/Handler/Repo/Darcs.hs @@ -96,6 +96,9 @@ getDarcsRepoSource repository user repo dir = do Just s -> return s addStylesheet $ HighlightStyleR style $(widgetFile "repo/source-darcs") + where + followButton = + followW (RepoFollowR user repo) (return $ repoFollowers repository) getDarcsRepoHeadChanges :: ShrIdent -> RpIdent -> Handler TypedContent getDarcsRepoHeadChanges shar repo = do diff --git a/src/Vervis/Handler/Repo/Git.hs b/src/Vervis/Handler/Repo/Git.hs index 9f34884..484a47d 100644 --- a/src/Vervis/Handler/Repo/Git.hs +++ b/src/Vervis/Handler/Repo/Git.hs @@ -111,6 +111,9 @@ getGitRepoSource repository user repo ref dir = do Just s -> return s addStylesheet $ HighlightStyleR style $(widgetFile "repo/source-git") + where + followButton = + followW (RepoFollowR user repo) (return $ repoFollowers repository) getGitRepoHeadChanges :: Repo -> ShrIdent -> RpIdent -> Handler TypedContent getGitRepoHeadChanges repository shar repo = diff --git a/src/Vervis/Handler/Ticket.hs b/src/Vervis/Handler/Ticket.hs index 74d0b60..2c921ab 100644 --- a/src/Vervis/Handler/Ticket.hs +++ b/src/Vervis/Handler/Ticket.hs @@ -291,7 +291,12 @@ getTicketR shar proj num = do encodeRouteHome . SharerR . sharerIdent . fst <$> massignee , AP.ticketIsResolved = ticketStatus ticket == TSClosed } - provideHtmlAndAP' host ticketAP $(widgetFile "ticket/one") + provideHtmlAndAP' host ticketAP $ + let followButton = + followW + (TicketFollowR shar proj num) + (return $ ticketFollowers ticket) + in $(widgetFile "ticket/one") putTicketR :: ShrIdent -> PrjIdent -> Int -> Handler Html putTicketR shar proj num = do diff --git a/src/Vervis/Widget.hs b/src/Vervis/Widget.hs index 68ed4ef..0b82a9b 100644 --- a/src/Vervis/Widget.hs +++ b/src/Vervis/Widget.hs @@ -1,6 +1,6 @@ {- This file is part of Vervis. - - - Written in 2016, 2018 by fr33domlover . + - Written in 2016, 2018, 2019 by fr33domlover . - - ♡ Copying is an act of love. Please copy, reuse and share. - @@ -27,7 +27,7 @@ import Data.Time.Calendar (toGregorian) import Data.Time.Clock (UTCTime (..)) import Development.Darcs.Rev import Formatting (sformat, (%), int, left) -import Network.HTTP.Types (StdMethod) +import Network.HTTP.Types.Method import Yesod.Core import Yesod.Core.Widget diff --git a/src/Vervis/Widget/Sharer.hs b/src/Vervis/Widget/Sharer.hs index 287ca47..7693187 100644 --- a/src/Vervis/Widget/Sharer.hs +++ b/src/Vervis/Widget/Sharer.hs @@ -16,17 +16,25 @@ module Vervis.Widget.Sharer ( sharerLinkW , sharerLinkFedW + , followW ) where +import Data.Foldable +import Database.Persist +import Network.HTTP.Types.Method import Yesod.Core +import Yesod.Persist.Core import Network.FedURI +import Yesod.Auth.Unverified + +import Database.Persist.Local import Vervis.Foundation import Vervis.Model -import Vervis.Model.Ident (ShrIdent, shr2text) -import Vervis.Settings (widgetFile) +import Vervis.Model.Ident +import Vervis.Widget sharerLinkW :: Sharer -> Widget sharerLinkW sharer = @@ -50,3 +58,17 @@ sharerLinkFedW (Right (inztance, actor)) = |] where uActor = ObjURI (instanceHost inztance) (remoteActorIdent actor) + +followW :: Route App -> AppDB FollowerSetId -> Widget +followW followRoute getFsid = do + mpid <- maybeVerifiedAuthId + for_ mpid $ \ pid -> do + mfollow <- handlerToWidget $ runDB $ do + fsid <- getFsid + getValBy $ UniqueFollow pid fsid + case mfollow of + Nothing -> buttonW POST "Follow" followRoute + Just _ -> + [whamlet| +
[Following] + |] diff --git a/templates/person.hamlet b/templates/person.hamlet index 97aae99..cdd535a 100644 --- a/templates/person.hamlet +++ b/templates/person.hamlet @@ -14,6 +14,8 @@ $# . ^{avatarW secure $ emailText $ personEmail person} +^{followButton} +

#{personAbout person}