From 0466e74a0a3da1ef6c8ee34a401e28635a51b0a8 Mon Sep 17 00:00:00 2001 From: Matthew Meszaros Date: Tue, 10 Nov 2026 19:18:19 +0100 Subject: [PATCH 1/4] feat: notify the mailbox owner about positive replies by default through a new inbound_positive_reply notification category, delivered as Reply received when that is on, and keep saved categories a client omits from the preferences PUT --- .../docs/api/reference/account-org.mdx | 6 +- docs/content/docs/guides/contacts-crm.mdx | 2 +- docs/content/docs/guides/notifications.mdx | 13 ++- docs/content/docs/guides/slack.mdx | 2 +- internal/api/handler/notification.go | 10 +- internal/app/advanced/incoming_reply_test.go | 5 + internal/app/advanced/service.go | 4 + internal/app/aitools/tools_slack.go | 2 +- internal/app/notification/email.go | 2 +- internal/app/notification/email_body_test.go | 2 +- internal/app/notification/message_test.go | 2 +- internal/app/notification/push.go | 4 +- internal/app/notification/service.go | 3 +- internal/app/slackapp/notifier.go | 2 +- internal/models/notification.go | 91 ++++++++++++------- internal/models/notification_test.go | 42 +++++++++ internal/repository/pg_notification.go | 8 +- .../Features/More/NotificationsView.swift | 12 ++- .../components/layout/NotificationBell.tsx | 1 + .../models/app/notifications/Notification.ts | 5 +- 20 files changed, 159 insertions(+), 59 deletions(-) create mode 100644 internal/models/notification_test.go diff --git a/docs/content/docs/api/reference/account-org.mdx b/docs/content/docs/api/reference/account-org.mdx index ab1883147..0bb35f97e 100644 --- a/docs/content/docs/api/reference/account-org.mdx +++ b/docs/content/docs/api/reference/account-org.mdx @@ -691,6 +691,7 @@ Auth: Session only (not available to API keys). { "preferences": { "inbound_reply": { "enabled": false, "channels": { "in_app": true, "email": false, "slack": false, "push": true } }, + "inbound_positive_reply": { "enabled": true, "channels": { "in_app": true, "email": false, "slack": false, "push": true } }, "inbound_out_of_office": { "enabled": false, "channels": { "in_app": true, "email": false, "slack": false, "push": true } }, "health_bounce": { "enabled": true, "channels": { "in_app": true, "email": false, "slack": false, "push": true } }, "health_complaint": { "enabled": true, "channels": { "in_app": true, "email": false, "slack": false, "push": true } }, @@ -712,7 +713,7 @@ Auth: Session only (not available to API keys). `PUT /auth/me/notification-preferences` -Replaces the caller's preferences. The full preferences object is sent under a `preferences` key and echoed back. +Saves the caller's preferences. The preferences object is sent under a `preferences` key and the saved result is echoed back. Auth: Session only (not available to API keys). @@ -720,12 +721,13 @@ Auth: Session only (not available to API keys). | Field | Type | Required | Description | |-------|------|----------|-------------| -| `preferences` | object | yes | The complete preferences object. Each category has `enabled` plus a `channels` object (`in_app`, `email`, `slack`, `push`), alongside `email_digest_minutes` (the email bundling window, `30` to `1440`). Categories absent from the request fall back to their defaults. | +| `preferences` | object | yes | The complete preferences object. Each category has `enabled` plus a `channels` object (`in_app`, `email`, `slack`, `push`), alongside `email_digest_minutes` (the email bundling window, `30` to `1440`). A category or field absent from the request keeps its saved value, so a client that does not know a newer category never changes it. | ```json { "preferences": { "inbound_reply": { "enabled": true, "channels": { "in_app": true, "email": false, "slack": false, "push": true } }, + "inbound_positive_reply": { "enabled": true, "channels": { "in_app": true, "email": false, "slack": false, "push": true } }, "inbound_out_of_office": { "enabled": false, "channels": { "in_app": true, "email": false, "slack": false, "push": true } }, "health_bounce": { "enabled": true, "channels": { "in_app": true, "email": false, "slack": false, "push": true } }, "health_complaint": { "enabled": true, "channels": { "in_app": true, "email": false, "slack": false, "push": true } }, diff --git a/docs/content/docs/guides/contacts-crm.mdx b/docs/content/docs/guides/contacts-crm.mdx index 9c526b336..71037b983 100644 --- a/docs/content/docs/guides/contacts-crm.mdx +++ b/docs/content/docs/guides/contacts-crm.mdx @@ -381,7 +381,7 @@ Before this rule, older mail could open tasks and record reply intents when its Automated replies are off deliberately. A vacation notice is not follow-up work, and a week of sending makes enough of them to bury the real replies. Tick **Automated** if you do want one per machine reply, or untick the human ones you do not need. Unticking everything is the same as turning the switch off. -The classification does more than decide the task: an automated reply never counts as a reply for **stop on reply** or for a **replied** branch in a sequence, and its notification goes to the **Out-of-office detected** preference rather than **New reply**, so muting one does not mute the other. +The classification does more than decide the task: an automated reply never counts as a reply for **stop on reply** or for a **replied** branch in a sequence, and its notification goes to the **Out-of-office detected** preference rather than **Positive reply** or **Reply received**, so muting one does not mute the other. diff --git a/docs/content/docs/guides/notifications.mdx b/docs/content/docs/guides/notifications.mdx index edaa9bb83..bf3e49447 100644 --- a/docs/content/docs/guides/notifications.mdx +++ b/docs/content/docs/guides/notifications.mdx @@ -32,7 +32,7 @@ Under Email delivery, pick how often unread notifications are emailed to you. ## Good to know - Feeds are per user, not shared across the workspace. -- Health alerts are on by default. **Reply received** is off by default, so a large campaign does not flood the feed. +- Health alerts and **Positive reply** are on by default. **Reply received**, which covers every reply, is off by default, so a large campaign does not flood the feed. - Nothing is emailed the moment it happens: unread notifications go out as one bundled email, every 30 minutes by default. - Anything you read in the dashboard before the email goes out is never emailed. - Every reply still lands in the [Unibox](/guides/unibox/), even with reply notifications off. @@ -71,10 +71,13 @@ The feed and the bell count update live, without refreshing. | New sign-in | Security | On | Your account is accessed from a new device, with browser, OS, and rough location | | Billing alerts | Billing | On, including email | A trial expired or sending was paused for billing | | Teammate joined | Team | On | Someone accepted an invitation | -| Reply received | Inbound | Off | A recipient replied to a cold email | +| Positive reply | Inbound | On | A recipient answered a cold email and the reply was classified as positive | +| Reply received | Inbound | Off | A recipient replied to a cold email, whatever they said | | Out-of-office detected | Inbound | Off | An auto-responder hit one of your sends | -Health defaults **on** because those alerts are operationally important and low volume. Inbound defaults **off** because a large campaign would generate one notification per recipient and flood the feed. Turn **Reply received** on only for smaller, higher-touch campaigns. +Health defaults **on** because those alerts are operationally important and low volume. **Positive reply** defaults **on** for the same reason: interested replies are few, and they are what a campaign is for. The other inbound categories default **off** because a large campaign would generate one notification per recipient and flood the feed. Turn **Reply received** on only for smaller, higher-touch campaigns. + +**Positive reply** and **Reply received** never announce the same message twice. With **Reply received** on, a positive reply is delivered as a **Reply received** notification, on that category's channels. With it off, positive replies use the **Positive reply** channels and every other reply stays quiet. A positive reply is one the [reply classification](/guides/contacts-crm/) read as interested. A reply it read as neutral, a question or negative raises only **Reply received**, and classification can be wrong, so the [Unibox](/guides/unibox/) remains the full record. Workspace events never fan out to everyone. Reply and bounce alerts go to the owner of the mailbox or campaign, worker downtime to members who can manage mailboxes, mailbox mail that needs action to members who can both manage mailboxes and use the inbox, a finished placement test to whoever started it, a placement monitor alert to members who can view campaigns, billing to those who can manage billing, and team changes to those who can manage the team. The person who joined is not notified about themselves. @@ -86,12 +89,12 @@ Workspace events never fan out to everyone. Reply and bounce alerts go to the ow ## Notifications about a message follow it -A **Reply received**, **Out-of-office detected** or **Mail that needs action** notification is about one message in the [Unibox](/guides/unibox/), and it stays in step with it: +A **Positive reply**, **Reply received**, **Out-of-office detected** or **Mail that needs action** notification is about one message in the [Unibox](/guides/unibox/), and it stays in step with it: - **Clicking it opens that conversation**, not the inbox in general. - **Reading the message reads the notification**, wherever you read it: in the Unibox, through the API, or in Gmail or Outlook, which Warmbly picks up on the next sync. A notification read this way is not emailed later either. - **Removing the message removes the notification.** Deleted mail, and mail later confirmed to be [warmup](/guides/warmup/), takes its notification out of the feed and the bell count. Warmup never raises one in the first place; this covers anything identified after it arrived. A push or Slack message already delivered cannot be recalled. -- **Routine automated mail is not a reply.** DMARC aggregate reports, delivery failures and other system notices do not raise **Reply received** or **Out-of-office detected** alerts. If a message is identified as routine automated mail later, its false reply alert disappears from the feed and bell count, and its pending email is cancelled. Genuine out-of-office and automatic replies still use **Out-of-office detected** when enabled. Automated mail that needs your action keeps its separate **Mail that needs action** alert, and bounce and domain-authentication health alerts are unchanged. +- **Routine automated mail is not a reply.** DMARC aggregate reports, delivery failures and other system notices do not raise **Positive reply**, **Reply received** or **Out-of-office detected** alerts. If a message is identified as routine automated mail later, its false reply alert disappears from the feed and bell count, and its pending email is cancelled. Genuine out-of-office and automatic replies still use **Out-of-office detected** when enabled. Automated mail that needs your action keeps its separate **Mail that needs action** alert, and bounce and domain-authentication health alerts are unchanged. Even with reply notifications off you never miss anything: every reply still lands in the [Unibox](/guides/unibox/). The notification is only an optional ping. diff --git a/docs/content/docs/guides/slack.mdx b/docs/content/docs/guides/slack.mdx index c794371f8..34656f938 100644 --- a/docs/content/docs/guides/slack.mdx +++ b/docs/content/docs/guides/slack.mdx @@ -217,7 +217,7 @@ Warmbly posts a notification to Slack when the category is enabled for Slack in The channel picker lists public channels and the private channels the bot has been invited to. To post to a private channel, invite the bot there first. -Each post carries an **Open in Warmbly** button. A **Reply received** notification also has **Draft a reply**, which starts the assistant in a thread on that post, for whoever pressed it, with the reply already in front of it. The draft is never sent without your approval. Pressing it needs a linked account. +Each post carries an **Open in Warmbly** button. A **Positive reply** or **Reply received** notification also has **Draft a reply**, which starts the assistant in a thread on that post, for whoever pressed it, with the reply already in front of it. The draft is never sent without your approval. Pressing it needs a linked account. **Personal DMs** are off until you turn them on, from **Integrations > Slack** in Warmbly (they need a linked account). You then get a DM for every category you have enabled for Slack in **Settings > Notifications**. diff --git a/internal/api/handler/notification.go b/internal/api/handler/notification.go index 0af7bafa6..4e583a772 100644 --- a/internal/api/handler/notification.go +++ b/internal/api/handler/notification.go @@ -49,13 +49,19 @@ func (h *Handler) GetNotificationPreferences(c *gin.Context) { c.JSON(http.StatusOK, gin.H{"preferences": prefs, "email_delivery": emailDeliveryInfo()}) } -// UpdateNotificationPreferences replaces the caller's notification preferences. +// UpdateNotificationPreferences saves the caller's notification preferences. func (h *Handler) UpdateNotificationPreferences(c *gin.Context) { uid, ok := notifActor(c) if !ok { return } - var req models.UpdateNotificationPreferencesRequest + current, xerr := h.NotificationService.GetPreferences(c.Request.Context(), uid) + if xerr != nil { + errx.JSON(c, xerr) + return + } + // Decoded over the stored value, so a client that predates a category leaves it alone. + req := models.UpdateNotificationPreferencesRequest{Preferences: *current} if err := c.ShouldBindJSON(&req); err != nil { errx.JSON(c, errx.InvalidBody(err)) return diff --git a/internal/app/advanced/incoming_reply_test.go b/internal/app/advanced/incoming_reply_test.go index 0a222cca7..87363ccb3 100644 --- a/internal/app/advanced/incoming_reply_test.go +++ b/internal/app/advanced/incoming_reply_test.go @@ -41,6 +41,7 @@ func TestProcessIncomingReplyHonorsMachineVerdicts(t *testing.T) { review string subject string sender string + snippet string flags []string want models.NotificationCategory }{ @@ -54,6 +55,7 @@ func TestProcessIncomingReplyHonorsMachineVerdicts(t *testing.T) { {name: "out of office without recognizable subject", kind: inboxtag.KindAutoReplyOOO, confidence: 0.95, want: models.NotifInboundOOO}, {name: "ticket acknowledgement without recognizable subject", kind: inboxtag.KindAutoReplyTicket, confidence: 0.95, want: models.NotifInboundOOO}, {name: "human reply", kind: inboxtag.KindHumanReply, confidence: 0.95, want: models.NotifInboundReply}, + {name: "interested human reply", kind: inboxtag.KindHumanReply, confidence: 0.95, snippet: "Yes, I am interested. Can we book a call next week?", want: models.NotifInboundPositiveReply}, {name: "uncertain kind", kind: inboxtag.KindNotification, confidence: 0.3, review: "kind", want: models.NotifInboundReply}, {name: "kind awaiting review", kind: inboxtag.KindNotification, confidence: 0.95, review: "kind", want: models.NotifInboundReply}, } { @@ -78,6 +80,9 @@ func TestProcessIncomingReplyHonorsMachineVerdicts(t *testing.T) { if tc.sender != "" { msg.FromAddr = []string{tc.sender} } + if tc.snippet != "" { + msg.Snippet = tc.snippet + } if err := s.ProcessIncomingReply(context.Background(), accountID, msg); err != nil { t.Fatal(err) } diff --git a/internal/app/advanced/service.go b/internal/app/advanced/service.go index 49a8f18eb..a172170c2 100644 --- a/internal/app/advanced/service.go +++ b/internal/app/advanced/service.go @@ -1880,6 +1880,10 @@ func (s *service) ProcessIncomingReply(ctx context.Context, emailAccountID uuid. cat := models.NotifInboundReply title := "New reply from " + sender body := msg.Subject + if intent == models.ReplyIntentPositive { + cat = models.NotifInboundPositiveReply + title = "Positive reply from " + sender + } if models.IsAutomatedIntent(intent) { // The "out-of-office detected" preference is what someone mutes to // stop hearing about auto-responders, so every machine reply goes diff --git a/internal/app/aitools/tools_slack.go b/internal/app/aitools/tools_slack.go index c1b5e9fb0..4dd3a44df 100644 --- a/internal/app/aitools/tools_slack.go +++ b/internal/app/aitools/tools_slack.go @@ -62,7 +62,7 @@ func RegisterSlackTools(r *Registry, slack SlackControl, audit audit.AuditServic func slackCategoryNames() []string { return []string{ - string(models.NotifInboundReply), string(models.NotifInboundOOO), string(models.NotifInboxActionRequired), + string(models.NotifInboundReply), string(models.NotifInboundPositiveReply), string(models.NotifInboundOOO), string(models.NotifInboxActionRequired), string(models.NotifCampaignPaused), string(models.NotifHealthBounce), string(models.NotifHealthComplaint), string(models.NotifDomainAuth), string(models.NotifPlacementFinished), string(models.NotifPlacementAlert), string(models.NotifWorkerDowntime), string(models.NotifSecuritySignIn), string(models.NotifBillingAlert), string(models.NotifTeamActivity), diff --git a/internal/app/notification/email.go b/internal/app/notification/email.go index 25ba0a900..1d3306375 100644 --- a/internal/app/notification/email.go +++ b/internal/app/notification/email.go @@ -291,7 +291,7 @@ func (s *service) keepEligibleEmailMessages(ctx context.Context, rows []models.N // of mail Warmbly sends; the in-app feed still shows it. func emailBody(n models.Notification) string { switch n.Category { - case models.NotifInboundReply, models.NotifInboundOOO: + case models.NotifInboundReply, models.NotifInboundPositiveReply, models.NotifInboundOOO: return "Open the conversation in your inbox to read it." } return n.Body diff --git a/internal/app/notification/email_body_test.go b/internal/app/notification/email_body_test.go index 68cac5248..31fe7c763 100644 --- a/internal/app/notification/email_body_test.go +++ b/internal/app/notification/email_body_test.go @@ -9,7 +9,7 @@ import ( func TestEmailBodyLeavesAnInboundSubjectOut(t *testing.T) { subject := "Claim your prize at evil.example" - for _, cat := range []models.NotificationCategory{models.NotifInboundReply, models.NotifInboundOOO} { + for _, cat := range []models.NotificationCategory{models.NotifInboundReply, models.NotifInboundPositiveReply, models.NotifInboundOOO} { if got := emailBody(models.Notification{Category: cat, Body: subject}); strings.Contains(got, subject) { t.Errorf("%s: email body carries the sender's subject", cat) } diff --git a/internal/app/notification/message_test.go b/internal/app/notification/message_test.go index 499e94345..e1495a695 100644 --- a/internal/app/notification/message_test.go +++ b/internal/app/notification/message_test.go @@ -110,7 +110,7 @@ func TestPendingPushRechecksTheMessageButKeepsActionAlerts(t *testing.T) { id := uuid.New() r := &messageNotificationRepo{} s := &service{repo: r} - for _, category := range []models.NotificationCategory{models.NotifInboundReply, models.NotifInboundOOO} { + for _, category := range []models.NotificationCategory{models.NotifInboundReply, models.NotifInboundPositiveReply, models.NotifInboundOOO} { if s.canPushMessage(context.Background(), category, pendingPush{MessageID: &id}) { t.Errorf("%s accepted an automated message", category) } diff --git a/internal/app/notification/push.go b/internal/app/notification/push.go index 4b88ac289..0190cb195 100644 --- a/internal/app/notification/push.go +++ b/internal/app/notification/push.go @@ -253,7 +253,7 @@ func (s *service) canPushMessage(ctx context.Context, category models.Notificati } func (s *service) pushMessageEligibility(ctx context.Context, category models.NotificationCategory, p pendingPush) (bool, error) { - if (category == models.NotifInboundReply || category == models.NotifInboundOOO) && + if category.IsInboundReply() && replyclassify.IsSystemReport(replyclassify.Input{Subject: p.Body}) { return false, nil } @@ -277,6 +277,8 @@ func digestTitle(category models.NotificationCategory, n int) string { switch category { case models.NotifInboundReply: return fmt.Sprintf("%d new replies", n) + case models.NotifInboundPositiveReply: + return fmt.Sprintf("%d positive replies", n) case models.NotifInboundOOO: return fmt.Sprintf("%d out-of-office replies", n) case models.NotifHealthBounce: diff --git a/internal/app/notification/service.go b/internal/app/notification/service.go index 8bc39887d..bd52edc70 100644 --- a/internal/app/notification/service.go +++ b/internal/app/notification/service.go @@ -259,6 +259,7 @@ func (s *service) notifyOneWithError(ctx context.Context, userID uuid.UUID, orgI if err != nil || prefs == nil { return false, err } + category = prefs.DeliveryCategory(category) cat := prefs.CategoryPref(category) if !cat.Enabled { return false, nil @@ -363,7 +364,7 @@ func (s *service) canNotifyMessage(ctx context.Context, category models.Notifica } func (s *service) messageEligibility(ctx context.Context, category models.NotificationCategory, messageID *uuid.UUID) (bool, error) { - if messageID == nil || (category != models.NotifInboundReply && category != models.NotifInboundOOO) { + if messageID == nil || !category.IsInboundReply() { return true, nil } return s.repo.CanNotifyAboutMessage(ctx, *messageID, category) diff --git a/internal/app/slackapp/notifier.go b/internal/app/slackapp/notifier.go index 4580e1fa7..b35a09041 100644 --- a/internal/app/slackapp/notifier.go +++ b/internal/app/slackapp/notifier.go @@ -97,7 +97,7 @@ func noticeMessage(n notification.SlackNotice) Message { text += "\n" + escapeMrkdwn(body) } var draft Block - if n.Category == models.NotifInboundReply { + if n.Category.IsHumanReply() { v := draftReplyValue{EmailID: metaString(n.Meta, "unibox_email_id"), ThreadID: metaString(n.Meta, "thread_id")} if v.EmailID != "" || v.ThreadID != "" { raw, _ := json.Marshal(v) diff --git a/internal/models/notification.go b/internal/models/notification.go index 670f041d2..45691a7a2 100644 --- a/internal/models/notification.go +++ b/internal/models/notification.go @@ -12,14 +12,17 @@ import ( type NotificationCategory string const ( - NotifInboundReply NotificationCategory = "inbound_reply" - NotifInboundOOO NotificationCategory = "inbound_out_of_office" - NotifHealthBounce NotificationCategory = "health_bounce" - NotifHealthComplaint NotificationCategory = "health_complaint" - NotifWorkerDowntime NotificationCategory = "health_worker_downtime" - NotifSecuritySignIn NotificationCategory = "security_new_signin" - NotifBillingAlert NotificationCategory = "billing_alert" - NotifTeamActivity NotificationCategory = "team_activity" + NotifInboundReply NotificationCategory = "inbound_reply" + // NotifInboundPositiveReply is a human reply classified as positive. It is + // the one inbound category on by default. + NotifInboundPositiveReply NotificationCategory = "inbound_positive_reply" + NotifInboundOOO NotificationCategory = "inbound_out_of_office" + NotifHealthBounce NotificationCategory = "health_bounce" + NotifHealthComplaint NotificationCategory = "health_complaint" + NotifWorkerDowntime NotificationCategory = "health_worker_downtime" + NotifSecuritySignIn NotificationCategory = "security_new_signin" + NotifBillingAlert NotificationCategory = "billing_alert" + NotifTeamActivity NotificationCategory = "team_activity" // NotifCampaignPaused fires when the platform pauses a campaign on its // own — today, when an auto-pause guardrail band is breached. Rare and // always actionable, so it defaults on with email. @@ -58,16 +61,18 @@ type CategoryPref struct { // NotificationPreferences is the per-user singleton (jsonb on users). Always // returned fully populated via DefaultNotificationPreferences merge. type NotificationPreferences struct { - InboundReply CategoryPref `json:"inbound_reply"` - InboundOOO CategoryPref `json:"inbound_out_of_office"` - HealthBounce CategoryPref `json:"health_bounce"` - HealthComplaint CategoryPref `json:"health_complaint"` - WorkerDowntime CategoryPref `json:"health_worker_downtime"` - SecuritySignIn CategoryPref `json:"security_new_signin"` - BillingAlert CategoryPref `json:"billing_alert"` - TeamActivity CategoryPref `json:"team_activity"` - CampaignPaused CategoryPref `json:"campaign_paused"` - DomainAuth CategoryPref `json:"health_domain_auth"` + InboundReply CategoryPref `json:"inbound_reply"` + // InboundPositiveReply covers positive replies while InboundReply is off. + InboundPositiveReply CategoryPref `json:"inbound_positive_reply"` + InboundOOO CategoryPref `json:"inbound_out_of_office"` + HealthBounce CategoryPref `json:"health_bounce"` + HealthComplaint CategoryPref `json:"health_complaint"` + WorkerDowntime CategoryPref `json:"health_worker_downtime"` + SecuritySignIn CategoryPref `json:"security_new_signin"` + BillingAlert CategoryPref `json:"billing_alert"` + TeamActivity CategoryPref `json:"team_activity"` + CampaignPaused CategoryPref `json:"campaign_paused"` + DomainAuth CategoryPref `json:"health_domain_auth"` // PlacementFinished and PlacementAlert are the inbox placement test pair. PlacementFinished CategoryPref `json:"placement_finished"` PlacementAlert CategoryPref `json:"placement_alert"` @@ -83,7 +88,8 @@ type NotificationPreferences struct { // DefaultNotificationPreferences is the merge base. Health categories default ON // (operationally important + low volume); inbound categories default OFF (a big -// campaign would otherwise flood the feed with a notification per recipient). +// campaign would otherwise flood the feed with a notification per recipient), +// except positive replies, which are few and are what the campaign is for. // Push defaults on: it only fires for devices the user explicitly registered by // granting the OS notification permission, and enabled categories should reach // those devices without a second opt-in. @@ -100,18 +106,19 @@ func DefaultNotificationPreferences() NotificationPreferences { // whoever can edit the DNS, so this one emails by default too. domainAuth := CategoryPref{Enabled: true, Channels: ChannelPrefs{InApp: true, Push: true, Email: true}} return NotificationPreferences{ - InboundReply: off, - InboundOOO: off, - HealthBounce: on, - HealthComplaint: on, - WorkerDowntime: on, - SecuritySignIn: on, - BillingAlert: billing, - TeamActivity: on, - CampaignPaused: campaignPaused, - DomainAuth: domainAuth, - PlacementFinished: on, - PlacementAlert: domainAuth, + InboundReply: off, + InboundPositiveReply: on, + InboundOOO: off, + HealthBounce: on, + HealthComplaint: on, + WorkerDowntime: on, + SecuritySignIn: on, + BillingAlert: billing, + TeamActivity: on, + CampaignPaused: campaignPaused, + DomainAuth: domainAuth, + PlacementFinished: on, + PlacementAlert: domainAuth, // A mailbox about to lose its subscription has to reach whoever can // fix it even when nobody reads the inbox, so this emails too. InboxActionRequired: domainAuth, @@ -124,6 +131,8 @@ func (p NotificationPreferences) CategoryPref(c NotificationCategory) CategoryPr switch c { case NotifInboundReply: return p.InboundReply + case NotifInboundPositiveReply: + return p.InboundPositiveReply case NotifInboundOOO: return p.InboundOOO case NotifHealthBounce: @@ -153,6 +162,26 @@ func (p NotificationPreferences) CategoryPref(c NotificationCategory) CategoryPr } } +// DeliveryCategory is the category a notification is raised under for this +// user: with every reply on, a positive one is delivered as a plain reply, so +// it keeps that category's channels and is never announced twice. +func (p NotificationPreferences) DeliveryCategory(c NotificationCategory) NotificationCategory { + if c == NotifInboundPositiveReply && p.InboundReply.Enabled { + return NotifInboundReply + } + return c +} + +// IsHumanReply reports a category raised by a person answering a send. +func (c NotificationCategory) IsHumanReply() bool { + return c == NotifInboundReply || c == NotifInboundPositiveReply +} + +// IsInboundReply reports a category raised by a reply, automatic ones included. +func (c NotificationCategory) IsInboundReply() bool { + return c.IsHumanReply() || c == NotifInboundOOO +} + // Notification is one row in the in-app feed. type Notification struct { ID uuid.UUID `json:"id"` diff --git a/internal/models/notification_test.go b/internal/models/notification_test.go new file mode 100644 index 000000000..f7c32794a --- /dev/null +++ b/internal/models/notification_test.go @@ -0,0 +1,42 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestPositiveRepliesNotifyByDefault(t *testing.T) { + p := DefaultNotificationPreferences() + if !p.CategoryPref(NotifInboundPositiveReply).Enabled { + t.Fatal("positive replies must notify by default") + } + if p.CategoryPref(NotifInboundReply).Enabled || p.CategoryPref(NotifInboundOOO).Enabled { + t.Fatal("other inbound categories must stay off by default") + } +} + +// Preferences saved before the category existed carry no key for it. +func TestStoredPreferencesWithoutPositiveReplyKeepTheDefault(t *testing.T) { + p := DefaultNotificationPreferences() + stored := `{"inbound_reply":{"enabled":false,"channels":{"in_app":true}},"email_digest_minutes":60}` + if err := json.Unmarshal([]byte(stored), &p); err != nil { + t.Fatal(err) + } + if !p.InboundPositiveReply.Enabled || !p.InboundPositiveReply.Channels.InApp { + t.Fatalf("got %+v", p.InboundPositiveReply) + } +} + +func TestDeliveryCategory(t *testing.T) { + p := DefaultNotificationPreferences() + if got := p.DeliveryCategory(NotifInboundPositiveReply); got != NotifInboundPositiveReply { + t.Fatalf("every reply off: got %s", got) + } + p.InboundReply.Enabled = true + if got := p.DeliveryCategory(NotifInboundPositiveReply); got != NotifInboundReply { + t.Fatalf("every reply on: got %s", got) + } + if got := p.DeliveryCategory(NotifInboundOOO); got != NotifInboundOOO { + t.Fatalf("other categories are untouched: got %s", got) + } +} diff --git a/internal/repository/pg_notification.go b/internal/repository/pg_notification.go index 33da0bcf1..940519c8b 100644 --- a/internal/repository/pg_notification.go +++ b/internal/repository/pg_notification.go @@ -152,13 +152,13 @@ var ErrNotificationMessageAutomated = errors.New("notification: message is not a // Legacy thread alerts are hidden only when every verdict in that mailbox's thread is automated. const notificationReplyVisibleSQL = `( - n.category NOT IN ('inbound_reply', 'inbound_out_of_office') OR ( + n.category NOT IN ('inbound_reply', 'inbound_positive_reply', 'inbound_out_of_office') OR ( NOT EXISTS ( SELECT 1 FROM unibox_emails ue LEFT JOIN inbox_tag_results r ON r.email_account_id = ue.email_id AND r.message_id = ue.message_id AND r.status = 'complete' WHERE ue.id = n.unibox_email_id AND ( - (n.category = 'inbound_reply' AND ue.automated) + (n.category IN ('inbound_reply', 'inbound_positive_reply') AND ue.automated) OR (r.kind IN ('notification', 'bounce_hard', 'bounce_soft') AND r.kind_confidence >= 0.70 AND r.review_reason <> 'kind') ) @@ -170,14 +170,14 @@ const notificationReplyVisibleSQL = `( AND r.thread_id <> '' AND r.thread_id = n.metadata->>'thread_id' AND r.status = 'complete' AND r.kind_confidence >= 0.70 AND r.review_reason <> 'kind' AND (r.kind IN ('notification', 'bounce_hard', 'bounce_soft') - OR (n.category = 'inbound_reply' AND r.automated)) + OR (n.category IN ('inbound_reply', 'inbound_positive_reply') AND r.automated)) AND NOT EXISTS ( SELECT 1 FROM inbox_tag_results other WHERE other.organization_id = r.organization_id AND other.email_account_id = r.email_account_id AND other.thread_id = r.thread_id AND NOT ( other.status = 'complete' AND other.kind_confidence >= 0.70 AND other.review_reason <> 'kind' AND (other.kind IN ('notification', 'bounce_hard', 'bounce_soft') - OR (n.category = 'inbound_reply' AND other.automated)) + OR (n.category IN ('inbound_reply', 'inbound_positive_reply') AND other.automated)) ) ) ) diff --git a/ios/Warmbly/Features/More/NotificationsView.swift b/ios/Warmbly/Features/More/NotificationsView.swift index 1fad1434e..b4604fcc8 100644 --- a/ios/Warmbly/Features/More/NotificationsView.swift +++ b/ios/Warmbly/Features/More/NotificationsView.swift @@ -119,7 +119,7 @@ final class MoreNotificationsStore { private enum MoreNotificationMeta { static func icon(_ category: String?) -> String { switch category { - case "inbound_reply": return "arrowshape.turn.up.left.fill" + case "inbound_reply", "inbound_positive_reply": return "arrowshape.turn.up.left.fill" case "inbound_out_of_office": return "moon.zzz.fill" case "health_bounce": return "arrow.uturn.left.circle.fill" case "health_complaint": return "flag.fill" @@ -133,7 +133,7 @@ private enum MoreNotificationMeta { static func tone(_ category: String?) -> Tone { switch category { - case "inbound_reply": return .emerald + case "inbound_reply", "inbound_positive_reply": return .emerald case "inbound_out_of_office": return .slate case "health_bounce": return .rose case "health_complaint": return .rose @@ -147,7 +147,8 @@ private enum MoreNotificationMeta { static func label(_ key: String) -> String { switch key { - case "inbound_reply": return "Replies" + case "inbound_positive_reply": return "Positive replies" + case "inbound_reply": return "All replies" case "inbound_out_of_office": return "Out of office" case "health_bounce": return "Bounces" case "health_complaint": return "Spam complaints" @@ -163,7 +164,8 @@ private enum MoreNotificationMeta { static func caption(_ key: String) -> String? { switch key { - case "inbound_reply": return "A contact replies to your outreach" + case "inbound_positive_reply": return "A contact answers your outreach with interest" + case "inbound_reply": return "A contact replies to your outreach, whatever they say" case "inbound_out_of_office": return "Auto-replies detected on your sends" case "health_bounce": return "A campaign email hard bounces" case "health_complaint": return "A recipient marks your mail as spam" @@ -176,7 +178,7 @@ private enum MoreNotificationMeta { } static let knownGroups: [(title: String, keys: [String])] = [ - ("Inbound", ["inbound_reply", "inbound_out_of_office"]), + ("Inbound", ["inbound_positive_reply", "inbound_reply", "inbound_out_of_office"]), ("Mailbox health", ["health_bounce", "health_complaint", "health_worker_downtime"]), ("Security", ["security_new_signin"]), ("Account", ["billing_alert", "team_activity"]), diff --git a/web/src/components/layout/NotificationBell.tsx b/web/src/components/layout/NotificationBell.tsx index 6727b011b..75335d474 100644 --- a/web/src/components/layout/NotificationBell.tsx +++ b/web/src/components/layout/NotificationBell.tsx @@ -34,6 +34,7 @@ import type { AppNotification } from "@/lib/api/models/app/notifications/Notific // Per-category icon + tone so the list scans by kind before reading titles. const CATEGORY_META: Record = { inbound_reply: { icon: ReplyIcon, tone: "bg-sky-50 text-sky-600" }, + inbound_positive_reply: { icon: ReplyIcon, tone: "bg-emerald-50 text-emerald-600" }, inbound_out_of_office: { icon: ClockIcon, tone: "bg-slate-100 text-slate-500" }, health_bounce: { icon: TriangleAlertIcon, tone: "bg-amber-50 text-amber-600" }, health_complaint: { icon: ShieldAlertIcon, tone: "bg-rose-50 text-rose-600" }, diff --git a/web/src/lib/api/models/app/notifications/Notification.ts b/web/src/lib/api/models/app/notifications/Notification.ts index bd003e373..985e458c1 100644 --- a/web/src/lib/api/models/app/notifications/Notification.ts +++ b/web/src/lib/api/models/app/notifications/Notification.ts @@ -22,6 +22,7 @@ export const EMAIL_WINDOW_MAX_MINUTES = 1440; export interface NotificationPreferences { inbound_reply: CategoryPref; + inbound_positive_reply: CategoryPref; inbound_out_of_office: CategoryPref; health_bounce: CategoryPref; health_complaint: CategoryPref; @@ -52,7 +53,8 @@ export const NOTIFICATION_CATEGORY_GROUPS: { id: string; label: string; categori id: "inbound", label: "Inbound activity", categories: [ - { key: "inbound_reply", label: "Reply received", hint: "A recipient replied to a cold email." }, + { key: "inbound_positive_reply", label: "Positive reply", hint: "A recipient answered a cold email with interest. On by default." }, + { key: "inbound_reply", label: "Reply received", hint: "Any recipient replied to a cold email, whatever they said. When on, it covers positive replies too." }, { key: "inbound_out_of_office", label: "Out-of-office detected", hint: "An auto-responder hit one of your sends." }, ], }, @@ -122,6 +124,7 @@ export function normalizeNotificationPreferences( const minutes = p?.email_digest_minutes ?? EMAIL_WINDOW_MIN_MINUTES; return { inbound_reply: p?.inbound_reply ?? off, + inbound_positive_reply: p?.inbound_positive_reply ?? on, inbound_out_of_office: p?.inbound_out_of_office ?? off, health_bounce: p?.health_bounce ?? on, health_complaint: p?.health_complaint ?? on, From 23394a29c602ddb690a0a333973d3b2af1d0c695 Mon Sep 17 00:00:00 2001 From: Matthew Meszaros Date: Tue, 10 Nov 2026 19:33:24 +0100 Subject: [PATCH 2/4] feat: keep saved notification preference keys that a save omits with a users trigger in migration 000387, so a release that predates a category cannot reset a member's choice for it, and state reply preference precedence in the notifications guide and the iOS caption --- docs/content/docs/guides/notifications.mdx | 2 +- ...ification_preferences_keep_unsent_keys.down.sql | 2 ++ ...otification_preferences_keep_unsent_keys.up.sql | 14 ++++++++++++++ internal/repository/pg_notification.go | 1 + ios/Warmbly/Features/More/NotificationsView.swift | 2 +- 5 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 internal/infrastructure/db/migrations/000387_notification_preferences_keep_unsent_keys.down.sql create mode 100644 internal/infrastructure/db/migrations/000387_notification_preferences_keep_unsent_keys.up.sql diff --git a/docs/content/docs/guides/notifications.mdx b/docs/content/docs/guides/notifications.mdx index bf3e49447..9b16b4799 100644 --- a/docs/content/docs/guides/notifications.mdx +++ b/docs/content/docs/guides/notifications.mdx @@ -77,7 +77,7 @@ The feed and the bell count update live, without refreshing. Health defaults **on** because those alerts are operationally important and low volume. **Positive reply** defaults **on** for the same reason: interested replies are few, and they are what a campaign is for. The other inbound categories default **off** because a large campaign would generate one notification per recipient and flood the feed. Turn **Reply received** on only for smaller, higher-touch campaigns. -**Positive reply** and **Reply received** never announce the same message twice. With **Reply received** on, a positive reply is delivered as a **Reply received** notification, on that category's channels. With it off, positive replies use the **Positive reply** channels and every other reply stays quiet. A positive reply is one the [reply classification](/guides/contacts-crm/) read as interested. A reply it read as neutral, a question or negative raises only **Reply received**, and classification can be wrong, so the [Unibox](/guides/unibox/) remains the full record. +**Positive reply** and **Reply received** never announce the same message twice. With **Reply received** on, a positive reply is delivered as a **Reply received** notification, on that category's channels. With it off, positive replies use the **Positive reply** channels and every other reply from a person stays quiet. Automatic replies follow their own **Out-of-office detected** preference either way. All three need reply intent on in the workspace's outreach settings, which is the default. A positive reply is one the [reply classification](/guides/contacts-crm/) read as interested. A reply it read as neutral, a question or negative raises only **Reply received**, and classification can be wrong, so the [Unibox](/guides/unibox/) remains the full record. Workspace events never fan out to everyone. Reply and bounce alerts go to the owner of the mailbox or campaign, worker downtime to members who can manage mailboxes, mailbox mail that needs action to members who can both manage mailboxes and use the inbox, a finished placement test to whoever started it, a placement monitor alert to members who can view campaigns, billing to those who can manage billing, and team changes to those who can manage the team. The person who joined is not notified about themselves. diff --git a/internal/infrastructure/db/migrations/000387_notification_preferences_keep_unsent_keys.down.sql b/internal/infrastructure/db/migrations/000387_notification_preferences_keep_unsent_keys.down.sql new file mode 100644 index 000000000..1fac7e7c3 --- /dev/null +++ b/internal/infrastructure/db/migrations/000387_notification_preferences_keep_unsent_keys.down.sql @@ -0,0 +1,2 @@ +DROP TRIGGER IF EXISTS users_keep_notification_preferences ON users; +DROP FUNCTION IF EXISTS users_keep_notification_preferences(); diff --git a/internal/infrastructure/db/migrations/000387_notification_preferences_keep_unsent_keys.up.sql b/internal/infrastructure/db/migrations/000387_notification_preferences_keep_unsent_keys.up.sql new file mode 100644 index 000000000..19a60c3aa --- /dev/null +++ b/internal/infrastructure/db/migrations/000387_notification_preferences_keep_unsent_keys.up.sql @@ -0,0 +1,14 @@ +-- A save from a release that does not know a category keeps that category's saved value. +CREATE OR REPLACE FUNCTION users_keep_notification_preferences() RETURNS trigger AS $$ +BEGIN + NEW.notification_preferences := OLD.notification_preferences || NEW.notification_preferences; + RETURN NEW; +END; +$$ LANGUAGE plpgsql; + +DROP TRIGGER IF EXISTS users_keep_notification_preferences ON users; +CREATE TRIGGER users_keep_notification_preferences + BEFORE UPDATE OF notification_preferences ON users + FOR EACH ROW + WHEN (jsonb_typeof(OLD.notification_preferences) = 'object' AND jsonb_typeof(NEW.notification_preferences) = 'object') + EXECUTE FUNCTION users_keep_notification_preferences(); diff --git a/internal/repository/pg_notification.go b/internal/repository/pg_notification.go index 940519c8b..f350004e4 100644 --- a/internal/repository/pg_notification.go +++ b/internal/repository/pg_notification.go @@ -85,6 +85,7 @@ func (r *notificationRepository) GetPreferences(ctx context.Context, userID uuid return &prefs, nil } +// UpdatePreferences saves the blob; a trigger (000387) keeps saved keys it omits. func (r *notificationRepository) UpdatePreferences(ctx context.Context, userID uuid.UUID, prefs *models.NotificationPreferences) error { raw, err := json.Marshal(prefs) if err != nil { diff --git a/ios/Warmbly/Features/More/NotificationsView.swift b/ios/Warmbly/Features/More/NotificationsView.swift index b4604fcc8..4ca6f9454 100644 --- a/ios/Warmbly/Features/More/NotificationsView.swift +++ b/ios/Warmbly/Features/More/NotificationsView.swift @@ -165,7 +165,7 @@ private enum MoreNotificationMeta { static func caption(_ key: String) -> String? { switch key { case "inbound_positive_reply": return "A contact answers your outreach with interest" - case "inbound_reply": return "A contact replies to your outreach, whatever they say" + case "inbound_reply": return "Every reply to your outreach. When on, it covers positive replies too" case "inbound_out_of_office": return "Auto-replies detected on your sends" case "health_bounce": return "A campaign email hard bounces" case "health_complaint": return "A recipient marks your mail as spam" From 797c3ae438e20c409f01ef021aa03c967079b393 Mon Sep 17 00:00:00 2001 From: Matthew Meszaros Date: Tue, 10 Nov 2026 19:47:31 +0100 Subject: [PATCH 3/4] feat: state in the API reference, the notifications guide, the dashboard hint and the iOS caption that Reply received covers replies a person writes, takes precedence over Positive reply while on, and that the preferences PUT returns the merged saved object --- docs/content/docs/api/reference/account-org.mdx | 6 +++--- docs/content/docs/guides/notifications.mdx | 4 ++-- ios/Warmbly/Features/More/NotificationsView.swift | 2 +- web/src/lib/api/models/app/notifications/Notification.ts | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/content/docs/api/reference/account-org.mdx b/docs/content/docs/api/reference/account-org.mdx index 0bb35f97e..080ba677c 100644 --- a/docs/content/docs/api/reference/account-org.mdx +++ b/docs/content/docs/api/reference/account-org.mdx @@ -713,7 +713,7 @@ Auth: Session only (not available to API keys). `PUT /auth/me/notification-preferences` -Saves the caller's preferences. The preferences object is sent under a `preferences` key and the saved result is echoed back. +Saves the caller's preferences. The preferences object is sent under a `preferences` key and the saved result is returned. Auth: Session only (not available to API keys). @@ -721,7 +721,7 @@ Auth: Session only (not available to API keys). | Field | Type | Required | Description | |-------|------|----------|-------------| -| `preferences` | object | yes | The complete preferences object. Each category has `enabled` plus a `channels` object (`in_app`, `email`, `slack`, `push`), alongside `email_digest_minutes` (the email bundling window, `30` to `1440`). A category or field absent from the request keeps its saved value, so a client that does not know a newer category never changes it. | +| `preferences` | object | yes | The preferences object. Each category has `enabled` plus a `channels` object (`in_app`, `email`, `slack`, `push`), alongside `email_digest_minutes` (the email bundling window, `30` to `1440`). A category or field absent from the request keeps its saved value, so a client that does not know a newer category never changes it. While `inbound_reply.enabled` is true, a positive reply is delivered under `inbound_reply` with its channels, whatever `inbound_positive_reply` is set to; `inbound_positive_reply` applies only while `inbound_reply` is off. | ```json { @@ -747,7 +747,7 @@ Auth: Session only (not available to API keys). #### Response -The same `{ "preferences": { ... } }` object that was sent. +The saved `{ "preferences": { ... } }` object: what was sent, merged over the values already saved for anything the request left out. ### List notifications diff --git a/docs/content/docs/guides/notifications.mdx b/docs/content/docs/guides/notifications.mdx index 9b16b4799..331043095 100644 --- a/docs/content/docs/guides/notifications.mdx +++ b/docs/content/docs/guides/notifications.mdx @@ -32,7 +32,7 @@ Under Email delivery, pick how often unread notifications are emailed to you. ## Good to know - Feeds are per user, not shared across the workspace. -- Health alerts and **Positive reply** are on by default. **Reply received**, which covers every reply, is off by default, so a large campaign does not flood the feed. +- Health alerts and **Positive reply** are on by default. **Reply received**, which covers every reply a person writes, is off by default, so a large campaign does not flood the feed. - Nothing is emailed the moment it happens: unread notifications go out as one bundled email, every 30 minutes by default. - Anything you read in the dashboard before the email goes out is never emailed. - Every reply still lands in the [Unibox](/guides/unibox/), even with reply notifications off. @@ -72,7 +72,7 @@ The feed and the bell count update live, without refreshing. | Billing alerts | Billing | On, including email | A trial expired or sending was paused for billing | | Teammate joined | Team | On | Someone accepted an invitation | | Positive reply | Inbound | On | A recipient answered a cold email and the reply was classified as positive | -| Reply received | Inbound | Off | A recipient replied to a cold email, whatever they said | +| Reply received | Inbound | Off | A person replied to a cold email, whatever they said. Automatic replies are not included | | Out-of-office detected | Inbound | Off | An auto-responder hit one of your sends | Health defaults **on** because those alerts are operationally important and low volume. **Positive reply** defaults **on** for the same reason: interested replies are few, and they are what a campaign is for. The other inbound categories default **off** because a large campaign would generate one notification per recipient and flood the feed. Turn **Reply received** on only for smaller, higher-touch campaigns. diff --git a/ios/Warmbly/Features/More/NotificationsView.swift b/ios/Warmbly/Features/More/NotificationsView.swift index 4ca6f9454..513cdfe75 100644 --- a/ios/Warmbly/Features/More/NotificationsView.swift +++ b/ios/Warmbly/Features/More/NotificationsView.swift @@ -165,7 +165,7 @@ private enum MoreNotificationMeta { static func caption(_ key: String) -> String? { switch key { case "inbound_positive_reply": return "A contact answers your outreach with interest" - case "inbound_reply": return "Every reply to your outreach. When on, it covers positive replies too" + case "inbound_reply": return "Every reply a person writes to your outreach, positive ones included. Auto-replies have their own setting" case "inbound_out_of_office": return "Auto-replies detected on your sends" case "health_bounce": return "A campaign email hard bounces" case "health_complaint": return "A recipient marks your mail as spam" diff --git a/web/src/lib/api/models/app/notifications/Notification.ts b/web/src/lib/api/models/app/notifications/Notification.ts index 985e458c1..f343858b5 100644 --- a/web/src/lib/api/models/app/notifications/Notification.ts +++ b/web/src/lib/api/models/app/notifications/Notification.ts @@ -54,7 +54,7 @@ export const NOTIFICATION_CATEGORY_GROUPS: { id: string; label: string; categori label: "Inbound activity", categories: [ { key: "inbound_positive_reply", label: "Positive reply", hint: "A recipient answered a cold email with interest. On by default." }, - { key: "inbound_reply", label: "Reply received", hint: "Any recipient replied to a cold email, whatever they said. When on, it covers positive replies too." }, + { key: "inbound_reply", label: "Reply received", hint: "A person replied to a cold email, whatever they said. When on, it covers positive replies too. Automatic replies have their own setting below." }, { key: "inbound_out_of_office", label: "Out-of-office detected", hint: "An auto-responder hit one of your sends." }, ], }, From ce43d939c244618f798e5bdba1ab3cb66aefe76a Mon Sep 17 00:00:00 2001 From: Matthew Meszaros Date: Tue, 10 Nov 2026 19:52:53 +0100 Subject: [PATCH 4/4] feat: cover the notification preferences trigger with a live repository test that saves an opt-out, saves a blob without that category the way an earlier release does, and reads the opt-out back, run in the live-1 CI suite --- .github/workflows/ci.yml | 9 +++++ .../notification_preferences_live_test.go | 39 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 internal/repository/notification_preferences_live_test.go diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6b756466b..c237cb345 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -372,6 +372,15 @@ jobs: WARMBLY_TEST_DB: postgres://warmbly:warmbly@127.0.0.1:5432/warmbly_test?sslmode=disable run: go test -race ./internal/repository -run '^TestLiveInvitedSignup$' -count=1 + - name: Notification preference save regressions (PostgreSQL) + if: matrix.suite == 'live-1' + env: + WARMBLY_TEST_DB: postgres://warmbly:warmbly@127.0.0.1:5432/warmbly_test?sslmode=disable + run: | + set -o pipefail + go test -race -v ./internal/repository -run '^TestLiveNotificationPreferencesKeepKeysASaveOmits$' -count=1 | tee notification-preferences.log + grep -q '^--- PASS: TestLiveNotificationPreferencesKeepKeysASaveOmits ' notification-preferences.log + - name: Tester initial password and sample data regressions (PostgreSQL) if: matrix.suite == 'live-1' env: diff --git a/internal/repository/notification_preferences_live_test.go b/internal/repository/notification_preferences_live_test.go new file mode 100644 index 000000000..83ec2f6e3 --- /dev/null +++ b/internal/repository/notification_preferences_live_test.go @@ -0,0 +1,39 @@ +package repository + +import ( + "context" + "testing" + + "github.com/warmbly/warmbly/internal/models" +) + +// A save from a release that predates a category arrives without its key. +func TestLiveNotificationPreferencesKeepKeysASaveOmits(t *testing.T) { + handle := liveUniboxFolderDB(t) + f := newUniboxFolderFixture(t, handle.Pool) + ctx := context.Background() + notifs := NewNotificationRepository(handle.Pool) + + prefs := models.DefaultNotificationPreferences() + prefs.InboundPositiveReply.Enabled = false + if err := notifs.UpdatePreferences(ctx, f.user, &prefs); err != nil { + t.Fatal(err) + } + older := `{"inbound_reply":{"enabled":true,"channels":{"in_app":true}},"email_digest_minutes":60}` + if _, err := handle.Pool.Exec(ctx, `UPDATE users SET notification_preferences = $2::jsonb WHERE id = $1`, f.user, older); err != nil { + t.Fatal(err) + } + got, err := notifs.GetPreferences(ctx, f.user) + if err != nil { + t.Fatal(err) + } + if got.InboundPositiveReply.Enabled { + t.Fatal("an omitted category lost its saved value") + } + if !got.InboundReply.Enabled || got.EmailDigestMinutes != 60 { + t.Fatalf("the keys the save carried were not applied: %+v", got) + } + if !got.HealthBounce.Enabled { + t.Fatal("an omitted category lost its saved value") + } +}