mailboxer 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +2 -0
- data/app/models/mailboxer_conversation.rb +19 -15
- data/app/models/mailboxer_mailbox.rb +33 -13
- data/mailboxer.gemspec +2 -2
- metadata +5 -4
data/.yardopts
ADDED
@@ -2,30 +2,34 @@ class MailboxerConversation < ActiveRecord::Base
|
|
2
2
|
attr_reader :originator, :original_message, :last_sender, :last_message, :users
|
3
3
|
has_many :mailboxer_messages
|
4
4
|
has_many :mailboxer_mails, :through => :mailboxer_messages
|
5
|
-
# before_create :clean
|
5
|
+
# before_create :clean
|
6
6
|
scope :participant, lambda {|participant|
|
7
7
|
joins(:mailboxer_mails).select('DISTINCT mailboxer_conversations.*').where('mailboxer_mails.receiver_id' => participant.id,'mailboxer_mails.receiver_type' => participant.class.to_s)
|
8
8
|
}
|
9
9
|
scope :inbox, lambda {|participant|
|
10
|
-
joins(:mailboxer_mails).select('DISTINCT mailboxer_conversations.*').where('mailboxer_mails.receiver_id' => participant.id,'mailboxer_mails.receiver_type' => participant.class.to_s, 'mailboxer_mails.mailbox_type' => 'inbox')
|
10
|
+
joins(:mailboxer_mails).select('DISTINCT mailboxer_conversations.*').where('mailboxer_mails.receiver_id' => participant.id,'mailboxer_mails.receiver_type' => participant.class.to_s, 'mailboxer_mails.mailbox_type' => 'inbox','mailboxer_mails.trashed' => false)
|
11
11
|
}
|
12
12
|
scope :sentbox, lambda {|participant|
|
13
|
-
joins(:mailboxer_mails).select('DISTINCT mailboxer_conversations.*').where('mailboxer_mails.receiver_id' => participant.id,'mailboxer_mails.receiver_type' => participant.class.to_s, 'mailboxer_mails.mailbox_type' => 'sentbox')
|
13
|
+
joins(:mailboxer_mails).select('DISTINCT mailboxer_conversations.*').where('mailboxer_mails.receiver_id' => participant.id,'mailboxer_mails.receiver_type' => participant.class.to_s, 'mailboxer_mails.mailbox_type' => 'sentbox','mailboxer_mails.trashed' => false)
|
14
|
+
}
|
15
|
+
scope :trash, lambda {|participant|
|
16
|
+
joins(:mailboxer_mails).select('DISTINCT mailboxer_conversations.*').where('mailboxer_mails.receiver_id' => participant.id,'mailboxer_mails.receiver_type' => participant.class.to_s,'mailboxer_mails.trashed' => true)
|
17
|
+
}
|
18
|
+
scope :unread, lambda {|participant|
|
19
|
+
joins(:mailboxer_mails).select('DISTINCT mailboxer_conversations.*').where('mailboxer_mails.receiver_id' => participant.id,'mailboxer_mails.receiver_type' => participant.class.to_s,'mailboxer_mails.read' => false)
|
14
20
|
}
|
15
|
-
scope :trash, joins(:mailboxer_mails).select('DISTINCT mailboxer_conversations.*').where('mailboxer_mails.trashed' => true)
|
16
|
-
scope :unread, joins(:mailboxer_mails).select('DISTINCT mailboxer_conversations.*').where('mailboxer_mails.read' => false)
|
17
21
|
|
18
22
|
class << self
|
19
23
|
def total
|
20
24
|
count('DISTINCT mailboxer_conversations.id')
|
21
25
|
end
|
22
26
|
end
|
23
|
-
|
27
|
+
|
24
28
|
def mark_as_read(participant)
|
25
29
|
return if participant.nil?
|
26
30
|
return MailboxerMail.conversation(self).receiver(participant).mark_as_read
|
27
31
|
end
|
28
|
-
|
32
|
+
|
29
33
|
def mark_as_unread(participant)
|
30
34
|
return if participant.nil?
|
31
35
|
return MailboxerMail.conversation(self).receiver(participant).mark_as_unread
|
@@ -87,12 +91,12 @@ class MailboxerConversation < ActiveRecord::Base
|
|
87
91
|
return MailboxerMessage.conversation(self).count
|
88
92
|
end
|
89
93
|
|
90
|
-
# protected
|
91
|
-
# #[empty method]
|
92
|
-
# #
|
93
|
-
# #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.
|
94
|
-
# def clean
|
95
|
-
# return if subject.nil?
|
96
|
-
# #strip all illegal content here. (scripts, shit that will break layout, etc.)
|
97
|
-
# 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
|
98
102
|
end
|
@@ -4,7 +4,7 @@ class MailboxerMailbox
|
|
4
4
|
#the user/owner of this mailbox, set when initialized.
|
5
5
|
attr_reader :messageable
|
6
6
|
#creates a new Mailbox instance with the given user and optional type.
|
7
|
-
|
7
|
+
|
8
8
|
def initialize(recipient, box = :all)
|
9
9
|
@messageable = recipient
|
10
10
|
@type = box
|
@@ -13,23 +13,43 @@ class MailboxerMailbox
|
|
13
13
|
def type=(val)
|
14
14
|
@type = val.to_sym
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def conversations(options = {})
|
18
|
-
|
18
|
+
conv = MailboxerConversation.participant(@messageable)
|
19
|
+
|
20
|
+
if options[:mailbox_type].present?
|
21
|
+
case options[:mailbox_type]
|
22
|
+
when 'inbox'
|
23
|
+
conv = MailboxerConversation.inbox(@messageable)
|
24
|
+
when 'sentbox'
|
25
|
+
conv = MailboxerConversation.sentbox(@messageable)
|
26
|
+
when 'trash'
|
27
|
+
conv = MailboxerConversation.trash(@messageable)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
if (options[:read].present? and options[:read]==false) or (options[:unread].present? and options[:unread]==true)
|
32
|
+
conv = conv.unread(@messageable)
|
33
|
+
end
|
34
|
+
|
35
|
+
return conv.uniq
|
19
36
|
end
|
20
37
|
|
21
38
|
def inbox(options={})
|
22
|
-
|
39
|
+
options = options.merge(:mailbox_type => 'inbox')
|
40
|
+
return self.conversations(options)
|
23
41
|
end
|
24
42
|
|
25
43
|
def sentbox(options={})
|
26
|
-
|
44
|
+
options = options.merge(:mailbox_type => 'sentbox')
|
45
|
+
return self.conversations(options)
|
27
46
|
end
|
28
47
|
|
29
48
|
def trash(options={})
|
30
|
-
|
49
|
+
options = options.merge(:mailbox_type => 'trash')
|
50
|
+
return self.conversations(options)
|
31
51
|
end
|
32
|
-
|
52
|
+
|
33
53
|
def mail(options = {})
|
34
54
|
return MailboxerMail.where(options).receiver(@messageable)
|
35
55
|
end
|
@@ -38,11 +58,11 @@ class MailboxerMailbox
|
|
38
58
|
self.type = mailbox_type
|
39
59
|
return self
|
40
60
|
end
|
41
|
-
|
61
|
+
|
42
62
|
def <<(msg)
|
43
63
|
return self.add(msg)
|
44
64
|
end
|
45
|
-
|
65
|
+
|
46
66
|
def add(msg)
|
47
67
|
mail_msg = MailboxerMail.new
|
48
68
|
mail_msg.mailboxer_message = msg
|
@@ -52,20 +72,20 @@ class MailboxerMailbox
|
|
52
72
|
@messageable.mailboxer_mails << mail_msg
|
53
73
|
return mail_msg
|
54
74
|
end
|
55
|
-
|
75
|
+
|
56
76
|
def empty_trash(options = {})
|
57
77
|
return self.mail.trash(options).delete_all
|
58
78
|
end
|
59
|
-
|
79
|
+
|
60
80
|
def has_conversation?(conversation)
|
61
81
|
return self.mail.conversation(converstaion).count!=0
|
62
82
|
end
|
63
|
-
|
83
|
+
|
64
84
|
def is_trashed?(conversation)
|
65
85
|
return self.mail.trash.conversation(conversation).count!=0
|
66
86
|
end
|
67
87
|
def is_completely_trashed?(conversation)
|
68
88
|
return self.mail.trash.conversation(conversation).count==self.mail.conversation(conversation).count
|
69
89
|
end
|
70
|
-
|
90
|
+
|
71
91
|
end
|
data/mailboxer.gemspec
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
|
2
2
|
Gem::Specification.new do |s|
|
3
3
|
s.name = "mailboxer"
|
4
|
-
s.version = "0.0.
|
4
|
+
s.version = "0.0.6"
|
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"]
|
8
|
-
s.date = %q{2011-03-
|
8
|
+
s.date = %q{2011-03-17}
|
9
9
|
s.description = %q{A Rails engine that allows any model to act as messageable, permitting it interchange messages with any other messageable model. }
|
10
10
|
s.email = %q{ecasanovac@gmail.com}
|
11
11
|
s.extra_rdoc_files = [
|
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: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 6
|
10
|
+
version: 0.0.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Eduardo Casanova Cuesta
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-03-
|
18
|
+
date: 2011-03-17 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -187,6 +187,7 @@ extra_rdoc_files:
|
|
187
187
|
- README.rdoc
|
188
188
|
files:
|
189
189
|
- .gitignore
|
190
|
+
- .yardopts
|
190
191
|
- Gemfile
|
191
192
|
- LICENSE.txt
|
192
193
|
- README.rdoc
|