2021-07-27 22:18:50 +00:00
|
|
|
use crate::{check_is_apub_id_valid, CommunityType};
|
|
|
|
use itertools::Itertools;
|
Apub inbox rewrite (#1652)
* start to implement apub inbox routing lib
* got something that almost works
* it compiles!
* implemented some more
* move library code to separate crate (most of it)
* convert private message handlers
* convert all comment receivers (except undo comment)
* convert post receiver
* add verify trait
* convert community receivers
* add cc field for all activities which i forgot before
* convert inbox functions, add missing checks
* convert undo like/dislike receivers
* convert undo_delete and undo_remove receivers
* move block/unblock activities
* convert remaining activity receivers
* reimplement http signature verification and other checks
* also use actor type for routing, VerifyActivity and SendActivity traits
* cleanup and restructure apub_receive code
* wip: try to fix activity routing
* implement a (very bad) derive macro for activityhandler
* working activity routing!
* rework pm verify(), fix tests and confirm manually
also remove inbox username check which was broken
* rework following verify(), fix tests and test manually
* fix post/comment create/update, rework voting
* Rewrite remove/delete post/comment, fix tests, test manually
* Rework and fix (un)block user, announce, update post
* some code cleanup
* rework delete/remove activity receivers (still quite messy)
* rewrite, test and fix add/remove mod, update community handlers
* add docs for ActivityHandler derive macro
* dont try to compile macro comments
2021-07-17 16:08:46 +00:00
|
|
|
use lemmy_api_common::{blocking, community::CommunityResponse};
|
2021-07-27 22:18:50 +00:00
|
|
|
use lemmy_db_schema::{source::community::Community, CommunityId};
|
Apub inbox rewrite (#1652)
* start to implement apub inbox routing lib
* got something that almost works
* it compiles!
* implemented some more
* move library code to separate crate (most of it)
* convert private message handlers
* convert all comment receivers (except undo comment)
* convert post receiver
* add verify trait
* convert community receivers
* add cc field for all activities which i forgot before
* convert inbox functions, add missing checks
* convert undo like/dislike receivers
* convert undo_delete and undo_remove receivers
* move block/unblock activities
* convert remaining activity receivers
* reimplement http signature verification and other checks
* also use actor type for routing, VerifyActivity and SendActivity traits
* cleanup and restructure apub_receive code
* wip: try to fix activity routing
* implement a (very bad) derive macro for activityhandler
* working activity routing!
* rework pm verify(), fix tests and confirm manually
also remove inbox username check which was broken
* rework following verify(), fix tests and test manually
* fix post/comment create/update, rework voting
* Rewrite remove/delete post/comment, fix tests, test manually
* Rework and fix (un)block user, announce, update post
* some code cleanup
* rework delete/remove activity receivers (still quite messy)
* rewrite, test and fix add/remove mod, update community handlers
* add docs for ActivityHandler derive macro
* dont try to compile macro comments
2021-07-17 16:08:46 +00:00
|
|
|
use lemmy_db_views_actor::community_view::CommunityView;
|
2021-07-27 22:18:50 +00:00
|
|
|
use lemmy_utils::{settings::structs::Settings, LemmyError};
|
Apub inbox rewrite (#1652)
* start to implement apub inbox routing lib
* got something that almost works
* it compiles!
* implemented some more
* move library code to separate crate (most of it)
* convert private message handlers
* convert all comment receivers (except undo comment)
* convert post receiver
* add verify trait
* convert community receivers
* add cc field for all activities which i forgot before
* convert inbox functions, add missing checks
* convert undo like/dislike receivers
* convert undo_delete and undo_remove receivers
* move block/unblock activities
* convert remaining activity receivers
* reimplement http signature verification and other checks
* also use actor type for routing, VerifyActivity and SendActivity traits
* cleanup and restructure apub_receive code
* wip: try to fix activity routing
* implement a (very bad) derive macro for activityhandler
* working activity routing!
* rework pm verify(), fix tests and confirm manually
also remove inbox username check which was broken
* rework following verify(), fix tests and test manually
* fix post/comment create/update, rework voting
* Rewrite remove/delete post/comment, fix tests, test manually
* Rework and fix (un)block user, announce, update post
* some code cleanup
* rework delete/remove activity receivers (still quite messy)
* rewrite, test and fix add/remove mod, update community handlers
* add docs for ActivityHandler derive macro
* dont try to compile macro comments
2021-07-17 16:08:46 +00:00
|
|
|
use lemmy_websocket::{messages::SendCommunityRoomMessage, LemmyContext};
|
2021-07-27 22:18:50 +00:00
|
|
|
use url::Url;
|
Apub inbox rewrite (#1652)
* start to implement apub inbox routing lib
* got something that almost works
* it compiles!
* implemented some more
* move library code to separate crate (most of it)
* convert private message handlers
* convert all comment receivers (except undo comment)
* convert post receiver
* add verify trait
* convert community receivers
* add cc field for all activities which i forgot before
* convert inbox functions, add missing checks
* convert undo like/dislike receivers
* convert undo_delete and undo_remove receivers
* move block/unblock activities
* convert remaining activity receivers
* reimplement http signature verification and other checks
* also use actor type for routing, VerifyActivity and SendActivity traits
* cleanup and restructure apub_receive code
* wip: try to fix activity routing
* implement a (very bad) derive macro for activityhandler
* working activity routing!
* rework pm verify(), fix tests and confirm manually
also remove inbox username check which was broken
* rework following verify(), fix tests and test manually
* fix post/comment create/update, rework voting
* Rewrite remove/delete post/comment, fix tests, test manually
* Rework and fix (un)block user, announce, update post
* some code cleanup
* rework delete/remove activity receivers (still quite messy)
* rewrite, test and fix add/remove mod, update community handlers
* add docs for ActivityHandler derive macro
* dont try to compile macro comments
2021-07-17 16:08:46 +00:00
|
|
|
|
|
|
|
pub mod add_mod;
|
|
|
|
pub mod announce;
|
|
|
|
pub mod block_user;
|
|
|
|
pub mod undo_block_user;
|
|
|
|
pub mod update;
|
|
|
|
|
|
|
|
pub(crate) async fn send_websocket_message<
|
|
|
|
OP: ToString + Send + lemmy_websocket::OperationType + 'static,
|
|
|
|
>(
|
|
|
|
community_id: CommunityId,
|
|
|
|
op: OP,
|
|
|
|
context: &LemmyContext,
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
let community_view = blocking(context.pool(), move |conn| {
|
|
|
|
CommunityView::read(conn, community_id, None)
|
|
|
|
})
|
|
|
|
.await??;
|
|
|
|
|
|
|
|
let res = CommunityResponse { community_view };
|
|
|
|
|
|
|
|
context.chat_server().do_send(SendCommunityRoomMessage {
|
|
|
|
op,
|
|
|
|
response: res,
|
|
|
|
community_id,
|
|
|
|
websocket_id: None,
|
|
|
|
});
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
2021-07-27 22:18:50 +00:00
|
|
|
|
|
|
|
async fn list_community_follower_inboxes(
|
|
|
|
community: &Community,
|
|
|
|
additional_inboxes: Vec<Url>,
|
|
|
|
context: &LemmyContext,
|
|
|
|
) -> Result<Vec<Url>, LemmyError> {
|
|
|
|
Ok(
|
|
|
|
vec![
|
|
|
|
community.get_follower_inboxes(context.pool()).await?,
|
|
|
|
additional_inboxes,
|
|
|
|
]
|
|
|
|
.iter()
|
|
|
|
.flatten()
|
|
|
|
.unique()
|
2021-08-04 21:13:51 +00:00
|
|
|
.filter(|inbox| inbox.host_str() != Some(&Settings::get().hostname))
|
2021-07-27 22:18:50 +00:00
|
|
|
.filter(|inbox| check_is_apub_id_valid(inbox, false).is_ok())
|
|
|
|
.map(|inbox| inbox.to_owned())
|
|
|
|
.collect(),
|
|
|
|
)
|
|
|
|
}
|