Initial tracking of unfollows on collab server
This commit is contained in:
parent
d6462c611c
commit
2592ec7265
2 changed files with 59 additions and 4 deletions
|
@ -1747,6 +1747,47 @@ impl Database {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn unfollow(
|
||||||
|
&self,
|
||||||
|
room_id: RoomId,
|
||||||
|
project_id: ProjectId,
|
||||||
|
leader_connection: ConnectionId,
|
||||||
|
follower_connection: ConnectionId,
|
||||||
|
) -> Result<RoomGuard<proto::Room>> {
|
||||||
|
self.room_transaction(|tx| async move {
|
||||||
|
follower::Entity::delete_many()
|
||||||
|
.filter(
|
||||||
|
Condition::all()
|
||||||
|
.add(follower::Column::RoomId.eq(room_id))
|
||||||
|
.add(follower::Column::ProjectId.eq(project_id))
|
||||||
|
.add(
|
||||||
|
Condition::any()
|
||||||
|
.add(
|
||||||
|
follower::Column::LeaderConnectionServerId
|
||||||
|
.eq(leader_connection.owner_id)
|
||||||
|
.and(
|
||||||
|
follower::Column::LeaderConnectionId
|
||||||
|
.eq(leader_connection.id),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.add(
|
||||||
|
follower::Column::FollowerConnectionServerId
|
||||||
|
.eq(follower_connection.owner_id)
|
||||||
|
.and(
|
||||||
|
follower::Column::FollowerConnectionId
|
||||||
|
.eq(follower_connection.id),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.exec(&*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok((room_id, self.get_room(room_id, &*tx).await?))
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn update_room_participant_location(
|
pub async fn update_room_participant_location(
|
||||||
&self,
|
&self,
|
||||||
room_id: RoomId,
|
room_id: RoomId,
|
||||||
|
|
|
@ -1719,13 +1719,14 @@ async fn follow(
|
||||||
response: Response<proto::Follow>,
|
response: Response<proto::Follow>,
|
||||||
session: Session,
|
session: Session,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let project_id = ProjectId::from_proto(request.project_id);
|
|
||||||
let room_id = RoomId::from_proto(request.project_id);
|
let room_id = RoomId::from_proto(request.project_id);
|
||||||
|
let project_id = ProjectId::from_proto(request.project_id);
|
||||||
let leader_id = request
|
let leader_id = request
|
||||||
.leader_id
|
.leader_id
|
||||||
.ok_or_else(|| anyhow!("invalid leader id"))?
|
.ok_or_else(|| anyhow!("invalid leader id"))?
|
||||||
.into();
|
.into();
|
||||||
let follower_id = session.connection_id;
|
let follower_id = session.connection_id;
|
||||||
|
|
||||||
{
|
{
|
||||||
let project_connection_ids = session
|
let project_connection_ids = session
|
||||||
.db()
|
.db()
|
||||||
|
@ -1758,22 +1759,35 @@ async fn follow(
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn unfollow(request: proto::Unfollow, session: Session) -> Result<()> {
|
async fn unfollow(request: proto::Unfollow, session: Session) -> Result<()> {
|
||||||
|
let room_id = RoomId::from_proto(request.project_id);
|
||||||
let project_id = ProjectId::from_proto(request.project_id);
|
let project_id = ProjectId::from_proto(request.project_id);
|
||||||
let leader_id = request
|
let leader_id = request
|
||||||
.leader_id
|
.leader_id
|
||||||
.ok_or_else(|| anyhow!("invalid leader id"))?
|
.ok_or_else(|| anyhow!("invalid leader id"))?
|
||||||
.into();
|
.into();
|
||||||
let project_connection_ids = session
|
let follower_id = session.connection_id;
|
||||||
|
|
||||||
|
if !session
|
||||||
.db()
|
.db()
|
||||||
.await
|
.await
|
||||||
.project_connection_ids(project_id, session.connection_id)
|
.project_connection_ids(project_id, session.connection_id)
|
||||||
.await?;
|
.await?
|
||||||
if !project_connection_ids.contains(&leader_id) {
|
.contains(&leader_id)
|
||||||
|
{
|
||||||
Err(anyhow!("no such peer"))?;
|
Err(anyhow!("no such peer"))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
session
|
session
|
||||||
.peer
|
.peer
|
||||||
.forward_send(session.connection_id, leader_id, request)?;
|
.forward_send(session.connection_id, leader_id, request)?;
|
||||||
|
|
||||||
|
let room = session
|
||||||
|
.db()
|
||||||
|
.await
|
||||||
|
.unfollow(room_id, project_id, leader_id, follower_id)
|
||||||
|
.await?;
|
||||||
|
room_updated(&room, &session.peer);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue