Skip to content

Commit

Permalink
fix: current view should be updated on a per user basis instead of wo…
Browse files Browse the repository at this point in the history
…rkspace
  • Loading branch information
khorshuheng committed Jan 28, 2025
1 parent 98463cc commit 1fa7b49
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions collab-folder/src/folder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ impl AsRef<str> for UserId {
const VIEWS: &str = "views";
const PARENT_CHILD_VIEW_RELATION: &str = "relation";
const CURRENT_VIEW: &str = "current_view";
const CURRENT_VIEW_FOR_USER: &str = "current_view_for_user";

pub(crate) const FAVORITES_V1: &str = "favorites";
const SECTION: &str = "section";
Expand Down Expand Up @@ -546,7 +547,10 @@ impl FolderBody {
}

meta.insert(&mut txn, FOLDER_WORKSPACE_ID, workspace_id);
meta.insert(&mut txn, CURRENT_VIEW, folder_data.current_view);
// For compatibility with older collab which doesn't have CURRENT_VIEW_FOR_USER.
meta.insert(&mut txn, CURRENT_VIEW, folder_data.current_view.clone());
let current_view_for_user = meta.get_or_init_map(&mut txn, CURRENT_VIEW_FOR_USER);
current_view_for_user.insert(&mut txn, uid.as_ref(), folder_data.current_view.clone());

if let Some(fav_section) = section.section_op(&txn, Section::Favorite) {
for (uid, sections) in folder_data.favorites {
Expand Down Expand Up @@ -733,11 +737,19 @@ impl FolderBody {
}

pub fn get_current_view<T: ReadTxn>(&self, txn: &T) -> Option<String> {
self.meta.get_with_txn(txn, CURRENT_VIEW)
let current_view_for_user = self.meta.get(txn, CURRENT_VIEW_FOR_USER);
if let Some(YrsValue::YMap(current_view_for_user)) = current_view_for_user {
current_view_for_user.get_with_txn(txn, self.uid.as_ref())
} else {
// Use CURRENT_VIEW as fallback, for compatibility with older collab which
// doesn't have CURRENT_VIEW_FOR_USER.
self.meta.get_with_txn(txn, CURRENT_VIEW)
}
}

pub fn set_current_view(&self, txn: &mut TransactionMut, view: String) {
self.meta.try_update(txn, CURRENT_VIEW, view);
let current_view_for_user = self.meta.get_or_init_map(txn, CURRENT_VIEW_FOR_USER);
current_view_for_user.try_update(txn, self.uid.0.clone(), view);
}
}

Expand Down

0 comments on commit 1fa7b49

Please sign in to comment.