thredded 0.13.3 → 0.13.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 446cac9b09b4d4bf92db6feaa8fdf3ed2b3708fc
4
- data.tar.gz: f2c7b6e776222e744532f53dc5ae04ed475353a7
3
+ metadata.gz: 6f51494c108c361f5f0d96441cf9bb0615f388d3
4
+ data.tar.gz: 0f98a9b720385ee57a189aaf42116d52b60bff87
5
5
  SHA512:
6
- metadata.gz: 9872e5d357a029ea8ca930b1c600ebd6687d26d7b2d6c8c710734cba6c5ec3e84795811b9ed905f3754d2baad27fa66bad7ab182674024695a3cf7be06495861
7
- data.tar.gz: b90d6d78537a2f1060aaf78f121fd15862bbab0d6c71e23403f22fee080fe1d9fdf54fd13073b121e1a465d200e1ff941bbb46ef3bb0ec8a5ffd128b9d278b3f
6
+ metadata.gz: 82f7a755ef708111bd17e06da26f684e870334f0b3acf0a555cb6d18a767f8e93858d9e04d7c9a90d69aded4dc8abacd9c295181e3808c6b30902b9d152476b8
7
+ data.tar.gz: 15b3f0169e31a3bf7938cee0eef98111967668e15f97aadf57b81af02e8a4c281863eeca013bab9a4535c243dad42c9e144623482cdfe1b266640af70601a4cf
data/README.md CHANGED
@@ -98,7 +98,7 @@ Then, see the rest of this Readme for more information about using and customizi
98
98
  Add the gem to your Gemfile:
99
99
 
100
100
  ```ruby
101
- gem 'thredded', '~> 0.13.3'
101
+ gem 'thredded', '~> 0.13.4'
102
102
  ```
103
103
 
104
104
  Add the Thredded [initializer] to your parent app by running the install generator.
@@ -14,9 +14,10 @@
14
14
  transition: all 0.15s ease-out 0s;
15
15
  }
16
16
 
17
- label + label {
17
+ label ~ label {
18
18
  display: inline-block;
19
19
  font-weight: normal;
20
+ margin-right: 15px;
20
21
  }
21
22
  }
22
23
 
@@ -9,47 +9,65 @@ module Thredded
9
9
  end
10
10
 
11
11
  def run
12
+ subscribed_users.select! do |user|
13
+ # Record idempotently that the notification happened.
14
+ # If a notification was already created (e.g. from another thread/process),
15
+ # this will return false due to the unique constraint on the table
16
+ # and the user will be excluded.
17
+ subscribed_via_any_notifier?(user) && record_as_notified_successful?(user)
18
+ end
12
19
  Thredded.notifiers.each do |notifier|
13
20
  notifiable_users = targeted_users(notifier)
14
- notifiable_users = notifiable_users.select do |user|
15
- # Create a notification for the user.
16
- # If a notification was already created (from another thread/process),
17
- # this will return false due to the unique constraint on the table
18
- # and the user will be excluded.
19
- Thredded::UserPostNotification.create_from_post_and_user(@post, user)
20
- end
21
21
  next if notifiable_users.empty?
22
22
  notifier.new_post(@post, notifiable_users)
23
23
  end
24
24
  end
25
25
 
26
26
  def targeted_users(notifier)
27
- users_subscribed_via(notifier).reject do |user|
28
- already_notified_user_ids.include?(user.id)
27
+ subscribed_users.select do |user|
28
+ user_subscribed_via?(user, notifier)
29
29
  end
30
30
  end
31
31
 
32
- def users_subscribed_via(notifier)
33
- subscribed_users.select do |user|
34
- Thredded::NotificationsForFollowedTopics
35
- .detect_or_default(user.thredded_notifications_for_followed_topics, notifier).enabled? &&
36
- Thredded::MessageboardNotificationsForFollowedTopics
37
- .detect_or_default(messageboard_notifier_prefs_by_user_id[user.id], notifier).enabled?
38
- end
32
+ def user_subscribed_via?(user, notifier)
33
+ Thredded::NotificationsForFollowedTopics
34
+ .detect_or_default(user.thredded_notifications_for_followed_topics, notifier).enabled? &&
35
+ Thredded::MessageboardNotificationsForFollowedTopics
36
+ .detect_or_default(messageboard_notifier_prefs_by_user_id[user.id], notifier).enabled?
39
37
  end
40
38
 
39
+ # @return [Array<User>]
41
40
  def subscribed_users
42
41
  @subscribed_users ||=
43
- @post.postable.followers.includes(:thredded_notifications_for_followed_topics).reject do |user|
44
- user == @post.user || !Thredded::PostPolicy.new(user, @post).read?
42
+ @post.postable.followers.includes(:thredded_notifications_for_followed_topics).select do |user|
43
+ !already_notified?(user) && !originator?(user) && can_read_post?(user)
45
44
  end
46
45
  end
47
46
 
48
- def already_notified_user_ids
49
- @notified_user_ids ||= Set.new Thredded::UserPostNotification.notified_user_ids(@post)
47
+ private
48
+
49
+ def originator?(user)
50
+ user == @post.user
50
51
  end
51
52
 
52
- private
53
+ def can_read_post?(user)
54
+ Thredded::PostPolicy.new(user, @post).read?
55
+ end
56
+
57
+ def already_notified?(user)
58
+ # We memoize the set so that records created during this task do not affect the result,
59
+ # so that a user can receive notifications via multiple notifiers.
60
+ @already_notified_user_ids ||= Set.new Thredded::UserPostNotification.notified_user_ids(@post)
61
+ @already_notified_user_ids.include?(user.id)
62
+ end
63
+
64
+ def subscribed_via_any_notifier?(user)
65
+ Thredded.notifiers.any? { |notifier| user_subscribed_via?(user, notifier) }
66
+ end
67
+
68
+ def record_as_notified_successful?(user)
69
+ Thredded::UserPostNotification.create_from_post_and_user(@post, user)
70
+ end
53
71
 
54
72
  def messageboard_notifier_prefs_by_user_id
55
73
  @messageboard_notifier_prefs_by_user_id ||= Thredded::MessageboardNotificationsForFollowedTopics
@@ -3,8 +3,8 @@
3
3
  class: 'thredded--form thredded--notification-preferences-form',
4
4
  'data-thredded-user-preferences-form' => true
5
5
  }) do |f| %>
6
- <ul class="thredded--form-list">
7
- <li>
6
+ <ul class="thredded--form-list thredded--user-preferences-global">
7
+ <li class="thredded--user-preferences--auto-follow-topics">
8
8
  <%= f.label :auto_follow_topics do %>
9
9
  <%= f.check_box :auto_follow_topics,
10
10
  'data-thredded-update-checkbox-on-change' =>
@@ -15,7 +15,7 @@
15
15
  </p>
16
16
  <% end %>
17
17
  </li>
18
- <li>
18
+ <li class="thredded--user-preferences--follow-topics-on-mention">
19
19
  <%= f.label :follow_topics_on_mention do %>
20
20
  <%= f.check_box :follow_topics_on_mention, 'data-thredded-bound-messageboard-pref' => 'user_preferences_form[messageboard_follow_topics_on_mention]' %>
21
21
  <%= t 'thredded.preferences.form.follow_topics_on_mention.label' %>
@@ -25,7 +25,7 @@
25
25
  <% end %>
26
26
  </li>
27
27
  <% if Thredded.notifiers.present? %>
28
- <li>
28
+ <li class="thredded--user-preferences--notifications-for-followed-topics">
29
29
  <label><%= t 'thredded.preferences.form.notifications_for_followed_topics.label' %></label>
30
30
  <%= f.fields_for :notifications_for_followed_topics, preferences.notifications_for_followed_topics do |fn| %>
31
31
  <%= fn.label :enabled do %>
@@ -37,7 +37,7 @@
37
37
  <%- end %>
38
38
  <%- end %>
39
39
  </li>
40
- <li>
40
+ <li class="thredded--user-preferences--notifications-for-private-topics">
41
41
  <label><%= t 'thredded.preferences.form.notifications_for_private_topics.label' %></label>
42
42
  <%= f.fields_for :notifications_for_private_topics, preferences.notifications_for_private_topics do |fn| %>
43
43
  <%= fn.label :enabled do %>
@@ -53,8 +53,8 @@
53
53
  <h2 class="thredded--preferences--title">
54
54
  <%= t 'thredded.preferences.messageboard_preferences_title_html', messageboard: messageboard.name %>
55
55
  </h2>
56
- <ul class="thredded--form-list" data-thredded-user-preferences-form-messageboard-fields>
57
- <li>
56
+ <ul class="thredded--form-list thredded--user-preferences-messageboard" data-thredded-user-preferences-form-messageboard-fields>
57
+ <li class="thredded--user-preferences--auto-follow-topics">
58
58
  <%= f.label :messageboard_auto_follow_topics do %>
59
59
  <%= f.check_box :messageboard_auto_follow_topics %>
60
60
  <%= t 'thredded.preferences.form.messageboard_auto_follow_topics.label' %>
@@ -63,7 +63,7 @@
63
63
  </p>
64
64
  <% end %>
65
65
  </li>
66
- <li>
66
+ <li class="thredded--user-preferences--follow-topics-on-mention">
67
67
  <%= f.label :messageboard_follow_topics_on_mention do %>
68
68
  <%= f.check_box :messageboard_follow_topics_on_mention %>
69
69
  <%= t 'thredded.preferences.form.messageboard_follow_topics_on_mention.label' %>
@@ -73,7 +73,7 @@
73
73
  <% end %>
74
74
  </li>
75
75
  <% if Thredded.notifiers.present? %>
76
- <li>
76
+ <li class="thredded--user-preferences--notifications-for-followed-topics">
77
77
  <label><%= t 'thredded.preferences.form.messageboard_notifications_for_followed_topics.label' %></label>
78
78
  <%= f.fields_for :messageboard_notifications_for_followed_topics,
79
79
  preferences.messageboard_notifications_for_followed_topics do |fn| %>
@@ -41,6 +41,7 @@
41
41
  <% end %>
42
42
  <% end %>
43
43
 
44
- <% if !topic_iteration.last? && topic.sticky? && !topics[topic_counter + 1].sticky? %>
44
+ <% if local_assigns[:sticky_topics_divider] &&
45
+ !topic_iteration.last? && topic.sticky? && !topics[topic_counter + 1].sticky? %>
45
46
  <%= render 'thredded/topics/sticky_topics_divider' %>
46
47
  <% end %>
@@ -13,7 +13,12 @@
13
13
  topic: @new_topic,
14
14
  css_class: 'thredded--is-compact',
15
15
  placeholder: t('thredded.topics.form.title_placeholder_start') if @new_topic %>
16
- <%= render partial: 'thredded/topics/topic', collection: @topics, locals: {topics: @topics} %>
16
+ <%= render partial: 'thredded/topics/topic',
17
+ collection: @topics,
18
+ locals: {
19
+ sticky_topics_divider: true,
20
+ topics: @topics
21
+ } %>
17
22
  <% end %>
18
23
 
19
24
  <footer class="thredded--pagination-bottom">
@@ -25,8 +25,7 @@ pl:
25
25
  unsubscribe_instructions: :thredded.emails.post_notification.text.unsubscribe_instructions
26
26
  post_notification:
27
27
  html:
28
- email_sent_reason_html: >-
29
- Ten e-mail został wysłany do Ciebie, ponieważ śledzisz ten temat: "<a href="%{post_url}">%{topic_title}</a>".
28
+ email_sent_reason_html: 'Ten e-mail został wysłany do Ciebie, ponieważ śledzisz ten temat: "<a href="%{post_url}">%{topic_title}</a>".'
30
29
  post_lead_html: '%{user} <a href="%{post_url}">powiedział w "%{topic_title}"</a>:'
31
30
  unsubscribe_instructions_html: Aby wypisać się z tych e-maili, zaktualizuj swoje <a href="%{preferences_url}">preferencje</a>.
32
31
  subject: Nowy post w "%{topic_title}" przez %{user}
@@ -25,8 +25,7 @@ ru:
25
25
  unsubscribe_instructions: :thredded.emails.post_notification.text.unsubscribe_instructions
26
26
  post_notification:
27
27
  html:
28
- email_sent_reason_html: >-
29
- Это письмо было отправлено вам, потому что вы подписаны на тему: «<a href="%{post_url}">%{topic_title}</a>».
28
+ email_sent_reason_html: 'Это письмо было отправлено вам, потому что вы подписаны на тему: «<a href="%{post_url}">%{topic_title}</a>».'
30
29
  post_lead_html: '%{user} в <a href="%{post_url}">«%{topic_title}»</a>:'
31
30
  unsubscribe_instructions_html: Чтобы отписаться от этих писем, обновите свои <a href="%{preferences_url}">настройки</a>.
32
31
  subject: Новое сообщение в «%{topic_title}» от %{user}
@@ -37,6 +37,7 @@ require 'thredded/view_hooks/renderer'
37
37
  # Require these explicitly so that they do not need to be required if used in the initializer:
38
38
  require 'thredded/content_formatter'
39
39
  require 'thredded/email_transformer'
40
+ require 'thredded/base_notifier'
40
41
 
41
42
  require 'thredded/collection_to_strings_with_cache_renderer'
42
43
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Thredded
4
- VERSION = '0.13.3'
4
+ VERSION = '0.13.4'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thredded
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.3
4
+ version: 0.13.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Oliveira
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-08-13 00:00:00.000000000 Z
12
+ date: 2017-09-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pundit
@@ -569,14 +569,14 @@ dependencies:
569
569
  requirements:
570
570
  - - ">="
571
571
  - !ruby/object:Gem::Version
572
- version: '0'
572
+ version: 0.9.18
573
573
  type: :development
574
574
  prerelease: false
575
575
  version_requirements: !ruby/object:Gem::Requirement
576
576
  requirements:
577
577
  - - ">="
578
578
  - !ruby/object:Gem::Version
579
- version: '0'
579
+ version: 0.9.18
580
580
  - !ruby/object:Gem::Dependency
581
581
  name: web-console
582
582
  requirement: !ruby/object:Gem::Requirement
@@ -840,7 +840,6 @@ files:
840
840
  - app/models/thredded/user_private_topic_read_state.rb
841
841
  - app/models/thredded/user_topic_follow.rb
842
842
  - app/models/thredded/user_topic_read_state.rb
843
- - app/notifiers/thredded/base_notifier.rb
844
843
  - app/notifiers/thredded/email_notifier.rb
845
844
  - app/policies/thredded/messageboard_group_policy.rb
846
845
  - app/policies/thredded/messageboard_policy.rb
@@ -994,6 +993,7 @@ files:
994
993
  - lib/tasks/thredded_tasks.rake
995
994
  - lib/thredded.rb
996
995
  - lib/thredded/base_migration.rb
996
+ - lib/thredded/base_notifier.rb
997
997
  - lib/thredded/collection_to_strings_with_cache_renderer.rb
998
998
  - lib/thredded/content_formatter.rb
999
999
  - lib/thredded/database_seeder.rb