Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add invite_link #17

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE telegram_chats DROP COLUMN invite_link;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE telegram_chats ADD COLUMN invite_link TEXT;
4 changes: 4 additions & 0 deletions src/bot/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ impl From<MessageChat> for NewTelegramChat {
first_name: Some(chat.first_name),
last_name: chat.last_name,
title: None,
invite_link: None,
},
MessageChat::Group(chat) => NewTelegramChat {
id: chat.id.into(),
Expand All @@ -33,6 +34,7 @@ impl From<MessageChat> for NewTelegramChat {
username: None,
first_name: None,
last_name: None,
invite_link: chat.invite_link,
},
MessageChat::Supergroup(chat) => NewTelegramChat {
id: chat.id.into(),
Expand All @@ -41,6 +43,7 @@ impl From<MessageChat> for NewTelegramChat {
username: chat.username,
first_name: None,
last_name: None,
invite_link: chat.invite_link,
},
MessageChat::Unknown(chat) => NewTelegramChat {
id: chat.id.into(),
Expand All @@ -49,6 +52,7 @@ impl From<MessageChat> for NewTelegramChat {
username: chat.username,
first_name: chat.first_name,
last_name: chat.last_name,
invite_link: chat.invite_link,
},
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/bot/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ mod tests {
username: Some("Username".to_string()),
first_name: Some("First".to_string()),
last_name: Some("Last".to_string()),
invite_link: None,
title: None,
};

Expand Down Expand Up @@ -230,6 +231,7 @@ mod tests {
first_name: Some("First".to_string()),
last_name: Some("Last".to_string()),
title: None,
invite_link: None,
};

db_connection.test_transaction::<(), super::SubscriptionError, _>(|| {
Expand All @@ -251,6 +253,7 @@ mod tests {
first_name: Some("First".to_string()),
last_name: Some("Last".to_string()),
title: None,
invite_link: None,
};

db_connection.test_transaction::<(), super::SubscriptionError, _>(|| {
Expand All @@ -275,6 +278,7 @@ mod tests {
first_name: Some("First".to_string()),
last_name: Some("Last".to_string()),
title: None,
invite_link: None,
};

db_connection.test_transaction::<(), super::SubscriptionError, _>(|| {
Expand Down Expand Up @@ -313,6 +317,7 @@ mod tests {
first_name: Some("First".to_string()),
last_name: Some("Last".to_string()),
title: None,
invite_link: None,
};

db_connection.test_transaction::<(), super::SubscriptionError, _>(|| {
Expand Down Expand Up @@ -356,6 +361,7 @@ mod tests {
first_name: Some("First".to_string()),
last_name: Some("Last".to_string()),
title: None,
invite_link: None,
};

db_connection.test_transaction::<(), super::SubscriptionError, _>(|| {
Expand Down
1 change: 1 addition & 0 deletions src/db/feeds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ mod tests {
first_name: Some("First".to_string()),
last_name: Some("Last".to_string()),
title: None,
invite_link: None,
};
let chat = telegram::create_chat(connection, new_chat).unwrap();

Expand Down
7 changes: 7 additions & 0 deletions src/db/telegram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct NewTelegramChat {
pub username: Option<String>,
pub first_name: Option<String>,
pub last_name: Option<String>,
pub invite_link: Option<String>,
}

#[derive(Insertable, Clone, Copy)]
Expand All @@ -42,6 +43,7 @@ pub fn create_chat(conn: &PgConnection, new_chat: NewTelegramChat) -> Result<Tel
telegram_chats::first_name.eq(excluded(telegram_chats::first_name)),
telegram_chats::last_name.eq(excluded(telegram_chats::last_name)),
telegram_chats::title.eq(excluded(telegram_chats::title)),
telegram_chats::invite_link.eq(excluded(telegram_chats::invite_link)),
))
.get_result::<TelegramChat>(conn)
}
Expand Down Expand Up @@ -230,6 +232,7 @@ mod tests {
first_name: Some("First".to_string()),
last_name: Some("Last".to_string()),
title: None,
invite_link: None,
};
let updated_chat = NewTelegramChat {
id: 42,
Expand All @@ -238,6 +241,7 @@ mod tests {
first_name: Some("First1".to_string()),
last_name: Some("Last1".to_string()),
title: None,
invite_link: None,
};
let connection = db::establish_connection();

Expand Down Expand Up @@ -271,6 +275,7 @@ mod tests {
first_name: Some("First".to_string()),
last_name: Some("Last".to_string()),
title: None,
invite_link: None,
};

connection.test_transaction::<(), Error, _>(|| {
Expand Down Expand Up @@ -581,6 +586,7 @@ mod tests {
first_name: Some("First".to_string()),
last_name: Some("Last".to_string()),
title: None,
invite_link: None,
}
}

Expand All @@ -592,6 +598,7 @@ mod tests {
first_name: Some("First".to_string()),
last_name: Some("Last".to_string()),
title: None,
invite_link: None,
}
}
}
1 change: 1 addition & 0 deletions src/models/telegram_chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ pub struct TelegramChat {
pub updated_at: DateTime<Utc>,
pub title: Option<String>,
pub utc_offset_minutes: Option<i32>,
pub invite_link: Option<String>,
}
1 change: 1 addition & 0 deletions src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ table! {
updated_at -> Timestamptz,
title -> Nullable<Text>,
utc_offset_minutes -> Nullable<Int4>,
invite_link -> Nullable<Text>,
}
}

Expand Down
66 changes: 62 additions & 4 deletions src/sync/reader/fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl From<Feed> for FetchedFeed {
.into_iter()
.filter(|item| !item.links.is_empty())
.map(|item| {
let pub_date: DateTime<Utc> = parse_time(item.published);
let pub_date: DateTime<Utc> = parse_time(item.published, item.updated);
FetchedFeedItem {
title: item.title.map_or_else(|| "".to_string(), |s| s.content),
description: item.summary.map(|s| s.content),
Expand Down Expand Up @@ -75,9 +75,12 @@ impl From<Feed> for FetchedFeed {
}
}

fn parse_time(pub_date: Option<DateTime<Utc>>) -> DateTime<Utc> {
fn parse_time(pub_date: Option<DateTime<Utc>>, updated: Option<DateTime<Utc>>) -> DateTime<Utc> {
match pub_date {
None => db::current_time(),
None => match updated {
Some(value) => value,
None => db::current_time(),
},
Some(value) => value,
}
}
Expand All @@ -96,7 +99,62 @@ mod tests {

let fetched_feed: FetchedFeed = feed.into();

let expected_result = FetchedFeed { title: "World".to_string(), link: "".to_string(), description: "NPR world news, international art and culture, world business and financial markets, world economy, and global trends in health, science and technology. Subscribe to the World Story of the Day podcast and RSS feed.".to_string(), feed_type: "json".to_string(), items: vec![FetchedFeedItem { title: "Trump Says U.S. Will Withdraw From WHO. Does He Have The Authority To Do It?".to_string(), description: Some("<p>In a press conference on Friday, the president said he would immediately sever ties — and funding — to the World Health Organization because of its relationship with China.</p><img src=\'https://media.npr.org/include/images/tracking/npr-rss-pixel.png?story=865816855\' />".to_string()), link: "https://www.npr.org/sections/goatsandsoda/2020/05/29/865816855/trump-says-u-s-will-withdraw-from-who-does-he-have-the-authority-to-do-it?utm_medium=JSONFeed&utm_campaign=world".to_string(), author: Some("Pien Huang".to_string()), guid: Some("865816855".to_string()), publication_date: DateTime::parse_from_rfc3339("2020-05-29T23:30:03Z").unwrap().into() }, FetchedFeedItem { title: "France Eases Some Pandemic Restrictions And Will Reopen Restaurants, Bars And Parks".to_string(), description: Some("<p>\"It will be so nice to be able to go lie on the grass in a park and have a picnic or to sit at a sidewalk cafe again,\" says a Paris resident. Restaurants and bars will reopen with restrictions June 2.</p><img src=\'https://media.npr.org/include/images/tracking/npr-rss-pixel.png?story=864892887\' />".to_string()), link: "https://www.npr.org/sections/coronavirus-live-updates/2020/05/29/864892887/france-eases-some-pandemic-restrictions-and-will-reopen-restaurants-bars-and-par?utm_medium=JSONFeed&utm_campaign=world".to_string(), author: Some("Eleanor Beardsley".to_string()), guid: Some("864892887".to_string()), publication_date: DateTime::parse_from_rfc3339("2020-05-29T20:00:34Z").unwrap().into() }, FetchedFeedItem { title: "Moscow Doubles Last Month\'s Coronavirus Death Toll Amid Suspicions Of Undercounting".to_string(), description: Some("<p>Media reports and analysts have questioned the accuracy of Russia\'s mortality figures for the virus. Moscow\'s Health Department now says 1,561 people died in April due to the coronavirus.</p><img src=\'https://media.npr.org/include/images/tracking/npr-rss-pixel.png?story=865044503\' />".to_string()), link: "https://www.npr.org/sections/coronavirus-live-updates/2020/05/29/865044503/moscow-doubles-last-months-coronavirus-death-toll-amid-suspicions-of-undercounti?utm_medium=JSONFeed&utm_campaign=world".to_string(), author: Some("Jason Slotkin".to_string()), guid: Some("865044503".to_string()), publication_date: DateTime::parse_from_rfc3339("2020-05-29T19:35:00Z").unwrap().into() }] };
let expected_result = FetchedFeed {
title: "World".to_string(),
link: "".to_string(),
description: "NPR world news, international art and culture, world business and financial markets, world economy, and global trends in health, science and technology. Subscribe to the World Story of the Day podcast and RSS feed.".into(),
feed_type: "json".to_string(),
items: vec![
FetchedFeedItem {
title: "Trump Says U.S. Will Withdraw From WHO. Does He Have The Authority To Do It?".to_string(),
description: Some("In a press conference on Friday, the president said he would immediately sever ties — and funding — to the World Health Organization because of its relationship with China.".to_string()),
link: "https://www.npr.org/sections/goatsandsoda/2020/05/29/865816855/trump-says-u-s-will-withdraw-from-who-does-he-have-the-authority-to-do-it?utm_medium=JSONFeed&utm_campaign=world".to_string(),
author: Some("Pien Huang".to_string()),
guid: Some("865816855".to_string()),
publication_date: DateTime::parse_from_rfc3339("2020-05-29T23:30:03Z").unwrap().into() },
FetchedFeedItem {
title: "France Eases Some Pandemic Restrictions And Will Reopen Restaurants, Bars And Parks".to_string(),
description: Some("\"It will be so nice to be able to go lie on the grass in a park and have a picnic or to sit at a sidewalk cafe again,\" says a Paris resident. Restaurants and bars will reopen with restrictions June 2.".to_string()),
link: "https://www.npr.org/sections/coronavirus-live-updates/2020/05/29/864892887/france-eases-some-pandemic-restrictions-and-will-reopen-restaurants-bars-and-par?utm_medium=JSONFeed&utm_campaign=world".to_string(),
author: Some("Eleanor Beardsley".to_string()),
guid: Some("864892887".to_string()),
publication_date: DateTime::parse_from_rfc3339("2020-05-29T20:00:34Z").unwrap().into() },
FetchedFeedItem {
title: "Moscow Doubles Last Month\'s Coronavirus Death Toll Amid Suspicions Of Undercounting".to_string(),
description: Some("Media reports and analysts have questioned the accuracy of Russia\'s mortality figures for the virus. Moscow\'s Health Department now says 1,561 people died in April due to the coronavirus.".to_string()),
link: "https://www.npr.org/sections/coronavirus-live-updates/2020/05/29/865044503/moscow-doubles-last-months-coronavirus-death-toll-amid-suspicions-of-undercounti?utm_medium=JSONFeed&utm_campaign=world".to_string(),
author: Some("Jason Slotkin".to_string()),
guid: Some("865044503".to_string()),
publication_date: DateTime::parse_from_rfc3339("2020-05-29T19:35:00Z").unwrap().into() }
]
};

assert_eq!(expected_result, fetched_feed);
}

#[test]
fn it_converts_atom_feed_to_fetched_feed() {
let atom_feed = fs::read_to_string("./tests/support/atom_feed_example.xml").unwrap();
let feed = parser::parse(atom_feed.as_bytes()).unwrap();

let fetched_feed: FetchedFeed = feed.into();

let expected_result = FetchedFeed {
title: "Example Feed".into(),
link: "".into(),
description: "".to_string(),
feed_type: "atom".to_string(),
items: vec![FetchedFeedItem {
title: "Atom-Powered Robots Run Amok".to_string(),
description: Some("Some text.".into()),
link: "http://example.org/2003/12/13/atom03".into(),
author: Some("".into()),
guid: Some("urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a".into()),
publication_date: DateTime::parse_from_rfc3339("2003-12-13T18:30:02Z")
.unwrap()
.into(),
}],
};

assert_eq!(expected_result, fetched_feed);
}
Expand Down
86 changes: 1 addition & 85 deletions tests/support/rss_feed_example.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,89 +63,5 @@ Job Postings &lt;/i&gt;&lt;/font&gt;</description>
<comments>http://www.feedforall.com/forum</comments>
<pubDate>Tue, 19 Oct 2004 11:09:07 -0400</pubDate>
</item>
<item>
<title>RSS Solutions for Governments</title>
<description>FeedForAll helps Governments communicate with the general public about positions on various issues, and keep the community aware of changes in important legislative issues. &lt;b&gt;&lt;i&gt;&lt;br&gt;
&lt;/b&gt;&lt;/i&gt;&lt;br&gt;
RSS uses Include:&lt;br&gt;
&lt;i&gt;&lt;font color=&quot;#00FF00&quot;&gt;Legislative Calendar&lt;br&gt;
Votes&lt;br&gt;
Bulletins&lt;/i&gt;&lt;/font&gt;</description>
<link>http://www.feedforall.com/government.htm</link>
<category domain="www.dmoz.com">Computers/Software/Internet/Site Management/Content Management</category>
<comments>http://www.feedforall.com/forum</comments>
<pubDate>Tue, 19 Oct 2004 11:09:05 -0400</pubDate>
</item>
<item>
<title>RSS Solutions for Politicians</title>
<description>FeedForAll helps Politicians communicate with the general public about positions on various issues, and keep the community notified of their schedule. &lt;br&gt;
&lt;br&gt;
Uses Include:&lt;br&gt;
&lt;i&gt;&lt;font color=&quot;#FF0000&quot;&gt;Blogs&lt;br&gt;
Speaking Engagements &lt;br&gt;
Statements&lt;br&gt;
&lt;/i&gt;&lt;/font&gt;</description>
<link>http://www.feedforall.com/politics.htm</link>
<category domain="www.dmoz.com">Computers/Software/Internet/Site Management/Content Management</category>
<comments>http://www.feedforall.com/forum</comments>
<pubDate>Tue, 19 Oct 2004 11:09:03 -0400</pubDate>
</item>
<item>
<title>RSS Solutions for Meteorologists</title>
<description>FeedForAll helps Meteorologists communicate with the general public about storm warnings and weather alerts, in specific regions. Using RSS meteorologists are able to quickly disseminate urgent and life threatening weather warnings. &lt;br&gt;
&lt;br&gt;
Uses Include:&lt;br&gt;
&lt;i&gt;&lt;font color=&quot;#0000FF&quot;&gt;Weather Alerts&lt;br&gt;
Plotting Storms&lt;br&gt;
School Cancellations &lt;/i&gt;&lt;/font&gt;</description>
<link>http://www.feedforall.com/weather.htm</link>
<category domain="www.dmoz.com">Computers/Software/Internet/Site Management/Content Management</category>
<comments>http://www.feedforall.com/forum</comments>
<pubDate>Tue, 19 Oct 2004 11:09:01 -0400</pubDate>
</item>
<item>
<title>RSS Solutions for Realtors &amp; Real Estate Firms</title>
<description>FeedForAll helps Realtors and Real Estate companies communicate with clients informing them of newly available properties, and open house announcements. RSS helps to reach a targeted audience and spread the word in an inexpensive, professional manner. &lt;font color=&quot;#0000FF&quot;&gt;&lt;br&gt;
&lt;/font&gt;&lt;br&gt;
Feeds can be used for:&lt;br&gt;
&lt;i&gt;&lt;font color=&quot;#FF0000&quot;&gt;Open House Dates&lt;br&gt;
New Properties For Sale&lt;br&gt;
Mortgage Rates&lt;/i&gt;&lt;/font&gt;</description>
<link>http://www.feedforall.com/real-estate.htm</link>
<category domain="www.dmoz.com">Computers/Software/Internet/Site Management/Content Management</category>
<comments>http://www.feedforall.com/forum</comments>
<pubDate>Tue, 19 Oct 2004 11:08:59 -0400</pubDate>
</item>
<item>
<title>RSS Solutions for Banks / Mortgage Companies</title>
<description>FeedForAll helps &lt;b&gt;Banks, Credit Unions and Mortgage companies&lt;/b&gt; communicate with the general public about rate changes in a prompt and professional manner. &lt;br&gt;
&lt;br&gt;
Uses include:&lt;br&gt;
&lt;i&gt;&lt;font color=&quot;#0000FF&quot;&gt;Mortgage Rates&lt;br&gt;
Foreign Exchange Rates &lt;br&gt;
Bank Rates&lt;br&gt;
Specials&lt;/i&gt;&lt;/font&gt;</description>
<link>http://www.feedforall.com/banks.htm</link>
<category domain="www.dmoz.com">Computers/Software/Internet/Site Management/Content Management</category>
<comments>http://www.feedforall.com/forum</comments>
<pubDate>Tue, 19 Oct 2004 11:08:57 -0400</pubDate>
</item>
<item>
<title>RSS Solutions for Law Enforcement</title>
<description>&lt;b&gt;FeedForAll&lt;/b&gt; helps Law Enforcement Professionals communicate with the general public and other agencies in a prompt and efficient manner. Using RSS police are able to quickly disseminate urgent and life threatening information. &lt;br&gt;
&lt;br&gt;
Uses include:&lt;br&gt;
&lt;i&gt;&lt;font color=&quot;#0000FF&quot;&gt;Amber Alerts&lt;br&gt;
Sex Offender Community Notification &lt;br&gt;
Weather Alerts &lt;br&gt;
Scheduling &lt;br&gt;
Security Alerts &lt;br&gt;
Police Report &lt;br&gt;
Meetings&lt;/i&gt;&lt;/font&gt;</description>
<link>http://www.feedforall.com/law-enforcement.htm</link>
<category domain="www.dmoz.com">Computers/Software/Internet/Site Management/Content Management</category>
<comments>http://www.feedforall.com/forum</comments>
<pubDate>Tue, 19 Oct 2004 11:08:56 -0400</pubDate>
</item>
</channel>
</rss>
</rss>