diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 5de0a457..94da6d10 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -29,6 +29,12 @@ const QVITTER_USER_TIMELINE_URL = '/api/qvitter/statuses/user_timeline.json' const BLOCKING_URL = '/api/blocks/create.json' const UNBLOCKING_URL = '/api/blocks/destroy.json' const USER_URL = '/api/users/show.json' +const GROUP_TIMELINE_URL = '/api/statusnet/groups/timeline' +const GROUP_JOINING_URL = '/api/statusnet/groups/join' +const GROUP_LEAVING_URL = '/api/statusnet/groups/leave' +const GROUP_CREATE_URL = '/api/statusnet/groups/create.json' +const USER_MEMBERSHIPS_URL = '/api/statusnet/groups/list.json' +const GROUP_MEMBERS_URL = '/api/statusnet/groups/membership' import { each, map } from 'lodash' import 'whatwg-fetch' @@ -261,7 +267,8 @@ const fetchTimeline = ({timeline, credentials, since = false, until = false, use mentions: MENTIONS_URL, 'publicAndExternal': PUBLIC_AND_EXTERNAL_TIMELINE_URL, user: QVITTER_USER_TIMELINE_URL, - tag: TAG_TIMELINE_URL + tag: TAG_TIMELINE_URL, + group: GROUP_TIMELINE_URL } let url = timelineUrls[timeline] @@ -358,6 +365,51 @@ const fetchMutes = ({credentials}) => { }).then((data) => data.json()) } +const joinGroup = ({id, credentials}) => { + const url = `${GROUP_JOINING_URL}/id.json` + + return fetch(url, { + headers: authHeaders(credentials) + }).then((data) => data.json()) +} + +const leaveGroup = ({id, credentials}) => { + const url = `${GROUP_LEAVING_URL}/id.json` + + return fetch(url, { + headers: authHeaders(credentials) + }).then((data) => data.json()) +} + +const createGroup = ({params, credentials}) => { + const form = new FormData() + + each(params, (value, key) => { + if (value) { + form.append(key, value) + } + }) + + return fetch(GROUP_CREATE_URL, { + method: 'POST', + body: form + }) +} + +const fetchMemberships = ({id, credentials}) => { + const url = `${USER_MEMBERSHIPS_URL}?user_id=${id}` + + return fetch(url, { + headers: authHeaders(credentials) + }).then((data) => data.json()) +} + +const fetchMembers = (id) => { + const url = `${GROUP_MEMBERS_URL}/${id}.json` + + return fetch(url).then((data) => data.json()) +} + const apiService = { verifyCredentials, fetchTimeline, @@ -384,7 +436,12 @@ const apiService = { updateBg, updateProfile, updateBanner, - externalProfile + externalProfile, + joinGroup, + leaveGroup, + createGroup, + fetchMemberships, + fetchMembers } export default apiService diff --git a/src/services/backend_interactor_service/backend_interactor_service.js b/src/services/backend_interactor_service/backend_interactor_service.js index ddaae3b2..c2f19bde 100644 --- a/src/services/backend_interactor_service/backend_interactor_service.js +++ b/src/services/backend_interactor_service/backend_interactor_service.js @@ -50,6 +50,24 @@ const backendInteractorService = (credentials) => { return apiService.setUserMute({id, muted, credentials}) } + const joinGroup = (id) => { + return apiService.joinGroup({id, credentials}) + } + + const leaveGroup = (id) => { + return apiService.leaveGroup({id, credentials}) + } + + const fetchMemberships = (id) => { + return apiService.fetchMemberships({id, credentials}) + } + + const fetchMembers = (id) => { + return apiService.fetchMemberships({id, credentials}) + } + + const createGroup = (params) => apiService.createGroup({params, credentials}) + const fetchMutes = () => apiService.fetchMutes({credentials}) const register = (params) => apiService.register(params) @@ -80,7 +98,12 @@ const backendInteractorService = (credentials) => { updateBg, updateBanner, updateProfile, - externalProfile + externalProfile, + joinGroup, + leaveGroup, + createGroup, + fetchMemberships, + fetchMembers } return backendInteractorServiceInstance