fix: add new type StatusList
Add a new type called StatusList for managing different types of status lists in preparation for bookmark support. This replaces the Timeline type. Update timeline headers.
This commit is contained in:
parent
8e4da7f827
commit
674f277eba
4 changed files with 74 additions and 53 deletions
|
@ -11,51 +11,55 @@ import (
|
|||
"codeflow.dananglin.me.uk/apollo/enbas/internal/model"
|
||||
)
|
||||
|
||||
func (g *Client) GetHomeTimeline(limit int) (model.Timeline, error) {
|
||||
func (g *Client) GetHomeTimeline(limit int) (model.StatusList, error) {
|
||||
path := fmt.Sprintf("/api/v1/timelines/home?limit=%d", limit)
|
||||
|
||||
timeline := model.Timeline{
|
||||
Name: "HOME TIMELINE",
|
||||
timeline := model.StatusList{
|
||||
Type: model.StatusListTimeline,
|
||||
Name: "HOME",
|
||||
Statuses: nil,
|
||||
}
|
||||
|
||||
return g.getTimeline(path, timeline)
|
||||
}
|
||||
|
||||
func (g *Client) GetPublicTimeline(limit int) (model.Timeline, error) {
|
||||
func (g *Client) GetPublicTimeline(limit int) (model.StatusList, error) {
|
||||
path := fmt.Sprintf("/api/v1/timelines/public?limit=%d", limit)
|
||||
|
||||
timeline := model.Timeline{
|
||||
Name: "PUBLIC TIMELINE",
|
||||
timeline := model.StatusList{
|
||||
Type: model.StatusListTimeline,
|
||||
Name: "PUBLIC",
|
||||
Statuses: nil,
|
||||
}
|
||||
|
||||
return g.getTimeline(path, timeline)
|
||||
}
|
||||
|
||||
func (g *Client) GetListTimeline(listID string, limit int) (model.Timeline, error) {
|
||||
func (g *Client) GetListTimeline(listID, title string, limit int) (model.StatusList, error) {
|
||||
path := fmt.Sprintf("/api/v1/timelines/list/%s?limit=%d", listID, limit)
|
||||
|
||||
timeline := model.Timeline{
|
||||
Name: "LIST: " + listID,
|
||||
timeline := model.StatusList{
|
||||
Type: model.StatusListTimeline,
|
||||
Name: "LIST (" + title + ")",
|
||||
Statuses: nil,
|
||||
}
|
||||
|
||||
return g.getTimeline(path, timeline)
|
||||
}
|
||||
|
||||
func (g *Client) GetTagTimeline(tag string, limit int) (model.Timeline, error) {
|
||||
func (g *Client) GetTagTimeline(tag string, limit int) (model.StatusList, error) {
|
||||
path := fmt.Sprintf("/api/v1/timelines/tag/%s?limit=%d", tag, limit)
|
||||
|
||||
timeline := model.Timeline{
|
||||
Name: "TAG: " + tag,
|
||||
timeline := model.StatusList{
|
||||
Type: model.StatusListTimeline,
|
||||
Name: "TAG (" + tag + ")",
|
||||
Statuses: nil,
|
||||
}
|
||||
|
||||
return g.getTimeline(path, timeline)
|
||||
}
|
||||
|
||||
func (g *Client) getTimeline(path string, timeline model.Timeline) (model.Timeline, error) {
|
||||
func (g *Client) getTimeline(path string, timeline model.StatusList) (model.StatusList, error) {
|
||||
url := g.Authentication.Instance + path
|
||||
|
||||
var statuses []model.Status
|
||||
|
|
|
@ -166,7 +166,7 @@ func (c *ShowExecutor) showStatus(gtsClient *client.Client) error {
|
|||
|
||||
func (c *ShowExecutor) showTimeline(gtsClient *client.Client) error {
|
||||
var (
|
||||
timeline model.Timeline
|
||||
timeline model.StatusList
|
||||
err error
|
||||
)
|
||||
|
||||
|
@ -180,7 +180,14 @@ func (c *ShowExecutor) showTimeline(gtsClient *client.Client) error {
|
|||
return FlagNotSetError{flagText: flagListID}
|
||||
}
|
||||
|
||||
timeline, err = gtsClient.GetListTimeline(c.listID, c.limit)
|
||||
var list model.List
|
||||
|
||||
list, err = gtsClient.GetList(c.listID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to retrieve the list: %w", err)
|
||||
}
|
||||
|
||||
timeline, err = gtsClient.GetListTimeline(list.ID, list.Title, c.limit)
|
||||
case model.TimelineCategoryTag:
|
||||
if c.tag == "" {
|
||||
return FlagNotSetError{flagText: flagTag}
|
||||
|
|
|
@ -6,6 +6,7 @@ package model
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/utilities"
|
||||
|
@ -199,3 +200,50 @@ func (s Status) Display(noColor bool) string {
|
|||
s.URL,
|
||||
)
|
||||
}
|
||||
|
||||
type StatusListType int
|
||||
|
||||
const (
|
||||
StatusListTimeline StatusListType = iota
|
||||
StatusListBookMarks
|
||||
)
|
||||
|
||||
type StatusList struct {
|
||||
Type StatusListType
|
||||
Name string
|
||||
Statuses []Status
|
||||
}
|
||||
|
||||
func (s StatusList) Display(noColor bool) string {
|
||||
var builder strings.Builder
|
||||
var name string
|
||||
|
||||
separator := "────────────────────────────────────────────────────────────────────────────────"
|
||||
|
||||
if s.Type == StatusListTimeline {
|
||||
name = "TIMELINE: " + s.Name
|
||||
} else {
|
||||
name = s.Name
|
||||
}
|
||||
|
||||
builder.WriteString(utilities.HeaderFormat(noColor, name) + "\n")
|
||||
|
||||
for _, status := range s.Statuses {
|
||||
builder.WriteString("\n" + utilities.DisplayNameFormat(noColor, status.Account.DisplayName) + " (@" + status.Account.Acct + ")\n")
|
||||
|
||||
statusID := status.ID
|
||||
createdAt := status.CreatedAt
|
||||
|
||||
if status.Reblog != nil {
|
||||
builder.WriteString("reposted this status from " + utilities.DisplayNameFormat(noColor, status.Reblog.Account.DisplayName) + " (@" + status.Reblog.Account.Acct + ")\n")
|
||||
statusID = status.Reblog.ID
|
||||
createdAt = status.Reblog.CreatedAt
|
||||
}
|
||||
|
||||
builder.WriteString(utilities.WrapLines(utilities.ConvertHTMLToText(status.Content), "\n", 80) + "\n\n")
|
||||
builder.WriteString(utilities.FieldFormat(noColor, "ID:") + " " + statusID + "\t" + utilities.FieldFormat(noColor, "Created at:") + " " + utilities.FormatTime(createdAt) + "\n")
|
||||
builder.WriteString(separator + "\n")
|
||||
}
|
||||
|
||||
return builder.String()
|
||||
}
|
||||
|
|
|
@ -4,12 +4,6 @@
|
|||
|
||||
package model
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/utilities"
|
||||
)
|
||||
|
||||
const (
|
||||
TimelineCategoryHome = "home"
|
||||
TimelineCategoryPublic = "public"
|
||||
|
@ -30,35 +24,3 @@ func (e InvalidTimelineCategoryError) Error() string {
|
|||
TimelineCategoryTag + ", " +
|
||||
TimelineCategoryList + ")"
|
||||
}
|
||||
|
||||
type Timeline struct {
|
||||
Name string
|
||||
Statuses []Status
|
||||
}
|
||||
|
||||
func (t Timeline) Display(noColor bool) string {
|
||||
var builder strings.Builder
|
||||
|
||||
separator := "────────────────────────────────────────────────────────────────────────────────"
|
||||
|
||||
builder.WriteString(utilities.HeaderFormat(noColor, t.Name) + "\n")
|
||||
|
||||
for _, status := range t.Statuses {
|
||||
builder.WriteString("\n" + utilities.DisplayNameFormat(noColor, status.Account.DisplayName) + " (@" + status.Account.Acct + ")\n")
|
||||
|
||||
statusID := status.ID
|
||||
createdAt := status.CreatedAt
|
||||
|
||||
if status.Reblog != nil {
|
||||
builder.WriteString("reposted this status from " + utilities.DisplayNameFormat(noColor, status.Reblog.Account.DisplayName) + " (@" + status.Reblog.Account.Acct + ")\n")
|
||||
statusID = status.Reblog.ID
|
||||
createdAt = status.Reblog.CreatedAt
|
||||
}
|
||||
|
||||
builder.WriteString(utilities.WrapLines(utilities.ConvertHTMLToText(status.Content), "\n", 80) + "\n\n")
|
||||
builder.WriteString(utilities.FieldFormat(noColor, "ID:") + " " + statusID + "\t" + utilities.FieldFormat(noColor, "Created at:") + " " + utilities.FormatTime(createdAt) + "\n")
|
||||
builder.WriteString(separator + "\n")
|
||||
}
|
||||
|
||||
return builder.String()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue