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
Improve federation regarding reshares and root post author #6481
Conversation
Also, the bug in action: https://iliketoast.net/posts/775355 <-- my reshare of HQ post, has a comment from Sean |
Hmm actually I need to continue testing this patch tomorrow... |
Actually, this ended up not being so simple. I managed to (by moving the code to
What happens now is that a participation is never created for user A on the reshared posts, which means that any replies will not arrive on user A pod. I managed to get that part working, ie participations are created to the root author always, independent of how far in the chain the resharing user is. But, if user C comments on his/her reshare, the comment only comes to user B's pod, not user A's. I can't really figure out how to handle the situation, to make either user B pod relay the comment to user A or something else. Anyway, I realized too that this changes quite a few things which maybe not everyone will like, though personally I would like. So, if this change was implemented, the original root author would always be subscribed to comments and likes to reshares. Of course, this is quite a big change in functionality, for me to the better.. What do people think - shall I continue working on fixing the relationships regarding participations in reshares? If you are wondering what the problem is - it is basically this: User A posts a post --> all the reshares end up on user A pod, but none of the interactions to it. This is broken functionality where the post exists but not the participations. We should somehow fix it OR not deliver the reshare to the root author pod at all. |
11c2ad2
to
af29fe4
Compare
OK I've added functionality now to also push comments made to reshares to the original author. This, with the first comment, will cause also a notification to the reshare author, unless the "notifications for non-contacts" bug is hit. I can't figure out how to write the test so that I can first build a comment, then except it in the dispatcher and then trigger everything so that I can check that |
For the changed functionality, would love some feedback whether it is acceptable. I guess it could be configurable ie "notify on all reshare activity" etc. The participation part could also be removed and only make comments federate better, I thought these are linked but not really in the end, so this PR kind of contains two changes. Can separate if wished. Ping for opinions @Flaburgan @goobertron @svbergerem @jhass @denschub @AugierLe42e |
Do you think it is possible for the comments to be the same on all the reshares? Because doing this could cause the problem that otheer people answer on the original post to a comment that has been made on a reshare so the author of the comment does not know someone has answered him (because he is notified for the reshare and not the original post). |
Where the comments link hasn't been changed, the comment is just delivered to one extra place: the root authors pod. |
I think @Flaburgan approved in principle in IRL discussion here at the hackathon, the adding participation between root author and reshare posts. Correct me if understood wrong :) I think it adds value to users to be notified when their posts are interacted with. |
527f5cd
to
6585f83
Compare
Postzord::Dispatcher.defer_build_and_post(@user, relayable, @dispatcher_opts) | ||
relayable | ||
end | ||
end | ||
|
||
def add_root_author(relayable) | ||
# If comment post is a reshare, include original author in subscribers | ||
if relayable.parent.respond_to?(:root) && relayable.parent.root |
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 a guard clause instead of wrapping the code inside a conditional expression.
Rebased, but still not really sure how to write the test. Any help appreciated. Btw, it's awesome receiving notifications for other people commenting on my reshares. Would really love to get this in. Also the comment federation would be appreciated by many. Anything I can do to move this? |
Yep +1 from my side. |
@root = @reshare.root | ||
end | ||
|
||
let(:receiver) { Postzord::Receiver::LocalBatch.new(@object, @ids) } |
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.
This line is not needed.
6585f83
to
895e1c4
Compare
# opts = {:additional_subscribers => [alice.person]} | ||
allow_any_instance_of(Federated::Generator).to receive(:create!) | ||
# expect(Postzord::Dispatcher).to receive(:defer_build_and_post).with(bob, @comment, opts) | ||
expect(Postzord::Dispatcher).to receive(:defer_build_and_post) |
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.
Thanks @jhass for the review. I still can't figure out this however, how to get @comment.save!
(which I assume is the right way to go from here) to end up calling defer_build_and_post
.
I assume I have to do some allow etc magic, but, as always, rspec got the better of me. I'll try reading up on it during the weekend, or if you have a quick hint, appreciated. Maybe the code doesn't work yet, but since the test doesn't even end up in that section (verified via debugger), difficult to say for sure.
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.
Let's trace the call chain. Creating a public comment via the UI:
- https://github.com/diaspora/diaspora/blob/develop/app/controllers/comments_controller.rb#L15
- https://github.com/diaspora/diaspora/blob/develop/app/services/comment_service.rb#L15
- https://github.com/diaspora/diaspora/blob/develop/app/models/user/social_actions.rb#L4
- https://github.com/diaspora/diaspora/blob/develop/app/models/comment.rb#L94
- https://github.com/diaspora/diaspora/blob/develop/lib/federated/generator.rb#L11
- https://github.com/diaspora/diaspora/blob/develop/lib/postzord/dispatcher.rb#L50
- https://github.com/diaspora/diaspora/blob/develop/app/workers/deferred_dispatch.rb#L16
So no, save!
doesn't trigger a callback that calls create!
, rather it's called explicitly and is what calls save!
. Let's pause here for a second and look at ...
Receiving a public comment via federation:
- https://github.com/diaspora/diaspora/blob/develop/app/controllers/publics_controller.rb#L24
- https://github.com/diaspora/diaspora/blob/develop/app/workers/receive_unencrypted_salmon.rb#L12
- https://github.com/diaspora/diaspora/blob/develop/lib/postzord/receiver.rb#L14
- https://github.com/diaspora/diaspora/blob/develop/lib/postzord/receiver/public.rb#L24
- https://github.com/diaspora/diaspora/blob/develop/lib/postzord/receiver/public.rb#L54
- https://github.com/diaspora/diaspora/blob/develop/lib/diaspora/parser.rb#L13
- Effectively
Comment.from_xml
,from_xml
is ROXML magic (thexml_attr
stuff in the models). No callbacks. - https://github.com/diaspora/diaspora/blob/develop/lib/postzord/receiver/public.rb#L59
- https://github.com/diaspora/diaspora/blob/develop/lib/postzord/receiver/public.rb#L67 (We're persisted to the DB now)
- https://github.com/diaspora/diaspora/blob/develop/lib/postzord/receiver/public.rb#L32-L33 (https://github.com/diaspora/diaspora/blob/develop/app/models/comment.rb#L10, https://github.com/diaspora/diaspora/blob/develop/lib/diaspora/relayable.rb#L43)
- https://github.com/diaspora/diaspora/blob/develop/lib/postzord/receiver/public.rb#L45
- https://github.com/diaspora/diaspora/blob/develop/lib/diaspora/relayable.rb#L89
Now we're at Postzord::Dispatcher.build(...).post
again, so the code paths converge here.
- https://github.com/diaspora/diaspora/blob/develop/lib/postzord/dispatcher.rb#L34
- https://github.com/diaspora/diaspora/blob/develop/lib/postzord/dispatcher.rb#L66
- https://github.com/diaspora/diaspora/blob/develop/lib/postzord/dispatcher.rb#L85
- https://github.com/diaspora/diaspora/blob/develop/lib/postzord/dispatcher.rb#L126
- https://github.com/diaspora/diaspora/blob/develop/lib/postzord/dispatcher.rb#L139
- https://github.com/diaspora/diaspora/blob/develop/app/workers/receive_local_batch.rb#L11-L12
- https://github.com/diaspora/diaspora/blob/develop/lib/postzord/receiver/local_batch.rb#L19
- https://github.com/diaspora/diaspora/blob/develop/lib/postzord/receiver/local_batch.rb#L36
- https://github.com/diaspora/diaspora/blob/develop/lib/diaspora/relayable.rb#L69 (the other codepath now, where we own the parent).
That should show all relevant "callback"/"hook" situations, the last part rather being for completeness.
It's probably fair if you just do the testcase for Federated::Generator
directly, using a test subclass that returns stub (double
) values. Or you argue that it's opaque behaviour of the CommentsController
or CommentService
even, though that's a bit on the far edge of unit testing.
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.
Thanks, now my head hurts ;) Will continue later with something..
895e1c4
to
f60d814
Compare
Hmmm odd thing with the tests. One of the builds passes (mysql 2.2), but all three others fail? |
As posts are always delivered also to reshare root, comments should also be delivered to reshare root, for concistency.
When author of the root post receives a reshare to it, no participation is added to the root author on the reshare. This causes any comments on the reshare on remote pods not to be sent to the author. Adding a participation should subscribe to the reshare and thus bring added comments back to the author.
747274e
to
a55713b
Compare
Final stage:
I have nothing more to add to this so unless review gives anything and if tests pass, ready for mergy. @denschub - could this be included in tomorrows 0.5 freeze since it improves federation? |
No objections, merged as 9a35a0d. |
Thanks @jaywink for your work. It really saves me a lot of time :) |
When author of the root post receives a reshare to it, no participation is added to the root author on the reshare. This causes any comments on the reshare on remote pods not to be sent to the author. Adding a participation should subscribe to the reshare and thus bring added comments back to the author.
Did some live testing with develop production pods to make sure of this case. Basically:
Expected:
What happens: