Closed bdashore3 closed 4 years ago
The way you find whether a user follows another user is by using the user::relation
function. You'd pull that info like this:
let other_user = tweet.user.unwrap();
let relation = egg_mode::user::relation(me.id, other_user.id).await?;
if relation.source.followed_by {
// add marker saying "Follows you" or the like
}
Thanks for the response! However, what if I wanted to use relation_lookup() since me.id is the authenticated user?
If you wanted to use relation_lookup
instead, it would look something like this:
use egg_mode::user::Connection::FollowedBy;
let other_user = tweet.user.unwrap();
let lookup = egg_mode::user::relation_lookup(&[other_user.id]).await?;
if lookup[0].connections.contains(&FollowedBy) {
// add marker saying "Follows you" or the like
}
So, cargo says the function takes 2 arguments and I added the user token in there, but I'm getting this error and I'm not sure why. I tried providing a non-refed u64 and binded the array separate to the function call.
let other_user = tweet.user.unwrap();
let lookup = relation_lookup(&[other_user.id], &config.token).await?;
Oh dang, it looks like the impl From<&u64> for UserID
got removed at some point. Replace the array with something like [other_user.id].iter().cloned()
, that should make it work. I'll have to add some of the From
impls back in.
Yes! That worked! Now for some weird reason, there's this error and I don't know what to make of it. They're both the same type, so why is Rust giving that error?
Here's the code
let other_user = status.user.as_ref().unwrap();
let lookup = relation_lookup([other_user.id].iter().cloned(), &config.token).await?;
if lookup[0].connections.contains(&Connection::FollowedBy) { <- Error occurring on the contains check
let _ = retweet(status.id, &config.token).await;
let _ = like(status.id, &config.token).await;
TWEET_MAP.insert(status.id, since_epoch + 3600);
}
Oh goodness, why did i not throw PartialEq
on that enum? Since there's no ==
operator for that type, you'll have to use the matches!
macro instead:
let other_user = status.user.as_ref().unwrap();
let lookup = relation_lookup([other_user.id].iter().cloned(), &config.token).await?;
if lookup[0].connections.iter().any(|c| matches!(c, &Connection::FollowedBy)) {
let _ = retweet(status.id, &config.token).await;
let _ = like(status.id, &config.token).await;
TWEET_MAP.insert(status.id, since_epoch + 3600);
}
Hi, I was looking at the docs and wanted to know how to check if the account that mentioned me actually follows me.
I'm currently using the mentions timeline and I understand that gives me a TwitterUser struct. How would I tell if that user is following me?