aboutsummaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorr <r@freesoftwareextremist.com>2019-12-18 22:14:02 +0000
committerr <r@freesoftwareextremist.com>2019-12-18 22:14:02 +0000
commitd7fc7cf2f5e9c11a401ee34ed498bca762c72b79 (patch)
treece0558257067eaf737c6fbcef1de8fef78c127fd /service
parente3565202903a051b19aa76b81a0b5f9f3fdea996 (diff)
downloadbloat-d7fc7cf2f5e9c11a401ee34ed498bca762c72b79.tar.gz
bloat-d7fc7cf2f5e9c11a401ee34ed498bca762c72b79.zip
Add reply links on thread page
Diffstat (limited to 'service')
-rw-r--r--service/service.go48
1 files changed, 38 insertions, 10 deletions
diff --git a/service/service.go b/service/service.go
index bb03c26..6c7a37d 100644
--- a/service/service.go
+++ b/service/service.go
@@ -267,34 +267,46 @@ func (svc *service) ServeThreadPage(ctx context.Context, client io.Writer, c *ma
return
}
- context, err := c.GetStatusContext(ctx, id)
- if err != nil {
- return
- }
-
u, err := c.GetAccountCurrentUser(ctx)
if err != nil {
return
}
var content string
+ var replyToID string
if reply {
+ replyToID = id
if u.ID != status.Account.ID {
content += "@" + status.Account.Acct + " "
}
- for _, m := range status.Mentions {
- if u.ID != m.ID {
- content += "@" + m.Acct + " "
+ for i := range status.Mentions {
+ if status.Mentions[i].ID != u.ID && status.Mentions[i].ID != status.Account.ID {
+ content += "@" + status.Mentions[i].Acct + " "
}
}
}
+ context, err := c.GetStatusContext(ctx, id)
+ if err != nil {
+ return
+ }
+
+ statuses := append(append(context.Ancestors, status), context.Descendants...)
+
+ replyMap := make(map[string][]mastodon.ReplyInfo)
+
+ for i := range statuses {
+ statuses[i].ShowReplies = true
+ statuses[i].ReplyMap = replyMap
+ addToReplyMap(replyMap, statuses[i].InReplyToID, statuses[i].ID, i+1)
+ }
+
navbarData, err := svc.getNavbarTemplateData(ctx, client, c)
if err != nil {
return
}
- data := renderer.NewThreadPageTemplateData(status, context, reply, id, content, navbarData)
+ data := renderer.NewThreadPageTemplateData(statuses, reply, replyToID, content, replyMap, navbarData)
err = svc.renderer.RenderThreadPage(ctx, client, data)
if err != nil {
return
@@ -323,7 +335,7 @@ func (svc *service) ServeNotificationPage(ctx context.Context, client io.Writer,
switch notifications[i].Type {
case "reblog", "favourite":
if notifications[i].Status != nil {
- notifications[i].Status.Account.ID = ""
+ notifications[i].Status.HideAccountInfo = true
}
}
if notifications[i].Pleroma != nil && notifications[i].Pleroma.IsSeen {
@@ -418,3 +430,19 @@ func (svc *service) PostTweet(ctx context.Context, client io.Writer, c *mastodon
return s.ID, nil
}
+
+func addToReplyMap(m map[string][]mastodon.ReplyInfo, key interface{}, val string, number int) {
+ if key == nil {
+ return
+ }
+ keyStr, ok := key.(string)
+ if !ok {
+ return
+ }
+ _, ok = m[keyStr]
+ if !ok {
+ m[keyStr] = []mastodon.ReplyInfo{}
+ }
+
+ m[keyStr] = append(m[keyStr], mastodon.ReplyInfo{val, number})
+}