notey 0.3.0 → 0.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 52c58921ef29966128ff879a465b658aecc03be72d9854b20e35fcf374bdf227
4
- data.tar.gz: f33f53d08767a17f9409255954c1561a9d334e58c8d4e141410a3f1e3af8d429
3
+ metadata.gz: 7610a3ba662e8faccd42819f0422ba19dd6b23f65619de246b28b89b201d7cbd
4
+ data.tar.gz: ce7e9b0e188efd5790e8b2d9a8545d0fdfc418133db9f7fca3f78cf529eb2e71
5
5
  SHA512:
6
- metadata.gz: 679238d4b8f289a4e653a11a86002544d1eabbba16d381e691bbbfc2d8a813c4c86d4a988d2d008f7d88d637bbfd8ab24b9f8b844bae12270d04f63150dbb6b0
7
- data.tar.gz: 4a0fe1f0a1f63ce23242147a896c8f45a6acad9bee3118b668a553aa9af68bf565e358d0ecc821511c5fa55b66c60dec7005bc99dd11bc43a9af2d9220608508
6
+ metadata.gz: 961ec39375572d803830b55c13bc140c44a2a999d7ce6bdc55ee5124ef5bf9f059adb46bbb87fce89af72b6a9bfb61ce5617bdd513fb0be725d48df2cbf88e4e
7
+ data.tar.gz: cf7398efa6cd3d2a7f8afe4ff6a7dd83076db6cc4929f3ca80506c590d5ab86aadf5fea04ec6cb3cac8119d4d00ec34c7e3112dc2c25ecc4e8dde29f44b44125
data/README.md CHANGED
@@ -163,8 +163,8 @@ end
163
163
 
164
164
  ## Settings sections
165
165
 
166
- Notey ships its two pages as partials and their saving as action objects, so a
167
- settings shell renders them inside its own chrome rather than linking away.
166
+ Notey ships its screens as partials and their saving as action objects, so a
167
+ settings shell renders them inside its own page frame rather than linking away.
168
168
  With [`bureau`](https://github.com/DYB-Development/bureau):
169
169
 
170
170
  ```ruby
@@ -180,6 +180,29 @@ A section registered this way is served by the settings shell, so the shell's
180
180
  own capability check guards it. A section that only links to a mounted path is
181
181
  not guarded, because the shell never renders it.
182
182
 
183
+ ## The inbox
184
+
185
+ The inbox is the same shape and is not a setting, so render it wherever a
186
+ person's notifications belong in your own pages:
187
+
188
+ ```erb
189
+ <%= render "notey/inbox",
190
+ person: current_user,
191
+ account: current_account.id,
192
+ submit_url: notifications_path %>
193
+ ```
194
+
195
+ It lists the notifications that person received in that account, newest first,
196
+ marking the unread ones. Marking one read posts to the url you named, so the
197
+ person stays on your page, and the action behind it runs:
198
+
199
+ ```ruby
200
+ Notey::MarkRead.new(person: current_user, account: current_account.id, values: params).call
201
+ ```
202
+
203
+ It marks only a notification that person received in that account, so an id
204
+ from anywhere else does nothing.
205
+
183
206
  `Notey::SavePreferences` and `Notey::SaveDestination` take `person:`, `account:`
184
207
  and `values:`, and answer with an object responding to `ok?` and `message`. The
185
208
  engine's own pages call the same two actions.
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Notey
4
+ class MarkRead
5
+ def initialize(values:, person: nil, account: nil)
6
+ @person = person
7
+ @account_id = account.respond_to?(:id) ? account.id : account
8
+ @values = values
9
+ end
10
+
11
+ def call
12
+ notification&.mark_as_read!
13
+
14
+ Kept.new
15
+ end
16
+
17
+ private
18
+
19
+ def notification
20
+ Inbox.for(@person, account_id: @account_id).find_by(id: @values[:read])
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ <% notifications = Notey::Inbox.for(person, account_id: account).includes(:event).order(created_at: :desc) %>
2
+
3
+ <% notifications.each do |notification| %>
4
+ <%= ui_panel do %>
5
+ <div data-notification-id="<%= notification.id %>">
6
+ <%= notification.event.title %>
7
+ <%= ui_badge(label: notification.read? ? "Read" : "Unread") %>
8
+ <% unless notification.read? %>
9
+ <%= ui_form(action: submit_url, method: :patch) do %>
10
+ <%= hidden_field_tag "read", notification.id, id: nil %>
11
+ <%= ui_button(label: "Mark read") %>
12
+ <% end %>
13
+ <% end %>
14
+ </div>
15
+ <% end %>
16
+ <% end %>
data/lib/notey/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Notey
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -45,6 +45,11 @@ This local assumes the gem is already hooked into the app; if it is not, that is
45
45
  set.
46
46
  - `Notey::Inbox.for(member, account_id:)` — returns that person's notifications
47
47
  for that account, as a relation.
48
+ - `notey/inbox` — the partial a host renders inside a page of its own to show a
49
+ person their notifications, taking `person`, `account` and the `submit_url`
50
+ that marking one read posts to.
51
+ - `Notey::MarkRead` — marks the notification a person picked as read, and marks
52
+ nothing when the id belongs to another person or another account.
48
53
  - `wants?(type, on:, account_id:)` — on the recipient model, true when that
49
54
  person wants that type on that channel in that account.
50
55
  - `channels_for(type, account_id:)` — on the recipient model, the channels that
@@ -22,6 +22,8 @@ develop:
22
22
  - Notey::DigestRun
23
23
  - Notey::DeleteOldAttempts
24
24
  - Notey::Inbox.for
25
+ - notey/inbox
26
+ - Notey::MarkRead
25
27
  - wants?
26
28
  - channels_for
27
29
  - digest_window_for
@@ -43,6 +45,8 @@ sources:
43
45
  - app/models/notey/digest.rb
44
46
  - app/models/notey/attempt.rb
45
47
  - app/models/notey/delete_old_attempts.rb
48
+ - app/models/notey/mark_read.rb
49
+ - app/views/notey/_inbox.html.erb
46
50
  - app/delivery_methods/notey/email.rb
47
51
  - app/delivery_methods/notey/in_app.rb
48
52
  - app/jobs/notey/digest_job.rb
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notey
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tylercschneider
@@ -92,6 +92,7 @@ files:
92
92
  - app/models/notey/destination.rb
93
93
  - app/models/notey/digest.rb
94
94
  - app/models/notey/kept.rb
95
+ - app/models/notey/mark_read.rb
95
96
  - app/models/notey/notification.rb
96
97
  - app/models/notey/preference.rb
97
98
  - app/models/notey/refusal.rb
@@ -99,6 +100,7 @@ files:
99
100
  - app/models/notey/save_my_destination.rb
100
101
  - app/models/notey/save_preferences.rb
101
102
  - app/views/notey/_destinations.html.erb
103
+ - app/views/notey/_inbox.html.erb
102
104
  - app/views/notey/_my_destinations.html.erb
103
105
  - app/views/notey/_preferences.html.erb
104
106
  - app/views/notey/destinations/show.html.erb