-
Notifications
You must be signed in to change notification settings - Fork 1.1k
On-site notifications #7030
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
pablobm
wants to merge
8
commits into
openstreetmap:master
Choose a base branch
from
pablobm:onsite-notifications
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
On-site notifications #7030
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
770e901
Create page to list notifications
pablobm e0c05a0
List changeset comment notifications
pablobm 8767e70
Show a message when there are no notifications
pablobm 92b7055
Show clear, separate link to the event
pablobm f1eaf43
More realistic content for changeset comment notification
pablobm 18da87b
Design more closely aligned with the email notifications
pablobm 99e7f5a
Implement "new follower" notification
pablobm 72131ba
Added notifications for GPX import results
pablobm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class NotificationsController < ApplicationController | ||
| layout :site_layout | ||
|
|
||
| before_action :authorize_web | ||
| before_action :set_locale | ||
|
|
||
| authorize_resource :class => false | ||
|
|
||
| before_action :check_database_readable | ||
|
|
||
| def index | ||
| @notifications = UserNotifications.new(current_user).visible | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class UserNotifications | ||
| class Notification | ||
| def self.from(notification) | ||
| partial_classname = notification.class.name.sub("Notifier::Notification", "") | ||
| klass = "UserNotifications::#{partial_classname}Notification".constantize | ||
| klass.new(notification) | ||
| end | ||
|
|
||
| def initialize(notification) | ||
| @notification = notification | ||
| end | ||
|
|
||
| def visible? | ||
| true | ||
| end | ||
|
|
||
| def to_partial_path | ||
| partial_basename = @notification.class.name.sub("Notifier::Notification", "").underscore | ||
| "notifications/#{partial_basename}" | ||
| end | ||
|
|
||
| def timestamp | ||
| record.created_at | ||
| end | ||
|
|
||
| def record | ||
| @notification.record | ||
| end | ||
| end | ||
|
|
||
| class ChangesetCommentNotification < Notification | ||
| delegate :changeset, :to => :record | ||
| delegate :visible?, :to => :record | ||
|
|
||
| def commenter | ||
| record.author | ||
| end | ||
|
|
||
| def comment_id | ||
| record.id | ||
| end | ||
|
|
||
| def comment_body | ||
| record.body | ||
| end | ||
| end | ||
|
|
||
| class GpxImportFailureNotification < Notification | ||
| def trace_filename | ||
| @notification.params[:trace_name] | ||
| end | ||
|
|
||
| def trace_description | ||
| @notification.params[:trace_description] | ||
| end | ||
|
|
||
| def trace_tags | ||
| @notification.params[:trace_tags] | ||
| end | ||
|
|
||
| def trace_possible_points | ||
| nil | ||
| end | ||
|
|
||
| def trace_points | ||
| nil | ||
| end | ||
| end | ||
|
|
||
| class GpxImportSuccessNotification < Notification | ||
| def trace_filename | ||
| record.file.name | ||
| end | ||
|
|
||
| def trace_description | ||
| record.description | ||
| end | ||
|
|
||
| def trace_tags | ||
| record.tags.map(&:tag) | ||
| end | ||
|
|
||
| def trace_possible_points | ||
| @notification.params[:possible_points] | ||
| end | ||
|
|
||
| def trace_points | ||
| record.size | ||
| end | ||
|
|
||
| def user | ||
| record.user | ||
| end | ||
| end | ||
|
|
||
| class NewFollowerNotification < Notification | ||
| delegate :follower, :to => :record | ||
| end | ||
|
|
||
| include Enumerable | ||
|
|
||
| LISTABLE_NOTIFICATIONS = %w[ | ||
| ChangesetCommentNotifier::Notification | ||
| GpxImportFailureNotifier::Notification | ||
| GpxImportSuccessNotifier::Notification | ||
| NewFollowerNotifier::Notification | ||
| ].freeze | ||
|
|
||
| def initialize(user) | ||
| @user = user | ||
| end | ||
|
|
||
| def visible | ||
| select(&:visible?) | ||
| end | ||
|
|
||
| def each(&) | ||
| @user | ||
| .notifications | ||
| .where(:type => LISTABLE_NOTIFICATIONS) | ||
| .newest_first | ||
| .map { |instance| Notification.from(instance) } | ||
| .each(&) | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| <%# locals: (notification:) %> | ||
|
|
||
| <article class="row"> | ||
| <div class="col-9"> | ||
| <p class="text-body-secondary mb-1"> | ||
| <%= link_to( | ||
| notification.commenter.display_name, | ||
| notification.commenter | ||
| ) %> | ||
| left a comment | ||
| <%= friendly_date_ago(notification.timestamp) %> | ||
| on a changeset you are watching, created by | ||
| <%= link_to( | ||
| notification.changeset.user.display_name, | ||
| notification.changeset.user | ||
| ) %> | ||
| with comment | ||
| <q><%= notification.changeset.comment %></q> | ||
| </p> | ||
| <div class="row"> | ||
| <div class="col-2 text-center"> | ||
| <%= link_to( | ||
| user_image(notification.commenter, :width => 50, :height => 50, :class => "img-fluid"), | ||
| user_url(notification.commenter), | ||
| :target => "_blank", :rel => "noopener" | ||
| ) %> | ||
| </div> | ||
| <blockquote class="col-10 fst-italic"> | ||
| <%= notification.comment_body.to_html %> | ||
| </blockquote> | ||
| </div> | ||
| </div> | ||
|
|
||
| <p class="col-3 text-center"> | ||
| <%= | ||
| link_to( | ||
| t(".view_changeset_comment"), | ||
| changeset_path( | ||
| notification.changeset, | ||
| :anchor => "c#{notification.comment_id}" | ||
| ) | ||
| ) | ||
| %> | ||
| </p> | ||
| </article> | ||
|
|
||
| <hr> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| <%# locals: (notification:) %> | ||
|
|
||
| <article class="row"> | ||
| <div class="col-9"> | ||
| <p class="text-body-secondary mb-1"> | ||
| It looks like your file failed to be imported as a GPS trace. | ||
| </p> | ||
| <div class="row"> | ||
| <div class="col-2 text-center"> | ||
| <%# This space intentionally left blank, as there is no other user %> | ||
| </div> | ||
| <div class="col-10"> | ||
| <dl> | ||
| <dt>Filename</dt> | ||
| <dd><%= notification.trace_filename %></dd> | ||
|
|
||
| <dt>Description</dt> | ||
| <dd><%= notification.trace_description %></dd> | ||
|
|
||
| <% if notification.trace_tags.length.positive? %> | ||
| <dt>Tags</dt> | ||
| <dd><%= notification.trace_tags.join(", ") %></dd> | ||
| <% end %> | ||
|
|
||
| <% if notification.trace_possible_points %> | ||
| <dt>Possible points</dt> | ||
| <dd><%= notification.trace_possible_points %></dd> | ||
| <% end %> | ||
|
|
||
| <% if notification.trace_points %> | ||
| <dt>Imported points</dt> | ||
| <dd><%= notification.trace_points %></dd> | ||
| <% end %> | ||
| </dl> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <p class="col-3 text-center"> | ||
| <%# This space intentionally left blank, as there is no obvious action %> | ||
| </p> | ||
| </article> | ||
|
|
||
| <hr> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| <%# locals: (notification:) %> | ||
|
|
||
| <article class="row"> | ||
| <div class="col-9"> | ||
| <p class="text-body-secondary mb-1"> | ||
| It looks like your file was imported successfully as a GPS trace. | ||
| </p> | ||
| <div class="row"> | ||
| <div class="col-2 text-center"> | ||
| <%# This space intentionally left blank, as there is no other user %> | ||
| </div> | ||
| <div class="col-10"> | ||
| <dl> | ||
| <dt>Filename</dt> | ||
| <dd><%= notification.trace_filename %></dd> | ||
|
|
||
| <dt>Description</dt> | ||
| <dd><%= notification.trace_description %></dd> | ||
|
|
||
| <% if notification.trace_tags.length.positive? %> | ||
| <dt>Tags</dt> | ||
| <dd><%= notification.trace_tags.join(", ") %></dd> | ||
| <% end %> | ||
|
|
||
| <% if notification.trace_possible_points %> | ||
| <dt>Possible points</dt> | ||
| <dd><%= notification.trace_possible_points %></dd> | ||
| <% end %> | ||
|
|
||
| <% if notification.trace_points %> | ||
| <dt>Imported points</dt> | ||
| <dd><%= notification.trace_points %></dd> | ||
| <% end %> | ||
| </dl> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <p class="col-3 text-center"> | ||
| <%= link_to "View", show_trace_path(notification.user, notification.record) %> | ||
| </p> | ||
| </article> | ||
|
|
||
| <hr> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <%# locals: (notification:) %> | ||
|
|
||
| <article class="row"> | ||
| <div class="col-9"> | ||
| <p class="text-body-secondary mb-1"> | ||
| <%= link_to( | ||
| notification.follower.display_name, | ||
| notification.follower | ||
| ) %> | ||
| started following you | ||
| <%= friendly_date_ago(notification.timestamp) %> | ||
| </p> | ||
| <div class="row"> | ||
| <div class="col-2 text-center"> | ||
| <%= link_to( | ||
| user_image(notification.follower, :width => 50, :height => 50, :class => "img-fluid"), | ||
| user_url(notification.follower), | ||
| :target => "_blank", :rel => "noopener" | ||
| ) %> | ||
| </div> | ||
| <div class="col-10"> | ||
| <p>You can <%= link_to "follow them back", follow_url(notification.follower) %> if you wish.</p> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <p class="col-3 text-center"> | ||
| <%# This space intentionally left blank, as there is no obvious action %> | ||
| </p> | ||
| </article> | ||
|
|
||
| <hr> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <% content_for :heading do %> | ||
| <h1><%= t ".title" %></h1> | ||
| <% end %> | ||
|
|
||
| <% if @notifications.empty? %> | ||
| <p>You have no notifications at the moment.</p> | ||
| <% end %> | ||
| <div class="container"> | ||
| <% @notifications.each do |notification| %> | ||
| <%= render :partial => notification.to_partial_path, :object => notification, :as => :notification %> | ||
| <% end %> | ||
| </div> | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be a good opportunity to link to the notification preferences in #7001, depending on which PR lands first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Yes, I think users are now used to "click here to change your notification preferences" at places like this.