diff --git a/jellyseerr/jellyseerr.go b/jellyseerr/jellyseerr.go index 82659fc..9dcf5b8 100644 --- a/jellyseerr/jellyseerr.go +++ b/jellyseerr/jellyseerr.go @@ -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 +} diff --git a/jellyseerr/models.go b/jellyseerr/models.go index 4cc3c02..4ec8d4b 100644 --- a/jellyseerr/models.go +++ b/jellyseerr/models.go @@ -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"` +}