1
0
mirror of https://github.com/hrfee/jfa-go.git synced 2024-09-19 19:00:11 +00:00

jellyseerr: add notifications related methods

similar in style to User, with Notifications/NotificationsTemplate, and
named fields for modifying discord and telegram IDs, and two modify
methods.
This commit is contained in:
Harvey Tindall 2024-07-29 17:56:28 +01:00
parent 73e985c45c
commit 7b9cdf385a
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2
2 changed files with 92 additions and 0 deletions

View File

@ -325,3 +325,53 @@ func (js *Jellyseerr) DeleteUser(jfID string) error {
delete(js.userCache, jfID)
return err
}
func (js *Jellyseerr) GetNotificationPreferences(jfID string) (Notifications, error) {
var data Notifications
u, err := js.MustGetUser(jfID)
if err != nil {
return data, err
}
resp, status, err := js.getJSON(fmt.Sprintf(js.server+"/user/%d/settings/notifications", u.ID), nil, url.Values{})
if err != nil {
return data, err
}
if status != 200 {
return data, fmt.Errorf("failed (error %d)", status)
}
err = json.Unmarshal([]byte(resp), &data)
return data, err
}
func (js *Jellyseerr) ApplyNotificationsTemplateToUser(jfID string, tmpl NotificationsTemplate) error {
u, err := js.MustGetUser(jfID)
if err != nil {
return err
}
_, status, err := js.post(fmt.Sprintf(js.server+"/user/%d/settings/notifications", u.ID), tmpl, false)
if err != nil {
return err
}
if status != 200 && status != 201 {
return fmt.Errorf("failed (error %d)", status)
}
return nil
}
func (js *Jellyseerr) ModifyNotifications(jfID string, conf map[NotificationsField]string) error {
u, err := js.MustGetUser(jfID)
if err != nil {
return err
}
_, status, err := js.post(fmt.Sprintf(js.server+"/user/%d/settings/notifications", u.ID), conf, false)
if err != nil {
return err
}
if status != 200 && status != 201 {
return fmt.Errorf("failed (error %d)", status)
}
return nil
}

View File

@ -56,3 +56,45 @@ type permissionsDTO struct {
}
type Permissions int
type NotificationTypes struct {
Discord int `json:"discord"`
Email int `json:"email"`
Pushbullet int `json:"pushbullet"`
Pushover int `json:"pushover"`
Slack int `json:"slack"`
Telegram int `json:"telegram"`
Webhook int `json:"webhook"`
Webpush int `json:"webpush"`
}
type NotificationsField string
const (
FieldDiscord NotificationsField = "discordId"
FieldTelegram NotificationsField = "telegramChatId"
FieldEmailEnabled NotificationsField = "emailEnabled"
FieldDiscordEnabled NotificationsField = "discordEnabled"
FieldTelegramEnabled NotificationsField = "telegramEnabled"
)
type Notifications struct {
NotificationsTemplate
PgpKey any `json:"pgpKey"`
DiscordID string `json:"discordId"`
PushbulletAccessToken any `json:"pushbulletAccessToken"`
PushoverApplicationToken any `json:"pushoverApplicationToken"`
PushoverUserKey any `json:"pushoverUserKey"`
TelegramChatID string `json:"telegramChatId"`
}
type NotificationsTemplate struct {
EmailEnabled bool `json:"emailEnabled"`
DiscordEnabled bool `json:"discordEnabled"`
DiscordEnabledTypes int `json:"discordEnabledTypes"`
PushoverSound any `json:"pushoverSound"`
TelegramEnabled bool `json:"telegramEnabled"`
TelegramSendSilently any `json:"telegramSendSilently"`
WebPushEnabled bool `json:"webPushEnabled"`
NotifTypes NotificationTypes `json:"notificationTypes"`
}