-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update code to use email_enabled attribute instead of record presence
- Loading branch information
1 parent
4be89fc
commit 5015dec
Showing
5 changed files
with
48 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
class NotificationSettingsService | ||
def initialize(user) | ||
@user = user | ||
end | ||
|
||
def email_disabled?(notification_type) | ||
!email_enabled?(notification_type) | ||
end | ||
|
||
def email_enabled?(notification_type) | ||
notification_enabled?(notification_type, :email_enabled?) | ||
end | ||
|
||
def in_app_enabled?(notification_type) | ||
notification_enabled?(notification_type, :in_app_enabled?) | ||
end | ||
|
||
private | ||
|
||
attr_reader :user | ||
|
||
delegate :user_preferences, to: :user | ||
|
||
def notification_enabled?(notification_type, pref_method) | ||
pref = user_preferences.find_by(email_type: notification_type) | ||
return true if pref.nil? | ||
|
||
pref.public_send pref_method | ||
end | ||
end |