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 blocking contacts sync #216

Merged
merged 3 commits into from
Mar 20, 2023
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
### Fixed

- Do not create log file when logging is disabled ([#204])
- Fix blocking contacts sync ([#216])

[#203]: https://github.com/boxdot/gurk-rs/pull/203
[#204]: https://github.com/boxdot/gurk-rs/pull/204
[#210]: https://github.com/boxdot/gurk-rs/pull/210
[#136]: https://github.com/boxdot/gurk-rs/pull/136
[#215]: https://github.com/boxdot/gurk-rs/pull/215
[#216]: https://github.com/boxdot/gurk-rs/pull/216

## 0.3.0

Expand Down
12 changes: 9 additions & 3 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::util::{self, LazyRegex, StatefulList, ATTACHMENT_REGEX, URL_REGEX};

use anyhow::{anyhow, bail, Context as _};
use arboard::Clipboard;
use chrono::{Duration, Utc};
use chrono::Utc;
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use itertools::Itertools;
use notify_rust::Notification;
Expand All @@ -35,9 +35,11 @@ use std::cmp::Reverse;
use std::collections::BTreeMap;
use std::convert::TryInto;
use std::path::Path;
use std::time::Duration;

/// Amount of time to skip contacts sync after the last sync
const CONTACTS_SYNC_DEADLINE_SEC: i64 = 60 * 60; // 1h
const CONTACTS_SYNC_TIMEOUT: Duration = Duration::from_secs(10);

pub struct App {
pub config: Config,
Expand Down Expand Up @@ -1285,11 +1287,15 @@ impl App {
let metadata = self.storage.metadata();
let do_sync = metadata
.contacts_sync_request_at
.map(|dt| dt + Duration::seconds(CONTACTS_SYNC_DEADLINE_SEC) < now)
.map(|dt| dt + chrono::Duration::seconds(CONTACTS_SYNC_DEADLINE_SEC) < now)
.unwrap_or(true);
if do_sync {
info!("requesting contact sync");
self.signal_manager.request_contacts_sync().await?;
tokio::time::timeout(
CONTACTS_SYNC_TIMEOUT,
self.signal_manager.request_contacts_sync(),
)
.await??;
let mut metadata = metadata.into_owned();
metadata.contacts_sync_request_at = Some(now);
self.storage.store_metadata(metadata);
Expand Down