Skip to content

Commit

Permalink
Add the ability to change to a new circle by replying to a circle
Browse files Browse the repository at this point in the history
  • Loading branch information
noellabo committed Sep 5, 2020
1 parent 7013a22 commit 7b2ba61
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/javascript/mastodon/components/status_action_bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class StatusActionBar extends ImmutablePureComponent {
menu.push({ text: intl.formatMessage(status.get('bookmarked') ? messages.removeBookmark : messages.bookmark), action: this.handleBookmarkClick });
menu.push(null);

if (status.getIn(['account', 'id']) === me && status.get('visibility') === 'limited' && !status.get('in_reply_to_id')) {
if (status.getIn(['account', 'id']) === me && status.get('visibility') === 'limited' && status.get('circle_id')) {
menu.push({ text: intl.formatMessage(messages.showMemberList), action: this.handleMemberListClick });
menu.push(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class ActionBar extends React.PureComponent {
menu.push({ text: intl.formatMessage(status.get('pinned') ? messages.unpin : messages.pin), action: this.handlePinClick });
}

if (status.get('visibility') === 'limited' && !status.get('in_reply_to_id')) {
if (status.get('visibility') === 'limited' && status.get('circle_id')) {
menu.push({ text: intl.formatMessage(messages.showMemberList), action: this.handleMemberListClick });
}

Expand Down
23 changes: 20 additions & 3 deletions app/models/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Status < ApplicationRecord
include Cacheable
include StatusThreadingConcern
include RateLimitable
include Redisable

rate_limit by: :account, family: :statuses

Expand All @@ -42,6 +43,8 @@ class Status < ApplicationRecord
# will be based on current time instead of `created_at`
attr_accessor :override_timestamps

attr_accessor :circle

update_index('statuses#status', :proper)

enum visibility: [:public, :unlisted, :private, :direct, :limited], _suffix: :visibility
Expand Down Expand Up @@ -276,6 +279,7 @@ def decrement_count!(key)
before_validation :set_local, on: :create

after_create :set_poll_id
after_create :set_circle

class << self
def selectable_visibilities
Expand Down Expand Up @@ -467,10 +471,23 @@ def set_conversation

if reply? && !thread.nil?
self.in_reply_to_account_id = carried_over_reply_to_account_id
self.conversation_id = thread.conversation_id if conversation_id.nil?
elsif conversation_id.nil?
build_owned_conversation
end

if conversation_id.nil?
if reply? && !thread.nil? && circle.nil?
self.conversation_id = thread.conversation_id
else
build_owned_conversation
end
end
end

def set_circle
redis.setex(circle_id_key, 3.days.seconds, circle.id) if circle.present?
end

def circle_id_key
"statuses/#{id}/circle_id"
end

def carried_over_reply_to_account_id
Expand Down
2 changes: 1 addition & 1 deletion app/policies/status_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def update?
end

def show_mentions?
limited? && !reply? && owned?
limited? && owned? && (!reply? || record.thread.conversation_id != record.conversation_id)
end

private
Expand Down
6 changes: 3 additions & 3 deletions app/serializers/rest/status_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class REST::StatusSerializer < ActiveModel::Serializer
attribute :muted, if: :current_user?
attribute :bookmarked, if: :current_user?
attribute :pinned, if: :pinnable?
attribute :circle_id, if: :limited_owned_status?
attribute :circle_id, if: :limited_owned_parent_status?

attribute :content, unless: :source_requested?
attribute :text, if: :source_requested?
Expand Down Expand Up @@ -67,8 +67,8 @@ def limited
object.limited_visibility?
end

def limited_owned_status?
object.limited_visibility? && owned_status? && object.in_reply_to_id.nil?
def limited_owned_parent_status?
object.limited_visibility? && owned_status? && (!object.reply? || object.thread.conversation_id != object.conversation_id)
end

def circle_id
Expand Down
6 changes: 1 addition & 5 deletions app/services/post_status_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def process_status!

ProcessHashtagsService.new.call(@status)
ProcessMentionsService.new.call(@status, @circle)
redis.setex(circle_id_key, 3.days.seconds, @circle.id) if @circle.present?
end

def schedule_status!
Expand Down Expand Up @@ -119,10 +118,6 @@ def scheduled?
@scheduled_at.present?
end

def circle_id_key
"statuses/#{@status.id}/circle_id"
end

def idempotency_key
"idempotency:status:#{@account.id}:#{@options[:idempotency]}"
end
Expand Down Expand Up @@ -163,6 +158,7 @@ def status_attributes
sensitive: @sensitive,
spoiler_text: @options[:spoiler_text] || '',
visibility: @visibility,
circle: @circle,
language: language_from_option(@options[:language]) || @account.user&.setting_default_language&.presence || LanguageDetector.instance.detect(@text, @account),
application: @options[:application],
rate_limit: @options[:with_rate_limit],
Expand Down
4 changes: 1 addition & 3 deletions app/services/process_mentions_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ def call(status, circle = nil)
circle.accounts.find_each do |target_account|
status.mentions.create(silent: true, account: target_account)
end
end

if status.limited_visibility? && status.thread&.limited_visibility?
elsif status.limited_visibility? && status.thread&.limited_visibility?
# If we are replying to a local status, then we'll have the complete
# audience copied here, both local and remote. If we are replying
# to a remote status, only local audience will be copied. Then we
Expand Down

0 comments on commit 7b2ba61

Please sign in to comment.