From 2b63fe830bd20005904afd01d2fab7d353b129eb Mon Sep 17 00:00:00 2001
From: BentiGorlich
Date: Fri, 14 Jun 2024 10:03:11 +0200
Subject: [PATCH 1/3] Add cake day and use a user's `published` field - add the
cake day to a users profile page, as well as the user popover - set the
`createdAt` field to a user's `published` field when updating them. We
already expose that field
---
src/Service/ActivityPubManager.php | 10 ++++++++++
src/Service/SettingsManager.php | 9 +++++++++
src/Twig/Extension/SettingsExtension.php | 1 +
src/Twig/Runtime/SettingsExtensionRuntime.php | 5 +++++
templates/user/_info.html.twig | 10 +++++++---
templates/user/_user_popover.html.twig | 4 ++++
translations/messages.en.yaml | 1 +
7 files changed, 37 insertions(+), 3 deletions(-)
diff --git a/src/Service/ActivityPubManager.php b/src/Service/ActivityPubManager.php
index fda2ec4cc..32073e078 100644
--- a/src/Service/ActivityPubManager.php
+++ b/src/Service/ActivityPubManager.php
@@ -330,6 +330,16 @@ public function updateUser(string $actorUrl): ?User
$user->apTimeoutAt = null;
$user->apFetchedAt = new \DateTime();
+ if (isset($actor['published'])) {
+ try {
+ $createdAt = new \DateTimeImmutable($actor['published']);
+ $now = new \DateTimeImmutable();
+ if ($createdAt < $now) {
+ $user->createdAt = $createdAt;
+ }
+ } catch (\Exception) {}
+ }
+
// Only update about when summary is set
if (isset($actor['summary'])) {
$converter = new HtmlConverter(['strip_tags' => true]);
diff --git a/src/Service/SettingsManager.php b/src/Service/SettingsManager.php
index 11ac26645..bcd672951 100644
--- a/src/Service/SettingsManager.php
+++ b/src/Service/SettingsManager.php
@@ -9,6 +9,7 @@
use App\Repository\SettingsRepository;
use Doctrine\ORM\EntityManagerInterface;
use JetBrains\PhpStorm\Pure;
+use Symfony\Component\HttpFoundation\RequestStack;
class SettingsManager
{
@@ -17,6 +18,7 @@ class SettingsManager
public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly SettingsRepository $repository,
+ private readonly RequestStack $requestStack,
private readonly string $kbinDomain,
private readonly string $kbinTitle,
private readonly string $kbinMetaTitle,
@@ -153,4 +155,11 @@ public static function getValue(string $name): string
{
return self::$dto->{$name};
}
+
+ public function getLocale(): string
+ {
+ $request = $this->requestStack->getCurrentRequest();
+
+ return $request->cookies->get('kbin_lang') ?? $request->getLocale() ?? $this->get('KBIN_DEFAULT_LANG');
+ }
}
diff --git a/src/Twig/Extension/SettingsExtension.php b/src/Twig/Extension/SettingsExtension.php
index c3981962e..1b966c0c3 100644
--- a/src/Twig/Extension/SettingsExtension.php
+++ b/src/Twig/Extension/SettingsExtension.php
@@ -31,6 +31,7 @@ public function getFunctions(): array
new TwigFunction('mbin_restrict_magazine_creation', [SettingsExtensionRuntime::class, 'mbinRestrictMagazineCreation']),
new TwigFunction('mbin_private_instance', [SettingsExtensionRuntime::class, 'mbinPrivateInstance']),
new TwigFunction('mbin_sso_show_first', [SettingsExtensionRuntime::class, 'mbinSsoShowFirst']),
+ new TwigFunction('mbin_lang', [SettingsExtensionRuntime::class, 'mbinLang']),
];
}
}
diff --git a/src/Twig/Runtime/SettingsExtensionRuntime.php b/src/Twig/Runtime/SettingsExtensionRuntime.php
index 6f5ce0ea5..2213d98fc 100644
--- a/src/Twig/Runtime/SettingsExtensionRuntime.php
+++ b/src/Twig/Runtime/SettingsExtensionRuntime.php
@@ -118,4 +118,9 @@ public function mbinSsoShowFirst(): bool
{
return $this->settings->get('MBIN_SSO_SHOW_FIRST');
}
+
+ public function mbinLang(): string
+ {
+ return $this->settings->getLocale();
+ }
}
diff --git a/templates/user/_info.html.twig b/templates/user/_info.html.twig
index c6ec88255..c6bbf2899 100644
--- a/templates/user/_info.html.twig
+++ b/templates/user/_info.html.twig
@@ -19,15 +19,19 @@
{% endif %}
diff --git a/templates/user/_user_popover.html.twig b/templates/user/_user_popover.html.twig
index a4569f9ee..59578f8a3 100644
--- a/templates/user/_user_popover.html.twig
+++ b/templates/user/_user_popover.html.twig
@@ -21,6 +21,10 @@
- {{ 'joined'|trans }}: {{ component('date', {date: user.createdAt}) }}
+ -
+
+ {{ user.createdAt|format_date('short', '', null, 'gregorian', mbin_lang()) }}
+
-
{%- set TYPE_ENTRY = constant('App\\Repository\\ReputationRepository::TYPE_ENTRY') -%}
diff --git a/translations/messages.en.yaml b/translations/messages.en.yaml
index ff6e41092..9105a67ec 100644
--- a/translations/messages.en.yaml
+++ b/translations/messages.en.yaml
@@ -824,5 +824,6 @@ related_entry: Related
restrict_magazine_creation: Restrict local magazine creation to admins and global mods
sso_show_first: Show SSO first on login and registration pages
continue_with: Continue with
+cake_day: Cake day
magazine_log_mod_added: has added a moderator
magazine_log_mod_removed: has removed a moderator
From 5f2a374f7b07e82eb7d0e3b2db2a4a9bab352817 Mon Sep 17 00:00:00 2001
From: BentiGorlich
Date: Fri, 14 Jun 2024 10:33:06 +0200
Subject: [PATCH 2/3] use a magazine's published field - set the `createdAt`
field to a magazine's `published` field when updating them. We already expose
that field
---
src/Service/ActivityPubManager.php | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/src/Service/ActivityPubManager.php b/src/Service/ActivityPubManager.php
index 32073e078..0216811bc 100644
--- a/src/Service/ActivityPubManager.php
+++ b/src/Service/ActivityPubManager.php
@@ -473,6 +473,16 @@ public function updateMagazine(string $actorUrl): ?Magazine
$magazine->title = $actor['preferredUsername'];
}
+ if (isset($actor['published'])) {
+ try {
+ $createdAt = new \DateTimeImmutable($actor['published']);
+ $now = new \DateTimeImmutable();
+ if ($createdAt < $now) {
+ $magazine->createdAt = $createdAt;
+ }
+ } catch (\Exception) {}
+ }
+
$magazine->apInboxUrl = $actor['endpoints']['sharedInbox'] ?? $actor['inbox'];
$magazine->apDomain = parse_url($actor['id'], PHP_URL_HOST);
$magazine->apFollowersUrl = $actor['followers'] ?? null;
From c21990bbd158fb15316845aecc4620a27f7d87bb Mon Sep 17 00:00:00 2001
From: BentiGorlich
Date: Fri, 14 Jun 2024 13:17:06 +0200
Subject: [PATCH 3/3] Fix linter
---
src/Service/ActivityPubManager.php | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/Service/ActivityPubManager.php b/src/Service/ActivityPubManager.php
index 0216811bc..bb1b2a60d 100644
--- a/src/Service/ActivityPubManager.php
+++ b/src/Service/ActivityPubManager.php
@@ -337,7 +337,8 @@ public function updateUser(string $actorUrl): ?User
if ($createdAt < $now) {
$user->createdAt = $createdAt;
}
- } catch (\Exception) {}
+ } catch (\Exception) {
+ }
}
// Only update about when summary is set
@@ -480,7 +481,8 @@ public function updateMagazine(string $actorUrl): ?Magazine
if ($createdAt < $now) {
$magazine->createdAt = $createdAt;
}
- } catch (\Exception) {}
+ } catch (\Exception) {
+ }
}
$magazine->apInboxUrl = $actor['endpoints']['sharedInbox'] ?? $actor['inbox'];