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

Big refactoring of the Inbox #443

Merged
merged 37 commits into from Apr 17, 2019
Merged

Big refactoring of the Inbox #443

merged 37 commits into from Apr 17, 2019

Conversation

elegaanz
Copy link
Member

@elegaanz elegaanz commented Feb 11, 2019

We now have a type that routes an activity through the registered handlers
until one of them matches.

Each Actor/Activity/Object combination is represented by an implementation of AsObject

These combinations are then registered on the Inbox type, which will try to deserialize
the incoming activity in the requested types.

Advantages:

  • nicer syntax: the final API is clearer and more idiomatic
  • more generic: only two traits (AsActor and AsObject) instead of one for each kind of activity
  • we always try to dereference unknown objects
  • it is easier to see which activities we handle and which one we don't

(sorry for the big diff once again 😕)

We now have a type that routes an activity through the registered handlers
until one of them matches.

Each Actor/Activity/Object combination is represented by an implementation of AsObject

These combinations are then registered on the Inbox type, which will try to deserialize
the incoming activity in the requested types.

Advantages:
- nicer syntax: the final API is clearer and more idiomatic
- more generic: only two traits (`AsActor` and `AsObject`) instead of one for each kind of activity
- it is easier to see which activities we handle and which one we don't
@elegaanz elegaanz added C: Enhancement New feature or request A: Federation Stuff related to Federation S: Ready for review This PR is ready to be reviewed A: Backend Code running on the server labels Feb 11, 2019
@codecov
Copy link

codecov bot commented Feb 11, 2019

Codecov Report

Merging #443 into master will increase coverage by 12.81%.
The diff coverage is 54.19%.

@@             Coverage Diff             @@
##           master     #443       +/-   ##
===========================================
+ Coverage   29.66%   42.48%   +12.81%     
===========================================
  Files          66       68        +2     
  Lines        7190     9314     +2124     
===========================================
+ Hits         2133     3957     +1824     
- Misses       5057     5357      +300

Copy link
Contributor

@trinity-1686a trinity-1686a left a comment

Choose a reason for hiding this comment

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

first batch of comments, I'll run some tests this evening or tomorrow

plume-common/src/activity_pub/inbox.rs Outdated Show resolved Hide resolved
plume-common/src/activity_pub/inbox.rs Outdated Show resolved Hide resolved
plume-models/src/blogs.rs Show resolved Hide resolved
plume-models/src/lib.rs Outdated Show resolved Hide resolved
plume-models/src/lib.rs Show resolved Hide resolved
plume-models/src/mentions.rs Outdated Show resolved Hide resolved
And fix compilations issues that I didn't catch before ?
- Avoid panics
- Don't search for AP ID infinitely
- Code style issues
@elegaanz elegaanz added this to the Alpha 2 milestone Mar 12, 2019
Copy link
Contributor

@trinity-1686a trinity-1686a left a comment

Choose a reason for hiding this comment

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

I'm trying to test each activities. Sending/receiving delete seems to not be working. Sending like/reshare/follow works, but not receiving them. I haven't tested some Undo because I wasn't able to create the related activity in the first place

src/routes/comments.rs Outdated Show resolved Hide resolved
src/inbox.rs Outdated Show resolved Hide resolved
src/routes/posts.rs Outdated Show resolved Hide resolved
src/inbox.rs Outdated Show resolved Hide resolved
src/inbox.rs Outdated Show resolved Hide resolved
src/inbox.rs Outdated Show resolved Hide resolved
src/inbox.rs Outdated Show resolved Hide resolved
@elegaanz
Copy link
Member Author

Thanks for your review @fdb-hiroshima. I'll try to reproduce your issues and fix them, and maybe add tests for it in plume-models too.

It should be implemented for any AP object.

It allows to look for an object in database using its AP ID, or to dereference it if it was not present in database

Also moves the inbox code to plume-models to test it (and write a basic test for each activity type we handle)
plume-common/src/activity_pub/inbox.rs Outdated Show resolved Hide resolved
plume-common/src/activity_pub/inbox.rs Outdated Show resolved Hide resolved
plume-common/src/activity_pub/inbox.rs Show resolved Hide resolved
plume-models/src/blogs.rs Show resolved Hide resolved
Replace Context with PlumeRockets (and use it for the API context too while we are at it)
@elegaanz
Copy link
Member Author

I fixed all the conflicts, and now instead of using Context we use PlumeRockets. I also deployed this branch to https://baptiste.gelez.xyz to make testing easier if needed.

Copy link
Contributor

@igalic igalic left a comment

Choose a reason for hiding this comment

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

weak 👀

plume-common/src/activity_pub/inbox.rs Outdated Show resolved Hide resolved
plume-models/src/comments.rs Outdated Show resolved Hide resolved
plume-models/src/comments.rs Outdated Show resolved Hide resolved
@elegaanz
Copy link
Member Author

elegaanz commented Mar 25, 2019

So I did some testing, and here are the results:

Mastodon Pleroma Plume
Announce ✔️ ✔️ ✔️
Create Note ✔️ ✔️ ✔️
Create Article - - ✔️
Delete Note ✔️ ✔️ ✔️
Delete Article - - ✔️
Follow ✔️ ✔️ ✔️
Like ✔️ ✔️ ✔️
Undo Announce ✔️ Works if the Pleroma user is followed ✔️
Undo Follow ✔️ ✔️ ✔️
Undo Like ✔️ Works if the Pleroma user is followed ✔️
Update Article - - ✔️
  1. The CW is not here
  2. The notification is not deleted (see Delete notifications when deleting comments #499)
  3. There is no error, but after refreshing the Mastodon page, the follow is not accepted (:hourglass: icon)

I will try to debug a bit more the errors I encountered.

@igalic
Copy link
Contributor

igalic commented Mar 25, 2019

it would be cool if we could add a service: mastodon and service: pleroma to Travis 😅

@elegaanz
Copy link
Member Author

I think if we were on Gitlab we could just pull their Docker images… I really miss Gitlab CI.

@trinity-1686a
Copy link
Contributor

can't we do it the ugly way with some bash script?

@elegaanz
Copy link
Member Author

We could, but it would take a lot of time to install all the dependencies, and the CI already takes so long to run.

@igalic
Copy link
Contributor

igalic commented Mar 25, 2019

i think we're starting to discuss integration tests, and it's not really fruitful in this PR.

@elegaanz
Copy link
Member Author

elegaanz commented Apr 2, 2019

Update: I optimized the algorithm a little bit to avoid dereferencing the same object twice, fixed the space-in-username issue, and found why it was not possible to Undo Announce and Like from Pleroma. It was just not sending the activity to Plume because no one was following the Pleroma account on the Plume instance. It works fine if I follow my Pleroma account from Plume. I still created a bug report.

So I think this PR is ready for another review. 😄

plume-models/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@trinity-1686a trinity-1686a left a comment

Choose a reason for hiding this comment

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

👀

plume-common/src/activity_pub/inbox.rs Outdated Show resolved Hide resolved
plume-common/src/activity_pub/inbox.rs Show resolved Hide resolved
Copy link
Contributor

@trinity-1686a trinity-1686a left a comment

Choose a reason for hiding this comment

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

👀

fn from_activity(c: &PlumeRocket, acct: CustomGroup) -> Result<Self> {
let url = Url::parse(&acct.object.object_props.id_string()?)?;
let inst = url.host_str()?;
let instance = Instance::find_by_domain(&c.conn, inst).or_else(|_| {
Copy link
Contributor

Choose a reason for hiding this comment

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

out of scope for this pr, but we should consider a find_or_create of some kind instead of find_by_domain.or_else(insert), so to not tie to much code from one part of the model to another

plume-models/src/blogs.rs Outdated Show resolved Hide resolved
plume-models/src/posts.rs Outdated Show resolved Hide resolved
plume-models/src/posts.rs Outdated Show resolved Hide resolved
plume-models/src/posts.rs Outdated Show resolved Hide resolved
plume-models/src/posts.rs Show resolved Hide resolved
po/plume-front/en.po~ Outdated Show resolved Hide resolved
@trinity-1686a
Copy link
Contributor

trinity-1686a commented Apr 7, 2019

Federation with old Plume

Sending activities

  • Unsubscribing from a user does not seem to delete the entry in database
  • Sending comment don't seem to propagate CW (maybe bug from old Plume) This is a bug from old Plume

Receiving

all right

Federation with itself

  • Unsubscribing from a user does not seem to delete the entry in database
  • Sending/Receiving Post Update does not seems to update post cover-picture

pleroma

Sending activities

  • boost (announce) post doesn't seems to work (unboost untested)
  • follow does not seems to work, but it might be my pleroma having problems (unfollow untested)

Receiving

  • again issues with follow, but again maybe my pleroma

@trinity-1686a
Copy link
Contributor

trinity-1686a commented Apr 7, 2019

#443 (comment) by the way if we manage to get some certificate we can use in tests, this is now probably possible with circleci

@elegaanz
Copy link
Member Author

@fdb-hiroshima The issues with Pleroma are normally fixed now.

Copy link
Contributor

@trinity-1686a trinity-1686a left a comment

Choose a reason for hiding this comment

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

🚀

@elegaanz
Copy link
Member Author

Yay, Finally! Thank you @igalic and @fdb-hiroshima for reviewing this big PR! 😊

@elegaanz elegaanz merged commit 12efe72 into master Apr 17, 2019
@elegaanz elegaanz deleted the inbox-refactor branch April 17, 2019 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A: Backend Code running on the server A: Federation Stuff related to Federation C: Enhancement New feature or request S: Ready for review This PR is ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants