Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Do Not Wipe Bookmarks On Failure #16

Merged
merged 1 commit into from
Dec 6, 2024
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
36 changes: 17 additions & 19 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,29 +519,27 @@ impl Application for Cosmicding {
}
Message::BookmarksView(message) => commands.push(self.bookmarks_view.update(message)),
Message::StartRefreshBookmarksForAllAccounts => {
if !self.bookmarks_view.bookmarks.is_empty() {
let message = |x: Vec<DetailedResponse>| {
cosmic::app::Message::App(Message::DoneRefreshBookmarksForAllAccounts(x))
};
if !self.accounts_view.accounts.is_empty() {
commands.push(Task::perform(
http::fetch_bookmarks_from_all_accounts(
self.accounts_view.accounts.clone(),
),
message,
));
commands.push(
self.toasts
.push(widget::toaster::Toast::new(fl!("refreshed-bookmarks")))
.map(cosmic::app::Message::App),
);
}
let message = |x: Vec<DetailedResponse>| {
cosmic::app::Message::App(Message::DoneRefreshBookmarksForAllAccounts(x))
};
if !self.accounts_view.accounts.is_empty() {
commands.push(Task::perform(
http::fetch_bookmarks_from_all_accounts(
self.accounts_view.accounts.clone(),
),
message,
));
commands.push(
self.toasts
.push(widget::toaster::Toast::new(fl!("refreshed-bookmarks")))
.map(cosmic::app::Message::App),
);
}
}
Message::DoneRefreshBookmarksForAllAccounts(remote_responses) => {
for response in remote_responses {
block_on(async {
db::SqliteDatabase::cache_bookmarks_for_acount(
db::SqliteDatabase::aggregate_bookmarks_for_acount(
&mut self.db,
&response.account,
response.bookmarks.unwrap_or_else(Vec::new),
Expand Down Expand Up @@ -583,7 +581,7 @@ impl Application for Cosmicding {
Message::DoneRefreshBookmarksForAccount(account, remote_responses) => {
for response in remote_responses {
block_on(async {
db::SqliteDatabase::cache_bookmarks_for_acount(
db::SqliteDatabase::aggregate_bookmarks_for_acount(
&mut self.db,
&account,
response.bookmarks.unwrap_or_else(Vec::new),
Expand Down
14 changes: 7 additions & 7 deletions src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl SqliteDatabase {
// .await
// .unwrap();
//}
pub async fn cache_bookmarks_for_acount(
pub async fn aggregate_bookmarks_for_acount(
&mut self,
account: &Account,
bookmarks: Vec<Bookmark>,
Expand All @@ -145,12 +145,12 @@ impl SqliteDatabase {
let delete_query: &str = "DELETE FROM Bookmarks where user_account_id = $1;";
let update_timestamp_query =
"UPDATE UserAccounts SET last_sync_status=$2, last_sync_timestamp=$3 WHERE id=$1";
sqlx::query(delete_query)
.bind(account.id)
.execute(&mut self.conn)
.await
.unwrap();
if !bookmarks.is_empty() {
if response_successful {
sqlx::query(delete_query)
.bind(account.id)
.execute(&mut self.conn)
.await
.unwrap();
for bookmark in bookmarks {
self.add_bookmark(&bookmark).await;
}
Expand Down
Loading