Skip to content

Commit

Permalink
Add appName to contactsmenu action API
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed Oct 18, 2021
1 parent 1e9ca81 commit 8b809b6
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 7 deletions.
9 changes: 6 additions & 3 deletions lib/private/Contacts/ContactsMenu/ActionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,26 @@ class ActionFactory implements IActionFactory {
* @param string $icon
* @param string $name
* @param string $href
* @param string $appName
* @return ILinkAction
*/
public function newLinkAction($icon, $name, $href) {
public function newLinkAction(string $icon, string $name, string $href, string $appName = ''): ILinkAction {
$action = new LinkAction();
$action->setName($name);
$action->setIcon($icon);
$action->setHref($href);
$action->setAppName($appName);
return $action;
}

/**
* @param string $icon
* @param string $name
* @param string $email
* @param string $appName
* @return ILinkAction
*/
public function newEMailAction($icon, $name, $email) {
return $this->newLinkAction($icon, $name, 'mailto:' . $email);
public function newEMailAction(string $icon, string $name, string $email, string $appName = ''): ILinkAction {
return $this->newLinkAction($icon, $name, 'mailto:' . $email, $appName);
}
}
20 changes: 20 additions & 0 deletions lib/private/Contacts/ContactsMenu/Actions/LinkAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class LinkAction implements ILinkAction {
/** @var int */
private $priority = 10;

/** @var string */
private $appName;

/**
* @param string $icon absolute URI to an icon
*/
Expand Down Expand Up @@ -87,6 +90,22 @@ public function getHref() {
return $this->href;
}

/**
* @param string $appName
* @since 23.0.0
*/
public function setAppName(string $appName) {
$this->appName = $appName;
}

/**
* @return string
* @since 23.0.0
*/
public function getAppName(): string {
return $this->appName;
}

/**
* @return array
*/
Expand All @@ -95,6 +114,7 @@ public function jsonSerialize() {
'title' => $this->name,
'icon' => $this->icon,
'hyperlink' => $this->href,
'appName' => $this->appName,
];
}
}
12 changes: 12 additions & 0 deletions lib/public/Contacts/ContactsMenu/IAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,16 @@ public function setPriority($priority);
* @since 12.0
*/
public function getPriority();

/**
* @param string $appName
* @since 23.0.0
*/
public function setAppName(string $appName);

/**
* @return string
* @since 23.0.0
*/
public function getAppName(): string;
}
10 changes: 6 additions & 4 deletions lib/public/Contacts/ContactsMenu/IActionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ interface IActionFactory {
* @param string $icon full path to the action's icon
* @param string $name localized name of the action
* @param string $href target URL
* @return ILinkAction
* @param string $appName the appName registering the action
* @return IAction
*/
public function newLinkAction($icon, $name, $href);
public function newLinkAction(string $icon, string $name, string $href, string $appName = ''): IAction;

/**
* Construct and return a new email action for the contacts menu
Expand All @@ -47,7 +48,8 @@ public function newLinkAction($icon, $name, $href);
* @param string $icon full path to the action's icon
* @param string $name localized name of the action
* @param string $email target e-mail address
* @return ILinkAction
* @param string $appName the appName registering the action
* @return IAction
*/
public function newEMailAction($icon, $name, $email);
public function newEMailAction(string $icon, string $name, string $email, string $appName = ''): IAction;
}
2 changes: 2 additions & 0 deletions tests/lib/Contacts/ContactsMenu/Actions/LinkActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ public function testJsonSerialize() {
$this->action->setName('Nickie Works');
$this->action->setPriority(33);
$this->action->setHref('example.com');
$this->action->setAppName('contacts');
$expected = [
'title' => 'Nickie Works',
'icon' => 'icon-contacts',
'hyperlink' => 'example.com',
'appName' => 'contacts',
];

$json = $this->action->jsonSerialize();
Expand Down

0 comments on commit 8b809b6

Please sign in to comment.