display an encouragement to contribute after many anonymous notes

create a counter of anonymous notes in a cookie, read by new note controller to display an encouragement to contribute in the already existing anonymous warning if the anonymous visitor has already created at least 10 anonymous notes. Cookie deleted on log-in and sign-up after email validation
This commit is contained in:
Etilène Jourdier 2025-01-12 22:42:57 +01:00 committed by Anton Khorev
parent 5d76ec051e
commit 0f2df0b9ef
6 changed files with 30 additions and 4 deletions

View file

@ -162,6 +162,10 @@ OSM.NewNote = function (map) {
newNoteMarker.dragging.disable(); newNoteMarker.dragging.disable();
createNote(location, text, (feature) => { createNote(location, text, (feature) => {
if (typeof OSM.user === "undefined") {
var anonymousNotesCount = Number(Cookies.get("_osm_anonymous_notes_count")) || 0;
Cookies.set("_osm_anonymous_notes_count", anonymousNotesCount + 1, { secure: true, expires: 30, path: "/", samesite: "lax" });
}
content.find("textarea").val(""); content.find("textarea").val("");
addCreatedNoteMarker(feature); addCreatedNoteMarker(feature);
OSM.router.route("/note/" + feature.properties.id); OSM.router.route("/note/" + feature.properties.id);

View file

@ -39,6 +39,8 @@ module SessionMethods
session[:fingerprint] = user.fingerprint session[:fingerprint] = user.fingerprint
session_expires_after 28.days if session[:remember_me] session_expires_after 28.days if session[:remember_me]
cookies.delete :_osm_anonymous_notes_count
target = referer || url_for(:controller => :site, :action => :index) target = referer || url_for(:controller => :site, :action => :index)
# The user is logged in, so decide where to send them: # The user is logged in, so decide where to send them:

View file

@ -30,6 +30,7 @@ class ConfirmationsController < ApplicationController
user.email_valid = true user.email_valid = true
flash[:notice] = gravatar_status_message(user) if gravatar_enable(user) flash[:notice] = gravatar_status_message(user) if gravatar_enable(user)
user.save! user.save!
cookies.delete :_osm_anonymous_notes_count
referer = safe_referer(params[:referer]) if params[:referer] referer = safe_referer(params[:referer]) if params[:referer]
pending_user = session.delete(:pending_user) pending_user = session.delete(:pending_user)

View file

@ -45,6 +45,7 @@ class NotesController < ApplicationController
end end
def new def new
@anonymous_notes_count = request.cookies["_osm_anonymous_notes_count"].to_i || 0
render :action => :new_readonly if api_status != "online" render :action => :new_readonly if api_status != "online"
end end
end end

View file

@ -5,9 +5,17 @@
<div class="note"> <div class="note">
<p class="alert alert-info"><%= t(".intro") %></p> <p class="alert alert-info"><%= t(".intro") %></p>
<% if !current_user %> <% if !current_user %>
<p class="alert alert-warning"><%= t ".anonymous_warning_html", <div class="alert alert-warning pb-0">
:log_in => link_to(t(".anonymous_warning_log_in"), login_path(:referer => new_note_path)), <p><%= t ".anonymous_warning_html",
:sign_up => link_to(t(".anonymous_warning_sign_up"), new_user_path) %></p> :log_in => link_to(t(".anonymous_warning_log_in"), login_path(:referer => new_note_path)),
:sign_up => link_to(t(".anonymous_warning_sign_up"), new_user_path) %></p>
<% if @anonymous_notes_count >= 10 %>
<p><%= t ".counter_warning_html",
:x_anonymous_notes => t(".x_anonymous_notes", :count => @anonymous_notes_count),
:contribute_by_yourself => link_to(t(".counter_warning_guide_link.text"), t(".counter_warning_guide_link.url")),
:community_can_help => link_to(t(".counter_warning_forum_link.text"), t(".counter_warning_forum_link.url")) %></p>
<% end %>
</div>
<% end %> <% end %>
<p class="alert alert-warning" id="new-note-zoom-warning" hidden><%= t "javascripts.site.createnote_disabled_tooltip" %></p> <p class="alert alert-warning" id="new-note-zoom-warning" hidden><%= t "javascripts.site.createnote_disabled_tooltip" %></p>
<form action="#"> <form action="#">

View file

@ -3087,9 +3087,19 @@ en:
new: new:
title: "New Note" title: "New Note"
intro: "Spotted a mistake or something missing? Let other mappers know so we can fix it. Move the marker to the correct position and type a note to explain the problem." intro: "Spotted a mistake or something missing? Let other mappers know so we can fix it. Move the marker to the correct position and type a note to explain the problem."
anonymous_warning_html: "You are not logged in. Please %{log_in} or %{sign_up} if you want to receive updates for your note." anonymous_warning_html: "You are not logged in. Please %{log_in} or %{sign_up} to receive updates for your note and help mappers resolve it."
anonymous_warning_log_in: "log in" anonymous_warning_log_in: "log in"
anonymous_warning_sign_up: "sign up" anonymous_warning_sign_up: "sign up"
counter_warning_html: "You have already posted at least %{x_anonymous_notes}, that's great for the community, thank you! Now we encourage you to %{contribute_by_yourself}, it is not that complicated, and %{community_can_help}."
x_anonymous_notes:
one: "%{count} anonymous note"
other: "%{count} anonymous notes"
counter_warning_guide_link:
text: "contribute by yourself"
url: https://wiki.openstreetmap.org/wiki/Beginners%27_guide
counter_warning_forum_link:
text: "the community can help you"
url: https://community.openstreetmap.org/
advice: "Your note is public and may be used to update the map, so don't enter personal information, or information from copyrighted maps or directory listings." advice: "Your note is public and may be used to update the map, so don't enter personal information, or information from copyrighted maps or directory listings."
add: Add Note add: Add Note
new_readonly: new_readonly: