diff --git a/app/controllers/async_info_controller.rb b/app/controllers/async_info_controller.rb index f6ff9c9d0..566dbec57 100644 --- a/app/controllers/async_info_controller.rb +++ b/app/controllers/async_info_controller.rb @@ -56,7 +56,7 @@ class AsyncInfoController < ApplicationController id: @user.id, name: @user.name, username: @user.username, - profile_image_90: Images::Profile.call(@user.profile_image_url, length: 90), + profile_image_90: ProfileImage.new(@user).get(width: 90), followed_tags: @user.cached_followed_tags.to_json(only: %i[id name bg_color_hex text_color_hex hotness_score], methods: [:points]), followed_podcast_ids: @user.cached_following_podcasts_ids, diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index 80466bd7e..7cf5a8893 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -378,7 +378,7 @@ class StoriesController < ApplicationController }, "url": URL.user(@user), "sameAs": user_same_as, - "image": Images::Profile.call(@user.profile_image_url, length: 320), + "image": ProfileImage.new(@user).get(width: 320), "name": @user.name, "email": @user.email_public ? @user.email : nil, "jobTitle": @user.employment_title.presence, @@ -444,7 +444,7 @@ class StoriesController < ApplicationController "@id": URL.organization(@organization) }, "url": URL.organization(@organization), - "image": Images::Profile.call(@organization.profile_image_url, length: 320), + "image": ProfileImage.new(@organization).get(width: 320), "name": @organization.name, "description": @organization.summary.presence || "404 bio not found" } diff --git a/app/helpers/chat_channel_membership_helper.rb b/app/helpers/chat_channel_membership_helper.rb index b922d8421..dc1ffb8b1 100644 --- a/app/helpers/chat_channel_membership_helper.rb +++ b/app/helpers/chat_channel_membership_helper.rb @@ -8,7 +8,7 @@ module ChatChannelMembershipHelper membership_id: membership.id, role: membership.role, status: membership.status, - image: Images::Profile.call(membership.user.profile_image_url, length: 90) + image: ProfileImage.new(membership.user).get(width: 90) } end end @@ -21,7 +21,7 @@ module ChatChannelMembershipHelper membership_id: membership.id, role: membership.role, status: membership.status, - image: Images::Profile.call(membership.user.profile_image_url, length: 90) + image: ProfileImage.new(membership.user).get(width: 90) } end end diff --git a/app/helpers/chat_channel_memberships_helper.rb b/app/helpers/chat_channel_memberships_helper.rb index 70e31f4ad..710511bf0 100644 --- a/app/helpers/chat_channel_memberships_helper.rb +++ b/app/helpers/chat_channel_memberships_helper.rb @@ -8,7 +8,7 @@ module ChatChannelMembershipsHelper membership_id: membership.id, role: membership.role, status: membership.status, - image: Images::Profile.call(membership.user.profile_image_url, length: 90), + image: ProfileImage.new(membership.user).get(width: 90), chat_channel_name: membership.chat_channel.channel_name, chat_channel_id: membership.chat_channel.id, slug: membership.chat_channel.slug diff --git a/app/helpers/messages_helper.rb b/app/helpers/messages_helper.rb index 46098d6b5..2af27b524 100644 --- a/app/helpers/messages_helper.rb +++ b/app/helpers/messages_helper.rb @@ -8,7 +8,7 @@ module MessagesHelper chat_channel_adjusted_slug: new_message.chat_channel.adjusted_slug(current_user, "sender"), channel_type: new_message.chat_channel.channel_type, username: new_message.user.username, - profile_image_url: Images::Profile.call(new_message.user.profile_image_url, length: 90), + profile_image_url: ProfileImage.new(new_message.user).get(width: 90), message: new_message.message_html, markdown: new_message.message_markdown, edited_at: new_message.edited_at, diff --git a/app/labor/profile_image.rb b/app/labor/profile_image.rb new file mode 100644 index 000000000..e3ed25b70 --- /dev/null +++ b/app/labor/profile_image.rb @@ -0,0 +1,13 @@ +class ProfileImage + BACKUP_LINK = "https://thepracticaldev.s3.amazonaws.com/i/99mvlsfu5tfj9m7ku25d.png".freeze + + attr_accessor :image_link + + def initialize(resource) + @image_link = resource.profile_image_url + end + + def get(width: 120) + Images::Optimizer.call(image_link || BACKUP_LINK, width: width, height: width, crop: "fill") + end +end diff --git a/app/models/chat_channel.rb b/app/models/chat_channel.rb index eab7ef3bb..dea2750ca 100644 --- a/app/models/chat_channel.rb +++ b/app/models/chat_channel.rb @@ -169,7 +169,7 @@ class ChatChannel < ApplicationRecord def user_obj(membership) { - profile_image: Images::Profile.call(membership.user.profile_image_url, length: 90), + profile_image: ProfileImage.new(membership.user).get(width: 90), darker_color: membership.user.decorate.darker_color, name: membership.user.name, last_opened_at: membership.last_opened_at, diff --git a/app/models/chat_channel_membership.rb b/app/models/chat_channel_membership.rb index 83d8220bf..4febd4607 100644 --- a/app/models/chat_channel_membership.rb +++ b/app/models/chat_channel_membership.rb @@ -50,7 +50,7 @@ class ChatChannelMembership < ApplicationRecord def channel_image if chat_channel.channel_type == "direct" - Images::Profile.call(other_user.profile_image_url, length: 90) + ProfileImage.new(other_user).get(width: 90) else ActionController::Base.helpers.asset_path("organization.svg") end diff --git a/app/models/message.rb b/app/models/message.rb index 6989c9e1c..4ffb0f882 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -109,7 +109,7 @@ class Message < ApplicationRecord target='_blank' rel='noopener' data-content='sidecar-article'> #{"
" if article.main_image.present?}
@<%= org.slug %>
+What next?
-
Purchase Credits for @<%= org.slug %>
+
Purchase Credits for @<%= org.slug %>
<% if org.credits.unspent.size > 0 %>
@<%= org.slug %>
+
@<%= org.slug %>
<% if org.enough_credits?(Sponsorship::CREDITS[level]) %>diff --git a/app/views/social_previews/articles/article.html.erb b/app/views/social_previews/articles/article.html.erb index 3ff8fbcdb..fa60c6025 100644 --- a/app/views/social_previews/articles/article.html.erb +++ b/app/views/social_previews/articles/article.html.erb @@ -127,7 +127,7 @@
<%= @article.title %>
<%= @article.title %>
<%= @comment.title %>
-
+
<%= truncate @user.name, length: 32 %>
-
" />
+
" />
<% else %>
-
" />
+
" />
<% end %>
diff --git a/app/views/users/_organizations_area.html.erb b/app/views/users/_organizations_area.html.erb
index 3d36b81e9..a9b575897 100644
--- a/app/views/users/_organizations_area.html.erb
+++ b/app/views/users/_organizations_area.html.erb
@@ -8,7 +8,7 @@
<% @user.organizations.each do |organization| %>
-
+
<% end %>
diff --git a/app/views/users/_profile.html.erb b/app/views/users/_profile.html.erb
index e9d0d554a..8b5d21c55 100644
--- a/app/views/users/_profile.html.erb
+++ b/app/views/users/_profile.html.erb
@@ -42,7 +42,7 @@
<% if @user.profile_image_url.present? %>
-
+
<%= f.file_field :profile_image, accept: "image/*", class: "crayons-card crayons-card--secondary p-3 flex items-center flex-1 w-100" %>
<% end %>
diff --git a/app/views/users/_profile_header.html.erb b/app/views/users/_profile_header.html.erb
index ed9aee8f3..4493539f9 100644
--- a/app/views/users/_profile_header.html.erb
+++ b/app/views/users/_profile_header.html.erb
@@ -20,7 +20,7 @@
-
+
@<%= @user.username %> diff --git a/app/views/users/_liquid.html.erb b/app/views/users/_liquid.html.erb index 182464717..a15580ca7 100644 --- a/app/views/users/_liquid.html.erb +++ b/app/views/users/_liquid.html.erb @@ -9,12 +9,12 @@ <% if user_path.present? %>
diff --git a/app/views/users/index.json.jbuilder b/app/views/users/index.json.jbuilder index 67db4f3c0..f5339f0c5 100644 --- a/app/views/users/index.json.jbuilder +++ b/app/views/users/index.json.jbuilder @@ -2,6 +2,6 @@ json.array! @users.each do |user| json.extract!(user, :id, :name, :username) json.summary truncate(user.summary.presence || "Active #{community_name} author", length: 100) - json.profile_image_url Images::Profile.call(user.profile_image_url, length: 90) + json.profile_image_url ProfileImage.new(user).get(width: 90) json.following false end diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index c7d5d8f31..a939c7d83 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -29,7 +29,7 @@
-
+
diff --git a/spec/services/images/profile_spec.rb b/spec/labor/profile_image_spec.rb similarity index 60% rename from spec/services/images/profile_spec.rb rename to spec/labor/profile_image_spec.rb index cd68dbf9e..13735983b 100644 --- a/spec/services/images/profile_spec.rb +++ b/spec/labor/profile_image_spec.rb @@ -1,17 +1,17 @@ require "rails_helper" -RSpec.describe Images::Profile, type: :services do +RSpec.describe ProfileImage, type: :labor do describe "#get" do it "returns user profile_image_url" do user = build_stubbed(:user) - expect(described_class.call(user.profile_image_url)).to eq(user.profile_image_url) + expect(described_class.new(user).get).to eq(user.profile_image_url) end context "when user has no profile_image" do it "returns backup image prefixed with Cloudinary" do user = build_stubbed(:user, profile_image: nil) correct_prefix = "/c_fill,f_auto,fl_progressive,h_120,q_auto,w_120/" - expect(described_class.call(user.profile_image_url)).to include(correct_prefix + described_class::BACKUP_LINK) + expect(described_class.new(user).get).to include(correct_prefix + described_class::BACKUP_LINK) end end end diff --git a/spec/liquid_tags/link_tag_spec.rb b/spec/liquid_tags/link_tag_spec.rb index 2f4e1aaa1..a18aa7ade 100644 --- a/spec/liquid_tags/link_tag_spec.rb +++ b/spec/liquid_tags/link_tag_spec.rb @@ -35,7 +35,7 @@ RSpec.describe LinkTag, type: :liquid_tag do
-
+
diff --git a/spec/requests/api/v0/followers_spec.rb b/spec/requests/api/v0/followers_spec.rb
index 8c9285ee9..befcf59c6 100644
--- a/spec/requests/api/v0/followers_spec.rb
+++ b/spec/requests/api/v0/followers_spec.rb
@@ -42,7 +42,7 @@ RSpec.describe "Api::V0::FollowersController", type: :request do
expect(response_follower["name"]).to eq(follower.name)
expect(response_follower["path"]).to eq(follower.path)
expect(response_follower["username"]).to eq(follower.username)
- expect(response_follower["profile_image"]).to eq(Images::Profile.call(follower.profile_image_url, length: 60))
+ expect(response_follower["profile_image"]).to eq(ProfileImage.new(follower).get(width: 60))
end
it "supports pagination" do
diff --git a/spec/requests/api/v0/users_spec.rb b/spec/requests/api/v0/users_spec.rb
index 4b0a51a88..6d081bb8d 100644
--- a/spec/requests/api/v0/users_spec.rb
+++ b/spec/requests/api/v0/users_spec.rb
@@ -46,7 +46,7 @@ RSpec.describe "Api::V0::Users", type: :request do
end
expect(response_user["joined_at"]).to eq(user.created_at.strftime("%b %e, %Y"))
- expect(response_user["profile_image"]).to eq(Images::Profile.call(user.profile_image_url, length: 320))
+ expect(response_user["profile_image"]).to eq(ProfileImage.new(user).get(width: 320))
end
end
@@ -74,7 +74,7 @@ RSpec.describe "Api::V0::Users", type: :request do
end
expect(response_user["joined_at"]).to eq(user.created_at.strftime("%b %e, %Y"))
- expect(response_user["profile_image"]).to eq(Images::Profile.call(user.profile_image_url, length: 320))
+ expect(response_user["profile_image"]).to eq(ProfileImage.new(user).get(width: 320))
end
it "returns 200 if no authentication and site config is set to private but user is authenticated" do
@@ -92,7 +92,7 @@ RSpec.describe "Api::V0::Users", type: :request do
end
expect(response_user["joined_at"]).to eq(user.created_at.strftime("%b %e, %Y"))
- expect(response_user["profile_image"]).to eq(Images::Profile.call(user.profile_image_url, length: 320))
+ expect(response_user["profile_image"]).to eq(ProfileImage.new(user).get(width: 320))
end
end
end
diff --git a/spec/requests/api/v0/webhooks_spec.rb b/spec/requests/api/v0/webhooks_spec.rb
index 0572b0895..fa0b74ad6 100644
--- a/spec/requests/api/v0/webhooks_spec.rb
+++ b/spec/requests/api/v0/webhooks_spec.rb
@@ -121,18 +121,15 @@ RSpec.describe "Api::V0::Webhooks", type: :request do
get api_webhook_path(webhook.id)
response_webhook_user = response.parsed_body["user"]
+ user_profile_image = ProfileImage.new(webhook.user)
- expect(response_webhook_user).to eq({
- "name" => webhook.user.name,
- "username" => webhook.user.username,
- "twitter_username" => webhook.user.twitter_username,
- "github_username" => webhook.user.github_username,
- "website_url" => webhook.user.processed_website_url,
- "profile_image" => Images::Profile.call(webhook.user.profile_image_url,
- length: 640),
- "profile_image_90" => Images::Profile.call(webhook.user.profile_image_url,
- length: 90)
- })
+ expect(response_webhook_user["name"]).to eq(webhook.user.name)
+ expect(response_webhook_user["username"]).to eq(webhook.user.username)
+ expect(response_webhook_user["twitter_username"]).to eq(webhook.user.twitter_username)
+ expect(response_webhook_user["github_username"]).to eq(webhook.user.github_username)
+ expect(response_webhook_user["website_url"]).to eq(webhook.user.processed_website_url)
+ expect(response_webhook_user["profile_image"]).to eq(user_profile_image.get(width: 640))
+ expect(response_webhook_user["profile_image_90"]).to eq(user_profile_image.get(width: 90))
end
end
diff --git a/spec/requests/articles/articles_show_spec.rb b/spec/requests/articles/articles_show_spec.rb
index 17846350b..62945ca1e 100644
--- a/spec/requests/articles/articles_show_spec.rb
+++ b/spec/requests/articles/articles_show_spec.rb
@@ -70,7 +70,7 @@ RSpec.describe "ArticlesShow", type: :request do
"@id" => URL.organization(organization)
},
"url" => URL.organization(organization),
- "image" => Images::Profile.call(organization.profile_image_url, length: 320),
+ "image" => ProfileImage.new(organization).get(width: 320),
"name" => organization.name,
"description" => organization.summary
},
diff --git a/spec/requests/chat_channels_spec.rb b/spec/requests/chat_channels_spec.rb
index 389224548..08420c5c2 100644
--- a/spec/requests/chat_channels_spec.rb
+++ b/spec/requests/chat_channels_spec.rb
@@ -406,7 +406,7 @@ RSpec.describe "ChatChannels", type: :request do
expected_last_opened_at = Time.zone.parse(response_channel_users[user.username]["last_opened_at"]).to_i
response_user = response_channel_users[user.username]
- expect(response_user["profile_image"]).to eq(Images::Profile.call(user.profile_image_url, length: 90))
+ expect(response_user["profile_image"]).to eq(ProfileImage.new(user).get(width: 90))
expect(response_user["darker_color"]).to eq(user.decorate.darker_color)
expect(response_user["name"]).to eq(user.name)
expect(expected_last_opened_at).to eq(user.chat_channel_memberships.last.last_opened_at.to_i)
diff --git a/spec/requests/followings_spec.rb b/spec/requests/followings_spec.rb
index 27f92ca82..74baddba1 100644
--- a/spec/requests/followings_spec.rb
+++ b/spec/requests/followings_spec.rb
@@ -35,7 +35,7 @@ RSpec.describe "FollowingsController", type: :request do
expect(response_following["name"]).to eq(followed.name)
expect(response_following["path"]).to eq(followed.path)
expect(response_following["username"]).to eq(followed.username)
- expect(response_following["profile_image"]).to eq(Images::Profile.call(followed.profile_image_url, length: 60))
+ expect(response_following["profile_image"]).to eq(ProfileImage.new(followed).get(width: 60))
end
end
end
@@ -111,7 +111,7 @@ RSpec.describe "FollowingsController", type: :request do
expect(response_following["name"]).to eq(followed.name)
expect(response_following["path"]).to eq(followed.path)
expect(response_following["username"]).to eq(followed.username)
- expect(response_following["profile_image"]).to eq(Images::Profile.call(followed.profile_image_url, length: 60))
+ expect(response_following["profile_image"]).to eq(ProfileImage.new(followed).get(width: 60))
end
end
end
@@ -148,7 +148,7 @@ RSpec.describe "FollowingsController", type: :request do
expect(response_following["name"]).to eq(followed.name)
expect(response_following["path"]).to eq("/#{followed.path}")
expect(response_following["username"]).to eq(followed.name)
- expect(response_following["profile_image"]).to eq(Images::Profile.call(followed.profile_image_url, length: 60))
+ expect(response_following["profile_image"]).to eq(ProfileImage.new(followed).get(width: 60))
end
end
end
diff --git a/spec/requests/user/user_show_spec.rb b/spec/requests/user/user_show_spec.rb
index 24ea7806c..9ae8be9cc 100644
--- a/spec/requests/user/user_show_spec.rb
+++ b/spec/requests/user/user_show_spec.rb
@@ -38,7 +38,7 @@ RSpec.describe "UserShow", type: :request do
user.twitch_username,
user.website_url,
],
- "image" => Images::Profile.call(user.profile_image_url, length: 320),
+ "image" => ProfileImage.new(user).get(width: 320),
"name" => user.name,
"email" => user.email,
"jobTitle" => user.employment_title,
diff --git a/spec/requests/user/user_suggestions_spec.rb b/spec/requests/user/user_suggestions_spec.rb
index 4b5e01970..d3af33183 100644
--- a/spec/requests/user/user_suggestions_spec.rb
+++ b/spec/requests/user/user_suggestions_spec.rb
@@ -32,7 +32,7 @@ RSpec.describe "Users", type: :request do
"name" => suggested_user.name,
"username" => suggested_user.username,
"summary" => suggested_user.summary,
- "profile_image_url" => Images::Profile.call(suggested_user.profile_image_url, length: 90),
+ "profile_image_url" => ProfileImage.new(suggested_user).get(width: 90),
"following" => false,
)
end