Add real time messaging
This commit is contained in:
parent
0163eab540
commit
9153ba841d
61 changed files with 882 additions and 230 deletions
56
src/services/message/message.ts
Normal file
56
src/services/message/message.ts
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
import {
|
||||
fetchMessageApi,
|
||||
createMessageApi,
|
||||
updateMessageApi,
|
||||
removeMessageApi,
|
||||
} from "../../api/message";
|
||||
import { MessageActionTypes } from "../../store/message";
|
||||
import { dispatch } from "../../store/state";
|
||||
|
||||
const fetchMessage = async (id: string) => {
|
||||
const data = await fetchMessageApi({
|
||||
id: id,
|
||||
});
|
||||
|
||||
dispatch({
|
||||
type: MessageActionTypes.FETCH_MESSAGE_FINISH,
|
||||
payload: data,
|
||||
});
|
||||
};
|
||||
|
||||
const createMessage = async (text: string, channelId: string) => {
|
||||
const data = await createMessageApi({
|
||||
text: text,
|
||||
channelId: channelId,
|
||||
});
|
||||
|
||||
dispatch({
|
||||
type: MessageActionTypes.CREATE_MESSAGE_FINISH,
|
||||
payload: data,
|
||||
});
|
||||
};
|
||||
|
||||
const updateMessage = async (id: string, text: string) => {
|
||||
const data = await updateMessageApi({
|
||||
id: id,
|
||||
text: text,
|
||||
});
|
||||
|
||||
dispatch({
|
||||
type: MessageActionTypes.UPDATE_MESSAGE_FINISH,
|
||||
payload: data,
|
||||
});
|
||||
};
|
||||
|
||||
const removeMessage = async (id: string) => {
|
||||
const data = await removeMessageApi({
|
||||
id: id,
|
||||
});
|
||||
|
||||
dispatch({
|
||||
type: MessageActionTypes.REMOVE_MESSAGE_FINISH,
|
||||
payload: data,
|
||||
});
|
||||
};
|
||||
|
||||
export { fetchMessage, createMessage, updateMessage, removeMessage };
|
||||
Loading…
Add table
Add a link
Reference in a new issue