kopia lustrzana https://github.com/nextcloud/social
Merge branch 'master' into enh/noid/account-statuses
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>pull/1583/head
commit
74f1a6f70d
|
@ -83,6 +83,7 @@ return [
|
||||||
['name' => 'Api#notifications', 'url' => '/api/v1/notifications', 'verb' => 'GET'],
|
['name' => 'Api#notifications', 'url' => '/api/v1/notifications', 'verb' => 'GET'],
|
||||||
['name' => 'Api#tag', 'url' => '/api/v1/timelines/tag/{hashtag}', 'verb' => 'GET'],
|
['name' => 'Api#tag', 'url' => '/api/v1/timelines/tag/{hashtag}', 'verb' => 'GET'],
|
||||||
['name' => 'Api#statusNew', 'url' => '/api/v1/statuses', 'verb' => 'POST'],
|
['name' => 'Api#statusNew', 'url' => '/api/v1/statuses', 'verb' => 'POST'],
|
||||||
|
['name' => 'Api#timelines', 'url' => '/api/v1/timelines/{timeline}/', 'verb' => 'GET'],
|
||||||
['name' => 'Api#accountStatuses', 'url' => '/api/v1/accounts/{account}/statuses', 'verb' => 'GET'],
|
['name' => 'Api#accountStatuses', 'url' => '/api/v1/accounts/{account}/statuses', 'verb' => 'GET'],
|
||||||
|
|
||||||
// Api for local front-end
|
// Api for local front-end
|
||||||
|
|
|
@ -248,6 +248,7 @@ class ApiController extends Controller {
|
||||||
* @param int $limit
|
* @param int $limit
|
||||||
* @param int $max_id
|
* @param int $max_id
|
||||||
* @param int $min_id
|
* @param int $min_id
|
||||||
|
* @param int $since_id
|
||||||
*
|
*
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
|
@ -257,7 +258,7 @@ class ApiController extends Controller {
|
||||||
int $limit = 20,
|
int $limit = 20,
|
||||||
int $max_id = 0,
|
int $max_id = 0,
|
||||||
int $min_id = 0,
|
int $min_id = 0,
|
||||||
int $since = 0
|
int $since_id = 0
|
||||||
): DataResponse {
|
): DataResponse {
|
||||||
try {
|
try {
|
||||||
$this->initViewer(true);
|
$this->initViewer(true);
|
||||||
|
@ -269,7 +270,7 @@ class ApiController extends Controller {
|
||||||
->setLimit($limit)
|
->setLimit($limit)
|
||||||
->setMaxId($max_id)
|
->setMaxId($max_id)
|
||||||
->setMinId($min_id)
|
->setMinId($min_id)
|
||||||
->setSince($since);
|
->setSince($since_id);
|
||||||
|
|
||||||
$posts = $this->streamService->getTimeline($options);
|
$posts = $this->streamService->getTimeline($options);
|
||||||
|
|
||||||
|
@ -328,7 +329,7 @@ class ApiController extends Controller {
|
||||||
* @param int $limit
|
* @param int $limit
|
||||||
* @param int $max_id
|
* @param int $max_id
|
||||||
* @param int $min_id
|
* @param int $min_id
|
||||||
* @param int $since
|
* @param int $since_id
|
||||||
*
|
*
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
|
@ -336,7 +337,7 @@ class ApiController extends Controller {
|
||||||
int $limit = 20,
|
int $limit = 20,
|
||||||
int $max_id = 0,
|
int $max_id = 0,
|
||||||
int $min_id = 0,
|
int $min_id = 0,
|
||||||
int $since = 0
|
int $since_id = 0
|
||||||
): DataResponse {
|
): DataResponse {
|
||||||
try {
|
try {
|
||||||
$this->initViewer(true);
|
$this->initViewer(true);
|
||||||
|
@ -347,7 +348,7 @@ class ApiController extends Controller {
|
||||||
->setLimit($limit)
|
->setLimit($limit)
|
||||||
->setMaxId($max_id)
|
->setMaxId($max_id)
|
||||||
->setMinId($min_id)
|
->setMinId($min_id)
|
||||||
->setSince($since);
|
->setSince($since_id);
|
||||||
|
|
||||||
$posts = $this->streamService->getTimeline($options);
|
$posts = $this->streamService->getTimeline($options);
|
||||||
|
|
||||||
|
@ -368,7 +369,7 @@ class ApiController extends Controller {
|
||||||
int $limit = 20,
|
int $limit = 20,
|
||||||
int $max_id = 0,
|
int $max_id = 0,
|
||||||
int $min_id = 0,
|
int $min_id = 0,
|
||||||
int $since = 0,
|
int $since_id = 0,
|
||||||
array $types = [],
|
array $types = [],
|
||||||
array $exclude_types = [],
|
array $exclude_types = [],
|
||||||
string $accountId = ''
|
string $accountId = ''
|
||||||
|
@ -382,7 +383,7 @@ class ApiController extends Controller {
|
||||||
->setLimit($limit)
|
->setLimit($limit)
|
||||||
->setMaxId($max_id)
|
->setMaxId($max_id)
|
||||||
->setMinId($min_id)
|
->setMinId($min_id)
|
||||||
->setSince($since)
|
->setSince($since_id)
|
||||||
->setTypes($types)
|
->setTypes($types)
|
||||||
->setExcludeTypes($exclude_types)
|
->setExcludeTypes($exclude_types)
|
||||||
->setAccountId($accountId);
|
->setAccountId($accountId);
|
||||||
|
@ -407,7 +408,7 @@ class ApiController extends Controller {
|
||||||
int $limit = 20,
|
int $limit = 20,
|
||||||
int $max_id = 0,
|
int $max_id = 0,
|
||||||
int $min_id = 0,
|
int $min_id = 0,
|
||||||
int $since = 0,
|
int $since_id = 0,
|
||||||
bool $local = false,
|
bool $local = false,
|
||||||
bool $only_media = false
|
bool $only_media = false
|
||||||
): DataResponse {
|
): DataResponse {
|
||||||
|
@ -420,7 +421,7 @@ class ApiController extends Controller {
|
||||||
->setLimit($limit)
|
->setLimit($limit)
|
||||||
->setMaxId($max_id)
|
->setMaxId($max_id)
|
||||||
->setMinId($min_id)
|
->setMinId($min_id)
|
||||||
->setSince($since)
|
->setSince($since_id)
|
||||||
->setLocal($local)
|
->setLocal($local)
|
||||||
->setOnlyMedia($only_media)
|
->setOnlyMedia($only_media)
|
||||||
->setArgument($hashtag);
|
->setArgument($hashtag);
|
||||||
|
|
|
@ -23,10 +23,13 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import logger from '../services/logger.js'
|
|
||||||
import axios from '@nextcloud/axios'
|
|
||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
|
|
||||||
|
import axios from '@nextcloud/axios'
|
||||||
import { generateUrl } from '@nextcloud/router'
|
import { generateUrl } from '@nextcloud/router'
|
||||||
|
import { showError } from '@nextcloud/dialogs'
|
||||||
|
|
||||||
|
import logger from '../services/logger.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {object} timeline - The posts' collection
|
* @property {object} timeline - The posts' collection
|
||||||
|
@ -48,8 +51,10 @@ 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,
|
||||||
|
@ -153,7 +158,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) {
|
||||||
OC.Notification.showTemporary('Failed to create a post')
|
showError('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 })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -162,7 +167,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) => {
|
||||||
OC.Notification.showTemporary('Failed to delete the post')
|
showError('Failed to delete the post')
|
||||||
logger.error('Failed to delete the post', { error })
|
logger.error('Failed to delete the post', { error })
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
@ -172,7 +177,7 @@ const actions = {
|
||||||
context.commit('likePost', { post, parentAnnounce })
|
context.commit('likePost', { post, parentAnnounce })
|
||||||
resolve(response)
|
resolve(response)
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
OC.Notification.showTemporary('Failed to like post')
|
showError('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)
|
||||||
})
|
})
|
||||||
|
@ -186,7 +191,7 @@ const actions = {
|
||||||
context.commit('removePost', post)
|
context.commit('removePost', post)
|
||||||
}
|
}
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
OC.Notification.showTemporary('Failed to unlike post')
|
showError('Failed to unlike post')
|
||||||
logger.error('Failed to unlike post', { error })
|
logger.error('Failed to unlike post', { error })
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
@ -197,7 +202,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) => {
|
||||||
OC.Notification.showTemporary('Failed to create a boost post')
|
showError('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)
|
||||||
})
|
})
|
||||||
|
@ -208,43 +213,62 @@ 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) => {
|
||||||
OC.Notification.showTemporary('Failed to delete the boost')
|
showError('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 }) {
|
/**
|
||||||
|
*
|
||||||
if (typeof sinceTimestamp === 'undefined') {
|
* @param {object} context
|
||||||
sinceTimestamp = state.since - 1
|
* @param {object} params - see https://docs.joinmastodon.org/methods/timelines
|
||||||
|
* @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
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute URl to get the data
|
if (params.limit === undefined) {
|
||||||
|
params.limit = 15
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compute URL to get the data
|
||||||
let url = ''
|
let url = ''
|
||||||
if (state.type === 'account') {
|
switch (state.type) {
|
||||||
url = generateUrl(`apps/social/api/v1/account/${state.account}/stream?limit=25&since=` + sinceTimestamp)
|
case 'account':
|
||||||
} else if (state.type === 'tags') {
|
// TODO: wait for maxence
|
||||||
url = generateUrl(`apps/social/api/v1/stream/tag/${state.params.tag}?limit=25&since=` + sinceTimestamp)
|
url = generateUrl(`apps/social/api/v1/timelines/${state.account}`, params)
|
||||||
} else if (state.type === 'single-post') {
|
break
|
||||||
url = generateUrl(`apps/social/local/v1/post/replies?id=${state.params.id}&limit=5&since=` + sinceTimestamp)
|
case 'tags':
|
||||||
} else {
|
url = generateUrl(`apps/social/api/v1/timelines/tag/${state.params.tag}`, params)
|
||||||
url = generateUrl(`apps/social/api/v1/stream/${state.type}?limit=25&since=` + sinceTimestamp)
|
break
|
||||||
|
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
|
||||||
return axios.get(url).then((response) => {
|
const response = await axios.get(url)
|
||||||
|
|
||||||
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)
|
||||||
|
|
Ładowanie…
Reference in New Issue