Use proper timezone and locale format for due date activities

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2018-12-07 16:33:49 +01:00
Родитель 96dffbfedd
Коммит 1dc68f97c5
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4C614C6ED2CDE6DF
4 изменённых файлов: 41 добавлений и 5 удалений

Просмотреть файл

@ -20,7 +20,7 @@
*
*/
/* global OC OCA OCP t escapeHTML Handlebars */
/* global OC OCA OCP t escapeHTML Handlebars moment */
import CommentCollection from '../legacy/commentcollection';
import CommentModel from '../legacy/commentmodel';
@ -279,7 +279,13 @@ class ActivityController {
return this.activityservice.getData(this.type, id);
}
parseMessage(subject, parameters) {
parseMessage(activity) {
let subject = activity.subject_rich[0];
let parameters = activity.subject_rich[1];
if (parameters.after && parameters.after.id && parameters.after.id.startsWith('dt:')) {
let dateTime = parameters.after.id.substr(3);
parameters.after.name = moment(dateTime).format('L LTS');
}
return OCA.Activity.RichObjectStringParser.parseMessage(subject, parameters);
}

Просмотреть файл

@ -31,8 +31,10 @@ use OCP\Activity\IProvider;
use OCP\Comments\IComment;
use OCP\Comments\ICommentsManager;
use OCP\Comments\NotFoundException;
use OCP\IConfig;
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\L10N\IFactory;
class DeckProvider implements IProvider {
@ -46,13 +48,19 @@ class DeckProvider implements IProvider {
private $userManager;
/** @var ICommentsManager */
private $commentsManager;
/** @var IFactory */
private $l10nFactory;
/** @var IConfig */
private $config;
public function __construct(IURLGenerator $urlGenerator, ActivityManager $activityManager, IUserManager $userManager, ICommentsManager $commentsManager, $userId) {
public function __construct(IURLGenerator $urlGenerator, ActivityManager $activityManager, IUserManager $userManager, ICommentsManager $commentsManager, IFactory $l10n, IConfig $config, $userId) {
$this->userId = $userId;
$this->urlGenerator = $urlGenerator;
$this->activityManager = $activityManager;
$this->commentsManager = $commentsManager;
$this->userManager = $userManager;
$this->l10nFactory = $l10n;
$this->config = $config;
}
/**
@ -94,6 +102,7 @@ class DeckProvider implements IProvider {
'name' => $user !== null ? $user->getDisplayName() : $author
],
];
$event->setAuthor($author);
if ($event->getObjectType() === ActivityManager::DECK_OBJECT_BOARD) {
if ($event->getObjectName() === '') {
$event->setObject($event->getObjectType(), $event->getObjectId(), $subjectParams['board']['title']);
@ -133,6 +142,7 @@ class DeckProvider implements IProvider {
$params = $this->parseParamForAcl($subjectParams, $params);
$params = $this->parseParamForChanges($subjectParams, $params, $event);
$params = $this->parseParamForComment($subjectParams, $params, $event);
$params = $this->parseParamForDuedate($subjectParams, $params, $event);
try {
$subject = $this->activityManager->getActivityFormat($subjectIdentifier, $subjectParams, $ownActivity);
@ -279,6 +289,22 @@ class DeckProvider implements IProvider {
return $params;
}
private function parseParamForDuedate($subjectParams, $params, IEvent $event) {
if (array_key_exists('after', $subjectParams) && $event->getSubject() === ActivityManager::SUBJECT_CARD_UPDATE_DUEDATE) {
$userLanguage = $this->config->getUserValue($event->getAuthor(), 'core', 'lang', $this->l10nFactory->findLanguage());
$userLocale = $this->config->getUserValue($event->getAuthor(), 'core', 'locale', $this->l10nFactory->findLocale());
$l10n = $this->l10nFactory->get('deck', $userLanguage, $userLocale);
$date = new \DateTime($subjectParams['after']);
$date->setTimezone(new \DateTimeZone(\date_default_timezone_get()));
$params['after'] = [
'type' => 'highlight',
'id' => 'dt:' . $subjectParams['after'],
'name' => $l10n->l('datetime', $date)
];
}
return $params;
}
/**
* Add diff to message if the subject parameter 'diff' is set, otherwise
* the changed values are added to before/after

Просмотреть файл

@ -20,7 +20,7 @@
</div>
<span class="activitytime has-tooltip live-relative-timestamp"
data-timestamp="{{ activity.timestamp }}">{{ activity.timestamp/1000 | relativeDateFilter }}</span>
<div class="activitysubject" ng-if="!activity.commentModel" bind-html-compile="$ctrl.parseMessage(activity.subject_rich[0], activity.subject_rich[1])"></div>
<div class="activitysubject" ng-if="!activity.commentModel" bind-html-compile="$ctrl.parseMessage(activity)"></div>
<div class="activitysubject commentAuthor" ng-if="activity.commentModel">
{{ activity.subject_rich[1].user.name }}
<div class="app-popover-menu-utils">

Просмотреть файл

@ -28,10 +28,12 @@ use OCA\Deck\Db\Acl;
use OCP\Activity\IEvent;
use OCP\Comments\IComment;
use OCP\Comments\ICommentsManager;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserManager;
use OCP\L10N\IFactory;
use OCP\RichObjectStrings\IValidator;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
@ -62,7 +64,9 @@ class DeckProviderTest extends TestCase {
$this->activityManager = $this->createMock(ActivityManager::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->commentsManager = $this->createMock(ICommentsManager::class);
$this->provider = new DeckProvider($this->urlGenerator, $this->activityManager, $this->userManager, $this->commentsManager, $this->userId);
$this->l10nFactory = $this->createMock(IFactory::class);
$this->config = $this->createMock(IConfig::class);
$this->provider = new DeckProvider($this->urlGenerator, $this->activityManager, $this->userManager, $this->commentsManager, $this->l10nFactory, $this->config, $this->userId);
}
private function mockEvent($objectType, $objectId, $objectName, $subject, $subjectParameters = []) {