notification-settings 1.0.0.beta6 → 1.0.0.beta7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +37 -0
- data/README.md +165 -26
- data/lib/generators/notification_settings/install_generator.rb +43 -0
- data/lib/generators/templates/install/README.md +1 -0
- data/lib/generators/templates/install/initializer.rb +24 -0
- data/lib/generators/templates/install/notifications_migration.rb.erb +29 -0
- data/lib/notification_settings/configuration.rb +32 -0
- data/lib/notification_settings/engine.rb +6 -0
- data/lib/notification_settings/notification_library.rb +60 -0
- data/lib/notification_settings/notification_scopes.rb +17 -0
- data/lib/notification_settings/setting_library.rb +16 -0
- data/lib/notification_settings/subscribable.rb +15 -0
- data/lib/notification_settings/subscriber.rb +18 -0
- data/lib/notification_settings/subscription_library.rb +13 -0
- data/lib/notification_settings/target.rb +15 -0
- data/lib/notification_settings.rb +15 -0
- metadata +19 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f63fb9f4357cdf63bbdc200883a8cd4011a29da844c8e5fa7d5eee78bfa107a4
|
4
|
+
data.tar.gz: 905c9245c94a361a6e477ffa59e98d91cd58d90094581468847c0614787c27f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ad972080a92d39020ce11147873493906a75cc7eb7587b33ac2a9df1ccc5efe92a6af35405a7844b78f38d8e1245efc540b022ac1bb9c77338fb83698d31237
|
7
|
+
data.tar.gz: 55054ebb25086a00670ac41d672e5f3e86e737d04ca4ff3daa4aa0cdd58f7a806a951a8adf68bf68b2a0d42efaa431b28abd190ce73c79e6dd49e65c31d2366a
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
### master
|
4
|
+
|
5
|
+
* nothing yet
|
6
|
+
|
7
|
+
### 1.0.0.beta6 - 2017-12-28
|
8
|
+
|
9
|
+
* bugfixes
|
10
|
+
* fix lib loading problems
|
11
|
+
|
12
|
+
### 1.0.0.beta5 - 2017-12-28
|
13
|
+
|
14
|
+
* bugfixes
|
15
|
+
* fix generators
|
16
|
+
* fix lib loading problems
|
17
|
+
* fix syntax errors
|
18
|
+
|
19
|
+
### 1.0.0.beta4 - 2017-12-27
|
20
|
+
|
21
|
+
* features
|
22
|
+
* add settings functionality
|
23
|
+
* add `category` attribute to `Notification` instances
|
24
|
+
* add subscription functonality
|
25
|
+
|
26
|
+
### 1.0.0.beta3 - 2017-12-25
|
27
|
+
|
28
|
+
* features
|
29
|
+
* add `Setting` ActiveRecord model
|
30
|
+
|
31
|
+
### 1.0.0.beta2 - 2017-12-23
|
32
|
+
|
33
|
+
* no changes
|
34
|
+
|
35
|
+
### 1.0.0.beta1 - 2017-12-22
|
36
|
+
|
37
|
+
* initial release
|
data/README.md
CHANGED
@@ -1,17 +1,24 @@
|
|
1
|
-
#
|
1
|
+
# NotificationSettings
|
2
2
|
|
3
|
-
[](https://badge.fury.io/rb/notification-settings) <img src="https://travis-ci.org/jonhue/notifications-rails.svg?branch=master" />
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
It integrates with the [Native](https://github.com/NativeGap/native-rails) gem to allow you to create a cross platform Rails app.
|
5
|
+
Integrates with your authentication solution to craft a personalized user notification platform.
|
8
6
|
|
9
7
|
---
|
10
8
|
|
11
9
|
## Table of Contents
|
12
10
|
|
13
|
-
* [Philosophy](#philosophy)
|
14
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)
|
15
22
|
* [To Do](#to-do)
|
16
23
|
* [Contributing](#contributing)
|
17
24
|
* [Contributors](#contributors)
|
@@ -20,49 +27,181 @@ It integrates with the [Native](https://github.com/NativeGap/native-rails) gem t
|
|
20
27
|
|
21
28
|
---
|
22
29
|
|
23
|
-
##
|
30
|
+
## Installation
|
24
31
|
|
25
|
-
|
32
|
+
NotificationSettings works with Rails 5 onwards. You can add it to your `Gemfile` with:
|
26
33
|
|
27
|
-
|
34
|
+
```ruby
|
35
|
+
gem 'notification-settings'
|
36
|
+
```
|
28
37
|
|
29
|
-
|
38
|
+
And then execute:
|
30
39
|
|
31
|
-
|
40
|
+
$ bundle
|
32
41
|
|
33
|
-
|
42
|
+
Or install it yourself as:
|
43
|
+
|
44
|
+
$ gem install notification-settings
|
34
45
|
|
35
|
-
|
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
|
36
59
|
|
37
60
|
---
|
38
61
|
|
39
|
-
##
|
62
|
+
## Usage
|
40
63
|
|
41
|
-
|
64
|
+
NotificationSettings will create a `NotificationSettings::Setting` record for every newly created `notification_target`-object. It is accessible by calling:
|
42
65
|
|
43
66
|
```ruby
|
44
|
-
|
67
|
+
User.first.notification_setting
|
45
68
|
```
|
46
69
|
|
47
|
-
|
70
|
+
### Categories
|
48
71
|
|
49
|
-
|
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:
|
50
73
|
|
51
|
-
|
74
|
+
```ruby
|
75
|
+
notification = Notification.create target: User.first, object: Recipe.first, category: 'notification'
|
76
|
+
```
|
52
77
|
|
53
|
-
|
78
|
+
**Note:** The `category` attribute of any new `Notification` record will default to the [`default_category` configuration](#configuration).
|
54
79
|
|
55
|
-
|
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
|
+
You can customize settings for a single subscription just as you would for a notification target:
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
s = User.first.notification_subscriptions.first.notification_setting
|
143
|
+
s.settings[:enabled] = false
|
144
|
+
```
|
145
|
+
|
146
|
+
[Learn more](#settings)
|
147
|
+
|
148
|
+
### Status
|
149
|
+
|
150
|
+
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.
|
151
|
+
|
152
|
+
This is how to define a status:
|
56
153
|
|
57
154
|
```ruby
|
58
|
-
|
155
|
+
User.first.notification_setting.status = 'do not disturb'
|
156
|
+
User.first.notification_setting.save
|
59
157
|
```
|
60
158
|
|
159
|
+
**Note:** You can set `status` to any string you like.
|
160
|
+
|
161
|
+
`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.
|
162
|
+
|
163
|
+
If you have set `status` to a custom value, you can get back to using the defaults by setting it back to `nil`.
|
164
|
+
|
165
|
+
You can define statuses that prevent creating new notifications for a target and statuses that just prevent pushing them:
|
166
|
+
|
167
|
+
```ruby
|
168
|
+
NotificationSettings.configure do |config|
|
169
|
+
config.do_not_notify_statuses = ['do not notify']
|
170
|
+
config.do_not_push_statuses = ['do not disturb']
|
171
|
+
end
|
172
|
+
```
|
173
|
+
|
174
|
+
---
|
175
|
+
|
176
|
+
## Configuration
|
177
|
+
|
178
|
+
You can configure NotificationSettings by passing a block to `configure`. This can be done in `config/initializers/notification-settings.rb`:
|
179
|
+
|
180
|
+
```ruby
|
181
|
+
NotificationSettings.configure do |config|
|
182
|
+
config.default_category = 'notification'
|
183
|
+
end
|
184
|
+
```
|
185
|
+
|
186
|
+
**`default_category`** Choose your default notification category. Takes a string. Defaults to `'notification'`.
|
187
|
+
|
188
|
+
### Status
|
189
|
+
|
190
|
+
**`idle_after`** Time duration without activity after which the status defaults to `'idle'`. Takes a time. Defaults to `10.minutes`.
|
191
|
+
|
192
|
+
**`offline_after`** Time duration without activity after which the status defaults to `'offline'`. Takes a time. Defaults to `3.hours`.
|
193
|
+
|
194
|
+
**`last_seen`** Stringified datetime attribute name of `object` that defines the time of the last activity. Takes a string. Defaults to `'last_seen'`.
|
195
|
+
|
196
|
+
**`do_not_notify_statuses`** Array of possible statuses that will prevent creating notifications for a target. Takes an array of strings. Defaults to `[]`.
|
197
|
+
|
198
|
+
**`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']`
|
199
|
+
|
61
200
|
---
|
62
201
|
|
63
202
|
## To Do
|
64
203
|
|
65
|
-
[Here](https://github.com/jonhue/notifications-rails/projects) is the full list of current projects.
|
204
|
+
[Here](https://github.com/jonhue/notifications-rails/projects/4) is the full list of current projects.
|
66
205
|
|
67
206
|
To propose your ideas, initiate the discussion by adding a [new issue](https://github.com/jonhue/notifications-rails/issues/new).
|
68
207
|
|
@@ -70,9 +209,9 @@ To propose your ideas, initiate the discussion by adding a [new issue](https://g
|
|
70
209
|
|
71
210
|
## Contributing
|
72
211
|
|
73
|
-
We hope that you will consider contributing to
|
212
|
+
We hope that you will consider contributing to NotificationSettings. Please read this short overview for some information about how to get started:
|
74
213
|
|
75
|
-
[Learn more about contributing to this repository](CONTRIBUTING.md), [Code of Conduct](CODE_OF_CONDUCT.md)
|
214
|
+
[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)
|
76
215
|
|
77
216
|
### Contributors
|
78
217
|
|
@@ -82,7 +221,7 @@ https://github.com/jonhue/notifications-rails/graphs/contributors
|
|
82
221
|
|
83
222
|
### Semantic Versioning
|
84
223
|
|
85
|
-
|
224
|
+
NotificationSettings follows Semantic Versioning 2.0 as defined at http://semver.org.
|
86
225
|
|
87
226
|
## License
|
88
227
|
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
|
4
|
+
module NotificationSettings
|
5
|
+
|
6
|
+
class InstallGenerator < Rails::Generators::Base
|
7
|
+
|
8
|
+
include Rails::Generators::Migration
|
9
|
+
|
10
|
+
source_root File.join File.dirname(__FILE__), '../templates/install'
|
11
|
+
desc 'Install NotificationSettings'
|
12
|
+
|
13
|
+
def self.next_migration_number dirname
|
14
|
+
if ActiveRecord::Base.timestamped_migrations
|
15
|
+
Time.now.utc.strftime '%Y%m%d%H%M%S'
|
16
|
+
else
|
17
|
+
"%.3d" % ( current_migration_number(dirname) + 1 )
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def create_initializer
|
22
|
+
template 'initializer.rb', 'config/initializers/notification-settings.rb'
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_notifications_migration_file
|
26
|
+
migration_template 'notifications_migration.rb.erb', 'db/migrate/notification_settings_migration.rb', migration_version: migration_version
|
27
|
+
end
|
28
|
+
|
29
|
+
def show_readme
|
30
|
+
readme 'README.md'
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def migration_version
|
36
|
+
if Rails.version >= '5.0.0'
|
37
|
+
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Now run `rails db:migrate` to add NotificationSettings to your database.
|
@@ -0,0 +1,24 @@
|
|
1
|
+
NotificationSettings.configure do |config|
|
2
|
+
|
3
|
+
# Choose your default notification category. Takes a string.
|
4
|
+
# config.default_category = 'notification'
|
5
|
+
|
6
|
+
|
7
|
+
### STATUS ###
|
8
|
+
|
9
|
+
# Time duration without activity after which the status defaults to `'idle'`. Takes a time.
|
10
|
+
# config.idle_after = 10.minutes
|
11
|
+
|
12
|
+
# Time duration without activity after which the status defaults to `'offline'`. Takes a time.
|
13
|
+
# config.offline_after = 3.hours
|
14
|
+
|
15
|
+
# Stringified datetime attribute name of `object` that defines the time of the last activity. Takes a string.
|
16
|
+
# config.last_seen = 'last_seen'
|
17
|
+
|
18
|
+
# Array of possible statuses that will prevent creating notifications for a target. Takes an array of strings.
|
19
|
+
# config.do_not_notify_statuses = []
|
20
|
+
|
21
|
+
# Array of possible statuses that will prevent pushing notifications of a target. Takes an array of strings.
|
22
|
+
# config.do_not_push_statuses = ['do not disturb']
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class NotificationSettingsMigration < ActiveRecord::Migration<%= migration_version %>
|
2
|
+
def change
|
3
|
+
add_column :notifications, :subscription_id, :bigint, index: true
|
4
|
+
add_column :notifications, :category, :string, index: true
|
5
|
+
|
6
|
+
create_table :notification_settings_settings do |t|
|
7
|
+
|
8
|
+
t.references :object, polymorphic: true, index: true
|
9
|
+
t.references :subscription, index: true
|
10
|
+
|
11
|
+
t.string :status
|
12
|
+
|
13
|
+
t.text :settings
|
14
|
+
t.text :category_settings
|
15
|
+
|
16
|
+
t.timestamps
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
create_table :notification_settings_subscriptions do |t|
|
21
|
+
|
22
|
+
t.references :subscriber, polymorphic: true, index: true
|
23
|
+
t.references :subscribable, polymorphic: true, index: true
|
24
|
+
|
25
|
+
t.timestamps
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module NotificationSettings
|
2
|
+
|
3
|
+
class << self
|
4
|
+
attr_accessor :configuration
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.configure
|
8
|
+
self.configuration ||= Configuration.new
|
9
|
+
yield configuration
|
10
|
+
end
|
11
|
+
|
12
|
+
class Configuration
|
13
|
+
|
14
|
+
attr_accessor :default_category
|
15
|
+
attr_accessor :last_seen
|
16
|
+
attr_accessor :idle_after
|
17
|
+
attr_accessor :offline_after
|
18
|
+
attr_accessor :do_not_notify_statuses
|
19
|
+
attr_accessor :do_not_push_statuses
|
20
|
+
|
21
|
+
def initialize
|
22
|
+
@default_category = 'notification'
|
23
|
+
@last_seen = 'last_seen'
|
24
|
+
@idle_after = 10.minutes
|
25
|
+
@offline_after = 3.hours
|
26
|
+
@do_not_notify_statuses = []
|
27
|
+
@do_not_push_statuses = ['do not disturb']
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module NotificationSettings
|
2
|
+
module NotificationLibrary
|
3
|
+
|
4
|
+
before_create :validate_create
|
5
|
+
|
6
|
+
belongs_to :subscription, class_name: 'NotificationSettings::Subscription', optional: true
|
7
|
+
|
8
|
+
def category
|
9
|
+
self[:category] || NotificationRenderer.configuration.default_category
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def validate_create
|
15
|
+
valid = true
|
16
|
+
|
17
|
+
if self.target.notification_setting.present?
|
18
|
+
# Status
|
19
|
+
valid = false if NotificationSettings.configuration.do_not_notify_statuses.include?(self.target.notification_setting.status)
|
20
|
+
|
21
|
+
# Settings
|
22
|
+
valid = false if !self.target.notification_setting.settings.dig(:enabled)
|
23
|
+
## Category
|
24
|
+
valid = false if !self.target.notification_setting.category_settings.dig(self.category.to_sym, :enabled)
|
25
|
+
end
|
26
|
+
|
27
|
+
valid
|
28
|
+
end
|
29
|
+
|
30
|
+
def validate_push
|
31
|
+
valid = true
|
32
|
+
|
33
|
+
if self.target.notification_setting.present?
|
34
|
+
# Status
|
35
|
+
valid = false if NotificationSettings.configuration.do_not_push_statuses.include?(self.target.notification_setting.status)
|
36
|
+
|
37
|
+
# Settings
|
38
|
+
if self.push.kind_of?(Array)
|
39
|
+
self.push.each do |pusher|
|
40
|
+
valid = false if !self.target.notification_setting.settings.dig(pusher.to_sym) || ( !self.target.notification_setting.settings.dig(:index) && self.target.notification_setting.settings.dig(pusher.to_sym).nil? )
|
41
|
+
## Category
|
42
|
+
valid = false if !self.target.notification_setting.category_settings.dig(self.category.to_sym, pusher.to_sym) || ( !self.target.notification_setting.category_settings.dig(self.category.to_sym, :index) && self.target.notification_setting.category_settings.dig(self.category.to_sym, pusher.to_sym).nil? )
|
43
|
+
end
|
44
|
+
else
|
45
|
+
valid = false if !self.target.notification_setting.settings.dig(self.push.to_sym) || ( !self.target.notification_setting.settings.dig(:index) && self.target.notification_setting.settings.dig(self.push.to_sym).nil? )
|
46
|
+
## Category
|
47
|
+
valid = false if !self.target.notification_setting.category_settings.dig(self.category.to_sym, self.push.to_sym) || ( !self.target.notification_setting.category_settings.dig(self.category.to_sym, :index) && self.target.notification_setting.category_settings.dig(self.category.to_sym, self.push.to_sym).nil? )
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
valid
|
52
|
+
end
|
53
|
+
|
54
|
+
def initialize_pusher
|
55
|
+
return unless validate_push
|
56
|
+
super
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module NotificationSettings
|
2
|
+
module NotificationScopes
|
3
|
+
|
4
|
+
def method_missing m, *args
|
5
|
+
if m.to_s[/(.+)_category/]
|
6
|
+
where category: $1.singularize.classify
|
7
|
+
else
|
8
|
+
super
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def respond_to? m, include_private = false
|
13
|
+
super || m.to_s[/(.+)_category/]
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module NotificationSettings
|
2
|
+
module SettingLibrary
|
3
|
+
|
4
|
+
def status
|
5
|
+
if self.object.respond_to?(NotificationSettings.configuration.last_seen) && ( Time.now - self.object.send(NotificationSettings.configuration.last_seen) ).round >= NotificationSettings.configuration.idle_after && ( Time.now - self.object.send(NotificationSettings.configuration.last_seen) ).round < NotificationSettings.configuration.offline_after
|
6
|
+
default = 'idle'
|
7
|
+
elsif self.object.respond_to?(NotificationSettings.configuration.last_seen) && ( Time.now - self.object.send(NotificationSettings.configuration.last_seen) ).round >= NotificationSettings.configuration.offline_after
|
8
|
+
default = 'offline'
|
9
|
+
else
|
10
|
+
'online'
|
11
|
+
end
|
12
|
+
self[:status] || default
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module NotificationSettings
|
2
|
+
module Subscribable
|
3
|
+
|
4
|
+
has_many :notification_subscriptions, as: :subscribable, class_name: 'NotificationSettings::Subscription', dependent: :destroy
|
5
|
+
has_many :notification_subscribers, through: :notification_subscriptions, source: :subscriber
|
6
|
+
|
7
|
+
def notify_subscribers options = {}
|
8
|
+
options[:object] = self
|
9
|
+
self.notification_subscribers.each do |subscriber|
|
10
|
+
subscriber.notify options
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module NotificationSettings
|
2
|
+
module Subscriber
|
3
|
+
|
4
|
+
has_many :notification_subscriptions, as: :subscriber, class_name: 'NotificationSettings::Subscription', dependent: :destroy
|
5
|
+
has_many :notification_subscribables, through: :notification_subscriptions, source: :subscribable
|
6
|
+
|
7
|
+
def subscribe options = {}
|
8
|
+
options[:subscriber] = self
|
9
|
+
NotificationSettings::Subscription.create options
|
10
|
+
end
|
11
|
+
|
12
|
+
def unsubscribe subscribable
|
13
|
+
subscription = self.notification_subscriptions.find_by subscribable_id: subscribable.id, subscribable_type: subscribable.class.to_s
|
14
|
+
subscription.destroy
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module NotificationSettings
|
2
|
+
module Target
|
3
|
+
|
4
|
+
has_one :notification_setting, as: :object, class_name: 'NotificationSettings::Setting', dependent: :destroy
|
5
|
+
|
6
|
+
after_create_commit :create_notification_setting
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def create_notification_setting
|
11
|
+
self.notification_setting.create!
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module NotificationSettings
|
2
|
+
|
3
|
+
require 'notification_settings/configuration'
|
4
|
+
|
5
|
+
require 'notification_settings/engine'
|
6
|
+
|
7
|
+
autoload :Target, 'notification_settings/target'
|
8
|
+
autoload :Subscriber, 'notification_settings/subscriber'
|
9
|
+
autoload :Subscribable, 'notification_settings/subscribable'
|
10
|
+
autoload :SettingLibrary, 'notification_settings/setting_library'
|
11
|
+
autoload :SubscriptionLibrary, 'notification_settings/subscription_library'
|
12
|
+
autoload :NotificationLibrary, 'notification_settings/notification_library'
|
13
|
+
autoload :NotificationScopes, 'notification_settings/notification_scopes'
|
14
|
+
|
15
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notification-settings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.beta7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonas Hübotter
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.0.0.
|
33
|
+
version: 1.0.0.beta7
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.0.0.
|
40
|
+
version: 1.0.0.beta7
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -73,8 +73,23 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
+
- CHANGELOG.md
|
76
77
|
- LICENSE
|
77
78
|
- README.md
|
79
|
+
- lib/generators/notification_settings/install_generator.rb
|
80
|
+
- lib/generators/templates/install/README.md
|
81
|
+
- lib/generators/templates/install/initializer.rb
|
82
|
+
- lib/generators/templates/install/notifications_migration.rb.erb
|
83
|
+
- lib/notification_settings.rb
|
84
|
+
- lib/notification_settings/configuration.rb
|
85
|
+
- lib/notification_settings/engine.rb
|
86
|
+
- lib/notification_settings/notification_library.rb
|
87
|
+
- lib/notification_settings/notification_scopes.rb
|
88
|
+
- lib/notification_settings/setting_library.rb
|
89
|
+
- lib/notification_settings/subscribable.rb
|
90
|
+
- lib/notification_settings/subscriber.rb
|
91
|
+
- lib/notification_settings/subscription_library.rb
|
92
|
+
- lib/notification_settings/target.rb
|
78
93
|
homepage: https://github.com/jonhue/notifications-rails/tree/master/notification-settings
|
79
94
|
licenses:
|
80
95
|
- MIT
|
@@ -82,7 +97,7 @@ metadata: {}
|
|
82
97
|
post_install_message:
|
83
98
|
rdoc_options: []
|
84
99
|
require_paths:
|
85
|
-
- lib
|
100
|
+
- lib
|
86
101
|
required_ruby_version: !ruby/object:Gem::Requirement
|
87
102
|
requirements:
|
88
103
|
- - ">="
|