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.
- checksums.yaml +4 -4
- data/.rubocop.yml +20 -0
- data/.ruby-gemset +1 -1
- data/.scss-lint.yml +7 -0
- data/.simplecov +1 -1
- data/.travis.yml +1 -1
- data/Gemfile +6 -2
- data/LICENSE.txt +2 -2
- data/README.rdoc +5 -5
- data/Rakefile +22 -21
- data/VERSION +1 -1
- data/app/assets/javascripts/message_train.js +1 -1
- data/app/assets/stylesheets/message_train.scss +29 -19
- data/app/controllers/concerns/message_train_support.rb +41 -37
- data/app/controllers/message_train/application_controller.rb +1 -0
- data/app/controllers/message_train/boxes_controller.rb +5 -4
- data/app/controllers/message_train/conversations_controller.rb +8 -7
- data/app/controllers/message_train/messages_controller.rb +25 -22
- data/app/controllers/message_train/participants_controller.rb +27 -23
- data/app/controllers/message_train/unsubscribes_controller.rb +37 -23
- data/app/helpers/message_train/application_helper.rb +6 -8
- data/app/helpers/message_train/attachments_helper.rb +12 -4
- data/app/helpers/message_train/boxes_helper.rb +38 -11
- data/app/helpers/message_train/collectives_helper.rb +38 -12
- data/app/helpers/message_train/conversations_helper.rb +43 -35
- data/app/helpers/message_train/messages_helper.rb +32 -25
- data/app/mailers/message_train/application_mailer.rb +7 -4
- data/app/mailers/message_train/previews/receipt_mailer_preview.rb +2 -3
- data/app/mailers/message_train/receipt_mailer.rb +14 -4
- data/app/models/message_train/attachment.rb +41 -25
- data/app/models/message_train/box.rb +159 -122
- data/app/models/message_train/conversation.rb +84 -41
- data/app/models/message_train/ignore.rb +8 -2
- data/app/models/message_train/message.rb +72 -42
- data/app/models/message_train/receipt.rb +30 -17
- data/app/models/message_train/unsubscribe.rb +1 -0
- data/app/views/application/404.html.haml +1 -1
- data/app/views/layouts/mailer.html.haml +2 -2
- data/app/views/layouts/mailer.text.haml +1 -1
- data/app/views/message_train/application/_attachment_fields.html.haml +1 -1
- data/app/views/message_train/application/_widget.html.haml +1 -1
- data/app/views/message_train/application/results.json.jbuilder +1 -1
- data/app/views/message_train/boxes/_dropdown_list.html.haml +1 -1
- data/app/views/message_train/boxes/_list_item.html.haml +1 -1
- data/app/views/message_train/boxes/show.html.haml +1 -1
- data/app/views/message_train/collectives/_dropdown_list.html.haml +1 -1
- data/app/views/message_train/collectives/_list_item.html.haml +1 -1
- data/app/views/message_train/conversations/_deleted_toggle.html.haml +1 -1
- data/app/views/message_train/conversations/_ignored_toggle.html.haml +2 -2
- data/app/views/message_train/conversations/_read_toggle.html.haml +1 -1
- data/app/views/message_train/conversations/_toggle.html.haml +1 -1
- data/app/views/message_train/conversations/_trashed_toggle.html.haml +1 -1
- data/app/views/message_train/conversations/show.html.haml +2 -2
- data/app/views/message_train/conversations/show.json.jbuilder +5 -1
- data/app/views/message_train/messages/_form.html.haml +1 -1
- data/app/views/message_train/messages/_message.html.haml +6 -6
- data/app/views/message_train/messages/_toggle.html.haml +1 -1
- data/app/views/message_train/messages/show.json.jbuilder +5 -1
- data/app/views/message_train/participants/_participant.json.jbuilder +1 -1
- data/app/views/message_train/participants/index.json.jbuilder +1 -1
- data/app/views/message_train/participants/show.json.jbuilder +1 -1
- data/app/views/message_train/receipt_mailer/notification_email.html.haml +1 -1
- data/app/views/message_train/receipt_mailer/notification_email.text.haml +1 -1
- data/app/views/message_train/unsubscribes/index.html.haml +1 -1
- data/config/environment.rb +1 -1
- data/config/initializers/date_time.rb +2 -2
- data/config/locales/en.yml +1 -1
- data/config/routes.rb +37 -15
- data/lib/generators/message_train/install/install_generator.rb +26 -11
- data/lib/generators/message_train/install/templates/initializer.rb +0 -2
- data/lib/generators/message_train/utils.rb +11 -4
- data/lib/message_train/configuration.rb +4 -5
- data/lib/message_train/engine.rb +1 -7
- data/lib/message_train/localization.rb +14 -18
- data/lib/message_train/mixin.rb +211 -150
- data/lib/message_train/version.rb +1 -0
- data/lib/message_train.rb +7 -6
- data/message_train.gemspec +24 -11
- data/spec/controllers/message_train/boxes_controller_spec.rb +63 -15
- data/spec/controllers/message_train/concerns_spec.rb +17 -13
- data/spec/controllers/message_train/conversations_controller_spec.rb +44 -12
- data/spec/controllers/message_train/messages_controller_spec.rb +87 -40
- data/spec/controllers/message_train/participants_controller_spec.rb +10 -4
- data/spec/controllers/message_train/unsubscribes_controller_spec.rb +43 -13
- data/spec/dummy/Rakefile +2 -1
- data/spec/dummy/app/assets/stylesheets/application.css.scss +7 -23
- data/spec/dummy/app/controllers/application_controller.rb +7 -7
- data/spec/dummy/app/models/group.rb +1 -1
- data/spec/dummy/app/models/role.rb +11 -7
- data/spec/dummy/app/models/user.rb +6 -5
- data/spec/dummy/app/views/layouts/_top_navigation.html.haml +1 -1
- data/spec/dummy/app/views/layouts/application.html.haml +1 -1
- data/spec/dummy/app/views/pages/index.html.haml +1 -1
- data/spec/dummy/config/application.rb +23 -17
- data/spec/dummy/config/environments/development.rb +5 -4
- data/spec/dummy/config/environments/production.rb +10 -6
- data/spec/dummy/config/environments/test.rb +4 -3
- data/spec/dummy/config/initializers/assets.rb +2 -1
- data/spec/dummy/config/initializers/backtrace_silencers.rb +4 -2
- data/spec/dummy/config/initializers/bootstrap_leather.rb +1 -1
- data/spec/dummy/config/initializers/devise.rb +63 -44
- data/spec/dummy/config/initializers/high_voltage.rb +1 -1
- data/spec/dummy/config/initializers/message_train.rb +5 -2
- data/spec/dummy/config/initializers/mime_types.rb +1 -1
- data/spec/dummy/config/initializers/paperclip.rb +5 -2
- data/spec/dummy/config/initializers/rolify.rb +3 -2
- data/spec/dummy/config/initializers/wrap_parameters.rb +2 -1
- data/spec/dummy/config/routes.rb +1 -3
- data/spec/dummy/config/settings.yml +1 -1
- data/spec/dummy/db/schema.rb +98 -98
- data/spec/dummy/db/seeds/conversations.seeds.rb +160 -160
- data/spec/dummy/db/seeds/development/conversations.seeds.rb +6 -2
- data/spec/dummy/db/seeds/groups.seeds.rb +11 -12
- data/spec/dummy/db/seeds/test/attachments.seeds.rb +13 -3
- data/spec/dummy/db/seeds/test/conversations.seeds.rb +6 -2
- data/spec/dummy/db/seeds/unsubscribes.seeds.rb +1 -1
- data/spec/dummy/db/seeds/users.seeds.rb +47 -42
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/factories/attachment.rb +6 -2
- data/spec/factories/group.rb +1 -4
- data/spec/factories/message.rb +29 -23
- data/spec/factories/user.rb +6 -4
- data/spec/features/boxes_spec.rb +76 -24
- data/spec/features/conversations_spec.rb +19 -7
- data/spec/features/messages_spec.rb +24 -5
- data/spec/features/unsubscribes_spec.rb +36 -9
- data/spec/helpers/message_train/application_helper_spec.rb +1 -1
- data/spec/helpers/message_train/attachment_helper_spec.rb +27 -12
- data/spec/helpers/message_train/boxes_helper_spec.rb +1 -1
- data/spec/helpers/message_train/collectives_helper_spec.rb +25 -9
- data/spec/helpers/message_train/conversations_helper_spec.rb +239 -120
- data/spec/helpers/message_train/messages_helper_spec.rb +137 -81
- data/spec/message_train_spec.rb +3 -2
- data/spec/models/group_spec.rb +12 -9
- data/spec/models/message_train/attachment_spec.rb +33 -30
- data/spec/models/message_train/box_spec.rb +243 -60
- data/spec/models/message_train/conversation_spec.rb +16 -12
- data/spec/models/message_train/ignore_spec.rb +3 -1
- data/spec/models/message_train/message_spec.rb +22 -7
- data/spec/models/message_train/receipt_spec.rb +14 -4
- data/spec/models/role_spec.rb +10 -6
- data/spec/models/user_spec.rb +74 -22
- data/spec/rails_helper.rb +9 -4
- data/spec/spec_helper.rb +6 -54
- data/spec/support/controller_behaviors.rb +8 -5
- data/spec/support/controller_macros.rb +2 -2
- data/spec/support/factory_girl.rb +1 -1
- data/spec/support/feature_behaviors.rb +42 -13
- data/spec/support/loaded_site/attachments.rb +8 -0
- data/spec/support/loaded_site/conversations.rb +73 -0
- data/spec/support/{groups.rb → loaded_site/groups.rb} +1 -1
- data/spec/support/{loaded_site.rb → loaded_site/loaded_site.rb} +1 -1
- data/spec/support/{messages.rb → loaded_site/messages.rb} +13 -5
- data/spec/support/{roles.rb → loaded_site/roles.rb} +1 -1
- data/spec/support/{users.rb → loaded_site/users.rb} +1 -1
- data/spec/support/shared_connection.rb +8 -6
- data/spec/support/utilities.rb +10 -10
- metadata +67 -10
- data/spec/dummy/config/unused/temporary_i18n_debugging.rb +0 -12
- data/spec/support/attachments.rb +0 -4
- 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
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
45
|
-
|
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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
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] =
|
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[
|
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(
|
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
|
-
|
80
|
+
private
|
68
81
|
|
69
|
-
# Never trust parameters from the scary internet, only allow the white list
|
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
|
-
|
11
|
-
|
10
|
+
case Time.now - time
|
11
|
+
when 0..1.minute
|
12
12
|
:just_now.l
|
13
|
-
|
13
|
+
when 1.minute..1.day
|
14
14
|
l(time, format: :fuzzy_today)
|
15
|
-
|
15
|
+
when 1.day..1.week
|
16
16
|
l(time, format: :fuzzy_this_week)
|
17
|
-
|
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(
|
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
|
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
|
-
|
9
|
-
text << badge(unread_count.to_s.gsub(/\s+/,
|
10
|
-
|
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
|
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
|
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
|
23
|
-
render
|
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(
|
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(
|
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
|
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
|
-
|
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
|
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
|
34
|
-
show[table_sym] = collectives.select
|
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
|
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(
|
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(
|
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
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
css_classes << if conversation.includes_unread_for?(@box_user)
|
16
|
+
'unread'
|
17
|
+
else
|
18
|
+
'read'
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
css_classes << 'draft'
|
22
|
-
end
|
21
|
+
conversation.includes_drafts_by?(@box_user) && css_classes << 'draft'
|
23
22
|
|
24
|
-
|
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
|
-
|
26
|
+
!conversation.includes_trashed_for?(@box_user) &&
|
30
27
|
css_classes << 'hide'
|
31
|
-
end
|
32
28
|
else
|
33
|
-
|
29
|
+
!conversation.includes_untrashed_for?(@box_user) &&
|
34
30
|
css_classes << 'hide'
|
35
|
-
end
|
36
31
|
if box.division == :ignored
|
37
|
-
|
38
|
-
css_classes << 'hide'
|
39
|
-
end
|
32
|
+
!conversation.participant_ignored?(@box_user) && css_classes << 'hide'
|
40
33
|
else
|
41
|
-
|
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
|
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
|
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
|
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
|
62
|
+
render(
|
63
|
+
partial: 'message_train/conversations/deleted_toggle',
|
64
|
+
locals: { conversation: conversation, collective: collective }
|
65
|
+
)
|
63
66
|
end
|
64
67
|
|
65
|
-
|
68
|
+
private
|
66
69
|
|
67
|
-
|
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] += "
|
73
|
-
render
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
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
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
css_classes << if message.is_unread_for?(@box_user)
|
8
|
+
'unread panel-info'
|
9
|
+
else
|
10
|
+
'read'
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
css_classes << 'draft'
|
14
|
-
end
|
13
|
+
message.draft && css_classes << 'draft'
|
15
14
|
|
16
15
|
if box.division == :trash
|
17
|
-
|
18
|
-
css_classes << 'hide'
|
19
|
-
end
|
16
|
+
!message.is_trashed_for?(@box_user) && css_classes << 'hide'
|
20
17
|
else
|
21
|
-
|
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
|
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
|
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
|
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
|
-
|
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] =
|
53
|
+
options[:class] = 'mark-link'
|
50
54
|
options[:method] = :put
|
51
55
|
options[:title] = title
|
52
|
-
render
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
4
|
-
|
5
|
-
|
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,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(
|
9
|
+
@heading = :new_message_on_site_name.l(
|
10
|
+
site_name: MessageTrain.configuration.site_name
|
11
|
+
)
|
9
12
|
else
|
10
|
-
@through_name = @through.send(
|
11
|
-
|
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
|