feat: add support for anonymous posting

Hooks up the configuration API to allow posting threads anonymously.
This commit is contained in:
Kshitij Sobti
2021-11-09 18:49:23 +05:30
parent 6bd7ce929d
commit 18d19369a9
15 changed files with 211 additions and 34 deletions

View File

@@ -78,9 +78,23 @@ export async function getThread(threadId) {
* @param {string} title
* @param {string} content
* @param {boolean} following Follow the thread after creating
* @param {boolean} anonymous Should the thread be anonymous to all users
* @param {boolean} anonymousToPeers Should the thread be anonymous to peers
* @returns {Promise<{}>}
*/
export async function postThread(courseId, topicId, type, title, content, following = false, cohort) {
export async function postThread(
courseId,
topicId,
type,
title,
content,
{
following,
cohort,
anonymous,
anonymousToPeers,
} = {},
) {
const postData = snakeCaseObject({
courseId,
topicId,
@@ -88,10 +102,13 @@ export async function postThread(courseId, topicId, type, title, content, follow
title,
raw_body: content,
following,
anonymous,
anonymousToPeers,
groupId: cohort,
});
const { data } = await getAuthenticatedHttpClient().post(threadsApiUrl, postData);
const { data } = await getAuthenticatedHttpClient()
.post(threadsApiUrl, postData);
return data;
}
@@ -146,7 +163,8 @@ export async function updateThread(threadId, {
*/
export async function deleteThread(threadId) {
const url = `${threadsApiUrl}${threadId}/`;
await getAuthenticatedHttpClient().delete(url);
await getAuthenticatedHttpClient()
.delete(url);
}
/**

View File

@@ -170,7 +170,9 @@ export function createNewThread({
type,
title,
content,
following = false,
following,
anonymous,
anonymousToPeers,
cohort,
}) {
return async (dispatch) => {
@@ -182,9 +184,16 @@ export function createNewThread({
title,
content,
following,
anonymous,
anonymousToPeers,
cohort,
}));
const data = await postThread(courseId, topicId, type, title, content, following, cohort);
const data = await postThread(courseId, topicId, type, title, content, {
cohort,
following,
anonymous,
anonymousToPeers,
});
dispatch(postThreadSuccess(camelCaseObject(data)));
} catch (error) {
if (getHttpErrorStatus(error) === 403) {