Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump version to 5.5 LTS #113

Merged
merged 5 commits into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/settings/privacy_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def update
private

def account_params
params.require(:account).permit(:discoverable, :unlocked, :indexable, :show_collections, :dissubscribable, settings: UserSettings.keys)
params.require(:account).permit(:discoverable, :unlocked, :indexable, :show_collections, settings: UserSettings.keys)
end

def set_account
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/settings/privacy_extra_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def update
private

def account_params
params.require(:account).permit(settings: UserSettings.keys)
params.require(:account).permit(:dissubscribable, settings: UserSettings.keys)
end

def set_account
Expand Down
1 change: 1 addition & 0 deletions app/lib/feed_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ def unmerge_tag_from_home(from_tag, into_account)
# also tagged with another followed hashtag or from a followed user
scope = from_tag.statuses
.where(id: timeline_status_ids)
.where.not(account: into_account)
.where.not(account: into_account.following)
.tagged_with_none(TagFollow.where(account: into_account).pluck(:tag_id))

Expand Down
8 changes: 8 additions & 0 deletions app/models/emoji_reaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ def remote_custom_emoji?
custom_emoji? && !custom_emoji.local?
end

def sign?
true
end

def object_type
:emoji_reaction
end

private

def refresh_cache
Expand Down
3 changes: 3 additions & 0 deletions app/services/emoji_react_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ def call(account, status, name)
raise Mastodon::ValidationError, I18n.t('reactions.errors.duplication') unless emoji_reaction.nil?

shortcode, domain = name.split('@')
domain = nil if TagManager.instance.local_domain?(domain)
custom_emoji = CustomEmoji.find_by(shortcode: shortcode, domain: domain)
return if domain.present? && !EmojiReaction.exists?(status: status, custom_emoji: custom_emoji)

emoji_reaction = EmojiReaction.create!(account: account, status: status, name: shortcode, custom_emoji: custom_emoji)

status.touch # rubocop:disable Rails/SkipsModelValidations
Expand Down
3 changes: 0 additions & 3 deletions app/views/settings/privacy/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
.fields-group
= ff.input :noai, wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_noai'), hint: I18n.t('simple_form.hints.defaults.setting_noai')

.fields-group
= f.input :dissubscribable, as: :boolean, wrapper: :with_label, kmyblue: true, hint: t('simple_form.hints.defaults.dissubscribable')

.fields-group
= f.input :unlocked, as: :boolean, wrapper: :with_label

Expand Down
6 changes: 6 additions & 0 deletions app/views/settings/privacy_extra/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
.fields-group
= ff.input :link_preview, wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_link_preview'), hint: I18n.t('simple_form.hints.defaults.setting_link_preview')

.fields-group
= f.input :dissubscribable, as: :boolean, wrapper: :with_label, kmyblue: true, hint: t('simple_form.hints.defaults.dissubscribable')

.fields-group
= ff.input :allow_quote, wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_allow_quote'), hint: false

%h4= t 'privacy_extra.stop_deliver'

%p.lead= t('privacy_extra.stop_deliver_hint_html')
Expand Down
2 changes: 1 addition & 1 deletion lib/mastodon/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def kmyblue_major
end

def kmyblue_minor
4
5
end

def kmyblue_flag
Expand Down
7 changes: 7 additions & 0 deletions spec/fabricators/emoji_reaction_fabricator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

Fabricator(:emoji_reaction) do
account { Fabricate.build(:account) }
status { Fabricate.build(:status) }
name '😀'
end
38 changes: 38 additions & 0 deletions spec/lib/feed_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,44 @@
end
end

describe '#unmerge_tag_from_home' do
let(:receiver) { Fabricate(:account) }
let(:tag) { Fabricate(:tag) }

it 'leaves a tagged status' do
status = Fabricate(:status)
status.tags << tag
described_class.instance.push_to_home(receiver, status)

described_class.instance.unmerge_tag_from_home(tag, receiver)

expect(redis.zrange("feed:home:#{receiver.id}", 0, -1)).to_not include(status.id.to_s)
end

it 'remains a tagged status written by receiver\'s followee' do
followee = Fabricate(:account)
receiver.follow!(followee)

status = Fabricate(:status, account: followee)
status.tags << tag
described_class.instance.push_to_home(receiver, status)

described_class.instance.unmerge_tag_from_home(tag, receiver)

expect(redis.zrange("feed:home:#{receiver.id}", 0, -1)).to include(status.id.to_s)
end

it 'remains a tagged status written by receiver' do
status = Fabricate(:status, account: receiver)
status.tags << tag
described_class.instance.push_to_home(receiver, status)

described_class.instance.unmerge_tag_from_home(tag, receiver)

expect(redis.zrange("feed:home:#{receiver.id}", 0, -1)).to include(status.id.to_s)
end
end

describe '#clear_from_home' do
let(:account) { Fabricate(:account) }
let(:followed_account) { Fabricate(:account) }
Expand Down
139 changes: 139 additions & 0 deletions spec/services/emoji_react_service_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe EmojiReactService, type: :service do
subject do
described_class.new.call(sender, status, name)
EmojiReaction.where(status: status, account: sender)
end

let(:name) { '😀' }
let(:sender) { Fabricate(:user).account }
let(:author) { Fabricate(:user).account }
let(:status) { Fabricate(:status, account: author) }

it 'with a simple case' do
expect(subject.count).to eq 1
expect(subject.first.name).to eq '😀'
expect(subject.first.custom_emoji_id).to be_nil
end

context 'with name duplication on same account' do
before { Fabricate(:emoji_reaction, status: status, name: '😀') }

it 'react with emoji' do
expect(subject.count).to eq 1
expect(subject.first.name).to eq '😀'
end
end

context 'when multiple reactions by same account' do
let(:name) { '😂' }

before { Fabricate(:emoji_reaction, account: sender, status: status, name: '😀') }

it 'react with emoji' do
expect(subject.count).to eq 2
expect(subject.pluck(:name)).to contain_exactly('😀', '😂')
end
end

context 'when already reacted by other account' do
let(:name) { '😂' }

before { Fabricate(:emoji_reaction, status: status, name: '😀') }

it 'react with emoji' do
expect(subject.count).to eq 1
expect(subject.pluck(:name)).to contain_exactly('😂')
end
end

context 'when already reacted same emoji by other account', :tag do
before { Fabricate(:emoji_reaction, status: status, name: '😀') }

it 'react with emoji' do
expect(subject.count).to eq 1
expect(subject.first.name).to eq '😀'
end
end

context 'when over limit' do
let(:name) { '🚗' }

before do
Fabricate(:emoji_reaction, status: status, account: sender, name: '😀')
Fabricate(:emoji_reaction, status: status, account: sender, name: '😎')
Fabricate(:emoji_reaction, status: status, account: sender, name: '🐟')
end

it 'react with emoji' do
expect { subject.count }.to raise_error Mastodon::ValidationError

reactions = EmojiReaction.where(status: status, account: sender).pluck(:name)
expect(reactions.size).to eq 3
expect(reactions).to contain_exactly('😀', '😎', '🐟')
end
end

context 'with custom emoji of local' do
let(:name) { 'ohagi' }
let!(:custom_emoji) { Fabricate(:custom_emoji, shortcode: 'ohagi') }

it 'react with emoji' do
expect(subject.count).to eq 1
expect(subject.first.name).to eq 'ohagi'
expect(subject.first.custom_emoji.id).to eq custom_emoji.id
end
end

context 'with custom emoji but not existing' do
let(:name) { 'ohagi' }

it 'react with emoji' do
expect { subject.count }.to raise_error ActiveRecord::RecordInvalid
expect(EmojiReaction.exists?(status: status, account: sender, name: 'ohagi')).to be false
end
end

context 'with custom emoji of remote' do
let(:name) { '[email protected]' }
let!(:custom_emoji) { Fabricate(:custom_emoji, shortcode: 'ohagi', domain: 'foo.bar', uri: 'https://foo.bar/emoji/ohagi') }

before { Fabricate(:emoji_reaction, status: status, name: 'ohagi', custom_emoji: custom_emoji) }

it 'react with emoji' do
expect(subject.count).to eq 1
expect(subject.first.name).to eq 'ohagi'
expect(subject.first.custom_emoji.id).to eq custom_emoji.id
end
end

context 'with custom emoji of remote without existing one' do
let(:name) { '[email protected]' }

before { Fabricate(:custom_emoji, shortcode: 'ohagi', domain: 'foo.bar', uri: 'https://foo.bar/emoji/ohagi') }

it 'react with emoji' do
expect(subject.count).to eq 0
end
end

context 'with custom emoji of remote but local has same name emoji' do
let(:name) { '[email protected]' }
let!(:custom_emoji) { Fabricate(:custom_emoji, shortcode: 'ohagi', domain: 'foo.bar', uri: 'https://foo.bar/emoji/ohagi') }

before do
Fabricate(:custom_emoji, shortcode: 'ohagi', domain: nil)
Fabricate(:emoji_reaction, status: status, name: 'ohagi', custom_emoji: custom_emoji)
end

it 'react with emoji' do
expect(subject.count).to eq 1
expect(subject.first.name).to eq 'ohagi'
expect(subject.first.custom_emoji.id).to eq custom_emoji.id
expect(subject.first.custom_emoji.domain).to eq 'foo.bar'
end
end
end