mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-12 05:15:00 +00:00
Retrieve room id from the project when following/unfollowing
Previously, we were accidentally using the project id as the room id.
This commit is contained in:
parent
c75aca25b6
commit
0dc92bec5c
2 changed files with 23 additions and 7 deletions
|
@ -1720,12 +1720,12 @@ impl Database {
|
||||||
|
|
||||||
pub async fn follow(
|
pub async fn follow(
|
||||||
&self,
|
&self,
|
||||||
room_id: RoomId,
|
|
||||||
project_id: ProjectId,
|
project_id: ProjectId,
|
||||||
leader_connection: ConnectionId,
|
leader_connection: ConnectionId,
|
||||||
follower_connection: ConnectionId,
|
follower_connection: ConnectionId,
|
||||||
) -> Result<RoomGuard<proto::Room>> {
|
) -> Result<RoomGuard<proto::Room>> {
|
||||||
self.room_transaction(|tx| async move {
|
self.room_transaction(|tx| async move {
|
||||||
|
let room_id = self.room_id_for_project(project_id, &*tx).await?;
|
||||||
follower::ActiveModel {
|
follower::ActiveModel {
|
||||||
room_id: ActiveValue::set(room_id),
|
room_id: ActiveValue::set(room_id),
|
||||||
project_id: ActiveValue::set(project_id),
|
project_id: ActiveValue::set(project_id),
|
||||||
|
@ -1749,16 +1749,15 @@ impl Database {
|
||||||
|
|
||||||
pub async fn unfollow(
|
pub async fn unfollow(
|
||||||
&self,
|
&self,
|
||||||
room_id: RoomId,
|
|
||||||
project_id: ProjectId,
|
project_id: ProjectId,
|
||||||
leader_connection: ConnectionId,
|
leader_connection: ConnectionId,
|
||||||
follower_connection: ConnectionId,
|
follower_connection: ConnectionId,
|
||||||
) -> Result<RoomGuard<proto::Room>> {
|
) -> Result<RoomGuard<proto::Room>> {
|
||||||
self.room_transaction(|tx| async move {
|
self.room_transaction(|tx| async move {
|
||||||
|
let room_id = self.room_id_for_project(project_id, &*tx).await?;
|
||||||
follower::Entity::delete_many()
|
follower::Entity::delete_many()
|
||||||
.filter(
|
.filter(
|
||||||
Condition::all()
|
Condition::all()
|
||||||
.add(follower::Column::RoomId.eq(room_id))
|
|
||||||
.add(follower::Column::ProjectId.eq(project_id))
|
.add(follower::Column::ProjectId.eq(project_id))
|
||||||
.add(
|
.add(
|
||||||
Condition::any()
|
Condition::any()
|
||||||
|
@ -1788,6 +1787,25 @@ impl Database {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn room_id_for_project(
|
||||||
|
&self,
|
||||||
|
project_id: ProjectId,
|
||||||
|
tx: &DatabaseTransaction,
|
||||||
|
) -> Result<RoomId> {
|
||||||
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
|
||||||
|
enum QueryAs {
|
||||||
|
RoomId,
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(project::Entity::find_by_id(project_id)
|
||||||
|
.select_only()
|
||||||
|
.column(project::Column::RoomId)
|
||||||
|
.into_values::<_, QueryAs>()
|
||||||
|
.one(&*tx)
|
||||||
|
.await?
|
||||||
|
.ok_or_else(|| anyhow!("no such project"))?)
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn update_room_participant_location(
|
pub async fn update_room_participant_location(
|
||||||
&self,
|
&self,
|
||||||
room_id: RoomId,
|
room_id: RoomId,
|
||||||
|
|
|
@ -1719,7 +1719,6 @@ async fn follow(
|
||||||
response: Response<proto::Follow>,
|
response: Response<proto::Follow>,
|
||||||
session: Session,
|
session: Session,
|
||||||
) -> Result<()> {
|
) -> 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
|
||||||
|
@ -1751,7 +1750,7 @@ async fn follow(
|
||||||
let room = session
|
let room = session
|
||||||
.db()
|
.db()
|
||||||
.await
|
.await
|
||||||
.follow(room_id, project_id, leader_id, follower_id)
|
.follow(project_id, leader_id, follower_id)
|
||||||
.await?;
|
.await?;
|
||||||
room_updated(&room, &session.peer);
|
room_updated(&room, &session.peer);
|
||||||
|
|
||||||
|
@ -1759,7 +1758,6 @@ 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
|
||||||
|
@ -1784,7 +1782,7 @@ async fn unfollow(request: proto::Unfollow, session: Session) -> Result<()> {
|
||||||
let room = session
|
let room = session
|
||||||
.db()
|
.db()
|
||||||
.await
|
.await
|
||||||
.unfollow(room_id, project_id, leader_id, follower_id)
|
.unfollow(project_id, leader_id, follower_id)
|
||||||
.await?;
|
.await?;
|
||||||
room_updated(&room, &session.peer);
|
room_updated(&room, &session.peer);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue