mirror of
https://framagit.org/veretcle/scootaloo.git
synced 2025-07-21 09:31:19 +02:00
Does proper mentions through the MentionEntity struct
This commit is contained in:
18
src/lib.rs
18
src/lib.rs
@@ -16,7 +16,7 @@ use serde::Deserialize;
|
||||
use egg_mode::{
|
||||
Token,
|
||||
KeyPair,
|
||||
entities::{UrlEntity, MediaEntity, MediaType},
|
||||
entities::{UrlEntity, MediaEntity, MentionEntity, MediaType},
|
||||
tweet::{
|
||||
Tweet,
|
||||
user_timeline,
|
||||
@@ -97,6 +97,16 @@ fn decode_urls(urls: &Vec<UrlEntity>) -> HashMap<String, String> {
|
||||
decoded_urls
|
||||
}
|
||||
|
||||
fn twitter_mentions(ums: &Vec<MentionEntity>) -> HashMap<String, String> {
|
||||
let mut decoded_mentions = HashMap::new();
|
||||
|
||||
for um in ums {
|
||||
decoded_mentions.insert(format!("@{}", um.screen_name), format!("@{}@twitter.com", um.screen_name));
|
||||
}
|
||||
|
||||
decoded_mentions
|
||||
}
|
||||
|
||||
/// Retrieve a single media from a tweet and store it in a temporary file
|
||||
fn get_tweet_media(m: &MediaEntity, t: &str) -> Result<String, Box<dyn Error>> {
|
||||
match m.media_type {
|
||||
@@ -147,6 +157,12 @@ fn build_basic_status(tweet: &Tweet) -> Result<StatusBuilder, Box<dyn Error>> {
|
||||
toot = toot.replace(&decoded_url.0, &decoded_url.1);
|
||||
}
|
||||
|
||||
let decoded_mentions = twitter_mentions(&tweet.entities.user_mentions);
|
||||
|
||||
for decoded_mention in decoded_mentions {
|
||||
toot = toot.replace(&decoded_mention.0, &decoded_mention.1);
|
||||
}
|
||||
|
||||
if let Ok(t) = decode_html(&toot) {
|
||||
toot = t;
|
||||
}
|
||||
|
Reference in New Issue
Block a user