Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ members = ["collab"]
resolver = "2"

[workspace.dependencies]
yrs = { version = "0.24", features = ["sync"] }
yrs = { version = "0.25", features = ["sync"] }
anyhow = "1.0.94"
thiserror = "1.0.39"
serde = { version = "1.0.157", features = ["derive"] }
Expand Down
31 changes: 28 additions & 3 deletions collab/src/core/collab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use yrs::{

use crate::entity::{EncodedCollab, EncoderVersion};
use crate::error::CollabError;
use crate::preclude::JsonValue;
use crate::preclude::{JsonValue, PermanentUserData};
use uuid::Uuid;

pub const DATA_SECTION: &str = "data";
Expand Down Expand Up @@ -87,17 +87,25 @@ pub struct CollabContext {
/// The current transaction that is being executed.
current_txn: Option<TransactionMut<'static>>,
version: Option<CollabVersion>,
/// Structure managing list of editors.
editors: Option<PermanentUserData>,
}

unsafe impl Send for CollabContext {}
unsafe impl Sync for CollabContext {}

impl CollabContext {
fn new(origin: CollabOrigin, awareness: Awareness, version: Option<CollabVersion>) -> Self {
fn new(
origin: CollabOrigin,
awareness: Awareness,
version: Option<CollabVersion>,
user_data: Option<PermanentUserData>,
) -> Self {
CollabContext {
origin,
awareness,
version,
editors: user_data,
undo_manager: None,
current_txn: None,
}
Expand All @@ -111,6 +119,10 @@ impl CollabContext {
&mut self.version
}

pub fn user_data(&self) -> Option<&PermanentUserData> {
self.editors.as_ref()
}

pub fn with_txn<F, T>(&mut self, f: F) -> Result<T, CollabError>
where
F: FnOnce(&mut TransactionMut) -> T,
Expand Down Expand Up @@ -304,6 +316,7 @@ pub struct CollabOptions {
pub data_source: Option<DataSource>,
pub client_id: ClientID,
pub skip_gc: bool,
pub remember_user: bool,
}

impl Display for CollabOptions {
Expand All @@ -324,6 +337,7 @@ impl CollabOptions {
data_source: None,
client_id,
skip_gc: false,
remember_user: false,
}
}

Expand All @@ -332,6 +346,11 @@ impl CollabOptions {
self
}

pub fn with_remember_user(mut self, remember_user: bool) -> Self {
self.remember_user = remember_user;
self
}

pub fn with_gc(mut self, gc: bool) -> Self {
self.skip_gc = !gc;
self
Expand All @@ -356,12 +375,18 @@ impl Collab {
let plugins = Plugins::new(vec![]);
let state = Arc::new(State::new(&object_id.to_string()));
let awareness = Awareness::new(doc);
let user_data = if options.remember_user {
Some(PermanentUserData::new(awareness.doc(), origin.clone()))
} else {
None
};
let mut this = Self {
object_id,
context: CollabContext::new(
origin,
awareness,
options.data_source.as_ref().and_then(DataSource::version),
user_data,
),
state,
data,
Expand Down Expand Up @@ -431,7 +456,7 @@ impl Collab {
object_id,
// if not the fact that we need origin here, it would be
// not necessary either
context: CollabContext::new(origin, awareness, None),
context: CollabContext::new(origin, awareness, None, None),
state,
data,
meta,
Expand Down
Loading
Loading