use crate::api::site::*;
use crate::api::user::*;
use crate::api::*;
+use crate::apub::puller::*;
use crate::websocket::UserOperation;
use crate::Settings;
sessions.remove(&id);
}
+ // Also leave all post rooms
+ // This avoids double messages
+ for sessions in self.post_rooms.values_mut() {
+ sessions.remove(&id);
+ }
+
// If the room doesn't exist yet
if self.community_rooms.get_mut(&community_id).is_none() {
self.community_rooms.insert(community_id, HashSet::new());
sessions.remove(&id);
}
+ // Also leave all communities
+ // This avoids double messages
+ for sessions in self.community_rooms.values_mut() {
+ sessions.remove(&id);
+ }
+
// If the room doesn't exist yet
if self.post_rooms.get_mut(&post_id).is_none() {
self.post_rooms.insert(post_id, HashSet::new());
self.send_user_room_message(recipient_id, &comment_reply_sent_str, id);
}
+ // Send it to the community too
+ self.send_community_room_message(0, &comment_post_sent_str, id);
+ self.send_community_room_message(comment.comment.community_id, &comment_post_sent_str, id);
+
Ok(comment_user_sent_str)
}
self.send_community_room_message(0, &post_sent_str, id);
self.send_community_room_message(community_id, &post_sent_str, id);
+ // Send it to the post room
+ self.send_post_room_message(post_sent.post.id, &post_sent_str, id);
+
to_json_string(&user_operation, post)
}
}
UserOperation::GetCommunity => {
let get_community: GetCommunity = serde_json::from_str(data)?;
- let mut res = Oper::new(get_community).perform(&conn)?;
+
+ 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
+ get_remote_community(community_name)?
+ // TODO what is this about
+ // get_community.name = Some(name.replace("!", ""));
+ } else {
+ Oper::new(get_community).perform(&conn)?
+ }
+ } else {
+ Oper::new(get_community).perform(&conn)?
+ }
+ } else {
+ Oper::new(get_community).perform(&conn)?
+ };
+
let community_id = res.community.id;
chat.join_community_room(community_id, msg.id);
to_json_string(&user_operation, &res)
}
UserOperation::ListCommunities => {
- do_user_operation::<ListCommunities, ListCommunitiesResponse>(user_operation, data, &conn)
+ 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)
+ }
}
UserOperation::CreateCommunity => {
chat.check_rate_limit_register(msg.id, true)?;
let res = Oper::new(get_posts).perform(&conn)?;
to_json_string(&user_operation, &res)
}
+ UserOperation::GetComments => {
+ let get_comments: GetComments = serde_json::from_str(data)?;
+ if get_comments.community_id.is_none() {
+ // 0 is the "all" community
+ chat.join_community_room(0, msg.id);
+ }
+ let res = Oper::new(get_comments).perform(&conn)?;
+ to_json_string(&user_operation, &res)
+ }
UserOperation::CreatePost => {
chat.check_rate_limit_post(msg.id, true)?;
let create_post: CreatePost = serde_json::from_str(data)?;