2016-05-23 20:46:54 +00:00
|
|
|
{- This file is part of Vervis.
|
|
|
|
-
|
2019-02-14 22:13:58 +00:00
|
|
|
- Written in 2016, 2019 by fr33domlover <fr33domlover@riseup.net>.
|
2016-05-23 20:46:54 +00:00
|
|
|
-
|
|
|
|
- ♡ Copying is an act of love. Please copy, reuse and share.
|
|
|
|
-
|
|
|
|
- The author(s) have dedicated all copyright and related and neighboring
|
|
|
|
- rights to this software to the public domain worldwide. This software is
|
|
|
|
- distributed without any warranty.
|
|
|
|
-
|
|
|
|
- You should have received a copy of the CC0 Public Domain Dedication along
|
|
|
|
- with this software. If not, see
|
|
|
|
- <http://creativecommons.org/publicdomain/zero/1.0/>.
|
|
|
|
-}
|
|
|
|
|
2016-05-24 21:48:21 +00:00
|
|
|
module Vervis.Widget.Sharer
|
2016-05-23 20:46:54 +00:00
|
|
|
( sharerLinkW
|
2019-06-07 04:26:32 +00:00
|
|
|
, sharerLinkFedW
|
2019-10-02 08:07:26 +00:00
|
|
|
, followW
|
2016-05-23 20:46:54 +00:00
|
|
|
)
|
|
|
|
where
|
|
|
|
|
2019-10-02 08:07:26 +00:00
|
|
|
import Data.Foldable
|
|
|
|
import Database.Persist
|
|
|
|
import Network.HTTP.Types.Method
|
2019-06-07 04:26:32 +00:00
|
|
|
import Yesod.Core
|
2019-10-02 08:07:26 +00:00
|
|
|
import Yesod.Persist.Core
|
2019-06-07 04:26:32 +00:00
|
|
|
|
|
|
|
import Network.FedURI
|
2019-10-02 08:07:26 +00:00
|
|
|
import Yesod.Auth.Unverified
|
|
|
|
|
|
|
|
import Database.Persist.Local
|
2016-05-24 21:48:21 +00:00
|
|
|
|
2016-05-23 20:46:54 +00:00
|
|
|
import Vervis.Foundation
|
|
|
|
import Vervis.Model
|
2019-10-02 08:07:26 +00:00
|
|
|
import Vervis.Model.Ident
|
|
|
|
import Vervis.Widget
|
2016-05-23 20:46:54 +00:00
|
|
|
|
|
|
|
sharerLinkW :: Sharer -> Widget
|
2019-06-07 04:26:32 +00:00
|
|
|
sharerLinkW sharer =
|
|
|
|
[whamlet|
|
|
|
|
<a href=@{SharerR $ sharerIdent sharer}>
|
|
|
|
$maybe name <- sharerName sharer
|
|
|
|
#{name}
|
|
|
|
$nothing
|
|
|
|
#{shr2text $ sharerIdent sharer}
|
|
|
|
|]
|
|
|
|
|
|
|
|
sharerLinkFedW :: Either Sharer (Instance, RemoteActor) -> Widget
|
|
|
|
sharerLinkFedW (Left sharer) = sharerLinkW sharer
|
|
|
|
sharerLinkFedW (Right (inztance, actor)) =
|
|
|
|
[whamlet|
|
2019-07-23 13:59:48 +00:00
|
|
|
<a href="#{renderObjURI uActor}">
|
2019-06-07 04:26:32 +00:00
|
|
|
$maybe name <- remoteActorName actor
|
|
|
|
#{name}
|
|
|
|
$nothing
|
|
|
|
(?)
|
|
|
|
|]
|
|
|
|
where
|
2019-07-23 13:59:48 +00:00
|
|
|
uActor = ObjURI (instanceHost inztance) (remoteActorIdent actor)
|
2019-10-02 08:07:26 +00:00
|
|
|
|
|
|
|
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|
|
|
|
|
<div>[Following]
|
|
|
|
|]
|