use super::*;
+use crate::apub::puller::{get_all_communities, get_remote_community};
+use crate::settings::Settings;
use diesel::PgConnection;
use std::str::FromStr;
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) => {
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),
use super::*;
+use crate::settings::Settings;
use diesel::PgConnection;
use std::str::FromStr;
fn perform(&self, conn: &PgConnection) -> Result<GetPostsResponse, Error> {
let data: &GetPosts = &self.data;
+ if Settings::get().federation_enabled {
+ dbg!(&data);
+ // TODO: intercept here (but the type is wrong)
+ //get_remote_community_posts(get_posts.community_id.unwrap())
+ }
+
let user_claims: Option<Claims> = match &data.auth {
Some(auth) => match Claims::decode(&auth) {
Ok(claims) => Some(claims.claims),
}
// TODO: this should be cached or stored in the database
-fn get_remote_community_uri(identifier: String) -> String {
+fn get_remote_community_uri(identifier: &str) -> String {
let x: Vec<&str> = identifier.split('@').collect();
let name = x[0].replace("!", "");
let instance = x[1];
format!("http://{}/federation/c/{}", instance, name)
}
-pub fn get_remote_community_posts(identifier: String) -> Result<GetPostsResponse, Error> {
+pub fn get_remote_community_posts(identifier: &str) -> Result<GetPostsResponse, Error> {
let community: Group = reqwest::get(&get_remote_community_uri(identifier))?.json()?;
let outbox_uri = &community.ap_actor_props.get_outbox().to_string();
let outbox: OrderedCollection = reqwest::get(outbox_uri)?.json()?;
unimplemented!()
}
-pub fn get_remote_community(identifier: String) -> Result<GetCommunityResponse, failure::Error> {
- let community: Group = reqwest::get(&get_remote_community_uri(identifier.clone()))?.json()?;
+pub fn get_remote_community(identifier: &str) -> Result<GetCommunityResponse, failure::Error> {
+ let community: Group = reqwest::get(&get_remote_community_uri(identifier))?.json()?;
let followers_uri = &community
.ap_actor_props
.get_followers()
community: CommunityView {
// TODO: we need to merge id and name into a single thing (stuff like @user@instance.com)
id: 1337, //community.object_props.get_id()
- name: identifier,
+ name: identifier.to_string(),
title: community
.object_props
.get_name_xsd_string()
use crate::api::site::*;
use crate::api::user::*;
use crate::api::*;
-use crate::apub::puller::*;
use crate::websocket::UserOperation;
use crate::Settings;
let user_operation: UserOperation = UserOperation::from_str(&op)?;
- // TODO: none of the chat messages are going to work if stuff is submitted via http api,
- // need to move that handling elsewhere
-
// A DDOS check
chat.check_rate_limit_message(msg.id, false)?;
UserOperation::GetCommunity => {
let get_community: GetCommunity = serde_json::from_str(data)?;
- let mut res = if Settings::get().federation_enabled {
- if let Some(community_name) = get_community.name.to_owned() {
- if community_name.contains('@') {
- // TODO: need to support sort, filter etc for remote communities
- // TODO: need to to this for http api as well
- get_remote_community(community_name)?
- } else {
- Oper::new(get_community).perform(&conn)?
- }
- } else {
- Oper::new(get_community).perform(&conn)?
- }
- } else {
- Oper::new(get_community).perform(&conn)?
- };
+ let mut res = Oper::new(get_community).perform(&conn)?;
let community_id = res.community.id;
to_json_string(&user_operation, &res)
}
UserOperation::ListCommunities => {
- if Settings::get().federation_enabled {
- let res = get_all_communities()?;
- let val = ListCommunitiesResponse { communities: res };
- to_json_string(&user_operation, &val)
- } else {
- do_user_operation::<ListCommunities, ListCommunitiesResponse>(user_operation, data, &conn)
- }
+ do_user_operation::<ListCommunities, ListCommunitiesResponse>(user_operation, data, &conn)
}
UserOperation::CreateCommunity => {
chat.check_rate_limit_register(msg.id, true)?;
}
UserOperation::GetPosts => {
let get_posts: GetPosts = serde_json::from_str(data)?;
- dbg!(&get_posts);
- // TODO: intercept here (but the type is wrong)
- //get_remote_community_posts(get_posts.community_id.unwrap())
+
if get_posts.community_id.is_none() {
// 0 is the "all" community
chat.join_community_room(0, msg.id);