Skip to content

An open-source cross-platform alternative to AirDrop

feat: show text messages in the CLI instead of asking to accept them

Tien Do Namc789295a473d
diff --git a/cli/src/app/receive.rs b/cli/src/app/receive.rs
index 148dea71..58d86a11 100644
--- a/cli/src/app/receive.rs
+++ b/cli/src/app/receive.rs
@@ -87,6 +87,19 @@ impl ReceiveSession {
}
}
+/// Returns the text of a "message request": a single text file whose content
+/// is already included as a preview, so there is nothing left to transfer.
+fn message_of(files: &HashMap<String, FileDto>) -> Option<&str> {
+ if files.len() != 1 {
+ return None;
+ }
+ let file = files.values().next()?;
+ if file.file_type != "text" && !file.file_type.starts_with("text/") {
+ return None;
+ }
+ file.preview.as_deref()
+}
+
/// The user's decision on a [`PendingReceive`].
pub(super) enum Answer {
Accept,
@@ -111,6 +124,17 @@ impl App {
// The sender is clearly reachable; make sure it has a slot.
self.device_confirmed(ip.to_string(), info.clone());
+ if let Some(message) = message_of(&files) {
+ // Nothing to transfer: the text is the request. Accepting
+ // no file ends the session right away.
+ let _ = decision_tx.send(PrepareUploadDecisionV2::Accept(HashSet::new()));
+ self.ui.log(
+ Category::Receive,
+ &format!("{}: Message received\n{}", info.alias, message),
+ );
+ return;
+ }
+
let sender = SenderTarget {
host: ip.to_string(),
port: info.port,