|
1 | 1 | pub use crate::entities::view::ViewDataTypePB; |
2 | | -use crate::entities::{ViewInfoPB, ViewLayoutTypePB}; |
| 2 | +use crate::entities::{DeletedViewPB, ViewInfoPB, ViewLayoutTypePB}; |
3 | 3 | use crate::manager::{ViewDataProcessor, ViewDataProcessorMap}; |
4 | 4 | use crate::{ |
5 | 5 | dart_notification::{send_dart_notification, FolderNotification}, |
@@ -122,20 +122,19 @@ impl ViewController { |
122 | 122 | .await |
123 | 123 | } |
124 | 124 |
|
125 | | - #[tracing::instrument(level = "debug", skip(self, view_id), fields(view_id = %view_id.value), err)] |
126 | | - pub(crate) async fn read_view(&self, view_id: ViewIdPB) -> Result<ViewRevision, FlowyError> { |
| 125 | + #[tracing::instrument(level = "debug", skip(self, view_id), err)] |
| 126 | + pub(crate) async fn read_view(&self, view_id: &str) -> Result<ViewRevision, FlowyError> { |
127 | 127 | let view_rev = self |
128 | 128 | .persistence |
129 | 129 | .begin_transaction(|transaction| { |
130 | | - let view = transaction.read_view(&view_id.value)?; |
| 130 | + let view = transaction.read_view(view_id)?; |
131 | 131 | let trash_ids = self.trash_controller.read_trash_ids(&transaction)?; |
132 | 132 | if trash_ids.contains(&view.id) { |
133 | 133 | return Err(FlowyError::record_not_found()); |
134 | 134 | } |
135 | 135 | Ok(view) |
136 | 136 | }) |
137 | 137 | .await?; |
138 | | - let _ = self.read_view_on_server(view_id); |
139 | 138 | Ok(view_rev) |
140 | 139 | } |
141 | 140 |
|
@@ -201,9 +200,26 @@ impl ViewController { |
201 | 200 | let _ = KV::remove(LATEST_VIEW_ID); |
202 | 201 | } |
203 | 202 | } |
204 | | - let view_id_pb = ViewIdPB::from(view_id.as_str()); |
| 203 | + |
| 204 | + let deleted_view = self |
| 205 | + .persistence |
| 206 | + .begin_transaction(|transaction| { |
| 207 | + let view = transaction.read_view(&view_id)?; |
| 208 | + let views = read_belonging_views_on_local(&view.app_id, self.trash_controller.clone(), &transaction)?; |
| 209 | + |
| 210 | + let index = views |
| 211 | + .iter() |
| 212 | + .position(|view| view.id == view_id) |
| 213 | + .and_then(|index| Some(index as i32)); |
| 214 | + Ok(DeletedViewPB { |
| 215 | + view_id: view_id.clone(), |
| 216 | + index, |
| 217 | + }) |
| 218 | + }) |
| 219 | + .await?; |
| 220 | + |
205 | 221 | send_dart_notification(&view_id, FolderNotification::ViewMoveToTrash) |
206 | | - .payload(view_id_pb) |
| 222 | + .payload(deleted_view) |
207 | 223 | .send(); |
208 | 224 |
|
209 | 225 | let processor = self.get_data_processor_from_view_id(&view_id).await?; |
|
0 commit comments