Class: WcoEmail::ConversationsController

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

Instance Method Summary collapse

Instance Method Details

#addtagObject

many tags to many convs



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

def addtag
  authorize! :addtag, WcoEmail::Conversation

  inbox = Wco::Tag.inbox
  outs = @convs.map do |conv|
    conv.tags.push @tags
    conv.tags.delete( inbox ) if params[:is_move]
    conv.save
  end
  flash_notice "Outcomes: #{outs}"

  render json: { status: 'ok' }
  # redirect_to request.referrer # || root_path
end

#editObject



25
26
27
28
# File 'app/controllers/wco_email/conversations_controller.rb', line 25

def edit
  @conversation = ::WcoEmail::Conversation.find( params[:id] )
  authorize! :edit, @conversation
end

#indexObject



30
31
32
33
# File 'app/controllers/wco_email/conversations_controller.rb', line 30

def index
  authorize! :index, WcoEmail::Conversation
  @conversations, @messages, @tag = WcoEmail::Conversation.load_conversations_messages_tag_by_params_and_profile( params, current_profile )
end

#mergeObject

merge conv1 into conv2, and delete conv1



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/wco_email/conversations_controller.rb', line 36

def merge
  authorize! :merge, WcoEmail::Conversation
  conv1 = WcoEmail::Conversation.find params[:id1]
  conv2 = WcoEmail::Conversation.find params[:id2]
  conv1.messages.map do |msg|
    msg.update conversation: conv2
  end
  conv1.tags.map do |tag|
    conv2.tags.push tag
  end
  conv1.leads.map do |lead|
    conv2.leads.push lead
  end
  conv2.save!
  conv1.delete

  flash_notice "Probably ok"
  redirect_to action: :show, id: conv2.id
end

#rmtagObject



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

def rmtag
  authorize! :addtag, WcoEmail::Conversation

  outs = @convs.map do |conv|
    @tags.map do |tag|
      conv.tags.delete( tag )
    end
    conv.save
  end
  flash_notice "Outcomes: #{outs}"
  render json: { status: 'ok' }
  # redirect_to request.referrer || root_path
end

#showObject



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

def show
  @conversation = ::WcoEmail::Conversation.find( params[:id] )
  authorize! :show, @conversation
  @messages     = @conversation.messages(
    ).order_by( date: :asc
    ).page( params[:messages_page ] ).per( @current_profile.per_page
    )

  @conversation.update_attributes({ status: Conv::STATUS_READ })

  @conversation.messages.unread.update_all({ read_at: Time.now })

  # @other_convs = WcoEmail::Message.where( :message_id.in => @messages.map( &:in_reply_to_id )
  #   ).where( :conversation_id.ne => @conversation.id
  #   ).map( &:conversation_id ).uniq
  # other_convs_by_subj = WcoEmail::Conversation.where( subject: @conversation.subject
  #   ).where( :conversation_id.ne => @conversation.id
  #   ).map( &:id )
  # if @other_convs.present? || other_convs_by_subj.present?
  #   @other_convs = WcoEmail::Conversation.find( @other_convs + other_convs_by_subj )
  # end
end

#updateObject



93
94
95
96
97
98
99
100
101
102
# File 'app/controllers/wco_email/conversations_controller.rb', line 93

def update
  @conversation = ::WcoEmail::Conversation.find( params[:id] )
  authorize! :update, @conversation
  if @conversation.update( params[:conversation].permit! )
    flash_notice 'ok'
  else
    flash_alert @conversation
  end
  redirect_to action: 'show', id: @conversation.id
end