Commit d75abde232

d75abde2329e88ba170520f58cafbf129f99d6ae

parent: cca24034ed

Unregistered key

TianHengZhuang <39034691+TianHengZhuang@users.noreply.github.com> · 2026-09-17 04:25 UTC
committer: <noreply@github.com>

Support opening location messages with :open (#695)

Co-authored-by: Ulyssa <git@ulyssa.dev>

Layout: unified · split

docs/iamb.5 +11 −1
@@ -224,9 +224,19 @@ See
224.Sx NOTIFICATIONS 224.Sx NOTIFICATIONS
225for more details. 225for more details.
226.It Sy open_command 226.It Sy open_command
227Defines a custom command and its arguments to run when opening downloads instead of the default. 227Defines a custom command and its arguments to run when handling
228.Sy :open
229instead of the default system behaviour.
228(For example, 230(For example,
229.Sy ["my-open",\ "--file"] . ) 231.Sy ["my-open",\ "--file"] . )
232Keep in mind that
233.Sy :open
234can be used for more than just opening downloads:
235this command may also be passed
236.Sy http[s]://
237and
238.Sy geo:
239URLs for relevant messages.
230.It Sy proxy 240.It Sy proxy
231When this subsection is present, you can configure how requests are proxied to the homeserver. 241When this subsection is present, you can configure how requests are proxied to the homeserver.
232See 242See
src/windows/room/chat.rs +44
@@ -160,6 +160,25 @@ impl ChatState {
160 } 160 }
161 161
162 if let Some(msgtype) = msg.event.msgtype() { 162 if let Some(msgtype) = msg.event.msgtype() {
163 // A location message has no attachment to download, so `:open`
164 // hands its `geo:` URI over to the system handler, which will
165 // let the desktop open it with an application of its choosing.
166 if let Some(geo_uri) = location_geo_uri(msgtype) {
167 if !flags.contains(DownloadFlags::OPEN) {
168 return Err(IambError::NoAttachment.into());
169 }
170
171 let target = OsString::from(geo_uri.to_owned());
172
173 return match open_command(
174 store.application.settings.tunables.open_command.as_ref(),
175 target,
176 ) {
177 Ok(_) => Ok(InfoMessage::from(format!("Opened {geo_uri}")).into()),
178 Err(err) => Err(err),
179 };
180 }
181
163 let media = client.media(); 182 let media = client.media();
164 let mut filename = match (filename, &settings.dirs.downloads) { 183 let mut filename = match (filename, &settings.dirs.downloads) {
165 (Some(f), _) => PathBuf::from(f), 184 (Some(f), _) => PathBuf::from(f),
@@ -1175,6 +1194,14 @@ impl StatefulWidget for Chat<'_> {
1175 } 1194 }
1176} 1195}
1177 1196
1197/// Returns the `geo:` URI that a location message refers to.
1198fn location_geo_uri(msgtype: &MessageType) -> Option<&str> {
1199 match msgtype {
1200 MessageType::Location(content) => Some(content.geo_uri()),
1201 _ => None,
1202 }
1203}
1204
1178fn open_command(open_command: Option<&Vec<String>>, target: OsString) -> IambResult<()> { 1205fn open_command(open_command: Option<&Vec<String>>, target: OsString) -> IambResult<()> {
1179 if let Some(mut cmd) = open_command.and_then(cmd) { 1206 if let Some(mut cmd) = open_command.and_then(cmd) {
1180 cmd.arg(target); 1207 cmd.arg(target);
@@ -1306,6 +1333,23 @@ mod tests {
1306 1333
1307 use crate::tests::{TEST_ROOM1_ID, mock_store}; 1334 use crate::tests::{TEST_ROOM1_ID, mock_store};
1308 1335
1336 #[test]
1337 fn test_location_geo_uri() {
1338 use matrix_sdk::ruma::events::room::message::{
1339 LocationMessageEventContent,
1340 TextMessageEventContent,
1341 };
1342
1343 let location = MessageType::Location(LocationMessageEventContent::new(
1344 "geo test".into(),
1345 "geo:51.5072,-0.1276".into(),
1346 ));
1347 assert_eq!(location_geo_uri(&location), Some("geo:51.5072,-0.1276"));
1348
1349 let text = MessageType::Text(TextMessageEventContent::plain("not a location"));
1350 assert_eq!(location_geo_uri(&text), None);
1351 }
1352
1309 macro_rules! move_line { 1353 macro_rules! move_line {
1310 ($dir: expr, $count: expr) => { 1354 ($dir: expr, $count: expr) => {
1311 EditorAction::Edit( 1355 EditorAction::Edit(