module MessageTrain::InstanceMethods::GeneralMethods
Included by InstanceMethods
when message_train mixin is run
Constants
- BOX_DEFINITIONS
- BOX_OMISSION_DEFINITIONS
Public Instance Methods
all_conversations(*args)
click to toggle source
# File lib/message_train/instance_methods.rb, line 89 def all_conversations(*args) participant = args[0] || self results = MessageTrain::Conversation.with_messages_through(self) return [] if results.empty? results.with_messages_for(participant) end
all_messages(*args)
click to toggle source
# File lib/message_train/instance_methods.rb, line 96 def all_messages(*args) participant = args[0] || self results = MessageTrain::Message.with_receipts_through(self) return [] if results.empty? results.with_receipts_for(participant) end
allows_access_by?(recipient)
click to toggle source
# File lib/message_train/instance_methods.rb, line 45 def allows_access_by?(recipient) allows_receiving_by?(recipient) || allows_sending_by?(recipient) end
allows_receiving_by?(recipient)
click to toggle source
# File lib/message_train/instance_methods.rb, line 49 def allows_receiving_by?(recipient) return false if valid_recipients.empty? valid_recipients.include? recipient end
allows_sending_by?(sender)
click to toggle source
# File lib/message_train/instance_methods.rb, line 37 def allows_sending_by?(sender) valid_senders.include? sender end
boxes_for_participant(participant)
click to toggle source
# File lib/message_train/instance_methods.rb, line 78 def boxes_for_participant(participant) original_order = [:in, :sent, :all, :drafts, :trash, :ignored] divisions = [:all, :trash] if respond_to?(:messages) || allows_sending_by?(participant) divisions += [:sent, :drafts] end divisions += [:in, :ignored] if allows_receiving_by?(participant) divisions.sort_by! { |x| original_order.index x } divisions.collect { |d| MessageTrain::Box.new(self, d, participant) } end
conversations(*args)
click to toggle source
# File lib/message_train/instance_methods.rb, line 59 def conversations(*args) division = args[0] || :in participant = args[1] || self definition_method = BOX_DEFINITIONS[division] return if definition_method.nil? conversations = defined_conversations(definition_method, participant) BOX_OMISSION_DEFINITIONS.each do |division_key, omission_method| next if division_key == division # Because not to be omitted conversations = conversations.send(omission_method, participant) end conversations end
defined_conversations(definition, participant)
click to toggle source
# File lib/message_train/instance_methods.rb, line 72 def defined_conversations(definition, participant) MessageTrain::Conversation.with_messages_through(self) .without_deleted_for(participant) .send(definition, participant) end
message_train_subscriptions()
click to toggle source
# File lib/message_train/instance_methods.rb, line 115 def message_train_subscriptions subscriptions = [self_subscription] subscriptions += collective_boxes.values.map do |boxes| boxes.map { |box| message_train_subscription(box) } end subscriptions.flatten.compact end
path_part()
click to toggle source
# File lib/message_train/instance_methods.rb, line 27 def path_part return unless self.class.collective? # This must mean it's a collective "#{self.class.table_name}:#{message_train_slug}" end
self_collection()
click to toggle source
# File lib/message_train/instance_methods.rb, line 54 def self_collection # This turns a single record into an active record collection. self.class.where(id: id) end
unsubscribe_from(from)
click to toggle source
# File lib/message_train/instance_methods.rb, line 111 def unsubscribe_from(from) unsubscribes.find_or_create_by(from: from) end
unsubscribed_from?(from)
click to toggle source
# File lib/message_train/instance_methods.rb, line 107 def unsubscribed_from?(from) unsubscribed_from_all? || unsubscribes.where(from: from).exists? end
unsubscribed_from_all?()
click to toggle source
# File lib/message_train/instance_methods.rb, line 103 def unsubscribed_from_all? unsubscribes.where(from: nil).exists? end
valid_recipients()
click to toggle source
# File lib/message_train/instance_methods.rb, line 41 def valid_recipients send(self.class.valid_recipients_method) end
valid_senders()
click to toggle source
# File lib/message_train/instance_methods.rb, line 33 def valid_senders send(self.class.valid_senders_method) end