diff --git a/app/controllers/api/v1/accounts_controller.rb b/app/controllers/api/v1/accounts_controller.rb index 4e73e9e8b5..1929f4a8be 100644 --- a/app/controllers/api/v1/accounts_controller.rb +++ b/app/controllers/api/v1/accounts_controller.rb @@ -26,7 +26,7 @@ class Api::V1::AccountsController < Api::BaseController end def mute - MuteService.new.call(current_user.account, @account, notifications: params[:notifications]) + MuteService.new.call(current_user.account, @account, notifications: params[:notifications], note: params[:note]) render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships end diff --git a/app/models/concerns/account_interactions.rb b/app/models/concerns/account_interactions.rb index fdf35a4e3f..8aee103729 100644 --- a/app/models/concerns/account_interactions.rb +++ b/app/models/concerns/account_interactions.rb @@ -93,6 +93,8 @@ module AccountInteractions if mute.hide_notifications? != notifications mute.update!(hide_notifications: notifications) end + + mute end def mute_conversation!(conversation) diff --git a/app/models/glitch/note.rb b/app/models/glitch/note.rb index e437d99f15..2950a75af9 100644 --- a/app/models/glitch/note.rb +++ b/app/models/glitch/note.rb @@ -12,4 +12,6 @@ class Glitch::Note < ApplicationRecord belongs_to :target, polymorphic: true + + alias_attribute :text, :note end diff --git a/app/serializers/rest/relationship_serializer.rb b/app/serializers/rest/relationship_serializer.rb index 45bfd4d6e7..c805d6db7e 100644 --- a/app/serializers/rest/relationship_serializer.rb +++ b/app/serializers/rest/relationship_serializer.rb @@ -2,12 +2,17 @@ class REST::RelationshipSerializer < ActiveModel::Serializer attributes :id, :following, :showing_reblogs, :followed_by, :blocking, - :muting, :muting_notifications, :requested, :domain_blocking + :muting, :muting_notifications, :requested, :domain_blocking, + :note def id object.id.to_s end + def note + object.respond_to?(:note) ? object.note.text : nil + end + def following instance_options[:relationships].following[object.id] ? true : false end diff --git a/app/services/mute_service.rb b/app/services/mute_service.rb index 547b2efa1a..5b2462b01e 100644 --- a/app/services/mute_service.rb +++ b/app/services/mute_service.rb @@ -1,10 +1,14 @@ # frozen_string_literal: true class MuteService < BaseService - def call(account, target_account, notifications: nil) + def call(account, target_account, notifications: nil, note: nil) return if account.id == target_account.id - mute = account.mute!(target_account, notifications: notifications) - BlockWorker.perform_async(account.id, target_account.id) - mute + + ActiveRecord::Base.transaction do + mute = account.mute!(target_account, notifications: notifications) + mute.create_note!(note: note) if note + BlockWorker.perform_async(account.id, target_account.id) + mute + end end end