diff --git a/app/assets/stylesheets/notifications.scss.erb b/app/assets/stylesheets/notifications.scss.erb index a866af04..d7942135 100644 --- a/app/assets/stylesheets/notifications.scss.erb +++ b/app/assets/stylesheets/notifications.scss.erb @@ -30,7 +30,7 @@ $unread_notifications_dot_size: 8px; margin-top: 1em + $menu_bar_height; font-family: 'din-regular', Sans-Serif; - & > .title { + & > .notification-title { border-bottom: 1px solid #eee; padding-bottom: 0.25em; margin-bottom: 0.5em; @@ -42,7 +42,7 @@ $unread_notifications_dot_size: 8px; } - .notification { + .notificationsPage .notification { .notification-subject { width: 25%; } @@ -68,4 +68,10 @@ $unread_notifications_dot_size: 8px; } } } + + .notificationPage .notification-body { + p, div { + margin: 1em auto; + } + } } diff --git a/app/controllers/access_controller.rb b/app/controllers/access_controller.rb index 5f19d23e..a287ca1b 100644 --- a/app/controllers/access_controller.rb +++ b/app/controllers/access_controller.rb @@ -22,12 +22,10 @@ class AccessController < ApplicationController request = AccessRequest.create(user: current_user, map: @map) # what about push notification to map owner? mail = MapMailer.access_request_email(request, @map) - @map.user.notify(mail.subject, mail.body.parts[1].body.to_s) + @map.user.notify(mail.subject, 'access request', request, true, MAILBOXER_CODE_ACCESS_REQUEST) respond_to do |format| - format.json do - head :ok - end + format.json { head :ok } end end @@ -38,16 +36,13 @@ class AccessController < ApplicationController @map.add_new_collaborators(user_ids).each do |user_id| # add_new_collaborators returns array of added users, # who we then send an email to - user = User.find(user_id) mail = MapMailer.invite_to_edit_email(@map, current_user, User.find(user_id)) - user.notify(mail.subject, mail.body.parts[1].body.to_s) + user.notify(mail.subject, 'invite to edit', UserMap.find_by(user_id: user_id, map: @map), true, MAILBOXER_CODE_INVITED_TO_EDIT) end @map.remove_old_collaborators(user_ids) respond_to do |format| - format.json do - head :ok - end + format.json { head :ok } end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index cc121cbe..45a5d565 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -38,18 +38,9 @@ module ApplicationHelper "#{request.base_url}/join" + (current_user ? "?code=#{current_user.code}" : '') end - def user_has_unread_notifications? - return @user_has_unread_notifications unless @user_has_unread_notifications.nil? - return (@user_has_unread_notifications = false) if current_user.nil? - current_user.mailboxer_notification_receipts.each do |receipt| - return (@user_has_unread_notifications = true) if receipt.is_read == false - end - @user_has_unread_notifications = false - end - def user_unread_notification_count return 0 if current_user.nil? - current_user.mailboxer_notification_receipts.reduce(0) do |total, receipt| + @user_unread_notification_count ||= current_user.mailboxer_notification_receipts.reduce(0) do |total, receipt| receipt.is_read ? total : total + 1 end end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 10961836..338f38ee 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -6,4 +6,16 @@ class ApplicationMailer < ActionMailer::Base def deliver raise NotImplementedError('Please use Mailboxer to send your emails.') end + + class << self + def mail_for_notification(notification) + if notification.notification_code == MAILBOXER_CODE_ACCESS_REQUEST + request = notification.notified_object + MapMailer.access_request_email(request, request.map) + elsif notification.notification_code == MAILBOXER_CODE_INVITED_TO_EDIT + user_map = notification.notified_object + MapMailer.invite_to_edit_email(user_map.map, user_map.map.user, user_map.user) + end + end + end end diff --git a/app/views/layouts/_mobilemenu.html.erb b/app/views/layouts/_mobilemenu.html.erb index c557f516..5ef3a66d 100644 --- a/app/views/layouts/_mobilemenu.html.erb +++ b/app/views/layouts/_mobilemenu.html.erb @@ -3,7 +3,7 @@ <%= yield(:mobile_title) %>
@@ -55,7 +55,7 @@