add priority to instances

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/58/head
Maxence Lange 2018-11-27 15:58:08 -01:00
rodzic bb06cc1063
commit 6210a6ec96
4 zmienionych plików z 93 dodań i 18 usunięć

Wyświetl plik

@ -348,6 +348,14 @@ class CoreRequestBuilder {
}
/**
* @param IQueryBuilder $qb
*/
protected function orderByPriority(IQueryBuilder &$qb) {
$qb->orderBy('priority', 'desc');
}
/**
* @param IQueryBuilder $qb
* @param string $field
@ -474,6 +482,7 @@ class CoreRequestBuilder {
// /** @noinspection PhpMethodParametersCountMismatchInspection */
$qb->selectAlias('ca.id', 'cacheactor_id')
->selectAlias('ca.type', 'cacheactor_type')
->selectAlias('ca.account', 'cacheactor_account')
->selectAlias('ca.following', 'cacheactor_following')
->selectAlias('ca.followers', 'cacheactor_followers')

Wyświetl plik

@ -44,11 +44,17 @@ class InstancePath implements JsonSerializable {
use TArrayTools;
const TYPE_PUBLIC = 0;
const TYPE_INBOX = 1;
const TYPE_GLOBAL = 2;
const TYPE_FOLLOWERS = 3;
const PRIORITY_NONE = 0;
const PRIORITY_LOW = 1;
const PRIORITY_MEDIUM = 2;
const PRIORITY_HIGH = 3;
const PRIORITY_TOP = 4;
/** @var string */
private $uri = '';
@ -56,19 +62,35 @@ class InstancePath implements JsonSerializable {
/** @var int */
private $type = 0;
/** @var int */
private $priority = 0;
/**
* InstancePath constructor.
*
* @param string $uri
* @param int $type
* @param int $priority
*/
public function __construct(string $uri = '', int $type = 0) {
public function __construct(string $uri = '', int $type = 0, int $priority = 0) {
$this->uri = $uri;
$this->type = $type;
$this->priority = $priority;
}
/**
* @param string $uri
*
* @return InstancePath
*/
public function setUri(string $uri): InstancePath {
$this->uri = $uri;
return $this;
}
/**
* @return string
*/
@ -77,6 +99,17 @@ class InstancePath implements JsonSerializable {
}
/**
* @param int $type
*
* @return InstancePath
*/
public function setType(int $type): InstancePath {
$this->type = $type;
return $this;
}
/**
* @return int
*/
@ -85,11 +118,30 @@ class InstancePath implements JsonSerializable {
}
/**
* @return int
*/
public function getPriority(): int {
return $this->priority;
}
/**
* @param int $priority
*
* @return InstancePath
*/
public function setPriority(int $priority): InstancePath {
$this->priority = $priority;
return $this;
}
/**
* @return string
*/
public function getAddress(): string {
$info = parse_url($this->uri);
$info = parse_url($this->getUri());
return $this->get('host', $info, '');
}
@ -99,15 +151,19 @@ class InstancePath implements JsonSerializable {
* @return string
*/
public function getPath(): string {
$info = parse_url($this->uri);
$info = parse_url($this->getUri());
return $this->get('path', $info, '');
}
/**
* @param array $data
*/
public function import(array $data) {
$this->setUri($this->get('uri', $data, ''));
$this->setType($this->getInt('type', $data, 0));
$this->setPriority($this->getInt('priority', $data, 0));
}
@ -116,8 +172,9 @@ class InstancePath implements JsonSerializable {
*/
public function jsonSerialize(): array {
return [
'uri' => $this->getUri(),
'type' => $this->getType()
'uri' => $this->getUri(),
'type' => $this->getType(),
'priority' => $this->getPriority()
];
}

Wyświetl plik

@ -39,6 +39,7 @@ use OCA\Social\Exceptions\FollowDoesNotExistException;
use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Exceptions\RequestException;
use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Exceptions\UrlCloudException;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\ActivityPub\Activity\Accept;
use OCA\Social\Model\ActivityPub\Activity\Reject;
@ -102,6 +103,7 @@ class FollowService implements ICoreService {
* @throws SocialAppConfigException
* @throws CacheActorDoesNotExistException
* @throws InvalidResourceException
* @throws UrlCloudException
*/
public function followAccount(Person $actor, string $account) {
$remoteActor = $this->personService->getFromAccount($account);
@ -117,9 +119,11 @@ class FollowService implements ICoreService {
$this->followsRequest->save($follow);
$follow->addInstancePath(
new InstancePath($remoteActor->getInbox(), InstancePath::TYPE_INBOX)
new InstancePath(
$remoteActor->getInbox(), InstancePath::TYPE_INBOX, InstancePath::PRIORITY_TOP
)
);
$this->activityService->manageRequest($follow);
$this->activityService->request($follow);
}
}
@ -131,6 +135,8 @@ class FollowService implements ICoreService {
* @throws CacheActorDoesNotExistException
* @throws InvalidResourceException
* @throws RequestException
* @throws SocialAppConfigException
* @throws UrlCloudException
*/
public function unfollowAccount(Person $actor, string $account) {
$remoteActor = $this->personService->getFromAccount($account);
@ -172,12 +178,14 @@ class FollowService implements ICoreService {
$accept->setObject($follow);
$accept->addInstancePath(
new InstancePath($remoteActor->getInbox(), InstancePath::TYPE_INBOX)
new InstancePath(
$remoteActor->getInbox(), InstancePath::TYPE_INBOX, InstancePath::PRIORITY_TOP
)
);
$follow->setParent($accept);
$this->activityService->manageRequest($accept);
$this->activityService->request($accept);
$this->followsRequest->accepted($follow);
} catch (Exception $e) {
}

Wyświetl plik

@ -149,7 +149,7 @@ class NoteService implements ICoreService {
case self::TYPE_UNLISTED:
$note->setTo($actor->getFollowers());
$note->addInstancePath(
new InstancePath($actor->getFollowers(), InstancePath::TYPE_FOLLOWERS)
new InstancePath($actor->getFollowers(), InstancePath::TYPE_FOLLOWERS, InstancePath::PRIORITY_LOW)
);
$note->addCc(ActivityService::TO_PUBLIC);
break;
@ -157,7 +157,7 @@ class NoteService implements ICoreService {
case self::TYPE_FOLLOWERS:
$note->setTo($actor->getFollowers());
$note->addInstancePath(
new InstancePath($actor->getFollowers(), InstancePath::TYPE_FOLLOWERS)
new InstancePath($actor->getFollowers(), InstancePath::TYPE_FOLLOWERS, InstancePath::PRIORITY_LOW)
);
break;
@ -168,7 +168,7 @@ class NoteService implements ICoreService {
$note->setTo(ActivityService::TO_PUBLIC);
$note->addCc($actor->getFollowers());
$note->addInstancePath(
new InstancePath($actor->getFollowers(), InstancePath::TYPE_FOLLOWERS)
new InstancePath($actor->getFollowers(), InstancePath::TYPE_FOLLOWERS, InstancePath::PRIORITY_LOW)
);
break;
}
@ -191,7 +191,9 @@ class NoteService implements ICoreService {
return;
}
$instancePath = new InstancePath($actor->getInbox(), InstancePath::TYPE_INBOX, InstancePath::PRIORITY_MEDIUM);
if ($type === self::TYPE_DIRECT) {
$instancePath->setPriority(InstancePath::PRIORITY_HIGH);
$note->addToArray($actor->getId());
} else {
$note->addCc($actor->getId());
@ -204,7 +206,7 @@ class NoteService implements ICoreService {
]
);
$note->addInstancePath(new InstancePath($actor->getInbox(), InstancePath::TYPE_INBOX));
$note->addInstancePath($instancePath);
}
@ -212,8 +214,6 @@ class NoteService implements ICoreService {
* @param Note $note
* @param string $type
* @param array $accounts
*
* @throws RequestException
*/
public function addRecipients(Note $note, string $type, array $accounts) {
if ($accounts === []) {
@ -236,7 +236,8 @@ class NoteService implements ICoreService {
}
$note->setInReplyTo($replyTo);
$note->addInstancePath(new InstancePath($replyTo));
// TODO - type can be NOT public !
$note->addInstancePath(new InstancePath($replyTo, InstancePath::TYPE_PUBLIC, InstancePath::PRIORITY_HIGH));
}