1<?php 2 3declare(strict_types=1); 4 5/** 6 * @copyright 2021 Christopher Ng <chrng8@gmail.com> 7 * 8 * @author Christopher Ng <chrng8@gmail.com> 9 * 10 * @license GNU AGPL version 3 or any later version 11 * 12 * This program is free software: you can redistribute it and/or modify 13 * it under the terms of the GNU Affero General Public License as 14 * published by the Free Software Foundation, either version 3 of the 15 * License, or (at your option) any later version. 16 * 17 * This program is distributed in the hope that it will be useful, 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 * GNU Affero General Public License for more details. 21 * 22 * You should have received a copy of the GNU Affero General Public License 23 * along with this program. If not, see <http://www.gnu.org/licenses/>. 24 * 25 */ 26 27namespace OC\Profile\Actions; 28 29use OCP\Accounts\IAccountManager; 30use OCP\IURLGenerator; 31use OCP\IUser; 32use OCP\L10N\IFactory; 33use OCP\Profile\ILinkAction; 34 35class EmailAction implements ILinkAction { 36 37 /** @var string */ 38 private $value; 39 40 /** @var IAccountManager */ 41 private $accountManager; 42 43 /** @var IFactory */ 44 private $l10nFactory; 45 46 /** @var IUrlGenerator */ 47 private $urlGenerator; 48 49 public function __construct( 50 IAccountManager $accountManager, 51 IFactory $l10nFactory, 52 IURLGenerator $urlGenerator 53 ) { 54 $this->accountManager = $accountManager; 55 $this->l10nFactory = $l10nFactory; 56 $this->urlGenerator = $urlGenerator; 57 } 58 59 public function preload(IUser $targetUser): void { 60 $account = $this->accountManager->getAccount($targetUser); 61 $this->value = $account->getProperty(IAccountManager::PROPERTY_EMAIL)->getValue(); 62 } 63 64 public function getAppId(): string { 65 return 'core'; 66 } 67 68 public function getId(): string { 69 return IAccountManager::PROPERTY_EMAIL; 70 } 71 72 public function getDisplayId(): string { 73 return $this->l10nFactory->get('core')->t('Email'); 74 } 75 76 public function getTitle(): string { 77 return $this->l10nFactory->get('core')->t('Mail %s', [$this->value]); 78 } 79 80 public function getPriority(): int { 81 return 20; 82 } 83 84 public function getIcon(): string { 85 return $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/mail.svg')); 86 } 87 88 public function getTarget(): ?string { 89 if (empty($this->value)) { 90 return null; 91 } 92 return 'mailto:' . $this->value; 93 } 94} 95