notification-settings 1.2.5 → 1.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +21 -21
- data/README.md +271 -271
- data/app/models/notification_settings/setting.rb +15 -13
- data/app/models/notification_settings/subscription.rb +15 -13
- data/lib/generators/notification_settings/install_generator.rb +40 -43
- data/lib/generators/templates/install/initializer.rb +28 -24
- data/lib/generators/templates/install/notifications_migration.rb.erb +27 -29
- data/lib/notification-settings.rb +15 -15
- data/lib/notification_settings/configuration.rb +30 -32
- data/lib/notification_settings/engine.rb +9 -7
- data/lib/notification_settings/notification_library.rb +144 -72
- data/lib/notification_settings/notification_scopes.rb +28 -30
- data/lib/notification_settings/setting_library.rb +60 -28
- data/lib/notification_settings/subscribable.rb +50 -42
- data/lib/notification_settings/subscriber.rb +35 -30
- data/lib/notification_settings/subscription_library.rb +23 -25
- data/lib/notification_settings/target.rb +27 -26
- metadata +46 -34
- data/CHANGELOG.md +0 -59
- data/lib/generators/templates/install/README.md +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4193e47d53d1953047f50b4e5d47cced6258e9bfb55a95f65e8bf387025cce93
|
4
|
+
data.tar.gz: 967ff77853953c85928e67b1ba76091c8ddd97111f7207ed5c53271dfe1b594f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e744b92cb72fc7b3bc1c4e3b278a9e31c0a3cd915986cd913b7adcf49db1809e70569ef88c9719dfeed66ffeaf527ad5fe0517acaf3190f31bdcc0556ca9af9
|
7
|
+
data.tar.gz: 163007c12e9559d559defa7fe71982c58fc6a2f7b46887843cbe7fd06f3e0375e1ffda7e062c3adcf6f7b8b397b5607afccb7dfbaa7219b7644e159623acf326
|
data/LICENSE
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
MIT License
|
2
|
-
|
3
|
-
Copyright (c) 2017 Jonas Hübotter
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
13
|
-
copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
SOFTWARE.
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017 Jonas Hübotter
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -1,271 +1,271 @@
|
|
1
|
-
# NotificationSettings
|
2
|
-
|
3
|
-
[![Gem Version](https://badge.fury.io/rb/notification-settings.svg)](https://badge.fury.io/rb/notification-settings) <img src="https://travis-ci.org/jonhue/notifications-rails.svg?branch=master" />
|
4
|
-
|
5
|
-
Integrates with your authentication solution to craft a personalized user notification platform.
|
6
|
-
|
7
|
-
---
|
8
|
-
|
9
|
-
## Table of Contents
|
10
|
-
|
11
|
-
* [Installation](#installation)
|
12
|
-
* [Usage](#usage)
|
13
|
-
* [Categories](#categories)
|
14
|
-
* [Settings](#settings)
|
15
|
-
* [Category specific settings](#category-specific-settings)
|
16
|
-
* [Pusher specific settings](#pusher-specific-settings)
|
17
|
-
* [Updating settings](#updating-settings)
|
18
|
-
* [Subscriptions](#subscriptions)
|
19
|
-
* [Status](#status)
|
20
|
-
* [Configuration](#configuration)
|
21
|
-
* [Status](#status)
|
22
|
-
* [To Do](#to-do)
|
23
|
-
* [Contributing](#contributing)
|
24
|
-
* [Contributors](#contributors)
|
25
|
-
* [Semantic versioning](#semantic-versioning)
|
26
|
-
* [License](#license)
|
27
|
-
|
28
|
-
---
|
29
|
-
|
30
|
-
## Installation
|
31
|
-
|
32
|
-
NotificationSettings works with Rails 5 onwards. You can add it to your `Gemfile` with:
|
33
|
-
|
34
|
-
```ruby
|
35
|
-
gem 'notification-settings'
|
36
|
-
```
|
37
|
-
|
38
|
-
And then execute:
|
39
|
-
|
40
|
-
$ bundle
|
41
|
-
|
42
|
-
Or install it yourself as:
|
43
|
-
|
44
|
-
$ gem install notification-settings
|
45
|
-
|
46
|
-
If you always want to be up to date fetch the latest from GitHub in your `Gemfile`:
|
47
|
-
|
48
|
-
```ruby
|
49
|
-
gem 'notification-settings', github: 'jonhue/notifications-rails'
|
50
|
-
```
|
51
|
-
|
52
|
-
Now run the generator:
|
53
|
-
|
54
|
-
$ rails g notification_settings:install
|
55
|
-
|
56
|
-
To wrap things up, migrate the changes to your database:
|
57
|
-
|
58
|
-
$ rails db:migrate
|
59
|
-
|
60
|
-
---
|
61
|
-
|
62
|
-
## Usage
|
63
|
-
|
64
|
-
NotificationSettings will create a `NotificationSettings::Setting` record for every newly created `notification_target`-object. It is accessible by calling:
|
65
|
-
|
66
|
-
```ruby
|
67
|
-
User.first.notification_setting
|
68
|
-
```
|
69
|
-
|
70
|
-
### Categories
|
71
|
-
|
72
|
-
NotificationSettings uses categories to allow your notification targets to define specific preferences. This is how you are able to specify the `category` of a `Notification` record:
|
73
|
-
|
74
|
-
```ruby
|
75
|
-
notification = Notification.create target: User.first, object: Recipe.first, category: 'notification'
|
76
|
-
```
|
77
|
-
|
78
|
-
**Note:** The `category` attribute of any new `Notification` record will default to the [`default_category` configuration](#configuration).
|
79
|
-
|
80
|
-
You can also scope records by their category:
|
81
|
-
|
82
|
-
```ruby
|
83
|
-
# Return records with `'notification'` as category
|
84
|
-
Notification.notification_category
|
85
|
-
|
86
|
-
# Return records with `'follow'` as category
|
87
|
-
Notification.follow_category
|
88
|
-
```
|
89
|
-
|
90
|
-
### Settings
|
91
|
-
|
92
|
-
You can disable notifications for a given notification target:
|
93
|
-
|
94
|
-
```ruby
|
95
|
-
s = User.first.notification_setting
|
96
|
-
s.settings[:enabled] = false
|
97
|
-
```
|
98
|
-
|
99
|
-
This will prevent you from creating any new notifications with this user as target.
|
100
|
-
|
101
|
-
#### Category specific settings
|
102
|
-
|
103
|
-
A user can also have category specific settings:
|
104
|
-
|
105
|
-
```ruby
|
106
|
-
s.category_settings[:category] = { enabled: false }
|
107
|
-
```
|
108
|
-
|
109
|
-
#### Pusher specific settings
|
110
|
-
|
111
|
-
He can have global or category specific pusher settings:
|
112
|
-
|
113
|
-
```ruby
|
114
|
-
s.settings[:ActionMailer] = false
|
115
|
-
s.category_settings[:category] = { ActionMailer: false }
|
116
|
-
```
|
117
|
-
|
118
|
-
#### Updating settings
|
119
|
-
|
120
|
-
...
|
121
|
-
|
122
|
-
### Subscriptions
|
123
|
-
|
124
|
-
Subscriptions are a way to better handle settings for notifications from different objects to one notification target.
|
125
|
-
|
126
|
-
This is how to subscribe/unsubscribe a target to an object:
|
127
|
-
|
128
|
-
```ruby
|
129
|
-
User.first.subscribe Recipe.first
|
130
|
-
User.first.unsubscribe Recipe.first
|
131
|
-
```
|
132
|
-
|
133
|
-
Now you can easily notify all subscribers from the subscribable object:
|
134
|
-
|
135
|
-
```ruby
|
136
|
-
Recipe.first.notify_subscribers push: :ActionMailer
|
137
|
-
```
|
138
|
-
|
139
|
-
Let's assume that we have a group which has multiple chats. When sending notifications to subscribers of a given chat, we only want them to get notified. But when sending notifications about the group, we want to have everyone notified, that is either subscribed to the group or subscribed to one of its chats. To do that you have to add the `private` method `notification_dependents` to your model (in this case `Group`) and return an array of ActiveRecord objects whose subscribers should receive notifications for objects of this class.
|
140
|
-
|
141
|
-
```ruby
|
142
|
-
has_many :chats
|
143
|
-
has_many :talks
|
144
|
-
|
145
|
-
private
|
146
|
-
|
147
|
-
def notification_dependents
|
148
|
-
self.chats
|
149
|
-
end
|
150
|
-
```
|
151
|
-
|
152
|
-
It is possible to override that behavior when notifying subscribers:
|
153
|
-
|
154
|
-
```ruby
|
155
|
-
# Disable notification dependents
|
156
|
-
Group.first.notify_subscribers dependents: nil
|
157
|
-
|
158
|
-
# Override notification dependents
|
159
|
-
Group.first.notify_subscribers dependents: Group.first.chats + Group.first.talks
|
160
|
-
```
|
161
|
-
|
162
|
-
You can customize settings for a single subscription just as you would for a notification target:
|
163
|
-
|
164
|
-
```ruby
|
165
|
-
s = User.first.notification_subscriptions.first.notification_setting
|
166
|
-
s.settings[:enabled] = false
|
167
|
-
```
|
168
|
-
|
169
|
-
[Learn more](#settings)
|
170
|
-
|
171
|
-
### Status
|
172
|
-
|
173
|
-
NotificationSettings comes with a handy feature called Status. The status of a record can temporarily disable the ability to create notifications for or to push notifications of a target.
|
174
|
-
|
175
|
-
This is how to define a status:
|
176
|
-
|
177
|
-
```ruby
|
178
|
-
User.first.notification_setting.status = 'do not disturb'
|
179
|
-
User.first.notification_setting.save
|
180
|
-
```
|
181
|
-
|
182
|
-
**Note:** You can set `status` to any string you like.
|
183
|
-
|
184
|
-
`status` has three possible values that are being used as defaults. Normally it defaults to `'online'`. If the `last_seen` [configuration](#configuration) option has been set, it can also default to `'idle'` or `'offline'` depending on the `idle_after` and `offline_after` [configuration](#configuration) options.
|
185
|
-
|
186
|
-
If you have set `status` to a custom value, you can get back to using the defaults by setting it back to `nil`.
|
187
|
-
|
188
|
-
You can define statuses that prevent creating new notifications for a target and statuses that just prevent pushing them:
|
189
|
-
|
190
|
-
```ruby
|
191
|
-
NotificationSettings.configure do |config|
|
192
|
-
config.do_not_notify_statuses = ['do not notify']
|
193
|
-
config.do_not_push_statuses = ['do not disturb']
|
194
|
-
end
|
195
|
-
```
|
196
|
-
|
197
|
-
---
|
198
|
-
|
199
|
-
## Configuration
|
200
|
-
|
201
|
-
You can configure NotificationSettings by passing a block to `configure`. This can be done in `config/initializers/notification-settings.rb`:
|
202
|
-
|
203
|
-
```ruby
|
204
|
-
NotificationSettings.configure do |config|
|
205
|
-
config.default_category = 'notification'
|
206
|
-
end
|
207
|
-
```
|
208
|
-
|
209
|
-
**`default_category`** Choose your default notification category. Takes a string. Defaults to `'notification'`.
|
210
|
-
|
211
|
-
### Status
|
212
|
-
|
213
|
-
**`idle_after`** Time duration without activity after which the status defaults to `'idle'`. Takes a time. Defaults to `10.minutes`.
|
214
|
-
|
215
|
-
**`offline_after`** Time duration without activity after which the status defaults to `'offline'`. Takes a time. Defaults to `3.hours`.
|
216
|
-
|
217
|
-
**`last_seen`** Stringified datetime attribute name of `object` that defines the time of the last activity. Takes a string. Defaults to `'last_seen'`.
|
218
|
-
|
219
|
-
**`do_not_notify_statuses`** Array of possible statuses that will prevent creating notifications for a target. Takes an array of strings. Defaults to `[]`.
|
220
|
-
|
221
|
-
**`do_not_push_statuses`** Array of possible statuses that will prevent pushing notifications of a target. Takes an array of strings. Defaults to `['do not disturb']`
|
222
|
-
|
223
|
-
---
|
224
|
-
|
225
|
-
## To Do
|
226
|
-
|
227
|
-
[Here](https://github.com/jonhue/notifications-rails/projects/4) is the full list of current projects.
|
228
|
-
|
229
|
-
To propose your ideas, initiate the discussion by adding a [new issue](https://github.com/jonhue/notifications-rails/issues/new).
|
230
|
-
|
231
|
-
---
|
232
|
-
|
233
|
-
## Contributing
|
234
|
-
|
235
|
-
We hope that you will consider contributing to NotificationSettings. Please read this short overview for some information about how to get started:
|
236
|
-
|
237
|
-
[Learn more about contributing to this repository](https://github.com/jonhue/notifications-rails/blob/master/CONTRIBUTING.md), [Code of Conduct](https://github.com/jonhue/notifications-rails/blob/master/CODE_OF_CONDUCT.md)
|
238
|
-
|
239
|
-
### Contributors
|
240
|
-
|
241
|
-
Give the people some :heart: who are working on this project. See them all at:
|
242
|
-
|
243
|
-
https://github.com/jonhue/notifications-rails/graphs/contributors
|
244
|
-
|
245
|
-
### Semantic Versioning
|
246
|
-
|
247
|
-
NotificationSettings follows Semantic Versioning 2.0 as defined at http://semver.org.
|
248
|
-
|
249
|
-
## License
|
250
|
-
|
251
|
-
MIT License
|
252
|
-
|
253
|
-
Copyright (c) 2017 Jonas Hübotter
|
254
|
-
|
255
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
256
|
-
of this software and associated documentation files (the "Software"), to deal
|
257
|
-
in the Software without restriction, including without limitation the rights
|
258
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
259
|
-
copies of the Software, and to permit persons to whom the Software is
|
260
|
-
furnished to do so, subject to the following conditions:
|
261
|
-
|
262
|
-
The above copyright notice and this permission notice shall be included in all
|
263
|
-
copies or substantial portions of the Software.
|
264
|
-
|
265
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
266
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
267
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
268
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
269
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
270
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
271
|
-
SOFTWARE.
|
1
|
+
# NotificationSettings
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/notification-settings.svg)](https://badge.fury.io/rb/notification-settings) <img src="https://travis-ci.org/jonhue/notifications-rails.svg?branch=master" />
|
4
|
+
|
5
|
+
Integrates with your authentication solution to craft a personalized user notification platform.
|
6
|
+
|
7
|
+
---
|
8
|
+
|
9
|
+
## Table of Contents
|
10
|
+
|
11
|
+
* [Installation](#installation)
|
12
|
+
* [Usage](#usage)
|
13
|
+
* [Categories](#categories)
|
14
|
+
* [Settings](#settings)
|
15
|
+
* [Category specific settings](#category-specific-settings)
|
16
|
+
* [Pusher specific settings](#pusher-specific-settings)
|
17
|
+
* [Updating settings](#updating-settings)
|
18
|
+
* [Subscriptions](#subscriptions)
|
19
|
+
* [Status](#status)
|
20
|
+
* [Configuration](#configuration)
|
21
|
+
* [Status](#status)
|
22
|
+
* [To Do](#to-do)
|
23
|
+
* [Contributing](#contributing)
|
24
|
+
* [Contributors](#contributors)
|
25
|
+
* [Semantic versioning](#semantic-versioning)
|
26
|
+
* [License](#license)
|
27
|
+
|
28
|
+
---
|
29
|
+
|
30
|
+
## Installation
|
31
|
+
|
32
|
+
NotificationSettings works with Rails 5 onwards. You can add it to your `Gemfile` with:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
gem 'notification-settings'
|
36
|
+
```
|
37
|
+
|
38
|
+
And then execute:
|
39
|
+
|
40
|
+
$ bundle
|
41
|
+
|
42
|
+
Or install it yourself as:
|
43
|
+
|
44
|
+
$ gem install notification-settings
|
45
|
+
|
46
|
+
If you always want to be up to date fetch the latest from GitHub in your `Gemfile`:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
gem 'notification-settings', github: 'jonhue/notifications-rails'
|
50
|
+
```
|
51
|
+
|
52
|
+
Now run the generator:
|
53
|
+
|
54
|
+
$ rails g notification_settings:install
|
55
|
+
|
56
|
+
To wrap things up, migrate the changes to your database:
|
57
|
+
|
58
|
+
$ rails db:migrate
|
59
|
+
|
60
|
+
---
|
61
|
+
|
62
|
+
## Usage
|
63
|
+
|
64
|
+
NotificationSettings will create a `NotificationSettings::Setting` record for every newly created `notification_target`-object. It is accessible by calling:
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
User.first.notification_setting
|
68
|
+
```
|
69
|
+
|
70
|
+
### Categories
|
71
|
+
|
72
|
+
NotificationSettings uses categories to allow your notification targets to define specific preferences. This is how you are able to specify the `category` of a `Notification` record:
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
notification = Notification.create target: User.first, object: Recipe.first, category: 'notification'
|
76
|
+
```
|
77
|
+
|
78
|
+
**Note:** The `category` attribute of any new `Notification` record will default to the [`default_category` configuration](#configuration).
|
79
|
+
|
80
|
+
You can also scope records by their category:
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
# Return records with `'notification'` as category
|
84
|
+
Notification.notification_category
|
85
|
+
|
86
|
+
# Return records with `'follow'` as category
|
87
|
+
Notification.follow_category
|
88
|
+
```
|
89
|
+
|
90
|
+
### Settings
|
91
|
+
|
92
|
+
You can disable notifications for a given notification target:
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
s = User.first.notification_setting
|
96
|
+
s.settings[:enabled] = false
|
97
|
+
```
|
98
|
+
|
99
|
+
This will prevent you from creating any new notifications with this user as target.
|
100
|
+
|
101
|
+
#### Category specific settings
|
102
|
+
|
103
|
+
A user can also have category specific settings:
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
s.category_settings[:category] = { enabled: false }
|
107
|
+
```
|
108
|
+
|
109
|
+
#### Pusher specific settings
|
110
|
+
|
111
|
+
He can have global or category specific pusher settings:
|
112
|
+
|
113
|
+
```ruby
|
114
|
+
s.settings[:ActionMailer] = false
|
115
|
+
s.category_settings[:category] = { ActionMailer: false }
|
116
|
+
```
|
117
|
+
|
118
|
+
#### Updating settings
|
119
|
+
|
120
|
+
...
|
121
|
+
|
122
|
+
### Subscriptions
|
123
|
+
|
124
|
+
Subscriptions are a way to better handle settings for notifications from different objects to one notification target.
|
125
|
+
|
126
|
+
This is how to subscribe/unsubscribe a target to an object:
|
127
|
+
|
128
|
+
```ruby
|
129
|
+
User.first.subscribe Recipe.first
|
130
|
+
User.first.unsubscribe Recipe.first
|
131
|
+
```
|
132
|
+
|
133
|
+
Now you can easily notify all subscribers from the subscribable object:
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
Recipe.first.notify_subscribers push: :ActionMailer
|
137
|
+
```
|
138
|
+
|
139
|
+
Let's assume that we have a group which has multiple chats. When sending notifications to subscribers of a given chat, we only want them to get notified. But when sending notifications about the group, we want to have everyone notified, that is either subscribed to the group or subscribed to one of its chats. To do that you have to add the `private` method `notification_dependents` to your model (in this case `Group`) and return an array of ActiveRecord objects whose subscribers should receive notifications for objects of this class.
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
has_many :chats
|
143
|
+
has_many :talks
|
144
|
+
|
145
|
+
private
|
146
|
+
|
147
|
+
def notification_dependents
|
148
|
+
self.chats
|
149
|
+
end
|
150
|
+
```
|
151
|
+
|
152
|
+
It is possible to override that behavior when notifying subscribers:
|
153
|
+
|
154
|
+
```ruby
|
155
|
+
# Disable notification dependents
|
156
|
+
Group.first.notify_subscribers dependents: nil
|
157
|
+
|
158
|
+
# Override notification dependents
|
159
|
+
Group.first.notify_subscribers dependents: Group.first.chats + Group.first.talks
|
160
|
+
```
|
161
|
+
|
162
|
+
You can customize settings for a single subscription just as you would for a notification target:
|
163
|
+
|
164
|
+
```ruby
|
165
|
+
s = User.first.notification_subscriptions.first.notification_setting
|
166
|
+
s.settings[:enabled] = false
|
167
|
+
```
|
168
|
+
|
169
|
+
[Learn more](#settings)
|
170
|
+
|
171
|
+
### Status
|
172
|
+
|
173
|
+
NotificationSettings comes with a handy feature called Status. The status of a record can temporarily disable the ability to create notifications for or to push notifications of a target.
|
174
|
+
|
175
|
+
This is how to define a status:
|
176
|
+
|
177
|
+
```ruby
|
178
|
+
User.first.notification_setting.status = 'do not disturb'
|
179
|
+
User.first.notification_setting.save
|
180
|
+
```
|
181
|
+
|
182
|
+
**Note:** You can set `status` to any string you like.
|
183
|
+
|
184
|
+
`status` has three possible values that are being used as defaults. Normally it defaults to `'online'`. If the `last_seen` [configuration](#configuration) option has been set, it can also default to `'idle'` or `'offline'` depending on the `idle_after` and `offline_after` [configuration](#configuration) options.
|
185
|
+
|
186
|
+
If you have set `status` to a custom value, you can get back to using the defaults by setting it back to `nil`.
|
187
|
+
|
188
|
+
You can define statuses that prevent creating new notifications for a target and statuses that just prevent pushing them:
|
189
|
+
|
190
|
+
```ruby
|
191
|
+
NotificationSettings.configure do |config|
|
192
|
+
config.do_not_notify_statuses = ['do not notify']
|
193
|
+
config.do_not_push_statuses = ['do not disturb']
|
194
|
+
end
|
195
|
+
```
|
196
|
+
|
197
|
+
---
|
198
|
+
|
199
|
+
## Configuration
|
200
|
+
|
201
|
+
You can configure NotificationSettings by passing a block to `configure`. This can be done in `config/initializers/notification-settings.rb`:
|
202
|
+
|
203
|
+
```ruby
|
204
|
+
NotificationSettings.configure do |config|
|
205
|
+
config.default_category = 'notification'
|
206
|
+
end
|
207
|
+
```
|
208
|
+
|
209
|
+
**`default_category`** Choose your default notification category. Takes a string. Defaults to `'notification'`.
|
210
|
+
|
211
|
+
### Status
|
212
|
+
|
213
|
+
**`idle_after`** Time duration without activity after which the status defaults to `'idle'`. Takes a time. Defaults to `10.minutes`.
|
214
|
+
|
215
|
+
**`offline_after`** Time duration without activity after which the status defaults to `'offline'`. Takes a time. Defaults to `3.hours`.
|
216
|
+
|
217
|
+
**`last_seen`** Stringified datetime attribute name of `object` that defines the time of the last activity. Takes a string. Defaults to `'last_seen'`.
|
218
|
+
|
219
|
+
**`do_not_notify_statuses`** Array of possible statuses that will prevent creating notifications for a target. Takes an array of strings. Defaults to `[]`.
|
220
|
+
|
221
|
+
**`do_not_push_statuses`** Array of possible statuses that will prevent pushing notifications of a target. Takes an array of strings. Defaults to `['do not disturb']`
|
222
|
+
|
223
|
+
---
|
224
|
+
|
225
|
+
## To Do
|
226
|
+
|
227
|
+
[Here](https://github.com/jonhue/notifications-rails/projects/4) is the full list of current projects.
|
228
|
+
|
229
|
+
To propose your ideas, initiate the discussion by adding a [new issue](https://github.com/jonhue/notifications-rails/issues/new).
|
230
|
+
|
231
|
+
---
|
232
|
+
|
233
|
+
## Contributing
|
234
|
+
|
235
|
+
We hope that you will consider contributing to NotificationSettings. Please read this short overview for some information about how to get started:
|
236
|
+
|
237
|
+
[Learn more about contributing to this repository](https://github.com/jonhue/notifications-rails/blob/master/CONTRIBUTING.md), [Code of Conduct](https://github.com/jonhue/notifications-rails/blob/master/CODE_OF_CONDUCT.md)
|
238
|
+
|
239
|
+
### Contributors
|
240
|
+
|
241
|
+
Give the people some :heart: who are working on this project. See them all at:
|
242
|
+
|
243
|
+
https://github.com/jonhue/notifications-rails/graphs/contributors
|
244
|
+
|
245
|
+
### Semantic Versioning
|
246
|
+
|
247
|
+
NotificationSettings follows Semantic Versioning 2.0 as defined at http://semver.org.
|
248
|
+
|
249
|
+
## License
|
250
|
+
|
251
|
+
MIT License
|
252
|
+
|
253
|
+
Copyright (c) 2017 Jonas Hübotter
|
254
|
+
|
255
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
256
|
+
of this software and associated documentation files (the "Software"), to deal
|
257
|
+
in the Software without restriction, including without limitation the rights
|
258
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
259
|
+
copies of the Software, and to permit persons to whom the Software is
|
260
|
+
furnished to do so, subject to the following conditions:
|
261
|
+
|
262
|
+
The above copyright notice and this permission notice shall be included in all
|
263
|
+
copies or substantial portions of the Software.
|
264
|
+
|
265
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
266
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
267
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
268
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
269
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
270
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
271
|
+
SOFTWARE.
|