Revert "Merge pull request #1581 from nextcloud/artonge/feat/use_new_api"

**This only reverts the js part of** commit 6eb5150698, reversing
changes made to f56e326f80.

Signed-off-by: Louis Chemineau <louis@chmn.me>
pull/1587/head
Louis Chemineau 2023-01-18 15:24:40 +01:00
rodzic f0fb3970d2
commit c4eef0b2d4
1 zmienionych plików z 31 dodań i 55 usunięć

Wyświetl plik

@ -23,13 +23,10 @@
* *
*/ */
import Vue from 'vue'
import axios from '@nextcloud/axios'
import { generateUrl } from '@nextcloud/router'
import { showError } from '@nextcloud/dialogs'
import logger from '../services/logger.js' import logger from '../services/logger.js'
import axios from '@nextcloud/axios'
import Vue from 'vue'
import { generateUrl } from '@nextcloud/router'
/** /**
* @property {object} timeline - The posts' collection * @property {object} timeline - The posts' collection
@ -51,10 +48,8 @@ const state = {
*/ */
params: {}, params: {},
account: '', account: '',
/** /* Tells whether the composer should be displayed or not.
* Tells whether the composer should be displayed or not.
* It's up to the view to honor this status or not. * It's up to the view to honor this status or not.
*
* @member {boolean} * @member {boolean}
*/ */
composerDisplayStatus: false, composerDisplayStatus: false,
@ -158,7 +153,7 @@ const actions = {
}) })
logger.info('Post created with token ' + data.result.token) logger.info('Post created with token ' + data.result.token)
} catch (error) { } catch (error) {
showError('Failed to create a post') OC.Notification.showTemporary('Failed to create a post')
logger.error('Failed to create a post', { error: error.response }) logger.error('Failed to create a post', { error: error.response })
} }
}, },
@ -167,7 +162,7 @@ const actions = {
context.commit('removePost', post) context.commit('removePost', post)
logger.info('Post deleted with token ' + response.data.result.token) logger.info('Post deleted with token ' + response.data.result.token)
}).catch((error) => { }).catch((error) => {
showError('Failed to delete the post') OC.Notification.showTemporary('Failed to delete the post')
logger.error('Failed to delete the post', { error }) logger.error('Failed to delete the post', { error })
}) })
}, },
@ -177,7 +172,7 @@ const actions = {
context.commit('likePost', { post, parentAnnounce }) context.commit('likePost', { post, parentAnnounce })
resolve(response) resolve(response)
}).catch((error) => { }).catch((error) => {
showError('Failed to like post') OC.Notification.showTemporary('Failed to like post')
logger.error('Failed to like post', { error: error.response }) logger.error('Failed to like post', { error: error.response })
reject(error) reject(error)
}) })
@ -191,7 +186,7 @@ const actions = {
context.commit('removePost', post) context.commit('removePost', post)
} }
}).catch((error) => { }).catch((error) => {
showError('Failed to unlike post') OC.Notification.showTemporary('Failed to unlike post')
logger.error('Failed to unlike post', { error }) logger.error('Failed to unlike post', { error })
}) })
}, },
@ -202,7 +197,7 @@ const actions = {
logger.info('Post boosted with token ' + response.data.result.token) logger.info('Post boosted with token ' + response.data.result.token)
resolve(response) resolve(response)
}).catch((error) => { }).catch((error) => {
showError('Failed to create a boost post') OC.Notification.showTemporary('Failed to create a boost post')
logger.error('Failed to create a boost post', { error: error.response }) logger.error('Failed to create a boost post', { error: error.response })
reject(error) reject(error)
}) })
@ -213,62 +208,43 @@ const actions = {
context.commit('unboostPost', { post, parentAnnounce }) context.commit('unboostPost', { post, parentAnnounce })
logger.info('Boost deleted with token ' + response.data.result.token) logger.info('Boost deleted with token ' + response.data.result.token)
}).catch((error) => { }).catch((error) => {
showError('Failed to delete the boost') OC.Notification.showTemporary('Failed to delete the boost')
logger.error('Failed to delete the boost', { error }) logger.error('Failed to delete the boost', { error })
}) })
}, },
refreshTimeline(context) { refreshTimeline(context) {
return this.dispatch('fetchTimeline', { sinceTimestamp: Math.floor(Date.now() / 1000) + 1 }) return this.dispatch('fetchTimeline', { sinceTimestamp: Math.floor(Date.now() / 1000) + 1 })
}, },
/** fetchTimeline(context, { sinceTimestamp }) {
*
* @param {object} context if (typeof sinceTimestamp === 'undefined') {
* @param {object} params - see https://docs.joinmastodon.org/methods/timelines sinceTimestamp = state.since - 1
* @param {number} [params.since_id] - Fetch results newer than ID
* @param {number} [params.max_id] - Fetch results older than ID
* @param {number} [params.min_id] - Fetch results immediately newer than ID
* @param {number} [params.limit] - Maximum number of results to return. Defaults to 20 statuses. Max 40 statuses
* @param {number} [params.local] - Show only local statuses? Defaults to false.
* @return {Promise<object>}
*/
async fetchTimeline(context, params = {}) {
if (params.since_id === undefined) {
params.since_id = state.since_id - 1
} }
if (params.limit === undefined) { // Compute URl to get the data
params.limit = 15
}
// Compute URL to get the data
let url = '' let url = ''
switch (state.type) { if (state.type === 'account') {
case 'account': url = generateUrl(`apps/social/api/v1/account/${state.account}/stream?limit=25&since=` + sinceTimestamp)
// TODO: wait for maxence } else if (state.type === 'tags') {
url = generateUrl(`apps/social/api/v1/timelines/${state.account}`, params) url = generateUrl(`apps/social/api/v1/stream/tag/${state.params.tag}?limit=25&since=` + sinceTimestamp)
break } else if (state.type === 'single-post') {
case 'tags': url = generateUrl(`apps/social/local/v1/post/replies?id=${state.params.id}&limit=5&since=` + sinceTimestamp)
url = generateUrl(`apps/social/api/v1/timelines/tag/${state.params.tag}`, params) } else {
break url = generateUrl(`apps/social/api/v1/stream/${state.type}?limit=25&since=` + sinceTimestamp)
case 'single-post':
// TODO: wait for maxence
url = generateUrl(`apps/social/local/v1/post/replies?id=${state.params.id}`, params)
break
default:
url = generateUrl(`apps/social/api/v1/timelines/${state.type}`, params)
} }
// Get the data and add them to the timeline // Get the data and add them to the timeline
const response = await axios.get(url) return axios.get(url).then((response) => {
if (response.status === -1) { if (response.status === -1) {
throw response.message throw response.message
} }
// Add results to timeline // Add results to timeline
context.commit('addToTimeline', response.data.result) context.commit('addToTimeline', response.data.result)
return response.data return response.data
})
}, },
addToTimeline(context, data) { addToTimeline(context, data) {
context.commit('addToTimeline', data) context.commit('addToTimeline', data)