1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
package main
import (
"encoding/json"
"net/http"
"slices"
"strings"
)
func (u *User) viewMentions(w http.ResponseWriter, r *http.Request) {
isAdmin, _ := u.config.IsAdmin(r)
if strings.Contains(r.Header.Get("accept"), "text/html") {
posts := []*Post{}
WalkCache(u, "mentions", "direct", func(id string, b []byte) {
postmeta := &PostMeta{}
if err := json.Unmarshal(b, postmeta); err == nil {
post := FromNote(id, u, postmeta.Actor, &postmeta.Object)
if isAdmin {
post.Sensitive = false
}
posts = append(posts, post)
}
})
WalkCache(u, "mentions", "remote", func(id string, b []byte) {
postmeta := &PostMeta{}
if err := json.Unmarshal(b, postmeta); err == nil {
post := FromNote(id, u, postmeta.Actor, &postmeta.Object)
if isAdmin {
post.Sensitive = false
}
posts = append(posts, post)
}
})
slices.SortFunc(posts, ComparePost)
slices.Reverse(posts)
page := u.config.DefaultPage(r)
page.User = u
page.IsAdmin = isAdmin
page.Posts = posts
u.config.Templates.ExecuteTemplate(w, "mentions.tpl.html", page)
return
}
}
|