I stuck at the beginning, the error said getFollowInfo is not a function. After I installed @amityco/js-sdk it’s working but still stuck with Cannot read properly 'userId' of undefined even if I harded code the userId as below.
Hi @JustTod - getFollowInfo was just recently launched so can you check whether you’re on the most recent version of amityco/js-sdk ?
eko-sdk is already deprecated and does not support follow / unfollow feature
I’ve try to implement follow API, as you can see above.
I can get follow count by using getFollowInfo with currentUserId and targetUserId then getFollowCount with targetUserId
Then I tried to do it again with random string or dummy id like 12345678 for non-login user, but I can’t fix this error.
Hi @JustTod - our SDK must always be logged in or it won’t have the access token to invoke any method. Can you share more detail on the use case on why do you want to use this with non-logged in users?
I found it out by using random string when register to SDK. It’s working fine now.
But I have some concern. Would this random string will effected this system in the future or cause any bug?
Hi @JustTod - you’re randomly creating new users to connect to the service - this means you’re now creating new user every time getFollowInfo is invoked - and will cause lots of spam users + rack up MAU license charges.
Thanks for your information. We will create dummy user for non-login user to get the follow info.
And another problem for a newbie like me. I can’t get a correct data from the live object right on time. It seems like the program return before receive the data from live object.
This is my code.
Also, when I use the getFollowInfo I already have async / await but it still didn’t synchronous yet.
Hi @JustTod - LiveObject is based on callback pattern and you need to wrap Promise around the object for it to work with await. You can use the sample code below:
export const asynchronize = async (liveThing, immediately = true) => {
if (immediately && ((liveThing.models && liveThing.models.length) || liveThing.model))
return liveThing.models || liveThing.model; // data is already loaded and can be returned right away
return new Promise((resolve, reject) => {
// we wrap the resolve in setTimeout(0) to allow 'hasMore' to refresh for live collection (reactive related bug.)
liveThing.once("dataUpdated", (data) =>
setTimeout(() => {
resolve(data);
}, 0)
)})
}
now you can use the function as followed:
const status = await asynchronize(liveFollowStatus)