message_train 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +20 -0
  3. data/.ruby-gemset +1 -1
  4. data/.scss-lint.yml +7 -0
  5. data/.simplecov +1 -1
  6. data/.travis.yml +1 -1
  7. data/Gemfile +6 -2
  8. data/LICENSE.txt +2 -2
  9. data/README.rdoc +5 -5
  10. data/Rakefile +22 -21
  11. data/VERSION +1 -1
  12. data/app/assets/javascripts/message_train.js +1 -1
  13. data/app/assets/stylesheets/message_train.scss +29 -19
  14. data/app/controllers/concerns/message_train_support.rb +41 -37
  15. data/app/controllers/message_train/application_controller.rb +1 -0
  16. data/app/controllers/message_train/boxes_controller.rb +5 -4
  17. data/app/controllers/message_train/conversations_controller.rb +8 -7
  18. data/app/controllers/message_train/messages_controller.rb +25 -22
  19. data/app/controllers/message_train/participants_controller.rb +27 -23
  20. data/app/controllers/message_train/unsubscribes_controller.rb +37 -23
  21. data/app/helpers/message_train/application_helper.rb +6 -8
  22. data/app/helpers/message_train/attachments_helper.rb +12 -4
  23. data/app/helpers/message_train/boxes_helper.rb +38 -11
  24. data/app/helpers/message_train/collectives_helper.rb +38 -12
  25. data/app/helpers/message_train/conversations_helper.rb +43 -35
  26. data/app/helpers/message_train/messages_helper.rb +32 -25
  27. data/app/mailers/message_train/application_mailer.rb +7 -4
  28. data/app/mailers/message_train/previews/receipt_mailer_preview.rb +2 -3
  29. data/app/mailers/message_train/receipt_mailer.rb +14 -4
  30. data/app/models/message_train/attachment.rb +41 -25
  31. data/app/models/message_train/box.rb +159 -122
  32. data/app/models/message_train/conversation.rb +84 -41
  33. data/app/models/message_train/ignore.rb +8 -2
  34. data/app/models/message_train/message.rb +72 -42
  35. data/app/models/message_train/receipt.rb +30 -17
  36. data/app/models/message_train/unsubscribe.rb +1 -0
  37. data/app/views/application/404.html.haml +1 -1
  38. data/app/views/layouts/mailer.html.haml +2 -2
  39. data/app/views/layouts/mailer.text.haml +1 -1
  40. data/app/views/message_train/application/_attachment_fields.html.haml +1 -1
  41. data/app/views/message_train/application/_widget.html.haml +1 -1
  42. data/app/views/message_train/application/results.json.jbuilder +1 -1
  43. data/app/views/message_train/boxes/_dropdown_list.html.haml +1 -1
  44. data/app/views/message_train/boxes/_list_item.html.haml +1 -1
  45. data/app/views/message_train/boxes/show.html.haml +1 -1
  46. data/app/views/message_train/collectives/_dropdown_list.html.haml +1 -1
  47. data/app/views/message_train/collectives/_list_item.html.haml +1 -1
  48. data/app/views/message_train/conversations/_deleted_toggle.html.haml +1 -1
  49. data/app/views/message_train/conversations/_ignored_toggle.html.haml +2 -2
  50. data/app/views/message_train/conversations/_read_toggle.html.haml +1 -1
  51. data/app/views/message_train/conversations/_toggle.html.haml +1 -1
  52. data/app/views/message_train/conversations/_trashed_toggle.html.haml +1 -1
  53. data/app/views/message_train/conversations/show.html.haml +2 -2
  54. data/app/views/message_train/conversations/show.json.jbuilder +5 -1
  55. data/app/views/message_train/messages/_form.html.haml +1 -1
  56. data/app/views/message_train/messages/_message.html.haml +6 -6
  57. data/app/views/message_train/messages/_toggle.html.haml +1 -1
  58. data/app/views/message_train/messages/show.json.jbuilder +5 -1
  59. data/app/views/message_train/participants/_participant.json.jbuilder +1 -1
  60. data/app/views/message_train/participants/index.json.jbuilder +1 -1
  61. data/app/views/message_train/participants/show.json.jbuilder +1 -1
  62. data/app/views/message_train/receipt_mailer/notification_email.html.haml +1 -1
  63. data/app/views/message_train/receipt_mailer/notification_email.text.haml +1 -1
  64. data/app/views/message_train/unsubscribes/index.html.haml +1 -1
  65. data/config/environment.rb +1 -1
  66. data/config/initializers/date_time.rb +2 -2
  67. data/config/locales/en.yml +1 -1
  68. data/config/routes.rb +37 -15
  69. data/lib/generators/message_train/install/install_generator.rb +26 -11
  70. data/lib/generators/message_train/install/templates/initializer.rb +0 -2
  71. data/lib/generators/message_train/utils.rb +11 -4
  72. data/lib/message_train/configuration.rb +4 -5
  73. data/lib/message_train/engine.rb +1 -7
  74. data/lib/message_train/localization.rb +14 -18
  75. data/lib/message_train/mixin.rb +211 -150
  76. data/lib/message_train/version.rb +1 -0
  77. data/lib/message_train.rb +7 -6
  78. data/message_train.gemspec +24 -11
  79. data/spec/controllers/message_train/boxes_controller_spec.rb +63 -15
  80. data/spec/controllers/message_train/concerns_spec.rb +17 -13
  81. data/spec/controllers/message_train/conversations_controller_spec.rb +44 -12
  82. data/spec/controllers/message_train/messages_controller_spec.rb +87 -40
  83. data/spec/controllers/message_train/participants_controller_spec.rb +10 -4
  84. data/spec/controllers/message_train/unsubscribes_controller_spec.rb +43 -13
  85. data/spec/dummy/Rakefile +2 -1
  86. data/spec/dummy/app/assets/stylesheets/application.css.scss +7 -23
  87. data/spec/dummy/app/controllers/application_controller.rb +7 -7
  88. data/spec/dummy/app/models/group.rb +1 -1
  89. data/spec/dummy/app/models/role.rb +11 -7
  90. data/spec/dummy/app/models/user.rb +6 -5
  91. data/spec/dummy/app/views/layouts/_top_navigation.html.haml +1 -1
  92. data/spec/dummy/app/views/layouts/application.html.haml +1 -1
  93. data/spec/dummy/app/views/pages/index.html.haml +1 -1
  94. data/spec/dummy/config/application.rb +23 -17
  95. data/spec/dummy/config/environments/development.rb +5 -4
  96. data/spec/dummy/config/environments/production.rb +10 -6
  97. data/spec/dummy/config/environments/test.rb +4 -3
  98. data/spec/dummy/config/initializers/assets.rb +2 -1
  99. data/spec/dummy/config/initializers/backtrace_silencers.rb +4 -2
  100. data/spec/dummy/config/initializers/bootstrap_leather.rb +1 -1
  101. data/spec/dummy/config/initializers/devise.rb +63 -44
  102. data/spec/dummy/config/initializers/high_voltage.rb +1 -1
  103. data/spec/dummy/config/initializers/message_train.rb +5 -2
  104. data/spec/dummy/config/initializers/mime_types.rb +1 -1
  105. data/spec/dummy/config/initializers/paperclip.rb +5 -2
  106. data/spec/dummy/config/initializers/rolify.rb +3 -2
  107. data/spec/dummy/config/initializers/wrap_parameters.rb +2 -1
  108. data/spec/dummy/config/routes.rb +1 -3
  109. data/spec/dummy/config/settings.yml +1 -1
  110. data/spec/dummy/db/schema.rb +98 -98
  111. data/spec/dummy/db/seeds/conversations.seeds.rb +160 -160
  112. data/spec/dummy/db/seeds/development/conversations.seeds.rb +6 -2
  113. data/spec/dummy/db/seeds/groups.seeds.rb +11 -12
  114. data/spec/dummy/db/seeds/test/attachments.seeds.rb +13 -3
  115. data/spec/dummy/db/seeds/test/conversations.seeds.rb +6 -2
  116. data/spec/dummy/db/seeds/unsubscribes.seeds.rb +1 -1
  117. data/spec/dummy/db/seeds/users.seeds.rb +47 -42
  118. data/spec/dummy/db/test.sqlite3 +0 -0
  119. data/spec/factories/attachment.rb +6 -2
  120. data/spec/factories/group.rb +1 -4
  121. data/spec/factories/message.rb +29 -23
  122. data/spec/factories/user.rb +6 -4
  123. data/spec/features/boxes_spec.rb +76 -24
  124. data/spec/features/conversations_spec.rb +19 -7
  125. data/spec/features/messages_spec.rb +24 -5
  126. data/spec/features/unsubscribes_spec.rb +36 -9
  127. data/spec/helpers/message_train/application_helper_spec.rb +1 -1
  128. data/spec/helpers/message_train/attachment_helper_spec.rb +27 -12
  129. data/spec/helpers/message_train/boxes_helper_spec.rb +1 -1
  130. data/spec/helpers/message_train/collectives_helper_spec.rb +25 -9
  131. data/spec/helpers/message_train/conversations_helper_spec.rb +239 -120
  132. data/spec/helpers/message_train/messages_helper_spec.rb +137 -81
  133. data/spec/message_train_spec.rb +3 -2
  134. data/spec/models/group_spec.rb +12 -9
  135. data/spec/models/message_train/attachment_spec.rb +33 -30
  136. data/spec/models/message_train/box_spec.rb +243 -60
  137. data/spec/models/message_train/conversation_spec.rb +16 -12
  138. data/spec/models/message_train/ignore_spec.rb +3 -1
  139. data/spec/models/message_train/message_spec.rb +22 -7
  140. data/spec/models/message_train/receipt_spec.rb +14 -4
  141. data/spec/models/role_spec.rb +10 -6
  142. data/spec/models/user_spec.rb +74 -22
  143. data/spec/rails_helper.rb +9 -4
  144. data/spec/spec_helper.rb +6 -54
  145. data/spec/support/controller_behaviors.rb +8 -5
  146. data/spec/support/controller_macros.rb +2 -2
  147. data/spec/support/factory_girl.rb +1 -1
  148. data/spec/support/feature_behaviors.rb +42 -13
  149. data/spec/support/loaded_site/attachments.rb +8 -0
  150. data/spec/support/loaded_site/conversations.rb +73 -0
  151. data/spec/support/{groups.rb → loaded_site/groups.rb} +1 -1
  152. data/spec/support/{loaded_site.rb → loaded_site/loaded_site.rb} +1 -1
  153. data/spec/support/{messages.rb → loaded_site/messages.rb} +13 -5
  154. data/spec/support/{roles.rb → loaded_site/roles.rb} +1 -1
  155. data/spec/support/{users.rb → loaded_site/users.rb} +1 -1
  156. data/spec/support/shared_connection.rb +8 -6
  157. data/spec/support/utilities.rb +10 -10
  158. metadata +67 -10
  159. data/spec/dummy/config/unused/temporary_i18n_debugging.rb +0 -12
  160. data/spec/support/attachments.rb +0 -4
  161. data/spec/support/conversations.rb +0 -23
@@ -1,4 +1,5 @@
1
1
  module MessageTrain
2
+ # Participants controller
2
3
  class ParticipantsController < MessageTrain::ApplicationController
3
4
  before_filter :load_participants
4
5
  before_filter :load_participant, only: :show
@@ -19,30 +20,33 @@ module MessageTrain
19
20
 
20
21
  private
21
22
 
22
- def load_participants
23
- if params[:model].empty?
24
- raise ActiveRecord::RecordNotFound
25
- end
26
- model_sym = params[:model].to_sym
27
- model = MessageTrain.configuration.recipient_tables[model_sym].constantize
28
- method = MessageTrain.configuration.address_book_methods[model_sym]
29
- fallback_method = MessageTrain.configuration.address_book_method
30
- current_participant = send(MessageTrain.configuration.current_user_method)
31
- if !method.nil? && model.respond_to?(method)
32
- @participants = model.send(method, current_participant)
33
- elsif !fallback_method.nil? && model.respond_to?(fallback_method)
34
- @participants = model.send(fallback_method, current_participant)
35
- else
36
- @participants = model.all
37
- end
38
- if params[:query].present?
39
- field_name = MessageTrain.configuration.slug_columns[model_sym]
40
- @participants = @participants.where("#{field_name} LIKE ?", "#{params[:query]}%")
41
- end
23
+ def load_participants
24
+ params[:model].empty? && raise(ActiveRecord::RecordNotFound)
25
+ model_sym = params[:model].to_sym
26
+ model = MessageTrain.configuration.recipient_tables[model_sym].constantize
27
+ method = MessageTrain.configuration.address_book_methods[model_sym]
28
+ fallback_method = MessageTrain.configuration.address_book_method
29
+ current_participant = send(MessageTrain.configuration.current_user_method)
30
+ if !method.nil? && model.respond_to?(method)
31
+ @participants = model.send(method, current_participant)
32
+ elsif !fallback_method.nil? && model.respond_to?(fallback_method)
33
+ @participants = model.send(fallback_method, current_participant)
34
+ else
35
+ @participants = model.all
42
36
  end
43
-
44
- def load_participant
45
- @participant = @participants.find(params[:id])
37
+ if params[:query].present?
38
+ field_name = MessageTrain.configuration.slug_columns[model_sym]
39
+ pattern = Regexp.union('\\', '%', '_')
40
+ query = params[:query].gsub(pattern) { |x| ['\\', x].join }
41
+ @participants = @participants.where(
42
+ "#{field_name} LIKE ?",
43
+ "#{query}%"
44
+ )
46
45
  end
46
+ end
47
+
48
+ def load_participant
49
+ @participant = @participants.find(params[:id])
50
+ end
47
51
  end
48
52
  end
@@ -1,6 +1,6 @@
1
1
  module MessageTrain
2
+ # Unsubscribes controller
2
3
  class UnsubscribesController < MessageTrain::ApplicationController
3
-
4
4
  # GET /unsubscribes
5
5
  def index
6
6
  @subscriptions = @box_user.subscriptions
@@ -16,28 +16,36 @@ module MessageTrain
16
16
  else
17
17
  flash[:error] = @unsubscribe.errors.full_messages.to_sentence
18
18
  end
19
- else
20
- unsub = unsubscribe_params
21
- model = unsub[:from_type].constantize
22
- @from = model.find(unsub[:from_id])
23
- if @from == @box_user || @from.allows_receiving_by?(@box_user)
24
- @unsubscribe = @box_user.unsubscribe_from(@from)
25
- if @unsubscribe.errors.empty?
26
- if @from == @box_user
27
- flash[:notice] = :unsubscribe_message.l
28
- else
29
- name_column = MessageTrain.configuration.name_columns[@from.class.table_name.to_sym]
30
- collective_name = @from.send(name_column)
31
- collective_type = @from.class.name
32
- flash[:notice] = :collective_unsubscribe_message.l(collective_name: collective_name, collective_type: collective_type)
33
- end
19
+ redirect_to message_train.unsubscribes_url
20
+ return
21
+ end
22
+ unsub = unsubscribe_params
23
+ model = unsub[:from_type].constantize
24
+ @from = model.find(unsub[:from_id])
25
+ if @from == @box_user || @from.allows_receiving_by?(@box_user)
26
+ @unsubscribe = @box_user.unsubscribe_from(@from)
27
+ if @unsubscribe.errors.empty?
28
+ if @from == @box_user
29
+ flash[:notice] = :unsubscribe_message.l
34
30
  else
35
- flash[:error] = @unsubscribe.errors.full_messages.to_sentence
31
+ name_column = MessageTrain.configuration.name_columns[
32
+ @from.class.table_name.to_sym
33
+ ]
34
+ collective_name = @from.send(name_column)
35
+ collective_type = @from.class.name
36
+ flash[:notice] = :collective_unsubscribe_message.l(
37
+ collective_name: collective_name,
38
+ collective_type: collective_type
39
+ )
36
40
  end
37
41
  else
38
- flash[:error] = :you_are_not_in_that_collective_type.l(collective_type: model.name)
39
- raise ActiveRecord::RecordNotFound
42
+ flash[:error] = @unsubscribe.errors.full_messages.to_sentence
40
43
  end
44
+ else
45
+ flash[:error] = :you_are_not_in_that_collective_type.l(
46
+ collective_type: model.name
47
+ )
48
+ raise ActiveRecord::RecordNotFound
41
49
  end
42
50
  redirect_to message_train.unsubscribes_url
43
51
  end
@@ -53,10 +61,15 @@ module MessageTrain
53
61
  if @from == @box_user
54
62
  message = :unsubscribe_removed_message.l
55
63
  else
56
- name_column = MessageTrain.configuration.name_columns[@unsubscribe.from.class.table_name.to_sym]
64
+ name_column = MessageTrain.configuration.name_columns[
65
+ @unsubscribe.from.class.table_name.to_sym
66
+ ]
57
67
  collective_name = @unsubscribe.from.send(name_column)
58
68
  collective_type = @unsubscribe.from_type
59
- message = :collective_unsubscribe_removed_message.l(collective_name: collective_name, collective_type: collective_type)
69
+ message = :collective_unsubscribe_removed_message.l(
70
+ collective_name: collective_name,
71
+ collective_type: collective_type
72
+ )
60
73
  end
61
74
  @unsubscribe.destroy
62
75
  flash[:notice] = message
@@ -64,9 +77,10 @@ module MessageTrain
64
77
  redirect_to message_train.unsubscribes_url
65
78
  end
66
79
 
67
- private
80
+ private
68
81
 
69
- # Never trust parameters from the scary internet, only allow the white list through.
82
+ # Never trust parameters from the scary internet, only allow the white list
83
+ # through.
70
84
  def unsubscribe_params
71
85
  params.require(:unsubscribe).permit(:from_type, :from_id)
72
86
  end
@@ -1,26 +1,24 @@
1
1
  module MessageTrain
2
+ # Application helper
2
3
  module ApplicationHelper
3
-
4
4
  def message_train_widget
5
5
  render partial: 'message_train/application/widget'
6
6
  end
7
7
 
8
8
  def fuzzy_date(date)
9
9
  time = Time.parse(date.strftime('%F %T'))
10
- # Don't get confused: ">" here means "after", not "more than"
11
- if time > 1.minute.ago
10
+ case Time.now - time
11
+ when 0..1.minute
12
12
  :just_now.l
13
- elsif time > 1.day.ago
13
+ when 1.minute..1.day
14
14
  l(time, format: :fuzzy_today)
15
- elsif time > 1.week.ago
15
+ when 1.day..1.week
16
16
  l(time, format: :fuzzy_this_week)
17
- elsif time > 1.year.ago
17
+ when 1.week..1.year
18
18
  l(time, format: :fuzzy_date_without_year)
19
19
  else
20
20
  l(time, format: :fuzzy_date)
21
21
  end
22
-
23
22
  end
24
-
25
23
  end
26
24
  end
@@ -1,11 +1,16 @@
1
1
  module MessageTrain
2
+ # Attachments helper
2
3
  module AttachmentsHelper
3
4
  def attachment_icon(attachment)
4
- html = ""
5
+ html = ''
5
6
  if attachment.image?
6
7
  html << image_tag(attachment.attachment.url(:thumb))
7
8
  else
8
- html << content_tag(:span, '', class: 'glyphicon glyphicon-save-file glyphicon-thumbnail')
9
+ html << content_tag(
10
+ :span,
11
+ '',
12
+ class: 'glyphicon glyphicon-save-file glyphicon-thumbnail'
13
+ )
9
14
  html << tag(:br)
10
15
  html << attachment.attachment_file_name
11
16
  end
@@ -13,7 +18,10 @@ module MessageTrain
13
18
  end
14
19
 
15
20
  def attachment_link(attachment)
16
- render partial: 'message_train/application/attachment_link', locals: { attachment: attachment }
21
+ render(
22
+ partial: 'message_train/application/attachment_link',
23
+ locals: { attachment: attachment }
24
+ )
17
25
  end
18
26
  end
19
- end
27
+ end
@@ -1,35 +1,62 @@
1
1
  module MessageTrain
2
+ # Boxes helper
2
3
  module BoxesHelper
3
-
4
4
  def box_nav_item(box)
5
5
  text = box.title
6
6
  link = message_train.box_path(box.division)
7
7
  unread_count = box.unread_count
8
- if unread_count > 0
9
- text << badge(unread_count.to_s.gsub(/\s+/, ""), 'info pull-right')
10
- end
11
- nav_item text.gsub(/[\n\t]/,'').html_safe, link
8
+ unread_count > 0 &&
9
+ text << badge(unread_count.to_s.gsub(/\s+/, ''), 'info pull-right')
10
+ nav_item text.gsub(/[\n\t]/, '').html_safe, link
12
11
  end
13
12
 
14
13
  def box_list_item(box, html_options = {})
15
- render partial: 'message_train/boxes/list_item', locals: { box: box, html_options: html_options, unread_count: box.unread_count }
14
+ render(
15
+ partial: 'message_train/boxes/list_item',
16
+ locals: {
17
+ box: box,
18
+ html_options: html_options,
19
+ unread_count: box.unread_count
20
+ }
21
+ )
16
22
  end
17
23
 
18
24
  def boxes_widget(box_user)
19
- render partial: 'message_train/boxes/widget', locals: { boxes: box_user.all_boxes }
25
+ render(
26
+ partial: 'message_train/boxes/widget',
27
+ locals: { boxes: box_user.all_boxes }
28
+ )
20
29
  end
21
30
 
22
- def boxes_dropdown_list(box_user, options = {})
23
- render partial: 'message_train/boxes/dropdown_list', locals: { boxes: box_user.all_boxes }
31
+ def boxes_dropdown_list(box_user)
32
+ render(
33
+ partial: 'message_train/boxes/dropdown_list',
34
+ locals: { boxes: box_user.all_boxes }
35
+ )
24
36
  end
25
37
 
26
38
  def box_participant_name(participant)
27
- participant.send(MessageTrain.configuration.name_columns[participant.class.table_name.to_sym])
39
+ participant.send(
40
+ MessageTrain.configuration.name_columns[
41
+ participant.class.table_name.to_sym
42
+ ]
43
+ )
28
44
  end
29
45
 
30
46
  def box_participant_slug(participant)
31
- participant.send(MessageTrain.configuration.slug_columns[participant.class.table_name.to_sym])
47
+ participant.send(
48
+ MessageTrain.configuration.slug_columns[
49
+ participant.class.table_name.to_sym
50
+ ]
51
+ )
32
52
  end
33
53
 
54
+ def box_participant_path(participant)
55
+ message_train.box_model_participant_path(
56
+ @box,
57
+ participant.class.table_name,
58
+ participant.id
59
+ )
60
+ end
34
61
  end
35
62
  end
@@ -1,8 +1,11 @@
1
1
  module MessageTrain
2
+ # Collectives helper
2
3
  module CollectivesHelper
3
-
4
4
  def collective_boxes_widget(collective, box_user)
5
- render partial: 'message_train/collectives/widget', locals: { collective: collective, box_user: box_user }
5
+ render(
6
+ partial: 'message_train/collectives/widget',
7
+ locals: { collective: collective, box_user: box_user }
8
+ )
6
9
  end
7
10
 
8
11
  def collective_nav_item(box, box_user)
@@ -16,33 +19,56 @@ module MessageTrain
16
19
  end
17
20
  link = message_train.collective_box_path(box.parent.path_part, division)
18
21
  unread_count = box.unread_count
19
- if unread_count > 0
20
- text << badge(unread_count.to_s, 'info pull-right')
21
- end
22
+ unread_count > 0 && text << badge(unread_count.to_s, 'info pull-right')
22
23
  nav_item text.html_safe, link
23
24
  end
24
25
 
25
26
  def collective_list_item(box, html_options = {})
26
- render partial: 'message_train/collectives/list_item', locals: { box: box, html_options: html_options, unread_count: box.unread_count }
27
+ render(
28
+ partial: 'message_train/collectives/list_item',
29
+ locals: {
30
+ box: box,
31
+ html_options: html_options,
32
+ unread_count: box.unread_count
33
+ }
34
+ )
27
35
  end
28
36
 
29
37
  def collective_boxes_dropdown_list(box_user)
30
38
  total_unread_count = {}
31
39
  show = {}
32
40
  box_user.collective_boxes.each do |table_sym, collectives|
33
- total_unread_count[table_sym] = collectives.collect { |collective_box| collective_box.unread_count }.sum
34
- show[table_sym] = collectives.select { |collective_box| collective_box.parent.allows_sending_by?(box_user) || collective_box.parent.allows_receiving_by?(box_user) }.any?
41
+ total_unread_count[table_sym] = collectives.collect(&:unread_count).sum
42
+ show[table_sym] = collectives.select do |collective_box|
43
+ collective_box.parent.allows_sending_by?(box_user) ||
44
+ collective_box.parent.allows_receiving_by?(box_user)
45
+ end.any?
35
46
  end
36
- render partial: 'message_train/collectives/dropdown_list', locals: { collective_boxes: box_user.collective_boxes, total_unread_count: total_unread_count, show: show, box_user: box_user }
47
+ render(
48
+ partial: 'message_train/collectives/dropdown_list',
49
+ locals: {
50
+ collective_boxes: box_user.collective_boxes,
51
+ total_unread_count: total_unread_count,
52
+ show: show,
53
+ box_user: box_user
54
+ }
55
+ )
37
56
  end
38
57
 
39
58
  def collective_name(collective)
40
- collective.send(MessageTrain.configuration.name_columns[collective.class.table_name.to_sym])
59
+ collective.send(
60
+ MessageTrain.configuration.name_columns[
61
+ collective.class.table_name.to_sym
62
+ ]
63
+ )
41
64
  end
42
65
 
43
66
  def collective_slug(collective)
44
- collective.send(MessageTrain.configuration.slug_columns[collective.class.table_name.to_sym])
67
+ collective.send(
68
+ MessageTrain.configuration.slug_columns[
69
+ collective.class.table_name.to_sym
70
+ ]
71
+ )
45
72
  end
46
-
47
73
  end
48
74
  end
@@ -1,4 +1,5 @@
1
1
  module MessageTrain
2
+ # Conversations helper
2
3
  module ConversationsHelper
3
4
  def conversation_senders(conversation)
4
5
  names = []
@@ -11,71 +12,78 @@ module MessageTrain
11
12
  def conversation_class(box, conversation)
12
13
  css_classes = []
13
14
 
14
- if conversation.includes_unread_for?(@box_user)
15
- css_classes << 'unread'
16
- else
17
- css_classes << 'read'
18
- end
15
+ css_classes << if conversation.includes_unread_for?(@box_user)
16
+ 'unread'
17
+ else
18
+ 'read'
19
+ end
19
20
 
20
- if conversation.includes_drafts_by?(@box_user)
21
- css_classes << 'draft'
22
- end
21
+ conversation.includes_drafts_by?(@box_user) && css_classes << 'draft'
23
22
 
24
- unless conversation.includes_undeleted_for?(@box_user)
25
- css_classes << 'hide'
26
- end
23
+ !conversation.includes_undeleted_for?(@box_user) && css_classes << 'hide'
27
24
 
28
25
  if box.division == :trash
29
- unless conversation.includes_trashed_for?(@box_user)
26
+ !conversation.includes_trashed_for?(@box_user) &&
30
27
  css_classes << 'hide'
31
- end
32
28
  else
33
- unless conversation.includes_untrashed_for?(@box_user)
29
+ !conversation.includes_untrashed_for?(@box_user) &&
34
30
  css_classes << 'hide'
35
- end
36
31
  if box.division == :ignored
37
- unless conversation.is_ignored?(@box_user)
38
- css_classes << 'hide'
39
- end
32
+ !conversation.participant_ignored?(@box_user) && css_classes << 'hide'
40
33
  else
41
- if conversation.is_ignored?(@box_user)
42
- css_classes << 'hide'
43
- end
34
+ conversation.participant_ignored?(@box_user) && css_classes << 'hide'
44
35
  end
45
36
  end
46
37
  css_classes.uniq.join(' ')
47
38
  end
48
39
 
49
40
  def conversation_trashed_toggle(conversation, collective = nil)
50
- render partial: 'message_train/conversations/trashed_toggle', locals: { conversation: conversation, collective: collective }
41
+ render(
42
+ partial: 'message_train/conversations/trashed_toggle',
43
+ locals: { conversation: conversation, collective: collective }
44
+ )
51
45
  end
52
46
 
53
47
  def conversation_read_toggle(conversation, collective = nil)
54
- render partial: 'message_train/conversations/read_toggle', locals: { conversation: conversation, collective: collective }
48
+ render(
49
+ partial: 'message_train/conversations/read_toggle',
50
+ locals: { conversation: conversation, collective: collective }
51
+ )
55
52
  end
56
53
 
57
54
  def conversation_ignored_toggle(conversation, collective = nil)
58
- render partial: 'message_train/conversations/ignored_toggle', locals: { conversation: conversation, collective: collective }
55
+ render(
56
+ partial: 'message_train/conversations/ignored_toggle',
57
+ locals: { conversation: conversation, collective: collective }
58
+ )
59
59
  end
60
60
 
61
61
  def conversation_deleted_toggle(conversation, collective = nil)
62
- render partial: 'message_train/conversations/deleted_toggle', locals: { conversation: conversation, collective: collective }
62
+ render(
63
+ partial: 'message_train/conversations/deleted_toggle',
64
+ locals: { conversation: conversation, collective: collective }
65
+ )
63
66
  end
64
67
 
65
- private
68
+ private
66
69
 
67
- def conversation_toggle(conversation, icon, mark_to_set, method, title, options = {})
70
+ # rubocop:disable Metrics/ParameterLists
71
+ def conversation_toggle(conv, icon, mark, method, title, options = {})
68
72
  options[:remote] = true
69
73
  options[:method] = method
70
74
  options[:title] = title
71
- options[:class] ||= ""
72
- options[:class] += " " + mark_to_set.to_s + "-toggle"
73
- render partial: 'message_train/conversations/toggle', locals: {
74
- conversation: conversation,
75
- icon: icon,
76
- mark_to_set: mark_to_set,
77
- options: options
78
- }
75
+ options[:class] ||= ''
76
+ options[:class] += " #{mark}-toggle"
77
+ render(
78
+ partial: 'message_train/conversations/toggle',
79
+ locals: {
80
+ conversation: conv,
81
+ icon: icon,
82
+ mark_to_set: mark,
83
+ options: options
84
+ }
85
+ )
79
86
  end
87
+ # rubocop:enable Metrics/ParameterLists
80
88
  end
81
89
  end
@@ -1,60 +1,67 @@
1
1
  module MessageTrain
2
+ # Messages helper
2
3
  module MessagesHelper
3
4
  def message_class(box, message)
4
5
  css_classes = []
5
6
 
6
- if message.is_unread_for?(@box_user)
7
- css_classes << 'unread panel-info'
8
- else
9
- css_classes << 'read'
10
- end
7
+ css_classes << if message.is_unread_for?(@box_user)
8
+ 'unread panel-info'
9
+ else
10
+ 'read'
11
+ end
11
12
 
12
- if message.draft
13
- css_classes << 'draft'
14
- end
13
+ message.draft && css_classes << 'draft'
15
14
 
16
15
  if box.division == :trash
17
- unless message.is_trashed_for?(@box_user)
18
- css_classes << 'hide'
19
- end
16
+ !message.is_trashed_for?(@box_user) && css_classes << 'hide'
20
17
  else
21
- unless message.is_untrashed_for?(@box_user)
22
- css_classes << 'hide'
23
- end
18
+ !message.is_untrashed_for?(@box_user) && css_classes << 'hide'
24
19
  end
25
20
  css_classes.join(' ')
26
21
  end
27
22
 
28
23
  def message_trashed_toggle(message)
29
- render partial: 'message_train/messages/trashed_toggle', locals: { message: message }
24
+ render(
25
+ partial: 'message_train/messages/trashed_toggle',
26
+ locals: { message: message }
27
+ )
30
28
  end
31
29
 
32
30
  def message_read_toggle(message)
33
- render partial: 'message_train/messages/read_toggle', locals: { message: message }
31
+ render(
32
+ partial: 'message_train/messages/read_toggle',
33
+ locals: { message: message }
34
+ )
34
35
  end
35
36
 
36
37
  def message_deleted_toggle(message)
37
- render partial: 'message_train/messages/deleted_toggle', locals: { message: message }
38
+ render(
39
+ partial: 'message_train/messages/deleted_toggle',
40
+ locals: { message: message }
41
+ )
38
42
  end
39
43
 
40
44
  def message_recipients(message)
41
45
  message.recipients.collect { |x| box_participant_name(x) }.to_sentence
42
46
  end
43
47
 
44
- private
48
+ private
45
49
 
46
50
  def message_toggle(message, icon, mark_to_set, title, options = {})
47
51
  options[:remote] = true
48
52
  options[:id] = "mark_#{mark_to_set}_#{message.id}"
49
- options[:class] = "mark-link"
53
+ options[:class] = 'mark-link'
50
54
  options[:method] = :put
51
55
  options[:title] = title
52
- render partial: 'message_train/messages/toggle', locals: {
53
- message: message,
54
- icon: icon,
55
- mark_to_set: mark_to_set,
56
- options: options
57
- }
56
+ render(
57
+ partial: 'message_train/messages/toggle',
58
+ locals: {
59
+ message: message,
60
+ icon: icon,
61
+ mark_to_set: mark_to_set,
62
+ options: options
63
+ }
64
+ )
58
65
  end
59
66
  end
60
67
  end
@@ -1,8 +1,11 @@
1
1
  module MessageTrain
2
+ # Application mailer
2
3
  class ApplicationMailer < ActionMailer::Base
3
- default from: MessageTrain.configuration.from_email,
4
- charset: "utf-8",
5
- content_type: "text/html"
4
+ default(
5
+ from: MessageTrain.configuration.from_email,
6
+ charset: 'utf-8',
7
+ content_type: 'text/html'
8
+ )
6
9
  layout 'mailer'
7
10
  end
8
- end
11
+ end
@@ -1,10 +1,9 @@
1
1
  module MessageTrain
2
+ # Receipt mailer preview
2
3
  class ReceiptMailerPreview < ActionMailer::Preview
3
-
4
4
  def notification_email
5
5
  receipt = MessageTrain::Receipt.last
6
6
  ReceiptMailer.notification_email(receipt)
7
7
  end
8
-
9
8
  end
10
- end
9
+ end
@@ -1,17 +1,27 @@
1
1
  module MessageTrain
2
+ # Receipt mailer
2
3
  class ReceiptMailer < ApplicationMailer
3
4
  def notification_email(receipt)
4
5
  @receipt = receipt
5
6
  @recipient = receipt.recipient
6
7
  @through = receipt.received_through
7
8
  if @recipient == @through
8
- @heading = :new_message_on_site_name.l(site_name: MessageTrain.configuration.site_name)
9
+ @heading = :new_message_on_site_name.l(
10
+ site_name: MessageTrain.configuration.site_name
11
+ )
9
12
  else
10
- @through_name = @through.send(MessageTrain.configuration.name_columns[@through.class.table_name.to_sym])
11
- @heading = :new_message_through_on_site_name.l(site_name: MessageTrain.configuration.site_name, through: @through_name)
13
+ @through_name = @through.send(
14
+ MessageTrain.configuration.name_columns[
15
+ @through.class.table_name.to_sym
16
+ ]
17
+ )
18
+ @heading = :new_message_through_on_site_name.l(
19
+ site_name: MessageTrain.configuration.site_name,
20
+ through: @through_name
21
+ )
12
22
  end
13
23
  @subject = "#{@heading}: #{@receipt.message.subject}"
14
24
  mail(to: @recipient.email, subject: @subject)
15
25
  end
16
26
  end
17
- end
27
+ end