From e9f9309ddc640960ffe4e80c960a536d77b133e7 Mon Sep 17 00:00:00 2001 From: yana-gi Date: Sun, 5 Sep 2021 15:13:13 +0900 Subject: [PATCH 01/25] =?UTF-8?q?Following=E3=83=86=E3=83=BC=E3=83=96?= =?UTF-8?q?=E3=83=AB=E3=81=ABwatch=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 現行のフォローは自動でWatchされるため、defaultをtrueに設定 --- db/migrate/20210905061726_add_watch_to_followings.rb | 5 +++++ db/schema.rb | 1 + 2 files changed, 6 insertions(+) create mode 100644 db/migrate/20210905061726_add_watch_to_followings.rb diff --git a/db/migrate/20210905061726_add_watch_to_followings.rb b/db/migrate/20210905061726_add_watch_to_followings.rb new file mode 100644 index 00000000000..89582da1cf6 --- /dev/null +++ b/db/migrate/20210905061726_add_watch_to_followings.rb @@ -0,0 +1,5 @@ +class AddWatchToFollowings < ActiveRecord::Migration[6.1] + def change + add_column :followings, :watch, :boolean, default: true, null: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 04d8c172c90..7df974ba33e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -173,6 +173,7 @@ t.integer "followed_id" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false + t.boolean "watch", default: true, null: false t.index ["followed_id"], name: "index_followings_on_followed_id" t.index ["follower_id", "followed_id"], name: "index_followings_on_follower_id_and_followed_id", unique: true t.index ["follower_id"], name: "index_followings_on_follower_id" From 4b348e8aac63f160b5c79a7b0e4154cb4f7a07f8 Mon Sep 17 00:00:00 2001 From: yana-gi Date: Sun, 5 Sep 2021 18:13:23 +0900 Subject: [PATCH 02/25] =?UTF-8?q?watch=3Dfalse=E3=81=AE=E5=A0=B4=E5=90=88?= =?UTF-8?q?=E3=80=81=E8=87=AA=E5=8B=95=E7=9A=84=E3=81=ABWatch=E3=81=97?= =?UTF-8?q?=E3=81=AA=E3=81=84=E3=82=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/followings_controller.rb | 3 ++- app/models/report_callbacks.rb | 2 +- app/models/user.rb | 8 +++++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/followings_controller.rb b/app/controllers/api/followings_controller.rb index c88af55e8ac..f1018da03b9 100644 --- a/app/controllers/api/followings_controller.rb +++ b/app/controllers/api/followings_controller.rb @@ -5,7 +5,8 @@ class API::FollowingsController < API::BaseController def create user = User.find(params[:id]) - if current_user.follow(user) + watch = params[:watch] == 'true' + if current_user.follow(user, watch) render json: { id: user.id } else head :bad_request diff --git a/app/models/report_callbacks.rb b/app/models/report_callbacks.rb index d7f23b41dcc..aa4d556f53d 100644 --- a/app/models/report_callbacks.rb +++ b/app/models/report_callbacks.rb @@ -52,7 +52,7 @@ def notify_advisers(report) def notify_followers(report) report.user.followers.each do |follower| NotificationFacade.following_report(report, follower) - create_following_watch(report, follower) + create_following_watch(report, follower) if follower.auto_watching?(report.user) end end diff --git a/app/models/user.rb b/app/models/user.rb index fdfc9c0030b..c13955abdb1 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -514,8 +514,10 @@ def active_practice active_practices.first.id end - def follow(other_user) + def follow(other_user, watch) following << other_user + following_row = Following.find_by(follower_id: self, followed_id: other_user) + following_row.update(watch: watch) end def unfollow(other_user) @@ -526,6 +528,10 @@ def following?(other_user) following.include?(other_user) end + def auto_watching?(other_user) + Following.find_by(follower_id: self, followed_id: other_user).watch + end + def completed_all_practices?(category) category.practices.size == completed_practices_size(category) end From 24867f0e8bb0783e5b355499c3397d34c4bd01a9 Mon Sep 17 00:00:00 2001 From: yana-gi Date: Sun, 5 Sep 2021 18:31:55 +0900 Subject: [PATCH 03/25] =?UTF-8?q?Following.watch=E3=82=92=E5=88=87?= =?UTF-8?q?=E3=82=8A=E6=9B=BF=E3=81=88=E3=82=89=E3=82=8C=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/followings_controller.rb | 10 ++++++++++ app/models/user.rb | 6 +++++- config/routes.rb | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/followings_controller.rb b/app/controllers/api/followings_controller.rb index f1018da03b9..0ba4fa2a104 100644 --- a/app/controllers/api/followings_controller.rb +++ b/app/controllers/api/followings_controller.rb @@ -13,6 +13,16 @@ def create end end + def update + user = User.find(params[:id]) + watch = params[:watch] == 'true' + if current_user.change_watching(user, watch) + head :no_content + else + head :bad_request + end + end + def destroy user = User.find(params[:id]) if current_user.unfollow(user) diff --git a/app/models/user.rb b/app/models/user.rb index c13955abdb1..d083c7e1f01 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -516,8 +516,12 @@ def active_practice def follow(other_user, watch) following << other_user + change_watching(other_user, watch) + end + + def change_watching(other_user, watch) following_row = Following.find_by(follower_id: self, followed_id: other_user) - following_row.update(watch: watch) + following_row.update!(watch: watch) end def unfollow(other_user) diff --git a/config/routes.rb b/config/routes.rb index 8f05290289f..bc0f9d525ec 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -58,7 +58,7 @@ resources :tags, only: %i(index) resources :pages, only: %i(update) resources :questions, only: %i(show update) - resources :followings, only: %i(create destroy) + resources :followings, only: %i(create update destroy) namespace :products do resources :unchecked, only: %i(index) resources :not_responded, only: %i(index) From 50a49ed61938921438ea8f1be3069ebddc932566 Mon Sep 17 00:00:00 2001 From: yana-gi Date: Tue, 7 Sep 2021 12:07:04 +0900 Subject: [PATCH 04/25] =?UTF-8?q?=E3=83=93=E3=83=A5=E3=83=BC=E5=81=B4?= =?UTF-8?q?=E3=81=A7=E3=83=95=E3=82=A9=E3=83=AD=E3=83=BC=E3=81=A7=E3=81=8D?= =?UTF-8?q?=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/following.js | 4 +++- app/javascript/following.vue | 8 +++++--- app/javascript/user.vue | 6 +++++- app/models/user.rb | 2 +- app/views/api/users/_list_user.json.jbuilder | 1 + app/views/users/show.html.slim | 2 +- 6 files changed, 16 insertions(+), 7 deletions(-) diff --git a/app/javascript/following.js b/app/javascript/following.js index 893f7113574..284d7ae546e 100644 --- a/app/javascript/following.js +++ b/app/javascript/following.js @@ -8,13 +8,15 @@ document.addEventListener('DOMContentLoaded', () => { const following = followings[i] const isFollowing = following.getAttribute('data-is-following') const userId = following.getAttribute('data-user-id') + const isWatching = following.getAttribute('data-is-watching') new Vue({ render: (h) => h(Following, { props: { isFollowing: isFollowing === 'true', - userId: Number(userId) + userId: Number(userId), + isWatching: isWatching === 'true', } }) }).$mount('.js-following') diff --git a/app/javascript/following.vue b/app/javascript/following.vue index 42cfd66bd0b..d31021c9a0c 100644 --- a/app/javascript/following.vue +++ b/app/javascript/following.vue @@ -3,7 +3,8 @@ button.card-main-actions__action.a-button.is-sm.is-block( :class='following ? "is-danger" : "is-secondary"', @click='followOrUnfollow' ) - | {{ buttonLabel }} + | {{ isWatching ? "✔︎" : "" }} + | コメントあり - + From 665f94e9e2ca5674b14c6cd873131daf0ee2881d Mon Sep 17 00:00:00 2001 From: yana-gi Date: Tue, 14 Sep 2021 16:46:37 +0900 Subject: [PATCH 09/25] =?UTF-8?q?=E3=83=95=E3=82=A9=E3=83=AD=E3=83=BC?= =?UTF-8?q?=E3=83=9C=E3=82=BF=E3=83=B3=E3=81=AE=E8=A1=A8=E7=A4=BA=E3=82=92?= =?UTF-8?q?=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/following.vue | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/javascript/following.vue b/app/javascript/following.vue index 60c64c83240..a946c89f341 100644 --- a/app/javascript/following.vue +++ b/app/javascript/following.vue @@ -1,7 +1,7 @@