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 7.1 #114

Merged
merged 9 commits into from
Oct 15, 2023
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
25 changes: 25 additions & 0 deletions app/helpers/kmyblue_capabilities_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,29 @@ def fedibird_capabilities

capabilities
end

def capabilities_for_nodeinfo
capabilities = %i(
wide_emoji
status_reference
quote
kmyblue_quote
searchability
kmyblue_searchability
visibility_mutual
visibility_limited
kmyblue_antenna
kmyblue_bookmark_category
kmyblue_searchability_limited
kmyblue_circle_history
)

capabilities << :full_text_search if Chewy.enabled?
if Setting.enable_emoji_reaction
capabilities << :emoji_reaction
capabilities << :enable_wide_emoji_reaction
end

capabilities
end
end
2 changes: 1 addition & 1 deletion app/lib/activitypub/activity/follow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def request_follow_for_friend
friend.update!(passive_state: :pending, active_state: :idle, passive_follow_activity_id: @json['id'])
else
@friend = FriendDomain.new(domain: @account.domain, passive_state: :pending, passive_follow_activity_id: @json['id'])
@friend.initialize_inbox_url!
@friend.inbox_url = @json['inboxUrl'].presence || @friend.default_inbox_url
@friend.save!
end

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
4 changes: 2 additions & 2 deletions app/lib/status_reach_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,15 @@ def relay_inboxes

def friend_inboxes
if @status.public_visibility? || @status.public_unlisted_visibility? || (@status.unlisted_visibility? && (@status.public_searchability? || @status.public_unlisted_searchability?))
DeliveryFailureTracker.without_unavailable(FriendDomain.distributables.where(delivery_local: true).pluck(:inbox_url))
DeliveryFailureTracker.without_unavailable(FriendDomain.distributables.where(delivery_local: true).where.not(domain: AccountDomainBlock.where(account: @status.account).select(:domain)).pluck(:inbox_url))
else
[]
end
end

def nolocal_friend_inboxes
if @status.public_visibility?
DeliveryFailureTracker.without_unavailable(FriendDomain.distributables.where(delivery_local: false).pluck(:inbox_url))
DeliveryFailureTracker.without_unavailable(FriendDomain.distributables.where(delivery_local: false).where.not(domain: AccountDomainBlock.where(account: @status.account).select(:domain)).pluck(:inbox_url))
else
[]
end
Expand Down
8 changes: 4 additions & 4 deletions app/models/emoji_reaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ def custom_emoji?
custom_emoji.present?
end

def remote_custom_emoji?
custom_emoji? && !custom_emoji.local?
def sign?
true
end

def sign?
status&.distributable_friend?
def object_type
:emoji_reaction
end

private
Expand Down
11 changes: 5 additions & 6 deletions app/models/friend_domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,12 @@ def destroy_without_signal!
destroy!
end

def initialize_inbox_url!
self.inbox_url = default_inbox_url
end

private

def default_inbox_url
"https://#{domain}/inbox"
end

private

def delete_for_friend!
activity_id = ActivityPub::TagManager.instance.generate_uri_for(nil)
payload = Oj.dump(delete_follow_activity(activity_id))
Expand All @@ -118,6 +114,9 @@ def follow_activity(activity_id)
type: 'Follow',
actor: ActivityPub::TagManager.instance.uri_for(some_local_account),
object: ActivityPub::TagManager::COLLECTIONS[:public],

# Cannot use inbox_url method because this model also has inbox_url column
inboxUrl: "https://#{Rails.configuration.x.web_domain}/inbox",
}
end

Expand Down
2 changes: 1 addition & 1 deletion app/serializers/nodeinfo/serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def open_registrations

def metadata
{
features: fedibird_capabilities,
features: capabilities_for_nodeinfo,
}
end

Expand Down
4 changes: 3 additions & 1 deletion app/services/emoji_react_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,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 Expand Up @@ -62,7 +65,6 @@ def notify_to_followers(emoji_reaction)
status = emoji_reaction.status

return unless status.account.local?
return if emoji_reaction.remote_custom_emoji?

ActivityPub::RawDistributionWorker.perform_async(build_json(emoji_reaction), status.account_id)
end
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
3 changes: 3 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,9 @@
.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

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
0
1
end

def kmyblue_flag
Expand Down
20 changes: 20 additions & 0 deletions spec/lib/activitypub/activity/follow_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@
let!(:friend) { Fabricate(:friend_domain, domain: 'abc.com', passive_state: :idle) }
let!(:owner_user) { Fabricate(:user, role: UserRole.find_by(name: 'Owner')) }
let!(:patch_user) { Fabricate(:user, role: Fabricate(:user_role, name: 'OhagiOps', permissions: UserRole::FLAGS[:manage_federation])) }
let(:inbox_url) { nil }

let(:json) do
{
Expand All @@ -318,6 +319,7 @@
type: 'Follow',
actor: ActivityPub::TagManager.instance.uri_for(sender),
object: 'https://www.w3.org/ns/activitystreams#Public',
inboxUrl: inbox_url,
}.with_indifferent_access
end

Expand All @@ -343,6 +345,24 @@
end
end

context 'when no record and inbox_url is specified' do
let(:inbox_url) { 'https://ohagi.com/inbox' }

before do
friend.update(domain: 'def.com')
end

it 'marks the friend as pending' do
subject.perform

friend = FriendDomain.find_by(domain: 'abc.com')
expect(friend).to_not be_nil
expect(friend.they_are_pending?).to be true
expect(friend.passive_follow_activity_id).to eq 'foo'
expect(friend.inbox_url).to eq 'https://ohagi.com/inbox'
end
end

context 'when my server is pending' do
before do
friend.update(active_state: :pending)
Expand Down
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
12 changes: 12 additions & 0 deletions spec/lib/status_reach_finder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,18 @@
expect(subject.inboxes_for_friend).to_not include 'https://foo.bar/inbox'
end
end

context 'when distributable but domain blocked by account' do
before do
Fabricate(:account_domain_block, account: alice, domain: 'foo.bar')
Fabricate(:friend_domain, domain: 'foo.bar', inbox_url: 'https://foo.bar/inbox', passive_state: :accepted, pseudo_relay: true)
end

it 'send status' do
expect(subject.inboxes).to_not include 'https://foo.bar/inbox'
expect(subject.inboxes_for_friend).to_not include 'https://foo.bar/inbox'
end
end
end

context 'when it contains distributable friend server' do
Expand Down
1 change: 1 addition & 0 deletions spec/models/friend_domain_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
type: 'Follow',
actor: 'https://cb6e6126.ngrok.io/actor',
object: 'https://www.w3.org/ns/activitystreams#Public',
inboxUrl: 'https://cb6e6126.ngrok.io/inbox',
}))).to have_been_made.once
end
end
Expand Down
5 changes: 5 additions & 0 deletions spec/serializers/nodeinfo/serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,10 @@
it 'returns features' do
expect(serialization['metadata']['features']).to include 'emoji_reaction'
end

it 'returns nodeinfo own features' do
expect(serialization['metadata']['features']).to include 'quote'
expect(serialization['metadata']['features']).to_not include 'kmyblue_markdown'
end
end
end
4 changes: 4 additions & 0 deletions spec/serializers/rest/instance_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,9 @@
it 'returns fedibird_capabilities' do
expect(serialization['fedibird_capabilities']).to include 'emoji_reaction'
end

it 'returns api own fedibird_capabilities' do
expect(serialization['fedibird_capabilities']).to include 'kmyblue_markdown'
end
end
end
Loading