Class: API::V1::ConversationsController

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

Instance Method Summary collapse

Methods inherited from Faalis::APIController

allow_query_on, #allowed_fields, #authenticate_filter, #load_resource_by_query, #set_csrf_cookie_for_ng

Methods inherited from Faalis::ApplicationController

#set_locale

Instance Method Details

#createObject



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

#destroyObject



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

#indexObject



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

#replyObject



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

#showObject



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

#trashObject



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

#untrashObject



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