mailboxer 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,102 +1,110 @@
1
1
  class Conversation < ActiveRecord::Base
2
- attr_reader :originator, :original_message, :last_sender, :last_message, :users
3
- has_many :messages
4
- has_many :receipts, :through => :messages
5
- # before_create :clean
6
- scope :participant, lambda {|participant|
2
+ attr_reader :originator, :original_message, :last_sender, :last_message, :users
3
+ has_many :messages
4
+ has_many :receipts, :through => :messages
5
+
6
+ before_create :clean
7
+
8
+ # before_create :clean
9
+ scope :participant, lambda {|participant|
7
10
  joins(:receipts).select('DISTINCT conversations.*').where('receipts.receiver_id' => participant.id,'receipts.receiver_type' => participant.class.to_s).order("conversations.updated_at DESC")
8
11
  }
9
- scope :inbox, lambda {|participant|
12
+ scope :inbox, lambda {|participant|
10
13
  joins(:receipts).select('DISTINCT conversations.*').where('receipts.receiver_id' => participant.id,'receipts.receiver_type' => participant.class.to_s, 'receipts.mailbox_type' => 'inbox','receipts.trashed' => false).order("conversations.updated_at DESC")
11
14
  }
12
- scope :sentbox, lambda {|participant|
13
- joins(:receipts).select('DISTINCT conversations.*').where('receipts.receiver_id' => participant.id,'receipts.receiver_type' => participant.class.to_s, 'receipts.mailbox_type' => 'sentbox','receipts.trashed' => false).order("conversations.updated_at DESC")
15
+ scope :sentbox, lambda {|participant|
16
+ joins(:receipts).select('DISTINCT conversations.*').where('receipts.receiver_id' => participant.id,'receipts.receiver_type' => participant.class.to_s, 'receipts.mailbox_type' => 'sentbox','receipts.trashed' => false).order("conversations.updated_at DESC")
14
17
  }
15
- scope :trash, lambda {|participant|
18
+ scope :trash, lambda {|participant|
16
19
  joins(:receipts).select('DISTINCT conversations.*').where('receipts.receiver_id' => participant.id,'receipts.receiver_type' => participant.class.to_s,'receipts.trashed' => true).order("conversations.updated_at DESC")
17
20
  }
18
- scope :unread, lambda {|participant|
21
+ scope :unread, lambda {|participant|
19
22
  joins(:receipts).select('DISTINCT conversations.*').where('receipts.receiver_id' => participant.id,'receipts.receiver_type' => participant.class.to_s,'receipts.read' => false).order("conversations.updated_at DESC")
20
23
  }
21
-
22
- class << self
23
- def total
24
- count('DISTINCT conversations.id')
25
- end
26
- end
27
-
28
- def mark_as_read(participant)
29
- return if participant.nil?
30
- return self.receipts(participant).mark_as_read
31
- end
32
-
33
- def mark_as_unread(participant)
34
- return if participant.nil?
35
- return self.receipts(participant).mark_as_unread
36
- end
37
-
38
- def move_to_trash(participant)
39
- return if participant.nil?
40
- return self.receipts(participant).move_to_trash
41
- end
42
-
43
- def untrash(participant)
44
- return if participant.nil?
45
- return self.receipts(participant).untrash
46
- end
47
-
48
- #originator of the conversation.
49
- def originator
50
- @orignator = self.original_message.sender if @originator.nil?
51
- return @orignator
52
- end
53
-
54
- #first message of the conversation.
55
- def original_message
56
- @original_message = self.messages.find(:first, :order => 'created_at') if @original_message.nil?
57
- return @original_message
58
- end
59
-
60
- #sender of the last message.
61
- def last_sender
62
- @last_sender = self.last_message.sender if @last_sender.nil?
63
- return @last_sender
64
- end
65
-
66
- #last message in the conversation.
67
- def last_message
68
- @last_message = self.messages.find(:first, :order => 'created_at DESC') if @last_message.nil?
69
- return @last_message
70
- end
71
-
72
- def receipts(participant=nil)
73
- return Receipt.conversation(self).receiver(participant) if participant
74
- return Receipt.conversation(self)
75
- end
76
-
77
- #all users involved in the conversation.
78
- def recipients
79
- return last_message.get_recipients
80
- end
81
-
82
- def get_recipients
83
- return self.recipients
84
- end
85
-
86
- def count_messages
87
- return Message.conversation(self).count
88
- end
89
-
90
- def is_participant?(participant)
91
- return false if participant.nil?
92
- return self.receipts(participant).count != 0
93
- end
94
- # protected
95
- # #[empty method]
96
- # #
97
- # #this gets called before_create. Implement this if you wish to clean out illegal content such as scripts or anything that will break layout. This is left empty because what is considered illegal content varies.
98
- # def clean
99
- # return if subject.nil?
100
- # #strip all illegal content here. (scripts, shit that will break layout, etc.)
101
- # end
24
+ class << self
25
+ def total
26
+ count('DISTINCT conversations.id')
27
+ end
28
+ end
29
+
30
+ def mark_as_read(participant)
31
+ return if participant.nil?
32
+ return self.receipts(participant).mark_as_read
33
+ end
34
+
35
+ def mark_as_unread(participant)
36
+ return if participant.nil?
37
+ return self.receipts(participant).mark_as_unread
38
+ end
39
+
40
+ def move_to_trash(participant)
41
+ return if participant.nil?
42
+ return self.receipts(participant).move_to_trash
43
+ end
44
+
45
+ def untrash(participant)
46
+ return if participant.nil?
47
+ return self.receipts(participant).untrash
48
+ end
49
+
50
+ #originator of the conversation.
51
+ def originator
52
+ @orignator = self.original_message.sender if @originator.nil?
53
+ return @orignator
54
+ end
55
+
56
+ #first message of the conversation.
57
+ def original_message
58
+ @original_message = self.messages.find(:first, :order => 'created_at') if @original_message.nil?
59
+ return @original_message
60
+ end
61
+
62
+ #sender of the last message.
63
+ def last_sender
64
+ @last_sender = self.last_message.sender if @last_sender.nil?
65
+ return @last_sender
66
+ end
67
+
68
+ #last message in the conversation.
69
+ def last_message
70
+ @last_message = self.messages.find(:first, :order => 'created_at DESC') if @last_message.nil?
71
+ return @last_message
72
+ end
73
+
74
+ def receipts(participant=nil)
75
+ return Receipt.conversation(self).receiver(participant) if participant
76
+ return Receipt.conversation(self)
77
+ end
78
+
79
+ #all users involved in the conversation.
80
+ def recipients
81
+ return last_message.get_recipients
82
+ end
83
+
84
+ def get_recipients
85
+ return self.recipients
86
+ end
87
+
88
+ def count_messages
89
+ return Message.conversation(self).count
90
+ end
91
+
92
+ def is_participant?(participant)
93
+ return false if participant.nil?
94
+ return self.receipts(participant).count != 0
95
+ end
96
+ # protected
97
+ # #[empty method]
98
+ # #
99
+ # #this gets called before_create. Implement this if you wish to clean out illegal content such as scripts or anything that will break layout. This is left empty because what is considered illegal content varies.
100
+ # def clean
101
+ # return if subject.nil?
102
+ # #strip all illegal content here. (scripts, shit that will break layout, etc.)
103
+ # end
104
+
105
+ include ActionView::Helpers::SanitizeHelper
106
+
107
+ def clean
108
+ self.subject = sanitize self.subject
109
+ end
102
110
  end
@@ -6,8 +6,6 @@ class Message < ActiveRecord::Base
6
6
 
7
7
  class_inheritable_accessor :on_deliver_callback
8
8
  protected :on_deliver_callback
9
- class_inheritable_accessor :on_deliver_clean
10
- protected :on_deliver_clean
11
9
  belongs_to :sender, :polymorphic => :true
12
10
  belongs_to :conversation
13
11
  has_many :receipts
@@ -16,14 +14,13 @@ class Message < ActiveRecord::Base
16
14
  }
17
15
 
18
16
  class << self
19
- def on_deliver(clean_method, callback_method)
20
- self.on_deliver_clean = clean_method
17
+ def on_deliver(callback_method)
21
18
  self.on_deliver_callback = callback_method
22
19
  end
23
20
  end
24
21
 
25
22
  def deliver(mailbox_type, should_clean = true)
26
- self.on_deliver_clean.call(self) unless self.on_deliver_clean.nil? or !should_clean
23
+ self.clean if should_clean
27
24
  self.save
28
25
  self.recipients.each do |r|
29
26
  r.mailbox[mailbox_type] << self
@@ -39,4 +36,12 @@ class Message < ActiveRecord::Base
39
36
  return recipients_array.uniq
40
37
  end
41
38
 
39
+ include ActionView::Helpers::SanitizeHelper
40
+ def clean
41
+ unless self.subject.nil?
42
+ self.subject = sanitize self.subject
43
+ end
44
+ self.body = sanitize self.body
45
+ end
46
+
42
47
  end
data/mailboxer.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  Gem::Specification.new do |s|
3
3
  s.name = "mailboxer"
4
- s.version = "0.0.10"
4
+ s.version = "0.0.11"
5
5
 
6
6
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
7
7
  s.authors = ["Eduardo Casanova Cuesta"]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailboxer
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 9
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 10
10
- version: 0.0.10
9
+ - 11
10
+ version: 0.0.11
11
11
  platform: ruby
12
12
  authors:
13
13
  - Eduardo Casanova Cuesta