[#34] Adjust action to adjusted api
This commit is contained in:
parent
9bcaf35e99
commit
9ed6228013
|
|
@ -5,16 +5,27 @@ import {getToken} from './defaultAxios';
|
||||||
import {snack} from './GlobalAction';
|
import {snack} from './GlobalAction';
|
||||||
import * as UserAction from './UserAction';
|
import * as UserAction from './UserAction';
|
||||||
|
|
||||||
/** Fetches all messages from the current user. */
|
export function fetchMessagesApp(id, since) {
|
||||||
export function fetchMessages() {
|
if (id === -1) {
|
||||||
axios.get(config.get('url') + 'message').then((resp) => {
|
return axios.get(config.get('url') + 'message?since=' + since).then((resp) => {
|
||||||
dispatcher.dispatch({type: 'UPDATE_MESSAGES', payload: resp.data});
|
newMessages(-1, resp.data);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return axios.get(config.get('url') + 'application/' + id + '/message?since=' + since).then((resp) => {
|
||||||
|
newMessages(id, resp.data);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Deletes all messages from the current user. */
|
function newMessages(id, data) {
|
||||||
export function deleteMessages() {
|
dispatcher.dispatch({
|
||||||
axios.delete(config.get('url') + 'message').then(fetchMessages).then(() => snack('Messages deleted'));
|
type: 'UPDATE_MESSAGES', payload: {
|
||||||
|
messages: data.messages,
|
||||||
|
hasMore: 'next' in data.paging,
|
||||||
|
nextSince: data.paging.since,
|
||||||
|
id,
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -22,16 +33,25 @@ export function deleteMessages() {
|
||||||
* @param {int} id the application id
|
* @param {int} id the application id
|
||||||
*/
|
*/
|
||||||
export function deleteMessagesByApp(id) {
|
export function deleteMessagesByApp(id) {
|
||||||
axios.delete(config.get('url') + 'application/' + id + '/message').then(fetchMessages)
|
if (id === -1) {
|
||||||
.then(() => snack('Deleted all messages from the application'));
|
axios.delete(config.get('url') + 'message').then(() => {
|
||||||
|
dispatcher.dispatch({type: 'DELETE_MESSAGES', id: -1});
|
||||||
|
snack('Messages deleted');
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
axios.delete(config.get('url') + 'application/' + id + '/message')
|
||||||
|
.then(() => {
|
||||||
|
dispatcher.dispatch({type: 'DELETE_MESSAGES', id});
|
||||||
|
snack('Deleted all messages from the application');
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
export function deleteMessage(msg) {
|
||||||
* Deletes a message by id.
|
axios.delete(config.get('url') + 'message/' + msg.id).then(() => {
|
||||||
* @param {int} id the message id
|
dispatcher.dispatch({type: 'DELETE_MESSAGE', payload: msg});
|
||||||
*/
|
snack('Message deleted');
|
||||||
export function deleteMessage(id) {
|
});
|
||||||
axios.delete(config.get('url') + 'message/' + id).then(fetchMessages).then(() => snack('Message deleted'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let wsActive = false;
|
let wsActive = false;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue