Merge pull request #2139 from pixelfed/staging

Fix remote usernames
This commit is contained in:
daniel 2020-04-22 00:00:28 -06:00 committed by GitHub
commit 7f0476f02e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 212 additions and 28 deletions

View file

@ -12,6 +12,7 @@
- Updated RemoteProfile, fix missing content warnings ([e487527a](https://github.com/pixelfed/pixelfed/commit/e487527a)) - Updated RemoteProfile, fix missing content warnings ([e487527a](https://github.com/pixelfed/pixelfed/commit/e487527a))
- Updated RemotePost component, fix missing like button on comments ([7ef90565](https://github.com/pixelfed/pixelfed/commit/7ef90565)) - Updated RemotePost component, fix missing like button on comments ([7ef90565](https://github.com/pixelfed/pixelfed/commit/7ef90565))
- Updated PublicApiControllers, fix block/mutes filtering on public timeline ([08383dd4](https://github.com/pixelfed/pixelfed/commit/08383dd4)) - Updated PublicApiControllers, fix block/mutes filtering on public timeline ([08383dd4](https://github.com/pixelfed/pixelfed/commit/08383dd4))
- Updated FixUsernames command, fixes remote username search ([0f943f67](https://github.com/pixelfed/pixelfed/commit/0f943f67))
## [v0.10.9 (2020-04-17)](https://github.com/pixelfed/pixelfed/compare/v0.10.8...v0.10.9) ## [v0.10.9 (2020-04-17)](https://github.com/pixelfed/pixelfed/compare/v0.10.8...v0.10.9)

View file

@ -2,7 +2,6 @@
<p align="center"> <p align="center">
<a href="https://circleci.com/gh/pixelfed/pixelfed"><img src="https://circleci.com/gh/pixelfed/pixelfed.svg?style=svg" alt="Build Status"></a> <a href="https://circleci.com/gh/pixelfed/pixelfed"><img src="https://circleci.com/gh/pixelfed/pixelfed.svg?style=svg" alt="Build Status"></a>
<a href="https://codeclimate.com/github/pixelfed/pixelfed/maintainability"><img src="https://api.codeclimate.com/v1/badges/0b038ebb94ab9080ef59/maintainability" /></a>
<a href="https://packagist.org/packages/pixelfed/pixelfed"><img src="https://poser.pugx.org/pixelfed/pixelfed/v/stable.svg" alt="Latest Stable Version"></a> <a href="https://packagist.org/packages/pixelfed/pixelfed"><img src="https://poser.pugx.org/pixelfed/pixelfed/v/stable.svg" alt="Latest Stable Version"></a>
<a href="https://packagist.org/packages/pixelfed/pixelfed"><img src="https://poser.pugx.org/pixelfed/pixelfed/license.svg" alt="License"></a> <a href="https://packagist.org/packages/pixelfed/pixelfed"><img src="https://poser.pugx.org/pixelfed/pixelfed/license.svg" alt="License"></a>
</p> </p>
@ -29,19 +28,9 @@ The ways you can communicate on the project are below. Before interacting, pleas
read through the [Code Of Conduct](CODE_OF_CONDUCT.md). read through the [Code Of Conduct](CODE_OF_CONDUCT.md).
* IRC: [#pixelfed](irc://chat.freenode.net/pixelfed) on irc.freenode.net * IRC: [#pixelfed](irc://chat.freenode.net/pixelfed) on irc.freenode.net
* Matrix: [#pixelfed:matrix.org](https://matrix.to/#/#pixelfed:matrix.org)
* Mastodon: [@pixelfed@mastodon.social](https://mastodon.social/@pixelfed) * Mastodon: [@pixelfed@mastodon.social](https://mastodon.social/@pixelfed)
* E-mail: [hello@pixelfed.org](mailto:hello@pixelfed.org) * E-mail: [hello@pixelfed.org](mailto:hello@pixelfed.org)
### Development
For more development focused communication methods, please visit the following:
* IRC: [#pixelfed-dev](irc://chat.freenode.net/pixelfed-dev) on irc.freenode.net
* Matrix: [#pixelfed-dev:matrix.org](https://matrix.to/#/#pixelfed-dev:matrix.org)
* Mastodon: [@pixeldev@mastodon.social](https://mastodon.social/@pixeldev)
## Pixelfed Sponsors ## Pixelfed Sponsors
We would like to extend our thanks to the following sponsors for funding Pixelfed development. If you are interested in becoming a sponsor, please visit the Pixelfed [Patreon Page](https://www.patreon.com/dansup/overview) We would like to extend our thanks to the following sponsors for funding Pixelfed development. If you are interested in becoming a sponsor, please visit the Pixelfed [Patreon Page](https://www.patreon.com/dansup/overview)
@ -49,5 +38,3 @@ We would like to extend our thanks to the following sponsors for funding Pixelfe
- [NLnet Foundation](https://nlnet.nl) and [NGI0 - [NLnet Foundation](https://nlnet.nl) and [NGI0
Discovery](https://nlnet.nl/discovery/), part of the [Next Generation Discovery](https://nlnet.nl/discovery/), part of the [Next Generation
Internet](https://ngi.eu) initiative. Internet](https://ngi.eu) initiative.
- [<img src="https://td-misc-public.s3.amazonaws.com/OscillasLogo.png" width="100px">](https://oscillas.com/)
- Managed Pixelfed Hosting by [Spacebear](https://app.spacebear.ee/)

View file

@ -40,8 +40,14 @@ class FixUsernames extends Command
*/ */
public function handle() public function handle()
{ {
$this->line(' ');
$this->info('Collecting data ...'); $this->info('Collecting data ...');
$this->line(' ');
$this->restrictedCheck();
}
protected function restrictedCheck()
{
$affected = collect([]); $affected = collect([]);
$restricted = RestrictedNames::get(); $restricted = RestrictedNames::get();
@ -61,6 +67,7 @@ class FixUsernames extends Command
} }
} }
}); });
if($affected->count() > 0) { if($affected->count() > 0) {
$this->info('Found: ' . $affected->count() . ' affected usernames'); $this->info('Found: ' . $affected->count() . ' affected usernames');
@ -118,7 +125,40 @@ class FixUsernames extends Command
$this->info('Fixed ' . $affected->count() . ' usernames!'); $this->info('Fixed ' . $affected->count() . ' usernames!');
} else { } else {
$this->info('No affected usernames found!'); $this->info('No restricted usernames found!');
} }
$this->line(' ');
$this->versionZeroTenNineFix();
}
protected function versionZeroTenNineFix()
{
$profiles = Profile::whereNotNull('domain')
->whereNull('private_key')
->where('username', 'not like', '@%@%')
->get();
$count = $profiles->count();
if($count > 0) {
$this->info("Found {$count} remote usernames to fix ...");
$this->line(' ');
} else {
$this->info('No remote fixes found!');
$this->line(' ');
return;
}
foreach($profiles as $p) {
$this->info("Fixed $p->username => $p->webfinger");
$p->username = $p->webfinger ?? "@{$p->username}@{$p->domain}";
if(Profile::whereUsername($p->username)->exists()) {
return;
}
$p->save();
}
if($count > 0) {
$this->line(' ');
}
} }
} }

View file

@ -61,6 +61,10 @@ class SearchController extends Controller
$this->webfingerSearch(); $this->webfingerSearch();
break; break;
case 'remote':
$this->remoteLookupSearch();
break;
default: default:
break; break;
} }
@ -179,24 +183,15 @@ class SearchController extends Controller
'following' => $item->followedBy(Auth::user()->profile), 'following' => $item->followedBy(Auth::user()->profile),
'follow_request' => $item->hasFollowRequestById(Auth::user()->profile_id), 'follow_request' => $item->hasFollowRequestById(Auth::user()->profile_id),
'thumb' => $item->avatarUrl(), 'thumb' => $item->avatarUrl(),
'local' => (bool) !$item->domain 'local' => (bool) !$item->domain,
'post_count' => $item->statuses()->count()
] ]
]]; ]];
return $tokens; return $tokens;
}); });
} }
} }
// elseif( Str::containsAll($tag, ['@', '.'])
// config('federation.activitypub.enabled') == true &&
// config('federation.activitypub.remoteFollow') == true
// ) {
// if(substr_count($tag, '@') == 2) {
// $domain = last(explode('@', sub_str($u, 1)));
// } else {
// $domain = last(explode('@', $u));
// }
// }
else { else {
$this->tokens['profiles'] = Cache::remember($key, $ttl, function() use($tag) { $this->tokens['profiles'] = Cache::remember($key, $ttl, function() use($tag) {
$users = Profile::select('domain', 'username', 'name', 'id') $users = Profile::select('domain', 'username', 'name', 'id')
@ -268,4 +263,53 @@ class SearchController extends Controller
]; ];
return; return;
} }
protected function remotePostLookup()
{
$tag = $this->term;
$hash = hash('sha256', $tag);
$local = Helpers::validateLocalUrl($tag);
$valid = Helpers::validateUrl($tag);
if($valid == false || $local == true) {
return;
}
if(Status::whereUri($tag)->whereLocal(false)->exists()) {
$item = Status::whereUri($tag)->first();
$this->tokens['posts'] = [[
'count' => 0,
'url' => "/i/web/post/_/$item->profile_id/$item->id",
'type' => 'status',
'username' => $item->profile->username,
'caption' => $item->rendered ?? $item->caption,
'thumb' => $item->firstMedia()->remote_url,
'timestamp' => $item->created_at->diffForHumans()
]];
}
$remote = Helpers::fetchFromUrl($tag);
if(isset($remote['type']) && $remote['type'] == 'Note') {
$item = Helpers::statusFetch($tag);
$this->tokens['posts'] = [[
'count' => 0,
'url' => "/i/web/post/_/$item->profile_id/$item->id",
'type' => 'status',
'username' => $item->profile->username,
'caption' => $item->rendered ?? $item->caption,
'thumb' => $item->firstMedia()->remote_url,
'timestamp' => $item->created_at->diffForHumans()
]];
}
}
protected function remoteLookupSearch()
{
if(!Helpers::validateUrl($this->term)) {
return;
}
$this->getProfiles();
$this->remotePostLookup();
}
} }

View file

@ -416,7 +416,7 @@ class Helpers {
if(!$profile) { if(!$profile) {
$profile = new Profile(); $profile = new Profile();
$profile->domain = strtolower($domain); $profile->domain = strtolower($domain);
$profile->username = strtolower(Purify::clean($remoteUsername)); $profile->username = strtolower(Purify::clean($webfinger));
$profile->name = isset($res['name']) ? Purify::clean($res['name']) : 'user'; $profile->name = isset($res['name']) ? Purify::clean($res['name']) : 'user';
$profile->bio = isset($res['summary']) ? Purify::clean($res['summary']) : null; $profile->bio = isset($res['summary']) ? Purify::clean($res['summary']) : null;
$profile->sharedInbox = isset($res['endpoints']) && isset($res['endpoints']['sharedInbox']) ? $res['endpoints']['sharedInbox'] : null; $profile->sharedInbox = isset($res['endpoints']) && isset($res['endpoints']['sharedInbox']) ? $res['endpoints']['sharedInbox'] : null;

BIN
public/js/search.js vendored

Binary file not shown.

Binary file not shown.

View file

@ -175,6 +175,82 @@
</div> </div>
</div> </div>
</div> </div>
<div v-else-if="analysis == 'remote'" class="row">
<div class="col-12 mb-5">
<p class="h5 font-weight-bold text-dark">Showing results for <i>{{query}}</i></p>
<hr>
</div>
<div v-if="results.profiles.length" class="col-md-6 offset-3">
<a v-for="(profile, index) in results.profiles" class="mb-2 result-card" :href="buildUrl('profile', profile)">
<div class="pb-3">
<div class="media align-items-center py-2 pr-3">
<img class="mr-3 rounded-circle border" :src="profile.entity.thumb" width="50px" height="50px" onerror="this.onerror=null;this.src='/storage/avatars/default.png';">
<div class="media-body">
<p class="mb-0 text-truncate text-dark font-weight-bold" data-toggle="tooltip" :title="profile.value">
{{profile.value}}
</p>
<p class="mb-0 small font-weight-bold text-muted text-uppercase">
{{profile.entity.post_count}} Posts
</p>
</div>
<div class="ml-3">
<a v-if="profile.entity.following" class="btn btn-primary btn-sm font-weight-bold text-uppercase py-0" :href="buildUrl('profile', profile)">Following</a>
<a v-else class="btn btn-outline-primary btn-sm font-weight-bold text-uppercase py-0" :href="buildUrl('profile', profile)">View</a>
</div>
</div>
</div>
</a>
</div>
<div v-if="results.statuses.length" class="col-md-6 offset-3">
<a v-for="(status, index) in results.statuses" class="mr-2 result-card" :href="buildUrl('status', status)">
<img :src="status.thumb" width="90px" height="90px" class="mb-2" onerror="this.onerror=null;this.src='/storage/no-preview.png';">
</a>
</div>
</div>
<div v-else-if="analysis == 'remotePost'" class="row">
<div class="col-12 mb-5">
<p class="h5 font-weight-bold text-dark">Showing results for <i>{{query}}</i></p>
<hr>
</div>
<div class="col-md-6 offset-md-3">
<div v-if="results.statuses.length">
<div v-for="(status, index) in results.statuses" class="card mb-4 shadow-none border">
<div class="card-header p-0 m-0">
<div style="width: 100%;height: 200px;background: #fff">
<div class="pt-4 text-center">
<img :src="status.thumb" class="img-fluid border" style="max-height: 140px;">
</div>
</div>
</div>
<div class="card-body">
<div class="mt-n4 mb-2">
<div class="media">
<img class="rounded-circle p-1 mr-2 border mt-n3 bg-white shadow" src="/storage/avatars/default.png" width="70px" height="70px;" onerror="this.onerror=null;this.src='/storage/avatars/default.png';">
<div class="media-body pt-3">
<p class="font-weight-bold mb-0">{{status.username}}</p>
</div>
<div class="float-right pt-3">
<p class="small mb-0 text-muted">{{status.timestamp}}</p>
</div>
</div>
</div>
<p class="text-center mb-3 lead" v-html="status.caption"></p>
<!-- <p class="text-center text-muted small text-uppercase mb-4">2 likes</p> -->
<!-- <div class="d-flex justify-content-center">
<a class="btn btn-primary btn-sm py-1 px-4 text-uppercase font-weight-bold" :href="status.url" style="font-weight: 500">View Post</a>
</div> -->
</div>
<div class="card-footer">
<a class="btn btn-primary btn-block font-weight-bold rounded-0" :href="status.url">View Post</a>
</div>
</div>
</div>
<div v-else>
<div class="border py-3 text-center font-weight-bold">No results found</div>
</div>
</div>
</div>
<div v-else class="col-12"> <div v-else class="col-12">
<p class="text-center text-muted lead font-weight-bold">No results found</p> <p class="text-center text-muted lead font-weight-bold">No results found</p>
</div> </div>
@ -232,6 +308,14 @@ export default {
}, },
fetchSearchResults() { fetchSearchResults() {
if(this.analysis == 'remote') {
let term = this.query;
let parsed = new URL(term);
if(parsed.host === window.location.host) {
window.location.href = term;
return;
}
}
this.searchContext(this.analysis); this.searchContext(this.analysis);
}, },
@ -266,7 +350,7 @@ export default {
return 'webfinger'; return 'webfinger';
} }
if(q.startsWith('@') || q.search('@') != -1) { if(q.startsWith('@')) {
return 'profile'; return 'profile';
} }
@ -320,6 +404,34 @@ export default {
}); });
break; break;
case 'remote':
axios.get('/api/search', {
params: {
'q': this.query,
'src': 'metro',
'v': 1,
'scope': 'remote'
}
}).then(res => {
let results = res.data;
this.results.hashtags = results.hashtags ? results.hashtags : [];
this.results.profiles = results.profiles ? results.profiles : [];
this.results.statuses = results.posts ? results.posts : [];
if(this.results.profiles.length) {
this.analysis = 'profile';
}
if(this.results.statuses.length) {
this.analysis = 'remotePost';
}
this.loading = false;
}).catch(err => {
this.loading = false;
console.log(err);
this.networkError = true;
});
break;
case 'hashtag': case 'hashtag':
axios.get('/api/search', { axios.get('/api/search', {
params: { params: {