diff options
author | Joas Schilling <coding@schilljs.com> | 2021-06-09 11:56:47 +0300 |
---|---|---|
committer | Marco Ambrosini <marcoambrosini@pm.me> | 2021-06-17 11:35:21 +0300 |
commit | 4fc545ef8cdab592fabd0584ef93389902c2b879 (patch) | |
tree | 361ad865d9d6361c7a845ab3e1b7bbc2fd24a8fb | |
parent | 09ad452bd76bc11af4c04701e1f909e21e3d7d6b (diff) |
Populate some additional contacts data when the file is a vCard
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r-- | lib/Chat/Parser/SystemMessage.php | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/lib/Chat/Parser/SystemMessage.php b/lib/Chat/Parser/SystemMessage.php index ce71303c0..03cf8929f 100644 --- a/lib/Chat/Parser/SystemMessage.php +++ b/lib/Chat/Parser/SystemMessage.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace OCA\Talk\Chat\Parser; +use OCA\DAV\CardDAV\PhotoCache; use OCA\Talk\Exceptions\ParticipantNotFoundException; use OCA\Talk\GuestManager; use OCA\Talk\Model\Attendee; @@ -43,6 +44,7 @@ use OCP\IURLGenerator; use OCP\IUser; use OCP\IUserManager; use OCP\Share\Exceptions\ShareNotFound; +use Sabre\VObject\Reader; class SystemMessage { @@ -56,6 +58,8 @@ class SystemMessage { protected $previewManager; /** @var RoomShareProvider */ protected $shareProvider; + /** @var PhotoCache */ + protected $photoCache; /** @var IRootFolder */ protected $rootFolder; /** @var IURLGenerator */ @@ -75,6 +79,7 @@ class SystemMessage { GuestManager $guestManager, IPreviewManager $previewManager, RoomShareProvider $shareProvider, + PhotoCache $photoCache, IRootFolder $rootFolder, IURLGenerator $url) { $this->userManager = $userManager; @@ -82,6 +87,7 @@ class SystemMessage { $this->guestManager = $guestManager; $this->previewManager = $previewManager; $this->shareProvider = $shareProvider; + $this->photoCache = $photoCache; $this->rootFolder = $rootFolder; $this->url = $url; } @@ -507,7 +513,7 @@ class SystemMessage { ]); } - return [ + $data = [ 'type' => 'file', 'id' => (string) $node->getId(), 'name' => $name, @@ -517,6 +523,23 @@ class SystemMessage { 'mimetype' => $node->getMimeType(), 'preview-available' => $this->previewManager->isAvailable($node) ? 'yes' : 'no', ]; + + if ($node->getMimeType() === 'text/vcard') { + $vCard = $node->getContent(); + + $vObject = Reader::read($vCard); + if (!empty($vObject->FN)) { + $data['contact-name'] = (string) $vObject->FN; + } + + $photo = $this->photoCache->getPhotoFromVObject($vObject); + if ($photo) { + $data['contact-photo-mimetype'] = $photo['Content-Type']; + $data['contact-photo'] = base64_encode($photo['body']); + } + } + + return $data; } protected function getActorFromComment(Room $room, IComment $comment): array { |