diff --git a/Changelog.md b/Changelog.md
index a354b4669..997795094 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -37,10 +37,13 @@ Although the chat was never enabled per default and was marked as experimental,
# 0.7.16.0
## Refactor
+* Cache local posts/comments count for statistics [#8241](https://github.com/diaspora/diaspora/pull/8241)
+* Fix html-syntax in some handlebars templates [#8251](https://github.com/diaspora/diaspora/pull/8251)
## Bug fixes
## Features
+* Add tags to tumblr posts [#8244](https://github.com/diaspora/diaspora/pull/8244)
# 0.7.15.0
diff --git a/app/assets/templates/aspect_membership_dropdown_tpl.jst.hbs b/app/assets/templates/aspect_membership_dropdown_tpl.jst.hbs
index 03e24c939..f4a96f1c2 100644
--- a/app/assets/templates/aspect_membership_dropdown_tpl.jst.hbs
+++ b/app/assets/templates/aspect_membership_dropdown_tpl.jst.hbs
@@ -10,7 +10,7 @@
{{ t "aspect_dropdown.toggle" count=aspectMembershipsLength }}
{{/if}}
-
+
{{#if dropdownMayCreateNewAspect}}
-
+
{{/if}}
diff --git a/app/assets/templates/comment-stream_tpl.jst.hbs b/app/assets/templates/comment-stream_tpl.jst.hbs
index 9e0da98b7..6ed798237 100644
--- a/app/assets/templates/comment-stream_tpl.jst.hbs
+++ b/app/assets/templates/comment-stream_tpl.jst.hbs
@@ -29,7 +29,7 @@
class="new-comment" id="new-comment-on-{{id}}" method="post">
+ id="comment_text_on_{{id}}" name="text" rows="1" required placeholder="{{t "stream.comment"}}">
diff --git a/app/assets/templates/comment_tpl.jst.hbs b/app/assets/templates/comment_tpl.jst.hbs
index 81c2d5064..36d56ef1c 100644
--- a/app/assets/templates/comment_tpl.jst.hbs
+++ b/app/assets/templates/comment_tpl.jst.hbs
@@ -11,7 +11,7 @@
{{#if canRemove}}
+
{{else}}
diff --git a/app/assets/templates/photo_tpl.jst.hbs b/app/assets/templates/photo_tpl.jst.hbs
index 388ddaf0b..9c5e4a4d2 100644
--- a/app/assets/templates/photo_tpl.jst.hbs
+++ b/app/assets/templates/photo_tpl.jst.hbs
@@ -27,10 +27,10 @@
diff --git a/app/assets/templates/pod_table_entry_tpl.jst.hbs b/app/assets/templates/pod_table_entry_tpl.jst.hbs
index e43ee6c6f..46f0a9909 100644
--- a/app/assets/templates/pod_table_entry_tpl.jst.hbs
+++ b/app/assets/templates/pod_table_entry_tpl.jst.hbs
@@ -9,7 +9,7 @@
{{host}}
-
+
{{#if has_no_errors}}
@@ -18,10 +18,10 @@
{{status_text}}
{{/if}}
{{#unless is_unchecked}}
- {{t 'admin.pods.last_check'}}
+ {{t 'admin.pods.last_check'}}
{{/unless}}
{{#if offline}}
- | {{t 'admin.pods.offline_since'}}
+ | {{t 'admin.pods.offline_since'}}
{{/if}}
{{#if is_unchecked}}{{t 'admin.pods.no_info'}} {{/if}}
diff --git a/app/assets/templates/reshare_tpl.jst.hbs b/app/assets/templates/reshare_tpl.jst.hbs
index 048b789f1..c8aa22095 100644
--- a/app/assets/templates/reshare_tpl.jst.hbs
+++ b/app/assets/templates/reshare_tpl.jst.hbs
@@ -15,7 +15,7 @@
-
-
+
diff --git a/app/assets/templates/single-post-viewer/single-post-content_tpl.jst.hbs b/app/assets/templates/single-post-viewer/single-post-content_tpl.jst.hbs
index dd96957c5..94995cb12 100644
--- a/app/assets/templates/single-post-viewer/single-post-content_tpl.jst.hbs
+++ b/app/assets/templates/single-post-viewer/single-post-content_tpl.jst.hbs
@@ -40,11 +40,11 @@
{{#if root}}
-
+
{{else}}
-
+
{{/if}}
@@ -59,12 +59,12 @@
{{/if}}
{{#unless root}}
-
+
{{/unless}}
{{#unless root}}
-
+
{{/unless}}
{{#if location.lat}}
@@ -92,13 +92,13 @@
-
+
{{/if}}
diff --git a/app/assets/templates/stream-element_tpl.jst.hbs b/app/assets/templates/stream-element_tpl.jst.hbs
index 9240a3bfd..cb860b63a 100644
--- a/app/assets/templates/stream-element_tpl.jst.hbs
+++ b/app/assets/templates/stream-element_tpl.jst.hbs
@@ -22,7 +22,7 @@
-
-
+
diff --git a/app/models/services/tumblr.rb b/app/models/services/tumblr.rb
index 59f93ef79..f1c77e3f8 100644
--- a/app/models/services/tumblr.rb
+++ b/app/models/services/tumblr.rb
@@ -1,69 +1,78 @@
# frozen_string_literal: true
-class Services::Tumblr < Service
- MAX_CHARACTERS = 1000
+module Services
+ class Tumblr < Service
+ MAX_CHARACTERS = 1000
- def provider
- "tumblr"
- end
-
- def consumer_key
- AppConfig.services.tumblr.key
- end
-
- def consumer_secret
- AppConfig.services.tumblr.secret
- end
-
- def post(post, url='')
- body = build_tumblr_post(post, url)
- user_info = JSON.parse(client.get("/v2/user/info").body)
- blogs = user_info["response"]["user"]["blogs"]
- primaryblog = blogs.find {|blog| blog["primary"] } || blogs[0]
- tumblr_ids = {}
-
- blogurl = URI.parse(primaryblog["url"])
- resp = client.post("/v2/blog/#{blogurl.host}/post", body)
- if resp.code == "201"
- tumblr_ids[blogurl.host.to_s] = JSON.parse(resp.body)["response"]["id"]
+ def provider
+ "tumblr"
end
- post.tumblr_ids = tumblr_ids.to_json
- post.save
- end
+ def post(post, url="") # rubocop:disable Metrics/AbcSize
+ return true if post.nil? # return if post is deleted while waiting in queue
- def build_tumblr_post(post, url)
- { :type => 'text', :format => "markdown", :body => tumblr_template(post, url) }
- end
+ body = build_tumblr_post(post, url)
+ user_info = JSON.parse(client.get("/v2/user/info").body)
+ blogs = user_info["response"]["user"]["blogs"]
+ primaryblog = blogs.find {|blog| blog["primary"] } || blogs[0]
- def tumblr_template(post, url)
- photo_html = post.photos.map {|photo|
- "})\n\n"
- }.join
+ tumblr_ids = {}
- "#{photo_html}#{post.message.html(mentioned_people: [])}\n\n[original post](#{url})"
- end
+ blogurl = URI.parse(primaryblog["url"])
+ tumblr_ids[blogurl.host.to_s] = request_to_external_blog(blogurl, body)
- def post_opts(post)
- {tumblr_ids: post.tumblr_ids} if post.tumblr_ids.present?
- end
-
- def delete_from_service(opts)
- logger.debug "event=delete_from_service type=tumblr sender_id=#{user_id} tumblr_ids=#{opts[:tumblr_ids]}"
- tumblr_posts = JSON.parse(opts[:tumblr_ids])
- tumblr_posts.each do |blog_name, post_id|
- delete_from_tumblr(blog_name, post_id)
+ post.tumblr_ids = tumblr_ids.to_json
+ post.save
end
- end
- def delete_from_tumblr(blog_name, service_post_id)
- client.post("/v2/blog/#{blog_name}/post/delete", "id" => service_post_id)
- end
+ def post_opts(post)
+ {tumblr_ids: post.tumblr_ids} if post.tumblr_ids.present?
+ end
- private
- def client
- @consumer ||= OAuth::Consumer.new(consumer_key, consumer_secret, :site => 'http://api.tumblr.com')
- @client ||= OAuth::AccessToken.new(@consumer, self.access_token, self.access_secret)
+ def delete_from_service(opts)
+ logger.debug "event=delete_from_service type=tumblr sender_id=#{user_id} tumblr_ids=#{opts[:tumblr_ids]}"
+ tumblr_posts = JSON.parse(opts[:tumblr_ids])
+ tumblr_posts.each do |blog_name, post_id|
+ delete_from_tumblr(blog_name, post_id)
+ end
+ end
+
+ def build_tumblr_post(post, url)
+ {type: "text", format: "markdown", body: tumblr_template(post, url), tags: tags(post), native_inline_images: true}
+ end
+
+ private
+
+ def client
+ @consumer ||= OAuth::Consumer.new(consumer_key, consumer_secret, site: "https://api.tumblr.com")
+ @client ||= OAuth::AccessToken.new(@consumer, access_token, access_secret)
+ end
+
+ def tumblr_template(post, url)
+ photo_html = post.photos.map {|photo| "})\n\n" }.join
+
+ "#{photo_html}#{post.message.html(mentioned_people: [])}\n\n[original post](#{url})"
+ end
+
+ def tags(post)
+ post.tags.pluck(:name).join(",").to_s
+ end
+
+ def delete_from_tumblr(blog_name, service_post_id)
+ client.post("/v2/blog/#{blog_name}/post/delete", "id" => service_post_id)
+ end
+
+ def request_to_external_blog(blogurl, body)
+ resp = client.post("/v2/blog/#{blogurl.host}/post", body)
+ JSON.parse(resp.body)["response"]["id"] if resp.code == "201"
+ end
+
+ def consumer_key
+ AppConfig.services.tumblr.key
+ end
+
+ def consumer_secret
+ AppConfig.services.tumblr.secret
+ end
end
end
-
diff --git a/app/presenters/node_info_presenter.rb b/app/presenters/node_info_presenter.rb
index f2f1566eb..ee7aec9b3 100644
--- a/app/presenters/node_info_presenter.rb
+++ b/app/presenters/node_info_presenter.rb
@@ -100,15 +100,19 @@ class NodeInfoPresenter
end
def local_posts
- @local_posts ||= Post.where(type: "StatusMessage")
- .joins(:author)
- .where("owner_id IS NOT null")
- .count
+ Rails.cache.fetch("NodeInfoPresenter/local_posts", expires_in: 1.hour) do
+ @local_posts ||= Post.where(type: "StatusMessage")
+ .joins(:author)
+ .where.not(people: {owner_id: nil})
+ .count
+ end
end
def local_comments
- @local_comments ||= Comment.joins(:author)
- .where("owner_id IS NOT null")
- .count
+ Rails.cache.fetch("NodeInfoPresenter/local_comments", expires_in: 1.hour) do
+ @local_comments ||= Comment.joins(:author)
+ .where.not(people: {owner_id: nil})
+ .count
+ end
end
end
diff --git a/spec/models/services/tumblr_spec.rb b/spec/models/services/tumblr_spec.rb
index 0da20eb37..2821dfd55 100644
--- a/spec/models/services/tumblr_spec.rb
+++ b/spec/models/services/tumblr_spec.rb
@@ -6,25 +6,42 @@ describe Services::Tumblr, type: :model do
let(:service) { Services::Tumblr.new(access_token: "yeah", access_secret: "foobar") }
let(:post_id) { "bla" }
+ describe "#provider" do
+ subject(:provider) { service.provider }
+
+ let(:expected_provider) { "tumblr" }
+
+ it "returns service provider" do
+ is_expected.to eq expected_provider
+ end
+ end
+
describe "#post" do
let(:post_request) { {body: service.build_tumblr_post(post, "")} }
let(:post_response) { {status: 201, body: {response: {id: post_id}}.to_json} }
before do
user.services << service
- stub_request(:get, "http://api.tumblr.com/v2/user/info").to_return(status: 200, body: user_info)
+ stub_request(:get, "https://api.tumblr.com/v2/user/info").to_return(status: 200, body: user_info)
end
context "with multiple blogs" do
- let(:user_info) {
- {response: {user: {blogs: [
- {primary: false, url: "http://foo.tumblr.com"},
- {primary: true, url: "http://bar.tumblr.com"}
- ]}}}.to_json
- }
+ let(:user_info) do
+ {
+ response:
+ {
+ user: {
+ blogs: [
+ {primary: false, url: "https://foo.tumblr.com"},
+ {primary: true, url: "https://bar.tumblr.com"}
+ ]
+ }
+ }
+ }.to_json
+ end
it "posts a status message to the primary blog and stores the id" do
- stub = stub_request(:post, "http://api.tumblr.com/v2/blog/bar.tumblr.com/post")
+ stub = stub_request(:post, "https://api.tumblr.com/v2/blog/bar.tumblr.com/post")
.with(post_request).to_return(post_response)
expect(post).to receive(:tumblr_ids=).with({"bar.tumblr.com" => post_id}.to_json)
@@ -36,10 +53,10 @@ describe Services::Tumblr, type: :model do
end
context "with a single blog" do
- let(:user_info) { {response: {user: {blogs: [{url: "http://foo.tumblr.com"}]}}}.to_json }
+ let(:user_info) { {response: {user: {blogs: [{url: "https://foo.tumblr.com"}]}}}.to_json }
it "posts a status message to the returned blog" do
- stub = stub_request(:post, "http://api.tumblr.com/v2/blog/foo.tumblr.com/post")
+ stub = stub_request(:post, "https://api.tumblr.com/v2/blog/foo.tumblr.com/post")
.with(post_request).to_return(post_response)
service.post(post)
@@ -63,7 +80,7 @@ describe Services::Tumblr, type: :model do
describe "#delete_from_service" do
it "removes posts from tumblr" do
tumblr_ids = {"foodbar.tumblr.com" => post_id}.to_json
- stub = stub_request(:post, "http://api.tumblr.com/v2/blog/foodbar.tumblr.com/post/delete")
+ stub = stub_request(:post, "https://api.tumblr.com/v2/blog/foodbar.tumblr.com/post/delete")
.with(body: {"id" => post_id}).to_return(status: 200)
service.delete_from_service(tumblr_ids: tumblr_ids)