mailboxer 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/.travis.yml +4 -2
- data/Gemfile +2 -2
- data/README.md +239 -0
- data/Rakefile +1 -21
- data/app/models/message.rb +3 -0
- data/app/models/receipt.rb +12 -0
- data/app/uploaders/attachment_uploader.rb +3 -0
- data/lib/generators/mailboxer/install_generator.rb +20 -12
- data/lib/generators/mailboxer/templates/add_attachments.rb +13 -0
- data/{db/migrate/20110912163911_add_notification_code.rb → lib/generators/mailboxer/templates/add_notification_code.rb} +0 -0
- data/{db/migrate/20110719110700_add_notified_object.rb → lib/generators/mailboxer/templates/add_notified_object.rb} +0 -0
- data/{db/migrate/20110511145103_create_mailboxer.rb → lib/generators/mailboxer/templates/create_mailboxer.rb} +0 -0
- data/lib/generators/mailboxer/templates/initializer.rb +8 -3
- data/lib/generators/mailboxer/views_generator.rb +9 -0
- data/lib/mailboxer.rb +7 -1
- data/lib/mailboxer/engine.rb +2 -0
- data/lib/mailboxer/models/messageable.rb +21 -12
- data/mailboxer.gemspec +39 -34
- data/spec/dummy/.gitignore +4 -0
- data/spec/dummy/Gemfile +28 -2
- data/spec/dummy/app/controllers/home_controller.rb +4 -0
- data/spec/dummy/{public/stylesheets → app/mailers}/.gitkeep +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/app/models/cylon.rb +1 -0
- data/spec/dummy/app/models/user.rb +1 -1
- 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/application.rb +3 -6
- data/spec/dummy/config/database.yml +5 -3
- data/spec/dummy/config/environments/development.rb +1 -1
- data/spec/dummy/config/environments/production.rb +1 -1
- data/spec/dummy/config/environments/test.rb +1 -1
- data/spec/dummy/config/initializers/mailboxer.rb +7 -2
- data/spec/dummy/config/initializers/secret_token.rb +1 -1
- data/spec/dummy/config/initializers/session_store.rb +1 -1
- data/spec/dummy/config/locales/en.yml +1 -1
- data/spec/dummy/config/routes.rb +1 -3
- data/spec/dummy/config/sunspot.yml +17 -0
- data/spec/dummy/db/migrate/{20110719111119_create_mailboxer.rb → 20120123185900_create_mailboxer.rb} +0 -0
- data/spec/dummy/db/migrate/{20110719121059_add_notified_object.rb → 20120123185901_add_notified_object.rb} +0 -0
- data/spec/dummy/db/migrate/{20110912170902_add_notification_code.rb → 20120123185902_add_notification_code.rb} +0 -0
- data/spec/dummy/db/migrate/20120123185903_add_attachments.rb +13 -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 +1 -1
- data/spec/integration/message_and_receipt_spec.rb +2 -2
- data/spec/mailers/message_mailer_spec.rb +1 -1
- data/spec/mailers/notification_mailer_spec.rb +2 -2
- data/spec/models/conversation_spec.rb +1 -1
- data/spec/models/mailbox_spec.rb +1 -1
- data/spec/models/mailboxer_models_messageable_spec.rb +6 -2
- data/spec/models/message_spec.rb +1 -1
- data/spec/models/notification_spec.rb +1 -1
- data/spec/models/receipt_spec.rb +1 -1
- data/spec/testfile.txt +1 -0
- metadata +112 -59
- data/README.textile +0 -194
- data/spec/dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/dummy/db/schema.rb +0 -73
- data/spec/dummy/public/javascripts/application.js +0 -2
- data/spec/dummy/public/javascripts/controls.js +0 -965
- data/spec/dummy/public/javascripts/dragdrop.js +0 -974
- data/spec/dummy/public/javascripts/effects.js +0 -1123
- data/spec/dummy/public/javascripts/prototype.js +0 -6001
- data/spec/dummy/public/javascripts/rails.js +0 -191
- data/spec/dummy/public/stylesheets/scaffold.css +0 -56
@@ -0,0 +1 @@
|
|
1
|
+
this is a dummy file to test file uploads
|
data/spec/dummy/script/rails
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe NotificationMailer do
|
4
4
|
before do
|
@@ -58,4 +58,4 @@ def print_emails
|
|
58
58
|
puts email.encoded
|
59
59
|
puts "----------------------------------------------------"
|
60
60
|
end
|
61
|
-
end
|
61
|
+
end
|
data/spec/models/mailbox_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "Mailboxer::Models::Messageable through User" do
|
4
4
|
|
@@ -297,6 +297,10 @@ describe "Mailboxer::Models::Messageable through User" do
|
|
297
297
|
@conversation.receipts_for(@entity1).first.trashed.should==true
|
298
298
|
end
|
299
299
|
|
300
|
+
it "should be able to read attachment" do
|
301
|
+
@receipt = @entity1.send_message(@entity2, "Body", "Subject", nil, File.open('spec/testfile.txt'))
|
302
|
+
@conversation = @receipt.conversation
|
303
|
+
@conversation.messages.first.attachment_identifier.should=='testfile.txt'
|
304
|
+
end
|
300
305
|
|
301
|
-
|
302
306
|
end
|
data/spec/models/message_spec.rb
CHANGED
data/spec/models/receipt_spec.rb
CHANGED
data/spec/testfile.txt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
this is a dummy file to test file uploads
|
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: 5
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 6
|
9
|
-
-
|
10
|
-
version: 0.6.
|
9
|
+
- 1
|
10
|
+
version: 0.6.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Eduardo Casanova Cuesta
|
@@ -15,10 +15,11 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-03-04 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
|
-
|
21
|
+
name: foreigner
|
22
|
+
prerelease: false
|
22
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
23
24
|
none: false
|
24
25
|
requirements:
|
@@ -30,42 +31,60 @@ dependencies:
|
|
30
31
|
- 9
|
31
32
|
- 1
|
32
33
|
version: 0.9.1
|
33
|
-
|
34
|
-
name: foreigner
|
34
|
+
type: :runtime
|
35
35
|
version_requirements: *id001
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
|
-
|
37
|
+
name: rails
|
38
|
+
prerelease: false
|
38
39
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
40
|
none: false
|
40
41
|
requirements:
|
41
|
-
- - "
|
42
|
+
- - ">"
|
42
43
|
- !ruby/object:Gem::Version
|
43
|
-
hash:
|
44
|
+
hash: 7
|
44
45
|
segments:
|
45
46
|
- 3
|
46
|
-
- 1
|
47
47
|
- 0
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
- 0
|
49
|
+
version: 3.0.0
|
50
|
+
type: :runtime
|
51
51
|
version_requirements: *id002
|
52
52
|
- !ruby/object:Gem::Dependency
|
53
|
-
|
53
|
+
name: carrierwave
|
54
|
+
prerelease: false
|
54
55
|
requirement: &id003 !ruby/object:Gem::Requirement
|
55
56
|
none: false
|
56
57
|
requirements:
|
57
58
|
- - ">="
|
58
59
|
- !ruby/object:Gem::Version
|
59
|
-
hash:
|
60
|
+
hash: 27
|
60
61
|
segments:
|
61
62
|
- 0
|
62
|
-
|
63
|
-
|
64
|
-
|
63
|
+
- 5
|
64
|
+
- 8
|
65
|
+
version: 0.5.8
|
66
|
+
type: :runtime
|
65
67
|
version_requirements: *id003
|
66
68
|
- !ruby/object:Gem::Dependency
|
67
|
-
|
69
|
+
name: sunspot_rails
|
70
|
+
prerelease: false
|
68
71
|
requirement: &id004 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 27
|
77
|
+
segments:
|
78
|
+
- 1
|
79
|
+
- 3
|
80
|
+
- 0
|
81
|
+
version: 1.3.0
|
82
|
+
type: :runtime
|
83
|
+
version_requirements: *id004
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: ruby-debug
|
86
|
+
prerelease: false
|
87
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
69
88
|
none: false
|
70
89
|
requirements:
|
71
90
|
- - ">="
|
@@ -76,12 +95,12 @@ dependencies:
|
|
76
95
|
- 10
|
77
96
|
- 3
|
78
97
|
version: 0.10.3
|
79
|
-
prerelease: false
|
80
|
-
name: ruby-debug
|
81
|
-
version_requirements: *id004
|
82
|
-
- !ruby/object:Gem::Dependency
|
83
98
|
type: :development
|
84
|
-
|
99
|
+
version_requirements: *id005
|
100
|
+
- !ruby/object:Gem::Dependency
|
101
|
+
name: rspec-rails
|
102
|
+
prerelease: false
|
103
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
85
104
|
none: false
|
86
105
|
requirements:
|
87
106
|
- - ">="
|
@@ -92,12 +111,12 @@ dependencies:
|
|
92
111
|
- 6
|
93
112
|
- 1
|
94
113
|
version: 2.6.1
|
95
|
-
prerelease: false
|
96
|
-
name: rspec-rails
|
97
|
-
version_requirements: *id005
|
98
|
-
- !ruby/object:Gem::Dependency
|
99
114
|
type: :development
|
100
|
-
|
115
|
+
version_requirements: *id006
|
116
|
+
- !ruby/object:Gem::Dependency
|
117
|
+
name: factory_girl
|
118
|
+
prerelease: false
|
119
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
101
120
|
none: false
|
102
121
|
requirements:
|
103
122
|
- - ">="
|
@@ -108,12 +127,12 @@ dependencies:
|
|
108
127
|
- 3
|
109
128
|
- 2
|
110
129
|
version: 1.3.2
|
111
|
-
prerelease: false
|
112
|
-
name: factory_girl
|
113
|
-
version_requirements: *id006
|
114
|
-
- !ruby/object:Gem::Dependency
|
115
130
|
type: :development
|
116
|
-
|
131
|
+
version_requirements: *id007
|
132
|
+
- !ruby/object:Gem::Dependency
|
133
|
+
name: forgery
|
134
|
+
prerelease: false
|
135
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
117
136
|
none: false
|
118
137
|
requirements:
|
119
138
|
- - ">="
|
@@ -124,12 +143,12 @@ dependencies:
|
|
124
143
|
- 3
|
125
144
|
- 6
|
126
145
|
version: 0.3.6
|
127
|
-
prerelease: false
|
128
|
-
name: forgery
|
129
|
-
version_requirements: *id007
|
130
|
-
- !ruby/object:Gem::Dependency
|
131
146
|
type: :development
|
132
|
-
|
147
|
+
version_requirements: *id008
|
148
|
+
- !ruby/object:Gem::Dependency
|
149
|
+
name: capybara
|
150
|
+
prerelease: false
|
151
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
133
152
|
none: false
|
134
153
|
requirements:
|
135
154
|
- - ">="
|
@@ -140,9 +159,38 @@ dependencies:
|
|
140
159
|
- 3
|
141
160
|
- 9
|
142
161
|
version: 0.3.9
|
162
|
+
type: :development
|
163
|
+
version_requirements: *id009
|
164
|
+
- !ruby/object:Gem::Dependency
|
165
|
+
name: sunspot_solr
|
143
166
|
prerelease: false
|
144
|
-
|
145
|
-
|
167
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
168
|
+
none: false
|
169
|
+
requirements:
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
hash: 27
|
173
|
+
segments:
|
174
|
+
- 1
|
175
|
+
- 3
|
176
|
+
- 0
|
177
|
+
version: 1.3.0
|
178
|
+
type: :development
|
179
|
+
version_requirements: *id010
|
180
|
+
- !ruby/object:Gem::Dependency
|
181
|
+
name: sqlite3-ruby
|
182
|
+
prerelease: false
|
183
|
+
requirement: &id011 !ruby/object:Gem::Requirement
|
184
|
+
none: false
|
185
|
+
requirements:
|
186
|
+
- - ">="
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
hash: 3
|
189
|
+
segments:
|
190
|
+
- 0
|
191
|
+
version: "0"
|
192
|
+
type: :development
|
193
|
+
version_requirements: *id011
|
146
194
|
description: A Rails engine that allows any model to act as messageable, allowing it to exchange messages with any other messageable model, even different ones. It supports the use of conversations with two or more recipients to organize the messages. You have a complete use of a mailbox object for each messageable model that manages an inbox, sentbox and trash for conversations. It also supports sending notifications to messageable models, intended to be used as system notifications.
|
147
195
|
email: ecasanovac@gmail.com
|
148
196
|
executables: []
|
@@ -158,7 +206,7 @@ files:
|
|
158
206
|
- .yardopts
|
159
207
|
- Gemfile
|
160
208
|
- LICENSE.txt
|
161
|
-
- README.
|
209
|
+
- README.md
|
162
210
|
- Rakefile
|
163
211
|
- VERSION
|
164
212
|
- app/mailers/message_mailer.rb
|
@@ -168,6 +216,7 @@ files:
|
|
168
216
|
- app/models/message.rb
|
169
217
|
- app/models/notification.rb
|
170
218
|
- app/models/receipt.rb
|
219
|
+
- app/uploaders/attachment_uploader.rb
|
171
220
|
- app/views/message_mailer/new_message_email.html.erb
|
172
221
|
- app/views/message_mailer/new_message_email.text.erb
|
173
222
|
- app/views/message_mailer/reply_message_email.html.erb
|
@@ -175,23 +224,30 @@ files:
|
|
175
224
|
- app/views/notification_mailer/new_notification_email.html.erb
|
176
225
|
- app/views/notification_mailer/new_notification_email.text.erb
|
177
226
|
- config/locales/en.yml
|
178
|
-
- db/migrate/20110511145103_create_mailboxer.rb
|
179
|
-
- db/migrate/20110719110700_add_notified_object.rb
|
180
|
-
- db/migrate/20110912163911_add_notification_code.rb
|
181
227
|
- lib/generators/mailboxer/install_generator.rb
|
228
|
+
- lib/generators/mailboxer/templates/add_attachments.rb
|
229
|
+
- lib/generators/mailboxer/templates/add_notification_code.rb
|
230
|
+
- lib/generators/mailboxer/templates/add_notified_object.rb
|
231
|
+
- lib/generators/mailboxer/templates/create_mailboxer.rb
|
182
232
|
- lib/generators/mailboxer/templates/initializer.rb
|
233
|
+
- lib/generators/mailboxer/views_generator.rb
|
183
234
|
- lib/mailboxer.rb
|
184
235
|
- lib/mailboxer/engine.rb
|
185
236
|
- lib/mailboxer/models/messageable.rb
|
186
237
|
- mailboxer.gemspec
|
238
|
+
- spec/dummy/.gitignore
|
187
239
|
- spec/dummy/Gemfile
|
188
240
|
- spec/dummy/Rakefile
|
189
241
|
- spec/dummy/app/controllers/application_controller.rb
|
242
|
+
- spec/dummy/app/controllers/home_controller.rb
|
190
243
|
- spec/dummy/app/helpers/application_helper.rb
|
244
|
+
- spec/dummy/app/mailers/.gitkeep
|
245
|
+
- spec/dummy/app/models/.gitkeep
|
191
246
|
- spec/dummy/app/models/cylon.rb
|
192
247
|
- spec/dummy/app/models/duck.rb
|
193
248
|
- spec/dummy/app/models/user.rb
|
194
|
-
- spec/dummy/app/views/
|
249
|
+
- spec/dummy/app/views/home/index.html.haml
|
250
|
+
- spec/dummy/app/views/layouts/application.html.haml
|
195
251
|
- spec/dummy/config.ru
|
196
252
|
- spec/dummy/config/application.rb
|
197
253
|
- spec/dummy/config/boot.rb
|
@@ -208,25 +264,21 @@ files:
|
|
208
264
|
- spec/dummy/config/initializers/session_store.rb
|
209
265
|
- spec/dummy/config/locales/en.yml
|
210
266
|
- spec/dummy/config/routes.rb
|
267
|
+
- spec/dummy/config/sunspot.yml
|
211
268
|
- spec/dummy/db/migrate/20110228120600_create_users.rb
|
212
269
|
- spec/dummy/db/migrate/20110306002940_create_ducks.rb
|
213
270
|
- spec/dummy/db/migrate/20110306015107_create_cylons.rb
|
214
|
-
- spec/dummy/db/migrate/
|
215
|
-
- spec/dummy/db/migrate/
|
216
|
-
- spec/dummy/db/migrate/
|
217
|
-
- spec/dummy/db/
|
271
|
+
- spec/dummy/db/migrate/20120123185900_create_mailboxer.rb
|
272
|
+
- spec/dummy/db/migrate/20120123185901_add_notified_object.rb
|
273
|
+
- spec/dummy/db/migrate/20120123185902_add_notification_code.rb
|
274
|
+
- spec/dummy/db/migrate/20120123185903_add_attachments.rb
|
218
275
|
- spec/dummy/public/404.html
|
219
276
|
- spec/dummy/public/422.html
|
220
277
|
- spec/dummy/public/500.html
|
221
278
|
- spec/dummy/public/favicon.ico
|
222
|
-
- spec/dummy/public/
|
223
|
-
- spec/dummy/public/
|
224
|
-
- spec/dummy/public/
|
225
|
-
- spec/dummy/public/javascripts/effects.js
|
226
|
-
- spec/dummy/public/javascripts/prototype.js
|
227
|
-
- spec/dummy/public/javascripts/rails.js
|
228
|
-
- spec/dummy/public/stylesheets/.gitkeep
|
229
|
-
- spec/dummy/public/stylesheets/scaffold.css
|
279
|
+
- spec/dummy/public/index.html
|
280
|
+
- spec/dummy/public/robots.txt
|
281
|
+
- spec/dummy/public/uploads/testfile.txt
|
230
282
|
- spec/dummy/script/rails
|
231
283
|
- spec/factories/cylon.rb
|
232
284
|
- spec/factories/duck.rb
|
@@ -243,6 +295,7 @@ files:
|
|
243
295
|
- spec/models/notification_spec.rb
|
244
296
|
- spec/models/receipt_spec.rb
|
245
297
|
- spec/spec_helper.rb
|
298
|
+
- spec/testfile.txt
|
246
299
|
homepage: https://github.com/ging/mailboxer
|
247
300
|
licenses: []
|
248
301
|
|
data/README.textile
DELETED
@@ -1,194 +0,0 @@
|
|
1
|
-
h1. Mailboxer 0.6.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 / social_stream":https://github.com/ging/social_stream. Instead of creating our core message system heavily dependent on our development we are trying to implement a generic and potent messaging gem.
|
4
|
-
|
5
|
-
After looking for a good gem to use we notice the lack of messaging gems and functionality in them. Mailboxer tries to fill this emptiness giving a powerfull and generic message system. It supports the use of conversations with two or more recipients, send notification to a recipient (intended to be used as system notifications "Your picture has new comments", "John Doe has updated its document", etc.), emails the messageable model (if configured to do so). It has a complete use of a @Mailbox@ object for each messageable with @inbox@, @sentbox@ and @trash@.
|
6
|
-
|
7
|
-
The gem is constantly growing and improving its functionality. As it is used with our paralell development "(ging / social_stream)":https://github.com/ging/social_stream we are finding and fixing bugs continously. If you want some functionality not supported yet or marked as TODO, you can create an "issue":https://github.com/ging/mailboxer/issues to ask for it. It will be a great feedback for us, and we will know what you may find useful of the gem.
|
8
|
-
|
9
|
-
Mailboxer was born from the great, but outdated, code from "lpsergi / acts_as_messageable":https://github.com/psergi/acts_as_messageable.
|
10
|
-
|
11
|
-
We are now working to make an exhaustive documentation and some wiki pages in order to make even easier to use the gem at its full potencial. Please, give us some time if you find something missing or "ask for it":https://github.com/ging/mailboxer/issues.
|
12
|
-
|
13
|
-
h2. Installation
|
14
|
-
|
15
|
-
Add to your Gemfile:
|
16
|
-
<pre><code>
|
17
|
-
gem 'mailboxer'
|
18
|
-
</code></pre>
|
19
|
-
Then run:
|
20
|
-
<pre><code>
|
21
|
-
bundle update
|
22
|
-
</code></pre>
|
23
|
-
Run install script:
|
24
|
-
<pre><code>
|
25
|
-
rails g mailboxer:install
|
26
|
-
</code></pre>
|
27
|
-
And don't forget to migrate you database:
|
28
|
-
<pre><code>
|
29
|
-
rake db:migrate
|
30
|
-
</code></pre>
|
31
|
-
|
32
|
-
h2. Requirements & Settings
|
33
|
-
|
34
|
-
h3. Emails
|
35
|
-
|
36
|
-
We are now adding support for sending emails when a Notification or a Message is sent to one o more recipients. You should modify mailboxer initializer (/config/initializer/mailboxer.rb) to edit this settings.
|
37
|
-
<pre><code>
|
38
|
-
Mailboxer.setup do |config|
|
39
|
-
...
|
40
|
-
#Configures if you applications uses or no the email sending for Notifications and Messages
|
41
|
-
config.uses_emails = true
|
42
|
-
#Configures the default from for the email sent for Messages and Notifications of Mailboxer
|
43
|
-
config.default_from = "no-reply@dit.upm.es"
|
44
|
-
...
|
45
|
-
end
|
46
|
-
</code></pre>
|
47
|
-
|
48
|
-
h3. User identities
|
49
|
-
|
50
|
-
Users must have an identity defined by a @name@ and an @email@. So that, we must assure that Messageable models have some specific methods. These methods are:
|
51
|
-
<pre><code>
|
52
|
-
#Returning any kind of identification you want for the model
|
53
|
-
def name
|
54
|
-
return "You should add method :name in your Messageable model"
|
55
|
-
end
|
56
|
-
</code></pre>
|
57
|
-
<pre><code>
|
58
|
-
#Returning the email address of the model if an email should be sent for this object (Message or Notification).
|
59
|
-
#If no mail has to be sent, return nil.
|
60
|
-
def mailboxer_email(object)
|
61
|
-
#Check if an email should be sent for that object
|
62
|
-
#if true
|
63
|
-
return "define_email@on_your.model"
|
64
|
-
#if false
|
65
|
-
#return nil
|
66
|
-
end
|
67
|
-
</code></pre>
|
68
|
-
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:
|
69
|
-
<pre><code>
|
70
|
-
Mailboxer.setup do |config|
|
71
|
-
...
|
72
|
-
#Configures the methods needed by mailboxer
|
73
|
-
config.email_method = :mailboxer_email
|
74
|
-
config.name_method = :name
|
75
|
-
...
|
76
|
-
end
|
77
|
-
</code></pre>
|
78
|
-
You may change whatever you want or need. For example:
|
79
|
-
<pre><code>
|
80
|
-
Mailboxer.setup do |config|
|
81
|
-
...
|
82
|
-
#Configures the methods needed by mailboxer
|
83
|
-
config.email_method = :notifications_email #instead of :mailboxer_email
|
84
|
-
config.name_method = :display_name #instead of :display_name
|
85
|
-
...
|
86
|
-
end
|
87
|
-
</code></pre>
|
88
|
-
Will use the method @notification_email(object)@ instead of @mailboxer_email(object)@ and @display_name@ for @name@
|
89
|
-
|
90
|
-
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.
|
91
|
-
|
92
|
-
h2. Preparing your models
|
93
|
-
|
94
|
-
In your model:
|
95
|
-
<pre><code>
|
96
|
-
class User < ActiveRecord::Base
|
97
|
-
acts_as_messageable
|
98
|
-
end
|
99
|
-
</code></pre>
|
100
|
-
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. Example:
|
101
|
-
<pre><code>
|
102
|
-
class Duck < ActiveRecord::Base
|
103
|
-
acts_as_messageable
|
104
|
-
end
|
105
|
-
</code></pre>
|
106
|
-
<pre><code>
|
107
|
-
class Cylon < ActiveRecord::Base
|
108
|
-
acts_as_messageable
|
109
|
-
end
|
110
|
-
</code></pre>
|
111
|
-
|
112
|
-
h2. Mailboxer API
|
113
|
-
|
114
|
-
h3. How can I send a message?
|
115
|
-
|
116
|
-
<pre><code>
|
117
|
-
#alfa wants to send a message to beta
|
118
|
-
alfa.send_message(beta, "Body", "subject")
|
119
|
-
</code></pre>
|
120
|
-
|
121
|
-
h3. How can I reply a message?
|
122
|
-
|
123
|
-
<pre><code>
|
124
|
-
#alfa wants to reply to all in a conversation
|
125
|
-
#using a receipt
|
126
|
-
alfa.reply_to_all(receipt, "Reply body")
|
127
|
-
#using a conversation
|
128
|
-
alfa.reply_to_conversation(conversation, "Reply body")
|
129
|
-
</code></pre>
|
130
|
-
<pre><code>
|
131
|
-
#alfa wants to reply to the sender of a message (and ONLY the sender)
|
132
|
-
#using a receipt
|
133
|
-
alfa.reply_to_sender(receipt, "Reply body")
|
134
|
-
</code></pre>
|
135
|
-
|
136
|
-
h3. How can I retrieve my conversations?
|
137
|
-
|
138
|
-
<pre><code>
|
139
|
-
#alfa wants to retrieve all his conversations
|
140
|
-
alfa.mailbox.conversations
|
141
|
-
#A wants to retrieve his inbox
|
142
|
-
alfa.mailbox.inbox
|
143
|
-
#A wants to retrieve his sent conversations
|
144
|
-
alfa.mailbox.sentbox
|
145
|
-
#alfa wants to retrieve his trashed conversations
|
146
|
-
alfa.mailbox.trash
|
147
|
-
</code></pre>
|
148
|
-
|
149
|
-
h3. How can I paginate conversations?
|
150
|
-
|
151
|
-
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.
|
152
|
-
<pre><code>
|
153
|
-
#Paginating all conversations using :page parameter and 9 per page
|
154
|
-
conversations = alfa.mailbox.conversations.page(params[:page]).per(9)
|
155
|
-
#Paginating received conversations using :page parameter and 9 per page
|
156
|
-
conversations = alfa.mailbox.inbox.page(params[:page]).per(9)
|
157
|
-
#Paginating sent conversations using :page parameter and 9 per page
|
158
|
-
conversations = alfa.mailbox.sentbox.page(params[:page]).per(9)
|
159
|
-
#Paginating trashed conversations using :page parameter and 9 per page
|
160
|
-
conversations = alfa.mailbox.trash.page(params[:page]).per(9)
|
161
|
-
</code></pre>
|
162
|
-
|
163
|
-
h3. How can I read the messages of a conversation?
|
164
|
-
|
165
|
-
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.
|
166
|
-
|
167
|
-
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.
|
168
|
-
<pre><code>
|
169
|
-
#alfa gets the last conversation (chronologically, the first in the inbox)
|
170
|
-
conversation = alfa.mailbox.inbox.first
|
171
|
-
#alfa gets it receipts chronologically ordered.
|
172
|
-
receipts = conversation.receipts_for alfa
|
173
|
-
#using the receipts (i.e. in the view)
|
174
|
-
receipts.each do |receipt|
|
175
|
-
...
|
176
|
-
message = receipt.message
|
177
|
-
read = receipt.is_unread? #or message.is_unread?(alfa)
|
178
|
-
...
|
179
|
-
end
|
180
|
-
</code></pre>
|
181
|
-
|
182
|
-
h3. Any other thing ...
|
183
|
-
|
184
|
-
You can take a look at the full documentation of Mailboxer in "rubydoc.info":http://rubydoc.info/gems/mailboxer/frames.
|
185
|
-
|
186
|
-
h2. License
|
187
|
-
|
188
|
-
Copyright (c) 2012 Eduardo Casanova Cuesta
|
189
|
-
|
190
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
191
|
-
|
192
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
193
|
-
|
194
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|