Hey I use amity sdk typescript when user click on the like button data not updated the response of the post kindly tell me how to do this
Hello, could you please help share the response screenshot, your ts sdk version and code sample?
Thanks for replying actually i use this function for like and dislike post aftre that donāt receive latest post dataPreformatted text
const handleLikePost = async () => {
// console.log(complete Item : ${JSON.stringify(item)}
);
if (!myReactions?.includes(āloveā)) {
ReactionRepository.addReaction(āpostā, postId, āloveā);
getPost();
// setLiked(true);
} else {
ReactionRepository.removeReaction(āpostā, postId, āloveā);
getPost();
// setLiked(false);
}
};
function getPost() {
PostRepository.getPost(postId, (data) => {
console.log(ālatest comment dataā>ā, data);
setPost(data?.data);
// setLatestComments(data?.data?.latestComments);
});
}
Hello,
We will escalate this matter to our team for thorough examination. Rest assured, we will keep you informed of any updates.
Hello @anser786 May I inquire about your current SDK version?
ā@amityco/ts-sdkā: ā^6.14.0ā,
Based on your code, getPost()
might be called before ReactionRepository.addReaction(āpostā, postId, āloveā);
is successfully called. Can you try adding await
in front of ReactionRepository and try calling getPost()
after that?
const isPostReactionAdded = await ReactionRepository.addReaction(
'post',
postId,
reactionName
);
if(isPostReactionAdded){
getPost()
}
I tried but face same issue.post data donāt updated after hit reaction api
Hello, @anser786 let me pass to may team check for you and iāll back to you.
Hey, I have a similar problem as mentioned above.
Iām subscribing to a bunch of posts based on a certain community ID. When Iām calling a CommentRepository service every post is updated accordingly without a need to refresh posts (calling a getPosts function again).
Itās sadly not a case for reactions. Looks like the subscription callback isnāt triggered for post reactions. Is that expected behavior?
(Iām using the same sdk version by the way)
It will be a different one from Reaction, but Can I see your code that youāre using?
Sure, here it is.
Itās a vue code, but I hope everything is straightforward.
const unsubscribe = ref<Amity.Unsubscriber>();
const posts = ref<Amity.Post<'text'>[]>([]);
const getPosts = () => {
unsubscribe.value = PostRepository.getPosts(getPostsParams, ({ data, loading, hasNextPage, onNextPage }) => {
posts.value = data;
});
};
Iām calling the getPosts function immediately after establishing the connection with Amity sdk
And there are button handlers:
const addPostReaction = async (type: Amity.ReactableType = 'post', postId: string, reaction = 'like') => {
await ReactionRepository.addReaction(type, postId, reaction);
};
const removePostReaction = async (type: Amity.ReactableType = 'post', postId: string, reaction = 'like') => {
await ReactionRepository.removeReaction(type, postId, reaction);
};
Thanks for the quick response, I appreciate that.
When I tried to subscribe to to PostTopic I stumbled on this error:
index.esm.js:20761 Failed to subscribe to topic 6552841adcf84ecddbf53c6b/social/community/65623a469ad025e5512235f5/post/+ Error: Amity SDK (800000): Unexpected error
at new ASCUnknownError (index.esm.js:804:9)
at callbackWrapper (index.esm.js:20759:29)
at cb (index.esm.js:2709:10)
at MqttClient._handleAck (index.esm.js:3526:8)
at MqttClient._handlePacket (index.esm.js:2419:13)
at work (index.esm.js:2315:13)
at writable._write (index.esm.js:2329:6)
at doWrite (index.esm.js:17546:140)
at writeOrBuffer (index.esm.js:17535:6)
at Writable.write (index.esm.js:17444:12)
To subscribe to to PostTopic, you need to run subscribeTopic
function first after you call getPosts
. Here is my example code
import { CommunityRepository, PostRepository, SubscriptionLevels, UserRepository, getCommunityTopic, getUserTopic, subscribeTopic } from '@amityco/ts-sdk-react-native';
const disposers: Amity.Unsubscriber[] = [];
let isSubscribed = false;
const subscribePostTopic = (targetType: string, targetId: string) => {
if (isSubscribed) return;
if (targetType === 'user') {
let user = {} as Amity.User; // use getUser to get user by targetId
UserRepository.getUser(targetId, ({ data }) => {
user = data
});
disposers.push(
subscribeTopic(getUserTopic(user, SubscriptionLevels.POST), () => {
// use callback to handle errors with event subscription
}),
);
isSubscribed = true;
return;
}
if (targetType === 'community') {
CommunityRepository.getCommunity(targetId, (data) => {
if (data.data) {
subscribeTopic(
getCommunityTopic(data.data, SubscriptionLevels.POST),
);
}
});
}
};
async function getFeed(): Promise<void> {
const unsubscribe = PostRepository.getPosts(
{ targetId, targetType, sortBy: 'lastCreated', limit: 10, feedType: 'published' },
(data) => {
setPostData(data);
subscribePostTopic(targetType, targetId)
}
);
}
I already use this subscribeTopic function when getPosts please check i face same problem with like updating
const subscribePostTopic = (targetType: string, targetId: string) => {
if (isSubscribed) return;
if (targetType === 'user') {
let user = {} as Amity.User; // use getUser to get user by targetId
UserRepository.getUser(targetId, ({ data }) => {
user = data;
});
disposers.push(
subscribeTopic(getUserTopic(user, SubscriptionLevels.POST), () => {
// use callback to handle errors with event subscription
}),
);
isSubscribed = true;
return;
}
if (targetType === 'community') {
CommunityRepository.getCommunity(targetId, (data) => {
if (data.data) {
subscribeTopic(getCommunityTopic(data.data, SubscriptionLevels.POST));
}
});
}
};
async function getFeed(props): Promise<void> {
// console.log('call');
const unsubscribe = PostRepository.getPosts(
{
targetId,
targetType,
...props,
},
(data) => {
console.log('Data from authProvider-->', data);
let slice = { ...data };
setPostData(slice);
subscribePostTopic(targetType, targetId);
},
);
disposers.push(unsubscribe);
}```
Hello! @anser786 Iāll pass to my team . After our recent holiday, weāre actively addressing it. Stay tuned for updates. Thanks for your patience!
Hello, could you please make sure that the user has successfully joined the community before proceeding to subscribe to the topic?
Is it necessary to join before subscribe to the topic?
okay now its working thanks