Rename color_index to participant_index

Co-authored-by: Conrad <conrad@zed.dev>
This commit is contained in:
Max Brunsfeld 2023-09-28 11:18:29 -07:00
parent 545b5e0161
commit 0f39b63801
17 changed files with 97 additions and 80 deletions

View file

@ -152,7 +152,7 @@ impl Database {
room_id: ActiveValue::set(room_id),
user_id: ActiveValue::set(called_user_id),
answering_connection_lost: ActiveValue::set(false),
color_index: ActiveValue::NotSet,
participant_index: ActiveValue::NotSet,
calling_user_id: ActiveValue::set(calling_user_id),
calling_connection_id: ActiveValue::set(calling_connection.id as i32),
calling_connection_server_id: ActiveValue::set(Some(ServerId(
@ -285,19 +285,19 @@ impl Database {
.ok_or_else(|| anyhow!("no such room"))?;
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
enum QueryColorIndices {
ColorIndex,
enum QueryParticipantIndices {
ParticipantIndex,
}
let existing_color_indices: Vec<i32> = room_participant::Entity::find()
let existing_participant_indices: Vec<i32> = room_participant::Entity::find()
.filter(room_participant::Column::RoomId.eq(room_id))
.select_only()
.column(room_participant::Column::ColorIndex)
.into_values::<_, QueryColorIndices>()
.column(room_participant::Column::ParticipantIndex)
.into_values::<_, QueryParticipantIndices>()
.all(&*tx)
.await?;
let mut color_index = 0;
while existing_color_indices.contains(&color_index) {
color_index += 1;
let mut participant_index = 0;
while existing_participant_indices.contains(&participant_index) {
participant_index += 1;
}
if let Some(channel_id) = channel_id {
@ -317,7 +317,7 @@ impl Database {
calling_connection_server_id: ActiveValue::set(Some(ServerId(
connection.owner_id as i32,
))),
color_index: ActiveValue::Set(color_index),
participant_index: ActiveValue::Set(participant_index),
..Default::default()
}])
.on_conflict(
@ -340,7 +340,7 @@ impl Database {
.add(room_participant::Column::AnsweringConnectionId.is_null()),
)
.set(room_participant::ActiveModel {
color_index: ActiveValue::Set(color_index),
participant_index: ActiveValue::Set(participant_index),
answering_connection_id: ActiveValue::set(Some(connection.id as i32)),
answering_connection_server_id: ActiveValue::set(Some(ServerId(
connection.owner_id as i32,
@ -1090,7 +1090,7 @@ impl Database {
peer_id: Some(answering_connection.into()),
projects: Default::default(),
location: Some(proto::ParticipantLocation { variant: location }),
color_index: db_participant.color_index as u32,
participant_index: db_participant.participant_index as u32,
},
);
} else {

View file

@ -18,7 +18,7 @@ pub struct Model {
pub calling_user_id: UserId,
pub calling_connection_id: i32,
pub calling_connection_server_id: Option<ServerId>,
pub color_index: i32,
pub participant_index: i32,
}
impl Model {

View file

@ -4,6 +4,7 @@ use crate::{
};
use call::ActiveCall;
use channel::Channel;
use client::ParticipantIndex;
use client::{Collaborator, UserId};
use collab_ui::channel_view::ChannelView;
use collections::HashMap;
@ -13,7 +14,6 @@ use gpui::{executor::Deterministic, ModelHandle, TestAppContext, ViewContext};
use rpc::{proto::PeerId, RECEIVE_TIMEOUT};
use serde_json::json;
use std::{ops::Range, sync::Arc};
use theme::ColorIndex;
#[gpui::test]
async fn test_core_channel_buffers(
@ -122,7 +122,7 @@ async fn test_core_channel_buffers(
}
#[gpui::test]
async fn test_channel_notes_color_indices(
async fn test_channel_notes_participant_indices(
deterministic: Arc<Deterministic>,
mut cx_a: &mut TestAppContext,
mut cx_b: &mut TestAppContext,
@ -226,12 +226,20 @@ async fn test_channel_notes_color_indices(
deterministic.run_until_parked();
channel_view_a.update(cx_a, |notes, cx| {
notes.editor.update(cx, |editor, cx| {
assert_remote_selections(editor, &[(Some(ColorIndex(1)), 1..2), (None, 2..3)], cx);
assert_remote_selections(
editor,
&[(Some(ParticipantIndex(1)), 1..2), (None, 2..3)],
cx,
);
});
});
channel_view_b.update(cx_b, |notes, cx| {
notes.editor.update(cx, |editor, cx| {
assert_remote_selections(editor, &[(Some(ColorIndex(0)), 0..1), (None, 2..3)], cx);
assert_remote_selections(
editor,
&[(Some(ParticipantIndex(0)), 0..1), (None, 2..3)],
cx,
);
});
});
@ -275,17 +283,17 @@ async fn test_channel_notes_color_indices(
// Clients A and B see each other with the same colors as in the channel notes.
editor_a.update(cx_a, |editor, cx| {
assert_remote_selections(editor, &[(Some(ColorIndex(1)), 2..3)], cx);
assert_remote_selections(editor, &[(Some(ParticipantIndex(1)), 2..3)], cx);
});
editor_b.update(cx_b, |editor, cx| {
assert_remote_selections(editor, &[(Some(ColorIndex(0)), 0..1)], cx);
assert_remote_selections(editor, &[(Some(ParticipantIndex(0)), 0..1)], cx);
});
}
#[track_caller]
fn assert_remote_selections(
editor: &mut Editor,
expected_selections: &[(Option<ColorIndex>, Range<usize>)],
expected_selections: &[(Option<ParticipantIndex>, Range<usize>)],
cx: &mut ViewContext<Editor>,
) {
let snapshot = editor.snapshot(cx);
@ -295,7 +303,7 @@ fn assert_remote_selections(
.map(|s| {
let start = s.selection.start.to_offset(&snapshot.buffer_snapshot);
let end = s.selection.end.to_offset(&snapshot.buffer_snapshot);
(s.color_index, start..end)
(s.participant_index, start..end)
})
.collect::<Vec<_>>();
assert_eq!(