Class: ConversationsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/conversations_controller.rb

Instance Method Summary (collapse)

Methods inherited from ApplicationController

#after_sign_in_path_for, #clear_gc_stats, #ensure_http_referer_is_set, #ensure_page, #grammatical_gender, #redirect_unless_admin, #set_git_header, #set_grammatical_gender, #set_header_data, #set_invites, #set_locale, #which_action_and_user

Instance Method Details

- (Object) create



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/conversations_controller.rb', line 24

def create
  person_ids = Contact.where(:id => params[:contact_ids].split(',')).map! do |contact|
    contact.person_id
  end

  params[:conversation][:participant_ids] = person_ids | [current_user.person.id]
  params[:conversation][:author] = current_user.person

  if @conversation = Conversation.create(params[:conversation])
    Postzord::Dispatch.new(current_user, @conversation).post

    flash[:notice] = I18n.t('conversations.create.sent')
    if params[:profile]
      redirect_to person_path(params[:profile])
    else
      redirect_to conversations_path(:conversation_id => @conversation.id)
    end
  end
end

- (Object) index



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/conversations_controller.rb', line 6

def index
  @conversations = Conversation.joins(:conversation_visibilities).where(
    :conversation_visibilities => {:person_id => current_user.person.id}).paginate(
    :page => params[:page], :per_page => 15, :order => 'updated_at DESC')

  @visibilities = ConversationVisibility.where(:person_id => current_user.person.id).paginate(
    :page => params[:page], :per_page => 15, :order => 'updated_at DESC')

  @unread_counts = {}
  @visibilities.each { |v| @unread_counts[v.conversation_id] = v.unread }

  @authors = {}
  @conversations.each { |c| @authors[c.id] = c.last_author }

  @conversation = Conversation.joins(:conversation_visibilities).where(
    :conversation_visibilities => {:person_id => current_user.person.id, :conversation_id => params[:conversation_id]}).first
end

- (Object) new



58
59
60
61
62
63
64
65
66
67
# File 'app/controllers/conversations_controller.rb', line 58

def new
  all_contacts_and_ids = Contact.connection.execute(current_user.contacts.joins(:person => :profile
    ).select("contacts.id, profiles.first_name, profiles.last_name, people.diaspora_handle").to_sql).map do |r|
    {:value => r[0],
     :name => Person.name_from_attrs(r[1], r[2], r[3]).gsub(/(")/, "'")}
  end
  @contacts_json = all_contacts_and_ids.to_json.gsub!(/(")/, '\\"')
  @contact = current_user.contacts.find(params[:contact_id]) if params[:contact_id]
  render :layout => false
end

- (Object) show



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/conversations_controller.rb', line 44

def show
  if @conversation = Conversation.joins(:conversation_visibilities).where(:id => params[:id],
                                                                          :conversation_visibilities => {:person_id => current_user.person.id}).first
    if @visibility = ConversationVisibility.where(:conversation_id => params[:id], :person_id => current_user.person.id).first
      @visibility.unread = 0
      @visibility.save
    end

    respond_with @conversation
  else
    redirect_to conversations_path
  end
end