From 6089c57a2093732efe3bdfdb2b88e1118bbe0cc0 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Thu, 21 Jul 2022 16:56:05 +0200 Subject: [PATCH] Appease the dog overlords --- app/controllers/notifications_controller.rb | 2 +- app/models/notification.rb | 18 ++++++++++-------- app/models/notification/comment_smiled.rb | 2 ++ app/models/notification/commented.rb | 4 +++- app/models/notification/question_answered.rb | 4 +++- app/models/notification/smiled.rb | 4 +++- app/models/notification/started_following.rb | 4 +++- 7 files changed, 25 insertions(+), 13 deletions(-) diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index 722fbe0c..89d6f656 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -8,7 +8,7 @@ class NotificationsController < ApplicationController "comment" => Notification::Commented.name, "commentsmile" => Notification::CommentSmiled.name, "relationship" => Notification::StartedFollowing.name, - "smile" => Notification::Smiled.name, + "smile" => Notification::Smiled.name }.freeze def index diff --git a/app/models/notification.rb b/app/models/notification.rb index f7a19c05..0d5f47d3 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + class Notification < ApplicationRecord - belongs_to :recipient, class_name: 'User' + belongs_to :recipient, class_name: "User" belongs_to :target, polymorphic: true class << self @@ -8,12 +10,12 @@ class Notification < ApplicationRecord define_cursor_paginator :cursored_for, :for define_cursor_paginator :cursored_for_type, :for_type - def for(recipient, options={}) - self.where(options.merge!(recipient: recipient)).order(:created_at).reverse_order + def for(recipient, options = {}) + where(options.merge!(recipient: recipient)).order(:created_at).reverse_order end - def for_type(recipient, type, options={}) - self.where(options.merge!(recipient: recipient)).where(type: type).order(:created_at).reverse_order + def for_type(recipient, type, options = {}) + where(options.merge!(recipient: recipient)).where(type: type).order(:created_at).reverse_order end def notify(recipient, target) @@ -33,15 +35,15 @@ class Notification < ApplicationRecord return nil unless notif_type notif = Notification.find_by(recipient: recipient, target: target) - notif.destroy unless notif.nil? + notif&.destroy end private def make_notification(recipient, target, notification_type) - n = notification_type.new(target: target, + n = notification_type.new(target: target, recipient: recipient, - new: true) + new: true) n.save! n end diff --git a/app/models/notification/comment_smiled.rb b/app/models/notification/comment_smiled.rb index 4f99d1c7..0a8efb23 100644 --- a/app/models/notification/comment_smiled.rb +++ b/app/models/notification/comment_smiled.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + class Notification::CommentSmiled < Notification end diff --git a/app/models/notification/commented.rb b/app/models/notification/commented.rb index 167f6cb4..d1b44635 100644 --- a/app/models/notification/commented.rb +++ b/app/models/notification/commented.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + class Notification::Commented < Notification -end \ No newline at end of file +end diff --git a/app/models/notification/question_answered.rb b/app/models/notification/question_answered.rb index a4189427..ad20a701 100644 --- a/app/models/notification/question_answered.rb +++ b/app/models/notification/question_answered.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + class Notification::QuestionAnswered < Notification -end \ No newline at end of file +end diff --git a/app/models/notification/smiled.rb b/app/models/notification/smiled.rb index 7cb99b3c..81cad52b 100644 --- a/app/models/notification/smiled.rb +++ b/app/models/notification/smiled.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + class Notification::Smiled < Notification -end \ No newline at end of file +end diff --git a/app/models/notification/started_following.rb b/app/models/notification/started_following.rb index 9d57696f..665a19be 100644 --- a/app/models/notification/started_following.rb +++ b/app/models/notification/started_following.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + class Notification::StartedFollowing < Notification -end \ No newline at end of file +end