Gemention/src/comments.rs

34 lines
1.3 KiB
Rust

use crate::error::GementionError;
use crate::models::mentions::Mention;
use crate::models::web::{C2SMentionRequest, MentionResponse};
use crate::validation::{AsyncValidation, Validation};
use fluffer::Client;
/// Receive a client-to-server Gemention: i.e. a user posting a
/// comment to a gemention-enabled page. The client must identify
/// themselves with a cert that at least has a username.
pub(crate) async fn receive_c2s_gemention(
client: Client,
) -> Result<MentionResponse, GementionError> {
let mention_upload = C2SMentionRequest::try_from(&client)?.validate()?;
let mention = Mention::try_from(mention_upload)?.validate_async().await?;
Ok(MentionResponse::from(mention))
}
/// Receive a server-to-server Gemention: another capsule linking to a
/// gemention-enabled page on this capsule. There is an exchange of
/// titan keys so that the servers can talk to one another.
pub(crate) async fn receive_s2s_gemention(
client: Client,
) -> Result<MentionResponse, GementionError> {
let mention_upload = C2SMentionRequest::try_from(&client)?;
let mention = Mention::try_from(mention_upload)?.validate_async().await?;
Ok(MentionResponse::from(mention))
}
// Render comments gemtext by requesting comments for a page.
// Proxy a webmention to Titan endpoint.