diff --git a/app/assets/images/social_link_icons/discord.svg b/app/assets/images/social_link_icons/discord.svg new file mode 100644 index 00000000000..5f5bdd6aa60 --- /dev/null +++ b/app/assets/images/social_link_icons/discord.svg @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/app/assets/images/social_link_icons/facebook.svg b/app/assets/images/social_link_icons/facebook.svg new file mode 100644 index 00000000000..e9e79635442 --- /dev/null +++ b/app/assets/images/social_link_icons/facebook.svg @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/app/assets/images/social_link_icons/github.svg b/app/assets/images/social_link_icons/github.svg new file mode 100644 index 00000000000..51b1a800191 --- /dev/null +++ b/app/assets/images/social_link_icons/github.svg @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/app/assets/images/social_link_icons/gitlab.svg b/app/assets/images/social_link_icons/gitlab.svg new file mode 100644 index 00000000000..760ea7c6caf --- /dev/null +++ b/app/assets/images/social_link_icons/gitlab.svg @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/app/assets/images/social_link_icons/instagram.svg b/app/assets/images/social_link_icons/instagram.svg new file mode 100644 index 00000000000..2724fbd5bd7 --- /dev/null +++ b/app/assets/images/social_link_icons/instagram.svg @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/app/assets/images/social_link_icons/line.svg b/app/assets/images/social_link_icons/line.svg new file mode 100644 index 00000000000..3808c88e23e --- /dev/null +++ b/app/assets/images/social_link_icons/line.svg @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/app/assets/images/social_link_icons/linkedin.svg b/app/assets/images/social_link_icons/linkedin.svg new file mode 100644 index 00000000000..59f2e4533f1 --- /dev/null +++ b/app/assets/images/social_link_icons/linkedin.svg @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/app/assets/images/social_link_icons/mastodon.svg b/app/assets/images/social_link_icons/mastodon.svg new file mode 100644 index 00000000000..44a2730f377 --- /dev/null +++ b/app/assets/images/social_link_icons/mastodon.svg @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/app/assets/images/social_link_icons/medium.svg b/app/assets/images/social_link_icons/medium.svg new file mode 100644 index 00000000000..b0c359ec840 --- /dev/null +++ b/app/assets/images/social_link_icons/medium.svg @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/app/assets/images/social_link_icons/other.svg b/app/assets/images/social_link_icons/other.svg new file mode 100644 index 00000000000..b78b4c73d98 --- /dev/null +++ b/app/assets/images/social_link_icons/other.svg @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/app/assets/images/social_link_icons/quora.svg b/app/assets/images/social_link_icons/quora.svg new file mode 100644 index 00000000000..e18e02e3f0a --- /dev/null +++ b/app/assets/images/social_link_icons/quora.svg @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/app/assets/images/social_link_icons/reddit.svg b/app/assets/images/social_link_icons/reddit.svg new file mode 100644 index 00000000000..dba2cb3f4bf --- /dev/null +++ b/app/assets/images/social_link_icons/reddit.svg @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/app/assets/images/social_link_icons/skype.svg b/app/assets/images/social_link_icons/skype.svg new file mode 100644 index 00000000000..ff4833d9da3 --- /dev/null +++ b/app/assets/images/social_link_icons/skype.svg @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/app/assets/images/social_link_icons/slack.svg b/app/assets/images/social_link_icons/slack.svg new file mode 100644 index 00000000000..46983144717 --- /dev/null +++ b/app/assets/images/social_link_icons/slack.svg @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/app/assets/images/social_link_icons/snapchat.svg b/app/assets/images/social_link_icons/snapchat.svg new file mode 100644 index 00000000000..a19a51993d3 --- /dev/null +++ b/app/assets/images/social_link_icons/snapchat.svg @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/app/assets/images/social_link_icons/stackoverflow.svg b/app/assets/images/social_link_icons/stackoverflow.svg new file mode 100644 index 00000000000..24aaca0ace2 --- /dev/null +++ b/app/assets/images/social_link_icons/stackoverflow.svg @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/app/assets/images/social_link_icons/strava.svg b/app/assets/images/social_link_icons/strava.svg new file mode 100644 index 00000000000..8e8625c1678 --- /dev/null +++ b/app/assets/images/social_link_icons/strava.svg @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/app/assets/images/social_link_icons/substack.svg b/app/assets/images/social_link_icons/substack.svg new file mode 100644 index 00000000000..d0d6d6d3aac --- /dev/null +++ b/app/assets/images/social_link_icons/substack.svg @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/app/assets/images/social_link_icons/telegram.svg b/app/assets/images/social_link_icons/telegram.svg new file mode 100644 index 00000000000..1b77dce2ade --- /dev/null +++ b/app/assets/images/social_link_icons/telegram.svg @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/app/assets/images/social_link_icons/threads.svg b/app/assets/images/social_link_icons/threads.svg new file mode 100644 index 00000000000..99ec9628921 --- /dev/null +++ b/app/assets/images/social_link_icons/threads.svg @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/app/assets/images/social_link_icons/tiktok.svg b/app/assets/images/social_link_icons/tiktok.svg new file mode 100644 index 00000000000..18f99ae1e92 --- /dev/null +++ b/app/assets/images/social_link_icons/tiktok.svg @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/app/assets/images/social_link_icons/twitch.svg b/app/assets/images/social_link_icons/twitch.svg new file mode 100644 index 00000000000..8e3ac6fbf26 --- /dev/null +++ b/app/assets/images/social_link_icons/twitch.svg @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/app/assets/images/social_link_icons/twitter_x.svg b/app/assets/images/social_link_icons/twitter_x.svg new file mode 100644 index 00000000000..d51006674d1 --- /dev/null +++ b/app/assets/images/social_link_icons/twitter_x.svg @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/app/assets/images/social_link_icons/vimeo.svg b/app/assets/images/social_link_icons/vimeo.svg new file mode 100644 index 00000000000..13c9fcf58b4 --- /dev/null +++ b/app/assets/images/social_link_icons/vimeo.svg @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/app/assets/images/social_link_icons/whatsapp.svg b/app/assets/images/social_link_icons/whatsapp.svg new file mode 100644 index 00000000000..e24000ea435 --- /dev/null +++ b/app/assets/images/social_link_icons/whatsapp.svg @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/app/assets/images/social_link_icons/youtube.svg b/app/assets/images/social_link_icons/youtube.svg new file mode 100644 index 00000000000..38b2704b08c --- /dev/null +++ b/app/assets/images/social_link_icons/youtube.svg @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/app/assets/javascripts/user.js b/app/assets/javascripts/user.js index b94db8b557e..7d7f86c335f 100644 --- a/app/assets/javascripts/user.js +++ b/app/assets/javascripts/user.js @@ -225,4 +225,27 @@ $(document).ready(function () { $("#read_tou").on("click", function () { $("#continue").prop("disabled", !($(this).prop("checked") && $("#read_ct").prop("checked"))); }); + + $("#add-social-link").click(function (event) { + event.preventDefault(); + const newIndex = -(new Date().getTime()); + const socialLinkForm = $(` +
+ `); + + socialLinkForm.find("button").click(function () { + $(this).parent().remove(); + }); + + $("#social_links").append(socialLinkForm); + }); + + $(".social_link_destroy input[type='checkbox']").change(function () { + $(this).parent().parent().addClass("d-none"); + }); }); diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb index 4005176ce19..428b1e36f67 100644 --- a/app/controllers/profiles_controller.rb +++ b/app/controllers/profiles_controller.rb @@ -12,6 +12,9 @@ class ProfilesController < ApplicationController def edit; end def update + social_links_params = params.require(:user).permit(:social_links_attributes => [:id, :url, :_destroy]) + current_user.assign_attributes(social_links_params) + if params[:user][:description] != current_user.description current_user.description = params[:user][:description] current_user.description_format = "markdown" diff --git a/app/models/social_link.rb b/app/models/social_link.rb new file mode 100644 index 00000000000..c7692962bef --- /dev/null +++ b/app/models/social_link.rb @@ -0,0 +1,48 @@ +class SocialLink < ApplicationRecord + belongs_to :user + + validates :url, :presence => true, :format => { :with => URI::DEFAULT_PARSER.make_regexp(%w[http https]), :message => I18n.t("profiles.edit.social_links.http_parse_error") } + + URL_PATTERNS = { + :discord => %r{discord\.com/users/(\d+)}, + :facebook => %r{facebook\.com/([a-zA-Z0-9.]+)}, + :github => %r{github\.com/([a-zA-Z0-9_-]+)}, + :gitlab => %r{gitlab\.com/([a-zA-Z0-9_-]+)}, + :instagram => %r{instagram\.com/([a-zA-Z0-9._]+)}, + :linkedin => %r{linkedin\.com/in/([a-zA-Z0-9_-]+)}, + :line => %r{line\.me/ti/p/([a-zA-Z0-9_-]+)}, + :mastodon => %r{mastodon\.social/@([a-zA-Z0-9_]+)}, + :medium => %r{medium\.com/@([a-zA-Z0-9_]+)}, + :quora => %r{quora\.com/profile/([a-zA-Z0-9_-]+)}, + :reddit => %r{reddit\.com/user/([a-zA-Z0-9_-]+)}, + :skype => %r{join\.skype\.com/invite/([a-zA-Z0-9_-]+)}, + :slack => %r{join\.slack\.com/shareDM/([a-zA-Z0-9_~-]+)}, + :snapchat => %r{snapchat\.com/add/([a-zA-Z0-9_-]+)}, + :stackoverflow => %r{stackoverflow\.com/users/(\d+/[a-zA-Z0-9_-]+)}, + :strava => %r{strava\.com/athletes/([a-zA-Z0-9_-]+)}, + :substack => %r{substack\.com/@([a-zA-Z0-9_-]+)}, + :telegram => %r{t\.me/([a-zA-Z0-9_]+)}, + :threads => %r{threads\.net/@([a-zA-Z0-9_]+)}, + :tiktok => %r{tiktok\.com/@([a-zA-Z0-9_]+)}, + :twitch => %r{twitch\.tv/([a-zA-Z0-9_]+)}, + :twitter_x => %r{(?:twitter|x)\.com/([a-zA-Z0-9_]+)}, + :vimeo => %r{vimeo.com/([a-zA-Z0-9_]+)}, + :whatsapp => %r{wa\.me/(\d+)}, + :youtube => %r{youtube\.com/@([a-zA-Z0-9_-]+)} + }.freeze + + NO_USERNAME_PLATFORMS = %w[discord line skype slack].freeze + + def parsed + URL_PATTERNS.each do |platform, pattern| + username = url.match(pattern) + if username + return { + :platform => platform.to_s, + :name => NO_USERNAME_PLATFORMS.include?(platform.to_s) ? platform.to_s.capitalize : username[1] + } + end + end + { :platform => nil, :name => url } + end +end diff --git a/app/models/user.rb b/app/models/user.rb index 917faca2184..01ff711c918 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -87,6 +87,9 @@ class User < ApplicationRecord has_many :reports + has_many :social_links + accepts_nested_attributes_for :social_links, :allow_destroy => true + scope :visible, -> { where(:status => %w[pending active confirmed]) } scope :active, -> { where(:status => %w[active confirmed]) } scope :identifiable, -> { where(:data_public => true) } diff --git a/app/views/profiles/edit.html.erb b/app/views/profiles/edit.html.erb index ac76b4d2d53..a80ab23625e 100644 --- a/app/views/profiles/edit.html.erb +++ b/app/views/profiles/edit.html.erb @@ -40,6 +40,21 @@ + +