'creator' field is missing in a post

I’m using ts-sdk 6.19.0 and running into this problem:
I’m fetching a post using PostRepository.getPost and I subscribe to its updates. When I add reaction to this post, using ReactionRepository.addReaction, post for some reason gives me undefined when I try to access ‘creator’ field which I use to display user’s avatar and name. Though reaction is added successfully.
This works only when I fetch only one post, when I use PostRepository.getPosts, and render all returned posts and then try to add reactions to some of them, it works fine.
What could be the possible reason of that? Is something wrong with my code or is it a bug?
Here is my useGetPost hook -

const useGetPost = (postId: string) => {
  const [post, setPost] = useState<SocialPost | null>(null);
  const { connectedToSocial } = useAppSelector(userSelectors.getUser);

  useEffect(() => {
    if (connectedToSocial) {
      const unsubscribe = PostRepository.getPost(
        postId,
        ({ data, loading, error }) => {
          if (error) {
            console.log('error fetching post', error);
            return;
          }

          if (!loading) {
            setPost(data);
            disposers.push(subscribeTopic(getPostTopic(data, SubscriptionLevels.POST)));
          }
        }
      );

      disposers.push(unsubscribe);
    }

    return () => {
      disposers.forEach((fn) => fn());
    };
  }, [connectedToSocial]);

  return post;
};

Hello, it seems like you’re getting updates for an object, could you please check this section

Getting Real Time updates for a collection: TypeScript Live Objects/Collections | Amity Docs

Hello @amitysupport.
Thanks for responding, I’ve checked this section multiple times. I don’t have any problems with post Collection. I have a separate page for each post, on this page I get post id and then I fetch this post using my useGetPost hook which I’ve included above. Then when I try to add reaction to this post, like for example, it returns me updated post object but with creator field undefined which is confusing

Hello @denys_danyliuk , thank you for your clarification, let us pass to the team to further investigate this.

Thank you @amitysupport

@amitysupport also for some reason I don’t get live updates for the comments of post, I’ve subscribed to a postTopic with SubscriptionLevels.COMMENT, but it doesn’t work. Reaction is added only when I refresh the page, here is my updated useEffect -

useEffect(() => {
    if (connectedToSocial) {
      const unsubscribe = PostRepository.getPost(
        postId,
        ({ data, loading, error }) => {
          if (error) {
            console.log('error fetching post', error);
            return;
          }

          if (!loading) {
            setPost(data);

            if (isSubscribed) return;

            disposers.push(
              subscribeTopic(getPostTopic(data, SubscriptionLevels.POST))
            );
            disposers.push(
              subscribeTopic(getPostTopic(data, SubscriptionLevels.COMMENT))
            );
            isSubscribed = true;
            return;
          }
        }
      );
2 Likes

Acknowledged, I’ll pass this on to our team.

2 Likes

For this issue, we recommend that you try this code.

  const disposers: Amity.Unsubscriber[] = [];
  let isSubscribed = false;

  const subscribeCommentTopic = (
    referenceId: string,
    targetType: "user" | "community"
  ) => {
    if (isSubscribed) return;

    if (targetType === "user") {
      const unsubscribe = UserRepository.getUser(referenceId, (({ data }) => {
        if (data) {
          disposers.push(
            subscribeTopic(getUserTopic(data, SubscriptionLevels.COMMENT), () => {
              // use callback to handle errors with event subscription
            })
          );
        }
      }));
      isSubscribed = true;
      return;
    }

    if (targetType === "community") {

      const unsubscribe = CommunityRepository.getCommunity(referenceId, (({ data }) => {
        if (data) {
          disposers.push(
            subscribeTopic(
              getCommunityTopic(data, SubscriptionLevels.COMMENT),
              () => {
                // use callback to handle errors with event subscription
              }
            )
          );
        }

      }));

      isSubscribed = true;
    }
  };


  const getCommentData = () => {
    const getCommentsParams: Amity.CommentLiveCollection = {
      dataTypes: { matchType: 'any', values: ['text', 'image'] },
      referenceId: "660a2c1ada08428adf749ad9",
      referenceType: 'post',
      limit: 6,
      sortBy: 'lastCreated'
    }
    let addedComment = false;
    const unsubscribe = CommentRepository.getComments(
      getCommentsParams,
      ({ data, ...metaData }) => {
        console.log('metaData', metaData)
        console.log("data", data);
        if (metaData?.error) console.log(" error ");

        subscribeCommentTopic("targetId", "targetType");// if post come from user, targetType = user, targetId=userId
        // if post come from community,targetType = community, targetId=communityId
      }
    );
  };

@amitysupport it does work, thanks. But it’s inconvenient to subscribe to all user’s comments when all I need is to subscribe to particular post updates, including comments. Why when I subscribe to post updates using getPostTopic it doesn’t work?
Also, how to type correctly return value from CommentRepository.getComments? In typedef it says that data parameter of callback function supposed to return Amity.InternalComment array, but this type doesn’t include creator field, at the same time there is type Amity.Comment which is more likely to be what the method actually returns, because creator field is present in all comments
Знімок екрана 2024-04-11 о 10.57.49

@denys_danyliuk We apologize for the inconvenience, and we appreciate your feedback. We will forward your feedback to the relevant team for further product development. Regarding the issue with the ‘creator’ field missing in a post, our team is currently investigating it. We will keep you updated on any progress.

@amitysupport thank you

Hello @denys_danyliuk , For the issue with the ‘creator’ field missing in a post, our team has now released a fix in Version v6.21.1. You can check it at this link: Amity TypeScript SDK on npm. Please try again, and if the issue persists, let us know.