Add notes to /api/v1/accounts/:id/mute (#193)

This commit is contained in:
David Yip 2018-01-25 22:38:02 -06:00
parent 47ec2eff65
commit 27f8d2c739
No known key found for this signature in database
GPG Key ID: 7DA0036508FCC0CC
5 changed files with 19 additions and 6 deletions

View File

@ -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

View File

@ -93,6 +93,8 @@ module AccountInteractions
if mute.hide_notifications? != notifications
mute.update!(hide_notifications: notifications)
end
mute
end
def mute_conversation!(conversation)

View File

@ -12,4 +12,6 @@
class Glitch::Note < ApplicationRecord
belongs_to :target, polymorphic: true
alias_attribute :text, :note
end

View File

@ -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

View File

@ -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