2023-09-09 16:25:03 +00:00
|
|
|
use crate::{
|
|
|
|
newtypes::{CommunityId, DbUrl},
|
|
|
|
schema::sent_activity,
|
|
|
|
};
|
2023-08-24 15:27:00 +00:00
|
|
|
use chrono::{DateTime, Utc};
|
2023-09-09 16:25:03 +00:00
|
|
|
use diesel::{sql_types::Nullable, Queryable};
|
2020-12-21 13:38:34 +00:00
|
|
|
use serde_json::Value;
|
2023-09-09 16:25:03 +00:00
|
|
|
use std::{collections::HashSet, fmt::Debug};
|
|
|
|
use url::Url;
|
|
|
|
|
|
|
|
#[derive(FromSqlRow, PartialEq, Eq, Debug, Default, Clone)]
|
|
|
|
/// describes where an activity should be sent
|
|
|
|
pub struct ActivitySendTargets {
|
|
|
|
/// send to these inboxes explicitly
|
|
|
|
pub inboxes: HashSet<Url>,
|
|
|
|
/// send to all followers of these local communities
|
|
|
|
pub community_followers_of: Option<CommunityId>,
|
|
|
|
/// send to all remote instances
|
|
|
|
pub all_instances: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
// todo: in different file?
|
|
|
|
impl ActivitySendTargets {
|
|
|
|
pub fn empty() -> ActivitySendTargets {
|
|
|
|
ActivitySendTargets::default()
|
|
|
|
}
|
|
|
|
pub fn to_inbox(url: Url) -> ActivitySendTargets {
|
|
|
|
let mut a = ActivitySendTargets::empty();
|
|
|
|
a.inboxes.insert(url);
|
|
|
|
a
|
|
|
|
}
|
|
|
|
pub fn to_local_community_followers(id: CommunityId) -> ActivitySendTargets {
|
|
|
|
let mut a = ActivitySendTargets::empty();
|
|
|
|
a.community_followers_of = Some(id);
|
|
|
|
a
|
|
|
|
}
|
|
|
|
pub fn to_all_instances() -> ActivitySendTargets {
|
|
|
|
let mut a = ActivitySendTargets::empty();
|
|
|
|
a.all_instances = true;
|
|
|
|
a
|
|
|
|
}
|
|
|
|
pub fn set_all_instances(&mut self) {
|
|
|
|
self.all_instances = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn add_inbox(&mut self, inbox: Url) {
|
|
|
|
self.inboxes.insert(inbox);
|
|
|
|
}
|
|
|
|
pub fn add_inboxes(&mut self, inboxes: impl Iterator<Item = Url>) {
|
|
|
|
self.inboxes.extend(inboxes);
|
|
|
|
}
|
|
|
|
}
|
2020-12-21 13:38:34 +00:00
|
|
|
|
2023-07-14 15:17:06 +00:00
|
|
|
#[derive(PartialEq, Eq, Debug, Queryable)]
|
|
|
|
#[diesel(table_name = sent_activity)]
|
|
|
|
pub struct SentActivity {
|
|
|
|
pub id: i64,
|
2021-11-22 18:57:03 +00:00
|
|
|
pub ap_id: DbUrl,
|
2023-07-14 15:17:06 +00:00
|
|
|
pub data: Value,
|
2023-04-17 19:19:51 +00:00
|
|
|
pub sensitive: bool,
|
2023-08-24 15:27:00 +00:00
|
|
|
pub published: DateTime<Utc>,
|
2023-09-09 16:25:03 +00:00
|
|
|
pub send_inboxes: Vec<Option<DbUrl>>,
|
|
|
|
pub send_community_followers_of: Option<CommunityId>,
|
|
|
|
pub send_all_instances: bool,
|
|
|
|
pub actor_type: ActorType,
|
|
|
|
pub actor_apub_id: Option<DbUrl>,
|
2020-12-21 13:38:34 +00:00
|
|
|
}
|
2023-09-09 16:25:03 +00:00
|
|
|
|
2022-10-27 09:24:07 +00:00
|
|
|
#[derive(Insertable)]
|
2023-07-14 15:17:06 +00:00
|
|
|
#[diesel(table_name = sent_activity)]
|
|
|
|
pub struct SentActivityForm {
|
2021-03-02 12:41:48 +00:00
|
|
|
pub ap_id: DbUrl,
|
2023-07-14 15:17:06 +00:00
|
|
|
pub data: Value,
|
|
|
|
pub sensitive: bool,
|
2023-09-09 16:25:03 +00:00
|
|
|
pub send_inboxes: Vec<Option<DbUrl>>,
|
|
|
|
pub send_community_followers_of: Option<i32>,
|
|
|
|
pub send_all_instances: bool,
|
|
|
|
pub actor_type: ActorType,
|
|
|
|
pub actor_apub_id: DbUrl,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug, diesel_derive_enum::DbEnum, PartialEq, Eq)]
|
|
|
|
#[ExistingTypePath = "crate::schema::sql_types::ActorTypeEnum"]
|
|
|
|
pub enum ActorType {
|
|
|
|
Site,
|
|
|
|
Community,
|
|
|
|
Person,
|
2022-10-27 09:24:07 +00:00
|
|
|
}
|
|
|
|
|
2023-07-14 15:17:06 +00:00
|
|
|
#[derive(PartialEq, Eq, Debug, Queryable)]
|
|
|
|
#[diesel(table_name = received_activity)]
|
|
|
|
pub struct ReceivedActivity {
|
|
|
|
pub id: i64,
|
|
|
|
pub ap_id: DbUrl,
|
2023-08-24 15:27:00 +00:00
|
|
|
pub published: DateTime<Utc>,
|
2020-12-21 13:38:34 +00:00
|
|
|
}
|