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

Make autofollow_on_join_user configuration a list #8430

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from
35 changes: 23 additions & 12 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -442,28 +442,39 @@ def self.diaspora_id_host
end

def seed_aspects
self.aspects.create(:name => I18n.t('aspects.seed.family'))
self.aspects.create(:name => I18n.t('aspects.seed.friends'))
self.aspects.create(:name => I18n.t('aspects.seed.work'))
aq = self.aspects.create(:name => I18n.t('aspects.seed.acquaintances'))

if AppConfig.settings.autofollow_on_join?
begin
default_account = Person.find_or_fetch_by_identifier(AppConfig.settings.autofollow_on_join_user)
share_with(default_account, aq)
rescue DiasporaFederation::Discovery::DiscoveryError
logger.warn "Error auto-sharing with #{AppConfig.settings.autofollow_on_join_user}
aspects.create(name: I18n.t("aspects.seed.family"))
aspects.create(name: I18n.t("aspects.seed.friends"))
aspects.create(name: I18n.t("aspects.seed.work"))
acquaintances = aspects.create(name: I18n.t("aspects.seed.acquaintances"))

acquaintances.tap do |aq|
if AppConfig.settings.autofollow_on_join?
autofollow_user = AppConfig.settings.autofollow_on_join_user
autofollow_accounts = Array.wrap(AppConfig.settings.autofollow_on_join_accounts)
autofollow_accounts.push(autofollow_user) if autofollow_user.present?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if just adding the old autofollow_on_join_user to the new default value of autofollow_on_join_accounts is the correct thing to do. For podmins who didn't configure anything, nothing chnages, but podmins who manually set another account, it silently adds the HQ-account to the list (as it's the default value for the new setting), until they manually migrate their config to the new autofollow_on_join_accounts and decide if they want to include the HQ-account now (in addition to their account), or if they still want to keep it with only one account.

My expectations would have been, that if the old autofollow_on_join_user is set, it still behaves as it was before, so just following that one user. And only if the new autofollow_on_join_accounts is the only option used, it follows multiple users.

But maybe the behavior is fine, as this will be released in a major version with a big changelog entry, so we can expect podmins to read that and react accordingly if they don't want the HQ-Account to be added by default? 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with breaking things in major releases. It's not our fault if people don't read changelogs, and in this case, this seems like a worthy change.


begin
autofollow_accounts.uniq.each { |user_id| follow_account(user_id, aq) } if autofollow_accounts.present?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
autofollow_accounts.uniq.each { |user_id| follow_account(user_id, aq) } if autofollow_accounts.present?
autofollow_accounts.uniq.each { |user_id| follow_account(user_id, aq) }

Array.wrap will ensure it's an array already, the #push call above would already fail if it's not and each on an empty array is a noop. So I think we can do without the if condition :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved here: 25ae7a9.

rescue DiasporaFederation::Discovery::DiscoveryError
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we fold the rescue into the loop (or follow_account that is) perhaps? That is wouldn't we want to attempt to follow the remaining users regardless of anyone failing?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved here: 25ae7a9.

logger.warn "Error auto-sharing with #{AppConfig.settings.autofollow_on_join_user}
fix autofollow_on_join_user in configuration."
end
end
end
aq
end

def follow_account(account_id, aq)
abrahamparayil marked this conversation as resolved.
Show resolved Hide resolved
account = Person.find_or_fetch_by_identifier(account_id)
share_with(account, aq)
end

def send_welcome_message
return unless AppConfig.settings.welcome_message.enabled? && AppConfig.admins.account?

sender_username = AppConfig.admins.account.get
sender = User.find_by(username: sender_username)
return if sender.nil?

conversation = sender.build_conversation(
participant_ids: [sender.person.id, person.id],
subject: AppConfig.settings.welcome_message.subject.get,
Expand Down
2 changes: 1 addition & 1 deletion config/defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ defaults:
enable_registrations: true
enable_local_posts_stream: 'disabled'
autofollow_on_join: true
autofollow_on_join_user: 'hq@pod.diaspora.software'
autofollow_on_join_accounts: ['hq@pod.diaspora.software']
welcome_message:
enabled: false
subject: 'Welcome Message'
Expand Down
11 changes: 6 additions & 5 deletions config/diaspora.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,12 @@
## follow an account upon creation.
#autofollow_on_join = true

## Auto-follow account (default="hq@pod.diaspora.software")
## The diaspora* HQ account keeps users up to date with news about Diaspora.
## If you set another auto-follow account (for example your podmin account),
## please consider resharing diaspora* HQ's posts for your pod's users!
#autofollow_on_join_user = "hq@pod.diaspora.software"
## Auto-follow accounts (default=["hq@pod.diaspora.software"])
## A list of accounts to auto-follow when a user joins the pod. By default
## the user follows the the diaspora* HQ account which keeps users up to
## date with news about Diaspora. Feel free to add your podmin account to
## the list.
#autofollow_on_join_accounts= ["hq@pod.diaspora.software"]

## Liberapay.com is a free platform which allow donations like patreon
## Set your username to include your Liberapay button
Expand Down
9 changes: 6 additions & 3 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -797,10 +797,13 @@
context "with autofollow sharing enabled" do
it "should start sharing with autofollow account" do
AppConfig.settings.autofollow_on_join = true
person = FactoryBot.build(:person)
AppConfig.settings.autofollow_on_join_user = person.diaspora_handle
person_one = FactoryBot.build(:person)
person_two = FactoryBot.build(:person)
AppConfig.settings.autofollow_on_join_accounts = [person_one.diaspora_handle]
AppConfig.settings.autofollow_on_join_user = person_two.diaspora_handle

expect(Person).to receive(:find_or_fetch_by_identifier).with(person.diaspora_handle).and_return(person)
expect(Person).to receive(:find_or_fetch_by_identifier).with(person_one.diaspora_handle).and_return(person_one)
abrahamparayil marked this conversation as resolved.
Show resolved Hide resolved
expect(Person).to receive(:find_or_fetch_by_identifier).with(person_two.diaspora_handle).and_return(person_two)
abrahamparayil marked this conversation as resolved.
Show resolved Hide resolved
user.seed_aspects
end
end
Expand Down