Make project id optional when following - server only
This commit is contained in:
parent
83455028b0
commit
c71566e7f5
10 changed files with 204 additions and 55 deletions
|
@ -1883,24 +1883,19 @@ async fn follow(
|
|||
response: Response<proto::Follow>,
|
||||
session: Session,
|
||||
) -> Result<()> {
|
||||
let project_id = ProjectId::from_proto(request.project_id);
|
||||
let room_id = RoomId::from_proto(request.room_id);
|
||||
let project_id = request.project_id.map(ProjectId::from_proto);
|
||||
let leader_id = request
|
||||
.leader_id
|
||||
.ok_or_else(|| anyhow!("invalid leader id"))?
|
||||
.into();
|
||||
let follower_id = session.connection_id;
|
||||
|
||||
{
|
||||
let project_connection_ids = session
|
||||
.db()
|
||||
.await
|
||||
.project_connection_ids(project_id, session.connection_id)
|
||||
.await?;
|
||||
|
||||
if !project_connection_ids.contains(&leader_id) {
|
||||
Err(anyhow!("no such peer"))?;
|
||||
}
|
||||
}
|
||||
session
|
||||
.db()
|
||||
.await
|
||||
.check_can_follow(room_id, project_id, leader_id, session.connection_id)
|
||||
.await?;
|
||||
|
||||
let mut response_payload = session
|
||||
.peer
|
||||
|
@ -1914,7 +1909,7 @@ async fn follow(
|
|||
let room = session
|
||||
.db()
|
||||
.await
|
||||
.follow(project_id, leader_id, follower_id)
|
||||
.follow(room_id, project_id, leader_id, follower_id)
|
||||
.await?;
|
||||
room_updated(&room, &session.peer);
|
||||
|
||||
|
@ -1922,22 +1917,19 @@ async fn follow(
|
|||
}
|
||||
|
||||
async fn unfollow(request: proto::Unfollow, session: Session) -> Result<()> {
|
||||
let project_id = ProjectId::from_proto(request.project_id);
|
||||
let room_id = RoomId::from_proto(request.room_id);
|
||||
let project_id = request.project_id.map(ProjectId::from_proto);
|
||||
let leader_id = request
|
||||
.leader_id
|
||||
.ok_or_else(|| anyhow!("invalid leader id"))?
|
||||
.into();
|
||||
let follower_id = session.connection_id;
|
||||
|
||||
if !session
|
||||
session
|
||||
.db()
|
||||
.await
|
||||
.project_connection_ids(project_id, session.connection_id)
|
||||
.await?
|
||||
.contains(&leader_id)
|
||||
{
|
||||
Err(anyhow!("no such peer"))?;
|
||||
}
|
||||
.check_can_unfollow(room_id, project_id, leader_id, session.connection_id)
|
||||
.await?;
|
||||
|
||||
session
|
||||
.peer
|
||||
|
@ -1946,7 +1938,7 @@ async fn unfollow(request: proto::Unfollow, session: Session) -> Result<()> {
|
|||
let room = session
|
||||
.db()
|
||||
.await
|
||||
.unfollow(project_id, leader_id, follower_id)
|
||||
.unfollow(room_id, project_id, leader_id, follower_id)
|
||||
.await?;
|
||||
room_updated(&room, &session.peer);
|
||||
|
||||
|
@ -1954,13 +1946,19 @@ async fn unfollow(request: proto::Unfollow, session: Session) -> Result<()> {
|
|||
}
|
||||
|
||||
async fn update_followers(request: proto::UpdateFollowers, session: Session) -> Result<()> {
|
||||
let project_id = ProjectId::from_proto(request.project_id);
|
||||
let project_connection_ids = session
|
||||
.db
|
||||
.lock()
|
||||
.await
|
||||
.project_connection_ids(project_id, session.connection_id)
|
||||
.await?;
|
||||
let room_id = RoomId::from_proto(request.room_id);
|
||||
let database = session.db.lock().await;
|
||||
|
||||
let connection_ids = if let Some(project_id) = request.project_id {
|
||||
let project_id = ProjectId::from_proto(project_id);
|
||||
database
|
||||
.project_connection_ids(project_id, session.connection_id)
|
||||
.await?
|
||||
} else {
|
||||
database
|
||||
.room_connection_ids(room_id, session.connection_id)
|
||||
.await?
|
||||
};
|
||||
|
||||
let leader_id = request.variant.as_ref().and_then(|variant| match variant {
|
||||
proto::update_followers::Variant::CreateView(payload) => payload.leader_id,
|
||||
|
@ -1969,9 +1967,7 @@ async fn update_followers(request: proto::UpdateFollowers, session: Session) ->
|
|||
});
|
||||
for follower_peer_id in request.follower_ids.iter().copied() {
|
||||
let follower_connection_id = follower_peer_id.into();
|
||||
if project_connection_ids.contains(&follower_connection_id)
|
||||
&& Some(follower_peer_id) != leader_id
|
||||
{
|
||||
if Some(follower_peer_id) != leader_id && connection_ids.contains(&follower_connection_id) {
|
||||
session.peer.forward_send(
|
||||
session.connection_id,
|
||||
follower_connection_id,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue