mirror of
https://github.com/rystaf/mlmym.git
synced 2024-12-29 03:53:46 +00:00
context and parent comment links
This commit is contained in:
parent
7b423eebb7
commit
ddf25011cc
|
@ -115,7 +115,8 @@ summary {
|
|||
.title a p {
|
||||
display: inline;
|
||||
}
|
||||
.post.distinguished .title a {
|
||||
.post.distinguished .title a,
|
||||
.dark .post.distinguished .title a:visited {
|
||||
color: #228822;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
@ -218,7 +219,7 @@ summary {
|
|||
font-size: 10px;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
.meta a {
|
||||
.meta a, .activity .meta a {
|
||||
color: #369;
|
||||
text-decoration: none;
|
||||
font-size: 10px;
|
||||
|
|
|
@ -307,7 +307,8 @@ function setup() {
|
|||
hidechildren.addEventListener("click", hideAllChildComments)
|
||||
}
|
||||
if (lmc = document.getElementById("lmc")){
|
||||
if (pager = document.getElementsByClassName("pager")){
|
||||
var pager = document.getElementsByClassName("pager")
|
||||
if (pager.length) {
|
||||
pager[0].style.display = "none";
|
||||
}
|
||||
lmc.addEventListener("click", loadMoreComments)
|
||||
|
|
|
@ -414,6 +414,10 @@ func GetComment(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|||
if len(m["source"]) > 0 {
|
||||
state.Op = "source"
|
||||
}
|
||||
if len(m["context"]) > 0 {
|
||||
ctx, _ := strconv.Atoi(m["context"][0])
|
||||
state.Context = ctx
|
||||
}
|
||||
commentid, _ := strconv.Atoi(ps.ByName("commentid"))
|
||||
state.GetComment(commentid)
|
||||
state.GetPost(state.PostID)
|
||||
|
|
37
state.go
37
state.go
|
@ -33,6 +33,12 @@ func (c *Comment) Submitter() bool {
|
|||
return c.P.Comment.CreatorID == c.P.Post.CreatorID
|
||||
}
|
||||
|
||||
func (c *Comment) ParentID() int {
|
||||
path := strings.Split(c.P.Comment.Path, ".")
|
||||
id, _ := strconv.Atoi(path[len(path)-2])
|
||||
return id
|
||||
}
|
||||
|
||||
type Person struct {
|
||||
types.PersonViewSafe
|
||||
}
|
||||
|
@ -78,6 +84,7 @@ type State struct {
|
|||
CommentCount int
|
||||
PostID int
|
||||
CommentID int
|
||||
Context int
|
||||
UserName string
|
||||
User *types.GetPersonDetailsResponse
|
||||
Now int64
|
||||
|
@ -258,6 +265,30 @@ func (state *State) GetComment(commentid int) {
|
|||
state.Comments = append(state.Comments, comment)
|
||||
}
|
||||
}
|
||||
ctx, err := state.GetContext(state.Context, state.Comments[0])
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
state.Comments = []Comment{ctx}
|
||||
}
|
||||
}
|
||||
func (state *State) GetContext(depth int, comment Comment) (ctx Comment, err error) {
|
||||
if depth < 1 || comment.ParentID() == 0 {
|
||||
return comment, nil
|
||||
}
|
||||
cresp, err := state.Client.Comment(context.Background(), types.GetComment{
|
||||
ID: comment.ParentID(),
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
ctx, err = state.GetContext(depth-1, Comment{
|
||||
P: cresp.CommentView,
|
||||
State: state,
|
||||
C: []Comment{comment},
|
||||
ChildCount: comment.ChildCount + 1,
|
||||
})
|
||||
return
|
||||
}
|
||||
func (state *State) GetComments() {
|
||||
if state.Sort != "Hot" && state.Sort != "Top" && state.Sort != "Old" && state.Sort != "New" {
|
||||
|
@ -504,9 +535,13 @@ func (state *State) Search(searchtype string) {
|
|||
})
|
||||
}
|
||||
for _, c := range resp.Comments {
|
||||
state.Comments = append(state.Comments, Comment{
|
||||
comment := Comment{
|
||||
P: c,
|
||||
State: state,
|
||||
}
|
||||
state.Activities = append(state.Activities, Activity{
|
||||
Timestamp: c.Comment.Published.Time,
|
||||
Comment: &comment,
|
||||
})
|
||||
}
|
||||
state.Communities = resp.Communities
|
||||
|
|
|
@ -3,16 +3,18 @@
|
|||
<div class="activity">
|
||||
{{ if $activity.Comment }}
|
||||
<div class="title{{ if eq $activity.Comment.Op "unread"}} orangered{{end}}">
|
||||
{{ if not $state.User }}
|
||||
{{ if and (not $state.User) (not $state.Query) }}
|
||||
<b>comment</b> on
|
||||
{{ end }}
|
||||
<a href="/{{$state.Host}}/post/{{ $activity.Comment.P.Post.ID}}">{{ $activity.Comment.P.Post.Name}}</a>
|
||||
<span class="meta">
|
||||
{{ if $state.User}}
|
||||
by
|
||||
<a href="">{{$state.User.PersonView.Person.Name }}</a>
|
||||
{{ end }}
|
||||
in
|
||||
<a href="/{{$state.Host}}/c/{{ fullcname $activity.Comment.P.Community }}">/c/{{ $activity.Comment.P.Community.Name }}</a>
|
||||
</span>
|
||||
</div>
|
||||
{{ template "comment.html" $activity.Comment }}
|
||||
{{ else if $activity.Post }}
|
||||
|
|
|
@ -87,6 +87,16 @@
|
|||
</a>
|
||||
</li>
|
||||
{{ end }}
|
||||
{{ if and .ParentID .State.CommentID }}
|
||||
<li>
|
||||
<a href="/{{.State.Host}}/comment/{{.ParentID}}">parent</a>
|
||||
</li>
|
||||
{{ end }}
|
||||
{{ if and .ParentID (or .State.Activities .State.Query) }}
|
||||
<li>
|
||||
<a href="/{{.State.Host}}/comment/{{.P.Comment.ID}}?context=3">context</a>
|
||||
</li>
|
||||
{{ end }}
|
||||
{{ if gt .ChildCount 0 }}
|
||||
<li><a class="hidechildren" for="c{{.P.Comment.ID}}" href=""><span class="hide">hide</span><span class="show">show {{ .ChildCount }}</span> child comments</a></li>
|
||||
{{ end }}
|
||||
|
@ -105,7 +115,7 @@
|
|||
</form>
|
||||
{{ end}}
|
||||
{{ range $ci, $child := .C }}{{ template "comment.html" $child }}{{end}}
|
||||
{{ if ne .P.Counts.ChildCount .ChildCount}}
|
||||
{{ if and (ne .P.Counts.ChildCount .ChildCount) (not .State.Activities) (not .State.Query) }}
|
||||
<div class="morecomments">
|
||||
<a class="loadmore" for="c{{ .P.Comment.ID}}" href="/{{.State.Host}}/comment/{{.P.Comment.ID}}?">load more comments</a>
|
||||
<span class="gray">({{ sub .P.Counts.ChildCount .ChildCount}} replies)</span>
|
||||
|
|
|
@ -108,7 +108,7 @@
|
|||
{{ template "comment.html" $comment }}
|
||||
{{ end }}
|
||||
|
||||
{{ if (and .Comments (gt (index .Posts 0).Counts.Comments .CommentCount)) }}
|
||||
{{ if and .Comments .Posts (gt (index .Posts 0).Counts.Comments .CommentCount) (not .CommentID)}}
|
||||
<div class="morecomments">
|
||||
<a id="lmc" href="" data-page="2">load more comments</a>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue