Allow clients to add mentions to a post

This commit is contained in:
silverpill 2022-01-15 16:36:25 +00:00
parent 5676d53cbb
commit 05205c398e
3 changed files with 34 additions and 3 deletions

View file

@ -295,6 +295,12 @@ paths:
enum:
- public
- direct
mentions:
description: Array of profile IDs to be mentioned
type: array
items:
type: string
format: uuid
required:
- status
responses:
@ -505,6 +511,21 @@ components:
description: Ethereum wallet address.
type: string
example: '0xd8da6bf...'
Mention:
type: object
properties:
id:
description: The profile ID of the mentioned user.
type: string
format: uuid
username:
description: The username of the mentioned user.
type: string
acct:
type: string
url:
description: The location of the mentioned user's profile.
type: string
Notification:
type: object
properties:
@ -561,6 +582,11 @@ components:
enum:
- public
- direct
mentions:
description: Mentions of users within the post.
type: array
items:
$ref: '#/components/schemas/Mention'
tags:
description: Hashtags used within the status content.
type: array

View file

@ -132,6 +132,9 @@ pub struct StatusData {
pub in_reply_to_id: Option<Uuid>,
pub visibility: Option<String>,
// Not supported by Mastodon
pub mentions: Option<Vec<Uuid>>,
}
impl TryFrom<StatusData> for PostCreateData {
@ -151,7 +154,7 @@ impl TryFrom<StatusData> for PostCreateData {
repost_of_id: None,
visibility: visibility,
attachments: value.media_ids.unwrap_or(vec![]),
mentions: vec![],
mentions: value.mentions.unwrap_or(vec![]),
tags: vec![],
object_id: None,
created_at: None,

View file

@ -75,8 +75,10 @@ async fn create_status(
&instance.url(),
&post_data.content,
);
post_data.mentions = mention_map.values()
.map(|profile| profile.id).collect();
post_data.mentions.extend(mention_map.values()
.map(|profile| profile.id));
post_data.mentions.sort();
post_data.mentions.dedup();
// Tags
post_data.tags = find_tags(&post_data.content);
post_data.content = replace_tags(