kopia lustrzana https://github.com/nextcloud/social
commit
527313d4a9
|
@ -62,7 +62,6 @@ return [
|
|||
['name' => 'ActivityPub#outbox', 'url' => '/@{username}/outbox', 'verb' => 'POST'],
|
||||
['name' => 'ActivityPub#followers', 'url' => '/@{username}/followers', 'verb' => 'GET'],
|
||||
['name' => 'ActivityPub#following', 'url' => '/@{username}/following', 'verb' => 'GET'],
|
||||
['name' => 'ActivityPub#test', 'url' => '/inbox/{username}', 'verb' => 'POST'],
|
||||
|
||||
['name' => 'SocialPub#displayPost', 'url' => '/@{username}/{postId}', 'verb' => 'GET'],
|
||||
|
||||
|
|
|
@ -226,19 +226,6 @@ class ActivityPubController extends Controller {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Testing method. does nothing.
|
||||
*
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function test(): Response {
|
||||
return $this->success(['toto']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Outbox. does nothing.
|
||||
*
|
||||
|
|
|
@ -191,7 +191,7 @@ class LocalController extends Controller {
|
|||
*
|
||||
* @return DataResponse
|
||||
*/
|
||||
public function streamHome(int $since = 0, int $limit = 5): DataResponse {
|
||||
public function streamHome($since = 0, int $limit = 5): DataResponse {
|
||||
|
||||
try {
|
||||
$actor = $this->actorService->getActorFromUserId($this->userId);
|
||||
|
|
|
@ -240,7 +240,7 @@ class CoreRequestBuilder {
|
|||
$date = new DateTime('now');
|
||||
$date->sub(new DateInterval('PT' . $delay . 'M'));
|
||||
|
||||
$this->limitToDBFieldDateTime($qb, 'creation', $date);
|
||||
$this->limitToDBFieldDateTime($qb, 'creation', $date, true);
|
||||
}
|
||||
|
||||
|
||||
|
@ -256,7 +256,7 @@ class CoreRequestBuilder {
|
|||
$date = new DateTime('now');
|
||||
$date->sub(new DateInterval('PT' . $delay . 'M'));
|
||||
|
||||
$this->limitToDBFieldDateTime($qb, 'caching', $date);
|
||||
$this->limitToDBFieldDateTime($qb, 'caching', $date, true);
|
||||
}
|
||||
|
||||
|
||||
|
@ -307,12 +307,19 @@ class CoreRequestBuilder {
|
|||
/**
|
||||
* @param IQueryBuilder $qb
|
||||
* @param string $recipient
|
||||
* @param bool $asAuthor
|
||||
*/
|
||||
protected function limitToRecipient(IQueryBuilder &$qb, string $recipient) {
|
||||
protected function limitToRecipient(
|
||||
IQueryBuilder &$qb, string $recipient, bool $asAuthor = false
|
||||
) {
|
||||
$expr = $qb->expr();
|
||||
$orX = $expr->orX();
|
||||
$dbConn = $this->dbConnection;
|
||||
|
||||
if ($asAuthor === true) {
|
||||
$orX->add($expr->eq('attributed_to', $qb->createNamedParameter($recipient)));
|
||||
}
|
||||
|
||||
$orX->add($expr->eq('to', $qb->createNamedParameter($recipient)));
|
||||
$orX->add(
|
||||
$expr->like(
|
||||
|
@ -344,18 +351,11 @@ class CoreRequestBuilder {
|
|||
*/
|
||||
protected function limitPaginate(IQueryBuilder &$qb, int $since = 0, int $limit = 5) {
|
||||
if ($since > 0) {
|
||||
$expr = $qb->expr();
|
||||
$dt = new \DateTime();
|
||||
$dt->setTimestamp($since);
|
||||
// TODO: Pagination should use published date, once we can properly query the db for that
|
||||
$qb->andWhere(
|
||||
$expr->lt(
|
||||
$this->defaultSelectAlias . '.creation',
|
||||
$qb->createNamedParameter($dt, IQueryBuilder::PARAM_DATE),
|
||||
IQueryBuilder::PARAM_DATE
|
||||
)
|
||||
);
|
||||
$dTime = new \DateTime();
|
||||
$dTime->setTimestamp($since);
|
||||
$this->limitToDBFieldDateTime($qb, 'published_time', $dTime);
|
||||
}
|
||||
|
||||
$qb->setMaxResults($limit);
|
||||
$qb->orderBy('creation', 'desc');
|
||||
}
|
||||
|
@ -379,6 +379,23 @@ class CoreRequestBuilder {
|
|||
protected function limitToDBField(
|
||||
IQueryBuilder &$qb, string $field, string $value, bool $cs = true, string $alias = ''
|
||||
) {
|
||||
$expr = $this->exprLimitToDBField($qb, $field, $value, $cs, $alias);
|
||||
$qb->andWhere($expr);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param IQueryBuilder $qb
|
||||
* @param string $field
|
||||
* @param string $value
|
||||
* @param bool $cs
|
||||
* @param string $alias
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function exprLimitToDBField(
|
||||
IQueryBuilder &$qb, string $field, string $value, bool $cs = true, string $alias = ''
|
||||
): string {
|
||||
$expr = $qb->expr();
|
||||
|
||||
$pf = '';
|
||||
|
@ -388,12 +405,11 @@ class CoreRequestBuilder {
|
|||
$field = $pf . $field;
|
||||
|
||||
if ($cs) {
|
||||
$qb->andWhere($expr->eq($field, $qb->createNamedParameter($value)));
|
||||
return $expr->eq($field, $qb->createNamedParameter($value));
|
||||
} else {
|
||||
$func = $qb->func();
|
||||
$qb->andWhere(
|
||||
$expr->eq($func->lower($field), $func->lower($qb->createNamedParameter($value)))
|
||||
);
|
||||
|
||||
return $expr->eq($func->lower($field), $func->lower($qb->createNamedParameter($value)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -429,15 +445,20 @@ class CoreRequestBuilder {
|
|||
* @param IQueryBuilder $qb
|
||||
* @param string $field
|
||||
* @param DateTime $date
|
||||
* @param bool $orNull
|
||||
*/
|
||||
protected function limitToDBFieldDateTime(IQueryBuilder &$qb, string $field, DateTime $date) {
|
||||
protected function limitToDBFieldDateTime(
|
||||
IQueryBuilder &$qb, string $field, DateTime $date, bool $orNull = false
|
||||
) {
|
||||
$expr = $qb->expr();
|
||||
$pf = ($qb->getType() === QueryBuilder::SELECT) ? $this->defaultSelectAlias . '.' : '';
|
||||
$field = $pf . $field;
|
||||
|
||||
$orX = $expr->orX();
|
||||
$orX->add($expr->lte($field, $qb->createNamedParameter($date, IQueryBuilder::PARAM_DATE)));
|
||||
$orX->add($expr->isNull($field));
|
||||
if ($orNull === true) {
|
||||
$orX->add($expr->isNull($field));
|
||||
}
|
||||
$qb->andWhere($orX);
|
||||
}
|
||||
|
||||
|
|
|
@ -139,16 +139,20 @@ class NotesRequest extends NotesRequestBuilder {
|
|||
|
||||
/**
|
||||
* @param string $actorId
|
||||
* @param int $since
|
||||
* @param int $limit
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getHomeNotesForActorId(string $actorId, $since, $limit): array {
|
||||
public function getHomeNotesForActorId(string $actorId, int $since = 0, int $limit = 5): array {
|
||||
$qb = $this->getNotesSelectSql();
|
||||
|
||||
$this->rightJoinFollowing($qb);
|
||||
$this->limitToActorId($qb, $actorId, 'f');
|
||||
$qb->orWhere($this->exprLimitToDBField($qb, 'attributed_to', $actorId));
|
||||
|
||||
$this->limitPaginate($qb, $since, $limit);
|
||||
// $this->leftJoinCacheActors($qb, 'attributed_to');
|
||||
$this->leftJoinCacheActors($qb, 'attributed_to');
|
||||
|
||||
$notes = [];
|
||||
$cursor = $qb->execute();
|
||||
|
@ -190,12 +194,15 @@ class NotesRequest extends NotesRequestBuilder {
|
|||
|
||||
/**
|
||||
* @param string $actorId
|
||||
* @param int $since
|
||||
* @param int $limit
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDirectNotesForActorId(string $actorId, $since, $limit): array {
|
||||
public function getDirectNotesForActorId(string $actorId, int $since = 0, int $limit = 5
|
||||
): array {
|
||||
$qb = $this->getNotesSelectSql();
|
||||
$this->limitToRecipient($qb, $actorId);
|
||||
$this->limitToRecipient($qb, $actorId, true);
|
||||
$this->limitPaginate($qb, $since, $limit);
|
||||
$this->leftJoinCacheActors($qb, 'attributed_to');
|
||||
|
||||
|
|
|
@ -149,7 +149,10 @@ class NoteService implements ICoreService {
|
|||
case self::TYPE_UNLISTED:
|
||||
$note->setTo($actor->getFollowers());
|
||||
$note->addInstancePath(
|
||||
new InstancePath($actor->getFollowers(), InstancePath::TYPE_FOLLOWERS, InstancePath::PRIORITY_LOW)
|
||||
new InstancePath(
|
||||
$actor->getFollowers(), InstancePath::TYPE_FOLLOWERS,
|
||||
InstancePath::PRIORITY_LOW
|
||||
)
|
||||
);
|
||||
$note->addCc(ActivityService::TO_PUBLIC);
|
||||
break;
|
||||
|
@ -157,7 +160,10 @@ class NoteService implements ICoreService {
|
|||
case self::TYPE_FOLLOWERS:
|
||||
$note->setTo($actor->getFollowers());
|
||||
$note->addInstancePath(
|
||||
new InstancePath($actor->getFollowers(), InstancePath::TYPE_FOLLOWERS, InstancePath::PRIORITY_LOW)
|
||||
new InstancePath(
|
||||
$actor->getFollowers(), InstancePath::TYPE_FOLLOWERS,
|
||||
InstancePath::PRIORITY_LOW
|
||||
)
|
||||
);
|
||||
break;
|
||||
|
||||
|
@ -168,7 +174,10 @@ class NoteService implements ICoreService {
|
|||
$note->setTo(ActivityService::TO_PUBLIC);
|
||||
$note->addCc($actor->getFollowers());
|
||||
$note->addInstancePath(
|
||||
new InstancePath($actor->getFollowers(), InstancePath::TYPE_FOLLOWERS, InstancePath::PRIORITY_LOW)
|
||||
new InstancePath(
|
||||
$actor->getFollowers(), InstancePath::TYPE_FOLLOWERS,
|
||||
InstancePath::PRIORITY_LOW
|
||||
)
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
@ -191,7 +200,9 @@ class NoteService implements ICoreService {
|
|||
return;
|
||||
}
|
||||
|
||||
$instancePath = new InstancePath($actor->getInbox(), InstancePath::TYPE_INBOX, InstancePath::PRIORITY_MEDIUM);
|
||||
$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());
|
||||
|
@ -237,7 +248,9 @@ class NoteService implements ICoreService {
|
|||
|
||||
$note->setInReplyTo($replyTo);
|
||||
// TODO - type can be NOT public !
|
||||
$note->addInstancePath(new InstancePath($replyTo, InstancePath::TYPE_PUBLIC, InstancePath::PRIORITY_HIGH));
|
||||
$note->addInstancePath(
|
||||
new InstancePath($replyTo, InstancePath::TYPE_PUBLIC, InstancePath::PRIORITY_HIGH)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
@ -310,9 +323,12 @@ class NoteService implements ICoreService {
|
|||
/**
|
||||
* @param Person $actor
|
||||
*
|
||||
* @param int $since
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Note[]
|
||||
*/
|
||||
public function getHomeNotesForActor(Person $actor, $since, $limit): array {
|
||||
public function getHomeNotesForActor(Person $actor, int $since = 0, int $limit = 5): array {
|
||||
return $this->notesRequest->getHomeNotesForActorId($actor->getId(), $since, $limit);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,11 +2,12 @@
|
|||
<div class="timeline-entry">
|
||||
<div class="entry-content">
|
||||
<div class="post-avatar">
|
||||
<avatar :size="32" :user="item.actor_info.preferredUsername" />
|
||||
<avatar v-if="item.actor_info" :size="32" :user="item.actor_info.preferredUsername" />
|
||||
<avatar :size="32" user="?" />
|
||||
</div>
|
||||
<div class="post-content">
|
||||
<div class="post-author-wrapper">
|
||||
<router-link v-if="item.actor_info.local" :to="{ name: 'profile', params: { account: item.actor_info.preferredUsername }}">
|
||||
<router-link v-if="item.actor_info && item.actor_info.local" :to="{ name: 'profile', params: { account: item.actor_info.preferredUsername }}">
|
||||
<span class="post-author">{{ item.actor_info.preferredUsername }}</span>
|
||||
<span class="post-author-id">{{ item.actor_info.account }}</span>
|
||||
</router-link>
|
||||
|
@ -16,7 +17,6 @@
|
|||
</a>
|
||||
</div>
|
||||
<div class="post-message" v-html="formatedMessage" />
|
||||
<!--<pre style="height: 200px; overflow:scroll;">{{item}}</pre> //-->
|
||||
</div>
|
||||
<div class="post-timestamp">{{ item.published }}</div>
|
||||
</div>
|
||||
|
@ -44,7 +44,9 @@ export default {
|
|||
formatedMessage: function() {
|
||||
let message = this.item.content
|
||||
message = message.replace(/(?:\r\n|\r|\n)/g, '<br />')
|
||||
return message.linkify()
|
||||
message = message.linkify()
|
||||
message = this.$twemoji.parse(message)
|
||||
return message
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -93,3 +95,8 @@ export default {
|
|||
opacity: .7;
|
||||
}
|
||||
</style>
|
||||
<style>
|
||||
.post-message a {
|
||||
text-decoration: underline;
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -32,15 +32,13 @@ const mutations = {
|
|||
addToTimeline(state, data) {
|
||||
for (let item in data) {
|
||||
state.since = data[item].publishedTime
|
||||
data[item].actor_info = {}
|
||||
Vue.set(state.timeline, data[item].id, data[item])
|
||||
}
|
||||
},
|
||||
addPost(state, data) {
|
||||
// FIXME: push data we receive to the timeline array
|
||||
// state.timeline.push(data)
|
||||
},
|
||||
resetTimeline(state) {
|
||||
state.timeline = {}
|
||||
state.since = Math.floor(Date.now() / 1000) + 1
|
||||
},
|
||||
setTimelineType(state, type) {
|
||||
state.type = type
|
||||
|
|
Ładowanie…
Reference in New Issue