module MessageTrain::InstanceMethods::RecipientMethods
Included by InstanceMethods
when message_train mixin is run, if this is a recipient
Public Instance Methods
all_boxes(*args)
click to toggle source
# File lib/message_train/instance_methods.rb, line 170 def all_boxes(*args) participant = args[0] || self divisions = [:in, :sent, :all, :drafts, :trash, :ignored] divisions.collect do |division| MessageTrain::Box.new(self, division, participant) end end
box(*args)
click to toggle source
# File lib/message_train/instance_methods.rb, line 127 def box(*args) division = args[0] || :in participant = args[1] || self @box ||= MessageTrain::Box.new(self, division, participant) end
collective_boxes(*args)
click to toggle source
# File lib/message_train/instance_methods.rb, line 133 def collective_boxes(*args) division = args[0] || :in participant = args[1] || self cb_tables = MessageTrain.configuration .collectives_for_recipient_methods return {} if cb_tables.empty? Hash[cb_tables.map do |key, value| box = table_collective_box(key, value, division, participant) [key, box] end] end
collective_boxes_show_flags()
click to toggle source
# File lib/message_train/instance_methods.rb, line 151 def collective_boxes_show_flags Hash[collective_boxes.map do |key, collectives| flag = collectives.select do |collective_box| collective_box.parent.allows_access_by?(self) end.any? [key, flag] end] end
collective_boxes_unread_counts()
click to toggle source
# File lib/message_train/instance_methods.rb, line 145 def collective_boxes_unread_counts Hash[collective_boxes.map do |key, collectives| [key, collectives.collect(&:unread_count).sum] end] end
message_train_name()
click to toggle source
# File lib/message_train/instance_methods.rb, line 178 def message_train_name send(self.class.name_column) end
message_train_slug()
click to toggle source
# File lib/message_train/instance_methods.rb, line 182 def message_train_slug send(self.class.slug_column) end
table_collective_box( table_sym, collectives_method, division, participant )
click to toggle source
# File lib/message_train/instance_methods.rb, line 160 def table_collective_box( table_sym, collectives_method, division, participant ) model = MessageTrain.configuration .recipient_tables[table_sym] .constantize collectives = model.send(collectives_method, participant) collectives.map { |x| x.box(division, participant) }.compact end
Protected Instance Methods
message_train_subscription(box)
click to toggle source
# File lib/message_train/instance_methods.rb, line 196 def message_train_subscription(box) parent = box.parent return unless parent.allows_receiving_by?(self) { from: parent, from_type: parent.class.name, from_id: parent.id, from_name: :messages_to_collective.l( collective: parent.message_train_name ), unsubscribe: unsubscribes.find_by(from: parent) } end
self_subscription()
click to toggle source
# File lib/message_train/instance_methods.rb, line 188 def self_subscription { from: self, from_type: self.class.name, from_id: id, from_name: :messages_directly_to_myself.l, unsubscribe: unsubscribes.find_by(from: self) } end