Skip to content

Commit fa83ec5

Browse files
authored
Revert "chore: return update when open folder (#439)" (#440)
This reverts commit b20ee27.
1 parent b20ee27 commit fa83ec5

File tree

2 files changed

+17
-71
lines changed

2 files changed

+17
-71
lines changed

collab/src/folder/folder.rs

Lines changed: 16 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -92,73 +92,36 @@ pub struct Folder {
9292
pub body: FolderBody,
9393
}
9494

95-
/// Result of opening a folder, including any migration update produced while initializing.
96-
pub struct FolderOpenResult {
97-
pub folder: Folder,
98-
/// Encoded Yrs update v1 representing changes made during initialization (if any).
99-
pub update: Option<Vec<u8>>,
100-
}
101-
102-
pub struct FolderBodyOpenResult {
103-
pub body: FolderBody,
104-
pub update: Option<Vec<u8>>,
105-
}
106-
10795
impl Folder {
108-
pub fn open(collab: Collab, notifier: Option<FolderNotify>) -> Result<Self, CollabError> {
109-
Self::open_with_update(collab, notifier).map(|result| result.folder)
110-
}
111-
112-
pub fn open_with_update(
113-
mut collab: Collab,
114-
notifier: Option<FolderNotify>,
115-
) -> Result<FolderOpenResult, CollabError> {
116-
let open_result = FolderBody::open(&mut collab, notifier)?;
117-
let folder = Folder {
118-
collab,
119-
body: open_result.body,
120-
};
96+
pub fn open(mut collab: Collab, notifier: Option<FolderNotify>) -> Result<Self, CollabError> {
97+
let body = FolderBody::open(&mut collab, notifier)?;
98+
let folder = Folder { collab, body };
12199
if folder.get_workspace_id().is_none() {
122100
// When the folder is opened, the workspace id must be present.
123101
Err(CollabError::FolderMissingRequiredData(
124102
"missing workspace id".into(),
125103
))
126104
} else {
127-
Ok(FolderOpenResult {
128-
folder,
129-
update: open_result.update,
130-
})
105+
Ok(folder)
131106
}
132107
}
133108

134109
pub fn create(mut collab: Collab, notifier: Option<FolderNotify>, data: FolderData) -> Self {
135-
let result = FolderBody::open_with(&mut collab, notifier, Some(data));
136-
Folder {
137-
collab,
138-
body: result.body,
139-
}
110+
let body = FolderBody::open_with(&mut collab, notifier, Some(data));
111+
Folder { collab, body }
140112
}
141113

142114
pub fn from_collab_doc_state(
143115
origin: CollabOrigin,
144116
collab_doc_state: DataSource,
145117
workspace_id: &str,
146118
client_id: ClientID,
147-
) -> Result<FolderOpenResult, CollabError> {
148-
Self::from_collab_doc_state_with_update(origin, collab_doc_state, workspace_id, client_id)
149-
}
150-
151-
pub fn from_collab_doc_state_with_update(
152-
origin: CollabOrigin,
153-
collab_doc_state: DataSource,
154-
workspace_id: &str,
155-
client_id: ClientID,
156-
) -> Result<FolderOpenResult, CollabError> {
119+
) -> Result<Self, CollabError> {
157120
let workspace_uuid = Uuid::parse_str(workspace_id)
158121
.map_err(|_| CollabError::Internal(anyhow!("Invalid workspace id format")))?;
159122
let options = CollabOptions::new(workspace_uuid, client_id).with_data_source(collab_doc_state);
160123
let collab = Collab::new_with_options(origin, options)?;
161-
Self::open_with_update(collab, None)
124+
Self::open(collab, None)
162125
}
163126

164127
pub fn close(&self) {
@@ -1253,10 +1216,7 @@ pub struct FolderBody {
12531216
}
12541217

12551218
impl FolderBody {
1256-
pub fn open(
1257-
collab: &mut Collab,
1258-
notifier: Option<FolderNotify>,
1259-
) -> Result<FolderBodyOpenResult, CollabError> {
1219+
pub fn open(collab: &mut Collab, notifier: Option<FolderNotify>) -> Result<Self, CollabError> {
12601220
CollabType::Folder.validate_require_data(collab)?;
12611221
Ok(Self::open_with(collab, notifier, None))
12621222
}
@@ -1265,8 +1225,7 @@ impl FolderBody {
12651225
collab: &mut Collab,
12661226
notifier: Option<FolderNotify>,
12671227
folder_data: Option<FolderData>,
1268-
) -> FolderBodyOpenResult {
1269-
let sv = collab.transact().state_vector();
1228+
) -> Self {
12701229
let mut txn = collab.context.transact_mut();
12711230
// create the folder
12721231
let root = collab.data.get_or_init_map(&mut txn, FOLDER);
@@ -1333,23 +1292,12 @@ impl FolderBody {
13331292
}
13341293
}
13351294
}
1336-
let update = {
1337-
let encoded = txn.encode_diff_v1(&sv);
1338-
if encoded.is_empty() {
1339-
None
1340-
} else {
1341-
Some(encoded)
1342-
}
1343-
};
1344-
FolderBodyOpenResult {
1345-
body: Self {
1346-
root,
1347-
views,
1348-
section,
1349-
meta,
1350-
notifier,
1351-
},
1352-
update,
1295+
Self {
1296+
root,
1297+
views,
1298+
section,
1299+
meta,
1300+
notifier,
13531301
}
13541302
}
13551303

@@ -1684,7 +1632,6 @@ mod tests {
16841632

16851633
use crate::core::collab::default_client_id;
16861634
use crate::core::{collab::CollabOptions, origin::CollabOrigin};
1687-
16881635
use crate::folder::{
16891636
Folder, FolderData, RepeatedViewIdentifier, SectionItem, SpaceInfo, UserId, View,
16901637
ViewIdentifier, ViewLayout, Workspace,

collab/src/folder/folder_diff.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ impl Folder {
3232
encoded_collab.into(),
3333
&workspace_id,
3434
client_id,
35-
)?
36-
.folder;
35+
)?;
3736
let cloned_container = other.body.views.container.clone();
3837
let sub = {
3938
let changes = changes.clone();

0 commit comments

Comments
 (0)