Does proper mentions through the MentionEntity struct

This commit is contained in:
VERET Clément
2020-03-05 15:02:43 +01:00
parent 1de5171f31
commit 6d46258d2d
4 changed files with 23 additions and 3 deletions

4
CHANGELOG Normal file
View File

@@ -0,0 +1,4 @@
# v0.1.8
* fix #1: mentions are treated like decoded urls (this is not really needed to push it this far but it would be easier in case you want to modify it)

2
Cargo.lock generated
View File

@@ -1498,7 +1498,7 @@ dependencies = [
[[package]]
name = "scootaloo"
version = "0.1.7"
version = "0.1.8"
dependencies = [
"clap",
"egg-mode",

View File

@@ -1,6 +1,6 @@
[package]
name = "scootaloo"
version = "0.1.7"
version = "0.1.8"
authors = ["VC <veretcle+framagit@mateu.be>"]
edition = "2018"

View File

@@ -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;
}