Skip to content

Commit 323cc95

Browse files
authored
hotfix: update presage fixing connection to Signal servers (#350)
See <whisperfish/presage#300>. Also the contact sync is disabled for now: <#349>.
1 parent ecf8a94 commit 323cc95

File tree

8 files changed

+58
-99
lines changed

8 files changed

+58
-99
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ debug = true
2828
dev = ["prost", "base64"]
2929

3030
[dependencies]
31-
presage = { git = "https://github.com/whisperfish/presage", rev = "8b9af8ee4758c73550024bea8c715a893e9e4e47" }
32-
presage-store-sled = { git = "https://github.com/whisperfish/presage", rev = "8b9af8ee4758c73550024bea8c715a893e9e4e47" }
31+
presage = { git = "https://github.com/whisperfish/presage", rev = "35c2c98ba782fb212ad6cd3356fd4807e5d5a8eb" }
32+
presage-store-sled = { git = "https://github.com/whisperfish/presage", rev = "35c2c98ba782fb212ad6cd3356fd4807e5d5a8eb" }
3333

3434
# dev feature dependencies
3535
prost = { version = "0.13.4", optional = true }

benches/app.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub fn bench_on_message(c: &mut Criterion) {
3636
|| (test_app(), data.clone()),
3737
|(mut app, data)| async move {
3838
for content in data {
39-
app.on_message(content).await.unwrap();
39+
app.on_message(Box::new(content)).await.unwrap();
4040
}
4141
},
4242
BatchSize::SmallInput,

src/app.rs

Lines changed: 23 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,14 @@
1-
use crate::channels::SelectChannel;
2-
use crate::command::{
3-
get_keybindings, Command, DirectionVertical, ModeKeybinding, MoveAmountText, MoveAmountVisual,
4-
MoveDirection, Widget, WindowMode,
5-
};
6-
use crate::config::Config;
7-
use crate::data::{BodyRange, Channel, ChannelId, Message, TypingAction, TypingSet};
8-
use crate::event::Event;
9-
use crate::input::Input;
10-
use crate::receipt::{Receipt, ReceiptEvent, ReceiptHandler};
11-
use crate::signal::{
12-
Attachment, GroupIdentifierBytes, GroupMasterKeyBytes, ProfileKeyBytes, ResolvedGroup,
13-
SignalManager,
14-
};
15-
use crate::storage::{MessageId, Storage};
16-
use crate::util::{self, LazyRegex, StatefulList, ATTACHMENT_REGEX, URL_REGEX};
1+
use std::borrow::Cow;
172
use std::cell::Cell;
3+
use std::cmp::Reverse;
4+
use std::collections::BTreeMap;
5+
use std::convert::TryInto;
6+
use std::future::Future;
187
use std::io::Cursor;
8+
use std::path::Path;
199

2010
use anyhow::{anyhow, Context as _};
2111
use arboard::Clipboard;
22-
use chrono::{DateTime, Utc};
2312
use crokey::Combiner;
2413
use crossterm::event::{KeyCode, KeyEvent};
2514
use image::codecs::png::PngEncoder;
@@ -39,17 +28,22 @@ use tokio::sync::mpsc;
3928
use tracing::{debug, error, info, warn};
4029
use uuid::Uuid;
4130

42-
use std::borrow::Cow;
43-
use std::cmp::Reverse;
44-
use std::collections::BTreeMap;
45-
use std::convert::TryInto;
46-
use std::future::Future;
47-
use std::path::Path;
48-
use std::time::Duration;
49-
50-
/// Amount of time to skip contacts sync after the last sync
51-
const CONTACTS_SYNC_DEADLINE_SEC: i64 = 60 * 60 * 24; // 1 day
52-
const CONTACTS_SYNC_TIMEOUT: Duration = Duration::from_secs(20);
31+
use crate::channels::SelectChannel;
32+
use crate::command::{
33+
get_keybindings, Command, DirectionVertical, ModeKeybinding, MoveAmountText, MoveAmountVisual,
34+
MoveDirection, Widget, WindowMode,
35+
};
36+
use crate::config::Config;
37+
use crate::data::{BodyRange, Channel, ChannelId, Message, TypingAction, TypingSet};
38+
use crate::event::Event;
39+
use crate::input::Input;
40+
use crate::receipt::{Receipt, ReceiptEvent, ReceiptHandler};
41+
use crate::signal::{
42+
Attachment, GroupIdentifierBytes, GroupMasterKeyBytes, ProfileKeyBytes, ResolvedGroup,
43+
SignalManager,
44+
};
45+
use crate::storage::{MessageId, Storage};
46+
use crate::util::{self, LazyRegex, StatefulList, ATTACHMENT_REGEX, URL_REGEX};
5347

5448
pub struct App {
5549
pub config: Config,
@@ -582,7 +576,7 @@ impl App {
582576
}
583577
}
584578

585-
pub async fn on_message(&mut self, content: Content) -> anyhow::Result<()> {
579+
pub async fn on_message(&mut self, content: Box<Content>) -> anyhow::Result<()> {
586580
// tracing::info!(?content, "incoming");
587581

588582
#[cfg(feature = "dev")]
@@ -1487,27 +1481,6 @@ impl App {
14871481
self.display_help
14881482
}
14891483

1490-
pub fn request_contacts_sync(
1491-
&self,
1492-
) -> Option<impl Future<Output = anyhow::Result<DateTime<Utc>>> + 'static> {
1493-
let now = Utc::now();
1494-
let metadata = self.storage.metadata();
1495-
let do_sync = metadata
1496-
.contacts_sync_request_at
1497-
.map(|dt| dt + chrono::Duration::seconds(CONTACTS_SYNC_DEADLINE_SEC) < now)
1498-
.unwrap_or(true);
1499-
let signal_manager = self.signal_manager.clone_boxed();
1500-
do_sync.then_some(async move {
1501-
info!(timeout =? CONTACTS_SYNC_TIMEOUT, "requesting contact sync");
1502-
tokio::time::timeout(
1503-
CONTACTS_SYNC_TIMEOUT,
1504-
signal_manager.request_contacts_sync(),
1505-
)
1506-
.await??;
1507-
Ok(Utc::now())
1508-
})
1509-
}
1510-
15111484
pub fn is_select_channel_shown(&self) -> bool {
15121485
self.select_channel.is_shown
15131486
}

src/main.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pub enum Event {
8080
Click(MouseEvent),
8181
Input(KeyEvent),
8282
Paste(String),
83-
Message(Content),
83+
Message(Box<Content>),
8484
Resize { cols: u16, rows: u16 },
8585
Quit(Option<anyhow::Error>),
8686
ContactSynced(DateTime<Utc>),
@@ -136,10 +136,6 @@ async fn run_single_threaded(relink: bool) -> anyhow::Result<()> {
136136
let (mut app, mut app_events) = App::try_new(config, signal_manager.clone_boxed(), storage)?;
137137
app.populate_names_cache().await;
138138

139-
// sync task can be only spawned after we start to listen to message, because it relies on
140-
// message sender to be running
141-
let mut contact_sync_task = app.request_contacts_sync();
142-
143139
let (tx, mut rx) = tokio::sync::mpsc::channel::<Event>(100);
144140
tokio::spawn({
145141
let tx = tx.clone();
@@ -186,21 +182,6 @@ async fn run_single_threaded(relink: bool) -> anyhow::Result<()> {
186182
}
187183
};
188184

189-
if let Some(task) = contact_sync_task.take() {
190-
let inner_tx = inner_tx.clone();
191-
tokio::task::spawn_local(async move {
192-
match task.await {
193-
Ok(at) => inner_tx
194-
.send(Event::ContactSynced(at))
195-
.await
196-
.expect("logic error: events channel closed"),
197-
Err(error) => {
198-
error!(%error, "failed to sync contacts");
199-
}
200-
}
201-
});
202-
}
203-
204185
while let Some(message) = messages.next().await {
205186
backoff.reset();
206187
inner_tx

src/signal/impl.rs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,23 @@ use std::pin::Pin;
44

55
use anyhow::Context;
66
use async_trait::async_trait;
7-
use presage::libsignal_service::content::{Content, ContentBody};
87
use presage::libsignal_service::prelude::ProfileKey;
98
use presage::libsignal_service::protocol::ServiceId;
109
use presage::libsignal_service::sender::AttachmentSpec;
11-
use presage::manager::{ReceivingMode, Registered};
10+
use presage::manager::Registered;
1211
use presage::model::contacts::Contact;
1312
use presage::model::groups::Group;
1413
use presage::proto::data_message::{Quote, Reaction};
1514
use presage::proto::{AttachmentPointer, DataMessage, EditMessage, GroupContextV2, ReceiptMessage};
1615
use presage::store::ContentsStore;
16+
use presage::{
17+
libsignal_service::content::{Content, ContentBody},
18+
model::messages::Received,
19+
};
1720
use presage_store_sled::SledStore;
1821
use tokio::sync::oneshot;
19-
use tokio_stream::Stream;
20-
use tracing::error;
22+
use tokio_stream::{Stream, StreamExt};
23+
use tracing::{error, warn};
2124
use uuid::Uuid;
2225

2326
use crate::data::{Channel, ChannelId, GroupData, Message};
@@ -322,10 +325,6 @@ impl SignalManager for PresageManager {
322325
}
323326
}
324327

325-
async fn request_contacts_sync(&self) -> anyhow::Result<()> {
326-
Ok(self.manager.clone().sync_contacts().await?)
327-
}
328-
329328
async fn profile_name(&self, id: Uuid) -> Option<String> {
330329
let profile_key = self.manager.store().profile_key(&id).await.ok()??;
331330
let profile = self.manager.store().profile(id, profile_key).await.ok()??;
@@ -341,12 +340,20 @@ impl SignalManager for PresageManager {
341340
self.manager.store().contact_by_id(&id).await.ok()?
342341
}
343342

344-
async fn receive_messages(&mut self) -> anyhow::Result<Pin<Box<dyn Stream<Item = Content>>>> {
345-
Ok(Box::pin(
346-
self.manager
347-
.receive_messages(ReceivingMode::Forever)
348-
.await?,
349-
))
343+
async fn receive_messages(
344+
&mut self,
345+
) -> anyhow::Result<Pin<Box<dyn Stream<Item = Box<Content>>>>> {
346+
Ok(Box::pin(self.manager.receive_messages().await?.filter_map(
347+
|received| match received {
348+
Received::Content(content) => Some(content),
349+
Received::QueueEmpty => None,
350+
Received::Contacts => {
351+
// TODO: <https://github.com/boxdot/gurk-rs/issues/349>
352+
warn!("Received contacts, but not implemented yet");
353+
None
354+
}
355+
},
356+
)))
350357
}
351358

352359
async fn contacts(&self) -> Box<dyn Iterator<Item = Contact>> {

src/signal/manager.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ pub trait SignalManager {
5858
profile_key: ProfileKeyBytes,
5959
) -> Option<String>;
6060

61-
async fn request_contacts_sync(&self) -> anyhow::Result<()>;
62-
6361
async fn contact(&self, id: Uuid) -> Option<Contact>;
6462

65-
async fn receive_messages(&mut self) -> anyhow::Result<Pin<Box<dyn Stream<Item = Content>>>>;
63+
async fn receive_messages(
64+
&mut self,
65+
) -> anyhow::Result<Pin<Box<dyn Stream<Item = Box<Content>>>>>;
6666

6767
async fn contacts(&self) -> Box<dyn Iterator<Item = Contact>>;
6868
async fn groups(&self) -> Box<dyn Iterator<Item = (GroupMasterKeyBytes, Group)>>;

src/signal/test.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,6 @@ impl SignalManager for SignalManagerMock {
126126
None
127127
}
128128

129-
async fn request_contacts_sync(&self) -> anyhow::Result<()> {
130-
Ok(())
131-
}
132-
133129
async fn profile_name(&self, _id: Uuid) -> Option<String> {
134130
None
135131
}
@@ -138,7 +134,9 @@ impl SignalManager for SignalManagerMock {
138134
None
139135
}
140136

141-
async fn receive_messages(&mut self) -> anyhow::Result<Pin<Box<dyn Stream<Item = Content>>>> {
137+
async fn receive_messages(
138+
&mut self,
139+
) -> anyhow::Result<Pin<Box<dyn Stream<Item = Box<Content>>>>> {
142140
Ok(Box::pin(tokio_stream::empty()))
143141
}
144142

0 commit comments

Comments
 (0)