Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

✨ Add per-poll notification muting (#RAL-1065) (#2268)

Luke Vella9a1c55f038dc
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.json
index 2edd3c801..eac18b41f 100644
--- a/apps/web/public/locales/en/app.json
+++ b/apps/web/public/locales/en/app.json
@@ -615,5 +615,7 @@
"notifyNewComment": "New comment",
"notificationsDescription": "Choose which email notifications you receive",
"timezoneInputPlaceholder": "Search timezone…",
- "cityTime": "{city} Time"
+ "cityTime": "{city} Time",
+ "unmuteNotifications": "Unmute notifications",
+ "muteNotifications": "Mute notifications"
}
diff --git a/apps/web/src/components/layouts/poll-layout.tsx b/apps/web/src/components/layouts/poll-layout.tsx
index af83f890b..d1fa48a73 100644
--- a/apps/web/src/components/layouts/poll-layout.tsx
+++ b/apps/web/src/components/layouts/poll-layout.tsx
@@ -8,6 +8,7 @@ import type React from "react";
import { InviteDialog } from "@/components/invite-dialog";
import ManagePoll from "@/components/poll/manage-poll";
+import { NotificationToggle } from "@/components/poll/notification-toggle";
import { LegacyPollContextProvider } from "@/components/poll/poll-context-provider";
import { usePoll } from "@/contexts/poll";
import { Trans } from "@/i18n/client";
@@ -15,6 +16,7 @@ import { Trans } from "@/i18n/client";
const AdminControls = () => {
return (
<div className="flex items-center gap-x-2">
+ <NotificationToggle />
<ManagePoll />
<InviteDialog />
</div>
diff --git a/apps/web/src/components/poll/notification-toggle.tsx b/apps/web/src/components/poll/notification-toggle.tsx
new file mode 100644
index 000000000..ebec3a34c
--- /dev/null
+++ b/apps/web/src/components/poll/notification-toggle.tsx
@@ -0,0 +1,79 @@
+"use client";
+
+import { Button } from "@rallly/ui/button";
+import {
+ Tooltip,
+ TooltipContent,
+ TooltipPortal,
+ TooltipTrigger,
+} from "@rallly/ui/tooltip";
+import { BellIcon, BellOffIcon } from "lucide-react";
+
+import { useUser } from "@/components/user-provider";
+import { usePoll } from "@/contexts/poll";
+import { Trans, useTranslation } from "@/i18n/client";
+import { trpc } from "@/trpc/client";
+
+export function NotificationToggle() {
+ const poll = usePoll();
+ const { user, ownsObject } = useUser();
+ const { t } = useTranslation();
+ const queryClient = trpc.useUtils();
+ const toggleMuted = trpc.polls.toggleMuted.useMutation({
+ onSuccess: (_data, vars) => {
+ queryClient.polls.get.setData({ urlId: vars.pollId }, (oldData) => {
+ if (!oldData) return oldData;
+ return {
+ ...oldData,
+ muted: vars.muted,
+ };
+ });
+ },
+ });
+
+ if (user?.isGuest || !ownsObject(poll)) {
+ return null;
+ }
+
+ return (
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <Button
+ variant="ghost"
+ aria-pressed={poll.muted}
+ aria-label={
+ poll.muted
+ ? t("unmuteNotifications", {
+ defaultValue: "Unmute notifications",
+ })
+ : t("muteNotifications", { defaultValue: "Mute notifications" })
+ }
+ onClick={() => {
+ toggleMuted.mutate({ pollId: poll.id, muted: !poll.muted });
+ }}
+ >
+ {poll.muted ? <BellOffIcon /> : <BellIcon />}
+ <span className="sr-only">
+ {poll.muted
+ ? t("unmuteNotifications", {
+ defaultValue: "Unmute notifications",
+ })
+ : t("muteNotifications", { defaultValue: "Mute notifications" })}
+ </span>
+ </Button>
+ </TooltipTrigger>
+ <TooltipPortal>
+ <TooltipContent>
+ {poll.muted ? (
+ <Trans
+ i18nKey="unmuteNotifications"
+ defaults="Unmute notifications"
+ />
+ ) : (
+ <Trans i18nKey="muteNotifications" defaults="Mute notifications" />
+ )}
+ </TooltipContent>
+ </TooltipPortal>
+ </Tooltip>
+ );
+}
diff --git a/apps/web/src/features/notifications/queries.ts b/apps/web/src/features/notifications/queries.ts
index 54917c422..4ce61e085 100644
--- a/apps/web/src/features/notifications/queries.ts
+++ b/apps/web/src/features/notifications/queries.ts
@@ -45,10 +45,10 @@ export async function getNotificationRecipient({
}): Promise<NotificationRecipient | null> {
const poll = await prisma.poll.findUnique({
where: { id: pollId },
- select: { userId: true },
+ select: { userId: true, muted: true },
});
- if (!poll?.userId || poll.userId === excludeUserId) {
+ if (!poll?.userId || poll.userId === excludeUserId || poll.muted) {
return null;
}
diff --git a/apps/web/src/features/poll/mutations.ts b/apps/web/src/features/poll/mutations.ts
index 8c123adb5..701ba8f0c 100644
--- a/apps/web/src/features/poll/mutations.ts
+++ b/apps/web/src/features/poll/mutations.ts
@@ -48,7 +48,6 @@ export const createPoll = async ({
adminUrlId: nanoid(),
participantUrlId: nanoid(),
userId,
- watchers: { create: { userId } },
spaceId,
options: { createMany: { data: options } },
},
diff --git a/apps/web/src/trpc/routers/polls.ts b/apps/web/src/trpc/routers/polls.ts
index c17e585a2..9f6326989 100644
--- a/apps/web/src/trpc/routers/polls.ts
+++ b/apps/web/src/trpc/routers/polls.ts
@@ -192,13 +192,6 @@ export const polls = router({
adminUrlId: adminToken,
participantUrlId,
userId: ctx.user.id,
- watchers: !ctx.user.isGuest
- ? {
- create: {
- userId: ctx.user.id,
- },
- }
- : undefined,
options: {
createMany: {
data: input.options.map((option) => ({
@@ -529,85 +522,25 @@ export const polls = router({
});
}),
// END LEGACY ROUTES
- // @deprecated — replaced by global notification preferences in /settings/notifications
- getWatchers: publicProcedure
- .input(
- z.object({
- pollId: z.string(),
- }),
- )
- .query(async ({ input: { pollId } }) => {
- return await prisma.watcher.findMany({
- where: {
- pollId,
- },
- select: {
- userId: true,
- },
- });
- }),
- // @deprecated — replaced by global notification preferences in /settings/notifications
- watch: privateProcedure
- .input(z.object({ pollId: z.string() }))
+ toggleMuted: privateProcedure
+ .input(z.object({ pollId: z.string(), muted: z.boolean() }))
.mutation(async ({ input, ctx }) => {
- const hasAccess = await hasPollAdminAccess(input.pollId, ctx.user.id);
+ const poll = await prisma.poll.findUnique({
+ where: { id: input.pollId },
+ select: { userId: true },
+ });
- if (!hasAccess) {
+ if (!poll || poll.userId !== ctx.user.id) {
throw new TRPCError({
code: "FORBIDDEN",
- message: "You are not allowed to watch this poll",
+ message: "Only the poll owner can mute notifications",
});
}
- await prisma.watcher.create({
- data: {
- pollId: input.pollId,
- userId: ctx.user.id,
- },
- });
-
- // Track poll watch analytics
- ctx.posthog?.capture({
- event: "poll_watch",
- distinctId: ctx.user.id,
- properties: {
- is_guest: ctx.user.isGuest,
- },
- groups: {
- poll: input.pollId,
- },
- });
- }),
- // @deprecated — replaced by global notification preferences in /settings/notifications
- unwatch: privateProcedure
- .input(z.object({ pollId: z.string() }))
- .mutation(async ({ input, ctx }) => {
- const watcher = await prisma.watcher.findFirst({
- where: {
- pollId: input.pollId,
- userId: ctx.user.id,
- },
- select: {
- id: true,
- },
+ await prisma.poll.update({
+ where: { id: input.pollId },
+ data: { muted: input.muted },
});
-
- if (watcher) {
- await prisma.watcher.delete({
- where: {
- id: watcher.id,
- },
- });
-
- // Track poll unwatch analytics
- ctx.posthog?.capture({
- event: "poll_unwatch",
- distinctId: ctx.user.id,
- groups: {
- poll: input.pollId,
- },
- });
- }
}),
get: publicProcedure
.input(
@@ -653,11 +586,7 @@ export const polls = router({
userId: true,
deleted: true,
spaceId: true,
- watchers: {
- select: {
- userId: true,
- },
- },
+ muted: true,
scheduledEvent: {
select: {
id: true,
@@ -1181,11 +1110,6 @@ export const polls = router({
disableComments: poll.disableComments,
adminUrlId: nanoid(),
participantUrlId: nanoid(),
- watchers: {
- create: {
- userId: ctx.user.id,
- },
- },
options: {
create: poll.options,
},
diff --git a/packages/database/prisma/migrations/20260309174403_add_poll_muted_drop_watchers/migration.sql b/packages/database/prisma/migrations/20260309174403_add_poll_muted_drop_watchers/migration.sql
new file mode 100644
index 000000000..6cd23fdac
--- /dev/null
+++ b/packages/database/prisma/migrations/20260309174403_add_poll_muted_drop_watchers/migration.sql
@@ -0,0 +1,26 @@
+/*
+ Warnings:
+
+ - You are about to drop the `watchers` table. If the table is not empty, all the data it contains will be lost.
+
+*/
+-- DropForeignKey
+ALTER TABLE "watchers" DROP CONSTRAINT "watchers_poll_id_fkey";
+
+-- DropForeignKey
+ALTER TABLE "watchers" DROP CONSTRAINT "watchers_user_id_fkey";
+
+-- AlterTable
+ALTER TABLE "polls" ADD COLUMN "muted" BOOLEAN NOT NULL DEFAULT false;
+
+-- Migrate: mark polls as muted where the creator had previously unwatched
+UPDATE "polls" p
+SET "muted" = true
+WHERE p."user_id" IS NOT NULL
+ AND NOT EXISTS (
+ SELECT 1 FROM "watchers" w
+ WHERE w."poll_id" = p."id" AND w."user_id" = p."user_id"
+ );
+
+-- DropTable
+DROP TABLE "watchers";
diff --git a/packages/database/prisma/models/poll.prisma b/packages/database/prisma/models/poll.prisma
index 54f6b1f91..f8c0250fb 100644
--- a/packages/database/prisma/models/poll.prisma
+++ b/packages/database/prisma/models/poll.prisma
@@ -38,12 +38,12 @@ model Poll {
hideScores Boolean @default(false) @map("hide_scores")
disableComments Boolean @default(false) @map("disable_comments")
requireParticipantEmail Boolean @default(false) @map("require_participant_email")
+ muted Boolean @default(false)
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
scheduledEvent ScheduledEvent? @relation(fields: [scheduledEventId], references: [id], onDelete: SetNull)
options Option[]
participants Participant[]
- watchers Watcher[]
comments Comment[]
votes Vote[]
views PollView[]
@@ -56,19 +56,6 @@ model Poll {
@@map("polls")
}
-model Watcher {
- id Int @id @default(autoincrement())
- userId String @map("user_id")
- pollId String @map("poll_id")
- createdAt DateTime @default(now()) @map("created_at")
-
- poll Poll @relation(fields: [pollId], references: [id], onDelete: Cascade)
- user User @relation(fields: [userId], references: [id], onDelete: Cascade)
-
- @@index([pollId], type: Hash)
- @@map("watchers")
-}
-
model Participant {
id String @id @default(cuid())
name String
diff --git a/packages/database/prisma/models/user.prisma b/packages/database/prisma/models/user.prisma
index 4143a625d..3328b0b37 100644
--- a/packages/database/prisma/models/user.prisma
+++ b/packages/database/prisma/models/user.prisma
@@ -57,14 +57,13 @@ model User {
lastLoginMethod String? @map("last_login_method")
isAnonymous Boolean @default(false) @map("anonymous")
- comments Comment[]
- polls Poll[]
- watcher Watcher[]
+ comments Comment[]
+ polls Poll[]
notificationPreferences UserNotificationPreferences?
- accounts Account[]
- participants Participant[]
- paymentMethods PaymentMethod[]
- spaceMemberInvites SpaceMemberInvite[]
+ accounts Account[]
+ participants Participant[]
+ paymentMethods PaymentMethod[]
+ spaceMemberInvites SpaceMemberInvite[]
subscriptions Subscription[] @relation("UserToSubscription")
spaces Space[] @relation("UserSpaces")