Class: API::V1::ConversationsController

Inherits:
APIController
  • Object
show all
Defined in:
app/controllers/faalis/api/v1/conversations_controller.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) conversation (private)



97
98
99
# File 'app/controllers/faalis/api/v1/conversations_controller.rb', line 97

def conversation
  @conversation ||= mailbox.conversations.find(params[:id])
end

- (Object) conversation_params(*keys) (private)



101
102
103
# File 'app/controllers/faalis/api/v1/conversations_controller.rb', line 101

def conversation_params(*keys)
  fetch_params(:conversation, *keys)
end

- (Object) create



8
9
10
11
12
13
14
15
16
17
# File 'app/controllers/faalis/api/v1/conversations_controller.rb', line 8

def create
  #binding.pry
  recipient_emails = message_params(:recipients).split(',')
  recipients = User.where(email: recipient_emails).all

  @conversation = current_user.
    send_message(recipients, *message_params(:body, :subject)).conversation

  respond_with(@conversation)
end

- (Object) destroy



41
42
43
44
45
46
47
48
49
# File 'app/controllers/faalis/api/v1/conversations_controller.rb', line 41

def destroy
  ids = params[:id].split(",")
  ids.each do |id|
    conversation = current_user.mailbox.conversations.find(params[:id])
    current_user.mark_as_deleted conversation
    #conversation.mark_as_deleted(current_user)
  end
  respond_with
end

- (Object) fetch_params(key, *subkeys) (private)



109
110
111
112
113
114
115
116
117
118
# File 'app/controllers/faalis/api/v1/conversations_controller.rb', line 109

def fetch_params(key, *subkeys)
  params[key].instance_eval do
    case subkeys.size
    when 0 then self
    when 1 then
      self[subkeys.first]
    else subkeys.map{|k| self[k] }
    end
  end
end

- (Object) index



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/controllers/faalis/api/v1/conversations_controller.rb', line 51

def index
  if params[:box] == "inbox"
    box = "inbox"
  elsif params[:box] == "sentbox"
    box = "sentbox"
  elsif params[:box] == "trash"
    box = "trash"
  else
    respond_to do |f|
      f.any { head :not_found }
    end
    returng
  end
  # puts current_user.mailbox.sent.to_json
  @mailbox ||= current_user.mailbox.send(box.to_sym)
  respond_with @mailbox
end

- (Object) mailbox (private)



92
93
94
# File 'app/controllers/faalis/api/v1/conversations_controller.rb', line 92

def mailbox
  @mailbox ||= current_user.mailbox
end

- (Object) message_params(*keys) (private)



105
106
107
# File 'app/controllers/faalis/api/v1/conversations_controller.rb', line 105

def message_params(*keys)
  fetch_params(:message, *keys)
end

- (Object) reply



19
20
21
22
# File 'app/controllers/faalis/api/v1/conversations_controller.rb', line 19

def reply
  @conversation = current_user.reply_to_conversation(conversation, *message_params(:body, :subject))
  respond_with(@conversation)
end

- (Object) show



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/controllers/faalis/api/v1/conversations_controller.rb', line 70

def show
  #def conversation
  @conversations ||= current_user.mailbox.conversations.find(params[:id])
  @current_user = current_user
  #      @conversation = {}
  #      conversations.each do |conversation|
  #        tmp = {
  #          :receipts => conversation.receipts,
  #          :body => conversation.messages.body,
  #          :is_read => conversation.is_read,
  #          :trashed => conversation.trashed,
  #          :deleted => conversation.deleted,
  #          :recipients => conversation.recipients
  #        }
  #unless @conversation.include? conversation.id
  #  @conversation[conversation.id] = tmp
  #end
  #end

end

- (Object) trash



24
25
26
27
28
29
30
# File 'app/controllers/faalis/api/v1/conversations_controller.rb', line 24

def trash
  ids = params[:id].split(",")
  ids.each do |id|
    conversation = current_user.mailbox.conversations.find(params[:id])
    conversation.move_to_trash(current_user)
  end
end

- (Object) untrash



32
33
34
35
36
37
38
39
# File 'app/controllers/faalis/api/v1/conversations_controller.rb', line 32

def untrash
  ids = params[:id].split(",")
  ids.each do |id|
    conversation = current_user.mailbox.conversations.find(params[:id])
    conversation.untrash(current_user)
  end

end