summaryrefslogtreecommitdiffstats
path: root/apps/dav
diff options
context:
space:
mode:
authorGeorg Ehrke <developer@georgehrke.com>2018-11-27 18:41:40 +0100
committerGeorg Ehrke <developer@georgehrke.com>2019-02-16 13:25:08 +0100
commit58520209be38b45438163fe32ef8089ce1bfaa6d (patch)
tree391e53afb09d75f8101ed334b2175df0e2a7f990 /apps/dav
parent9d0ce129702f69dfc26429b833079cccc4faaf8c (diff)
downloadnextcloud-server-58520209be38b45438163fe32ef8089ce1bfaa6d.tar.gz
nextcloud-server-58520209be38b45438163fe32ef8089ce1bfaa6d.zip
unicode all the birthday icons
Signed-off-by: Georg Ehrke <developer@georgehrke.com>
Diffstat (limited to 'apps/dav')
-rw-r--r--apps/dav/lib/CalDAV/BirthdayService.php33
-rw-r--r--apps/dav/tests/unit/CardDAV/BirthdayServiceTest.php53
2 files changed, 57 insertions, 29 deletions
diff --git a/apps/dav/lib/CalDAV/BirthdayService.php b/apps/dav/lib/CalDAV/BirthdayService.php
index 9629a62e7c0..25cf19b460d 100644
--- a/apps/dav/lib/CalDAV/BirthdayService.php
+++ b/apps/dav/lib/CalDAV/BirthdayService.php
@@ -32,6 +32,7 @@ use Exception;
use OCA\DAV\CardDAV\CardDavBackend;
use OCA\DAV\DAV\GroupPrincipalBackend;
use OCP\IConfig;
+use OCP\IDBConnection;
use Sabre\VObject\Component\VCalendar;
use Sabre\VObject\Component\VCard;
use Sabre\VObject\DateTimeParser;
@@ -56,6 +57,9 @@ class BirthdayService {
/** @var IConfig */
private $config;
+ /** @var IDBConnection */
+ private $dbConnection;
+
/**
* BirthdayService constructor.
*
@@ -64,11 +68,12 @@ class BirthdayService {
* @param GroupPrincipalBackend $principalBackend
* @param IConfig $config;
*/
- public function __construct(CalDavBackend $calDavBackEnd, CardDavBackend $cardDavBackEnd, GroupPrincipalBackend $principalBackend, IConfig $config) {
+ public function __construct(CalDavBackend $calDavBackEnd, CardDavBackend $cardDavBackEnd, GroupPrincipalBackend $principalBackend, IConfig $config, IDBConnection $dbConnection) {
$this->calDavBackEnd = $calDavBackEnd;
$this->cardDavBackEnd = $cardDavBackEnd;
$this->principalBackend = $principalBackend;
$this->config = $config;
+ $this->dbConnection = $dbConnection;
}
/**
@@ -85,9 +90,9 @@ class BirthdayService {
$book = $this->cardDavBackEnd->getAddressBookById($addressBookId);
$targetPrincipals[] = $book['principaluri'];
$datesToSync = [
- ['postfix' => '', 'field' => 'BDAY', 'symbol' => '*'],
- ['postfix' => '-death', 'field' => 'DEATHDATE', 'symbol' => "†"],
- ['postfix' => '-anniversary', 'field' => 'ANNIVERSARY', 'symbol' => "⚭"],
+ ['postfix' => '', 'field' => 'BDAY', 'symbol' => '*', 'utfSymbol' => '🎂'],
+ ['postfix' => '-death', 'field' => 'DEATHDATE', 'symbol' => "†", 'utfSymbol' => '⚰️'],
+ ['postfix' => '-anniversary', 'field' => 'ANNIVERSARY', 'symbol' => "⚭", 'utfSymbol' => '💍'],
];
foreach ($targetPrincipals as $principalUri) {
if (!$this->isUserEnabled($principalUri)) {
@@ -150,9 +155,10 @@ class BirthdayService {
* @param string $dateField
* @param string $postfix
* @param string $summarySymbol
+ * @param string $utfSummarySymbol
* @return null|VCalendar
*/
- public function buildDateFromContact($cardData, $dateField, $postfix, $summarySymbol) {
+ public function buildDateFromContact($cardData, $dateField, $postfix, $summarySymbol, $utfSummarySymbol) {
if (empty($cardData)) {
return null;
}
@@ -218,11 +224,20 @@ class BirthdayService {
} catch (Exception $e) {
return null;
}
- if ($unknownYear) {
- $summary = $doc->FN->getValue() . ' ' . $summarySymbol;
+ if ($this->dbConnection->supports4ByteText()) {
+ if ($unknownYear) {
+ $summary = $utfSummarySymbol . ' ' . $doc->FN->getValue();
+ } else {
+ $summary = $utfSummarySymbol . ' ' . $doc->FN->getValue() . " ($originalYear)";
+ }
} else {
- $summary = $doc->FN->getValue() . " ($summarySymbol$originalYear)";
+ if ($unknownYear) {
+ $summary = $doc->FN->getValue() . ' ' . $summarySymbol;
+ } else {
+ $summary = $doc->FN->getValue() . " ($summarySymbol$originalYear)";
+ }
}
+
$vCal = new VCalendar();
$vCal->VERSION = '2.0';
$vEvent = $vCal->createComponent('VEVENT');
@@ -318,7 +333,7 @@ class BirthdayService {
*/
private function updateCalendar($cardUri, $cardData, $book, $calendarId, $type) {
$objectUri = $book['uri'] . '-' . $cardUri . $type['postfix'] . '.ics';
- $calendarData = $this->buildDateFromContact($cardData, $type['field'], $type['postfix'], $type['symbol']);
+ $calendarData = $this->buildDateFromContact($cardData, $type['field'], $type['postfix'], $type['symbol'], $type['utfSymbol']);
$existing = $this->calDavBackEnd->getCalendarObject($calendarId, $objectUri);
if (is_null($calendarData)) {
if (!is_null($existing)) {
diff --git a/apps/dav/tests/unit/CardDAV/BirthdayServiceTest.php b/apps/dav/tests/unit/CardDAV/BirthdayServiceTest.php
index 3461c4af3b6..9587640386f 100644
--- a/apps/dav/tests/unit/CardDAV/BirthdayServiceTest.php
+++ b/apps/dav/tests/unit/CardDAV/BirthdayServiceTest.php
@@ -29,6 +29,7 @@ use OCA\DAV\CalDAV\CalDavBackend;
use OCA\DAV\CardDAV\CardDavBackend;
use OCA\DAV\DAV\GroupPrincipalBackend;
use OCP\IConfig;
+use OCP\IDBConnection;
use Sabre\VObject\Component\VCalendar;
use Sabre\VObject\Reader;
use Test\TestCase;
@@ -45,6 +46,8 @@ class BirthdayServiceTest extends TestCase {
private $groupPrincipalBackend;
/** @var IConfig | \PHPUnit_Framework_MockObject_MockObject */
private $config;
+ /** @var IDBConnection | \PHPUnit_Framework_MockObject_MockObject */
+ private $dbConnection;
public function setUp() {
parent::setUp();
@@ -53,9 +56,10 @@ class BirthdayServiceTest extends TestCase {
$this->cardDav = $this->createMock(CardDavBackend::class);
$this->groupPrincipalBackend = $this->createMock(GroupPrincipalBackend::class);
$this->config = $this->createMock(IConfig::class);
+ $this->dbConnection = $this->createMock(IDBConnection::class);
$this->service = new BirthdayService($this->calDav, $this->cardDav,
- $this->groupPrincipalBackend, $this->config);
+ $this->groupPrincipalBackend, $this->config, $this->dbConnection);
}
/**
@@ -67,8 +71,10 @@ class BirthdayServiceTest extends TestCase {
* @param string $expectedOriginalYear
* @param string | null $data
*/
- public function testBuildBirthdayFromContact($expectedSummary, $expectedDTStart, $expectedFieldType, $expectedUnknownYear, $expectedOriginalYear, $data) {
- $cal = $this->service->buildDateFromContact($data, 'BDAY', '', '*');
+ public function testBuildBirthdayFromContact($expectedSummary, $expectedDTStart, $expectedFieldType, $expectedUnknownYear, $expectedOriginalYear, $data, $supports4Bytes) {
+ $this->dbConnection->method('supports4ByteText')->willReturn($supports4Bytes);
+ $cal = $this->service->buildDateFromContact($data, 'BDAY', '', '*', '🎂');
+
if ($expectedSummary === null) {
$this->assertNull($cal);
} else {
@@ -163,7 +169,7 @@ class BirthdayServiceTest extends TestCase {
$service = $this->getMockBuilder(BirthdayService::class)
->setMethods(['buildDateFromContact', 'birthdayEvenChanged'])
- ->setConstructorArgs([$this->calDav, $this->cardDav, $this->groupPrincipalBackend, $this->config])
+ ->setConstructorArgs([$this->calDav, $this->cardDav, $this->groupPrincipalBackend, $this->config, $this->dbConnection])
->getMock();
$service->onCardChanged(666, 'gump.vcf', '');
@@ -192,7 +198,7 @@ class BirthdayServiceTest extends TestCase {
/** @var BirthdayService | \PHPUnit_Framework_MockObject_MockObject $service */
$service = $this->getMockBuilder(BirthdayService::class)
->setMethods(['buildDateFromContact', 'birthdayEvenChanged'])
- ->setConstructorArgs([$this->calDav, $this->cardDav, $this->groupPrincipalBackend, $this->config])
+ ->setConstructorArgs([$this->calDav, $this->cardDav, $this->groupPrincipalBackend, $this->config, $this->dbConnection])
->getMock();
$service->onCardChanged(666, 'gump.vcf', '');
@@ -228,7 +234,7 @@ class BirthdayServiceTest extends TestCase {
/** @var BirthdayService | \PHPUnit_Framework_MockObject_MockObject $service */
$service = $this->getMockBuilder(BirthdayService::class)
->setMethods(['buildDateFromContact', 'birthdayEvenChanged'])
- ->setConstructorArgs([$this->calDav, $this->cardDav, $this->groupPrincipalBackend, $this->config])
+ ->setConstructorArgs([$this->calDav, $this->cardDav, $this->groupPrincipalBackend, $this->config, $this->dbConnection])
->getMock();
if ($expectedOp === 'delete') {
@@ -350,20 +356,27 @@ class BirthdayServiceTest extends TestCase {
public function providesVCards() {
return [
- // $expectedSummary, $expectedDTStart, $expectedFieldType, $expectedUnknownYear, $expectedOriginalYear, $data
- [null, null, null, null, null, null],
- [null, null, null, null, null, ''],
- [null, null, null, null, null, 'yasfewf'],
- [null, null, null, null, null, "BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nUID:12345\r\nFN:12345\r\nN:12345;;;;\r\nEND:VCARD\r\n", "Dr. Foo Bar"],
- [null, null, null, null, null, "BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nUID:12345\r\nFN:12345\r\nN:12345;;;;\r\nBDAY:\r\nEND:VCARD\r\n", "Dr. Foo Bar"],
- [null, null, null, null, null, "BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nUID:12345\r\nFN:12345\r\nN:12345;;;;\r\nBDAY:someday\r\nEND:VCARD\r\n", "Dr. Foo Bar"],
- ['12345 (*1900)', '19700101', 'BDAY', '0', '1900', "BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nUID:12345\r\nFN:12345\r\nN:12345;;;;\r\nBDAY:19000101\r\nEND:VCARD\r\n", "Dr. Foo Bar"],
- ['12345 (*1900)', '19701231', 'BDAY', '0', '1900', "BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nUID:12345\r\nFN:12345\r\nN:12345;;;;\r\nBDAY:19001231\r\nEND:VCARD\r\n", "Dr. Foo Bar"],
- ['12345 *', '19701231', 'BDAY', '1', null, "BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nUID:12345\r\nFN:12345\r\nN:12345;;;;\r\nBDAY:--1231\r\nEND:VCARD\r\n", "Dr. Foo Bar"],
- ['12345 *', '19701231', 'BDAY', '1', null, "BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nUID:12345\r\nFN:12345\r\nN:12345;;;;\r\nBDAY;X-APPLE-OMIT-YEAR=1604:16041231\r\nEND:VCARD\r\n", "Dr. Foo Bar"],
- [null, null, null, null, null, "BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nUID:12345\r\nFN:12345\r\nN:12345;;;;\r\nBDAY:;VALUE=text:circa 1800\r\nEND:VCARD\r\n", "Dr. Foo Bar"],
- [null, null, null, null, null, "BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nUID:12345\r\nN:12345;;;;\r\nBDAY:20031231\r\nEND:VCARD\r\n", "Dr. Foo Bar"],
- ['12345 (*900)', '19701231', 'BDAY', '0', '900', "BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nUID:12345\r\nFN:12345\r\nN:12345;;;;\r\nBDAY:09001231\r\nEND:VCARD\r\n", "Dr. Foo Bar"],
+ // $expectedSummary, $expectedDTStart, $expectedFieldType, $expectedUnknownYear, $expectedOriginalYear, $data, $supports4Byte
+ [null, null, null, null, null, null, true],
+ [null, null, null, null, null, '', true],
+ [null, null, null, null, null, 'yasfewf', true],
+ [null, null, null, null, null, "BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nUID:12345\r\nFN:12345\r\nN:12345;;;;\r\nEND:VCARD\r\n", true],
+ [null, null, null, null, null, "BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nUID:12345\r\nFN:12345\r\nN:12345;;;;\r\nBDAY:\r\nEND:VCARD\r\n", true],
+ [null, null, null, null, null, "BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nUID:12345\r\nFN:12345\r\nN:12345;;;;\r\nBDAY:someday\r\nEND:VCARD\r\n", true],
+ ['🎂 12345 (1900)', '19700101', 'BDAY', '0', '1900', "BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nUID:12345\r\nFN:12345\r\nN:12345;;;;\r\nBDAY:19000101\r\nEND:VCARD\r\n", true],
+ ['🎂 12345 (1900)', '19701231', 'BDAY', '0', '1900', "BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nUID:12345\r\nFN:12345\r\nN:12345;;;;\r\nBDAY:19001231\r\nEND:VCARD\r\n", true],
+ ['🎂 12345', '19701231', 'BDAY', '1', null, "BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nUID:12345\r\nFN:12345\r\nN:12345;;;;\r\nBDAY:--1231\r\nEND:VCARD\r\n", true],
+ ['🎂 12345', '19701231', 'BDAY', '1', null, "BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nUID:12345\r\nFN:12345\r\nN:12345;;;;\r\nBDAY;X-APPLE-OMIT-YEAR=1604:16041231\r\nEND:VCARD\r\n", true],
+ [null, null, null, null, null, "BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nUID:12345\r\nFN:12345\r\nN:12345;;;;\r\nBDAY:;VALUE=text:circa 1800\r\nEND:VCARD\r\n", true],
+ [null, null, null, null, null, "BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nUID:12345\r\nN:12345;;;;\r\nBDAY:20031231\r\nEND:VCARD\r\n", true],
+ ['🎂 12345 (900)', '19701231', 'BDAY', '0', '900', "BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nUID:12345\r\nFN:12345\r\nN:12345;;;;\r\nBDAY:09001231\r\nEND:VCARD\r\n", true],
+ ['12345 (*1900)', '19700101', 'BDAY', '0', '1900', "BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nUID:12345\r\nFN:12345\r\nN:12345;;;;\r\nBDAY:19000101\r\nEND:VCARD\r\n", false],
+ ['12345 (*1900)', '19701231', 'BDAY', '0', '1900', "BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nUID:12345\r\nFN:12345\r\nN:12345;;;;\r\nBDAY:19001231\r\nEND:VCARD\r\n", false],
+ ['12345 *', '19701231', 'BDAY', '1', null, "BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nUID:12345\r\nFN:12345\r\nN:12345;;;;\r\nBDAY:--1231\r\nEND:VCARD\r\n", false],
+ ['12345 *', '19701231', 'BDAY', '1', null, "BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nUID:12345\r\nFN:12345\r\nN:12345;;;;\r\nBDAY;X-APPLE-OMIT-YEAR=1604:16041231\r\nEND:VCARD\r\n", false],
+ [null, null, null, null, null, "BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nUID:12345\r\nFN:12345\r\nN:12345;;;;\r\nBDAY:;VALUE=text:circa 1800\r\nEND:VCARD\r\n", false],
+ [null, null, null, null, null, "BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nUID:12345\r\nN:12345;;;;\r\nBDAY:20031231\r\nEND:VCARD\r\n", false],
+ ['12345 (*900)', '19701231', 'BDAY', '0', '900', "BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nUID:12345\r\nFN:12345\r\nN:12345;;;;\r\nBDAY:09001231\r\nEND:VCARD\r\n", false],
];
}
}