Class: Smalltalk::Message

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Workflow
Defined in:
lib/smalltalk/message.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.for(messenger) ⇒ Object



31
32
33
# File 'lib/smalltalk/message.rb', line 31

def self.for(messenger)
  where("(sender_type = ? AND sender_id = ?) OR (recipient_type = ? AND recipient_id = ?)", messenger.class.name, messenger.id, messenger.class.name, messenger.id)
end

.received_by(recipient) ⇒ Object



39
40
41
# File 'lib/smalltalk/message.rb', line 39

def self.received_by(recipient)
  where(recipient_type: recipient.class.name, recipient_id: recipient.id)
end

.sent_by(sender) ⇒ Object



35
36
37
# File 'lib/smalltalk/message.rb', line 35

def self.sent_by(sender)
  where(sender_type: sender.class.name, sender_id: sender.id)
end

Instance Method Details

#hide!Object



73
74
75
76
# File 'lib/smalltalk/message.rb', line 73

def hide!
  self.hidden = true
  self.save!
end

#received_by?(recipient) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/smalltalk/message.rb', line 47

def received_by?(recipient)
  (recipient_type == recipient.class.name) && (recipient_id == recipient.id)
end

#recipientObject



60
61
62
# File 'lib/smalltalk/message.rb', line 60

def recipient
  self.recipient_type.constantize.find(recipient_id)
end

#recipient=(recipient) ⇒ Object



64
65
66
67
# File 'lib/smalltalk/message.rb', line 64

def recipient=(recipient)
  self.recipient_type = recipient.class.name
  self.recipient_id = recipient.id
end

#reply(params = {}) ⇒ Object



69
70
71
# File 'lib/smalltalk/message.rb', line 69

def reply(params = {})
  Smalltalk::Reply.new(params.merge(message: self)).build!
end

#senderObject



51
52
53
# File 'lib/smalltalk/message.rb', line 51

def sender
  self.sender_type.constantize.find(sender_id)
end

#sender=(sender) ⇒ Object



55
56
57
58
# File 'lib/smalltalk/message.rb', line 55

def sender=(sender)
  self.sender_type = sender.class.name
  self.sender_id = sender.id
end

#sent_by?(sender) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/smalltalk/message.rb', line 43

def sent_by?(sender)
  (sender_type == sender.class.name) && (sender.id == sender.id)
end

#view!Object



78
79
80
81
# File 'lib/smalltalk/message.rb', line 78

def view!
  self.viewed = true
  self.save!
end