update if on the right timeline

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/678/head
Maxence Lange 2019-08-15 12:56:29 -01:00
rodzic 3b2942f3ee
commit 135bb96694
8 zmienionych plików z 72 dodań i 19 usunięć

Wyświetl plik

@ -461,7 +461,6 @@ class StreamRequestBuilder extends CoreRequestBuilder {
}
$item->setAction($action);
if ($item->getType() === Announce::TYPE) {
$item->setAttributedTo($this->get('following_actor_id', $data, ''));
}

Wyświetl plik

@ -153,7 +153,7 @@ class NoteInterface implements IActivityPubInterface {
$this->streamRequest->getStreamById($note->getId());
} catch (StreamNotFoundException $e) {
$this->streamRequest->save($note);
$this->pushService->onNewStream($note);
$this->pushService->onNewStream($note->getId());
}
}

Wyświetl plik

@ -82,6 +82,9 @@ class Stream extends ACore implements JsonSerializable {
/** @var StreamAction */
private $action = null;
/** @var string */
private $timeline = '';
/** @var bool */
private $hiddenOnTimeline = false;
@ -304,6 +307,25 @@ class Stream extends ACore implements JsonSerializable {
}
/**
* @return string
*/
public function getTimeline(): string {
return $this->timeline;
}
/**
* @param string $timeline
*
* @return Stream
*/
public function setTimeline(string $timeline): self {
$this->timeline = $timeline;
return $this;
}
/**
* @return bool
*/

Wyświetl plik

@ -88,7 +88,7 @@ class DetailsService {
$details = new StreamDetails($stream);
$this->setStreamViewers($details);
if ($stream->getType() === Stream::TYPE_PUBLIC) {
if ($stream->getTimeline() === Stream::TYPE_PUBLIC) {
if ($stream->isLocal()) {
$details->setPublic(true);
} else {

Wyświetl plik

@ -32,10 +32,11 @@ namespace OCA\Social\Service;
use daita\MySmallPhpTools\Traits\TAsync;
use OC\Stratos\Model\Helper\StratosEvent;
use OC;
use OC\Stratos\Model\Helper\StratosCallback;
use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Exceptions\StreamNotFoundException;
use OCA\Social\Model\ActivityPub\Actor\Person;
use OCA\Social\Model\ActivityPub\Stream;
use OCP\AppFramework\QueryException;
use OCP\Stratos\Exceptions\StratosInstallException;
use OCP\Stratos\IStratosManager;
@ -59,6 +60,9 @@ class PushService {
/** @var DetailsService */
private $detailsService;
/** @var StreamService */
private $streamService;
/** @var MiscService */
private $miscService;
@ -69,14 +73,17 @@ class PushService {
* @param DetailsService $detailsService
* @param MiscService $miscService
*/
public function __construct(DetailsService $detailsService, MiscService $miscService) {
public function __construct(
DetailsService $detailsService, StreamService $streamService, MiscService $miscService
) {
$this->detailsService = $detailsService;
$this->streamService = $streamService;
$this->miscService = $miscService;
// FIX ME: nc18/stratos
if ($this->miscService->getNcVersion() >= 17) {
try {
$this->stratosManager = \OC::$server->query(IStratosManager::class);
$this->stratosManager = OC::$server->query(IStratosManager::class);
} catch (QueryException $e) {
$miscService->log('QueryException while loading StratosManager');
}
@ -85,12 +92,12 @@ class PushService {
/**
* @param Stream $stream
* @param string $streamId
*
* @throws SocialAppConfigException
* @throws StratosInstallException
*/
public function onNewStream(Stream $stream) {
public function onNewStream(string $streamId) {
// FIXME: remove in nc18
if ($this->miscService->getNcVersion() < 17) {
return;
@ -100,8 +107,13 @@ class PushService {
return;
}
$stratosHelper = $this->stratosManager->getStratosHelper();
try {
$stream = $this->streamService->getStreamById($streamId);
} catch (StreamNotFoundException $e) {
return;
}
$stratosHelper = $this->stratosManager->getStratosHelper();
$details = $this->detailsService->generateDetailsFromStream($stream);
$home = array_map(
function(Person $item): string {
@ -109,10 +121,10 @@ class PushService {
}, $details->getHomeViewers()
);
$event = new StratosEvent('social', 'Social.timeline.home');
$event->addUsers($home);
$event->setPayloadSerializable($stream);
$stratosHelper->broadcastEvent($event);
$callback = new StratosCallback('social', 'timeline.home');
$callback->setPayloadSerializable($stream);
$callback->addUsers($home);
$stratosHelper->toCallback($callback);
$direct = array_map(
function(Person $item): string {
@ -120,10 +132,10 @@ class PushService {
}, $details->getDirectViewers()
);
$event = new StratosEvent('social', 'Social.timeline.direct');
$event->addUsers($direct);
$event->setPayloadSerializable($stream);
$stratosHelper->broadcastEvent($event);
$callback = new StratosCallback('social', 'timeline.direct');
$callback->addUsers($direct);
$callback->setPayloadSerializable($stream);
$stratosHelper->toCallback($callback);
}

Wyświetl plik

@ -213,7 +213,7 @@ class StreamService {
*/
public function detectType(Stream $stream) {
if (in_array(ACore::CONTEXT_PUBLIC, $stream->getToAll())) {
$stream->setType(Stream::TYPE_PUBLIC);
$stream->setTimeline(Stream::TYPE_PUBLIC);
return;
}

Wyświetl plik

@ -210,6 +210,9 @@ export default {
this.$store.dispatch('fetchCurrentAccountInfo', this.cloudId)
}
if (OCA.Stratos && OCA.Stratos.isEnabled()) {
OCA.Stratos.addCallback(this.fromStratos, 'social')
}
},
methods: {
hideInfo() {
@ -226,6 +229,20 @@ export default {
},
resetSearch() {
this.searchTerm = ''
},
fromStratos: function(data) {
// FIXME: might be better to use Timeline.type() ?
let timeline = 'home'
if (this.$route.params.type) {
timeline = this.$route.params.type
}
if (data.source === 'timeline.home' && timeline === 'home') {
this.$store.dispatch('addToTimeline', [data.payload])
}
if (data.source === 'timeline.direct' && timeline === 'direct') {
this.$store.dispatch('addToTimeline', [data.payload])
}
}
}
}

Wyświetl plik

@ -199,6 +199,9 @@ const actions = {
context.commit('addToTimeline', response.data.result)
return response.data
})
},
addToTimeline(context, data) {
context.commit('addToTimeline', data)
}
}