Merge branch 'next-minor' into develop

This commit is contained in:
Benjamin Neff 2021-06-13 01:27:34 +02:00
commit a17fca02ff
No known key found for this signature in database
GPG key ID: 971464C3F1A90194
12 changed files with 128 additions and 95 deletions

View file

@ -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

View file

@ -10,7 +10,7 @@
{{ t "aspect_dropdown.toggle" count=aspectMembershipsLength }}
{{/if}}
</span>
<span class="caret" />
<span class="caret"></span>
</button>
<ul class="dropdown-menu aspect-membership pull-right" unselectable="on">
@ -29,8 +29,8 @@
>
<a>
<span class="status_indicator">
<i class="glyphicon glyphicon-ok" />
<i class="glyphicon glyphicon-refresh" />
<i class="glyphicon glyphicon-ok"></i>
<i class="glyphicon glyphicon-refresh"></i>
</span>
<span class="text">
{{name}}
@ -39,7 +39,7 @@
</li>
{{/each}}
{{#if dropdownMayCreateNewAspect}}
<li class="divider" />
<li class="divider"></li>
<li class="newItem add_aspect">
<a data-target="#newAspectModal" data-toggle="modal" href="#">
{{ t "aspects.create.add_a_new_aspect" }}
@ -48,5 +48,5 @@
{{/if}}
</ul>
{{#if dropdownMayCreateNewAspect}}
<div class="newAspectContainer"/>
<div class="newAspectContainer"></div>
{{/if}}

View file

@ -29,7 +29,7 @@
class="new-comment" id="new-comment-on-{{id}}" method="post">
<textarea class="comment-box form-control mention-textarea"
id="comment_text_on_{{id}}" name="text" rows="1" required placeholder="{{t "stream.comment"}}" />
id="comment_text_on_{{id}}" name="text" rows="1" required placeholder="{{t "stream.comment"}}"></textarea>
<div class="typeahead-mention-box-wrap">
<input class="typeahead-mention-box hidden" type="text">
</div>

View file

@ -11,7 +11,7 @@
{{#if canRemove}}
<a href="#" class="delete comment_delete" title="{{t "delete"}}">
<i class="entypo-trash"></i>
<a/>
</a>
{{else}}
<a href="#" data-type="Comment" class="comment_report" title="{{t "report.name"}}">
<i class="entypo-warning"></i>
@ -26,7 +26,7 @@
{{/linkToAuthor}}
-
<a href="/posts/{{parent.id}}#{{guid}}" class="permalink_comment">
<time class="timeago" data-original-title="{{{localTime created_at}}}" datetime="{{created_at}}"/>
<time class="timeago" data-original-title="{{{localTime created_at}}}" datetime="{{created_at}}"></time>
</a>
<a href="/posts/{{parent.guid}}#{{guid}}" class="permalink gray" title="{{t "stream.permalink"}}">
<i class="entypo-link"></i>

View file

@ -27,10 +27,10 @@
<div class="footer-container">
{{#if status_message}}
<a href="{{urlTo "post" status_message.id}}">
<time class="timeago" data-original-title="{{{localTime created_at}}}" datetime="{{created_at}}" />
<time class="timeago" data-original-title="{{{localTime created_at}}}" datetime="{{created_at}}"></time>
</a>
{{else}}
<time class="timeago" data-original-title="{{{localTime created_at}}}" datetime="{{created_at}}" />
<time class="timeago" data-original-title="{{{localTime created_at}}}" datetime="{{created_at}}"></time>
{{/if}}
</div>
</div>

View file

@ -9,7 +9,7 @@
</td>
<td class="pod-title" title="{{host}}">{{host}}</td>
<td class="added">
<small><time datetime="{{created_at}}" title="{{localTime created_at}}" /></small>
<small><time datetime="{{created_at}}" title="{{localTime created_at}}"></time></small>
</td>
<td>
{{#if has_no_errors}}
@ -18,10 +18,10 @@
{{status_text}}
{{/if}}
{{#unless is_unchecked}}
<br><small>{{t 'admin.pods.last_check'}} <time datetime="{{checked_at}}" title="{{localTime checked_at}}" /></small>
<br><small>{{t 'admin.pods.last_check'}} <time datetime="{{checked_at}}" title="{{localTime checked_at}}"></time></small>
{{/unless}}
{{#if offline}}
| <small>{{t 'admin.pods.offline_since'}} <time datetime="{{offline_since}}" title="{{localTime offline_since}}" /></small>
| <small>{{t 'admin.pods.offline_since'}} <time datetime="{{offline_since}}" title="{{localTime offline_since}}"></time></small>
{{/if}}
{{#if is_unchecked}}<br><small class="text-muted">{{t 'admin.pods.no_info'}}</small>{{/if}}
<pre class="details" style="display: none;">

View file

@ -15,7 +15,7 @@
<span class="details gray">
-
<a href="/posts/{{id}}">
<time class="timeago" data-original-title="{{{localTime created_at}}}" datetime="{{created_at}}" />
<time class="timeago" data-original-title="{{{localTime created_at}}}" datetime="{{created_at}}"></time>
</a>
</span>
</div>

View file

@ -40,11 +40,11 @@
<span class="post-time">
{{#if root}}
<a href="/posts/{{root.guid}}">
<time datetime="{{root.created_at}}" title="{{localTime root.created_at}}" />
<time datetime="{{root.created_at}}" title="{{localTime root.created_at}}"></time>
</a>
{{else}}
<a href="/posts/{{guid}}">
<time datetime="{{created_at}}" title="{{localTime created_at}}" />
<time datetime="{{created_at}}" title="{{localTime created_at}}"></time>
</a>
{{/if}}
</span>
@ -59,12 +59,12 @@
{{/if}}
</div>
{{#unless root}}
<div id="single-post-moderation" />
<div id="single-post-moderation"></div>
{{/unless}}
</div>
</div>
{{#unless root}}
<div id="single-post-actions" class="col-md-4" />
<div id="single-post-actions" class="col-md-4"></div>
{{/unless}}
</div>
{{#if location.lat}}
@ -92,13 +92,13 @@
<div class="post-context">
<span class="post-time">
<a href="/posts/{{guid}}">
<time datetime="{{created_at}}" title="{{localTime created_at}}" />
<time datetime="{{created_at}}" title="{{localTime created_at}}"></time>
</a>
</span>
<span id="single-post-moderation" />
<span id="single-post-moderation"></span>
</div>
</div>
<div id="single-post-actions" class="col-md-4" />
<div id="single-post-actions" class="col-md-4"></div>
</div>
{{/if}}
</div>

View file

@ -22,7 +22,7 @@
<span class="details gray post-timestamp">
-
<a href="/posts/{{id}}">
<time class="timeago" data-original-title="{{{localTime created_at}}}" datetime="{{created_at}}" />
<time class="timeago" data-original-title="{{{localTime created_at}}}" datetime="{{created_at}}"></time>
</a>
<a href="/posts/{{guid}}" class="permalink" title="{{t "stream.permalink"}}">

View file

@ -1,49 +1,30 @@
# frozen_string_literal: true
class Services::Tumblr < Service
module Services
class Tumblr < Service
MAX_CHARACTERS = 1000
def provider
"tumblr"
end
def consumer_key
AppConfig.services.tumblr.key
end
def post(post, url="") # rubocop:disable Metrics/AbcSize
return true if post.nil? # return if post is deleted while waiting in queue
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"]
end
tumblr_ids[blogurl.host.to_s] = request_to_external_blog(blogurl, body)
post.tumblr_ids = tumblr_ids.to_json
post.save
end
def build_tumblr_post(post, url)
{ :type => 'text', :format => "markdown", :body => tumblr_template(post, url) }
end
def tumblr_template(post, url)
photo_html = post.photos.map {|photo|
"![photo](#{photo.url(:scaled_full)})\n\n"
}.join
"#{photo_html}#{post.message.html(mentioned_people: [])}\n\n[original post](#{url})"
end
def post_opts(post)
{tumblr_ids: post.tumblr_ids} if post.tumblr_ids.present?
end
@ -56,14 +37,42 @@ class Services::Tumblr < Service
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| "![photo](#{photo.url(:scaled_full)})\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
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 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

View file

@ -100,15 +100,19 @@ class NodeInfoPresenter
end
def local_posts
Rails.cache.fetch("NodeInfoPresenter/local_posts", expires_in: 1.hour) do
@local_posts ||= Post.where(type: "StatusMessage")
.joins(:author)
.where("owner_id IS NOT null")
.where.not(people: {owner_id: nil})
.count
end
end
def local_comments
Rails.cache.fetch("NodeInfoPresenter/local_comments", expires_in: 1.hour) do
@local_comments ||= Comment.joins(:author)
.where("owner_id IS NOT null")
.where.not(people: {owner_id: nil})
.count
end
end
end

View file

@ -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)