-
-
Notifications
You must be signed in to change notification settings - Fork 945
Add hashing for activity ids #6366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
48f44e7
b34f06b
5b6348d
41bbfc6
18c6db2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -55,7 +55,7 @@ impl CreateOrUpdateNote { | |||||
| .await? | ||||||
| .into(); | ||||||
|
|
||||||
| let id = generate_activity_id(kind.clone(), &context)?; | ||||||
| let id = generate_activity_id(kind.clone(), None, &context)?; | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| let note = ApubComment(comment).into_json(&context).await?; | ||||||
|
|
||||||
| let create_or_update = CreateOrUpdateNote { | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -44,9 +44,10 @@ impl CreateOrUpdatePage { | |||||
| actor: &ApubPerson, | ||||||
| community: &ApubCommunity, | ||||||
| kind: CreateOrUpdateType, | ||||||
| object_id: Option<&str>, | ||||||
| context: &Data<LemmyContext>, | ||||||
| ) -> LemmyResult<CreateOrUpdatePage> { | ||||||
| let id = generate_activity_id(kind.clone(), context)?; | ||||||
| let id = generate_activity_id(kind.clone(), object_id, context)?; | ||||||
| Ok(CreateOrUpdatePage { | ||||||
| actor: actor.id().clone().into(), | ||||||
| to: generate_to(community)?, | ||||||
|
|
@@ -71,7 +72,7 @@ impl CreateOrUpdatePage { | |||||
| .into(); | ||||||
|
|
||||||
| let create_or_update = | ||||||
| CreateOrUpdatePage::new(post.into(), &person, &community, kind, &context).await?; | ||||||
| CreateOrUpdatePage::new(post.into(), &person, &community, kind, None, &context).await?; | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually this can be a problem when editing the post, then each Update activity will have the same id. So you also need to hash the timestamp (published_at or updated_at). |
||||||
| let inboxes = tagged_user_inboxes(&create_or_update.object.tag, &context).await?; | ||||||
| let activity = AnnouncableActivities::CreateOrUpdatePost(create_or_update); | ||||||
| send_activity_in_community(activity, &person, &community, inboxes, false, &context).await?; | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -82,30 +82,50 @@ pub(crate) fn check_community_deleted_or_removed(community: &Community) -> Lemmy | |||||
|
|
||||||
| /// Generate a unique ID for an activity, in the format: | ||||||
| /// `http(s)://example.com/receive/create/202daf0a-1489-45df-8d2e-c8a3173fed36` | ||||||
| fn generate_activity_id<T>(kind: T, context: &LemmyContext) -> Result<Url, ParseError> | ||||||
| fn generate_activity_id<T>( | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To avoid passing None in so many places, you could do: fn generate_activity_id_with_object_id(kind, context) {
generate_activity_id(kind, None, context)
}
fn generate_activity_id(kind, object_id, context) {
generate_activity_id(kind, context)
} |
||||||
| kind: T, | ||||||
| object_id: Option<&str>, | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| context: &LemmyContext, | ||||||
| ) -> Result<Url, ParseError> | ||||||
| where | ||||||
| T: ToString, | ||||||
| { | ||||||
| let id = format!( | ||||||
| "{}/activities/{}/{}", | ||||||
| &context.settings().get_protocol_and_hostname(), | ||||||
| kind.to_string().to_lowercase(), | ||||||
| Uuid::new_v4() | ||||||
| ); | ||||||
| let hostname = context.settings().get_protocol_and_hostname(); | ||||||
| let kind_str = kind.to_string().to_lowercase(); | ||||||
|
|
||||||
| let uuid_str = if let Some(o) = object_id { | ||||||
| let input = format!("{}:{}", kind_str, o); | ||||||
| Uuid::from_bytes(md5::compute(input).0).to_string() | ||||||
| } else { | ||||||
| Uuid::new_v4().to_string() | ||||||
| }; | ||||||
|
|
||||||
| let id = format!("{}/activities/{}/{}", hostname, kind_str, uuid_str); | ||||||
| Url::parse(&id) | ||||||
| } | ||||||
|
|
||||||
| /// like generate_activity_id but also add the inner kind for easier debugging | ||||||
| fn generate_announce_activity_id( | ||||||
| inner_kind: &str, | ||||||
| protocol_and_hostname: &str, | ||||||
| object_id: Option<&str>, | ||||||
| ) -> Result<Url, ParseError> { | ||||||
| let inner_kind_str = inner_kind.to_lowercase(); | ||||||
|
|
||||||
| let uuid_str = if let Some(o) = object_id { | ||||||
| // add "announce:" in front to avoid collision with generate_activity_id | ||||||
| let input = format!("announce:{}:{}", inner_kind_str, o); | ||||||
| Uuid::from_bytes(md5::compute(input).0).to_string() | ||||||
| } else { | ||||||
| Uuid::new_v4().to_string() | ||||||
| }; | ||||||
|
|
||||||
| let id = format!( | ||||||
| "{}/activities/{}/{}/{}", | ||||||
| protocol_and_hostname, | ||||||
| AnnounceType::Announce.to_string().to_lowercase(), | ||||||
| inner_kind.to_lowercase(), | ||||||
| Uuid::new_v4() | ||||||
| inner_kind_str, | ||||||
| uuid_str | ||||||
| ); | ||||||
| Url::parse(&id) | ||||||
| } | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
sha2which we are already using as dependency.