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

Improve federation regarding reshares and root post author #6481

Closed
wants to merge 2 commits into from

Conversation

jaywink
Copy link
Contributor

@jaywink jaywink commented Oct 9, 2015

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:

  • User A posts a post on pod A
  • User B, who follows user A, reshares it on pod B
  • User C, who follows user B, comments on the reshare of B on pod C

Expected:

  • Pod A should receive the reshare and the comment
  • Pod B should receive the reshare and the comment
  • Pod C should receive the reshare and the comment (has authored it)

What happens:

  • Pod A receives only the reshare, not the comment
  • Pod B receives the reshare and the comment
  • Pod C receives the reshare and the comment (has authored it)

@jaywink
Copy link
Contributor Author

jaywink commented Oct 9, 2015

Also, the bug in action:

https://iliketoast.net/posts/775355 <-- my reshare of HQ post, has a comment from Sean
https://pod.diaspora.software/p/0746ec1050d10133bafa6c626dd55703 <-- my reshare on HQ, never got the comment

@jaywink
Copy link
Contributor Author

jaywink commented Oct 10, 2015

Hmm actually I need to continue testing this patch tomorrow...

@jaywink
Copy link
Contributor Author

jaywink commented Oct 10, 2015

Actually, this ended up not being so simple. I managed to (by moving the code to lib.postzord.receiver.local_batch.receive!) get the participations to be created, so for example a situation where:

  • User A writes a post, doesn't follow anyone
  • User B follows user A, reshares user A post
  • User C follows user B, reshares user B reshare (ie user A post)

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
User B reshares
User C reshares (from following user B)

--> 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.

@jaywink
Copy link
Contributor Author

jaywink commented Oct 10, 2015

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 defer_build_and_dispatch gets the correct additional_subscribers. Any pointers towards how to rewrite the test a bit for that?

@jaywink
Copy link
Contributor Author

jaywink commented Oct 11, 2015

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

@ghost
Copy link

ghost commented Oct 11, 2015

OK I've added functionality now to also push comments made to reshares to the original author.

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).

@jaywink
Copy link
Contributor Author

jaywink commented Oct 11, 2015

Do you think it is possible for the comments to be the same on all the reshares?

Where the comments link hasn't been changed, the comment is just delivered to one extra place: the root authors pod.

@jaywink
Copy link
Contributor Author

jaywink commented Oct 11, 2015

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.

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

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.

@jaywink
Copy link
Contributor Author

jaywink commented Oct 28, 2015

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?

@Flaburgan
Copy link
Member

Yep +1 from my side.

@root = @reshare.root
end

let(:receiver) { Postzord::Receiver::LocalBatch.new(@object, @ids) }
Copy link
Member

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.

# 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)
Copy link
Contributor Author

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.

Copy link
Member

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:

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:

Now we're at Postzord::Dispatcher.build(...).post again, so the code paths converge here.

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.

Copy link
Contributor Author

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..

@jaywink
Copy link
Contributor Author

jaywink commented Nov 21, 2015

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.
@jaywink jaywink changed the title Add participation to root.author on receiving reshare Improve federation regarding reshares and root post author Nov 21, 2015
@jaywink
Copy link
Contributor Author

jaywink commented Nov 21, 2015

Final stage:

  • Send comment to reshare author when commenting on reshare. As posts are always delivered also to reshare root, comments should also be delivered to reshare root, for concistency.
  • Add participation to root.author on receiving reshare. 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.

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?

@jaywink jaywink closed this in 9a35a0d Nov 22, 2015
@denschub denschub added this to the 0.5.5.0 milestone Nov 22, 2015
@denschub
Copy link
Member

No objections, merged as 9a35a0d.

@jaywink jaywink deleted the reshare-participate branch November 22, 2015 06:25
@TheRadialActive
Copy link

Thanks @jaywink for your work. It really saves me a lot of time :)

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.

None yet

6 participants