From 6695226e1291aaf5335c3022fd331c8f1e5a68db Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Thu, 14 Nov 2019 22:42:56 +0900 Subject: [PATCH] Add statuses page --- src/api/peers.js | 14 ++++++++ src/api/status.js | 9 +++++ src/lang/en.js | 4 +++ src/router/index.js | 15 ++++++++ src/store/getters.js | 2 ++ src/store/index.js | 2 ++ src/store/modules/peers.js | 28 +++++++++++++++ src/store/modules/status.js | 21 +++++++++++- src/views/statuses/index.vue | 66 ++++++++++++++++++++++++++++++++++++ 9 files changed, 160 insertions(+), 1 deletion(-) create mode 100644 src/api/peers.js create mode 100644 src/store/modules/peers.js create mode 100644 src/views/statuses/index.vue diff --git a/src/api/peers.js b/src/api/peers.js new file mode 100644 index 00000000..4b80d7ab --- /dev/null +++ b/src/api/peers.js @@ -0,0 +1,14 @@ +import request from '@/utils/request' +import { getToken } from '@/utils/auth' +import { baseName } from './utils' + +export async function fetchPeers(authHost, token) { + return await request({ + baseURL: baseName(authHost), + url: `/api/v1/instance/peers`, + method: 'get', + headers: authHeaders(token) + }) +} + +const authHeaders = (token) => token ? { 'Authorization': `Bearer ${getToken()}` } : {} diff --git a/src/api/status.js b/src/api/status.js index 7d931ae0..4b62da0b 100644 --- a/src/api/status.js +++ b/src/api/status.js @@ -21,4 +21,13 @@ export async function deleteStatus(id, authHost, token) { }) } +export async function fetchStatusesByInstance(instance, authHost, token) { + return await request({ + baseURL: baseName(authHost), + url: `/api/pleroma/admin/instances/${instance}/statuses`, + method: 'get', + headers: authHeaders(token) + }) +} + const authHeaders = (token) => token ? { 'Authorization': `Bearer ${getToken()}` } : {} diff --git a/src/lang/en.js b/src/lang/en.js index 41d7f54a..f9c56069 100644 --- a/src/lang/en.js +++ b/src/lang/en.js @@ -230,6 +230,10 @@ export default { passwordResetTokenCreated: 'Password reset token was created', accountCreated: 'New account was created!' }, + statuses: { + statuses: 'Statuses', + instanceFilter: 'Instance filter' + }, userProfile: { tags: 'Tags', moderator: 'Moderator', diff --git a/src/router/index.js b/src/router/index.js index b0e0d750..87a6295d 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -21,6 +21,20 @@ const settings = { ] } +const statusesDisabled = disabledFeatures.includes('statuses') +const statuses = { + path: '/statuses', + component: Layout, + children: [ + { + path: 'index', + component: () => import('@/views/statuses/index'), + name: 'Statuses', + meta: { title: 'Statuses', icon: 'form', noCache: true } + } + ] +} + const reportsDisabled = disabledFeatures.includes('reports') const reports = { path: '/reports', @@ -126,6 +140,7 @@ export const asyncRouterMap = [ } ] }, + ...(statusesDisabled ? [] : [statuses]), ...(settingsDisabled ? [] : [settings]), ...(reportsDisabled ? [] : [reports]), ...(invitesDisabled ? [] : [invites]), diff --git a/src/store/getters.js b/src/store/getters.js index 03899ea7..159fb48c 100644 --- a/src/store/getters.js +++ b/src/store/getters.js @@ -49,6 +49,7 @@ const getters = { http: state => state.settings.settings['http'], httpSecurity: state => state.settings.settings['http_security'], instance: state => state.settings.settings['instance'], + instances: state => state.peers.fetchedPeers, kocaptcha: state => state.settings.settings['Pleroma.Captcha.Kocaptcha'], level: state => state.settings.settings['level'], ldap: state => state.settings.settings['ldap'], @@ -82,6 +83,7 @@ const getters = { richMedia: state => state.settings.settings['rich_media'], suggestions: state => state.settings.settings['suggestions'], scheduledActivity: state => state.settings.settings['Pleroma.ScheduledActivity'], + statuses: state => state.status.fetchedStatuses, teslaAdapter: state => state.settings.settings['adapter'], twitter: state => state.settings.settings['Ueberauth.Strategy.Twitter.OAuth'], ueberauth: state => state.settings.settings['Ueberauth'], diff --git a/src/store/index.js b/src/store/index.js index 9a3cad50..0475c748 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -3,6 +3,7 @@ import Vuex from 'vuex' import app from './modules/app' import errorLog from './modules/errorLog' import invites from './modules/invites' +import peers from './modules/peers' import permission from './modules/permission' import reports from './modules/reports' import settings from './modules/settings' @@ -21,6 +22,7 @@ const store = new Vuex.Store({ app, errorLog, invites, + peers, permission, reports, settings, diff --git a/src/store/modules/peers.js b/src/store/modules/peers.js new file mode 100644 index 00000000..fa37a1d0 --- /dev/null +++ b/src/store/modules/peers.js @@ -0,0 +1,28 @@ +import { fetchPeers } from '@/api/peers' + +const peers = { + state: { + fetchedPeers: [], + loading: true + }, + + mutations: { + SET_PEERS: (state, peers) => { + state.fetchedPeers = peers + }, + SET_LOADING: (state, status) => { + state.loading = status + } + }, + + actions: { + async FetchPeers({ commit, getters }) { + const peers = await fetchPeers(getters.authHost, getters.token) + + commit('SET_PEERS', peers.data) + commit('SET_LOADING', false) + } + } +} + +export default peers diff --git a/src/store/modules/status.js b/src/store/modules/status.js index 15d1f1f7..a1a864b3 100644 --- a/src/store/modules/status.js +++ b/src/store/modules/status.js @@ -1,6 +1,18 @@ -import { changeStatusScope, deleteStatus } from '@/api/status' +import { changeStatusScope, deleteStatus, fetchStatusesByInstance } from '@/api/status' const status = { + state: { + fetchedStatuses: [], + loading: false + }, + mutations: { + SET_STATUSES: (state, statuses) => { + state.fetchedStatuses = statuses + }, + SET_LOADING: (state, status) => { + state.loading = status + } + }, actions: { async ChangeStatusScope({ dispatch, getters }, { statusId, isSensitive, visibility, reportCurrentPage, userId, godmode }) { await changeStatusScope(statusId, isSensitive, visibility, getters.authHost, getters.token) @@ -17,6 +29,13 @@ const status = { } else if (userId.length > 0) { dispatch('FetchUserStatuses', { userId, godmode }) } + }, + async FetchStatusesByInstance({ commit, getters }, instance) { + commit('SET_LOADING', true) + const statuses = await fetchStatusesByInstance(instance, getters.authHost, getters.token) + + commit('SET_STATUSES', statuses.data) + commit('SET_LOADING', false) } } } diff --git a/src/views/statuses/index.vue b/src/views/statuses/index.vue new file mode 100644 index 00000000..adf56052 --- /dev/null +++ b/src/views/statuses/index.vue @@ -0,0 +1,66 @@ + + + + +