Skip to content

Commit

Permalink
Modify the way Friends are added
Browse files Browse the repository at this point in the history
  • Loading branch information
nertc committed Oct 22, 2024
1 parent 8689337 commit 8393857
Show file tree
Hide file tree
Showing 18 changed files with 104 additions and 104 deletions.
2 changes: 1 addition & 1 deletion app/abilities/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def initialize(user)
can [:create, :subscribe, :unsubscribe], DiaryEntry
can :update, DiaryEntry, :user => user
can [:create], DiaryComment
can [:make_friend, :remove_friend], Friendship
can [:follow, :unfollow], Friendship
can [:create, :reply, :show, :inbox, :outbox, :muted, :mark, :unmute, :destroy], Message
can [:close, :reopen], Note
can [:show, :update], :preference
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/diary_entries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def index
end
elsif params[:friends]
if current_user
@title = t ".title_friends"
@title = t ".title_followed"
entries = DiaryEntry.where(:user => current_user.friends)
else
require_user
Expand Down
12 changes: 6 additions & 6 deletions app/controllers/friendships_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ class FriendshipsController < ApplicationController

authorize_resource

before_action :check_database_writable, :only => [:make_friend, :remove_friend]
before_action :lookup_friend, :only => [:make_friend, :remove_friend]
before_action :check_database_writable, :only => [:follow, :unfollow]
before_action :lookup_friend, :only => [:follow, :unfollow]

def make_friend
def follow
if request.post?
friendship = Friendship.new
friendship.befriender = current_user
friendship.befriendee = @friend
if current_user.friends_with?(@friend)
flash[:warning] = t ".already_a_friend", :name => @friend.display_name
flash[:warning] = t ".already_followed", :name => @friend.display_name
elsif current_user.friendships.where(:created_at => Time.now.utc - 1.hour..).count >= current_user.max_friends_per_hour
flash[:error] = t ".limit_exceeded"
elsif friendship.save
Expand All @@ -34,13 +34,13 @@ def make_friend
end
end

def remove_friend
def unfollow
if request.post?
if current_user.friends_with?(@friend)
Friendship.where(:befriender => current_user, :befriendee => @friend).delete_all
flash[:notice] = t ".success", :name => @friend.display_name
else
flash[:error] = t ".not_a_friend", :name => @friend.display_name
flash[:error] = t ".not_followed", :name => @friend.display_name
end

referer = safe_referer(params[:referer]) if params[:referer]
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/changesets_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def changeset_details(changeset)

def changeset_index_title(params, user)
if params[:friends] && user
t "changesets.index.title_friend"
t "changesets.index.title_followed"
elsif params[:nearby] && user
t "changesets.index.title_nearby"
elsif params[:display_name]
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def friendship_notification(friendship)
with_recipient_locale friendship.befriendee do
@friendship = friendship
@viewurl = user_url(@friendship.befriender)
@friendurl = make_friend_url(@friendship.befriender)
@followurl = follow_url(@friendship.befriender)
@author = @friendship.befriender.display_name

attach_user_avatar(@friendship.befriender)
Expand Down
6 changes: 3 additions & 3 deletions app/views/dashboards/_contact.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<% user_data = {
:lon => contact.home_lon,
:lat => contact.home_lat,
:icon => image_path(type == "friend" ? "marker-blue.png" : "marker-green.png"),
:icon => image_path(type == "following" ? "marker-blue.png" : "marker-green.png"),
:description => render(:partial => "popup", :object => contact, :locals => { :type => type })
} %>
<%= tag.div :class => "clearfix row", :data => { :user => user_data } do %>
Expand Down Expand Up @@ -36,9 +36,9 @@
<li><%= link_to t("users.show.send message"), new_message_path(contact) %></li>
<li>
<% if current_user.friends_with?(contact) %>
<%= link_to t("users.show.remove as friend"), remove_friend_path(:display_name => contact.display_name, :referer => request.fullpath), :method => :post %>
<%= link_to t("users.show.unfollow"), unfollow_path(:display_name => contact.display_name, :referer => request.fullpath), :method => :post %>
<% else %>
<%= link_to t("users.show.add as friend"), make_friend_path(:display_name => contact.display_name, :referer => request.fullpath), :method => :post %>
<%= link_to t("users.follow"), follow_path(:display_name => contact.display_name, :referer => request.fullpath), :method => :post %>
<% end %>
</li>
</ul>
Expand Down
10 changes: 5 additions & 5 deletions app/views/dashboards/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@
</div>

<div class="col-md">
<h2><%= t ".my friends" %></h2>
<h2><%= t ".followings" %></h2>

<% if friends.empty? %>
<%= t ".no friends" %>
<%= t ".no followings" %>
<% else %>
<nav class='secondary-actions mb-3'>
<ul class='clearfix'>
<li><%= link_to t(".friends_changesets"), friend_changesets_path %></li>
<li><%= link_to t(".friends_diaries"), friends_diary_entries_path %></li>
<li><%= link_to t(".followed_changesets"), friend_changesets_path %></li>
<li><%= link_to t(".followed_diaries"), friends_diary_entries_path %></li>
</ul>
</nav>
<div>
<%= render :partial => "contact", :collection => friends, :locals => { :type => "friend" } %>
<%= render :partial => "contact", :collection => friends, :locals => { :type => "following" } %>
</div>
<% end %>

Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions app/views/user_mailer/friendship_notification.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<p><%= t ".hi", :to_user => @friendship.befriendee.display_name %></p>

<p><%= t ".had_added_you", :user => @friendship.befriender.display_name %></p>
<p><%= t ".followed_you", :user => @friendship.befriender.display_name %></p>

<%= message_body do %>
<p><%= t ".see_their_profile_html", :userurl => link_to(@viewurl, @viewurl) %></p>

<% unless @friendship.befriendee.friends_with?(@friendship.befriender) -%>
<p><%= t ".befriend_them_html", :befriendurl => link_to(@friendurl, @friendurl) %></p>
<p><%= t ".follow_them_html", :followurl => link_to(@followurl, @followurl) %></p>
<% end -%>
<% end %>
4 changes: 2 additions & 2 deletions app/views/user_mailer/friendship_notification.text.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<%= t ".hi", :to_user => @friendship.befriendee.display_name %>

<%= t '.had_added_you', :user => @friendship.befriender.display_name %>
<%= t '.followed_you', :user => @friendship.befriender.display_name %>

<%= t '.see_their_profile', :userurl => @viewurl %>

<% unless @friendship.befriendee.friends_with?(@friendship.befriender) -%>
<%= t '.befriend_them', :befriendurl => @friendurl %>
<%= t '.follow_them', :followurl => @followurl %>
<% end -%>
4 changes: 2 additions & 2 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@
<% if current_user %>
<li>
<% if current_user.friends_with?(@user) %>
<%= link_to t(".remove as friend"), remove_friend_path(:display_name => @user.display_name), :method => :post %>
<%= link_to t(".unfollow"), unfollow_path(:display_name => @user.display_name), :method => :post %>
<% else %>
<%= link_to t(".add as friend"), make_friend_path(:display_name => @user.display_name), :method => :post %>
<%= link_to t(".follow"), follow_path(:display_name => @user.display_name), :method => :post %>
<% end %>
</li>
<% end %>
Expand Down
54 changes: 27 additions & 27 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ en:
support_url: Support URL
allow_read_prefs: read their user preferences
allow_write_prefs: modify their user preferences
allow_write_diary: create diary entries, comments and make friends
allow_write_diary: create diary entries and comments
allow_write_api: modify the map
allow_read_gpx: read their private GPS traces
allow_write_gpx: upload GPS traces
Expand Down Expand Up @@ -445,7 +445,7 @@ en:
title: "Changesets"
title_user: "Changesets by %{user}"
title_user_link_html: "Changesets by %{user_link}"
title_friend: "Changesets by my friends"
title_followed: "Changesets by followings"
title_nearby: "Changesets by nearby users"
empty: "No changesets found."
empty_area: "No changesets in this area."
Expand Down Expand Up @@ -509,17 +509,17 @@ en:
popup:
your location: "Your location"
nearby mapper: "Nearby mapper"
friend: "Friend"
following: "Following"
show:
title: My Dashboard
no_home_location_html: "%{edit_profile_link} and set your home location to see nearby users."
edit_your_profile: Edit your profile
my friends: My friends
no friends: You have not added any friends yet.
followings: Followings
no followings: You have not followed any user yet.
nearby users: "Other nearby users"
no nearby users: "There are no other users who admit to mapping nearby yet."
friends_changesets: "friends' changesets"
friends_diaries: "friends' diary entries"
followed_changesets: "changesets"
followed_diaries: "diary entries"
nearby_changesets: "nearby user changesets"
nearby_diaries: "nearby user diary entries"
diary_entries:
Expand All @@ -530,7 +530,7 @@ en:
use_map_link: Use Map
index:
title: "Users' Diaries"
title_friends: "Friends' Diaries"
title_followed: "Followings' Diaries"
title_nearby: "Nearby Users' Diaries"
user_title: "%{user}'s Diary"
in_language_title: "Diary Entries in %{language}"
Expand Down Expand Up @@ -652,18 +652,18 @@ en:
title: File not found
description: Couldn't find a file/directory/API operation by that name on the OpenStreetMap server (HTTP 404)
friendships:
make_friend:
heading: "Add %{user} as a friend?"
button: "Add as friend"
success: "%{name} is now your friend!"
failed: "Sorry, failed to add %{name} as a friend."
already_a_friend: "You are already friends with %{name}."
limit_exceeded: "You have friended a lot of users recently. Please wait a while before trying to friend any more."
remove_friend:
heading: "Unfriend %{user}?"
button: "Unfriend"
success: "%{name} was removed from your friends."
not_a_friend: "%{name} is not one of your friends."
follow:
heading: "Do you want to follow %{user}?"
button: "Follow User"
success: "You are now following %{name}!"
failed: "Sorry, your request to follow %{name} has failed."
already_followed: "You already follow %{name}."
limit_exceeded: "You have followed a lot of users recently. Please wait a while before trying to follow any more."
unfollow:
heading: "Do you want to unfollow %{user}?"
button: "Unfollow"
success: "You successfully unfollowed %{name}."
not_followed: "You are not following %{name}."
geocoder:
search:
title:
Expand Down Expand Up @@ -1603,12 +1603,12 @@ en:
footer_html: "You can also read the message at %{readurl} and you can send a message to the author at %{replyurl}"
friendship_notification:
hi: "Hi %{to_user},"
subject: "[OpenStreetMap] %{user} added you as a friend"
had_added_you: "%{user} has added you as a friend on OpenStreetMap."
subject: "[OpenStreetMap] %{user} followed you"
followed_you: "%{user} is now following you on OpenStreetMap."
see_their_profile: "You can see their profile at %{userurl}."
see_their_profile_html: "You can see their profile at %{userurl}."
befriend_them: "You can also add them as a friend at %{befriendurl}."
befriend_them_html: "You can also add them as a friend at %{befriendurl}."
follow_them: "You can also follow them at %{followurl}."
follow_them_html: "You can also follow them at %{followurl}."
gpx_description:
description_with_tags: "It looks like your file %{trace_name} with the description %{trace_description} and the following tags: %{tags}"
description_with_tags_html: "It looks like your file %{trace_name} with the description %{trace_description} and the following tags: %{tags}"
Expand Down Expand Up @@ -2601,7 +2601,7 @@ en:
openid: Sign-in using OpenStreetMap
read_prefs: Read user preferences
write_prefs: Modify user preferences
write_diary: Create diary entries, comments and make friends
write_diary: Create diary entries and comments
write_api: Modify the map
read_gpx: Read private GPS traces
write_gpx: Upload GPS traces
Expand Down Expand Up @@ -2749,8 +2749,8 @@ en:
edits: Edits
traces: Traces
notes: Map Notes
remove as friend: Unfriend
add as friend: Add Friend
unfollow: Unfollow
follow: Follow
mapper since: "Mapper since:"
last map edit: "Last map edit:"
no activity yet: "No activity yet"
Expand Down
4 changes: 2 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@
resource :profile, :only => [:edit, :update]

# friendships
match "/user/:display_name/make_friend" => "friendships#make_friend", :via => [:get, :post], :as => "make_friend"
match "/user/:display_name/remove_friend" => "friendships#remove_friend", :via => [:get, :post], :as => "remove_friend"
match "/user/:display_name/follow" => "friendships#follow", :via => [:get, :post], :as => "follow"
match "/user/:display_name/unfollow" => "friendships#unfollow", :via => [:get, :post], :as => "unfollow"

# user lists
match "/users" => "users#index", :via => [:get, :post]
Expand Down
Loading

0 comments on commit 8393857

Please sign in to comment.