Compare commits

..

No commits in common. "ae1bf73b90510461da271ea94b7e92a04cb06494" and "b91ebe58640b11e51427d626e92648493d0ae641" have entirely different histories.

4 changed files with 17 additions and 153 deletions

View file

@ -15,13 +15,12 @@ const (
listTitleFlag = "list-title"
listRepliesPolicyFlag = "list-replies-policy"
myAccountFlag = "my-account"
notificationIDFlag = "notification-id"
removeFromFlag = "remove-from"
resourceTypeFlag = "type"
statusIDFlag = "status-id"
tagFlag = "tag"
timelineCategoryFlag = "timeline-category"
limitFlag = "limit"
timelineLimitFlag = "timeline-limit"
toAccountFlag = "to-account"
)
@ -29,7 +28,6 @@ const (
accountResource = "account"
instanceResource = "instance"
listResource = "list"
notificationResource = "notification"
statusResource = "status"
timelineResource = "timeline"
)

View file

@ -19,8 +19,7 @@ type showCommand struct {
timelineCategory string
listID string
tag string
limit int
notificationID string
timelineLimit int
}
func newShowCommand(name, summary string) *showCommand {
@ -35,8 +34,7 @@ func newShowCommand(name, summary string) *showCommand {
command.StringVar(&command.timelineCategory, timelineCategoryFlag, "home", "specify the type of timeline to display (valid values are home, public, list and tag)")
command.StringVar(&command.listID, listIDFlag, "", "specify the ID of the list to display")
command.StringVar(&command.tag, tagFlag, "", "specify the name of the tag to use")
command.IntVar(&command.limit, limitFlag, 20, "specify the limit")
command.StringVar(&command.notificationID, notificationIDFlag, "", "specify the ID of the notification to display")
command.IntVar(&command.timelineLimit, timelineLimitFlag, 5, "specify the number of statuses to display")
command.Usage = commandUsageFunc(name, summary, command.FlagSet)
@ -54,7 +52,6 @@ func (c *showCommand) Execute() error {
statusResource: c.showStatus,
timelineResource: c.showTimeline,
listResource: c.showList,
notificationResource: c.showNotification,
}
doFunc, ok := funcMap[c.resourceType]
@ -132,21 +129,21 @@ func (c *showCommand) showTimeline(gts *client.Client) error {
switch c.timelineCategory {
case "home":
timeline, err = gts.GetHomeTimeline(c.limit)
timeline, err = gts.GetHomeTimeline(c.timelineLimit)
case "public":
timeline, err = gts.GetPublicTimeline(c.limit)
timeline, err = gts.GetPublicTimeline(c.timelineLimit)
case "list":
if c.listID == "" {
return flagNotSetError{flagText: listIDFlag}
}
timeline, err = gts.GetListTimeline(c.listID, c.limit)
timeline, err = gts.GetListTimeline(c.listID, c.timelineLimit)
case "tag":
if c.tag == "" {
return flagNotSetError{flagText: tagFlag}
}
timeline, err = gts.GetTagTimeline(c.tag, c.limit)
timeline, err = gts.GetTagTimeline(c.tag, c.timelineLimit)
default:
return invalidTimelineCategoryError{category: c.timelineCategory}
}
@ -186,7 +183,6 @@ func (c *showCommand) showList(gts *client.Client) error {
for i := range accounts {
accountMap[accounts[i].ID] = accounts[i].Username
}
list.Accounts = accountMap
}
@ -212,16 +208,3 @@ func (c *showCommand) showLists(gts *client.Client) error {
return nil
}
func (c *showCommand) showNotification(gts *client.Client) error {
notifications, err := gts.GetNotifications(c.limit)
if err != nil {
return fmt.Errorf("unable to retrieve the notifications; %w", err)
}
for i := range notifications {
fmt.Printf("\nNotification ID: %s\n%s", notifications[i].ID, notifications[i].Type)
}
return nil
}

View file

@ -1,29 +0,0 @@
package client
import (
"fmt"
"net/http"
"codeflow.dananglin.me.uk/apollo/enbas/internal/model"
)
func (g *Client) GetNotifications(limit int) ([]model.Notification, error) {
path := fmt.Sprintf("/api/v1/notifications?limit=%d", limit)
url := g.Authentication.Instance + path
var notifications []model.Notification
if err := g.sendRequest(http.MethodGet, url, nil, &notifications); err != nil {
return nil, fmt.Errorf("received an error after sending the request to get the notifications; %w", err)
}
return notifications, nil
}
func (g *Client) GetNotification() error {
return nil
}
func (g *Client) DeleteAllNotifications() error {
return nil
}

View file

@ -1,88 +0,0 @@
package model
import (
"encoding/json"
"errors"
"fmt"
"time"
)
type NotificationType int
const (
NotificationTypeFollow NotificationType = iota
NotificationTypeFollowRequest
NotificationTypeMention
NotificationTypeReblog
NotificationTypeFavourite
NotificationTypePoll
NotificationTypeStatus
)
func ParseNotificationType(notificationType string) (NotificationType, error) {
switch notificationType {
case "follow":
return NotificationTypeFollow, nil
case "follow_request":
return NotificationTypeFollowRequest, nil
case "mention":
return NotificationTypeMention, nil
case "reblog":
return NotificationTypeReblog, nil
case "favourite":
return NotificationTypeFavourite, nil
case "poll":
return NotificationTypePoll, nil
case "status":
return NotificationTypeStatus, nil
}
return NotificationType(-1), errors.New("invalid notification type")
}
func (n NotificationType) String() string {
switch n {
case NotificationTypeFollow:
return "Someone followed you"
case NotificationTypeFollowRequest:
return "Someone requested to follow you"
case NotificationTypeMention:
return "Someone mentioned you in their status"
case NotificationTypeReblog:
return "Someone reposted one of your statuses"
case NotificationTypeFavourite:
return "Someone liked one of your statuses"
case NotificationTypePoll:
return "A poll you have participated in has ended"
case NotificationTypeStatus:
return "Someone you enabled notifications for has posted a status"
}
return ""
}
func (n *NotificationType) UnmarshalJSON(data []byte) error {
var (
value string
err error
)
if err = json.Unmarshal(data, &value); err != nil {
return fmt.Errorf("unable to unmarshal the data; %w", err)
}
*n, err = ParseNotificationType(value)
if err != nil {
return fmt.Errorf("unable to parse %q as a notification type; %w", value, err)
}
return nil
}
type Notification struct {
Account *Account `json:"account"`
CreatedAt time.Time `json:"created_at"`
ID string `json:"id"`
Status *Status `json:"status"`
Type NotificationType `json:"type"`
}