mirror of https://github.com/pixelfed/pixelfed
Add profile pronouns
parent
8a73643277
commit
fabb57a9d5
@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class UserPronoun extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
}
|
@ -0,0 +1,102 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services;
|
||||||
|
|
||||||
|
use Cache;
|
||||||
|
use App\Models\UserPronoun;
|
||||||
|
use App\Profile;
|
||||||
|
|
||||||
|
class PronounService {
|
||||||
|
|
||||||
|
public static function get($id)
|
||||||
|
{
|
||||||
|
$key = 'user:pronouns:' . $id;
|
||||||
|
$ttl = now()->addHours(12);
|
||||||
|
|
||||||
|
return Cache::remember($key, $ttl, function() use($id) {
|
||||||
|
$res = UserPronoun::whereProfileId($id)->first();
|
||||||
|
return $res ? json_decode($res->pronouns, true) : [];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function put($id, $pronouns)
|
||||||
|
{
|
||||||
|
$res = UserPronoun::whereProfileId($id)->first();
|
||||||
|
$key = 'user:pronouns:' . $id;
|
||||||
|
|
||||||
|
if($res) {
|
||||||
|
$res->pronouns = json_encode($pronouns);
|
||||||
|
$res->save();
|
||||||
|
Cache::forget($key);
|
||||||
|
AccountService::del($id);
|
||||||
|
return $res->pronouns;
|
||||||
|
}
|
||||||
|
|
||||||
|
$res = new UserPronoun;
|
||||||
|
$res->profile_id = $id;
|
||||||
|
$res->pronouns = json_encode($pronouns);
|
||||||
|
$res->save();
|
||||||
|
Cache::forget($key);
|
||||||
|
AccountService::del($id);
|
||||||
|
return $res->pronouns;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function clear($id)
|
||||||
|
{
|
||||||
|
$res = UserPronoun::whereProfileId($id)->first();
|
||||||
|
if($res) {
|
||||||
|
$res->pronouns = null;
|
||||||
|
$res->save();
|
||||||
|
}
|
||||||
|
$key = 'user:pronouns:' . $id;
|
||||||
|
Cache::forget($key);
|
||||||
|
AccountService::del($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function pronouns()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'co',
|
||||||
|
'cos',
|
||||||
|
'e',
|
||||||
|
'ey',
|
||||||
|
'em',
|
||||||
|
'eir',
|
||||||
|
'fae',
|
||||||
|
'faer',
|
||||||
|
'he',
|
||||||
|
'him',
|
||||||
|
'his',
|
||||||
|
'her',
|
||||||
|
'hers',
|
||||||
|
'hir',
|
||||||
|
'mer',
|
||||||
|
'mers',
|
||||||
|
'ne',
|
||||||
|
'nir',
|
||||||
|
'nirs',
|
||||||
|
'nee',
|
||||||
|
'ner',
|
||||||
|
'ners',
|
||||||
|
'per',
|
||||||
|
'pers',
|
||||||
|
'she',
|
||||||
|
'they',
|
||||||
|
'them',
|
||||||
|
'theirs',
|
||||||
|
'thon',
|
||||||
|
'thons',
|
||||||
|
've',
|
||||||
|
'ver',
|
||||||
|
'vis',
|
||||||
|
'vi',
|
||||||
|
'vir',
|
||||||
|
'xe',
|
||||||
|
'xem',
|
||||||
|
'xyr',
|
||||||
|
'ze',
|
||||||
|
'zir',
|
||||||
|
'zie'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class CreateUserPronounsTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('user_pronouns', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->unsignedInteger('user_id')->nullable()->unique()->index();
|
||||||
|
$table->bigInteger('profile_id')->unique()->index();
|
||||||
|
$table->json('pronouns')->nullable();
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('user_pronouns');
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue