Cannot update reactions on comments

I’m adding and removing reactions to comments. But the subscription to the comments of a Post is not reacting after adding or removing an action.

I’m using this method:

CommentRepository.getComments(
        { referenceType: 'post', referenceId, parentId, limit: 10, sortBy: 'firstCreated' },
        setComments,
);

Is there a better way to subscribe to the reactions of a specific comment?

Hi @fabianr

Which platform and version are you using?

Amity Support

I’m using React Native with Amity TS SDK

Do you have further information regarding this request?

We will require your sdk version as well, thank you.

@amityco/ts-sdk”: “^6.5.2”,

Hello, thank you for your patience. We are currently in touch with our engineering team and will promptly provide an update as soon as we receive one.

Hello, could you pls check the sample code below, this should address the reaction problem:

import { CommentRepository, CommunityRepository, SubscriptionLevels, UserRepository, getCommunityTopic, getUserTopic, subscribeTopic } from '@amityco/ts-sdk';


const [communityObject, setCommunityObject] = useState<Amity.Community>()
  const [userObject, setUserObject] = useState<Amity.User>()
  const [commentCollection, setCommentCollection] =useState<Amity.LiveCollection<Amity.Comment<any>>>();


 const subscribeCommentTopic = (targetType: string) => {
    if (isSubscribed) return;
  
    if (targetType === 'user' && userObject) {
      const user = userObject as Amity.User; // use getUser to get user by targetId
      disposers.push(
        subscribeTopic(getUserTopic(user, SubscriptionLevels.COMMENT), () => {
          // use callback to handle errors with event subscription
        }),
      );
      isSubscribed = true;
      return;
    }
  
    if (targetType === 'community' && communityObject) {
      console.log('communityObject:', communityObject)
      const community = communityObject as Amity.Community; // use getCommunity to get community by targetId
      disposers.push(
        subscribeTopic(getCommunityTopic(community, SubscriptionLevels.COMMENT), () => {
          // use callback to handle errors with event subscription
        }),
      );
      isSubscribed = true;
    }
  };

  function getCommentsByPostId(postId: string) {
    const unsubscribe = CommentRepository.getComments(
      {
        dataTypes: { matchType: 'any', values: ['text', 'image'] },
        referenceId: postId,
        referenceType: 'post',
      },
      (data: Amity.LiveCollection<Amity.Comment<any>>) => {
        if (data.error) throw data.error;
        if (!data.loading) {
          setCommentCollection(data);
        }
      }
    );

  }
  useEffect(() => {
    if(communityObject || userObject){
    console.log('postDetail.targetType:', postDetail.targetType)
      subscribeCommentTopic(postDetail.targetType as string);
    }
 
  }, [communityObject,userObject])
  
  useEffect(() => {
// targetType and targetId will be inside post object that you want to subscribe
    if(targetType === 'community'){
      CommunityRepository.getCommunity(postDetail.targetId, ({data: community})=>{
        setCommunityObject(community)
      });
    }else if(targetType === 'user'){
      UserRepository.getUser(postDetail.targetId, ({data: user})=>{
        setUserObject(user)
      });
    }
    getCommentsByPostId(postDetail.postId);
  }, [targetId, targetType]);