Class: Marley::Joints::Messages::Resources::PrivateMessage

Inherits:
Message
  • Object
show all
Defined in:
lib/marley/joints/messages.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Message

#author

Instance Attribute Details

#recipientsObject



48
49
50
# File 'lib/marley/joints/messages.rb', line 48

def recipients
  users.map{|u|u.name}.join(',')
end

Class Method Details

.list_dataset(params = {}) ⇒ Object



38
39
40
# File 'lib/marley/joints/messages.rb', line 38

def self.list_dataset(params={})
  super.filter(:messages__id => DB[:messages_users].filter(:user_id => current_user[:id]).select(:message_id))
end

Instance Method Details

#actions(parent_instance = nil) ⇒ Object



44
45
46
47
# File 'lib/marley/joints/messages.rb', line 44

def actions(parent_instance=nil)
  return super if new? || ! recipients.to_s.match(/,/) 
  {:get => [:reply, :reply_all]}
end

#after_saveObject



66
67
68
69
# File 'lib/marley/joints/messages.rb', line 66

def after_save
  super
  @recipients.each {|recipient| add_user recipient} 
end

#current_user_roleObject



41
42
43
# File 'lib/marley/joints/messages.rb', line 41

def current_user_role
  super || (self.users.include?(self.class.current_user) && 'recipient')
end

#replyObject



51
52
53
# File 'lib/marley/joints/messages.rb', line 51

def reply
  super.reggae_instance.set_values(:recipients => author)
end

#reply_allObject



54
55
56
# File 'lib/marley/joints/messages.rb', line 54

def reply_all
  reply.set_values(:recipients => "#{author},#{recipients}".sub(/\b#{self.class.current_user.name}\b,?/,''))
end

#rest_colsObject



34
35
36
# File 'lib/marley/joints/messages.rb', line 34

def rest_cols
  [:recipients] + super
end

#validateObject



57
58
59
60
61
62
63
64
65
# File 'lib/marley/joints/messages.rb', line 57

def validate
  super
  errors[:recipients]='Recipients must be specified' unless @recipients
  @recipients=@recipients.split(',').map do |recipient_name|
    u=MR::User[:name => recipient_name]
    errors[:recipients] << "#{recipient_name} is not a valid message recipient" unless u
    u
  end
end