summaryrefslogtreecommitdiffstats
path: root/server/src/api/community.rs
diff options
context:
space:
mode:
authorFelix Ableitner <me@nutomic.com>2020-03-14 13:15:23 +0100
committerFelix Ableitner <me@nutomic.com>2020-03-14 13:15:23 +0100
commit5896a9d251f13e4387fe34e0f8cd21317494ec15 (patch)
tree4a8a66135602f4cbc8375926559dece271d2c90d /server/src/api/community.rs
parentb01f4f75d6dbbc579099422ccb2a897899dfe343 (diff)
Move apub related code from websocket into api package
Diffstat (limited to 'server/src/api/community.rs')
-rw-r--r--server/src/api/community.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/server/src/api/community.rs b/server/src/api/community.rs
index 7d5f8d61..0f104c2d 100644
--- a/server/src/api/community.rs
+++ b/server/src/api/community.rs
@@ -1,4 +1,6 @@
use super::*;
+use crate::apub::puller::{get_all_communities, get_remote_community};
+use crate::settings::Settings;
use diesel::PgConnection;
use std::str::FromStr;
@@ -117,6 +119,13 @@ impl Perform<GetCommunityResponse> for Oper<GetCommunity> {
fn perform(&self, conn: &PgConnection) -> Result<GetCommunityResponse, Error> {
let data: &GetCommunity = &self.data;
+ if data.name.is_some()
+ && Settings::get().federation_enabled
+ && data.name.as_ref().unwrap().contains('@')
+ {
+ return get_remote_community(data.name.as_ref().unwrap());
+ }
+
let user_id: Option<i32> = match &data.auth {
Some(auth) => match Claims::decode(&auth) {
Ok(claims) => {
@@ -333,6 +342,12 @@ impl Perform<ListCommunitiesResponse> for Oper<ListCommunities> {
fn perform(&self, conn: &PgConnection) -> Result<ListCommunitiesResponse, Error> {
let data: &ListCommunities = &self.data;
+ if Settings::get().federation_enabled {
+ return Ok(ListCommunitiesResponse {
+ communities: get_all_communities()?,
+ });
+ }
+
let user_claims: Option<Claims> = match &data.auth {
Some(auth) => match Claims::decode(&auth) {
Ok(claims) => Some(claims.claims),