begin formatting notification messages

This commit is contained in:
Dan Anglin 2024-06-03 11:16:19 +01:00
parent 2919bb9fa2
commit c2957c179d
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638
2 changed files with 16 additions and 10 deletions

View file

@ -338,7 +338,7 @@ func (s *ShowExecutor) showNotifications(gts *client.Client) error {
} }
for i := range notifications { for i := range notifications {
fmt.Printf("\nNotification ID: %s\n%s", notifications[i].ID, notifications[i].Type) utilities.Display(notifications[i], *s.topLevelFlags.NoColor)
} }
return nil return nil

View file

@ -8,6 +8,8 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"time" "time"
"codeflow.dananglin.me.uk/apollo/enbas/internal/utilities"
) )
type NotificationType int type NotificationType int
@ -33,20 +35,20 @@ const (
notificationStatus = "status" notificationStatus = "status"
) )
func (n NotificationType) String() string { func (n NotificationType) MessageFormat() string {
mapped := map[NotificationType]string{ mapped := map[NotificationType]string{
NotificationTypeFollow: "Someone followed you", NotificationTypeFollow: "%s followed you",
NotificationTypeFollowRequest: "Someone requested to follow you", NotificationTypeFollowRequest: "%s has requested to follow you",
NotificationTypeMention: "Someone mentioned you in their status", NotificationTypeMention: "%s has mentioned you in this status",
NotificationTypeReblog: "Someone reposted one of your statuses", NotificationTypeReblog: "%s reposted this status from you",
NotificationTypeFavourite: "Someone liked one of your statuses", NotificationTypeFavourite: "%s liked this status from you",
NotificationTypePoll: "A poll you have participated in has ended", NotificationTypePoll: "A poll from %s that you have voted in has ended",
NotificationTypeStatus: "Someone you enabled notifications for has posted a status", NotificationTypeStatus: "%s has posted this status",
} }
output, ok := mapped[n] output, ok := mapped[n]
if !ok { if !ok {
return "You have received an unknown notification" return "You have received a notification of an unknown type"
} }
return output return output
@ -101,3 +103,7 @@ type Notification struct {
Status *Status `json:"status"` Status *Status `json:"status"`
Type NotificationType `json:"type"` 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 + ")")
}