aboutsummaryrefslogtreecommitdiff
path: root/src/services/CommentService.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/services/CommentService.ts')
-rw-r--r--src/services/CommentService.ts24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/services/CommentService.ts b/src/services/CommentService.ts
index e85b1991..b21c6dfd 100644
--- a/src/services/CommentService.ts
+++ b/src/services/CommentService.ts
@@ -3,11 +3,13 @@ import {Alert} from 'react-native';
import {
COMMENTS_ENDPOINT,
COMMENT_REACTIONS_ENDPOINT,
+ COMMENT_REACTIONS_REPLY_ENDPOINT,
COMMENT_THREAD_ENDPOINT,
} from '../constants';
import {ERROR_FAILED_TO_COMMENT} from '../constants/strings';
import {
CommentBaseType,
+ CommentThreadType,
CommentType,
ProfilePreviewType,
ReactionOptionsType,
@@ -133,12 +135,18 @@ export const deleteComment = async (id: string, isThread: boolean) => {
* @param comment the comment object that contains `user_reaction` (or not)
* @returns
*/
-export const handleLikeUnlikeComment = async (comment: CommentBaseType) => {
+export const handleLikeUnlikeComment = async (
+ comment: CommentType | CommentThreadType,
+) => {
try {
+ const isReply = 'parent_comment' in comment;
const token = await AsyncStorage.getItem('token');
+ let url = isReply
+ ? COMMENT_REACTIONS_REPLY_ENDPOINT
+ : COMMENT_REACTIONS_ENDPOINT;
if (comment.user_reaction !== null) {
// unlike a comment
- const url = COMMENT_REACTIONS_ENDPOINT + `${comment.user_reaction.id}/`;
+ url += `${comment.user_reaction.id}/`;
const response = await fetch(url, {
method: 'DELETE',
headers: {
@@ -148,7 +156,6 @@ export const handleLikeUnlikeComment = async (comment: CommentBaseType) => {
return response.status === 200;
} else {
// like a comment
- const url = COMMENT_REACTIONS_ENDPOINT;
const form = new FormData();
form.append('comment_id', comment.comment_id);
form.append('reaction_type', ReactionOptionsType.Like);
@@ -168,11 +175,16 @@ export const handleLikeUnlikeComment = async (comment: CommentBaseType) => {
}
};
-export const getUsersReactedToAComment = async (comment: CommentBaseType) => {
+export const getUsersReactedToAComment = async (
+ comment: CommentType | CommentThreadType,
+) => {
try {
+ const isReply = 'parent_comment' in comment;
const token = await AsyncStorage.getItem('token');
- const url =
- COMMENT_REACTIONS_ENDPOINT + `?comment_id=${comment.comment_id}`;
+ let url = isReply
+ ? COMMENT_REACTIONS_REPLY_ENDPOINT
+ : COMMENT_REACTIONS_ENDPOINT;
+ url += `?comment_id=${comment.comment_id}`;
const response = await fetch(url, {
method: 'GET',
headers: {