Skip to content

Commit

Permalink
Rename message variants
Browse files Browse the repository at this point in the history
  • Loading branch information
sandreae committed Dec 29, 2024
1 parent eae8121 commit 1e97281
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
6 changes: 3 additions & 3 deletions aardvark-app/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@ impl AardvarkApplication {
glib::spawn_future_local(async move {
while let Some(message) = rx.recv().await {
match message {
ToApp::NewDocument(text_document) => {
ToApp::SubscriptionSuccess(text_document) => {
// @TODO: get the short code for this document into the share UI
// component.
println!("new document: {}", text_document.hash())
}
ToApp::Message(bytes) => application.ingest_message(bytes),
ToApp::MessageReceived(bytes) => application.ingest_message(bytes),
}
}
});
Expand Down Expand Up @@ -227,7 +227,7 @@ impl AardvarkApplication {
let bytes = self.imp().document.save_incremental();
let tx = self.imp().tx.clone();
glib::spawn_future_local(async move {
tx.send(FromApp::Message(bytes))
tx.send(FromApp::HandleMessage(bytes))
.await
.expect("sending message to networking backend");
});
Expand Down
4 changes: 2 additions & 2 deletions aardvark-app/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ mod imp {
let window = self.obj().clone();
let dialog = self.open_document_dialog.clone();
self.open_document_button.connect_clicked(move |_| {
// @TODO: Send `FromApp::Subscribe` message to network containing the share code
// and wait for the document to be joined.
// @TODO: Send `FromApp::SubscribeToDocument` message to network containing the
// share code and wait for the document to be joined.
dialog.present(Some(&window));
});
}
Expand Down
26 changes: 13 additions & 13 deletions aardvark-node/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ use crate::operation::{
use crate::topics::{AardvarkTopics, DiscoveryCode, TextDocument};

pub enum FromApp {
Subscribe(ShortCode),
Message(Vec<u8>),
SubscribeToDocument(ShortCode),
HandleMessage(Vec<u8>),
}

pub enum ToApp {
NewDocument(TextDocument),
Message(Vec<u8>),
SubscriptionSuccess(TextDocument),
MessageReceived(Vec<u8>),
}

pub fn run() -> Result<(
Expand Down Expand Up @@ -112,7 +112,7 @@ pub fn run() -> Result<(
.expect("node can announce document");

to_app_tx
.send(ToApp::NewDocument(document.clone()))
.send(ToApp::SubscriptionSuccess(document.clone()))
.await
.expect("can send on app channel");

Expand Down Expand Up @@ -168,7 +168,7 @@ impl Node {
tokio::task::spawn(async move {
while let Some(message) = from_app.recv().await {
match message {
FromApp::Subscribe(short_code) => {
FromApp::SubscribeToDocument(short_code) => {
let document = match self.discovered_documents.get(&short_code) {
Some(document) => document.clone(),
None => {
Expand All @@ -179,10 +179,10 @@ impl Node {
};
self.subscribe(&document).await?;
self.to_app_tx
.send(ToApp::NewDocument(document.clone()))
.send(ToApp::SubscriptionSuccess(document.clone()))
.await?;
}
FromApp::Message(bytes) => self.handle_application_bytes(bytes).await?,
FromApp::HandleMessage(bytes) => self.handle_application_bytes(bytes).await?,
}
}

Expand Down Expand Up @@ -392,7 +392,7 @@ impl Node {
// Forward the payload up to the app.
if let Some(body) = operation.body {
to_app_tx
.send(ToApp::Message(body.to_bytes()))
.send(ToApp::MessageReceived(body.to_bytes()))
.await?;
}
}
Expand Down Expand Up @@ -538,22 +538,22 @@ mod tests {
node_b.run(from_app_rx_b).await;

from_app_tx_b
.send(FromApp::Subscribe(document_a.short_code()))
.send(FromApp::SubscribeToDocument(document_a.short_code()))
.await
.unwrap();

let ToApp::NewDocument(document_a_again) = to_app_rx_b.recv().await.unwrap() else {
let ToApp::SubscriptionSuccess(document_a_again) = to_app_rx_b.recv().await.unwrap() else {
panic!("expected new document enum variant")
};

assert_eq!(document_a, document_a_again);

from_app_tx_a
.send(FromApp::Message(vec![0, 1, 2, 3]))
.send(FromApp::HandleMessage(vec![0, 1, 2, 3]))
.await
.unwrap();

let ToApp::Message(bytes) = to_app_rx_b.recv().await.unwrap() else {
let ToApp::MessageReceived(bytes) = to_app_rx_b.recv().await.unwrap() else {
panic!("expected message enum variant")
};

Expand Down

0 comments on commit 1e97281

Please sign in to comment.