-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
fix(CalDAV): imip set language per user #55473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
| use OCP\IConfig; | ||
| use OCP\IDBConnection; | ||
| use OCP\IL10N; | ||
| use OCP\IUserManager; | ||
| use OCP\L10N\IFactory as L10NFactory; | ||
| use OCP\Mail\IEMailTemplate; | ||
| use OCP\Security\ISecureRandom; | ||
|
|
@@ -44,6 +45,7 @@ public function __construct( | |
| private ISecureRandom $random, | ||
| private L10NFactory $l10nFactory, | ||
| private ITimeFactory $timeFactory, | ||
| private readonly IUserManager $userManager, | ||
| ) { | ||
| $language = $this->l10nFactory->findGenericLanguage(); | ||
| $locale = $this->l10nFactory->findLocale($language); | ||
|
|
@@ -870,18 +872,35 @@ public function getLastOccurrence(VCalendar $vObject) { | |
| } | ||
|
|
||
| /** | ||
| * @param Property|null $attendee | ||
| * @param Property $attendee | ||
| */ | ||
| public function setL10n(?Property $attendee = null) { | ||
| if ($attendee === null) { | ||
| return; | ||
| public function setL10nFromAttendee(Property $attendee) { | ||
| $language = null; | ||
| $locale = null; | ||
| // check if the attendee is a system user | ||
| $userAddress = $attendee->getValue(); | ||
| if (str_starts_with($userAddress, 'mailto:')) { | ||
| $userAddress = substr($userAddress, 7); | ||
| } | ||
|
|
||
| $lang = $attendee->offsetGet('LANGUAGE'); | ||
| if ($lang instanceof Parameter) { | ||
| $lang = $lang->getValue(); | ||
| $this->l10n = $this->l10nFactory->get('dav', $lang); | ||
| $users = $this->userManager->getByEmail($userAddress); | ||
| if ($users !== []) { | ||
| $user = array_shift($users); | ||
| $language = $this->config->getUserValue($user->getUID(), 'core', 'lang', null); | ||
| $locale = $this->config->getUserValue($user->getUID(), 'core', 'locale', null); | ||
| } | ||
| // fallback to attendee LANGUAGE parameter if language not set | ||
| if ($language === null && isset($attendee['LANGUAGE']) && $attendee['LANGUAGE'] instanceof Parameter) { | ||
| $language = $attendee['LANGUAGE']->getValue(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi, We will address this in a separate PR, the L10n should automatically determine the format and pick the correct language
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a ticket/PR for that @SebastianKrupinski?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ticket: #56624 |
||
| } | ||
| // fallback to system language if language not set | ||
| if ($language === null) { | ||
| $language = $this->l10nFactory->findGenericLanguage(); | ||
| } | ||
| // fallback to system locale if locale not set | ||
| if ($locale === null) { | ||
| $locale = $this->l10nFactory->findLocale($language); | ||
| } | ||
| $this->l10n = $this->l10nFactory->get('dav', $language, $locale); | ||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IDE is giving me some warnings about $attendee might be null. Could we maybe wrap every code that depends on $attendee != null in a if block? That would make it easier to understand the whole flow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears that we are initializing
$this->l10nin the constructor with the defaults. Could we change setL10n to setL10nByAttendeed and make $attendeed not nullable and check if not null one level above?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SebastianKrupinski ^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I've made the attendee property a required one.