@@ -29,7 +29,7 @@ use yrs::{
2929
3030use crate :: entity:: { EncodedCollab , EncoderVersion } ;
3131use crate :: error:: CollabError ;
32- use crate :: preclude:: JsonValue ;
32+ use crate :: preclude:: { JsonValue , PermanentUserData } ;
3333use uuid:: Uuid ;
3434
3535pub const DATA_SECTION : & str = "data" ;
@@ -87,17 +87,25 @@ pub struct CollabContext {
8787 /// The current transaction that is being executed.
8888 current_txn : Option < TransactionMut < ' static > > ,
8989 version : Option < CollabVersion > ,
90+ /// Structure managing list of editors.
91+ editors : Option < PermanentUserData > ,
9092}
9193
9294unsafe impl Send for CollabContext { }
9395unsafe impl Sync for CollabContext { }
9496
9597impl CollabContext {
96- fn new ( origin : CollabOrigin , awareness : Awareness , version : Option < CollabVersion > ) -> Self {
98+ fn new (
99+ origin : CollabOrigin ,
100+ awareness : Awareness ,
101+ version : Option < CollabVersion > ,
102+ user_data : Option < PermanentUserData > ,
103+ ) -> Self {
97104 CollabContext {
98105 origin,
99106 awareness,
100107 version,
108+ editors : user_data,
101109 undo_manager : None ,
102110 current_txn : None ,
103111 }
@@ -111,6 +119,10 @@ impl CollabContext {
111119 & mut self . version
112120 }
113121
122+ pub fn user_data ( & self ) -> Option < & PermanentUserData > {
123+ self . editors . as_ref ( )
124+ }
125+
114126 pub fn with_txn < F , T > ( & mut self , f : F ) -> Result < T , CollabError >
115127 where
116128 F : FnOnce ( & mut TransactionMut ) -> T ,
@@ -304,6 +316,7 @@ pub struct CollabOptions {
304316 pub data_source : Option < DataSource > ,
305317 pub client_id : ClientID ,
306318 pub skip_gc : bool ,
319+ pub remember_user : bool ,
307320}
308321
309322impl Display for CollabOptions {
@@ -324,6 +337,7 @@ impl CollabOptions {
324337 data_source : None ,
325338 client_id,
326339 skip_gc : false ,
340+ remember_user : false ,
327341 }
328342 }
329343
@@ -332,6 +346,11 @@ impl CollabOptions {
332346 self
333347 }
334348
349+ pub fn with_remember_user ( mut self , remember_user : bool ) -> Self {
350+ self . remember_user = remember_user;
351+ self
352+ }
353+
335354 pub fn with_gc ( mut self , gc : bool ) -> Self {
336355 self . skip_gc = !gc;
337356 self
@@ -356,12 +375,18 @@ impl Collab {
356375 let plugins = Plugins :: new ( vec ! [ ] ) ;
357376 let state = Arc :: new ( State :: new ( & object_id. to_string ( ) ) ) ;
358377 let awareness = Awareness :: new ( doc) ;
378+ let user_data = if options. remember_user {
379+ Some ( PermanentUserData :: new ( awareness. doc ( ) , origin. clone ( ) ) )
380+ } else {
381+ None
382+ } ;
359383 let mut this = Self {
360384 object_id,
361385 context : CollabContext :: new (
362386 origin,
363387 awareness,
364388 options. data_source . as_ref ( ) . and_then ( DataSource :: version) ,
389+ user_data,
365390 ) ,
366391 state,
367392 data,
@@ -431,7 +456,7 @@ impl Collab {
431456 object_id,
432457 // if not the fact that we need origin here, it would be
433458 // not necessary either
434- context : CollabContext :: new ( origin, awareness, None ) ,
459+ context : CollabContext :: new ( origin, awareness, None , None ) ,
435460 state,
436461 data,
437462 meta,
0 commit comments