curationexperts-mailboxer 0.10.3.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +1 -0
- data/.travis.yml +10 -0
- data/.yardopts +2 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +20 -0
- data/README.md +273 -0
- data/Rakefile +7 -0
- data/app/mailers/message_mailer.rb +37 -0
- data/app/mailers/notification_mailer.rb +21 -0
- data/app/models/conversation.rb +143 -0
- data/app/models/mailbox.rb +121 -0
- data/app/models/message.rb +66 -0
- data/app/models/notification.rb +184 -0
- data/app/models/receipt.rb +151 -0
- data/app/uploaders/attachment_uploader.rb +3 -0
- data/app/views/message_mailer/new_message_email.html.erb +20 -0
- data/app/views/message_mailer/new_message_email.text.erb +10 -0
- data/app/views/message_mailer/reply_message_email.html.erb +20 -0
- data/app/views/message_mailer/reply_message_email.text.erb +10 -0
- data/app/views/notification_mailer/new_notification_email.html.erb +20 -0
- data/app/views/notification_mailer/new_notification_email.text.erb +10 -0
- data/config/locales/en.yml +7 -0
- data/db/migrate/20110511145103_create_mailboxer.rb +61 -0
- data/db/migrate/20110719110700_add_notified_object.rb +17 -0
- data/db/migrate/20110912163911_add_notification_code.rb +13 -0
- data/db/migrate/20111204163911_add_attachments.rb +9 -0
- data/db/migrate/20120813110712_rename_receipts_read.rb +9 -0
- data/db/migrate/20130305144212_add_global_notification_support.rb +9 -0
- data/lib/generators/mailboxer/install_generator.rb +35 -0
- data/lib/generators/mailboxer/templates/initializer.rb +17 -0
- data/lib/generators/mailboxer/views_generator.rb +9 -0
- data/lib/mailboxer.rb +31 -0
- data/lib/mailboxer/concerns/configurable_mailer.rb +13 -0
- data/lib/mailboxer/engine.rb +18 -0
- data/lib/mailboxer/models/messageable.rb +208 -0
- data/mailboxer.gemspec +47 -0
- data/spec/dummy/.gitignore +5 -0
- data/spec/dummy/Gemfile +33 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/home_controller.rb +4 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/app/models/cylon.rb +7 -0
- data/spec/dummy/app/models/duck.rb +11 -0
- data/spec/dummy/app/models/user.rb +6 -0
- data/spec/dummy/app/views/home/index.html.haml +7 -0
- data/spec/dummy/app/views/layouts/application.html.haml +11 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +42 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +24 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +26 -0
- data/spec/dummy/config/environments/production.rb +49 -0
- data/spec/dummy/config/environments/test.rb +33 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mailboxer.rb +17 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +58 -0
- data/spec/dummy/config/sunspot.yml +17 -0
- data/spec/dummy/db/migrate/20110228120600_create_users.rb +14 -0
- data/spec/dummy/db/migrate/20110306002940_create_ducks.rb +14 -0
- data/spec/dummy/db/migrate/20110306015107_create_cylons.rb +14 -0
- data/spec/dummy/db/migrate/20120305103200_create_mailboxer.rb +61 -0
- data/spec/dummy/db/migrate/20120305103201_add_notified_object.rb +17 -0
- data/spec/dummy/db/migrate/20120305103202_add_notification_code.rb +13 -0
- data/spec/dummy/db/migrate/20120305103203_add_attachments.rb +5 -0
- data/spec/dummy/db/migrate/20120813110712_rename_receipts_read.rb +9 -0
- data/spec/dummy/db/migrate/20130305144212_add_global_notification_support.rb +11 -0
- data/spec/dummy/db/schema.rb +74 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/index.html +239 -0
- data/spec/dummy/public/robots.txt +5 -0
- data/spec/dummy/public/uploads/testfile.txt +1 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/factories/cylon.rb +10 -0
- data/spec/factories/duck.rb +10 -0
- data/spec/factories/user.rb +10 -0
- data/spec/integration/message_and_receipt_spec.rb +903 -0
- data/spec/integration/navigation_spec.rb +9 -0
- data/spec/mailboxer/concerns/configurable_mailer_spec.rb +27 -0
- data/spec/mailboxer_spec.rb +7 -0
- data/spec/mailers/message_mailer_spec.rb +110 -0
- data/spec/mailers/notification_mailer_spec.rb +61 -0
- data/spec/models/conversation_spec.rb +101 -0
- data/spec/models/mailbox_spec.rb +124 -0
- data/spec/models/mailboxer_models_messageable_spec.rb +315 -0
- data/spec/models/message_spec.rb +24 -0
- data/spec/models/notification_spec.rb +200 -0
- data/spec/models/receipt_spec.rb +44 -0
- data/spec/spec_helper.rb +36 -0
- data/spec/testfile.txt +1 -0
- metadata +263 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e2c8a26ae7c959416ecf05e4f596960cef2704c5
|
4
|
+
data.tar.gz: 6b213b2edbc6c9773102cb3bd657130adf66fba3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 76a2a3ad96c9d859199b8cd792a701832977062535d02ec4cb9ac9cffb74b5087314f0d7d75d3495dd80d41fe9c388e7a98cf8459a387d62abd924e585aac3cf
|
7
|
+
data.tar.gz: 2be1cf1b92b7a8db4bff3932226ce3ce07a96810dac9aa39ad44e85ec1a767df81970649b0a7f783d06bd385540b556538d8842f7bff1e57d2bbc701b8288c89
|
data/.gitignore
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
.bundle/
|
2
|
+
log/*.log
|
3
|
+
pkg/
|
4
|
+
spec/dummy/db/*.sqlite3
|
5
|
+
spec/dummy/log/*.log
|
6
|
+
spec/dummy/log/*.lck
|
7
|
+
spec/dummy/tmp/
|
8
|
+
spec/dummy/.project
|
9
|
+
spec/dummy/solr
|
10
|
+
**.tmp_*
|
11
|
+
Gemfile.lock
|
12
|
+
.idea
|
13
|
+
.project
|
14
|
+
.document
|
15
|
+
.settings/
|
16
|
+
rdoc/
|
17
|
+
doc/
|
18
|
+
.yardoc/*
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.travis.yml
ADDED
data/.yardopts
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Universidad Politécnica de Madrid
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,273 @@
|
|
1
|
+
# Mailboxer 0.10.x [![](https://secure.travis-ci.org/ging/mailboxer.png)](http://travis-ci.org/ging/mailboxer) [![](https://gemnasium.com/ging/mailboxer.png)](https://gemnasium.com/ging/mailboxer)
|
2
|
+
|
3
|
+
This project is based on the need of a private message system for [ging
|
4
|
+
/ social\_stream](https://github.com/ging/social_stream). Instead of creating our core message system heavily
|
5
|
+
dependent on our development we are trying to implement a generic and
|
6
|
+
potent messaging gem.
|
7
|
+
|
8
|
+
After looking for a good gem to use we notice the lack of messaging gems
|
9
|
+
and functionality in them. Mailboxer tries to fill this emptiness giving
|
10
|
+
a powerfull and generic message system. It supports the use of
|
11
|
+
conversations with two or more recipients, send notification to a
|
12
|
+
recipient (intended to be used as system notifications “Your picture has
|
13
|
+
new comments”, “John Doe has updated its document”, etc.), emails the
|
14
|
+
messageable model (if configured to do so). It has a complete use of a
|
15
|
+
`Mailbox` object for each messageable with `inbox`, `sentbox` and
|
16
|
+
`trash`.
|
17
|
+
|
18
|
+
The gem is constantly growing and improving its functionality. As it is
|
19
|
+
used with our parallel development [ging / social\_stream](https://github.com/ging/social_stream) we are finding and fixing bugs continously. If you want
|
20
|
+
some functionality not supported yet or marked as TODO, you can create
|
21
|
+
an [issue](https://github.com/ging/mailboxer/issues) to ask for it. It will be a great feedback for us, and we
|
22
|
+
will know what you may find useful of the gem.
|
23
|
+
|
24
|
+
Mailboxer was born from the great, but outdated, code from [lpsergi /
|
25
|
+
acts*as*messageable](https://github.com/psergi/acts_as_messageable).
|
26
|
+
|
27
|
+
We are now working to make an exhaustive documentation and some wiki
|
28
|
+
pages in order to make even easier to use the gem at its full potencial.
|
29
|
+
Please, give us some time if you find something missing or [ask for
|
30
|
+
it](https://github.com/ging/mailboxer/issues).
|
31
|
+
|
32
|
+
Installation
|
33
|
+
------------
|
34
|
+
|
35
|
+
Add to your Gemfile:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
gem 'mailboxer'
|
39
|
+
```
|
40
|
+
|
41
|
+
Then run:
|
42
|
+
|
43
|
+
```sh
|
44
|
+
$ bundle update
|
45
|
+
```
|
46
|
+
|
47
|
+
Run install script:
|
48
|
+
|
49
|
+
```sh
|
50
|
+
$ rails g mailboxer:install
|
51
|
+
```
|
52
|
+
|
53
|
+
And don't forget to migrate you database:
|
54
|
+
|
55
|
+
```sh
|
56
|
+
$ rake db:migrate
|
57
|
+
```
|
58
|
+
|
59
|
+
## Requirements & Settings
|
60
|
+
|
61
|
+
### Emails
|
62
|
+
|
63
|
+
We are now adding support for sending emails when a Notification or a Message is sent to one or more recipients. You should modify mailboxer initializer (/config/initializer/mailboxer.rb) to edit this settings.
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
Mailboxer.setup do |config|
|
67
|
+
#Configures if you applications uses or no the email sending for Notifications and Messages
|
68
|
+
config.uses_emails = true
|
69
|
+
#Configures the default from for the email sent for Messages and Notifications of Mailboxer
|
70
|
+
config.default_from = "no-reply@dit.upm.es"
|
71
|
+
...
|
72
|
+
end
|
73
|
+
```
|
74
|
+
|
75
|
+
You can change the way in which emails are delivered by specifying a custom implementation for notification and message mailer
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
Mailboxer.setup do |config|
|
79
|
+
config.notification_mailer = CustomNotificationMailer
|
80
|
+
config.message_mailer = CustomMessageMailer
|
81
|
+
...
|
82
|
+
end
|
83
|
+
```
|
84
|
+
|
85
|
+
### User identities
|
86
|
+
|
87
|
+
Users must have an identity defined by a `name` and an `email`. We must assure that Messageable models have some specific methods. These methods are:
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
#Returning any kind of identification you want for the model
|
91
|
+
def name
|
92
|
+
return "You should add method :name in your Messageable model"
|
93
|
+
end
|
94
|
+
```
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
#Returning the email address of the model if an email should be sent for this object (Message or Notification).
|
98
|
+
#If no mail has to be sent, return nil.
|
99
|
+
def mailboxer_email(object)
|
100
|
+
#Check if an email should be sent for that object
|
101
|
+
#if true
|
102
|
+
return "define_email@on_your.model"
|
103
|
+
#if false
|
104
|
+
#return nil
|
105
|
+
end
|
106
|
+
```
|
107
|
+
|
108
|
+
These names are explicit enough to avoid colliding with other methods, but as long as you need to change them you can do it by using mailboxer initializer (/config/initializer/mailboxer.rb). Just add or uncomment the following lines:
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
Mailboxer.setup do |config|
|
112
|
+
# ...
|
113
|
+
#Configures the methods needed by mailboxer
|
114
|
+
config.email_method = :mailboxer_email
|
115
|
+
config.name_method = :name
|
116
|
+
# ...
|
117
|
+
end
|
118
|
+
```
|
119
|
+
|
120
|
+
You may change whatever you want or need. For example:
|
121
|
+
|
122
|
+
```ruby
|
123
|
+
config.email_method = :notifications_email
|
124
|
+
config.name_method = :display_name
|
125
|
+
```
|
126
|
+
|
127
|
+
Will use the method `notification_email(object)` instead of `mailboxer_email(object)` and `display_name` for `name`.
|
128
|
+
|
129
|
+
Using default or custom method names, if your model doesn't implement them, Mailboxer will use dummy methods not to crash but notify you the missing methods.
|
130
|
+
|
131
|
+
## Preparing your models
|
132
|
+
|
133
|
+
In your model:
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
class User < ActiveRecord::Base
|
137
|
+
acts_as_messageable
|
138
|
+
end
|
139
|
+
```
|
140
|
+
|
141
|
+
You are not limited to User model. You can use Mailboxer in any other model and use it in serveral different models. If you have ducks and cylons in your application and you want to interchange messages as if they where the same, just use act_as_messageable in each one and you will be able to send duck-duck, duck-cylon, cylon-duck and cylon-cylon messages. Of course, you can extend it for as many clases as you need.
|
142
|
+
|
143
|
+
Example:
|
144
|
+
|
145
|
+
```ruby
|
146
|
+
class Duck < ActiveRecord::Base
|
147
|
+
acts_as_messageable
|
148
|
+
end
|
149
|
+
```
|
150
|
+
|
151
|
+
```ruby
|
152
|
+
class Cylon < ActiveRecord::Base
|
153
|
+
acts_as_messageable
|
154
|
+
end
|
155
|
+
```
|
156
|
+
|
157
|
+
## Mailboxer API
|
158
|
+
|
159
|
+
### Warning for version 0.8.0
|
160
|
+
Version 0.8.0 sees `Messageable#read` and `Messageable#unread` renamed to `mark_as_(un)read`, and `Receipt#read` and `Receipt#unread` to `is_(un)read`. This may break existing applications, but `read` is a reserved name for Active Record, and the best pratice in this case is simply avoid using it.
|
161
|
+
|
162
|
+
### How can I send a message?
|
163
|
+
|
164
|
+
```ruby
|
165
|
+
#alfa wants to send a message to beta
|
166
|
+
alfa.send_message(beta, "Body", "subject")
|
167
|
+
```
|
168
|
+
|
169
|
+
### How can I reply a message?
|
170
|
+
|
171
|
+
```ruby
|
172
|
+
#alfa wants to reply to all in a conversation
|
173
|
+
#using a receipt
|
174
|
+
alfa.reply_to_all(receipt, "Reply body")
|
175
|
+
|
176
|
+
#using a conversation
|
177
|
+
alfa.reply_to_conversation(conversation, "Reply body")
|
178
|
+
```
|
179
|
+
|
180
|
+
```ruby
|
181
|
+
#alfa wants to reply to the sender of a message (and ONLY the sender)
|
182
|
+
#using a receipt
|
183
|
+
alfa.reply_to_sender(receipt, "Reply body")
|
184
|
+
```
|
185
|
+
|
186
|
+
### How can I retrieve my conversations?
|
187
|
+
|
188
|
+
```ruby
|
189
|
+
#alfa wants to retrieve all his conversations
|
190
|
+
alfa.mailbox.conversations
|
191
|
+
|
192
|
+
#A wants to retrieve his inbox
|
193
|
+
alfa.mailbox.inbox
|
194
|
+
|
195
|
+
#A wants to retrieve his sent conversations
|
196
|
+
alfa.mailbox.sentbox
|
197
|
+
|
198
|
+
#alfa wants to retrieve his trashed conversations
|
199
|
+
alfa.mailbox.trash
|
200
|
+
```
|
201
|
+
|
202
|
+
### How can I paginate conversations?
|
203
|
+
|
204
|
+
You can use Kaminari to paginate the conversations as normal. Please, make sure you use the last version as mailboxer uses `select('DISTINCT conversations.*')` which was not respected before Kaminari 0.12.4 according to its changelog. Working corretly on Kaminari 0.13.0.
|
205
|
+
|
206
|
+
```ruby
|
207
|
+
#Paginating all conversations using :page parameter and 9 per page
|
208
|
+
conversations = alfa.mailbox.conversations.page(params[:page]).per(9)
|
209
|
+
|
210
|
+
#Paginating received conversations using :page parameter and 9 per page
|
211
|
+
conversations = alfa.mailbox.inbox.page(params[:page]).per(9)
|
212
|
+
|
213
|
+
#Paginating sent conversations using :page parameter and 9 per page
|
214
|
+
conversations = alfa.mailbox.sentbox.page(params[:page]).per(9)
|
215
|
+
|
216
|
+
#Paginating trashed conversations using :page parameter and 9 per page
|
217
|
+
conversations = alfa.mailbox.trash.page(params[:page]).per(9)
|
218
|
+
```
|
219
|
+
|
220
|
+
### How can I read the messages of a conversation?
|
221
|
+
|
222
|
+
As a messageable, what you receive receipts wich are linked with the message itself. You should retrieve your receipts for the conversation a get the message associated to them.
|
223
|
+
|
224
|
+
This is done this way because receipts save the information about the relation between messageable and the messages: is it read?, is it trashed?, etc.
|
225
|
+
|
226
|
+
```ruby
|
227
|
+
#alfa gets the last conversation (chronologically, the first in the inbox)
|
228
|
+
conversation = alfa.mailbox.inbox.first
|
229
|
+
|
230
|
+
#alfa gets it receipts chronologically ordered.
|
231
|
+
receipts = conversation.receipts_for alfa
|
232
|
+
|
233
|
+
#using the receipts (i.e. in the view)
|
234
|
+
receipts.each do |receipt|
|
235
|
+
...
|
236
|
+
message = receipt.message
|
237
|
+
read = receipt.is_unread? #or message.is_unread?(alfa)
|
238
|
+
...
|
239
|
+
end
|
240
|
+
```
|
241
|
+
|
242
|
+
You can take a look at the full documentation of Mailboxer in [rubydoc.info](http://rubydoc.info/gems/mailboxer/frames).
|
243
|
+
|
244
|
+
## Do you want to test Mailboxer?
|
245
|
+
|
246
|
+
Thanks to [Roman Kushnir (@RKushnir)](https://github.com/RKushnir/) you can test Mailboxer with this [sample app](https://github.com/RKushnir/mailboxer-app).
|
247
|
+
|
248
|
+
## I need a GUI!
|
249
|
+
|
250
|
+
If you need a GUI you should take a look a this links:
|
251
|
+
|
252
|
+
* The [rails-messaging](https://github.com/frodefi/rails-messaging) project.
|
253
|
+
* The wiki page [GUI Example on a real application](https://github.com/ging/mailboxer/wiki/GUI-Example-on-a-real-application).
|
254
|
+
|
255
|
+
## Contributors
|
256
|
+
* [Roendal](https://github.com/ging/mailboxer/commits/master?author=Roendal) (Eduardo Casanova)
|
257
|
+
* [dickeyxxx](https://github.com/ging/mailboxer/commits/master?author=dickeyxxx) (Jeff Dickey)
|
258
|
+
* [RKushnir](https://github.com/ging/mailboxer/commits/master?author=RKushnir) (Roman Kushnir)
|
259
|
+
* [amaierhofer](https://github.com/ging/mailboxer/commits/master?author=amaierhofer) (Andreas Maierhofer)
|
260
|
+
* [tonydewan](https://github.com/ging/mailboxer/commits/master?author=tonydewan) (Tony Dewan)
|
261
|
+
* [plentz](https://github.com/ging/mailboxer/commits/master?author=plentz) (Diego Plentz)
|
262
|
+
* [laserlemon](https://github.com/ging/mailboxer/commits/master?author=laserlemon) (Steve Richert)
|
263
|
+
* [daveworth](https://github.com/ging/mailboxer/commits/master?author=daveworth) (Dave Worth)
|
264
|
+
* [rafaelgg](https://github.com/ging/mailboxer/commits/master?author=rafaelgg) (Rafael Garcia)
|
265
|
+
* [joshblour](https://github.com/ging/mailboxer/commits/master?author=joshblour) (joshblour)
|
266
|
+
* [iamdeuterium](https://github.com/ging/mailboxer/commits/master?author=iamdeuterium) (iamdeuterium)
|
267
|
+
* [daveworth](https://github.com/ging/mailboxer/commits/master?author=daveworth) (Dave Worth)
|
268
|
+
* [parndt](https://github.com/ging/mailboxer/commits/master?author=parndt) (Philip Arndt)
|
269
|
+
* [atd](https://github.com/ging/mailboxer/commits/master?author=atd) (Antonio Tapiador)
|
270
|
+
* [mobilutz](https://github.com/ging/mailboxer/commits/master?author=mobilutz) (Lutz)
|
271
|
+
* [bennick](https://github.com/ging/mailboxer/commits/master?author=bennick) (Ryan Bennick)
|
272
|
+
* [rjst](https://github.com/ging/mailboxer/commits/master?author=rjst) (Ricardo Trindade)
|
273
|
+
* [fabianoalmeida](https://github.com/ging/mailboxer/commits/master?author=fabianoalmeida) (Fabiano Almeida)
|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
class MessageMailer < ActionMailer::Base
|
2
|
+
default :from => Mailboxer.default_from
|
3
|
+
#Sends and email for indicating a new message or a reply to a receiver.
|
4
|
+
#It calls new_message_email if notifing a new message and reply_message_email
|
5
|
+
#when indicating a reply to an already created conversation.
|
6
|
+
def send_email(message,receiver)
|
7
|
+
if message.conversation.messages.size > 1
|
8
|
+
reply_message_email(message,receiver)
|
9
|
+
else
|
10
|
+
new_message_email(message,receiver)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
include ActionView::Helpers::SanitizeHelper
|
15
|
+
|
16
|
+
#Sends an email for indicating a new message for the receiver
|
17
|
+
def new_message_email(message,receiver)
|
18
|
+
@message = message
|
19
|
+
@receiver = receiver
|
20
|
+
subject = message.subject.to_s
|
21
|
+
subject = strip_tags(subject) unless subject.html_safe?
|
22
|
+
mail :to => receiver.send(Mailboxer.email_method,message),
|
23
|
+
:subject => t('mailboxer.message_mailer.subject_new', :subject => subject),
|
24
|
+
:template_name => 'new_message_email'
|
25
|
+
end
|
26
|
+
|
27
|
+
#Sends and email for indicating a reply in an already created conversation
|
28
|
+
def reply_message_email(message,receiver)
|
29
|
+
@message = message
|
30
|
+
@receiver = receiver
|
31
|
+
subject = message.subject.to_s
|
32
|
+
subject = strip_tags(subject) unless subject.html_safe?
|
33
|
+
mail :to => receiver.send(Mailboxer.email_method,message),
|
34
|
+
:subject => t('mailboxer.message_mailer.subject_reply', :subject => subject),
|
35
|
+
:template_name => 'reply_message_email'
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class NotificationMailer < ActionMailer::Base
|
2
|
+
default :from => Mailboxer.default_from
|
3
|
+
#Sends and email for indicating a new notification to a receiver.
|
4
|
+
#It calls new_notification_email.
|
5
|
+
def send_email(notification,receiver)
|
6
|
+
new_notification_email(notification,receiver)
|
7
|
+
end
|
8
|
+
|
9
|
+
include ActionView::Helpers::SanitizeHelper
|
10
|
+
|
11
|
+
#Sends an email for indicating a new message for the receiver
|
12
|
+
def new_notification_email(notification,receiver)
|
13
|
+
@notification = notification
|
14
|
+
@receiver = receiver
|
15
|
+
subject = notification.subject.to_s
|
16
|
+
subject = strip_tags(subject) unless subject.html_safe?
|
17
|
+
mail :to => receiver.send(Mailboxer.email_method,notification),
|
18
|
+
:subject => t('mailboxer.notification_mailer.subject', :subject => subject),
|
19
|
+
:template_name => 'new_notification_email'
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
class Conversation < ActiveRecord::Base
|
2
|
+
attr_accessible :subject if Rails::VERSION::MAJOR == 3
|
3
|
+
|
4
|
+
has_many :messages, :dependent => :destroy
|
5
|
+
has_many :receipts, :through => :messages
|
6
|
+
|
7
|
+
validates_presence_of :subject
|
8
|
+
|
9
|
+
before_validation :clean
|
10
|
+
|
11
|
+
scope :participant, lambda {|participant|
|
12
|
+
select('DISTINCT conversations.*').
|
13
|
+
where('notifications.type'=> Message.name).
|
14
|
+
order("conversations.updated_at DESC").
|
15
|
+
joins(:receipts).merge(Receipt.recipient(participant))
|
16
|
+
}
|
17
|
+
scope :inbox, lambda {|participant|
|
18
|
+
participant(participant).merge(Receipt.inbox.not_trash)
|
19
|
+
}
|
20
|
+
scope :sentbox, lambda {|participant|
|
21
|
+
participant(participant).merge(Receipt.sentbox.not_trash)
|
22
|
+
}
|
23
|
+
scope :trash, lambda {|participant|
|
24
|
+
participant(participant).merge(Receipt.trash)
|
25
|
+
}
|
26
|
+
scope :unread, lambda {|participant|
|
27
|
+
participant(participant).merge(Receipt.is_unread)
|
28
|
+
}
|
29
|
+
scope :not_trash, lambda {|participant|
|
30
|
+
participant(participant).merge(Receipt.not_trash)
|
31
|
+
}
|
32
|
+
|
33
|
+
#Mark the conversation as read for one of the participants
|
34
|
+
def mark_as_read(participant)
|
35
|
+
return if participant.nil?
|
36
|
+
return self.receipts_for(participant).mark_as_read
|
37
|
+
end
|
38
|
+
|
39
|
+
#Mark the conversation as unread for one of the participants
|
40
|
+
def mark_as_unread(participant)
|
41
|
+
return if participant.nil?
|
42
|
+
return self.receipts_for(participant).mark_as_unread
|
43
|
+
end
|
44
|
+
|
45
|
+
#Move the conversation to the trash for one of the participants
|
46
|
+
def move_to_trash(participant)
|
47
|
+
return if participant.nil?
|
48
|
+
return self.receipts_for(participant).move_to_trash
|
49
|
+
end
|
50
|
+
|
51
|
+
#Takes the conversation out of the trash for one of the participants
|
52
|
+
def untrash(participant)
|
53
|
+
return if participant.nil?
|
54
|
+
return self.receipts_for(participant).untrash
|
55
|
+
end
|
56
|
+
|
57
|
+
#Returns an array of participants
|
58
|
+
def recipients
|
59
|
+
if self.last_message
|
60
|
+
recps = self.last_message.recipients
|
61
|
+
recps = recps.is_a?(Array) ? recps : [recps]
|
62
|
+
return recps
|
63
|
+
end
|
64
|
+
return []
|
65
|
+
end
|
66
|
+
|
67
|
+
#Returns an array of participants
|
68
|
+
def participants
|
69
|
+
return recipients
|
70
|
+
end
|
71
|
+
|
72
|
+
#Originator of the conversation.
|
73
|
+
def originator
|
74
|
+
@originator = self.original_message.sender if @originator.nil?
|
75
|
+
return @originator
|
76
|
+
end
|
77
|
+
|
78
|
+
#First message of the conversation.
|
79
|
+
def original_message
|
80
|
+
@original_message = self.messages.order('created_at').first if @original_message.nil?
|
81
|
+
return @original_message
|
82
|
+
end
|
83
|
+
|
84
|
+
#Sender of the last message.
|
85
|
+
def last_sender
|
86
|
+
@last_sender = self.last_message.sender if @last_sender.nil?
|
87
|
+
return @last_sender
|
88
|
+
end
|
89
|
+
|
90
|
+
#Last message in the conversation.
|
91
|
+
def last_message
|
92
|
+
@last_message = self.messages.order('created_at DESC').first if @last_message.nil?
|
93
|
+
return @last_message
|
94
|
+
end
|
95
|
+
|
96
|
+
#Returns the receipts of the conversation for one participants
|
97
|
+
def receipts_for(participant)
|
98
|
+
return Receipt.conversation(self).recipient(participant)
|
99
|
+
end
|
100
|
+
|
101
|
+
#Returns the number of messages of the conversation
|
102
|
+
def count_messages
|
103
|
+
return Message.conversation(self).count
|
104
|
+
end
|
105
|
+
|
106
|
+
#Returns true if the messageable is a participant of the conversation
|
107
|
+
def is_participant?(participant)
|
108
|
+
return false if participant.nil?
|
109
|
+
return self.receipts_for(participant).count != 0
|
110
|
+
end
|
111
|
+
|
112
|
+
#Returns true if the participant has at least one trashed message of the conversation
|
113
|
+
def is_trashed?(participant)
|
114
|
+
return false if participant.nil?
|
115
|
+
return self.receipts_for(participant).trash.count!=0
|
116
|
+
end
|
117
|
+
|
118
|
+
#Returns true if the participant has trashed all the messages of the conversation
|
119
|
+
def is_completely_trashed?(participant)
|
120
|
+
return false if participant.nil?
|
121
|
+
return self.receipts_for(participant).trash.count == self.receipts_for(participant).count
|
122
|
+
end
|
123
|
+
|
124
|
+
def is_read?(participant)
|
125
|
+
!self.is_unread?(participant)
|
126
|
+
end
|
127
|
+
|
128
|
+
#Returns true if the participant has at least one unread message of the conversation
|
129
|
+
def is_unread?(participant)
|
130
|
+
return false if participant.nil?
|
131
|
+
return self.receipts_for(participant).not_trash.is_unread.count!=0
|
132
|
+
end
|
133
|
+
|
134
|
+
protected
|
135
|
+
|
136
|
+
include ActionView::Helpers::SanitizeHelper
|
137
|
+
|
138
|
+
#Use the default sanitize to clean the conversation subject
|
139
|
+
def clean
|
140
|
+
self.subject = sanitize self.subject
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|