Skip to main content

feder_core/
storage.rs

1// Feder: A portable ActivityPub core for many runtimes.
2// Copyright (C) 2026 Feder contributors
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU Affero General Public License as published by
6// the Free Software Foundation, version 3.
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11// GNU Affero General Public License for more details.
12//
13// You should have received a copy of the GNU Affero General Public License
14// along with this program.  If not, see <https://www.gnu.org/licenses/>.
15
16use alloc::vec::Vec;
17
18use feder_vocab::{Actor, Iri, Note};
19
20use crate::follow::PendingFollow;
21#[cfg(feature = "http-signatures")]
22use crate::key::ActorKeyPair;
23
24pub trait Storage {
25    type Error;
26}
27
28pub trait ServerStorage: Storage {
29    fn store_follower(&self, follower: &Actor, following: &Iri) -> Result<(), Self::Error>;
30
31    #[cfg(feature = "http-signatures")]
32    fn load_actor_key_pair(&self, actor_id: &Iri) -> Result<Option<ActorKeyPair>, Self::Error>;
33
34    fn remove_follower(&self, follower: &Iri, following: &Iri) -> Result<(), Self::Error>;
35
36    fn list_followers(&self, following: &Iri) -> Result<Vec<Iri>, Self::Error>;
37
38    fn store_pending_follow(&self, follow: &PendingFollow) -> Result<(), Self::Error>;
39
40    fn load_pending_follow(
41        &self,
42        follow_activity: &Iri,
43    ) -> Result<Option<PendingFollow>, Self::Error>;
44
45    /// Confirm `expected` only if that exact relationship is still pending.
46    fn confirm_pending_follow(&self, expected: &PendingFollow) -> Result<bool, Self::Error>;
47}
48
49pub trait NoteStore: Storage {
50    fn store_note(&self, note: &Note) -> Result<(), Self::Error>;
51
52    fn load_note(&self, note_id: &Iri) -> Result<Option<Note>, Self::Error>;
53}
54
55/// The stored addressing facts needed to deliver an activity to a follower.
56#[derive(Clone, Debug, Eq, PartialEq)]
57pub struct FollowerDeliveryTarget {
58    pub actor_id: Iri,
59    pub inbox: Iri,
60    pub shared_inbox: Option<Iri>,
61}
62
63pub trait FollowerDeliveryStore: ServerStorage {
64    fn list_follower_delivery_targets(
65        &self,
66        local_actor: &Iri,
67    ) -> Result<Vec<FollowerDeliveryTarget>, Self::Error>;
68}