]> Untitled Git - lemmy.git/commitdiff
Merge branch 'dev' into federation
authorDessalines <tyhou13@gmx.com>
Mon, 10 Feb 2020 16:52:32 +0000 (11:52 -0500)
committerDessalines <tyhou13@gmx.com>
Mon, 10 Feb 2020 16:52:32 +0000 (11:52 -0500)
1  2 
server/src/websocket/server.rs

index 7ba79e6c49dff70ef074ca773ba318bcf341ae5f,1cbcb34fb738ebd10e853d65a196fa10246b5e28..76a55540f887ea2b5fad8b444e48dcdaeb52d0d8
@@@ -20,7 -20,6 +20,7 @@@ use crate::api::post::*
  use crate::api::site::*;
  use crate::api::user::*;
  use crate::api::*;
 +use crate::apub::puller::*;
  use crate::websocket::UserOperation;
  use crate::Settings;
  
@@@ -122,6 -121,12 +122,12 @@@ impl ChatServer 
        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)
    }
  
@@@ -532,24 -550,7 +551,24 @@@ fn parse_json_message(chat: &mut ChatSe
      }
      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)?;