diff --git a/CHANGELOG.md b/CHANGELOG.md index b4aecf1..30db6ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Validation of Monero subscription payout address. - Accept webfinger requests where `resource` is actor ID. - Adeed support for `as:Public` and `Public` audience identifiers. +- Displaying custom emojis. ### Changed diff --git a/docs/openapi.yaml b/docs/openapi.yaml index 86dcc8b..8a2a054 100644 --- a/docs/openapi.yaml +++ b/docs/openapi.yaml @@ -1361,6 +1361,18 @@ components: url: description: The location of the original full-size attachment. type: string + CustomEmoji: + type: object + properties: + shortcode: + description: The name of the custom emoji. + type: string + url: + description: A link to the custom emoji. + type: string + visible_in_picker: + description: Whether this Emoji should be visible in the picker or unlisted. + type: boolean Field: type: object properties: @@ -1654,6 +1666,11 @@ components: type: array items: $ref: '#/components/schemas/Tag' + emojis: + description: Custom emoji to be used when rendering post content. + type: array + items: + $ref: '#/components/schemas/CustomEmoji' reblog: description: The post being reposted. type: object diff --git a/src/mastodon_api/statuses/types.rs b/src/mastodon_api/statuses/types.rs index c744775..cbf6a22 100644 --- a/src/mastodon_api/statuses/types.rs +++ b/src/mastodon_api/statuses/types.rs @@ -4,8 +4,12 @@ use uuid::Uuid; use crate::mastodon_api::accounts::types::Account; use crate::mastodon_api::media::types::Attachment; -use crate::models::posts::types::{Post, Visibility}; -use crate::models::profiles::types::DbActorProfile; +use crate::models::{ + emojis::types::DbEmoji, + posts::types::{Post, Visibility}, + profiles::types::DbActorProfile, +}; +use crate::utils::files::get_file_url; /// https://docs.joinmastodon.org/entities/mention/ #[derive(Serialize)] @@ -44,6 +48,24 @@ impl Tag { } } +/// https://docs.joinmastodon.org/entities/CustomEmoji/ +#[derive(Serialize)] +pub struct CustomEmoji { + shortcode: String, + url: String, + visible_in_picker: bool, +} + +impl CustomEmoji { + fn from_db(instance_url: &str, emoji: DbEmoji) -> Self { + Self { + shortcode: emoji.emoji_name, + url: get_file_url(instance_url, &emoji.image.file_name), + visible_in_picker: true, + } + } +} + /// https://docs.joinmastodon.org/entities/status/ #[derive(Serialize)] pub struct Status { @@ -63,6 +85,7 @@ pub struct Status { pub media_attachments: Vec, mentions: Vec, tags: Vec, + emojis: Vec, // Authorized user attributes pub favourited: bool, @@ -87,6 +110,9 @@ impl Status { let tags: Vec = post.tags.into_iter() .map(Tag::from_tag_name) .collect(); + let emojis: Vec = post.emojis.into_iter() + .map(|emoji| CustomEmoji::from_db(instance_url, emoji)) + .collect(); let account = Account::from_profile(post.author, instance_url); let reblog = if let Some(repost_of) = post.repost_of { let status = Status::from_post(*repost_of, instance_url); @@ -119,6 +145,7 @@ impl Status { media_attachments: attachments, mentions: mentions, tags: tags, + emojis: emojis, favourited: post.actions.as_ref().map_or(false, |actions| actions.favourited), reblogged: post.actions.as_ref().map_or(false, |actions| actions.reposted), ipfs_cid: post.ipfs_cid,