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 {
fmt.Printf("\nNotification ID: %s\n%s", notifications[i].ID, notifications[i].Type)
utilities.Display(notifications[i], *s.topLevelFlags.NoColor)
}
return nil

View file

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