Add emoji array to Status object

This commit is contained in:
silverpill 2023-01-16 22:40:03 +00:00
parent 56e75895bd
commit 578629f8bd
3 changed files with 47 additions and 2 deletions

View file

@ -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. - Validation of Monero subscription payout address.
- Accept webfinger requests where `resource` is actor ID. - Accept webfinger requests where `resource` is actor ID.
- Adeed support for `as:Public` and `Public` audience identifiers. - Adeed support for `as:Public` and `Public` audience identifiers.
- Displaying custom emojis.
### Changed ### Changed

View file

@ -1361,6 +1361,18 @@ components:
url: url:
description: The location of the original full-size attachment. description: The location of the original full-size attachment.
type: string 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: Field:
type: object type: object
properties: properties:
@ -1654,6 +1666,11 @@ components:
type: array type: array
items: items:
$ref: '#/components/schemas/Tag' $ref: '#/components/schemas/Tag'
emojis:
description: Custom emoji to be used when rendering post content.
type: array
items:
$ref: '#/components/schemas/CustomEmoji'
reblog: reblog:
description: The post being reposted. description: The post being reposted.
type: object type: object

View file

@ -4,8 +4,12 @@ use uuid::Uuid;
use crate::mastodon_api::accounts::types::Account; use crate::mastodon_api::accounts::types::Account;
use crate::mastodon_api::media::types::Attachment; use crate::mastodon_api::media::types::Attachment;
use crate::models::posts::types::{Post, Visibility}; use crate::models::{
use crate::models::profiles::types::DbActorProfile; emojis::types::DbEmoji,
posts::types::{Post, Visibility},
profiles::types::DbActorProfile,
};
use crate::utils::files::get_file_url;
/// https://docs.joinmastodon.org/entities/mention/ /// https://docs.joinmastodon.org/entities/mention/
#[derive(Serialize)] #[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/ /// https://docs.joinmastodon.org/entities/status/
#[derive(Serialize)] #[derive(Serialize)]
pub struct Status { pub struct Status {
@ -63,6 +85,7 @@ pub struct Status {
pub media_attachments: Vec<Attachment>, pub media_attachments: Vec<Attachment>,
mentions: Vec<Mention>, mentions: Vec<Mention>,
tags: Vec<Tag>, tags: Vec<Tag>,
emojis: Vec<CustomEmoji>,
// Authorized user attributes // Authorized user attributes
pub favourited: bool, pub favourited: bool,
@ -87,6 +110,9 @@ impl Status {
let tags: Vec<Tag> = post.tags.into_iter() let tags: Vec<Tag> = post.tags.into_iter()
.map(Tag::from_tag_name) .map(Tag::from_tag_name)
.collect(); .collect();
let emojis: Vec<CustomEmoji> = post.emojis.into_iter()
.map(|emoji| CustomEmoji::from_db(instance_url, emoji))
.collect();
let account = Account::from_profile(post.author, instance_url); let account = Account::from_profile(post.author, instance_url);
let reblog = if let Some(repost_of) = post.repost_of { let reblog = if let Some(repost_of) = post.repost_of {
let status = Status::from_post(*repost_of, instance_url); let status = Status::from_post(*repost_of, instance_url);
@ -119,6 +145,7 @@ impl Status {
media_attachments: attachments, media_attachments: attachments,
mentions: mentions, mentions: mentions,
tags: tags, tags: tags,
emojis: emojis,
favourited: post.actions.as_ref().map_or(false, |actions| actions.favourited), favourited: post.actions.as_ref().map_or(false, |actions| actions.favourited),
reblogged: post.actions.as_ref().map_or(false, |actions| actions.reposted), reblogged: post.actions.as_ref().map_or(false, |actions| actions.reposted),
ipfs_cid: post.ipfs_cid, ipfs_cid: post.ipfs_cid,