checkpoint: notifications implementation
This commit is contained in:
parent
70a09941d7
commit
ae1bf73b90
4 changed files with 66 additions and 18 deletions
|
@ -15,21 +15,23 @@ const (
|
||||||
listTitleFlag = "list-title"
|
listTitleFlag = "list-title"
|
||||||
listRepliesPolicyFlag = "list-replies-policy"
|
listRepliesPolicyFlag = "list-replies-policy"
|
||||||
myAccountFlag = "my-account"
|
myAccountFlag = "my-account"
|
||||||
|
notificationIDFlag = "notification-id"
|
||||||
removeFromFlag = "remove-from"
|
removeFromFlag = "remove-from"
|
||||||
resourceTypeFlag = "type"
|
resourceTypeFlag = "type"
|
||||||
statusIDFlag = "status-id"
|
statusIDFlag = "status-id"
|
||||||
tagFlag = "tag"
|
tagFlag = "tag"
|
||||||
timelineCategoryFlag = "timeline-category"
|
timelineCategoryFlag = "timeline-category"
|
||||||
timelineLimitFlag = "timeline-limit"
|
limitFlag = "limit"
|
||||||
toAccountFlag = "to-account"
|
toAccountFlag = "to-account"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
accountResource = "account"
|
accountResource = "account"
|
||||||
instanceResource = "instance"
|
instanceResource = "instance"
|
||||||
listResource = "list"
|
listResource = "list"
|
||||||
statusResource = "status"
|
notificationResource = "notification"
|
||||||
timelineResource = "timeline"
|
statusResource = "status"
|
||||||
|
timelineResource = "timeline"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Executor interface {
|
type Executor interface {
|
||||||
|
|
|
@ -19,7 +19,8 @@ type showCommand struct {
|
||||||
timelineCategory string
|
timelineCategory string
|
||||||
listID string
|
listID string
|
||||||
tag string
|
tag string
|
||||||
timelineLimit int
|
limit int
|
||||||
|
notificationID string
|
||||||
}
|
}
|
||||||
|
|
||||||
func newShowCommand(name, summary string) *showCommand {
|
func newShowCommand(name, summary string) *showCommand {
|
||||||
|
@ -34,7 +35,8 @@ 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.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.listID, listIDFlag, "", "specify the ID of the list to display")
|
||||||
command.StringVar(&command.tag, tagFlag, "", "specify the name of the tag to use")
|
command.StringVar(&command.tag, tagFlag, "", "specify the name of the tag to use")
|
||||||
command.IntVar(&command.timelineLimit, timelineLimitFlag, 5, "specify the number of statuses to display")
|
command.IntVar(&command.limit, limitFlag, 20, "specify the limit")
|
||||||
|
command.StringVar(&command.notificationID, notificationIDFlag, "", "specify the ID of the notification to display")
|
||||||
|
|
||||||
command.Usage = commandUsageFunc(name, summary, command.FlagSet)
|
command.Usage = commandUsageFunc(name, summary, command.FlagSet)
|
||||||
|
|
||||||
|
@ -47,11 +49,12 @@ func (c *showCommand) Execute() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
funcMap := map[string]func(*client.Client) error{
|
funcMap := map[string]func(*client.Client) error{
|
||||||
instanceResource: c.showInstance,
|
instanceResource: c.showInstance,
|
||||||
accountResource: c.showAccount,
|
accountResource: c.showAccount,
|
||||||
statusResource: c.showStatus,
|
statusResource: c.showStatus,
|
||||||
timelineResource: c.showTimeline,
|
timelineResource: c.showTimeline,
|
||||||
listResource: c.showList,
|
listResource: c.showList,
|
||||||
|
notificationResource: c.showNotification,
|
||||||
}
|
}
|
||||||
|
|
||||||
doFunc, ok := funcMap[c.resourceType]
|
doFunc, ok := funcMap[c.resourceType]
|
||||||
|
@ -129,21 +132,21 @@ func (c *showCommand) showTimeline(gts *client.Client) error {
|
||||||
|
|
||||||
switch c.timelineCategory {
|
switch c.timelineCategory {
|
||||||
case "home":
|
case "home":
|
||||||
timeline, err = gts.GetHomeTimeline(c.timelineLimit)
|
timeline, err = gts.GetHomeTimeline(c.limit)
|
||||||
case "public":
|
case "public":
|
||||||
timeline, err = gts.GetPublicTimeline(c.timelineLimit)
|
timeline, err = gts.GetPublicTimeline(c.limit)
|
||||||
case "list":
|
case "list":
|
||||||
if c.listID == "" {
|
if c.listID == "" {
|
||||||
return flagNotSetError{flagText: listIDFlag}
|
return flagNotSetError{flagText: listIDFlag}
|
||||||
}
|
}
|
||||||
|
|
||||||
timeline, err = gts.GetListTimeline(c.listID, c.timelineLimit)
|
timeline, err = gts.GetListTimeline(c.listID, c.limit)
|
||||||
case "tag":
|
case "tag":
|
||||||
if c.tag == "" {
|
if c.tag == "" {
|
||||||
return flagNotSetError{flagText: tagFlag}
|
return flagNotSetError{flagText: tagFlag}
|
||||||
}
|
}
|
||||||
|
|
||||||
timeline, err = gts.GetTagTimeline(c.tag, c.timelineLimit)
|
timeline, err = gts.GetTagTimeline(c.tag, c.limit)
|
||||||
default:
|
default:
|
||||||
return invalidTimelineCategoryError{category: c.timelineCategory}
|
return invalidTimelineCategoryError{category: c.timelineCategory}
|
||||||
}
|
}
|
||||||
|
@ -183,6 +186,7 @@ func (c *showCommand) showList(gts *client.Client) error {
|
||||||
for i := range accounts {
|
for i := range accounts {
|
||||||
accountMap[accounts[i].ID] = accounts[i].Username
|
accountMap[accounts[i].ID] = accounts[i].Username
|
||||||
}
|
}
|
||||||
|
|
||||||
list.Accounts = accountMap
|
list.Accounts = accountMap
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,3 +212,16 @@ func (c *showCommand) showLists(gts *client.Client) error {
|
||||||
|
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
|
29
internal/client/notifications.go
Normal file
29
internal/client/notifications.go
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
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, ¬ifications); 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
|
||||||
|
}
|
|
@ -53,7 +53,7 @@ func (n NotificationType) String() string {
|
||||||
case NotificationTypeFavourite:
|
case NotificationTypeFavourite:
|
||||||
return "Someone liked one of your statuses"
|
return "Someone liked one of your statuses"
|
||||||
case NotificationTypePoll:
|
case NotificationTypePoll:
|
||||||
return "A poll you have voted in (or created) has ended"
|
return "A poll you have participated in has ended"
|
||||||
case NotificationTypeStatus:
|
case NotificationTypeStatus:
|
||||||
return "Someone you enabled notifications for has posted a status"
|
return "Someone you enabled notifications for has posted a status"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue