mailboxer 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/app/models/conversation.rb +99 -91
- data/app/models/message.rb +10 -5
- data/mailboxer.gemspec +1 -1
- metadata +3 -3
data/app/models/conversation.rb
CHANGED
@@ -1,102 +1,110 @@
|
|
1
1
|
class Conversation < ActiveRecord::Base
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
#
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
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
|
data/app/models/message.rb
CHANGED
@@ -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(
|
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.
|
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
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:
|
4
|
+
hash: 9
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 11
|
10
|
+
version: 0.0.11
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Eduardo Casanova Cuesta
|