Merge pull request #2746 from pixelfed/staging

Staging
This commit is contained in:
daniel 2021-05-01 16:17:20 -06:00 committed by GitHub
commit 67f7a75bd0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 472 additions and 453 deletions

View file

@ -76,6 +76,12 @@
- Updated StoryController, optimize photo size by resizing to 9:16 aspect. ([e66ed9a2](https://github.com/pixelfed/pixelfed/commit/e66ed9a2))
- Updated StoryCompose crop logic. ([2ead622c](https://github.com/pixelfed/pixelfed/commit/2ead622c))
- Updated StatusController, allow license edits without 24 hour limit. ([c799a01a](https://github.com/pixelfed/pixelfed/commit/c799a01a))
- Updated Settings, remove reports page. ([9cf962ff](https://github.com/pixelfed/pixelfed/commit/9cf962ff))
- Updated ProfileService, use account transformer. ([391b1287](https://github.com/pixelfed/pixelfed/commit/391b1287))
- Updated LikeController, hide like counts. ([ea687240](https://github.com/pixelfed/pixelfed/commit/ea687240))
- Updated StatusTransformers, add liked_by attribute. ([372bacb0](https://github.com/pixelfed/pixelfed/commit/372bacb0))
- Updated PostComponent, change like logic. ([0a35f5d6](https://github.com/pixelfed/pixelfed/commit/0a35f5d6))
- Updated Timeline component, change like logic. ([7bcbf96b](https://github.com/pixelfed/pixelfed/commit/7bcbf96b))
- ([](https://github.com/pixelfed/pixelfed/commit/))
## [v0.10.10 (2021-01-28)](https://github.com/pixelfed/pixelfed/compare/v0.10.9...v0.10.10)

View file

@ -62,7 +62,7 @@ class LikeController extends Controller
StatusService::del($status->id);
if ($request->ajax()) {
$response = ['code' => 200, 'msg' => 'Like saved', 'count' => $count];
$response = ['code' => 200, 'msg' => 'Like saved', 'count' => 0];
} else {
$response = redirect($status->url());
}

View file

@ -151,13 +151,6 @@ class SettingsController extends Controller
return view('settings.export.show');
}
public function reportsHome(Request $request)
{
$profile = Auth::user()->profile;
$reports = Report::whereProfileId($profile->id)->orderByDesc('created_at')->paginate(10);
return view('settings.reports', compact('reports'));
}
public function metroDarkMode(Request $request)
{
$this->validate($request, [

View file

@ -0,0 +1,65 @@
<?php
namespace App\Services;
use App\Util\ActivityPub\Helpers;
use Illuminate\Support\Facades\Redis;
use App\Like;
class LikeService {
const CACHE_KEY = 'pf:services:likes:ids:';
public static function getUser($profile_id)
{
return self::get($profile_id);
}
protected static function get($profile_id)
{
$key = self::CACHE_KEY . $profile_id;
if(Redis::zcard($key) == 0) {
self::warmCache($profile_id);
} else {
return Redis::zrevrange($key, 0, 40);
}
}
protected static function set($profile_id, $status_id)
{
$key = self::CACHE_KEY . $profile_id;
Redis::zadd($key, $status_id, $status_id);
}
public static function warmCache($profile_id)
{
Like::select('id', 'profile_id', 'status_id')
->whereProfileId($profile_id)
->latest()
->get()
->each(function($like) use ($profile_id) {
self::set($profile_id, $like->status_id);
});
}
public static function liked($profileId, $statusId)
{
$key = self::CACHE_KEY . $profileId;
return (bool) Redis::zrank($key, $statusId);
}
public static function likedBy($status)
{
if(!$status->likes_count) {
return [
'username' => null,
'others' => false
];
}
$id = Like::whereStatusId($status->id)->first()->profile_id;
return [
'username' => ProfileService::get($id)['username'],
'others' => $status->likes_count >= 5,
];
}
}

View file

@ -57,7 +57,7 @@ class MediaTagService
protected function idToUsername($id)
{
$profile = ProfileService::build()->profileId($id);
$profile = ProfileService::get($id);
if(!$profile) {
return 'unavailable';
@ -65,8 +65,8 @@ class MediaTagService
return [
'id' => (string) $id,
'username' => $profile->username,
'avatar' => $profile->avatarUrl()
'username' => $profile['username'],
'avatar' => $profile['avatar']
];
}

View file

@ -4,41 +4,29 @@ namespace App\Services;
use Cache;
use Illuminate\Support\Facades\Redis;
use App\{
Follower,
Profile
};
use App\Transformer\Api\AccountTransformer;
use League\Fractal;
use League\Fractal\Serializer\ArraySerializer;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use App\Profile;
class ProfileService {
protected $profile;
protected $profile_prefix;
public static function build()
public static function get($id)
{
return new self();
$key = 'profile:model:' . $id;
$ttl = now()->addHours(4);
$res = Cache::remember($key, $ttl, function() use($id) {
$profile = Profile::find($id);
if(!$profile) {
return false;
}
public function profile(Profile $profile)
{
$this->profile = $profile;
$this->profile_prefix = 'profile:model:'.$profile->id;
return $this;
}
public function profileId($id)
{
return Cache::rememberForever('profile:model:'.$id, function() use($id) {
return Profile::findOrFail($id);
});
}
public function get()
{
return Cache::rememberForever($this->profile_prefix, function() {
return $this->profile;
$fractal = new Fractal\Manager();
$fractal->setSerializer(new ArraySerializer());
$resource = new Fractal\Resource\Item($profile, new AccountTransformer());
return $fractal->createData($resource)->toArray();
});
return $res;
}
}

View file

@ -6,7 +6,10 @@ use App\Status;
use League\Fractal;
use Cache;
use App\Services\HashidService;
use App\Services\LikeService;
use App\Services\MediaTagService;
use App\Services\StatusLabelService;
use App\Services\ProfileService;
class StatusStatelessTransformer extends Fractal\TransformerAbstract
{
@ -32,8 +35,8 @@ class StatusStatelessTransformer extends Fractal\TransformerAbstract
'content_text' => $status->caption,
'created_at' => $status->created_at->format('c'),
'emojis' => [],
'reblogs_count' => $status->reblogs_count ?? 0,
'favourites_count' => $status->likes_count ?? 0,
'reblogs_count' => 0,
'favourites_count' => 0,
'reblogged' => null,
'favourited' => null,
'muted' => null,
@ -56,7 +59,9 @@ class StatusStatelessTransformer extends Fractal\TransformerAbstract
'parent' => [],
'place' => $status->place,
'local' => (bool) $status->local,
'taggedPeople' => $taggedPeople
'taggedPeople' => $taggedPeople,
'label' => StatusLabelService::get($status),
'liked_by' => LikeService::likedBy($status)
];
}

View file

@ -2,12 +2,15 @@
namespace App\Transformer\Api;
use App\Like;
use App\Status;
use League\Fractal;
use Cache;
use App\Services\HashidService;
use App\Services\LikeService;
use App\Services\MediaTagService;
use App\Services\StatusLabelService;
use App\Services\ProfileService;
use Illuminate\Support\Str;
class StatusTransformer extends Fractal\TransformerAbstract
@ -34,8 +37,8 @@ class StatusTransformer extends Fractal\TransformerAbstract
'content_text' => $status->caption,
'created_at' => $status->created_at->format('c'),
'emojis' => [],
'reblogs_count' => $status->reblogs_count ?? 0,
'favourites_count' => $status->likes_count ?? 0,
'reblogs_count' => 0,
'favourites_count' => 0,
'reblogged' => $status->shared(),
'favourited' => $status->liked(),
'muted' => null,
@ -59,7 +62,8 @@ class StatusTransformer extends Fractal\TransformerAbstract
'place' => $status->place,
'local' => (bool) $status->local,
'taggedPeople' => $taggedPeople,
'label' => StatusLabelService::get($status)
'label' => StatusLabelService::get($status),
'liked_by' => LikeService::likedBy($status)
];
}

BIN
public/js/status.js vendored

Binary file not shown.

BIN
public/js/timeline.js vendored

Binary file not shown.

Binary file not shown.

View file

@ -220,14 +220,16 @@
<h3 v-if="status.visibility == 'public'" v-bind:class="[reactions.bookmarked ? 'fas fa-bookmark text-warning m-0 mr-3 cursor-pointer' : 'far fa-bookmark m-0 mr-3 cursor-pointer']" title="Bookmark" v-on:click="bookmarkStatus"></h3>
<h3 v-if="status.visibility == 'public'" v-bind:class="[reactions.shared ? 'fas fa-retweet m-0 text-primary cursor-pointer' : 'fas fa-retweet m-0 share-btn cursor-pointer']" title="Share" v-on:click="shareStatus"></h3>
</div>
<div class="reaction-counts font-weight-bold mb-0">
<span style="cursor:pointer;" v-on:click="likesModal">
<span class="like-count">{{status.favourites_count || 0}}</span> likes
<div class="reaction-counts mb-0">
<div v-if="status.liked_by.username && status.liked_by.username !== user.username" class="likes mb-1">
<span class="like-count">Liked by
<a class="font-weight-bold text-dark" :href="'/'+status.liked_by.username">{{status.liked_by.username}}</a>
<span v-if="status.liked_by.others == true">
and <span class="font-weight-bold text-dark cursor-pointer" @click="likesModal">others</span>
</span>
<span v-if="status.visibility == 'public'" class="float-right" style="cursor:pointer;" v-on:click="sharesModal">
<span class="share-count pl-4">{{status.reblogs_count || 0}}</span> shares
</span>
</div>
</div>
<div class="timestamp pt-2 d-flex align-items-bottom justify-content-between">
<a v-bind:href="statusUrl" class="small text-muted" :title="status.created_at">
{{timestampFormat()}}
@ -978,9 +980,6 @@ export default {
window.location.href = '/login?next=' + encodeURIComponent('/p/' + this.status.shortcode);
return;
}
if(this.status.favourites_count == 0) {
return;
}
if(this.likes.length) {
this.$refs.likesModal.show();
return;

View file

@ -224,8 +224,13 @@
</span>
</div>
<div class="likes font-weight-bold" v-if="expLc(status) == true">
<span class="like-count">{{status.favourites_count}}</span> {{status.favourites_count == 1 ? 'like' : 'likes'}}
<div v-if="status.liked_by.username && status.liked_by.username !== profile.username" class="likes mb-1">
<span class="like-count">Liked by
<a class="font-weight-bold text-dark" :href="'/'+status.liked_by.username">{{status.liked_by.username}}</a>
<span v-if="status.liked_by.others == true">
and <span class="font-weight-bold">others</span>
</span>
</span>
</div>
<div v-if="status.pf_type != 'text'" class="caption">
<p v-if="!status.sensitive" class="mb-2 read-more" style="overflow: hidden;">

View file

@ -26,16 +26,9 @@
<li class="nav-item pl-3 {{request()->is('settings/relationships*')?'active':''}}">
<a class="nav-link font-weight-light text-muted" href="{{route('settings.relationships')}}">Relationships</a>
</li>
<li class="nav-item pl-3 {{request()->is('settings/reports*')?'active':''}}">
<a class="nav-link font-weight-light text-muted" href="{{route('settings.reports')}}">Reports</a>
</li>
<li class="nav-item pl-3 {{request()->is('settings/security*')?'active':''}}">
<a class="nav-link font-weight-light text-muted" href="{{route('settings.security')}}">Security</a>
</li>
{{-- <li class="nav-item pl-3 {{request()->is('settings/sponsor*')?'active':''}}">
<a class="nav-link font-weight-light text-muted" href="{{route('settings.sponsor')}}">Sponsor</a>
</li> --}}
<li class="nav-item">
<hr>
</li>

View file

@ -1,38 +0,0 @@
@extends('settings.template')
@section('section')
<div class="title">
<h3 class="font-weight-bold">Reports</h3>
</div>
<hr>
<p class="lead">A list of reports you have made. </p>
<table class="table table-responsive">
<thead class="bg-light">
<th scope="col">ID</th>
<th scope="col">Type</th>
<th scope="col">Reported</th>
<th scope="col">Status</th>
<th scope="col">Created</th>
</tr>
</thead>
<tbody>
@foreach($reports as $report)
<tr>
<td class="font-weight-bold">{{$report->id}}</td>
<td class="font-weight-bold">{{$report->type}}</td>
<td class="font-weight-bold"><a href="{{$report->reported()->url()}}">{{str_limit($report->reported()->url(), 30)}}</a></td>
@if(!$report->admin_seen)
<td><span class="text-danger font-weight-bold">Unresolved</span></td>
@else
<td><span class="text-success font-weight-bold">Resolved</span></td>
@endif
<td class="font-weight-bold">{{$report->created_at->diffForHumans(null, true, true)}}</td>
</tr>
@endforeach
</tbody>
</table>
<div class="d-flex justify-content-center mt-5 small">
{{$reports->links()}}
</div>
@endsection

View file

@ -351,7 +351,6 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact
Route::post('privacy/blocked-instances/unblock', 'SettingsController@blockedInstanceUnblock')->name('settings.privacy.blocked-instances.unblock');
Route::get('privacy/blocked-keywords', 'SettingsController@blockedKeywords')->name('settings.privacy.blocked-keywords');
Route::post('privacy/account', 'SettingsController@privateAccountOptions')->name('settings.privacy.account');
Route::get('reports', 'SettingsController@reportsHome')->name('settings.reports');
Route::group(['prefix' => 'remove', 'middleware' => 'dangerzone'], function() {
Route::get('request/temporary', 'SettingsController@removeAccountTemporary')->name('settings.remove.temporary');
Route::post('request/temporary', 'SettingsController@removeAccountTemporarySubmit');