From 2604e6b2404d48062304c268b36faa8fd355960f Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Thu, 16 Feb 2023 23:51:38 +0100 Subject: [PATCH 01/18] Prefetch subscriptions --- app/controllers/question_controller.rb | 4 +++- app/controllers/timeline_controller.rb | 4 +++- app/controllers/user_controller.rb | 4 +++- app/views/actions/_answer.html.haml | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/controllers/question_controller.rb b/app/controllers/question_controller.rb index 9d9c2891..0952f8d7 100644 --- a/app/controllers/question_controller.rb +++ b/app/controllers/question_controller.rb @@ -4,8 +4,10 @@ class QuestionController < ApplicationController def show @question = Question.find(params[:id]) @answers = @question.cursored_answers(last_id: params[:last_id], current_user:) - @answers_last_id = @answers.map(&:id).min + answer_ids = @answers.map(&:id) + @answers_last_id = answer_ids.min @more_data_available = !@question.cursored_answers(last_id: @answers_last_id, size: 1, current_user:).count.zero? + @subscribed = Subscription.where(user: current_user, answer_id: answer_ids).pluck(:answer_id) if user_signed_in? respond_to do |format| format.html diff --git a/app/controllers/timeline_controller.rb b/app/controllers/timeline_controller.rb index 4445af6a..7e56ba73 100644 --- a/app/controllers/timeline_controller.rb +++ b/app/controllers/timeline_controller.rb @@ -32,8 +32,10 @@ class TimelineController < ApplicationController def paginate_timeline @timeline = yield(last_id: params[:last_id]) - @timeline_last_id = @timeline.map(&:id).min + timeline_ids = @timeline.map(&:id) + @timeline_last_id = timeline_ids.min @more_data_available = !yield(last_id: @timeline_last_id, size: 1).count.zero? + @subscribed = Subscription.where(user: current_user, answer_id: timeline_ids).pluck(:answer_id) if user_signed_in? respond_to do |format| format.html { render "timeline/timeline" } diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 1963b496..56262166 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -7,9 +7,11 @@ class UserController < ApplicationController def show @answers = @user.cursored_answers(last_id: params[:last_id]) + answer_ids = @answers.map(&:id) @pinned_answers = @user.answers.pinned.order(pinned_at: :desc).limit(10) - @answers_last_id = @answers.map(&:id).min + @answers_last_id = answer_ids.min @more_data_available = !@user.cursored_answers(last_id: @answers_last_id, size: 1).count.zero? + @subscribed = Subscription.where(user: current_user, answer_id: answer_ids).pluck(:answer_id) if user_signed_in? respond_to do |format| format.html diff --git a/app/views/actions/_answer.html.haml b/app/views/actions/_answer.html.haml index de81c031..b0fe1909 100644 --- a/app/views/actions/_answer.html.haml +++ b/app/views/actions/_answer.html.haml @@ -1,5 +1,5 @@ .dropdown-menu.dropdown-menu-end{ role: :menu } - - if Subscription.is_subscribed(current_user, answer) + - if @subscribed&.include?(answer.id) -# fun joke should subscribe? %a.dropdown-item{ href: "#", data: { a_id: answer.id, action: "ab-submarine", torpedo: "no" } } %i.fa.fa-fw.fa-anchor From 7aed99d187fda6b303dcf879308b71c95f2bcab3 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Fri, 17 Feb 2023 00:35:03 +0100 Subject: [PATCH 02/18] Appease the dog overlords --- app/controllers/concerns/paginates_answers.rb | 11 +++++++++++ app/controllers/question_controller.rb | 6 ++++-- app/controllers/timeline_controller.rb | 6 +++--- app/controllers/user_controller.rb | 11 +++++------ app/views/actions/_answer.html.haml | 2 +- app/views/answerbox/_actions.html.haml | 2 +- app/views/application/_answerbox.html.haml | 4 ++-- app/views/question/show.html.haml | 2 +- app/views/question/show.turbo_stream.haml | 2 +- app/views/timeline/timeline.html.haml | 2 +- app/views/user/show.html.haml | 4 ++-- app/views/user/show.turbo_stream.haml | 2 +- 12 files changed, 33 insertions(+), 21 deletions(-) create mode 100644 app/controllers/concerns/paginates_answers.rb diff --git a/app/controllers/concerns/paginates_answers.rb b/app/controllers/concerns/paginates_answers.rb new file mode 100644 index 00000000..83fd5293 --- /dev/null +++ b/app/controllers/concerns/paginates_answers.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module PaginatesAnswers + def paginate_answers + answer_ids = @answers.map(&:id) + answer_ids += @pinned_answers.pluck(:id) if @pinned_answers.present? + @answers_last_id = answer_ids.min + @more_data_available = !@user.cursored_answers(last_id: @answers_last_id, size: 1).count.zero? + Subscription.where(user: current_user, answer_id: answer_ids + @pinned_answers.pluck(:id)).pluck(:answer_id) if user_signed_in? + end +end diff --git a/app/controllers/question_controller.rb b/app/controllers/question_controller.rb index 0952f8d7..77100737 100644 --- a/app/controllers/question_controller.rb +++ b/app/controllers/question_controller.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class QuestionController < ApplicationController + include PaginatesAnswers + def show @question = Question.find(params[:id]) @answers = @question.cursored_answers(last_id: params[:last_id], current_user:) @@ -10,8 +12,8 @@ class QuestionController < ApplicationController @subscribed = Subscription.where(user: current_user, answer_id: answer_ids).pluck(:answer_id) if user_signed_in? respond_to do |format| - format.html - format.turbo_stream { render layout: false, status: :see_other } + format.html { render locals: { subscribed_answer_ids: } } + format.turbo_stream { render layout: false, status: :see_other, locals: { subscribed_answer_ids: } } end end end diff --git a/app/controllers/timeline_controller.rb b/app/controllers/timeline_controller.rb index 7e56ba73..75c54e78 100644 --- a/app/controllers/timeline_controller.rb +++ b/app/controllers/timeline_controller.rb @@ -35,11 +35,11 @@ class TimelineController < ApplicationController timeline_ids = @timeline.map(&:id) @timeline_last_id = timeline_ids.min @more_data_available = !yield(last_id: @timeline_last_id, size: 1).count.zero? - @subscribed = Subscription.where(user: current_user, answer_id: timeline_ids).pluck(:answer_id) if user_signed_in? + subscribed_answer_ids = Subscription.where(user: current_user, answer_id: timeline_ids).pluck(:answer_id) if user_signed_in? respond_to do |format| - format.html { render "timeline/timeline" } - format.turbo_stream { render "timeline/timeline", layout: false, status: :see_other } + format.html { render "timeline/timeline", locals: { subscribed_answer_ids: } } + format.turbo_stream { render "timeline/timeline", layout: false, status: :see_other, locals: { subscribed_answer_ids: } } end end end diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 56262166..0fc30366 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -1,21 +1,20 @@ # frozen_string_literal: true class UserController < ApplicationController + include PaginatesAnswers + before_action :set_user before_action :hidden_social_graph_redirect, only: %i[followers followings] after_action :mark_notification_as_read, only: %i[show] def show @answers = @user.cursored_answers(last_id: params[:last_id]) - answer_ids = @answers.map(&:id) @pinned_answers = @user.answers.pinned.order(pinned_at: :desc).limit(10) - @answers_last_id = answer_ids.min - @more_data_available = !@user.cursored_answers(last_id: @answers_last_id, size: 1).count.zero? - @subscribed = Subscription.where(user: current_user, answer_id: answer_ids).pluck(:answer_id) if user_signed_in? + subscribed_answer_ids = paginate_answers respond_to do |format| - format.html - format.turbo_stream + format.html { render locals: { subscribed_answer_ids: } } + format.turbo_stream { render layout: false, locals: { subscribed_answer_ids: } } end end diff --git a/app/views/actions/_answer.html.haml b/app/views/actions/_answer.html.haml index b0fe1909..e63e452b 100644 --- a/app/views/actions/_answer.html.haml +++ b/app/views/actions/_answer.html.haml @@ -1,5 +1,5 @@ .dropdown-menu.dropdown-menu-end{ role: :menu } - - if @subscribed&.include?(answer.id) + - if subscribed_answer_ids&.include?(answer.id) -# fun joke should subscribe? %a.dropdown-item{ href: "#", data: { a_id: answer.id, action: "ab-submarine", torpedo: "no" } } %i.fa.fa-fw.fa-anchor diff --git a/app/views/answerbox/_actions.html.haml b/app/views/answerbox/_actions.html.haml index 4ec1c35d..5c152abe 100644 --- a/app/views/answerbox/_actions.html.haml +++ b/app/views/answerbox/_actions.html.haml @@ -13,4 +13,4 @@ .btn-group %button.btn.btn-default.btn-sm.dropdown-toggle{ data: { bs_toggle: :dropdown }, aria: { expanded: false } } %span.caret - = render "actions/answer", answer: a + = render "actions/answer", answer: a, subscribed_answer_ids: diff --git a/app/views/application/_answerbox.html.haml b/app/views/application/_answerbox.html.haml index 36c2a90e..b84a5f17 100644 --- a/app/views/application/_answerbox.html.haml +++ b/app/views/application/_answerbox.html.haml @@ -21,7 +21,7 @@ .answerbox__answer-date = link_to(raw(t("time.distance_ago", time: time_tooltip(a))), answer_path(a.user.screen_name, a.id), data: { selection_hotkey: "l" }) .col-md-6.d-flex.d-md-block.answerbox__actions - = render "answerbox/actions", a: a, display_all: display_all + = render "answerbox/actions", a:, display_all:, subscribed_answer_ids: - else .row .col-md-6.text-start.text-muted @@ -33,7 +33,7 @@ %i.fa.fa-thumbtack = t(".pinned") .col-md-6.d-md-flex.answerbox__actions - = render "answerbox/actions", a: a, display_all: display_all + = render "answerbox/actions", a:, display_all:, subscribed_answer_ids: .card-footer{ id: "ab-comments-section-#{a.id}", class: display_all.nil? ? "d-none" : nil } %div{ id: "ab-smiles-#{a.id}" }= render "answerbox/smiles", a: a %div{ id: "ab-comments-#{a.id}" }= render "answerbox/comments", a: a diff --git a/app/views/question/show.html.haml b/app/views/question/show.html.haml index b21b70f1..102389f6 100644 --- a/app/views/question/show.html.haml +++ b/app/views/question/show.html.haml @@ -6,7 +6,7 @@ %button.d-none{ data: { hotkey: "j", action: "navigation#down" } } %button.d-none{ data: { hotkey: "k", action: "navigation#up" } } - @answers.each do |a| - = render "answerbox", a: a, show_question: false + = render "answerbox", a:, show_question: false, subscribed_answer_ids: - if @more_data_available .d-flex.justify-content-center.justify-content-sm-start#paginator diff --git a/app/views/question/show.turbo_stream.haml b/app/views/question/show.turbo_stream.haml index 34f6be75..758a5e23 100644 --- a/app/views/question/show.turbo_stream.haml +++ b/app/views/question/show.turbo_stream.haml @@ -1,6 +1,6 @@ = turbo_stream.append "answers" do - @answers.each do |a| - = render "answerbox", a: a, show_question: false + = render "answerbox", a:, show_question: false, subscribed_answer_ids: = turbo_stream.update "paginator" do - if @more_data_available diff --git a/app/views/timeline/timeline.html.haml b/app/views/timeline/timeline.html.haml index 2b3089b8..6515d9bf 100644 --- a/app/views/timeline/timeline.html.haml +++ b/app/views/timeline/timeline.html.haml @@ -2,7 +2,7 @@ %button.d-none{ data: { hotkey: "j", action: "navigation#down" } } %button.d-none{ data: { hotkey: "k", action: "navigation#up" } } - @timeline.each do |answer| - = render "answerbox", a: answer + = render "answerbox", a: answer, subscribed_answer_ids: - if @more_data_available .d-flex.justify-content-center#paginator diff --git a/app/views/user/show.html.haml b/app/views/user/show.html.haml index 98f36de8..69a03fe8 100644 --- a/app/views/user/show.html.haml +++ b/app/views/user/show.html.haml @@ -4,11 +4,11 @@ %button.d-none{ data: { hotkey: "k", action: "navigation#up" } } #pinned-answers - @pinned_answers.each do |a| - = render "answerbox", a: + = render "answerbox", a:, subscribed_answer_ids: #answers - @answers.each do |a| - = render "answerbox", a: + = render "answerbox", a:, subscribed_answer_ids: - if @more_data_available .d-flex.justify-content-center.justify-content-sm-start#paginator diff --git a/app/views/user/show.turbo_stream.haml b/app/views/user/show.turbo_stream.haml index c341e74b..a3477c47 100644 --- a/app/views/user/show.turbo_stream.haml +++ b/app/views/user/show.turbo_stream.haml @@ -1,6 +1,6 @@ = turbo_stream.append "answers" do - @answers.each do |a| - = render 'answerbox', a: a + = render "answerbox", a:, subscribed_answer_ids: = turbo_stream.update "paginator" do - if @more_data_available From d7997db4920e88b2b7bb0f5675349402d488da4e Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Fri, 17 Feb 2023 00:45:40 +0100 Subject: [PATCH 03/18] Check subscription in `answer/show` --- app/controllers/answer_controller.rb | 1 + app/views/answer/show.html.haml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/answer_controller.rb b/app/controllers/answer_controller.rb index d5e70881..110486d1 100644 --- a/app/controllers/answer_controller.rb +++ b/app/controllers/answer_controller.rb @@ -9,6 +9,7 @@ class AnswerController < ApplicationController def show @answer = Answer.includes(comments: %i[user smiles], question: [:user], smiles: [:user]).find(params[:id]) + @subscribed = Subscription.where(user: current_user, answer: @answer).pluck(:id) @display_all = true if user_signed_in? diff --git a/app/views/answer/show.html.haml b/app/views/answer/show.html.haml index 5f84d47d..393b0dd5 100644 --- a/app/views/answer/show.html.haml +++ b/app/views/answer/show.html.haml @@ -1,4 +1,4 @@ - provide(:title, answer_title(@answer)) - provide(:og, answer_opengraph(@answer)) .container-lg.container--main - = render 'answerbox', a: @answer, display_all: @display_all + = render 'answerbox', a: @answer, display_all: @display_all, subscribed_answer_ids: @subscribed From 0771c689ead9cc52fe11c00a161016f73e64f68d Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Fri, 17 Feb 2023 01:18:33 +0100 Subject: [PATCH 04/18] Clean up marking notifications as read when viewing an answer --- app/controllers/answer_controller.rb | 23 ++++++++++++----------- app/views/answer/show.html.haml | 2 +- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/app/controllers/answer_controller.rb b/app/controllers/answer_controller.rb index 110486d1..3d520116 100644 --- a/app/controllers/answer_controller.rb +++ b/app/controllers/answer_controller.rb @@ -11,17 +11,7 @@ class AnswerController < ApplicationController @answer = Answer.includes(comments: %i[user smiles], question: [:user], smiles: [:user]).find(params[:id]) @subscribed = Subscription.where(user: current_user, answer: @answer).pluck(:id) @display_all = true - - if user_signed_in? - notif = Notification.where(type: "Notification::QuestionAnswered", target_id: @answer.id, recipient_id: current_user.id, new: true).first - notif&.update(new: false) - notif = Notification.where(type: "Notification::Commented", target_id: @answer.comments.pluck(:id), recipient_id: current_user.id, new: true) - notif.update_all(new: false) unless notif.empty? - notif = Notification.where(type: "Notification::Smiled", target_id: @answer.smiles.pluck(:id), recipient_id: current_user.id, new: true) - notif.update_all(new: false) unless notif.empty? - notif = Notification.where(type: "Notification::CommentSmiled", target_id: @answer.comment_smiles.pluck(:id), recipient_id: current_user.id, new: true) - notif.update_all(new: false) unless notif.empty? - end + mark_notifications_as_read if user_signed_in? end def pin @@ -53,4 +43,15 @@ class AnswerController < ApplicationController end end end + + private + + def mark_notifications_as_read + Notification.where(recipient_id: current_user.id, new: true) + .and(Notification.where(type: "Notification::QuestionAnswered", target_id: @answer.id) + .or(Notification.where(type: "Notification::Commented", target_id: @answer.comments.pluck(:id))) + .or(Notification.where(type: "Notification::Smiled", target_id: @answer.smiles.pluck(:id))) + .or(Notification.where(type: "Notification::CommentSmiled", target_id: @answer.comment_smiles.pluck(:id)))) + .update_all(new: false) # rubocop:disable Rails/SkipsModelValidations + end end diff --git a/app/views/answer/show.html.haml b/app/views/answer/show.html.haml index 393b0dd5..8a50232f 100644 --- a/app/views/answer/show.html.haml +++ b/app/views/answer/show.html.haml @@ -1,4 +1,4 @@ - provide(:title, answer_title(@answer)) - provide(:og, answer_opengraph(@answer)) .container-lg.container--main - = render 'answerbox', a: @answer, display_all: @display_all, subscribed_answer_ids: @subscribed + = render "answerbox", a: @answer, display_all: @display_all, subscribed_answer_ids: @subscribed From 904eab8daaedcc043aa8fed3b79fe087f5ed68db Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Fri, 17 Feb 2023 09:08:13 +0100 Subject: [PATCH 05/18] Remove now unused `is_subscribed` method --- app/models/subscription.rb | 9 --------- 1 file changed, 9 deletions(-) diff --git a/app/models/subscription.rb b/app/models/subscription.rb index bab3bf39..e8704d8b 100644 --- a/app/models/subscription.rb +++ b/app/models/subscription.rb @@ -7,15 +7,6 @@ class Subscription < ApplicationRecord Subscription.where(answer: target) end - def is_subscribed(recipient, target) - existing = Subscription.find_by(user: recipient, answer: target) - if existing.nil? - false - else - existing.is_active - end - end - def subscribe(recipient, target, force = true) existing = Subscription.find_by(user: recipient, answer: target) if existing.nil? From d77919ee01b6e188764c52cd0f0f50adb710c58f Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Sun, 19 Feb 2023 15:50:32 +0100 Subject: [PATCH 06/18] Don't check for user sign in when fetching subscriptions in timeline --- app/controllers/timeline_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/timeline_controller.rb b/app/controllers/timeline_controller.rb index 75c54e78..d905ccd5 100644 --- a/app/controllers/timeline_controller.rb +++ b/app/controllers/timeline_controller.rb @@ -35,7 +35,7 @@ class TimelineController < ApplicationController timeline_ids = @timeline.map(&:id) @timeline_last_id = timeline_ids.min @more_data_available = !yield(last_id: @timeline_last_id, size: 1).count.zero? - subscribed_answer_ids = Subscription.where(user: current_user, answer_id: timeline_ids).pluck(:answer_id) if user_signed_in? + subscribed_answer_ids = Subscription.where(user: current_user, answer_id: timeline_ids).pluck(:answer_id) respond_to do |format| format.html { render "timeline/timeline", locals: { subscribed_answer_ids: } } From 6fc4049f6c250ecf2e65606e129ac4960016f830 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Sun, 19 Feb 2023 15:51:19 +0100 Subject: [PATCH 07/18] Pass answer list method into `paginate_answers` --- app/controllers/answer_controller.rb | 8 ++++++-- app/controllers/concerns/paginates_answers.rb | 5 +++-- app/controllers/user_controller.rb | 3 +-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/controllers/answer_controller.rb b/app/controllers/answer_controller.rb index 3d520116..56577a41 100644 --- a/app/controllers/answer_controller.rb +++ b/app/controllers/answer_controller.rb @@ -9,9 +9,13 @@ class AnswerController < ApplicationController def show @answer = Answer.includes(comments: %i[user smiles], question: [:user], smiles: [:user]).find(params[:id]) - @subscribed = Subscription.where(user: current_user, answer: @answer).pluck(:id) @display_all = true - mark_notifications_as_read if user_signed_in? + @subscribed = [] + + return unless user_signed_in? + + @subscribed = Subscription.where(user: current_user, answer: @answer).pluck(:answer_id) + mark_notifications_as_read end def pin diff --git a/app/controllers/concerns/paginates_answers.rb b/app/controllers/concerns/paginates_answers.rb index 83fd5293..bd49d4e2 100644 --- a/app/controllers/concerns/paginates_answers.rb +++ b/app/controllers/concerns/paginates_answers.rb @@ -2,10 +2,11 @@ module PaginatesAnswers def paginate_answers + @answers = yield(last_id: params[:last_id]) answer_ids = @answers.map(&:id) answer_ids += @pinned_answers.pluck(:id) if @pinned_answers.present? @answers_last_id = answer_ids.min - @more_data_available = !@user.cursored_answers(last_id: @answers_last_id, size: 1).count.zero? - Subscription.where(user: current_user, answer_id: answer_ids + @pinned_answers.pluck(:id)).pluck(:answer_id) if user_signed_in? + @more_data_available = !yield(last_id: @answers_last_id, size: 1).count.zero? + Subscription.where(user: current_user, answer_id: answer_ids).pluck(:answer_id) if user_signed_in? end end diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 0fc30366..1fe36a4f 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -8,9 +8,8 @@ class UserController < ApplicationController after_action :mark_notification_as_read, only: %i[show] def show - @answers = @user.cursored_answers(last_id: params[:last_id]) @pinned_answers = @user.answers.pinned.order(pinned_at: :desc).limit(10) - subscribed_answer_ids = paginate_answers + subscribed_answer_ids = paginate_answers { |args| @user.cursored_answers(**args) } respond_to do |format| format.html { render locals: { subscribed_answer_ids: } } From 0a97a86d7349206d5f3a2ad03d9d48e883f95c9f Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Sun, 19 Feb 2023 15:51:33 +0100 Subject: [PATCH 08/18] Pass `subscribed_answer_ids` into `answerbox` in Turbo Stream --- app/views/timeline/timeline.turbo_stream.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/timeline/timeline.turbo_stream.haml b/app/views/timeline/timeline.turbo_stream.haml index 561309e6..f1d93222 100644 --- a/app/views/timeline/timeline.turbo_stream.haml +++ b/app/views/timeline/timeline.turbo_stream.haml @@ -1,6 +1,6 @@ = turbo_stream.append "timeline" do - @timeline.each do |answer| - = render "answerbox", a: answer + = render "answerbox", a: answer, subscribed_answer_ids: = turbo_stream.update "paginator" do - if @more_data_available From 51638d2eb24af748149846633cd89e87886cdb35 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Mon, 27 Feb 2023 21:34:34 +0100 Subject: [PATCH 09/18] Remove `subscriptions.is_active` column --- .../20230227174822_remove_is_active_from_subscriptions.rb | 8 ++++++++ db/schema.rb | 3 +-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20230227174822_remove_is_active_from_subscriptions.rb diff --git a/db/migrate/20230227174822_remove_is_active_from_subscriptions.rb b/db/migrate/20230227174822_remove_is_active_from_subscriptions.rb new file mode 100644 index 00000000..3b8cb4b5 --- /dev/null +++ b/db/migrate/20230227174822_remove_is_active_from_subscriptions.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +class RemoveIsActiveFromSubscriptions < ActiveRecord::Migration[6.1] + def up + execute "DELETE FROM subscriptions WHERE is_active = FALSE" + remove_column :subscriptions, :is_active + end +end diff --git a/db/schema.rb b/db/schema.rb index 3cabc240..39dc6424 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2023_02_25_143633) do +ActiveRecord::Schema.define(version: 2023_02_27_174822) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -261,7 +261,6 @@ ActiveRecord::Schema.define(version: 2023_02_25_143633) do t.bigint "answer_id", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.boolean "is_active", default: true t.index ["user_id", "answer_id"], name: "index_subscriptions_on_user_id_and_answer_id" end From 0132d7b25130d8e2920029e9be0914934b124ffc Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Sat, 4 Mar 2023 20:42:51 +0100 Subject: [PATCH 10/18] Remove usages of `is_active` --- .../ajax/subscription_controller.rb | 8 ++++---- app/models/comment.rb | 2 +- app/models/subscription.rb | 18 ++++++------------ .../ajax/subscription_controller_spec.rb | 10 +++++----- 4 files changed, 16 insertions(+), 22 deletions(-) diff --git a/app/controllers/ajax/subscription_controller.rb b/app/controllers/ajax/subscription_controller.rb index a04520e4..fd574e78 100644 --- a/app/controllers/ajax/subscription_controller.rb +++ b/app/controllers/ajax/subscription_controller.rb @@ -4,14 +4,14 @@ class Ajax::SubscriptionController < AjaxController def subscribe params.require :answer @response[:status] = :okay - state = Subscription.subscribe(current_user, Answer.find(params[:answer])).nil? - @response[:success] = state == false + result = Subscription.subscribe(current_user, Answer.find(params[:answer])) + @response[:success] = result.present? end def unsubscribe params.require :answer @response[:status] = :okay - state = Subscription.unsubscribe(current_user, Answer.find(params[:answer])).nil? - @response[:success] = state == false + result = Subscription.unsubscribe(current_user, Answer.find(params[:answer])) + @response[:success] = result&.destroyed? || false end end diff --git a/app/models/comment.rb b/app/models/comment.rb index 3b43999e..830a6f4e 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -8,7 +8,7 @@ class Comment < ApplicationRecord validates :content, length: { maximum: 512 } after_create do - Subscription.subscribe self.user, answer, false + Subscription.subscribe self.user, answer Subscription.notify self, answer end diff --git a/app/models/subscription.rb b/app/models/subscription.rb index e8704d8b..1eb4fd9e 100644 --- a/app/models/subscription.rb +++ b/app/models/subscription.rb @@ -3,17 +3,11 @@ class Subscription < ApplicationRecord belongs_to :answer class << self - def for(target) - Subscription.where(answer: target) - end - - def subscribe(recipient, target, force = true) + def subscribe(recipient, target) existing = Subscription.find_by(user: recipient, answer: target) - if existing.nil? - Subscription.new(user: recipient, answer: target).save! - elsif force - existing.update(is_active: true) - end + return true if existing.present? + + Subscription.create!(user: recipient, answer: target) end def unsubscribe(recipient, target) @@ -22,7 +16,7 @@ class Subscription < ApplicationRecord end subs = Subscription.find_by(user: recipient, answer: target) - subs.update(is_active: false) unless subs.nil? + subs&.destroy end def destruct(target) @@ -46,7 +40,7 @@ class Subscription < ApplicationRecord return nil end - Subscription.where(answer: target, is_active: true).each do |subs| + Subscription.where(answer: target).each do |subs| next unless not subs.user == source.user Notification.notify subs.user, source end diff --git a/spec/controllers/ajax/subscription_controller_spec.rb b/spec/controllers/ajax/subscription_controller_spec.rb index 6a14aeee..23499211 100644 --- a/spec/controllers/ajax/subscription_controller_spec.rb +++ b/spec/controllers/ajax/subscription_controller_spec.rb @@ -33,7 +33,7 @@ describe Ajax::SubscriptionController, :ajax_controller, type: :controller do context "when subscription does not exist" do it "creates a subscription on the answer" do expect { subject }.to(change { answer.subscriptions.count }.by(1)) - expect(answer.subscriptions.where(is_active: true).map { |s| s.user.id }.sort).to eq([answer_user.id, user.id].sort) + expect(answer.subscriptions.map { |s| s.user.id }.sort).to eq([answer_user.id, user.id].sort) end include_examples "returns the expected response" @@ -44,7 +44,7 @@ describe Ajax::SubscriptionController, :ajax_controller, type: :controller do it "does not modify the answer's subscriptions" do expect { subject }.to(change { answer.subscriptions.count }.by(0)) - expect(answer.subscriptions.where(is_active: true).map { |s| s.user.id }.sort).to eq([answer_user.id, user.id].sort) + expect(answer.subscriptions.map { |s| s.user.id }.sort).to eq([answer_user.id, user.id].sort) end include_examples "returns the expected response" @@ -105,8 +105,8 @@ describe Ajax::SubscriptionController, :ajax_controller, type: :controller do before(:each) { Subscription.subscribe(user, answer) } it "removes an active subscription from the answer" do - expect { subject }.to(change { answer.subscriptions.where(is_active: true).count }.by(-1)) - expect(answer.subscriptions.where(is_active: true).map { |s| s.user.id }.sort).to eq([answer_user.id].sort) + expect { subject }.to(change { answer.subscriptions.count }.by(-1)) + expect(answer.subscriptions.map { |s| s.user.id }.sort).to eq([answer_user.id].sort) end include_examples "returns the expected response" @@ -123,7 +123,7 @@ describe Ajax::SubscriptionController, :ajax_controller, type: :controller do it "does not modify the answer's subscriptions" do expect { subject }.to(change { answer.subscriptions.count }.by(0)) - expect(answer.subscriptions.where(is_active: true).map { |s| s.user.id }.sort).to eq([answer_user.id].sort) + expect(answer.subscriptions.map { |s| s.user.id }.sort).to eq([answer_user.id].sort) end include_examples "returns the expected response" From f73fc87991924a8ddd83675f63030ea7d6439fa9 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Sun, 5 Mar 2023 13:47:46 +0100 Subject: [PATCH 11/18] Simplify `notify` and `denotify` methods --- app/models/subscription.rb | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/app/models/subscription.rb b/app/models/subscription.rb index 1eb4fd9e..0424c3da 100644 --- a/app/models/subscription.rb +++ b/app/models/subscription.rb @@ -36,23 +36,20 @@ class Subscription < ApplicationRecord end def notify(source, target) - if source.nil? or target.nil? - return nil + return nil if source.nil? || target.nil? + + notifications = Subscription.where(answer: target).where.not(user: target.user).map do |s| + { target_id: source.id, target_type: Comment, recipient_id: s.user_id, new: true, type: Notification::Commented } end - Subscription.where(answer: target).each do |subs| - next unless not subs.user == source.user - Notification.notify subs.user, source - end + Notification.insert_all!(notifications) end def denotify(source, target) - if source.nil? or target.nil? - return nil - end - Subscription.where(answer: target).each do |subs| - Notification.denotify subs.user, source - end + return nil if source.nil? or target.nil? + + subs = Subscription.where(answer: target) + Notification.where(target:, recipient: subs.map(&:user)).delete_all end end end From 36d59d100edff8d2436f6821e5bafc9300477316 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Sun, 5 Mar 2023 13:48:27 +0100 Subject: [PATCH 12/18] Remove unused `destruct_by` method --- app/models/subscription.rb | 9 --------- 1 file changed, 9 deletions(-) diff --git a/app/models/subscription.rb b/app/models/subscription.rb index 0424c3da..6d6af38e 100644 --- a/app/models/subscription.rb +++ b/app/models/subscription.rb @@ -26,15 +26,6 @@ class Subscription < ApplicationRecord Subscription.where(answer: target).destroy_all end - def destruct_by(recipient, target) - if recipient.nil? or target.nil? - return nil - end - - subs = Subscription.find_by(user: recipient, answer: target) - subs.destroy unless subs.nil? - end - def notify(source, target) return nil if source.nil? || target.nil? From fb83f48adf5c0c2100c1dd504145e8ea1ccb3314 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Sun, 5 Mar 2023 13:48:59 +0100 Subject: [PATCH 13/18] Fix lint errors --- app/models/subscription.rb | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/models/subscription.rb b/app/models/subscription.rb index 6d6af38e..a94d95ab 100644 --- a/app/models/subscription.rb +++ b/app/models/subscription.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Subscription < ApplicationRecord belongs_to :user belongs_to :answer @@ -11,18 +13,15 @@ class Subscription < ApplicationRecord end def unsubscribe(recipient, target) - if recipient.nil? or target.nil? - return nil - end + return nil if recipient.nil? || target.nil? subs = Subscription.find_by(user: recipient, answer: target) subs&.destroy end def destruct(target) - if target.nil? - return nil - end + return nil if target.nil? + Subscription.where(answer: target).destroy_all end @@ -37,7 +36,7 @@ class Subscription < ApplicationRecord end def denotify(source, target) - return nil if source.nil? or target.nil? + return nil if source.nil? || target.nil? subs = Subscription.where(answer: target) Notification.where(target:, recipient: subs.map(&:user)).delete_all From b93058b11df7ff9b02e08114cadb31d8375b771e Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Sun, 5 Mar 2023 14:01:56 +0100 Subject: [PATCH 14/18] Fix remaining lint errors --- app/models/comment.rb | 2 +- app/models/subscription.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index 830a6f4e..00472037 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -8,7 +8,7 @@ class Comment < ApplicationRecord validates :content, length: { maximum: 512 } after_create do - Subscription.subscribe self.user, answer + Subscription.subscribe user, answer Subscription.notify self, answer end diff --git a/app/models/subscription.rb b/app/models/subscription.rb index a94d95ab..507cc55c 100644 --- a/app/models/subscription.rb +++ b/app/models/subscription.rb @@ -32,7 +32,7 @@ class Subscription < ApplicationRecord { target_id: source.id, target_type: Comment, recipient_id: s.user_id, new: true, type: Notification::Commented } end - Notification.insert_all!(notifications) + Notification.insert_all!(notifications) # rubocop:disable Rails/SkipsModelValidations end def denotify(source, target) From 9c4b2e452a905a85b9000751ec85ef15acbb1858 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Sun, 5 Mar 2023 14:15:52 +0100 Subject: [PATCH 15/18] Prevent error when no one is subscribed --- app/models/subscription.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/subscription.rb b/app/models/subscription.rb index 507cc55c..b7971a98 100644 --- a/app/models/subscription.rb +++ b/app/models/subscription.rb @@ -32,7 +32,7 @@ class Subscription < ApplicationRecord { target_id: source.id, target_type: Comment, recipient_id: s.user_id, new: true, type: Notification::Commented } end - Notification.insert_all!(notifications) # rubocop:disable Rails/SkipsModelValidations + Notification.insert_all!(notifications) unless notifications.empty? # rubocop:disable Rails/SkipsModelValidations end def denotify(source, target) From bbc0afe292177168308c06171fcf5846604405d9 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Sun, 19 Mar 2023 16:00:15 +0100 Subject: [PATCH 16/18] Move subscribed answer IDs to an ivar --- app/controllers/answer_controller.rb | 4 ++-- app/controllers/concerns/paginates_answers.rb | 2 +- app/controllers/question_controller.rb | 4 ++-- app/controllers/timeline_controller.rb | 6 +++--- app/controllers/user_controller.rb | 6 +++--- app/views/answer/show.html.haml | 2 +- app/views/application/_answerbox.html.haml | 2 +- app/views/question/show.html.haml | 2 +- app/views/question/show.turbo_stream.haml | 2 +- app/views/timeline/timeline.html.haml | 2 +- app/views/timeline/timeline.turbo_stream.haml | 2 +- app/views/user/show.html.haml | 4 ++-- app/views/user/show.turbo_stream.haml | 2 +- 13 files changed, 20 insertions(+), 20 deletions(-) diff --git a/app/controllers/answer_controller.rb b/app/controllers/answer_controller.rb index 56577a41..ac52ab40 100644 --- a/app/controllers/answer_controller.rb +++ b/app/controllers/answer_controller.rb @@ -10,11 +10,11 @@ class AnswerController < ApplicationController def show @answer = Answer.includes(comments: %i[user smiles], question: [:user], smiles: [:user]).find(params[:id]) @display_all = true - @subscribed = [] + @subscribed_answer_ids = [] return unless user_signed_in? - @subscribed = Subscription.where(user: current_user, answer: @answer).pluck(:answer_id) + @subscribed_answer_ids = Subscription.where(user: current_user, answer: @answer).pluck(:answer_id) mark_notifications_as_read end diff --git a/app/controllers/concerns/paginates_answers.rb b/app/controllers/concerns/paginates_answers.rb index bd49d4e2..567eee25 100644 --- a/app/controllers/concerns/paginates_answers.rb +++ b/app/controllers/concerns/paginates_answers.rb @@ -7,6 +7,6 @@ module PaginatesAnswers answer_ids += @pinned_answers.pluck(:id) if @pinned_answers.present? @answers_last_id = answer_ids.min @more_data_available = !yield(last_id: @answers_last_id, size: 1).count.zero? - Subscription.where(user: current_user, answer_id: answer_ids).pluck(:answer_id) if user_signed_in? + @subscribed_answer_ids = Subscription.where(user: current_user, answer_id: answer_ids).pluck(:answer_id) if user_signed_in? end end diff --git a/app/controllers/question_controller.rb b/app/controllers/question_controller.rb index 77100737..14dbe80e 100644 --- a/app/controllers/question_controller.rb +++ b/app/controllers/question_controller.rb @@ -12,8 +12,8 @@ class QuestionController < ApplicationController @subscribed = Subscription.where(user: current_user, answer_id: answer_ids).pluck(:answer_id) if user_signed_in? respond_to do |format| - format.html { render locals: { subscribed_answer_ids: } } - format.turbo_stream { render layout: false, status: :see_other, locals: { subscribed_answer_ids: } } + format.html + format.turbo_stream { render layout: false, status: :see_other } end end end diff --git a/app/controllers/timeline_controller.rb b/app/controllers/timeline_controller.rb index d905ccd5..6b34fdb4 100644 --- a/app/controllers/timeline_controller.rb +++ b/app/controllers/timeline_controller.rb @@ -35,11 +35,11 @@ class TimelineController < ApplicationController timeline_ids = @timeline.map(&:id) @timeline_last_id = timeline_ids.min @more_data_available = !yield(last_id: @timeline_last_id, size: 1).count.zero? - subscribed_answer_ids = Subscription.where(user: current_user, answer_id: timeline_ids).pluck(:answer_id) + @subscribed_answer_ids = Subscription.where(user: current_user, answer_id: timeline_ids).pluck(:answer_id) respond_to do |format| - format.html { render "timeline/timeline", locals: { subscribed_answer_ids: } } - format.turbo_stream { render "timeline/timeline", layout: false, status: :see_other, locals: { subscribed_answer_ids: } } + format.html { render "timeline/timeline" } + format.turbo_stream { render "timeline/timeline", layout: false, status: :see_other } end end end diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 1fe36a4f..7b9084b9 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -9,11 +9,11 @@ class UserController < ApplicationController def show @pinned_answers = @user.answers.pinned.order(pinned_at: :desc).limit(10) - subscribed_answer_ids = paginate_answers { |args| @user.cursored_answers(**args) } + paginate_answers { |args| @user.cursored_answers(**args) } respond_to do |format| - format.html { render locals: { subscribed_answer_ids: } } - format.turbo_stream { render layout: false, locals: { subscribed_answer_ids: } } + format.html + format.turbo_stream { render layout: false } end end diff --git a/app/views/answer/show.html.haml b/app/views/answer/show.html.haml index 8a50232f..55f2a90b 100644 --- a/app/views/answer/show.html.haml +++ b/app/views/answer/show.html.haml @@ -1,4 +1,4 @@ - provide(:title, answer_title(@answer)) - provide(:og, answer_opengraph(@answer)) .container-lg.container--main - = render "answerbox", a: @answer, display_all: @display_all, subscribed_answer_ids: @subscribed + = render "answerbox", a: @answer, display_all: @display_all, subscribed_answer_ids: @subscribed_answer_ids diff --git a/app/views/application/_answerbox.html.haml b/app/views/application/_answerbox.html.haml index b84a5f17..2064909e 100644 --- a/app/views/application/_answerbox.html.haml +++ b/app/views/application/_answerbox.html.haml @@ -21,7 +21,7 @@ .answerbox__answer-date = link_to(raw(t("time.distance_ago", time: time_tooltip(a))), answer_path(a.user.screen_name, a.id), data: { selection_hotkey: "l" }) .col-md-6.d-flex.d-md-block.answerbox__actions - = render "answerbox/actions", a:, display_all:, subscribed_answer_ids: + = render "answerbox/actions", a:, display_all: - else .row .col-md-6.text-start.text-muted diff --git a/app/views/question/show.html.haml b/app/views/question/show.html.haml index 102389f6..e1d0b238 100644 --- a/app/views/question/show.html.haml +++ b/app/views/question/show.html.haml @@ -6,7 +6,7 @@ %button.d-none{ data: { hotkey: "j", action: "navigation#down" } } %button.d-none{ data: { hotkey: "k", action: "navigation#up" } } - @answers.each do |a| - = render "answerbox", a:, show_question: false, subscribed_answer_ids: + = render "answerbox", a:, show_question: false, subscribed_answer_ids: @subscribed_answer_ids - if @more_data_available .d-flex.justify-content-center.justify-content-sm-start#paginator diff --git a/app/views/question/show.turbo_stream.haml b/app/views/question/show.turbo_stream.haml index 758a5e23..96facf13 100644 --- a/app/views/question/show.turbo_stream.haml +++ b/app/views/question/show.turbo_stream.haml @@ -1,6 +1,6 @@ = turbo_stream.append "answers" do - @answers.each do |a| - = render "answerbox", a:, show_question: false, subscribed_answer_ids: + = render "answerbox", a:, show_question: false, subscribed_answer_ids: @subscribed_answer_ids = turbo_stream.update "paginator" do - if @more_data_available diff --git a/app/views/timeline/timeline.html.haml b/app/views/timeline/timeline.html.haml index 6515d9bf..4ed197a8 100644 --- a/app/views/timeline/timeline.html.haml +++ b/app/views/timeline/timeline.html.haml @@ -2,7 +2,7 @@ %button.d-none{ data: { hotkey: "j", action: "navigation#down" } } %button.d-none{ data: { hotkey: "k", action: "navigation#up" } } - @timeline.each do |answer| - = render "answerbox", a: answer, subscribed_answer_ids: + = render "answerbox", a: answer, subscribed_answer_ids: @subscribed_answer_ids - if @more_data_available .d-flex.justify-content-center#paginator diff --git a/app/views/timeline/timeline.turbo_stream.haml b/app/views/timeline/timeline.turbo_stream.haml index f1d93222..1802f630 100644 --- a/app/views/timeline/timeline.turbo_stream.haml +++ b/app/views/timeline/timeline.turbo_stream.haml @@ -1,6 +1,6 @@ = turbo_stream.append "timeline" do - @timeline.each do |answer| - = render "answerbox", a: answer, subscribed_answer_ids: + = render "answerbox", a: answer, subscribed_answer_ids: @subscribed_answer_ids = turbo_stream.update "paginator" do - if @more_data_available diff --git a/app/views/user/show.html.haml b/app/views/user/show.html.haml index 69a03fe8..e110ca20 100644 --- a/app/views/user/show.html.haml +++ b/app/views/user/show.html.haml @@ -4,11 +4,11 @@ %button.d-none{ data: { hotkey: "k", action: "navigation#up" } } #pinned-answers - @pinned_answers.each do |a| - = render "answerbox", a:, subscribed_answer_ids: + = render "answerbox", a:, subscribed_answer_ids: @subscribed_answer_ids #answers - @answers.each do |a| - = render "answerbox", a:, subscribed_answer_ids: + = render "answerbox", a:, subscribed_answer_ids: @subscribed_answer_ids - if @more_data_available .d-flex.justify-content-center.justify-content-sm-start#paginator diff --git a/app/views/user/show.turbo_stream.haml b/app/views/user/show.turbo_stream.haml index a3477c47..ae7889ad 100644 --- a/app/views/user/show.turbo_stream.haml +++ b/app/views/user/show.turbo_stream.haml @@ -1,6 +1,6 @@ = turbo_stream.append "answers" do - @answers.each do |a| - = render "answerbox", a:, subscribed_answer_ids: + = render "answerbox", a: = turbo_stream.update "paginator" do - if @more_data_available From 4221f8cee900317eb175b29a35f46f3d75371475 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Wed, 29 Mar 2023 15:35:16 +0200 Subject: [PATCH 17/18] Fix incorrect user being notified and mutes not being respected --- app/models/subscription.rb | 9 ++++++++- spec/models/subscription_spec.rb | 28 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 spec/models/subscription_spec.rb diff --git a/app/models/subscription.rb b/app/models/subscription.rb index b7971a98..66520203 100644 --- a/app/models/subscription.rb +++ b/app/models/subscription.rb @@ -28,7 +28,14 @@ class Subscription < ApplicationRecord def notify(source, target) return nil if source.nil? || target.nil? - notifications = Subscription.where(answer: target).where.not(user: target.user).map do |s| + muted_by = Relationships::Mute.where(target: source.user).pluck(&:source_id) + + # As we will need to notify for each person subscribed, + # it's much faster to bulk insert than to use +Notification.notify+ + notifications = Subscription.where(answer: target) + .where.not(user: source.user) + .where.not(user_id: muted_by) + .map do |s| { target_id: source.id, target_type: Comment, recipient_id: s.user_id, new: true, type: Notification::Commented } end diff --git a/spec/models/subscription_spec.rb b/spec/models/subscription_spec.rb new file mode 100644 index 00000000..eac76a29 --- /dev/null +++ b/spec/models/subscription_spec.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require "rails_helper" + +describe Subscription do + describe "singleton object" do + describe "#notify" do + subject { Subscription.notify(source, target) } + + context "answer with one comment" do + let(:answer_author) { FactoryBot.create(:user) } + let(:answer) { FactoryBot.create(:answer, user: answer_author) } + let(:commenter) { FactoryBot.create(:user) } + let!(:comment) { FactoryBot.create(:comment, answer:, user: commenter) } + let(:source) { comment } + let(:target) { answer } + + it "notifies the target about source" do + # The method we're testing here is already called the +after_create+ of +Comment+ so there already is a notification + expect { subject }.to change { Notification.count }.from(1).to(2) + created = Notification.order(:created_at).first! + expect(created.target).to eq(comment) + expect(created.recipient).to eq(answer_author) + end + end + end + end +end From 142a31f6552afb0f37b55c56f8ec96b0661d6929 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Tue, 11 Apr 2023 11:06:34 +0200 Subject: [PATCH 18/18] Set `subscribed_answer_ids` in answerbox when user is not set --- app/views/application/_answerbox.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/application/_answerbox.html.haml b/app/views/application/_answerbox.html.haml index 2064909e..b84a5f17 100644 --- a/app/views/application/_answerbox.html.haml +++ b/app/views/application/_answerbox.html.haml @@ -21,7 +21,7 @@ .answerbox__answer-date = link_to(raw(t("time.distance_ago", time: time_tooltip(a))), answer_path(a.user.screen_name, a.id), data: { selection_hotkey: "l" }) .col-md-6.d-flex.d-md-block.answerbox__actions - = render "answerbox/actions", a:, display_all: + = render "answerbox/actions", a:, display_all:, subscribed_answer_ids: - else .row .col-md-6.text-start.text-muted