2021-04-09 00:22:17 +00:00
|
|
|
use chrono::{DateTime, Utc};
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use serde_json::{json, Value};
|
2022-07-14 10:18:03 +00:00
|
|
|
|
|
|
|
use super::constants::AP_CONTEXT;
|
|
|
|
use super::views::get_actor_url;
|
2021-04-09 00:22:17 +00:00
|
|
|
use super::vocabulary::*;
|
|
|
|
|
|
|
|
#[derive(Deserialize, Serialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct Attachment {
|
2021-11-18 16:50:42 +00:00
|
|
|
pub name: Option<String>,
|
2021-04-09 00:22:17 +00:00
|
|
|
|
|
|
|
#[serde(rename = "type")]
|
|
|
|
pub attachment_type: String,
|
|
|
|
|
2021-12-29 13:57:57 +00:00
|
|
|
pub media_type: Option<String>,
|
2022-01-08 21:16:12 +00:00
|
|
|
pub url: Option<String>,
|
2021-04-09 00:22:17 +00:00
|
|
|
}
|
|
|
|
|
2022-02-15 23:14:39 +00:00
|
|
|
fn default_tag_type() -> String { HASHTAG.to_string() }
|
|
|
|
|
2021-11-11 21:51:47 +00:00
|
|
|
#[derive(Deserialize, Serialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct Tag {
|
2022-04-27 09:53:52 +00:00
|
|
|
pub name: Option<String>,
|
2021-11-11 21:51:47 +00:00
|
|
|
|
2022-02-15 23:14:39 +00:00
|
|
|
#[serde(rename = "type", default = "default_tag_type")]
|
2021-11-11 21:51:47 +00:00
|
|
|
pub tag_type: String,
|
|
|
|
|
2021-11-24 19:00:36 +00:00
|
|
|
pub href: Option<String>,
|
2021-11-11 21:51:47 +00:00
|
|
|
}
|
|
|
|
|
2021-10-29 16:33:50 +00:00
|
|
|
#[derive(Default, Deserialize, Serialize)]
|
2021-04-09 00:22:17 +00:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct Object {
|
|
|
|
#[serde(rename = "@context")]
|
|
|
|
pub context: Option<Value>,
|
|
|
|
|
|
|
|
pub id: String,
|
|
|
|
|
|
|
|
#[serde(rename = "type")]
|
|
|
|
pub object_type: String,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2022-04-29 13:15:16 +00:00
|
|
|
pub name: Option<String>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2021-04-09 00:22:17 +00:00
|
|
|
pub actor: Option<String>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2022-04-13 22:30:41 +00:00
|
|
|
pub attachment: Option<Value>,
|
2021-04-09 00:22:17 +00:00
|
|
|
|
2022-01-04 20:52:41 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub cc: Option<Value>,
|
|
|
|
|
2021-12-18 23:20:25 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub former_type: Option<String>,
|
|
|
|
|
2021-04-09 00:22:17 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub object: Option<String>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub published: Option<DateTime<Utc>>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2021-12-24 15:13:25 +00:00
|
|
|
pub attributed_to: Option<Value>,
|
2021-04-09 00:22:17 +00:00
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub in_reply_to: Option<String>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub content: Option<String>,
|
|
|
|
|
2021-11-11 21:51:47 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub tag: Option<Vec<Tag>>,
|
|
|
|
|
2021-04-09 00:22:17 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub to: Option<Value>,
|
2022-05-11 12:50:36 +00:00
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub updated: Option<DateTime<Utc>>,
|
2021-04-09 00:22:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize, Serialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct Activity {
|
|
|
|
#[serde(rename = "@context")]
|
|
|
|
pub context: Value,
|
|
|
|
|
|
|
|
pub id: String,
|
|
|
|
|
|
|
|
#[serde(rename = "type")]
|
|
|
|
pub activity_type: String,
|
|
|
|
|
|
|
|
pub actor: String,
|
|
|
|
pub object: Value,
|
2021-11-20 21:15:56 +00:00
|
|
|
pub to: Option<Value>,
|
2022-01-04 20:52:41 +00:00
|
|
|
pub cc: Option<Value>,
|
2021-04-09 00:22:17 +00:00
|
|
|
}
|
|
|
|
|
2022-06-01 21:39:23 +00:00
|
|
|
pub fn create_activity(
|
2021-04-09 00:22:17 +00:00
|
|
|
instance_url: &str,
|
|
|
|
actor_name: &str,
|
|
|
|
activity_type: &str,
|
2022-04-14 18:05:10 +00:00
|
|
|
activity_id: String,
|
2021-11-12 21:33:19 +00:00
|
|
|
object: impl Serialize,
|
2022-01-04 20:52:41 +00:00
|
|
|
primary_audience: Vec<String>,
|
|
|
|
secondary_audience: Vec<String>,
|
2021-04-09 00:22:17 +00:00
|
|
|
) -> Activity {
|
|
|
|
let actor_id = get_actor_url(
|
|
|
|
instance_url,
|
2021-11-13 17:37:31 +00:00
|
|
|
actor_name,
|
2021-04-09 00:22:17 +00:00
|
|
|
);
|
2021-11-13 17:37:31 +00:00
|
|
|
Activity {
|
2021-04-09 00:22:17 +00:00
|
|
|
context: json!(AP_CONTEXT),
|
|
|
|
id: activity_id,
|
|
|
|
activity_type: activity_type.to_string(),
|
|
|
|
actor: actor_id,
|
2021-11-12 21:33:19 +00:00
|
|
|
object: serde_json::to_value(object).unwrap(),
|
2022-01-04 20:52:41 +00:00
|
|
|
to: Some(json!(primary_audience)),
|
|
|
|
cc: Some(json!(secondary_audience)),
|
2021-11-13 17:37:31 +00:00
|
|
|
}
|
2021-04-09 00:22:17 +00:00
|
|
|
}
|