Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/controllers/articles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def create
@article.user = current_user if @article.user.nil?
set_wip
if @article.save
Newspaper.publish(:create_article, { article: @article })
ActiveSupport::Notifications.instrument('article.create', article: @article)

redirect_to redirect_url(@article), notice: notice_message(@article)
else
Expand All @@ -49,7 +49,7 @@ def create
def update
set_wip
if @article.update(article_params)
Newspaper.publish(:create_article, { article: @article })
ActiveSupport::Notifications.instrument('article.create', article: @article)
redirect_to redirect_url(@article), notice: notice_message(@article)
else
render :edit
Expand All @@ -58,7 +58,7 @@ def update

def destroy
@article.destroy
Newspaper.publish(:destroy_article, { article: @article })
ActiveSupport::Notifications.instrument('article.destroy', article: @article)
redirect_to articles_url, notice: '記事を削除しました'
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/works_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def create
@work = Work.new(work_params)
@work.user = current_user
if @work.save
Newspaper.publish(:work_create, { work: @work })
ActiveSupport::Notifications.instrument('work.create', work: @work)
redirect_to @work, notice: 'ポートフォリオに作品を追加しました。'
else
render :new
Expand Down
2 changes: 1 addition & 1 deletion app/models/article_notification_destroyer.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class ArticleNotificationDestroyer
def call(payload)
def call(_name, _started, _finished, _unique_id, payload)
article = payload[:article]
Notification.where(link: "/articles/#{article.id}").destroy_all
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/article_notifier.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class ArticleNotifier
def call(payload)
def call(_name, _started, _finished, _unique_id, payload)
article = payload[:article]
return unless article.saved_change_to_attribute?(:published_at, from: nil)

Expand Down
2 changes: 1 addition & 1 deletion app/models/work_notifier.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class WorkNotifier
def call(payload)
def call(_name, _started, _finished, _unique_id, payload)
work = Work.eager_load(:user).find(payload[:work].id)

User.admins_and_mentors.each do |receiver|
Expand Down
3 changes: 3 additions & 0 deletions config/initializers/active_support_notifications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@
ActiveSupport::Notifications.subscribe('announcement.create', AnnouncementNotifier.new)
ActiveSupport::Notifications.subscribe('announcement.update', AnnouncementNotifier.new)
ActiveSupport::Notifications.subscribe('announcement.destroy', AnnouncementNotificationDestroyer.new)
ActiveSupport::Notifications.subscribe('article.create', ArticleNotifier.new)
ActiveSupport::Notifications.subscribe('article.destroy', ArticleNotificationDestroyer.new)
ActiveSupport::Notifications.subscribe('work.create', WorkNotifier.new)
end
4 changes: 0 additions & 4 deletions config/initializers/newspaper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@
Newspaper.subscribe(:came_comment, CommentNotifier.new)
Newspaper.subscribe(:came_comment_in_talk, CommentNotifierForAdmin.new)

Newspaper.subscribe(:create_article, ArticleNotifier.new)
Newspaper.subscribe(:destroy_article, ArticleNotificationDestroyer.new)

Newspaper.subscribe(:work_create, WorkNotifier.new)
Newspaper.subscribe(:work_destroy, WorkNotificationDestroyer.new)

Newspaper.subscribe(:came_inquiry, InquiryNotifier.new)
Expand Down