|
1 | 1 | class NotificationMailer < ApplicationMailer
|
2 | 2 | default from: ENV["DEFAULT_FROM_ADDRESS"]
|
3 | 3 |
|
| 4 | + ALLY_NOTIFY_TYPES = ["new_ally_request", "accepted_ally_request"] |
| 5 | + |
4 | 6 | def take_medication(reminder)
|
5 | 7 | @medication = reminder.medication
|
6 | 8 | @user = @medication.user
|
7 |
| - mail( |
8 |
| - to: @user.email, |
9 |
| - subject: "Don't forget to take #{@medication.name}!" |
10 |
| - ) |
| 9 | + mail(to: @user.email, |
| 10 | + subject: "Don't forget to take #{@medication.name}!") |
11 | 11 | end
|
12 | 12 |
|
13 | 13 | def refill_medication(reminder)
|
14 | 14 | @medication = reminder.medication
|
15 | 15 | @user = @medication.user
|
16 |
| - mail( |
17 |
| - to: @user.email, |
18 |
| - subject: "Your refill for #{@medication.name} is coming up soon!" |
19 |
| - ) |
| 16 | + mail(to: @user.email, |
| 17 | + subject: "Your refill for #{@medication.name} is coming up soon!") |
20 | 18 | end
|
21 | 19 |
|
22 |
| - |
23 | 20 | def notification_email(recipientid, data)
|
24 |
| - @data = JSON.parse(data) |
25 |
| - @recipient = User.where(id: recipientid).first |
26 |
| - subject = 'if me | ' |
27 |
| - |
28 |
| - if (can_notify(@recipient, 'comment_notify') && |
29 |
| - (@data['type'] == 'comment_on_moment' || |
30 |
| - @data['type'] == 'comment_on_moment_private' || |
31 |
| - @data['type'] == 'comment_on_strategy' || |
32 |
| - @data['type'] == 'comment_on_strategy_private' || |
33 |
| - @data['type'] == 'comment_on_meeting')) |
34 |
| - |
35 |
| - if (@data['type'] == 'comment_on_moment' || @data['type'] == 'comment_on_moment_private') |
36 |
| - subject += @data['user'].to_s + ' commented on your moment "' + @data['moment'].to_s + '"' |
37 |
| - elsif @data['type'] == 'comment_on_strategy' || @data['type'] == 'comment_on_strategy_private' |
38 |
| - subject += @data['user'].to_s + ' commented on your strategy "' + @data['strategy'].to_s + '"' |
39 |
| - else |
40 |
| - groupid = Meeting.where(id: @data['meetingid']).first.groupid |
41 |
| - group = Group.where(id: groupid).first.name |
42 |
| - subject += @data['user'].to_s + ' commented on the meeting "' + @data['meeting'].to_s + '" in the group "' + group.to_s + '"' |
43 |
| - end |
44 |
| - |
45 |
| - if @data['type'] == 'comment_on_moment_private' || @data['type'] == 'comment_on_strategy_private' |
46 |
| - @message = '<p>Your ally <strong>' + @data['user'].to_s + '</strong> commented privately:</p>'; |
47 |
| - else |
48 |
| - @message = '<p>Your ally <strong>' + @data['user'].to_s + '</strong> commented:</p>'; |
49 |
| - end |
50 |
| - |
51 |
| - if @data['cutoff'] |
52 |
| - @message += '<p><i>' + @data['comment'].to_s + ' [...]</i></p>' |
53 |
| - else |
54 |
| - @message += '<p><i>' + @data['comment'].to_s + '</i></p>' |
55 |
| - end |
56 |
| - |
57 |
| - if (@data['type'] == 'comment_on_moment' || @data['type'] == 'comment_on_moment_private') |
58 |
| - link = link_to("here", moment_url(@data['momentid'])) |
59 |
| - @message += '<p>You can read it all ' + link + '!</p>' |
60 |
| - elsif @data['type'] == 'comment_on_strategy' || @data['type'] == 'comment_on_strategy_private' |
61 |
| - link = link_to("here", strategy_url(@data['strategyid'])) |
62 |
| - @message += '<p>You can read it all ' + link + '!</p>' |
63 |
| - else |
64 |
| - link = link_to("here", meeting_url(@data['meetingid'])) |
65 |
| - @message += '<p>You can read it all ' + link + '!</p>' |
66 |
| - end |
67 |
| - |
68 |
| - mail(to: @recipient.email, subject: subject) |
69 |
| - elsif (can_notify(@recipient, 'ally_notify') && |
70 |
| - (@data['type'] == 'accepted_ally_request' || |
71 |
| - @data['type'] == 'new_ally_request')) |
72 |
| - |
73 |
| - if @data['type'] == 'accepted_ally_request' |
74 |
| - subject += @data['user'].to_s + ' accepted your ally request!' |
75 |
| - @message = '<p>Congrats! You can now share Moments, Strategies, and more with ' + @data['user'].to_s + '.</p>' |
76 |
| - else |
77 |
| - subject += @data['user'].to_s + ' sent an ally request!' |
78 |
| - link = link_to("sign in", allies_url) |
79 |
| - @message = '<p>Please ' + link + ' to accept or reject the request!</p>' |
80 |
| - end |
81 |
| - |
82 |
| - mail(to: @recipient.email, subject: subject) |
83 |
| - elsif ((can_notify(@recipient, 'group_notify') && |
84 |
| - (@data['type'] == 'new_group' || |
85 |
| - @data['type'] == 'new_group_member' || |
86 |
| - @data['type'] == 'add_group_leader' || |
87 |
| - @data['type'] == 'remove_group_leader')) || |
88 |
| - (can_notify(@recipient, 'meeting_notify') && |
89 |
| - (@data['type'] == 'new_meeting' || |
90 |
| - @data['type'] == 'remove_meeting' || |
91 |
| - @data['type'] == 'update_meeting' || |
92 |
| - @data['type'] == 'join_meeting'))) |
93 |
| - |
94 |
| - if @data['type'] == 'new_group' |
95 |
| - what = @data['user'].to_s + ' created a group "' + @data['group'].to_s + '"' |
96 |
| - subject += what |
97 |
| - group_description = Group.where(id: @data['groupid']).first.description |
98 |
| - link = link_to("click here", group_url(@data['groupid'])) |
99 |
| - @message = '<p>' + what + ':</p>' |
100 |
| - @message += '<p><i>' + group_description.to_s + '</i></p>' |
101 |
| - @message += '<p>To learn more and join, ' + link + '!</p>' |
102 |
| - |
103 |
| - elsif @data['type'] == 'new_group_member' |
104 |
| - subject += @data['user'].to_s + ' joined your group "' + @data['group'].to_s + '"' |
105 |
| - link = link_to("click here", group_url(@data['groupid'])) |
106 |
| - @message = '<p>To see ' + @data['group'].to_s + ', ' + link + '!</p>' |
107 |
| - |
108 |
| - elsif @data['type'] == 'add_group_leader' |
109 |
| - if @recipient.name == @data['user'] |
110 |
| - subject += 'You became a leader of "' + @data['group'].to_s + '"' |
111 |
| - else |
112 |
| - subject += @data['user'].to_s + ' became a leader of "' + @data['group'].to_s + '"' |
113 |
| - end |
114 |
| - link = link_to("click here", group_url(@data['groupid'])) |
115 |
| - @message = '<p>To see ' + @data['group'].to_s + ', ' + link + '! </p>' |
116 |
| - |
117 |
| - elsif @data['type'] == 'remove_group_leader' |
118 |
| - if @recipient.name == @data['user'] |
119 |
| - subject += 'You are no longer a leader of "' + @data['group'].to_s + '"' |
120 |
| - else |
121 |
| - subject += @data['user'].to_s + ' is no longer a leader of "' + @data['group'].to_s + '"' |
122 |
| - end |
123 |
| - link = link_to("click here", group_url(@data['groupid'])) |
124 |
| - @message = '<p>To see ' + @data['group'].to_s + ', ' + link + '!</p>' |
125 |
| - |
126 |
| - elsif @data['type'] == 'new_meeting' || @data['type'] == 'update_meeting' |
127 |
| - if @data['type'] == 'update_meeting' |
128 |
| - what = @data['user'].to_s + ' has updated the meeting "' + @data['meeting'].to_s + '" for "' + @data['group'].to_s + '"' |
129 |
| - else |
130 |
| - what = @data['user'].to_s + ' created a new meeting "' + @data['meeting'].to_s + '" for "' + @data['group'].to_s + '"' |
131 |
| - end |
132 |
| - subject += what |
133 |
| - |
134 |
| - meeting_description = Meeting.where(id: @data['meetingid']).first.description |
135 |
| - meeting_location = Meeting.where(id: @data['meetingid']).first.location |
136 |
| - meeting_date = Meeting.where(id: @data['meetingid']).first.date |
137 |
| - meeting_time = Meeting.where(id: @data['meetingid']).first.time |
138 |
| - link = link_to("click here", meeting_url(@data['meetingid'])) |
139 |
| - @message = '<p>' + what + ':</p>' |
140 |
| - @message += '<p><i>' + meeting_description.to_s + '</i></p>' |
141 |
| - @message += '<p><strong>Location:</strong> ' + meeting_location.to_s + '</p>' |
142 |
| - @message += '<p><strong>Date:</strong> ' + meeting_date.to_s + '</p>' |
143 |
| - @message += '<p><strong>Time:</strong> ' + meeting_time.to_s + '</p>' |
144 |
| - |
145 |
| - if @data['type'] == 'new_meeting' |
146 |
| - @message += '<p>To learn more and attend, ' + link + '!</p>' |
147 |
| - else |
148 |
| - @message += '<p>To learn more, ' + link + '!</p>' |
149 |
| - end |
150 |
| - |
151 |
| - elsif @data['type'] == 'remove_meeting' |
152 |
| - subject += @data['user'].to_s + ' has cancelled "' + @data['meeting'].to_s + '" for "' + @data['group'].to_s + '"' |
153 |
| - link = link_to("click here", group_url(@data['groupid'])) |
154 |
| - @message = '<p>To see ' + @data['group'].to_s + ', ' + link + '!</p>' |
155 |
| - |
156 |
| - elsif @data['type'] == 'join_meeting' |
157 |
| - subject += @data['user'].to_s + ' has joined "' + @data['meeting'].to_s + '" for "' + @data['group'].to_s + '"' |
158 |
| - link = link_to("click here", meeting_url(@data['meetingid'])) |
159 |
| - @message = '<p>To see ' + @data['meeting'].to_s + ', ' + link + '!</p>' |
160 |
| - |
161 |
| - end |
162 |
| - |
163 |
| - mail(to: @recipient.email, subject: subject) |
164 |
| - end |
165 |
| - end |
| 21 | + @data = JSON.parse(data) |
| 22 | + @recipient = User.where(id: recipientid).first |
| 23 | + subject = 'if me | ' |
| 24 | + |
| 25 | + if (can_notify(@recipient, 'comment_notify') && |
| 26 | + (@data['type'] == 'comment_on_moment' || |
| 27 | + @data['type'] == 'comment_on_moment_private' || |
| 28 | + @data['type'] == 'comment_on_strategy' || |
| 29 | + @data['type'] == 'comment_on_strategy_private' || |
| 30 | + @data['type'] == 'comment_on_meeting')) |
| 31 | + |
| 32 | + if (@data['type'] == 'comment_on_moment' || @data['type'] == 'comment_on_moment_private') |
| 33 | + subject += @data['user'].to_s + ' commented on your moment "' + @data['moment'].to_s + '"' |
| 34 | + elsif @data['type'] == 'comment_on_strategy' || @data['type'] == 'comment_on_strategy_private' |
| 35 | + subject += @data['user'].to_s + ' commented on your strategy "' + @data['strategy'].to_s + '"' |
| 36 | + else |
| 37 | + groupid = Meeting.where(id: @data['meetingid']).first.groupid |
| 38 | + group = Group.where(id: groupid).first.name |
| 39 | + subject += @data['user'].to_s + ' commented on the meeting "' + @data['meeting'].to_s + '" in the group "' + group.to_s + '"' |
| 40 | + end |
| 41 | + |
| 42 | + if @data['type'] == 'comment_on_moment_private' || @data['type'] == 'comment_on_strategy_private' |
| 43 | + @message = '<p>Your ally <strong>' + @data['user'].to_s + '</strong> commented privately:</p>'; |
| 44 | + else |
| 45 | + @message = '<p>Your ally <strong>' + @data['user'].to_s + '</strong> commented:</p>'; |
| 46 | + end |
| 47 | + |
| 48 | + if @data['cutoff'] |
| 49 | + @message += '<p><i>' + @data['comment'].to_s + ' [...]</i></p>' |
| 50 | + else |
| 51 | + @message += '<p><i>' + @data['comment'].to_s + '</i></p>' |
| 52 | + end |
| 53 | + |
| 54 | + if (@data['type'] == 'comment_on_moment' || @data['type'] == 'comment_on_moment_private') |
| 55 | + link = link_to("here", moment_url(@data['momentid'])) |
| 56 | + @message += '<p>You can read it all ' + link + '!</p>' |
| 57 | + elsif @data['type'] == 'comment_on_strategy' || @data['type'] == 'comment_on_strategy_private' |
| 58 | + link = link_to("here", strategy_url(@data['strategyid'])) |
| 59 | + @message += '<p>You can read it all ' + link + '!</p>' |
| 60 | + else |
| 61 | + link = link_to("here", meeting_url(@data['meetingid'])) |
| 62 | + @message += '<p>You can read it all ' + link + '!</p>' |
| 63 | + end |
| 64 | + |
| 65 | + mail(to: @recipient.email, subject: subject) |
| 66 | + elsif (can_notify(@recipient, 'ally_notify') && ALLY_NOTIFY_TYPES.include?(@data['type'])) |
| 67 | + |
| 68 | + if @data['type'] == 'accepted_ally_request' |
| 69 | + subject += @data['user'].to_s + ' accepted your ally request!' |
| 70 | + @message = '<p>Congrats! You can now share Moments, Strategies, and more with ' + @data['user'].to_s + '.</p>' |
| 71 | + else |
| 72 | + subject += @data['user'].to_s + ' sent an ally request!' |
| 73 | + link = link_to("sign in", allies_url) |
| 74 | + @message = '<p>Please ' + link + ' to accept or reject the request!</p>' |
| 75 | + end |
| 76 | + |
| 77 | + mail(to: @recipient.email, subject: subject) |
| 78 | + elsif ((can_notify(@recipient, 'group_notify') && |
| 79 | + (@data['type'] == 'new_group' || |
| 80 | + @data['type'] == 'new_group_member' || |
| 81 | + @data['type'] == 'add_group_leader' || |
| 82 | + @data['type'] == 'remove_group_leader')) || |
| 83 | + (can_notify(@recipient, 'meeting_notify') && |
| 84 | + (@data['type'] == 'new_meeting' || |
| 85 | + @data['type'] == 'remove_meeting' || |
| 86 | + @data['type'] == 'update_meeting' || |
| 87 | + @data['type'] == 'join_meeting'))) |
| 88 | + |
| 89 | + if @data['type'] == 'new_group' |
| 90 | + what = @data['user'].to_s + ' created a group "' + @data['group'].to_s + '"' |
| 91 | + subject += what |
| 92 | + group_description = Group.where(id: @data['groupid']).first.description |
| 93 | + link = link_to("click here", group_url(@data['groupid'])) |
| 94 | + @message = '<p>' + what + ':</p>' |
| 95 | + @message += '<p><i>' + group_description.to_s + '</i></p>' |
| 96 | + @message += '<p>To learn more and join, ' + link + '!</p>' |
| 97 | + |
| 98 | + elsif @data['type'] == 'new_group_member' |
| 99 | + subject += @data['user'].to_s + ' joined your group "' + @data['group'].to_s + '"' |
| 100 | + link = link_to("click here", group_url(@data['groupid'])) |
| 101 | + @message = '<p>To see ' + @data['group'].to_s + ', ' + link + '!</p>' |
| 102 | + |
| 103 | + elsif @data['type'] == 'add_group_leader' |
| 104 | + if @recipient.name == @data['user'] |
| 105 | + subject += 'You became a leader of "' + @data['group'].to_s + '"' |
| 106 | + else |
| 107 | + subject += @data['user'].to_s + ' became a leader of "' + @data['group'].to_s + '"' |
| 108 | + end |
| 109 | + link = link_to("click here", group_url(@data['groupid'])) |
| 110 | + @message = '<p>To see ' + @data['group'].to_s + ', ' + link + '! </p>' |
| 111 | + |
| 112 | + elsif @data['type'] == 'remove_group_leader' |
| 113 | + if @recipient.name == @data['user'] |
| 114 | + subject += 'You are no longer a leader of "' + @data['group'].to_s + '"' |
| 115 | + else |
| 116 | + subject += @data['user'].to_s + ' is no longer a leader of "' + @data['group'].to_s + '"' |
| 117 | + end |
| 118 | + link = link_to("click here", group_url(@data['groupid'])) |
| 119 | + @message = '<p>To see ' + @data['group'].to_s + ', ' + link + '!</p>' |
| 120 | + |
| 121 | + elsif @data['type'] == 'new_meeting' || @data['type'] == 'update_meeting' |
| 122 | + if @data['type'] == 'update_meeting' |
| 123 | + what = @data['user'].to_s + ' has updated the meeting "' + @data['meeting'].to_s + '" for "' + @data['group'].to_s + '"' |
| 124 | + else |
| 125 | + what = @data['user'].to_s + ' created a new meeting "' + @data['meeting'].to_s + '" for "' + @data['group'].to_s + '"' |
| 126 | + end |
| 127 | + subject += what |
| 128 | + |
| 129 | + meeting_description = Meeting.where(id: @data['meetingid']).first.description |
| 130 | + meeting_location = Meeting.where(id: @data['meetingid']).first.location |
| 131 | + meeting_date = Meeting.where(id: @data['meetingid']).first.date |
| 132 | + meeting_time = Meeting.where(id: @data['meetingid']).first.time |
| 133 | + link = link_to("click here", meeting_url(@data['meetingid'])) |
| 134 | + @message = '<p>' + what + ':</p>' |
| 135 | + @message += '<p><i>' + meeting_description.to_s + '</i></p>' |
| 136 | + @message += '<p><strong>Location:</strong> ' + meeting_location.to_s + '</p>' |
| 137 | + @message += '<p><strong>Date:</strong> ' + meeting_date.to_s + '</p>' |
| 138 | + @message += '<p><strong>Time:</strong> ' + meeting_time.to_s + '</p>' |
| 139 | + |
| 140 | + if @data['type'] == 'new_meeting' |
| 141 | + @message += '<p>To learn more and attend, ' + link + '!</p>' |
| 142 | + else |
| 143 | + @message += '<p>To learn more, ' + link + '!</p>' |
| 144 | + end |
| 145 | + |
| 146 | + elsif @data['type'] == 'remove_meeting' |
| 147 | + subject += @data['user'].to_s + ' has cancelled "' + @data['meeting'].to_s + '" for "' + @data['group'].to_s + '"' |
| 148 | + link = link_to("click here", group_url(@data['groupid'])) |
| 149 | + @message = '<p>To see ' + @data['group'].to_s + ', ' + link + '!</p>' |
| 150 | + |
| 151 | + elsif @data['type'] == 'join_meeting' |
| 152 | + subject += @data['user'].to_s + ' has joined "' + @data['meeting'].to_s + '" for "' + @data['group'].to_s + '"' |
| 153 | + link = link_to("click here", meeting_url(@data['meetingid'])) |
| 154 | + @message = '<p>To see ' + @data['meeting'].to_s + ', ' + link + '!</p>' |
| 155 | + |
| 156 | + end |
| 157 | + |
| 158 | + mail(to: @recipient.email, subject: subject) |
| 159 | + end |
| 160 | + end |
166 | 161 | end
|
0 commit comments