Add emoji array to Status object
This commit is contained in:
parent
56e75895bd
commit
578629f8bd
3 changed files with 47 additions and 2 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<Attachment>,
|
||||
mentions: Vec<Mention>,
|
||||
tags: Vec<Tag>,
|
||||
emojis: Vec<CustomEmoji>,
|
||||
|
||||
// Authorized user attributes
|
||||
pub favourited: bool,
|
||||
|
@ -87,6 +110,9 @@ impl Status {
|
|||
let tags: Vec<Tag> = post.tags.into_iter()
|
||||
.map(Tag::from_tag_name)
|
||||
.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 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,
|
||||
|
|
Loading…
Reference in a new issue