Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

Notifications settings for mentions

Matt Roberts102cd07038bc
diff --git a/app/models/enum/notification.go b/app/models/enum/notification.go
index 03fe67c6e..21f38a2a0 100644
--- a/app/models/enum/notification.go
+++ b/app/models/enum/notification.go
@@ -4,7 +4,7 @@ import (
"strconv"
)
-//NotificationChannel represents the medium that the notification is sent
+// NotificationChannel represents the medium that the notification is sent
type NotificationChannel int
var (
@@ -14,7 +14,7 @@ var (
NotificationChannelEmail NotificationChannel = 2
)
-//NotificationEvent represents all possible notification events
+// NotificationEvent represents all possible notification events
type NotificationEvent struct {
UserSettingsKeyName string
DefaultSettingValue string
@@ -52,6 +52,19 @@ var (
},
Validate: notificationEventValidation,
}
+ //NotificationEventMention is triggered when a new comment is posted with the user @-mentioned
+ NotificationEventMention = NotificationEvent{
+ UserSettingsKeyName: "event_notification_mention",
+ DefaultSettingValue: strconv.Itoa(int(NotificationChannelWeb | NotificationChannelEmail)),
+ RequiresSubscriptionUserRoles: []Role{
+ RoleVisitor,
+ },
+ DefaultEnabledUserRoles: []Role{
+ RoleAdministrator,
+ RoleCollaborator,
+ },
+ Validate: notificationEventValidation,
+ }
//NotificationEventChangeStatus is triggered when a new post has its status changed
NotificationEventChangeStatus = NotificationEvent{
UserSettingsKeyName: "event_notification_change_status",
@@ -70,6 +83,7 @@ var (
AllNotificationEvents = []NotificationEvent{
NotificationEventNewPost,
NotificationEventNewComment,
+ NotificationEventMention,
NotificationEventChangeStatus,
}
)
diff --git a/public/pages/MySettings/components/NotificationSettings.tsx b/public/pages/MySettings/components/NotificationSettings.tsx
index 8585e8351..428a62402 100644
--- a/public/pages/MySettings/components/NotificationSettings.tsx
+++ b/public/pages/MySettings/components/NotificationSettings.tsx
@@ -2,7 +2,6 @@ import React, { useState } from "react"
import { UserSettings } from "@fider/models"
import { Toggle, Field } from "@fider/components"
-import { useFider } from "@fider/hooks"
import { HStack, VStack } from "@fider/components/layout"
import { t, Trans } from "@lingui/macro"
@@ -16,7 +15,6 @@ const WebChannel: Channel = 1
const EmailChannel: Channel = 2
export const NotificationSettings = (props: NotificationSettingsProps) => {
- const fider = useFider()
const [userSettings, setUserSettings] = useState(props.userSettings)
const isEnabled = (settingsKey: string, channel: Channel): boolean => {
@@ -45,96 +43,58 @@ export const NotificationSettings = (props: NotificationSettingsProps) => {
return <Toggle key={`${settingsKey}_${channel}`} active={active} label={label} onToggle={onToggle} />
}
- const info = (settingsKey: string, aboutForVisitors: string, aboutForCollaborators: string) => {
- const about = fider.session.user.isCollaborator ? aboutForCollaborators : aboutForVisitors
- const webEnabled = isEnabled(settingsKey, WebChannel)
- const emailEnabled = isEnabled(settingsKey, EmailChannel)
-
- if (!webEnabled && !emailEnabled) {
- return (
- <p className="text-muted">
- <Trans id="mysettings.notification.message.none">
- You&apos;ll <strong>NOT</strong> receive any notification about this event.
- </Trans>
- </p>
- )
- } else if (webEnabled && !emailEnabled) {
- return (
- <p className="text-muted">
- <Trans id="mysettings.notification.message.webonly">
- You&apos;ll receive <strong>web</strong> notifications about {about}.
- </Trans>
- </p>
- )
- } else if (!webEnabled && emailEnabled) {
- return (
- <p className="text-muted">
- <Trans id="mysettings.notification.message.emailonly">
- You&apos;ll receive <strong>email</strong> notifications about {about}.
- </Trans>
- </p>
- )
- } else if (webEnabled && emailEnabled) {
- return (
- <p className="text-muted">
- <Trans id="mysettings.notification.message.webandemail">
- You&apos;ll receive <strong>web</strong> and <strong>email</strong> notifications about {about}.
- </Trans>
- </p>
- )
- }
- return null
- }
return (
<>
<Field label={t({ id: "label.notifications", message: "Notifications" })}>
- <p className="text-muted">
- <Trans id="mysettings.notification.title">Use following panel to choose which events you&apos;d like to receive notification</Trans>
+ <p className="text-muted mb-6">
+ <Trans id="mysettings.notification.title">Choose the events to recieve a notification for.</Trans>
</p>
- <div className="notifications-settings">
- <VStack spacing={4} divide={true} className="p-2 rounded">
+ <div className="notifications-settings mt-4">
+ <VStack spacing={4} divide={true} className="rounded">
+ <div>
+ <HStack spacing={6} justify="between">
+ <span>
+ <Trans id="mysettings.notification.event.newpost">New Post</Trans>
+ </span>
+ <HStack spacing={6}>
+ {icon("event_notification_new_post", WebChannel)}
+ {icon("event_notification_new_post", EmailChannel)}
+ </HStack>
+ </HStack>
+ </div>
<div>
- <div className="mb-1">
- <Trans id="mysettings.notification.event.newpost">New Post</Trans>
- </div>
- {info(
- "event_notification_new_post",
- t({ id: "mysettings.notification.event.newpost.visitors", message: "new posts on this site" }),
- t({ id: "mysettings.notification.event.newpost.staff", message: "new posts on this site" })
- )}
- <HStack spacing={6}>
- {icon("event_notification_new_post", WebChannel)}
- {icon("event_notification_new_post", EmailChannel)}
+ <HStack spacing={6} justify="between">
+ <span className="mb-1">
+ <Trans id="mysettings.notification.event.discussion">New Comments</Trans>
+ </span>
+ <HStack spacing={6}>
+ {icon("event_notification_new_comment", WebChannel)}
+ {icon("event_notification_new_comment", EmailChannel)}
+ </HStack>
</HStack>
</div>
<div>
- <div className="mb-1">
- <Trans id="mysettings.notification.event.discussion">Discussion</Trans>
- </div>
- {info(
- "event_notification_new_comment",
- t({ id: "mysettings.notification.event.discussion.visitors", message: "comments on posts you've subscribed to" }),
- t({ id: "mysettings.notification.event.discussion.staff", message: "comments on all posts unless individually unsubscribed" })
- )}
- <HStack spacing={6}>
- {icon("event_notification_new_comment", WebChannel)}
- {icon("event_notification_new_comment", EmailChannel)}
+ <HStack spacing={6} justify="between">
+ <div className="mb-1">
+ <Trans id="mysettings.notification.event.mention">Mentions</Trans>
+ </div>
+ <HStack spacing={6}>
+ {icon("event_notification_mention", WebChannel)}
+ {icon("event_notification_mention", EmailChannel)}
+ </HStack>
</HStack>
</div>
<div>
- <div className="mb-1">
- <Trans id="mysettings.notification.event.statuschanged">Status Changed</Trans>
- </div>
- {info(
- "event_notification_change_status",
- t({ id: "mysettings.notification.event.statuschanged.visitors", message: "status change on posts you've subscribed to" }),
- t({ id: "mysettings.notification.event.statuschanged.staff", message: "status change on all posts unless individually unsubscribed" })
- )}
- <HStack spacing={6}>
- {icon("event_notification_change_status", WebChannel)}
- {icon("event_notification_change_status", EmailChannel)}
+ <HStack spacing={6} justify="between">
+ <span className="mb-1">
+ <Trans id="mysettings.notification.event.statuschanged">Status Changed</Trans>
+ </span>
+ <HStack spacing={6}>
+ {icon("event_notification_change_status", WebChannel)}
+ {icon("event_notification_change_status", EmailChannel)}
+ </HStack>
</HStack>
</div>
</VStack>