diaspora/lib/stream/multi.rb
Jonne Haß 2a4db54db9 New configuration system
* Throw away old system
* Add new system
* Add new example files
* Replace all calls
* add the most important docs
* Add Specs
* rename disable_ssl_requirement to require_ssl
* cloudfiles isn't used/called in our code
* since community_spotlight.list is only used as enable flag replace it with such one and remove all legacy and irelevant codepaths around it
* die if session secret is unset and on heroku
* First basic infrastructure for version information
2012-09-26 20:19:37 +02:00

82 lines
2.1 KiB
Ruby

class Stream::Multi < Stream::Base
# @return [String] URL
def link(opts)
Rails.application.routes.url_helpers.stream_path(opts)
end
# @return [String]
def title
I18n.t('streams.multi.title')
end
# @return [String]
def contacts_title
I18n.t('streams.multi.contacts_title')
end
def posts
@posts ||= ::EvilQuery::MultiStream.new(user, order, max_time, include_community_spotlight?).make_relation!
end
#emits an enum of the groups which the post appeared
# :spotlight, :aspects, :tags, :mentioned
def post_from_group(post)
streams_included.collect do |source|
is_in?(source, post)
end.compact
end
private
def publisher_opts
if welcome?
{:open => true, :prefill => publisher_prefill, :public => true}
else
super
end
end
# Generates the prefill for the publisher
#
# @return [String]
def publisher_prefill
prefill = I18n.t("shared.publisher.new_user_prefill.hello", :new_user_tag => I18n.t('shared.publisher.new_user_prefill.newhere'))
if self.user.followed_tags.size > 0
tag_string = self.user.followed_tags.map{|t| "##{t.name}"}.to_sentence
prefill << I18n.t("shared.publisher.new_user_prefill.i_like", :tags => tag_string)
end
if inviter = self.user.invited_by.try(:person)
prefill << I18n.t("shared.publisher.new_user_prefill.invited_by")
prefill << "@{#{inviter.name} ; #{inviter.diaspora_handle}}!"
end
prefill
end
# @return [Boolean]
def welcome?
self.user.getting_started
end
# @return [Array<Symbol>]
def streams_included
@streams_included ||= lambda do
array = [:mentioned, :aspects, :followed_tags]
array << :community_spotlight if include_community_spotlight?
array
end.call
end
# @return [Symbol]
def is_in?(sym, post)
if self.send("#{sym.to_s}_post_ids").find{|x| (x == post.id) || (x.to_s == post.id.to_s)}
"#{sym.to_s}_stream".to_sym
end
end
# @return [Boolean]
def include_community_spotlight?
AppConfig.environment.community_spotlight.enable? && user.show_community_spotlight_in_stream?
end
end