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

Unsubscribe original territory owner on transfer or unarchive #1791

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

riccardobl
Copy link
Member

Description

Fixes #1517

Checklist

Are your changes backwards compatible? Please answer below:
yes

On a scale of 1-10 how well and how have you QA'd this change and any features it might affect? Please answer below:

  • transfer
  • transfer when source is not subscribed
  • transfer when destination is already subscribed
  • unarchive
  • unarchive when source is not subscribed
  • unarchive when destination is already subscribed
  • self unarchive

For frontend changes: Tested on mobile, light and dark mode? Please answer below:

Did you introduce any new environment variables? If so, call them out explicitly here:
no


// unsubscribe the old user
const oldSubscription = await tx.subSubscription.findUnique({ where: { userId_subName: { userId: oldUserId, subName: name } } })
if (oldSubscription) await tx.subSubscription.delete({ where: { userId_subName: { subName: name, userId: oldUserId } } })
Copy link
Member Author

Choose a reason for hiding this comment

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

do you prefer this or deleteMany?

Copy link
Member

Choose a reason for hiding this comment

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

I think delete should be fine. But do you need to check first if it exists?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, delete will error if the record does not exist (eg. if the user unsubscribed manually before transferring the territory) the workaround is to use deleteMany that will not error.
But in this case, since it is already inside a transaction, maybe this is better?

Copy link
Member

Choose a reason for hiding this comment

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

I would use deleteMany then

// unsubscribe the old user
const oldSubscription = await tx.subSubscription.findUnique({ where: { userId_subName: { userId: oldUserId, subName } } })
if (oldSubscription) await tx.subSubscription.delete({ where: { userId_subName: { subName, userId: oldUserId } } })
return updatedSub
Copy link
Member Author

Choose a reason for hiding this comment

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

Should it also subscribe the new user if they aren't already?
On one hand, I think it would be expected to do so, but on the other hand, you can transfer territories without the receiver's consent, so maybe it shouldn’t subscribe automatically?

Copy link
Member

Choose a reason for hiding this comment

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

Nah, I'd say let's not automatically subscribe them for the reason you mentioned

@riccardobl riccardobl changed the title Unsubtransfer Unsubscribe original territory owner on transfer or unarchive Jan 3, 2025
@ekzyis ekzyis self-requested a review January 5, 2025 18:03
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.

Founders of archived territories are get post notifications when unarchived by new founders
2 participants