Rename instance.host() to instance.hostname()
This commit is contained in:
parent
473147ed04
commit
262b910638
17 changed files with 68 additions and 71 deletions
|
@ -217,13 +217,9 @@ pub struct ActorAddress {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ActorAddress {
|
impl ActorAddress {
|
||||||
pub fn is_local(&self, instance_host: &str) -> bool {
|
|
||||||
self.hostname == instance_host
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns acct string, as used in Mastodon
|
/// Returns acct string, as used in Mastodon
|
||||||
pub fn acct(&self, instance_host: &str) -> String {
|
pub fn acct(&self, local_hostname: &str) -> String {
|
||||||
if self.is_local(instance_host) {
|
if self.hostname == local_hostname {
|
||||||
self.username.clone()
|
self.username.clone()
|
||||||
} else {
|
} else {
|
||||||
self.to_string()
|
self.to_string()
|
||||||
|
@ -357,8 +353,8 @@ pub fn get_instance_actor(
|
||||||
])),
|
])),
|
||||||
id: actor_id,
|
id: actor_id,
|
||||||
object_type: SERVICE.to_string(),
|
object_type: SERVICE.to_string(),
|
||||||
name: Some(instance.host()),
|
name: Some(instance.hostname()),
|
||||||
preferred_username: instance.host(),
|
preferred_username: instance.hostname(),
|
||||||
inbox: actor_inbox,
|
inbox: actor_inbox,
|
||||||
outbox: actor_outbox,
|
outbox: actor_outbox,
|
||||||
followers: None,
|
followers: None,
|
||||||
|
@ -385,7 +381,7 @@ mod tests {
|
||||||
};
|
};
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
const INSTANCE_HOST: &str = "example.com";
|
const INSTANCE_HOSTNAME: &str = "example.com";
|
||||||
const INSTANCE_URL: &str = "https://example.com";
|
const INSTANCE_URL: &str = "https://example.com";
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -405,8 +401,7 @@ mod tests {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let actor_address = actor.address().unwrap();
|
let actor_address = actor.address().unwrap();
|
||||||
assert_eq!(actor_address.is_local(INSTANCE_HOST), false);
|
assert_eq!(actor_address.acct(INSTANCE_HOSTNAME), "test@test.org");
|
||||||
assert_eq!(actor_address.acct(INSTANCE_HOST), "test@test.org");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -58,7 +58,7 @@ pub struct Note {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_note(
|
pub fn build_note(
|
||||||
instance_host: &str,
|
instance_hostname: &str,
|
||||||
instance_url: &str,
|
instance_url: &str,
|
||||||
post: &Post,
|
post: &Post,
|
||||||
) -> Note {
|
) -> Note {
|
||||||
|
@ -97,7 +97,7 @@ pub fn build_note(
|
||||||
|
|
||||||
let mut tags = vec![];
|
let mut tags = vec![];
|
||||||
for profile in &post.mentions {
|
for profile in &post.mentions {
|
||||||
let tag_name = format!("@{}", profile.actor_address(instance_host));
|
let tag_name = format!("@{}", profile.actor_address(instance_hostname));
|
||||||
let actor_id = profile.actor_id(instance_url);
|
let actor_id = profile.actor_id(instance_url);
|
||||||
if !primary_audience.contains(&actor_id) {
|
if !primary_audience.contains(&actor_id) {
|
||||||
primary_audience.push(actor_id.clone());
|
primary_audience.push(actor_id.clone());
|
||||||
|
@ -164,11 +164,11 @@ pub fn build_note(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_create_note(
|
pub fn build_create_note(
|
||||||
instance_host: &str,
|
instance_hostname: &str,
|
||||||
instance_url: &str,
|
instance_url: &str,
|
||||||
post: &Post,
|
post: &Post,
|
||||||
) -> Activity {
|
) -> Activity {
|
||||||
let object = build_note(instance_host, instance_url, post);
|
let object = build_note(instance_hostname, instance_url, post);
|
||||||
let primary_audience = object.to.clone();
|
let primary_audience = object.to.clone();
|
||||||
let secondary_audience = object.cc.clone();
|
let secondary_audience = object.cc.clone();
|
||||||
let activity_id = format!("{}/create", object.id);
|
let activity_id = format!("{}/create", object.id);
|
||||||
|
@ -225,7 +225,7 @@ pub async fn prepare_create_note(
|
||||||
) -> Result<OutgoingActivity<Activity>, DatabaseError> {
|
) -> Result<OutgoingActivity<Activity>, DatabaseError> {
|
||||||
assert_eq!(author.id, post.author.id);
|
assert_eq!(author.id, post.author.id);
|
||||||
let activity = build_create_note(
|
let activity = build_create_note(
|
||||||
&instance.host(),
|
&instance.hostname(),
|
||||||
&instance.url(),
|
&instance.url(),
|
||||||
post,
|
post,
|
||||||
);
|
);
|
||||||
|
@ -244,7 +244,7 @@ mod tests {
|
||||||
use crate::models::profiles::types::DbActorProfile;
|
use crate::models::profiles::types::DbActorProfile;
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
const INSTANCE_HOST: &str = "example.com";
|
const INSTANCE_HOSTNAME: &str = "example.com";
|
||||||
const INSTANCE_URL: &str = "https://example.com";
|
const INSTANCE_URL: &str = "https://example.com";
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -254,7 +254,7 @@ mod tests {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let post = Post { author, ..Default::default() };
|
let post = Post { author, ..Default::default() };
|
||||||
let note = build_note(INSTANCE_HOST, INSTANCE_URL, &post);
|
let note = build_note(INSTANCE_HOSTNAME, INSTANCE_URL, &post);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
note.id,
|
note.id,
|
||||||
|
@ -279,7 +279,7 @@ mod tests {
|
||||||
visibility: Visibility::Followers,
|
visibility: Visibility::Followers,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let note = build_note(INSTANCE_HOST, INSTANCE_URL, &post);
|
let note = build_note(INSTANCE_HOSTNAME, INSTANCE_URL, &post);
|
||||||
|
|
||||||
assert_eq!(note.to, vec![
|
assert_eq!(note.to, vec![
|
||||||
local_actor_followers(INSTANCE_URL, &post.author.username),
|
local_actor_followers(INSTANCE_URL, &post.author.username),
|
||||||
|
@ -305,7 +305,7 @@ mod tests {
|
||||||
mentions: vec![subscriber],
|
mentions: vec![subscriber],
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let note = build_note(INSTANCE_HOST, INSTANCE_URL, &post);
|
let note = build_note(INSTANCE_HOSTNAME, INSTANCE_URL, &post);
|
||||||
|
|
||||||
assert_eq!(note.to, vec![
|
assert_eq!(note.to, vec![
|
||||||
local_actor_subscribers(INSTANCE_URL, &post.author.username),
|
local_actor_subscribers(INSTANCE_URL, &post.author.username),
|
||||||
|
@ -332,7 +332,7 @@ mod tests {
|
||||||
mentions: vec![mentioned],
|
mentions: vec![mentioned],
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let note = build_note(INSTANCE_HOST, INSTANCE_URL, &post);
|
let note = build_note(INSTANCE_HOSTNAME, INSTANCE_URL, &post);
|
||||||
|
|
||||||
assert_eq!(note.to, vec![mentioned_id]);
|
assert_eq!(note.to, vec![mentioned_id]);
|
||||||
assert_eq!(note.cc.is_empty(), true);
|
assert_eq!(note.cc.is_empty(), true);
|
||||||
|
@ -346,7 +346,7 @@ mod tests {
|
||||||
in_reply_to: Some(Box::new(parent.clone())),
|
in_reply_to: Some(Box::new(parent.clone())),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let note = build_note(INSTANCE_HOST, INSTANCE_URL, &post);
|
let note = build_note(INSTANCE_HOSTNAME, INSTANCE_URL, &post);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
note.in_reply_to.unwrap(),
|
note.in_reply_to.unwrap(),
|
||||||
|
@ -386,7 +386,7 @@ mod tests {
|
||||||
mentions: vec![parent_author],
|
mentions: vec![parent_author],
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let note = build_note(INSTANCE_HOST, INSTANCE_URL, &post);
|
let note = build_note(INSTANCE_HOSTNAME, INSTANCE_URL, &post);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
note.in_reply_to.unwrap(),
|
note.in_reply_to.unwrap(),
|
||||||
|
@ -408,7 +408,7 @@ mod tests {
|
||||||
};
|
};
|
||||||
let post = Post { author, ..Default::default() };
|
let post = Post { author, ..Default::default() };
|
||||||
let activity = build_create_note(
|
let activity = build_create_note(
|
||||||
INSTANCE_HOST,
|
INSTANCE_HOSTNAME,
|
||||||
INSTANCE_URL,
|
INSTANCE_URL,
|
||||||
&post,
|
&post,
|
||||||
);
|
);
|
||||||
|
|
|
@ -17,7 +17,7 @@ use super::create_note::{
|
||||||
};
|
};
|
||||||
|
|
||||||
fn build_delete_note(
|
fn build_delete_note(
|
||||||
instance_host: &str,
|
instance_hostname: &str,
|
||||||
instance_url: &str,
|
instance_url: &str,
|
||||||
post: &Post,
|
post: &Post,
|
||||||
) -> Activity {
|
) -> Activity {
|
||||||
|
@ -31,7 +31,7 @@ fn build_delete_note(
|
||||||
};
|
};
|
||||||
let activity_id = format!("{}/delete", object.id);
|
let activity_id = format!("{}/delete", object.id);
|
||||||
let Note { to, cc, .. } = build_note(
|
let Note { to, cc, .. } = build_note(
|
||||||
instance_host,
|
instance_hostname,
|
||||||
instance_url,
|
instance_url,
|
||||||
post,
|
post,
|
||||||
);
|
);
|
||||||
|
@ -57,7 +57,7 @@ pub async fn prepare_delete_note(
|
||||||
let mut post = post.clone();
|
let mut post = post.clone();
|
||||||
add_related_posts(db_client, vec![&mut post]).await?;
|
add_related_posts(db_client, vec![&mut post]).await?;
|
||||||
let activity = build_delete_note(
|
let activity = build_delete_note(
|
||||||
&instance.host(),
|
&instance.hostname(),
|
||||||
&instance.url(),
|
&instance.url(),
|
||||||
&post,
|
&post,
|
||||||
);
|
);
|
||||||
|
@ -80,7 +80,7 @@ mod tests {
|
||||||
use crate::models::profiles::types::DbActorProfile;
|
use crate::models::profiles::types::DbActorProfile;
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
const INSTANCE_HOST: &str = "example.com";
|
const INSTANCE_HOSTNAME: &str = "example.com";
|
||||||
const INSTANCE_URL: &str = "https://example.com";
|
const INSTANCE_URL: &str = "https://example.com";
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -91,7 +91,7 @@ mod tests {
|
||||||
};
|
};
|
||||||
let post = Post { author, ..Default::default() };
|
let post = Post { author, ..Default::default() };
|
||||||
let activity = build_delete_note(
|
let activity = build_delete_note(
|
||||||
INSTANCE_HOST,
|
INSTANCE_HOSTNAME,
|
||||||
INSTANCE_URL,
|
INSTANCE_URL,
|
||||||
&post,
|
&post,
|
||||||
);
|
);
|
||||||
|
|
|
@ -38,7 +38,7 @@ async fn create_remote_profile(
|
||||||
actor: Actor,
|
actor: Actor,
|
||||||
) -> Result<DbActorProfile, HandlerError> {
|
) -> Result<DbActorProfile, HandlerError> {
|
||||||
let actor_address = actor.address()?;
|
let actor_address = actor.address()?;
|
||||||
if actor_address.is_local(&instance.host()) {
|
if actor_address.hostname == instance.hostname() {
|
||||||
return Err(HandlerError::LocalObject);
|
return Err(HandlerError::LocalObject);
|
||||||
};
|
};
|
||||||
let (maybe_avatar, maybe_banner) = fetch_actor_images(
|
let (maybe_avatar, maybe_banner) = fetch_actor_images(
|
||||||
|
@ -110,7 +110,7 @@ pub async fn get_or_import_profile_by_actor_id(
|
||||||
Err(DatabaseError::NotFound(_)) => {
|
Err(DatabaseError::NotFound(_)) => {
|
||||||
let actor = fetch_actor(instance, actor_id).await?;
|
let actor = fetch_actor(instance, actor_id).await?;
|
||||||
let actor_address = actor.address()?;
|
let actor_address = actor.address()?;
|
||||||
let acct = actor_address.acct(&instance.host());
|
let acct = actor_address.acct(&instance.hostname());
|
||||||
match get_profile_by_acct(db_client, &acct).await {
|
match get_profile_by_acct(db_client, &acct).await {
|
||||||
Ok(profile) => {
|
Ok(profile) => {
|
||||||
// WARNING: Possible actor ID change
|
// WARNING: Possible actor ID change
|
||||||
|
@ -149,13 +149,13 @@ pub async fn import_profile_by_actor_address(
|
||||||
media_dir: &Path,
|
media_dir: &Path,
|
||||||
actor_address: &ActorAddress,
|
actor_address: &ActorAddress,
|
||||||
) -> Result<DbActorProfile, HandlerError> {
|
) -> Result<DbActorProfile, HandlerError> {
|
||||||
if actor_address.hostname == instance.host() {
|
if actor_address.hostname == instance.hostname() {
|
||||||
return Err(HandlerError::LocalObject);
|
return Err(HandlerError::LocalObject);
|
||||||
};
|
};
|
||||||
let actor_id = perform_webfinger_query(instance, actor_address).await?;
|
let actor_id = perform_webfinger_query(instance, actor_address).await?;
|
||||||
let actor = fetch_actor(instance, &actor_id).await?;
|
let actor = fetch_actor(instance, &actor_id).await?;
|
||||||
let profile_acct = actor.address()?.acct(&instance.host());
|
let profile_acct = actor.address()?.acct(&instance.hostname());
|
||||||
if profile_acct != actor_address.acct(&instance.host()) {
|
if profile_acct != actor_address.acct(&instance.hostname()) {
|
||||||
// Redirected to different server
|
// Redirected to different server
|
||||||
match get_profile_by_acct(db_client, &profile_acct).await {
|
match get_profile_by_acct(db_client, &profile_acct).await {
|
||||||
Ok(profile) => return Ok(profile),
|
Ok(profile) => return Ok(profile),
|
||||||
|
|
|
@ -260,7 +260,7 @@ pub async fn handle_note(
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
if let Ok(actor_address) = mention_to_address(&tag_name) {
|
if let Ok(actor_address) = mention_to_address(&tag_name) {
|
||||||
let acct = actor_address.acct(&instance.host());
|
let acct = actor_address.acct(&instance.hostname());
|
||||||
let profile = match get_profile_by_acct(
|
let profile = match get_profile_by_acct(
|
||||||
db_client,
|
db_client,
|
||||||
&acct,
|
&acct,
|
||||||
|
|
|
@ -147,7 +147,7 @@ async fn outbox(
|
||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
let activity = build_create_note(
|
let activity = build_create_note(
|
||||||
&instance.host(),
|
&instance.hostname(),
|
||||||
&instance.url(),
|
&instance.url(),
|
||||||
post,
|
post,
|
||||||
);
|
);
|
||||||
|
@ -316,7 +316,7 @@ pub async fn object_view(
|
||||||
};
|
};
|
||||||
add_related_posts(db_client, vec![&mut post]).await?;
|
add_related_posts(db_client, vec![&mut post]).await?;
|
||||||
let object = build_note(
|
let object = build_note(
|
||||||
&config.instance().host(),
|
&config.instance().hostname(),
|
||||||
&config.instance().url(),
|
&config.instance().url(),
|
||||||
&post,
|
&post,
|
||||||
);
|
);
|
||||||
|
|
|
@ -52,7 +52,7 @@ pub fn make_feed(
|
||||||
let actor_url = local_actor_id(&instance.url(), &profile.username);
|
let actor_url = local_actor_id(&instance.url(), &profile.username);
|
||||||
let actor_name = profile.display_name.as_ref()
|
let actor_name = profile.display_name.as_ref()
|
||||||
.unwrap_or(&profile.username);
|
.unwrap_or(&profile.username);
|
||||||
let actor_address = profile.actor_address(&instance.host());
|
let actor_address = profile.actor_address(&instance.hostname());
|
||||||
let feed_title = format!("{} (@{})", actor_name, actor_address);
|
let feed_title = format!("{} (@{})", actor_name, actor_address);
|
||||||
let mut entries = vec![];
|
let mut entries = vec![];
|
||||||
let mut feed_updated_at = get_min_datetime();
|
let mut feed_updated_at = get_min_datetime();
|
||||||
|
|
|
@ -185,7 +185,7 @@ impl Instance {
|
||||||
self._url.origin().ascii_serialization()
|
self._url.origin().ascii_serialization()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn host(&self) -> String {
|
pub fn hostname(&self) -> String {
|
||||||
self._url.host_str().unwrap().to_string()
|
self._url.host_str().unwrap().to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,7 +300,7 @@ mod tests {
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(instance.url(), "https://example.com");
|
assert_eq!(instance.url(), "https://example.com");
|
||||||
assert_eq!(instance.host(), "example.com");
|
assert_eq!(instance.hostname(), "example.com");
|
||||||
assert_eq!(instance.agent(), "Mitra 1.0.0; https://example.com");
|
assert_eq!(instance.agent(), "Mitra 1.0.0; https://example.com");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,6 +317,6 @@ mod tests {
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(instance.url(), "http://1.2.3.4:3777");
|
assert_eq!(instance.url(), "http://1.2.3.4:3777");
|
||||||
assert_eq!(instance.host(), "1.2.3.4");
|
assert_eq!(instance.hostname(), "1.2.3.4");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,15 +10,15 @@ use super::utils::address_to_string;
|
||||||
pub fn verify_eip4361_signature(
|
pub fn verify_eip4361_signature(
|
||||||
message: &str,
|
message: &str,
|
||||||
signature: &str,
|
signature: &str,
|
||||||
instance_host: &str,
|
instance_hostname: &str,
|
||||||
login_message: &str,
|
login_message: &str,
|
||||||
) -> Result<String, ValidationError> {
|
) -> Result<String, ValidationError> {
|
||||||
let message: Message = message.parse()
|
let message: Message = message.parse()
|
||||||
.map_err(|_| ValidationError("invalid EIP-4361 message"))?;
|
.map_err(|_| ValidationError("invalid EIP-4361 message"))?;
|
||||||
let signature_bytes = <[u8; 65]>::from_hex(signature.trim_start_matches("0x"))
|
let signature_bytes = <[u8; 65]>::from_hex(signature.trim_start_matches("0x"))
|
||||||
.map_err(|_| ValidationError("invalid signature string"))?;
|
.map_err(|_| ValidationError("invalid signature string"))?;
|
||||||
if message.domain != instance_host {
|
if message.domain != instance_hostname {
|
||||||
return Err(ValidationError("domain doesn't match instance host"));
|
return Err(ValidationError("domain doesn't match instance hostname"));
|
||||||
};
|
};
|
||||||
let statement = message.statement.as_ref()
|
let statement = message.statement.as_ref()
|
||||||
.ok_or(ValidationError("statement is missing"))?;
|
.ok_or(ValidationError("statement is missing"))?;
|
||||||
|
@ -42,7 +42,7 @@ pub fn verify_eip4361_signature(
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
const INSTANCE_HOST: &str = "example.com";
|
const INSTANCE_HOSTNAME: &str = "example.com";
|
||||||
const LOGIN_MESSAGE: &str = "test";
|
const LOGIN_MESSAGE: &str = "test";
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -60,7 +60,8 @@ Issued At: 2022-02-14T22:27:35.500Z";
|
||||||
let signature = "0x9059c9a69c31e87d887262a574abcc33f320d5b778bea8a35c6fbdea94a17e9652b99f7cdd146ed67fa8e4bb02462774b958a129c421fe8d743a43bf67dcbcd61c";
|
let signature = "0x9059c9a69c31e87d887262a574abcc33f320d5b778bea8a35c6fbdea94a17e9652b99f7cdd146ed67fa8e4bb02462774b958a129c421fe8d743a43bf67dcbcd61c";
|
||||||
let wallet_address = verify_eip4361_signature(
|
let wallet_address = verify_eip4361_signature(
|
||||||
message, signature,
|
message, signature,
|
||||||
INSTANCE_HOST, LOGIN_MESSAGE,
|
INSTANCE_HOSTNAME,
|
||||||
|
LOGIN_MESSAGE,
|
||||||
).unwrap();
|
).unwrap();
|
||||||
assert_eq!(wallet_address, "0x70997970c51812dc3a010c7d01b50e0d17dc79c8");
|
assert_eq!(wallet_address, "0x70997970c51812dc3a010c7d01b50e0d17dc79c8");
|
||||||
}
|
}
|
||||||
|
@ -71,7 +72,8 @@ Issued At: 2022-02-14T22:27:35.500Z";
|
||||||
let signature = "xyz";
|
let signature = "xyz";
|
||||||
let error = verify_eip4361_signature(
|
let error = verify_eip4361_signature(
|
||||||
message, signature,
|
message, signature,
|
||||||
INSTANCE_HOST, LOGIN_MESSAGE,
|
INSTANCE_HOSTNAME,
|
||||||
|
LOGIN_MESSAGE,
|
||||||
).unwrap_err();
|
).unwrap_err();
|
||||||
assert_eq!(error.to_string(), "invalid EIP-4361 message");
|
assert_eq!(error.to_string(), "invalid EIP-4361 message");
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,7 +135,7 @@ pub async fn create_account(
|
||||||
let wallet_address = verify_eip4361_signature(
|
let wallet_address = verify_eip4361_signature(
|
||||||
message,
|
message,
|
||||||
signature,
|
signature,
|
||||||
&config.instance().host(),
|
&config.instance().hostname(),
|
||||||
&config.login_message,
|
&config.login_message,
|
||||||
)?;
|
)?;
|
||||||
Some(wallet_address)
|
Some(wallet_address)
|
||||||
|
|
|
@ -102,7 +102,7 @@ impl InstanceInfo {
|
||||||
None => (),
|
None => (),
|
||||||
};
|
};
|
||||||
Self {
|
Self {
|
||||||
uri: config.instance().host(),
|
uri: config.instance().hostname(),
|
||||||
title: config.instance_title.clone(),
|
title: config.instance_title.clone(),
|
||||||
short_description: config.instance_short_description.clone(),
|
short_description: config.instance_short_description.clone(),
|
||||||
description: config.instance_description.clone(),
|
description: config.instance_description.clone(),
|
||||||
|
|
|
@ -52,7 +52,7 @@ async fn token_view(
|
||||||
let wallet_address = verify_eip4361_signature(
|
let wallet_address = verify_eip4361_signature(
|
||||||
message,
|
message,
|
||||||
signature,
|
signature,
|
||||||
&config.instance().host(),
|
&config.instance().hostname(),
|
||||||
&config.login_message,
|
&config.login_message,
|
||||||
)?;
|
)?;
|
||||||
get_user_by_login_address(db_client, &wallet_address).await?
|
get_user_by_login_address(db_client, &wallet_address).await?
|
||||||
|
|
|
@ -105,7 +105,7 @@ async fn search_profiles_or_import(
|
||||||
limit: u16,
|
limit: u16,
|
||||||
) -> Result<Vec<DbActorProfile>, DatabaseError> {
|
) -> Result<Vec<DbActorProfile>, DatabaseError> {
|
||||||
if let Some(ref hostname) = maybe_hostname {
|
if let Some(ref hostname) = maybe_hostname {
|
||||||
if hostname == &config.instance().host() {
|
if hostname == &config.instance().hostname() {
|
||||||
// This is a local profile
|
// This is a local profile
|
||||||
maybe_hostname = None;
|
maybe_hostname = None;
|
||||||
};
|
};
|
||||||
|
|
|
@ -61,12 +61,12 @@ async fn create_status(
|
||||||
// Mentions
|
// Mentions
|
||||||
let mention_map = find_mentioned_profiles(
|
let mention_map = find_mentioned_profiles(
|
||||||
db_client,
|
db_client,
|
||||||
&instance.host(),
|
&instance.hostname(),
|
||||||
&post_data.content,
|
&post_data.content,
|
||||||
).await?;
|
).await?;
|
||||||
post_data.content = replace_mentions(
|
post_data.content = replace_mentions(
|
||||||
&mention_map,
|
&mention_map,
|
||||||
&instance.host(),
|
&instance.hostname(),
|
||||||
&instance.url(),
|
&instance.url(),
|
||||||
&post_data.content,
|
&post_data.content,
|
||||||
);
|
);
|
||||||
|
|
|
@ -15,7 +15,7 @@ const MENTION_SEARCH_SECONDARY_RE: &str = r"^(?P<username>[\w\.-]+)(@(?P<hostnam
|
||||||
|
|
||||||
/// Finds everything that looks like a mention
|
/// Finds everything that looks like a mention
|
||||||
fn find_mentions(
|
fn find_mentions(
|
||||||
instance_host: &str,
|
instance_hostname: &str,
|
||||||
text: &str,
|
text: &str,
|
||||||
) -> Vec<String> {
|
) -> Vec<String> {
|
||||||
let mention_re = Regex::new(MENTION_SEARCH_RE).unwrap();
|
let mention_re = Regex::new(MENTION_SEARCH_RE).unwrap();
|
||||||
|
@ -26,10 +26,10 @@ fn find_mentions(
|
||||||
let username = secondary_caps["username"].to_string();
|
let username = secondary_caps["username"].to_string();
|
||||||
let hostname = secondary_caps.name("hostname")
|
let hostname = secondary_caps.name("hostname")
|
||||||
.map(|match_| match_.as_str())
|
.map(|match_| match_.as_str())
|
||||||
.unwrap_or(instance_host)
|
.unwrap_or(instance_hostname)
|
||||||
.to_string();
|
.to_string();
|
||||||
let actor_address = ActorAddress { username, hostname };
|
let actor_address = ActorAddress { username, hostname };
|
||||||
let acct = actor_address.acct(instance_host);
|
let acct = actor_address.acct(instance_hostname);
|
||||||
if !mentions.contains(&acct) {
|
if !mentions.contains(&acct) {
|
||||||
mentions.push(acct);
|
mentions.push(acct);
|
||||||
};
|
};
|
||||||
|
@ -40,10 +40,10 @@ fn find_mentions(
|
||||||
|
|
||||||
pub async fn find_mentioned_profiles(
|
pub async fn find_mentioned_profiles(
|
||||||
db_client: &impl GenericClient,
|
db_client: &impl GenericClient,
|
||||||
instance_host: &str,
|
instance_hostname: &str,
|
||||||
text: &str,
|
text: &str,
|
||||||
) -> Result<HashMap<String, DbActorProfile>, DatabaseError> {
|
) -> Result<HashMap<String, DbActorProfile>, DatabaseError> {
|
||||||
let mentions = find_mentions(instance_host, text);
|
let mentions = find_mentions(instance_hostname, text);
|
||||||
let profiles = get_profiles_by_accts(db_client, mentions).await?;
|
let profiles = get_profiles_by_accts(db_client, mentions).await?;
|
||||||
let mut mention_map: HashMap<String, DbActorProfile> = HashMap::new();
|
let mut mention_map: HashMap<String, DbActorProfile> = HashMap::new();
|
||||||
for profile in profiles {
|
for profile in profiles {
|
||||||
|
@ -54,7 +54,7 @@ pub async fn find_mentioned_profiles(
|
||||||
|
|
||||||
pub fn replace_mentions(
|
pub fn replace_mentions(
|
||||||
mention_map: &HashMap<String, DbActorProfile>,
|
mention_map: &HashMap<String, DbActorProfile>,
|
||||||
instance_host: &str,
|
instance_hostname: &str,
|
||||||
instance_url: &str,
|
instance_url: &str,
|
||||||
text: &str,
|
text: &str,
|
||||||
) -> String {
|
) -> String {
|
||||||
|
@ -65,10 +65,10 @@ pub fn replace_mentions(
|
||||||
let username = secondary_caps["username"].to_string();
|
let username = secondary_caps["username"].to_string();
|
||||||
let hostname = secondary_caps.name("hostname")
|
let hostname = secondary_caps.name("hostname")
|
||||||
.map(|match_| match_.as_str())
|
.map(|match_| match_.as_str())
|
||||||
.unwrap_or(instance_host)
|
.unwrap_or(instance_hostname)
|
||||||
.to_string();
|
.to_string();
|
||||||
let actor_address = ActorAddress { username, hostname };
|
let actor_address = ActorAddress { username, hostname };
|
||||||
let acct = actor_address.acct(instance_host);
|
let acct = actor_address.acct(instance_hostname);
|
||||||
if let Some(profile) = mention_map.get(&acct) {
|
if let Some(profile) = mention_map.get(&acct) {
|
||||||
// Replace with a link to profile.
|
// Replace with a link to profile.
|
||||||
// Actor URL may differ from actor ID.
|
// Actor URL may differ from actor ID.
|
||||||
|
@ -108,7 +108,7 @@ mod tests {
|
||||||
use crate::activitypub::actors::types::Actor;
|
use crate::activitypub::actors::types::Actor;
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
const INSTANCE_HOST: &str = "server1.com";
|
const INSTANCE_HOSTNAME: &str = "server1.com";
|
||||||
const INSTANCE_URL: &str = "https://server1.com";
|
const INSTANCE_URL: &str = "https://server1.com";
|
||||||
const TEXT_WITH_MENTIONS: &str = concat!(
|
const TEXT_WITH_MENTIONS: &str = concat!(
|
||||||
"@user1 ",
|
"@user1 ",
|
||||||
|
@ -124,7 +124,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_find_mentions() {
|
fn test_find_mentions() {
|
||||||
let results = find_mentions(INSTANCE_HOST, TEXT_WITH_MENTIONS);
|
let results = find_mentions(INSTANCE_HOSTNAME, TEXT_WITH_MENTIONS);
|
||||||
assert_eq!(results, vec![
|
assert_eq!(results, vec![
|
||||||
"user1",
|
"user1",
|
||||||
"user_x",
|
"user_x",
|
||||||
|
@ -171,7 +171,7 @@ mod tests {
|
||||||
]);
|
]);
|
||||||
let result = replace_mentions(
|
let result = replace_mentions(
|
||||||
&mention_map,
|
&mention_map,
|
||||||
INSTANCE_HOST,
|
INSTANCE_HOSTNAME,
|
||||||
INSTANCE_URL,
|
INSTANCE_URL,
|
||||||
TEXT_WITH_MENTIONS,
|
TEXT_WITH_MENTIONS,
|
||||||
);
|
);
|
||||||
|
|
|
@ -330,12 +330,12 @@ impl DbActorProfile {
|
||||||
self.actor_id(instance_url)
|
self.actor_id(instance_url)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn actor_address(&self, instance_host: &str) -> ActorAddress {
|
pub fn actor_address(&self, local_hostname: &str) -> ActorAddress {
|
||||||
assert_eq!(self.hostname.is_none(), self.is_local());
|
assert_eq!(self.hostname.is_none(), self.is_local());
|
||||||
ActorAddress {
|
ActorAddress {
|
||||||
username: self.username.clone(),
|
username: self.username.clone(),
|
||||||
hostname: self.hostname.as_deref()
|
hostname: self.hostname.as_deref()
|
||||||
.unwrap_or(instance_host)
|
.unwrap_or(local_hostname)
|
||||||
.to_string(),
|
.to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -475,7 +475,7 @@ mod tests {
|
||||||
use crate::activitypub::actors::types::Actor;
|
use crate::activitypub::actors::types::Actor;
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
const INSTANCE_HOST: &str = "example.com";
|
const INSTANCE_HOSTNAME: &str = "example.com";
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_identity_proof_serialization() {
|
fn test_identity_proof_serialization() {
|
||||||
|
@ -527,7 +527,7 @@ mod tests {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
local_profile.actor_address(INSTANCE_HOST).to_string(),
|
local_profile.actor_address(INSTANCE_HOSTNAME).to_string(),
|
||||||
"user@example.com",
|
"user@example.com",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -545,7 +545,7 @@ mod tests {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
remote_profile.actor_address(INSTANCE_HOST).to_string(),
|
remote_profile.actor_address(INSTANCE_HOSTNAME).to_string(),
|
||||||
remote_profile.acct,
|
remote_profile.acct,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,11 +37,11 @@ async fn get_user_info(
|
||||||
query_params: WebfingerQueryParams,
|
query_params: WebfingerQueryParams,
|
||||||
) -> Result<JsonResourceDescriptor, HttpError> {
|
) -> Result<JsonResourceDescriptor, HttpError> {
|
||||||
let actor_address = parse_acct_uri(&query_params.resource)?;
|
let actor_address = parse_acct_uri(&query_params.resource)?;
|
||||||
if !actor_address.is_local(&instance.host()) {
|
if actor_address.hostname != instance.hostname() {
|
||||||
// Wrong instance
|
// Wrong instance
|
||||||
return Err(HttpError::NotFoundError("user"));
|
return Err(HttpError::NotFoundError("user"));
|
||||||
};
|
};
|
||||||
let actor_url = if actor_address.username == instance.host() {
|
let actor_url = if actor_address.username == instance.hostname() {
|
||||||
local_instance_actor_id(&instance.url())
|
local_instance_actor_id(&instance.url())
|
||||||
} else {
|
} else {
|
||||||
if !is_registered_user(db_client, &actor_address.username).await? {
|
if !is_registered_user(db_client, &actor_address.username).await? {
|
||||||
|
|
Loading…
Reference in a new issue