kopia lustrzana https://github.com/nextcloud/social
filter displayed Post based on viewer
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>pull/952/head
rodzic
fd5790bd5c
commit
b91f94b32e
|
@ -36,12 +36,14 @@ use daita\MySmallPhpTools\Traits\TStringTools;
|
|||
use Exception;
|
||||
use OC\AppFramework\Http;
|
||||
use OCA\Social\AppInfo\Application;
|
||||
use OCA\Social\Exceptions\AccountDoesNotExistException;
|
||||
use OCA\Social\Exceptions\ItemUnknownException;
|
||||
use OCA\Social\Exceptions\RealTokenException;
|
||||
use OCA\Social\Exceptions\SignatureIsGoneException;
|
||||
use OCA\Social\Exceptions\SocialAppConfigException;
|
||||
use OCA\Social\Exceptions\StreamNotFoundException;
|
||||
use OCA\Social\Exceptions\UrlCloudException;
|
||||
use OCA\Social\Service\AccountService;
|
||||
use OCA\Social\Service\CacheActorService;
|
||||
use OCA\Social\Service\ConfigService;
|
||||
use OCA\Social\Service\FediverseService;
|
||||
|
@ -82,6 +84,9 @@ class ActivityPubController extends Controller {
|
|||
/** @var ImportService */
|
||||
private $importService;
|
||||
|
||||
/** @var AccountService */
|
||||
private $accountService;
|
||||
|
||||
/** @var FollowService */
|
||||
private $followService;
|
||||
|
||||
|
@ -105,17 +110,18 @@ class ActivityPubController extends Controller {
|
|||
* @param SignatureService $signatureService
|
||||
* @param StreamQueueService $streamQueueService
|
||||
* @param ImportService $importService
|
||||
* @param AccountService $accountService
|
||||
* @param FollowService $followService
|
||||
* @param StreamService $streamService
|
||||
* @param ConfigService $configService
|
||||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(
|
||||
IRequest $request, SocialPubController $socialPubController,
|
||||
FediverseService $fediverseService, CacheActorService $cacheActorService,
|
||||
SignatureService $signatureService, StreamQueueService $streamQueueService,
|
||||
ImportService $importService, FollowService $followService, StreamService $streamService,
|
||||
ConfigService $configService, MiscService $miscService
|
||||
IRequest $request, SocialPubController $socialPubController, FediverseService $fediverseService,
|
||||
CacheActorService $cacheActorService, SignatureService $signatureService,
|
||||
StreamQueueService $streamQueueService, ImportService $importService, AccountService $accountService,
|
||||
FollowService $followService, StreamService $streamService, ConfigService $configService,
|
||||
MiscService $miscService
|
||||
) {
|
||||
parent::__construct(Application::APP_NAME, $request);
|
||||
|
||||
|
@ -125,6 +131,7 @@ class ActivityPubController extends Controller {
|
|||
$this->signatureService = $signatureService;
|
||||
$this->streamQueueService = $streamQueueService;
|
||||
$this->importService = $importService;
|
||||
$this->accountService = $accountService;
|
||||
$this->followService = $followService;
|
||||
$this->streamService = $streamService;
|
||||
$this->configService = $configService;
|
||||
|
@ -364,9 +371,14 @@ class ActivityPubController extends Controller {
|
|||
return $this->socialPubController->displayPost($username, $token);
|
||||
}
|
||||
|
||||
// TODO - check viewer rights !
|
||||
try {
|
||||
$viewer = $this->accountService->getCurrentViewer();
|
||||
$this->streamService->setViewer($viewer);
|
||||
} catch (AccountDoesNotExistException $e) {
|
||||
}
|
||||
|
||||
$postId = $this->configService->getSocialUrl() . '@' . $username . '/' . $token;
|
||||
$stream = $this->streamService->getStreamById($postId, false);
|
||||
$stream = $this->streamService->getStreamById($postId, true);
|
||||
|
||||
$stream->setCompleteDetails(false);
|
||||
|
||||
|
|
|
@ -33,10 +33,12 @@ namespace OCA\Social\Controller;
|
|||
use daita\MySmallPhpTools\Traits\Nextcloud\TNCDataResponse;
|
||||
use Exception;
|
||||
use OCA\Social\AppInfo\Application;
|
||||
use OCA\Social\Exceptions\AccountDoesNotExistException;
|
||||
use OCA\Social\Exceptions\CacheActorDoesNotExistException;
|
||||
use OCA\Social\Exceptions\SocialAppConfigException;
|
||||
use OCA\Social\Exceptions\StreamNotFoundException;
|
||||
use OCA\Social\Exceptions\UrlCloudException;
|
||||
use OCA\Social\Model\ActivityPub\Actor\Person;
|
||||
use OCA\Social\Service\AccountService;
|
||||
use OCA\Social\Service\CacheActorService;
|
||||
use OCA\Social\Service\ConfigService;
|
||||
|
@ -212,20 +214,18 @@ class SocialPubController extends Controller {
|
|||
* @param string $token
|
||||
*
|
||||
* @return TemplateResponse
|
||||
* @throws StreamNotFoundException
|
||||
* @throws SocialAppConfigException
|
||||
* @throws StreamNotFoundException
|
||||
*/
|
||||
public function displayPost(string $username, string $token): TemplateResponse {
|
||||
$postId = $this->configService->getSocialUrl() . '@' . $username . '/' . $token;
|
||||
|
||||
if (isset($this->userId)) {
|
||||
try {
|
||||
$viewer = $this->accountService->getActorFromUserId($this->userId, true);
|
||||
$this->streamService->setViewer($viewer);
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
try {
|
||||
$viewer = $this->accountService->getCurrentViewer();
|
||||
$this->streamService->setViewer($viewer);
|
||||
} catch (AccountDoesNotExistException $e) {
|
||||
}
|
||||
|
||||
$postId = $this->configService->getSocialUrl() . '@' . $username . '/' . $token;
|
||||
|
||||
$stream = $this->streamService->getStreamById($postId, true);
|
||||
$data = [
|
||||
'id' => $postId,
|
||||
|
|
|
@ -381,9 +381,12 @@ class SocialLimitsQueryBuilder extends SocialCrossQueryBuilder {
|
|||
/**
|
||||
* @param string $aliasDest
|
||||
* @param string $aliasFollowing
|
||||
* @param bool $public
|
||||
* @param bool $allowPublic
|
||||
* @param bool $allowDirect
|
||||
*/
|
||||
public function limitToViewer(string $aliasDest = 'sd', string $aliasFollowing = 'f', bool $public = false
|
||||
public function limitToViewer(
|
||||
string $aliasDest = 'sd', string $aliasFollowing = 'f', bool $allowPublic = false,
|
||||
bool $allowDirect = false
|
||||
) {
|
||||
if (!$this->hasViewer()) {
|
||||
$this->selectDestFollowing($aliasDest);
|
||||
|
@ -403,10 +406,14 @@ class SocialLimitsQueryBuilder extends SocialCrossQueryBuilder {
|
|||
);
|
||||
$orX->add($following);
|
||||
|
||||
if ($public) {
|
||||
if ($allowPublic) {
|
||||
$orX->add($this->exprLimitToDest(ACore::CONTEXT_PUBLIC, 'recipient', '', $aliasDest));
|
||||
}
|
||||
|
||||
if ($allowDirect) {
|
||||
$orX->add($this->exprLimitToDest($actor->getId(), 'dm', '', $aliasDest));
|
||||
}
|
||||
|
||||
$this->andWhere($orX);
|
||||
}
|
||||
|
||||
|
|
|
@ -241,13 +241,11 @@ class StreamRequest extends StreamRequestBuilder {
|
|||
};
|
||||
|
||||
$qb = $this->getStreamSelectSql();
|
||||
$expr = $qb->expr();
|
||||
|
||||
$qb->limitToIdPrim($qb->prim($id));
|
||||
$qb->linkToCacheActors('ca', 's.attributed_to_prim');
|
||||
|
||||
if ($asViewer) {
|
||||
$qb->limitToViewer('sd', 'f', true);
|
||||
$qb->limitToViewer('sd', 'f', true, true);
|
||||
$qb->leftJoinStreamAction('sa');
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ use OCA\Social\Db\ActorsRequest;
|
|||
use OCA\Social\Db\FollowsRequest;
|
||||
use OCA\Social\Db\StreamRequest;
|
||||
use OCA\Social\Exceptions\AccountAlreadyExistsException;
|
||||
use OCA\Social\Exceptions\AccountDoesNotExistException;
|
||||
use OCA\Social\Exceptions\ActorDoesNotExistException;
|
||||
use OCA\Social\Exceptions\ItemAlreadyExistsException;
|
||||
use OCA\Social\Exceptions\ItemUnknownException;
|
||||
|
@ -45,6 +46,7 @@ use OCA\Social\Exceptions\UrlCloudException;
|
|||
use OCA\Social\Model\ActivityPub\Actor\Person;
|
||||
use OCP\Accounts\IAccountManager;
|
||||
use OCP\IUserManager;
|
||||
use OCP\IUserSession;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -64,6 +66,9 @@ class AccountService {
|
|||
/** @var IUserManager */
|
||||
private $userManager;
|
||||
|
||||
/** @var IUserSession */
|
||||
private $userSession;
|
||||
|
||||
/** @var IAccountManager */
|
||||
private $accountManager;
|
||||
|
||||
|
@ -96,6 +101,7 @@ class AccountService {
|
|||
* ActorService constructor.
|
||||
*
|
||||
* @param IUserManager $userManager
|
||||
* @param IUserSession $userSession
|
||||
* @param IAccountManager $accountManager
|
||||
* @param ActorsRequest $actorsRequest
|
||||
* @param FollowsRequest $followsRequest
|
||||
|
@ -107,12 +113,14 @@ class AccountService {
|
|||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(
|
||||
IUserManager $userManager, IAccountManager $accountManager, ActorsRequest $actorsRequest,
|
||||
IUserManager $userManager, IUserSession $userSession, IAccountManager $accountManager,
|
||||
ActorsRequest $actorsRequest,
|
||||
FollowsRequest $followsRequest, StreamRequest $streamRequest, ActorService $actorService,
|
||||
DocumentService $documentService, SignatureService $signatureService,
|
||||
ConfigService $configService, MiscService $miscService
|
||||
) {
|
||||
$this->userManager = $userManager;
|
||||
$this->userSession = $userSession;
|
||||
$this->accountManager = $accountManager;
|
||||
$this->actorsRequest = $actorsRequest;
|
||||
$this->followsRequest = $followsRequest;
|
||||
|
@ -152,6 +160,24 @@ class AccountService {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Person
|
||||
* @throws AccountDoesNotExistException
|
||||
*/
|
||||
public function getCurrentViewer(): Person {
|
||||
$user = $this->userSession->getUser();
|
||||
if ($user === null) {
|
||||
throw new AccountDoesNotExistException();
|
||||
}
|
||||
|
||||
try {
|
||||
return $this->getActorFromUserId($user->getUID());
|
||||
} catch (Exception $e) {
|
||||
throw new AccountDoesNotExistException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $userId
|
||||
* @param bool $create
|
||||
|
|
Ładowanie…
Reference in New Issue