Skip to content

Commit 78a8d3c

Browse files
fixed an issue causing errors when trying to open user timelines from other instances timelines, closes #88
1 parent a61f64b commit 78a8d3c

2 files changed

Lines changed: 45 additions & 7 deletions

File tree

src/commands.rs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,15 @@ pub fn handle_ui_command(cmd: UiCommand, ctx: &mut UiCommandContext<'_>) {
11261126
return;
11271127
}
11281128
};
1129+
1130+
if let Some(url) = foreign_url(state, Some(&account.url)) {
1131+
state.pending_user_lookup_action = Some(action);
1132+
if let Some(net) = &state.network_handle {
1133+
net.send(NetworkCommand::ResolveAccount { url });
1134+
}
1135+
return;
1136+
}
1137+
11291138
match action {
11301139
dialogs::UserLookupAction::Profile => {
11311140
if let Some(net) = &state.network_handle {
@@ -1283,9 +1292,9 @@ pub fn handle_ui_command(cmd: UiCommand, ctx: &mut UiCommandContext<'_>) {
12831292
|suggestions: &mut Vec<String>,
12841293
status: &Status,
12851294
push_unique: &mut dyn FnMut(&mut Vec<String>, String)| {
1286-
push_unique(suggestions, format!("@{}", status.account.acct));
1295+
push_unique(suggestions, format!("@{}", status.account.full_acct()));
12871296
if let Some(reblog) = &status.reblog {
1288-
push_unique(suggestions, format!("@{}", reblog.account.acct));
1297+
push_unique(suggestions, format!("@{}", reblog.account.full_acct()));
12891298
for mention in &reblog.mentions {
12901299
push_unique(suggestions, format!("@{}", mention.acct));
12911300
}
@@ -1299,19 +1308,19 @@ pub fn handle_ui_command(cmd: UiCommand, ctx: &mut UiCommandContext<'_>) {
12991308
if let Some(entry) = get_selected_entry(state) {
13001309
match entry {
13011310
TimelineEntry::Status(status) => {
1302-
default_value = Some(format!("@{}", status.account.acct));
1311+
default_value = Some(format!("@{}", status.account.full_acct()));
13031312
collect_status_users(&mut suggestions, status, &mut push_unique);
13041313
}
13051314
TimelineEntry::Notification(notification) => {
1306-
let handle = format!("@{}", notification.account.acct);
1315+
let handle = format!("@{}", notification.account.full_acct());
13071316
default_value = Some(handle.clone());
13081317
push_unique(&mut suggestions, handle);
13091318
if let Some(status) = &notification.status {
13101319
collect_status_users(&mut suggestions, status, &mut push_unique);
13111320
}
13121321
}
13131322
TimelineEntry::Account(account) => {
1314-
let handle = format!("@{}", account.acct);
1323+
let handle = format!("@{}", account.full_acct());
13151324
default_value = Some(handle.clone());
13161325
push_unique(&mut suggestions, handle);
13171326
}
@@ -1327,13 +1336,13 @@ pub fn handle_ui_command(cmd: UiCommand, ctx: &mut UiCommandContext<'_>) {
13271336
collect_status_users(&mut suggestions, status, &mut push_unique);
13281337
}
13291338
TimelineEntry::Notification(notification) => {
1330-
push_unique(&mut suggestions, format!("@{}", notification.account.acct));
1339+
push_unique(&mut suggestions, format!("@{}", notification.account.full_acct()));
13311340
if let Some(status) = &notification.status {
13321341
collect_status_users(&mut suggestions, status, &mut push_unique);
13331342
}
13341343
}
13351344
TimelineEntry::Account(account) => {
1336-
push_unique(&mut suggestions, format!("@{}", account.acct));
1345+
push_unique(&mut suggestions, format!("@{}", account.full_acct()));
13371346
}
13381347
TimelineEntry::Hashtag(_) => {}
13391348
}
@@ -1407,6 +1416,14 @@ pub fn handle_ui_command(cmd: UiCommand, ctx: &mut UiCommandContext<'_>) {
14071416
return;
14081417
}
14091418
if let Some((mention, action)) = dialogs::prompt_for_mentions(frame, &all_mentions) {
1419+
if let Some(url) = foreign_url(state, Some(&mention.url)) {
1420+
state.pending_user_lookup_action = Some(action);
1421+
if let Some(net) = &state.network_handle {
1422+
net.send(NetworkCommand::ResolveAccount { url });
1423+
}
1424+
return;
1425+
}
1426+
14101427
// Resolution chain: get_account by ID → lookup_account by acct → synthetic fallback
14111428
let account = if let (Some(client), Some(token)) = (&state.client, &state.access_token) {
14121429
let by_id = if mention.id.is_empty() { None } else { client.get_account(token, &mention.id).ok() };
@@ -1763,6 +1780,14 @@ pub fn handle_ui_command(cmd: UiCommand, ctx: &mut UiCommandContext<'_>) {
17631780
};
17641781
match &entry {
17651782
TimelineEntry::Account(account) => {
1783+
if let Some(url) = foreign_url(state, Some(&account.url)) {
1784+
state.pending_user_lookup_action = Some(dialogs::UserLookupAction::Profile);
1785+
if let Some(net) = &state.network_handle {
1786+
net.send(NetworkCommand::ResolveAccount { url });
1787+
}
1788+
return;
1789+
}
1790+
17661791
if let Some(net) = &state.network_handle {
17671792
net.send(NetworkCommand::FetchRelationship { account_id: account.id.clone() });
17681793
net.send(NetworkCommand::FetchAccount { account_id: account.id.clone() });

src/mastodon.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,19 @@ impl Account {
877877
if self.display_name.is_empty() { &self.username } else { &self.display_name }
878878
}
879879

880+
pub fn full_acct(&self) -> String {
881+
if self.acct.contains('@') {
882+
self.acct.clone()
883+
} else {
884+
if let Ok(url) = reqwest::Url::parse(&self.url) {
885+
if let Some(host) = url.host_str() {
886+
return format!("{}@{}", self.acct, host);
887+
}
888+
}
889+
self.acct.clone()
890+
}
891+
}
892+
880893
pub fn timeline_display_name(&self, mode: DisplayNameEmojiMode) -> String {
881894
if mode == DisplayNameEmojiMode::None {
882895
return self.display_name_or_username().to_string();

0 commit comments

Comments
 (0)