Skip to content
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

Wrap attributedTo for group to fix Peertube federation #5509

Merged
merged 10 commits into from
Mar 26, 2025

Conversation

flamingo-cant-draw
Copy link
Collaborator

Peertube uses attributedTo on Groups differently to Lemmy, which has the knock-on effect of making Lemmy reject videos from Peertube (more details). To get around this, we need to wrap attributedTo for Group like we do for Page.

@Nutomic
Copy link
Member

Nutomic commented Mar 17, 2025

Unfortunately it still cant fetch the channel. You can try with cargo run and the command below. To see the error message add logging here.

curl http://localhost:8536/api/v4/resolve_object?q=https://tilvids.com/c/thelinuxexperiment_channel

The error is value too long for type character varying(150)", see #1375. 150 chars means the problem is community.description, or summary in terms of federation which has 545 chars for that channel. The solution for that would be a helper method which cuts off strings longer than x chars so they fit in the db limit.

Comment on lines 248 to 252
if !(page.kind == PageType::Video) {
to_local_url(url.as_str(), context).await.or(Some(url))
} else {
Some(url)
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed to prevent a stack overflow from happening, as this will endlessly recurse otherwise. But now you can resolve a PeerTube video without issue.

curl http://localhost:8536/api/v4/resolve_object?q=https://tilvids.com/videos/watch/251f4ba5-2bb6-4b26-be3b-d7e7c0a93084

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, to_local_url really needs some kind of stack to keep track of what's already being resolved as it's trivial to cause a stack overflow with it. E.g:

curl http://localhost:8536/api/v4/resolve_object?q=https://lemmy.dbzer0.com/u/Blaze

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, opened #5536 for that.


pub fn truncate_description(string: String) -> String {
truncate_for_db(string, SITE_DESCRIPTION_MAX_LENGTH)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there is any way to get the max_length attributes from schema.rs, then we dont have to define them twice.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pry not worth it anyway.

Comment on lines +231 to +232
.filter(|p| p.kind == PersonOrGroupType::Person)
.map(|p| ObjectId::<ApubPerson>::from(p.id.clone().into_inner()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's also a filter_map function that can combine these 2 steps:

Suggested change
.filter(|p| p.kind == PersonOrGroupType::Person)
.map(|p| ObjectId::<ApubPerson>::from(p.id.clone().into_inner()))
.filter_map(|p| (p.kind == PersonOrGroupType::Person)
.then(|| ObjectId::<ApubPerson>::from(p.id.clone().into_inner()))
)

If the type that p.id implements Copy, you can also omit the call to clone.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +153 to +156
match self {
AttributedTo::Lemmy(l) => Some(l.moderators().into()),
AttributedTo::Peertube(_) => None,
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: could be:

Suggested change
match self {
AttributedTo::Lemmy(l) => Some(l.moderators().into()),
AttributedTo::Peertube(_) => None,
}
if let AttributedTo::Lemmy(l) = self {
Some(l.moderators().into())
} else {
None
}

I'll leave it to the other reviewers to decide which style is preferred.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Match has less lines which makes it easier to read, plus we might add more variants in the future. So leave it as is.

Copy link
Member

@dessalines dessalines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@Nutomic Nutomic merged commit 0c1d9c9 into LemmyNet:main Mar 26, 2025
1 check passed
@flamingo-cant-draw flamingo-cant-draw deleted the peertube-moderators branch March 26, 2025 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants