Compare commits
No commits in common. "c2957c179da0cc69b46ae951bb04e607c4c3c324" and "0f7668a0462e751a934a464f2dff1d7799e93574" have entirely different histories.
c2957c179d
...
0f7668a046
5 changed files with 11 additions and 168 deletions
|
@ -1,33 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Dan Anglin <d.n.i.anglin@gmail.com>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
|
|
||||||
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 your notifications: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return notifications, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *Client) GetNotification() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *Client) DeleteAllNotifications() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
|
@ -45,5 +45,4 @@ const (
|
||||||
resourceStatus = "status"
|
resourceStatus = "status"
|
||||||
resourceTimeline = "timeline"
|
resourceTimeline = "timeline"
|
||||||
resourceBookmarks = "bookmarks"
|
resourceBookmarks = "bookmarks"
|
||||||
resourceNotification = "notification"
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -67,7 +67,6 @@ func (s *ShowExecutor) Execute() error {
|
||||||
resourceFollowing: s.showFollowing,
|
resourceFollowing: s.showFollowing,
|
||||||
resourceBlocked: s.showBlocked,
|
resourceBlocked: s.showBlocked,
|
||||||
resourceBookmarks: s.showBookmarks,
|
resourceBookmarks: s.showBookmarks,
|
||||||
resourceNotification: s.showNotifications,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
doFunc, ok := funcMap[s.resourceType]
|
doFunc, ok := funcMap[s.resourceType]
|
||||||
|
@ -330,16 +329,3 @@ func (s *ShowExecutor) showBookmarks(gtsClient *client.Client) error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ShowExecutor) showNotifications(gts *client.Client) error {
|
|
||||||
notifications, err := gts.GetNotifications(s.limit)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("unable to retrieve your notifications: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := range notifications {
|
|
||||||
utilities.Display(notifications[i], *s.topLevelFlags.NoColor)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,109 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Dan Anglin <d.n.i.anglin@gmail.com>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
|
|
||||||
package model
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/utilities"
|
|
||||||
)
|
|
||||||
|
|
||||||
type NotificationType int
|
|
||||||
|
|
||||||
const (
|
|
||||||
NotificationTypeFollow NotificationType = iota
|
|
||||||
NotificationTypeFollowRequest
|
|
||||||
NotificationTypeMention
|
|
||||||
NotificationTypeReblog
|
|
||||||
NotificationTypeFavourite
|
|
||||||
NotificationTypePoll
|
|
||||||
NotificationTypeStatus
|
|
||||||
NotificationTypeUnknown
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
notificationFollow = "follow"
|
|
||||||
notificationFollowRequest = "follow_request"
|
|
||||||
notificationMention = "mention"
|
|
||||||
notificationReblog = "reblog"
|
|
||||||
notificationFavourite = "favourite"
|
|
||||||
notificationPoll = "poll"
|
|
||||||
notificationStatus = "status"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (n NotificationType) MessageFormat() string {
|
|
||||||
mapped := map[NotificationType]string{
|
|
||||||
NotificationTypeFollow: "%s followed you",
|
|
||||||
NotificationTypeFollowRequest: "%s has requested to follow you",
|
|
||||||
NotificationTypeMention: "%s has mentioned you in this status",
|
|
||||||
NotificationTypeReblog: "%s reposted this status from you",
|
|
||||||
NotificationTypeFavourite: "%s liked this status from you",
|
|
||||||
NotificationTypePoll: "A poll from %s that you have voted in has ended",
|
|
||||||
NotificationTypeStatus: "%s has posted this status",
|
|
||||||
}
|
|
||||||
|
|
||||||
output, ok := mapped[n]
|
|
||||||
if !ok {
|
|
||||||
return "You have received a notification of an unknown type"
|
|
||||||
}
|
|
||||||
|
|
||||||
return output
|
|
||||||
}
|
|
||||||
|
|
||||||
func ParseNotificationType(value string) (NotificationType, error) {
|
|
||||||
mapped := map[string]NotificationType{
|
|
||||||
notificationFollow: NotificationTypeFollow,
|
|
||||||
notificationFollowRequest: NotificationTypeFollowRequest,
|
|
||||||
notificationMention: NotificationTypeMention,
|
|
||||||
notificationReblog: NotificationTypeReblog,
|
|
||||||
notificationFavourite: NotificationTypeFavourite,
|
|
||||||
notificationPoll: NotificationTypePoll,
|
|
||||||
notificationStatus: NotificationTypeStatus,
|
|
||||||
}
|
|
||||||
|
|
||||||
output, ok := mapped[value]
|
|
||||||
if !ok {
|
|
||||||
return NotificationTypeUnknown, UnknownNotificationError{}
|
|
||||||
}
|
|
||||||
|
|
||||||
return output, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ignore the error if the notification type from another Fediverse service
|
|
||||||
// is not known by enbas. It will be seen as an unknown notification to the user.
|
|
||||||
*n, _ = ParseNotificationType(value)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type UnknownNotificationError struct{}
|
|
||||||
|
|
||||||
func (e UnknownNotificationError) Error() string {
|
|
||||||
return "unknown notification type"
|
|
||||||
}
|
|
||||||
|
|
||||||
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"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n Notification) Display(noColor bool) string {
|
|
||||||
return fmt.Sprintf(n.Type.MessageFormat(), utilities.DisplayNameFormat(noColor, n.Account.DisplayName) + " (@" + n.Account.Acct + ")")
|
|
||||||
}
|
|
|
@ -83,7 +83,7 @@ type Poll struct {
|
||||||
|
|
||||||
type PollOption struct {
|
type PollOption struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
VotesCount int `json:"votes_count"`
|
VotesCount string `json:"votes_count"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type StatusReblogged struct {
|
type StatusReblogged struct {
|
||||||
|
|
Loading…
Reference in a new issue