diff options
author | Morris Jobke <hey@morrisjobke.de> | 2016-10-26 14:02:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-26 14:02:49 +0200 |
commit | cde7f535bd9fd95325545a68e4c0e8926b726a2e (patch) | |
tree | 94a1525dd139de54e5e6db6534ed0aefe5435766 /apps/dav | |
parent | b358b4eebc5079416c9cb437ff54705686cb215c (diff) | |
parent | b12b52b73bb225c29f4009f9b9095cacc093ea7e (diff) | |
download | nextcloud-server-cde7f535bd9fd95325545a68e4c0e8926b726a2e.tar.gz nextcloud-server-cde7f535bd9fd95325545a68e4c0e8926b726a2e.zip |
Merge pull request #1738 from nextcloud/comments-provide-displaynames-with-mentions
comment mentions: show displayname not uid
Diffstat (limited to 'apps/dav')
-rw-r--r-- | apps/dav/lib/Comments/CommentNode.php | 44 | ||||
-rw-r--r-- | apps/dav/tests/unit/Comments/CommentsNodeTest.php | 34 |
2 files changed, 77 insertions, 1 deletions
diff --git a/apps/dav/lib/Comments/CommentNode.php b/apps/dav/lib/Comments/CommentNode.php index f247921be79..1fa8e057b99 100644 --- a/apps/dav/lib/Comments/CommentNode.php +++ b/apps/dav/lib/Comments/CommentNode.php @@ -41,6 +41,11 @@ class CommentNode implements \Sabre\DAV\INode, \Sabre\DAV\IProperties { const PROPERTY_NAME_UNREAD = '{http://owncloud.org/ns}isUnread'; const PROPERTY_NAME_MESSAGE = '{http://owncloud.org/ns}message'; const PROPERTY_NAME_ACTOR_DISPLAYNAME = '{http://owncloud.org/ns}actorDisplayName'; + const PROPERTY_NAME_MENTIONS = '{http://owncloud.org/ns}mentions'; + const PROPERTY_NAME_MENTION = '{http://owncloud.org/ns}mention'; + const PROPERTY_NAME_MENTION_TYPE = '{http://owncloud.org/ns}mentionType'; + const PROPERTY_NAME_MENTION_ID = '{http://owncloud.org/ns}mentionId'; + const PROPERTY_NAME_MENTION_DISPLAYNAME = '{http://owncloud.org/ns}mentionDisplayName'; /** @var IComment */ public $comment; @@ -85,6 +90,9 @@ class CommentNode implements \Sabre\DAV\INode, \Sabre\DAV\IProperties { return strpos($name, 'get') === 0; }); foreach($methods as $getter) { + if($getter === 'getMentions') { + continue; // special treatment + } $name = '{'.self::NS_OWNCLOUD.'}' . lcfirst(substr($getter, 3)); $this->properties[$name] = $getter; } @@ -113,7 +121,12 @@ class CommentNode implements \Sabre\DAV\INode, \Sabre\DAV\IProperties { // re-used property names are defined as constants self::PROPERTY_NAME_MESSAGE, self::PROPERTY_NAME_ACTOR_DISPLAYNAME, - self::PROPERTY_NAME_UNREAD + self::PROPERTY_NAME_UNREAD, + self::PROPERTY_NAME_MENTIONS, + self::PROPERTY_NAME_MENTION, + self::PROPERTY_NAME_MENTION_TYPE, + self::PROPERTY_NAME_MENTION_ID, + self::PROPERTY_NAME_MENTION_DISPLAYNAME, ]; } @@ -240,6 +253,8 @@ class CommentNode implements \Sabre\DAV\INode, \Sabre\DAV\IProperties { $result[self::PROPERTY_NAME_ACTOR_DISPLAYNAME] = $displayName; } + $result[self::PROPERTY_NAME_MENTIONS] = $this->composeMentionsPropertyValue(); + $unread = null; $user = $this->userSession->getUser(); if(!is_null($user)) { @@ -260,4 +275,31 @@ class CommentNode implements \Sabre\DAV\INode, \Sabre\DAV\IProperties { return $result; } + + /** + * transforms a mentions array as returned from IComment->getMentions to an + * array with DAV-compatible structure that can be assigned to the + * PROPERTY_NAME_MENTION property. + * + * @return array + */ + protected function composeMentionsPropertyValue() { + return array_map(function($mention) { + try { + $displayName = $this->commentsManager->resolveDisplayName($mention['type'], $mention['id']); + } catch (\OutOfBoundsException $e) { + $this->logger->logException($e); + // No displayname, upon client's discretion what to display. + $displayName = ''; + } + + return [ + self::PROPERTY_NAME_MENTION => [ + self::PROPERTY_NAME_MENTION_TYPE => $mention['type'], + self::PROPERTY_NAME_MENTION_ID => $mention['id'], + self::PROPERTY_NAME_MENTION_DISPLAYNAME => $displayName, + ] + ]; + }, $this->comment->getMentions()); + } } diff --git a/apps/dav/tests/unit/Comments/CommentsNodeTest.php b/apps/dav/tests/unit/Comments/CommentsNodeTest.php index 1c7bd782496..94eaea01d56 100644 --- a/apps/dav/tests/unit/Comments/CommentsNodeTest.php +++ b/apps/dav/tests/unit/Comments/CommentsNodeTest.php @@ -27,11 +27,14 @@ namespace OCA\DAV\Tests\unit\Comments; use OCA\DAV\Comments\CommentNode; use OCP\Comments\IComment; +use OCP\Comments\ICommentsManager; use OCP\Comments\MessageTooLongException; class CommentsNodeTest extends \Test\TestCase { + /** @var ICommentsManager|\PHPUnit_Framework_MockObject_MockObject */ protected $commentsManager; + protected $comment; protected $node; protected $userManager; @@ -373,6 +376,18 @@ class CommentsNodeTest extends \Test\TestCase { $ns . 'topmostParentId' => '2', $ns . 'childrenCount' => 3, $ns . 'message' => 'such a nice file you haveā¦', + $ns . 'mentions' => [ + [ $ns . 'mention' => [ + $ns . 'mentionType' => 'user', + $ns . 'mentionId' => 'alice', + $ns . 'mentionDisplayName' => 'Alice Al-Isson', + ] ], + [ $ns . 'mention' => [ + $ns . 'mentionType' => 'user', + $ns . 'mentionId' => 'bob', + $ns . 'mentionDisplayName' => 'Unknown user', + ] ], + ], $ns . 'verb' => 'comment', $ns . 'actorType' => 'users', $ns . 'actorId' => 'alice', @@ -384,6 +399,14 @@ class CommentsNodeTest extends \Test\TestCase { $ns . 'isUnread' => null, ]; + $this->commentsManager->expects($this->exactly(2)) + ->method('resolveDisplayName') + ->withConsecutive( + [$this->equalTo('user'), $this->equalTo('alice')], + [$this->equalTo('user'), $this->equalTo('bob')] + ) + ->willReturnOnConsecutiveCalls('Alice Al-Isson', 'Unknown user'); + $this->comment->expects($this->once()) ->method('getId') ->will($this->returnValue($expected[$ns . 'id'])); @@ -405,6 +428,13 @@ class CommentsNodeTest extends \Test\TestCase { ->will($this->returnValue($expected[$ns . 'message'])); $this->comment->expects($this->once()) + ->method('getMentions') + ->willReturn([ + ['type' => 'user', 'id' => 'alice'], + ['type' => 'user', 'id' => 'bob'], + ]); + + $this->comment->expects($this->once()) ->method('getVerb') ->will($this->returnValue($expected[$ns . 'verb'])); @@ -475,6 +505,10 @@ class CommentsNodeTest extends \Test\TestCase { ->method('getCreationDateTime') ->will($this->returnValue($creationDT)); + $this->comment->expects($this->any()) + ->method('getMentions') + ->willReturn([]); + $this->commentsManager->expects($this->once()) ->method('getReadMark') ->will($this->returnValue($readDT)); |