Skip to content

Commit

Permalink
Merge pull request #91 from h3poteto/iss-90
Browse files Browse the repository at this point in the history
refs #90 Add announcement
  • Loading branch information
h3poteto authored May 30, 2023
2 parents 8051c89 + a86680e commit f020622
Show file tree
Hide file tree
Showing 22 changed files with 528 additions and 20 deletions.
44 changes: 44 additions & 0 deletions src/entities/announcement.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use super::{status, Emoji};
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Announcement {
pub id: String,
pub conent: String,
pub starts_at: Option<DateTime<Utc>>,
pub ends_at: Option<DateTime<Utc>>,
pub published: bool,
pub all_day: bool,
pub published_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
pub read: Option<bool>,
pub mentions: Vec<Account>,
pub statuses: Vec<Status>,
pub tags: Vec<status::Tag>,
pub emojis: Vec<Emoji>,
pub reactions: Vec<Reaction>,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Account {
pub id: String,
pub username: String,
pub url: String,
pub acct: String,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Status {
pub id: String,
pub url: String,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Reaction {
pub name: String,
pub count: i64,
pub me: Option<bool>,
pub url: Option<String>,
pub static_url: Option<String>,
}
1 change: 1 addition & 0 deletions src/entities/emoji.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ pub struct Emoji {
pub static_url: String,
pub url: String,
pub visible_in_picker: bool,
pub category: String,
}
2 changes: 2 additions & 0 deletions src/entities/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

pub mod account;
pub mod activity;
pub mod announcement;
pub mod application;
pub mod async_attachment;
pub mod attachment;
Expand Down Expand Up @@ -39,6 +40,7 @@ pub mod urls;

pub use account::Account;
pub use activity::Activity;
pub use announcement::Announcement;
pub use application::Application;
pub use async_attachment::AsyncAttachment;
pub use async_attachment::UploadMedia;
Expand Down
11 changes: 8 additions & 3 deletions src/entities/status.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use serde::{Deserialize, Serialize};

use super::{Account, Application, Attachment, Card, Emoji, Mention, Poll, Reaction, Tag};
use super::{Account, Application, Attachment, Card, Emoji, Mention, Poll, Reaction};
use crate::error::{Error, Kind};
use chrono::{DateTime, Utc};
use core::fmt;
use serde::{Deserialize, Serialize};
use std::str::FromStr;

#[derive(Debug, Clone, Deserialize, Serialize)]
Expand Down Expand Up @@ -74,3 +73,9 @@ impl FromStr for StatusVisibility {
}
}
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Tag {
pub name: String,
pub url: String,
}
2 changes: 1 addition & 1 deletion src/entities/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ use super::History;
pub struct Tag {
pub name: String,
pub url: String,
pub history: Option<Vec<History>>,
pub history: Vec<History>,
pub following: Option<bool>,
}
1 change: 1 addition & 0 deletions src/friendica/entities/emoji.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ impl Into<MegalodonEntities::Emoji> for Emoji {
static_url: self.static_url,
url: self.url,
visible_in_picker: self.visible_in_picker,
category: "".to_string(),
}
}
}
16 changes: 15 additions & 1 deletion src/friendica/entities/status.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use core::fmt;
use std::str::FromStr;

use super::{Account, Application, Attachment, Card, Emoji, Mention, Poll, Tag};
use super::{Account, Application, Attachment, Card, Emoji, Mention, Poll};
use crate::error::{Error, Kind};
use crate::{entities as MegalodonEntities, megalodon};
use chrono::{DateTime, Utc};
Expand Down Expand Up @@ -72,6 +72,20 @@ impl FromStr for StatusVisibility {
}
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Tag {
pub name: String,
pub url: String,
}

impl Into<MegalodonEntities::status::Tag> for Tag {
fn into(self) -> MegalodonEntities::status::Tag {
MegalodonEntities::status::Tag {
name: self.name,
url: self.url,
}
}
}
impl Into<MegalodonEntities::status::StatusVisibility> for StatusVisibility {
fn into(self) -> MegalodonEntities::status::StatusVisibility {
match self {
Expand Down
6 changes: 2 additions & 4 deletions src/friendica/entities/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use serde::Deserialize;
pub struct Tag {
name: String,
url: String,
history: Option<Vec<History>>,
history: Vec<History>,
following: Option<bool>,
}

Expand All @@ -15,9 +15,7 @@ impl Into<MegalodonEntities::Tag> for Tag {
MegalodonEntities::Tag {
name: self.name,
url: self.url,
history: self
.history
.map(|i| i.into_iter().map(|j| j.into()).collect()),
history: self.history.into_iter().map(|j| j.into()).collect(),
following: self.following,
}
}
Expand Down
46 changes: 46 additions & 0 deletions src/friendica/friendica.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2582,6 +2582,52 @@ impl megalodon::Megalodon for Friendica {
))
}

async fn get_instance_announcements(
&self,
) -> Result<Response<Vec<MegalodonEntities::Announcement>>, Error> {
Ok(Response::<Vec<MegalodonEntities::Announcement>>::new(
[].to_vec(),
200,
"200".to_string(),
HeaderMap::new(),
))
}

async fn dismiss_instance_announcement(&self, _id: String) -> Result<Response<()>, Error> {
Err(Error::new_own(
"Friendica doest not support".to_string(),
error::Kind::NoImplementedError,
None,
None,
))
}

async fn add_reaction_to_announcement(
&self,
_id: String,
_name: String,
) -> Result<Response<()>, Error> {
Err(Error::new_own(
"Friendica doest not support".to_string(),
error::Kind::NoImplementedError,
None,
None,
))
}

async fn remove_reaction_from_announcement(
&self,
_id: String,
_name: String,
) -> Result<Response<()>, Error> {
Err(Error::new_own(
"Friendica doest not support".to_string(),
error::Kind::NoImplementedError,
None,
None,
))
}

async fn create_emoji_reaction(
&self,
_id: String,
Expand Down
98 changes: 98 additions & 0 deletions src/mastodon/entities/announcement.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
use super::{status, Emoji};
use crate::entities as MegalodonEntities;
use chrono::{DateTime, Utc};
use serde::Deserialize;

#[derive(Debug, Clone, Deserialize)]
pub struct Announcement {
id: String,
conent: String,
starts_at: Option<DateTime<Utc>>,
ends_at: Option<DateTime<Utc>>,
published: bool,
all_day: bool,
published_at: DateTime<Utc>,
updated_at: DateTime<Utc>,
read: Option<bool>,
mentions: Vec<Account>,
statuses: Vec<Status>,
tags: Vec<status::Tag>,
emojis: Vec<Emoji>,
reactions: Vec<Reaction>,
}

#[derive(Debug, Clone, Deserialize)]
pub struct Account {
id: String,
username: String,
url: String,
acct: String,
}

#[derive(Debug, Clone, Deserialize)]
pub struct Status {
id: String,
url: String,
}

#[derive(Debug, Clone, Deserialize)]
pub struct Reaction {
name: String,
count: i64,
me: Option<bool>,
url: Option<String>,
static_url: Option<String>,
}

impl Into<MegalodonEntities::Announcement> for Announcement {
fn into(self) -> MegalodonEntities::Announcement {
MegalodonEntities::Announcement {
id: self.id,
conent: self.conent,
starts_at: self.starts_at,
ends_at: self.ends_at,
published: self.published,
all_day: self.all_day,
published_at: self.published_at,
updated_at: self.updated_at,
read: self.read,
mentions: self.mentions.into_iter().map(|i| i.into()).collect(),
statuses: self.statuses.into_iter().map(|i| i.into()).collect(),
tags: self.tags.into_iter().map(|i| i.into()).collect(),
emojis: self.emojis.into_iter().map(|i| i.into()).collect(),
reactions: self.reactions.into_iter().map(|i| i.into()).collect(),
}
}
}

impl Into<MegalodonEntities::announcement::Account> for Account {
fn into(self) -> MegalodonEntities::announcement::Account {
MegalodonEntities::announcement::Account {
id: self.id,
username: self.username,
url: self.url,
acct: self.acct,
}
}
}

impl Into<MegalodonEntities::announcement::Status> for Status {
fn into(self) -> MegalodonEntities::announcement::Status {
MegalodonEntities::announcement::Status {
id: self.id,
url: self.url,
}
}
}

impl Into<MegalodonEntities::announcement::Reaction> for Reaction {
fn into(self) -> MegalodonEntities::announcement::Reaction {
MegalodonEntities::announcement::Reaction {
name: self.name,
count: self.count,
me: self.me,
url: self.url,
static_url: self.static_url,
}
}
}
3 changes: 3 additions & 0 deletions src/mastodon/entities/emoji.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub struct Emoji {
static_url: String,
url: String,
visible_in_picker: bool,
category: String,
}

impl From<MegalodonEntities::Emoji> for Emoji {
Expand All @@ -16,6 +17,7 @@ impl From<MegalodonEntities::Emoji> for Emoji {
static_url: item.static_url,
url: item.url,
visible_in_picker: item.visible_in_picker,
category: item.category,
}
}
}
Expand All @@ -27,6 +29,7 @@ impl Into<MegalodonEntities::Emoji> for Emoji {
static_url: self.static_url,
url: self.url,
visible_in_picker: self.visible_in_picker,
category: self.category,
}
}
}
2 changes: 2 additions & 0 deletions src/mastodon/entities/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod account;
pub mod activity;
pub mod announcement;
pub mod application;
pub mod attachment;
pub mod card;
Expand Down Expand Up @@ -34,6 +35,7 @@ pub mod urls;

pub use account::Account;
pub use activity::Activity;
pub use announcement::Announcement;
pub use application::Application;
pub use attachment::Attachment;
pub use card::Card;
Expand Down
16 changes: 15 additions & 1 deletion src/mastodon/entities/status.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use core::fmt;
use std::str::FromStr;

use super::{Account, Application, Attachment, Card, Emoji, Mention, Poll, Tag};
use super::{Account, Application, Attachment, Card, Emoji, Mention, Poll};
use crate::error::{Error, Kind};
use crate::{entities as MegalodonEntities, megalodon};
use chrono::{DateTime, Utc};
Expand Down Expand Up @@ -74,6 +74,20 @@ impl FromStr for StatusVisibility {
}
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Tag {
pub name: String,
pub url: String,
}
impl Into<MegalodonEntities::status::Tag> for Tag {
fn into(self) -> MegalodonEntities::status::Tag {
MegalodonEntities::status::Tag {
name: self.name,
url: self.url,
}
}
}

impl Into<MegalodonEntities::status::StatusVisibility> for StatusVisibility {
fn into(self) -> MegalodonEntities::status::StatusVisibility {
match self {
Expand Down
6 changes: 2 additions & 4 deletions src/mastodon/entities/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use serde::Deserialize;
pub struct Tag {
name: String,
url: String,
history: Option<Vec<History>>,
history: Vec<History>,
following: Option<bool>,
}

Expand All @@ -15,9 +15,7 @@ impl Into<MegalodonEntities::Tag> for Tag {
MegalodonEntities::Tag {
name: self.name,
url: self.url,
history: self
.history
.map(|i| i.into_iter().map(|j| j.into()).collect()),
history: self.history.into_iter().map(|j| j.into()).collect(),
following: self.following,
}
}
Expand Down
Loading

0 comments on commit f020622

Please sign in to comment.