diff options
| -rw-r--r-- | mastodon/status.go | 16 | ||||
| -rw-r--r-- | model/status.go | 1 | ||||
| -rw-r--r-- | renderer/model.go | 10 | ||||
| -rw-r--r-- | service/service.go | 48 | ||||
| -rw-r--r-- | static/main.css | 27 | ||||
| -rw-r--r-- | templates/status.tmpl | 17 | ||||
| -rw-r--r-- | templates/thread.tmpl | 8 | 
7 files changed, 103 insertions, 24 deletions
| diff --git a/mastodon/status.go b/mastodon/status.go index b6110d5..9f029d1 100644 --- a/mastodon/status.go +++ b/mastodon/status.go @@ -10,6 +10,15 @@ import (  	"time"  ) +type StatusPleroma struct { +	InReplyToAccountAcct string `json:"in_reply_to_account_acct"` +} + +type ReplyInfo struct { +	ID     string `json:"id"` +	Number int    `json:"number"` +} +  // Status is struct to hold status.  type Status struct {  	ID                 string       `json:"id"` @@ -38,6 +47,13 @@ type Status struct {  	Application        Application  `json:"application"`  	Language           string       `json:"language"`  	Pinned             interface{}  `json:"pinned"` + +	// Custom fields +	Pleroma         StatusPleroma          `json:"pleroma"` +	HideAccountInfo bool                   `json:"hide_account_info"` +	ShowReplies     bool                   `json:"show_replies"` +	ReplyMap        map[string][]ReplyInfo `json:"reply_map"` +	ReplyNumber     int                    `json:"reply_number"`  }  // Context hold information for mastodon context. diff --git a/model/status.go b/model/status.go new file mode 100644 index 0000000..8b53790 --- /dev/null +++ b/model/status.go @@ -0,0 +1 @@ +package model diff --git a/renderer/model.go b/renderer/model.go index 4529386..2a320cc 100644 --- a/renderer/model.go +++ b/renderer/model.go @@ -36,21 +36,21 @@ func NewTimelinePageTemplateData(statuses []*mastodon.Status, hasNext bool, next  }  type ThreadPageTemplateData struct { -	Status       *mastodon.Status -	Context      *mastodon.Context +	Statuses     []*mastodon.Status  	PostReply    bool  	ReplyToID    string  	ReplyContent string +	ReplyMap     map[string][]mastodon.ReplyInfo  	NavbarData   *NavbarTemplateData  } -func NewThreadPageTemplateData(status *mastodon.Status, context *mastodon.Context, postReply bool, replyToID string, replyContent string, navbarData *NavbarTemplateData) *ThreadPageTemplateData { +func NewThreadPageTemplateData(statuses []*mastodon.Status, postReply bool, replyToID string, replyContent string, replyMap map[string][]mastodon.ReplyInfo, navbarData *NavbarTemplateData) *ThreadPageTemplateData {  	return &ThreadPageTemplateData{ -		Status:       status, -		Context:      context, +		Statuses:     statuses,  		PostReply:    postReply,  		ReplyToID:    replyToID,  		ReplyContent: replyContent, +		ReplyMap:     replyMap,  		NavbarData:   navbarData,  	}  } 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}) +} diff --git a/static/main.css b/static/main.css index 8865820..7f8cd90 100644 --- a/static/main.css +++ b/static/main.css @@ -7,7 +7,7 @@  }  .status-content { -	margin: 8px 0; +	margin: 4px 0 8px 0;  }  .status-content p { @@ -18,6 +18,7 @@  	height: 48px;  	width: 48px;  	margin-right: 8px; +	object-fit: contain;  }  .status { @@ -118,6 +119,7 @@  	height: 24px;  	width: 24px;  	margin-bottom: -8px; +	margin-right: 0px;  }  .retweet-info .status-dname{ @@ -161,3 +163,26 @@  .notification-follow-uname {  	margin-top: 8px;  } + +.status-reply-to { +	vertical-align: center; +	font-size: 10pt +} + +.status-reply-container .icon { +	font-size: 10pt; +	vertical-align: sub; +	margin-right: -2px; +} + +.status-reply-text { +	font-size: 10pt; +} + +.status-reply { +	font-size: 10pt; +} + +.status-reply-info-divider { +	margin: 0 4px; +} diff --git a/templates/status.tmpl b/templates/status.tmpl index 7020be0..4dbbe3c 100644 --- a/templates/status.tmpl +++ b/templates/status.tmpl @@ -11,17 +11,30 @@  	{{block "status" .}}  	<div class="status-container">  		<div> -			{{if ne .Account.ID ""}} +			{{if not .HideAccountInfo}}  			<img class="status-profile-img" src="{{.Account.AvatarStatic}}" alt="profile-avatar" />  			{{end}}  		</div>  		<div class="status">  -			{{if ne .Account.ID ""}} +			{{if not .HideAccountInfo}}  			<div class="status-name">  				<span class="status-dname"> {{WithEmojis .Account.DisplayName .Account.Emojis}} </span>   				<span class="status-uname"> {{.Account.Acct}} </span>  			</div>  			{{end}} +			<div class="status-reply-container"> +				{{if .InReplyToID}} +				<span class="icon dripicons-forward"></span>  +				<a class="status-reply-to" href="{{if not .ShowReplies}}/thread/{{.InReplyToID}}{{end}}#status-{{.InReplyToID}}"> reply to {{.Pleroma.InReplyToAccountAcct}} </a> +				{{if index .ReplyMap .ID}} <span class="status-reply-info-divider"> - </span> {{end}} +				{{end}} +				{{if .ShowReplies}} +				{{if index .ReplyMap .ID}} <span class="status-reply-text"> replies: </span> {{end}} +				{{range index .ReplyMap .ID}} +				<a class="status-reply" href="#status-{{.ID}}">#{{.Number}}</a> +				{{end}} +				{{end}} +			</div>  			<div class="status-content"> {{WithEmojis .Content .Emojis}} </div>  			<div class="status-media-container">  			{{range .MediaAttachments}} diff --git a/templates/thread.tmpl b/templates/thread.tmpl index 29d702b..e36c5ea 100644 --- a/templates/thread.tmpl +++ b/templates/thread.tmpl @@ -2,12 +2,10 @@  {{template "navigation.tmpl" .NavbarData}}  <div class="page-title"> Thread </div> -{{range .Context.Ancestors}} +{{range .Statuses}}  {{template "status.tmpl" .}} -{{end}} -{{template "status.tmpl" .Status}} -{{if .PostReply}} +{{if eq .ID $.ReplyToID}}  <form class="timeline-post-form" action="/post" method="POST" enctype="multipart/form-data">  	<input type="hidden" name="reply_to_id" value="{{.ReplyToID}}" />  	<label for="post-content"> Reply to {{.Status.Account.DisplayName}} </label> @@ -20,8 +18,6 @@  </form>  {{end}} -{{range .Context.Descendants}} -{{template "status.tmpl" .}}  {{end}}  {{template "footer.tmpl"}} | 
