Skip to content

Commit 88de844

Browse files
committed
MSC4352 small fixes with os
Signed-off-by: Igor Somov <[email protected]>
1 parent 1d266fd commit 88de844

File tree

3 files changed

+79
-6
lines changed

3 files changed

+79
-6
lines changed

Cargo.lock

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

src/main.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -770,10 +770,16 @@ impl Application {
770770
// Try to copy to clipboard if available
771771
#[cfg(feature = "desktop")]
772772
{
773-
use modalkit::clipboard::ClipboardProvider;
774-
if let Ok(mut clipboard) = modalkit::clipboard::ClipboardProvider::new() {
775-
let _ = clipboard.set_contents(permalink.clone());
776-
}
773+
use modalkit::prelude::{Register, TargetShape};
774+
use modalkit::editing::rope::EditRope;
775+
use modalkit::editing::store::{RegisterCell, RegisterPutFlags};
776+
777+
let cell = RegisterCell {
778+
value: EditRope::from(permalink.clone()),
779+
shape: TargetShape::LineWise,
780+
};
781+
782+
let _ = store.registers.put(&Register::SelectionClipboard, cell, RegisterPutFlags::NONE);
777783
}
778784

779785
let msg = format!("Permalink: {} (copied to clipboard)", permalink);

src/permalink.rs

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub fn convert_https_permalink_to_matrix_uri(url_str: &str) -> Option<String> {
5757
// Room alias - Example: #room:example.org -> matrix:r/room:example.org
5858
format!("matrix:r/{}", &stripped[1..])
5959
} else if stripped.starts_with('!') {
60-
// Room ID - Example: !roomid:example.org -> matrix:roomid/roomid:example.org
60+
// Room ID - Example: !roomid:example.org -> matrix:roomid/!roomid:example.org
6161
format!("matrix:roomid/{}", stripped)
6262
} else if stripped.starts_with('@') {
6363
// User ID - Example: @user:example.org -> matrix:u/user:example.org
@@ -236,4 +236,72 @@ mod tests {
236236
"https://matrix.to"
237237
);
238238
}
239+
240+
#[test]
241+
fn test_room_alias_conversion() {
242+
// Test room alias: #room:example.org
243+
let url = "https://links.example.org/#/#room:example.org";
244+
let result = convert_https_permalink_to_matrix_uri(url).unwrap();
245+
assert_eq!(result, "matrix:r/room:example.org");
246+
}
247+
248+
#[test]
249+
fn test_room_id_conversion() {
250+
// Test room ID: !roomid:example.org
251+
let url = "https://custom.resolver/#/!roomid:example.org";
252+
let result = convert_https_permalink_to_matrix_uri(url).unwrap();
253+
assert_eq!(result, "matrix:roomid/!roomid:example.org");
254+
}
255+
256+
#[test]
257+
fn test_user_id_conversion() {
258+
// Test user ID: @user:example.org
259+
let url = "https://matrix.to/#/@user:example.org";
260+
let result = convert_https_permalink_to_matrix_uri(url).unwrap();
261+
assert_eq!(result, "matrix:u/user:example.org");
262+
}
263+
264+
#[test]
265+
fn test_event_permalink_with_query() {
266+
// Test with query parameters
267+
let url = "https://matrix.to/#/#room:example.org?via=server1.org&via=server2.org";
268+
let result = convert_https_permalink_to_matrix_uri(url).unwrap();
269+
// Should preserve query parameters
270+
assert_eq!(result, "matrix:r/room:example.org?via=server1.org&via=server2.org");
271+
}
272+
273+
#[test]
274+
fn test_invalid_permalink_no_conversion() {
275+
// Test invalid permalink (no fragment)
276+
let url = "https://example.com/page";
277+
let result = convert_https_permalink_to_matrix_uri(url);
278+
assert!(result.is_none());
279+
280+
// Test invalid permalink (fragment doesn't start with /)
281+
let url2 = "https://example.com/#anchor";
282+
let result2 = convert_https_permalink_to_matrix_uri(url2);
283+
assert!(result2.is_none());
284+
}
285+
286+
#[test]
287+
fn test_linkify_with_room_id() {
288+
// Test linkify with room ID
289+
let text = "Join this room: https://matrix.to/#/!roomid:example.org";
290+
let result = linkify_outgoing_text_to_html(text).unwrap();
291+
292+
// Should contain correct matrix: URI with ! preserved
293+
assert!(result.contains(r#"href="matrix:roomid/!roomid:example.org""#));
294+
assert!(result.contains("https://matrix.to/#/!roomid:example.org"));
295+
}
296+
297+
#[test]
298+
fn test_linkify_mixed_identifiers() {
299+
// Test with different identifier types
300+
let text = "User https://matrix.to/#/@user:example.org room https://links.org/#/!room:example.org";
301+
let result = linkify_outgoing_text_to_html(text).unwrap();
302+
303+
// Check both conversions
304+
assert!(result.contains("matrix:u/user:example.org"));
305+
assert!(result.contains("matrix:roomid/!room:example.org"));
306+
}
239307
}

0 commit comments

Comments
 (0)