-
-
Notifications
You must be signed in to change notification settings - Fork 948
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 21 commits
7cf9223
36f48fe
b4bab81
a9f4195
91f043f
b6a25e9
0a619de
99d0782
5ae79aa
ef854ef
73db584
f2d4584
5a72720
de6b70c
2205372
b7ac661
f1b062f
3195399
6039b71
10bdad2
70a38e2
2de5147
70bba34
b62280d
fc443e1
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 |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| use crate::{ | ||
| activity_lists::AnnouncableActivities, | ||
| generate_activity_id, | ||
| generate_activity_id_with_object_id, | ||
| generate_announce_activity_id, | ||
| protocol::{ | ||
| IdOrNestedObject, | ||
|
|
@@ -82,15 +82,19 @@ impl AnnounceActivity { | |
| pub fn new( | ||
| object: RawAnnouncableActivities, | ||
| community: &ApubCommunity, | ||
| object_id: Option<&Url>, | ||
| context: &Data<LemmyContext>, | ||
| ) -> LemmyResult<AnnounceActivity> { | ||
| let inner_kind = object | ||
| .other | ||
| .get("type") | ||
| .and_then(serde_json::Value::as_str) | ||
| .unwrap_or("other"); | ||
| let id = | ||
| generate_announce_activity_id(inner_kind, &context.settings().get_protocol_and_hostname())?; | ||
| let id = generate_announce_activity_id( | ||
| inner_kind, | ||
| &context.settings().get_protocol_and_hostname(), | ||
| object_id, | ||
| )?; | ||
| Ok(AnnounceActivity { | ||
| actor: community.id().clone().into(), | ||
| to: generate_to(community)?, | ||
|
|
@@ -111,7 +115,7 @@ impl AnnounceActivity { | |
| community: &ApubCommunity, | ||
| context: &Data<LemmyContext>, | ||
| ) -> LemmyResult<()> { | ||
| let announce = AnnounceActivity::new(object.clone(), community, context)?; | ||
| let announce = AnnounceActivity::new(object.clone(), community, None, context)?; | ||
| let inboxes = ActivitySendTargets::to_local_community_followers(community.id); | ||
|
Author
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. Are we sure we want the activity id for
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. The same activity must always have the same ID. |
||
| send_lemmy_activity(context, announce, community, inboxes.clone(), false).await?; | ||
|
|
||
|
|
@@ -122,14 +126,14 @@ impl AnnounceActivity { | |
| // Hack: need to convert Page into a format which can be sent as activity, which requires | ||
| // adding actor field. | ||
| let announcable_page = RawAnnouncableActivities { | ||
| id: generate_activity_id(AnnounceType::Announce, context)?, | ||
| id: generate_activity_id_with_object_id(AnnounceType::Announce, context)?, | ||
| actor: c.actor.clone().into_inner(), | ||
| other: serde_json::to_value(c.object)? | ||
| .as_object() | ||
| .ok_or(UntranslatedError::Unreachable)? | ||
| .clone(), | ||
| }; | ||
| let announce_compat = AnnounceActivity::new(announcable_page, community, context)?; | ||
| let announce_compat = AnnounceActivity::new(announcable_page, community, None, context)?; | ||
| send_lemmy_activity(context, announce_compat, community, inboxes, false).await?; | ||
| } | ||
| Ok(()) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,7 +46,12 @@ impl CreateOrUpdatePage { | |
| kind: CreateOrUpdateType, | ||
| context: &Data<LemmyContext>, | ||
| ) -> LemmyResult<CreateOrUpdatePage> { | ||
| let id = generate_activity_id(kind.clone(), context)?; | ||
| // get object_id | ||
| let timestamp = post.updated_at.unwrap_or(post.published_at); // use the latest timestamp | ||
| let mut object_id = (*post.ap_id.0).clone(); | ||
| object_id.set_fragment(Some(×tamp.to_rfc3339())); | ||
|
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. This code is duped several times. Make it an impl function on post: crates/db_schema/src/impls/post.rs
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. This still needs to be addressed. |
||
|
|
||
| let id = generate_activity_id(kind.clone(), Some(&object_id), context)?; | ||
| Ok(CreateOrUpdatePage { | ||
| actor: actor.id().clone().into(), | ||
| to: generate_to(community)?, | ||
|
|
@@ -70,6 +75,20 @@ impl CreateOrUpdatePage { | |
| .await? | ||
| .into(); | ||
|
|
||
| // get object_id for activity id generation | ||
| let ap_id = (*post.ap_id.0).clone(); | ||
| let _object_id = match kind { | ||
| // for Create, use the post's ap id | ||
| CreateOrUpdateType::Create => Some(&ap_id), | ||
| // for Update, use a timestamp to ensure each Update activity is unique | ||
| CreateOrUpdateType::Update => { | ||
| let timestamp = post.updated_at.unwrap_or(post.published_at); // use the latest timestamp | ||
| let mut seed_url = ap_id; | ||
| seed_url.set_fragment(Some(×tamp.to_rfc3339())); | ||
| Some(&seed_url.clone()) | ||
|
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. See above |
||
| } | ||
| }; | ||
|
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. Private message also needs the same logic. Best And you dont need to change anything in this file, it only needs to be in |
||
|
|
||
| let create_or_update = | ||
| CreateOrUpdatePage::new(post.into(), &person, &community, kind, &context).await?; | ||
| let inboxes = tagged_user_inboxes(&create_or_update.object.tag, &context).await?; | ||
|
|
||
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.
Got checked in by mistake I think.