2018-10-10 07:46:26 +00:00
|
|
|
/*
|
|
|
|
* @copyright Copyright (c) 2018 Julius Härtl <jus@bitgrid.net>
|
|
|
|
*
|
|
|
|
* @author Julius Härtl <jus@bitgrid.net>
|
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-11-13 14:20:43 +00:00
|
|
|
import axios from 'nextcloud-axios'
|
|
|
|
|
2018-10-10 07:46:26 +00:00
|
|
|
const state = {
|
2018-11-13 14:20:43 +00:00
|
|
|
timeline: [],
|
2018-11-21 11:36:46 +00:00
|
|
|
since: new Date()
|
2018-10-26 08:33:27 +00:00
|
|
|
}
|
2018-10-10 07:46:26 +00:00
|
|
|
const mutations = {
|
|
|
|
addToTimeline(state, data) {
|
|
|
|
for (let item in data) {
|
2018-11-21 11:36:46 +00:00
|
|
|
state.since = data[item].published
|
2018-10-26 08:33:27 +00:00
|
|
|
state.timeline.push(data[item])
|
2018-10-10 07:46:26 +00:00
|
|
|
}
|
2018-11-21 14:23:25 +00:00
|
|
|
},
|
|
|
|
addPost(state, data) {
|
|
|
|
// FIXME: push data we receive to the timeline array
|
|
|
|
// state.timeline.push(data)
|
2018-10-10 07:46:26 +00:00
|
|
|
}
|
2018-10-26 08:33:27 +00:00
|
|
|
}
|
2018-10-10 07:46:26 +00:00
|
|
|
const getters = {
|
|
|
|
getTimeline(state) {
|
2018-10-26 08:33:27 +00:00
|
|
|
return state.timeline
|
2018-10-10 07:46:26 +00:00
|
|
|
}
|
2018-10-26 08:33:27 +00:00
|
|
|
}
|
2018-11-13 14:20:43 +00:00
|
|
|
const actions = {
|
|
|
|
post(context, post) {
|
2018-11-21 12:13:21 +00:00
|
|
|
return axios.post(OC.generateUrl('apps/social/api/v1/post'), { data: post }).then((response) => {
|
|
|
|
context.commit('addPost', { data: response.data })
|
2018-11-21 14:23:25 +00:00
|
|
|
}).catch((error) => {
|
|
|
|
OC.Notification.showTemporary('Failed to create a post')
|
|
|
|
console.error('Failed to create a post', error)
|
2018-11-13 14:20:43 +00:00
|
|
|
})
|
|
|
|
},
|
|
|
|
fetchTimeline(context, account) {
|
2018-11-21 11:36:46 +00:00
|
|
|
const sinceTimestamp = Date.parse(state.since) / 1000
|
2018-11-14 11:06:51 +00:00
|
|
|
return axios.get(OC.generateUrl('apps/social/api/v1/timeline?limit=5&since=' + sinceTimestamp)).then((response) => {
|
2018-11-19 20:54:26 +00:00
|
|
|
if (response.status === -1) {
|
2018-11-21 11:49:31 +00:00
|
|
|
throw response.message
|
2018-11-19 20:54:26 +00:00
|
|
|
}
|
2018-11-21 11:49:31 +00:00
|
|
|
context.commit('addToTimeline', response.data.result)
|
|
|
|
return response.data
|
2018-11-13 14:20:43 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2018-10-10 07:46:26 +00:00
|
|
|
|
2018-10-26 08:33:27 +00:00
|
|
|
export default { state, mutations, getters, actions }
|