mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-19 08:26:23 -07:00
Implement thread-unique poster ID
This commit is contained in:
parent
7690bad025
commit
0db91f277c
4 changed files with 41 additions and 0 deletions
|
@ -261,4 +261,10 @@ div.inlinepostprev {
|
|||
padding: 4px;
|
||||
display: inline-block;
|
||||
background: colors.$hashtagbg;
|
||||
}
|
||||
|
||||
.poster-id {
|
||||
font-size: 0.8em;
|
||||
padding: 0 5px;
|
||||
border-radius: 1em;
|
||||
}
|
|
@ -280,6 +280,12 @@ div.inlinepostprev {
|
|||
background: rgba(0, 0, 0, 0.1019607843);
|
||||
}
|
||||
|
||||
.poster-id {
|
||||
font-size: 0.8em;
|
||||
padding: 0 5px;
|
||||
border-radius: 1em;
|
||||
}
|
||||
|
||||
div.section-block {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package building
|
|||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"net"
|
||||
"path"
|
||||
|
@ -79,6 +80,7 @@ type Post struct {
|
|||
Country geoip.Country `json:"-"`
|
||||
thread gcsql.Thread
|
||||
uploadPath string
|
||||
uniqueID string
|
||||
}
|
||||
|
||||
// TitleText returns the text to be used for the title of the page
|
||||
|
@ -102,6 +104,29 @@ func (p *Post) ThreadPath() string {
|
|||
return config.WebPath(p.BoardDir, "res", strconv.Itoa(threadID)+".html")
|
||||
}
|
||||
|
||||
// ThreadUniqueID returns a 6-character hexidecimal ID for the user in a thread, allowing anonymity while discouraging sockpuppetting
|
||||
func (p *Post) ThreadUniqueID() string {
|
||||
if p.uniqueID != "" {
|
||||
return p.uniqueID
|
||||
}
|
||||
hash := sha256.New()
|
||||
hash.Write(p.IP)
|
||||
hash.Write([]byte(p.BoardDir))
|
||||
hash.Write([]byte(strconv.Itoa(p.ParentID)))
|
||||
p.uniqueID = fmt.Sprintf("%02x", hash.Sum(nil)[:3])
|
||||
return p.uniqueID
|
||||
}
|
||||
|
||||
// ThreadUniqueIDColorIsDark returns true if the color represented by the thread unique ID has a dark luminance
|
||||
func (p *Post) ThreadUniqueIDColorIsDark() bool {
|
||||
id := p.ThreadUniqueID()
|
||||
red, _ := strconv.ParseInt(id[0:2], 16, 0)
|
||||
green, _ := strconv.ParseInt(id[2:4], 16, 0)
|
||||
blue, _ := strconv.ParseInt(id[4:6], 16, 0)
|
||||
luminance := 0.299*float32(red) + 0.587*float32(green) + 0.114*float32(blue)
|
||||
return luminance < 128
|
||||
}
|
||||
|
||||
// Timestamp returns the time the post was created.
|
||||
// Deprecated: Use CreatedOn instead.
|
||||
func (p *Post) Timestamp() time.Time {
|
||||
|
|
|
@ -18,6 +18,10 @@
|
|||
{{- end -}}
|
||||
{{- if ne .post.Email ""}}</a>{{end}}</span>
|
||||
{{- if ne .post.Tripcode ""}}<span class="tripcode">!{{.post.Tripcode}}</span>{{end -}}
|
||||
{{- if .global.boardConfig.ShowPosterID -}}
|
||||
{{$uniqueID := .post.ThreadUniqueID}}
|
||||
<span class="poster-id-container">(ID: <span class="poster-id" style="background: #{{$uniqueID}}; color: {{if .post.ThreadUniqueIDColorIsDark}}white{{else}}black{{end}}">{{$uniqueID}}</span>)</span>
|
||||
{{- end -}}
|
||||
{{- if ne .post.Country.Flag ""}}{{template "post_flag" .post.Country}}{{end}}
|
||||
<time datetime="{{formatTimestampAttribute .post.Timestamp}}">{{formatTimestamp .post.Timestamp}}</time>
|
||||
</label> <a href="{{.post.WebPath}}">No.</a> <a href="javascript:quote({{.post.ID}})" class="backlink-click">{{.post.ID}}</a>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue