app/commands/thredded/autofollow_users.rb
def auto_followers
      u = Thredded.user_class.arel_table
      u_pkey = u[Thredded.user_class.primary_key]
      up = Thredded::UserPreference.arel_table
      ump = Thredded::UserMessageboardPreference.arel_table
      coalesce = [
        ump[:auto_follow_topics],
        up[:auto_follow_topics],
      ]
      coalesce << Arel::Nodes::Quoted.new(true) if Thredded::UserPreference.column_defaults['auto_follow_topics']
      Thredded.user_class
        .select(Thredded.user_class.primary_key)
        .joins(
          u.join(up, Arel::Nodes::OuterJoin)
            .on(up[:user_id].eq(u_pkey))
            .join(ump, Arel::Nodes::OuterJoin)
            .on(ump[:user_id].eq(u_pkey).and(ump[:messageboard_id].eq(post.messageboard_id)))
            .join_sources
        ).where(Arel::Nodes::NamedFunction.new('COALESCE', coalesce).eq(true))
    end
def auto_followers
      u = Thredded.user_class.arel_table
      u_pkey = u[Thredded.user_class.primary_key]
      up = Thredded::UserPreference.arel_table
      ump = Thredded::UserMessageboardPreference.arel_table
      coalesce = [
        ump[:auto_follow_topics],
        up[:auto_follow_topics],
      ]
      coalesce << Arel::Nodes::Quoted.new(true) if Thredded::UserPreference.column_defaults['auto_follow_topics']
      Thredded.user_class
        .select(Thredded.user_class.primary_key)
        .joins(
          u.join(up, Arel::Nodes::OuterJoin)
            .on(up[:user_id].eq(u_pkey))
            .join(ump, Arel::Nodes::OuterJoin)
            .on(ump[:user_id].eq(u_pkey).and(ump[:messageboard_id].eq(post.messageboard_id)))
            .join_sources
        ).where(Arel::Nodes::NamedFunction.new('COALESCE', coalesce).eq(true))
    end
Returns the users that have:

    COALESCE(
      `user_messageboard_preferences`.`auto_follow_topics`,
      `user_preferences`.`auto_follow_topics`,
      default for `user_preferences`.`auto_follow_topics`
    ) = true

 @return [Enumerable<Thredded.user_class>]