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

feat: move subscription to merged discussion #50

Conversation

SychO9
Copy link
Contributor

@SychO9 SychO9 commented Jul 21, 2023

Changes proposed in this pull request:

  • This PR allows moving subscriptions from merged discussions to the new final discussion, useful if someone is following discussion A but discussion A gets merged into B.

Confirmed

  • Frontend changes: tested on a local Flarum installation.
  • Backend changes: tests are green (run composer test).

Required changes:

Copy link
Contributor

@luceos luceos left a comment

Choose a reason for hiding this comment

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

The handler is growing quite large this way. I can imagine we need to refactor this at some point. I can also imagine other extensions wanting to extend the merging logic anyway.

Once someone tests this locally I think it would be okay to merge.

})
->update([
'discussion_id' => $discussion->id,
'last_read_post_number' => $discussion->last_post_number,
Copy link
Member

Choose a reason for hiding this comment

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

Does this mean the new merged discussion will be marked completely as read if any of the merged ones was being followed by the user? Even if the user hadn't read any of the posts involved in the merge?

Copy link
Contributor Author

@SychO9 SychO9 Jul 29, 2023

Choose a reason for hiding this comment

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

Yea, it only applies if they've never read the target discussion though, setting the number to 1 might be better in retrospect.

Copy link
Member

@dsevillamartin dsevillamartin Jul 29, 2023

Choose a reason for hiding this comment

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

I think i'd rather set it to the last post number where the user has read all previous posts - but that requires either checking old & new post numbers or created times. More complicated. And not limited to flarum/subscriptions either.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure that it's doable, post numbers change when merging from discussion A, B, C to discussion Y. Which post number to pick from A B C and how to pick it with its new value seems like a lot of complexity.

Also, since they haven't read discussion Y at all, setting a post number other than 1 means original posts they haven't read gets marked as read.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, so what I described was keeping the original "last read post" references of each discussion and comparing their new post numbers, picking the smallest one as the one to save in the new discussion. This way it'd resume them at the point where new posts appear that they may have not read, with the ones they definitely had before them.

Eg.

Original Discussion ID Last Read Post's Old Number Last Read Post's New Number
1 4 6
2 1 3
3 1 8

We know they must've read posts #1-3 at least in the merged discussion, so we can set last post read number to 3. This doesn't necessarily mean the next post will not have been read, but it guarantees the ones beforehand were.

Of course, this could be also done by calculating which post is first encountered in the new numbering that wasn't read, but that seems more consuming.

Or we can do none of this cause It's not worth it 🤷. Not in the scope of this PR anyways.
I did start second guessing myself while I wrote this 😅 but I think what I wrote is correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, thinking back again maybe it's too much to introduce this PR logic in the extension, might be better to keep it simple. How about just a MergingDiscussions event dispatched instead. That way it can be used for custom behavior without burdening current extension.

@SychO9
Copy link
Contributor Author

SychO9 commented Jul 30, 2023

The handler is growing quite large this way. I can imagine we need to refactor this at some point. I can also imagine other extensions wanting to extend the merging logic anyway.

Agreed, after further thought, i think it'd be better to dispatch an appropriate event instead.
#51

@SychO9 SychO9 mentioned this pull request Jul 30, 2023
3 tasks
@imorland imorland closed this Aug 1, 2023
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