Kibou is a federated social networking server.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

activity.rs 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. use activity;
  2. use database;
  3. use env;
  4. use rocket_contrib::json;
  5. use rocket_contrib::json::JsonValue;
  6. use serde::{Serialize, Deserialize};
  7. use serde_json;
  8. // ActivityStreams2/AcitivityPub properties are expressed in CamelCase
  9. #[allow(non_snake_case)]
  10. #[derive(Serialize, Deserialize)]
  11. pub struct Activity
  12. {
  13. // Properties according to
  14. // - https://www.w3.org/TR/activitystreams-core/#activities
  15. #[serde(rename = "@context")]
  16. pub context: Vec<String>,
  17. #[serde(rename = "type")]
  18. pub _type: String,
  19. pub id: String,
  20. pub actor: String,
  21. pub object: serde_json::Value,
  22. pub published: String,
  23. pub to: Vec<String>,
  24. pub cc: Vec<String>
  25. }
  26. #[allow(non_snake_case)]
  27. #[derive(Serialize, Deserialize)]
  28. pub struct Object
  29. {
  30. #[serde(rename = "type")]
  31. pub _type: String,
  32. pub id: String,
  33. pub published: String,
  34. pub attributedTo: String,
  35. pub inReplyTo: Option<String>,
  36. pub summary: Option<String>,
  37. pub content: String,
  38. pub to: Vec<String>,
  39. pub cc: Vec<String>,
  40. pub tag: Vec<serde_json::Value>
  41. }
  42. #[derive(Serialize, Deserialize)]
  43. pub struct Tag
  44. {
  45. #[serde(rename = "type")]
  46. pub _type: String,
  47. pub href: String,
  48. pub name: String
  49. }
  50. pub fn get_json_by_id(id: String) -> JsonValue
  51. {
  52. let database = database::establish_connection();
  53. let object_id = format!("{}://{}/objects/{}", env::get_value(String::from("endpoint.base_scheme")), env::get_value(String::from("endpoint.base_domain")), id);
  54. match activity::get_ap_object_by_id(&database, &object_id)
  55. {
  56. Ok(activity) => json!(serialize_from_internal_activity(activity).object),
  57. Err(_) => json!({"error": "Object not found."})
  58. }
  59. }
  60. pub fn serialize_from_internal_activity(activity: activity::Activity) -> Activity
  61. {
  62. let payload: Activity = serde_json::from_value(activity.data).unwrap();
  63. payload
  64. }
  65. pub fn create_internal_activity(json_activity: serde_json::Value, actor_uri: String) -> activity::Activity
  66. {
  67. activity::Activity
  68. {
  69. id: 0,
  70. data: json_activity,
  71. actor: actor_uri
  72. }
  73. }