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
224224.Sx NOTIFICATIONS
225225for more details.
226226.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.
228230(For example,
229231.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.
230240.It Sy proxy
231241When this subsection is present, you can configure how requests are proxied to the homeserver.
232242See
src/windows/room/chat.rs +44
@@ -160,6 +160,25 @@ impl ChatState {
160160 }
161161
162162 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
163182 let media = client.media();
164183 let mut filename = match (filename, &settings.dirs.downloads) {
165184 (Some(f), _) => PathBuf::from(f),
@@ -1175,6 +1194,14 @@ impl StatefulWidget for Chat<'_> {
11751194 }
11761195}
11771196
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
11781205fn open_command(open_command: Option<&Vec<String>>, target: OsString) -> IambResult<()> {
11791206 if let Some(mut cmd) = open_command.and_then(cmd) {
11801207 cmd.arg(target);
@@ -1306,6 +1333,23 @@ mod tests {
13061333
13071334 use crate::tests::{TEST_ROOM1_ID, mock_store};
13081335
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
13091353 macro_rules! move_line {
13101354 ($dir: expr, $count: expr) => {
13111355 EditorAction::Edit(