kopia lustrzana https://github.com/nextcloud/social
Merge pull request #52 from nextcloud-gmbh/frontend-implement-different-streams
Frontend implement different streamspull/56/head
commit
f6f7f2cd6a
|
@ -73,6 +73,9 @@ class ActivityPubController extends Controller {
|
|||
/** @var MiscService */
|
||||
private $miscService;
|
||||
|
||||
/** @var NavigationController */
|
||||
private $navigationController;
|
||||
|
||||
|
||||
/**
|
||||
* ActivityPubController constructor.
|
||||
|
@ -90,11 +93,13 @@ class ActivityPubController extends Controller {
|
|||
IRequest $request, SocialPubController $socialPubController,
|
||||
ActivityService $activityService, ImportService $importService,
|
||||
FollowService $followService, ActorService $actorService, NotesRequest $notesRequest,
|
||||
NavigationController $navigationController,
|
||||
MiscService $miscService
|
||||
) {
|
||||
parent::__construct(Application::APP_NAME, $request);
|
||||
|
||||
$this->socialPubController = $socialPubController;
|
||||
$this->navigationController = $navigationController;
|
||||
|
||||
$this->activityService = $activityService;
|
||||
$this->importService = $importService;
|
||||
|
@ -119,10 +124,11 @@ class ActivityPubController extends Controller {
|
|||
* @param string $username
|
||||
*
|
||||
* @return Response
|
||||
* @throws \OC\User\NoUserException
|
||||
*/
|
||||
public function actor(string $username): Response {
|
||||
if (!$this->checkSourceActivityStreams()) {
|
||||
return $this->socialPubController->actor($username);
|
||||
return $this->navigationController->public($username);
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -326,7 +332,7 @@ class ActivityPubController extends Controller {
|
|||
private function checkSourceActivityStreams(): bool {
|
||||
|
||||
// uncomment this line to display the result that would be return to an ActivityPub service (TEST)
|
||||
return true;
|
||||
// return true;
|
||||
|
||||
if ($this->request->getHeader('Accept')
|
||||
=== 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"') {
|
||||
|
|
|
@ -95,7 +95,7 @@ class LocalController extends Controller {
|
|||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(
|
||||
IRequest $request, string $userId, PersonService $personService,
|
||||
IRequest $request, $userId, PersonService $personService,
|
||||
FollowService $followService, ActorService $actorService,
|
||||
PostService $postService, NoteService $noteService,
|
||||
MiscService $miscService
|
||||
|
@ -181,11 +181,11 @@ class LocalController extends Controller {
|
|||
*
|
||||
* @return DataResponse
|
||||
*/
|
||||
public function streamHome(): DataResponse {
|
||||
public function streamHome(int $since = 0, int $limit = 5): DataResponse {
|
||||
|
||||
try {
|
||||
$actor = $this->actorService->getActorFromUserId($this->userId);
|
||||
$posts = $this->noteService->getHomeNotesForActor($actor);
|
||||
$posts = $this->noteService->getHomeNotesForActor($actor, $since, $limit);
|
||||
|
||||
return $this->success($posts);
|
||||
} catch (Exception $e) {
|
||||
|
@ -203,11 +203,11 @@ class LocalController extends Controller {
|
|||
*
|
||||
* @return DataResponse
|
||||
*/
|
||||
public function streamDirect(): DataResponse {
|
||||
public function streamDirect(int $since = 0, int $limit = 5): DataResponse {
|
||||
|
||||
try {
|
||||
$actor = $this->actorService->getActorFromUserId($this->userId);
|
||||
$posts = $this->noteService->getDirectNotesForActor($actor);
|
||||
$posts = $this->noteService->getDirectNotesForActor($actor, $since, $limit);
|
||||
|
||||
return $this->success($posts);
|
||||
} catch (Exception $e) {
|
||||
|
|
|
@ -142,11 +142,12 @@ class NotesRequest extends NotesRequestBuilder {
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getHomeNotesForActorId(string $actorId): array {
|
||||
public function getHomeNotesForActorId(string $actorId, $since, $limit): array {
|
||||
$qb = $this->getNotesSelectSql();
|
||||
|
||||
$this->rightJoinFollowing($qb);
|
||||
$this->limitToActorId($qb, $actorId, 'f');
|
||||
$this->limitPaginate($qb, $since, $limit);
|
||||
// $this->leftJoinCacheActors($qb, 'attributed_to');
|
||||
|
||||
$notes = [];
|
||||
|
@ -192,9 +193,10 @@ class NotesRequest extends NotesRequestBuilder {
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDirectNotesForActorId(string $actorId): array {
|
||||
public function getDirectNotesForActorId(string $actorId, $since, $limit): array {
|
||||
$qb = $this->getNotesSelectSql();
|
||||
$this->limitToRecipient($qb, $actorId);
|
||||
$this->limitPaginate($qb, $since, $limit);
|
||||
$this->leftJoinCacheActors($qb, 'attributed_to');
|
||||
|
||||
$notes = [];
|
||||
|
|
|
@ -312,8 +312,8 @@ class NoteService implements ICoreService {
|
|||
*
|
||||
* @return Note[]
|
||||
*/
|
||||
public function getHomeNotesForActor(Person $actor): array {
|
||||
return $this->notesRequest->getHomeNotesForActorId($actor->getId());
|
||||
public function getHomeNotesForActor(Person $actor, $since, $limit): array {
|
||||
return $this->notesRequest->getHomeNotesForActorId($actor->getId(), $since, $limit);
|
||||
}
|
||||
|
||||
|
||||
|
@ -322,8 +322,8 @@ class NoteService implements ICoreService {
|
|||
*
|
||||
* @return Note[]
|
||||
*/
|
||||
public function getDirectNotesForActor(Person $actor): array {
|
||||
return $this->notesRequest->getDirectNotesForActorId($actor->getId());
|
||||
public function getDirectNotesForActor(Person $actor, $since, $limit): array {
|
||||
return $this->notesRequest->getDirectNotesForActorId($actor->getId(), $since, $limit);
|
||||
}
|
||||
|
||||
|
||||
|
|
46
src/App.vue
46
src/App.vue
|
@ -89,12 +89,22 @@ export default {
|
|||
{
|
||||
id: 'social-timeline',
|
||||
classes: [],
|
||||
icon: 'icon-category-monitoring',
|
||||
text: t('social', 'Timeline'),
|
||||
icon: 'icon-home',
|
||||
text: t('social', 'Home'),
|
||||
router: {
|
||||
name: 'timeline'
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'social-direct-messages',
|
||||
classes: [],
|
||||
router: {
|
||||
name: 'timeline',
|
||||
params: { type: 'direct' }
|
||||
},
|
||||
icon: 'icon-comment',
|
||||
text: t('social', 'Direct messages')
|
||||
},
|
||||
{
|
||||
id: 'social-account',
|
||||
classes: [],
|
||||
|
@ -106,28 +116,28 @@ export default {
|
|||
}
|
||||
},
|
||||
{
|
||||
id: 'social-friends',
|
||||
classes: [],
|
||||
href: '#',
|
||||
icon: 'icon-category-social',
|
||||
text: t('social', 'Friends')
|
||||
id: 'social-spacer',
|
||||
classes: []
|
||||
},
|
||||
{
|
||||
id: 'social-favorites',
|
||||
id: 'social-local',
|
||||
classes: [],
|
||||
href: '#',
|
||||
icon: 'icon-favorite',
|
||||
text: t('social', 'Favorites')
|
||||
icon: 'icon-category-monitoring',
|
||||
text: t('social', 'Local timeline'),
|
||||
router: {
|
||||
name: 'timeline',
|
||||
params: { type: 'timeline' }
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'social-direct-messages',
|
||||
id: 'social-global',
|
||||
classes: [],
|
||||
href: '#',
|
||||
icon: 'icon-comment',
|
||||
utils: {
|
||||
counter: 3
|
||||
},
|
||||
text: t('social', 'Direct messages')
|
||||
icon: 'icon-link',
|
||||
text: t('social', 'Global timeline'),
|
||||
router: {
|
||||
name: 'timeline',
|
||||
params: { type: 'federated' }
|
||||
}
|
||||
}
|
||||
]
|
||||
return {
|
||||
|
|
|
@ -33,13 +33,13 @@
|
|||
|
||||
<ul class="user-profile--sections">
|
||||
<li>
|
||||
<router-link to="./" class="icon-category-monitoring">{{ accountInfo.posts }} posts</router-link>
|
||||
<router-link :to="{ name: 'profile', params: { account: $route.params.account }}" class="icon-category-monitoring">{{ accountInfo.posts }} posts</router-link>
|
||||
</li>
|
||||
<li>
|
||||
<router-link to="./following" class="icon-category-social">{{ accountInfo.following }} following</router-link>
|
||||
<router-link :to="{ name: 'following', params: { account: $route.params.account }}" class="icon-category-social">{{ accountInfo.following }} following</router-link>
|
||||
</li>
|
||||
<li>
|
||||
<router-link to="./followers" class="icon-category-social">{{ accountInfo.followers }} followers</router-link>
|
||||
<router-link :to="{ name: 'followers', params: { account: $route.params.account }}" class="icon-category-social">{{ accountInfo.followers }} followers</router-link>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
|
@ -41,6 +41,10 @@ export default new Router({
|
|||
routes: [
|
||||
{
|
||||
path: '/:index(index.php/)?apps/social/',
|
||||
redirect: { name: 'timeline' }
|
||||
},
|
||||
{
|
||||
path: '/:index(index.php/)?apps/social/timeline/:type?',
|
||||
components: {
|
||||
default: Timeline
|
||||
},
|
||||
|
@ -48,7 +52,7 @@ export default new Router({
|
|||
name: 'timeline'
|
||||
},
|
||||
{
|
||||
path: '/:index(index.php/)?apps/social/account/:account',
|
||||
path: '/:index(index.php/)?apps/social/account/@:account',
|
||||
components: {
|
||||
default: Profile
|
||||
},
|
||||
|
@ -78,7 +82,7 @@ export default new Router({
|
|||
]
|
||||
},
|
||||
{
|
||||
path: '/:index(index.php/)?apps/social/:account',
|
||||
path: '/:index(index.php/)?apps/social/@:account',
|
||||
component: Profile,
|
||||
props: true,
|
||||
name: 'public'
|
||||
|
|
|
@ -25,18 +25,25 @@ import Vue from 'vue'
|
|||
|
||||
const state = {
|
||||
timeline: {},
|
||||
since: new Date()
|
||||
since: Math.floor(Date.now() / 1000) + 1,
|
||||
type: 'home'
|
||||
}
|
||||
const mutations = {
|
||||
addToTimeline(state, data) {
|
||||
for (let item in data) {
|
||||
state.since = data[item].published
|
||||
state.since = data[item].publishedTime
|
||||
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 = {}
|
||||
},
|
||||
setTimelineType(state, type) {
|
||||
state.type = type
|
||||
}
|
||||
}
|
||||
const getters = {
|
||||
|
@ -47,6 +54,10 @@ const getters = {
|
|||
}
|
||||
}
|
||||
const actions = {
|
||||
changeTimelineType(context, type) {
|
||||
context.commit('resetTimeline')
|
||||
context.commit('setTimelineType', type)
|
||||
},
|
||||
post(context, post) {
|
||||
return axios.post(OC.generateUrl('apps/social/api/v1/post'), { data: post }).then((response) => {
|
||||
context.commit('addPost', { data: response.data })
|
||||
|
@ -60,9 +71,9 @@ const actions = {
|
|||
},
|
||||
fetchTimeline(context, { account, sinceTimestamp }) {
|
||||
if (typeof sinceTimestamp === 'undefined') {
|
||||
sinceTimestamp = Date.parse(state.since) / 1000
|
||||
sinceTimestamp = state.since - 1
|
||||
}
|
||||
return axios.get(OC.generateUrl('apps/social/api/v1/stream/timeline?limit=5&since=' + sinceTimestamp)).then((response) => {
|
||||
return axios.get(OC.generateUrl(`apps/social/api/v1/stream/${state.type}?limit=5&since=` + sinceTimestamp)).then((response) => {
|
||||
if (response.status === -1) {
|
||||
throw response.message
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<template>
|
||||
<div class="social__wrapper">
|
||||
{{ type }}
|
||||
<div class="social__container">
|
||||
<transition name="slide-fade">
|
||||
<div v-if="showInfo" class="social__welcome">
|
||||
|
@ -124,6 +125,12 @@ export default {
|
|||
}
|
||||
},
|
||||
computed: {
|
||||
type: function() {
|
||||
if (this.$route.params.type) {
|
||||
return this.$route.params.type
|
||||
}
|
||||
return 'home'
|
||||
},
|
||||
url: function() {
|
||||
return OC.linkTo('social', 'img/nextcloud.png')
|
||||
},
|
||||
|
@ -181,7 +188,7 @@ export default {
|
|||
}
|
||||
},
|
||||
beforeMount: function() {
|
||||
|
||||
this.$store.dispatch('changeTimelineType', this.type)
|
||||
},
|
||||
methods: {
|
||||
hideInfo() {
|
||||
|
@ -201,6 +208,7 @@ export default {
|
|||
}).catch((error) => {
|
||||
OC.Notification.showTemporary('Failed to load more timeline entries')
|
||||
console.error('Failed to load more timeline entries', error)
|
||||
$state.complete()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue