1
0
Fork 0
mirror of https://code.sup39.dev/repos/Wqawg synced 2024-12-27 17:14:52 +09:00

In ticket discussion, have links to the individual messages (MessageR route)

This commit is contained in:
fr33domlover 2019-05-07 02:54:45 +00:00
parent 9bc78bf303
commit 0e4070db75
5 changed files with 31 additions and 13 deletions

View file

@ -27,6 +27,7 @@ import Data.Graph.Inductive.Graph (mkGraph, lab')
import Data.Graph.Inductive.PatriciaTree (Gr)
import Data.Graph.Inductive.Query.DFS (dffWith)
import Data.Maybe (isNothing, mapMaybe)
import Data.Text (Text)
import Data.Tree (Forest)
import Database.Esqueleto hiding (isNothing)
import Yesod.Persist.Core (runDB)
@ -41,7 +42,7 @@ import Vervis.Model
data MessageTreeNodeAuthor
= MessageTreeNodeLocal LocalMessageId Sharer
| MessageTreeNodeRemote FedURI
| MessageTreeNodeRemote Text LocalURI LocalURI
data MessageTreeNode = MessageTreeNode
{ mtnMessageId :: MessageId
@ -63,13 +64,18 @@ getMessages getdid = runDB $ do
on $ rm ^. RemoteMessageAuthor ==. rs ^. RemoteActorId
on $ rm ^. RemoteMessageRest ==. m ^. MessageId
where_ $ m ^. MessageRoot ==. val did
return (m, i ^. InstanceHost, rs ^. RemoteActorIdent)
return
( m
, i ^. InstanceHost
, rm ^. RemoteMessageIdent
, rs ^. RemoteActorIdent
)
return $ map mklocal l ++ map mkremote r
where
mklocal (Entity mid m, Value lmid, Entity _ s) =
MessageTreeNode mid m $ MessageTreeNodeLocal lmid s
mkremote (Entity mid m, Value h, Value lu) =
MessageTreeNode mid m $ MessageTreeNodeRemote $ l2f h lu
mkremote (Entity mid m, Value h, Value luMsg, Value luAuthor) =
MessageTreeNode mid m $ MessageTreeNodeRemote h luMsg luAuthor
discussionTree :: [MessageTreeNode] -> Forest MessageTreeNode
discussionTree mss =

View file

@ -85,8 +85,11 @@ getNode getdid mid = do
(Nothing, Just (Entity _rmid rm)) -> do
rs <- getJust $ remoteMessageAuthor rm
i <- getJust $ remoteActorInstance rs
return $ MessageTreeNodeRemote $
l2f (instanceHost i) (remoteActorIdent rs)
return $
MessageTreeNodeRemote
(instanceHost i)
(remoteMessageIdent rm)
(remoteActorIdent rs)
return $ MessageTreeNode mid m author
{-

View file

@ -33,9 +33,11 @@ import Yesod.Core.Widget
import qualified Data.Text as T (filter)
import Network.FedURI
import Yesod.Hashids
import Data.EventTime.Local
import Data.Time.Clock.Local ()
import Vervis.Discussion
import Vervis.Foundation
import Vervis.MediaType (MediaType (Markdown))
@ -48,18 +50,19 @@ import Vervis.Widget.Sharer (personLinkW)
actorLinkW :: MessageTreeNodeAuthor -> Widget
actorLinkW actor = $(widgetFile "widget/actor-link")
where
shortURI (FedURI h p f) = h <> p <> f
shortURI h (LocalURI p f) = h <> p <> f
messageW
:: UTCTime -> MessageTreeNode -> (MessageId -> Route App) -> Widget
messageW now (MessageTreeNode msgid msg author) reply =
messageW now (MessageTreeNode msgid msg author) reply = do
encodeHid <- getEncodeKeyHashid
let showTime =
showEventTime .
intervalToEventTime .
FriendlyConvert .
diffUTCTime now
showContent = renderSourceT Markdown . T.filter (/= '\r')
in $(widgetFile "discussion/widget/message")
$(widgetFile "discussion/widget/message")
messageTreeW
:: (MessageId -> Route App)

View file

@ -14,7 +14,13 @@ $# <http://creativecommons.org/publicdomain/zero/1.0/>.
^{actorLinkW author}
<div>
#{showTime $ messageCreated msg}
$case author
$of MessageTreeNodeLocal lmid s
<a href=@{MessageR (sharerIdent s) (encodeHid lmid)}>
#{showTime $ messageCreated msg}
$of MessageTreeNodeRemote h luMsg _luAuthor
<a href="#{renderFedURI $ l2f h luMsg}"}>
#{showTime $ messageCreated msg}
<div>
^{showContent $ messageContent msg}
<div>

View file

@ -21,8 +21,8 @@ $case actor
#{shr2text $ sharerIdent s}
<span>
./s/#{shr2text $ sharerIdent s}
$of MessageTreeNodeRemote uAuthor
<a href="#{renderFedURI uAuthor}">
$of MessageTreeNodeRemote h _luMsg luAuthor
<a href="#{renderFedURI $ l2f h luAuthor}">
(?)
<span>
#{shortURI uAuthor}
#{shortURI h luAuthor}