[bugfix/frontend] Don't show replies to hidden parents; return 404 if no "main" thread (#3411)
This commit is contained in:
parent
1bc59a0a33
commit
a69142a403
|
@ -19,6 +19,7 @@ package status
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -402,6 +403,10 @@ func (p *Processor) WebContextGet(
|
||||||
// We should mark the next **VISIBLE**
|
// We should mark the next **VISIBLE**
|
||||||
// reply as the first reply.
|
// reply as the first reply.
|
||||||
markNextVisibleAsFirstReply bool
|
markNextVisibleAsFirstReply bool
|
||||||
|
|
||||||
|
// Map of statuses that didn't pass visi
|
||||||
|
// checks and won't be shown via the web.
|
||||||
|
hiddenStatuses = make(map[string]struct{})
|
||||||
)
|
)
|
||||||
|
|
||||||
for idx, status := range wholeThread {
|
for idx, status := range wholeThread {
|
||||||
|
@ -427,11 +432,16 @@ func (p *Processor) WebContextGet(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure status is actually
|
// Ensure status is actually visible to just
|
||||||
// visible to just anyone, and
|
// anyone, and hide / don't include it if not.
|
||||||
// hide / don't include it if not.
|
//
|
||||||
|
// Include a check to see if the parent status
|
||||||
|
// is hidden; if so, we shouldn't show the child
|
||||||
|
// as it leads to weird-looking threading where
|
||||||
|
// a status seems to reply to nothing.
|
||||||
|
_, parentHidden := hiddenStatuses[status.InReplyToID]
|
||||||
v, err := p.visFilter.StatusVisible(ctx, nil, status)
|
v, err := p.visFilter.StatusVisible(ctx, nil, status)
|
||||||
if err != nil || !v {
|
if err != nil || !v || parentHidden {
|
||||||
if !inReplies {
|
if !inReplies {
|
||||||
// Main thread entry hidden.
|
// Main thread entry hidden.
|
||||||
wCtx.ThreadHidden++
|
wCtx.ThreadHidden++
|
||||||
|
@ -439,12 +449,15 @@ func (p *Processor) WebContextGet(
|
||||||
// Reply hidden.
|
// Reply hidden.
|
||||||
wCtx.ThreadRepliesHidden++
|
wCtx.ThreadRepliesHidden++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hiddenStatuses[status.ID] = struct{}{}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare visible status to add to thread context.
|
// Prepare visible status to add to thread context.
|
||||||
webStatus, err := p.converter.StatusToWebStatus(ctx, status)
|
webStatus, err := p.converter.StatusToWebStatus(ctx, status)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
hiddenStatuses[status.ID] = struct{}{}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -512,9 +525,17 @@ func (p *Processor) WebContextGet(
|
||||||
wCtx.ThreadLength = threadLength
|
wCtx.ThreadLength = threadLength
|
||||||
}
|
}
|
||||||
|
|
||||||
// Jot down number of hidden posts so template doesn't have to do it.
|
// Jot down number of "main" thread entries shown.
|
||||||
wCtx.ThreadShown = wCtx.ThreadLength - wCtx.ThreadHidden
|
wCtx.ThreadShown = wCtx.ThreadLength - wCtx.ThreadHidden
|
||||||
|
|
||||||
|
// If there's no posts visible in the
|
||||||
|
// "main" thread we shouldn't show replies
|
||||||
|
// via the web as that's just weird.
|
||||||
|
if wCtx.ThreadShown < 1 {
|
||||||
|
const text = "no statuses visible in main thread"
|
||||||
|
return nil, gtserror.NewErrorNotFound(errors.New(text))
|
||||||
|
}
|
||||||
|
|
||||||
// Mark the last "main" visible status.
|
// Mark the last "main" visible status.
|
||||||
wCtx.Statuses[wCtx.ThreadShown-1].ThreadLastMain = true
|
wCtx.Statuses[wCtx.ThreadShown-1].ThreadLastMain = true
|
||||||
|
|
||||||
|
@ -523,7 +544,7 @@ func (p *Processor) WebContextGet(
|
||||||
// part of the "main" thread.
|
// part of the "main" thread.
|
||||||
wCtx.ThreadReplies = threadLength - wCtx.ThreadLength
|
wCtx.ThreadReplies = threadLength - wCtx.ThreadLength
|
||||||
|
|
||||||
// Jot down number of hidden replies so template doesn't have to do it.
|
// Jot down number of "replies" shown.
|
||||||
wCtx.ThreadRepliesShown = wCtx.ThreadReplies - wCtx.ThreadRepliesHidden
|
wCtx.ThreadRepliesShown = wCtx.ThreadReplies - wCtx.ThreadRepliesHidden
|
||||||
|
|
||||||
// Return the finished context.
|
// Return the finished context.
|
||||||
|
|
Loading…
Reference in New Issue